diff mbox

[v1,3/4] thermal: mediatek: extend calibration data for mt2712 chip

Message ID 1501134417-3505-4-git-send-email-louis.yu@mediatek.com (mailing list archive)
State New, archived
Headers show

Commit Message

Louis Yu July 27, 2017, 5:46 a.m. UTC
From: Louis Yu <louis.yu@mediatek.com>

This patch adds support for mt2712 chip thermal calibration data
and calculation.

Signed-off-by: Louis Yu <louis.yu@mediatek.com>
---
 drivers/thermal/mtk_thermal.c | 8 +++++++-
 1 file changed, 7 insertions(+), 1 deletion(-)

Comments

Matthias Brugger July 27, 2017, 3:46 p.m. UTC | #1
On 07/27/2017 07:46 AM, louis.yu@mediatek.com wrote:
> From: Louis Yu <louis.yu@mediatek.com>
> 
> This patch adds support for mt2712 chip thermal calibration data
> and calculation.
> 
> Signed-off-by: Louis Yu <louis.yu@mediatek.com>
> ---
>   drivers/thermal/mtk_thermal.c | 8 +++++++-
>   1 file changed, 7 insertions(+), 1 deletion(-)
> 
> diff --git a/drivers/thermal/mtk_thermal.c b/drivers/thermal/mtk_thermal.c
> index e35d28d..f2a7155 100644
> --- a/drivers/thermal/mtk_thermal.c
> +++ b/drivers/thermal/mtk_thermal.c
> @@ -126,6 +126,8 @@
>   #define MT8173_CALIB_BUF2_VTS_TSABB(x)	(((x) >> 14) & 0x1ff)
>   #define MT8173_CALIB_BUF0_DEGC_CALI(x)	(((x) >> 1) & 0x3f)
>   #define MT8173_CALIB_BUF0_O_SLOPE(x)	(((x) >> 26) & 0x3f)
> +#define MT8173_CALIB_BUF0_O_SLOPE_SIGN(x)	(((x) >> 7) & 0x1)
> +#define MT8173_CALIB_BUF1_ID(x)	(((x) >> 9) & 0x1)

Why do define them as MT8173_* is this calibration computation generic to 
all/some SoCs?

Regards,
Matthias

>   
>   /* MT2701 thermal sensors */
>   #define MT2701_TS1	0
> @@ -609,7 +611,11 @@ static int mtk_thermal_get_calibration_data(struct device *dev,
>   		mt->vts[MT8173_TS4] = MT8173_CALIB_BUF2_VTS_TS4(buf[2]);
>   		mt->vts[MT8173_TSABB] = MT8173_CALIB_BUF2_VTS_TSABB(buf[2]);
>   		mt->degc_cali = MT8173_CALIB_BUF0_DEGC_CALI(buf[0]);
> -		mt->o_slope = MT8173_CALIB_BUF0_O_SLOPE(buf[0]);
> +		if (MT8173_CALIB_BUF1_ID(buf[1]) &
> +		    MT8173_CALIB_BUF0_O_SLOPE_SIGN(buf[0]))
> +			mt->o_slope = -MT8173_CALIB_BUF0_O_SLOPE(buf[0]);
> +		else
> +			mt->o_slope = MT8173_CALIB_BUF0_O_SLOPE(buf[0]);
>   	} else {
>   		dev_info(dev, "Device not calibrated, using default calibration values\n");
>   	}
>
Louis Yu July 31, 2017, 7:21 a.m. UTC | #2
Hi Matthias,

On Thu, 2017-07-27 at 17:46 +0200, Matthias Brugger wrote:
> 
> On 07/27/2017 07:46 AM, louis.yu@mediatek.com wrote:
> > From: Louis Yu <louis.yu@mediatek.com>
> > 
> > This patch adds support for mt2712 chip thermal calibration data
> > and calculation.
> > 
> > Signed-off-by: Louis Yu <louis.yu@mediatek.com>
> > ---
> >   drivers/thermal/mtk_thermal.c | 8 +++++++-
> >   1 file changed, 7 insertions(+), 1 deletion(-)
> > 
> > diff --git a/drivers/thermal/mtk_thermal.c b/drivers/thermal/mtk_thermal.c
> > index e35d28d..f2a7155 100644
> > --- a/drivers/thermal/mtk_thermal.c
> > +++ b/drivers/thermal/mtk_thermal.c
> > @@ -126,6 +126,8 @@
> >   #define MT8173_CALIB_BUF2_VTS_TSABB(x)	(((x) >> 14) & 0x1ff)
> >   #define MT8173_CALIB_BUF0_DEGC_CALI(x)	(((x) >> 1) & 0x3f)
> >   #define MT8173_CALIB_BUF0_O_SLOPE(x)	(((x) >> 26) & 0x3f)
> > +#define MT8173_CALIB_BUF0_O_SLOPE_SIGN(x)	(((x) >> 7) & 0x1)
> > +#define MT8173_CALIB_BUF1_ID(x)	(((x) >> 9) & 0x1)
> 
> Why do define them as MT8173_* is this calibration computation generic to 
> all/some SoCs?
> 
> Regards,
> Matthias
> 

Since this calibration computation is generic to all current
upstreamable Mediatek SoCs including mt8173, mt2701, and mt2712. Hence,
The definition of the added bits in calibration data is common for
mt8173, mt2701 and mt2712, and is compatible with these SoCs.

Regards,
Louis

> >   
> >   /* MT2701 thermal sensors */
> >   #define MT2701_TS1	0
> > @@ -609,7 +611,11 @@ static int mtk_thermal_get_calibration_data(struct device *dev,
> >   		mt->vts[MT8173_TS4] = MT8173_CALIB_BUF2_VTS_TS4(buf[2]);
> >   		mt->vts[MT8173_TSABB] = MT8173_CALIB_BUF2_VTS_TSABB(buf[2]);
> >   		mt->degc_cali = MT8173_CALIB_BUF0_DEGC_CALI(buf[0]);
> > -		mt->o_slope = MT8173_CALIB_BUF0_O_SLOPE(buf[0]);
> > +		if (MT8173_CALIB_BUF1_ID(buf[1]) &
> > +		    MT8173_CALIB_BUF0_O_SLOPE_SIGN(buf[0]))
> > +			mt->o_slope = -MT8173_CALIB_BUF0_O_SLOPE(buf[0]);
> > +		else
> > +			mt->o_slope = MT8173_CALIB_BUF0_O_SLOPE(buf[0]);
> >   	} else {
> >   		dev_info(dev, "Device not calibrated, using default calibration values\n");
> >   	}
> >
diff mbox

Patch

diff --git a/drivers/thermal/mtk_thermal.c b/drivers/thermal/mtk_thermal.c
index e35d28d..f2a7155 100644
--- a/drivers/thermal/mtk_thermal.c
+++ b/drivers/thermal/mtk_thermal.c
@@ -126,6 +126,8 @@ 
 #define MT8173_CALIB_BUF2_VTS_TSABB(x)	(((x) >> 14) & 0x1ff)
 #define MT8173_CALIB_BUF0_DEGC_CALI(x)	(((x) >> 1) & 0x3f)
 #define MT8173_CALIB_BUF0_O_SLOPE(x)	(((x) >> 26) & 0x3f)
+#define MT8173_CALIB_BUF0_O_SLOPE_SIGN(x)	(((x) >> 7) & 0x1)
+#define MT8173_CALIB_BUF1_ID(x)	(((x) >> 9) & 0x1)
 
 /* MT2701 thermal sensors */
 #define MT2701_TS1	0
@@ -609,7 +611,11 @@  static int mtk_thermal_get_calibration_data(struct device *dev,
 		mt->vts[MT8173_TS4] = MT8173_CALIB_BUF2_VTS_TS4(buf[2]);
 		mt->vts[MT8173_TSABB] = MT8173_CALIB_BUF2_VTS_TSABB(buf[2]);
 		mt->degc_cali = MT8173_CALIB_BUF0_DEGC_CALI(buf[0]);
-		mt->o_slope = MT8173_CALIB_BUF0_O_SLOPE(buf[0]);
+		if (MT8173_CALIB_BUF1_ID(buf[1]) &
+		    MT8173_CALIB_BUF0_O_SLOPE_SIGN(buf[0]))
+			mt->o_slope = -MT8173_CALIB_BUF0_O_SLOPE(buf[0]);
+		else
+			mt->o_slope = MT8173_CALIB_BUF0_O_SLOPE(buf[0]);
 	} else {
 		dev_info(dev, "Device not calibrated, using default calibration values\n");
 	}