linux-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH] thermal: sun8i: Use bitmap API instead of open code
@ 2020-11-09 11:43 Frank Lee
  2020-11-09 11:45 ` Frank Lee
  0 siblings, 1 reply; 4+ messages in thread
From: Frank Lee @ 2020-11-09 11:43 UTC (permalink / raw)
  To: anarsoul, tiny.windzz, rui.zhang, daniel.lezcano, amitk, mripard, wens
  Cc: linux-pm, linux-arm-kernel, linux-kernel, Yangtao Li

From: Yangtao Li <frank@allwinnertech.com>

The bitmap_* API is the standard way to access data in the bitfield.
So convert irq_ack to return an unsigned long, and make things to use
bitmap API.

Signed-off-by: Yangtao Li <frank@allwinnertech.com>
---
v2:
Make irq_ack to return an unsigned long
---
 drivers/thermal/sun8i_thermal.c | 33 +++++++++++++++++----------------
 1 file changed, 17 insertions(+), 16 deletions(-)

diff --git a/drivers/thermal/sun8i_thermal.c b/drivers/thermal/sun8i_thermal.c
index f8b13071a6f4..8c80bd06dd9f 100644
--- a/drivers/thermal/sun8i_thermal.c
+++ b/drivers/thermal/sun8i_thermal.c
@@ -8,6 +8,7 @@
  * Based on the work of Josef Gajdusek <atx@atx.name>
  */
 
+#include <linux/bitmap.h>
 #include <linux/clk.h>
 #include <linux/device.h>
 #include <linux/interrupt.h>
@@ -74,7 +75,7 @@ struct ths_thermal_chip {
 	int		(*calibrate)(struct ths_device *tmdev,
 				     u16 *caldata, int callen);
 	int		(*init)(struct ths_device *tmdev);
-	int             (*irq_ack)(struct ths_device *tmdev);
+	unsigned long	(*irq_ack)(struct ths_device *tmdev);
 	int		(*calc_temp)(struct ths_device *tmdev,
 				     int id, int reg);
 };
@@ -146,9 +147,10 @@ static const struct regmap_config config = {
 	.max_register = 0xfc,
 };
 
-static int sun8i_h3_irq_ack(struct ths_device *tmdev)
+static unsigned long sun8i_h3_irq_ack(struct ths_device *tmdev)
 {
-	int i, state, ret = 0;
+	unsigned long irq_bitmap = 0;
+	int i, state;
 
 	regmap_read(tmdev->regmap, SUN8I_THS_IS, &state);
 
@@ -156,16 +158,17 @@ static int sun8i_h3_irq_ack(struct ths_device *tmdev)
 		if (state & SUN8I_THS_DATA_IRQ_STS(i)) {
 			regmap_write(tmdev->regmap, SUN8I_THS_IS,
 				     SUN8I_THS_DATA_IRQ_STS(i));
-			ret |= BIT(i);
+			bitmap_set(&irq_bitmap, i, 1);
 		}
 	}
 
-	return ret;
+	return irq_bitmap;
 }
 
-static int sun50i_h6_irq_ack(struct ths_device *tmdev)
+static unsigned long sun50i_h6_irq_ack(struct ths_device *tmdev)
 {
-	int i, state, ret = 0;
+	unsigned long irq_bitmap = 0;
+	int i, state;
 
 	regmap_read(tmdev->regmap, SUN50I_H6_THS_DIS, &state);
 
@@ -173,24 +176,22 @@ static int sun50i_h6_irq_ack(struct ths_device *tmdev)
 		if (state & SUN50I_H6_THS_DATA_IRQ_STS(i)) {
 			regmap_write(tmdev->regmap, SUN50I_H6_THS_DIS,
 				     SUN50I_H6_THS_DATA_IRQ_STS(i));
-			ret |= BIT(i);
+			bitmap_set(&irq_bitmap, i, 1);
 		}
 	}
 
-	return ret;
+	return irq_bitmap;
 }
 
 static irqreturn_t sun8i_irq_thread(int irq, void *data)
 {
 	struct ths_device *tmdev = data;
-	int i, state;
-
-	state = tmdev->chip->irq_ack(tmdev);
+	unsigned long irq_bitmap = tmdev->chip->irq_ack(tmdev);
+	int i;
 
-	for (i = 0; i < tmdev->chip->sensor_num; i++) {
-		if (state & BIT(i))
-			thermal_zone_device_update(tmdev->sensor[i].tzd,
-						   THERMAL_EVENT_UNSPECIFIED);
+	for_each_set_bit(i, &irq_bitmap, tmdev->chip->sensor_num) {
+		thermal_zone_device_update(tmdev->sensor[i].tzd,
+					   THERMAL_EVENT_UNSPECIFIED);
 	}
 
 	return IRQ_HANDLED;
-- 
2.28.0


^ permalink raw reply related	[flat|nested] 4+ messages in thread

* Re: [PATCH] thermal: sun8i: Use bitmap API instead of open code
  2020-11-09 11:43 [PATCH] thermal: sun8i: Use bitmap API instead of open code Frank Lee
@ 2020-11-09 11:45 ` Frank Lee
  0 siblings, 0 replies; 4+ messages in thread
From: Frank Lee @ 2020-11-09 11:45 UTC (permalink / raw)
  To: Frank Lee
  Cc: Vasily Khoruzhick, Zhang Rui, Daniel Lezcano, amitk,
	Maxime Ripard, Chen-Yu Tsai, Linux PM, Linux ARM,
	Linux Kernel Mailing List

I forgot to add "V2", I will resend.

Yangtao

^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: [PATCH] thermal: sun8i: Use bitmap API instead of open code
  2020-10-19 11:58 Frank Lee
@ 2020-10-28 13:51 ` Maxime Ripard
  0 siblings, 0 replies; 4+ messages in thread
From: Maxime Ripard @ 2020-10-28 13:51 UTC (permalink / raw)
  To: Frank Lee
  Cc: anarsoul, tiny.windzz, rui.zhang, daniel.lezcano, amitk, wens,
	linux-pm, linux-arm-kernel, linux-kernel

[-- Attachment #1: Type: text/plain, Size: 3835 bytes --]

Hi Frank,

On Mon, Oct 19, 2020 at 07:58:36PM +0800, Frank Lee wrote:
> From: Yangtao Li <frank@allwinnertech.com>
> 
> Thw bitmap_* API is the standard way to access data in the bitfield.
> 
> Signed-off-by: Yangtao Li <frank@allwinnertech.com>
> ---
>  drivers/thermal/sun8i_thermal.c | 35 +++++++++++++++++----------------
>  1 file changed, 18 insertions(+), 17 deletions(-)
> 
> diff --git a/drivers/thermal/sun8i_thermal.c b/drivers/thermal/sun8i_thermal.c
> index f8b13071a6f4..f2e4a4f18101 100644
> --- a/drivers/thermal/sun8i_thermal.c
> +++ b/drivers/thermal/sun8i_thermal.c
> @@ -8,6 +8,7 @@
>   * Based on the work of Josef Gajdusek <atx@atx.name>
>   */
>  
> +#include <linux/bitmap.h>
>  #include <linux/clk.h>
>  #include <linux/device.h>
>  #include <linux/interrupt.h>
> @@ -74,7 +75,7 @@ struct ths_thermal_chip {
>  	int		(*calibrate)(struct ths_device *tmdev,
>  				     u16 *caldata, int callen);
>  	int		(*init)(struct ths_device *tmdev);
> -	int             (*irq_ack)(struct ths_device *tmdev);
> +	void		(*irq_ack)(struct ths_device *tmdev);
>  	int		(*calc_temp)(struct ths_device *tmdev,
>  				     int id, int reg);
>  };
> @@ -82,6 +83,7 @@ struct ths_thermal_chip {
>  struct ths_device {
>  	const struct ths_thermal_chip		*chip;
>  	struct device				*dev;
> +	DECLARE_BITMAP(irq_bitmap, MAX_SENSOR_NUM);
>  	struct regmap				*regmap;
>  	struct reset_control			*reset;
>  	struct clk				*bus_clk;
> @@ -146,9 +148,11 @@ static const struct regmap_config config = {
>  	.max_register = 0xfc,
>  };
>  
> -static int sun8i_h3_irq_ack(struct ths_device *tmdev)
> +static void sun8i_h3_irq_ack(struct ths_device *tmdev)
>  {
> -	int i, state, ret = 0;
> +	int i, state;
> +
> +	bitmap_zero(tmdev->irq_bitmap, tmdev->chip->sensor_num);
>  
>  	regmap_read(tmdev->regmap, SUN8I_THS_IS, &state);
>  
> @@ -156,16 +160,16 @@ static int sun8i_h3_irq_ack(struct ths_device *tmdev)
>  		if (state & SUN8I_THS_DATA_IRQ_STS(i)) {
>  			regmap_write(tmdev->regmap, SUN8I_THS_IS,
>  				     SUN8I_THS_DATA_IRQ_STS(i));
> -			ret |= BIT(i);
> +			bitmap_set(tmdev->irq_bitmap, i, 1);
>  		}
>  	}
> -
> -	return ret;
>  }
>  
> -static int sun50i_h6_irq_ack(struct ths_device *tmdev)
> +static void sun50i_h6_irq_ack(struct ths_device *tmdev)
>  {
> -	int i, state, ret = 0;
> +	int i, state;
> +
> +	bitmap_zero(tmdev->irq_bitmap, tmdev->chip->sensor_num);
>  
>  	regmap_read(tmdev->regmap, SUN50I_H6_THS_DIS, &state);
>  
> @@ -173,24 +177,21 @@ static int sun50i_h6_irq_ack(struct ths_device *tmdev)
>  		if (state & SUN50I_H6_THS_DATA_IRQ_STS(i)) {
>  			regmap_write(tmdev->regmap, SUN50I_H6_THS_DIS,
>  				     SUN50I_H6_THS_DATA_IRQ_STS(i));
> -			ret |= BIT(i);
> +			bitmap_set(tmdev->irq_bitmap, i, 1);
>  		}
>  	}
> -
> -	return ret;

The bitfield of the acked interrupts is mostly something internal to the
handler, so I'm not really convinced about sharing that through the
global structure.

With that being said...

>  }
>  
>  static irqreturn_t sun8i_irq_thread(int irq, void *data)
>  {
>  	struct ths_device *tmdev = data;
> -	int i, state;
> +	int i;
>  
> -	state = tmdev->chip->irq_ack(tmdev);
> +	tmdev->chip->irq_ack(tmdev);
>  
> -	for (i = 0; i < tmdev->chip->sensor_num; i++) {
> -		if (state & BIT(i))
> -			thermal_zone_device_update(tmdev->sensor[i].tzd,
> -						   THERMAL_EVENT_UNSPECIFIED);
> +	for_each_set_bit(i, tmdev->irq_bitmap, tmdev->chip->sensor_num) {
> +		thermal_zone_device_update(tmdev->sensor[i].tzd,
> +					   THERMAL_EVENT_UNSPECIFIED);

.. for_each_set_bit is definitely cleaner and more readable.

Since it can operate on any unsigned long pointer, maybe we can just
make irq_ack return an unsigned long, and iterate over it here?

Maxime

[-- Attachment #2: signature.asc --]
[-- Type: application/pgp-signature, Size: 228 bytes --]

^ permalink raw reply	[flat|nested] 4+ messages in thread

* [PATCH] thermal: sun8i: Use bitmap API instead of open code
@ 2020-10-19 11:58 Frank Lee
  2020-10-28 13:51 ` Maxime Ripard
  0 siblings, 1 reply; 4+ messages in thread
From: Frank Lee @ 2020-10-19 11:58 UTC (permalink / raw)
  To: anarsoul, tiny.windzz, rui.zhang, daniel.lezcano, amitk, mripard, wens
  Cc: linux-pm, linux-arm-kernel, linux-kernel, Yangtao Li

From: Yangtao Li <frank@allwinnertech.com>

Thw bitmap_* API is the standard way to access data in the bitfield.

Signed-off-by: Yangtao Li <frank@allwinnertech.com>
---
 drivers/thermal/sun8i_thermal.c | 35 +++++++++++++++++----------------
 1 file changed, 18 insertions(+), 17 deletions(-)

diff --git a/drivers/thermal/sun8i_thermal.c b/drivers/thermal/sun8i_thermal.c
index f8b13071a6f4..f2e4a4f18101 100644
--- a/drivers/thermal/sun8i_thermal.c
+++ b/drivers/thermal/sun8i_thermal.c
@@ -8,6 +8,7 @@
  * Based on the work of Josef Gajdusek <atx@atx.name>
  */
 
+#include <linux/bitmap.h>
 #include <linux/clk.h>
 #include <linux/device.h>
 #include <linux/interrupt.h>
@@ -74,7 +75,7 @@ struct ths_thermal_chip {
 	int		(*calibrate)(struct ths_device *tmdev,
 				     u16 *caldata, int callen);
 	int		(*init)(struct ths_device *tmdev);
-	int             (*irq_ack)(struct ths_device *tmdev);
+	void		(*irq_ack)(struct ths_device *tmdev);
 	int		(*calc_temp)(struct ths_device *tmdev,
 				     int id, int reg);
 };
@@ -82,6 +83,7 @@ struct ths_thermal_chip {
 struct ths_device {
 	const struct ths_thermal_chip		*chip;
 	struct device				*dev;
+	DECLARE_BITMAP(irq_bitmap, MAX_SENSOR_NUM);
 	struct regmap				*regmap;
 	struct reset_control			*reset;
 	struct clk				*bus_clk;
@@ -146,9 +148,11 @@ static const struct regmap_config config = {
 	.max_register = 0xfc,
 };
 
-static int sun8i_h3_irq_ack(struct ths_device *tmdev)
+static void sun8i_h3_irq_ack(struct ths_device *tmdev)
 {
-	int i, state, ret = 0;
+	int i, state;
+
+	bitmap_zero(tmdev->irq_bitmap, tmdev->chip->sensor_num);
 
 	regmap_read(tmdev->regmap, SUN8I_THS_IS, &state);
 
@@ -156,16 +160,16 @@ static int sun8i_h3_irq_ack(struct ths_device *tmdev)
 		if (state & SUN8I_THS_DATA_IRQ_STS(i)) {
 			regmap_write(tmdev->regmap, SUN8I_THS_IS,
 				     SUN8I_THS_DATA_IRQ_STS(i));
-			ret |= BIT(i);
+			bitmap_set(tmdev->irq_bitmap, i, 1);
 		}
 	}
-
-	return ret;
 }
 
-static int sun50i_h6_irq_ack(struct ths_device *tmdev)
+static void sun50i_h6_irq_ack(struct ths_device *tmdev)
 {
-	int i, state, ret = 0;
+	int i, state;
+
+	bitmap_zero(tmdev->irq_bitmap, tmdev->chip->sensor_num);
 
 	regmap_read(tmdev->regmap, SUN50I_H6_THS_DIS, &state);
 
@@ -173,24 +177,21 @@ static int sun50i_h6_irq_ack(struct ths_device *tmdev)
 		if (state & SUN50I_H6_THS_DATA_IRQ_STS(i)) {
 			regmap_write(tmdev->regmap, SUN50I_H6_THS_DIS,
 				     SUN50I_H6_THS_DATA_IRQ_STS(i));
-			ret |= BIT(i);
+			bitmap_set(tmdev->irq_bitmap, i, 1);
 		}
 	}
-
-	return ret;
 }
 
 static irqreturn_t sun8i_irq_thread(int irq, void *data)
 {
 	struct ths_device *tmdev = data;
-	int i, state;
+	int i;
 
-	state = tmdev->chip->irq_ack(tmdev);
+	tmdev->chip->irq_ack(tmdev);
 
-	for (i = 0; i < tmdev->chip->sensor_num; i++) {
-		if (state & BIT(i))
-			thermal_zone_device_update(tmdev->sensor[i].tzd,
-						   THERMAL_EVENT_UNSPECIFIED);
+	for_each_set_bit(i, tmdev->irq_bitmap, tmdev->chip->sensor_num) {
+		thermal_zone_device_update(tmdev->sensor[i].tzd,
+					   THERMAL_EVENT_UNSPECIFIED);
 	}
 
 	return IRQ_HANDLED;
-- 
2.28.0


^ permalink raw reply related	[flat|nested] 4+ messages in thread

end of thread, other threads:[~2020-11-09 11:45 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2020-11-09 11:43 [PATCH] thermal: sun8i: Use bitmap API instead of open code Frank Lee
2020-11-09 11:45 ` Frank Lee
  -- strict thread matches above, loose matches on Subject: below --
2020-10-19 11:58 Frank Lee
2020-10-28 13:51 ` Maxime Ripard

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).