bel-pfe.c 3.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132
  1. // SPDX-License-Identifier: GPL-2.0+
  2. /*
  3. * Hardware monitoring driver for BEL PFE family power supplies.
  4. *
  5. * Copyright (c) 2019 Facebook Inc.
  6. */
  7. #include <linux/err.h>
  8. #include <linux/i2c.h>
  9. #include <linux/init.h>
  10. #include <linux/kernel.h>
  11. #include <linux/module.h>
  12. #include <linux/pmbus.h>
  13. #include "pmbus.h"
  14. enum chips {pfe1100, pfe3000};
  15. /*
  16. * Disable status check because some devices report communication error
  17. * (invalid command) for VOUT_MODE command (0x20) although the correct
  18. * VOUT_MODE (0x16) is returned: it leads to incorrect exponent in linear
  19. * mode.
  20. * This affects both pfe3000 and pfe1100.
  21. */
  22. static struct pmbus_platform_data pfe_plat_data = {
  23. .flags = PMBUS_SKIP_STATUS_CHECK,
  24. };
  25. static struct pmbus_driver_info pfe_driver_info[] = {
  26. [pfe1100] = {
  27. .pages = 1,
  28. .format[PSC_VOLTAGE_IN] = linear,
  29. .format[PSC_VOLTAGE_OUT] = linear,
  30. .format[PSC_CURRENT_IN] = linear,
  31. .format[PSC_CURRENT_OUT] = linear,
  32. .format[PSC_POWER] = linear,
  33. .format[PSC_TEMPERATURE] = linear,
  34. .format[PSC_FAN] = linear,
  35. .func[0] = PMBUS_HAVE_VOUT | PMBUS_HAVE_STATUS_VOUT |
  36. PMBUS_HAVE_IOUT | PMBUS_HAVE_STATUS_IOUT |
  37. PMBUS_HAVE_POUT |
  38. PMBUS_HAVE_VIN | PMBUS_HAVE_IIN |
  39. PMBUS_HAVE_PIN | PMBUS_HAVE_STATUS_INPUT |
  40. PMBUS_HAVE_TEMP | PMBUS_HAVE_TEMP2 |
  41. PMBUS_HAVE_STATUS_TEMP |
  42. PMBUS_HAVE_FAN12,
  43. },
  44. [pfe3000] = {
  45. .pages = 7,
  46. .format[PSC_VOLTAGE_IN] = linear,
  47. .format[PSC_VOLTAGE_OUT] = linear,
  48. .format[PSC_CURRENT_IN] = linear,
  49. .format[PSC_CURRENT_OUT] = linear,
  50. .format[PSC_POWER] = linear,
  51. .format[PSC_TEMPERATURE] = linear,
  52. .format[PSC_FAN] = linear,
  53. /* Page 0: V1. */
  54. .func[0] = PMBUS_HAVE_VOUT | PMBUS_HAVE_STATUS_VOUT |
  55. PMBUS_HAVE_IOUT | PMBUS_HAVE_STATUS_IOUT |
  56. PMBUS_HAVE_POUT | PMBUS_HAVE_FAN12 |
  57. PMBUS_HAVE_VIN | PMBUS_HAVE_IIN |
  58. PMBUS_HAVE_PIN | PMBUS_HAVE_STATUS_INPUT |
  59. PMBUS_HAVE_TEMP | PMBUS_HAVE_TEMP2 |
  60. PMBUS_HAVE_TEMP3 | PMBUS_HAVE_STATUS_TEMP |
  61. PMBUS_HAVE_VCAP,
  62. /* Page 1: Vsb. */
  63. .func[1] = PMBUS_HAVE_VOUT | PMBUS_HAVE_STATUS_VOUT |
  64. PMBUS_HAVE_IOUT | PMBUS_HAVE_STATUS_IOUT |
  65. PMBUS_HAVE_PIN | PMBUS_HAVE_STATUS_INPUT |
  66. PMBUS_HAVE_POUT,
  67. /*
  68. * Page 2: V1 Ishare.
  69. * Page 3: Reserved.
  70. * Page 4: V1 Cathode.
  71. * Page 5: Vsb Cathode.
  72. * Page 6: V1 Sense.
  73. */
  74. .func[2] = PMBUS_HAVE_VOUT,
  75. .func[4] = PMBUS_HAVE_VOUT,
  76. .func[5] = PMBUS_HAVE_VOUT,
  77. .func[6] = PMBUS_HAVE_VOUT,
  78. },
  79. };
  80. static const struct i2c_device_id pfe_device_id[];
  81. static int pfe_pmbus_probe(struct i2c_client *client)
  82. {
  83. int model;
  84. model = (int)i2c_match_id(pfe_device_id, client)->driver_data;
  85. client->dev.platform_data = &pfe_plat_data;
  86. /*
  87. * PFE3000-12-069RA devices may not stay in page 0 during device
  88. * probe which leads to probe failure (read status word failed).
  89. * So let's set the device to page 0 at the beginning.
  90. */
  91. if (model == pfe3000)
  92. i2c_smbus_write_byte_data(client, PMBUS_PAGE, 0);
  93. return pmbus_do_probe(client, &pfe_driver_info[model]);
  94. }
  95. static const struct i2c_device_id pfe_device_id[] = {
  96. {"pfe1100", pfe1100},
  97. {"pfe3000", pfe3000},
  98. {}
  99. };
  100. MODULE_DEVICE_TABLE(i2c, pfe_device_id);
  101. static struct i2c_driver pfe_pmbus_driver = {
  102. .driver = {
  103. .name = "bel-pfe",
  104. },
  105. .probe_new = pfe_pmbus_probe,
  106. .id_table = pfe_device_id,
  107. };
  108. module_i2c_driver(pfe_pmbus_driver);
  109. MODULE_AUTHOR("Tao Ren <[email protected]>");
  110. MODULE_DESCRIPTION("PMBus driver for BEL PFE Family Power Supplies");
  111. MODULE_LICENSE("GPL");
  112. MODULE_IMPORT_NS(PMBUS);