1626bb2f3STao Ren // SPDX-License-Identifier: GPL-2.0+ 2626bb2f3STao Ren /* 3626bb2f3STao Ren * Hardware monitoring driver for BEL PFE family power supplies. 4626bb2f3STao Ren * 5626bb2f3STao Ren * Copyright (c) 2019 Facebook Inc. 6626bb2f3STao Ren */ 7626bb2f3STao Ren 8626bb2f3STao Ren #include <linux/err.h> 9626bb2f3STao Ren #include <linux/i2c.h> 10626bb2f3STao Ren #include <linux/init.h> 11626bb2f3STao Ren #include <linux/kernel.h> 12626bb2f3STao Ren #include <linux/module.h> 13626bb2f3STao Ren #include <linux/pmbus.h> 14626bb2f3STao Ren 15626bb2f3STao Ren #include "pmbus.h" 16626bb2f3STao Ren 17626bb2f3STao Ren enum chips {pfe1100, pfe3000}; 18626bb2f3STao Ren 19626bb2f3STao Ren /* 20626bb2f3STao Ren * Disable status check for pfe3000 devices, because some devices report 21626bb2f3STao Ren * communication error (invalid command) for VOUT_MODE command (0x20) 22626bb2f3STao Ren * although correct VOUT_MODE (0x16) is returned: it leads to incorrect 23626bb2f3STao Ren * exponent in linear mode. 24626bb2f3STao Ren */ 25626bb2f3STao Ren static struct pmbus_platform_data pfe3000_plat_data = { 26626bb2f3STao Ren .flags = PMBUS_SKIP_STATUS_CHECK, 27626bb2f3STao Ren }; 28626bb2f3STao Ren 29626bb2f3STao Ren static struct pmbus_driver_info pfe_driver_info[] = { 30626bb2f3STao Ren [pfe1100] = { 31626bb2f3STao Ren .pages = 1, 32626bb2f3STao Ren .format[PSC_VOLTAGE_IN] = linear, 33626bb2f3STao Ren .format[PSC_VOLTAGE_OUT] = linear, 34626bb2f3STao Ren .format[PSC_CURRENT_IN] = linear, 35626bb2f3STao Ren .format[PSC_CURRENT_OUT] = linear, 36626bb2f3STao Ren .format[PSC_POWER] = linear, 37626bb2f3STao Ren .format[PSC_TEMPERATURE] = linear, 38626bb2f3STao Ren .format[PSC_FAN] = linear, 39626bb2f3STao Ren 40626bb2f3STao Ren .func[0] = PMBUS_HAVE_VOUT | PMBUS_HAVE_STATUS_VOUT | 41626bb2f3STao Ren PMBUS_HAVE_IOUT | PMBUS_HAVE_STATUS_IOUT | 42626bb2f3STao Ren PMBUS_HAVE_POUT | 43626bb2f3STao Ren PMBUS_HAVE_VIN | PMBUS_HAVE_IIN | 44626bb2f3STao Ren PMBUS_HAVE_PIN | PMBUS_HAVE_STATUS_INPUT | 45626bb2f3STao Ren PMBUS_HAVE_TEMP | PMBUS_HAVE_TEMP2 | 46626bb2f3STao Ren PMBUS_HAVE_STATUS_TEMP | 47626bb2f3STao Ren PMBUS_HAVE_FAN12, 48626bb2f3STao Ren }, 49626bb2f3STao Ren 50626bb2f3STao Ren [pfe3000] = { 51626bb2f3STao Ren .pages = 7, 52626bb2f3STao Ren .format[PSC_VOLTAGE_IN] = linear, 53626bb2f3STao Ren .format[PSC_VOLTAGE_OUT] = linear, 54626bb2f3STao Ren .format[PSC_CURRENT_IN] = linear, 55626bb2f3STao Ren .format[PSC_CURRENT_OUT] = linear, 56626bb2f3STao Ren .format[PSC_POWER] = linear, 57626bb2f3STao Ren .format[PSC_TEMPERATURE] = linear, 58626bb2f3STao Ren .format[PSC_FAN] = linear, 59626bb2f3STao Ren 60626bb2f3STao Ren /* Page 0: V1. */ 61626bb2f3STao Ren .func[0] = PMBUS_HAVE_VOUT | PMBUS_HAVE_STATUS_VOUT | 62626bb2f3STao Ren PMBUS_HAVE_IOUT | PMBUS_HAVE_STATUS_IOUT | 63626bb2f3STao Ren PMBUS_HAVE_POUT | PMBUS_HAVE_FAN12 | 64626bb2f3STao Ren PMBUS_HAVE_VIN | PMBUS_HAVE_IIN | 65626bb2f3STao Ren PMBUS_HAVE_PIN | PMBUS_HAVE_STATUS_INPUT | 66626bb2f3STao Ren PMBUS_HAVE_TEMP | PMBUS_HAVE_TEMP2 | 67626bb2f3STao Ren PMBUS_HAVE_TEMP3 | PMBUS_HAVE_STATUS_TEMP | 68626bb2f3STao Ren PMBUS_HAVE_VCAP, 69626bb2f3STao Ren 70626bb2f3STao Ren /* Page 1: Vsb. */ 71626bb2f3STao Ren .func[1] = PMBUS_HAVE_VOUT | PMBUS_HAVE_STATUS_VOUT | 72626bb2f3STao Ren PMBUS_HAVE_IOUT | PMBUS_HAVE_STATUS_IOUT | 73626bb2f3STao Ren PMBUS_HAVE_PIN | PMBUS_HAVE_STATUS_INPUT | 74626bb2f3STao Ren PMBUS_HAVE_POUT, 75626bb2f3STao Ren 76626bb2f3STao Ren /* 77626bb2f3STao Ren * Page 2: V1 Ishare. 78626bb2f3STao Ren * Page 3: Reserved. 79626bb2f3STao Ren * Page 4: V1 Cathode. 80626bb2f3STao Ren * Page 5: Vsb Cathode. 81626bb2f3STao Ren * Page 6: V1 Sense. 82626bb2f3STao Ren */ 83626bb2f3STao Ren .func[2] = PMBUS_HAVE_VOUT, 84626bb2f3STao Ren .func[4] = PMBUS_HAVE_VOUT, 85626bb2f3STao Ren .func[5] = PMBUS_HAVE_VOUT, 86626bb2f3STao Ren .func[6] = PMBUS_HAVE_VOUT, 87626bb2f3STao Ren }, 88626bb2f3STao Ren }; 89626bb2f3STao Ren 90*dd431939SStephen Kitt static const struct i2c_device_id pfe_device_id[]; 91*dd431939SStephen Kitt 92*dd431939SStephen Kitt static int pfe_pmbus_probe(struct i2c_client *client) 93626bb2f3STao Ren { 94626bb2f3STao Ren int model; 95626bb2f3STao Ren 96*dd431939SStephen Kitt model = (int)i2c_match_id(pfe_device_id, client)->driver_data; 97626bb2f3STao Ren 98626bb2f3STao Ren /* 99626bb2f3STao Ren * PFE3000-12-069RA devices may not stay in page 0 during device 100626bb2f3STao Ren * probe which leads to probe failure (read status word failed). 101626bb2f3STao Ren * So let's set the device to page 0 at the beginning. 102626bb2f3STao Ren */ 103626bb2f3STao Ren if (model == pfe3000) { 104626bb2f3STao Ren client->dev.platform_data = &pfe3000_plat_data; 105626bb2f3STao Ren i2c_smbus_write_byte_data(client, PMBUS_PAGE, 0); 106626bb2f3STao Ren } 107626bb2f3STao Ren 108*dd431939SStephen Kitt return pmbus_do_probe(client, &pfe_driver_info[model]); 109626bb2f3STao Ren } 110626bb2f3STao Ren 111626bb2f3STao Ren static const struct i2c_device_id pfe_device_id[] = { 112626bb2f3STao Ren {"pfe1100", pfe1100}, 113626bb2f3STao Ren {"pfe3000", pfe3000}, 114626bb2f3STao Ren {} 115626bb2f3STao Ren }; 116626bb2f3STao Ren 117626bb2f3STao Ren MODULE_DEVICE_TABLE(i2c, pfe_device_id); 118626bb2f3STao Ren 119626bb2f3STao Ren static struct i2c_driver pfe_pmbus_driver = { 120626bb2f3STao Ren .driver = { 121626bb2f3STao Ren .name = "bel-pfe", 122626bb2f3STao Ren }, 123*dd431939SStephen Kitt .probe_new = pfe_pmbus_probe, 124626bb2f3STao Ren .remove = pmbus_do_remove, 125626bb2f3STao Ren .id_table = pfe_device_id, 126626bb2f3STao Ren }; 127626bb2f3STao Ren 128626bb2f3STao Ren module_i2c_driver(pfe_pmbus_driver); 129626bb2f3STao Ren 130626bb2f3STao Ren MODULE_AUTHOR("Tao Ren <rentao.bupt@gmail.com>"); 131626bb2f3STao Ren MODULE_DESCRIPTION("PMBus driver for BEL PFE Family Power Supplies"); 132626bb2f3STao Ren MODULE_LICENSE("GPL"); 133