tps53679.c 3.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121
  1. /*
  2. * Hardware monitoring driver for Texas Instruments TPS53679
  3. *
  4. * Copyright (c) 2017 Mellanox Technologies. All rights reserved.
  5. * Copyright (c) 2017 Vadim Pasternak <vadimp@mellanox.com>
  6. *
  7. * This program is free software; you can redistribute it and/or modify
  8. * it under the terms of the GNU General Public License as published by
  9. * the Free Software Foundation; either version 2 of the License, or
  10. * (at your option) any later version.
  11. *
  12. * This program is distributed in the hope that it will be useful,
  13. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  14. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  15. * GNU General Public License for more details.
  16. */
  17. #include <linux/err.h>
  18. #include <linux/i2c.h>
  19. #include <linux/init.h>
  20. #include <linux/kernel.h>
  21. #include <linux/module.h>
  22. #include "pmbus.h"
  23. #define TPS53679_PROT_VR12_5MV 0x01 /* VR12.0 mode, 5-mV DAC */
  24. #define TPS53679_PROT_VR12_5_10MV 0x02 /* VR12.5 mode, 10-mV DAC */
  25. #define TPS53679_PROT_VR13_10MV 0x04 /* VR13.0 mode, 10-mV DAC */
  26. #define TPS53679_PROT_IMVP8_5MV 0x05 /* IMVP8 mode, 5-mV DAC */
  27. #define TPS53679_PROT_VR13_5MV 0x07 /* VR13.0 mode, 5-mV DAC */
  28. #define TPS53679_PAGE_NUM 2
  29. static int tps53679_identify(struct i2c_client *client,
  30. struct pmbus_driver_info *info)
  31. {
  32. u8 vout_params;
  33. int ret;
  34. /* Read the register with VOUT scaling value.*/
  35. ret = pmbus_read_byte_data(client, 0, PMBUS_VOUT_MODE);
  36. if (ret < 0)
  37. return ret;
  38. vout_params = ret & GENMASK(4, 0);
  39. switch (vout_params) {
  40. case TPS53679_PROT_VR13_10MV:
  41. case TPS53679_PROT_VR12_5_10MV:
  42. info->vrm_version = vr13;
  43. break;
  44. case TPS53679_PROT_VR13_5MV:
  45. case TPS53679_PROT_VR12_5MV:
  46. case TPS53679_PROT_IMVP8_5MV:
  47. info->vrm_version = vr12;
  48. break;
  49. default:
  50. return -EINVAL;
  51. }
  52. return 0;
  53. }
  54. static struct pmbus_driver_info tps53679_info = {
  55. .pages = TPS53679_PAGE_NUM,
  56. .format[PSC_VOLTAGE_IN] = linear,
  57. .format[PSC_VOLTAGE_OUT] = vid,
  58. .format[PSC_TEMPERATURE] = linear,
  59. .format[PSC_CURRENT_OUT] = linear,
  60. .format[PSC_POWER] = linear,
  61. .func[0] = PMBUS_HAVE_VIN | PMBUS_HAVE_VOUT | PMBUS_HAVE_STATUS_VOUT |
  62. PMBUS_HAVE_IOUT | PMBUS_HAVE_STATUS_IOUT |
  63. PMBUS_HAVE_TEMP | PMBUS_HAVE_STATUS_TEMP |
  64. PMBUS_HAVE_POUT,
  65. .func[1] = PMBUS_HAVE_VIN | PMBUS_HAVE_VOUT | PMBUS_HAVE_STATUS_VOUT |
  66. PMBUS_HAVE_IOUT | PMBUS_HAVE_STATUS_IOUT |
  67. PMBUS_HAVE_TEMP | PMBUS_HAVE_STATUS_TEMP |
  68. PMBUS_HAVE_POUT,
  69. .identify = tps53679_identify,
  70. };
  71. static int tps53679_probe(struct i2c_client *client,
  72. const struct i2c_device_id *id)
  73. {
  74. struct pmbus_driver_info *info;
  75. info = devm_kmemdup(&client->dev, &tps53679_info, sizeof(*info),
  76. GFP_KERNEL);
  77. if (!info)
  78. return -ENOMEM;
  79. return pmbus_do_probe(client, id, info);
  80. }
  81. static const struct i2c_device_id tps53679_id[] = {
  82. {"tps53679", 0},
  83. {}
  84. };
  85. MODULE_DEVICE_TABLE(i2c, tps53679_id);
  86. static const struct of_device_id tps53679_of_match[] = {
  87. {.compatible = "ti,tps53679"},
  88. {}
  89. };
  90. MODULE_DEVICE_TABLE(of, tps53679_of_match);
  91. static struct i2c_driver tps53679_driver = {
  92. .driver = {
  93. .name = "tps53679",
  94. .of_match_table = of_match_ptr(tps53679_of_match),
  95. },
  96. .probe = tps53679_probe,
  97. .remove = pmbus_do_remove,
  98. .id_table = tps53679_id,
  99. };
  100. module_i2c_driver(tps53679_driver);
  101. MODULE_AUTHOR("Vadim Pasternak <vadimp@mellanox.com>");
  102. MODULE_DESCRIPTION("PMBus driver for Texas Instruments TPS53679");
  103. MODULE_LICENSE("GPL");