From patchwork Wed Aug 5 17:23:08 2015 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Eduardo Valentin X-Patchwork-Id: 504119 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by ozlabs.org (Postfix) with ESMTP id E3CAE1402B7 for ; Thu, 6 Aug 2015 03:23:54 +1000 (AEST) Authentication-Results: ozlabs.org; dkim=fail reason="signature verification failed" (2048-bit key; unprotected) header.d=gmail.com header.i=@gmail.com header.b=akJAuSkn; dkim-atps=neutral Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1753477AbbHERXk (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 Received: by pabyb7 with SMTP id yb7so8987085pab.0; Wed, 05 Aug 2015 10:23:38 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=from:to:cc:subject:date:message-id:in-reply-to:references; bh=wBG3smXJA4YpJ5ufRaiypt5peqE19vYzlbLRn006YRE=; b=akJAuSkniTTfyeySrBH+MqrYJr5pEIqVPWx3lO2pggAlskxPzpoP23rM4Ew92K7cmC Lb0SAusQwEnWzbGA+FCPuldygtJoR0Z8JybzktVkNIQV4kyYUOe2HvMWecYr9tFOPcBk OEwHBuOd8dk82z2/ae+F5T/9qryWsesdPeWxUErHYBK/Qyd+nGlUueqaQlr6tuKhxHcv 1V7gsZy6mw9TpFPwvRCteW+c7E1PIPOyxdT0sRhOGQArcaWHtxiuBTLKCqBqf+nYmyJ7 lvdvzYfzJfn24N/hNhQ7TzLwn+9uVxeieHk/2aW1VaIf1g6/0kKbbasURCU083BULlZT x+AA== X-Received: by 10.68.138.134 with SMTP id qq6mr21271881pbb.87.1438795418142; Wed, 05 Aug 2015 10:23:38 -0700 (PDT) Received: from localhost (amazon.gigabitethernet4-0-6.asr1.snv2.gblx.net. [64.211.110.86]) by smtp.gmail.com with ESMTPSA id lm8sm3554680pbc.22.2015.08.05.10.23.37 (version=TLSv1.2 cipher=RC4-SHA bits=128/128); Wed, 05 Aug 2015 10:23:37 -0700 (PDT) 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-gpio-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-gpio@vger.kernel.org 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;