From patchwork Sat Jun 27 08:14:23 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Syed Nayyar Waris X-Patchwork-Id: 11629387 Return-Path: Received: from mail.kernel.org (pdx-korg-mail-1.web.codeaurora.org [172.30.200.123]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id A4116138C for ; Sat, 27 Jun 2020 08:16:45 +0000 (UTC) Received: from merlin.infradead.org (merlin.infradead.org [205.233.59.134]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPS id 728012080C for ; Sat, 27 Jun 2020 08:16:45 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=lists.infradead.org header.i=@lists.infradead.org header.b="ujdxSony"; dkim=fail reason="signature verification failed" (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="fTYh6RdX" DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 728012080C Authentication-Results: mail.kernel.org; dmarc=fail (p=none dis=none) header.from=gmail.com Authentication-Results: mail.kernel.org; spf=none smtp.mailfrom=linux-arm-kernel-bounces+patchwork-linux-arm=patchwork.kernel.org@lists.infradead.org DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=merlin.20170209; h=Sender:Content-Transfer-Encoding: Content-Type:Cc:List-Subscribe:List-Help:List-Post:List-Archive: List-Unsubscribe:List-Id:In-Reply-To:MIME-Version:References:Message-ID: Subject:To:From:Date:Reply-To:Content-ID:Content-Description:Resent-Date: Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID:List-Owner; bh=shxe2D+VuMDl6ZocbjQTjnQzwCdE1bEG85uq7yVg/Xg=; b=ujdxSonycQ/pVoxxBs9D3dWEP R6Wv1woTuZL55RBViBhpnF8L41nF/p8l16eHCTMrN5T/HLT5iA0GBa/PEJ3BIskOhg9V+1s+JSyzo 83euualJ44bDJHKbqZMh/+s6dzx/z6DMChjbD5tdeLYmzcxShQekGLtycuQ0qXzzzw8VQP4NJhill SDWp+1nla3Y2r1WQL9Jlpjaw/8/gUG5ROfzLTjKGSR6eNDvAkne33a/C5IWp8yA2y3T2oa/OOfdnE HpKveY4ajIDf5bVaYPxVLTx3VevhB4bOe4YdxlZ9zSgjb3t9L8/MpB5g85Y/aGWIuVklVeFxuzPFx KpxuPVRRQ==; Received: from localhost ([::1] helo=merlin.infradead.org) by merlin.infradead.org with esmtp (Exim 4.92.3 #3 (Red Hat Linux)) id 1jp5z2-0006eU-VR; Sat, 27 Jun 2020 08:14:45 +0000 Received: from mail-pj1-x1043.google.com ([2607:f8b0:4864:20::1043]) by merlin.infradead.org with esmtps (Exim 4.92.3 #3 (Red Hat Linux)) id 1jp5z0-0006dv-AH for linux-arm-kernel@lists.infradead.org; Sat, 27 Jun 2020 08:14:43 +0000 Received: by mail-pj1-x1043.google.com with SMTP id q90so5151090pjh.3 for ; Sat, 27 Jun 2020 01:14:41 -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=dpM993DYx757L959Dyb6uvrVfTSpmyE+QSSbfrUcBkg=; b=fTYh6RdXSkRMtPVsVoCTi+cghdBug+y6T/Sv1djnKnS6+QYs2f0ANYxz7WUZWL4GFU 30XWR+Q9ZlueRgvjp3kAApQM7cevL+S3SeJwqUcom8G/6i4lEC0Rk8eq4MYH91hukfHN Y3d4pFYZAC846CyRqMV26J0zt29EG8sRJ8sUw/TY0W/MzH9Fop8HGLEc6dxKJm9MPP8W dcfTmVRBDmUcYORA/2MrB+cvCYjdx0kFDA/Ez71dHrT5buCCxxDQdtydTuIRI/8DRd9K jFcq1Roi44BLAdOJL/SZfUxLcpjBVU9y+nEjotyAmW5biH72ZqW0ycSpWHSLpuGwjkaf i/Fw== 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=dpM993DYx757L959Dyb6uvrVfTSpmyE+QSSbfrUcBkg=; b=PatoJElVmjeJZWT35YsuO2wYm2oC6bOYgP6pqkdRCoPPenBsPXLZNn1cbXgZuvAz07 C+0vmP/1nghxz8hVrl8J0Rs0xkIiyxL07JcHv1djJsb2OFWFgSdSicrh5Yi2J7PzG6xt FEEzbHT27/XPJt/d7JIZ8JlKBB+7C2PLIvEEtnX1evpiEWw9P7asxwQBihaGIO1f0Fje Vchv2wykweGbZLJ2xDLE2IDShagSCh3wHcZzqxdiCyD8/ZdMJ/0CLLbJ+lOYgUMibvl1 GPcaQ/NxjYOvTXfgeZxxx90fU7wMgFa/c3+suW1Yc/OaCJyyl28OXWMpdB1OGqy1sIRV hdcA== X-Gm-Message-State: AOAM533y3ryV+OPomOxlK+bZgHMpUD7AZHb50GUu80m9AvVu4kZ+R2Rx 4RwyPeRWwS1MWJ8bLHk3T2w= X-Google-Smtp-Source: ABdhPJxlLPfHUJU3msNctbpW/nRfqu1Q5Wt3/FlbO0z+jENpMMgputAm+r7e4r8/qnaj7e1ONqgjNw== X-Received: by 2002:a17:902:fe8f:: with SMTP id x15mr5557911plm.249.1593245679417; Sat, 27 Jun 2020 01:14:39 -0700 (PDT) Received: from syed ([106.198.160.82]) by smtp.gmail.com with ESMTPSA id h3sm4416100pjz.23.2020.06.27.01.14.35 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Sat, 27 Jun 2020 01:14:39 -0700 (PDT) Date: Sat, 27 Jun 2020 13:44:23 +0530 From: Syed Nayyar Waris To: linus.walleij@linaro.org Subject: [PATCH v9 4/4] gpio: xilinx: Utilize generic bitmap_get_value and _set_value. Message-ID: <0a35c10d1613aff43038bc7d4d6f95061d9d80d3.1593243081.git.syednwaris@gmail.com> References: MIME-Version: 1.0 Content-Disposition: inline In-Reply-To: User-Agent: Mutt/1.5.24 (2015-08-30) X-Spam-Note: CRM114 invocation failed X-Spam-Score: -0.2 (/) X-Spam-Report: SpamAssassin version 3.4.4 on merlin.infradead.org summary: Content analysis details: (-0.2 points) pts rule name description ---- ---------------------- -------------------------------------------------- -0.0 RCVD_IN_DNSWL_NONE RBL: Sender listed at https://www.dnswl.org/, no trust [2607:f8b0:4864:20:0:0:0:1043 listed in] [list.dnswl.org] 0.0 FREEMAIL_FROM Sender email is commonly abused enduser mail provider [syednwaris[at]gmail.com] -0.0 SPF_PASS SPF: sender matches SPF record 0.0 SPF_HELO_NONE SPF: HELO does not publish an SPF Record -0.1 DKIM_VALID_EF Message has a valid DKIM or DK signature from envelope-from domain -0.1 DKIM_VALID Message has at least one valid DKIM or DK signature -0.1 DKIM_VALID_AU Message has a valid DKIM or DK signature from author's domain 0.1 DKIM_SIGNED Message has a DKIM or DK signature, not necessarily valid X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: linux-gpio@vger.kernel.org, linux-kernel@vger.kernel.org, vilhelm.gray@gmail.com, michal.simek@xilinx.com, bgolaszewski@baylibre.com, andriy.shevchenko@linux.intel.com, linux-arm-kernel@lists.infradead.org Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+patchwork-linux-arm=patchwork.kernel.org@lists.infradead.org This patch reimplements the xgpio_set_multiple function in drivers/gpio/gpio-xilinx.c to use the new generic functions: bitmap_get_value and bitmap_set_value. The code is now simpler to read and understand. Moreover, instead of looping for each bit in xgpio_set_multiple function, now we can check each channel at a time and save cycles. --- Changes in v9: - Remove looping of 'for_each_set_clump' and instead process two halves of a 64-bit bitmap separately or individually. Use normal spin_lock call for second inner lock. And take the spin_lock_init call outside the 'if' condition in the 'probe' function of driver. Changes in v8: - No change. 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 | 66 +++++++++++++++++++------------------- 1 file changed, 33 insertions(+), 33 deletions(-) diff --git a/drivers/gpio/gpio-xilinx.c b/drivers/gpio/gpio-xilinx.c index 67f9f82e0db0..48393d06fb55 100644 --- a/drivers/gpio/gpio-xilinx.c +++ b/drivers/gpio/gpio-xilinx.c @@ -136,39 +136,39 @@ 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 flag; 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); - } - } - - xgpio_writereg(chip->regs + XGPIO_DATA_OFFSET + - index * XGPIO_CHANNEL_OFFSET, chip->gpio_state[index]); - - spin_unlock_irqrestore(&chip->gpio_lock[index], flags); + u32 *const state = chip->gpio_state; + unsigned int *const width = chip->gpio_width; + + DECLARE_BITMAP(old, 64); + DECLARE_BITMAP(new, 64); + DECLARE_BITMAP(changed, 64); + + spin_lock_irqsave(&chip->gpio_lock[0], flag); + spin_lock(&chip->gpio_lock[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); + + if (((u32 *)changed)[0]) + xgpio_writereg(chip->regs + XGPIO_DATA_OFFSET, + state[0]); + if (((u32 *)changed)[1]) + xgpio_writereg(chip->regs + XGPIO_DATA_OFFSET + + XGPIO_CHANNEL_OFFSET, state[1]); + + spin_unlock(&chip->gpio_lock[1]); + spin_unlock_irqrestore(&chip->gpio_lock[0], flag); } /** @@ -292,6 +292,7 @@ static int xgpio_probe(struct platform_device *pdev) chip->gpio_width[0] = 32; spin_lock_init(&chip->gpio_lock[0]); + spin_lock_init(&chip->gpio_lock[1]); if (of_property_read_u32(np, "xlnx,is-dual", &is_dual)) is_dual = 0; @@ -314,7 +315,6 @@ static int xgpio_probe(struct platform_device *pdev) &chip->gpio_width[1])) chip->gpio_width[1] = 32; - spin_lock_init(&chip->gpio_lock[1]); } chip->gc.base = -1;