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) {