tps546d24.c 1.7 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071
  1. // SPDX-License-Identifier: GPL-2.0+
  2. /*
  3. * Hardware monitoring driver for TEXAS TPS546D24 buck converter
  4. */
  5. #include <linux/err.h>
  6. #include <linux/i2c.h>
  7. #include <linux/init.h>
  8. #include <linux/kernel.h>
  9. #include <linux/module.h>
  10. #include <linux/pmbus.h>
  11. #include "pmbus.h"
  12. static struct pmbus_driver_info tps546d24_info = {
  13. .pages = 1,
  14. .format[PSC_VOLTAGE_IN] = linear,
  15. .format[PSC_VOLTAGE_OUT] = linear,
  16. .format[PSC_TEMPERATURE] = linear,
  17. .format[PSC_CURRENT_OUT] = linear,
  18. .func[0] = PMBUS_HAVE_VIN | PMBUS_HAVE_IIN
  19. | PMBUS_HAVE_IOUT | PMBUS_HAVE_VOUT
  20. | PMBUS_HAVE_STATUS_IOUT | PMBUS_HAVE_STATUS_VOUT
  21. | PMBUS_HAVE_TEMP | PMBUS_HAVE_STATUS_TEMP,
  22. };
  23. static int tps546d24_probe(struct i2c_client *client)
  24. {
  25. int reg;
  26. reg = i2c_smbus_read_byte_data(client, PMBUS_VOUT_MODE);
  27. if (reg < 0)
  28. return reg;
  29. if (reg & 0x80) {
  30. int err;
  31. err = i2c_smbus_write_byte_data(client, PMBUS_VOUT_MODE, reg & 0x7f);
  32. if (err < 0)
  33. return err;
  34. }
  35. return pmbus_do_probe(client, &tps546d24_info);
  36. }
  37. static const struct i2c_device_id tps546d24_id[] = {
  38. {"tps546d24", 0},
  39. {}
  40. };
  41. MODULE_DEVICE_TABLE(i2c, tps546d24_id);
  42. static const struct of_device_id __maybe_unused tps546d24_of_match[] = {
  43. {.compatible = "ti,tps546d24"},
  44. {}
  45. };
  46. MODULE_DEVICE_TABLE(of, tps546d24_of_match);
  47. /* This is the driver that will be inserted */
  48. static struct i2c_driver tps546d24_driver = {
  49. .driver = {
  50. .name = "tps546d24",
  51. .of_match_table = of_match_ptr(tps546d24_of_match),
  52. },
  53. .probe_new = tps546d24_probe,
  54. .id_table = tps546d24_id,
  55. };
  56. module_i2c_driver(tps546d24_driver);
  57. MODULE_AUTHOR("Duke Du <[email protected]>");
  58. MODULE_DESCRIPTION("PMBus driver for TI tps546d24");
  59. MODULE_LICENSE("GPL");
  60. MODULE_IMPORT_NS(PMBUS);