Received: by 2002:ac0:a594:0:0:0:0:0 with SMTP id m20-v6csp4317178imm; Mon, 14 May 2018 05:59:04 -0700 (PDT) X-Google-Smtp-Source: AB8JxZqpEH88Gt+rAs4LiDih6ZLMm301AghIXR1fqpAUFiqjOyCO7waEGUW32VwV/+n7wuJ2lMi3 X-Received: by 2002:a62:1f03:: with SMTP id f3-v6mr10466926pff.213.1526302744461; Mon, 14 May 2018 05:59:04 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1526302744; cv=none; d=google.com; s=arc-20160816; b=wc6mKiEg0xmrZtVTZtnItDDN6lgMriaiocAPRkXW9aLlMIg4HHJo1oTW7Zaw3IyaXZ X+4trm5DKWQoH0XT9x/kvPJXk5qt4SApBNqjRanYTGE9DY6AA8ug0U+yLjxlfIZGhw0S IeoMcyX7i4kXAOKo404nju04f7igZmE1fDUF2PqOJEvBu/eagIcKlcdIWG+5kTlwhhww 8efWNim/X/rVTxj+eBim8v8MMDUm7YeWRKmtOPt/g0yt635MAzYpCtmIrgSUPVrIZ9B2 I49Z0IsBUi0UJ6W2G+zsC3amXkRSZeLcoiK4VYBxmANJtzQGUXzHsBEYmV84yi2t18fT SxsA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:user-agent:in-reply-to :content-disposition:mime-version:references:message-id:subject:cc :to:from:date:dkim-signature:arc-authentication-results; bh=1PJBPuxDxmJu5uaMqM4Sr1r0smNOGQi0FyNCt6eEJYI=; b=qfndMmMLEgEhN3Hbe9c7s348y3nNJjwfr+dJbs35ssFAzyw0yZFHMAhvzAEL7yc3Cb IntjjvUFUJSBkHZXpCHz5cReLTtWg+zdoEBCEDJGkAVp9e7LkvXqox3cq8NaR8zFVY0U mJVDN1X/iZeC4Su6XMLhlWqdSszLWkoZfFN1V+dV7y68+50xWzCEx4ma0QDeRkxJliCD EcwRumuIZN9+0/mK6elxN9JnhH42zNVq6BfKDrKtWsKhEHVoxrP2gnDsHmGc19n5if+r +SMc14k2JM6+ariFmje4fNqqK9wBWNTbJn83zYcOwfSBzGFACua8Ku1lErEr7mkrOuuJ ZSew== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gmail.com header.s=20161025 header.b=MoARRepg; 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 h8-v6si9380463pfi.115.2018.05.14.05.58.49; Mon, 14 May 2018 05:59:04 -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=MoARRepg; 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 S932117AbeENM6F (ORCPT + 99 others); Mon, 14 May 2018 08:58:05 -0400 Received: from mail-yw0-f194.google.com ([209.85.161.194]:41062 "EHLO mail-yw0-f194.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1753275AbeENM6C (ORCPT ); Mon, 14 May 2018 08:58:02 -0400 Received: by mail-yw0-f194.google.com with SMTP id q125-v6so3535504ywc.8; Mon, 14 May 2018 05:58:02 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=date:from:to:cc:subject:message-id:references:mime-version :content-disposition:in-reply-to:user-agent; bh=1PJBPuxDxmJu5uaMqM4Sr1r0smNOGQi0FyNCt6eEJYI=; b=MoARRepgIhEoAaMR/HkHIf4HICQQWx8X6YwtUYrdE0kFUusdrbBoYR6k6qJti2Uq+M s2apos2RXxQDTxf6FFdcrQ2hoqbeWEZCJG6FmjQaTEA4LeEo+U/ofilsil8AakBelQ9I MSxu4iQSiIMfL4ltK517gTjtGxvdiEmWphnlsn57oerBZ8ffkTE60BMtt7u/O2/Gtxn8 brbydsZcwluM8ZYkAWBn4a0P7u+byZmwTgHi+ycdSHIrlwZmOgm/G/1FycY+I+8+7eg/ 5Uw/HhPgIlxUSFyt5Q/XweoEm/l1cgVzMJAhHse2/d1PpdQZtX24jJ9aPBVE2yJtZwLy 0QYg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:date:from:to:cc:subject:message-id:references :mime-version:content-disposition:in-reply-to:user-agent; bh=1PJBPuxDxmJu5uaMqM4Sr1r0smNOGQi0FyNCt6eEJYI=; b=Z3StzXNF6E4Ykm6NryvD13lvJyeGmmfeUEwLU4s/PRqx9BYjIJh0gz9kY3GSmYvJqB Nm24SBn17j5QclxmDz/PrEIbPVinThoKjGB5/ffqdvyNnKebKT0w6JkWQq2vH7MqCQJa FdAvIotc7EyeiEcfTBQjkOpOQ9dFozAxMnpFu+4V+E8naetIHWxFNyTgeCbhAmqsrLI3 nMlEgZ6tpFn6ooZoy53VYLAK2Ls3eXn1Mubp8Nd36MUZ8gUBFRLj5qXwDZEYU4nSZuPH C4eMrEmJ1EfmTuPyE+RAhiVA9mHdhdKDNoh5IP4tkqJSOG/vLTF8pmQH5nlhlWdCAT0x +psA== X-Gm-Message-State: ALKqPwciCMi+l9CS4zzxG0A/KHjWDfHgIEHd4jyTBXSyiAB9+w1ES8Tg zwD4LMNVhMQ4vjWu+f1JyiDoAg== X-Received: by 2002:a81:740a:: with SMTP id p10-v6mr4353543ywc.40.1526302681671; Mon, 14 May 2018 05:58:01 -0700 (PDT) Received: from sophia ([72.188.97.40]) by smtp.gmail.com with ESMTPSA id 184-v6sm525825ywi.28.2018.05.14.05.58.00 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Mon, 14 May 2018 05:58:01 -0700 (PDT) Date: Mon, 14 May 2018 08:57:54 -0400 From: William Breathitt Gray To: Andy Shevchenko Cc: Linus Walleij , "open list:GPIO SUBSYSTEM" , Linux-Arch , Linux Kernel Mailing List Subject: Re: [PATCH v2 0/7] Introduce the for_each_set_port_word macro Message-ID: <20180514125743.GA20325@sophia> References: MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Disposition: inline In-Reply-To: User-Agent: Mutt/1.9.5 (2018-04-13) Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Sun, May 13, 2018 at 06:11:45PM +0300, Andy Shevchenko wrote: >On Tue, May 8, 2018 at 4:26 PM, William Breathitt Gray > wrote: > >> 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 > >8-bit itteration. Is it correct? This case is 4-bit iteration for the sake of example, but the idea is to have the for_each_set_port_word macro to be capable of 8-bit iteration, as well as any other number of bits, as specified by the port_size parameter. > >> Third loop: XXXX 1110 0000 1111 > >Looking at the example above I highly recommend to introduce some test >cases for your helper function. > >Consider extending lib/test_bitmap.c for this purpose. That's a good idea. I'll add in some test cases to lib/test_bitmap.c to help check the implementation of these functions and macro. William Breathitt Gray > >> >> 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: >> >> * commit aaf96e51de11 ("gpio: pci-idio-16: Fix port memory offset for get_multiple callback") >> * commit 304440aa96c6 ("gpio: pcie-idio-24: Fix port memory offset for get_multiple/set_multiple callbacks") >> * commit 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 | 26 ++++++++ >> include/linux/bitops.h | 9 +++ >> lib/find_bit.c | 28 ++++++++ >> 9 files changed, 172 insertions(+), 292 deletions(-) >> >> -- >> 2.17.0 >> > > > >-- >With Best Regards, >Andy Shevchenko