static int msm_vidc_load_bus_vectors(struct msm_vidc_platform_resources *res) { struct platform_device *pdev = res->pdev; struct device_node *child_node, *bus_node; struct bus_set *buses = &res->bus_set; int rc = 0, c = 0; u32 num_buses = 0; bus_node = of_find_node_by_name(pdev->dev.of_node, "qcom,msm-bus-clients"); if (!bus_node) { /* Not a required property */ dprintk(VIDC_DBG, "qcom,msm-bus-clients not found\n"); rc = 0; goto err_bad_node; } for_each_child_of_node(bus_node, child_node) ++num_buses; buses->bus_tbl = devm_kzalloc(&pdev->dev, sizeof(*buses->bus_tbl) * num_buses, GFP_KERNEL); if (!buses->bus_tbl) { dprintk(VIDC_ERR, "%s: Failed to allocate memory\n", __func__); rc = -ENOMEM; goto err_bad_node; } buses->count = num_buses; c = 0; for_each_child_of_node(bus_node, child_node) { bool passive = false; bool low_power = false; u32 configs = 0; struct bus_info *bus = &buses->bus_tbl[c]; passive = of_property_read_bool(child_node, "qcom,bus-passive"); low_power = of_property_read_bool(child_node, "qcom,bus-low-power"); rc = of_property_read_u32(child_node, "qcom,bus-configs", &configs); if (rc) { dprintk(VIDC_ERR, "Failed to read qcom,bus-configs in %s: %d\n", child_node->name, rc); break; } bus->passive = passive; bus->low_power = low_power; bus->sessions_supported = configs; bus->pdata = msm_bus_pdata_from_node(pdev, child_node); if (IS_ERR_OR_NULL(bus->pdata)) { rc = PTR_ERR(bus->pdata) ?: -EBADHANDLE; dprintk(VIDC_ERR, "Failed to get bus pdata: %d\n", rc); break; }
static inline int of_get_child_count(const struct device_node *np) { struct device_node *child; int num = 0; for_each_child_of_node(np, child) num++; return num; }
static struct samsung_keypad_platdata *samsung_keypad_parse_dt( struct device *dev) { struct samsung_keypad_platdata *pdata; struct matrix_keymap_data *keymap_data; uint32_t *keymap, num_rows = 0, num_cols = 0; struct device_node *np = dev->of_node, *key_np; unsigned int key_count = 0; pdata = devm_kzalloc(dev, sizeof(*pdata), GFP_KERNEL); if (!pdata) { dev_err(dev, "could not allocate memory for platform data\n"); return NULL; } of_property_read_u32(np, "samsung,keypad-num-rows", &num_rows); of_property_read_u32(np, "samsung,keypad-num-columns", &num_cols); if (!num_rows || !num_cols) { dev_err(dev, "number of keypad rows/columns not specified\n"); return NULL; } pdata->rows = num_rows; pdata->cols = num_cols; keymap_data = devm_kzalloc(dev, sizeof(*keymap_data), GFP_KERNEL); if (!keymap_data) { dev_err(dev, "could not allocate memory for keymap data\n"); return NULL; } pdata->keymap_data = keymap_data; for_each_child_of_node(np, key_np) key_count++; keymap_data->keymap_size = key_count; keymap = devm_kzalloc(dev, sizeof(uint32_t) * key_count, GFP_KERNEL); if (!keymap) { dev_err(dev, "could not allocate memory for keymap\n"); return NULL; } keymap_data->keymap = keymap; for_each_child_of_node(np, key_np) { u32 row, col, key_code; of_property_read_u32(key_np, "keypad,row", &row); of_property_read_u32(key_np, "keypad,column", &col); of_property_read_u32(key_np, "linux,code", &key_code); *keymap++ = KEY(row, col, key_code); }
int __devinit mc13xxx_get_num_regulators_dt(struct platform_device *pdev) { struct device_node *parent, *child; int num = 0; of_node_get(pdev->dev.parent->of_node); parent = of_find_node_by_name(pdev->dev.parent->of_node, "regulators"); if (!parent) return -ENODEV; for_each_child_of_node(parent, child) num++; return num; }
static int mbigen_device_probe(struct platform_device *pdev) { struct mbigen_device *mgn_chip; struct resource *res; mgn_chip = devm_kzalloc(&pdev->dev, sizeof(*mgn_chip), GFP_KERNEL); if (!mgn_chip) return -ENOMEM; mgn_chip->pdev = pdev; res = platform_get_resource(pdev, IORESOURCE_MEM, 0); mgn_chip->base = devm_ioremap(&pdev->dev, res->start, resource_size(res)); if (IS_ERR(mgn_chip->base)) return PTR_ERR(mgn_chip->base); if (IS_ENABLED(CONFIG_OF) && pdev->dev.of_node) { struct device_node *np; for_each_child_of_node(pdev->dev.of_node, np) mbigen_create_domain(mgn_chip, np); } else if (ACPI_COMPANION(&pdev->dev)) { struct irq_domain *domain; u32 num_pins; if (device_property_read_u32(&pdev->dev, "num-pins", &num_pins) < 0) return -EINVAL; domain = platform_msi_create_device_domain(&pdev->dev, num_pins, mbigen_write_msg, &mbigen_domain_ops, mgn_chip); if (!domain) return -ENOMEM; dev_info(&pdev->dev, "domain created, Allocated %d MSIs\n", num_pins); } platform_set_drvdata(pdev, mgn_chip); return 0; }
static int msm_iommu_parse_dt(struct platform_device *pdev, struct msm_iommu_drvdata *drvdata) { struct device_node *child; int ret = 0; struct resource *r; drvdata->dev = &pdev->dev; ret = __get_bus_vote_client(pdev, drvdata); if (ret) goto fail; ret = msm_iommu_parse_bfb_settings(pdev, drvdata); if (ret) goto fail; for_each_child_of_node(pdev->dev.of_node, child) drvdata->ncb++; drvdata->asid = devm_kzalloc(&pdev->dev, drvdata->ncb * sizeof(int), GFP_KERNEL); if (!drvdata->asid) { pr_err("Unable to get memory for asid array\n"); ret = -ENOMEM; goto fail; } ret = of_property_read_string(pdev->dev.of_node, "label", &drvdata->name); if (ret) goto fail; drvdata->sec_id = -1; get_secure_id(pdev->dev.of_node, drvdata); r = platform_get_resource_byname(pdev, IORESOURCE_MEM, "clk_base"); if (r) { drvdata->clk_reg_virt = devm_ioremap(&pdev->dev, r->start, resource_size(r)); if (!drvdata->clk_reg_virt) { pr_err("Failed to map resource for iommu clk: %pr\n", r); ret = -ENOMEM; goto fail; } } drvdata->halt_enabled = of_property_read_bool(pdev->dev.of_node, "qcom,iommu-enable-halt"); ret = of_platform_populate(pdev->dev.of_node, msm_iommu_ctx_match_table, NULL, &pdev->dev); if (ret) { pr_err("Failed to create iommu context device\n"); goto fail; } msm_iommu_add_drv(drvdata); return 0; fail: __put_bus_vote_client(drvdata); return ret; }
static struct ion_platform_data *sprd_ion_parse_dt(struct platform_device *pdev) { int i = 0, ret = 0; const struct device_node *parent = pdev->dev.of_node; struct device_node *child = NULL; struct ion_platform_data *pdata = NULL; struct ion_platform_heap *ion_heaps = NULL; struct platform_device *new_dev = NULL; uint32_t val = 0, type = 0; const char *name; uint32_t out_values[2]; for_each_child_of_node(parent, child) num_heaps++; if (!num_heaps) return ERR_PTR(-EINVAL); pr_info("%s: num_heaps=%d\n", __func__, num_heaps); pdata = kzalloc(sizeof(struct ion_platform_data), GFP_KERNEL); if (!pdata) return ERR_PTR(-ENOMEM); ion_heaps = kzalloc(sizeof(struct ion_platform_heap)*num_heaps, GFP_KERNEL); if (!ion_heaps) { kfree(pdata); return ERR_PTR(-ENOMEM); } pdata->heaps = ion_heaps; pdata->nr = num_heaps; for_each_child_of_node(parent, child) { new_dev = of_platform_device_create(child, NULL, &pdev->dev); if (!new_dev) { pr_err("Failed to create device %s\n", child->name); goto out; } pdata->heaps[i].priv = &new_dev->dev; ret = of_property_read_u32(child, "reg", &val); if (ret) { pr_err("%s: Unable to find reg key, ret=%d", __func__, ret); goto out; } pdata->heaps[i].id = val; ret = of_property_read_string(child, "reg-names", &name); if (ret) { pr_err("%s: Unable to find reg-names key, ret=%d", __func__, ret); goto out; } pdata->heaps[i].name = name; ret = of_property_read_u32(child, "sprd,ion-heap-type", &type); if (ret) { pr_err("%s: Unable to find ion-heap-type key, ret=%d", __func__, ret); goto out; } pdata->heaps[i].type = type; ret = of_property_read_u32_array(child, "sprd,ion-heap-mem", out_values, 2); if (!ret) { pdata->heaps[i].base = out_values[0]; pdata->heaps[i].size = out_values[1]; } pr_info("%s: heaps[%d]: %s type: %d base: %lu size %u\n", __func__, i, pdata->heaps[i].name, pdata->heaps[i].type, pdata->heaps[i].base, pdata->heaps[i].size); ++i; }
static int simple_for_each_link(struct simple_priv *priv, struct link_info *li, int (*func_noml)(struct simple_priv *priv, struct device_node *np, struct device_node *codec, struct link_info *li, bool is_top), int (*func_dpcm)(struct simple_priv *priv, struct device_node *np, struct device_node *codec, struct link_info *li, bool is_top)) { struct device *dev = simple_priv_to_dev(priv); struct device_node *top = dev->of_node; struct device_node *node; uintptr_t dpcm_selectable = (uintptr_t)of_device_get_match_data(dev); bool is_top = 0; int ret = 0; /* Check if it has dai-link */ node = of_get_child_by_name(top, PREFIX "dai-link"); if (!node) { node = of_node_get(top); is_top = 1; } /* loop for all dai-link */ do { struct asoc_simple_card_data adata; struct device_node *codec; struct device_node *np; int num = of_get_child_count(node); /* get codec */ codec = of_get_child_by_name(node, is_top ? PREFIX "codec" : "codec"); if (!codec) { ret = -ENODEV; goto error; } of_node_put(codec); /* get convert-xxx property */ memset(&adata, 0, sizeof(adata)); for_each_child_of_node(node, np) simple_get_conversion(dev, np, &adata); /* loop for all CPU/Codec node */ for_each_child_of_node(node, np) { /* * It is DPCM * if it has many CPUs, * or has convert-xxx property */ if (dpcm_selectable && (num > 2 || adata.convert_rate || adata.convert_channels)) ret = func_dpcm(priv, np, codec, li, is_top); /* else normal sound */ else ret = func_noml(priv, np, codec, li, is_top); if (ret < 0) { of_node_put(np); goto error; } } node = of_get_next_child(top, node); } while (!is_top && node); error: of_node_put(node); return ret; }
static int hi6220_set_platform_data(struct platform_device *pdev) { unsigned int base; unsigned int size; unsigned int id; const char *heap_name; const char *type_name; enum ion_heap_type type; int ret; struct device_node *np; struct ion_platform_heap *p_data; const struct device_node *dt_node = pdev->dev.of_node; int index = 0; for_each_child_of_node(dt_node, np) num_heaps++; heaps_data = devm_kzalloc(&pdev->dev, sizeof(struct ion_platform_heap *) * num_heaps, GFP_KERNEL); if (!heaps_data) return -ENOMEM; for_each_child_of_node(dt_node, np) { ret = of_property_read_string(np, "heap-name", &heap_name); if (ret < 0) { pr_err("check the name of node %s\n", np->name); continue; } ret = of_property_read_u32(np, "heap-id", &id); if (ret < 0) { pr_err("check the id %s\n", np->name); continue; } ret = of_property_read_u32(np, "heap-base", &base); if (ret < 0) { pr_err("check the base of node %s\n", np->name); continue; } ret = of_property_read_u32(np, "heap-size", &size); if (ret < 0) { pr_err("check the size of node %s\n", np->name); continue; } ret = of_property_read_string(np, "heap-type", &type_name); if (ret < 0) { pr_err("check the type of node %s\n", np->name); continue; } ret = get_type_by_name(type_name, &type); if (ret < 0) { pr_err("type name error %s!\n", type_name); continue; } pr_info("heap index %d : name %s base 0x%x size 0x%x id %d type %d\n", index, heap_name, base, size, id, type); p_data = devm_kzalloc(&pdev->dev, sizeof(struct ion_platform_heap), GFP_KERNEL); if (!p_data) return -ENOMEM; p_data->name = heap_name; p_data->base = base; p_data->size = size; p_data->id = id; p_data->type = type; heaps_data[index] = p_data; index++; }