Received: by 2002:ac0:a594:0:0:0:0:0 with SMTP id m20-v6csp805237imm; Tue, 15 May 2018 09:24:39 -0700 (PDT) X-Google-Smtp-Source: AB8JxZrP+hYrsXm1XdT413CZwDkzYuPgjXBcKKdqhsiq/LWi8NoI3AqZlGUJCxP+bwNcapl87V2N X-Received: by 2002:aa7:83c7:: with SMTP id j7-v6mr15811663pfn.50.1526401479409; Tue, 15 May 2018 09:24:39 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1526401479; cv=none; d=google.com; s=arc-20160816; b=U88PhYa6D6Hdbbu06PE76oPvNoWvfW0g02n+7SXJrCTTZEoHjQYPnGqtFZnlfCsKlE tkX0zbRzyWQtcp5BUGVTMklVwbuvphChG/IbO5+qqQtK0LiKu4ldcaixkfXHqd7rXBEr Ba1NcCbqst7L3xtZ/STtOissy+rW1YnztBVr4LMzZ9lrqYJbOSoWYPFiUU+sXFywBIK4 9HwajqNLSL2HK+rT3AJI2IT6XtwGNONLFJMAZhOVvapd/RQE8/nGJe3y6uJHqR5F53YZ znsq+P96eR7F6MEwP629bpSfsPhhTnkoF4fLo9gi8owXbIZqwJ2mMNt0Iw92R9KAc3m7 gwCw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:references:in-reply-to:message-id:date :subject:cc:to:from:dkim-signature:arc-authentication-results; bh=tAo7rXu+mux3L7ze8r9gzOGceOAVFwQmVWVRQkyRRgw=; b=ek8A4Ann0sDbM974aO7Ime7NsIlbBObVbooI/0AlyeoDxQEFAa4Lylw/NKpXNOBmji iLCzY2bg2Mws77+blWm2OKb7O7NULHqlH2wJIyGhZpHDY1XAdueG841uayXMCcELneLp c0PT0EWI41C6WRaAx3m+FmSr/bOsXG49oCgPZZWpZLSIjMyl6LkovCHlG7yfVeH9ywoA hkle6Wm2V68f0GRFuyfx0sf6khV7QplQi9oYpWhUBQnGxS7YCpEsdTvERpXu/cMoWFZ5 WvaiJkPWbKHUe+WXQdGDD0UzMJsy+/rIxSsZr2nAt6OfOGPRcyMNCnFcLO4iJT6/Iep8 0Jrg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gmail.com header.s=20161025 header.b=k0y5+BtU; 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 n12-v6si290237pgs.560.2018.05.15.09.24.20; Tue, 15 May 2018 09:24:39 -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=k0y5+BtU; 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 S1754215AbeEOQXi (ORCPT + 99 others); Tue, 15 May 2018 12:23:38 -0400 Received: from mail-yb0-f196.google.com ([209.85.213.196]:33143 "EHLO mail-yb0-f196.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1753984AbeEOQXe (ORCPT ); Tue, 15 May 2018 12:23:34 -0400 Received: by mail-yb0-f196.google.com with SMTP id y5-v6so261145ybg.0; Tue, 15 May 2018 09:23:34 -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; bh=tAo7rXu+mux3L7ze8r9gzOGceOAVFwQmVWVRQkyRRgw=; b=k0y5+BtUBd4IyC+OUFlBlHbTEJAMXU9t1JrQSkv2jLV2/zinkC6BDhiJGy4JIleaYx /Gg89LUcM93QDX1Z9Uo19fdl7QIiBIaiihLXX3vF7CIsIWXz+PnEnb6JmFGEwhPK5PlL d82AFbvJ1IQ4SfmfeDcs2hVK1EqptOEDemTZt49h7+a9ejbg9kVAWH9A6DUN1VVXWnNu 3/vTqQgZBFksmlwpMmztCPk1oka/hdusqDwGBWz91OMP5fM+pAeBaoR1DLpGibaW3+9V DL3lA3RUPL871i8/EDYZR2wHBNq7RYofOh7JkQz2ljs78O8S6nz8/V5txW1Vz7/qebvZ 5dWQ== 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; bh=tAo7rXu+mux3L7ze8r9gzOGceOAVFwQmVWVRQkyRRgw=; b=GtQFclDzxc8vnXGB9ZiM2L2te0dGwua17JV6OfPMOWNnhTqKqywf4s+PKMCWhCORc9 +K1W17wTl02Mq6DSSuBktdUdRp9bM0iX7PyiFlOKPiiz0uUPDjnN86uB8rMYEmtH8hWS u0infCte6Q1XzvwRC/pGIbwxBo4MmPnd4MxKNWiiaysrHTLjUxpvwjEGPK6c30PZ8of5 e4NKDu8D+1dW0/RIvlXnl+ZOz27XCWOLGvekv8D6hMPIh4Dw99FU2sCuXTvnKaSc2IEA vCzvrWzsQKdLNVPAcrrzcjKOS99flm8NhflzzH4+Wd08ImrI7PllW7zqRGfcPZ9wgXPb GE1g== X-Gm-Message-State: ALKqPwc8zoiNzpKJqbwZ9wLyDf2Q//rBnOAvILEClJRbk/YJl6fxP33y 7PRSe2SpsmaXYBnyw794Qdk= X-Received: by 2002:a25:42c2:: with SMTP id p185-v6mr8991887yba.313.1526401414204; Tue, 15 May 2018 09:23:34 -0700 (PDT) Received: from localhost ([72.188.97.40]) by smtp.gmail.com with ESMTPSA id t124-v6sm142031ywe.107.2018.05.15.09.23.33 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Tue, 15 May 2018 09:23:33 -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 v4 6/8] gpio: ws16c48: Utilize for_each_set_clump macro Date: Tue, 15 May 2018 12:23:27 -0400 Message-Id: <639ed637c39c77fe6df26f0b55b930751c5864ca.1526400945.git.vilhelm.gray@gmail.com> X-Mailer: git-send-email 2.17.0 In-Reply-To: References: Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Replace verbose implementation in get_multiple/set_multiple callbacks with for_each_set_clump macro to simplify code and improve clarity. Signed-off-by: William Breathitt Gray --- drivers/gpio/gpio-ws16c48.c | 66 +++++++++---------------------------- 1 file changed, 16 insertions(+), 50 deletions(-) diff --git a/drivers/gpio/gpio-ws16c48.c b/drivers/gpio/gpio-ws16c48.c index c7028eb0b8e1..625336376b5d 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); + size_t port; + size_t word; + unsigned int offset; + const unsigned int port_size = 8; + const size_t num_ports = chip->ngpio / port_size; 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; - - /* 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; + for_each_set_clump(port, word, offset, mask, num_ports, port_size) { + port_state = inb(ws16c48gpio->base + port); + bits[word] |= port_state << offset; } return 0; @@ -203,26 +180,19 @@ 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; + size_t port; + size_t word; + unsigned int offset; + const unsigned int port_size = 8; + const size_t num_ports = chip->ngpio / port_size; unsigned int iomask; unsigned int bitmask; unsigned long flags; - /* set bits are evaluated a gpio register size at a time */ - for (i = 0; i < chip->ngpio; i += gpio_reg_size) { - /* no more set bits in this mask word; skip to the next word */ - if (!mask[BIT_WORD(i)]) { - i = (BIT_WORD(i) + 1) * BITS_PER_LONG - gpio_reg_size; - continue; - } - - port = i / gpio_reg_size; - + for_each_set_clump(port, word, offset, mask, num_ports, port_size) { /* mask out GPIO configured for input */ - iomask = mask[BIT_WORD(i)] & ~ws16c48gpio->io_state[port]; - bitmask = iomask & bits[BIT_WORD(i)]; + iomask = (mask[word] >> offset) & ~ws16c48gpio->io_state[port]; + bitmask = iomask & (bits[word] >> offset); raw_spin_lock_irqsave(&ws16c48gpio->lock, flags); @@ -232,10 +202,6 @@ static void ws16c48_gpio_set_multiple(struct gpio_chip *chip, outb(ws16c48gpio->out_state[port], ws16c48gpio->base + port); 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; } } -- 2.17.0