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