Received: by 2002:ac0:a594:0:0:0:0:0 with SMTP id m20-v6csp773221imm; Tue, 15 May 2018 09:00:05 -0700 (PDT) X-Google-Smtp-Source: AB8JxZox7kButwyq6bHJRoxYV2tv++dVTNLHJ9vA/AngmwkDhgpibpbZul/5uamO9+GVgFA2sO/G X-Received: by 2002:a65:61a8:: with SMTP id i8-v6mr12402391pgv.381.1526400005548; Tue, 15 May 2018 09:00:05 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1526400005; cv=none; d=google.com; s=arc-20160816; b=HjHmyaym3zqtTBkIRPlxl+DCtbJTg9tVNkN7gCDkZ5NsVjYnS2DTnXow7wkLDq9fNQ 3QsQqctZgD9f+lsv19CD4bAMhCs00W8gZd3X9UvlmyKBVWHuqLXBqp/3MwbZSAVLFDet Q3PCFqXpDllvsv9yALRGD4TrhahBUJjxNkftECkDIK6aYzM7tNEx6bLowA4bhBQnsUPI oodik4Ir6N6O1CQ0z/KP5sW3VbBz29eiIQ3Pu7mxzcCp2r58MJ6TudPk3kM5Ti+KBgQi rBBp90/a9lWBE/FWY1KXYtRbt+DjGZnzQ5Wo8vzb5DUP0KTOySnJZhvdjg6T9WlhSJFe ay1Q== 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=tAo7rXu+mux3L7ze8r9gzOGceOAVFwQmVWVRQkyRRgw=; b=Ih1ufoz6AncxzC2jNu4vGKufBNlV4v9WxCs9zlI+oXqDj74RPNoc5wQtAknVPOywiG +sDNlK5VGrl/Ci9mT4gmVtOGQgHr7UUFr1pKBGlyHoRQSrjFPhtf00dOd+zkjldA8HkU jdoJPHn5cc6p7ohWySWBHs2cCBDWl8PiEVpA30mtw+m8a5ccnt+tNpfh9kVFd8kpSUhk xtC8cqfu32FUqC1wKWy+3W7yDQHOs3oEhp9JRv3C7CQvCQVZwHWf6VdjfCmRPgLwStCE f7UdPyBpW0MKxflZYhSggt/f7psVW42T69xqH08JbjsHvbKt6oheUVGCcIDAK+I+QG7j WUAA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gmail.com header.s=20161025 header.b=h4mn5x8Y; 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 f2-v6si231614pgs.655.2018.05.15.08.59.50; Tue, 15 May 2018 09:00:05 -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=h4mn5x8Y; 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 S1754292AbeEOPvK (ORCPT + 99 others); Tue, 15 May 2018 11:51:10 -0400 Received: from mail-yb0-f195.google.com ([209.85.213.195]:42586 "EHLO mail-yb0-f195.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1754276AbeEOPvI (ORCPT ); Tue, 15 May 2018 11:51:08 -0400 Received: by mail-yb0-f195.google.com with SMTP id 140-v6so213139ybc.9; Tue, 15 May 2018 08:51:07 -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=tAo7rXu+mux3L7ze8r9gzOGceOAVFwQmVWVRQkyRRgw=; b=h4mn5x8YYkR4E/GOjWgwqntmch0dvHvbZ4ZSNh/BH8QbemmmzuWaaPmiYyYd3rUye9 /fHOsseRA6GGSZWZgBmTbzP1vpeQ7VtPYtGRi9pkuSe9i6Ul0uzg5/J2qcKQDuOxngf5 yHxOxGodqeYVMl/llttEWEF7lQ+Jo0L60CApGzZQuVcyBJLaFbeuvqV5Vm4pP/px2Dm8 TW+TYMEkY1C1q2DrkT+CRGkjB/DuqlBXVSAUqawLpoZ81H+m+GHOjQfY2Dj57aqUGLAI uY/lN+QVZTXJJ0/Ny4ckPmtfGUZYjNWptkcG6gqQ0QTPOzzHOM+/I1MwcSAHa1RbAYNp 4/mg== 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=tAo7rXu+mux3L7ze8r9gzOGceOAVFwQmVWVRQkyRRgw=; b=DzpN/U69867IgwlttZ9EETy2dqXshG1BvEPEoBbwWXwaOTa/MuB9XwqvsnExA6Nw7x n5x6iVYrrXBtwztSVVSS3188BpsNVmhKG9SHN6FssogYWrwwunBJl2oMlmrbasVt1jjn Q91lChpEcrOhNzUf896qdKrjPJp2DVqQDDQTyyIn9R06LoavLFqdbn2tpI7tzGJrx+6d pbxgUdLjjUmdI4DN0Zf1B8UJKl0R/7k1l41Yefi9NKYZSILd4MYIlRrcneFHUhDjxprz 4LonP1qaKCIQQXwF0krgfS26zuheR8Q41v1dc32vIJO9DKV7DXFN0QEupUWplweAXhJm c/BQ== X-Gm-Message-State: ALKqPwflDLeI2gNmOqKtRvGBcWsBRY4Gt5IrE4PumQ/FOtX6GU568mR9 P1RH6g2XKAuwPBTmAe1Yckw= X-Received: by 2002:a25:6648:: with SMTP id z8-v6mr6329849ybm.108.1526399467235; Tue, 15 May 2018 08:51:07 -0700 (PDT) Received: from localhost ([72.188.97.40]) by smtp.gmail.com with ESMTPSA id b188-v6sm132960ywc.72.2018.05.15.08.51.06 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Tue, 15 May 2018 08:51:06 -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 6/8] gpio: ws16c48: Utilize for_each_set_clump macro Date: Tue, 15 May 2018 11:51:01 -0400 Message-Id: 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-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..625336376b5d 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_clump(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_clump(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