Skip to content

Commit 1bc6020

Browse files
CHKDSK88groeck
authored andcommitted
hwmon: pmbus: mpq8785: Prepare driver for multiple device support
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>
1 parent e00fe40 commit 1bc6020

File tree

1 file changed

+30
-8
lines changed

1 file changed

+30
-8
lines changed

drivers/hwmon/pmbus/mpq8785.c

Lines changed: 30 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,8 @@
88
#include <linux/of_device.h>
99
#include "pmbus.h"
1010

11+
enum chips { mpq8785 };
12+
1113
static int mpq8785_identify(struct i2c_client *client,
1214
struct pmbus_driver_info *info)
1315
{
@@ -53,26 +55,46 @@ static struct pmbus_driver_info mpq8785_info = {
5355
PMBUS_HAVE_VOUT | PMBUS_HAVE_STATUS_VOUT |
5456
PMBUS_HAVE_IOUT | PMBUS_HAVE_STATUS_IOUT |
5557
PMBUS_HAVE_TEMP | PMBUS_HAVE_STATUS_TEMP,
56-
.identify = mpq8785_identify,
57-
};
58-
59-
static int mpq8785_probe(struct i2c_client *client)
60-
{
61-
return pmbus_do_probe(client, &mpq8785_info);
6258
};
6359

6460
static const struct i2c_device_id mpq8785_id[] = {
65-
{ "mpq8785" },
61+
{ "mpq8785", mpq8785 },
6662
{ },
6763
};
6864
MODULE_DEVICE_TABLE(i2c, mpq8785_id);
6965

7066
static const struct of_device_id __maybe_unused mpq8785_of_match[] = {
71-
{ .compatible = "mps,mpq8785" },
67+
{ .compatible = "mps,mpq8785", .data = (void *)mpq8785 },
7268
{}
7369
};
7470
MODULE_DEVICE_TABLE(of, mpq8785_of_match);
7571

72+
static int mpq8785_probe(struct i2c_client *client)
73+
{
74+
struct device *dev = &client->dev;
75+
struct pmbus_driver_info *info;
76+
enum chips chip_id;
77+
78+
info = devm_kmemdup(dev, &mpq8785_info, sizeof(*info), GFP_KERNEL);
79+
if (!info)
80+
return -ENOMEM;
81+
82+
if (dev->of_node)
83+
chip_id = (kernel_ulong_t)of_device_get_match_data(dev);
84+
else
85+
chip_id = (kernel_ulong_t)i2c_get_match_data(client);
86+
87+
switch (chip_id) {
88+
case mpq8785:
89+
info->identify = mpq8785_identify;
90+
break;
91+
default:
92+
return -ENODEV;
93+
}
94+
95+
return pmbus_do_probe(client, info);
96+
};
97+
7698
static struct i2c_driver mpq8785_driver = {
7799
.driver = {
78100
.name = "mpq8785",

0 commit comments

Comments
 (0)