lp87565.c 1.9 KB

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