blob: 188af4c89f40fe1d2dee176e024d73cae0d1d46c [file] [log] [blame]
Guenter Roeck83f76492011-03-17 13:16:01 -07001/*
2 * Hardware monitoring driver for Analog Devices ADM1275 Hot-Swap Controller
3 * and Digital Power Monitor
4 *
5 * Copyright (c) 2011 Ericsson AB.
6 *
7 * This program is free software; you can redistribute it and/or modify
8 * it under the terms of the GNU General Public License as published by
9 * the Free Software Foundation; either version 2 of the License, or
10 * (at your option) any later version.
11 *
12 * This program is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 * GNU General Public License for more details.
16 */
17
18#include <linux/kernel.h>
19#include <linux/module.h>
20#include <linux/init.h>
21#include <linux/err.h>
22#include <linux/slab.h>
23#include <linux/i2c.h>
Guenter Roeck99b41602015-07-04 09:19:48 -070024#include <linux/bitops.h>
Guenter Roeck83f76492011-03-17 13:16:01 -070025#include "pmbus.h"
26
Guenter Roeck68a40382015-03-17 13:19:51 -070027enum chips { adm1075, adm1275, adm1276, adm1293, adm1294 };
28
29#define ADM1275_MFR_STATUS_IOUT_WARN2 BIT(0)
30#define ADM1293_MFR_STATUS_VAUX_UV_WARN BIT(5)
31#define ADM1293_MFR_STATUS_VAUX_OV_WARN BIT(6)
Guenter Roeck5cf231a2011-07-14 11:55:35 -070032
Guenter Roeckc576e302011-07-09 11:17:33 -070033#define ADM1275_PEAK_IOUT 0xd0
34#define ADM1275_PEAK_VIN 0xd1
35#define ADM1275_PEAK_VOUT 0xd2
Guenter Roeck83f76492011-03-17 13:16:01 -070036#define ADM1275_PMON_CONFIG 0xd4
37
Guenter Roeck99b41602015-07-04 09:19:48 -070038#define ADM1275_VIN_VOUT_SELECT BIT(6)
39#define ADM1275_VRANGE BIT(5)
40#define ADM1075_IRANGE_50 BIT(4)
41#define ADM1075_IRANGE_25 BIT(3)
42#define ADM1075_IRANGE_MASK (BIT(3) | BIT(4))
Guenter Roeck83f76492011-03-17 13:16:01 -070043
Guenter Roeck68a40382015-03-17 13:19:51 -070044#define ADM1293_IRANGE_25 0
45#define ADM1293_IRANGE_50 BIT(6)
46#define ADM1293_IRANGE_100 BIT(7)
47#define ADM1293_IRANGE_200 (BIT(6) | BIT(7))
48#define ADM1293_IRANGE_MASK (BIT(6) | BIT(7))
49
50#define ADM1293_VIN_SEL_012 BIT(2)
51#define ADM1293_VIN_SEL_074 BIT(3)
52#define ADM1293_VIN_SEL_210 (BIT(2) | BIT(3))
53#define ADM1293_VIN_SEL_MASK (BIT(2) | BIT(3))
54
55#define ADM1293_VAUX_EN BIT(1)
56
Guenter Roeckc5e67632011-08-02 11:08:57 -070057#define ADM1275_IOUT_WARN2_LIMIT 0xd7
58#define ADM1275_DEVICE_CONFIG 0xd8
59
Guenter Roeck99b41602015-07-04 09:19:48 -070060#define ADM1275_IOUT_WARN2_SELECT BIT(4)
Guenter Roeckc5e67632011-08-02 11:08:57 -070061
Guenter Roeck5cf231a2011-07-14 11:55:35 -070062#define ADM1276_PEAK_PIN 0xda
Guenter Roeck92711262012-02-24 03:40:53 -080063#define ADM1075_READ_VAUX 0xdd
64#define ADM1075_VAUX_OV_WARN_LIMIT 0xde
65#define ADM1075_VAUX_UV_WARN_LIMIT 0xdf
Guenter Roeck68a40382015-03-17 13:19:51 -070066#define ADM1293_IOUT_MIN 0xe3
67#define ADM1293_PIN_MIN 0xe4
Guenter Roeck92711262012-02-24 03:40:53 -080068#define ADM1075_VAUX_STATUS 0xf6
69
Guenter Roeck99b41602015-07-04 09:19:48 -070070#define ADM1075_VAUX_OV_WARN BIT(7)
71#define ADM1075_VAUX_UV_WARN BIT(6)
Guenter Roeck92711262012-02-24 03:40:53 -080072
Guenter Roeckc5e67632011-08-02 11:08:57 -070073struct adm1275_data {
Guenter Roeck5cf231a2011-07-14 11:55:35 -070074 int id;
Guenter Roeckc5e67632011-08-02 11:08:57 -070075 bool have_oc_fault;
Guenter Roeck90485392015-07-04 10:09:54 -070076 bool have_uc_fault;
77 bool have_vout;
78 bool have_vaux_status;
Guenter Roeck68a40382015-03-17 13:19:51 -070079 bool have_mfr_vaux_status;
80 bool have_iout_min;
81 bool have_pin_min;
Guenter Roeck90485392015-07-04 10:09:54 -070082 bool have_pin_max;
Guenter Roeckc5e67632011-08-02 11:08:57 -070083 struct pmbus_driver_info info;
84};
85
86#define to_adm1275_data(x) container_of(x, struct adm1275_data, info)
87
Guenter Roeck904b2962015-07-04 08:39:18 -070088struct coefficients {
89 s16 m;
90 s16 b;
91 s16 R;
92};
93
94static 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 */
98 [3] = { 0, -1, 8549 }, /* power, irange25 */
99 [4] = { 0, -1, 4279 }, /* power, irange50 */
100};
101
102static const struct coefficients adm1275_coefficients[] = {
103 [0] = { 19199, 0, -2 }, /* voltage, vrange set */
104 [1] = { 6720, 0, -1 }, /* voltage, vrange not set */
105 [2] = { 807, 20475, -1 }, /* current */
106};
107
108static const struct coefficients adm1276_coefficients[] = {
109 [0] = { 19199, 0, -2 }, /* voltage, vrange set */
110 [1] = { 6720, 0, -1 }, /* voltage, vrange not set */
111 [2] = { 807, 20475, -1 }, /* current */
112 [3] = { 6043, 0, -2 }, /* power, vrange set */
113 [4] = { 2115, 0, -1 }, /* power, vrange not set */
114};
115
Guenter Roeck68a40382015-03-17 13:19:51 -0700116static const struct coefficients adm1293_coefficients[] = {
117 [0] = { 3333, -1, 0 }, /* voltage, vrange 1.2V */
118 [1] = { 5552, -5, -1 }, /* voltage, vrange 7.4V */
119 [2] = { 19604, -50, -2 }, /* voltage, vrange 21V */
120 [3] = { 8000, -100, -2 }, /* current, irange25 */
121 [4] = { 4000, -100, -2 }, /* current, irange50 */
122 [5] = { 20000, -1000, -3 }, /* current, irange100 */
123 [6] = { 10000, -1000, -3 }, /* current, irange200 */
124 [7] = { 10417, 0, -1 }, /* power, 1.2V, irange25 */
125 [8] = { 5208, 0, -1 }, /* power, 1.2V, irange50 */
126 [9] = { 26042, 0, -2 }, /* power, 1.2V, irange100 */
127 [10] = { 13021, 0, -2 }, /* power, 1.2V, irange200 */
128 [11] = { 17351, 0, -2 }, /* power, 7.4V, irange25 */
129 [12] = { 8676, 0, -2 }, /* power, 7.4V, irange50 */
130 [13] = { 4338, 0, -2 }, /* power, 7.4V, irange100 */
131 [14] = { 21689, 0, -3 }, /* power, 7.4V, irange200 */
132 [15] = { 6126, 0, -2 }, /* power, 21V, irange25 */
133 [16] = { 30631, 0, -3 }, /* power, 21V, irange50 */
134 [17] = { 15316, 0, -3 }, /* power, 21V, irange100 */
135 [18] = { 7658, 0, -3 }, /* power, 21V, irange200 */
136};
137
Guenter Roeckc576e302011-07-09 11:17:33 -0700138static int adm1275_read_word_data(struct i2c_client *client, int page, int reg)
139{
Guenter Roeckc5e67632011-08-02 11:08:57 -0700140 const struct pmbus_driver_info *info = pmbus_get_driver_info(client);
141 const struct adm1275_data *data = to_adm1275_data(info);
Guenter Roeck5cf231a2011-07-14 11:55:35 -0700142 int ret = 0;
Guenter Roeckc576e302011-07-09 11:17:33 -0700143
144 if (page)
Guenter Roeckc5e67632011-08-02 11:08:57 -0700145 return -ENXIO;
Guenter Roeckc576e302011-07-09 11:17:33 -0700146
147 switch (reg) {
Guenter Roeckc5e67632011-08-02 11:08:57 -0700148 case PMBUS_IOUT_UC_FAULT_LIMIT:
Guenter Roeck90485392015-07-04 10:09:54 -0700149 if (!data->have_uc_fault)
150 return -ENXIO;
Guenter Roeckc5e67632011-08-02 11:08:57 -0700151 ret = pmbus_read_word_data(client, 0, ADM1275_IOUT_WARN2_LIMIT);
152 break;
153 case PMBUS_IOUT_OC_FAULT_LIMIT:
Guenter Roeck90485392015-07-04 10:09:54 -0700154 if (!data->have_oc_fault)
155 return -ENXIO;
Guenter Roeckc5e67632011-08-02 11:08:57 -0700156 ret = pmbus_read_word_data(client, 0, ADM1275_IOUT_WARN2_LIMIT);
157 break;
Guenter Roeck92711262012-02-24 03:40:53 -0800158 case PMBUS_VOUT_OV_WARN_LIMIT:
Guenter Roeck90485392015-07-04 10:09:54 -0700159 if (data->have_vout)
160 return -ENODATA;
Guenter Roeck92711262012-02-24 03:40:53 -0800161 ret = pmbus_read_word_data(client, 0,
162 ADM1075_VAUX_OV_WARN_LIMIT);
163 break;
164 case PMBUS_VOUT_UV_WARN_LIMIT:
Guenter Roeck90485392015-07-04 10:09:54 -0700165 if (data->have_vout)
166 return -ENODATA;
Guenter Roeck92711262012-02-24 03:40:53 -0800167 ret = pmbus_read_word_data(client, 0,
168 ADM1075_VAUX_UV_WARN_LIMIT);
169 break;
170 case PMBUS_READ_VOUT:
Guenter Roeck90485392015-07-04 10:09:54 -0700171 if (data->have_vout)
172 return -ENODATA;
Guenter Roeck92711262012-02-24 03:40:53 -0800173 ret = pmbus_read_word_data(client, 0, ADM1075_READ_VAUX);
174 break;
Guenter Roeck68a40382015-03-17 13:19:51 -0700175 case PMBUS_VIRT_READ_IOUT_MIN:
176 if (!data->have_iout_min)
177 return -ENXIO;
178 ret = pmbus_read_word_data(client, 0, ADM1293_IOUT_MIN);
179 break;
Guenter Roeckc576e302011-07-09 11:17:33 -0700180 case PMBUS_VIRT_READ_IOUT_MAX:
181 ret = pmbus_read_word_data(client, 0, ADM1275_PEAK_IOUT);
182 break;
183 case PMBUS_VIRT_READ_VOUT_MAX:
184 ret = pmbus_read_word_data(client, 0, ADM1275_PEAK_VOUT);
185 break;
186 case PMBUS_VIRT_READ_VIN_MAX:
187 ret = pmbus_read_word_data(client, 0, ADM1275_PEAK_VIN);
188 break;
Guenter Roeck68a40382015-03-17 13:19:51 -0700189 case PMBUS_VIRT_READ_PIN_MIN:
190 if (!data->have_pin_min)
191 return -ENXIO;
192 ret = pmbus_read_word_data(client, 0, ADM1293_PIN_MIN);
193 break;
Guenter Roeck5cf231a2011-07-14 11:55:35 -0700194 case PMBUS_VIRT_READ_PIN_MAX:
Guenter Roeck90485392015-07-04 10:09:54 -0700195 if (!data->have_pin_max)
196 return -ENXIO;
Guenter Roeck5cf231a2011-07-14 11:55:35 -0700197 ret = pmbus_read_word_data(client, 0, ADM1276_PEAK_PIN);
198 break;
Guenter Roeckc576e302011-07-09 11:17:33 -0700199 case PMBUS_VIRT_RESET_IOUT_HISTORY:
200 case PMBUS_VIRT_RESET_VOUT_HISTORY:
201 case PMBUS_VIRT_RESET_VIN_HISTORY:
Guenter Roeck5cf231a2011-07-14 11:55:35 -0700202 break;
203 case PMBUS_VIRT_RESET_PIN_HISTORY:
Guenter Roeck90485392015-07-04 10:09:54 -0700204 if (!data->have_pin_max)
205 return -ENXIO;
Guenter Roeckc576e302011-07-09 11:17:33 -0700206 break;
207 default:
208 ret = -ENODATA;
209 break;
210 }
211 return ret;
212}
213
214static int adm1275_write_word_data(struct i2c_client *client, int page, int reg,
215 u16 word)
216{
Guenter Roeck68a40382015-03-17 13:19:51 -0700217 const struct pmbus_driver_info *info = pmbus_get_driver_info(client);
218 const struct adm1275_data *data = to_adm1275_data(info);
Guenter Roeckc576e302011-07-09 11:17:33 -0700219 int ret;
220
221 if (page)
Guenter Roeckc5e67632011-08-02 11:08:57 -0700222 return -ENXIO;
Guenter Roeckc576e302011-07-09 11:17:33 -0700223
224 switch (reg) {
Guenter Roeckc5e67632011-08-02 11:08:57 -0700225 case PMBUS_IOUT_UC_FAULT_LIMIT:
226 case PMBUS_IOUT_OC_FAULT_LIMIT:
227 ret = pmbus_write_word_data(client, 0, ADM1275_IOUT_WARN2_LIMIT,
228 word);
229 break;
Guenter Roeckc576e302011-07-09 11:17:33 -0700230 case PMBUS_VIRT_RESET_IOUT_HISTORY:
231 ret = pmbus_write_word_data(client, 0, ADM1275_PEAK_IOUT, 0);
Guenter Roeck68a40382015-03-17 13:19:51 -0700232 if (!ret && data->have_iout_min)
233 ret = pmbus_write_word_data(client, 0,
234 ADM1293_IOUT_MIN, 0);
Guenter Roeckc576e302011-07-09 11:17:33 -0700235 break;
236 case PMBUS_VIRT_RESET_VOUT_HISTORY:
237 ret = pmbus_write_word_data(client, 0, ADM1275_PEAK_VOUT, 0);
238 break;
239 case PMBUS_VIRT_RESET_VIN_HISTORY:
240 ret = pmbus_write_word_data(client, 0, ADM1275_PEAK_VIN, 0);
241 break;
Guenter Roeck5cf231a2011-07-14 11:55:35 -0700242 case PMBUS_VIRT_RESET_PIN_HISTORY:
243 ret = pmbus_write_word_data(client, 0, ADM1276_PEAK_PIN, 0);
Guenter Roeck68a40382015-03-17 13:19:51 -0700244 if (!ret && data->have_pin_min)
245 ret = pmbus_write_word_data(client, 0,
246 ADM1293_PIN_MIN, 0);
Guenter Roeck5cf231a2011-07-14 11:55:35 -0700247 break;
Guenter Roeckc576e302011-07-09 11:17:33 -0700248 default:
249 ret = -ENODATA;
250 break;
251 }
252 return ret;
253}
254
Guenter Roeckc5e67632011-08-02 11:08:57 -0700255static int adm1275_read_byte_data(struct i2c_client *client, int page, int reg)
256{
257 const struct pmbus_driver_info *info = pmbus_get_driver_info(client);
258 const struct adm1275_data *data = to_adm1275_data(info);
259 int mfr_status, ret;
260
Guenter Roeckda8e48a2011-07-29 22:19:39 -0700261 if (page > 0)
Guenter Roeckc5e67632011-08-02 11:08:57 -0700262 return -ENXIO;
263
264 switch (reg) {
265 case PMBUS_STATUS_IOUT:
266 ret = pmbus_read_byte_data(client, page, PMBUS_STATUS_IOUT);
267 if (ret < 0)
268 break;
Guenter Roeck90485392015-07-04 10:09:54 -0700269 if (!data->have_oc_fault && !data->have_uc_fault)
270 break;
Guenter Roeckc5e67632011-08-02 11:08:57 -0700271 mfr_status = pmbus_read_byte_data(client, page,
272 PMBUS_STATUS_MFR_SPECIFIC);
Guenter Roeck90485392015-07-04 10:09:54 -0700273 if (mfr_status < 0)
274 return mfr_status;
Guenter Roeckc5e67632011-08-02 11:08:57 -0700275 if (mfr_status & ADM1275_MFR_STATUS_IOUT_WARN2) {
276 ret |= data->have_oc_fault ?
277 PB_IOUT_OC_FAULT : PB_IOUT_UC_FAULT;
278 }
279 break;
Guenter Roeck92711262012-02-24 03:40:53 -0800280 case PMBUS_STATUS_VOUT:
Guenter Roeck90485392015-07-04 10:09:54 -0700281 if (data->have_vout)
282 return -ENODATA;
Guenter Roeck92711262012-02-24 03:40:53 -0800283 ret = 0;
Guenter Roeck90485392015-07-04 10:09:54 -0700284 if (data->have_vaux_status) {
285 mfr_status = pmbus_read_byte_data(client, 0,
286 ADM1075_VAUX_STATUS);
287 if (mfr_status < 0)
288 return mfr_status;
289 if (mfr_status & ADM1075_VAUX_OV_WARN)
290 ret |= PB_VOLTAGE_OV_WARNING;
291 if (mfr_status & ADM1075_VAUX_UV_WARN)
292 ret |= PB_VOLTAGE_UV_WARNING;
Guenter Roeck68a40382015-03-17 13:19:51 -0700293 } else if (data->have_mfr_vaux_status) {
294 mfr_status = pmbus_read_byte_data(client, page,
295 PMBUS_STATUS_MFR_SPECIFIC);
296 if (mfr_status < 0)
297 return mfr_status;
298 if (mfr_status & ADM1293_MFR_STATUS_VAUX_OV_WARN)
299 ret |= PB_VOLTAGE_OV_WARNING;
300 if (mfr_status & ADM1293_MFR_STATUS_VAUX_UV_WARN)
301 ret |= PB_VOLTAGE_UV_WARNING;
Guenter Roeck90485392015-07-04 10:09:54 -0700302 }
Guenter Roeck92711262012-02-24 03:40:53 -0800303 break;
Guenter Roeckc5e67632011-08-02 11:08:57 -0700304 default:
305 ret = -ENODATA;
306 break;
307 }
308 return ret;
309}
310
Guenter Roeck87102802011-09-30 11:53:25 -0700311static const struct i2c_device_id adm1275_id[] = {
Guenter Roeck92711262012-02-24 03:40:53 -0800312 { "adm1075", adm1075 },
Guenter Roeck87102802011-09-30 11:53:25 -0700313 { "adm1275", adm1275 },
314 { "adm1276", adm1276 },
Guenter Roeck68a40382015-03-17 13:19:51 -0700315 { "adm1293", adm1293 },
316 { "adm1294", adm1294 },
Guenter Roeck87102802011-09-30 11:53:25 -0700317 { }
318};
319MODULE_DEVICE_TABLE(i2c, adm1275_id);
320
Guenter Roeck83f76492011-03-17 13:16:01 -0700321static int adm1275_probe(struct i2c_client *client,
322 const struct i2c_device_id *id)
323{
Guenter Roeck87102802011-09-30 11:53:25 -0700324 u8 block_buffer[I2C_SMBUS_BLOCK_MAX + 1];
Guenter Roeckc5e67632011-08-02 11:08:57 -0700325 int config, device_config;
Guenter Roeck3b33ca42011-06-30 02:30:03 -0700326 int ret;
Guenter Roeck83f76492011-03-17 13:16:01 -0700327 struct pmbus_driver_info *info;
Guenter Roeckc5e67632011-08-02 11:08:57 -0700328 struct adm1275_data *data;
Guenter Roeck87102802011-09-30 11:53:25 -0700329 const struct i2c_device_id *mid;
Guenter Roeck904b2962015-07-04 08:39:18 -0700330 const struct coefficients *coefficients;
Guenter Roeck68a40382015-03-17 13:19:51 -0700331 int vindex = -1, voindex = -1, cindex = -1, pindex = -1;
Guenter Roeck83f76492011-03-17 13:16:01 -0700332
333 if (!i2c_check_functionality(client->adapter,
Guenter Roeck87102802011-09-30 11:53:25 -0700334 I2C_FUNC_SMBUS_READ_BYTE_DATA
335 | I2C_FUNC_SMBUS_BLOCK_DATA))
Guenter Roeck83f76492011-03-17 13:16:01 -0700336 return -ENODEV;
337
Guenter Roeck87102802011-09-30 11:53:25 -0700338 ret = i2c_smbus_read_block_data(client, PMBUS_MFR_ID, block_buffer);
339 if (ret < 0) {
340 dev_err(&client->dev, "Failed to read Manufacturer ID\n");
341 return ret;
342 }
343 if (ret != 3 || strncmp(block_buffer, "ADI", 3)) {
344 dev_err(&client->dev, "Unsupported Manufacturer ID\n");
345 return -ENODEV;
346 }
347
348 ret = i2c_smbus_read_block_data(client, PMBUS_MFR_MODEL, block_buffer);
349 if (ret < 0) {
350 dev_err(&client->dev, "Failed to read Manufacturer Model\n");
351 return ret;
352 }
353 for (mid = adm1275_id; mid->name[0]; mid++) {
354 if (!strncasecmp(mid->name, block_buffer, strlen(mid->name)))
355 break;
356 }
357 if (!mid->name[0]) {
358 dev_err(&client->dev, "Unsupported device\n");
359 return -ENODEV;
360 }
361
362 if (id->driver_data != mid->driver_data)
363 dev_notice(&client->dev,
364 "Device mismatch: Configured %s, detected %s\n",
365 id->name, mid->name);
366
367 config = i2c_smbus_read_byte_data(client, ADM1275_PMON_CONFIG);
368 if (config < 0)
369 return config;
370
371 device_config = i2c_smbus_read_byte_data(client, ADM1275_DEVICE_CONFIG);
372 if (device_config < 0)
373 return device_config;
374
Guenter Roeck8b313ca2012-02-22 08:56:43 -0800375 data = devm_kzalloc(&client->dev, sizeof(struct adm1275_data),
376 GFP_KERNEL);
Guenter Roeckc5e67632011-08-02 11:08:57 -0700377 if (!data)
Guenter Roeck83f76492011-03-17 13:16:01 -0700378 return -ENOMEM;
379
Guenter Roeck87102802011-09-30 11:53:25 -0700380 data->id = mid->driver_data;
Guenter Roeck83f76492011-03-17 13:16:01 -0700381
Guenter Roeckc5e67632011-08-02 11:08:57 -0700382 info = &data->info;
383
Guenter Roeck83f76492011-03-17 13:16:01 -0700384 info->pages = 1;
Guenter Roeck1061d852011-06-25 11:21:49 -0700385 info->format[PSC_VOLTAGE_IN] = direct;
386 info->format[PSC_VOLTAGE_OUT] = direct;
387 info->format[PSC_CURRENT_OUT] = direct;
Guenter Roeck904b2962015-07-04 08:39:18 -0700388 info->format[PSC_POWER] = direct;
Guenter Roeck83f76492011-03-17 13:16:01 -0700389 info->func[0] = PMBUS_HAVE_IOUT | PMBUS_HAVE_STATUS_IOUT;
390
Guenter Roeckc576e302011-07-09 11:17:33 -0700391 info->read_word_data = adm1275_read_word_data;
Guenter Roeckc5e67632011-08-02 11:08:57 -0700392 info->read_byte_data = adm1275_read_byte_data;
Guenter Roeckc576e302011-07-09 11:17:33 -0700393 info->write_word_data = adm1275_write_word_data;
394
Guenter Roeck87102802011-09-30 11:53:25 -0700395 switch (data->id) {
Guenter Roeck92711262012-02-24 03:40:53 -0800396 case adm1075:
Guenter Roeck90485392015-07-04 10:09:54 -0700397 if (device_config & ADM1275_IOUT_WARN2_SELECT)
398 data->have_oc_fault = true;
399 else
400 data->have_uc_fault = true;
401 data->have_pin_max = true;
402 data->have_vaux_status = true;
403
Guenter Roeck904b2962015-07-04 08:39:18 -0700404 coefficients = adm1075_coefficients;
405 vindex = 0;
Guenter Roeck92711262012-02-24 03:40:53 -0800406 switch (config & ADM1075_IRANGE_MASK) {
407 case ADM1075_IRANGE_25:
Guenter Roeck904b2962015-07-04 08:39:18 -0700408 cindex = 1;
409 pindex = 3;
Guenter Roeck92711262012-02-24 03:40:53 -0800410 break;
411 case ADM1075_IRANGE_50:
Guenter Roeck904b2962015-07-04 08:39:18 -0700412 cindex = 2;
413 pindex = 4;
Guenter Roeck92711262012-02-24 03:40:53 -0800414 break;
415 default:
416 dev_err(&client->dev, "Invalid input current range");
Guenter Roeck92711262012-02-24 03:40:53 -0800417 break;
418 }
Guenter Roeck904b2962015-07-04 08:39:18 -0700419
Guenter Roeck92711262012-02-24 03:40:53 -0800420 info->func[0] |= PMBUS_HAVE_VIN | PMBUS_HAVE_PIN
421 | PMBUS_HAVE_STATUS_INPUT;
422 if (config & ADM1275_VIN_VOUT_SELECT)
423 info->func[0] |=
424 PMBUS_HAVE_VOUT | PMBUS_HAVE_STATUS_VOUT;
425 break;
Guenter Roeck5cf231a2011-07-14 11:55:35 -0700426 case adm1275:
Guenter Roeck90485392015-07-04 10:09:54 -0700427 if (device_config & ADM1275_IOUT_WARN2_SELECT)
428 data->have_oc_fault = true;
429 else
430 data->have_uc_fault = true;
431 data->have_vout = true;
432
Guenter Roeck904b2962015-07-04 08:39:18 -0700433 coefficients = adm1275_coefficients;
434 vindex = (config & ADM1275_VRANGE) ? 0 : 1;
435 cindex = 2;
436
Guenter Roeck5cf231a2011-07-14 11:55:35 -0700437 if (config & ADM1275_VIN_VOUT_SELECT)
438 info->func[0] |=
439 PMBUS_HAVE_VOUT | PMBUS_HAVE_STATUS_VOUT;
440 else
441 info->func[0] |=
442 PMBUS_HAVE_VIN | PMBUS_HAVE_STATUS_INPUT;
443 break;
444 case adm1276:
Guenter Roeck90485392015-07-04 10:09:54 -0700445 if (device_config & ADM1275_IOUT_WARN2_SELECT)
446 data->have_oc_fault = true;
447 else
448 data->have_uc_fault = true;
449 data->have_vout = true;
450 data->have_pin_max = true;
451
Guenter Roeck904b2962015-07-04 08:39:18 -0700452 coefficients = adm1276_coefficients;
453 vindex = (config & ADM1275_VRANGE) ? 0 : 1;
454 cindex = 2;
455 pindex = (config & ADM1275_VRANGE) ? 3 : 4;
456
Guenter Roeck5cf231a2011-07-14 11:55:35 -0700457 info->func[0] |= PMBUS_HAVE_VIN | PMBUS_HAVE_PIN
458 | PMBUS_HAVE_STATUS_INPUT;
459 if (config & ADM1275_VIN_VOUT_SELECT)
460 info->func[0] |=
461 PMBUS_HAVE_VOUT | PMBUS_HAVE_STATUS_VOUT;
Guenter Roeck5cf231a2011-07-14 11:55:35 -0700462 break;
Guenter Roeck68a40382015-03-17 13:19:51 -0700463 case adm1293:
464 case adm1294:
465 data->have_iout_min = true;
466 data->have_pin_min = true;
467 data->have_pin_max = true;
468 data->have_mfr_vaux_status = true;
469
470 coefficients = adm1293_coefficients;
471
472 voindex = 0;
473 switch (config & ADM1293_VIN_SEL_MASK) {
474 case ADM1293_VIN_SEL_012: /* 1.2V */
475 vindex = 0;
476 break;
477 case ADM1293_VIN_SEL_074: /* 7.4V */
478 vindex = 1;
479 break;
480 case ADM1293_VIN_SEL_210: /* 21V */
481 vindex = 2;
482 break;
483 default: /* disabled */
484 break;
485 }
486
487 switch (config & ADM1293_IRANGE_MASK) {
488 case ADM1293_IRANGE_25:
489 cindex = 3;
490 break;
491 case ADM1293_IRANGE_50:
492 cindex = 4;
493 break;
494 case ADM1293_IRANGE_100:
495 cindex = 5;
496 break;
497 case ADM1293_IRANGE_200:
498 cindex = 6;
499 break;
500 }
501
502 if (vindex >= 0)
503 pindex = 7 + vindex * 4 + (cindex - 3);
504
505 if (config & ADM1293_VAUX_EN)
506 info->func[0] |=
507 PMBUS_HAVE_VOUT | PMBUS_HAVE_STATUS_VOUT;
508
509 info->func[0] |= PMBUS_HAVE_PIN |
510 PMBUS_HAVE_VIN | PMBUS_HAVE_STATUS_INPUT;
511
512 break;
Guenter Roeck904b2962015-07-04 08:39:18 -0700513 default:
514 dev_err(&client->dev, "Unsupported device\n");
515 return -ENODEV;
516 }
Guenter Roeck68a40382015-03-17 13:19:51 -0700517
518 if (voindex < 0)
519 voindex = vindex;
Guenter Roeck904b2962015-07-04 08:39:18 -0700520 if (vindex >= 0) {
521 info->m[PSC_VOLTAGE_IN] = coefficients[vindex].m;
522 info->b[PSC_VOLTAGE_IN] = coefficients[vindex].b;
523 info->R[PSC_VOLTAGE_IN] = coefficients[vindex].R;
Guenter Roeck68a40382015-03-17 13:19:51 -0700524 }
525 if (voindex >= 0) {
526 info->m[PSC_VOLTAGE_OUT] = coefficients[voindex].m;
527 info->b[PSC_VOLTAGE_OUT] = coefficients[voindex].b;
528 info->R[PSC_VOLTAGE_OUT] = coefficients[voindex].R;
Guenter Roeck904b2962015-07-04 08:39:18 -0700529 }
530 if (cindex >= 0) {
531 info->m[PSC_CURRENT_OUT] = coefficients[cindex].m;
532 info->b[PSC_CURRENT_OUT] = coefficients[cindex].b;
533 info->R[PSC_CURRENT_OUT] = coefficients[cindex].R;
534 }
535 if (pindex >= 0) {
536 info->m[PSC_POWER] = coefficients[pindex].m;
537 info->b[PSC_POWER] = coefficients[pindex].b;
538 info->R[PSC_POWER] = coefficients[pindex].R;
Guenter Roeck5cf231a2011-07-14 11:55:35 -0700539 }
Guenter Roeck83f76492011-03-17 13:16:01 -0700540
Guenter Roeck8b313ca2012-02-22 08:56:43 -0800541 return pmbus_do_probe(client, id, info);
Guenter Roeck83f76492011-03-17 13:16:01 -0700542}
543
Guenter Roeck83f76492011-03-17 13:16:01 -0700544static struct i2c_driver adm1275_driver = {
545 .driver = {
546 .name = "adm1275",
547 },
548 .probe = adm1275_probe,
Guenter Roeckdd285ad2012-02-22 08:56:44 -0800549 .remove = pmbus_do_remove,
Guenter Roeck83f76492011-03-17 13:16:01 -0700550 .id_table = adm1275_id,
551};
552
Axel Linf0967ee2012-01-20 15:38:18 +0800553module_i2c_driver(adm1275_driver);
Guenter Roeck83f76492011-03-17 13:16:01 -0700554
555MODULE_AUTHOR("Guenter Roeck");
Guenter Roeck5cf231a2011-07-14 11:55:35 -0700556MODULE_DESCRIPTION("PMBus driver for Analog Devices ADM1275 and compatibles");
Guenter Roeck83f76492011-03-17 13:16:01 -0700557MODULE_LICENSE("GPL");