Received: by 10.223.176.46 with SMTP id f43csp2629703wra; Mon, 22 Jan 2018 00:25:54 -0800 (PST) X-Google-Smtp-Source: AH8x224QxvYBJwj6fTlI4qFvOdu9S36AMKSRvtHD2B8VwTsmx4ceJ+6eJ0/w7CZB7YqGtpqjA8ld X-Received: by 10.98.158.89 with SMTP id s86mr7789710pfd.203.1516609554672; Mon, 22 Jan 2018 00:25:54 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1516609554; cv=none; d=google.com; s=arc-20160816; b=XuXvbflBFDY5Q6sfyYHineX491nITWCalD+B2l4ZrVz8E8Z36ccntadS18G8zek51m VGVFqvjpsVUme9TWb6CNCksBfweZOqJDXuecqZRwHb8VZGhn1CsTSCdAY8p6OotKMpmw adFTK/81mayjATbg5utYH8s2ZGRZbLzls8yv1yBODEVEfaRk4T1fIdSVFsSKaCmxU5pg resfH4UhSxYjvmJx4k2Pu+JAzRBok6BTt0dS5AqPvQU+iwWPX7MdPMIGJuHvncpKnGF/ epmD1mRRq0ioSxDXcb7lF3Hk56Qc09w4sbI8gMrG7wBO2zMsx3TBogKtb5XmVH2Q91L5 MYhA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:spamdiagnosticmetadata :spamdiagnosticoutput:mime-version:references:in-reply-to:message-id :date:subject:cc:to:from:arc-authentication-results; bh=3EaKfGsF9gpZ9JRhTDY4fp0D4SmqpYSgmIkRDX348IQ=; b=guA6d3xZMr3Zj7CK9S5LS66uqgNzIMVhxKBDuhujvuDpysFlP5TFJRZnhNvVecsvC2 35c88MKf5S/juUXaqInzXGh7oJ2vARg49F/P3GLOWsyFFygQkDTU0mwufKyNKHk1mnBO ddxPRrpVzaj1q42qtXSTJ93GJljwtEj1i/8ZPysJSQNcCfRcR3yz5oUCUagKs2xzGIBW AEQ00YNq0lUTy9vB2nWu/7qPy4tuOesUzE/cXqRzXAQXENoMYZssG38DxbdgSp3dAjPi LfxykcKqK8RG3I7mJJ+rCDsFZxmgBuYtIg1D3QYR1t+MMFzvpwPNy1RkHhVzl7KMHY49 NCGA== 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 i1-v6si3176785pll.411.2018.01.22.00.25.40; Mon, 22 Jan 2018 00:25:54 -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 S1751140AbeAVIY4 (ORCPT + 99 others); Mon, 22 Jan 2018 03:24:56 -0500 Received: from mail-sn1nam02on0067.outbound.protection.outlook.com ([104.47.36.67]:52902 "EHLO NAM02-SN1-obe.outbound.protection.outlook.com" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S1751028AbeAVIYw (ORCPT ); Mon, 22 Jan 2018 03:24:52 -0500 Received: from CY4PR03CA0021.namprd03.prod.outlook.com (10.168.162.31) by CY1PR03MB2361.namprd03.prod.outlook.com (10.166.207.148) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_CBC_SHA384_P256) id 15.20.428.17; Mon, 22 Jan 2018 08:24:50 +0000 Received: from BL2FFO11OLC009.protection.gbl (2a01:111:f400:7c09::183) by CY4PR03CA0021.outlook.office365.com (2603:10b6:903:33::31) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_CBC_SHA384) id 15.20.428.17 via Frontend Transport; Mon, 22 Jan 2018 08:24:50 +0000 Authentication-Results: spf=fail (sender IP is 192.88.168.50) smtp.mailfrom=nxp.com; vger.kernel.org; dkim=none (message not signed) header.d=none;vger.kernel.org; dmarc=fail action=none header.from=nxp.com; Received-SPF: Fail (protection.outlook.com: domain of nxp.com does not designate 192.88.168.50 as permitted sender) receiver=protection.outlook.com; client-ip=192.88.168.50; helo=tx30smr01.am.freescale.net; Received: from tx30smr01.am.freescale.net (192.88.168.50) by BL2FFO11OLC009.mail.protection.outlook.com (10.173.160.145) with Microsoft SMTP Server (version=TLS1_0, cipher=TLS_RSA_WITH_AES_256_CBC_SHA) id 15.20.428.12 via Frontend Transport; Mon, 22 Jan 2018 08:24:49 +0000 Received: from shlinux2.ap.freescale.net (shlinux2.ap.freescale.net [10.192.224.44]) by tx30smr01.am.freescale.net (8.14.3/8.14.0) with ESMTP id w0M7QR73021564; Mon, 22 Jan 2018 00:26:33 -0700 From: Anson Huang To: , , , , , , , , CC: , , , , , Subject: [PATCH 2/2] thermal: imx: add i.MX7 thermal sensor support Date: Mon, 22 Jan 2018 15:25:49 +0800 Message-ID: <1516605949-14663-2-git-send-email-Anson.Huang@nxp.com> X-Mailer: git-send-email 1.9.1 In-Reply-To: <1516605949-14663-1-git-send-email-Anson.Huang@nxp.com> References: <1516605949-14663-1-git-send-email-Anson.Huang@nxp.com> X-EOPAttributedMessage: 0 X-Matching-Connectors: 131610830906903497;(91ab9b29-cfa4-454e-5278-08d120cd25b8);() X-Forefront-Antispam-Report: CIP:192.88.168.50;IPV:NLI;CTRY:US;EFV:NLI;SFV:NSPM;SFS:(10009020)(39380400002)(39860400002)(396003)(346002)(376002)(2980300002)(1109001)(1110001)(339900001)(189003)(199004)(2950100002)(16586007)(50466002)(48376002)(316002)(110136005)(104016004)(356003)(105606002)(36756003)(305945005)(106466001)(5660300001)(6636002)(54906003)(6666003)(450100002)(81166006)(68736007)(85426001)(76176011)(498600001)(26005)(97736004)(47776003)(51416003)(2201001)(72206003)(4326008)(50226002)(77096007)(8676002)(8936002)(2906002)(81156014)(86362001)(53936002)(59450400001)(336011);DIR:OUT;SFP:1101;SCL:1;SRVR:CY1PR03MB2361;H:tx30smr01.am.freescale.net;FPR:;SPF:Fail;PTR:InfoDomainNonexistent;MX:1;A:1;LANG:en; X-Microsoft-Exchange-Diagnostics: 1;BL2FFO11OLC009;1:2ksvCyjHusorAQShlKv0vGfBQZi/Mim9FR/H8lgQFiPhqPBEJHmPH46Z/NJ5oVnuN1bstmhiv/PyYF4EuaefNThXi6yZdDkV31eVDeAb9HwBP456aiZZN9zmsVQW+Zew MIME-Version: 1.0 Content-Type: text/plain X-MS-PublicTrafficType: Email X-MS-Office365-Filtering-Correlation-Id: 0190fbe8-73af-4283-cbc9-08d561719b43 X-Microsoft-Antispam: UriScan:;BCL:0;PCL:0;RULEID:(7020095)(5600026)(4604075)(2017052603307);SRVR:CY1PR03MB2361; X-Microsoft-Exchange-Diagnostics: 1;CY1PR03MB2361;3:UDddCnO0o/XiUHTI4OYiBhpjyPSc+G4SgC8ed/ar5fl8C3dWkxGohY1AvVpFT8I0dO/oX6dr3xAIWNpqKyiAFF03E22qYTnqUJHNfDtUAcrqlsxTiJW3OLmjat90idps99rAmRJKTgT4kDk3E2Nx1TUvNmSZ3jKskM4swWgSd2DmvvqvJvtH0wNkRyBVabir9QFP/2bStt5YmWAywkBhoiC7rr3RqrzGVfyv/frCN7O0ZyV0mc4JCjRFJwOuCSe7nr66IqyBUxf5pGocpu5WhOsr/TsScwFOMtxWcJ3zf0G+ODtiS4ri6JlEyqhbNVW1ffCVD2z7cHtiL/m3AwG4YMG9fBtq/XfTYRw90PS/j5o=;25:zWOZcJOLMd9RrEfChxEGvqoMr1N+xst9I/4NBL5xtKmoHnmPVyME/8GiAXohMOv5o4T5C9Uw6Fm0ZqkTiFQ4FT/sYYhgK67apPcilhjS8Yz/Vm+SHl8gS/aTsMstLz16KMOKgOpzUmvQRJYZD4Rx182uQGiliqEyEp0+Npadb3hirSGOxRdnShVcUliHiuyGOpRCA4TKvlj4a3ciOm7Lczl1ax5NJutgP/PR4c5odWgQet/K4qOBT0FR3gxv7Qk8xi7PDTB59WtDvt5djBUTaHkN4X0FoAG21sbdQwo+958q8NbVLC/NTZZC7HLZhe6oMk/PZ0AMKOYa4isXgOK1fA== X-MS-TrafficTypeDiagnostic: CY1PR03MB2361: X-Microsoft-Exchange-Diagnostics: 1;CY1PR03MB2361;31:nvis1JI0SORH4C/bfXgRtwOx9n+fPvzjaPAjdDHgAOYI+bwUOoCcuHhoNgGCKwXs90dctMbXk4pIiwkBGjw7h2rPeIsUP7af4gdUNWzGbzPp1C4/d8zd3+cR6dJYgNvVyKFro70tK1L29PBBH8nmgtqm/TLE97z7t4sXG5FNLRxJS3xH/TkA/QI6Itdq2bWyODpg5lJVUH41+zn6dn58yxd7Uv6VZGJgRqEq7CKVrSg=;4:ytEiBjUGPxaQzsMGyM2dOCNvTVG68egTBNiqz0f5qNtQxkuMfluJhVIID1R9vX4KqX220lgMryA8WlQ54pYuoZefWnToirZv8IwTHHdifOcMeYxLEelj0dCrKGKLN/VOrT2PpKo5MxFWxffJdmSmxLHSkU0GbYKp9By1+Tz8z/5/Ajic6H1mwCxczrKzcwAn77WigB+Jl/2O2Qs0xOchdF0w4kdpJsORAFp65FhtkPYFp5zXxrMLwGxtRWjLn24o3sVWbIhLIPQiCrJHs6qErOuwbEGWQHR8u25KZPp+6j8ysZ4/CxG31mhd2Yf+k0kr X-Microsoft-Antispam-PRVS: X-Exchange-Antispam-Report-Test: UriScan:(185117386973197); X-Exchange-Antispam-Report-CFA-Test: BCL:0;PCL:0;RULEID:(6095135)(2401047)(5005006)(8121501046)(3231023)(2400081)(944501161)(93006095)(93001095)(10201501046)(3002001)(6055026)(6096035)(20161123563025)(20161123559100)(201703131430075)(201703131433075)(201703131448075)(201703151042153)(20161123556025)(20161123561025)(20161123565025)(201708071742011);SRVR:CY1PR03MB2361;BCL:0;PCL:0;RULEID:(100000803101)(100110400095)(400006);SRVR:CY1PR03MB2361; X-Forefront-PRVS: 0560A2214D X-Microsoft-Exchange-Diagnostics: =?us-ascii?Q?1;CY1PR03MB2361;23:i5KG1oOdYgkhEksLW1g5AweaGzONwHsUHVC3x0ffW?= =?us-ascii?Q?ZBRkPHNFMRN2cWRqWK8xNiAmYofXe+owWzBQgsMPOGs/MG2FwYPsfSmMJNHm?= =?us-ascii?Q?Jakomn6jD400jr/e7fmYsq3LpNwzuhDb/gK9mBn+3/+aHT0bTlkkphezL/fV?= =?us-ascii?Q?Ll5BJfZVVXfqiVoqLYxMl8axNSm9YcH5+Au2J0lp7m3jha7FXme7lWqR/dFt?= =?us-ascii?Q?Fx3ZYk5X2DeM20VpJQShRFrJLhXj+uq3Mw1kwB2QS5HVH49rR2Xnu8cK/rQa?= =?us-ascii?Q?GVrX/X1cYTPyZnd3QsmCRu6VCR8k7VnN8dK3E5sKWBDhuqt6D7nI9JWSrbW5?= =?us-ascii?Q?HJh2ygrFuPwVL6+Y6zHlRJtr1jY/EjCayjYWxJ0jdBras1PWnk/VtNReKnkO?= =?us-ascii?Q?ODnTau7zuEPsPaO5j8V5j/sphiZ9Okj8tvERXJFiopmUfxfGJNKlvY5ndzrJ?= =?us-ascii?Q?bca1AkfJbwwM+WBBEh6+Ls7IRk1WEPW5awZykHAXniwb0lhwgywaU4KYT+/r?= =?us-ascii?Q?aqNKBMBsauodUF0Tc5YVGn9lgKB047yhJZOCtK2I19drI1l8K6eisdjIgeaR?= =?us-ascii?Q?K/EBmjtMm5N/gvTUvG6NP2PhpQZDDcDJt3oSq2EycpBc3D0J0mu7SrezAoD0?= =?us-ascii?Q?LpAw1xTJE+6Y6PeUnrvGJTm4maF9cvw6cNReSY3YuQgU6E84bK3I4prSR2Oy?= =?us-ascii?Q?RlFlE2dbNOSxyrPCEvh+kcRmG8P1GDHYqanXgJAPq3pymffDP/9P5gn/mfZ1?= =?us-ascii?Q?0t9etT71tkiApzwMWyLFqBVSyaThHtHXvuEJo91ABNWsvAep1Vvul+9oua+X?= =?us-ascii?Q?czAnmUdYgYmPuD2HECD9vRZ1WtJcHkya0u1ihfqoKxHK5K5s/G5zVJgUjN2+?= =?us-ascii?Q?Nn01VpQKoHCyrM0nfRcFbLwnTFLW2hcVBIjEk3blA3ezXwkKvnUxKrNPAh8v?= =?us-ascii?Q?zEuGfy2NKFGcVD35al4WQFk6pbkCy0kHkowSFTIYzCked/1tT2rs42W+NLV2?= =?us-ascii?Q?PQHhV7bt/8kETbr9uzvglvbOnbRZEzkWPzadsnFGCXSo87TOpzIqTlC12xI1?= =?us-ascii?Q?d6kvL8BGQxSh6IM9N6eyx+62ABmYYRfDQIU2J6FCqLEE3N7GaPh9U2zhMu0A?= =?us-ascii?Q?fOweW+OXxWrSlrk6lr7uFJP8J/OpX0RlRevGigSsElCwimgQX6Yzg=3D=3D?= X-Microsoft-Exchange-Diagnostics: 1;CY1PR03MB2361;6:HGT5CDs+c2LItxwTuZYYuq1IR++jFtibL6KI/7BKI4sgAcFlCkvkIZPS/nVOXjhp+6A13zQo244zfaP6L0qjJV/LVwKr2+VdK5ariGG5EYTmUNZbMofb1HkerkIVaqRobvxU4SXk1XCB75OFIfMajfxMscS87U5RYT1SNnqIb1n+Q8bJkoGLvUjz6T3RPU2cpr0DcUyeaTWtzeGUboK7gxIjyiz9lt/CMkcRyCBWXXIJK3qMrKcCIhLu0a5B3FVkbInmaP/z84mR9oDzmuHml+g0FtWmdu27OVA3Vb0+6g5faSD9+R7zIwDh93nA/yXtmiVCeZk6EdPWynaYGWyzWDDbj/SxyXVNqne7s7kZIEA=;5:M04Sj/CFsddtyB+IJi6hcaORpXrBmKJPsH69SOeRlhXUioUhWgU+3tV0xIjgax/p2DRO0uO9bJAL8WCfMSvXmkq9bxNruDBVVWQAEggrs71xoT2sKqpKMdAPxmh0l/5CJaAoJ32svTjkCBnfPXPXYLeNH5EMBAa41OM/ZXsUB+k=;24:Ms1ggd77GHQR7fZsVF9cxU3W4wGHnEnHS99UAQ6xUMwyR+lyRHIvdgiekjQ1/o8QjDkWFQSZ+XDxLZFvuTwIeOA053uOY2BchHOKbtsj1HY=;7:rCljDBjnU9TNfkAOff1C3CszcGLp2fwwlEWJpKKQS6s9SOfra4vabKXq3v8DBH1FiKlysLIRfLd0oU9uWsJ2R+KE107tW/3Q4ylErlzEEO49dMXQLspS/J9NpCzCKAXxPeawjVRI2LXRVq4psfZtLKMIkTVoViDUQnHErqqYkMWc+nTFswzXIzPw1uihiNIlzYAZ1Ch7Wa9BLXt2R2QrnBJy0te6CR752fXjQrQP0+mplvzLyzMf+8LhzyYJ6IeM SpamDiagnosticOutput: 1:99 SpamDiagnosticMetadata: NSPM X-MS-Exchange-CrossTenant-OriginalArrivalTime: 22 Jan 2018 08:24:49.2551 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: 0190fbe8-73af-4283-cbc9-08d561719b43 X-MS-Exchange-CrossTenant-Id: 5afe0b00-7697-4969-b663-5eab37d5f47e X-MS-Exchange-CrossTenant-OriginalAttributedTenantConnectingIp: TenantId=5afe0b00-7697-4969-b663-5eab37d5f47e;Ip=[192.88.168.50];Helo=[tx30smr01.am.freescale.net] X-MS-Exchange-CrossTenant-FromEntityHeader: HybridOnPrem X-MS-Exchange-Transport-CrossTenantHeadersStamped: CY1PR03MB2361 Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org This patch adds i.MX7 thermal sensor support, most of the i.MX7 thermal sensor functions are same with i.MX6 except the registers offset/layout, so we move those registers offset/layout definitions to soc data structure. i.MX7 uses single calibration data @25C, the calibration data is located at OCOTP offset 0x4F0, bit[17:9], the formula is as below: Tmeas = (Nmeas - n1) + 25; n1 is the fuse value for 25C. Signed-off-by: Anson Huang Signed-off-by: Bai Ping --- drivers/thermal/imx_thermal.c | 315 +++++++++++++++++++++++++++++++++--------- 1 file changed, 247 insertions(+), 68 deletions(-) diff --git a/drivers/thermal/imx_thermal.c b/drivers/thermal/imx_thermal.c index e7d4ffc..b2a00d6 100644 --- a/drivers/thermal/imx_thermal.c +++ b/drivers/thermal/imx_thermal.c @@ -31,34 +31,58 @@ #define REG_CLR 0x8 #define REG_TOG 0xc -#define MISC0 0x0150 -#define MISC0_REFTOP_SELBIASOFF (1 << 3) -#define MISC1 0x0160 -#define MISC1_IRQ_TEMPHIGH (1 << 29) +/* i.MX6 specific */ +#define IMX6_MISC0 0x0150 +#define IMX6_MISC0_REFTOP_SELBIASOFF (1 << 3) +#define IMX6_MISC1 0x0160 +#define IMX6_MISC1_IRQ_TEMPHIGH (1 << 29) /* Below LOW and PANIC bits are only for TEMPMON_IMX6SX */ -#define MISC1_IRQ_TEMPLOW (1 << 28) -#define MISC1_IRQ_TEMPPANIC (1 << 27) - -#define TEMPSENSE0 0x0180 -#define TEMPSENSE0_ALARM_VALUE_SHIFT 20 -#define TEMPSENSE0_ALARM_VALUE_MASK (0xfff << TEMPSENSE0_ALARM_VALUE_SHIFT) -#define TEMPSENSE0_TEMP_CNT_SHIFT 8 -#define TEMPSENSE0_TEMP_CNT_MASK (0xfff << TEMPSENSE0_TEMP_CNT_SHIFT) -#define TEMPSENSE0_FINISHED (1 << 2) -#define TEMPSENSE0_MEASURE_TEMP (1 << 1) -#define TEMPSENSE0_POWER_DOWN (1 << 0) - -#define TEMPSENSE1 0x0190 -#define TEMPSENSE1_MEASURE_FREQ 0xffff -/* Below TEMPSENSE2 is only for TEMPMON_IMX6SX */ -#define TEMPSENSE2 0x0290 -#define TEMPSENSE2_LOW_VALUE_SHIFT 0 -#define TEMPSENSE2_LOW_VALUE_MASK 0xfff -#define TEMPSENSE2_PANIC_VALUE_SHIFT 16 -#define TEMPSENSE2_PANIC_VALUE_MASK 0xfff0000 +#define IMX6_MISC1_IRQ_TEMPLOW (1 << 28) +#define IMX6_MISC1_IRQ_TEMPPANIC (1 << 27) + +#define IMX6_TEMPSENSE0 0x0180 +#define IMX6_TEMPSENSE0_ALARM_VALUE_SHIFT 20 +#define IMX6_TEMPSENSE0_ALARM_VALUE_MASK (0xfff << 20) +#define IMX6_TEMPSENSE0_TEMP_CNT_SHIFT 8 +#define IMX6_TEMPSENSE0_TEMP_CNT_MASK (0xfff << 8) +#define IMX6_TEMPSENSE0_FINISHED (1 << 2) +#define IMX6_TEMPSENSE0_MEASURE_TEMP (1 << 1) +#define IMX6_TEMPSENSE0_POWER_DOWN (1 << 0) + +#define IMX6_TEMPSENSE1 0x0190 +#define IMX6_TEMPSENSE1_MEASURE_FREQ 0xffff +#define IMX6_TEMPSENSE1_MEASURE_FREQ_SHIFT 0 -#define OCOTP_MEM0 0x0480 -#define OCOTP_ANA1 0x04e0 +/* Below TEMPSENSE2 is only for TEMPMON_IMX6SX */ +#define IMX6_TEMPSENSE2 0x0290 +#define IMX6_TEMPSENSE2_LOW_VALUE_SHIFT 0 +#define IMX6_TEMPSENSE2_LOW_VALUE_MASK 0xfff +#define IMX6_TEMPSENSE2_PANIC_VALUE_SHIFT 16 +#define IMX6_TEMPSENSE2_PANIC_VALUE_MASK 0xfff0000 + +/* i.MX7 specific */ +#define IMX7_ANADIG_DIGPROG 0x800 +#define IMX7_TEMPSENSE0 0x300 +#define IMX7_TEMPSENSE0_PANIC_ALARM_SHIFT 18 +#define IMX7_TEMPSENSE0_PANIC_ALARM_MASK (0x1ff << 18) +#define IMX7_TEMPSENSE0_HIGH_ALARM_SHIFT 9 +#define IMX7_TEMPSENSE0_HIGH_ALARM_MASK (0x1ff << 9) +#define IMX7_TEMPSENSE0_LOW_ALARM_SHIFT 0 +#define IMX7_TEMPSENSE0_LOW_ALARM_MASK 0x1ff + +#define IMX7_TEMPSENSE1 0x310 +#define IMX7_TEMPSENSE1_MEASURE_FREQ_SHIFT 16 +#define IMX7_TEMPSENSE1_MEASURE_FREQ_MASK (0xffff << 16) +#define IMX7_TEMPSENSE1_FINISHED (1 << 11) +#define IMX7_TEMPSENSE1_MEASURE_TEMP (1 << 10) +#define IMX7_TEMPSENSE1_POWER_DOWN (1 << 9) +#define IMX7_TEMPSENSE1_TEMP_VALUE_SHIFT 0 +#define IMX7_TEMPSENSE1_TEMP_VALUE_MASK 0x1ff + +#define IMX6_OCOTP_MEM0 0x0480 +#define IMX6_OCOTP_ANA1 0x04e0 +#define IMX7_OCOTP_TESTER3 0x0440 +#define IMX7_OCOTP_ANA1 0x04f0 /* The driver supports 1 passive trip point and 1 critical trip point */ enum imx_thermal_trip { @@ -76,17 +100,110 @@ enum imx_thermal_trip { #define TEMPMON_IMX6Q 1 #define TEMPMON_IMX6SX 2 +#define TEMPMON_IMX7 3 struct thermal_soc_data { u32 version; + + u32 sensor_ctrl; + u32 power_down_mask; + u32 measure_temp_mask; + + u32 measure_freq_ctrl; + u32 measure_freq_mask; + u32 measure_freq_shift; + + u32 temp_data; + u32 temp_value_mask; + u32 temp_value_shift; + u32 temp_valid_mask; + + u32 panic_alarm_ctrl; + u32 panic_alarm_mask; + u32 panic_alarm_shift; + + u32 high_alarm_ctrl; + u32 high_alarm_mask; + u32 high_alarm_shift; + + u32 low_alarm_ctrl; + u32 low_alarm_mask; + u32 low_alarm_shift; }; static struct thermal_soc_data thermal_imx6q_data = { .version = TEMPMON_IMX6Q, + + .sensor_ctrl = IMX6_TEMPSENSE0, + .power_down_mask = IMX6_TEMPSENSE0_POWER_DOWN, + .measure_temp_mask = IMX6_TEMPSENSE0_MEASURE_TEMP, + + .measure_freq_ctrl = IMX6_TEMPSENSE1, + .measure_freq_shift = IMX6_TEMPSENSE1_MEASURE_FREQ_SHIFT, + .measure_freq_mask = IMX6_TEMPSENSE1_MEASURE_FREQ, + + .temp_data = IMX6_TEMPSENSE0, + .temp_value_mask = IMX6_TEMPSENSE0_TEMP_CNT_MASK, + .temp_value_shift = IMX6_TEMPSENSE0_TEMP_CNT_SHIFT, + .temp_valid_mask = IMX6_TEMPSENSE0_FINISHED, + + .high_alarm_ctrl = IMX6_TEMPSENSE0, + .high_alarm_mask = IMX6_TEMPSENSE0_ALARM_VALUE_MASK, + .high_alarm_shift = IMX6_TEMPSENSE0_ALARM_VALUE_SHIFT, }; static struct thermal_soc_data thermal_imx6sx_data = { .version = TEMPMON_IMX6SX, + + .sensor_ctrl = IMX6_TEMPSENSE0, + .power_down_mask = IMX6_TEMPSENSE0_POWER_DOWN, + .measure_temp_mask = IMX6_TEMPSENSE0_MEASURE_TEMP, + + .measure_freq_ctrl = IMX6_TEMPSENSE1, + .measure_freq_shift = IMX6_TEMPSENSE1_MEASURE_FREQ_SHIFT, + .measure_freq_mask = IMX6_TEMPSENSE1_MEASURE_FREQ, + + .temp_data = IMX6_TEMPSENSE0, + .temp_value_mask = IMX6_TEMPSENSE0_TEMP_CNT_MASK, + .temp_value_shift = IMX6_TEMPSENSE0_TEMP_CNT_SHIFT, + .temp_valid_mask = IMX6_TEMPSENSE0_FINISHED, + + .high_alarm_ctrl = IMX6_TEMPSENSE0, + .high_alarm_mask = IMX6_TEMPSENSE0_ALARM_VALUE_MASK, + .high_alarm_shift = IMX6_TEMPSENSE0_ALARM_VALUE_SHIFT, + + .panic_alarm_ctrl = IMX6_TEMPSENSE2, + .panic_alarm_mask = IMX6_TEMPSENSE2_PANIC_VALUE_MASK, + .panic_alarm_shift = IMX6_TEMPSENSE2_PANIC_VALUE_SHIFT, +}; + +static struct thermal_soc_data thermal_imx7_data = { + .version = TEMPMON_IMX7, + + .sensor_ctrl = IMX7_TEMPSENSE1, + .power_down_mask = IMX7_TEMPSENSE1_POWER_DOWN, + .measure_temp_mask = IMX7_TEMPSENSE1_MEASURE_TEMP, + + .measure_freq_ctrl = IMX7_TEMPSENSE1, + .measure_freq_shift = IMX7_TEMPSENSE1_MEASURE_FREQ_SHIFT, + .measure_freq_mask = IMX7_TEMPSENSE1_MEASURE_FREQ_MASK, + + .temp_data = IMX7_TEMPSENSE1, + .temp_value_mask = IMX7_TEMPSENSE1_TEMP_VALUE_MASK, + .temp_value_shift = IMX7_TEMPSENSE1_TEMP_VALUE_SHIFT, + .temp_valid_mask = IMX7_TEMPSENSE1_FINISHED, + + .panic_alarm_ctrl = IMX7_TEMPSENSE1, + .panic_alarm_mask = IMX7_TEMPSENSE0_PANIC_ALARM_MASK, + .panic_alarm_shift = IMX7_TEMPSENSE0_PANIC_ALARM_SHIFT, + + .high_alarm_ctrl = IMX7_TEMPSENSE0, + .high_alarm_mask = IMX7_TEMPSENSE0_HIGH_ALARM_MASK, + .high_alarm_shift = IMX7_TEMPSENSE0_HIGH_ALARM_SHIFT, + + .low_alarm_ctrl = IMX7_TEMPSENSE0, + .low_alarm_mask = IMX7_TEMPSENSE0_LOW_ALARM_MASK, + .low_alarm_shift = IMX7_TEMPSENSE0_LOW_ALARM_SHIFT, }; struct imx_thermal_data { @@ -112,30 +229,44 @@ static void imx_set_panic_temp(struct imx_thermal_data *data, int panic_temp) { struct regmap *map = data->tempmon; + const struct thermal_soc_data *soc_data = data->socdata; int critical_value; - critical_value = (data->c2 - panic_temp) / data->c1; - regmap_write(map, TEMPSENSE2 + REG_CLR, TEMPSENSE2_PANIC_VALUE_MASK); - regmap_write(map, TEMPSENSE2 + REG_SET, critical_value << - TEMPSENSE2_PANIC_VALUE_SHIFT); + if (data->socdata->version == TEMPMON_IMX7) + critical_value = panic_temp / 1000 + data->c1 - 25; + else + critical_value = (data->c2 - panic_temp) / data->c1; + + regmap_write(map, soc_data->panic_alarm_ctrl + REG_CLR, + soc_data->panic_alarm_mask); + regmap_write(map, soc_data->panic_alarm_ctrl + REG_SET, + critical_value << soc_data->panic_alarm_shift); } static void imx_set_alarm_temp(struct imx_thermal_data *data, int alarm_temp) { struct regmap *map = data->tempmon; + const struct thermal_soc_data *soc_data = data->socdata; int alarm_value; data->alarm_temp = alarm_temp; - alarm_value = (data->c2 - alarm_temp) / data->c1; - regmap_write(map, TEMPSENSE0 + REG_CLR, TEMPSENSE0_ALARM_VALUE_MASK); - regmap_write(map, TEMPSENSE0 + REG_SET, alarm_value << - TEMPSENSE0_ALARM_VALUE_SHIFT); + + if (data->socdata->version == TEMPMON_IMX7) + alarm_value = alarm_temp / 1000 + data->c1 - 25; + else + alarm_value = (data->c2 - alarm_temp) / data->c1; + + regmap_write(map, soc_data->high_alarm_ctrl + REG_CLR, + soc_data->high_alarm_mask); + regmap_write(map, soc_data->high_alarm_ctrl + REG_SET, + alarm_value << soc_data->high_alarm_shift); } static int imx_get_temp(struct thermal_zone_device *tz, int *temp) { struct imx_thermal_data *data = tz->devdata; + const struct thermal_soc_data *soc_data = data->socdata; struct regmap *map = data->tempmon; unsigned int n_meas; bool wait; @@ -143,16 +274,18 @@ static int imx_get_temp(struct thermal_zone_device *tz, int *temp) if (data->mode == THERMAL_DEVICE_ENABLED) { /* Check if a measurement is currently in progress */ - regmap_read(map, TEMPSENSE0, &val); - wait = !(val & TEMPSENSE0_FINISHED); + regmap_read(map, soc_data->temp_data, &val); + wait = !(val & soc_data->temp_valid_mask); } else { /* * Every time we measure the temperature, we will power on the * temperature sensor, enable measurements, take a reading, * disable measurements, power off the temperature sensor. */ - regmap_write(map, TEMPSENSE0 + REG_CLR, TEMPSENSE0_POWER_DOWN); - regmap_write(map, TEMPSENSE0 + REG_SET, TEMPSENSE0_MEASURE_TEMP); + regmap_write(map, soc_data->sensor_ctrl + REG_CLR, + soc_data->power_down_mask); + regmap_write(map, soc_data->sensor_ctrl + REG_SET, + soc_data->measure_temp_mask); wait = true; } @@ -164,22 +297,28 @@ static int imx_get_temp(struct thermal_zone_device *tz, int *temp) if (wait) usleep_range(20, 50); - regmap_read(map, TEMPSENSE0, &val); + regmap_read(map, soc_data->temp_data, &val); if (data->mode != THERMAL_DEVICE_ENABLED) { - regmap_write(map, TEMPSENSE0 + REG_CLR, TEMPSENSE0_MEASURE_TEMP); - regmap_write(map, TEMPSENSE0 + REG_SET, TEMPSENSE0_POWER_DOWN); + regmap_write(map, soc_data->sensor_ctrl + REG_CLR, + soc_data->measure_temp_mask); + regmap_write(map, soc_data->sensor_ctrl + REG_SET, + soc_data->power_down_mask); } - if ((val & TEMPSENSE0_FINISHED) == 0) { + if ((val & soc_data->temp_valid_mask) == 0) { dev_dbg(&tz->device, "temp measurement never finished\n"); return -EAGAIN; } - n_meas = (val & TEMPSENSE0_TEMP_CNT_MASK) >> TEMPSENSE0_TEMP_CNT_SHIFT; + n_meas = (val & soc_data->temp_value_mask) + >> soc_data->temp_value_shift; /* See imx_init_calib() for formula derivation */ - *temp = data->c2 - n_meas * data->c1; + if (data->socdata->version == TEMPMON_IMX7) + *temp = (n_meas - data->c1 + 25) * 1000; + else + *temp = data->c2 - n_meas * data->c1; /* Update alarm value to next higher trip point for TEMPMON_IMX6Q */ if (data->socdata->version == TEMPMON_IMX6Q) { @@ -223,21 +362,26 @@ static int imx_set_mode(struct thermal_zone_device *tz, { struct imx_thermal_data *data = tz->devdata; struct regmap *map = data->tempmon; + const struct thermal_soc_data *soc_data = data->socdata; if (mode == THERMAL_DEVICE_ENABLED) { tz->polling_delay = IMX_POLLING_DELAY; tz->passive_delay = IMX_PASSIVE_DELAY; - regmap_write(map, TEMPSENSE0 + REG_CLR, TEMPSENSE0_POWER_DOWN); - regmap_write(map, TEMPSENSE0 + REG_SET, TEMPSENSE0_MEASURE_TEMP); + regmap_write(map, soc_data->sensor_ctrl + REG_CLR, + soc_data->power_down_mask); + regmap_write(map, soc_data->sensor_ctrl + REG_SET, + soc_data->measure_temp_mask); if (!data->irq_enabled) { data->irq_enabled = true; enable_irq(data->irq); } } else { - regmap_write(map, TEMPSENSE0 + REG_CLR, TEMPSENSE0_MEASURE_TEMP); - regmap_write(map, TEMPSENSE0 + REG_SET, TEMPSENSE0_POWER_DOWN); + regmap_write(map, soc_data->sensor_ctrl + REG_CLR, + soc_data->measure_temp_mask); + regmap_write(map, soc_data->sensor_ctrl + REG_SET, + soc_data->power_down_mask); tz->polling_delay = 0; tz->passive_delay = 0; @@ -359,6 +503,15 @@ static int imx_init_calib(struct platform_device *pdev, u32 val) } /* + * On i.MX7, we only use the calibration data at 25C to get the temp, + * Tmeas = ( Nmeas - n1) + 25; n1 is the fuse value for 25C. + */ + if (data->socdata->version == TEMPMON_IMX7) { + data->c1 = (val >> 9) & 0x1ff; + return 0; + } + + /* * Sensor data layout: * [31:20] - sensor value @ 25C * Use universal formula now and only need sensor value @ 25C @@ -426,6 +579,7 @@ static void imx_init_temp_grade(struct platform_device *pdev, u32 val) static int imx_init_from_tempmon_data(struct platform_device *pdev) { + struct imx_thermal_data *data = platform_get_drvdata(pdev); struct regmap *map; int ret; u32 val; @@ -438,7 +592,11 @@ static int imx_init_from_tempmon_data(struct platform_device *pdev) return ret; } - ret = regmap_read(map, OCOTP_ANA1, &val); + if (data->socdata->version == TEMPMON_IMX7) + ret = regmap_read(map, IMX7_OCOTP_ANA1, &val); + else + ret = regmap_read(map, IMX6_OCOTP_ANA1, &val); + if (ret) { dev_err(&pdev->dev, "failed to read sensor data: %d\n", ret); return ret; @@ -447,7 +605,11 @@ static int imx_init_from_tempmon_data(struct platform_device *pdev) if (ret) return ret; - ret = regmap_read(map, OCOTP_MEM0, &val); + /* use OTP for thermal grade */ + if (data->socdata->version == TEMPMON_IMX7) + ret = regmap_read(map, IMX7_OCOTP_TESTER3, &val); + else + ret = regmap_read(map, IMX6_OCOTP_MEM0, &val); if (ret) { dev_err(&pdev->dev, "failed to read sensor data: %d\n", ret); return ret; @@ -500,6 +662,7 @@ static irqreturn_t imx_thermal_alarm_irq_thread(int irq, void *dev) static const struct of_device_id of_imx_thermal_match[] = { { .compatible = "fsl,imx6q-tempmon", .data = &thermal_imx6q_data, }, { .compatible = "fsl,imx6sx-tempmon", .data = &thermal_imx6sx_data, }, + { .compatible = "fsl,imx7-tempmon", .data = &thermal_imx7_data, }, { /* end */ } }; MODULE_DEVICE_TABLE(of, of_imx_thermal_match); @@ -531,14 +694,15 @@ static int imx_thermal_probe(struct platform_device *pdev) /* make sure the IRQ flag is clear before enabling irq on i.MX6SX */ if (data->socdata->version == TEMPMON_IMX6SX) { - regmap_write(map, MISC1 + REG_CLR, MISC1_IRQ_TEMPHIGH | - MISC1_IRQ_TEMPLOW | MISC1_IRQ_TEMPPANIC); + regmap_write(map, IMX6_MISC1 + REG_CLR, + IMX6_MISC1_IRQ_TEMPHIGH | IMX6_MISC1_IRQ_TEMPLOW + | IMX6_MISC1_IRQ_TEMPPANIC); /* * reset value of LOW ALARM is incorrect, set it to lowest * value to avoid false trigger of low alarm. */ - regmap_write(map, TEMPSENSE2 + REG_SET, - TEMPSENSE2_LOW_VALUE_MASK); + regmap_write(map, IMX6_TEMPSENSE2 + REG_SET, + IMX6_TEMPSENSE2_LOW_VALUE_MASK); } data->irq = platform_get_irq(pdev, 0); @@ -565,11 +729,17 @@ static int imx_thermal_probe(struct platform_device *pdev) } /* Make sure sensor is in known good state for measurements */ - regmap_write(map, TEMPSENSE0 + REG_CLR, TEMPSENSE0_POWER_DOWN); - regmap_write(map, TEMPSENSE0 + REG_CLR, TEMPSENSE0_MEASURE_TEMP); - regmap_write(map, TEMPSENSE1 + REG_CLR, TEMPSENSE1_MEASURE_FREQ); - regmap_write(map, MISC0 + REG_SET, MISC0_REFTOP_SELBIASOFF); - regmap_write(map, TEMPSENSE0 + REG_SET, TEMPSENSE0_POWER_DOWN); + regmap_write(map, data->socdata->sensor_ctrl + REG_CLR, + data->socdata->power_down_mask); + regmap_write(map, data->socdata->sensor_ctrl + REG_CLR, + data->socdata->measure_temp_mask); + regmap_write(map, data->socdata->measure_freq_ctrl + REG_CLR, + data->socdata->measure_freq_mask); + if (data->socdata->version != TEMPMON_IMX7) + regmap_write(map, IMX6_MISC0 + REG_SET, + IMX6_MISC0_REFTOP_SELBIASOFF); + regmap_write(map, data->socdata->sensor_ctrl + REG_SET, + data->socdata->power_down_mask); data->policy = cpufreq_cpu_get(0); if (!data->policy) { @@ -634,16 +804,20 @@ static int imx_thermal_probe(struct platform_device *pdev) data->temp_passive / 1000); /* Enable measurements at ~ 10 Hz */ - regmap_write(map, TEMPSENSE1 + REG_CLR, TEMPSENSE1_MEASURE_FREQ); + regmap_write(map, data->socdata->measure_freq_ctrl + REG_CLR, + data->socdata->measure_freq_mask); measure_freq = DIV_ROUND_UP(32768, 10); /* 10 Hz */ - regmap_write(map, TEMPSENSE1 + REG_SET, measure_freq); + regmap_write(map, data->socdata->measure_freq_ctrl + REG_SET, + measure_freq << data->socdata->measure_freq_shift); imx_set_alarm_temp(data, data->temp_passive); if (data->socdata->version == TEMPMON_IMX6SX) imx_set_panic_temp(data, data->temp_critical); - regmap_write(map, TEMPSENSE0 + REG_CLR, TEMPSENSE0_POWER_DOWN); - regmap_write(map, TEMPSENSE0 + REG_SET, TEMPSENSE0_MEASURE_TEMP); + regmap_write(map, data->socdata->sensor_ctrl + REG_CLR, + data->socdata->power_down_mask); + regmap_write(map, data->socdata->sensor_ctrl + REG_SET, + data->socdata->measure_temp_mask); ret = devm_request_threaded_irq(&pdev->dev, data->irq, imx_thermal_alarm_irq, imx_thermal_alarm_irq_thread, @@ -669,7 +843,8 @@ static int imx_thermal_remove(struct platform_device *pdev) struct regmap *map = data->tempmon; /* Disable measurements */ - regmap_write(map, TEMPSENSE0 + REG_SET, TEMPSENSE0_POWER_DOWN); + regmap_write(map, data->socdata->sensor_ctrl + REG_SET, + data->socdata->power_down_mask); if (!IS_ERR(data->thermal_clk)) clk_disable_unprepare(data->thermal_clk); @@ -692,8 +867,10 @@ static int imx_thermal_suspend(struct device *dev) * temperature will be read as the thermal sensor is powered * down. */ - regmap_write(map, TEMPSENSE0 + REG_CLR, TEMPSENSE0_MEASURE_TEMP); - regmap_write(map, TEMPSENSE0 + REG_SET, TEMPSENSE0_POWER_DOWN); + regmap_write(map, data->socdata->sensor_ctrl + REG_CLR, + data->socdata->measure_temp_mask); + regmap_write(map, data->socdata->sensor_ctrl + REG_SET, + data->socdata->power_down_mask); data->mode = THERMAL_DEVICE_DISABLED; clk_disable_unprepare(data->thermal_clk); @@ -710,8 +887,10 @@ static int imx_thermal_resume(struct device *dev) if (ret) return ret; /* Enabled thermal sensor after resume */ - regmap_write(map, TEMPSENSE0 + REG_CLR, TEMPSENSE0_POWER_DOWN); - regmap_write(map, TEMPSENSE0 + REG_SET, TEMPSENSE0_MEASURE_TEMP); + regmap_write(map, data->socdata->sensor_ctrl + REG_CLR, + data->socdata->power_down_mask); + regmap_write(map, data->socdata->sensor_ctrl + REG_SET, + data->socdata->measure_temp_mask); data->mode = THERMAL_DEVICE_ENABLED; return 0; -- 2.7.4