From patchwork Fri Jun 17 07:08:42 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Francesco Dolcini X-Patchwork-Id: 12885134 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 565E6C433EF for ; Fri, 17 Jun 2022 07:10:44 +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=iFyTqB86mtw1fELsyIE4UsWh6b6FE+LIPiunIB47OJA=; b=VTv3/s1qfqgL6N nbCzNm/S+ki1Ey5PJxzIgMeCCYjzZebmvXvpjmA5QnIPRHWwhtPX6KeOcClDhmmopOCzpQGQQk9RJ lbANees8Ff0NUTjFKW9Ko3pbXGb1KDhQlsNJc922SRoK6+FpTKQ+toG7oyLi/o0+qvvotVwdDqmvC BE224uwh+9vKqyeSdJRbVa74OscwYv1HHkIsyPaSNRGOT/Ton80BXXLTzmPF7bzgB7CpVLEN/M1D/ OUHnHFYyrbz6Cp92l1qtUNHmSTETaMivOQGHAxqRZQa+bu6+CsND8I0Pa4EGStaz5yeQBtgUXxGvW IHH9jygiy+U0a3zRsm8Q==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.94.2 #2 (Red Hat Linux)) id 1o266p-005qkw-31; Fri, 17 Jun 2022 07:09:35 +0000 Received: from de-smtp-delivery-113.mimecast.com ([194.104.109.113]) by bombadil.infradead.org with esmtps (Exim 4.94.2 #2 (Red Hat Linux)) id 1o266G-005qZ1-OG for linux-arm-kernel@lists.infradead.org; Fri, 17 Jun 2022 07:09:02 +0000 Received: from CHE01-GV0-obe.outbound.protection.outlook.com (mail-gv0che01lp2043.outbound.protection.outlook.com [104.47.22.43]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id de-mta-31-inJrkMMeN7ilk6Iy1a5WUQ-1; Fri, 17 Jun 2022 09:08:55 +0200 X-MC-Unique: inJrkMMeN7ilk6Iy1a5WUQ-1 Received: from ZRAP278MB0495.CHEP278.PROD.OUTLOOK.COM (2603:10a6:910:2e::8) by GVAP278MB0263.CHEP278.PROD.OUTLOOK.COM (2603:10a6:710:3d::7) 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:08:51 +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:08:51 +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: [PATCH v2 4/9] imx: thermal: Configure trip point from DT Date: Fri, 17 Jun 2022 09:08:42 +0200 Message-ID: <20220617070847.186876-5-francesco.dolcini@toradex.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20220617070847.186876-1-francesco.dolcini@toradex.com> References: <20220617070847.186876-1-francesco.dolcini@toradex.com> X-ClientProxiedBy: MR1P264CA0106.FRAP264.PROD.OUTLOOK.COM (2603:10a6:501:50::6) 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: 45f7e960-8879-43fb-9ee0-08da50303b20 X-MS-TrafficTypeDiagnostic: GVAP278MB0263: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: ocUC4vZEmZjch65m1MjMyi3x6dGnIg3Eek1H3taveVrCI/oKi91VnZwy7OiqPrSlwCoIhIG1c7ie0EaMv3Wpte4Zvxk1bf2kfwuyzAhERlxP88oC5dtWZjQQGVsJ9sxDSAgaZ7E7nwT1N4a42d0eAz30Nnq8h1D8yI2X3uC+NYpPvDCa+XofPUDSvwD4so7eG13dm0WnsH9InspamZ57BtqPBOkWqGjSMRavC3FPENj0ey5sU3fqjpAwuqNOom14d6Vp7T48MO45SD12OChlFtQndpspLeNN5YOinFEWMGNlQS7Y50bLpYkaWfvyDNb1HvfIXW20eD13yNnGcypDcHY3Yz2QdEKAL7fh7qR0lfU1zr+fJ6F3bnk8Di/pFsybjueOcTfJ5dRysbB3zTACDo1DBbmFL443pAH4G/uI8sOMOhU3YTbG1Ewv6gSCSjfqkJ5zQ4mQN/TgfJh10S6H8CrNzdZnBNWm6k5iOJZV2JezzscFG5bULsp9NX6HWMuHnVrLttHniz4Cp94xcbV20a+Io8PCbQc7lzHbT1/MulilJqcZQWLvDJE3nWQHT9tJSf1o6gNNnez1sLAdcZeDnydwxsbZuJ4zUHRksRhxS+d7dKqXWO0C7RDLYITWfXpSRMmW+GyDLaQ83V2ED1nB6ZtWVWFGwy3YhLlVlOzl2XI4dkvj4WFLDf6ov7CYWA0gH5ZCQktteo9JZbgg37cFVg== 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)(39840400004)(346002)(136003)(396003)(366004)(38100700002)(6506007)(52116002)(8936002)(6666004)(6512007)(6486002)(26005)(83380400001)(2906002)(110136005)(5660300002)(54906003)(316002)(36756003)(86362001)(1076003)(2616005)(41300700001)(66556008)(4326008)(44832011)(8676002)(186003)(66476007)(38350700002)(508600001)(66946007)(7416002);DIR:OUT;SFP:1102 X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-MessageData-0: u/TcxaIDgQATQot86UfP+djSB6LC8gj1KrImI6ZaHE2Lie8uVk41pLbHAY8B/gK3Bk8qBkn5EXfmEvPZKz1yyoXrSETfGqlvdxIhSaSyISZiywe3o1InoaKU86yOzJvVa2khLL7xvz3kGBuEUelnvLdkYIHgUwE6pxwsJV0TQ+7qX866lF//t3IFKP5Fy5AU+Ihl1uGChd/z2JwnPUBFxXyF0rTYWGYW+QjKcaHGl0yiBTBPNpMHQKxHcgj4AmzuvHJ2B6v3HfKIW9xmpyMtfYT1BkT8XNTN1na7BuZ3+76sN91dClKcbpeo3sH1B1T01rxOjTgs/rU8AcjCVuOfFr76CaVOysxpBRVRvouS08BAKn+FpPOuhdkGBsWvkqfUC60gXm/gKssxu4rBRJDIyk0p2XxBKLF31fw2x8vt64v0RVgM0NI8EopGepeo+Kf6d+5QcehvOjsoHChhaqG/x2qdOppXx3MDPRmJhPFJQ7p4fJxO8BzG8ZA9uksJ3QO+OIlFgrVuedYqFbi39+KI3OblLL2poxtMwHgTkEHuTzaloxdmlJ2Jwj8nm32F89NRyXRhrq9EsVMejLdcr7GAn5hTcH2qm430UqnoX09+H4NTKr7miKp/dLRYy8V62tnG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JBdrTOsVC8zQgEZQN46o+NhnRVBw2+4x2ecHFlR9QhhPN3GQ= X-OriginatorOrg: toradex.com X-MS-Exchange-CrossTenant-Network-Message-Id: 45f7e960-8879-43fb-9ee0-08da50303b20 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:08:50.7929 (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: S8488D7bxBNG1E9AUM3wbX/+k+WDusKXb1QV7C4vaKIOsX4aqm3THGGGfk6rGxVn9LRg8FI96JERh9/4qdUadyJzG7nFXRo/iHCdZnYik+w= X-MS-Exchange-Transport-CrossTenantHeadersStamped: GVAP278MB0263 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 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20220617_000901_140036_E258AF73 X-CRM114-Status: GOOD ( 14.58 ) 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 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)