hwmon fixes for v6.1-rc4

Fix two regressions:
 
 - Commit 54cc3dbfc1 ("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.
 -----BEGIN PGP SIGNATURE-----
 
 iQIzBAABCAAdFiEEiHPvMQj9QTOCiqgVyx8mb86fmYEFAmNnv0YACgkQyx8mb86f
 mYEAPQ/7BfM6TjP3L85oGHPUxhP+AEkEoCfD1gplgRD4JPxYZZlwv8F+YGTV/PPQ
 mp12Bh8AH+NSryu6PhuhHKZxIvKcgxg+FEedfnT4gPYcMKtevPF84TBIbbFmLpuo
 culgJm4w3w2qwqP480kF0UTow1pRXqwjZYd3/GILzcaCIjWS2JS55w//YMQrE5J+
 +OkZsJSGWJITAJPYhIb0ETFcqjp8GROWfMZos2IdpErzmcuS31tcrD0igSwLXFwP
 bylDDXb9O9AiLT/qzkc0kjZvaohC2zoP5we+7JyXj0sUSODf+wBCEClvM1DI00JN
 CcS0zmgrmscktkTkonZDIz95vqO2Il5UmKXlK6dkpdDSS78JAX8g78LU1J7aFJ/9
 3iZnmYg4J8NXsO01plr4P3cGdPRqDoZMEYojSWq4WQs2VaKNIxsk5Zzcl6XN6OT1
 MT4w55d8QSQEghDu8vUvnmMg1X5Pkzc50RFYcWyeyMDrtue3rP4uD8m+wl9Sjgvs
 tWdayF9JmTQBaVvh3dUO3OR+z+66T8Qk1YBE1xqb+ocptYPNA1+wGum/O5wT+3ew
 lE8Jfn/8q7DAJ7lVNXKMyXMvPhZJZ5afhs+gpIJgPB2+m8p3plKgpGdW6Ew36AKe
 PKwmGx8kgfzQ6RYqXmCMG6wCr+xiLrYDPNOVz5ewC5LvYVtibs4=
 =u6Ip
 -----END PGP SIGNATURE-----

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 54cc3dbfc1 ("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
This commit is contained in:
Linus Torvalds 2022-11-06 12:59:12 -08:00
commit aa52994915
2 changed files with 103 additions and 14 deletions

View file

@ -467,7 +467,6 @@ extern const struct regulator_ops pmbus_regulator_ops;
#define PMBUS_REGULATOR_STEP(_name, _id, _voltages, _step) \
[_id] = { \
.name = (_name # _id), \
.supply_name = "vin", \
.id = (_id), \
.of_match = of_match_ptr(_name # _id), \
.regulators_node = of_match_ptr("regulators"), \

View file

@ -20,6 +20,11 @@ struct scmi_sensors {
const struct scmi_sensor_info **info[hwmon_max];
};
struct scmi_thermal_sensor {
const struct scmi_protocol_handle *ph;
const struct scmi_sensor_info *info;
};
static inline u64 __pow10(u8 x)
{
u64 r = 1;
@ -64,16 +69,14 @@ static int scmi_hwmon_scale(const struct scmi_sensor_info *sensor, u64 *value)
return 0;
}
static int scmi_hwmon_read(struct device *dev, enum hwmon_sensor_types type,
u32 attr, int channel, long *val)
static int scmi_hwmon_read_scaled_value(const struct scmi_protocol_handle *ph,
const struct scmi_sensor_info *sensor,
long *val)
{
int ret;
u64 value;
const struct scmi_sensor_info *sensor;
struct scmi_sensors *scmi_sensors = dev_get_drvdata(dev);
sensor = *(scmi_sensors->info[type] + channel);
ret = sensor_ops->reading_get(scmi_sensors->ph, sensor->id, &value);
ret = sensor_ops->reading_get(ph, sensor->id, &value);
if (ret)
return ret;
@ -84,6 +87,17 @@ static int scmi_hwmon_read(struct device *dev, enum hwmon_sensor_types type,
return ret;
}
static int scmi_hwmon_read(struct device *dev, enum hwmon_sensor_types type,
u32 attr, int channel, long *val)
{
const struct scmi_sensor_info *sensor;
struct scmi_sensors *scmi_sensors = dev_get_drvdata(dev);
sensor = *(scmi_sensors->info[type] + channel);
return scmi_hwmon_read_scaled_value(scmi_sensors->ph, sensor, val);
}
static int
scmi_hwmon_read_string(struct device *dev, enum hwmon_sensor_types type,
u32 attr, int channel, const char **str)
@ -122,6 +136,25 @@ static struct hwmon_chip_info scmi_chip_info = {
.info = NULL,
};
static int scmi_hwmon_thermal_get_temp(struct thermal_zone_device *tz,
int *temp)
{
int ret;
long value;
struct scmi_thermal_sensor *th_sensor = tz->devdata;
ret = scmi_hwmon_read_scaled_value(th_sensor->ph, th_sensor->info,
&value);
if (!ret)
*temp = value;
return ret;
}
static const struct thermal_zone_device_ops scmi_hwmon_thermal_ops = {
.get_temp = scmi_hwmon_thermal_get_temp,
};
static int scmi_hwmon_add_chan_info(struct hwmon_channel_info *scmi_hwmon_chan,
struct device *dev, int num,
enum hwmon_sensor_types type, u32 config)
@ -149,7 +182,6 @@ static enum hwmon_sensor_types scmi_types[] = {
};
static u32 hwmon_attributes[hwmon_max] = {
[hwmon_chip] = HWMON_C_REGISTER_TZ,
[hwmon_temp] = HWMON_T_INPUT | HWMON_T_LABEL,
[hwmon_in] = HWMON_I_INPUT | HWMON_I_LABEL,
[hwmon_curr] = HWMON_C_INPUT | HWMON_C_LABEL,
@ -157,6 +189,43 @@ static u32 hwmon_attributes[hwmon_max] = {
[hwmon_energy] = HWMON_E_INPUT | HWMON_E_LABEL,
};
static int scmi_thermal_sensor_register(struct device *dev,
const struct scmi_protocol_handle *ph,
const struct scmi_sensor_info *sensor)
{
struct scmi_thermal_sensor *th_sensor;
struct thermal_zone_device *tzd;
th_sensor = devm_kzalloc(dev, sizeof(*th_sensor), GFP_KERNEL);
if (!th_sensor)
return -ENOMEM;
th_sensor->ph = ph;
th_sensor->info = sensor;
/*
* Try to register a temperature sensor with the Thermal Framework:
* skip sensors not defined as part of any thermal zone (-ENODEV) but
* report any other errors related to misconfigured zones/sensors.
*/
tzd = devm_thermal_of_zone_register(dev, th_sensor->info->id, th_sensor,
&scmi_hwmon_thermal_ops);
if (IS_ERR(tzd)) {
devm_kfree(dev, th_sensor);
if (PTR_ERR(tzd) != -ENODEV)
return PTR_ERR(tzd);
dev_dbg(dev, "Sensor '%s' not attached to any thermal zone.\n",
sensor->name);
} else {
dev_dbg(dev, "Sensor '%s' attached to thermal zone ID:%d\n",
sensor->name, tzd->id);
}
return 0;
}
static int scmi_hwmon_probe(struct scmi_device *sdev)
{
int i, idx;
@ -164,7 +233,7 @@ static int scmi_hwmon_probe(struct scmi_device *sdev)
enum hwmon_sensor_types type;
struct scmi_sensors *scmi_sensors;
const struct scmi_sensor_info *sensor;
int nr_count[hwmon_max] = {0}, nr_types = 0;
int nr_count[hwmon_max] = {0}, nr_types = 0, nr_count_temp = 0;
const struct hwmon_chip_info *chip_info;
struct device *hwdev, *dev = &sdev->dev;
struct hwmon_channel_info *scmi_hwmon_chan;
@ -208,10 +277,8 @@ static int scmi_hwmon_probe(struct scmi_device *sdev)
}
}
if (nr_count[hwmon_temp]) {
nr_count[hwmon_chip]++;
nr_types++;
}
if (nr_count[hwmon_temp])
nr_count_temp = nr_count[hwmon_temp];
scmi_hwmon_chan = devm_kcalloc(dev, nr_types, sizeof(*scmi_hwmon_chan),
GFP_KERNEL);
@ -262,8 +329,31 @@ static int scmi_hwmon_probe(struct scmi_device *sdev)
hwdev = devm_hwmon_device_register_with_info(dev, "scmi_sensors",
scmi_sensors, chip_info,
NULL);
if (IS_ERR(hwdev))
return PTR_ERR(hwdev);
return PTR_ERR_OR_ZERO(hwdev);
for (i = 0; i < nr_count_temp; i++) {
int ret;
sensor = *(scmi_sensors->info[hwmon_temp] + i);
if (!sensor)
continue;
/*
* Warn on any misconfiguration related to thermal zones but
* bail out of probing only on memory errors.
*/
ret = scmi_thermal_sensor_register(dev, ph, sensor);
if (ret) {
if (ret == -ENOMEM)
return ret;
dev_warn(dev,
"Thermal zone misconfigured for %s. err=%d\n",
sensor->name, ret);
}
}
return 0;
}
static const struct scmi_device_id scmi_id_table[] = {