From patchwork Tue Aug 27 05:27:03 2013 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: archit taneja X-Patchwork-Id: 2849995 Return-Path: X-Original-To: patchwork-linux-arm@patchwork.kernel.org Delivered-To: patchwork-parsemail@patchwork2.web.kernel.org Received: from mail.kernel.org (mail.kernel.org [198.145.19.201]) by patchwork2.web.kernel.org (Postfix) with ESMTP id C2F39BF546 for ; Tue, 27 Aug 2013 05:29:07 +0000 (UTC) Received: from mail.kernel.org (localhost [127.0.0.1]) by mail.kernel.org (Postfix) with ESMTP id BA01C203F1 for ; Tue, 27 Aug 2013 05:29:06 +0000 (UTC) Received: from casper.infradead.org (casper.infradead.org [85.118.1.10]) (using TLSv1 with cipher DHE-RSA-AES256-SHA (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPS id 93CFA203ED for ; Tue, 27 Aug 2013 05:29:05 +0000 (UTC) Received: from merlin.infradead.org ([2001:4978:20e::2]) by casper.infradead.org with esmtps (Exim 4.80.1 #2 (Red Hat Linux)) id 1VEBpd-0005t4-Lx; Tue, 27 Aug 2013 05:28:45 +0000 Received: from localhost ([::1] helo=merlin.infradead.org) by merlin.infradead.org with esmtp (Exim 4.80.1 #2 (Red Hat Linux)) id 1VEBpb-0000Zl-Ej; Tue, 27 Aug 2013 05:28:43 +0000 Received: from devils.ext.ti.com ([198.47.26.153]) by merlin.infradead.org with esmtps (Exim 4.80.1 #2 (Red Hat Linux)) id 1VEBpY-0000ZR-T0 for linux-arm-kernel@lists.infradead.org; Tue, 27 Aug 2013 05:28:42 +0000 Received: from dlelxv90.itg.ti.com ([172.17.2.17]) by devils.ext.ti.com (8.13.7/8.13.7) with ESMTP id r7R5SIXJ018936; Tue, 27 Aug 2013 00:28:18 -0500 Received: from DFLE72.ent.ti.com (dfle72.ent.ti.com [128.247.5.109]) by dlelxv90.itg.ti.com (8.14.3/8.13.8) with ESMTP id r7R5SIHd031025; Tue, 27 Aug 2013 00:28:18 -0500 Received: from dlep33.itg.ti.com (157.170.170.75) by DFLE72.ent.ti.com (128.247.5.109) with Microsoft SMTP Server id 14.2.342.3; Tue, 27 Aug 2013 00:28:18 -0500 Received: from legion.dal.design.ti.com (legion.dal.design.ti.com [128.247.22.53]) by dlep33.itg.ti.com (8.14.3/8.13.8) with ESMTP id r7R5SIZg018630; Tue, 27 Aug 2013 00:28:18 -0500 Received: from localhost (a0393947pc.apr.dhcp.ti.com [172.24.145.166]) by legion.dal.design.ti.com (8.11.7p1+Sun/8.11.7) with ESMTP id r7R5SGt28400; Tue, 27 Aug 2013 00:28:16 -0500 (CDT) From: Archit Taneja To: Subject: [RESEND PATCH v2] gpio: Enable pcf857x GPIO expander for Device Tree Date: Tue, 27 Aug 2013 10:57:03 +0530 Message-ID: <1377581223-3728-1-git-send-email-archit@ti.com> X-Mailer: git-send-email 1.8.1.2 In-Reply-To: <1370527523-1030-1-git-send-email-archit@ti.com> References: <1370527523-1030-1-git-send-email-archit@ti.com> MIME-Version: 1.0 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20130827_012841_048190_16F7C8B6 X-CRM114-Status: GOOD ( 18.06 ) X-Spam-Score: -9.3 (---------) Cc: devicetree@vger.kernel.org, linux-doc@vger.kernel.org, grant.likely@secretlab.ca, Archit Taneja , linux-omap@vger.kernel.org, linux-arm-kernel@lists.infradead.org X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.15 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+patchwork-linux-arm=patchwork.kernel.org@lists.infradead.org X-Spam-Status: No, score=-6.7 required=5.0 tests=BAYES_00, RCVD_IN_DNSWL_MED, RP_MATCHES_RCVD, UNPARSEABLE_RELAY autolearn=unavailable version=3.3.1 X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on mail.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP Add code to parse the GPIO expander Device Tree node and extract platform data out of it, and populate the struct 'pcf857x_platform_data' maintained by the driver. This enables devices to reference the gpio expander from Device Tree. Add DT binding info in Documentation. Signed-off-by: Archit Taneja --- - v2 posted after quite a while, sorry for the delay! Changes in v2: - second gpeio-cell description corrected in Documentation - interrupt controller description removed for now, will be added in a follow up patch - n_latch description updated .../devicetree/bindings/gpio/gpio-pcf857x.txt | 41 ++++++++++++++++ drivers/gpio/gpio-pcf857x.c | 57 ++++++++++++++++++++-- 2 files changed, 94 insertions(+), 4 deletions(-) create mode 100644 Documentation/devicetree/bindings/gpio/gpio-pcf857x.txt diff --git a/Documentation/devicetree/bindings/gpio/gpio-pcf857x.txt b/Documentation/devicetree/bindings/gpio/gpio-pcf857x.txt new file mode 100644 index 0000000..504d114 --- /dev/null +++ b/Documentation/devicetree/bindings/gpio/gpio-pcf857x.txt @@ -0,0 +1,41 @@ +PCF857x I2C based GPIO controller bindings + +Required properties: +- compatible: + - "nxp,pca9670" for NXP PCA9670 8 bit I/O expander + - "nxp,pca9672" for NXP PCA9672 8 bit I/O expander with interrupt + - "nxp,pca9674" for NXP PCA9672 8 bit I/O expander with interrupt + - "nxp,pca8574" for NXP PCA8574 8 bit I/O expander with interrupt + - "nxp,pca8575" for NXP PCA8575 16 bit I/O expander with interrupt + - "nxp,pca9671" for NXP PCA9671 16 bit I/O expander + - "nxp,pca9673" for NXP PCA9673 16 bit I/O expander with interrupt + - "nxp,pca9675" for NXP PCA9675 16 bit I/O expander with interrupt + - "ti,pcf8574" for TI PCF8574 8 bit I/O expander with interrupt + - "ti,pcf8574a" for TI PCF8574A 8 bit I/O expander with interrupt + - "ti,pcf8575" for TI PCF8575 16 bit I/O expander with interrupt + - "ti,tca9554" for TI TCA9554 8 bit I/O expander with interrupt + - "maxim,max7328" for MAXIM MAX7328 8 bit I/O expander with interrupt + - "maxim,max7329" for MAXIM MAX7329 8 bit I/O expander with interrupt +- gpio-controller : Marks the device node as a GPIO controller. +- #gpio-cells : Should be two. + - first cell is the pin number. + - second cell is used to specify optional parameters (currently unused, but + needed by gpiolib). +- reg: I2C address of the chip. + +Device speific properties: +- n_latch: optional bit-inverse of initial register value; if + you leave this initialized to zero the driver will act + like the chip was just reset. If it is a non-zero + value, the driver will program the inverted value of + n_latch as the initial state of the gpios. + +Example: + +pcf8575: pcf8575 { + compatible = "ti,pcf8575"; + gpio-controller; + #gpio-cells = <2>; + reg = <0x20>; + n_latch = <0x0>; +}; diff --git a/drivers/gpio/gpio-pcf857x.c b/drivers/gpio/gpio-pcf857x.c index e8faf53..3435790 100644 --- a/drivers/gpio/gpio-pcf857x.c +++ b/drivers/gpio/gpio-pcf857x.c @@ -21,6 +21,7 @@ #include #include #include +#include #include #include #include @@ -255,17 +256,42 @@ fail: /*-------------------------------------------------------------------------*/ +static struct pcf857x_platform_data *of_gpio_pcf857x(struct device *dev) +{ + struct pcf857x_platform_data *pdata; + int r; + + pdata = devm_kzalloc(dev, sizeof(*pdata), GFP_KERNEL); + if (!pdata) + return NULL; + + pdata->gpio_base = -1; + + r = of_property_read_u32(dev->of_node, "n_latch", &pdata->n_latch); + if (r) { + dev_dbg(dev, "couldn't find n-latch, use default\n"); + pdata->n_latch = 0; + } + + return pdata; +} + static int pcf857x_probe(struct i2c_client *client, const struct i2c_device_id *id) { struct pcf857x_platform_data *pdata; + struct device_node *node; struct pcf857x *gpio; int status; pdata = client->dev.platform_data; - if (!pdata) { + node = client->dev.of_node; + + if (!pdata && node) + pdata = of_gpio_pcf857x(&client->dev); + + if (!pdata) dev_dbg(&client->dev, "no platform data\n"); - } /* Allocate, initialize, and register this gpio_chip. */ gpio = devm_kzalloc(&client->dev, sizeof(*gpio), GFP_KERNEL); @@ -420,10 +446,33 @@ static int pcf857x_remove(struct i2c_client *client) return status; } +static const struct of_device_id pcf857x_dt_ids[] = { + { .compatible = "nxp,pca9670", }, + { .compatible = "nxp,pca9672", }, + { .compatible = "nxp,pca9674", }, + { .compatible = "nxp,pca8574", }, + { .compatible = "nxp,pca8575", }, + { .compatible = "nxp,pca9671", }, + { .compatible = "nxp,pca9673", }, + { .compatible = "nxp,pca9675", }, + + { .compatible = "ti,pcf8574", }, + { .compatible = "ti,pcf8574a", }, + { .compatible = "ti,pcf8575", }, + { .compatible = "ti,tca9554", }, + + { .compatible = "maxim,max7328", }, + { .compatible = "maxim,max7329", }, + { } +}; + +MODULE_DEVICE_TABLE(of, pcf857x_dt_ids); + static struct i2c_driver pcf857x_driver = { .driver = { - .name = "pcf857x", - .owner = THIS_MODULE, + .name = "pcf857x", + .owner = THIS_MODULE, + .of_match_table = pcf857x_dt_ids, }, .probe = pcf857x_probe, .remove = pcf857x_remove,