pmic_tps65910_dm.c 2.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495
  1. // SPDX-License-Identifier: GPL-2.0+
  2. /*
  3. * Copyright (C) EETS GmbH, 2017, Felix Brack <f.brack@eets.ch>
  4. */
  5. #include <common.h>
  6. #include <dm.h>
  7. #include <i2c.h>
  8. #include <power/pmic.h>
  9. #include <power/regulator.h>
  10. #include <power/tps65910_pmic.h>
  11. static const struct pmic_child_info pmic_children_info[] = {
  12. { .prefix = "ldo_", .driver = TPS65910_LDO_DRIVER },
  13. { .prefix = "buck_", .driver = TPS65910_BUCK_DRIVER },
  14. { .prefix = "boost_", .driver = TPS65910_BOOST_DRIVER },
  15. { },
  16. };
  17. static int pmic_tps65910_reg_count(struct udevice *dev)
  18. {
  19. return TPS65910_NUM_REGS;
  20. }
  21. static int pmic_tps65910_write(struct udevice *dev, uint reg, const u8 *buffer,
  22. int len)
  23. {
  24. int ret;
  25. ret = dm_i2c_write(dev, reg, buffer, len);
  26. if (ret)
  27. pr_err("%s write error on register %02x\n", dev->name, reg);
  28. return ret;
  29. }
  30. static int pmic_tps65910_read(struct udevice *dev, uint reg, u8 *buffer,
  31. int len)
  32. {
  33. int ret;
  34. ret = dm_i2c_read(dev, reg, buffer, len);
  35. if (ret)
  36. pr_err("%s read error on register %02x\n", dev->name, reg);
  37. return ret;
  38. }
  39. static int pmic_tps65910_bind(struct udevice *dev)
  40. {
  41. ofnode regulators_node;
  42. int children;
  43. regulators_node = dev_read_subnode(dev, "regulators");
  44. if (!ofnode_valid(regulators_node)) {
  45. debug("%s regulators subnode not found\n", dev->name);
  46. return -EINVAL;
  47. }
  48. children = pmic_bind_children(dev, regulators_node, pmic_children_info);
  49. if (!children)
  50. debug("%s has no children (regulators)\n", dev->name);
  51. return 0;
  52. }
  53. static int pmic_tps65910_probe(struct udevice *dev)
  54. {
  55. /* use I2C control interface instead of I2C smartreflex interface to
  56. * access smartrefelex registers VDD1_OP_REG, VDD1_SR_REG, VDD2_OP_REG
  57. * and VDD2_SR_REG
  58. */
  59. return pmic_clrsetbits(dev, TPS65910_REG_DEVICE_CTRL, 0,
  60. TPS65910_I2C_SEL_MASK);
  61. }
  62. static struct dm_pmic_ops pmic_tps65910_ops = {
  63. .reg_count = pmic_tps65910_reg_count,
  64. .read = pmic_tps65910_read,
  65. .write = pmic_tps65910_write,
  66. };
  67. static const struct udevice_id pmic_tps65910_match[] = {
  68. { .compatible = "ti,tps65910" },
  69. { /* sentinel */ }
  70. };
  71. U_BOOT_DRIVER(pmic_tps65910) = {
  72. .name = "pmic_tps65910",
  73. .id = UCLASS_PMIC,
  74. .of_match = pmic_tps65910_match,
  75. .bind = pmic_tps65910_bind,
  76. .probe = pmic_tps65910_probe,
  77. .ops = &pmic_tps65910_ops,
  78. };