max34440.c 6.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200
  1. /*
  2. * Hardware monitoring driver for Maxim MAX34440/MAX34441
  3. *
  4. * Copyright (c) 2011 Ericsson AB.
  5. *
  6. * This program is free software; you can redistribute it and/or modify
  7. * it under the terms of the GNU General Public License as published by
  8. * the Free Software Foundation; either version 2 of the License, or
  9. * (at your option) any later version.
  10. *
  11. * This program is distributed in the hope that it will be useful,
  12. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  13. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  14. * GNU General Public License for more details.
  15. *
  16. * You should have received a copy of the GNU General Public License
  17. * along with this program; if not, write to the Free Software
  18. * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
  19. */
  20. #include <linux/kernel.h>
  21. #include <linux/module.h>
  22. #include <linux/init.h>
  23. #include <linux/err.h>
  24. #include <linux/i2c.h>
  25. #include "pmbus.h"
  26. enum chips { max34440, max34441 };
  27. #define MAX34440_STATUS_OC_WARN (1 << 0)
  28. #define MAX34440_STATUS_OC_FAULT (1 << 1)
  29. #define MAX34440_STATUS_OT_FAULT (1 << 5)
  30. #define MAX34440_STATUS_OT_WARN (1 << 6)
  31. static int max34440_read_byte_data(struct i2c_client *client, int page, int reg)
  32. {
  33. int ret;
  34. int mfg_status;
  35. ret = pmbus_set_page(client, page);
  36. if (ret < 0)
  37. return ret;
  38. switch (reg) {
  39. case PMBUS_STATUS_IOUT:
  40. mfg_status = pmbus_read_word_data(client, 0,
  41. PMBUS_STATUS_MFR_SPECIFIC);
  42. if (mfg_status < 0)
  43. return mfg_status;
  44. if (mfg_status & MAX34440_STATUS_OC_WARN)
  45. ret |= PB_IOUT_OC_WARNING;
  46. if (mfg_status & MAX34440_STATUS_OC_FAULT)
  47. ret |= PB_IOUT_OC_FAULT;
  48. break;
  49. case PMBUS_STATUS_TEMPERATURE:
  50. mfg_status = pmbus_read_word_data(client, 0,
  51. PMBUS_STATUS_MFR_SPECIFIC);
  52. if (mfg_status < 0)
  53. return mfg_status;
  54. if (mfg_status & MAX34440_STATUS_OT_WARN)
  55. ret |= PB_TEMP_OT_WARNING;
  56. if (mfg_status & MAX34440_STATUS_OT_FAULT)
  57. ret |= PB_TEMP_OT_FAULT;
  58. break;
  59. default:
  60. ret = -ENODATA;
  61. break;
  62. }
  63. return ret;
  64. }
  65. static struct pmbus_driver_info max34440_info[] = {
  66. [max34440] = {
  67. .pages = 14,
  68. .direct[PSC_VOLTAGE_IN] = true,
  69. .direct[PSC_VOLTAGE_OUT] = true,
  70. .direct[PSC_TEMPERATURE] = true,
  71. .direct[PSC_CURRENT_OUT] = true,
  72. .m[PSC_VOLTAGE_IN] = 1,
  73. .b[PSC_VOLTAGE_IN] = 0,
  74. .R[PSC_VOLTAGE_IN] = 3, /* R = 0 in datasheet reflects mV */
  75. .m[PSC_VOLTAGE_OUT] = 1,
  76. .b[PSC_VOLTAGE_OUT] = 0,
  77. .R[PSC_VOLTAGE_OUT] = 3, /* R = 0 in datasheet reflects mV */
  78. .m[PSC_CURRENT_OUT] = 1,
  79. .b[PSC_CURRENT_OUT] = 0,
  80. .R[PSC_CURRENT_OUT] = 3, /* R = 0 in datasheet reflects mA */
  81. .m[PSC_TEMPERATURE] = 1,
  82. .b[PSC_TEMPERATURE] = 0,
  83. .R[PSC_TEMPERATURE] = 2,
  84. .func[0] = PMBUS_HAVE_VOUT | PMBUS_HAVE_STATUS_VOUT
  85. | PMBUS_HAVE_IOUT | PMBUS_HAVE_STATUS_IOUT,
  86. .func[1] = PMBUS_HAVE_VOUT | PMBUS_HAVE_STATUS_VOUT
  87. | PMBUS_HAVE_IOUT | PMBUS_HAVE_STATUS_IOUT,
  88. .func[2] = PMBUS_HAVE_VOUT | PMBUS_HAVE_STATUS_VOUT
  89. | PMBUS_HAVE_IOUT | PMBUS_HAVE_STATUS_IOUT,
  90. .func[3] = PMBUS_HAVE_VOUT | PMBUS_HAVE_STATUS_VOUT
  91. | PMBUS_HAVE_IOUT | PMBUS_HAVE_STATUS_IOUT,
  92. .func[4] = PMBUS_HAVE_VOUT | PMBUS_HAVE_STATUS_VOUT
  93. | PMBUS_HAVE_IOUT | PMBUS_HAVE_STATUS_IOUT,
  94. .func[5] = PMBUS_HAVE_VOUT | PMBUS_HAVE_STATUS_VOUT
  95. | PMBUS_HAVE_IOUT | PMBUS_HAVE_STATUS_IOUT,
  96. .func[6] = PMBUS_HAVE_TEMP | PMBUS_HAVE_STATUS_TEMP,
  97. .func[7] = PMBUS_HAVE_TEMP | PMBUS_HAVE_STATUS_TEMP,
  98. .func[8] = PMBUS_HAVE_TEMP | PMBUS_HAVE_STATUS_TEMP,
  99. .func[9] = PMBUS_HAVE_TEMP | PMBUS_HAVE_STATUS_TEMP,
  100. .func[10] = PMBUS_HAVE_TEMP | PMBUS_HAVE_STATUS_TEMP,
  101. .func[11] = PMBUS_HAVE_TEMP | PMBUS_HAVE_STATUS_TEMP,
  102. .func[12] = PMBUS_HAVE_TEMP | PMBUS_HAVE_STATUS_TEMP,
  103. .func[13] = PMBUS_HAVE_TEMP | PMBUS_HAVE_STATUS_TEMP,
  104. .read_byte_data = max34440_read_byte_data,
  105. },
  106. [max34441] = {
  107. .pages = 12,
  108. .direct[PSC_VOLTAGE_IN] = true,
  109. .direct[PSC_VOLTAGE_OUT] = true,
  110. .direct[PSC_TEMPERATURE] = true,
  111. .direct[PSC_CURRENT_OUT] = true,
  112. .direct[PSC_FAN] = true,
  113. .m[PSC_VOLTAGE_IN] = 1,
  114. .b[PSC_VOLTAGE_IN] = 0,
  115. .R[PSC_VOLTAGE_IN] = 3,
  116. .m[PSC_VOLTAGE_OUT] = 1,
  117. .b[PSC_VOLTAGE_OUT] = 0,
  118. .R[PSC_VOLTAGE_OUT] = 3,
  119. .m[PSC_CURRENT_OUT] = 1,
  120. .b[PSC_CURRENT_OUT] = 0,
  121. .R[PSC_CURRENT_OUT] = 3,
  122. .m[PSC_TEMPERATURE] = 1,
  123. .b[PSC_TEMPERATURE] = 0,
  124. .R[PSC_TEMPERATURE] = 2,
  125. .m[PSC_FAN] = 1,
  126. .b[PSC_FAN] = 0,
  127. .R[PSC_FAN] = 0,
  128. .func[0] = PMBUS_HAVE_VOUT | PMBUS_HAVE_STATUS_VOUT
  129. | PMBUS_HAVE_IOUT | PMBUS_HAVE_STATUS_IOUT,
  130. .func[1] = PMBUS_HAVE_VOUT | PMBUS_HAVE_STATUS_VOUT
  131. | PMBUS_HAVE_IOUT | PMBUS_HAVE_STATUS_IOUT,
  132. .func[2] = PMBUS_HAVE_VOUT | PMBUS_HAVE_STATUS_VOUT
  133. | PMBUS_HAVE_IOUT | PMBUS_HAVE_STATUS_IOUT,
  134. .func[3] = PMBUS_HAVE_VOUT | PMBUS_HAVE_STATUS_VOUT
  135. | PMBUS_HAVE_IOUT | PMBUS_HAVE_STATUS_IOUT,
  136. .func[4] = PMBUS_HAVE_VOUT | PMBUS_HAVE_STATUS_VOUT
  137. | PMBUS_HAVE_IOUT | PMBUS_HAVE_STATUS_IOUT,
  138. .func[5] = PMBUS_HAVE_FAN12 | PMBUS_HAVE_STATUS_FAN12,
  139. .func[6] = PMBUS_HAVE_TEMP | PMBUS_HAVE_STATUS_TEMP,
  140. .func[7] = PMBUS_HAVE_TEMP | PMBUS_HAVE_STATUS_TEMP,
  141. .func[8] = PMBUS_HAVE_TEMP | PMBUS_HAVE_STATUS_TEMP,
  142. .func[9] = PMBUS_HAVE_TEMP | PMBUS_HAVE_STATUS_TEMP,
  143. .func[10] = PMBUS_HAVE_TEMP | PMBUS_HAVE_STATUS_TEMP,
  144. .func[11] = PMBUS_HAVE_TEMP | PMBUS_HAVE_STATUS_TEMP,
  145. .read_byte_data = max34440_read_byte_data,
  146. },
  147. };
  148. static int max34440_probe(struct i2c_client *client,
  149. const struct i2c_device_id *id)
  150. {
  151. return pmbus_do_probe(client, id, &max34440_info[id->driver_data]);
  152. }
  153. static int max34440_remove(struct i2c_client *client)
  154. {
  155. return pmbus_do_remove(client);
  156. }
  157. static const struct i2c_device_id max34440_id[] = {
  158. {"max34440", max34440},
  159. {"max34441", max34441},
  160. {}
  161. };
  162. MODULE_DEVICE_TABLE(i2c, max34440_id);
  163. /* This is the driver that will be inserted */
  164. static struct i2c_driver max34440_driver = {
  165. .driver = {
  166. .name = "max34440",
  167. },
  168. .probe = max34440_probe,
  169. .remove = max34440_remove,
  170. .id_table = max34440_id,
  171. };
  172. static int __init max34440_init(void)
  173. {
  174. return i2c_add_driver(&max34440_driver);
  175. }
  176. static void __exit max34440_exit(void)
  177. {
  178. i2c_del_driver(&max34440_driver);
  179. }
  180. MODULE_AUTHOR("Guenter Roeck");
  181. MODULE_DESCRIPTION("PMBus driver for Maxim MAX34440/MAX34441");
  182. MODULE_LICENSE("GPL");
  183. module_init(max34440_init);
  184. module_exit(max34440_exit);