From patchwork Mon Nov 5 16:51:34 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Lucas Stach X-Patchwork-Id: 10668637 X-Patchwork-Delegate: eduardo.valentin@ti.com Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 443161751 for ; Mon, 5 Nov 2018 16:51:41 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 342B129C28 for ; Mon, 5 Nov 2018 16:51:41 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 287FC29C4D; Mon, 5 Nov 2018 16:51:41 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-7.9 required=2.0 tests=BAYES_00,MAILING_LIST_MULTI, RCVD_IN_DNSWL_HI autolearn=ham version=3.3.1 Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 8714629C28 for ; Mon, 5 Nov 2018 16:51:40 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1729720AbeKFCMM (ORCPT ); Mon, 5 Nov 2018 21:12:12 -0500 Received: from metis.ext.pengutronix.de ([85.220.165.71]:59327 "EHLO metis.ext.pengutronix.de" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1729545AbeKFCMM (ORCPT ); Mon, 5 Nov 2018 21:12:12 -0500 Received: from dude.hi.pengutronix.de ([2001:67c:670:100:1d::7] helo=dude.pengutronix.de.) by metis.ext.pengutronix.de with esmtp (Exim 4.89) (envelope-from ) id 1gJi6D-0005Ss-CO; Mon, 05 Nov 2018 17:51:37 +0100 From: Lucas Stach To: Zhang Rui , Eduardo Valentin Cc: Daniel Lezcano , linux-pm@vger.kernel.org, patchwork-lst@pengutronix.de, kernel@pengutronix.de Subject: [PATCH] thermal: imx: register as OF sensor Date: Mon, 5 Nov 2018 17:51:34 +0100 Message-Id: <20181105165134.28963-1-l.stach@pengutronix.de> X-Mailer: git-send-email 2.19.1 MIME-Version: 1.0 X-SA-Exim-Connect-IP: 2001:67c:670:100:1d::7 X-SA-Exim-Mail-From: l.stach@pengutronix.de X-SA-Exim-Scanned: No (on metis.ext.pengutronix.de); SAEximRunCond expanded to false X-PTX-Original-Recipient: linux-pm@vger.kernel.org Sender: linux-pm-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-pm@vger.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP To make the internal sensor usable with a thermal zone description provided via DT, also register our device as a OF sensor. Signed-off-by: Lucas Stach --- drivers/thermal/imx_thermal.c | 17 ++++++++++++++++- 1 file changed, 16 insertions(+), 1 deletion(-) diff --git a/drivers/thermal/imx_thermal.c b/drivers/thermal/imx_thermal.c index aa452acb60b6..32f406099479 100644 --- a/drivers/thermal/imx_thermal.c +++ b/drivers/thermal/imx_thermal.c @@ -202,7 +202,7 @@ static struct thermal_soc_data thermal_imx7d_data = { struct imx_thermal_data { struct cpufreq_policy *policy; - struct thermal_zone_device *tz; + struct thermal_zone_device *tz, *sensor; struct thermal_cooling_device *cdev; enum thermal_device_mode mode; struct regmap *tempmon; @@ -338,6 +338,13 @@ static int imx_get_temp(struct thermal_zone_device *tz, int *temp) return 0; } +static int imx_of_sensor_get_temp(void *data, int *temp) +{ + struct imx_thermal_data *thermal_data = data; + + return imx_get_temp(thermal_data->tz, temp); +} + static int imx_get_mode(struct thermal_zone_device *tz, enum thermal_device_mode *mode) { @@ -482,6 +489,10 @@ static struct thermal_zone_device_ops imx_tz_ops = { .set_trip_temp = imx_set_trip_temp, }; +static const struct thermal_zone_of_device_ops imx_tz_of_ops = { + .get_temp = imx_of_sensor_get_temp, +}; + static int imx_init_calib(struct platform_device *pdev, u32 ocotp_ana1) { struct imx_thermal_data *data = platform_get_drvdata(pdev); @@ -798,6 +809,9 @@ static int imx_thermal_probe(struct platform_device *pdev) return ret; } + data->sensor = thermal_zone_of_sensor_register(&pdev->dev, 0, data, + &imx_tz_of_ops); + dev_info(&pdev->dev, "%s CPU temperature grade - max:%dC" " critical:%dC passive:%dC\n", data->temp_grade, data->temp_max / 1000, data->temp_critical / 1000, @@ -848,6 +862,7 @@ static int imx_thermal_remove(struct platform_device *pdev) if (!IS_ERR(data->thermal_clk)) clk_disable_unprepare(data->thermal_clk); + thermal_zone_of_sensor_unregister(&pdev->dev, data->sensor); thermal_zone_device_unregister(data->tz); cpufreq_cooling_unregister(data->cdev); cpufreq_cpu_put(data->policy);