1 // SPDX-License-Identifier: GPL-2.0-or-later 2 /* 3 * Copyright 2023 IBM Corp. 4 */ 5 6 #include <linux/device.h> 7 #include <linux/fs.h> 8 #include <linux/i2c.h> 9 #include <linux/module.h> 10 #include <linux/pmbus.h> 11 #include <linux/hwmon-sysfs.h> 12 #include "pmbus.h" 13 14 static const struct i2c_device_id acbel_fsg032_id[] = { 15 { "acbel_fsg032" }, 16 {} 17 }; 18 19 static struct pmbus_driver_info acbel_fsg032_info = { 20 .pages = 1, 21 .func[0] = PMBUS_HAVE_VIN | PMBUS_HAVE_IIN | PMBUS_HAVE_PIN | 22 PMBUS_HAVE_VOUT | PMBUS_HAVE_IOUT | PMBUS_HAVE_POUT | 23 PMBUS_HAVE_TEMP | PMBUS_HAVE_TEMP2 | PMBUS_HAVE_TEMP3 | 24 PMBUS_HAVE_FAN12 | PMBUS_HAVE_STATUS_VOUT | 25 PMBUS_HAVE_STATUS_IOUT | PMBUS_HAVE_STATUS_TEMP | 26 PMBUS_HAVE_STATUS_INPUT | PMBUS_HAVE_STATUS_FAN12, 27 }; 28 29 static int acbel_fsg032_probe(struct i2c_client *client) 30 { 31 u8 buf[I2C_SMBUS_BLOCK_MAX + 1]; 32 struct device *dev = &client->dev; 33 int rc; 34 35 rc = i2c_smbus_read_block_data(client, PMBUS_MFR_ID, buf); 36 if (rc < 0) { 37 dev_err(dev, "Failed to read PMBUS_MFR_ID\n"); 38 return rc; 39 } 40 if (strncmp(buf, "ACBEL", 5)) { 41 buf[rc] = '\0'; 42 dev_err(dev, "Manufacturer '%s' not supported\n", buf); 43 return -ENODEV; 44 } 45 46 rc = i2c_smbus_read_block_data(client, PMBUS_MFR_MODEL, buf); 47 if (rc < 0) { 48 dev_err(dev, "Failed to read PMBUS_MFR_MODEL\n"); 49 return rc; 50 } 51 52 if (strncmp(buf, "FSG032", 6)) { 53 buf[rc] = '\0'; 54 dev_err(dev, "Model '%s' not supported\n", buf); 55 return -ENODEV; 56 } 57 58 rc = pmbus_do_probe(client, &acbel_fsg032_info); 59 if (rc) 60 return rc; 61 62 return 0; 63 } 64 65 static const struct of_device_id acbel_fsg032_of_match[] = { 66 { .compatible = "acbel,fsg032" }, 67 {} 68 }; 69 MODULE_DEVICE_TABLE(of, acbel_fsg032_of_match); 70 71 static struct i2c_driver acbel_fsg032_driver = { 72 .driver = { 73 .name = "acbel-fsg032", 74 .of_match_table = acbel_fsg032_of_match, 75 }, 76 .probe = acbel_fsg032_probe, 77 .id_table = acbel_fsg032_id, 78 }; 79 80 module_i2c_driver(acbel_fsg032_driver); 81 82 MODULE_AUTHOR("Lakshmi Yadlapati"); 83 MODULE_DESCRIPTION("PMBus driver for AcBel Power System power supplies"); 84 MODULE_LICENSE("GPL"); 85 MODULE_IMPORT_NS(PMBUS); 86