Received: by 2002:ad5:474a:0:0:0:0:0 with SMTP id i10csp3235960imu; Sun, 13 Jan 2019 22:22:36 -0800 (PST) X-Google-Smtp-Source: ALg8bN6e4kbzuZxShG2yPicUz2gooRV4k8vNjSiJsW9UErrpfeSkkGgR7iy+IaoFfot/rbqNqqqY X-Received: by 2002:a62:130c:: with SMTP id b12mr24178728pfj.247.1547446956823; Sun, 13 Jan 2019 22:22:36 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1547446956; cv=none; d=google.com; s=arc-20160816; b=agfp9IPtd59Um6uuooEA7hhAkwoyrY5gx4zosJPSN/i/CBHXoinLkgH58etad3y5Mi WKYM3/qQpgYOCdyB/oUyrYLnsB5v4GYHQngVSo3hFhLOeqXKN0l83PVoWMHOSGZAmzbQ Hn2aIbu0b5dw+p6lUZXmpPZX+CxVrppvRL0KZHsCuWRpk/IT11pl+wCgD4GEw8q73D6W dAiD2sL8oSETn0CcCl9joDn3XBaYU+CNuwq4EJ/rzV9kvJoS9vGzg2XNfA/hTuE8aikc zXW+yAtxLGMZhxZQH6S4i5tHt9Ycqt1yfSNrjiFOVW2J8lPwzEYL9hmkYNTEdTJrovdh 9pOg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:content-transfer-encoding:mime-version :references:in-reply-to:message-id:date:subject:cc:to:from :dkim-signature; bh=7s7wYeX/GD7rWEVAPX5wPgr67IG4VRsYD+ssbUVyFFk=; b=AbtyaCJLUYvCt8fk3IPSFeh0ytn+LdmczI8CpfgbCdvVm7Bnb29Eqok0yRKAX126Xj wa69v0m7EONKMBub2wjpb6jYZdPEdU/7l+Dk3O1IywzuvlLH55WeFwT7jBjSQAkffVZt ymC/WR0toqJgtsguMXX90H9RmHNxRq7cjVIwLGL9bxD2d1seDEdzZpbtEOjUgYbGOzdL YJFIpnIhFsXo9JBoAAsO7G3K5k+9a/58r4I9+zZK7/dGPcM4hIklxfAjWK9IzgEMyFQT waiih5ZACtGuz/LWc1h3h1Qj6sBwHcKzEBBGMHqmZ1ohT664Bok0AHHHK29/PuWv+h/0 k9vg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gmail.com header.s=20161025 header.b=twEF5vVa; 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 k69si1385551pga.176.2019.01.13.22.22.21; Sun, 13 Jan 2019 22:22:36 -0800 (PST) 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=twEF5vVa; 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 S1726641AbfANGUK (ORCPT + 99 others); Mon, 14 Jan 2019 01:20:10 -0500 Received: from mail-pf1-f193.google.com ([209.85.210.193]:34204 "EHLO mail-pf1-f193.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726067AbfANGUJ (ORCPT ); Mon, 14 Jan 2019 01:20:09 -0500 Received: by mail-pf1-f193.google.com with SMTP id h3so9866344pfg.1; Sun, 13 Jan 2019 22:20:09 -0800 (PST) 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 :mime-version:content-transfer-encoding; bh=7s7wYeX/GD7rWEVAPX5wPgr67IG4VRsYD+ssbUVyFFk=; b=twEF5vVaZkG8Sp8D0/br++Ki6dABNQ+C6olAR/vu00RUIjUQVsPoGZskmGl6QMxF2w HpZo6c3cKrDzBj9j4duhO1aDtjLm0jluuok9jUzvMhJCgU5TmgiiIsLkaH93YnJBXvDJ ZBGZXsKe3xZSk8tWzkeJSxMkzIFqQPlM+YGXEEhIOH+Wo4SQ25ZjDRO80qIPKJByyq+o HFxSSwtE5oxjvtaZMpwrXOQwKyEiK1YZiSNYzB8tboPYJgFlq8codMVSQ33ptEYoRqG3 5Ypf7ZSxbZTaDKy8UV7kvJ4u/IVAeUTFgTIb5RBPn78emBKQVDlTlj0KhSCaanPp7xSi W/OA== 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:mime-version:content-transfer-encoding; bh=7s7wYeX/GD7rWEVAPX5wPgr67IG4VRsYD+ssbUVyFFk=; b=ALIRQGvhL1rwsjfhB4HQ4sAvyE5AGPVyxDYMLcSlUWPXoRDa7gMm61xglmTUErCXnJ gwhhvde2118PeIu11kJHXvzwz/FcWKdLDIpM3HP/XKWCzyv8W/eKxHkD6E9Zyo2Fj7fb m890fk1gEyytKjuGjEcpApZTVbsVk3umjinlVX+bMBHWj1O4FJCtezP/SZV1FzjL1FF1 dyPe9mRPnq0sb54nRTPgD+ylsckTOqYd0k+XTu2VxZG7GyvzTYJcWnpfFDektpncfF8C HmzH60P9xOKDNcc7lF8qWh1F+nMZQzWd+vKAZJ+z6Ct8aH9608xKHWWKdiJH68fBXRD6 BGUw== X-Gm-Message-State: AJcUukcrRpCHC4+5EdugaFV8TJxO5OXIGZe8qJSgTcmGozUjLMlkEuz/ sEeZtlWhAuPXv4IWadYeQjw= X-Received: by 2002:a63:7418:: with SMTP id p24mr11708492pgc.196.1547446808865; Sun, 13 Jan 2019 22:20:08 -0800 (PST) Received: from localhost.localdomain ([2001:268:c0a3:70f2:4411:7de2:8afe:823b]) by smtp.gmail.com with ESMTPSA id i184sm117311947pfc.41.2019.01.13.22.20.04 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Sun, 13 Jan 2019 22:20:08 -0800 (PST) From: William Breathitt Gray To: linus.walleij@linaro.org Cc: akpm@linux-foundation.org, linux-gpio@vger.kernel.org, linux-arch@vger.kernel.org, linux-kernel@vger.kernel.org, andriy.shevchenko@linux.intel.com, linux@rasmusvillemoes.dk, William Breathitt Gray Subject: [PATCH v8 4/8] gpio: 104-idi-48: Utilize for_each_set_clump8 macro Date: Mon, 14 Jan 2019 15:20:44 +0900 Message-Id: X-Mailer: git-send-email 2.20.1 In-Reply-To: References: MIME-Version: 1.0 Content-Transfer-Encoding: 8bit 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_clump8 macro to simplify code and improve clarity. Signed-off-by: William Breathitt Gray --- drivers/gpio/gpio-104-idi-48.c | 37 ++++++++-------------------------- 1 file changed, 8 insertions(+), 29 deletions(-) diff --git a/drivers/gpio/gpio-104-idi-48.c b/drivers/gpio/gpio-104-idi-48.c index 88dc6f2449f6..59c571aecf9a 100644 --- a/drivers/gpio/gpio-104-idi-48.c +++ b/drivers/gpio/gpio-104-idi-48.c @@ -93,42 +93,21 @@ static int idi_48_gpio_get_multiple(struct gpio_chip *chip, unsigned long *mask, unsigned long *bits) { struct idi_48_gpio *const idi48gpio = gpiochip_get_data(chip); - size_t i; + unsigned int offset; + unsigned long gpio_mask; 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); + const unsigned int ngpio = ARRAY_SIZE(ports) * 8; + unsigned int port_addr; 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; + for_each_set_clump8(offset, gpio_mask, mask, ngpio) { + port_addr = idi48gpio->base + ports[offset / 8]; + port_state = inb(port_addr) & gpio_mask; - /* 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(idi48gpio->base + ports[i]); - - /* store acquired bits at respective bits array offset */ - bits[word_index] |= (port_state << word_offset) & word_mask; + bitmap_set_value8(bits, ngpio, port_state, offset); } return 0; -- 2.20.1