int bldr_log_init(void) { struct device_node *np; struct resource temp_res; int num_reg = 0; np = of_find_compatible_node(NULL, NULL, RAMLOG_COMPATIBLE_NAME); if (np) { if (of_can_translate_address(np)) { while (of_address_to_resource(np, num_reg, &temp_res) == 0) { if (!strcmp(temp_res.name, RAMLOG_LAST_RSE_NAME)) bldr_log_setup(temp_res.start, resource_size(&temp_res), true); else if (!strcmp(temp_res.name, RAMLOG_CUR_RSE_NAME)) bldr_log_setup(temp_res.start, resource_size(&temp_res), false); else pr_warn("%s: unknown bldr resource %s\n", __func__, temp_res.name); num_reg++; } if (!num_reg) pr_warn("%s: can't find address resource\n", __func__); } else pr_warn("%s: translate address fail\n", __func__); } else pr_warn("%s: can't find compatible '%s'\n", __func__, RAMLOG_COMPATIBLE_NAME); return num_reg; }
/** * of_device_make_bus_id - Use the device node data to assign a unique name * @dev: pointer to device structure that is linked to a device tree node * * This routine will first try using either the dcr-reg or the reg property * value to derive a unique name. As a last resort it will use the node * name followed by a unique number. */ void of_device_make_bus_id(struct device *dev) { static atomic_t bus_no_reg_magic; struct device_node *node = dev->of_node; const __be32 *reg; u64 addr; const __be32 *addrp; int magic; #ifdef CONFIG_PPC_DCR /* * If it's a DCR based device, use 'd' for native DCRs * and 'D' for MMIO DCRs. */ reg = of_get_property(node, "dcr-reg", NULL); if (reg) { #ifdef CONFIG_PPC_DCR_NATIVE dev_set_name(dev, "d%x.%s", *reg, node->name); #else /* CONFIG_PPC_DCR_NATIVE */ u64 addr = of_translate_dcr_address(node, *reg, NULL); if (addr != OF_BAD_ADDR) { dev_set_name(dev, "D%llx.%s", (unsigned long long)addr, node->name); return; } #endif /* !CONFIG_PPC_DCR_NATIVE */ } #endif /* CONFIG_PPC_DCR */ /* * For MMIO, get the physical address */ reg = of_get_property(node, "reg", NULL); if (reg) { if (of_can_translate_address(node)) { addr = of_translate_address(node, reg); } else { addrp = of_get_address(node, 0, NULL, NULL); if (addrp) addr = of_read_number(addrp, 1); else addr = OF_BAD_ADDR; } if (addr != OF_BAD_ADDR) { dev_set_name(dev, "%llx.%s", (unsigned long long)addr, node->name); return; } } /* * No BusID, use the node name and add a globally incremented * counter (and pray...) */ magic = atomic_add_return(1, &bus_no_reg_magic); dev_set_name(dev, "%s.%d", node->name, magic - 1); }
/** * of_device_alloc - Allocate and initialize an of_device * @np: device node to assign to device * @bus_id: Name to assign to the device. May be null to use default name. * @parent: Parent device. */ struct platform_device *of_device_alloc(struct device_node *np, const char *bus_id, struct device *parent) { struct platform_device *dev; int rc, i, num_reg = 0, num_irq; struct resource *res, temp_res; dev = platform_device_alloc("", -1); if (!dev) return NULL; /* count the io and irq resources */ if (of_can_translate_address(np)) while (of_address_to_resource(np, num_reg, &temp_res) == 0) num_reg++; num_irq = of_irq_count(np); /* Populate the resource table */ if (num_irq || num_reg) { res = kzalloc(sizeof(*res) * (num_irq + num_reg), GFP_KERNEL); if (!res) { platform_device_put(dev); return NULL; } dev->num_resources = num_reg + num_irq; dev->resource = res; for (i = 0; i < num_reg; i++, res++) { rc = of_address_to_resource(np, i, res); WARN_ON(rc); } WARN_ON(of_irq_to_resource_table(np, res, num_irq) != num_irq); } dev->dev.of_node = of_node_get(np); #if defined(CONFIG_MICROBLAZE) dev->dev.dma_mask = &dev->archdata.dma_mask; #endif dev->dev.parent = parent; if (bus_id) dev_set_name(&dev->dev, "%s", bus_id); else of_device_make_bus_id(&dev->dev); return dev; }
void of_device_make_bus_id(struct device *dev) { static atomic_t bus_no_reg_magic; struct device_node *node = dev->of_node; const u32 *reg; u64 addr; const __be32 *addrp; int magic; #ifdef CONFIG_PPC_DCR reg = of_get_property(node, "dcr-reg", NULL); if (reg) { #ifdef CONFIG_PPC_DCR_NATIVE dev_set_name(dev, "d%x.%s", *reg, node->name); #else u64 addr = of_translate_dcr_address(node, *reg, NULL); if (addr != OF_BAD_ADDR) { dev_set_name(dev, "D%llx.%s", (unsigned long long)addr, node->name); return; } #endif } #endif reg = of_get_property(node, "reg", NULL); if (reg) { if (of_can_translate_address(node)) { addr = of_translate_address(node, reg); } else { addrp = of_get_address(node, 0, NULL, NULL); if (addrp) addr = of_read_number(addrp, 1); else addr = OF_BAD_ADDR; } if (addr != OF_BAD_ADDR) { dev_set_name(dev, "%llx.%s", (unsigned long long)addr, node->name); return; } } magic = atomic_add_return(1, &bus_no_reg_magic); dev_set_name(dev, "%s.%d", node->name, magic - 1); }
/** * of_device_make_bus_id - Use the device node data to assign a unique name * @dev: pointer to device structure that is linked to a device tree node * * This routine will first try using either the dcr-reg or the reg property * value to derive a unique name. As a last resort it will use the node * name followed by a unique number. */ static void of_device_make_bus_id(struct device_d *dev) { static int bus_no_reg_magic; struct device_node *np = dev->device_node; const __be32 *reg, *addrp; u64 addr; char *name, *at; name = xstrdup(np->name); at = strchr(name, '@'); if (at) *at = '\0'; #ifdef CONFIG_PPC_DCR /* * If it's a DCR based device, use 'd' for native DCRs * and 'D' for MMIO DCRs. */ reg = of_get_property(np, "dcr-reg", NULL); if (reg) { #ifdef CONFIG_PPC_DCR_NATIVE snprintf(dev->name, MAX_DRIVER_NAME, "d%x.%s", *reg, name); #else /* CONFIG_PPC_DCR_NATIVE */ u64 addr = of_translate_dcr_address(np, *reg, NULL); if (addr != OF_BAD_ADDR) { snprintf(dev->name, MAX_DRIVER_NAME, "D%llx.%s", (unsigned long long)addr, name); free(name); return; } #endif /* !CONFIG_PPC_DCR_NATIVE */ } #endif /* CONFIG_PPC_DCR */ /* * For MMIO, get the physical address */ reg = of_get_property(np, "reg", NULL); if (reg) { if (of_can_translate_address(np)) { addr = of_translate_address(np, reg); } else { addrp = of_get_address(np, 0, NULL, NULL); if (addrp) addr = of_read_number(addrp, 1); else addr = OF_BAD_ADDR; } if (addr != OF_BAD_ADDR) { snprintf(dev->name, MAX_DRIVER_NAME, "%llx.%s", (unsigned long long)addr, name); free(name); return; } } /* * No BusID, use the node name and add a globally incremented counter */ snprintf(dev->name, MAX_DRIVER_NAME, "%s.%d", name, bus_no_reg_magic++); free(name); }
/** * of_platform_device_create - Alloc, initialize and register an of_device * @np: pointer to node to create device for * @parent: device model parent device. * * Returns pointer to created platform device, or NULL if a device was not * registered. Unavailable devices will not get registered. */ static struct device_d *of_platform_device_create(struct device_node *np, struct device_d *parent) { struct device_d *dev; struct resource *res = NULL, temp_res; int i, j, ret, num_reg = 0, match; if (!of_device_is_available(np)) return NULL; /* count the io resources */ if (of_can_translate_address(np)) while (of_address_to_resource(np, num_reg, &temp_res) == 0) num_reg++; /* Populate the resource table */ if (num_reg) { res = xzalloc(sizeof(*res) * num_reg); for (i = 0; i < num_reg; i++) { ret = of_address_to_resource(np, i, &res[i]); if (ret) { free(res); return NULL; } } /* * A device may already be registered as platform_device. * Instead of registering the same device again, just * add this node to the existing device. */ for_each_device(dev) { if (!dev->resource) continue; for (i = 0, match = 0; i < num_reg; i++) for (j = 0; j < dev->num_resources; j++) if (dev->resource[j].start == res[i].start && dev->resource[j].end == res[i].end) { match++; break; } /* check if all address resources match */ if (match == num_reg) { debug("connecting %s to %s\n", np->name, dev_name(dev)); dev->device_node = np; free(res); return dev; } } } /* setup generic device info */ dev = xzalloc(sizeof(*dev)); dev->id = DEVICE_ID_SINGLE; dev->device_node = np; dev->parent = parent; dev->resource = res; dev->num_resources = num_reg; of_device_make_bus_id(dev); debug("%s: register device %s, io=" PRINTF_CONVERSION_RESOURCE "\n", __func__, dev_name(dev), (num_reg) ? dev->resource[0].start : (-1)); ret = platform_device_register(dev); if (!ret) return dev; free(dev); if (num_reg) free(res); return NULL; }