Commit e01aac53 authored by Yangtao Li's avatar Yangtao Li Committed by Daniel Lezcano

thermal: sun8i: Use bitmap API instead of open code

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: default avatarYangtao Li <frank@allwinnertech.com>
Acked-by: default avatarMaxime Ripard <mripard@kernel.org>
Signed-off-by: default avatarDaniel Lezcano <daniel.lezcano@linaro.org>
Link: https://lore.kernel.org/r/20201109114624.23035-1-frank@allwinnertech.com
parent ef63b043
...@@ -8,6 +8,7 @@ ...@@ -8,6 +8,7 @@
* Based on the work of Josef Gajdusek <atx@atx.name> * Based on the work of Josef Gajdusek <atx@atx.name>
*/ */
#include <linux/bitmap.h>
#include <linux/clk.h> #include <linux/clk.h>
#include <linux/device.h> #include <linux/device.h>
#include <linux/interrupt.h> #include <linux/interrupt.h>
...@@ -74,7 +75,7 @@ struct ths_thermal_chip { ...@@ -74,7 +75,7 @@ struct ths_thermal_chip {
int (*calibrate)(struct ths_device *tmdev, int (*calibrate)(struct ths_device *tmdev,
u16 *caldata, int callen); u16 *caldata, int callen);
int (*init)(struct ths_device *tmdev); 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 (*calc_temp)(struct ths_device *tmdev,
int id, int reg); int id, int reg);
}; };
...@@ -146,9 +147,10 @@ static const struct regmap_config config = { ...@@ -146,9 +147,10 @@ static const struct regmap_config config = {
.max_register = 0xfc, .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); regmap_read(tmdev->regmap, SUN8I_THS_IS, &state);
...@@ -156,16 +158,17 @@ static int sun8i_h3_irq_ack(struct ths_device *tmdev) ...@@ -156,16 +158,17 @@ static int sun8i_h3_irq_ack(struct ths_device *tmdev)
if (state & SUN8I_THS_DATA_IRQ_STS(i)) { if (state & SUN8I_THS_DATA_IRQ_STS(i)) {
regmap_write(tmdev->regmap, SUN8I_THS_IS, regmap_write(tmdev->regmap, SUN8I_THS_IS,
SUN8I_THS_DATA_IRQ_STS(i)); 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); regmap_read(tmdev->regmap, SUN50I_H6_THS_DIS, &state);
...@@ -173,24 +176,22 @@ static int sun50i_h6_irq_ack(struct ths_device *tmdev) ...@@ -173,24 +176,22 @@ static int sun50i_h6_irq_ack(struct ths_device *tmdev)
if (state & SUN50I_H6_THS_DATA_IRQ_STS(i)) { if (state & SUN50I_H6_THS_DATA_IRQ_STS(i)) {
regmap_write(tmdev->regmap, SUN50I_H6_THS_DIS, regmap_write(tmdev->regmap, SUN50I_H6_THS_DIS,
SUN50I_H6_THS_DATA_IRQ_STS(i)); 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) static irqreturn_t sun8i_irq_thread(int irq, void *data)
{ {
struct ths_device *tmdev = data; struct ths_device *tmdev = data;
int i, state; unsigned long irq_bitmap = tmdev->chip->irq_ack(tmdev);
int i;
state = tmdev->chip->irq_ack(tmdev);
for (i = 0; i < tmdev->chip->sensor_num; i++) { for_each_set_bit(i, &irq_bitmap, tmdev->chip->sensor_num) {
if (state & BIT(i)) thermal_zone_device_update(tmdev->sensor[i].tzd,
thermal_zone_device_update(tmdev->sensor[i].tzd, THERMAL_EVENT_UNSPECIFIED);
THERMAL_EVENT_UNSPECIFIED);
} }
return IRQ_HANDLED; return IRQ_HANDLED;
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment