dart: add dart_init_fdt()

Used to intialize by FDT phandle.

Signed-off-by: Janne Grunau <j@jannau.net>
This commit is contained in:
Janne Grunau 2022-04-06 22:29:35 +02:00 committed by Asahi Lina
parent 3c5b0fdd52
commit 233264cda2
2 changed files with 49 additions and 0 deletions

View file

@ -8,6 +8,8 @@
#include "string.h"
#include "utils.h"
#include "libfdt/libfdt.h"
#define DART_T8020_CONFIG 0x60
#define DART_T8020_CONFIG_LOCK BIT(15)
@ -318,6 +320,52 @@ dart_dev_t *dart_init_adt(const char *path, int instance, int device, bool keep_
return dart;
}
dart_dev_t *dart_init_fdt(void *dt, u32 phandle, int device, bool keep_pts)
{
int node = fdt_node_offset_by_phandle(dt, phandle);
if (node < 0) {
printf("FDT: node for phandle %u not found\n", phandle);
return NULL;
}
int len;
const void *prop = fdt_getprop(dt, node, "reg", &len);
if (!prop || len < 8) {
return NULL;
}
uintptr_t base = fdt64_ld((const fdt64_t *)prop);
if (!base)
return NULL;
enum dart_type_t type;
const char *type_s;
const char *name = fdt_get_name(dt, node, NULL);
if (fdt_node_check_compatible(dt, node, "apple,t8103-dart") == 0) {
type = DART_T8020;
type_s = "t8020";
} else if (fdt_node_check_compatible(dt, node, "apple,t6000-dart") == 0) {
type = DART_T6000;
type_s = "t6000";
} else if (fdt_node_check_compatible(dt, node, "apple,t8110-dart") == 0) {
type = DART_T8110;
type_s = "t8110";
} else {
printf("dart: dart %s at 0x%lx is of an unknown type\n", name, base);
return NULL;
}
dart_dev_t *dart = dart_init(base, device, keep_pts, type);
if (!dart)
return NULL;
printf("dart: dart %s at 0x%lx is a %s%s\n", name, base, type_s,
dart->locked ? " (locked)" : "");
return dart;
}
int dart_setup_pt_region(dart_dev_t *dart, const char *path, int device)
{
/* only device 0 of dart-dcp and dart-disp0 are of interest */

View file

@ -18,6 +18,7 @@ enum dart_type_t {
dart_dev_t *dart_init(uintptr_t base, u8 device, bool keep_pts, enum dart_type_t type);
dart_dev_t *dart_init_adt(const char *path, int instance, int device, bool keep_pts);
dart_dev_t *dart_init_fdt(void *dt, u32 phandle, int device, bool keep_pts);
int dart_setup_pt_region(dart_dev_t *dart, const char *path, int device);
int dart_map(dart_dev_t *dart, uintptr_t iova, void *bfr, size_t len);
void dart_unmap(dart_dev_t *dart, uintptr_t iova, size_t len);