From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-14.2 required=3.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,FREEMAIL_FORGED_FROMDOMAIN,FREEMAIL_FROM, HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_CR_TRAILER,INCLUDES_PATCH, MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS,URIBL_BLOCKED,USER_AGENT_SANE_1 autolearn=unavailable autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 48C9FC433DB for ; Fri, 12 Feb 2021 13:23:50 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 1605C64E57 for ; Fri, 12 Feb 2021 13:23:50 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231236AbhBLNX2 (ORCPT ); Fri, 12 Feb 2021 08:23:28 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:51864 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231814AbhBLNW4 (ORCPT ); Fri, 12 Feb 2021 08:22:56 -0500 Received: from mail-pl1-x62a.google.com (mail-pl1-x62a.google.com [IPv6:2607:f8b0:4864:20::62a]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id A852DC061574; Fri, 12 Feb 2021 05:22:15 -0800 (PST) Received: by mail-pl1-x62a.google.com with SMTP id a24so3145223plm.11; Fri, 12 Feb 2021 05:22:15 -0800 (PST) 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=LlK4oOejkGmVCANiTlUnm8yrZASNqtveudOgthnjqjI=; b=iQSwM5JwXDKLM+rqGqJmII6cCxrZTr/MDyQJcOwWPdUIGET0SX5Dx13XxnWQoAB9ce Yl/C+Dxd75UvNlHjdqdFOvI3d49JZhiBywK3vO9N83sZOlwQU3mLGNoVFiFIMtzr/GHe vlII8OXJn+L2qWA7GV2gpHFjmDN84VXCKXAujllae/ClEjYEuu4ABe9ijORyyc99KJel iAWaJs2XjitDtSwsr1UsCh2gWMmCdk6GpV6sJLpKNDrjJ4LDnhm17LeQGe+6VHoprmpd qB/jEHYVAzgUPn1QREHwoiEfhRO/e2Is8Hpj3lwdSFIJdo12N8xnMPq0/3IQYvMeamib W4HQ== 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=LlK4oOejkGmVCANiTlUnm8yrZASNqtveudOgthnjqjI=; b=q5NcLFN9CElP2o+Glk8nn/D+z2yP8M6uLCbJBbi0xZUDht889ybZW2gPxPA5FtDe5M JNlHvViICdH8o3P8M6nI3ivJcYFjfBsqZEOq5WMGp+awrJNn4wrtBORtfjb00afVW6Ea X6ma2aEQgG8AjC7dCKGzt7HM+cqNDY8zq+fbdfA5c1qTOWE3lV2wVU3hn/bwhsX8JnF4 YmQa4rcZOJFi/N2LxtRgRmwpNZR0tw/k93t/pMuG1R/HFQ1ZXc3aJf7RnAQdcJxk3GO7 IytzFIvUcRiux99KVDQNC8Zl5ybcBIQ5S7ZDz3wFkZc41kWRYTC5PSxs7dnDMxZrHCSe i8yA== X-Gm-Message-State: AOAM530oXakW7YIYVu7/P/+Rn6PLV4m4Zgr1P1cgXILOlR/JzARUwKeh 6o4Zogh5i7m/OM+89L4hip4= X-Google-Smtp-Source: ABdhPJyV9t8X6mKuwfE8e/aZK1KZFuuyTqGY4IAiBevhX62jo7ymr64zGlqJd1+zqtCK1Yew5apvoQ== X-Received: by 2002:a17:90a:6549:: with SMTP id f9mr2754627pjs.17.1613136135243; Fri, 12 Feb 2021 05:22:15 -0800 (PST) Received: from syed.domain.name ([103.201.127.1]) by smtp.gmail.com with ESMTPSA id q43sm5591021pjq.25.2021.02.12.05.22.08 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Fri, 12 Feb 2021 05:22:15 -0800 (PST) Date: Fri, 12 Feb 2021 18:52:00 +0530 From: Syed Nayyar Waris To: bgolaszewski@baylibre.com Cc: andriy.shevchenko@linux.intel.com, vilhelm.gray@gmail.com, michal.simek@xilinx.com, arnd@arndb.de, rrichter@marvell.com, linus.walleij@linaro.org, bgolaszewski@baylibre.com, yamada.masahiro@socionext.com, akpm@linux-foundation.org, rui.zhang@intel.com, daniel.lezcano@linaro.org, amit.kucheria@verdurent.com, linux-arch@vger.kernel.org, linux-gpio@vger.kernel.org, linux-kernel@vger.kernel.org, linux-arm-kernel@lists.infradead.org, linux-pm@vger.kernel.org Subject: [PATCH v2 3/3] gpio: xilinx: Utilize generic bitmap_get_value and _set_value Message-ID: <1b1f706b60e4c571c4f17d53ac640e8bd8384856.1613134924.git.syednwaris@gmail.com> 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) Precedence: bulk List-ID: X-Mailing-List: linux-gpio@vger.kernel.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. Cc: William Breathitt Gray Cc: Bartosz Golaszewski Cc: Michal Simek Signed-off-by: Syed Nayyar Waris --- drivers/gpio/gpio-xilinx.c | 63 +++++++++++++++++++------------------- 1 file changed, 32 insertions(+), 31 deletions(-) diff --git a/drivers/gpio/gpio-xilinx.c b/drivers/gpio/gpio-xilinx.c index be539381fd82..8445e69cf37b 100644 --- a/drivers/gpio/gpio-xilinx.c +++ b/drivers/gpio/gpio-xilinx.c @@ -15,6 +15,7 @@ #include #include #include +#include "gpiolib.h" /* Register Offset Definitions */ #define XGPIO_DATA_OFFSET (0x0) /* Data register */ @@ -141,37 +142,37 @@ static void xgpio_set_multiple(struct gpio_chip *gc, unsigned long *mask, { unsigned long flags; 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], flags); + spin_lock(&chip->gpio_lock[1]); + + bitmap_set_value(old, 64, state[0], width[0], 0); + bitmap_set_value(old, 64, state[1], width[1], width[0]); + bitmap_replace(new, old, bits, mask, gc->ngpio); + + bitmap_set_value(old, 64, state[0], 32, 0); + bitmap_set_value(old, 64, 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, 64, state[0], 32, 0); + bitmap_set_value(new, 64, 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], flags); } /** -- 2.29.0 From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-12.2 required=3.0 tests=BAYES_00, DKIM_ADSP_CUSTOM_MED,DKIM_SIGNED,DKIM_VALID,FREEMAIL_FORGED_FROMDOMAIN, FREEMAIL_FROM,HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_CR_TRAILER, INCLUDES_PATCH,MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS,URIBL_BLOCKED, USER_AGENT_SANE_1 autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 86C51C433DB for ; Fri, 12 Feb 2021 13:23:29 +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 3C92B60295 for ; Fri, 12 Feb 2021 13:23:29 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 3C92B60295 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+linux-arm-kernel=archiver.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=zNHEmrLX7c0kFQ7f4y7wKD443F645Ap6oyrDVsaMJ4Y=; b=jA99BpI6QGFl6rk/825wOkQ8A SAujMlxk0sBJash8CPaOG1sMtkwOcPayyOh/uhk8SQAUGmmSrzP+IJCIexPg5vgaTsbFQ13zT7xnc AiO9MZeXkrnjnu2a/N/awzhViMAxhwmd68wZKhmmfzDGQg4R2SyMMa0GJQQKDV6yC9C4Nnl5APJZ+ 9sMMMY6OH44kSJfdTpk9Z0bONFZal/6utmgBqlYGDHC9EeHoUjAhvC6I2l2lKihbma0Z66TVmrPB7 1I1Q7mgws6GWvNH5y7PUAGAvqTnZ/6njYnouv5OQPEGzYMm+7A3wLIKJNjrmVtqH0yyv66CN8kBGg 6HjiM+Y0w==; Received: from localhost ([::1] helo=merlin.infradead.org) by merlin.infradead.org with esmtp (Exim 4.92.3 #3 (Red Hat Linux)) id 1lAYOr-0003DU-Se; Fri, 12 Feb 2021 13:22:21 +0000 Received: from mail-pj1-x1036.google.com ([2607:f8b0:4864:20::1036]) by merlin.infradead.org with esmtps (Exim 4.92.3 #3 (Red Hat Linux)) id 1lAYOn-0003Av-Gh for linux-arm-kernel@lists.infradead.org; Fri, 12 Feb 2021 13:22:18 +0000 Received: by mail-pj1-x1036.google.com with SMTP id lw17so384964pjb.0 for ; Fri, 12 Feb 2021 05:22:16 -0800 (PST) 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=LlK4oOejkGmVCANiTlUnm8yrZASNqtveudOgthnjqjI=; b=iQSwM5JwXDKLM+rqGqJmII6cCxrZTr/MDyQJcOwWPdUIGET0SX5Dx13XxnWQoAB9ce Yl/C+Dxd75UvNlHjdqdFOvI3d49JZhiBywK3vO9N83sZOlwQU3mLGNoVFiFIMtzr/GHe vlII8OXJn+L2qWA7GV2gpHFjmDN84VXCKXAujllae/ClEjYEuu4ABe9ijORyyc99KJel iAWaJs2XjitDtSwsr1UsCh2gWMmCdk6GpV6sJLpKNDrjJ4LDnhm17LeQGe+6VHoprmpd qB/jEHYVAzgUPn1QREHwoiEfhRO/e2Is8Hpj3lwdSFIJdo12N8xnMPq0/3IQYvMeamib W4HQ== 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=LlK4oOejkGmVCANiTlUnm8yrZASNqtveudOgthnjqjI=; b=O+Z9IkgdspSfBe7LYZ3+Sn4iZNRHZAn7TRf0JkbKKTkJlIPnUZSJyUFUtgTF3kELE4 45PfAbwpceIHcJz38tHiLsX4x6Vx7pb0WZ/ppA/oy6LutGjXcbt3xs8F/90OBh0EWL7M lwuguzUARz7AZNBShhMbKgJCtt7rh9nFugDxb4SRdEUQ7IfqAfvZwksJc5oHdQj7nUeG rDjI0uCOhyafs6prfc4XRuRsESEvKu5puhQOlDd4gXrhP4NM+Z9G1CBFWdiQ7RuZe0tV X874Zzwtm8IkfzJ9JXOL9dExofG8wr0qZJxTA+sxAZkUWKNWWDcTp+OcFXR0H6LpAP1S Lc9A== X-Gm-Message-State: AOAM533YrHcfa8V1SToabed5bKRM2wdwm5KCqX29AB1MyOmOis8GFGrK s4vzP8LuWVuXp0eUkkZhhO0= X-Google-Smtp-Source: ABdhPJyV9t8X6mKuwfE8e/aZK1KZFuuyTqGY4IAiBevhX62jo7ymr64zGlqJd1+zqtCK1Yew5apvoQ== X-Received: by 2002:a17:90a:6549:: with SMTP id f9mr2754627pjs.17.1613136135243; Fri, 12 Feb 2021 05:22:15 -0800 (PST) Received: from syed.domain.name ([103.201.127.1]) by smtp.gmail.com with ESMTPSA id q43sm5591021pjq.25.2021.02.12.05.22.08 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Fri, 12 Feb 2021 05:22:15 -0800 (PST) Date: Fri, 12 Feb 2021 18:52:00 +0530 From: Syed Nayyar Waris To: bgolaszewski@baylibre.com Subject: [PATCH v2 3/3] gpio: xilinx: Utilize generic bitmap_get_value and _set_value Message-ID: <1b1f706b60e4c571c4f17d53ac640e8bd8384856.1613134924.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-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20210212_082217_615655_6F136014 X-CRM114-Status: GOOD ( 17.75 ) 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-arch@vger.kernel.org, amit.kucheria@verdurent.com, arnd@arndb.de, yamada.masahiro@socionext.com, linux-kernel@vger.kernel.org, linus.walleij@linaro.org, daniel.lezcano@linaro.org, vilhelm.gray@gmail.com, michal.simek@xilinx.com, bgolaszewski@baylibre.com, rrichter@marvell.com, linux-gpio@vger.kernel.org, linux-pm@vger.kernel.org, akpm@linux-foundation.org, andriy.shevchenko@linux.intel.com, rui.zhang@intel.com, linux-arm-kernel@lists.infradead.org Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: 7bit Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+linux-arm-kernel=archiver.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. Cc: William Breathitt Gray Cc: Bartosz Golaszewski Cc: Michal Simek Signed-off-by: Syed Nayyar Waris --- drivers/gpio/gpio-xilinx.c | 63 +++++++++++++++++++------------------- 1 file changed, 32 insertions(+), 31 deletions(-) diff --git a/drivers/gpio/gpio-xilinx.c b/drivers/gpio/gpio-xilinx.c index be539381fd82..8445e69cf37b 100644 --- a/drivers/gpio/gpio-xilinx.c +++ b/drivers/gpio/gpio-xilinx.c @@ -15,6 +15,7 @@ #include #include #include +#include "gpiolib.h" /* Register Offset Definitions */ #define XGPIO_DATA_OFFSET (0x0) /* Data register */ @@ -141,37 +142,37 @@ static void xgpio_set_multiple(struct gpio_chip *gc, unsigned long *mask, { unsigned long flags; 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], flags); + spin_lock(&chip->gpio_lock[1]); + + bitmap_set_value(old, 64, state[0], width[0], 0); + bitmap_set_value(old, 64, state[1], width[1], width[0]); + bitmap_replace(new, old, bits, mask, gc->ngpio); + + bitmap_set_value(old, 64, state[0], 32, 0); + bitmap_set_value(old, 64, 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, 64, state[0], 32, 0); + bitmap_set_value(new, 64, 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], flags); } /** -- 2.29.0 _______________________________________________ linux-arm-kernel mailing list linux-arm-kernel@lists.infradead.org http://lists.infradead.org/mailman/listinfo/linux-arm-kernel