adm1275.c 17 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612
  1. /*
  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. #include <linux/kernel.h>
  18. #include <linux/module.h>
  19. #include <linux/init.h>
  20. #include <linux/err.h>
  21. #include <linux/slab.h>
  22. #include <linux/i2c.h>
  23. #include <linux/bitops.h>
  24. #include "pmbus.h"
  25. enum chips { adm1075, adm1275, adm1276, adm1278, adm1293, adm1294 };
  26. #define ADM1275_MFR_STATUS_IOUT_WARN2 BIT(0)
  27. #define ADM1293_MFR_STATUS_VAUX_UV_WARN BIT(5)
  28. #define ADM1293_MFR_STATUS_VAUX_OV_WARN BIT(6)
  29. #define ADM1275_PEAK_IOUT 0xd0
  30. #define ADM1275_PEAK_VIN 0xd1
  31. #define ADM1275_PEAK_VOUT 0xd2
  32. #define ADM1275_PMON_CONFIG 0xd4
  33. #define ADM1275_VIN_VOUT_SELECT BIT(6)
  34. #define ADM1275_VRANGE BIT(5)
  35. #define ADM1075_IRANGE_50 BIT(4)
  36. #define ADM1075_IRANGE_25 BIT(3)
  37. #define ADM1075_IRANGE_MASK (BIT(3) | BIT(4))
  38. #define ADM1278_TEMP1_EN BIT(3)
  39. #define ADM1278_VIN_EN BIT(2)
  40. #define ADM1278_VOUT_EN BIT(1)
  41. #define ADM1293_IRANGE_25 0
  42. #define ADM1293_IRANGE_50 BIT(6)
  43. #define ADM1293_IRANGE_100 BIT(7)
  44. #define ADM1293_IRANGE_200 (BIT(6) | BIT(7))
  45. #define ADM1293_IRANGE_MASK (BIT(6) | BIT(7))
  46. #define ADM1293_VIN_SEL_012 BIT(2)
  47. #define ADM1293_VIN_SEL_074 BIT(3)
  48. #define ADM1293_VIN_SEL_210 (BIT(2) | BIT(3))
  49. #define ADM1293_VIN_SEL_MASK (BIT(2) | BIT(3))
  50. #define ADM1293_VAUX_EN BIT(1)
  51. #define ADM1278_PEAK_TEMP 0xd7
  52. #define ADM1275_IOUT_WARN2_LIMIT 0xd7
  53. #define ADM1275_DEVICE_CONFIG 0xd8
  54. #define ADM1275_IOUT_WARN2_SELECT BIT(4)
  55. #define ADM1276_PEAK_PIN 0xda
  56. #define ADM1075_READ_VAUX 0xdd
  57. #define ADM1075_VAUX_OV_WARN_LIMIT 0xde
  58. #define ADM1075_VAUX_UV_WARN_LIMIT 0xdf
  59. #define ADM1293_IOUT_MIN 0xe3
  60. #define ADM1293_PIN_MIN 0xe4
  61. #define ADM1075_VAUX_STATUS 0xf6
  62. #define ADM1075_VAUX_OV_WARN BIT(7)
  63. #define ADM1075_VAUX_UV_WARN BIT(6)
  64. struct adm1275_data {
  65. int id;
  66. bool have_oc_fault;
  67. bool have_uc_fault;
  68. bool have_vout;
  69. bool have_vaux_status;
  70. bool have_mfr_vaux_status;
  71. bool have_iout_min;
  72. bool have_pin_min;
  73. bool have_pin_max;
  74. bool have_temp_max;
  75. struct pmbus_driver_info info;
  76. };
  77. #define to_adm1275_data(x) container_of(x, struct adm1275_data, info)
  78. struct coefficients {
  79. s16 m;
  80. s16 b;
  81. s16 R;
  82. };
  83. static const struct coefficients adm1075_coefficients[] = {
  84. [0] = { 27169, 0, -1 }, /* voltage */
  85. [1] = { 806, 20475, -1 }, /* current, irange25 */
  86. [2] = { 404, 20475, -1 }, /* current, irange50 */
  87. [3] = { 8549, 0, -1 }, /* power, irange25 */
  88. [4] = { 4279, 0, -1 }, /* power, irange50 */
  89. };
  90. static const struct coefficients adm1275_coefficients[] = {
  91. [0] = { 19199, 0, -2 }, /* voltage, vrange set */
  92. [1] = { 6720, 0, -1 }, /* voltage, vrange not set */
  93. [2] = { 807, 20475, -1 }, /* current */
  94. };
  95. static const struct coefficients adm1276_coefficients[] = {
  96. [0] = { 19199, 0, -2 }, /* voltage, vrange set */
  97. [1] = { 6720, 0, -1 }, /* voltage, vrange not set */
  98. [2] = { 807, 20475, -1 }, /* current */
  99. [3] = { 6043, 0, -2 }, /* power, vrange set */
  100. [4] = { 2115, 0, -1 }, /* power, vrange not set */
  101. };
  102. static const struct coefficients adm1278_coefficients[] = {
  103. [0] = { 19599, 0, -2 }, /* voltage */
  104. [1] = { 800, 20475, -1 }, /* current */
  105. [2] = { 6123, 0, -2 }, /* power */
  106. [3] = { 42, 31880, -1 }, /* temperature */
  107. };
  108. static const struct coefficients adm1293_coefficients[] = {
  109. [0] = { 3333, -1, 0 }, /* voltage, vrange 1.2V */
  110. [1] = { 5552, -5, -1 }, /* voltage, vrange 7.4V */
  111. [2] = { 19604, -50, -2 }, /* voltage, vrange 21V */
  112. [3] = { 8000, -100, -2 }, /* current, irange25 */
  113. [4] = { 4000, -100, -2 }, /* current, irange50 */
  114. [5] = { 20000, -1000, -3 }, /* current, irange100 */
  115. [6] = { 10000, -1000, -3 }, /* current, irange200 */
  116. [7] = { 10417, 0, -1 }, /* power, 1.2V, irange25 */
  117. [8] = { 5208, 0, -1 }, /* power, 1.2V, irange50 */
  118. [9] = { 26042, 0, -2 }, /* power, 1.2V, irange100 */
  119. [10] = { 13021, 0, -2 }, /* power, 1.2V, irange200 */
  120. [11] = { 17351, 0, -2 }, /* power, 7.4V, irange25 */
  121. [12] = { 8676, 0, -2 }, /* power, 7.4V, irange50 */
  122. [13] = { 4338, 0, -2 }, /* power, 7.4V, irange100 */
  123. [14] = { 21689, 0, -3 }, /* power, 7.4V, irange200 */
  124. [15] = { 6126, 0, -2 }, /* power, 21V, irange25 */
  125. [16] = { 30631, 0, -3 }, /* power, 21V, irange50 */
  126. [17] = { 15316, 0, -3 }, /* power, 21V, irange100 */
  127. [18] = { 7658, 0, -3 }, /* power, 21V, irange200 */
  128. };
  129. static int adm1275_read_word_data(struct i2c_client *client, int page, int reg)
  130. {
  131. const struct pmbus_driver_info *info = pmbus_get_driver_info(client);
  132. const struct adm1275_data *data = to_adm1275_data(info);
  133. int ret = 0;
  134. if (page > 0)
  135. return -ENXIO;
  136. switch (reg) {
  137. case PMBUS_IOUT_UC_FAULT_LIMIT:
  138. if (!data->have_uc_fault)
  139. return -ENXIO;
  140. ret = pmbus_read_word_data(client, 0, ADM1275_IOUT_WARN2_LIMIT);
  141. break;
  142. case PMBUS_IOUT_OC_FAULT_LIMIT:
  143. if (!data->have_oc_fault)
  144. return -ENXIO;
  145. ret = pmbus_read_word_data(client, 0, ADM1275_IOUT_WARN2_LIMIT);
  146. break;
  147. case PMBUS_VOUT_OV_WARN_LIMIT:
  148. if (data->have_vout)
  149. return -ENODATA;
  150. ret = pmbus_read_word_data(client, 0,
  151. ADM1075_VAUX_OV_WARN_LIMIT);
  152. break;
  153. case PMBUS_VOUT_UV_WARN_LIMIT:
  154. if (data->have_vout)
  155. return -ENODATA;
  156. ret = pmbus_read_word_data(client, 0,
  157. ADM1075_VAUX_UV_WARN_LIMIT);
  158. break;
  159. case PMBUS_READ_VOUT:
  160. if (data->have_vout)
  161. return -ENODATA;
  162. ret = pmbus_read_word_data(client, 0, ADM1075_READ_VAUX);
  163. break;
  164. case PMBUS_VIRT_READ_IOUT_MIN:
  165. if (!data->have_iout_min)
  166. return -ENXIO;
  167. ret = pmbus_read_word_data(client, 0, ADM1293_IOUT_MIN);
  168. break;
  169. case PMBUS_VIRT_READ_IOUT_MAX:
  170. ret = pmbus_read_word_data(client, 0, ADM1275_PEAK_IOUT);
  171. break;
  172. case PMBUS_VIRT_READ_VOUT_MAX:
  173. ret = pmbus_read_word_data(client, 0, ADM1275_PEAK_VOUT);
  174. break;
  175. case PMBUS_VIRT_READ_VIN_MAX:
  176. ret = pmbus_read_word_data(client, 0, ADM1275_PEAK_VIN);
  177. break;
  178. case PMBUS_VIRT_READ_PIN_MIN:
  179. if (!data->have_pin_min)
  180. return -ENXIO;
  181. ret = pmbus_read_word_data(client, 0, ADM1293_PIN_MIN);
  182. break;
  183. case PMBUS_VIRT_READ_PIN_MAX:
  184. if (!data->have_pin_max)
  185. return -ENXIO;
  186. ret = pmbus_read_word_data(client, 0, ADM1276_PEAK_PIN);
  187. break;
  188. case PMBUS_VIRT_READ_TEMP_MAX:
  189. if (!data->have_temp_max)
  190. return -ENXIO;
  191. ret = pmbus_read_word_data(client, 0, ADM1278_PEAK_TEMP);
  192. break;
  193. case PMBUS_VIRT_RESET_IOUT_HISTORY:
  194. case PMBUS_VIRT_RESET_VOUT_HISTORY:
  195. case PMBUS_VIRT_RESET_VIN_HISTORY:
  196. break;
  197. case PMBUS_VIRT_RESET_PIN_HISTORY:
  198. if (!data->have_pin_max)
  199. return -ENXIO;
  200. break;
  201. case PMBUS_VIRT_RESET_TEMP_HISTORY:
  202. if (!data->have_temp_max)
  203. return -ENXIO;
  204. break;
  205. default:
  206. ret = -ENODATA;
  207. break;
  208. }
  209. return ret;
  210. }
  211. static int adm1275_write_word_data(struct i2c_client *client, int page, int reg,
  212. u16 word)
  213. {
  214. const struct pmbus_driver_info *info = pmbus_get_driver_info(client);
  215. const struct adm1275_data *data = to_adm1275_data(info);
  216. int ret;
  217. if (page > 0)
  218. return -ENXIO;
  219. switch (reg) {
  220. case PMBUS_IOUT_UC_FAULT_LIMIT:
  221. case PMBUS_IOUT_OC_FAULT_LIMIT:
  222. ret = pmbus_write_word_data(client, 0, ADM1275_IOUT_WARN2_LIMIT,
  223. word);
  224. break;
  225. case PMBUS_VIRT_RESET_IOUT_HISTORY:
  226. ret = pmbus_write_word_data(client, 0, ADM1275_PEAK_IOUT, 0);
  227. if (!ret && data->have_iout_min)
  228. ret = pmbus_write_word_data(client, 0,
  229. ADM1293_IOUT_MIN, 0);
  230. break;
  231. case PMBUS_VIRT_RESET_VOUT_HISTORY:
  232. ret = pmbus_write_word_data(client, 0, ADM1275_PEAK_VOUT, 0);
  233. break;
  234. case PMBUS_VIRT_RESET_VIN_HISTORY:
  235. ret = pmbus_write_word_data(client, 0, ADM1275_PEAK_VIN, 0);
  236. break;
  237. case PMBUS_VIRT_RESET_PIN_HISTORY:
  238. ret = pmbus_write_word_data(client, 0, ADM1276_PEAK_PIN, 0);
  239. if (!ret && data->have_pin_min)
  240. ret = pmbus_write_word_data(client, 0,
  241. ADM1293_PIN_MIN, 0);
  242. break;
  243. case PMBUS_VIRT_RESET_TEMP_HISTORY:
  244. ret = pmbus_write_word_data(client, 0, ADM1278_PEAK_TEMP, 0);
  245. break;
  246. default:
  247. ret = -ENODATA;
  248. break;
  249. }
  250. return ret;
  251. }
  252. static int adm1275_read_byte_data(struct i2c_client *client, int page, int reg)
  253. {
  254. const struct pmbus_driver_info *info = pmbus_get_driver_info(client);
  255. const struct adm1275_data *data = to_adm1275_data(info);
  256. int mfr_status, ret;
  257. if (page > 0)
  258. return -ENXIO;
  259. switch (reg) {
  260. case PMBUS_STATUS_IOUT:
  261. ret = pmbus_read_byte_data(client, page, PMBUS_STATUS_IOUT);
  262. if (ret < 0)
  263. break;
  264. if (!data->have_oc_fault && !data->have_uc_fault)
  265. break;
  266. mfr_status = pmbus_read_byte_data(client, page,
  267. PMBUS_STATUS_MFR_SPECIFIC);
  268. if (mfr_status < 0)
  269. return mfr_status;
  270. if (mfr_status & ADM1275_MFR_STATUS_IOUT_WARN2) {
  271. ret |= data->have_oc_fault ?
  272. PB_IOUT_OC_FAULT : PB_IOUT_UC_FAULT;
  273. }
  274. break;
  275. case PMBUS_STATUS_VOUT:
  276. if (data->have_vout)
  277. return -ENODATA;
  278. ret = 0;
  279. if (data->have_vaux_status) {
  280. mfr_status = pmbus_read_byte_data(client, 0,
  281. ADM1075_VAUX_STATUS);
  282. if (mfr_status < 0)
  283. return mfr_status;
  284. if (mfr_status & ADM1075_VAUX_OV_WARN)
  285. ret |= PB_VOLTAGE_OV_WARNING;
  286. if (mfr_status & ADM1075_VAUX_UV_WARN)
  287. ret |= PB_VOLTAGE_UV_WARNING;
  288. } else if (data->have_mfr_vaux_status) {
  289. mfr_status = pmbus_read_byte_data(client, page,
  290. PMBUS_STATUS_MFR_SPECIFIC);
  291. if (mfr_status < 0)
  292. return mfr_status;
  293. if (mfr_status & ADM1293_MFR_STATUS_VAUX_OV_WARN)
  294. ret |= PB_VOLTAGE_OV_WARNING;
  295. if (mfr_status & ADM1293_MFR_STATUS_VAUX_UV_WARN)
  296. ret |= PB_VOLTAGE_UV_WARNING;
  297. }
  298. break;
  299. default:
  300. ret = -ENODATA;
  301. break;
  302. }
  303. return ret;
  304. }
  305. static const struct i2c_device_id adm1275_id[] = {
  306. { "adm1075", adm1075 },
  307. { "adm1275", adm1275 },
  308. { "adm1276", adm1276 },
  309. { "adm1278", adm1278 },
  310. { "adm1293", adm1293 },
  311. { "adm1294", adm1294 },
  312. { }
  313. };
  314. MODULE_DEVICE_TABLE(i2c, adm1275_id);
  315. static int adm1275_probe(struct i2c_client *client,
  316. const struct i2c_device_id *id)
  317. {
  318. u8 block_buffer[I2C_SMBUS_BLOCK_MAX + 1];
  319. int config, device_config;
  320. int ret;
  321. struct pmbus_driver_info *info;
  322. struct adm1275_data *data;
  323. const struct i2c_device_id *mid;
  324. const struct coefficients *coefficients;
  325. int vindex = -1, voindex = -1, cindex = -1, pindex = -1;
  326. int tindex = -1;
  327. if (!i2c_check_functionality(client->adapter,
  328. I2C_FUNC_SMBUS_READ_BYTE_DATA
  329. | I2C_FUNC_SMBUS_BLOCK_DATA))
  330. return -ENODEV;
  331. ret = i2c_smbus_read_block_data(client, PMBUS_MFR_ID, block_buffer);
  332. if (ret < 0) {
  333. dev_err(&client->dev, "Failed to read Manufacturer ID\n");
  334. return ret;
  335. }
  336. if (ret != 3 || strncmp(block_buffer, "ADI", 3)) {
  337. dev_err(&client->dev, "Unsupported Manufacturer ID\n");
  338. return -ENODEV;
  339. }
  340. ret = i2c_smbus_read_block_data(client, PMBUS_MFR_MODEL, block_buffer);
  341. if (ret < 0) {
  342. dev_err(&client->dev, "Failed to read Manufacturer Model\n");
  343. return ret;
  344. }
  345. for (mid = adm1275_id; mid->name[0]; mid++) {
  346. if (!strncasecmp(mid->name, block_buffer, strlen(mid->name)))
  347. break;
  348. }
  349. if (!mid->name[0]) {
  350. dev_err(&client->dev, "Unsupported device\n");
  351. return -ENODEV;
  352. }
  353. if (id->driver_data != mid->driver_data)
  354. dev_notice(&client->dev,
  355. "Device mismatch: Configured %s, detected %s\n",
  356. id->name, mid->name);
  357. config = i2c_smbus_read_byte_data(client, ADM1275_PMON_CONFIG);
  358. if (config < 0)
  359. return config;
  360. device_config = i2c_smbus_read_byte_data(client, ADM1275_DEVICE_CONFIG);
  361. if (device_config < 0)
  362. return device_config;
  363. data = devm_kzalloc(&client->dev, sizeof(struct adm1275_data),
  364. GFP_KERNEL);
  365. if (!data)
  366. return -ENOMEM;
  367. data->id = mid->driver_data;
  368. info = &data->info;
  369. info->pages = 1;
  370. info->format[PSC_VOLTAGE_IN] = direct;
  371. info->format[PSC_VOLTAGE_OUT] = direct;
  372. info->format[PSC_CURRENT_OUT] = direct;
  373. info->format[PSC_POWER] = direct;
  374. info->format[PSC_TEMPERATURE] = direct;
  375. info->func[0] = PMBUS_HAVE_IOUT | PMBUS_HAVE_STATUS_IOUT;
  376. info->read_word_data = adm1275_read_word_data;
  377. info->read_byte_data = adm1275_read_byte_data;
  378. info->write_word_data = adm1275_write_word_data;
  379. switch (data->id) {
  380. case adm1075:
  381. if (device_config & ADM1275_IOUT_WARN2_SELECT)
  382. data->have_oc_fault = true;
  383. else
  384. data->have_uc_fault = true;
  385. data->have_pin_max = true;
  386. data->have_vaux_status = true;
  387. coefficients = adm1075_coefficients;
  388. vindex = 0;
  389. switch (config & ADM1075_IRANGE_MASK) {
  390. case ADM1075_IRANGE_25:
  391. cindex = 1;
  392. pindex = 3;
  393. break;
  394. case ADM1075_IRANGE_50:
  395. cindex = 2;
  396. pindex = 4;
  397. break;
  398. default:
  399. dev_err(&client->dev, "Invalid input current range");
  400. break;
  401. }
  402. info->func[0] |= PMBUS_HAVE_VIN | PMBUS_HAVE_PIN
  403. | PMBUS_HAVE_STATUS_INPUT;
  404. if (config & ADM1275_VIN_VOUT_SELECT)
  405. info->func[0] |=
  406. PMBUS_HAVE_VOUT | PMBUS_HAVE_STATUS_VOUT;
  407. break;
  408. case adm1275:
  409. if (device_config & ADM1275_IOUT_WARN2_SELECT)
  410. data->have_oc_fault = true;
  411. else
  412. data->have_uc_fault = true;
  413. data->have_vout = true;
  414. coefficients = adm1275_coefficients;
  415. vindex = (config & ADM1275_VRANGE) ? 0 : 1;
  416. cindex = 2;
  417. if (config & ADM1275_VIN_VOUT_SELECT)
  418. info->func[0] |=
  419. PMBUS_HAVE_VOUT | PMBUS_HAVE_STATUS_VOUT;
  420. else
  421. info->func[0] |=
  422. PMBUS_HAVE_VIN | PMBUS_HAVE_STATUS_INPUT;
  423. break;
  424. case adm1276:
  425. if (device_config & ADM1275_IOUT_WARN2_SELECT)
  426. data->have_oc_fault = true;
  427. else
  428. data->have_uc_fault = true;
  429. data->have_vout = true;
  430. data->have_pin_max = true;
  431. coefficients = adm1276_coefficients;
  432. vindex = (config & ADM1275_VRANGE) ? 0 : 1;
  433. cindex = 2;
  434. pindex = (config & ADM1275_VRANGE) ? 3 : 4;
  435. info->func[0] |= PMBUS_HAVE_VIN | PMBUS_HAVE_PIN
  436. | PMBUS_HAVE_STATUS_INPUT;
  437. if (config & ADM1275_VIN_VOUT_SELECT)
  438. info->func[0] |=
  439. PMBUS_HAVE_VOUT | PMBUS_HAVE_STATUS_VOUT;
  440. break;
  441. case adm1278:
  442. data->have_vout = true;
  443. data->have_pin_max = true;
  444. data->have_temp_max = true;
  445. coefficients = adm1278_coefficients;
  446. vindex = 0;
  447. cindex = 1;
  448. pindex = 2;
  449. tindex = 3;
  450. info->func[0] |= PMBUS_HAVE_PIN | PMBUS_HAVE_STATUS_INPUT;
  451. if (config & ADM1278_TEMP1_EN)
  452. info->func[0] |=
  453. PMBUS_HAVE_TEMP | PMBUS_HAVE_STATUS_TEMP;
  454. if (config & ADM1278_VIN_EN)
  455. info->func[0] |= PMBUS_HAVE_VIN;
  456. if (config & ADM1278_VOUT_EN)
  457. info->func[0] |=
  458. PMBUS_HAVE_VOUT | PMBUS_HAVE_STATUS_VOUT;
  459. break;
  460. case adm1293:
  461. case adm1294:
  462. data->have_iout_min = true;
  463. data->have_pin_min = true;
  464. data->have_pin_max = true;
  465. data->have_mfr_vaux_status = true;
  466. coefficients = adm1293_coefficients;
  467. voindex = 0;
  468. switch (config & ADM1293_VIN_SEL_MASK) {
  469. case ADM1293_VIN_SEL_012: /* 1.2V */
  470. vindex = 0;
  471. break;
  472. case ADM1293_VIN_SEL_074: /* 7.4V */
  473. vindex = 1;
  474. break;
  475. case ADM1293_VIN_SEL_210: /* 21V */
  476. vindex = 2;
  477. break;
  478. default: /* disabled */
  479. break;
  480. }
  481. switch (config & ADM1293_IRANGE_MASK) {
  482. case ADM1293_IRANGE_25:
  483. cindex = 3;
  484. break;
  485. case ADM1293_IRANGE_50:
  486. cindex = 4;
  487. break;
  488. case ADM1293_IRANGE_100:
  489. cindex = 5;
  490. break;
  491. case ADM1293_IRANGE_200:
  492. cindex = 6;
  493. break;
  494. }
  495. if (vindex >= 0)
  496. pindex = 7 + vindex * 4 + (cindex - 3);
  497. if (config & ADM1293_VAUX_EN)
  498. info->func[0] |=
  499. PMBUS_HAVE_VOUT | PMBUS_HAVE_STATUS_VOUT;
  500. info->func[0] |= PMBUS_HAVE_PIN |
  501. PMBUS_HAVE_VIN | PMBUS_HAVE_STATUS_INPUT;
  502. break;
  503. default:
  504. dev_err(&client->dev, "Unsupported device\n");
  505. return -ENODEV;
  506. }
  507. if (voindex < 0)
  508. voindex = vindex;
  509. if (vindex >= 0) {
  510. info->m[PSC_VOLTAGE_IN] = coefficients[vindex].m;
  511. info->b[PSC_VOLTAGE_IN] = coefficients[vindex].b;
  512. info->R[PSC_VOLTAGE_IN] = coefficients[vindex].R;
  513. }
  514. if (voindex >= 0) {
  515. info->m[PSC_VOLTAGE_OUT] = coefficients[voindex].m;
  516. info->b[PSC_VOLTAGE_OUT] = coefficients[voindex].b;
  517. info->R[PSC_VOLTAGE_OUT] = coefficients[voindex].R;
  518. }
  519. if (cindex >= 0) {
  520. info->m[PSC_CURRENT_OUT] = coefficients[cindex].m;
  521. info->b[PSC_CURRENT_OUT] = coefficients[cindex].b;
  522. info->R[PSC_CURRENT_OUT] = coefficients[cindex].R;
  523. }
  524. if (pindex >= 0) {
  525. info->m[PSC_POWER] = coefficients[pindex].m;
  526. info->b[PSC_POWER] = coefficients[pindex].b;
  527. info->R[PSC_POWER] = coefficients[pindex].R;
  528. }
  529. if (tindex >= 0) {
  530. info->m[PSC_TEMPERATURE] = coefficients[tindex].m;
  531. info->b[PSC_TEMPERATURE] = coefficients[tindex].b;
  532. info->R[PSC_TEMPERATURE] = coefficients[tindex].R;
  533. }
  534. return pmbus_do_probe(client, id, info);
  535. }
  536. static struct i2c_driver adm1275_driver = {
  537. .driver = {
  538. .name = "adm1275",
  539. },
  540. .probe = adm1275_probe,
  541. .remove = pmbus_do_remove,
  542. .id_table = adm1275_id,
  543. };
  544. module_i2c_driver(adm1275_driver);
  545. MODULE_AUTHOR("Guenter Roeck");
  546. MODULE_DESCRIPTION("PMBus driver for Analog Devices ADM1275 and compatibles");
  547. MODULE_LICENSE("GPL");