Received: by 10.192.165.148 with SMTP id m20csp4304701imm; Tue, 8 May 2018 06:28:04 -0700 (PDT) X-Google-Smtp-Source: AB8JxZo1csgsogGtOHVinHE3d94IiOuMu9YHp9qAC7VGAESXmqB6Tw8piUIGRsFIEPxO4fAthjgD X-Received: by 2002:a17:902:8f82:: with SMTP id z2-v6mr38379373plo.350.1525786084574; Tue, 08 May 2018 06:28:04 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1525786084; cv=none; d=google.com; s=arc-20160816; b=qbeabcvn0kD0UbOdwv7WiGellvjlnYsu/M+schKXPsQBdUqse1GYGxkQaPz/1wl0cx l/V7yweOL7oY+9kRTT78Skktlba+Na4M0Cm+KbyW86cnlYwbJ8IxmB5LktgJKqh3eN7P AMHjIxNhbR3D5iHXrThwAVrKwa40tk7jsbQ4hsJ3Zh+Xf38NN/JT1UJydORvHPfUgshB vAxAJXqeq4Q66XQVoMdgAmxZILQ3GIdKVFhKn6pWeBd22Or1+b4ESAkPPUzidQuwzd2f P8kYNBKrCMRN+BbzIQbjeKPbRW847f5i+VKNVUtrwvFdqWv/Lfgk6VyB/Dw2D2N2UcLs b3FQ== 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=slf1J3iHpjNeA4Hre3fVutRjHc1MIIIvq7nrD4k34rM=; b=CAc+04HHhrRlql7A60oIC8neh9M5Ik7ytTpGZDDaYEUsZBsufS09jfFtN05bb6bnI4 ITU+jn1QR1sEDvPp3j4Pcv4+STCCAjcKF3fmIqtuDmVULRPc2duo07Mrr9fcVQDOVx5j mKdGjLIaT0YOhxcS4OUf4Z9V5IIKgXm4OK9Spf9rIVpHxa28LdNIJ4ukKvR5reJDppXk Z3kXwEA0Sp26xJzCwLwDhrOCkIkY1Ae/TKvCmyVPDTrMLVWrya+FgY8Z1nTAY0PW23Gz vdnBm1eqaucuscLT+7ZZs54zn2CD8gg9aZdqqESai1boc4hegWGmKEwm2M7BL6UM8QVn 9bTQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gmail.com header.s=20161025 header.b=lpGNUHeR; 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 bh1-v6si18245058plb.481.2018.05.08.06.27.50; Tue, 08 May 2018 06:28:04 -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=lpGNUHeR; 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 S1755226AbeEHN1V (ORCPT + 99 others); Tue, 8 May 2018 09:27:21 -0400 Received: from mail-yb0-f194.google.com ([209.85.213.194]:43032 "EHLO mail-yb0-f194.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1755193AbeEHN1T (ORCPT ); Tue, 8 May 2018 09:27:19 -0400 Received: by mail-yb0-f194.google.com with SMTP id v12-v6so2165846ybl.10; Tue, 08 May 2018 06:27:19 -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=slf1J3iHpjNeA4Hre3fVutRjHc1MIIIvq7nrD4k34rM=; b=lpGNUHeRedhgHozPgIzVjQZkKYFIEX0u15rIFChbLUXL0fq5+6b9OO1mdTT9pag+Gc sXO17T7MSjB6SP0enZqdXo0ohe233bwyWK0LKYzp9lYgi2pGyojYZuLTxmpkXtiaEvTC mDkC/4SznodG1zlIyO7APvbmVkrbVQTmPs6dUHS8yNhjgCCnSo+UCSGD0xGhqp7dxa0v peo5feLV5CZPvxIKA7FyMGWr6TQBzAdNnwiO1Um0ju5tgtYLB2+j2yXr+cylweB3Lk3H QwrzKdXgt8XaBhdpr1bbXxqCy+bRrN+rPFrSmz0dzB7UKt4p/SEe3v6Eu0RXj0upN/iZ pVTA== 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=slf1J3iHpjNeA4Hre3fVutRjHc1MIIIvq7nrD4k34rM=; b=s2oN+tx25RznLZmFGLZXfFRHkt34ckNviGdpmCc2/5vxqODkWJWlN9M01wis5kmsm9 IMZNRVp0jPt56DybbKEyvGmjczRdwndydOywI5sfBC+n1hIGMS7D5lFpLCwSHYeQKCYm lBIta0RxR6G5/E1WurNUsHEOpr5wjnmvTpBY2LRv7PJAsXPWfbj08BEVMn1tkQjPNYNX hF67GytJTYv/Vyz3de6rqA9uvFJuQnKAIcIJOH/ofK7SwW+K89HQF7rTYWSq2y1pGU3m jBM5Nxc1UKBTWzeLLEhmx7poFHXhcQ2q390TxGS7AgGrEgsFmWNwIgiYPgYqsuZQLT3R sXPw== X-Gm-Message-State: ALKqPwcyHqHnRBpdTw9QuqSkHYUxx609vgcEV6g03EO4A1fUUfBZs/0n MYeyLRJqXyOgoy2Cc2i40I4= X-Received: by 2002:a5b:12:: with SMTP id a18-v6mr6707798ybp.524.1525786039241; Tue, 08 May 2018 06:27:19 -0700 (PDT) Received: from localhost ([72.188.97.40]) by smtp.gmail.com with ESMTPSA id z24-v6sm4807863ywj.99.2018.05.08.06.27.18 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Tue, 08 May 2018 06:27:18 -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 3/7] gpio: 104-idi-48: Utilize for_each_set_port_word macro Date: Tue, 8 May 2018 09:27:13 -0400 Message-Id: <20a56dc5911439a36485faaf2e515dac0ecc6206.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 the get_multiple callback with the for_each_set_port_word macro in order to simplify 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..414dc8de0bd8 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_port_word(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