From patchwork Fri Mar 29 03:04:08 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: 10876237 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 D34561669 for ; Fri, 29 Mar 2019 03:03:24 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id B94F02909E for ; Fri, 29 Mar 2019 03:03:24 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id ADA40290A2; Fri, 29 Mar 2019 03:03:24 +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 49E2C2909E for ; Fri, 29 Mar 2019 03:03:24 +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=PTBWLxK3JkdnZXrWCRMQaL69IpxnSv926xa+6EYuhJU=; b=mYNS08oOUxwV5d lJaEi4Er9ntRC5wXlnvDBK19BnZ2l+Fcc6Gmx+0xEy/kktwRsk3dYgnDNTJTENhcY/8cd3kd77j5Z BpsYHvI1t7NCRWKRj3WYPlIXn2kBx1ZSZkTHpbyzrNwtRLZKiZpU4iwWB0N3xY3CeGxiwBNOR0GNF /VFTVNDzV7DylN0LDMlksYwULqRfHmiLc2ycj6IcxU4HSjkQXanAq9mncUqFxrrUi5YFr1bXyO10l tbQYixVubwHxEGZAlanCSuGwaFW/GkmkiSjOhI+XB2yT3a8pPrB0xMZ6XJ/tiAIwFUk/ntd8qdjEM 39jPUiMoQmyUk+INXeMg==; 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 1h9hnZ-0001mM-Oz; Fri, 29 Mar 2019 03:03:17 +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 1h9hnV-0001hn-GG for linux-arm-kernel@lists.infradead.org; Fri, 29 Mar 2019 03:03:16 +0000 Received: by mail-pf1-x443.google.com with SMTP id c207so329993pfc.7 for ; Thu, 28 Mar 2019 20:03: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=K34goq+zf1vvl+0PBwq115Mp4iHOPY/zupPfI+vUQAE=; b=V5Efa6TNudb05BAu+jsft37SCTSyK3Nz05lSgABhwTr9dPRAszIcUwdt+nYaBN1YUq nnkABvG5YB0g+mbL+H4YOeXLTLMWVfra7pf9w1hi3tgYPFOqdXEq4YgMudGJ6RXlcPIn 5c+GFggYuTno7DCS2U+hdFm9EvEUaH7glYeCT87Mm6zWAm+wbuFqKOQp8QmPPHFR3Etw 83TK9UyeSc17lP/TJB+beQzngcxHo6eJ/qlRplHyCLTz7Z2R419iblqcXAX+iG+2EMiy KqpBpTbVsPCTTxQ0ISWh3jNC/Q2NdMlQjPmN3vqJPH4nLlS4MCIiDiRrUSZCGIkMxsuG EE/w== 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=K34goq+zf1vvl+0PBwq115Mp4iHOPY/zupPfI+vUQAE=; b=PTEO2MPp0YfuZchAm3KxdzbCbv89iIQtbwdTgbFeejFSIhIwm7QZAGW0QQfRzi5pN0 1zUluCBZYMKU5Si0GTo3GxralD3xs3ibR2gXJ97ToGeah4+B6DYwhvqLBbJ1SQ70iGiO JPgIMHDhc6Ba4joiBKVQ6NQEsR29RnFy69gDkClh/VlhbgmwcX5zNM/yYKTjM03RNdxS WVUBsgVwHN0SqH8IMtjKMLK18SECpnYfORqYY+00+HfZXNVtHcvRfjKqkOnR++oENNGG 5XLP+HAJ/EmGbGZtheq1FOs0WsCk/cSQ+BWAL00yhFABOiSArH/ke2nSrp/IjnlfeGX7 qbuQ== X-Gm-Message-State: APjAAAV4BE4OxwYWZkCnjqlDK9bgLvRe+Qe7A3KwOXVYKj/IOIxdUi1e OpEbYLVE3lR6l+LHVn1xXL4= X-Google-Smtp-Source: APXvYqyMfQEASrbwMcf+1MYodXZ4CyjTM5wNZZ2aZtGMR/8wEoFz1iHj6gTxqTHYRgJfKOFim8ijag== X-Received: by 2002:a65:4542:: with SMTP id x2mr42882493pgr.65.1553828592563; Thu, 28 Mar 2019 20:03:12 -0700 (PDT) Received: from localhost.localdomain ([2001:268:c0a5:ba2:c70:4af9:86e2:2]) by smtp.gmail.com with ESMTPSA id x9sm730532pfn.60.2019.03.28.20.03.05 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Thu, 28 Mar 2019 20:03:11 -0700 (PDT) From: William Breathitt Gray To: linus.walleij@linaro.org, bgolaszewski@baylibre.com Subject: [PATCH v14 01/11] bitops: Introduce the for_each_set_clump8 macro Date: Fri, 29 Mar 2019 12:04:08 +0900 Message-Id: <1cc8b30bb3954ca2a0961ffb0a2eed8a005ed670.1553828158.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-20190328_200313_812397_8D11B041 X-CRM114-Status: GOOD ( 13.67 ) 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 , lukas@wunner.de, 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 Suggested-by: Lukas Wunner Cc: Arnd Bergmann Cc: Andrew Morton Cc: Linus Walleij Acked-by: Andy Shevchenko Signed-off-by: William Breathitt Gray Reviewed-by: Linus Walleij --- include/asm-generic/bitops/find.h | 61 +++++++++++++++++++++++++++++++ include/linux/bitops.h | 5 +++ 2 files changed, 66 insertions(+) diff --git a/include/asm-generic/bitops/find.h b/include/asm-generic/bitops/find.h index 8a1ee10014de..45aa6d718cbd 100644 --- a/include/asm-generic/bitops/find.h +++ b/include/asm-generic/bitops/find.h @@ -80,4 +80,65 @@ extern unsigned long find_first_zero_bit(const unsigned long *addr, #endif /* CONFIG_GENERIC_FIND_FIRST_BIT */ +/** + * bitmap_get_value8 - get an 8-bit value within a memory region + * @addr: address to the bitmap memory region + * @start: bit offset of the 8-bit value; must be a multiple of 8 + * + * Returns the 8-bit value located at the @start bit offset within the @addr + * memory region. + */ +static inline unsigned long bitmap_get_value8(const unsigned long *addr, + unsigned long start) +{ + const size_t index = BIT_WORD(start); + const unsigned long offset = start % BITS_PER_LONG; + + return (addr[index] >> offset) & 0xFF; +} + +/** + * bitmap_set_value8 - set an 8-bit value within a memory region + * @addr: address to the bitmap memory region + * @value: the 8-bit value; values wider than 8 bits may clobber bitmap + * @start: bit offset of the 8-bit value; must be a multiple of 8 + */ +static inline void bitmap_set_value8(unsigned long *addr, unsigned long value, + unsigned long start) +{ + const size_t index = BIT_WORD(start); + const unsigned long offset = start % BITS_PER_LONG; + + addr[index] &= ~(0xFF << offset); + addr[index] |= value << offset; +} + +/** + * 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 + * @size: bitmap size in number of bits + * @offset: bit offset at which to start searching + * + * 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. + */ +static inline unsigned long find_next_clump8(unsigned long *clump, + const unsigned long *addr, + unsigned long size, + unsigned long offset) +{ + offset = find_next_bit(addr, size, offset); + if (offset == size) + return size; + + offset = round_down(offset, 8); + *clump = bitmap_get_value8(addr, offset); + + return offset; +} + +#define find_first_clump8(clump, bits, size) \ + find_next_clump8((clump), (bits), (size), 0) + #endif /*_ASM_GENERIC_BITOPS_FIND_H_ */ diff --git a/include/linux/bitops.h b/include/linux/bitops.h index 602af23b98c7..1d9b5efb9bd4 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), (size), (start) + 8)) + static inline int get_bitmask_order(unsigned int count) { int order; From patchwork Fri Mar 29 03:04:29 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: William Breathitt Gray X-Patchwork-Id: 10876241 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 5EA5D1669 for ; Fri, 29 Mar 2019 03:03:46 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 42C8D290A2 for ; Fri, 29 Mar 2019 03:03:46 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 32CBD290A6; Fri, 29 Mar 2019 03:03:46 +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 BE805290A2 for ; Fri, 29 Mar 2019 03:03:45 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20170209; h=Sender: Content-Transfer-Encoding:Content-Type:Cc:List-Subscribe:List-Help:List-Post: List-Archive:List-Unsubscribe:List-Id:MIME-Version:References:In-Reply-To: Message-Id:Date:Subject:To:From:Reply-To:Content-ID:Content-Description: Resent-Date:Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID: List-Owner; bh=NGjO61jJ+ZtHjMj7PjKydAZFMhP3fiH/iEzwOEbSN9s=; b=qaOYiW+9DlARMc qLqB9+zt/FqYHn36t1W5Zr4DKWYt5vvR1fp9NP+bmA+NcZQVjv2i8OmUMohfG834RiHKTQ5nv3+3C ZTWlF3QGaFtjP/CGtrrCpDjGP5ZbebC9lj1rvY82VGtOT8OVSvl0wOTO8oMTj0bgJzc6H+c0MKzW9 2+V9jMRlXBdZrGUxQkBKUpzMceYa5Bx1lmbH5WeklO46Qg1KOUmvT9jvajPqIfixS40pMmjI8XPZe F7sR9mcCs+2TMO+pHWTS79AorZxXqaZWdypCjXRS25VnaAqJakeMJ/eYl6K+iJkYL+n/VW6hemkLv KxR1Lwig49CH67l1nVFA==; 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 1h9hnu-000268-W7; Fri, 29 Mar 2019 03:03:39 +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 1h9hnp-00023t-Ax for linux-arm-kernel@lists.infradead.org; Fri, 29 Mar 2019 03:03:37 +0000 Received: by mail-pf1-x441.google.com with SMTP id 9so316205pfj.13 for ; Thu, 28 Mar 2019 20:03:33 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=voPjJIpaEIENDSX5D22rQL6GtMzeJ5e93HyvmN9lrck=; b=FKXQdVCGLKfyuSoq4WzfGFf4LnXnRbm0ysr/SlvDiJyZe/Nl+D36Hsae0YbkCkVsG3 m+9YesA8P/RUSsulN03LU0TzwVR8DoHNzGdpZ7HeJQYI5BUq7oSquF358f5TCKkYOHbo kUcboC8hcGiYM0Tg8HPWzdNnKys/fe1ds6Gjx4E6xrSmaSjSPjogHO0qonhz/y2gLCzU aqbHrb84iDCR/J/KaGCB2XdwxCUYuZ6pQkTgRYg42WKAMjCsWYUYvwzudFaMdMk+SkGb p22u+GluQzBr1BlnhEdSd/miGBihzcejoD03z8sIiEbz6ZN0UjBmPubm+4q507GEvvVi jo2w== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=voPjJIpaEIENDSX5D22rQL6GtMzeJ5e93HyvmN9lrck=; b=dghR0Mc1SqY89YZJ9+i0ufFZ0Kpdpwjarj8nHTDAtfQFCKI9p9kaiscJtQ1nYLuCPs p+7qOocoDp/LXRcMYkcKmS2Kjev9I1LGBx8cEoT7TrwrxgxKTXN7GElc0si/kiX5+blE qV7DBLg5A+bmdcBn7HvnvHLDKBns93iyd9JPyfNA26oqrUxb9y2F5SMfdzlamz3g5CRx 9TAkva6r+U3OIXElFRjF2fU+B96ntXVfPfh9OeGOgKqYQcGZ7KZdlgkpoN64cp85AbVL VgFCICPuyb1Q7KLcRfleIVxrCD9QsbzQXvajIutWPrHLOBT5PVUxtp7Mo3/assw5ESVC w8Ew== X-Gm-Message-State: APjAAAWODZNuTPT08Ppb7NTnnzKtgkDANHlduFq/RDmc1SNjfNf6sdiB iou/aYjox6FIsxU3wcbohV9X8bIJ X-Google-Smtp-Source: APXvYqxi49xuewvzw0oP0dAiDUsaCW96vW9bJkIxv5sajuOg6P5Vno+QImcnedQUp/39MJYKF5+SNA== X-Received: by 2002:a65:62c5:: with SMTP id m5mr42772448pgv.77.1553828612557; Thu, 28 Mar 2019 20:03:32 -0700 (PDT) Received: from localhost.localdomain ([2001:268:c0a5:ba2:c70:4af9:86e2:2]) by smtp.gmail.com with ESMTPSA id u14sm694291pfm.66.2019.03.28.20.03.27 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Thu, 28 Mar 2019 20:03:32 -0700 (PDT) From: William Breathitt Gray To: linus.walleij@linaro.org, bgolaszewski@baylibre.com Subject: [PATCH v14 02/11] lib/test_bitmap.c: Add for_each_set_clump8 test cases Date: Fri, 29 Mar 2019 12:04:29 +0900 Message-Id: <824581738681f13901653cee31c430a0e53d7b9f.1553828158.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-20190328_200333_474166_F8D6C984 X-CRM114-Status: GOOD ( 14.07 ) 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 , lukas@wunner.de, geert@linux-m68k.org, akpm@linux-foundation.org, andriy.shevchenko@linux.intel.com, linux-arm-kernel@lists.infradead.org Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+patchwork-linux-arm=patchwork.kernel.org@lists.infradead.org X-Virus-Scanned: ClamAV using ClamSMTP The introduction of the for_each_set_clump8 macro warrants test cases to verify the implementation. This patch adds test case checks for whether an out-of-bounds clump index is returned, a zero clump is returned, or the returned clump value differs from the expected clump value. Cc: Rasmus Villemoes Acked-by: Andrew Morton Reviewed-by: Andy Shevchenko Reviewed-by: Linus Walleij Signed-off-by: William Breathitt Gray --- lib/test_bitmap.c | 65 +++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 65 insertions(+) diff --git a/lib/test_bitmap.c b/lib/test_bitmap.c index 6cd7d0740005..8d1f268069c1 100644 --- a/lib/test_bitmap.c +++ b/lib/test_bitmap.c @@ -88,6 +88,36 @@ __check_eq_u32_array(const char *srcfile, unsigned int line, return true; } +static bool __init __check_eq_clump8(const char *srcfile, unsigned int line, + const unsigned int offset, + const unsigned int size, + const unsigned char *const clump_exp, + const unsigned long *const clump) +{ + unsigned long exp; + + if (offset >= size) { + pr_warn("[%s:%u] bit offset for clump out-of-bounds: expected less than %u, got %u\n", + srcfile, line, size, offset); + return false; + } + + exp = clump_exp[offset / 8]; + if (!exp) { + pr_warn("[%s:%u] bit offset for zero clump: expected nonzero clump, got bit offset %u with clump value 0", + srcfile, line, offset); + return false; + } + + if (*clump != exp) { + pr_warn("[%s:%u] expected clump value of 0x%lX, got clump value of 0x%lX", + srcfile, line, exp, *clump); + return false; + } + + return true; +} + #define __expect_eq(suffix, ...) \ ({ \ int result = 0; \ @@ -104,6 +134,7 @@ __check_eq_u32_array(const char *srcfile, unsigned int line, #define expect_eq_bitmap(...) __expect_eq(bitmap, ##__VA_ARGS__) #define expect_eq_pbl(...) __expect_eq(pbl, ##__VA_ARGS__) #define expect_eq_u32_array(...) __expect_eq(u32_array, ##__VA_ARGS__) +#define expect_eq_clump8(...) __expect_eq(clump8, ##__VA_ARGS__) static void __init test_zero_clear(void) { @@ -361,6 +392,39 @@ static void noinline __init test_mem_optimisations(void) } } +static const unsigned char clump_exp[] __initconst = { + 0x01, /* 1 bit set */ + 0x02, /* non-edge 1 bit set */ + 0x00, /* zero bits set */ + 0x38, /* 3 bits set across 4-bit boundary */ + 0x38, /* Repeated clump */ + 0x0F, /* 4 bits set */ + 0xFF, /* all bits set */ + 0x05, /* non-adjacent 2 bits set */ +}; + +static void __init test_for_each_set_clump8(void) +{ +#define CLUMP_EXP_NUMBITS 64 + DECLARE_BITMAP(bits, CLUMP_EXP_NUMBITS); + unsigned int start; + unsigned long clump; + + /* set bitmap to test case */ + bitmap_zero(bits, CLUMP_EXP_NUMBITS); + bitmap_set(bits, 0, 1); /* 0x01 */ + bitmap_set(bits, 9, 1); /* 0x02 */ + bitmap_set(bits, 27, 3); /* 0x28 */ + bitmap_set(bits, 35, 3); /* 0x28 */ + bitmap_set(bits, 40, 4); /* 0x0F */ + bitmap_set(bits, 48, 8); /* 0xFF */ + bitmap_set(bits, 56, 1); /* 0x05 - part 1 */ + bitmap_set(bits, 58, 1); /* 0x05 - part 2 */ + + for_each_set_clump8(start, clump, bits, CLUMP_EXP_NUMBITS) + expect_eq_clump8(start, CLUMP_EXP_NUMBITS, clump_exp, &clump); +} + static int __init test_bitmap_init(void) { test_zero_clear(); @@ -369,6 +433,7 @@ static int __init test_bitmap_init(void) test_bitmap_arr32(); test_bitmap_parselist(); test_mem_optimisations(); + test_for_each_set_clump8(); if (failed_tests == 0) pr_info("all %u tests passed\n", total_tests); From patchwork Fri Mar 29 03:04:48 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: 10876245 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 77F3E1390 for ; Fri, 29 Mar 2019 03:04:08 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 54BF9290A5 for ; Fri, 29 Mar 2019 03:04:08 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 43BF1290AB; Fri, 29 Mar 2019 03:04:08 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-5.2 required=2.0 tests=BAYES_00,DKIM_ADSP_CUSTOM_MED, DKIM_SIGNED,DKIM_VALID,FREEMAIL_FROM,MAILING_LIST_MULTI,RCVD_IN_DNSWL_MED autolearn=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 D28EE290A5 for ; Fri, 29 Mar 2019 03:04:07 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20170209; h=Sender: Content-Transfer-Encoding:Content-Type:Cc:List-Subscribe:List-Help:List-Post: List-Archive:List-Unsubscribe:List-Id:MIME-Version:References:In-Reply-To: Message-Id:Date:Subject:To:From:Reply-To:Content-ID:Content-Description: Resent-Date:Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID: List-Owner; bh=l99R3wWJRaBqrH98wdYRSkqiaXhXq8c3Vjz4HTrmSko=; b=Xv+3o/lYsyCGCJ cAzvLHg3Bu1XEFgfoYDgzJ4wvvu2/WMaoFijpmvSjrElGC3fBF3seWofZnGW2OX0QxKT6mAAcUqVU u8ezgIHGwYFXctIUkVCrZ0bK4zIEwf8En5qk3uDcloAkQ6Th8qfAT7besxsQC7iiVuSYzlc6za5qr tHO7bk6uPXoYmoaBhT5IuNJy53LxtAfFIDgTI57UcXj28Z+UpwRLzlw9/H3SOk5Tct9yA2A2Qob6Z Fzl+942bRrQdJa+QVk2crESG+Br0U819Vom2OMoWD2g3bkKyP19NpJcRkDCMwRkPP9NpuHvCwocgx dFA1HWT4fFqNpFqkqYyA==; 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 1h9hoE-0002Md-SC; Fri, 29 Mar 2019 03:03:58 +0000 Received: from mail-pl1-x641.google.com ([2607:f8b0:4864:20::641]) by bombadil.infradead.org with esmtps (Exim 4.90_1 #2 (Red Hat Linux)) id 1h9hoA-0002Kg-P0 for linux-arm-kernel@lists.infradead.org; Fri, 29 Mar 2019 03:03:56 +0000 Received: by mail-pl1-x641.google.com with SMTP id g12so296932pll.11 for ; Thu, 28 Mar 2019 20:03:53 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=D+VKB8odm/iRn7Qlf3NsRe6rs5PO9H8u0I72DJse46A=; b=uQNu9sC7c+om5e3vgk0flmjjZKWU3pJaB8T+WBl+D330fN+sPMPwNY1f965Td2Uat5 ChuA59TrLhkmRuPXmjktAcu6smGTPLng6l5ZmOh5kDIlDPrGMDknjaLKykXjybe816fd +aLUY+3vmhwGbj2fiN8znPltSgkFxUgFp3RKElcaDsg+6flrAaqw1XrX3QT/j+KGI7NK XteKOU1FxjDecX+j6ODvbal/rBKJLfv05ZMA1JxslyGNDN9TYEYvtqQ/cp0ukvcnP/Nq 6epaWASlegYukExRuYw7ItPwk3AQT15OHn5psCD0fW/SPZvnBUYtfo1DMGZ1RiBSCIMU Rf5Q== 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=D+VKB8odm/iRn7Qlf3NsRe6rs5PO9H8u0I72DJse46A=; b=IZqn0fygoRyeWCfu15ZqyYLZCGruc4tsIZs6y75oF4mzhgausKdDuhkkV70uCRwHhJ iDo6kvkn/DzyJcpkjVBdeTuxW0a8xU7Ph1vbSyHgFUdbDhHlKMQg0hCiXcUiRKqIueMQ Un4vdJIdoseWsvgMeiXMX+XL5fIv2H8L20swOZihxC6tb9y38SsT/CvxJtC9zveOlEgY QIaVAWjlefMNISUMvTS7FInQiSbDs5jS+6vT5yRIDJBcPg87BUuGWHNYHWAKGgFIhnGH r+sJHcexRlFz77QsyNqm0QmRVEweAW6423k4SHEqNji5Fyd6RdcqOMnO4TcjnU1r/9zn HPPQ== X-Gm-Message-State: APjAAAUrWPIMWUY/nseHemP7+8a5KbALp7Qv4s78KuATSpEfJTTamA89 3z50ZZ/4JywuvNLX7aRvAalD7y3U X-Google-Smtp-Source: APXvYqzQxn36O5ObsJGBGNKD6tiCbowYgmszf87eZW9UoikvPwKFjdTDbqUWXRPNs9BctnBL1lh7yA== X-Received: by 2002:a17:902:26f:: with SMTP id 102mr45575694plc.175.1553828632290; Thu, 28 Mar 2019 20:03:52 -0700 (PDT) Received: from localhost.localdomain ([2001:268:c0a5:ba2:c70:4af9:86e2:2]) by smtp.gmail.com with ESMTPSA id e13sm648881pgb.37.2019.03.28.20.03.45 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Thu, 28 Mar 2019 20:03:51 -0700 (PDT) From: William Breathitt Gray To: linus.walleij@linaro.org, bgolaszewski@baylibre.com Subject: [PATCH v14 03/11] gpio: 104-dio-48e: Utilize for_each_set_clump8 macro Date: Fri, 29 Mar 2019 12:04:48 +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-20190328_200354_813364_7B67774E X-CRM114-Status: GOOD ( 14.54 ) 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, lukas@wunner.de, 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, 21 insertions(+), 52 deletions(-) diff --git a/drivers/gpio/gpio-104-dio-48e.c b/drivers/gpio/gpio-104-dio-48e.c index 92c8f944bf64..2fc6d2b11d25 100644 --- a/drivers/gpio/gpio-104-dio-48e.c +++ b/drivers/gpio/gpio-104-dio-48e.c @@ -183,46 +183,25 @@ 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 long 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 < 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, ARRAY_SIZE(ports) * 8) { + 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, port_state, offset); } return 0; @@ -252,37 +231,27 @@ 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 bitmask; + unsigned long offset; + unsigned long gpio_mask; + size_t index; + unsigned int port_addr; + unsigned long 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, ARRAY_SIZE(ports) * 8) { + 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, 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 Fri Mar 29 03:05:07 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: 10876249 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 7B5B41390 for ; Fri, 29 Mar 2019 03:04:23 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 63E5B28A3B for ; Fri, 29 Mar 2019 03:04:23 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 57F4628A4B; Fri, 29 Mar 2019 03:04: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=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 0C4EA28A3B for ; Fri, 29 Mar 2019 03:04:22 +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=3m+yWWlSu3ywB6ToREJoZIqNevDJdffMz81YzdDxoIc=; b=Pc3DMrfSPnAPfr YaEQim6Evp2UifkG3cVDYqtXIL78mbNiMp+VXA3Nh9BdXMqggjyIVT0+s8Wo/X+ju3YgXzqNgv7B0 ++qaVzv4Et73T7KnA9/8crp5jTdgrDaAABU/cL+NDWvYKMwDHa5cmqOcA3RNmInFDa+aGEGf+6khy CaimTZudciQosKcP/JQ6h9rUNHhq0eHtKcIrVLqcUapgjAbdEcn1oH7N57m1GEa1JQsdUlfFKbEFr qDiFSu8y9DQkfNWVNHYeUpmJlsySiYmz2hQ5VtrBCr/bz7ND1pvqUNWEkju6iyEJ73Y/lBRSxESJh mb5n2uxs3r6iCKoRfUKg==; 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 1h9hoX-0002d9-VR; Fri, 29 Mar 2019 03:04:17 +0000 Received: from mail-pl1-x642.google.com ([2607:f8b0:4864:20::642]) by bombadil.infradead.org with esmtps (Exim 4.90_1 #2 (Red Hat Linux)) id 1h9hoU-0002bp-TQ for linux-arm-kernel@lists.infradead.org; Fri, 29 Mar 2019 03:04:16 +0000 Received: by mail-pl1-x642.google.com with SMTP id q6so312631pll.4 for ; Thu, 28 Mar 2019 20:04:14 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=tvDsEaR5RVMjQmpl7pvXE6aMRh7V9pplB1t4MlLyGlo=; b=l9tVVjx+aEWiEWC6CwVS8J3GwCm51Rj2E6HqC9eJnyGCQUIh1MVdSqhjsZHnms2Iv7 MLz7B5w9G7FiDgSk74g6rnzWp+vLSZoE0Fyr1t/o2BuV8k47BIkWFFRqAfNAFDGIaxJK eD6tAPsMqSYyRpK5mAI/xWBO2dYr6acNmqeJDC7KOSEmKNhRtKUAgFjGrQ3Wq23pdxcL 6ILzXpCZmdVCCgYxJJ8cz8aczA0V5SHcqFzRXYeZlM2KHaM2FDXV4KnKAmxaMhbbnfwm wyY/x21zKwLH95FtVlVPc6+h1mZAkfhGXRGFSFTBy+UpQ72k+W3NkVXg8wLK5Sf8vAQ8 U9WA== 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=tvDsEaR5RVMjQmpl7pvXE6aMRh7V9pplB1t4MlLyGlo=; b=ZsdDyi966+Vzi+x3EfYKrEchTVfQ7FbeQ6oDDAY+dL0CkhvNS/mofGwm+PbJqAFCsK knbfpl0x3QwO1haqONqrav1RIluzfClVVGodNrQsZ13eNFeW4at0DvCVJKSHMGvax8xH RGqZKwMcFJ/K8ylypIVGJR++dQzdIBMq/rKeBGdGYL8B0dWp2E4+p2UdnRylQSFgmqaX 6c6l9abWkwUOS2gGaVu2nDCztyTEfwlhXj4bOOKuYoHwUVhFEL1MibZ/M5FF59k176GJ JohPC8QR3hXQ2wpv5t9wvNXmgkVit6KMPAV8BNI49hrre9c1QNFmKoHWj3XlNuu7/yDQ /wiA== X-Gm-Message-State: APjAAAUXg0yYZDzhVdP0c5nw52XYwqhYM4y1DK2G7gqgUFYgpuQ4TCzy GRtyyePuDryrL+FCcSfYbEQ= X-Google-Smtp-Source: APXvYqym6fvwUFI7HLO94yJuUsFZUzM1NU578GYk1TBDaZRuCZbhNmpJ6GxLnFhCX7imUSSTS+8EqA== X-Received: by 2002:a17:902:a714:: with SMTP id w20mr47383803plq.331.1553828652412; Thu, 28 Mar 2019 20:04:12 -0700 (PDT) Received: from localhost.localdomain ([2001:268:c0a5:ba2:c70:4af9:86e2:2]) by smtp.gmail.com with ESMTPSA id m67sm739087pfj.70.2019.03.28.20.04.04 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Thu, 28 Mar 2019 20:04:11 -0700 (PDT) From: William Breathitt Gray To: linus.walleij@linaro.org, bgolaszewski@baylibre.com Subject: [PATCH v14 04/11] gpio: 104-idi-48: Utilize for_each_set_clump8 macro Date: Fri, 29 Mar 2019 12:05:07 +0900 Message-Id: <6523418679ed2a9dc3d9b955891623313ca01f55.1553828158.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-20190328_200414_971671_2F5ED52C X-CRM114-Status: GOOD ( 14.38 ) 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, lukas@wunner.de, 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 | 36 +++++++--------------------------- 1 file changed, 7 insertions(+), 29 deletions(-) diff --git a/drivers/gpio/gpio-104-idi-48.c b/drivers/gpio/gpio-104-idi-48.c index 88dc6f2449f6..9b43964b0412 100644 --- a/drivers/gpio/gpio-104-idi-48.c +++ b/drivers/gpio/gpio-104-idi-48.c @@ -93,42 +93,20 @@ static int idi_48_gpio_get_multiple(struct gpio_chip *chip, unsigned long *mask, unsigned long *bits) { struct idi_48_gpio *const idi48gpio = gpiochip_get_data(chip); - size_t i; + unsigned long offset; + unsigned long gpio_mask; static const size_t ports[] = { 0, 1, 2, 4, 5, 6 }; - const unsigned int gpio_reg_size = 8; - unsigned int bits_offset; - size_t word_index; - unsigned int word_offset; - unsigned long word_mask; - const unsigned long port_mask = GENMASK(gpio_reg_size - 1, 0); + unsigned int port_addr; unsigned long port_state; /* clear bits array to a clean slate */ bitmap_zero(bits, chip->ngpio); - /* get bits are evaluated a gpio port register at a time */ - for (i = 0; i < ARRAY_SIZE(ports); i++) { - /* gpio offset in bits array */ - bits_offset = i * gpio_reg_size; + for_each_set_clump8(offset, gpio_mask, mask, ARRAY_SIZE(ports) * 8) { + port_addr = idi48gpio->base + ports[offset / 8]; + port_state = inb(port_addr) & gpio_mask; - /* word index for bits array */ - word_index = BIT_WORD(bits_offset); - - /* gpio offset within current word of bits array */ - word_offset = bits_offset % BITS_PER_LONG; - - /* mask of get bits for current gpio within current word */ - word_mask = mask[word_index] & (port_mask << word_offset); - if (!word_mask) { - /* no get bits in this port so skip to next one */ - continue; - } - - /* read bits from current gpio port */ - port_state = inb(idi48gpio->base + ports[i]); - - /* store acquired bits at respective bits array offset */ - bits[word_index] |= (port_state << word_offset) & word_mask; + bitmap_set_value8(bits, port_state, offset); } return 0; From patchwork Fri Mar 29 03:05:27 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: 10876253 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 3BDBE1390 for ; Fri, 29 Mar 2019 03:04:48 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 2168C28A3B for ; Fri, 29 Mar 2019 03:04:48 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 13E5A290A6; Fri, 29 Mar 2019 03:04:48 +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 A0EA428A3B for ; Fri, 29 Mar 2019 03:04:46 +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=2aFOFeeqhEDbaSMUlHqhPoezYFoyIto7RGTWQetNonc=; b=o5DG8hPL9H7gSS YFwIQ7TYBVA/+AFUcUsxexHodHmuw0fwKrb08+48a8l+Uc5B2AscOgJR0o1DcOBb31sWahlDRcWP4 RjeuIoi9wQDmbv08YY4ZiKnbQ8QXbgI+qYd4vdeKL/8ZRLihKeG84wuCUNj856avlaHxuG3ChyUsj +DzUEqV0pa0/2uFup7J359o1h0u25s8ZiGp7oodPeQ8f4NC0ox7ydbNZX2SnByVXWheJGm1ppVIWc slY8OgCJXoBpWEfPwtTMR2AdLVqSJv9IFXV/S4Wr2Zc0xZWvmQHhGwHu5C3LGB2mLyVXiGBezUoSR XV0UDT4PmMuI8hkUoinQ==; 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 1h9hor-0002y5-HV; Fri, 29 Mar 2019 03:04:37 +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 1h9hom-0002tk-D8 for linux-arm-kernel@lists.infradead.org; Fri, 29 Mar 2019 03:04:34 +0000 Received: by mail-pg1-x544.google.com with SMTP id f6so474327pgs.8 for ; Thu, 28 Mar 2019 20: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=gbLsQajapHp8yt8fkh0lWuCUAozPg7cvkSOmtAlT5GA=; b=a8irCDeUZTYaWDlOPVhkUhdNdadXC5FKigwUBS5FyKvPTq2m8ypAM17/+I0gtzczuc SOG9Zd7KiJy6pnKr1Uk6eN3VDO551iSEW3nF4n0RRaSacK8OxWTyC0WPIXWJKlcscal9 lNHA/Tt7wX6Ae6oRUyBepvjiTEX0zzNQ1Lts5fTgOmFaOH4tL5TtZWy7iBVrWkLZ6RDh fMD2+UxDchjJAUXJsmWo1WgQgK5OEz6L4p8La/Rz2ds0y57qSt3k9Zs+XTP56ih7IQ6/ nrzuRapXW2cbb6e+AGWXyutszzyg0YfbdvbirVvyZ2ykmZw9CA9VkrAngTUGH8NvU1uA rCjA== 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=gbLsQajapHp8yt8fkh0lWuCUAozPg7cvkSOmtAlT5GA=; b=t83bSgMjUSem/z+0G92QdsnhLgJcxnJfmdSvqoEh2z4SBaoWeXy2n5QmSngvv3K1wb bxfKW9b7ozIEuDKu7f79MJ2Gm54SMTTpm5LSAY3J2hCiZlrl+2Lj5dXTerFGLOtsClrs ILESlbhEiGPbg4cTrg6gKUgCLG0D212Sk4IYnuDkSk0Ue7KZyuAePcriKjjAhOXbsNsj oJNrfdpiC680NxmSTq1B5kzcqvmFTkrdm6utAcbuUY0V9kYfOXFgPYbk5zwveIcQyZTY OgD32GPvONkmVMBQ6rwd0a5Ip+f+ax/ficwyC/ZOwbSaCSh160dCKLKP0BdgzL8t6D9B MFbQ== X-Gm-Message-State: APjAAAUncIjQ/b07/NdgWrb27y/KioJ/bxut94ErcRFbzrOImCfFyNLU i96sZM+sOtdKFd4g8nvsOh0= X-Google-Smtp-Source: APXvYqxaCXcFVyKNJq16Zf6auT0bGV+1KCnb/RiAUMSxEyS5pWivOMuXAweElNbEHMF73mwkC+O8MA== X-Received: by 2002:aa7:8552:: with SMTP id y18mr1267316pfn.176.1553828671186; Thu, 28 Mar 2019 20:04:31 -0700 (PDT) Received: from localhost.localdomain ([2001:268:c0a5:ba2:c70:4af9:86e2:2]) by smtp.gmail.com with ESMTPSA id k9sm661900pga.22.2019.03.28.20.04.24 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Thu, 28 Mar 2019 20:04:30 -0700 (PDT) From: William Breathitt Gray To: linus.walleij@linaro.org, bgolaszewski@baylibre.com Subject: [PATCH v14 05/11] gpio: gpio-mm: Utilize for_each_set_clump8 macro Date: Fri, 29 Mar 2019 12:05:27 +0900 Message-Id: <0090cb40d7eb69434210c1f3eeb32e0f952dee78.1553828158.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-20190328_200432_599607_390D9C14 X-CRM114-Status: GOOD ( 14.54 ) 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, lukas@wunner.de, 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, 21 insertions(+), 52 deletions(-) diff --git a/drivers/gpio/gpio-gpio-mm.c b/drivers/gpio/gpio-gpio-mm.c index 8c150fd68d9d..0cef50d14c5a 100644 --- a/drivers/gpio/gpio-gpio-mm.c +++ b/drivers/gpio/gpio-gpio-mm.c @@ -172,46 +172,25 @@ 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 long 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 < 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, ARRAY_SIZE(ports) * 8) { + 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, port_state, offset); } return 0; @@ -242,37 +221,27 @@ 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 bitmask; + unsigned long offset; + unsigned long gpio_mask; + size_t index; + unsigned int port_addr; + unsigned long 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, ARRAY_SIZE(ports) * 8) { + 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, 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 Fri Mar 29 03:05:48 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: 10876257 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 0D1BA1390 for ; Fri, 29 Mar 2019 03:05:04 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id E7BC7290B0 for ; Fri, 29 Mar 2019 03:05:03 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id DAFB7290BD; Fri, 29 Mar 2019 03:05:03 +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 7A58C290B0 for ; Fri, 29 Mar 2019 03:05:03 +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=rm5LNNGDjLJSmM1BSkm3XR7tYj1ijQezLBd0obXUdG0=; b=OizKfg7midmy3f 1D7XjUm2EZRwbg1SwNwxX6WbKz/oNrBvCxZ+aPwb2kUbHU+VK5NdsF9rumofN4zFlhiSz6BFJfEUT EN74chkAdFfJnqsM8nPjgRpJO8E3OQ0btP9SLXLpr6WyzxH6zK1eBr5eUS9bbag8BNFMTNyOgI/fp Oyquo2yvS2sOteU4ktE4xbeYXMINE3h/c6LOOQcunxoQT3XGIh7RnT1O5WMNrn8wgP0Kad5JsItyB vRXrNwYbmyZdpekEzjX39pWZIjOdEADd2uN44cy6B4vgE534a6/x5hlzCMdzInLzceGIRGA+tBEaS f/Sv6pL/7p2Oc+VBrlNQ==; 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 1h9hpA-0003EQ-Gg; Fri, 29 Mar 2019 03:04:56 +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 1h9hp6-0003CS-F1 for linux-arm-kernel@lists.infradead.org; Fri, 29 Mar 2019 03:04:54 +0000 Received: by mail-pf1-x443.google.com with SMTP id y13so322455pfm.11 for ; Thu, 28 Mar 2019 20:04:52 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=qhXdbnOxR8IcT7b6oZcrLksWSW3Riv+VrvVQHErm2EM=; b=fLbSzD3w3zCgtresbccjv/SejzzXYViVr+zkBe1DiQmO89fKWqn/mAeiiYjXCimeSP DqABINzeipztDrT27cJeViqsCO6J1dkeYWvQYo14JyzJG9lW9RjwwUtCWMwqVz1PgYqL xeG+6kk2xKOPeGFQwqPY0L/Ram6uom9RAcvYUh2ktDWO76F6PX1LY2Gs3NFEMhTjEOXt G7ipG+F+cO6frL3PvLCJZu44NgZIQRl36c3prQQARz3IaTM9fKKZMMP89bfUYLNed43J ZpxAEgvwKUC2dyVxssM57XDJ0cNNfIAFUhcxqPGzICt0snTQPBPJrS94LUVmM6rxh6Ah xMvA== 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=qhXdbnOxR8IcT7b6oZcrLksWSW3Riv+VrvVQHErm2EM=; b=ngZk9YjkeTOuhIIkcEg5wunRCESYGCYLu9iOLd78MFm5ghkMr+F6DZiIp22K/GiWaX pwh83RHYJhDz49JxXI33SSsNIWoILsbrlbpz/t6IeuiqZWAuJtHTHPmoOMwXDG/ouoCT Ra9oMBtsPYGr6/FmooPQ01pODUFAzjUDUEMIPUi9NCbq2PKdBqpqDKlKuEiATgwwSFcq CASNug5vX1e3U4BcAAIAwTjJFnve/SMg2MpcsvRs/r+hVD/4xcyPRxltdw4ROee87Ojw OKE/kHah3idaw+zUbFU73cFVjw41/OH8CCTQRiCQ9oEJbAVcwH8n256SYP13XFSvJ+SI W+dw== X-Gm-Message-State: APjAAAUQSf5t5KGCNdPn/XLko32BbsxtMc8mCrZK74qsjuLVhfwTHgac jiK+Wh74QXrTKPeuEQwNHOA= X-Google-Smtp-Source: APXvYqwEdUIKM8m/0l5GnoFIXn1qzN2MOFWQVLlE07qz/5yaqaCI03QDf3s9nSzN+fSks9UMZDnL+A== X-Received: by 2002:a63:c505:: with SMTP id f5mr40071923pgd.87.1553828691857; Thu, 28 Mar 2019 20:04:51 -0700 (PDT) Received: from localhost.localdomain ([2001:268:c0a5:ba2:c70:4af9:86e2:2]) by smtp.gmail.com with ESMTPSA id d11sm648622pgq.6.2019.03.28.20.04.44 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Thu, 28 Mar 2019 20:04:51 -0700 (PDT) From: William Breathitt Gray To: linus.walleij@linaro.org, bgolaszewski@baylibre.com Subject: [PATCH v14 06/11] gpio: ws16c48: Utilize for_each_set_clump8 macro Date: Fri, 29 Mar 2019 12:05:48 +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-20190328_200452_508187_BB76F568 X-CRM114-Status: GOOD ( 14.87 ) 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, lukas@wunner.de, 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 | 73 ++++++++++--------------------------- 1 file changed, 20 insertions(+), 53 deletions(-) diff --git a/drivers/gpio/gpio-ws16c48.c b/drivers/gpio/gpio-ws16c48.c index 5cf3697bfb15..ee30417d6394 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 long 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, port_state, offset); } return 0; @@ -203,39 +180,29 @@ 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 bitmask; + unsigned long offset; + unsigned long gpio_mask; + size_t index; + unsigned int port_addr; + unsigned long 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, 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 Fri Mar 29 03:06:07 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: 10876265 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 C3CB21669 for ; Fri, 29 Mar 2019 03:05:28 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id AAEE428A3B for ; Fri, 29 Mar 2019 03:05:28 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 9F61F290A5; Fri, 29 Mar 2019 03:05:28 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-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 4524A28A3B for ; Fri, 29 Mar 2019 03:05:28 +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=Uwq6vjS7DQSvAAzgUJDxTE+siGNtTkY5vjN5J4XC0Ek=; b=bjnpaqR6NmIBbz FsuJOu+YfcKw1ZXArfLUrgq+gli6x0kAs4Tn+SPgmiAFoU70mfWp0AwWYmss6Zw00zUWY0TmZkObr pVqOjmysdHMphwUwxOFkZyQO4r2T18S5kJ5Zf/Eehc0p0O4OjB7+ntfMbmp757yipOiQ6YOhShEku NnOC3tKl5fGpT5slMkUcKdD9YYt+qeqkaREVLVipOckjzulFj6qMChC7NQuGly6ICnK/XYqwYiKkw vM8QTmbHaiJXi7HwHPjU5uNEhGkRwIb9eLX8h1a7aB3dVg3BfbFGou1/gWg6RwXs7PGY8S7u95VKR HIZ+xnL+hm76eJ25WrzA==; 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 1h9hpU-0004iO-Vr; Fri, 29 Mar 2019 03:05:16 +0000 Received: from mail-pl1-x643.google.com ([2607:f8b0:4864:20::643]) by bombadil.infradead.org with esmtps (Exim 4.90_1 #2 (Red Hat Linux)) id 1h9hpP-00049n-Vr for linux-arm-kernel@lists.infradead.org; Fri, 29 Mar 2019 03:05:14 +0000 Received: by mail-pl1-x643.google.com with SMTP id y5so305248plk.8 for ; Thu, 28 Mar 2019 20:05:11 -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=PqXTy5leW1u0qHG2FvwK5coDmQU6qYHNOD3tv8uuTcU=; b=rw2qkKCSDVz/Tpp1+Y5IyUbsMzLRJ9+s4Cz/WjhER5Jybu9T6Y5N60EEBl71gjCs/X S1tSVCrxBfo/ImRC9QyElTBpmHI3VRHOKL3z4VGs9ms/XDdwke57w/r+D1RVg9GgHK5q DRUzR/RVlCyWxU5vIQCvCG65ojVMyKlMInJaMuCvrUcBDrWUxGKK04mMgS9mG5OZ+VLC KbMlkzRksYlMgjqdbtKpCO/ge5iSxSz+MnEYH6NU+a6PyrsAiZASiRtb4p/gEqWds55X qfXVcwqK656KCl01JcEw68ZOKbacIYh459e0dEsC9eVPGkDaw3NcP9rjRlbe9zb8cu+D ikVA== 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=PqXTy5leW1u0qHG2FvwK5coDmQU6qYHNOD3tv8uuTcU=; b=EM3pw3kFwa2isVTL19RraBqubF5loTA3DerN8pDLUuUOoLm/htuqJuAT6WEkyF1nPq JihUzQNW0RjgY3nRkbxzcE1UsOmqCnfVsA0l+mGDjOENzeKusEVYw+wVPPE/orGzBFCR 3Lq6jtrt0h6yVWGBPNP/W4OwSlhPPUwWm79JWnNRw046Lw1Ylza+J5XmGagPxv86wIgt 4IeqGXaCg/hbRql1QW1Q2yglecEcGYSJErKd29t1pzpZc9q03XyV/CVm2sx7YjVh8569 g9RUFnZTfSkoehzjgYk6n8b9voduORIVL60EO5CGPAvmieMJKe38aXwfYhfTi3g9lHui kqjQ== X-Gm-Message-State: APjAAAU/4POKupiPD5FWedW10rEa7PmxWH6YLlV3Cu7/zaJ5IZrJKcnd KQotSEW8ilYO+v00winWJ/E= X-Google-Smtp-Source: APXvYqwm/vmhMs1fugXusZtfLAQ45dsVVfOHhFRxC8MtOhTqDQtGGbtS+df14mtlC60BCAhd7KKNwg== X-Received: by 2002:a17:902:822:: with SMTP id 31mr2944849plk.290.1553828711252; Thu, 28 Mar 2019 20:05:11 -0700 (PDT) Received: from localhost.localdomain ([2001:268:c0a5:ba2:c70:4af9:86e2:2]) by smtp.gmail.com with ESMTPSA id o5sm107443pfa.135.2019.03.28.20.05.05 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Thu, 28 Mar 2019 20:05:10 -0700 (PDT) From: William Breathitt Gray To: linus.walleij@linaro.org, bgolaszewski@baylibre.com Subject: [PATCH v14 07/11] gpio: pci-idio-16: Utilize for_each_set_clump8 macro Date: Fri, 29 Mar 2019 12:06:07 +0900 Message-Id: <074936a78128d5a2e604c8cca6e49c647c9e1f8f.1553828158.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-20190328_200512_217440_0B472AC1 X-CRM114-Status: GOOD ( 14.92 ) 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, lukas@wunner.de, 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, 27 insertions(+), 48 deletions(-) diff --git a/drivers/gpio/gpio-pci-idio-16.c b/drivers/gpio/gpio-pci-idio-16.c index 6b7349783223..a67388db28ad 100644 --- a/drivers/gpio/gpio-pci-idio-16.c +++ b/drivers/gpio/gpio-pci-idio-16.c @@ -108,45 +108,23 @@ 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 long offset; + unsigned long gpio_mask; void __iomem *ports[] = { &idio16gpio->reg->out0_7, &idio16gpio->reg->out8_15, &idio16gpio->reg->in0_7, &idio16gpio->reg->in8_15, }; + 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; - - /* 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, ARRAY_SIZE(ports) * 8) { + port_addr = ports[offset / 8]; + port_state = ioread8(port_addr) & gpio_mask; - /* 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, port_state, offset); } return 0; @@ -186,30 +164,31 @@ 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 long offset; + unsigned long gpio_mask; + void __iomem *ports[] = { + &idio16gpio->reg->out0_7, &idio16gpio->reg->out8_15, + }; + size_t index; + void __iomem *port_addr; + unsigned long bitmask; unsigned long flags; - unsigned int out_state; + unsigned long out_state; - raw_spin_lock_irqsave(&idio16gpio->lock, flags); + for_each_set_clump8(offset, gpio_mask, mask, ARRAY_SIZE(ports) * 8) { + 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, 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 Fri Mar 29 03:06:29 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: William Breathitt Gray X-Patchwork-Id: 10876269 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 05F4C1390 for ; Fri, 29 Mar 2019 03:05:46 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id E1A4F28A3B for ; Fri, 29 Mar 2019 03:05:45 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id D4F0B290A5; Fri, 29 Mar 2019 03:05:45 +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 6654628A3B for ; Fri, 29 Mar 2019 03:05:45 +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=fdEjYvFxJwb4pV5EOt/GjSw5Rd8wLETkJjg9NfJDyNk=; b=imaDLAKVhfrMVg SGhClvNMhk5oF0Hl/CkxgNkiFd/NpB2I6yiSOxmEhBkSjcMEi4xGI6uibz9IjFt9DPB64m2AyEQ22 THsmoCtI3nzIaUxXbRx3URGMgQkv8SHx08a0O11Xc5GNnJ8xuVElS3FBfV3CzNjoWWblWLy8Civ7Z 505s28nKlEWTg822HezkM2pFRr2cSzCWyFebskZa+47eMPD6FihQ5tH9QtWf0qBWEZOI1POSmEWLn bozqYDmlnVxtVmHmoaK+tGY88acR4wktgsyg9Ho7Hmew4PZSK0vm4i3Sw9Tc/qNawf+FMXI+kUhbm /CFGfAKR6HhGICOlDqFA==; 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 1h9hpq-00051z-67; Fri, 29 Mar 2019 03:05:38 +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 1h9hpm-00050w-FC for linux-arm-kernel@lists.infradead.org; Fri, 29 Mar 2019 03:05:36 +0000 Received: by mail-pf1-x441.google.com with SMTP id t21so342177pfe.2 for ; Thu, 28 Mar 2019 20: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=OkTwC9+bMfKIv7o0Jn0YcCWU1jhpVQZU39lRVQzfxwM=; b=AaPkJbA8KpjkT+oEElgvdj8yV3VjzAqWtBuR+1/ujRnrofrFA51dQP23BCWay8puQy zHlpsmAXTNCly7NSYJ+/PCBKJbt+cH/z0oerW6+DmgTb5UEbXowqhKQezSvsBwIRjKo5 HwjPBQ+kU14YALSjaM3lbrw/xIEHxkfEm9yuOf1GQDpOD2q2GxixIFB1cz3d+lViX8dl uklEQXNvKZeE8pG0iAihaC3ljGItzzjW+mvOAt7a0NLSFmSJbJ7Y4e5GkCdxBuUGoPfo sjeR+38cxVPa1vNyarT4i+lze7KEsgKP6P42VrHiC31c1SwP7RunPDegFMwSUSC4E05K Bm3g== 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=OkTwC9+bMfKIv7o0Jn0YcCWU1jhpVQZU39lRVQzfxwM=; b=dTKA7xo8UNA5BCJCkvvATxmQqOgex8ckbzqz/3xLQZ21jQy9L2jbHUQWdPbXw3AfP+ dD7tlWSJXo25OUglWFzle12QPDMVszh160uIgulLEP4jDJlIEBzpw32yObKC/Mc8P6oP fVnOjeFsWb2MiPLIQc0kagtor1WqdSYUzOBgaXSOI2IWprGuFB6x+RGBQF3aBeDR7dIi 2fhD+XYMk25nxAdH8T0DnQ19O3WWdowLeHuuxZ630Qy5oWWpf9UFHUKttZq0YM4GSZ51 7qtNAjlloby5vlr06PZhvL/4MDxeO2nmCSYNUD7zZ5m0GmfJLaQ+P2MFdc/RyaA9Upyg Vp1Q== X-Gm-Message-State: APjAAAXAs17EWwKxdFwCTvEbl8sG+8xlEgKQIGrUSS3siukpz83PSNdl qWO9oxO0M6e1btS7x3gR9bw= X-Google-Smtp-Source: APXvYqwfNATZjEaFxrVy68IqzRyPoA0A4udtUF9fEqXHBYtS6Anqgs18Tbwi457jc5qf8EI39SzlRA== X-Received: by 2002:a62:4602:: with SMTP id t2mr30841921pfa.26.1553828733837; Thu, 28 Mar 2019 20:05:33 -0700 (PDT) Received: from localhost.localdomain ([2001:268:c0a5:ba2:c70:4af9:86e2:2]) by smtp.gmail.com with ESMTPSA id s4sm607195pgp.89.2019.03.28.20.05.28 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Thu, 28 Mar 2019 20:05:33 -0700 (PDT) From: William Breathitt Gray To: linus.walleij@linaro.org, bgolaszewski@baylibre.com Subject: [PATCH v14 08/11] gpio: pcie-idio-24: Utilize for_each_set_clump8 macro Date: Fri, 29 Mar 2019 12:06:29 +0900 Message-Id: <0715d937b024ed50d52836308a2516fc1653a0cf.1553828158.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-20190328_200534_505769_F3471058 X-CRM114-Status: GOOD ( 16.58 ) 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, lukas@wunner.de, 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 | 109 ++++++++++++------------------- 1 file changed, 40 insertions(+), 69 deletions(-) diff --git a/drivers/gpio/gpio-pcie-idio-24.c b/drivers/gpio/gpio-pcie-idio-24.c index 52f1647a46fd..924ec916b358 100644 --- a/drivers/gpio/gpio-pcie-idio-24.c +++ b/drivers/gpio/gpio-pcie-idio-24.c @@ -198,52 +198,34 @@ 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 long 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, }; + 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, ARRAY_SIZE(ports) * 8) { + 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, port_state, offset); } return 0; @@ -294,59 +276,48 @@ 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 long 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 }; + size_t index; + unsigned long bitmask; + unsigned long flags; + unsigned long 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, ARRAY_SIZE(ports) * 8) { + 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, 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 Fri Mar 29 03:06:49 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: 10876273 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 99DB21669 for ; Fri, 29 Mar 2019 03:06:10 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 81AB22906E for ; Fri, 29 Mar 2019 03:06:10 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 75EC1290A6; Fri, 29 Mar 2019 03:06:10 +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 0FB462906E for ; Fri, 29 Mar 2019 03:06:10 +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=aYK1v5ZuK8n3jHA7j/nmZTuC9frj5JQdQzi4h+4cS1I=; b=GoWe4qZtO8VcKQ O98GAHU+Gk4Vb4vtFdrybgsLMQxJsurXDpHj0FjCM9YpwIbvKP0PknhTqBJkH3CARAFy82Fq0Oz89 PXlGoANEH4lMfAE3m864dGUPh+/BjLTilyrpnb5dGEV5I3Lj2K9DQ3iKB1/JPmrSBW1eo/GRJNJOA 7uCBLHPufr4mdynUvXbm/N6r9zo8fpm8F1Rk7XD63kiGcjMqB/UDt//oLFOlg7722pmdhSmEPGMya tpS0Zd7J2bqwrXa7yZyyHFT0hV2CpZEFAIeNF3LbdYsXEheMkNCO7bTMoYw3NaImR7OgwACkJO99t L1g4+2pCtZqUEvxvMoNA==; 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 1h9hqD-0005Pg-1K; Fri, 29 Mar 2019 03:06:01 +0000 Received: from mail-pl1-x644.google.com ([2607:f8b0:4864:20::644]) by bombadil.infradead.org with esmtps (Exim 4.90_1 #2 (Red Hat Linux)) id 1h9hq4-0005HG-Ul for linux-arm-kernel@lists.infradead.org; Fri, 29 Mar 2019 03:05:54 +0000 Received: by mail-pl1-x644.google.com with SMTP id g37so311854plb.5 for ; Thu, 28 Mar 2019 20:05:52 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=kZSRiSxJh+YYsNmeIydN7WXteuBFfpjUBowwMs4kNhU=; b=KWnGgzBWLTCozh/KEfa65tk/St87oTo2wJuOL8E3BE/4C/OrqxarUzYbKBOoU92/gT YfusM2bZaX6obDHs5GmmuXS4odkAhdmnuBrUz/beSE9jdxS1Ctbvk+nvHdfMm3ox3iT+ gKgoQcVto1yN86P3yQe0QbCdDEx4A+QuQ8l4WRVQoL8xoVfv1PdmzsGgooQ4QbTK/4fc RPHibIoV+U9gApNGjB8Grlnx67InMK/tSLNJJSepysfjqJGcm33oiVjwyze5UHeysmpQ 6vCAE+hUNF+OTmfHN7g4e/zQOM5phBt6mOyH2u4+I8sF5pOEOtA1kk2AArCruucLQpcf N7/g== 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=kZSRiSxJh+YYsNmeIydN7WXteuBFfpjUBowwMs4kNhU=; b=ps6/DUsFgi/zcSKJtefNcnaTCPT7s6mUv0f1cSEnsn14IggwTHrEg4x3K4kwIzXKUJ EHvGTgV9nOvOuh93uprQWBf30rTIltmsosXeEIoFTtPIk7xeJ1aN7odRNx8uBMqTwa67 8/GPsBj4toy80JRj5/BJag0DLsRR04YUiYzCIm/igqNiPDtQgb50KRu/VBntB7s6vTiX Ffm69oQhyR+yUiA1uS+Ohf39uiglreYSS7a4Brw2OCB9XmNutSqZmgoFvYayJQJUrGVE zF+1yIUV/lnRhNGf5UwgKhXCcri0ROAcjeYmBT88fDS0dInCAOA4XUzTIJQ/bXupBKyo dUnw== X-Gm-Message-State: APjAAAUMYnS9BIybwWzEwqiXLn2ZadNLRSf7XMzuIwVBd3CGyR9spB3a 6y7EAeFpcRsNyqtJMTX1xiE= X-Google-Smtp-Source: APXvYqzjdiuEQzvKUGIzvn81X4Wqs4VOKQtF5LYTH98WcXqThbgwMjoEZHdlwlbGWk40c4f8F8ThSg== X-Received: by 2002:a17:902:b418:: with SMTP id x24mr39789647plr.323.1553828752410; Thu, 28 Mar 2019 20:05:52 -0700 (PDT) Received: from localhost.localdomain ([2001:268:c0a5:ba2:c70:4af9:86e2:2]) by smtp.gmail.com with ESMTPSA id 4sm697551pfo.110.2019.03.28.20.05.47 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Thu, 28 Mar 2019 20:05:51 -0700 (PDT) From: William Breathitt Gray To: linus.walleij@linaro.org, bgolaszewski@baylibre.com Subject: [PATCH v14 09/11] gpio: uniphier: Utilize for_each_set_clump8 macro Date: Fri, 29 Mar 2019 12:06:49 +0900 Message-Id: <9758aea685bbc9b6b148977880b971920e7b97b6.1553828158.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-20190328_200553_225845_3C3166D3 X-CRM114-Status: GOOD ( 11.44 ) 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, lukas@wunner.de, 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..d79c34e9b23b 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 long i; + unsigned long bank_mask; + unsigned long bank; + unsigned long 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, i); uniphier_gpio_bank_write(chip, bank, UNIPHIER_GPIO_PORT_DATA, bank_mask, bank_bits); From patchwork Fri Mar 29 03:07:07 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: 10876279 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 0583E1669 for ; Fri, 29 Mar 2019 03:06:31 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id E12DF28A3B for ; Fri, 29 Mar 2019 03:06:30 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id D4E5A290A5; Fri, 29 Mar 2019 03:06:30 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-5.2 required=2.0 tests=BAYES_00,DKIM_ADSP_CUSTOM_MED, DKIM_SIGNED,DKIM_VALID,FREEMAIL_FROM,MAILING_LIST_MULTI,RCVD_IN_DNSWL_MED autolearn=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 739DC28A3B for ; Fri, 29 Mar 2019 03:06:30 +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=e1pUdTfZB+sfPH1E0XqjjU8jKhPmtvvxsdhTkhdW0Ek=; b=I7e92i1R5KrbJB kGLfqAYIa8w3DVveelz1PrzkedmLVhwohpUPAWdGCkE5JCxEokyYuKaVw2locO9nevXfLvm5ahF9e Yph4BdlXf7d9k+K/T5MO59+4GJpwUYPlxuJ5bjs+c6j/Bmku68ts9FDhju/GiWaIwL+Vh8bBcarmD VErsY/ZOPRYRXIAaspbAwdOhCSrQ9HSw0z96FZJ5Ul0NM6lT5qKaMXY7bwNgMW0/vZYqXEieVnlOX azZ1A03jrLy6SnqwzwzjEoCGoAEDCTPyhGXdfmbvcPWM+9x7qZSymX4FgAtsS/CtAhSK9iZ1noIAZ peY1pv4dkLvqf8roIQXQ==; 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 1h9hqa-0005oh-6N; Fri, 29 Mar 2019 03:06:24 +0000 Received: from mail-pg1-x541.google.com ([2607:f8b0:4864:20::541]) by bombadil.infradead.org with esmtps (Exim 4.90_1 #2 (Red Hat Linux)) id 1h9hqP-0005he-QH for linux-arm-kernel@lists.infradead.org; Fri, 29 Mar 2019 03:06:22 +0000 Received: by mail-pg1-x541.google.com with SMTP id q1so462953pgv.13 for ; Thu, 28 Mar 2019 20:06: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=dQT+4k892SeDr0jEBp9yKTp//A73nSq2Dh+saIUctZQ=; b=Kv2gkFD/LfDZMH1yUpLLoQDeqknfoK2lmKmZINCPIJux3BnDlSkBr6LPLIf87oGC3b Ei8zGBJkWMjQ0scq5CY73vpbcAOHrmOABVjLkqQySEIBEG/aQZsqZLweiLkeNvF3Sekd dJClA+LYa5pkxaXsO3xK0p8NcfUr/36Ulkn81DQrZMrw6x3Ak/2kWaWrqa66vijrNFbE //jN8YUXaQ9cO8S+hsNa/3si9t0kDXW55ilykTX1CJI40OiIoNOa0wMnn6Gv9gODcNvZ ydBObKmbQ8tsbP8gSuRLqhYjuFQokdKmoY9nw+L4t4aMn09FJi4qxkYfdjqP9jjZKTPc V+Ig== 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=dQT+4k892SeDr0jEBp9yKTp//A73nSq2Dh+saIUctZQ=; b=JxLJvsibFVk+uYrZ/RYOUDAGFJGQWjybZl7j7+pLuNwEU99RJ+FuuM5AlbGTkQ5uHc H8qRe/0JCdOx2I2vcVHqf35/R4aFkCsOPY0qbQwIFDc+7ENWLodjvyzHGw8Om7TmldQs L4hxsyZqAYXPQLH5XBEFpjcKnYL5Sj30J1d+QNEL57EN0he0jXaovHtgwSbkljTKlgrc BFU56Uz4r69TEAwBY1fomdeDswQxca48N+F/fndDOvqHt/O6EOpWuHvBb6FCfyspO66p UHTEQXbjIwOfb6ViGVFfSuTcc9U5yEC+0t42pzjpN8sz7eM/nMyn7N14v5rhQ0sGcDf2 L3Yg== X-Gm-Message-State: APjAAAWK/XPYWb46fZEhuV0LIPDaAjkhhNdTEkGydVE5+VOka2PE4pMJ ANRGwHk1KaQr0QAWBSbyMnQ= X-Google-Smtp-Source: APXvYqwvCTl69l0VdR73TwLG64piqZSCIotkCo4f2C8z4dMSswzCr5Ql2nYhiK/1MXIBZ8JY4tYZCw== X-Received: by 2002:a65:4689:: with SMTP id h9mr17001919pgr.295.1553828771474; Thu, 28 Mar 2019 20:06:11 -0700 (PDT) Received: from localhost.localdomain ([2001:268:c0a5:ba2:c70:4af9:86e2:2]) by smtp.gmail.com with ESMTPSA id w68sm724917pfb.176.2019.03.28.20.06.04 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Thu, 28 Mar 2019 20:06:10 -0700 (PDT) From: William Breathitt Gray To: linus.walleij@linaro.org, bgolaszewski@baylibre.com Subject: [PATCH v14 10/11] gpio: 74x164: Utilize the for_each_set_clump8 macro Date: Fri, 29 Mar 2019 12:07:07 +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-20190328_200614_144697_0A6139A6 X-CRM114-Status: GOOD ( 12.44 ) 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, lukas@wunner.de, 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 | 19 +++++++++---------- 1 file changed, 9 insertions(+), 10 deletions(-) diff --git a/drivers/gpio/gpio-74x164.c b/drivers/gpio/gpio-74x164.c index fb7b620763a2..de1e8b37e102 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,18 @@ 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 long offset; + unsigned long bankmask; + size_t bank; + unsigned long 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, chip->registers * 8) { + bank = chip->registers - 1 - offset / 8; + bitmask = bitmap_get_value8(bits, 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); From patchwork Fri Mar 29 03:07:26 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: 10876285 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 F280B1390 for ; Fri, 29 Mar 2019 03:06:53 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id DA49F290A5 for ; Fri, 29 Mar 2019 03:06:53 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id CEAA0290AA; Fri, 29 Mar 2019 03:06:53 +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 756C7290A5 for ; Fri, 29 Mar 2019 03:06:53 +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=Et2Hx9PLsg6iEwrazfuS/YReNBJlm6rHK3pigHIGti8=; b=RtUwgMW2IqJkz9 FfDRxLqDqFI8AYfCUfWlCnf+qT9kOSiR7K9ecjjsnEjG1ZCXr/5L/JYfski/srLIA5AuXo6XUraeP BpPMrW+72Z6PjJpiGAPbEnoCXEgSLsGXD5OwgRpAo/mELDgXKs2uUuSsV+ICM6O/8CHDgzmosj0QE Li91Yq6ZxZAPWYP30vfc/jYLcMWaDC0Nw4ObcAppSVzKM5UgYC8JWcOs9C1PZQ2g9yNhq6PGvGPXV gm9UshqQso36bryy9G5G8ziELnLWxJlSzgK4X7RxVZZ3FMwJm/LSCC1AsSRR8i0xsLbL43pxLunbq 3iHTIUqv2BDruEQzYu5g==; 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 1h9hr1-0006DR-Np; Fri, 29 Mar 2019 03:06:51 +0000 Received: from mail-pg1-x543.google.com ([2607:f8b0:4864:20::543]) by bombadil.infradead.org with esmtps (Exim 4.90_1 #2 (Red Hat Linux)) id 1h9hqj-0005zr-UH for linux-arm-kernel@lists.infradead.org; Fri, 29 Mar 2019 03:06:39 +0000 Received: by mail-pg1-x543.google.com with SMTP id 85so487387pgc.3 for ; Thu, 28 Mar 2019 20:06:33 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=bnOm4aYIKD2kSQWsZFrlwKooGVBEjRhwfdK8IJWhQ7o=; b=gU8q5odCNLcZdQWnjVmacPohTRS/h05dCvrZiL8X0uJ621gTO6u2hIgw7/Oh6sWlZ2 Lw2KuFLa85+sWiFHY4e7cIevoeS/G7rldztULoROImj79MQIQEZCJbMih6wib9yhQOi3 7gybsY5ZAr+0MOxd3JbD90AMGsrv+HMWUpvUBqQ6KcSv7KhZ6eiDDRtzobjPplGIAzky cWpLetvioIJP8LozsOwG4RTVZfk/PM8+I+WdV16ZsxGX+ivV4x2MYdA3g/tOXbIJkWEU 2AU2ov9vPFKyl2tfUtaYBQrcmaVlis4YNg4IfcXOf829KdwYfKYnJhfCD9kbWxkro5Uw UvBg== 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=bnOm4aYIKD2kSQWsZFrlwKooGVBEjRhwfdK8IJWhQ7o=; b=hvWf9W8BCez95E7RlSjvtO74M8eCG4OLQAat4dl/N5SsHlzftLWLziKZi6I/BWaJw5 ux8LQO0FNW7/uBx2bW2lpNNFXLtJM6/53MBNMzsbO5bQL9sIBciJTJNBn2089l852bHj wimK5/4wwQv8SFu2NYdgZECf1uMAqg5Pork5TBP5uqT6eP+GTpMiIsxiHO4Jl2Gb90fS DPfQ+HEUyxv16o27pOpK6UBc9G9hE6/ytJ48Km0KqhWEGJH4Xct8HSbozNhOlWeokf/2 ReG2ZsQZN7Gn1OvSZSED8xkrvsg9MQi7j7wcNKkPRTQKHUyaUGwKon5RMJyzUT2+5Ijx 5lXA== X-Gm-Message-State: APjAAAXbBZQSlKsGtrvVHocdHY1zT4rB9C00dqB+90UzGOMBRy5ERB5G DmhHICdhmhX2z+vdOqn3iQQ= X-Google-Smtp-Source: APXvYqzJHHWccE6r/ABmxHutKRCH84tnwL+KcfETjAHgllfLu7rm9wgEsMXxht7qAhzQoRO7/zq50Q== X-Received: by 2002:a62:14c3:: with SMTP id 186mr44794755pfu.21.1553828793350; Thu, 28 Mar 2019 20:06:33 -0700 (PDT) Received: from localhost.localdomain ([2001:268:c0a5:ba2:c70:4af9:86e2:2]) by smtp.gmail.com with ESMTPSA id k17sm660235pfk.166.2019.03.28.20.06.27 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Thu, 28 Mar 2019 20:06:32 -0700 (PDT) From: William Breathitt Gray To: linus.walleij@linaro.org, bgolaszewski@baylibre.com Subject: [PATCH v14 11/11] thermal: intel: intel_soc_dts_iosf: Utilize for_each_set_clump8 macro Date: Fri, 29 Mar 2019 12:07:26 +0900 Message-Id: <671029ab8c9f3a630e77b454b25d6697c8375f24.1553828158.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-20190328_200634_720411_F4254B24 X-CRM114-Status: GOOD ( 14.60 ) X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: linux-arch@vger.kernel.org, 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, lukas@wunner.de, 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..2aa16b5262e9 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, 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, 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 long 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;