1 // SPDX-License-Identifier: GPL-2.0-or-later
3 * Copyright 2023 IBM Corp.
6 #include <linux/debugfs.h>
7 #include <linux/device.h>
10 #include <linux/minmax.h>
11 #include <linux/module.h>
12 #include <linux/pmbus.h>
13 #include <linux/hwmon-sysfs.h>
16 #define ACBEL_MFR_FW_REVISION 0xd9
18 static ssize_t acbel_fsg032_debugfs_read(struct file *file, char __user *buf, size_t count,
21 struct i2c_client *client = file->private_data;
22 u8 data[I2C_SMBUS_BLOCK_MAX + 2] = { 0 };
26 rc = i2c_smbus_read_block_data(client, ACBEL_MFR_FW_REVISION, data);
30 rc = snprintf(out, sizeof(out), "%*phN\n", min(rc, 3), data);
31 return simple_read_from_buffer(buf, count, ppos, out, rc);
34 static const struct file_operations acbel_debugfs_ops = {
35 .llseek = noop_llseek,
36 .read = acbel_fsg032_debugfs_read,
41 static void acbel_fsg032_init_debugfs(struct i2c_client *client)
43 struct dentry *debugfs = pmbus_get_debugfs_dir(client);
48 debugfs_create_file("fw_version", 0444, debugfs, client, &acbel_debugfs_ops);
51 static const struct i2c_device_id acbel_fsg032_id[] = {
56 static struct pmbus_driver_info acbel_fsg032_info = {
58 .func[0] = PMBUS_HAVE_VIN | PMBUS_HAVE_IIN | PMBUS_HAVE_PIN |
59 PMBUS_HAVE_VOUT | PMBUS_HAVE_IOUT | PMBUS_HAVE_POUT |
60 PMBUS_HAVE_TEMP | PMBUS_HAVE_TEMP2 | PMBUS_HAVE_TEMP3 |
61 PMBUS_HAVE_FAN12 | PMBUS_HAVE_STATUS_VOUT |
62 PMBUS_HAVE_STATUS_IOUT | PMBUS_HAVE_STATUS_TEMP |
63 PMBUS_HAVE_STATUS_INPUT | PMBUS_HAVE_STATUS_FAN12,
66 static int acbel_fsg032_probe(struct i2c_client *client)
68 u8 buf[I2C_SMBUS_BLOCK_MAX + 1];
69 struct device *dev = &client->dev;
72 rc = i2c_smbus_read_block_data(client, PMBUS_MFR_ID, buf);
74 dev_err(dev, "Failed to read PMBUS_MFR_ID\n");
77 if (strncmp(buf, "ACBEL", 5)) {
79 dev_err(dev, "Manufacturer '%s' not supported\n", buf);
83 rc = i2c_smbus_read_block_data(client, PMBUS_MFR_MODEL, buf);
85 dev_err(dev, "Failed to read PMBUS_MFR_MODEL\n");
89 if (strncmp(buf, "FSG032", 6)) {
91 dev_err(dev, "Model '%s' not supported\n", buf);
95 rc = pmbus_do_probe(client, &acbel_fsg032_info);
99 acbel_fsg032_init_debugfs(client);
103 static const struct of_device_id acbel_fsg032_of_match[] = {
104 { .compatible = "acbel,fsg032" },
107 MODULE_DEVICE_TABLE(of, acbel_fsg032_of_match);
109 static struct i2c_driver acbel_fsg032_driver = {
111 .name = "acbel-fsg032",
112 .of_match_table = acbel_fsg032_of_match,
114 .probe = acbel_fsg032_probe,
115 .id_table = acbel_fsg032_id,
118 module_i2c_driver(acbel_fsg032_driver);
120 MODULE_AUTHOR("Lakshmi Yadlapati");
121 MODULE_DESCRIPTION("PMBus driver for AcBel Power System power supplies");
122 MODULE_LICENSE("GPL");
123 MODULE_IMPORT_NS("PMBUS");