Received: by 2002:ad5:474a:0:0:0:0:0 with SMTP id i10csp4717556imu; Tue, 18 Dec 2018 22:04:07 -0800 (PST) X-Google-Smtp-Source: AFSGD/VTCecNayabi+xEnYa+IQwcxki+bl+uKn2RCDSFevCC1jSKX/FCLSo40iJOfDO0YfRo1629 X-Received: by 2002:a62:442:: with SMTP id 63mr18933113pfe.156.1545199447545; Tue, 18 Dec 2018 22:04:07 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1545199447; cv=none; d=google.com; s=arc-20160816; b=jAXsfmUMw3i39OgqUTIz4iAzwRuuBeYyfZjQM5PRpqwvRDmPw5aYy9M8krdpWO9YC5 ubGRJ0/qgoC4cfj0OZnZsjdCUjCWriQSKKOm8Wr378FIEnDvtEDYSWyF+40gdZX+8iIM 1OXWfHlMg5M/fsZniSVLWmvMrYfcUJNjJTg9b3+oXs2e76fWBuS6Sgw/r7v94adVK/YS d79X3FDg5Z37rZ3FAxjUIdfV/CiiHaPVCIdKjw8T0J51t7dh602Be+Igsy75y09y9uA/ EaVTV38jO3sgt3TTSxEl8YRzwHvnFLZsIzFI1EVvAhSn9X56Gm8oZWAJsSWit5HGL1kb GTww== 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=wIUcUn9NZpZ4AkNdcsel1CBOeLuu/XGaElsnv6eh2k0=; b=hUlnJuPtt7vTzP5UupzFuoUl61dUuNI+DDhF2aG+9DGkwlOA219xffJzvlD8vLpSQa rWqxc6SkNgQfSwdFbcci1fEo9Y1tiJtyHD0IuRu7pwsJSHHrb6khxKHBbyPlAthcl5OS 7opmZK1exqadW2RAjnjBdUqhDhTRdUHgwKsQGGNlrM7DkmkIfqoi+/wHErzFmP6GkU71 lZ7CxIROGH35srQZlCutUALoWWkb9dHMRACB1jeyE1YQtxB8h+FTFUJi6vwb0OvHuJ50 HsXbbaPa8eMdQinsP4/2l7jfJ06CoMJ/QEcbRlwtNGUq20pK2bu0dXu58YqlULbt1IyP RfNw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gmail.com header.s=20161025 header.b="Mq/SKHN1"; 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 h16si15289008pgh.283.2018.12.18.22.03.52; Tue, 18 Dec 2018 22:04:07 -0800 (PST) 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="Mq/SKHN1"; 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 S1727909AbeLSGB6 (ORCPT + 99 others); Wed, 19 Dec 2018 01:01:58 -0500 Received: from mail-pl1-f195.google.com ([209.85.214.195]:41276 "EHLO mail-pl1-f195.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1725290AbeLSGB6 (ORCPT ); Wed, 19 Dec 2018 01:01:58 -0500 Received: by mail-pl1-f195.google.com with SMTP id u6so8969721plm.8; Tue, 18 Dec 2018 22:01:57 -0800 (PST) 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=wIUcUn9NZpZ4AkNdcsel1CBOeLuu/XGaElsnv6eh2k0=; b=Mq/SKHN1Pa1jJV/gK8xYyQVVXSeSxSKLvUSNyDtEOSaTc51svpF4JLwagxE6Bwk5lo VsaZ9UNZuPx8c3y00lXdiYWuuaUKe3QhReyuFBv8y0vlFtx6SIa2RyGnzeWRgEStNuoN CpAwEq+uNe5HD6WE5dVlGMqsM2exDcEgsrHF6mxFusok3NFt+emtb/z6RsAqffk+PF4l moehez3veCXjdUVyzd1LAjwRXWF1BwHYJ4/6gO0Ck5chBb1ey4Zl8z661XPSZna9bjsu 3GXC/9gYm7hKq2V2jAObn98i9AFSvWv4QWUJDsRLj4Gk0qzP5hLroKo+pV3OQ+iyAFDm gesQ== 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=wIUcUn9NZpZ4AkNdcsel1CBOeLuu/XGaElsnv6eh2k0=; b=ex80MNp8ErLIj26a5k1nPQM8+KYqFTLisum8O7CHjMYfrw4eg1G1tLfSPaQSd5hN/8 0u5tmg8lYISIlFxsQ5D2fAv+GMjLk524DCPIW3PChJgmj8rb0RX8JXVlnOkA6PiKsHl+ WVltgt8ruaH9mTJvkWUcHNkYubWpFgMFKpe+C6QX9qZ0o1J3nZ0NWPXQc8PUt8fApsV3 wUy1lSTCsffoSOZaBxIVgyqkQ/CmhmNILkaJOFzz4vp7f4aYRXY4zcY/HkYzGzPcp0jk 2CnPv8aEZ3uNRIUlwB6joSeF6j3OHTxBLt/1VAF8+I78LZ/Wk6cYKKrurOWMxmY4oYJf X/Fw== X-Gm-Message-State: AA+aEWblyTIOeWhDHLSjITwpp2mXxD/rb9U5PGXOGCwKVJaIz6zGEFSu pxdAMOBRN4tFeTLyvCrV2Xo= X-Received: by 2002:a17:902:7614:: with SMTP id k20mr19383438pll.285.1545199317307; Tue, 18 Dec 2018 22:01:57 -0800 (PST) Received: from localhost.localdomain ([2001:268:c0a2:eb51:6018:45d4:55a2:e94b]) by smtp.gmail.com with ESMTPSA id r12sm19801353pgv.83.2018.12.18.22.01.54 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Tue, 18 Dec 2018 22:01:56 -0800 (PST) From: William Breathitt Gray To: linus.walleij@linaro.org Cc: akpm@linux-foundation.org, 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: [PATCH v6 7/8] gpio: pci-idio-16: Utilize for_each_set_clump8 macro Date: Wed, 19 Dec 2018 15:02:21 +0900 Message-Id: <20f43bb1c4b9d7b5f0a0cd044258f2eec8c68a2a.1545198260.git.vilhelm.gray@gmail.com> X-Mailer: git-send-email 2.20.1 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_clump8 macro to simplify code and improve clarity. Signed-off-by: William Breathitt Gray --- drivers/gpio/gpio-pci-idio-16.c | 73 ++++++++++++--------------------- 1 file changed, 26 insertions(+), 47 deletions(-) diff --git a/drivers/gpio/gpio-pci-idio-16.c b/drivers/gpio/gpio-pci-idio-16.c index 6b7349783223..4eb89f8b5f9b 100644 --- a/drivers/gpio/gpio-pci-idio-16.c +++ b/drivers/gpio/gpio-pci-idio-16.c @@ -108,45 +108,23 @@ static int idio_16_gpio_get_multiple(struct gpio_chip *chip, unsigned long *mask, unsigned long *bits) { 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; + unsigned int offset; + unsigned long gpio_mask; void __iomem *ports[] = { &idio16gpio->reg->out0_7, &idio16gpio->reg->out8_15, &idio16gpio->reg->in0_7, &idio16gpio->reg->in8_15, }; + void __iomem *port_addr; + 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; + for_each_set_clump8(offset, gpio_mask, mask, ARRAY_SIZE(ports) * 8) { + port_addr = ports[offset / 8]; + port_state = ioread8(port_addr) & gpio_mask; - /* 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 */ - port_state = ioread8(ports[i]); - - /* store acquired bits at respective bits array offset */ - bits[word_index] |= (port_state << word_offset) & word_mask; + bitmap_set_value8(bits, &port_state, offset); } return 0; @@ -186,30 +164,31 @@ 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); + unsigned int offset; + unsigned long gpio_mask; + void __iomem *ports[] = { + &idio16gpio->reg->out0_7, &idio16gpio->reg->out8_15, + }; + size_t index; + void __iomem *port_addr; + unsigned int bitmask; unsigned long flags; unsigned int out_state; - raw_spin_lock_irqsave(&idio16gpio->lock, flags); + for_each_set_clump8(offset, gpio_mask, mask, ARRAY_SIZE(ports) * 8) { + index = offset / 8; + port_addr = ports[index]; - /* 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); - } + bitmask = bitmap_get_value8(bits, offset) & gpio_mask; + + raw_spin_lock_irqsave(&idio16gpio->lock, flags); - /* shift to next output line word */ - *mask >>= 8; + out_state = ioread8(port_addr) & ~gpio_mask; + out_state |= bitmask; + iowrite8(out_state, port_addr); - /* 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.20.1