From patchwork Thu Dec 12 20:59:59 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Frank Li X-Patchwork-Id: 13905995 X-Patchwork-Delegate: daniel.lezcano@linaro.org Received: from EUR05-VI1-obe.outbound.protection.outlook.com (mail-vi1eur05on2045.outbound.protection.outlook.com [40.107.21.45]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id DE55E19D074; Thu, 12 Dec 2024 21:00:31 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=fail smtp.client-ip=40.107.21.45 ARC-Seal: i=2; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1734037235; cv=fail; b=g7fEtgPVYuotUV8wmbaDAe87CPCNI3khNtNdvyi5DFnUz/eETo4SJ5lFkGiZObEi92Had3gP63lcFGy/W+I/VWCWiZA4Ok0aXmCu0p6dLbZJiJZpn/1tLwEtLIkJ4HX2dscGv4GDlW3dAPxMuAZl7mAmRWTZXWLFsb67lcHlkQ8= ARC-Message-Signature: i=2; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1734037235; c=relaxed/simple; bh=ruIJLlF20swj7SJdyvZ5zimlnM5QVKtZfGGBtF7YgjA=; h=From:Date:Subject:Content-Type:Message-Id:References:In-Reply-To: To:Cc:MIME-Version; b=AJW3rC4SnX2cVWdCCSiXusm24vOyyYIXzZkmHqTrOyNgfm/zlsiPs+NZcfe82xUnrFNYfHaqCpveoznFwxtxG6Ols/nKGg4HQ9itjsj824G4H6UAG1X6Ecf0AqyI2IzKxXhRY/rb4vssoJFR4f0NHnTqcD8xkH3Wj+p1ONFvLjo= ARC-Authentication-Results: i=2; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=nxp.com; spf=pass smtp.mailfrom=nxp.com; dkim=pass (2048-bit key) header.d=nxp.com header.i=@nxp.com header.b=OecRacAm; arc=fail smtp.client-ip=40.107.21.45 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=nxp.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=nxp.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=nxp.com header.i=@nxp.com header.b="OecRacAm" ARC-Seal: i=1; a=rsa-sha256; s=arcselector10001; d=microsoft.com; cv=none; b=lwGBq40CuX7jGxKFlTPFk0gyiJxbcWu3MKcuf5RVKjEPs46wo/uiCzux7YDXQF7QgY/PzR3H2kI0Z7dhm5DUzUmIevnq0SRa0n0PdPa/wsX3gpkaRcLijU9qN/fvkZaLKjGxs72IOrrdoH5MAYDlNhbhBdhhgRoUY0cocyk2+PyZtCM1FKl2HFEcnK75nIg0WwnrIOtE9Llv0v7+FIvFILg/1Se7GEkFcig7RO0geF5MooV76pdpokiSFqsfclo+QOlPV4dzI0/hGZeiDSMBREYpXGNAlk21ijT0zch5BC0exyDJmcxHFBEPBo7dUoGipe7uaYKOrzX3rCywaaKYtw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=microsoft.com; s=arcselector10001; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-AntiSpam-MessageData-ChunkCount:X-MS-Exchange-AntiSpam-MessageData-0:X-MS-Exchange-AntiSpam-MessageData-1; bh=L99lfwl1lXdal6iy5qw3rDaAXaDEKsCNMObfCtzX3ZY=; b=dplqirbC8B+aQZvjb57hgy2IUkZTmjs4PhcaALL/DmpqqfWvex8Cw2FD/nGcQGKjVjyCNHrzQ+fnUrk5h4JoM84ct7t1BV/yVw1+maMpYkpUg/2n7b9MqIxovt69vgc2Kie1h3HILzEnfapRcd7cWN9wcmkDVtF8juS6ESGhFKa/pkF18cU+f2i0t8c2WACjXIVCtb0+C/gKR/VBJlnF/SHnA1YI7vuuCtAi1MPHYKWm73klczxFoIR7YFjhcfr8Cd64gI94EYeAhU0EpD7I1hiCc+XiiSiE0twi6bShT4usKrnDjbx/2aHRCpEx/eHJSYSJmlxgQkx8Y8YWCDfqmA== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass smtp.mailfrom=nxp.com; dmarc=pass action=none header.from=nxp.com; dkim=pass header.d=nxp.com; arc=none DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=nxp.com; s=selector1; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=L99lfwl1lXdal6iy5qw3rDaAXaDEKsCNMObfCtzX3ZY=; b=OecRacAmDalLEZCjg7ovoPbim9nz7z3VLZB3UcJKMKpzNuRKgcbeGBB+sUxJ6DfjaXneHRZgKRWEerH5TQVkUZsbU+T4czXW8Kws2T+NdDuazZ8DujU4wSAn+Wn61/wEoB123T+txIhCii0IqJHyC+Lbj5SJ810WcvHytP+1cp97OLRRkMg1gxVLh4iY43c7B+OKO+M6NHaPt3M+vpXFdigNfDw8HxTOqmdD61GJQ1u1UTb/OvWlGZ6AX7SsOsp4fMuuGrk26bJJ+rotqOcCHN3YvFxoQjjgrTZrypv80H8jTfHDzC2q2PNuVPkPuCXaljfc34yDC30tfDtzlzVUaA== Authentication-Results: dkim=none (message not signed) header.d=none;dmarc=none action=none header.from=nxp.com; Received: from PAXPR04MB9642.eurprd04.prod.outlook.com (2603:10a6:102:240::14) by AS8PR04MB7560.eurprd04.prod.outlook.com (2603:10a6:20b:29d::14) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.8251.15; Thu, 12 Dec 2024 21:00:28 +0000 Received: from PAXPR04MB9642.eurprd04.prod.outlook.com ([fe80::9126:a61e:341d:4b06]) by PAXPR04MB9642.eurprd04.prod.outlook.com ([fe80::9126:a61e:341d:4b06%5]) with mapi id 15.20.8230.010; Thu, 12 Dec 2024 21:00:28 +0000 From: Frank Li Date: Thu, 12 Dec 2024 15:59:59 -0500 Subject: [PATCH v3 1/2] dt-bindings: thermal: fsl,imx91-tmu: add bindings for NXP i.MX91 thermal module Message-Id: <20241212-imx91tmu-v3-1-85e756b29437@nxp.com> References: <20241212-imx91tmu-v3-0-85e756b29437@nxp.com> In-Reply-To: <20241212-imx91tmu-v3-0-85e756b29437@nxp.com> To: "Rafael J. Wysocki" , Daniel Lezcano , Zhang Rui , Lukasz Luba , Rob Herring , Krzysztof Kozlowski , Conor Dooley , Shawn Guo , Sascha Hauer , Pengutronix Kernel Team , Fabio Estevam , Pengfei Li , Marco Felsch Cc: linux-pm@vger.kernel.org, devicetree@vger.kernel.org, imx@lists.linux.dev, linux-arm-kernel@lists.infradead.org, linux-kernel@vger.kernel.org, Frank Li X-Mailer: b4 0.13-dev-e586c X-Developer-Signature: v=1; a=ed25519-sha256; t=1734037218; l=2361; i=Frank.Li@nxp.com; s=20240130; h=from:subject:message-id; bh=nIgf6yhXwINBKNcOtb5V9xIxfpGGwkUZ0FakJ5QJxZM=; b=Aw3XA4xG9d49zpxSYipWVwTUzY9ap+5By12YAaobM8/w46hCtTIsCEOJ73E1NEH/4+G3ZCI/0 xj2fbWHqDJjCf4y3YKv5mEhd0kJqohKpInoNZuJm9WOTqWHije+aL3e X-Developer-Key: i=Frank.Li@nxp.com; a=ed25519; pk=I0L1sDUfPxpAkRvPKy7MdauTuSENRq+DnA+G4qcS94Q= X-ClientProxiedBy: BY3PR05CA0025.namprd05.prod.outlook.com (2603:10b6:a03:254::30) To PAXPR04MB9642.eurprd04.prod.outlook.com (2603:10a6:102:240::14) Precedence: bulk X-Mailing-List: linux-pm@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: PAXPR04MB9642:EE_|AS8PR04MB7560:EE_ X-MS-Office365-Filtering-Correlation-Id: 1a9398e3-c0d2-47d2-45c6-08dd1af00219 X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0;ARA:13230040|1800799024|366016|376014|7416014|52116014|10070799003|921020; X-Microsoft-Antispam-Message-Info: =?utf-8?q?hkN4rZoqvJiccamFL+ymKqxzfbXmJ2h?= =?utf-8?q?rAirOoUZkF9TQuw7UhdtSB5qMOwwNcMmI0FPyZz9K4zvn0XUlyOQye13oWaWfaMF2?= =?utf-8?q?rM1+xJm2dXf33rTHIzsR1cROSJlU3M4+GtCbA1taDRnBsUjBeIQUNesAyUCRSBo80?= =?utf-8?q?SU/sYuX26GNxQG/xw0uUB4u2PfMmeJd0dIFCj0og0jQ2Knb9hM7P/BcXvyvmsc6KO?= =?utf-8?q?+CDYBswKtPCR5aA452EE0vI+gfVrwK9Avkuv6vFp0j49KpoufmTQCz5F1z80PY5Wh?= =?utf-8?q?zmAv/Q0LSH9+cfyWMacoZOZ6qEBO1G/GJPxBVqsYdqNR+Jvlj3AFvlpVKa4X7Alwm?= =?utf-8?q?ZWOICYEIUoBIZd9upWLWnwha/W9zk5CgxP8MIdxF6Qw56EzWu7JJnaheptkV5UZ/l?= =?utf-8?q?wEMzqd2HCpmwNEQ0IOIYM4kOmbwHVWPOGYRVcC7NHC7ISsfi4VIG+d8vyO+HBMLVS?= =?utf-8?q?u/gRZS5YrFyEAJ7XV8ZUDVDU/+VxJuIcWmh3bJhaDqHgw+VJdnaitZXzpk2YMWzFq?= =?utf-8?q?aAV1wczJf8/K9jBfB9eq7wNpMJiyItJZO8lrkDcVoNMzkDMV+ig1yJPWnXV6ZFYRI?= =?utf-8?q?cwiMPsZEGJ9wmerg1biDUaM4vsCbYHs6orLxObXZ1YgyvsBNhC21mUuGbjitJui4P?= =?utf-8?q?zGFhwn6jJl/5FTj0nvp+OU48sMUdLEgpzOkw2p/j8Lel56D0Yj328kppf56nJ5w7o?= =?utf-8?q?e7dcmw9k9cfm0RJ/MwJgaE2f9qOxLq0gYBrCXXMx8hu0EqIPCz2IJDgugLAwHbdQ3?= =?utf-8?q?OQc2ZzNHnvQmQPvGqfdh67YybMPSe4JEhIolmnOQR1VH10rms3zZddd+yWhn7Wysq?= =?utf-8?q?wet04b4XONeyTsPMYwhtQQgZsbkEdN38AYpZFXsUNVoePN7hNT8D1VErU8RjXgpYp?= =?utf-8?q?YoGk3b6lbucP+Bni7Z2IJ7cw+OzgTvSK2zOIQBR+9VBA0Lm8dVbon7UV/WamhgE+Q?= =?utf-8?q?iEQ5T0nLj/r5SDfNkJOsubT+hDHglDUV5YEXHbBamhZuUhLGYem202ah4iIza4STd?= =?utf-8?q?+J6SJvm2BN91LRnm7kY01/HWKY03NlfaweL/lPKdAOd+hxAoRpjWyonr5zZJ9HRHN?= =?utf-8?q?qxKK/rSE5ZjNagKWEOEryNSo42StJfw6V2hutUooy6tg07wYiKdIMXiTm3xE5o+Kh?= =?utf-8?q?YuSi3paSXMjFI34/xlX4yi0pvSqeKkg+D6L9ubBFvJio1AlUeCCiraFiQUK0gBy2I?= =?utf-8?q?g+ueqPRMfebC5fR6v61DSBHAkwbrZQ5m5DAuzZtbDs5MQyHFRy1ZPZlk8Thc45a40?= =?utf-8?q?GcERSd2DgUuubYk6nsYlRJRZekmGQxAVXXg=3D=3D?= X-Forefront-Antispam-Report: CIP:255.255.255.255;CTRY:;LANG:en;SCL:1;SRV:;IPV:NLI;SFV:NSPM;H:PAXPR04MB9642.eurprd04.prod.outlook.com;PTR:;CAT:NONE;SFS:(13230040)(1800799024)(366016)(376014)(7416014)(52116014)(10070799003)(921020);DIR:OUT;SFP:1101; X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-MessageData-0: =?utf-8?q?eX3qnj05/20YySSWndq9kEhrl4gV?= =?utf-8?q?hAtF5Ai/I9BzzEXwbGDzvN1y/vSnCpJC2gx1LA7at7GwWnJO/m0Tu+HvoKAHwrnIS?= =?utf-8?q?EEtcPvqo9/xauWCXruWFBHY9tNMd1ZWJ4JNGp6eAtalm1YFFmehmKuw4ys01bvq7t?= =?utf-8?q?3X1AAOnwMDErSsNZFj+KmTKi3EvRdmR2ouVTNU05XnsILBYtEUxeEQH4KM8wpbjOo?= =?utf-8?q?rVw1njqEz6haNxZX38pc5SFP/yP/pX2V0LtEqhp1HijfRVjN4RMmLOicYzLHqpMP9?= =?utf-8?q?tjhf8pxVb02zlvpz0xMDh3tFrN80rgc7qBJXzAKmICIhgOe7YQWmhVBK5Lw2xEkbu?= =?utf-8?q?89Wvi0tD1y00J6VB06taLFWMZr0NuVSh5DDJlw7mUx5oiVkCA7PFjV0CNO3OinsJa?= =?utf-8?q?vJNJZjaXw8GUgWnoY2DPyM16ikw3sLM1SHmPdLX5kwIk/twHv6emDF85UHiBYHOPd?= =?utf-8?q?5u/Zr33q9PLgMKRyfTOS2bB/OzQszb4b/PS5MLHH0XoLVGvfxRk3GacbXvo3plImR?= =?utf-8?q?ITjaOMz94KEwafUmZCz4RTZ/tT6dzqwNhDJnb0XsgOEgHG+4lb9mcrLv9V4w5f4ZE?= =?utf-8?q?qKa/zwESeyDk6YxjGGH31poVJc2YXano+zd3HbKiBWgPA9g4w7e5qIH30xy4m/AGC?= =?utf-8?q?Nafg3dirVZE6G4YqFiAkqJY8gvoEwpQ8OvJB70JhN+AZaGKWJoF7gWNeprF9NcScO?= =?utf-8?q?G91H/cJI/geqcUCg1pVsLnqIKQMqNNsUYpBNRFJSnMrTUJYQTm77xI/RdoWAV/BZ/?= =?utf-8?q?D1p6GJrNHOLJHzScBOinlDNs+B9Qw6S5IJpNsb7W5lnM7+EvM36UrvaZfimMUNLdC?= =?utf-8?q?dNVc5poJOlF68OKpZv7IiGylhVSP6zHYoJoAJExIfx8MI4wV7hJOOJh0TzJbbXcfm?= =?utf-8?q?DJCkWj32eXjrJlf8qbdccai840xhzVCMUtWTgUjGShLKA7FWvWCAanw6C5yn59lTr?= =?utf-8?q?y98YBYBb5rfwapvP3O0Ob+osO4t0BtYALZbkg9EEAqRkkR7x6To3avk5BoVlCF26P?= =?utf-8?q?l/SlRGk9Vmr/U+YdOaGTuAOMlT8kcviD0dQkEM72ZCIEhjHoYAu4TqkeJti7Mi9BD?= =?utf-8?q?ytAUtTdY0wLYkB9upGs9pRq8UTjS8RV8sq8hQCvcoOHCrH+KH0EdJae6CzcZkSvil?= =?utf-8?q?jtz+Vda/1cVgGRjlXBdGhURfvi1f0r1Rjz33a96MMcu5liNm8JEd5p/AkoNBypU/V?= =?utf-8?q?1BtQ1lcOp3PkBHsP7/DNwcpPFhvDpDC8I7mtk7VbD8M7X7EVENscA9TbuTwtIfD97?= =?utf-8?q?Y4q8f1jJ8MQSbAhH/8CARrmCtuXU60h73rDPZ3+a9AN3jB82arMSCvlZFwbddHWNC?= =?utf-8?q?+E07qwiLDAeKObhZSgHRpmZ8jCgoa74kQET1LpsFby4TBcBABChIUSZkjkvKjRES1?= =?utf-8?q?aDfPgr/3gLM4WPJ+WBL1l31f/gGMsDWnGDMk3Vx+BLLVNuZkTqYUzrU9uX8YIkjQA?= =?utf-8?q?vPeKic2k+z6ZNF4P+gokH3D8VhXWt4jL4HmQdwaC99D6zUIMkhM+UKLodHOzVBhgc?= =?utf-8?q?fTpdO6sndRSTPVK5wSIi1uooJu7iZ0dTsO4gw90g75dYknP+nurCEsxb6FS7Z005W?= =?utf-8?q?/F3nf3qwxpG?= X-OriginatorOrg: nxp.com X-MS-Exchange-CrossTenant-Network-Message-Id: 1a9398e3-c0d2-47d2-45c6-08dd1af00219 X-MS-Exchange-CrossTenant-AuthSource: PAXPR04MB9642.eurprd04.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 12 Dec 2024 21:00:28.7153 (UTC) X-MS-Exchange-CrossTenant-FromEntityHeader: Hosted X-MS-Exchange-CrossTenant-Id: 686ea1d3-bc2b-4c6f-a92c-d99c5c301635 X-MS-Exchange-CrossTenant-MailboxType: HOSTED X-MS-Exchange-CrossTenant-UserPrincipalName: 6atMOLJp7qWKTToPNRhZBBBBXUmSE9HINHZ1dZ3uP8zmNOeS98Gq2SLTUoGkriRHAzeKsLaGUt+gq+Eiezo4yw== X-MS-Exchange-Transport-CrossTenantHeadersStamped: AS8PR04MB7560 From: Pengfei Li Add bindings documentation for i.MX91 thermal modules. Signed-off-by: Pengfei Li Signed-off-by: Frank Li Reviewed-by: Krzysztof Kozlowski --- Change from v2 to v3 - add ref thermal-sensor - restrict #thermal-sensor-cells to 0 only - Change to unevaluatedProperties --- .../devicetree/bindings/thermal/fsl,imx91-tmu.yaml | 67 ++++++++++++++++++++++ 1 file changed, 67 insertions(+) diff --git a/Documentation/devicetree/bindings/thermal/fsl,imx91-tmu.yaml b/Documentation/devicetree/bindings/thermal/fsl,imx91-tmu.yaml new file mode 100644 index 0000000000000..8411f3233bf44 --- /dev/null +++ b/Documentation/devicetree/bindings/thermal/fsl,imx91-tmu.yaml @@ -0,0 +1,67 @@ +# SPDX-License-Identifier: (GPL-2.0-only OR BSD-2-Clause) +%YAML 1.2 +--- +$id: http://devicetree.org/schemas/thermal/fsl,imx91-tmu.yaml# +$schema: http://devicetree.org/meta-schemas/core.yaml# + +title: NXP i.MX91 Thermal + +maintainers: + - Pengfei Li + +description: + i.MX91 features a new temperature sensor. It includes programmable + temperature threshold comparators for both normal and privileged + accesses and allows a programmable measurement frequency for the + Periodic One-Shot Measurement mode. Additionally, it provides + status registers for indicating the end of measurement and threshold + violation events. + +properties: + compatible: + items: + - const: fsl,imx91-tmu + + reg: + maxItems: 1 + + clocks: + maxItems: 1 + + nvmem-cells: + items: + - description: Phandle to the trim control 1 provided by ocotp + - description: Phandle to the trim control 2 provided by ocotp + + nvmem-cell-names: + items: + - const: trim1 + - const: trim2 + + "#thermal-sensor-cells": + const: 0 + +required: + - compatible + - reg + - clocks + +allOf: + - $ref: thermal-sensor.yaml + +unevaluatedProperties: false + +examples: + - | + #include + + thermal-sensor@44482000 { + compatible = "fsl,imx91-tmu"; + reg = <0x44482000 0x1000>; + #thermal-sensor-cells = <0>; + clocks = <&clk IMX93_CLK_TMC_GATE>; + nvmem-cells = <&tmu_trim1>, <&tmu_trim2>; + nvmem-cell-names = "trim1", "trim2"; + }; + +... From patchwork Thu Dec 12 21:00:00 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Frank Li X-Patchwork-Id: 13905996 X-Patchwork-Delegate: daniel.lezcano@linaro.org Received: from EUR05-DB8-obe.outbound.protection.outlook.com (mail-db8eur05on2043.outbound.protection.outlook.com [40.107.20.43]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 565F71C5F07; Thu, 12 Dec 2024 21:00:36 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=fail smtp.client-ip=40.107.20.43 ARC-Seal: i=2; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1734037240; cv=fail; b=XNMiWTZaUP8eS04LvCbcr+G1CGhzNlt3Qx1GCc5H2ctXBejPQmvbawXq/3F+Yeh/e62WJGC5XfJkQoq499m7aq+/Fkoh5xoW9/sIUWum+6lMqmOT5CeUIc8dMNWw5OYBKodmgJua9yOOPQ3z/wgl/ETdVarQQfm9Wc5OZxTKKiA= ARC-Message-Signature: i=2; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1734037240; c=relaxed/simple; bh=pFRXWA2TwO/wUmImPmOAMiljT/WPmqaPXAbH6JQQMmY=; h=From:Date:Subject:Content-Type:Message-Id:References:In-Reply-To: To:Cc:MIME-Version; b=TJEEBpQfnhzINYzbg9p1KFJU1gNvxQcp/9QiHggAJxt0EAWRu4ExzmAz4li49/0mh+rii5vRj8EbZdIt3aLitX98ar5xcPy7DvlN8Mwfl1P9L3xVavERLq+zpXOTeev966DInFGByQ1shsKCEymcxchvuUopNAJGoEOyBoCzux8= ARC-Authentication-Results: i=2; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=nxp.com; spf=pass smtp.mailfrom=nxp.com; dkim=pass (2048-bit key) header.d=nxp.com header.i=@nxp.com header.b=FjHq1Lnr; arc=fail smtp.client-ip=40.107.20.43 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=nxp.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=nxp.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=nxp.com header.i=@nxp.com header.b="FjHq1Lnr" ARC-Seal: i=1; a=rsa-sha256; s=arcselector10001; d=microsoft.com; cv=none; b=MyCyVS46FlKIVMj6CL10Q7uZ6kOSkU9fMLmzVvghEBoF3TvjXUuEmzAOUC2W9JSUjEFK8k+v3jhjMYlr0toUPRHPx02HBWhj8wzuzPQTxBpi9im5+WA/wEcRu3Cuj1I0NhvtZSL4Le/hD2zUAM0ILeKq0RBX9YKVEM07BzIK38R+2xSIpJW4NwJKb8N3C00dIJrqpj479z7NGpZQhgs4KRjaeghQ0JY0SZbo+SPyd28tuoDYR4Ux4DocFRh72rxq9fmuwDYHSZFH7Zw1IHthpZUO1RB0pg6vAXUgNS1x86m/F/xaUBk08OS8X3r9MZ4JWda7sNyQ0ZFzr8KIr4mCCA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=microsoft.com; s=arcselector10001; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-AntiSpam-MessageData-ChunkCount:X-MS-Exchange-AntiSpam-MessageData-0:X-MS-Exchange-AntiSpam-MessageData-1; bh=Mu/LPt3yx4FBUCM4QCAaFywQ/R9bTTHrooRW+dw8ym0=; b=XKcaJX3vzM/Cv192XM7VI0ky4CcF1MHiieRdzRyO7Vjn72P6a+gSakKcC4X3cdD7rvGKJaoGJ2doyJSVLyoKXukqPjvk+N7BQg7GJEISyqcdXXPtifzGHMMBjcRTeOr0BlJl0yZhoCZTKH+antBMkufhN4NheqLHHD4F6Z1apNq0SVaXeWqjIT82yUvCjiCfGlxOPYofGNWbprsPVYO5VGxnebeKuhuCXCP777Xn/W/AA1PMqTHh5M3LDUQneemrlRJ7qRisOgmEVcEh3bjoWvoeOegneVydN3t9hc7i18HeL98tE64UQWiesd03lz6S8nUL5l2cKAFB03G+a6IvxA== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass smtp.mailfrom=nxp.com; dmarc=pass action=none header.from=nxp.com; dkim=pass header.d=nxp.com; arc=none DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=nxp.com; s=selector1; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=Mu/LPt3yx4FBUCM4QCAaFywQ/R9bTTHrooRW+dw8ym0=; b=FjHq1LnrsfqsV6LltyB0hWf9C+SGdkFoLu31f0eyKdD0wwVe7SMDPAp+tYLFHnI1B6KgjsmFZW4yaeqetYIOWBiDsOkGbv0WQjrDct1pqZKGwtZNt9f/WNvchHlsUciLX1KH+0aRS3aFwFv8qUu3pdjU9dO6HYM96PgH4L3WzPykgmnjUkd7bU2D/SgqI+A95IxP8qXxbZVLv9SPzF329Cra272wPVMyEynGMueGdD71jzX0YDGOVV0GnAC4binvsEKC6LU1SscpequRRzRHSG7DeVaqRnbGHrRSNudir+4ok2yuopX6pnx7zBeEFmI4BEaeKr+s02kK0czb80pqLQ== Authentication-Results: dkim=none (message not signed) header.d=none;dmarc=none action=none header.from=nxp.com; Received: from PAXPR04MB9642.eurprd04.prod.outlook.com (2603:10a6:102:240::14) by AS8PR04MB7560.eurprd04.prod.outlook.com (2603:10a6:20b:29d::14) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.8251.15; Thu, 12 Dec 2024 21:00:34 +0000 Received: from PAXPR04MB9642.eurprd04.prod.outlook.com ([fe80::9126:a61e:341d:4b06]) by PAXPR04MB9642.eurprd04.prod.outlook.com ([fe80::9126:a61e:341d:4b06%5]) with mapi id 15.20.8230.010; Thu, 12 Dec 2024 21:00:34 +0000 From: Frank Li Date: Thu, 12 Dec 2024 16:00:00 -0500 Subject: [PATCH v3 2/2] thermal: imx91: Add support for i.MX91 thermal monitoring unit Message-Id: <20241212-imx91tmu-v3-2-85e756b29437@nxp.com> References: <20241212-imx91tmu-v3-0-85e756b29437@nxp.com> In-Reply-To: <20241212-imx91tmu-v3-0-85e756b29437@nxp.com> To: "Rafael J. Wysocki" , Daniel Lezcano , Zhang Rui , Lukasz Luba , Rob Herring , Krzysztof Kozlowski , Conor Dooley , Shawn Guo , Sascha Hauer , Pengutronix Kernel Team , Fabio Estevam , Pengfei Li , Marco Felsch Cc: linux-pm@vger.kernel.org, devicetree@vger.kernel.org, imx@lists.linux.dev, linux-arm-kernel@lists.infradead.org, linux-kernel@vger.kernel.org, Frank Li , Peng Fan X-Mailer: b4 0.13-dev-e586c X-Developer-Signature: v=1; a=ed25519-sha256; t=1734037218; l=10296; i=Frank.Li@nxp.com; s=20240130; h=from:subject:message-id; bh=6kF2c/YSx7LoiU1VwjjvTmVypq+sG5LudLSU6kO8t+s=; b=7kTtNd81/dyL1DLuudNWdlLADsuauzCtqndFgzkp7zaFu/ihOXh/icfaiwfUtmM1H2jB7ehSH JkQ1kqAbi+IDzusOb+h77Ah6XbpkF2Q5CbEJ+JPIWed+Pz/2P6ClQyf X-Developer-Key: i=Frank.Li@nxp.com; a=ed25519; pk=I0L1sDUfPxpAkRvPKy7MdauTuSENRq+DnA+G4qcS94Q= X-ClientProxiedBy: BY3PR05CA0025.namprd05.prod.outlook.com (2603:10b6:a03:254::30) To PAXPR04MB9642.eurprd04.prod.outlook.com (2603:10a6:102:240::14) Precedence: bulk X-Mailing-List: linux-pm@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: PAXPR04MB9642:EE_|AS8PR04MB7560:EE_ X-MS-Office365-Filtering-Correlation-Id: 5d5223f8-a8ae-41f5-0a86-08dd1af0057c X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0;ARA:13230040|1800799024|366016|376014|7416014|52116014|10070799003|921020; X-Microsoft-Antispam-Message-Info: =?utf-8?q?O7/CO2hHOT2ZDHCx+03kemewmx8lrOK?= =?utf-8?q?LlbgyfmHxwd0duZMFqsbqXAVZxyolE0dUh3wnnQAklsU3n3CfnPospU3KQEb+LHOm?= =?utf-8?q?/fZbeADuWrgh+mm2I/4tfOt2eycH/vvDAcPw90Qu7JJvdqqs/BiPEWnJqIs3As47m?= =?utf-8?q?Idgy1HClQ6QHFAiFC5T6eEygVeN88Qt6OT+wzQw5mL6jnkVHc+125NOjul3Ic1qZ8?= =?utf-8?q?P1erIT3Vwg1R9hVI03dMQJWCqpm703CacFfD+pWIW35xJ7Eq8GOUyNmy3FWZCy5vP?= =?utf-8?q?40vH28KP+nhb8gNVH7ptv2t47ZQNj6708QSTcc8gIayExS5fkSJdhWTa19EzegPGA?= =?utf-8?q?3kZYXHeebLApIaMokLGb/+Yn6yO43hO6ELWVbukmwlyJ4e0FG+a/b2WV6TqNxx29L?= =?utf-8?q?iz5/lVBl1gPUMMdEdGDSTeVNz3dQKf5UUHjWavHTXqv8g1r1LgllKzdNS7etkJ79w?= =?utf-8?q?wDT+bI5+zxt9ysJgechb/HGu/aWGGmdp+feJPro09goEZ+M3/v2Vea8NRzfkrntnC?= =?utf-8?q?/Aq3PSOTHRW3BNNoxnYLpb7U6JSxHcJTXzW0Whm3zb08kBlFZE80g84TY41K+Psxc?= =?utf-8?q?AuSA/MAemv6sJ/bEsIC+GEs6EHZpQU/NaJdgzjfbBNToVV7seELgEDUWVXGA/uojp?= =?utf-8?q?LctSIpDsz1Bqcqa/jbdznHAMJH3zn+mEVLUUBV474uKYTA8eA0n6ArAoP4XbskPkV?= =?utf-8?q?8xCvY3kTqivjSTS012LdRf2zC/Ti7G2MaHD+N6N93wTf3YpgS1sSyt27fe76dGOnk?= =?utf-8?q?zP2q+W3IJUUbJv9V0TZH7hQM1el+oV7xtsuAaWifwUm7AEpWgJORbsxfNAhll8fXZ?= =?utf-8?q?E6Cw5S8IltDgSd3667AMzpL08rSZABf/IsrJ8Td7esmEjs8ZCcuj3xuJexVLff1PJ?= =?utf-8?q?PljZyIEv5c0abKOhgHoUx1Whkb5N6xplDWRFe2j5ISJUZ1hTpTQVIspKgfqnXZGnV?= =?utf-8?q?YAtC1GodvjMOntY57A8wtlriCAGAJBXH72u/ju86kM7FJoULkwAbUorTE4g5KMJJC?= =?utf-8?q?GNhrE/JbR0juZfbXp4Q7eJG7mBE9XVxOXdJYX88CPFyNPdzHlVNoK0xM1ex7Dhu1S?= =?utf-8?q?ynVQVhrzfJAWH+9QpSGYVyhYq+Qk+BID6mmby2keKbRmhNHQFCSlNyzcrgYsqojl7?= =?utf-8?q?jD7q2DDmYf7PLjkZZ3ZcVnnqTmDblkfeclpuwKJFCVMGbGSxvoKCnGfe/+nrqX5Zj?= =?utf-8?q?MBa1Mau3mV/jlsGR0gqnM6Up1EvlunSsSHEGmZn1tevgq9S7JWe3DFZPJSh+tLxC8?= =?utf-8?q?VaOpT1pcNHUt2QwukWZKC2I1zUXrq/lEBK1ICkuEU4eYydEJHwanIz8srzttNKsJX?= =?utf-8?q?8036MAI7CIscoy0EqqzLbyDnUna1TwGHwQ=3D=3D?= X-Forefront-Antispam-Report: CIP:255.255.255.255;CTRY:;LANG:en;SCL:1;SRV:;IPV:NLI;SFV:NSPM;H:PAXPR04MB9642.eurprd04.prod.outlook.com;PTR:;CAT:NONE;SFS:(13230040)(1800799024)(366016)(376014)(7416014)(52116014)(10070799003)(921020);DIR:OUT;SFP:1101; X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-MessageData-0: =?utf-8?q?p9aF/rMVA6cPVYxN2LoCTfyieieq?= =?utf-8?q?9zvvH94mFUxk/fCvT9lOYzglyDjnHpOGTrbta9wnuwuHSTm96Vdh6zApN9l35FBxc?= =?utf-8?q?ehFgW5PJOGsCturMovOJG2H8N9p0wLA0Bc+EBbAPLvBXjJpRWYMUaVfSkImgZ4GId?= =?utf-8?q?1Yr4+nhZWwNMrUMCdSHvkX/YFOiz05V5h1y98IX2VazSHiYa/9VB+WbIIXf09L/d4?= =?utf-8?q?ov30zBe4ojNy7dIE4YhgEsPs5mWbiSgdz/vRymddmajd4RoP++5EZMqEhTjgsoEJS?= =?utf-8?q?cvEeuK43Dkje0W1ynMFW1zyPRANzKYtgR3aJZE8ytcE42gvt3io+DRrAHZJnkbRhc?= =?utf-8?q?b1QjpISzRjEItiQKvXgiV/yzC/IWZGkxQZkKwmRcX8TjcRes+ctZDzIK+HhxQ5iHn?= =?utf-8?q?b76UUDtw374/I3NV89AF8CIRhdgodDDTDGsnhGzQxDHgLvY3jeHvuvnVk6NM5X3n7?= =?utf-8?q?yEJkopgrGyoZCqAkIVm7TbkigzG4JPbxnH35w4lYltbW+bokcNXehcCyBd6LQTjXE?= =?utf-8?q?/o83ulyH3RdP0t9Yb1DEiBApEvR/btI6m2j6U1zNMwmF9MiLr7BBTj2Bj3O+bplg7?= =?utf-8?q?iLnxbSW0BTih9O+fuIUdJYk60E8NptjM2P3tf/bKz5oDSpsaGiXa0qJzIB1AgIhlc?= =?utf-8?q?1iJUrk7Rurv0+bvJz4oyggCzI3A56gmfR0CoAVdC11V1NR7rDTLsy9DmmBRCmR8Co?= =?utf-8?q?Vv7x+EcqUPUuHt0exUUgRQeFU4dimr+fPJrJ1TujN/XKzyBSBXXIRm1ksyPf5ASLr?= =?utf-8?q?bMgE9NYTfhDFPdVFClbRIs7/M09kvenEQvQHdrDLNF9Q0xYZddb9bzsiB0SWjj6BL?= =?utf-8?q?rO/MkRFV0V/n4tW8OHaRvfHYulo+L5um3GIqK3PGGVm7giRMpHOFsaiS1Ukoe+sSy?= =?utf-8?q?yZ3Kd7ifoDuHrg85w5d9cTtw/YDI1hYTbeLFzXOEZBnMyoCrktvAoRxW76FtX8OC/?= =?utf-8?q?LDKg+hGFVnqyX4SD00aUTctjbfF1yJiZTPleo3kupA2gCoiOalXAURq4nbLHxu47q?= =?utf-8?q?JNeHktRs0K9ZEJmg/uExb6MPlhkS3ZxvapxBnKz/9c/DZpD3ZjziR/Gc5KuTejJSe?= =?utf-8?q?kgTe3sO7xqKb65XywkfqQ8XGZlzGTEkDA2XqIKF4LHpkeHT99HNBodvsa9h9bTSHx?= =?utf-8?q?rN5sfwuLv0j0WuNgI9O5jt1/TO/Ly410lCTBaS+wTaYXZAGC7DDc7hzgPoxZ5F4Mj?= =?utf-8?q?aKJOnyUq41c+AUxQi3eyd0UQvoAI0L3o634MTSbRkUgdTID5QIGdC1Xo7EPmm8P7K?= =?utf-8?q?HJV1CVcfNa9w9SvZxY4AtxfrrCCWnIJ2jrjkFsnRa/JSXfPmkrl/QQ3uAfxJPStYZ?= =?utf-8?q?k8gaJZZWWPRWWP7jHmr3lq8ZvmYkSMZkm1UfPICLyBONjuTmPrkkCldJ2oYc8Y31b?= =?utf-8?q?zeoQ+jsSnOMCV//TJvjujQGoLvdWE7MLyPKmNe0sQ0DKW96643V4ST+bOCmbxu7Cp?= =?utf-8?q?ZaiO9iqfCZRf8eUMCyN+dAhCbGoKfbnMpkcX6XFuQX51yVAlcJBpzVB9c+rog1TaN?= =?utf-8?q?dYjz1VKZtxSwnIsxyxWsaHcEE/BbtG3dU3UnqJew5/H7VpeqAAndJqw493lBrLdqL?= =?utf-8?q?Bek63svKdy7?= X-OriginatorOrg: nxp.com X-MS-Exchange-CrossTenant-Network-Message-Id: 5d5223f8-a8ae-41f5-0a86-08dd1af0057c X-MS-Exchange-CrossTenant-AuthSource: PAXPR04MB9642.eurprd04.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 12 Dec 2024 21:00:34.5244 (UTC) X-MS-Exchange-CrossTenant-FromEntityHeader: Hosted X-MS-Exchange-CrossTenant-Id: 686ea1d3-bc2b-4c6f-a92c-d99c5c301635 X-MS-Exchange-CrossTenant-MailboxType: HOSTED X-MS-Exchange-CrossTenant-UserPrincipalName: sPjDhVebg8V4T7X4l8e9xVY9PPxbtvZi9gx0+1+zqlkQqG8FKPXkY4Vu5SbgbidauB7VlvpgVil+k+vTLoKUtg== X-MS-Exchange-Transport-CrossTenantHeadersStamped: AS8PR04MB7560 From: Pengfei Li Introduce support for the i.MX91 thermal monitoring unit, which features a single sensor for the CPU. The register layout differs from other chips, necessitating the creation of a dedicated file for this. Signed-off-by: Pengfei Li Signed-off-by: Peng Fan Signed-off-by: Frank Li Reviewed-by: Marco Felsch --- change from v2 to v3 - add IMX91_TMU_ prefix for register define - remove unused register define - fix missed pm_runtime_put() at error path in imx91_tmu_get_temp() - use dev variable in probe function - use pm_runtime_set_active() in probe - move START to imx91_tmu_get_temp() - use DEFINE_RUNTIME_DEV_PM_OPS() - keep set reset value because there are not sw "reset" bit in controller, uboot may change and enable tmu. change from v1 to v2 - use low case for hexvalue - combine struct imx91_tmu and tmu_sensor - simplify imx91_tmu_start() and imx91_tmu_enable() - use s16 for imx91_tmu_get_temp(), which may negative value - use reverse christmas tree style - use run time pm - use oneshot to sample temp - register thermal zone after hardware init --- drivers/thermal/Kconfig | 10 ++ drivers/thermal/Makefile | 1 + drivers/thermal/imx91_thermal.c | 263 ++++++++++++++++++++++++++++++++++++++++ 3 files changed, 274 insertions(+) diff --git a/drivers/thermal/Kconfig b/drivers/thermal/Kconfig index d3f9686e26e71..da403ed86aeb1 100644 --- a/drivers/thermal/Kconfig +++ b/drivers/thermal/Kconfig @@ -296,6 +296,16 @@ config IMX8MM_THERMAL cpufreq is used as the cooling device to throttle CPUs when the passive trip is crossed. +config IMX91_THERMAL + tristate "Temperature sensor driver for NXP i.MX91 SoC" + depends on ARCH_MXC || COMPILE_TEST + depends on OF + help + Support for Temperature sensor found on NXP i.MX91 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 K3_THERMAL tristate "Texas Instruments K3 thermal support" depends on ARCH_K3 || COMPILE_TEST diff --git a/drivers/thermal/Makefile b/drivers/thermal/Makefile index 9abf43a74f2bb..08da241e6a598 100644 --- a/drivers/thermal/Makefile +++ b/drivers/thermal/Makefile @@ -50,6 +50,7 @@ obj-$(CONFIG_ARMADA_THERMAL) += armada_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_IMX91_THERMAL) += imx91_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/imx91_thermal.c b/drivers/thermal/imx91_thermal.c new file mode 100644 index 0000000000000..62b579365fd03 --- /dev/null +++ b/drivers/thermal/imx91_thermal.c @@ -0,0 +1,263 @@ +// SPDX-License-Identifier: GPL-2.0 +/* + * Copyright 2024 NXP. + */ + +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include + +#define IMX91_TMU_STAT0 0x10 +#define IMX91_TMU_STAT0_DRDY0_IF_MASK BIT(16) + +#define IMX91_TMU_DATA0 0x20 + +#define IMX91_TMU_CTRL1_SET 0x204 +#define IMX91_TMU_CTRL1_CLR 0x208 +#define IMX91_TMU_CTRL1_EN BIT(31) +#define IMX91_TMU_CTRL1_START BIT(30) +#define IMX91_TMU_CTRL1_STOP BIT(29) +#define IMX91_TMU_CTRL1_RES_MASK GENMASK(19, 18) +#define IMX91_TMU_CTRL1_MEAS_MODE_MASK GENMASK(25, 24) +#define IMX91_TMU_CTRL1_MEAS_MODE_SINGLE 0 +#define IMX91_TMU_CTRL1_MEAS_MODE_CONTINUES 1 +#define IMX91_TMU_CTRL1_MEAS_MODE_PERIODIC 2 + +#define IMX91_TMU_REF_DIV 0x280 +#define IMX91_TMU_DIV_EN BIT(31) +#define IMX91_TMU_DIV_MASK GENMASK(23, 16) +#define IMX91_TMU_DIV_MAX 255 + +#define IMX91_TMU_PUD_ST_CTRL 0x2b0 +#define IMX91_TMU_PUDL_MASK GENMASK(23, 16) + +#define IMX91_TMU_TRIM1 0x2e0 +#define IMX91_TMU_TRIM2 0x2f0 + +#define IMX91_TMU_TEMP_LOW_LIMIT -40000 +#define IMX91_TMU_TEMP_HIGH_LIMIT 125000 + +#define IMX91_TMU_DEFAULT_TRIM1_CONFIG 0xb561bc2d +#define IMX91_TMU_DEFAULT_TRIM2_CONFIG 0x65d4 + +struct imx91_tmu { + void __iomem *base; + struct clk *clk; + struct device *dev; + struct thermal_zone_device *tzd; +}; + +static void imx91_tmu_start(struct imx91_tmu *tmu, bool start) +{ + u32 val = start ? IMX91_TMU_CTRL1_START : IMX91_TMU_CTRL1_STOP; + + writel_relaxed(val, tmu->base + IMX91_TMU_CTRL1_SET); +} + +static void imx91_tmu_enable(struct imx91_tmu *tmu, bool enable) +{ + u32 reg = enable ? IMX91_TMU_CTRL1_SET : IMX91_TMU_CTRL1_CLR; + + writel_relaxed(IMX91_TMU_CTRL1_EN, tmu->base + reg); +} + +static int imx91_tmu_get_temp(struct thermal_zone_device *tz, int *temp) +{ + struct imx91_tmu *tmu = thermal_zone_device_priv(tz); + s16 data; + int ret; + u32 val; + + ret = pm_runtime_resume_and_get(tmu->dev); + if (ret < 0) + return ret; + + imx91_tmu_start(tmu, true); + + ret = readl_relaxed_poll_timeout(tmu->base + IMX91_TMU_STAT0, val, + val & IMX91_TMU_STAT0_DRDY0_IF_MASK, 1000, 40000); + if (ret) { + ret = -EAGAIN; + goto out; + } + + /* DATA0 is 16bit signed number */ + data = readw_relaxed(tmu->base + IMX91_TMU_DATA0); + *temp = data * 1000 / 64; + if (*temp < IMX91_TMU_TEMP_LOW_LIMIT || *temp > IMX91_TMU_TEMP_HIGH_LIMIT) + ret = -EAGAIN; + +out: + pm_runtime_put(tmu->dev); + + return ret; +} + +static struct thermal_zone_device_ops tmu_tz_ops = { + .get_temp = imx91_tmu_get_temp, +}; + +static int imx91_init_from_nvmem_cells(struct imx91_tmu *tmu) +{ + struct device *dev = tmu->dev; + u32 trim1, trim2; + int ret; + + ret = nvmem_cell_read_u32(dev, "trim1", &trim1); + if (ret) + return ret; + + ret = nvmem_cell_read_u32(dev, "trim2", &trim2); + if (ret) + return ret; + + if (trim1 == 0 || trim2 == 0) + return -EINVAL; + + writel_relaxed(trim1, tmu->base + IMX91_TMU_TRIM1); + writel_relaxed(trim2, tmu->base + IMX91_TMU_TRIM2); + + return 0; +} + +static int imx91_tmu_probe(struct platform_device *pdev) +{ + struct device *dev = &pdev->dev; + struct imx91_tmu *tmu; + unsigned long rate; + u32 div; + int ret; + + tmu = devm_kzalloc(dev, sizeof(struct imx91_tmu), GFP_KERNEL); + if (!tmu) + return -ENOMEM; + + tmu->dev = dev; + + tmu->base = devm_platform_ioremap_resource(pdev, 0); + if (IS_ERR(tmu->base)) + return dev_err_probe(dev, PTR_ERR(tmu->base), "failed to get io resource"); + + tmu->clk = devm_clk_get_enabled(dev, NULL); + if (IS_ERR(tmu->clk)) + return dev_err_probe(dev, PTR_ERR(tmu->clk), "failed to get tmu clock\n"); + + platform_set_drvdata(pdev, tmu); + + /* disable the monitor during initialization */ + imx91_tmu_enable(tmu, false); + imx91_tmu_start(tmu, false); + + ret = imx91_init_from_nvmem_cells(tmu); + if (ret) { + writel_relaxed(IMX91_TMU_DEFAULT_TRIM1_CONFIG, tmu->base + IMX91_TMU_TRIM1); + writel_relaxed(IMX91_TMU_DEFAULT_TRIM2_CONFIG, tmu->base + IMX91_TMU_TRIM2); + } + + /* The typical conv clk is 4MHz, the output freq is 'rate / (div + 1)' */ + rate = clk_get_rate(tmu->clk); + div = (rate / 4000000) - 1; + if (div > IMX91_TMU_DIV_MAX) + return dev_err_probe(dev, -EINVAL, "clock divider exceed hardware limiation"); + + /* Set divider value and enable divider */ + writel_relaxed(IMX91_TMU_DIV_EN | FIELD_PREP(IMX91_TMU_DIV_MASK, div), + tmu->base + IMX91_TMU_REF_DIV); + + /* Set max power up delay: 'Tpud(ms) = 0xFF * 1000 / 4000000' */ + writel_relaxed(FIELD_PREP(IMX91_TMU_PUDL_MASK, 100U), tmu->base + IMX91_TMU_PUD_ST_CTRL); + + /* + * Set resolution mode + * 00b - Conversion time = 0.59325 ms + * 01b - Conversion time = 1.10525 ms + * 10b - Conversion time = 2.12925 ms + * 11b - Conversion time = 4.17725 ms + */ + writel_relaxed(FIELD_PREP(IMX91_TMU_CTRL1_RES_MASK, 0x3), tmu->base + IMX91_TMU_CTRL1_CLR); + writel_relaxed(FIELD_PREP(IMX91_TMU_CTRL1_RES_MASK, 0x1), tmu->base + IMX91_TMU_CTRL1_SET); + + writel_relaxed(IMX91_TMU_CTRL1_MEAS_MODE_MASK, tmu->base + IMX91_TMU_CTRL1_CLR); + writel_relaxed(FIELD_PREP(IMX91_TMU_CTRL1_MEAS_MODE_MASK, IMX91_TMU_CTRL1_MEAS_MODE_SINGLE), + tmu->base + IMX91_TMU_CTRL1_SET); + + imx91_tmu_enable(tmu, true); + pm_runtime_set_active(dev); + devm_pm_runtime_enable(dev); + + tmu->tzd = devm_thermal_of_zone_register(dev, 0, tmu, &tmu_tz_ops); + if (IS_ERR(tmu->tzd)) + return dev_err_probe(dev, PTR_ERR(tmu->tzd), + "failed to register thermal zone sensor\n"); + + pm_runtime_put(dev); + + return 0; +} + +static void imx91_tmu_remove(struct platform_device *pdev) +{ + struct imx91_tmu *tmu = platform_get_drvdata(pdev); + + /* disable tmu */ + imx91_tmu_start(tmu, false); + imx91_tmu_enable(tmu, false); +} + +static int imx91_tmu_runtime_suspend(struct device *dev) +{ + struct imx91_tmu *tmu = dev_get_drvdata(dev); + + /* disable tmu */ + imx91_tmu_enable(tmu, false); + + clk_disable_unprepare(tmu->clk); + + return 0; +} + +static int imx91_tmu_runtime_resume(struct device *dev) +{ + struct imx91_tmu *tmu = dev_get_drvdata(dev); + int ret; + + ret = clk_prepare_enable(tmu->clk); + if (ret) + return ret; + + imx91_tmu_enable(tmu, true); + + return 0; +} + +static DEFINE_RUNTIME_DEV_PM_OPS(imx91_tmu_pm_ops, imx91_tmu_runtime_suspend, + imx91_tmu_runtime_resume, NULL); + +static const struct of_device_id imx91_tmu_table[] = { + { .compatible = "fsl,imx91-tmu", }, + { }, +}; +MODULE_DEVICE_TABLE(of, imx91_tmu_table); + +static struct platform_driver imx91_tmu = { + .driver = { + .name = "imx91_thermal", + .pm = pm_ptr(&imx91_tmu_pm_ops), + .of_match_table = imx91_tmu_table, + }, + .probe = imx91_tmu_probe, + .remove = imx91_tmu_remove, +}; +module_platform_driver(imx91_tmu); + +MODULE_AUTHOR("Peng Fan "); +MODULE_DESCRIPTION("i.MX91 Thermal Monitor Unit driver"); +MODULE_LICENSE("GPL");