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