From ad275a5bbec916fab25fb31633df7215e8736386 Mon Sep 17 00:00:00 2001 From: Amit Kucheria Date: Mon, 20 Aug 2018 15:04:54 +0530 Subject: arm64: dts: msm8916: Add gpu thermal management Initialise the gpu thermal zone and scale gpu frequency for thermal mitigation if needed. Signed-off-by: Amit Kucheria --- arch/arm64/boot/dts/qcom/msm8916.dtsi | 30 +++++++++++++++++++++++++++++- 1 file changed, 29 insertions(+), 1 deletion(-) diff --git a/arch/arm64/boot/dts/qcom/msm8916.dtsi b/arch/arm64/boot/dts/qcom/msm8916.dtsi index 7b32b8990d62..1af00f478d75 100644 --- a/arch/arm64/boot/dts/qcom/msm8916.dtsi +++ b/arch/arm64/boot/dts/qcom/msm8916.dtsi @@ -237,6 +237,33 @@ }; }; + gpu-thermal { + polling-delay-passive = <250>; + polling-delay = <1000>; + + thermal-sensors = <&tsens 2>; + + trips { + gpu_alert: trip0 { + temperature = <75000>; + hysteresis = <2000>; + type = "passive"; + }; + gpu_crit: trip1 { + temperature = <95000>; + hysteresis = <2000>; + type = "critical"; + }; + }; + + cooling-maps { + map0 { + trip = <&gpu_alert>; + cooling-device = <&gpu THERMAL_NO_LIMIT THERMAL_NO_LIMIT>; + }; + }; + }; + }; cpu_opp_table: cpu_opp_table { @@ -822,7 +849,7 @@ }; }; - gpu@1c00000 { + gpu: gpu@1c00000 { compatible = "qcom,adreno-306.0", "qcom,adreno"; reg = <0x01c00000 0x20000>; reg-names = "kgsl_3d0_reg_memory"; @@ -844,6 +871,7 @@ <&gcc GFX3D_CLK_SRC>; power-domains = <&gcc OXILI_GDSC>; operating-points-v2 = <&gpu_opp_table>; + #cooling-cells = <2>; iommus = <&gpu_iommu 1>, <&gpu_iommu 2>; }; -- cgit v1.2.3 From caa6e0404f7eccd699e86fd314b138c7e09d7f48 Mon Sep 17 00:00:00 2001 From: Amit Kucheria Date: Mon, 20 Aug 2018 15:36:26 +0530 Subject: arm64: dts: msm8916: Add camera thermal zone Initialise the camera thermal zone to export temperature to userspace. Signed-off-by: Amit Kucheria --- arch/arm64/boot/dts/qcom/msm8916.dtsi | 21 +++++++++++++++++++++ 1 file changed, 21 insertions(+) diff --git a/arch/arm64/boot/dts/qcom/msm8916.dtsi b/arch/arm64/boot/dts/qcom/msm8916.dtsi index 1af00f478d75..e10319ad511f 100644 --- a/arch/arm64/boot/dts/qcom/msm8916.dtsi +++ b/arch/arm64/boot/dts/qcom/msm8916.dtsi @@ -264,6 +264,27 @@ }; }; + camera-thermal { + polling-delay-passive = <250>; + polling-delay = <1000>; + + thermal-sensors = <&tsens 1>; + + trips { + cam_alert: trip0 { + temperature = <75000>; + hysteresis = <2000>; + type = "passive"; + }; + cam_crit: trip1 { + temperature = <95000>; + hysteresis = <2000>; + type = "critical"; + }; + }; + + }; + }; cpu_opp_table: cpu_opp_table { -- cgit v1.2.3 From 2c136d8cc66979e9e7afe0ecefbcb77f9b73338d Mon Sep 17 00:00:00 2001 From: Amit Kucheria Date: Thu, 6 Sep 2018 15:13:59 +0530 Subject: thermal: tsens: Prepare 8916 and 8974 tsens to use SROT and TM address space We've already converted over the devicetree of platforms using v2 version of the TSENS IP to use two address spaces. Now prepare to convert over the 8916 and 8974 platforms to use separate SROT and TM address spaces. This patch will work with device trees with one or two address spaces because we set the tm_offset in commit 5b1283984fa3 ("thermal: tsens: Add support to split up register address space into two"). Signed-off-by: Amit Kucheria Reviewed-by: Matthias Kaehlcke --- drivers/thermal/qcom/tsens-common.c | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/drivers/thermal/qcom/tsens-common.c b/drivers/thermal/qcom/tsens-common.c index 6207d8d92351..478739543bbc 100644 --- a/drivers/thermal/qcom/tsens-common.c +++ b/drivers/thermal/qcom/tsens-common.c @@ -21,7 +21,7 @@ #include #include "tsens.h" -#define S0_ST_ADDR 0x1030 +#define STATUS_OFFSET 0x30 #define SN_ADDR_OFFSET 0x4 #define SN_ST_TEMP_MASK 0x3ff #define CAL_DEGC_PT1 30 @@ -107,8 +107,9 @@ int get_temp_common(struct tsens_device *tmdev, int id, int *temp) unsigned int status_reg; int last_temp = 0, ret; - status_reg = S0_ST_ADDR + s->hw_id * SN_ADDR_OFFSET; + status_reg = tmdev->tm_offset + STATUS_OFFSET + s->hw_id * SN_ADDR_OFFSET; ret = regmap_read(tmdev->map, status_reg, &code); + if (ret) return ret; last_temp = code & SN_ST_TEMP_MASK; -- cgit v1.2.3 From 424b136c927bacb07e1b76ad14b29bc9253c7098 Mon Sep 17 00:00:00 2001 From: Amit Kucheria Date: Wed, 1 Aug 2018 00:26:02 +0530 Subject: thermal: tsens: Add SPDX license identifiers The TSENS drivers use a GPL-2.0 license. Replace with equivalent SPDX tags and delete the full license text. Signed-off-by: Amit Kucheria Reviewed-by: Matthias Kaehlcke Reviewed-by: Bjorn Andersson --- drivers/thermal/qcom/tsens-8916.c | 11 +---------- drivers/thermal/qcom/tsens-8960.c | 11 +---------- drivers/thermal/qcom/tsens-8974.c | 11 +---------- drivers/thermal/qcom/tsens-common.c | 11 +---------- drivers/thermal/qcom/tsens.c | 11 +---------- drivers/thermal/qcom/tsens.h | 11 ++--------- 6 files changed, 7 insertions(+), 59 deletions(-) diff --git a/drivers/thermal/qcom/tsens-8916.c b/drivers/thermal/qcom/tsens-8916.c index fdf561b8b81d..c4955c85e922 100644 --- a/drivers/thermal/qcom/tsens-8916.c +++ b/drivers/thermal/qcom/tsens-8916.c @@ -1,15 +1,6 @@ +// SPDX-License-Identifier: GPL-2.0 /* * Copyright (c) 2015, The Linux Foundation. All rights reserved. - * - * This program is free software; you can redistribute it and/or modify - * it under the terms of the GNU General Public License version 2 and - * only version 2 as published by the Free Software Foundation. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * */ #include diff --git a/drivers/thermal/qcom/tsens-8960.c b/drivers/thermal/qcom/tsens-8960.c index 0451277d3a8f..4af76de7dc2e 100644 --- a/drivers/thermal/qcom/tsens-8960.c +++ b/drivers/thermal/qcom/tsens-8960.c @@ -1,15 +1,6 @@ +// SPDX-License-Identifier: GPL-2.0 /* * Copyright (c) 2015, The Linux Foundation. All rights reserved. - * - * This program is free software; you can redistribute it and/or modify - * it under the terms of the GNU General Public License version 2 and - * only version 2 as published by the Free Software Foundation. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * */ #include diff --git a/drivers/thermal/qcom/tsens-8974.c b/drivers/thermal/qcom/tsens-8974.c index 9baf77e8cbe3..7e149edbfeb6 100644 --- a/drivers/thermal/qcom/tsens-8974.c +++ b/drivers/thermal/qcom/tsens-8974.c @@ -1,15 +1,6 @@ +// SPDX-License-Identifier: GPL-2.0 /* * Copyright (c) 2015, The Linux Foundation. All rights reserved. - * - * This program is free software; you can redistribute it and/or modify - * it under the terms of the GNU General Public License version 2 and - * only version 2 as published by the Free Software Foundation. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * */ #include diff --git a/drivers/thermal/qcom/tsens-common.c b/drivers/thermal/qcom/tsens-common.c index 478739543bbc..303e3fdaca98 100644 --- a/drivers/thermal/qcom/tsens-common.c +++ b/drivers/thermal/qcom/tsens-common.c @@ -1,15 +1,6 @@ +// SPDX-License-Identifier: GPL-2.0 /* * Copyright (c) 2015, The Linux Foundation. All rights reserved. - * - * This program is free software; you can redistribute it and/or modify - * it under the terms of the GNU General Public License version 2 and - * only version 2 as published by the Free Software Foundation. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * */ #include diff --git a/drivers/thermal/qcom/tsens.c b/drivers/thermal/qcom/tsens.c index a2c9bfae3d86..90bb431cf740 100644 --- a/drivers/thermal/qcom/tsens.c +++ b/drivers/thermal/qcom/tsens.c @@ -1,15 +1,6 @@ +// SPDX-License-Identifier: GPL-2.0 /* * Copyright (c) 2015, The Linux Foundation. All rights reserved. - * - * This program is free software; you can redistribute it and/or modify - * it under the terms of the GNU General Public License version 2 and - * only version 2 as published by the Free Software Foundation. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * */ #include diff --git a/drivers/thermal/qcom/tsens.h b/drivers/thermal/qcom/tsens.h index 14331eb45a86..8207610f326a 100644 --- a/drivers/thermal/qcom/tsens.h +++ b/drivers/thermal/qcom/tsens.h @@ -1,15 +1,8 @@ +/* SPDX-License-Identifier: GPL-2.0 */ /* * Copyright (c) 2015, The Linux Foundation. All rights reserved. - * - * This software is licensed under the terms of the GNU General Public - * License version 2, as published by the Free Software Foundation, and - * may be copied, distributed, and modified under those terms. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. */ + #ifndef __QCOM_TSENS_H__ #define __QCOM_TSENS_H__ -- cgit v1.2.3 From 0d652e156453af3d2451bce040ce824791804a3b Mon Sep 17 00:00:00 2001 From: Amit Kucheria Date: Mon, 6 Aug 2018 17:28:56 +0530 Subject: thermal: tsens: Get rid of dead code hw_id is dynamically allocated but not used anywhere. Get rid of dead code. Signed-off-by: Amit Kucheria Reviewed-by: Matthias Kaehlcke Reviewed-by: Bjorn Andersson --- drivers/thermal/qcom/tsens.c | 5 ----- 1 file changed, 5 deletions(-) diff --git a/drivers/thermal/qcom/tsens.c b/drivers/thermal/qcom/tsens.c index 90bb431cf740..9a8e8f7b4ae1 100644 --- a/drivers/thermal/qcom/tsens.c +++ b/drivers/thermal/qcom/tsens.c @@ -80,11 +80,6 @@ static int tsens_register(struct tsens_device *tmdev) { int i; struct thermal_zone_device *tzd; - u32 *hw_id, n = tmdev->num_sensors; - - hw_id = devm_kcalloc(tmdev->dev, n, sizeof(u32), GFP_KERNEL); - if (!hw_id) - return -ENOMEM; for (i = 0; i < tmdev->num_sensors; i++) { tmdev->sensor[i].tmdev = tmdev; -- cgit v1.2.3 From b8973c639707d6b7047b933ec9f99a720e76615c Mon Sep 17 00:00:00 2001 From: Amit Kucheria Date: Thu, 26 Jul 2018 21:55:22 +0530 Subject: thermal: tsens: Rename map field in order to add a second address map The TSENS driver currently only uses a limited set of registers from the TM address space. So it was ok to map just that set of registers and call it "map". We'd now like to map a second set: SROT registers to introduce new functionality. Rename the "map" field to a more appropriate "tm_map". The 8960 doesn't have a clear split between TM and SROT registers. To avoid complicating the data structure, it will switchover to using tm_map for its maps. There is no functional change with this patch. Signed-off-by: Amit Kucheria Reviewed-by: Matthias Kaehlcke Reviewed-by: Bjorn Andersson --- drivers/thermal/qcom/tsens-8960.c | 30 +++++++++++++++--------------- drivers/thermal/qcom/tsens-common.c | 17 ++++++++--------- drivers/thermal/qcom/tsens-v2.c | 6 +++--- drivers/thermal/qcom/tsens.h | 2 +- 4 files changed, 27 insertions(+), 28 deletions(-) diff --git a/drivers/thermal/qcom/tsens-8960.c b/drivers/thermal/qcom/tsens-8960.c index 4af76de7dc2e..0f0adb302a7b 100644 --- a/drivers/thermal/qcom/tsens-8960.c +++ b/drivers/thermal/qcom/tsens-8960.c @@ -60,7 +60,7 @@ static int suspend_8960(struct tsens_device *tmdev) { int ret; unsigned int mask; - struct regmap *map = tmdev->map; + struct regmap *map = tmdev->tm_map; ret = regmap_read(map, THRESHOLD_ADDR, &tmdev->ctx.threshold); if (ret) @@ -85,7 +85,7 @@ static int suspend_8960(struct tsens_device *tmdev) static int resume_8960(struct tsens_device *tmdev) { int ret; - struct regmap *map = tmdev->map; + struct regmap *map = tmdev->tm_map; ret = regmap_update_bits(map, CNTL_ADDR, SW_RST, SW_RST); if (ret) @@ -117,12 +117,12 @@ static int enable_8960(struct tsens_device *tmdev, int id) int ret; u32 reg, mask; - ret = regmap_read(tmdev->map, CNTL_ADDR, ®); + ret = regmap_read(tmdev->tm_map, CNTL_ADDR, ®); if (ret) return ret; mask = BIT(id + SENSOR0_SHIFT); - ret = regmap_write(tmdev->map, CNTL_ADDR, reg | SW_RST); + ret = regmap_write(tmdev->tm_map, CNTL_ADDR, reg | SW_RST); if (ret) return ret; @@ -131,7 +131,7 @@ static int enable_8960(struct tsens_device *tmdev, int id) else reg |= mask | SLP_CLK_ENA_8660 | EN; - ret = regmap_write(tmdev->map, CNTL_ADDR, reg); + ret = regmap_write(tmdev->tm_map, CNTL_ADDR, reg); if (ret) return ret; @@ -148,7 +148,7 @@ static void disable_8960(struct tsens_device *tmdev) mask <<= SENSOR0_SHIFT; mask |= EN; - ret = regmap_read(tmdev->map, CNTL_ADDR, ®_cntl); + ret = regmap_read(tmdev->tm_map, CNTL_ADDR, ®_cntl); if (ret) return; @@ -159,7 +159,7 @@ static void disable_8960(struct tsens_device *tmdev) else reg_cntl &= ~SLP_CLK_ENA_8660; - regmap_write(tmdev->map, CNTL_ADDR, reg_cntl); + regmap_write(tmdev->tm_map, CNTL_ADDR, reg_cntl); } static int init_8960(struct tsens_device *tmdev) @@ -167,8 +167,8 @@ static int init_8960(struct tsens_device *tmdev) int ret, i; u32 reg_cntl; - tmdev->map = dev_get_regmap(tmdev->dev, NULL); - if (!tmdev->map) + tmdev->tm_map = dev_get_regmap(tmdev->dev, NULL); + if (!tmdev->tm_map) return -ENODEV; /* @@ -184,14 +184,14 @@ static int init_8960(struct tsens_device *tmdev) } reg_cntl = SW_RST; - ret = regmap_update_bits(tmdev->map, CNTL_ADDR, SW_RST, reg_cntl); + ret = regmap_update_bits(tmdev->tm_map, CNTL_ADDR, SW_RST, reg_cntl); if (ret) return ret; if (tmdev->num_sensors > 1) { reg_cntl |= SLP_CLK_ENA | (MEASURE_PERIOD << 18); reg_cntl &= ~SW_RST; - ret = regmap_update_bits(tmdev->map, CONFIG_ADDR, + ret = regmap_update_bits(tmdev->tm_map, CONFIG_ADDR, CONFIG_MASK, CONFIG); } else { reg_cntl |= SLP_CLK_ENA_8660 | (MEASURE_PERIOD << 16); @@ -200,12 +200,12 @@ static int init_8960(struct tsens_device *tmdev) } reg_cntl |= GENMASK(tmdev->num_sensors - 1, 0) << SENSOR0_SHIFT; - ret = regmap_write(tmdev->map, CNTL_ADDR, reg_cntl); + ret = regmap_write(tmdev->tm_map, CNTL_ADDR, reg_cntl); if (ret) return ret; reg_cntl |= EN; - ret = regmap_write(tmdev->map, CNTL_ADDR, reg_cntl); + ret = regmap_write(tmdev->tm_map, CNTL_ADDR, reg_cntl); if (ret) return ret; @@ -252,12 +252,12 @@ static int get_temp_8960(struct tsens_device *tmdev, int id, int *temp) timeout = jiffies + usecs_to_jiffies(TIMEOUT_US); do { - ret = regmap_read(tmdev->map, INT_STATUS_ADDR, &trdy); + ret = regmap_read(tmdev->tm_map, INT_STATUS_ADDR, &trdy); if (ret) return ret; if (!(trdy & TRDY_MASK)) continue; - ret = regmap_read(tmdev->map, s->status, &code); + ret = regmap_read(tmdev->tm_map, s->status, &code); if (ret) return ret; *temp = code_to_mdegC(code, s); diff --git a/drivers/thermal/qcom/tsens-common.c b/drivers/thermal/qcom/tsens-common.c index 303e3fdaca98..0585084630b3 100644 --- a/drivers/thermal/qcom/tsens-common.c +++ b/drivers/thermal/qcom/tsens-common.c @@ -99,8 +99,7 @@ int get_temp_common(struct tsens_device *tmdev, int id, int *temp) int last_temp = 0, ret; status_reg = tmdev->tm_offset + STATUS_OFFSET + s->hw_id * SN_ADDR_OFFSET; - ret = regmap_read(tmdev->map, status_reg, &code); - + ret = regmap_read(tmdev->tm_map, status_reg, &code); if (ret) return ret; last_temp = code & SN_ST_TEMP_MASK; @@ -118,7 +117,7 @@ static const struct regmap_config tsens_config = { int __init init_common(struct tsens_device *tmdev) { - void __iomem *base; + void __iomem *tm_base; struct resource *res; struct platform_device *op = of_find_device_by_node(tmdev->dev->of_node); @@ -134,13 +133,13 @@ int __init init_common(struct tsens_device *tmdev) } res = platform_get_resource(op, IORESOURCE_MEM, 0); - base = devm_ioremap_resource(&op->dev, res); - if (IS_ERR(base)) - return PTR_ERR(base); + tm_base = devm_ioremap_resource(&op->dev, res); + if (IS_ERR(tm_base)) + return PTR_ERR(tm_base); - tmdev->map = devm_regmap_init_mmio(tmdev->dev, base, &tsens_config); - if (IS_ERR(tmdev->map)) - return PTR_ERR(tmdev->map); + tmdev->tm_map = devm_regmap_init_mmio(tmdev->dev, tm_base, &tsens_config); + if (IS_ERR(tmdev->tm_map)) + return PTR_ERR(tmdev->tm_map); return 0; } diff --git a/drivers/thermal/qcom/tsens-v2.c b/drivers/thermal/qcom/tsens-v2.c index 44da02f594ac..1bdef92e4521 100644 --- a/drivers/thermal/qcom/tsens-v2.c +++ b/drivers/thermal/qcom/tsens-v2.c @@ -21,7 +21,7 @@ static int get_temp_tsens_v2(struct tsens_device *tmdev, int id, int *temp) int ret; status_reg = tmdev->tm_offset + STATUS_OFFSET + s->hw_id * 4; - ret = regmap_read(tmdev->map, status_reg, &code); + ret = regmap_read(tmdev->tm_map, status_reg, &code); if (ret) return ret; last_temp = code & LAST_TEMP_MASK; @@ -29,7 +29,7 @@ static int get_temp_tsens_v2(struct tsens_device *tmdev, int id, int *temp) goto done; /* Try a second time */ - ret = regmap_read(tmdev->map, status_reg, &code); + ret = regmap_read(tmdev->tm_map, status_reg, &code); if (ret) return ret; if (code & STATUS_VALID_BIT) { @@ -40,7 +40,7 @@ static int get_temp_tsens_v2(struct tsens_device *tmdev, int id, int *temp) } /* Try a third/last time */ - ret = regmap_read(tmdev->map, status_reg, &code); + ret = regmap_read(tmdev->tm_map, status_reg, &code); if (ret) return ret; if (code & STATUS_VALID_BIT) { diff --git a/drivers/thermal/qcom/tsens.h b/drivers/thermal/qcom/tsens.h index 8207610f326a..58e98c4d3a8b 100644 --- a/drivers/thermal/qcom/tsens.h +++ b/drivers/thermal/qcom/tsens.h @@ -69,7 +69,7 @@ struct tsens_context { struct tsens_device { struct device *dev; u32 num_sensors; - struct regmap *map; + struct regmap *tm_map; u32 tm_offset; struct tsens_context ctx; const struct tsens_ops *ops; -- cgit v1.2.3 From 452c5c4626966262132cfb36f907fdbb53b01462 Mon Sep 17 00:00:00 2001 From: Amit Kucheria Date: Thu, 26 Jul 2018 22:01:11 +0530 Subject: thermal: tsens: Add the SROT address map On platforms whose device trees specify two address spaces for TSENS, the second one points to the SROT registers. Initialise the SROT map on those platforms. Signed-off-by: Amit Kucheria Reviewed-by: Matthias Kaehlcke Reviewed-by: Bjorn Andersson --- drivers/thermal/qcom/tsens-common.c | 14 ++++++++++++-- drivers/thermal/qcom/tsens.h | 1 + 2 files changed, 13 insertions(+), 2 deletions(-) diff --git a/drivers/thermal/qcom/tsens-common.c b/drivers/thermal/qcom/tsens-common.c index 0585084630b3..0b8a793f15f4 100644 --- a/drivers/thermal/qcom/tsens-common.c +++ b/drivers/thermal/qcom/tsens-common.c @@ -117,16 +117,26 @@ static const struct regmap_config tsens_config = { int __init init_common(struct tsens_device *tmdev) { - void __iomem *tm_base; + void __iomem *tm_base, *srot_base; struct resource *res; struct platform_device *op = of_find_device_by_node(tmdev->dev->of_node); if (!op) return -EINVAL; - /* The driver only uses the TM register address space for now */ if (op->num_resources > 1) { + /* DT with separate SROT and TM address space */ tmdev->tm_offset = 0; + res = platform_get_resource(op, IORESOURCE_MEM, 1); + srot_base = devm_ioremap_resource(&op->dev, res); + if (IS_ERR(srot_base)) + return PTR_ERR(srot_base); + + tmdev->srot_map = devm_regmap_init_mmio(tmdev->dev, + srot_base, &tsens_config); + if (IS_ERR(tmdev->srot_map)) + return PTR_ERR(tmdev->srot_map); + } else { /* old DTs where SROT and TM were in a contiguous 2K block */ tmdev->tm_offset = 0x1000; diff --git a/drivers/thermal/qcom/tsens.h b/drivers/thermal/qcom/tsens.h index 58e98c4d3a8b..b9c4bcf255fa 100644 --- a/drivers/thermal/qcom/tsens.h +++ b/drivers/thermal/qcom/tsens.h @@ -70,6 +70,7 @@ struct tsens_device { struct device *dev; u32 num_sensors; struct regmap *tm_map; + struct regmap *srot_map; u32 tm_offset; struct tsens_context ctx; const struct tsens_ops *ops; -- cgit v1.2.3 From 55bdd4bb4cfd4770527b0834c6a9760094e5b0f4 Mon Sep 17 00:00:00 2001 From: Amit Kucheria Date: Mon, 6 Aug 2018 16:40:01 +0530 Subject: thermal: tsens: Get rid of 'id' field The hw_id field in 'struct tsens_sensor' can do the job of tracking unique ids for each sensor connected to each tsens device instance. It also allows hw_ids to be overridden (e.g. 8916) in cases where some sensors in a sequence are disabled on a particular platform. Use the hw_id field instead of the id field consistently across the tsens code. While we're at it, document the fields of struct tsens_sensor. Signed-off-by: Amit Kucheria Reviewed-by: Matthias Kaehlcke Reviewed-by: Bjorn Andersson --- drivers/thermal/qcom/tsens.c | 5 ++--- drivers/thermal/qcom/tsens.h | 10 +++++++++- 2 files changed, 11 insertions(+), 4 deletions(-) diff --git a/drivers/thermal/qcom/tsens.c b/drivers/thermal/qcom/tsens.c index 9a8e8f7b4ae1..fb728ec5d77f 100644 --- a/drivers/thermal/qcom/tsens.c +++ b/drivers/thermal/qcom/tsens.c @@ -17,7 +17,7 @@ static int tsens_get_temp(void *data, int *temp) const struct tsens_sensor *s = data; struct tsens_device *tmdev = s->tmdev; - return tmdev->ops->get_temp(tmdev, s->id, temp); + return tmdev->ops->get_temp(tmdev, s->hw_id, temp); } static int tsens_get_trend(void *p, int trip, enum thermal_trend *trend) @@ -26,7 +26,7 @@ static int tsens_get_trend(void *p, int trip, enum thermal_trend *trend) struct tsens_device *tmdev = s->tmdev; if (tmdev->ops->get_trend) - return tmdev->ops->get_trend(tmdev, s->id, trend); + return tmdev->ops->get_trend(tmdev, s->hw_id, trend); return -ENOTSUPP; } @@ -83,7 +83,6 @@ static int tsens_register(struct tsens_device *tmdev) for (i = 0; i < tmdev->num_sensors; i++) { tmdev->sensor[i].tmdev = tmdev; - tmdev->sensor[i].id = i; tzd = devm_thermal_zone_of_sensor_register(tmdev->dev, i, &tmdev->sensor[i], &tsens_of_ops); diff --git a/drivers/thermal/qcom/tsens.h b/drivers/thermal/qcom/tsens.h index b9c4bcf255fa..2a3174dfc1a9 100644 --- a/drivers/thermal/qcom/tsens.h +++ b/drivers/thermal/qcom/tsens.h @@ -14,11 +14,19 @@ struct tsens_device; +/** + * struct tsens_sensor - sensor-specific data + * @tmdev: tsens device instance this sensor is connected to + * @tzd: thermal zone corresponding to this sensor + * @offset: offset from calibration data to convert ADC data to degrees + * @hw_id: unique sensor ID for each sensor connected to tsens device instance + * @slope: slope from calibration data to convert ADC data to degrees + * @status: 8960-specific status register addresses + */ struct tsens_sensor { struct tsens_device *tmdev; struct thermal_zone_device *tzd; int offset; - int id; int hw_id; int slope; u32 status; -- cgit v1.2.3 From ad4e394f8918406e4b0097d2b9cb188dabd66272 Mon Sep 17 00:00:00 2001 From: Amit Kucheria Date: Wed, 1 Aug 2018 02:15:26 +0530 Subject: MAINTAINERS: Add entry for Qualcomm TSENS thermal drivers Create an entry for the TSENS drivers and mark them as maintained Signed-off-by: Amit Kucheria Reviewed-by: Matthias Kaehlcke Acked-by: Rajendra Nayak Acked-by: Bjorn Andersson --- MAINTAINERS | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/MAINTAINERS b/MAINTAINERS index a5b256b25905..b8c96e0699c9 100644 --- a/MAINTAINERS +++ b/MAINTAINERS @@ -12076,6 +12076,13 @@ L: linux-arm-msm@vger.kernel.org S: Maintained F: drivers/iommu/qcom_iommu.c +QUALCOMM TSENS THERMAL DRIVER +M: Amit Kucheria +L: linux-pm@vger.kernel.org +L: linux-arm-msm@vger.kernel.org +S: Maintained +F: drivers/thermal/qcom/ + QUALCOMM VENUS VIDEO ACCELERATOR DRIVER M: Stanimir Varbanov L: linux-media@vger.kernel.org -- cgit v1.2.3 From a6a3d47a3628992bbb2fddd17973fd9c709081fa Mon Sep 17 00:00:00 2001 From: Amit Kucheria Date: Thu, 30 Aug 2018 16:48:13 +0530 Subject: thermal: tsens: Pass register offsets as private data Registers have moved around across TSENS generations. For example, the CTRL register was at offset 0x0 in the SROT region on msm8916 but is at offset 0x4 in newer v2 based TSENS HW blocks. Allow passing offsets of important registers so that we can continue to use common functions. Signed-off-by: Amit Kucheria --- drivers/thermal/qcom/tsens-8916.c | 1 + drivers/thermal/qcom/tsens-8974.c | 1 + drivers/thermal/qcom/tsens-v2.c | 2 ++ drivers/thermal/qcom/tsens.c | 3 +++ drivers/thermal/qcom/tsens.h | 9 +++++++++ 5 files changed, 16 insertions(+) diff --git a/drivers/thermal/qcom/tsens-8916.c b/drivers/thermal/qcom/tsens-8916.c index c4955c85e922..39a4dcbb9588 100644 --- a/drivers/thermal/qcom/tsens-8916.c +++ b/drivers/thermal/qcom/tsens-8916.c @@ -100,5 +100,6 @@ static const struct tsens_ops ops_8916 = { const struct tsens_data data_8916 = { .num_sensors = 5, .ops = &ops_8916, + .reg_offsets = {[SROT_CTRL_OFFSET] = 0x0}, .hw_ids = (unsigned int []){0, 1, 2, 4, 5 }, }; diff --git a/drivers/thermal/qcom/tsens-8974.c b/drivers/thermal/qcom/tsens-8974.c index 7e149edbfeb6..3a7a7659b8e4 100644 --- a/drivers/thermal/qcom/tsens-8974.c +++ b/drivers/thermal/qcom/tsens-8974.c @@ -232,4 +232,5 @@ static const struct tsens_ops ops_8974 = { const struct tsens_data data_8974 = { .num_sensors = 11, .ops = &ops_8974, + .reg_offsets = {[SROT_CTRL_OFFSET] = 0x0}, }; diff --git a/drivers/thermal/qcom/tsens-v2.c b/drivers/thermal/qcom/tsens-v2.c index 1bdef92e4521..7750c7235b63 100644 --- a/drivers/thermal/qcom/tsens-v2.c +++ b/drivers/thermal/qcom/tsens-v2.c @@ -68,10 +68,12 @@ static const struct tsens_ops ops_generic_v2 = { const struct tsens_data data_tsens_v2 = { .ops = &ops_generic_v2, + .reg_offsets = {[SROT_CTRL_OFFSET] = 0x4}, }; /* Kept around for backward compatibility with old msm8996.dtsi */ const struct tsens_data data_8996 = { .num_sensors = 13, .ops = &ops_generic_v2, + .reg_offsets = {[SROT_CTRL_OFFSET] = 0x4}, }; diff --git a/drivers/thermal/qcom/tsens.c b/drivers/thermal/qcom/tsens.c index fb728ec5d77f..b721b517696c 100644 --- a/drivers/thermal/qcom/tsens.c +++ b/drivers/thermal/qcom/tsens.c @@ -143,6 +143,9 @@ static int tsens_probe(struct platform_device *pdev) else tmdev->sensor[i].hw_id = i; } + for (i = 0; i < REG_ARRAY_SIZE; i++) { + tmdev->reg_offsets[i] = data->reg_offsets[i]; + } if (!tmdev->ops || !tmdev->ops->init || !tmdev->ops->get_temp) return -EINVAL; diff --git a/drivers/thermal/qcom/tsens.h b/drivers/thermal/qcom/tsens.h index 2a3174dfc1a9..c6d76095f637 100644 --- a/drivers/thermal/qcom/tsens.h +++ b/drivers/thermal/qcom/tsens.h @@ -56,15 +56,23 @@ struct tsens_ops { int (*get_trend)(struct tsens_device *, int, enum thermal_trend *); }; +enum reg_list { + SROT_CTRL_OFFSET, + + REG_ARRAY_SIZE, +}; + /** * struct tsens_data - tsens instance specific data * @num_sensors: Max number of sensors supported by platform * @ops: operations the tsens instance supports * @hw_ids: Subset of sensors ids supported by platform, if not the first n + * @reg_offsets: Register offsets for commonly used registers */ struct tsens_data { const u32 num_sensors; const struct tsens_ops *ops; + const u16 reg_offsets[REG_ARRAY_SIZE]; unsigned int *hw_ids; }; @@ -80,6 +88,7 @@ struct tsens_device { struct regmap *tm_map; struct regmap *srot_map; u32 tm_offset; + u16 reg_offsets[REG_ARRAY_SIZE]; struct tsens_context ctx; const struct tsens_ops *ops; struct tsens_sensor sensor[0]; -- cgit v1.2.3 From 88fabb752a66545b828301306729548e4bc09347 Mon Sep 17 00:00:00 2001 From: Amit Kucheria Date: Wed, 18 Jul 2018 23:55:58 +0530 Subject: thermal: tsens: Check if the IP is correctly enabled by firmware The SROT registers are initialised by the secure firmware at boot. We don't have write access to the registers. Check if the block is enabled before continuing. Signed-off-by: Amit Kucheria Reviewed-by: Bjorn Andersson --- drivers/thermal/qcom/tsens-common.c | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) diff --git a/drivers/thermal/qcom/tsens-common.c b/drivers/thermal/qcom/tsens-common.c index 0b8a793f15f4..3be4be2e0465 100644 --- a/drivers/thermal/qcom/tsens-common.c +++ b/drivers/thermal/qcom/tsens-common.c @@ -12,6 +12,10 @@ #include #include "tsens.h" +/* SROT */ +#define TSENS_EN BIT(0) + +/* TM */ #define STATUS_OFFSET 0x30 #define SN_ADDR_OFFSET 0x4 #define SN_ST_TEMP_MASK 0x3ff @@ -119,7 +123,10 @@ int __init init_common(struct tsens_device *tmdev) { void __iomem *tm_base, *srot_base; struct resource *res; + u32 code; + int ret; struct platform_device *op = of_find_device_by_node(tmdev->dev->of_node); + u16 ctrl_offset = tmdev->reg_offsets[SROT_CTRL_OFFSET]; if (!op) return -EINVAL; @@ -151,5 +158,15 @@ int __init init_common(struct tsens_device *tmdev) if (IS_ERR(tmdev->tm_map)) return PTR_ERR(tmdev->tm_map); + if (tmdev->srot_map) { + ret = regmap_read(tmdev->srot_map, ctrl_offset, &code); + if (ret) + return ret; + if (!(code & TSENS_EN)) { + dev_err(tmdev->dev, "tsens device is not enabled\n"); + return -ENODEV; + } + } + return 0; } -- cgit v1.2.3 From f662fb848c9a2e145e28792893974bb8d3594fcc Mon Sep 17 00:00:00 2001 From: Amit Kucheria Date: Thu, 6 Sep 2018 15:24:12 +0530 Subject: arm: dts: msm8974: thermal: split address space into two We've earlier added support to split the register address space into TM and SROT regions. Split up the regmap address space into two for msm8974 that has a similar register layout. Since tsens-common.c/init_common() currently only registers one address space, the order is important (TM before SROT). This is OK since the code doesn't really use the SROT functionality yet. Signed-off-by: Amit Kucheria Reviewed-by: Matthias Kaehlcke --- arch/arm/boot/dts/qcom-msm8974.dtsi | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/arch/arm/boot/dts/qcom-msm8974.dtsi b/arch/arm/boot/dts/qcom-msm8974.dtsi index d9019a49b292..56dbbf788d15 100644 --- a/arch/arm/boot/dts/qcom-msm8974.dtsi +++ b/arch/arm/boot/dts/qcom-msm8974.dtsi @@ -427,9 +427,10 @@ }; }; - tsens: thermal-sensor@fc4a8000 { + tsens: thermal-sensor@fc4a9000 { compatible = "qcom,msm8974-tsens"; - reg = <0xfc4a8000 0x2000>; + reg = <0xfc4a9000 0x1000>, /* TM */ + <0xfc4a8000 0x1000>; /* SROT */ nvmem-cells = <&tsens_calib>, <&tsens_backup>; nvmem-cell-names = "calib", "calib_backup"; #thermal-sensor-cells = <1>; -- cgit v1.2.3 From 4da198c8b7f461e2d3200d26c17a998ad38de8f8 Mon Sep 17 00:00:00 2001 From: Amit Kucheria Date: Thu, 6 Sep 2018 15:26:39 +0530 Subject: arm64: dts: msm8916: thermal: split address space into two We've earlier added support to split the register address space into TM and SROT regions. Split up the regmap address space into two for msm8916 that has a similar register layout. Since tsens-common.c/init_common() currently only registers one address space, the order is important (TM before SROT). This is OK since the code doesn't really use the SROT functionality yet. Signed-off-by: Amit Kucheria Reviewed-by: Matthias Kaehlcke --- arch/arm64/boot/dts/qcom/msm8916.dtsi | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/arch/arm64/boot/dts/qcom/msm8916.dtsi b/arch/arm64/boot/dts/qcom/msm8916.dtsi index 7b32b8990d62..6a277fce3333 100644 --- a/arch/arm64/boot/dts/qcom/msm8916.dtsi +++ b/arch/arm64/boot/dts/qcom/msm8916.dtsi @@ -761,9 +761,10 @@ }; }; - tsens: thermal-sensor@4a8000 { + tsens: thermal-sensor@4a9000 { compatible = "qcom,msm8916-tsens"; - reg = <0x4a8000 0x2000>; + reg = <0x4a9000 0x1000>, /* TM */ + <0x4a8000 0x1000>; /* SROT */ nvmem-cells = <&tsens_caldata>, <&tsens_calsel>; nvmem-cell-names = "calib", "calib_sel"; #thermal-sensor-cells = <1>; -- cgit v1.2.3 From 8512838d43865b876e51382667edae68c2800bf8 Mon Sep 17 00:00:00 2001 From: Amit Kucheria Date: Fri, 10 Aug 2018 10:38:09 +0530 Subject: arm: dts: msm8974: thermal: Add "qcom,sensors" property This new property allows the number of sensors to be configured from DT instead of being hardcoded in platform data. Use it. Signed-off-by: Amit Kucheria Reviewed-by: Matthias Kaehlcke Reviewed-by: Bjorn Andersson --- arch/arm/boot/dts/qcom-msm8974.dtsi | 1 + 1 file changed, 1 insertion(+) diff --git a/arch/arm/boot/dts/qcom-msm8974.dtsi b/arch/arm/boot/dts/qcom-msm8974.dtsi index 56dbbf788d15..3c4b81c29798 100644 --- a/arch/arm/boot/dts/qcom-msm8974.dtsi +++ b/arch/arm/boot/dts/qcom-msm8974.dtsi @@ -433,6 +433,7 @@ <0xfc4a8000 0x1000>; /* SROT */ nvmem-cells = <&tsens_calib>, <&tsens_backup>; nvmem-cell-names = "calib", "calib_backup"; + #qcom,sensors = <11>; #thermal-sensor-cells = <1>; }; -- cgit v1.2.3 From a0fd6f5ad96257c42d118dc8853c9ea243f2f095 Mon Sep 17 00:00:00 2001 From: Amit Kucheria Date: Thu, 6 Sep 2018 15:44:34 +0530 Subject: arm64: dts: msm8916: thermal: Add "qcom,sensors" property This new property allows the number of sensors to be configured from DT instead of being hardcoded in platform data. Use it. Signed-off-by: Amit Kucheria Reviewed-by: Bjorn Andersson --- arch/arm64/boot/dts/qcom/msm8916.dtsi | 1 + 1 file changed, 1 insertion(+) diff --git a/arch/arm64/boot/dts/qcom/msm8916.dtsi b/arch/arm64/boot/dts/qcom/msm8916.dtsi index 6a277fce3333..be27d8dc9e6b 100644 --- a/arch/arm64/boot/dts/qcom/msm8916.dtsi +++ b/arch/arm64/boot/dts/qcom/msm8916.dtsi @@ -767,6 +767,7 @@ <0x4a8000 0x1000>; /* SROT */ nvmem-cells = <&tsens_caldata>, <&tsens_calsel>; nvmem-cell-names = "calib", "calib_sel"; + #qcom,sensors = <5>; #thermal-sensor-cells = <1>; }; -- cgit v1.2.3 From 1ccff2eeb268aa50d5294ede8f385b0ce9971117 Mon Sep 17 00:00:00 2001 From: Amit Kucheria Date: Thu, 9 Aug 2018 03:32:10 +0530 Subject: dt-bindings: thermal: Fix a typo in documentation c(1) + x(1) was actually meant to be c(1) * x(1). Signed-off-by: Amit Kucheria Reviewed-by: Matthias Kaehlcke Acked-by: Rob Herring Reviewed-by: Bjorn Andersson --- Documentation/devicetree/bindings/thermal/thermal.txt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Documentation/devicetree/bindings/thermal/thermal.txt b/Documentation/devicetree/bindings/thermal/thermal.txt index eb7ee91556a5..ca14ba959e0d 100644 --- a/Documentation/devicetree/bindings/thermal/thermal.txt +++ b/Documentation/devicetree/bindings/thermal/thermal.txt @@ -152,7 +152,7 @@ Optional property: Elem size: one cell the sensors listed in the thermal-sensors property. Elem type: signed Coefficients defaults to 1, in case this property is not specified. A simple linear polynomial is used: - Z = c0 * x0 + c1 + x1 + ... + c(n-1) * x(n-1) + cn. + Z = c0 * x0 + c1 * x1 + ... + c(n-1) * x(n-1) + cn. The coefficients are ordered and they match with sensors by means of sensor ID. Additional coefficients are -- cgit v1.2.3