From: Michael Kao <michael.kao@mediatek.com>
To: Matthias Brugger <matthias.bgg@gmail.com>,
Zhang Rui <rui.zhang@intel.com>,
Eduardo Valentin <edubezval@gmail.com>,
Daniel Lezcano <daniel.lezcano@linaro.org>,
Rob Herring <robh+dt@kernel.org>,
Mark Rutland <mark.rutland@arm.com>, <hsinyi@chromium.org>,
<linux-pm@vger.kernel.org>, <srv_heupstream@mediatek.com>,
<michael.kao@mediatek.com>
Cc: <devicetree@vger.kernel.org>, <linux-kernel@vger.kernel.org>,
<linux-arm-kernel@lists.infradead.org>,
<linux-mediatek@lists.infradead.org>
Subject: [v4,6/7] thermal: mediatek: add another get_temp ops for thermal sensors
Date: Mon, 23 Mar 2020 20:15:36 +0800 [thread overview]
Message-ID: <20200323121537.22697-7-michael.kao@mediatek.com> (raw)
In-Reply-To: <20200323121537.22697-1-michael.kao@mediatek.com>
Provide thermal zone to read thermal sensor
in the SoC. We can read all the thermal sensors
value in the SoC by the node /sys/class/thermal/
In mtk_thermal_bank_temperature, return -EAGAIN instead of -EACCESS
on the first read of sensor that often are bogus values.
This can avoid following warning on boot:
thermal thermal_zone6: failed to read out thermal zone (-13)
Signed-off-by: Michael Kao <michael.kao@mediatek.com>
Signed-off-by: Hsin-Yi Wang <hsinyi@chromium.org>
---
drivers/thermal/mtk_thermal.c | 74 +++++++++++++++++++++++++++++++----
1 file changed, 67 insertions(+), 7 deletions(-)
diff --git a/drivers/thermal/mtk_thermal.c b/drivers/thermal/mtk_thermal.c
index 6b7ef1993d7e..9eaca432920e 100644
--- a/drivers/thermal/mtk_thermal.c
+++ b/drivers/thermal/mtk_thermal.c
@@ -225,6 +225,11 @@ enum {
struct mtk_thermal;
+struct mtk_thermal_zone {
+ struct mtk_thermal *mt;
+ int id;
+};
+
struct thermal_bank_cfg {
unsigned int num_sensors;
const int *sensors;
@@ -607,7 +612,7 @@ static int mtk_thermal_bank_temperature(struct mtk_thermal_bank *bank)
* not immediately shut down.
*/
if (temp > 200000)
- temp = 0;
+ temp = -EAGAIN;
if (temp > max)
max = temp;
@@ -618,7 +623,8 @@ static int mtk_thermal_bank_temperature(struct mtk_thermal_bank *bank)
static int mtk_read_temp(void *data, int *temperature)
{
- struct mtk_thermal *mt = data;
+ struct mtk_thermal_zone *tz = data;
+ struct mtk_thermal *mt = tz->mt;
int i;
int tempmax = INT_MIN;
@@ -637,10 +643,44 @@ static int mtk_read_temp(void *data, int *temperature)
return 0;
}
+static int mtk_read_sensor_temp(void *data, int *temperature)
+{
+ struct mtk_thermal_zone *tz = data;
+ struct mtk_thermal *mt = tz->mt;
+ const struct mtk_thermal_data *conf = mt->conf;
+ int id = tz->id - 1;
+ int temp = INT_MIN;
+ u32 raw;
+
+ if (id < 0)
+ return -EACCES;
+
+ raw = readl(mt->thermal_base + conf->msr[id]);
+
+ temp = raw_to_mcelsius(mt, id, raw);
+
+ /*
+ * The first read of a sensor often contains very high bogus
+ * temperature value. Filter these out so that the system does
+ * not immediately shut down.
+ */
+
+ if (temp > 200000)
+ return -EAGAIN;
+
+ *temperature = temp;
+
+ return 0;
+}
+
static const struct thermal_zone_of_device_ops mtk_thermal_ops = {
.get_temp = mtk_read_temp,
};
+static const struct thermal_zone_of_device_ops mtk_thermal_sensor_ops = {
+ .get_temp = mtk_read_sensor_temp,
+};
+
static void mtk_thermal_init_bank(struct mtk_thermal *mt, int num,
u32 apmixed_phys_base, u32 auxadc_phys_base,
int ctrl_id)
@@ -873,6 +913,7 @@ static int mtk_thermal_probe(struct platform_device *pdev)
struct resource *res;
u64 auxadc_phys_base, apmixed_phys_base;
struct thermal_zone_device *tzdev;
+ struct mtk_thermal_zone *tz;
mt = devm_kzalloc(&pdev->dev, sizeof(*mt), GFP_KERNEL);
if (!mt)
@@ -954,11 +995,30 @@ static int mtk_thermal_probe(struct platform_device *pdev)
platform_set_drvdata(pdev, mt);
- tzdev = devm_thermal_zone_of_sensor_register(&pdev->dev, 0, mt,
- &mtk_thermal_ops);
- if (IS_ERR(tzdev)) {
- ret = PTR_ERR(tzdev);
- goto err_disable_clk_peri_therm;
+ for (i = 0; i < mt->conf->num_sensors + 1; i++) {
+ tz = kmalloc(sizeof(*tz), GFP_KERNEL);
+ if (!tz)
+ return -ENOMEM;
+
+ tz->mt = mt;
+ tz->id = i;
+
+ tzdev = devm_thermal_zone_of_sensor_register(&pdev->dev, i,
+ tz, (i == 0) ?
+ &mtk_thermal_ops : &mtk_thermal_sensor_ops);
+
+ if (IS_ERR(tzdev)) {
+ if (PTR_ERR(tzdev) == -ENODEV) {
+ dev_warn(&pdev->dev,
+ "sensor %d not registered in thermal zone in dt\n",
+ i);
+ continue;
+ }
+ if (PTR_ERR(tzdev) == -EACCES) {
+ ret = PTR_ERR(tzdev);
+ goto err_disable_clk_peri_therm;
+ }
+ }
}
return 0;
--
2.18.0
next prev parent reply other threads:[~2020-03-23 12:15 UTC|newest]
Thread overview: 16+ messages / expand[flat|nested] mbox.gz Atom feed top
[not found] <20200323121537.22697-1-michael.kao@mediatek.com>
2020-03-23 12:15 ` [v4,2/7] arm64: dts: mt8183: add dynamic power coefficients Michael Kao
2020-03-23 12:15 ` [v4,3/7] arm64: dts: mt8183: Add #cooling-cells to CPU nodes Michael Kao
2020-03-23 12:15 ` [v4,4/7] arm64: dts: mt8183: Configure CPU cooling Michael Kao
2020-03-23 12:15 ` [v4,5/7] thermal: mediatek: mt8183: fix bank number settings Michael Kao
2020-05-22 15:33 ` Daniel Lezcano
2020-03-23 12:15 ` Michael Kao [this message]
2020-05-22 15:32 ` [v4,6/7] thermal: mediatek: add another get_temp ops for thermal sensors Daniel Lezcano
2020-07-07 3:07 ` [v4, 6/7] " Michael Kao
2020-05-21 12:51 ` [v4,0/7] Add Mediatek thermal dirver and dtsi Matthias Brugger
2020-05-22 4:07 ` Michael Kao
2020-05-22 4:09 ` Michael Kao
[not found] ` <20200323121537.22697-8-michael.kao@mediatek.com>
[not found] ` <1589439322.11120.2.camel@mtksdccf07>
2020-05-14 8:08 ` [v4,7/7] thermal: mediatek: use spinlock to protect PTPCORESEL Daniel Lezcano
2020-05-22 15:36 ` Daniel Lezcano
[not found] ` <1591329023.12739.0.camel@mtksdccf07>
[not found] ` <1594090621.20216.0.camel@mtksdccf07>
2020-07-07 8:11 ` Daniel Lezcano
2020-07-07 8:13 ` Daniel Lezcano
2020-07-08 10:00 ` Michael Kao
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20200323121537.22697-7-michael.kao@mediatek.com \
--to=michael.kao@mediatek.com \
--cc=daniel.lezcano@linaro.org \
--cc=devicetree@vger.kernel.org \
--cc=edubezval@gmail.com \
--cc=hsinyi@chromium.org \
--cc=linux-arm-kernel@lists.infradead.org \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-mediatek@lists.infradead.org \
--cc=linux-pm@vger.kernel.org \
--cc=mark.rutland@arm.com \
--cc=matthias.bgg@gmail.com \
--cc=robh+dt@kernel.org \
--cc=rui.zhang@intel.com \
--cc=srv_heupstream@mediatek.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox