Received: by 2002:ac0:aed5:0:0:0:0:0 with SMTP id t21csp1605710imb; Sat, 2 Mar 2019 23:50:56 -0800 (PST) X-Google-Smtp-Source: AHgI3IaU8v+yQyhXxgOcZs3Ph3MMBReN/ftnYqF05eTg4v6VU3LUcnxLL7rPB7O7Z+TaZ07kkmOs X-Received: by 2002:a62:e086:: with SMTP id d6mr14136411pfm.247.1551599456814; Sat, 02 Mar 2019 23:50:56 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1551599456; cv=none; d=google.com; s=arc-20160816; b=s+3mZG8Mxz7eCP4XtFNkS2M7+BYUqnYJAI+j7dSqyy/f5Xf//fi6onmYcKqYfAsGHW UsREJxCCninLj4Lj+/JXxav5wd+GmlqAEiUHsW23AICBKyyCqLoL/mxHDP6jgZ4XDpnV J/l19cGpCqr9rtl8M4wBuKSxhVvLLrozk2IJ7kKTHIc5exWlPigQ9LExssPaqX3fdsQH I4N29Rzp+HpNAaVnHj052+gzBwgia34rzEww7sgoIhR56D/83l907i/OAJBQtMdqx1SD 4L82KSTOfOdkNeLxBcwHAk8QFa0w7ob0WoaYy8WrFHGUrhyfgP7g5Uciiw9vLwJP3dfK f99w== 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=LbAhFB9V6BisOLUTsbpvSet6qgSjh9MdQ4kQbff2Dwk=; b=TxBAlEeEczJlVjSjG0HYf4nwCN8mN9x1UDQtDLO36dIWWAI117l4LiOQr/y96C7LTS GQh6C/T3Sb7/8Np6MKvUSaHNJuXPAPUNn64O0d1mIYDDH2ihDJzkr6JZmGqMK1wyKdyL kJ62Ym8WectiHWeNp614r1BPtrHF/ZLcm7HeJ7MPsG1j0DWMQ5VmuX7vTb4q+h9xvumR 17mzqEbIAyJ7akmn5E59ost2sFNaMc9tzTVZrNLAbfp1R/H6aJ0nGCLk85Zf5204oNXP SgQqV855zuDtCaFzmgnrZovf31TlJdvJbtiXKNDfJCeztPJoMuvJvqdYzP549mBgtaJe aDiQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gmail.com header.s=20161025 header.b="Cu/ZQLm/"; 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 bd4si2438128plb.434.2019.03.02.23.50.41; Sat, 02 Mar 2019 23:50:56 -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="Cu/ZQLm/"; 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 S1726118AbfCCHuU (ORCPT + 99 others); Sun, 3 Mar 2019 02:50:20 -0500 Received: from mail-pg1-f196.google.com ([209.85.215.196]:36527 "EHLO mail-pg1-f196.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1725877AbfCCHuT (ORCPT ); Sun, 3 Mar 2019 02:50:19 -0500 Received: by mail-pg1-f196.google.com with SMTP id r124so1031482pgr.3; Sat, 02 Mar 2019 23:50:19 -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=LbAhFB9V6BisOLUTsbpvSet6qgSjh9MdQ4kQbff2Dwk=; b=Cu/ZQLm/PMQ+35N4B+1w2GzVF/wnQbzhvIxAUyvrfaDGjy4s/zcWT78ShgMr7csjUr 6Ilv7n8l9iCFRc96ZHkCX762mgNAcxuHZ9Led++XnUtVoZA8ZZ0T3JCJbr/RRFgsN+bj hWbKqc8YxkfFf9RmKdqM/LqANEX7CZ/mzFBcnVDv/aBU3jxR4KzEdMpobSMo13Dc0MgJ 2YrLE4rOUZbQwITj6BkPd3IFaJpI1yl7tZyClzUqXcQ+7Z6u4POaiIT/6ykP4i0RVD3P CL1YYaJqDAGPAGw+BNLN5DoYRoaAy1ncPc+G3krHbrpoQQ5WLDO23c5pXVCezrue7iBr 64pw== 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=LbAhFB9V6BisOLUTsbpvSet6qgSjh9MdQ4kQbff2Dwk=; b=hxkB95lMN6OvquGGz8WJ2SUOvHlSygC3PmiDa5RkCloH1s/dQwKa1c79xEZqw0f9ow dByrMy1IQ5StNP+k/pDiodKFWpbdHPrsAbLShS4e/GNOhL56gR2qK5BqceNqnLLgRMBZ kkchs5vcBRpBxp5dv+UrgbY2HpXJCPHxy/APQXvPB55awajk6rzHMPpAx5b2IV5zD3Tt uXUhN498JctbyyzgGDY/Ju+3CnMkAtWG8c52LhI5O2kX62s0rEaRuZcX9e39TwvJAg2v HqUkQ8gfwrXdrOEACPUAIzXm1EBQ/81RKZUwtTY2XUrdvL7kFCOhTqHwrDkbJ4mjH3Y6 UC5g== X-Gm-Message-State: APjAAAXyfMskbM+5NyunqoVxNVVuwKGpruaDLnzeI5sTRtdaZlQX7aQM 8i6Of3Hmy+TdqKbFxbqAAhU= X-Received: by 2002:a65:6149:: with SMTP id o9mr12931211pgv.315.1551599418721; Sat, 02 Mar 2019 23:50:18 -0800 (PST) Received: from localhost.localdomain ([2001:268:c0a5:3b5c:c70:4af9:86e2:2]) by smtp.gmail.com with ESMTPSA id y37sm1027068pgk.78.2019.03.02.23.50.14 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Sat, 02 Mar 2019 23:50:18 -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, yamada.masahiro@socionext.com, bgolaszewski@baylibre.com, linux-arm-kernel@lists.infradead.org, William Breathitt Gray Subject: [PATCH v9 7/9] gpio: pci-idio-16: Utilize for_each_set_clump8 macro Date: Sun, 3 Mar 2019 16:51:03 +0900 Message-Id: <98a51320cce75fe3fcc2c716965c86c779ed959c.1551598603.git.vilhelm.gray@gmail.com> X-Mailer: git-send-email 2.21.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_clump8 macro to simplify code and improve clarity. Reviewed-by: Linus Walleij Signed-off-by: William Breathitt Gray --- drivers/gpio/gpio-pci-idio-16.c | 75 ++++++++++++--------------------- 1 file changed, 28 insertions(+), 47 deletions(-) diff --git a/drivers/gpio/gpio-pci-idio-16.c b/drivers/gpio/gpio-pci-idio-16.c index 6b7349783223..b0ed6bb68296 100644 --- a/drivers/gpio/gpio-pci-idio-16.c +++ b/drivers/gpio/gpio-pci-idio-16.c @@ -108,45 +108,24 @@ 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, }; + const unsigned int ngpio = ARRAY_SIZE(ports) * 8; + 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, ngpio) { + 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, ngpio, port_state, offset); } return 0; @@ -186,30 +165,32 @@ 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, + }; + const unsigned int ngpio = ARRAY_SIZE(ports) * 8; + 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, ngpio) { + 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, ngpio, 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.21.0