From: Frank Lee <frank@allwinnertech.com>
To: anarsoul@gmail.com, tiny.windzz@gmail.com, rui.zhang@intel.com,
daniel.lezcano@linaro.org, amitk@kernel.org, mripard@kernel.org,
wens@csie.org
Cc: linux-pm@vger.kernel.org, linux-arm-kernel@lists.infradead.org,
linux-kernel@vger.kernel.org,
Yangtao Li <frank@allwinnertech.com>
Subject: [PATCH] thermal: sun8i: Use bitmap API instead of open code
Date: Mon, 19 Oct 2020 19:58:36 +0800 [thread overview]
Message-ID: <20201019115836.13982-1-frank@allwinnertech.com> (raw)
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
next reply other threads:[~2020-10-19 11:58 UTC|newest]
Thread overview: 4+ messages / expand[flat|nested] mbox.gz Atom feed top
2020-10-19 11:58 Frank Lee [this message]
2020-10-28 13:51 ` [PATCH] thermal: sun8i: Use bitmap API instead of open code Maxime Ripard
-- strict thread matches above, loose matches on Subject: below --
2020-11-09 11:43 Frank Lee
2020-11-09 11:45 ` Frank Lee
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20201019115836.13982-1-frank@allwinnertech.com \
--to=frank@allwinnertech.com \
--cc=amitk@kernel.org \
--cc=anarsoul@gmail.com \
--cc=daniel.lezcano@linaro.org \
--cc=linux-arm-kernel@lists.infradead.org \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-pm@vger.kernel.org \
--cc=mripard@kernel.org \
--cc=rui.zhang@intel.com \
--cc=tiny.windzz@gmail.com \
--cc=wens@csie.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox