From patchwork Thu Dec 3 15:25:15 2015 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Tim Harvey X-Patchwork-Id: 552361 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Received: from arrakis.dune.hu (arrakis.dune.hu [78.24.191.176]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 404341402C4 for ; Fri, 4 Dec 2015 02:25:35 +1100 (AEDT) Authentication-Results: ozlabs.org; dkim=fail reason="signature verification failed" (2048-bit key; unprotected) header.d=gateworks-com.20150623.gappssmtp.com header.i=@gateworks-com.20150623.gappssmtp.com header.b=bHZvXf4w; dkim-atps=neutral Received: from arrakis.dune.hu (localhost [127.0.0.1]) by arrakis.dune.hu (Postfix) with ESMTP id 99DA6281573; Thu, 3 Dec 2015 16:25:21 +0100 (CET) X-Spam-Checker-Version: SpamAssassin 3.3.2 (2011-06-06) on arrakis.dune.hu X-Spam-Level: X-Spam-Status: No, score=-1.5 required=5.0 tests=BAYES_00,T_DKIM_INVALID autolearn=unavailable version=3.3.2 Received: from arrakis.dune.hu (localhost [127.0.0.1]) by arrakis.dune.hu (Postfix) with ESMTP id 31A5A281573 for ; Thu, 3 Dec 2015 16:25:14 +0100 (CET) X-policyd-weight: using cached result; rate: -5.5 Received: from mail-pa0-f54.google.com (mail-pa0-f54.google.com [209.85.220.54]) by arrakis.dune.hu (Postfix) with ESMTPS for ; Thu, 3 Dec 2015 16:25:13 +0100 (CET) Received: by pacej9 with SMTP id ej9so70743782pac.2 for ; Thu, 03 Dec 2015 07:25:17 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gateworks-com.20150623.gappssmtp.com; s=20150623; h=from:to:cc:subject:date:message-id; bh=BQBMV+iK0zdR6wypLBf6PA/AAfq2NDCqHza6F6acgj4=; b=bHZvXf4wpViciS6norMnNj65KX3Oz/bdsJS9w1F5jY/nljldBvTwhpPGqTEYFnCMCs cXoQtmpbvcef9CexwpbzaNb/3k1Ch9w8BAdVdUcvZT6+xbkAqaYxtlZdIL1wMArD40Rt DhRMZUDX5RWVUHDM/uK5ZLrPidH75eyIp8XKnDNIBPJ3YTb58FdssqA7jGu6cSIsrsUl 5fsBievNEivG7RfFGdWYGm/W7lG9fWZkgbHRjb1iWtFfclK6P6x1izUrl/g6drdk/Xlv SCeGzpl3FJXnQLCFTR+HXfxuNzXM4FBHpe0Wdn578+vBMBZDKfi15z2eZ8ukxtnAl3ZE ZAFg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20130820; h=x-gm-message-state:from:to:cc:subject:date:message-id; bh=BQBMV+iK0zdR6wypLBf6PA/AAfq2NDCqHza6F6acgj4=; b=UN/B8rgMnuqYgIEolHPTxRahiI7uCXRlhLY/ZVLdZYQ46ixd+NcT2YRI8oEpho3ZG0 +O3Sqj81aGF94WHtVHMAMqZwuAoszWd5RKneShjb4SE1tiVlDCnsCZz7tysy408GX0v6 moHRW/Map222FZyVYpHnvDfUeQue1pEm30coNULW2IK1sC1j3iXeDwdGkVCDeqC6k80L yVufWevU71j8nOCD8AnoqNtfQEpwWCVGnFDC/iWepWFaUhrQ0P2FsliR/DdfbIfF1wln uFqy15vFaqEV6b4DWV9co05O8mXGwRZkC9q6mHNta7MzAoQgK5rRvqF58RYvXRUiEP8F HgdQ== X-Gm-Message-State: ALoCoQl88AVOWb6lwVYaLzePAPmLVbC10Vcvpmmm1/PAXsld5roP2wOB0MkgMBI9nHRleACatNjY X-Received: by 10.67.5.164 with SMTP id cn4mr13518363pad.141.1449156317798; Thu, 03 Dec 2015 07:25:17 -0800 (PST) Received: from tharvey.gw (68-189-91-139.static.snlo.ca.charter.com. [68.189.91.139]) by smtp.gmail.com with ESMTPSA id 6sm11447766pfm.58.2015.12.03.07.25.16 (version=TLS1_2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Thu, 03 Dec 2015 07:25:17 -0800 (PST) From: Tim Harvey To: Luka Perkov Date: Thu, 3 Dec 2015 07:25:15 -0800 Message-Id: <1449156315-765-1-git-send-email-tharvey@gateworks.com> X-Mailer: git-send-email 1.9.1 Cc: OpenWrt Development List Subject: [OpenWrt-Devel] [PATCH] imx6: imx: thermal: use CPU temperature grade info for thresholds X-BeenThere: openwrt-devel@lists.openwrt.org X-Mailman-Version: 2.1.15 Precedence: list List-Id: OpenWrt Development List List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , MIME-Version: 1.0 Errors-To: openwrt-devel-bounces@lists.openwrt.org Sender: "openwrt-devel" This is a backport of a2291badc355d58ead5c19ae0609468947416040 from thermal-soc accepted upstream. The IMX6Q/IMX6DL SoC's have a 2-bit temperature grade stored in OTP. Instead of assuming 85C for passive cooling threshold and 100C for critical base these thresholds off the thermal gade max CPU temperature: - passive threshold: max - 10C - critical threshold: max - 5C Signed-off-by: Tim Harvey --- ...l-use-cpu-temperature-grade-info-for-thresholds | 112 +++++++++++++++++++++ 1 file changed, 112 insertions(+) create mode 100644 target/linux/imx6/patches-4.1/045-imx-thermal-use-cpu-temperature-grade-info-for-thresholds diff --git a/target/linux/imx6/patches-4.1/045-imx-thermal-use-cpu-temperature-grade-info-for-thresholds b/target/linux/imx6/patches-4.1/045-imx-thermal-use-cpu-temperature-grade-info-for-thresholds new file mode 100644 index 0000000..44f1b0f --- /dev/null +++ b/target/linux/imx6/patches-4.1/045-imx-thermal-use-cpu-temperature-grade-info-for-thresholds @@ -0,0 +1,112 @@ +--- a/drivers/thermal/imx_thermal.c ++++ b/drivers/thermal/imx_thermal.c +@@ -55,6 +55,7 @@ + #define TEMPSENSE2_PANIC_VALUE_SHIFT 16 + #define TEMPSENSE2_PANIC_VALUE_MASK 0xfff0000 + ++#define OCOTP_MEM0 0x0480 + #define OCOTP_ANA1 0x04e0 + + /* The driver supports 1 passive trip point and 1 critical trip point */ +@@ -64,12 +65,6 @@ enum imx_thermal_trip { + IMX_TRIP_NUM, + }; + +-/* +- * It defines the temperature in millicelsius for passive trip point +- * that will trigger cooling action when crossed. +- */ +-#define IMX_TEMP_PASSIVE 85000 +- + #define IMX_POLLING_DELAY 2000 /* millisecond */ + #define IMX_PASSIVE_DELAY 1000 + +@@ -100,12 +95,14 @@ struct imx_thermal_data { + u32 c1, c2; /* See formula in imx_get_sensor_data() */ + unsigned long temp_passive; + unsigned long temp_critical; ++ unsigned long temp_max; + unsigned long alarm_temp; + unsigned long last_temp; + bool irq_enabled; + int irq; + struct clk *thermal_clk; + const struct thermal_soc_data *socdata; ++ const char *temp_grade; + }; + + static void imx_set_panic_temp(struct imx_thermal_data *data, +@@ -286,10 +283,12 @@ static int imx_set_trip_temp(struct ther + { + struct imx_thermal_data *data = tz->devdata; + ++ /* do not allow changing critical threshold */ + if (trip == IMX_TRIP_CRITICAL) + return -EPERM; + +- if (temp > IMX_TEMP_PASSIVE) ++ /* do not allow passive to be set higher than critical */ ++ if (temp < 0 || temp > data->temp_critical) + return -EINVAL; + + data->temp_passive = temp; +@@ -404,17 +403,39 @@ static int imx_get_sensor_data(struct pl + data->c1 = temp64; + data->c2 = n1 * data->c1 + 1000 * t1; + +- /* +- * Set the default passive cooling trip point, +- * can be changed from userspace. +- */ +- data->temp_passive = IMX_TEMP_PASSIVE; ++ /* use OTP for thermal grade */ ++ ret = regmap_read(map, OCOTP_MEM0, &val); ++ if (ret) { ++ dev_err(&pdev->dev, "failed to read temp grade: %d\n", ret); ++ return ret; ++ } ++ ++ /* The maximum die temp is specified by the Temperature Grade */ ++ switch ((val >> 6) & 0x3) { ++ case 0: /* Commercial (0 to 95C) */ ++ data->temp_grade = "Commercial"; ++ data->temp_max = 95000; ++ break; ++ case 1: /* Extended Commercial (-20 to 105C) */ ++ data->temp_grade = "Extended Commercial"; ++ data->temp_max = 105000; ++ break; ++ case 2: /* Industrial (-40 to 105C) */ ++ data->temp_grade = "Industrial"; ++ data->temp_max = 105000; ++ break; ++ case 3: /* Automotive (-40 to 125C) */ ++ data->temp_grade = "Automotive"; ++ data->temp_max = 125000; ++ break; ++ } + + /* +- * The maximum die temperature set to 20 C higher than +- * IMX_TEMP_PASSIVE. ++ * Set the critical trip point at 5C under max ++ * Set the passive trip point at 10C under max (can change via sysfs) + */ +- data->temp_critical = 1000 * 20 + data->temp_passive; ++ data->temp_critical = data->temp_max - (1000 * 5); ++ data->temp_passive = data->temp_max - (1000 * 10); + + return 0; + } +@@ -559,6 +580,11 @@ static int imx_thermal_probe(struct plat + return ret; + } + ++ dev_info(&pdev->dev, "%s CPU temperature grade - max:%ldC" ++ " critical:%ldC passive:%ldC\n", data->temp_grade, ++ data->temp_max / 1000, data->temp_critical / 1000, ++ data->temp_passive / 1000); ++ + /* Enable measurements at ~ 10 Hz */ + regmap_write(map, TEMPSENSE1 + REG_CLR, TEMPSENSE1_MEASURE_FREQ); + measure_freq = DIV_ROUND_UP(32768, 10); /* 10 Hz */