Received: by 2002:ac0:a594:0:0:0:0:0 with SMTP id m20-v6csp805460imm; Tue, 15 May 2018 09:24:51 -0700 (PDT) X-Google-Smtp-Source: AB8JxZqbgL/3W1y0wYKjUDsDgC0pvDR9xz0n0HgrUKnxWxRXoi6d9fBmCI894AM42+ERokcrXByE X-Received: by 2002:a17:902:380c:: with SMTP id l12-v6mr15253203plc.19.1526401491472; Tue, 15 May 2018 09:24:51 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1526401491; cv=none; d=google.com; s=arc-20160816; b=Nv3b2XAiockh8WrH5B1OCZ5E280R7PwrsJ/2fUanptuBJSQomI7qg1pjRq3zEbeUoL yrrGKPPvXpW+e4+X+KA1IpVlLg/XtQxlCOc2gOqL7+B/gjBoM3HHNaz6EpKNJyHhZFY3 v0/Nmhbnf6iOqyIUSohhWtFdvxV3L2yuKvl3+XQ1w98PZQCutfer7W7RPp/w5+BMAxfF 9CtcBq1EKiPIip/l4gT/qam1kgM6XAq5rMV7NYInyqRV9Wdy6wwNoCuePyWpayIzena3 HpkZuOkphsxsWlu50SxCoqLHyGs4eXI3nRBh4I7vrPKlwqAp0T8584N331KOzypbPQNp NWXg== 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=2U7Ozw2SgAQBqAZnsfCoNU2PQB0sCh7oHKc5SOqZD3A=; b=eTbs7YNgOvr92MyqbAo9oFyzm8hxLxM2B4EjhfLlR5flQWGeg+8qGK5OWRnckYhpBN PwDG1ZHieqnUhv26uCs5zPTvMM4bf9JhVotZJZfCeWIVZetutyvBCB+KRaXBtVH+Z4Rh 9gbUmCOxLb/+TvFo4jxIoemuYSRdfH7dGyrxCB7iVBILE/sgbIY+8NY9mZBNdllwQMSl cVN0qDmu+iMIpDNlXKDEhpC1DA26Pj5AHw5BGXnOkS5yfozlFkPSS0ir4o92vFZh2RVg +T3qhAKW1yG2qgFO9/JB5K8rLgMo8CDnaDmhxqEEfBMDvATHzPjeJXjXk4YCG/uqlHZi Le+A== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gmail.com header.s=20161025 header.b=NQMGzK9d; 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 5-v6si332157pfd.73.2018.05.15.09.24.37; Tue, 15 May 2018 09:24:51 -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=NQMGzK9d; 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 S1754164AbeEOQXI (ORCPT + 99 others); Tue, 15 May 2018 12:23:08 -0400 Received: from mail-yw0-f194.google.com ([209.85.161.194]:35029 "EHLO mail-yw0-f194.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1752750AbeEOQXF (ORCPT ); Tue, 15 May 2018 12:23:05 -0400 Received: by mail-yw0-f194.google.com with SMTP id m8-v6so245175ywd.2; Tue, 15 May 2018 09:23:05 -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=2U7Ozw2SgAQBqAZnsfCoNU2PQB0sCh7oHKc5SOqZD3A=; b=NQMGzK9dHqaZwtP9jFu5a/W8u9WU0lpMbC+8FtMHw+9N84IeE4+qKcQAZHX6lGEg66 de7Ga2dUtJmPnmgu5duHWmX3P3mb/gCVVKuVI82XLna/5qFll5rjVpzjKYA7CFpSKkp4 lEJVQIQE7GWujOjIFCZrGIH1AOQzH7P3yNoTQnxdy3NmEhezK/zOVrpx2lixux4guVeU OkxaW2EfEhq5oxjO+hhI9SJD6GUyAHMFe2SMCyJeChtxqYqQ10Se+UmIYiGxF4bCM0Ts C1+UpDhR5bNN3kd6Xvh5ggo4ZgJBxdnyl2UjPjNNZzgfZ4Pjo7e7Zs2ltpkU1NC6ASje qRkw== 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=2U7Ozw2SgAQBqAZnsfCoNU2PQB0sCh7oHKc5SOqZD3A=; b=rSz/B5eodum0VJVd4riidrfQwzzqT/4sJJImtLB4hJIR90uyXfmJSd14mXlHRdLcJ/ SNBfDhJPjh6uXBqOk3/E7TeMfyEd2kEhPtUbMUheGVDnm84b4yVgp4/DMudQYTw6Pn09 EUd6Qi8yBO2h94+Ta/3OkciUmfmfQIpVa+1hLAxIWeLpFr8PlqpPu3vi4DqBEbyXEzpb bkh+8xhl5iY9FJ8aA4dHeQifLvnNmQUBuHnAGYd6xubfQDQNTSegHraN952uLSfh9tv4 O2Xc4sAKnjMkO666OnwI2LjhCrtnlLKtd89lGJ1zY8f8N+FjJmn5uPPHMvOzAsIlL45F iV8Q== X-Gm-Message-State: ALKqPwciNkikKkNZoM01XB04Nf2JUrajwxcwX32E0IHiZNwlf8FfsAzB DQ40sXABdJTcZ7oACXjPJpiZiQ== X-Received: by 2002:a81:37ce:: with SMTP id e197-v6mr6933867ywa.340.1526401384905; Tue, 15 May 2018 09:23:04 -0700 (PDT) Received: from localhost ([72.188.97.40]) by smtp.gmail.com with ESMTPSA id 205-v6sm136882ywv.79.2018.05.15.09.23.04 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Tue, 15 May 2018 09:23:04 -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 4/8] gpio: 104-idi-48: Utilize for_each_set_clump macro Date: Tue, 15 May 2018 12:22:59 -0400 Message-Id: <2dd756692d0fdd20be629ea341a0e563c079f374.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-104-idi-48.c | 32 ++++---------------------------- 1 file changed, 4 insertions(+), 28 deletions(-) diff --git a/drivers/gpio/gpio-104-idi-48.c b/drivers/gpio/gpio-104-idi-48.c index 2c9738adb3a6..f8de5560174f 100644 --- a/drivers/gpio/gpio-104-idi-48.c +++ b/drivers/gpio/gpio-104-idi-48.c @@ -94,41 +94,17 @@ static int idi_48_gpio_get_multiple(struct gpio_chip *chip, unsigned long *mask, { struct idi_48_gpio *const idi48gpio = gpiochip_get_data(chip); size_t i; + size_t word; + unsigned int offset; static const size_t ports[] = { 0, 1, 2, 4, 5, 6 }; - 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; /* 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 = inb(idi48gpio->base + ports[i]); - - /* store acquired bits at respective bits array offset */ - bits[word_index] |= port_state << word_offset; + bits[word] |= port_state << offset; } return 0; -- 2.17.0