Received: by 2002:ac0:a594:0:0:0:0:0 with SMTP id m20-v6csp771681imm; Tue, 15 May 2018 08:58:35 -0700 (PDT) X-Google-Smtp-Source: AB8JxZp2YT+/lP6CaqGz98JfdfnPs/VeUZD6JzwPJ+PYIQB4Dni6ogEZLGraq2aB5MtOo1mWL0pV X-Received: by 2002:a17:902:a711:: with SMTP id w17-v6mr15069722plq.292.1526399915387; Tue, 15 May 2018 08:58:35 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1526399915; cv=none; d=google.com; s=arc-20160816; b=BnzOzc3UJAkRyFtau5hl9Ztg35ZRZ+RzuHf1KbRip/Sf7zs275lMFZXevy8/pLFEtN viroCB+whCLgtHL/OPt0vsOm//Ckxe3TAWZrPiUty4kshDCFNjtMRz6Cab+xFlX3JowF V4l6sGbdn+O3Xzjx29JPIsbmIW/v9xzR5SY3E6AAtrChOJWAcoqH30XzPq6GW3wuytC+ 3rQ14u32ygsZUdSql9wnUqbfFgYisTDryS3kYtFYXCpUrR23uMnL1WuGGzTXSr2y8wyb OIiYHVf+ioaRNdf6n7hnrRCEwcuqlHCSSBD94oSy/zN5t1bDJrSwP4oZI0PnuCu6+8kG ddoA== 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=IoD1lZO4k+PKyMx13F60lkg2p5U45xTp/+buSWctes9p/dsGA3yBjqGGTQNYa2soqT gJ2mF4B7caUup01WuFFf/K26shAxw271y7s2ZH6vTpq5QXYQqSEUMd4fGt07YoSs2tNn JQ9++XQPENy8VkY0rTb1Rkxo/W1eZcHXpcz8ofBIwrc6FWG8/j/LyfgFfwpYRJ2BFswf l3jl3xu0k5VbvEwLFuvaK7gRf45JDnittHsdGtkOa/8cQ3Bl8F6TSvV/79zPzlDckK0D HhzXK0k1sy39lzXx5HbZO9klv9wY4FYh6+xch0cgPAL7Yn4zjyaTG37OXeQsEAz6lp27 +xQQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gmail.com header.s=20161025 header.b=QDKMt1dM; 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 q192-v6si309126pfq.307.2018.05.15.08.58.20; Tue, 15 May 2018 08:58:35 -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=QDKMt1dM; 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 S1754234AbeEOPut (ORCPT + 99 others); Tue, 15 May 2018 11:50:49 -0400 Received: from mail-yw0-f195.google.com ([209.85.161.195]:35445 "EHLO mail-yw0-f195.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1753977AbeEOPuq (ORCPT ); Tue, 15 May 2018 11:50:46 -0400 Received: by mail-yw0-f195.google.com with SMTP id m8-v6so210272ywd.2; Tue, 15 May 2018 08:50:46 -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=QDKMt1dMc3g1RQ7EpNnEBgjbw2a2FfG1pPs5CbWgxn3InLJjw44uepeogTOu69ioTo /Pn4ZiuY+tramvXdvoEBhgI6W1tEnPYWWZjj3nOF4qGbKmIxj5Q+45500pJ6VekqPMlX o4JgqaUOccoaqX57XE5Qm8ApYUcngjVn/dHRFJ4KFyBDI0XvqfDgX/pTX1bOtUeHuQHZ MX3HOA4Pd9wiV0kXHO5nF87I2kybFp9S9kI+D8yQZG7vWxyFf0ik26VL38GL0ohr2e3t W5NRbRD8uVE+d3t45OFzStyEX4TJKihY9eTmar6L4Rl7ELNNOzT1kKRCoCmdMTd9fezX snIw== 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=XfPUnAQyln2WWbP+ay8PxujCfHBqsy3Pzm6tqKIt7VgTmfIo87AkalURCrI3dMppl8 ldW5JWzRjc7CsUhZ4T/qjgRZhrrWNic+MtRwnO6g4/p58KGdltILHWdr5YSqhWPJwS3E kGpXMpd6ou77Ag87l/sIEBTx/oFASSES4jlZZIavByOwnC9Z3t/p6LcnuBJAL0hsahO0 WwF5vXW3ZKejHL4/aDNUGhiVZiHOwhg5mOd1Wi9XEjsDSD0Yhbq+HKODtfMPbjJHIwbQ KxQXa7gYrYFwHeZQkia+lRkLEAmlj54Ez9aoFZ9w2Zoza3gQsJsSrikWIPZ1kIuNrUSO NuzQ== X-Gm-Message-State: ALKqPwd1zwy7DtZu5siN21XcbfbOCh6KR0kASgDxjVYShxoyjFIx8E+H N2nnwz+nApOQWkPZGzD1KlI= X-Received: by 2002:a0d:e6d6:: with SMTP id p205-v6mr6885784ywe.9.1526399445901; Tue, 15 May 2018 08:50:45 -0700 (PDT) Received: from localhost ([72.188.97.40]) by smtp.gmail.com with ESMTPSA id m125-v6sm145892ywm.53.2018.05.15.08.50.45 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Tue, 15 May 2018 08:50:45 -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 v3 4/8] gpio: 104-idi-48: Utilize for_each_set_clump macro Date: Tue, 15 May 2018 11:50:39 -0400 Message-Id: <49e61fc62ad34928ae05eaa77d757070636aefb8.1526397764.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