From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-8.3 required=3.0 tests=DKIM_SIGNED,DKIM_VALID, DKIM_VALID_AU,HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_PATCH,MAILING_LIST_MULTI, SIGNED_OFF_BY,SPF_HELO_NONE,SPF_PASS,URIBL_BLOCKED,USER_AGENT_SANE_1 autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 54221C433E0 for ; Fri, 22 May 2020 15:32:09 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 1E03620663 for ; Fri, 22 May 2020 15:32:09 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=linaro.org header.i=@linaro.org header.b="YjORt36O" Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1730471AbgEVPcI (ORCPT ); Fri, 22 May 2020 11:32:08 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:35328 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1730393AbgEVPcI (ORCPT ); Fri, 22 May 2020 11:32:08 -0400 Received: from mail-wm1-x343.google.com (mail-wm1-x343.google.com [IPv6:2a00:1450:4864:20::343]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id CEF29C061A0E for ; Fri, 22 May 2020 08:32:07 -0700 (PDT) Received: by mail-wm1-x343.google.com with SMTP id f13so9013657wmc.5 for ; Fri, 22 May 2020 08:32:07 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; h=subject:to:cc:references:from:message-id:date:user-agent :mime-version:in-reply-to:content-language:content-transfer-encoding; bh=otTjOhB3pQfb5rvNf3iE/1EF+uvqWUVNS9VHLDzOq6I=; b=YjORt36Ol5Z1zqcZJ9PdVDQlWbU2xMv+HuUp2H6cXcxLt9hXl7O4guMpdaJSCxMlk/ F0ZgAw2FvlH34VcN4fni2/NgLuZkYmwMItA0MjVGnZ5p9uL6jvhBff0Q4CTl85Yw1pw3 rvDo4oOuVmI951FS3NPpy9tLJaA5xxllVZY0spCqdqsRGD2+abdJquNCoJXQpWfgPgGu ZCn9yjxdzIlUYRfFPLW4aL2snRBCG82tP7948zBCVceR9ovXv0brb7+4rimzBnUS+lwv j8ylwDgWE60TyNowyMK8CQRJ2u9gxTZKcsVP1PX2qZIf9VY10WFDjw1Xh8dRTP1Yiq0I zC8g== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:subject:to:cc:references:from:message-id:date :user-agent:mime-version:in-reply-to:content-language :content-transfer-encoding; bh=otTjOhB3pQfb5rvNf3iE/1EF+uvqWUVNS9VHLDzOq6I=; b=V20RRYsZmuA2iPH0ZkgQd0RSiimSQ+gYGrSt6PbLJIe6UF+lZR+Vy+HV+GYXUc2HhP onl1yZf6AjyZ9MbyRqWfAHrW/4uHjl7sCm/Cf2sYYPeTOIQuNfCotwnMQGWsVsJnZFGR UC006r3MNkqGzCWy545oZw+sig9YfEIA1FpIs55bVuUhQFBylG9OJaPYX16qfw0U5jPk cAEPOa6SUzEL5ISVHhwiARkb8qLI1lsJ0OETCqMW7qOWMKGAKoCANl9NKDxltCx9kNa5 K9tue0NMn40LX4zi+wRgMNBFKEIZcGpOBjCB7/t5YQ7biUgznvQmbNdB8xwRzlUzVn7l xYGg== X-Gm-Message-State: AOAM53147em+u5jypuwbc9SrIMVeP4+pb1jFft8dDki9ql6uCMfWVUkT TQsTnE9v/mwyD3nYXcnSbYZKiw== X-Google-Smtp-Source: ABdhPJxZhfb8FvGiHXbP4WIrzNxdJ9R0OJbYjAm99WLd9VjIJX2ehUsAjztVxh8MlTgphwpbBpEHEA== X-Received: by 2002:a1c:1983:: with SMTP id 125mr13524236wmz.43.1590161526337; Fri, 22 May 2020 08:32:06 -0700 (PDT) Received: from ?IPv6:2a01:e34:ed2f:f020:a82f:eaec:3c49:875a? ([2a01:e34:ed2f:f020:a82f:eaec:3c49:875a]) by smtp.googlemail.com with ESMTPSA id x17sm9694035wrp.71.2020.05.22.08.32.04 (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Fri, 22 May 2020 08:32:05 -0700 (PDT) Subject: Re: [v4,6/7] thermal: mediatek: add another get_temp ops for thermal sensors To: Michael Kao , Matthias Brugger , Zhang Rui , Eduardo Valentin , Rob Herring , Mark Rutland , hsinyi@chromium.org, linux-pm@vger.kernel.org, srv_heupstream@mediatek.com Cc: devicetree@vger.kernel.org, linux-kernel@vger.kernel.org, linux-arm-kernel@lists.infradead.org, linux-mediatek@lists.infradead.org References: <20200323121537.22697-1-michael.kao@mediatek.com> <20200323121537.22697-7-michael.kao@mediatek.com> From: Daniel Lezcano Message-ID: Date: Fri, 22 May 2020 17:32:04 +0200 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:68.0) Gecko/20100101 Thunderbird/68.7.0 MIME-Version: 1.0 In-Reply-To: <20200323121537.22697-7-michael.kao@mediatek.com> Content-Type: text/plain; charset=utf-8 Content-Language: en-US Content-Transfer-Encoding: 8bit Sender: devicetree-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: devicetree@vger.kernel.org On 23/03/2020 13:15, Michael Kao wrote: > 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) What the source problem of the sensor returning bogus values? > Signed-off-by: Michael Kao > Signed-off-by: Hsin-Yi Wang > --- > 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; > -- Linaro.org │ Open source software for ARM SoCs Follow Linaro: Facebook | Twitter | Blog