From patchwork Thu Apr 30 16:02:37 2015 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Tim Harvey X-Patchwork-Id: 6305361 Return-Path: X-Original-To: patchwork-linux-arm@patchwork.kernel.org Delivered-To: patchwork-parsemail@patchwork1.web.kernel.org Received: from mail.kernel.org (mail.kernel.org [198.145.29.136]) by patchwork1.web.kernel.org (Postfix) with ESMTP id 603C79F326 for ; Thu, 30 Apr 2015 16:05:27 +0000 (UTC) Received: from mail.kernel.org (localhost [127.0.0.1]) by mail.kernel.org (Postfix) with ESMTP id 69E71201E4 for ; Thu, 30 Apr 2015 16:05:26 +0000 (UTC) Received: from bombadil.infradead.org (bombadil.infradead.org [198.137.202.9]) (using TLSv1.2 with cipher DHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPS id 3423520120 for ; Thu, 30 Apr 2015 16:05:25 +0000 (UTC) Received: from localhost ([127.0.0.1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.80.1 #2 (Red Hat Linux)) id 1Ynqvt-0001lE-RF; Thu, 30 Apr 2015 16:03:25 +0000 Received: from mail-pd0-f179.google.com ([209.85.192.179]) by bombadil.infradead.org with esmtps (Exim 4.80.1 #2 (Red Hat Linux)) id 1Ynqve-0001Uq-2e for linux-arm-kernel@lists.infradead.org; Thu, 30 Apr 2015 16:03:11 +0000 Received: by pdbqa5 with SMTP id qa5so64824407pdb.1 for ; Thu, 30 Apr 2015 09:02:48 -0700 (PDT) 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=u1SrwiNrQgG7wHB2Bimru1mZ9yDT8t/UR7G8q7eIVX8=; b=kcdrOB/7GWdKaitaVDAOmVYZyms+Gpde9Y/yq2qACWSVwBCzSfIRAPS/u1gI2UsuLq jtrDuO9SH55sBbmurqFuIAM+LKq//WhRwGlrp5X0Uq12/2w1IbpzMXsTgomnNodTn8km 9cdZvZuddrbRsvFLBRk3klhw3vGKgRivt/HAEvlM4ABxG1IDuqnIYoyg/r5G18vEPf/Y NFQrZGeuKZLonMI/3lAo+11kQW25g6eRGzzJoZp8Lw57ur0A9zKNQDp7dKTN82y21y6D iTnoUGcmd5rbZgSUpQFWdqDHBEYmL0WJN9PwNJHUH0zLlfdE2PDnuSd96I3poJInTrmA WgBA== X-Gm-Message-State: ALoCoQkH2XnceJVuo3lI6X5u2wlpOJIwflUKug3n5ZY7Vh/ZxG+/EgcMjPAtgpasDPJR5UvZBF/0 X-Received: by 10.70.42.13 with SMTP id j13mr9673916pdl.64.1430409768022; Thu, 30 Apr 2015 09:02:48 -0700 (PDT) Received: from tharvey.gw (68-189-91-139.static.snlo.ca.charter.com. [68.189.91.139]) by mx.google.com with ESMTPSA id te4sm1224077pbc.88.2015.04.30.09.02.46 (version=TLSv1.2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Thu, 30 Apr 2015 09:02:47 -0700 (PDT) From: Tim Harvey To: Zhang Rui , Eduardo Valentin Subject: [PATCH] imx: thermal: use CPU temperature grade info for thresholds Date: Thu, 30 Apr 2015 09:02:37 -0700 Message-Id: <1430409757-16195-1-git-send-email-tharvey@gateworks.com> X-Mailer: git-send-email 1.9.1 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20150430_090310_254982_A0841472 X-CRM114-Status: GOOD ( 17.73 ) X-Spam-Score: -0.9 (/) Cc: Fabio Estevam , Anson Huang , Shawn Guo , linux-arm-kernel@lists.infradead.org X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.18-1 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , MIME-Version: 1.0 Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+patchwork-linux-arm=patchwork.kernel.org@lists.infradead.org X-Spam-Status: No, score=-4.2 required=5.0 tests=BAYES_00, RCVD_IN_DNSWL_MED, T_RP_MATCHES_RCVD, UNPARSEABLE_RELAY autolearn=unavailable version=3.3.1 X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on mail.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP The IMX6Q/IMX6DL SoC's have a 2-bit temperature grade stored in OTP. Instead of assuming 85C for passive cooling threshold and 105C for critical use the thermal grade for these configurations. For IMX6SX which does not have a temperature grade in OTP (according to the ref manual) assume 105C critical. We will default the user-settable passive threshold to crit - 20C. Cc: Anson Huang Cc: Fabio Estevam Cc: Shawn Guo Signed-off-by: Tim Harvey Acked-by: Shawn Guo Acked-by: Jon Nettleton --- drivers/thermal/imx_thermal.c | 64 +++++++++++++++++++++++++++++++++---------- 1 file changed, 49 insertions(+), 15 deletions(-) diff --git a/drivers/thermal/imx_thermal.c b/drivers/thermal/imx_thermal.c index 2ccbc07..c6a4eed 100644 --- 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 @@ -106,6 +101,7 @@ struct imx_thermal_data { 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, @@ -289,7 +285,8 @@ static int imx_set_trip_temp(struct thermal_zone_device *tz, int trip, if (trip == IMX_TRIP_CRITICAL) return -EPERM; - if (temp > IMX_TEMP_PASSIVE) + /* do not allow passive to be set higher than critical - 20C */ + if (temp > (data->temp_critical - (1000 * 20))) return -EINVAL; data->temp_passive = temp; @@ -404,17 +401,50 @@ static int imx_get_sensor_data(struct platform_device *pdev) 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; + /* Assume Extended Commercial temperature grade limits (105C max) */ + data->temp_grade = "unknown"; + data->temp_critical = 105000; + + /* For IMX6Q use OTP for thermal grade */ + if (data->socdata->version == TEMPMON_IMX6Q) { + ret = regmap_read(map, OCOTP_MEM0, &val); + if (ret) { + dev_err(&pdev->dev, "failed to read temp grade: %d\n", + ret); + return ret; + } + + if (val == 0 || val == ~0) { + dev_err(&pdev->dev, "invalid temp grade data\n"); + return -EINVAL; + } + + /* 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_critical = 95000; + break; + case 1: /* Extended Commercial (-20 to 105C) */ + data->temp_grade = "Extended Commercial"; + data->temp_critical = 105000; + break; + case 2: /* Industrial (-40 to 105C) */ + data->temp_grade = "Industrial"; + data->temp_critical = 105000; + break; + case 3: /* Automotive (-40 to 125C) */ + data->temp_grade = "Automotive"; + data->temp_critical = 125000; + break; + } + } /* - * The maximum die temperature set to 20 C higher than - * IMX_TEMP_PASSIVE. + * Set the default passive cooling trip point to critical - 20C + * (can be changed from userspace) */ - data->temp_critical = 1000 * 20 + data->temp_passive; + data->temp_passive = data->temp_critical - (1000 * 20); return 0; } @@ -559,6 +589,10 @@ static int imx_thermal_probe(struct platform_device *pdev) return ret; } + dev_info(&pdev->dev, "%s CPU temperature grade - " + "thresholds: crit:%ldC passive:%ldC\n", data->temp_grade, + 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 */