Received: by 2002:ac0:a594:0:0:0:0:0 with SMTP id m20-v6csp805243imm; Tue, 15 May 2018 09:24:40 -0700 (PDT) X-Google-Smtp-Source: AB8JxZroHGeqPP9XWITUKKNl8YVpZkvrTPdqbuW4E3V6ZOfII7uP0n5wjA0Ja5qPxKGcnXDan/8K X-Received: by 2002:a17:902:6b09:: with SMTP id o9-v6mr15406949plk.256.1526401479992; 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=ShPIHzwgUU6qHigJcO4M1mpAW2HYAeM7NFt6WrjJOrvtU54CRtJwBrLlyAf1wcpb6G aWiK+7gT43QGP/JxpBmprJ5MqxQWFdK5Kk12GW06k+t1gSp7Ur8ghT+/CtJzYYI/9i8O DkrEQDCxUU8FFrs823A8GsuV9M58rEhSBuWzwbC80uQmwZRRXd8a/QOZHzPaO2RKvYNQ uyW/mLCcRQykoQHu9ByE3vM8+4M1zRMR19P4hlhQX2IF5mldxZIyGMTu4UdVsyPgyyWd J88Si1AMSWuuQImKZ1mCdiNKOrWYjQgEnvmeHAFpSYJ8JMebDk57yVVM/CzCEndeWIUW RefA== 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=4t9I9klQQ8DpB7w8AbzTMPlX1P6Su0J5LCLKig5N73k=; b=Tul273CCrJrethY6GDo3WfwOHlx9behMYCsqAtwe90QkTGQKJyxdKTIMflWQo9IPlJ FMNwfLmejgrfOk0XZhD8fxkw9KBkO2Xe0kX3UoXSpqdkgvvn9xMx2kPm2wdnLvhsXKR9 VeOvp2Nd17354BWDznkiXJJcpcgIUuY/C3+fTZ6Y+tvSrBUAFqQ8xgr/uV+YIfAkM2Bt C3gqIXU+B56KxCQH046KSTOCYqug4ZNHc8BhVtcdvC/eoR1vE9GSokbZF0UMEYsjKfjJ x+MQOTV56+oaJhOuA4Nb3av3aVxQ4DlijFMoX602tH3aARNa3hfLfJHxLj/F/+RKOvvD +fhQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gmail.com header.s=20161025 header.b=oMJfnsu/; 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 f11-v6si393323plj.58.2018.05.15.09.24.26; 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=oMJfnsu/; 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 S1754234AbeEOQXr (ORCPT + 99 others); Tue, 15 May 2018 12:23:47 -0400 Received: from mail-yw0-f194.google.com ([209.85.161.194]:35892 "EHLO mail-yw0-f194.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1752002AbeEOQXp (ORCPT ); Tue, 15 May 2018 12:23:45 -0400 Received: by mail-yw0-f194.google.com with SMTP id l15-v6so243546ywk.3; Tue, 15 May 2018 09:23:45 -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=4t9I9klQQ8DpB7w8AbzTMPlX1P6Su0J5LCLKig5N73k=; b=oMJfnsu/UsITQBCutoO3+KU1hnXZHNlqYvNIwSwr9hSnGJCwFbWI0LchIK2Ti9luww 2IhmjmxZgcZ3juflyL5BEfd8yW/BK7BoL6R7ggcErNxJ70az25Devz7g9SDlCfiiYz3E n5XHcT+AO1qoVtCbHMGYR2sQGc4UlLd9C5XDIQDNCK5qQloJcsmWWU6nqdoGkKeUu8oP E0dF9XmZa5sAuLG7HDfYYG4LxifgG9jr0oTnN/nVQmDnTGiidTrFe08EuLmoBNyn4q9e YQEckY5edVersWUtUGDziCKLRNw6IgH0hV/PdgoxL+6Z9mrONGiwL1ikXHLldgJ4XQGn iyUw== 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=4t9I9klQQ8DpB7w8AbzTMPlX1P6Su0J5LCLKig5N73k=; b=s+ZzvygH5+f1h42Zn0kyOJzDTHtW7mxXcKIA4w13Mm+LMvPxX+okh7BjZNBC14pR8y TGPV2jk1Pldk8FTS9oRc+CFnJxqCQe0A6jwwDFWRr3btiO9tmGsZXwNjPvAhsm8S2xCX uZgoHufs+uCH7+Ev35KVf7oeeVmsWkcWhDLoMFSEqiOm/ztMnXrgc9m7ERI98ijqecz/ b4ke5nSYvWepufR82b4GTH4l+DjRYltipzwfDPW6sg6pRLcBqz3fmoOYC6+vKnRCNUyS i0lxtJxGC7HD21yBiLil448Rtk2yUvyTkEaq3Ud/V88vDRyomNBTe4hIUf0N658FGOmF jJzQ== X-Gm-Message-State: ALKqPwcYpvTmnDYCwfYnSxZzZKkIbZeAXhMIBmEx5Olo6vPCSJevkHVh oP10e/LLFkLQPo+8nKAxfg0= X-Received: by 2002:a81:f211:: with SMTP id i17-v6mr6587528ywm.160.1526401424800; Tue, 15 May 2018 09:23:44 -0700 (PDT) Received: from localhost ([72.188.97.40]) by smtp.gmail.com with ESMTPSA id y2-v6sm145644ywf.76.2018.05.15.09.23.44 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Tue, 15 May 2018 09:23:44 -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 7/8] gpio: pci-idio-16: Utilize for_each_set_clump macro Date: Tue, 15 May 2018 12:23:39 -0400 Message-Id: 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-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..6d748c6e59cb 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_clump(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_clump(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