Received: by 10.192.165.148 with SMTP id m20csp3221464imm; Mon, 7 May 2018 08:37:28 -0700 (PDT) X-Google-Smtp-Source: AB8JxZrQQ1/ZUrcCO07iZ/LwLJ2JC2K5fD9FzB7I2LPl192E4WdXjCISiqNb/MNOovvKVL/buo5l X-Received: by 2002:a24:641:: with SMTP id 62-v6mr1600430itv.89.1525707448729; Mon, 07 May 2018 08:37:28 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1525707448; cv=none; d=google.com; s=arc-20160816; b=EhVmNqyxpXLb6CF+rskUhJRXt1/7fUZULAcNLWhZpBaB7z71c0eUqvY0Qpo7uaYZZ5 kP1/ZWNUszFJbzO22eVkCCh/c2nGgfsAOjP/atfsoUJ9ohblfEaRwMuV5iKvVZUzD6Go OEZ8gpqFj5Y+VtFZMNYUpT4F0we9jOoub5nBcK2uWJr1+gtLN6Oy01lpdoHg2mDg5hTJ yQD85EMzcSnoBJpY4Dmka4oMMfWRpr1KkI6eJO6cAeR/P4hxfFhXd/H8EVDyg6oagXxD 5EwjPPqGwWVhxsWo6CT9Oljhh11gFAplF+5pEMRLhDoIrsJulA9JOCZcBVPhp6yIGfGR VMTQ== 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=N1qr5mPLUp6tibcrgruG48HDs2QXpm3E5BwEcWdVbcyl/JcT9bVK48YoLzxudEMOPT /btg+Pbvdeq5D0Y/FazE0LMN5yvZlayo5QqVgARBZ76zV2tAIJ8Va9d/kI2TJQOl0NXr 232Rbi61HEOyESjJ1/DQ54jTzVlxGDVSW2ifyUYrPn1mXk4XZQO5eo54r+aLy8aGmo9P SsnGrifALcvDFosrJ3yKZKdY3dOH7m6IIeSpf2PbcCrMSHx2UND+lYLsMjKT/iVbV6LE ME0qjuqFoEzN6wBmQDqAJ8fR9w5ARMu7iiLhvqIjfKr0/PFdhmwEGGdBuN4OqozoZX1F 2YhA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gmail.com header.s=20161025 header.b=j4PsHhPr; 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 e134-v6si7328282ita.67.2018.05.07.08.37.15; Mon, 07 May 2018 08:37:28 -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=j4PsHhPr; 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 S1752642AbeEGPgo (ORCPT + 99 others); Mon, 7 May 2018 11:36:44 -0400 Received: from mail-yb0-f195.google.com ([209.85.213.195]:34389 "EHLO mail-yb0-f195.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1752320AbeEGPgm (ORCPT ); Mon, 7 May 2018 11:36:42 -0400 Received: by mail-yb0-f195.google.com with SMTP id b14-v6so10076954ybk.1; Mon, 07 May 2018 08:36:41 -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=j4PsHhPrj7CE3vvwsWWeIiErt4byPDF8eqUE4hIx3LugW/Ty/Wo5JJCAYJRrf/u4wz J2RvXu1yGoEhssEpv4VIzjPhDVA4o1OwOfgti9BUzvhhupyFuCOOd02AxwNSVVT3463m p/2EsY3257PNjgzlZIlghmSc7xOURudMW5DIsxZAPJ+q3Kl5esPdQjqSU3X8AXW+xMOd 95HAfLm5glHrxxIiaXqBVLH0iYJ2wmYYbxoalg12WTqlml/TBCuwww8BteoJuY1gVwJ4 Z/I8No6yW4Nz5v09EHQ1LfyhS2pkwu6sRQKRmI8Sp/taDBU27lLEML8s1R+4aF1SU32J URog== 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=da2P1g7uQnKGkQfxW3zd5ioXyhc4vsUxV6cgiH4rzjoOT9L7TsY8ooUPbx7myiq92V xA52XQU2MpJ+dD5OWQuZdOCM8XVYPypvB58VfdsQMUwcVMF4FF4t6V7vBPutsJ8pTrDK f6PYkBKxbWTii+Y+0CYjflHUgu/gxHTYNrpF49bmKbTZUNRuTFuovEfjDJkEzTEoa7vi uY3U0iHzlYNAEMt9NHBAyQ9HFr0iuvOsFuRsoqsPq7u2OBuXhB/a31IgA8uZAub0WsQU AcUKaYoWjHaBefwIRpY4ukcwejMEBnvZn3yroswkAR0fcjkjwpSDY3uvrmqZpyhm+NDu 4mwQ== X-Gm-Message-State: ALQs6tCj4MlYAbtxKOlaogoNjnZgvwzhGKA0vmvlOQwq4zEYeoBP+EKG M8pQuTyWMSr/C7KYjjLA7Qk= X-Received: by 2002:a25:c708:: with SMTP id w8-v6mr23320398ybe.486.1525707401224; Mon, 07 May 2018 08:36:41 -0700 (PDT) Received: from localhost ([72.188.97.40]) by smtp.gmail.com with ESMTPSA id y2-v6sm3623322ywa.18.2018.05.07.08.36.40 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Mon, 07 May 2018 08:36:40 -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 6/7] gpio: pci-idio-16: Utilize for_each_set_port_word macro Date: Mon, 7 May 2018 11:36:34 -0400 Message-Id: <71119902fde043315d469f790e645666cf59b310.1525704095.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