Received: by 10.192.165.148 with SMTP id m20csp4306108imm; Tue, 8 May 2018 06:29:20 -0700 (PDT) X-Google-Smtp-Source: AB8JxZomoUnFD5+jnPzMq/4CM2NdScnfkh/AhswUCzq1am/zNgMgyDWWH0oowm3ZK8CH9vd/DsOC X-Received: by 10.98.104.131 with SMTP id d125mr624113pfc.26.1525786160853; Tue, 08 May 2018 06:29:20 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1525786160; cv=none; d=google.com; s=arc-20160816; b=N44VPb4LdMFT75nMP6oin9UvUPbuTwY0rOvcIPRYwzIE0LbLYEv/lyWwoOR/r2r+/e SjGEl7m/ZTbINPdSqlJ6MnxOeanhsdofbyDqN2Mt0t2CqNHCzcbbOYQHHe36P2UVlHJW 4xqvHY4PfW8tHgX+8lXukKplZktfGIK+hi+hFTDuoZE3QNZk9QJs7gMWeHy18/KCcrsB 606xJCH9O5tksNhgrUfjdeFKwVC2tAZwo2bg7Jc1M/kylQF22mGDZ4SAmdH1idajQjzh 8gpfGHvwsWqEyfX9omYp69/a0VySo0YPqQIUpyFUhgvdwUR+tfvaoL/iqdpFUulHrnlm 8JqQ== 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=3A4UFcL/bX0UJEmvMYaIqM/7AFjz8+PWXaKRAZfKHcQ=; b=tayI70IOb6rMLrd5TImWZoTB1g8my9szbNfcl0Ka/PKuc+D/PpC/dOp4Q4Umq3/41B VOvMckhOprS4TDla16dGVX7aOznHhplZCtSp3kCGByVaRTlB8eqsyUzELXpssOn27T6b WRkz2q5BbaB5qAzSazW093MGbVtnn/BmPAqVHAViNQYmS5UdPB88o93bUCxMqyqsmBRM 75fPRZVufjhNbCc2wCu98ddGD79oMnfmgl3xP6HasQM6zbjngLJEQlJcLUocyopHxb/b 8OCvbG4hQ/RfqpOaEH9sOqvdfIQ5SOCt2fPxUKYPwit7wKmGjhv7pqj0bRxKTvmDwirM K7Jw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gmail.com header.s=20161025 header.b=l4hiAee3; 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 203si11583802pfc.21.2018.05.08.06.29.05; Tue, 08 May 2018 06:29:20 -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=l4hiAee3; 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 S932219AbeEHN2P (ORCPT + 99 others); Tue, 8 May 2018 09:28:15 -0400 Received: from mail-yw0-f195.google.com ([209.85.161.195]:35456 "EHLO mail-yw0-f195.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S932168AbeEHN2N (ORCPT ); Tue, 8 May 2018 09:28:13 -0400 Received: by mail-yw0-f195.google.com with SMTP id m8-v6so34379ywd.2; Tue, 08 May 2018 06:28:12 -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=3A4UFcL/bX0UJEmvMYaIqM/7AFjz8+PWXaKRAZfKHcQ=; b=l4hiAee30NQC/e/jGO0w2l0ocqbtpAUQvuEYAeWd9MCgJ3orB0gU6zeEhA9kClF69Q wqK2stZi58qkiw5PuDY/pFdCzOB2O5MqTn9aQeWwLgzmMdeqdAj4OESHHFyJfg/ATRz9 g89cOk4Lckdw2Gloa5ffwjXcLFSpt3dnCatU/3eD/HAc59WEupgTdrhUhWVf/DEsU0yw +d+5JJZHPVs7gFN9bZSu/yrozs8VhuDPRIqon45h3ps4MHmKCGoyonK0An/IjDXvJXy1 ItX0mtvhSWaNK+YKJiM21N84thGuHskUFHto/kFoq/Epc5wC9p9NtKQDdmqS+aaIXHsL +W1A== 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=3A4UFcL/bX0UJEmvMYaIqM/7AFjz8+PWXaKRAZfKHcQ=; b=JVnWbP0IRKJKs+KEdXbaHRNVliugcbZTi8HsQe38NjC7JEIrUgyRD+y1pQbnhdYrJW aVbCdJbD2Gb9rAxUxkFzqKQRwWIbYtKOmU7LWe/Z5BorNAIY6e8dHSZrBbnLrECrPjPY 14ZWFJE+Jk4s7oXGNBi4EbrddgdQod9n23SeUxBKmjWsA5FUmWVOj4KgQh4O8amQnZRc E7dxg1ojJw7t+wnS5okpntd+7JxrEojtyK53qdOS8EK5yw4YKXJ/MmD08724AGqvDdrC xCKQQSlXn32I0vw2ysLXJA7YN1k1CMxdETp5QTlsOMqid7JRSWf0cwT4AbyM7K+A9LdQ gQcg== X-Gm-Message-State: ALQs6tAFMKx8A3RoZSuhVPyeTAyBl5kJoaCKJuwCHqdVdatLuAAMz71E yJdauhBd/tGtvHdGej2NZyk= X-Received: by 2002:a81:830e:: with SMTP id t14-v6mr9235417ywf.203.1525786092327; Tue, 08 May 2018 06:28:12 -0700 (PDT) Received: from localhost ([72.188.97.40]) by smtp.gmail.com with ESMTPSA id l126-v6sm11345329ywb.67.2018.05.08.06.28.11 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Tue, 08 May 2018 06:28:11 -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 6/7] gpio: pci-idio-16: Utilize for_each_set_port_word macro Date: Tue, 8 May 2018 09:28:03 -0400 Message-Id: <60108b1e9c1a12ce16a9edc4fc7ad94125e3aad6.1525785532.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 boilerplate code in get_multiple/set_multiple callbacks with for_each_set_port_word macro to simplify code and improve clarity. Signed-off-by: William Breathitt Gray --- drivers/gpio/gpio-pci-idio-16.c | 67 +++++++++++---------------------- 1 file changed, 21 insertions(+), 46 deletions(-) diff --git a/drivers/gpio/gpio-pci-idio-16.c b/drivers/gpio/gpio-pci-idio-16.c index 25d16b2af1c3..f5c759d70081 100644 --- a/drivers/gpio/gpio-pci-idio-16.c +++ b/drivers/gpio/gpio-pci-idio-16.c @@ -109,44 +109,20 @@ static int idio_16_gpio_get_multiple(struct gpio_chip *chip, { 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; + size_t word; + unsigned int offset; void __iomem *ports[] = { &idio16gpio->reg->out0_7, &idio16gpio->reg->out8_15, &idio16gpio->reg->in0_7, &idio16gpio->reg->in8_15, }; + 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 */ + for_each_set_port_word(i, word, offset, mask, ARRAY_SIZE(ports), 8) { port_state = ioread8(ports[i]); - - /* store acquired bits at respective bits array offset */ - bits[word_index] |= port_state << word_offset; + bits[word] |= port_state << offset; } return 0; @@ -186,30 +162,29 @@ 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); + size_t i; + size_t word; + unsigned int offset; + void __iomem *ports[] = { + &idio16gpio->reg->out0_7, &idio16gpio->reg->out8_15, + }; + unsigned int iomask; + unsigned int bitmask; unsigned long flags; unsigned int out_state; - raw_spin_lock_irqsave(&idio16gpio->lock, flags); + for_each_set_port_word(i, word, offset, mask, ARRAY_SIZE(ports), 8) { + iomask = mask[word] >> offset; + bitmask = iomask & (bits[word] >> offset); - /* 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); - } + raw_spin_lock_irqsave(&idio16gpio->lock, flags); - /* shift to next output line word */ - *mask >>= 8; + out_state = ioread8(ports[i]) & ~iomask; + out_state |= bitmask; + iowrite8(out_state, ports[i]); - /* 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) -- 2.17.0