]> git.ipfire.org Git - thirdparty/kernel/linux.git/commitdiff
hwmon: pmbus: mpq8785: Prepare driver for multiple device support
authorPawel Dembicki <paweldembicki@gmail.com>
Sun, 11 May 2025 03:55:45 +0000 (05:55 +0200)
committerGuenter Roeck <linux@roeck-us.net>
Mon, 12 May 2025 16:42:39 +0000 (09:42 -0700)
Refactor the driver to support multiple Monolithic Power Systems devices.
Introduce chip ID handling based on device tree matching.

No functional changes intended.

Signed-off-by: Pawel Dembicki <paweldembicki@gmail.com>
Link: https://lore.kernel.org/r/20250511035701.2607947-3-paweldembicki@gmail.com
Signed-off-by: Guenter Roeck <linux@roeck-us.net>
drivers/hwmon/pmbus/mpq8785.c

index 331c274ca89226c7b71d3a4ddeda2fcfd9174586..d0ac294b4bbcdecf5b3b9c280149ebd0a3c042c6 100644 (file)
@@ -8,6 +8,8 @@
 #include <linux/of_device.h>
 #include "pmbus.h"
 
+enum chips { mpq8785 };
+
 static int mpq8785_identify(struct i2c_client *client,
                            struct pmbus_driver_info *info)
 {
@@ -53,26 +55,46 @@ static struct pmbus_driver_info mpq8785_info = {
                PMBUS_HAVE_VOUT | PMBUS_HAVE_STATUS_VOUT |
                PMBUS_HAVE_IOUT | PMBUS_HAVE_STATUS_IOUT |
                PMBUS_HAVE_TEMP | PMBUS_HAVE_STATUS_TEMP,
-       .identify = mpq8785_identify,
-};
-
-static int mpq8785_probe(struct i2c_client *client)
-{
-       return pmbus_do_probe(client, &mpq8785_info);
 };
 
 static const struct i2c_device_id mpq8785_id[] = {
-       { "mpq8785" },
+       { "mpq8785", mpq8785 },
        { },
 };
 MODULE_DEVICE_TABLE(i2c, mpq8785_id);
 
 static const struct of_device_id __maybe_unused mpq8785_of_match[] = {
-       { .compatible = "mps,mpq8785" },
+       { .compatible = "mps,mpq8785", .data = (void *)mpq8785 },
        {}
 };
 MODULE_DEVICE_TABLE(of, mpq8785_of_match);
 
+static int mpq8785_probe(struct i2c_client *client)
+{
+       struct device *dev = &client->dev;
+       struct pmbus_driver_info *info;
+       enum chips chip_id;
+
+       info = devm_kmemdup(dev, &mpq8785_info, sizeof(*info), GFP_KERNEL);
+       if (!info)
+               return -ENOMEM;
+
+       if (dev->of_node)
+               chip_id = (kernel_ulong_t)of_device_get_match_data(dev);
+       else
+               chip_id = (kernel_ulong_t)i2c_get_match_data(client);
+
+       switch (chip_id) {
+       case mpq8785:
+               info->identify = mpq8785_identify;
+               break;
+       default:
+               return -ENODEV;
+       }
+
+       return pmbus_do_probe(client, info);
+};
+
 static struct i2c_driver mpq8785_driver = {
        .driver = {
                   .name = "mpq8785",