[PATCH 1/2] PowerPC: Add 44x NDFC device-tree aware support
Stephen Rothwell
sfr at canb.auug.org.au
Sat Oct 27 13:37:34 EST 2007
On Fri, 26 Oct 2007 20:39:58 +0400 Valentine Barshak <vbarshak at ru.mvista.com> wrote:
>
> +static int __devinit parse_partitions(struct of_ndfc *ndfc,
> + struct of_device *dev)
> +{
> + const char *partname;
> + static const char *part_probe_types[]
> + = { "cmdlinepart", "RedBoot", NULL };
> + struct device_node *dp = dev->node, *pp;
> + int nr_parts, i;
> +
> + /* First look for RedBoot table or partitions on the command
> + * line, these take precedence over device tree information */
> + nr_parts = parse_mtd_partitions(&ndfc->mtd, part_probe_types,
> + &ndfc->parts, 0);
> + if (nr_parts > 0) {
> + add_mtd_partitions(&ndfc->mtd, ndfc->parts, nr_parts);
> + return 0;
> + }
> +
> + /* First count the subnodes */
> + nr_parts = 0;
> + for (pp = dp->child; pp; pp = pp->sibling)
For proper ref counting and locking, use:
for (pp = of_get_next_child(dp, NULL); pp;
pp = of_get_next_child(dp, pp))
> + nr_parts++;
> +
> + if (nr_parts == 0)
> + return 0;
> +
> + ndfc->parts = kzalloc(nr_parts * sizeof(*ndfc->parts),
> + GFP_KERNEL);
> + if (!ndfc->parts)
> + return -ENOMEM;
> +
> + for (pp = dp->child, i = 0; pp; pp = pp->sibling, i++) {
for (pp = of_get_next_child(dp, NULL), i = 0; pp;
pp = of_get_next_child(dp, pp), i++)
> + const u32 *reg;
> + int len;
> +
> + reg = of_get_property(pp, "reg", &len);
> + if (!reg || (len != 2*sizeof(u32))) {
of_node_put(pp);
> + dev_err(&dev->dev, "Invalid 'reg' on %s\n",
> + dp->full_name);
> + kfree(ndfc->parts);
> + ndfc->parts = NULL;
> + return -EINVAL;
> + }
> + ndfc->parts[i].offset = reg[0];
> + ndfc->parts[i].size = reg[1];
> +
> + partname = of_get_property(pp, "label", &len);
> + if (!partname)
> + partname = of_get_property(pp, "name", &len);
> + ndfc->parts[i].name = (char *)partname;
> +
> + if (of_get_property(pp, "read-only", &len))
> + ndfc->parts[i].mask_flags = MTD_WRITEABLE;
> + }
> +
> + return nr_parts;
> +}
> +#else /* MTD_PARTITIONS */
> +#define OF_FLASH_PARTS(ndfc) (0)
> +#define parse_partitions(ndfc, dev) (0)
static inline int parse_partitions(struct of_ndfc *ndfc, struct of_device *dev)
{
return 0;
}
> +#endif /* MTD_PARTITIONS */
> +static int __devinit of_ndfc_probe(struct of_device *dev,
> + const struct of_device_id *match)
> +{
> + struct device_node *dp = dev->node;
> + struct resource res;
> + struct of_ndfc *ndfc;
> + const u32 *prop;
> + resource_size_t rlen;
> + int err;
> +
> + err = -ENXIO;
> + if (of_address_to_resource(dp, 0, &res)) {
> + dev_err(&dev->dev, "can't get IO address from device tree\n");
> + goto err_out;
> + }
> +
> + dev_dbg(&dev->dev, "regs: %.8llx-%.8llx\n",
indentation ?
--
Cheers,
Stephen Rothwell sfr at canb.auug.org.au
http://www.canb.auug.org.au/~sfr/
-------------- next part --------------
A non-text attachment was scrubbed...
Name: not available
Type: application/pgp-signature
Size: 189 bytes
Desc: not available
URL: <http://lists.ozlabs.org/pipermail/linuxppc-dev/attachments/20071027/0b5aba62/attachment.pgp>
More information about the Linuxppc-dev
mailing list