Received: by 10.192.165.148 with SMTP id m20csp4304270imm; Tue, 8 May 2018 06:27:37 -0700 (PDT) X-Google-Smtp-Source: AB8JxZpczqag9FQftGQPcU5Job6iUBhalO0uBBBxooWLO/N3mFVLr7VDOkZOKDoh+EsmxHktV1MK X-Received: by 2002:a63:78c3:: with SMTP id t186-v6mr32633834pgc.97.1525786057440; Tue, 08 May 2018 06:27:37 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1525786057; cv=none; d=google.com; s=arc-20160816; b=xyYaQt6Vjt80eKawrgyBWgW6nrO++37a0Ph3ArVVZHx5JkN0fQaf5PAqHK4U7/Cdef WHYt/LBeK5wZBSH7VYFYXS48YIg7o4n4uxrYfVlIzq7BfVBfP1iQcMOM3Z1LVf0O4dsu cTU51YxPIDmWic02Ua4OI5XF2nVeozIyFhzenDlGhYvBr4r0WFAVz3JtXVZVaTgAjnjB Zhk2Zkk44OKIaI+9vyZXUhhEgl1YI95hUijIJNLQCJ5hmwRv6v4IXUaihKH6p2a/swmU twNXbbBwQq91CV3B0vdcAcpNCCTjPx9Z/QJtkGpY7GrzVyzcN9r6LQ5so5OBtFmjmkfv 4ZlQ== 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=u/4+aSQMNk/G8E5D+4UK7p1QBTiB/Y3h/gDZCR8OANo=; b=udXOJFDB9UfEX8k/DXcQMyDDUxloWEANVvbp1ucMnSd0CINllsVfJ+BQpoEmN/XKl2 mOkgEzo/qiub1RS6p0U1qHkohHAVvKLJsb9tbSvwY2M5XuLof9mS5nXg3z1xtC+WnesE xbgfQSbi529saDbZUTeYJU1myvWXj+R0l9llDIJRHaorObpZgEdGS2TjqBNlIYMnrtBL dMl+kA33iGk6I/zcmtdCr98vKSfUQHw22Mf66v44I5mYWCj9PR/Ks8DW+UTM4eniKR/h O3p2P2NkwSJrl7d478awK9JT9xt1To559wlvUNJ/1evI6GkVVdFMhgabxHiW9J4WNpUa usKw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gmail.com header.s=20161025 header.b=B2elQwli; 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 h12si24215490pfd.253.2018.05.08.06.27.22; Tue, 08 May 2018 06:27:37 -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=B2elQwli; 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 S1755137AbeEHN0w (ORCPT + 99 others); Tue, 8 May 2018 09:26:52 -0400 Received: from mail-yb0-f194.google.com ([209.85.213.194]:46381 "EHLO mail-yb0-f194.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1754554AbeEHN0r (ORCPT ); Tue, 8 May 2018 09:26:47 -0400 Received: by mail-yb0-f194.google.com with SMTP id f3-v6so2730629ybg.13; Tue, 08 May 2018 06:26:47 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:date:message-id; bh=u/4+aSQMNk/G8E5D+4UK7p1QBTiB/Y3h/gDZCR8OANo=; b=B2elQwlitFDPicoGpgVocrshlaDlvFwlE2dw1+OKTq5Yo+t6bCJAwsBq+00pdMcaGw 2OvA97oVkkc/d8JoTiM9LDACgvF1LPfiAOh48oNp3KJkkLw9abpLXWr8lj0j0rDqpGWb QyE5Q7swKxPks4KSKHQc8vHO1vsJvw6S7qmyIR3EtRp0faQ0QR0o6Ifjws/w3xVI2YUr znIaA85RzSuCl9JRWAvFPHQ1nehKLxzFWUBkSz3F0PIburrlAWa88tvfYUIy86o0HJiD ugF5+4eJTagtqAwGCI9wAOW1yqVmHhUtARsw76F2A/l11hHewSJxY1POlct0zOo5p0u2 6H+A== 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=u/4+aSQMNk/G8E5D+4UK7p1QBTiB/Y3h/gDZCR8OANo=; b=JGiZRJIqYHpNdIZ+vPxqpxqur2B8fNIFA7r9m6yIufduspMHWEhJH23NuOtBLrUWuA 4zerqR3GOzFlhuQbIq0eyyEqP4psZEr9iEKhTED1sZslhvq6/RVjyMCgpPEZ61OUemqW GLC6IkYzoz8k5hkd2Orqyb8g7Gg3YN8SJDSfU9Zw7+tvy8sjoNNUsd3JN+Dju5ycCkN3 AJps54wynkcKiFCA+KckaYpKCgWNdGrfhA4L1WCiOXN5SjLAkvO9Js8lWpRXfKa7rukD DB2GQygpSANann9D2gFvFuWSM9UBGJXVxKIn1+b1K5E0cOLsW7stD+CKeaQfoWkPKsZT fOTA== X-Gm-Message-State: ALQs6tDsKwa8ut4sdFIVfAQZ9SftEtArmR4ZLi5aSj3hwfpeM86ZOXFG mfHtpPq4eVEmedifDNwOY5s= X-Received: by 2002:a25:9392:: with SMTP id a18-v6mr25037056ybm.404.1525786007221; Tue, 08 May 2018 06:26:47 -0700 (PDT) Received: from localhost ([72.188.97.40]) by smtp.gmail.com with ESMTPSA id p17-v6sm11332898ywe.100.2018.05.08.06.26.46 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Tue, 08 May 2018 06:26:46 -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 v2 0/7] Introduce the for_each_set_port_word macro Date: Tue, 8 May 2018 09:26:34 -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 Changes in v2: - Include linux/types.h file in bitops/find.h to define size_t 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: * 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