lkml.org 
[lkml]   [2019]   [Aug]   [10]   [last100]   RSS Feed
Views: [wrap][no wrap]   [headers]  [forward] 
 
Messages in this thread
Patch in this message
/
From
Subject[PATCH v5 05/18] thermal: sun8i: rework for sun8i_ths_get_temp()
Date
For different socs, the way they get and calculate the
temperature is roughly the same. So get the difference
from device compatible.

Difference point:
1) temperature calculation formula parameters
2) ths data register start address

Signed-off-by: Yangtao Li <tiny.windzz@gmail.com>
---
drivers/thermal/sun8i_thermal.c | 17 +++++++++++------
1 file changed, 11 insertions(+), 6 deletions(-)

diff --git a/drivers/thermal/sun8i_thermal.c b/drivers/thermal/sun8i_thermal.c
index e9c2acbaac74..f338fa25b98e 100644
--- a/drivers/thermal/sun8i_thermal.c
+++ b/drivers/thermal/sun8i_thermal.c
@@ -22,9 +22,6 @@

#define MAX_SENSOR_NUM 4

-#define SUN50I_H6_OFFSET -2794
-#define SUN50I_H6_SCALE -67
-
#define FT_TEMP_MASK GENMASK(11, 0)
#define TEMP_CALIB_MASK GENMASK(11, 0)
#define TEMP_TO_REG 672
@@ -58,6 +55,10 @@ struct tsensor {

struct ths_thermal_chip {
int sensor_num;
+ int offset;
+ int scale;
+ int ft_deviation;
+ int temp_data_base;
};

struct ths_device {
@@ -73,7 +74,7 @@ struct ths_device {
static int sun8i_ths_reg2temp(struct ths_device *tmdev,
int reg)
{
- return (reg + SUN50I_H6_OFFSET) * SUN50I_H6_SCALE;
+ return (reg + tmdev->chip->offset) * tmdev->chip->scale;
}

static int sun8i_ths_get_temp(void *data, int *temp)
@@ -82,7 +83,7 @@ static int sun8i_ths_get_temp(void *data, int *temp)
struct ths_device *tmdev = s->tmdev;
int val;

- regmap_read(tmdev->regmap, SUN50I_H6_THS_TEMP_DATA +
+ regmap_read(tmdev->regmap, tmdev->chip->temp_data_base +
0x4 * s->id, &val);

/* ths have no data yet */
@@ -98,7 +99,7 @@ static int sun8i_ths_get_temp(void *data, int *temp)
* temperature above is also used when the sensor is calibrated. If
* do this, the correct calibration formula is hard to know.
*/
- *temp += SUN50I_H6_FT_DEVIATION;
+ *temp += tmdev->chip->ft_deviation;

return 0;
}
@@ -389,6 +390,10 @@ static int sun8i_ths_remove(struct platform_device *pdev)

static const struct ths_thermal_chip sun50i_h6_ths = {
.sensor_num = 2,
+ .offset = -2794,
+ .scale = -67,
+ .ft_deviation = SUN50I_H6_FT_DEVIATION,
+ .temp_data_base = SUN50I_H6_THS_TEMP_DATA,
};

static const struct of_device_id of_ths_match[] = {
--
2.17.1
\
 
 \ /
  Last update: 2019-08-10 07:29    [W:0.217 / U:83.364 seconds]
©2003-2018 Jasper Spaans|hosted at Digital Ocean and TransIP|Read the blog|Advertise on this site