[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Message-Id: <20190810052829.6032-16-tiny.windzz@gmail.com>
Date: Sat, 10 Aug 2019 05:28:26 +0000
From: Yangtao Li <tiny.windzz@...il.com>
To: rui.zhang@...el.com, edubezval@...il.com,
daniel.lezcano@...aro.org, robh+dt@...nel.org,
mark.rutland@....com, maxime.ripard@...tlin.com, wens@...e.org,
mchehab+samsung@...nel.org, davem@...emloft.net,
gregkh@...uxfoundation.org, Jonathan.Cameron@...wei.com,
nicolas.ferre@...rochip.com
Cc: linux-pm@...r.kernel.org, devicetree@...r.kernel.org,
linux-arm-kernel@...ts.infradead.org, linux-kernel@...r.kernel.org,
Icenowy Zheng <icenowy@...c.io>
Subject: [PATCH v5 15/18] thermal: sun8i: allow to use custom temperature calculation function
From: Icenowy Zheng <icenowy@...c.io>
The H5 temperature calculation function is strange. Firstly, it's
segmented. Secondly, the formula of two sensors are different in the
second segment.
Allow to use a custom temperature calculation function, in case of
the function is complex.
Signed-off-by: Icenowy Zheng <icenowy@...c.io>
---
drivers/thermal/sun8i_thermal.c | 12 ++++++++----
1 file changed, 8 insertions(+), 4 deletions(-)
diff --git a/drivers/thermal/sun8i_thermal.c b/drivers/thermal/sun8i_thermal.c
index 3259081da841..a761e2afda08 100644
--- a/drivers/thermal/sun8i_thermal.c
+++ b/drivers/thermal/sun8i_thermal.c
@@ -76,6 +76,7 @@ struct ths_thermal_chip {
u16 *caldata, int callen);
int (*init)(struct ths_device *tmdev);
int (*irq_ack)(struct ths_device *tmdev);
+ int (*calc_temp)(int id, int reg);
};
struct ths_device {
@@ -90,9 +91,12 @@ struct ths_device {
/* Temp Unit: millidegree Celsius */
static int sun8i_ths_reg2temp(struct ths_device *tmdev,
- int reg)
+ int id, int reg)
{
- return (reg + tmdev->chip->offset) * tmdev->chip->scale;
+ if (tmdev->chip->calc_temp)
+ return tmdev->chip->calc_temp(id, reg);
+ else
+ return (reg + tmdev->chip->offset) * tmdev->chip->scale;
}
static int sun8i_ths_get_temp(void *data, int *temp)
@@ -108,7 +112,7 @@ static int sun8i_ths_get_temp(void *data, int *temp)
if (!val)
return -EAGAIN;
- *temp = sun8i_ths_reg2temp(tmdev, val);
+ *temp = sun8i_ths_reg2temp(tmdev, s->id, val);
/*
* XX - According to the original sdk, there are some platforms(rarely)
* that add a fixed offset value after calculating the temperature
@@ -232,7 +236,7 @@ static int sun50i_h6_ths_calibrate(struct ths_device *tmdev,
for (i = 0; i < tmdev->chip->sensor_num; i++) {
int reg = (int)caldata[i + 1];
- int sensor_temp = sun8i_ths_reg2temp(tmdev, reg);
+ int sensor_temp = sun8i_ths_reg2temp(tmdev, i, reg);
int delta, cdata, offset;
/*
--
2.17.1
Powered by blists - more mailing lists