From patchwork Tue Oct 29 16:45:34 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Pascal Paillet X-Patchwork-Id: 11218265 Return-Path: Received: from mail.kernel.org (pdx-korg-mail-1.web.codeaurora.org [172.30.200.123]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 64C22112B for ; Tue, 29 Oct 2019 16:50:31 +0000 (UTC) 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 mail.kernel.org (Postfix) with ESMTPS id 3A43120830 for ; Tue, 29 Oct 2019 16:50:31 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=lists.infradead.org header.i=@lists.infradead.org header.b="gFbamHhc"; dkim=fail reason="signature verification failed" (2048-bit key) header.d=st.com header.i=@st.com header.b="NOm/Fr6/" DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 3A43120830 Authentication-Results: mail.kernel.org; dmarc=fail (p=none dis=none) header.from=st.com Authentication-Results: mail.kernel.org; spf=none smtp.mailfrom=linux-arm-kernel-bounces+patchwork-linux-arm=patchwork.kernel.org@lists.infradead.org DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20170209; h=Sender: Content-Transfer-Encoding:Content-Type:Cc:List-Subscribe:List-Help:List-Post: List-Archive:List-Unsubscribe:List-Id:MIME-Version:References:In-Reply-To: Message-ID:Date:Subject:To:From:Reply-To:Content-ID:Content-Description: Resent-Date:Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID: List-Owner; bh=cZmGWOa97p0VNNLqfQ3sshBEBlmQkIuSZhB8JT2wDpQ=; b=gFbamHhcb3DPWY 0NlKezFIDfEGDSUPPAxBWCXFT6sEcZJ+EbIpUE06eJuJ8jZSLNqqns8QGHHMWRNXK3g7RETziiAl/ O422YCcZr65WUHtNU0yJ4kCdyhNIRTomgbKQCB+z9PM7bYkBOBIS8tURQQwrvzwKEhpCJXLVrD0/P CzaAxl0ZRK+m8ObYxIZHTtIwFDgKaSUGj8+0EdYtylUBBflqng3whderDJv1gXVrslItnLbmAIvZ6 FXYWbijy+CEH4XgpGC9KwlbUAVf4xwa0I2WQ10Y9FpxioKbFrXBVCxsp/wUvryZZ1xXSCAELEdvbx qCUE0OJDHAfcyA9ByzlQ==; Received: from localhost ([127.0.0.1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.92.3 #3 (Red Hat Linux)) id 1iPUhR-0001fP-2e; Tue, 29 Oct 2019 16:50:29 +0000 Received: from mx07-00178001.pphosted.com ([62.209.51.94]) by bombadil.infradead.org with esmtps (Exim 4.92.3 #3 (Red Hat Linux)) id 1iPUd3-0004kS-N6 for linux-arm-kernel@lists.infradead.org; Tue, 29 Oct 2019 16:46:03 +0000 Received: from pps.filterd (m0046037.ppops.net [127.0.0.1]) by mx07-00178001.pphosted.com (8.16.0.42/8.16.0.42) with SMTP id x9TGhCLU011486; Tue, 29 Oct 2019 17:45:44 +0100 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=st.com; h=from : to : cc : subject : date : message-id : in-reply-to : references : mime-version : content-type; s=STMicroelectronics; bh=Yrqc3VV7V0g8I95k9AcWJcE8fDpK5QUBl1zPkRiabLs=; b=NOm/Fr6/eGqwkmQinF5k9jH8Vndjdc/qD1KlDeshDk44ib6zgs0wtfGMFMfOqkQeDK4k psobIbSbCY1t3ka1n97nJIMRtgsKQ17Do39UY294YkePDjVHkhJRVUkt8Dy5lbzzq4FD HnFjLxwwauIEp5+Zo/vGwN8ehHinFQ8wcW6y4JM2nMegS2QmBuoWVSO83Bm8tHcUoWWE 5JgwCwVZsiui7T0IbtUfPaHSlvfyrPe3lK9DsTLmoSBCzIg6ClhKvVVfKn0SxUkWlWT6 ITIscXxueoJ+6sYnrJakMGi1qBw67iJ2TYZhuyG78MvG6Q1nwoZ77T5MkCmA0510BBkN WQ== Received: from beta.dmz-eu.st.com (beta.dmz-eu.st.com [164.129.1.35]) by mx07-00178001.pphosted.com with ESMTP id 2vvbww8tn4-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Tue, 29 Oct 2019 17:45:44 +0100 Received: from euls16034.sgp.st.com (euls16034.sgp.st.com [10.75.44.20]) by beta.dmz-eu.st.com (STMicroelectronics) with ESMTP id 09F69100034; Tue, 29 Oct 2019 17:45:44 +0100 (CET) Received: from Webmail-eu.st.com (sfhdag6node2.st.com [10.75.127.17]) by euls16034.sgp.st.com (STMicroelectronics) with ESMTP id ED7C32A748A; Tue, 29 Oct 2019 17:45:43 +0100 (CET) Received: from localhost (10.75.127.49) by SFHDAG6NODE2.st.com (10.75.127.17) with Microsoft SMTP Server (TLS) id 15.0.1347.2; Tue, 29 Oct 2019 17:45:43 +0100 From: Pascal Paillet To: , , , , , , , , , , , , , , Subject: [PATCH 1/4] thermal: stm32: implement set_trips callback Date: Tue, 29 Oct 2019 17:45:34 +0100 Message-ID: <20191029164537.1561-2-p.paillet@st.com> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20191029164537.1561-1-p.paillet@st.com> References: <20191029164537.1561-1-p.paillet@st.com> MIME-Version: 1.0 X-Originating-IP: [10.75.127.49] X-ClientProxiedBy: SFHDAG2NODE3.st.com (10.75.127.6) To SFHDAG6NODE2.st.com (10.75.127.17) X-Proofpoint-Virus-Version: vendor=fsecure engine=2.50.10434:6.0.95,1.0.8 definitions=2019-10-29_05:2019-10-28,2019-10-29 signatures=0 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20191029_094558_147052_F711A01F X-CRM114-Status: GOOD ( 24.53 ) X-Spam-Score: -0.9 (/) X-Spam-Report: SpamAssassin version 3.4.2 on bombadil.infradead.org summary: Content analysis details: (-0.9 points) pts rule name description ---- ---------------------- -------------------------------------------------- -0.7 RCVD_IN_DNSWL_LOW RBL: Sender listed at https://www.dnswl.org/, low trust [62.209.51.94 listed in list.dnswl.org] -0.0 SPF_PASS SPF: sender matches SPF record 0.0 SPF_HELO_NONE SPF: HELO does not publish an SPF Record -0.1 DKIM_VALID_AU Message has a valid DKIM or DK signature from author's domain -0.1 DKIM_VALID_EF Message has a valid DKIM or DK signature from envelope-from domain 0.1 DKIM_SIGNED Message has a DKIM or DK signature, not necessarily valid -0.1 DKIM_VALID Message has at least one valid DKIM or DK signature X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: p.paillet@st.com Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+patchwork-linux-arm=patchwork.kernel.org@lists.infradead.org Implement set_trips() so that the trip points are managed by the thermal framework. The user is free to define any trip points he needs. Simplify interrupt handling. Signed-off-by: Pascal Paillet Change-Id: I2929d4fa5b4c5dca45cec7cb3b93fffc277394d2 --- drivers/thermal/st/stm_thermal.c | 370 +++++++++++-------------------- 1 file changed, 125 insertions(+), 245 deletions(-) diff --git a/drivers/thermal/st/stm_thermal.c b/drivers/thermal/st/stm_thermal.c index cf9ddc52f30e..0aae1cc14235 100644 --- a/drivers/thermal/st/stm_thermal.c +++ b/drivers/thermal/st/stm_thermal.c @@ -30,7 +30,7 @@ #define DTS_DR_OFFSET 0x1C #define DTS_SR_OFFSET 0x20 #define DTS_ITENR_OFFSET 0x24 -#define DTS_CIFR_OFFSET 0x28 +#define DTS_ICIFR_OFFSET 0x28 /* DTS_CFGR1 register mask definitions */ #define HSREF_CLK_DIV_MASK GENMASK(30, 24) @@ -51,10 +51,17 @@ /* DTS_DR register mask definitions */ #define TS1_MFREQ_MASK GENMASK(15, 0) +/* DTS_ITENR register mask definitions */ +#define ITENR_MASK (GENMASK(2, 0) | GENMASK(6, 4)) + +/* DTS_ICIFR register mask definitions */ +#define ICIFR_MASK (GENMASK(2, 0) | GENMASK(6, 4)) + /* Less significant bit position definitions */ #define TS1_T0_POS 16 #define TS1_SMP_TIME_POS 16 #define TS1_HITTHD_POS 16 +#define TS1_LITTHD_POS 0 #define HSREF_CLK_DIV_POS 24 /* DTS_CFGR1 bit definitions */ @@ -91,44 +98,59 @@ struct stm_thermal_sensor { struct thermal_zone_device *th_dev; enum thermal_device_mode mode; struct clk *clk; - int high_temp; - int low_temp; - int temp_critical; - int temp_passive; - unsigned int low_temp_enabled; - int num_trips; int irq; - unsigned int irq_enabled; void __iomem *base; int t0, fmt0, ramp_coeff; + int low_en, high_en; }; -static irqreturn_t stm_thermal_alarm_irq(int irq, void *sdata) +static void stm_thermal_disable_irq(struct stm_thermal_sensor *sensor) { - struct stm_thermal_sensor *sensor = sdata; + u32 itenr; + + /* Disable IT generation */ + itenr = readl_relaxed(sensor->base + DTS_ITENR_OFFSET); + itenr &= ~ITENR_MASK; + writel_relaxed(itenr, sensor->base + DTS_ITENR_OFFSET); +} + +static void stm_thermal_set_irq_state(struct stm_thermal_sensor *sensor) +{ + u32 itenr; + + dev_dbg(sensor->dev, "low:%d high:%d\n", sensor->low_en, + sensor->high_en); + + /* Disable IT generation for low and high thresholds */ + itenr = readl_relaxed(sensor->base + DTS_ITENR_OFFSET); + itenr &= ~(LOW_THRESHOLD | HIGH_THRESHOLD); + + if (sensor->low_en) + itenr |= HIGH_THRESHOLD; - disable_irq_nosync(irq); - sensor->irq_enabled = false; + if (sensor->high_en) + itenr |= LOW_THRESHOLD; - return IRQ_WAKE_THREAD; + /* Enable interrupts */ + writel_relaxed(itenr, sensor->base + DTS_ITENR_OFFSET); } static irqreturn_t stm_thermal_alarm_irq_thread(int irq, void *sdata) { - u32 value; struct stm_thermal_sensor *sensor = sdata; - /* read IT reason in SR and clear flags */ - value = readl_relaxed(sensor->base + DTS_SR_OFFSET); - - if ((value & LOW_THRESHOLD) == LOW_THRESHOLD) - writel_relaxed(LOW_THRESHOLD, sensor->base + DTS_CIFR_OFFSET); + dev_dbg(sensor->dev, "sr:%d\n", + readl_relaxed(sensor->base + DTS_SR_OFFSET)); - if ((value & HIGH_THRESHOLD) == HIGH_THRESHOLD) - writel_relaxed(HIGH_THRESHOLD, sensor->base + DTS_CIFR_OFFSET); + stm_thermal_disable_irq(sensor); thermal_zone_device_update(sensor->th_dev, THERMAL_EVENT_UNSPECIFIED); + stm_thermal_set_irq_state(sensor); + + /* Acknoledge all DTS irqs */ + writel_relaxed(ICIFR_MASK, sensor->base + DTS_ICIFR_OFFSET); + return IRQ_HANDLED; } @@ -160,6 +182,8 @@ static int stm_sensor_power_on(struct stm_thermal_sensor *sensor) writel_relaxed(value, sensor->base + DTS_CFGR1_OFFSET); + sensor->mode = THERMAL_DEVICE_ENABLED; + return 0; } @@ -167,6 +191,8 @@ static int stm_sensor_power_off(struct stm_thermal_sensor *sensor) { u32 value; + sensor->mode = THERMAL_DEVICE_DISABLED; + /* Stop measuring */ value = readl_relaxed(sensor->base + DTS_CFGR1_OFFSET); value &= ~TS1_START; @@ -285,118 +311,7 @@ static int stm_thermal_calculate_threshold(struct stm_thermal_sensor *sensor, *th *= sampling_time; - return 0; -} - -static int stm_thermal_set_threshold(struct stm_thermal_sensor *sensor) -{ - u32 value, th; - int ret; - - value = readl_relaxed(sensor->base + DTS_ITR1_OFFSET); - - /* Erase threshold content */ - value &= ~(TS1_LITTHD_MASK | TS1_HITTHD_MASK); - - /* Retrieve the sample threshold number th for a given temperature */ - ret = stm_thermal_calculate_threshold(sensor, sensor->high_temp, &th); - if (ret) - return ret; - - value |= th & TS1_LITTHD_MASK; - - if (sensor->low_temp_enabled) { - /* Retrieve the sample threshold */ - ret = stm_thermal_calculate_threshold(sensor, sensor->low_temp, - &th); - if (ret) - return ret; - - value |= (TS1_HITTHD_MASK & (th << TS1_HITTHD_POS)); - } - - /* Write value on the Low interrupt threshold */ - writel_relaxed(value, sensor->base + DTS_ITR1_OFFSET); - - return 0; -} - -/* Disable temperature interrupt */ -static int stm_disable_irq(struct stm_thermal_sensor *sensor) -{ - u32 value; - - /* Disable IT generation for low and high thresholds */ - value = readl_relaxed(sensor->base + DTS_ITENR_OFFSET); - writel_relaxed(value & ~(LOW_THRESHOLD | HIGH_THRESHOLD), - sensor->base + DTS_ITENR_OFFSET); - - dev_dbg(sensor->dev, "%s: IT disabled on sensor side", __func__); - - return 0; -} - -/* Enable temperature interrupt */ -static int stm_enable_irq(struct stm_thermal_sensor *sensor) -{ - u32 value; - - /* - * Code below enables High temperature threshold using a low threshold - * sampling value - */ - - /* Make sure LOW_THRESHOLD IT is clear before enabling */ - writel_relaxed(LOW_THRESHOLD, sensor->base + DTS_CIFR_OFFSET); - - /* Enable IT generation for low threshold */ - value = readl_relaxed(sensor->base + DTS_ITENR_OFFSET); - value |= LOW_THRESHOLD; - - /* Enable the low temperature threshold if needed */ - if (sensor->low_temp_enabled) { - /* Make sure HIGH_THRESHOLD IT is clear before enabling */ - writel_relaxed(HIGH_THRESHOLD, sensor->base + DTS_CIFR_OFFSET); - - /* Enable IT generation for high threshold */ - value |= HIGH_THRESHOLD; - } - - /* Enable thresholds */ - writel_relaxed(value, sensor->base + DTS_ITENR_OFFSET); - - dev_dbg(sensor->dev, "%s: IT enabled on sensor side", __func__); - - return 0; -} - -static int stm_thermal_update_threshold(struct stm_thermal_sensor *sensor) -{ - int ret; - - sensor->mode = THERMAL_DEVICE_DISABLED; - - ret = stm_sensor_power_off(sensor); - if (ret) - return ret; - - ret = stm_disable_irq(sensor); - if (ret) - return ret; - - ret = stm_thermal_set_threshold(sensor); - if (ret) - return ret; - - ret = stm_enable_irq(sensor); - if (ret) - return ret; - - ret = stm_sensor_power_on(sensor); - if (ret) - return ret; - - sensor->mode = THERMAL_DEVICE_ENABLED; + dev_dbg(sensor->dev, "freqM=%d Hz, threshold=0x%x", freqM, *th); return 0; } @@ -440,42 +355,54 @@ static int stm_thermal_get_temp(void *data, int *temp) *temp = mcelsius(sensor->t0 + ((freqM - sensor->fmt0) / sensor->ramp_coeff)); - dev_dbg(sensor->dev, "%s: temperature = %d millicelsius", - __func__, *temp); - - /* Update thresholds */ - if (sensor->num_trips > 1) { - /* Update alarm threshold value to next higher trip point */ - if (sensor->high_temp == sensor->temp_passive && - celsius(*temp) >= sensor->temp_passive) { - sensor->high_temp = sensor->temp_critical; - sensor->low_temp = sensor->temp_passive; - sensor->low_temp_enabled = true; - ret = stm_thermal_update_threshold(sensor); - if (ret) - return ret; - } - - if (sensor->high_temp == sensor->temp_critical && - celsius(*temp) < sensor->temp_passive) { - sensor->high_temp = sensor->temp_passive; - sensor->low_temp_enabled = false; - ret = stm_thermal_update_threshold(sensor); - if (ret) - return ret; - } - - /* - * Re-enable alarm IRQ if temperature below critical - * temperature - */ - if (!sensor->irq_enabled && - (celsius(*temp) < sensor->temp_critical)) { - sensor->irq_enabled = true; - enable_irq(sensor->irq); - } + dev_dbg(sensor->dev, "temperature = %d millicelsius", *temp); + + return 0; +} + +static int stm_thermal_set_trips(void *data, int low, int high) +{ + struct stm_thermal_sensor *sensor = data; + u32 itr1, th; + int ret; + + dev_dbg(sensor->dev, "set trips %d <--> %d\n", low, high); + + /* Erase threshold content */ + itr1 = readl_relaxed(sensor->base + DTS_ITR1_OFFSET); + itr1 &= ~(TS1_LITTHD_MASK | TS1_HITTHD_MASK); + + /* + * Disable low-temp if "low" is too small. As per thermal framework + * API, we use -INT_MAX rather than INT_MIN. + */ + + if (low > -INT_MAX) { + sensor->low_en = 1; + ret = stm_thermal_calculate_threshold(sensor, low, &th); + if (ret) + return ret; + + itr1 |= (TS1_HITTHD_MASK & (th << TS1_HITTHD_POS)); + } else { + sensor->low_en = 0; } + /* Disable high-temp if "high" is too big. */ + if (high < INT_MAX) { + sensor->high_en = 1; + ret = stm_thermal_calculate_threshold(sensor, high, &th); + if (ret) + return ret; + + itr1 |= (TS1_LITTHD_MASK & (th << TS1_LITTHD_POS)); + } else { + sensor->high_en = 0; + } + + /* Write new threshod values*/ + writel_relaxed(itr1, sensor->base + DTS_ITR1_OFFSET); + return 0; } @@ -493,8 +420,7 @@ static int stm_register_irq(struct stm_thermal_sensor *sensor) } ret = devm_request_threaded_irq(dev, sensor->irq, - stm_thermal_alarm_irq, - stm_thermal_alarm_irq_thread, + NULL, stm_thermal_alarm_irq_thread, IRQF_ONESHOT, dev->driver->name, sensor); if (ret) { @@ -503,8 +429,6 @@ static int stm_register_irq(struct stm_thermal_sensor *sensor) return ret; } - sensor->irq_enabled = true; - dev_dbg(dev, "%s: thermal IRQ registered", __func__); return 0; @@ -514,6 +438,8 @@ static int stm_thermal_sensor_off(struct stm_thermal_sensor *sensor) { int ret; + stm_thermal_disable_irq(sensor); + ret = stm_sensor_power_off(sensor); if (ret) return ret; @@ -526,7 +452,6 @@ static int stm_thermal_sensor_off(struct stm_thermal_sensor *sensor) static int stm_thermal_prepare(struct stm_thermal_sensor *sensor) { int ret; - struct device *dev = sensor->dev; ret = clk_prepare_enable(sensor->clk); if (ret) @@ -540,26 +465,8 @@ static int stm_thermal_prepare(struct stm_thermal_sensor *sensor) if (ret) goto thermal_unprepare; - /* Set threshold(s) for IRQ */ - ret = stm_thermal_set_threshold(sensor); - if (ret) - goto thermal_unprepare; - - ret = stm_enable_irq(sensor); - if (ret) - goto thermal_unprepare; - - ret = stm_sensor_power_on(sensor); - if (ret) { - dev_err(dev, "%s: failed to power on sensor\n", __func__); - goto irq_disable; - } - return 0; -irq_disable: - stm_disable_irq(sensor); - thermal_unprepare: clk_disable_unprepare(sensor->clk); @@ -576,8 +483,6 @@ static int stm_thermal_suspend(struct device *dev) if (ret) return ret; - sensor->mode = THERMAL_DEVICE_DISABLED; - return 0; } @@ -590,7 +495,12 @@ static int stm_thermal_resume(struct device *dev) if (ret) return ret; - sensor->mode = THERMAL_DEVICE_ENABLED; + ret = stm_sensor_power_on(sensor); + if (ret) + return ret; + + thermal_zone_device_update(sensor->th_dev, THERMAL_EVENT_UNSPECIFIED); + stm_thermal_set_irq_state(sensor); return 0; } @@ -600,6 +510,7 @@ SIMPLE_DEV_PM_OPS(stm_thermal_pm_ops, stm_thermal_suspend, stm_thermal_resume); static const struct thermal_zone_of_device_ops stm_tz_ops = { .get_temp = stm_thermal_get_temp, + .set_trips = stm_thermal_set_trips, }; static const struct of_device_id stm_thermal_of_match[] = { @@ -612,9 +523,8 @@ static int stm_thermal_probe(struct platform_device *pdev) { struct stm_thermal_sensor *sensor; struct resource *res; - const struct thermal_trip *trip; void __iomem *base; - int ret, i; + int ret; if (!pdev->dev.of_node) { dev_err(&pdev->dev, "%s: device tree node not found\n", @@ -645,10 +555,23 @@ static int stm_thermal_probe(struct platform_device *pdev) return PTR_ERR(sensor->clk); } - /* Register IRQ into GIC */ - ret = stm_register_irq(sensor); - if (ret) + stm_thermal_disable_irq(sensor); + + /* Clear irq flags */ + writel_relaxed(ICIFR_MASK, sensor->base + DTS_ICIFR_OFFSET); + + /* Configure and enable HW sensor */ + ret = stm_thermal_prepare(sensor); + if (ret) { + dev_err(&pdev->dev, "Error preprare sensor: %d\n", ret); return ret; + } + + ret = stm_sensor_power_on(sensor); + if (ret) { + dev_err(&pdev->dev, "Error power on sensor: %d\n", ret); + return ret; + } sensor->th_dev = devm_thermal_zone_of_sensor_register(&pdev->dev, 0, sensor, @@ -661,53 +584,12 @@ static int stm_thermal_probe(struct platform_device *pdev) return ret; } - if (!sensor->th_dev->ops->get_crit_temp) { - /* Critical point must be provided */ - ret = -EINVAL; - goto err_tz; - } - - ret = sensor->th_dev->ops->get_crit_temp(sensor->th_dev, - &sensor->temp_critical); - if (ret) { - dev_err(&pdev->dev, - "Not able to read critical_temp: %d\n", ret); + /* Register IRQ into GIC */ + ret = stm_register_irq(sensor); + if (ret) goto err_tz; - } - sensor->temp_critical = celsius(sensor->temp_critical); - - /* Set thresholds for IRQ */ - sensor->high_temp = sensor->temp_critical; - - trip = of_thermal_get_trip_points(sensor->th_dev); - sensor->num_trips = of_thermal_get_ntrips(sensor->th_dev); - - /* Find out passive temperature if it exists */ - for (i = (sensor->num_trips - 1); i >= 0; i--) { - if (trip[i].type == THERMAL_TRIP_PASSIVE) { - sensor->temp_passive = celsius(trip[i].temperature); - /* Update high temperature threshold */ - sensor->high_temp = sensor->temp_passive; - } - } - - /* - * Ensure low_temp_enabled flag is disabled. - * By disabling low_temp_enabled, low threshold IT will not be - * configured neither enabled because it is not needed as high - * threshold is set on the lowest temperature trip point after - * probe. - */ - sensor->low_temp_enabled = false; - - /* Configure and enable HW sensor */ - ret = stm_thermal_prepare(sensor); - if (ret) { - dev_err(&pdev->dev, - "Not able to enable sensor: %d\n", ret); - goto err_tz; - } + stm_thermal_set_irq_state(sensor); /* * Thermal_zone doesn't enable hwmon as default, @@ -718,8 +600,6 @@ static int stm_thermal_probe(struct platform_device *pdev) if (ret) goto err_tz; - sensor->mode = THERMAL_DEVICE_ENABLED; - dev_info(&pdev->dev, "%s: Driver initialized successfully\n", __func__); From patchwork Tue Oct 29 16:45:35 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Pascal Paillet X-Patchwork-Id: 11218259 Return-Path: Received: from mail.kernel.org (pdx-korg-mail-1.web.codeaurora.org [172.30.200.123]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 14136112B for ; Tue, 29 Oct 2019 16:49:37 +0000 (UTC) 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 mail.kernel.org (Postfix) with ESMTPS id E47F420830 for ; Tue, 29 Oct 2019 16:49:36 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=lists.infradead.org header.i=@lists.infradead.org header.b="lSFmkwaz"; dkim=fail reason="signature verification failed" (2048-bit key) header.d=st.com header.i=@st.com header.b="t6qvVNmC" DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org E47F420830 Authentication-Results: mail.kernel.org; dmarc=fail (p=none dis=none) header.from=st.com Authentication-Results: mail.kernel.org; spf=none smtp.mailfrom=linux-arm-kernel-bounces+patchwork-linux-arm=patchwork.kernel.org@lists.infradead.org DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20170209; h=Sender: Content-Transfer-Encoding:Content-Type:Cc:List-Subscribe:List-Help:List-Post: List-Archive:List-Unsubscribe:List-Id:MIME-Version:References:In-Reply-To: Message-ID:Date:Subject:To:From:Reply-To:Content-ID:Content-Description: Resent-Date:Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID: List-Owner; bh=5YOWLiFsXPXS0QiVYz6zBamwnBUoW3WbVghX59qZ9YU=; b=lSFmkwaz+SYlXv iqBOXu4lPtx2gi5hE+cJDwCHacA49rqN6cGszHfLyW/C+n4pnewVTjefR9L09iLVV/rs1wew9zO5n bMMosdNWHWXlUJHofwNRtYoMZoj9jz3OYPSVTxT346DR8SawZ06sYZLd9FvSbqFvwAIo8nhW9MWlN 7fNzZxZoHpWKSKQu3YOak3liEHbet9ZcGkGib147t4/tzPei3VNHOC1/EbxaBCN+aIGcAonPadqz3 pfRZ9zQfXia8S4q0zTbKcaQRc4BEbxThNG36FDhOaMl++dCyvC42Tmt3pBCdCFC6PN1Q+1WS8+sKH shw0btM7Y4z3p0dzUerw==; Received: from localhost ([127.0.0.1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.92.3 #3 (Red Hat Linux)) id 1iPUgY-00088r-Ra; Tue, 29 Oct 2019 16:49:34 +0000 Received: from mx07-00178001.pphosted.com ([62.209.51.94]) by bombadil.infradead.org with esmtps (Exim 4.92.3 #3 (Red Hat Linux)) id 1iPUd3-0004kP-G3 for linux-arm-kernel@lists.infradead.org; Tue, 29 Oct 2019 16:46:01 +0000 Received: from pps.filterd (m0046668.ppops.net [127.0.0.1]) by mx07-00178001.pphosted.com (8.16.0.42/8.16.0.42) with SMTP id x9TGhXa2026559; Tue, 29 Oct 2019 17:45:45 +0100 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=st.com; h=from : to : cc : subject : date : message-id : in-reply-to : references : mime-version : content-type; s=STMicroelectronics; bh=cUNYleQOTDVYQ2kHeqm4eAjJNxaCQ04tYu9otVBG33M=; b=t6qvVNmCbyVwbLydDiLqxFcdzWvqEScCxt31fTLVerLjU2PZEIXSJ777akiQQUE3CFlZ y1ghwEYLI13DZdNHTJruAgW+c1HMPF5mHHfDj5DwWUU3B9+p84kKt0vnkUOe+w+t5O8I pxfKRICCTiHPn1oScsABlEPgqG+Vg5gtGAotX36LXFTO2+BC94DjBTETTmJoCxjdi2EE KlH2HCmuJ682lRZBresYUbjbmxxPGEFjKTeRGXcvxAZ/zbhwim5N9L5i3ajNcVrBIRMb 28V7aAS7Ao5I0CEuvQo9uQor95snjbYv2C02L1NwcG/dvAOkr0KGLRv5Ra6QWhJfN/43 jA== Received: from beta.dmz-eu.st.com (beta.dmz-eu.st.com [164.129.1.35]) by mx07-00178001.pphosted.com with ESMTP id 2vvbm0gwdb-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Tue, 29 Oct 2019 17:45:45 +0100 Received: from euls16034.sgp.st.com (euls16034.sgp.st.com [10.75.44.20]) by beta.dmz-eu.st.com (STMicroelectronics) with ESMTP id BFD34100034; Tue, 29 Oct 2019 17:45:44 +0100 (CET) Received: from Webmail-eu.st.com (sfhdag6node2.st.com [10.75.127.17]) by euls16034.sgp.st.com (STMicroelectronics) with ESMTP id AE8C62A748A; Tue, 29 Oct 2019 17:45:44 +0100 (CET) Received: from localhost (10.75.127.49) by SFHDAG6NODE2.st.com (10.75.127.17) with Microsoft SMTP Server (TLS) id 15.0.1347.2; Tue, 29 Oct 2019 17:45:44 +0100 From: Pascal Paillet To: , , , , , , , , , , , , , , Subject: [PATCH 2/4] thermal: stm32: fix IRQ flood on low threshold Date: Tue, 29 Oct 2019 17:45:35 +0100 Message-ID: <20191029164537.1561-3-p.paillet@st.com> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20191029164537.1561-1-p.paillet@st.com> References: <20191029164537.1561-1-p.paillet@st.com> MIME-Version: 1.0 X-Originating-IP: [10.75.127.49] X-ClientProxiedBy: SFHDAG2NODE1.st.com (10.75.127.4) To SFHDAG6NODE2.st.com (10.75.127.17) X-Proofpoint-Virus-Version: vendor=fsecure engine=2.50.10434:6.0.95,1.0.8 definitions=2019-10-29_05:2019-10-28,2019-10-29 signatures=0 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20191029_094557_968074_32CCD6CC X-CRM114-Status: GOOD ( 18.57 ) X-Spam-Score: -0.9 (/) X-Spam-Report: SpamAssassin version 3.4.2 on bombadil.infradead.org summary: Content analysis details: (-0.9 points) pts rule name description ---- ---------------------- -------------------------------------------------- -0.7 RCVD_IN_DNSWL_LOW RBL: Sender listed at https://www.dnswl.org/, low trust [62.209.51.94 listed in list.dnswl.org] -0.0 SPF_PASS SPF: sender matches SPF record 0.0 SPF_HELO_NONE SPF: HELO does not publish an SPF Record -0.1 DKIM_VALID_AU Message has a valid DKIM or DK signature from author's domain -0.1 DKIM_VALID_EF Message has a valid DKIM or DK signature from envelope-from domain 0.1 DKIM_SIGNED Message has a DKIM or DK signature, not necessarily valid -0.1 DKIM_VALID Message has at least one valid DKIM or DK signature X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: p.paillet@st.com Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+patchwork-linux-arm=patchwork.kernel.org@lists.infradead.org Fix IRQ flood on low threshold by too ways: - improve temperature reading resolution, - add an hysteresis to the low threshold: on low threshold interrupt, it is not possible to get the temperature value that has fired the interrupt. The time to acquire a new value is enough for the CPU to become hotter than the current low threshold. Signed-off-by: Pascal Paillet Change-Id: I3b63b8aab38fd651a165c4e69a2d090b3c6f5db3 --- drivers/thermal/st/stm_thermal.c | 73 +++++++++----------------------- 1 file changed, 19 insertions(+), 54 deletions(-) diff --git a/drivers/thermal/st/stm_thermal.c b/drivers/thermal/st/stm_thermal.c index 0aae1cc14235..4bc1bbece0de 100644 --- a/drivers/thermal/st/stm_thermal.c +++ b/drivers/thermal/st/stm_thermal.c @@ -59,7 +59,6 @@ /* Less significant bit position definitions */ #define TS1_T0_POS 16 -#define TS1_SMP_TIME_POS 16 #define TS1_HITTHD_POS 16 #define TS1_LITTHD_POS 0 #define HSREF_CLK_DIV_POS 24 @@ -83,15 +82,10 @@ #define ONE_MHZ 1000000 #define POLL_TIMEOUT 5000 #define STARTUP_TIME 40 -#define TS1_T0_VAL0 30 -#define TS1_T0_VAL1 130 +#define TS1_T0_VAL0 30000 /* 30 celsius */ +#define TS1_T0_VAL1 130000 /* 130 celsius */ #define NO_HW_TRIG 0 - -/* The Thermal Framework expects millidegrees */ -#define mcelsius(temp) ((temp) * 1000) - -/* The Sensor expects oC degrees */ -#define celsius(temp) ((temp) / 1000) +#define SAMPLING_TIME 15 struct stm_thermal_sensor { struct device *dev; @@ -222,12 +216,8 @@ static int stm_thermal_calibration(struct stm_thermal_sensor *sensor) if (!clk_freq) return -EINVAL; - prescaler = 0; - clk_freq /= ONE_MHZ; - if (clk_freq) { - while (prescaler <= clk_freq) - prescaler++; - } + /* calculate divider for maximum 1MHz PCLK */ + prescaler = clk_freq / ONE_MHZ + 1; value = readl_relaxed(sensor->base + DTS_CFGR1_OFFSET); @@ -235,7 +225,7 @@ static int stm_thermal_calibration(struct stm_thermal_sensor *sensor) value &= ~HSREF_CLK_DIV_MASK; /* Set prescaler. pclk_freq/prescaler < 1MHz */ - value |= (prescaler << HSREF_CLK_DIV_POS); + value |= (prescaler << HSREF_CLK_DIV_POS) & HSREF_CLK_DIV_MASK; /* Select PCLK as reference clock */ value &= ~REFCLK_SEL; @@ -289,28 +279,16 @@ static int stm_thermal_calculate_threshold(struct stm_thermal_sensor *sensor, int temp, u32 *th) { int freqM; - u32 sampling_time; - - /* Retrieve the number of periods to sample */ - sampling_time = (readl_relaxed(sensor->base + DTS_CFGR1_OFFSET) & - TS1_SMP_TIME_MASK) >> TS1_SMP_TIME_POS; /* Figure out the CLK_PTAT frequency for a given temperature */ - freqM = ((temp - sensor->t0) * sensor->ramp_coeff) - + sensor->fmt0; - - dev_dbg(sensor->dev, "%s: freqM for threshold = %d Hz", - __func__, freqM); + freqM = ((temp - sensor->t0) * sensor->ramp_coeff) / 1000 + + sensor->fmt0; /* Figure out the threshold sample number */ - *th = clk_get_rate(sensor->clk); + *th = clk_get_rate(sensor->clk) * SAMPLING_TIME / freqM; if (!*th) return -EINVAL; - *th = *th / freqM; - - *th *= sampling_time; - dev_dbg(sensor->dev, "freqM=%d Hz, threshold=0x%x", freqM, *th); return 0; @@ -320,42 +298,28 @@ static int stm_thermal_calculate_threshold(struct stm_thermal_sensor *sensor, static int stm_thermal_get_temp(void *data, int *temp) { struct stm_thermal_sensor *sensor = data; - u32 sampling_time; + u32 periods; int freqM, ret; if (sensor->mode != THERMAL_DEVICE_ENABLED) return -EAGAIN; - /* Retrieve the number of samples */ - ret = readl_poll_timeout(sensor->base + DTS_DR_OFFSET, freqM, - (freqM & TS1_MFREQ_MASK), STARTUP_TIME, - POLL_TIMEOUT); - + /* Retrieve the number of periods sampled */ + ret = readl_relaxed_poll_timeout(sensor->base + DTS_DR_OFFSET, periods, + (periods & TS1_MFREQ_MASK), + STARTUP_TIME, POLL_TIMEOUT); if (ret) return ret; - if (!freqM) - return -ENODATA; - - /* Retrieve the number of periods sampled */ - sampling_time = (readl_relaxed(sensor->base + DTS_CFGR1_OFFSET) & - TS1_SMP_TIME_MASK) >> TS1_SMP_TIME_POS; - - /* Figure out the number of samples per period */ - freqM /= sampling_time; - /* Figure out the CLK_PTAT frequency */ - freqM = clk_get_rate(sensor->clk) / freqM; + freqM = (clk_get_rate(sensor->clk) * SAMPLING_TIME) / periods; if (!freqM) return -EINVAL; - dev_dbg(sensor->dev, "%s: freqM=%d\n", __func__, freqM); - /* Figure out the temperature in mili celsius */ - *temp = mcelsius(sensor->t0 + ((freqM - sensor->fmt0) / - sensor->ramp_coeff)); + *temp = (freqM - sensor->fmt0) * 1000 / sensor->ramp_coeff + sensor->t0; - dev_dbg(sensor->dev, "temperature = %d millicelsius", *temp); + dev_dbg(sensor->dev, "periods=0x%x t=%d mC", periods, *temp); return 0; } @@ -379,7 +343,8 @@ static int stm_thermal_set_trips(void *data, int low, int high) if (low > -INT_MAX) { sensor->low_en = 1; - ret = stm_thermal_calculate_threshold(sensor, low, &th); + /* add 0.5 of hysteresis due to measurement error */ + ret = stm_thermal_calculate_threshold(sensor, low - 500, &th); if (ret) return ret; From patchwork Tue Oct 29 16:45:36 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Pascal Paillet X-Patchwork-Id: 11218263 Return-Path: Received: from mail.kernel.org (pdx-korg-mail-1.web.codeaurora.org [172.30.200.123]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 06866112B for ; Tue, 29 Oct 2019 16:50:19 +0000 (UTC) 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 mail.kernel.org (Postfix) with ESMTPS id D73DF21479 for ; Tue, 29 Oct 2019 16:50:18 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=lists.infradead.org header.i=@lists.infradead.org header.b="OPDzk93+"; dkim=fail reason="signature verification failed" (2048-bit key) header.d=st.com header.i=@st.com header.b="lqmOI5eT" DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org D73DF21479 Authentication-Results: mail.kernel.org; dmarc=fail (p=none dis=none) header.from=st.com Authentication-Results: mail.kernel.org; spf=none smtp.mailfrom=linux-arm-kernel-bounces+patchwork-linux-arm=patchwork.kernel.org@lists.infradead.org DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20170209; h=Sender: Content-Transfer-Encoding:Content-Type:Cc:List-Subscribe:List-Help:List-Post: List-Archive:List-Unsubscribe:List-Id:MIME-Version:References:In-Reply-To: Message-ID:Date:Subject:To:From:Reply-To:Content-ID:Content-Description: Resent-Date:Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID: List-Owner; bh=XHJN68T+m1tzkFxoxmeP6y5WYeA3mxnAM26hCS1a4Ak=; b=OPDzk93+sscs8N lEgFyduXxQACdPsmFoNdLH7EYwsQTOeBBTKUwLd1IPo5jWQrxgdwOPhO8tu21yrTt/hogwpjX4DM2 zFZxdk/tgAdrC+GzxBD1qJMrcUvbzcQnccGFVQ8L3+kQk5tDS3Ftb1nOSevPECZlICHrpil2jnn8j /AP4+f5F+O/Dx+jI2izH00BaQ6K4XriS1AL8I4kl6IHGx5E2I5HJrdV+e5W6Q8jKFyEY2lFs9MBDk DLe3C4wlt1ejc2UmGZW0gx+C1YeO5YDJZW5602uJMmcNzFNvUPBXifrJXuDy38+9bOnGysw6aOkaH BFRmCJn29nH+QbEvoXwg==; Received: from localhost ([127.0.0.1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.92.3 #3 (Red Hat Linux)) id 1iPUhD-0001Tb-P0; Tue, 29 Oct 2019 16:50:15 +0000 Received: from mx07-00178001.pphosted.com ([62.209.51.94]) by bombadil.infradead.org with esmtps (Exim 4.92.3 #3 (Red Hat Linux)) id 1iPUd3-0004kT-Rg for linux-arm-kernel@lists.infradead.org; Tue, 29 Oct 2019 16:46:01 +0000 Received: from pps.filterd (m0046037.ppops.net [127.0.0.1]) by mx07-00178001.pphosted.com (8.16.0.42/8.16.0.42) with SMTP id x9TGhCLW011486; Tue, 29 Oct 2019 17:45:46 +0100 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=st.com; h=from : to : cc : subject : date : message-id : in-reply-to : references : mime-version : content-type; s=STMicroelectronics; bh=92G5zptu/BKdiJ/91ipkjy88pDUEE0M92MQEthDZ4Bk=; b=lqmOI5eT2E2ok6TTbsDFq80hzIuZPJR0ek81UttTo0T+ZyrGy4F78IjQiu96mBkXZezH SYRjxHNiZgttrBNkGEJFrbwWw0U3CttXPjsLi7IElcIaHK6t+u1DsfNKhaZDiXhflwym 9a2ub13RaTlC5L2XrpE9FJRhukvlu5JGzcnZjzRY9+j0hEotsMkENLOZ3dbTwFDNOt3M 7Zq75itVQlTNh9tGRfhlR1OsJiQjHSI2NRjbQEpURd3HlIy60JGSzUnPvuHf3eT1ptwx ZwQ9StWI+0lCTtc127OfK3RQ0iqD1sW0xHAVsWflVS6Ff0Rfjjlcc+YidhIESCApC2PF eQ== Received: from beta.dmz-eu.st.com (beta.dmz-eu.st.com [164.129.1.35]) by mx07-00178001.pphosted.com with ESMTP id 2vvbww8tn9-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Tue, 29 Oct 2019 17:45:45 +0100 Received: from euls16034.sgp.st.com (euls16034.sgp.st.com [10.75.44.20]) by beta.dmz-eu.st.com (STMicroelectronics) with ESMTP id 761D510002A; Tue, 29 Oct 2019 17:45:45 +0100 (CET) Received: from Webmail-eu.st.com (sfhdag6node2.st.com [10.75.127.17]) by euls16034.sgp.st.com (STMicroelectronics) with ESMTP id 654DF2A748A; Tue, 29 Oct 2019 17:45:45 +0100 (CET) Received: from localhost (10.75.127.51) by SFHDAG6NODE2.st.com (10.75.127.17) with Microsoft SMTP Server (TLS) id 15.0.1347.2; Tue, 29 Oct 2019 17:45:45 +0100 From: Pascal Paillet To: , , , , , , , , , , , , , , Subject: [PATCH 3/4] thermal: stm32: fix engineering calibration value Date: Tue, 29 Oct 2019 17:45:36 +0100 Message-ID: <20191029164537.1561-4-p.paillet@st.com> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20191029164537.1561-1-p.paillet@st.com> References: <20191029164537.1561-1-p.paillet@st.com> MIME-Version: 1.0 X-Originating-IP: [10.75.127.51] X-ClientProxiedBy: SFHDAG6NODE3.st.com (10.75.127.18) To SFHDAG6NODE2.st.com (10.75.127.17) X-Proofpoint-Virus-Version: vendor=fsecure engine=2.50.10434:6.0.95,1.0.8 definitions=2019-10-29_05:2019-10-28,2019-10-29 signatures=0 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20191029_094558_263816_46E5C5CB X-CRM114-Status: GOOD ( 15.76 ) X-Spam-Score: -0.9 (/) X-Spam-Report: SpamAssassin version 3.4.2 on bombadil.infradead.org summary: Content analysis details: (-0.9 points) pts rule name description ---- ---------------------- -------------------------------------------------- -0.7 RCVD_IN_DNSWL_LOW RBL: Sender listed at https://www.dnswl.org/, low trust [62.209.51.94 listed in list.dnswl.org] -0.0 SPF_PASS SPF: sender matches SPF record 0.0 SPF_HELO_NONE SPF: HELO does not publish an SPF Record -0.1 DKIM_VALID_AU Message has a valid DKIM or DK signature from author's domain -0.1 DKIM_VALID_EF Message has a valid DKIM or DK signature from envelope-from domain 0.1 DKIM_SIGNED Message has a DKIM or DK signature, not necessarily valid -0.1 DKIM_VALID Message has at least one valid DKIM or DK signature X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: p.paillet@st.com Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+patchwork-linux-arm=patchwork.kernel.org@lists.infradead.org TS1_T0 is only used by engineering during calibration. The temperature offset is actually fixed to 30 Celsius. Signed-off-by: Pascal Paillet Change-Id: I83abea65ff3f58f8954256495f2d5d38f0d868d9 --- drivers/thermal/st/stm_thermal.c | 22 ++++++---------------- 1 file changed, 6 insertions(+), 16 deletions(-) diff --git a/drivers/thermal/st/stm_thermal.c b/drivers/thermal/st/stm_thermal.c index 4bc1bbece0de..37abbdffe573 100644 --- a/drivers/thermal/st/stm_thermal.c +++ b/drivers/thermal/st/stm_thermal.c @@ -82,8 +82,7 @@ #define ONE_MHZ 1000000 #define POLL_TIMEOUT 5000 #define STARTUP_TIME 40 -#define TS1_T0_VAL0 30000 /* 30 celsius */ -#define TS1_T0_VAL1 130000 /* 130 celsius */ +#define T0 30000 /* 30 celsius */ #define NO_HW_TRIG 0 #define SAMPLING_TIME 15 @@ -94,7 +93,7 @@ struct stm_thermal_sensor { struct clk *clk; int irq; void __iomem *base; - int t0, fmt0, ramp_coeff; + int fmt0, ramp_coeff; int low_en, high_en; }; @@ -248,14 +247,6 @@ static int stm_thermal_calibration(struct stm_thermal_sensor *sensor) /* Fill in DTS structure with factory sensor values */ static int stm_thermal_read_factory_settings(struct stm_thermal_sensor *sensor) { - /* Retrieve engineering calibration temperature */ - sensor->t0 = readl_relaxed(sensor->base + DTS_T0VALR1_OFFSET) & - TS1_T0_MASK; - if (!sensor->t0) - sensor->t0 = TS1_T0_VAL0; - else - sensor->t0 = TS1_T0_VAL1; - /* Retrieve fmt0 and put it on Hz */ sensor->fmt0 = ADJUST * (readl_relaxed(sensor->base + DTS_T0VALR1_OFFSET) & TS1_FMT0_MASK); @@ -269,8 +260,8 @@ static int stm_thermal_read_factory_settings(struct stm_thermal_sensor *sensor) return -EINVAL; } - dev_dbg(sensor->dev, "%s: T0 = %doC, FMT0 = %dHz, RAMP_COEFF = %dHz/oC", - __func__, sensor->t0, sensor->fmt0, sensor->ramp_coeff); + dev_dbg(sensor->dev, "%s: FMT0 = %dHz, RAMP_COEFF = %dHz/oC", + __func__, sensor->fmt0, sensor->ramp_coeff); return 0; } @@ -281,8 +272,7 @@ static int stm_thermal_calculate_threshold(struct stm_thermal_sensor *sensor, int freqM; /* Figure out the CLK_PTAT frequency for a given temperature */ - freqM = ((temp - sensor->t0) * sensor->ramp_coeff) / 1000 + - sensor->fmt0; + freqM = ((temp - T0) * sensor->ramp_coeff) / 1000 + sensor->fmt0; /* Figure out the threshold sample number */ *th = clk_get_rate(sensor->clk) * SAMPLING_TIME / freqM; @@ -317,7 +307,7 @@ static int stm_thermal_get_temp(void *data, int *temp) return -EINVAL; /* Figure out the temperature in mili celsius */ - *temp = (freqM - sensor->fmt0) * 1000 / sensor->ramp_coeff + sensor->t0; + *temp = (freqM - sensor->fmt0) * 1000 / sensor->ramp_coeff + T0; dev_dbg(sensor->dev, "periods=0x%x t=%d mC", periods, *temp); From patchwork Tue Oct 29 16:45:37 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Pascal Paillet X-Patchwork-Id: 11218257 Return-Path: Received: from mail.kernel.org (pdx-korg-mail-1.web.codeaurora.org [172.30.200.123]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 25ABB112B for ; Tue, 29 Oct 2019 16:49:21 +0000 (UTC) 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 mail.kernel.org (Postfix) with ESMTPS id C6E5720830 for ; Tue, 29 Oct 2019 16:49:20 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=lists.infradead.org header.i=@lists.infradead.org header.b="unpLW5oA"; dkim=fail reason="signature verification failed" (2048-bit key) header.d=st.com header.i=@st.com header.b="cepqO2/6" DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org C6E5720830 Authentication-Results: mail.kernel.org; dmarc=fail (p=none dis=none) header.from=st.com Authentication-Results: mail.kernel.org; spf=none smtp.mailfrom=linux-arm-kernel-bounces+patchwork-linux-arm=patchwork.kernel.org@lists.infradead.org DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20170209; h=Sender: Content-Transfer-Encoding:Content-Type:Cc:List-Subscribe:List-Help:List-Post: List-Archive:List-Unsubscribe:List-Id:MIME-Version:References:In-Reply-To: Message-ID:Date:Subject:To:From:Reply-To:Content-ID:Content-Description: Resent-Date:Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID: List-Owner; bh=dh6FUsYAc/7l2T2WgHfRAdI160ARBJdpAkOGTo06D/0=; b=unpLW5oAiDXBij 2p0/9O3ejBENYw4lLcwjA42Y5xsuVIX2SbpFJrLhtOhioMLXTGhTvIwAKk+SZ69cXEQn/gy4pbUmc QPLkng/ueL+4pzJDos8hwM5cXlF9APIyjwEweg1VqLi5zgs7gV9KLOlMOUVmE3OPIazfFEdnMUB/B 4f9hx+0UNrwEPiCHtsbAmEwTe8nuFcpO95M7CLWTcUP8p3+H1ybowdr2psyGsRXT/xBCQfPxWnzqq WjEmkn9qLYpMmrb6QeGIi7xcLK/Y8l29dfOIIo40w2MbutVDiyZzis+CekK/IJ09MNx/rUtEHVDoc PbSeMSp4ZtjPYQiA8X8A==; Received: from localhost ([127.0.0.1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.92.3 #3 (Red Hat Linux)) id 1iPUgI-0007tU-9q; Tue, 29 Oct 2019 16:49:18 +0000 Received: from mx07-00178001.pphosted.com ([62.209.51.94]) by bombadil.infradead.org with esmtps (Exim 4.92.3 #3 (Red Hat Linux)) id 1iPUd3-0004kR-G4 for linux-arm-kernel@lists.infradead.org; Tue, 29 Oct 2019 16:45:59 +0000 Received: from pps.filterd (m0046668.ppops.net [127.0.0.1]) by mx07-00178001.pphosted.com (8.16.0.42/8.16.0.42) with SMTP id x9TGgwJm026459; Tue, 29 Oct 2019 17:45:46 +0100 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=st.com; h=from : to : cc : subject : date : message-id : in-reply-to : references : mime-version : content-type; s=STMicroelectronics; bh=UqBLShJCTgixGdbgFzma65RAxEtmlze/XM6cp3uTtSQ=; b=cepqO2/65Lz5Bhz53U3SzJUY4oirqjrlIoH/Xf+rSA2N//WoxU5JLEhRHpUN3ewF7gGZ CBifsmb2jZkxvxCRk8n3NH/w6WvggYteTIFuPgl+Ud0KoO634ZIP6zVBpoyMXtaif00o peULpGUwSho/30zIo6YEpkwg/Ixy9v/wUzSaTEW3a9RCxLVSCgx0/2WU1NwetLjsL0mY r2jaah/jM/2cfkZuQzhOp7kmTAni0V+sD3FE/kgc2QjBzT/eF/rAGYDX+FpPDvBWyUck 46adMW/HVVtT+QfANEaVFtVds4QZt0/vSNpOTknykhlkI6+u8espWryGMyR47znJEL+k Bw== Received: from beta.dmz-eu.st.com (beta.dmz-eu.st.com [164.129.1.35]) by mx07-00178001.pphosted.com with ESMTP id 2vvbm0gwdg-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Tue, 29 Oct 2019 17:45:46 +0100 Received: from euls16034.sgp.st.com (euls16034.sgp.st.com [10.75.44.20]) by beta.dmz-eu.st.com (STMicroelectronics) with ESMTP id 6704810002A; Tue, 29 Oct 2019 17:45:46 +0100 (CET) Received: from Webmail-eu.st.com (sfhdag6node2.st.com [10.75.127.17]) by euls16034.sgp.st.com (STMicroelectronics) with ESMTP id 56EFE2A748A; Tue, 29 Oct 2019 17:45:46 +0100 (CET) Received: from localhost (10.75.127.50) by SFHDAG6NODE2.st.com (10.75.127.17) with Microsoft SMTP Server (TLS) id 15.0.1347.2; Tue, 29 Oct 2019 17:45:45 +0100 From: Pascal Paillet To: , , , , , , , , , , , , , , Subject: [PATCH 4/4] ARM: dts: stm32: remove thermal passive trip point on stm32mp157c Date: Tue, 29 Oct 2019 17:45:37 +0100 Message-ID: <20191029164537.1561-5-p.paillet@st.com> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20191029164537.1561-1-p.paillet@st.com> References: <20191029164537.1561-1-p.paillet@st.com> MIME-Version: 1.0 X-Originating-IP: [10.75.127.50] X-ClientProxiedBy: SFHDAG8NODE3.st.com (10.75.127.24) To SFHDAG6NODE2.st.com (10.75.127.17) X-Proofpoint-Virus-Version: vendor=fsecure engine=2.50.10434:6.0.95,1.0.8 definitions=2019-10-29_05:2019-10-28,2019-10-29 signatures=0 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20191029_094557_958351_D398FD86 X-CRM114-Status: GOOD ( 12.00 ) X-Spam-Score: -0.9 (/) X-Spam-Report: SpamAssassin version 3.4.2 on bombadil.infradead.org summary: Content analysis details: (-0.9 points) pts rule name description ---- ---------------------- -------------------------------------------------- -0.7 RCVD_IN_DNSWL_LOW RBL: Sender listed at https://www.dnswl.org/, low trust [62.209.51.94 listed in list.dnswl.org] -0.0 SPF_PASS SPF: sender matches SPF record 0.0 SPF_HELO_NONE SPF: HELO does not publish an SPF Record -0.1 DKIM_VALID_AU Message has a valid DKIM or DK signature from author's domain -0.1 DKIM_VALID_EF Message has a valid DKIM or DK signature from envelope-from domain 0.1 DKIM_SIGNED Message has a DKIM or DK signature, not necessarily valid -0.1 DKIM_VALID Message has at least one valid DKIM or DK signature X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: p.paillet@st.com Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+patchwork-linux-arm=patchwork.kernel.org@lists.infradead.org Remove thermal passive trip point. Signed-off-by: Pascal Paillet Change-Id: I494313cf467eea491236e73bd2fbe1803345586f --- arch/arm/boot/dts/stm32mp157c.dtsi | 6 ------ 1 file changed, 6 deletions(-) diff --git a/arch/arm/boot/dts/stm32mp157c.dtsi b/arch/arm/boot/dts/stm32mp157c.dtsi index 9b11654a0a39..799b2aedd2c9 100644 --- a/arch/arm/boot/dts/stm32mp157c.dtsi +++ b/arch/arm/boot/dts/stm32mp157c.dtsi @@ -91,12 +91,6 @@ thermal-sensors = <&dts>; trips { - cpu_alert1: cpu-alert1 { - temperature = <85000>; - hysteresis = <0>; - type = "passive"; - }; - cpu-crit { temperature = <120000>; hysteresis = <0>;