Currently, cooling devices have no parent device, potentially causing issues with suspend ordering and making it impossible for consumers (thermal zones and userspace appications) to associate a given cooling device with its parent device. Extend __thermal_cooling_device_register() to also accept a parent device pointer. For now only devm_thermal_of_cooling_device_register() uses this, as the other wrapper functions need to be extended first. Signed-off-by: Armin Wolf --- drivers/thermal/thermal_core.c | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/drivers/thermal/thermal_core.c b/drivers/thermal/thermal_core.c index 17ca5c082643..c8b720194b44 100644 --- a/drivers/thermal/thermal_core.c +++ b/drivers/thermal/thermal_core.c @@ -1040,6 +1040,7 @@ static void thermal_cooling_device_init_complete(struct thermal_cooling_device * /** * __thermal_cooling_device_register() - register a new thermal cooling device + * @parent: parent device pointer. * @np: a pointer to a device tree node. * @type: the thermal cooling device type. * @devdata: device private data. @@ -1055,7 +1056,7 @@ static void thermal_cooling_device_init_complete(struct thermal_cooling_device * * ERR_PTR. Caller must check return value with IS_ERR*() helpers. */ static struct thermal_cooling_device * -__thermal_cooling_device_register(struct device_node *np, +__thermal_cooling_device_register(struct device *parent, struct device_node *np, const char *type, void *devdata, const struct thermal_cooling_device_ops *ops) { @@ -1092,6 +1093,7 @@ __thermal_cooling_device_register(struct device_node *np, cdev->ops = ops; cdev->updated = false; cdev->device.class = thermal_class; + cdev->device.parent = parent; cdev->devdata = devdata; ret = cdev->ops->get_max_state(cdev, &cdev->max_state); @@ -1158,7 +1160,7 @@ struct thermal_cooling_device * thermal_cooling_device_register(const char *type, void *devdata, const struct thermal_cooling_device_ops *ops) { - return __thermal_cooling_device_register(NULL, type, devdata, ops); + return __thermal_cooling_device_register(NULL, NULL, type, devdata, ops); } EXPORT_SYMBOL_GPL(thermal_cooling_device_register); @@ -1182,7 +1184,7 @@ thermal_of_cooling_device_register(struct device_node *np, const char *type, void *devdata, const struct thermal_cooling_device_ops *ops) { - return __thermal_cooling_device_register(np, type, devdata, ops); + return __thermal_cooling_device_register(NULL, np, type, devdata, ops); } EXPORT_SYMBOL_GPL(thermal_of_cooling_device_register); @@ -1222,7 +1224,7 @@ devm_thermal_of_cooling_device_register(struct device *dev, if (!ptr) return ERR_PTR(-ENOMEM); - tcd = __thermal_cooling_device_register(np, type, devdata, ops); + tcd = __thermal_cooling_device_register(dev, np, type, devdata, ops); if (IS_ERR(tcd)) { devres_free(ptr); return tcd; -- 2.39.5 Extend thermal_of_cooling_device_register() to allow users to specify the parent device of the cooling device to be created. Signed-off-by: Armin Wolf --- drivers/gpu/drm/etnaviv/etnaviv_gpu.c | 4 ++-- drivers/thermal/cpufreq_cooling.c | 2 +- drivers/thermal/cpuidle_cooling.c | 2 +- drivers/thermal/devfreq_cooling.c | 2 +- drivers/thermal/tegra/soctherm.c | 5 ++--- drivers/thermal/thermal_core.c | 5 +++-- include/linux/thermal.h | 9 ++++----- 7 files changed, 14 insertions(+), 15 deletions(-) diff --git a/drivers/gpu/drm/etnaviv/etnaviv_gpu.c b/drivers/gpu/drm/etnaviv/etnaviv_gpu.c index cf0d9049bcf1..f2c98e46a1c6 100644 --- a/drivers/gpu/drm/etnaviv/etnaviv_gpu.c +++ b/drivers/gpu/drm/etnaviv/etnaviv_gpu.c @@ -1778,8 +1778,8 @@ static int etnaviv_gpu_bind(struct device *dev, struct device *master, int ret; if (IS_ENABLED(CONFIG_DRM_ETNAVIV_THERMAL)) { - gpu->cooling = thermal_of_cooling_device_register(dev->of_node, - (char *)dev_name(dev), gpu, &cooling_ops); + gpu->cooling = thermal_of_cooling_device_register(dev, dev->of_node, dev_name(dev), + gpu, &cooling_ops); if (IS_ERR(gpu->cooling)) return PTR_ERR(gpu->cooling); } diff --git a/drivers/thermal/cpufreq_cooling.c b/drivers/thermal/cpufreq_cooling.c index 6b7ab1814c12..af9250c44da7 100644 --- a/drivers/thermal/cpufreq_cooling.c +++ b/drivers/thermal/cpufreq_cooling.c @@ -593,7 +593,7 @@ __cpufreq_cooling_register(struct device_node *np, if (!name) goto remove_qos_req; - cdev = thermal_of_cooling_device_register(np, name, cpufreq_cdev, + cdev = thermal_of_cooling_device_register(dev, np, name, cpufreq_cdev, cooling_ops); kfree(name); diff --git a/drivers/thermal/cpuidle_cooling.c b/drivers/thermal/cpuidle_cooling.c index f678c1281862..520c89a36d90 100644 --- a/drivers/thermal/cpuidle_cooling.c +++ b/drivers/thermal/cpuidle_cooling.c @@ -207,7 +207,7 @@ static int __cpuidle_cooling_register(struct device_node *np, goto out_unregister; } - cdev = thermal_of_cooling_device_register(np, name, idle_cdev, + cdev = thermal_of_cooling_device_register(dev, np, name, idle_cdev, &cpuidle_cooling_ops); if (IS_ERR(cdev)) { ret = PTR_ERR(cdev); diff --git a/drivers/thermal/devfreq_cooling.c b/drivers/thermal/devfreq_cooling.c index 8fd7cf1932cd..d91695ed0f26 100644 --- a/drivers/thermal/devfreq_cooling.c +++ b/drivers/thermal/devfreq_cooling.c @@ -454,7 +454,7 @@ of_devfreq_cooling_register_power(struct device_node *np, struct devfreq *df, if (!name) goto remove_qos_req; - cdev = thermal_of_cooling_device_register(np, name, dfc, ops); + cdev = thermal_of_cooling_device_register(dev, np, name, dfc, ops); kfree(name); if (IS_ERR(cdev)) { diff --git a/drivers/thermal/tegra/soctherm.c b/drivers/thermal/tegra/soctherm.c index 5d26b52beaba..4f43da123be4 100644 --- a/drivers/thermal/tegra/soctherm.c +++ b/drivers/thermal/tegra/soctherm.c @@ -1700,9 +1700,8 @@ static void soctherm_init_hw_throt_cdev(struct platform_device *pdev) stc->init = true; } else { - tcd = thermal_of_cooling_device_register(np_stcc, - (char *)name, ts, - &throt_cooling_ops); + tcd = thermal_of_cooling_device_register(dev, np_stcc, name, ts, + &throt_cooling_ops); if (IS_ERR_OR_NULL(tcd)) { dev_err(dev, "throttle-cfg: %s: failed to register cooling device\n", diff --git a/drivers/thermal/thermal_core.c b/drivers/thermal/thermal_core.c index c8b720194b44..5d752e712cc0 100644 --- a/drivers/thermal/thermal_core.c +++ b/drivers/thermal/thermal_core.c @@ -1166,6 +1166,7 @@ EXPORT_SYMBOL_GPL(thermal_cooling_device_register); /** * thermal_of_cooling_device_register() - register an OF thermal cooling device + * @parent: parent device pointer. * @np: a pointer to a device tree node. * @type: the thermal cooling device type. * @devdata: device private data. @@ -1180,11 +1181,11 @@ EXPORT_SYMBOL_GPL(thermal_cooling_device_register); * ERR_PTR. Caller must check return value with IS_ERR*() helpers. */ struct thermal_cooling_device * -thermal_of_cooling_device_register(struct device_node *np, +thermal_of_cooling_device_register(struct device *parent, struct device_node *np, const char *type, void *devdata, const struct thermal_cooling_device_ops *ops) { - return __thermal_cooling_device_register(NULL, np, type, devdata, ops); + return __thermal_cooling_device_register(parent, np, type, devdata, ops); } EXPORT_SYMBOL_GPL(thermal_of_cooling_device_register); diff --git a/include/linux/thermal.h b/include/linux/thermal.h index 0b5ed6821080..fa53d12173ce 100644 --- a/include/linux/thermal.h +++ b/include/linux/thermal.h @@ -253,8 +253,8 @@ void thermal_zone_device_update(struct thermal_zone_device *, struct thermal_cooling_device *thermal_cooling_device_register(const char *, void *, const struct thermal_cooling_device_ops *); struct thermal_cooling_device * -thermal_of_cooling_device_register(struct device_node *np, const char *, void *, - const struct thermal_cooling_device_ops *); +thermal_of_cooling_device_register(struct device *parent, struct device_node *np, const char *type, + void *devdata, const struct thermal_cooling_device_ops *); struct thermal_cooling_device * devm_thermal_of_cooling_device_register(struct device *dev, struct device_node *np, @@ -302,9 +302,8 @@ thermal_cooling_device_register(const char *type, void *devdata, const struct thermal_cooling_device_ops *ops) { return ERR_PTR(-ENODEV); } static inline struct thermal_cooling_device * -thermal_of_cooling_device_register(struct device_node *np, - const char *type, void *devdata, - const struct thermal_cooling_device_ops *ops) +thermal_of_cooling_device_register(struct device *parent, struct device_node *np, const char *type, + void *devdata, const struct thermal_cooling_device_ops *ops) { return ERR_PTR(-ENODEV); } static inline struct thermal_cooling_device * devm_thermal_of_cooling_device_register(struct device *dev, -- 2.39.5 The thermal core will soon automatically create sysfs links between the cooling device and its parent device. Stop manually creating the "device" sysfs link between the cooling device and the parent device to avoid a name collision. The "thermal_cooling" sysfs link however stays for backwards compatibility, as it does not suffer from a name collision. Signed-off-by: Armin Wolf --- drivers/acpi/processor_thermal.c | 13 +------------ 1 file changed, 1 insertion(+), 12 deletions(-) diff --git a/drivers/acpi/processor_thermal.c b/drivers/acpi/processor_thermal.c index c7b1dc5687ec..1ff10321eac5 100644 --- a/drivers/acpi/processor_thermal.c +++ b/drivers/acpi/processor_thermal.c @@ -323,6 +323,7 @@ int acpi_processor_thermal_init(struct acpi_processor *pr, dev_dbg(&device->dev, "registered as cooling_device%d\n", pr->cdev->id); + /* For backwards compatibility */ result = sysfs_create_link(&device->dev.kobj, &pr->cdev->device.kobj, "thermal_cooling"); @@ -332,19 +333,8 @@ int acpi_processor_thermal_init(struct acpi_processor *pr, goto err_thermal_unregister; } - result = sysfs_create_link(&pr->cdev->device.kobj, - &device->dev.kobj, - "device"); - if (result) { - dev_err(&pr->cdev->device, - "Failed to create sysfs link 'device'\n"); - goto err_remove_sysfs_thermal; - } - return 0; -err_remove_sysfs_thermal: - sysfs_remove_link(&device->dev.kobj, "thermal_cooling"); err_thermal_unregister: thermal_cooling_device_unregister(pr->cdev); @@ -356,7 +346,6 @@ void acpi_processor_thermal_exit(struct acpi_processor *pr, { if (pr->cdev) { sysfs_remove_link(&device->dev.kobj, "thermal_cooling"); - sysfs_remove_link(&pr->cdev->device.kobj, "device"); thermal_cooling_device_unregister(pr->cdev); pr->cdev = NULL; } -- 2.39.5 The thermal core will soon automatically create sysfs links between the cooling device and its parent device. Stop manually creating the "device" sysfs link between the cooling device and the parent device to avoid a name collision. The "thermal_cooling" sysfs link however stays for backwards compatibility, as it does not suffer from a name collision. Signed-off-by: Armin Wolf --- drivers/acpi/fan_core.c | 12 +----------- 1 file changed, 1 insertion(+), 11 deletions(-) diff --git a/drivers/acpi/fan_core.c b/drivers/acpi/fan_core.c index fb08b8549ed7..2ca3e347f15c 100644 --- a/drivers/acpi/fan_core.c +++ b/drivers/acpi/fan_core.c @@ -594,6 +594,7 @@ static int acpi_fan_probe(struct platform_device *pdev) dev_dbg(&pdev->dev, "registered as cooling_device%d\n", cdev->id); fan->cdev = cdev; + /* For backwards compatibility */ result = sysfs_create_link(&pdev->dev.kobj, &cdev->device.kobj, "thermal_cooling"); @@ -602,18 +603,8 @@ static int acpi_fan_probe(struct platform_device *pdev) goto err_unregister; } - result = sysfs_create_link(&cdev->device.kobj, - &pdev->dev.kobj, - "device"); - if (result) { - dev_err(&pdev->dev, "Failed to create sysfs link 'device'\n"); - goto err_remove_link; - } - return 0; -err_remove_link: - sysfs_remove_link(&pdev->dev.kobj, "thermal_cooling"); err_unregister: thermal_cooling_device_unregister(cdev); err_end: @@ -633,7 +624,6 @@ static void acpi_fan_remove(struct platform_device *pdev) acpi_fan_delete_attributes(device); } sysfs_remove_link(&pdev->dev.kobj, "thermal_cooling"); - sysfs_remove_link(&fan->cdev->device.kobj, "device"); thermal_cooling_device_unregister(fan->cdev); } -- 2.39.5 The thermal core will soon automatically create sysfs links between the cooling device and its parent device. Stop manually creating the "device" sysfs link between the cooling device and the parent device to avoid a name collision. The "thermal_cooling" sysfs link however stays for backwards compatibility, as it does not suffer from a name collision. Signed-off-by: Armin Wolf --- drivers/acpi/acpi_video.c | 7 +------ 1 file changed, 1 insertion(+), 6 deletions(-) diff --git a/drivers/acpi/acpi_video.c b/drivers/acpi/acpi_video.c index be8e7e18abca..658e11745523 100644 --- a/drivers/acpi/acpi_video.c +++ b/drivers/acpi/acpi_video.c @@ -1774,16 +1774,12 @@ static void acpi_video_dev_register_backlight(struct acpi_video_device *device) dev_info(&device->dev->dev, "registered as cooling_device%d\n", device->cooling_dev->id); + /* For backwards compatibility */ result = sysfs_create_link(&device->dev->dev.kobj, &device->cooling_dev->device.kobj, "thermal_cooling"); if (result) pr_info("sysfs link creation failed\n"); - - result = sysfs_create_link(&device->cooling_dev->device.kobj, - &device->dev->dev.kobj, "device"); - if (result) - pr_info("Reverse sysfs link creation failed\n"); } static void acpi_video_run_bcl_for_osi(struct acpi_video_bus *video) @@ -1852,7 +1848,6 @@ static void acpi_video_dev_unregister_backlight(struct acpi_video_device *device } if (device->cooling_dev) { sysfs_remove_link(&device->dev->dev.kobj, "thermal_cooling"); - sysfs_remove_link(&device->cooling_dev->device.kobj, "device"); thermal_cooling_device_unregister(device->cooling_dev); device->cooling_dev = NULL; } -- 2.39.5 Extend thermal_cooling_device_register() to allow users to specify the parent device of the cooling device to be created. Signed-off-by: Armin Wolf --- Documentation/driver-api/thermal/sysfs-api.rst | 5 ++++- drivers/acpi/acpi_video.c | 2 +- drivers/acpi/fan_core.c | 4 ++-- drivers/acpi/processor_thermal.c | 2 +- drivers/net/ethernet/mellanox/mlxsw/core_thermal.c | 2 +- drivers/net/wireless/ath/ath10k/thermal.c | 2 +- drivers/net/wireless/ath/ath11k/thermal.c | 2 +- drivers/net/wireless/intel/iwlwifi/mld/thermal.c | 4 +--- drivers/net/wireless/intel/iwlwifi/mvm/tt.c | 2 +- drivers/net/wireless/mediatek/mt76/mt7915/init.c | 2 +- drivers/net/wireless/mediatek/mt76/mt7996/init.c | 2 +- drivers/platform/x86/acerhdf.c | 2 +- drivers/thermal/intel/int340x_thermal/int3403_thermal.c | 4 ++-- drivers/thermal/intel/int340x_thermal/int3406_thermal.c | 2 +- drivers/thermal/intel/intel_powerclamp.c | 2 +- drivers/thermal/intel/intel_tcc_cooling.c | 2 +- drivers/thermal/pcie_cooling.c | 2 +- drivers/thermal/thermal_core.c | 5 +++-- include/linux/thermal.h | 9 +++++---- 19 files changed, 30 insertions(+), 27 deletions(-) diff --git a/Documentation/driver-api/thermal/sysfs-api.rst b/Documentation/driver-api/thermal/sysfs-api.rst index f73de211bdce..cf242cd16f2e 100644 --- a/Documentation/driver-api/thermal/sysfs-api.rst +++ b/Documentation/driver-api/thermal/sysfs-api.rst @@ -215,13 +215,16 @@ temperature) and throttle appropriate devices. :: struct thermal_cooling_device - *thermal_cooling_device_register(char *name, + *thermal_cooling_device_register(struct device *parent, char *name, void *devdata, struct thermal_cooling_device_ops *) This interface function adds a new thermal cooling device (fan/processor/...) to /sys/class/thermal/ folder as `cooling_device[0-*]`. It tries to bind itself to all the thermal zone devices registered at the same time. + parent: + parent device pointer. + name: the cooling device name. devdata: diff --git a/drivers/acpi/acpi_video.c b/drivers/acpi/acpi_video.c index 658e11745523..eae1ff9805b1 100644 --- a/drivers/acpi/acpi_video.c +++ b/drivers/acpi/acpi_video.c @@ -1759,7 +1759,7 @@ static void acpi_video_dev_register_backlight(struct acpi_video_device *device) device->backlight->props.brightness = acpi_video_get_brightness(device->backlight); - device->cooling_dev = thermal_cooling_device_register("LCD", device, + device->cooling_dev = thermal_cooling_device_register(parent, "LCD", device, &video_cooling_ops); if (IS_ERR(device->cooling_dev)) { /* diff --git a/drivers/acpi/fan_core.c b/drivers/acpi/fan_core.c index 2ca3e347f15c..7ebf2529fbfd 100644 --- a/drivers/acpi/fan_core.c +++ b/drivers/acpi/fan_core.c @@ -584,8 +584,8 @@ static int acpi_fan_probe(struct platform_device *pdev) else name = acpi_device_bid(device); - cdev = thermal_cooling_device_register(name, device, - &fan_cooling_ops); + cdev = thermal_cooling_device_register(&pdev->dev, name, device, + &fan_cooling_ops); if (IS_ERR(cdev)) { result = PTR_ERR(cdev); goto err_end; diff --git a/drivers/acpi/processor_thermal.c b/drivers/acpi/processor_thermal.c index 1ff10321eac5..a7307f5d137f 100644 --- a/drivers/acpi/processor_thermal.c +++ b/drivers/acpi/processor_thermal.c @@ -313,7 +313,7 @@ int acpi_processor_thermal_init(struct acpi_processor *pr, { int result = 0; - pr->cdev = thermal_cooling_device_register("Processor", device, + pr->cdev = thermal_cooling_device_register(&device->dev, "Processor", device, &processor_cooling_ops); if (IS_ERR(pr->cdev)) { result = PTR_ERR(pr->cdev); diff --git a/drivers/net/ethernet/mellanox/mlxsw/core_thermal.c b/drivers/net/ethernet/mellanox/mlxsw/core_thermal.c index eac9a14a6058..1117d59b74fd 100644 --- a/drivers/net/ethernet/mellanox/mlxsw/core_thermal.c +++ b/drivers/net/ethernet/mellanox/mlxsw/core_thermal.c @@ -693,7 +693,7 @@ int mlxsw_thermal_init(struct mlxsw_core *core, mlxsw_cdev = &thermal->cdevs[i]; mlxsw_cdev->thermal = thermal; mlxsw_cdev->idx = i; - cdev = thermal_cooling_device_register("mlxsw_fan", + cdev = thermal_cooling_device_register(dev, "mlxsw_fan", mlxsw_cdev, &mlxsw_cooling_ops); if (IS_ERR(cdev)) { diff --git a/drivers/net/wireless/ath/ath10k/thermal.c b/drivers/net/wireless/ath/ath10k/thermal.c index 8b15ec07b107..16eb41b928ba 100644 --- a/drivers/net/wireless/ath/ath10k/thermal.c +++ b/drivers/net/wireless/ath/ath10k/thermal.c @@ -161,7 +161,7 @@ int ath10k_thermal_register(struct ath10k *ar) if (!test_bit(WMI_SERVICE_THERM_THROT, ar->wmi.svc_map)) return 0; - cdev = thermal_cooling_device_register("ath10k_thermal", ar, + cdev = thermal_cooling_device_register(ar->dev, "ath10k_thermal", ar, &ath10k_thermal_ops); if (IS_ERR(cdev)) { diff --git a/drivers/net/wireless/ath/ath11k/thermal.c b/drivers/net/wireless/ath/ath11k/thermal.c index 18d6eab5cce3..363697ce8641 100644 --- a/drivers/net/wireless/ath/ath11k/thermal.c +++ b/drivers/net/wireless/ath/ath11k/thermal.c @@ -172,7 +172,7 @@ int ath11k_thermal_register(struct ath11k_base *ab) if (!ar) continue; - cdev = thermal_cooling_device_register("ath11k_thermal", ar, + cdev = thermal_cooling_device_register(&ar->hw->wiphy->dev, "ath11k_thermal", ar, &ath11k_thermal_ops); if (IS_ERR(cdev)) { diff --git a/drivers/net/wireless/intel/iwlwifi/mld/thermal.c b/drivers/net/wireless/intel/iwlwifi/mld/thermal.c index f8a8c35066be..9e56e6e80ab7 100644 --- a/drivers/net/wireless/intel/iwlwifi/mld/thermal.c +++ b/drivers/net/wireless/intel/iwlwifi/mld/thermal.c @@ -366,9 +366,7 @@ static void iwl_mld_cooling_device_register(struct iwl_mld *mld) BUILD_BUG_ON(ARRAY_SIZE(name) >= THERMAL_NAME_LENGTH); mld->cooling_dev.cdev = - thermal_cooling_device_register(name, - mld, - &tcooling_ops); + thermal_cooling_device_register(mld->dev, name, mld, &tcooling_ops); if (IS_ERR(mld->cooling_dev.cdev)) { IWL_DEBUG_TEMP(mld, diff --git a/drivers/net/wireless/intel/iwlwifi/mvm/tt.c b/drivers/net/wireless/intel/iwlwifi/mvm/tt.c index 53bab21ebae2..b184f08230b9 100644 --- a/drivers/net/wireless/intel/iwlwifi/mvm/tt.c +++ b/drivers/net/wireless/intel/iwlwifi/mvm/tt.c @@ -744,7 +744,7 @@ static void iwl_mvm_cooling_device_register(struct iwl_mvm *mvm) BUILD_BUG_ON(ARRAY_SIZE(name) >= THERMAL_NAME_LENGTH); mvm->cooling_dev.cdev = - thermal_cooling_device_register(name, + thermal_cooling_device_register(mvm->dev, name, mvm, &tcooling_ops); diff --git a/drivers/net/wireless/mediatek/mt76/mt7915/init.c b/drivers/net/wireless/mediatek/mt76/mt7915/init.c index 5ea8b46e092e..cb08bb36f6e2 100644 --- a/drivers/net/wireless/mediatek/mt76/mt7915/init.c +++ b/drivers/net/wireless/mediatek/mt76/mt7915/init.c @@ -200,7 +200,7 @@ static int mt7915_thermal_init(struct mt7915_phy *phy) if (!name) return -ENOMEM; - cdev = thermal_cooling_device_register(name, phy, &mt7915_thermal_ops); + cdev = thermal_cooling_device_register(&wiphy->dev, name, phy, &mt7915_thermal_ops); if (!IS_ERR(cdev)) { if (sysfs_create_link(&wiphy->dev.kobj, &cdev->device.kobj, "cooling_device") < 0) diff --git a/drivers/net/wireless/mediatek/mt76/mt7996/init.c b/drivers/net/wireless/mediatek/mt76/mt7996/init.c index 5e95a36b42d1..bb6e55d79d0e 100644 --- a/drivers/net/wireless/mediatek/mt76/mt7996/init.c +++ b/drivers/net/wireless/mediatek/mt76/mt7996/init.c @@ -249,7 +249,7 @@ static int mt7996_thermal_init(struct mt7996_phy *phy) snprintf(cname, sizeof(cname), "cooling_device%d", phy->mt76->band_idx); - cdev = thermal_cooling_device_register(name, phy, &mt7996_thermal_ops); + cdev = thermal_cooling_device_register(&wiphy->dev, name, phy, &mt7996_thermal_ops); if (!IS_ERR(cdev)) { if (sysfs_create_link(&wiphy->dev.kobj, &cdev->device.kobj, cname) < 0) diff --git a/drivers/platform/x86/acerhdf.c b/drivers/platform/x86/acerhdf.c index 5ce5ad3efe69..c74937d475e5 100644 --- a/drivers/platform/x86/acerhdf.c +++ b/drivers/platform/x86/acerhdf.c @@ -650,7 +650,7 @@ static int __init acerhdf_register_thermal(void) { int ret; - cl_dev = thermal_cooling_device_register("acerhdf-fan", NULL, + cl_dev = thermal_cooling_device_register(NULL, "acerhdf-fan", NULL, &acerhdf_cooling_ops); if (IS_ERR(cl_dev)) diff --git a/drivers/thermal/intel/int340x_thermal/int3403_thermal.c b/drivers/thermal/intel/int340x_thermal/int3403_thermal.c index 264c9bc8e645..08d9e91f01cb 100644 --- a/drivers/thermal/intel/int340x_thermal/int3403_thermal.c +++ b/drivers/thermal/intel/int340x_thermal/int3403_thermal.c @@ -178,8 +178,8 @@ static int int3403_cdev_add(struct int3403_priv *priv) priv->priv = obj; obj->max_state = p->package.count - 1; obj->cdev = - thermal_cooling_device_register(acpi_device_bid(priv->adev), - priv, &int3403_cooling_ops); + thermal_cooling_device_register(&priv->adev->dev, acpi_device_bid(priv->adev), + priv, &int3403_cooling_ops); if (IS_ERR(obj->cdev)) result = PTR_ERR(obj->cdev); diff --git a/drivers/thermal/intel/int340x_thermal/int3406_thermal.c b/drivers/thermal/intel/int340x_thermal/int3406_thermal.c index e21fcbccf4ba..e458add39a88 100644 --- a/drivers/thermal/intel/int340x_thermal/int3406_thermal.c +++ b/drivers/thermal/intel/int340x_thermal/int3406_thermal.c @@ -157,7 +157,7 @@ static int int3406_thermal_probe(struct platform_device *pdev) int3406_thermal_get_limit(d); - d->cooling_dev = thermal_cooling_device_register(acpi_device_bid(adev), + d->cooling_dev = thermal_cooling_device_register(&pdev->dev, acpi_device_bid(adev), d, &video_cooling_ops); if (IS_ERR(d->cooling_dev)) goto err; diff --git a/drivers/thermal/intel/intel_powerclamp.c b/drivers/thermal/intel/intel_powerclamp.c index 9a4cec000910..a8f798bf459f 100644 --- a/drivers/thermal/intel/intel_powerclamp.c +++ b/drivers/thermal/intel/intel_powerclamp.c @@ -779,7 +779,7 @@ static int __init powerclamp_init(void) /* set default limit, maybe adjusted during runtime based on feedback */ window_size = 2; - cooling_dev = thermal_cooling_device_register("intel_powerclamp", NULL, + cooling_dev = thermal_cooling_device_register(NULL, "intel_powerclamp", NULL, &powerclamp_cooling_ops); if (IS_ERR(cooling_dev)) return -ENODEV; diff --git a/drivers/thermal/intel/intel_tcc_cooling.c b/drivers/thermal/intel/intel_tcc_cooling.c index f352ecafbedf..a0ead0fb1fbe 100644 --- a/drivers/thermal/intel/intel_tcc_cooling.c +++ b/drivers/thermal/intel/intel_tcc_cooling.c @@ -101,7 +101,7 @@ static int __init tcc_cooling_init(void) pr_info("Programmable TCC Offset detected\n"); tcc_cdev = - thermal_cooling_device_register("TCC Offset", NULL, + thermal_cooling_device_register(NULL, "TCC Offset", NULL, &tcc_cooling_ops); if (IS_ERR(tcc_cdev)) { ret = PTR_ERR(tcc_cdev); diff --git a/drivers/thermal/pcie_cooling.c b/drivers/thermal/pcie_cooling.c index a876d64f1582..4d37f7f9d108 100644 --- a/drivers/thermal/pcie_cooling.c +++ b/drivers/thermal/pcie_cooling.c @@ -61,7 +61,7 @@ struct thermal_cooling_device *pcie_cooling_device_register(struct pci_dev *port if (!name) return ERR_PTR(-ENOMEM); - return thermal_cooling_device_register(name, port, &pcie_cooling_ops); + return thermal_cooling_device_register(&port->dev, name, port, &pcie_cooling_ops); } void pcie_cooling_device_unregister(struct thermal_cooling_device *cdev) diff --git a/drivers/thermal/thermal_core.c b/drivers/thermal/thermal_core.c index 5d752e712cc0..92e51d2e4535 100644 --- a/drivers/thermal/thermal_core.c +++ b/drivers/thermal/thermal_core.c @@ -1145,6 +1145,7 @@ __thermal_cooling_device_register(struct device *parent, struct device_node *np, /** * thermal_cooling_device_register() - register a new thermal cooling device + * @parent: parent device pointer. * @type: the thermal cooling device type. * @devdata: device private data. * @ops: standard thermal cooling devices callbacks. @@ -1157,10 +1158,10 @@ __thermal_cooling_device_register(struct device *parent, struct device_node *np, * ERR_PTR. Caller must check return value with IS_ERR*() helpers. */ struct thermal_cooling_device * -thermal_cooling_device_register(const char *type, void *devdata, +thermal_cooling_device_register(struct device *parent, const char *type, void *devdata, const struct thermal_cooling_device_ops *ops) { - return __thermal_cooling_device_register(NULL, NULL, type, devdata, ops); + return __thermal_cooling_device_register(parent, NULL, type, devdata, ops); } EXPORT_SYMBOL_GPL(thermal_cooling_device_register); diff --git a/include/linux/thermal.h b/include/linux/thermal.h index fa53d12173ce..29a608bf5f80 100644 --- a/include/linux/thermal.h +++ b/include/linux/thermal.h @@ -250,8 +250,9 @@ struct device *thermal_zone_device(struct thermal_zone_device *tzd); void thermal_zone_device_update(struct thermal_zone_device *, enum thermal_notify_event); -struct thermal_cooling_device *thermal_cooling_device_register(const char *, - void *, const struct thermal_cooling_device_ops *); +struct thermal_cooling_device * +thermal_cooling_device_register(struct device *parent, const char *type, void *drvdata, + const struct thermal_cooling_device_ops *ops); struct thermal_cooling_device * thermal_of_cooling_device_register(struct device *parent, struct device_node *np, const char *type, void *devdata, const struct thermal_cooling_device_ops *); @@ -298,8 +299,8 @@ static inline void thermal_zone_device_update(struct thermal_zone_device *tz, { } static inline struct thermal_cooling_device * -thermal_cooling_device_register(const char *type, void *devdata, - const struct thermal_cooling_device_ops *ops) +thermal_cooling_device_register(struct device *parent, const char *type, void *devdata, + const struct thermal_cooling_device_ops *ops) { return ERR_PTR(-ENODEV); } static inline struct thermal_cooling_device * thermal_of_cooling_device_register(struct device *parent, struct device_node *np, const char *type, -- 2.39.5 The thermal core will soon automatically create sysfs links between the thermal zone device and its parent device. Stop manually creating the "device" sysfs link between the thermal zone device and the parent device to avoid a name collision. The "thermal_zone" sysfs link however stays for backwards compatibility, as it does not suffer from a name collision. Signed-off-by: Armin Wolf --- drivers/acpi/thermal.c | 17 ++--------------- 1 file changed, 2 insertions(+), 15 deletions(-) diff --git a/drivers/acpi/thermal.c b/drivers/acpi/thermal.c index a511f9ea0267..99ad67bbd764 100644 --- a/drivers/acpi/thermal.c +++ b/drivers/acpi/thermal.c @@ -592,27 +592,14 @@ static const struct thermal_zone_device_ops acpi_thermal_zone_ops = { static int acpi_thermal_zone_sysfs_add(struct acpi_thermal *tz) { struct device *tzdev = thermal_zone_device(tz->thermal_zone); - int ret; - ret = sysfs_create_link(&tz->device->dev.kobj, - &tzdev->kobj, "thermal_zone"); - if (ret) - return ret; - - ret = sysfs_create_link(&tzdev->kobj, - &tz->device->dev.kobj, "device"); - if (ret) - sysfs_remove_link(&tz->device->dev.kobj, "thermal_zone"); - - return ret; + /* For backwards compatibility */ + return sysfs_create_link(&tz->device->dev.kobj, &tzdev->kobj, "thermal_zone"); } static void acpi_thermal_zone_sysfs_remove(struct acpi_thermal *tz) { - struct device *tzdev = thermal_zone_device(tz->thermal_zone); - sysfs_remove_link(&tz->device->dev.kobj, "thermal_zone"); - sysfs_remove_link(&tzdev->kobj, "device"); } static int acpi_thermal_register_thermal_zone(struct acpi_thermal *tz, -- 2.39.5 Thermal zone devices currently have no parent device, potentially causing issues with suspend ordering and making it impossible for user space appications to associate a given thermal zone device with its parent device. Extend the functions used to register thermal zone devices to also accept a parent device pointer. Also update all users of those functions to provide a parent device pointer if available. Signed-off-by: Armin Wolf --- Documentation/driver-api/thermal/sysfs-api.rst | 5 ++- drivers/acpi/thermal.c | 16 +++++--- drivers/net/ethernet/chelsio/cxgb4/cxgb4_thermal.c | 4 +- drivers/net/ethernet/mellanox/mlxsw/core_thermal.c | 45 +++++++++++----------- drivers/net/wireless/intel/iwlwifi/mld/thermal.c | 2 +- drivers/net/wireless/intel/iwlwifi/mvm/tt.c | 10 ++--- drivers/platform/x86/acerhdf.c | 2 +- drivers/power/supply/power_supply_core.c | 4 +- drivers/thermal/armada_thermal.c | 2 +- drivers/thermal/da9062-thermal.c | 2 +- drivers/thermal/dove_thermal.c | 2 +- drivers/thermal/imx_thermal.c | 2 +- .../intel/int340x_thermal/int3400_thermal.c | 2 +- .../intel/int340x_thermal/int340x_thermal_zone.c | 13 +++---- .../int340x_thermal/processor_thermal_device_pci.c | 7 ++-- drivers/thermal/intel/intel_pch_thermal.c | 2 +- drivers/thermal/intel/intel_quark_dts_thermal.c | 2 +- drivers/thermal/intel/intel_soc_dts_iosf.c | 2 +- drivers/thermal/intel/x86_pkg_temp_thermal.c | 6 +-- drivers/thermal/kirkwood_thermal.c | 2 +- drivers/thermal/renesas/rcar_thermal.c | 10 +++-- drivers/thermal/spear_thermal.c | 2 +- drivers/thermal/testing/zone.c | 2 +- drivers/thermal/thermal_core.c | 7 +++- drivers/thermal/thermal_of.c | 9 +++-- include/linux/thermal.h | 4 ++ 26 files changed, 92 insertions(+), 74 deletions(-) diff --git a/Documentation/driver-api/thermal/sysfs-api.rst b/Documentation/driver-api/thermal/sysfs-api.rst index cf242cd16f2e..0a29bc949ef3 100644 --- a/Documentation/driver-api/thermal/sysfs-api.rst +++ b/Documentation/driver-api/thermal/sysfs-api.rst @@ -37,7 +37,8 @@ temperature) and throttle appropriate devices. :: struct thermal_zone_device * - thermal_zone_device_register_with_trips(const char *type, + thermal_zone_device_register_with_trips(struct device *parent, + const char *type, const struct thermal_trip *trips, int num_trips, void *devdata, const struct thermal_zone_device_ops *ops, @@ -49,6 +50,8 @@ temperature) and throttle appropriate devices. /sys/class/thermal folder as `thermal_zone[0-*]`. It tries to bind all the thermal cooling devices registered to it at the same time. + parent: + parent device pointer. type: the thermal zone type. trips: diff --git a/drivers/acpi/thermal.c b/drivers/acpi/thermal.c index 99ad67bbd764..483e28ce0d67 100644 --- a/drivers/acpi/thermal.c +++ b/drivers/acpi/thermal.c @@ -607,16 +607,20 @@ static int acpi_thermal_register_thermal_zone(struct acpi_thermal *tz, unsigned int trip_count, int passive_delay) { + unsigned int polling_delay = tz->polling_frequency * 100; int result; if (trip_count) - tz->thermal_zone = thermal_zone_device_register_with_trips( - "acpitz", trip_table, trip_count, tz, - &acpi_thermal_zone_ops, NULL, passive_delay, - tz->polling_frequency * 100); + tz->thermal_zone = thermal_zone_device_register_with_trips(&tz->device->dev, + "acpitz", trip_table, + trip_count, tz, + &acpi_thermal_zone_ops, + NULL, passive_delay, + polling_delay); else - tz->thermal_zone = thermal_tripless_zone_device_register( - "acpitz", tz, &acpi_thermal_zone_ops, NULL); + tz->thermal_zone = thermal_tripless_zone_device_register(&tz->device->dev, "acpitz", + tz, &acpi_thermal_zone_ops, + NULL); if (IS_ERR(tz->thermal_zone)) return PTR_ERR(tz->thermal_zone); diff --git a/drivers/net/ethernet/chelsio/cxgb4/cxgb4_thermal.c b/drivers/net/ethernet/chelsio/cxgb4/cxgb4_thermal.c index 7bab8da8f6e6..05a1ec7df7a5 100644 --- a/drivers/net/ethernet/chelsio/cxgb4/cxgb4_thermal.c +++ b/drivers/net/ethernet/chelsio/cxgb4/cxgb4_thermal.c @@ -59,8 +59,8 @@ int cxgb4_thermal_init(struct adapter *adap) } snprintf(ch_tz_name, sizeof(ch_tz_name), "cxgb4_%s", adap->name); - ch_thermal->tzdev = thermal_zone_device_register_with_trips(ch_tz_name, &trip, num_trip, - adap, + ch_thermal->tzdev = thermal_zone_device_register_with_trips(adap->pdev_dev, ch_tz_name, + &trip, num_trip, adap, &cxgb4_thermal_ops, NULL, 0, 0); if (IS_ERR(ch_thermal->tzdev)) { diff --git a/drivers/net/ethernet/mellanox/mlxsw/core_thermal.c b/drivers/net/ethernet/mellanox/mlxsw/core_thermal.c index 1117d59b74fd..a1b1e9e8dd3d 100644 --- a/drivers/net/ethernet/mellanox/mlxsw/core_thermal.c +++ b/drivers/net/ethernet/mellanox/mlxsw/core_thermal.c @@ -349,6 +349,8 @@ static const struct thermal_cooling_device_ops mlxsw_cooling_ops = { static int mlxsw_thermal_module_tz_init(struct mlxsw_thermal_module *module_tz) { + unsigned int polling_delay = module_tz->parent->polling_delay; + struct device *dev = module_tz->parent->bus_info->dev; char tz_name[40]; int err; @@ -358,14 +360,12 @@ mlxsw_thermal_module_tz_init(struct mlxsw_thermal_module *module_tz) else snprintf(tz_name, sizeof(tz_name), "mlxsw-module%d", module_tz->module + 1); - module_tz->tzdev = thermal_zone_device_register_with_trips(tz_name, - module_tz->trips, - MLXSW_THERMAL_NUM_TRIPS, - module_tz, - &mlxsw_thermal_module_ops, - &mlxsw_thermal_params, - 0, - module_tz->parent->polling_delay); + module_tz->tzdev = thermal_zone_device_register_with_trips(dev, tz_name, module_tz->trips, + MLXSW_THERMAL_NUM_TRIPS, + module_tz, + &mlxsw_thermal_module_ops, + &mlxsw_thermal_params, 0, + polling_delay); if (IS_ERR(module_tz->tzdev)) { err = PTR_ERR(module_tz->tzdev); return err; @@ -466,6 +466,8 @@ mlxsw_thermal_modules_fini(struct mlxsw_thermal *thermal, static int mlxsw_thermal_gearbox_tz_init(struct mlxsw_thermal_module *gearbox_tz) { + unsigned int polling_delay = gearbox_tz->parent->polling_delay; + struct device *dev = gearbox_tz->parent->bus_info->dev; char tz_name[40]; int ret; @@ -475,13 +477,13 @@ mlxsw_thermal_gearbox_tz_init(struct mlxsw_thermal_module *gearbox_tz) else snprintf(tz_name, sizeof(tz_name), "mlxsw-gearbox%d", gearbox_tz->module + 1); - gearbox_tz->tzdev = thermal_zone_device_register_with_trips(tz_name, - gearbox_tz->trips, - MLXSW_THERMAL_NUM_TRIPS, - gearbox_tz, - &mlxsw_thermal_gearbox_ops, - &mlxsw_thermal_params, 0, - gearbox_tz->parent->polling_delay); + gearbox_tz->tzdev = thermal_zone_device_register_with_trips(dev, tz_name, + gearbox_tz->trips, + MLXSW_THERMAL_NUM_TRIPS, + gearbox_tz, + &mlxsw_thermal_gearbox_ops, + &mlxsw_thermal_params, 0, + polling_delay); if (IS_ERR(gearbox_tz->tzdev)) return PTR_ERR(gearbox_tz->tzdev); @@ -709,13 +711,12 @@ int mlxsw_thermal_init(struct mlxsw_core *core, MLXSW_THERMAL_SLOW_POLL_INT : MLXSW_THERMAL_POLL_INT; - thermal->tzdev = thermal_zone_device_register_with_trips("mlxsw", - thermal->trips, - MLXSW_THERMAL_NUM_TRIPS, - thermal, - &mlxsw_thermal_ops, - &mlxsw_thermal_params, 0, - thermal->polling_delay); + thermal->tzdev = thermal_zone_device_register_with_trips(dev, "mlxsw", + thermal->trips, + MLXSW_THERMAL_NUM_TRIPS, + thermal, &mlxsw_thermal_ops, + &mlxsw_thermal_params, 0, + thermal->polling_delay); if (IS_ERR(thermal->tzdev)) { err = PTR_ERR(thermal->tzdev); dev_err(dev, "Failed to register thermal zone\n"); diff --git a/drivers/net/wireless/intel/iwlwifi/mld/thermal.c b/drivers/net/wireless/intel/iwlwifi/mld/thermal.c index 9e56e6e80ab7..56a0022d33db 100644 --- a/drivers/net/wireless/intel/iwlwifi/mld/thermal.c +++ b/drivers/net/wireless/intel/iwlwifi/mld/thermal.c @@ -256,7 +256,7 @@ static void iwl_mld_thermal_zone_register(struct iwl_mld *mld) sprintf(name, "iwlwifi_%u", atomic_inc_return(&counter) & 0xFF); mld->tzone = - thermal_zone_device_register_with_trips(name, trips, + thermal_zone_device_register_with_trips(mld->dev, name, trips, IWL_MAX_DTS_TRIPS, mld, &tzone_ops, NULL, 0, 0); diff --git a/drivers/net/wireless/intel/iwlwifi/mvm/tt.c b/drivers/net/wireless/intel/iwlwifi/mvm/tt.c index b184f08230b9..e4777b815976 100644 --- a/drivers/net/wireless/intel/iwlwifi/mvm/tt.c +++ b/drivers/net/wireless/intel/iwlwifi/mvm/tt.c @@ -672,11 +672,11 @@ static void iwl_mvm_thermal_zone_register(struct iwl_mvm *mvm) mvm->tz_device.trips[i].type = THERMAL_TRIP_PASSIVE; mvm->tz_device.trips[i].flags = THERMAL_TRIP_FLAG_RW_TEMP; } - mvm->tz_device.tzone = thermal_zone_device_register_with_trips(name, - mvm->tz_device.trips, - IWL_MAX_DTS_TRIPS, - mvm, &tzone_ops, - NULL, 0, 0); + mvm->tz_device.tzone = thermal_zone_device_register_with_trips(mvm->dev, name, + mvm->tz_device.trips, + IWL_MAX_DTS_TRIPS, + mvm, &tzone_ops, + NULL, 0, 0); if (IS_ERR(mvm->tz_device.tzone)) { IWL_DEBUG_TEMP(mvm, "Failed to register to thermal zone (err = %ld)\n", diff --git a/drivers/platform/x86/acerhdf.c b/drivers/platform/x86/acerhdf.c index c74937d475e5..abdb5749c169 100644 --- a/drivers/platform/x86/acerhdf.c +++ b/drivers/platform/x86/acerhdf.c @@ -656,7 +656,7 @@ static int __init acerhdf_register_thermal(void) if (IS_ERR(cl_dev)) return -EINVAL; - thz_dev = thermal_zone_device_register_with_trips("acerhdf", trips, ARRAY_SIZE(trips), + thz_dev = thermal_zone_device_register_with_trips(NULL, "acerhdf", trips, ARRAY_SIZE(trips), NULL, &acerhdf_dev_ops, &acerhdf_zone_params, 0, (kernelmode) ? interval*1000 : 0); diff --git a/drivers/power/supply/power_supply_core.c b/drivers/power/supply/power_supply_core.c index 9a28381e2607..cbc4bed17efa 100644 --- a/drivers/power/supply/power_supply_core.c +++ b/drivers/power/supply/power_supply_core.c @@ -1531,8 +1531,8 @@ static int psy_register_thermal(struct power_supply *psy) struct thermal_zone_params tzp = { .no_hwmon = IS_ENABLED(CONFIG_POWER_SUPPLY_HWMON) }; - psy->tzd = thermal_tripless_zone_device_register(psy->desc->name, - psy, &psy_tzd_ops, &tzp); + psy->tzd = thermal_tripless_zone_device_register(&psy->dev, psy->desc->name, psy, + &psy_tzd_ops, &tzp); if (IS_ERR(psy->tzd)) return PTR_ERR(psy->tzd); ret = thermal_zone_device_enable(psy->tzd); diff --git a/drivers/thermal/armada_thermal.c b/drivers/thermal/armada_thermal.c index c2fbdb534f61..fc60b0bab627 100644 --- a/drivers/thermal/armada_thermal.c +++ b/drivers/thermal/armada_thermal.c @@ -871,7 +871,7 @@ static int armada_thermal_probe(struct platform_device *pdev) /* Wait the sensors to be valid */ armada_wait_sensor_validity(priv); - tz = thermal_tripless_zone_device_register(priv->zone_name, + tz = thermal_tripless_zone_device_register(&pdev->dev, priv->zone_name, priv, &legacy_ops, NULL); if (IS_ERR(tz)) { diff --git a/drivers/thermal/da9062-thermal.c b/drivers/thermal/da9062-thermal.c index a8d4b766ba21..c5368c2b53b9 100644 --- a/drivers/thermal/da9062-thermal.c +++ b/drivers/thermal/da9062-thermal.c @@ -196,7 +196,7 @@ static int da9062_thermal_probe(struct platform_device *pdev) INIT_DELAYED_WORK(&thermal->work, da9062_thermal_poll_on); mutex_init(&thermal->lock); - thermal->zone = thermal_zone_device_register_with_trips(thermal->config->name, + thermal->zone = thermal_zone_device_register_with_trips(&pdev->dev, thermal->config->name, trips, ARRAY_SIZE(trips), thermal, &da9062_thermal_ops, NULL, pp_tmp, 0); diff --git a/drivers/thermal/dove_thermal.c b/drivers/thermal/dove_thermal.c index 723bc72f0626..101c6109b04a 100644 --- a/drivers/thermal/dove_thermal.c +++ b/drivers/thermal/dove_thermal.c @@ -139,7 +139,7 @@ static int dove_thermal_probe(struct platform_device *pdev) return ret; } - thermal = thermal_tripless_zone_device_register("dove_thermal", priv, + thermal = thermal_tripless_zone_device_register(&pdev->dev, "dove_thermal", priv, &ops, NULL); if (IS_ERR(thermal)) { dev_err(&pdev->dev, diff --git a/drivers/thermal/imx_thermal.c b/drivers/thermal/imx_thermal.c index 38c993d1bcb3..043e80756017 100644 --- a/drivers/thermal/imx_thermal.c +++ b/drivers/thermal/imx_thermal.c @@ -679,7 +679,7 @@ static int imx_thermal_probe(struct platform_device *pdev) goto legacy_cleanup; } - data->tz = thermal_zone_device_register_with_trips("imx_thermal_zone", + data->tz = thermal_zone_device_register_with_trips(dev, "imx_thermal_zone", trips, ARRAY_SIZE(trips), data, diff --git a/drivers/thermal/intel/int340x_thermal/int3400_thermal.c b/drivers/thermal/intel/int340x_thermal/int3400_thermal.c index 41d3bc3ed8a2..ed21da8f0a47 100644 --- a/drivers/thermal/intel/int340x_thermal/int3400_thermal.c +++ b/drivers/thermal/intel/int340x_thermal/int3400_thermal.c @@ -594,7 +594,7 @@ static int int3400_thermal_probe(struct platform_device *pdev) evaluate_odvp(priv); - priv->thermal = thermal_tripless_zone_device_register("INT3400 Thermal", priv, + priv->thermal = thermal_tripless_zone_device_register(&pdev->dev, "INT3400 Thermal", priv, &int3400_thermal_ops, &int3400_thermal_params); if (IS_ERR(priv->thermal)) { diff --git a/drivers/thermal/intel/int340x_thermal/int340x_thermal_zone.c b/drivers/thermal/intel/int340x_thermal/int340x_thermal_zone.c index 3d9efe69d562..3adccb7fc157 100644 --- a/drivers/thermal/intel/int340x_thermal/int340x_thermal_zone.c +++ b/drivers/thermal/intel/int340x_thermal/int340x_thermal_zone.c @@ -160,13 +160,12 @@ struct int34x_thermal_zone *int340x_thermal_zone_add(struct acpi_device *adev, int34x_zone->lpat_table = acpi_lpat_get_conversion_table(adev->handle); - int34x_zone->zone = thermal_zone_device_register_with_trips( - acpi_device_bid(adev), - zone_trips, trip_cnt, - int34x_zone, - &zone_ops, - &int340x_thermal_params, - 0, 0); + int34x_zone->zone = thermal_zone_device_register_with_trips(&adev->dev, + acpi_device_bid(adev), + zone_trips, trip_cnt, + int34x_zone, &zone_ops, + &int340x_thermal_params, + 0, 0); kfree(zone_trips); if (IS_ERR(int34x_zone->zone)) { diff --git a/drivers/thermal/intel/int340x_thermal/processor_thermal_device_pci.c b/drivers/thermal/intel/int340x_thermal/processor_thermal_device_pci.c index 0d4dcc66e097..2b3116e23fa1 100644 --- a/drivers/thermal/intel/int340x_thermal/processor_thermal_device_pci.c +++ b/drivers/thermal/intel/int340x_thermal/processor_thermal_device_pci.c @@ -371,10 +371,9 @@ static int proc_thermal_pci_probe(struct pci_dev *pdev, const struct pci_device_ psv_trip.temperature = get_trip_temp(pci_info); - pci_info->tzone = thermal_zone_device_register_with_trips("TCPU_PCI", &psv_trip, - 1, pci_info, - &tzone_ops, - &tzone_params, 0, 0); + pci_info->tzone = thermal_zone_device_register_with_trips(&pdev->dev, "TCPU_PCI", &psv_trip, + 1, pci_info, &tzone_ops, + &tzone_params, 0, 0); if (IS_ERR(pci_info->tzone)) { ret = PTR_ERR(pci_info->tzone); goto err_del_legacy; diff --git a/drivers/thermal/intel/intel_pch_thermal.c b/drivers/thermal/intel/intel_pch_thermal.c index fc326985796c..754527b2b09a 100644 --- a/drivers/thermal/intel/intel_pch_thermal.c +++ b/drivers/thermal/intel/intel_pch_thermal.c @@ -235,7 +235,7 @@ static int intel_pch_thermal_probe(struct pci_dev *pdev, nr_trips += pch_wpt_add_acpi_psv_trip(ptd, &ptd_trips[nr_trips]); - ptd->tzd = thermal_zone_device_register_with_trips(board_names[board_id], + ptd->tzd = thermal_zone_device_register_with_trips(&pdev->dev, board_names[board_id], ptd_trips, nr_trips, ptd, &tzd_ops, NULL, 0, 0); diff --git a/drivers/thermal/intel/intel_quark_dts_thermal.c b/drivers/thermal/intel/intel_quark_dts_thermal.c index 89498eb29a89..d8d38b6ed452 100644 --- a/drivers/thermal/intel/intel_quark_dts_thermal.c +++ b/drivers/thermal/intel/intel_quark_dts_thermal.c @@ -376,7 +376,7 @@ static struct soc_sensor_entry *alloc_soc_dts(void) trips[QRK_DTS_ID_TP_HOT].temperature = get_trip_temp(QRK_DTS_ID_TP_HOT); trips[QRK_DTS_ID_TP_HOT].type = THERMAL_TRIP_HOT; - aux_entry->tzone = thermal_zone_device_register_with_trips("quark_dts", + aux_entry->tzone = thermal_zone_device_register_with_trips(NULL, "quark_dts", trips, QRK_MAX_DTS_TRIPS, aux_entry, diff --git a/drivers/thermal/intel/intel_soc_dts_iosf.c b/drivers/thermal/intel/intel_soc_dts_iosf.c index ea87439fe7a9..74638dac75e6 100644 --- a/drivers/thermal/intel/intel_soc_dts_iosf.c +++ b/drivers/thermal/intel/intel_soc_dts_iosf.c @@ -230,7 +230,7 @@ static int add_dts_thermal_zone(int id, struct intel_soc_dts_sensor_entry *dts, } } snprintf(name, sizeof(name), "soc_dts%d", id); - dts->tzone = thermal_zone_device_register_with_trips(name, trips, + dts->tzone = thermal_zone_device_register_with_trips(NULL, name, trips, SOC_MAX_DTS_TRIPS, dts, &tzone_ops, NULL, 0, 0); diff --git a/drivers/thermal/intel/x86_pkg_temp_thermal.c b/drivers/thermal/intel/x86_pkg_temp_thermal.c index 3fc679b6f11b..807126dc4bea 100644 --- a/drivers/thermal/intel/x86_pkg_temp_thermal.c +++ b/drivers/thermal/intel/x86_pkg_temp_thermal.c @@ -342,9 +342,9 @@ static int pkg_temp_thermal_device_add(unsigned int cpu) INIT_DELAYED_WORK(&zonedev->work, pkg_temp_thermal_threshold_work_fn); zonedev->cpu = cpu; - zonedev->tzone = thermal_zone_device_register_with_trips("x86_pkg_temp", - trips, thres_count, - zonedev, &tzone_ops, &pkg_temp_tz_params, 0, 0); + zonedev->tzone = thermal_zone_device_register_with_trips(NULL, "x86_pkg_temp", trips, + thres_count, zonedev, &tzone_ops, + &pkg_temp_tz_params, 0, 0); if (IS_ERR(zonedev->tzone)) { err = PTR_ERR(zonedev->tzone); goto out_kfree_zonedev; diff --git a/drivers/thermal/kirkwood_thermal.c b/drivers/thermal/kirkwood_thermal.c index 4619e090f756..4827ad2bdb49 100644 --- a/drivers/thermal/kirkwood_thermal.c +++ b/drivers/thermal/kirkwood_thermal.c @@ -71,7 +71,7 @@ static int kirkwood_thermal_probe(struct platform_device *pdev) if (IS_ERR(priv->sensor)) return PTR_ERR(priv->sensor); - thermal = thermal_tripless_zone_device_register("kirkwood_thermal", + thermal = thermal_tripless_zone_device_register(&pdev->dev, "kirkwood_thermal", priv, &ops, NULL); if (IS_ERR(thermal)) { dev_err(&pdev->dev, diff --git a/drivers/thermal/renesas/rcar_thermal.c b/drivers/thermal/renesas/rcar_thermal.c index fdd7afdc4ff6..3d228e4c7b09 100644 --- a/drivers/thermal/renesas/rcar_thermal.c +++ b/drivers/thermal/renesas/rcar_thermal.c @@ -488,10 +488,12 @@ static int rcar_thermal_probe(struct platform_device *pdev) dev, i, priv, &rcar_thermal_zone_ops); } else { - priv->zone = thermal_zone_device_register_with_trips( - "rcar_thermal", trips, ARRAY_SIZE(trips), priv, - &rcar_thermal_zone_ops, NULL, 0, - idle); + priv->zone = thermal_zone_device_register_with_trips(dev, "rcar_thermal", + trips, + ARRAY_SIZE(trips), + priv, + &rcar_thermal_zone_ops, + NULL, 0, idle); ret = thermal_zone_device_enable(priv->zone); if (ret) { diff --git a/drivers/thermal/spear_thermal.c b/drivers/thermal/spear_thermal.c index 603dadcd3df5..c5bba9d600d4 100644 --- a/drivers/thermal/spear_thermal.c +++ b/drivers/thermal/spear_thermal.c @@ -122,7 +122,7 @@ static int spear_thermal_probe(struct platform_device *pdev) stdev->flags = val; writel_relaxed(stdev->flags, stdev->thermal_base); - spear_thermal = thermal_tripless_zone_device_register("spear_thermal", + spear_thermal = thermal_tripless_zone_device_register(&pdev->dev, "spear_thermal", stdev, &ops, NULL); if (IS_ERR(spear_thermal)) { dev_err(&pdev->dev, "thermal zone device is NULL\n"); diff --git a/drivers/thermal/testing/zone.c b/drivers/thermal/testing/zone.c index c12c405225bb..5a7e9969582e 100644 --- a/drivers/thermal/testing/zone.c +++ b/drivers/thermal/testing/zone.c @@ -402,7 +402,7 @@ static int tt_zone_register_tz(struct tt_thermal_zone *tt_zone) tt_zone->tz_temp = tt_zone->temp; - tz = thermal_zone_device_register_with_trips("test_tz", trips, i, tt_zone, + tz = thermal_zone_device_register_with_trips(NULL, "test_tz", trips, i, tt_zone, &tt_zone_ops, NULL, 0, 0); if (IS_ERR(tz)) return PTR_ERR(tz); diff --git a/drivers/thermal/thermal_core.c b/drivers/thermal/thermal_core.c index 92e51d2e4535..9d8499999579 100644 --- a/drivers/thermal/thermal_core.c +++ b/drivers/thermal/thermal_core.c @@ -1475,6 +1475,7 @@ static void thermal_zone_init_complete(struct thermal_zone_device *tz) /** * thermal_zone_device_register_with_trips() - register a new thermal zone device + * @parent: parent device pointer * @type: the thermal zone device type * @trips: a pointer to an array of thermal trips * @num_trips: the number of trip points the thermal zone support @@ -1498,7 +1499,7 @@ static void thermal_zone_init_complete(struct thermal_zone_device *tz) * IS_ERR*() helpers. */ struct thermal_zone_device * -thermal_zone_device_register_with_trips(const char *type, +thermal_zone_device_register_with_trips(struct device *parent, const char *type, const struct thermal_trip *trips, int num_trips, void *devdata, const struct thermal_zone_device_ops *ops, @@ -1576,6 +1577,7 @@ thermal_zone_device_register_with_trips(const char *type, tz->ops.critical = thermal_zone_device_critical; tz->device.class = thermal_class; + tz->device.parent = parent; tz->devdata = devdata; tz->num_trips = num_trips; for_each_trip_desc(tz, td) { @@ -1651,12 +1653,13 @@ thermal_zone_device_register_with_trips(const char *type, EXPORT_SYMBOL_GPL(thermal_zone_device_register_with_trips); struct thermal_zone_device *thermal_tripless_zone_device_register( + struct device *parent, const char *type, void *devdata, const struct thermal_zone_device_ops *ops, const struct thermal_zone_params *tzp) { - return thermal_zone_device_register_with_trips(type, NULL, 0, devdata, + return thermal_zone_device_register_with_trips(parent, type, NULL, 0, devdata, ops, tzp, 0, 0); } EXPORT_SYMBOL_GPL(thermal_tripless_zone_device_register); diff --git a/drivers/thermal/thermal_of.c b/drivers/thermal/thermal_of.c index 1a51a4d240ff..e3359ca20d77 100644 --- a/drivers/thermal/thermal_of.c +++ b/drivers/thermal/thermal_of.c @@ -354,6 +354,7 @@ static void thermal_of_zone_unregister(struct thermal_zone_device *tz) * zone properties and registers new thermal zone with those * properties. * + * @parent: parent device pointer * @sensor: A device node pointer corresponding to the sensor in the device tree * @id: An integer as sensor identifier * @data: A private data to be stored in the thermal zone dedicated private area @@ -364,7 +365,9 @@ static void thermal_of_zone_unregister(struct thermal_zone_device *tz) * - ENOMEM: if one structure can not be allocated * - Other negative errors are returned by the underlying called functions */ -static struct thermal_zone_device *thermal_of_zone_register(struct device_node *sensor, int id, void *data, +static struct thermal_zone_device *thermal_of_zone_register(struct device *parent, + struct device_node *sensor, + int id, void *data, const struct thermal_zone_device_ops *ops) { struct thermal_zone_device_ops of_ops = *ops; @@ -412,7 +415,7 @@ static struct thermal_zone_device *thermal_of_zone_register(struct device_node * of_ops.critical = thermal_zone_device_critical_shutdown; } - tz = thermal_zone_device_register_with_trips(np->name, trips, ntrips, + tz = thermal_zone_device_register_with_trips(parent, np->name, trips, ntrips, data, &of_ops, &tzp, pdelay, delay); if (IS_ERR(tz)) { @@ -478,7 +481,7 @@ struct thermal_zone_device *devm_thermal_of_zone_register(struct device *dev, in if (!ptr) return ERR_PTR(-ENOMEM); - tzd = thermal_of_zone_register(dev->of_node, sensor_id, data, ops); + tzd = thermal_of_zone_register(dev, dev->of_node, sensor_id, data, ops); if (IS_ERR(tzd)) { devres_free(ptr); return tzd; diff --git a/include/linux/thermal.h b/include/linux/thermal.h index 29a608bf5f80..0c5a91313bd5 100644 --- a/include/linux/thermal.h +++ b/include/linux/thermal.h @@ -226,6 +226,7 @@ int thermal_zone_get_crit_temp(struct thermal_zone_device *tz, int *temp); #ifdef CONFIG_THERMAL struct thermal_zone_device *thermal_zone_device_register_with_trips( + struct device *parent, const char *type, const struct thermal_trip *trips, int num_trips, void *devdata, @@ -235,6 +236,7 @@ struct thermal_zone_device *thermal_zone_device_register_with_trips( unsigned int polling_delay); struct thermal_zone_device *thermal_tripless_zone_device_register( + struct device *parent, const char *type, void *devdata, const struct thermal_zone_device_ops *ops, @@ -276,6 +278,7 @@ int thermal_zone_device_disable(struct thermal_zone_device *tz); void thermal_zone_device_critical(struct thermal_zone_device *tz); #else static inline struct thermal_zone_device *thermal_zone_device_register_with_trips( + struct device *parent, const char *type, const struct thermal_trip *trips, int num_trips, void *devdata, @@ -285,6 +288,7 @@ static inline struct thermal_zone_device *thermal_zone_device_register_with_trip { return ERR_PTR(-ENODEV); } static inline struct thermal_zone_device *thermal_tripless_zone_device_register( + struct device *parent, const char *type, void *devdata, struct thermal_zone_device_ops *ops, -- 2.39.5