xref: /openbmc/linux/drivers/hwmon/pmbus/xdpe152c4.c (revision 2bc7d3e0)
1 // SPDX-License-Identifier: GPL-2.0-or-later
2 /*
3  * Hardware monitoring driver for Infineon Multi-phase Digital VR Controllers
4  *
5  * Copyright (c) 2022 Infineon Technologies. All rights reserved.
6  */
7 
8 #include <linux/err.h>
9 #include <linux/i2c.h>
10 #include <linux/init.h>
11 #include <linux/kernel.h>
12 #include <linux/module.h>
13 #include "pmbus.h"
14 
15 #define XDPE152_PAGE_NUM 2
16 
17 static struct pmbus_driver_info xdpe152_info = {
18 	.pages = XDPE152_PAGE_NUM,
19 	.format[PSC_VOLTAGE_IN] = linear,
20 	.format[PSC_VOLTAGE_OUT] = linear,
21 	.format[PSC_TEMPERATURE] = linear,
22 	.format[PSC_CURRENT_IN] = linear,
23 	.format[PSC_CURRENT_OUT] = linear,
24 	.format[PSC_POWER] = linear,
25 	.func[0] = PMBUS_HAVE_VIN | PMBUS_HAVE_VOUT | PMBUS_HAVE_STATUS_VOUT |
26 		PMBUS_HAVE_IIN | PMBUS_HAVE_IOUT | PMBUS_HAVE_STATUS_IOUT |
27 		PMBUS_HAVE_TEMP | PMBUS_HAVE_TEMP2 | PMBUS_HAVE_STATUS_TEMP |
28 		PMBUS_HAVE_POUT | PMBUS_HAVE_PIN | PMBUS_HAVE_STATUS_INPUT,
29 	.func[1] = PMBUS_HAVE_VIN | PMBUS_HAVE_VOUT | PMBUS_HAVE_STATUS_VOUT |
30 		PMBUS_HAVE_IIN | PMBUS_HAVE_IOUT | PMBUS_HAVE_STATUS_IOUT |
31 		PMBUS_HAVE_POUT | PMBUS_HAVE_PIN | PMBUS_HAVE_STATUS_INPUT,
32 };
33 
34 static int xdpe152_probe(struct i2c_client *client)
35 {
36 	struct pmbus_driver_info *info;
37 
38 	info = devm_kmemdup(&client->dev, &xdpe152_info, sizeof(*info),
39 			    GFP_KERNEL);
40 	if (!info)
41 		return -ENOMEM;
42 
43 	return pmbus_do_probe(client, info);
44 }
45 
46 static const struct i2c_device_id xdpe152_id[] = {
47 	{"xdpe152c4", 0},
48 	{"xdpe15284", 0},
49 	{}
50 };
51 
52 MODULE_DEVICE_TABLE(i2c, xdpe152_id);
53 
54 static const struct of_device_id __maybe_unused xdpe152_of_match[] = {
55 	{.compatible = "infineon,xdpe152c4"},
56 	{.compatible = "infineon,xdpe15284"},
57 	{}
58 };
59 MODULE_DEVICE_TABLE(of, xdpe152_of_match);
60 
61 static struct i2c_driver xdpe152_driver = {
62 	.driver = {
63 		.name = "xdpe152c4",
64 		.of_match_table = of_match_ptr(xdpe152_of_match),
65 	},
66 	.probe_new = xdpe152_probe,
67 	.id_table = xdpe152_id,
68 };
69 
70 module_i2c_driver(xdpe152_driver);
71 
72 MODULE_AUTHOR("Greg Schwendimann <greg.schwendimann@infineon.com>");
73 MODULE_DESCRIPTION("PMBus driver for Infineon XDPE152 family");
74 MODULE_LICENSE("GPL");
75 MODULE_IMPORT_NS(PMBUS);
76