static int localbus_attach(device_t dev) { device_t dev_child; struct localbus_softc *sc; struct localbus_devinfo *di; phandle_t dt_node, dt_child; sc = device_get_softc(dev); sc->sc_dev = dev; sc->sc_banks = localbus_banks; /* * Walk localbus and add direct subordinates as our children. */ dt_node = ofw_bus_get_node(dev); for (dt_child = OF_child(dt_node); dt_child != 0; dt_child = OF_peer(dt_child)) { /* Check and process 'status' property. */ if (!(fdt_is_enabled(dt_child))) continue; if (!(fdt_pm_is_enabled(dt_child))) continue; di = malloc(sizeof(*di), M_LOCALBUS, M_WAITOK | M_ZERO); if (ofw_bus_gen_setup_devinfo(&di->di_ofw, dt_child) != 0) { free(di, M_LOCALBUS); device_printf(dev, "could not set up devinfo\n"); continue; } resource_list_init(&di->di_res); if (fdt_localbus_reg_decode(dt_child, sc, di)) { device_printf(dev, "could not process 'reg' " "property\n"); ofw_bus_gen_destroy_devinfo(&di->di_ofw); free(di, M_LOCALBUS); continue; } /* Add newbus device for this FDT node */ dev_child = device_add_child(dev, NULL, -1); if (dev_child == NULL) { device_printf(dev, "could not add child: %s\n", di->di_ofw.obd_name); resource_list_free(&di->di_res); ofw_bus_gen_destroy_devinfo(&di->di_ofw); free(di, M_LOCALBUS); continue; } #ifdef DEBUG device_printf(dev, "added child: %s\n\n", di->di_ofw.obd_name); #endif device_set_ivars(dev_child, di); } return (bus_generic_attach(dev)); }
static void pci_from_fdt_node(device_t dev_par, phandle_t dt_node, char *name, char *type, char *compat) { u_long reg_base, reg_size; phandle_t dt_child; /* * Retrieve 'reg' property. */ if (fdt_regsize(dt_node, ®_base, ®_size) != 0) { device_printf(dev_par, "could not retrieve 'reg' prop\n"); return; } /* * Walk the PCI node and instantiate newbus devices representing * logical resources (bridges / ports). */ for (dt_child = OF_child(dt_node); dt_child != 0; dt_child = OF_peer(dt_child)) { if (!(fdt_is_enabled(dt_child))) continue; newbus_pci_create(dev_par, dt_child, reg_base, reg_size); } }
static int pinmux_set(struct iomuxc_softc *sc) { phandle_t child, parent, root; pcell_t iomux_config[MAX_MUX_LEN]; int len; int values; int pin; int pin_cfg; int i; root = OF_finddevice("/"); len = 0; parent = root; /* Find 'iomux_config' prop in the nodes */ for (child = OF_child(parent); child != 0; child = OF_peer(child)) { /* Find a 'leaf'. Start the search from this node. */ while (OF_child(child)) { parent = child; child = OF_child(child); } if (!fdt_is_enabled(child)) continue; if ((len = OF_getproplen(child, "iomux_config")) > 0) { OF_getprop(child, "iomux_config", &iomux_config, len); values = len / (sizeof(uint32_t)); for (i = 0; i < values; i += 2) { pin = fdt32_to_cpu(iomux_config[i]); pin_cfg = fdt32_to_cpu(iomux_config[i+1]); #if 0 device_printf(sc->dev, "Set pin %d to 0x%08x\n", pin, pin_cfg); #endif WRITE4(sc, IOMUXC(pin), pin_cfg); } } if (OF_peer(child) == 0) { /* No more siblings. */ child = parent; parent = OF_parent(child); } } return (0); }
static int pinmux_configure(device_t dev, phandle_t cfgxref) { struct pinmux_softc *sc; phandle_t node, cfgnode; int rv; sc = device_get_softc(dev); cfgnode = OF_node_from_xref(cfgxref); for (node = OF_child(cfgnode); node != 0; node = OF_peer(node)) { if (!fdt_is_enabled(node)) continue; rv = pinmux_process_node(sc, node); } return (0); }
static int simplebus_attach(device_t dev) { device_t dev_child; struct simplebus_devinfo *di; struct simplebus_softc *sc; phandle_t dt_node, dt_child; sc = device_get_softc(dev); /* * Walk simple-bus and add direct subordinates as our children. */ dt_node = ofw_bus_get_node(dev); for (dt_child = OF_child(dt_node); dt_child != 0; dt_child = OF_peer(dt_child)) { /* Check and process 'status' property. */ if (!(fdt_is_enabled(dt_child))) continue; if (!(fdt_pm_is_enabled(dt_child))) continue; di = malloc(sizeof(*di), M_SIMPLEBUS, M_WAITOK | M_ZERO); if (ofw_bus_gen_setup_devinfo(&di->di_ofw, dt_child) != 0) { free(di, M_SIMPLEBUS); device_printf(dev, "could not set up devinfo\n"); continue; } resource_list_init(&di->di_res); if (fdt_reg_to_rl(dt_child, &di->di_res)) { device_printf(dev, "%s: could not process 'reg' " "property\n", di->di_ofw.obd_name); /* XXX should unmap */ ofw_bus_gen_destroy_devinfo(&di->di_ofw); free(di, M_SIMPLEBUS); continue; } if (fdt_intr_to_rl(dt_child, &di->di_res, di->di_intr_sl)) { device_printf(dev, "%s: could not process " "'interrupts' property\n", di->di_ofw.obd_name); resource_list_free(&di->di_res); /* XXX should unmap */ ofw_bus_gen_destroy_devinfo(&di->di_ofw); free(di, M_SIMPLEBUS); continue; } /* Add newbus device for this FDT node */ dev_child = device_add_child(dev, NULL, -1); if (dev_child == NULL) { device_printf(dev, "could not add child: %s\n", di->di_ofw.obd_name); resource_list_free(&di->di_res); /* XXX should unmap */ ofw_bus_gen_destroy_devinfo(&di->di_ofw); free(di, M_SIMPLEBUS); continue; } #ifdef DEBUG device_printf(dev, "added child: %s\n\n", di->di_ofw.obd_name); #endif device_set_ivars(dev_child, di); } return (bus_generic_attach(dev)); }
static int fdtbus_attach(device_t dev) { phandle_t root; phandle_t child; struct fdtbus_softc *sc; u_long start, end; int error; if ((root = OF_finddevice("/")) == -1) panic("fdtbus_attach: no root node."); sc = device_get_softc(dev); /* * IRQ rman. */ start = 0; end = ~0; sc->sc_irq.rm_start = start; sc->sc_irq.rm_end = end; sc->sc_irq.rm_type = RMAN_ARRAY; sc->sc_irq.rm_descr = "Interrupt request lines"; if ((error = rman_init(&sc->sc_irq)) != 0) { device_printf(dev, "could not init IRQ rman, error = %d\n", error); return (error); } if ((error = rman_manage_region(&sc->sc_irq, start, end)) != 0) { device_printf(dev, "could not manage IRQ region, error = %d\n", error); return (error); } /* * Mem-mapped I/O space rman. */ start = 0; end = ~0ul; sc->sc_mem.rm_start = start; sc->sc_mem.rm_end = end; sc->sc_mem.rm_type = RMAN_ARRAY; sc->sc_mem.rm_descr = "I/O memory"; if ((error = rman_init(&sc->sc_mem)) != 0) { device_printf(dev, "could not init I/O mem rman, error = %d\n", error); return (error); } if ((error = rman_manage_region(&sc->sc_mem, start, end)) != 0) { device_printf(dev, "could not manage I/O mem region, " "error = %d\n", error); return (error); } /* * Walk the FDT root node and add top-level devices as our children. */ for (child = OF_child(root); child != 0; child = OF_peer(child)) { /* Check and process 'status' property. */ if (!(fdt_is_enabled(child))) continue; newbus_device_from_fdt_node(dev, child); } return (bus_generic_attach(dev)); }