From patchwork Mon Mar 25 06:03:13 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: 10867911 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 648121390 for ; Mon, 25 Mar 2019 06:02:20 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 490832916C for ; Mon, 25 Mar 2019 06:02:20 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 36696291D2; Mon, 25 Mar 2019 06:02:20 +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=-8.0 required=2.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,FREEMAIL_FROM,MAILING_LIST_MULTI,RCVD_IN_DNSWL_HI autolearn=ham version=3.3.1 Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 6D30C2916C for ; Mon, 25 Mar 2019 06:02:19 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1729447AbfCYGCS (ORCPT ); Mon, 25 Mar 2019 02:02:18 -0400 Received: from mail-pg1-f196.google.com ([209.85.215.196]:41393 "EHLO mail-pg1-f196.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1729373AbfCYGCS (ORCPT ); Mon, 25 Mar 2019 02:02:18 -0400 Received: by mail-pg1-f196.google.com with SMTP id f6so1579179pgs.8; Sun, 24 Mar 2019 23:02:17 -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=ez7ZzkC0Ak7aYk3BUE6/NHn4l6C5sfpy4Uv8mjEL3xM=; b=VCJi6P0v7PMWaX+AcmGNy17eE7dSpng3HsjixnR1IbTAFeRSW6kM/SN4IT9qGsqyPe buTKNmokd9md7Mst7vgiFJb+9Mu4HM8zykhdZczHMSnHQkG3LVE9nG0rz1XB4hCewMur GeRB5Jb1lJ0tMUhO4rqsfhihuXR3ZNOX3vr1DrWSTEaUXcoSXD420EgihRjG2tZA21TW i+ON9j/r+GHJ8v9ENStjlSzXc2yNFqRpZtANKu/BUQfn5tlMaiiNjejEF63s3yx0QECZ Pan2TM6mUYrgbROBVwDsO5JO6Su57H3u/uyCV+Ukctmcv7ZXxEl8M/qDOPX6JtzJcpEL LY4g== 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=ez7ZzkC0Ak7aYk3BUE6/NHn4l6C5sfpy4Uv8mjEL3xM=; b=tQVw15RSLKOS/P3LOuvL4qPSMCtHrfV25RYbcdReM9ShbVL8vherHOzr/RPx5YORpL KFehwcxPoGNfwPBhBNyuc8XX3pMNaSqqEoef7oGbfQf4hNyE8BwwFH56LdXnCMydc5Zp 3ERcct4W5IUpBcNEUlV2ORJP3UWafXf+v2gPLdl6nnWdb5aRIiqqH2hBDXICYYjVgWHL F9XhRB9MriAIWwwTqwMH9Nci4EhZiSWNZrrz1N+nlJsZoPd9T4fUeAsH48+awNf9CLWm LYqjLJKww4WikvhD2U4MdoCtQ4YEKX+lbAddIAqH3Q6HG8j8z7gdJOt6MVquZEX9jNAf iTtA== X-Gm-Message-State: APjAAAUDOdQs2QLH95Od87SeEUxj2xQp5ckS2wo5HQX2jrgBWUTYaEWh McGdKbupizCLFW53RGhh2U0= X-Google-Smtp-Source: APXvYqyJX1OKLzcw9XTWvb8RMbdMXvszO+qx+gHh4PgykeRMVMxJz/OJ+CmMkh0YgWOpEL0qdtgAUg== X-Received: by 2002:a63:e554:: with SMTP id z20mr20226843pgj.234.1553493737475; Sun, 24 Mar 2019 23:02:17 -0700 (PDT) Received: from localhost.localdomain ([2001:268:c0a5:e068:c70:4af9:86e2:2]) by smtp.gmail.com with ESMTPSA id t82sm10820235pfa.153.2019.03.24.23.02.11 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Sun, 24 Mar 2019 23:02:16 -0700 (PDT) From: William Breathitt Gray To: linus.walleij@linaro.org, bgolaszewski@baylibre.com Cc: akpm@linux-foundation.org, linux-gpio@vger.kernel.org, linux-arch@vger.kernel.org, linux-kernel@vger.kernel.org, andriy.shevchenko@linux.intel.com, linux@rasmusvillemoes.dk, yamada.masahiro@socionext.com, linux-arm-kernel@lists.infradead.org, linux-pm@vger.kernel.org, geert@linux-m68k.org, preid@electromag.com.au, William Breathitt Gray , Andy Shevchenko , Arnd Bergmann Subject: [PATCH v11 01/11] bitops: Introduce the for_each_set_clump8 macro Date: Mon, 25 Mar 2019 15:03:13 +0900 Message-Id: <64f9eed704899d31b34798c7ec7a42f28fd2d051.1553492741.git.vilhelm.gray@gmail.com> X-Mailer: git-send-email 2.21.0 In-Reply-To: References: MIME-Version: 1.0 Sender: linux-pm-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-pm@vger.kernel.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 Acked-by: 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 602af23b98c7..f19a7bc8f559 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 Mon Mar 25 06:03:30 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: 10867917 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 C730F1390 for ; Mon, 25 Mar 2019 06:02:42 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id B33B62916C for ; Mon, 25 Mar 2019 06:02:42 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id A6F5D291D2; Mon, 25 Mar 2019 06:02:42 +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=-8.0 required=2.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,FREEMAIL_FROM,MAILING_LIST_MULTI,RCVD_IN_DNSWL_HI autolearn=ham version=3.3.1 Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 25D4B2916C for ; Mon, 25 Mar 2019 06:02:42 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1729517AbfCYGCg (ORCPT ); Mon, 25 Mar 2019 02:02:36 -0400 Received: from mail-pg1-f194.google.com ([209.85.215.194]:32924 "EHLO mail-pg1-f194.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1729373AbfCYGCg (ORCPT ); Mon, 25 Mar 2019 02:02:36 -0400 Received: by mail-pg1-f194.google.com with SMTP id b12so5738903pgk.0; Sun, 24 Mar 2019 23:02:35 -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=j0Kkp+Q1g48qFmEIxNbX8Si8M5iMlqRk5DRd5visCZQ=; b=K19JcWsHru69/+JRSlGqp3B/5LztIKApPQ5qeczawd17eLLZm8xx3TOD7oyw+N2Cys 0eZEsSNXBSqoZEZb0gebw9rYuGzkBaoGTqe3KibF1fgw4sJa3MjBEBMEGcqWUN0TAAWJ gvUYcJsqMHINydviLMcByLM5sYr4FxTz4qwKUq4d9/iA2VipNNly1i2tef6gEv6QrCvt bJDpp0UQhmvbN0RmiIPAcDgV5+UAfzGxbqytdM73AKFCXiHZyssF4pYXufy8gvV0gFt2 pC/vPyuCfcgLoQHx6rTryLo9dRa1tqcgBvcaoyxnW942GFZ3wNFSMlg7XBNBNsvYw8jJ dsJg== 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=j0Kkp+Q1g48qFmEIxNbX8Si8M5iMlqRk5DRd5visCZQ=; b=CIc7dy+1QWT7Eq2L66Nf4EavGutcn1uLHQXKkJorINZvbCzYPAs3UG6NP1W0hpBDHc oe3hutftARK+3uaYK3CQwimduQaeWyizg6YHF9rE73l9opDffIcrBEjQNF4sy7KOV+fD tEykkCSZcaC3/joWJEryUFElm5QxHa9G9/MTECkaLn+oQ4seiU/z2qzlhzkyMHx8/AJD yvH5K7CNj5BhgoDby/vF94QjCniLlpNH/4tjHTJYWjP6nt2+2dOmr0BvB+BK6WNB3cUy rF5WjfGIyDmVYTu6eDps+nfNcX9+ei7IQWxKWNFGNjBJ6z9Qga5sqV5Y7woTNzfIvrZY cfMQ== X-Gm-Message-State: APjAAAWKBrR8pUOGEO5Tz9MhD4T8vcwBQE1Z3lXMNa7JPqUugG7x32pg LBBOAhDAs8VEir0odhl2k+Y= X-Google-Smtp-Source: APXvYqwebddJln7MTdN4Umod2UvaujF1PygARHgSMbYGPz0slKRd3drAsDSWfNavDz7GqDq2EWBGKQ== X-Received: by 2002:aa7:9219:: with SMTP id 25mr22949965pfo.205.1553493754906; Sun, 24 Mar 2019 23:02:34 -0700 (PDT) Received: from localhost.localdomain ([2001:268:c0a5:e068:c70:4af9:86e2:2]) by smtp.gmail.com with ESMTPSA id u4sm16965798pgp.59.2019.03.24.23.02.29 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Sun, 24 Mar 2019 23:02:34 -0700 (PDT) From: William Breathitt Gray To: linus.walleij@linaro.org, bgolaszewski@baylibre.com Cc: akpm@linux-foundation.org, linux-gpio@vger.kernel.org, linux-arch@vger.kernel.org, linux-kernel@vger.kernel.org, andriy.shevchenko@linux.intel.com, linux@rasmusvillemoes.dk, yamada.masahiro@socionext.com, linux-arm-kernel@lists.infradead.org, linux-pm@vger.kernel.org, geert@linux-m68k.org, preid@electromag.com.au, William Breathitt Gray , Andy Shevchenko Subject: [PATCH v11 02/11] lib/test_bitmap.c: Add for_each_set_clump8 test cases Date: Mon, 25 Mar 2019 15:03:30 +0900 Message-Id: <1cc0950e1e68270918da157b979dcbc32eedfd59.1553492741.git.vilhelm.gray@gmail.com> X-Mailer: git-send-email 2.21.0 In-Reply-To: References: MIME-Version: 1.0 Sender: linux-pm-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-pm@vger.kernel.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: Rasmus Villemoes Acked-by: Andrew Morton Reviewed-by: Andy Shevchenko Reviewed-by: Linus Walleij Signed-off-by: William Breathitt Gray --- lib/find_bit.c | 2 +- lib/test_bitmap.c | 65 +++++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 66 insertions(+), 1 deletion(-) diff --git a/lib/find_bit.c b/lib/find_bit.c index c2af1f013ea2..1b6f8a6f1957 100644 --- a/lib/find_bit.c +++ b/lib/find_bit.c @@ -258,7 +258,7 @@ void bitmap_set_value8(unsigned long *const bitmap, const unsigned int size, 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 long low_mask = GENMASK(low_width - 1, 0) << offset; const unsigned int high_width = 8 - low_width; const unsigned long high_mask = GENMASK(high_width - 1, 0); diff --git a/lib/test_bitmap.c b/lib/test_bitmap.c index 6cd7d0740005..8d1f268069c1 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 */ + 0x38, /* 3 bits set across 4-bit boundary */ + 0x38, /* 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, 9, 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 Mon Mar 25 06:03:50 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: 10867921 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 A316F13B5 for ; Mon, 25 Mar 2019 06:03:09 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 8F9272916C for ; Mon, 25 Mar 2019 06:03:09 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 831FC291D2; Mon, 25 Mar 2019 06:03:09 +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=-8.0 required=2.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,FREEMAIL_FROM,MAILING_LIST_MULTI,RCVD_IN_DNSWL_HI autolearn=ham version=3.3.1 Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 084622916C for ; Mon, 25 Mar 2019 06:03:09 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1729482AbfCYGDD (ORCPT ); Mon, 25 Mar 2019 02:03:03 -0400 Received: from mail-pf1-f194.google.com ([209.85.210.194]:36410 "EHLO mail-pf1-f194.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1729373AbfCYGDD (ORCPT ); Mon, 25 Mar 2019 02:03:03 -0400 Received: by mail-pf1-f194.google.com with SMTP id p10so5609271pff.3; Sun, 24 Mar 2019 23:03:02 -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=5tnH02Yc3JnragyosQ4LQT3N7xcrc3Yee7t/cF7aZ1U=; b=jXcJtuVpXOyy1eS/IuOBtT/mVywf/udSKMN9lHjbVpMSww81XCsWV028peup4S4Y7D K7zpMUxdKCaYGIe2Ouaslcx/k/+Ls36UX2GQhSe6rQM/fN+in+RkTx9AT6uxQHpi8oQb LtmlMu4Yvspgyp+9m4c1uSfWawvyadYwSdnbGpOBWcHnP1DZ1FePhrtJ4KUT7ymjYgt4 a1WzOe3D/E5cZ2uCdVC1mTVumhGtFM1nLNuY7DFOe0unxSsmI0hCpXQ76DhuJwef/qmT +DmvGxIas0UslSP9Q5J1HjWFBKJ4pdJx0s8qZn4DFLINFNKNWEoNboQFEWPCOUWasdxo j/Cg== 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=rcNJ2qFBn3hIfOTFCKWSRY9tD55g5tNbJGkKlZtnMo09VbvEhnGyJAgJwb9MqKlK6a aUjC8f3OuRiFVNlmWc2/q30oQrj+16NsfpzdI2w6G6TqdJCyVzcGJNrkFoPHYjr2P8J/ bbPRgrWfDjYCoo7Yj2XfRs5kMBjwh+YeDZWrFgE31u/QYIaby3qf1VdHpY76Eyse2orW r31eY5IilTphkywdShTk1qzUGLSlArLm/cOmALIdFmk265CaQPU0b4j8EwHKKhV92JH5 MyC0GLEEoivaSGjO890umFyVnJZQHCStRopHtjgDBBCtwoLEdfRIkF33APlUrLiC9q/J 74vA== X-Gm-Message-State: APjAAAXZjGnq2D6SU2QVh+F0OGr+1hi2KmA9q5DuDqhE/+lcm6iqpApe L5TKCgPAi9Vj2vnMzpb5Rp4= X-Google-Smtp-Source: APXvYqweGMQRP0AIffUxQkYe4iWYYQtCjS/M0jWgdhXaSpHh4Es1axIwQe8A3wvmL9qDKMr7bk7LqA== X-Received: by 2002:a17:902:1125:: with SMTP id d34mr23926978pla.75.1553493782495; Sun, 24 Mar 2019 23:03:02 -0700 (PDT) Received: from localhost.localdomain ([2001:268:c0a5:e068:c70:4af9:86e2:2]) by smtp.gmail.com with ESMTPSA id m2sm18006198pgr.74.2019.03.24.23.02.54 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Sun, 24 Mar 2019 23:03:01 -0700 (PDT) From: William Breathitt Gray To: linus.walleij@linaro.org, bgolaszewski@baylibre.com Cc: akpm@linux-foundation.org, linux-gpio@vger.kernel.org, linux-arch@vger.kernel.org, linux-kernel@vger.kernel.org, andriy.shevchenko@linux.intel.com, linux@rasmusvillemoes.dk, yamada.masahiro@socionext.com, linux-arm-kernel@lists.infradead.org, linux-pm@vger.kernel.org, geert@linux-m68k.org, preid@electromag.com.au, William Breathitt Gray Subject: [PATCH v11 03/11] gpio: 104-dio-48e: Utilize for_each_set_clump8 macro Date: Mon, 25 Mar 2019 15:03:50 +0900 Message-Id: X-Mailer: git-send-email 2.21.0 In-Reply-To: References: MIME-Version: 1.0 Sender: linux-pm-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-pm@vger.kernel.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 Mon Mar 25 06:04:16 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: 10867925 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 2FDB11390 for ; Mon, 25 Mar 2019 06:03:28 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 1A3CE2916C for ; Mon, 25 Mar 2019 06:03:28 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 0DB0D291CF; Mon, 25 Mar 2019 06:03:28 +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=-8.0 required=2.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,FREEMAIL_FROM,MAILING_LIST_MULTI,RCVD_IN_DNSWL_HI autolearn=ham version=3.3.1 Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 8D269291CF for ; Mon, 25 Mar 2019 06:03:27 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1729508AbfCYGDW (ORCPT ); Mon, 25 Mar 2019 02:03:22 -0400 Received: from mail-pf1-f194.google.com ([209.85.210.194]:43909 "EHLO mail-pf1-f194.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1729447AbfCYGDW (ORCPT ); Mon, 25 Mar 2019 02:03:22 -0400 Received: by mail-pf1-f194.google.com with SMTP id c8so5591130pfd.10; Sun, 24 Mar 2019 23:03:21 -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=wovyItwhuu6up6N9d5xqiEvzR3TkCWii5hwPk2X/3Vc=; b=t7dheYot/to1cOshyBqUFiWKdlK6zUPa2kZgUX9ri9YieAOtQx1M8ljQ2y3F+hlMw+ yZktELnPYVjXjOcQXYhLtjLZvN+Cn+FsSbX0mShwzls2Gkbd0YX0NGM7Ki1+k/6CFeET xmwsMxRzJP1jgzh9y1V0BjDNqkvJb/RRlBtlGEiWuzXqEpF6F0jX9PMjfRQvITS4Ad5Z JeKOn3E3NcAehXBJ417LE51vyin7ympkxi1bkxRCleUe4yF3Y5dYrqxV5Gt4JWroLbgq roCPv0N2VH0J0+FB+tJ3BY3TlWezPpCQTkQ/wlr5TQd4vTwChfvs+GR0g1E2T5j6zqee TU7A== 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=Br5crryZqGY8I+pZ9ffuUNMH2Q37Po4U9IMCmGmXZ1YjZvrBZsSWPI+8uHYb4Vqvpx K15BIb9AVr7ysgw6B4vamnHQ1Mi3CnUaZmLo028GQ3l/+rpiXh45xGLdbun51dM8Vk+N ybKj5OiSoClMqKhMbVW00f6HBL8OPmZ3E69ZpvEEJkVEr/a8hw8kqW0s4JfXkA0vufXb DjWBRG6P9eVKGPa15+ZF3/AM2X2FuWtTQl6KeAhnDwoviRVlP547oiGSxMo8AeaAOFnM K4L3dl65v6qv79qYKJ/jZHOv51+xKnb4u6fDctIhQOEhcUmvaP27+oUXs/7TyaiMWZ0Q ZiYw== X-Gm-Message-State: APjAAAXkjBzSvGr8EMU6W2YkkwPiMoC5XMTm45qvBxDrTYdb0Lih43Sr AoA0j0/Yyrtx9EPGfkUdHIw= X-Google-Smtp-Source: APXvYqw5waGrSLHDsnc18OzsVFHqn2mGhg5skjMtoDXJZ7lHdplfgjMSLhEk0lD7XRiX2TDJzbP8AQ== X-Received: by 2002:a17:902:2d01:: with SMTP id o1mr23638429plb.155.1553493801272; Sun, 24 Mar 2019 23:03:21 -0700 (PDT) Received: from localhost.localdomain ([2001:268:c0a5:e068:c70:4af9:86e2:2]) by smtp.gmail.com with ESMTPSA id i22sm19433145pfa.88.2019.03.24.23.03.14 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Sun, 24 Mar 2019 23:03:20 -0700 (PDT) From: William Breathitt Gray To: linus.walleij@linaro.org, bgolaszewski@baylibre.com Cc: akpm@linux-foundation.org, linux-gpio@vger.kernel.org, linux-arch@vger.kernel.org, linux-kernel@vger.kernel.org, andriy.shevchenko@linux.intel.com, linux@rasmusvillemoes.dk, yamada.masahiro@socionext.com, linux-arm-kernel@lists.infradead.org, linux-pm@vger.kernel.org, geert@linux-m68k.org, preid@electromag.com.au, William Breathitt Gray Subject: [PATCH v11 04/11] gpio: 104-idi-48: Utilize for_each_set_clump8 macro Date: Mon, 25 Mar 2019 15:04:16 +0900 Message-Id: X-Mailer: git-send-email 2.21.0 In-Reply-To: References: MIME-Version: 1.0 Sender: linux-pm-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-pm@vger.kernel.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 Mon Mar 25 06:04:35 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: 10867929 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 9890A1390 for ; Mon, 25 Mar 2019 06:03:43 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 82DF62916C for ; Mon, 25 Mar 2019 06:03:43 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 740F6291D2; Mon, 25 Mar 2019 06:03:43 +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=-8.0 required=2.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,FREEMAIL_FROM,MAILING_LIST_MULTI,RCVD_IN_DNSWL_HI autolearn=ham version=3.3.1 Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 6135D2916C for ; Mon, 25 Mar 2019 06:03:42 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1729591AbfCYGDl (ORCPT ); Mon, 25 Mar 2019 02:03:41 -0400 Received: from mail-pg1-f195.google.com ([209.85.215.195]:35028 "EHLO mail-pg1-f195.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1729421AbfCYGDl (ORCPT ); Mon, 25 Mar 2019 02:03:41 -0400 Received: by mail-pg1-f195.google.com with SMTP id g8so5732591pgf.2; Sun, 24 Mar 2019 23:03:40 -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=rgWDXyitkPfkOwvJZbjg9H8+KzeLJbUpGMI+NATW6JM=; b=o7Q8LOBMw1DMmvh2FQtEPxvk2VrhyZpW2Djdn/MEPusKFoQxLORfh2u1h5c2mzM+Nv XB7ANjW7dtonG+JfBPa30RrRBPCjuz8V1yjpweC/M6O7gK3kUeSl/j9WnbVOGQmmDblA la4HDSEdB4BVqtSG/0aWx5S0QfuKbxfj2AxX7ecA5PRQwdzpBm69fdxTNlE8BhQXOP5r Dprh830R5tYwYKeFTQm24Q69ZLNsZ28oJVWQM7SKCXSDv4GO98z9FBY98tYR5BtoMhzl Hkg4gQhFqYGjxgmlVUmSwMTC8hSZx+tsimw82JrvCg4Sng/45lecLfj/MJfG+gUg/H8j gMdg== 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=b/qAxPGZ5h1zHQEi+eYcsTD+G3v3hOa00ri2OBLKKeU6wVgyBD3Gd0t1G1lmKWU9Lp s/TvLkoPUdC0BzVwNRtd/ejI5ev/LC5QrE/TLt3CUBrQdMq7NSQBAOnnzaIHg7fmaqGv e0TYzy4QetKLBeT462WWUiej2/sH/KHanYsaqva5+1DCtRnkTYF+8yoLU6Hma+g9biWj otSCx7T3d+jC26VsuDhrt8xjOFdqhDahaReaQ8YM8sq2Xk1Pbv6jKurPU9SSPDutGogf YnRNL/hI2L9jXUNdP1pF1iEZHbUpSVGgO92uHrN6z8vSangmYqxtRsvINk34s66nMso1 lFdw== X-Gm-Message-State: APjAAAXG+bafuwvRjPqc/RLeY1EPwMplG6riuGHMsLITbWRs/tQOtCzX uE03FnT8WDFTQMfCZaMB1kk= X-Google-Smtp-Source: APXvYqwJHxRiKAOreV/2XbIRIK5zC0Oj8txemDUjqCdl8WYAyZoWteeMw82eWzU5s3uS6Ulj31Wgeg== X-Received: by 2002:a63:ff1d:: with SMTP id k29mr22089186pgi.258.1553493820509; Sun, 24 Mar 2019 23:03:40 -0700 (PDT) Received: from localhost.localdomain ([2001:268:c0a5:e068:c70:4af9:86e2:2]) by smtp.gmail.com with ESMTPSA id s4sm16610875pgp.89.2019.03.24.23.03.33 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Sun, 24 Mar 2019 23:03:40 -0700 (PDT) From: William Breathitt Gray To: linus.walleij@linaro.org, bgolaszewski@baylibre.com Cc: akpm@linux-foundation.org, linux-gpio@vger.kernel.org, linux-arch@vger.kernel.org, linux-kernel@vger.kernel.org, andriy.shevchenko@linux.intel.com, linux@rasmusvillemoes.dk, yamada.masahiro@socionext.com, linux-arm-kernel@lists.infradead.org, linux-pm@vger.kernel.org, geert@linux-m68k.org, preid@electromag.com.au, William Breathitt Gray Subject: [PATCH v11 05/11] gpio: gpio-mm: Utilize for_each_set_clump8 macro Date: Mon, 25 Mar 2019 15:04:35 +0900 Message-Id: <72cd757e67c1f4651a0066f25f142080b4501f13.1553492741.git.vilhelm.gray@gmail.com> X-Mailer: git-send-email 2.21.0 In-Reply-To: References: MIME-Version: 1.0 Sender: linux-pm-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-pm@vger.kernel.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 Mon Mar 25 06:04: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: 10867933 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 A253D1390 for ; Mon, 25 Mar 2019 06:04:04 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 8D1DF2916C for ; Mon, 25 Mar 2019 06:04:04 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 81004291D2; Mon, 25 Mar 2019 06:04:04 +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=-8.0 required=2.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,FREEMAIL_FROM,MAILING_LIST_MULTI,RCVD_IN_DNSWL_HI autolearn=ham version=3.3.1 Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 090182916C for ; Mon, 25 Mar 2019 06:04:04 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1729519AbfCYGED (ORCPT ); Mon, 25 Mar 2019 02:04:03 -0400 Received: from mail-pg1-f193.google.com ([209.85.215.193]:35065 "EHLO mail-pg1-f193.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1729342AbfCYGEC (ORCPT ); Mon, 25 Mar 2019 02:04:02 -0400 Received: by mail-pg1-f193.google.com with SMTP id g8so5733339pgf.2; Sun, 24 Mar 2019 23:04:02 -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=JhQ28KZcd91XNKjTCGWYQ1G7G3aiOZwynfHwUrGcvPU=; b=UKDCmV880Ib+0mSZI487ICH1lhL+8Y7B9pfFY93mw9KhNqWmu1SkkHSCYV4ymyXwMS Zd2srRA95lCFo7nqx4KXNImPOvkbxd18ddCM92SWYwefyEJOuP9q2im4UOUvnEdSGjgc upekYpbjj/OI+DfCycs2qnrmbXNzle8jU65dthVcI5N5BSwlVQwOVAxTM1NKSELGK50S ORfN0aNNWGu1nbEH2jZo+UUGzt8kvZN0mlv71U+FYobl80fPSyPfM9FQTu+sNH0fIwVo WQkmAS87B3Mc8LBGe+iGfj+bSH5d/iYVRzbflHWDPI8QwqplccMtV8Pbh1ETnYb97VkK n09w== 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=Ka/HCX6NUZn8cc0VDCXXvV+FQ07Z1P0Fn8Oec1XCLsF+79wPw5cuJSODj7mo/G1crO pgMQ7JYrVl9KQ/cQeo3qNA/c9t1plUreHImzwnM4pkX2Bk6D9adqOycg8f1BBL7V4YCg 1Pw6hjyK+mK+ehb/K1nuaXVP4Dt/8A33WEpRtSzri/tjtM47aNUSD4aP5LK4z9jTkxhQ sQvcWvCRYxF5mXmtSXbYTkHwAReO+BE24Aj4uqJXyyJLkT4pNzkUnlFcvWFppS8+hBVX Ogfb3274y7lDrG2olGARMeoWmoAjTAVxiaeosUGwOiDTJ8OyhjBkiHoio0DYjjisiNDV wAUQ== X-Gm-Message-State: APjAAAVzJx4eAutlgw2q8p+OH96xRvsQOtNWNKVfVC2KiaowEQ9EWv2A xRcb04kIzO/WV5IcesFCc3g= X-Google-Smtp-Source: APXvYqz6b4Z+uH5QudnEyELTjtjeKxo6PAfrZgYc1QQLZX2IAinJV8EwccTFTKX01X+cJFZ3+Urb6w== X-Received: by 2002:aa7:938b:: with SMTP id t11mr15219939pfe.67.1553493842170; Sun, 24 Mar 2019 23:04:02 -0700 (PDT) Received: from localhost.localdomain ([2001:268:c0a5:e068:c70:4af9:86e2:2]) by smtp.gmail.com with ESMTPSA id y12sm4568022pgq.64.2019.03.24.23.03.54 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Sun, 24 Mar 2019 23:04:01 -0700 (PDT) From: William Breathitt Gray To: linus.walleij@linaro.org, bgolaszewski@baylibre.com Cc: akpm@linux-foundation.org, linux-gpio@vger.kernel.org, linux-arch@vger.kernel.org, linux-kernel@vger.kernel.org, andriy.shevchenko@linux.intel.com, linux@rasmusvillemoes.dk, yamada.masahiro@socionext.com, linux-arm-kernel@lists.infradead.org, linux-pm@vger.kernel.org, geert@linux-m68k.org, preid@electromag.com.au, William Breathitt Gray Subject: [PATCH v11 06/11] gpio: ws16c48: Utilize for_each_set_clump8 macro Date: Mon, 25 Mar 2019 15:04:54 +0900 Message-Id: <186e263055b327f3333677db67f0ac4a3b428def.1553492741.git.vilhelm.gray@gmail.com> X-Mailer: git-send-email 2.21.0 In-Reply-To: References: MIME-Version: 1.0 Sender: linux-pm-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-pm@vger.kernel.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 Mon Mar 25 06:05:16 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: 10867937 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 866A91390 for ; Mon, 25 Mar 2019 06:04:39 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 6DAD12908E for ; Mon, 25 Mar 2019 06:04:39 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 5E301290EB; Mon, 25 Mar 2019 06:04:39 +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=-8.0 required=2.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,FREEMAIL_FROM,MAILING_LIST_MULTI,RCVD_IN_DNSWL_HI autolearn=ham version=3.3.1 Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id D5E382908E for ; Mon, 25 Mar 2019 06:04:38 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1729503AbfCYGEd (ORCPT ); Mon, 25 Mar 2019 02:04:33 -0400 Received: from mail-pf1-f195.google.com ([209.85.210.195]:46467 "EHLO mail-pf1-f195.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1729342AbfCYGEd (ORCPT ); Mon, 25 Mar 2019 02:04:33 -0400 Received: by mail-pf1-f195.google.com with SMTP id 9so5580356pfj.13; Sun, 24 Mar 2019 23:04:32 -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=LbAhFB9V6BisOLUTsbpvSet6qgSjh9MdQ4kQbff2Dwk=; b=PwqVKKMSGSxhxKN7Au2TB+BzoEmcE1w/jEZtrJlYLBGEwmz8ULf1pWG2j0/LGWtovG wx4eXyQSQwq3ug9iJZBsR1DK7AX3QxX7UlVBxvj2pcHTN/iXP+JWox901huyuvzIKAPG 7l8OWVureNvuYpp+I80NJ126AWSOgoNGGsM543rdnmQHDNLOtEg8p3COaoOkiNr3vRBj CM1nkINpm+NbjujgsyETGdbbDLQ8mJ457BBphNBAZSJzNJJv+V342cog8bfNktDtvggh eqKkNH8/CaJ6tFg6B5QXJxrQse8S/kBOOpRyFKEAj2IvKgTg6MKKa77vtpTif8vL+MQP vS9w== 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=GzxL2YJ3CR1mpu+n0ZOa4l3XMRyRaZ5o4rK1f3IkjegYln9QyGHVg1ceGN1pR0Wwfv evSkC4xC4ZbT5KGBF+bZdjePnpd7+JMKMyggkAI0E+dv2F7zm2Lc9y+gaMrfG+8LC5GK WzMJJisleNHPLghkU45bOSpJBlqBOsiTsNPQYJd055wqe9frh+/myHQPaV4a4sYQYeRu b35M3zQhTIlZIwjaFRE8X2Fohq3zTiZSoaXp2QOb+0UnMGvwqe25gp0VMNIZVXdIcexB FKZZNNnMCUz4pTuk/A97/eooay7lqKA+SM88nzofOauxEnVJthcg6fmstb1F3MCZoAot Sy7A== X-Gm-Message-State: APjAAAUD4bTDc+fFhYofK0YYDQFAB+jAr7w2zEPLnwQmNn3j31M28I3U 0qZ8TudR9/enfRGcomfhn2Q= X-Google-Smtp-Source: APXvYqxGtFKQhfIms0S4Sx0CIXZrTI1OK0EqTLcruiRSdqQwPUA55C8iFjdr/u+iHjpmJTXjtVpVtg== X-Received: by 2002:a17:902:76c1:: with SMTP id j1mr21210416plt.224.1553493872149; Sun, 24 Mar 2019 23:04:32 -0700 (PDT) Received: from localhost.localdomain ([2001:268:c0a5:e068:c70:4af9:86e2:2]) by smtp.gmail.com with ESMTPSA id m67sm21403332pfj.70.2019.03.24.23.04.26 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Sun, 24 Mar 2019 23:04:31 -0700 (PDT) From: William Breathitt Gray To: linus.walleij@linaro.org, bgolaszewski@baylibre.com Cc: akpm@linux-foundation.org, linux-gpio@vger.kernel.org, linux-arch@vger.kernel.org, linux-kernel@vger.kernel.org, andriy.shevchenko@linux.intel.com, linux@rasmusvillemoes.dk, yamada.masahiro@socionext.com, linux-arm-kernel@lists.infradead.org, linux-pm@vger.kernel.org, geert@linux-m68k.org, preid@electromag.com.au, William Breathitt Gray Subject: [PATCH v11 07/11] gpio: pci-idio-16: Utilize for_each_set_clump8 macro Date: Mon, 25 Mar 2019 15:05:16 +0900 Message-Id: <4405d4ee08f03855d5884f89e834c6f1c88b26bf.1553492741.git.vilhelm.gray@gmail.com> X-Mailer: git-send-email 2.21.0 In-Reply-To: References: MIME-Version: 1.0 Sender: linux-pm-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-pm@vger.kernel.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 Mon Mar 25 06:05:46 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: 10867941 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 548E61390 for ; Mon, 25 Mar 2019 06:04:57 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 40B6F29195 for ; Mon, 25 Mar 2019 06:04:57 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 3507F29199; Mon, 25 Mar 2019 06:04:57 +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=-8.0 required=2.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,FREEMAIL_FROM,MAILING_LIST_MULTI,RCVD_IN_DNSWL_HI autolearn=ham version=3.3.1 Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 9C5B129195 for ; Mon, 25 Mar 2019 06:04:56 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1729373AbfCYGE4 (ORCPT ); Mon, 25 Mar 2019 02:04:56 -0400 Received: from mail-pf1-f194.google.com ([209.85.210.194]:34581 "EHLO mail-pf1-f194.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1729342AbfCYGEz (ORCPT ); Mon, 25 Mar 2019 02:04:55 -0400 Received: by mail-pf1-f194.google.com with SMTP id b3so4228734pfd.1; Sun, 24 Mar 2019 23:04:55 -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=lo/y4LVrDbirngV8ZQJtGQjH8jQRyE53ymUz3wq08xM=; b=ryg5WfZWRCdggnxmMinSCT4uHdXW9ujOrE7WO/i/SiuGIeLNk/0H06mUkmn59gDYBA tCqEAXoZMemt9Zu8uZMqr52y54hDldz5qH3NggOsK1at1mavOdgS1y12kBuy770StvVK aSc/8mh+9FYkY9XRcQY70nRInfP/4aMDk7Ss5zDiLtS1MKNY5IvnqYBRTCjq6a/bIKI4 Z4C8lj6K8R4JY8pONH1PKNRP7OwDF+uFBIyHlpgas9ZlvYwKwXW+pTUrmDPi0dIFflu3 zL4TOJm9dqwyyALNQmSzdUy1Q34nELpiRO6nA/Tx8l2munD1npTqS6gUbjW/cLq6B3Kz 8OuA== 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=JRvHSJXx/DmU3ESiAULnvlAoD6w8WpMFbUCZHTn7yvDmGVMZvNNuxlrbIKZPP1nS7w Rop9MMpy9YDpbG9klLoMip48RnuLpN9ba3WETx37iyoDjYt1Aj0ZaZItb1AAxbFlRf3R ULJFtjI3Z8mm+2TS58AlZtj/I+A7arAgeLOb39dwwqZlMfJtgGuONq+EL5smKTP/oYFS BAgFv5EhVZ2GqYZUKwhFhIfbopLlQHKUh5bc7+OyAqUZcWpbIo5sojMYoJPH7cI5CdpH QLyotr0dcB+EgDnf0N+pow3GWOu86l2beyXJDZLAJrGH5sG639aiibaaEB9ZTxi3Y9L5 5BaQ== X-Gm-Message-State: APjAAAUzQg9SVROccEU753NOjxJEtYsEG737CHpwhM6aeWFX5l4k2qie ONMRgkIxPomiBYk7117mqtc= X-Google-Smtp-Source: APXvYqzFhzHd2Jxz0COAG4rEDOkX/DQLp/PHNeDIqAzJs9KxeLlCrjKi73Y0vhgkOcYbZfwwQoCyqA== X-Received: by 2002:a17:902:6a89:: with SMTP id n9mr22786402plk.223.1553493895062; Sun, 24 Mar 2019 23:04:55 -0700 (PDT) Received: from localhost.localdomain ([2001:268:c0a5:e068:c70:4af9:86e2:2]) by smtp.gmail.com with ESMTPSA id s4sm16613629pgp.89.2019.03.24.23.04.44 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Sun, 24 Mar 2019 23:04:54 -0700 (PDT) From: William Breathitt Gray To: linus.walleij@linaro.org, bgolaszewski@baylibre.com Cc: akpm@linux-foundation.org, linux-gpio@vger.kernel.org, linux-arch@vger.kernel.org, linux-kernel@vger.kernel.org, andriy.shevchenko@linux.intel.com, linux@rasmusvillemoes.dk, yamada.masahiro@socionext.com, linux-arm-kernel@lists.infradead.org, linux-pm@vger.kernel.org, geert@linux-m68k.org, preid@electromag.com.au, William Breathitt Gray Subject: [PATCH v11 08/11] gpio: pcie-idio-24: Utilize for_each_set_clump8 macro Date: Mon, 25 Mar 2019 15:05:46 +0900 Message-Id: X-Mailer: git-send-email 2.21.0 In-Reply-To: References: MIME-Version: 1.0 Sender: linux-pm-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-pm@vger.kernel.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 Mon Mar 25 06:06:09 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: 10867945 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 1C0AF139A for ; Mon, 25 Mar 2019 06:05:20 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 07FE229195 for ; Mon, 25 Mar 2019 06:05:20 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id F061629199; Mon, 25 Mar 2019 06:05:19 +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=-8.0 required=2.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,FREEMAIL_FROM,MAILING_LIST_MULTI,RCVD_IN_DNSWL_HI autolearn=ham version=3.3.1 Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 88B7B29195 for ; Mon, 25 Mar 2019 06:05:19 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1729608AbfCYGFO (ORCPT ); Mon, 25 Mar 2019 02:05:14 -0400 Received: from mail-pf1-f196.google.com ([209.85.210.196]:34617 "EHLO mail-pf1-f196.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1729519AbfCYGFN (ORCPT ); Mon, 25 Mar 2019 02:05:13 -0400 Received: by mail-pf1-f196.google.com with SMTP id b3so4229275pfd.1; Sun, 24 Mar 2019 23:05:13 -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=UifkzEkFRqXu3yixaaw6yvTChu7M21y6ZQxvlg1zFMs=; b=cUZivDN2YWWNLkTIYSS6FpIHofsi9nxbjKjplH5GCWNdwnLqzZLYIHVzd0DMyNb/0F JfvRjZ39ub+vB+JlNnJEulAXTcC7kJCoZXroxbm64jTDrNDOr/ZgrG98g6gkXJeJ7dkF n8ZCBvTgQUvXlBy7f2DZvi3loBxuDWodB8DoWyK2LWYGThL5u6qi8s1mFYVG75RKASyQ +VmBfU5mpq0ZYbg76cUhEA3lB5K2OxKme606WKXH2PdIjwEOFJtgY1Pe07L3eicxIHYT OpZqL7ktiWVKWd21K2HYs/5QGn0TPruxFiaY2p2PiFcALREQNBY91tY39orS71lN5eku w27Q== 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=YkLR2muv5Z9psikLRjMBrOaJqmgFsL+N+yjMWl6fHxLiX/k/4Cd2ZJDrJBvUVVG204 +l24/6m0+ir1q7TwThSzzVAUBIgxa0endMEZDOhv9HFJQjYXup6ERENFs19gTB0dk/D6 bHa22Mg1j88UqrA4loNS6uOD7wrPp0JBesCaIpglNsrxh8Vk6TJEykAmC2OUXrxNzIiL XJsaXpzhXaAMRlwcHVaPXSLG62ssCKMn3brQycT1+cBeLfnffmP82G/sB6w3rM2Pg7hg l42Fr7Ggwim6Ki2SGGQI+P4DT/aXKoYAkWE0s0i23ZZHQWcPvtZPGr7mTNhAAC7q6Nlw Z0qg== X-Gm-Message-State: APjAAAWQwM5PH4HzKB6nhuSDwExWse4u5+TsnRagifeWHSu7aAdYv9Rl 1fAM9eXngc+2x5f03OX2zXQ= X-Google-Smtp-Source: APXvYqwW/zp/Q8To3dpTdoxUCtqXaOHNaAgv7+rJZJtMlrJQoCPCu3MGz2qZUjdACT3vJv1BfuwrqA== X-Received: by 2002:a17:902:121:: with SMTP id 30mr23719883plb.315.1553493913056; Sun, 24 Mar 2019 23:05:13 -0700 (PDT) Received: from localhost.localdomain ([2001:268:c0a5:e068:c70:4af9:86e2:2]) by smtp.gmail.com with ESMTPSA id w123sm21668681pfw.72.2019.03.24.23.05.08 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Sun, 24 Mar 2019 23:05:12 -0700 (PDT) From: William Breathitt Gray To: linus.walleij@linaro.org, bgolaszewski@baylibre.com Cc: akpm@linux-foundation.org, linux-gpio@vger.kernel.org, linux-arch@vger.kernel.org, linux-kernel@vger.kernel.org, andriy.shevchenko@linux.intel.com, linux@rasmusvillemoes.dk, yamada.masahiro@socionext.com, linux-arm-kernel@lists.infradead.org, linux-pm@vger.kernel.org, geert@linux-m68k.org, preid@electromag.com.au, William Breathitt Gray Subject: [PATCH v11 09/11] gpio: uniphier: Utilize for_each_set_clump8 macro Date: Mon, 25 Mar 2019 15:06:09 +0900 Message-Id: <82b21a3c4f84bad98487c450a8b3072ecf1c44c3.1553492741.git.vilhelm.gray@gmail.com> X-Mailer: git-send-email 2.21.0 In-Reply-To: References: MIME-Version: 1.0 Sender: linux-pm-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-pm@vger.kernel.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); From patchwork Mon Mar 25 06:06:28 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: 10867949 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 B2101139A for ; Mon, 25 Mar 2019 06:05:40 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 9DF6529195 for ; Mon, 25 Mar 2019 06:05:40 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 9225429199; Mon, 25 Mar 2019 06:05:40 +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=-8.0 required=2.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,FREEMAIL_FROM,MAILING_LIST_MULTI,RCVD_IN_DNSWL_HI autolearn=ham version=3.3.1 Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 160AB29198 for ; Mon, 25 Mar 2019 06:05:40 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1729587AbfCYGFe (ORCPT ); Mon, 25 Mar 2019 02:05:34 -0400 Received: from mail-pg1-f195.google.com ([209.85.215.195]:46650 "EHLO mail-pg1-f195.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1729400AbfCYGFe (ORCPT ); Mon, 25 Mar 2019 02:05:34 -0400 Received: by mail-pg1-f195.google.com with SMTP id a22so5690514pgg.13; Sun, 24 Mar 2019 23:05:33 -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=o+xpStCAm5+KqB9WkdPQRn7Ir+DpSVJA0QLNqt7/oEw=; b=Q28Sq2XUEgcaTJcwxxckkZWKTAytkpVpdRls9LHOvD9lQskNxUADGQcPDfb54E4ZUf 1t4clNC9Nc/Wd8MSgpv/CmsfyGkFH1/gwwXcmxq1mAXx96SoA8dSnqHBGCGbxYavIIka UNBnAJ6GUnLyB2qGA2IlqbML1y0mEwdGTB/bIocp78FLPTT3KycCziysUxYojSIarv+e d4npvK249GckLUYus0xv8xLBCb+TqsbkRrMGcNha3OKwRuoprMh+Gl9oQsHmiyAMeELR rsFi+D6gBoM+7DifiHl0uC6JOoiUmZ4aUa9pa7k1KHhdCuhOronP3JzUftAxLPO1dP7w nj8Q== 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=o+xpStCAm5+KqB9WkdPQRn7Ir+DpSVJA0QLNqt7/oEw=; b=PkkXRnskz4TuzjN4wp8Q6UvIFFLpXHpbg8c9dYyKJHln4qVwVv3zj1u5EwrFT/WsyD 4EM8Jh84oG1PVUS4m7qX0xn3lAjwJobxMj0q/rB6CcheMSfjq94H2+QK0SMdzweny5ov oys3xf7Gxy98kMkTpnFLDbrSxuN3sZ9fr2iD+3pvVLaM449nzM2QurBG5BhmIkgt/Z7a 6fd+0GmZQAcvncojZ6EH5spGYymnBP7rjfjwaTgFzW3ifd8pPaRpIxFCACkojuL5CN2T NpC+DH8WtlYVHQYjIOpcv7zakkf00Z/6pcccacnOzPEy6i67pQbzCU+9tPe0y8hUZYkc frYQ== X-Gm-Message-State: APjAAAWnrKUNGiQBHrA7Ua0uT7gWsbxJXHDLSrsOCDErWwATzwk3tXO/ xnr9H6u7aaZaJz9kHOYWuDs= X-Google-Smtp-Source: APXvYqzMSY3gRxBRSywfQidmG96EAN7QjCHLwLjuGUdsN7BrTElN8NIefTvVxBsheUxWhV3wYBCNmw== X-Received: by 2002:aa7:8ad4:: with SMTP id b20mr15624226pfd.249.1553493933529; Sun, 24 Mar 2019 23:05:33 -0700 (PDT) Received: from localhost.localdomain ([2001:268:c0a5:e068:c70:4af9:86e2:2]) by smtp.gmail.com with ESMTPSA id m24sm16401479pgv.1.2019.03.24.23.05.27 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Sun, 24 Mar 2019 23:05:33 -0700 (PDT) From: William Breathitt Gray To: linus.walleij@linaro.org, bgolaszewski@baylibre.com Cc: akpm@linux-foundation.org, linux-gpio@vger.kernel.org, linux-arch@vger.kernel.org, linux-kernel@vger.kernel.org, andriy.shevchenko@linux.intel.com, linux@rasmusvillemoes.dk, yamada.masahiro@socionext.com, linux-arm-kernel@lists.infradead.org, linux-pm@vger.kernel.org, geert@linux-m68k.org, preid@electromag.com.au, William Breathitt Gray Subject: [PATCH v11 10/11] thermal: intel: intel_soc_dts_iosf: Utilize for_each_set_clump8 macro Date: Mon, 25 Mar 2019 15:06:28 +0900 Message-Id: <02ebb522c3c07e9ed13b8e07559abd17e8648987.1553492741.git.vilhelm.gray@gmail.com> X-Mailer: git-send-email 2.21.0 In-Reply-To: References: MIME-Version: 1.0 Sender: linux-pm-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-pm@vger.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP Utilize for_each_set_clump8 macro, and the bitmap_set_value8 and bitmap_get_value8 functions, where appropriate. In addition, remove the now unnecessary temp_mask and temp_shift members of the intel_soc_dts_sensor_entry structure. Suggested-by: Andy Shevchenko Tested-by: Andy Shevchenko Signed-off-by: William Breathitt Gray --- drivers/thermal/intel/intel_soc_dts_iosf.c | 29 +++++++++++++--------- drivers/thermal/intel/intel_soc_dts_iosf.h | 2 -- 2 files changed, 17 insertions(+), 14 deletions(-) diff --git a/drivers/thermal/intel/intel_soc_dts_iosf.c b/drivers/thermal/intel/intel_soc_dts_iosf.c index e0813dfaa278..832e74e5fbde 100644 --- a/drivers/thermal/intel/intel_soc_dts_iosf.c +++ b/drivers/thermal/intel/intel_soc_dts_iosf.c @@ -15,6 +15,7 @@ #define pr_fmt(fmt) KBUILD_MODNAME ": " fmt +#include #include #include #include @@ -111,6 +112,7 @@ static int update_trip_temp(struct intel_soc_dts_sensor_entry *dts, { int status; u32 temp_out; + unsigned long update_ptps; u32 out; u32 store_ptps; u32 store_ptmc; @@ -129,8 +131,9 @@ static int update_trip_temp(struct intel_soc_dts_sensor_entry *dts, if (status) return status; - out = (store_ptps & ~(0xFF << (thres_index * 8))); - out |= (temp_out & 0xFF) << (thres_index * 8); + update_ptps = store_ptps; + bitmap_set_value8(&update_ptps, 32, temp_out & 0xFF, thres_index * 8); + out = update_ptps; status = iosf_mbi_write(BT_MBI_UNIT_PMC, MBI_REG_WRITE, SOC_DTS_OFFSET_PTPS, out); if (status) @@ -232,6 +235,7 @@ static int sys_get_curr_temp(struct thermal_zone_device *tzd, u32 out; struct intel_soc_dts_sensor_entry *dts; struct intel_soc_dts_sensors *sensors; + unsigned long temp_raw; dts = tzd->devdata; sensors = dts->sensors; @@ -240,7 +244,8 @@ static int sys_get_curr_temp(struct thermal_zone_device *tzd, if (status) return status; - out = (out & dts->temp_mask) >> dts->temp_shift; + temp_raw = out; + out = bitmap_get_value8(&temp_raw, 32, dts->id * 8); out -= SOC_DTS_TJMAX_ENCODING; *temp = sensors->tj_max - out * 1000; @@ -290,10 +295,13 @@ static int add_dts_thermal_zone(int id, struct intel_soc_dts_sensor_entry *dts, { char name[10]; int trip_count = 0; + int writable_trip_count = 0; int trip_mask = 0; u32 store_ptps; int ret; - int i; + unsigned int i; + unsigned long trip; + unsigned long ptps; /* Store status to restor on exit */ ret = iosf_mbi_read(BT_MBI_UNIT_PMC, MBI_REG_READ, @@ -302,11 +310,10 @@ static int add_dts_thermal_zone(int id, struct intel_soc_dts_sensor_entry *dts, goto err_ret; dts->id = id; - dts->temp_mask = 0x00FF << (id * 8); - dts->temp_shift = id * 8; if (notification_support) { trip_count = min(SOC_MAX_DTS_TRIPS, trip_cnt); - trip_mask = BIT(trip_count - read_only_trip_cnt) - 1; + writable_trip_count = trip_count - read_only_trip_cnt; + trip_mask = GENMASK(writable_trip_count - 1, 0); } /* Check if the writable trip we provide is not used by BIOS */ @@ -315,11 +322,9 @@ static int add_dts_thermal_zone(int id, struct intel_soc_dts_sensor_entry *dts, if (ret) trip_mask = 0; else { - for (i = 0; i < trip_count; ++i) { - if (trip_mask & BIT(i)) - if (store_ptps & (0xff << (i * 8))) - trip_mask &= ~BIT(i); - } + ptps = store_ptps; + for_each_set_clump8(i, trip, &ptps, writable_trip_count * 8) + trip_mask &= ~BIT(i / 8); } dts->trip_mask = trip_mask; dts->trip_count = trip_count; diff --git a/drivers/thermal/intel/intel_soc_dts_iosf.h b/drivers/thermal/intel/intel_soc_dts_iosf.h index 625e37bf93dc..d0362d7acdef 100644 --- a/drivers/thermal/intel/intel_soc_dts_iosf.h +++ b/drivers/thermal/intel/intel_soc_dts_iosf.h @@ -33,8 +33,6 @@ struct intel_soc_dts_sensors; struct intel_soc_dts_sensor_entry { int id; - u32 temp_mask; - u32 temp_shift; u32 store_status; u32 trip_mask; u32 trip_count; From patchwork Mon Mar 25 06:06:47 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: 10867951 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 C0270139A for ; Mon, 25 Mar 2019 06:05:56 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id AC93928567 for ; Mon, 25 Mar 2019 06:05:56 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 9D848291DA; Mon, 25 Mar 2019 06:05:56 +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=-8.0 required=2.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,FREEMAIL_FROM,MAILING_LIST_MULTI,RCVD_IN_DNSWL_HI autolearn=ham version=3.3.1 Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 7E18F28567 for ; Mon, 25 Mar 2019 06:05:55 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1729633AbfCYGFy (ORCPT ); Mon, 25 Mar 2019 02:05:54 -0400 Received: from mail-pf1-f193.google.com ([209.85.210.193]:44248 "EHLO mail-pf1-f193.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1729373AbfCYGFy (ORCPT ); Mon, 25 Mar 2019 02:05:54 -0400 Received: by mail-pf1-f193.google.com with SMTP id a3so5587351pff.11; Sun, 24 Mar 2019 23:05:53 -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=p6jZFM4uKZmmd8N/chkful+ZD8FsiAd/9uwJICIJ0zk=; b=jqumGuL+igo/SkIi2aID93fjdQzDHtjSSvtucpTKc92SzXwZT4k5G+kymX27UTh541 d0B+WYVS4FKTQFfwoolGxbR8dwqIp+3BE/22l0q2wEDoOxsBxqqae8QyqJycRidrZWI0 ACclu19uKMz4gcTlU873cG9+xs1K+5DGzeLcxzYRRwbxkiXAnZ1Lq/KZMdGvRkG4cNJN hwGvJWSx6fTXA39+0VSWWwTmjUnRT4s/NU3g4i/tfiLCQiOb99NVKOA1mvnwRHS+PjyG C0I1Kg8eizZA/SJrgWlrKs68LwenOWrg7n1bS87ydxx0jrwZZnNZmYX1YwHxV6xwzLp1 75tQ== 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=p6jZFM4uKZmmd8N/chkful+ZD8FsiAd/9uwJICIJ0zk=; b=KK2A27C79S+o6plLBXlSYhLmoyNWcZnJEXCSEclWQe4J28AYetjfNZBBjjO+aGT88v dmjK6Vd3zYX2R5HzMaxSFHOgcNnbTkEsutg3RHUN/7/jR0W5PUG1gwseltEpD9xzGKSA qzg+cI/U0iT17ULnwNzi1DmOecEUJTH7qX4Hdc6VeHlIZxmKf8uW1g3fJ0Nh/n2MbzxO k0nu54hKZ6pMhQD5Ga2WuuqX3Tia04gjFd++7f9FpunYqGOjz9nrtYdRv2ka2BlHkD7j OABmhSqhqG8coaSzHSLws3yXukF0UBWzQGVRkHUYQc5SSvO5adnklDVGB76tgJjdaeZz DZMw== X-Gm-Message-State: APjAAAU8uoMPHc/m36M2uSRwAoUgS0RLOWY1QYSNkJRp0Pp5flsDMopK 73WazdJAyBZEJjafG9IFFn8= X-Google-Smtp-Source: APXvYqwDxykQkjuOKa1oZBlXM1NHkyoBvXV+7ZgKvU3Rmy/U4UOsNXSh3i4l6XjRsDUy5ImRcJfMow== X-Received: by 2002:a17:902:282b:: with SMTP id e40mr23266401plb.111.1553493953557; Sun, 24 Mar 2019 23:05:53 -0700 (PDT) Received: from localhost.localdomain ([2001:268:c0a5:e068:c70:4af9:86e2:2]) by smtp.gmail.com with ESMTPSA id k22sm20299064pfi.90.2019.03.24.23.05.46 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Sun, 24 Mar 2019 23:05:53 -0700 (PDT) From: William Breathitt Gray To: linus.walleij@linaro.org, bgolaszewski@baylibre.com Cc: akpm@linux-foundation.org, linux-gpio@vger.kernel.org, linux-arch@vger.kernel.org, linux-kernel@vger.kernel.org, andriy.shevchenko@linux.intel.com, linux@rasmusvillemoes.dk, yamada.masahiro@socionext.com, linux-arm-kernel@lists.infradead.org, linux-pm@vger.kernel.org, geert@linux-m68k.org, preid@electromag.com.au, William Breathitt Gray , Geert Uytterhoeven Subject: [PATCH v11 11/11] gpio: 74x164: Utilize the for_each_set_clump8 macro Date: Mon, 25 Mar 2019 15:06:47 +0900 Message-Id: <8a2e010aa62e00e1fd56802d6c842ae972d2f283.1553492741.git.vilhelm.gray@gmail.com> X-Mailer: git-send-email 2.21.0 In-Reply-To: References: MIME-Version: 1.0 Sender: linux-pm-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-pm@vger.kernel.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. Suggested-by: Andy Shevchenko Cc: Geert Uytterhoeven Cc: Phil Reid Signed-off-by: William Breathitt Gray --- drivers/gpio/gpio-74x164.c | 20 ++++++++++---------- 1 file changed, 10 insertions(+), 10 deletions(-) diff --git a/drivers/gpio/gpio-74x164.c b/drivers/gpio/gpio-74x164.c index fb7b620763a2..e43a6de3b6eb 100644 --- a/drivers/gpio/gpio-74x164.c +++ b/drivers/gpio/gpio-74x164.c @@ -9,6 +9,7 @@ * published by the Free Software Foundation. */ +#include #include #include #include @@ -75,20 +76,19 @@ static void gen_74x164_set_multiple(struct gpio_chip *gc, unsigned long *mask, unsigned long *bits) { struct gen_74x164_chip *chip = gpiochip_get_data(gc); - unsigned int i, idx, shift; - u8 bank, bankmask; + unsigned int offset; + unsigned long bankmask; + const unsigned int ngpio = chip->registers * 8; + size_t bank; + unsigned int bitmask; mutex_lock(&chip->lock); - for (i = 0, bank = chip->registers - 1; i < chip->registers; - i++, bank--) { - idx = i / sizeof(*mask); - shift = i % sizeof(*mask) * BITS_PER_BYTE; - bankmask = mask[idx] >> shift; - if (!bankmask) - continue; + for_each_set_clump8(offset, bankmask, mask, ngpio) { + bank = (chip->registers - 1) - (offset / 8); + bitmask = bitmap_get_value8(bits, ngpio, offset) & bankmask; chip->buffer[bank] &= ~bankmask; - chip->buffer[bank] |= bankmask & (bits[idx] >> shift); + chip->buffer[bank] |= bitmask; } __gen_74x164_write_config(chip); mutex_unlock(&chip->lock);