Received: by 2002:ac0:a594:0:0:0:0:0 with SMTP id m20-v6csp772667imm; Tue, 15 May 2018 08:59:38 -0700 (PDT) X-Google-Smtp-Source: AB8JxZoDdhoJoJooDWDglWxdq3kzal+oJ2OjT8Cm2I2eErlCtVInFFKAP/nqbK4GP30vp9hvbvqX X-Received: by 2002:a17:902:8692:: with SMTP id g18-v6mr15093793plo.152.1526399978600; Tue, 15 May 2018 08:59:38 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1526399978; cv=none; d=google.com; s=arc-20160816; b=HmMGVsWosJtlTuqCtN2Lw1QZ7b0ZujXVVrACrz+6zEekJ6FYxf9sOILn7gHWcFa4pi P/x44pCwUnOFsCMNzj0u8Vj8KmDRJVuJjSXkdg2aWTvUMRTvG1Jc6xLHNCcyA/VFQhhB BSzv3Dp9I9W+Wrh/ZuiBBUxAGVrGSA+b1PqHia/DMfhUKKuc3NaN5SoTUo5yqFj45RF0 RmvYOR2tadCYwvcd3WI4MzuMAyPUhsOd85fQaDbZs2zWoDKzn4eRAxxcfthyRJe4DGsn Loh4wKFG/PNwcFomZXZpE4Pnbu9+Uw1Sm8FYh32bd4EVI9YOc74eXAcDJe41QA+wnTJD EqmA== 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=cqn4+jiz5oe6kncPUTPm6vr+8HnP5nZtg5T4HJOdQ+w=; b=Yu05mdQYDTq7AxeI+iKrAIMoR4QNAYHIRsNwdR88vXBq8n/9Pn6BX1dux7InQfoRuN XNIYKS1AUxpvhzkdxONJ9Yyd7bOevgdFTUeQmTfTX6OUK4gfL0eW0tD5iDNVB9xo8SN+ 0PgPL783bFDB0hUYgbcTZ5WiGoyRvIt+qM+LdMrg+JfIJL09uXGP44L28D3zxoWzlZKv qeWlL5MEO8Jhsg1rgPdW7vpaCMOCn8WJPYZxxgnFOvyTraiM7294PK15xDiEwlxE0IFH PSpj49nMeZHwe4SmfshkcadqUgqo+Hnrjqhob9vK94g9A7RhnwDL0ohodpxz0XXZodWh CiOQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gmail.com header.s=20161025 header.b=WNVeuS62; 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 s61-v6si300312plb.271.2018.05.15.08.59.24; Tue, 15 May 2018 08:59:38 -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=WNVeuS62; 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 S1754266AbeEOPvA (ORCPT + 99 others); Tue, 15 May 2018 11:51:00 -0400 Received: from mail-yw0-f196.google.com ([209.85.161.196]:34211 "EHLO mail-yw0-f196.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1754243AbeEOPu5 (ORCPT ); Tue, 15 May 2018 11:50:57 -0400 Received: by mail-yw0-f196.google.com with SMTP id x27-v6so210235ywj.1; Tue, 15 May 2018 08:50:57 -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=cqn4+jiz5oe6kncPUTPm6vr+8HnP5nZtg5T4HJOdQ+w=; b=WNVeuS62sZeE5IF/vqXVRZZwWC16QYOLyL5hUNna2bTM/eMe5bdDdK68eGLvaNQ9Kr h2qqHwEBYeSItBNLOyyTg3VlP487l+skhzVhn2BoGfp1aiCJjE3D0ry34wqT6h4hEiQy enqd+qCd8YhdQbHy9g8M7ra7jK5Oo/zEum0oM2oPRY+vW3s5fkaYyzFrYCsNyF1bp1Eb mDMZLioQklkWdbX/cgZC+lmDYkLtBTqqbqf3W/kAVK1Y8On3n5e+3l3/XDuwqWq/VKel 7MrSnb3shlKFz6+MDqeFWYDlL0Arz7JS8BHubIMXjJIdtE4AbP6H4dy82ZBzIoHzlWiv K0IA== 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=cqn4+jiz5oe6kncPUTPm6vr+8HnP5nZtg5T4HJOdQ+w=; b=cZaL6JXgjC/0FpcFRuPSmZTMchacHcZQYE/QN5Je09IRl9gepDysRVPh3+0SXznd1P GwsrviJC5qE3DV4bwo6+9k7LG26fdfLgJv6Jv9QJQRNXp2q3PC5iCRIcmkOhlWytytxC VQaQoSWQAWHUyOaDgqKLwsqD1PDvBLHVVTQ8uixlIBBWmTGIS0TD+UCLMb56qst7+m3V AJpv3x+hjvM7+d4B/w/AygoEIBM9JQD6tfD3BV7aiI//hj6TzukCJLttZlcF9IInvGj8 wYte/7n99antgDAi9rpnwTNxtgLFFO9Xao7kVBfMkzb4hFBSQL1WO/oa7j+YOL0jtnua ASiw== X-Gm-Message-State: ALKqPwcw1DwYjfcQXvK1OzRwqiJBWVwaEMjxsbFez6LGBAfj5JDSe41s AgOwjYzaU4HEnM8BBMezxTs= X-Received: by 2002:a0d:c382:: with SMTP id f124-v6mr6925537ywd.28.1526399457061; Tue, 15 May 2018 08:50:57 -0700 (PDT) Received: from localhost ([72.188.97.40]) by smtp.gmail.com with ESMTPSA id m24-v6sm120739ywh.19.2018.05.15.08.50.56 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Tue, 15 May 2018 08:50:56 -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 5/8] gpio: gpio-mm: Utilize for_each_set_clump macro Date: Tue, 15 May 2018 11:50:51 -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-gpio-mm.c | 67 +++++++++---------------------------- 1 file changed, 16 insertions(+), 51 deletions(-) diff --git a/drivers/gpio/gpio-gpio-mm.c b/drivers/gpio/gpio-gpio-mm.c index b56ff2efbf36..72668da8bf8d 100644 --- a/drivers/gpio/gpio-gpio-mm.c +++ b/drivers/gpio/gpio-gpio-mm.c @@ -172,46 +172,23 @@ static int gpiomm_gpio_get(struct gpio_chip *chip, unsigned int offset) return !!(port_state & mask); } +static const size_t ports[] = { 0, 1, 2, 4, 5, 6 }; + static int gpiomm_gpio_get_multiple(struct gpio_chip *chip, unsigned long *mask, unsigned long *bits) { struct gpiomm_gpio *const gpiommgpio = 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(gpiommgpio->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; @@ -242,37 +219,25 @@ static void gpiomm_gpio_set_multiple(struct gpio_chip *chip, unsigned long *mask, unsigned long *bits) { struct gpiomm_gpio *const gpiommgpio = 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); spin_lock_irqsave(&gpiommgpio->lock, flags); /* update output state data and set device gpio register */ - gpiommgpio->out_state[port] &= ~mask[BIT_WORD(i)]; - gpiommgpio->out_state[port] |= bitmask; - outb(gpiommgpio->out_state[port], gpiommgpio->base + out_port); + gpiommgpio->out_state[i] &= ~iomask; + gpiommgpio->out_state[i] |= bitmask; + outb(gpiommgpio->out_state[i], gpiommgpio->base + ports[i]); spin_unlock_irqrestore(&gpiommgpio->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