Received: by 2002:ac0:a582:0:0:0:0:0 with SMTP id m2-v6csp733740imm; Mon, 1 Oct 2018 18:16:16 -0700 (PDT) X-Google-Smtp-Source: ACcGV63eLOhXWzfcgWUfzdq9qp7SCx4OqnhAxZaiwPAADc/3q6cHp01MyXbItTz1T0uCUnQnHM+0 X-Received: by 2002:a17:902:3324:: with SMTP id a33-v6mr14401926plc.208.1538442976861; Mon, 01 Oct 2018 18:16:16 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1538442976; cv=none; d=google.com; s=arc-20160816; b=d1zsTzrFN3wGTUjfkWBwYMEtzrhagv7F6WKlagN0LTvopPVLYwzMcixGi2tfqLztjC uyZCrzyJTjim8xI5jF6c/LyudeazKxglhSWBx79zSkaHqNtaUXDG1rapP/wkwhZQGJZU urf7G2vrbXpYx9r8avoKxna1IvKNx8qVrGIdnQqQ1MqHLgonxgkoEmmo68qpvEdy/wMI wgy2t68CbrOoB0BSxXA6OoigS5dPMobLER1CJhErKrDk/H6CC+E5s42iXhDvsBLydvw4 d63iAj+YMG+Pa873WgXp5skz5zX0e9h4vXxSzuHm1h2mxSCiZysFtGIdr3UCVsPuv4mF wNtA== 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 :references:in-reply-to:message-id:date:subject:cc:to:from :dkim-signature; bh=BAIY58cG2lAF0QLUr5y2z0xC0M6YOWGQFl14m1ZUlO0=; b=WOq5OjqfPQCb16vPoq/j72TzF4mNBA/5cN9/vUVXtJt4Iy715R8BN/ZrlMWbFIvz7j +u7B3md0t+J/5pASEMFmpobBWqJdjzwK+8DUFnXT9WDevxjgZwJRRdjnYhbo3zSdOLJE DD85NYiLQ3egsXsivmq+H0gqKcd3HGHAADnQ4GdCEg7pT09UUTIIZ4vvi8fnoAw/2sXv IP0LxO62O8tdOQROvedZq8Rt3ZWaw/1Pi9Dg4+zlkNJOO1TPHq61DH1M33lOVSAWYcGL hZBODlXwuH4y2MLalAyVnl5h1xRbj3+YQRr9skIzGq2WUJIE/XafCImAG8ExtFKsth5p 0bqg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gmail.com header.s=20161025 header.b=aKNe49Oc; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id e14-v6si13166293pgm.679.2018.10.01.18.16.02; Mon, 01 Oct 2018 18:16:16 -0700 (PDT) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; dkim=pass header.i=@gmail.com header.s=20161025 header.b=aKNe49Oc; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727068AbeJBH4c (ORCPT + 99 others); Tue, 2 Oct 2018 03:56:32 -0400 Received: from mail-io1-f66.google.com ([209.85.166.66]:42950 "EHLO mail-io1-f66.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726459AbeJBH4c (ORCPT ); Tue, 2 Oct 2018 03:56:32 -0400 Received: by mail-io1-f66.google.com with SMTP id n18-v6so311001ioa.9; Mon, 01 Oct 2018 18:15:57 -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 :mime-version:content-transfer-encoding; bh=BAIY58cG2lAF0QLUr5y2z0xC0M6YOWGQFl14m1ZUlO0=; b=aKNe49Ocl/ef2DiyqjmVyMOkVvqSIgjFXJWSkvCbllzDujEqGCsbx2AbH+H31mi2PZ U4p69kN/0Xa2qHmMlIt9iRjDqCO7EQ8jiDxTecIpRWc3eAo1SMVeT8mNu70nWfDzMF71 o+e/gKE5YEGmu2rCXUOig1+5Volgi8VWIuO97omk6KMahcmKjko4g14fIW2cYmMqEynS Nc3oSTt+9Mhn/Kd8vtaI6ylGMBngCF3QQykRsMelNLU2LN9+nXkT0wYR+PiIRoJlYgAP IeN84HJs4YoKeCxXSiJY56NDUuiY3H29xQ2CACghJNpZ4dYxKAPy+CfzD3YLlVAS7qcR zKCA== 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:mime-version:content-transfer-encoding; bh=BAIY58cG2lAF0QLUr5y2z0xC0M6YOWGQFl14m1ZUlO0=; b=NtHR2akqP0cGga/9Z4TnXeoW/Q6FJj27gOKML0onh233zVTqPniVQ3Dyoo55IjKs7X hfd5zLRR+iSCkZ2UcJdjVeLqLb8UZm+2vPbaJza/hp7doVRdPxr599PyINpRlakEDnFB vaJyyihZbFFDL/4mEW3sJDsMip9R3QVfB1CD86cF/1ZY164YVctrA2i3pXBrCPvci/1P y44r0JflPKImXn/1dESA+YA6sis+hlwtArP6OCx8z/FRb60ecZOMB9Y4RCqnLNs2qa5Y ucFTaw96kAa/mKLItQifGAkMq+DwWyk1+2p3rUvvyhHIWyv53WgQ5zZbpUjhM4NUjj5B R/Mg== X-Gm-Message-State: ABuFfohTWKtOdiCmYV4ojDS2WwQAK++w9N6Guc5gzjbXQjx6xRzAhgt9 xwL3RkeVDTLQFRlJydtBo4hmmtyu X-Received: by 2002:a62:34c4:: with SMTP id b187-v6mr13942578pfa.15.1538442957406; Mon, 01 Oct 2018 18:15:57 -0700 (PDT) Received: from localhost.localdomain (122-223-50-245.fukuoka.fdn.vectant.ne.jp. [122.223.50.245]) by smtp.gmail.com with ESMTPSA id u21-v6sm14805702pfa.176.2018.10.01.18.15.55 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Mon, 01 Oct 2018 18:15:57 -0700 (PDT) From: William Breathitt Gray To: linus.walleij@linaro.org, akpm@linux-foundation.org Cc: linux-gpio@vger.kernel.org, linux-arch@vger.kernel.org, linux-kernel@vger.kernel.org, andriy.shevchenko@linux.intel.com, linux@rasmusvillemoes.dk, William Breathitt Gray Subject: [RESEND PATCH v4 7/8] gpio: pci-idio-16: Utilize for_each_set_clump macro Date: Tue, 2 Oct 2018 10:16:00 +0900 Message-Id: <4ec0716fc3bcad6d0d90598ebd08b753cc354738.1538441919.git.vilhelm.gray@gmail.com> X-Mailer: git-send-email 2.19.0 In-Reply-To: References: MIME-Version: 1.0 Content-Transfer-Encoding: 8bit Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@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) -- 2.19.0