2021-03-20 11:21:24

by Frank Wunderlich

[permalink] [raw]
Subject: [PATCH] thermal: mediatek: add sensors-support

From: Frank Wunderlich <[email protected]>

add HWMON-support to mediateks thermanl driver to allow lm-sensors
userspace tools read soc temperature

Signed-off-by: Frank Wunderlich <[email protected]>
---
drivers/thermal/mtk_thermal.c | 22 ++++++++++++++++++++++
1 file changed, 22 insertions(+)

diff --git a/drivers/thermal/mtk_thermal.c b/drivers/thermal/mtk_thermal.c
index 149c6d7fd5a0..e22d77d57458 100644
--- a/drivers/thermal/mtk_thermal.c
+++ b/drivers/thermal/mtk_thermal.c
@@ -23,6 +23,8 @@
#include <linux/reset.h>
#include <linux/types.h>

+#include "thermal_hwmon.h"
+
/* AUXADC Registers */
#define AUXADC_CON1_SET_V 0x008
#define AUXADC_CON1_CLR_V 0x00c
@@ -983,6 +985,13 @@ static void mtk_thermal_release_periodic_ts(struct mtk_thermal *mt,
writel((tmp & (~0x10e)), mt->thermal_base + TEMP_MSRCTL1);
}

+static void mtk_thermal_hwmon_action(void *data)
+{
+ struct thermal_zone_device *zone = data;
+
+ thermal_remove_hwmon_sysfs(zone);
+}
+
static int mtk_thermal_probe(struct platform_device *pdev)
{
int ret, i, ctrl_id;
@@ -1087,6 +1096,19 @@ static int mtk_thermal_probe(struct platform_device *pdev)
goto err_disable_clk_peri_therm;
}

+#ifdef CONFIG_THERMAL_HWMON
+ tzdev->tzp->no_hwmon = false;
+ ret = thermal_add_hwmon_sysfs(tzdev);
+ if (ret)
+ dev_err(&pdev->dev, "error in thermal_add_hwmon_sysfs");
+
+ ret = devm_add_action(&pdev->dev, mtk_thermal_hwmon_action, tzdev);
+ if (ret) {
+ dev_err(&pdev->dev, "error in devm_add_action");
+ mtk_thermal_hwmon_action(tzdev);
+ }
+#endif
+
return 0;

err_disable_clk_peri_therm:
--
2.25.1


2021-04-18 12:08:38

by Frank Wunderlich

[permalink] [raw]
Subject: Aw: [PATCH] thermal: mediatek: add sensors-support

Hi,

any opinion (except typo)?

thermanl => thermal

regards Frank


> Gesendet: Samstag, 20. März 2021 um 10:06 Uhr
> Von: "Frank Wunderlich" <[email protected]>
> add HWMON-support to mediateks thermanl driver to allow lm-sensors
> userspace tools read soc temperature

2021-04-20 12:08:45

by Daniel Lezcano

[permalink] [raw]
Subject: Re: [PATCH] thermal: mediatek: add sensors-support

On 20/03/2021 09:06, Frank Wunderlich wrote:
> From: Frank Wunderlich <[email protected]>
>
> add HWMON-support to mediateks thermanl driver to allow lm-sensors
> userspace tools read soc temperature
>
> Signed-off-by: Frank Wunderlich <[email protected]>
> ---
> drivers/thermal/mtk_thermal.c | 22 ++++++++++++++++++++++
> 1 file changed, 22 insertions(+)
>
> diff --git a/drivers/thermal/mtk_thermal.c b/drivers/thermal/mtk_thermal.c
> index 149c6d7fd5a0..e22d77d57458 100644
> --- a/drivers/thermal/mtk_thermal.c
> +++ b/drivers/thermal/mtk_thermal.c
> @@ -23,6 +23,8 @@
> #include <linux/reset.h>
> #include <linux/types.h>
>
> +#include "thermal_hwmon.h"
> +
> /* AUXADC Registers */
> #define AUXADC_CON1_SET_V 0x008
> #define AUXADC_CON1_CLR_V 0x00c
> @@ -983,6 +985,13 @@ static void mtk_thermal_release_periodic_ts(struct mtk_thermal *mt,
> writel((tmp & (~0x10e)), mt->thermal_base + TEMP_MSRCTL1);
> }
>
> +static void mtk_thermal_hwmon_action(void *data)
> +{
> + struct thermal_zone_device *zone = data;
> +
> + thermal_remove_hwmon_sysfs(zone);
> +}
> +
> static int mtk_thermal_probe(struct platform_device *pdev)
> {
> int ret, i, ctrl_id;
> @@ -1087,6 +1096,19 @@ static int mtk_thermal_probe(struct platform_device *pdev)
> goto err_disable_clk_peri_therm;
> }
>
> +#ifdef CONFIG_THERMAL_HWMON

No #ifdef in C file.

> + tzdev->tzp->no_hwmon = false;
> + ret = thermal_add_hwmon_sysfs(tzdev);
> + if (ret)
> + dev_err(&pdev->dev, "error in thermal_add_hwmon_sysfs");
> +
> + ret = devm_add_action(&pdev->dev, mtk_thermal_hwmon_action, tzdev);

devm_thermal_add_hwmon_sysfs() ?

> + if (ret) {
> + dev_err(&pdev->dev, "error in devm_add_action");
> + mtk_thermal_hwmon_action(tzdev);
> + }
> +#endif
> +
> return 0;
>
> err_disable_clk_peri_therm:
>


--
<http://www.linaro.org/> Linaro.org │ Open source software for ARM SoCs

Follow Linaro: <http://www.facebook.com/pages/Linaro> Facebook |
<http://twitter.com/#!/linaroorg> Twitter |
<http://www.linaro.org/linaro-blog/> Blog

2021-04-20 15:01:43

by Frank Wunderlich

[permalink] [raw]
Subject: Aw: Re: [PATCH] thermal: mediatek: add sensors-support

Hi,

> Gesendet: Dienstag, 20. April 2021 um 14:07 Uhr
> Von: "Daniel Lezcano" <[email protected]>

> No #ifdef in C file.
...

> devm_thermal_add_hwmon_sysfs() ?

based on your comments this should be enough/right?

#if IS_ENABLED(CONFIG_THERMAL_HWMON)
tzdev->tzp->no_hwmon = false;
ret = devm_thermal_add_hwmon_sysfs(tzdev);
if (ret)
dev_err(&pdev->dev, "error in thermal_add_hwmon_sysfs");
#endif

if yes i send out v2, at least it works on my device

regards Frank


2021-04-20 15:20:14

by Daniel Lezcano

[permalink] [raw]
Subject: Re: Aw: Re: [PATCH] thermal: mediatek: add sensors-support


Hi Frank,

On 20/04/2021 16:59, Frank Wunderlich wrote:
> Hi,
>
>> Gesendet: Dienstag, 20. April 2021 um 14:07 Uhr
>> Von: "Daniel Lezcano" <[email protected]>
>
>> No #ifdef in C file.
> ...
>
>> devm_thermal_add_hwmon_sysfs() ?
>
> based on your comments this should be enough/right?
>
> #if IS_ENABLED(CONFIG_THERMAL_HWMON)
> tzdev->tzp->no_hwmon = false;> ret = devm_thermal_add_hwmon_sysfs(tzdev);
> if (ret)
> dev_err(&pdev->dev, "error in thermal_add_hwmon_sysfs");
> #endif
>
> if yes i send out v2, at least it works on my device

just the following lines should work:

ret = devm_thermal_add_hwmon_sysfs(tzdev);
if (ret)
dev_err(&pdev->dev, "error in thermal_add_hwmon_sysfs");


The no_hwmon usage is a bit fuzzy in the thermal core code.


--
<http://www.linaro.org/> Linaro.org │ Open source software for ARM SoCs

Follow Linaro: <http://www.facebook.com/pages/Linaro> Facebook |
<http://twitter.com/#!/linaroorg> Twitter |
<http://www.linaro.org/linaro-blog/> Blog

2021-04-20 15:26:22

by Frank Wunderlich

[permalink] [raw]
Subject: Re: Aw: Re: [PATCH] thermal: mediatek: add sensors-support

Am 20. April 2021 17:18:32 MESZ schrieb Daniel Lezcano <[email protected]>:
>
>Hi Frank,

>The no_hwmon usage is a bit fuzzy in the thermal core code.

Maybe add depency in Kconfig? Else we can get undefined symbols on linking

regards Frank

2021-04-20 15:28:19

by Daniel Lezcano

[permalink] [raw]
Subject: Re: Aw: Re: [PATCH] thermal: mediatek: add sensors-support

On 20/04/2021 17:24, Frank Wunderlich wrote:
> Am 20. April 2021 17:18:32 MESZ schrieb Daniel Lezcano <[email protected]>:
>>
>> Hi Frank,
>
>> The no_hwmon usage is a bit fuzzy in the thermal core code.
>
> Maybe add depency in Kconfig? Else we can get undefined symbols on linking
>
> regards Frank

Nope, there are the stubs in thermal_hwmon.h



--
<http://www.linaro.org/> Linaro.org │ Open source software for ARM SoCs

Follow Linaro: <http://www.facebook.com/pages/Linaro> Facebook |
<http://twitter.com/#!/linaroorg> Twitter |
<http://www.linaro.org/linaro-blog/> Blog