Received: by 10.192.165.148 with SMTP id m20csp3220057imm; Mon, 7 May 2018 08:36:02 -0700 (PDT) X-Google-Smtp-Source: AB8JxZpdGl6MKa89G3CflD5hWFQ4qYEJOYXRt4Mjyd6rp8hOXCutdBTnDFIM2ZinwsbbR5SNG266 X-Received: by 2002:a6b:ac85:: with SMTP id v127-v6mr26508628ioe.286.1525707362456; Mon, 07 May 2018 08:36:02 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1525707362; cv=none; d=google.com; s=arc-20160816; b=pUmGhu8uqfmQYOS0/Rc+1vtpAesNgy8cG8RuFbu2QFElBr7wGkglFod5yHR3VadEGY toURX28kWkSmSQCjAXCIGv5Pvc8d99SyAAHnSUZ/3zVStFZuyg2LqgZKT9NXBkxQlvZu p4dMNNEMFvM8e2yuv+4MFcw/mMIR5Fdezx5aGAI1EitpSgeaaK9TaUHyqJhxDRH3+Jhe V32/4+EC6o1BL8wEcnMq82OXO0fmODWR6/kF5JQtjqDMU5c1GJ/aXyJm6jXMSuVxS+D1 OCDgd1KqVXfkubitbLH60wx6i4ZS8mmdvck6hkiM0HGo4lzDa1FOlhWTUydFl8hWLmsc KFEw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:message-id:date:subject:cc:to:from :dkim-signature:arc-authentication-results; bh=nr17vJJwcw8x5jSKlMYxR+ezHQSSzeb6t1G+kmLJBtA=; b=nxE/wOtjuqGXE20zqmbaWsiLLKl+wj6DgRWSwpuc7oqQx6nXPifWgM/8/yA3ptQDS7 bO92def+VhcoEt4CKL8FCJDLGUSIg2ouxWjpTtUSdZEFVWE8E55nfV+qyvdkpohP+dKk NYGPUnqZt/gnLzbST0NJNBwShZEyqYPpLBK0wrsi2rXjAxcvRQd2Mtm2jmMWh87bCG2L QLK16rY5qLHvnmLn/eUtGyLIXYM12hhd4G2RG6i89LWayHnmlNLhLNB0ddXtelus/Q4v 7iomqoA/0qTMO7M3a3RfXdhVan8tSdN0C/HtEvSp60DXLG2XRaM1MJ0FS/5cRixuGOww yooA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gmail.com header.s=20161025 header.b=L9zObmCJ; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id b126-v6si4386405iti.28.2018.05.07.08.35.48; Mon, 07 May 2018 08:36:02 -0700 (PDT) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; dkim=pass header.i=@gmail.com header.s=20161025 header.b=L9zObmCJ; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1752035AbeEGPfR (ORCPT + 99 others); Mon, 7 May 2018 11:35:17 -0400 Received: from mail-yw0-f196.google.com ([209.85.161.196]:45841 "EHLO mail-yw0-f196.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1750881AbeEGPfO (ORCPT ); Mon, 7 May 2018 11:35:14 -0400 Received: by mail-yw0-f196.google.com with SMTP id g9-v6so8723494ywb.12; Mon, 07 May 2018 08:35:14 -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; bh=nr17vJJwcw8x5jSKlMYxR+ezHQSSzeb6t1G+kmLJBtA=; b=L9zObmCJWzEGcO2rw4bg5kL5UbxiZwBracAnhxEYuyGuIXk+eNh63RuiDETl5Iotnb +YOtcN4ExaVUqGapQbUF6pjCKihqucCJxVP3yVmR5caoZw6qfhl4bytssm86iPfpm7jK 5CDQZ50Wel1as4YmcwE+YgvTdJ7G3BNYKryJnKDPAIzXfmbxsX7dLSR3uttB3fzUBnQT Ap/igRIda9NsAy3nuolIvn9ImoZB3jHdifMZl7fB/yQPAhREFkpM3Na3ErWdKcCVn/vd +iyy0i+Ja048ewjh7ztMzSj2th1XjB+0ZhTBZFRg65xlOx0Hcgfjx3ZfLWdpyQBE+SzB rALg== 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; bh=nr17vJJwcw8x5jSKlMYxR+ezHQSSzeb6t1G+kmLJBtA=; b=PykWn/Da/kPzDJ7eAKyb8GIdzptn1GdE1198xYOJRhcQLNAQm/qHQXQGe16NSo6rE+ jS1Jk6ihhqNKIIvcAfGxVjINHE7vL859uXD/+40M31SwxFtKi3v87Cv+0qgQb0zabtwK aLZO67mLNuZ97FUYihKTxXmpwZnSUe39ES83xsmk8h+QF6/2kcbBWXinvveIXpnHM+5u 9mpuXRI6qwT77lxO0TE5G7P5EDqnN3wq26pHnLufNk5a7Y6qtkM7KJ6eMXdYxw88++vJ O3t/iZc09mVi6noHMBUpyA+pGNh0w56VaVm684qEqSRo9ZcTaK95kFWRlwzDaWn5+1X9 u7Fg== X-Gm-Message-State: ALQs6tA6N07QjJ0Mhe3zyrswlfWonnF2a+x11ovOMUij+mWMyFa+qhhG iC+lRMLeGlGXMcPjkRnK7e/lnA== X-Received: by 2002:a81:6189:: with SMTP id v131-v6mr1994699ywb.20.1525707313973; Mon, 07 May 2018 08:35:13 -0700 (PDT) Received: from localhost ([72.188.97.40]) by smtp.gmail.com with ESMTPSA id g132-v6sm8813700ywb.88.2018.05.07.08.35.12 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Mon, 07 May 2018 08:35:13 -0700 (PDT) From: William Breathitt Gray To: linus.walleij@linaro.org Cc: linux-gpio@vger.kernel.org, linux-arch@vger.kernel.org, linux-kernel@vger.kernel.org, William Breathitt Gray Subject: [PATCH 0/7] Introduce the for_each_set_port_word macro Date: Mon, 7 May 2018 11:35:02 -0400 Message-Id: X-Mailer: git-send-email 2.17.0 Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org While adding GPIO get_multiple/set_multiple callback support for various drivers, I noticed a pattern of looping manifesting that would be useful standardized as a macro. This patchset introduces the for_each_set_port_word macro and utilizes it in several GPIO drivers. The for_each_set_port_word macro facilitates a for-loop syntax that iterates over entire groups of set bits at a time. For example, suppose you would like to iterate over a 16-bit integer 4 bits at a time, skipping over 4-bit groups with no set bit, where XXXX represents the current 4-bit group: Example: 1011 1110 0000 1111 First loop: 1011 1110 0000 XXXX Second loop: 1011 XXXX 0000 1111 Third loop: XXXX 1110 0000 1111 Each iteration of the loop returns the next 4-bit group that has at least one set bit. The for_each_set_port_word macro has six parameters: * port_word: set to current port word index for the iteration * word_index: set to current bitmap word index for the iteration * word_offset: bits offset of the found port word in the bitmap word * bits: bitmap to search within * size: bitmap size in number of port words * port_size: port word size in number of bits The port_size argument can be an arbitrary number of bits and is not required to be a multiple of 2. I've called the group of bits a "port word" which may be a confusing naming convention; I was afraid calling that them a "group" may be too vague. Should a different name be chosen; what would you suggest? This patchset was rebased on top of the following three commits: * aaf96e51de11 ("gpio: pci-idio-16: Fix port memory offset for get_multiple callback") * 304440aa96c6 ("gpio: pcie-idio-24: Fix port memory offset for get_multiple/set_multiple callbacks") * e026646c178d ("gpio: pcie-idio-24: Fix off-by-one error in get_multiple loop") William Breathitt Gray William Breathitt Gray (7): bitops: Introduce the for_each_set_port_word macro gpio: 104-dio-48e: Utilize for_each_set_port_word macro gpio: 104-idi-48: Utilize for_each_set_port_word macro gpio: gpio-mm: Utilize for_each_set_port_word macro gpio: ws16c48: Utilize for_each_set_port_word macro gpio: pci-idio-16: Utilize for_each_set_port_word macro gpio: pcie-idio-24: Utilize for_each_set_port_word macro drivers/gpio/gpio-104-dio-48e.c | 67 +++++--------------- drivers/gpio/gpio-104-idi-48.c | 32 ++-------- drivers/gpio/gpio-gpio-mm.c | 67 +++++--------------- drivers/gpio/gpio-pci-idio-16.c | 67 ++++++-------------- drivers/gpio/gpio-pcie-idio-24.c | 102 +++++++++++------------------- drivers/gpio/gpio-ws16c48.c | 66 +++++-------------- include/asm-generic/bitops/find.h | 24 +++++++ include/linux/bitops.h | 9 +++ lib/find_bit.c | 28 ++++++++ 9 files changed, 170 insertions(+), 292 deletions(-) -- 2.17.0