lp873x.c 1.8 KB

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