From patchwork Mon Mar 25 06:22:23 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: 10867965 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 8C1FD13B5 for ; Mon, 25 Mar 2019 06:21:55 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 722B0291F6 for ; Mon, 25 Mar 2019 06:21:55 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 6FF7E291FB; Mon, 25 Mar 2019 06:21:55 +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=unavailable 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 E197F291F6 for ; Mon, 25 Mar 2019 06:21:54 +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=PYuv7+y3DQ3wgYZLBa/YTei7Be9SR7HMvSa1NOTh6f8=; b=e8oGfZsQYhSsU2 BkbabxDE0f8VaMqry/GSymgamQwzlO/Hvqb/fX7Kacu0mfjKCq0ufJ2pw4n908aea1prWkF35HNMg lGNMOL+CCfENQsGaxmLZ8Qv6JnIcXLg+gBJscbMi9a6xmOFXkanBQr3aDT3sEJIJN4y/5Un6oiA4w Hb1vVHnNucPlYW9nueE7yiqew6AywocMvLz4srZwUV5NxZbSUNquHhxmEKneaiQSC6SRNNTZUOYf0 4BgUEc7GV4D4suN5Mgdk/7HXvLOdgAYiHGmnXsFOriC2YXeGCvWN2LbRfKFALifWFN6taf8/xaOf6 fyRP4nKGr4Lp0KyMg3dQ==; 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 1h8IzR-0005SK-G8; Mon, 25 Mar 2019 06:21:45 +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 1h8IzJ-0005Qv-4J for linux-arm-kernel@lists.infradead.org; Mon, 25 Mar 2019 06:21:43 +0000 Received: by mail-pg1-x542.google.com with SMTP id g8so5766900pgf.2 for ; Sun, 24 Mar 2019 23:21:37 -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=aV6ymFQx+nOtCqgpruu20OLoQlbPHl6p+VcsTxWKcH8=; b=l+3QIjV+3MgIWEYuBy5dV0/rTPiVcvZxtqATTNnNp7aHeyRqSVs9aM4UCcA4jOvKjW NzWylOestU1bIWWrWyLFjHc8q2eZ8j+nQmQ6PH3Y1XealDaKuyQApB3EHr28F8U6XarU Tx/TKLSVJtayTWvIFYyeIuqKDdfdZ7tVC43zCq/wwelQuZjsTs9KohcRCVLUGLSIsSgo Q4lkIvJbtVcZ0UTbc7h26eK1sGJMP+Ho6HYlWiNJVrdHhXvoCt1WWuvM3gbj+lkT/KG+ EETcV4nRiJWT47zKRtrMC5fSBZ8D+cXCMz329ig7L15kqbszQy+e4VhkTHLNSTO/oPr4 P+EA== 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=aV6ymFQx+nOtCqgpruu20OLoQlbPHl6p+VcsTxWKcH8=; b=RXFByywIblmUAdOwvuL//CVx0nx+cdRVyPkhK5PiQZvh5BIZVLrvgLJaGb+OC0tacv SS5ENPJQtRzcLE+M8Pmr+zwQ/ehDuF/zWANMKLaznSrDy5LLMkg4DeJbjo46Cev9JFfL ZShzlul69fzmQ0uFCDQZ9kM2P4gZBNXBMPuCDdsvkjctqIrytM/A56GeQ8gVBsRyxhU3 7YAyu+k2pVD1u8ngRZm0FQXMUnY6cgNLBgBGGBB8nzn58/LFTKOmIhWm13/XBiidlzJy FxkwF15V+oYXPaUa0WG8rDHg2waVtE8kFRcK+EEy7KYBnJ1w7T5rbFyGkAYoggCz0vfE 3eSg== X-Gm-Message-State: APjAAAWAXt1yYZtB5rd/ElRfxNOzqKEv6kwW3tqKHfuIhS6rYQ1F7A+l uqZrUKJPkRpt0W/rsXVmcRc= X-Google-Smtp-Source: APXvYqyGFRJcNXz8zrAtlQoSN+BKG5OunI07yjZBglN4A6mnndvUfGJ0CpDCPXWNYLBvZyY0bat1tw== X-Received: by 2002:a17:902:2ac3:: with SMTP id j61mr23358166plb.112.1553494894741; Sun, 24 Mar 2019 23:21:34 -0700 (PDT) Received: from localhost.localdomain ([2001:268:c0a5:e068:c70:4af9:86e2:2]) by smtp.gmail.com with ESMTPSA id k17sm18916699pfk.166.2019.03.24.23.21.28 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Sun, 24 Mar 2019 23:21:34 -0700 (PDT) From: William Breathitt Gray To: linus.walleij@linaro.org, bgolaszewski@baylibre.com Subject: [PATCH v12 01/11] bitops: Introduce the for_each_set_clump8 macro Date: Mon, 25 Mar 2019 15:22:23 +0900 Message-Id: <9afc30a574ce3e6a86b51dd522146a1d2156dedd.1553494625.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-20190324_232137_172228_49D726F0 X-CRM114-Status: GOOD ( 15.05 ) 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, preid@electromag.com.au, Arnd Bergmann , yamada.masahiro@socionext.com, linux-pm@vger.kernel.org, linux@rasmusvillemoes.dk, linux-kernel@vger.kernel.org, William Breathitt Gray , linux-gpio@vger.kernel.org, Andy Shevchenko , geert@linux-m68k.org, 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 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..1b6f8a6f1957 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(low_width - 1, 0) << 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:23: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: 10867969 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 8DAA214DE for ; Mon, 25 Mar 2019 06:22:32 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 763C7290E3 for ; Mon, 25 Mar 2019 06:22:32 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 688B0291EF; Mon, 25 Mar 2019 06:22:32 +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=unavailable 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 C853F291FD for ; Mon, 25 Mar 2019 06:22:31 +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=NGjO61jJ+ZtHjMj7PjKydAZFMhP3fiH/iEzwOEbSN9s=; b=QPVnC7N4EOv7Yn QlncJFiwVNpRwP5cmfK7BnwPF92ByqY0IeHQfsFyivgAbOs23lzJqAJGFTY3Sa1MJLGfAqrmr/377 hle4iAP8SS77xq1XW3D2KuMicS5FIOPSAPde3+XPv8GAwo0d/U7vkkr2GW383d/RWGtvFQxKjZi0o l25ZeE1rbACv9ftzG7tM5V6htWg/XpUXuns3VoB/RZF6QTDEQCF6vzX3KuONVxyQQ3VL1VuU2chY/ JT3h8KOIhK4NDFvnJUuIMRwJTdpSCbTJ+aF9WeFYflRFbP5AG60i2DyzRjlpC+tmggy2BMO6HYs1R SGzdOe8zRNP4ZPAM0X2g==; 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 1h8J01-0005os-Qu; Mon, 25 Mar 2019 06:22:21 +0000 Received: from mail-pf1-x442.google.com ([2607:f8b0:4864:20::442]) by bombadil.infradead.org with esmtps (Exim 4.90_1 #2 (Red Hat Linux)) id 1h8Izw-0005ne-TX for linux-arm-kernel@lists.infradead.org; Mon, 25 Mar 2019 06:22:19 +0000 Received: by mail-pf1-x442.google.com with SMTP id p10so5643217pff.3 for ; Sun, 24 Mar 2019 23:22:16 -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=voPjJIpaEIENDSX5D22rQL6GtMzeJ5e93HyvmN9lrck=; b=vNwjGWjxEhWt5QWVZT1aFeY5G/+y9WIguBjBa2SkkKwSXWEuCI07PAqcaqZb0sF25s buN8M1Jb2P6GxF6WJf1IkuNvhq9V02P/pJEjJiAnKoP64vdQvQvoHHtU8umEVTUnxKmH BL+pOi54Lt0LIr+mqRYTTXR4kYTwZpv6ZN+F3KD1voDmGVP4oik3vOy8+Gonu1PVujYd wv7nBAnjoI02zxKlqAaZtyI8iNbxixjEf5kl87+Un2p934VWkvLjB9vt2iNYnXCRnBYw WjkcyTFdyfp3zVsLCePywJm6ZkjrtM+ieR1KGeDhqMnPfHdi407juihqBajN6I5DjJsa uGPw== 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=voPjJIpaEIENDSX5D22rQL6GtMzeJ5e93HyvmN9lrck=; b=XInFHcX9Z8xeQagAZHFUXZmxkT78vewO2BSXrDEzw3pWT22a4JBUVwuI2MHWR+ntLr tbPBWSGE/8e3/8DwG9GvBJ+Yw0/LvMlN0omY7EGnXZOtZkdDBkz48OnqzULQSNWtizYz 567gYFXIyf87YSGW0NLZ9YxKjflCavtx80S/6rzoj8FR+MwLegt264el6be7kIyQiTT5 IyAnBy3/2PnRtAOVR0hK2zNY68/yJzg43bNKJD4XYRtnqMcs3DRkRa7Z8/UYB4ti4yhh GrBNePlpcIQtNDEA03uGRwdqnZwv38wl4QdTxvwAOtWenPyE978C+ZoIa3NaR5iSyEwP +Y7g== X-Gm-Message-State: APjAAAXE8uyOpGYa/W5rjeA7llwvrY81c/rypoqTs+kfEwPXIRZ0Gj+a Rn8KyucCvC9wgMj2gXs1UDI= X-Google-Smtp-Source: APXvYqxJGgyonBs5GOQpLl8fBNPRPEvQA1Y95A/k3Oi3can/YVX5PkR0Bm+H7W3GHNPK00LXk20wUw== X-Received: by 2002:a65:614f:: with SMTP id o15mr21578292pgv.383.1553494935117; Sun, 24 Mar 2019 23:22:15 -0700 (PDT) Received: from localhost.localdomain ([2001:268:c0a5:e068:c70:4af9:86e2:2]) by smtp.gmail.com with ESMTPSA id h126sm33590899pfc.135.2019.03.24.23.22.08 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Sun, 24 Mar 2019 23:22:14 -0700 (PDT) From: William Breathitt Gray To: linus.walleij@linaro.org, bgolaszewski@baylibre.com Subject: [PATCH v12 02/11] lib/test_bitmap.c: Add for_each_set_clump8 test cases Date: Mon, 25 Mar 2019 15:23:03 +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-20190324_232216_952333_692C4CE8 X-CRM114-Status: GOOD ( 13.79 ) 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, preid@electromag.com.au, yamada.masahiro@socionext.com, linux-pm@vger.kernel.org, linux@rasmusvillemoes.dk, linux-kernel@vger.kernel.org, William Breathitt Gray , linux-gpio@vger.kernel.org, Andy Shevchenko , geert@linux-m68k.org, 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: Rasmus Villemoes Acked-by: Andrew Morton 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..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:23:29 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: 10867973 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 D187C14DE for ; Mon, 25 Mar 2019 06:22:47 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id BF2CB291DF for ; Mon, 25 Mar 2019 06:22:47 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id BD05229202; Mon, 25 Mar 2019 06:22:47 +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=unavailable 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 4E77B291DF for ; Mon, 25 Mar 2019 06:22:47 +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=KziDbtjSke2jUk MtVUzyyG11VAsgDEhWQEQBiV6nwYY9eL0QJy8XzB6Cu7vd1PyEtQEkRyUQ72Vn2vYXMbYJUkGSOVU d3ItMo4CzwnoA6Q2DhmHyQGprRx4Gf+RM3d0744TJl0Q9t7UjXvVcsFoRU3sSkNjYylGAvTNoXHj7 W2urkyQ2KQ9A0MS5cPocmJXGnZyAULwoUmIREPAz7g+2kCJrRmvvRQga5eSirOBWlkvhjhBvqnGK5 vKKVCM3Td8uCQws6VPOzyTiE2BbYWTYwFrIg7AmIxq4SB1P1AA6PXwtshrs1J/kXnNBIIoSJs9+PB E1ye3M60fgxj9utwezZA==; 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 1h8J0I-00063W-PL; Mon, 25 Mar 2019 06:22:38 +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 1h8J0E-00061W-VQ for linux-arm-kernel@lists.infradead.org; Mon, 25 Mar 2019 06:22:36 +0000 Received: by mail-pf1-x443.google.com with SMTP id i17so5639061pfo.6 for ; Sun, 24 Mar 2019 23:22:34 -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=Zglu8jGHEy3GA3bBX2ID5Z5+aj9jPW93UCrZnEZr80ipTSVj09kgE0gCfJjAMkebUN 3QLRpLZWAqOPVJxiZOhUro3UcCiDCnM9rK0ZGARnAn1fl0dHn+Dmuf/4FGI2RZOkaXwu 53G1hbrzFgxUADJGLZam9g9XV34IWutqifSYBwO97tp3aXXQN0bq6FgIuNA+FDYHMH7F 4fh8mnMObW8jEGEQ48CshI5R0RmnCeQWvxqg3LpIRGWClvHXFpUhy+3rmy8++tK74YcQ tdpo6qzBydG/7O6gSLL+BobSesH7KWfD5M4j48PScK/5BMkczHIVq4i6tIWpu3ffY8y7 eyfQ== 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=DXCbd8sO9cTHGsbxjd7EUIj1jRDUyPyIQwm19N3pTQs0yDfEBUxMjFrDVnjwBXENjc x0GDMU8wxLlS3V39KBqvCC7LSocMSX9N92k/Q1AL+MY15psfjLk4dKSCcQ/aLgCT8pB8 f8T0v46n/mMtLrj+tS6uTkpEHJ66+auu74jt1CaK2kADems4FMVd+SK280D28JOIGQua cFHPXj7jEyBma6wEfCeZilqPuwiZPIOfhde5qZzzmKZGV77aTtV8hEQhIK7HdnmwRVC9 TfsaXp2ezXLy1GqvO+2HVvFGRgO1dqfxXv3c2SZs6z2V5euui/HRPK4HVwiKwBWRZw/A ps0g== X-Gm-Message-State: APjAAAXrPv3DciaKCbYGzknpLpC0q+7+dJ5NA8a3bzxrSezDpJB/Tu5x lbBRAGtd6ZCTxhPmg3BSAlo= X-Google-Smtp-Source: APXvYqy5ZPmKCt18bnXr3VI5tH6MBgbDi/N0m0Yixk4KZ5ULReBjUYdf0Oe/cwGgawipSQySsrz3Pw== X-Received: by 2002:a63:e303:: with SMTP id f3mr21619616pgh.374.1553494953687; Sun, 24 Mar 2019 23:22:33 -0700 (PDT) Received: from localhost.localdomain ([2001:268:c0a5:e068:c70:4af9:86e2:2]) by smtp.gmail.com with ESMTPSA id d69sm7529414pfg.26.2019.03.24.23.22.29 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Sun, 24 Mar 2019 23:22:33 -0700 (PDT) From: William Breathitt Gray To: linus.walleij@linaro.org, bgolaszewski@baylibre.com Subject: [PATCH v12 03/11] gpio: 104-dio-48e: Utilize for_each_set_clump8 macro Date: Mon, 25 Mar 2019 15:23:29 +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-20190324_232235_064538_42E46BB8 X-CRM114-Status: GOOD ( 14.48 ) 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, preid@electromag.com.au, yamada.masahiro@socionext.com, linux-pm@vger.kernel.org, linux@rasmusvillemoes.dk, linux-kernel@vger.kernel.org, William Breathitt Gray , linux-gpio@vger.kernel.org, geert@linux-m68k.org, 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 Mon Mar 25 06:23: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: 10867979 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 A3FF414DE for ; Mon, 25 Mar 2019 06:23:17 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 944B3291E3 for ; Mon, 25 Mar 2019 06:23:17 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 922A729202; Mon, 25 Mar 2019 06:23:17 +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=unavailable 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 3420A291E3 for ; Mon, 25 Mar 2019 06:23:17 +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=NmALFjIa2ac//E kC9G6mP1p4MxWUe6KC+YsLCtL9Wab3l1IbQg3O97Qw/WqqfwhzcNY8hk4sE118jKJJ0Vj/OIrSaFX RaeIVqeA2IOeaPPXtnHhABcxjLLm3RZAJhLMeaZNcSAfsIyaLO5HbcioUc9FcqqdCuNnOdwKXaE+/ DCMBi/rpQPaICH3EW27yDSHnYBlbgYwOGK5UuW6RGFiY/gN4R0/02Ar0Qwg/mLSQunnaA0bCGS1fB X6SZy4C3cdVmSBN2EMYhKfON0/ivHo0jm3n5kPnc/C+R9TOhGQrfYKO/Rl38ZipfnlsbKFbSa8yNG T5bvh/3XXYuqkG+HN1Yg==; 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 1h8J0h-0006Li-2h; Mon, 25 Mar 2019 06:23:03 +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 1h8J0W-0006Hj-Ux for linux-arm-kernel@lists.infradead.org; Mon, 25 Mar 2019 06:23:00 +0000 Received: by mail-pg1-x543.google.com with SMTP id a22so5723386pgg.13 for ; Sun, 24 Mar 2019 23:22:52 -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=k8bfgdC35YuzrdwsSZ5zBZxonj7tKQjAvBUnLY2G4c8ouxJD6tExysVXc6o5BBagd/ Khu6FvIiiyiyUsC3nknsLh1+Q+eiOzMiYH9hwsoWkAeIFU8RJWy5G0wysmfJnstvHaqQ 05rAE2kU3QlP15HFXZLPcfii+diLOtsVTTizIno/D7tC72ofXmMKMnLkGkHjmRSwyZ9p 2OMDeCGUPfUWVkksAcAbKlJAfmoAPMvQSE6rJZgB5Da0L3Kzt0uBVfI+pLpjIYyLzb4P ypFLghvE5G0lR93kxTq1y5oLey6CQzl3EkK9W4/F4gkS/xs5GZRjprjJ9PSIkmFXW9FC pN1A== 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=SY3sb7vEHXmI56WX3TLlAEf9BpuIs5rrEj0YUH6k1m1d+swSWrfdvetxFhWvkAbgi6 8ZB2SMm/9bP200rAdbljnyOBPpivLpQmRDbPIpdZ2wpfWil4ho2jQRQY/HRrTXldBApm lIneBgTGy7bSLyFaABTSszn66VD591x+jIFuJqZnsTUUM7DjfxaTthzcKvB33IvEy+Y2 au48OOqcTHj099vJprBzbvLBb+s8Wn54IDDSodBTu3XmLnz1xSInGe2NJMU/6uQQeVNN Hoze7s7sjQKsHZWvo7LXXN8GJ3bLmhgDTTo2PWWAXkd0U1mZ23liJxHlVyohEnimWD+f b7tQ== X-Gm-Message-State: APjAAAWxAAJ4m/ESjbaCm0sKdI+/LBHVTQoCA4zhDJQn8+bSf/p/R+IV /qT8cc07FMxwcumI/54RnvA= X-Google-Smtp-Source: APXvYqwO1uw8Gsq1gIvv4tV3BZ28qRzs7qbFCmIfifMlhXyJO9IqvrfTljiqn4sirx/Rrm8jdPoF2w== X-Received: by 2002:a65:6645:: with SMTP id z5mr22214836pgv.251.1553494972350; Sun, 24 Mar 2019 23:22:52 -0700 (PDT) Received: from localhost.localdomain ([2001:268:c0a5:e068:c70:4af9:86e2:2]) by smtp.gmail.com with ESMTPSA id 15sm19598988pfy.148.2019.03.24.23.22.46 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Sun, 24 Mar 2019 23:22:51 -0700 (PDT) From: William Breathitt Gray To: linus.walleij@linaro.org, bgolaszewski@baylibre.com Subject: [PATCH v12 04/11] gpio: 104-idi-48: Utilize for_each_set_clump8 macro Date: Mon, 25 Mar 2019 15:23:47 +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-20190324_232252_997721_DE74C083 X-CRM114-Status: GOOD ( 14.01 ) 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, preid@electromag.com.au, yamada.masahiro@socionext.com, linux-pm@vger.kernel.org, linux@rasmusvillemoes.dk, linux-kernel@vger.kernel.org, William Breathitt Gray , linux-gpio@vger.kernel.org, geert@linux-m68k.org, 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 Mon Mar 25 06:24:06 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: 10867981 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 84B6B13B5 for ; Mon, 25 Mar 2019 06:23:30 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 75274291FF for ; Mon, 25 Mar 2019 06:23:30 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 735B729200; Mon, 25 Mar 2019 06:23:30 +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=unavailable 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 0CA1129206 for ; Mon, 25 Mar 2019 06:23:29 +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=q3+EBqgZFw77/+ SdTEoJOkKEmAYLkfGMLea9NCqiDM4xkgSxEXDYncLNmW4CneLSUd4wjh42cNA3u0MhfE1My5SkNHi 67TTKJ5lq9QeLUNl1gp0a1ARMJXKL25QJatRGgR7ZaCEgiKRcQuF5wQsH2SSIRuxSIe5HkqEWXLSE EL7hS0/q1244scEqzFrwAY3EcmHqJQ/wbyqJub2SGaIjb4WRt8od/+BFjikYiq4iGYXFg3TLQNqzY VZC5fYBzOEiDIWygB9BARmCPylAe7s2Htz1XILpJkvPc31erwGew3XGIHQLc/T6NZkRbjsmmIrYTN jIq5vLSXoyM1fHc8aj5A==; 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 1h8J0y-0006fN-NJ; Mon, 25 Mar 2019 06:23:20 +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 1h8J0s-0006bS-Cz for linux-arm-kernel@lists.infradead.org; Mon, 25 Mar 2019 06:23:19 +0000 Received: by mail-pf1-x443.google.com with SMTP id e24so4774825pfi.12 for ; Sun, 24 Mar 2019 23:23:14 -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=IGDM1WXrWs00QprYpjPDFyUpmB34OuNPGF2aow50mUHQq6jonCNZIpq6ezMWAkOPLP zMSuapjbXeiBcey6Mr8Vp4Ltn22LVSceVltgjtgqurQ3kb/xMCVvl+NtpS41dOjVNOAF lXG6lOVi0EWO1BdzsTYnk391w8ZwnQIQXz1R8DFisoUVCgPgIN09WiMl6C/mxcEWkUYY nUt7gu660HsIZvvGOZeFwYXOJmu25cKXQMFt5Xsen2mKRYsvVmAbjS2Dshd4o1F6M7Jz meKz1GOLXkCbenDZI5tzwiAYiVw/E9gDxxy3LToKMPjHkzVlXtHa01jZFnsWNTM847al ofoQ== 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=F8elXlSLDjjaFBCtgII0h4tJ1l2LZUu5WNJRQ9Z2XcBOL2syvd/tXKJV8G4sGHXR6J mHhBpI8n6XFOES2TbdNj16JeAcnuppk2RZR3az0v2E/WbG6/r/FE2dnJsJ/Bg47HmVFv Lvhezd8YvnD4N/RLCH43/PtGAor52unz+s7NIqkQLHy59truJD3p8o7Z1svVw68qD3aR XOkegQpp2cjUs5ru4Tmh+hzZwPFCGU/GwQZmAEtAlWs/jeVw1ZbIklHM0KSS1O0JhMVg j+SvOenCK6pBGwzgKESZpPuh9nauV7Q1xaQx37xG8yrZdIMLYtLs5XV6Eg8MD7a6drO1 nsNg== X-Gm-Message-State: APjAAAXrPotEes0OgYZlzcC234Twoy5Lw+3IsFpPuzkMY77BNFBwYC+z 5RICcSwXWarO6mXGlFPEkI4= X-Google-Smtp-Source: APXvYqyGTv/AJ8DiPXhGlVppglbyoTzXzesGeimDseTZmlJMyXSAFB03SgdphPnP5REhFTE3gqIsmg== X-Received: by 2002:a17:902:8609:: with SMTP id f9mr23721645plo.85.1553494991874; Sun, 24 Mar 2019 23:23:11 -0700 (PDT) Received: from localhost.localdomain ([2001:268:c0a5:e068:c70:4af9:86e2:2]) by smtp.gmail.com with ESMTPSA id l80sm5413802pfb.60.2019.03.24.23.23.05 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Sun, 24 Mar 2019 23:23:11 -0700 (PDT) From: William Breathitt Gray To: linus.walleij@linaro.org, bgolaszewski@baylibre.com Subject: [PATCH v12 05/11] gpio: gpio-mm: Utilize for_each_set_clump8 macro Date: Mon, 25 Mar 2019 15:24:06 +0900 Message-Id: <49eb64a1bf665dd0dbdd1ba4ba25d8fdb4ff8000.1553494625.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-20190324_232314_463586_5552FA51 X-CRM114-Status: GOOD ( 14.48 ) 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, preid@electromag.com.au, yamada.masahiro@socionext.com, linux-pm@vger.kernel.org, linux@rasmusvillemoes.dk, linux-kernel@vger.kernel.org, William Breathitt Gray , linux-gpio@vger.kernel.org, geert@linux-m68k.org, 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 Mon Mar 25 06:24: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: 10867985 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 660EF17EE for ; Mon, 25 Mar 2019 06:23:49 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 55B46291E3 for ; Mon, 25 Mar 2019 06:23:49 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 54050291E5; Mon, 25 Mar 2019 06:23: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=unavailable 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 E2ADC291D9 for ; Mon, 25 Mar 2019 06:23: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=aFOyVg51VmvjMddDtCmCNUdEzDTDp6zBLLKchh5tJDo=; b=eiIxLY9i5yvYFk aUDyRVq3tgUaa82P/65ZB+sSPx+ZRXJjGDQc+EWu6fkc383icuornbJAE9kIYHU8mYz9AqGV7Qd5f PmfYSzCpc4lu2m5jbXCgKieYzh44bUwnBVP413in6hWGp9dKJJbQqHpp3ZOG3a6DoK1t5mexFyXGc sFC+jAW1STYdnY2GK++RZI9PslEH8eFYZa/O13aQmGAdOMdA6yvnp3D1JbyrsNbw6IHlsJbec1iy+ 8s1hoCDNCdt3Ee0/4fvAG0T//ZwQGCQ/bcla21ITBLe3pMvPaoGSA1BgFN2Y885wIRhRDQ5byZjKb x5qP/LQZFJVk+huwMuMQ==; 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 1h8J1L-00071g-LX; Mon, 25 Mar 2019 06:23:43 +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 1h8J1C-0006u0-9T for linux-arm-kernel@lists.infradead.org; Mon, 25 Mar 2019 06:23:42 +0000 Received: by mail-pg1-x544.google.com with SMTP id i2so5738341pgj.11 for ; Sun, 24 Mar 2019 23:23: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=JhQ28KZcd91XNKjTCGWYQ1G7G3aiOZwynfHwUrGcvPU=; b=YGpcw2JrZ0sKDXYTV5QNEKZGFKKMsoVXiRvDebD/T7CZKy1ifVY7UTisBcBYGvhRfO nDR9bAY1Yrcen0HU9nTcgrHi5mjqv3+Rn6lzLIE71xzf6q9s/wd8ikPvSgo2csXgWNV1 8jdv9Em+DZBuQkr1FZrdWkRQWS9cEkiSQgF+XLnrE5R4Wu/gEgoQ2n7LdS136Ig7O/Do JUtKe4+j8R0YOrL/PPOV6SBywmJTS/v2W/rIXxk+HQopfTPcAEfNfglpT27uBqbTXKgl wX4/RlRyqGC/A2KA/3G3yrqfM+WwqvMFsY3pFLtzFuN5tHvFcGvRWmTJb28T68ztZWCI FFTw== 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=PX4S/SMGsVmzvCTs0TwTVf9iuwz7GlwPUKPIi8CRzNA7q3uvSk5S4577I43p89DD6H SX/XKGu7+/nA/dtphfzMSaxpQAzOr8MXKjsmVw0HW9gP9V1Pu8iBbjBtrCTlpkyJgYpp olsEj7tXq6AUBkL70mKq/j/EsDKZ+/KCGK6JlGNICCongDj6R+5jlrqjN+rsSV2JU1Pn 7NScFrcBgyLDKAm/oYghDKmnxamEqMqaXsDS7Xqr5p1wFX3r7/ypAkpo/MG88Qeu4DV4 mV/sxprZIy3cFqTc5o4l7zSw0McnGphcax1bujbcF1su1czu35rH0XD+47CFntGO8ZgK CAVw== X-Gm-Message-State: APjAAAXKaRMxt8KBnINuYy+RO2reuS1mQjRcj4m06Hxo/uBA9D/fPWH2 EnDNaUHRzkFwVgpN4PT5Y94= X-Google-Smtp-Source: APXvYqyh/9g5QxK2rXaIAR3R5RDkD+c/VnBzHibFTsLMDXEH7a8F1owpawcpemfjCbBtlcr4Cf1fUA== X-Received: by 2002:a62:168a:: with SMTP id 132mr22155046pfw.155.1553495012833; Sun, 24 Mar 2019 23:23:32 -0700 (PDT) Received: from localhost.localdomain ([2001:268:c0a5:e068:c70:4af9:86e2:2]) by smtp.gmail.com with ESMTPSA id s5sm21795975pfm.184.2019.03.24.23.23.25 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Sun, 24 Mar 2019 23:23:32 -0700 (PDT) From: William Breathitt Gray To: linus.walleij@linaro.org, bgolaszewski@baylibre.com Subject: [PATCH v12 06/11] gpio: ws16c48: Utilize for_each_set_clump8 macro Date: Mon, 25 Mar 2019 15:24: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-20190324_232334_332728_31EAD400 X-CRM114-Status: GOOD ( 14.75 ) 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, preid@electromag.com.au, yamada.masahiro@socionext.com, linux-pm@vger.kernel.org, linux@rasmusvillemoes.dk, linux-kernel@vger.kernel.org, William Breathitt Gray , linux-gpio@vger.kernel.org, geert@linux-m68k.org, 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 Mon Mar 25 06:24: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: 10867989 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 1909C14DE for ; Mon, 25 Mar 2019 06:24:23 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 08262290B8 for ; Mon, 25 Mar 2019 06:24:23 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id EFD3A290DA; Mon, 25 Mar 2019 06:24:22 +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=unavailable 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 B5E432905F for ; Mon, 25 Mar 2019 06:24:21 +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=nA47Xss3joDihM cKglYK64v+k5MtyQR5crkh6xbdojzMTTvNGV2MVRlJTF72gwzkYhbiNOX77DcgkGBAacK+QFfzxTA 8sSWM1wlDdwrd2Z9ybE2rOHJpf793pZJK3EmNYL13m1NdhIb/31GuYSX9TzKHa3lqjTfXsNm6aUwR AeJBbx3n+KgqV4clVlICA4o4SOdfbrwtHPWRDBHeqlJkQ05qslUTktuCCELJ012MmYMSBas5MJ9Ku b5Hwc4qYpQQiypKeqG199aXsxkFkblUG2vYjdJR7eRPDVDCP2syenPb9M7LbrARlvqqI9NEbQ0Y+D yc8VVX65IZOdju0xD5vQ==; 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 1h8J1n-0007J3-2p; Mon, 25 Mar 2019 06:24:11 +0000 Received: from mail-pf1-x444.google.com ([2607:f8b0:4864:20::444]) by bombadil.infradead.org with esmtps (Exim 4.90_1 #2 (Red Hat Linux)) id 1h8J1j-0007I8-KO for linux-arm-kernel@lists.infradead.org; Mon, 25 Mar 2019 06:24:09 +0000 Received: by mail-pf1-x444.google.com with SMTP id 10so5639698pfo.5 for ; Sun, 24 Mar 2019 23:24:07 -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=Qwjx//4iQrJ3rvc7sBULilZKlCQxpv/EQlZE4eWnag8Z45GLH6tiJIkYOw5kDj+hfz sOw2QjfV2Pnjk8E7RofEw43zsbTaP9rxWuBl14Za2XtCCpTNmLOpOHqtrBQQ5V4QdXKV MTxy7bOnZx+EjjGIg+y0Z1EFjnspFjeWufVoe5VUGL//EXVX8X8jQ/5KwF0mLNNOVo+T x+pDHFRV+8jvcuyuk/l7npv2Zw16HvqGMNe71gpXLbg3+4AbDORp+5CDiDaFjx57i+PK DFUocaWL1et856OaAnRKz8k9mmRMY3z1d6MKn0R++OwmrVl3dIKsCKVTTysQBkWHWa3R RcQg== 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=RR+3IfVikKfDmRhLyuLKkmfVNSTeAEulw3g/4rnklW8CnbdS2907lY20tw+0PgqFFf 6MwEYv13AjuiXSH7FOTSjXfNnbW9VI2jR0+e45zMQGSPfb5hONtAlm9OURfBdZ2FVtr8 JzVfk5AW7R/OWkVmoEpQ3YuigwKldccJYvuTDvY3WeNolOETL26Pb4bvIPV3F2vvkyI0 z1MOvDYOf5e1FjrTFENLlv1ISGDZfhZDs2oUXSDdMVEXn/tpCUZf+hm3gkrmyrwasuhE D5dPXRLXh17za8j6GqE7d+oZAFZ5ZD0Kt+VsYU9wh2vtVCBAJSnZB3EfbyQCbhcRDnfw wD8Q== X-Gm-Message-State: APjAAAW/8SCAkza5zi4m8UoUnYv/KSokWH1S4XSN6Mp0SN9kgahYZ6yG YKaCiJDRn3rbbjyT7x5nJvA= X-Google-Smtp-Source: APXvYqzIs0UpnYio1il82B0al5vdTE3wJQOR+TTLqL25xR3GAwu/rtcxsLRiQVwIfA30qONhLJkdMg== X-Received: by 2002:a62:a515:: with SMTP id v21mr15001300pfm.41.1553495046909; Sun, 24 Mar 2019 23:24:06 -0700 (PDT) Received: from localhost.localdomain ([2001:268:c0a5:e068:c70:4af9:86e2:2]) by smtp.gmail.com with ESMTPSA id h87sm28266989pfj.20.2019.03.24.23.24.02 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Sun, 24 Mar 2019 23:24:06 -0700 (PDT) From: William Breathitt Gray To: linus.walleij@linaro.org, bgolaszewski@baylibre.com Subject: [PATCH v12 07/11] gpio: pci-idio-16: Utilize for_each_set_clump8 macro Date: Mon, 25 Mar 2019 15:24:47 +0900 Message-Id: <0cf302707a78db8cad9e308ca883442583cae3bd.1553494625.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-20190324_232407_667410_9BB5E568 X-CRM114-Status: GOOD ( 15.01 ) 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, preid@electromag.com.au, yamada.masahiro@socionext.com, linux-pm@vger.kernel.org, linux@rasmusvillemoes.dk, linux-kernel@vger.kernel.org, William Breathitt Gray , linux-gpio@vger.kernel.org, geert@linux-m68k.org, 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 Mon Mar 25 06:25:22 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: 10867993 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 7BDD813B5 for ; Mon, 25 Mar 2019 06:24:43 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 6B93429049 for ; Mon, 25 Mar 2019 06:24:43 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 699F4291DF; Mon, 25 Mar 2019 06:24: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=-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=unavailable 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 ED0E929049 for ; Mon, 25 Mar 2019 06:24:42 +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=Zf5B1YjqDR6aI7 QcotJ75uGfhoh4ecKPOYNYGfC87420Voc+8Tyvyay2T2+zgsJTUkDOH9Cv74SLpREwUUu27tCT6Dg 4rb/NYXK+aB5GgSvYGFzNoLvXoo+F57+K9JgkcVtXsKbxtI4TjCm7/TrIGGgnTDy4lPQcDl7jrE8R ewIpgdqACNnnoCzMVdyloXwzANunSYqDBvnT93l/qgjkhzAWJHDhdSlZ/2EC1YJ3gpuVwnM1ntOhj HPwP0OXX23F2+qVUxinYONDnpIHXH6ss+lafT5CUKz5D42xw9t1sXIkHJDbY3H+/IWWPd8EySLZhi 0lCq+8LCO3knfb6tt66Q==; 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 1h8J28-0007aQ-Ge; Mon, 25 Mar 2019 06:24:32 +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 1h8J24-0007Yq-64 for linux-arm-kernel@lists.infradead.org; Mon, 25 Mar 2019 06:24:31 +0000 Received: by mail-pg1-x543.google.com with SMTP id i2so5740008pgj.11 for ; Sun, 24 Mar 2019 23:24:27 -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=Kf2q0kOf3jDuYOqZ2HdDbras2I8Gdg3L3X3+enOFu39j1vrFi3QFyZzWzlQxbJeySx A95P6ihz+hGY9n84Lx99Zui99Xg1Bha3sq/c5Eft/XwOI698ClzA7ueeqPe2FirIVHUp 6f/IW+80bumuBuYsPxK09nP13pTyhbjX8sgjU18UqkSP8b/EXqouNHSK83xKISXSWBuP /fvbPi+xt4MiLNhzV1lHQITepzgOZEPAvFpJ0pH8kVp5iV/BWijgcNgNj7HhqeC0NbJW r6T7ovxfG4hlUbf3UEZ4W+qvoGbuSxrUXoiODIJWFip09WdcJYWaw0Qbn5dRgcLA13Kn wJcQ== 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=tk3DLjRiMYx8jr0McSucxBaSyDwL4lMkqs1Ku3HE/0/FdzvKxTcL1d4VrMyIvMVM3H 19Br2aSvXUET3J0cy/lkSglypLdpB2h71paAmbAltKqbn6o+99yj3XTKCc8aZaPAnirn b8m4NWkP8JsbSSwAe9eEtR8v9245eE0NrXv14/gIuDtNy2yM+iu/qBZfsQF+5oV5icX8 fTeyxMTRAU1nDIJbkD6nmOtx+9jHCsrf0rskjg9Wuhh9yRAqMynKvXycxyWW6wAsFDSp 9FuKd15M3SGxnA2w0gs0wKt9v0XaJZpTMpzaOtRor2BPtCQYbRqX+FH2QeVLWi4qNIb/ 0hTA== X-Gm-Message-State: APjAAAUtcW07mkIuCpFokQQlEVTDVwZlnE95+AeJN8E76O7fIrN/H3VC x3HwRLRwrHoDC3XLKgvaZNk= X-Google-Smtp-Source: APXvYqw3uP6LxLY8CpyAO9NWeLE1ZxzPvnGUhrQcJVKzWywfIRImSi8/5go3T0WE8TM8XIZYV+2yIA== X-Received: by 2002:a63:4750:: with SMTP id w16mr22197719pgk.256.1553495066164; Sun, 24 Mar 2019 23:24:26 -0700 (PDT) Received: from localhost.localdomain ([2001:268:c0a5:e068:c70:4af9:86e2:2]) by smtp.gmail.com with ESMTPSA id g6sm21853059pgq.54.2019.03.24.23.24.21 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Sun, 24 Mar 2019 23:24:25 -0700 (PDT) From: William Breathitt Gray To: linus.walleij@linaro.org, bgolaszewski@baylibre.com Subject: [PATCH v12 08/11] gpio: pcie-idio-24: Utilize for_each_set_clump8 macro Date: Mon, 25 Mar 2019 15:25:22 +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-20190324_232428_224650_B15F0251 X-CRM114-Status: GOOD ( 16.78 ) 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, preid@electromag.com.au, yamada.masahiro@socionext.com, linux-pm@vger.kernel.org, linux@rasmusvillemoes.dk, linux-kernel@vger.kernel.org, William Breathitt Gray , linux-gpio@vger.kernel.org, geert@linux-m68k.org, 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 Mon Mar 25 06:25:41 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: 10867997 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 5E39C14DE for ; Mon, 25 Mar 2019 06:24:59 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 4EE29291E3 for ; Mon, 25 Mar 2019 06:24:59 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 4CFEA291EE; Mon, 25 Mar 2019 06:24:59 +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 EAFC2291E3 for ; Mon, 25 Mar 2019 06:24:58 +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=Fz9842lPzqbk/S ShOwOFMJydJo3SnNtMeqChxzA7bIIrNvs1kwlnYktp3Fic429QaMPrnXx5aYcw2gsjlxrkfkq5PSm kaluMynnMNxN6Hgtd22RJOF+rUxqonnSmDejjF7ud15IodFpwNDhPv3Z1WS0QUWIVymrpIU3IRU/8 iPzNrTCUiauVj+usmWRrigN8sick5j6rldU20QNnA9YEiEIoUEZZ/Oqfefoca6bVnDlJ7EyVGrvHL ETdduqyhSbMxVX3efMY5NSvcFsjaZEKMtCAdvpt93MUa2dYXt9W4/TxQSjZ262vzkkMqCn3GmX07H gVKEamlZv20mrBn6MGiQ==; 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 1h8J2R-0007qr-8A; Mon, 25 Mar 2019 06:24:51 +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 1h8J2N-0007p8-6v for linux-arm-kernel@lists.infradead.org; Mon, 25 Mar 2019 06:24:49 +0000 Received: by mail-pg1-x543.google.com with SMTP id p6so5751497pgh.9 for ; Sun, 24 Mar 2019 23:24:46 -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=YjdEB03/bL1qKLf54ZWZ8Cx8OaY4qHeFXqQC7ahjJw8t+9gRJWPkqjZQmVg68+HOxl InLiArYk1FQUAaK5yZ15U+19TSrApltw0szFgOZp951dNfdKInl3WRNaODE9rwS9TPeI 2EVc4ci3AjiI57FtJI8zX/Ltxw+tSNMiuTDebpgwgiZkuct/tK42MzJoMqYSd5e6eh3Q nazprjUW2izeF4aU7CwO2Ql3NU0ltrjN940DzpNeLQsYfRqggxUKQaVRvDbw2JWdtiBC HYdljrEbZyvLJwOgg4kAHslQfgVr9fKAlgU51RG72WR+UL/pls6UnDcLZuTwHosZsyUJ wLUQ== 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=BHFOdGi03tLgnI3CAn4ga0cqbKy1EXll0c8Lx81byHdtildLpwv7nx8J0nzhz0bw8k EEfkYUe7XxCA3HHldnI6w65FBvGpjuu5bj3uBPfjQ/rdKe+QAXvXzuMzYC00HogeGm2Z QfEztFRLBqhhondKE/0qN7lVMXYSI+U56KWF3R+iV5QqgJ/uJDr91RE4Q5IIJe07wdiF jq+QQ+xURNimz2MBlRGc3DZFnvj/wDYvfL9czjB3FCGFw1/Dr8yJeRP8ZbO9QsWya8mx 6MN+RGEgwKIxPWTq8ZpqmgrvPiRevlkkTsuNBYBBG5StgwYAjDxSxoesMqfyOtE292MK wVEA== X-Gm-Message-State: APjAAAXf/7KUy4xMvQebNMN09do7Fqyace7z8VoJHgeVBCk2sDaNCiAF Yv3DFp/O+UBoxE6B4cjqSL0= X-Google-Smtp-Source: APXvYqx2Mogi4mKA6cNteEHUGvt1E0/OL97PltBMxG53qeXqJaUKoPqFLm2al+SPbMrYgjLLPRx5Hw== X-Received: by 2002:a63:234c:: with SMTP id u12mr22229188pgm.282.1553495086111; Sun, 24 Mar 2019 23:24:46 -0700 (PDT) Received: from localhost.localdomain ([2001:268:c0a5:e068:c70:4af9:86e2:2]) by smtp.gmail.com with ESMTPSA id p88sm24194193pfa.80.2019.03.24.23.24.41 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Sun, 24 Mar 2019 23:24:45 -0700 (PDT) From: William Breathitt Gray To: linus.walleij@linaro.org, bgolaszewski@baylibre.com Subject: [PATCH v12 09/11] gpio: uniphier: Utilize for_each_set_clump8 macro Date: Mon, 25 Mar 2019 15:25:41 +0900 Message-Id: <4d45bc472fabd5f5339a182782b27bd25f82cd49.1553494625.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-20190324_232447_249353_CAB635DC X-CRM114-Status: GOOD ( 11.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, preid@electromag.com.au, yamada.masahiro@socionext.com, linux-pm@vger.kernel.org, linux@rasmusvillemoes.dk, linux-kernel@vger.kernel.org, William Breathitt Gray , linux-gpio@vger.kernel.org, geert@linux-m68k.org, 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); From patchwork Mon Mar 25 06:26:00 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: 10868001 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 2492513B5 for ; Mon, 25 Mar 2019 06:25:20 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 142B12910B for ; Mon, 25 Mar 2019 06:25:20 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 126A0291E2; Mon, 25 Mar 2019 06:25: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=-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=unavailable 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 96D8F2910B for ; Mon, 25 Mar 2019 06:25:19 +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=jFi9yYjYCuRYtRrrijvCVZWQoWGZRwBrITLNoL+tBjc=; b=TQS8MHU4N5v4VK PhkCFfSw+RcTLMTKzshn3hKUcbC+C0IzCEBkgDMZb2OAFw60P9337gJkZABvPDakn243Ycm0uZUJy Po7BZY6euxjxSCJkuluJ1FxleOUjMf9k60uOM83Cd0dNiL9Wb3Gs+k8igrGqRxAZiRh6HvS4hcTka itdZJYg5FDuL1LHwjFccrNAZazBEebk422hXBDmBhzcPvsXG3yXiJlbx0GxRaogDfVAXV4nNuq772 DAKRbpq3P/GpfCM9WphK48K+a41KXJWiu8uG4PM6C2cdH1OaMfJwQLqpuCQcQdzl+ynVX8qDt76sC OrzqX3iQV4uji+kuzcyw==; 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 1h8J2m-0000Tc-VP; Mon, 25 Mar 2019 06:25:12 +0000 Received: from mail-pf1-x441.google.com ([2607:f8b0:4864:20::441]) by bombadil.infradead.org with esmtps (Exim 4.90_1 #2 (Red Hat Linux)) id 1h8J2f-0008Dj-IU for linux-arm-kernel@lists.infradead.org; Mon, 25 Mar 2019 06:25:09 +0000 Received: by mail-pf1-x441.google.com with SMTP id b3so4264504pfd.1 for ; Sun, 24 Mar 2019 23:25:05 -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=rn9yFD+HCmLRiJvK0EHcTg58WpdUT2SY4x4SxooleZ8cn6gLA3L3Ka/E0yd9y/IkLf HTjO3KtgruTpFsCCttihDDRp6Kt7AzEjK0LOwJ+hYpjDYYHWVOouAduSiQxkJRXMzsFr 4dm+fmfAgraOsmrw5WY881LCHPrawKfe08g+Q0N5a4BsfJmwdOsMK+eZ6nDwI64GaARy Jxeql8wjHmiChuSw4ZvtN9I2N1JKhga/mAlSFjym5U3z/6TpwV0tHuSiFDDGW+67K1Fp Xbo5lMCpO8RdOL4+I9y2c4hRFZm2hh4IK99kJvVFcQdjDih9GM27SFNtHfa+LZ0gFmtc Cy8A== 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=K5EGKOJmufZgxHDhu9mloUvOg5BJTsKUoI0HiMJQ7PIBQExmfS4dptSIpMwhutLcIe PxQm3oJ3pCPYk8RYU30W7GJQwiPPxs2349LaFzNpXM37PjIVRVL5tVXXy+m7Rdplbq1X wBWseuJ9VOtg98hFDzT5VFnefGPKtKP+T2luifinZPHBkSXI1E8pWZ2wSO0J14nOR0zo C0snIOu8vR9y6YHaYZUIdCXl4JUzgmXRYsKFJ3tEI2QDOPecFq8bKgwygJmxJsVa3pp6 V841H61kEgCFWw/TzXi02gFaeK11NKlxnSrFsO0BSgrFIPweLaYivXPBJgYJR5j0+HSx fSqQ== X-Gm-Message-State: APjAAAURpBrDy7QJ0eefrMJGmAYxCdrdj5z1Kx2uhlZX9KvoqZU5R1tn 29RK9/52DRO9MkWiAXDb9lonmdvY X-Google-Smtp-Source: APXvYqww67AXAbRRzSzMyBvGI/P5H6tq9HiN2vfehl7XlqahLGYqB1nuidspt/MryO0ncPbvP1GVZA== X-Received: by 2002:a63:65c4:: with SMTP id z187mr21481220pgb.102.1553495104377; Sun, 24 Mar 2019 23:25:04 -0700 (PDT) Received: from localhost.localdomain ([2001:268:c0a5:e068:c70:4af9:86e2:2]) by smtp.gmail.com with ESMTPSA id 125sm22703186pfw.139.2019.03.24.23.24.59 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Sun, 24 Mar 2019 23:25:03 -0700 (PDT) From: William Breathitt Gray To: linus.walleij@linaro.org, bgolaszewski@baylibre.com Subject: [PATCH v12 10/11] thermal: intel: intel_soc_dts_iosf: Utilize for_each_set_clump8 macro Date: Mon, 25 Mar 2019 15:26:00 +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-20190324_232506_018221_847F593D X-CRM114-Status: GOOD ( 14.78 ) 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, preid@electromag.com.au, yamada.masahiro@socionext.com, linux-pm@vger.kernel.org, linux@rasmusvillemoes.dk, linux-kernel@vger.kernel.org, William Breathitt Gray , linux-gpio@vger.kernel.org, geert@linux-m68k.org, 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 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:26:18 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: 10868005 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 E66ED14DE for ; Mon, 25 Mar 2019 06:25:34 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id D6452291DF for ; Mon, 25 Mar 2019 06:25:34 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id CA910291E1; Mon, 25 Mar 2019 06:25:34 +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 69BC3291ED for ; Mon, 25 Mar 2019 06:25:34 +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=axzlx/Ik2uzhXbcP42ilqfckjYdzlE9ebOg0xAU2kbQ=; b=XsOrfdPyWhgvx3 szllsXVqlVZatq4fWm2krK4jostBA/Hg8Z6lsaTtvXUoeLhBSjWLIoRmJR/Bym4dL6o2dSF2Gh6lB T83zqQpcxfxXNXwO/eIkNPT9DefxFP7bQ5KsQVdiYyZ2mZQovnFZbUtakajupuQBLXsXnOSDmXgFX +BZ+EVHHgw0MykKa10B9cfm+A5HUBm6cx7iuokYVAbRXSka5JAKjQe/XkCXj7P4UmDMNlFdsPVj5q p6RAWwfBdbi7gi3R1If/CemZmH2K6YZp7dLzBdk2jREg8iX9V2JGdF8IY7KXtjotZCwpDDU3YDrAg ZfVnzJKR+KDqTyBTt6Yg==; 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 1h8J36-0001Eg-UT; Mon, 25 Mar 2019 06:25:32 +0000 Received: from mail-pf1-x444.google.com ([2607:f8b0:4864:20::444]) by bombadil.infradead.org with esmtps (Exim 4.90_1 #2 (Red Hat Linux)) id 1h8J2y-0001AK-Lp for linux-arm-kernel@lists.infradead.org; Mon, 25 Mar 2019 06:25:31 +0000 Received: by mail-pf1-x444.google.com with SMTP id 9so5617319pfj.13 for ; Sun, 24 Mar 2019 23:25:24 -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=tniDY5EwLN11L7eu43+i1s1Bf9E9i7HV2YfeauI/peDqWD8tGU2R5dqkOGctVVJfui i/MvRy8sQhgXUU+mbgvuG+h4RWexOCRA+Veg33w1T1wS27K5s9bZtVaPqvz5lYHzvNWZ 0nEhRXKCrs3I5AZHdYyf7DvHyGOu4dMOG1Olkpxka0j9vHxPRafIAqNBziUcT42FpZLf a+mcGGU3PqcYQYVW6iV6tlfBd8ofNO/IroRs1xEsBNyX0laAYfFqpWceLJ9gAx4RXGOs YFnFUMbb3/gt2wVY/Y1nQBUWI+yd5fM13fOzVrkYsBUsi42cqUKJm5mNXXmxe7bLiDUo em5g== 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=Z/xMWwoPUVFSrnBGgm4ZxfRcuOltQPqboUC3IJmS1cWvrIwnS2R8nARlJZ7O+3GX68 RgwCS86uz6bIIlrG091Be+niJUGiw3r5Y+F464punIBiMygcG6FsFPtVjULBkSZCnRIX JBI/QH6NgXAwD1jLDGFQLUQQSHgmrmUbS51cOw4snZ1N2xc8loz+yl4hYGP5nRYBXO/Q AVqycjRcOI/vqtNf+r2PG1U4yJeuZMaXdtiq28twGMF+s/jw2D8w0RwnLxyognXUwC30 EXlqFVYOycNXmFUfsRb2ZRZzRDHik4uxQTtVMe8gSgo78dkAue8w1X3XskBQ5/QgdmPm 33mQ== X-Gm-Message-State: APjAAAVmpLcDoN86dDhe4n9tohrsqkXhunecLffmX7rwhziKdkuze1tM RmFGVh4Lp9/3X83eZwqXZHSRgPpQ X-Google-Smtp-Source: APXvYqwsG4wMT6D5NTstH+BJC+sL2uKdKWfZk0yHRaCFUmLDoDJQF0+Xwfb5A5errea2GsbkTYEN8A== X-Received: by 2002:a63:470a:: with SMTP id u10mr22217094pga.17.1553495124097; Sun, 24 Mar 2019 23:25:24 -0700 (PDT) Received: from localhost.localdomain ([2001:268:c0a5:e068:c70:4af9:86e2:2]) by smtp.gmail.com with ESMTPSA id a65sm19978589pgc.72.2019.03.24.23.25.19 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Sun, 24 Mar 2019 23:25:23 -0700 (PDT) From: William Breathitt Gray To: linus.walleij@linaro.org, bgolaszewski@baylibre.com Subject: [PATCH v12 11/11] gpio: 74x164: Utilize the for_each_set_clump8 macro Date: Mon, 25 Mar 2019 15:26:18 +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-20190324_232525_472062_9AB4926A X-CRM114-Status: GOOD ( 13.08 ) 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, preid@electromag.com.au, Geert Uytterhoeven , yamada.masahiro@socionext.com, linux-pm@vger.kernel.org, linux@rasmusvillemoes.dk, linux-kernel@vger.kernel.org, William Breathitt Gray , linux-gpio@vger.kernel.org, geert@linux-m68k.org, 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. 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);