From patchwork Fri Jan 3 06:44:06 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Michael Kao X-Patchwork-Id: 11316479 Return-Path: Received: from mail.kernel.org (pdx-korg-mail-1.web.codeaurora.org [172.30.200.123]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 7CC5B109A for ; Fri, 3 Jan 2020 06:44:42 +0000 (UTC) Received: from bombadil.infradead.org (bombadil.infradead.org [198.137.202.133]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPS id 5AB6A2084D for ; Fri, 3 Jan 2020 06:44:42 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=lists.infradead.org header.i=@lists.infradead.org header.b="TkdhQNNj"; dkim=fail reason="signature verification failed" (1024-bit key) header.d=mediatek.com header.i=@mediatek.com header.b="a5u2SUAB" DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 5AB6A2084D Authentication-Results: mail.kernel.org; dmarc=fail (p=none dis=none) header.from=mediatek.com Authentication-Results: mail.kernel.org; spf=none smtp.mailfrom=linux-arm-kernel-bounces+patchwork-linux-arm=patchwork.kernel.org@lists.infradead.org DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20170209; h=Sender: Content-Transfer-Encoding:Content-Type:Cc:List-Subscribe:List-Help:List-Post: List-Archive:List-Unsubscribe:List-Id:MIME-Version:References:In-Reply-To: Message-ID:Date:Subject:To:From:Reply-To:Content-ID:Content-Description: Resent-Date:Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID: List-Owner; bh=EncqDd+W6D2JgxwEZMLOswmd6fO1fxUr7Rip0prGd2s=; b=TkdhQNNjLoTIR5 BGdgCvTfcF+SiQCBoOP5qhIdx9rIS+wumb9rTgidpY9yuJz9d7H5M3MOXBpfFPjyDDiczHOi+4S5q T8TvR8A071nZPk15mpnQVDy7z8B9m6EqPPMcnOUm193y82YpqcfHvpwtpUhGtzO5bqKM09r2tjMAz JjWoYyREvncxqJK3mBY7gVa9ypdayjGlDYI+SPM94pmVtTNTw0j6trs9OKly1oin+4anlb2+lwmkR g4Owf1iRKfYcw1qPHtJBINundY/UFBfgbTW+4nVdAdUDzn/6Leb3dxM/lqQrB32yRBh5rGcEZP2NK ifVR8lraOgoJH1nQWtrw==; Received: from localhost ([127.0.0.1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.92.3 #3 (Red Hat Linux)) id 1inGhN-0004wu-Px; Fri, 03 Jan 2020 06:44:41 +0000 Received: from mailgw02.mediatek.com ([216.200.240.185]) by bombadil.infradead.org with esmtps (Exim 4.92.3 #3 (Red Hat Linux)) id 1inGhB-0004lI-EK; Fri, 03 Jan 2020 06:44:31 +0000 X-UUID: a583988803af45e4b947fe748b166e23-20200102 DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=mediatek.com; s=dk; h=Content-Transfer-Encoding:Content-Type:MIME-Version:References:In-Reply-To:Message-ID:Date:Subject:CC:To:From; bh=nZu5Vg6KMNlzJgVAxVNPrImqFUM2QdXibq/TjqkgBuo=; b=a5u2SUABpErw+Z3MiXyeTKhfpmQ8l83pcyM/AAGPQx2foGxH8WoivR52CXmHdN2QidfbvAsxwRgaK1/AmLlEv8XJC07879w1XG43Lz4zzeS0W9zLbSLh1NxFNtoDFaqWPGWE8sys54B4LnQ1lIF9nbbsBbL7A8n0sl1SrWq7HSU=; X-UUID: a583988803af45e4b947fe748b166e23-20200102 Received: from mtkcas66.mediatek.inc [(172.29.193.44)] by mailgw02.mediatek.com (envelope-from ) (musrelay.mediatek.com ESMTP with TLS) with ESMTP id 1050637886; Thu, 02 Jan 2020 22:44:23 -0800 Received: from mtkmbs05n1.mediatek.inc (172.21.101.15) by MTKMBS62N1.mediatek.inc (172.29.193.41) with Microsoft SMTP Server (TLS) id 15.0.1395.4; Thu, 2 Jan 2020 22:44:37 -0800 Received: from mtkcas08.mediatek.inc (172.21.101.126) by mtkmbs05n1.mediatek.inc (172.21.101.15) with Microsoft SMTP Server (TLS) id 15.0.1395.4; Fri, 3 Jan 2020 14:43:44 +0800 Received: from mtksdccf07.mediatek.inc (172.21.84.99) by mtkcas08.mediatek.inc (172.21.101.73) with Microsoft SMTP Server id 15.0.1395.4 via Frontend Transport; Fri, 3 Jan 2020 14:44:09 +0800 From: Michael Kao To: Zhang Rui , Eduardo Valentin , Daniel Lezcano , Rob Herring , Mark Rutland , Matthias Brugger , , , Subject: [PATCH v3, 7/8] thermal: mediatek: add another get_temp ops for thermal sensors Date: Fri, 3 Jan 2020 14:44:06 +0800 Message-ID: <20200103064407.19861-8-michael.kao@mediatek.com> X-Mailer: git-send-email 2.18.0 In-Reply-To: <20200103064407.19861-1-michael.kao@mediatek.com> References: <20200103064407.19861-1-michael.kao@mediatek.com> MIME-Version: 1.0 X-MTK: N X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20200102_224429_492158_25E919C9 X-CRM114-Status: GOOD ( 17.42 ) X-Spam-Score: -0.2 (/) X-Spam-Report: SpamAssassin version 3.4.2 on bombadil.infradead.org summary: Content analysis details: (-0.2 points) pts rule name description ---- ---------------------- -------------------------------------------------- -0.0 SPF_PASS SPF: sender matches SPF record 0.0 SPF_HELO_NONE SPF: HELO does not publish an SPF Record 0.0 MIME_BASE64_TEXT RAW: Message text disguised using base64 encoding -0.1 DKIM_VALID_EF Message has a valid DKIM or DK signature from envelope-from domain -0.1 DKIM_VALID Message has at least one valid DKIM or DK signature -0.1 DKIM_VALID_AU Message has a valid DKIM or DK signature from author's domain 0.1 DKIM_SIGNED Message has a DKIM or DK signature, not necessarily valid 0.0 UNPARSEABLE_RELAY Informational: message has unparseable relay lines X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: devicetree@vger.kernel.org, linux-mediatek@lists.infradead.org, linux-kernel@vger.kernel.org, linux-arm-kernel@lists.infradead.org, Michael Kao Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+patchwork-linux-arm=patchwork.kernel.org@lists.infradead.org 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/ Bypass the failure that non cpu_thermal sensor is not find in thermal-zones in dts, which is normal for mt8173, so prompt a warning here instead of failing. 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 Signed-off-by: Hsin-Yi Wang --- drivers/thermal/mtk_thermal.c | 74 +++++++++++++++++++++++++++++++---- 1 file changed, 66 insertions(+), 8 deletions(-) diff --git a/drivers/thermal/mtk_thermal.c b/drivers/thermal/mtk_thermal.c index d6fabd0a7da6..9be9fcb18d9e 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; @@ -631,16 +637,48 @@ static int mtk_read_temp(void *data, int *temperature) mtk_thermal_put_bank(bank); } - *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; + 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 +911,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 +993,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 (IS_ERR(tzdev) != -EACCES) { + ret = PTR_ERR(tzdev); + goto err_disable_clk_peri_therm; + } + } } return 0;