]>
Commit | Line | Data |
---|---|---|
c942fddf | 1 | // SPDX-License-Identifier: GPL-2.0-or-later |
83f7649c GR |
2 | /* |
3 | * Hardware monitoring driver for Analog Devices ADM1275 Hot-Swap Controller | |
4 | * and Digital Power Monitor | |
5 | * | |
6 | * Copyright (c) 2011 Ericsson AB. | |
4ff0ce22 | 7 | * Copyright (c) 2018 Guenter Roeck |
83f7649c GR |
8 | */ |
9 | ||
10 | #include <linux/kernel.h> | |
11 | #include <linux/module.h> | |
12 | #include <linux/init.h> | |
13 | #include <linux/err.h> | |
14 | #include <linux/slab.h> | |
15 | #include <linux/i2c.h> | |
99b41608 | 16 | #include <linux/bitops.h> |
83f7649c GR |
17 | #include "pmbus.h" |
18 | ||
4ff0ce22 | 19 | enum chips { adm1075, adm1272, adm1275, adm1276, adm1278, adm1293, adm1294 }; |
68a40382 GR |
20 | |
21 | #define ADM1275_MFR_STATUS_IOUT_WARN2 BIT(0) | |
22 | #define ADM1293_MFR_STATUS_VAUX_UV_WARN BIT(5) | |
23 | #define ADM1293_MFR_STATUS_VAUX_OV_WARN BIT(6) | |
5cf231a3 | 24 | |
c576e30c GR |
25 | #define ADM1275_PEAK_IOUT 0xd0 |
26 | #define ADM1275_PEAK_VIN 0xd1 | |
27 | #define ADM1275_PEAK_VOUT 0xd2 | |
83f7649c GR |
28 | #define ADM1275_PMON_CONFIG 0xd4 |
29 | ||
99b41608 GR |
30 | #define ADM1275_VIN_VOUT_SELECT BIT(6) |
31 | #define ADM1275_VRANGE BIT(5) | |
32 | #define ADM1075_IRANGE_50 BIT(4) | |
33 | #define ADM1075_IRANGE_25 BIT(3) | |
34 | #define ADM1075_IRANGE_MASK (BIT(3) | BIT(4)) | |
83f7649c | 35 | |
4ff0ce22 GR |
36 | #define ADM1272_IRANGE BIT(0) |
37 | ||
709066ac GR |
38 | #define ADM1278_TEMP1_EN BIT(3) |
39 | #define ADM1278_VIN_EN BIT(2) | |
40 | #define ADM1278_VOUT_EN BIT(1) | |
41 | ||
68a40382 GR |
42 | #define ADM1293_IRANGE_25 0 |
43 | #define ADM1293_IRANGE_50 BIT(6) | |
44 | #define ADM1293_IRANGE_100 BIT(7) | |
45 | #define ADM1293_IRANGE_200 (BIT(6) | BIT(7)) | |
46 | #define ADM1293_IRANGE_MASK (BIT(6) | BIT(7)) | |
47 | ||
48 | #define ADM1293_VIN_SEL_012 BIT(2) | |
49 | #define ADM1293_VIN_SEL_074 BIT(3) | |
50 | #define ADM1293_VIN_SEL_210 (BIT(2) | BIT(3)) | |
51 | #define ADM1293_VIN_SEL_MASK (BIT(2) | BIT(3)) | |
52 | ||
53 | #define ADM1293_VAUX_EN BIT(1) | |
54 | ||
709066ac | 55 | #define ADM1278_PEAK_TEMP 0xd7 |
c5e67636 GR |
56 | #define ADM1275_IOUT_WARN2_LIMIT 0xd7 |
57 | #define ADM1275_DEVICE_CONFIG 0xd8 | |
58 | ||
99b41608 | 59 | #define ADM1275_IOUT_WARN2_SELECT BIT(4) |
c5e67636 | 60 | |
5cf231a3 | 61 | #define ADM1276_PEAK_PIN 0xda |
92711269 GR |
62 | #define ADM1075_READ_VAUX 0xdd |
63 | #define ADM1075_VAUX_OV_WARN_LIMIT 0xde | |
64 | #define ADM1075_VAUX_UV_WARN_LIMIT 0xdf | |
68a40382 GR |
65 | #define ADM1293_IOUT_MIN 0xe3 |
66 | #define ADM1293_PIN_MIN 0xe4 | |
92711269 GR |
67 | #define ADM1075_VAUX_STATUS 0xf6 |
68 | ||
99b41608 GR |
69 | #define ADM1075_VAUX_OV_WARN BIT(7) |
70 | #define ADM1075_VAUX_UV_WARN BIT(6) | |
92711269 | 71 | |
c5e67636 | 72 | struct adm1275_data { |
5cf231a3 | 73 | int id; |
c5e67636 | 74 | bool have_oc_fault; |
9048539b GR |
75 | bool have_uc_fault; |
76 | bool have_vout; | |
77 | bool have_vaux_status; | |
68a40382 GR |
78 | bool have_mfr_vaux_status; |
79 | bool have_iout_min; | |
80 | bool have_pin_min; | |
9048539b | 81 | bool have_pin_max; |
709066ac | 82 | bool have_temp_max; |
c5e67636 GR |
83 | struct pmbus_driver_info info; |
84 | }; | |
85 | ||
86 | #define to_adm1275_data(x) container_of(x, struct adm1275_data, info) | |
87 | ||
904b296f GR |
88 | struct coefficients { |
89 | s16 m; | |
90 | s16 b; | |
91 | s16 R; | |
92 | }; | |
93 | ||
94 | static const struct coefficients adm1075_coefficients[] = { | |
95 | [0] = { 27169, 0, -1 }, /* voltage */ | |
96 | [1] = { 806, 20475, -1 }, /* current, irange25 */ | |
97 | [2] = { 404, 20475, -1 }, /* current, irange50 */ | |
6faecba0 SD |
98 | [3] = { 8549, 0, -1 }, /* power, irange25 */ |
99 | [4] = { 4279, 0, -1 }, /* power, irange50 */ | |
904b296f GR |
100 | }; |
101 | ||
4ff0ce22 GR |
102 | static const struct coefficients adm1272_coefficients[] = { |
103 | [0] = { 6770, 0, -2 }, /* voltage, vrange 60V */ | |
104 | [1] = { 4062, 0, -2 }, /* voltage, vrange 100V */ | |
105 | [2] = { 1326, 20480, -1 }, /* current, vsense range 15mV */ | |
106 | [3] = { 663, 20480, -1 }, /* current, vsense range 30mV */ | |
107 | [4] = { 3512, 0, -2 }, /* power, vrange 60V, irange 15mV */ | |
108 | [5] = { 21071, 0, -3 }, /* power, vrange 100V, irange 15mV */ | |
109 | [6] = { 17561, 0, -3 }, /* power, vrange 60V, irange 30mV */ | |
110 | [7] = { 10535, 0, -3 }, /* power, vrange 100V, irange 30mV */ | |
111 | [8] = { 42, 31871, -1 }, /* temperature */ | |
112 | ||
113 | }; | |
114 | ||
904b296f GR |
115 | static const struct coefficients adm1275_coefficients[] = { |
116 | [0] = { 19199, 0, -2 }, /* voltage, vrange set */ | |
117 | [1] = { 6720, 0, -1 }, /* voltage, vrange not set */ | |
118 | [2] = { 807, 20475, -1 }, /* current */ | |
119 | }; | |
120 | ||
121 | static const struct coefficients adm1276_coefficients[] = { | |
122 | [0] = { 19199, 0, -2 }, /* voltage, vrange set */ | |
123 | [1] = { 6720, 0, -1 }, /* voltage, vrange not set */ | |
124 | [2] = { 807, 20475, -1 }, /* current */ | |
125 | [3] = { 6043, 0, -2 }, /* power, vrange set */ | |
126 | [4] = { 2115, 0, -1 }, /* power, vrange not set */ | |
127 | }; | |
128 | ||
709066ac GR |
129 | static const struct coefficients adm1278_coefficients[] = { |
130 | [0] = { 19599, 0, -2 }, /* voltage */ | |
131 | [1] = { 800, 20475, -1 }, /* current */ | |
132 | [2] = { 6123, 0, -2 }, /* power */ | |
133 | [3] = { 42, 31880, -1 }, /* temperature */ | |
134 | }; | |
135 | ||
68a40382 GR |
136 | static const struct coefficients adm1293_coefficients[] = { |
137 | [0] = { 3333, -1, 0 }, /* voltage, vrange 1.2V */ | |
138 | [1] = { 5552, -5, -1 }, /* voltage, vrange 7.4V */ | |
139 | [2] = { 19604, -50, -2 }, /* voltage, vrange 21V */ | |
140 | [3] = { 8000, -100, -2 }, /* current, irange25 */ | |
141 | [4] = { 4000, -100, -2 }, /* current, irange50 */ | |
142 | [5] = { 20000, -1000, -3 }, /* current, irange100 */ | |
143 | [6] = { 10000, -1000, -3 }, /* current, irange200 */ | |
144 | [7] = { 10417, 0, -1 }, /* power, 1.2V, irange25 */ | |
145 | [8] = { 5208, 0, -1 }, /* power, 1.2V, irange50 */ | |
146 | [9] = { 26042, 0, -2 }, /* power, 1.2V, irange100 */ | |
147 | [10] = { 13021, 0, -2 }, /* power, 1.2V, irange200 */ | |
148 | [11] = { 17351, 0, -2 }, /* power, 7.4V, irange25 */ | |
149 | [12] = { 8676, 0, -2 }, /* power, 7.4V, irange50 */ | |
150 | [13] = { 4338, 0, -2 }, /* power, 7.4V, irange100 */ | |
151 | [14] = { 21689, 0, -3 }, /* power, 7.4V, irange200 */ | |
152 | [15] = { 6126, 0, -2 }, /* power, 21V, irange25 */ | |
153 | [16] = { 30631, 0, -3 }, /* power, 21V, irange50 */ | |
154 | [17] = { 15316, 0, -3 }, /* power, 21V, irange100 */ | |
155 | [18] = { 7658, 0, -3 }, /* power, 21V, irange200 */ | |
156 | }; | |
157 | ||
c576e30c GR |
158 | static int adm1275_read_word_data(struct i2c_client *client, int page, int reg) |
159 | { | |
c5e67636 GR |
160 | const struct pmbus_driver_info *info = pmbus_get_driver_info(client); |
161 | const struct adm1275_data *data = to_adm1275_data(info); | |
5cf231a3 | 162 | int ret = 0; |
c576e30c | 163 | |
ecb29abd | 164 | if (page > 0) |
c5e67636 | 165 | return -ENXIO; |
c576e30c GR |
166 | |
167 | switch (reg) { | |
c5e67636 | 168 | case PMBUS_IOUT_UC_FAULT_LIMIT: |
9048539b GR |
169 | if (!data->have_uc_fault) |
170 | return -ENXIO; | |
c5e67636 GR |
171 | ret = pmbus_read_word_data(client, 0, ADM1275_IOUT_WARN2_LIMIT); |
172 | break; | |
173 | case PMBUS_IOUT_OC_FAULT_LIMIT: | |
9048539b GR |
174 | if (!data->have_oc_fault) |
175 | return -ENXIO; | |
c5e67636 GR |
176 | ret = pmbus_read_word_data(client, 0, ADM1275_IOUT_WARN2_LIMIT); |
177 | break; | |
92711269 | 178 | case PMBUS_VOUT_OV_WARN_LIMIT: |
9048539b GR |
179 | if (data->have_vout) |
180 | return -ENODATA; | |
92711269 GR |
181 | ret = pmbus_read_word_data(client, 0, |
182 | ADM1075_VAUX_OV_WARN_LIMIT); | |
183 | break; | |
184 | case PMBUS_VOUT_UV_WARN_LIMIT: | |
9048539b GR |
185 | if (data->have_vout) |
186 | return -ENODATA; | |
92711269 GR |
187 | ret = pmbus_read_word_data(client, 0, |
188 | ADM1075_VAUX_UV_WARN_LIMIT); | |
189 | break; | |
190 | case PMBUS_READ_VOUT: | |
9048539b GR |
191 | if (data->have_vout) |
192 | return -ENODATA; | |
92711269 GR |
193 | ret = pmbus_read_word_data(client, 0, ADM1075_READ_VAUX); |
194 | break; | |
68a40382 GR |
195 | case PMBUS_VIRT_READ_IOUT_MIN: |
196 | if (!data->have_iout_min) | |
197 | return -ENXIO; | |
198 | ret = pmbus_read_word_data(client, 0, ADM1293_IOUT_MIN); | |
199 | break; | |
c576e30c GR |
200 | case PMBUS_VIRT_READ_IOUT_MAX: |
201 | ret = pmbus_read_word_data(client, 0, ADM1275_PEAK_IOUT); | |
202 | break; | |
203 | case PMBUS_VIRT_READ_VOUT_MAX: | |
204 | ret = pmbus_read_word_data(client, 0, ADM1275_PEAK_VOUT); | |
205 | break; | |
206 | case PMBUS_VIRT_READ_VIN_MAX: | |
207 | ret = pmbus_read_word_data(client, 0, ADM1275_PEAK_VIN); | |
208 | break; | |
68a40382 GR |
209 | case PMBUS_VIRT_READ_PIN_MIN: |
210 | if (!data->have_pin_min) | |
211 | return -ENXIO; | |
212 | ret = pmbus_read_word_data(client, 0, ADM1293_PIN_MIN); | |
213 | break; | |
5cf231a3 | 214 | case PMBUS_VIRT_READ_PIN_MAX: |
9048539b GR |
215 | if (!data->have_pin_max) |
216 | return -ENXIO; | |
5cf231a3 GR |
217 | ret = pmbus_read_word_data(client, 0, ADM1276_PEAK_PIN); |
218 | break; | |
709066ac GR |
219 | case PMBUS_VIRT_READ_TEMP_MAX: |
220 | if (!data->have_temp_max) | |
221 | return -ENXIO; | |
222 | ret = pmbus_read_word_data(client, 0, ADM1278_PEAK_TEMP); | |
223 | break; | |
c576e30c GR |
224 | case PMBUS_VIRT_RESET_IOUT_HISTORY: |
225 | case PMBUS_VIRT_RESET_VOUT_HISTORY: | |
226 | case PMBUS_VIRT_RESET_VIN_HISTORY: | |
5cf231a3 GR |
227 | break; |
228 | case PMBUS_VIRT_RESET_PIN_HISTORY: | |
9048539b GR |
229 | if (!data->have_pin_max) |
230 | return -ENXIO; | |
c576e30c | 231 | break; |
709066ac GR |
232 | case PMBUS_VIRT_RESET_TEMP_HISTORY: |
233 | if (!data->have_temp_max) | |
234 | return -ENXIO; | |
235 | break; | |
c576e30c GR |
236 | default: |
237 | ret = -ENODATA; | |
238 | break; | |
239 | } | |
240 | return ret; | |
241 | } | |
242 | ||
243 | static int adm1275_write_word_data(struct i2c_client *client, int page, int reg, | |
244 | u16 word) | |
245 | { | |
68a40382 GR |
246 | const struct pmbus_driver_info *info = pmbus_get_driver_info(client); |
247 | const struct adm1275_data *data = to_adm1275_data(info); | |
c576e30c GR |
248 | int ret; |
249 | ||
ecb29abd | 250 | if (page > 0) |
c5e67636 | 251 | return -ENXIO; |
c576e30c GR |
252 | |
253 | switch (reg) { | |
c5e67636 GR |
254 | case PMBUS_IOUT_UC_FAULT_LIMIT: |
255 | case PMBUS_IOUT_OC_FAULT_LIMIT: | |
256 | ret = pmbus_write_word_data(client, 0, ADM1275_IOUT_WARN2_LIMIT, | |
257 | word); | |
258 | break; | |
c576e30c GR |
259 | case PMBUS_VIRT_RESET_IOUT_HISTORY: |
260 | ret = pmbus_write_word_data(client, 0, ADM1275_PEAK_IOUT, 0); | |
68a40382 GR |
261 | if (!ret && data->have_iout_min) |
262 | ret = pmbus_write_word_data(client, 0, | |
263 | ADM1293_IOUT_MIN, 0); | |
c576e30c GR |
264 | break; |
265 | case PMBUS_VIRT_RESET_VOUT_HISTORY: | |
266 | ret = pmbus_write_word_data(client, 0, ADM1275_PEAK_VOUT, 0); | |
267 | break; | |
268 | case PMBUS_VIRT_RESET_VIN_HISTORY: | |
269 | ret = pmbus_write_word_data(client, 0, ADM1275_PEAK_VIN, 0); | |
270 | break; | |
5cf231a3 GR |
271 | case PMBUS_VIRT_RESET_PIN_HISTORY: |
272 | ret = pmbus_write_word_data(client, 0, ADM1276_PEAK_PIN, 0); | |
68a40382 GR |
273 | if (!ret && data->have_pin_min) |
274 | ret = pmbus_write_word_data(client, 0, | |
275 | ADM1293_PIN_MIN, 0); | |
5cf231a3 | 276 | break; |
709066ac GR |
277 | case PMBUS_VIRT_RESET_TEMP_HISTORY: |
278 | ret = pmbus_write_word_data(client, 0, ADM1278_PEAK_TEMP, 0); | |
279 | break; | |
c576e30c GR |
280 | default: |
281 | ret = -ENODATA; | |
282 | break; | |
283 | } | |
284 | return ret; | |
285 | } | |
286 | ||
c5e67636 GR |
287 | static int adm1275_read_byte_data(struct i2c_client *client, int page, int reg) |
288 | { | |
289 | const struct pmbus_driver_info *info = pmbus_get_driver_info(client); | |
290 | const struct adm1275_data *data = to_adm1275_data(info); | |
291 | int mfr_status, ret; | |
292 | ||
da8e48ab | 293 | if (page > 0) |
c5e67636 GR |
294 | return -ENXIO; |
295 | ||
296 | switch (reg) { | |
297 | case PMBUS_STATUS_IOUT: | |
298 | ret = pmbus_read_byte_data(client, page, PMBUS_STATUS_IOUT); | |
299 | if (ret < 0) | |
300 | break; | |
9048539b GR |
301 | if (!data->have_oc_fault && !data->have_uc_fault) |
302 | break; | |
c5e67636 GR |
303 | mfr_status = pmbus_read_byte_data(client, page, |
304 | PMBUS_STATUS_MFR_SPECIFIC); | |
9048539b GR |
305 | if (mfr_status < 0) |
306 | return mfr_status; | |
c5e67636 GR |
307 | if (mfr_status & ADM1275_MFR_STATUS_IOUT_WARN2) { |
308 | ret |= data->have_oc_fault ? | |
309 | PB_IOUT_OC_FAULT : PB_IOUT_UC_FAULT; | |
310 | } | |
311 | break; | |
92711269 | 312 | case PMBUS_STATUS_VOUT: |
9048539b GR |
313 | if (data->have_vout) |
314 | return -ENODATA; | |
92711269 | 315 | ret = 0; |
9048539b GR |
316 | if (data->have_vaux_status) { |
317 | mfr_status = pmbus_read_byte_data(client, 0, | |
318 | ADM1075_VAUX_STATUS); | |
319 | if (mfr_status < 0) | |
320 | return mfr_status; | |
321 | if (mfr_status & ADM1075_VAUX_OV_WARN) | |
322 | ret |= PB_VOLTAGE_OV_WARNING; | |
323 | if (mfr_status & ADM1075_VAUX_UV_WARN) | |
324 | ret |= PB_VOLTAGE_UV_WARNING; | |
68a40382 GR |
325 | } else if (data->have_mfr_vaux_status) { |
326 | mfr_status = pmbus_read_byte_data(client, page, | |
327 | PMBUS_STATUS_MFR_SPECIFIC); | |
328 | if (mfr_status < 0) | |
329 | return mfr_status; | |
330 | if (mfr_status & ADM1293_MFR_STATUS_VAUX_OV_WARN) | |
331 | ret |= PB_VOLTAGE_OV_WARNING; | |
332 | if (mfr_status & ADM1293_MFR_STATUS_VAUX_UV_WARN) | |
333 | ret |= PB_VOLTAGE_UV_WARNING; | |
9048539b | 334 | } |
92711269 | 335 | break; |
c5e67636 GR |
336 | default: |
337 | ret = -ENODATA; | |
338 | break; | |
339 | } | |
340 | return ret; | |
341 | } | |
342 | ||
87102808 | 343 | static const struct i2c_device_id adm1275_id[] = { |
92711269 | 344 | { "adm1075", adm1075 }, |
4ff0ce22 | 345 | { "adm1272", adm1272 }, |
87102808 GR |
346 | { "adm1275", adm1275 }, |
347 | { "adm1276", adm1276 }, | |
709066ac | 348 | { "adm1278", adm1278 }, |
68a40382 GR |
349 | { "adm1293", adm1293 }, |
350 | { "adm1294", adm1294 }, | |
87102808 GR |
351 | { } |
352 | }; | |
353 | MODULE_DEVICE_TABLE(i2c, adm1275_id); | |
354 | ||
83f7649c GR |
355 | static int adm1275_probe(struct i2c_client *client, |
356 | const struct i2c_device_id *id) | |
357 | { | |
87102808 | 358 | u8 block_buffer[I2C_SMBUS_BLOCK_MAX + 1]; |
c5e67636 | 359 | int config, device_config; |
3b33ca41 | 360 | int ret; |
83f7649c | 361 | struct pmbus_driver_info *info; |
c5e67636 | 362 | struct adm1275_data *data; |
87102808 | 363 | const struct i2c_device_id *mid; |
904b296f | 364 | const struct coefficients *coefficients; |
68a40382 | 365 | int vindex = -1, voindex = -1, cindex = -1, pindex = -1; |
709066ac | 366 | int tindex = -1; |
6e5c06ad | 367 | u32 shunt; |
83f7649c GR |
368 | |
369 | if (!i2c_check_functionality(client->adapter, | |
87102808 GR |
370 | I2C_FUNC_SMBUS_READ_BYTE_DATA |
371 | | I2C_FUNC_SMBUS_BLOCK_DATA)) | |
83f7649c GR |
372 | return -ENODEV; |
373 | ||
87102808 GR |
374 | ret = i2c_smbus_read_block_data(client, PMBUS_MFR_ID, block_buffer); |
375 | if (ret < 0) { | |
376 | dev_err(&client->dev, "Failed to read Manufacturer ID\n"); | |
377 | return ret; | |
378 | } | |
379 | if (ret != 3 || strncmp(block_buffer, "ADI", 3)) { | |
380 | dev_err(&client->dev, "Unsupported Manufacturer ID\n"); | |
381 | return -ENODEV; | |
382 | } | |
83f7649c | 383 | |
87102808 GR |
384 | ret = i2c_smbus_read_block_data(client, PMBUS_MFR_MODEL, block_buffer); |
385 | if (ret < 0) { | |
386 | dev_err(&client->dev, "Failed to read Manufacturer Model\n"); | |
387 | return ret; | |
388 | } | |
389 | for (mid = adm1275_id; mid->name[0]; mid++) { | |
390 | if (!strncasecmp(mid->name, block_buffer, strlen(mid->name))) | |
391 | break; | |
392 | } | |
393 | if (!mid->name[0]) { | |
394 | dev_err(&client->dev, "Unsupported device\n"); | |
395 | return -ENODEV; | |
3b33ca41 | 396 | } |
83f7649c | 397 | |
87102808 GR |
398 | if (id->driver_data != mid->driver_data) |
399 | dev_notice(&client->dev, | |
400 | "Device mismatch: Configured %s, detected %s\n", | |
401 | id->name, mid->name); | |
402 | ||
403 | config = i2c_smbus_read_byte_data(client, ADM1275_PMON_CONFIG); | |
404 | if (config < 0) | |
405 | return config; | |
406 | ||
c5e67636 | 407 | device_config = i2c_smbus_read_byte_data(client, ADM1275_DEVICE_CONFIG); |
87102808 GR |
408 | if (device_config < 0) |
409 | return device_config; | |
410 | ||
8b313ca7 GR |
411 | data = devm_kzalloc(&client->dev, sizeof(struct adm1275_data), |
412 | GFP_KERNEL); | |
87102808 GR |
413 | if (!data) |
414 | return -ENOMEM; | |
415 | ||
6e5c06ad KY |
416 | if (of_property_read_u32(client->dev.of_node, |
417 | "shunt-resistor-micro-ohms", &shunt)) | |
418 | shunt = 1000; /* 1 mOhm if not set via DT */ | |
419 | ||
420 | if (shunt == 0) | |
421 | return -EINVAL; | |
422 | ||
87102808 | 423 | data->id = mid->driver_data; |
c5e67636 GR |
424 | |
425 | info = &data->info; | |
426 | ||
83f7649c | 427 | info->pages = 1; |
1061d851 GR |
428 | info->format[PSC_VOLTAGE_IN] = direct; |
429 | info->format[PSC_VOLTAGE_OUT] = direct; | |
430 | info->format[PSC_CURRENT_OUT] = direct; | |
904b296f | 431 | info->format[PSC_POWER] = direct; |
709066ac | 432 | info->format[PSC_TEMPERATURE] = direct; |
83f7649c GR |
433 | info->func[0] = PMBUS_HAVE_IOUT | PMBUS_HAVE_STATUS_IOUT; |
434 | ||
c576e30c | 435 | info->read_word_data = adm1275_read_word_data; |
c5e67636 | 436 | info->read_byte_data = adm1275_read_byte_data; |
c576e30c GR |
437 | info->write_word_data = adm1275_write_word_data; |
438 | ||
87102808 | 439 | switch (data->id) { |
92711269 | 440 | case adm1075: |
9048539b GR |
441 | if (device_config & ADM1275_IOUT_WARN2_SELECT) |
442 | data->have_oc_fault = true; | |
443 | else | |
444 | data->have_uc_fault = true; | |
445 | data->have_pin_max = true; | |
446 | data->have_vaux_status = true; | |
447 | ||
904b296f GR |
448 | coefficients = adm1075_coefficients; |
449 | vindex = 0; | |
92711269 GR |
450 | switch (config & ADM1075_IRANGE_MASK) { |
451 | case ADM1075_IRANGE_25: | |
904b296f GR |
452 | cindex = 1; |
453 | pindex = 3; | |
92711269 GR |
454 | break; |
455 | case ADM1075_IRANGE_50: | |
904b296f GR |
456 | cindex = 2; |
457 | pindex = 4; | |
92711269 GR |
458 | break; |
459 | default: | |
460 | dev_err(&client->dev, "Invalid input current range"); | |
92711269 GR |
461 | break; |
462 | } | |
904b296f | 463 | |
92711269 GR |
464 | info->func[0] |= PMBUS_HAVE_VIN | PMBUS_HAVE_PIN |
465 | | PMBUS_HAVE_STATUS_INPUT; | |
466 | if (config & ADM1275_VIN_VOUT_SELECT) | |
467 | info->func[0] |= | |
468 | PMBUS_HAVE_VOUT | PMBUS_HAVE_STATUS_VOUT; | |
469 | break; | |
4ff0ce22 GR |
470 | case adm1272: |
471 | data->have_vout = true; | |
472 | data->have_pin_max = true; | |
473 | data->have_temp_max = true; | |
474 | ||
475 | coefficients = adm1272_coefficients; | |
476 | vindex = (config & ADM1275_VRANGE) ? 1 : 0; | |
477 | cindex = (config & ADM1272_IRANGE) ? 3 : 2; | |
478 | /* pindex depends on the combination of the above */ | |
479 | switch (config & (ADM1275_VRANGE | ADM1272_IRANGE)) { | |
480 | case 0: | |
481 | default: | |
482 | pindex = 4; | |
483 | break; | |
484 | case ADM1275_VRANGE: | |
485 | pindex = 5; | |
486 | break; | |
487 | case ADM1272_IRANGE: | |
488 | pindex = 6; | |
489 | break; | |
490 | case ADM1275_VRANGE | ADM1272_IRANGE: | |
491 | pindex = 7; | |
492 | break; | |
493 | } | |
494 | tindex = 8; | |
495 | ||
496 | info->func[0] |= PMBUS_HAVE_PIN | PMBUS_HAVE_STATUS_INPUT | | |
497 | PMBUS_HAVE_VOUT | PMBUS_HAVE_STATUS_VOUT; | |
498 | ||
499 | /* Enable VOUT if not enabled (it is disabled by default) */ | |
500 | if (!(config & ADM1278_VOUT_EN)) { | |
501 | config |= ADM1278_VOUT_EN; | |
502 | ret = i2c_smbus_write_byte_data(client, | |
503 | ADM1275_PMON_CONFIG, | |
504 | config); | |
505 | if (ret < 0) { | |
506 | dev_err(&client->dev, | |
507 | "Failed to enable VOUT monitoring\n"); | |
508 | return -ENODEV; | |
509 | } | |
510 | } | |
511 | ||
512 | if (config & ADM1278_TEMP1_EN) | |
513 | info->func[0] |= | |
514 | PMBUS_HAVE_TEMP | PMBUS_HAVE_STATUS_TEMP; | |
515 | if (config & ADM1278_VIN_EN) | |
516 | info->func[0] |= PMBUS_HAVE_VIN; | |
517 | break; | |
5cf231a3 | 518 | case adm1275: |
9048539b GR |
519 | if (device_config & ADM1275_IOUT_WARN2_SELECT) |
520 | data->have_oc_fault = true; | |
521 | else | |
522 | data->have_uc_fault = true; | |
523 | data->have_vout = true; | |
524 | ||
904b296f GR |
525 | coefficients = adm1275_coefficients; |
526 | vindex = (config & ADM1275_VRANGE) ? 0 : 1; | |
527 | cindex = 2; | |
528 | ||
5cf231a3 GR |
529 | if (config & ADM1275_VIN_VOUT_SELECT) |
530 | info->func[0] |= | |
531 | PMBUS_HAVE_VOUT | PMBUS_HAVE_STATUS_VOUT; | |
532 | else | |
533 | info->func[0] |= | |
534 | PMBUS_HAVE_VIN | PMBUS_HAVE_STATUS_INPUT; | |
535 | break; | |
536 | case adm1276: | |
9048539b GR |
537 | if (device_config & ADM1275_IOUT_WARN2_SELECT) |
538 | data->have_oc_fault = true; | |
539 | else | |
540 | data->have_uc_fault = true; | |
541 | data->have_vout = true; | |
542 | data->have_pin_max = true; | |
543 | ||
904b296f GR |
544 | coefficients = adm1276_coefficients; |
545 | vindex = (config & ADM1275_VRANGE) ? 0 : 1; | |
546 | cindex = 2; | |
547 | pindex = (config & ADM1275_VRANGE) ? 3 : 4; | |
548 | ||
5cf231a3 GR |
549 | info->func[0] |= PMBUS_HAVE_VIN | PMBUS_HAVE_PIN |
550 | | PMBUS_HAVE_STATUS_INPUT; | |
551 | if (config & ADM1275_VIN_VOUT_SELECT) | |
552 | info->func[0] |= | |
553 | PMBUS_HAVE_VOUT | PMBUS_HAVE_STATUS_VOUT; | |
5cf231a3 | 554 | break; |
709066ac GR |
555 | case adm1278: |
556 | data->have_vout = true; | |
557 | data->have_pin_max = true; | |
558 | data->have_temp_max = true; | |
559 | ||
560 | coefficients = adm1278_coefficients; | |
561 | vindex = 0; | |
562 | cindex = 1; | |
563 | pindex = 2; | |
564 | tindex = 3; | |
565 | ||
2b3d0c19 YL |
566 | info->func[0] |= PMBUS_HAVE_PIN | PMBUS_HAVE_STATUS_INPUT | |
567 | PMBUS_HAVE_VOUT | PMBUS_HAVE_STATUS_VOUT; | |
568 | ||
569 | /* Enable VOUT if not enabled (it is disabled by default) */ | |
570 | if (!(config & ADM1278_VOUT_EN)) { | |
571 | config |= ADM1278_VOUT_EN; | |
572 | ret = i2c_smbus_write_byte_data(client, | |
573 | ADM1275_PMON_CONFIG, | |
574 | config); | |
575 | if (ret < 0) { | |
576 | dev_err(&client->dev, | |
577 | "Failed to enable VOUT monitoring\n"); | |
578 | return -ENODEV; | |
579 | } | |
580 | } | |
581 | ||
709066ac GR |
582 | if (config & ADM1278_TEMP1_EN) |
583 | info->func[0] |= | |
584 | PMBUS_HAVE_TEMP | PMBUS_HAVE_STATUS_TEMP; | |
585 | if (config & ADM1278_VIN_EN) | |
586 | info->func[0] |= PMBUS_HAVE_VIN; | |
709066ac | 587 | break; |
68a40382 GR |
588 | case adm1293: |
589 | case adm1294: | |
590 | data->have_iout_min = true; | |
591 | data->have_pin_min = true; | |
592 | data->have_pin_max = true; | |
593 | data->have_mfr_vaux_status = true; | |
594 | ||
595 | coefficients = adm1293_coefficients; | |
596 | ||
597 | voindex = 0; | |
598 | switch (config & ADM1293_VIN_SEL_MASK) { | |
599 | case ADM1293_VIN_SEL_012: /* 1.2V */ | |
600 | vindex = 0; | |
601 | break; | |
602 | case ADM1293_VIN_SEL_074: /* 7.4V */ | |
603 | vindex = 1; | |
604 | break; | |
605 | case ADM1293_VIN_SEL_210: /* 21V */ | |
606 | vindex = 2; | |
607 | break; | |
608 | default: /* disabled */ | |
609 | break; | |
610 | } | |
611 | ||
612 | switch (config & ADM1293_IRANGE_MASK) { | |
613 | case ADM1293_IRANGE_25: | |
614 | cindex = 3; | |
615 | break; | |
616 | case ADM1293_IRANGE_50: | |
617 | cindex = 4; | |
618 | break; | |
619 | case ADM1293_IRANGE_100: | |
620 | cindex = 5; | |
621 | break; | |
622 | case ADM1293_IRANGE_200: | |
623 | cindex = 6; | |
624 | break; | |
625 | } | |
626 | ||
627 | if (vindex >= 0) | |
628 | pindex = 7 + vindex * 4 + (cindex - 3); | |
629 | ||
630 | if (config & ADM1293_VAUX_EN) | |
631 | info->func[0] |= | |
632 | PMBUS_HAVE_VOUT | PMBUS_HAVE_STATUS_VOUT; | |
633 | ||
634 | info->func[0] |= PMBUS_HAVE_PIN | | |
635 | PMBUS_HAVE_VIN | PMBUS_HAVE_STATUS_INPUT; | |
636 | ||
637 | break; | |
904b296f GR |
638 | default: |
639 | dev_err(&client->dev, "Unsupported device\n"); | |
640 | return -ENODEV; | |
641 | } | |
68a40382 GR |
642 | |
643 | if (voindex < 0) | |
644 | voindex = vindex; | |
904b296f GR |
645 | if (vindex >= 0) { |
646 | info->m[PSC_VOLTAGE_IN] = coefficients[vindex].m; | |
647 | info->b[PSC_VOLTAGE_IN] = coefficients[vindex].b; | |
648 | info->R[PSC_VOLTAGE_IN] = coefficients[vindex].R; | |
68a40382 GR |
649 | } |
650 | if (voindex >= 0) { | |
651 | info->m[PSC_VOLTAGE_OUT] = coefficients[voindex].m; | |
652 | info->b[PSC_VOLTAGE_OUT] = coefficients[voindex].b; | |
653 | info->R[PSC_VOLTAGE_OUT] = coefficients[voindex].R; | |
904b296f GR |
654 | } |
655 | if (cindex >= 0) { | |
6e5c06ad KY |
656 | /* Scale current with sense resistor value */ |
657 | info->m[PSC_CURRENT_OUT] = | |
658 | coefficients[cindex].m * shunt / 1000; | |
904b296f GR |
659 | info->b[PSC_CURRENT_OUT] = coefficients[cindex].b; |
660 | info->R[PSC_CURRENT_OUT] = coefficients[cindex].R; | |
661 | } | |
662 | if (pindex >= 0) { | |
6e5c06ad KY |
663 | info->m[PSC_POWER] = |
664 | coefficients[pindex].m * shunt / 1000; | |
904b296f GR |
665 | info->b[PSC_POWER] = coefficients[pindex].b; |
666 | info->R[PSC_POWER] = coefficients[pindex].R; | |
5cf231a3 | 667 | } |
709066ac GR |
668 | if (tindex >= 0) { |
669 | info->m[PSC_TEMPERATURE] = coefficients[tindex].m; | |
670 | info->b[PSC_TEMPERATURE] = coefficients[tindex].b; | |
671 | info->R[PSC_TEMPERATURE] = coefficients[tindex].R; | |
672 | } | |
83f7649c | 673 | |
8b313ca7 | 674 | return pmbus_do_probe(client, id, info); |
83f7649c GR |
675 | } |
676 | ||
83f7649c GR |
677 | static struct i2c_driver adm1275_driver = { |
678 | .driver = { | |
679 | .name = "adm1275", | |
680 | }, | |
681 | .probe = adm1275_probe, | |
dd285ad7 | 682 | .remove = pmbus_do_remove, |
83f7649c GR |
683 | .id_table = adm1275_id, |
684 | }; | |
685 | ||
f0967eea | 686 | module_i2c_driver(adm1275_driver); |
83f7649c GR |
687 | |
688 | MODULE_AUTHOR("Guenter Roeck"); | |
5cf231a3 | 689 | MODULE_DESCRIPTION("PMBus driver for Analog Devices ADM1275 and compatibles"); |
83f7649c | 690 | MODULE_LICENSE("GPL"); |