Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

Merge tag 'thermal-6.17-rc1' of git://git.kernel.org/pub/scm/linux/kernel/git/rafael/linux-pm

Pull thermal control updates from Rafael Wysocki:
"These update the thermal control sysfs interface and multiple thermal
control drivers:

- Convert EAGAIN into ENODATA in temp_show() to prevent user space
from polling the sysfs file in vain after a failing O_NONBLOCK read
under the assumption that the read would have blocked (Hsin-Te
Yuan)

- Add Wildcat Lake PCI ID to the int340x Intel processor thermal
driver (Srinivas Pandruvada)

- Add debugfs interface to override the temperature set by the
firmware in the Intel platform temperature control (PTC) interface
and add a new sysfs control attribute called thermal_tolerance to
it (Srinivas Pandruvada)

- Enable the stage 2 shutdown in the qcom-spmi-temp-alarm thermal
driver and add support for more SPMI variants to it (Anjelique
Melendez)

- Constify the thermal_zone_device_ops structure where possible in
several assorted thermal drivers (Christophe Jaillet)

- Use the dev_fwnode() helper instead of of_fwnode_handle(), as it is
more adequate, wherever possible in thermal drivers (Jiri Slaby)

- Implement and document One-Time Programmable fuse support in the
Rockchip thermal driver in order to increase the precision of the
measurements (Nicolas Frattaroli)

- Change the way the Mediatek LTVS thermal driver stores the
initialization data sequence to support different sequences
matching different platforms. Introduce mt7988 support with a new
initialization sequence (Mason Chang)

- Document the QCom TSens Milos Temperature Sensor DT bindings (Luca
Weiss)

- Add the fallback compatible string for MT7981 and MT8516 DT
bindings (Aleksander Jan Bajkowski)

- Add the compatible string for the Tegra210B01 SOC_THERM driver
(Aaron Kling)"

* tag 'thermal-6.17-rc1' of git://git.kernel.org/pub/scm/linux/kernel/git/rafael/linux-pm: (23 commits)
dt-bindings: thermal: tegra: Document Tegra210B01
dt-bindings: thermal: mediatek: Add fallback compatible string for MT7981 and MT8516
dt-bindings: thermal: qcom-tsens: document the Milos Temperature Sensor
thermal/drivers/mediatek/lvts_thermal: Add mt7988 lvts commands
thermal/drivers/mediatek/lvts_thermal: Add lvts commands and their sizes to driver data
thermal/drivers/mediatek/lvts_thermal: Change lvts commands array to static const
thermal/drivers/rockchip: Support reading trim values from OTP
dt-bindings: thermal: rockchip: document otp thermal trim
thermal/drivers/rockchip: Support RK3576 SoC in the thermal driver
dt-bindings: rockchip-thermal: Add RK3576 compatible
thermal/drivers/rockchip: Rename rk_tsadcv3_tshut_mode
thermal: Use dev_fwnode()
thermal: Constify struct thermal_zone_device_ops
thermal/drivers/loongson2: Constify struct thermal_zone_device_ops
thermal/drivers/qcom-spmi-temp-alarm: Add support for LITE PMIC peripherals
thermal/drivers/qcom-spmi-temp-alarm: Add support for GEN2 rev 2 PMIC peripherals
thermal/drivers/qcom-spmi-temp-alarm: Prepare to support additional Temp Alarm subtypes
thermal/drivers/qcom-spmi-temp-alarm: Add temp alarm data struct based on HW subtype
thermal/drivers/qcom-spmi-temp-alarm: Enable stage 2 shutdown when required
thermal: sysfs: Return ENODATA instead of EAGAIN for reads
...

+1014 -150
+17 -10
Documentation/devicetree/bindings/thermal/mediatek,thermal.yaml
··· 20 20 21 21 properties: 22 22 compatible: 23 - enum: 24 - - mediatek,mt2701-thermal 25 - - mediatek,mt2712-thermal 26 - - mediatek,mt7622-thermal 27 - - mediatek,mt7981-thermal 28 - - mediatek,mt7986-thermal 29 - - mediatek,mt8173-thermal 30 - - mediatek,mt8183-thermal 31 - - mediatek,mt8365-thermal 32 - - mediatek,mt8516-thermal 23 + oneOf: 24 + - enum: 25 + - mediatek,mt2701-thermal 26 + - mediatek,mt2712-thermal 27 + - mediatek,mt7622-thermal 28 + - mediatek,mt7986-thermal 29 + - mediatek,mt8173-thermal 30 + - mediatek,mt8183-thermal 31 + - mediatek,mt8365-thermal 32 + - items: 33 + - enum: 34 + - mediatek,mt8516-thermal 35 + - const: mediatek,mt2701-thermal 36 + - items: 37 + - enum: 38 + - mediatek,mt7981-thermal 39 + - const: mediatek,mt7986-thermal 33 40 34 41 reg: 35 42 maxItems: 1
+2
Documentation/devicetree/bindings/thermal/nvidia,tegra124-soctherm.yaml
··· 21 21 - nvidia,tegra124-soctherm 22 22 - nvidia,tegra132-soctherm 23 23 - nvidia,tegra210-soctherm 24 + - nvidia,tegra210b01-soctherm 24 25 25 26 reg: 26 27 maxItems: 2 ··· 208 207 enum: 209 208 - nvidia,tegra124-soctherm 210 209 - nvidia,tegra210-soctherm 210 + - nvidia,tegra210b01-soctherm 211 211 then: 212 212 properties: 213 213 reg:
+1
Documentation/devicetree/bindings/thermal/qcom-tsens.yaml
··· 49 49 - description: v2 of TSENS 50 50 items: 51 51 - enum: 52 + - qcom,milos-tsens 52 53 - qcom,msm8953-tsens 53 54 - qcom,msm8996-tsens 54 55 - qcom,msm8998-tsens
+62
Documentation/devicetree/bindings/thermal/rockchip-thermal.yaml
··· 21 21 - rockchip,rk3368-tsadc 22 22 - rockchip,rk3399-tsadc 23 23 - rockchip,rk3568-tsadc 24 + - rockchip,rk3576-tsadc 24 25 - rockchip,rk3588-tsadc 25 26 - rockchip,rv1108-tsadc 26 27 ··· 40 39 - const: tsadc 41 40 - const: apb_pclk 42 41 42 + nvmem-cells: 43 + items: 44 + - description: cell handle to where the trim's base temperature is stored 45 + - description: 46 + cell handle to where the trim's tenths of Celsius base value is stored 47 + 48 + nvmem-cell-names: 49 + items: 50 + - const: trim_base 51 + - const: trim_base_frac 52 + 43 53 resets: 44 54 minItems: 1 45 55 maxItems: 3 ··· 61 49 - const: tsadc-apb 62 50 - const: tsadc 63 51 - const: tsadc-phy 52 + 53 + "#address-cells": 54 + const: 1 55 + 56 + "#size-cells": 57 + const: 0 64 58 65 59 "#thermal-sensor-cells": 66 60 const: 1 ··· 89 71 $ref: /schemas/types.yaml#/definitions/uint32 90 72 enum: [0, 1] 91 73 74 + patternProperties: 75 + "@[0-9a-f]+$": 76 + type: object 77 + properties: 78 + reg: 79 + maxItems: 1 80 + description: sensor ID, a.k.a. channel number 81 + 82 + nvmem-cells: 83 + items: 84 + - description: handle of cell containing calibration data 85 + 86 + nvmem-cell-names: 87 + items: 88 + - const: trim 89 + 90 + required: 91 + - reg 92 + 93 + unevaluatedProperties: false 94 + 92 95 required: 93 96 - compatible 94 97 - reg ··· 117 78 - clocks 118 79 - clock-names 119 80 - resets 81 + 82 + allOf: 83 + - if: 84 + not: 85 + properties: 86 + compatible: 87 + contains: 88 + const: rockchip,rk3568-tsadc 89 + then: 90 + properties: 91 + nvmem-cells: false 92 + nvmem-cell-names: false 93 + - if: 94 + not: 95 + properties: 96 + compatible: 97 + contains: 98 + enum: 99 + - rockchip,rk3568-tsadc 100 + - rockchip,rk3576-tsadc 101 + then: 102 + patternProperties: 103 + "@[0-9a-f]+$": false 120 104 121 105 unevaluatedProperties: false 122 106
+9
Documentation/driver-api/thermal/intel_dptf.rst
··· 206 206 Update a new temperature target in milli degree celsius for hardware to 207 207 use for the temperature control. 208 208 209 + ``thermal_tolerance`` (RW) 210 + This attribute ranges from 0 to 7, where 0 represents 211 + the most aggressive control to avoid any temperature overshoots, and 212 + 7 represents a more graceful approach, favoring performance even at 213 + the expense of temperature overshoots. 214 + Note: This level may not scale linearly. For example, a value of 3 does 215 + not necessarily imply a 50% improvement in performance compared to a 216 + value of 0. 217 + 209 218 Given that this is platform temperature control, it is expected that a 210 219 single user-level manager owns and manages the controls. If multiple 211 220 user-level software applications attempt to write different targets, it
+1 -1
drivers/thermal/armada_thermal.c
··· 408 408 return ret; 409 409 } 410 410 411 - static struct thermal_zone_device_ops legacy_ops = { 411 + static const struct thermal_zone_device_ops legacy_ops = { 412 412 .get_temp = armada_get_temp_legacy, 413 413 }; 414 414
+1 -1
drivers/thermal/da9062-thermal.c
··· 137 137 return 0; 138 138 } 139 139 140 - static struct thermal_zone_device_ops da9062_thermal_ops = { 140 + static const struct thermal_zone_device_ops da9062_thermal_ops = { 141 141 .get_temp = da9062_thermal_get_temp, 142 142 }; 143 143
+1 -1
drivers/thermal/dove_thermal.c
··· 106 106 return 0; 107 107 } 108 108 109 - static struct thermal_zone_device_ops ops = { 109 + static const struct thermal_zone_device_ops ops = { 110 110 .get_temp = dove_get_temp, 111 111 }; 112 112
+1 -1
drivers/thermal/imx_thermal.c
··· 361 361 return trip->type == THERMAL_TRIP_PASSIVE; 362 362 } 363 363 364 - static struct thermal_zone_device_ops imx_tz_ops = { 364 + static const struct thermal_zone_device_ops imx_tz_ops = { 365 365 .should_bind = imx_should_bind, 366 366 .get_temp = imx_get_temp, 367 367 .change_mode = imx_change_mode,
+1 -1
drivers/thermal/intel/int340x_thermal/int3400_thermal.c
··· 515 515 return result; 516 516 } 517 517 518 - static struct thermal_zone_device_ops int3400_thermal_ops = { 518 + static const struct thermal_zone_device_ops int3400_thermal_ops = { 519 519 .get_temp = int3400_thermal_get_temp, 520 520 .change_mode = int3400_thermal_change_mode, 521 521 };
+71 -1
drivers/thermal/intel/int340x_thermal/platform_temperature_control.c
··· 38 38 39 39 #include <linux/kernel.h> 40 40 #include <linux/module.h> 41 + #include <linux/debugfs.h> 41 42 #include <linux/pci.h> 42 43 #include "processor_thermal_device.h" 43 44 ··· 50 49 }; 51 50 52 51 #define MAX_ATTR_GROUP_NAME_LEN 32 53 - #define PTC_MAX_ATTRS 3 52 + #define PTC_MAX_ATTRS 4 54 53 55 54 struct ptc_data { 56 55 u32 offset; 56 + struct pci_dev *pdev; 57 57 struct attribute_group ptc_attr_group; 58 58 struct attribute *ptc_attrs[PTC_MAX_ATTRS]; 59 59 struct device_attribute temperature_target_attr; 60 60 struct device_attribute enable_attr; 61 + struct device_attribute thermal_tolerance_attr; 61 62 char group_name[MAX_ATTR_GROUP_NAME_LEN]; 62 63 }; 63 64 ··· 81 78 static const char * const ptc_strings[] = { 82 79 "temperature_target", 83 80 "enable", 81 + "thermal_tolerance", 84 82 NULL 85 83 }; 86 84 ··· 181 177 PTC_STORE(temperature_target); 182 178 PTC_SHOW(enable); 183 179 PTC_STORE(enable); 180 + PTC_SHOW(thermal_tolerance); 181 + PTC_STORE(thermal_tolerance); 184 182 185 183 #define ptc_init_attribute(_name)\ 186 184 do {\ ··· 199 193 200 194 ptc_init_attribute(temperature_target); 201 195 ptc_init_attribute(enable); 196 + ptc_init_attribute(thermal_tolerance); 202 197 203 198 data->ptc_attrs[index++] = &data->temperature_target_attr.attr; 204 199 data->ptc_attrs[index++] = &data->enable_attr.attr; 200 + data->ptc_attrs[index++] = &data->thermal_tolerance_attr.attr; 205 201 data->ptc_attrs[index] = NULL; 206 202 207 203 snprintf(data->group_name, MAX_ATTR_GROUP_NAME_LEN, ··· 217 209 } 218 210 219 211 static struct ptc_data ptc_instance[PTC_MAX_INSTANCES]; 212 + static struct dentry *ptc_debugfs; 213 + 214 + #define PTC_TEMP_OVERRIDE_ENABLE_INDEX 4 215 + #define PTC_TEMP_OVERRIDE_INDEX 5 216 + 217 + static ssize_t ptc_temperature_write(struct file *file, const char __user *data, 218 + size_t count, loff_t *ppos) 219 + { 220 + struct ptc_data *ptc_instance = file->private_data; 221 + struct pci_dev *pdev = ptc_instance->pdev; 222 + char buf[32]; 223 + ssize_t len; 224 + u32 value; 225 + 226 + len = min(count, sizeof(buf) - 1); 227 + if (copy_from_user(buf, data, len)) 228 + return -EFAULT; 229 + 230 + buf[len] = '\0'; 231 + if (kstrtouint(buf, 0, &value)) 232 + return -EINVAL; 233 + 234 + if (ptc_mmio_regs[PTC_TEMP_OVERRIDE_INDEX].units) 235 + value /= ptc_mmio_regs[PTC_TEMP_OVERRIDE_INDEX].units; 236 + 237 + if (value > ptc_mmio_regs[PTC_TEMP_OVERRIDE_INDEX].mask) 238 + return -EINVAL; 239 + 240 + if (!value) { 241 + ptc_mmio_write(pdev, ptc_instance->offset, PTC_TEMP_OVERRIDE_ENABLE_INDEX, 0); 242 + } else { 243 + ptc_mmio_write(pdev, ptc_instance->offset, PTC_TEMP_OVERRIDE_INDEX, value); 244 + ptc_mmio_write(pdev, ptc_instance->offset, PTC_TEMP_OVERRIDE_ENABLE_INDEX, 1); 245 + } 246 + 247 + return count; 248 + } 249 + 250 + static const struct file_operations ptc_fops = { 251 + .open = simple_open, 252 + .write = ptc_temperature_write, 253 + .llseek = generic_file_llseek, 254 + }; 255 + 256 + static void ptc_create_debugfs(void) 257 + { 258 + ptc_debugfs = debugfs_create_dir("platform_temperature_control", NULL); 259 + 260 + debugfs_create_file("temperature_0", 0200, ptc_debugfs, &ptc_instance[0], &ptc_fops); 261 + debugfs_create_file("temperature_1", 0200, ptc_debugfs, &ptc_instance[1], &ptc_fops); 262 + debugfs_create_file("temperature_2", 0200, ptc_debugfs, &ptc_instance[2], &ptc_fops); 263 + } 264 + 265 + static void ptc_delete_debugfs(void) 266 + { 267 + debugfs_remove_recursive(ptc_debugfs); 268 + } 220 269 221 270 int proc_thermal_ptc_add(struct pci_dev *pdev, struct proc_thermal_device *proc_priv) 222 271 { ··· 282 217 283 218 for (i = 0; i < PTC_MAX_INSTANCES; i++) { 284 219 ptc_instance[i].offset = ptc_offsets[i]; 220 + ptc_instance[i].pdev = pdev; 285 221 ptc_create_groups(pdev, i, &ptc_instance[i]); 286 222 } 223 + 224 + ptc_create_debugfs(); 287 225 } 288 226 289 227 return 0; ··· 302 234 303 235 for (i = 0; i < PTC_MAX_INSTANCES; i++) 304 236 sysfs_remove_group(&pdev->dev.kobj, &ptc_instance[i].ptc_attr_group); 237 + 238 + ptc_delete_debugfs(); 305 239 } 306 240 } 307 241 EXPORT_SYMBOL_GPL(proc_thermal_ptc_remove);
+1
drivers/thermal/intel/int340x_thermal/processor_thermal_device.h
··· 31 31 #define PCI_DEVICE_ID_INTEL_SKL_THERMAL 0x1903 32 32 #define PCI_DEVICE_ID_INTEL_TGL_THERMAL 0x9A03 33 33 #define PCI_DEVICE_ID_INTEL_PTL_THERMAL 0xB01D 34 + #define PCI_DEVICE_ID_INTEL_WCL_THERMAL 0xFD1D 34 35 35 36 struct power_config { 36 37 u32 index;
+4
drivers/thermal/intel/int340x_thermal/processor_thermal_device_pci.c
··· 499 499 PROC_THERMAL_FEATURE_DLVR | PROC_THERMAL_FEATURE_DVFS | 500 500 PROC_THERMAL_FEATURE_MSI_SUPPORT | PROC_THERMAL_FEATURE_WT_HINT | 501 501 PROC_THERMAL_FEATURE_POWER_FLOOR | PROC_THERMAL_FEATURE_PTC) }, 502 + { PCI_DEVICE_DATA(INTEL, WCL_THERMAL, PROC_THERMAL_FEATURE_MSI_SUPPORT | 503 + PROC_THERMAL_FEATURE_RAPL | PROC_THERMAL_FEATURE_DLVR | 504 + PROC_THERMAL_FEATURE_DVFS | PROC_THERMAL_FEATURE_WT_HINT | 505 + PROC_THERMAL_FEATURE_POWER_FLOOR | PROC_THERMAL_FEATURE_PTC) }, 502 506 { }, 503 507 }; 504 508
+1
drivers/thermal/intel/int340x_thermal/processor_thermal_rfim.c
··· 442 442 switch (pdev->device) { 443 443 case PCI_DEVICE_ID_INTEL_LNLM_THERMAL: 444 444 case PCI_DEVICE_ID_INTEL_PTL_THERMAL: 445 + case PCI_DEVICE_ID_INTEL_WCL_THERMAL: 445 446 dlvr_mmio_regs_table = lnl_dlvr_mmio_regs; 446 447 dlvr_mapping = lnl_dlvr_mapping; 447 448 break;
+1 -1
drivers/thermal/kirkwood_thermal.c
··· 48 48 return 0; 49 49 } 50 50 51 - static struct thermal_zone_device_ops ops = { 51 + static const struct thermal_zone_device_ops ops = { 52 52 .get_temp = kirkwood_get_temp, 53 53 }; 54 54
+11 -4
drivers/thermal/loongson2_thermal.c
··· 112 112 return loongson2_thermal_set(data, low/MILLI, high/MILLI, true); 113 113 } 114 114 115 - static struct thermal_zone_device_ops loongson2_of_thermal_ops = { 115 + static const struct thermal_zone_device_ops loongson2_2k1000_of_thermal_ops = { 116 116 .get_temp = loongson2_2k1000_get_temp, 117 + .set_trips = loongson2_thermal_set_trips, 118 + }; 119 + 120 + static const struct thermal_zone_device_ops loongson2_2k2000_of_thermal_ops = { 121 + .get_temp = loongson2_2k2000_get_temp, 117 122 .set_trips = loongson2_thermal_set_trips, 118 123 }; 119 124 120 125 static int loongson2_thermal_probe(struct platform_device *pdev) 121 126 { 127 + const struct thermal_zone_device_ops *thermal_ops; 122 128 struct device *dev = &pdev->dev; 123 129 struct loongson2_thermal_data *data; 124 130 struct thermal_zone_device *tzd; ··· 146 140 if (IS_ERR(data->temp_reg)) 147 141 return PTR_ERR(data->temp_reg); 148 142 149 - loongson2_of_thermal_ops.get_temp = loongson2_2k2000_get_temp; 143 + thermal_ops = &loongson2_2k2000_of_thermal_ops; 144 + } else { 145 + thermal_ops = &loongson2_2k1000_of_thermal_ops; 150 146 } 151 147 152 148 irq = platform_get_irq(pdev, 0); ··· 160 152 loongson2_thermal_set(data, 0, 0, false); 161 153 162 154 for (i = 0; i <= LOONGSON2_MAX_SENSOR_SEL_NUM; i++) { 163 - tzd = devm_thermal_of_zone_register(dev, i, data, 164 - &loongson2_of_thermal_ops); 155 + tzd = devm_thermal_of_zone_register(dev, i, data, thermal_ops); 165 156 166 157 if (!IS_ERR(tzd)) 167 158 break;
+62 -14
drivers/thermal/mediatek/lvts_thermal.c
··· 125 125 126 126 struct lvts_data { 127 127 const struct lvts_ctrl_data *lvts_ctrl; 128 + const u32 *conn_cmd; 129 + const u32 *init_cmd; 128 130 int num_lvts_ctrl; 131 + int num_conn_cmd; 132 + int num_init_cmd; 129 133 int temp_factor; 130 134 int temp_offset; 131 135 int gt_calib_bit_offset; ··· 575 571 return iret; 576 572 } 577 573 578 - static struct thermal_zone_device_ops lvts_ops = { 574 + static const struct thermal_zone_device_ops lvts_ops = { 579 575 .get_temp = lvts_get_temp, 580 576 .set_trips = lvts_set_trips, 581 577 }; ··· 906 902 * each write in the configuration register must be separated by a 907 903 * delay of 2 us. 908 904 */ 909 - static void lvts_write_config(struct lvts_ctrl *lvts_ctrl, u32 *cmds, int nr_cmds) 905 + static void lvts_write_config(struct lvts_ctrl *lvts_ctrl, const u32 *cmds, int nr_cmds) 910 906 { 911 907 int i; 912 908 ··· 989 985 990 986 static int lvts_ctrl_connect(struct device *dev, struct lvts_ctrl *lvts_ctrl) 991 987 { 992 - u32 id, cmds[] = { 0xC103FFFF, 0xC502FF55 }; 988 + const struct lvts_data *lvts_data = lvts_ctrl->lvts_data; 989 + u32 id; 993 990 994 - lvts_write_config(lvts_ctrl, cmds, ARRAY_SIZE(cmds)); 991 + lvts_write_config(lvts_ctrl, lvts_data->conn_cmd, lvts_data->num_conn_cmd); 995 992 996 993 /* 997 994 * LVTS_ID : Get ID and status of the thermal controller ··· 1011 1006 1012 1007 static int lvts_ctrl_initialize(struct device *dev, struct lvts_ctrl *lvts_ctrl) 1013 1008 { 1014 - /* 1015 - * Write device mask: 0xC1030000 1016 - */ 1017 - u32 cmds[] = { 1018 - 0xC1030E01, 0xC1030CFC, 0xC1030A8C, 0xC103098D, 0xC10308F1, 1019 - 0xC10307A6, 0xC10306B8, 0xC1030500, 0xC1030420, 0xC1030300, 1020 - 0xC1030030, 0xC10300F6, 0xC1030050, 0xC1030060, 0xC10300AC, 1021 - 0xC10300FC, 0xC103009D, 0xC10300F1, 0xC10300E1 1022 - }; 1009 + const struct lvts_data *lvts_data = lvts_ctrl->lvts_data; 1023 1010 1024 - lvts_write_config(lvts_ctrl, cmds, ARRAY_SIZE(cmds)); 1011 + lvts_write_config(lvts_ctrl, lvts_data->init_cmd, lvts_data->num_init_cmd); 1025 1012 1026 1013 return 0; 1027 1014 } ··· 1442 1445 return 0; 1443 1446 } 1444 1447 1448 + static const u32 default_conn_cmds[] = { 0xC103FFFF, 0xC502FF55 }; 1449 + static const u32 mt7988_conn_cmds[] = { 0xC103FFFF, 0xC502FC55 }; 1450 + 1451 + /* 1452 + * Write device mask: 0xC1030000 1453 + */ 1454 + static const u32 default_init_cmds[] = { 1455 + 0xC1030E01, 0xC1030CFC, 0xC1030A8C, 0xC103098D, 0xC10308F1, 1456 + 0xC10307A6, 0xC10306B8, 0xC1030500, 0xC1030420, 0xC1030300, 1457 + 0xC1030030, 0xC10300F6, 0xC1030050, 0xC1030060, 0xC10300AC, 1458 + 0xC10300FC, 0xC103009D, 0xC10300F1, 0xC10300E1 1459 + }; 1460 + 1461 + static const u32 mt7988_init_cmds[] = { 1462 + 0xC1030300, 0xC1030420, 0xC1030500, 0xC10307A6, 0xC1030CFC, 1463 + 0xC1030A8C, 0xC103098D, 0xC10308F1, 0xC1030B04, 0xC1030E01, 1464 + 0xC10306B8 1465 + }; 1466 + 1445 1467 /* 1446 1468 * The MT8186 calibration data is stored as packed 3-byte little-endian 1447 1469 * values using a weird layout that makes sense only when viewed as a 32-bit ··· 1755 1739 1756 1740 static const struct lvts_data mt7988_lvts_ap_data = { 1757 1741 .lvts_ctrl = mt7988_lvts_ap_data_ctrl, 1742 + .conn_cmd = mt7988_conn_cmds, 1743 + .init_cmd = mt7988_init_cmds, 1758 1744 .num_lvts_ctrl = ARRAY_SIZE(mt7988_lvts_ap_data_ctrl), 1745 + .num_conn_cmd = ARRAY_SIZE(mt7988_conn_cmds), 1746 + .num_init_cmd = ARRAY_SIZE(mt7988_init_cmds), 1759 1747 .temp_factor = LVTS_COEFF_A_MT7988, 1760 1748 .temp_offset = LVTS_COEFF_B_MT7988, 1761 1749 .gt_calib_bit_offset = 24, ··· 1767 1747 1768 1748 static const struct lvts_data mt8186_lvts_data = { 1769 1749 .lvts_ctrl = mt8186_lvts_data_ctrl, 1750 + .conn_cmd = default_conn_cmds, 1751 + .init_cmd = default_init_cmds, 1770 1752 .num_lvts_ctrl = ARRAY_SIZE(mt8186_lvts_data_ctrl), 1753 + .num_conn_cmd = ARRAY_SIZE(default_conn_cmds), 1754 + .num_init_cmd = ARRAY_SIZE(default_init_cmds), 1771 1755 .temp_factor = LVTS_COEFF_A_MT7988, 1772 1756 .temp_offset = LVTS_COEFF_B_MT7988, 1773 1757 .gt_calib_bit_offset = 24, ··· 1780 1756 1781 1757 static const struct lvts_data mt8188_lvts_mcu_data = { 1782 1758 .lvts_ctrl = mt8188_lvts_mcu_data_ctrl, 1759 + .conn_cmd = default_conn_cmds, 1760 + .init_cmd = default_init_cmds, 1783 1761 .num_lvts_ctrl = ARRAY_SIZE(mt8188_lvts_mcu_data_ctrl), 1762 + .num_conn_cmd = ARRAY_SIZE(default_conn_cmds), 1763 + .num_init_cmd = ARRAY_SIZE(default_init_cmds), 1784 1764 .temp_factor = LVTS_COEFF_A_MT8195, 1785 1765 .temp_offset = LVTS_COEFF_B_MT8195, 1786 1766 .gt_calib_bit_offset = 20, ··· 1793 1765 1794 1766 static const struct lvts_data mt8188_lvts_ap_data = { 1795 1767 .lvts_ctrl = mt8188_lvts_ap_data_ctrl, 1768 + .conn_cmd = default_conn_cmds, 1769 + .init_cmd = default_init_cmds, 1796 1770 .num_lvts_ctrl = ARRAY_SIZE(mt8188_lvts_ap_data_ctrl), 1771 + .num_conn_cmd = ARRAY_SIZE(default_conn_cmds), 1772 + .num_init_cmd = ARRAY_SIZE(default_init_cmds), 1797 1773 .temp_factor = LVTS_COEFF_A_MT8195, 1798 1774 .temp_offset = LVTS_COEFF_B_MT8195, 1799 1775 .gt_calib_bit_offset = 20, ··· 1806 1774 1807 1775 static const struct lvts_data mt8192_lvts_mcu_data = { 1808 1776 .lvts_ctrl = mt8192_lvts_mcu_data_ctrl, 1777 + .conn_cmd = default_conn_cmds, 1778 + .init_cmd = default_init_cmds, 1809 1779 .num_lvts_ctrl = ARRAY_SIZE(mt8192_lvts_mcu_data_ctrl), 1780 + .num_conn_cmd = ARRAY_SIZE(default_conn_cmds), 1781 + .num_init_cmd = ARRAY_SIZE(default_init_cmds), 1810 1782 .temp_factor = LVTS_COEFF_A_MT8195, 1811 1783 .temp_offset = LVTS_COEFF_B_MT8195, 1812 1784 .gt_calib_bit_offset = 24, ··· 1819 1783 1820 1784 static const struct lvts_data mt8192_lvts_ap_data = { 1821 1785 .lvts_ctrl = mt8192_lvts_ap_data_ctrl, 1786 + .conn_cmd = default_conn_cmds, 1787 + .init_cmd = default_init_cmds, 1822 1788 .num_lvts_ctrl = ARRAY_SIZE(mt8192_lvts_ap_data_ctrl), 1789 + .num_conn_cmd = ARRAY_SIZE(default_conn_cmds), 1790 + .num_init_cmd = ARRAY_SIZE(default_init_cmds), 1823 1791 .temp_factor = LVTS_COEFF_A_MT8195, 1824 1792 .temp_offset = LVTS_COEFF_B_MT8195, 1825 1793 .gt_calib_bit_offset = 24, ··· 1832 1792 1833 1793 static const struct lvts_data mt8195_lvts_mcu_data = { 1834 1794 .lvts_ctrl = mt8195_lvts_mcu_data_ctrl, 1795 + .conn_cmd = default_conn_cmds, 1796 + .init_cmd = default_init_cmds, 1835 1797 .num_lvts_ctrl = ARRAY_SIZE(mt8195_lvts_mcu_data_ctrl), 1798 + .num_conn_cmd = ARRAY_SIZE(default_conn_cmds), 1799 + .num_init_cmd = ARRAY_SIZE(default_init_cmds), 1836 1800 .temp_factor = LVTS_COEFF_A_MT8195, 1837 1801 .temp_offset = LVTS_COEFF_B_MT8195, 1838 1802 .gt_calib_bit_offset = 24, ··· 1845 1801 1846 1802 static const struct lvts_data mt8195_lvts_ap_data = { 1847 1803 .lvts_ctrl = mt8195_lvts_ap_data_ctrl, 1804 + .conn_cmd = default_conn_cmds, 1805 + .init_cmd = default_init_cmds, 1848 1806 .num_lvts_ctrl = ARRAY_SIZE(mt8195_lvts_ap_data_ctrl), 1807 + .num_conn_cmd = ARRAY_SIZE(default_conn_cmds), 1808 + .num_init_cmd = ARRAY_SIZE(default_init_cmds), 1849 1809 .temp_factor = LVTS_COEFF_A_MT8195, 1850 1810 .temp_offset = LVTS_COEFF_B_MT8195, 1851 1811 .gt_calib_bit_offset = 24,
+1 -2
drivers/thermal/qcom/lmh.c
··· 209 209 } 210 210 211 211 lmh_data->irq = platform_get_irq(pdev, 0); 212 - lmh_data->domain = irq_domain_create_linear(of_fwnode_handle(np), 1, &lmh_irq_ops, 213 - lmh_data); 212 + lmh_data->domain = irq_domain_create_linear(dev_fwnode(dev), 1, &lmh_irq_ops, lmh_data); 214 213 if (!lmh_data->domain) { 215 214 dev_err(dev, "Error adding irq_domain\n"); 216 215 return -EINVAL;
+521 -77
drivers/thermal/qcom/qcom-spmi-temp-alarm.c
··· 1 1 // SPDX-License-Identifier: GPL-2.0-only 2 2 /* 3 3 * Copyright (c) 2011-2015, 2017, 2020, The Linux Foundation. All rights reserved. 4 + * Copyright (c) Qualcomm Technologies, Inc. and/or its subsidiaries. 4 5 */ 5 6 7 + #include <linux/bitfield.h> 6 8 #include <linux/bitops.h> 7 9 #include <linux/delay.h> 8 10 #include <linux/err.h> ··· 18 16 19 17 #include "../thermal_hwmon.h" 20 18 19 + #define QPNP_TM_REG_DIG_MINOR 0x00 21 20 #define QPNP_TM_REG_DIG_MAJOR 0x01 22 21 #define QPNP_TM_REG_TYPE 0x04 23 22 #define QPNP_TM_REG_SUBTYPE 0x05 24 23 #define QPNP_TM_REG_STATUS 0x08 24 + #define QPNP_TM_REG_IRQ_STATUS 0x10 25 25 #define QPNP_TM_REG_SHUTDOWN_CTRL1 0x40 26 26 #define QPNP_TM_REG_ALARM_CTRL 0x46 27 + 28 + /* TEMP_DAC_STGx registers are only present for TEMP_GEN2 v2.0 */ 29 + #define QPNP_TM_REG_TEMP_DAC_STG1 0x47 30 + #define QPNP_TM_REG_TEMP_DAC_STG2 0x48 31 + #define QPNP_TM_REG_TEMP_DAC_STG3 0x49 32 + #define QPNP_TM_REG_LITE_TEMP_CFG1 0x50 33 + #define QPNP_TM_REG_LITE_TEMP_CFG2 0x51 27 34 28 35 #define QPNP_TM_TYPE 0x09 29 36 #define QPNP_TM_SUBTYPE_GEN1 0x08 30 37 #define QPNP_TM_SUBTYPE_GEN2 0x09 38 + #define QPNP_TM_SUBTYPE_LITE 0xC0 31 39 32 40 #define STATUS_GEN1_STAGE_MASK GENMASK(1, 0) 33 41 #define STATUS_GEN2_STATE_MASK GENMASK(6, 4) 34 - #define STATUS_GEN2_STATE_SHIFT 4 35 42 36 - #define SHUTDOWN_CTRL1_OVERRIDE_S2 BIT(6) 43 + /* IRQ status only needed for TEMP_ALARM_LITE */ 44 + #define IRQ_STATUS_MASK BIT(0) 45 + 46 + #define SHUTDOWN_CTRL1_OVERRIDE_STAGE2 BIT(6) 37 47 #define SHUTDOWN_CTRL1_THRESHOLD_MASK GENMASK(1, 0) 38 48 39 49 #define SHUTDOWN_CTRL1_RATE_25HZ BIT(3) 40 50 41 51 #define ALARM_CTRL_FORCE_ENABLE BIT(7) 42 52 53 + #define LITE_TEMP_CFG_THRESHOLD_MASK GENMASK(3, 2) 54 + 43 55 #define THRESH_COUNT 4 44 56 #define STAGE_COUNT 3 57 + 58 + enum overtemp_stage { 59 + STAGE1 = 0, 60 + STAGE2, 61 + STAGE3, 62 + }; 45 63 46 64 /* Over-temperature trip point values in mC */ 47 65 static const long temp_map_gen1[THRESH_COUNT][STAGE_COUNT] = { ··· 85 63 86 64 #define TEMP_STAGE_HYSTERESIS 2000 87 65 66 + /* 67 + * For TEMP_GEN2 v2.0, TEMP_DAC_STG1/2/3 registers are used to set the threshold 68 + * for each stage independently. 69 + * TEMP_DAC_STG* = 0 --> 80 C 70 + * Each 8 step increase in TEMP_DAC_STG* value corresponds to 5 C (5000 mC). 71 + */ 72 + #define TEMP_DAC_MIN 80000 73 + #define TEMP_DAC_SCALE_NUM 8 74 + #define TEMP_DAC_SCALE_DEN 5000 75 + 76 + #define TEMP_DAC_TEMP_TO_REG(temp) \ 77 + (((temp) - TEMP_DAC_MIN) * TEMP_DAC_SCALE_NUM / TEMP_DAC_SCALE_DEN) 78 + #define TEMP_DAC_REG_TO_TEMP(reg) \ 79 + (TEMP_DAC_MIN + (reg) * TEMP_DAC_SCALE_DEN / TEMP_DAC_SCALE_NUM) 80 + 81 + static const long temp_dac_max[STAGE_COUNT] = { 82 + 119375, 159375, 159375 83 + }; 84 + 85 + /* 86 + * TEMP_ALARM_LITE has two stages: warning and shutdown with independently 87 + * configured threshold temperatures. 88 + */ 89 + 90 + static const long temp_lite_warning_map[THRESH_COUNT] = { 91 + 115000, 125000, 135000, 145000 92 + }; 93 + 94 + static const long temp_lite_shutdown_map[THRESH_COUNT] = { 95 + 135000, 145000, 160000, 175000 96 + }; 97 + 88 98 /* Temperature in Milli Celsius reported during stage 0 if no ADC is present */ 89 99 #define DEFAULT_TEMP 37000 100 + 101 + struct qpnp_tm_chip; 102 + 103 + struct spmi_temp_alarm_data { 104 + const struct thermal_zone_device_ops *ops; 105 + const long (*temp_map)[THRESH_COUNT][STAGE_COUNT]; 106 + int (*sync_thresholds)(struct qpnp_tm_chip *chip); 107 + int (*get_temp_stage)(struct qpnp_tm_chip *chip); 108 + int (*configure_trip_temps)(struct qpnp_tm_chip *chip); 109 + }; 90 110 91 111 struct qpnp_tm_chip { 92 112 struct regmap *map; 93 113 struct device *dev; 94 114 struct thermal_zone_device *tz_dev; 115 + const struct spmi_temp_alarm_data *data; 95 116 unsigned int subtype; 96 117 long temp; 97 - unsigned int thresh; 98 118 unsigned int stage; 99 119 unsigned int base; 120 + unsigned int ntrips; 100 121 /* protects .thresh, .stage and chip registers */ 101 122 struct mutex lock; 102 123 bool initialized; 124 + bool require_stage2_shutdown; 125 + long temp_thresh_map[STAGE_COUNT]; 103 126 104 127 struct iio_channel *adc; 105 - const long (*temp_map)[THRESH_COUNT][STAGE_COUNT]; 106 128 }; 107 129 108 130 /* This array maps from GEN2 alarm state to GEN1 alarm stage */ ··· 180 114 */ 181 115 static long qpnp_tm_decode_temp(struct qpnp_tm_chip *chip, unsigned int stage) 182 116 { 183 - if (!chip->temp_map || chip->thresh >= THRESH_COUNT || stage == 0 || 184 - stage > STAGE_COUNT) 117 + if (stage == 0 || stage > STAGE_COUNT) 185 118 return 0; 186 119 187 - return (*chip->temp_map)[chip->thresh][stage - 1]; 120 + return chip->temp_thresh_map[stage - 1]; 188 121 } 189 122 190 123 /** 191 - * qpnp_tm_get_temp_stage() - return over-temperature stage 124 + * qpnp_tm_gen1_get_temp_stage() - return over-temperature stage 192 125 * @chip: Pointer to the qpnp_tm chip 193 126 * 194 - * Return: stage (GEN1) or state (GEN2) on success, or errno on failure. 127 + * Return: stage on success, or errno on failure. 195 128 */ 196 - static int qpnp_tm_get_temp_stage(struct qpnp_tm_chip *chip) 129 + static int qpnp_tm_gen1_get_temp_stage(struct qpnp_tm_chip *chip) 197 130 { 198 131 int ret; 199 - u8 reg = 0; 132 + u8 reg; 200 133 201 134 ret = qpnp_tm_read(chip, QPNP_TM_REG_STATUS, &reg); 202 135 if (ret < 0) 203 136 return ret; 204 137 205 - if (chip->subtype == QPNP_TM_SUBTYPE_GEN1) 206 - ret = reg & STATUS_GEN1_STAGE_MASK; 207 - else 208 - ret = (reg & STATUS_GEN2_STATE_MASK) >> STATUS_GEN2_STATE_SHIFT; 138 + return FIELD_GET(STATUS_GEN1_STAGE_MASK, reg); 139 + } 209 140 210 - return ret; 141 + /** 142 + * qpnp_tm_gen2_get_temp_stage() - return over-temperature stage 143 + * @chip: Pointer to the qpnp_tm chip 144 + * 145 + * Return: stage on success, or errno on failure. 146 + */ 147 + static int qpnp_tm_gen2_get_temp_stage(struct qpnp_tm_chip *chip) 148 + { 149 + int ret; 150 + u8 reg; 151 + 152 + ret = qpnp_tm_read(chip, QPNP_TM_REG_STATUS, &reg); 153 + if (ret < 0) 154 + return ret; 155 + 156 + ret = FIELD_GET(STATUS_GEN2_STATE_MASK, reg); 157 + 158 + return alarm_state_map[ret]; 159 + } 160 + 161 + /** 162 + * qpnp_tm_lite_get_temp_stage() - return over-temperature stage 163 + * @chip: Pointer to the qpnp_tm chip 164 + * 165 + * Return: alarm interrupt state on success, or errno on failure. 166 + */ 167 + static int qpnp_tm_lite_get_temp_stage(struct qpnp_tm_chip *chip) 168 + { 169 + u8 reg = 0; 170 + int ret; 171 + 172 + ret = qpnp_tm_read(chip, QPNP_TM_REG_IRQ_STATUS, &reg); 173 + if (ret < 0) 174 + return ret; 175 + 176 + return FIELD_GET(IRQ_STATUS_MASK, reg); 211 177 } 212 178 213 179 /* ··· 248 150 */ 249 151 static int qpnp_tm_update_temp_no_adc(struct qpnp_tm_chip *chip) 250 152 { 251 - unsigned int stage, stage_new, stage_old; 153 + unsigned int stage_new, stage_old; 252 154 int ret; 253 155 254 156 WARN_ON(!mutex_is_locked(&chip->lock)); 255 157 256 - ret = qpnp_tm_get_temp_stage(chip); 158 + ret = chip->data->get_temp_stage(chip); 257 159 if (ret < 0) 258 160 return ret; 259 - stage = ret; 260 - 261 - if (chip->subtype == QPNP_TM_SUBTYPE_GEN1) { 262 - stage_new = stage; 263 - stage_old = chip->stage; 264 - } else { 265 - stage_new = alarm_state_map[stage]; 266 - stage_old = alarm_state_map[chip->stage]; 267 - } 161 + stage_new = ret; 162 + stage_old = chip->stage; 268 163 269 164 if (stage_new > stage_old) { 270 165 /* increasing stage, use lower bound */ ··· 269 178 - TEMP_STAGE_HYSTERESIS; 270 179 } 271 180 272 - chip->stage = stage; 181 + chip->stage = stage_new; 273 182 274 183 return 0; 275 184 } ··· 309 218 static int qpnp_tm_update_critical_trip_temp(struct qpnp_tm_chip *chip, 310 219 int temp) 311 220 { 312 - long stage2_threshold_min = (*chip->temp_map)[THRESH_MIN][1]; 313 - long stage2_threshold_max = (*chip->temp_map)[THRESH_MAX][1]; 314 - bool disable_s2_shutdown = false; 315 - u8 reg; 221 + long stage2_threshold_min = (*chip->data->temp_map)[THRESH_MIN][STAGE2]; 222 + long stage2_threshold_max = (*chip->data->temp_map)[THRESH_MAX][STAGE2]; 223 + bool disable_stage2_shutdown = false; 224 + u8 reg, threshold; 316 225 317 226 WARN_ON(!mutex_is_locked(&chip->lock)); 318 227 319 228 /* 320 - * Default: S2 and S3 shutdown enabled, thresholds at 229 + * Default: Stage 2 and Stage 3 shutdown enabled, thresholds at 321 230 * lowest threshold set, monitoring at 25Hz 322 231 */ 323 232 reg = SHUTDOWN_CTRL1_RATE_25HZ; 324 233 325 234 if (temp == THERMAL_TEMP_INVALID || 326 235 temp < stage2_threshold_min) { 327 - chip->thresh = THRESH_MIN; 236 + threshold = THRESH_MIN; 328 237 goto skip; 329 238 } 330 239 331 240 if (temp <= stage2_threshold_max) { 332 - chip->thresh = THRESH_MAX - 241 + threshold = THRESH_MAX - 333 242 ((stage2_threshold_max - temp) / 334 243 TEMP_THRESH_STEP); 335 - disable_s2_shutdown = true; 244 + disable_stage2_shutdown = true; 336 245 } else { 337 - chip->thresh = THRESH_MAX; 246 + threshold = THRESH_MAX; 338 247 339 248 if (chip->adc) 340 - disable_s2_shutdown = true; 249 + disable_stage2_shutdown = true; 341 250 else 342 251 dev_warn(chip->dev, 343 252 "No ADC is configured and critical temperature %d mC is above the maximum stage 2 threshold of %ld mC! Configuring stage 2 shutdown at %ld mC.\n", ··· 345 254 } 346 255 347 256 skip: 348 - reg |= chip->thresh; 349 - if (disable_s2_shutdown) 350 - reg |= SHUTDOWN_CTRL1_OVERRIDE_S2; 257 + memcpy(chip->temp_thresh_map, chip->data->temp_map[threshold], 258 + sizeof(chip->temp_thresh_map)); 259 + reg |= threshold; 260 + if (disable_stage2_shutdown && !chip->require_stage2_shutdown) 261 + reg |= SHUTDOWN_CTRL1_OVERRIDE_STAGE2; 351 262 352 263 return qpnp_tm_write(chip, QPNP_TM_REG_SHUTDOWN_CTRL1, reg); 353 264 } ··· 375 282 .set_trip_temp = qpnp_tm_set_trip_temp, 376 283 }; 377 284 285 + static int qpnp_tm_gen2_rev2_set_temp_thresh(struct qpnp_tm_chip *chip, unsigned int trip, int temp) 286 + { 287 + int ret, temp_cfg; 288 + u8 reg; 289 + 290 + WARN_ON(!mutex_is_locked(&chip->lock)); 291 + 292 + if (trip >= STAGE_COUNT) { 293 + dev_err(chip->dev, "invalid TEMP_DAC trip = %d\n", trip); 294 + return -EINVAL; 295 + } else if (temp < TEMP_DAC_MIN || temp > temp_dac_max[trip]) { 296 + dev_err(chip->dev, "invalid TEMP_DAC temp = %d\n", temp); 297 + return -EINVAL; 298 + } 299 + 300 + reg = TEMP_DAC_TEMP_TO_REG(temp); 301 + temp_cfg = TEMP_DAC_REG_TO_TEMP(reg); 302 + 303 + ret = qpnp_tm_write(chip, QPNP_TM_REG_TEMP_DAC_STG1 + trip, reg); 304 + if (ret < 0) { 305 + dev_err(chip->dev, "TEMP_DAC_STG write failed, ret=%d\n", ret); 306 + return ret; 307 + } 308 + 309 + chip->temp_thresh_map[trip] = temp_cfg; 310 + 311 + return 0; 312 + } 313 + 314 + static int qpnp_tm_gen2_rev2_set_trip_temp(struct thermal_zone_device *tz, 315 + const struct thermal_trip *trip, int temp) 316 + { 317 + unsigned int trip_index = THERMAL_TRIP_PRIV_TO_INT(trip->priv); 318 + struct qpnp_tm_chip *chip = thermal_zone_device_priv(tz); 319 + int ret; 320 + 321 + mutex_lock(&chip->lock); 322 + ret = qpnp_tm_gen2_rev2_set_temp_thresh(chip, trip_index, temp); 323 + mutex_unlock(&chip->lock); 324 + 325 + return ret; 326 + } 327 + 328 + static const struct thermal_zone_device_ops qpnp_tm_gen2_rev2_sensor_ops = { 329 + .get_temp = qpnp_tm_get_temp, 330 + .set_trip_temp = qpnp_tm_gen2_rev2_set_trip_temp, 331 + }; 332 + 333 + static int qpnp_tm_lite_set_temp_thresh(struct qpnp_tm_chip *chip, unsigned int trip, int temp) 334 + { 335 + int ret, temp_cfg, i; 336 + const long *temp_map; 337 + u8 reg, thresh; 338 + u16 addr; 339 + 340 + WARN_ON(!mutex_is_locked(&chip->lock)); 341 + 342 + if (trip >= STAGE_COUNT) { 343 + dev_err(chip->dev, "invalid TEMP_LITE trip = %d\n", trip); 344 + return -EINVAL; 345 + } 346 + 347 + switch (trip) { 348 + case 0: 349 + temp_map = temp_lite_warning_map; 350 + addr = QPNP_TM_REG_LITE_TEMP_CFG1; 351 + break; 352 + case 1: 353 + /* 354 + * The second trip point is purely in software to facilitate 355 + * a controlled shutdown after the warning threshold is crossed 356 + * but before the automatic hardware shutdown threshold is 357 + * crossed. 358 + */ 359 + return 0; 360 + case 2: 361 + temp_map = temp_lite_shutdown_map; 362 + addr = QPNP_TM_REG_LITE_TEMP_CFG2; 363 + break; 364 + default: 365 + return 0; 366 + } 367 + 368 + if (temp < temp_map[THRESH_MIN] || temp > temp_map[THRESH_MAX]) { 369 + dev_err(chip->dev, "invalid TEMP_LITE temp = %d\n", temp); 370 + return -EINVAL; 371 + } 372 + 373 + thresh = 0; 374 + temp_cfg = temp_map[thresh]; 375 + for (i = THRESH_MAX; i >= THRESH_MIN; i--) { 376 + if (temp >= temp_map[i]) { 377 + thresh = i; 378 + temp_cfg = temp_map[i]; 379 + break; 380 + } 381 + } 382 + 383 + if (temp_cfg == chip->temp_thresh_map[trip]) 384 + return 0; 385 + 386 + ret = qpnp_tm_read(chip, addr, &reg); 387 + if (ret < 0) { 388 + dev_err(chip->dev, "LITE_TEMP_CFG read failed, ret=%d\n", ret); 389 + return ret; 390 + } 391 + 392 + reg &= ~LITE_TEMP_CFG_THRESHOLD_MASK; 393 + reg |= FIELD_PREP(LITE_TEMP_CFG_THRESHOLD_MASK, thresh); 394 + 395 + ret = qpnp_tm_write(chip, addr, reg); 396 + if (ret < 0) { 397 + dev_err(chip->dev, "LITE_TEMP_CFG write failed, ret=%d\n", ret); 398 + return ret; 399 + } 400 + 401 + chip->temp_thresh_map[trip] = temp_cfg; 402 + 403 + return 0; 404 + } 405 + 406 + static int qpnp_tm_lite_set_trip_temp(struct thermal_zone_device *tz, 407 + const struct thermal_trip *trip, int temp) 408 + { 409 + unsigned int trip_index = THERMAL_TRIP_PRIV_TO_INT(trip->priv); 410 + struct qpnp_tm_chip *chip = thermal_zone_device_priv(tz); 411 + int ret; 412 + 413 + mutex_lock(&chip->lock); 414 + ret = qpnp_tm_lite_set_temp_thresh(chip, trip_index, temp); 415 + mutex_unlock(&chip->lock); 416 + 417 + return ret; 418 + } 419 + 420 + static const struct thermal_zone_device_ops qpnp_tm_lite_sensor_ops = { 421 + .get_temp = qpnp_tm_get_temp, 422 + .set_trip_temp = qpnp_tm_lite_set_trip_temp, 423 + }; 424 + 378 425 static irqreturn_t qpnp_tm_isr(int irq, void *data) 379 426 { 380 427 struct qpnp_tm_chip *chip = data; ··· 524 291 return IRQ_HANDLED; 525 292 } 526 293 527 - /* 528 - * This function initializes the internal temp value based on only the 529 - * current thermal stage and threshold. Setup threshold control and 530 - * disable shutdown override. 531 - */ 532 - static int qpnp_tm_init(struct qpnp_tm_chip *chip) 294 + /* Read the hardware default stage threshold temperatures */ 295 + static int qpnp_tm_sync_thresholds(struct qpnp_tm_chip *chip) 533 296 { 534 - unsigned int stage; 297 + u8 reg, threshold; 535 298 int ret; 536 - u8 reg = 0; 537 - int crit_temp; 538 - 539 - mutex_lock(&chip->lock); 540 299 541 300 ret = qpnp_tm_read(chip, QPNP_TM_REG_SHUTDOWN_CTRL1, &reg); 542 301 if (ret < 0) 543 - goto out; 302 + return ret; 544 303 545 - chip->thresh = reg & SHUTDOWN_CTRL1_THRESHOLD_MASK; 546 - chip->temp = DEFAULT_TEMP; 304 + threshold = reg & SHUTDOWN_CTRL1_THRESHOLD_MASK; 305 + memcpy(chip->temp_thresh_map, chip->data->temp_map[threshold], 306 + sizeof(chip->temp_thresh_map)); 547 307 548 - ret = qpnp_tm_get_temp_stage(chip); 549 - if (ret < 0) 550 - goto out; 551 - chip->stage = ret; 308 + return ret; 309 + } 552 310 553 - stage = chip->subtype == QPNP_TM_SUBTYPE_GEN1 554 - ? chip->stage : alarm_state_map[chip->stage]; 555 - 556 - if (stage) 557 - chip->temp = qpnp_tm_decode_temp(chip, stage); 558 - 559 - mutex_unlock(&chip->lock); 311 + static int qpnp_tm_configure_trip_temp(struct qpnp_tm_chip *chip) 312 + { 313 + int crit_temp, ret; 560 314 561 315 ret = thermal_zone_get_crit_temp(chip->tz_dev, &crit_temp); 562 316 if (ret) 563 317 crit_temp = THERMAL_TEMP_INVALID; 564 318 565 319 mutex_lock(&chip->lock); 566 - 567 320 ret = qpnp_tm_update_critical_trip_temp(chip, crit_temp); 321 + mutex_unlock(&chip->lock); 322 + 323 + return ret; 324 + } 325 + 326 + /* Configure TEMP_DAC registers based on DT thermal_zone trips */ 327 + static int qpnp_tm_gen2_rev2_configure_trip_temps_cb(struct thermal_trip *trip, void *data) 328 + { 329 + struct qpnp_tm_chip *chip = data; 330 + int ret; 331 + 332 + mutex_lock(&chip->lock); 333 + trip->priv = THERMAL_INT_TO_TRIP_PRIV(chip->ntrips); 334 + ret = qpnp_tm_gen2_rev2_set_temp_thresh(chip, chip->ntrips, trip->temperature); 335 + chip->ntrips++; 336 + mutex_unlock(&chip->lock); 337 + 338 + return ret; 339 + } 340 + 341 + static int qpnp_tm_gen2_rev2_configure_trip_temps(struct qpnp_tm_chip *chip) 342 + { 343 + int ret, i; 344 + 345 + ret = thermal_zone_for_each_trip(chip->tz_dev, 346 + qpnp_tm_gen2_rev2_configure_trip_temps_cb, chip); 568 347 if (ret < 0) 569 - goto out; 348 + return ret; 349 + 350 + /* Verify that trips are strictly increasing. */ 351 + for (i = 1; i < STAGE_COUNT; i++) { 352 + if (chip->temp_thresh_map[i] <= chip->temp_thresh_map[i - 1]) { 353 + dev_err(chip->dev, "Threshold %d=%ld <= threshold %d=%ld\n", 354 + i, chip->temp_thresh_map[i], i - 1, 355 + chip->temp_thresh_map[i - 1]); 356 + return -EINVAL; 357 + } 358 + } 359 + 360 + return 0; 361 + } 362 + 363 + /* Read the hardware default TEMP_DAC stage threshold temperatures */ 364 + static int qpnp_tm_gen2_rev2_sync_thresholds(struct qpnp_tm_chip *chip) 365 + { 366 + int ret, i; 367 + u8 reg = 0; 368 + 369 + for (i = 0; i < STAGE_COUNT; i++) { 370 + ret = qpnp_tm_read(chip, QPNP_TM_REG_TEMP_DAC_STG1 + i, &reg); 371 + if (ret < 0) 372 + return ret; 373 + 374 + chip->temp_thresh_map[i] = TEMP_DAC_REG_TO_TEMP(reg); 375 + } 376 + 377 + return 0; 378 + } 379 + 380 + /* Configure TEMP_LITE registers based on DT thermal_zone trips */ 381 + static int qpnp_tm_lite_configure_trip_temps_cb(struct thermal_trip *trip, void *data) 382 + { 383 + struct qpnp_tm_chip *chip = data; 384 + int ret; 385 + 386 + mutex_lock(&chip->lock); 387 + trip->priv = THERMAL_INT_TO_TRIP_PRIV(chip->ntrips); 388 + ret = qpnp_tm_lite_set_temp_thresh(chip, chip->ntrips, trip->temperature); 389 + chip->ntrips++; 390 + mutex_unlock(&chip->lock); 391 + 392 + return ret; 393 + } 394 + 395 + static int qpnp_tm_lite_configure_trip_temps(struct qpnp_tm_chip *chip) 396 + { 397 + int ret; 398 + 399 + ret = thermal_zone_for_each_trip(chip->tz_dev, qpnp_tm_lite_configure_trip_temps_cb, chip); 400 + if (ret < 0) 401 + return ret; 402 + 403 + /* Verify that trips are strictly increasing. */ 404 + if (chip->temp_thresh_map[2] <= chip->temp_thresh_map[0]) { 405 + dev_err(chip->dev, "Threshold 2=%ld <= threshold 0=%ld\n", 406 + chip->temp_thresh_map[2], chip->temp_thresh_map[0]); 407 + return -EINVAL; 408 + } 409 + 410 + return 0; 411 + } 412 + 413 + /* Read the hardware default TEMP_LITE stage threshold temperatures */ 414 + static int qpnp_tm_lite_sync_thresholds(struct qpnp_tm_chip *chip) 415 + { 416 + int ret, thresh; 417 + u8 reg = 0; 418 + 419 + /* 420 + * Store the warning trip temp in temp_thresh_map[0] and the shutdown trip 421 + * temp in temp_thresh_map[2]. The second trip point is purely in software 422 + * to facilitate a controlled shutdown after the warning threshold is 423 + * crossed but before the automatic hardware shutdown threshold is 424 + * crossed. Thus, there is no register to read for the second trip 425 + * point. 426 + */ 427 + ret = qpnp_tm_read(chip, QPNP_TM_REG_LITE_TEMP_CFG1, &reg); 428 + if (ret < 0) 429 + return ret; 430 + 431 + thresh = FIELD_GET(LITE_TEMP_CFG_THRESHOLD_MASK, reg); 432 + chip->temp_thresh_map[0] = temp_lite_warning_map[thresh]; 433 + 434 + ret = qpnp_tm_read(chip, QPNP_TM_REG_LITE_TEMP_CFG2, &reg); 435 + if (ret < 0) 436 + return ret; 437 + 438 + thresh = FIELD_GET(LITE_TEMP_CFG_THRESHOLD_MASK, reg); 439 + chip->temp_thresh_map[2] = temp_lite_shutdown_map[thresh]; 440 + 441 + return 0; 442 + } 443 + 444 + static const struct spmi_temp_alarm_data spmi_temp_alarm_data = { 445 + .ops = &qpnp_tm_sensor_ops, 446 + .temp_map = &temp_map_gen1, 447 + .sync_thresholds = qpnp_tm_sync_thresholds, 448 + .configure_trip_temps = qpnp_tm_configure_trip_temp, 449 + .get_temp_stage = qpnp_tm_gen1_get_temp_stage, 450 + }; 451 + 452 + static const struct spmi_temp_alarm_data spmi_temp_alarm_gen2_data = { 453 + .ops = &qpnp_tm_sensor_ops, 454 + .temp_map = &temp_map_gen1, 455 + .sync_thresholds = qpnp_tm_sync_thresholds, 456 + .configure_trip_temps = qpnp_tm_configure_trip_temp, 457 + .get_temp_stage = qpnp_tm_gen2_get_temp_stage, 458 + }; 459 + 460 + static const struct spmi_temp_alarm_data spmi_temp_alarm_gen2_rev1_data = { 461 + .ops = &qpnp_tm_sensor_ops, 462 + .temp_map = &temp_map_gen2_v1, 463 + .sync_thresholds = qpnp_tm_sync_thresholds, 464 + .configure_trip_temps = qpnp_tm_configure_trip_temp, 465 + .get_temp_stage = qpnp_tm_gen2_get_temp_stage, 466 + }; 467 + 468 + static const struct spmi_temp_alarm_data spmi_temp_alarm_gen2_rev2_data = { 469 + .ops = &qpnp_tm_gen2_rev2_sensor_ops, 470 + .sync_thresholds = qpnp_tm_gen2_rev2_sync_thresholds, 471 + .configure_trip_temps = qpnp_tm_gen2_rev2_configure_trip_temps, 472 + .get_temp_stage = qpnp_tm_gen2_get_temp_stage, 473 + }; 474 + 475 + static const struct spmi_temp_alarm_data spmi_temp_alarm_lite_data = { 476 + .ops = &qpnp_tm_lite_sensor_ops, 477 + .sync_thresholds = qpnp_tm_lite_sync_thresholds, 478 + .configure_trip_temps = qpnp_tm_lite_configure_trip_temps, 479 + .get_temp_stage = qpnp_tm_lite_get_temp_stage, 480 + }; 481 + 482 + /* 483 + * This function initializes the internal temp value based on only the 484 + * current thermal stage and threshold. 485 + */ 486 + static int qpnp_tm_threshold_init(struct qpnp_tm_chip *chip) 487 + { 488 + int ret; 489 + 490 + ret = chip->data->sync_thresholds(chip); 491 + if (ret < 0) 492 + return ret; 493 + 494 + ret = chip->data->get_temp_stage(chip); 495 + if (ret < 0) 496 + return ret; 497 + chip->stage = ret; 498 + chip->temp = DEFAULT_TEMP; 499 + 500 + if (chip->stage) 501 + chip->temp = qpnp_tm_decode_temp(chip, chip->stage); 502 + 503 + return ret; 504 + } 505 + 506 + /* This function initializes threshold control and disables shutdown override. */ 507 + static int qpnp_tm_init(struct qpnp_tm_chip *chip) 508 + { 509 + int ret; 510 + u8 reg; 511 + 512 + ret = chip->data->configure_trip_temps(chip); 513 + if (ret < 0) 514 + return ret; 570 515 571 516 /* Enable the thermal alarm PMIC module in always-on mode. */ 572 517 reg = ALARM_CTRL_FORCE_ENABLE; ··· 752 341 753 342 chip->initialized = true; 754 343 755 - out: 756 - mutex_unlock(&chip->lock); 757 344 return ret; 758 345 } 759 346 ··· 759 350 { 760 351 struct qpnp_tm_chip *chip; 761 352 struct device_node *node; 762 - u8 type, subtype, dig_major; 763 - u32 res; 353 + u8 type, subtype, dig_major, dig_minor; 354 + u32 res, dig_revision; 764 355 int ret, irq; 765 356 766 357 node = pdev->dev.of_node; ··· 811 402 return dev_err_probe(&pdev->dev, ret, 812 403 "could not read dig_major\n"); 813 404 405 + ret = qpnp_tm_read(chip, QPNP_TM_REG_DIG_MINOR, &dig_minor); 406 + if (ret < 0) 407 + return dev_err_probe(&pdev->dev, ret, 408 + "could not read dig_minor\n"); 409 + 814 410 if (type != QPNP_TM_TYPE || (subtype != QPNP_TM_SUBTYPE_GEN1 815 - && subtype != QPNP_TM_SUBTYPE_GEN2)) { 411 + && subtype != QPNP_TM_SUBTYPE_GEN2 412 + && subtype != QPNP_TM_SUBTYPE_LITE)) { 816 413 dev_err(&pdev->dev, "invalid type 0x%02x or subtype 0x%02x\n", 817 414 type, subtype); 818 415 return -ENODEV; 819 416 } 820 417 821 418 chip->subtype = subtype; 822 - if (subtype == QPNP_TM_SUBTYPE_GEN2 && dig_major >= 1) 823 - chip->temp_map = &temp_map_gen2_v1; 419 + if (subtype == QPNP_TM_SUBTYPE_GEN1) 420 + chip->data = &spmi_temp_alarm_data; 421 + else if (subtype == QPNP_TM_SUBTYPE_GEN2 && dig_major == 0) 422 + chip->data = &spmi_temp_alarm_gen2_data; 423 + else if (subtype == QPNP_TM_SUBTYPE_GEN2 && dig_major == 1) 424 + chip->data = &spmi_temp_alarm_gen2_rev1_data; 425 + else if (subtype == QPNP_TM_SUBTYPE_GEN2 && dig_major >= 2) 426 + chip->data = &spmi_temp_alarm_gen2_rev2_data; 427 + else if (subtype == QPNP_TM_SUBTYPE_LITE) 428 + chip->data = &spmi_temp_alarm_lite_data; 824 429 else 825 - chip->temp_map = &temp_map_gen1; 430 + return -ENODEV; 431 + 432 + if (chip->subtype == QPNP_TM_SUBTYPE_GEN2) { 433 + dig_revision = (dig_major << 8) | dig_minor; 434 + /* 435 + * Check if stage 2 automatic partial shutdown must remain 436 + * enabled to avoid potential repeated faults upon reaching 437 + * over-temperature stage 3. 438 + */ 439 + switch (dig_revision) { 440 + case 0x0001: 441 + case 0x0002: 442 + case 0x0100: 443 + case 0x0101: 444 + chip->require_stage2_shutdown = true; 445 + break; 446 + } 447 + } 448 + 449 + ret = qpnp_tm_threshold_init(chip); 450 + if (ret < 0) 451 + return dev_err_probe(&pdev->dev, ret, "threshold init failed\n"); 826 452 827 453 /* 828 454 * Register the sensor before initializing the hardware to be able to ··· 865 421 * before the hardware initialization is completed. 866 422 */ 867 423 chip->tz_dev = devm_thermal_of_zone_register( 868 - &pdev->dev, 0, chip, &qpnp_tm_sensor_ops); 424 + &pdev->dev, 0, chip, chip->data->ops); 869 425 if (IS_ERR(chip->tz_dev)) 870 426 return dev_err_probe(&pdev->dev, PTR_ERR(chip->tz_dev), 871 427 "failed to register sensor\n");
+1 -1
drivers/thermal/renesas/rcar_thermal.c
··· 277 277 return rcar_thermal_get_current_temp(priv, temp); 278 278 } 279 279 280 - static struct thermal_zone_device_ops rcar_thermal_zone_ops = { 280 + static const struct thermal_zone_device_ops rcar_thermal_zone_ops = { 281 281 .get_temp = rcar_thermal_get_temp, 282 282 }; 283 283
+230 -21
drivers/thermal/rockchip_thermal.c
··· 9 9 #include <linux/interrupt.h> 10 10 #include <linux/io.h> 11 11 #include <linux/module.h> 12 + #include <linux/nvmem-consumer.h> 12 13 #include <linux/of.h> 13 14 #include <linux/of_address.h> 14 15 #include <linux/of_irq.h> ··· 70 69 * struct rockchip_tsadc_chip - hold the private data of tsadc chip 71 70 * @chn_offset: the channel offset of the first channel 72 71 * @chn_num: the channel number of tsadc chip 73 - * @tshut_temp: the hardware-controlled shutdown temperature value 72 + * @trim_slope: used to convert the trim code to a temperature in millicelsius 73 + * @tshut_temp: the hardware-controlled shutdown temperature value, with no trim 74 74 * @tshut_mode: the hardware-controlled shutdown mode (0:CRU 1:GPIO) 75 75 * @tshut_polarity: the hardware-controlled active polarity (0:LOW 1:HIGH) 76 76 * @initialize: SoC special initialize tsadc controller method 77 77 * @irq_ack: clear the interrupt 78 78 * @control: enable/disable method for the tsadc controller 79 - * @get_temp: get the temperature 79 + * @get_temp: get the raw temperature, unadjusted by trim 80 80 * @set_alarm_temp: set the high temperature interrupt 81 81 * @set_tshut_temp: set the hardware-controlled shutdown temperature 82 82 * @set_tshut_mode: set the hardware-controlled shutdown mode 83 + * @get_trim_code: convert a hardware temperature code to one adjusted for by trim 83 84 * @table: the chip-specific conversion table 84 85 */ 85 86 struct rockchip_tsadc_chip { 86 87 /* The sensor id of chip correspond to the ADC channel */ 87 88 int chn_offset; 88 89 int chn_num; 90 + 91 + /* Used to convert trim code to trim temp */ 92 + int trim_slope; 89 93 90 94 /* The hardware-controlled tshut property */ 91 95 int tshut_temp; ··· 111 105 int (*set_tshut_temp)(const struct chip_tsadc_table *table, 112 106 int chn, void __iomem *reg, int temp); 113 107 void (*set_tshut_mode)(int chn, void __iomem *reg, enum tshut_mode m); 108 + int (*get_trim_code)(const struct chip_tsadc_table *table, 109 + int code, int trim_base, int trim_base_frac); 114 110 115 111 /* Per-table methods */ 116 112 struct chip_tsadc_table table; ··· 122 114 * struct rockchip_thermal_sensor - hold the information of thermal sensor 123 115 * @thermal: pointer to the platform/configuration data 124 116 * @tzd: pointer to a thermal zone 117 + * @of_node: pointer to the device_node representing this sensor, if any 125 118 * @id: identifier of the thermal sensor 119 + * @trim_temp: per-sensor trim temperature value 126 120 */ 127 121 struct rockchip_thermal_sensor { 128 122 struct rockchip_thermal_data *thermal; 129 123 struct thermal_zone_device *tzd; 124 + struct device_node *of_node; 130 125 int id; 126 + int trim_temp; 131 127 }; 132 128 133 129 /** ··· 144 132 * @pclk: the advanced peripherals bus clock 145 133 * @grf: the general register file will be used to do static set by software 146 134 * @regs: the base address of tsadc controller 147 - * @tshut_temp: the hardware-controlled shutdown temperature value 135 + * @trim_base: major component of sensor trim value, in Celsius 136 + * @trim_base_frac: minor component of sensor trim value, in Decicelsius 137 + * @trim: fallback thermal trim value for each channel 138 + * @tshut_temp: the hardware-controlled shutdown temperature value, with no trim 139 + * @trim_temp: the fallback trim temperature for the whole sensor 148 140 * @tshut_mode: the hardware-controlled shutdown mode (0:CRU 1:GPIO) 149 141 * @tshut_polarity: the hardware-controlled active polarity (0:LOW 1:HIGH) 150 142 */ ··· 165 149 struct regmap *grf; 166 150 void __iomem *regs; 167 151 152 + int trim_base; 153 + int trim_base_frac; 154 + int trim; 155 + 168 156 int tshut_temp; 157 + int trim_temp; 169 158 enum tshut_mode tshut_mode; 170 159 enum tshut_polarity tshut_polarity; 171 160 }; ··· 269 248 #define GRF_TSADC_VCM_EN_H (0x10001 << 7) 270 249 271 250 #define GRF_CON_TSADC_CH_INV (0x10001 << 1) 251 + 252 + 253 + #define RK_MAX_TEMP (180000) 272 254 273 255 /** 274 256 * struct tsadc_table - code to temperature conversion table ··· 1069 1045 writel_relaxed(val, regs + TSADCV2_INT_EN); 1070 1046 } 1071 1047 1072 - static void rk_tsadcv3_tshut_mode(int chn, void __iomem *regs, 1048 + static void rk_tsadcv4_tshut_mode(int chn, void __iomem *regs, 1073 1049 enum tshut_mode mode) 1074 1050 { 1075 1051 u32 val_gpio, val_cru; ··· 1083 1059 } 1084 1060 writel_relaxed(val_gpio, regs + TSADCV3_HSHUT_GPIO_INT_EN); 1085 1061 writel_relaxed(val_cru, regs + TSADCV3_HSHUT_CRU_INT_EN); 1062 + } 1063 + 1064 + static int rk_tsadcv2_get_trim_code(const struct chip_tsadc_table *table, 1065 + int code, int trim_base, int trim_base_frac) 1066 + { 1067 + int temp = trim_base * 1000 + trim_base_frac * 100; 1068 + u32 base_code = rk_tsadcv2_temp_to_code(table, temp); 1069 + 1070 + return code - base_code; 1086 1071 } 1087 1072 1088 1073 static const struct rockchip_tsadc_chip px30_tsadc_data = { ··· 1317 1284 }, 1318 1285 }; 1319 1286 1287 + static const struct rockchip_tsadc_chip rk3576_tsadc_data = { 1288 + /* top, big_core, little_core, ddr, npu, gpu */ 1289 + .chn_offset = 0, 1290 + .chn_num = 6, /* six channels for tsadc */ 1291 + .tshut_mode = TSHUT_MODE_GPIO, /* default TSHUT via GPIO give PMIC */ 1292 + .tshut_polarity = TSHUT_LOW_ACTIVE, /* default TSHUT LOW ACTIVE */ 1293 + .tshut_temp = 95000, 1294 + .initialize = rk_tsadcv8_initialize, 1295 + .irq_ack = rk_tsadcv4_irq_ack, 1296 + .control = rk_tsadcv4_control, 1297 + .get_temp = rk_tsadcv4_get_temp, 1298 + .set_alarm_temp = rk_tsadcv3_alarm_temp, 1299 + .set_tshut_temp = rk_tsadcv3_tshut_temp, 1300 + .set_tshut_mode = rk_tsadcv4_tshut_mode, 1301 + .get_trim_code = rk_tsadcv2_get_trim_code, 1302 + .trim_slope = 923, 1303 + .table = { 1304 + .id = rk3588_code_table, 1305 + .length = ARRAY_SIZE(rk3588_code_table), 1306 + .data_mask = TSADCV4_DATA_MASK, 1307 + .mode = ADC_INCREMENT, 1308 + }, 1309 + }; 1310 + 1320 1311 static const struct rockchip_tsadc_chip rk3588_tsadc_data = { 1321 1312 /* top, big_core0, big_core1, little_core, center, gpu, npu */ 1322 1313 .chn_offset = 0, ··· 1354 1297 .get_temp = rk_tsadcv4_get_temp, 1355 1298 .set_alarm_temp = rk_tsadcv3_alarm_temp, 1356 1299 .set_tshut_temp = rk_tsadcv3_tshut_temp, 1357 - .set_tshut_mode = rk_tsadcv3_tshut_mode, 1300 + .set_tshut_mode = rk_tsadcv4_tshut_mode, 1358 1301 .table = { 1359 1302 .id = rk3588_code_table, 1360 1303 .length = ARRAY_SIZE(rk3588_code_table), ··· 1398 1341 { 1399 1342 .compatible = "rockchip,rk3568-tsadc", 1400 1343 .data = (void *)&rk3568_tsadc_data, 1344 + }, 1345 + { 1346 + .compatible = "rockchip,rk3576-tsadc", 1347 + .data = (void *)&rk3576_tsadc_data, 1401 1348 }, 1402 1349 { 1403 1350 .compatible = "rockchip,rk3588-tsadc", ··· 1448 1387 __func__, sensor->id, low, high); 1449 1388 1450 1389 return tsadc->set_alarm_temp(&tsadc->table, 1451 - sensor->id, thermal->regs, high); 1390 + sensor->id, thermal->regs, high + sensor->trim_temp); 1452 1391 } 1453 1392 1454 1393 static int rockchip_thermal_get_temp(struct thermal_zone_device *tz, int *out_temp) ··· 1460 1399 1461 1400 retval = tsadc->get_temp(&tsadc->table, 1462 1401 sensor->id, thermal->regs, out_temp); 1402 + *out_temp -= sensor->trim_temp; 1403 + 1463 1404 return retval; 1464 1405 } 1465 1406 ··· 1469 1406 .get_temp = rockchip_thermal_get_temp, 1470 1407 .set_trips = rockchip_thermal_set_trips, 1471 1408 }; 1409 + 1410 + /** 1411 + * rockchip_get_efuse_value - read an OTP cell from a device node 1412 + * @np: pointer to the device node with the nvmem-cells property 1413 + * @cell_name: name of cell that should be read 1414 + * @value: pointer to where the read value will be placed 1415 + * 1416 + * Return: Negative errno on failure, during which *value will not be touched, 1417 + * or 0 on success. 1418 + */ 1419 + static int rockchip_get_efuse_value(struct device_node *np, const char *cell_name, 1420 + int *value) 1421 + { 1422 + struct nvmem_cell *cell; 1423 + int ret = 0; 1424 + size_t len; 1425 + u8 *buf; 1426 + int i; 1427 + 1428 + cell = of_nvmem_cell_get(np, cell_name); 1429 + if (IS_ERR(cell)) 1430 + return PTR_ERR(cell); 1431 + 1432 + buf = nvmem_cell_read(cell, &len); 1433 + 1434 + nvmem_cell_put(cell); 1435 + 1436 + if (IS_ERR(buf)) 1437 + return PTR_ERR(buf); 1438 + 1439 + if (len > sizeof(*value)) { 1440 + ret = -ERANGE; 1441 + goto exit; 1442 + } 1443 + 1444 + /* Copy with implicit endian conversion */ 1445 + *value = 0; 1446 + for (i = 0; i < len; i++) 1447 + *value |= (int) buf[i] << (8 * i); 1448 + 1449 + exit: 1450 + kfree(buf); 1451 + return ret; 1452 + } 1453 + 1454 + static int rockchip_get_trim_configuration(struct device *dev, struct device_node *np, 1455 + struct rockchip_thermal_data *thermal) 1456 + { 1457 + const struct rockchip_tsadc_chip *tsadc = thermal->chip; 1458 + int trim_base = 0, trim_base_frac = 0, trim = 0; 1459 + int trim_code; 1460 + int ret; 1461 + 1462 + thermal->trim_base = 0; 1463 + thermal->trim_base_frac = 0; 1464 + thermal->trim = 0; 1465 + 1466 + if (!tsadc->get_trim_code) 1467 + return 0; 1468 + 1469 + ret = rockchip_get_efuse_value(np, "trim_base", &trim_base); 1470 + if (ret < 0) { 1471 + if (ret == -ENOENT) { 1472 + trim_base = 30; 1473 + dev_dbg(dev, "trim_base is absent, defaulting to 30\n"); 1474 + } else { 1475 + dev_err(dev, "failed reading nvmem value of trim_base: %pe\n", 1476 + ERR_PTR(ret)); 1477 + return ret; 1478 + } 1479 + } 1480 + ret = rockchip_get_efuse_value(np, "trim_base_frac", &trim_base_frac); 1481 + if (ret < 0) { 1482 + if (ret == -ENOENT) { 1483 + dev_dbg(dev, "trim_base_frac is absent, defaulting to 0\n"); 1484 + } else { 1485 + dev_err(dev, "failed reading nvmem value of trim_base_frac: %pe\n", 1486 + ERR_PTR(ret)); 1487 + return ret; 1488 + } 1489 + } 1490 + thermal->trim_base = trim_base; 1491 + thermal->trim_base_frac = trim_base_frac; 1492 + 1493 + /* 1494 + * If the tsadc node contains the trim property, then it is used in the 1495 + * absence of per-channel trim values 1496 + */ 1497 + if (!rockchip_get_efuse_value(np, "trim", &trim)) 1498 + thermal->trim = trim; 1499 + if (trim) { 1500 + trim_code = tsadc->get_trim_code(&tsadc->table, trim, 1501 + trim_base, trim_base_frac); 1502 + thermal->trim_temp = thermal->chip->trim_slope * trim_code; 1503 + } 1504 + 1505 + return 0; 1506 + } 1472 1507 1473 1508 static int rockchip_configure_from_dt(struct device *dev, 1474 1509 struct device_node *np, ··· 1628 1467 if (IS_ERR(thermal->grf)) 1629 1468 dev_warn(dev, "Missing rockchip,grf property\n"); 1630 1469 1470 + rockchip_get_trim_configuration(dev, np, thermal); 1471 + 1631 1472 return 0; 1632 1473 } 1633 1474 ··· 1640 1477 int id) 1641 1478 { 1642 1479 const struct rockchip_tsadc_chip *tsadc = thermal->chip; 1480 + struct device *dev = &pdev->dev; 1481 + int trim = thermal->trim; 1482 + int trim_code, tshut_temp; 1483 + int trim_temp = 0; 1643 1484 int error; 1485 + 1486 + if (thermal->trim_temp) 1487 + trim_temp = thermal->trim_temp; 1488 + 1489 + if (tsadc->get_trim_code && sensor->of_node) { 1490 + error = rockchip_get_efuse_value(sensor->of_node, "trim", &trim); 1491 + if (error < 0 && error != -ENOENT) { 1492 + dev_err(dev, "failed reading trim of sensor %d: %pe\n", 1493 + id, ERR_PTR(error)); 1494 + return error; 1495 + } 1496 + if (trim) { 1497 + trim_code = tsadc->get_trim_code(&tsadc->table, trim, 1498 + thermal->trim_base, 1499 + thermal->trim_base_frac); 1500 + trim_temp = thermal->chip->trim_slope * trim_code; 1501 + } 1502 + } 1503 + 1504 + sensor->trim_temp = trim_temp; 1505 + 1506 + dev_dbg(dev, "trim of sensor %d is %d\n", id, sensor->trim_temp); 1507 + 1508 + tshut_temp = min(thermal->tshut_temp + sensor->trim_temp, RK_MAX_TEMP); 1644 1509 1645 1510 tsadc->set_tshut_mode(id, thermal->regs, thermal->tshut_mode); 1646 1511 1647 - error = tsadc->set_tshut_temp(&tsadc->table, id, thermal->regs, 1648 - thermal->tshut_temp); 1512 + error = tsadc->set_tshut_temp(&tsadc->table, id, thermal->regs, tshut_temp); 1649 1513 if (error) 1650 - dev_err(&pdev->dev, "%s: invalid tshut=%d, error=%d\n", 1651 - __func__, thermal->tshut_temp, error); 1514 + dev_err(dev, "%s: invalid tshut=%d, error=%d\n", 1515 + __func__, tshut_temp, error); 1652 1516 1653 1517 sensor->thermal = thermal; 1654 1518 sensor->id = id; 1655 - sensor->tzd = devm_thermal_of_zone_register(&pdev->dev, id, sensor, 1519 + sensor->tzd = devm_thermal_of_zone_register(dev, id, sensor, 1656 1520 &rockchip_of_thermal_ops); 1657 1521 if (IS_ERR(sensor->tzd)) { 1658 1522 error = PTR_ERR(sensor->tzd); 1659 - dev_err(&pdev->dev, "failed to register sensor %d: %d\n", 1523 + dev_err(dev, "failed to register sensor %d: %d\n", 1660 1524 id, error); 1661 1525 return error; 1662 1526 } ··· 1706 1516 { 1707 1517 struct device_node *np = pdev->dev.of_node; 1708 1518 struct rockchip_thermal_data *thermal; 1519 + struct device_node *child; 1709 1520 int irq; 1710 1521 int i; 1711 1522 int error; 1523 + u32 chn; 1712 1524 1713 1525 irq = platform_get_irq(pdev, 0); 1714 1526 if (irq < 0) ··· 1760 1568 1761 1569 thermal->chip->initialize(thermal->grf, thermal->regs, 1762 1570 thermal->tshut_polarity); 1571 + 1572 + for_each_available_child_of_node(np, child) { 1573 + if (!of_property_read_u32(child, "reg", &chn)) { 1574 + if (chn < thermal->chip->chn_num) 1575 + thermal->sensors[chn].of_node = child; 1576 + else 1577 + dev_warn(&pdev->dev, 1578 + "sensor address (%d) too large, ignoring its trim\n", 1579 + chn); 1580 + } 1581 + 1582 + } 1763 1583 1764 1584 for (i = 0; i < thermal->chip->chn_num; i++) { 1765 1585 error = rockchip_thermal_register_sensor(pdev, thermal, ··· 1842 1638 static int __maybe_unused rockchip_thermal_resume(struct device *dev) 1843 1639 { 1844 1640 struct rockchip_thermal_data *thermal = dev_get_drvdata(dev); 1845 - int i; 1641 + const struct rockchip_tsadc_chip *tsadc = thermal->chip; 1642 + struct rockchip_thermal_sensor *sensor; 1643 + int tshut_temp; 1846 1644 int error; 1645 + int i; 1847 1646 1848 1647 error = clk_enable(thermal->clk); 1849 1648 if (error) ··· 1860 1653 1861 1654 rockchip_thermal_reset_controller(thermal->reset); 1862 1655 1863 - thermal->chip->initialize(thermal->grf, thermal->regs, 1864 - thermal->tshut_polarity); 1656 + tsadc->initialize(thermal->grf, thermal->regs, thermal->tshut_polarity); 1865 1657 1866 1658 for (i = 0; i < thermal->chip->chn_num; i++) { 1867 - int id = thermal->sensors[i].id; 1659 + sensor = &thermal->sensors[i]; 1868 1660 1869 - thermal->chip->set_tshut_mode(id, thermal->regs, 1661 + tshut_temp = min(thermal->tshut_temp + sensor->trim_temp, 1662 + RK_MAX_TEMP); 1663 + 1664 + tsadc->set_tshut_mode(sensor->id, thermal->regs, 1870 1665 thermal->tshut_mode); 1871 1666 1872 - error = thermal->chip->set_tshut_temp(&thermal->chip->table, 1873 - id, thermal->regs, 1874 - thermal->tshut_temp); 1667 + error = tsadc->set_tshut_temp(&thermal->chip->table, 1668 + sensor->id, thermal->regs, 1669 + tshut_temp); 1875 1670 if (error) 1876 1671 dev_err(dev, "%s: invalid tshut=%d, error=%d\n", 1877 - __func__, thermal->tshut_temp, error); 1672 + __func__, tshut_temp, error); 1878 1673 } 1879 1674 1880 1675 thermal->chip->control(thermal->regs, true);
+1 -1
drivers/thermal/spear_thermal.c
··· 41 41 return 0; 42 42 } 43 43 44 - static struct thermal_zone_device_ops ops = { 44 + static const struct thermal_zone_device_ops ops = { 45 45 .get_temp = thermal_get_temp, 46 46 }; 47 47
+1 -1
drivers/thermal/st/st_thermal.c
··· 132 132 return 0; 133 133 } 134 134 135 - static struct thermal_zone_device_ops st_tz_ops = { 135 + static const struct thermal_zone_device_ops st_tz_ops = { 136 136 .get_temp = st_thermal_get_temp, 137 137 }; 138 138
+5 -8
drivers/thermal/tegra/soctherm.c
··· 1206 1206 /** 1207 1207 * soctherm_oc_int_init() - Initial enabling of the over 1208 1208 * current interrupts 1209 - * @np: The devicetree node for soctherm 1209 + * @fwnode: The devicetree node for soctherm 1210 1210 * @num_irqs: The number of new interrupt requests 1211 1211 * 1212 1212 * Sets the over current interrupt request chip data ··· 1215 1215 * -ENOMEM (out of memory), or irq_base if the function failed to 1216 1216 * allocate the irqs 1217 1217 */ 1218 - static int soctherm_oc_int_init(struct device_node *np, int num_irqs) 1218 + static int soctherm_oc_int_init(struct fwnode_handle *fwnode, int num_irqs) 1219 1219 { 1220 1220 if (!num_irqs) { 1221 1221 pr_info("%s(): OC interrupts are not enabled\n", __func__); ··· 1234 1234 soc_irq_cdata.irq_chip.irq_set_type = soctherm_oc_irq_set_type; 1235 1235 soc_irq_cdata.irq_chip.irq_set_wake = NULL; 1236 1236 1237 - soc_irq_cdata.domain = irq_domain_create_linear(of_fwnode_handle(np), num_irqs, 1238 - &soctherm_oc_domain_ops, 1239 - &soc_irq_cdata); 1240 - 1237 + soc_irq_cdata.domain = irq_domain_create_linear(fwnode, num_irqs, &soctherm_oc_domain_ops, 1238 + &soc_irq_cdata); 1241 1239 if (!soc_irq_cdata.domain) { 1242 1240 pr_err("%s: Failed to create IRQ domain\n", __func__); 1243 1241 return -ENOMEM; ··· 1966 1968 static int soctherm_interrupts_init(struct platform_device *pdev, 1967 1969 struct tegra_soctherm *tegra) 1968 1970 { 1969 - struct device_node *np = pdev->dev.of_node; 1970 1971 int ret; 1971 1972 1972 - ret = soctherm_oc_int_init(np, TEGRA_SOC_OC_IRQ_MAX); 1973 + ret = soctherm_oc_int_init(dev_fwnode(&pdev->dev), TEGRA_SOC_OC_IRQ_MAX); 1973 1974 if (ret < 0) { 1974 1975 dev_err(&pdev->dev, "soctherm_oc_int_init failed\n"); 1975 1976 return ret;
+1 -1
drivers/thermal/testing/zone.c
··· 381 381 return 0; 382 382 } 383 383 384 - static struct thermal_zone_device_ops tt_zone_ops = { 384 + static const struct thermal_zone_device_ops tt_zone_ops = { 385 385 .get_temp = tt_zone_get_temp, 386 386 }; 387 387
+6 -3
drivers/thermal/thermal_sysfs.c
··· 40 40 41 41 ret = thermal_zone_get_temp(tz, &temperature); 42 42 43 - if (ret) 44 - return ret; 43 + if (!ret) 44 + return sprintf(buf, "%d\n", temperature); 45 45 46 - return sprintf(buf, "%d\n", temperature); 46 + if (ret == -EAGAIN) 47 + return -ENODATA; 48 + 49 + return ret; 47 50 } 48 51 49 52 static ssize_t