static int gswip_gphy_fw_list(struct gswip_priv *priv, struct device_node *gphy_fw_list_np, u32 version) { struct device *dev = priv->dev; struct device_node *gphy_fw_np; const struct of_device_id *match; int err; int i = 0; /* The VRX200 rev 1.1 uses the GSWIP 2.0 and needs the older * GPHY firmware. The VRX200 rev 1.2 uses the GSWIP 2.1 and also * needs a different GPHY firmware. */ if (of_device_is_compatible(gphy_fw_list_np, "lantiq,xrx200-gphy-fw")) { switch (version) { case GSWIP_VERSION_2_0: priv->gphy_fw_name_cfg = &xrx200a1x_gphy_data; break; case GSWIP_VERSION_2_1: priv->gphy_fw_name_cfg = &xrx200a2x_gphy_data; break; default: dev_err(dev, "unknown GSWIP version: 0x%x", version); return -ENOENT; } } match = of_match_node(xway_gphy_match, gphy_fw_list_np); if (match && match->data) priv->gphy_fw_name_cfg = match->data; if (!priv->gphy_fw_name_cfg) { dev_err(dev, "GPHY compatible type not supported"); return -ENOENT; } priv->num_gphy_fw = of_get_available_child_count(gphy_fw_list_np); if (!priv->num_gphy_fw) return -ENOENT; priv->rcu_regmap = syscon_regmap_lookup_by_phandle(gphy_fw_list_np, "lantiq,rcu"); if (IS_ERR(priv->rcu_regmap)) return PTR_ERR(priv->rcu_regmap); priv->gphy_fw = devm_kmalloc_array(dev, priv->num_gphy_fw, sizeof(*priv->gphy_fw), GFP_KERNEL | __GFP_ZERO); if (!priv->gphy_fw) return -ENOMEM; for_each_available_child_of_node(gphy_fw_list_np, gphy_fw_np) { err = gswip_gphy_fw_probe(priv, &priv->gphy_fw[i], gphy_fw_np, i); if (err) goto remove_gphy; i++; }
struct ion_platform_data *ion_parse_dt(struct platform_device *pdev, struct ion_of_heap *compatible) { int num_heaps, ret; const struct device_node *dt_node = pdev->dev.of_node; struct device_node *node; struct ion_platform_heap *heaps; struct ion_platform_data *data; int i = 0; num_heaps = of_get_available_child_count(dt_node); if (!num_heaps) return ERR_PTR(-EINVAL); heaps = devm_kzalloc(&pdev->dev, sizeof(struct ion_platform_heap) * num_heaps, GFP_KERNEL); if (!heaps) return ERR_PTR(-ENOMEM); data = devm_kzalloc(&pdev->dev, sizeof(struct ion_platform_data), GFP_KERNEL); if (!data) return ERR_PTR(-ENOMEM); for_each_available_child_of_node(dt_node, node) { struct platform_device *heap_pdev; ret = ion_parse_dt_heap_common(node, &heaps[i], compatible); if (ret) return ERR_PTR(ret); heap_pdev = of_platform_device_create(node, heaps[i].name, &pdev->dev); if (!heap_pdev) return ERR_PTR(-ENOMEM); heap_pdev->dev.platform_data = &heaps[i]; heaps[i].priv = &heap_pdev->dev; ret = ion_setup_heap_common(pdev, node, &heaps[i]); if (ret) goto out_err; i++; } data->heaps = heaps; data->nr = num_heaps; return data; out_err: for ( ; i >= 0; i--) if (heaps[i].priv) of_device_unregister(to_platform_device(heaps[i].priv)); return ERR_PTR(ret); }
void __init device_tree_init(void) { struct device_node *np; unflatten_and_copy_device_tree(); /* Disable SMP boot unless both CPUs are listed in DT and !disabled */ np = of_find_node_by_name(NULL, "cpus"); if (np && of_get_available_child_count(np) <= 1) bmips_smp_enabled = 0; of_node_put(np); }
static int pm8xxx_xoadc_parse_channels(struct pm8xxx_xoadc *adc, struct device_node *np) { struct device_node *child; struct pm8xxx_chan_info *ch; int ret; int i; adc->nchans = of_get_available_child_count(np); if (!adc->nchans) { dev_err(adc->dev, "no channel children\n"); return -ENODEV; } dev_dbg(adc->dev, "found %d ADC channels\n", adc->nchans); adc->iio_chans = devm_kcalloc(adc->dev, adc->nchans, sizeof(*adc->iio_chans), GFP_KERNEL); if (!adc->iio_chans) return -ENOMEM; adc->chans = devm_kcalloc(adc->dev, adc->nchans, sizeof(*adc->chans), GFP_KERNEL); if (!adc->chans) return -ENOMEM; i = 0; for_each_available_child_of_node(np, child) { ch = &adc->chans[i]; ret = pm8xxx_xoadc_parse_channel(adc->dev, child, adc->variant->channels, &adc->iio_chans[i], ch); if (ret) { of_node_put(child); return ret; } i++; }