Re: [PATCH v1] hwmon: drivetemp: support to be a platform driver for thermal_of

From: Phinex Hung
Date: Thu Mar 16 2023 - 03:48:36 EST




On 3/16/23 15:35 "Phinex Hung" <phinex@xxxxxxxxxxx <mailto:phinex@xxxxxxxxxxx> wrote:

>Not sure whether this is the difference, but use the following patch can solve this issue.

>@@ -540,9 +531,9 @@ static int drivetemp_add(struct device *dev, struct class_interface *intf)
>goto abort;
>}
>
>
>- st->hwdev = hwmon_device_register_with_info(dev->parent, "drivetemp",
>- st, &drivetemp_chip_info,
>- NULL);
>+ st->hwdev = hwmon_device_register_with_info(
>+ dev->parent->parent->parent->parent->parent, "drivetemp", st,
>+ &drivetemp_chip_info, NULL);


A more generic patch works in my case, listed below:

diff --git a/drivers/hwmon/drivetemp.c b/drivers/hwmon/drivetemp.c
index 1cf4f9015316..a4cddfea8d22 100644
--- a/drivers/hwmon/drivetemp.c
+++ b/drivers/hwmon/drivetemp.c
@@ -525,6 +525,7 @@ static int drivetemp_add(struct device *dev, struct class_interface *intf)
{
struct scsi_device *sdev = to_scsi_device(dev->parent);
struct drivetemp_data *st;
+ struct device *tdev = dev->parent;
int err;

st = kzalloc(sizeof(*st), GFP_KERNEL);
@@ -540,8 +541,11 @@ static int drivetemp_add(struct device *dev, struct class_interface *intf)
goto abort;
}

- st->hwdev = hwmon_device_register_with_info(dev->parent, "drivetemp",
- st, &drivetemp_chip_info,
+ while(!tdev->of_node)
+ tdev = tdev->parent;
+
+ st->hwdev = hwmon_device_register_with_info(tdev, "drivetemp", st,
+ &drivetemp_chip_info,
NULL);
if (IS_ERR(st->hwdev)) {
err = PTR_ERR(st->hwdev);

Thanks

Regards,
Phinex