Received: by 2002:a5b:505:0:0:0:0:0 with SMTP id o5csp1201275ybp; Wed, 9 Oct 2019 10:16:06 -0700 (PDT) X-Google-Smtp-Source: APXvYqw2IaxWAAj0F+wpstTM9BV/vUxo7a9GWS7JeGP/7AmmQPFtLTstfzxMVuhxDMzo34rPe4Ok X-Received: by 2002:a50:ec96:: with SMTP id e22mr4015475edr.109.1570641366092; Wed, 09 Oct 2019 10:16:06 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1570641366; cv=none; d=google.com; s=arc-20160816; b=R4YDDFeB1+KElPJFRTIRXEhiGu5J8E1eCeyOC3ptot1joXxfbXVZlrRwHb6EYBw2ni vvANmgRZU4sC65okRGxvu0j8EM/GSn0A6P7v+wuuIGnUHTx+UtGLtAAUjuFnC+qUwJR6 HBhT+Qs51DoO1sWWyG4RwdTCX27swWLGr2l5O40TCkd/JWu5vsWItKYz7nFTdVTvF8Ag vHnqzrPB7Tsq/yJ/7SIyug1Y8qpu/GmPcBpfehx9TJtdvUisaJrihlpSc8uXB9iMwbYc 6QLqpLnrs//iitfnZCnfoYrJ6fJALa0mTLkcovBi0UQSV1RA378vRhAS+/SNrtQEnBQp Jeyg== 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=kIovLVirYpbsjXR9oN+2msyJPjO/yPvE5mW4qwwn3Bw=; b=NyxRmMOOne6bgCxg7mXEP0oQVDseThBw5nwewS1rBMZ36K9NqDoHJPLyhnWzD3dBlg DWFC/wV6l6KgmTAOrwtSNfvsXXYrhYP7lvItdClofcJHKZgFYrQr+oQa2SyIaz5lGiST FsTcENqRAcUcveJnOtDWndNgUvbomJePG4xU7mjhH+QWOG58DXYzpOxCG4rbElTd9d8I SBpPno7Nl9h3jJ6Zqhx8PS5ASdMDpCIcw38PGUHVRdu6UdQlvrSpcr0VK91DVdQSXcNn mX5ANeyoXndAfW7n1CAzzLhQTseYuBpms2U3hhhxysA5nOu2A8Z155VuXd17J6Vre1nD 6qXg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gmail.com header.s=20161025 header.b=ah1+XT0k; 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 e48si2004525eda.130.2019.10.09.10.15.42; Wed, 09 Oct 2019 10:16:06 -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=ah1+XT0k; 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 S1731928AbfJIRPY (ORCPT + 99 others); Wed, 9 Oct 2019 13:15:24 -0400 Received: from mail-yw1-f68.google.com ([209.85.161.68]:39930 "EHLO mail-yw1-f68.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1731896AbfJIRPT (ORCPT ); Wed, 9 Oct 2019 13:15:19 -0400 Received: by mail-yw1-f68.google.com with SMTP id n11so1087853ywn.6; Wed, 09 Oct 2019 10:15:18 -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=kIovLVirYpbsjXR9oN+2msyJPjO/yPvE5mW4qwwn3Bw=; b=ah1+XT0k8DPclq+S0Z7sEWJaH9LrEz/TnwqaetNaHN1XexeohYnsPCfX3F5PAkWFde udifAlApSRKyTGyq2G1cXzaigaiRiAOBuoE/bcGJhj9vkySCQX9caXluonGaQEPqTGyf DFlD/s0GYVY/DwnM54qbU1+dQoMv8FPVhrW7MGAXT1sxjnL4UH9Psl3cgdq0H6VXr4GC Eub87uyAMboYgJzrMK76SEhMiQQ8Xw6VzvTxQzb53y0H1ZbIgEh3jrYaENwByZHXXjJ6 18rLDkmpgqjGqzkXak5GUx5X6fqGw8EUfkpR7H7JU0rfknTnuM4zW6vuN61Bu8K71xye ueaA== 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=kIovLVirYpbsjXR9oN+2msyJPjO/yPvE5mW4qwwn3Bw=; b=ZbCZ/KSKjfDnkkLQeGHTiGux5rTnA384K7eXXnf1facux7d4mdvcJjHJWdcmL1N33z sZO/hSxOFL/27+pzDJSaGlHR8lnq6dghBzGuP/hdTIM3mGWS+iYZA8vVgmKEmy3l4Ugu 9v4Gpp0qnropV2HzCphC1UdW/DAv3vOBvog8e+eIaj4wwuA+XkfEFgwtj672i+xcLac6 a0+U1Np1/XLerds77LCd+E9Y67xAWZrx2ngRCWbaT4cSoW73+uU8MB16czT4AePPEtCq 8PTRxTXnrdswpTGmeMnRCq7g65w6F6kmfDGT04hR6H4Opz2UUQmcw5DmYn2EVibJaUGT tJUw== X-Gm-Message-State: APjAAAWQwpvUrdQ3SfIEcMiY55fhH6XUSGqTR3uBuN4oXj1cDJ0EfKiJ 9lQDBg17/o2Mih7V7fXIQ6E= X-Received: by 2002:a81:2004:: with SMTP id g4mr3708572ywg.418.1570641318369; Wed, 09 Oct 2019 10:15:18 -0700 (PDT) Received: from localhost.localdomain (072-189-084-142.res.spectrum.com. [72.189.84.142]) by smtp.gmail.com with ESMTPSA id r63sm743292ywg.36.2019.10.09.10.15.16 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 09 Oct 2019 10:15:17 -0700 (PDT) From: William Breathitt Gray To: linus.walleij@linaro.org, bgolaszewski@baylibre.com, akpm@linux-foundation.org Cc: linux-gpio@vger.kernel.org, linux-kernel@vger.kernel.org, linux-arch@vger.kernel.org, andriy.shevchenko@linux.intel.com, linux@rasmusvillemoes.dk, yamada.masahiro@socionext.com, linux-arm-kernel@lists.infradead.org, linux-pm@vger.kernel.org, geert@linux-m68k.org, preid@electromag.com.au, lukas@wunner.de, William Breathitt Gray Subject: [PATCH v18 04/14] gpio: 104-idi-48: Utilize for_each_set_clump8 macro Date: Wed, 9 Oct 2019 13:14:40 -0400 Message-Id: X-Mailer: git-send-email 2.23.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-104-idi-48.c | 36 +++++++--------------------------- 1 file changed, 7 insertions(+), 29 deletions(-) diff --git a/drivers/gpio/gpio-104-idi-48.c b/drivers/gpio/gpio-104-idi-48.c index ff53887bdaa8..bf67040cbbbb 100644 --- a/drivers/gpio/gpio-104-idi-48.c +++ b/drivers/gpio/gpio-104-idi-48.c @@ -85,42 +85,20 @@ static int idi_48_gpio_get_multiple(struct gpio_chip *chip, unsigned long *mask, unsigned long *bits) { struct idi_48_gpio *const idi48gpio = gpiochip_get_data(chip); - size_t i; + unsigned long offset; + unsigned long gpio_mask; static const size_t ports[] = { 0, 1, 2, 4, 5, 6 }; - 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 int 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; + for_each_set_clump8(offset, gpio_mask, mask, ARRAY_SIZE(ports) * 8) { + port_addr = idi48gpio->base + ports[offset / 8]; + port_state = inb(port_addr) & gpio_mask; - /* 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 */ - port_state = inb(idi48gpio->base + 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; -- 2.23.0