diff --git a/Documentation/devicetree/bindings/hwmon/apple,smc-hwmon.yaml b/Documentation/devicetree/bindings/hwmon/apple,smc-hwmon.yaml index b0b1dac1225ee..b01f2607731d0 100644 --- a/Documentation/devicetree/bindings/hwmon/apple,smc-hwmon.yaml +++ b/Documentation/devicetree/bindings/hwmon/apple,smc-hwmon.yaml @@ -90,7 +90,11 @@ properties: const: 1 description: The cell is the zero-based index of a temperature channel, counting - the temperature-* child nodes in order. + the temperature-* child nodes in order. With + apple,discover-temperatures, whose channel indices are not stable, the + only sensor is 1000, the hottest of the apple,soc-die-keys readings. + A thermal zone on it comes in addition to the macsmc_soc_die zone, + which is still registered for the users that look it up by name. "#cooling-cells": const: 3 diff --git a/drivers/hwmon/macsmc-hwmon.c b/drivers/hwmon/macsmc-hwmon.c index 50591b3d1d55b..69d12ceb859ff 100644 --- a/drivers/hwmon/macsmc-hwmon.c +++ b/drivers/hwmon/macsmc-hwmon.c @@ -1354,6 +1354,13 @@ static void macsmc_hwmon_populate_fan_configs(u32 *configs, const struct macsmc_ */ #if IS_ENABLED(CONFIG_THERMAL) #define MACSMC_SOC_DIE_ZONE "macsmc_soc_die" +/* + * The thermal sensor ID of the SoC die zone for a device tree thermal zone, on + * a node that discovers its temperatures and is a thermal sensor provider. It + * must stay above every temperature channel index the hwmon core registers; + * discovered channels are not bounded at build time, so probe checks it. + */ +#define MACSMC_SOC_DIE_SENSOR_ID 1000 #define MACSMC_DIE_MIN_MC -40000 #define MACSMC_DIE_MAX_MC 150000 @@ -1425,6 +1432,27 @@ static int macsmc_hwmon_die_register(struct macsmc_hwmon *hwmon) key >> 24, (key >> 16) & 0xff, (key >> 8) & 0xff, key & 0xff); } + /* + * A board with a device tree zone on the die sensor gets that zone, with its trips and + * cooling maps. Its lifetime is managed by the OF helper. The named tripless zone below + * is registered either way: the GPU drivers' governors look it up by its name. + */ + if (of_property_present(hwmon->dev->of_node, "#thermal-sensor-cells") && + hwmon->temp.count >= MACSMC_SOC_DIE_SENSOR_ID) { + dev_warn(hwmon->dev, "%u temperature channels reach the SoC die sensor ID %u\n", + hwmon->temp.count, MACSMC_SOC_DIE_SENSOR_ID); + } else if (of_property_present(hwmon->dev->of_node, "#thermal-sensor-cells")) { + tz = devm_thermal_of_zone_register(hwmon->dev, MACSMC_SOC_DIE_SENSOR_ID, hwmon, + &macsmc_hwmon_die_ops); + if (!IS_ERR(tz)) + dev_info(hwmon->dev, "SoC die zone %s (device tree): hottest of%s (%u of %u keys)\n", + thermal_zone_device_type(tz), keys, hwmon->die_count, + hwmon->die_listed); + else if (PTR_ERR(tz) != -ENODEV) + dev_warn(hwmon->dev, + "cannot register the device tree SoC die zone (%pe)\n", tz); + } + tz = thermal_tripless_zone_device_register(MACSMC_SOC_DIE_ZONE, hwmon, &macsmc_hwmon_die_ops, NULL); if (IS_ERR(tz)) {