From patchwork Fri Oct 20 14:14:13 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Linus Walleij X-Patchwork-Id: 116503 Delivered-To: patch@linaro.org Received: by 10.80.245.45 with SMTP id t42csp25840edm; Fri, 20 Oct 2017 07:16:22 -0700 (PDT) X-Received: by 10.99.47.6 with SMTP id v6mr4622357pgv.452.1508508982374; Fri, 20 Oct 2017 07:16:22 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1508508982; cv=none; d=google.com; s=arc-20160816; b=OqGYYreDY640I+2ioAG7o3HxFVG+AWY/heOAhQ8feARKRQkh71C0HB+qXCwU+FL5Hj hcfJHw+rej/NQV8r7JTfBoI8z11AbDkFnSJeHvwJ7LOIzrW6owksNRloSI4ozkY7LS83 jt62/QkNLFz7w+Y1+iKDqJDnb8VKuj7HuxUPSeey93DaHuIXO6ep9z990zgCVrn4cTV5 Gg7oG4Bk+gdQYC8qPQ310O8Zv7qP3SSvKBn39pd6VVum0tRXtKGeoUhE0GV9Nvp65aQ8 3bR0y6lhr0jpt7iz2NRhWFGFafwBaXSX7MN8EvgPQSwKNgtu6vZrnVFeij/xs5OCyTnO hilQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:content-transfer-encoding:mime-version :message-id:date:subject:cc:to:from:dkim-signature :arc-authentication-results; bh=/rYeSv0hUiQjwfZkT9SF7Ncx9RF5H8Vc3bV3cBt9zVQ=; b=Vx0IJwsdCsIIaOvgX0b2kimAuYoPrKb+I4oZG7s6hyeR6shjGzKiwJ5aAxoHX5WRoM NXmlbuT3vTEAFzCherAO86/ohn//Uh9O70a16mRGfMJj7ilMJBdf02N9Lrcj19f4i9C0 UqmY1Z/mY0XxPNk9TfseV3ChDmVTsmBgeymQBJ6pT3xQBKDdv6QWvYGcvzidMA+/DAwP YWRvdGluRh8ytJYuOHFmiXJt/ksNNR3ZpmrBcekVqgRMwxoXxlhFlOdQqmdk+wPGeex9 Pf5s4N3kOj7yTmWDjH+GkI6Afou4P+KL2Ac/G9OI2FjvJIzUb1aKdtR81ihus56vvebl D4Wg== ARC-Authentication-Results: i=1; mx.google.com; dkim=neutral (body hash did not verify) header.i=@linaro.org header.s=google header.b=i1RhrJq4; 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 y10si759547pgs.754.2017.10.20.07.16.22; Fri, 20 Oct 2017 07:16:22 -0700 (PDT) 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=i1RhrJq4; 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 S1751848AbdJTOQV (ORCPT + 6 others); Fri, 20 Oct 2017 10:16:21 -0400 Received: from mail-lf0-f65.google.com ([209.85.215.65]:50345 "EHLO mail-lf0-f65.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1751750AbdJTOQV (ORCPT ); Fri, 20 Oct 2017 10:16:21 -0400 Received: by mail-lf0-f65.google.com with SMTP id a132so13366628lfa.7 for ; Fri, 20 Oct 2017 07:16:20 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; h=from:to:cc:subject:date:message-id:mime-version :content-transfer-encoding; bh=/FwLNI7xGXvQRHwOKrUC/yqqo+fsWKCDCB0Pe9C3gMs=; b=i1RhrJq4PiqzQaQARQWefnUr/ar6dQABZVqViQibO0WSj6Qk2LHgGdPp6z7y/Oc9Tq FRbBzX8uOnO9RHRytoJfadGtD+4ESQDLGhjOa1iPtK85XkRSSxV0UILemOZUA4Ow68+O Uvst3X8DlSsYyw7sE0vivLglwFmUuSJp9wRWE= 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:mime-version :content-transfer-encoding; bh=/FwLNI7xGXvQRHwOKrUC/yqqo+fsWKCDCB0Pe9C3gMs=; b=Cg8ZLBaZ5aiAHBIupBs82ai7LisRdrr7vuujRUYioWac9XVphN5eWPps9RP1pDYp2h Xmgtzcm8gXFmZqw6ETe3w6YpOVAHYa8dhCHIjZT8+9AuA2FLSkBZLOfcDEBWdNHzPqWU J0kibxHVhD6dC5mwm0bJQFZlYmVSk4y8YHqc7ZtnvibGvyESsD9QRJ0v+0Lsi0ASGlEZ xeDKpnRAk+daaxBc/iJmdSprtnh0WzK4Dp5GkJJ3sYLpm1GNQglRwWN7dK3XT4PnTo4D MEVdsS0sDLVz7M7V+kRBePB1jWybmNYKiz3iQEoQU1Z0lY8oAT+uLtO1bafv+Dz7Wn9E es2g== X-Gm-Message-State: AMCzsaXknQSoor/TAXFf4RPIO7PXTMDV3PHTR1KjWWKZLuLSdcXyEAcZ jev1wBM1tsuBbAsEFrBOJO0kUMAg9Yw= X-Google-Smtp-Source: ABhQp+Sm6cF2erHWY77eBcKHNDqR0YHgMJwkqruk/9k2sKja0f/eyc3avORERyHLtWZsKE9qBboBUQ== X-Received: by 10.46.47.7 with SMTP id v7mr1895728ljv.192.1508508979040; Fri, 20 Oct 2017 07:16:19 -0700 (PDT) Received: from localhost.localdomain (c-5f7c71d5.014-348-6c756e10.cust.bredbandsbolaget.se. [213.113.124.95]) by smtp.gmail.com with ESMTPSA id 64sm210213lfp.90.2017.10.20.07.16.17 (version=TLS1_2 cipher=ECDHE-RSA-CHACHA20-POLY1305 bits=256/256); Fri, 20 Oct 2017 07:16:18 -0700 (PDT) From: Linus Walleij To: linux-gpio@vger.kernel.org Cc: Linus Walleij , Liu Gang , =?utf-8?q?Uwe_Kleine-K=C3=B6nig?= Subject: [PATCH] gpio: mpc8xxx: Do not reverse bits using bgpio Date: Fri, 20 Oct 2017 16:14:13 +0200 Message-Id: <20171020141413.29459-1-linus.walleij@linaro.org> X-Mailer: git-send-email 2.13.6 MIME-Version: 1.0 Sender: linux-gpio-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-gpio@vger.kernel.org The MPC8xxx driver is always instantiating its generic GPIO functions with the flag BGPIOF_BIG_ENDIAN. This means "big-endian bit order" and means the bits representing the GPIO lines in the registers are reversed around 31 bits so line 0 is at bit 31 and so forth down to line 31 in bit 0. Instead of looping into the generic MMIO gpio to do the simple calculation of a bitmask, through a vtable call with two parameters likely using stack frames etc (unless the compiler optimize it) and obscuring the view for the programmer, let's just open-code what the call does. This likely executes faster, saves space and makes the code easier to read. Cc: Liu Gang Cc: Uwe Kleine-König Signed-off-by: Linus Walleij --- drivers/gpio/gpio-mpc8xxx.c | 23 +++++++++++++++++------ 1 file changed, 17 insertions(+), 6 deletions(-) -- 2.13.6 -- 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 diff --git a/drivers/gpio/gpio-mpc8xxx.c b/drivers/gpio/gpio-mpc8xxx.c index 8c93dec498fa..ff5bf9c5dcec 100644 --- a/drivers/gpio/gpio-mpc8xxx.c +++ b/drivers/gpio/gpio-mpc8xxx.c @@ -21,6 +21,7 @@ #include #include #include +#include #define MPC8XXX_GPIO_PINS 32 @@ -44,6 +45,16 @@ struct mpc8xxx_gpio_chip { unsigned int irqn; }; +/* + * This hardware has a big endian bit assignment such that GPIO line 0 is + * connected to bit 31, line 1 to bit 30 ... line 31 to bit 0. + * This inline helper give the right bitmask for a certain line. + */ +static inline u32 mpc_pin2mask(unsigned int offset) +{ + return BIT(31 - offset); +} + /* Workaround GPIO 1 errata on MPC8572/MPC8536. The status of GPIOs * defined as output cannot be determined by reading GPDAT register, * so we use shadow data register instead. The status of input pins @@ -59,7 +70,7 @@ static int mpc8572_gpio_get(struct gpio_chip *gc, unsigned int gpio) val = gc->read_reg(mpc8xxx_gc->regs + GPIO_DAT) & ~out_mask; out_shadow = gc->bgpio_data & out_mask; - return !!((val | out_shadow) & gc->pin2mask(gc, gpio)); + return !!((val | out_shadow) & mpc_pin2mask(offset)); } static int mpc5121_gpio_dir_out(struct gpio_chip *gc, @@ -120,7 +131,7 @@ static void mpc8xxx_irq_unmask(struct irq_data *d) gc->write_reg(mpc8xxx_gc->regs + GPIO_IMR, gc->read_reg(mpc8xxx_gc->regs + GPIO_IMR) - | gc->pin2mask(gc, irqd_to_hwirq(d))); + | mpc_pin2mask(irqd_to_hwirq(d))); raw_spin_unlock_irqrestore(&mpc8xxx_gc->lock, flags); } @@ -135,7 +146,7 @@ static void mpc8xxx_irq_mask(struct irq_data *d) gc->write_reg(mpc8xxx_gc->regs + GPIO_IMR, gc->read_reg(mpc8xxx_gc->regs + GPIO_IMR) - & ~(gc->pin2mask(gc, irqd_to_hwirq(d)))); + & ~mpc_pin2mask(irqd_to_hwirq(d))); raw_spin_unlock_irqrestore(&mpc8xxx_gc->lock, flags); } @@ -146,7 +157,7 @@ static void mpc8xxx_irq_ack(struct irq_data *d) struct gpio_chip *gc = &mpc8xxx_gc->gc; gc->write_reg(mpc8xxx_gc->regs + GPIO_IER, - gc->pin2mask(gc, irqd_to_hwirq(d))); + mpc_pin2mask(irqd_to_hwirq(d))); } static int mpc8xxx_irq_set_type(struct irq_data *d, unsigned int flow_type) @@ -160,7 +171,7 @@ static int mpc8xxx_irq_set_type(struct irq_data *d, unsigned int flow_type) raw_spin_lock_irqsave(&mpc8xxx_gc->lock, flags); gc->write_reg(mpc8xxx_gc->regs + GPIO_ICR, gc->read_reg(mpc8xxx_gc->regs + GPIO_ICR) - | gc->pin2mask(gc, irqd_to_hwirq(d))); + | mpc_pin2mask(irqd_to_hwirq(d))); raw_spin_unlock_irqrestore(&mpc8xxx_gc->lock, flags); break; @@ -168,7 +179,7 @@ static int mpc8xxx_irq_set_type(struct irq_data *d, unsigned int flow_type) raw_spin_lock_irqsave(&mpc8xxx_gc->lock, flags); gc->write_reg(mpc8xxx_gc->regs + GPIO_ICR, gc->read_reg(mpc8xxx_gc->regs + GPIO_ICR) - & ~(gc->pin2mask(gc, irqd_to_hwirq(d)))); + & ~mpc_pin2mask(irqd_to_hwirq(d))); raw_spin_unlock_irqrestore(&mpc8xxx_gc->lock, flags); break;