Received: by 2002:ad5:474a:0:0:0:0:0 with SMTP id i10csp3675279imu; Tue, 18 Dec 2018 02:14:02 -0800 (PST) X-Google-Smtp-Source: AFSGD/U0tSNy5tIJQtdc9LVXor3qQEP4w/8b/BExZsCipgz31iZztvt6UQGfuobNVoNrarBkyoG4 X-Received: by 2002:a63:4665:: with SMTP id v37mr2414981pgk.425.1545128042189; Tue, 18 Dec 2018 02:14:02 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1545128042; cv=none; d=google.com; s=arc-20160816; b=sD0rKZO0Q59O/ufidbzY42iX8/Spt//qmMJKKTjVWvjcUYQRVivoXMX4y/DS8GjMx3 0PoaqRCyPDaoKy9bQHwfk5nxeAemiInc+EzETLQvBm4Z94axlegYEiAqBJmbfGcF7IGx gpe2VvxWPnNL1qp3YIvodmVvPhQQ2IvXkMUyUjFc+iy21qvuO8gECCkI3/IlH5kfujcu R2nMTONKvXXcwHhIwaqmjBcJj5XxKE2pUuAQSbcNvLZFoh+NKHZ36eMX4GZJe6qJ8AJ2 rVWVuiH9U6gP79iGPMxZAKk4O37+n7ROiyUNJSg+4mynjUlMZ5L6vwTlCY94NlhWUS6G HNmg== 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=eB7spxvnRVzN64veVyAd+oRPwk/YF9AvoB3zSfrDoHQ=; b=fmr/bChrSg73P06ENduB+rWhTC41CHzCZAbqg2OY0omJHM2Pw4IQT271lTwpH5C69c 38TyE/TIW28s3r0L7MShNAJ27yNJ9ScTNvoyzUOi5n5pWwbWeWoMJaC37c+44xftFewY Z8tFat6H0HlvG8vadw3/C/bBy3f/wQonX8Va/9NZPoNkJwIOHcKUHtghVkgLV2msI+dE SM395YIklWfzc6MtdARZJG4ZmY1NXyAtnCw8SsvJUtmzUYbjP8zgZJTh+cxTz3XBY8sj 3ApfcYu6l014RheXTiRLJ50FflYcHcTHTuxec5ZV6gjtAqgBxBB7Ozrtyos2z0d6BobQ gxpA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gmail.com header.s=20161025 header.b=PVHe0mJJ; 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 t20si13230801plj.94.2018.12.18.02.13.46; Tue, 18 Dec 2018 02:14:02 -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=PVHe0mJJ; 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 S1726764AbeLRKMe (ORCPT + 99 others); Tue, 18 Dec 2018 05:12:34 -0500 Received: from mail-pg1-f193.google.com ([209.85.215.193]:37964 "EHLO mail-pg1-f193.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726341AbeLRKMc (ORCPT ); Tue, 18 Dec 2018 05:12:32 -0500 Received: by mail-pg1-f193.google.com with SMTP id g189so7598681pgc.5; Tue, 18 Dec 2018 02:12:31 -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=eB7spxvnRVzN64veVyAd+oRPwk/YF9AvoB3zSfrDoHQ=; b=PVHe0mJJnKQ4CZTVx5O10lu/FZg5OdeoH35Si01XPfW7s77k0MDM89wycUwOVedHCb xOJJjTEIuNRVVSscNWQlpY7ZwziTY7ZwoSrF1WFlqu9kkIz85nLfLL16OTGSQa1VOTJ/ AgaAMBN507tUHv4VTjrW98LCQU0urOArODcHr7NKqQasY14kUE93FBRGqCw8Tlrn1m4u Eegdu4bK396WQWdBvaKs0XIyMVKi+75ZZIjVWSkdolhjBBoA5tHB8bhJQtCnI9Zy0py/ IUBYNF+k9IouW05EJj1iwIfuhVwMRTPQHIQzFi3kKS17LWnX7Zot2Eky+mRpocwnSBhA i24g== 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=eB7spxvnRVzN64veVyAd+oRPwk/YF9AvoB3zSfrDoHQ=; b=OXm8zowePJ4J3/wQxZErZ4uFPUh3cL72TtBSnqtvMAmkj5z4L9/tZIOOesVBotpIHm YMbDkswCgdabUNiauS/s4W+E4tycjSWqaSZty86Q9ewzzKgoFH7X6PuRXMns59xbSj1T z0+Vd2DWonA139yMOkAJQt3+uLDU+9HfX6qfgw7IsIGp8veMtVvlB1DCmDdkkQ9eY3QU Tilji0WSQGlrFICEcdW8ZwRQDj+lIbvBQcX1v6zYy7L1aLRmHVLJVUAf4QX/ASJxkZ7n iUwsUxy9uWCDP0bc0owhMH8wYS6fsgoH/FotejYmv5/JC2P80eXNJSvQO6sr/vAU//x8 5NtA== X-Gm-Message-State: AA+aEWZsBV8vQFMfGoYectTOtd2FTbRKyd7PtXB5ex7colZ/ZdEvLmAa slYCmHxIPxCq9yceBUt3ghA= X-Received: by 2002:a62:5dd1:: with SMTP id n78mr15802212pfj.58.1545127951505; Tue, 18 Dec 2018 02:12:31 -0800 (PST) Received: from localhost.localdomain ([2001:268:c0a5:b5e9:3c79:e26e:bf45:b953]) by smtp.gmail.com with ESMTPSA id t67sm26244979pfd.90.2018.12.18.02.12.28 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Tue, 18 Dec 2018 02:12:31 -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 v5 4/8] gpio: 104-idi-48: Utilize for_each_set_clump8 macro Date: Tue, 18 Dec 2018 19:13:01 +0900 Message-Id: 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-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 88dc6f2449f6..fdf1b8b64cc4 100644 --- a/drivers/gpio/gpio-104-idi-48.c +++ b/drivers/gpio/gpio-104-idi-48.c @@ -93,42 +93,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 int 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.20.1