max8688.c 4.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159
  1. /*
  2. * Hardware monitoring driver for Maxim MAX8688
  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. #define MAX8688_MFG_STATUS 0xd8
  27. #define MAX8688_STATUS_OC_FAULT (1 << 4)
  28. #define MAX8688_STATUS_OV_FAULT (1 << 5)
  29. #define MAX8688_STATUS_OV_WARNING (1 << 8)
  30. #define MAX8688_STATUS_UV_FAULT (1 << 9)
  31. #define MAX8688_STATUS_UV_WARNING (1 << 10)
  32. #define MAX8688_STATUS_UC_FAULT (1 << 11)
  33. #define MAX8688_STATUS_OC_WARNING (1 << 12)
  34. #define MAX8688_STATUS_OT_FAULT (1 << 13)
  35. #define MAX8688_STATUS_OT_WARNING (1 << 14)
  36. static int max8688_read_byte_data(struct i2c_client *client, int page, int reg)
  37. {
  38. int ret = 0;
  39. int mfg_status;
  40. if (page)
  41. return -EINVAL;
  42. switch (reg) {
  43. case PMBUS_STATUS_VOUT:
  44. mfg_status = pmbus_read_word_data(client, 0,
  45. MAX8688_MFG_STATUS);
  46. if (mfg_status < 0)
  47. return mfg_status;
  48. if (mfg_status & MAX8688_STATUS_UV_WARNING)
  49. ret |= PB_VOLTAGE_UV_WARNING;
  50. if (mfg_status & MAX8688_STATUS_UV_FAULT)
  51. ret |= PB_VOLTAGE_UV_FAULT;
  52. if (mfg_status & MAX8688_STATUS_OV_WARNING)
  53. ret |= PB_VOLTAGE_OV_WARNING;
  54. if (mfg_status & MAX8688_STATUS_OV_FAULT)
  55. ret |= PB_VOLTAGE_OV_FAULT;
  56. break;
  57. case PMBUS_STATUS_IOUT:
  58. mfg_status = pmbus_read_word_data(client, 0,
  59. MAX8688_MFG_STATUS);
  60. if (mfg_status < 0)
  61. return mfg_status;
  62. if (mfg_status & MAX8688_STATUS_UC_FAULT)
  63. ret |= PB_IOUT_UC_FAULT;
  64. if (mfg_status & MAX8688_STATUS_OC_WARNING)
  65. ret |= PB_IOUT_OC_WARNING;
  66. if (mfg_status & MAX8688_STATUS_OC_FAULT)
  67. ret |= PB_IOUT_OC_FAULT;
  68. break;
  69. case PMBUS_STATUS_TEMPERATURE:
  70. mfg_status = pmbus_read_word_data(client, 0,
  71. MAX8688_MFG_STATUS);
  72. if (mfg_status < 0)
  73. return mfg_status;
  74. if (mfg_status & MAX8688_STATUS_OT_WARNING)
  75. ret |= PB_TEMP_OT_WARNING;
  76. if (mfg_status & MAX8688_STATUS_OT_FAULT)
  77. ret |= PB_TEMP_OT_FAULT;
  78. break;
  79. default:
  80. ret = -ENODATA;
  81. break;
  82. }
  83. return ret;
  84. }
  85. static struct pmbus_driver_info max8688_info = {
  86. .pages = 1,
  87. .direct[PSC_VOLTAGE_IN] = true,
  88. .direct[PSC_VOLTAGE_OUT] = true,
  89. .direct[PSC_TEMPERATURE] = true,
  90. .direct[PSC_CURRENT_OUT] = true,
  91. .m[PSC_VOLTAGE_IN] = 19995,
  92. .b[PSC_VOLTAGE_IN] = 0,
  93. .R[PSC_VOLTAGE_IN] = -1,
  94. .m[PSC_VOLTAGE_OUT] = 19995,
  95. .b[PSC_VOLTAGE_OUT] = 0,
  96. .R[PSC_VOLTAGE_OUT] = -1,
  97. .m[PSC_CURRENT_OUT] = 23109,
  98. .b[PSC_CURRENT_OUT] = 0,
  99. .R[PSC_CURRENT_OUT] = -2,
  100. .m[PSC_TEMPERATURE] = -7612,
  101. .b[PSC_TEMPERATURE] = 335,
  102. .R[PSC_TEMPERATURE] = -3,
  103. .func[0] = PMBUS_HAVE_VOUT | PMBUS_HAVE_IOUT | PMBUS_HAVE_TEMP
  104. | PMBUS_HAVE_STATUS_VOUT | PMBUS_HAVE_STATUS_IOUT
  105. | PMBUS_HAVE_STATUS_TEMP,
  106. .read_byte_data = max8688_read_byte_data,
  107. };
  108. static int max8688_probe(struct i2c_client *client,
  109. const struct i2c_device_id *id)
  110. {
  111. return pmbus_do_probe(client, id, &max8688_info);
  112. }
  113. static int max8688_remove(struct i2c_client *client)
  114. {
  115. return pmbus_do_remove(client);
  116. }
  117. static const struct i2c_device_id max8688_id[] = {
  118. {"max8688", 0},
  119. { }
  120. };
  121. MODULE_DEVICE_TABLE(i2c, max8688_id);
  122. /* This is the driver that will be inserted */
  123. static struct i2c_driver max8688_driver = {
  124. .driver = {
  125. .name = "max8688",
  126. },
  127. .probe = max8688_probe,
  128. .remove = max8688_remove,
  129. .id_table = max8688_id,
  130. };
  131. static int __init max8688_init(void)
  132. {
  133. return i2c_add_driver(&max8688_driver);
  134. }
  135. static void __exit max8688_exit(void)
  136. {
  137. i2c_del_driver(&max8688_driver);
  138. }
  139. MODULE_AUTHOR("Guenter Roeck");
  140. MODULE_DESCRIPTION("PMBus driver for Maxim MAX8688");
  141. MODULE_LICENSE("GPL");
  142. module_init(max8688_init);
  143. module_exit(max8688_exit);