Received: by 2002:a25:1506:0:0:0:0:0 with SMTP id 6csp408046ybv; Thu, 20 Feb 2020 00:24:04 -0800 (PST) X-Google-Smtp-Source: APXvYqy93SseaCxlZg4CkHNkW0nWng07fONncfg+Nk7bIT4uUDCTDMWBaAaGsPDPwJhzciHcsJwV X-Received: by 2002:a05:6808:1:: with SMTP id u1mr1214230oic.74.1582187044568; Thu, 20 Feb 2020 00:24:04 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1582187044; cv=none; d=google.com; s=arc-20160816; b=NVsAwx4uBVkvskECCMk/wfxcr++wuwVKOzRe5bbhPjCpeNr0aDvZ6GzG0XKW/5A9pv S1SOf23rkIuBwsscCzrl9AC18UUSthzRKRFOi+dahtBmDDU7YfjhcCCa0o/q1Jfub97b i6ogmbDRxsVGxk0aSKGfCToN8PQ8yekRl3WIpRvDDcuaKmGLuNM/CTJg//f9A4yfAggv /f66wtkl7BSpBhxKMuIr9lZ+YE97P4eTxIocYLaRFlV89sG+VutB0C9bsDF6GFtKhRUB 6tG0WdpzEtlQJz33o6kNsCmooP+A2qOazANOGw327P3IVTpYqN6vDLDeLlary4cLHAE3 V3jQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:references:in-reply-to:message-id:date :subject:cc:to:from; bh=bj1L1uZ9sM8xqcZqNHeIHYiwdkNlSDwxQOZzkgiZkHw=; b=Q7vN6J6Ct7tn2goDobl2ekdkYiWkgGY3GI4w2+JDAry8boet/GKBxs4rLf/sbmBoZq bnnjNHiCwvu8LnziZuw++n9BHvoCRXBkvg1Gn0OtEkIVH0GbqTcXJTq8itVGd6HOxAkC VpJ1NTEhlV1KLmHHXnQUVuJh1Fx44XbtTgWzaDHKwuvPvFWJkcSZnw46a/V4Tds4CxG5 uDuxBn8tO/BRByOj/FXGi1clORN1Dp/JCgBhn0EcqGNoRGExrFLD0SXdmmLDVCKOYE+x 8qjUA7pyXSc2X9np2wUI7wXKU+AJftEQVtymqZam1hzOjwAZhZ4QonE2JXGVdXmCpWZR ohEQ== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=nxp.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id s17si1359162otd.76.2020.02.20.00.23.52; Thu, 20 Feb 2020 00:24:04 -0800 (PST) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=nxp.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726959AbgBTIXn (ORCPT + 99 others); Thu, 20 Feb 2020 03:23:43 -0500 Received: from inva020.nxp.com ([92.121.34.13]:51632 "EHLO inva020.nxp.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726637AbgBTIXm (ORCPT ); Thu, 20 Feb 2020 03:23:42 -0500 Received: from inva020.nxp.com (localhost [127.0.0.1]) by inva020.eu-rdc02.nxp.com (Postfix) with ESMTP id C35741A54EB; Thu, 20 Feb 2020 09:23:39 +0100 (CET) Received: from invc005.ap-rdc01.nxp.com (invc005.ap-rdc01.nxp.com [165.114.16.14]) by inva020.eu-rdc02.nxp.com (Postfix) with ESMTP id 516891A53D0; Thu, 20 Feb 2020 09:23:24 +0100 (CET) Received: from localhost.localdomain (shlinux2.ap.freescale.net [10.192.224.44]) by invc005.ap-rdc01.nxp.com (Postfix) with ESMTP id EFF18402AB; Thu, 20 Feb 2020 16:23:10 +0800 (SGT) From: Anson Huang To: rui.zhang@intel.com, daniel.lezcano@linaro.org, amit.kucheria@verdurent.com, robh+dt@kernel.org, mark.rutland@arm.com, shawnguo@kernel.org, s.hauer@pengutronix.de, kernel@pengutronix.de, festevam@gmail.com, catalin.marinas@arm.com, will@kernel.org, leonard.crestez@nxp.com, daniel.baluta@nxp.com, shengjiu.wang@nxp.com, peng.fan@nxp.com, ping.bai@nxp.com, jun.li@nxp.com, bjorn.andersson@linaro.org, olof@lixom.net, vkoul@kernel.org, dinguyen@kernel.org, marcin.juszkiewicz@linaro.org, linux-pm@vger.kernel.org, devicetree@vger.kernel.org, linux-arm-kernel@lists.infradead.org, linux-kernel@vger.kernel.org Cc: Linux-imx@nxp.com Subject: [PATCH RESEND 2/4] thermal: imx8mm: Add support for i.MX8MM thermal monitoring unit Date: Thu, 20 Feb 2020 16:17:24 +0800 Message-Id: <1582186646-22096-2-git-send-email-Anson.Huang@nxp.com> X-Mailer: git-send-email 2.7.4 In-Reply-To: <1582186646-22096-1-git-send-email-Anson.Huang@nxp.com> References: <1582186646-22096-1-git-send-email-Anson.Huang@nxp.com> X-Virus-Scanned: ClamAV using ClamSMTP Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org i.MX8MM has a thermal monitoring unit(TMU) inside, it ONLY has one sensor for CPU, add support for reading immediate temperature of this sensor. Signed-off-by: Anson Huang --- This patch is base on patch series: https://lkml.org/lkml/2020/2/19/1258 --- drivers/thermal/Kconfig | 10 +++ drivers/thermal/Makefile | 1 + drivers/thermal/imx8mm_thermal.c | 134 +++++++++++++++++++++++++++++++++++++++ 3 files changed, 145 insertions(+) create mode 100644 drivers/thermal/imx8mm_thermal.c diff --git a/drivers/thermal/Kconfig b/drivers/thermal/Kconfig index d1cb8dc..972b169 100644 --- a/drivers/thermal/Kconfig +++ b/drivers/thermal/Kconfig @@ -262,6 +262,16 @@ config IMX_SC_THERMAL sensor. It supports one critical trip point and one passive trip point for each thermal sensor. +config IMX8MM_THERMAL + tristate "Temperature sensor driver for Freescale i.MX8MM SoC" + depends on ARCH_MXC + depends on OF + help + Support for Thermal Monitoring Unit (TMU) found on Freescale i.MX8MM SoC. + It supports one critical trip point and one passive trip point. The + cpufreq is used as the cooling device to throttle CPUs when the passive + trip is crossed. + config MAX77620_THERMAL tristate "Temperature sensor driver for Maxim MAX77620 PMIC" depends on MFD_MAX77620 diff --git a/drivers/thermal/Makefile b/drivers/thermal/Makefile index a11a6d8..120a05e 100644 --- a/drivers/thermal/Makefile +++ b/drivers/thermal/Makefile @@ -44,6 +44,7 @@ obj-$(CONFIG_ARMADA_THERMAL) += armada_thermal.o obj-$(CONFIG_TANGO_THERMAL) += tango_thermal.o obj-$(CONFIG_IMX_THERMAL) += imx_thermal.o obj-$(CONFIG_IMX_SC_THERMAL) += imx_sc_thermal.o +obj-$(CONFIG_IMX8MM_THERMAL) += imx8mm_thermal.o obj-$(CONFIG_MAX77620_THERMAL) += max77620_thermal.o obj-$(CONFIG_QORIQ_THERMAL) += qoriq_thermal.o obj-$(CONFIG_DA9062_THERMAL) += da9062-thermal.o diff --git a/drivers/thermal/imx8mm_thermal.c b/drivers/thermal/imx8mm_thermal.c new file mode 100644 index 0000000..04f8a8f --- /dev/null +++ b/drivers/thermal/imx8mm_thermal.c @@ -0,0 +1,134 @@ +// SPDX-License-Identifier: GPL-2.0 +/* + * Copyright 2019 NXP. + * + */ + +#include +#include +#include +#include +#include +#include +#include +#include +#include + +#include "thermal_core.h" + +#define TER 0x0 /* TMU enable */ +#define TRITSR 0x20 /* TMU immediate temp */ + +#define TER_EN BIT(31) +#define TRITSR_VAL_MASK 0xff + +#define TEMP_LOW_LIMIT 10 + +struct imx8mm_tmu { + struct thermal_zone_device *tzd; + void __iomem *base; + struct clk *clk; +}; + +static int tmu_get_temp(void *data, int *temp) +{ + struct imx8mm_tmu *tmu = data; + u32 val; + + /* the temp sensor need about 1ms to finish the measurement */ + usleep_range(1000, 2000); + + val = readl_relaxed(tmu->base + TRITSR) & TRITSR_VAL_MASK; + if (val < TEMP_LOW_LIMIT) + return -EAGAIN; + + *temp = val * 1000; + + return 0; +} + +static struct thermal_zone_of_device_ops tmu_tz_ops = { + .get_temp = tmu_get_temp, +}; + +static int imx8mm_tmu_probe(struct platform_device *pdev) +{ + struct imx8mm_tmu *tmu; + u32 val; + int ret; + + tmu = devm_kzalloc(&pdev->dev, sizeof(struct imx8mm_tmu), GFP_KERNEL); + if (!tmu) + return -ENOMEM; + + tmu->base = devm_platform_ioremap_resource(pdev, 0); + if (IS_ERR(tmu->base)) + return PTR_ERR(tmu->base); + + tmu->clk = devm_clk_get(&pdev->dev, NULL); + if (IS_ERR(tmu->clk)) { + ret = PTR_ERR(tmu->clk); + if (ret != -EPROBE_DEFER) + dev_err(&pdev->dev, + "failed to get tmu clock: %d\n", ret); + return ret; + } + + ret = clk_prepare_enable(tmu->clk); + if (ret) { + dev_err(&pdev->dev, "failed to enable tmu clock: %d\n", ret); + return ret; + } + + tmu->tzd = devm_thermal_zone_of_sensor_register(&pdev->dev, 0, + tmu, &tmu_tz_ops); + if (IS_ERR(tmu->tzd)) { + dev_err(&pdev->dev, + "failed to register thermal zone sensor: %d\n", ret); + return PTR_ERR(tmu->tzd); + } + + platform_set_drvdata(pdev, tmu); + + /* enable the monitor */ + val = readl_relaxed(tmu->base + TER); + val |= TER_EN; + writel_relaxed(val, tmu->base + TER); + + return 0; +} + +static int imx8mm_tmu_remove(struct platform_device *pdev) +{ + struct imx8mm_tmu *tmu = platform_get_drvdata(pdev); + u32 val; + + /* disable TMU */ + val = readl_relaxed(tmu->base + TER); + val &= ~TER_EN; + writel_relaxed(val, tmu->base + TER); + + clk_disable_unprepare(tmu->clk); + platform_set_drvdata(pdev, NULL); + + return 0; +} + +static const struct of_device_id imx8mm_tmu_table[] = { + { .compatible = "fsl,imx8mm-tmu", }, + { }, +}; + +static struct platform_driver imx8mm_tmu = { + .driver = { + .name = "i.mx8mm_thermal", + .of_match_table = imx8mm_tmu_table, + }, + .probe = imx8mm_tmu_probe, + .remove = imx8mm_tmu_remove, +}; +module_platform_driver(imx8mm_tmu); + +MODULE_AUTHOR("Anson Huang "); +MODULE_DESCRIPTION("i.MX8MM Thermal Monitor Unit driver"); +MODULE_LICENSE("GPL v2"); -- 2.7.4