From patchwork Thu Jul 28 06:41:32 2011 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Haojian Zhuang X-Patchwork-Id: 1014592 Received: from merlin.infradead.org (merlin.infradead.org [205.233.59.134]) by demeter1.kernel.org (8.14.4/8.14.4) with ESMTP id p6S6pxAN018651 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-SHA bits=256 verify=NO) for ; Thu, 28 Jul 2011 06:52:20 GMT Received: from canuck.infradead.org ([134.117.69.58]) by merlin.infradead.org with esmtps (Exim 4.76 #1 (Red Hat Linux)) id 1QmKRF-0003FW-Cb; Thu, 28 Jul 2011 06:51:22 +0000 Received: from localhost ([127.0.0.1] helo=canuck.infradead.org) by canuck.infradead.org with esmtp (Exim 4.76 #1 (Red Hat Linux)) id 1QmKRE-0006vD-S8; Thu, 28 Jul 2011 06:51:20 +0000 Received: from dakia2.marvell.com ([65.219.4.35]) by canuck.infradead.org with esmtps (Exim 4.76 #1 (Red Hat Linux)) id 1QmKPN-0006Yy-4N for linux-arm-kernel@lists.infradead.org; Thu, 28 Jul 2011 06:49:27 +0000 X-ASG-Debug-ID: 1311835764-082befb90001-tbGyMd Received: from maili.marvell.com (maili.marvell.com [10.68.76.51]) by dakia2.marvell.com with ESMTP id ElndemYFiHbKSGlZ; Wed, 27 Jul 2011 23:49:24 -0700 (PDT) X-Barracuda-Envelope-From: haojian.zhuang@marvell.com Received: from localhost (unknown [10.38.164.65]) by maili.marvell.com (Postfix) with ESMTP id C3AC68A002; Wed, 27 Jul 2011 23:49:23 -0700 (PDT) From: Haojian Zhuang To: haojian.zhuang@gmail.com, eric.y.miao@gmail.com, linux@arm.linux.org.uk, grant.likely@secretlab.ca, alan@linux.intel.com, linux-arm-kernel@lists.infradead.org, devicetree-discuss@lists.ozlabs.org X-ASG-Orig-Subj: [PATCH v2 6/7] i2c: pxa: support i2c controller from DT Subject: [PATCH v2 6/7] i2c: pxa: support i2c controller from DT Date: Thu, 28 Jul 2011 14:41:32 +0800 X-ASG-Orig-Subj: [PATCH v2 6/7] i2c: pxa: support i2c controller from DT Message-Id: <1311835293-18125-7-git-send-email-haojian.zhuang@marvell.com> X-Mailer: git-send-email 1.5.6.5 In-Reply-To: <1311835293-18125-6-git-send-email-haojian.zhuang@marvell.com> References: <1311835293-18125-1-git-send-email-haojian.zhuang@marvell.com> <1311835293-18125-2-git-send-email-haojian.zhuang@marvell.com> <1311835293-18125-3-git-send-email-haojian.zhuang@marvell.com> <1311835293-18125-4-git-send-email-haojian.zhuang@marvell.com> <1311835293-18125-5-git-send-email-haojian.zhuang@marvell.com> <1311835293-18125-6-git-send-email-haojian.zhuang@marvell.com> X-Barracuda-Connect: maili.marvell.com[10.68.76.51] X-Barracuda-Start-Time: 1311835764 X-Barracuda-URL: http://10.68.76.222:80/cgi-mod/mark.cgi X-Barracuda-Spam-Score: -1002.00 X-Barracuda-Spam-Status: No, SCORE=-1002.00 using global scores of TAG_LEVEL=1000.0 QUARANTINE_LEVEL=1000.0 KILL_LEVEL=1000.0 X-CRM114-Version: 20090807-BlameThorstenAndJenny ( TRE 0.7.6 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20110728_024925_610946_07EA514E X-CRM114-Status: GOOD ( 16.63 ) X-Spam-Score: -1.2 (-) X-Spam-Report: SpamAssassin version 3.3.1 on canuck.infradead.org summary: Content analysis details: (-1.2 points) pts rule name description ---- ---------------------- -------------------------------------------------- -1.2 RP_MATCHES_RCVD Envelope sender domain matches handover relay domain Cc: Haojian Zhuang X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.12 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , MIME-Version: 1.0 Sender: linux-arm-kernel-bounces@lists.infradead.org Errors-To: linux-arm-kernel-bounces+patchwork-linux-arm=patchwork.kernel.org@lists.infradead.org X-Greylist: IP, sender and recipient auto-whitelisted, not delayed by milter-greylist-4.2.6 (demeter1.kernel.org [140.211.167.41]); Thu, 28 Jul 2011 06:52:20 +0000 (UTC) support i2c-pxa controller from DT. Signed-off-by: Haojian Zhuang --- drivers/i2c/busses/i2c-pxa.c | 51 +++++++++++++++++++++++++++++++---------- 1 files changed, 38 insertions(+), 13 deletions(-) diff --git a/drivers/i2c/busses/i2c-pxa.c b/drivers/i2c/busses/i2c-pxa.c index d603646..8c27733 100644 --- a/drivers/i2c/busses/i2c-pxa.c +++ b/drivers/i2c/busses/i2c-pxa.c @@ -29,6 +29,7 @@ #include #include #include +#include #include #include #include @@ -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++; + 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. + */ + 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; @@ -1234,6 +1258,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, };