From patchwork Thu Mar 14 12:30:02 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: 10852709 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 3F71C139A for ; Thu, 14 Mar 2019 12:29:21 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 2528E286EC for ; Thu, 14 Mar 2019 12:29:21 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 194312A006; Thu, 14 Mar 2019 12:29:21 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-5.2 required=2.0 tests=BAYES_00,DKIM_ADSP_CUSTOM_MED, DKIM_SIGNED,DKIM_VALID,FREEMAIL_FROM,MAILING_LIST_MULTI,RCVD_IN_DNSWL_MED autolearn=ham version=3.3.1 Received: from bombadil.infradead.org (bombadil.infradead.org [198.137.202.133]) (using TLSv1.2 with cipher AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.wl.linuxfoundation.org (Postfix) with ESMTPS id 8015E29EF5 for ; Thu, 14 Mar 2019 12:29:20 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20170209; h=Sender: Content-Transfer-Encoding:Content-Type:Cc:List-Subscribe:List-Help:List-Post: List-Archive:List-Unsubscribe:List-Id:MIME-Version:References:In-Reply-To: Message-Id:Date:Subject:To:From:Reply-To:Content-ID:Content-Description: Resent-Date:Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID: List-Owner; bh=W/5GS66YYQKdjerXP8slR4oeAyQdvJBU8Beb0XK1v4A=; b=FoFlc9FI2UlQB1 i0qsYs7lkUejp7U+1OrmreC5jYCG+/UAUvSpHTN5+ZmJB5d979ihXXsedBZNRyeBj52DKRM1nfoAz eEd0TjZw/DES5JyaMcohphG+4K6nvdLl/HASkmGEGy3uYnM4Exdq512ksSMLXhM5NWnzZjga2xLF9 VZEeJ8GwN9glrHIA5BTKnF3HmDthAjopBxgypzSwWzwvzYWJN07QziUpok87sC78WfFWvJGOj7ghE By2sgYdkgzZ6J1TGodPPyD7Sa89Uc1r5W67bhEClnll5BOlNmfW2E7ZdOjGbKiwttoqcq6/xHIonV UVfu8dB2fDE9SYk0UKHA==; Received: from localhost ([127.0.0.1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.90_1 #2 (Red Hat Linux)) id 1h4PU6-0005UH-Gs; Thu, 14 Mar 2019 12:29:18 +0000 Received: from mail-pg1-x541.google.com ([2607:f8b0:4864:20::541]) by bombadil.infradead.org with esmtps (Exim 4.90_1 #2 (Red Hat Linux)) id 1h4PU2-0005TB-0m for linux-arm-kernel@lists.infradead.org; Thu, 14 Mar 2019 12:29:16 +0000 Received: by mail-pg1-x541.google.com with SMTP id e17so3882383pgd.2 for ; Thu, 14 Mar 2019 05:29:13 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=fq6Xm53C+heMXT2c+ND0di1HUX14yEET8qKlzoFNfpw=; b=Ck7GLcpyG6wLhHl5A0PNRGDMVGSWdvreR9shUs1kcEsyr2w4FWN/ygos1sZsT+cdCi 7dTW4CTApaRASe7cnYM84Szvazoj5wTcuCpYy76YpyGYSPVhNSAMI+EYoQ76cPzQfhiA OIJjRDAy5iTMszFp5hdA0uYdMOq8ncPn7ClCUCxsW7bSyAdcMBE79dpg3fF7m1mFUNFs xh7W9PGxIafqueYac7Nhdoi5FXQucwjz9D/MMRabWS9HNyhBMmw+2wnTlOAJlIUeiWoR pcCq/VDhlJn+SGD96E1MC1Om44ckVDoZJWQh+huf3+2u475PTfSiu3vfIOS7xqbILtmD DaEQ== 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=fq6Xm53C+heMXT2c+ND0di1HUX14yEET8qKlzoFNfpw=; b=OczM1RN/lhUv+8TdTpZ4IlhsjP7Yfym3x/rfJI41H3RT2NOPp7mRG3hIIxERnUxeH9 dzxdCqHo8IoBprG74OlvTvNTGByGphQRzXTFYgHKBeIP0Jdn64oLkzRouWcdluGf0RTm HwEUckm4tX3ePjmO7kX8ZtqT8ZkSCXxiyl3QJUE8djriEtBqelx+8jnpZPzMGg9gwPZQ 9mHzaHwhs17aZk4QpEIvDOWj+H6ob5bBGlfdHLWKWcdeA2b598zBR8qw8plwqRt1j8cZ o6wGiCeqlCpZp5RyZkIiwOuNemeO3lo1WCfLrmnZML9OgeOVs6fQW7yinWX9zAt3WIvP w6SA== X-Gm-Message-State: APjAAAXPGyUl4VcOAV1uMPvpxKFkM3cBJ6jTG/wQ7o898jHkyUp9MRfs JRLg7MJnIQcmTFPv9orNP60= X-Google-Smtp-Source: APXvYqxzAQX9w1BWqiu5T2oM2H1q3X0lR4pNz3Z8C9cG00cB+QxlRrzSofJUB/mxr/DW4W0PAImhEg== X-Received: by 2002:a17:902:112c:: with SMTP id d41mr51072666pla.177.1552566553320; Thu, 14 Mar 2019 05:29:13 -0700 (PDT) Received: from localhost.localdomain ([2001:268:c0a4:3974:c70:4af9:86e2:2]) by smtp.gmail.com with ESMTPSA id g2sm26358279pfm.144.2019.03.14.05.29.07 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Thu, 14 Mar 2019 05:29:12 -0700 (PDT) From: William Breathitt Gray To: linus.walleij@linaro.org Subject: [PATCH v10 01/10] bitops: Introduce the for_each_set_clump8 macro Date: Thu, 14 Mar 2019 21:30:02 +0900 Message-Id: <0e4d352418252d480dfc7d529604819f8ff88d9c.1552566113.git.vilhelm.gray@gmail.com> X-Mailer: git-send-email 2.21.0 In-Reply-To: References: MIME-Version: 1.0 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20190314_052914_059019_E2145BC7 X-CRM114-Status: GOOD ( 14.82 ) X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: linux-arch@vger.kernel.org, Arnd Bergmann , yamada.masahiro@socionext.com, linux@rasmusvillemoes.dk, linux-kernel@vger.kernel.org, William Breathitt Gray , linux-gpio@vger.kernel.org, Andy Shevchenko , bgolaszewski@baylibre.com, akpm@linux-foundation.org, andriy.shevchenko@linux.intel.com, linux-arm-kernel@lists.infradead.org Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+patchwork-linux-arm=patchwork.kernel.org@lists.infradead.org X-Virus-Scanned: ClamAV using ClamSMTP This macro iterates for each 8-bit group of bits (clump) with set bits, within a bitmap memory region. For each iteration, "start" is set to the bit offset of the found clump, while the respective clump value is stored to the location pointed by "clump". Additionally, the bitmap_get_value8 and bitmap_set_value8 functions are introduced to respectively get and set an 8-bit value in a bitmap memory region. Suggested-by: Andy Shevchenko Suggested-by: Rasmus Villemoes Cc: Arnd Bergmann Acked-by: Andrew Morton Reviewed-by: Andy Shevchenko Reviewed-by: Linus Walleij Signed-off-by: William Breathitt Gray --- include/asm-generic/bitops/find.h | 14 ++++++ include/linux/bitops.h | 5 ++ lib/find_bit.c | 81 +++++++++++++++++++++++++++++++ 3 files changed, 100 insertions(+) diff --git a/include/asm-generic/bitops/find.h b/include/asm-generic/bitops/find.h index 8a1ee10014de..9a76adff59c6 100644 --- a/include/asm-generic/bitops/find.h +++ b/include/asm-generic/bitops/find.h @@ -80,4 +80,18 @@ extern unsigned long find_first_zero_bit(const unsigned long *addr, #endif /* CONFIG_GENERIC_FIND_FIRST_BIT */ +unsigned long bitmap_get_value8(const unsigned long *const bitmap, + const unsigned int size, + const unsigned int start); + +void bitmap_set_value8(unsigned long *const bitmap, const unsigned int size, + const unsigned long value, const unsigned int start); + +unsigned int find_next_clump8(unsigned long *const clump, + const unsigned long *const addr, + unsigned int offset, const unsigned int size); + +#define find_first_clump8(clump, bits, size) \ + find_next_clump8((clump), (bits), 0, (size)) + #endif /*_ASM_GENERIC_BITOPS_FIND_H_ */ diff --git a/include/linux/bitops.h b/include/linux/bitops.h index 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..c2af1f013ea2 100644 --- a/lib/find_bit.c +++ b/lib/find_bit.c @@ -218,3 +218,84 @@ EXPORT_SYMBOL(find_next_bit_le); #endif #endif /* __BIG_ENDIAN */ + +/** + * bitmap_get_value8 - get an 8-bit value within a memory region + * @bitmap: address to the bitmap memory region + * @size: bitmap size in number of bits + * @start: bit offset of the 8-bit value + * + * Returns the 8-bit value located at the @start bit offset within the @bitmap + * memory region. + */ +unsigned long bitmap_get_value8(const unsigned long *const bitmap, + const unsigned int size, + const unsigned int start) +{ + const size_t index = BIT_WORD(start); + const unsigned int offset = start % BITS_PER_LONG; + const unsigned int low_width = (offset + 8 > BITS_PER_LONG) ? + BITS_PER_LONG - offset : 8; + const unsigned long low = bitmap[index] >> offset; + const unsigned long high = (low_width < 8 && start + 8 <= size) ? + bitmap[index + 1] << low_width : 0; + + return (low | high) & 0xFF; +} +EXPORT_SYMBOL(bitmap_get_value8); + +/** + * bitmap_set_value8 - set an 8-bit value within a memory region + * @bitmap: address to the bitmap memory region + * @size: bitmap size in number of bits + * @value: the 8-bit value; values wider than 8 bits may clobber bitmap + * @start: bit offset of the 8-bit value + */ +void bitmap_set_value8(unsigned long *const bitmap, const unsigned int size, + const unsigned long value, const unsigned int start) +{ + const size_t index = BIT_WORD(start); + const unsigned int offset = start % BITS_PER_LONG; + const unsigned int low_width = (offset + 8 > BITS_PER_LONG) ? + BITS_PER_LONG - offset : 8; + const unsigned long low_mask = GENMASK(offset + low_width - 1, offset); + const unsigned int high_width = 8 - low_width; + const unsigned long high_mask = GENMASK(high_width - 1, 0); + + /* set lower portion */ + bitmap[index] &= ~low_mask; + bitmap[index] |= value << offset; + + /* set higher portion if space available in bitmap */ + if (high_width && start + 8 <= size) { + bitmap[index + 1] &= ~high_mask; + bitmap[index + 1] |= value >> low_width; + } +} +EXPORT_SYMBOL(bitmap_set_value8); + +/** + * find_next_clump8 - find next 8-bit clump with set bits in a memory region + * @clump: location to store copy of found clump + * @addr: address to base the search on + * @offset: bit offset at which to start searching + * @size: bitmap size in number of bits + * + * Returns the bit offset for the next set clump; the found clump value is + * copied to the location pointed by @clump. If no bits are set, returns @size. + */ +unsigned int find_next_clump8(unsigned long *const clump, + const unsigned long *const addr, + unsigned int offset, const unsigned int size) +{ + for (; offset < size; offset += 8) { + *clump = bitmap_get_value8(addr, size, offset); + if (!*clump) + continue; + + return offset; + } + + return size; +} +EXPORT_SYMBOL(find_next_clump8); From patchwork Thu Mar 14 12:30:24 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: William Breathitt Gray X-Patchwork-Id: 10852711 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 2EEE41515 for ; Thu, 14 Mar 2019 12:29:40 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 14C1F2A37B for ; Thu, 14 Mar 2019 12:29:40 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 084552A3AF; Thu, 14 Mar 2019 12:29:40 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-5.2 required=2.0 tests=BAYES_00,DKIM_ADSP_CUSTOM_MED, DKIM_SIGNED,DKIM_VALID,FREEMAIL_FROM,MAILING_LIST_MULTI,RCVD_IN_DNSWL_MED autolearn=ham version=3.3.1 Received: from bombadil.infradead.org (bombadil.infradead.org [198.137.202.133]) (using TLSv1.2 with cipher AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.wl.linuxfoundation.org (Postfix) with ESMTPS id 842432A37B for ; Thu, 14 Mar 2019 12:29:39 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20170209; h=Sender: Content-Transfer-Encoding:Content-Type:Cc:List-Subscribe:List-Help:List-Post: List-Archive:List-Unsubscribe:List-Id:MIME-Version:References:In-Reply-To: Message-Id:Date:Subject:To:From:Reply-To:Content-ID:Content-Description: Resent-Date:Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID: List-Owner; bh=NGjO61jJ+ZtHjMj7PjKydAZFMhP3fiH/iEzwOEbSN9s=; b=ZlwQNKyOt5TYQ8 JMgzraUt2EZNEf3oLz5j8oXBdIJ8b9TfDsN85NHV6YN1bzqoUoKU2uQf8iAcIu6s1FC0KPKDnPOVc 4E/V9/z0E9qRf7lEsKxvrKjgL9LEcm4bI5lZAfUf2K564TeR0OgiVlcWEKRJNkfun+RcgiWg22xqE XvuBYYMG3RqCWWpCEQGyLFBxxVhYQxsGjWMj3gGxEUJLlzN6hPvjCPyAoSLPI3oFAFd9fcgaGnEjS hZuWTcxpdPJwtUV+VsA5WQzx94VtZC4VGOlNNw7kENMatjrFqRHuIb+/BRNxiZcKQLEqKPQrhJI96 HzmRWdAAP4SjXbb0O1cQ==; Received: from localhost ([127.0.0.1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.90_1 #2 (Red Hat Linux)) id 1h4PUP-0005pB-Bz; Thu, 14 Mar 2019 12:29:37 +0000 Received: from mail-pf1-x444.google.com ([2607:f8b0:4864:20::444]) by bombadil.infradead.org with esmtps (Exim 4.90_1 #2 (Red Hat Linux)) id 1h4PUK-0005kJ-BB for linux-arm-kernel@lists.infradead.org; Thu, 14 Mar 2019 12:29:35 +0000 Received: by mail-pf1-x444.google.com with SMTP id d25so3718066pfn.8 for ; Thu, 14 Mar 2019 05:29:32 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=voPjJIpaEIENDSX5D22rQL6GtMzeJ5e93HyvmN9lrck=; b=pTqUtj30cxrD+gvouv7l3w0sFX0bU95MZfqL2IhBnTFd3ZXuG/F5ODVBg9kgA9QzHs r3mDBmiOdL+UC7yLlhKjBcQ36z0WatAFhJT2WDUW9Ync2XxWNO3qNODGTvVMlbhOOXpj lefjWJGy+IWcFMkn6iVeqNNz5N+0ijmh/LpNpFp97+yrMMq7gZ+OwYHQJNm3lzvfByRj Mh0Fjho/B5rZRA/iSHmM5FyRH+snx0QBJjNfgzqxiv5mjFlQj3tnpez3VKh0d6z3rzE8 RNt/AhoyDOsoSHal0yMP+L9rQ2hK6bRHJ38L63OkIDRR9fgMUXTT+9kbS3Ezmq7LFXrw hecA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=voPjJIpaEIENDSX5D22rQL6GtMzeJ5e93HyvmN9lrck=; b=oslDVWTjeso6uD8lVgdsS7KTlrQiXRc6n5rue9t1soqk+oFWKq48CvDuA85GldHfYg /Mtj+Vm/K1qvg3X7JFbdA2/GLEaeQBwH0yL8V/Y4eK2cRA7JYXqdKENA+VtAues2xPrz sKkqc3s5pfNSACrz06WLWP9MVPf6a2s7AAyYIsXKqn8SgkihfGk41vsaqrdqT6alOYyH YTfGZEgfu77U3MRC4IAOViFTYSEj3mI6pg9xCNVc8QSJalWGopo2ouaDQhZ3TWwZ/Ps+ C/T6IrzWroIIGx3miqS3T68ZILdEZtJL4ZtrmXJenqymbpVV5nBZjACKsTZ2x21riSZL P4Mw== X-Gm-Message-State: APjAAAXRbP+3SmdJ/Jln8yCYSbxZDjHYxRA33LlKYDTizxPHguoi5wd2 By4azziwy6/B9HEw/B2Gx+X4Gw8R X-Google-Smtp-Source: APXvYqy5UvtD/Kf3+GFJlYe8rHPF7gTdnvCaAjrNRw0ivGvgRMuD2mN3+AT9okFrXWaVOTJwEpNVnQ== X-Received: by 2002:a63:da58:: with SMTP id l24mr9806796pgj.167.1552566571813; Thu, 14 Mar 2019 05:29:31 -0700 (PDT) Received: from localhost.localdomain ([2001:268:c0a4:3974:c70:4af9:86e2:2]) by smtp.gmail.com with ESMTPSA id k189sm13888301pgk.21.2019.03.14.05.29.27 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Thu, 14 Mar 2019 05:29:31 -0700 (PDT) From: William Breathitt Gray To: linus.walleij@linaro.org Subject: [PATCH v10 02/10] lib/test_bitmap.c: Add for_each_set_clump8 test cases Date: Thu, 14 Mar 2019 21:30:24 +0900 Message-Id: X-Mailer: git-send-email 2.21.0 In-Reply-To: References: MIME-Version: 1.0 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20190314_052932_407414_93E7DDA4 X-CRM114-Status: GOOD ( 14.04 ) X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: linux-arch@vger.kernel.org, yamada.masahiro@socionext.com, linux@rasmusvillemoes.dk, linux-kernel@vger.kernel.org, William Breathitt Gray , linux-gpio@vger.kernel.org, Andy Shevchenko , bgolaszewski@baylibre.com, akpm@linux-foundation.org, andriy.shevchenko@linux.intel.com, linux-arm-kernel@lists.infradead.org Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+patchwork-linux-arm=patchwork.kernel.org@lists.infradead.org X-Virus-Scanned: ClamAV using ClamSMTP The introduction of the for_each_set_clump8 macro warrants test cases to verify the implementation. This patch adds test case checks for whether an out-of-bounds clump index is returned, a zero clump is returned, or the returned clump value differs from the expected clump value. Cc: Rasmus Villemoes Acked-by: Andrew Morton Reviewed-by: Andy Shevchenko Reviewed-by: Linus Walleij Signed-off-by: William Breathitt Gray --- lib/test_bitmap.c | 65 +++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 65 insertions(+) diff --git a/lib/test_bitmap.c b/lib/test_bitmap.c index 6cd7d0740005..8d1f268069c1 100644 --- a/lib/test_bitmap.c +++ b/lib/test_bitmap.c @@ -88,6 +88,36 @@ __check_eq_u32_array(const char *srcfile, unsigned int line, return true; } +static bool __init __check_eq_clump8(const char *srcfile, unsigned int line, + const unsigned int offset, + const unsigned int size, + const unsigned char *const clump_exp, + const unsigned long *const clump) +{ + unsigned long exp; + + if (offset >= size) { + pr_warn("[%s:%u] bit offset for clump out-of-bounds: expected less than %u, got %u\n", + srcfile, line, size, offset); + return false; + } + + exp = clump_exp[offset / 8]; + if (!exp) { + pr_warn("[%s:%u] bit offset for zero clump: expected nonzero clump, got bit offset %u with clump value 0", + srcfile, line, offset); + return false; + } + + if (*clump != exp) { + pr_warn("[%s:%u] expected clump value of 0x%lX, got clump value of 0x%lX", + srcfile, line, exp, *clump); + return false; + } + + return true; +} + #define __expect_eq(suffix, ...) \ ({ \ int result = 0; \ @@ -104,6 +134,7 @@ __check_eq_u32_array(const char *srcfile, unsigned int line, #define expect_eq_bitmap(...) __expect_eq(bitmap, ##__VA_ARGS__) #define expect_eq_pbl(...) __expect_eq(pbl, ##__VA_ARGS__) #define expect_eq_u32_array(...) __expect_eq(u32_array, ##__VA_ARGS__) +#define expect_eq_clump8(...) __expect_eq(clump8, ##__VA_ARGS__) static void __init test_zero_clear(void) { @@ -361,6 +392,39 @@ static void noinline __init test_mem_optimisations(void) } } +static const unsigned char clump_exp[] __initconst = { + 0x01, /* 1 bit set */ + 0x02, /* non-edge 1 bit set */ + 0x00, /* zero bits set */ + 0x38, /* 3 bits set across 4-bit boundary */ + 0x38, /* Repeated clump */ + 0x0F, /* 4 bits set */ + 0xFF, /* all bits set */ + 0x05, /* non-adjacent 2 bits set */ +}; + +static void __init test_for_each_set_clump8(void) +{ +#define CLUMP_EXP_NUMBITS 64 + DECLARE_BITMAP(bits, CLUMP_EXP_NUMBITS); + unsigned int start; + unsigned long clump; + + /* set bitmap to test case */ + bitmap_zero(bits, CLUMP_EXP_NUMBITS); + bitmap_set(bits, 0, 1); /* 0x01 */ + bitmap_set(bits, 9, 1); /* 0x02 */ + bitmap_set(bits, 27, 3); /* 0x28 */ + bitmap_set(bits, 35, 3); /* 0x28 */ + bitmap_set(bits, 40, 4); /* 0x0F */ + bitmap_set(bits, 48, 8); /* 0xFF */ + bitmap_set(bits, 56, 1); /* 0x05 - part 1 */ + bitmap_set(bits, 58, 1); /* 0x05 - part 2 */ + + for_each_set_clump8(start, clump, bits, CLUMP_EXP_NUMBITS) + expect_eq_clump8(start, CLUMP_EXP_NUMBITS, clump_exp, &clump); +} + static int __init test_bitmap_init(void) { test_zero_clear(); @@ -369,6 +433,7 @@ static int __init test_bitmap_init(void) test_bitmap_arr32(); test_bitmap_parselist(); test_mem_optimisations(); + test_for_each_set_clump8(); if (failed_tests == 0) pr_info("all %u tests passed\n", total_tests); From patchwork Thu Mar 14 12:30:42 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: 10852713 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id C31871515 for ; Thu, 14 Mar 2019 12:30:01 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id A6C032A3BC for ; Thu, 14 Mar 2019 12:30:01 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 9898E2A3AA; Thu, 14 Mar 2019 12:30:01 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-5.2 required=2.0 tests=BAYES_00,DKIM_ADSP_CUSTOM_MED, DKIM_SIGNED,DKIM_VALID,FREEMAIL_FROM,MAILING_LIST_MULTI,RCVD_IN_DNSWL_MED autolearn=ham version=3.3.1 Received: from bombadil.infradead.org (bombadil.infradead.org [198.137.202.133]) (using TLSv1.2 with cipher AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.wl.linuxfoundation.org (Postfix) with ESMTPS id 720B22A3BC for ; Thu, 14 Mar 2019 12:30:00 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20170209; h=Sender: Content-Transfer-Encoding:Content-Type:Cc:List-Subscribe:List-Help:List-Post: List-Archive:List-Unsubscribe:List-Id:MIME-Version:References:In-Reply-To: Message-Id:Date:Subject:To:From:Reply-To:Content-ID:Content-Description: Resent-Date:Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID: List-Owner; bh=8S1NRFXAry7OT1sEQgnbr77coxWRoNIKo3aUm4nxjFs=; b=t+RNd8bm6v7PIu ovA6BgYnHUw7qvaFVdYf0XdT1LWEExeHrfiaMQlxyz8uUV6eiZlfqMRL2IgtqI/6SP2NgoGSTCnsB aeJ2xCHPztXdUpYwjcedKEc+AEDR6MTmX5/wTC41arzHQPMD72YzHALVOguTU4x0xBi+MrPaR+o7b k1qXkIMxn7ski5jHWD4nTj7Kg0QNiTiCL7a4+cExjyAw7+oMvdFHhLGnbtomX35hcNB+fA+UalVOw VXrAczRLDaw6UgZ3W34Cq+R4L/jkLquXKgsuLauQojHhKH6FvHppJzAuEwdPGYRQ5f6XzQCTIWr5P KLOmCbYxlon13+TawK0Q==; Received: from localhost ([127.0.0.1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.90_1 #2 (Red Hat Linux)) id 1h4PUk-0006HX-Mw; Thu, 14 Mar 2019 12:29:58 +0000 Received: from mail-pf1-x443.google.com ([2607:f8b0:4864:20::443]) by bombadil.infradead.org with esmtps (Exim 4.90_1 #2 (Red Hat Linux)) id 1h4PUc-0006AB-20 for linux-arm-kernel@lists.infradead.org; Thu, 14 Mar 2019 12:29:56 +0000 Received: by mail-pf1-x443.google.com with SMTP id y124so3720017pfy.7 for ; Thu, 14 Mar 2019 05:29:50 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=5tnH02Yc3JnragyosQ4LQT3N7xcrc3Yee7t/cF7aZ1U=; b=afmsyoRZR6TWA9FJLD5BfcEqWqmpjPB9rVYhyp0oYzUnGbT1Pnfl4b5u9zw3LUOux6 E/GJMatSIN2+oVDq5f38rNIW5jvbWl/u6EV9VmTDgFr9Mvz4U4XjVhqORKNfa5rpSh0+ rH49wcep/vZ5Ysg0Q81B7YJ+AeqZij78MojNWLZhe3BFmEh3i6MQqs7QiGxuq/YlKWTJ NBu18By2/pv3a3HL+2PBZ64c0e7M/ZRDuSwHH9nBwPV/GtlWLLZiSnl1+g56aqfMgXkC GnR5mEd1nhmFeNmEjI0fwH7n+LJXfwZTWDSmUeRcl272v2EkvPFC6syWTeF4o9jG/Uzc 5Tqw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=5tnH02Yc3JnragyosQ4LQT3N7xcrc3Yee7t/cF7aZ1U=; b=IMK7Edv6tQ8LO9q4uPNKgbdzBdgQM7zElwIiLg7jt/oYJV4jIpm/A3741FHWlv04dJ KRIbWl1+S/6eOu4ygYn9LzDwk3StTgIhw6YaI5SaLsw1XjoJkx3qqoEj9XKUGtykmK6Z RMW1xKAX0eLSNLmZca7oyWfO46KlWYgzQXXnAvvhohsmcYgaJiKIpXrTQmHv7gNeu3sl xQKipb559taSo1wJfN1V7kNBeUZcbwCZmRuVQFjmbWOjbneqS37reOfs9yAbzFYtexfH Uaz+FwsiCR1AZSVnIzkfJy5t+MNfplHJVM2i+IT9dHgxc2lmhVBLohFBAJ4Ee0y5E7sK ZEiw== X-Gm-Message-State: APjAAAVWUvSjjwCBbWO9ETBlKAbzGPfCyTfFhzJhwxCSYtjSX6OEZAFT IctFyMuUGqKH7z6Eyj36Y6Q= X-Google-Smtp-Source: APXvYqw423ATEMoqNrHOhcNG2pTRmU6ZYg2xUtFiWBO3VGcqVA2QpSceHQwaOWAhy9z+5SX2/ghV6A== X-Received: by 2002:a17:902:1621:: with SMTP id g30mr51058579plg.116.1552566589450; Thu, 14 Mar 2019 05:29:49 -0700 (PDT) Received: from localhost.localdomain ([2001:268:c0a4:3974:c70:4af9:86e2:2]) by smtp.gmail.com with ESMTPSA id d16sm22550391pfo.112.2019.03.14.05.29.45 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Thu, 14 Mar 2019 05:29:49 -0700 (PDT) From: William Breathitt Gray To: linus.walleij@linaro.org Subject: [PATCH v10 03/10] gpio: 104-dio-48e: Utilize for_each_set_clump8 macro Date: Thu, 14 Mar 2019 21:30:42 +0900 Message-Id: X-Mailer: git-send-email 2.21.0 In-Reply-To: References: MIME-Version: 1.0 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20190314_052950_243734_286E181A X-CRM114-Status: GOOD ( 14.34 ) X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: linux-arch@vger.kernel.org, yamada.masahiro@socionext.com, linux@rasmusvillemoes.dk, linux-kernel@vger.kernel.org, William Breathitt Gray , linux-gpio@vger.kernel.org, bgolaszewski@baylibre.com, akpm@linux-foundation.org, andriy.shevchenko@linux.intel.com, linux-arm-kernel@lists.infradead.org Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+patchwork-linux-arm=patchwork.kernel.org@lists.infradead.org X-Virus-Scanned: ClamAV using ClamSMTP Replace verbose implementation in get_multiple/set_multiple callbacks with for_each_set_clump8 macro to simplify code and improve clarity. Reviewed-by: Linus Walleij Signed-off-by: William Breathitt Gray --- drivers/gpio/gpio-104-dio-48e.c | 73 ++++++++++----------------------- 1 file changed, 22 insertions(+), 51 deletions(-) diff --git a/drivers/gpio/gpio-104-dio-48e.c b/drivers/gpio/gpio-104-dio-48e.c index 92c8f944bf64..23413d90e944 100644 --- a/drivers/gpio/gpio-104-dio-48e.c +++ b/drivers/gpio/gpio-104-dio-48e.c @@ -183,46 +183,26 @@ static int dio48e_gpio_get(struct gpio_chip *chip, unsigned offset) return !!(port_state & mask); } +static const size_t ports[] = { 0, 1, 2, 4, 5, 6 }; + static int dio48e_gpio_get_multiple(struct gpio_chip *chip, unsigned long *mask, unsigned long *bits) { struct dio48e_gpio *const dio48egpio = gpiochip_get_data(chip); - size_t i; - static const size_t ports[] = { 0, 1, 2, 4, 5, 6 }; - const unsigned int gpio_reg_size = 8; - unsigned int bits_offset; - size_t word_index; - unsigned int word_offset; - unsigned long word_mask; - const unsigned long port_mask = GENMASK(gpio_reg_size - 1, 0); + unsigned int offset; + unsigned long gpio_mask; + const unsigned int ngpio = ARRAY_SIZE(ports) * 8; + unsigned int port_addr; unsigned long port_state; /* clear bits array to a clean slate */ bitmap_zero(bits, chip->ngpio); - /* get bits are evaluated a gpio port register at a time */ - for (i = 0; i < ARRAY_SIZE(ports); i++) { - /* gpio offset in bits array */ - bits_offset = i * gpio_reg_size; - - /* word index for bits array */ - word_index = BIT_WORD(bits_offset); - - /* gpio offset within current word of bits array */ - word_offset = bits_offset % BITS_PER_LONG; - - /* mask of get bits for current gpio within current word */ - word_mask = mask[word_index] & (port_mask << word_offset); - if (!word_mask) { - /* no get bits in this port so skip to next one */ - continue; - } - - /* read bits from current gpio port */ - port_state = inb(dio48egpio->base + ports[i]); + for_each_set_clump8(offset, gpio_mask, mask, ngpio) { + port_addr = dio48egpio->base + ports[offset / 8]; + port_state = inb(port_addr) & gpio_mask; - /* store acquired bits at respective bits array offset */ - bits[word_index] |= (port_state << word_offset) & word_mask; + bitmap_set_value8(bits, ngpio, port_state, offset); } return 0; @@ -252,37 +232,28 @@ static void dio48e_gpio_set_multiple(struct gpio_chip *chip, unsigned long *mask, unsigned long *bits) { struct dio48e_gpio *const dio48egpio = gpiochip_get_data(chip); - unsigned int i; - const unsigned int gpio_reg_size = 8; - unsigned int port; - unsigned int out_port; + unsigned int offset; + unsigned long gpio_mask; + const unsigned int ngpio = ARRAY_SIZE(ports) * 8; + size_t index; + unsigned int port_addr; unsigned int bitmask; unsigned long flags; - /* set bits are evaluated a gpio register size at a time */ - for (i = 0; i < chip->ngpio; i += gpio_reg_size) { - /* no more set bits in this mask word; skip to the next word */ - if (!mask[BIT_WORD(i)]) { - i = (BIT_WORD(i) + 1) * BITS_PER_LONG - gpio_reg_size; - continue; - } + for_each_set_clump8(offset, gpio_mask, mask, ngpio) { + index = offset / 8; + port_addr = dio48egpio->base + ports[index]; - port = i / gpio_reg_size; - out_port = (port > 2) ? port + 1 : port; - bitmask = mask[BIT_WORD(i)] & bits[BIT_WORD(i)]; + bitmask = bitmap_get_value8(bits, ngpio, offset) & gpio_mask; raw_spin_lock_irqsave(&dio48egpio->lock, flags); /* update output state data and set device gpio register */ - dio48egpio->out_state[port] &= ~mask[BIT_WORD(i)]; - dio48egpio->out_state[port] |= bitmask; - outb(dio48egpio->out_state[port], dio48egpio->base + out_port); + dio48egpio->out_state[index] &= ~gpio_mask; + dio48egpio->out_state[index] |= bitmask; + outb(dio48egpio->out_state[index], port_addr); raw_spin_unlock_irqrestore(&dio48egpio->lock, flags); - - /* prepare for next gpio register set */ - mask[BIT_WORD(i)] >>= gpio_reg_size; - bits[BIT_WORD(i)] >>= gpio_reg_size; } } From patchwork Thu Mar 14 12:30:59 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: 10852715 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 0C01D1390 for ; Thu, 14 Mar 2019 12:30:30 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id E4AB52A3E8 for ; Thu, 14 Mar 2019 12:30:29 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id E24D62A407; Thu, 14 Mar 2019 12:30:29 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-5.2 required=2.0 tests=BAYES_00,DKIM_ADSP_CUSTOM_MED, DKIM_SIGNED,DKIM_VALID,FREEMAIL_FROM,MAILING_LIST_MULTI,RCVD_IN_DNSWL_MED autolearn=ham version=3.3.1 Received: from bombadil.infradead.org (bombadil.infradead.org [198.137.202.133]) (using TLSv1.2 with cipher AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.wl.linuxfoundation.org (Postfix) with ESMTPS id 6E11F2A3F9 for ; Thu, 14 Mar 2019 12:30:28 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20170209; h=Sender: Content-Transfer-Encoding:Content-Type:Cc:List-Subscribe:List-Help:List-Post: List-Archive:List-Unsubscribe:List-Id:MIME-Version:References:In-Reply-To: Message-Id:Date:Subject:To:From:Reply-To:Content-ID:Content-Description: Resent-Date:Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID: List-Owner; bh=mKZJ1IaY7GlXT9kvyDtjHSZohYXBb+bquG+//QQEco4=; b=k6Bm0IRJt8em1G vz5gzK57yI10K0MJtPzxKMEapvfk7zijB6xnE029ZiKgCpiKZf3yQUSaVT8ZJ4WixDou5HvU6zbEj nP1D41ZkKEmvANxiDH3qiVe/i+/GrP+d2x5xJGJHCIkfjhG0vORebf3YQswPiDb8B4jQkr+bM62re gD6LvowM7RS7WBa8hDXM9O6yCq1EBTZK9zZZwKbiYM81R+KeDdFFzG+tGwtGSxFTAYMkTKBa+jLFb i9NuRFp2QoPwndzFk3gupzuhUSltFPpxZiCWUoyeVDAhF7JVw0ii40MvjRx3cOObd63Y6Z9LNBtPo 516hXKcy/8v2efQm7/WQ==; Received: from localhost ([127.0.0.1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.90_1 #2 (Red Hat Linux)) id 1h4PVB-00081I-VV; Thu, 14 Mar 2019 12:30:25 +0000 Received: from mail-pf1-x444.google.com ([2607:f8b0:4864:20::444]) by bombadil.infradead.org with esmtps (Exim 4.90_1 #2 (Red Hat Linux)) id 1h4PUu-0006i3-Nz for linux-arm-kernel@lists.infradead.org; Thu, 14 Mar 2019 12:30:21 +0000 Received: by mail-pf1-x444.google.com with SMTP id n125so3726559pfn.5 for ; Thu, 14 Mar 2019 05:30:08 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=wovyItwhuu6up6N9d5xqiEvzR3TkCWii5hwPk2X/3Vc=; b=AfW758lGDfOT0nmEzqbNvKwVxfumX+W8/udGCjXD6F/kVAt+9HW3qbkUb+4xAQrlHH AYvMwh96/N5Ddez9BM8eWr9IZUijPL2TVPQELBcOvUtSlvloVDco3F5xGxa2QYq0B883 /gu79bAOD15xvxV70t0nRKxz+jDfMF2eQ1vFZEOeNFDJKfeY3gU4AJczX4nm5KhQNA84 AaRUnFYStfFVEE78/q4kBNq8j02L5rSWEEkOLkplz8cZqTCd1dzdaCJgP2F+CRSnWXgU OZ/3xcX8RznL7GB8OqRe47m0nLGrdA+7OeRe1cH0d59wujsho13eR1KMNnBCDp/96DsS Tjmg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=wovyItwhuu6up6N9d5xqiEvzR3TkCWii5hwPk2X/3Vc=; b=byVqjIHrvx5lpLgaXXtVWtPrsKe6CAkrsyRxbpNgE9Jvn4YCcbJWRL9CVnDZ/d7l6x zVXUF1UM8gZryv3PlZJKYip+voYaBNlnsslGq40BzbmSlhhcQN1qkWSx45NBpvTxmR4N KymawD8LEXJO/yqUN/p9g8pZUArI9/9xHAPKtn1f/EMASNZRLRFS4M59UDvzD8lsRabI lww7Qzf2sxxDm1vo20ZaNBcCmLiptNrh4xaLGymk6FxBREanzYwtKIQHosJ5xOqCHez5 i+KG7fj1jl/E1oTB41ptMLdfo8HizUhNEUJWRmKTa0ZBPJwh6fhLW3MaqupdkZZINAR5 VH3g== X-Gm-Message-State: APjAAAUgj5dju+wML9Wm5BvsBiIn8bSfQqydIrMliJ18E0OSnAPaklZ5 JyJaTlOIvemCpzIquTY5kIc= X-Google-Smtp-Source: APXvYqzkBFfEOq7My/mjnNtvbYiVspZBPohjmp4JfJkVKzGcZtulSYEO1Yn4cdZul+eFkTi1Vkunww== X-Received: by 2002:a63:124c:: with SMTP id 12mr29049250pgs.86.1552566607946; Thu, 14 Mar 2019 05:30:07 -0700 (PDT) Received: from localhost.localdomain ([2001:268:c0a4:3974:c70:4af9:86e2:2]) by smtp.gmail.com with ESMTPSA id r86sm25075639pfa.82.2019.03.14.05.30.01 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Thu, 14 Mar 2019 05:30:07 -0700 (PDT) From: William Breathitt Gray To: linus.walleij@linaro.org Subject: [PATCH v10 04/10] gpio: 104-idi-48: Utilize for_each_set_clump8 macro Date: Thu, 14 Mar 2019 21:30:59 +0900 Message-Id: X-Mailer: git-send-email 2.21.0 In-Reply-To: References: MIME-Version: 1.0 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20190314_053009_328957_DAE8D699 X-CRM114-Status: GOOD ( 13.87 ) X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: linux-arch@vger.kernel.org, yamada.masahiro@socionext.com, linux@rasmusvillemoes.dk, linux-kernel@vger.kernel.org, William Breathitt Gray , linux-gpio@vger.kernel.org, bgolaszewski@baylibre.com, akpm@linux-foundation.org, andriy.shevchenko@linux.intel.com, linux-arm-kernel@lists.infradead.org Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+patchwork-linux-arm=patchwork.kernel.org@lists.infradead.org X-Virus-Scanned: ClamAV using ClamSMTP Replace verbose implementation in get_multiple/set_multiple callbacks with for_each_set_clump8 macro to simplify code and improve clarity. Reviewed-by: Linus Walleij Signed-off-by: William Breathitt Gray --- drivers/gpio/gpio-104-idi-48.c | 37 ++++++++-------------------------- 1 file changed, 8 insertions(+), 29 deletions(-) diff --git a/drivers/gpio/gpio-104-idi-48.c b/drivers/gpio/gpio-104-idi-48.c index 88dc6f2449f6..59c571aecf9a 100644 --- a/drivers/gpio/gpio-104-idi-48.c +++ b/drivers/gpio/gpio-104-idi-48.c @@ -93,42 +93,21 @@ static int idi_48_gpio_get_multiple(struct gpio_chip *chip, unsigned long *mask, unsigned long *bits) { struct idi_48_gpio *const idi48gpio = gpiochip_get_data(chip); - size_t i; + unsigned int offset; + unsigned long gpio_mask; static const size_t ports[] = { 0, 1, 2, 4, 5, 6 }; - const unsigned int gpio_reg_size = 8; - unsigned int bits_offset; - size_t word_index; - unsigned int word_offset; - unsigned long word_mask; - const unsigned long port_mask = GENMASK(gpio_reg_size - 1, 0); + const unsigned int ngpio = ARRAY_SIZE(ports) * 8; + unsigned int port_addr; unsigned long port_state; /* clear bits array to a clean slate */ bitmap_zero(bits, chip->ngpio); - /* get bits are evaluated a gpio port register at a time */ - for (i = 0; i < ARRAY_SIZE(ports); i++) { - /* gpio offset in bits array */ - bits_offset = i * gpio_reg_size; + for_each_set_clump8(offset, gpio_mask, mask, ngpio) { + port_addr = idi48gpio->base + ports[offset / 8]; + port_state = inb(port_addr) & gpio_mask; - /* word index for bits array */ - word_index = BIT_WORD(bits_offset); - - /* gpio offset within current word of bits array */ - word_offset = bits_offset % BITS_PER_LONG; - - /* mask of get bits for current gpio within current word */ - word_mask = mask[word_index] & (port_mask << word_offset); - if (!word_mask) { - /* no get bits in this port so skip to next one */ - continue; - } - - /* read bits from current gpio port */ - port_state = inb(idi48gpio->base + ports[i]); - - /* store acquired bits at respective bits array offset */ - bits[word_index] |= (port_state << word_offset) & word_mask; + bitmap_set_value8(bits, ngpio, port_state, offset); } return 0; From patchwork Thu Mar 14 12:31:17 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: 10852717 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 1C5021390 for ; Thu, 14 Mar 2019 12:30:44 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 0061E2A413 for ; Thu, 14 Mar 2019 12:30:44 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id F21382A427; Thu, 14 Mar 2019 12:30:43 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-5.2 required=2.0 tests=BAYES_00,DKIM_ADSP_CUSTOM_MED, DKIM_SIGNED,DKIM_VALID,FREEMAIL_FROM,MAILING_LIST_MULTI,RCVD_IN_DNSWL_MED autolearn=ham version=3.3.1 Received: from bombadil.infradead.org (bombadil.infradead.org [198.137.202.133]) (using TLSv1.2 with cipher AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.wl.linuxfoundation.org (Postfix) with ESMTPS id 4895C2A402 for ; Thu, 14 Mar 2019 12:30:43 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20170209; h=Sender: Content-Transfer-Encoding:Content-Type:Cc:List-Subscribe:List-Help:List-Post: List-Archive:List-Unsubscribe:List-Id:MIME-Version:References:In-Reply-To: Message-Id:Date:Subject:To:From:Reply-To:Content-ID:Content-Description: Resent-Date:Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID: List-Owner; bh=ltMveRREfZQi7O8lmC3CWFTY0DsgtZ26c0A2N3p8JI8=; b=uq3Xx37L5u3tkZ JsgHywAWA8CJ78Bi0cfiX6hpnwz0cFFrPOx3qF6QW+hLHqED18yTkyymQsyAWxeGfvlSZx95SSGqC yPxHDAXI3Z7NKmtJ7uQ3joaagiQYKDScJHEIUEOOp32Y8f+SeZw4jAdgPQV4aGmor93mHJUnqJDq5 9qaqfDm+ZRd9/nDcM2oB4LBqBKaZ/FzFUl9JAdL7fKBLEMtOqLvCuKp7wOBEuqIF1PEwluCP6HhDI tBMxsf736omZRCaJm/751wH1xI2ya7WhkiqyyaejnlSaZWCDIGeTnm47rUiMMWmBkWJsU4yGTpulp xTBLol7OhfUDF7foikkw==; Received: from localhost ([127.0.0.1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.90_1 #2 (Red Hat Linux)) id 1h4PVR-0008Ml-EC; Thu, 14 Mar 2019 12:30:41 +0000 Received: from mail-pf1-x443.google.com ([2607:f8b0:4864:20::443]) by bombadil.infradead.org with esmtps (Exim 4.90_1 #2 (Red Hat Linux)) id 1h4PVC-00084o-7o for linux-arm-kernel@lists.infradead.org; Thu, 14 Mar 2019 12:30:38 +0000 Received: by mail-pf1-x443.google.com with SMTP id i20so3729757pfo.6 for ; Thu, 14 Mar 2019 05:30:26 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=rgWDXyitkPfkOwvJZbjg9H8+KzeLJbUpGMI+NATW6JM=; b=kjsTP5p0+GWOwXOYu5Bi9m2dVvaNyXAgG3YCKpsX9i/ir4zGPJ1XdAha7AiYWTIRQx JVKlbWUuqEZs+gnPWubwBp+pKtnB8cfcs9kUAfKkbFidA1dEErrQJ34CiXhuPVj0WJRI 7G9kA1A8jeRTXtfv5TH8fYyL/ksC9A0jJGm3YT3MsWqtZLpJGqTqyMj5lFyVWI9qFMhP ZwB6XiSmP4TrTRXE4IyWo22m2CFxYV4zT7We4nXWQjlhqvhgMwAkn2/DY4rrWfSOP7MT FPDFJD4aofzhSg4O0s25vCdzcEPON46c+MTAHsEqjtNPNfwFLHe/yR8d5sdwI0nkxyJK 9vhA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=rgWDXyitkPfkOwvJZbjg9H8+KzeLJbUpGMI+NATW6JM=; b=WMVM0sQXujbSR++OP7zBuQ3sKZDzKtThGxlvD5ueeJ1hC+XG5zND7JgjSmXnPC/+tB ngnO4JF3MLE6Z4UdG662dm0vOZ7Kf8fQINqLqAwT/nt6jPGpOvwaBNTpmUPs38PqGNv+ smBh3ijIjTZVuZ+ROYYDnJLWQjnH2FJbxzAYmw0kJbvfcjqDpUyqKxk44uKER1GEgSvo fBNFrT94U7JhgRJUTLlxcBwrOAGpS6oeX2WEojuMHJ0NEQGKlTGwRv5f4lPFGHQWcG4E ziWSJ3+QM0hGTAl9220hpW3MaZqobY/3zl9AKbLh55Bv1a2qpkAwwHMGHng2nP5Ull70 kiyQ== X-Gm-Message-State: APjAAAX9k+FQpB9JJD6Hj863XtY3R+36DuX2FiSh6e/N3PBw8wgbgAKv IlxCvD2CuTxOOjwLGp9kIDU= X-Google-Smtp-Source: APXvYqwUoq89fOMmvUCeAGQzO+rCWADn20XycYNM+pSRJBjADqYx+zJzeLzPcEPNxNXn/DAZX9VskA== X-Received: by 2002:a63:f80f:: with SMTP id n15mr1305759pgh.283.1552566625638; Thu, 14 Mar 2019 05:30:25 -0700 (PDT) Received: from localhost.localdomain ([2001:268:c0a4:3974:c70:4af9:86e2:2]) by smtp.gmail.com with ESMTPSA id m3sm16777366pgp.85.2019.03.14.05.30.19 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Thu, 14 Mar 2019 05:30:25 -0700 (PDT) From: William Breathitt Gray To: linus.walleij@linaro.org Subject: [PATCH v10 05/10] gpio: gpio-mm: Utilize for_each_set_clump8 macro Date: Thu, 14 Mar 2019 21:31:17 +0900 Message-Id: <7c2fefac3369b9444c41764fcda6766959f49692.1552566114.git.vilhelm.gray@gmail.com> X-Mailer: git-send-email 2.21.0 In-Reply-To: References: MIME-Version: 1.0 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20190314_053026_725024_38FC39AE X-CRM114-Status: GOOD ( 14.34 ) X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: linux-arch@vger.kernel.org, yamada.masahiro@socionext.com, linux@rasmusvillemoes.dk, linux-kernel@vger.kernel.org, William Breathitt Gray , linux-gpio@vger.kernel.org, bgolaszewski@baylibre.com, akpm@linux-foundation.org, andriy.shevchenko@linux.intel.com, linux-arm-kernel@lists.infradead.org Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+patchwork-linux-arm=patchwork.kernel.org@lists.infradead.org X-Virus-Scanned: ClamAV using ClamSMTP Replace verbose implementation in get_multiple/set_multiple callbacks with for_each_set_clump8 macro to simplify code and improve clarity. Reviewed-by: Linus Walleij Signed-off-by: William Breathitt Gray --- drivers/gpio/gpio-gpio-mm.c | 73 +++++++++++-------------------------- 1 file changed, 22 insertions(+), 51 deletions(-) diff --git a/drivers/gpio/gpio-gpio-mm.c b/drivers/gpio/gpio-gpio-mm.c index 8c150fd68d9d..4c1037a005ab 100644 --- a/drivers/gpio/gpio-gpio-mm.c +++ b/drivers/gpio/gpio-gpio-mm.c @@ -172,46 +172,26 @@ static int gpiomm_gpio_get(struct gpio_chip *chip, unsigned int offset) return !!(port_state & mask); } +static const size_t ports[] = { 0, 1, 2, 4, 5, 6 }; + static int gpiomm_gpio_get_multiple(struct gpio_chip *chip, unsigned long *mask, unsigned long *bits) { struct gpiomm_gpio *const gpiommgpio = gpiochip_get_data(chip); - size_t i; - static const size_t ports[] = { 0, 1, 2, 4, 5, 6 }; - const unsigned int gpio_reg_size = 8; - unsigned int bits_offset; - size_t word_index; - unsigned int word_offset; - unsigned long word_mask; - const unsigned long port_mask = GENMASK(gpio_reg_size - 1, 0); + unsigned int offset; + unsigned long gpio_mask; + const unsigned int ngpio = ARRAY_SIZE(ports) * 8; + unsigned int port_addr; unsigned long port_state; /* clear bits array to a clean slate */ bitmap_zero(bits, chip->ngpio); - /* get bits are evaluated a gpio port register at a time */ - for (i = 0; i < ARRAY_SIZE(ports); i++) { - /* gpio offset in bits array */ - bits_offset = i * gpio_reg_size; - - /* word index for bits array */ - word_index = BIT_WORD(bits_offset); - - /* gpio offset within current word of bits array */ - word_offset = bits_offset % BITS_PER_LONG; - - /* mask of get bits for current gpio within current word */ - word_mask = mask[word_index] & (port_mask << word_offset); - if (!word_mask) { - /* no get bits in this port so skip to next one */ - continue; - } - - /* read bits from current gpio port */ - port_state = inb(gpiommgpio->base + ports[i]); + for_each_set_clump8(offset, gpio_mask, mask, ngpio) { + port_addr = gpiommgpio->base + ports[offset / 8]; + port_state = inb(port_addr) & gpio_mask; - /* store acquired bits at respective bits array offset */ - bits[word_index] |= (port_state << word_offset) & word_mask; + bitmap_set_value8(bits, ngpio, port_state, offset); } return 0; @@ -242,37 +222,28 @@ static void gpiomm_gpio_set_multiple(struct gpio_chip *chip, unsigned long *mask, unsigned long *bits) { struct gpiomm_gpio *const gpiommgpio = gpiochip_get_data(chip); - unsigned int i; - const unsigned int gpio_reg_size = 8; - unsigned int port; - unsigned int out_port; + unsigned int offset; + unsigned long gpio_mask; + const unsigned int ngpio = ARRAY_SIZE(ports) * 8; + size_t index; + unsigned int port_addr; unsigned int bitmask; unsigned long flags; - /* set bits are evaluated a gpio register size at a time */ - for (i = 0; i < chip->ngpio; i += gpio_reg_size) { - /* no more set bits in this mask word; skip to the next word */ - if (!mask[BIT_WORD(i)]) { - i = (BIT_WORD(i) + 1) * BITS_PER_LONG - gpio_reg_size; - continue; - } + for_each_set_clump8(offset, gpio_mask, mask, ngpio) { + index = offset / 8; + port_addr = gpiommgpio->base + ports[index]; - port = i / gpio_reg_size; - out_port = (port > 2) ? port + 1 : port; - bitmask = mask[BIT_WORD(i)] & bits[BIT_WORD(i)]; + bitmask = bitmap_get_value8(bits, ngpio, offset) & gpio_mask; spin_lock_irqsave(&gpiommgpio->lock, flags); /* update output state data and set device gpio register */ - gpiommgpio->out_state[port] &= ~mask[BIT_WORD(i)]; - gpiommgpio->out_state[port] |= bitmask; - outb(gpiommgpio->out_state[port], gpiommgpio->base + out_port); + gpiommgpio->out_state[index] &= ~gpio_mask; + gpiommgpio->out_state[index] |= bitmask; + outb(gpiommgpio->out_state[index], port_addr); spin_unlock_irqrestore(&gpiommgpio->lock, flags); - - /* prepare for next gpio register set */ - mask[BIT_WORD(i)] >>= gpio_reg_size; - bits[BIT_WORD(i)] >>= gpio_reg_size; } } From patchwork Thu Mar 14 12:31:36 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: 10852719 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id D1D59139A for ; Thu, 14 Mar 2019 12:30:59 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id B856C2A3E6 for ; Thu, 14 Mar 2019 12:30:59 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id B64162A3EB; Thu, 14 Mar 2019 12:30:59 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-5.2 required=2.0 tests=BAYES_00,DKIM_ADSP_CUSTOM_MED, DKIM_SIGNED,DKIM_VALID,FREEMAIL_FROM,MAILING_LIST_MULTI,RCVD_IN_DNSWL_MED autolearn=ham version=3.3.1 Received: from bombadil.infradead.org (bombadil.infradead.org [198.137.202.133]) (using TLSv1.2 with cipher AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.wl.linuxfoundation.org (Postfix) with ESMTPS id 216012A422 for ; Thu, 14 Mar 2019 12:30:58 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20170209; h=Sender: Content-Transfer-Encoding:Content-Type:Cc:List-Subscribe:List-Help:List-Post: List-Archive:List-Unsubscribe:List-Id:MIME-Version:References:In-Reply-To: Message-Id:Date:Subject:To:From:Reply-To:Content-ID:Content-Description: Resent-Date:Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID: List-Owner; bh=aFOyVg51VmvjMddDtCmCNUdEzDTDp6zBLLKchh5tJDo=; b=DlQpw5Or/mGCxR o+hBv1lOWDtNnDZmP+34bRHFya1hkU9epyFZCvWrg2pzedPo3Y6JwajJAzZ4Bw8zGcRvboWsofyqn oghNd8+6PS8gUDCzJtcKm1ngyfs+ZKsfKWjfRgtZoaXhI3bYdByG2OLzP9qOhR1JHZVMzceydsXtI 0xJMRMYK7qMHb48SCrUvUCg3pQSGjxx394QeG97HGP4UCfZ6RekhDWs/u5GsWBtA6LAKZ6nGE7npH ZKb6gT0s3NlvsgppDSpEIFeCFEstEpgd0rkMTeMCr6d3WuDcj/On5Ggminj4tFC3cxe0cq0FiRFqk z+GIevSagy2gjhYnZLQQ==; Received: from localhost ([127.0.0.1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.90_1 #2 (Red Hat Linux)) id 1h4PVg-0000C0-Vn; Thu, 14 Mar 2019 12:30:56 +0000 Received: from mail-pg1-x541.google.com ([2607:f8b0:4864:20::541]) by bombadil.infradead.org with esmtps (Exim 4.90_1 #2 (Red Hat Linux)) id 1h4PVZ-00006K-EV for linux-arm-kernel@lists.infradead.org; Thu, 14 Mar 2019 12:30:54 +0000 Received: by mail-pg1-x541.google.com with SMTP id v12so3897610pgq.1 for ; Thu, 14 Mar 2019 05:30:49 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=JhQ28KZcd91XNKjTCGWYQ1G7G3aiOZwynfHwUrGcvPU=; b=Z20N14jduB0i02AsdL05vaQOwSPD+QSSFBQ9T3qCz7Ejh1x6KtAcRmZsza9tvq0Kvp rnTtirBabetLCzTsvGjVqqAYWseTnUV6sEXCop7B3gNT/gbrtuD4/REnBVodpgiZM8J7 xIZikGUoVuCfF25IgGozDjroghBBww65JbCQg+HceLpELDHYUsUK1CQKLtv8+Br1j44S Cd/Qo41WJGs3HdFXsBVOQ/DyZetBklE+WBhcQLyHCQk7V6jvk6VmwNqbnotxdRRhs+2E S0fEuBKZpPzVNiaqdHVgYX0D77aU67Kt9Ei4W0a3CuVTTqGybc+gBwCrNM1vxR2GdMo7 IyIg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=JhQ28KZcd91XNKjTCGWYQ1G7G3aiOZwynfHwUrGcvPU=; b=DgwSuzXsfHwzCm4Grek/HE7Bvnd5YvQEizEBVja9wbnH3COQ8yEhF3T/5P/Kp3U+h2 HeBsIP4iM+gF0sGWU8MOmRMQJJuguC8D5664KlzMtaT3C5zGchCEoRLSsMIDJhakQle8 NdNngsqL+FezVCQ4ed1eESYxSdP4bMJ4Wb25x/wiLa4g6x5rI01AZBCUG8P6s77eDloG jJL+xx883z+ypwxLRx2kuNmwICIpp4rUezVLbYy8c/98p2tuEl9AS0HCxbjghpZY14h7 Q4jHYQqlUMbc3FnjAT4wPaR/HopKlz9Mp0YC8chFcJFPjR+Pfhx6OJvooDOaEzK4+lV2 OX3A== X-Gm-Message-State: APjAAAVlnBZCyFJhSXkcWWqD2Aih07Ti5HzWN5h9tr/RP3sLfjvYmAkG P9ZivYCnwGmEWMgLjAB2BkQ= X-Google-Smtp-Source: APXvYqxsAcdIohIYrCAAKONAfVTAoioViiXPUHVAoW37FVmu9RFKMcerKJbEXnMXhqdFWy+g8Y8fXw== X-Received: by 2002:aa7:8a59:: with SMTP id n25mr14606746pfa.251.1552566648786; Thu, 14 Mar 2019 05:30:48 -0700 (PDT) Received: from localhost.localdomain ([2001:268:c0a4:3974:c70:4af9:86e2:2]) by smtp.gmail.com with ESMTPSA id r82sm24007368pfa.161.2019.03.14.05.30.44 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Thu, 14 Mar 2019 05:30:48 -0700 (PDT) From: William Breathitt Gray To: linus.walleij@linaro.org Subject: [PATCH v10 06/10] gpio: ws16c48: Utilize for_each_set_clump8 macro Date: Thu, 14 Mar 2019 21:31:36 +0900 Message-Id: <2be67e8cd255884af67e053e21577cdf4c7ab83a.1552566114.git.vilhelm.gray@gmail.com> X-Mailer: git-send-email 2.21.0 In-Reply-To: References: MIME-Version: 1.0 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20190314_053049_785267_51B1EC8D X-CRM114-Status: GOOD ( 14.61 ) X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: linux-arch@vger.kernel.org, yamada.masahiro@socionext.com, linux@rasmusvillemoes.dk, linux-kernel@vger.kernel.org, William Breathitt Gray , linux-gpio@vger.kernel.org, bgolaszewski@baylibre.com, akpm@linux-foundation.org, andriy.shevchenko@linux.intel.com, linux-arm-kernel@lists.infradead.org Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+patchwork-linux-arm=patchwork.kernel.org@lists.infradead.org X-Virus-Scanned: ClamAV using ClamSMTP Replace verbose implementation in get_multiple/set_multiple callbacks with for_each_set_clump8 macro to simplify code and improve clarity. Reviewed-by: Linus Walleij Signed-off-by: William Breathitt Gray --- drivers/gpio/gpio-ws16c48.c | 72 +++++++++++-------------------------- 1 file changed, 20 insertions(+), 52 deletions(-) diff --git a/drivers/gpio/gpio-ws16c48.c b/drivers/gpio/gpio-ws16c48.c index 5cf3697bfb15..1d071a3d3e81 100644 --- a/drivers/gpio/gpio-ws16c48.c +++ b/drivers/gpio/gpio-ws16c48.c @@ -134,42 +134,19 @@ static int ws16c48_gpio_get_multiple(struct gpio_chip *chip, unsigned long *mask, unsigned long *bits) { struct ws16c48_gpio *const ws16c48gpio = gpiochip_get_data(chip); - const unsigned int gpio_reg_size = 8; - size_t i; - const size_t num_ports = chip->ngpio / gpio_reg_size; - unsigned int bits_offset; - size_t word_index; - unsigned int word_offset; - unsigned long word_mask; - const unsigned long port_mask = GENMASK(gpio_reg_size - 1, 0); + unsigned int offset; + unsigned long gpio_mask; + unsigned int port_addr; unsigned long port_state; /* clear bits array to a clean slate */ bitmap_zero(bits, chip->ngpio); - /* get bits are evaluated a gpio port register at a time */ - for (i = 0; i < num_ports; i++) { - /* gpio offset in bits array */ - bits_offset = i * gpio_reg_size; + for_each_set_clump8(offset, gpio_mask, mask, chip->ngpio) { + port_addr = ws16c48gpio->base + offset / 8; + port_state = inb(port_addr) & gpio_mask; - /* word index for bits array */ - word_index = BIT_WORD(bits_offset); - - /* gpio offset within current word of bits array */ - word_offset = bits_offset % BITS_PER_LONG; - - /* mask of get bits for current gpio within current word */ - word_mask = mask[word_index] & (port_mask << word_offset); - if (!word_mask) { - /* no get bits in this port so skip to next one */ - continue; - } - - /* read bits from current gpio port */ - port_state = inb(ws16c48gpio->base + i); - - /* store acquired bits at respective bits array offset */ - bits[word_index] |= (port_state << word_offset) & word_mask; + bitmap_set_value8(bits, chip->ngpio, port_state, offset); } return 0; @@ -203,39 +180,30 @@ static void ws16c48_gpio_set_multiple(struct gpio_chip *chip, unsigned long *mask, unsigned long *bits) { struct ws16c48_gpio *const ws16c48gpio = gpiochip_get_data(chip); - unsigned int i; - const unsigned int gpio_reg_size = 8; - unsigned int port; - unsigned int iomask; + unsigned int offset; + unsigned long gpio_mask; + size_t index; + unsigned int port_addr; unsigned int bitmask; unsigned long flags; - /* set bits are evaluated a gpio register size at a time */ - for (i = 0; i < chip->ngpio; i += gpio_reg_size) { - /* no more set bits in this mask word; skip to the next word */ - if (!mask[BIT_WORD(i)]) { - i = (BIT_WORD(i) + 1) * BITS_PER_LONG - gpio_reg_size; - continue; - } - - port = i / gpio_reg_size; + for_each_set_clump8(offset, gpio_mask, mask, chip->ngpio) { + index = offset / 8; + port_addr = ws16c48gpio->base + index; /* mask out GPIO configured for input */ - iomask = mask[BIT_WORD(i)] & ~ws16c48gpio->io_state[port]; - bitmask = iomask & bits[BIT_WORD(i)]; + gpio_mask &= ~ws16c48gpio->io_state[index]; + bitmask = bitmap_get_value8(bits, chip->ngpio, offset) & + gpio_mask; raw_spin_lock_irqsave(&ws16c48gpio->lock, flags); /* update output state data and set device gpio register */ - ws16c48gpio->out_state[port] &= ~iomask; - ws16c48gpio->out_state[port] |= bitmask; - outb(ws16c48gpio->out_state[port], ws16c48gpio->base + port); + ws16c48gpio->out_state[index] &= ~gpio_mask; + ws16c48gpio->out_state[index] |= bitmask; + outb(ws16c48gpio->out_state[index], port_addr); raw_spin_unlock_irqrestore(&ws16c48gpio->lock, flags); - - /* prepare for next gpio register set */ - mask[BIT_WORD(i)] >>= gpio_reg_size; - bits[BIT_WORD(i)] >>= gpio_reg_size; } } From patchwork Thu Mar 14 12:31:59 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: 10852721 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 442711390 for ; Thu, 14 Mar 2019 12:31:20 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 22E292A426 for ; Thu, 14 Mar 2019 12:31:20 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 202FF2A3F4; Thu, 14 Mar 2019 12:31:20 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-5.2 required=2.0 tests=BAYES_00,DKIM_ADSP_CUSTOM_MED, DKIM_SIGNED,DKIM_VALID,FREEMAIL_FROM,MAILING_LIST_MULTI,RCVD_IN_DNSWL_MED autolearn=ham version=3.3.1 Received: from bombadil.infradead.org (bombadil.infradead.org [198.137.202.133]) (using TLSv1.2 with cipher AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.wl.linuxfoundation.org (Postfix) with ESMTPS id 7D17E2A429 for ; Thu, 14 Mar 2019 12:31:19 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20170209; h=Sender: Content-Transfer-Encoding:Content-Type:Cc:List-Subscribe:List-Help:List-Post: List-Archive:List-Unsubscribe:List-Id:MIME-Version:References:In-Reply-To: Message-Id:Date:Subject:To:From:Reply-To:Content-ID:Content-Description: Resent-Date:Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID: List-Owner; bh=FoeQ32wgGtXsTfxq5BtLa8uxa+0QAJgtirYiMIlzuBU=; b=ufKnDXwMP9rtXz VA1O+5EAVbMiMpG8ifhKuWXsYtVHlOaWBLh7zgMcyIoGGKYJ9NGyNq5OrCO91x4ChfLz3MTHHakYZ ZKCdL6I9e7mcTIfAww9AxgfbpizrpJsauFYZPg6GgoBm8mBbsGSpr8XIn7ZjRDdrGE1BqEGSOM5zs Ey0u9BeTolgaOB93Xg27TkUIf2GjYPj8+ZNVzxibBnI5kdO2bvyQnMPmrp0KjJRWOco0CopdcpUly Uk6j1gBfw/kIhh2nqvFTMf0BGdvNG+H6/IeHM9djDSNMW+2x1VVqt41RpvAKpFpuavzthes2C/Ke7 /MJUKLWz6Pf+/59NYZpQ==; Received: from localhost ([127.0.0.1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.90_1 #2 (Red Hat Linux)) id 1h4PW1-0000h1-Oh; Thu, 14 Mar 2019 12:31:17 +0000 Received: from mail-pg1-x542.google.com ([2607:f8b0:4864:20::542]) by bombadil.infradead.org with esmtps (Exim 4.90_1 #2 (Red Hat Linux)) id 1h4PVs-0000Rc-OW for linux-arm-kernel@lists.infradead.org; Thu, 14 Mar 2019 12:31:15 +0000 Received: by mail-pg1-x542.google.com with SMTP id q206so3881833pgq.4 for ; Thu, 14 Mar 2019 05:31:08 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=LbAhFB9V6BisOLUTsbpvSet6qgSjh9MdQ4kQbff2Dwk=; b=uxtIOha4Fnzs6SOsQD1Ql1xjv2GH9TBwMM9l+tWjlowLccn1fclPM0CyZZ5DH0DuVB R6vmze9LQ1dGE4KQMDY0ImtXHTaaxr0ud9fRMt6KqIqFGpoVYnMxlzUZctyyZV8QaDCn dG/R4BMhzzzm2+9Gx5+Slm5rMoN1sefu+n3ldcfh18wSWjk6l2jKuu2KmO/iJTsDryrj hEzbz0BfTqFg9YllPoi/3WFy0mRLwK0exHlef0tGg5XUoRMQocvzy5m0ZvoRGyCrQZ6H 6kLdM9vnKOv1gM2T8W3SoB453h5Mc1HlR0W++Ywmbxdw6tUNtSBXUZ/pPOZCSk9QH5lc AWwQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=LbAhFB9V6BisOLUTsbpvSet6qgSjh9MdQ4kQbff2Dwk=; b=LfCSfNvJRwGzfTaHXMzAqhbGgSZ+wh1Wrrus4H7s/PtLB+PpU5eT1B7z6lMFz3j25i j99m4LiGs34NXssjmNT+iwHCcaory4xThhxV/HtaN+AqXzCKFGiuJ/QX0LqjqNcNCoE0 vtmWoDpVvuqUTQ+GgURCXeMwGXTUovV0HA65lLSx1IloBqQ6Rxoro4u6Hvx0TbNEKzFl s60F9xFoJEppkeWbqU4L1IxieaiCPVDLpLhVL3ZlJlOAwohp8yrs1aspOfnsWInslcG+ Zzyo7JFMCHc9x2OHRpTXUWoIHPL0RyZzeDAPO0fWMeCoZbyHi0rzbj0k9/ucrmViZRXe 2fUg== X-Gm-Message-State: APjAAAVmD5m7s79YA5udmndpXc25gOZ68O3UpoupkAo9i1WsZkBxZUvR f+f8yvp8m6FazwUL2EsEku0= X-Google-Smtp-Source: APXvYqz80anp5Shjlxi98RKXCsygh6QDmcxgW9odRHJF60PX7qkRmL9EHK0gKWz8dcsTEDpJ9k3MoA== X-Received: by 2002:a62:445a:: with SMTP id r87mr48344992pfa.13.1552566668171; Thu, 14 Mar 2019 05:31:08 -0700 (PDT) Received: from localhost.localdomain ([2001:268:c0a4:3974:c70:4af9:86e2:2]) by smtp.gmail.com with ESMTPSA id f3sm21493367pfn.100.2019.03.14.05.31.01 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Thu, 14 Mar 2019 05:31:07 -0700 (PDT) From: William Breathitt Gray To: linus.walleij@linaro.org Subject: [PATCH v10 07/10] gpio: pci-idio-16: Utilize for_each_set_clump8 macro Date: Thu, 14 Mar 2019 21:31:59 +0900 Message-Id: <123abfe91b09731c84d078bf8f4c218bfd5d7284.1552566114.git.vilhelm.gray@gmail.com> X-Mailer: git-send-email 2.21.0 In-Reply-To: References: MIME-Version: 1.0 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20190314_053109_184022_6C1FF92D X-CRM114-Status: GOOD ( 14.94 ) X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: linux-arch@vger.kernel.org, yamada.masahiro@socionext.com, linux@rasmusvillemoes.dk, linux-kernel@vger.kernel.org, William Breathitt Gray , linux-gpio@vger.kernel.org, bgolaszewski@baylibre.com, akpm@linux-foundation.org, andriy.shevchenko@linux.intel.com, linux-arm-kernel@lists.infradead.org Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+patchwork-linux-arm=patchwork.kernel.org@lists.infradead.org X-Virus-Scanned: ClamAV using ClamSMTP Replace verbose implementation in get_multiple/set_multiple callbacks with for_each_set_clump8 macro to simplify code and improve clarity. Reviewed-by: Linus Walleij Signed-off-by: William Breathitt Gray --- drivers/gpio/gpio-pci-idio-16.c | 75 ++++++++++++--------------------- 1 file changed, 28 insertions(+), 47 deletions(-) diff --git a/drivers/gpio/gpio-pci-idio-16.c b/drivers/gpio/gpio-pci-idio-16.c index 6b7349783223..b0ed6bb68296 100644 --- a/drivers/gpio/gpio-pci-idio-16.c +++ b/drivers/gpio/gpio-pci-idio-16.c @@ -108,45 +108,24 @@ static int idio_16_gpio_get_multiple(struct gpio_chip *chip, unsigned long *mask, unsigned long *bits) { struct idio_16_gpio *const idio16gpio = gpiochip_get_data(chip); - size_t i; - const unsigned int gpio_reg_size = 8; - unsigned int bits_offset; - size_t word_index; - unsigned int word_offset; - unsigned long word_mask; - const unsigned long port_mask = GENMASK(gpio_reg_size - 1, 0); - unsigned long port_state; + unsigned int offset; + unsigned long gpio_mask; void __iomem *ports[] = { &idio16gpio->reg->out0_7, &idio16gpio->reg->out8_15, &idio16gpio->reg->in0_7, &idio16gpio->reg->in8_15, }; + const unsigned int ngpio = ARRAY_SIZE(ports) * 8; + void __iomem *port_addr; + unsigned long port_state; /* clear bits array to a clean slate */ bitmap_zero(bits, chip->ngpio); - /* get bits are evaluated a gpio port register at a time */ - for (i = 0; i < ARRAY_SIZE(ports); i++) { - /* gpio offset in bits array */ - bits_offset = i * gpio_reg_size; - - /* word index for bits array */ - word_index = BIT_WORD(bits_offset); - - /* gpio offset within current word of bits array */ - word_offset = bits_offset % BITS_PER_LONG; + for_each_set_clump8(offset, gpio_mask, mask, ngpio) { + port_addr = ports[offset / 8]; + port_state = ioread8(port_addr) & gpio_mask; - /* mask of get bits for current gpio within current word */ - word_mask = mask[word_index] & (port_mask << word_offset); - if (!word_mask) { - /* no get bits in this port so skip to next one */ - continue; - } - - /* read bits from current gpio port */ - port_state = ioread8(ports[i]); - - /* store acquired bits at respective bits array offset */ - bits[word_index] |= (port_state << word_offset) & word_mask; + bitmap_set_value8(bits, ngpio, port_state, offset); } return 0; @@ -186,30 +165,32 @@ static void idio_16_gpio_set_multiple(struct gpio_chip *chip, unsigned long *mask, unsigned long *bits) { struct idio_16_gpio *const idio16gpio = gpiochip_get_data(chip); + unsigned int offset; + unsigned long gpio_mask; + void __iomem *ports[] = { + &idio16gpio->reg->out0_7, &idio16gpio->reg->out8_15, + }; + const unsigned int ngpio = ARRAY_SIZE(ports) * 8; + size_t index; + void __iomem *port_addr; + unsigned int bitmask; unsigned long flags; unsigned int out_state; - raw_spin_lock_irqsave(&idio16gpio->lock, flags); + for_each_set_clump8(offset, gpio_mask, mask, ngpio) { + index = offset / 8; + port_addr = ports[index]; - /* process output lines 0-7 */ - if (*mask & 0xFF) { - out_state = ioread8(&idio16gpio->reg->out0_7) & ~*mask; - out_state |= *mask & *bits; - iowrite8(out_state, &idio16gpio->reg->out0_7); - } + bitmask = bitmap_get_value8(bits, ngpio, offset) & gpio_mask; + + raw_spin_lock_irqsave(&idio16gpio->lock, flags); - /* shift to next output line word */ - *mask >>= 8; + out_state = ioread8(port_addr) & ~gpio_mask; + out_state |= bitmask; + iowrite8(out_state, port_addr); - /* process output lines 8-15 */ - if (*mask & 0xFF) { - *bits >>= 8; - out_state = ioread8(&idio16gpio->reg->out8_15) & ~*mask; - out_state |= *mask & *bits; - iowrite8(out_state, &idio16gpio->reg->out8_15); + raw_spin_unlock_irqrestore(&idio16gpio->lock, flags); } - - raw_spin_unlock_irqrestore(&idio16gpio->lock, flags); } static void idio_16_irq_ack(struct irq_data *data) From patchwork Thu Mar 14 12:32:18 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: 10852723 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 341D01390 for ; Thu, 14 Mar 2019 12:31:38 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 168BE2A3EF for ; Thu, 14 Mar 2019 12:31:38 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 147A32A423; Thu, 14 Mar 2019 12:31:38 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-5.2 required=2.0 tests=BAYES_00,DKIM_ADSP_CUSTOM_MED, DKIM_SIGNED,DKIM_VALID,FREEMAIL_FROM,MAILING_LIST_MULTI,RCVD_IN_DNSWL_MED autolearn=ham version=3.3.1 Received: from bombadil.infradead.org (bombadil.infradead.org [198.137.202.133]) (using TLSv1.2 with cipher AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.wl.linuxfoundation.org (Postfix) with ESMTPS id 715DF2A3EF for ; Thu, 14 Mar 2019 12:31:37 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20170209; h=Sender: Content-Transfer-Encoding:Content-Type:Cc:List-Subscribe:List-Help:List-Post: List-Archive:List-Unsubscribe:List-Id:MIME-Version:References:In-Reply-To: Message-Id:Date:Subject:To:From:Reply-To:Content-ID:Content-Description: Resent-Date:Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID: List-Owner; bh=q84phXcAp+vIZjtnn7AlnlI5I9dK1+bwdUcWYAP/t20=; b=fCpzarVgxcsG3O TV+YVoexRWhgqzJe28ST2EaUqGkb0tVCyrBgrhflAwCQKFDQxb1X8EjA4MJo2jRFwnwEDL6JjtJ28 ciQ0+foyNS15N6POdgkQOP/tD1y3s2lKsZMkndNv3YRlJANfcrUsZgoGXL2YgCzKcmCtFRHkCLUgd 2W80IYX91GfdhcYsTJDaamB6c4AZSSMFSuCKGx7dTQuS0lqCUTiK9+Ddw7PjWMdK9QI0jH8OamzYu pn1Y0YoGP++R2uuojNHriWk23AThhjVuEJXmK8FIZuAc6LLIzXNsUG/2I4CUO+ivTxr7El91E0lA8 /KxllZA10ArS2ANTTsHg==; Received: from localhost ([127.0.0.1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.90_1 #2 (Red Hat Linux)) id 1h4PWK-00010f-08; Thu, 14 Mar 2019 12:31:36 +0000 Received: from mail-pg1-x542.google.com ([2607:f8b0:4864:20::542]) by bombadil.infradead.org with esmtps (Exim 4.90_1 #2 (Red Hat Linux)) id 1h4PWB-0000wB-UM for linux-arm-kernel@lists.infradead.org; Thu, 14 Mar 2019 12:31:32 +0000 Received: by mail-pg1-x542.google.com with SMTP id h34so3857029pgh.11 for ; Thu, 14 Mar 2019 05:31:27 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=lo/y4LVrDbirngV8ZQJtGQjH8jQRyE53ymUz3wq08xM=; b=oM5iblP78OzyxCZATeQUq8xvUmXDLBVDBq0QRqiczBqpBE+xAD5vsAAm/44LI6vmms zH5YDEtShHMZ6ay/I7OYWnDxv+VgooXKRKGflmXOsUT6GaS5WDIMv2TTPfz/XgX7p9sT i+Ux5ogxcRk50uAwIHeB1b95vZV/If9lN+lp3gBp3/VMqL5m0V+v7dokyikodAtdYuBn JANhIDTacRjx/tbM3kiGJNun2W5/TEiFygabN97L9PsMLfUNg3cuckP5el3damW3jC7u IDP5XmgE0w4dEIlbk0yNGkHQaXbisghzbrS/kD0JKNZc/snnCWaWvcCrObUE40VeVB0C RgaQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=lo/y4LVrDbirngV8ZQJtGQjH8jQRyE53ymUz3wq08xM=; b=KTUAPCr43E8b3Ho3V9Qh98tJuyNQHBGzPOLVtn01WiFU59isLid0/S6Ex8AgSfn6cr jQETpCi744yxwwhwEo/oRkR+3rF1AbSh0xy4I0PXDcZcnqZPLGorzcAXzLwIxyThRRc9 thgR1GHA6FSiGHl4QMYA1RxzZTxJOGhT4BAzU8Ahbc+PFLWWFIS5qkzSIbdB1Ehl0Yir 69swLL71j4Foz0YAKPgYa5IhssYD8IiWU7BAWSkKviZyze8GkOkw0oi8SBjVCF7Lsfvf Y3y/OwSLXdC8BjSM6HS83qwu3c3DEZnTn6yZIxBapvK0jRrAmGjbqjV2xpGVa7JcU4G9 zYAg== X-Gm-Message-State: APjAAAVEeNldcmJ85WnNVbJ7e9b3nG1d6VCLqoSh42M3TCSlTAaLVEa1 D6Nd2dDrUEYvPvjMV6rbbWiw+7Te X-Google-Smtp-Source: APXvYqwNExg9QOEUjzZQv18lqt+hQhxSdzQwEb9iNTdtnK45BdM7jM3WS+o1v32NXdXVlfaW6yEYug== X-Received: by 2002:aa7:84d8:: with SMTP id x24mr282407pfn.20.1552566687359; Thu, 14 Mar 2019 05:31:27 -0700 (PDT) Received: from localhost.localdomain ([2001:268:c0a4:3974:c70:4af9:86e2:2]) by smtp.gmail.com with ESMTPSA id z7sm21920616pfn.177.2019.03.14.05.31.21 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Thu, 14 Mar 2019 05:31:26 -0700 (PDT) From: William Breathitt Gray To: linus.walleij@linaro.org Subject: [PATCH v10 08/10] gpio: pcie-idio-24: Utilize for_each_set_clump8 macro Date: Thu, 14 Mar 2019 21:32:18 +0900 Message-Id: X-Mailer: git-send-email 2.21.0 In-Reply-To: References: MIME-Version: 1.0 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20190314_053128_110199_FA2A2025 X-CRM114-Status: GOOD ( 16.64 ) X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: linux-arch@vger.kernel.org, yamada.masahiro@socionext.com, linux@rasmusvillemoes.dk, linux-kernel@vger.kernel.org, William Breathitt Gray , linux-gpio@vger.kernel.org, bgolaszewski@baylibre.com, akpm@linux-foundation.org, andriy.shevchenko@linux.intel.com, linux-arm-kernel@lists.infradead.org Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+patchwork-linux-arm=patchwork.kernel.org@lists.infradead.org X-Virus-Scanned: ClamAV using ClamSMTP Replace verbose implementation in get_multiple/set_multiple callbacks with for_each_set_clump8 macro to simplify code and improve clarity. Reviewed-by: Linus Walleij Signed-off-by: William Breathitt Gray --- drivers/gpio/gpio-pcie-idio-24.c | 111 ++++++++++++------------------- 1 file changed, 42 insertions(+), 69 deletions(-) diff --git a/drivers/gpio/gpio-pcie-idio-24.c b/drivers/gpio/gpio-pcie-idio-24.c index 52f1647a46fd..2ceff1f5d8fd 100644 --- a/drivers/gpio/gpio-pcie-idio-24.c +++ b/drivers/gpio/gpio-pcie-idio-24.c @@ -198,52 +198,35 @@ static int idio_24_gpio_get_multiple(struct gpio_chip *chip, unsigned long *mask, unsigned long *bits) { struct idio_24_gpio *const idio24gpio = gpiochip_get_data(chip); - size_t i; - const unsigned int gpio_reg_size = 8; - unsigned int bits_offset; - size_t word_index; - unsigned int word_offset; - unsigned long word_mask; - const unsigned long port_mask = GENMASK(gpio_reg_size - 1, 0); - unsigned long port_state; + unsigned int offset; + unsigned long gpio_mask; void __iomem *ports[] = { &idio24gpio->reg->out0_7, &idio24gpio->reg->out8_15, &idio24gpio->reg->out16_23, &idio24gpio->reg->in0_7, &idio24gpio->reg->in8_15, &idio24gpio->reg->in16_23, }; + const unsigned int ngpio = ARRAY_SIZE(ports) * 8; + size_t index; + unsigned long port_state; const unsigned long out_mode_mask = BIT(1); /* clear bits array to a clean slate */ bitmap_zero(bits, chip->ngpio); - /* get bits are evaluated a gpio port register at a time */ - for (i = 0; i < ARRAY_SIZE(ports) + 1; i++) { - /* gpio offset in bits array */ - bits_offset = i * gpio_reg_size; - - /* word index for bits array */ - word_index = BIT_WORD(bits_offset); - - /* gpio offset within current word of bits array */ - word_offset = bits_offset % BITS_PER_LONG; - - /* mask of get bits for current gpio within current word */ - word_mask = mask[word_index] & (port_mask << word_offset); - if (!word_mask) { - /* no get bits in this port so skip to next one */ - continue; - } + for_each_set_clump8(offset, gpio_mask, mask, ngpio) { + index = offset / 8; /* read bits from current gpio port (port 6 is TTL GPIO) */ - if (i < 6) - port_state = ioread8(ports[i]); + if (index < 6) + port_state = ioread8(ports[index]); else if (ioread8(&idio24gpio->reg->ctl) & out_mode_mask) port_state = ioread8(&idio24gpio->reg->ttl_out0_7); else port_state = ioread8(&idio24gpio->reg->ttl_in0_7); - /* store acquired bits at respective bits array offset */ - bits[word_index] |= (port_state << word_offset) & word_mask; + port_state &= gpio_mask; + + bitmap_set_value8(bits, ngpio, port_state, offset); } return 0; @@ -294,59 +277,49 @@ static void idio_24_gpio_set_multiple(struct gpio_chip *chip, unsigned long *mask, unsigned long *bits) { struct idio_24_gpio *const idio24gpio = gpiochip_get_data(chip); - size_t i; - unsigned long bits_offset; + unsigned int offset; unsigned long gpio_mask; - const unsigned int gpio_reg_size = 8; - const unsigned long port_mask = GENMASK(gpio_reg_size, 0); - unsigned long flags; - unsigned int out_state; void __iomem *ports[] = { &idio24gpio->reg->out0_7, &idio24gpio->reg->out8_15, &idio24gpio->reg->out16_23 }; + const unsigned int ngpio = ARRAY_SIZE(ports) * 8; + size_t index; + unsigned int bitmask; + unsigned long flags; + unsigned int out_state; const unsigned long out_mode_mask = BIT(1); - const unsigned int ttl_offset = 48; - const size_t ttl_i = BIT_WORD(ttl_offset); - const unsigned int word_offset = ttl_offset % BITS_PER_LONG; - const unsigned long ttl_mask = (mask[ttl_i] >> word_offset) & port_mask; - const unsigned long ttl_bits = (bits[ttl_i] >> word_offset) & ttl_mask; - - /* set bits are processed a gpio port register at a time */ - for (i = 0; i < ARRAY_SIZE(ports); i++) { - /* gpio offset in bits array */ - bits_offset = i * gpio_reg_size; - - /* check if any set bits for current port */ - gpio_mask = (*mask >> bits_offset) & port_mask; - if (!gpio_mask) { - /* no set bits for this port so move on to next port */ - continue; - } - raw_spin_lock_irqsave(&idio24gpio->lock, flags); + for_each_set_clump8(offset, gpio_mask, mask, ngpio) { + index = offset / 8; - /* process output lines */ - out_state = ioread8(ports[i]) & ~gpio_mask; - out_state |= (*bits >> bits_offset) & gpio_mask; - iowrite8(out_state, ports[i]); + bitmask = bitmap_get_value8(bits, ngpio, offset) & gpio_mask; - raw_spin_unlock_irqrestore(&idio24gpio->lock, flags); - } + raw_spin_lock_irqsave(&idio24gpio->lock, flags); - /* check if setting TTL lines and if they are in output mode */ - if (!ttl_mask || !(ioread8(&idio24gpio->reg->ctl) & out_mode_mask)) - return; + /* read bits from current gpio port (port 6 is TTL GPIO) */ + if (index < 6) { + out_state = ioread8(ports[index]); + } else if (ioread8(&idio24gpio->reg->ctl) & out_mode_mask) { + out_state = ioread8(&idio24gpio->reg->ttl_out0_7); + } else { + /* skip TTL GPIO if set for input */ + raw_spin_unlock_irqrestore(&idio24gpio->lock, flags); + continue; + } - /* handle TTL output */ - raw_spin_lock_irqsave(&idio24gpio->lock, flags); + /* set requested bit states */ + out_state &= ~gpio_mask; + out_state |= bitmask; - /* process output lines */ - out_state = ioread8(&idio24gpio->reg->ttl_out0_7) & ~ttl_mask; - out_state |= ttl_bits; - iowrite8(out_state, &idio24gpio->reg->ttl_out0_7); + /* write bits for current gpio port (port 6 is TTL GPIO) */ + if (index < 6) + iowrite8(out_state, ports[index]); + else + iowrite8(out_state, &idio24gpio->reg->ttl_out0_7); - raw_spin_unlock_irqrestore(&idio24gpio->lock, flags); + raw_spin_unlock_irqrestore(&idio24gpio->lock, flags); + } } static void idio_24_irq_ack(struct irq_data *data) From patchwork Thu Mar 14 12:32:37 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: 10852725 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id A5170139A for ; Thu, 14 Mar 2019 12:31:53 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 8A9CC2A3E6 for ; Thu, 14 Mar 2019 12:31:53 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 888B42A3FB; Thu, 14 Mar 2019 12:31:53 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-5.2 required=2.0 tests=BAYES_00,DKIM_ADSP_CUSTOM_MED, DKIM_SIGNED,DKIM_VALID,FREEMAIL_FROM,MAILING_LIST_MULTI,RCVD_IN_DNSWL_MED autolearn=ham version=3.3.1 Received: from bombadil.infradead.org (bombadil.infradead.org [198.137.202.133]) (using TLSv1.2 with cipher AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.wl.linuxfoundation.org (Postfix) with ESMTPS id 251722A411 for ; Thu, 14 Mar 2019 12:31:53 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20170209; h=Sender: Content-Transfer-Encoding:Content-Type:Cc:List-Subscribe:List-Help:List-Post: List-Archive:List-Unsubscribe:List-Id:MIME-Version:References:In-Reply-To: Message-Id:Date:Subject:To:From:Reply-To:Content-ID:Content-Description: Resent-Date:Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID: List-Owner; bh=gZ3NYMrQ1q/us7gBx3qTXKTVVtPVjOQLX1dn8tMYBNg=; b=PMmQPUP4jD0oPC RAz7MLCecmwjpC+/UDLsF190MDXJsPPFayhBhOkotoTlDLIq5utwPg2jgC/ZcBAwfnpTYcHu3LGuM Hk0BE5Ufa0y84K5T66ZVvQlwK/cZZ1aCWcNy65zV5N5ZaxsE43IY43xp+Uyl4eHFGH4mNHJEK2YN1 WOQNj3KCT7Ws3BaVvnddkmCK8E+N4iotyrEXMefFxQo0dihkLhjChV83v2ZYOFzvMlssL0Sep/s/i G/KmmJtGSS7siPuwir1x4lHn61D95ar7G7bpl2dTXETEcdLP1+9iL+647oxJnAeyHZlXiznKeWRcZ cXlEm/itCfpYXQEZ2ywA==; Received: from localhost ([127.0.0.1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.90_1 #2 (Red Hat Linux)) id 1h4PWZ-0001QW-5O; Thu, 14 Mar 2019 12:31:51 +0000 Received: from mail-pg1-x544.google.com ([2607:f8b0:4864:20::544]) by bombadil.infradead.org with esmtps (Exim 4.90_1 #2 (Red Hat Linux)) id 1h4PWV-0001JS-2u for linux-arm-kernel@lists.infradead.org; Thu, 14 Mar 2019 12:31:48 +0000 Received: by mail-pg1-x544.google.com with SMTP id u9so3870902pgo.7 for ; Thu, 14 Mar 2019 05:31:47 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=UifkzEkFRqXu3yixaaw6yvTChu7M21y6ZQxvlg1zFMs=; b=sS0MVDMDyFcESOfK3Nol8/Q9B+4Nq7OBizGym/jfhkZlhXLU9qaRP6cu4TLyqsxpdP T+67ww1K+a5bDz9/uvJhZpx6XAt7LqHkiY/4jGQ2K/Uv9ycyFEHqD6MpWTX5D+/C8LZz nWCrs2WKQJv3X+k+icsJNiOYtS5hdrVOS1OUExDpeDyHGC+b/pxVo7yVviZDGh9EnES9 U5QXzA5y4Yp9wgoTr9uinS/Bdy73Ls7b0q2iQ+LuKofZKwy/AnpKnF8xTIZfs0IL98hf fds9yWMwj/yd22EWN6ACH+4PQv9V7c8xm2pQ4BQ1E1sUQ3f+ezVaXEXRZpiw0m6bEMhN vquw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=UifkzEkFRqXu3yixaaw6yvTChu7M21y6ZQxvlg1zFMs=; b=FW9CEMhOXhd87thPtzdP27HcVz/4bkibI2Xi2XG2RxgcxIWIF8/dN4c+3QxLICO0DA OYhfeec2j23kt3x9MuO4gxzp92BxE+uiNcrujwsh87ODDtwi0gGR7ug7aiCkA+50jiJ6 VZEvRF3MsopXFfSIzL8DJJycMlM/aoITPrm5Rm370Pcv1RiKfw9h715KcvF90ttvsQOQ tsXIVdaCRXibUENd8KbKqJA1e9Jv67q8I/QOAR/7panV8WSwfHulJKWD8tXC1Qpal/t4 vP4qZE7gPDe0yuIJoIw6PZXUXjOCIWEuuEYYR5isR5mMQFG7S0lyTiV4N7ZNa0hAsCLH TPiQ== X-Gm-Message-State: APjAAAX48n+AS4x1lVpXiE5g0uj39EhTxKytB6mW1pDu7mlddmpCuFWI CXA5Xapbc+8tsndS3EI39MHaX4gq X-Google-Smtp-Source: APXvYqxRMyrpEmHYR/ILhPTW1Bg/IeYMXzo2jTUTJ/0icyFY2AGGTdVBvD1DUJFo/IuPL0FXmtdrZQ== X-Received: by 2002:a65:4547:: with SMTP id x7mr36531973pgr.350.1552566706556; Thu, 14 Mar 2019 05:31:46 -0700 (PDT) Received: from localhost.localdomain ([2001:268:c0a4:3974:c70:4af9:86e2:2]) by smtp.gmail.com with ESMTPSA id l184sm23077547pfc.41.2019.03.14.05.31.40 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Thu, 14 Mar 2019 05:31:46 -0700 (PDT) From: William Breathitt Gray To: linus.walleij@linaro.org Subject: [PATCH v10 09/10] gpio: uniphier: Utilize for_each_set_clump8 macro Date: Thu, 14 Mar 2019 21:32:37 +0900 Message-Id: <9487b6bd8f9c2242448729f5f8fc9534f724b221.1552566114.git.vilhelm.gray@gmail.com> X-Mailer: git-send-email 2.21.0 In-Reply-To: References: MIME-Version: 1.0 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20190314_053147_260525_77D6BEC7 X-CRM114-Status: GOOD ( 11.41 ) X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: linux-arch@vger.kernel.org, yamada.masahiro@socionext.com, linux@rasmusvillemoes.dk, linux-kernel@vger.kernel.org, William Breathitt Gray , linux-gpio@vger.kernel.org, bgolaszewski@baylibre.com, akpm@linux-foundation.org, andriy.shevchenko@linux.intel.com, linux-arm-kernel@lists.infradead.org Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+patchwork-linux-arm=patchwork.kernel.org@lists.infradead.org X-Virus-Scanned: ClamAV using ClamSMTP Replace verbose implementation in set_multiple callback with for_each_set_clump8 macro to simplify code and improve clarity. An improvement in this case is that banks that are not masked will now be skipped. Cc: Masahiro Yamada Signed-off-by: William Breathitt Gray --- drivers/gpio/gpio-uniphier.c | 16 ++++++---------- 1 file changed, 6 insertions(+), 10 deletions(-) diff --git a/drivers/gpio/gpio-uniphier.c b/drivers/gpio/gpio-uniphier.c index 0f662b297a95..df640cb29b9c 100644 --- a/drivers/gpio/gpio-uniphier.c +++ b/drivers/gpio/gpio-uniphier.c @@ -15,9 +15,6 @@ #include #include -#define UNIPHIER_GPIO_BANK_MASK \ - GENMASK((UNIPHIER_GPIO_LINES_PER_BANK) - 1, 0) - #define UNIPHIER_GPIO_IRQ_MAX_NUM 24 #define UNIPHIER_GPIO_PORT_DATA 0x0 /* data */ @@ -147,15 +144,14 @@ static void uniphier_gpio_set(struct gpio_chip *chip, static void uniphier_gpio_set_multiple(struct gpio_chip *chip, unsigned long *mask, unsigned long *bits) { - unsigned int bank, shift, bank_mask, bank_bits; - int i; + unsigned int i; + unsigned long bank_mask; + unsigned int bank; + unsigned int bank_bits; - for (i = 0; i < chip->ngpio; i += UNIPHIER_GPIO_LINES_PER_BANK) { + for_each_set_clump8(i, bank_mask, mask, chip->ngpio) { bank = i / UNIPHIER_GPIO_LINES_PER_BANK; - shift = i % BITS_PER_LONG; - bank_mask = (mask[BIT_WORD(i)] >> shift) & - UNIPHIER_GPIO_BANK_MASK; - bank_bits = bits[BIT_WORD(i)] >> shift; + bank_bits = bitmap_get_value8(bits, chip->ngpio, i); uniphier_gpio_bank_write(chip, bank, UNIPHIER_GPIO_PORT_DATA, bank_mask, bank_bits); From patchwork Thu Mar 14 12:32: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: 10852727 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id DBBC2139A for ; Thu, 14 Mar 2019 12:32:13 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id B9C7E2A2A8 for ; Thu, 14 Mar 2019 12:32:13 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id B7A512A431; Thu, 14 Mar 2019 12:32:13 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-5.2 required=2.0 tests=BAYES_00,DKIM_ADSP_CUSTOM_MED, DKIM_SIGNED,DKIM_VALID,FREEMAIL_FROM,MAILING_LIST_MULTI,RCVD_IN_DNSWL_MED autolearn=ham version=3.3.1 Received: from bombadil.infradead.org (bombadil.infradead.org [198.137.202.133]) (using TLSv1.2 with cipher AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.wl.linuxfoundation.org (Postfix) with ESMTPS id 2EF3A2A2A8 for ; Thu, 14 Mar 2019 12:32:13 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20170209; h=Sender: Content-Transfer-Encoding:Content-Type:Cc:List-Subscribe:List-Help:List-Post: List-Archive:List-Unsubscribe:List-Id:MIME-Version:References:In-Reply-To: Message-Id:Date:Subject:To:From:Reply-To:Content-ID:Content-Description: Resent-Date:Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID: List-Owner; bh=mZ8Dex5CrrnyQB2GdpThZ990L41+7OHdR4DBcXiAcls=; b=OYXzlDdszn56lJ n+mwJaMNM6xINCiLVrE0n1eewVrwOHjiYthVK85pVgAOJkNxLAakbEWPyAoEVfNMaks/QEohh81ff xc8ZPCNEZZM8gltf7vQnIcz/a4FuVsfF8eRdfX495jyjSlW9kpQrWxjg1aVYyADJlDOM43F1shOrg kyoEWilU4kaQFNEAlW1Ga83GjhCke4vBuPlzfZTYuejW9FPNut9sI6i0rKPVbvT0K5q5Hn0kppgpT 7wJnNSsQ/VF7OT+c+0mCOo6RKySICpMg/c4abpqNe/FgM+kRuaSpFVv1DC4AB8HVY6nKOaFc+74OO 14BAMNPOd4FagGVevhqA==; Received: from localhost ([127.0.0.1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.90_1 #2 (Red Hat Linux)) id 1h4PWt-0001ny-O0; Thu, 14 Mar 2019 12:32:11 +0000 Received: from mail-pf1-x444.google.com ([2607:f8b0:4864:20::444]) by bombadil.infradead.org with esmtps (Exim 4.90_1 #2 (Red Hat Linux)) id 1h4PWp-0001mM-7Y for linux-arm-kernel@lists.infradead.org; Thu, 14 Mar 2019 12:32:09 +0000 Received: by mail-pf1-x444.google.com with SMTP id n22so3742790pfa.3 for ; Thu, 14 Mar 2019 05:32:07 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=sWqvhLQCqB3hBbf5JX4U0MkWu6YAuBs79qXIdQl30ic=; b=IRXlJ0qz9Kd2BXOAGQXdGk3vrjZktWGUQA0Ze+NSBebsfQMXPdFs6hBVx21VsIyUHP kUh6yNJLGYlApze+XvlXL2gsOeTjcpU3Go6OWq+H/VXTT4mniRnF4mBhcZXwhkM7yAu3 l9nbtdUPHbvS4WjBybLMmglR4uRpscwGmLcY/I0RSQz5xFm8xsyYr+AbINezSvLrt5gy PKYGJWPDoqUQZ9oekQawmgNk0XM7nyeyu4BqRlggebSMBBfc4SEqdbChusSu5vcH7DKV kzdQu03OjIWvHnuKXTJYADMLVQwhyhtnE6d4RjMbYltZbWC+hzoeKxq4G4Rmirq0MpMZ NptQ== 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=sWqvhLQCqB3hBbf5JX4U0MkWu6YAuBs79qXIdQl30ic=; b=lxM7LDEzwAwPNLW5V5RMZJevQIjfqav/bYwE3yaGgjSbV/8BPwZsxOQO8SavGm0VRM 03ogIifG75qyNpyBiinCTv+sAwEm9+8SsQkBcxjR8juPzSGwMd7tVViAoe8b2R3F6BnT GsjHfGYrtZfPXb7gNLaIKRKHXr2fdMr9gAkV8Fbc6YWUwMIp0lNPh93WiKxzVgtjT/UH pqyzWithaSFQBt4q0KW/rVVnEQNFjeXWQOp4Ni4rL2wer9n6q/kzlCFEcngqFlRJ3MIf gvXNnPzTXiKQs2NrD2TQGt4u5vmyoG3dSdZCNE0BxWWvslFJDwD2ZmMmuIM61nzb9C5Y imsw== X-Gm-Message-State: APjAAAVtkWOF1PtNieyGJDnsC0/0G2CduO0EXZ+LnXMfgubz5TJZDiR5 6/aLcTmJRQ5P8hXWfKUkda8= X-Google-Smtp-Source: APXvYqwIys2uDBj0/pFaYWB0nOI1dwhLgM0FarRD92hYDrV3JKRuOZ2eaL6CqnIG5l12Va686Atr8g== X-Received: by 2002:a17:902:bd82:: with SMTP id q2mr51435386pls.65.1552566726479; Thu, 14 Mar 2019 05:32:06 -0700 (PDT) Received: from localhost.localdomain ([2001:268:c0a4:3974:c70:4af9:86e2:2]) by smtp.gmail.com with ESMTPSA id y5sm1006181pgv.15.2019.03.14.05.32.00 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Thu, 14 Mar 2019 05:32:05 -0700 (PDT) From: William Breathitt Gray To: linus.walleij@linaro.org Subject: [PATCH v10 10/10] thermal: intel: intel_soc_dts_iosf: Utilize for_each_set_clump8 macro Date: Thu, 14 Mar 2019 21:32:57 +0900 Message-Id: X-Mailer: git-send-email 2.21.0 In-Reply-To: References: MIME-Version: 1.0 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20190314_053207_369372_0096D7FC X-CRM114-Status: GOOD ( 14.63 ) X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: linux-arch@vger.kernel.org, yamada.masahiro@socionext.com, linux@rasmusvillemoes.dk, linux-kernel@vger.kernel.org, William Breathitt Gray , linux-gpio@vger.kernel.org, bgolaszewski@baylibre.com, akpm@linux-foundation.org, andriy.shevchenko@linux.intel.com, linux-arm-kernel@lists.infradead.org Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+patchwork-linux-arm=patchwork.kernel.org@lists.infradead.org X-Virus-Scanned: ClamAV using ClamSMTP Utilize for_each_set_clump8 macro, and the bitmap_set_value8 and bitmap_get_value8 functions, where appropriate. In addition, remove the now unnecessary temp_mask and temp_shift members of the intel_soc_dts_sensor_entry structure. Cc: Andy Shevchenko Signed-off-by: William Breathitt Gray Tested-by: Andy Shevchenko --- drivers/thermal/intel/intel_soc_dts_iosf.c | 29 +++++++++++++--------- drivers/thermal/intel/intel_soc_dts_iosf.h | 2 -- 2 files changed, 17 insertions(+), 14 deletions(-) diff --git a/drivers/thermal/intel/intel_soc_dts_iosf.c b/drivers/thermal/intel/intel_soc_dts_iosf.c index e0813dfaa278..b66f554670f7 100644 --- a/drivers/thermal/intel/intel_soc_dts_iosf.c +++ b/drivers/thermal/intel/intel_soc_dts_iosf.c @@ -15,6 +15,7 @@ #define pr_fmt(fmt) KBUILD_MODNAME ": " fmt +#include #include #include #include @@ -111,6 +112,7 @@ static int update_trip_temp(struct intel_soc_dts_sensor_entry *dts, { int status; u32 temp_out; + unsigned long update_ptps; u32 out; u32 store_ptps; u32 store_ptmc; @@ -129,8 +131,9 @@ static int update_trip_temp(struct intel_soc_dts_sensor_entry *dts, if (status) return status; - out = (store_ptps & ~(0xFF << (thres_index * 8))); - out |= (temp_out & 0xFF) << (thres_index * 8); + update_ptps = store_ptps; + bitmap_set_value8(&update_ptps, 32, temp_out & 0xFF, thres_index * 8); + out = update_ptps; status = iosf_mbi_write(BT_MBI_UNIT_PMC, MBI_REG_WRITE, SOC_DTS_OFFSET_PTPS, out); if (status) @@ -232,6 +235,7 @@ static int sys_get_curr_temp(struct thermal_zone_device *tzd, u32 out; struct intel_soc_dts_sensor_entry *dts; struct intel_soc_dts_sensors *sensors; + unsigned long temp_raw; dts = tzd->devdata; sensors = dts->sensors; @@ -240,7 +244,8 @@ static int sys_get_curr_temp(struct thermal_zone_device *tzd, if (status) return status; - out = (out & dts->temp_mask) >> dts->temp_shift; + temp_raw = out; + out = bitmap_get_value8(&temp_raw, 32, dts->id * 8); out -= SOC_DTS_TJMAX_ENCODING; *temp = sensors->tj_max - out * 1000; @@ -290,10 +295,13 @@ static int add_dts_thermal_zone(int id, struct intel_soc_dts_sensor_entry *dts, { char name[10]; int trip_count = 0; + int writable_trip_count = 0; int trip_mask = 0; u32 store_ptps; int ret; - int i; + unsigned int i; + unsigned long trip; + unsigned long ptps; /* Store status to restor on exit */ ret = iosf_mbi_read(BT_MBI_UNIT_PMC, MBI_REG_READ, @@ -302,11 +310,10 @@ static int add_dts_thermal_zone(int id, struct intel_soc_dts_sensor_entry *dts, goto err_ret; dts->id = id; - dts->temp_mask = 0x00FF << (id * 8); - dts->temp_shift = id * 8; if (notification_support) { trip_count = min(SOC_MAX_DTS_TRIPS, trip_cnt); - trip_mask = BIT(trip_count - read_only_trip_cnt) - 1; + writable_trip_count = trip_count - read_only_trip_cnt; + trip_mask = GENMASK(writable_trip_count - 1, 0); } /* Check if the writable trip we provide is not used by BIOS */ @@ -315,11 +322,9 @@ static int add_dts_thermal_zone(int id, struct intel_soc_dts_sensor_entry *dts, if (ret) trip_mask = 0; else { - for (i = 0; i < trip_count; ++i) { - if (trip_mask & BIT(i)) - if (store_ptps & (0xff << (i * 8))) - trip_mask &= ~BIT(i); - } + ptps = store_ptps; + for_each_set_clump8(i, trip, ptps, writable_trip_count * 8) + trip_mask &= ~BIT(i / 8); } dts->trip_mask = trip_mask; dts->trip_count = trip_count; diff --git a/drivers/thermal/intel/intel_soc_dts_iosf.h b/drivers/thermal/intel/intel_soc_dts_iosf.h index 625e37bf93dc..d0362d7acdef 100644 --- a/drivers/thermal/intel/intel_soc_dts_iosf.h +++ b/drivers/thermal/intel/intel_soc_dts_iosf.h @@ -33,8 +33,6 @@ struct intel_soc_dts_sensors; struct intel_soc_dts_sensor_entry { int id; - u32 temp_mask; - u32 temp_shift; u32 store_status; u32 trip_mask; u32 trip_count;