From patchwork Wed Mar 27 04:58:45 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: William Breathitt Gray X-Patchwork-Id: 10872487 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 4BFAA14DE for ; Wed, 27 Mar 2019 04:57:59 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 3113E28A38 for ; Wed, 27 Mar 2019 04:57:59 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 24F1A28D33; Wed, 27 Mar 2019 04:57: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=unavailable version=3.3.1 Received: from bombadil.infradead.org (bombadil.infradead.org [198.137.202.133]) (using TLSv1.2 with cipher AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.wl.linuxfoundation.org (Postfix) with ESMTPS id AD00028A38 for ; Wed, 27 Mar 2019 04:57: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=sCSCCLM8hyd9M7S3H0nnv+Lmb8myjKvJrsqCl1kU+wU=; b=Pgvo6031q9emt6 1NiS3ugJqjUuF+E2/MpOy74hflB2LYFCdzz9usjuCrWzv9PL+lLjnAsI0azSxSnzCjPabNKpa+Pkm BDoj9xeq2jquEX7PphheU2dAQhBigtTb+ClTuCqhZrcLCiToHOafzk0aEF/GxJJ0DBwOUly6xdEfx rfJr29bp9Vw8CtIKsmK8wPXqn9c7s5LaavIiuAzYWIBoegY7EfLHDvHKvu4Edy+q20aZS2wk4Bmgp XnDAuRPV84WLj9eBO8ZHn4r/lWzfHzvc4RaU2hAw8TnB/h+EC73y2s86mAQx+oyyE+mk53LW2bGv2 LqGGEbImHU7NK3ovobTQ==; 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 1h90dQ-0003jo-5w; Wed, 27 Mar 2019 04:57:56 +0000 Received: from mail-pf1-x443.google.com ([2607:f8b0:4864:20::443]) by bombadil.infradead.org with esmtps (Exim 4.90_1 #2 (Red Hat Linux)) id 1h90dL-0003ha-JT for linux-arm-kernel@lists.infradead.org; Wed, 27 Mar 2019 04:57:53 +0000 Received: by mail-pf1-x443.google.com with SMTP id c207so9139847pfc.7 for ; Tue, 26 Mar 2019 21:57:51 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=Uip2SJNOxYS4/yCupvO0yCYaokZfoOseJfUme2GdvMI=; b=VXnjPTjsu4YySzBI7FUjsuKpACfcIimz0wCHKOW79RkaSxLv7spNkcaKT2scqV7H8v SNALUo3sBmzp1jt86RvYXQowaViVEy6gNG2Esxt1f4OiUNu1p7YedEPz1OjiktSo+aPp 3H2NmDzjrZDlyZivCvs7z0OPi2C2cFN/Ci8+hV8DKYH7bqBtg/7GMnv8c5a1q3ew4SN7 2x5U8kwYQJJ1kcWFCqPrL20gU1rpYt46wdh4Ck2GDzZnp02Sr8aUVSRMDrjW1IzSyriV aQtyhK8bCuOP6NSZEWdvRfRaMxBLCLX1tyhmCbnui4PrKBoGhoBkeqCxwcRvhudZ4Cga L3kw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=Uip2SJNOxYS4/yCupvO0yCYaokZfoOseJfUme2GdvMI=; b=NGGO8B4cCEufIFKwwIShTE9Yb6EXUqIYKOFzw4CzlOjMPVRT6ni6pmiFeWGBjntJm+ 191O7FIZ8q3y08k9ku24EYvhGt2SCPGQypCSWbTGZVfnvYa4wEr3oRqIv2+7t3RMsb/b EEmfrvYnYWhoX+vwPeP7JXZIupNZRTKC+oBuoriudUGQRzaRA71GBHDKBODlkF4ZHHk+ vaFfg1F14Oeoja7HG2k2Cn17bnwaqVxheggidsD+NFHnXcPlHjCc5AfYwAkFDB++TLdw JM60L/eMgdT7kDf2nd0lLU6B7ZWYCKm+QvuCNexiPpNDb9VBzhAfBG21FEcN/Hqgzjux z/0A== X-Gm-Message-State: APjAAAWkDHqeiiNWVCDzQEP9AdQHgLDnHU9FpTXdJRwW26dyYrLT1UQY BZCM12w5rTzV2HKKhEVnxnbqNvrQ X-Google-Smtp-Source: APXvYqwIBIGzL2EaNaieYfvz6H4C3wp+BjWPMVK5N9esxq/aTuo7hAczrGEKE4BQzsFQkWH0P1a9TA== X-Received: by 2002:a62:3585:: with SMTP id c127mr32910673pfa.71.1553662670879; Tue, 26 Mar 2019 21:57:50 -0700 (PDT) Received: from localhost.localdomain ([2001:268:c0a5:6014:c70:4af9:86e2:2]) by smtp.gmail.com with ESMTPSA id e22sm27564056pfi.126.2019.03.26.21.57.45 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Tue, 26 Mar 2019 21:57:50 -0700 (PDT) From: William Breathitt Gray To: linus.walleij@linaro.org, bgolaszewski@baylibre.com Subject: [PATCH v13 01/11] bitops: Introduce the for_each_set_clump8 macro Date: Wed, 27 Mar 2019 13:58:45 +0900 Message-Id: <497dc4b5b1f668b54e008e10a43d4108f4a41213.1553661964.git.vilhelm.gray@gmail.com> X-Mailer: git-send-email 2.21.0 In-Reply-To: References: MIME-Version: 1.0 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20190326_215751_922848_137523EF X-CRM114-Status: GOOD ( 13.96 ) X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: linux-arch@vger.kernel.org, preid@electromag.com.au, Arnd Bergmann , yamada.masahiro@socionext.com, linux-pm@vger.kernel.org, linux@rasmusvillemoes.dk, linux-kernel@vger.kernel.org, William Breathitt Gray , linux-gpio@vger.kernel.org, Andy Shevchenko , Lukas Wunner , geert@linux-m68k.org, akpm@linux-foundation.org, andriy.shevchenko@linux.intel.com, linux-arm-kernel@lists.infradead.org Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+patchwork-linux-arm=patchwork.kernel.org@lists.infradead.org X-Virus-Scanned: ClamAV using ClamSMTP This macro iterates for each 8-bit group of bits (clump) with set bits, within a bitmap memory region. For each iteration, "start" is set to the bit offset of the found clump, while the respective clump value is stored to the location pointed by "clump". Additionally, the bitmap_get_value8 and bitmap_set_value8 functions are introduced to respectively get and set an 8-bit value in a bitmap memory region. Suggested-by: Andy Shevchenko Suggested-by: Rasmus Villemoes Suggested-by: Lukas Wunner Cc: Arnd Bergmann Cc: Andrew Morton Cc: Andy Shevchenko Cc: Linus Walleij Signed-off-by: William Breathitt Gray --- include/asm-generic/bitops/find.h | 11 ++++++ include/linux/bitops.h | 5 +++ lib/find_bit.c | 58 +++++++++++++++++++++++++++++++ 3 files changed, 74 insertions(+) diff --git a/include/asm-generic/bitops/find.h b/include/asm-generic/bitops/find.h index 8a1ee10014de..b0a99035f64f 100644 --- a/include/asm-generic/bitops/find.h +++ b/include/asm-generic/bitops/find.h @@ -80,4 +80,15 @@ extern unsigned long find_first_zero_bit(const unsigned long *addr, #endif /* CONFIG_GENERIC_FIND_FIRST_BIT */ +unsigned long bitmap_get_value8(const unsigned long *addr, unsigned long start); + +void bitmap_set_value8(unsigned long *addr, unsigned long value, + unsigned long start); + +unsigned long find_next_clump8(unsigned long *clump, const unsigned long *addr, + unsigned long size, unsigned long offset); + +#define find_first_clump8(clump, bits, size) \ + find_next_clump8((clump), (bits), (size), 0) + #endif /*_ASM_GENERIC_BITOPS_FIND_H_ */ diff --git a/include/linux/bitops.h b/include/linux/bitops.h index 602af23b98c7..1d9b5efb9bd4 100644 --- a/include/linux/bitops.h +++ b/include/linux/bitops.h @@ -40,6 +40,11 @@ extern unsigned long __sw_hweight64(__u64 w); (bit) < (size); \ (bit) = find_next_zero_bit((addr), (size), (bit) + 1)) +#define for_each_set_clump8(start, clump, bits, size) \ + for ((start) = find_first_clump8(&(clump), (bits), (size)); \ + (start) < (size); \ + (start) = find_next_clump8(&(clump), (bits), (size), (start) + 8)) + static inline int get_bitmask_order(unsigned int count) { int order; diff --git a/lib/find_bit.c b/lib/find_bit.c index ee3df93ba69a..71a4e0a31e40 100644 --- a/lib/find_bit.c +++ b/lib/find_bit.c @@ -218,3 +218,61 @@ EXPORT_SYMBOL(find_next_bit_le); #endif #endif /* __BIG_ENDIAN */ + +/** + * bitmap_get_value8 - get an 8-bit value within a memory region + * @addr: address to the bitmap memory region + * @start: bit offset of the 8-bit value; must be a multiple of 8 + * + * Returns the 8-bit value located at the @start bit offset within the @addr + * memory region. + */ +unsigned long bitmap_get_value8(const unsigned long *addr, unsigned long start) +{ + const size_t idx = BIT_WORD(start); + const unsigned long offset = start % BITS_PER_LONG; + + return (addr[idx] >> offset) & 0xFF; +} +EXPORT_SYMBOL(bitmap_get_value8); + +/** + * bitmap_set_value8 - set an 8-bit value within a memory region + * @addr: address to the bitmap memory region + * @value: the 8-bit value; values wider than 8 bits may clobber bitmap + * @start: bit offset of the 8-bit value; must be a multiple of 8 + */ +void bitmap_set_value8(unsigned long *addr, unsigned long value, + unsigned long start) +{ + const size_t idx = BIT_WORD(start); + const unsigned long offset = start % BITS_PER_LONG; + + addr[idx] &= ~(0xFF << offset); + addr[idx] |= value << offset; +} +EXPORT_SYMBOL(bitmap_set_value8); + +/** + * find_next_clump8 - find next 8-bit clump with set bits in a memory region + * @clump: location to store copy of found clump + * @addr: address to base the search on + * @size: bitmap size in number of bits + * @offset: bit offset at which to start searching + * + * Returns the bit offset for the next set clump; the found clump value is + * copied to the location pointed by @clump. If no bits are set, returns @size. + */ +unsigned long find_next_clump8(unsigned long *clump, const unsigned long *addr, + unsigned long size, unsigned long offset) +{ + offset = find_next_bit(addr, size, offset); + if (offset == size) + return size; + + offset = round_down(offset, 8); + *clump = bitmap_get_value8(addr, offset); + + return offset; +} +EXPORT_SYMBOL(find_next_clump8); From patchwork Wed Mar 27 04:59:05 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: William Breathitt Gray X-Patchwork-Id: 10872489 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 B263A139A for ; Wed, 27 Mar 2019 04:58:19 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 9A4D028A38 for ; Wed, 27 Mar 2019 04:58:19 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 8E8DF28D33; Wed, 27 Mar 2019 04:58:19 +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 2396128A38 for ; Wed, 27 Mar 2019 04:58: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=NGjO61jJ+ZtHjMj7PjKydAZFMhP3fiH/iEzwOEbSN9s=; b=X70jX/y1jgqJ2D NF4+u95+crfGsUJvuRuPIxqMxVKC9dUR/i1Cg/DF+dMsjGL+LVuoq82IxVfnaD2aPRZ5tvGCT41SL zaayPhtOBXcDjErWU111FGM6OS+FJhZOgQvjAJH9gG2e22ogBSWFcVgW5kj7AnF0K/RIkhjjUFrpx LTaDw2IEDwln/cV5GYUhVcC13ntDxcTH4L0ttxrLgHaFi3kB0X2nkfsFC6XeSvluD3PdMOylFO09a 4ILyOIV255qVbdPj9n/xWlfQwqvRXKPafJqsiED4fgVZI5LUNYKKp6BvUQtjE9CyHhDihkGkfQyQS mT5M2AXzuBHXJch4fPxg==; 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 1h90dl-00042E-6z; Wed, 27 Mar 2019 04:58:17 +0000 Received: from mail-pl1-x644.google.com ([2607:f8b0:4864:20::644]) by bombadil.infradead.org with esmtps (Exim 4.90_1 #2 (Red Hat Linux)) id 1h90df-0003zk-H1 for linux-arm-kernel@lists.infradead.org; Wed, 27 Mar 2019 04:58:14 +0000 Received: by mail-pl1-x644.google.com with SMTP id m10so2725563plt.10 for ; Tue, 26 Mar 2019 21:58:10 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=voPjJIpaEIENDSX5D22rQL6GtMzeJ5e93HyvmN9lrck=; b=hwamcCt2ulELLEuskhsLCImVFMv2a97a0lQZoYcRyKuJrzsjVIqZU2frCB8UMNZvvC oaacF4wgDmoIgX2DUUpDVCl+MSnEo2A8Y9PSz2isQd0SIZprEQUcQ5TG82IxYtEBFh63 mM3FrKIk3zFchrNeuhIL+7Z4gojX/dz5khT2bMZo1NmIKlppI5fHST2mLwx/Zg1t+9Uu sMOJrHtRzUU2+TAJV1ON7P56OJK0aqodRrPtffq83Po4Rqp32Af2bEU9KuRDhznHC0VA 72y44/ibe1oVK9TO7pJWxKt624iDJSHqXrwDTk7iI7llFXvA+yn6OAULWM5WQTndpYQg OBHg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=voPjJIpaEIENDSX5D22rQL6GtMzeJ5e93HyvmN9lrck=; b=rRx82VLx/8PbVfj2rUUwVTvjtuFOyD1s1p1t1HwMAuNnSpKGiSPtZzwdMe3ks2zlgP fTKXJHjmINa+7tg9Op2mSLOM1Zwzfk8aPIc5VS7bsgDEi7/O+mwOgUcoiQtQIg9eYsjT FAT8rNJA+LSSDgypV+Evr/YRdIDDa5SjK16V/IB6dKUzs2CShTit6SmFuAKUwEn5BV0s Ksz14HpGmOP3wJoiGSxLn+YzqIk+oal1A6eFCp0u5rkI31dkFNEe/wSti6taFZs9Vuri A5choL5mUOdoTQAjvCe1doz8LOlpUiLTmpax9QXOAqKLcsa51XjYFYT9DsrtMx1li2Bc 8rxg== X-Gm-Message-State: APjAAAWoJCWKjACMEOWDm8IndVahZRNX2xwVi/AFuVzgoXpfKM5GlIYG yXVkV/sTBhX2zOmiLD0T2as= X-Google-Smtp-Source: APXvYqzo65K90+xL7aOCZ0TQNayGxWizVGQ3lrqBiJdDKj1edlvX8dhBi6MkQL5Ybh1LoRvlUQ7wRQ== X-Received: by 2002:a17:902:a612:: with SMTP id u18mr34599414plq.145.1553662689376; Tue, 26 Mar 2019 21:58:09 -0700 (PDT) Received: from localhost.localdomain ([2001:268:c0a5:6014:c70:4af9:86e2:2]) by smtp.gmail.com with ESMTPSA id d130sm44455194pfg.49.2019.03.26.21.58.04 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Tue, 26 Mar 2019 21:58:08 -0700 (PDT) From: William Breathitt Gray To: linus.walleij@linaro.org, bgolaszewski@baylibre.com Subject: [PATCH v13 02/11] lib/test_bitmap.c: Add for_each_set_clump8 test cases Date: Wed, 27 Mar 2019 13:59:05 +0900 Message-Id: <924aa49777091e103c383073800c908c55bce631.1553661964.git.vilhelm.gray@gmail.com> X-Mailer: git-send-email 2.21.0 In-Reply-To: References: MIME-Version: 1.0 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20190326_215811_570742_9FF6C108 X-CRM114-Status: GOOD ( 14.08 ) X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: linux-arch@vger.kernel.org, preid@electromag.com.au, yamada.masahiro@socionext.com, linux-pm@vger.kernel.org, linux@rasmusvillemoes.dk, linux-kernel@vger.kernel.org, William Breathitt Gray , linux-gpio@vger.kernel.org, Andy Shevchenko , geert@linux-m68k.org, akpm@linux-foundation.org, andriy.shevchenko@linux.intel.com, linux-arm-kernel@lists.infradead.org Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+patchwork-linux-arm=patchwork.kernel.org@lists.infradead.org X-Virus-Scanned: ClamAV using ClamSMTP The introduction of the for_each_set_clump8 macro warrants test cases to verify the implementation. This patch adds test case checks for whether an out-of-bounds clump index is returned, a zero clump is returned, or the returned clump value differs from the expected clump value. Cc: Rasmus Villemoes Acked-by: Andrew Morton Reviewed-by: Andy Shevchenko Reviewed-by: Linus Walleij Signed-off-by: William Breathitt Gray --- lib/test_bitmap.c | 65 +++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 65 insertions(+) diff --git a/lib/test_bitmap.c b/lib/test_bitmap.c index 6cd7d0740005..8d1f268069c1 100644 --- a/lib/test_bitmap.c +++ b/lib/test_bitmap.c @@ -88,6 +88,36 @@ __check_eq_u32_array(const char *srcfile, unsigned int line, return true; } +static bool __init __check_eq_clump8(const char *srcfile, unsigned int line, + const unsigned int offset, + const unsigned int size, + const unsigned char *const clump_exp, + const unsigned long *const clump) +{ + unsigned long exp; + + if (offset >= size) { + pr_warn("[%s:%u] bit offset for clump out-of-bounds: expected less than %u, got %u\n", + srcfile, line, size, offset); + return false; + } + + exp = clump_exp[offset / 8]; + if (!exp) { + pr_warn("[%s:%u] bit offset for zero clump: expected nonzero clump, got bit offset %u with clump value 0", + srcfile, line, offset); + return false; + } + + if (*clump != exp) { + pr_warn("[%s:%u] expected clump value of 0x%lX, got clump value of 0x%lX", + srcfile, line, exp, *clump); + return false; + } + + return true; +} + #define __expect_eq(suffix, ...) \ ({ \ int result = 0; \ @@ -104,6 +134,7 @@ __check_eq_u32_array(const char *srcfile, unsigned int line, #define expect_eq_bitmap(...) __expect_eq(bitmap, ##__VA_ARGS__) #define expect_eq_pbl(...) __expect_eq(pbl, ##__VA_ARGS__) #define expect_eq_u32_array(...) __expect_eq(u32_array, ##__VA_ARGS__) +#define expect_eq_clump8(...) __expect_eq(clump8, ##__VA_ARGS__) static void __init test_zero_clear(void) { @@ -361,6 +392,39 @@ static void noinline __init test_mem_optimisations(void) } } +static const unsigned char clump_exp[] __initconst = { + 0x01, /* 1 bit set */ + 0x02, /* non-edge 1 bit set */ + 0x00, /* zero bits set */ + 0x38, /* 3 bits set across 4-bit boundary */ + 0x38, /* Repeated clump */ + 0x0F, /* 4 bits set */ + 0xFF, /* all bits set */ + 0x05, /* non-adjacent 2 bits set */ +}; + +static void __init test_for_each_set_clump8(void) +{ +#define CLUMP_EXP_NUMBITS 64 + DECLARE_BITMAP(bits, CLUMP_EXP_NUMBITS); + unsigned int start; + unsigned long clump; + + /* set bitmap to test case */ + bitmap_zero(bits, CLUMP_EXP_NUMBITS); + bitmap_set(bits, 0, 1); /* 0x01 */ + bitmap_set(bits, 9, 1); /* 0x02 */ + bitmap_set(bits, 27, 3); /* 0x28 */ + bitmap_set(bits, 35, 3); /* 0x28 */ + bitmap_set(bits, 40, 4); /* 0x0F */ + bitmap_set(bits, 48, 8); /* 0xFF */ + bitmap_set(bits, 56, 1); /* 0x05 - part 1 */ + bitmap_set(bits, 58, 1); /* 0x05 - part 2 */ + + for_each_set_clump8(start, clump, bits, CLUMP_EXP_NUMBITS) + expect_eq_clump8(start, CLUMP_EXP_NUMBITS, clump_exp, &clump); +} + static int __init test_bitmap_init(void) { test_zero_clear(); @@ -369,6 +433,7 @@ static int __init test_bitmap_init(void) test_bitmap_arr32(); test_bitmap_parselist(); test_mem_optimisations(); + test_for_each_set_clump8(); if (failed_tests == 0) pr_info("all %u tests passed\n", total_tests); From patchwork Wed Mar 27 04:59:24 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: William Breathitt Gray X-Patchwork-Id: 10872495 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 063F8139A for ; Wed, 27 Mar 2019 04:58:39 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id E0A3628A38 for ; Wed, 27 Mar 2019 04:58:38 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id D424F28D33; Wed, 27 Mar 2019 04:58: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=unavailable version=3.3.1 Received: from bombadil.infradead.org (bombadil.infradead.org [198.137.202.133]) (using TLSv1.2 with cipher AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.wl.linuxfoundation.org (Postfix) with ESMTPS id 6530728A38 for ; Wed, 27 Mar 2019 04:58:38 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20170209; h=Sender: Content-Transfer-Encoding:Content-Type:Cc:List-Subscribe:List-Help:List-Post: List-Archive:List-Unsubscribe:List-Id:MIME-Version:References:In-Reply-To: Message-Id:Date:Subject:To:From:Reply-To:Content-ID:Content-Description: Resent-Date:Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID: List-Owner; bh=l99R3wWJRaBqrH98wdYRSkqiaXhXq8c3Vjz4HTrmSko=; b=p1VosOFdKGvvSz Sy/wDWzgx8drEGNnCpz5k6g8P5sLFJeH6OL5UCMTj/SK/A4FqKnqzLrKcCSXvbZmZOlQMgg9Qt+hy U+/Jxoivn48Ed5Og80Qt3ovYyaX2L7Ii7AQR1b5+1u+5FqgHAh9Sicnd+SDWd6ZT7zxw75QrZnADg eo+Eg/clKHqZh8FcGDeXyOERa2q6cGKjGkjn/uoCc6Fufxdz3kLZQRzCjWriTBRzFfSKJ/YB0lFtp qdh1jSdAaXJXKauj44pxKt55BuRmLvMxGrtMKbof7SlPC0fhYw9ZCXWreTWi63q/rfo02q9cLTiPu QcMYR01roum1qEusE0Lw==; 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 1h90e4-0004IN-4L; Wed, 27 Mar 2019 04:58:36 +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 1h90dz-0004Gz-SD for linux-arm-kernel@lists.infradead.org; Wed, 27 Mar 2019 04:58:33 +0000 Received: by mail-pg1-x541.google.com with SMTP id p6so9349716pgh.9 for ; Tue, 26 Mar 2019 21:58:31 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=D+VKB8odm/iRn7Qlf3NsRe6rs5PO9H8u0I72DJse46A=; b=QiZYWv98mpUpZW7djHUVZS0MEFySpQjFTUP9fp/wlZ4PeMl2XJrN+g9Gh/8jgXbwzt 3wv+5c9twrrKcbT8FeddPYDk+IqFi8Nwyt/U6UOqdSK3VREjeRNF/ZuSKx1HoBwyqPz9 AtAAN7uKcl06iTl7mY6OOfFp7z8cS7jyzl+9nDlKIq2bRATR1rf7QXPGFr1FrRFws3YB tvGe4gWIRkyPXkush5lGWK1HtIq4SaHazEUidxScUcmdtmDE3upJnCuqrH5D0j6dZYmj uToISTrJJlneDT1//jBoWeynokP6ehckgWqJVjzz09I98YJ41YgIvXvOdp+zRzzUN3nr hoiQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=D+VKB8odm/iRn7Qlf3NsRe6rs5PO9H8u0I72DJse46A=; b=S+kkCilEBUcBQtSAbmrN4Ti9xq0250hwZm1nAPJBLbEsv8A1V8emoglg/2X9HpcRAC MBCWOsHgjUgmyBJ6twCzLDlbpohg7HssLr/drlPkEta30gC+HT3N4GQukmoMl6l0X7+7 LR3tzu3hDzQNCAbOGXuzA9xkCW5aVTbts705pL+jMSCfCfRegKpPaf3H80zhN4JeCDcA VXqYcbsbEB/WXMnKPMs5dfzKH45LeAcSqjRWaFrJhT1zQS8KwkBt2SeU0SmV5aIwhnI2 pIfNMCgwnbj1TivqLxcaZoiOcGljaf9K9MXeIaop6PvBbsJqpBIyFmhSvwgLQ7WBECgA Xc+A== X-Gm-Message-State: APjAAAW3MWKhDGS6g8IjNi6CH6zigJtnl07pNsuuyakw+iAmDXns8LUU gCT4TW2+gWiJicTqSb6RKus= X-Google-Smtp-Source: APXvYqxE+ztDBBrFWBqATimDFtBanMe9IkMpfq68fj7mvbOYiy6sJk9MwgvB5X80CHzRbaQi1yE0LQ== X-Received: by 2002:a63:fb45:: with SMTP id w5mr32663083pgj.118.1553662710330; Tue, 26 Mar 2019 21:58:30 -0700 (PDT) Received: from localhost.localdomain ([2001:268:c0a5:6014:c70:4af9:86e2:2]) by smtp.gmail.com with ESMTPSA id j8sm24879147pff.183.2019.03.26.21.58.23 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Tue, 26 Mar 2019 21:58:29 -0700 (PDT) From: William Breathitt Gray To: linus.walleij@linaro.org, bgolaszewski@baylibre.com Subject: [PATCH v13 03/11] gpio: 104-dio-48e: Utilize for_each_set_clump8 macro Date: Wed, 27 Mar 2019 13:59:24 +0900 Message-Id: X-Mailer: git-send-email 2.21.0 In-Reply-To: References: MIME-Version: 1.0 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20190326_215832_138437_AAC7B001 X-CRM114-Status: GOOD ( 14.55 ) X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: linux-arch@vger.kernel.org, preid@electromag.com.au, yamada.masahiro@socionext.com, linux-pm@vger.kernel.org, linux@rasmusvillemoes.dk, linux-kernel@vger.kernel.org, William Breathitt Gray , linux-gpio@vger.kernel.org, geert@linux-m68k.org, akpm@linux-foundation.org, andriy.shevchenko@linux.intel.com, linux-arm-kernel@lists.infradead.org Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+patchwork-linux-arm=patchwork.kernel.org@lists.infradead.org X-Virus-Scanned: ClamAV using ClamSMTP Replace verbose implementation in get_multiple/set_multiple callbacks with for_each_set_clump8 macro to simplify code and improve clarity. Reviewed-by: Linus Walleij Signed-off-by: William Breathitt Gray --- drivers/gpio/gpio-104-dio-48e.c | 73 ++++++++++----------------------- 1 file changed, 21 insertions(+), 52 deletions(-) diff --git a/drivers/gpio/gpio-104-dio-48e.c b/drivers/gpio/gpio-104-dio-48e.c index 92c8f944bf64..2fc6d2b11d25 100644 --- a/drivers/gpio/gpio-104-dio-48e.c +++ b/drivers/gpio/gpio-104-dio-48e.c @@ -183,46 +183,25 @@ static int dio48e_gpio_get(struct gpio_chip *chip, unsigned offset) return !!(port_state & mask); } +static const size_t ports[] = { 0, 1, 2, 4, 5, 6 }; + static int dio48e_gpio_get_multiple(struct gpio_chip *chip, unsigned long *mask, unsigned long *bits) { struct dio48e_gpio *const dio48egpio = gpiochip_get_data(chip); - size_t i; - static const size_t ports[] = { 0, 1, 2, 4, 5, 6 }; - const unsigned int gpio_reg_size = 8; - unsigned int bits_offset; - size_t word_index; - unsigned int word_offset; - unsigned long word_mask; - const unsigned long port_mask = GENMASK(gpio_reg_size - 1, 0); + unsigned long offset; + unsigned long gpio_mask; + unsigned int port_addr; unsigned long port_state; /* clear bits array to a clean slate */ bitmap_zero(bits, chip->ngpio); - /* get bits are evaluated a gpio port register at a time */ - for (i = 0; i < ARRAY_SIZE(ports); i++) { - /* gpio offset in bits array */ - bits_offset = i * gpio_reg_size; - - /* word index for bits array */ - word_index = BIT_WORD(bits_offset); - - /* gpio offset within current word of bits array */ - word_offset = bits_offset % BITS_PER_LONG; - - /* mask of get bits for current gpio within current word */ - word_mask = mask[word_index] & (port_mask << word_offset); - if (!word_mask) { - /* no get bits in this port so skip to next one */ - continue; - } - - /* read bits from current gpio port */ - port_state = inb(dio48egpio->base + ports[i]); + for_each_set_clump8(offset, gpio_mask, mask, ARRAY_SIZE(ports) * 8) { + port_addr = dio48egpio->base + ports[offset / 8]; + port_state = inb(port_addr) & gpio_mask; - /* store acquired bits at respective bits array offset */ - bits[word_index] |= (port_state << word_offset) & word_mask; + bitmap_set_value8(bits, port_state, offset); } return 0; @@ -252,37 +231,27 @@ static void dio48e_gpio_set_multiple(struct gpio_chip *chip, unsigned long *mask, unsigned long *bits) { struct dio48e_gpio *const dio48egpio = gpiochip_get_data(chip); - unsigned int i; - const unsigned int gpio_reg_size = 8; - unsigned int port; - unsigned int out_port; - unsigned int bitmask; + unsigned long offset; + unsigned long gpio_mask; + size_t index; + unsigned int port_addr; + unsigned long bitmask; unsigned long flags; - /* set bits are evaluated a gpio register size at a time */ - for (i = 0; i < chip->ngpio; i += gpio_reg_size) { - /* no more set bits in this mask word; skip to the next word */ - if (!mask[BIT_WORD(i)]) { - i = (BIT_WORD(i) + 1) * BITS_PER_LONG - gpio_reg_size; - continue; - } + for_each_set_clump8(offset, gpio_mask, mask, ARRAY_SIZE(ports) * 8) { + index = offset / 8; + port_addr = dio48egpio->base + ports[index]; - port = i / gpio_reg_size; - out_port = (port > 2) ? port + 1 : port; - bitmask = mask[BIT_WORD(i)] & bits[BIT_WORD(i)]; + bitmask = bitmap_get_value8(bits, offset) & gpio_mask; raw_spin_lock_irqsave(&dio48egpio->lock, flags); /* update output state data and set device gpio register */ - dio48egpio->out_state[port] &= ~mask[BIT_WORD(i)]; - dio48egpio->out_state[port] |= bitmask; - outb(dio48egpio->out_state[port], dio48egpio->base + out_port); + dio48egpio->out_state[index] &= ~gpio_mask; + dio48egpio->out_state[index] |= bitmask; + outb(dio48egpio->out_state[index], port_addr); raw_spin_unlock_irqrestore(&dio48egpio->lock, flags); - - /* prepare for next gpio register set */ - mask[BIT_WORD(i)] >>= gpio_reg_size; - bits[BIT_WORD(i)] >>= gpio_reg_size; } } From patchwork Wed Mar 27 04:59:50 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: William Breathitt Gray X-Patchwork-Id: 10872497 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 5763E14DE for ; Wed, 27 Mar 2019 04:59:01 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 33C5128D32 for ; Wed, 27 Mar 2019 04:59:01 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 2797A28D37; Wed, 27 Mar 2019 04:59:01 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-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 C04EB28D32 for ; Wed, 27 Mar 2019 04:58:59 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20170209; h=Sender: Content-Transfer-Encoding:Content-Type:Cc:List-Subscribe:List-Help:List-Post: List-Archive:List-Unsubscribe:List-Id:MIME-Version:References:In-Reply-To: Message-Id:Date:Subject:To:From:Reply-To:Content-ID:Content-Description: Resent-Date:Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID: List-Owner; bh=3m+yWWlSu3ywB6ToREJoZIqNevDJdffMz81YzdDxoIc=; b=ikANBzGyl7QnfU 5+vICZJa/i5W0RdkgES/HcDlR8EuiCNMpW1LX4+cboL+mZHQ+ahH6Klbq9pO42A7ifGdVoshAzREQ i4gWOVP6Bv/o1cZhzhRFpzK/geXurIn6daB/ZajlTUSHYOX25RqItpn8dxxfxvdi59XQUX3ba3oz/ z5auGvBSmoaw89a4HsmQhGNs2KEAf5+yx+h0JwkTTTs5Alxsyu1Bn89oGMzW83HIauj0UZ800wiex PM9RPGoUg+rQzHjATuL2C/34O3XbuX7skbUIdBlzXLSpbmXpWl08KGAJpshygS794+1cIr2BJ6yAe JPf8AHaE8vgboK52Mekw==; 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 1h90eQ-0004YH-OM; Wed, 27 Mar 2019 04:58:58 +0000 Received: from mail-pl1-x642.google.com ([2607:f8b0:4864:20::642]) by bombadil.infradead.org with esmtps (Exim 4.90_1 #2 (Red Hat Linux)) id 1h90eN-0004Xk-Am for linux-arm-kernel@lists.infradead.org; Wed, 27 Mar 2019 04:58:56 +0000 Received: by mail-pl1-x642.google.com with SMTP id y6so2727506plt.1 for ; Tue, 26 Mar 2019 21:58:55 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=tvDsEaR5RVMjQmpl7pvXE6aMRh7V9pplB1t4MlLyGlo=; b=ttJmL44tLwmeymwJk21YO5pD2dbq91CaeW1b2AyPJi9Sl5J2FnhLhAjxGI07JVZ0ev GAUnoTmThB2nh0kOiZNRgIRXh9sUjgXjGLE7RRHXP0MLUC4EkXkBDSstM64EDRJ6YqqS TFtKVyWQCYL3irrd6qYAZs8JbDNwm/qw8n6UdWxC1aXCjf3zpnvbubMqR2FvGESakekj DvJserniuhIzf91JoYxCeyLD6opMp7lemdpPjpAoADet3HJvymtnIIY27MJF92IUjXTS +uRkEYqZ4T84bPPnrXA36HLVVVOxcGIV7XMwEe8Gpsx1FuSe0yq4UCs9g1kDr15iuSUs uz0g== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=tvDsEaR5RVMjQmpl7pvXE6aMRh7V9pplB1t4MlLyGlo=; b=MwsnITTGjeI4VjH1YuT00BuDRm7U/amlVIMCnm9/qZoIX/jolHLYzL1tNjJE1Dl7tF vQyiBnPBzxotpqMc1I+EkWWKx5x032X9F335wazK7p9o4MRlkpadjrfRig6RuCKH9CT4 Rmol74NIfo5Fb4DLdRbBipPtRUijxX1qVywKV2iEyawqOaf61X4eZEd5VjSzKDPVdOwi CWivDzpwVn1JPmthBdE+dvoXEYNU6V9ZfKebXhTFvPIoDegYK6sirZGgJHCwSp/98iwq qbqJ8P83vpdA1bd5gx/FFDuYS2fCr/ogGzyw4z2Xw+eevYwmn4fXPR93AwHCbxxYyY8h 8dPQ== X-Gm-Message-State: APjAAAUgFUmI+OIhG59NI+Zvs8pehCIgFVAGiq6T0IKk2XkiIEwJ9MV2 Go7fAnMKhKsMYH0VJIUaQnM= X-Google-Smtp-Source: APXvYqyqCK2pgNbDSWh5tfKVfkD1OLh24THmdaZzxauSeDG2Mm7+3YUTDtyZf8C5ZYbDUHkhAAYEqw== X-Received: by 2002:a17:902:988e:: with SMTP id s14mr22560082plp.167.1553662734795; Tue, 26 Mar 2019 21:58:54 -0700 (PDT) Received: from localhost.localdomain ([2001:268:c0a5:6014:c70:4af9:86e2:2]) by smtp.gmail.com with ESMTPSA id l19sm877015pff.1.2019.03.26.21.58.48 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Tue, 26 Mar 2019 21:58:54 -0700 (PDT) From: William Breathitt Gray To: linus.walleij@linaro.org, bgolaszewski@baylibre.com Subject: [PATCH v13 04/11] gpio: 104-idi-48: Utilize for_each_set_clump8 macro Date: Wed, 27 Mar 2019 13:59:50 +0900 Message-Id: <1476995eb0bf988b4a3cc27f0e5e1484933d93ec.1553661964.git.vilhelm.gray@gmail.com> X-Mailer: git-send-email 2.21.0 In-Reply-To: References: MIME-Version: 1.0 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20190326_215855_371379_D46A8E38 X-CRM114-Status: GOOD ( 14.39 ) X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: linux-arch@vger.kernel.org, preid@electromag.com.au, yamada.masahiro@socionext.com, linux-pm@vger.kernel.org, linux@rasmusvillemoes.dk, linux-kernel@vger.kernel.org, William Breathitt Gray , linux-gpio@vger.kernel.org, geert@linux-m68k.org, akpm@linux-foundation.org, andriy.shevchenko@linux.intel.com, linux-arm-kernel@lists.infradead.org Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+patchwork-linux-arm=patchwork.kernel.org@lists.infradead.org X-Virus-Scanned: ClamAV using ClamSMTP Replace verbose implementation in get_multiple/set_multiple callbacks with for_each_set_clump8 macro to simplify code and improve clarity. Reviewed-by: Linus Walleij Signed-off-by: William Breathitt Gray --- drivers/gpio/gpio-104-idi-48.c | 36 +++++++--------------------------- 1 file changed, 7 insertions(+), 29 deletions(-) diff --git a/drivers/gpio/gpio-104-idi-48.c b/drivers/gpio/gpio-104-idi-48.c index 88dc6f2449f6..9b43964b0412 100644 --- a/drivers/gpio/gpio-104-idi-48.c +++ b/drivers/gpio/gpio-104-idi-48.c @@ -93,42 +93,20 @@ static int idi_48_gpio_get_multiple(struct gpio_chip *chip, unsigned long *mask, unsigned long *bits) { struct idi_48_gpio *const idi48gpio = gpiochip_get_data(chip); - size_t i; + unsigned long offset; + unsigned long gpio_mask; static const size_t ports[] = { 0, 1, 2, 4, 5, 6 }; - const unsigned int gpio_reg_size = 8; - unsigned int bits_offset; - size_t word_index; - unsigned int word_offset; - unsigned long word_mask; - const unsigned long port_mask = GENMASK(gpio_reg_size - 1, 0); + unsigned int port_addr; unsigned long port_state; /* clear bits array to a clean slate */ bitmap_zero(bits, chip->ngpio); - /* get bits are evaluated a gpio port register at a time */ - for (i = 0; i < ARRAY_SIZE(ports); i++) { - /* gpio offset in bits array */ - bits_offset = i * gpio_reg_size; + for_each_set_clump8(offset, gpio_mask, mask, ARRAY_SIZE(ports) * 8) { + port_addr = idi48gpio->base + ports[offset / 8]; + port_state = inb(port_addr) & gpio_mask; - /* word index for bits array */ - word_index = BIT_WORD(bits_offset); - - /* gpio offset within current word of bits array */ - word_offset = bits_offset % BITS_PER_LONG; - - /* mask of get bits for current gpio within current word */ - word_mask = mask[word_index] & (port_mask << word_offset); - if (!word_mask) { - /* no get bits in this port so skip to next one */ - continue; - } - - /* read bits from current gpio port */ - port_state = inb(idi48gpio->base + ports[i]); - - /* store acquired bits at respective bits array offset */ - bits[word_index] |= (port_state << word_offset) & word_mask; + bitmap_set_value8(bits, port_state, offset); } return 0; From patchwork Wed Mar 27 05:00:10 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: William Breathitt Gray X-Patchwork-Id: 10872501 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 7C77E139A for ; Wed, 27 Mar 2019 04:59:26 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 5F28728758 for ; Wed, 27 Mar 2019 04:59:26 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 4DA40287BB; Wed, 27 Mar 2019 04:59:26 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-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 CD96528758 for ; Wed, 27 Mar 2019 04:59:25 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20170209; h=Sender: Content-Transfer-Encoding:Content-Type:Cc:List-Subscribe:List-Help:List-Post: List-Archive:List-Unsubscribe:List-Id:MIME-Version:References:In-Reply-To: Message-Id:Date:Subject:To:From:Reply-To:Content-ID:Content-Description: Resent-Date:Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID: List-Owner; bh=2aFOFeeqhEDbaSMUlHqhPoezYFoyIto7RGTWQetNonc=; b=F0h0YJm00nIxVp Z7sbOH2q6VsXucZ/lu52KpRM4ybOpEP7C2Yuzlx2R1qxLdqWFYDwpUPAReMQdiTgPQKKyTsT1hIqM LFnB09OmOo9EfKcTfwYzuH8jFKS3M07TXLgjoNM1r7fBhyUP6GLRUMYuGIgQf1bECSeNsf9wcfsCq WjWOxWnOZaESzvkgOjNUS9FGFEvO4WBx1ehgmGk575nTYejaB+Ws2TbxooRySmKbxh4YDaVMQdGTg ZhERgb/hSxOEbVNAsZPNjmxrjWuprdxML7wwvy9SgmvaFdy+QXiM3jQTZAzfkLkDP6/BzUPdtfhFs 8AJC9697ehEiW04LOP4A==; 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 1h90eq-0004tn-Hq; Wed, 27 Mar 2019 04:59:24 +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 1h90em-0004tA-3q for linux-arm-kernel@lists.infradead.org; Wed, 27 Mar 2019 04:59:22 +0000 Received: by mail-pf1-x444.google.com with SMTP id c207so9141468pfc.7 for ; Tue, 26 Mar 2019 21:59:20 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=gbLsQajapHp8yt8fkh0lWuCUAozPg7cvkSOmtAlT5GA=; b=HsXWqFbK4h2vjS6XbRFUkVqK7tZM6SdYfp0Z1hI0UP5TFv0G7nw4V/MGYYMPLzHMdx O6k2HEsdCsOH7n667eMxq2havDwD0uI+zY4sAJ/pagqecSOqmKy6HiTl4arijqQs06Dc zt5wteOtMGcJwO4wIm66boQPaD/6Um3Mv20wu+mi4w/qtj0tBRrWjcvjohoOW30lfauM PDiGQZXTLvmJD3gYP3yhKhni0JTSisUCUXD8xvE/DBOBy8BGqurnHvNNqPVNpdI+HTmA I7xwDxuLYlENM4mqGm8BxtzvA9sgaiYfVg5qUhYuExYLaPJR2j+7BN2NVrEpcRZmKGrM EK5Q== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=gbLsQajapHp8yt8fkh0lWuCUAozPg7cvkSOmtAlT5GA=; b=cZK9QHWQtUpIBhGH/zGdHQVxBdh6oIwNYVuekLsOrbFlVIZbbnkZ+3dFHhGzU8H3DT dWZiSVR+9fwA6ysHDd/dxTTsmW4AKN8qaUr5HXkVjiyZSdk8uAlwge6WGItNIomnjKfm OKcBwOn1BUZ96GStKsepC7geQ1ODEu+X8eB5mSN24Q9NKK5j2wu9FzeVsdlDiGUzw7s4 yOqev5eApwUXJX7DjFcVxTPyX44gE85R0GOS229O0YDOzxg3tWWn1ZhyVZ+9yeIIYAPs UrIgi+w15EpBL7FtKt9DWhHS/phJzUuLkaY8MZC2rXX8eXgRjzeo8t1lGtDZEZkMY02b 4MOg== X-Gm-Message-State: APjAAAX8amOPknGMa1dZKlXXPu6kStneS53l/i4qN1V7LEjkMnnzBC79 Phg6e5j0alDV1XFWygSaFFg= X-Google-Smtp-Source: APXvYqw9pqGDQLDvev7hWSvpe+IZ4GA3cqzDzC2rsG73IuYK6jyFsZLC/yydvfpq4ECwqpBO6ip3RA== X-Received: by 2002:a65:4844:: with SMTP id i4mr31635821pgs.347.1553662759269; Tue, 26 Mar 2019 21:59:19 -0700 (PDT) Received: from localhost.localdomain ([2001:268:c0a5:6014:c70:4af9:86e2:2]) by smtp.gmail.com with ESMTPSA id y12sm26769011pgq.64.2019.03.26.21.59.14 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Tue, 26 Mar 2019 21:59:18 -0700 (PDT) From: William Breathitt Gray To: linus.walleij@linaro.org, bgolaszewski@baylibre.com Subject: [PATCH v13 05/11] gpio: gpio-mm: Utilize for_each_set_clump8 macro Date: Wed, 27 Mar 2019 14:00:10 +0900 Message-Id: <09275d98903df1b8c43b7fb469f5bc1ea562285b.1553661964.git.vilhelm.gray@gmail.com> X-Mailer: git-send-email 2.21.0 In-Reply-To: References: MIME-Version: 1.0 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20190326_215920_166315_6761CEBA X-CRM114-Status: GOOD ( 14.55 ) X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: linux-arch@vger.kernel.org, preid@electromag.com.au, yamada.masahiro@socionext.com, linux-pm@vger.kernel.org, linux@rasmusvillemoes.dk, linux-kernel@vger.kernel.org, William Breathitt Gray , linux-gpio@vger.kernel.org, geert@linux-m68k.org, akpm@linux-foundation.org, andriy.shevchenko@linux.intel.com, linux-arm-kernel@lists.infradead.org Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+patchwork-linux-arm=patchwork.kernel.org@lists.infradead.org X-Virus-Scanned: ClamAV using ClamSMTP Replace verbose implementation in get_multiple/set_multiple callbacks with for_each_set_clump8 macro to simplify code and improve clarity. Reviewed-by: Linus Walleij Signed-off-by: William Breathitt Gray --- drivers/gpio/gpio-gpio-mm.c | 73 +++++++++++-------------------------- 1 file changed, 21 insertions(+), 52 deletions(-) diff --git a/drivers/gpio/gpio-gpio-mm.c b/drivers/gpio/gpio-gpio-mm.c index 8c150fd68d9d..0cef50d14c5a 100644 --- a/drivers/gpio/gpio-gpio-mm.c +++ b/drivers/gpio/gpio-gpio-mm.c @@ -172,46 +172,25 @@ static int gpiomm_gpio_get(struct gpio_chip *chip, unsigned int offset) return !!(port_state & mask); } +static const size_t ports[] = { 0, 1, 2, 4, 5, 6 }; + static int gpiomm_gpio_get_multiple(struct gpio_chip *chip, unsigned long *mask, unsigned long *bits) { struct gpiomm_gpio *const gpiommgpio = gpiochip_get_data(chip); - size_t i; - static const size_t ports[] = { 0, 1, 2, 4, 5, 6 }; - const unsigned int gpio_reg_size = 8; - unsigned int bits_offset; - size_t word_index; - unsigned int word_offset; - unsigned long word_mask; - const unsigned long port_mask = GENMASK(gpio_reg_size - 1, 0); + unsigned long offset; + unsigned long gpio_mask; + unsigned int port_addr; unsigned long port_state; /* clear bits array to a clean slate */ bitmap_zero(bits, chip->ngpio); - /* get bits are evaluated a gpio port register at a time */ - for (i = 0; i < ARRAY_SIZE(ports); i++) { - /* gpio offset in bits array */ - bits_offset = i * gpio_reg_size; - - /* word index for bits array */ - word_index = BIT_WORD(bits_offset); - - /* gpio offset within current word of bits array */ - word_offset = bits_offset % BITS_PER_LONG; - - /* mask of get bits for current gpio within current word */ - word_mask = mask[word_index] & (port_mask << word_offset); - if (!word_mask) { - /* no get bits in this port so skip to next one */ - continue; - } - - /* read bits from current gpio port */ - port_state = inb(gpiommgpio->base + ports[i]); + for_each_set_clump8(offset, gpio_mask, mask, ARRAY_SIZE(ports) * 8) { + port_addr = gpiommgpio->base + ports[offset / 8]; + port_state = inb(port_addr) & gpio_mask; - /* store acquired bits at respective bits array offset */ - bits[word_index] |= (port_state << word_offset) & word_mask; + bitmap_set_value8(bits, port_state, offset); } return 0; @@ -242,37 +221,27 @@ static void gpiomm_gpio_set_multiple(struct gpio_chip *chip, unsigned long *mask, unsigned long *bits) { struct gpiomm_gpio *const gpiommgpio = gpiochip_get_data(chip); - unsigned int i; - const unsigned int gpio_reg_size = 8; - unsigned int port; - unsigned int out_port; - unsigned int bitmask; + unsigned long offset; + unsigned long gpio_mask; + size_t index; + unsigned int port_addr; + unsigned long bitmask; unsigned long flags; - /* set bits are evaluated a gpio register size at a time */ - for (i = 0; i < chip->ngpio; i += gpio_reg_size) { - /* no more set bits in this mask word; skip to the next word */ - if (!mask[BIT_WORD(i)]) { - i = (BIT_WORD(i) + 1) * BITS_PER_LONG - gpio_reg_size; - continue; - } + for_each_set_clump8(offset, gpio_mask, mask, ARRAY_SIZE(ports) * 8) { + index = offset / 8; + port_addr = gpiommgpio->base + ports[index]; - port = i / gpio_reg_size; - out_port = (port > 2) ? port + 1 : port; - bitmask = mask[BIT_WORD(i)] & bits[BIT_WORD(i)]; + bitmask = bitmap_get_value8(bits, offset) & gpio_mask; spin_lock_irqsave(&gpiommgpio->lock, flags); /* update output state data and set device gpio register */ - gpiommgpio->out_state[port] &= ~mask[BIT_WORD(i)]; - gpiommgpio->out_state[port] |= bitmask; - outb(gpiommgpio->out_state[port], gpiommgpio->base + out_port); + gpiommgpio->out_state[index] &= ~gpio_mask; + gpiommgpio->out_state[index] |= bitmask; + outb(gpiommgpio->out_state[index], port_addr); spin_unlock_irqrestore(&gpiommgpio->lock, flags); - - /* prepare for next gpio register set */ - mask[BIT_WORD(i)] >>= gpio_reg_size; - bits[BIT_WORD(i)] >>= gpio_reg_size; } } From patchwork Wed Mar 27 05:00:34 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: William Breathitt Gray X-Patchwork-Id: 10872507 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 ABB7F14DE for ; Wed, 27 Mar 2019 04:59:47 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 9248128758 for ; Wed, 27 Mar 2019 04:59:47 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 8615C28C19; Wed, 27 Mar 2019 04:59:47 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-5.2 required=2.0 tests=BAYES_00,DKIM_ADSP_CUSTOM_MED, DKIM_SIGNED,DKIM_VALID,FREEMAIL_FROM,MAILING_LIST_MULTI,RCVD_IN_DNSWL_MED autolearn=unavailable version=3.3.1 Received: from bombadil.infradead.org (bombadil.infradead.org [198.137.202.133]) (using TLSv1.2 with cipher AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.wl.linuxfoundation.org (Postfix) with ESMTPS id 0785128758 for ; Wed, 27 Mar 2019 04:59:47 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20170209; h=Sender: Content-Transfer-Encoding:Content-Type:Cc:List-Subscribe:List-Help:List-Post: List-Archive:List-Unsubscribe:List-Id:MIME-Version:References:In-Reply-To: Message-Id:Date:Subject:To:From:Reply-To:Content-ID:Content-Description: Resent-Date:Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID: List-Owner; bh=rm5LNNGDjLJSmM1BSkm3XR7tYj1ijQezLBd0obXUdG0=; b=MP3qYJTD9Koe/d ZUX0PIh8qz79iasFqllb8tehmkUurxvoa+vmC2GqfA4E9oyyiQklL4EIBG/+M/+pZS1iiobbQydjP tKTDyHNbzEpz5T5jNv6GZrYnjNY8d23JFG0WJ2aWWtS2dNDCAi0pZEMu3v+dyiO3ptpcvlaUE3WSU +MCd4qqJLo7s/219SiDfZEry1ffZ2omsBfYu5tBJXrLSu11r9OEOCHXNKDsTZBRV72uhv3FGSoLbP 56X4AtZoNSfnOSaFftIi2wAjeK+k8HhOrgi1d9qmVcw/t9ZwZcXjoSUZSlIKrX8TK4BjPIuvzH8yG YTalPJMlSTcun0kxl8JQ==; 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 1h90fA-0005A1-Uq; Wed, 27 Mar 2019 04:59:44 +0000 Received: from mail-pf1-x441.google.com ([2607:f8b0:4864:20::441]) by bombadil.infradead.org with esmtps (Exim 4.90_1 #2 (Red Hat Linux)) id 1h90f7-000596-3L for linux-arm-kernel@lists.infradead.org; Wed, 27 Mar 2019 04:59:42 +0000 Received: by mail-pf1-x441.google.com with SMTP id c8so9126223pfd.10 for ; Tue, 26 Mar 2019 21:59:41 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=qhXdbnOxR8IcT7b6oZcrLksWSW3Riv+VrvVQHErm2EM=; b=gwEAP9GrydoTtYhHNr0uqtkUfGhqgQ3kbw57kbahUFeIbfZeHOMgcy1OtYqzNQ9Rik ZAD+/ZqVyx2J9eLSc8cQCE3fFQTIzuH6cLczCYkXI2iFqSqJVUh1v/IS2Z3L5/HwIx3C zY/tB9SFGwusVeEENOQ/QqrbSsdKIUXcqYO0QiCySOrZmgYlIMZ2vLuNxJdYUeM0Oh03 p6QabOfXbwB16Ut9MNOl/a5mOWGJ0udnMPlrjuUJIhLdt/wWGM9H89KBT+qR/cOVrx+N WqSHnYENCPuKZyVLhal2Qr/zg0ujZAr4dqDFMWiruHdfj0C4HI5mg9gu66GcDt7RklHZ 7NUA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=qhXdbnOxR8IcT7b6oZcrLksWSW3Riv+VrvVQHErm2EM=; b=Mkr4mzW9laSglvpJ96qDB1fqgZHkOdvsyy5Zafrc+PBUyCBgDRpH98+SWdxWFp3mZ0 ST3E+Mq2OXVwbDYhPdvO0Sq9F0J9C0bEcv4lG5mU0eCRraZOPbaB2uh1rBlzB0piYclK tMg4V3isAwyYPRboAGuJP3iLgkpXYVJaYaIvuDZz0Q/XF6Tr8TMC/W11+SvtNVbIZhuH w3nxqqCqbmJvTpM4HH/93Pl30EKRVwDT+5fkpb4HpVzJTaLaooSDVtgtcJ75VkYACSKY vNG5HeF/G2I93otMJcefAaX6F2DvlUhdc3drW1m5VcJer5V/Opa/+HB0aqX3yENFs5rd RFnQ== X-Gm-Message-State: APjAAAVB0ktVyCne7uVXC3p/Vyl9qlgnFCnwAUkL1mvYkyKpqErCJTQE YO32UHRc4vCaRbDQGGB+C3I= X-Google-Smtp-Source: APXvYqxa/iVOaeCWIDM9+3BJzH8fnANPK5Yqmrl2pniOvStbPri0TqYEZgBlq4j/FXknWDG2+dG5zQ== X-Received: by 2002:a62:5543:: with SMTP id j64mr33305459pfb.105.1553662778635; Tue, 26 Mar 2019 21:59:38 -0700 (PDT) Received: from localhost.localdomain ([2001:268:c0a5:6014:c70:4af9:86e2:2]) by smtp.gmail.com with ESMTPSA id p86sm35800592pfa.104.2019.03.26.21.59.31 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Tue, 26 Mar 2019 21:59:38 -0700 (PDT) From: William Breathitt Gray To: linus.walleij@linaro.org, bgolaszewski@baylibre.com Subject: [PATCH v13 06/11] gpio: ws16c48: Utilize for_each_set_clump8 macro Date: Wed, 27 Mar 2019 14:00:34 +0900 Message-Id: <728fe1eccac5117aa1c61bfa1003366b511d9d58.1553661964.git.vilhelm.gray@gmail.com> X-Mailer: git-send-email 2.21.0 In-Reply-To: References: MIME-Version: 1.0 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20190326_215941_213128_6123C9DE X-CRM114-Status: GOOD ( 14.87 ) X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: linux-arch@vger.kernel.org, preid@electromag.com.au, yamada.masahiro@socionext.com, linux-pm@vger.kernel.org, linux@rasmusvillemoes.dk, linux-kernel@vger.kernel.org, William Breathitt Gray , linux-gpio@vger.kernel.org, geert@linux-m68k.org, akpm@linux-foundation.org, andriy.shevchenko@linux.intel.com, linux-arm-kernel@lists.infradead.org Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+patchwork-linux-arm=patchwork.kernel.org@lists.infradead.org X-Virus-Scanned: ClamAV using ClamSMTP Replace verbose implementation in get_multiple/set_multiple callbacks with for_each_set_clump8 macro to simplify code and improve clarity. Reviewed-by: Linus Walleij Signed-off-by: William Breathitt Gray --- drivers/gpio/gpio-ws16c48.c | 73 ++++++++++--------------------------- 1 file changed, 20 insertions(+), 53 deletions(-) diff --git a/drivers/gpio/gpio-ws16c48.c b/drivers/gpio/gpio-ws16c48.c index 5cf3697bfb15..ee30417d6394 100644 --- a/drivers/gpio/gpio-ws16c48.c +++ b/drivers/gpio/gpio-ws16c48.c @@ -134,42 +134,19 @@ static int ws16c48_gpio_get_multiple(struct gpio_chip *chip, unsigned long *mask, unsigned long *bits) { struct ws16c48_gpio *const ws16c48gpio = gpiochip_get_data(chip); - const unsigned int gpio_reg_size = 8; - size_t i; - const size_t num_ports = chip->ngpio / gpio_reg_size; - unsigned int bits_offset; - size_t word_index; - unsigned int word_offset; - unsigned long word_mask; - const unsigned long port_mask = GENMASK(gpio_reg_size - 1, 0); + unsigned long offset; + unsigned long gpio_mask; + unsigned int port_addr; unsigned long port_state; /* clear bits array to a clean slate */ bitmap_zero(bits, chip->ngpio); - /* get bits are evaluated a gpio port register at a time */ - for (i = 0; i < num_ports; i++) { - /* gpio offset in bits array */ - bits_offset = i * gpio_reg_size; + for_each_set_clump8(offset, gpio_mask, mask, chip->ngpio) { + port_addr = ws16c48gpio->base + offset / 8; + port_state = inb(port_addr) & gpio_mask; - /* word index for bits array */ - word_index = BIT_WORD(bits_offset); - - /* gpio offset within current word of bits array */ - word_offset = bits_offset % BITS_PER_LONG; - - /* mask of get bits for current gpio within current word */ - word_mask = mask[word_index] & (port_mask << word_offset); - if (!word_mask) { - /* no get bits in this port so skip to next one */ - continue; - } - - /* read bits from current gpio port */ - port_state = inb(ws16c48gpio->base + i); - - /* store acquired bits at respective bits array offset */ - bits[word_index] |= (port_state << word_offset) & word_mask; + bitmap_set_value8(bits, port_state, offset); } return 0; @@ -203,39 +180,29 @@ static void ws16c48_gpio_set_multiple(struct gpio_chip *chip, unsigned long *mask, unsigned long *bits) { struct ws16c48_gpio *const ws16c48gpio = gpiochip_get_data(chip); - unsigned int i; - const unsigned int gpio_reg_size = 8; - unsigned int port; - unsigned int iomask; - unsigned int bitmask; + unsigned long offset; + unsigned long gpio_mask; + size_t index; + unsigned int port_addr; + unsigned long bitmask; unsigned long flags; - /* set bits are evaluated a gpio register size at a time */ - for (i = 0; i < chip->ngpio; i += gpio_reg_size) { - /* no more set bits in this mask word; skip to the next word */ - if (!mask[BIT_WORD(i)]) { - i = (BIT_WORD(i) + 1) * BITS_PER_LONG - gpio_reg_size; - continue; - } - - port = i / gpio_reg_size; + for_each_set_clump8(offset, gpio_mask, mask, chip->ngpio) { + index = offset / 8; + port_addr = ws16c48gpio->base + index; /* mask out GPIO configured for input */ - iomask = mask[BIT_WORD(i)] & ~ws16c48gpio->io_state[port]; - bitmask = iomask & bits[BIT_WORD(i)]; + gpio_mask &= ~ws16c48gpio->io_state[index]; + bitmask = bitmap_get_value8(bits, offset) & gpio_mask; raw_spin_lock_irqsave(&ws16c48gpio->lock, flags); /* update output state data and set device gpio register */ - ws16c48gpio->out_state[port] &= ~iomask; - ws16c48gpio->out_state[port] |= bitmask; - outb(ws16c48gpio->out_state[port], ws16c48gpio->base + port); + ws16c48gpio->out_state[index] &= ~gpio_mask; + ws16c48gpio->out_state[index] |= bitmask; + outb(ws16c48gpio->out_state[index], port_addr); raw_spin_unlock_irqrestore(&ws16c48gpio->lock, flags); - - /* prepare for next gpio register set */ - mask[BIT_WORD(i)] >>= gpio_reg_size; - bits[BIT_WORD(i)] >>= gpio_reg_size; } } From patchwork Wed Mar 27 05:00:53 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: William Breathitt Gray X-Patchwork-Id: 10872511 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 65693925 for ; Wed, 27 Mar 2019 05:00:09 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 4AF8828758 for ; Wed, 27 Mar 2019 05:00:09 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 3D1ED28C19; Wed, 27 Mar 2019 05:00:09 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-5.2 required=2.0 tests=BAYES_00,DKIM_ADSP_CUSTOM_MED, DKIM_SIGNED,DKIM_VALID,FREEMAIL_FROM,MAILING_LIST_MULTI,RCVD_IN_DNSWL_MED autolearn=unavailable version=3.3.1 Received: from bombadil.infradead.org (bombadil.infradead.org [198.137.202.133]) (using TLSv1.2 with cipher AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.wl.linuxfoundation.org (Postfix) with ESMTPS id C641728758 for ; Wed, 27 Mar 2019 05:00:08 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20170209; h=Sender: Content-Transfer-Encoding:Content-Type:Cc:List-Subscribe:List-Help:List-Post: List-Archive:List-Unsubscribe:List-Id:MIME-Version:References:In-Reply-To: Message-Id:Date:Subject:To:From:Reply-To:Content-ID:Content-Description: Resent-Date:Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID: List-Owner; bh=Uwq6vjS7DQSvAAzgUJDxTE+siGNtTkY5vjN5J4XC0Ek=; b=ia6Xhx1g+UTMAC aDHfH2zkRWIZBc+ZN5cpi6qukjFRdQt6wWGquru/b+NFq/nMZf4xvI+/EYKaPX+B54mx2DsIu+lbb KAvwbp3yKgTUK77GclCSoTGvgVWmTwhgVe36lv8Pk3ayUl+2J7+OVg58dzQYHi18lSwdjjveiE6aF s9w/ikZFwUY43QnEeOEzy0Y62Ef73LYe/MCLnppLNNk8fnq7GSiVPWVfMwrH5LxMGHenqys3LmaIj 6ziqaZhaGtLzOe3AT23dnl9BHsxeUnsc7zGyOVX7N9p635nJ6661q2BI6y5zP0r6n7iCDatv5Bdpq UBmqikKq3qN3NjrPxOOw==; 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 1h90fV-0005ck-GB; Wed, 27 Mar 2019 05:00:05 +0000 Received: from mail-pf1-x442.google.com ([2607:f8b0:4864:20::442]) by bombadil.infradead.org with esmtps (Exim 4.90_1 #2 (Red Hat Linux)) id 1h90fP-0005OK-V6 for linux-arm-kernel@lists.infradead.org; Wed, 27 Mar 2019 05:00:02 +0000 Received: by mail-pf1-x442.google.com with SMTP id i19so504681pfd.0 for ; Tue, 26 Mar 2019 21:59:59 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=PqXTy5leW1u0qHG2FvwK5coDmQU6qYHNOD3tv8uuTcU=; b=ac50dJOb//RJN+hEGpzU97wnNrD9H4Cs+VgJS1YC9zsDxjW95Zc/Wir7tFfZj3yjoy MahuXnpxy6qn5tQ8zYZduAgEgxe8DTPWE1S9q5Cq0e8JoWXAjLQyPPVLfOWCNyeVyNbV qo49esRcIfNy59iOhau9RHOKKUA517hzZeXBmdZQSi0mEKwCORqQAxYbIIAkRt3hG/x9 H5FqXgODbwy0ZFk0c2smbvgeLTFlBh4RMqg1WhRZEUEwlnfZYZMxI3lUbeB2qrou0gWE CobkMtXmj1nknn4rxCQv3xn6frKiDiEXUv+4kEaXMel+saRHNo0csLh3GvvxHoSQuMfq fAxQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=PqXTy5leW1u0qHG2FvwK5coDmQU6qYHNOD3tv8uuTcU=; b=oELuGZGakx1XM+V4eP5Bw1+RpXyf+36uQLU1rP1TjnCN6XHKqSz9xqTyUIFr7sJXk5 Y85sJqOwqruEDnoI1Rhk3yuZzPAy/8HPHTctA8UvgmhTGEqvd9x2V1CPm2ngqGdo67FN PYpP0JVe3bmFbBL9VktQCJf7PB9HR8lqHsoSCHiup+hxLjUhSUrLh2r5kvuKpFtgkJgH yLkEwW0gd7JG3wMDdagOz0myudFBDpT8kxEjixwVqYE7/svwixlHuEzRWvVjErjiZfgD N5S8+rB4RM7wM9mRfyQ2DY6DtNkva9Ia3Dc3V79cg+gFGyLjlujU39fW1+zpcd7uOJOx 6q1A== X-Gm-Message-State: APjAAAVYcZ+ZoCG3caPzLml1v+jMwUv/tADROhQ3+MOlc+LRcdVMDAq+ cqMriCt/suWiGUHFmoJJFzY= X-Google-Smtp-Source: APXvYqwyrim8K8IdJ/eBKlgxpvfqB1BoJjWgqgKxJB76F8yWv7xE74d9bC3gvfz6CJUQfHoTmC+acg== X-Received: by 2002:a63:1064:: with SMTP id 36mr5257983pgq.155.1553662798642; Tue, 26 Mar 2019 21:59:58 -0700 (PDT) Received: from localhost.localdomain ([2001:268:c0a5:6014:c70:4af9:86e2:2]) by smtp.gmail.com with ESMTPSA id g73sm1086022pfd.185.2019.03.26.21.59.51 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Tue, 26 Mar 2019 21:59:58 -0700 (PDT) From: William Breathitt Gray To: linus.walleij@linaro.org, bgolaszewski@baylibre.com Subject: [PATCH v13 07/11] gpio: pci-idio-16: Utilize for_each_set_clump8 macro Date: Wed, 27 Mar 2019 14:00:53 +0900 Message-Id: <4698abb45402d0671e0400be7133e3ccdc2b9fe1.1553661964.git.vilhelm.gray@gmail.com> X-Mailer: git-send-email 2.21.0 In-Reply-To: References: MIME-Version: 1.0 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20190326_215959_998221_135C83BB X-CRM114-Status: GOOD ( 14.93 ) X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: linux-arch@vger.kernel.org, preid@electromag.com.au, yamada.masahiro@socionext.com, linux-pm@vger.kernel.org, linux@rasmusvillemoes.dk, linux-kernel@vger.kernel.org, William Breathitt Gray , linux-gpio@vger.kernel.org, geert@linux-m68k.org, akpm@linux-foundation.org, andriy.shevchenko@linux.intel.com, linux-arm-kernel@lists.infradead.org Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+patchwork-linux-arm=patchwork.kernel.org@lists.infradead.org X-Virus-Scanned: ClamAV using ClamSMTP Replace verbose implementation in get_multiple/set_multiple callbacks with for_each_set_clump8 macro to simplify code and improve clarity. Reviewed-by: Linus Walleij Signed-off-by: William Breathitt Gray --- drivers/gpio/gpio-pci-idio-16.c | 75 ++++++++++++--------------------- 1 file changed, 27 insertions(+), 48 deletions(-) diff --git a/drivers/gpio/gpio-pci-idio-16.c b/drivers/gpio/gpio-pci-idio-16.c index 6b7349783223..a67388db28ad 100644 --- a/drivers/gpio/gpio-pci-idio-16.c +++ b/drivers/gpio/gpio-pci-idio-16.c @@ -108,45 +108,23 @@ static int idio_16_gpio_get_multiple(struct gpio_chip *chip, unsigned long *mask, unsigned long *bits) { struct idio_16_gpio *const idio16gpio = gpiochip_get_data(chip); - size_t i; - const unsigned int gpio_reg_size = 8; - unsigned int bits_offset; - size_t word_index; - unsigned int word_offset; - unsigned long word_mask; - const unsigned long port_mask = GENMASK(gpio_reg_size - 1, 0); - unsigned long port_state; + unsigned long offset; + unsigned long gpio_mask; void __iomem *ports[] = { &idio16gpio->reg->out0_7, &idio16gpio->reg->out8_15, &idio16gpio->reg->in0_7, &idio16gpio->reg->in8_15, }; + void __iomem *port_addr; + unsigned long port_state; /* clear bits array to a clean slate */ bitmap_zero(bits, chip->ngpio); - /* get bits are evaluated a gpio port register at a time */ - for (i = 0; i < ARRAY_SIZE(ports); i++) { - /* gpio offset in bits array */ - bits_offset = i * gpio_reg_size; - - /* word index for bits array */ - word_index = BIT_WORD(bits_offset); - - /* gpio offset within current word of bits array */ - word_offset = bits_offset % BITS_PER_LONG; - - /* mask of get bits for current gpio within current word */ - word_mask = mask[word_index] & (port_mask << word_offset); - if (!word_mask) { - /* no get bits in this port so skip to next one */ - continue; - } + for_each_set_clump8(offset, gpio_mask, mask, ARRAY_SIZE(ports) * 8) { + port_addr = ports[offset / 8]; + port_state = ioread8(port_addr) & gpio_mask; - /* read bits from current gpio port */ - port_state = ioread8(ports[i]); - - /* store acquired bits at respective bits array offset */ - bits[word_index] |= (port_state << word_offset) & word_mask; + bitmap_set_value8(bits, port_state, offset); } return 0; @@ -186,30 +164,31 @@ static void idio_16_gpio_set_multiple(struct gpio_chip *chip, unsigned long *mask, unsigned long *bits) { struct idio_16_gpio *const idio16gpio = gpiochip_get_data(chip); + unsigned long offset; + unsigned long gpio_mask; + void __iomem *ports[] = { + &idio16gpio->reg->out0_7, &idio16gpio->reg->out8_15, + }; + size_t index; + void __iomem *port_addr; + unsigned long bitmask; unsigned long flags; - unsigned int out_state; + unsigned long out_state; - raw_spin_lock_irqsave(&idio16gpio->lock, flags); + for_each_set_clump8(offset, gpio_mask, mask, ARRAY_SIZE(ports) * 8) { + index = offset / 8; + port_addr = ports[index]; - /* process output lines 0-7 */ - if (*mask & 0xFF) { - out_state = ioread8(&idio16gpio->reg->out0_7) & ~*mask; - out_state |= *mask & *bits; - iowrite8(out_state, &idio16gpio->reg->out0_7); - } + bitmask = bitmap_get_value8(bits, offset) & gpio_mask; + + raw_spin_lock_irqsave(&idio16gpio->lock, flags); - /* shift to next output line word */ - *mask >>= 8; + out_state = ioread8(port_addr) & ~gpio_mask; + out_state |= bitmask; + iowrite8(out_state, port_addr); - /* process output lines 8-15 */ - if (*mask & 0xFF) { - *bits >>= 8; - out_state = ioread8(&idio16gpio->reg->out8_15) & ~*mask; - out_state |= *mask & *bits; - iowrite8(out_state, &idio16gpio->reg->out8_15); + raw_spin_unlock_irqrestore(&idio16gpio->lock, flags); } - - raw_spin_unlock_irqrestore(&idio16gpio->lock, flags); } static void idio_16_irq_ack(struct irq_data *data) From patchwork Wed Mar 27 05:01:13 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: William Breathitt Gray X-Patchwork-Id: 10872515 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 C7DE2139A for ; Wed, 27 Mar 2019 05:00:27 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id AD95B28758 for ; Wed, 27 Mar 2019 05:00:27 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id A1B6D28C19; Wed, 27 Mar 2019 05:00:27 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-5.2 required=2.0 tests=BAYES_00,DKIM_ADSP_CUSTOM_MED, DKIM_SIGNED,DKIM_VALID,FREEMAIL_FROM,MAILING_LIST_MULTI,RCVD_IN_DNSWL_MED autolearn=unavailable version=3.3.1 Received: from bombadil.infradead.org (bombadil.infradead.org [198.137.202.133]) (using TLSv1.2 with cipher AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.wl.linuxfoundation.org (Postfix) with ESMTPS id 34B2E28758 for ; Wed, 27 Mar 2019 05:00:27 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20170209; h=Sender: Content-Transfer-Encoding:Content-Type:Cc:List-Subscribe:List-Help:List-Post: List-Archive:List-Unsubscribe:List-Id:MIME-Version:References:In-Reply-To: Message-Id:Date:Subject:To:From:Reply-To:Content-ID:Content-Description: Resent-Date:Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID: List-Owner; bh=fdEjYvFxJwb4pV5EOt/GjSw5Rd8wLETkJjg9NfJDyNk=; b=TrenqmZWKfMsPl R+Iv80BYbdNxPctwv8NJeCSMICEzFJRdeMRK63CYjoLidXth86MYAm9fXuIecfhMDbGnWRBMDI3ss AxF8fxJV/1s+6McGG3svwJ1DxGsS4+pty8hNxA2QqFg4OuOV0+Da2b0nrNOYbNzSYrOLE/Kr55524 HnBMwoeYUXS1VASmLpWu6eatcm69M2Sv9tCOS4A9MHu88bOMC1ge1hX0hdGSvB/YpmTTK1+0SkgXI 6a/gxlhLT/eiy1RHxSWQQzHIB0+SJ4ZdlaRluQt5gHZNUTV715UhJCU3jSBIgl/6FiIyVPt5Vly2W AuXZMRG5Ca/6LDO+feew==; 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 1h90fo-0006we-Sm; Wed, 27 Mar 2019 05:00:24 +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 1h90fk-0006vC-JW for linux-arm-kernel@lists.infradead.org; Wed, 27 Mar 2019 05:00:22 +0000 Received: by mail-pg1-x544.google.com with SMTP id b12so9382866pgk.0 for ; Tue, 26 Mar 2019 22:00:20 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=OkTwC9+bMfKIv7o0Jn0YcCWU1jhpVQZU39lRVQzfxwM=; b=kLby6UMMUISj9YX3QMOybUionexQpzW4Cnh9y8rHOG0lTQidh8H25i2C2nMCxgT+iR B6cOJUpNVrUL32UMZN5gUFBPXr+nm/LKXbnXE/MURr6L8Co7zasVkTAfWOStrTb6LFMn DhIa7tHG9GpyOOZu+6SQkDwgH/bulkp7GTAdYr+J19HxbYw14DRSWej/fk1oPKmqtHQ9 dhcOYIzhPEugC7fX9og+6X+JYD078OY+GqYmnoqNInAZI0SDPI1YLuCVGnlGvKgqDgnh pGamrec1z4Yrez30Ey884dWgAzeMafuBYEhrfhTs4/0xDzKsBSH8w0tPi7n6OUEN7Q19 BEXA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=OkTwC9+bMfKIv7o0Jn0YcCWU1jhpVQZU39lRVQzfxwM=; b=SwW6ae5ZL9OhBwSK9zrUsQXi6n4v8s2ocX7W5Auv8v9sd0646ONEYh5T9Oyj/4c5wq p+qCS+OmNYzq2Qbl1cKPZh9mNU64mKRukp7A4V4UszE654TR2u5LBF0fMK3JW1qrhPAK ANIcqpJd+MDSmbNXEEMGeDzWq8sSpsXRp6Y/qa8xB/jkE7krzEWoi3Ox5I6YjV2PbzbS dc8XnUa4Gr/ETmBjcLP7hjOjxH7qR+z3lGwhbcJpN6KzRnb5MrWjQ0dXY8GAsj6gfGSC GrXMkLuJFTpv8Qd7aCXQA2AOH8lc5JUWqzvmgVUxjWB2/mzO80pz2izejPRXmfDv6alR eLIA== X-Gm-Message-State: APjAAAUTs6xXo4dWsbiDKtFlRv3YGNZm7tynNJ58/LmQqPGKf5zwXH0i CVkeQf1XjoFhRf9RHj8dXBI= X-Google-Smtp-Source: APXvYqz1kD55kg6GG7SDVFuBdsfAb/ei7DPNUHoceb7E6zL086rWJB2GQiYauDMqiz2ujovfzzNQvw== X-Received: by 2002:a63:570d:: with SMTP id l13mr24905748pgb.55.1553662820110; Tue, 26 Mar 2019 22:00:20 -0700 (PDT) Received: from localhost.localdomain ([2001:268:c0a5:6014:c70:4af9:86e2:2]) by smtp.gmail.com with ESMTPSA id e15sm28629604pgk.30.2019.03.26.22.00.15 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Tue, 26 Mar 2019 22:00:19 -0700 (PDT) From: William Breathitt Gray To: linus.walleij@linaro.org, bgolaszewski@baylibre.com Subject: [PATCH v13 08/11] gpio: pcie-idio-24: Utilize for_each_set_clump8 macro Date: Wed, 27 Mar 2019 14:01:13 +0900 Message-Id: <93e629552491a546c838519ee3b0dbe4bc08f3ed.1553661964.git.vilhelm.gray@gmail.com> X-Mailer: git-send-email 2.21.0 In-Reply-To: References: MIME-Version: 1.0 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20190326_220020_665803_0CD7C69C X-CRM114-Status: GOOD ( 16.59 ) X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: linux-arch@vger.kernel.org, preid@electromag.com.au, yamada.masahiro@socionext.com, linux-pm@vger.kernel.org, linux@rasmusvillemoes.dk, linux-kernel@vger.kernel.org, William Breathitt Gray , linux-gpio@vger.kernel.org, geert@linux-m68k.org, akpm@linux-foundation.org, andriy.shevchenko@linux.intel.com, linux-arm-kernel@lists.infradead.org Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+patchwork-linux-arm=patchwork.kernel.org@lists.infradead.org X-Virus-Scanned: ClamAV using ClamSMTP Replace verbose implementation in get_multiple/set_multiple callbacks with for_each_set_clump8 macro to simplify code and improve clarity. Reviewed-by: Linus Walleij Signed-off-by: William Breathitt Gray --- drivers/gpio/gpio-pcie-idio-24.c | 109 ++++++++++++------------------- 1 file changed, 40 insertions(+), 69 deletions(-) diff --git a/drivers/gpio/gpio-pcie-idio-24.c b/drivers/gpio/gpio-pcie-idio-24.c index 52f1647a46fd..924ec916b358 100644 --- a/drivers/gpio/gpio-pcie-idio-24.c +++ b/drivers/gpio/gpio-pcie-idio-24.c @@ -198,52 +198,34 @@ static int idio_24_gpio_get_multiple(struct gpio_chip *chip, unsigned long *mask, unsigned long *bits) { struct idio_24_gpio *const idio24gpio = gpiochip_get_data(chip); - size_t i; - const unsigned int gpio_reg_size = 8; - unsigned int bits_offset; - size_t word_index; - unsigned int word_offset; - unsigned long word_mask; - const unsigned long port_mask = GENMASK(gpio_reg_size - 1, 0); - unsigned long port_state; + unsigned long offset; + unsigned long gpio_mask; void __iomem *ports[] = { &idio24gpio->reg->out0_7, &idio24gpio->reg->out8_15, &idio24gpio->reg->out16_23, &idio24gpio->reg->in0_7, &idio24gpio->reg->in8_15, &idio24gpio->reg->in16_23, }; + size_t index; + unsigned long port_state; const unsigned long out_mode_mask = BIT(1); /* clear bits array to a clean slate */ bitmap_zero(bits, chip->ngpio); - /* get bits are evaluated a gpio port register at a time */ - for (i = 0; i < ARRAY_SIZE(ports) + 1; i++) { - /* gpio offset in bits array */ - bits_offset = i * gpio_reg_size; - - /* word index for bits array */ - word_index = BIT_WORD(bits_offset); - - /* gpio offset within current word of bits array */ - word_offset = bits_offset % BITS_PER_LONG; - - /* mask of get bits for current gpio within current word */ - word_mask = mask[word_index] & (port_mask << word_offset); - if (!word_mask) { - /* no get bits in this port so skip to next one */ - continue; - } + for_each_set_clump8(offset, gpio_mask, mask, ARRAY_SIZE(ports) * 8) { + index = offset / 8; /* read bits from current gpio port (port 6 is TTL GPIO) */ - if (i < 6) - port_state = ioread8(ports[i]); + if (index < 6) + port_state = ioread8(ports[index]); else if (ioread8(&idio24gpio->reg->ctl) & out_mode_mask) port_state = ioread8(&idio24gpio->reg->ttl_out0_7); else port_state = ioread8(&idio24gpio->reg->ttl_in0_7); - /* store acquired bits at respective bits array offset */ - bits[word_index] |= (port_state << word_offset) & word_mask; + port_state &= gpio_mask; + + bitmap_set_value8(bits, port_state, offset); } return 0; @@ -294,59 +276,48 @@ static void idio_24_gpio_set_multiple(struct gpio_chip *chip, unsigned long *mask, unsigned long *bits) { struct idio_24_gpio *const idio24gpio = gpiochip_get_data(chip); - size_t i; - unsigned long bits_offset; + unsigned long offset; unsigned long gpio_mask; - const unsigned int gpio_reg_size = 8; - const unsigned long port_mask = GENMASK(gpio_reg_size, 0); - unsigned long flags; - unsigned int out_state; void __iomem *ports[] = { &idio24gpio->reg->out0_7, &idio24gpio->reg->out8_15, &idio24gpio->reg->out16_23 }; + size_t index; + unsigned long bitmask; + unsigned long flags; + unsigned long out_state; const unsigned long out_mode_mask = BIT(1); - const unsigned int ttl_offset = 48; - const size_t ttl_i = BIT_WORD(ttl_offset); - const unsigned int word_offset = ttl_offset % BITS_PER_LONG; - const unsigned long ttl_mask = (mask[ttl_i] >> word_offset) & port_mask; - const unsigned long ttl_bits = (bits[ttl_i] >> word_offset) & ttl_mask; - - /* set bits are processed a gpio port register at a time */ - for (i = 0; i < ARRAY_SIZE(ports); i++) { - /* gpio offset in bits array */ - bits_offset = i * gpio_reg_size; - - /* check if any set bits for current port */ - gpio_mask = (*mask >> bits_offset) & port_mask; - if (!gpio_mask) { - /* no set bits for this port so move on to next port */ - continue; - } - raw_spin_lock_irqsave(&idio24gpio->lock, flags); + for_each_set_clump8(offset, gpio_mask, mask, ARRAY_SIZE(ports) * 8) { + index = offset / 8; - /* process output lines */ - out_state = ioread8(ports[i]) & ~gpio_mask; - out_state |= (*bits >> bits_offset) & gpio_mask; - iowrite8(out_state, ports[i]); + bitmask = bitmap_get_value8(bits, offset) & gpio_mask; - raw_spin_unlock_irqrestore(&idio24gpio->lock, flags); - } + raw_spin_lock_irqsave(&idio24gpio->lock, flags); - /* check if setting TTL lines and if they are in output mode */ - if (!ttl_mask || !(ioread8(&idio24gpio->reg->ctl) & out_mode_mask)) - return; + /* read bits from current gpio port (port 6 is TTL GPIO) */ + if (index < 6) { + out_state = ioread8(ports[index]); + } else if (ioread8(&idio24gpio->reg->ctl) & out_mode_mask) { + out_state = ioread8(&idio24gpio->reg->ttl_out0_7); + } else { + /* skip TTL GPIO if set for input */ + raw_spin_unlock_irqrestore(&idio24gpio->lock, flags); + continue; + } - /* handle TTL output */ - raw_spin_lock_irqsave(&idio24gpio->lock, flags); + /* set requested bit states */ + out_state &= ~gpio_mask; + out_state |= bitmask; - /* process output lines */ - out_state = ioread8(&idio24gpio->reg->ttl_out0_7) & ~ttl_mask; - out_state |= ttl_bits; - iowrite8(out_state, &idio24gpio->reg->ttl_out0_7); + /* write bits for current gpio port (port 6 is TTL GPIO) */ + if (index < 6) + iowrite8(out_state, ports[index]); + else + iowrite8(out_state, &idio24gpio->reg->ttl_out0_7); - raw_spin_unlock_irqrestore(&idio24gpio->lock, flags); + raw_spin_unlock_irqrestore(&idio24gpio->lock, flags); + } } static void idio_24_irq_ack(struct irq_data *data) From patchwork Wed Mar 27 05:02:20 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: William Breathitt Gray X-Patchwork-Id: 10872519 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 CEA31925 for ; Wed, 27 Mar 2019 05:01:36 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id B574E28429 for ; Wed, 27 Mar 2019 05:01:36 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id A612328C50; Wed, 27 Mar 2019 05:01:36 +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 4F6FB28429 for ; Wed, 27 Mar 2019 05:01:36 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20170209; h=Sender: Content-Transfer-Encoding:Content-Type:Cc:List-Subscribe:List-Help:List-Post: List-Archive:List-Unsubscribe:List-Id:MIME-Version:References:In-Reply-To: Message-Id:Date:Subject:To:From:Reply-To:Content-ID:Content-Description: Resent-Date:Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID: List-Owner; bh=aYK1v5ZuK8n3jHA7j/nmZTuC9frj5JQdQzi4h+4cS1I=; b=MhkDUdVxOA1YTD 8ZzjqpZB2XfcKei2exNII3v6QWSIx/qJzgsEoorNzFUVKZbUNOAL6lCoA0KzBP54NnZgD7YXAIJDv Bn5WGHlxWgQvyjXn6E18/NPLGV2ezjbII2GlYigrX6IOUEfSIbMocoi/ez1Vhd4+bGzwzmyvtDahZ rC5cU9cSAz3rm6yHH0+7C2XqFtlxX2OrmrnVVLMOxsbTLfNTIGKD1314SaKhC1DmprQxhWGtVVg3m h7OA8C2fbrcd4+EO4Imf5mu9ctJBFJyDcpxnOrnQDJQh30HGKqLIM55N27SoaHdInFNLnyIE6uIs3 5tEvqgBbWIGtkiuXQBQw==; 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 1h90gv-0007KS-Pd; Wed, 27 Mar 2019 05:01:33 +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 1h90go-0007JQ-Ft for linux-arm-kernel@lists.infradead.org; Wed, 27 Mar 2019 05:01:31 +0000 Received: by mail-pf1-x443.google.com with SMTP id e24so8279530pfi.12 for ; Tue, 26 Mar 2019 22:01:26 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=kZSRiSxJh+YYsNmeIydN7WXteuBFfpjUBowwMs4kNhU=; b=uQyk8R0py7UcGbhlLGdW/9Nv1ykF7ezJedfRqJMZf/2BH3uU9YMwLv2AxpRIQEL0tJ fDXgKX03TyTUWCj6FdlVlx/c6dkOR5uhFbuJhHI4Rj0v+bnjAja5EdqVQV8O7OJYzZNY RzrxlaON7mgw22IlE+Ni4o7/M93Uvmqm0wxO75WjbxSNo9v02/tMYCmyKC/Clu0r1KLj fyPBXTegeWjZzictHs0EG+R+dyS+YT3GH8vNhX7VsYq0bVF4BTEqrTx0S699XB+LmHeB GUdPF1POnQGe2cFxFE36FF/by/CVHbwwC8JTZoDLuhD/U3YBPqMKWxD+7KibfJLUmbfO tOXw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=kZSRiSxJh+YYsNmeIydN7WXteuBFfpjUBowwMs4kNhU=; b=dVVgOCKuBoHXiEiawQzCDfNIfwcTfIqQnyT3WJryEGkBGi+d7rvhKOEK1ZihQXl1Q+ ZL1tgRNU7+tXhnaJTBGXG3uub0i8qNt4S+9dtwzvLOck8daWLuqyXcUySaNm1oIJ0Kcc o/3BAwP1V/E9/r8cw5PAjrzdHbqHPBgxGJD3ElJ5jdNLdqNT3NuWN8jg69ZieTc2BtbQ lKE1ZEq0+fy0I0cvqLj03MfQ4uSkQsdaYxdHrM95YGEmTFhBLjl9EJmzmg5cloBIw81Q R1w0MwmAUFmSJky/n6y73oliaw4JRjQI44PFzP4I//v1W9j7Ml6aOdqIpnwumt/MBBRe 1eNQ== X-Gm-Message-State: APjAAAWzI53QTTKnQWB9SSLIUBad6E+5QF3rOHaBFiXqn5VyzjjwlXNK m7vpFihGFnCvLCbmVKvG+uo= X-Google-Smtp-Source: APXvYqy8chgZQxN1dbU1Rt8odCCSTgnvSjwQecTcyPAZzo6VKRdqUrpBsaL34+XVHdAO/Z1iurzsAA== X-Received: by 2002:aa7:8190:: with SMTP id g16mr6378755pfi.92.1553662885842; Tue, 26 Mar 2019 22:01:25 -0700 (PDT) Received: from localhost.localdomain ([2001:268:c0a5:6014:c70:4af9:86e2:2]) by smtp.gmail.com with ESMTPSA id k10sm31080261pgj.11.2019.03.26.22.01.19 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Tue, 26 Mar 2019 22:01:25 -0700 (PDT) From: William Breathitt Gray To: linus.walleij@linaro.org, bgolaszewski@baylibre.com Subject: [PATCH v13 09/11] gpio: uniphier: Utilize for_each_set_clump8 macro Date: Wed, 27 Mar 2019 14:02:20 +0900 Message-Id: X-Mailer: git-send-email 2.21.0 In-Reply-To: References: MIME-Version: 1.0 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20190326_220129_854424_A2B5F40B X-CRM114-Status: GOOD ( 11.45 ) X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: linux-arch@vger.kernel.org, preid@electromag.com.au, yamada.masahiro@socionext.com, linux-pm@vger.kernel.org, linux@rasmusvillemoes.dk, linux-kernel@vger.kernel.org, William Breathitt Gray , linux-gpio@vger.kernel.org, geert@linux-m68k.org, akpm@linux-foundation.org, andriy.shevchenko@linux.intel.com, linux-arm-kernel@lists.infradead.org Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+patchwork-linux-arm=patchwork.kernel.org@lists.infradead.org X-Virus-Scanned: ClamAV using ClamSMTP Replace verbose implementation in set_multiple callback with for_each_set_clump8 macro to simplify code and improve clarity. An improvement in this case is that banks that are not masked will now be skipped. Cc: Masahiro Yamada Signed-off-by: William Breathitt Gray --- drivers/gpio/gpio-uniphier.c | 16 ++++++---------- 1 file changed, 6 insertions(+), 10 deletions(-) diff --git a/drivers/gpio/gpio-uniphier.c b/drivers/gpio/gpio-uniphier.c index 0f662b297a95..d79c34e9b23b 100644 --- a/drivers/gpio/gpio-uniphier.c +++ b/drivers/gpio/gpio-uniphier.c @@ -15,9 +15,6 @@ #include #include -#define UNIPHIER_GPIO_BANK_MASK \ - GENMASK((UNIPHIER_GPIO_LINES_PER_BANK) - 1, 0) - #define UNIPHIER_GPIO_IRQ_MAX_NUM 24 #define UNIPHIER_GPIO_PORT_DATA 0x0 /* data */ @@ -147,15 +144,14 @@ static void uniphier_gpio_set(struct gpio_chip *chip, static void uniphier_gpio_set_multiple(struct gpio_chip *chip, unsigned long *mask, unsigned long *bits) { - unsigned int bank, shift, bank_mask, bank_bits; - int i; + unsigned long i; + unsigned long bank_mask; + unsigned long bank; + unsigned long bank_bits; - for (i = 0; i < chip->ngpio; i += UNIPHIER_GPIO_LINES_PER_BANK) { + for_each_set_clump8(i, bank_mask, mask, chip->ngpio) { bank = i / UNIPHIER_GPIO_LINES_PER_BANK; - shift = i % BITS_PER_LONG; - bank_mask = (mask[BIT_WORD(i)] >> shift) & - UNIPHIER_GPIO_BANK_MASK; - bank_bits = bits[BIT_WORD(i)] >> shift; + bank_bits = bitmap_get_value8(bits, i); uniphier_gpio_bank_write(chip, bank, UNIPHIER_GPIO_PORT_DATA, bank_mask, bank_bits); From patchwork Wed Mar 27 05:02:39 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: William Breathitt Gray X-Patchwork-Id: 10872523 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 90BB1139A for ; Wed, 27 Mar 2019 05:01:53 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 77DCA28429 for ; Wed, 27 Mar 2019 05:01:53 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 6C10228C50; Wed, 27 Mar 2019 05:01: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 8B92228758 for ; Wed, 27 Mar 2019 05:01:51 +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=pi2uc1FUqKqG2bIWH2GaYrpMnHj4llDATf9RqWmoG3o=; b=GFid7XaZbsfmzf C8qZEDgw1yMEwvJT8XAeYlPM2j8C755urJi7Ta9KmHw7qr5gX5RtOrXqfhoqetiNkjCYewIk3dJx3 bDjOLph+Ec0aLls8xd1fp+82CxmnImysTL6JYZDfW+h3XDQlR2Ss5wfiKSxDQfXDbpic/gyB7hyk8 Lm+6rEOY+MEHOv/AN53qpPsRSXTOn9bgJUh31gMNyJV8cCLMDUYK01WV8gM1moamxf5gZAbG9s7Vx 1QrNTbTLDLpJ18c2j0VWR/LIsRsSE3HSryDl2X/zcRMWPlPUhymhTdz7PpkPoXxkRw2IaulFT78O/ toj/BCa0B9BavNAODnBA==; 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 1h90hB-0007Zt-Jq; Wed, 27 Mar 2019 05:01:49 +0000 Received: from mail-pg1-x543.google.com ([2607:f8b0:4864:20::543]) by bombadil.infradead.org with esmtps (Exim 4.90_1 #2 (Red Hat Linux)) id 1h90h7-0007YC-Oh for linux-arm-kernel@lists.infradead.org; Wed, 27 Mar 2019 05:01:47 +0000 Received: by mail-pg1-x543.google.com with SMTP id q1so1178928pgv.13 for ; Tue, 26 Mar 2019 22:01:45 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=0I71euHhTT2+JwpcW5o8Nyy8nGlG1C3w/bjF+uE002A=; b=RxJAI+wrrnLYuf5zN1LqQ0NfP/sRXnHsNkAerPKlXipn3hfibBfpYNyEyXZkV27rvv 1LEtXRdFz0qjzjnTAvIiYMA7TjHI+7o38Xb1wpFPFC4MdzacMWClpF8uQ7jJ1UssfKw1 NB/D4Jyx2Uk4Qdb/dFms8L9Jc3b44ezmBnZYRsKGnCl4WvSJ19dj9zQRdArtaD1+95JK 61n7uZiyp4TctN6ocARJffFWWb41MXz6CajEq9rf19Lzpxi26YPHA5faOg5po3ZiRTJ9 fUW2GoFH5cew28D6mPeJepXDvgqNDmDzbkUeJLo1WUSS7T5dZDPknOzeL37S6/XoDpSM s3qg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=0I71euHhTT2+JwpcW5o8Nyy8nGlG1C3w/bjF+uE002A=; b=I5sYbeOJ4X5VUWXfa9W/tIVswXojhpOuXiPBOYXFDchf9B0o/omLm3uOpfXEXNqSY2 Oqs5GRY/RAqdMFeyfgJLW9Ef38LHx7dss76xlVxz74ua3W8DHjDksqVnNSezewbRuX2l OchSVQqhkuOdecLeLdguWVt43BWDWcHRubqRUzJok0nDrptGZiBFf9P0FGCVJy7mish1 W1tLFqEvve/4jlaSqadYTaPWJPEVj3vGkOjoSDjjFKohquEkoemCbrgcne5peaGrsEm4 DApQrMa+2IQakudD177MIjQc+qMfKaNTa5/YoTJeqpaelKagTpwN1b1vHLYlcI3lTFuj pkDg== X-Gm-Message-State: APjAAAUdPLWxixwSdAOHw46I8IHDgnLmbADAFLAox9VdF7a6sVJMAMKf 5Le7mebWk5FSVY133vMPln4= X-Google-Smtp-Source: APXvYqy8zgtoeHpZ4u2hckq1rici1mAiaKRLX+aQROjYLbCJtAExdV6KIq7Rxz2ipsv5r7oqvAD8NA== X-Received: by 2002:aa7:82d9:: with SMTP id f25mr33179072pfn.45.1553662904075; Tue, 26 Mar 2019 22:01:44 -0700 (PDT) Received: from localhost.localdomain ([2001:268:c0a5:6014:c70:4af9:86e2:2]) by smtp.gmail.com with ESMTPSA id 143sm2358172pge.50.2019.03.26.22.01.38 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Tue, 26 Mar 2019 22:01:43 -0700 (PDT) From: William Breathitt Gray To: linus.walleij@linaro.org, bgolaszewski@baylibre.com Subject: [PATCH v13 10/11] gpio: 74x164: Utilize the for_each_set_clump8 macro Date: Wed, 27 Mar 2019 14:02:39 +0900 Message-Id: <645f16f1d1ad3f215e34a82f457e06725fcf8f56.1553661964.git.vilhelm.gray@gmail.com> X-Mailer: git-send-email 2.21.0 In-Reply-To: References: MIME-Version: 1.0 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20190326_220145_814759_8A3F5379 X-CRM114-Status: GOOD ( 12.27 ) X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: linux-arch@vger.kernel.org, preid@electromag.com.au, Geert Uytterhoeven , yamada.masahiro@socionext.com, linux-pm@vger.kernel.org, linux@rasmusvillemoes.dk, linux-kernel@vger.kernel.org, William Breathitt Gray , linux-gpio@vger.kernel.org, geert@linux-m68k.org, akpm@linux-foundation.org, andriy.shevchenko@linux.intel.com, linux-arm-kernel@lists.infradead.org Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+patchwork-linux-arm=patchwork.kernel.org@lists.infradead.org X-Virus-Scanned: ClamAV using ClamSMTP Replace verbose implementation in set_multiple callback with for_each_set_clump8 macro to simplify code and improve clarity. Suggested-by: Andy Shevchenko Cc: Geert Uytterhoeven Cc: Phil Reid Signed-off-by: William Breathitt Gray --- drivers/gpio/gpio-74x164.c | 19 +++++++++---------- 1 file changed, 9 insertions(+), 10 deletions(-) diff --git a/drivers/gpio/gpio-74x164.c b/drivers/gpio/gpio-74x164.c index fb7b620763a2..0bbf1162bb31 100644 --- a/drivers/gpio/gpio-74x164.c +++ b/drivers/gpio/gpio-74x164.c @@ -9,6 +9,7 @@ * published by the Free Software Foundation. */ +#include #include #include #include @@ -75,20 +76,18 @@ static void gen_74x164_set_multiple(struct gpio_chip *gc, unsigned long *mask, unsigned long *bits) { struct gen_74x164_chip *chip = gpiochip_get_data(gc); - unsigned int i, idx, shift; - u8 bank, bankmask; + unsigned long offset; + unsigned long bankmask; + size_t bank; + unsigned long bitmask; mutex_lock(&chip->lock); - for (i = 0, bank = chip->registers - 1; i < chip->registers; - i++, bank--) { - idx = i / sizeof(*mask); - shift = i % sizeof(*mask) * BITS_PER_BYTE; - bankmask = mask[idx] >> shift; - if (!bankmask) - continue; + for_each_set_clump8(offset, bankmask, mask, chip->registers * 8) { + bank = (chip->registers - 1) - (offset / 8); + bitmask = bitmap_get_value8(bits, offset) & bankmask; chip->buffer[bank] &= ~bankmask; - chip->buffer[bank] |= bankmask & (bits[idx] >> shift); + chip->buffer[bank] |= bitmask; } __gen_74x164_write_config(chip); mutex_unlock(&chip->lock); From patchwork Wed Mar 27 05:02:57 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: William Breathitt Gray X-Patchwork-Id: 10872527 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 3761E925 for ; Wed, 27 Mar 2019 05:02:09 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 1D13228429 for ; Wed, 27 Mar 2019 05:02:09 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 1104628758; Wed, 27 Mar 2019 05:02:09 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-5.2 required=2.0 tests=BAYES_00,DKIM_ADSP_CUSTOM_MED, DKIM_SIGNED,DKIM_VALID,FREEMAIL_FROM,MAILING_LIST_MULTI,RCVD_IN_DNSWL_MED autolearn=unavailable version=3.3.1 Received: from bombadil.infradead.org (bombadil.infradead.org [198.137.202.133]) (using TLSv1.2 with cipher AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.wl.linuxfoundation.org (Postfix) with ESMTPS id A7F8228D4B for ; Wed, 27 Mar 2019 05:02:08 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20170209; h=Sender: Content-Transfer-Encoding:Content-Type:Cc:List-Subscribe:List-Help:List-Post: List-Archive:List-Unsubscribe:List-Id:MIME-Version:References:In-Reply-To: Message-Id:Date:Subject:To:From:Reply-To:Content-ID:Content-Description: Resent-Date:Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID: List-Owner; bh=Et2Hx9PLsg6iEwrazfuS/YReNBJlm6rHK3pigHIGti8=; b=O4M1Z3ITX8mNfs +7UjI710dMAgS8BVRyhRpdXtJcm8JtBKcxCPfe4pjV3yxa6d3DvKrimoUEJPhUy8WlC3oT0Wmzx0K ngDCaEEObSIKpkBF5gEgd70ESaDF5cmaUKwr+z1hDY5cHxJNWJxuLo/6rWNAK0JTp7ylzfb32i5JU 5/u+brvNYwN8JY0KS5b566yRcj51iddr0589wMNST1ZyxJbPYJT/0IyazHMUE+XLfirTaiOEfeDBp 1lAz6CwaI8CehRzgKa6o/+57c/qY/EDliSPrLfPWUgfYA7Sk1ulpSIeqG1vXp8c2epA6BcV1RLOJD gI590HipEKulOWK5pOhg==; 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 1h90hS-0007ov-81; Wed, 27 Mar 2019 05:02:06 +0000 Received: from mail-pl1-x644.google.com ([2607:f8b0:4864:20::644]) by bombadil.infradead.org with esmtps (Exim 4.90_1 #2 (Red Hat Linux)) id 1h90hN-0007nD-EO for linux-arm-kernel@lists.infradead.org; Wed, 27 Mar 2019 05:02:03 +0000 Received: by mail-pl1-x644.google.com with SMTP id y5so2722326plk.8 for ; Tue, 26 Mar 2019 22:02:01 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=bnOm4aYIKD2kSQWsZFrlwKooGVBEjRhwfdK8IJWhQ7o=; b=dGvvPxIy/m4VZWdnvn/MiQ00fT/OPgP3hhe0kjEdXiNMUSgYnE8YUJCaXlzO9BEbky 95qqpJU4hCCwHrTOf5tor7PQ8JXUu9lC3pWT1dh1YuGS6rAD0/bJYClZ1vM0KdhorNjv VSfOZo1Vai/sIP+yH5FMXkphSs9334PDdFl7/b7dnnng3utFIFiY6jm8psRCu47dCM7W 3i2dFdPb3pKfmGT+9XfAYuLCHKGarFWE07KbzF4vX5Kt4qCr557/zyWsNQKpUApLezzi qkRxeHkALUZn7RQw0xY/Ic7GN9qpsVnMEsfg0vZclIBNwA+nwp+VXjK+6r+5W1Cw4gER GnRg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=bnOm4aYIKD2kSQWsZFrlwKooGVBEjRhwfdK8IJWhQ7o=; b=J78LcfEweKQwFzR1QOLi1iFiL9fQ0gzSpxk6TTyv/cX7uBYr/v8wpZ7R5ETsN0hk0a ocS/ETuHcBMA5spqUxheqO9UsyTUXkNfb4nZZNSzOMga0h3fvmKbw7Y5NPDPIsJze3PA /QmKGfFvKUXXN7dSXDmirJKC8NL7AZV+PO0naaA0jFGmYsJ5tiWcymZxDWLtUo6FPSkt FCNqhYJAe6+Vj+rLXmn7GNRmvHHKxGHfA2FKaN8wAbOG8vll/2WElmij6YsZSQJMCYFd m93Yi708xNcqjhRm7OXjCpRXJU034vsAdF5VQtqz1pFdxnVvQNnUjURNhvpptMchOIzA sk9g== X-Gm-Message-State: APjAAAUsratUsIm0/aYAOnaAGJc0lrYNTUtA3gWXDh0Xdj1OZQ5DFmUo NntFXL5VgR3qqintGkUFLvg= X-Google-Smtp-Source: APXvYqzlK6yAH+z2MpWlMuT24AimhcSTFq81vcQA1qzet5WlawC79ydrqZzjLC5p8V58SsuIBf/0Uw== X-Received: by 2002:a17:902:7b90:: with SMTP id w16mr35646281pll.228.1553662920954; Tue, 26 Mar 2019 22:02:00 -0700 (PDT) Received: from localhost.localdomain ([2001:268:c0a5:6014:c70:4af9:86e2:2]) by smtp.gmail.com with ESMTPSA id d20sm7014940pfo.77.2019.03.26.22.01.56 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Tue, 26 Mar 2019 22:02:00 -0700 (PDT) From: William Breathitt Gray To: linus.walleij@linaro.org, bgolaszewski@baylibre.com Subject: [PATCH v13 11/11] thermal: intel: intel_soc_dts_iosf: Utilize for_each_set_clump8 macro Date: Wed, 27 Mar 2019 14:02:57 +0900 Message-Id: <2a9aec7e4601b1b0ea4494e1b8d3f7d200a12007.1553661964.git.vilhelm.gray@gmail.com> X-Mailer: git-send-email 2.21.0 In-Reply-To: References: MIME-Version: 1.0 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20190326_220201_486222_1082B6ED X-CRM114-Status: GOOD ( 14.60 ) X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: linux-arch@vger.kernel.org, preid@electromag.com.au, yamada.masahiro@socionext.com, linux-pm@vger.kernel.org, linux@rasmusvillemoes.dk, linux-kernel@vger.kernel.org, William Breathitt Gray , linux-gpio@vger.kernel.org, geert@linux-m68k.org, akpm@linux-foundation.org, andriy.shevchenko@linux.intel.com, linux-arm-kernel@lists.infradead.org Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+patchwork-linux-arm=patchwork.kernel.org@lists.infradead.org X-Virus-Scanned: ClamAV using ClamSMTP Utilize for_each_set_clump8 macro, and the bitmap_set_value8 and bitmap_get_value8 functions, where appropriate. In addition, remove the now unnecessary temp_mask and temp_shift members of the intel_soc_dts_sensor_entry structure. Suggested-by: Andy Shevchenko Tested-by: Andy Shevchenko Signed-off-by: William Breathitt Gray --- drivers/thermal/intel/intel_soc_dts_iosf.c | 29 +++++++++++++--------- drivers/thermal/intel/intel_soc_dts_iosf.h | 2 -- 2 files changed, 17 insertions(+), 14 deletions(-) diff --git a/drivers/thermal/intel/intel_soc_dts_iosf.c b/drivers/thermal/intel/intel_soc_dts_iosf.c index e0813dfaa278..2aa16b5262e9 100644 --- a/drivers/thermal/intel/intel_soc_dts_iosf.c +++ b/drivers/thermal/intel/intel_soc_dts_iosf.c @@ -15,6 +15,7 @@ #define pr_fmt(fmt) KBUILD_MODNAME ": " fmt +#include #include #include #include @@ -111,6 +112,7 @@ static int update_trip_temp(struct intel_soc_dts_sensor_entry *dts, { int status; u32 temp_out; + unsigned long update_ptps; u32 out; u32 store_ptps; u32 store_ptmc; @@ -129,8 +131,9 @@ static int update_trip_temp(struct intel_soc_dts_sensor_entry *dts, if (status) return status; - out = (store_ptps & ~(0xFF << (thres_index * 8))); - out |= (temp_out & 0xFF) << (thres_index * 8); + update_ptps = store_ptps; + bitmap_set_value8(&update_ptps, temp_out & 0xFF, thres_index * 8); + out = update_ptps; status = iosf_mbi_write(BT_MBI_UNIT_PMC, MBI_REG_WRITE, SOC_DTS_OFFSET_PTPS, out); if (status) @@ -232,6 +235,7 @@ static int sys_get_curr_temp(struct thermal_zone_device *tzd, u32 out; struct intel_soc_dts_sensor_entry *dts; struct intel_soc_dts_sensors *sensors; + unsigned long temp_raw; dts = tzd->devdata; sensors = dts->sensors; @@ -240,7 +244,8 @@ static int sys_get_curr_temp(struct thermal_zone_device *tzd, if (status) return status; - out = (out & dts->temp_mask) >> dts->temp_shift; + temp_raw = out; + out = bitmap_get_value8(&temp_raw, dts->id * 8); out -= SOC_DTS_TJMAX_ENCODING; *temp = sensors->tj_max - out * 1000; @@ -290,10 +295,13 @@ static int add_dts_thermal_zone(int id, struct intel_soc_dts_sensor_entry *dts, { char name[10]; int trip_count = 0; + int writable_trip_count = 0; int trip_mask = 0; u32 store_ptps; int ret; - int i; + unsigned long i; + unsigned long trip; + unsigned long ptps; /* Store status to restor on exit */ ret = iosf_mbi_read(BT_MBI_UNIT_PMC, MBI_REG_READ, @@ -302,11 +310,10 @@ static int add_dts_thermal_zone(int id, struct intel_soc_dts_sensor_entry *dts, goto err_ret; dts->id = id; - dts->temp_mask = 0x00FF << (id * 8); - dts->temp_shift = id * 8; if (notification_support) { trip_count = min(SOC_MAX_DTS_TRIPS, trip_cnt); - trip_mask = BIT(trip_count - read_only_trip_cnt) - 1; + writable_trip_count = trip_count - read_only_trip_cnt; + trip_mask = GENMASK(writable_trip_count - 1, 0); } /* Check if the writable trip we provide is not used by BIOS */ @@ -315,11 +322,9 @@ static int add_dts_thermal_zone(int id, struct intel_soc_dts_sensor_entry *dts, if (ret) trip_mask = 0; else { - for (i = 0; i < trip_count; ++i) { - if (trip_mask & BIT(i)) - if (store_ptps & (0xff << (i * 8))) - trip_mask &= ~BIT(i); - } + ptps = store_ptps; + for_each_set_clump8(i, trip, &ptps, writable_trip_count * 8) + trip_mask &= ~BIT(i / 8); } dts->trip_mask = trip_mask; dts->trip_count = trip_count; diff --git a/drivers/thermal/intel/intel_soc_dts_iosf.h b/drivers/thermal/intel/intel_soc_dts_iosf.h index 625e37bf93dc..d0362d7acdef 100644 --- a/drivers/thermal/intel/intel_soc_dts_iosf.h +++ b/drivers/thermal/intel/intel_soc_dts_iosf.h @@ -33,8 +33,6 @@ struct intel_soc_dts_sensors; struct intel_soc_dts_sensor_entry { int id; - u32 temp_mask; - u32 temp_shift; u32 store_status; u32 trip_mask; u32 trip_count;