From patchwork Mon Feb 12 10:11:25 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Linus Walleij X-Patchwork-Id: 871955 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: ozlabs.org; spf=none (mailfrom) smtp.mailfrom=vger.kernel.org (client-ip=209.132.180.67; helo=vger.kernel.org; envelope-from=linux-gpio-owner@vger.kernel.org; receiver=) Authentication-Results: ozlabs.org; dkim=fail reason="signature verification failed" (1024-bit key; unprotected) header.d=linaro.org header.i=@linaro.org header.b="NCQmwckK"; dkim-atps=neutral Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by ozlabs.org (Postfix) with ESMTP id 3zg1fd6Mrrz9t5Y for ; Mon, 12 Feb 2018 21:11:37 +1100 (AEDT) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S932877AbeBLKLg (ORCPT ); Mon, 12 Feb 2018 05:11:36 -0500 Received: from mail-lf0-f67.google.com ([209.85.215.67]:42951 "EHLO mail-lf0-f67.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1751176AbeBLKLd (ORCPT ); Mon, 12 Feb 2018 05:11:33 -0500 Received: by mail-lf0-f67.google.com with SMTP id w10so6903323lfc.9 for ; Mon, 12 Feb 2018 02:11:32 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; h=from:to:cc:subject:date:message-id:in-reply-to:references; bh=8DFSULZ9odAJo1lqwirSSVSgQOy+PmtqPkxHlo1HwD0=; b=NCQmwckKSCbQxEYCnyp1ihzP2CzgPyoKmWDKXET7HV1N4w2mR3IYogX3EHwO9E/WJJ V5gCZxfIP2ksu8HmbEJ39L09RSyHnOL5c04aYKHIRufiaFjFd4O+VoJKhuIHQ+AdKctU NtBykzmpQEv3jPu1Po1d2F4l9UZ6OpwAMTW5Q= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references; bh=8DFSULZ9odAJo1lqwirSSVSgQOy+PmtqPkxHlo1HwD0=; b=mM2UBk7ciYwdjh41j5rIa6V7CXyNJky6BMidMkQveQwt58UCPX28hgxS/Do6dmAstm az96lrQolOIemnFi4x+ilifCUTQBfGX6VKmghAVSaZ3edM5AIz7icI/9dE4XCsZs195/ TdoSLwdWq5Ggh1pk1hn9NLuojQ/oaovKJ7+3gw1DYg01MVS8UiXCDMC9oM3AN6yZbHjP dJ5uOjQH0ll73qJNipy95iRsnPbak3D2jLEkAU/NDde9FekThVkmTr0dvJ1/ajEHDfAL tAG50mXwN0hN5gALB6LecoqJgOwRbgALX3+AXq1aex5zJFF378mFxiGQUcMIM164oMs1 eGDA== X-Gm-Message-State: APf1xPBm7HQN2EZdYRdBfOKziRTXlKukv5nn6nGBHtq3ZFEVISOAjsWz cKStvOgqP1OSVYbGL5PCz39Ar9rQYxc= X-Google-Smtp-Source: AH8x226i6c+vEgT42M6GQikFmSOY39L264vMRLqEyFiVdGJV2AHZzvibgp1op3LjzwsO9a5YmI2xDg== X-Received: by 10.46.66.8 with SMTP id p8mr1481357lja.3.1518430291856; Mon, 12 Feb 2018 02:11:31 -0800 (PST) Received: from genomnajs.ideon.se ([85.235.10.227]) by smtp.gmail.com with ESMTPSA id l193sm1618055lfg.50.2018.02.12.02.11.30 (version=TLS1_2 cipher=ECDHE-RSA-CHACHA20-POLY1305 bits=256/256); Mon, 12 Feb 2018 02:11:31 -0800 (PST) From: Linus Walleij To: linux-gpio@vger.kernel.org, Hoan Tran Cc: Linus Walleij Subject: [PATCH 2/2] gpio: dwapb: Call directly into the gpiochip to read value Date: Mon, 12 Feb 2018 11:11:25 +0100 Message-Id: <20180212101125.7890-2-linus.walleij@linaro.org> X-Mailer: git-send-email 2.14.3 In-Reply-To: <20180212101125.7890-1-linus.walleij@linaro.org> References: <20180212101125.7890-1-linus.walleij@linaro.org> Sender: linux-gpio-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-gpio@vger.kernel.org We were going out through the (legacy) gpio API to read the value of a line to set up polarity inversion. This is abusive. Do something less abusive by looking up the actual struct gpio_chip * instance and calling .get() directly on it. Signed-off-by: Linus Walleij Acked-by: Hoan Tran --- drivers/gpio/gpio-dwapb.c | 37 ++++++++++++++++++++++++++++++------- 1 file changed, 30 insertions(+), 7 deletions(-) diff --git a/drivers/gpio/gpio-dwapb.c b/drivers/gpio/gpio-dwapb.c index 677988f21369..b0704a883513 100644 --- a/drivers/gpio/gpio-dwapb.c +++ b/drivers/gpio/gpio-dwapb.c @@ -9,8 +9,6 @@ */ #include #include -/* FIXME: for gpio_get_value(), replace this with direct register read */ -#include #include #include #include @@ -153,16 +151,40 @@ static int dwapb_gpio_to_irq(struct gpio_chip *gc, unsigned offset) return irq_find_mapping(gpio->domain, offset); } +static struct dwapb_gpio_port *dwapb_offs_to_port(struct dwapb_gpio *gpio, unsigned int offs) +{ + struct dwapb_gpio_port *port; + int i; + + for (i = 0; i < gpio->nr_ports; i++) { + port = &gpio->ports[i]; + if (port->idx == offs / 32) + return port; + } + + return NULL; +} + static void dwapb_toggle_trigger(struct dwapb_gpio *gpio, unsigned int offs) { - u32 v = dwapb_read(gpio, GPIO_INT_POLARITY); + struct dwapb_gpio_port *port = dwapb_offs_to_port(gpio, offs); + struct gpio_chip *gc; + u32 pol; + int val; + + if (!port) + return; + gc = &port->gc; - if (gpio_get_value(gpio->ports[0].gc.base + offs)) - v &= ~BIT(offs); + pol = dwapb_read(gpio, GPIO_INT_POLARITY); + /* Just read the current value right out of the data register */ + val = gc->get(gc, offs % 32); + if (val) + pol &= ~BIT(offs); else - v |= BIT(offs); + pol |= BIT(offs); - dwapb_write(gpio, GPIO_INT_POLARITY, v); + dwapb_write(gpio, GPIO_INT_POLARITY, pol); } static u32 dwapb_do_irq(struct dwapb_gpio *gpio) @@ -481,6 +503,7 @@ static int dwapb_gpio_add_port(struct dwapb_gpio *gpio, dirout = gpio->regs + GPIO_SWPORTA_DDR + (pp->idx * GPIO_SWPORT_DDR_STRIDE); + /* This registers 32 GPIO lines per port */ err = bgpio_init(&port->gc, gpio->dev, 4, dat, set, NULL, dirout, NULL, 0); if (err) {