Re: [PATCH 19 4/5] Convert PowerPC MPC i2c to of_platform_driverfrom platform_driver
From: Stephen Rothwell
Date: Fri Jan 11 2008 - 23:07:53 EST
Hi Jon,
On Fri, 11 Jan 2008 21:47:46 -0500 Jon Smirl <jonsmirl@xxxxxxxxx> wrote:
>
> +++ b/drivers/i2c/busses/i2c-mpc.c
> +static void of_register_i2c_devices(struct i2c_adapter *adap, struct device_node *adap_node)
> +{
> + struct device_node *node = NULL;
> +
> + while ((node = of_get_next_child(adap_node, node))) {
We have for_each_child_of_node(adap_node, node) now for this (and it
means you don't need to initialize the "node" above).
> + struct i2c_board_info info;
> + const u32 *addr;
> + const char *compatible;
> + int len;
> +
> + addr = of_get_property(node, "reg", &len);
> + if (!addr || len < sizeof(int) || *addr > (1 << 10) - 1) {
> + printk(KERN_ERR "i2c-mpc.c: invalid entry, missing reg attribute\n");
> + continue;
> + }
> +
> + info.irq = irq_of_parse_and_map(node, 0);
> + if (info.irq == NO_IRQ)
> + info.irq = -1;
> +
> + compatible = of_get_property(node, "compatible", &len);
> + if (!compatible) {
> + printk(KERN_ERR "i2c-mpc.c: invalid entry, missing compatible attribute\n");
> + continue;
You may need to clean up from the irq_of_pase_and_map().
> + }
> +
> + /* need full alias i2c:NOF,vendor,device */
> + strcpy(info.type, I2C_OF_MODULE_PREFIX);
> + strncat(info.type, compatible, sizeof(info.type));
> + request_module(info.type);
> +
> + /* need module alias OF,vendor,device */
> + strcpy(info.type, OF_I2C_PREFIX);
> + strncat(info.type, compatible, sizeof(info.type));
> +
> + info.driver_name[0] = '\0';
> + info.platform_data = NULL;
> + info.addr = *addr;
> +
> + if (!i2c_new_device(adap, &info)) {
> + printk(KERN_ERR "i2c-mpc.c: Failed to load driver for %s\n", info.type);
> + continue;
And again.
> + }
> + }
> +}
> +
> +static int mpc_i2c_probe(struct of_device *op, const struct of_device_id *match)
> +{
> + dev_set_drvdata(&op->dev, i2c);
> +
> + i2c->adap = mpc_ops;
> + i2c_set_adapdata(&i2c->adap, i2c);
> + i2c->adap.dev.parent = &op->dev;
> +
> + result = i2c_add_adapter(&i2c->adap);
> + if (result < 0) {
> + printk(KERN_ERR "i2c-mpc - failed to add adapter\n");
> + goto fail_add;
> + }
> +
> + of_register_i2c_devices(&i2c->adap, op->node);
> +
> + return result;
> +
> +fail_add:
dev_set_dvdata(&op->dev, NULL);
> + free_irq(i2c->irq, i2c);
> +fail_request:
> + irq_dispose_mapping(i2c->irq);
> +fail_irq:
> + iounmap(i2c->base);
> +fail_map:
> + kfree(i2c);
> + return result;
> +};
> +static struct of_device_id mpc_i2c_of_match[] = {
const, please.
--
Cheers,
Stephen Rothwell sfr@xxxxxxxxxxxxxxxx
http://www.canb.auug.org.au/~sfr/
Attachment:
pgp00000.pgp
Description: PGP signature