From patchwork Sun Mar 3 07:48:36 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: William Breathitt Gray X-Patchwork-Id: 10836983 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 04D111575 for ; Sun, 3 Mar 2019 07:48:01 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id E165D2A52D for ; Sun, 3 Mar 2019 07:48:00 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id D055E2A52F; Sun, 3 Mar 2019 07:48:00 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-5.2 required=2.0 tests=BAYES_00,DKIM_ADSP_CUSTOM_MED, DKIM_SIGNED,DKIM_VALID,FREEMAIL_FROM,MAILING_LIST_MULTI,RCVD_IN_DNSWL_MED autolearn=ham version=3.3.1 Received: from bombadil.infradead.org (bombadil.infradead.org [198.137.202.133]) (using TLSv1.2 with cipher AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.wl.linuxfoundation.org (Postfix) with ESMTPS id 406CC2A52D for ; Sun, 3 Mar 2019 07:48:00 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20170209; h=Sender: Content-Transfer-Encoding:Content-Type:Cc:List-Subscribe:List-Help:List-Post: List-Archive:List-Unsubscribe:List-Id:MIME-Version:References:In-Reply-To: Message-Id:Date:Subject:To:From:Reply-To:Content-ID:Content-Description: Resent-Date:Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID: List-Owner; bh=oq/2+P7lEOa9ZL7OvXd1p1OPe3Ukr7b4yRP6j5yHvsc=; b=MzESkx9azEh3qn jvzh2ZRHmtHfYWz+eSLnACNXR05JiVFmcgAipM7HzGvQy7AqKH4EePTk7NGl6owCO4fzUuzKNlO87 6gIDeWOkPfon5VY4yDk/pn5vEMmzAnSPiOlHvAzI88bnDj/cnN4/ZNCOSh3cQsFSCCYNLn8jXnMgM XJddPi/l8eCzvlsI4sRB3ATXzZrDdLIS9Xj8sGM/S9QrUW4F14P0gID2/HHlHR3nrcBRzS4H3efin bHBoR8e58+/e7n3DV1vV4Mx3V0qPNJ1gES7Sg62W5578tdVaQRBk6VnhNWYqOs1sCwKQyxaAnU+/6 k0lDQw7uhLiChqLC6sXQ==; Received: from localhost ([127.0.0.1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.90_1 #2 (Red Hat Linux)) id 1h0Lqi-0008C4-7i; Sun, 03 Mar 2019 07:47:52 +0000 Received: from mail-pf1-x443.google.com ([2607:f8b0:4864:20::443]) by bombadil.infradead.org with esmtps (Exim 4.90_1 #2 (Red Hat Linux)) id 1h0Lqf-0008Bh-EX for linux-arm-kernel@lists.infradead.org; Sun, 03 Mar 2019 07:47:51 +0000 Received: by mail-pf1-x443.google.com with SMTP id i19so974800pfd.0 for ; Sat, 02 Mar 2019 23:47:49 -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=5ShWnQ4n5foUkzD6q0EUYaaxbLy/TY+i7Ft3bXpmfRg=; b=K3s/GXb+qCLU0tBYbjBhACOHRqxVXy2BWt5nyY+EvGvmDBAC7MK9VBL/i9RznuxDjb 1RWbpzO1U2Yn7QVl+uUxTwp2Lh3HJZCuy1YsIQ+SnBUBW+OSxZ47/stUiOUO1X24WApq kUpZmhyburujHHRvLdYqnB6KXa6+PJH1SF93j9FUT8Zts5rQf2RcQ46nZscCTFjljzEu M3CoCh/u7zsq9wqWYQF4W0llTsv/YS10EYOrCfCDlpCE91P51dqtXii2ghQHWOckIPe1 FyuyzDMT0DXMpv8gtxsVodAw8oPkNg/2X1sQxVj1ODG1pV0zkIyKX392ccLS28bpeedJ Xp8A== 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=5ShWnQ4n5foUkzD6q0EUYaaxbLy/TY+i7Ft3bXpmfRg=; b=oRwGtPqVDZODmBPu5igI0TC73iBCffj+9qp2Hv8hsw/M7mDYjHfZppCC8y/DooTh0o Z2vtTPJ25GPF38vPBHqn122WwmrAT2yypfqjOjM8YtszJ6asxCGtkESVa141Op3/a0ck 0ePqrzUrfYSi8xRu0odwEKlH7IRDSGHvQsaxy1/6lcRJ7ZMhmmt7RROnjfrSU4aqccqJ khZ9ufcooBcwi4y3L3R1RALjNsJxziPAIk9hsvslippI8RNAL6g8pF1lT0ZyMFzQPLPC X/FwpFszn8BhpBNF7oP1fXXHGP7EqZX1IweoOp3Tp29o8UrDahaMFnTwUq8xgZF1E0OT nXrA== X-Gm-Message-State: APjAAAX/UFoi/bH/yxN9jHvTBbKRQFCwpln7+DnB/rb10FDNrClF2FDh DP63nGW6nBhXFTSQQ6wBZtg= X-Google-Smtp-Source: APXvYqwSy53757lsDFOC+awhk1BMnvhr27fsGj+61YyFheroHA9PEVmgQnFH9Af4uXRvS4HNYIogqQ== X-Received: by 2002:a63:8042:: with SMTP id j63mr12561873pgd.36.1551599269023; Sat, 02 Mar 2019 23:47:49 -0800 (PST) Received: from localhost.localdomain ([2001:268:c0a5:3b5c:c70:4af9:86e2:2]) by smtp.gmail.com with ESMTPSA id s1sm3443392pgv.30.2019.03.02.23.47.43 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Sat, 02 Mar 2019 23:47:48 -0800 (PST) From: William Breathitt Gray To: linus.walleij@linaro.org Subject: [PATCH v9 1/9] bitops: Introduce the for_each_set_clump8 macro Date: Sun, 3 Mar 2019 16:48:36 +0900 Message-Id: <12b3a364ac7fc32194fa6f55911dd800aca92a56.1551598603.git.vilhelm.gray@gmail.com> X-Mailer: git-send-email 2.21.0 In-Reply-To: References: MIME-Version: 1.0 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20190302_234749_483190_E75E2443 X-CRM114-Status: GOOD ( 15.60 ) X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: linux-arch@vger.kernel.org, Arnd Bergmann , yamada.masahiro@socionext.com, linux@rasmusvillemoes.dk, linux-kernel@vger.kernel.org, William Breathitt Gray , linux-gpio@vger.kernel.org, Andy Shevchenko , bgolaszewski@baylibre.com, akpm@linux-foundation.org, andriy.shevchenko@linux.intel.com, linux-arm-kernel@lists.infradead.org Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+patchwork-linux-arm=patchwork.kernel.org@lists.infradead.org X-Virus-Scanned: ClamAV using ClamSMTP This macro iterates for each 8-bit group of bits (clump) with set bits, within a bitmap memory region. For each iteration, "start" is set to the bit offset of the found clump, while the respective clump value is stored to the location pointed by "clump". Additionally, the bitmap_get_value8 and bitmap_set_value8 functions are introduced to respectively get and set an 8-bit value in a bitmap memory region. Suggested-by: Andy Shevchenko Suggested-by: Rasmus Villemoes Cc: Arnd Bergmann Cc: Andrew Morton Reviewed-by: Andy Shevchenko Reviewed-by: Linus Walleij Signed-off-by: William Breathitt Gray --- include/asm-generic/bitops/find.h | 14 ++++++ include/linux/bitops.h | 5 ++ lib/find_bit.c | 81 +++++++++++++++++++++++++++++++ 3 files changed, 100 insertions(+) diff --git a/include/asm-generic/bitops/find.h b/include/asm-generic/bitops/find.h index 8a1ee10014de..9a76adff59c6 100644 --- a/include/asm-generic/bitops/find.h +++ b/include/asm-generic/bitops/find.h @@ -80,4 +80,18 @@ extern unsigned long find_first_zero_bit(const unsigned long *addr, #endif /* CONFIG_GENERIC_FIND_FIRST_BIT */ +unsigned long bitmap_get_value8(const unsigned long *const bitmap, + const unsigned int size, + const unsigned int start); + +void bitmap_set_value8(unsigned long *const bitmap, const unsigned int size, + const unsigned long value, const unsigned int start); + +unsigned int find_next_clump8(unsigned long *const clump, + const unsigned long *const addr, + unsigned int offset, const unsigned int size); + +#define find_first_clump8(clump, bits, size) \ + find_next_clump8((clump), (bits), 0, (size)) + #endif /*_ASM_GENERIC_BITOPS_FIND_H_ */ diff --git a/include/linux/bitops.h b/include/linux/bitops.h index 705f7c442691..61c10f20079e 100644 --- a/include/linux/bitops.h +++ b/include/linux/bitops.h @@ -40,6 +40,11 @@ extern unsigned long __sw_hweight64(__u64 w); (bit) < (size); \ (bit) = find_next_zero_bit((addr), (size), (bit) + 1)) +#define for_each_set_clump8(start, clump, bits, size) \ + for ((start) = find_first_clump8(&(clump), (bits), (size)); \ + (start) < (size); \ + (start) = find_next_clump8(&(clump), (bits), (start) + 8, (size))) + static inline int get_bitmask_order(unsigned int count) { int order; diff --git a/lib/find_bit.c b/lib/find_bit.c index ee3df93ba69a..c2af1f013ea2 100644 --- a/lib/find_bit.c +++ b/lib/find_bit.c @@ -218,3 +218,84 @@ EXPORT_SYMBOL(find_next_bit_le); #endif #endif /* __BIG_ENDIAN */ + +/** + * bitmap_get_value8 - get an 8-bit value within a memory region + * @bitmap: address to the bitmap memory region + * @size: bitmap size in number of bits + * @start: bit offset of the 8-bit value + * + * Returns the 8-bit value located at the @start bit offset within the @bitmap + * memory region. + */ +unsigned long bitmap_get_value8(const unsigned long *const bitmap, + const unsigned int size, + const unsigned int start) +{ + const size_t index = BIT_WORD(start); + const unsigned int offset = start % BITS_PER_LONG; + const unsigned int low_width = (offset + 8 > BITS_PER_LONG) ? + BITS_PER_LONG - offset : 8; + const unsigned long low = bitmap[index] >> offset; + const unsigned long high = (low_width < 8 && start + 8 <= size) ? + bitmap[index + 1] << low_width : 0; + + return (low | high) & 0xFF; +} +EXPORT_SYMBOL(bitmap_get_value8); + +/** + * bitmap_set_value8 - set an 8-bit value within a memory region + * @bitmap: address to the bitmap memory region + * @size: bitmap size in number of bits + * @value: the 8-bit value; values wider than 8 bits may clobber bitmap + * @start: bit offset of the 8-bit value + */ +void bitmap_set_value8(unsigned long *const bitmap, const unsigned int size, + const unsigned long value, const unsigned int start) +{ + const size_t index = BIT_WORD(start); + const unsigned int offset = start % BITS_PER_LONG; + const unsigned int low_width = (offset + 8 > BITS_PER_LONG) ? + BITS_PER_LONG - offset : 8; + const unsigned long low_mask = GENMASK(offset + low_width - 1, offset); + const unsigned int high_width = 8 - low_width; + const unsigned long high_mask = GENMASK(high_width - 1, 0); + + /* set lower portion */ + bitmap[index] &= ~low_mask; + bitmap[index] |= value << offset; + + /* set higher portion if space available in bitmap */ + if (high_width && start + 8 <= size) { + bitmap[index + 1] &= ~high_mask; + bitmap[index + 1] |= value >> low_width; + } +} +EXPORT_SYMBOL(bitmap_set_value8); + +/** + * find_next_clump8 - find next 8-bit clump with set bits in a memory region + * @clump: location to store copy of found clump + * @addr: address to base the search on + * @offset: bit offset at which to start searching + * @size: bitmap size in number of bits + * + * Returns the bit offset for the next set clump; the found clump value is + * copied to the location pointed by @clump. If no bits are set, returns @size. + */ +unsigned int find_next_clump8(unsigned long *const clump, + const unsigned long *const addr, + unsigned int offset, const unsigned int size) +{ + for (; offset < size; offset += 8) { + *clump = bitmap_get_value8(addr, size, offset); + if (!*clump) + continue; + + return offset; + } + + return size; +} +EXPORT_SYMBOL(find_next_clump8); From patchwork Sun Mar 3 07:48:54 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: William Breathitt Gray X-Patchwork-Id: 10836985 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id C162A1575 for ; Sun, 3 Mar 2019 07:48:14 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id AC20A2A52D for ; Sun, 3 Mar 2019 07:48:14 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 9E52A2A52F; Sun, 3 Mar 2019 07:48:14 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-5.2 required=2.0 tests=BAYES_00,DKIM_ADSP_CUSTOM_MED, DKIM_SIGNED,DKIM_VALID,FREEMAIL_FROM,MAILING_LIST_MULTI,RCVD_IN_DNSWL_MED autolearn=ham version=3.3.1 Received: from bombadil.infradead.org (bombadil.infradead.org [198.137.202.133]) (using TLSv1.2 with cipher AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.wl.linuxfoundation.org (Postfix) with ESMTPS id 304432A52D for ; Sun, 3 Mar 2019 07:48:14 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20170209; h=Sender: Content-Transfer-Encoding:Content-Type:Cc:List-Subscribe:List-Help:List-Post: List-Archive:List-Unsubscribe:List-Id:MIME-Version:References:In-Reply-To: Message-Id:Date:Subject:To:From:Reply-To:Content-ID:Content-Description: Resent-Date:Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID: List-Owner; bh=2W94OZMPcH2ptpAzoAEWY+ygJCv7fiy5KF/I6aVgz4o=; b=iV+KAJZhTS1nB3 kDAzsaVHTXAkWCj+fijWNKCndWi8/DMkQhMQgt4X3g3MWWkLZ1tFRO4waTYopLIUKbN+/iCZAhIYZ ZGmPK7xqus2Z74shYFiMxrKIJlUkNZ7LRHz6MHjYyXebNShnAX/3IeDAHMTagdatG21Q+EROZIwEU /KkF5lRZ3Rf3HnCSvwQIkmapS3VH6fLD1BOO/nEsWjagC98/7WcZRTDAmYnQb8Wz36EO+2BxT0x5Y 0mw54a5Llm8HWer9XYtuyx8DZ4Yq2NWUp4rgmk8bJkGaKIVY8FNUaoclmIVNhKh5F195Uma26sr8t t254ntaFZqIxTqfUxvrg==; Received: from localhost ([127.0.0.1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.90_1 #2 (Red Hat Linux)) id 1h0Lqz-0008SE-EH; Sun, 03 Mar 2019 07:48:09 +0000 Received: from mail-pg1-x544.google.com ([2607:f8b0:4864:20::544]) by bombadil.infradead.org with esmtps (Exim 4.90_1 #2 (Red Hat Linux)) id 1h0Lqw-0008RS-Db for linux-arm-kernel@lists.infradead.org; Sun, 03 Mar 2019 07:48:08 +0000 Received: by mail-pg1-x544.google.com with SMTP id r124so1030244pgr.3 for ; Sat, 02 Mar 2019 23:48:06 -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=ElsNjzQ7K98lI/bHz/nS5DIDC37ffsppngWHxCUh4y8=; b=Pg2kb3SyiFiHaFONBSKyoKCSYn7k0JkY9T1bWjWkklQDuMf7SeigsW9psZ0MXIdi0o OIjXZv3fYQ/Ned1bAUGm6ZmxS2HgRyHUikRiaL2i5+EuW2s1G7iQUAH+2fKJj5hhHW2b oXEnxot/6EFeD5V/BpKdXCN+bDX3f36684GL654E0rOJqZ/IukC/xTI3ve8ElTjKg5pY pvcE71lkFAXer8x8c9B+KU6KYARhGjUuPp6yjelZyUh8NBStcprLtne1/NOPSFB3Gstn IKuVYH1uBrArLWTwbucdd8FvOOACQ5GvwG15V2BCugcj8A+OUjv2j14psCvQkvUSv+ER rOnw== 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=ElsNjzQ7K98lI/bHz/nS5DIDC37ffsppngWHxCUh4y8=; b=XkWdNiTh/WRhlIaopZf/V421CdVFIZ4ZOqT8XKj/XbMpcrq0yOx3M2ZwjROAH7Ias5 UHsWxWhewqzpEJnlrfqbAz0Ec6HSyP9gafeS7Am7le+IsNi3rBerCBAu6i+D9iOBs+qb KohXtPrLS1b9Hg+Z7daas7aq4z4XoORiQUm3m+5b+qtA3FqhYpiZ2AOUnHmGoc9+BEwS KPqNjc33XI6UdZoXmhu6QVT9prkagDlKRc9xCO3wU44JK/XozF7z98Zkmge1MrzrO+0K 9j+sprmHt8/K9SctMuPY4+R8bNXJspm7yi6DdIC4z0MjNhY3f30weahjH/1u81a+g3nh BfOQ== X-Gm-Message-State: APjAAAXykkW/XB210RPkO9BrkohdIlbn9Sbk4Wa8Jd6yXnd/uDC+VRWa 0+9U/W25axMglxNpehjH7Gg= X-Google-Smtp-Source: APXvYqwSltqoEw9JKp+yIsusA5L0KKE4BlpoSKKUPKWyfM62T0xKFe79n2gcx85OxQve/J1AyinmKA== X-Received: by 2002:a63:d49:: with SMTP id 9mr12937777pgn.27.1551599285644; Sat, 02 Mar 2019 23:48:05 -0800 (PST) Received: from localhost.localdomain ([2001:268:c0a5:3b5c:c70:4af9:86e2:2]) by smtp.gmail.com with ESMTPSA id b7sm4572950pfi.36.2019.03.02.23.48.00 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Sat, 02 Mar 2019 23:48:05 -0800 (PST) From: William Breathitt Gray To: linus.walleij@linaro.org Subject: [PATCH v9 2/9] lib/test_bitmap.c: Add for_each_set_clump8 test cases Date: Sun, 3 Mar 2019 16:48:54 +0900 Message-Id: X-Mailer: git-send-email 2.21.0 In-Reply-To: References: MIME-Version: 1.0 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20190302_234806_454573_8A561CB4 X-CRM114-Status: GOOD ( 14.82 ) X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: linux-arch@vger.kernel.org, yamada.masahiro@socionext.com, linux@rasmusvillemoes.dk, linux-kernel@vger.kernel.org, William Breathitt Gray , linux-gpio@vger.kernel.org, Andy Shevchenko , bgolaszewski@baylibre.com, akpm@linux-foundation.org, andriy.shevchenko@linux.intel.com, linux-arm-kernel@lists.infradead.org Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+patchwork-linux-arm=patchwork.kernel.org@lists.infradead.org X-Virus-Scanned: ClamAV using ClamSMTP The introduction of the for_each_set_clump8 macro warrants test cases to verify the implementation. This patch adds test case checks for whether an out-of-bounds clump index is returned, a zero clump is returned, or the returned clump value differs from the expected clump value. Cc: Andrew Morton Cc: Rasmus Villemoes Reviewed-by: Andy Shevchenko Reviewed-by: Linus Walleij Signed-off-by: William Breathitt Gray --- lib/test_bitmap.c | 65 +++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 65 insertions(+) diff --git a/lib/test_bitmap.c b/lib/test_bitmap.c index 6cd7d0740005..66ddb3fb98cb 100644 --- a/lib/test_bitmap.c +++ b/lib/test_bitmap.c @@ -88,6 +88,36 @@ __check_eq_u32_array(const char *srcfile, unsigned int line, return true; } +static bool __init __check_eq_clump8(const char *srcfile, unsigned int line, + const unsigned int offset, + const unsigned int size, + const unsigned char *const clump_exp, + const unsigned long *const clump) +{ + unsigned long exp; + + if (offset >= size) { + pr_warn("[%s:%u] bit offset for clump out-of-bounds: expected less than %u, got %u\n", + srcfile, line, size, offset); + return false; + } + + exp = clump_exp[offset / 8]; + if (!exp) { + pr_warn("[%s:%u] bit offset for zero clump: expected nonzero clump, got bit offset %u with clump value 0", + srcfile, line, offset); + return false; + } + + if (*clump != exp) { + pr_warn("[%s:%u] expected clump value of 0x%lX, got clump value of 0x%lX", + srcfile, line, exp, *clump); + return false; + } + + return true; +} + #define __expect_eq(suffix, ...) \ ({ \ int result = 0; \ @@ -104,6 +134,7 @@ __check_eq_u32_array(const char *srcfile, unsigned int line, #define expect_eq_bitmap(...) __expect_eq(bitmap, ##__VA_ARGS__) #define expect_eq_pbl(...) __expect_eq(pbl, ##__VA_ARGS__) #define expect_eq_u32_array(...) __expect_eq(u32_array, ##__VA_ARGS__) +#define expect_eq_clump8(...) __expect_eq(clump8, ##__VA_ARGS__) static void __init test_zero_clear(void) { @@ -361,6 +392,39 @@ static void noinline __init test_mem_optimisations(void) } } +static const unsigned char clump_exp[] __initconst = { + 0x01, /* 1 bit set */ + 0x02, /* non-edge 1 bit set */ + 0x00, /* zero bits set */ + 0x28, /* 3 bits set across 4-bit boundary */ + 0x28, /* Repeated clump */ + 0x0F, /* 4 bits set */ + 0xFF, /* all bits set */ + 0x05, /* non-adjacent 2 bits set */ +}; + +static void __init test_for_each_set_clump8(void) +{ +#define CLUMP_EXP_NUMBITS 64 + DECLARE_BITMAP(bits, CLUMP_EXP_NUMBITS); + unsigned int start; + unsigned long clump; + + /* set bitmap to test case */ + bitmap_zero(bits, CLUMP_EXP_NUMBITS); + bitmap_set(bits, 0, 1); /* 0x01 */ + bitmap_set(bits, 8, 1); /* 0x02 */ + bitmap_set(bits, 27, 3); /* 0x28 */ + bitmap_set(bits, 35, 3); /* 0x28 */ + bitmap_set(bits, 40, 4); /* 0x0F */ + bitmap_set(bits, 48, 8); /* 0xFF */ + bitmap_set(bits, 56, 1); /* 0x05 - part 1 */ + bitmap_set(bits, 58, 1); /* 0x05 - part 2 */ + + for_each_set_clump8(start, clump, bits, CLUMP_EXP_NUMBITS) + expect_eq_clump8(start, CLUMP_EXP_NUMBITS, clump_exp, &clump); +} + static int __init test_bitmap_init(void) { test_zero_clear(); @@ -369,6 +433,7 @@ static int __init test_bitmap_init(void) test_bitmap_arr32(); test_bitmap_parselist(); test_mem_optimisations(); + test_for_each_set_clump8(); if (failed_tests == 0) pr_info("all %u tests passed\n", total_tests); From patchwork Sun Mar 3 07:49:12 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: William Breathitt Gray X-Patchwork-Id: 10836987 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 931191669 for ; Sun, 3 Mar 2019 07:48:37 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 7C0932A52D for ; Sun, 3 Mar 2019 07:48:37 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 6A7C82A52F; Sun, 3 Mar 2019 07:48:37 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-5.2 required=2.0 tests=BAYES_00,DKIM_ADSP_CUSTOM_MED, DKIM_SIGNED,DKIM_VALID,FREEMAIL_FROM,MAILING_LIST_MULTI,RCVD_IN_DNSWL_MED autolearn=ham version=3.3.1 Received: from bombadil.infradead.org (bombadil.infradead.org [198.137.202.133]) (using TLSv1.2 with cipher AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.wl.linuxfoundation.org (Postfix) with ESMTPS id F0D1E2A52D for ; Sun, 3 Mar 2019 07:48:36 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20170209; h=Sender: Content-Transfer-Encoding:Content-Type:Cc:List-Subscribe:List-Help:List-Post: List-Archive:List-Unsubscribe:List-Id:MIME-Version:References:In-Reply-To: Message-Id:Date:Subject:To:From:Reply-To:Content-ID:Content-Description: Resent-Date:Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID: List-Owner; bh=8S1NRFXAry7OT1sEQgnbr77coxWRoNIKo3aUm4nxjFs=; b=njFPc4WKiMaxmX q1ouegL4hdn7VPd8FU8HZ32RMFVm9wxBVFkmku4WdGFOeXLnEtZmgccpdaSbEzJCF2yc071OkZden jadFSi3xYXXvCvlby9DfA8wmeczCo2slVglkm7Aw5TrckxDeF4GE5zRQelP5ldzmXDM+DEXbZXPQw 5Cd/+eKnu8sMsfGsZUVuvbTxhGHFNV6bxJdHytfKJfdgxyLpJH8cSlgsm0D/659K6xsQO9Icp6kKx JRgdWraiAny31COEfqL9Mrwfk/b+b2Az+J9wBS0GkaKPh/otytSvl95GsyaMhCBDl3a+z8ZoDhpb3 RiGwlqy+1pYpadZ5+JyA==; Received: from localhost ([127.0.0.1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.90_1 #2 (Red Hat Linux)) id 1h0LrM-0000HB-Gb; Sun, 03 Mar 2019 07:48:32 +0000 Received: from mail-pg1-x542.google.com ([2607:f8b0:4864:20::542]) by bombadil.infradead.org with esmtps (Exim 4.90_1 #2 (Red Hat Linux)) id 1h0LrJ-0000Gi-Sz for linux-arm-kernel@lists.infradead.org; Sun, 03 Mar 2019 07:48:31 +0000 Received: by mail-pg1-x542.google.com with SMTP id r124so1030469pgr.3 for ; Sat, 02 Mar 2019 23:48:29 -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=5tnH02Yc3JnragyosQ4LQT3N7xcrc3Yee7t/cF7aZ1U=; b=d5tdHdk/dXVHhpM/iwTFQAMCU6nxjlFGFA75JZfUDSO5n2uwMUpeA2mK27EEw4YDLc nVML3HTHz9YU9l3JtOmcLVfB54Nyqs49wZcW0gbfIpy/oL50NDkGmZTvGgeIjm0YbYVE FnnCpLuEwPETOPqcDi5xDA8dbmRrm41jH8Kb907N8tBgC1VzRsFj82x7o/B/+2rhHjvP MtIJnJLEbtYgFwqVd+ICq/vBGAlG/S4CWEW/RfB1Cv9L1nuxuHQN9tKANt+PhgCKOgBa A2S3eTMWWA3+XsKq2MsEHhKnL8aKBCA9oq/mifPrkS86ZF66DDVOZZIhpTdtFW9OJFi8 E2uA== 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=5tnH02Yc3JnragyosQ4LQT3N7xcrc3Yee7t/cF7aZ1U=; b=AEF9doa2qqHCEbx9L6Lx7N4fUiW3C3cPl5H1YFfT0b6TH51hJYBMnjNOnfpCM3059r +ZOfzzc4zxmihof0N+TqyP51c+tOjtBuEFoCzcqzr6Ysj/58hffhJoQRowzInJevJSRY ccJSOkV2ejObZvBVfiyDJRXZ2rIdOFQThb/nPzvfcKlpsw9cB9FkXaz8eflEe1i5oT22 S8WI1DyAv/+gQXSMCYQFsj3mUyS7SjO3OYR6Ate2wp0uzjvDzg+aNSvGy23Kr4L9QBZP XHlpS81mo6Vz6BatAG+0Nbe6SV6na9C0mMj5jQuL5SrgpljlmUImMK2ODWxUUwulCSb/ 2c1A== X-Gm-Message-State: APjAAAWXuzgk0GjjOvveJhONSPiZdG0j7zs/B5EFFfm12v+niGne+ipu CFGDKIF1Nc5VZ4+mzaKW2pEWBo8UYiA= X-Google-Smtp-Source: APXvYqz3Jsn9xW0QSB6jSVnOf2omraUyY0d2RgaTrdzAJJcObf4dOEla17HZKPdj8LV2z62687lNSg== X-Received: by 2002:a62:1b03:: with SMTP id b3mr14272320pfb.218.1551599309389; Sat, 02 Mar 2019 23:48:29 -0800 (PST) Received: from localhost.localdomain ([2001:268:c0a5:3b5c:c70:4af9:86e2:2]) by smtp.gmail.com with ESMTPSA id y37sm1018524pgk.78.2019.03.02.23.48.23 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Sat, 02 Mar 2019 23:48:28 -0800 (PST) From: William Breathitt Gray To: linus.walleij@linaro.org Subject: [PATCH v9 3/9] gpio: 104-dio-48e: Utilize for_each_set_clump8 macro Date: Sun, 3 Mar 2019 16:49:12 +0900 Message-Id: <9e9563f0d3f627110c0b72620dee2921425967d6.1551598603.git.vilhelm.gray@gmail.com> X-Mailer: git-send-email 2.21.0 In-Reply-To: References: MIME-Version: 1.0 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20190302_234829_932885_CDE07CD2 X-CRM114-Status: GOOD ( 15.02 ) X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: linux-arch@vger.kernel.org, yamada.masahiro@socionext.com, linux@rasmusvillemoes.dk, linux-kernel@vger.kernel.org, William Breathitt Gray , linux-gpio@vger.kernel.org, bgolaszewski@baylibre.com, akpm@linux-foundation.org, andriy.shevchenko@linux.intel.com, linux-arm-kernel@lists.infradead.org Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+patchwork-linux-arm=patchwork.kernel.org@lists.infradead.org X-Virus-Scanned: ClamAV using ClamSMTP 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-dio-48e.c | 73 ++++++++++----------------------- 1 file changed, 22 insertions(+), 51 deletions(-) diff --git a/drivers/gpio/gpio-104-dio-48e.c b/drivers/gpio/gpio-104-dio-48e.c index 92c8f944bf64..23413d90e944 100644 --- a/drivers/gpio/gpio-104-dio-48e.c +++ b/drivers/gpio/gpio-104-dio-48e.c @@ -183,46 +183,26 @@ static int dio48e_gpio_get(struct gpio_chip *chip, unsigned offset) return !!(port_state & mask); } +static const size_t ports[] = { 0, 1, 2, 4, 5, 6 }; + static int dio48e_gpio_get_multiple(struct gpio_chip *chip, unsigned long *mask, unsigned long *bits) { struct dio48e_gpio *const dio48egpio = gpiochip_get_data(chip); - size_t i; - 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 offset; + unsigned long gpio_mask; + const unsigned int ngpio = ARRAY_SIZE(ports) * 8; + 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; - - /* 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(dio48egpio->base + ports[i]); + for_each_set_clump8(offset, gpio_mask, mask, ngpio) { + port_addr = dio48egpio->base + ports[offset / 8]; + port_state = inb(port_addr) & gpio_mask; - /* 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; @@ -252,37 +232,28 @@ static void dio48e_gpio_set_multiple(struct gpio_chip *chip, unsigned long *mask, unsigned long *bits) { struct dio48e_gpio *const dio48egpio = gpiochip_get_data(chip); - unsigned int i; - const unsigned int gpio_reg_size = 8; - unsigned int port; - unsigned int out_port; + unsigned int offset; + unsigned long gpio_mask; + const unsigned int ngpio = ARRAY_SIZE(ports) * 8; + size_t index; + unsigned int port_addr; unsigned int bitmask; unsigned long flags; - /* set bits are evaluated a gpio register size at a time */ - for (i = 0; i < chip->ngpio; i += gpio_reg_size) { - /* no more set bits in this mask word; skip to the next word */ - if (!mask[BIT_WORD(i)]) { - i = (BIT_WORD(i) + 1) * BITS_PER_LONG - gpio_reg_size; - continue; - } + for_each_set_clump8(offset, gpio_mask, mask, ngpio) { + index = offset / 8; + port_addr = dio48egpio->base + ports[index]; - port = i / gpio_reg_size; - out_port = (port > 2) ? port + 1 : port; - bitmask = mask[BIT_WORD(i)] & bits[BIT_WORD(i)]; + bitmask = bitmap_get_value8(bits, ngpio, offset) & gpio_mask; raw_spin_lock_irqsave(&dio48egpio->lock, flags); /* update output state data and set device gpio register */ - dio48egpio->out_state[port] &= ~mask[BIT_WORD(i)]; - dio48egpio->out_state[port] |= bitmask; - outb(dio48egpio->out_state[port], dio48egpio->base + out_port); + dio48egpio->out_state[index] &= ~gpio_mask; + dio48egpio->out_state[index] |= bitmask; + outb(dio48egpio->out_state[index], port_addr); raw_spin_unlock_irqrestore(&dio48egpio->lock, flags); - - /* prepare for next gpio register set */ - mask[BIT_WORD(i)] >>= gpio_reg_size; - bits[BIT_WORD(i)] >>= gpio_reg_size; } } From patchwork Sun Mar 3 07:49:39 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: William Breathitt Gray X-Patchwork-Id: 10836989 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 5E0A41575 for ; Sun, 3 Mar 2019 07:49:02 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 4A3D82A089 for ; Sun, 3 Mar 2019 07:49:02 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 3E99F2A107; Sun, 3 Mar 2019 07:49:02 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-5.2 required=2.0 tests=BAYES_00,DKIM_ADSP_CUSTOM_MED, DKIM_SIGNED,DKIM_VALID,FREEMAIL_FROM,MAILING_LIST_MULTI,RCVD_IN_DNSWL_MED autolearn=ham version=3.3.1 Received: from bombadil.infradead.org (bombadil.infradead.org [198.137.202.133]) (using TLSv1.2 with cipher AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.wl.linuxfoundation.org (Postfix) with ESMTPS id 19EDE2A089 for ; Sun, 3 Mar 2019 07:49:01 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20170209; h=Sender: Content-Transfer-Encoding:Content-Type:Cc:List-Subscribe:List-Help:List-Post: List-Archive:List-Unsubscribe:List-Id:MIME-Version:References:In-Reply-To: Message-Id:Date:Subject:To:From:Reply-To:Content-ID:Content-Description: Resent-Date:Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID: List-Owner; bh=mKZJ1IaY7GlXT9kvyDtjHSZohYXBb+bquG+//QQEco4=; b=TsZQgsOaMoC5Vm +Udu95DnKUhoCt1y+nPMln5iCxcNQxFD5a0OJgV5KGoCWuC2bR3kONdfRkXYHIo3h3urbt3udnWO7 0Iwom+fllha5lWUlpUsBTO4z7hvP3vYT9iP9jQ74Os+8mDzuYYldoBLYEch2uEWo5JAxgeCsWK51/ FC7V8K8gmz304BerDTpIb9fiSLkuBt0H/GFYxUfzktAX8fgNsZgmbkVvac/HVI43qBCX+Dant+F6W 5msrtQLMFaybp7ZI4daVj9vQ+Vw77+xhVPrzYPzNC5VzpHitGWqh1xXU102y0j3fJqyVMi83QMBa/ ptMUdZcpPobEFD7FdUjg==; Received: from localhost ([127.0.0.1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.90_1 #2 (Red Hat Linux)) id 1h0Lrk-0000cs-DG; Sun, 03 Mar 2019 07:48:56 +0000 Received: from mail-pl1-x643.google.com ([2607:f8b0:4864:20::643]) by bombadil.infradead.org with esmtps (Exim 4.90_1 #2 (Red Hat Linux)) id 1h0Lrg-0000c0-P9 for linux-arm-kernel@lists.infradead.org; Sun, 03 Mar 2019 07:48:54 +0000 Received: by mail-pl1-x643.google.com with SMTP id r14so1009026pls.12 for ; Sat, 02 Mar 2019 23:48:52 -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=wovyItwhuu6up6N9d5xqiEvzR3TkCWii5hwPk2X/3Vc=; b=eXiKnpZevNwmTcamVOu5dvTkOTzeJHUS3N7oxCh6oN/eUC/IOXFVHczGOZY8H2SvOW viPL4N0S1C/g4As1/2iqAQTqsfv+d38J4qd3qqdWMFDk6Xbbvkii2F6HjFpYNY2aBnbc jZCgn1XWouMsQvMbdAE7gO78LifKT8C128YaA2pZRvmWBFUflqzJJgrreU/EkDQDlMQM c5G/rnuEjk4PYxWPYI6E8O2ev2mU81LWbY9xRTKq+8TcBVcwsV+ZS4u5ElX5KG1l8qBl ABtV0SlWBwBrSGS1td16eDdY8vmaunw9R0S/coPVgaGvVAyWmTB6qRMTVHWey87B/57Q r+UQ== 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=wovyItwhuu6up6N9d5xqiEvzR3TkCWii5hwPk2X/3Vc=; b=gUboPV5ARUC0DVhyc9vT4ALE3lIoxQbOuMTt+T0fchLuYRIb0vCh6KDcLdyRONLKmN XsGRSEEpFDN3grgP0xnPVHwRuoogdhOBhJCrRfwtLJvfqBYdmu1uUhdgsmrQB3ABaXY5 OiCn57K1ojUgTwueYW6LHvjpXM994fFKYJ+OWdgKTjAU9pvEfwo14YiAAzFtXJbqK1Wq L2mrzjZSvyrRriwcPzRPQXLDMt/9gXwmkSVqhnw2YL/teHw0bSSispgA6EtQVlZg9qvq my3wahqvt57FpHkXcIZMKF4hb7VcbyjRg7o5jbu59rTslJpvOBU3R6FEfAUgPySS/2G3 R7Ug== X-Gm-Message-State: APjAAAU6DCDE/oO2Ps2wcjj5cLlxQ7xEnJcs6htDPKZuum6BCzUYLfDE xdV7n3kRCxfoZGNeX6+Dby0= X-Google-Smtp-Source: APXvYqxKvXnNRkzJ3XKz8Dvb0TZTczUrUD0RwTzhdC44b8wCEU11Ii75h7s7ilHi/hAKi8sdJSYEVg== X-Received: by 2002:a17:902:a414:: with SMTP id p20mr13908371plq.289.1551599332376; Sat, 02 Mar 2019 23:48:52 -0800 (PST) Received: from localhost.localdomain ([2001:268:c0a5:3b5c:c70:4af9:86e2:2]) by smtp.gmail.com with ESMTPSA id f125sm4464483pfc.91.2019.03.02.23.48.48 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Sat, 02 Mar 2019 23:48:51 -0800 (PST) From: William Breathitt Gray To: linus.walleij@linaro.org Subject: [PATCH v9 4/9] gpio: 104-idi-48: Utilize for_each_set_clump8 macro Date: Sun, 3 Mar 2019 16:49:39 +0900 Message-Id: <1292b15bc62e72d01d45e60fbd33a4da850fa2d5.1551598603.git.vilhelm.gray@gmail.com> X-Mailer: git-send-email 2.21.0 In-Reply-To: References: MIME-Version: 1.0 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20190302_234852_814120_3385229B X-CRM114-Status: GOOD ( 14.55 ) X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: linux-arch@vger.kernel.org, yamada.masahiro@socionext.com, linux@rasmusvillemoes.dk, linux-kernel@vger.kernel.org, William Breathitt Gray , linux-gpio@vger.kernel.org, bgolaszewski@baylibre.com, akpm@linux-foundation.org, andriy.shevchenko@linux.intel.com, linux-arm-kernel@lists.infradead.org Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+patchwork-linux-arm=patchwork.kernel.org@lists.infradead.org X-Virus-Scanned: ClamAV using ClamSMTP 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 | 37 ++++++++-------------------------- 1 file changed, 8 insertions(+), 29 deletions(-) diff --git a/drivers/gpio/gpio-104-idi-48.c b/drivers/gpio/gpio-104-idi-48.c index 88dc6f2449f6..59c571aecf9a 100644 --- a/drivers/gpio/gpio-104-idi-48.c +++ b/drivers/gpio/gpio-104-idi-48.c @@ -93,42 +93,21 @@ 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); + const unsigned int ngpio = ARRAY_SIZE(ports) * 8; + 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, ngpio) { + 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, ngpio, port_state, offset); } return 0; From patchwork Sun Mar 3 07:50:01 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: William Breathitt Gray X-Patchwork-Id: 10836991 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 7643E180E for ; Sun, 3 Mar 2019 07:49:21 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 6396D2A107 for ; Sun, 3 Mar 2019 07:49:21 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 574F52A11A; Sun, 3 Mar 2019 07:49:21 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-5.2 required=2.0 tests=BAYES_00,DKIM_ADSP_CUSTOM_MED, DKIM_SIGNED,DKIM_VALID,FREEMAIL_FROM,MAILING_LIST_MULTI,RCVD_IN_DNSWL_MED autolearn=ham version=3.3.1 Received: from bombadil.infradead.org (bombadil.infradead.org [198.137.202.133]) (using TLSv1.2 with cipher AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.wl.linuxfoundation.org (Postfix) with ESMTPS id DFBFA2A107 for ; Sun, 3 Mar 2019 07:49:20 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20170209; h=Sender: Content-Transfer-Encoding:Content-Type:Cc:List-Subscribe:List-Help:List-Post: List-Archive:List-Unsubscribe:List-Id:MIME-Version:References:In-Reply-To: Message-Id:Date:Subject:To:From:Reply-To:Content-ID:Content-Description: Resent-Date:Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID: List-Owner; bh=ltMveRREfZQi7O8lmC3CWFTY0DsgtZ26c0A2N3p8JI8=; b=HGDZxToVC0MV/i I0kWFgSVF1883V2qAbAwefLVJ90AWE/V/GZs4JlX2esj42lEoQOBoSkygouH/l7YjzSRl9bquA6y0 X5ET+Zot5uCMp3YzGhpNMRWAg/ibE0KXDMKs27XhfcRb7GyWgIVkCeQ8wnXj8AmXy7QRe4qNFdosZ 0jpITRSSHI8ETpH696t61hwlNcGnzR++8pdy0NekZq4IQzmNbKWJ2G1ZOCue+RTyIeBlZCHKaT6GO XLszJ+fuhAIOQzeiE0rHRd4nqotojq8iO7oV3g6avvLKg5hB5fhgf7aC3AKy7vepnyOfSN9T+K6LX DY37XDqO2JuqhiQwF+4w==; Received: from localhost ([127.0.0.1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.90_1 #2 (Red Hat Linux)) id 1h0Ls4-0000tT-Mn; Sun, 03 Mar 2019 07:49:16 +0000 Received: from mail-pl1-x644.google.com ([2607:f8b0:4864:20::644]) by bombadil.infradead.org with esmtps (Exim 4.90_1 #2 (Red Hat Linux)) id 1h0Ls1-0000sa-7z for linux-arm-kernel@lists.infradead.org; Sun, 03 Mar 2019 07:49:14 +0000 Received: by mail-pl1-x644.google.com with SMTP id b65so1019692plb.6 for ; Sat, 02 Mar 2019 23:49:13 -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=rgWDXyitkPfkOwvJZbjg9H8+KzeLJbUpGMI+NATW6JM=; b=nNZcDVT7gCmLRW7btBJZFuhEeXBszPuLxdF8l527tPJJvZzbH8EJ7oJjGevImyvnRW 2+wiyoWqjJ2C0n8E4rNzV5FTVYDDG+jtLD4kMgCMUKHdGlSSU09QcjVqNrJKLVYYZtNF GsRLhXw9pZuFnUOsOId3pCKdSYebF4mSr/N+RFQC49dl3jws1kfLZJ7FY2b2PhjXwWUz 3fN+jRnqXM0BTZNXPSL7Cfb5z9i68NoNK1sUNupcoums7hrj9u5WvUVW1Kvkut34EG26 P9uPYUUkqpFNSfNWNHsHvBl3ZW8eWikPU/n/ukLFIIfykDLFA5TlbtWYTBrYfousPQVI l5zw== 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=rgWDXyitkPfkOwvJZbjg9H8+KzeLJbUpGMI+NATW6JM=; b=gTUI4ZXTZZ9gYEuk8tIpsVv5XyZ5AbllB7toTzznTvNK6XqqjsXmjI0HbEvnotHQpG 4XjuPmhyV1nwB5BAOlOZFUAxltqVf8lzGt9Pb9MTM1nRQm2TWe+/lStxJlCzdqWLm/c1 6mpBnDKvamvW0fabgh0V7dQI7EDPoF4t0vN0wUbq8OLK82q2z+nATX1A8apPC3668Ipg J8tfSbd9OzxW215sY1sU2kBCmzNRnQflq+0kSrN+QlsX5xzwvtAT3zYKKThYTS6Qo2BZ XFQOtBybdtLRvWjPkXw5KLP0n/xR1wU5z63cn1oTVcvlZMwqw6B7aURGLQN2+8NM+F/t cYtg== X-Gm-Message-State: APjAAAX4icQNCtoPdz3Snm4qwW5+No6knAdvPQwFyxZy48olQejUxCf/ AStB1WZ2zBQqywmw4Zf1twM= X-Google-Smtp-Source: APXvYqyoWyflno0hUvYm4dF/b+uTzDFho/HKq9iiGjwE0w/mIEL/ab2t65dLHqBHIRpgu/3Xup3Z+g== X-Received: by 2002:a17:902:7e49:: with SMTP id a9mr13482396pln.303.1551599352826; Sat, 02 Mar 2019 23:49:12 -0800 (PST) Received: from localhost.localdomain ([2001:268:c0a5:3b5c:c70:4af9:86e2:2]) by smtp.gmail.com with ESMTPSA id u24sm3606943pfm.140.2019.03.02.23.49.08 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Sat, 02 Mar 2019 23:49:12 -0800 (PST) From: William Breathitt Gray To: linus.walleij@linaro.org Subject: [PATCH v9 5/9] gpio: gpio-mm: Utilize for_each_set_clump8 macro Date: Sun, 3 Mar 2019 16:50:01 +0900 Message-Id: <1caa420858570551283e6ac76ff6f52b3338a17b.1551598603.git.vilhelm.gray@gmail.com> X-Mailer: git-send-email 2.21.0 In-Reply-To: References: MIME-Version: 1.0 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20190302_234913_280913_711AB891 X-CRM114-Status: GOOD ( 15.12 ) X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: linux-arch@vger.kernel.org, yamada.masahiro@socionext.com, linux@rasmusvillemoes.dk, linux-kernel@vger.kernel.org, William Breathitt Gray , linux-gpio@vger.kernel.org, bgolaszewski@baylibre.com, akpm@linux-foundation.org, andriy.shevchenko@linux.intel.com, linux-arm-kernel@lists.infradead.org Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+patchwork-linux-arm=patchwork.kernel.org@lists.infradead.org X-Virus-Scanned: ClamAV using ClamSMTP 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-gpio-mm.c | 73 +++++++++++-------------------------- 1 file changed, 22 insertions(+), 51 deletions(-) diff --git a/drivers/gpio/gpio-gpio-mm.c b/drivers/gpio/gpio-gpio-mm.c index 8c150fd68d9d..4c1037a005ab 100644 --- a/drivers/gpio/gpio-gpio-mm.c +++ b/drivers/gpio/gpio-gpio-mm.c @@ -172,46 +172,26 @@ static int gpiomm_gpio_get(struct gpio_chip *chip, unsigned int offset) return !!(port_state & mask); } +static const size_t ports[] = { 0, 1, 2, 4, 5, 6 }; + static int gpiomm_gpio_get_multiple(struct gpio_chip *chip, unsigned long *mask, unsigned long *bits) { struct gpiomm_gpio *const gpiommgpio = gpiochip_get_data(chip); - size_t i; - 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 offset; + unsigned long gpio_mask; + const unsigned int ngpio = ARRAY_SIZE(ports) * 8; + 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; - - /* 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(gpiommgpio->base + ports[i]); + for_each_set_clump8(offset, gpio_mask, mask, ngpio) { + port_addr = gpiommgpio->base + ports[offset / 8]; + port_state = inb(port_addr) & gpio_mask; - /* 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; @@ -242,37 +222,28 @@ static void gpiomm_gpio_set_multiple(struct gpio_chip *chip, unsigned long *mask, unsigned long *bits) { struct gpiomm_gpio *const gpiommgpio = gpiochip_get_data(chip); - unsigned int i; - const unsigned int gpio_reg_size = 8; - unsigned int port; - unsigned int out_port; + unsigned int offset; + unsigned long gpio_mask; + const unsigned int ngpio = ARRAY_SIZE(ports) * 8; + size_t index; + unsigned int port_addr; unsigned int bitmask; unsigned long flags; - /* set bits are evaluated a gpio register size at a time */ - for (i = 0; i < chip->ngpio; i += gpio_reg_size) { - /* no more set bits in this mask word; skip to the next word */ - if (!mask[BIT_WORD(i)]) { - i = (BIT_WORD(i) + 1) * BITS_PER_LONG - gpio_reg_size; - continue; - } + for_each_set_clump8(offset, gpio_mask, mask, ngpio) { + index = offset / 8; + port_addr = gpiommgpio->base + ports[index]; - port = i / gpio_reg_size; - out_port = (port > 2) ? port + 1 : port; - bitmask = mask[BIT_WORD(i)] & bits[BIT_WORD(i)]; + bitmask = bitmap_get_value8(bits, ngpio, offset) & gpio_mask; spin_lock_irqsave(&gpiommgpio->lock, flags); /* update output state data and set device gpio register */ - gpiommgpio->out_state[port] &= ~mask[BIT_WORD(i)]; - gpiommgpio->out_state[port] |= bitmask; - outb(gpiommgpio->out_state[port], gpiommgpio->base + out_port); + gpiommgpio->out_state[index] &= ~gpio_mask; + gpiommgpio->out_state[index] |= bitmask; + outb(gpiommgpio->out_state[index], port_addr); spin_unlock_irqrestore(&gpiommgpio->lock, flags); - - /* prepare for next gpio register set */ - mask[BIT_WORD(i)] >>= gpio_reg_size; - bits[BIT_WORD(i)] >>= gpio_reg_size; } } From patchwork Sun Mar 3 07:50:42 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: William Breathitt Gray X-Patchwork-Id: 10836993 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 3672213B5 for ; Sun, 3 Mar 2019 07:50:08 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 2044C2A508 for ; Sun, 3 Mar 2019 07:50:08 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 102542A530; Sun, 3 Mar 2019 07:50:08 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-5.2 required=2.0 tests=BAYES_00,DKIM_ADSP_CUSTOM_MED, DKIM_SIGNED,DKIM_VALID,FREEMAIL_FROM,MAILING_LIST_MULTI,RCVD_IN_DNSWL_MED autolearn=ham version=3.3.1 Received: from bombadil.infradead.org (bombadil.infradead.org [198.137.202.133]) (using TLSv1.2 with cipher AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.wl.linuxfoundation.org (Postfix) with ESMTPS id 7F82B2A508 for ; Sun, 3 Mar 2019 07:50:07 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20170209; h=Sender: Content-Transfer-Encoding:Content-Type:Cc:List-Subscribe:List-Help:List-Post: List-Archive:List-Unsubscribe:List-Id:MIME-Version:References:In-Reply-To: Message-Id:Date:Subject:To:From:Reply-To:Content-ID:Content-Description: Resent-Date:Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID: List-Owner; bh=aFOyVg51VmvjMddDtCmCNUdEzDTDp6zBLLKchh5tJDo=; b=emkLMSWRiASj7P gGq8UG1KC1ucJ1lfJGMJuCsKwkXINQBRhsDlzy9IGO+ichYM35FpYQ7QbVdCSGKveVdz5LYkZS4MX ehVgVbbR+vcDxcTEMnKEK7cIa4g+IyoR9N99AE5wASe8joZmlQV+IWPraG/msXqZEmuhUOebaDfA5 WKrcjfMTkcXJh4XSnZGHXnsRjgNk9ogfk3s/loKN1rdhceX/Lxi+KjS42hi4/UcLPq9NmxKEsRisx 5gP6E4gZYxbf2vxgTryi2zP7N46eHg5SJVncV+CnIZlGBugtt5Q+l6avRn0SbzRL1VIY3FIQUBGpU n7dtWMOiMOrdL5rnGMfA==; Received: from localhost ([127.0.0.1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.90_1 #2 (Red Hat Linux)) id 1h0Lsl-0001AC-F5; Sun, 03 Mar 2019 07:49:59 +0000 Received: from mail-pf1-x443.google.com ([2607:f8b0:4864:20::443]) by bombadil.infradead.org with esmtps (Exim 4.90_1 #2 (Red Hat Linux)) id 1h0Lsi-00019m-CE for linux-arm-kernel@lists.infradead.org; Sun, 03 Mar 2019 07:49:58 +0000 Received: by mail-pf1-x443.google.com with SMTP id a3so956878pff.11 for ; Sat, 02 Mar 2019 23:49:56 -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=JhQ28KZcd91XNKjTCGWYQ1G7G3aiOZwynfHwUrGcvPU=; b=Bam77vDD1tCuqDxCF0IcCKgnNzw8GpQon75PFQFQEOOepcG0dtY0LydsboWhTUhgTM LFYthlyHTGGr3mGihCHLzkdk+aQj+AklVfYXjk7xd/6A35DLVmdEKSpEfmmPaZS8HQm/ /qmJbh9yscMIOal6u7SLsv+4lZ/wgoMY0LNDr83uHRs9md9+B33Mup8U352U124TGII+ oosd01G1jb2qG2oEMSeKsOOleLFvWEEU7iyuNldaOK/gwv6uE9UIekgYWnKBZ2IpiaCm Esa+9dX/CnXb8H0ENDNdjGKxY5p9+REOnNmck9E9761k3V2uJyvNI3rMy098CU3Z7PCI BSwA== 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=JhQ28KZcd91XNKjTCGWYQ1G7G3aiOZwynfHwUrGcvPU=; b=RTfD+ICfHPbj1WlzPZedsVigig8pixvMxMVq1ZWFTcm97Acw2MZYgV/wcSEFdzm6ta sajCUFn9Hvlg8GkmW4ELmd/zAucGVthv3rmO4OCXz/rE26Vm9SgMOWgLsYWfyc/Ia3vW 2fhyt4iM+f409OsqzkXLRSmKP1IUnBbuQYopFc1YcV+35ZCqR1pZn3U2DgMEZRf883GT YdYsqLbdbLwQnO25o9WB+Qy9vfkqMYvBcrLP4l5y+An4WU3gzYZnBXzfYcIiB8dciuSi HWzkPe3kKEOIBJAkPfrSvgJUXJg9oLzlT+3DfYd1FQWx+m2Upz4wVXBInRxXk4xH+sdL eGxw== X-Gm-Message-State: APjAAAWMYPD/k+7BqzRofvdGyDs9COzhbq3xyPheG78a7UlK6mVGLPCD 2jZt5qoseq5iZh4JW9+4p4U= X-Google-Smtp-Source: APXvYqwGqFl0d/l1kXcUR+JEMAN+AdTga040FQBJQpmxnclXVEpXD35y02QTWkfd2hVGCraLprjWhA== X-Received: by 2002:a63:c0b:: with SMTP id b11mr9994330pgl.388.1551599395879; Sat, 02 Mar 2019 23:49:55 -0800 (PST) Received: from localhost.localdomain ([2001:268:c0a5:3b5c:c70:4af9:86e2:2]) by smtp.gmail.com with ESMTPSA id j14sm3692361pfe.12.2019.03.02.23.49.50 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Sat, 02 Mar 2019 23:49:55 -0800 (PST) From: William Breathitt Gray To: linus.walleij@linaro.org Subject: [PATCH v9 6/9] gpio: ws16c48: Utilize for_each_set_clump8 macro Date: Sun, 3 Mar 2019 16:50:42 +0900 Message-Id: X-Mailer: git-send-email 2.21.0 In-Reply-To: References: MIME-Version: 1.0 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20190302_234956_438166_27333362 X-CRM114-Status: GOOD ( 15.29 ) X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: linux-arch@vger.kernel.org, yamada.masahiro@socionext.com, linux@rasmusvillemoes.dk, linux-kernel@vger.kernel.org, William Breathitt Gray , linux-gpio@vger.kernel.org, bgolaszewski@baylibre.com, akpm@linux-foundation.org, andriy.shevchenko@linux.intel.com, linux-arm-kernel@lists.infradead.org Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+patchwork-linux-arm=patchwork.kernel.org@lists.infradead.org X-Virus-Scanned: ClamAV using ClamSMTP 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-ws16c48.c | 72 +++++++++++-------------------------- 1 file changed, 20 insertions(+), 52 deletions(-) diff --git a/drivers/gpio/gpio-ws16c48.c b/drivers/gpio/gpio-ws16c48.c index 5cf3697bfb15..1d071a3d3e81 100644 --- a/drivers/gpio/gpio-ws16c48.c +++ b/drivers/gpio/gpio-ws16c48.c @@ -134,42 +134,19 @@ static int ws16c48_gpio_get_multiple(struct gpio_chip *chip, unsigned long *mask, unsigned long *bits) { struct ws16c48_gpio *const ws16c48gpio = gpiochip_get_data(chip); - const unsigned int gpio_reg_size = 8; - size_t i; - const size_t num_ports = chip->ngpio / gpio_reg_size; - 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 offset; + unsigned long gpio_mask; + 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 < num_ports; i++) { - /* gpio offset in bits array */ - bits_offset = i * gpio_reg_size; + for_each_set_clump8(offset, gpio_mask, mask, chip->ngpio) { + port_addr = ws16c48gpio->base + 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(ws16c48gpio->base + i); - - /* store acquired bits at respective bits array offset */ - bits[word_index] |= (port_state << word_offset) & word_mask; + bitmap_set_value8(bits, chip->ngpio, port_state, offset); } return 0; @@ -203,39 +180,30 @@ static void ws16c48_gpio_set_multiple(struct gpio_chip *chip, unsigned long *mask, unsigned long *bits) { struct ws16c48_gpio *const ws16c48gpio = gpiochip_get_data(chip); - unsigned int i; - const unsigned int gpio_reg_size = 8; - unsigned int port; - unsigned int iomask; + unsigned int offset; + unsigned long gpio_mask; + size_t index; + unsigned int port_addr; unsigned int bitmask; unsigned long flags; - /* set bits are evaluated a gpio register size at a time */ - for (i = 0; i < chip->ngpio; i += gpio_reg_size) { - /* no more set bits in this mask word; skip to the next word */ - if (!mask[BIT_WORD(i)]) { - i = (BIT_WORD(i) + 1) * BITS_PER_LONG - gpio_reg_size; - continue; - } - - port = i / gpio_reg_size; + for_each_set_clump8(offset, gpio_mask, mask, chip->ngpio) { + index = offset / 8; + port_addr = ws16c48gpio->base + index; /* mask out GPIO configured for input */ - iomask = mask[BIT_WORD(i)] & ~ws16c48gpio->io_state[port]; - bitmask = iomask & bits[BIT_WORD(i)]; + gpio_mask &= ~ws16c48gpio->io_state[index]; + bitmask = bitmap_get_value8(bits, chip->ngpio, offset) & + gpio_mask; raw_spin_lock_irqsave(&ws16c48gpio->lock, flags); /* update output state data and set device gpio register */ - ws16c48gpio->out_state[port] &= ~iomask; - ws16c48gpio->out_state[port] |= bitmask; - outb(ws16c48gpio->out_state[port], ws16c48gpio->base + port); + ws16c48gpio->out_state[index] &= ~gpio_mask; + ws16c48gpio->out_state[index] |= bitmask; + outb(ws16c48gpio->out_state[index], port_addr); raw_spin_unlock_irqrestore(&ws16c48gpio->lock, flags); - - /* prepare for next gpio register set */ - mask[BIT_WORD(i)] >>= gpio_reg_size; - bits[BIT_WORD(i)] >>= gpio_reg_size; } } From patchwork Sun Mar 3 07:51:03 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: William Breathitt Gray X-Patchwork-Id: 10836995 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 1110113B5 for ; Sun, 3 Mar 2019 07:50:27 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id F13E22A508 for ; Sun, 3 Mar 2019 07:50:26 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id E41AA2A530; Sun, 3 Mar 2019 07:50:26 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-5.2 required=2.0 tests=BAYES_00,DKIM_ADSP_CUSTOM_MED, DKIM_SIGNED,DKIM_VALID,FREEMAIL_FROM,MAILING_LIST_MULTI,RCVD_IN_DNSWL_MED autolearn=ham version=3.3.1 Received: from bombadil.infradead.org (bombadil.infradead.org [198.137.202.133]) (using TLSv1.2 with cipher AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.wl.linuxfoundation.org (Postfix) with ESMTPS id 73B112A508 for ; Sun, 3 Mar 2019 07:50:26 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20170209; h=Sender: Content-Transfer-Encoding:Content-Type:Cc:List-Subscribe:List-Help:List-Post: List-Archive:List-Unsubscribe:List-Id:MIME-Version:References:In-Reply-To: Message-Id:Date:Subject:To:From:Reply-To:Content-ID:Content-Description: Resent-Date:Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID: List-Owner; bh=FoeQ32wgGtXsTfxq5BtLa8uxa+0QAJgtirYiMIlzuBU=; b=DA4QU37nc/jHUT ILLkyYTMrwypHbXvmjg7SrGG6s88RIDNToY8pqb3jsBnGNBfRQS3aNrQcLtJArelnedMcghqoZTp0 LO33oibSOa1uyAKmuTK/raKoQUuojDm7d9HdNcND4ZpqSkR989RuBjlB5Ev93zSd3QjLsYS2Oz8VY 0KSMS5lODiQwTQi2yOVF5it4vGX+ksSWxSkCpAD5JKuL0q0mmLFC4VkuC6caB9quI1FUjGgt+kMvv B8nkkxpDs/JWKrsidCSqtCc2FvGEAA8D8A7PoPmQBb4HVZk7cDRsAF73yG0u077dnF46fhriM9zUD RbPm+1yXUjOR1s9IH59Q==; Received: from localhost ([127.0.0.1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.90_1 #2 (Red Hat Linux)) id 1h0Lt7-0002fj-VZ; Sun, 03 Mar 2019 07:50:21 +0000 Received: from mail-pg1-x543.google.com ([2607:f8b0:4864:20::543]) by bombadil.infradead.org with esmtps (Exim 4.90_1 #2 (Red Hat Linux)) id 1h0Lt5-0002fC-6Y for linux-arm-kernel@lists.infradead.org; Sun, 03 Mar 2019 07:50:20 +0000 Received: by mail-pg1-x543.google.com with SMTP id h11so1036820pgl.0 for ; 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=LTbmuNIrdiBJK8Elcyxi17IegSA4ACPbGTDOv+WpXJGgGkPMyaPcW/V9ij/BnslupB +KnwWAh9v0iZdok2pjCrZj2JcZDZ5ecpBec3hhmA33h/Oyu4iqFG7zQDSn738dCuj/pN YxXpT+FpKsx/Cl9guqbHi3KApHEjemV3La/083/s6CHiD9fZTQCG0Pk5RW5l2I3bE10T vzygqudWoEcLrngDzmVyy/tcp+s0lGyVEaYw9B4Ziba+MwoUnhyGsucgksPBVouBn7BC 6oalfJR9ZEaGtErdf9fetBDH7U305+5+cbrkcamwcWhDYdhT/FeWIFCaCmpAIc9ANVue TVuA== X-Gm-Message-State: APjAAAUdKubL4xRo4teKChPcK0P0d4tb86/iyjKXmRIjARD29A51McbN LjKK0TxcKV4CgXrUuKL2PKxMc0I9AY0= X-Google-Smtp-Source: APXvYqwGtoVxiOiJshtmW3aEc1CCJhEyW0KxGk8D4DnFKW19Lj1dbJiqF+D7Ff3nVrcefHUJ+hDX/Q== 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 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 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20190302_235019_242777_D62CA243 X-CRM114-Status: GOOD ( 15.56 ) X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: linux-arch@vger.kernel.org, yamada.masahiro@socionext.com, linux@rasmusvillemoes.dk, linux-kernel@vger.kernel.org, William Breathitt Gray , linux-gpio@vger.kernel.org, bgolaszewski@baylibre.com, akpm@linux-foundation.org, andriy.shevchenko@linux.intel.com, linux-arm-kernel@lists.infradead.org Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+patchwork-linux-arm=patchwork.kernel.org@lists.infradead.org X-Virus-Scanned: ClamAV using ClamSMTP 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) From patchwork Sun Mar 3 07:51:25 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: William Breathitt Gray X-Patchwork-Id: 10836997 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 4CDAD1575 for ; Sun, 3 Mar 2019 07:50:49 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 3B1762A508 for ; Sun, 3 Mar 2019 07:50:49 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 2EED62A530; Sun, 3 Mar 2019 07:50:49 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-5.2 required=2.0 tests=BAYES_00,DKIM_ADSP_CUSTOM_MED, DKIM_SIGNED,DKIM_VALID,FREEMAIL_FROM,MAILING_LIST_MULTI,RCVD_IN_DNSWL_MED autolearn=ham version=3.3.1 Received: from bombadil.infradead.org (bombadil.infradead.org [198.137.202.133]) (using TLSv1.2 with cipher AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.wl.linuxfoundation.org (Postfix) with ESMTPS id A5A542A508 for ; Sun, 3 Mar 2019 07:50:48 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20170209; h=Sender: Content-Transfer-Encoding:Content-Type:Cc:List-Subscribe:List-Help:List-Post: List-Archive:List-Unsubscribe:List-Id:MIME-Version:References:In-Reply-To: Message-Id:Date:Subject:To:From:Reply-To:Content-ID:Content-Description: Resent-Date:Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID: List-Owner; bh=q84phXcAp+vIZjtnn7AlnlI5I9dK1+bwdUcWYAP/t20=; b=L65QJa5Nrmn5NE G7WAII9OkjgriXEA3MM1Zsnwbx9TC41N8AeB5yNObRWvsJdnWUWjnGZhZU1A3Hge0zzEq+hKdkWV6 tPJU0LS/+jSfQYNUejv+WuGziL2hcgQdlygbwcVh9nngWdq3A+OG9VsbfyoB9XKRThjNHlHdXKXoE kNFz4gWuzGzLN5cCj2pgjZhD52RxMicHQL+Tt6+duqCZK7UwA4kAk9ljJ+HQ6kAM2J8bYLQ7zkoVY X2qKvyPzF2mkmrUkTVEoTwpJufEQUAejG1f5APRIQy0t0e8P2pwLYEDJmLNM7joasP9hp0BYORf8i jwVcZEHKfcQiOILdXXSQ==; Received: from localhost ([127.0.0.1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.90_1 #2 (Red Hat Linux)) id 1h0LtS-00031h-5e; Sun, 03 Mar 2019 07:50:42 +0000 Received: from mail-pl1-x641.google.com ([2607:f8b0:4864:20::641]) by bombadil.infradead.org with esmtps (Exim 4.90_1 #2 (Red Hat Linux)) id 1h0LtN-0002zi-7T for linux-arm-kernel@lists.infradead.org; Sun, 03 Mar 2019 07:50:40 +0000 Received: by mail-pl1-x641.google.com with SMTP id c4so1013633pls.11 for ; Sat, 02 Mar 2019 23:50:37 -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=lo/y4LVrDbirngV8ZQJtGQjH8jQRyE53ymUz3wq08xM=; b=DUIWBaz+2lKKv6q0nv8pC3fyrnsY34azOHBaXezmQKXHeQD2YAnoC5RBC5qUByNMPK JnYIOqukzlP3M45D3Q9qezSgvkYLRBGOr/3MHW5q7IWTwteW5J9uu2F40LWc2+hlyR8p RcC31sR7NhgEUoUU4CQlz9Y/j/OfB9NXeTVm73iEp4iNYaX2adLNCUFCKA/ODB2PsEXE XkgkIuzS1KMjSsdVEhD0cmB4+6peSimwdQh8AJUAbNHS1g2H+EL5vnqZEUhtsxhIuaN7 KRj6GfYbqd55FcACa2OcbdrY2c64ApvqvrK0zJaizSPScZG/0b6k9ntNmlCYSAWFaG8u vCsQ== 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=lo/y4LVrDbirngV8ZQJtGQjH8jQRyE53ymUz3wq08xM=; b=GrSPzPrRbNVb1wMHdJmVer5gMqSxacwzLKpT3Dcie0gwnAmoAUkPqT1XyKI6GK9MRr geVsA/cM2VIxCjkSgldCFMe7KZDJdeflFZVTOmQFFqRA5NA7adEyB/NrzbokdVdvquGY 1EOSOJCCrw5u6gPH65z4z24Qu/EWr6zBpyvQujh3cDvyeryMVTprCcNPiAmBnR9IqWkE zIK26VKhmhQf4KgZn9Zttm54ZdgBrScTJQhK+gbH2RxtfJdg8kmEsMhmZD+Kzha9GllL FthHyZBvQl+ECGYnrhI9PZbxbXevpBsTt6izahtXImFQn6k4t2QbRM6vViHJz8iMbs7E 8l+Q== X-Gm-Message-State: APjAAAWRZgmEx1a8UGVEK3c4BopXWr5pD02gOdnG55qwuYgYsLTBEMk0 2bkaAUc43oU6VmwtfwGj1KQ= X-Google-Smtp-Source: APXvYqxIjd1zxPy5tETGOyp0wLUJOev8wuN5NLSMJTse4fHkXiQ1o+yU5M7kms2IIhvyqyHHZBkO+Q== X-Received: by 2002:a17:902:76c8:: with SMTP id j8mr4554264plt.18.1551599436777; Sat, 02 Mar 2019 23:50:36 -0800 (PST) Received: from localhost.localdomain ([2001:268:c0a5:3b5c:c70:4af9:86e2:2]) by smtp.gmail.com with ESMTPSA id n15sm2008926pfi.173.2019.03.02.23.50.30 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Sat, 02 Mar 2019 23:50:36 -0800 (PST) From: William Breathitt Gray To: linus.walleij@linaro.org Subject: [PATCH v9 8/9] gpio: pcie-idio-24: Utilize for_each_set_clump8 macro Date: Sun, 3 Mar 2019 16:51:25 +0900 Message-Id: X-Mailer: git-send-email 2.21.0 In-Reply-To: References: MIME-Version: 1.0 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20190302_235037_435538_764B298A X-CRM114-Status: GOOD ( 17.27 ) X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: linux-arch@vger.kernel.org, yamada.masahiro@socionext.com, linux@rasmusvillemoes.dk, linux-kernel@vger.kernel.org, William Breathitt Gray , linux-gpio@vger.kernel.org, bgolaszewski@baylibre.com, akpm@linux-foundation.org, andriy.shevchenko@linux.intel.com, linux-arm-kernel@lists.infradead.org Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+patchwork-linux-arm=patchwork.kernel.org@lists.infradead.org X-Virus-Scanned: ClamAV using ClamSMTP 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-pcie-idio-24.c | 111 ++++++++++++------------------- 1 file changed, 42 insertions(+), 69 deletions(-) diff --git a/drivers/gpio/gpio-pcie-idio-24.c b/drivers/gpio/gpio-pcie-idio-24.c index 52f1647a46fd..2ceff1f5d8fd 100644 --- a/drivers/gpio/gpio-pcie-idio-24.c +++ b/drivers/gpio/gpio-pcie-idio-24.c @@ -198,52 +198,35 @@ static int idio_24_gpio_get_multiple(struct gpio_chip *chip, unsigned long *mask, unsigned long *bits) { struct idio_24_gpio *const idio24gpio = 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[] = { &idio24gpio->reg->out0_7, &idio24gpio->reg->out8_15, &idio24gpio->reg->out16_23, &idio24gpio->reg->in0_7, &idio24gpio->reg->in8_15, &idio24gpio->reg->in16_23, }; + const unsigned int ngpio = ARRAY_SIZE(ports) * 8; + size_t index; + unsigned long port_state; const unsigned long out_mode_mask = BIT(1); /* 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) + 1; 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; - } + for_each_set_clump8(offset, gpio_mask, mask, ngpio) { + index = offset / 8; /* read bits from current gpio port (port 6 is TTL GPIO) */ - if (i < 6) - port_state = ioread8(ports[i]); + if (index < 6) + port_state = ioread8(ports[index]); else if (ioread8(&idio24gpio->reg->ctl) & out_mode_mask) port_state = ioread8(&idio24gpio->reg->ttl_out0_7); else port_state = ioread8(&idio24gpio->reg->ttl_in0_7); - /* store acquired bits at respective bits array offset */ - bits[word_index] |= (port_state << word_offset) & word_mask; + port_state &= gpio_mask; + + bitmap_set_value8(bits, ngpio, port_state, offset); } return 0; @@ -294,59 +277,49 @@ static void idio_24_gpio_set_multiple(struct gpio_chip *chip, unsigned long *mask, unsigned long *bits) { struct idio_24_gpio *const idio24gpio = gpiochip_get_data(chip); - size_t i; - unsigned long bits_offset; + unsigned int offset; unsigned long gpio_mask; - const unsigned int gpio_reg_size = 8; - const unsigned long port_mask = GENMASK(gpio_reg_size, 0); - unsigned long flags; - unsigned int out_state; void __iomem *ports[] = { &idio24gpio->reg->out0_7, &idio24gpio->reg->out8_15, &idio24gpio->reg->out16_23 }; + const unsigned int ngpio = ARRAY_SIZE(ports) * 8; + size_t index; + unsigned int bitmask; + unsigned long flags; + unsigned int out_state; const unsigned long out_mode_mask = BIT(1); - const unsigned int ttl_offset = 48; - const size_t ttl_i = BIT_WORD(ttl_offset); - const unsigned int word_offset = ttl_offset % BITS_PER_LONG; - const unsigned long ttl_mask = (mask[ttl_i] >> word_offset) & port_mask; - const unsigned long ttl_bits = (bits[ttl_i] >> word_offset) & ttl_mask; - - /* set bits are processed 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; - - /* check if any set bits for current port */ - gpio_mask = (*mask >> bits_offset) & port_mask; - if (!gpio_mask) { - /* no set bits for this port so move on to next port */ - continue; - } - raw_spin_lock_irqsave(&idio24gpio->lock, flags); + for_each_set_clump8(offset, gpio_mask, mask, ngpio) { + index = offset / 8; - /* process output lines */ - out_state = ioread8(ports[i]) & ~gpio_mask; - out_state |= (*bits >> bits_offset) & gpio_mask; - iowrite8(out_state, ports[i]); + bitmask = bitmap_get_value8(bits, ngpio, offset) & gpio_mask; - raw_spin_unlock_irqrestore(&idio24gpio->lock, flags); - } + raw_spin_lock_irqsave(&idio24gpio->lock, flags); - /* check if setting TTL lines and if they are in output mode */ - if (!ttl_mask || !(ioread8(&idio24gpio->reg->ctl) & out_mode_mask)) - return; + /* read bits from current gpio port (port 6 is TTL GPIO) */ + if (index < 6) { + out_state = ioread8(ports[index]); + } else if (ioread8(&idio24gpio->reg->ctl) & out_mode_mask) { + out_state = ioread8(&idio24gpio->reg->ttl_out0_7); + } else { + /* skip TTL GPIO if set for input */ + raw_spin_unlock_irqrestore(&idio24gpio->lock, flags); + continue; + } - /* handle TTL output */ - raw_spin_lock_irqsave(&idio24gpio->lock, flags); + /* set requested bit states */ + out_state &= ~gpio_mask; + out_state |= bitmask; - /* process output lines */ - out_state = ioread8(&idio24gpio->reg->ttl_out0_7) & ~ttl_mask; - out_state |= ttl_bits; - iowrite8(out_state, &idio24gpio->reg->ttl_out0_7); + /* write bits for current gpio port (port 6 is TTL GPIO) */ + if (index < 6) + iowrite8(out_state, ports[index]); + else + iowrite8(out_state, &idio24gpio->reg->ttl_out0_7); - raw_spin_unlock_irqrestore(&idio24gpio->lock, flags); + raw_spin_unlock_irqrestore(&idio24gpio->lock, flags); + } } static void idio_24_irq_ack(struct irq_data *data) From patchwork Sun Mar 3 07:51:43 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: William Breathitt Gray X-Patchwork-Id: 10836999 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 3A9B21575 for ; Sun, 3 Mar 2019 07:51:05 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 27D182A530 for ; Sun, 3 Mar 2019 07:51:05 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 19EF52A53C; Sun, 3 Mar 2019 07:51:05 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-5.2 required=2.0 tests=BAYES_00,DKIM_ADSP_CUSTOM_MED, DKIM_SIGNED,DKIM_VALID,FREEMAIL_FROM,MAILING_LIST_MULTI,RCVD_IN_DNSWL_MED autolearn=ham version=3.3.1 Received: from bombadil.infradead.org (bombadil.infradead.org [198.137.202.133]) (using TLSv1.2 with cipher AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.wl.linuxfoundation.org (Postfix) with ESMTPS id BB7782A530 for ; Sun, 3 Mar 2019 07:51:04 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20170209; h=Sender: Content-Transfer-Encoding:Content-Type:Cc:List-Subscribe:List-Help:List-Post: List-Archive:List-Unsubscribe:List-Id:MIME-Version:References:In-Reply-To: Message-Id:Date:Subject:To:From:Reply-To:Content-ID:Content-Description: Resent-Date:Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID: List-Owner; bh=gZ3NYMrQ1q/us7gBx3qTXKTVVtPVjOQLX1dn8tMYBNg=; b=j9ZX9hoZgc0UNC dR9828VlrWV7JH/6gwPYFJe/YBArCGeFJGe4HzF9W86WH2UaVOKiB8oCb4so5QqpWt2YiUQKtjt9o 3TrPF23RrApIVkI6Gu4FoqkOq0RQNXIPGL5UhQj3CZ3O72shJIEWmfnXZnLUSBWkFydykgNgSpEHr p30tsBefdeQbL5q12/ddv4GQCqGRx5XYudeWycRGOfiRdOvMqM2v3NDhiYv89dKgQw0glzA7ClPkm 4aTM7FmkSMIBHIq8CQaUGISHQBRnrkv8NFq/y3E49vX5x1w3uBZ01r8oaS0ipwY++fhe4hT8DKolo Jimg4f24erV7KrFtNjiQ==; Received: from localhost ([127.0.0.1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.90_1 #2 (Red Hat Linux)) id 1h0Ltk-0003I7-6Q; Sun, 03 Mar 2019 07:51:00 +0000 Received: from mail-pg1-x543.google.com ([2607:f8b0:4864:20::543]) by bombadil.infradead.org with esmtps (Exim 4.90_1 #2 (Red Hat Linux)) id 1h0Ltg-0003HB-5z for linux-arm-kernel@lists.infradead.org; Sun, 03 Mar 2019 07:50:57 +0000 Received: by mail-pg1-x543.google.com with SMTP id e17so1033082pgd.2 for ; Sat, 02 Mar 2019 23:50:56 -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=UifkzEkFRqXu3yixaaw6yvTChu7M21y6ZQxvlg1zFMs=; b=ojfxmGFwRLFyuJDYOF9Bd8zYmbOX5hRQmO1fjeBXHYEdxDNCk6flfMYPtIFbF/Sosu QjwqzgGRRzUR/gH75F37vldJ64FXGmkznZTBs/I8bp7wJi+x6UTMG5/Uq3nl79IMn2HJ VRogi8HkGoEN2YeXoVDyWsCBHU+6x3Wv0ETXILjP7Jea3MPDNcl1LiVEel0zJR/QS5FM xlFADQCDFaLDH4BPluMBDDnyxXr2SEFY2i424dUS8hQE+ClDNnYTrltlMfApDQOmqTvz bw8Eb8gsTf8s32czH9FAQdATV0ueUid+zPCUt1o3lcs7tbuTUAt1jxHsgLoGa8BxD2A0 7L8A== 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=UifkzEkFRqXu3yixaaw6yvTChu7M21y6ZQxvlg1zFMs=; b=M2+TAUNRRiTp3uq3sBTKLYhziB0X8smo3GWPyrEXkQ1VQ/jLH5uNs3nicnN+VImN/j ca4jP80iksQPg3XK9v7FRdHO+gGyHgXtIoWvvTzbsRnys9712jSJiasbgy1ogYTiiJlg cnFVMpQFhZOspL1svOXgS8KbQmUMbUGwnpKFDmy+xJmBjQmdAg40V6LIn5IY3ZGXkmro JH47tP4bboURsUYDz8mqxDdUcRGEKC7pVFitRnNiX9cdWBGVUtO+4ycZIsSRrMDhZYMe McWML1t+1z0Nr+kap4phjObsaQQ/kibBR/SF1nXqgPaQB+ZLC8Vfz/3EQj5mYlOL1Kr8 HxPg== X-Gm-Message-State: APjAAAWLAEGUBHOw6/WGhsfhvEU+ttbH1COm64AP7kFs5U89YT9Wd6yL 1QCSxhNT02NLfXljadNidz4= X-Google-Smtp-Source: AHgI3IaRcnUNGGrMNo351mYUWL3BWUGU+5ZHcEvSSM8aSjLkbPbmGgKncncfSHeoBVILcIaVCq+gbA== X-Received: by 2002:aa7:8299:: with SMTP id s25mr14222435pfm.56.1551599455604; Sat, 02 Mar 2019 23:50:55 -0800 (PST) Received: from localhost.localdomain ([2001:268:c0a5:3b5c:c70:4af9:86e2:2]) by smtp.gmail.com with ESMTPSA id y6sm4735357pfy.87.2019.03.02.23.50.49 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Sat, 02 Mar 2019 23:50:55 -0800 (PST) From: William Breathitt Gray To: linus.walleij@linaro.org Subject: [PATCH v9 9/9] gpio: uniphier: Utilize for_each_set_clump8 macro Date: Sun, 3 Mar 2019 16:51:43 +0900 Message-Id: <0840d55707dacd1121659723246fa9f55737f426.1551598603.git.vilhelm.gray@gmail.com> X-Mailer: git-send-email 2.21.0 In-Reply-To: References: MIME-Version: 1.0 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20190302_235056_220944_3BC0CE25 X-CRM114-Status: GOOD ( 12.09 ) X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: linux-arch@vger.kernel.org, yamada.masahiro@socionext.com, linux@rasmusvillemoes.dk, linux-kernel@vger.kernel.org, William Breathitt Gray , linux-gpio@vger.kernel.org, bgolaszewski@baylibre.com, akpm@linux-foundation.org, andriy.shevchenko@linux.intel.com, linux-arm-kernel@lists.infradead.org Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+patchwork-linux-arm=patchwork.kernel.org@lists.infradead.org X-Virus-Scanned: ClamAV using ClamSMTP Replace verbose implementation in set_multiple callback with for_each_set_clump8 macro to simplify code and improve clarity. An improvement in this case is that banks that are not masked will now be skipped. Cc: Masahiro Yamada Signed-off-by: William Breathitt Gray --- drivers/gpio/gpio-uniphier.c | 16 ++++++---------- 1 file changed, 6 insertions(+), 10 deletions(-) diff --git a/drivers/gpio/gpio-uniphier.c b/drivers/gpio/gpio-uniphier.c index 0f662b297a95..df640cb29b9c 100644 --- a/drivers/gpio/gpio-uniphier.c +++ b/drivers/gpio/gpio-uniphier.c @@ -15,9 +15,6 @@ #include #include -#define UNIPHIER_GPIO_BANK_MASK \ - GENMASK((UNIPHIER_GPIO_LINES_PER_BANK) - 1, 0) - #define UNIPHIER_GPIO_IRQ_MAX_NUM 24 #define UNIPHIER_GPIO_PORT_DATA 0x0 /* data */ @@ -147,15 +144,14 @@ static void uniphier_gpio_set(struct gpio_chip *chip, static void uniphier_gpio_set_multiple(struct gpio_chip *chip, unsigned long *mask, unsigned long *bits) { - unsigned int bank, shift, bank_mask, bank_bits; - int i; + unsigned int i; + unsigned long bank_mask; + unsigned int bank; + unsigned int bank_bits; - for (i = 0; i < chip->ngpio; i += UNIPHIER_GPIO_LINES_PER_BANK) { + for_each_set_clump8(i, bank_mask, mask, chip->ngpio) { bank = i / UNIPHIER_GPIO_LINES_PER_BANK; - shift = i % BITS_PER_LONG; - bank_mask = (mask[BIT_WORD(i)] >> shift) & - UNIPHIER_GPIO_BANK_MASK; - bank_bits = bits[BIT_WORD(i)] >> shift; + bank_bits = bitmap_get_value8(bits, chip->ngpio, i); uniphier_gpio_bank_write(chip, bank, UNIPHIER_GPIO_PORT_DATA, bank_mask, bank_bits);