static int node_match(struct device *dev, void *data) { struct of_device *op = to_of_device(dev); struct device_node *dp = data; return (op->node == dp); }
static ssize_t dev_show_devspec(struct device *dev, struct device_attribute *attr, char *buf) { struct of_device *ofdev; ofdev = to_of_device(dev); return sprintf(buf, "%s", ofdev->node->full_name); }
static int ibmebus_unregister_device(struct device *dev) { device_remove_file(dev, &dev_attr_name); of_device_unregister(to_of_device(dev)); return 0; }
/** * of_release_dev - free an of device structure when all users of it are finished. * @dev: device that's been disconnected * * Will be called only by the device core when all users of this of device are * done. */ void of_release_dev(struct device *dev) { struct of_device *ofdev; ofdev = to_of_device(dev); kfree(ofdev); }
static ssize_t name_show(struct device *dev, struct device_attribute *attr, char *buf) { struct of_device *ofdev; ofdev = to_of_device(dev); return sprintf(buf, "%s\n", ofdev->node->name); }
static void of_platform_device_shutdown(struct device *dev) { struct of_device *of_dev = to_of_device(dev); struct of_platform_driver *drv = to_of_platform_driver(dev->driver); if (dev->driver && drv->shutdown) drv->shutdown(of_dev); }
/** * of_release_dev - free an of device structure when all users of it are finished. * @dev: device that's been disconnected * * Will be called only by the device core when all users of this of device are * done. */ void of_release_dev(struct device *dev) { struct of_device *ofdev; ofdev = to_of_device(dev); of_node_put(ofdev->node); kfree(ofdev); }
static int of_platform_device_remove(struct device *dev) { struct of_device * of_dev = to_of_device(dev); struct of_platform_driver * drv = to_of_platform_driver(dev->driver); if (dev->driver && drv->remove) drv->remove(of_dev); return 0; }
static int of_platform_device_suspend(struct device *dev, pm_message_t state) { struct of_device * of_dev = to_of_device(dev); struct of_platform_driver * drv = to_of_platform_driver(dev->driver); int error = 0; if (dev->driver && drv->suspend) error = drv->suspend(of_dev, state); return error; }
static int of_platform_device_resume(struct device * dev) { struct of_device * of_dev = to_of_device(dev); struct of_platform_driver * drv = to_of_platform_driver(dev->driver); int error = 0; if (dev->driver && drv->resume) error = drv->resume(of_dev); return error; }
struct of_device *of_find_device_by_phandle(phandle ph) { struct device *dev; dev = bus_find_device(&of_platform_bus_type, NULL, &ph, of_dev_phandle_match); if (dev) return to_of_device(dev); return NULL; }
static inline unsigned long device_to_node(struct device *hwdev) { #ifdef CONFIG_NUMA struct of_device *ofdev = to_of_device(hwdev); return ofdev->numa_node; #else return 0; #endif }
struct of_device *of_find_device_by_node(struct device_node *dp) { struct device *dev = bus_find_device(&of_platform_bus_type, NULL, dp, node_match); if (dev) return to_of_device(dev); return NULL; }
static int of_platform_legacy_resume(struct device *dev) { struct of_device *of_dev = to_of_device(dev); struct of_platform_driver *drv = to_of_platform_driver(dev->driver); int ret = 0; if (dev->driver && drv->resume) ret = drv->resume(of_dev); return ret; }
static int of_platform_legacy_suspend(struct device *dev, pm_message_t mesg) { struct of_device *of_dev = to_of_device(dev); struct of_platform_driver *drv = to_of_platform_driver(dev->driver); int ret = 0; if (dev->driver && drv->suspend) ret = drv->suspend(of_dev, mesg); return ret; }
static ssize_t axon_ram_sysfs_ecc(struct device *dev, struct device_attribute *attr, char *buf) { struct of_device *device = to_of_device(dev); struct axon_ram_bank *bank = device->dev.platform_data; BUG_ON(!bank); return sprintf(buf, "%ld\n", bank->ecc_counter); }
static ssize_t modalias_show(struct device *dev, struct device_attribute *attr, char *buf) { struct of_device *ofdev = to_of_device(dev); ssize_t len = 0; len = of_device_get_modalias(ofdev, buf, PAGE_SIZE - 2); buf[len] = '\n'; buf[len+1] = 0; return len+1; }
static int of_platform_bus_match(struct device *dev, struct device_driver *drv) { struct of_device * of_dev = to_of_device(dev); struct of_platform_driver * of_drv = to_of_platform_driver(drv); const struct of_device_id * matches = of_drv->match_table; if (!matches) return 0; return of_match_device(matches, of_dev) != NULL; }
struct of_device *of_dev_get(struct of_device *dev) { struct device *tmp; if (!dev) return NULL; tmp = get_device(&dev->dev); if (tmp) return to_of_device(tmp); else return NULL; }
int of_device_uevent(struct device *dev, struct kobj_uevent_env *env) { struct of_device *ofdev; const char *compat; int seen = 0, cplen, sl; if (!dev) return -ENODEV; ofdev = to_of_device(dev); if (add_uevent_var(env, "OF_NAME=%s", ofdev->dev.of_node->name)) return -ENOMEM; if (add_uevent_var(env, "OF_TYPE=%s", ofdev->dev.of_node->type)) return -ENOMEM; /* Since the compatible field can contain pretty much anything * it's not really legal to split it out with commas. We split it * up using a number of environment variables instead. */ compat = of_get_property(ofdev->dev.of_node, "compatible", &cplen); while (compat && *compat && cplen > 0) { if (add_uevent_var(env, "OF_COMPATIBLE_%d=%s", seen, compat)) return -ENOMEM; sl = strlen (compat) + 1; compat += sl; cplen -= sl; seen++; } if (add_uevent_var(env, "OF_COMPATIBLE_N=%d", seen)) return -ENOMEM; /* modalias is trickier, we add it in 2 steps */ if (add_uevent_var(env, "MODALIAS=")) return -ENOMEM; sl = of_device_get_modalias(ofdev, &env->buf[env->buflen-1], sizeof(env->buf) - env->buflen); if (sl >= (sizeof(env->buf) - env->buflen)) return -ENOMEM; env->buflen += sl; return 0; }
static int do_pd_setup(struct fs_enet_private *fep) { struct of_device *ofdev = to_of_device(fep->dev); fep->interrupt = of_irq_to_resource(ofdev->node, 0, NULL); if (fep->interrupt == NO_IRQ) return -EINVAL; fep->scc.sccp = of_iomap(ofdev->node, 0); if (!fep->scc.sccp) return -EINVAL; fep->scc.ep = of_iomap(ofdev->node, 1); if (!fep->scc.ep) { iounmap(fep->scc.sccp); return -EINVAL; } return 0; }
static int do_pd_setup(struct fs_enet_private *fep) { struct of_device *ofdev = to_of_device(fep->dev); struct fs_platform_info *fpi = fep->fpi; int ret = -EINVAL; fep->interrupt = of_irq_to_resource(ofdev->node, 0, NULL); if (fep->interrupt == NO_IRQ) goto out; fep->fcc.fccp = of_iomap(ofdev->node, 0); if (!fep->fcc.fccp) goto out; fep->fcc.ep = of_iomap(ofdev->node, 1); if (!fep->fcc.ep) goto out_fccp; fep->fcc.fcccp = of_iomap(ofdev->node, 2); if (!fep->fcc.fcccp) goto out_ep; fep->fcc.mem = (void __iomem *)cpm2_immr; fpi->dpram_offset = cpm_dpalloc(128, 8); if (IS_ERR_VALUE(fpi->dpram_offset)) { ret = fpi->dpram_offset; goto out_fcccp; } return 0; out_fcccp: iounmap(fep->fcc.fcccp); out_ep: iounmap(fep->fcc.ep); out_fccp: iounmap(fep->fcc.fccp); out: return ret; }
static int of_platform_device_probe(struct device *dev) { int error = -ENODEV; struct of_platform_driver *drv; struct of_device *of_dev; const struct of_device_id *match; drv = to_of_platform_driver(dev->driver); of_dev = to_of_device(dev); if (!drv->probe) return error; of_dev_get(of_dev); match = of_match_device(drv->match_table, of_dev); if (match) error = drv->probe(of_dev, match); if (error) of_dev_put(of_dev); return error; }
static void __init build_device_resources(struct of_device *op, struct device *parent) { struct of_device *p_op; struct of_bus *bus; int na, ns; int index, num_reg; const void *preg; if (!parent) return; p_op = to_of_device(parent); bus = of_match_bus(p_op->node); bus->count_cells(op->node, &na, &ns); preg = of_get_property(op->node, bus->addr_prop_name, &num_reg); if (!preg || num_reg == 0) return; /* Convert to num-cells. */ num_reg /= 4; /* Conver to num-entries. */ num_reg /= na + ns; for (index = 0; index < num_reg; index++) { struct resource *r = &op->resource[index]; u32 addr[OF_MAX_ADDR_CELLS]; const u32 *reg = (preg + (index * ((na + ns) * 4))); struct device_node *dp = op->node; struct device_node *pp = p_op->node; struct of_bus *pbus, *dbus; u64 size, result = OF_BAD_ADDR; unsigned long flags; int dna, dns; int pna, pns; size = of_read_addr(reg + na, ns); flags = bus->get_flags(reg); memcpy(addr, reg, na * 4); /* If the immediate parent has no ranges property to apply, * just use a 1<->1 mapping. */ if (of_find_property(pp, "ranges", NULL) == NULL) { result = of_read_addr(addr, na); goto build_res; } dna = na; dns = ns; dbus = bus; while (1) { dp = pp; pp = dp->parent; if (!pp) { result = of_read_addr(addr, dna); break; } pbus = of_match_bus(pp); pbus->count_cells(dp, &pna, &pns); if (build_one_resource(dp, dbus, pbus, addr, dna, dns, pna)) break; dna = pna; dns = pns; dbus = pbus; } build_res: memset(r, 0, sizeof(*r)); if (of_resource_verbose) printk("%s reg[%d] -> %llx\n", op->node->full_name, index, result); if (result != OF_BAD_ADDR) { r->start = result & 0xffffffff; r->end = result + size - 1; r->flags = flags | ((result >> 32ULL) & 0xffUL); } r->name = op->node->name; }
static inline struct iommu_table *device_to_table(struct device *hwdev) { struct of_device *ofdev = to_of_device(hwdev); return hwdev ? ofdev->iommu : NULL; }
static inline unsigned long device_to_mask(struct device *hwdev) { struct of_device *ofdev = to_of_device(hwdev); return ofdev->dma_mask; }
int nwpserial_register_port(struct uart_port *port) { struct nwpserial_port *up = NULL; int ret = -1; int i; static int first = 1; int dcr_len; int dcr_base; struct device_node *dn; mutex_lock(&nwpserial_mutex); dn = to_of_device(port->dev)->dev.of_node; if (dn == NULL) goto out; /* get dcr base. */ dcr_base = dcr_resource_start(dn, 0); /* find matching entry */ for (i = 0; i < NWPSERIAL_NR; i++) if (nwpserial_ports[i].port.iobase == dcr_base) { up = &nwpserial_ports[i]; break; } /* we didn't find a mtching entry, search for a free port */ if (up == NULL) for (i = 0; i < NWPSERIAL_NR; i++) if (nwpserial_ports[i].port.type == PORT_UNKNOWN && nwpserial_ports[i].port.iobase == 0) { up = &nwpserial_ports[i]; break; } if (up == NULL) { ret = -EBUSY; goto out; } if (first) uart_register_driver(&nwpserial_reg); first = 0; up->port.membase = port->membase; up->port.irq = port->irq; up->port.uartclk = port->uartclk; up->port.fifosize = port->fifosize; up->port.regshift = port->regshift; up->port.iotype = port->iotype; up->port.flags = port->flags; up->port.mapbase = port->mapbase; up->port.private_data = port->private_data; if (port->dev) up->port.dev = port->dev; if (up->port.iobase != dcr_base) { up->port.ops = &nwpserial_pops; up->port.fifosize = 16; spin_lock_init(&up->port.lock); up->port.iobase = dcr_base; dcr_len = dcr_resource_len(dn, 0); up->dcr_host = dcr_map(dn, dcr_base, dcr_len); if (!DCR_MAP_OK(up->dcr_host)) { printk(KERN_ERR "Cannot map DCR resources for NWPSERIAL"); goto out; } } ret = uart_add_one_port(&nwpserial_reg, &up->port); if (ret == 0) ret = up->port.line; out: mutex_unlock(&nwpserial_mutex); return ret; }
static int of_dev_phandle_match(struct device *dev, void *data) { phandle *ph = data; return to_of_device(dev)->node->linux_phandle == *ph; }
static int of_dev_node_match(struct device *dev, void *data) { return to_of_device(dev)->node == data; }
static int __devinit bw2_probe(struct of_device *dev, const struct of_device_id *match) { struct of_device *op = to_of_device(&dev->dev); return bw2_init_one(op); }