1 // SPDX-License-Identifier: GPL-2.0+
2 /*
3  * Hardware monitoring driver for TEXAS TPS546D24 buck converter
4  */
5 
6 #include <linux/err.h>
7 #include <linux/i2c.h>
8 #include <linux/init.h>
9 #include <linux/kernel.h>
10 #include <linux/module.h>
11 #include <linux/pmbus.h>
12 #include "pmbus.h"
13 
14 static struct pmbus_driver_info tps546d24_info = {
15 	.pages = 1,
16 	.format[PSC_VOLTAGE_IN] = linear,
17 	.format[PSC_VOLTAGE_OUT] = linear,
18 	.format[PSC_TEMPERATURE] = linear,
19 	.format[PSC_CURRENT_OUT] = linear,
20 	.func[0] = PMBUS_HAVE_VIN | PMBUS_HAVE_IIN
21 			| PMBUS_HAVE_IOUT | PMBUS_HAVE_VOUT
22 			| PMBUS_HAVE_STATUS_IOUT | PMBUS_HAVE_STATUS_VOUT
23 			| PMBUS_HAVE_TEMP | PMBUS_HAVE_STATUS_TEMP,
24 };
25 
tps546d24_probe(struct i2c_client * client)26 static int tps546d24_probe(struct i2c_client *client)
27 {
28 	int reg;
29 
30 	reg = i2c_smbus_read_byte_data(client, PMBUS_VOUT_MODE);
31 	if (reg < 0)
32 		return reg;
33 
34 	if (reg & 0x80) {
35 		int err;
36 
37 		err = i2c_smbus_write_byte_data(client, PMBUS_VOUT_MODE, reg & 0x7f);
38 		if (err < 0)
39 			return err;
40 	}
41 	return pmbus_do_probe(client, &tps546d24_info);
42 }
43 
44 static const struct i2c_device_id tps546d24_id[] = {
45 	{"tps546d24", 0},
46 	{}
47 };
48 MODULE_DEVICE_TABLE(i2c, tps546d24_id);
49 
50 static const struct of_device_id __maybe_unused tps546d24_of_match[] = {
51 	{.compatible = "ti,tps546d24"},
52 	{}
53 };
54 MODULE_DEVICE_TABLE(of, tps546d24_of_match);
55 
56 /* This is the driver that will be inserted */
57 static struct i2c_driver tps546d24_driver = {
58 	.driver = {
59 		   .name = "tps546d24",
60 		   .of_match_table = of_match_ptr(tps546d24_of_match),
61 	   },
62 	.probe_new = tps546d24_probe,
63 	.id_table = tps546d24_id,
64 };
65 
66 module_i2c_driver(tps546d24_driver);
67 
68 MODULE_AUTHOR("Duke Du <dukedu83@gmail.com>");
69 MODULE_DESCRIPTION("PMBus driver for TI tps546d24");
70 MODULE_LICENSE("GPL");
71 MODULE_IMPORT_NS(PMBUS);
72