From: Nicolas Boichat <drinkcat@chromium.org>
To: "michael.kao" <michael.kao@mediatek.com>
Cc: Fan Chen <fan.chen@mediatek.com>,
James Liao <jamesjj.liao@mediatek.com>,
dawei.chien@mediatek.com, louis.yu@mediatek.com,
roger.lu@mediatek.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>,
Matthias Brugger <matthias.bgg@gmail.com>,
devicetree@vger.kernel.org,
"moderated list:ARM/Mediatek SoC support"
<linux-mediatek@lists.infradead.org>,
lkml <linux-kernel@vger.kernel.org>,
linux-arm Mailing List <linux-arm-kernel@lists.infradead.org>,
linux-pm@vger.kernel.org, Hsin-Yi Wang <hsinyi@chromium.org>
Subject: Re: [PATCH 7/8] thermal: mediatek: add another get_temp ops for thermal sensors
Date: Sat, 11 May 2019 11:31:08 +0900 [thread overview]
Message-ID: <CANMq1KBna0V2X3_CNQrcH==WVLs7oY=GvFGzEbWS91-oZCLKTQ@mail.gmail.com> (raw)
In-Reply-To: <1556793795-25204-8-git-send-email-michael.kao@mediatek.com>
On Thu, May 2, 2019 at 7:45 PM michael.kao <michael.kao@mediatek.com> wrote:
>
> From: Michael Kao <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/
>
> Signed-off-by: Michael Kao <michael.kao@mediatek.com>
> ---
> drivers/thermal/mtk_thermal.c | 68 ++++++++++++++++++++++++++++++++++++++-----
> 1 file changed, 60 insertions(+), 8 deletions(-)
>
> diff --git a/drivers/thermal/mtk_thermal.c b/drivers/thermal/mtk_thermal.c
> index cb41e46..d5c78b0 100644
> --- a/drivers/thermal/mtk_thermal.c
> +++ b/drivers/thermal/mtk_thermal.c
> @@ -230,6 +230,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;
> @@ -612,7 +617,7 @@ static int mtk_thermal_bank_temperature(struct mtk_thermal_bank *bank)
> * not immediately shut down.
> */
> if (temp > 200000)
> - temp = 0;
> + temp = -EACCES;
EACCES/permission denied doesn't really seem to be the right error
code here. Maybe EAGAIN?
>
> if (temp > max)
> max = temp;
> @@ -623,7 +628,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;
>
> @@ -636,16 +642,48 @@ static int mtk_read_temp(void *data, int *temperature)
>
> mtk_thermal_put_bank(bank);
> }
> -
I'd drop that change.
> *temperature = tempmax;
>
> 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;
No need to initialize temp.
> + u32 raw;
> +
> + if (id < 0)
> + return -EACCES;
EINVAL?
> +
> + 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.
> + */
> +
nit: Drop this blank line
> + if (temp > 200000)
> + return -EACCES;
Again, EAGAIN, maybe?
> +
> + *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)
> @@ -878,6 +916,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)
> @@ -959,11 +998,24 @@ 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);
Are we leaking this pointer? Should this be devm_kmalloc?
> + 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 (IS_ERR(tzdev) != -EACCES) {
Why would EACCES ever happen? AFAICT
devm_thermal_zone_of_sensor_register does not actually try to read the
temperature value? Or does the error come from somewhere else?
> + ret = PTR_ERR(tzdev);
> + goto err_disable_clk_peri_therm;
> + }
> + }
> }
>
> return 0;
> --
> 1.9.1
>
>
> _______________________________________________
> Linux-mediatek mailing list
> Linux-mediatek@lists.infradead.org
> http://lists.infradead.org/mailman/listinfo/linux-mediatek
next prev parent reply other threads:[~2019-05-11 2:31 UTC|newest]
Thread overview: 24+ messages / expand[flat|nested] mbox.gz Atom feed top
2019-05-02 10:43 [PATCH 0/8] Add Mediatek thermal dirver and dtsi michael.kao
2019-05-02 10:43 ` [PATCH 2/8] arm64: dts: mt8183: add/update dynamic power coefficients michael.kao
2019-05-03 7:16 ` Hsin-Yi Wang
2019-05-08 12:27 ` Michael Kao
2019-05-02 10:43 ` [PATCH 3/8] arm64: dts: mt8183: Add #cooling-cells to CPU nodes michael.kao
2019-05-06 5:25 ` Eddie Huang
2019-05-08 12:29 ` Michael Kao
2019-05-02 10:43 ` [PATCH 4/8] arm64: dts: mt8183: Configure CPU cooling michael.kao
2019-05-07 8:57 ` Hsin-Yi Wang
2019-05-02 10:43 ` [PATCH 5/8] arm64: dts: mt8183: Increase polling frequency for CPU thermal zone michael.kao
2019-05-07 8:58 ` Hsin-Yi Wang
[not found] ` <1556793795-25204-1-git-send-email-michael.kao-NuS5LvNUpcJWk0Htik3J/w@public.gmane.org>
2019-05-02 10:43 ` [PATCH 1/8] arm64: dts: mt8183: add thermal zone node michael.kao
2019-05-03 8:03 ` Hsin-Yi Wang
2019-05-03 16:46 ` Matthias Kaehlcke
2019-05-06 10:43 ` Daniel Lezcano
2019-05-08 12:23 ` Michael Kao
2019-05-10 8:14 ` Daniel Lezcano
2019-05-10 10:52 ` Michael Kao
2019-05-06 9:43 ` Daniel Lezcano
2019-05-02 10:43 ` [PATCH 6/8] thermal: mediatek: mt8183: fix bank number settings michael.kao
2019-05-07 8:58 ` Hsin-Yi Wang
2019-05-02 10:43 ` [PATCH 7/8] thermal: mediatek: add another get_temp ops for thermal sensors michael.kao
2019-05-11 2:31 ` Nicolas Boichat [this message]
2019-05-02 10:43 ` [PATCH 8/8] thermal: mediatek: use spinlock to protect PTPCORESEL 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='CANMq1KBna0V2X3_CNQrcH==WVLs7oY=GvFGzEbWS91-oZCLKTQ@mail.gmail.com' \
--to=drinkcat@chromium.org \
--cc=daniel.lezcano@linaro.org \
--cc=dawei.chien@mediatek.com \
--cc=devicetree@vger.kernel.org \
--cc=edubezval@gmail.com \
--cc=fan.chen@mediatek.com \
--cc=hsinyi@chromium.org \
--cc=jamesjj.liao@mediatek.com \
--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=louis.yu@mediatek.com \
--cc=mark.rutland@arm.com \
--cc=matthias.bgg@gmail.com \
--cc=michael.kao@mediatek.com \
--cc=robh+dt@kernel.org \
--cc=roger.lu@mediatek.com \
--cc=rui.zhang@intel.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;
as well as URLs for NNTP newsgroup(s).