lp87565.c 1.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687
  1. /*
  2. * (C) Copyright 2017 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/lp87565.h>
  15. #include <dm/device.h>
  16. DECLARE_GLOBAL_DATA_PTR;
  17. static const struct pmic_child_info pmic_children_info[] = {
  18. { .prefix = "buck", .driver = LP87565_BUCK_DRIVER },
  19. { },
  20. };
  21. static int lp87565_write(struct udevice *dev, uint reg, const uint8_t *buff,
  22. int len)
  23. {
  24. int ret;
  25. ret = dm_i2c_write(dev, reg, buff, len);
  26. if (ret)
  27. error("write error to device: %p register: %#x!", dev, reg);
  28. return ret;
  29. }
  30. static int lp87565_read(struct udevice *dev, uint reg, uint8_t *buff, int len)
  31. {
  32. int ret;
  33. ret = dm_i2c_read(dev, reg, buff, len);
  34. if (ret)
  35. error("read error from device: %p register: %#x!", dev, reg);
  36. return ret;
  37. }
  38. static int lp87565_bind(struct udevice *dev)
  39. {
  40. ofnode regulators_node;
  41. int children;
  42. regulators_node = dev_read_subnode(dev, "regulators");
  43. if (!ofnode_valid(regulators_node)) {
  44. debug("%s: %s regulators subnode not found!", __func__,
  45. dev->name);
  46. return -ENXIO;
  47. }
  48. debug("%s: '%s' - found regulators subnode\n", __func__, dev->name);
  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 lp87565_ops = {
  56. .read = lp87565_read,
  57. .write = lp87565_write,
  58. };
  59. static const struct udevice_id lp87565_ids[] = {
  60. { .compatible = "ti,lp87565", .data = LP87565 },
  61. { .compatible = "ti,lp87565-q1", .data = LP87565_Q1 },
  62. { }
  63. };
  64. U_BOOT_DRIVER(pmic_lp87565) = {
  65. .name = "lp87565_pmic",
  66. .id = UCLASS_PMIC,
  67. .of_match = lp87565_ids,
  68. .bind = lp87565_bind,
  69. .ops = &lp87565_ops,
  70. };