From patchwork Sat Jan 12 01:48:04 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: 1023833 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="ZmveBxgE"; dkim-atps=neutral Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by ozlabs.org (Postfix) with ESMTP id 43c2fz03Xmz9sDX for ; Sat, 12 Jan 2019 12:47:39 +1100 (AEDT) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726227AbfALBrc (ORCPT ); Fri, 11 Jan 2019 20:47:32 -0500 Received: from mail-pl1-f193.google.com ([209.85.214.193]:34825 "EHLO mail-pl1-f193.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726491AbfALBrb (ORCPT ); Fri, 11 Jan 2019 20:47:31 -0500 Received: by mail-pl1-f193.google.com with SMTP id p8so7543045plo.2; Fri, 11 Jan 2019 17:47:31 -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=illMOt5TaobGwcDI7Guq/1X4h0CJv2ntS15Gr9KbqVs=; b=ZmveBxgE1z/B5oYqjdB2x4uZybFrWzQx04VDoQhQm4vPdU9tfNMrJuE2mOhKVNJtQy aJ2hmaJsAqiF4XtxW5OXmllaQU3BtzUL1bfGOvEQFM98RcIh1OjHAbSM9TMn057b9PIu X7qyAv4GiOjLC2hA76r9NyzuZXZYNmWJeTU4aZUC+cbfnsfP+tYARAkec7kdgqxwg8La BNLVkbAVhPXbDb8VV7o5hmLibhjF1i/kQDxzHRlB5E0n4Uzt5hDoM8YlzuGUJg1VdKzd GRTLHUP3I4IVAd2nh/Qtj1+L0Ri50VgextjcMHj36lUObgtlAmJn3SRw424FA0RJJavG M0vQ== 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=illMOt5TaobGwcDI7Guq/1X4h0CJv2ntS15Gr9KbqVs=; b=o4lUSAIhtoB+NdJ4/pLueG9kpDWoa4rDKG4tN1yX32WXxPOfntSG2YNVccsja4qYxX mTBLpbwZmfon8Hsgeuv7jH3OqAHncP2WTnf2Xyr8IcT1u3SPQV86kGktX01X9ZpVEHLR EFloNAjCKZN3061HuZ1uQxyQzoLQB+ok8n2CgkvIkA0HShXk0wZRYi/Ona7CwZCjBHij KwrX0JPDHB/wN9cStYPvxWJCL+Wd/IPKudSM0yq/7ezCPuOd9hL5TNj4iyiq1+GBxT1X ALFwlWP+dWXeNLI1tr5Xop86XLBarloluoXQIu/meFGwKWLNUp0AUkZK4c/cZiri9Wo5 A7SA== X-Gm-Message-State: AJcUuke9siDIM93KDQZ1qjSr2pDSMR6pzCQ86WRLkqjHaPcAz2N9RekY 4H5IN+/bnqwdk5YyznbgNpcheWX0 X-Google-Smtp-Source: ALg8bN5uq+eJVGOV4ZinkDWFmXW1PB+ryQAxeieq4m4cPotiC8i7gin6VG7AY2orsUTRxZhRc6oWkA== X-Received: by 2002:a17:902:5ac7:: with SMTP id g7mr17110945plm.212.1547257650635; Fri, 11 Jan 2019 17:47:30 -0800 (PST) Received: from localhost.localdomain ([2001:268:c0a3:ffc5:36e2:bccb:ba63:9e84]) by smtp.gmail.com with ESMTPSA id 128sm120175296pfu.129.2019.01.11.17.47.25 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Fri, 11 Jan 2019 17:47:30 -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 v7 1/8] bitops: Introduce the for_each_set_clump8 macro Date: Sat, 12 Jan 2019 10:48:04 +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 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..61c496ae94cf 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 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..97d96e65a3d9 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 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; +} +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 Sat Jan 12 01:48:22 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: William Breathitt Gray X-Patchwork-Id: 1023834 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="o3K+Q70d"; dkim-atps=neutral Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by ozlabs.org (Postfix) with ESMTP id 43c2g96MRHz9sDn for ; Sat, 12 Jan 2019 12:47:49 +1100 (AEDT) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726528AbfALBrt (ORCPT ); Fri, 11 Jan 2019 20:47:49 -0500 Received: from mail-pf1-f195.google.com ([209.85.210.195]:34516 "EHLO mail-pf1-f195.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726433AbfALBrt (ORCPT ); Fri, 11 Jan 2019 20:47:49 -0500 Received: by mail-pf1-f195.google.com with SMTP id h3so7770114pfg.1; Fri, 11 Jan 2019 17:47:48 -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=o3K+Q70dRYXJYzCFwWch5KEqXsgFigIsL/80tqUUNOhIJIXdqALdqbal6IffdnMY5v ufqbh2VCxOLKNDRlhMSOuTJJhXx357jjGaVZFDAhiO4/rtADmrL2ZYEiwa/62/YCULTl xT3fZTKjFsMyk6CmtUPVW+61CM70Tm/H5/5pmIMrMLib1NO/UlmlItycUgk6rNSocgf5 mbDhcQZKBCylkX3NH0pCA909rLP9qt7sqIOWpzT8wFoaYdY0IdK13uj3ohcDUjibfa8o hW5ki+sx2XSOijXUBNi6SMkGI3V/7kZEHxI6Kh+Rlx1pgghL444plYya/WzvYIBfb9jo YmGg== 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=S/t8GhtfmIvqdNCx/qDi9fCYP2CK7n3MTjD1h7LYLVE7YtaObhNd5pbFjIg8YPAr7H B1wA05Vj2p8ywcSpSu3epjNhVPwk9ZW6Bi/HEdq3yWhjeddKl2cR43bzbm+5Va1f7VI5 jJhbownhRgnRPG4/fJjY+zm5hpgG1rT6GO8FJRaBfxVXc7Cm77gaMeJrogFtVWgfvPwK Flrexwnx5+y4el5NrPLTTt7zn3X3ePx2EcCow7blI7P3BPhQgTehv+mdKkWA8zVQAwny x6SvR6jtXem0vdFuYOa8S0Teu5nbApex2Voa7HudUpI9yCr8U2CO24uZWHRQxgcYiruY Bg9Q== X-Gm-Message-State: AJcUukcjroPjHdeKNM9rui9KTt12nvNx2KGO5YWej9L9TN0rFZLLxww8 3Y8H6c7kHpxNiQ4oAZL4rhw= X-Google-Smtp-Source: ALg8bN477mHDKeHca4Y2XClQhmJDdTvgWEC0kBn00N0zzPAR0hcctFDDIeQKv68KgCJWKyhTUE/Qmg== X-Received: by 2002:a63:2b01:: with SMTP id r1mr15297416pgr.432.1547257668154; Fri, 11 Jan 2019 17:47:48 -0800 (PST) Received: from localhost.localdomain ([2001:268:c0a3:ffc5:36e2:bccb:ba63:9e84]) by smtp.gmail.com with ESMTPSA id 4sm130950762pfq.10.2019.01.11.17.47.43 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Fri, 11 Jan 2019 17:47: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 , Andy Shevchenko Subject: [PATCH v7 2/8] lib/test_bitmap.c: Add for_each_set_clump8 test cases Date: Sat, 12 Jan 2019 10:48:22 +0900 Message-Id: <7672ec8b5801519cf4b459926b13bd37370bc581.1547257386.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 Sat Jan 12 01:48:41 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: William Breathitt Gray X-Patchwork-Id: 1023835 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="R15Vlkdu"; dkim-atps=neutral Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by ozlabs.org (Postfix) with ESMTP id 43c2gV6xRTz9s9h for ; Sat, 12 Jan 2019 12:48:06 +1100 (AEDT) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726433AbfALBsG (ORCPT ); Fri, 11 Jan 2019 20:48:06 -0500 Received: from mail-pl1-f196.google.com ([209.85.214.196]:33375 "EHLO mail-pl1-f196.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726270AbfALBsF (ORCPT ); Fri, 11 Jan 2019 20:48:05 -0500 Received: by mail-pl1-f196.google.com with SMTP id z23so7560546plo.0; Fri, 11 Jan 2019 17:48:05 -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=QRpQERtbKh/21jrrs3pu0HDTwJ5Ec3WzG9pqSzCr2+g=; b=R15VlkduRMAQy3j1tg+tp/SRVMObJbWXfb6snpuzaM2ozfURF5iLGORBdM2ez3kq16 q+vyWVownlBg/18AwUe7TYhUllIda5UhaqPEehy6vAZEbnMgGDt4NTkVYDZx18qaaCwx mWGS+3Ca1YiZoWxsKr6LAWjFizBOM0WSVahjlhw3CyWAE04Tz19Edur8m8WtNrF6w1e6 yuCeN3b06naTC7dW6iXXlKJBdG+69npNaKnP5ehPEy/QAHLn6RYpt4BXIIbgSDL8ZVXt zSOOUlL9OVXpVw6c+jNMNyLC5p8mz9L4wJfBLlys4oqoaqUhWsRVhMCGkAihH40Mc5a+ BMuw== 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=QRpQERtbKh/21jrrs3pu0HDTwJ5Ec3WzG9pqSzCr2+g=; b=JJRDp+qvPWXj5Sl50aCzgG/AGLRNziJ12hOpGabR1RI9/8/TJ6IB8B4hgb7D8lgFUj TWaW3NAikFSQPgw9+2RJS+xgAq/2yLnE1t6KXesQd46bcGEA8NzMgcyEpCAyqPQ155Gr 3qs46t/WmgEGojMC+O9ciw67u+C2pYhi6VmwoFhV2hOilMLGjHv51tvioVTIimiugXGZ buRGRp/QvhohE1hz0OWDJA06Ui69GZf/KDC8iL7XxiI8+v1vyXbGDT2Od1Aw0UnCNgUi GWa1WU57U3FcKTyzb9PHPLwJ3KKQSySbNJQGCXxc7BRMGqrtad/lR3HItOfn/CJkOPPt SmMw== X-Gm-Message-State: AJcUukcc42+d5+E+LLl0GqXtvVqejBd1dDNdG/v8FIP1iZrpa7UIHCDt 69akCo0F+t8jHXSz9IL5NA4= X-Google-Smtp-Source: ALg8bN6S2XwQ/uQx7rxzVVAkXQHcg+VdM8UhTG9tH+X2+nlsrHZtGRLtRwz+2mqOIHn8+tqUwmdyfw== X-Received: by 2002:a17:902:2ec1:: with SMTP id r59mr17098176plb.254.1547257684728; Fri, 11 Jan 2019 17:48:04 -0800 (PST) Received: from localhost.localdomain ([2001:268:c0a3:ffc5:36e2:bccb:ba63:9e84]) by smtp.gmail.com with ESMTPSA id c13sm117586446pfo.121.2019.01.11.17.48.01 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Fri, 11 Jan 2019 17:48:04 -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 v7 3/8] gpio: 104-dio-48e: Utilize for_each_set_clump8 macro Date: Sat, 12 Jan 2019 10:48:41 +0900 Message-Id: <5a82cc7b828945a27d97b21f13410eb1404e5180.1547257386.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..1093a1403d77 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 Sat Jan 12 01:49:00 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: William Breathitt Gray X-Patchwork-Id: 1023836 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="sRnxm6Xl"; dkim-atps=neutral Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by ozlabs.org (Postfix) with ESMTP id 43c2gv3qWwz9s55 for ; Sat, 12 Jan 2019 12:48:27 +1100 (AEDT) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726270AbfALBs1 (ORCPT ); Fri, 11 Jan 2019 20:48:27 -0500 Received: from mail-pf1-f196.google.com ([209.85.210.196]:41295 "EHLO mail-pf1-f196.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726227AbfALBs0 (ORCPT ); Fri, 11 Jan 2019 20:48:26 -0500 Received: by mail-pf1-f196.google.com with SMTP id b7so7755488pfi.8; Fri, 11 Jan 2019 17:48:26 -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=ee1QyAa1N2Ih1UTUQsFUgosd6lppQCkmPJ1LX1IRxh8=; b=sRnxm6XlguEcP7Y7xA94mg9LjdTv3VwEzOJWSan8l6mm37M8hHn9kH6fStS7SwHPq+ U+Rn/j0XRInBIGwBGP8SIBkyurk3yzzexWIJWq8I5+MXjY2yD9eo2PU0FuSAkIVVCV0E tx7Scyc7nUTsRoqlPjh/XzAF4My9omT5Qt47l4MGVPNWtvlkCB/JXEsGg3BlCOJB1uSN Tt0nZLZnju/m3nBzWA8rwhmUlsu9mdYqh8s0F6u5KDwvvfYLBcUa5FlAW0Ja2L1zEZSA K1FNJSJYzarya6Sde2i1H8ZmqiS1CXy+ULm60vqv53Hzx4fNc33NdVBpNmJpszSQkMCD J5iA== 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=ee1QyAa1N2Ih1UTUQsFUgosd6lppQCkmPJ1LX1IRxh8=; b=ljJDGB7MfIbDjhhMefmsXRc2mJtTJU+zO0ZNELfXAZeWD9a7qdpn9ARyv5hO+4hrtK oL7TfU9RmS/234ZJRyhmbLauvFxJLwNMSZwBf+Lcj4Pw9UZalx8JoNyhy3ZJdSwKaSdc xFXinvOw+zkGVQGj5HqeMEIRR6ZfSC4jec3k81AF7uzVxBjSNUcqsLQFqZwapr9kJiWa 98LAEAKDfz7cCJ7uI0Ck5nx4DzpmRld9jvO0tQvMCyFASlnQiKmZ0Qpxfhm1x+0eht1D ONKnH8hRj0CdH4TI7v75axvqUpmLqQwWD3fesgZzDh+p8CtTF8vzeXJOe+8y/fGPjFje klMQ== X-Gm-Message-State: AJcUukeP4EpAWkkYuHij/sqFKSqdS7cmp+tKDdmeg5gxkWitHRlfV80J 9yoiiyILADw7pfZYebPOfcI= X-Google-Smtp-Source: ALg8bN5z0ml+/Qns/rYRpD4KNOMjYe+qqyIeCzAYOc79+rve4wjhs1p2W21VtC8wU0JnQt5mASMwbw== X-Received: by 2002:a63:6984:: with SMTP id e126mr15624649pgc.143.1547257705852; Fri, 11 Jan 2019 17:48:25 -0800 (PST) Received: from localhost.localdomain ([2001:268:c0a3:ffc5:36e2:bccb:ba63:9e84]) by smtp.gmail.com with ESMTPSA id j9sm102086832pfi.86.2019.01.11.17.48.22 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Fri, 11 Jan 2019 17:48:25 -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 v7 4/8] gpio: 104-idi-48: Utilize for_each_set_clump8 macro Date: Sat, 12 Jan 2019 10:49:00 +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-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..d58382958bd5 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 Sat Jan 12 01:49:22 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: William Breathitt Gray X-Patchwork-Id: 1023837 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="VH2sbDqE"; dkim-atps=neutral Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by ozlabs.org (Postfix) with ESMTP id 43c2hN2N1Rz9s55 for ; Sat, 12 Jan 2019 12:48:52 +1100 (AEDT) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726383AbfALBsv (ORCPT ); Fri, 11 Jan 2019 20:48:51 -0500 Received: from mail-pl1-f196.google.com ([209.85.214.196]:45039 "EHLO mail-pl1-f196.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726227AbfALBsu (ORCPT ); Fri, 11 Jan 2019 20:48:50 -0500 Received: by mail-pl1-f196.google.com with SMTP id e11so7533065plt.11; Fri, 11 Jan 2019 17:48:50 -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=nHEyzaj0Xe6lvGvK4uNO3cxht7LVWKgKLecVOkA5AJQ=; b=VH2sbDqESi0AnunOAsfDSuIVoNd42nu1gfA+bSGRS+j4Z9nHZI4QKuaKLCyNITzqRL +12MwkhkkW4rE1IDF9J1RjoSCYcx3Cv0EjdQyNmfy+IcO6pviKuxQHH5u3yYBLGiKjpH PdQ+Vml/Pa+886Ct6AHygrgqNUnPXq00PVBcUvL07GpkHrGrBp2eI4GfnxRoo8GT275e kD6ZPR6hYxY8YxEKuKzr2X7dFDftTncewZq0grrYEj3rIQ4N0DUQGZMF6b9gxo4tdPnq 5tvxid+IEX1hJSTNR+tD1zXVxAppgbo7/KMpvRSxNLTBWjcthSpsrqlOvM/rv4UO0yN4 ZexQ== 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=nHEyzaj0Xe6lvGvK4uNO3cxht7LVWKgKLecVOkA5AJQ=; b=gabkbgrAifLLADi83MgdBvf/auUglaiiGchAntx65GXINTilC1FGJp/Kp0iZbxAVJs kuk6HtRk4Gq7NLyN1DgT+CpjS/7umu+eVdX6jUq50Ki4vhi9FqdTBs9EZelQVuqFjJMn yygg1QxWekBg6r/2cfnSdfhC4nawe58+UG8pztuSl3jgZ81tOp8ge5bMHOcYMuoSKPu3 AqeD9MIuSPqkUGUFJpnBnYxc44D/CMNGWeaHZWO3hHh5oFG4C3fz+n6t30V/9PAhdUkj BIzeBSir+KaRJb91OT1cpcb2cLcRf9fYvuE/p/7CkWTtJqvqSJkC3tnqoqU97F8kpis0 3HAQ== X-Gm-Message-State: AJcUukeFAUozQsWHNDZmvX6r7umRGJsmV3M497uyiaWS0tUpIRUkeQ4x eNlTVhyPBpjlEoM3UZYrCqw= X-Google-Smtp-Source: ALg8bN4PCamluMdLU0hkgebW1ttPbfO74CfvEYNuCmS3/QWZ5thQuxE5CG8AVaqjL4CF7JlVWnPDbg== X-Received: by 2002:a17:902:22f:: with SMTP id 44mr16736941plc.137.1547257729798; Fri, 11 Jan 2019 17:48:49 -0800 (PST) Received: from localhost.localdomain ([2001:268:c0a3:ffc5:36e2:bccb:ba63:9e84]) by smtp.gmail.com with ESMTPSA id w5sm104233368pfn.89.2019.01.11.17.48.43 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Fri, 11 Jan 2019 17:48:49 -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 v7 5/8] gpio: gpio-mm: Utilize for_each_set_clump8 macro Date: Sat, 12 Jan 2019 10:49:22 +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-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..ad80f874e004 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 Sat Jan 12 01:49:41 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: William Breathitt Gray X-Patchwork-Id: 1023838 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="GYToRQse"; dkim-atps=neutral Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by ozlabs.org (Postfix) with ESMTP id 43c2hp6cy2z9sDn for ; Sat, 12 Jan 2019 12:49:14 +1100 (AEDT) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726418AbfALBtG (ORCPT ); Fri, 11 Jan 2019 20:49:06 -0500 Received: from mail-pg1-f193.google.com ([209.85.215.193]:41610 "EHLO mail-pg1-f193.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726227AbfALBtG (ORCPT ); Fri, 11 Jan 2019 20:49:06 -0500 Received: by mail-pg1-f193.google.com with SMTP id m1so7048086pgq.8; Fri, 11 Jan 2019 17:49:05 -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=lWYabFVT2N9Pm4UFPqAjVCH7x7Uil0K2CYo2zNlIxxg=; b=GYToRQseVhD5lZ1KnIs4C6hTA6wVbzAOXMogWlGw6QLGXl0xMyu2E8nb5L05+a3Gwb 7H6WRX1EFy74XDXSh24uqlf3XdUZhLTRDMypGJmaLpvhi3FEh89OQKx8DpjbIw27TZ7/ H/96YoTFFE7RcYsVAP7zZ6mYl27LBl27ZD4+m+scns9aDC+U1P6KpcET/UAFFT4KCqWX P70v7EXhvmSJTTTCBD7jVIiEKQBFnzgpmEa2CKhGQPU9PzhdkZ3Wurc4QSiEuIu3W9iu AQljyyFG/hHKdien4X/fBBMJlpw/64KwGk6ryqYK/C7KofLI+fGEquWKmz1eabrJoFWX 15+Q== 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=lWYabFVT2N9Pm4UFPqAjVCH7x7Uil0K2CYo2zNlIxxg=; b=fJjNOO62xbNJGepMiT7tzR2JQbzJnpK5I6zOZetBvUYFo/t1gU7Lvnj/ZQwUnUoZDS e5jTp7pw5PSxZvI8P3nAHZplBBIX6H4dfFmTaCJ8+2Uh5CbfMYuo4QUt49Ot5/OE5Zye +fTpLaDqhfPYXgitnFKlI1g8CeHPymwjh11PX8FZoleSdnq/uoXvUJLXi/CYRyPyNaB8 lQ7mo42WC7dSN9wZDVGdjDt2lbIjk5D0evBTciPrjL9PtY6l5dwIZTfmLqq5aSRsba38 NP5lW/VFH1s5W9aS8glSrvip1WuJouRngeFBOLrkkRmyjAKafMg43KAyH03fKOgN8wW3 fBHA== X-Gm-Message-State: AJcUukdyMRFbwyc61gGBlew4c3y+aPGGYKO2tHRHSa7HrzWr9VlMDGgd 0H41uWBi4tRTBjeOYUqbzINDBaj3 X-Google-Smtp-Source: ALg8bN6lNkqtn2MZtn6UfD6T/12+OQWvO1zORFjIZ1LXe8gQvIE1fsyPPuT59S8tWU/xiWpzykwe7w== X-Received: by 2002:a63:554b:: with SMTP id f11mr13558256pgm.37.1547257745112; Fri, 11 Jan 2019 17:49:05 -0800 (PST) Received: from localhost.localdomain ([2001:268:c0a3:ffc5:36e2:bccb:ba63:9e84]) by smtp.gmail.com with ESMTPSA id w184sm90638299pgd.34.2019.01.11.17.49.02 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Fri, 11 Jan 2019 17:49:04 -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 v7 6/8] gpio: ws16c48: Utilize for_each_set_clump8 macro Date: Sat, 12 Jan 2019 10:49:41 +0900 Message-Id: <5c530526bc8c55c83dc3c47abee5129bda3e41db.1547257386.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-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..48cb9aa740b5 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 Sat Jan 12 01:49: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: 1023839 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="e6kVu4bL"; dkim-atps=neutral Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by ozlabs.org (Postfix) with ESMTP id 43c2hy67MZz9s55 for ; Sat, 12 Jan 2019 12:49:22 +1100 (AEDT) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726496AbfALBtV (ORCPT ); Fri, 11 Jan 2019 20:49:21 -0500 Received: from mail-pl1-f193.google.com ([209.85.214.193]:39790 "EHLO mail-pl1-f193.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726497AbfALBtV (ORCPT ); Fri, 11 Jan 2019 20:49:21 -0500 Received: by mail-pl1-f193.google.com with SMTP id 101so7536211pld.6; Fri, 11 Jan 2019 17:49:20 -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=iTzVoRUCUmsw6JJQwL/GudbwLQByFCx/7cmwrU+BhiQ=; b=e6kVu4bL6SYzmzWgExnsZ4tMFecdyv1391hJc3SJ+oqyDZzKQj1o1dUJ4Lcoc1DPk3 DAOK473DbR+W8wGKmjoWhId4qoQ/e4ZhHGlZecwEKmv9n7DYIdatsyTNhyaTYVqOeb65 bQogce+rubiY17R63wworsNdyZGIIBZ1rw/oB4JLp1H581sBrZTwQu4unPRszUukHQAL PxJBhMwJyEzz65DYjeMqSFT3waMsFtMEF5vTwyD7+ZarFbOyOAtgObc+XMd7ksduxVgB XyLaBTSsNCZ/RCVOEbmQKAR0nFqA0j2ZTLgoYeWc5Pol0gIgopd2V1kHz8l9SPvPJ2n1 r1xQ== 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=iTzVoRUCUmsw6JJQwL/GudbwLQByFCx/7cmwrU+BhiQ=; b=iHSpXskB1iwhbuiJ71/9KU0/H+vzAVeOpItlBh6WqchSga4P+FMV9yLhGVIbnSV1W0 7AxxjPJNTlcr2T3na7BJUw7oPXWGNIGmUK/foFaQuv5ZXTiOb/woJ+y3r6REYb+J2GMw qmTMv70FMVfQX+yXTkGSkdC3GHHuTQfU/PpXB4N6/TRq2UN+qbJMlizmjb9LyHSW+SE2 I5AmyKYunlFwcfPn0L5i/o66j6G76scVOJNoYtVgM7PIJJexS9cIfd8OluuAJvSR5ymz 38PrftIEBtPV99rNOe1uYsBihegJKuztkwd+ZyaaXI0YulOj29fvIP5dDl5cyfI0J/ln bUJQ== X-Gm-Message-State: AJcUukdzrnn7pQTn9oi3bsZ8BOefp8ZTqqpq0CNEygPsT+3al3neek7X RWQsRYU7LI3UDbsNUsy0eCg= X-Google-Smtp-Source: ALg8bN42pcs/xbMT69wcX9Q9oTApAADZGd4X598hcehGjxC63qcge3SSW63EH+yLpvOD/EGGlFNSMQ== X-Received: by 2002:a17:902:ab84:: with SMTP id f4mr16489635plr.207.1547257760516; Fri, 11 Jan 2019 17:49:20 -0800 (PST) Received: from localhost.localdomain ([2001:268:c0a3:ffc5:36e2:bccb:ba63:9e84]) by smtp.gmail.com with ESMTPSA id 186sm157318979pga.36.2019.01.11.17.49.17 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Fri, 11 Jan 2019 17:49: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 v7 7/8] gpio: pci-idio-16: Utilize for_each_set_clump8 macro Date: Sat, 12 Jan 2019 10:49:57 +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-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..f115b923ae98 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 Sat Jan 12 01:50:14 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: 1023840 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="oIVo/7bY"; dkim-atps=neutral Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by ozlabs.org (Postfix) with ESMTP id 43c2jL4DG8z9s9h for ; Sat, 12 Jan 2019 12:49:42 +1100 (AEDT) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726486AbfALBtl (ORCPT ); Fri, 11 Jan 2019 20:49:41 -0500 Received: from mail-pg1-f193.google.com ([209.85.215.193]:41642 "EHLO mail-pg1-f193.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726270AbfALBtl (ORCPT ); Fri, 11 Jan 2019 20:49:41 -0500 Received: by mail-pg1-f193.google.com with SMTP id m1so7048534pgq.8; Fri, 11 Jan 2019 17:49:40 -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=jURKoCuYgoRmXfa/TDGyum4RfP73k6trObkzzXQFc10=; b=oIVo/7bYM4y8C6UMJuJeZOkjAP0OTolk3hB4gwgryVVcnyExwPeFTdODwcDdUQxPFI qXB2620UUzj8DgJGkMsDAAKPbKfethtB1FtSriSK9ywHWVKabaEvqKcd0PGMmMJQX8Y3 dPjdEifWzNvmUd3PjzY/l7opkj8ZyJQyLfaj5evVOHt4lvC4eHti52Iqhl54SmWyE0rS MFKHg2E4sgBOl6vSYIUeAG0A+IQlOQb22rtDGp7Zt6ycYA3U2ZxLnVlljfkm6hcL/Ns6 K6uxmwtkDG5VE/jB9/IDuTzMFnhAvgJfTGDunli/HEP0nFrXEH8P99UOP5qC+jkLDXHD 1DBg== 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=jURKoCuYgoRmXfa/TDGyum4RfP73k6trObkzzXQFc10=; b=A4y4Yn7DgHJm4NIR7b3y4GgKkwdfGdcuEHfAXrjpPSCLR/+il2NfA3ivlaEusQ3Hz6 T3Z8Had47fBZJxrCgvwznsePkQ9XdUydtL8B0eQ167aNr8VIhNUqdtrKO0+uxwfhw4Z8 1g1uFyui+Q/TlYuJ3sL9LyKKZMe16iBsqd4aABmjrm0uKWECM0gRwD8XJDhKtOSJIPnF VKikZtqTu/dk4Lj0P9WnIIGY1I2QYcoO7a7Ei1H6biHPHof0UbDmSHOfVztXVn5NehMd vfDnMElmUtpwMV9STFmEaSA8duMjhHVzBnQQdTvMwnTGxCfVcBlxpzswLdsZPLhaVtz+ ZvdQ== X-Gm-Message-State: AJcUukfO5TDH8h+KSxvwt3p208HFkNCf/RzOc60mjNudLut7abCHzLSR c2/nfdzq1g5b7w56Q3fOvkc= X-Google-Smtp-Source: ALg8bN5bXIhovq0o5pVes9JxrkelE4oxa8ivINsI7H1QX+y2M24tOpLOoiwYrHN0KeK8E76B+/rVBw== X-Received: by 2002:a63:b4c:: with SMTP id a12mr15644035pgl.131.1547257780194; Fri, 11 Jan 2019 17:49:40 -0800 (PST) Received: from localhost.localdomain ([2001:268:c0a3:ffc5:36e2:bccb:ba63:9e84]) by smtp.gmail.com with ESMTPSA id 128sm120178819pfu.129.2019.01.11.17.49.34 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Fri, 11 Jan 2019 17:49:39 -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 v7 8/8] gpio: pcie-idio-24: Utilize for_each_set_clump8 macro Date: Sat, 12 Jan 2019 10:50:14 +0900 Message-Id: <1c82bec73e574b11504c1244d6f3d099a1cbb66c.1547257386.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-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..1cfe39fb8e9e 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)