From patchwork Thu Jan 5 10:17:46 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: "Alice Guo (OSS)" X-Patchwork-Id: 13090428 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org 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 smtp.lore.kernel.org (Postfix) with ESMTPS id 1C7A9C3DA7A for ; Thu, 5 Jan 2023 20:14:47 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20210309; h=Sender: Content-Transfer-Encoding:Content-Type:List-Subscribe:List-Help:List-Post: List-Archive:List-Unsubscribe:List-Id:MIME-Version:References:In-Reply-To: Message-Id:Date:Subject:Cc:To:From:Reply-To:Content-ID:Content-Description: Resent-Date:Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID: List-Owner; bh=LWKfLqba/d4bAhTWZFRXXHXa5vwas/JwNzX2RiG4rlY=; b=hG+ZlGp7FkvWgU fnFRkcKIM6I3JYVH1dHK6l/E25sKbKcsf1fNL6goyK8zhI4MD5YLP7Ey+iajdYmQ4CmloMOgpIYJW q6onjQp/ka/Tfuwh1YJ8OYyz1io5sx0Gj+ewjbcWHJCRNJLyehq2xTyPnB6Aiu4uDysc76TIgljIs JLmNh8j5pDKO5W9+NQSKMDgNMZM0g3WbjprMAxv6yWHGyezcfUPHE9cFriQ232Sc8XYAW/mG41Aum RAm6qnJSt7PpOCJqmL1Nc/WxDS6n8KACTfbmnvCdiCngDxZ9HLp0a1eGRPrIxSPCG0qhbsR1wJYfn QQEF3Uz11W+y4av19a4A==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.94.2 #2 (Red Hat Linux)) id 1pDWcD-00EQdk-Gr; Thu, 05 Jan 2023 20:13:30 +0000 Received: from mail-db3eur04on2062.outbound.protection.outlook.com ([40.107.6.62] helo=EUR04-DB3-obe.outbound.protection.outlook.com) by bombadil.infradead.org with esmtps (Exim 4.94.2 #2 (Red Hat Linux)) id 1pDNKi-00ATLx-Ie for linux-arm-kernel@lists.infradead.org; Thu, 05 Jan 2023 10:18:50 +0000 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=Y9gNGNNqGi99DDYBHW54tTTb8I45V9ttIaWo0/kw9PqglDtZcoIvfYXouqTdSWHcZ9k9aY98c12WWuFQ0OnDhPyjXZC2DxzJBcM/aJtCBT5rVTlpJzSc75VLE1hxqd7zXu9trqaFGL/fjGpw/gvOu9qYbQmhfbPh+hkYwj8hN5t/jP9XXk7G9/jaUp7/JyJZFD5DjKun92ImQeUiK08hZCl7CQJRv8tFuXMHWQleIgBAfYYlRkkZou61gmnCFt7uqePt47gmGhuHV20J8Wl5OJAPVx1oNnZGmhwjXAkf6udQppIqukfyV2QGSjChUafcaH4a+PzugYEm4uYJHp9qTg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=microsoft.com; s=arcselector9901; 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=mlpPpNYvPVCjP2c7H64FoabqZdh+z3HL3BQL1ylLrVI=; b=Z+i1TvFXhaFnYjDuos5YzP8rQjAXpSCqpJ768hWsskSabAOyeDRJF3p5TPCvAlhpEKRM9Ca3WjKMOAVAIoogt0jMwnwG0XL2UKYzTLY09DabvoIcbLrLCim7fRRNZmmepiJulcUoap0hYWNBpgUip+tjvqZZ7pwiSsLqpoweDm7aroItl3Li2bqa5+mryqxk7HClthUiac7WARepggWEnEaefoPyCEkRZePbgnrwekMpc5OcgaEAHX8lOqURvJ+jRl5zUPxuHeAwuAFFJRcNXO+BhLmrAKDq325GBB4Er7JWhar6dEiQ5+pDXjB68/TNQOOwOxi+Y6wHF6w/Ulm82g== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass smtp.mailfrom=oss.nxp.com; dmarc=pass action=none header.from=oss.nxp.com; dkim=pass header.d=oss.nxp.com; arc=none DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=NXP1.onmicrosoft.com; s=selector2-NXP1-onmicrosoft-com; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=mlpPpNYvPVCjP2c7H64FoabqZdh+z3HL3BQL1ylLrVI=; b=Uakkmo5asZJNON3rQLlgBe9oU9ozqCmz9j8XQSkLKneNGYuBbBw2193u1OvfjSIka5F3titsTWjSkFBsl2v8dq7A3Lf/vYSSPNpUoZMngce/GSKXEy8hQQeUoSd8jkTIqLxBfRH3xD4TuHRIsne8+qg+XKuwOifo70B5jCdgvEg= Authentication-Results: dkim=none (message not signed) header.d=none;dmarc=none action=none header.from=oss.nxp.com; Received: from AM6PR04MB6053.eurprd04.prod.outlook.com (2603:10a6:20b:b9::10) by DBBPR04MB7625.eurprd04.prod.outlook.com (2603:10a6:10:202::18) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.5944.19; Thu, 5 Jan 2023 10:18:44 +0000 Received: from AM6PR04MB6053.eurprd04.prod.outlook.com ([fe80::f75a:918f:6b4c:4a00]) by AM6PR04MB6053.eurprd04.prod.outlook.com ([fe80::f75a:918f:6b4c:4a00%4]) with mapi id 15.20.5944.019; Thu, 5 Jan 2023 10:18:44 +0000 From: "Alice Guo (OSS)" To: rafael@kernel.org, daniel.lezcano@linaro.org, amitk@kernel.org, rui.zhang@intel.com, robh+dt@kernel.org, krzysztof.kozlowski+dt@linaro.org, shawnguo@kernel.org, s.hauer@pengutronix.de, festevam@gmail.com Cc: linux-pm@vger.kernel.org, linux-kernel@vger.kernel.org, linux-arm-kernel@lists.infradead.org, devicetree@vger.kernel.org, linux-imx@nxp.com Subject: [PATCH v1 2/4] thermal: qoriq: add i.MX93 TMU support Date: Thu, 5 Jan 2023 18:17:46 +0800 Message-Id: <20230105101748.6714-3-alice.guo@oss.nxp.com> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20230105101748.6714-1-alice.guo@oss.nxp.com> References: <20230105101748.6714-1-alice.guo@oss.nxp.com> X-ClientProxiedBy: SI2P153CA0009.APCP153.PROD.OUTLOOK.COM (2603:1096:4:140::18) To AM6PR04MB6053.eurprd04.prod.outlook.com (2603:10a6:20b:b9::10) MIME-Version: 1.0 X-MS-Exchange-MessageSentRepresentingType: 1 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: AM6PR04MB6053:EE_|DBBPR04MB7625:EE_ X-MS-Office365-Filtering-Correlation-Id: 661adaa4-0a16-482a-425d-08daef063990 X-MS-Exchange-SharedMailbox-RoutingAgent-Processed: True X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: QL39zXp9Y9v6dLc9Ifag92W8NjyEoVFzwYAaKz+vk5iweEonDpfpOD5wdmTbAn4KWI1P9zIx60DeWCbu/OKtWtSremrpzv/r6TQBdu/1Bdzdc4yMxNW2IYB5OEXs/DP8hM3XAUIgwYNBY8/hvttK73BTLRVEY2hql2jQ8sHe1Yz2Pao1vtVrXQgatgoWhKtl4pC7zWX/tAbNzcEVyFXIQ8Ljd7TGcwgGEz7GRYq33RqTHVjnAm9f43fCDhTEAPzD7dRe8opne9UvVxtRqdvcaxBJ6TXxl/CZqN9G4txdjRP2zUjJeNCwQC44RtJoE8exzqYfonlonCZ1CTOKZvhFpVGSOlKIa5NsEaKaDTTUXbNmQ1qu3sjIqJWzSs+GTnpbhvhCeQ3J0pW7il0nFpABokoDh/m8NVAHE7rjkwM/sbaEkIvk8OWxiSjvedG6AYhulti5/zoRFLkrhvrOdAiax0x76Iqe95QiCskDo7zCeaZJZeCn6/i0RgrS/8x1bcDo/qgX8nxlULtqBTO09aP3uwCNGy2JEhilJ0CDW3BtPl70/gmV6Y1haO60vszRIjG91aw36zN807XVJlclzJwocZyFrI6gilXdA1UR+KjKNa6zgAgy2bAmijneXbAlNIvLCZyYZ2quKmt7Mz0vlJFoxpOqdoeqe4Hb4OToNuqMny4btpGkvrHF5lJMLgSvcCJZ X-Forefront-Antispam-Report: CIP:255.255.255.255;CTRY:;LANG:en;SCL:1;SRV:;IPV:NLI;SFV:NSPM;H:AM6PR04MB6053.eurprd04.prod.outlook.com;PTR:;CAT:NONE;SFS:(13230022)(4636009)(39860400002)(346002)(376002)(136003)(366004)(396003)(451199015)(2616005)(6506007)(52116002)(186003)(6512007)(86362001)(26005)(316002)(8676002)(1076003)(66946007)(4326008)(66556008)(66476007)(5660300002)(7416002)(41300700001)(478600001)(8936002)(38100700002)(38350700002)(83380400001)(6486002)(2906002);DIR:OUT;SFP:1101; X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-MessageData-0: =?utf-8?q?XYFfbLezBYzdWRWQ8mkpVXi0YSbZ?= =?utf-8?q?c0TpKBE8PDHzJxHnWRYItWLuF39M4xW5EGVrQaNQO8b1CAD99HRnI6/438kGVwKnm?= =?utf-8?q?SLFW3AtAXHZXaBx4jEHDaRCxuyeQPrYg5zfBfXLelKUrUc5j2tkeDOQsnFPrwfbKF?= =?utf-8?q?veFm8T0wtpPHhXGKhw/CbzA//O0kmr4nqORiunyFD8uskP2coNnhW/sRiT/Erbjq5?= =?utf-8?q?Xi2QjLiRsAHBCGs3xyGK67yJKcaLifdVGY53g6bJ71AOV/W8pQIfmd+zlPogdzw/J?= =?utf-8?q?Ooh5RqjYU7GZ2NELoQ65zutsGoIfhcS+z6Pzfzg4aiBgz+4OGlh/lNLI753QLseFu?= =?utf-8?q?z1OrBlZEkW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brqxbO3ZWAz6gbzJaP5xU/TQFsWvQjZ07p89rieYDaWQqrN?= =?utf-8?q?S01y68LPnGHRsCIp3g0/7MQSahuNfNh3Va3dJAeygGHNS4wiwg8s3HPwBxtTgsGvD?= =?utf-8?q?q7KmJfsGkwtLeehZhoJ+2PJ0z29xJYmBzhlxAuRpxcyUqtxwPfwoJ8wC/yCrB2Y1o?= =?utf-8?q?xoF8fZ6eJpsJk97AGP8ZFW3MipXw5j6ggz/youDBM/zbB+EJZrln3pkT6Z401x9Rd?= =?utf-8?q?DMlZAkONczJRID4/lA08I19Kq/tHECjEaBo5TcWEruyiWqi0BSBYXmWzL4RRzRW5N?= =?utf-8?q?uwsOROsKWFtp?= X-OriginatorOrg: oss.nxp.com X-MS-Exchange-CrossTenant-Network-Message-Id: 661adaa4-0a16-482a-425d-08daef063990 X-MS-Exchange-CrossTenant-AuthSource: AM6PR04MB6053.eurprd04.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 05 Jan 2023 10:18:44.2975 (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: qXWQ/NTVbO35Aw1YWAKdxJ1Z1URcUTWG6Wg3/sP6Wc4lEsN0Sl7fRC3TdPAT7i+UsVsbtsEUJO2N9cFn86b71g== X-MS-Exchange-Transport-CrossTenantHeadersStamped: DBBPR04MB7625 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20230105_021848_662551_E1BE09AE X-CRM114-Status: GOOD ( 20.23 ) X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.34 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+linux-arm-kernel=archiver.kernel.org@lists.infradead.org From: Alice Guo The procedure to program the calibration table of i.MX93 TMU: 1. disable monitoring mode 2. configure TCMCFG 3. write TTCFGR with TTCFGR[CAL_PT] = n 4. write TSCFGR with the sensor value of the calibration point n 5. write TTRCRn associated with the calibration point n Need to repeat steps 3—5 for all calibration points from the calibration table provided by the TMU device node. When TRITSR[V] = 1 and TRITSR[TP5] = 1, need to add 0.5K to TRITSR[TEMP]. IPBRR0s of lx2160ardb, lx2162aqds and i.MX93 have the same value 0x01900201 so that use the compatible to determine whether the current TMU belongs to i.MX93 or not. Signed-off-by: Alice Guo Reviewed-by: Jacky Bai Reviewed-by: Ye Li Acked-by: Jason Liu --- drivers/thermal/qoriq_thermal.c | 56 ++++++++++++++++++++++++++++++--- 1 file changed, 52 insertions(+), 4 deletions(-) diff --git a/drivers/thermal/qoriq_thermal.c b/drivers/thermal/qoriq_thermal.c index d111e218f362..18030bd68687 100644 --- a/drivers/thermal/qoriq_thermal.c +++ b/drivers/thermal/qoriq_thermal.c @@ -24,9 +24,11 @@ #define TMTMIR_DEFAULT 0x0000000f #define TIER_DISABLE 0x0 #define TEUMR0_V2 0x51009c00 +#define TEUMR0_V21 0x55010c00 #define TMSARA_V2 0xe #define TMU_VER1 0x1 #define TMU_VER2 0x2 +#define TMU_VER93 0x3 #define REGS_TMR 0x000 /* Mode Register */ #define TMR_DISABLE 0x0 @@ -52,6 +54,7 @@ * Site Register */ #define TRITSR_V BIT(31) +#define TRITSR_TP5 BIT(9) #define REGS_V2_TMSAR(n) (0x304 + 16 * (n)) /* TMU monitoring * site adjustment register */ @@ -114,10 +117,16 @@ static int tmu_get_temp(struct thermal_zone_device *tz, int *temp) 10 * USEC_PER_MSEC)) return -ENODATA; - if (qdata->ver == TMU_VER1) + if (qdata->ver == TMU_VER1) { *temp = (val & GENMASK(7, 0)) * MILLIDEGREE_PER_DEGREE; - else + } else if (qdata->ver == TMU_VER93) { + if (val & TRITSR_TP5) + *temp = milli_kelvin_to_millicelsius((val & GENMASK(8, 0)) * MILLIDEGREE_PER_DEGREE + 500); + else + *temp = kelvin_to_millicelsius(val & GENMASK(8, 0)); + } else { *temp = kelvin_to_millicelsius(val & GENMASK(8, 0)); + } return 0; } @@ -207,6 +216,33 @@ static int qoriq_tmu_calibration(struct device *dev, return 0; } +static int imx93_tmu_calibration(struct device *dev, + struct qoriq_tmu_data *data) +{ + const u32 *calibration = NULL; + u32 cal_pt = 0; + u32 val = 0; + unsigned int len = 0; + unsigned int i = 0; + + calibration = of_get_property(dev->of_node, "fsl,tmu-calibration", &len); + if (calibration == NULL || len / 8 > 16 || len % 8) { + dev_err(dev, "invalid tmu calibration\n"); + return -ENODEV; + } + + for (i = 0; i < len; i += 0x8, calibration += 2) { + cal_pt = i / 8; + regmap_write(data->regmap, REGS_TTCFGR, cal_pt); + val = of_read_number(calibration, 1); + regmap_write(data->regmap, REGS_TSCFGR, val); + val = of_read_number(calibration + 1, 1); + regmap_write(data->regmap, REGS_TTRnCR(cal_pt), val); + } + + return 0; +} + static void qoriq_tmu_init_device(struct qoriq_tmu_data *data) { int i; @@ -218,6 +254,11 @@ static void qoriq_tmu_init_device(struct qoriq_tmu_data *data) if (data->ver == TMU_VER1) { regmap_write(data->regmap, REGS_TMTMIR, TMTMIR_DEFAULT); + } else if (data->ver == TMU_VER93) { + regmap_write(data->regmap, REGS_V2_TMTMIR, TMTMIR_DEFAULT); + regmap_write(data->regmap, REGS_V2_TEUMR(0), TEUMR0_V21); + for (i = 0; i < SITES_MAX; i++) + regmap_write(data->regmap, REGS_V2_TMSAR(i), TMSARA_V2); } else { regmap_write(data->regmap, REGS_V2_TMTMIR, TMTMIR_DEFAULT); regmap_write(data->regmap, REGS_V2_TEUMR(0), TEUMR0_V2); @@ -231,7 +272,7 @@ static void qoriq_tmu_init_device(struct qoriq_tmu_data *data) static const struct regmap_range qoriq_yes_ranges[] = { regmap_reg_range(REGS_TMR, REGS_TSCFGR), - regmap_reg_range(REGS_TTRnCR(0), REGS_TTRnCR(3)), + regmap_reg_range(REGS_TTRnCR(0), REGS_TTRnCR(15)), regmap_reg_range(REGS_V2_TEUMR(0), REGS_V2_TEUMR(2)), regmap_reg_range(REGS_V2_TMSAR(0), REGS_V2_TMSAR(15)), regmap_reg_range(REGS_IPBRR(0), REGS_IPBRR(1)), @@ -319,9 +360,15 @@ static int qoriq_tmu_probe(struct platform_device *pdev) } data->ver = (ver >> 8) & 0xff; + if (of_find_compatible_node(NULL, NULL, "fsl,imx93-tmu")) + data->ver = TMU_VER93; + qoriq_tmu_init_device(data); /* TMU initialization */ - ret = qoriq_tmu_calibration(dev, data); /* TMU calibration */ + if (data->ver == TMU_VER93) + ret = imx93_tmu_calibration(dev, data); + else + ret = qoriq_tmu_calibration(dev, data); /* TMU calibration */ if (ret < 0) return ret; @@ -369,6 +416,7 @@ static SIMPLE_DEV_PM_OPS(qoriq_tmu_pm_ops, static const struct of_device_id qoriq_tmu_match[] = { { .compatible = "fsl,qoriq-tmu", }, { .compatible = "fsl,imx8mq-tmu", }, + { .compatible = "fsl,imx93-tmu", }, {}, }; MODULE_DEVICE_TABLE(of, qoriq_tmu_match);