xref: /linux/drivers/hwmon/pmbus/pm6764tr.c (revision 1975d167869ef03102771d6267582623d6e07058)
17537862aSCharles // SPDX-License-Identifier: GPL-2.0+
27537862aSCharles /*
37537862aSCharles  * Hardware monitoring driver for STMicroelectronics digital controller PM6764TR
47537862aSCharles  */
57537862aSCharles 
67537862aSCharles #include <linux/err.h>
77537862aSCharles #include <linux/i2c.h>
87537862aSCharles #include <linux/init.h>
97537862aSCharles #include <linux/kernel.h>
107537862aSCharles #include <linux/module.h>
117537862aSCharles #include <linux/pmbus.h>
127537862aSCharles #include "pmbus.h"
137537862aSCharles 
147537862aSCharles #define PM6764TR_PMBUS_READ_VOUT	0xD4
157537862aSCharles 
167537862aSCharles static int pm6764tr_read_word_data(struct i2c_client *client, int page, int phase, int reg)
177537862aSCharles {
187537862aSCharles 	int ret;
197537862aSCharles 
207537862aSCharles 	switch (reg) {
217537862aSCharles 	case PMBUS_VIRT_READ_VMON:
227537862aSCharles 		ret = pmbus_read_word_data(client, page, phase, PM6764TR_PMBUS_READ_VOUT);
237537862aSCharles 		break;
247537862aSCharles 	default:
257537862aSCharles 		ret = -ENODATA;
267537862aSCharles 		break;
277537862aSCharles 	}
287537862aSCharles 	return ret;
297537862aSCharles }
307537862aSCharles 
317537862aSCharles static struct pmbus_driver_info pm6764tr_info = {
327537862aSCharles 	.pages = 1,
337537862aSCharles 	.format[PSC_VOLTAGE_IN] = linear,
347537862aSCharles 	.format[PSC_VOLTAGE_OUT] = vid,
357537862aSCharles 	.format[PSC_TEMPERATURE] = linear,
367537862aSCharles 	.format[PSC_CURRENT_OUT] = linear,
377537862aSCharles 	.format[PSC_POWER] = linear,
387537862aSCharles 	.func[0] = PMBUS_HAVE_VIN | PMBUS_HAVE_IIN |  PMBUS_HAVE_PIN |
397537862aSCharles 	    PMBUS_HAVE_IOUT | PMBUS_HAVE_POUT | PMBUS_HAVE_VMON |
407537862aSCharles 		PMBUS_HAVE_STATUS_IOUT | PMBUS_HAVE_STATUS_VOUT |
417537862aSCharles 		PMBUS_HAVE_TEMP | PMBUS_HAVE_STATUS_TEMP,
427537862aSCharles 	.read_word_data = pm6764tr_read_word_data,
437537862aSCharles };
447537862aSCharles 
457537862aSCharles static int pm6764tr_probe(struct i2c_client *client)
467537862aSCharles {
477537862aSCharles 	return pmbus_do_probe(client, &pm6764tr_info);
487537862aSCharles }
497537862aSCharles 
507537862aSCharles static const struct i2c_device_id pm6764tr_id[] = {
517537862aSCharles 	{"pm6764tr", 0},
527537862aSCharles 	{}
537537862aSCharles };
547537862aSCharles MODULE_DEVICE_TABLE(i2c, pm6764tr_id);
557537862aSCharles 
567537862aSCharles static const struct of_device_id __maybe_unused pm6764tr_of_match[] = {
577537862aSCharles 	{.compatible = "st,pm6764tr"},
587537862aSCharles 	{}
597537862aSCharles };
607537862aSCharles 
617537862aSCharles /* This is the driver that will be inserted */
627537862aSCharles static struct i2c_driver pm6764tr_driver = {
637537862aSCharles 	.driver = {
647537862aSCharles 		   .name = "pm6764tr",
657537862aSCharles 		   .of_match_table = of_match_ptr(pm6764tr_of_match),
667537862aSCharles 		   },
67*1975d167SUwe Kleine-König 	.probe = pm6764tr_probe,
687537862aSCharles 	.id_table = pm6764tr_id,
697537862aSCharles };
707537862aSCharles 
717537862aSCharles module_i2c_driver(pm6764tr_driver);
727537862aSCharles 
737537862aSCharles MODULE_AUTHOR("Charles Hsu");
747537862aSCharles MODULE_DESCRIPTION("PMBus driver for  ST PM6764TR");
757537862aSCharles MODULE_LICENSE("GPL");
76b94ca77eSGuenter Roeck MODULE_IMPORT_NS(PMBUS);
77