Received: by 10.192.165.148 with SMTP id m20csp3221223imm; Mon, 7 May 2018 08:37:12 -0700 (PDT) X-Google-Smtp-Source: AB8JxZok471449n5c4avqsuuWq6vuuEmw1FJlzE3piGV69z3A2sfRoVNAKZO3tUsRkxYdybBGDqS X-Received: by 2002:a24:2494:: with SMTP id f142-v6mr1804759ita.0.1525707432527; Mon, 07 May 2018 08:37:12 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1525707432; cv=none; d=google.com; s=arc-20160816; b=eioqe6X4+A6hxcFooO1fnZmbqJCaWUrdzbmraAvk7gnxXrRj0AJKNHUhzebqR8jVnE iWZTEN/ouLs9uu8wA0k91JHMzBILz3sV7vHYEI/xqNJ1/FdgzxABe0eVdcNrQla6PW6d xH+vsBem+yEBOL8U23Au+ehMiLzNpHvEe3eT1hMeG0TCYZ+DoZQwZtl4r7kMes3ngZTH UQkY6AwZR5GjYq1mZFPJwDDopsrrRRvq7uPUx0YEBerwFYn8ztOkV7D0zDhfsqQRjwsB Tl5WYSTIW33uVd490tpvRS2ys3LWtJSvpKUVfTYWPyDkn5U+5ZDXFra2QM1g5uG6iQLJ QV3Q== 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=IBIBNhSQ0ajv4mOvaURSmQs0HFlBxEAuRaVG0JJUT0Q=; b=jqwOJalziLsZYVjxNHuEQmQv13tAFpDxuhCVBFUaG9tXDkHVPO+2shLzwNzfCNRk40 9p80YtPq/sluk2g4/3B6kLqNna0T91T0gyxDzZ4v0w3+Wr6NxhPTKvJgRscUHq3rzYZ7 oo+zjTJS2gjuG1UEICqurDV7mIJsnAJdTYymDmQNnEA+nT1IK5Em+v637PKTySRA+2aT rGPy/8UnOW7ZnmBLrzedpXjKuR3tLhnYcbBtA88PGwNX3u+yAWeU6XpwN2mCPwDhvaDh IkgDDgA4AAmTPMFBsmgqlnXawa+pgv/EHAuNC47TYG5EfIyTAZuXArsEXy9YzOdNmQ4n Zh7A== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gmail.com header.s=20161025 header.b=rjh/gO/w; 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 d4-v6si19188648ioc.103.2018.05.07.08.36.59; Mon, 07 May 2018 08:37:12 -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=rjh/gO/w; 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 S1752612AbeEGPgc (ORCPT + 99 others); Mon, 7 May 2018 11:36:32 -0400 Received: from mail-yb0-f196.google.com ([209.85.213.196]:45056 "EHLO mail-yb0-f196.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1751913AbeEGPga (ORCPT ); Mon, 7 May 2018 11:36:30 -0400 Received: by mail-yb0-f196.google.com with SMTP id r13-v6so10062061ybm.12; Mon, 07 May 2018 08:36:29 -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=IBIBNhSQ0ajv4mOvaURSmQs0HFlBxEAuRaVG0JJUT0Q=; b=rjh/gO/wPMOMpADDqTblQzHJhu39ImEbWPCHeEf0hh7H6tD13nwsgjP0O5QtbS1ksM +X+90ypSQBB4q+VSvoKyhQ/UwFTkcy5YTbK1cXlzZj0fL0wt8WlKlJz42a/sbpRw9fW9 NYyv9mu3g1r2e39AQRvdN7qj6sdo6ZytH8TXH0bLwrJPcGJHQ+B8P/H7WZcbA4ipCjuC /9bL9DbjR+ZtEiQIx/vCsPONN19MRf8R2YtaHTSJJPlwjXKTLVf1Acldk3Y5S3Z7otyp HpNMs5e+WvfqwBKNTdKiCA1r9us61+6Fwu6rWAEapC6/4BXMGbBBFWbnD0tvnxxAB4oO 0+1Q== 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=IBIBNhSQ0ajv4mOvaURSmQs0HFlBxEAuRaVG0JJUT0Q=; b=TGE6fibsCOzb3+Lj9gazh8KRAVWZs/VI2NCYfeiHQRHAct2BtDrKzCEEuDbc35j0A7 sGcrGcoNUr/nrm+2h2yEgKXU7ZkDeXzPJNLGe4atGjD833E1Th05WawIMQFiL+auV9ta ymEVYyo7OOto4XdPNms2MoNzo/k4Qc0CConIhhilrI2vyJ/e0ik8BrNxLJLGX3COQRHL sPE2kDwY+9UQ3KUZaVdDBHF762xGcoA6rI8dA0uJsyeZwB5qLN2ZKpPWMnyzsenyrzwW mqDkgfdFI9jsGD2+Of6gzvfbSCqzMT6sOdq1FbmNTV3FmAXKyDkEo2xvGobmJPQoDOdQ qpag== X-Gm-Message-State: ALQs6tCGA1sXsb8LeqTLIcYf+DYX+1dct6VPifIuh/t53E0xtPSFB4Kj bvN1MFP6CmjoRTB42lbsacMBpw== X-Received: by 2002:a25:f401:: with SMTP id q1-v6mr22610289ybd.314.1525707389331; Mon, 07 May 2018 08:36:29 -0700 (PDT) Received: from localhost ([72.188.97.40]) by smtp.gmail.com with ESMTPSA id u8-v6sm10129047ywb.28.2018.05.07.08.36.28 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Mon, 07 May 2018 08:36:29 -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 5/7] gpio: ws16c48: Utilize for_each_set_port_word macro Date: Mon, 7 May 2018 11:36:22 -0400 Message-Id: <93b3cfe4fd47cc9b16f69816fafa17e9779bbe9d.1525704095.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 get_multiple/set_multiple callbacks with for_each_set_port_word macro to simplify code and improve clarity. Signed-off-by: William Breathitt Gray --- drivers/gpio/gpio-ws16c48.c | 66 +++++++++---------------------------- 1 file changed, 16 insertions(+), 50 deletions(-) diff --git a/drivers/gpio/gpio-ws16c48.c b/drivers/gpio/gpio-ws16c48.c index c7028eb0b8e1..ab8b36f3595c 100644 --- a/drivers/gpio/gpio-ws16c48.c +++ b/drivers/gpio/gpio-ws16c48.c @@ -134,42 +134,19 @@ static int ws16c48_gpio_get_multiple(struct gpio_chip *chip, unsigned long *mask, unsigned long *bits) { struct ws16c48_gpio *const ws16c48gpio = gpiochip_get_data(chip); - const unsigned int gpio_reg_size = 8; - size_t i; - const size_t num_ports = chip->ngpio / gpio_reg_size; - 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 port; + size_t word; + unsigned int offset; + const unsigned int port_size = 8; + const size_t num_ports = chip->ngpio / port_size; 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 < num_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 */ - port_state = inb(ws16c48gpio->base + i); - - /* store acquired bits at respective bits array offset */ - bits[word_index] |= port_state << word_offset; + for_each_set_port_word(port, word, offset, mask, num_ports, port_size) { + port_state = inb(ws16c48gpio->base + port); + bits[word] |= port_state << offset; } return 0; @@ -203,26 +180,19 @@ static void ws16c48_gpio_set_multiple(struct gpio_chip *chip, unsigned long *mask, unsigned long *bits) { struct ws16c48_gpio *const ws16c48gpio = gpiochip_get_data(chip); - unsigned int i; - const unsigned int gpio_reg_size = 8; - unsigned int port; + size_t port; + size_t word; + unsigned int offset; + const unsigned int port_size = 8; + const size_t num_ports = chip->ngpio / port_size; 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; - + for_each_set_port_word(port, word, offset, mask, num_ports, port_size) { /* mask out GPIO configured for input */ - iomask = mask[BIT_WORD(i)] & ~ws16c48gpio->io_state[port]; - bitmask = iomask & bits[BIT_WORD(i)]; + iomask = (mask[word] >> offset) & ~ws16c48gpio->io_state[port]; + bitmask = iomask & (bits[word] >> offset); raw_spin_lock_irqsave(&ws16c48gpio->lock, flags); @@ -232,10 +202,6 @@ static void ws16c48_gpio_set_multiple(struct gpio_chip *chip, outb(ws16c48gpio->out_state[port], ws16c48gpio->base + port); raw_spin_unlock_irqrestore(&ws16c48gpio->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