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: 127981 Delivered-To: patch@linaro.org Received: by 10.46.124.24 with SMTP id x24csp3058130ljc; Mon, 12 Feb 2018 02:11:36 -0800 (PST) X-Google-Smtp-Source: AH8x225z1iAL4sFKE4LJiZFw5C/Pu52h4BpgfxrAsqATqqzS5p/tVBBXcJZcedOfwhtE+nIEeWeN X-Received: by 2002:a17:902:8487:: with SMTP id c7-v6mr10178739plo.7.1518430296614; Mon, 12 Feb 2018 02:11:36 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1518430296; cv=none; d=google.com; s=arc-20160816; b=j5Dd/me6OragUU6sELVt6CqVGmFVQmUEB383CZhShUNoX9pFKJP3t17BFEiicwnrTg QckDgqx0JB8aH2z9nSIqSjWAbCgSkNb8Aa7feBGC31zA855ffwE00F1B4fGdf7S6panb JFbnWxAdMHqGpXNYDCKScgJTXd+MZr+rJfr3rZ+arOi8sEoF3NMLE002aqo/Pc0hlfws bUbVuvm9YYhuifPKxuUh7eLtFHeonP6JplDvcJTHBC2wOH+lakqPNsyzht/4XR3LJzNE 0G81l17dzrVUJFJHcpg9nztVEDMEiTtxLsgk1OhYmZeYMbTKuAKzK/9o5WM87Lqgu+wf Tbsw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:message-id:date:subject:cc:to:from :dkim-signature:arc-authentication-results; bh=syaCAG2Vv/EIy5bKsOuQadnFJZP9+w+41Yno4Aa05DM=; b=mZMxirmxWigUuIxNyOWL99crli9RjsE3eFhQ5iiUgEEfDUal1ApcfKGyEXLcrQWgom gfVxIrT1i4hhBs9ZCyvJB3MGWTZet5u6Rx/htRu/vUwWwPuoj8Stfacb7tnlTTrkczjv 2X94hNEJ+OB4LDOVlZHS2KnZJEc+fd3knpoj5UlCE0ZtEWl02KvABh0SQWVfUJviApgH 4HlVQWlUyCoRVgi1m3Dn0KQJ2pixTDR3hVJd4h82TC9YWFQxxUNFcEoSo8YJWzDmv6H/ ajkaPn44DMJNGIUAhmBUfqa7wlQz8SqiSJw8wliVcvIEmwey+pvWenvwpcmIzq7DDIuO 72Ag== ARC-Authentication-Results: i=1; mx.google.com; dkim=neutral (body hash did not verify) header.i=@linaro.org header.s=google header.b=iFbJENlT; spf=pass (google.com: best guess record for domain of linux-gpio-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-gpio-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=linaro.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id c23si4369733pfl.392.2018.02.12.02.11.36; Mon, 12 Feb 2018 02:11:36 -0800 (PST) Received-SPF: pass (google.com: best guess record for domain of linux-gpio-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; dkim=neutral (body hash did not verify) header.i=@linaro.org header.s=google header.b=iFbJENlT; spf=pass (google.com: best guess record for domain of linux-gpio-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-gpio-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=linaro.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S932702AbeBLKLe (ORCPT + 5 others); 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-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 --- drivers/gpio/gpio-dwapb.c | 24 ++++++++++++------------ 1 file changed, 12 insertions(+), 12 deletions(-) -- 2.14.3 -- To unsubscribe from this list: send the line "unsubscribe linux-gpio" in the body of a message to majordomo@vger.kernel.org More majordomo info at http://vger.kernel.org/majordomo-info.html Acked-by: Hoan Tran 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: 127982 Delivered-To: patch@linaro.org Received: by 10.46.124.24 with SMTP id x24csp3058141ljc; Mon, 12 Feb 2018 02:11:37 -0800 (PST) X-Google-Smtp-Source: AH8x225VHIm+ga+yE3KCc6Hg8HvlzXth4HofGcrPlB2mD0kpmXvgptcoyGOBrbmvrR4d1wg9qo2u X-Received: by 10.99.177.4 with SMTP id r4mr8921084pgf.245.1518430297306; Mon, 12 Feb 2018 02:11:37 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1518430297; cv=none; d=google.com; s=arc-20160816; b=ZCzILNZzGq58CvvSPekTiC2E/jz5TXhnC/sKYcctGBqY9QnYDLSgzhdPkrEGAHOjfi 6sSzDgab35lzYto0YSp4pyO1FS1TzrEDz2o8iwnuLPORIvNDZT8Clj+ScejZKyR2tPuy g+4TxMlqv8zvxdNvjmh68lDVPJ+73HKMM0Oci9gUMZLK2BAAwDPK5XM7h1jsqWypHsIv 0tsf/DW/UfS2IcBdx7cYMZbGeg+Terv2fbEhnRCZPSBxt1Jgr3o08Psn6LQ64bgqeIUV Ya0hbP54mWIPLsjoJ5tfXorzhYuSycrHIJOhn4NA6/KsH7O0AFcp9d5d+3fMMqFFgDnw HdXg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:references:in-reply-to:message-id:date :subject:cc:to:from:dkim-signature:arc-authentication-results; bh=mnIGZuLKDqGeI4cx63FA+/aLGdoyVyXztN+TNTuTcVY=; b=HRYhjOJ6OZJE9R2BDB1IKWCbE5XSMtaigOh1JcdTrpaih0BR+/GwM9kqdzCufwJrL9 cEZsp/qzn3fsEgKL/Ddrwpk7HFur7r9cftdHqlAZ+Cv9GkL2FWhEH7xlCrUVVl95svzT denYozfT44DakRp0oVIX4mDKzmatnyt1+2YX3xaKBmEN5OuXTHZZH1VD7dOt66cXgJaH g/7ed2bzLXceg6L02UeJlO8/a12iz3a9jnIm8ZVes/Q0ff4cQQSLilWj3lVN/Siv/+Cc AXiv43Px/Lsjcf571BAjhrYtDPTSMV0e2JJd0SOENDFyt/3wgTSnY5HhVIFyCL/253Sd jjNw== ARC-Authentication-Results: i=1; mx.google.com; dkim=neutral (body hash did not verify) header.i=@linaro.org header.s=google header.b=NCQmwckK; spf=pass (google.com: best guess record for domain of linux-gpio-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-gpio-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=linaro.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id c23si4369733pfl.392.2018.02.12.02.11.37; Mon, 12 Feb 2018 02:11:37 -0800 (PST) Received-SPF: pass (google.com: best guess record for domain of linux-gpio-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; dkim=neutral (body hash did not verify) header.i=@linaro.org header.s=google header.b=NCQmwckK; spf=pass (google.com: best guess record for domain of linux-gpio-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-gpio-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=linaro.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S932877AbeBLKLg (ORCPT + 5 others); 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-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 --- drivers/gpio/gpio-dwapb.c | 37 ++++++++++++++++++++++++++++++------- 1 file changed, 30 insertions(+), 7 deletions(-) -- 2.14.3 -- To unsubscribe from this list: send the line "unsubscribe linux-gpio" in the body of a message to majordomo@vger.kernel.org More majordomo info at http://vger.kernel.org/majordomo-info.html Acked-by: Hoan Tran 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) {