[v1,4/5] gpio: xilinx: Replace bitmap_bitremap() calls

Message ID 20230926052007.3917389-5-andriy.shevchenko@linux.intel.com
State New
Headers
Series bitmap: get rid of bitmap_remap() and bitmap_biremap() uses |

Commit Message

Andy Shevchenko Sept. 26, 2023, 5:20 a.m. UTC
  We have sparse and dence masks of the line mappings based on
the view point (Linux numbering or hardware numbering). Since
the Linux side uses sequential bits for the mask, we can simply
convert a Linux number to the hardware one and vise versa by
counting set bits in the respective mask. Hence replace
bitmap_bitremap() calls by simpler equivalents.

With this done the dence mask is not needed and thus dropped.

Signed-off-by: Andy Shevchenko <andriy.shevchenko@linux.intel.com>
---
 drivers/gpio/gpio-xilinx.c | 9 ++-------
 1 file changed, 2 insertions(+), 7 deletions(-)
  

Comments

Kent Gibson Sept. 26, 2023, 10:41 a.m. UTC | #1
On Tue, Sep 26, 2023 at 08:20:06AM +0300, Andy Shevchenko wrote:
> We have sparse and dence masks of the line mappings based on

dense

> the view point (Linux numbering or hardware numbering). Since
> the Linux side uses sequential bits for the mask, we can simply
> convert a Linux number to the hardware one and vise versa by

vice

> counting set bits in the respective mask. Hence replace
> bitmap_bitremap() calls by simpler equivalents.
> 
> With this done the dence mask is not needed and thus dropped.
> 

And dense again.

Cheers,
Kent.

> Signed-off-by: Andy Shevchenko <andriy.shevchenko@linux.intel.com>
> ---
>  drivers/gpio/gpio-xilinx.c | 9 ++-------
>  1 file changed, 2 insertions(+), 7 deletions(-)
> 
> diff --git a/drivers/gpio/gpio-xilinx.c b/drivers/gpio/gpio-xilinx.c
> index f103c30cc74f..14ca3097563a 100644
> --- a/drivers/gpio/gpio-xilinx.c
> +++ b/drivers/gpio/gpio-xilinx.c
> @@ -46,7 +46,6 @@
>   * @gc: GPIO chip
>   * @regs: register block
>   * @hw_map: GPIO pin mapping on hardware side
> - * @sw_map: GPIO pin mapping on software side
>   * @state: GPIO write state shadow register
>   * @last_irq_read: GPIO read state register from last interrupt
>   * @dir: GPIO direction shadow register
> @@ -62,7 +61,6 @@ struct xgpio_instance {
>  	struct gpio_chip gc;
>  	void __iomem *regs;
>  	DECLARE_BITMAP(hw_map, 64);
> -	DECLARE_BITMAP(sw_map, 64);
>  	DECLARE_BITMAP(state, 64);
>  	DECLARE_BITMAP(last_irq_read, 64);
>  	DECLARE_BITMAP(dir, 64);
> @@ -76,12 +74,12 @@ struct xgpio_instance {
>  
>  static inline int xgpio_from_bit(struct xgpio_instance *chip, int bit)
>  {
> -	return bitmap_bitremap(bit, chip->hw_map, chip->sw_map, 64);
> +	return bitmap_weight(chip->hw_map, bit + 1);
>  }
>  
>  static inline int xgpio_to_bit(struct xgpio_instance *chip, int gpio)
>  {
> -	return bitmap_bitremap(gpio, chip->sw_map, chip->hw_map, 64);
> +	return find_nth_bit(chip->hw_map, 64, gpio);
>  }
>  
>  static inline u32 xgpio_get_value32(const unsigned long *map, int bit)
> @@ -619,9 +617,6 @@ static int xgpio_probe(struct platform_device *pdev)
>  	if (width[1] > 32)
>  		return -EINVAL;
>  
> -	/* Setup software pin mapping */
> -	bitmap_set(chip->sw_map, 0, width[0] + width[1]);
> -
>  	/* Setup hardware pin mapping */
>  	bitmap_set(chip->hw_map,  0, width[0]);
>  	bitmap_set(chip->hw_map, 32, width[1]);
> -- 
> 2.40.0.1.gaa8946217a0b
>
  
Andy Shevchenko Sept. 26, 2023, 11:11 a.m. UTC | #2
On Tue, Sep 26, 2023 at 06:41:00PM +0800, Kent Gibson wrote:
> On Tue, Sep 26, 2023 at 08:20:06AM +0300, Andy Shevchenko wrote:
> > We have sparse and dence masks of the line mappings based on
> 
> dense
> 
> > the view point (Linux numbering or hardware numbering). Since
> > the Linux side uses sequential bits for the mask, we can simply
> > convert a Linux number to the hardware one and vise versa by
> 
> vice
> 
> > counting set bits in the respective mask. Hence replace
> > bitmap_bitremap() calls by simpler equivalents.
> > 
> > With this done the dence mask is not needed and thus dropped.
> 
> And dense again.

Thank you, Kent, I really appreciate your help with my poor English,
nevertheless it would be nice if you can look at the last patch and
maybe even test it, so we have a bit of confidence that it works
as expected.

(The spelling will be fixed in the next version.)
  
Kent Gibson Sept. 26, 2023, 11:17 a.m. UTC | #3
On Tue, Sep 26, 2023 at 02:11:14PM +0300, Andy Shevchenko wrote:
> On Tue, Sep 26, 2023 at 06:41:00PM +0800, Kent Gibson wrote:
> > On Tue, Sep 26, 2023 at 08:20:06AM +0300, Andy Shevchenko wrote:
> > > We have sparse and dence masks of the line mappings based on
> > 
> > dense
> > 
> > > the view point (Linux numbering or hardware numbering). Since
> > > the Linux side uses sequential bits for the mask, we can simply
> > > convert a Linux number to the hardware one and vise versa by
> > 
> > vice
> > 
> > > counting set bits in the respective mask. Hence replace
> > > bitmap_bitremap() calls by simpler equivalents.
> > > 
> > > With this done the dence mask is not needed and thus dropped.
> > 
> > And dense again.
> 
> Thank you, Kent, I really appreciate your help with my poor English,
> nevertheless it would be nice if you can look at the last patch and
> maybe even test it, so we have a bit of confidence that it works
> as expected.
> 

Well that is the plan, but I haven't been in the GPIO space for a while so
I need to pull my test setup out of mothballs first - so don't hold your
breath.

> (The spelling will be fixed in the next version.)
> 

Those I can spot without needing to compile anything ;-).

Cheers,
Kent.
  

Patch

diff --git a/drivers/gpio/gpio-xilinx.c b/drivers/gpio/gpio-xilinx.c
index f103c30cc74f..14ca3097563a 100644
--- a/drivers/gpio/gpio-xilinx.c
+++ b/drivers/gpio/gpio-xilinx.c
@@ -46,7 +46,6 @@ 
  * @gc: GPIO chip
  * @regs: register block
  * @hw_map: GPIO pin mapping on hardware side
- * @sw_map: GPIO pin mapping on software side
  * @state: GPIO write state shadow register
  * @last_irq_read: GPIO read state register from last interrupt
  * @dir: GPIO direction shadow register
@@ -62,7 +61,6 @@  struct xgpio_instance {
 	struct gpio_chip gc;
 	void __iomem *regs;
 	DECLARE_BITMAP(hw_map, 64);
-	DECLARE_BITMAP(sw_map, 64);
 	DECLARE_BITMAP(state, 64);
 	DECLARE_BITMAP(last_irq_read, 64);
 	DECLARE_BITMAP(dir, 64);
@@ -76,12 +74,12 @@  struct xgpio_instance {
 
 static inline int xgpio_from_bit(struct xgpio_instance *chip, int bit)
 {
-	return bitmap_bitremap(bit, chip->hw_map, chip->sw_map, 64);
+	return bitmap_weight(chip->hw_map, bit + 1);
 }
 
 static inline int xgpio_to_bit(struct xgpio_instance *chip, int gpio)
 {
-	return bitmap_bitremap(gpio, chip->sw_map, chip->hw_map, 64);
+	return find_nth_bit(chip->hw_map, 64, gpio);
 }
 
 static inline u32 xgpio_get_value32(const unsigned long *map, int bit)
@@ -619,9 +617,6 @@  static int xgpio_probe(struct platform_device *pdev)
 	if (width[1] > 32)
 		return -EINVAL;
 
-	/* Setup software pin mapping */
-	bitmap_set(chip->sw_map, 0, width[0] + width[1]);
-
 	/* Setup hardware pin mapping */
 	bitmap_set(chip->hw_map,  0, width[0]);
 	bitmap_set(chip->hw_map, 32, width[1]);