1 // SPDX-License-Identifier: GPL-2.0-or-later
3 * Driver for Delta DPS920AB PSU
5 * Copyright (C) 2021 Delta Networks, Inc.
6 * Copyright (C) 2021 Sartura Ltd.
9 #include <linux/debugfs.h>
10 #include <linux/i2c.h>
11 #include <linux/module.h>
12 #include <linux/of_device.h>
15 struct dps920ab_data {
20 static int dps920ab_read_word_data(struct i2c_client *client, int page, int phase, int reg)
23 * This masks commands which are not supported.
24 * PSU advertises that all features are supported,
25 * in reality that unfortunately is not true.
26 * So enable only those that the datasheet confirms.
29 case PMBUS_FAN_COMMAND_1:
30 case PMBUS_IOUT_OC_WARN_LIMIT:
31 case PMBUS_STATUS_WORD:
36 case PMBUS_READ_TEMPERATURE_1:
37 case PMBUS_READ_TEMPERATURE_2:
38 case PMBUS_READ_TEMPERATURE_3:
39 case PMBUS_READ_FAN_SPEED_1:
42 case PMBUS_MFR_VOUT_MIN:
43 case PMBUS_MFR_VOUT_MAX:
44 case PMBUS_MFR_IOUT_MAX:
45 case PMBUS_MFR_POUT_MAX:
46 return pmbus_read_word_data(client, page, phase, reg);
52 static int dps920ab_write_word_data(struct i2c_client *client, int page, int reg,
56 * This masks commands which are not supported.
57 * PSU only has one R/W register and that is
61 case PMBUS_FAN_COMMAND_1:
62 return pmbus_write_word_data(client, page, reg, word);
68 static struct pmbus_driver_info dps920ab_info = {
71 .format[PSC_VOLTAGE_IN] = linear,
72 .format[PSC_VOLTAGE_OUT] = linear,
73 .format[PSC_CURRENT_IN] = linear,
74 .format[PSC_CURRENT_OUT] = linear,
75 .format[PSC_POWER] = linear,
76 .format[PSC_FAN] = linear,
77 .format[PSC_TEMPERATURE] = linear,
80 PMBUS_HAVE_VIN | PMBUS_HAVE_IIN | PMBUS_HAVE_PIN |
81 PMBUS_HAVE_VOUT | PMBUS_HAVE_IOUT | PMBUS_HAVE_POUT |
82 PMBUS_HAVE_TEMP | PMBUS_HAVE_TEMP2 | PMBUS_HAVE_TEMP3 |
83 PMBUS_HAVE_FAN12 | PMBUS_HAVE_STATUS_FAN12 |
84 PMBUS_HAVE_STATUS_VOUT | PMBUS_HAVE_STATUS_IOUT |
85 PMBUS_HAVE_STATUS_INPUT | PMBUS_HAVE_STATUS_TEMP,
86 .read_word_data = dps920ab_read_word_data,
87 .write_word_data = dps920ab_write_word_data,
90 static int dps920ab_mfr_id_show(struct seq_file *s, void *data)
92 struct dps920ab_data *priv = s->private;
94 seq_printf(s, "%s\n", priv->mfr_id);
99 DEFINE_SHOW_ATTRIBUTE(dps920ab_mfr_id);
101 static int dps920ab_mfr_model_show(struct seq_file *s, void *data)
103 struct dps920ab_data *priv = s->private;
105 seq_printf(s, "%s\n", priv->mfr_model);
110 DEFINE_SHOW_ATTRIBUTE(dps920ab_mfr_model);
112 static void dps920ab_init_debugfs(struct dps920ab_data *data, struct i2c_client *client)
114 struct dentry *debugfs_dir;
117 root = pmbus_get_debugfs_dir(client);
121 debugfs_dir = debugfs_create_dir(client->name, root);
123 debugfs_create_file("mfr_id",
127 &dps920ab_mfr_id_fops);
129 debugfs_create_file("mfr_model",
133 &dps920ab_mfr_model_fops);
136 static int dps920ab_probe(struct i2c_client *client)
138 u8 buf[I2C_SMBUS_BLOCK_MAX + 1];
139 struct dps920ab_data *data;
142 data = devm_kzalloc(&client->dev, sizeof(*data), GFP_KERNEL);
146 ret = i2c_smbus_read_block_data(client, PMBUS_MFR_ID, buf);
148 dev_err(&client->dev, "Failed to read Manufacturer ID\n");
153 if (ret != 5 || strncmp(buf, "DELTA", 5)) {
155 dev_err(&client->dev, "Unsupported Manufacturer ID '%s'\n", buf);
158 data->mfr_id = devm_kstrdup(&client->dev, buf, GFP_KERNEL);
162 ret = i2c_smbus_read_block_data(client, PMBUS_MFR_MODEL, buf);
164 dev_err(&client->dev, "Failed to read Manufacturer Model\n");
169 if (ret != 11 || strncmp(buf, "DPS-920AB", 9)) {
170 dev_err(&client->dev, "Unsupported Manufacturer Model '%s'\n", buf);
173 data->mfr_model = devm_kstrdup(&client->dev, buf, GFP_KERNEL);
174 if (!data->mfr_model)
177 ret = pmbus_do_probe(client, &dps920ab_info);
181 dps920ab_init_debugfs(data, client);
186 static const struct of_device_id __maybe_unused dps920ab_of_match[] = {
187 { .compatible = "delta,dps920ab", },
191 MODULE_DEVICE_TABLE(of, dps920ab_of_match);
193 static struct i2c_driver dps920ab_driver = {
196 .of_match_table = of_match_ptr(dps920ab_of_match),
198 .probe_new = dps920ab_probe,
201 module_i2c_driver(dps920ab_driver);
204 MODULE_DESCRIPTION("PMBus driver for Delta DPS920AB PSU");
205 MODULE_LICENSE("GPL");
206 MODULE_IMPORT_NS(PMBUS);