From patchwork Wed Jun 15 09:47:59 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Francesco Dolcini X-Patchwork-Id: 12881993 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 45CC2C433EF for ; Wed, 15 Jun 2022 09:50:27 +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=duu+DBDun4Q15TfnVx5tsWdfGUeTQK/rc/6HDVOIqPU=; b=MY0gWVAYWuqB5r ymV+LuTNqTAghMNfuKNnHzUz9h+PC8WANsFZH2Exf7zFPliWGlW6y4OaTTeQMEcMS1g+28GUOlkkT FhVQb3WPGf7OF4z7T9viwwlWUTpB8mLKMW2++Bht2TvAbMcUcmGcPPPRoysXU3FqqmUZOIC399T+r c9vm95wZZyOIlKEXvfyGsGPXPMC2gmE4wBOzusolmtqp/yCBNN93ffNVNUQB4Y6IodsaWM0qrFK99 t1W3EQvONYLvKtF/+xmTwpf3owR9XdkQzyBH7UuATtSJSIFB5VFzb0xMFSImxYCcc6U7JP7B1wzB6 hjaUOJN8XtFuS/2t/pvg==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.94.2 #2 (Red Hat Linux)) id 1o1PeA-00DZ7u-UG; Wed, 15 Jun 2022 09:49:11 +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 1o1PdO-00DYwW-Lm for linux-arm-kernel@lists.infradead.org; Wed, 15 Jun 2022 09:48:24 +0000 Received: from CHE01-GV0-obe.outbound.protection.outlook.com (mail-gv0che01lp2042.outbound.protection.outlook.com [104.47.22.42]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id de-mta-25-b2yI8NakMo67c_ZUP3cFQg-3; Wed, 15 Jun 2022 11:48:16 +0200 X-MC-Unique: b2yI8NakMo67c_ZUP3cFQg-3 Received: from ZRAP278MB0495.CHEP278.PROD.OUTLOOK.COM (2603:10a6:910:2e::8) by GVAP278MB0392.CHEP278.PROD.OUTLOOK.COM (2603:10a6:710:3d::9) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.5332.13; Wed, 15 Jun 2022 09:48:14 +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.013; Wed, 15 Jun 2022 09:48:13 +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 v1 4/9] imx: thermal: Configure trip point from DT Date: Wed, 15 Jun 2022 11:47:59 +0200 Message-ID: <20220615094804.388280-5-francesco.dolcini@toradex.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20220615094804.388280-1-francesco.dolcini@toradex.com> References: <20220615094804.388280-1-francesco.dolcini@toradex.com> X-ClientProxiedBy: MRXP264CA0043.FRAP264.PROD.OUTLOOK.COM (2603:10a6:500:14::31) 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: 7c196331-b62b-4bdc-87da-08da4eb429d2 X-MS-TrafficTypeDiagnostic: GVAP278MB0392: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: 3khyPStUl7MH7vt17yO2T0Gb+npu4U+Ecyq6vLdeqSTAZ3fBzgCuIa5PIRUxveUCGcp74hC5TE1m90pPEjomPv3sbwdv43yt4Hl//1CnN7bLkZKcjYnQmZwOd2Q24/n+BJIxB0yQ3wHeBtJ8b8d6sFROGRXWca7iYIIBtAd5YUTulnt/J4f99kgJamllLbkt4es1mlPSX1JHXHcDL5Cqf4x7w7gJB8KPbQ8DcBH963gKvmqXm66/wkOp4uCdCmO/Dsw3MzyoFI8cpGva612fmXK1oAuToGyeuf0DJKPx5WVeVPkPJqC42uYhlYpfXO9gUjeCrHz/6MdjVx6pluwUo7Dr4IO5K5iOXG4EtcHCQ2bEoV8LD2tcVRUklIQ+SOw6gecO1HRz9M2o+qUG1FbyLpa8JWC3fcIDUAGqctIQrXLTwZ974AFKiAqH+HzWcMi0+BqbgFP0B3AeZFjH7+lhPAspXPv85zKWO/pHAdXqWgLw9iwhLVpUHbMF+TJChbiI+yJjzfDU3J6NDhIAk4LKwkp0WdyMq/Z8FMivPVswxqu2XjEK7Tu/am7mZZm90DPUgcd6iWlG9upNo6rav2jpkdWGmsXppkbr9LwIlYSPXOMj2ZhCu2voB47h3bkoRmy6uFf8x9LNfwXGKQAHnD94uPc2h1sCA/vWwc1liYTIOKl4v9b8qrHtq/pHp63J6K4NN30DHbJoeoOeKayX+uVoHg== 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)(136003)(396003)(39850400004)(346002)(366004)(1076003)(41300700001)(2616005)(8676002)(110136005)(8936002)(6666004)(316002)(66946007)(508600001)(4326008)(86362001)(66556008)(54906003)(66476007)(26005)(52116002)(6512007)(6506007)(36756003)(2906002)(38350700002)(83380400001)(38100700002)(44832011)(5660300002)(6486002)(186003)(7416002);DIR:OUT;SFP:1102 X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-MessageData-0: GCPrv6sUnpYLMhvQK9IQnNxQPVO0YHavV695Q+D7F7RH4C+LdcYW7+VtJFbo4xrJzmBmnlafJiFlmk3oXcyS4fOx2OK1Z81peLrK6LY0L33eDHEdjYuDXuDfkhWsr495COvtCQrcq4yglmB4Z+f3h3+TJmUshisio8YgSXAaE13ZBB7U06O0ZJiTa4EnQzTeZxwRFougyM6EazPdWQmJSkPPWAPtx6TcFCJnV9dUWyzlKLJ+itw+XcdIuu7GwngzSIkOZYIpLCSPcQd4KM8tLYIumXFi9hbTAfna4EH9jXqKCZMR4VsUUicPbh2HbklqPu0WBBY1zpcv0NHg+R91yqV0I3aUllZ+YSoh72pIHsjVCyRKhB6psayJCZjBkYYgWeO4CSTclNO4eX/dvzZ+fWezAUfRyii+TwTHN69mAGZT2WCWU/PLQ/1FvpxEWHA7zLUTffqlLVU/onjSj3LQpMfBYhoUy7ur1xFdbWkjWRr6ymcYOJM+jlzAaDkn1h6D3gu18C3kIyhn3LLnMiAJn85K1Y36KpTy95zzGZXczZGfUrBXUBy4yHYopkixl+LEHYmN89b06M95ptWuhdGS/RBIKzG4JGPZuLxHSVZLGLeMpDk1VqGHQk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bwXZKE7oWrgdQGi9FqrKCe25ng6HUSMlA7RDDtbDrkjCuYHggsAQE8hPK4BzeN1fxHo= X-OriginatorOrg: toradex.com X-MS-Exchange-CrossTenant-Network-Message-Id: 7c196331-b62b-4bdc-87da-08da4eb429d2 X-MS-Exchange-CrossTenant-AuthSource: ZRAP278MB0495.CHEP278.PROD.OUTLOOK.COM X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 15 Jun 2022 09:48:13.0183 (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: PNMRwWF5mzgD0m5CF4BhENtefFdWToRJA8l2hcl21WoPC2UOF0JDNymNEPoknA2wYF0t2vCRzlzQvBV3gPGhpc63vz/XJxuvDnAn+xl4+O0= X-MS-Exchange-Transport-CrossTenantHeadersStamped: GVAP278MB0392 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-20220615_024823_079039_2B682F2F X-CRM114-Status: GOOD ( 12.31 ) 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 --- drivers/thermal/imx_thermal.c | 49 +++++++++++++++++++++++++++++++++++ 1 file changed, 49 insertions(+) diff --git a/drivers/thermal/imx_thermal.c b/drivers/thermal/imx_thermal.c index 16663373b682..ef3e152b5ee2 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,83 @@ 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); + 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_dbg(&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"); + 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)