From: Jochen Friedrich <jochen@scram.de>
To: Jon Smirl <jonsmirl@gmail.com>
Cc: Scott Wood <scottwood@freescale.com>, linuxppc-dev@ozlabs.org
Subject: Re: [PATCH 4/5] Convert PowerPC MPC i2c to of_platform_driver from platform_driver
Date: Wed, 02 Jan 2008 20:41:44 +0100 [thread overview]
Message-ID: <477BE8F8.9030804@scram.de> (raw)
In-Reply-To: <20071220044144.20091.35917.stgit@terra.home>
Hi Jon,
> Convert MPC i2c driver from being a platform_driver to an open firmware version. Error returns were improved. Routine names were changed from fsl_ to mpc_ to make them match the file name
I did the same for my i2c-cpm. Tested with the frontprocessor driver (dbox2 specific) converted to new style. I'll post the new i2c-cpm, as well.
> +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))) {
> + 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;
> + }
> +
> + /* need full alias i2c:NOF,vendor,device */
> + strcpy(info.driver_name, I2C_OF_MODULE_PREFIX);
> + strncat(info.driver_name, compatible, sizeof(info.driver_name));
> + request_module(info.driver_name);
> +
> + /* need module alias OF,vendor,device */
> + strcpy(info.driver_name, OF_I2C_PREFIX);
> + strncat(info.driver_name, compatible, sizeof(info.driver_name));
> +
> + info.type[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.driver_name);
> + continue;
> + }
> + }
> +}
Should this go into some central file? Else we would have to copy it in any i2c bus driver that supports powerpc.
This would at least be i2c-cpm and i2c-gpio.
> +static int mpc_i2c_probe(struct of_device *op, const struct of_device_id *match)
> +{
> + int result = 0;
> + struct mpc_i2c *i2c;
> +
> + i2c = kzalloc(sizeof(*i2c), GFP_KERNEL);
> + if (!i2c)
> + return -ENOMEM;
> +
> + if (of_get_property(op->node, "dfsrr", NULL))
> + i2c->flags |= FSL_I2C_DEV_SEPARATE_DFSRR;
> +
> + if (of_device_is_compatible(op->node, "mpc5200-i2c"))
> + i2c->flags |= FSL_I2C_DEV_CLOCK_5200;
> +
> + init_waitqueue_head(&i2c->queue);
> +
> + i2c->base = of_iomap(op->node, 0);
> + if (!i2c->base) {
> + printk(KERN_ERR "i2c-mpc - failed to map controller\n");
> + result = -ENOMEM;
> + goto fail_map;
> + }
> +
> + i2c->irq = irq_of_parse_and_map(op->node, 0);
> + if (i2c->irq == NO_IRQ) {
> + result = -ENXIO;
> + goto fail_irq;
> + }
> +
> + result = request_irq(i2c->irq, mpc_i2c_isr, IRQF_SHARED, "i2c-mpc", i2c);
> + if (result < 0) {
> + printk(KERN_ERR "i2c-mpc - failed to attach interrupt\n");
> + goto fail_request;
> + }
> +
> + mpc_i2c_setclock(i2c);
> +
> + 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:
> + free_irq(i2c->irq, i2c);
> +fail_request:
> + irq_dispose_mapping(i2c->irq);
> +fail_irq:
> + iounmap(i2c->base);
> +fail_map:
> + kfree(i2c);
> + return result;
> +};
IMHO, there should be a node attribute to override i2c_adapter.class. Legacy i2c drivers (in particular v4l and dvb drivers) use this class to decide which adapter to bind to. dbox2 needs I2C_CLASS_TV_DIGITAL (4).
Thanks,
Jochen
next prev parent reply other threads:[~2008-01-02 19:40 UTC|newest]
Thread overview: 58+ messages / expand[flat|nested] mbox.gz Atom feed top
2007-12-20 4:41 [PATCH 0/5] Version 17, series to add device tree naming to i2c Jon Smirl
2007-12-20 4:41 ` [PATCH 1/5] Implement module aliasing for i2c to translate from device tree names Jon Smirl
2008-01-11 19:20 ` [i2c] " Jean Delvare
2008-01-11 19:20 ` Jean Delvare
2008-01-12 8:46 ` Jean Delvare
2008-01-12 8:46 ` Jean Delvare
2008-01-12 16:26 ` Jon Smirl
2008-01-13 14:41 ` Jean Delvare
2008-01-13 16:24 ` Jon Smirl
2008-01-13 17:40 ` Jean Delvare
2008-01-13 17:40 ` Jean Delvare
[not found] ` <20080113184017.7e3b409f-ig7AzVSIIG7kN2dkZ6Wm7A@public.gmane.org>
2008-01-13 18:01 ` Jon Smirl
2008-01-13 18:01 ` Jon Smirl
2008-01-13 18:01 ` Jon Smirl
2008-01-13 18:45 ` Jean Delvare
2008-01-13 18:45 ` Jean Delvare
[not found] ` <20080113194523.51683e97-ig7AzVSIIG7kN2dkZ6Wm7A@public.gmane.org>
2008-01-13 18:50 ` Jon Smirl
2008-01-13 18:50 ` Jon Smirl
2008-01-13 18:50 ` Jon Smirl
2008-01-13 19:05 ` Jean Delvare
2008-01-13 19:05 ` Jean Delvare
2007-12-20 4:41 ` [PATCH 2/5] Modify several rtc drivers to use the alias names list property of i2c Jon Smirl
2007-12-20 4:41 ` [PATCH 3/5] Clean up error returns Jon Smirl
2007-12-20 4:41 ` [PATCH 4/5] Convert PowerPC MPC i2c to of_platform_driver from platform_driver Jon Smirl
2007-12-20 5:16 ` David Gibson
2007-12-20 5:16 ` David Gibson
2007-12-20 6:01 ` Olof Johansson
2007-12-20 6:04 ` Stefan Roese
2007-12-20 6:04 ` Stefan Roese
2007-12-20 15:56 ` Jon Smirl
2008-01-02 19:41 ` Jochen Friedrich [this message]
2008-01-02 19:49 ` Jon Smirl
2007-12-20 4:41 ` [PATCH 5/5] Convert pfc8563 i2c driver from old style to new style Jon Smirl
2007-12-20 23:59 ` [PATCH 0/5] Version 17, series to add device tree naming to i2c Jon Smirl
2007-12-27 16:47 ` Jon Smirl
2007-12-28 12:14 ` Jean Delvare
2007-12-28 12:14 ` Jean Delvare
2007-12-28 12:14 ` Jean Delvare
[not found] ` <20071220044136.20091.70984.stgit-+J+k29bDNxlBDLzU/O5InQ@public.gmane.org>
2008-01-10 14:14 ` Jon Smirl
2008-01-10 14:14 ` Jon Smirl
[not found] ` <9e4733910801100614y7522a573qb2af41a714b08d5-JsoAwUIsXosN+BqQ9rBEUg@public.gmane.org>
2008-01-10 16:14 ` Jean Delvare
2008-01-10 16:14 ` Jean Delvare
2008-01-11 8:56 ` [i2c] " Jean Delvare
2008-01-11 8:56 ` Jean Delvare
2008-01-11 15:52 ` Jon Smirl
2008-01-11 15:52 ` Jon Smirl
2008-01-11 16:05 ` Jochen Friedrich
2008-01-11 19:15 ` Jean Delvare
2008-01-11 19:15 ` Jean Delvare
2008-01-11 20:16 ` Jon Smirl
2008-01-11 20:16 ` Jon Smirl
2008-01-12 9:08 ` Jean Delvare
2008-01-12 9:08 ` Jean Delvare
2008-01-12 16:00 ` Jon Smirl
2008-01-12 16:00 ` Jon Smirl
2008-01-13 15:09 ` Jean Delvare
2008-01-13 15:09 ` Jean Delvare
-- strict thread matches above, loose matches on Subject: below --
2007-12-10 18:33 [PATCH 0/5] Series " Jon Smirl
2007-12-10 18:33 ` [PATCH 4/5] Convert PowerPC MPC i2c to of_platform_driver from platform_driver Jon Smirl
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=477BE8F8.9030804@scram.de \
--to=jochen@scram.de \
--cc=jonsmirl@gmail.com \
--cc=linuxppc-dev@ozlabs.org \
--cc=scottwood@freescale.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.