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

Configure Feed

Select the types of activity you want to include in your feed.

Merge tag 'hwmon-for-v6.1-rc4' of git://git.kernel.org/pub/scm/linux/kernel/git/groeck/linux-staging

Pull hwmon fixes from Guenter Roeck:
"Fix two regressions:

- Commit 54cc3dbfc10d ("hwmon: (pmbus) Add regulator supply into
macro") resulted in regulator undercount when disabling regulators.
Revert it.

- The thermal subsystem rework caused the scmi driver to no longer
register with the thermal subsystem because index values no longer
match. To fix the problem, the scmi driver now directly registers
with the thermal subsystem, no longer through the hwmon core"

* tag 'hwmon-for-v6.1-rc4' of git://git.kernel.org/pub/scm/linux/kernel/git/groeck/linux-staging:
Revert "hwmon: (pmbus) Add regulator supply into macro"
hwmon: (scmi) Register explicitly with Thermal Framework

+103 -14
-1
drivers/hwmon/pmbus/pmbus.h
··· 467 467 #define PMBUS_REGULATOR_STEP(_name, _id, _voltages, _step) \ 468 468 [_id] = { \ 469 469 .name = (_name # _id), \ 470 - .supply_name = "vin", \ 471 470 .id = (_id), \ 472 471 .of_match = of_match_ptr(_name # _id), \ 473 472 .regulators_node = of_match_ptr("regulators"), \
+103 -13
drivers/hwmon/scmi-hwmon.c
··· 20 20 const struct scmi_sensor_info **info[hwmon_max]; 21 21 }; 22 22 23 + struct scmi_thermal_sensor { 24 + const struct scmi_protocol_handle *ph; 25 + const struct scmi_sensor_info *info; 26 + }; 27 + 23 28 static inline u64 __pow10(u8 x) 24 29 { 25 30 u64 r = 1; ··· 69 64 return 0; 70 65 } 71 66 72 - static int scmi_hwmon_read(struct device *dev, enum hwmon_sensor_types type, 73 - u32 attr, int channel, long *val) 67 + static int scmi_hwmon_read_scaled_value(const struct scmi_protocol_handle *ph, 68 + const struct scmi_sensor_info *sensor, 69 + long *val) 74 70 { 75 71 int ret; 76 72 u64 value; 77 - const struct scmi_sensor_info *sensor; 78 - struct scmi_sensors *scmi_sensors = dev_get_drvdata(dev); 79 73 80 - sensor = *(scmi_sensors->info[type] + channel); 81 - ret = sensor_ops->reading_get(scmi_sensors->ph, sensor->id, &value); 74 + ret = sensor_ops->reading_get(ph, sensor->id, &value); 82 75 if (ret) 83 76 return ret; 84 77 ··· 85 82 *val = value; 86 83 87 84 return ret; 85 + } 86 + 87 + static int scmi_hwmon_read(struct device *dev, enum hwmon_sensor_types type, 88 + u32 attr, int channel, long *val) 89 + { 90 + const struct scmi_sensor_info *sensor; 91 + struct scmi_sensors *scmi_sensors = dev_get_drvdata(dev); 92 + 93 + sensor = *(scmi_sensors->info[type] + channel); 94 + 95 + return scmi_hwmon_read_scaled_value(scmi_sensors->ph, sensor, val); 88 96 } 89 97 90 98 static int ··· 136 122 .info = NULL, 137 123 }; 138 124 125 + static int scmi_hwmon_thermal_get_temp(struct thermal_zone_device *tz, 126 + int *temp) 127 + { 128 + int ret; 129 + long value; 130 + struct scmi_thermal_sensor *th_sensor = tz->devdata; 131 + 132 + ret = scmi_hwmon_read_scaled_value(th_sensor->ph, th_sensor->info, 133 + &value); 134 + if (!ret) 135 + *temp = value; 136 + 137 + return ret; 138 + } 139 + 140 + static const struct thermal_zone_device_ops scmi_hwmon_thermal_ops = { 141 + .get_temp = scmi_hwmon_thermal_get_temp, 142 + }; 143 + 139 144 static int scmi_hwmon_add_chan_info(struct hwmon_channel_info *scmi_hwmon_chan, 140 145 struct device *dev, int num, 141 146 enum hwmon_sensor_types type, u32 config) ··· 182 149 }; 183 150 184 151 static u32 hwmon_attributes[hwmon_max] = { 185 - [hwmon_chip] = HWMON_C_REGISTER_TZ, 186 152 [hwmon_temp] = HWMON_T_INPUT | HWMON_T_LABEL, 187 153 [hwmon_in] = HWMON_I_INPUT | HWMON_I_LABEL, 188 154 [hwmon_curr] = HWMON_C_INPUT | HWMON_C_LABEL, 189 155 [hwmon_power] = HWMON_P_INPUT | HWMON_P_LABEL, 190 156 [hwmon_energy] = HWMON_E_INPUT | HWMON_E_LABEL, 191 157 }; 158 + 159 + static int scmi_thermal_sensor_register(struct device *dev, 160 + const struct scmi_protocol_handle *ph, 161 + const struct scmi_sensor_info *sensor) 162 + { 163 + struct scmi_thermal_sensor *th_sensor; 164 + struct thermal_zone_device *tzd; 165 + 166 + th_sensor = devm_kzalloc(dev, sizeof(*th_sensor), GFP_KERNEL); 167 + if (!th_sensor) 168 + return -ENOMEM; 169 + 170 + th_sensor->ph = ph; 171 + th_sensor->info = sensor; 172 + 173 + /* 174 + * Try to register a temperature sensor with the Thermal Framework: 175 + * skip sensors not defined as part of any thermal zone (-ENODEV) but 176 + * report any other errors related to misconfigured zones/sensors. 177 + */ 178 + tzd = devm_thermal_of_zone_register(dev, th_sensor->info->id, th_sensor, 179 + &scmi_hwmon_thermal_ops); 180 + if (IS_ERR(tzd)) { 181 + devm_kfree(dev, th_sensor); 182 + 183 + if (PTR_ERR(tzd) != -ENODEV) 184 + return PTR_ERR(tzd); 185 + 186 + dev_dbg(dev, "Sensor '%s' not attached to any thermal zone.\n", 187 + sensor->name); 188 + } else { 189 + dev_dbg(dev, "Sensor '%s' attached to thermal zone ID:%d\n", 190 + sensor->name, tzd->id); 191 + } 192 + 193 + return 0; 194 + } 192 195 193 196 static int scmi_hwmon_probe(struct scmi_device *sdev) 194 197 { ··· 233 164 enum hwmon_sensor_types type; 234 165 struct scmi_sensors *scmi_sensors; 235 166 const struct scmi_sensor_info *sensor; 236 - int nr_count[hwmon_max] = {0}, nr_types = 0; 167 + int nr_count[hwmon_max] = {0}, nr_types = 0, nr_count_temp = 0; 237 168 const struct hwmon_chip_info *chip_info; 238 169 struct device *hwdev, *dev = &sdev->dev; 239 170 struct hwmon_channel_info *scmi_hwmon_chan; ··· 277 208 } 278 209 } 279 210 280 - if (nr_count[hwmon_temp]) { 281 - nr_count[hwmon_chip]++; 282 - nr_types++; 283 - } 211 + if (nr_count[hwmon_temp]) 212 + nr_count_temp = nr_count[hwmon_temp]; 284 213 285 214 scmi_hwmon_chan = devm_kcalloc(dev, nr_types, sizeof(*scmi_hwmon_chan), 286 215 GFP_KERNEL); ··· 329 262 hwdev = devm_hwmon_device_register_with_info(dev, "scmi_sensors", 330 263 scmi_sensors, chip_info, 331 264 NULL); 265 + if (IS_ERR(hwdev)) 266 + return PTR_ERR(hwdev); 332 267 333 - return PTR_ERR_OR_ZERO(hwdev); 268 + for (i = 0; i < nr_count_temp; i++) { 269 + int ret; 270 + 271 + sensor = *(scmi_sensors->info[hwmon_temp] + i); 272 + if (!sensor) 273 + continue; 274 + 275 + /* 276 + * Warn on any misconfiguration related to thermal zones but 277 + * bail out of probing only on memory errors. 278 + */ 279 + ret = scmi_thermal_sensor_register(dev, ph, sensor); 280 + if (ret) { 281 + if (ret == -ENOMEM) 282 + return ret; 283 + dev_warn(dev, 284 + "Thermal zone misconfigured for %s. err=%d\n", 285 + sensor->name, ret); 286 + } 287 + } 288 + 289 + return 0; 334 290 } 335 291 336 292 static const struct scmi_device_id scmi_id_table[] = {