From: grant.likely@secretlab.ca (Grant Likely)
To: linux-arm-kernel@lists.infradead.org
Subject: [PATCH 6/7] i2c: pxa: support i2c controller from DT
Date: Tue, 19 Jul 2011 13:43:37 -0600 [thread overview]
Message-ID: <20110719194337.GJ6848@ponder.secretlab.ca> (raw)
In-Reply-To: <1311042290-20253-7-git-send-email-haojian.zhuang@marvell.com>
On Tue, Jul 19, 2011 at 10:24:49AM +0800, Haojian Zhuang wrote:
> support i2c-pxa controller from DT.
>
> Signed-off-by: Haojian Zhuang <haojian.zhuang@marvell.com>
> ---
> drivers/i2c/busses/i2c-pxa.c | 58 ++++++++++++++++++++++++++++++-----------
> 1 files changed, 42 insertions(+), 16 deletions(-)
>
> diff --git a/drivers/i2c/busses/i2c-pxa.c b/drivers/i2c/busses/i2c-pxa.c
> index d603646..adac74a 100644
> --- a/drivers/i2c/busses/i2c-pxa.c
> +++ b/drivers/i2c/busses/i2c-pxa.c
> @@ -29,6 +29,7 @@
> #include <linux/errno.h>
> #include <linux/interrupt.h>
> #include <linux/i2c-pxa.h>
> +#include <linux/of_device.h>
> #include <linux/of_i2c.h>
> #include <linux/platform_device.h>
> #include <linux/err.h>
> @@ -1044,15 +1045,31 @@ static const struct i2c_algorithm i2c_pxa_pio_algorithm = {
> .functionality = i2c_pxa_functionality,
> };
>
> +static const struct of_device_id pxa_i2c_of_match[] = {
> + { .compatible = "mrvl,pxa255-i2c", .data = (void *)REGS_PXA2XX, },
> + { .compatible = "mrvl,pxa300-pwri2c", .data = (void *)REGS_PXA3XX, },
> + {},
> +};
> +
> static int i2c_pxa_probe(struct platform_device *dev)
> {
> + struct device_node *np = dev->dev.of_node;
> + const struct of_device_id *match;
> struct pxa_i2c *i2c;
> - struct resource *res;
> struct i2c_pxa_platform_data *plat = dev->dev.platform_data;
> const struct platform_device_id *id = platform_get_device_id(dev);
> - enum pxa_i2c_types i2c_type = id->driver_data;
> - int ret;
> - int irq;
> + enum pxa_i2c_types i2c_type;
> + struct resource *res;
> + int irq, ret;
> + static int idx = 0;
> +
> + if (np) {
> + match = of_match_device(pxa_i2c_of_match, &dev->dev);
> + if (match == NULL)
> + return -ENODEV;
> + i2c_type = (int)match->data;
> + } else
> + i2c_type = id->driver_data;
>
> res = platform_get_resource(dev, IORESOURCE_MEM, 0);
> irq = platform_get_irq(dev, 0);
> @@ -1074,16 +1091,23 @@ static int i2c_pxa_probe(struct platform_device *dev)
> spin_lock_init(&i2c->lock);
> init_waitqueue_head(&i2c->wait);
>
> - /*
> - * If "dev->id" is negative we consider it as zero.
> - * The reason to do so is to avoid sysfs names that only make
> - * sense when there are multiple adapters.
> - */
> - i2c->adap.nr = dev->id;
> - snprintf(i2c->adap.name, sizeof(i2c->adap.name), "pxa_i2c-i2c.%u",
> - i2c->adap.nr);
>
> - i2c->clk = clk_get(&dev->dev, NULL);
> + if (np) {
> + i2c->adap.nr = idx++;
No, just set adap.nr to -1. The i2c layer will dynamically assign an
id (there is a chance queued for v3.1 that fixes the i2c add
numbered adapter function to do this).
> + snprintf(i2c->adap.name, sizeof(i2c->adap.name),
> + "pxa2xx-i2c.%u", i2c->adap.nr);
> + i2c->clk = clk_get_sys(i2c->adap.name, NULL);
> + } else {
> + /*
> + * If "dev->id" is negative we consider it as zero.
> + * The reason to do so is to avoid sysfs names that only make
> + * sense when there are multiple adapters.
> + */
will no longer be necessary in v3.1
> + i2c->adap.nr = dev->id;
> + snprintf(i2c->adap.name, sizeof(i2c->adap.name),
> + "pxa_i2c-i2c.%u", i2c->adap.nr);
> + i2c->clk = clk_get(&dev->dev, NULL);
> + }
> if (IS_ERR(i2c->clk)) {
> ret = PTR_ERR(i2c->clk);
> goto eclk;
> @@ -1138,11 +1162,12 @@ static int i2c_pxa_probe(struct platform_device *dev)
>
> i2c->adap.algo_data = i2c;
> i2c->adap.dev.parent = &dev->dev;
> -#ifdef CONFIG_OF
> i2c->adap.dev.of_node = dev->dev.of_node;
> -#endif
>
> - ret = i2c_add_numbered_adapter(&i2c->adap);
> + if (i2c_type == REGS_CE4100)
> + ret = i2c_add_adapter(&i2c->adap);
> + else
> + ret = i2c_add_numbered_adapter(&i2c->adap);
The hunk can be dropped.
> if (ret < 0) {
> printk(KERN_INFO "I2C: Failed to add bus\n");
> goto eadapt;
> @@ -1234,6 +1259,7 @@ static struct platform_driver i2c_pxa_driver = {
> .name = "pxa2xx-i2c",
> .owner = THIS_MODULE,
> .pm = I2C_PXA_DEV_PM_OPS,
> + .of_match_table = pxa_i2c_of_match,
> },
> .id_table = i2c_pxa_id_table,
> };
> --
> 1.5.6.5
>
next prev parent reply other threads:[~2011-07-19 19:43 UTC|newest]
Thread overview: 25+ messages / expand[flat|nested] mbox.gz Atom feed top
[not found] <2011071901>
2011-07-19 2:24 ` [PATCH 0/7] support DT on ARCH-MMP Haojian Zhuang
2011-07-19 2:24 ` [PATCH 1/7] ARM: mmp: parse irq from DT Haojian Zhuang
2011-07-19 2:24 ` [PATCH 2/7] ARM: mmp: append MMP_USE_OF config Haojian Zhuang
2011-07-19 2:24 ` [PATCH 3/7] ARM: mmp: support DT on both dkb and brownstone Haojian Zhuang
2011-07-19 2:24 ` [PATCH 4/7] tty: serial: support device tree in pxa Haojian Zhuang
2011-07-19 2:24 ` [PATCH 5/7] tty: serial: check ops before registering console Haojian Zhuang
2011-07-19 2:24 ` [PATCH 6/7] i2c: pxa: support i2c controller from DT Haojian Zhuang
2011-07-19 2:24 ` [PATCH 7/7] i2c: pxa: support to parse property Haojian Zhuang
2011-07-19 10:17 ` Eric Miao
2011-07-19 19:47 ` Grant Likely
2011-07-19 19:45 ` Grant Likely
2011-07-20 1:22 ` Eric Miao
2011-07-19 19:43 ` Grant Likely [this message]
2011-07-19 19:40 ` [PATCH 4/7] tty: serial: support device tree in pxa Grant Likely
2011-07-19 19:48 ` Arnd Bergmann
2011-07-19 19:53 ` Grant Likely
2011-07-19 20:05 ` Russell King - ARM Linux
2011-07-19 20:17 ` Arnd Bergmann
2011-07-20 1:26 ` Eric Miao
2011-07-19 13:42 ` [PATCH 3/7] ARM: mmp: support DT on both dkb and brownstone Mitch Bradley
2011-07-19 19:49 ` Grant Likely
2011-07-19 19:36 ` Grant Likely
2011-07-19 19:24 ` [PATCH 2/7] ARM: mmp: append MMP_USE_OF config Grant Likely
2011-07-19 17:39 ` [PATCH 1/7] ARM: mmp: parse irq from DT Grant Likely
2011-07-19 7:12 ` [PATCH 0/7] support DT on ARCH-MMP Jean Delvare
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=20110719194337.GJ6848@ponder.secretlab.ca \
--to=grant.likely@secretlab.ca \
--cc=linux-arm-kernel@lists.infradead.org \
/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 a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).