From patchwork Mon Mar 25 06:03:13 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: William Breathitt Gray X-Patchwork-Id: 10867915 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 5AA551390 for ; Mon, 25 Mar 2019 06:02:36 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 416E12916C for ; Mon, 25 Mar 2019 06:02:36 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 34E92291D2; Mon, 25 Mar 2019 06:02:36 +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 A533A2916C for ; Mon, 25 Mar 2019 06:02:35 +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=EOfjzTJ2oRE7GZy6GRUoBGslos4aU74//FEXpfWgTGA=; b=XiRCJPRUuTV1Bp dt+AIbj1oBfBVtu2CXdf7f+Dug8Lfb6WbJJsBgJ6xUbQ9MA1/t+s08yFFioBIENsTn+1ogBgkvOeD Oal1CC5cp1YTirC1WlOBCja9I0Xj6b9wfwuILz69HaadB4t1ZPRNh5aYTXoNZbvq2cjXtrd0+fvqJ 0Qio/Tl4Zf81nYSXezHOWTY+ZJ8F+DW6q/KeyAbiMnA9td+9PF3pSISx9e4BUFLwnyiO9fw03HVNM NY+DmpVc48mFffV/54RSRERtWuZdr9bQKBPfs2JNqYpmJFW4y+HknDod0bKryRqGEakn7F2TegTYe 53ycBmW8qvMN3am1BYBQ==; 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 1h8Igi-0002uB-TM; Mon, 25 Mar 2019 06:02:24 +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 1h8Igc-0002ot-Bi for linux-arm-kernel@lists.infradead.org; Mon, 25 Mar 2019 06:02:22 +0000 Received: by mail-pg1-x542.google.com with SMTP id p6so5708183pgh.9 for ; Sun, 24 Mar 2019 23:02:17 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=ez7ZzkC0Ak7aYk3BUE6/NHn4l6C5sfpy4Uv8mjEL3xM=; b=VCJi6P0v7PMWaX+AcmGNy17eE7dSpng3HsjixnR1IbTAFeRSW6kM/SN4IT9qGsqyPe buTKNmokd9md7Mst7vgiFJb+9Mu4HM8zykhdZczHMSnHQkG3LVE9nG0rz1XB4hCewMur GeRB5Jb1lJ0tMUhO4rqsfhihuXR3ZNOX3vr1DrWSTEaUXcoSXD420EgihRjG2tZA21TW i+ON9j/r+GHJ8v9ENStjlSzXc2yNFqRpZtANKu/BUQfn5tlMaiiNjejEF63s3yx0QECZ Pan2TM6mUYrgbROBVwDsO5JO6Su57H3u/uyCV+Ukctmcv7ZXxEl8M/qDOPX6JtzJcpEL LY4g== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=ez7ZzkC0Ak7aYk3BUE6/NHn4l6C5sfpy4Uv8mjEL3xM=; b=SI8y/khJtJIRlprPIOIOhJQcua9lvNaUgji9Y0FjHbMUMY++H6TRuvHTfwtQ8T5Fh3 cj75BNwZ/Tg4obYDiPL/iLH1hC4/dde346tIFlEFaQpLvcwogx1+KqHTfXkWih0TBe5D A11w7SV94e+v90wKF5dHFQ5SdpKXYoBRGYWbmnPDA9ja8vLEmIDedVc8ESKjyZbPGOcN 2MM2G/+ZbSGC/hTfqx4DtStulfyv3kSbuEwx46D+OWW/A7WxdxG2IDeXnCMnFB6OA7zl aqBzJQ010RwHhFqW/YTn5htBAg+qMkpKOKUljTVhR4aYPh3qCZuR8Mm4MNGvqHKHTlzK ipyA== X-Gm-Message-State: APjAAAVyFPb/gy4QBxV87nFtD5T63Nvyd6uk64r5rO3JNMGP5hNZlUgD XV11M/cdrk97rB1kpGE1fOYwsglg X-Google-Smtp-Source: APXvYqyJX1OKLzcw9XTWvb8RMbdMXvszO+qx+gHh4PgykeRMVMxJz/OJ+CmMkh0YgWOpEL0qdtgAUg== X-Received: by 2002:a63:e554:: with SMTP id z20mr20226843pgj.234.1553493737475; Sun, 24 Mar 2019 23:02:17 -0700 (PDT) Received: from localhost.localdomain ([2001:268:c0a5:e068:c70:4af9:86e2:2]) by smtp.gmail.com with ESMTPSA id t82sm10820235pfa.153.2019.03.24.23.02.11 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Sun, 24 Mar 2019 23:02:16 -0700 (PDT) From: William Breathitt Gray To: linus.walleij@linaro.org, bgolaszewski@baylibre.com Subject: [PATCH v11 01/11] bitops: Introduce the for_each_set_clump8 macro Date: Mon, 25 Mar 2019 15:03:13 +0900 Message-Id: <64f9eed704899d31b34798c7ec7a42f28fd2d051.1553492741.git.vilhelm.gray@gmail.com> X-Mailer: git-send-email 2.21.0 In-Reply-To: References: MIME-Version: 1.0 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20190324_230218_413273_BCCBF887 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..c2af1f013ea2 100644 --- a/lib/find_bit.c +++ b/lib/find_bit.c @@ -218,3 +218,84 @@ EXPORT_SYMBOL(find_next_bit_le); #endif #endif /* __BIG_ENDIAN */ + +/** + * bitmap_get_value8 - get an 8-bit value within a memory region + * @bitmap: address to the bitmap memory region + * @size: bitmap size in number of bits + * @start: bit offset of the 8-bit value + * + * Returns the 8-bit value located at the @start bit offset within the @bitmap + * memory region. + */ +unsigned long bitmap_get_value8(const unsigned long *const bitmap, + const unsigned int size, + const unsigned int start) +{ + const size_t index = BIT_WORD(start); + const unsigned int offset = start % BITS_PER_LONG; + const unsigned int low_width = (offset + 8 > BITS_PER_LONG) ? + BITS_PER_LONG - offset : 8; + const unsigned long low = bitmap[index] >> offset; + const unsigned long high = (low_width < 8 && start + 8 <= size) ? + bitmap[index + 1] << low_width : 0; + + return (low | high) & 0xFF; +} +EXPORT_SYMBOL(bitmap_get_value8); + +/** + * bitmap_set_value8 - set an 8-bit value within a memory region + * @bitmap: address to the bitmap memory region + * @size: bitmap size in number of bits + * @value: the 8-bit value; values wider than 8 bits may clobber bitmap + * @start: bit offset of the 8-bit value + */ +void bitmap_set_value8(unsigned long *const bitmap, const unsigned int size, + const unsigned long value, const unsigned int start) +{ + const size_t index = BIT_WORD(start); + const unsigned int offset = start % BITS_PER_LONG; + const unsigned int low_width = (offset + 8 > BITS_PER_LONG) ? + BITS_PER_LONG - offset : 8; + const unsigned long low_mask = GENMASK(offset + low_width - 1, offset); + const unsigned int high_width = 8 - low_width; + const unsigned long high_mask = GENMASK(high_width - 1, 0); + + /* set lower portion */ + bitmap[index] &= ~low_mask; + bitmap[index] |= value << offset; + + /* set higher portion if space available in bitmap */ + if (high_width && start + 8 <= size) { + bitmap[index + 1] &= ~high_mask; + bitmap[index + 1] |= value >> low_width; + } +} +EXPORT_SYMBOL(bitmap_set_value8); + +/** + * find_next_clump8 - find next 8-bit clump with set bits in a memory region + * @clump: location to store copy of found clump + * @addr: address to base the search on + * @offset: bit offset at which to start searching + * @size: bitmap size in number of bits + * + * Returns the bit offset for the next set clump; the found clump value is + * copied to the location pointed by @clump. If no bits are set, returns @size. + */ +unsigned int find_next_clump8(unsigned long *const clump, + const unsigned long *const addr, + unsigned int offset, const unsigned int size) +{ + for (; offset < size; offset += 8) { + *clump = bitmap_get_value8(addr, size, offset); + if (!*clump) + continue; + + return offset; + } + + return size; +} +EXPORT_SYMBOL(find_next_clump8); From patchwork Mon Mar 25 06:03:30 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: William Breathitt Gray X-Patchwork-Id: 10867919 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 7287F1390 for ; Mon, 25 Mar 2019 06:03:06 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 57D182916C for ; Mon, 25 Mar 2019 06:03:06 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 47843291D2; Mon, 25 Mar 2019 06:03:06 +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 C363A2916C for ; Mon, 25 Mar 2019 06:03:05 +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=tBOKxBtDY7Ttemj/TO23+AqbwteD7s2+32Zq5Ufqsfg=; b=W0aFH8Zdu8GAEE IZSTe8bpPIy2FV5AMa/gl9X2PbnIn09BgYKGMCwtkyaVZzbKdyKd6LQAsSr7Yz2ulKeVMOv21ZaCp 0WV/5x8g3EplBskm/4uj550XMigEjXbamkkLYiLgmNCc+QP1rKbH3IK2CZBGhrXyBIWuehikYF3Z9 5xYcajRBml/SndZkzoqnP0CQ7OSBvHJmPCgCtMDI+kKCntGTnb/ZyMJMoqQl1hSkaywyeEagRb9MF /mrpF30ZMDVV0GvuW4nHwUnw6f/k9IQPABOkIQLlNAv2oYrYjNtQq/lKt4u82Ue9sFTkqA5pJZDQy 7D2+p9U7Z4DS7c9tYcHg==; 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 1h8Ih8-0003Jd-Mm; Mon, 25 Mar 2019 06:02:50 +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 1h8Igy-0003AS-QO for linux-arm-kernel@lists.infradead.org; Mon, 25 Mar 2019 06:02:48 +0000 Received: by mail-pf1-x443.google.com with SMTP id i17so5603729pfo.6 for ; Sun, 24 Mar 2019 23:02:38 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=j0Kkp+Q1g48qFmEIxNbX8Si8M5iMlqRk5DRd5visCZQ=; b=K19JcWsHru69/+JRSlGqp3B/5LztIKApPQ5qeczawd17eLLZm8xx3TOD7oyw+N2Cys 0eZEsSNXBSqoZEZb0gebw9rYuGzkBaoGTqe3KibF1fgw4sJa3MjBEBMEGcqWUN0TAAWJ gvUYcJsqMHINydviLMcByLM5sYr4FxTz4qwKUq4d9/iA2VipNNly1i2tef6gEv6QrCvt bJDpp0UQhmvbN0RmiIPAcDgV5+UAfzGxbqytdM73AKFCXiHZyssF4pYXufy8gvV0gFt2 pC/vPyuCfcgLoQHx6rTryLo9dRa1tqcgBvcaoyxnW942GFZ3wNFSMlg7XBNBNsvYw8jJ dsJg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=j0Kkp+Q1g48qFmEIxNbX8Si8M5iMlqRk5DRd5visCZQ=; b=hIaNBVF+2K1ShxjHE11lKZ2338iYEpLJBVjQZiQQ2ZZdm8fuSE4CLX3Uub3SF51GgR AEPiRmlGnofeoEy8GzRGQZ1PWPi08kVGVI6ngER04vfSFEsU33sEVoF24UI2hqvzoQzG Ard3qK6z4Y0f8R+YS0SFxoqHT7EnqBjI/BHhpHZFQGSpCWC6vgKonrAONbZEefrruJzx o9g+mhzvwKUFk15vc51cFOjlILOd3IVfY3m9GOxxjN/k8IZUww58azKL90qDdC3vQlUX u1UbpEiblULq3uoe7PY+wywWTZZModE+XGkvKf0vUqlk0BfQnPkT6BNAuEbwYrw08bjf xB5A== X-Gm-Message-State: APjAAAXClj8JmVFZMZUkP+g3GU2i5lhtuPhYTKUiTbpcUVd9Fb9ZbQt8 XkySUjj3RTmPRwbCsmoRj3Q= X-Google-Smtp-Source: APXvYqwebddJln7MTdN4Umod2UvaujF1PygARHgSMbYGPz0slKRd3drAsDSWfNavDz7GqDq2EWBGKQ== X-Received: by 2002:aa7:9219:: with SMTP id 25mr22949965pfo.205.1553493754906; Sun, 24 Mar 2019 23:02:34 -0700 (PDT) Received: from localhost.localdomain ([2001:268:c0a5:e068:c70:4af9:86e2:2]) by smtp.gmail.com with ESMTPSA id u4sm16965798pgp.59.2019.03.24.23.02.29 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Sun, 24 Mar 2019 23:02:34 -0700 (PDT) From: William Breathitt Gray To: linus.walleij@linaro.org, bgolaszewski@baylibre.com Subject: [PATCH v11 02/11] lib/test_bitmap.c: Add for_each_set_clump8 test cases Date: Mon, 25 Mar 2019 15:03:30 +0900 Message-Id: <1cc0950e1e68270918da157b979dcbc32eedfd59.1553492741.git.vilhelm.gray@gmail.com> X-Mailer: git-send-email 2.21.0 In-Reply-To: References: MIME-Version: 1.0 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20190324_230241_422016_D65CFC4B X-CRM114-Status: GOOD ( 15.70 ) 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/find_bit.c | 2 +- lib/test_bitmap.c | 65 +++++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 66 insertions(+), 1 deletion(-) diff --git a/lib/find_bit.c b/lib/find_bit.c index c2af1f013ea2..1b6f8a6f1957 100644 --- a/lib/find_bit.c +++ b/lib/find_bit.c @@ -258,7 +258,7 @@ void bitmap_set_value8(unsigned long *const bitmap, const unsigned int size, const unsigned int offset = start % BITS_PER_LONG; const unsigned int low_width = (offset + 8 > BITS_PER_LONG) ? BITS_PER_LONG - offset : 8; - const unsigned long low_mask = GENMASK(offset + low_width - 1, offset); + const unsigned long low_mask = GENMASK(low_width - 1, 0) << offset; const unsigned int high_width = 8 - low_width; const unsigned long high_mask = GENMASK(high_width - 1, 0); diff --git a/lib/test_bitmap.c b/lib/test_bitmap.c index 6cd7d0740005..8d1f268069c1 100644 --- a/lib/test_bitmap.c +++ b/lib/test_bitmap.c @@ -88,6 +88,36 @@ __check_eq_u32_array(const char *srcfile, unsigned int line, return true; } +static bool __init __check_eq_clump8(const char *srcfile, unsigned int line, + const unsigned int offset, + const unsigned int size, + const unsigned char *const clump_exp, + const unsigned long *const clump) +{ + unsigned long exp; + + if (offset >= size) { + pr_warn("[%s:%u] bit offset for clump out-of-bounds: expected less than %u, got %u\n", + srcfile, line, size, offset); + return false; + } + + exp = clump_exp[offset / 8]; + if (!exp) { + pr_warn("[%s:%u] bit offset for zero clump: expected nonzero clump, got bit offset %u with clump value 0", + srcfile, line, offset); + return false; + } + + if (*clump != exp) { + pr_warn("[%s:%u] expected clump value of 0x%lX, got clump value of 0x%lX", + srcfile, line, exp, *clump); + return false; + } + + return true; +} + #define __expect_eq(suffix, ...) \ ({ \ int result = 0; \ @@ -104,6 +134,7 @@ __check_eq_u32_array(const char *srcfile, unsigned int line, #define expect_eq_bitmap(...) __expect_eq(bitmap, ##__VA_ARGS__) #define expect_eq_pbl(...) __expect_eq(pbl, ##__VA_ARGS__) #define expect_eq_u32_array(...) __expect_eq(u32_array, ##__VA_ARGS__) +#define expect_eq_clump8(...) __expect_eq(clump8, ##__VA_ARGS__) static void __init test_zero_clear(void) { @@ -361,6 +392,39 @@ static void noinline __init test_mem_optimisations(void) } } +static const unsigned char clump_exp[] __initconst = { + 0x01, /* 1 bit set */ + 0x02, /* non-edge 1 bit set */ + 0x00, /* zero bits set */ + 0x38, /* 3 bits set across 4-bit boundary */ + 0x38, /* Repeated clump */ + 0x0F, /* 4 bits set */ + 0xFF, /* all bits set */ + 0x05, /* non-adjacent 2 bits set */ +}; + +static void __init test_for_each_set_clump8(void) +{ +#define CLUMP_EXP_NUMBITS 64 + DECLARE_BITMAP(bits, CLUMP_EXP_NUMBITS); + unsigned int start; + unsigned long clump; + + /* set bitmap to test case */ + bitmap_zero(bits, CLUMP_EXP_NUMBITS); + bitmap_set(bits, 0, 1); /* 0x01 */ + bitmap_set(bits, 9, 1); /* 0x02 */ + bitmap_set(bits, 27, 3); /* 0x28 */ + bitmap_set(bits, 35, 3); /* 0x28 */ + bitmap_set(bits, 40, 4); /* 0x0F */ + bitmap_set(bits, 48, 8); /* 0xFF */ + bitmap_set(bits, 56, 1); /* 0x05 - part 1 */ + bitmap_set(bits, 58, 1); /* 0x05 - part 2 */ + + for_each_set_clump8(start, clump, bits, CLUMP_EXP_NUMBITS) + expect_eq_clump8(start, CLUMP_EXP_NUMBITS, clump_exp, &clump); +} + static int __init test_bitmap_init(void) { test_zero_clear(); @@ -369,6 +433,7 @@ static int __init test_bitmap_init(void) test_bitmap_arr32(); test_bitmap_parselist(); test_mem_optimisations(); + test_for_each_set_clump8(); if (failed_tests == 0) pr_info("all %u tests passed\n", total_tests); From patchwork Mon Mar 25 06:03:50 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: William Breathitt Gray X-Patchwork-Id: 10867923 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 4E77F13B5 for ; Mon, 25 Mar 2019 06:03:20 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 36B9E2916C for ; Mon, 25 Mar 2019 06:03:20 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 29FB8291D2; Mon, 25 Mar 2019 06:03: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 BEE382916C for ; Mon, 25 Mar 2019 06:03: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=8S1NRFXAry7OT1sEQgnbr77coxWRoNIKo3aUm4nxjFs=; b=N3E+DZXULR6VTQ FtG4z8Egb1R2cfmDW/Q7ATbJntbtyTyUdWxKOBlz1TxPVfQQYdIHjT8bniTD42vg8axGGgBqDezxn Z/1Zhez03976PtMqqmCRNF+k+Wl6Sa1au8kSY/LP7NdxPc3W3JCS3f93DI9t/jMEWDpsH70kYe/XD 81JFFuIN3HfCfBGdQwszvU6lWcev4XHhTn03UUI1wjDFjoXnU2jq5Zw0zxAryAWaYnp3cK7g1ebjr ErsEwebbkWA/eXD0tH3w/Zf2RC9TskbV1+BXfsX48/moNSMXOAcVOd7likBEhDcSogt5OLFnWKk2j ywakAbD2nF4NkDoaJLRA==; 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 1h8IhT-0003aQ-Pd; Mon, 25 Mar 2019 06:03:11 +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 1h8IhL-0003VI-0y for linux-arm-kernel@lists.infradead.org; Mon, 25 Mar 2019 06:03:09 +0000 Received: by mail-pg1-x544.google.com with SMTP id j26so3705014pgl.5 for ; Sun, 24 Mar 2019 23:03:02 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=5tnH02Yc3JnragyosQ4LQT3N7xcrc3Yee7t/cF7aZ1U=; b=jXcJtuVpXOyy1eS/IuOBtT/mVywf/udSKMN9lHjbVpMSww81XCsWV028peup4S4Y7D K7zpMUxdKCaYGIe2Ouaslcx/k/+Ls36UX2GQhSe6rQM/fN+in+RkTx9AT6uxQHpi8oQb LtmlMu4Yvspgyp+9m4c1uSfWawvyadYwSdnbGpOBWcHnP1DZ1FePhrtJ4KUT7ymjYgt4 a1WzOe3D/E5cZ2uCdVC1mTVumhGtFM1nLNuY7DFOe0unxSsmI0hCpXQ76DhuJwef/qmT +DmvGxIas0UslSP9Q5J1HjWFBKJ4pdJx0s8qZn4DFLINFNKNWEoNboQFEWPCOUWasdxo j/Cg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=5tnH02Yc3JnragyosQ4LQT3N7xcrc3Yee7t/cF7aZ1U=; b=FLkKLCWFZhMYThGcezeVg7yyBzL7k0ry0e7c7wDxuMZgAmDF6RiO1f3ytn6PRMsKwR p4W1aYG0iwcGJCkVGFbnJ/WcR0O8hntdDFVyhE0yuEbBzuERAOn44n+njkIhHZXMk4Zp Kfx7pF/qjteNgyuPfts+0+42kJ3fOk5E4D977z1uEC9Lel+TI6myrOoW4ZBBQJbRa+fe UMFBHDx4Z8RvS6XRl2T7VnwgUCkLaPkAwQhW+wYKNxV8DV8L7YSc5qCQpNVp1ewmVcKR RW7i60mjkB6QmBrSqaqcibV6P5f8d0uHAp6vLBf1bzHOgY4E4nSrBMdYdsuW2L1C39eT sDkQ== X-Gm-Message-State: APjAAAWD9G96KdV2rnfPCdyJMqBcxZqKv5xpn71XOOUXR+cR8t0PNm97 22BwBj4F7Yt4IPKm39vh7FE= X-Google-Smtp-Source: APXvYqweGMQRP0AIffUxQkYe4iWYYQtCjS/M0jWgdhXaSpHh4Es1axIwQe8A3wvmL9qDKMr7bk7LqA== X-Received: by 2002:a17:902:1125:: with SMTP id d34mr23926978pla.75.1553493782495; Sun, 24 Mar 2019 23:03:02 -0700 (PDT) Received: from localhost.localdomain ([2001:268:c0a5:e068:c70:4af9:86e2:2]) by smtp.gmail.com with ESMTPSA id m2sm18006198pgr.74.2019.03.24.23.02.54 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Sun, 24 Mar 2019 23:03:01 -0700 (PDT) From: William Breathitt Gray To: linus.walleij@linaro.org, bgolaszewski@baylibre.com Subject: [PATCH v11 03/11] gpio: 104-dio-48e: Utilize for_each_set_clump8 macro Date: Mon, 25 Mar 2019 15:03:50 +0900 Message-Id: X-Mailer: git-send-email 2.21.0 In-Reply-To: References: MIME-Version: 1.0 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20190324_230304_043334_39858F32 X-CRM114-Status: GOOD ( 14.39 ) 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:04:16 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: William Breathitt Gray X-Patchwork-Id: 10867927 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 D499F13B5 for ; Mon, 25 Mar 2019 06:03:33 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id BCF3F291CF for ; Mon, 25 Mar 2019 06:03:33 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id B12EE291D4; Mon, 25 Mar 2019 06:03:33 +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 5DA8B291CF for ; Mon, 25 Mar 2019 06:03:33 +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=J1u7iZz3Dz0fhr 0pdw468TBjk7O0kwl+7Pw+ugPY/0cfofoLMvyjJFta3sAdzFEihWzzGUbM0ELqQrvKoIGO/rzrIwR /caG2vnXsQwIMgjdJApFwn52Hechv7KWS6yrzRvyVTD/41LeVuEBxaVZhx3aMDbRDT7c1h96OkEa2 wt5MkpJaN8rhES/cBoxwIDw4F5wvMwd3Yk/JM17Vxr7/7EA6ccOkkXF9GfZrKp6SbFwNpxFDrW8jM /01Qzw+QeL9lnEU47IfDY/2Lot3rGsFTVzSIti9plqlC0QsYxpqzXyH94XfPffU0Vl/QyLGGufxdG fB9SgomCzGLQDQnKpvkQ==; 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 1h8Ihn-0003rV-0O; Mon, 25 Mar 2019 06:03:31 +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 1h8Ihd-0003mO-T7 for linux-arm-kernel@lists.infradead.org; Mon, 25 Mar 2019 06:03:29 +0000 Received: by mail-pf1-x441.google.com with SMTP id r15so5589193pfn.9 for ; Sun, 24 Mar 2019 23:03:21 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=wovyItwhuu6up6N9d5xqiEvzR3TkCWii5hwPk2X/3Vc=; b=t7dheYot/to1cOshyBqUFiWKdlK6zUPa2kZgUX9ri9YieAOtQx1M8ljQ2y3F+hlMw+ yZktELnPYVjXjOcQXYhLtjLZvN+Cn+FsSbX0mShwzls2Gkbd0YX0NGM7Ki1+k/6CFeET xmwsMxRzJP1jgzh9y1V0BjDNqkvJb/RRlBtlGEiWuzXqEpF6F0jX9PMjfRQvITS4Ad5Z JeKOn3E3NcAehXBJ417LE51vyin7ympkxi1bkxRCleUe4yF3Y5dYrqxV5Gt4JWroLbgq roCPv0N2VH0J0+FB+tJ3BY3TlWezPpCQTkQ/wlr5TQd4vTwChfvs+GR0g1E2T5j6zqee TU7A== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=wovyItwhuu6up6N9d5xqiEvzR3TkCWii5hwPk2X/3Vc=; b=tOJ0rRWmwg4kKaXZO3Xf3sccWibV2EyFEIjtyg/H/OFtpalEke6R1RM89iBkmV9jRd bOXhb7QvrJjLp+bnoyjiHUpVTW2tt+SudYwV4ik3Hu5DbEMvcEwrooIqmBW7h3uIYE57 zMIEjkWFxTIaliX6swhbzcHSfrfKoMF6NvYms5aCpWWfhxOgJHJv5VKPUyoNCnHWs19k IPQHxx1ZHSAT4bQ+QXLvUuaUt8lIMUggACuKUDwgPUkVnQW1vYSHruz6k4v4eotFR8VY 3g9iTpOUbKk2ub2VyNm6HrEbtRGQ7gtK15pXCBEfGAPoLkaGD3L05T+1h67HKRgGa/yQ B4Eg== X-Gm-Message-State: APjAAAUBzuxDiEyULjcUlKG9ZZ92mmWnOLvc22hygzrSWAjldCd5pgEb hAl4CpxIug55fR4mVJ/FI9s= X-Google-Smtp-Source: APXvYqw5waGrSLHDsnc18OzsVFHqn2mGhg5skjMtoDXJZ7lHdplfgjMSLhEk0lD7XRiX2TDJzbP8AQ== X-Received: by 2002:a17:902:2d01:: with SMTP id o1mr23638429plb.155.1553493801272; Sun, 24 Mar 2019 23:03:21 -0700 (PDT) Received: from localhost.localdomain ([2001:268:c0a5:e068:c70:4af9:86e2:2]) by smtp.gmail.com with ESMTPSA id i22sm19433145pfa.88.2019.03.24.23.03.14 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Sun, 24 Mar 2019 23:03:20 -0700 (PDT) From: William Breathitt Gray To: linus.walleij@linaro.org, bgolaszewski@baylibre.com Subject: [PATCH v11 04/11] gpio: 104-idi-48: Utilize for_each_set_clump8 macro Date: Mon, 25 Mar 2019 15:04:16 +0900 Message-Id: X-Mailer: git-send-email 2.21.0 In-Reply-To: References: MIME-Version: 1.0 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20190324_230322_108954_9BEA9F56 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:04:35 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: William Breathitt Gray X-Patchwork-Id: 10867931 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 816691390 for ; Mon, 25 Mar 2019 06:03:56 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 671D7291CF for ; Mon, 25 Mar 2019 06:03:56 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 5B21A291D4; Mon, 25 Mar 2019 06:03:56 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-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 ED7FC291CF for ; Mon, 25 Mar 2019 06:03:55 +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=lo8WHfPgThCX01 KGnb5zImWmljMiGTsaLx1tFS6BudIm/xLKXrQMun17CN2vBkfnRX2C0sWu/blvQzmV5n83c4OGQ8H BivEe/Oefczs+LY667HjMIp2DCZSMxYWRX+WZ9B02ZPD5ElC3YBtCEYYOm7E1x3y3ujWJJeWqCN2i GFEFze249Cd7ywv7j9xd8syDWnLvEPfyNFzBgU7l6yCeOEjqsYJ1msP2727ulv1La1BQUGxDmofRq IPUJfx+L6mItP+Lvx/rL3MQHxkZr4V7JwEO3M9fo0EoLzfw2fp3Ozyz43AgtXD+E92LJIigRW2UOr qerIi99vi9WtquPUze+Q==; 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 1h8Ii5-00048I-3j; Mon, 25 Mar 2019 06:03:49 +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 1h8Ihx-000430-2g for linux-arm-kernel@lists.infradead.org; Mon, 25 Mar 2019 06:03:47 +0000 Received: by mail-pf1-x444.google.com with SMTP id c207so5600947pfc.7 for ; Sun, 24 Mar 2019 23:03:40 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=rgWDXyitkPfkOwvJZbjg9H8+KzeLJbUpGMI+NATW6JM=; b=o7Q8LOBMw1DMmvh2FQtEPxvk2VrhyZpW2Djdn/MEPusKFoQxLORfh2u1h5c2mzM+Nv XB7ANjW7dtonG+JfBPa30RrRBPCjuz8V1yjpweC/M6O7gK3kUeSl/j9WnbVOGQmmDblA la4HDSEdB4BVqtSG/0aWx5S0QfuKbxfj2AxX7ecA5PRQwdzpBm69fdxTNlE8BhQXOP5r Dprh830R5tYwYKeFTQm24Q69ZLNsZ28oJVWQM7SKCXSDv4GO98z9FBY98tYR5BtoMhzl Hkg4gQhFqYGjxgmlVUmSwMTC8hSZx+tsimw82JrvCg4Sng/45lecLfj/MJfG+gUg/H8j gMdg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=rgWDXyitkPfkOwvJZbjg9H8+KzeLJbUpGMI+NATW6JM=; b=c2amvlY7aMwYyR5nso71+zup/G8r2SjvLk/+QS46pJpyLavERvEsFdGcMvEDTixRT3 M2f32n1bezd6WmolKtRRDfyTONCQPBhLaql6NiDSvusvY3nH5QAQvVqi2BA6BmInO2/y Lr1L1mnk51WpqLrTRb3BRFBi/unkJBshVnWQOtoIJFFQyqB90qWnE/jJ3Umdh3gUtHhP +gqvKT6ai+ymDkuICYuOw9M4DQdAYO1w2dKplSHPQe0KXVKbyGeVOEMDnmlZ09MQUVCK mv3axPECnJLLXOgATyt6AwxCfQuzaMI/LGeCc3n+clpAsRmxkoc7HrIhLwl84nx0RYA6 ITIA== X-Gm-Message-State: APjAAAVQq/PAo5X7yMmpdI+qopRrkjfJvqfd01DNEqSrhLCU0Jd/3Xf+ psSRhSJW33MPK9XVQSJeY28= X-Google-Smtp-Source: APXvYqwJHxRiKAOreV/2XbIRIK5zC0Oj8txemDUjqCdl8WYAyZoWteeMw82eWzU5s3uS6Ulj31Wgeg== X-Received: by 2002:a63:ff1d:: with SMTP id k29mr22089186pgi.258.1553493820509; Sun, 24 Mar 2019 23:03:40 -0700 (PDT) Received: from localhost.localdomain ([2001:268:c0a5:e068:c70:4af9:86e2:2]) by smtp.gmail.com with ESMTPSA id s4sm16610875pgp.89.2019.03.24.23.03.33 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Sun, 24 Mar 2019 23:03:40 -0700 (PDT) From: William Breathitt Gray To: linus.walleij@linaro.org, bgolaszewski@baylibre.com Subject: [PATCH v11 05/11] gpio: gpio-mm: Utilize for_each_set_clump8 macro Date: Mon, 25 Mar 2019 15:04:35 +0900 Message-Id: <72cd757e67c1f4651a0066f25f142080b4501f13.1553492741.git.vilhelm.gray@gmail.com> X-Mailer: git-send-email 2.21.0 In-Reply-To: References: MIME-Version: 1.0 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20190324_230341_331426_7CBA4216 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:04:54 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: William Breathitt Gray X-Patchwork-Id: 10867935 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 85D8813B5 for ; Mon, 25 Mar 2019 06:04:18 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 6DA4329085 for ; Mon, 25 Mar 2019 06:04:18 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 5F2B92908E; Mon, 25 Mar 2019 06:04:18 +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 F358A29085 for ; Mon, 25 Mar 2019 06:04: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=aFOyVg51VmvjMddDtCmCNUdEzDTDp6zBLLKchh5tJDo=; b=EkeaDisYqSQ4F8 Mi0RiN12evGUAgA+C5SGVgoQ57gdQiycU9YbbXmDMCjTNu/KCDbxDvu3oG0dlxljLXpMXvnCqGlU7 RX2Icp0cKUg/0RJ3kMv85sMfZgaXg5jjsotQKf8mow0HvJOW4W4h9H/25C8FLGdLMhVSSMS3N+XVV MTBEvd6lLjgouoVW4Oz/TgWziB5K5In4wD578yPqeCfIt3fGpmr8+vvl75iwhynaXFW7glcfefd5Y Lu1M8BTZ0pV3aExdEFeiWC1QDmlBl6ciTAJAUA+P6y0yZTUjvRPrD2UtoSTe7urFRGjM1reZ/Irq8 g+Q4S0NhdCP6KTOZGQbQ==; 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 1h8IiQ-0004Te-RH; Mon, 25 Mar 2019 06:04:10 +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 1h8IiI-0004P5-NK for linux-arm-kernel@lists.infradead.org; Mon, 25 Mar 2019 06:04:07 +0000 Received: by mail-pf1-x441.google.com with SMTP id i17so5606334pfo.6 for ; Sun, 24 Mar 2019 23:04:02 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=JhQ28KZcd91XNKjTCGWYQ1G7G3aiOZwynfHwUrGcvPU=; b=UKDCmV880Ib+0mSZI487ICH1lhL+8Y7B9pfFY93mw9KhNqWmu1SkkHSCYV4ymyXwMS Zd2srRA95lCFo7nqx4KXNImPOvkbxd18ddCM92SWYwefyEJOuP9q2im4UOUvnEdSGjgc upekYpbjj/OI+DfCycs2qnrmbXNzle8jU65dthVcI5N5BSwlVQwOVAxTM1NKSELGK50S ORfN0aNNWGu1nbEH2jZo+UUGzt8kvZN0mlv71U+FYobl80fPSyPfM9FQTu+sNH0fIwVo WQkmAS87B3Mc8LBGe+iGfj+bSH5d/iYVRzbflHWDPI8QwqplccMtV8Pbh1ETnYb97VkK n09w== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=JhQ28KZcd91XNKjTCGWYQ1G7G3aiOZwynfHwUrGcvPU=; b=mAwBCKMUaFQytObGWBjSWR8/2tbuY8demR6dHJo4DqiwETgVbHMqv5C+mTHgbRGjfI OyCQSHuMRlegQmtuWCkW7t4gdlN4C+eDWHaVE7FY2yM415DP01KLcdMHJIQJmKwSxWe0 LmxSX7PwucwAeuC25vEnJyYHwymHv9d7yX1Yy4hcsiuOC/akTIQMaTUe3NIodM3FLhPy qnkBGCyM/KansvoRAGYzeMk7PJ34m8j27gvj6N3fmcXC3qa1SgUS75jckWxFLAdHgphC WAUr/UBA+Tg0282otHd9+QyOrXPZf9DrdG2GF8ViK+nYsvTouM9ZiJxjEhRgi6weJD/d gJrg== X-Gm-Message-State: APjAAAXpLZIWIS2/1Eh+RQjkaCPQCise1VjewvFv57RiuzylRFAE0XKs oItMOKtRkaRTmsJzMhtxif0= X-Google-Smtp-Source: APXvYqz6b4Z+uH5QudnEyELTjtjeKxo6PAfrZgYc1QQLZX2IAinJV8EwccTFTKX01X+cJFZ3+Urb6w== X-Received: by 2002:aa7:938b:: with SMTP id t11mr15219939pfe.67.1553493842170; Sun, 24 Mar 2019 23:04:02 -0700 (PDT) Received: from localhost.localdomain ([2001:268:c0a5:e068:c70:4af9:86e2:2]) by smtp.gmail.com with ESMTPSA id y12sm4568022pgq.64.2019.03.24.23.03.54 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Sun, 24 Mar 2019 23:04:01 -0700 (PDT) From: William Breathitt Gray To: linus.walleij@linaro.org, bgolaszewski@baylibre.com Subject: [PATCH v11 06/11] gpio: ws16c48: Utilize for_each_set_clump8 macro Date: Mon, 25 Mar 2019 15:04:54 +0900 Message-Id: <186e263055b327f3333677db67f0ac4a3b428def.1553492741.git.vilhelm.gray@gmail.com> X-Mailer: git-send-email 2.21.0 In-Reply-To: References: MIME-Version: 1.0 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20190324_230402_860348_B0C3DBC9 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:05:16 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: William Breathitt Gray X-Patchwork-Id: 10867939 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 5E95913B5 for ; Mon, 25 Mar 2019 06:04:50 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 4617D29195 for ; Mon, 25 Mar 2019 06:04:50 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 3A4BE29199; Mon, 25 Mar 2019 06:04:50 +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 D102229198 for ; Mon, 25 Mar 2019 06:04:49 +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=Vg5FF7EgoERTxy dG2473BWlDfc6+KEUq+GlZWfgGQZbjatc+qg5tzQwxsmsrWrNWRpcyN0+/JGfS0f2La7x1pcLWWXH gU8P5JPC+fAeos2Li28X1ftfUdD7fbF0eTJrgHUKDzSorsjWZEueu5EsA/STHbd/HlHqcLNb783G+ K01NBW5XfwFjnGyqpbCtwJpNaNfgj1ct2SWol6hZxv4VhTfpnGpwfOUSJUbLMMykSi5A5oC2XNDUH UzHqCBVhbg7rQdzUat7KxVe4xkLECtez4XCjeYECvtTv6VPMqd3bmmfIjk2YtA/FPfhoo+M1FnYo6 V/yfSzSsel+D4pL8Se0Q==; 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 1h8Iiw-0004l1-7D; Mon, 25 Mar 2019 06:04:42 +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 1h8Iim-0004k6-Jv for linux-arm-kernel@lists.infradead.org; Mon, 25 Mar 2019 06:04:38 +0000 Received: by mail-pg1-x542.google.com with SMTP id a22so5688440pgg.13 for ; Sun, 24 Mar 2019 23:04:32 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=LbAhFB9V6BisOLUTsbpvSet6qgSjh9MdQ4kQbff2Dwk=; b=PwqVKKMSGSxhxKN7Au2TB+BzoEmcE1w/jEZtrJlYLBGEwmz8ULf1pWG2j0/LGWtovG wx4eXyQSQwq3ug9iJZBsR1DK7AX3QxX7UlVBxvj2pcHTN/iXP+JWox901huyuvzIKAPG 7l8OWVureNvuYpp+I80NJ126AWSOgoNGGsM543rdnmQHDNLOtEg8p3COaoOkiNr3vRBj CM1nkINpm+NbjujgsyETGdbbDLQ8mJ457BBphNBAZSJzNJJv+V342cog8bfNktDtvggh eqKkNH8/CaJ6tFg6B5QXJxrQse8S/kBOOpRyFKEAj2IvKgTg6MKKa77vtpTif8vL+MQP vS9w== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=LbAhFB9V6BisOLUTsbpvSet6qgSjh9MdQ4kQbff2Dwk=; b=qmIxGBRpJrWOg+kt+W57TqkqT641MOGJ0nu/VA+O4Af57bKjNajvYSg04IIiQPkLz9 KJGOKmgpnw6j1cZBeM+pAx1icK9g9YbWqsTEmqVQg57QY0zgBJDdz6+l6S+xmt8GkSfe BMzneNqO93o/X77w1en8MeioR7hEWVGeiYQ9+d78xiaw2NsG/z3sHrmRTnZWWbAkv3O+ Fys+FMebYFRhhPlseb2UN544H07vCePXpbdFTfRaTbH8J3aAamC0XAEfp/sIWsE+dUNA meKXQlSksuS3CQ9khamug9gBJAQXtZCTO0NAogeJUXVT0fnY7bjWyojW464631jkEf1P xsog== X-Gm-Message-State: APjAAAUC0Fa20UHAd+qEKD5NOoJk/cQ1X7Ucf3NFIQp80PvhiAByt+X+ C2UiKifaRwpPTMrrcTxRCsU= X-Google-Smtp-Source: APXvYqxGtFKQhfIms0S4Sx0CIXZrTI1OK0EqTLcruiRSdqQwPUA55C8iFjdr/u+iHjpmJTXjtVpVtg== X-Received: by 2002:a17:902:76c1:: with SMTP id j1mr21210416plt.224.1553493872149; Sun, 24 Mar 2019 23:04:32 -0700 (PDT) Received: from localhost.localdomain ([2001:268:c0a5:e068:c70:4af9:86e2:2]) by smtp.gmail.com with ESMTPSA id m67sm21403332pfj.70.2019.03.24.23.04.26 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Sun, 24 Mar 2019 23:04:31 -0700 (PDT) From: William Breathitt Gray To: linus.walleij@linaro.org, bgolaszewski@baylibre.com Subject: [PATCH v11 07/11] gpio: pci-idio-16: Utilize for_each_set_clump8 macro Date: Mon, 25 Mar 2019 15:05:16 +0900 Message-Id: <4405d4ee08f03855d5884f89e834c6f1c88b26bf.1553492741.git.vilhelm.gray@gmail.com> X-Mailer: git-send-email 2.21.0 In-Reply-To: References: MIME-Version: 1.0 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20190324_230432_738386_FE38458C 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:05:46 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: William Breathitt Gray X-Patchwork-Id: 10867943 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 77BA3139A for ; Mon, 25 Mar 2019 06:05:14 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 5B12429195 for ; Mon, 25 Mar 2019 06:05:14 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 4A6F529199; Mon, 25 Mar 2019 06:05:14 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-5.2 required=2.0 tests=BAYES_00,DKIM_ADSP_CUSTOM_MED, DKIM_SIGNED,DKIM_VALID,FREEMAIL_FROM,MAILING_LIST_MULTI,RCVD_IN_DNSWL_MED autolearn=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 C4C3829195 for ; Mon, 25 Mar 2019 06:05:13 +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=krNCLGBDyveEMa IeEZOIVo7bu4JzdqSFaNErAnZmU22lznuur4WCrR7b9Cxc3np/Me+JsGX7tDjSfSdStHRE+tFDT/3 LbKGFm2XMXnas7lZpAc97e5p4sbImOlmj19hoXolX93R2ZFN6Lv7V/HlJdcoeKJtc8DxZtCW9f0rj cd4/RreZ0dvERHXi9i2PCb4USXW6KObxV6yX58NosxK7V4W5URLPdPYht7uMW1HUF2eA09043O1BE /M4ndOEK21xLxqbsswsfPvl64lZi40JlBn4xN0Jj5UcBWRoP2YxiqtNrlUL3DvUDzJXxyRs4TSlDk EFuuTMZ8PqfUZEkqebsA==; 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 1h8IjH-000531-EM; Mon, 25 Mar 2019 06:05:03 +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 1h8Ij9-0004zf-OR for linux-arm-kernel@lists.infradead.org; Mon, 25 Mar 2019 06:05:01 +0000 Received: by mail-pf1-x442.google.com with SMTP id 9so5581062pfj.13 for ; Sun, 24 Mar 2019 23:04:55 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=lo/y4LVrDbirngV8ZQJtGQjH8jQRyE53ymUz3wq08xM=; b=ryg5WfZWRCdggnxmMinSCT4uHdXW9ujOrE7WO/i/SiuGIeLNk/0H06mUkmn59gDYBA tCqEAXoZMemt9Zu8uZMqr52y54hDldz5qH3NggOsK1at1mavOdgS1y12kBuy770StvVK aSc/8mh+9FYkY9XRcQY70nRInfP/4aMDk7Ss5zDiLtS1MKNY5IvnqYBRTCjq6a/bIKI4 Z4C8lj6K8R4JY8pONH1PKNRP7OwDF+uFBIyHlpgas9ZlvYwKwXW+pTUrmDPi0dIFflu3 zL4TOJm9dqwyyALNQmSzdUy1Q34nELpiRO6nA/Tx8l2munD1npTqS6gUbjW/cLq6B3Kz 8OuA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=lo/y4LVrDbirngV8ZQJtGQjH8jQRyE53ymUz3wq08xM=; b=Pt1psXwjnjYWk6dCLV8bj7y6H/wxK8w1/SM3LdSRZKJnU+wcJ2NK4FkynXZYXKKDD7 7Gs8ODfLVhVIs+KpOQ851p5meSKaPSYCXg58Jdbsl98r6VEDt3Y8yXmT/97Sx57/ga3J tJRfSUJY+AktDKd2RTwnCsq2Z9X1Tvdu1Wi/IC5k9VvsbJYDudri6W+5S2MZuaBat6O+ ABal6brFrFtMjbKS30/FcZD7eUxFEHazMzongUXfCX+4RJ9UCfbQLXWGSmF/JY8VHdq+ hKTAMBEbxu1LaD4jmJjOL7Vq+eJFkb8fI0o3NG7kUdFjc8jGuuYsovAGOCDZS+NNdJe1 1WUA== X-Gm-Message-State: APjAAAXFVia5iwOT/hi6YCIuTldez44wpaIrtyVrO8ekoC4+oTbeD/3f v9rloKqhm2GzDOsoCnyQmbA= X-Google-Smtp-Source: APXvYqzFhzHd2Jxz0COAG4rEDOkX/DQLp/PHNeDIqAzJs9KxeLlCrjKi73Y0vhgkOcYbZfwwQoCyqA== X-Received: by 2002:a17:902:6a89:: with SMTP id n9mr22786402plk.223.1553493895062; Sun, 24 Mar 2019 23:04:55 -0700 (PDT) Received: from localhost.localdomain ([2001:268:c0a5:e068:c70:4af9:86e2:2]) by smtp.gmail.com with ESMTPSA id s4sm16613629pgp.89.2019.03.24.23.04.44 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Sun, 24 Mar 2019 23:04:54 -0700 (PDT) From: William Breathitt Gray To: linus.walleij@linaro.org, bgolaszewski@baylibre.com Subject: [PATCH v11 08/11] gpio: pcie-idio-24: Utilize for_each_set_clump8 macro Date: Mon, 25 Mar 2019 15:05:46 +0900 Message-Id: X-Mailer: git-send-email 2.21.0 In-Reply-To: References: MIME-Version: 1.0 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20190324_230455_818704_C7D247DF 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:06:09 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: William Breathitt Gray X-Patchwork-Id: 10867947 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 927921390 for ; Mon, 25 Mar 2019 06:05:23 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 7A94B29195 for ; Mon, 25 Mar 2019 06:05:23 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 6EA2D29199; Mon, 25 Mar 2019 06:05:23 +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 01B1329195 for ; Mon, 25 Mar 2019 06:05:23 +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=oi7oKz5G0tDfnB gibLnCyAs1jBlycuXwbwqBMc6nz5RMsPn4KEw5mNgLq9n7j+K06YuJFzdVm20pokTsDXSr1nXyTm6 2iamgBuqv62CpLDPs3fWMLo1CP1GlllwsBlO6ZAPgqcGqIlgpARfNmQqPO/ptPxrvv1x2/8oy0nR3 kANaCkMdm1JJzVhFR6shdYknDIP9IjPJCMLcz8bPc7IpuVJpMATNg1XrXAu2hOAxFKsrCGj3qOwNf h6xIK0UxLnUNuMfpHhIjcEalp7fDFY1bJKr0Rffe4dKWjvYGA94opsD8rXCwbjHEdkMIVVp+LbMD/ JAW4f0No0O0O5IpxPByA==; 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 1h8IjZ-0006TO-Kw; Mon, 25 Mar 2019 06:05:21 +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 1h8IjR-00069h-HJ for linux-arm-kernel@lists.infradead.org; Mon, 25 Mar 2019 06:05:19 +0000 Received: by mail-pf1-x441.google.com with SMTP id 188so156327pfd.8 for ; Sun, 24 Mar 2019 23:05:13 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=UifkzEkFRqXu3yixaaw6yvTChu7M21y6ZQxvlg1zFMs=; b=cUZivDN2YWWNLkTIYSS6FpIHofsi9nxbjKjplH5GCWNdwnLqzZLYIHVzd0DMyNb/0F JfvRjZ39ub+vB+JlNnJEulAXTcC7kJCoZXroxbm64jTDrNDOr/ZgrG98g6gkXJeJ7dkF n8ZCBvTgQUvXlBy7f2DZvi3loBxuDWodB8DoWyK2LWYGThL5u6qi8s1mFYVG75RKASyQ +VmBfU5mpq0ZYbg76cUhEA3lB5K2OxKme606WKXH2PdIjwEOFJtgY1Pe07L3eicxIHYT OpZqL7ktiWVKWd21K2HYs/5QGn0TPruxFiaY2p2PiFcALREQNBY91tY39orS71lN5eku w27Q== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=UifkzEkFRqXu3yixaaw6yvTChu7M21y6ZQxvlg1zFMs=; b=ACsWWVc0kHPyJTdxX78k/x2kQI8pDVSG8/foNERxHLh2/70PK/CyPRhLFq5/46FuB9 /AJuHY2/cgtcggieiFayI0x24vWNpxI21PbOMi0Yqmvg89bf+DgdK7qSnT5SEB20Z71q F+ul/aqk/aEDCRNkuh3b5bc5zji92Ky38RPU4koY4mOlejnsZkBNNe6TlS4xRPX0VVVI E24pUn5Dc34e15Pfjo/De99UFFnCyZnHIvcE6W5MUMEb8Cg5AdAznEi2EL0iedIyJUlD P3TlgZCUrHRCxeXZFIv9nNA+IhVVAOsMkGxL5fCHB2hW9LzGnIa3HO8QwryET+Y/YaAG 9AVg== X-Gm-Message-State: APjAAAXu6BX19lr+KxWyqcJMw/pYCbbaXxAS5E1HGAWHKxBXebrh7cEX 4QxkvLk317EY1HzriMRo/jo= X-Google-Smtp-Source: APXvYqwW/zp/Q8To3dpTdoxUCtqXaOHNaAgv7+rJZJtMlrJQoCPCu3MGz2qZUjdACT3vJv1BfuwrqA== X-Received: by 2002:a17:902:121:: with SMTP id 30mr23719883plb.315.1553493913056; Sun, 24 Mar 2019 23:05:13 -0700 (PDT) Received: from localhost.localdomain ([2001:268:c0a5:e068:c70:4af9:86e2:2]) by smtp.gmail.com with ESMTPSA id w123sm21668681pfw.72.2019.03.24.23.05.08 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Sun, 24 Mar 2019 23:05:12 -0700 (PDT) From: William Breathitt Gray To: linus.walleij@linaro.org, bgolaszewski@baylibre.com Subject: [PATCH v11 09/11] gpio: uniphier: Utilize for_each_set_clump8 macro Date: Mon, 25 Mar 2019 15:06:09 +0900 Message-Id: <82b21a3c4f84bad98487c450a8b3072ecf1c44c3.1553492741.git.vilhelm.gray@gmail.com> X-Mailer: git-send-email 2.21.0 In-Reply-To: References: MIME-Version: 1.0 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20190324_230514_137326_4D3E9137 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:06:28 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: William Breathitt Gray X-Patchwork-Id: 10867953 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 4113B1390 for ; Mon, 25 Mar 2019 06:06:22 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 2908228567 for ; Mon, 25 Mar 2019 06:06:22 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 1C9AE291D4; Mon, 25 Mar 2019 06:06: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 A458D28567 for ; Mon, 25 Mar 2019 06:06: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=jFi9yYjYCuRYtRrrijvCVZWQoWGZRwBrITLNoL+tBjc=; b=cJZVNScTTEnxPr jbSLUcuPrl7I/VVH2YctTD4sl1zjZ7SwWKSxHdfkWl0lpaJDveULrj1uXl7Fq4wZ1Yb4dodF0d6Bu wfiz+oLrqNOlQuVC+VrnF0+f/apHdy9k26Vad62goouB3H+vdPlai5KJK9tFVpqhYXhtEtyVLP2Dv zu/N0LwvDMcUkBtfXSJHql1jirlhrYQfmZGsPtrZwf+6zc6I11UYKPoiDzxrASkhAX2tGlm9+uHCq b4yhVVa0ORtGHKSV7laJ13urioFgA1RgYpW8cY4y0bOq/k/PwRrI8vUPSmWO7DmIz0M1zhUzr2z0A MvwXcZbdpflJpKjpAwGQ==; 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 1h8IkE-0007JN-QX; Mon, 25 Mar 2019 06:06:02 +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 1h8Ijm-0006lz-7y for linux-arm-kernel@lists.infradead.org; Mon, 25 Mar 2019 06:05:47 +0000 Received: by mail-pg1-x542.google.com with SMTP id y3so5700051pgk.12 for ; Sun, 24 Mar 2019 23:05: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=o+xpStCAm5+KqB9WkdPQRn7Ir+DpSVJA0QLNqt7/oEw=; b=Q28Sq2XUEgcaTJcwxxckkZWKTAytkpVpdRls9LHOvD9lQskNxUADGQcPDfb54E4ZUf 1t4clNC9Nc/Wd8MSgpv/CmsfyGkFH1/gwwXcmxq1mAXx96SoA8dSnqHBGCGbxYavIIka UNBnAJ6GUnLyB2qGA2IlqbML1y0mEwdGTB/bIocp78FLPTT3KycCziysUxYojSIarv+e d4npvK249GckLUYus0xv8xLBCb+TqsbkRrMGcNha3OKwRuoprMh+Gl9oQsHmiyAMeELR rsFi+D6gBoM+7DifiHl0uC6JOoiUmZ4aUa9pa7k1KHhdCuhOronP3JzUftAxLPO1dP7w nj8Q== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=o+xpStCAm5+KqB9WkdPQRn7Ir+DpSVJA0QLNqt7/oEw=; b=HVpHH/l/V9KFOYuPx+tl8XN0PjgESPQj6Poqc1nBxHBebkxlU84zfw74tLPT4alFob Up54NyrSzD6y2HmfJn+zPTK5vLKU1KWwzJxaFv+aR/tq5tusl1NPXpeYkDOCgM2BMECF FuyXS5bq3R9g3hzUUFkiB6TKk0UkKHj/z6QtpSZem3nuURYQ0YrzG3uJlDBLG9Zr957s m8LixwvKfyXcT10rBBDd1jWoO7oKTmCA5ksZ1o9tTgheCvf4RxGpekpj7MsEZgdhxgqg Op1tVSnnSD5HrCBF4ZGdJn5+rY7afxpge63Bi9yUNYB/1ZxLifN89nIplPDu1FsOZk09 +7yA== X-Gm-Message-State: APjAAAV1AkzsON4Zp1C3sMTSLAWUHnIwRNGskev5VKyzNh+tblvzJ3tf L/akxZ6pJ4AEU4HHkZBonUk= X-Google-Smtp-Source: APXvYqzMSY3gRxBRSywfQidmG96EAN7QjCHLwLjuGUdsN7BrTElN8NIefTvVxBsheUxWhV3wYBCNmw== X-Received: by 2002:aa7:8ad4:: with SMTP id b20mr15624226pfd.249.1553493933529; Sun, 24 Mar 2019 23:05:33 -0700 (PDT) Received: from localhost.localdomain ([2001:268:c0a5:e068:c70:4af9:86e2:2]) by smtp.gmail.com with ESMTPSA id m24sm16401479pgv.1.2019.03.24.23.05.27 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Sun, 24 Mar 2019 23:05:33 -0700 (PDT) From: William Breathitt Gray To: linus.walleij@linaro.org, bgolaszewski@baylibre.com Subject: [PATCH v11 10/11] thermal: intel: intel_soc_dts_iosf: Utilize for_each_set_clump8 macro Date: Mon, 25 Mar 2019 15:06:28 +0900 Message-Id: <02ebb522c3c07e9ed13b8e07559abd17e8648987.1553492741.git.vilhelm.gray@gmail.com> X-Mailer: git-send-email 2.21.0 In-Reply-To: References: MIME-Version: 1.0 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20190324_230534_300190_C9F656E7 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:06:47 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: William Breathitt Gray X-Patchwork-Id: 10867955 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 C61B61390 for ; Mon, 25 Mar 2019 06:06:31 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id AECEF28567 for ; Mon, 25 Mar 2019 06:06:31 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id A2700291D4; Mon, 25 Mar 2019 06:06:31 +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 3DFDE28567 for ; Mon, 25 Mar 2019 06:06: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=axzlx/Ik2uzhXbcP42ilqfckjYdzlE9ebOg0xAU2kbQ=; b=cpo/CBQrGreKZx RSDDuAgKjZ+l/ZmDWqbPb501JQJeC8Wg1n8z8mmnnB65J5VYTznrTD9LHvUD3PbbVIxneBcCs0DLd +ZtS0d9Cz82pPCvZutS9hJppeCem9w9vrDQN3tvy5FElAhUWVQZXZ7MRMOcq+N3FxTSAXnf3JSgxk y/UzqmrMtdcz+YjxoSWELLMt+kbtI262pS7n+/jUfxqS0uljyz9AWgqbx1eDrnffrjc1+TQlCpsh0 yF+pV8DawxIPgT7TOf3ajRXv4yZqfSTSL85S8/T2W8nrCQCjfrRE958qh97r/UTYgRMFSbpvuuXCG TjH/YtCkHjHC8a8yIeeg==; 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 1h8IkY-0007cC-RJ; Mon, 25 Mar 2019 06:06:22 +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 1h8Ik8-0007BU-C9 for linux-arm-kernel@lists.infradead.org; Mon, 25 Mar 2019 06:06:20 +0000 Received: by mail-pf1-x441.google.com with SMTP id c8so5595788pfd.10 for ; Sun, 24 Mar 2019 23:05:56 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=p6jZFM4uKZmmd8N/chkful+ZD8FsiAd/9uwJICIJ0zk=; b=jqumGuL+igo/SkIi2aID93fjdQzDHtjSSvtucpTKc92SzXwZT4k5G+kymX27UTh541 d0B+WYVS4FKTQFfwoolGxbR8dwqIp+3BE/22l0q2wEDoOxsBxqqae8QyqJycRidrZWI0 ACclu19uKMz4gcTlU873cG9+xs1K+5DGzeLcxzYRRwbxkiXAnZ1Lq/KZMdGvRkG4cNJN hwGvJWSx6fTXA39+0VSWWwTmjUnRT4s/NU3g4i/tfiLCQiOb99NVKOA1mvnwRHS+PjyG C0I1Kg8eizZA/SJrgWlrKs68LwenOWrg7n1bS87ydxx0jrwZZnNZmYX1YwHxV6xwzLp1 75tQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=p6jZFM4uKZmmd8N/chkful+ZD8FsiAd/9uwJICIJ0zk=; b=unf+JVYvL0aAXkHDh8wYvK7nA2wFBS/CYCkfwPdSs30bTKBA+qR/o7WXbNDti9YcSG 0UAubUqj+fv5G6K7L8d7Awe/niL3KNK2EXVHvGBbHHU8TC9FPI2hT8PBr9a7Nh3723aO h1Tenm03TnITJcCKin+KRfVQzETaRVB/P6lO2k7IQMJkSHqeSoPXoOLrTdSvKhAddtin K1EmvwiSWP2+NDkwLwqVQrokazJqgWU3tTxpBzukZYAGI4Eye5/aAkK3IBlwA0ReqeWS xmlCI87D07+D+sqOP9I/rE8A9WmQYM6SyA1tQ5M4tswrF+Fu3SKe9NQzwu+yS6y2R1Nq 4CAg== X-Gm-Message-State: APjAAAXPKPjg8v2d6MrfrdqmmY8/lr35yrjCBfMmPpnIQPKhQinfPNFd 6o8SHAmVb6aOiZScGvo75oA= X-Google-Smtp-Source: APXvYqwDxykQkjuOKa1oZBlXM1NHkyoBvXV+7ZgKvU3Rmy/U4UOsNXSh3i4l6XjRsDUy5ImRcJfMow== X-Received: by 2002:a17:902:282b:: with SMTP id e40mr23266401plb.111.1553493953557; Sun, 24 Mar 2019 23:05:53 -0700 (PDT) Received: from localhost.localdomain ([2001:268:c0a5:e068:c70:4af9:86e2:2]) by smtp.gmail.com with ESMTPSA id k22sm20299064pfi.90.2019.03.24.23.05.46 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Sun, 24 Mar 2019 23:05:53 -0700 (PDT) From: William Breathitt Gray To: linus.walleij@linaro.org, bgolaszewski@baylibre.com Subject: [PATCH v11 11/11] gpio: 74x164: Utilize the for_each_set_clump8 macro Date: Mon, 25 Mar 2019 15:06:47 +0900 Message-Id: <8a2e010aa62e00e1fd56802d6c842ae972d2f283.1553492741.git.vilhelm.gray@gmail.com> X-Mailer: git-send-email 2.21.0 In-Reply-To: References: MIME-Version: 1.0 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20190324_230556_732779_02871D96 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);