lp873x.c 1.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384
  1. /*
  2. * (C) Copyright 2016 Texas Instruments Incorporated, <www.ti.com>
  3. * Keerthy <j-keerthy@ti.com>
  4. *
  5. * SPDX-License-Identifier: GPL-2.0+
  6. */
  7. #include <common.h>
  8. #include <fdtdec.h>
  9. #include <errno.h>
  10. #include <dm.h>
  11. #include <i2c.h>
  12. #include <power/pmic.h>
  13. #include <power/regulator.h>
  14. #include <power/lp873x.h>
  15. #include <dm/device.h>
  16. DECLARE_GLOBAL_DATA_PTR;
  17. static const struct pmic_child_info pmic_children_info[] = {
  18. { .prefix = "ldo", .driver = LP873X_LDO_DRIVER },
  19. { .prefix = "buck", .driver = LP873X_BUCK_DRIVER },
  20. { },
  21. };
  22. static int lp873x_write(struct udevice *dev, uint reg, const uint8_t *buff,
  23. int len)
  24. {
  25. if (dm_i2c_write(dev, reg, buff, len)) {
  26. error("write error to device: %p register: %#x!", dev, reg);
  27. return -EIO;
  28. }
  29. return 0;
  30. }
  31. static int lp873x_read(struct udevice *dev, uint reg, uint8_t *buff, int len)
  32. {
  33. if (dm_i2c_read(dev, reg, buff, len)) {
  34. error("read error from device: %p register: %#x!", dev, reg);
  35. return -EIO;
  36. }
  37. return 0;
  38. }
  39. static int lp873x_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: %s regulators subnode not found!", __func__,
  46. dev->name);
  47. return -ENXIO;
  48. }
  49. children = pmic_bind_children(dev, regulators_node, pmic_children_info);
  50. if (!children)
  51. printf("%s: %s - no child found\n", __func__, dev->name);
  52. /* Always return success for this device */
  53. return 0;
  54. }
  55. static struct dm_pmic_ops lp873x_ops = {
  56. .read = lp873x_read,
  57. .write = lp873x_write,
  58. };
  59. static const struct udevice_id lp873x_ids[] = {
  60. { .compatible = "ti,lp8732", .data = LP8732 },
  61. { .compatible = "ti,lp8733" , .data = LP8733 },
  62. { }
  63. };
  64. U_BOOT_DRIVER(pmic_lp873x) = {
  65. .name = "lp873x_pmic",
  66. .id = UCLASS_PMIC,
  67. .of_match = lp873x_ids,
  68. .bind = lp873x_bind,
  69. .ops = &lp873x_ops,
  70. };