Return-Path: Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1753649AbbHERXk (ORCPT ); Wed, 5 Aug 2015 13:23:40 -0400 Received: from mail-pa0-f43.google.com ([209.85.220.43]:33666 "EHLO mail-pa0-f43.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1753140AbbHERXi (ORCPT ); Wed, 5 Aug 2015 13:23:38 -0400 From: Eduardo Valentin To: Linus Walleij , Alexandre Courbot Cc: ubrindis56@gmail.com, Fabio Estevam , festevam@gmail.com, linux-gpio@vger.kernel.org, linux-kernel@vger.kernel.org, Eduardo Valentin Subject: [PATCH 2/2] gpio/mxc: implement reading output gpio value Date: Wed, 5 Aug 2015 10:23:08 -0700 Message-Id: <1438795388-22743-3-git-send-email-edubezval@gmail.com> X-Mailer: git-send-email 2.5.0 In-Reply-To: <1438795388-22743-1-git-send-email-edubezval@gmail.com> References: <1438795388-22743-1-git-send-email-edubezval@gmail.com> Sender: linux-kernel-owner@vger.kernel.org List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Length: 2285 Lines: 62 In current implementation, reading the value of an output gpio always return 0. The reason is because when a gpio is configured as output, its output status can be read from the GPIO_DR register, and when it is configure as input, its value can be read from GPIO_PSR. With current implementation of basic mmio gpio driver, we can only read the value from one single register. Therefore, to workaround the basic mmio gpio driver limitation, this patch changes the gpio-mxc driver to provide its own .get callback. In the callback, we check the current status of the gpio direction, and read the correct register based on its current gpio direction status. Cc: Linus Walleij Cc: Alexandre Courbot Cc: linux-gpio@vger.kernel.org Cc: linux-kernel@vger.kernel.org Signed-off-by: Ulises Brindis Signed-off-by: Eduardo Valentin --- drivers/gpio/gpio-mxc.c | 13 +++++++++++++ 1 file changed, 13 insertions(+) diff --git a/drivers/gpio/gpio-mxc.c b/drivers/gpio/gpio-mxc.c index 9e5bdbd..8822823 100644 --- a/drivers/gpio/gpio-mxc.c +++ b/drivers/gpio/gpio-mxc.c @@ -401,6 +401,18 @@ static int mxc_gpio_to_irq(struct gpio_chip *gc, unsigned offset) return irq_find_mapping(port->domain, offset); } +static int mxc_gpio_get(struct gpio_chip *gc, unsigned int gpio) +{ + struct bgpio_chip *bgc = to_bgpio_chip(gc); + + if (!!(bgc->read_reg(bgc->reg_dir) & bgc->pin2mask(bgc, gpio))) + return !!(bgc->read_reg(bgc->reg_set) & + bgc->pin2mask(bgc, gpio)); + else + return !!(bgc->read_reg(bgc->reg_dat) & + bgc->pin2mask(bgc, gpio)); +} + static int mxc_gpio_probe(struct platform_device *pdev) { struct device_node *np = pdev->dev.of_node; @@ -455,6 +467,7 @@ static int mxc_gpio_probe(struct platform_device *pdev) if (err) goto out_bgio; + port->bgc.gc.get = mxc_gpio_get; port->bgc.gc.to_irq = mxc_gpio_to_irq; port->bgc.gc.base = (pdev->id < 0) ? of_alias_get_id(np, "gpio") * 32 : pdev->id * 32; -- 2.5.0 -- To unsubscribe from this list: send the line "unsubscribe linux-kernel" in the body of a message to majordomo@vger.kernel.org More majordomo info at http://vger.kernel.org/majordomo-info.html Please read the FAQ at http://www.tux.org/lkml/