From patchwork Mon Feb 12 10:11:24 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Linus Walleij X-Patchwork-Id: 871954 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="iFbJENlT"; dkim-atps=neutral Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by ozlabs.org (Postfix) with ESMTP id 3zg1fd11nRz9t34 for ; Mon, 12 Feb 2018 21:11:37 +1100 (AEDT) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S932702AbeBLKLe (ORCPT ); Mon, 12 Feb 2018 05:11:34 -0500 Received: from mail-lf0-f68.google.com ([209.85.215.68]:42946 "EHLO mail-lf0-f68.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S933650AbeBLKLb (ORCPT ); Mon, 12 Feb 2018 05:11:31 -0500 Received: by mail-lf0-f68.google.com with SMTP id w10so6903181lfc.9 for ; Mon, 12 Feb 2018 02:11:30 -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; bh=lKcp2ft4HfsjDGLAUehwtM4U7Z5iLvsWEHmThK1KPPI=; b=iFbJENlTBnXbCpkLgyW6vA7u0t/sHheSazrc4dReStCyY8/bdwby9I+wg1hq3IPbaT j/7mtXX+FQWmeIdwDvx9cn7wVwo9pmG71pTQj5bY/u3Kk4B1mn0iotL0ELHw3G56chB5 axs7lU/3gkqicK6oSPfDJvBVY/DupUsSycDrs= 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; bh=lKcp2ft4HfsjDGLAUehwtM4U7Z5iLvsWEHmThK1KPPI=; b=jd+/21DQkRSbcbIdSjCNmkXupuzldxL31EVnp9Sb2Se6iETh+lqRu9salwjSzL9FQ/ gTmeXC5xnNlRYuXsmDus3OjeVxBdfROTJHbPOeGaDHGQkSilFFWV7Jk3HOaC/2+QPQw4 r4YAYmBh9ErEK0T/1cIFjNtjtbolzWSZUcZkdeRRpH7LZ8mv2v6vU54trztFgTJS3jL3 sBYDEUY9EUsvNKHFK9265PgHq/uL4otgCfXEQN0spgYxYbKetwPRu8EG/QLWKqT3voUE PuYX9PaQhCUO5gygvddcznpc8tLIOWBGUZPXWI3KDVitffwZkkE+sa4uAV3FMwfmhf0V QFPA== X-Gm-Message-State: APf1xPB0VFiLoqR1HM9OoaK6OfVjrol3sGkvzT5R6NGlprianHsC06KX EN6BloTq5AvQ9gToZt/IEQQwcwSHWQg= X-Google-Smtp-Source: AH8x2264VI3q0KH2o4ng0wjR8OGHRHJbsPP/ibFLO31nJs63HEjaopxNVG2jEJ0Gy802I17SA8ngCQ== X-Received: by 10.46.70.18 with SMTP id t18mr7085722lja.41.1518430289633; Mon, 12 Feb 2018 02:11:29 -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.28 (version=TLS1_2 cipher=ECDHE-RSA-CHACHA20-POLY1305 bits=256/256); Mon, 12 Feb 2018 02:11:28 -0800 (PST) From: Linus Walleij To: linux-gpio@vger.kernel.org, Hoan Tran Cc: Linus Walleij Subject: [PATCH 1/2] gpio: dwapb: Use "stride" rather than "size" for register distance Date: Mon, 12 Feb 2018 11:11:24 +0100 Message-Id: <20180212101125.7890-1-linus.walleij@linaro.org> X-Mailer: git-send-email 2.14.3 Sender: linux-gpio-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-gpio@vger.kernel.org This terminology is more precise. Also cut the stride calculation in the preprocessor, it confuses more than it helps when reading the driver. Signed-off-by: Linus Walleij Acked-by: Hoan Tran --- drivers/gpio/gpio-dwapb.c | 24 ++++++++++++------------ 1 file changed, 12 insertions(+), 12 deletions(-) diff --git a/drivers/gpio/gpio-dwapb.c b/drivers/gpio/gpio-dwapb.c index 6730c6642ce3..677988f21369 100644 --- a/drivers/gpio/gpio-dwapb.c +++ b/drivers/gpio/gpio-dwapb.c @@ -53,9 +53,9 @@ #define GPIO_EXT_PORTD 0x5c #define DWAPB_MAX_PORTS 4 -#define GPIO_EXT_PORT_SIZE (GPIO_EXT_PORTB - GPIO_EXT_PORTA) -#define GPIO_SWPORT_DR_SIZE (GPIO_SWPORTB_DR - GPIO_SWPORTA_DR) -#define GPIO_SWPORT_DDR_SIZE (GPIO_SWPORTB_DDR - GPIO_SWPORTA_DDR) +#define GPIO_EXT_PORT_STRIDE 0x04 /* register stride 32 bits */ +#define GPIO_SWPORT_DR_STRIDE 0x0c /* register stride 3*32 bits */ +#define GPIO_SWPORT_DDR_STRIDE 0x0c /* register stride 3*32 bits */ #define GPIO_REG_OFFSET_V2 1 @@ -476,10 +476,10 @@ static int dwapb_gpio_add_port(struct dwapb_gpio *gpio, return -ENOMEM; #endif - dat = gpio->regs + GPIO_EXT_PORTA + (pp->idx * GPIO_EXT_PORT_SIZE); - set = gpio->regs + GPIO_SWPORTA_DR + (pp->idx * GPIO_SWPORT_DR_SIZE); + dat = gpio->regs + GPIO_EXT_PORTA + (pp->idx * GPIO_EXT_PORT_STRIDE); + set = gpio->regs + GPIO_SWPORTA_DR + (pp->idx * GPIO_SWPORT_DR_STRIDE); dirout = gpio->regs + GPIO_SWPORTA_DDR + - (pp->idx * GPIO_SWPORT_DDR_SIZE); + (pp->idx * GPIO_SWPORT_DDR_STRIDE); err = bgpio_init(&port->gc, gpio->dev, 4, dat, set, NULL, dirout, NULL, 0); @@ -710,13 +710,13 @@ static int dwapb_gpio_suspend(struct device *dev) BUG_ON(!ctx); - offset = GPIO_SWPORTA_DDR + idx * GPIO_SWPORT_DDR_SIZE; + offset = GPIO_SWPORTA_DDR + idx * GPIO_SWPORT_DDR_STRIDE; ctx->dir = dwapb_read(gpio, offset); - offset = GPIO_SWPORTA_DR + idx * GPIO_SWPORT_DR_SIZE; + offset = GPIO_SWPORTA_DR + idx * GPIO_SWPORT_DR_STRIDE; ctx->data = dwapb_read(gpio, offset); - offset = GPIO_EXT_PORTA + idx * GPIO_EXT_PORT_SIZE; + offset = GPIO_EXT_PORTA + idx * GPIO_EXT_PORT_STRIDE; ctx->ext = dwapb_read(gpio, offset); /* Only port A can provide interrupts */ @@ -753,13 +753,13 @@ static int dwapb_gpio_resume(struct device *dev) BUG_ON(!ctx); - offset = GPIO_SWPORTA_DR + idx * GPIO_SWPORT_DR_SIZE; + offset = GPIO_SWPORTA_DR + idx * GPIO_SWPORT_DR_STRIDE; dwapb_write(gpio, offset, ctx->data); - offset = GPIO_SWPORTA_DDR + idx * GPIO_SWPORT_DDR_SIZE; + offset = GPIO_SWPORTA_DDR + idx * GPIO_SWPORT_DDR_STRIDE; dwapb_write(gpio, offset, ctx->dir); - offset = GPIO_EXT_PORTA + idx * GPIO_EXT_PORT_SIZE; + offset = GPIO_EXT_PORTA + idx * GPIO_EXT_PORT_STRIDE; dwapb_write(gpio, offset, ctx->ext); /* Only port A can provide interrupts */ 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) {