[3/6] thermal/drivers/qcom/tsens-v0_1: Add support for MSM8226

Message ID 20230507201225.89694-4-matti.lehtimaki@gmail.com
State New
Headers
Series Enable MSM8226 TSENS support |

Commit Message

Matti Lehtimäki May 7, 2023, 8:12 p.m. UTC
  The MSM8226 TSENS IP has 6 thermal sensors in a TSENS v0.1 block.
The thermal sensors use non-standard slope values.

Signed-off-by: Matti Lehtimäki <matti.lehtimaki@gmail.com>
---
 drivers/thermal/qcom/tsens-v0_1.c | 27 ++++++++++++++++++++++++++-
 drivers/thermal/qcom/tsens.c      |  3 +++
 drivers/thermal/qcom/tsens.h      |  2 +-
 3 files changed, 30 insertions(+), 2 deletions(-)
  

Comments

Luca Weiss May 7, 2023, 8:26 p.m. UTC | #1
On Sonntag, 7. Mai 2023 22:12:21 CEST Matti Lehtimäki wrote:
> The MSM8226 TSENS IP has 6 thermal sensors in a TSENS v0.1 block.
> The thermal sensors use non-standard slope values.

Matches the configuration found in msm8226-v2.dtsi in msm-3.10 kernel.

Reviewed-by: Luca Weiss <luca@z3ntu.xyz>

> 
> Signed-off-by: Matti Lehtimäki <matti.lehtimaki@gmail.com>
> ---
>  drivers/thermal/qcom/tsens-v0_1.c | 27 ++++++++++++++++++++++++++-
>  drivers/thermal/qcom/tsens.c      |  3 +++
>  drivers/thermal/qcom/tsens.h      |  2 +-
>  3 files changed, 30 insertions(+), 2 deletions(-)
> 
> diff --git a/drivers/thermal/qcom/tsens-v0_1.c
> b/drivers/thermal/qcom/tsens-v0_1.c index e89c6f39a3ae..ad57ab94546b 100644
> --- a/drivers/thermal/qcom/tsens-v0_1.c
> +++ b/drivers/thermal/qcom/tsens-v0_1.c
> @@ -243,6 +243,18 @@ static int calibrate_8974(struct tsens_priv *priv)
>  	return 0;
>  }
> 
> +static int __init init_8226(struct tsens_priv *priv)
> +{
> +	priv->sensor[0].slope = 2901;
> +	priv->sensor[1].slope = 2846;
> +	priv->sensor[2].slope = 3038;
> +	priv->sensor[3].slope = 2955;
> +	priv->sensor[4].slope = 2901;
> +	priv->sensor[5].slope = 2846;
> +
> +	return init_common(priv);
> +}
> +
>  static int __init init_8939(struct tsens_priv *priv) {
>  	priv->sensor[0].slope = 2911;
>  	priv->sensor[1].slope = 2789;
> @@ -258,7 +270,7 @@ static int __init init_8939(struct tsens_priv *priv) {
>  	return init_common(priv);
>  }
> 
> -/* v0.1: 8916, 8939, 8974, 9607 */
> +/* v0.1: 8226, 8916, 8939, 8974, 9607 */
> 
>  static struct tsens_features tsens_v0_1_feat = {
>  	.ver_major	= VER_0_1,
> @@ -313,6 +325,19 @@ static const struct tsens_ops ops_v0_1 = {
>  	.get_temp	= get_temp_common,
>  };
> 
> +static const struct tsens_ops ops_8226 = {
> +	.init		= init_8226,
> +	.calibrate	= tsens_calibrate_common,
> +	.get_temp	= get_temp_common,
> +};
> +
> +struct tsens_plat_data data_8226 = {
> +	.num_sensors	= 6,
> +	.ops		= &ops_8226,
> +	.feat		= &tsens_v0_1_feat,
> +	.fields	= tsens_v0_1_regfields,
> +};
> +
>  static const struct tsens_ops ops_8916 = {
>  	.init		= init_common,
>  	.calibrate	= calibrate_8916,
> diff --git a/drivers/thermal/qcom/tsens.c b/drivers/thermal/qcom/tsens.c
> index 8020ead2794e..eb33a8bf0488 100644
> --- a/drivers/thermal/qcom/tsens.c
> +++ b/drivers/thermal/qcom/tsens.c
> @@ -1095,6 +1095,9 @@ static const struct of_device_id tsens_table[] = {
>  	}, {
>  		.compatible = "qcom,mdm9607-tsens",
>  		.data = &data_9607,
> +	}, {
> +		.compatible = "qcom,msm8226-tsens",
> +		.data = &data_8226,
>  	}, {
>  		.compatible = "qcom,msm8916-tsens",
>  		.data = &data_8916,
> diff --git a/drivers/thermal/qcom/tsens.h b/drivers/thermal/qcom/tsens.h
> index dba9cd38f637..433eba370998 100644
> --- a/drivers/thermal/qcom/tsens.h
> +++ b/drivers/thermal/qcom/tsens.h
> @@ -635,7 +635,7 @@ int get_temp_common(const struct tsens_sensor *s, int
> *temp); extern struct tsens_plat_data data_8960;
> 
>  /* TSENS v0.1 targets */
> -extern struct tsens_plat_data data_8916, data_8939, data_8974, data_9607;
> +extern struct tsens_plat_data data_8226, data_8916, data_8939, data_8974,
> data_9607;
> 
>  /* TSENS v1 targets */
>  extern struct tsens_plat_data data_tsens_v1, data_8976, data_8956;
  
Dmitry Baryshkov May 7, 2023, 8:40 p.m. UTC | #2
On 07/05/2023 23:12, Matti Lehtimäki wrote:
> The MSM8226 TSENS IP has 6 thermal sensors in a TSENS v0.1 block.
> The thermal sensors use non-standard slope values.

Reviewed-by: Dmitry Baryshkov <dmitry.baryshkov@linaro.org>

Note, the driver from 3.10 also provides custom data for non-calibrated 
mode. We can either ignore that (in the hope that all devices leaving 
the factory are calibrated), or fix it in the manner close to 8x74.

> 
> Signed-off-by: Matti Lehtimäki <matti.lehtimaki@gmail.com>
> ---
>   drivers/thermal/qcom/tsens-v0_1.c | 27 ++++++++++++++++++++++++++-
>   drivers/thermal/qcom/tsens.c      |  3 +++
>   drivers/thermal/qcom/tsens.h      |  2 +-
>   3 files changed, 30 insertions(+), 2 deletions(-)
> 
> diff --git a/drivers/thermal/qcom/tsens-v0_1.c b/drivers/thermal/qcom/tsens-v0_1.c
> index e89c6f39a3ae..ad57ab94546b 100644
> --- a/drivers/thermal/qcom/tsens-v0_1.c
> +++ b/drivers/thermal/qcom/tsens-v0_1.c
> @@ -243,6 +243,18 @@ static int calibrate_8974(struct tsens_priv *priv)
>   	return 0;
>   }
>   
> +static int __init init_8226(struct tsens_priv *priv)
> +{
> +	priv->sensor[0].slope = 2901;
> +	priv->sensor[1].slope = 2846;
> +	priv->sensor[2].slope = 3038;
> +	priv->sensor[3].slope = 2955;
> +	priv->sensor[4].slope = 2901;
> +	priv->sensor[5].slope = 2846;
> +
> +	return init_common(priv);
> +}
> +
>   static int __init init_8939(struct tsens_priv *priv) {
>   	priv->sensor[0].slope = 2911;
>   	priv->sensor[1].slope = 2789;
> @@ -258,7 +270,7 @@ static int __init init_8939(struct tsens_priv *priv) {
>   	return init_common(priv);
>   }
>   
> -/* v0.1: 8916, 8939, 8974, 9607 */
> +/* v0.1: 8226, 8916, 8939, 8974, 9607 */
>   
>   static struct tsens_features tsens_v0_1_feat = {
>   	.ver_major	= VER_0_1,
> @@ -313,6 +325,19 @@ static const struct tsens_ops ops_v0_1 = {
>   	.get_temp	= get_temp_common,
>   };
>   
> +static const struct tsens_ops ops_8226 = {
> +	.init		= init_8226,
> +	.calibrate	= tsens_calibrate_common,
> +	.get_temp	= get_temp_common,
> +};
> +
> +struct tsens_plat_data data_8226 = {
> +	.num_sensors	= 6,
> +	.ops		= &ops_8226,
> +	.feat		= &tsens_v0_1_feat,
> +	.fields	= tsens_v0_1_regfields,
> +};
> +
>   static const struct tsens_ops ops_8916 = {
>   	.init		= init_common,
>   	.calibrate	= calibrate_8916,
> diff --git a/drivers/thermal/qcom/tsens.c b/drivers/thermal/qcom/tsens.c
> index 8020ead2794e..eb33a8bf0488 100644
> --- a/drivers/thermal/qcom/tsens.c
> +++ b/drivers/thermal/qcom/tsens.c
> @@ -1095,6 +1095,9 @@ static const struct of_device_id tsens_table[] = {
>   	}, {
>   		.compatible = "qcom,mdm9607-tsens",
>   		.data = &data_9607,
> +	}, {
> +		.compatible = "qcom,msm8226-tsens",
> +		.data = &data_8226,
>   	}, {
>   		.compatible = "qcom,msm8916-tsens",
>   		.data = &data_8916,
> diff --git a/drivers/thermal/qcom/tsens.h b/drivers/thermal/qcom/tsens.h
> index dba9cd38f637..433eba370998 100644
> --- a/drivers/thermal/qcom/tsens.h
> +++ b/drivers/thermal/qcom/tsens.h
> @@ -635,7 +635,7 @@ int get_temp_common(const struct tsens_sensor *s, int *temp);
>   extern struct tsens_plat_data data_8960;
>   
>   /* TSENS v0.1 targets */
> -extern struct tsens_plat_data data_8916, data_8939, data_8974, data_9607;
> +extern struct tsens_plat_data data_8226, data_8916, data_8939, data_8974, data_9607;
>   
>   /* TSENS v1 targets */
>   extern struct tsens_plat_data data_tsens_v1, data_8976, data_8956;
  
Matti Lehtimäki May 7, 2023, 9:11 p.m. UTC | #3
On 7.5.2023 23.40, Dmitry Baryshkov wrote:
> On 07/05/2023 23:12, Matti Lehtimäki wrote:
>> The MSM8226 TSENS IP has 6 thermal sensors in a TSENS v0.1 block.
>> The thermal sensors use non-standard slope values.
> 
> Reviewed-by: Dmitry Baryshkov <dmitry.baryshkov@linaro.org>
> 
> Note, the driver from 3.10 also provides custom data for non-calibrated mode. We can either ignore that (in the hope that all devices leaving the factory are calibrated), or fix it in the manner close to 8x74.

That is true, 3.10 kernel does support non-calibrated mode. I can add support for that in a new version if that is wanted.
  
Dmitry Baryshkov May 7, 2023, 10:49 p.m. UTC | #4
On Mon, 8 May 2023 at 00:11, Matti Lehtimäki <matti.lehtimaki@gmail.com> wrote:
>
> On 7.5.2023 23.40, Dmitry Baryshkov wrote:
> > On 07/05/2023 23:12, Matti Lehtimäki wrote:
> >> The MSM8226 TSENS IP has 6 thermal sensors in a TSENS v0.1 block.
> >> The thermal sensors use non-standard slope values.
> >
> > Reviewed-by: Dmitry Baryshkov <dmitry.baryshkov@linaro.org>
> >
> > Note, the driver from 3.10 also provides custom data for non-calibrated mode. We can either ignore that (in the hope that all devices leaving the factory are calibrated), or fix it in the manner close to 8x74.
>
> That is true, 3.10 kernel does support non-calibrated mode. I can add support for that in a new version if that is wanted.

If there are no other comments, I'd suggest sending that as a follow
up (if sending it at all). The tsens driver provides some default
values for non-calibrated mode, so it is a minor issue.
  
Daniel Lezcano June 5, 2023, 2:39 p.m. UTC | #5
On 07/05/2023 22:12, Matti Lehtimäki wrote:
> The MSM8226 TSENS IP has 6 thermal sensors in a TSENS v0.1 block.
> The thermal sensors use non-standard slope values.
> 
> Signed-off-by: Matti Lehtimäki <matti.lehtimaki@gmail.com>
> ---

Applied, thanks
  

Patch

diff --git a/drivers/thermal/qcom/tsens-v0_1.c b/drivers/thermal/qcom/tsens-v0_1.c
index e89c6f39a3ae..ad57ab94546b 100644
--- a/drivers/thermal/qcom/tsens-v0_1.c
+++ b/drivers/thermal/qcom/tsens-v0_1.c
@@ -243,6 +243,18 @@  static int calibrate_8974(struct tsens_priv *priv)
 	return 0;
 }
 
+static int __init init_8226(struct tsens_priv *priv)
+{
+	priv->sensor[0].slope = 2901;
+	priv->sensor[1].slope = 2846;
+	priv->sensor[2].slope = 3038;
+	priv->sensor[3].slope = 2955;
+	priv->sensor[4].slope = 2901;
+	priv->sensor[5].slope = 2846;
+
+	return init_common(priv);
+}
+
 static int __init init_8939(struct tsens_priv *priv) {
 	priv->sensor[0].slope = 2911;
 	priv->sensor[1].slope = 2789;
@@ -258,7 +270,7 @@  static int __init init_8939(struct tsens_priv *priv) {
 	return init_common(priv);
 }
 
-/* v0.1: 8916, 8939, 8974, 9607 */
+/* v0.1: 8226, 8916, 8939, 8974, 9607 */
 
 static struct tsens_features tsens_v0_1_feat = {
 	.ver_major	= VER_0_1,
@@ -313,6 +325,19 @@  static const struct tsens_ops ops_v0_1 = {
 	.get_temp	= get_temp_common,
 };
 
+static const struct tsens_ops ops_8226 = {
+	.init		= init_8226,
+	.calibrate	= tsens_calibrate_common,
+	.get_temp	= get_temp_common,
+};
+
+struct tsens_plat_data data_8226 = {
+	.num_sensors	= 6,
+	.ops		= &ops_8226,
+	.feat		= &tsens_v0_1_feat,
+	.fields	= tsens_v0_1_regfields,
+};
+
 static const struct tsens_ops ops_8916 = {
 	.init		= init_common,
 	.calibrate	= calibrate_8916,
diff --git a/drivers/thermal/qcom/tsens.c b/drivers/thermal/qcom/tsens.c
index 8020ead2794e..eb33a8bf0488 100644
--- a/drivers/thermal/qcom/tsens.c
+++ b/drivers/thermal/qcom/tsens.c
@@ -1095,6 +1095,9 @@  static const struct of_device_id tsens_table[] = {
 	}, {
 		.compatible = "qcom,mdm9607-tsens",
 		.data = &data_9607,
+	}, {
+		.compatible = "qcom,msm8226-tsens",
+		.data = &data_8226,
 	}, {
 		.compatible = "qcom,msm8916-tsens",
 		.data = &data_8916,
diff --git a/drivers/thermal/qcom/tsens.h b/drivers/thermal/qcom/tsens.h
index dba9cd38f637..433eba370998 100644
--- a/drivers/thermal/qcom/tsens.h
+++ b/drivers/thermal/qcom/tsens.h
@@ -635,7 +635,7 @@  int get_temp_common(const struct tsens_sensor *s, int *temp);
 extern struct tsens_plat_data data_8960;
 
 /* TSENS v0.1 targets */
-extern struct tsens_plat_data data_8916, data_8939, data_8974, data_9607;
+extern struct tsens_plat_data data_8226, data_8916, data_8939, data_8974, data_9607;
 
 /* TSENS v1 targets */
 extern struct tsens_plat_data data_tsens_v1, data_8976, data_8956;