From patchwork Tue May 15 16:23:39 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: William Breathitt Gray X-Patchwork-Id: 913810 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; dmarc=fail (p=none dis=none) header.from=gmail.com Authentication-Results: ozlabs.org; dkim=fail reason="signature verification failed" (2048-bit key; unprotected) header.d=gmail.com header.i=@gmail.com header.b="oMJfnsu/"; dkim-atps=neutral Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by ozlabs.org (Postfix) with ESMTP id 40ljYq0qhnz9s0q for ; Wed, 16 May 2018 02:23:59 +1000 (AEST) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1754224AbeEOQXr (ORCPT ); Tue, 15 May 2018 12:23:47 -0400 Received: from mail-yw0-f194.google.com ([209.85.161.194]:35892 "EHLO mail-yw0-f194.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1752002AbeEOQXp (ORCPT ); Tue, 15 May 2018 12:23:45 -0400 Received: by mail-yw0-f194.google.com with SMTP id l15-v6so243546ywk.3; Tue, 15 May 2018 09:23:45 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:date:message-id:in-reply-to:references; bh=4t9I9klQQ8DpB7w8AbzTMPlX1P6Su0J5LCLKig5N73k=; b=oMJfnsu/UsITQBCutoO3+KU1hnXZHNlqYvNIwSwr9hSnGJCwFbWI0LchIK2Ti9luww 2IhmjmxZgcZ3juflyL5BEfd8yW/BK7BoL6R7ggcErNxJ70az25Devz7g9SDlCfiiYz3E n5XHcT+AO1qoVtCbHMGYR2sQGc4UlLd9C5XDIQDNCK5qQloJcsmWWU6nqdoGkKeUu8oP E0dF9XmZa5sAuLG7HDfYYG4LxifgG9jr0oTnN/nVQmDnTGiidTrFe08EuLmoBNyn4q9e YQEckY5edVersWUtUGDziCKLRNw6IgH0hV/PdgoxL+6Z9mrONGiwL1ikXHLldgJ4XQGn iyUw== 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=4t9I9klQQ8DpB7w8AbzTMPlX1P6Su0J5LCLKig5N73k=; b=s+ZzvygH5+f1h42Zn0kyOJzDTHtW7mxXcKIA4w13Mm+LMvPxX+okh7BjZNBC14pR8y TGPV2jk1Pldk8FTS9oRc+CFnJxqCQe0A6jwwDFWRr3btiO9tmGsZXwNjPvAhsm8S2xCX uZgoHufs+uCH7+Ev35KVf7oeeVmsWkcWhDLoMFSEqiOm/ztMnXrgc9m7ERI98ijqecz/ b4ke5nSYvWepufR82b4GTH4l+DjRYltipzwfDPW6sg6pRLcBqz3fmoOYC6+vKnRCNUyS i0lxtJxGC7HD21yBiLil448Rtk2yUvyTkEaq3Ud/V88vDRyomNBTe4hIUf0N658FGOmF jJzQ== X-Gm-Message-State: ALKqPwcYpvTmnDYCwfYnSxZzZKkIbZeAXhMIBmEx5Olo6vPCSJevkHVh oP10e/LLFkLQPo+8nKAxfg0= X-Google-Smtp-Source: AB8JxZr7Xv0iSO9qC1cejRuS4N07nwPVBPPdTMAc89jkiFkgck3IUNtjFyTE+XSLW8G29qLnfnPIXQ== X-Received: by 2002:a81:f211:: with SMTP id i17-v6mr6587528ywm.160.1526401424800; Tue, 15 May 2018 09:23:44 -0700 (PDT) Received: from localhost ([72.188.97.40]) by smtp.gmail.com with ESMTPSA id y2-v6sm145644ywf.76.2018.05.15.09.23.44 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Tue, 15 May 2018 09:23:44 -0700 (PDT) From: William Breathitt Gray To: linus.walleij@linaro.org Cc: linux-gpio@vger.kernel.org, linux-arch@vger.kernel.org, linux-kernel@vger.kernel.org, William Breathitt Gray Subject: [PATCH v4 7/8] gpio: pci-idio-16: Utilize for_each_set_clump macro Date: Tue, 15 May 2018 12:23:39 -0400 Message-Id: X-Mailer: git-send-email 2.17.0 In-Reply-To: References: Sender: linux-gpio-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-gpio@vger.kernel.org Replace verbose implementation in get_multiple/set_multiple callbacks with for_each_set_clump macro to simplify code and improve clarity. Signed-off-by: William Breathitt Gray --- drivers/gpio/gpio-pci-idio-16.c | 67 +++++++++++---------------------- 1 file changed, 21 insertions(+), 46 deletions(-) diff --git a/drivers/gpio/gpio-pci-idio-16.c b/drivers/gpio/gpio-pci-idio-16.c index 25d16b2af1c3..6d748c6e59cb 100644 --- a/drivers/gpio/gpio-pci-idio-16.c +++ b/drivers/gpio/gpio-pci-idio-16.c @@ -109,44 +109,20 @@ static int idio_16_gpio_get_multiple(struct gpio_chip *chip, { struct idio_16_gpio *const idio16gpio = gpiochip_get_data(chip); size_t i; - const unsigned int gpio_reg_size = 8; - unsigned int bits_offset; - size_t word_index; - unsigned int word_offset; - unsigned long word_mask; - const unsigned long port_mask = GENMASK(gpio_reg_size - 1, 0); - unsigned long port_state; + size_t word; + unsigned int offset; void __iomem *ports[] = { &idio16gpio->reg->out0_7, &idio16gpio->reg->out8_15, &idio16gpio->reg->in0_7, &idio16gpio->reg->in8_15, }; + unsigned long port_state; /* clear bits array to a clean slate */ bitmap_zero(bits, chip->ngpio); - /* get bits are evaluated a gpio port register at a time */ - for (i = 0; i < ARRAY_SIZE(ports); i++) { - /* gpio offset in bits array */ - bits_offset = i * gpio_reg_size; - - /* word index for bits array */ - word_index = BIT_WORD(bits_offset); - - /* gpio offset within current word of bits array */ - word_offset = bits_offset % BITS_PER_LONG; - - /* mask of get bits for current gpio within current word */ - word_mask = mask[word_index] & (port_mask << word_offset); - if (!word_mask) { - /* no get bits in this port so skip to next one */ - continue; - } - - /* read bits from current gpio port */ + for_each_set_clump(i, word, offset, mask, ARRAY_SIZE(ports), 8) { port_state = ioread8(ports[i]); - - /* store acquired bits at respective bits array offset */ - bits[word_index] |= port_state << word_offset; + bits[word] |= port_state << offset; } return 0; @@ -186,30 +162,29 @@ static void idio_16_gpio_set_multiple(struct gpio_chip *chip, unsigned long *mask, unsigned long *bits) { struct idio_16_gpio *const idio16gpio = gpiochip_get_data(chip); + size_t i; + size_t word; + unsigned int offset; + void __iomem *ports[] = { + &idio16gpio->reg->out0_7, &idio16gpio->reg->out8_15, + }; + unsigned int iomask; + unsigned int bitmask; unsigned long flags; unsigned int out_state; - raw_spin_lock_irqsave(&idio16gpio->lock, flags); + for_each_set_clump(i, word, offset, mask, ARRAY_SIZE(ports), 8) { + iomask = mask[word] >> offset; + bitmask = iomask & (bits[word] >> offset); - /* process output lines 0-7 */ - if (*mask & 0xFF) { - out_state = ioread8(&idio16gpio->reg->out0_7) & ~*mask; - out_state |= *mask & *bits; - iowrite8(out_state, &idio16gpio->reg->out0_7); - } + raw_spin_lock_irqsave(&idio16gpio->lock, flags); - /* shift to next output line word */ - *mask >>= 8; + out_state = ioread8(ports[i]) & ~iomask; + out_state |= bitmask; + iowrite8(out_state, ports[i]); - /* process output lines 8-15 */ - if (*mask & 0xFF) { - *bits >>= 8; - out_state = ioread8(&idio16gpio->reg->out8_15) & ~*mask; - out_state |= *mask & *bits; - iowrite8(out_state, &idio16gpio->reg->out8_15); + raw_spin_unlock_irqrestore(&idio16gpio->lock, flags); } - - raw_spin_unlock_irqrestore(&idio16gpio->lock, flags); } static void idio_16_irq_ack(struct irq_data *data)