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 <[email protected]>
---
 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

Reply via email to