From patchwork Wed Mar 27 04:58:45 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: 10872485 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 8563114DE for ; Wed, 27 Mar 2019 04:57:58 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 6BEE828A38 for ; Wed, 27 Mar 2019 04:57:58 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 5E29728D33; Wed, 27 Mar 2019 04:57:58 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-8.0 required=2.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,FREEMAIL_FROM,MAILING_LIST_MULTI,RCVD_IN_DNSWL_HI autolearn=ham version=3.3.1 Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 3CEFA28A38 for ; Wed, 27 Mar 2019 04:57:57 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1725763AbfC0E5w (ORCPT ); Wed, 27 Mar 2019 00:57:52 -0400 Received: from mail-pf1-f194.google.com ([209.85.210.194]:34132 "EHLO mail-pf1-f194.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1725613AbfC0E5v (ORCPT ); Wed, 27 Mar 2019 00:57:51 -0400 Received: by mail-pf1-f194.google.com with SMTP id b3so7765857pfd.1; Tue, 26 Mar 2019 21:57:51 -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=Uip2SJNOxYS4/yCupvO0yCYaokZfoOseJfUme2GdvMI=; b=VXnjPTjsu4YySzBI7FUjsuKpACfcIimz0wCHKOW79RkaSxLv7spNkcaKT2scqV7H8v SNALUo3sBmzp1jt86RvYXQowaViVEy6gNG2Esxt1f4OiUNu1p7YedEPz1OjiktSo+aPp 3H2NmDzjrZDlyZivCvs7z0OPi2C2cFN/Ci8+hV8DKYH7bqBtg/7GMnv8c5a1q3ew4SN7 2x5U8kwYQJJ1kcWFCqPrL20gU1rpYt46wdh4Ck2GDzZnp02Sr8aUVSRMDrjW1IzSyriV aQtyhK8bCuOP6NSZEWdvRfRaMxBLCLX1tyhmCbnui4PrKBoGhoBkeqCxwcRvhudZ4Cga L3kw== 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=Uip2SJNOxYS4/yCupvO0yCYaokZfoOseJfUme2GdvMI=; b=fBzeNaIFbQtd21rWQUuBH1Wz1z2SnlwQSVIFkwEJk211LmOYZk7THLrCESNjOnvFfD H7Ygyp4zwmDZUGltqBQ9jYXGIOYmEwR5l7HUKJyDkX0VGp/Dv6v8xwXBc4OytkxAaQVV pI6u3+BGh7yxEYJuIEM4g5Fay0wofETu/GBFusyujGKbfFVK0qds8dGHXU2Mk6xHPJy1 t+1zX8HPyUL6HczfSeaIR7wNhOWwRqZj0Nqu3yhlCapBWcAw//i9Ys2dRdBVmaT7L13R YGlgLReIXXp5YCy5tIqWmCZvE5SDXQP0xLU0bX7CAfyURF2c9LNSTn5PDquu2vTfT7LY A+wQ== X-Gm-Message-State: APjAAAXV8TtFRp/UqNMj11fVpDTliWI9d+62J6+S839E1YhBACQg8RTN 62m4EKnsLPdNXmH4oNxtP2s= X-Google-Smtp-Source: APXvYqwIBIGzL2EaNaieYfvz6H4C3wp+BjWPMVK5N9esxq/aTuo7hAczrGEKE4BQzsFQkWH0P1a9TA== X-Received: by 2002:a62:3585:: with SMTP id c127mr32910673pfa.71.1553662670879; Tue, 26 Mar 2019 21:57:50 -0700 (PDT) Received: from localhost.localdomain ([2001:268:c0a5:6014:c70:4af9:86e2:2]) by smtp.gmail.com with ESMTPSA id e22sm27564056pfi.126.2019.03.26.21.57.45 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Tue, 26 Mar 2019 21:57:50 -0700 (PDT) From: William Breathitt Gray To: linus.walleij@linaro.org, bgolaszewski@baylibre.com Cc: akpm@linux-foundation.org, linux-gpio@vger.kernel.org, linux-arch@vger.kernel.org, linux-kernel@vger.kernel.org, andriy.shevchenko@linux.intel.com, linux@rasmusvillemoes.dk, yamada.masahiro@socionext.com, linux-arm-kernel@lists.infradead.org, linux-pm@vger.kernel.org, geert@linux-m68k.org, preid@electromag.com.au, William Breathitt Gray , Andy Shevchenko , Lukas Wunner , Arnd Bergmann Subject: [PATCH v13 01/11] bitops: Introduce the for_each_set_clump8 macro Date: Wed, 27 Mar 2019 13:58:45 +0900 Message-Id: <497dc4b5b1f668b54e008e10a43d4108f4a41213.1553661964.git.vilhelm.gray@gmail.com> X-Mailer: git-send-email 2.21.0 In-Reply-To: References: MIME-Version: 1.0 Sender: linux-pm-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-pm@vger.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP This macro iterates for each 8-bit group of bits (clump) with set bits, within a bitmap memory region. For each iteration, "start" is set to the bit offset of the found clump, while the respective clump value is stored to the location pointed by "clump". Additionally, the bitmap_get_value8 and bitmap_set_value8 functions are introduced to respectively get and set an 8-bit value in a bitmap memory region. Suggested-by: Andy Shevchenko Suggested-by: Rasmus Villemoes Suggested-by: Lukas Wunner Cc: Arnd Bergmann Cc: Andrew Morton Cc: Andy Shevchenko Cc: Linus Walleij Signed-off-by: William Breathitt Gray --- include/asm-generic/bitops/find.h | 11 ++++++ include/linux/bitops.h | 5 +++ lib/find_bit.c | 58 +++++++++++++++++++++++++++++++ 3 files changed, 74 insertions(+) diff --git a/include/asm-generic/bitops/find.h b/include/asm-generic/bitops/find.h index 8a1ee10014de..b0a99035f64f 100644 --- a/include/asm-generic/bitops/find.h +++ b/include/asm-generic/bitops/find.h @@ -80,4 +80,15 @@ extern unsigned long find_first_zero_bit(const unsigned long *addr, #endif /* CONFIG_GENERIC_FIND_FIRST_BIT */ +unsigned long bitmap_get_value8(const unsigned long *addr, unsigned long start); + +void bitmap_set_value8(unsigned long *addr, unsigned long value, + unsigned long start); + +unsigned long find_next_clump8(unsigned long *clump, const unsigned long *addr, + unsigned long size, unsigned long 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; diff --git a/lib/find_bit.c b/lib/find_bit.c index ee3df93ba69a..71a4e0a31e40 100644 --- a/lib/find_bit.c +++ b/lib/find_bit.c @@ -218,3 +218,61 @@ EXPORT_SYMBOL(find_next_bit_le); #endif #endif /* __BIG_ENDIAN */ + +/** + * 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. + */ +unsigned long bitmap_get_value8(const unsigned long *addr, unsigned long start) +{ + const size_t idx = BIT_WORD(start); + const unsigned long offset = start % BITS_PER_LONG; + + return (addr[idx] >> offset) & 0xFF; +} +EXPORT_SYMBOL(bitmap_get_value8); + +/** + * 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 + */ +void bitmap_set_value8(unsigned long *addr, unsigned long value, + unsigned long start) +{ + const size_t idx = BIT_WORD(start); + const unsigned long offset = start % BITS_PER_LONG; + + addr[idx] &= ~(0xFF << offset); + addr[idx] |= value << offset; +} +EXPORT_SYMBOL(bitmap_set_value8); + +/** + * find_next_clump8 - find next 8-bit clump with set bits in a memory region + * @clump: location to store copy of found clump + * @addr: address to base the search on + * @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. + */ +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; +} +EXPORT_SYMBOL(find_next_clump8); From patchwork Wed Mar 27 04:59:05 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: 10872491 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 3871714DE for ; Wed, 27 Mar 2019 04:58:21 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 232E328A38 for ; Wed, 27 Mar 2019 04:58:21 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 177AB28D33; Wed, 27 Mar 2019 04:58:21 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-8.0 required=2.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,FREEMAIL_FROM,MAILING_LIST_MULTI,RCVD_IN_DNSWL_HI autolearn=unavailable version=3.3.1 Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id A718528A38 for ; Wed, 27 Mar 2019 04:58:20 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726268AbfC0E6K (ORCPT ); Wed, 27 Mar 2019 00:58:10 -0400 Received: from mail-pl1-f194.google.com ([209.85.214.194]:40470 "EHLO mail-pl1-f194.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1725613AbfC0E6K (ORCPT ); Wed, 27 Mar 2019 00:58:10 -0400 Received: by mail-pl1-f194.google.com with SMTP id b11so2719290plr.7; Tue, 26 Mar 2019 21:58:09 -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=hwamcCt2ulELLEuskhsLCImVFMv2a97a0lQZoYcRyKuJrzsjVIqZU2frCB8UMNZvvC oaacF4wgDmoIgX2DUUpDVCl+MSnEo2A8Y9PSz2isQd0SIZprEQUcQ5TG82IxYtEBFh63 mM3FrKIk3zFchrNeuhIL+7Z4gojX/dz5khT2bMZo1NmIKlppI5fHST2mLwx/Zg1t+9Uu sMOJrHtRzUU2+TAJV1ON7P56OJK0aqodRrPtffq83Po4Rqp32Af2bEU9KuRDhznHC0VA 72y44/ibe1oVK9TO7pJWxKt624iDJSHqXrwDTk7iI7llFXvA+yn6OAULWM5WQTndpYQg OBHg== 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=qqUhDRMFaMgKkHbIzEbK3W/nQb0GmDX36yGApwRGTkjsv1nIhyXZ1kVcC+mkg46IRk 3fw3+fnpVRX/z+JVKcMD+lRE8Tmv7Ib8HE+AVuNGAQdzd8R2vLqVSJYCXSsGqejUsmnh D+nq8afNHRfobf7iXkQDEoeXOH3xH6hmaPRxnAD3PVJ8UyXeUeNbDUA+2pikkXtMm58G tlQAKGKXfCGp7aJ2OKcsnKZ3GKphm4Qk0Da89pVxSkOSzAc0YV69zsnAhIvvEJEo/1AK RLMRyqSFqMU/OtXJJs+Nqk69Jgn7y5N9f32Wy+O+wV34OMr2SiBhvvZp6l/36CGkhbm6 WerQ== X-Gm-Message-State: APjAAAXLwOLtF9V2br3Fql9BGYjtv+k/DsvrdNAS25nnlWAaa/595Rd6 ej4AGzlUnohHeVYUd/LS0n8= X-Google-Smtp-Source: APXvYqzo65K90+xL7aOCZ0TQNayGxWizVGQ3lrqBiJdDKj1edlvX8dhBi6MkQL5Ybh1LoRvlUQ7wRQ== X-Received: by 2002:a17:902:a612:: with SMTP id u18mr34599414plq.145.1553662689376; Tue, 26 Mar 2019 21:58:09 -0700 (PDT) Received: from localhost.localdomain ([2001:268:c0a5:6014:c70:4af9:86e2:2]) by smtp.gmail.com with ESMTPSA id d130sm44455194pfg.49.2019.03.26.21.58.04 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Tue, 26 Mar 2019 21:58:08 -0700 (PDT) From: William Breathitt Gray To: linus.walleij@linaro.org, bgolaszewski@baylibre.com Cc: akpm@linux-foundation.org, linux-gpio@vger.kernel.org, linux-arch@vger.kernel.org, linux-kernel@vger.kernel.org, andriy.shevchenko@linux.intel.com, linux@rasmusvillemoes.dk, yamada.masahiro@socionext.com, linux-arm-kernel@lists.infradead.org, linux-pm@vger.kernel.org, geert@linux-m68k.org, preid@electromag.com.au, William Breathitt Gray , Andy Shevchenko Subject: [PATCH v13 02/11] lib/test_bitmap.c: Add for_each_set_clump8 test cases Date: Wed, 27 Mar 2019 13:59:05 +0900 Message-Id: <924aa49777091e103c383073800c908c55bce631.1553661964.git.vilhelm.gray@gmail.com> X-Mailer: git-send-email 2.21.0 In-Reply-To: References: MIME-Version: 1.0 Sender: linux-pm-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-pm@vger.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP The introduction of the for_each_set_clump8 macro warrants test cases to verify the implementation. This patch adds test case checks for whether an out-of-bounds clump index is returned, a zero clump is returned, or the returned clump value differs from the expected clump value. Cc: Rasmus Villemoes Acked-by: Andrew Morton Reviewed-by: Andy Shevchenko Reviewed-by: Linus Walleij Signed-off-by: William Breathitt Gray --- lib/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 Wed Mar 27 04:59:24 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: 10872493 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 D6AEF14DE for ; Wed, 27 Mar 2019 04:58:32 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id C298328A38 for ; Wed, 27 Mar 2019 04:58:32 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id B694C28D33; Wed, 27 Mar 2019 04:58:32 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-8.0 required=2.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,FREEMAIL_FROM,MAILING_LIST_MULTI,RCVD_IN_DNSWL_HI autolearn=ham version=3.3.1 Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 4275328A38 for ; Wed, 27 Mar 2019 04:58:32 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1725807AbfC0E6b (ORCPT ); Wed, 27 Mar 2019 00:58:31 -0400 Received: from mail-pf1-f196.google.com ([209.85.210.196]:43203 "EHLO mail-pf1-f196.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1725613AbfC0E6b (ORCPT ); Wed, 27 Mar 2019 00:58:31 -0400 Received: by mail-pf1-f196.google.com with SMTP id c8so9124893pfd.10; Tue, 26 Mar 2019 21:58:30 -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=QiZYWv98mpUpZW7djHUVZS0MEFySpQjFTUP9fp/wlZ4PeMl2XJrN+g9Gh/8jgXbwzt 3wv+5c9twrrKcbT8FeddPYDk+IqFi8Nwyt/U6UOqdSK3VREjeRNF/ZuSKx1HoBwyqPz9 AtAAN7uKcl06iTl7mY6OOfFp7z8cS7jyzl+9nDlKIq2bRATR1rf7QXPGFr1FrRFws3YB tvGe4gWIRkyPXkush5lGWK1HtIq4SaHazEUidxScUcmdtmDE3upJnCuqrH5D0j6dZYmj uToISTrJJlneDT1//jBoWeynokP6ehckgWqJVjzz09I98YJ41YgIvXvOdp+zRzzUN3nr hoiQ== 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=VmWvbSqqqgtF6PqXJ1ShiNiIRk3or+9UTWygI0PpCf2YXneQiLJe06QHkr4RFas/mj xEUw55o4XWOK1Mt0iv+NebZrIKw0k35620pKDY0lLTjb8GMLWVvhMczuksHLf1GhBYGP xtqHB9hFBmsCWo8im4Ls1TybO+NWyWAze8J+zRbeNRndUk8HLoPTNd6j2AUv+5L3nMHV Gb/2XpmignF/87RvYgCJQJye4SrBR6958vED7lwrfAvmAtva8bAe4GM8OPVSTbYHGE+U W8+aB/P3pskHAGRsfMARRAtdab+sfKlwJQwoQuQM75LzBjmJcAQcQfYDQT5GAsfb9PZS LH1Q== X-Gm-Message-State: APjAAAUpNXRf8k5Hbf1QFr/Q1CIsGnvu5NjE4zAG596Adrkz7eBTqwFG 2Y4ksrnIY1YkuVc6/6mtNy4= X-Google-Smtp-Source: APXvYqxE+ztDBBrFWBqATimDFtBanMe9IkMpfq68fj7mvbOYiy6sJk9MwgvB5X80CHzRbaQi1yE0LQ== X-Received: by 2002:a63:fb45:: with SMTP id w5mr32663083pgj.118.1553662710330; Tue, 26 Mar 2019 21:58:30 -0700 (PDT) Received: from localhost.localdomain ([2001:268:c0a5:6014:c70:4af9:86e2:2]) by smtp.gmail.com with ESMTPSA id j8sm24879147pff.183.2019.03.26.21.58.23 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Tue, 26 Mar 2019 21:58:29 -0700 (PDT) From: William Breathitt Gray To: linus.walleij@linaro.org, bgolaszewski@baylibre.com Cc: akpm@linux-foundation.org, linux-gpio@vger.kernel.org, linux-arch@vger.kernel.org, linux-kernel@vger.kernel.org, andriy.shevchenko@linux.intel.com, linux@rasmusvillemoes.dk, yamada.masahiro@socionext.com, linux-arm-kernel@lists.infradead.org, linux-pm@vger.kernel.org, geert@linux-m68k.org, preid@electromag.com.au, William Breathitt Gray Subject: [PATCH v13 03/11] gpio: 104-dio-48e: Utilize for_each_set_clump8 macro Date: Wed, 27 Mar 2019 13:59:24 +0900 Message-Id: X-Mailer: git-send-email 2.21.0 In-Reply-To: References: MIME-Version: 1.0 Sender: linux-pm-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-pm@vger.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP Replace verbose implementation in get_multiple/set_multiple callbacks with for_each_set_clump8 macro to simplify code and improve clarity. Reviewed-by: Linus Walleij Signed-off-by: William Breathitt Gray --- drivers/gpio/gpio-104-dio-48e.c | 73 ++++++++++----------------------- 1 file changed, 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 Wed Mar 27 04:59:50 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: William Breathitt Gray X-Patchwork-Id: 10872499 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 95766186E for ; Wed, 27 Mar 2019 04:59:01 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 8074828D32 for ; Wed, 27 Mar 2019 04:59:01 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 73E2928D35; Wed, 27 Mar 2019 04:59:01 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-8.0 required=2.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,FREEMAIL_FROM,MAILING_LIST_MULTI,RCVD_IN_DNSWL_HI autolearn=unavailable version=3.3.1 Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 2246028D33 for ; Wed, 27 Mar 2019 04:59:01 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1725730AbfC0E6z (ORCPT ); Wed, 27 Mar 2019 00:58:55 -0400 Received: from mail-pl1-f194.google.com ([209.85.214.194]:36622 "EHLO mail-pl1-f194.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1725613AbfC0E6z (ORCPT ); Wed, 27 Mar 2019 00:58:55 -0400 Received: by mail-pl1-f194.google.com with SMTP id k2so2721881plt.3; Tue, 26 Mar 2019 21:58:55 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=tvDsEaR5RVMjQmpl7pvXE6aMRh7V9pplB1t4MlLyGlo=; b=ttJmL44tLwmeymwJk21YO5pD2dbq91CaeW1b2AyPJi9Sl5J2FnhLhAjxGI07JVZ0ev GAUnoTmThB2nh0kOiZNRgIRXh9sUjgXjGLE7RRHXP0MLUC4EkXkBDSstM64EDRJ6YqqS TFtKVyWQCYL3irrd6qYAZs8JbDNwm/qw8n6UdWxC1aXCjf3zpnvbubMqR2FvGESakekj DvJserniuhIzf91JoYxCeyLD6opMp7lemdpPjpAoADet3HJvymtnIIY27MJF92IUjXTS +uRkEYqZ4T84bPPnrXA36HLVVVOxcGIV7XMwEe8Gpsx1FuSe0yq4UCs9g1kDr15iuSUs uz0g== 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=p9XmdMyNM8V+wc8t340fA27pcPiYp26slEDfSumiWxq0ZWtT3u66De4tWpKG/O96kG CZtqLPU6OTrm1p5k1pfKuAUJ8oros1NBfLPpo6nzFHxY5dHyROAWEURL+zth2uVCe0K+ rNo2e8UAtMogOrUeEOKZbBRWk5XokDxSkwI2ewfBUtzIZIVQOkQ0yaKQva8jEKzVxzEZ CWL4GdSB/bop8dmspcarDtHcyB2qbkUkm1s/pi1SkjEAR3wAtJmdvZamBYpBFSAbeZ9j Wg0IJmR1VYEzRg2td2A4EzdfGw1to4V5b6V/dL7I39Y4TKnkDg4dL/s0g0DuPot72oUw kbdw== X-Gm-Message-State: APjAAAVsJ47pMz/H7Fu2zZi5uv+2WYIuXTXvf4yEZJkXV9g2ON6Ul1Qe VkXEmdUKhIHXhBvQlQ6pRJU= X-Google-Smtp-Source: APXvYqyqCK2pgNbDSWh5tfKVfkD1OLh24THmdaZzxauSeDG2Mm7+3YUTDtyZf8C5ZYbDUHkhAAYEqw== X-Received: by 2002:a17:902:988e:: with SMTP id s14mr22560082plp.167.1553662734795; Tue, 26 Mar 2019 21:58:54 -0700 (PDT) Received: from localhost.localdomain ([2001:268:c0a5:6014:c70:4af9:86e2:2]) by smtp.gmail.com with ESMTPSA id l19sm877015pff.1.2019.03.26.21.58.48 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Tue, 26 Mar 2019 21:58:54 -0700 (PDT) From: William Breathitt Gray To: linus.walleij@linaro.org, bgolaszewski@baylibre.com Cc: akpm@linux-foundation.org, linux-gpio@vger.kernel.org, linux-arch@vger.kernel.org, linux-kernel@vger.kernel.org, andriy.shevchenko@linux.intel.com, linux@rasmusvillemoes.dk, yamada.masahiro@socionext.com, linux-arm-kernel@lists.infradead.org, linux-pm@vger.kernel.org, geert@linux-m68k.org, preid@electromag.com.au, William Breathitt Gray Subject: [PATCH v13 04/11] gpio: 104-idi-48: Utilize for_each_set_clump8 macro Date: Wed, 27 Mar 2019 13:59:50 +0900 Message-Id: <1476995eb0bf988b4a3cc27f0e5e1484933d93ec.1553661964.git.vilhelm.gray@gmail.com> X-Mailer: git-send-email 2.21.0 In-Reply-To: References: MIME-Version: 1.0 Sender: linux-pm-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-pm@vger.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP Replace verbose implementation in get_multiple/set_multiple callbacks with for_each_set_clump8 macro to simplify code and improve clarity. Reviewed-by: Linus Walleij Signed-off-by: William Breathitt Gray --- drivers/gpio/gpio-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 Wed Mar 27 05:00:10 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: 10872503 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 C3847186E for ; Wed, 27 Mar 2019 04:59:26 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id AF8C228758 for ; Wed, 27 Mar 2019 04:59:26 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id A35792876C; Wed, 27 Mar 2019 04:59:26 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-8.0 required=2.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,FREEMAIL_FROM,MAILING_LIST_MULTI,RCVD_IN_DNSWL_HI autolearn=unavailable version=3.3.1 Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 2D49028769 for ; Wed, 27 Mar 2019 04:59:26 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1725829AbfC0E7U (ORCPT ); Wed, 27 Mar 2019 00:59:20 -0400 Received: from mail-pg1-f196.google.com ([209.85.215.196]:40105 "EHLO mail-pg1-f196.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1725613AbfC0E7U (ORCPT ); Wed, 27 Mar 2019 00:59:20 -0400 Received: by mail-pg1-f196.google.com with SMTP id u9so9342378pgo.7; Tue, 26 Mar 2019 21:59:19 -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=HsXWqFbK4h2vjS6XbRFUkVqK7tZM6SdYfp0Z1hI0UP5TFv0G7nw4V/MGYYMPLzHMdx O6k2HEsdCsOH7n667eMxq2havDwD0uI+zY4sAJ/pagqecSOqmKy6HiTl4arijqQs06Dc zt5wteOtMGcJwO4wIm66boQPaD/6Um3Mv20wu+mi4w/qtj0tBRrWjcvjohoOW30lfauM PDiGQZXTLvmJD3gYP3yhKhni0JTSisUCUXD8xvE/DBOBy8BGqurnHvNNqPVNpdI+HTmA I7xwDxuLYlENM4mqGm8BxtzvA9sgaiYfVg5qUhYuExYLaPJR2j+7BN2NVrEpcRZmKGrM EK5Q== 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=bueVbPYbNx71wyfwmv4L5lxMvsZGKE6y1RQGfJ50EuGHT8NpRLI3HgHXtNpQaSXFU8 OeL9ldGAex9fblZqp9tcH6gmSmN6invxKLFBehBMIXmiLBZXsyBCnsF8z17+jTwayGqQ pQ8ET2E/NTEBuiR8aOgt87ca1jRxDuSTxJEqkUBguI+QDyQ9leHuRDP2XZui8iq64cEW Xg95xIo4AMtl/T5PoiwQpIyzw7kIsRixGHV7vc4lI2/ypHbOSfjxykgOM6pYTyI6IAMd 5X/0+Ha/LG3xnCPgjBoRvtaJOaccNxlh0NGWvJq3TN9y4kGgqtv8GYa752IlvA0ATafu 3cWw== X-Gm-Message-State: APjAAAUsmEGb5y2BqOoNPk1ZEFk90OUKbIIgS+CpDJNu7g7x+8q9LR4p U6VoX1SgZKNfQa6y2zGP2EQ= X-Google-Smtp-Source: APXvYqw9pqGDQLDvev7hWSvpe+IZ4GA3cqzDzC2rsG73IuYK6jyFsZLC/yydvfpq4ECwqpBO6ip3RA== X-Received: by 2002:a65:4844:: with SMTP id i4mr31635821pgs.347.1553662759269; Tue, 26 Mar 2019 21:59:19 -0700 (PDT) Received: from localhost.localdomain ([2001:268:c0a5:6014:c70:4af9:86e2:2]) by smtp.gmail.com with ESMTPSA id y12sm26769011pgq.64.2019.03.26.21.59.14 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Tue, 26 Mar 2019 21:59:18 -0700 (PDT) From: William Breathitt Gray To: linus.walleij@linaro.org, bgolaszewski@baylibre.com Cc: akpm@linux-foundation.org, linux-gpio@vger.kernel.org, linux-arch@vger.kernel.org, linux-kernel@vger.kernel.org, andriy.shevchenko@linux.intel.com, linux@rasmusvillemoes.dk, yamada.masahiro@socionext.com, linux-arm-kernel@lists.infradead.org, linux-pm@vger.kernel.org, geert@linux-m68k.org, preid@electromag.com.au, William Breathitt Gray Subject: [PATCH v13 05/11] gpio: gpio-mm: Utilize for_each_set_clump8 macro Date: Wed, 27 Mar 2019 14:00:10 +0900 Message-Id: <09275d98903df1b8c43b7fb469f5bc1ea562285b.1553661964.git.vilhelm.gray@gmail.com> X-Mailer: git-send-email 2.21.0 In-Reply-To: References: MIME-Version: 1.0 Sender: linux-pm-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-pm@vger.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP Replace verbose implementation in get_multiple/set_multiple callbacks with for_each_set_clump8 macro to simplify code and improve clarity. Reviewed-by: Linus Walleij Signed-off-by: William Breathitt Gray --- drivers/gpio/gpio-gpio-mm.c | 73 +++++++++++-------------------------- 1 file changed, 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 Wed Mar 27 05:00:34 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: 10872505 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 7699714DE for ; Wed, 27 Mar 2019 04:59:46 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 616FD28758 for ; Wed, 27 Mar 2019 04:59:46 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 558B528BBD; Wed, 27 Mar 2019 04:59: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=-8.0 required=2.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,FREEMAIL_FROM,MAILING_LIST_MULTI,RCVD_IN_DNSWL_HI autolearn=ham version=3.3.1 Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id C986928758 for ; Wed, 27 Mar 2019 04:59:45 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726392AbfC0E7j (ORCPT ); Wed, 27 Mar 2019 00:59:39 -0400 Received: from mail-pf1-f195.google.com ([209.85.210.195]:36045 "EHLO mail-pf1-f195.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726358AbfC0E7j (ORCPT ); Wed, 27 Mar 2019 00:59:39 -0400 Received: by mail-pf1-f195.google.com with SMTP id p10so9147075pff.3; Tue, 26 Mar 2019 21:59:38 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=qhXdbnOxR8IcT7b6oZcrLksWSW3Riv+VrvVQHErm2EM=; b=gwEAP9GrydoTtYhHNr0uqtkUfGhqgQ3kbw57kbahUFeIbfZeHOMgcy1OtYqzNQ9Rik ZAD+/ZqVyx2J9eLSc8cQCE3fFQTIzuH6cLczCYkXI2iFqSqJVUh1v/IS2Z3L5/HwIx3C zY/tB9SFGwusVeEENOQ/QqrbSsdKIUXcqYO0QiCySOrZmgYlIMZ2vLuNxJdYUeM0Oh03 p6QabOfXbwB16Ut9MNOl/a5mOWGJ0udnMPlrjuUJIhLdt/wWGM9H89KBT+qR/cOVrx+N WqSHnYENCPuKZyVLhal2Qr/zg0ujZAr4dqDFMWiruHdfj0C4HI5mg9gu66GcDt7RklHZ 7NUA== 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=tU4Z5H9uO+sdf5YXj88h+VUiq6+a8uNu/9fKyOEY2SSgB26lnDCg8+Dy/f4loprj9X Ol/OzlxuLatW6xsSKMZu3ch8/sNOnFZO4GvWu9mssHcMLgdRYFHQ9zBOX5HmkIA/4EDg Z4m3lrrBYaBHY1xsou5denhvj8bB4Yxkz7pks/ld2YUW+Qx9YpILcuVuHQXEQ5wmwIcv W5/2adL3FnaHWhJQvzvdYig+m+Th1efJJjXc9DykmfMMdbpRNXMc93UwuzT044fcz8AI jYA26kCClwSTd16zDIz9p2/JM0yp6QvsPTeLOZDt9uYTvDnE0A5IbzmjthLS76ukCoRu 3bzQ== X-Gm-Message-State: APjAAAU5g+vt8DpIBZXGyRc4+7tPCs2QzrrabaXNYkv17VWt/3GQZZ9V KISrE5ViG4pm1bncbIei/x4= X-Google-Smtp-Source: APXvYqxa/iVOaeCWIDM9+3BJzH8fnANPK5Yqmrl2pniOvStbPri0TqYEZgBlq4j/FXknWDG2+dG5zQ== X-Received: by 2002:a62:5543:: with SMTP id j64mr33305459pfb.105.1553662778635; Tue, 26 Mar 2019 21:59:38 -0700 (PDT) Received: from localhost.localdomain ([2001:268:c0a5:6014:c70:4af9:86e2:2]) by smtp.gmail.com with ESMTPSA id p86sm35800592pfa.104.2019.03.26.21.59.31 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Tue, 26 Mar 2019 21:59:38 -0700 (PDT) From: William Breathitt Gray To: linus.walleij@linaro.org, bgolaszewski@baylibre.com Cc: akpm@linux-foundation.org, linux-gpio@vger.kernel.org, linux-arch@vger.kernel.org, linux-kernel@vger.kernel.org, andriy.shevchenko@linux.intel.com, linux@rasmusvillemoes.dk, yamada.masahiro@socionext.com, linux-arm-kernel@lists.infradead.org, linux-pm@vger.kernel.org, geert@linux-m68k.org, preid@electromag.com.au, William Breathitt Gray Subject: [PATCH v13 06/11] gpio: ws16c48: Utilize for_each_set_clump8 macro Date: Wed, 27 Mar 2019 14:00:34 +0900 Message-Id: <728fe1eccac5117aa1c61bfa1003366b511d9d58.1553661964.git.vilhelm.gray@gmail.com> X-Mailer: git-send-email 2.21.0 In-Reply-To: References: MIME-Version: 1.0 Sender: linux-pm-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-pm@vger.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP Replace verbose implementation in get_multiple/set_multiple callbacks with for_each_set_clump8 macro to simplify code and improve clarity. Reviewed-by: Linus Walleij Signed-off-by: William Breathitt Gray --- drivers/gpio/gpio-ws16c48.c | 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 Wed Mar 27 05:00:53 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: 10872509 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 3C9E6139A for ; Wed, 27 Mar 2019 05:00:01 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 28CD928758 for ; Wed, 27 Mar 2019 05:00:01 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 1C99928C19; Wed, 27 Mar 2019 05:00:01 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-8.0 required=2.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,FREEMAIL_FROM,MAILING_LIST_MULTI,RCVD_IN_DNSWL_HI autolearn=ham version=3.3.1 Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id A347828758 for ; Wed, 27 Mar 2019 05:00:00 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727328AbfC0FAA (ORCPT ); Wed, 27 Mar 2019 01:00:00 -0400 Received: from mail-pg1-f196.google.com ([209.85.215.196]:40989 "EHLO mail-pg1-f196.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1725613AbfC0E77 (ORCPT ); Wed, 27 Mar 2019 00:59:59 -0400 Received: by mail-pg1-f196.google.com with SMTP id f6so5222826pgs.8; Tue, 26 Mar 2019 21:59:58 -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=ac50dJOb//RJN+hEGpzU97wnNrD9H4Cs+VgJS1YC9zsDxjW95Zc/Wir7tFfZj3yjoy MahuXnpxy6qn5tQ8zYZduAgEgxe8DTPWE1S9q5Cq0e8JoWXAjLQyPPVLfOWCNyeVyNbV qo49esRcIfNy59iOhau9RHOKKUA517hzZeXBmdZQSi0mEKwCORqQAxYbIIAkRt3hG/x9 H5FqXgODbwy0ZFk0c2smbvgeLTFlBh4RMqg1WhRZEUEwlnfZYZMxI3lUbeB2qrou0gWE CobkMtXmj1nknn4rxCQv3xn6frKiDiEXUv+4kEaXMel+saRHNo0csLh3GvvxHoSQuMfq fAxQ== 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=Ek88MCKbtDK1X0tULpYiYailyS1svn7+jXVA2+/Uwbo6glY0cORSWblUA+D3nO98GT pmX1e6GaxlT+XcYdsgNLXPlOEWt9kmqYx9PxPjf5BDhv1vj6KIGv8n8g1p/IUv6D/sKY H84NzC1f379bOswA010V6ut4Tol9g2mSHLa3nTE12XcRcqFN1AiVZVVEAW3pF0YLHAOz LhludlexyDpS0LE9rQtM9GexOzqnkrsGV1J/akvjr2jwsE7OkNVlj/ztzUQEs45YaHcF bID6kMkIFFsYGAJfLrctL7y+0dbjUxzTW5Mvek1wJr4XTKG75mdP1GFu2nmF6N/auLk3 uoug== X-Gm-Message-State: APjAAAVE2lay46PIXpWRf4iREbPwjMpAR0w9WrfjH19sEEm7jIyrW4gW 4GRaB1z4BY52o/KZStx9dqs= X-Google-Smtp-Source: APXvYqwyrim8K8IdJ/eBKlgxpvfqB1BoJjWgqgKxJB76F8yWv7xE74d9bC3gvfz6CJUQfHoTmC+acg== X-Received: by 2002:a63:1064:: with SMTP id 36mr5257983pgq.155.1553662798642; Tue, 26 Mar 2019 21:59:58 -0700 (PDT) Received: from localhost.localdomain ([2001:268:c0a5:6014:c70:4af9:86e2:2]) by smtp.gmail.com with ESMTPSA id g73sm1086022pfd.185.2019.03.26.21.59.51 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Tue, 26 Mar 2019 21:59:58 -0700 (PDT) From: William Breathitt Gray To: linus.walleij@linaro.org, bgolaszewski@baylibre.com Cc: akpm@linux-foundation.org, linux-gpio@vger.kernel.org, linux-arch@vger.kernel.org, linux-kernel@vger.kernel.org, andriy.shevchenko@linux.intel.com, linux@rasmusvillemoes.dk, yamada.masahiro@socionext.com, linux-arm-kernel@lists.infradead.org, linux-pm@vger.kernel.org, geert@linux-m68k.org, preid@electromag.com.au, William Breathitt Gray Subject: [PATCH v13 07/11] gpio: pci-idio-16: Utilize for_each_set_clump8 macro Date: Wed, 27 Mar 2019 14:00:53 +0900 Message-Id: <4698abb45402d0671e0400be7133e3ccdc2b9fe1.1553661964.git.vilhelm.gray@gmail.com> X-Mailer: git-send-email 2.21.0 In-Reply-To: References: MIME-Version: 1.0 Sender: linux-pm-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-pm@vger.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP Replace verbose implementation in get_multiple/set_multiple callbacks with for_each_set_clump8 macro to simplify code and improve clarity. Reviewed-by: Linus Walleij Signed-off-by: William Breathitt Gray --- drivers/gpio/gpio-pci-idio-16.c | 75 ++++++++++++--------------------- 1 file changed, 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 Wed Mar 27 05:01:13 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: William Breathitt Gray X-Patchwork-Id: 10872513 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 E6AF8139A for ; Wed, 27 Mar 2019 05:00:22 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id D00A028758 for ; Wed, 27 Mar 2019 05:00:22 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id BEB7928C19; Wed, 27 Mar 2019 05:00:22 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-8.0 required=2.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,FREEMAIL_FROM,MAILING_LIST_MULTI,RCVD_IN_DNSWL_HI autolearn=ham version=3.3.1 Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 2C5DC28758 for ; Wed, 27 Mar 2019 05:00:22 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1725807AbfC0FAV (ORCPT ); Wed, 27 Mar 2019 01:00:21 -0400 Received: from mail-pg1-f196.google.com ([209.85.215.196]:41028 "EHLO mail-pg1-f196.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1725613AbfC0FAU (ORCPT ); Wed, 27 Mar 2019 01:00:20 -0400 Received: by mail-pg1-f196.google.com with SMTP id f6so5223345pgs.8; Tue, 26 Mar 2019 22:00:20 -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=kLby6UMMUISj9YX3QMOybUionexQpzW4Cnh9y8rHOG0lTQidh8H25i2C2nMCxgT+iR B6cOJUpNVrUL32UMZN5gUFBPXr+nm/LKXbnXE/MURr6L8Co7zasVkTAfWOStrTb6LFMn DhIa7tHG9GpyOOZu+6SQkDwgH/bulkp7GTAdYr+J19HxbYw14DRSWej/fk1oPKmqtHQ9 dhcOYIzhPEugC7fX9og+6X+JYD078OY+GqYmnoqNInAZI0SDPI1YLuCVGnlGvKgqDgnh pGamrec1z4Yrez30Ey884dWgAzeMafuBYEhrfhTs4/0xDzKsBSH8w0tPi7n6OUEN7Q19 BEXA== 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=hcCSZk/iFmJY8T4N226jjUciJeUsiSrnCZHhdYfwl4ghB6ezaPAryvW082xOeWy+BN 9z0bdvgohyAL2buJzGFwgLm5H3sFOj6iHVczy8IxXglfnn+9BXfZktDhOepjYJ6OPPvi Oa2BLsp59L755LjIe42NIEJeD3YMQIw0MxnRxewZ67/g46HLt4ZdzTVIGpViI73SqPHU cCBs4ilz1LUfapML4zheEEs1E2EcfJ3NR4ZAmg2mzBbvYmteVFHvBg9yyBdyKHCHwmwn 7Cu33/J77TQLm9nRTPEawUiuec2TNrC03ADMR9acak41iZ4hX/CU0IGOQBK9OXcvBkh/ zvKA== X-Gm-Message-State: APjAAAVMqxFrOvLduT0iytmx4wRwjK7hWXJ+YE0kESu9sLRnOdN+KMK2 STtevXUFjRhRU3/zBuX+4GA= X-Google-Smtp-Source: APXvYqz1kD55kg6GG7SDVFuBdsfAb/ei7DPNUHoceb7E6zL086rWJB2GQiYauDMqiz2ujovfzzNQvw== X-Received: by 2002:a63:570d:: with SMTP id l13mr24905748pgb.55.1553662820110; Tue, 26 Mar 2019 22:00:20 -0700 (PDT) Received: from localhost.localdomain ([2001:268:c0a5:6014:c70:4af9:86e2:2]) by smtp.gmail.com with ESMTPSA id e15sm28629604pgk.30.2019.03.26.22.00.15 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Tue, 26 Mar 2019 22:00:19 -0700 (PDT) From: William Breathitt Gray To: linus.walleij@linaro.org, bgolaszewski@baylibre.com Cc: akpm@linux-foundation.org, linux-gpio@vger.kernel.org, linux-arch@vger.kernel.org, linux-kernel@vger.kernel.org, andriy.shevchenko@linux.intel.com, linux@rasmusvillemoes.dk, yamada.masahiro@socionext.com, linux-arm-kernel@lists.infradead.org, linux-pm@vger.kernel.org, geert@linux-m68k.org, preid@electromag.com.au, William Breathitt Gray Subject: [PATCH v13 08/11] gpio: pcie-idio-24: Utilize for_each_set_clump8 macro Date: Wed, 27 Mar 2019 14:01:13 +0900 Message-Id: <93e629552491a546c838519ee3b0dbe4bc08f3ed.1553661964.git.vilhelm.gray@gmail.com> X-Mailer: git-send-email 2.21.0 In-Reply-To: References: MIME-Version: 1.0 Sender: linux-pm-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-pm@vger.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP Replace verbose implementation in get_multiple/set_multiple callbacks with for_each_set_clump8 macro to simplify code and improve clarity. Reviewed-by: Linus Walleij Signed-off-by: William Breathitt Gray --- drivers/gpio/gpio-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 Wed Mar 27 05:02:20 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: 10872517 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 0AC04139A for ; Wed, 27 Mar 2019 05:01:28 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id E871128429 for ; Wed, 27 Mar 2019 05:01:27 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id DC1CB28C50; Wed, 27 Mar 2019 05:01:27 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-8.0 required=2.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,FREEMAIL_FROM,MAILING_LIST_MULTI,RCVD_IN_DNSWL_HI autolearn=ham version=3.3.1 Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 64AAE28429 for ; Wed, 27 Mar 2019 05:01:27 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1725763AbfC0FB0 (ORCPT ); Wed, 27 Mar 2019 01:01:26 -0400 Received: from mail-pf1-f196.google.com ([209.85.210.196]:38580 "EHLO mail-pf1-f196.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1725613AbfC0FB0 (ORCPT ); Wed, 27 Mar 2019 01:01:26 -0400 Received: by mail-pf1-f196.google.com with SMTP id 10so9147170pfo.5; Tue, 26 Mar 2019 22:01:26 -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=uQyk8R0py7UcGbhlLGdW/9Nv1ykF7ezJedfRqJMZf/2BH3uU9YMwLv2AxpRIQEL0tJ fDXgKX03TyTUWCj6FdlVlx/c6dkOR5uhFbuJhHI4Rj0v+bnjAja5EdqVQV8O7OJYzZNY RzrxlaON7mgw22IlE+Ni4o7/M93Uvmqm0wxO75WjbxSNo9v02/tMYCmyKC/Clu0r1KLj fyPBXTegeWjZzictHs0EG+R+dyS+YT3GH8vNhX7VsYq0bVF4BTEqrTx0S699XB+LmHeB GUdPF1POnQGe2cFxFE36FF/by/CVHbwwC8JTZoDLuhD/U3YBPqMKWxD+7KibfJLUmbfO tOXw== 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=BMn7zfNbGh5opcIphf7+eZ8ciaKamd/ui8uqjbNwitLSY6ZQnMGZJ6ecDgg95teIkv 1jk/hjmI4l2ehWawu2R23KZMEOqkyGf6JORLfUcLKj3zt2Sp8Ei9FyiXpRJn9aLylTqb Tef1WPWv34xht/hZXU+J4N7ykRj8op172nAPJEPOZZYUigaEUydiUYa3B9lENj4MVUf5 VV1Qi3ZMO1PdtPD1WFq5iBz69ESjFtatQHbaF2DsNVq1IiL77Z/5WVu20DGUQDBTv7mw ZBhqDGKuRGO1L5HQ6zgxP+Zzn5UrBaxVE4/lo39xmeWOldBbZa/Wei5rig/beXd5Ot+J 7dmA== X-Gm-Message-State: APjAAAV5dRCVMJbXDApkjGA1lmgu5kNLkgf2MTpdkGIEO1DMLDdBtoW2 SlHdrhUo/6Z9PDVhSYatdRM= X-Google-Smtp-Source: APXvYqy8chgZQxN1dbU1Rt8odCCSTgnvSjwQecTcyPAZzo6VKRdqUrpBsaL34+XVHdAO/Z1iurzsAA== X-Received: by 2002:aa7:8190:: with SMTP id g16mr6378755pfi.92.1553662885842; Tue, 26 Mar 2019 22:01:25 -0700 (PDT) Received: from localhost.localdomain ([2001:268:c0a5:6014:c70:4af9:86e2:2]) by smtp.gmail.com with ESMTPSA id k10sm31080261pgj.11.2019.03.26.22.01.19 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Tue, 26 Mar 2019 22:01:25 -0700 (PDT) From: William Breathitt Gray To: linus.walleij@linaro.org, bgolaszewski@baylibre.com Cc: akpm@linux-foundation.org, linux-gpio@vger.kernel.org, linux-arch@vger.kernel.org, linux-kernel@vger.kernel.org, andriy.shevchenko@linux.intel.com, linux@rasmusvillemoes.dk, yamada.masahiro@socionext.com, linux-arm-kernel@lists.infradead.org, linux-pm@vger.kernel.org, geert@linux-m68k.org, preid@electromag.com.au, William Breathitt Gray Subject: [PATCH v13 09/11] gpio: uniphier: Utilize for_each_set_clump8 macro Date: Wed, 27 Mar 2019 14:02:20 +0900 Message-Id: X-Mailer: git-send-email 2.21.0 In-Reply-To: References: MIME-Version: 1.0 Sender: linux-pm-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-pm@vger.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP Replace verbose implementation in 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 Wed Mar 27 05:02:39 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: William Breathitt Gray X-Patchwork-Id: 10872521 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 89A9E925 for ; Wed, 27 Mar 2019 05:01:52 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 75AE728429 for ; Wed, 27 Mar 2019 05:01:52 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 68AA628D52; Wed, 27 Mar 2019 05:01:52 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-8.0 required=2.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,FREEMAIL_FROM,MAILING_LIST_MULTI,RCVD_IN_DNSWL_HI autolearn=ham version=3.3.1 Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 0AE5128429 for ; Wed, 27 Mar 2019 05:01:50 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726358AbfC0FBp (ORCPT ); Wed, 27 Mar 2019 01:01:45 -0400 Received: from mail-pg1-f194.google.com ([209.85.215.194]:41155 "EHLO mail-pg1-f194.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1725613AbfC0FBo (ORCPT ); Wed, 27 Mar 2019 01:01:44 -0400 Received: by mail-pg1-f194.google.com with SMTP id f6so5225299pgs.8; Tue, 26 Mar 2019 22:01:44 -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=0I71euHhTT2+JwpcW5o8Nyy8nGlG1C3w/bjF+uE002A=; b=RxJAI+wrrnLYuf5zN1LqQ0NfP/sRXnHsNkAerPKlXipn3hfibBfpYNyEyXZkV27rvv 1LEtXRdFz0qjzjnTAvIiYMA7TjHI+7o38Xb1wpFPFC4MdzacMWClpF8uQ7jJ1UssfKw1 NB/D4Jyx2Uk4Qdb/dFms8L9Jc3b44ezmBnZYRsKGnCl4WvSJ19dj9zQRdArtaD1+95JK 61n7uZiyp4TctN6ocARJffFWWb41MXz6CajEq9rf19Lzpxi26YPHA5faOg5po3ZiRTJ9 fUW2GoFH5cew28D6mPeJepXDvgqNDmDzbkUeJLo1WUSS7T5dZDPknOzeL37S6/XoDpSM s3qg== 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=0I71euHhTT2+JwpcW5o8Nyy8nGlG1C3w/bjF+uE002A=; b=TVsLPGcO7sgKGy8VgUMlYhKg4U9wZso/++x1oyFM5rFiQykr/I7eIbWdONor7KcEI2 lQszT+Q/tNAS9Xt54LexJq+W6AoIMblo6c1XgkBA4S9Go0wru5cFcQ4+fxHGvQI1YsLi XD6B9MecB+59l1qpgyVmiGFn/RtAslWHuzVsh3eKbkZab0F2YoUM+wAhbVXCHEZchvRK gwKjbhw5UyaPPtThzzZvjR589BWwu6dihdHCq+4/Ig1Z3T/uLdtMTG0ufgKEiz3DnpEF eKaaKCYtBzhT90G8f2uqnoieFaNo7L/1vXWZmgSvYHrbaPg4rzcsTtkVOginMl+SB1cn EDOQ== X-Gm-Message-State: APjAAAWSvA8Xer2o2kp/yYKLxMdosmbLBnuyFMgI9vIlgprN9JarFxWz FYEQZNZeDIGvNLDrlmnP5MM= X-Google-Smtp-Source: APXvYqy8zgtoeHpZ4u2hckq1rici1mAiaKRLX+aQROjYLbCJtAExdV6KIq7Rxz2ipsv5r7oqvAD8NA== X-Received: by 2002:aa7:82d9:: with SMTP id f25mr33179072pfn.45.1553662904075; Tue, 26 Mar 2019 22:01:44 -0700 (PDT) Received: from localhost.localdomain ([2001:268:c0a5:6014:c70:4af9:86e2:2]) by smtp.gmail.com with ESMTPSA id 143sm2358172pge.50.2019.03.26.22.01.38 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Tue, 26 Mar 2019 22:01:43 -0700 (PDT) From: William Breathitt Gray To: linus.walleij@linaro.org, bgolaszewski@baylibre.com Cc: akpm@linux-foundation.org, linux-gpio@vger.kernel.org, linux-arch@vger.kernel.org, linux-kernel@vger.kernel.org, andriy.shevchenko@linux.intel.com, linux@rasmusvillemoes.dk, yamada.masahiro@socionext.com, linux-arm-kernel@lists.infradead.org, linux-pm@vger.kernel.org, geert@linux-m68k.org, preid@electromag.com.au, William Breathitt Gray , Geert Uytterhoeven Subject: [PATCH v13 10/11] gpio: 74x164: Utilize the for_each_set_clump8 macro Date: Wed, 27 Mar 2019 14:02:39 +0900 Message-Id: <645f16f1d1ad3f215e34a82f457e06725fcf8f56.1553661964.git.vilhelm.gray@gmail.com> X-Mailer: git-send-email 2.21.0 In-Reply-To: References: MIME-Version: 1.0 Sender: linux-pm-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-pm@vger.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP Replace verbose implementation in set_multiple callback with for_each_set_clump8 macro to simplify code and improve clarity. Suggested-by: Andy Shevchenko Cc: Geert Uytterhoeven Cc: Phil Reid Signed-off-by: William Breathitt Gray --- drivers/gpio/gpio-74x164.c | 19 +++++++++---------- 1 file changed, 9 insertions(+), 10 deletions(-) diff --git a/drivers/gpio/gpio-74x164.c b/drivers/gpio/gpio-74x164.c index fb7b620763a2..0bbf1162bb31 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 Wed Mar 27 05:02:57 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: 10872525 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 AE874139A for ; Wed, 27 Mar 2019 05:02:08 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 9428328429 for ; Wed, 27 Mar 2019 05:02:08 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 8479A28C50; Wed, 27 Mar 2019 05:02: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=-8.0 required=2.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,FREEMAIL_FROM,MAILING_LIST_MULTI,RCVD_IN_DNSWL_HI autolearn=ham version=3.3.1 Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 073C028429 for ; Wed, 27 Mar 2019 05:02:08 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1731915AbfC0FCC (ORCPT ); Wed, 27 Mar 2019 01:02:02 -0400 Received: from mail-pl1-f193.google.com ([209.85.214.193]:45797 "EHLO mail-pl1-f193.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1725613AbfC0FCC (ORCPT ); Wed, 27 Mar 2019 01:02:02 -0400 Received: by mail-pl1-f193.google.com with SMTP id bf11so2731729plb.12; Tue, 26 Mar 2019 22:02:01 -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=dGvvPxIy/m4VZWdnvn/MiQ00fT/OPgP3hhe0kjEdXiNMUSgYnE8YUJCaXlzO9BEbky 95qqpJU4hCCwHrTOf5tor7PQ8JXUu9lC3pWT1dh1YuGS6rAD0/bJYClZ1vM0KdhorNjv VSfOZo1Vai/sIP+yH5FMXkphSs9334PDdFl7/b7dnnng3utFIFiY6jm8psRCu47dCM7W 3i2dFdPb3pKfmGT+9XfAYuLCHKGarFWE07KbzF4vX5Kt4qCr557/zyWsNQKpUApLezzi qkRxeHkALUZn7RQw0xY/Ic7GN9qpsVnMEsfg0vZclIBNwA+nwp+VXjK+6r+5W1Cw4gER GnRg== 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=X0aqCpKXseLESYhQCQ2pqwUKZxfWtefW639d5oKmuzgRq9ET7BmF30rDYPJ3tt4O8M YKCpNfWejBZw0vPveQ74Dgvw3NlgFNu6VzkUcpa8fmUim4ztJyzS2YVFOXJ+rzYWlJwh SHWWKyDE29NOz1owu4XndfLZRJcuyUn7yeiXOKxYapKxb0Rryx6KJrtlrOxycthAg1i8 BpaKgGnXT8FVI+/Xe5UoT8jwq+Sgnp6IF55s3+LwU18D8QkBoFDxqX/bMWHMmL+oTKfe d85tqD0013xmRlRhE+n1dJ8g0oN78UkYgmuXDSta7EBt6i4La55BIuPvEjRJ7vUOc/S9 uIkQ== X-Gm-Message-State: APjAAAXctgr11bV609ILMd9Erc23kQUIwRiNbL6rweYE6cp/b38CSkU/ NuY3IlpK/qYwusqOdtvEInU= X-Google-Smtp-Source: APXvYqzlK6yAH+z2MpWlMuT24AimhcSTFq81vcQA1qzet5WlawC79ydrqZzjLC5p8V58SsuIBf/0Uw== X-Received: by 2002:a17:902:7b90:: with SMTP id w16mr35646281pll.228.1553662920954; Tue, 26 Mar 2019 22:02:00 -0700 (PDT) Received: from localhost.localdomain ([2001:268:c0a5:6014:c70:4af9:86e2:2]) by smtp.gmail.com with ESMTPSA id d20sm7014940pfo.77.2019.03.26.22.01.56 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Tue, 26 Mar 2019 22:02:00 -0700 (PDT) From: William Breathitt Gray To: linus.walleij@linaro.org, bgolaszewski@baylibre.com Cc: akpm@linux-foundation.org, linux-gpio@vger.kernel.org, linux-arch@vger.kernel.org, linux-kernel@vger.kernel.org, andriy.shevchenko@linux.intel.com, linux@rasmusvillemoes.dk, yamada.masahiro@socionext.com, linux-arm-kernel@lists.infradead.org, linux-pm@vger.kernel.org, geert@linux-m68k.org, preid@electromag.com.au, William Breathitt Gray Subject: [PATCH v13 11/11] thermal: intel: intel_soc_dts_iosf: Utilize for_each_set_clump8 macro Date: Wed, 27 Mar 2019 14:02:57 +0900 Message-Id: <2a9aec7e4601b1b0ea4494e1b8d3f7d200a12007.1553661964.git.vilhelm.gray@gmail.com> X-Mailer: git-send-email 2.21.0 In-Reply-To: References: MIME-Version: 1.0 Sender: linux-pm-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-pm@vger.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP Utilize for_each_set_clump8 macro, and the bitmap_set_value8 and bitmap_get_value8 functions, where appropriate. In addition, remove the now unnecessary temp_mask and temp_shift members of the intel_soc_dts_sensor_entry structure. Suggested-by: Andy Shevchenko Tested-by: Andy Shevchenko Signed-off-by: William Breathitt Gray --- drivers/thermal/intel/intel_soc_dts_iosf.c | 29 +++++++++++++--------- drivers/thermal/intel/intel_soc_dts_iosf.h | 2 -- 2 files changed, 17 insertions(+), 14 deletions(-) diff --git a/drivers/thermal/intel/intel_soc_dts_iosf.c b/drivers/thermal/intel/intel_soc_dts_iosf.c index e0813dfaa278..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;