Received: by 2002:ac0:a594:0:0:0:0:0 with SMTP id m20-v6csp805681imm; Tue, 15 May 2018 09:25:02 -0700 (PDT) X-Google-Smtp-Source: AB8JxZq8m5T2/XajX50q2anZuOuljHY90aLqMCkwNEKTE85QEal274j+UsatDPN2WDBcZQB+oz5a X-Received: by 2002:a63:5f95:: with SMTP id t143-v6mr12541330pgb.165.1526401502235; Tue, 15 May 2018 09:25:02 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1526401502; cv=none; d=google.com; s=arc-20160816; b=Y6eWfX4CtjFjcSIXCXy3OC0B8Vp4BmgOz2UTZT5rm0iVZgbsWEz54EkuxhCxAw6b2c 40DD0Jdb+8ZmprqfBcmjXRJoJ/2UVliXVI9NDbrUVHGolRHtGUO2k8o9XKgw0dnZWvPr iha8LTEfUNNOFFImMKhWMIKP9PFK+0eZk+ssM8ogT8zXoNGS1xB3EbyRfcoPEVLjU1Xr jMidfEl3N9iz7Kc5Kkks53ljGNbeGwPuvCLP/bXknvvntibDiJT2iuVErgvaAZLX1ehp LNiGZ2Cx73VKWRWPGK30CqP5t/xgU/D6oRcZuAJuvm/ufDSsgpcYTrFiSeUO9Lf5Ut1r 8BxQ== 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=TLBQUSLk/aso1SuCLv4JMP9OzoNWej0XaQvzNIL4VeA=; b=fpzSAyuxAnDQ1iyg/QkNIGR9yFkIP9Kn5L+R0AOAFjLoR7Y35MeJTR4DaNSW1V887m +gCulOeUMyQ95bbAayIoRifzw+o6IZWUTRY+KPEV/tIGVx0S4tqhFYlD6e8ZLrRS8Ck7 vYVHzmDUsMfiYfcPV5vUpbPcuDkY7EAUaSkXAfGUbPq2lQHXoRLN7HpBJyXraWLVARlZ VsndbBPdqzDu+X8b7eUhq3RdxbiNFewDJyfJrMafiOHcgbMM+QRbmt36nJEB5K49WZQ9 +P7LsEmAu80aH0e6K4nGrfelPVt3uY/xFEiePyU1gaSsIpGfFhwgfVcWLn2Oow8vc6Ca lZKQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gmail.com header.s=20161025 header.b=bdJUFf6Q; 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 m26-v6si372694pfk.56.2018.05.15.09.24.48; Tue, 15 May 2018 09:25:02 -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=bdJUFf6Q; 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 S1754122AbeEOQW4 (ORCPT + 99 others); Tue, 15 May 2018 12:22:56 -0400 Received: from mail-yb0-f193.google.com ([209.85.213.193]:39160 "EHLO mail-yb0-f193.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1752750AbeEOQWy (ORCPT ); Tue, 15 May 2018 12:22:54 -0400 Received: by mail-yb0-f193.google.com with SMTP id g140-v6so253742ybf.6; Tue, 15 May 2018 09:22:54 -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=TLBQUSLk/aso1SuCLv4JMP9OzoNWej0XaQvzNIL4VeA=; b=bdJUFf6Qy8bqBOirtCHEgDtl3t0vfn9gzKdHbkZAlGccxoXM6O7Lj8aJNTIxPGZvVt /XmGH9pOeLaoIdtQI01Fyhj0/QH88J2R+LWW8eFnOCDDXq4Ei6d5UGzDDxKcZDt97f+i n3lRmrgpO/U/HX9MDkTZ4TrbDXEiZxSMRdpU+fe/X1maMwirAf4mbZBGkqCwfuoi8xUo EQVGGSy/2A9QE0cfGSSR8PtNrAZawbBxxL8tevAwdJm8nk+oGA5I7yO0NXmkkHxfl0Ti GfArWH06Fynq55TENzYwpoWMbHxw+jR6nhp+2r5nFDhYAteMVZ2owQjsALyL2MxWW+CT ZITw== 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=TLBQUSLk/aso1SuCLv4JMP9OzoNWej0XaQvzNIL4VeA=; b=SM/UyQ7RGD3IqmLh64xvVHLr6X8U57IlxuUhke5fi278S4d6sAKSeRpxEdoDufCJOq xXqyUEbL9enJVU3cmU4W7pEPJ1la65lm8Wc6yb6YKdBNhhjHGEAWQPdxLudQJ4JvwTbx PoT1PasgD1J77dLzrNu6o3JopVDsBZcSG5F9eWCFqzwCOoAbyRChmqUphsFDBDPx98P8 az7ZXsXjqNAyBVrA35krBMIubf5JpnGdMFjVBUJKuovfmMdj2i/mAs5yS9K9M2uu0LcK E8SzjVwUCFPR0mT7N87buv+G7IMOsFiomAoIfZZNaULTyFHF6Ksu9HwAw1X8QltAyy3p 7Ckw== X-Gm-Message-State: ALKqPwdrT+Ob66JvMXkDl7GBo41uBv78k2g6WH4UtUXKk0He7jKZNq1d mZ1ByJvQjlFo7+F4DQOwn8g= X-Received: by 2002:a25:bc85:: with SMTP id e5-v6mr9078820ybk.33.1526401373938; Tue, 15 May 2018 09:22:53 -0700 (PDT) Received: from localhost ([72.188.97.40]) by smtp.gmail.com with ESMTPSA id w138-v6sm151285ywd.41.2018.05.15.09.22.53 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Tue, 15 May 2018 09:22:53 -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 3/8] gpio: 104-dio-48e: Utilize for_each_set_clump macro Date: Tue, 15 May 2018 12:22:48 -0400 Message-Id: <3c9de7a04c7b02555067d17d55956bdb0365ae50.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-dio-48e.c | 67 ++++++++------------------------- 1 file changed, 16 insertions(+), 51 deletions(-) diff --git a/drivers/gpio/gpio-104-dio-48e.c b/drivers/gpio/gpio-104-dio-48e.c index 9c4e07fcb74b..77eeaa36094c 100644 --- a/drivers/gpio/gpio-104-dio-48e.c +++ b/drivers/gpio/gpio-104-dio-48e.c @@ -183,46 +183,23 @@ static int dio48e_gpio_get(struct gpio_chip *chip, unsigned offset) return !!(port_state & mask); } +static const size_t ports[] = { 0, 1, 2, 4, 5, 6 }; + static int dio48e_gpio_get_multiple(struct gpio_chip *chip, unsigned long *mask, unsigned long *bits) { struct dio48e_gpio *const dio48egpio = gpiochip_get_data(chip); size_t i; - 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); + size_t word; + unsigned int offset; 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(dio48egpio->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; @@ -252,37 +229,25 @@ static void dio48e_gpio_set_multiple(struct gpio_chip *chip, unsigned long *mask, unsigned long *bits) { struct dio48e_gpio *const dio48egpio = gpiochip_get_data(chip); - unsigned int i; - const unsigned int gpio_reg_size = 8; - unsigned int port; - unsigned int out_port; + size_t i; + size_t word; + unsigned int offset; + unsigned int iomask; unsigned int bitmask; unsigned long flags; - /* set bits are evaluated a gpio register size at a time */ - for (i = 0; i < chip->ngpio; i += gpio_reg_size) { - /* no more set bits in this mask word; skip to the next word */ - if (!mask[BIT_WORD(i)]) { - i = (BIT_WORD(i) + 1) * BITS_PER_LONG - gpio_reg_size; - continue; - } - - port = i / gpio_reg_size; - out_port = (port > 2) ? port + 1 : port; - bitmask = mask[BIT_WORD(i)] & bits[BIT_WORD(i)]; + for_each_set_clump(i, word, offset, mask, ARRAY_SIZE(ports), 8) { + iomask = mask[word] >> offset; + bitmask = iomask & (bits[word] >> offset); raw_spin_lock_irqsave(&dio48egpio->lock, flags); /* update output state data and set device gpio register */ - dio48egpio->out_state[port] &= ~mask[BIT_WORD(i)]; - dio48egpio->out_state[port] |= bitmask; - outb(dio48egpio->out_state[port], dio48egpio->base + out_port); + dio48egpio->out_state[i] &= ~iomask; + dio48egpio->out_state[i] |= bitmask; + outb(dio48egpio->out_state[i], dio48egpio->base + ports[i]); raw_spin_unlock_irqrestore(&dio48egpio->lock, flags); - - /* prepare for next gpio register set */ - mask[BIT_WORD(i)] >>= gpio_reg_size; - bits[BIT_WORD(i)] >>= gpio_reg_size; } } -- 2.17.0