From patchwork Wed Dec 19 06:00:39 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: William Breathitt Gray X-Patchwork-Id: 1015841 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: ozlabs.org; spf=none (mailfrom) smtp.mailfrom=vger.kernel.org (client-ip=209.132.180.67; helo=vger.kernel.org; envelope-from=linux-gpio-owner@vger.kernel.org; receiver=) Authentication-Results: ozlabs.org; dmarc=pass (p=none dis=none) header.from=gmail.com Authentication-Results: ozlabs.org; dkim=pass (2048-bit key; unprotected) header.d=gmail.com header.i=@gmail.com header.b="TqubCjyI"; dkim-atps=neutral Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by ozlabs.org (Postfix) with ESMTP id 43KPPk0ZJnz9s3Z for ; Wed, 19 Dec 2018 17:00:26 +1100 (AEDT) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727729AbeLSGAM (ORCPT ); Wed, 19 Dec 2018 01:00:12 -0500 Received: from mail-pg1-f194.google.com ([209.85.215.194]:46937 "EHLO mail-pg1-f194.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726920AbeLSGAM (ORCPT ); Wed, 19 Dec 2018 01:00:12 -0500 Received: by mail-pg1-f194.google.com with SMTP id w7so8945479pgp.13; Tue, 18 Dec 2018 22:00:11 -0800 (PST) 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=u1oZXhPLBwf6ld/Ap5bG26cpxbbDtyrh+8dpvM7Fc0E=; b=TqubCjyIfIJJbFdMSsP5578TCHQFawBB5j28IM913BWu5NKWtsn34/uCMSTVNW+dXK W+CieSYpmmOY2V6v52Oi7HfZKhlNUs6J5tiRvUGOlR++7Eq9PCAKNH+YSk6e4IfFCx5w HmiqWVM/DB7pini343cGVPIo3a2Z0nfnDurTiJjWjX650ibEs6c5MYNzx0XDsf20BvW1 Ch/hmOWNJ8ojH5CV0WP87ghMiqRquCy26aSFS8F0oOGppddcf4bS/6mOfh9MnuSce7eb 8wQBx/MoD4nUEymCKinPHg/z8/uRhxCqohJGo7yfdUQbR2jyB0v/6ahsho2RCNxG49yu 6P0Q== 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=u1oZXhPLBwf6ld/Ap5bG26cpxbbDtyrh+8dpvM7Fc0E=; b=HNda6cRBeShPP3OCVtuHWLmdCbAL5AbzwN98rfWxopxuvDAOH9D7NydpLlRfbr6S2L 9jPEw11MZf7j/o1arIUi6NNnCrlrMwc4YC3CKUxSo7EFFJD0/Tu+Cd5YWITHZNQJSSc7 fXaNXGaAzA3lrKa4TraMHBv/GJQT/lupimbRIdyKr40U1cqzbM5Ad0flgosm6C9OhK51 z7nXhWYiC7nV6f2wOS61HOMfMP+d4Vfrm1LYygLi5S879/LxjYyk3B7MF6+qdLAAOdh6 lEmM4i+WwRQQmCps9zULSutM8eYu6qXMLJkqWxY0G2fXf9XlAMw/HRxPmS1Hh7/navRF /GpQ== X-Gm-Message-State: AA+aEWaH6RZBaL/bNMUG85MVM+JQhy6uBCJWpEmfdXd76PD8JZa4GSJG 3o/LZR9haND+bx+FQpGL4WmwJPst X-Google-Smtp-Source: AFSGD/WdnZ2lJ9Y2Xvo7N21mpAuZKWH8m/p5IqXc3iIbpashwifPPehbLDpY6fIZ2XKZcB8unP1i/g== X-Received: by 2002:a63:ac46:: with SMTP id z6mr1850033pgn.162.1545199211433; Tue, 18 Dec 2018 22:00:11 -0800 (PST) Received: from localhost.localdomain ([2001:268:c0a2:eb51:6018:45d4:55a2:e94b]) by smtp.gmail.com with ESMTPSA id h15sm20600853pgl.43.2018.12.18.22.00.07 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Tue, 18 Dec 2018 22:00:10 -0800 (PST) From: William Breathitt Gray To: linus.walleij@linaro.org 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, William Breathitt Gray , Andy Shevchenko , Arnd Bergmann Subject: [PATCH v6 1/8] bitops: Introduce the for_each_set_clump8 macro Date: Wed, 19 Dec 2018 15:00:39 +0900 Message-Id: <9fb3981cbcfbce3fb8b42bf419d734c0e5a44d0e.1545198260.git.vilhelm.gray@gmail.com> X-Mailer: git-send-email 2.20.1 In-Reply-To: References: MIME-Version: 1.0 Sender: linux-gpio-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-gpio@vger.kernel.org This macro iterates for each 8-bit group of bits (clump) with set bits, within a bitmap memory region. For each iteration, "start" is set to the bit offset of the found clump, while the respective clump value is stored to the location pointed by "clump". Additionally, the bitmap_get_value8 and bitmap_set_value8 functions are introduced to respectively get and set an 8-bit value in a bitmap memory region. Suggested-by: Andy Shevchenko Suggested-by: Rasmus Villemoes Cc: Arnd Bergmann Cc: Andrew Morton Signed-off-by: William Breathitt Gray --- include/asm-generic/bitops/find.h | 14 +++++++ include/linux/bitops.h | 5 +++ lib/find_bit.c | 63 +++++++++++++++++++++++++++++++ 3 files changed, 82 insertions(+) diff --git a/include/asm-generic/bitops/find.h b/include/asm-generic/bitops/find.h index 8a1ee10014de..457b93e6f5c9 100644 --- a/include/asm-generic/bitops/find.h +++ b/include/asm-generic/bitops/find.h @@ -80,4 +80,18 @@ extern unsigned long find_first_zero_bit(const unsigned long *addr, #endif /* CONFIG_GENERIC_FIND_FIRST_BIT */ +unsigned int bitmap_get_value8(const unsigned long *const bitmap, + const unsigned int start); + +void bitmap_set_value8(unsigned long *const bitmap, + const unsigned long *const value, + const unsigned int start); + +unsigned int find_next_clump8(unsigned long *const clump, + const unsigned long *const addr, + unsigned int offset, const unsigned int size); + +#define find_first_clump8(clump, bits, size) \ + find_next_clump8((clump), (bits), 0, (size)) + #endif /*_ASM_GENERIC_BITOPS_FIND_H_ */ diff --git a/include/linux/bitops.h b/include/linux/bitops.h index 705f7c442691..61c10f20079e 100644 --- a/include/linux/bitops.h +++ b/include/linux/bitops.h @@ -40,6 +40,11 @@ extern unsigned long __sw_hweight64(__u64 w); (bit) < (size); \ (bit) = find_next_zero_bit((addr), (size), (bit) + 1)) +#define for_each_set_clump8(start, clump, bits, size) \ + for ((start) = find_first_clump8(&(clump), (bits), (size)); \ + (start) < (size); \ + (start) = find_next_clump8(&(clump), (bits), (start) + 8, (size))) + static inline int get_bitmask_order(unsigned int count) { int order; diff --git a/lib/find_bit.c b/lib/find_bit.c index ee3df93ba69a..2e56d2b907bc 100644 --- a/lib/find_bit.c +++ b/lib/find_bit.c @@ -218,3 +218,66 @@ EXPORT_SYMBOL(find_next_bit_le); #endif #endif /* __BIG_ENDIAN */ + +/** + * bitmap_get_value8 - get an 8-bit value within a memory region + * @bitmap: address to the bitmap memory region + * @start: bit offset of the 8-bit value + * + * Returns the 8-bit value located at the @start bit offset within the @bitmap + * memory region. + */ +unsigned int bitmap_get_value8(const unsigned long *const bitmap, + const unsigned int start) +{ + const size_t index = BIT_WORD(start); + const unsigned int offset = start % BITS_PER_LONG; + + return (bitmap[index] >> offset) & 0xFF; +} +EXPORT_SYMBOL(bitmap_get_value8); + +/** + * bitmap_set_value8 - set an 8-bit value within a memory region + * @bitmap: address to the bitmap memory region + * @value: the 8-bit value + * @start: bit offset of the 8-bit value + */ +void bitmap_set_value8(unsigned long *const bitmap, + const unsigned long *const value, + const unsigned int start) +{ + const size_t index = BIT_WORD(start); + const unsigned int offset = start % BITS_PER_LONG; + const unsigned long mask = GENMASK(7, offset); + + bitmap[index] &= ~mask; + bitmap[index] |= (*value << offset) & mask; +} +EXPORT_SYMBOL(bitmap_set_value8); + +/** + * find_next_clump8 - find next 8-bit clump with set bits in a memory region + * @clump: location to store copy of found clump + * @addr: address to base the search on + * @offset: bit offset at which to start searching + * @size: bitmap size in number of bits + * + * Returns the bit offset for the next set clump; the found clump value is + * copied to the location pointed by @clump. If no bits are set, returns @size. + */ +unsigned int find_next_clump8(unsigned long *const clump, + const unsigned long *const addr, + unsigned int offset, const unsigned int size) +{ + for (; offset < size; offset += 8) { + *clump = bitmap_get_value8(addr, offset); + if (!*clump) + continue; + + return offset; + } + + return size; +} +EXPORT_SYMBOL(find_next_clump8); From patchwork Wed Dec 19 06:00:55 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: William Breathitt Gray X-Patchwork-Id: 1015842 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: ozlabs.org; spf=none (mailfrom) smtp.mailfrom=vger.kernel.org (client-ip=209.132.180.67; helo=vger.kernel.org; envelope-from=linux-gpio-owner@vger.kernel.org; receiver=) Authentication-Results: ozlabs.org; dmarc=pass (p=none dis=none) header.from=gmail.com Authentication-Results: ozlabs.org; dkim=pass (2048-bit key; unprotected) header.d=gmail.com header.i=@gmail.com header.b="FLrEwq39"; dkim-atps=neutral Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by ozlabs.org (Postfix) with ESMTP id 43KPPn11gKz9sB7 for ; Wed, 19 Dec 2018 17:00:29 +1100 (AEDT) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727356AbeLSGA2 (ORCPT ); Wed, 19 Dec 2018 01:00:28 -0500 Received: from mail-pg1-f196.google.com ([209.85.215.196]:42997 "EHLO mail-pg1-f196.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726920AbeLSGA1 (ORCPT ); Wed, 19 Dec 2018 01:00:27 -0500 Received: by mail-pg1-f196.google.com with SMTP id d72so8957610pga.9; Tue, 18 Dec 2018 22:00:27 -0800 (PST) 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=xnUaejTO+RHAIQg3+66gxDXJKefuVgpBWyozPBW8nPI=; b=FLrEwq39Dtedo1lXWu9vPxPrs8VKabP7hU3XdGRj1wdQrfW8ERYTnWU00o1IL+LXoA YYkuIwg6K6s72ZxcaQoJhwl+Ta0rHybTa7GCCw1LoNN96+ClZWjd/Unj4FdPwv+DPEUU F1ZOJxqzLu8MJOezGWG8rEze1xOYsjwPBS2NFe+boRsA5m4sfLF3OAyrSMKFiwMKn1LU 6R+uRpEXHs+aE9lalbm78bpGct+1ujgG0cXgWEAkGeoPyQ4X/n+sxoYxzemOB5R7cAOn 4s3Cahua2bDvMcz8P91qK4PsaLqVtHTSDRBizLr44yYg5dqBRDw5WUwxE3Ayv3FOiNUg YB7w== 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=xnUaejTO+RHAIQg3+66gxDXJKefuVgpBWyozPBW8nPI=; b=mTK2WczdkClzVrVxp/4dvDkuL0NjTAsL+EeWRL0PWD/C8gYewBp2Z9IGOSFFcdtIcv 4nVcgsnUt+KLzqZIbKtITMFhFPlumT2HiR76dMfiUvKY/iXQTglOpjFAquu5S7bACLIA 6mUdHd08WyuGMY+7Z4OkNFRMxJ8IHtb5W4om+nzFIHOm2w+z4Qn15W3Rjq+9INqkjW3p mZabPMo0GAlIvUoukWfI+Pyc/z05qm6OHBf5z0fIN8QPJ6X3yig46i04BX8nC4mghrwd xsxnV47YjrdDR4u0oQ27CNOAEYjemhluYPKBlAKndiuKn/x500Rf/MPBiXwfG7C7UO6I aBCg== X-Gm-Message-State: AA+aEWb3SY6a4tVKiNiG2ICyXUymLSefuaj1gc/UAnu5uohJF+Ejpcfh ZfMZ+Boa2Xdf66AMaYYfwOE= X-Google-Smtp-Source: AFSGD/WHmQ9X27h92uOdmBRpRx3CaD6yCd2EJdwDwblDrGSruGB8BueNmhEA6SGaOuI2ok6KnTYHUg== X-Received: by 2002:a63:e5c:: with SMTP id 28mr5404940pgo.369.1545199226912; Tue, 18 Dec 2018 22:00:26 -0800 (PST) Received: from localhost.localdomain ([2001:268:c0a2:eb51:6018:45d4:55a2:e94b]) by smtp.gmail.com with ESMTPSA id y71sm35592141pfi.123.2018.12.18.22.00.22 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Tue, 18 Dec 2018 22:00:26 -0800 (PST) From: William Breathitt Gray To: linus.walleij@linaro.org 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, William Breathitt Gray , Andy Shevchenko Subject: [PATCH v6 2/8] lib/test_bitmap.c: Add for_each_set_clump8 test cases Date: Wed, 19 Dec 2018 15:00:55 +0900 Message-Id: <53bc13df75e9a26ef9fc7ba764c3536b4fc51433.1545198260.git.vilhelm.gray@gmail.com> X-Mailer: git-send-email 2.20.1 In-Reply-To: References: MIME-Version: 1.0 Sender: linux-gpio-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-gpio@vger.kernel.org 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: Andy Shevchenko Cc: Andrew Morton Cc: Rasmus Villemoes 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..66ddb3fb98cb 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 */ + 0x28, /* 3 bits set across 4-bit boundary */ + 0x28, /* 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, 8, 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 Dec 19 06:01:11 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: William Breathitt Gray X-Patchwork-Id: 1015843 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: ozlabs.org; spf=none (mailfrom) smtp.mailfrom=vger.kernel.org (client-ip=209.132.180.67; helo=vger.kernel.org; envelope-from=linux-gpio-owner@vger.kernel.org; receiver=) Authentication-Results: ozlabs.org; dmarc=pass (p=none dis=none) header.from=gmail.com Authentication-Results: ozlabs.org; dkim=pass (2048-bit key; unprotected) header.d=gmail.com header.i=@gmail.com header.b="sUdQoCTO"; dkim-atps=neutral Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by ozlabs.org (Postfix) with ESMTP id 43KPQH0cwXz9s3Z for ; Wed, 19 Dec 2018 17:00:55 +1100 (AEDT) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1725287AbeLSGAs (ORCPT ); Wed, 19 Dec 2018 01:00:48 -0500 Received: from mail-pg1-f193.google.com ([209.85.215.193]:35792 "EHLO mail-pg1-f193.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1725290AbeLSGAs (ORCPT ); Wed, 19 Dec 2018 01:00:48 -0500 Received: by mail-pg1-f193.google.com with SMTP id s198so8969016pgs.2; Tue, 18 Dec 2018 22:00:47 -0800 (PST) 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=OyPcckJ9H9PrTKbckA2hoYoFgyfsOddw9oRRuNtLyW8=; b=sUdQoCTOEGG58uvIG83VfokhzOrjY3aHRNfpnn4uqmwBnPyoudgocGV3ukp0UeuxdK hiEiyWnbEYF8b/tQIUEeL2BOxYkV07vBoBh6y9Q0WEOKJTdTDkuLHlDD+Drd1kulsDPQ oB7arBjoUlUa1+M2Qa8dON8fb5yxSIL10zrICabh0dv/eoMShQ2FKgzdm3sg6igL/gYe EZ8zgRNxR80H62JJxfCEgo0DYKo7puWaFYt6cuarvvrymi9CobDF7uRjZp4i+Tgs2Q2w NiP9nrmq38CnZ6u4fgHl5qCjIkeCDrnSYKbzN0WKiJN1M6gOIKG0qC2MhKOdtGBPjtKv jarw== 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=OyPcckJ9H9PrTKbckA2hoYoFgyfsOddw9oRRuNtLyW8=; b=K1lyVBowyHc5HOjfviQlwQPSfr2t5FhPd1F0Q4WwS506r3+VbKKqySwzQ0mdfBBYFH 5lEjZbtb2hiv/pfB9sD081tRqbZs3i9ikhJ6YfV9fiSap+d9a2rIKgShl3ljXlSjlKAl GvmrHkdZ9u1+iWIepPQ4zaXvz1pPPawS/3JGXuudXLpF1s5hBAj51MG4jYzvR7CaOOGC Wsrfb2SkS93qcZwXuktMZGPNWjl2hdV1yXjUFCaLFIReGHcOllx1AZtRm9Ym603M/kam bhCJ53ywg0XDjbRjWykuwcTmULhDZm9fdbIWS58nblUvL1uadpsqQzp2yLnHEWXwbrj5 wt5A== X-Gm-Message-State: AA+aEWbGUkSf6LaGo4syesA2NFIB4nK9sxEixbFi23lUhKzwsPWDHQ8G uODdow1y8q8YZBur1cv94jE= X-Google-Smtp-Source: AFSGD/WMplKAGrAcY92hFIgCFo4TngZLvkcjOF5l4biXvQvWVNbTB/eEsgUZGbkxf6tJwKeKpUtwEA== X-Received: by 2002:a62:160d:: with SMTP id 13mr19178644pfw.203.1545199247574; Tue, 18 Dec 2018 22:00:47 -0800 (PST) Received: from localhost.localdomain ([2001:268:c0a2:eb51:6018:45d4:55a2:e94b]) by smtp.gmail.com with ESMTPSA id d3sm20020656pgl.64.2018.12.18.22.00.44 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Tue, 18 Dec 2018 22:00:47 -0800 (PST) From: William Breathitt Gray To: linus.walleij@linaro.org 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, William Breathitt Gray Subject: [PATCH v6 3/8] gpio: 104-dio-48e: Utilize for_each_set_clump8 macro Date: Wed, 19 Dec 2018 15:01:11 +0900 Message-Id: <55fb51137ad12bf83a6a57edcad8966ffe74646d.1545198260.git.vilhelm.gray@gmail.com> X-Mailer: git-send-email 2.20.1 In-Reply-To: References: MIME-Version: 1.0 Sender: linux-gpio-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-gpio@vger.kernel.org Replace verbose implementation in get_multiple/set_multiple callbacks with for_each_set_clump8 macro to simplify code and improve clarity. Signed-off-by: William Breathitt Gray --- drivers/gpio/gpio-104-dio-48e.c | 71 ++++++++++----------------------- 1 file changed, 20 insertions(+), 51 deletions(-) diff --git a/drivers/gpio/gpio-104-dio-48e.c b/drivers/gpio/gpio-104-dio-48e.c index 92c8f944bf64..b68c39f8aa23 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 int offset; + unsigned long gpio_mask; + unsigned int port_addr; unsigned long port_state; /* clear bits array to a clean slate */ bitmap_zero(bits, chip->ngpio); - /* get bits are evaluated a gpio port register at a time */ - for (i = 0; i < 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 offset; + unsigned long gpio_mask; + size_t index; + unsigned int port_addr; unsigned int bitmask; unsigned long flags; - /* set bits are evaluated a gpio register size at a time */ - for (i = 0; i < chip->ngpio; i += gpio_reg_size) { - /* no more set bits in this mask word; skip to the next word */ - if (!mask[BIT_WORD(i)]) { - i = (BIT_WORD(i) + 1) * BITS_PER_LONG - gpio_reg_size; - continue; - } + 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 Dec 19 06:01:35 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: William Breathitt Gray X-Patchwork-Id: 1015844 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: ozlabs.org; spf=none (mailfrom) smtp.mailfrom=vger.kernel.org (client-ip=209.132.180.67; helo=vger.kernel.org; envelope-from=linux-gpio-owner@vger.kernel.org; receiver=) Authentication-Results: ozlabs.org; dmarc=pass (p=none dis=none) header.from=gmail.com Authentication-Results: ozlabs.org; dkim=pass (2048-bit key; unprotected) header.d=gmail.com header.i=@gmail.com header.b="EMztUl/C"; dkim-atps=neutral Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by ozlabs.org (Postfix) with ESMTP id 43KPQW4JS3z9s3Z for ; Wed, 19 Dec 2018 17:01:07 +1100 (AEDT) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726652AbeLSGBH (ORCPT ); Wed, 19 Dec 2018 01:01:07 -0500 Received: from mail-pf1-f193.google.com ([209.85.210.193]:35931 "EHLO mail-pf1-f193.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1725290AbeLSGBG (ORCPT ); Wed, 19 Dec 2018 01:01:06 -0500 Received: by mail-pf1-f193.google.com with SMTP id b85so9332616pfc.3; Tue, 18 Dec 2018 22:01:06 -0800 (PST) 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=eB7spxvnRVzN64veVyAd+oRPwk/YF9AvoB3zSfrDoHQ=; b=EMztUl/CYTQJiwZMzKATY8ZZgFmNoEEOhNlEGGP06aROo5hQ0f7GoIMQfTzQSdM6M5 fkF4o/oqL/9aX86vWsMUbQsaxdBfzwlqvNajRafjQTIg3ogUlTdNEnlA/VxKN+fYSoHp Cq4hhxgjyG9UZdLRtPFTawdcNexYV1G/lRkB29/mENrc5ZzE/FYbJ0eqNhFC8WfYa67a HRx6xfSjZbvJJIiPXMAWi+fonjcsdoiOfhcyOtx0cCTulG3YcDPBOdoWxITWAdTIPxh/ FzBjVpOXT5BCp4qTIR0oRNA1/ovzCE5G9sPSTd4zWfnyRSi3t4/ufKKiVyXpePvhRzeT Xc3A== 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=eB7spxvnRVzN64veVyAd+oRPwk/YF9AvoB3zSfrDoHQ=; b=BssbxclL1ajJKUKeBjRMIzBJNuoOenABoNv9oww0wnq5Mh/bWbMtrvsJPOV8WcyOba BU02UNUo5CqFqrbkrjaVI5zIbdE3dxZFV88R7foI3RVKcms+IxLkHlNYKUNOpNxG627R slHxS+IsOg9P4lQKsm50xT3NTABtq8aPTMYc9aNJqBaV3lHQFzc+HJMII7FVQpgHmjeR qb/U9qvat9N9pyCQB8/PybGcTUo1pMj04qZH7fvX4bRXBztnC5+6Qpl8IzBeRtYk8sKy BBGKsHHkNFedgCDShUbvbG6bg9NcRouGThO2/BN300oXnokmKKlguEigQjwqTgUKrXht Bkvw== X-Gm-Message-State: AA+aEWZ9Z2lz5gjGgc76vMdZ3BqT//aFCN52otyMNy2Fuz628AwaA2cs Ds6RwiEMPr7lOjMAoH3rczg= X-Google-Smtp-Source: AFSGD/X8qlK2n2hplDG4tQv2vtWc0LV4NfhJ1pj+xYVqIzWvNUyv6n93sVcwGp3e8NfA1x/ZuORuog== X-Received: by 2002:a63:2946:: with SMTP id p67mr18573591pgp.317.1545199266042; Tue, 18 Dec 2018 22:01:06 -0800 (PST) Received: from localhost.localdomain ([2001:268:c0a2:eb51:6018:45d4:55a2:e94b]) by smtp.gmail.com with ESMTPSA id o7sm22396064pfb.34.2018.12.18.22.01.03 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Tue, 18 Dec 2018 22:01:05 -0800 (PST) From: William Breathitt Gray To: linus.walleij@linaro.org 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, William Breathitt Gray Subject: [PATCH v6 4/8] gpio: 104-idi-48: Utilize for_each_set_clump8 macro Date: Wed, 19 Dec 2018 15:01:35 +0900 Message-Id: <67e0105ad1718d3fd1cdf991d56427ac38969891.1545198260.git.vilhelm.gray@gmail.com> X-Mailer: git-send-email 2.20.1 In-Reply-To: References: MIME-Version: 1.0 Sender: linux-gpio-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-gpio@vger.kernel.org Replace verbose implementation in get_multiple/set_multiple callbacks with for_each_set_clump8 macro to simplify code and improve clarity. 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..fdf1b8b64cc4 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 int offset; + unsigned long gpio_mask; static const size_t ports[] = { 0, 1, 2, 4, 5, 6 }; - const unsigned int gpio_reg_size = 8; - unsigned int bits_offset; - size_t word_index; - unsigned int word_offset; - unsigned long word_mask; - const unsigned long port_mask = GENMASK(gpio_reg_size - 1, 0); + 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 Dec 19 06:01:50 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: William Breathitt Gray X-Patchwork-Id: 1015845 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: ozlabs.org; spf=none (mailfrom) smtp.mailfrom=vger.kernel.org (client-ip=209.132.180.67; helo=vger.kernel.org; envelope-from=linux-gpio-owner@vger.kernel.org; receiver=) Authentication-Results: ozlabs.org; dmarc=pass (p=none dis=none) header.from=gmail.com Authentication-Results: ozlabs.org; dkim=pass (2048-bit key; unprotected) header.d=gmail.com header.i=@gmail.com header.b="bs8D01ND"; dkim-atps=neutral Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by ozlabs.org (Postfix) with ESMTP id 43KPQq0lKfz9sB7 for ; Wed, 19 Dec 2018 17:01:23 +1100 (AEDT) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727052AbeLSGBW (ORCPT ); Wed, 19 Dec 2018 01:01:22 -0500 Received: from mail-pg1-f196.google.com ([209.85.215.196]:45601 "EHLO mail-pg1-f196.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1725290AbeLSGBW (ORCPT ); Wed, 19 Dec 2018 01:01:22 -0500 Received: by mail-pg1-f196.google.com with SMTP id y4so8946161pgc.12; Tue, 18 Dec 2018 22:01:21 -0800 (PST) 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=85H/4t6RkooDK10L2W5Uhts7AwM0xn2RPdanjNRGSLI=; b=bs8D01NDGRrQMYQeznQEUI87B/5jG5L0Zm2E3nB1wbgxDqkWavCfYb9XVR0iGOxhHs 6lKf3kSAcNplpUuq4YbSGpTeb9LullDC8ZJb5kkBcDbVwzcyg3lo4GcMuNyWpju+EM6c E2Yw43ILSZ7qkqXfqSYPNATYje8bKhjq1YD3vkyvcD6OvHscULQp5HemeelM5OhsDr2z 8q/nAXVYUeO4kAE5CqZdLiLpSB/en5tjMAuQMZ5itFVR1nNBYXQrixVsuMmi8owqm9ce lz7rWFrA5+43643xsL8F6IoMXBdQBmPnMTFwB03m+86jNkjL+z9z5PWBg1nN5Wm8Knga 8Stg== 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=85H/4t6RkooDK10L2W5Uhts7AwM0xn2RPdanjNRGSLI=; b=U3oFe061wrXUP9Wj+wmk5f4CS0EJNlQhB8szLLxi7O0b+zMUAEYh0P8uHmCwIz9Inp Y5Bs24bqwo+oJs/RmuhKgG/mC/2Qj4FCH7Zv7vVXJS8OFBbAN8Y0k9MRoeN8YPcRDFsY ZmgV4Gyt0Ysr02vSXB2G0/AR0+Sr9Ibm9PaKrPh0fFsu7Y7wi/T54n4SzAuT4UevLTGC SW02pmTbhfHPjMKDbQQ4uU7s5H9Kd1R1Bp3wTkrA8ZbrCtq9YhcsuLAjhGq87VdyE3RH GVLP+yYG8Ti8Y+Xgz2ovk1iZPyQLTq9ntWdwSIZAPYs/y0gkB7BgIGpxUnknSTbAr2EH y6EQ== X-Gm-Message-State: AA+aEWahKckk7CjvyRc808qxm97IMytT/RchBHErcwpp7lSJmKcxbE26 OqZvomuvSr4NKvE9zTgRel8zffi8 X-Google-Smtp-Source: AFSGD/UcrILknSxpVDLDAcvOQm+uq/TzPuniH98X6Cc9U0UDisgtiBR1YtRZmcMzC6rgQpWATQ7Hww== X-Received: by 2002:a62:509b:: with SMTP id g27mr19577844pfj.48.1545199280959; Tue, 18 Dec 2018 22:01:20 -0800 (PST) Received: from localhost.localdomain ([2001:268:c0a2:eb51:6018:45d4:55a2:e94b]) by smtp.gmail.com with ESMTPSA id v89sm25093381pfk.12.2018.12.18.22.01.17 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Tue, 18 Dec 2018 22:01:20 -0800 (PST) From: William Breathitt Gray To: linus.walleij@linaro.org 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, William Breathitt Gray Subject: [PATCH v6 5/8] gpio: gpio-mm: Utilize for_each_set_clump8 macro Date: Wed, 19 Dec 2018 15:01:50 +0900 Message-Id: <1a54a935c918d2b9c2dcd268e1ccc34ba3c00142.1545198260.git.vilhelm.gray@gmail.com> X-Mailer: git-send-email 2.20.1 In-Reply-To: References: MIME-Version: 1.0 Sender: linux-gpio-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-gpio@vger.kernel.org Replace verbose implementation in get_multiple/set_multiple callbacks with for_each_set_clump8 macro to simplify code and improve clarity. Signed-off-by: William Breathitt Gray --- drivers/gpio/gpio-gpio-mm.c | 71 +++++++++++-------------------------- 1 file changed, 20 insertions(+), 51 deletions(-) diff --git a/drivers/gpio/gpio-gpio-mm.c b/drivers/gpio/gpio-gpio-mm.c index 8c150fd68d9d..5647abe72376 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 int offset; + unsigned long gpio_mask; + unsigned int port_addr; unsigned long port_state; /* clear bits array to a clean slate */ bitmap_zero(bits, chip->ngpio); - /* get bits are evaluated a gpio port register at a time */ - for (i = 0; i < 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 offset; + unsigned long gpio_mask; + size_t index; + unsigned int port_addr; unsigned int bitmask; unsigned long flags; - /* set bits are evaluated a gpio register size at a time */ - for (i = 0; i < chip->ngpio; i += gpio_reg_size) { - /* no more set bits in this mask word; skip to the next word */ - if (!mask[BIT_WORD(i)]) { - i = (BIT_WORD(i) + 1) * BITS_PER_LONG - gpio_reg_size; - continue; - } + 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 Dec 19 06:02:05 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: William Breathitt Gray X-Patchwork-Id: 1015846 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: ozlabs.org; spf=none (mailfrom) smtp.mailfrom=vger.kernel.org (client-ip=209.132.180.67; helo=vger.kernel.org; envelope-from=linux-gpio-owner@vger.kernel.org; receiver=) Authentication-Results: ozlabs.org; dmarc=pass (p=none dis=none) header.from=gmail.com Authentication-Results: ozlabs.org; dkim=pass (2048-bit key; unprotected) header.d=gmail.com header.i=@gmail.com header.b="UazKgOdz"; dkim-atps=neutral Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by ozlabs.org (Postfix) with ESMTP id 43KPR64H5fz9s3Z for ; Wed, 19 Dec 2018 17:01:38 +1100 (AEDT) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726917AbeLSGBi (ORCPT ); Wed, 19 Dec 2018 01:01:38 -0500 Received: from mail-pg1-f196.google.com ([209.85.215.196]:46088 "EHLO mail-pg1-f196.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1725290AbeLSGBi (ORCPT ); Wed, 19 Dec 2018 01:01:38 -0500 Received: by mail-pg1-f196.google.com with SMTP id w7so8947608pgp.13; Tue, 18 Dec 2018 22:01:37 -0800 (PST) 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=DkIxDSyjoROWp7biDXggOXD5cmZ4EeyYKd2Z/CBdLgA=; b=UazKgOdz/nQ9DTP7n9U8w8oofqO1GweSN2TMmj/w4CeeHw9P9N5fBczVSHIoAjceND 2wF9eFvXQPI452xyknTONJnE1TAjygdASnhqxat7aYfFbH7vzuyCyrAFp/PLwX0+/1V7 1yvrLs5NM5Ije7zNAAdQ6LUqNj2KbdBhO/QoW2pHo37yq640R1OOq0m2DhTORpXuL3S5 4JGcjuqld+AbMKRyiKjMg0KOKPiMpEHspoprMsUe56LyIOycmUISoL+nufOaY5bBcZjT Nvm9XX1hc2sO/VrtCbvbhCgbEIXJQm8FkFbeEhVFfK6CzK2GMoKoOLkp4hiGmSIKDa6h tD4g== 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=DkIxDSyjoROWp7biDXggOXD5cmZ4EeyYKd2Z/CBdLgA=; b=emMOJ/iXJbFFaHlzz9QKEB9FsjrIAsxxTcSpji/qzJtcLqfAlQNS98fjO9YWoKB9S0 wN4TW+ZwrpM9UZPL4gGSMtMjUIB0/7mbAoSLBN73JNIoDsJXdAWjjnYUe1PiIiAE5L/n xVQ4E21xTIUCXgwMcB/XKZmw5SE3shwLtwiOV29zV8bQvWapOXsngxZaIpfzQhfxJjJ5 3NoAh4RyStpiMe2NkiOJ7RNa9quuZdoMBfyyEmD7ytttm8FrRyYkhHnrZXD5KNgXhp7J nsRNZThhD9wB4ex48nHGiIlmFs0McZf5sy8YgKiAKVYyOexyI21HXQIjQZo80P5F3tvw bukA== X-Gm-Message-State: AA+aEWaIS+aKAXsF83CcRxNKma0rYOZyJH28zxA9HDFH+65zMWiwcupi ZhGI8haUzMdvNhAyZ6nwp08= X-Google-Smtp-Source: AFSGD/VTk5vPZO2j5/ZtyS6wHGwXa99sLcuZwZOSQKPn/Y77/ipt7oy1dB6MZxKBmeV+lpKN5wK+3w== X-Received: by 2002:a63:de04:: with SMTP id f4mr1820251pgg.292.1545199296958; Tue, 18 Dec 2018 22:01:36 -0800 (PST) Received: from localhost.localdomain ([2001:268:c0a2:eb51:6018:45d4:55a2:e94b]) by smtp.gmail.com with ESMTPSA id f13sm23123740pfa.132.2018.12.18.22.01.33 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Tue, 18 Dec 2018 22:01:36 -0800 (PST) From: William Breathitt Gray To: linus.walleij@linaro.org 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, William Breathitt Gray Subject: [PATCH v6 6/8] gpio: ws16c48: Utilize for_each_set_clump8 macro Date: Wed, 19 Dec 2018 15:02:05 +0900 Message-Id: X-Mailer: git-send-email 2.20.1 In-Reply-To: References: MIME-Version: 1.0 Sender: linux-gpio-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-gpio@vger.kernel.org Replace verbose implementation in get_multiple/set_multiple callbacks with for_each_set_clump8 macro to simplify code and improve clarity. Signed-off-by: William Breathitt Gray --- drivers/gpio/gpio-ws16c48.c | 71 ++++++++++--------------------------- 1 file changed, 19 insertions(+), 52 deletions(-) diff --git a/drivers/gpio/gpio-ws16c48.c b/drivers/gpio/gpio-ws16c48.c index 5cf3697bfb15..b4c544d5da18 100644 --- a/drivers/gpio/gpio-ws16c48.c +++ b/drivers/gpio/gpio-ws16c48.c @@ -134,42 +134,19 @@ static int ws16c48_gpio_get_multiple(struct gpio_chip *chip, unsigned long *mask, unsigned long *bits) { struct ws16c48_gpio *const ws16c48gpio = gpiochip_get_data(chip); - const unsigned int gpio_reg_size = 8; - size_t i; - const size_t num_ports = chip->ngpio / gpio_reg_size; - unsigned int bits_offset; - size_t word_index; - unsigned int word_offset; - unsigned long word_mask; - const unsigned long port_mask = GENMASK(gpio_reg_size - 1, 0); + unsigned int offset; + unsigned long gpio_mask; + unsigned int port_addr; unsigned long port_state; /* clear bits array to a clean slate */ bitmap_zero(bits, chip->ngpio); - /* get bits are evaluated a gpio port register at a time */ - for (i = 0; i < num_ports; i++) { - /* gpio offset in bits array */ - bits_offset = i * gpio_reg_size; + for_each_set_clump8(offset, gpio_mask, mask, chip->ngpio) { + port_addr = ws16c48gpio->base + offset / 8; + port_state = inb(port_addr) & gpio_mask; - /* word index for bits array */ - word_index = BIT_WORD(bits_offset); - - /* gpio offset within current word of bits array */ - word_offset = bits_offset % BITS_PER_LONG; - - /* mask of get bits for current gpio within current word */ - word_mask = mask[word_index] & (port_mask << word_offset); - if (!word_mask) { - /* no get bits in this port so skip to next one */ - continue; - } - - /* read bits from current gpio port */ - port_state = inb(ws16c48gpio->base + i); - - /* store acquired bits at respective bits array offset */ - bits[word_index] |= (port_state << word_offset) & word_mask; + bitmap_set_value8(bits, &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 offset; + unsigned long gpio_mask; + size_t index; + unsigned int port_addr; unsigned int bitmask; unsigned long flags; - /* set bits are evaluated a gpio register size at a time */ - for (i = 0; i < chip->ngpio; i += gpio_reg_size) { - /* no more set bits in this mask word; skip to the next word */ - if (!mask[BIT_WORD(i)]) { - i = (BIT_WORD(i) + 1) * BITS_PER_LONG - gpio_reg_size; - continue; - } - - port = i / gpio_reg_size; + for_each_set_clump8(offset, gpio_mask, mask, chip->ngpio) { + index = offset / 8; + port_addr = ws16c48gpio->base + index; /* mask out GPIO configured for input */ - iomask = mask[BIT_WORD(i)] & ~ws16c48gpio->io_state[port]; - bitmask = iomask & bits[BIT_WORD(i)]; + gpio_mask &= ~ws16c48gpio->io_state[index]; + bitmask = bitmap_get_value8(bits, 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 Dec 19 06:02:21 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: William Breathitt Gray X-Patchwork-Id: 1015847 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: ozlabs.org; spf=none (mailfrom) smtp.mailfrom=vger.kernel.org (client-ip=209.132.180.67; helo=vger.kernel.org; envelope-from=linux-gpio-owner@vger.kernel.org; receiver=) Authentication-Results: ozlabs.org; dmarc=pass (p=none dis=none) header.from=gmail.com Authentication-Results: ozlabs.org; dkim=pass (2048-bit key; unprotected) header.d=gmail.com header.i=@gmail.com header.b="Mq/SKHN1"; dkim-atps=neutral Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by ozlabs.org (Postfix) with ESMTP id 43KPRW4z6Nz9s8r for ; Wed, 19 Dec 2018 17:01:59 +1100 (AEDT) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726993AbeLSGB6 (ORCPT ); Wed, 19 Dec 2018 01:01:58 -0500 Received: from mail-pl1-f195.google.com ([209.85.214.195]:41276 "EHLO mail-pl1-f195.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1725290AbeLSGB6 (ORCPT ); Wed, 19 Dec 2018 01:01:58 -0500 Received: by mail-pl1-f195.google.com with SMTP id u6so8969721plm.8; Tue, 18 Dec 2018 22:01:57 -0800 (PST) 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=wIUcUn9NZpZ4AkNdcsel1CBOeLuu/XGaElsnv6eh2k0=; b=Mq/SKHN1Pa1jJV/gK8xYyQVVXSeSxSKLvUSNyDtEOSaTc51svpF4JLwagxE6Bwk5lo VsaZ9UNZuPx8c3y00lXdiYWuuaUKe3QhReyuFBv8y0vlFtx6SIa2RyGnzeWRgEStNuoN CpAwEq+uNe5HD6WE5dVlGMqsM2exDcEgsrHF6mxFusok3NFt+emtb/z6RsAqffk+PF4l moehez3veCXjdUVyzd1LAjwRXWF1BwHYJ4/6gO0Ck5chBb1ey4Zl8z661XPSZna9bjsu 3GXC/9gYm7hKq2V2jAObn98i9AFSvWv4QWUJDsRLj4Gk0qzP5hLroKo+pV3OQ+iyAFDm gesQ== 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=wIUcUn9NZpZ4AkNdcsel1CBOeLuu/XGaElsnv6eh2k0=; b=ex80MNp8ErLIj26a5k1nPQM8+KYqFTLisum8O7CHjMYfrw4eg1G1tLfSPaQSd5hN/8 0u5tmg8lYISIlFxsQ5D2fAv+GMjLk524DCPIW3PChJgmj8rb0RX8JXVlnOkA6PiKsHl+ WVltgt8ruaH9mTJvkWUcHNkYubWpFgMFKpe+C6QX9qZ0o1J3nZ0NWPXQc8PUt8fApsV3 wUy1lSTCsffoSOZaBxIVgyqkQ/CmhmNILkaJOFzz4vp7f4aYRXY4zcY/HkYzGzPcp0jk 2CnPv8aEZ3uNRIUlwB6joSeF6j3OHTxBLt/1VAF8+I78LZ/Wk6cYKKrurOWMxmY4oYJf X/Fw== X-Gm-Message-State: AA+aEWblyTIOeWhDHLSjITwpp2mXxD/rb9U5PGXOGCwKVJaIz6zGEFSu pxdAMOBRN4tFeTLyvCrV2Xo= X-Google-Smtp-Source: AFSGD/Wkeu9DAc0W3L/E3CARwVCVrK8ODHNnlVX8e1Ps9CNkuZU2PX/dvrjuAsObgNHhPV0fkGKLxA== X-Received: by 2002:a17:902:7614:: with SMTP id k20mr19383438pll.285.1545199317307; Tue, 18 Dec 2018 22:01:57 -0800 (PST) Received: from localhost.localdomain ([2001:268:c0a2:eb51:6018:45d4:55a2:e94b]) by smtp.gmail.com with ESMTPSA id r12sm19801353pgv.83.2018.12.18.22.01.54 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Tue, 18 Dec 2018 22:01:56 -0800 (PST) From: William Breathitt Gray To: linus.walleij@linaro.org 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, William Breathitt Gray Subject: [PATCH v6 7/8] gpio: pci-idio-16: Utilize for_each_set_clump8 macro Date: Wed, 19 Dec 2018 15:02:21 +0900 Message-Id: <20f43bb1c4b9d7b5f0a0cd044258f2eec8c68a2a.1545198260.git.vilhelm.gray@gmail.com> X-Mailer: git-send-email 2.20.1 In-Reply-To: References: MIME-Version: 1.0 Sender: linux-gpio-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-gpio@vger.kernel.org Replace verbose implementation in get_multiple/set_multiple callbacks with for_each_set_clump8 macro to simplify code and improve clarity. Signed-off-by: William Breathitt Gray --- drivers/gpio/gpio-pci-idio-16.c | 73 ++++++++++++--------------------- 1 file changed, 26 insertions(+), 47 deletions(-) diff --git a/drivers/gpio/gpio-pci-idio-16.c b/drivers/gpio/gpio-pci-idio-16.c index 6b7349783223..4eb89f8b5f9b 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 int offset; + unsigned long gpio_mask; void __iomem *ports[] = { &idio16gpio->reg->out0_7, &idio16gpio->reg->out8_15, &idio16gpio->reg->in0_7, &idio16gpio->reg->in8_15, }; + void __iomem *port_addr; + unsigned long port_state; /* clear bits array to a clean slate */ bitmap_zero(bits, chip->ngpio); - /* get bits are evaluated a gpio port register at a time */ - for (i = 0; i < ARRAY_SIZE(ports); i++) { - /* gpio offset in bits array */ - bits_offset = i * gpio_reg_size; - - /* word index for bits array */ - word_index = BIT_WORD(bits_offset); - - /* gpio offset within current word of bits array */ - word_offset = bits_offset % BITS_PER_LONG; + for_each_set_clump8(offset, gpio_mask, mask, ARRAY_SIZE(ports) * 8) { + port_addr = ports[offset / 8]; + port_state = ioread8(port_addr) & gpio_mask; - /* mask of get bits for current gpio within current word */ - word_mask = mask[word_index] & (port_mask << word_offset); - if (!word_mask) { - /* no get bits in this port so skip to next one */ - continue; - } - - /* read bits from current gpio port */ - port_state = ioread8(ports[i]); - - /* store acquired bits at respective bits array offset */ - bits[word_index] |= (port_state << word_offset) & word_mask; + bitmap_set_value8(bits, &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 int offset; + unsigned long gpio_mask; + void __iomem *ports[] = { + &idio16gpio->reg->out0_7, &idio16gpio->reg->out8_15, + }; + size_t index; + void __iomem *port_addr; + unsigned int bitmask; unsigned long flags; unsigned int out_state; - raw_spin_lock_irqsave(&idio16gpio->lock, flags); + for_each_set_clump8(offset, gpio_mask, mask, 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 Dec 19 06:02:41 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: William Breathitt Gray X-Patchwork-Id: 1015848 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: ozlabs.org; spf=none (mailfrom) smtp.mailfrom=vger.kernel.org (client-ip=209.132.180.67; helo=vger.kernel.org; envelope-from=linux-gpio-owner@vger.kernel.org; receiver=) Authentication-Results: ozlabs.org; dmarc=pass (p=none dis=none) header.from=gmail.com Authentication-Results: ozlabs.org; dkim=pass (2048-bit key; unprotected) header.d=gmail.com header.i=@gmail.com header.b="FVDwNNN4"; dkim-atps=neutral Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by ozlabs.org (Postfix) with ESMTP id 43KPRp0vjxz9s8r for ; Wed, 19 Dec 2018 17:02:14 +1100 (AEDT) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726959AbeLSGCN (ORCPT ); Wed, 19 Dec 2018 01:02:13 -0500 Received: from mail-pl1-f196.google.com ([209.85.214.196]:40112 "EHLO mail-pl1-f196.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1725290AbeLSGCM (ORCPT ); Wed, 19 Dec 2018 01:02:12 -0500 Received: by mail-pl1-f196.google.com with SMTP id u18so8974148plq.7; Tue, 18 Dec 2018 22:02:12 -0800 (PST) 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=jsdsM+RlRyjEYiOfR3l9qfrS9JfRbsBc4uOym3o91cU=; b=FVDwNNN4/QEW0JxopFOPAytCm7K0c+FbApWoylTZAy6V/YU+SwJ7LYw3AkdXHZ8Itp zEpdHAjegbfja/7hHlB4W7q+Lf2w6QArmUp1gEU09dMnI/8NbDNq8gUtSlQmerFU9uWm lNJjFXudlbdzpFjlcWYhE/pL+O/wbm4JWyai+pSguneOq4iV5ZNZIdPwrY+74cGpuLmY +n5m4d+BnHMzEefGgJhcmjmbqwPvdy1AC4GL9bJIn2nrc3D9P6xiUdIRKYLCIfNK8AQc FovsZjaAxZ6Y59MOfYPm6ALbNJ6RPov6fvqY8r+LDEST1Xg+ac2Ki7/AuJTlGeLpRWCF +2fw== 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=jsdsM+RlRyjEYiOfR3l9qfrS9JfRbsBc4uOym3o91cU=; b=qpUoHvYTTcKCcCdXSDf2xcoGKIS1k90UW9Wle+EgHuw5e4nkU66fJNsFg6kBw7XRat y0l0szot1xInr5IaBtVLJQBxTUDYJpy5C0m/PFM0gOoYUKM/HD570I/ATAyYMcichy0d jSDyw8OZHz/2lnXy4hu0EzudiMiX/EJrpoOnywG8ySMRaaK75qWmku02+rFcGXW62tCR YOjogMSMTatHzRr+/ZyqOHE4b6eYI2XMMLm3v8UVOyhZZUYKsHcFccupVI93H/Of9EhF t6PSDeeeKGtY6N++MCfjtdur0izxhX9mFjUKu201bWrtuRFms5doLBjhmEGtVGFFKyXM wJ3A== X-Gm-Message-State: AA+aEWZpprNzjsRSyzcJtWF0yM4088rsBC6MAty5lBVJv4aeDt8Zwaaa c6JDfVFuApdHQFwWBwUDodI= X-Google-Smtp-Source: AFSGD/VVrN2SKlSw43k8ZzTjfFOFnm011I9x2XD7QFckTwebxE7SOjDaP/lPJtiUnAxZ5tUTVaxP4A== X-Received: by 2002:a17:902:e20b:: with SMTP id ce11mr18410953plb.251.1545199331909; Tue, 18 Dec 2018 22:02:11 -0800 (PST) Received: from localhost.localdomain ([2001:268:c0a2:eb51:6018:45d4:55a2:e94b]) by smtp.gmail.com with ESMTPSA id y71sm35607348pfi.123.2018.12.18.22.02.08 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Tue, 18 Dec 2018 22:02:11 -0800 (PST) From: William Breathitt Gray To: linus.walleij@linaro.org 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, William Breathitt Gray Subject: [PATCH v6 8/8] gpio: pcie-idio-24: Utilize for_each_set_clump8 macro Date: Wed, 19 Dec 2018 15:02:41 +0900 Message-Id: X-Mailer: git-send-email 2.20.1 In-Reply-To: References: MIME-Version: 1.0 Sender: linux-gpio-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-gpio@vger.kernel.org Replace verbose implementation in get_multiple/set_multiple callbacks with for_each_set_clump8 macro to simplify code and improve clarity. 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..b1686b052633 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 int offset; + unsigned long gpio_mask; void __iomem *ports[] = { &idio24gpio->reg->out0_7, &idio24gpio->reg->out8_15, &idio24gpio->reg->out16_23, &idio24gpio->reg->in0_7, &idio24gpio->reg->in8_15, &idio24gpio->reg->in16_23, }; + 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 int offset; unsigned long gpio_mask; - const unsigned int gpio_reg_size = 8; - const unsigned long port_mask = GENMASK(gpio_reg_size, 0); - unsigned long flags; - unsigned int out_state; void __iomem *ports[] = { &idio24gpio->reg->out0_7, &idio24gpio->reg->out8_15, &idio24gpio->reg->out16_23 }; + size_t index; + unsigned int bitmask; + unsigned long flags; + unsigned int out_state; const unsigned long out_mode_mask = BIT(1); - const unsigned int ttl_offset = 48; - const size_t ttl_i = BIT_WORD(ttl_offset); - const unsigned int word_offset = ttl_offset % BITS_PER_LONG; - const unsigned long ttl_mask = (mask[ttl_i] >> word_offset) & port_mask; - const unsigned long ttl_bits = (bits[ttl_i] >> word_offset) & ttl_mask; - - /* set bits are processed a gpio port register at a time */ - for (i = 0; i < ARRAY_SIZE(ports); i++) { - /* gpio offset in bits array */ - bits_offset = i * gpio_reg_size; - - /* check if any set bits for current port */ - gpio_mask = (*mask >> bits_offset) & port_mask; - if (!gpio_mask) { - /* no set bits for this port so move on to next port */ - continue; - } - raw_spin_lock_irqsave(&idio24gpio->lock, flags); + for_each_set_clump8(offset, gpio_mask, mask, 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)