From patchwork Fri Jun 17 07:14:06 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Francesco Dolcini X-Patchwork-Id: 12885169 X-Patchwork-Delegate: daniel.lezcano@linaro.org 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 5C204CCA479 for ; Fri, 17 Jun 2022 07:14:37 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1380550AbiFQHOe convert rfc822-to-8bit (ORCPT ); Fri, 17 Jun 2022 03:14:34 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:54254 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230044AbiFQHOY (ORCPT ); Fri, 17 Jun 2022 03:14:24 -0400 Received: from de-smtp-delivery-113.mimecast.com (de-smtp-delivery-113.mimecast.com [194.104.111.113]) by lindbergh.monkeyblade.net (Postfix) with ESMTP id 0D75865400 for ; Fri, 17 Jun 2022 00:14:22 -0700 (PDT) Received: from CHE01-ZR0-obe.outbound.protection.outlook.com (mail-zr0che01lp2112.outbound.protection.outlook.com [104.47.22.112]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id de-mta-34-Uz7mLjrSNSydKNOMOzBtkA-4; Fri, 17 Jun 2022 09:14:19 +0200 X-MC-Unique: Uz7mLjrSNSydKNOMOzBtkA-4 Received: from ZRAP278MB0495.CHEP278.PROD.OUTLOOK.COM (2603:10a6:910:2e::8) by GVAP278MB0438.CHEP278.PROD.OUTLOOK.COM (2603:10a6:710:3e::6) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.5353.15; Fri, 17 Jun 2022 07:14:15 +0000 Received: from ZRAP278MB0495.CHEP278.PROD.OUTLOOK.COM ([fe80::2879:acb:62c8:4987]) by ZRAP278MB0495.CHEP278.PROD.OUTLOOK.COM ([fe80::2879:acb:62c8:4987%8]) with mapi id 15.20.5353.016; Fri, 17 Jun 2022 07:14:15 +0000 From: Francesco Dolcini To: Daniel Lezcano , Rob Herring , "Rafael J. Wysocki" , Krzysztof Kozlowski , Shawn Guo , Marco Felsch , Anson Huang CC: Francesco Dolcini , Amit Kucheria , Zhang Rui , linux-pm@vger.kernel.org, devicetree@vger.kernel.org, Pengutronix Kernel Team , Sascha Hauer , Fabio Estevam , NXP Linux Team , linux-arm-kernel@lists.infradead.org Subject: [RESEND PATCH v2 4/9] imx: thermal: Configure trip point from DT Date: Fri, 17 Jun 2022 09:14:06 +0200 Message-ID: <20220617071411.187542-5-francesco.dolcini@toradex.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20220617071411.187542-1-francesco.dolcini@toradex.com> References: <20220617071411.187542-1-francesco.dolcini@toradex.com> X-ClientProxiedBy: MR2P264CA0188.FRAP264.PROD.OUTLOOK.COM (2603:10a6:501::27) To ZRAP278MB0495.CHEP278.PROD.OUTLOOK.COM (2603:10a6:910:2e::8) MIME-Version: 1.0 X-MS-PublicTrafficType: Email X-MS-Office365-Filtering-Correlation-Id: 638b06b0-7000-4645-350e-08da5030fbc7 X-MS-TrafficTypeDiagnostic: GVAP278MB0438:EE_ X-Microsoft-Antispam-PRVS: X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0 X-Microsoft-Antispam-Message-Info: q/tYp7sLaM+sP1+vT7QWFYqbVN7eNdzuF1G37PvyI0UvEIF3AGAgWIX+Tcm/nAyeW8H5ARtTmOfskdoK6Yk4nQ1eNOwDwczpgdZSWtkSBKinx9JLqyiwiRtcdNAAji+6tslEJuUiC++kbbyVq50RmlJh7gfiDVvm14j+/RrTKzeeZ4pmk8up663cz8WLCjHRmhst54joDFNoK+A65ABP01WmlRAxmXQxJZ4OrvE1Tz0DSGXDilGQk9k41917+TaJpeSHwxy459n1F8RhEj5wD3ZxyHc89DQNQfK+rdmH5QDFPgf4H5gqhc4LltnriVqW2FrCStf8ykaC7C+WxfcSMJMishG/WXf/jCC0/DZvgUmyzXM0T51rxynaIsgzJPVKHlYhHHMl0hlEJ5NzuHdQw7pw0AZC3cfYn8qAcT8xkRSkP0RbLdO1Ku222NHxopkfkIXjmxqx94Ff4xXtJuVusI2js5iiAJhUz0eSo3gg6NqxCThXhLbPgE3hiTdNEztTLdctJlF/YyCVY5r9kzmScJET4lXJcdW6EG4ITumjvsBDXctBL3qoysuQEknYKLl3DSxEZHgO5TFvTG/FZwIdfds2ZuevIU1yyr2xPq+owhR0/XkT2dyoTXKCyZev0t/OFNJtVKS8FhaiB2mfMIMBouUBIjUDhF3w1NvyqvgmlL6OhqZ5XYQqRmh0DI/K8PBhBRvYmtvgSDt4JVXL0chsGQ== X-Forefront-Antispam-Report: CIP:255.255.255.255;CTRY:;LANG:en;SCL:1;SRV:;IPV:NLI;SFV:NSPM;H:ZRAP278MB0495.CHEP278.PROD.OUTLOOK.COM;PTR:;CAT:NONE;SFS:(13230016)(4636009)(396003)(366004)(136003)(39850400004)(346002)(52116002)(38100700002)(38350700002)(6506007)(2906002)(8676002)(8936002)(6666004)(6486002)(316002)(66946007)(86362001)(7416002)(508600001)(5660300002)(44832011)(83380400001)(110136005)(41300700001)(2616005)(26005)(6512007)(36756003)(66556008)(54906003)(4326008)(66476007)(186003)(1076003);DIR:OUT;SFP:1102 X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-MessageData-0: VYYuuc7AMDDmDsAe67J+xV+/6W2kQmitfSqKvm7yk2Lt/Oa4sb/ji4LSU9JnUyiAlKLjABaZt+vfPifpvY/iT7DSVuFulRBf/F6ooF/WEY5udTt/S1OcF4+t6iXg7HZ/FXW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Tzfqwv6E3F+J6ZO7xM65WAinn7K534ZqNmyhCGnbhmS8MzUAbbTsL8pERRDczjobMVbWi0tSqUOPWbuMPgx0ztWecpHmCQ/+u6d9Y411nowZu4YGzUpbW1qStFx7tInbgYHp5nlOHGq7DMy+q33oUXzzxKHpImg3pmryCe9RfZj4Ae3VU8x4DXFuw859k2oUAxXHTjCIwVppN2CmkayVFyWUSV6i/ZRWUUQ/kjsnJy2cmntFsQEIRR73AtLTQlebs33eohEGA0MDYRiYMj94GnYDcZ+hRoXZdG5T6DKRc/pYAz4EmyIDauJqLpPCaVZtbDMN0PpodqbxBCSrvx+hIP7IYzJ/oIuBcFyBA5WVXIEryXfHLQgRjXk3nhXRDf5JYGJtsHEpSHKsrnc+ghYp+Ix7G+9w+m1P4NlJoiQTFLDxOhhsfrDd46yZDor8j8/fQEpPe9e5EUWSoug68WJJYucd47w2GbZ1saZ2N28BvaZJ+wUk3bZ3K8mdBXAj9deElU5rIJwYwYlJ7tX3gWg/6fWDZANNCHTfjOM/GceNH7pTdoe+WsQ= X-OriginatorOrg: toradex.com X-MS-Exchange-CrossTenant-Network-Message-Id: 638b06b0-7000-4645-350e-08da5030fbc7 X-MS-Exchange-CrossTenant-AuthSource: ZRAP278MB0495.CHEP278.PROD.OUTLOOK.COM X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 17 Jun 2022 07:14:14.0396 (UTC) X-MS-Exchange-CrossTenant-FromEntityHeader: Hosted X-MS-Exchange-CrossTenant-Id: d9995866-0d9b-4251-8315-093f062abab4 X-MS-Exchange-CrossTenant-MailboxType: HOSTED X-MS-Exchange-CrossTenant-UserPrincipalName: yP/YPN6rHwvEZW6k41vlxl0SWujoN6iKgni3gtBLLU9KonPYPfl5vA/y4o4ORlSuSUKU1l0i/IRdQJKFSb+9ANEPLi/PFvXguTWQkSkfQYc= X-MS-Exchange-Transport-CrossTenantHeadersStamped: GVAP278MB0438 Authentication-Results: relay.mimecast.com; auth=pass smtp.auth=CDE13A77 smtp.mailfrom=francesco.dolcini@toradex.com X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: toradex.com Precedence: bulk List-ID: X-Mailing-List: linux-pm@vger.kernel.org Allow over-writing critical and passive trip point for each temperature grade from the device tree, by default the pre-existing hard-coded trip points are used. This change enables configuring the system thermal characteristics into the system-specific device tree instead of relying on global hard-coded temperature thresholds that does not take into account the specific system thermal design. Signed-off-by: Francesco Dolcini --- v2: - return immediately if no thermal node present in the dts - use dev_info instead of dev_dbg if there is an invalid trip - additional comment in case passive trip point is higher than critical --- drivers/thermal/imx_thermal.c | 58 +++++++++++++++++++++++++++++++++++ 1 file changed, 58 insertions(+) diff --git a/drivers/thermal/imx_thermal.c b/drivers/thermal/imx_thermal.c index 16663373b682..a964baf802fc 100644 --- a/drivers/thermal/imx_thermal.c +++ b/drivers/thermal/imx_thermal.c @@ -17,6 +17,8 @@ #include #include +#include "thermal_core.h" + #define REG_SET 0x4 #define REG_CLR 0x8 #define REG_TOG 0xc @@ -479,36 +481,92 @@ static int imx_init_calib(struct platform_device *pdev, u32 ocotp_ana1) return 0; } +static void imx_init_temp_from_of(struct platform_device *pdev, const char *name) +{ + struct imx_thermal_data *data = platform_get_drvdata(pdev); + struct device_node *thermal, *trips, *trip_point; + + thermal = of_get_child_by_name(pdev->dev.of_node, name); + if (!thermal) + return; + + trips = of_get_child_by_name(thermal, "trips"); + + for_each_child_of_node(trips, trip_point) { + struct thermal_trip t; + + if (thermal_of_populate_trip(trip_point, &t)) + continue; + + switch (t.type) { + case THERMAL_TRIP_PASSIVE: + data->temp_passive = t.temperature; + break; + case THERMAL_TRIP_CRITICAL: + data->temp_critical = t.temperature; + break; + default: + dev_info(&pdev->dev, "Ignoring trip type %d\n", t.type); + break; + } + }; + + of_node_put(trips); + of_node_put(thermal); + + if (data->temp_passive >= data->temp_critical) { + dev_warn(&pdev->dev, + "passive trip point must be lower than critical, fixing it up\n"); + /* + * In case of misconfiguration set passive temperature to + * 5°C less than critical, this seems like a reasonable + * default and the same is done when no thermal trips are + * available in the device tree. + */ + data->temp_passive = data->temp_critical - (1000 * 5); + } +} + static void imx_init_temp_grade(struct platform_device *pdev, u32 ocotp_mem0) { struct imx_thermal_data *data = platform_get_drvdata(pdev); + const char *thermal_node_name; /* The maximum die temp is specified by the Temperature Grade */ switch ((ocotp_mem0 >> 6) & 0x3) { case 0: /* Commercial (0 to 95 °C) */ + thermal_node_name = "commercial-thermal"; data->temp_grade = "Commercial"; data->temp_max = 95000; break; case 1: /* Extended Commercial (-20 °C to 105 °C) */ + thermal_node_name = "extended-commercial-thermal"; data->temp_grade = "Extended Commercial"; data->temp_max = 105000; break; case 2: /* Industrial (-40 °C to 105 °C) */ + thermal_node_name = "industrial-thermal"; data->temp_grade = "Industrial"; data->temp_max = 105000; break; case 3: /* Automotive (-40 °C to 125 °C) */ + thermal_node_name = "automotive-thermal"; data->temp_grade = "Automotive"; data->temp_max = 125000; break; } /* + * Set defaults trips + * * Set the critical trip point at 5 °C under max * Set the passive trip point at 10 °C under max (changeable via sysfs) */ data->temp_critical = data->temp_max - (1000 * 5); data->temp_passive = data->temp_max - (1000 * 10); + + /* Override critical/passive temperature from devicetree */ + imx_init_temp_from_of(pdev, thermal_node_name); } static int imx_init_from_tempmon_data(struct platform_device *pdev)