static int __init smu_controls_init(void) { struct device_node *smu, *fans, *fan; if (!smu_present()) return -ENODEV; smu = of_find_node_by_type(NULL, "smu"); if (smu == NULL) return -ENODEV; /* Look for RPM fans */ for (fans = NULL; (fans = of_get_next_child(smu, fans)) != NULL;) if (!strcmp(fans->name, "rpm-fans") || of_device_is_compatible(fans, "smu-rpm-fans")) break; for (fan = NULL; fans && (fan = of_get_next_child(fans, fan)) != NULL;) { struct smu_fan_control *fct; fct = smu_fan_create(fan, 0); if (fct == NULL) { #ifdef CONFIG_DEBUG_PRINTK printk(KERN_WARNING "windfarm: Failed to create SMU " "RPM fan %s\n", fan->name); #else ; #endif continue; } list_add(&fct->link, &smu_fans); } of_node_put(fans); /* Look for PWM fans */ for (fans = NULL; (fans = of_get_next_child(smu, fans)) != NULL;) if (!strcmp(fans->name, "pwm-fans")) break; for (fan = NULL; fans && (fan = of_get_next_child(fans, fan)) != NULL;) { struct smu_fan_control *fct; fct = smu_fan_create(fan, 1); if (fct == NULL) { #ifdef CONFIG_DEBUG_PRINTK printk(KERN_WARNING "windfarm: Failed to create SMU " "PWM fan %s\n", fan->name); #else ; #endif continue; } list_add(&fct->link, &smu_fans); } of_node_put(fans); of_node_put(smu); return 0; }
int __devinit of_mtd_parse_partitions(struct device *dev, struct device_node *node, struct mtd_partition **pparts) { const char *partname; struct device_node *pp; int nr_parts, i; /* First count the subnodes */ pp = NULL; nr_parts = 0; while ((pp = of_get_next_child(node, pp))) nr_parts++; if (nr_parts == 0) return 0; *pparts = kzalloc(nr_parts * sizeof(**pparts), GFP_KERNEL); if (!*pparts) return -ENOMEM; pp = NULL; i = 0; while ((pp = of_get_next_child(node, pp))) { const u32 *reg; int len; reg = of_get_property(pp, "reg", &len); if (!reg) { nr_parts--; continue; } (*pparts)[i].offset = reg[0]; (*pparts)[i].size = reg[1]; partname = of_get_property(pp, "label", &len); if (!partname) partname = of_get_property(pp, "name", &len); (*pparts)[i].name = (char *)partname; if (of_get_property(pp, "read-only", &len)) (*pparts)[i].mask_flags = MTD_WRITEABLE; i++; } if (!i) { of_node_put(pp); dev_err(dev, "No valid partition found on %s\n", node->full_name); kfree(*pparts); *pparts = NULL; return -EINVAL; } return nr_parts; }
static void macio_gpio_init_one(struct macio_chip *macio) { struct device_node *gparent, *gp; /* */ for (gparent = NULL; (gparent = of_get_next_child(macio->of_node, gparent)) != NULL;) if (strcmp(gparent->name, "gpio") == 0) break; if (gparent == NULL) return; DBG("Installing GPIO functions for macio %s\n", macio->of_node->full_name); /* */ for (gp = NULL; (gp = of_get_next_child(gparent, gp)) != NULL;) { const u32 *reg = of_get_property(gp, "reg", NULL); unsigned long offset; if (reg == NULL) continue; offset = *reg; /* */ if (offset < 0x50) offset += 0x50; offset += (unsigned long)macio->base; pmf_register_driver(gp, &macio_gpio_handlers, (void *)offset); } DBG("Calling initial GPIO functions for macio %s\n", macio->of_node->full_name); /* */ for (gp = NULL; (gp = of_get_next_child(gparent, gp)) != NULL;) pmf_do_functions(gp, NULL, 0, PMF_FLAGS_ON_INIT, NULL); /* */ }
unsigned long __init find_and_init_phbs(void) { struct device_node *node; struct pci_controller *phb; unsigned int index; struct device_node *root = of_find_node_by_path("/"); index = 0; for (node = of_get_next_child(root, NULL); node != NULL; node = of_get_next_child(root, node)) { if (node->type == NULL || (strcmp(node->type, "pci") != 0 && strcmp(node->type, "pciex") != 0)) continue; phb = pcibios_alloc_controller(node); if (!phb) continue; rtas_setup_phb(phb); pci_process_bridge_OF_ranges(phb, node, 0); pci_setup_phb_io(phb, index == 0); index++; } of_node_put(root); pci_devs_phb_init(); /* * pci_probe_only and pci_assign_all_buses can be set via properties * in chosen. */ if (of_chosen) { const int *prop; prop = get_property(of_chosen, "linux,pci-probe-only", NULL); if (prop) pci_probe_only = *prop; prop = get_property(of_chosen, "linux,pci-assign-all-buses", NULL); if (prop) pci_assign_all_buses = *prop; } return 0; }
static void macio_gpio_init_one(struct macio_chip *macio) { struct device_node *gparent, *gp; /* * Find the "gpio" parent node */ for (gparent = NULL; (gparent = of_get_next_child(macio->of_node, gparent)) != NULL;) if (strcmp(gparent->name, "gpio") == 0) break; if (gparent == NULL) return; DBG("Installing GPIO functions for macio %s\n", macio->of_node->full_name); /* * Ok, got one, we dont need anything special to track them down, so * we just create them all */ for (gp = NULL; (gp = of_get_next_child(gparent, gp)) != NULL;) { const u32 *reg = of_get_property(gp, "reg", NULL); unsigned long offset; if (reg == NULL) continue; offset = *reg; /* Deal with old style device-tree. We can safely hard code the * offset for now too even if it's a bit gross ... */ if (offset < 0x50) offset += 0x50; offset += (unsigned long)macio->base; pmf_register_driver(gp, &macio_gpio_handlers, (void *)offset); } DBG("Calling initial GPIO functions for macio %s\n", macio->of_node->full_name); /* And now we run all the init ones */ for (gp = NULL; (gp = of_get_next_child(gparent, gp)) != NULL;) pmf_do_functions(gp, NULL, 0, PMF_FLAGS_ON_INIT, NULL); /* Note: We do not at this point implement the "at sleep" or "at wake" * functions. I yet to find any for GPIOs anyway */ }
static int amlogic_pinctrl_probe_dt(struct platform_device *pdev, struct amlogic_pmx *d) { struct amlogic_pinctrl_soc_data *soc = d->soc; struct device_node *np = pdev->dev.of_node; struct device_node *child; struct amlogic_pmx_func *f; const char *pinctrl_set = "amlogic,setmask"; const char *pinctrl_clr="amlogic,clrmask"; const char *fn, *fnull = ""; int i = 0, idxf = 0, idxg = 0; int ret; u32 val; child = of_get_next_child(np, NULL); if (!child) { dev_err(&pdev->dev, "no group is defined\n"); return -ENOENT; } /* Count total functions and groups */ fn = fnull; for_each_child_of_node(np, child) { soc->ngroups++; /* Skip pure pinconf node */ if (of_property_read_u32(child, pinctrl_set, &val)&& of_property_read_u32(child, pinctrl_clr, &val)) continue; if (strcmp(fn, child->name)) { fn = child->name; soc->nfunctions++; } }
static void uninorth_install_pfunc(void) { struct device_node *np; DBG("Installing functions for UniN %pOF\n", uninorth_node); /* * Install handlers for the bridge itself */ pmf_register_driver(uninorth_node, &unin_mmio_handlers, NULL); pmf_do_functions(uninorth_node, NULL, 0, PMF_FLAGS_ON_INIT, NULL); /* * Install handlers for the hwclock child if any */ for (np = NULL; (np = of_get_next_child(uninorth_node, np)) != NULL;) if (of_node_name_eq(np, "hw-clock")) { unin_hwclock = np; break; } if (unin_hwclock) { DBG("Installing functions for UniN clock %pOF\n", unin_hwclock); pmf_register_driver(unin_hwclock, &unin_mmio_handlers, NULL); pmf_do_functions(unin_hwclock, NULL, 0, PMF_FLAGS_ON_INIT, NULL); } }
static void uninorth_install_pfunc(void) { struct device_node *np; DBG("Installing functions for UniN %s\n", uninorth_node->full_name); /* */ pmf_register_driver(uninorth_node, &unin_mmio_handlers, NULL); pmf_do_functions(uninorth_node, NULL, 0, PMF_FLAGS_ON_INIT, NULL); /* */ for (np = NULL; (np = of_get_next_child(uninorth_node, np)) != NULL;) if (strcmp(np->name, "hw-clock") == 0) { unin_hwclock = np; break; } if (unin_hwclock) { DBG("Installing functions for UniN clock %s\n", unin_hwclock->full_name); pmf_register_driver(unin_hwclock, &unin_mmio_handlers, NULL); pmf_do_functions(unin_hwclock, NULL, 0, PMF_FLAGS_ON_INIT, NULL); } }
static struct device_node *get_gpio(char *name, char *altname, int *gpioptr, int *gpioactiveptr) { struct device_node *np, *gpio; const u32 *reg; const char *audio_gpio; *gpioptr = -1; /* check if we can get it the easy way ... */ np = of_find_node_by_name(NULL, name); if (!np) { /* some machines have only gpioX/extint-gpioX nodes, * and an audio-gpio property saying what it is ... * So what we have to do is enumerate all children * of the gpio node and check them all. */ gpio = of_find_node_by_name(NULL, "gpio"); if (!gpio) return NULL; while ((np = of_get_next_child(gpio, np))) { audio_gpio = of_get_property(np, "audio-gpio", NULL); if (!audio_gpio) continue; if (strcmp(audio_gpio, name) == 0) break; if (altname && (strcmp(audio_gpio, altname) == 0)) break; } /* still not found, assume not there */ if (!np) return NULL; } reg = of_get_property(np, "reg", NULL); if (!reg) return NULL; *gpioptr = *reg; /* this is a hack, usually the GPIOs 'reg' property * should have the offset based from the GPIO space * which is at 0x50, but apparently not always... */ if (*gpioptr < 0x50) *gpioptr += 0x50; reg = of_get_property(np, "audio-gpio-active-state", NULL); if (!reg) /* Apple seems to default to 1, but * that doesn't seem right at least on most * machines. So until proven that the opposite * is necessary, we default to 0 * (which, incidentally, snd-powermac also does...) */ *gpioactiveptr = 0; else *gpioactiveptr = *reg; return np; }
/** * of_platform_bus_create - Create an OF device for a bus node and all its * children. Optionally recursively instanciate matching busses. * @bus: device node of the bus to instanciate * @matches: match table, NULL to use the default, OF_NO_DEEP_PROBE to * disallow recursive creation of child busses */ static int of_platform_bus_create(struct device_node *bus, struct of_device_id *matches, struct device *parent) { struct device_node *child; struct of_device *dev; int rc = 0; for (child = NULL; (child = of_get_next_child(bus, child)); ) { pr_debug(" create child: %s\n", child->full_name); dev = of_platform_device_create(child, NULL, parent); if (dev == NULL) rc = -ENOMEM; else if (!of_match_node(matches, child)) continue; if (rc == 0) { pr_debug(" and sub busses\n"); rc = of_platform_bus_create(child, matches, &dev->dev); } if (rc) { of_node_put(child); break; } } return rc; }
static void __init efika_pcisetup(void) { const int *bus_range; int len; struct pci_controller *hose; struct device_node *root; struct device_node *pcictrl; root = of_find_node_by_path("/"); if (root == NULL) { printk(KERN_WARNING EFIKA_PLATFORM_NAME ": Unable to find the root node\n"); return; } for (pcictrl = NULL;;) { pcictrl = of_get_next_child(root, pcictrl); if ((pcictrl == NULL) || (strcmp(pcictrl->name, "pci") == 0)) break; } of_node_put(root); if (pcictrl == NULL) { printk(KERN_WARNING EFIKA_PLATFORM_NAME ": Unable to find the PCI bridge node\n"); return; } bus_range = of_get_property(pcictrl, "bus-range", &len); if (bus_range == NULL || len < 2 * sizeof(int)) { printk(KERN_WARNING EFIKA_PLATFORM_NAME ": Can't get bus-range for %s\n", pcictrl->full_name); <<<<<<< HEAD
static int wf_max6690_attach(struct i2c_adapter *adapter) { struct device_node *busnode, *dev = NULL; struct pmac_i2c_bus *bus; const char *loc; bus = pmac_i2c_adapter_to_bus(adapter); if (bus == NULL) return -ENODEV; busnode = pmac_i2c_get_bus_node(bus); while ((dev = of_get_next_child(busnode, dev)) != NULL) { u8 addr; /* We must re-match the adapter in order to properly check * the channel on multibus setups */ if (!pmac_i2c_match_adapter(dev, adapter)) continue; if (!of_device_is_compatible(dev, "max6690")) continue; addr = pmac_i2c_get_dev_addr(dev); loc = of_get_property(dev, "hwsensor-location", NULL); if (loc == NULL || addr == 0) continue; ; wf_max6690_create(adapter, addr, loc); } return 0; }
void __init efika_pcisetup(void) { const int *bus_range; int len; struct pci_controller *hose; struct device_node *root; struct device_node *pcictrl; root = of_find_node_by_path("/"); if (root == NULL) { printk(KERN_WARNING EFIKA_PLATFORM_NAME ": Unable to find the root node\n"); return; } for (pcictrl = NULL;;) { pcictrl = of_get_next_child(root, pcictrl); if ((pcictrl == NULL) || (strcmp(pcictrl->name, "pci") == 0)) break; } of_node_put(root); if (pcictrl == NULL) { printk(KERN_WARNING EFIKA_PLATFORM_NAME ": Unable to find the PCI bridge node\n"); return; } bus_range = of_get_property(pcictrl, "bus-range", &len); if (bus_range == NULL || len < 2 * sizeof(int)) { printk(KERN_WARNING EFIKA_PLATFORM_NAME ": Can't get bus-range for %s\n", pcictrl->full_name); return; } if (bus_range[1] == bus_range[0]) printk(KERN_INFO EFIKA_PLATFORM_NAME ": PCI bus %d", bus_range[0]); else printk(KERN_INFO EFIKA_PLATFORM_NAME ": PCI buses %d..%d", bus_range[0], bus_range[1]); printk(" controlled by %s\n", pcictrl->full_name); printk("\n"); hose = pcibios_alloc_controller(); if (!hose) { printk(KERN_WARNING EFIKA_PLATFORM_NAME ": Can't allocate PCI controller structure for %s\n", pcictrl->full_name); return; } hose->arch_data = of_node_get(pcictrl); hose->first_busno = bus_range[0]; hose->last_busno = bus_range[1]; hose->ops = &rtas_pci_ops; pci_process_bridge_OF_ranges(hose, pcictrl, 0); }
static int grlib_apbuart_configure(void) { struct device_node *np, *rp; const u32 *prop; int freq_khz, line = 0; /* Get bus frequency */ rp = of_find_node_by_path("/"); if (!rp) return -ENODEV; rp = of_get_next_child(rp, NULL); if (!rp) return -ENODEV; prop = of_get_property(rp, "clock-frequency", NULL); if (!prop) return -ENODEV; freq_khz = *prop; for_each_matching_node(np, apbuart_match) { const int *irqs, *ampopts; const struct amba_prom_registers *regs; struct uart_port *port; unsigned long addr; ampopts = of_get_property(np, "ampopts", NULL); if (ampopts && (*ampopts == 0)) continue; /* Ignore if used by another OS instance */ irqs = of_get_property(np, "interrupts", NULL); regs = of_get_property(np, "reg", NULL); if (!irqs || !regs) continue; grlib_apbuart_nodes[line] = np; addr = regs->phys_addr; port = &grlib_apbuart_ports[line]; port->mapbase = addr; port->membase = ioremap(addr, sizeof(struct grlib_apbuart_regs_map)); port->irq = *irqs; port->iotype = UPIO_MEM; port->ops = &grlib_apbuart_ops; port->flags = UPF_BOOT_AUTOCONF; port->line = line; port->uartclk = freq_khz * 1000; port->fifosize = apbuart_scan_fifo_size((struct uart_port *) port, line); line++; /* We support maximum UART_NR uarts ... */ if (line == UART_NR) break; } grlib_apbuart_driver.nr = grlib_apbuart_port_nr = line; return line ? 0 : -ENODEV; }
int dlpar_detach_node(struct device_node *dn) { struct device_node *child; int rc; child = of_get_next_child(dn, NULL); while (child) { dlpar_detach_node(child); child = of_get_next_child(dn, child); } rc = of_detach_node(dn); if (rc) return rc; return 0; }
static int __devinit fs_enet_mdio_probe(struct of_device *ofdev, const struct of_device_id *match) { struct device_node *np = NULL; struct mii_bus *new_bus; struct bb_info *bitbang; int ret = -ENOMEM; int i; bitbang = kzalloc(sizeof(struct bb_info), GFP_KERNEL); if (!bitbang) goto out; bitbang->ctrl.ops = &bb_ops; new_bus = alloc_mdio_bitbang(&bitbang->ctrl); if (!new_bus) goto out_free_priv; new_bus->name = "CPM2 Bitbanged MII", ret = fs_mii_bitbang_init(new_bus, ofdev->node); if (ret) goto out_free_bus; new_bus->phy_mask = ~0; new_bus->irq = kmalloc(sizeof(int) * PHY_MAX_ADDR, GFP_KERNEL); if (!new_bus->irq) goto out_unmap_regs; for (i = 0; i < PHY_MAX_ADDR; i++) new_bus->irq[i] = -1; while ((np = of_get_next_child(ofdev->node, np))) if (!strcmp(np->type, "ethernet-phy")) add_phy(new_bus, np); new_bus->parent = &ofdev->dev; dev_set_drvdata(&ofdev->dev, new_bus); ret = mdiobus_register(new_bus); if (ret) goto out_free_irqs; return 0; out_free_irqs: dev_set_drvdata(&ofdev->dev, NULL); kfree(new_bus->irq); out_unmap_regs: iounmap(bitbang->dir); out_free_bus: free_mdio_bitbang(new_bus); out_free_priv: kfree(bitbang); out: return ret; }
void __init find_and_init_phbs(void) { struct device_node *node; struct pci_controller *phb; struct device_node *root = of_find_node_by_path("/"); for (node = of_get_next_child(root, NULL); node != NULL; node = of_get_next_child(root, node)) { if (node->type == NULL || (strcmp(node->type, "pci") != 0 && strcmp(node->type, "pciex") != 0)) continue; phb = pcibios_alloc_controller(node); if (!phb) continue; rtas_setup_phb(phb); pci_process_bridge_OF_ranges(phb, node, 0); isa_bridge_find_early(phb); } of_node_put(root); pci_devs_phb_init(); /* * pci_probe_only and pci_assign_all_buses can be set via properties * in chosen. */ if (of_chosen) { const int *prop; prop = of_get_property(of_chosen, "linux,pci-probe-only", NULL); if (prop) pci_probe_only = *prop; #ifdef CONFIG_PPC32 /* Will be made generic soon */ prop = of_get_property(of_chosen, "linux,pci-assign-all-buses", NULL); if (prop && *prop) ppc_pci_flags |= PPC_PCI_REASSIGN_ALL_BUS; #endif /* CONFIG_PPC32 */ } }
int dlpar_detach_node(struct device_node *dn) { struct device_node *child; int rc; child = of_get_next_child(dn, NULL); while (child) { dlpar_detach_node(child); child = of_get_next_child(dn, child); } rc = of_detach_node(dn); if (rc) return rc; of_node_put(dn); /* Must decrement the refcount */ return 0; }
static int __init gfar_mdio_of_init(void) { struct device_node *np; unsigned int i; struct platform_device *mdio_dev; struct resource res; int ret; for (np = NULL, i = 0; (np = of_find_compatible_node(np, "mdio", "gianfar")) != NULL; i++) { int k; struct device_node *child = NULL; struct gianfar_mdio_data mdio_data; memset(&res, 0, sizeof(res)); memset(&mdio_data, 0, sizeof(mdio_data)); ret = of_address_to_resource(np, 0, &res); if (ret) goto err; mdio_dev = platform_device_register_simple("fsl-gianfar_mdio", res.start, &res, 1); if (IS_ERR(mdio_dev)) { ret = PTR_ERR(mdio_dev); goto err; } for (k = 0; k < 32; k++) mdio_data.irq[k] = PHY_POLL; while ((child = of_get_next_child(np, child)) != NULL) { int irq = irq_of_parse_and_map(child, 0); if (irq != NO_IRQ) { const u32 *id = of_get_property(child, "reg", NULL); mdio_data.irq[*id] = irq; } } ret = platform_device_add_data(mdio_dev, &mdio_data, sizeof(struct gianfar_mdio_data)); if (ret) goto unreg; } return 0; unreg: platform_device_unregister(mdio_dev); err: return ret; }
static int axidma_of_parse_channel(struct device_node *dma_node, int channel, struct axidma_chan *chan, struct axidma_device *dev) { int rc; struct device_node *dma_chan_node; u32 channel_id; // Verify that the DMA node has two channel (child) nodes, one for TX and RX if (of_get_child_count(dma_node) < 1) { axidma_node_err(dma_node, "DMA does not have any channel nodes.\n"); return -EINVAL; } else if (of_get_child_count(dma_node) > 2) { axidma_node_err(dma_node, "DMA has more than two channel nodes.\n"); return -EINVAL; } // Go to the child node that we're parsing dma_chan_node = of_get_next_child(dma_node, NULL); if (channel == 1) { dma_chan_node = of_get_next_child(dma_node, dma_chan_node); } // Read out the channel's unique device id, and put it in the structure if (of_find_property(dma_chan_node, "xlnx,device-id", NULL) == NULL) { axidma_node_err(dma_chan_node, "DMA channel is missing the " "'xlnx,device-id' property.\n"); return -EINVAL; } rc = of_property_read_u32(dma_chan_node, "xlnx,device-id", &channel_id); if (rc < 0) { axidma_err("Unable to read the 'xlnx,device-id' property.\n"); return -EINVAL; } chan->channel_id = channel_id; // Use the compatible string to determine the channel's information rc = axidma_parse_compatible_property(dma_chan_node, chan, dev); if (rc < 0) { return rc; } return 0; }
int nvidia_probe_of_connector(struct fb_info *info, int conn, u8 **out_edid) { struct nvidia_par *par = info->par; struct device_node *parent, *dp; unsigned char *pedid = NULL; static char *propnames[] = { "DFP,EDID", "LCD,EDID", "EDID", "EDID1", "EDID,B", "EDID,A", NULL }; int i; parent = pci_device_to_OF_node(par->pci_dev); if (parent == NULL) return -1; if (par->twoHeads) { char *pname; int len; for (dp = NULL; (dp = of_get_next_child(parent, dp)) != NULL;) { pname = (char *)get_property(dp, "name", NULL); if (!pname) continue; len = strlen(pname); if ((pname[len-1] == 'A' && conn == 1) || (pname[len-1] == 'B' && conn == 2)) { for (i = 0; propnames[i] != NULL; ++i) { pedid = (unsigned char *) get_property(dp, propnames[i], NULL); if (pedid != NULL) break; } of_node_put(dp); break; } } } if (pedid == NULL) { for (i = 0; propnames[i] != NULL; ++i) { pedid = (unsigned char *) get_property(parent, propnames[i], NULL); if (pedid != NULL) break; } } if (pedid) { *out_edid = kmalloc(EDID_LENGTH, GFP_KERNEL); if (*out_edid == NULL) return -1; memcpy(*out_edid, pedid, EDID_LENGTH); printk(KERN_DEBUG "nvidiafb: Found OF EDID for head %d\n", conn); return 0; } return -1; }
/* * Initialize chip structure */ static int ndfc_chip_init(struct ndfc_controller *ndfc, struct device_node *node) { struct device_node *flash_np; struct nand_chip *chip = &ndfc->chip; struct mtd_part_parser_data ppdata; int ret; chip->IO_ADDR_R = ndfc->ndfcbase + NDFC_DATA; chip->IO_ADDR_W = ndfc->ndfcbase + NDFC_DATA; chip->cmd_ctrl = ndfc_hwcontrol; chip->dev_ready = ndfc_ready; chip->select_chip = ndfc_select_chip; chip->chip_delay = 50; chip->controller = &ndfc->ndfc_control; chip->read_buf = ndfc_read_buf; chip->write_buf = ndfc_write_buf; chip->verify_buf = ndfc_verify_buf; chip->ecc.correct = nand_correct_data; chip->ecc.hwctl = ndfc_enable_hwecc; chip->ecc.calculate = ndfc_calculate_ecc; chip->ecc.mode = NAND_ECC_HW; chip->ecc.size = 256; chip->ecc.bytes = 3; chip->ecc.strength = 1; chip->priv = ndfc; ndfc->mtd.priv = chip; ndfc->mtd.owner = THIS_MODULE; flash_np = of_get_next_child(node, NULL); if (!flash_np) return -ENODEV; ppdata.of_node = flash_np; ndfc->mtd.name = kasprintf(GFP_KERNEL, "%s.%s", dev_name(&ndfc->ofdev->dev), flash_np->name); if (!ndfc->mtd.name) { ret = -ENOMEM; goto err; } ret = nand_scan(&ndfc->mtd, 1); if (ret) goto err; ret = mtd_device_parse_register(&ndfc->mtd, NULL, &ppdata, NULL, 0); err: of_node_put(flash_np); if (ret) kfree(ndfc->mtd.name); return ret; }
int of_platform_bus_probe(struct device_node *root, struct of_device_id *matches, struct device *parent) { struct device_node *child; struct of_device *dev; int rc = 0; if (matches == NULL) matches = of_default_bus_ids; if (matches == OF_NO_DEEP_PROBE) return -EINVAL; if (root == NULL) root = of_find_node_by_path("/"); else of_node_get(root); pr_debug("of_platform_bus_probe()\n"); pr_debug(" starting at: %s\n", root->full_name); /* Do a self check of bus type, if there's a match, create * children */ if (of_match_node(matches, root)) { pr_debug(" root match, create all sub devices\n"); dev = of_platform_device_create(root, NULL, parent); if (dev == NULL) { rc = -ENOMEM; goto bail; } pr_debug(" create all sub busses\n"); rc = of_platform_bus_create(root, matches, &dev->dev); goto bail; } for (child = NULL; (child = of_get_next_child(root, child)); ) { if (!of_match_node(matches, child)) continue; pr_debug(" match: %s\n", child->full_name); dev = of_platform_device_create(child, NULL, parent); if (dev == NULL) rc = -ENOMEM; else rc = of_platform_bus_create(child, matches, &dev->dev); if (rc) { of_node_put(child); break; } } bail: of_node_put(root); return rc; }
static int hall_sensor_get_devtree_pdata(struct device *dev, struct hall_sensor_platform_data *pdata) { struct device_node *node, *pp = NULL; struct det_gpio *hall_det_gpios; int i; unsigned int reg; node = dev->of_node; hall_det_gpios = pdata->gpios; pdata->name = of_get_property(node, "input-name", NULL); pp = NULL; i = 0; while ((pp = of_get_next_child(node, pp))) { enum of_gpio_flags flags; if (!of_find_property(pp, "gpios", NULL)) { pdata->ngpios--; printk("Found detgpio without gpios\n"); continue; } hall_det_gpios[i].gpio = of_get_gpio_flags(pp, 0, &flags); hall_det_gpios[i].active_low = flags & OF_GPIO_ACTIVE_LOW; if (of_property_read_u32(pp, "linux,code", ®)) { printk("detgpio without keycode: 0x%x\n", hall_det_gpios[i].gpio); goto out_fail; } hall_det_gpios[i].code = reg; hall_det_gpios[i].desc = of_get_property(pp, "label", NULL); if (of_property_read_u32(pp, "linux,input-type", ®) == 0) hall_det_gpios[i].type = reg; else goto out_fail; if (of_property_read_u32(pp, "debounce-interval", ®) == 0) hall_det_gpios[i].debounce_interval = reg; else hall_det_gpios[i].debounce_interval = 50; i++; } return 0; out_fail: return -ENODEV; }
static void __init cell_find_and_init_phbs(void) { struct device_node *axon, *plb5, *plb4, *np; int index = 0; /* Old blades, use generic code */ axon = of_find_node_by_name(NULL, "axon"); if (axon == NULL) { find_and_init_phbs(); return; } /* New blades, manually instanciate bridges for now as * RHEL5 doesn't have the infrastructure to do it from * of_platform */ for (; axon; axon = of_find_node_by_name(axon, "axon")) { for (plb5 = NULL; !!(plb5 = of_get_next_child(axon, plb5));) if (strcmp(plb5->name, "plb5") == 0) break; if (plb5 == NULL) continue; for (np = NULL; !!(np = of_get_next_child(plb5, np));) if ((strcmp(np->name, "pcie") == 0) || (strcmp(np->name, "pciex") == 0)) cell_add_phb(np, index++); for (plb4 = NULL; !!(plb4 = of_get_next_child(plb5, plb4));) if (strcmp(plb4->name, "plb4") == 0) break; of_node_put(plb5); if (plb4 == NULL) continue; for (np = NULL; !!(np = of_get_next_child(plb4, np));) if (strcmp(np->name, "pcix") == 0) cell_add_phb(np, index++); of_node_put(plb4); } pci_devs_phb_init(); }
/* * Initialize chip structure */ static int ndfc_chip_init(struct ndfc_controller *ndfc, struct device_node *node) { struct device_node *flash_np; struct nand_chip *chip = &ndfc->chip; struct mtd_info *mtd = nand_to_mtd(chip); int ret; chip->IO_ADDR_R = ndfc->ndfcbase + NDFC_DATA; chip->IO_ADDR_W = ndfc->ndfcbase + NDFC_DATA; chip->cmd_ctrl = ndfc_hwcontrol; chip->dev_ready = ndfc_ready; chip->select_chip = ndfc_select_chip; chip->chip_delay = 50; chip->controller = &ndfc->ndfc_control; chip->read_buf = ndfc_read_buf; chip->write_buf = ndfc_write_buf; chip->ecc.correct = nand_correct_data; chip->ecc.hwctl = ndfc_enable_hwecc; chip->ecc.calculate = ndfc_calculate_ecc; chip->ecc.mode = NAND_ECC_HW; chip->ecc.size = 256; chip->ecc.bytes = 3; chip->ecc.strength = 1; nand_set_controller_data(chip, ndfc); mtd->dev.parent = &ndfc->ofdev->dev; flash_np = of_get_next_child(node, NULL); if (!flash_np) return -ENODEV; nand_set_flash_node(chip, flash_np); mtd->name = kasprintf(GFP_KERNEL, "%s.%s", dev_name(&ndfc->ofdev->dev), flash_np->name); if (!mtd->name) { ret = -ENOMEM; goto err; } ret = nand_scan(mtd, 1); if (ret) goto err; ret = mtd_device_register(mtd, NULL, 0); err: of_node_put(flash_np); if (ret) kfree(mtd->name); return ret; }
/* Register all SoC external sub-devices */ static int fimc_md_register_sensor_entities(struct fimc_md *fmd) { struct device_node *parent = fmd->pdev->dev.of_node; struct device_node *node, *ports; int index = 0; int ret; /* * Runtime resume one of the FIMC entities to make sure * the sclk_cam clocks are not globally disabled. */ if (!fmd->pmf) return -ENXIO; ret = pm_runtime_get_sync(fmd->pmf); if (ret < 0) return ret; fmd->num_sensors = 0; /* Attach sensors linked to MIPI CSI-2 receivers */ for_each_available_child_of_node(parent, node) { struct device_node *port; if (of_node_cmp(node->name, "csis")) continue; /* The csis node can have only port subnode. */ port = of_get_next_child(node, NULL); if (!port) continue; ret = fimc_md_parse_port_node(fmd, port, index); if (ret < 0) { of_node_put(node); goto rpm_put; } index++; } /* Attach sensors listed in the parallel-ports node */ ports = of_get_child_by_name(parent, "parallel-ports"); if (!ports) goto rpm_put; for_each_child_of_node(ports, node) { ret = fimc_md_parse_port_node(fmd, node, index); if (ret < 0) { of_node_put(node); break; } index++; }
static int wf_sat_attach(struct i2c_adapter *adapter) { struct device_node *busnode, *dev = NULL; struct pmac_i2c_bus *bus; bus = pmac_i2c_adapter_to_bus(adapter); if (bus == NULL) return -ENODEV; busnode = pmac_i2c_get_bus_node(bus); while ((dev = of_get_next_child(busnode, dev)) != NULL) if (of_device_is_compatible(dev, "smu-sat")) wf_sat_create(adapter, dev); return 0; }
static int imx7_csi_get_upstream_endpoint(struct imx7_csi *csi, struct v4l2_fwnode_endpoint *ep, bool skip_mux) { struct device_node *endpoint, *port; struct media_entity *src; struct v4l2_subdev *sd; struct media_pad *pad; if (!csi->src_sd) return -EPIPE; src = &csi->src_sd->entity; skip_video_mux: /* get source pad of entity directly upstream from src */ pad = imx_media_pipeline_pad(src, 0, 0, true); if (IS_ERR(pad)) return PTR_ERR(pad); sd = media_entity_to_v4l2_subdev(pad->entity); /* To get bus type we may need to skip video mux */ if (skip_mux && src->function == MEDIA_ENT_F_VID_MUX) { src = &sd->entity; goto skip_video_mux; } /* * NOTE: this assumes an OF-graph port id is the same as a * media pad index. */ port = of_graph_get_port_by_id(sd->dev->of_node, pad->index); if (!port) return -ENODEV; endpoint = of_get_next_child(port, NULL); of_node_put(port); if (!endpoint) return -ENODEV; v4l2_fwnode_endpoint_parse(of_fwnode_handle(endpoint), ep); of_node_put(endpoint); return 0; }
static struct device_node *cvm_oct_of_get_child( const struct device_node *parent, int reg_val) { struct device_node *node = NULL; int size; const __be32 *addr; for (;;) { node = of_get_next_child(parent, node); if (!node) break; addr = of_get_property(node, "reg", &size); if (addr && (be32_to_cpu(*addr) == reg_val)) break; } return node; }