Received: by 2002:a25:2c96:0:0:0:0:0 with SMTP id s144csp85439ybs; Sat, 23 May 2020 22:12:05 -0700 (PDT) X-Google-Smtp-Source: ABdhPJyEV4oXUPphAiARwhubn1VHF3Bwq/6ZaevCUPpTuAqzJYCAVM6JwKUPuOCTAA/AgTmOsUX5 X-Received: by 2002:a17:907:40c7:: with SMTP id nv7mr13462603ejb.16.1590297125058; Sat, 23 May 2020 22:12:05 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1590297125; cv=none; d=google.com; s=arc-20160816; b=eoEhIsRilmwDX+SsUngg+QPqHl0aS4K2cK9+EAFNSsf/QQob1hpQ18aFuCanT9+Er+ j3YDpiiNTJx599NJP4vXtrg65sNgcGrmPvV4m/pNZiqgPcKnT3oE44UASv63IGjdtbXa q16Y1Nekm4v7AMNvVOXpXkYUOPedGx0b2LFoZqzC+A2K8u+kT2hv9tzNKIy5efp8cuwa Nb3myp5bHP+QBbSOuplhuHW2oSGJkh5MtqofmYpYbLB5Hp/0a8Ach2c/iJNF3ueNuNbU U7JLg89q9KivBpz1Vk8v4ix2IIxBRzlPXX9yp+RKCVwPDV7E9bh6svP72YGUE6YmAkcK 7sjA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:user-agent:in-reply-to :content-disposition:mime-version:references:message-id:subject:cc :to:from:date:dkim-signature; bh=mvYhtqV1U4qqhDVOWFjEaTG959+IGNH15YQtyFmwOMk=; b=XTPGToURvyKar3ghw3iIkx4kHQK6Tk26NbT38cJx2g7xOF6jzmnC7fxSPGE2Sy7B1o I95ZryAo3L92wU1N99AhojKSlIU+7DZG0GF7qEkriguMGkZMBAe3tiOxAEiNhKpLjykQ 4P6ZAzypXSKdhykXoGNyD2fI8UnVJmzGWfBITqgMN6lA50rYALhkibJDiJr2ldja9O6Q kPsvJGzoztrrW5Q4iNwYfK1duvEQ/XH5rSQn7hiONUXfKDfGMV/eBMo+2x/3I/wqzY9a 1Uw/MCkm5n6+8qJNJ+XewWEgP5XgQoEhII5uGEdpH4Tku2n4TTPl8MWjmwTR2s4Xu1bJ VmGg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gmail.com header.s=20161025 header.b=NK9MXfpY; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 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. [23.128.96.18]) by mx.google.com with ESMTP id h17si7296059ejk.369.2020.05.23.22.11.42; Sat, 23 May 2020 22:12:05 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; dkim=pass header.i=@gmail.com header.s=20161025 header.b=NK9MXfpY; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 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 S1728722AbgEXFHP (ORCPT + 99 others); Sun, 24 May 2020 01:07:15 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:45870 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1725856AbgEXFHO (ORCPT ); Sun, 24 May 2020 01:07:14 -0400 Received: from mail-pj1-x1044.google.com (mail-pj1-x1044.google.com [IPv6:2607:f8b0:4864:20::1044]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 87E0DC061A0E; Sat, 23 May 2020 22:07:14 -0700 (PDT) Received: by mail-pj1-x1044.google.com with SMTP id ci21so6932288pjb.3; Sat, 23 May 2020 22:07:14 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=date:from:to:cc:subject:message-id:references:mime-version :content-disposition:in-reply-to:user-agent; bh=mvYhtqV1U4qqhDVOWFjEaTG959+IGNH15YQtyFmwOMk=; b=NK9MXfpY/j07O5SEzOIz6vmM8uitKXAVhNCl78GoFuyoMSl3Ju3Y1LOp1r5n3k3Uti qAId0zGO/uQmZoPLTK2fv0F9VJR1JCG87zsD5AEGCEfaTUXH+F+9JQORk//ZvioDaf21 I7cN4ryMBsN/FZ/Vdh0c0WnC58sJ8tvFzyYFjAXB9ADZC1b0z6eZ6L4KITmyNJ5OycL6 VIAHI0Wl8TQ36rlBEuAg1n4nd+7Lly0BD/+0N3YIBYJLHrKIm330hRmVWPDYdhCBm2V9 U/g8lqbwi0Z1/UpEj3tslj9qgTX0lGCrnbYsRh3DmqfjEKT9ZGC5OVymv6Mmt/N2HCsW z0Ng== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:date:from:to:cc:subject:message-id:references :mime-version:content-disposition:in-reply-to:user-agent; bh=mvYhtqV1U4qqhDVOWFjEaTG959+IGNH15YQtyFmwOMk=; b=sb/Bjn8DTIdFijfvtHkPlU5ldIX1DS6lgDx84jWTlA0imXO+1gr2A9wGbZFOkBHcdK 7AMa7yn8JTwmeizUSjemtENWrSzQzs2nr8tSif5VacLFJYcEmyEPYkbtE5rUn0sDz9ib A+DUGru4pxK39ofWtjJDtOPvIX94hLL6QGdSC3Xz0s0pkn97EOgU2bwNfpFdbuz9VLAj v9rcM1HOcAarAgNyo8ks9g2Menbo+dTaYlS51jpKhVGVzewKRqkFi4/YMzn8TBfV4rE6 0n2Gue7VwmeHmty6f7jD4bXKTFpG0V5gSbvcGY/JqWZW6VGq5bOIwG7cFsEM2iESNmZw sl9Q== X-Gm-Message-State: AOAM533wcFZxQInm1qgDujL5zPNzTJUlEaElWZODXvnz0sPdRXIdwDf6 LkkeJqa+NnoiDoTHtzU10II= X-Received: by 2002:a17:902:6b09:: with SMTP id o9mr21058970plk.100.1590296834091; Sat, 23 May 2020 22:07:14 -0700 (PDT) Received: from syed ([106.223.122.111]) by smtp.gmail.com with ESMTPSA id h7sm8985165pgn.60.2020.05.23.22.07.08 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Sat, 23 May 2020 22:07:13 -0700 (PDT) Date: Sun, 24 May 2020 10:36:56 +0530 From: Syed Nayyar Waris To: linus.walleij@linaro.org, akpm@linux-foundation.org Cc: andriy.shevchenko@linux.intel.com, vilhelm.gray@gmail.com, bgolaszewski@baylibre.com, michal.simek@xilinx.com, linux-gpio@vger.kernel.org, linux-arm-kernel@lists.infradead.org, linux-kernel@vger.kernel.org Subject: [PATCH v7 4/4] gpio: xilinx: Utilize for_each_set_clump macro Message-ID: References: MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: User-Agent: Mutt/1.5.24 (2015-08-30) Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org This patch reimplements the xgpio_set_multiple function in drivers/gpio/gpio-xilinx.c to use the new for_each_set_clump macro. Instead of looping for each bit in xgpio_set_multiple function, now we can check each channel at a time and save cycles. Cc: Bartosz Golaszewski Cc: Michal Simek Signed-off-by: Syed Nayyar Waris Signed-off-by: William Breathitt Gray --- Changes in v7: - No change. Changes in v6: - No change. Changes in v5: - Minor change: Inline values '32' and '64' in code for better code readability. Changes in v4: - Minor change: Inline values '32' and '64' in code for better code readability. Changes in v3: - No change. Changes in v2: - No change. drivers/gpio/gpio-xilinx.c | 62 ++++++++++++++++++++------------------ 1 file changed, 32 insertions(+), 30 deletions(-) diff --git a/drivers/gpio/gpio-xilinx.c b/drivers/gpio/gpio-xilinx.c index 67f9f82e0db0..e81092dea27e 100644 --- a/drivers/gpio/gpio-xilinx.c +++ b/drivers/gpio/gpio-xilinx.c @@ -136,39 +136,41 @@ static void xgpio_set(struct gpio_chip *gc, unsigned int gpio, int val) static void xgpio_set_multiple(struct gpio_chip *gc, unsigned long *mask, unsigned long *bits) { - unsigned long flags; + unsigned long flags[2]; struct xgpio_instance *chip = gpiochip_get_data(gc); - int index = xgpio_index(chip, 0); - int offset, i; - - spin_lock_irqsave(&chip->gpio_lock[index], flags); - - /* Write to GPIO signals */ - for (i = 0; i < gc->ngpio; i++) { - if (*mask == 0) - break; - /* Once finished with an index write it out to the register */ - if (index != xgpio_index(chip, i)) { - xgpio_writereg(chip->regs + XGPIO_DATA_OFFSET + - index * XGPIO_CHANNEL_OFFSET, - chip->gpio_state[index]); - spin_unlock_irqrestore(&chip->gpio_lock[index], flags); - index = xgpio_index(chip, i); - spin_lock_irqsave(&chip->gpio_lock[index], flags); - } - if (__test_and_clear_bit(i, mask)) { - offset = xgpio_offset(chip, i); - if (test_bit(i, bits)) - chip->gpio_state[index] |= BIT(offset); - else - chip->gpio_state[index] &= ~BIT(offset); - } + u32 *const state = chip->gpio_state; + unsigned int *const width = chip->gpio_width; + unsigned long offset, clump; + size_t index; + + DECLARE_BITMAP(old, 64); + DECLARE_BITMAP(new, 64); + DECLARE_BITMAP(changed, 64); + + spin_lock_irqsave(&chip->gpio_lock[0], flags[0]); + spin_lock_irqsave(&chip->gpio_lock[1], flags[1]); + + bitmap_set_value(old, state[0], 0, width[0]); + bitmap_set_value(old, state[1], width[0], width[1]); + bitmap_replace(new, old, bits, mask, gc->ngpio); + + bitmap_set_value(old, state[0], 0, 32); + bitmap_set_value(old, state[1], 32, 32); + state[0] = bitmap_get_value(new, 0, width[0]); + state[1] = bitmap_get_value(new, width[0], width[1]); + bitmap_set_value(new, state[0], 0, 32); + bitmap_set_value(new, state[1], 32, 32); + bitmap_xor(changed, old, new, 64); + + for_each_set_clump(offset, clump, changed, 64, 32) { + index = offset / 32; + xgpio_writereg(chip->regs + XGPIO_DATA_OFFSET + + index * XGPIO_CHANNEL_OFFSET, + state[index]); } - xgpio_writereg(chip->regs + XGPIO_DATA_OFFSET + - index * XGPIO_CHANNEL_OFFSET, chip->gpio_state[index]); - - spin_unlock_irqrestore(&chip->gpio_lock[index], flags); + spin_unlock_irqrestore(&chip->gpio_lock[1], flags[1]); + spin_unlock_irqrestore(&chip->gpio_lock[0], flags[0]); } /** -- 2.26.2