max16064.c 3.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128
  1. /*
  2. * Hardware monitoring driver for Maxim MAX16064
  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 MAX16064_MFR_VOUT_PEAK 0xd4
  27. #define MAX16064_MFR_TEMPERATURE_PEAK 0xd6
  28. static int max16064_read_word_data(struct i2c_client *client, int page, int reg)
  29. {
  30. int ret;
  31. switch (reg) {
  32. case PMBUS_VIRT_READ_VOUT_MAX:
  33. ret = pmbus_read_word_data(client, page,
  34. MAX16064_MFR_VOUT_PEAK);
  35. break;
  36. case PMBUS_VIRT_READ_TEMP_MAX:
  37. ret = pmbus_read_word_data(client, page,
  38. MAX16064_MFR_TEMPERATURE_PEAK);
  39. break;
  40. case PMBUS_VIRT_RESET_VOUT_HISTORY:
  41. case PMBUS_VIRT_RESET_TEMP_HISTORY:
  42. ret = 0;
  43. break;
  44. default:
  45. ret = -ENODATA;
  46. break;
  47. }
  48. return ret;
  49. }
  50. static int max16064_write_word_data(struct i2c_client *client, int page,
  51. int reg, u16 word)
  52. {
  53. int ret;
  54. switch (reg) {
  55. case PMBUS_VIRT_RESET_VOUT_HISTORY:
  56. ret = pmbus_write_word_data(client, page,
  57. MAX16064_MFR_VOUT_PEAK, 0);
  58. break;
  59. case PMBUS_VIRT_RESET_TEMP_HISTORY:
  60. ret = pmbus_write_word_data(client, page,
  61. MAX16064_MFR_TEMPERATURE_PEAK,
  62. 0xffff);
  63. break;
  64. default:
  65. ret = -ENODATA;
  66. break;
  67. }
  68. return ret;
  69. }
  70. static struct pmbus_driver_info max16064_info = {
  71. .pages = 4,
  72. .format[PSC_VOLTAGE_IN] = direct,
  73. .format[PSC_VOLTAGE_OUT] = direct,
  74. .format[PSC_TEMPERATURE] = direct,
  75. .m[PSC_VOLTAGE_IN] = 19995,
  76. .b[PSC_VOLTAGE_IN] = 0,
  77. .R[PSC_VOLTAGE_IN] = -1,
  78. .m[PSC_VOLTAGE_OUT] = 19995,
  79. .b[PSC_VOLTAGE_OUT] = 0,
  80. .R[PSC_VOLTAGE_OUT] = -1,
  81. .m[PSC_TEMPERATURE] = -7612,
  82. .b[PSC_TEMPERATURE] = 335,
  83. .R[PSC_TEMPERATURE] = -3,
  84. .func[0] = PMBUS_HAVE_VOUT | PMBUS_HAVE_TEMP
  85. | PMBUS_HAVE_STATUS_VOUT | PMBUS_HAVE_STATUS_TEMP,
  86. .func[1] = PMBUS_HAVE_VOUT | PMBUS_HAVE_STATUS_VOUT,
  87. .func[2] = PMBUS_HAVE_VOUT | PMBUS_HAVE_STATUS_VOUT,
  88. .func[3] = PMBUS_HAVE_VOUT | PMBUS_HAVE_STATUS_VOUT,
  89. .read_word_data = max16064_read_word_data,
  90. .write_word_data = max16064_write_word_data,
  91. };
  92. static int max16064_probe(struct i2c_client *client,
  93. const struct i2c_device_id *id)
  94. {
  95. return pmbus_do_probe(client, id, &max16064_info);
  96. }
  97. static const struct i2c_device_id max16064_id[] = {
  98. {"max16064", 0},
  99. {}
  100. };
  101. MODULE_DEVICE_TABLE(i2c, max16064_id);
  102. /* This is the driver that will be inserted */
  103. static struct i2c_driver max16064_driver = {
  104. .driver = {
  105. .name = "max16064",
  106. },
  107. .probe = max16064_probe,
  108. .remove = pmbus_do_remove,
  109. .id_table = max16064_id,
  110. };
  111. module_i2c_driver(max16064_driver);
  112. MODULE_AUTHOR("Guenter Roeck");
  113. MODULE_DESCRIPTION("PMBus driver for Maxim MAX16064");
  114. MODULE_LICENSE("GPL");