From patchwork Tue May 16 08:37:45 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Peng Fan \(OSS\)" X-Patchwork-Id: 683197 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 vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 45717C77B7F for ; Tue, 16 May 2023 08:33:26 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231453AbjEPIdX (ORCPT ); Tue, 16 May 2023 04:33:23 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:51662 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231685AbjEPIdR (ORCPT ); Tue, 16 May 2023 04:33:17 -0400 Received: from EUR04-VI1-obe.outbound.protection.outlook.com (mail-vi1eur04on2079.outbound.protection.outlook.com [40.107.8.79]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 7792A3C01; Tue, 16 May 2023 01:33:09 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=FLX/OlxedYLQo4Bj9yKSTcsToyuFrHoSsv/YjW//g492atFT1mtENM9jX6G+b5vAJSBamhVID4SzAWy9MNen1YItRBaOOGLAZ5skT/Jf1nD5yUzp2nwErDkyDuBmCL3psjMncFxjGqTeOZ2Ql/RdkrIjDoWgfR4CRQ8v+OxlqSxLzkOOWmp4uS7SCktP+SOg+J9NJn1u867ZOENSkoH7Kdysvmr/Mvn/XalZMxvuRZP8pj24axVJryhf3gy88UxWFVxxfdgscNKfrR5P+MzgUUQT7lO/V6eNRf3lbCFVWCBCaoXf6ahnB9Vuh3vnGrZs4p7T6L/PNQs2RzYfQAKgIQ== 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=NlKTHXOziId6LQ8cWVoLEmTl1D3ynNMFsB9JUxtVvQg=; b=EKenF515sNJot3nY0MkHcbwfcZj2zoyyesT6O5bTiR8+gcQ1Cb4x9jQRVVUkeBDZXFD9xbl2Lo+qWSNGMwVIUu52ZzHGHzIP4h1EeT4u9b6PO2wVXP3FsFZ5Cp4JcHuk/yYPNVf3Bt98Hxf+34/RrfM29gHtjs7OEEQEvNTQlIbGEjdyB4fagJsH4ulUxwdNkfIsmmgDk23saTmED6twhaCYbt9mJpHdTmQEQuH6l6IXJmnrkp7doeR5s+TTCuT5hcUdRWyV16/SbCdcOYG8mRLH1QuKAvTNxS8Jyjc78ixkVdng3V2tu0eRoNnenpBSGslJ6oeILzdzOvlIA9ToxQ== 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=NlKTHXOziId6LQ8cWVoLEmTl1D3ynNMFsB9JUxtVvQg=; b=kXeWPfpJU9uzaWRcdAgJwqgaD0cm4502ALT/P8LNOCPHyvxCszHI52/tub7hSvL6IVDUub2LF5bZYbtNX9YdR+u4+Cdf8QcmmbLE7Anqw5uRPurR8BruXOPG0FrfZsUyteyKRbXodZNWD6Oh8niz7uucaml+q5JGmkmQFPz72QE= Authentication-Results: dkim=none (message not signed) header.d=none;dmarc=none action=none header.from=oss.nxp.com; Received: from DU0PR04MB9417.eurprd04.prod.outlook.com (2603:10a6:10:358::11) by DBBPR04MB7644.eurprd04.prod.outlook.com (2603:10a6:10:20c::20) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.6387.33; Tue, 16 May 2023 08:33:06 +0000 Received: from DU0PR04MB9417.eurprd04.prod.outlook.com ([fe80::b999:f2c6:a8cc:7b4]) by DU0PR04MB9417.eurprd04.prod.outlook.com ([fe80::b999:f2c6:a8cc:7b4%6]) with mapi id 15.20.6387.030; Tue, 16 May 2023 08:33:06 +0000 From: "Peng Fan (OSS)" To: rafael@kernel.org, daniel.lezcano@linaro.org, shawnguo@kernel.org, s.hauer@pengutronix.de Cc: amitk@kernel.org, rui.zhang@intel.com, andrew.smirnov@gmail.com, linux-pm@vger.kernel.org, linux-kernel@vger.kernel.org, kernel@pengutronix.de, festevam@gmail.com, linux-imx@nxp.com, linux-arm-kernel@lists.infradead.org, alice.guo@nxp.com, Peng Fan Subject: [PATCH 2/3] thermal: qoriq_thermal: only enable supported sensors Date: Tue, 16 May 2023 16:37:45 +0800 Message-Id: <20230516083746.63436-3-peng.fan@oss.nxp.com> X-Mailer: git-send-email 2.37.1 In-Reply-To: <20230516083746.63436-1-peng.fan@oss.nxp.com> References: <20230516083746.63436-1-peng.fan@oss.nxp.com> X-ClientProxiedBy: SG2PR03CA0099.apcprd03.prod.outlook.com (2603:1096:4:7c::27) To DU0PR04MB9417.eurprd04.prod.outlook.com (2603:10a6:10:358::11) MIME-Version: 1.0 X-MS-Exchange-MessageSentRepresentingType: 1 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: DU0PR04MB9417:EE_|DBBPR04MB7644:EE_ X-MS-Office365-Filtering-Correlation-Id: a273cce4-c2dc-4fa3-d9c0-08db55e82bcd 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: /vMaMLs0KY02/g49zTtBF0DI95K7EeUij7xj+HNJ1S57jN5T8Xg/tlHNpls45KkcZFJ+PSbHKylB+nEK+qPnhie4Q+/Cd8C0lH31GQdujDGgzNtjCqW9e1rtE51VKT8UB6NYOtsJasWCQrhV9cOUyJtj1jcUTyESj7ozdUHprUclbHYTl9XJQSlvt397G9C4SBSSSm0nIhvY54TMg5RS0yOAk354E4TGJfET+hm9IfTKOJ/f5iP1WEeAS44Jk3P3LBFExYU5LPnfP58z0RyoLCe37TPBr+00UsSLYRQRCm8xhQ32GiEKwMGOhsT/NsnaKMOPA+NigvMejaSxN8FdbZ9ER3ShqNRCVXqYO9uEqAPUknYrLV73I5cdtTM+uKpWPj9V3RJYR8nYl37MPfWEG/iw952bDgrbfBj3ufXGo+rz52I4q+PgAfpCQXGCs4Te7il0yUoVQUa7ixW3TMsvzcEQsL4buGNuV/zu6tWf3NMNIR+v+EekN0HsfWaoiER/63nqX2/0bvT/DBrCCprwx70pL7FI+gYMUU37fkrZ7u9oDlQLUMkACUkP02uaOz80WV5JBYanqTSLvqyzDuC2xW4Z4rQbxQC5LfT5BGcMAS0cNL6I+kQVRUCgQljX57fw X-Forefront-Antispam-Report: CIP:255.255.255.255; CTRY:; LANG:en; SCL:1; SRV:; IPV:NLI; SFV:NSPM; H:DU0PR04MB9417.eurprd04.prod.outlook.com; PTR:; CAT:NONE; SFS:(13230028)(4636009)(346002)(376002)(396003)(39860400002)(366004)(136003)(451199021)(52116002)(66556008)(66476007)(66946007)(478600001)(4326008)(316002)(86362001)(83380400001)(6506007)(6512007)(1076003)(2616005)(186003)(26005)(6486002)(41300700001)(8936002)(8676002)(5660300002)(7416002)(2906002)(6666004)(38350700002)(38100700002); DIR:OUT; SFP:1101; X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-MessageData-0: 0UAsRi8QkKLZ9i5jfYUQ3J7JLpiKmGOFDfkCftwMTGmnCY+PzeicLPfuMTy1iIoUXQdgMqtGTH0a8PaUViO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ntN7h9fG2WWUqINgpiitIBdXlfzINYWvLtQzGTO+JNxSAxtaLvxYQo3xFdc9E1slNdslM9nDlZOwVu7SxrBpKldwpnybfKPZiFP03RdZQE3Zh9spHnGY3q+UPFHQeSaXRrw9ugUL+WcF2nqQpHbHTNCoKGtzUeXzL7ewESTbLowCgd8mPhI0bF2W5ItKU4/QW4IrYsBt6Cw1ErgkySNObzdj7TqxEsm0yNgavJS5cqpbS2+FsZHH4RuO7hf5d4ESwow9vimToRGG8mOPKo0f1G7A+M6GvzKwTn371GoWA2fgOszvhBK9AfjJDQpk0S0z+18ZgI6e+iqbjuCWphfcY4DQpKKV5/4m/3RtEu2pnpnOQdDibXcwiVI7A1E1RUQSon0CKI5R3PqkW838MJ40LPiLiHu83srWBXQ1jcdBR+r79xUsFiMZ6C/Epw X-OriginatorOrg: oss.nxp.com X-MS-Exchange-CrossTenant-Network-Message-Id: a273cce4-c2dc-4fa3-d9c0-08db55e82bcd X-MS-Exchange-CrossTenant-AuthSource: DU0PR04MB9417.eurprd04.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 16 May 2023 08:33:06.1545 (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: tJ/ZHohGvo9au6ASm8biL46fU09aAgX6QOJgAFfoNvtHKH2PplFlw98OZ457D2gH8X+Vcl/KgyKvIKw83/EDLw== X-MS-Exchange-Transport-CrossTenantHeadersStamped: DBBPR04MB7644 Precedence: bulk List-ID: X-Mailing-List: linux-pm@vger.kernel.org From: Peng Fan There are MAX 16 sensors, but not all of them supported. Such as i.MX8MQ, there are only 3 sensors. Enabling all 16 sensors will touch reserved bits from i.MX8MQ reference mannual, and TMU will stuck, temperature will not update anymore. Fixes: 45038e03d633 ("thermal: qoriq: Enable all sensors before registering them") Signed-off-by: Peng Fan --- drivers/thermal/qoriq_thermal.c | 30 +++++++++++++++++++----------- 1 file changed, 19 insertions(+), 11 deletions(-) diff --git a/drivers/thermal/qoriq_thermal.c b/drivers/thermal/qoriq_thermal.c index b806a0929459..53748c4a5be1 100644 --- a/drivers/thermal/qoriq_thermal.c +++ b/drivers/thermal/qoriq_thermal.c @@ -31,7 +31,6 @@ #define TMR_DISABLE 0x0 #define TMR_ME 0x80000000 #define TMR_ALPF 0x0c000000 -#define TMR_MSITE_ALL GENMASK(15, 0) #define REGS_TMTMIR 0x008 /* Temperature measurement interval Register */ #define TMTMIR_DEFAULT 0x0000000f @@ -105,6 +104,11 @@ static int tmu_get_temp(struct thermal_zone_device *tz, int *temp) * within sensor range. TEMP is an 9 bit value representing * temperature in KelVin. */ + + regmap_read(qdata->regmap, REGS_TMR, &val); + if (!(val & TMR_ME)) + return -EAGAIN; + if (regmap_read_poll_timeout(qdata->regmap, REGS_TRITSR(qsensor->id), val, @@ -128,15 +132,7 @@ static const struct thermal_zone_device_ops tmu_tz_ops = { static int qoriq_tmu_register_tmu_zone(struct device *dev, struct qoriq_tmu_data *qdata) { - int id; - - if (qdata->ver == TMU_VER1) { - regmap_write(qdata->regmap, REGS_TMR, - TMR_MSITE_ALL | TMR_ME | TMR_ALPF); - } else { - regmap_write(qdata->regmap, REGS_V2_TMSR, TMR_MSITE_ALL); - regmap_write(qdata->regmap, REGS_TMR, TMR_ME | TMR_ALPF_V2); - } + int id, sites = 0; for (id = 0; id < SITES_MAX; id++) { struct thermal_zone_device *tzd; @@ -153,14 +149,26 @@ static int qoriq_tmu_register_tmu_zone(struct device *dev, if (ret == -ENODEV) continue; - regmap_write(qdata->regmap, REGS_TMR, TMR_DISABLE); return ret; } + if (qdata->ver == TMU_VER1) + sites |= 0x1 << (15 - id); + else + sites |= 0x1 << id; + if (devm_thermal_add_hwmon_sysfs(dev, tzd)) dev_warn(dev, "Failed to add hwmon sysfs attributes\n"); + } + if (sites) { + if (qdata->ver == TMU_VER1) { + regmap_write(qdata->regmap, REGS_TMR, TMR_ME | TMR_ALPF | sites); + } else { + regmap_write(qdata->regmap, REGS_V2_TMSR, sites); + regmap_write(qdata->regmap, REGS_TMR, TMR_ME | TMR_ALPF_V2); + } } return 0;