This source file includes following definitions.
- pmbus_find_sensor_groups
- pmbus_identify
- pmbus_probe
1
2
3
4
5
6
7
8 #include <linux/kernel.h>
9 #include <linux/module.h>
10 #include <linux/init.h>
11 #include <linux/err.h>
12 #include <linux/slab.h>
13 #include <linux/mutex.h>
14 #include <linux/i2c.h>
15 #include <linux/pmbus.h>
16 #include "pmbus.h"
17
18 struct pmbus_device_info {
19 int pages;
20 u32 flags;
21 };
22
23
24
25
26 static void pmbus_find_sensor_groups(struct i2c_client *client,
27 struct pmbus_driver_info *info)
28 {
29 int page;
30
31
32 if (pmbus_check_word_register(client, 0, PMBUS_READ_VIN))
33 info->func[0] |= PMBUS_HAVE_VIN;
34 if (pmbus_check_word_register(client, 0, PMBUS_READ_VCAP))
35 info->func[0] |= PMBUS_HAVE_VCAP;
36 if (pmbus_check_word_register(client, 0, PMBUS_READ_IIN))
37 info->func[0] |= PMBUS_HAVE_IIN;
38 if (pmbus_check_word_register(client, 0, PMBUS_READ_PIN))
39 info->func[0] |= PMBUS_HAVE_PIN;
40 if (info->func[0]
41 && pmbus_check_byte_register(client, 0, PMBUS_STATUS_INPUT))
42 info->func[0] |= PMBUS_HAVE_STATUS_INPUT;
43 if (pmbus_check_byte_register(client, 0, PMBUS_FAN_CONFIG_12) &&
44 pmbus_check_word_register(client, 0, PMBUS_READ_FAN_SPEED_1)) {
45 info->func[0] |= PMBUS_HAVE_FAN12;
46 if (pmbus_check_byte_register(client, 0, PMBUS_STATUS_FAN_12))
47 info->func[0] |= PMBUS_HAVE_STATUS_FAN12;
48 }
49 if (pmbus_check_byte_register(client, 0, PMBUS_FAN_CONFIG_34) &&
50 pmbus_check_word_register(client, 0, PMBUS_READ_FAN_SPEED_3)) {
51 info->func[0] |= PMBUS_HAVE_FAN34;
52 if (pmbus_check_byte_register(client, 0, PMBUS_STATUS_FAN_34))
53 info->func[0] |= PMBUS_HAVE_STATUS_FAN34;
54 }
55 if (pmbus_check_word_register(client, 0, PMBUS_READ_TEMPERATURE_1))
56 info->func[0] |= PMBUS_HAVE_TEMP;
57 if (pmbus_check_word_register(client, 0, PMBUS_READ_TEMPERATURE_2))
58 info->func[0] |= PMBUS_HAVE_TEMP2;
59 if (pmbus_check_word_register(client, 0, PMBUS_READ_TEMPERATURE_3))
60 info->func[0] |= PMBUS_HAVE_TEMP3;
61 if (info->func[0] & (PMBUS_HAVE_TEMP | PMBUS_HAVE_TEMP2
62 | PMBUS_HAVE_TEMP3)
63 && pmbus_check_byte_register(client, 0,
64 PMBUS_STATUS_TEMPERATURE))
65 info->func[0] |= PMBUS_HAVE_STATUS_TEMP;
66
67
68 for (page = 0; page < info->pages; page++) {
69 if (pmbus_check_word_register(client, page, PMBUS_READ_VOUT)) {
70 info->func[page] |= PMBUS_HAVE_VOUT;
71 if (pmbus_check_byte_register(client, page,
72 PMBUS_STATUS_VOUT))
73 info->func[page] |= PMBUS_HAVE_STATUS_VOUT;
74 }
75 if (pmbus_check_word_register(client, page, PMBUS_READ_IOUT)) {
76 info->func[page] |= PMBUS_HAVE_IOUT;
77 if (pmbus_check_byte_register(client, 0,
78 PMBUS_STATUS_IOUT))
79 info->func[page] |= PMBUS_HAVE_STATUS_IOUT;
80 }
81 if (pmbus_check_word_register(client, page, PMBUS_READ_POUT))
82 info->func[page] |= PMBUS_HAVE_POUT;
83 }
84 }
85
86
87
88
89 static int pmbus_identify(struct i2c_client *client,
90 struct pmbus_driver_info *info)
91 {
92 int ret = 0;
93
94 if (!info->pages) {
95
96
97
98
99
100
101 if (pmbus_check_byte_register(client, 0, PMBUS_PAGE)) {
102 int page;
103
104 for (page = 1; page < PMBUS_PAGES; page++) {
105 if (pmbus_set_page(client, page) < 0)
106 break;
107 }
108 pmbus_set_page(client, 0);
109 info->pages = page;
110 } else {
111 info->pages = 1;
112 }
113
114 pmbus_clear_faults(client);
115 }
116
117 if (pmbus_check_byte_register(client, 0, PMBUS_VOUT_MODE)) {
118 int vout_mode;
119
120 vout_mode = pmbus_read_byte_data(client, 0, PMBUS_VOUT_MODE);
121 if (vout_mode >= 0 && vout_mode != 0xff) {
122 switch (vout_mode >> 5) {
123 case 0:
124 break;
125 case 1:
126 info->format[PSC_VOLTAGE_OUT] = vid;
127 info->vrm_version = vr11;
128 break;
129 case 2:
130 info->format[PSC_VOLTAGE_OUT] = direct;
131 break;
132 default:
133 ret = -ENODEV;
134 goto abort;
135 }
136 }
137 }
138
139
140
141
142
143
144
145
146
147
148
149
150 if (info->format[PSC_VOLTAGE_OUT] == direct) {
151 ret = -ENODEV;
152 goto abort;
153 }
154
155
156 pmbus_find_sensor_groups(client, info);
157 abort:
158 return ret;
159 }
160
161 static int pmbus_probe(struct i2c_client *client,
162 const struct i2c_device_id *id)
163 {
164 struct pmbus_driver_info *info;
165 struct pmbus_platform_data *pdata = NULL;
166 struct device *dev = &client->dev;
167 struct pmbus_device_info *device_info;
168
169 info = devm_kzalloc(dev, sizeof(struct pmbus_driver_info), GFP_KERNEL);
170 if (!info)
171 return -ENOMEM;
172
173 device_info = (struct pmbus_device_info *)id->driver_data;
174 if (device_info->flags & PMBUS_SKIP_STATUS_CHECK) {
175 pdata = devm_kzalloc(dev, sizeof(struct pmbus_platform_data),
176 GFP_KERNEL);
177 if (!pdata)
178 return -ENOMEM;
179
180 pdata->flags = PMBUS_SKIP_STATUS_CHECK;
181 }
182
183 info->pages = device_info->pages;
184 info->identify = pmbus_identify;
185 dev->platform_data = pdata;
186
187 return pmbus_do_probe(client, id, info);
188 }
189
190 static const struct pmbus_device_info pmbus_info_one = {
191 .pages = 1,
192 .flags = 0
193 };
194 static const struct pmbus_device_info pmbus_info_zero = {
195 .pages = 0,
196 .flags = 0
197 };
198 static const struct pmbus_device_info pmbus_info_one_skip = {
199 .pages = 1,
200 .flags = PMBUS_SKIP_STATUS_CHECK
201 };
202
203
204
205
206 static const struct i2c_device_id pmbus_id[] = {
207 {"adp4000", (kernel_ulong_t)&pmbus_info_one},
208 {"bmr453", (kernel_ulong_t)&pmbus_info_one},
209 {"bmr454", (kernel_ulong_t)&pmbus_info_one},
210 {"dps460", (kernel_ulong_t)&pmbus_info_one_skip},
211 {"dps650ab", (kernel_ulong_t)&pmbus_info_one_skip},
212 {"dps800", (kernel_ulong_t)&pmbus_info_one_skip},
213 {"mdt040", (kernel_ulong_t)&pmbus_info_one},
214 {"ncp4200", (kernel_ulong_t)&pmbus_info_one},
215 {"ncp4208", (kernel_ulong_t)&pmbus_info_one},
216 {"pdt003", (kernel_ulong_t)&pmbus_info_one},
217 {"pdt006", (kernel_ulong_t)&pmbus_info_one},
218 {"pdt012", (kernel_ulong_t)&pmbus_info_one},
219 {"pmbus", (kernel_ulong_t)&pmbus_info_zero},
220 {"sgd009", (kernel_ulong_t)&pmbus_info_one_skip},
221 {"tps40400", (kernel_ulong_t)&pmbus_info_one},
222 {"tps544b20", (kernel_ulong_t)&pmbus_info_one},
223 {"tps544b25", (kernel_ulong_t)&pmbus_info_one},
224 {"tps544c20", (kernel_ulong_t)&pmbus_info_one},
225 {"tps544c25", (kernel_ulong_t)&pmbus_info_one},
226 {"udt020", (kernel_ulong_t)&pmbus_info_one},
227 {}
228 };
229
230 MODULE_DEVICE_TABLE(i2c, pmbus_id);
231
232
233 static struct i2c_driver pmbus_driver = {
234 .driver = {
235 .name = "pmbus",
236 },
237 .probe = pmbus_probe,
238 .remove = pmbus_do_remove,
239 .id_table = pmbus_id,
240 };
241
242 module_i2c_driver(pmbus_driver);
243
244 MODULE_AUTHOR("Guenter Roeck");
245 MODULE_DESCRIPTION("Generic PMBus driver");
246 MODULE_LICENSE("GPL");