xref: /openbmc/linux/drivers/hwmon/pmbus/pm6764tr.c (revision 7537862a90b8b9106d42ad2f53de2b96fd1673c5)
1*7537862aSCharles // SPDX-License-Identifier: GPL-2.0+
2*7537862aSCharles /*
3*7537862aSCharles  * Hardware monitoring driver for STMicroelectronics digital controller PM6764TR
4*7537862aSCharles  */
5*7537862aSCharles 
6*7537862aSCharles #include <linux/err.h>
7*7537862aSCharles #include <linux/i2c.h>
8*7537862aSCharles #include <linux/init.h>
9*7537862aSCharles #include <linux/kernel.h>
10*7537862aSCharles #include <linux/module.h>
11*7537862aSCharles #include <linux/pmbus.h>
12*7537862aSCharles #include "pmbus.h"
13*7537862aSCharles 
14*7537862aSCharles #define PM6764TR_PMBUS_READ_VOUT	0xD4
15*7537862aSCharles 
16*7537862aSCharles static int pm6764tr_read_word_data(struct i2c_client *client, int page, int phase, int reg)
17*7537862aSCharles {
18*7537862aSCharles 	int ret;
19*7537862aSCharles 
20*7537862aSCharles 	switch (reg) {
21*7537862aSCharles 	case PMBUS_VIRT_READ_VMON:
22*7537862aSCharles 		ret = pmbus_read_word_data(client, page, phase, PM6764TR_PMBUS_READ_VOUT);
23*7537862aSCharles 		break;
24*7537862aSCharles 	default:
25*7537862aSCharles 		ret = -ENODATA;
26*7537862aSCharles 		break;
27*7537862aSCharles 	}
28*7537862aSCharles 	return ret;
29*7537862aSCharles }
30*7537862aSCharles 
31*7537862aSCharles static struct pmbus_driver_info pm6764tr_info = {
32*7537862aSCharles 	.pages = 1,
33*7537862aSCharles 	.format[PSC_VOLTAGE_IN] = linear,
34*7537862aSCharles 	.format[PSC_VOLTAGE_OUT] = vid,
35*7537862aSCharles 	.format[PSC_TEMPERATURE] = linear,
36*7537862aSCharles 	.format[PSC_CURRENT_OUT] = linear,
37*7537862aSCharles 	.format[PSC_POWER] = linear,
38*7537862aSCharles 	.func[0] = PMBUS_HAVE_VIN | PMBUS_HAVE_IIN |  PMBUS_HAVE_PIN |
39*7537862aSCharles 	    PMBUS_HAVE_IOUT | PMBUS_HAVE_POUT | PMBUS_HAVE_VMON |
40*7537862aSCharles 		PMBUS_HAVE_STATUS_IOUT | PMBUS_HAVE_STATUS_VOUT |
41*7537862aSCharles 		PMBUS_HAVE_TEMP | PMBUS_HAVE_STATUS_TEMP,
42*7537862aSCharles 	.read_word_data = pm6764tr_read_word_data,
43*7537862aSCharles };
44*7537862aSCharles 
45*7537862aSCharles static int pm6764tr_probe(struct i2c_client *client)
46*7537862aSCharles {
47*7537862aSCharles 	return pmbus_do_probe(client, &pm6764tr_info);
48*7537862aSCharles }
49*7537862aSCharles 
50*7537862aSCharles static const struct i2c_device_id pm6764tr_id[] = {
51*7537862aSCharles 	{"pm6764tr", 0},
52*7537862aSCharles 	{}
53*7537862aSCharles };
54*7537862aSCharles MODULE_DEVICE_TABLE(i2c, pm6764tr_id);
55*7537862aSCharles 
56*7537862aSCharles static const struct of_device_id __maybe_unused pm6764tr_of_match[] = {
57*7537862aSCharles 	{.compatible = "st,pm6764tr"},
58*7537862aSCharles 	{}
59*7537862aSCharles };
60*7537862aSCharles 
61*7537862aSCharles /* This is the driver that will be inserted */
62*7537862aSCharles static struct i2c_driver pm6764tr_driver = {
63*7537862aSCharles 	.driver = {
64*7537862aSCharles 		   .name = "pm6764tr",
65*7537862aSCharles 		   .of_match_table = of_match_ptr(pm6764tr_of_match),
66*7537862aSCharles 		   },
67*7537862aSCharles 	.probe_new = pm6764tr_probe,
68*7537862aSCharles 	.id_table = pm6764tr_id,
69*7537862aSCharles };
70*7537862aSCharles 
71*7537862aSCharles module_i2c_driver(pm6764tr_driver);
72*7537862aSCharles 
73*7537862aSCharles MODULE_AUTHOR("Charles Hsu");
74*7537862aSCharles MODULE_DESCRIPTION("PMBus driver for  ST PM6764TR");
75*7537862aSCharles MODULE_LICENSE("GPL");
76