From 33140e668b10200b775779f302b143b32e6ae7ca Mon Sep 17 00:00:00 2001 From: Markus Schneider-Pargmann Date: Fri, 27 Jan 2023 16:44:43 +0100 Subject: thermal/drivers/mediatek: Control buffer enablement tweaks Add logic in order to be able to turn on the control buffer on MT8365. This change now allows to have control buffer support for MTK_THERMAL_V1, and it allows to define the register offset, and mask used to enable it. Signed-off-by: Markus Schneider-Pargmann Signed-off-by: Fabien Parent Signed-off-by: Amjad Ouled-Ameur Reviewed-by: AngeloGioacchino Del Regno Link: https://lore.kernel.org/r/20221018-up-i350-thermal-bringup-v9-2-55a1ae14af74@baylibre.com Signed-off-by: Daniel Lezcano --- drivers/thermal/mediatek/auxadc_thermal.c | 28 +++++++++++++++++++--------- 1 file changed, 19 insertions(+), 9 deletions(-) (limited to 'drivers/thermal') diff --git a/drivers/thermal/mediatek/auxadc_thermal.c b/drivers/thermal/mediatek/auxadc_thermal.c index 7b146350050d..2b6186c150be 100644 --- a/drivers/thermal/mediatek/auxadc_thermal.c +++ b/drivers/thermal/mediatek/auxadc_thermal.c @@ -307,6 +307,9 @@ struct mtk_thermal_data { bool need_switch_bank; struct thermal_bank_cfg bank_data[MAX_NUM_ZONES]; enum mtk_thermal_version version; + u32 apmixed_buffer_ctl_reg; + u32 apmixed_buffer_ctl_mask; + u32 apmixed_buffer_ctl_set; }; struct mtk_thermal { @@ -560,6 +563,9 @@ static const struct mtk_thermal_data mt7622_thermal_data = { .adcpnp = mt7622_adcpnp, .sensor_mux_values = mt7622_mux_values, .version = MTK_THERMAL_V2, + .apmixed_buffer_ctl_reg = APMIXED_SYS_TS_CON1, + .apmixed_buffer_ctl_mask = GENMASK(31, 6) | BIT(3), + .apmixed_buffer_ctl_set = BIT(0), }; /* @@ -1079,14 +1085,18 @@ static const struct of_device_id mtk_thermal_of_match[] = { }; MODULE_DEVICE_TABLE(of, mtk_thermal_of_match); -static void mtk_thermal_turn_on_buffer(void __iomem *apmixed_base) +static void mtk_thermal_turn_on_buffer(struct mtk_thermal *mt, + void __iomem *apmixed_base) { - int tmp; + u32 tmp; + + if (!mt->conf->apmixed_buffer_ctl_reg) + return; - tmp = readl(apmixed_base + APMIXED_SYS_TS_CON1); - tmp &= ~(0x37); - tmp |= 0x1; - writel(tmp, apmixed_base + APMIXED_SYS_TS_CON1); + tmp = readl(apmixed_base + mt->conf->apmixed_buffer_ctl_reg); + tmp &= mt->conf->apmixed_buffer_ctl_mask; + tmp |= mt->conf->apmixed_buffer_ctl_set; + writel(tmp, apmixed_base + mt->conf->apmixed_buffer_ctl_reg); udelay(200); } @@ -1184,10 +1194,10 @@ static int mtk_thermal_probe(struct platform_device *pdev) goto err_disable_clk_auxadc; } - if (mt->conf->version != MTK_THERMAL_V1) { - mtk_thermal_turn_on_buffer(apmixed_base); + mtk_thermal_turn_on_buffer(mt, apmixed_base); + + if (mt->conf->version != MTK_THERMAL_V2) mtk_thermal_release_periodic_ts(mt, auxadc_base); - } if (mt->conf->version == MTK_THERMAL_V1) mt->raw_to_mcelsius = raw_to_mcelsius_v1; -- cgit v1.2.3 From 56edffdc298a056ed6923c89b9af7c927ff0ac8f Mon Sep 17 00:00:00 2001 From: Fabien Parent Date: Fri, 27 Jan 2023 16:44:44 +0100 Subject: thermal/drivers/mediatek: Add support for MT8365 SoC MT8365 is similar to the other SoCs supported by the driver. It has only one bank and 3 actual sensors that can be multiplexed. There is another one sensor that does not have usable data. Signed-off-by: Fabien Parent Signed-off-by: Amjad Ouled-Ameur Reviewed-by: AngeloGioacchino Del Regno Link: https://lore.kernel.org/r/20221018-up-i350-thermal-bringup-v9-3-55a1ae14af74@baylibre.com Signed-off-by: Daniel Lezcano --- drivers/thermal/mediatek/auxadc_thermal.c | 68 +++++++++++++++++++++++++++++++ 1 file changed, 68 insertions(+) (limited to 'drivers/thermal') diff --git a/drivers/thermal/mediatek/auxadc_thermal.c b/drivers/thermal/mediatek/auxadc_thermal.c index 2b6186c150be..3c959a827451 100644 --- a/drivers/thermal/mediatek/auxadc_thermal.c +++ b/drivers/thermal/mediatek/auxadc_thermal.c @@ -31,6 +31,7 @@ #define AUXADC_CON2_V 0x010 #define AUXADC_DATA(channel) (0x14 + (channel) * 4) +#define APMIXED_SYS_TS_CON0 0x600 #define APMIXED_SYS_TS_CON1 0x604 /* Thermal Controller Registers */ @@ -281,6 +282,17 @@ enum mtk_thermal_version { /* The calibration coefficient of sensor */ #define MT7986_CALIBRATION 165 +/* MT8365 */ +#define MT8365_TEMP_AUXADC_CHANNEL 11 +#define MT8365_CALIBRATION 164 +#define MT8365_NUM_CONTROLLER 1 +#define MT8365_NUM_BANKS 1 +#define MT8365_NUM_SENSORS 3 +#define MT8365_NUM_SENSORS_PER_ZONE 3 +#define MT8365_TS1 0 +#define MT8365_TS2 1 +#define MT8365_TS3 2 + struct mtk_thermal; struct thermal_bank_cfg { @@ -435,6 +447,24 @@ static const int mt7986_mux_values[MT7986_NUM_SENSORS] = { 0, }; static const int mt7986_vts_index[MT7986_NUM_SENSORS] = { VTS1 }; static const int mt7986_tc_offset[MT7986_NUM_CONTROLLER] = { 0x0, }; +/* MT8365 thermal sensor data */ +static const int mt8365_bank_data[MT8365_NUM_SENSORS] = { + MT8365_TS1, MT8365_TS2, MT8365_TS3 +}; + +static const int mt8365_msr[MT8365_NUM_SENSORS_PER_ZONE] = { + TEMP_MSR0, TEMP_MSR1, TEMP_MSR2 +}; + +static const int mt8365_adcpnp[MT8365_NUM_SENSORS_PER_ZONE] = { + TEMP_ADCPNP0, TEMP_ADCPNP1, TEMP_ADCPNP2 +}; + +static const int mt8365_mux_values[MT8365_NUM_SENSORS] = { 0, 1, 2 }; +static const int mt8365_tc_offset[MT8365_NUM_CONTROLLER] = { 0 }; + +static const int mt8365_vts_index[MT8365_NUM_SENSORS] = { VTS1, VTS2, VTS3 }; + /* * The MT8173 thermal controller has four banks. Each bank can read up to * four temperature sensors simultaneously. The MT8173 has a total of 5 @@ -509,6 +539,40 @@ static const struct mtk_thermal_data mt2701_thermal_data = { .version = MTK_THERMAL_V1, }; +/* + * The MT8365 thermal controller has one bank, which can read up to + * four temperature sensors simultaneously. The MT8365 has a total of 3 + * temperature sensors. + * + * The thermal core only gets the maximum temperature of this one bank, + * so the bank concept wouldn't be necessary here. However, the SVS (Smart + * Voltage Scaling) unit makes its decisions based on the same bank + * data. + */ +static const struct mtk_thermal_data mt8365_thermal_data = { + .auxadc_channel = MT8365_TEMP_AUXADC_CHANNEL, + .num_banks = MT8365_NUM_BANKS, + .num_sensors = MT8365_NUM_SENSORS, + .vts_index = mt8365_vts_index, + .cali_val = MT8365_CALIBRATION, + .num_controller = MT8365_NUM_CONTROLLER, + .controller_offset = mt8365_tc_offset, + .need_switch_bank = false, + .bank_data = { + { + .num_sensors = MT8365_NUM_SENSORS, + .sensors = mt8365_bank_data + }, + }, + .msr = mt8365_msr, + .adcpnp = mt8365_adcpnp, + .sensor_mux_values = mt8365_mux_values, + .version = MTK_THERMAL_V1, + .apmixed_buffer_ctl_reg = APMIXED_SYS_TS_CON0, + .apmixed_buffer_ctl_mask = (u32) ~GENMASK(29, 28), + .apmixed_buffer_ctl_set = 0, +}; + /* * The MT2712 thermal controller has one bank, which can read up to * four temperature sensors simultaneously. The MT2712 has a total of 4 @@ -1080,6 +1144,10 @@ static const struct of_device_id mtk_thermal_of_match[] = { { .compatible = "mediatek,mt8183-thermal", .data = (void *)&mt8183_thermal_data, + }, + { + .compatible = "mediatek,mt8365-thermal", + .data = (void *)&mt8365_thermal_data, }, { }, }; -- cgit v1.2.3 From 4eb7c2f3a3d7cd6c50f391ac555b50c3fc5b3799 Mon Sep 17 00:00:00 2001 From: Zhang Rui Date: Wed, 29 Mar 2023 17:00:55 +0800 Subject: thermal: thermal_hwmon: Fix a kernel NULL pointer dereference When the hwmon device node of a thermal zone device is not found, using hwmon->device causes a kernel NULL pointer dereference. Fixes: dec07d399cc8 ("thermal: Don't use 'device' internal thermal zone structure field") Reported-by: Preble Adam C Signed-off-by: Zhang Rui Acked-by: Daniel Lezcano Signed-off-by: Rafael J. Wysocki --- drivers/thermal/thermal_hwmon.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'drivers/thermal') diff --git a/drivers/thermal/thermal_hwmon.c b/drivers/thermal/thermal_hwmon.c index c59db17dddd6..261743f461be 100644 --- a/drivers/thermal/thermal_hwmon.c +++ b/drivers/thermal/thermal_hwmon.c @@ -229,7 +229,7 @@ void thermal_remove_hwmon_sysfs(struct thermal_zone_device *tz) hwmon = thermal_hwmon_lookup_by_type(tz); if (unlikely(!hwmon)) { /* Should never happen... */ - dev_dbg(hwmon->device, "hwmon device lookup failed!\n"); + dev_dbg(&tz->device, "hwmon device lookup failed!\n"); return; } -- cgit v1.2.3 From d9dc06009b35dd2942561bf5c939a1c91bb5d9e4 Mon Sep 17 00:00:00 2001 From: "Rafael J. Wysocki" Date: Wed, 29 Mar 2023 19:44:21 +0200 Subject: thermal: thermal_hwmon: Revert recent message adjustment For the sake of consistency, revert the second part of the thermal_hwmon.c hunk from commit dec07d399cc8 ("thermal: Don't use 'device' internal thermal zone structure field") after the first part of it has been reverted. Link: https://lore.kernel.org/linux-pm/5b084360-898b-aad0-0b8e-33acc585d71d@linaro.org Signed-off-by: Rafael J. Wysocki Acked-by: Daniel Lezcano --- drivers/thermal/thermal_hwmon.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'drivers/thermal') diff --git a/drivers/thermal/thermal_hwmon.c b/drivers/thermal/thermal_hwmon.c index 261743f461be..fbe55509e307 100644 --- a/drivers/thermal/thermal_hwmon.c +++ b/drivers/thermal/thermal_hwmon.c @@ -236,7 +236,7 @@ void thermal_remove_hwmon_sysfs(struct thermal_zone_device *tz) temp = thermal_hwmon_lookup_temp(hwmon, tz); if (unlikely(!temp)) { /* Should never happen... */ - dev_dbg(hwmon->device, "temperature input lookup failed!\n"); + dev_dbg(&tz->device, "temperature input lookup failed!\n"); return; } -- cgit v1.2.3 From 86df7d19083c66fb1e2e1b3800f29586429a4d92 Mon Sep 17 00:00:00 2001 From: Rob Herring Date: Fri, 10 Mar 2023 08:47:26 -0600 Subject: thermal: Use of_property_present() for testing DT property presence It is preferred to use typed property access functions (i.e. of_property_read_ functions) rather than low-level of_get_property/of_find_property functions for reading properties. As part of this, convert of_get_property/of_find_property calls to the recently added of_property_present() helper when we just want to test for presence of a property and nothing more. Signed-off-by: Rob Herring Acked-by: Viresh Kumar Signed-off-by: Rafael J. Wysocki --- drivers/thermal/cpufreq_cooling.c | 2 +- drivers/thermal/imx8mm_thermal.c | 2 +- drivers/thermal/imx_thermal.c | 4 ++-- drivers/thermal/ti-soc-thermal/ti-thermal-common.c | 2 +- 4 files changed, 5 insertions(+), 5 deletions(-) (limited to 'drivers/thermal') diff --git a/drivers/thermal/cpufreq_cooling.c b/drivers/thermal/cpufreq_cooling.c index 9f8b438fcf8f..4608555b7ec3 100644 --- a/drivers/thermal/cpufreq_cooling.c +++ b/drivers/thermal/cpufreq_cooling.c @@ -633,7 +633,7 @@ of_cpufreq_cooling_register(struct cpufreq_policy *policy) return NULL; } - if (of_find_property(np, "#cooling-cells", NULL)) { + if (of_property_present(np, "#cooling-cells")) { struct em_perf_domain *em = em_cpu_get(policy->cpu); cdev = __cpufreq_cooling_register(np, policy, em); diff --git a/drivers/thermal/imx8mm_thermal.c b/drivers/thermal/imx8mm_thermal.c index e0de6ac49469..d8005e9ec992 100644 --- a/drivers/thermal/imx8mm_thermal.c +++ b/drivers/thermal/imx8mm_thermal.c @@ -282,7 +282,7 @@ static int imx8mm_tmu_probe_set_calib(struct platform_device *pdev, * strongly recommended to update such old DTs to get correct * temperature compensation values for each SoC. */ - if (!of_find_property(pdev->dev.of_node, "nvmem-cells", NULL)) { + if (!of_property_present(pdev->dev.of_node, "nvmem-cells")) { dev_warn(dev, "No OCOTP nvmem reference found, SoC-specific calibration not loaded. Please update your DT.\n"); return 0; diff --git a/drivers/thermal/imx_thermal.c b/drivers/thermal/imx_thermal.c index c3136978adee..dbc1649f7bf3 100644 --- a/drivers/thermal/imx_thermal.c +++ b/drivers/thermal/imx_thermal.c @@ -571,7 +571,7 @@ static int imx_thermal_register_legacy_cooling(struct imx_thermal_data *data) np = of_get_cpu_node(data->policy->cpu, NULL); - if (!np || !of_find_property(np, "#cooling-cells", NULL)) { + if (!np || !of_property_present(np, "#cooling-cells")) { data->cdev = cpufreq_cooling_register(data->policy); if (IS_ERR(data->cdev)) { ret = PTR_ERR(data->cdev); @@ -648,7 +648,7 @@ static int imx_thermal_probe(struct platform_device *pdev) platform_set_drvdata(pdev, data); - if (of_find_property(pdev->dev.of_node, "nvmem-cells", NULL)) { + if (of_property_present(pdev->dev.of_node, "nvmem-cells")) { ret = imx_init_from_nvmem_cells(pdev); if (ret) return dev_err_probe(&pdev->dev, ret, diff --git a/drivers/thermal/ti-soc-thermal/ti-thermal-common.c b/drivers/thermal/ti-soc-thermal/ti-thermal-common.c index 0c8914017c18..938ddf4fb328 100644 --- a/drivers/thermal/ti-soc-thermal/ti-thermal-common.c +++ b/drivers/thermal/ti-soc-thermal/ti-thermal-common.c @@ -223,7 +223,7 @@ int ti_thermal_register_cpu_cooling(struct ti_bandgap *bgp, int id) * using DT, then it must be aware that the cooling device * loading has to happen via cpufreq driver. */ - if (of_find_property(np, "#thermal-sensor-cells", NULL)) + if (of_property_present(np, "#thermal-sensor-cells")) return 0; data = ti_bandgap_get_sensor_data(bgp, id); -- cgit v1.2.3 From 10debf8c2da8011c8009dd4b3f6d0ab85891c81b Mon Sep 17 00:00:00 2001 From: Amjad Ouled-Ameur Date: Fri, 27 Jan 2023 16:44:46 +0100 Subject: thermal/drivers/mediatek: Add delay after thermal banks initialization Thermal sensor reads performed immediately after thermal bank initialization returns bogus values. This is currently tackled by returning 0 if the temperature is bogus (exceeding 200000). Instead, add a delay between the bank init and the thermal zone device register to properly fix this. Signed-off-by: Michael Kao Signed-off-by: Hsin-Yi Wang Signed-off-by: Amjad Ouled-Ameur Reviewed-by: AngeloGioacchino Del Regno Link: https://lore.kernel.org/r/20221018-up-i350-thermal-bringup-v9-5-55a1ae14af74@baylibre.com Signed-off-by: Daniel Lezcano --- drivers/thermal/mediatek/auxadc_thermal.c | 11 +++-------- 1 file changed, 3 insertions(+), 8 deletions(-) (limited to 'drivers/thermal') diff --git a/drivers/thermal/mediatek/auxadc_thermal.c b/drivers/thermal/mediatek/auxadc_thermal.c index 3c959a827451..b6bb9eaafb74 100644 --- a/drivers/thermal/mediatek/auxadc_thermal.c +++ b/drivers/thermal/mediatek/auxadc_thermal.c @@ -816,14 +816,6 @@ static int mtk_thermal_bank_temperature(struct mtk_thermal_bank *bank) mt, conf->bank_data[bank->id].sensors[i], raw); - /* - * The first read of a sensor often contains very high bogus - * temperature value. Filter these out so that the system does - * not immediately shut down. - */ - if (temp > 200000) - temp = 0; - if (temp > max) max = temp; } @@ -1281,6 +1273,9 @@ static int mtk_thermal_probe(struct platform_device *pdev) platform_set_drvdata(pdev, mt); + /* Delay for thermal banks to be ready */ + msleep(30); + tzdev = devm_thermal_of_zone_register(&pdev->dev, 0, mt, &mtk_thermal_ops); if (IS_ERR(tzdev)) { -- cgit v1.2.3 From 3f2f689559f77a47972dede0483b7b8f2ead2125 Mon Sep 17 00:00:00 2001 From: Wolfram Sang Date: Tue, 7 Mar 2023 17:30:34 +0100 Subject: thermal/drivers/rcar_gen3_thermal: Remove R-Car H3 ES1.* handling MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit R-Car H3 ES1.* was only available to an internal development group and needed a lot of quirks and workarounds. These become a maintenance burden now, so our development group decided to remove upstream support and disable booting for this SoC. Public users only have ES2 onwards. Reviewed-by: Laurent Pinchart Reviewed-by: Niklas Söderlund Reviewed-by: Geert Uytterhoeven Signed-off-by: Wolfram Sang Link: https://lore.kernel.org/r/20230307163041.3815-7-wsa+renesas@sang-engineering.com Signed-off-by: Daniel Lezcano --- drivers/thermal/rcar_gen3_thermal.c | 52 ++----------------------------------- 1 file changed, 2 insertions(+), 50 deletions(-) (limited to 'drivers/thermal') diff --git a/drivers/thermal/rcar_gen3_thermal.c b/drivers/thermal/rcar_gen3_thermal.c index 3df00c9d55ab..42a4724d3920 100644 --- a/drivers/thermal/rcar_gen3_thermal.c +++ b/drivers/thermal/rcar_gen3_thermal.c @@ -14,7 +14,6 @@ #include #include #include -#include #include #include "thermal_hwmon.h" @@ -27,7 +26,6 @@ #define REG_GEN3_IRQTEMP1 0x14 #define REG_GEN3_IRQTEMP2 0x18 #define REG_GEN3_IRQTEMP3 0x1C -#define REG_GEN3_CTSR 0x20 #define REG_GEN3_THCTR 0x20 #define REG_GEN3_TEMP 0x28 #define REG_GEN3_THCODE1 0x50 @@ -46,14 +44,6 @@ #define IRQ_TEMPD2 BIT(4) #define IRQ_TEMPD3 BIT(5) -/* CTSR bits */ -#define CTSR_PONM BIT(8) -#define CTSR_AOUT BIT(7) -#define CTSR_THBGR BIT(5) -#define CTSR_VMEN BIT(4) -#define CTSR_VMST BIT(1) -#define CTSR_THSST BIT(0) - /* THCTR bits */ #define THCTR_PONM BIT(6) #define THCTR_THSST BIT(0) @@ -88,8 +78,6 @@ struct rcar_gen3_thermal_priv { struct rcar_gen3_thermal_tsc *tscs[TSC_MAX_NUM]; struct thermal_zone_device_ops ops; unsigned int num_tscs; - void (*thermal_init)(struct rcar_gen3_thermal_priv *priv, - struct rcar_gen3_thermal_tsc *tsc); int ptat[3]; }; @@ -248,11 +236,6 @@ static irqreturn_t rcar_gen3_thermal_irq(int irq, void *data) return IRQ_HANDLED; } -static const struct soc_device_attribute r8a7795es1[] = { - { .soc_id = "r8a7795", .revision = "ES1.*" }, - { /* sentinel */ } -}; - static bool rcar_gen3_thermal_read_fuses(struct rcar_gen3_thermal_priv *priv) { unsigned int i; @@ -311,34 +294,6 @@ static bool rcar_gen3_thermal_read_fuses(struct rcar_gen3_thermal_priv *priv) return true; } -static void rcar_gen3_thermal_init_r8a7795es1(struct rcar_gen3_thermal_priv *priv, - struct rcar_gen3_thermal_tsc *tsc) -{ - rcar_gen3_thermal_write(tsc, REG_GEN3_CTSR, CTSR_THBGR); - rcar_gen3_thermal_write(tsc, REG_GEN3_CTSR, 0x0); - - usleep_range(1000, 2000); - - rcar_gen3_thermal_write(tsc, REG_GEN3_CTSR, CTSR_PONM); - - rcar_gen3_thermal_write(tsc, REG_GEN3_IRQCTL, 0x3F); - rcar_gen3_thermal_write(tsc, REG_GEN3_IRQMSK, 0); - if (priv->ops.set_trips) - rcar_gen3_thermal_write(tsc, REG_GEN3_IRQEN, - IRQ_TEMPD1 | IRQ_TEMP2); - - rcar_gen3_thermal_write(tsc, REG_GEN3_CTSR, - CTSR_PONM | CTSR_AOUT | CTSR_THBGR | CTSR_VMEN); - - usleep_range(100, 200); - - rcar_gen3_thermal_write(tsc, REG_GEN3_CTSR, - CTSR_PONM | CTSR_AOUT | CTSR_THBGR | CTSR_VMEN | - CTSR_VMST | CTSR_THSST); - - usleep_range(1000, 2000); -} - static void rcar_gen3_thermal_init(struct rcar_gen3_thermal_priv *priv, struct rcar_gen3_thermal_tsc *tsc) { @@ -474,9 +429,6 @@ static int rcar_gen3_thermal_probe(struct platform_device *pdev) return -ENOMEM; priv->ops = rcar_gen3_tz_of_ops; - priv->thermal_init = rcar_gen3_thermal_init; - if (soc_device_match(r8a7795es1)) - priv->thermal_init = rcar_gen3_thermal_init_r8a7795es1; platform_set_drvdata(pdev, priv); @@ -516,7 +468,7 @@ static int rcar_gen3_thermal_probe(struct platform_device *pdev) for (i = 0; i < priv->num_tscs; i++) { struct rcar_gen3_thermal_tsc *tsc = priv->tscs[i]; - priv->thermal_init(priv, tsc); + rcar_gen3_thermal_init(priv, tsc); rcar_gen3_thermal_calc_coefs(priv, tsc, *ths_tj_1); zone = devm_thermal_of_zone_register(dev, i, tsc, &priv->ops); @@ -563,7 +515,7 @@ static int __maybe_unused rcar_gen3_thermal_resume(struct device *dev) for (i = 0; i < priv->num_tscs; i++) { struct rcar_gen3_thermal_tsc *tsc = priv->tscs[i]; - priv->thermal_init(priv, tsc); + rcar_gen3_thermal_init(priv, tsc); } return 0; -- cgit v1.2.3 From 53c9ce497dd79fb567214452f4cea5bb4c541b5e Mon Sep 17 00:00:00 2001 From: Daniel Lezcano Date: Thu, 9 Mar 2023 10:28:20 +0100 Subject: thermal/drivers/imx: Remove get_trip_temp ops The i.MX thermal sensor uses the generic trip points. The thermal framework can return the critical temperature directly. Remove the pointless get_trip_temp ops. Signed-off-by: Daniel Lezcano Reviewed-by: Fabio Estevam Link: https://lore.kernel.org/r/20230309092821.1590586-1-daniel.lezcano@linaro.org Signed-off-by: Daniel Lezcano --- drivers/thermal/imx_thermal.c | 8 -------- 1 file changed, 8 deletions(-) (limited to 'drivers/thermal') diff --git a/drivers/thermal/imx_thermal.c b/drivers/thermal/imx_thermal.c index c3136978adee..69ed482167f7 100644 --- a/drivers/thermal/imx_thermal.c +++ b/drivers/thermal/imx_thermal.c @@ -330,13 +330,6 @@ static int imx_change_mode(struct thermal_zone_device *tz, return 0; } -static int imx_get_crit_temp(struct thermal_zone_device *tz, int *temp) -{ - *temp = trips[IMX_TRIP_CRITICAL].temperature; - - return 0; -} - static int imx_set_trip_temp(struct thermal_zone_device *tz, int trip, int temp) { @@ -384,7 +377,6 @@ static struct thermal_zone_device_ops imx_tz_ops = { .unbind = imx_unbind, .get_temp = imx_get_temp, .change_mode = imx_change_mode, - .get_crit_temp = imx_get_crit_temp, .set_trip_temp = imx_set_trip_temp, }; -- cgit v1.2.3 From ed4b51b8fd0bebfb4181a44c6458d8e3c07989b2 Mon Sep 17 00:00:00 2001 From: Daniel Lezcano Date: Thu, 9 Mar 2023 10:28:21 +0100 Subject: thermal/drivers/imx: Use the thermal framework for the trip point The thermal framework provides an API to get the trip related to a trip point id. We want to consolidate the generic trip points code, thus preventing the different drivers to deal with the trip points after they registered them. The set_trip_temp ops will be changed regarding the above changes but first we need to rework a bit the different implementation in the drivers. The goal is to prevent using the trip id but use a trip point passed as parameter which will contain all the needed information. As we don't have the trip point passed as parameter yet, we get the trip point using the generic trip thermal framewrok APIs and use it to take exactly the same decisions. The difference with this change and the previous code is from where we get the thermal trip point (which is the same). No functional change intended. Signed-off-by: Daniel Lezcano Reviewed-by: Fabio Estevam Link: https://lore.kernel.org/r/20230309092821.1590586-2-daniel.lezcano@linaro.org Signed-off-by: Daniel Lezcano --- drivers/thermal/imx_thermal.c | 11 +++++++---- 1 file changed, 7 insertions(+), 4 deletions(-) (limited to 'drivers/thermal') diff --git a/drivers/thermal/imx_thermal.c b/drivers/thermal/imx_thermal.c index 69ed482167f7..13c56e45cdbc 100644 --- a/drivers/thermal/imx_thermal.c +++ b/drivers/thermal/imx_thermal.c @@ -330,26 +330,29 @@ static int imx_change_mode(struct thermal_zone_device *tz, return 0; } -static int imx_set_trip_temp(struct thermal_zone_device *tz, int trip, +static int imx_set_trip_temp(struct thermal_zone_device *tz, int trip_id, int temp) { struct imx_thermal_data *data = thermal_zone_device_priv(tz); + struct thermal_trip trip; int ret; ret = pm_runtime_resume_and_get(data->dev); if (ret < 0) return ret; + ret = __thermal_zone_get_trip(tz, trip_id, &trip); + if (ret) + return ret; + /* do not allow changing critical threshold */ - if (trip == IMX_TRIP_CRITICAL) + if (trip.type == THERMAL_TRIP_CRITICAL) return -EPERM; /* do not allow passive to be set higher than critical */ if (temp < 0 || temp > trips[IMX_TRIP_CRITICAL].temperature) return -EINVAL; - trips[IMX_TRIP_PASSIVE].temperature = temp; - imx_set_alarm_temp(data, temp); pm_runtime_put(data->dev); -- cgit v1.2.3 From e45c9a2fc59da2d5f8004ce1e6894cd5d74788e3 Mon Sep 17 00:00:00 2001 From: Yang Li Date: Wed, 8 Mar 2023 14:27:19 +0800 Subject: thermal/drivers/hisi: Use devm_platform_ioremap_resource() According to commit 7945f929f1a7 ("drivers: provide devm_platform_ioremap_resource()"), convert platform_get_resource(), devm_ioremap_resource() to a single call to Use devm_platform_ioremap_resource(), as this is exactly what this function does. Signed-off-by: Yang Li Link: https://lore.kernel.org/r/20230308062719.79522-1-yang.lee@linux.alibaba.com Signed-off-by: Daniel Lezcano --- drivers/thermal/hisi_thermal.c | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) (limited to 'drivers/thermal') diff --git a/drivers/thermal/hisi_thermal.c b/drivers/thermal/hisi_thermal.c index 0d135b8a5b62..3f09ef8be41a 100644 --- a/drivers/thermal/hisi_thermal.c +++ b/drivers/thermal/hisi_thermal.c @@ -544,7 +544,6 @@ static int hisi_thermal_probe(struct platform_device *pdev) { struct hisi_thermal_data *data; struct device *dev = &pdev->dev; - struct resource *res; int i, ret; data = devm_kzalloc(dev, sizeof(*data), GFP_KERNEL); @@ -555,8 +554,7 @@ static int hisi_thermal_probe(struct platform_device *pdev) platform_set_drvdata(pdev, data); data->ops = of_device_get_match_data(dev); - res = platform_get_resource(pdev, IORESOURCE_MEM, 0); - data->regs = devm_ioremap_resource(dev, res); + data->regs = devm_platform_ioremap_resource(pdev, 0); if (IS_ERR(data->regs)) return PTR_ERR(data->regs); -- cgit v1.2.3 From 32a7a02117de01199ce15ec121ac7af417c340eb Mon Sep 17 00:00:00 2001 From: Daniel Lezcano Date: Tue, 7 Mar 2023 14:37:25 +0100 Subject: thermal/core: Relocate the traces definition in thermal directory The traces are exported but only local to the thermal core code. On the other side, the traces take the thermal zone device structure as argument, thus they have to rely on the exported thermal.h header file. As we want to move the structure to the private thermal core header, first we have to relocate those traces to the same place as many drivers do. Cc: Steven Rostedt Suggested-by: Steven Rostedt Signed-off-by: Daniel Lezcano Reviewed-by: Steven Rostedt (Google) Link: https://lore.kernel.org/r/20230307133735.90772-2-daniel.lezcano@linaro.org --- drivers/thermal/Makefile | 3 +- drivers/thermal/cpufreq_cooling.c | 2 +- drivers/thermal/devfreq_cooling.c | 2 +- drivers/thermal/gov_fair_share.c | 2 +- drivers/thermal/gov_power_allocator.c | 2 +- drivers/thermal/gov_step_wise.c | 2 +- drivers/thermal/thermal_core.c | 2 +- drivers/thermal/thermal_helpers.c | 3 +- drivers/thermal/thermal_trace.h | 205 +++++++++++++++++++++++++ drivers/thermal/thermal_trace_ipa.h | 94 ++++++++++++ include/trace/events/thermal.h | 199 ------------------------ include/trace/events/thermal_power_allocator.h | 88 ----------- 12 files changed, 308 insertions(+), 296 deletions(-) create mode 100644 drivers/thermal/thermal_trace.h create mode 100644 drivers/thermal/thermal_trace_ipa.h delete mode 100644 include/trace/events/thermal.h delete mode 100644 include/trace/events/thermal_power_allocator.h (limited to 'drivers/thermal') diff --git a/drivers/thermal/Makefile b/drivers/thermal/Makefile index eed300e83d48..058664bc3ec0 100644 --- a/drivers/thermal/Makefile +++ b/drivers/thermal/Makefile @@ -2,7 +2,7 @@ # # Makefile for sensor chip drivers. # - +CFLAGS_thermal_core.o := -I$(src) obj-$(CONFIG_THERMAL) += thermal_sys.o thermal_sys-y += thermal_core.o thermal_sysfs.o thermal_sys-y += thermal_trip.o thermal_helpers.o @@ -16,6 +16,7 @@ thermal_sys-$(CONFIG_THERMAL_OF) += thermal_of.o thermal_sys-$(CONFIG_THERMAL_ACPI) += thermal_acpi.o # governors +CFLAGS_gov_power_allocator.o := -I$(src) thermal_sys-$(CONFIG_THERMAL_GOV_FAIR_SHARE) += gov_fair_share.o thermal_sys-$(CONFIG_THERMAL_GOV_BANG_BANG) += gov_bang_bang.o thermal_sys-$(CONFIG_THERMAL_GOV_STEP_WISE) += gov_step_wise.o diff --git a/drivers/thermal/cpufreq_cooling.c b/drivers/thermal/cpufreq_cooling.c index 9f8b438fcf8f..65ef08b30334 100644 --- a/drivers/thermal/cpufreq_cooling.c +++ b/drivers/thermal/cpufreq_cooling.c @@ -23,7 +23,7 @@ #include #include -#include +#include "thermal_trace.h" /* * Cooling state <-> CPUFreq frequency diff --git a/drivers/thermal/devfreq_cooling.c b/drivers/thermal/devfreq_cooling.c index 24b474925cd6..262e62ab6cf2 100644 --- a/drivers/thermal/devfreq_cooling.c +++ b/drivers/thermal/devfreq_cooling.c @@ -20,7 +20,7 @@ #include #include -#include +#include "thermal_trace.h" #define SCALE_ERROR_MITIGATION 100 diff --git a/drivers/thermal/gov_fair_share.c b/drivers/thermal/gov_fair_share.c index aad7d5fe3a14..03c2daeb6ee8 100644 --- a/drivers/thermal/gov_fair_share.c +++ b/drivers/thermal/gov_fair_share.c @@ -11,7 +11,7 @@ */ #include -#include +#include "thermal_trace.h" #include "thermal_core.h" diff --git a/drivers/thermal/gov_power_allocator.c b/drivers/thermal/gov_power_allocator.c index 0eaf1527d3e3..8642f1096b91 100644 --- a/drivers/thermal/gov_power_allocator.c +++ b/drivers/thermal/gov_power_allocator.c @@ -12,7 +12,7 @@ #include #define CREATE_TRACE_POINTS -#include +#include "thermal_trace_ipa.h" #include "thermal_core.h" diff --git a/drivers/thermal/gov_step_wise.c b/drivers/thermal/gov_step_wise.c index 31235e169c5a..3d3067804df2 100644 --- a/drivers/thermal/gov_step_wise.c +++ b/drivers/thermal/gov_step_wise.c @@ -12,7 +12,7 @@ #include #include -#include +#include "thermal_trace.h" #include "thermal_core.h" diff --git a/drivers/thermal/thermal_core.c b/drivers/thermal/thermal_core.c index 5ae72f314683..ed628d21e1bc 100644 --- a/drivers/thermal/thermal_core.c +++ b/drivers/thermal/thermal_core.c @@ -22,7 +22,7 @@ #include #define CREATE_TRACE_POINTS -#include +#include "thermal_trace.h" #include "thermal_core.h" #include "thermal_hwmon.h" diff --git a/drivers/thermal/thermal_helpers.c b/drivers/thermal/thermal_helpers.c index 92e7e7fd7357..cfba0965a22d 100644 --- a/drivers/thermal/thermal_helpers.c +++ b/drivers/thermal/thermal_helpers.c @@ -19,9 +19,8 @@ #include #include -#include - #include "thermal_core.h" +#include "thermal_trace.h" int get_tz_trend(struct thermal_zone_device *tz, int trip) { diff --git a/drivers/thermal/thermal_trace.h b/drivers/thermal/thermal_trace.h new file mode 100644 index 000000000000..459c8ce6cf3b --- /dev/null +++ b/drivers/thermal/thermal_trace.h @@ -0,0 +1,205 @@ +/* SPDX-License-Identifier: GPL-2.0 */ +#undef TRACE_SYSTEM +#define TRACE_SYSTEM thermal + +#if !defined(_TRACE_THERMAL_H) || defined(TRACE_HEADER_MULTI_READ) +#define _TRACE_THERMAL_H + +#include +#include +#include + +TRACE_DEFINE_ENUM(THERMAL_TRIP_CRITICAL); +TRACE_DEFINE_ENUM(THERMAL_TRIP_HOT); +TRACE_DEFINE_ENUM(THERMAL_TRIP_PASSIVE); +TRACE_DEFINE_ENUM(THERMAL_TRIP_ACTIVE); + +#define show_tzt_type(type) \ + __print_symbolic(type, \ + { THERMAL_TRIP_CRITICAL, "CRITICAL"}, \ + { THERMAL_TRIP_HOT, "HOT"}, \ + { THERMAL_TRIP_PASSIVE, "PASSIVE"}, \ + { THERMAL_TRIP_ACTIVE, "ACTIVE"}) + +TRACE_EVENT(thermal_temperature, + + TP_PROTO(struct thermal_zone_device *tz), + + TP_ARGS(tz), + + TP_STRUCT__entry( + __string(thermal_zone, tz->type) + __field(int, id) + __field(int, temp_prev) + __field(int, temp) + ), + + TP_fast_assign( + __assign_str(thermal_zone, tz->type); + __entry->id = tz->id; + __entry->temp_prev = tz->last_temperature; + __entry->temp = tz->temperature; + ), + + TP_printk("thermal_zone=%s id=%d temp_prev=%d temp=%d", + __get_str(thermal_zone), __entry->id, __entry->temp_prev, + __entry->temp) +); + +TRACE_EVENT(cdev_update, + + TP_PROTO(struct thermal_cooling_device *cdev, unsigned long target), + + TP_ARGS(cdev, target), + + TP_STRUCT__entry( + __string(type, cdev->type) + __field(unsigned long, target) + ), + + TP_fast_assign( + __assign_str(type, cdev->type); + __entry->target = target; + ), + + TP_printk("type=%s target=%lu", __get_str(type), __entry->target) +); + +TRACE_EVENT(thermal_zone_trip, + + TP_PROTO(struct thermal_zone_device *tz, int trip, + enum thermal_trip_type trip_type), + + TP_ARGS(tz, trip, trip_type), + + TP_STRUCT__entry( + __string(thermal_zone, tz->type) + __field(int, id) + __field(int, trip) + __field(enum thermal_trip_type, trip_type) + ), + + TP_fast_assign( + __assign_str(thermal_zone, tz->type); + __entry->id = tz->id; + __entry->trip = trip; + __entry->trip_type = trip_type; + ), + + TP_printk("thermal_zone=%s id=%d trip=%d trip_type=%s", + __get_str(thermal_zone), __entry->id, __entry->trip, + show_tzt_type(__entry->trip_type)) +); + +#ifdef CONFIG_CPU_THERMAL +TRACE_EVENT(thermal_power_cpu_get_power_simple, + TP_PROTO(int cpu, u32 power), + + TP_ARGS(cpu, power), + + TP_STRUCT__entry( + __field(int, cpu) + __field(u32, power) + ), + + TP_fast_assign( + __entry->cpu = cpu; + __entry->power = power; + ), + + TP_printk("cpu=%d power=%u", __entry->cpu, __entry->power) +); + +TRACE_EVENT(thermal_power_cpu_limit, + TP_PROTO(const struct cpumask *cpus, unsigned int freq, + unsigned long cdev_state, u32 power), + + TP_ARGS(cpus, freq, cdev_state, power), + + TP_STRUCT__entry( + __bitmask(cpumask, num_possible_cpus()) + __field(unsigned int, freq ) + __field(unsigned long, cdev_state) + __field(u32, power ) + ), + + TP_fast_assign( + __assign_bitmask(cpumask, cpumask_bits(cpus), + num_possible_cpus()); + __entry->freq = freq; + __entry->cdev_state = cdev_state; + __entry->power = power; + ), + + TP_printk("cpus=%s freq=%u cdev_state=%lu power=%u", + __get_bitmask(cpumask), __entry->freq, __entry->cdev_state, + __entry->power) +); +#endif /* CONFIG_CPU_THERMAL */ + +#ifdef CONFIG_DEVFREQ_THERMAL +TRACE_EVENT(thermal_power_devfreq_get_power, + TP_PROTO(struct thermal_cooling_device *cdev, + struct devfreq_dev_status *status, unsigned long freq, + u32 power), + + TP_ARGS(cdev, status, freq, power), + + TP_STRUCT__entry( + __string(type, cdev->type ) + __field(unsigned long, freq ) + __field(u32, busy_time) + __field(u32, total_time) + __field(u32, power) + ), + + TP_fast_assign( + __assign_str(type, cdev->type); + __entry->freq = freq; + __entry->busy_time = status->busy_time; + __entry->total_time = status->total_time; + __entry->power = power; + ), + + TP_printk("type=%s freq=%lu load=%u power=%u", + __get_str(type), __entry->freq, + __entry->total_time == 0 ? 0 : + (100 * __entry->busy_time) / __entry->total_time, + __entry->power) +); + +TRACE_EVENT(thermal_power_devfreq_limit, + TP_PROTO(struct thermal_cooling_device *cdev, unsigned long freq, + unsigned long cdev_state, u32 power), + + TP_ARGS(cdev, freq, cdev_state, power), + + TP_STRUCT__entry( + __string(type, cdev->type) + __field(unsigned int, freq ) + __field(unsigned long, cdev_state) + __field(u32, power ) + ), + + TP_fast_assign( + __assign_str(type, cdev->type); + __entry->freq = freq; + __entry->cdev_state = cdev_state; + __entry->power = power; + ), + + TP_printk("type=%s freq=%u cdev_state=%lu power=%u", + __get_str(type), __entry->freq, __entry->cdev_state, + __entry->power) +); +#endif /* CONFIG_DEVFREQ_THERMAL */ +#endif /* _TRACE_THERMAL_H */ + +#undef TRACE_INCLUDE_PATH +#define TRACE_INCLUDE_PATH . + +#undef TRACE_INCLUDE_FILE +#define TRACE_INCLUDE_FILE thermal_trace + +/* This part must be outside protection */ +#include diff --git a/drivers/thermal/thermal_trace_ipa.h b/drivers/thermal/thermal_trace_ipa.h new file mode 100644 index 000000000000..84568db5421b --- /dev/null +++ b/drivers/thermal/thermal_trace_ipa.h @@ -0,0 +1,94 @@ +/* SPDX-License-Identifier: GPL-2.0 */ +#undef TRACE_SYSTEM +#define TRACE_SYSTEM thermal_power_allocator + +#if !defined(_TRACE_THERMAL_POWER_ALLOCATOR_H) || defined(TRACE_HEADER_MULTI_READ) +#define _TRACE_THERMAL_POWER_ALLOCATOR_H + +#include + +TRACE_EVENT(thermal_power_allocator, + TP_PROTO(struct thermal_zone_device *tz, u32 *req_power, + u32 total_req_power, u32 *granted_power, + u32 total_granted_power, size_t num_actors, + u32 power_range, u32 max_allocatable_power, + int current_temp, s32 delta_temp), + TP_ARGS(tz, req_power, total_req_power, granted_power, + total_granted_power, num_actors, power_range, + max_allocatable_power, current_temp, delta_temp), + TP_STRUCT__entry( + __field(int, tz_id ) + __dynamic_array(u32, req_power, num_actors ) + __field(u32, total_req_power ) + __dynamic_array(u32, granted_power, num_actors) + __field(u32, total_granted_power ) + __field(size_t, num_actors ) + __field(u32, power_range ) + __field(u32, max_allocatable_power ) + __field(int, current_temp ) + __field(s32, delta_temp ) + ), + TP_fast_assign( + __entry->tz_id = tz->id; + memcpy(__get_dynamic_array(req_power), req_power, + num_actors * sizeof(*req_power)); + __entry->total_req_power = total_req_power; + memcpy(__get_dynamic_array(granted_power), granted_power, + num_actors * sizeof(*granted_power)); + __entry->total_granted_power = total_granted_power; + __entry->num_actors = num_actors; + __entry->power_range = power_range; + __entry->max_allocatable_power = max_allocatable_power; + __entry->current_temp = current_temp; + __entry->delta_temp = delta_temp; + ), + + TP_printk("thermal_zone_id=%d req_power={%s} total_req_power=%u granted_power={%s} total_granted_power=%u power_range=%u max_allocatable_power=%u current_temperature=%d delta_temperature=%d", + __entry->tz_id, + __print_array(__get_dynamic_array(req_power), + __entry->num_actors, 4), + __entry->total_req_power, + __print_array(__get_dynamic_array(granted_power), + __entry->num_actors, 4), + __entry->total_granted_power, __entry->power_range, + __entry->max_allocatable_power, __entry->current_temp, + __entry->delta_temp) +); + +TRACE_EVENT(thermal_power_allocator_pid, + TP_PROTO(struct thermal_zone_device *tz, s32 err, s32 err_integral, + s64 p, s64 i, s64 d, s32 output), + TP_ARGS(tz, err, err_integral, p, i, d, output), + TP_STRUCT__entry( + __field(int, tz_id ) + __field(s32, err ) + __field(s32, err_integral) + __field(s64, p ) + __field(s64, i ) + __field(s64, d ) + __field(s32, output ) + ), + TP_fast_assign( + __entry->tz_id = tz->id; + __entry->err = err; + __entry->err_integral = err_integral; + __entry->p = p; + __entry->i = i; + __entry->d = d; + __entry->output = output; + ), + + TP_printk("thermal_zone_id=%d err=%d err_integral=%d p=%lld i=%lld d=%lld output=%d", + __entry->tz_id, __entry->err, __entry->err_integral, + __entry->p, __entry->i, __entry->d, __entry->output) +); +#endif /* _TRACE_THERMAL_POWER_ALLOCATOR_H */ + +#undef TRACE_INCLUDE_PATH +#define TRACE_INCLUDE_PATH . + +#undef TRACE_INCLUDE_FILE +#define TRACE_INCLUDE_FILE thermal_trace_ipa + +/* This part must be outside protection */ +#include diff --git a/include/trace/events/thermal.h b/include/trace/events/thermal.h deleted file mode 100644 index e58bf3072f32..000000000000 --- a/include/trace/events/thermal.h +++ /dev/null @@ -1,199 +0,0 @@ -/* SPDX-License-Identifier: GPL-2.0 */ -#undef TRACE_SYSTEM -#define TRACE_SYSTEM thermal - -#if !defined(_TRACE_THERMAL_H) || defined(TRACE_HEADER_MULTI_READ) -#define _TRACE_THERMAL_H - -#include -#include -#include - -TRACE_DEFINE_ENUM(THERMAL_TRIP_CRITICAL); -TRACE_DEFINE_ENUM(THERMAL_TRIP_HOT); -TRACE_DEFINE_ENUM(THERMAL_TRIP_PASSIVE); -TRACE_DEFINE_ENUM(THERMAL_TRIP_ACTIVE); - -#define show_tzt_type(type) \ - __print_symbolic(type, \ - { THERMAL_TRIP_CRITICAL, "CRITICAL"}, \ - { THERMAL_TRIP_HOT, "HOT"}, \ - { THERMAL_TRIP_PASSIVE, "PASSIVE"}, \ - { THERMAL_TRIP_ACTIVE, "ACTIVE"}) - -TRACE_EVENT(thermal_temperature, - - TP_PROTO(struct thermal_zone_device *tz), - - TP_ARGS(tz), - - TP_STRUCT__entry( - __string(thermal_zone, tz->type) - __field(int, id) - __field(int, temp_prev) - __field(int, temp) - ), - - TP_fast_assign( - __assign_str(thermal_zone, tz->type); - __entry->id = tz->id; - __entry->temp_prev = tz->last_temperature; - __entry->temp = tz->temperature; - ), - - TP_printk("thermal_zone=%s id=%d temp_prev=%d temp=%d", - __get_str(thermal_zone), __entry->id, __entry->temp_prev, - __entry->temp) -); - -TRACE_EVENT(cdev_update, - - TP_PROTO(struct thermal_cooling_device *cdev, unsigned long target), - - TP_ARGS(cdev, target), - - TP_STRUCT__entry( - __string(type, cdev->type) - __field(unsigned long, target) - ), - - TP_fast_assign( - __assign_str(type, cdev->type); - __entry->target = target; - ), - - TP_printk("type=%s target=%lu", __get_str(type), __entry->target) -); - -TRACE_EVENT(thermal_zone_trip, - - TP_PROTO(struct thermal_zone_device *tz, int trip, - enum thermal_trip_type trip_type), - - TP_ARGS(tz, trip, trip_type), - - TP_STRUCT__entry( - __string(thermal_zone, tz->type) - __field(int, id) - __field(int, trip) - __field(enum thermal_trip_type, trip_type) - ), - - TP_fast_assign( - __assign_str(thermal_zone, tz->type); - __entry->id = tz->id; - __entry->trip = trip; - __entry->trip_type = trip_type; - ), - - TP_printk("thermal_zone=%s id=%d trip=%d trip_type=%s", - __get_str(thermal_zone), __entry->id, __entry->trip, - show_tzt_type(__entry->trip_type)) -); - -#ifdef CONFIG_CPU_THERMAL -TRACE_EVENT(thermal_power_cpu_get_power_simple, - TP_PROTO(int cpu, u32 power), - - TP_ARGS(cpu, power), - - TP_STRUCT__entry( - __field(int, cpu) - __field(u32, power) - ), - - TP_fast_assign( - __entry->cpu = cpu; - __entry->power = power; - ), - - TP_printk("cpu=%d power=%u", __entry->cpu, __entry->power) -); - -TRACE_EVENT(thermal_power_cpu_limit, - TP_PROTO(const struct cpumask *cpus, unsigned int freq, - unsigned long cdev_state, u32 power), - - TP_ARGS(cpus, freq, cdev_state, power), - - TP_STRUCT__entry( - __bitmask(cpumask, num_possible_cpus()) - __field(unsigned int, freq ) - __field(unsigned long, cdev_state) - __field(u32, power ) - ), - - TP_fast_assign( - __assign_bitmask(cpumask, cpumask_bits(cpus), - num_possible_cpus()); - __entry->freq = freq; - __entry->cdev_state = cdev_state; - __entry->power = power; - ), - - TP_printk("cpus=%s freq=%u cdev_state=%lu power=%u", - __get_bitmask(cpumask), __entry->freq, __entry->cdev_state, - __entry->power) -); -#endif /* CONFIG_CPU_THERMAL */ - -#ifdef CONFIG_DEVFREQ_THERMAL -TRACE_EVENT(thermal_power_devfreq_get_power, - TP_PROTO(struct thermal_cooling_device *cdev, - struct devfreq_dev_status *status, unsigned long freq, - u32 power), - - TP_ARGS(cdev, status, freq, power), - - TP_STRUCT__entry( - __string(type, cdev->type ) - __field(unsigned long, freq ) - __field(u32, busy_time) - __field(u32, total_time) - __field(u32, power) - ), - - TP_fast_assign( - __assign_str(type, cdev->type); - __entry->freq = freq; - __entry->busy_time = status->busy_time; - __entry->total_time = status->total_time; - __entry->power = power; - ), - - TP_printk("type=%s freq=%lu load=%u power=%u", - __get_str(type), __entry->freq, - __entry->total_time == 0 ? 0 : - (100 * __entry->busy_time) / __entry->total_time, - __entry->power) -); - -TRACE_EVENT(thermal_power_devfreq_limit, - TP_PROTO(struct thermal_cooling_device *cdev, unsigned long freq, - unsigned long cdev_state, u32 power), - - TP_ARGS(cdev, freq, cdev_state, power), - - TP_STRUCT__entry( - __string(type, cdev->type) - __field(unsigned int, freq ) - __field(unsigned long, cdev_state) - __field(u32, power ) - ), - - TP_fast_assign( - __assign_str(type, cdev->type); - __entry->freq = freq; - __entry->cdev_state = cdev_state; - __entry->power = power; - ), - - TP_printk("type=%s freq=%u cdev_state=%lu power=%u", - __get_str(type), __entry->freq, __entry->cdev_state, - __entry->power) -); -#endif /* CONFIG_DEVFREQ_THERMAL */ -#endif /* _TRACE_THERMAL_H */ - -/* This part must be outside protection */ -#include diff --git a/include/trace/events/thermal_power_allocator.h b/include/trace/events/thermal_power_allocator.h deleted file mode 100644 index 1c8fb95544f9..000000000000 --- a/include/trace/events/thermal_power_allocator.h +++ /dev/null @@ -1,88 +0,0 @@ -/* SPDX-License-Identifier: GPL-2.0 */ -#undef TRACE_SYSTEM -#define TRACE_SYSTEM thermal_power_allocator - -#if !defined(_TRACE_THERMAL_POWER_ALLOCATOR_H) || defined(TRACE_HEADER_MULTI_READ) -#define _TRACE_THERMAL_POWER_ALLOCATOR_H - -#include - -TRACE_EVENT(thermal_power_allocator, - TP_PROTO(struct thermal_zone_device *tz, u32 *req_power, - u32 total_req_power, u32 *granted_power, - u32 total_granted_power, size_t num_actors, - u32 power_range, u32 max_allocatable_power, - int current_temp, s32 delta_temp), - TP_ARGS(tz, req_power, total_req_power, granted_power, - total_granted_power, num_actors, power_range, - max_allocatable_power, current_temp, delta_temp), - TP_STRUCT__entry( - __field(int, tz_id ) - __dynamic_array(u32, req_power, num_actors ) - __field(u32, total_req_power ) - __dynamic_array(u32, granted_power, num_actors) - __field(u32, total_granted_power ) - __field(size_t, num_actors ) - __field(u32, power_range ) - __field(u32, max_allocatable_power ) - __field(int, current_temp ) - __field(s32, delta_temp ) - ), - TP_fast_assign( - __entry->tz_id = tz->id; - memcpy(__get_dynamic_array(req_power), req_power, - num_actors * sizeof(*req_power)); - __entry->total_req_power = total_req_power; - memcpy(__get_dynamic_array(granted_power), granted_power, - num_actors * sizeof(*granted_power)); - __entry->total_granted_power = total_granted_power; - __entry->num_actors = num_actors; - __entry->power_range = power_range; - __entry->max_allocatable_power = max_allocatable_power; - __entry->current_temp = current_temp; - __entry->delta_temp = delta_temp; - ), - - TP_printk("thermal_zone_id=%d req_power={%s} total_req_power=%u granted_power={%s} total_granted_power=%u power_range=%u max_allocatable_power=%u current_temperature=%d delta_temperature=%d", - __entry->tz_id, - __print_array(__get_dynamic_array(req_power), - __entry->num_actors, 4), - __entry->total_req_power, - __print_array(__get_dynamic_array(granted_power), - __entry->num_actors, 4), - __entry->total_granted_power, __entry->power_range, - __entry->max_allocatable_power, __entry->current_temp, - __entry->delta_temp) -); - -TRACE_EVENT(thermal_power_allocator_pid, - TP_PROTO(struct thermal_zone_device *tz, s32 err, s32 err_integral, - s64 p, s64 i, s64 d, s32 output), - TP_ARGS(tz, err, err_integral, p, i, d, output), - TP_STRUCT__entry( - __field(int, tz_id ) - __field(s32, err ) - __field(s32, err_integral) - __field(s64, p ) - __field(s64, i ) - __field(s64, d ) - __field(s32, output ) - ), - TP_fast_assign( - __entry->tz_id = tz->id; - __entry->err = err; - __entry->err_integral = err_integral; - __entry->p = p; - __entry->i = i; - __entry->d = d; - __entry->output = output; - ), - - TP_printk("thermal_zone_id=%d err=%d err_integral=%d p=%lld i=%lld d=%lld output=%d", - __entry->tz_id, __entry->err, __entry->err_integral, - __entry->p, __entry->i, __entry->d, __entry->output) -); -#endif /* _TRACE_THERMAL_POWER_ALLOCATOR_H */ - -/* This part must be outside protection */ -#include -- cgit v1.2.3 From 311526b7e38fb35ab6dcdec290babda3d2b4f8d3 Mon Sep 17 00:00:00 2001 From: Daniel Lezcano Date: Tue, 7 Mar 2023 14:37:28 +0100 Subject: thermal/drivers/db8500: Use driver dev instead of tz->device The db8500 driver uses the thermal zone device instead of the device attached to it. In order to prevent the drivers to access the thermal zone device structure, replace the thermal zone device by the driver to show the debug message. Cc: Linus Walleij Signed-off-by: Daniel Lezcano Reviewed-by: Linus Walleij Link: https://lore.kernel.org/r/20230307133735.90772-5-daniel.lezcano@linaro.org --- drivers/thermal/db8500_thermal.c | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) (limited to 'drivers/thermal') diff --git a/drivers/thermal/db8500_thermal.c b/drivers/thermal/db8500_thermal.c index c0418497520c..fca5c2c93bf9 100644 --- a/drivers/thermal/db8500_thermal.c +++ b/drivers/thermal/db8500_thermal.c @@ -53,6 +53,7 @@ static const unsigned long db8500_thermal_points[] = { struct db8500_thermal_zone { struct thermal_zone_device *tz; + struct device *dev; unsigned long interpolated_temp; unsigned int cur_index; }; @@ -114,7 +115,7 @@ static irqreturn_t prcmu_low_irq_handler(int irq, void *irq_data) idx -= 1; db8500_thermal_update_config(th, idx, next_low, next_high); - dev_dbg(&th->tz->device, + dev_dbg(th->dev, "PRCMU set max %ld, min %ld\n", next_high, next_low); thermal_zone_device_update(th->tz, THERMAL_EVENT_UNSPECIFIED); @@ -136,7 +137,7 @@ static irqreturn_t prcmu_high_irq_handler(int irq, void *irq_data) db8500_thermal_update_config(th, idx, next_low, next_high); - dev_dbg(&th->tz->device, + dev_dbg(th->dev, "PRCMU set max %ld, min %ld\n", next_high, next_low); } else if (idx == num_points - 1) /* So we roof out 1 degree over the max point */ @@ -157,6 +158,8 @@ static int db8500_thermal_probe(struct platform_device *pdev) if (!th) return -ENOMEM; + th->dev = dev; + low_irq = platform_get_irq_byname(pdev, "IRQ_HOTMON_LOW"); if (low_irq < 0) return low_irq; -- cgit v1.2.3 From 0fb6c6493fa240048e6afa2b810b45007129a4a0 Mon Sep 17 00:00:00 2001 From: Daniel Lezcano Date: Tue, 7 Mar 2023 14:37:29 +0100 Subject: thermal/drivers/stm: Don't set no_hwmon to false The thermal->tzp->no_hwmon parameter is only used when calling thermal_zone_device_register(). Setting it to 'false' before calling thermal_add_hwmon_sysfs() has no effect. Remove the call and again prevent the drivers to access the thermal internals. Cc: Maxime Coquelin Cc: Alexandre Torgue Signed-off-by: Daniel Lezcano Link: https://lore.kernel.org/r/20230307133735.90772-6-daniel.lezcano@linaro.org --- drivers/thermal/st/stm_thermal.c | 1 - 1 file changed, 1 deletion(-) (limited to 'drivers/thermal') diff --git a/drivers/thermal/st/stm_thermal.c b/drivers/thermal/st/stm_thermal.c index 6f2bad8ef82f..903fcf1763f1 100644 --- a/drivers/thermal/st/stm_thermal.c +++ b/drivers/thermal/st/stm_thermal.c @@ -558,7 +558,6 @@ static int stm_thermal_probe(struct platform_device *pdev) * Thermal_zone doesn't enable hwmon as default, * enable it here */ - sensor->th_dev->tzp->no_hwmon = false; ret = thermal_add_hwmon_sysfs(sensor->th_dev); if (ret) goto err_tz; -- cgit v1.2.3 From 0c492be4002b7411a1587b429e68e0cf3f562488 Mon Sep 17 00:00:00 2001 From: Daniel Lezcano Date: Tue, 7 Mar 2023 14:37:30 +0100 Subject: thermal/drivers/ti: Use fixed update interval Currently the TI thermal driver sets the sensor update interval based on the polling of the thermal zone. In order to get the polling rate, the code inspects the thermal zone device structure internals, thus breaking the self-encapsulation of the thermal framework core framework. On the other side, we see the common polling rates set in the device tree for the platforms using this driver are 500 or 1000 ms. Setting the polling rate to 250 ms would be far enough to cover the combination we found in the device tree. Instead of accessing the thermal zone device structure polling rate, let's use a common update interval of 250 ms for the driver. Cc: Keerthy Signed-off-by: Daniel Lezcano Reviewed-by: Dhruva Gole Acked-by: Keerthy Link: https://lore.kernel.org/r/20230307133735.90772-7-daniel.lezcano@linaro.org --- drivers/thermal/ti-soc-thermal/ti-thermal-common.c | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) (limited to 'drivers/thermal') diff --git a/drivers/thermal/ti-soc-thermal/ti-thermal-common.c b/drivers/thermal/ti-soc-thermal/ti-thermal-common.c index 0c8914017c18..430c4b43151f 100644 --- a/drivers/thermal/ti-soc-thermal/ti-thermal-common.c +++ b/drivers/thermal/ti-soc-thermal/ti-thermal-common.c @@ -23,6 +23,8 @@ #include "ti-bandgap.h" #include "../thermal_hwmon.h" +#define TI_BANDGAP_UPDATE_INTERVAL_MS 250 + /* common data structures */ struct ti_thermal_data { struct cpufreq_policy *policy; @@ -159,7 +161,6 @@ int ti_thermal_expose_sensor(struct ti_bandgap *bgp, int id, char *domain) { struct ti_thermal_data *data; - int interval; data = ti_bandgap_get_sensor_data(bgp, id); @@ -177,10 +178,9 @@ int ti_thermal_expose_sensor(struct ti_bandgap *bgp, int id, return PTR_ERR(data->ti_thermal); } - interval = jiffies_to_msecs(data->ti_thermal->polling_delay_jiffies); - ti_bandgap_set_sensor_data(bgp, id, data); - ti_bandgap_write_update_interval(bgp, data->sensor_id, interval); + ti_bandgap_write_update_interval(bgp, data->sensor_id, + TI_BANDGAP_UPDATE_INTERVAL_MS); if (devm_thermal_add_hwmon_sysfs(bgp->dev, data->ti_thermal)) dev_warn(bgp->dev, "failed to add hwmon sysfs attributes\n"); -- cgit v1.2.3 From cd246fa969ec9f31a244f4056361c694ca8d99d3 Mon Sep 17 00:00:00 2001 From: "Rafael J. Wysocki" Date: Wed, 22 Mar 2023 20:34:12 +0100 Subject: thermal: core: Clean up thermal_list_lock locking Once thermal_list_lock has been acquired in __thermal_cooling_device_register(), it is not necessary to drop it and take it again until all of the thermal zones have been updated, so change the code accordingly. No expected functional impact. Signed-off-by: Rafael J. Wysocki --- drivers/thermal/thermal_core.c | 8 ++------ 1 file changed, 2 insertions(+), 6 deletions(-) (limited to 'drivers/thermal') diff --git a/drivers/thermal/thermal_core.c b/drivers/thermal/thermal_core.c index 9cb0a78636e3..94765b008393 100644 --- a/drivers/thermal/thermal_core.c +++ b/drivers/thermal/thermal_core.c @@ -826,8 +826,6 @@ static void bind_cdev(struct thermal_cooling_device *cdev) const struct thermal_zone_params *tzp; struct thermal_zone_device *pos = NULL; - mutex_lock(&thermal_list_lock); - list_for_each_entry(pos, &thermal_tz_list, node) { if (!pos->tzp && !pos->ops->bind) continue; @@ -854,8 +852,6 @@ static void bind_cdev(struct thermal_cooling_device *cdev) tzp->tbp[i].weight); } } - - mutex_unlock(&thermal_list_lock); } /** @@ -933,17 +929,17 @@ __thermal_cooling_device_register(struct device_node *np, /* Add 'this' new cdev to the global cdev list */ mutex_lock(&thermal_list_lock); + list_add(&cdev->node, &thermal_cdev_list); - mutex_unlock(&thermal_list_lock); /* Update binding information for 'this' new cdev */ bind_cdev(cdev); - mutex_lock(&thermal_list_lock); list_for_each_entry(pos, &thermal_tz_list, node) if (atomic_cmpxchg(&pos->need_update, 1, 0)) thermal_zone_device_update(pos, THERMAL_EVENT_UNSPECIFIED); + mutex_unlock(&thermal_list_lock); return cdev; -- cgit v1.2.3