Merge tag 'clk-fixes-for-linus' of git://git.kernel.org/pub/scm/linux/kernel/git...
[linux.git] / drivers / hwmon / pmbus / acbel-fsg032.c
blob9f07fb4abaffd44834f3861f7e1d3780e48c5c0c
1 // SPDX-License-Identifier: GPL-2.0-or-later
2 /*
3 * Copyright 2023 IBM Corp.
4 */
6 #include <linux/debugfs.h>
7 #include <linux/device.h>
8 #include <linux/fs.h>
9 #include <linux/i2c.h>
10 #include <linux/minmax.h>
11 #include <linux/module.h>
12 #include <linux/pmbus.h>
13 #include <linux/hwmon-sysfs.h>
14 #include "pmbus.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,
19 loff_t *ppos)
21 struct i2c_client *client = file->private_data;
22 u8 data[I2C_SMBUS_BLOCK_MAX + 2] = { 0 };
23 char out[8];
24 int rc;
26 rc = i2c_smbus_read_block_data(client, ACBEL_MFR_FW_REVISION, data);
27 if (rc < 0)
28 return rc;
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,
37 .write = NULL,
38 .open = simple_open,
41 static void acbel_fsg032_init_debugfs(struct i2c_client *client)
43 struct dentry *debugfs = pmbus_get_debugfs_dir(client);
45 if (!debugfs)
46 return;
48 debugfs_create_file("fw_version", 0444, debugfs, client, &acbel_debugfs_ops);
51 static const struct i2c_device_id acbel_fsg032_id[] = {
52 { "acbel_fsg032" },
56 static struct pmbus_driver_info acbel_fsg032_info = {
57 .pages = 1,
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;
70 int rc;
72 rc = i2c_smbus_read_block_data(client, PMBUS_MFR_ID, buf);
73 if (rc < 0) {
74 dev_err(dev, "Failed to read PMBUS_MFR_ID\n");
75 return rc;
77 if (strncmp(buf, "ACBEL", 5)) {
78 buf[rc] = '\0';
79 dev_err(dev, "Manufacturer '%s' not supported\n", buf);
80 return -ENODEV;
83 rc = i2c_smbus_read_block_data(client, PMBUS_MFR_MODEL, buf);
84 if (rc < 0) {
85 dev_err(dev, "Failed to read PMBUS_MFR_MODEL\n");
86 return rc;
89 if (strncmp(buf, "FSG032", 6)) {
90 buf[rc] = '\0';
91 dev_err(dev, "Model '%s' not supported\n", buf);
92 return -ENODEV;
95 rc = pmbus_do_probe(client, &acbel_fsg032_info);
96 if (rc)
97 return rc;
99 acbel_fsg032_init_debugfs(client);
100 return 0;
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 = {
110 .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");