static int omap_init(void) { int ret; struct device_node *root; root = of_get_root_node(); if (root) { __omap_cpu_type = omap_soc_from_dt(); if (!__omap_cpu_type) hang(); } if (cpu_is_omap3()) ret = omap3_init(); else if (cpu_is_omap4()) ret = omap4_init(); else if (cpu_is_am33xx()) ret = am33xx_init(); else return -EINVAL; if (root) return ret; if (cpu_is_omap3()) ret = omap3_devices_init(); else if (cpu_is_omap4()) ret = omap4_devices_init(); else if (cpu_is_am33xx()) ret = am33xx_devices_init(); else return -EINVAL; return ret; }
static int rdu2_ethernet_init(void) { const char *aliases[] = { "ethernet0", "ethernet1" }; struct device_node *np, *root; int i, ret; if (!of_machine_is_compatible("zii,imx6q-zii-rdu2") && !of_machine_is_compatible("zii,imx6qp-zii-rdu2")) return 0; root = of_get_root_node(); for (i = 0; i < ARRAY_SIZE(aliases); i++) { const char *alias = aliases[i]; np = of_find_node_by_alias(root, alias); if (!np) { pr_warn("Failed to find %s\n", alias); continue; } ret = rdu2_eth_register_ethaddr(np); if (ret) { pr_warn("Failed to register MAC for %s\n", alias); continue; } } return 0; }
static int imx23_devices_init(void) { if (of_get_root_node()) return 0; add_generic_device("imx23-dma-apbh", 0, NULL, MXS_APBH_BASE, 0x2000, IORESOURCE_MEM, NULL); add_generic_device("imx23-clkctrl", 0, NULL, IMX_CCM_BASE, 0x100, IORESOURCE_MEM, NULL); add_generic_device("imx23-gpio", 0, NULL, IMX_IOMUXC_BASE, 0x2000, IORESOURCE_MEM, NULL); add_generic_device("imx23-gpio", 1, NULL, IMX_IOMUXC_BASE, 0x2000, IORESOURCE_MEM, NULL); add_generic_device("imx23-gpio", 2, NULL, IMX_IOMUXC_BASE, 0x2000, IORESOURCE_MEM, NULL); return 0; }
static int of_openrisc_init(void) { struct device_node *root; root = of_get_root_node(); if (root) return 0; root = of_unflatten_dtb(__dtb_start); if (root) { pr_debug("using internal DTB\n"); of_set_root_node(root); if (IS_ENABLED(CONFIG_OFDEVICE)) of_probe(); } return 0; }
static int barebox_of_driver_init(void) { struct device_node *node; node = of_get_root_node(); if (!node) return 0; node = of_find_node_by_path("/chosen"); if (!node) return 0; of_platform_populate(node, of_default_bus_match_table, NULL); platform_driver_register(&environment_driver); return 0; }
static int of_arm_init(void) { struct device_node *root; void *fdt; /* See if we already have a dtb */ root = of_get_root_node(); if (root) return 0; /* See if we are provided a dtb in boarddata */ fdt = barebox_arm_boot_dtb(); if (fdt) pr_debug("using boarddata provided DTB\n"); /* Next see if we have a builtin dtb */ if (!fdt && IS_ENABLED(CONFIG_BUILTIN_DTB)) { fdt = __dtb_start; pr_debug("using internal DTB\n"); } if (!fdt) { pr_debug("No DTB found\n"); return 0; } root = of_unflatten_dtb(fdt); if (root) { of_set_root_node(root); of_fix_tree(root); if (IS_ENABLED(CONFIG_OFDEVICE)) of_probe(); } return 0; }
static int do_oftree(int argc, char *argv[]) { struct fdt_header *fdt = NULL; void *fdt_free = NULL; int size; int opt; char *file = NULL; const char *node = "/"; int dump = 0; int probe = 0; int load = 0; int save = 0; int free_of = 0; int ret; while ((opt = getopt(argc, argv, "dpfn:ls")) > 0) { switch (opt) { case 'l': load = 1; break; case 'd': dump = 1; break; case 'p': if (IS_ENABLED(CONFIG_CMD_OFTREE_PROBE)) { probe = 1; } else { printf("oftree device probe support disabled\n"); return COMMAND_ERROR_USAGE; } break; case 'f': free_of = 1; break; case 'n': node = optarg; break; case 's': save = 1; break; } } if (free_of) { struct device_node *root = of_get_root_node(); if (root) of_free(root); return 0; } if (optind < argc) file = argv[optind]; if (!dump && !probe && !load && !save) return COMMAND_ERROR_USAGE; if (save) { if (!file) { printf("no file given\n"); ret = -ENOENT; goto out; } fdt = of_get_fixed_tree(NULL); if (!fdt) { printf("no devicetree available\n"); ret = -EINVAL; goto out; } ret = write_file(file, fdt, fdt_totalsize(fdt)); goto out; } if (file) { fdt = read_file(file, &size); if (!fdt) { printf("unable to read %s\n", file); return 1; } fdt_free = fdt; } if (load) { if (!fdt) { printf("no fdt given\n"); ret = -ENOENT; goto out; } ret = of_unflatten_dtb(fdt); if (ret) { printf("parse oftree: %s\n", strerror(-ret)); goto out; } } if (dump) { if (fdt) { ret = fdt_print(fdt, node); } else { struct device_node *n = of_find_node_by_path(node); if (!n) { ret = -ENOENT; goto out; } of_print_nodes(n, 0); ret = 0; } goto out; } if (probe) { ret = of_probe(); if (ret) goto out; } ret = 0; out: free(fdt_free); return ret; }
static int do_of_dump(int argc, char *argv[]) { int opt; int ret = 0; int fix = 0; struct device_node *root = NULL, *node, *of_free = NULL; char *dtbfile = NULL; size_t size; const char *nodename; int names_only = 0; while ((opt = getopt(argc, argv, "Ff:n")) > 0) { switch (opt) { case 'f': dtbfile = optarg; break; case 'F': fix = 1; break; case 'n': names_only = 1; break; default: return COMMAND_ERROR_USAGE; } } if (optind == argc) nodename = "/"; else nodename = argv[optind]; if (dtbfile) { void *fdt; fdt = read_file(dtbfile, &size); if (!fdt) { printf("unable to read %s: %s\n", dtbfile, strerror(errno)); return -errno; } root = of_unflatten_dtb(fdt); free(fdt); if (IS_ERR(root)) { ret = PTR_ERR(root); goto out; } of_free = root; } else { root = of_get_root_node(); if (fix) { /* create a copy of internal devicetree */ void *fdt; fdt = of_flatten_dtb(root); root = of_unflatten_dtb(fdt); free(fdt); if (IS_ERR(root)) { ret = PTR_ERR(root); goto out; } of_free = root; } } if (fix) { ret = of_fix_tree(root); if (ret) goto out; } node = of_find_node_by_path_or_alias(root, nodename); if (!node) { printf("Cannot find nodepath %s\n", nodename); ret = -ENOENT; goto out; } if (names_only) of_print_nodenames(node); else of_print_nodes(node, 0); out: if (of_free) of_delete_node(of_free); return ret; }