adm1275.c 19 KB

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