lp873x.c 1.9 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586
  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. int regulators_node;
  42. const void *blob = gd->fdt_blob;
  43. int children;
  44. int node = dev->of_offset;
  45. regulators_node = fdt_subnode_offset(blob, node, "regulators");
  46. if (regulators_node <= 0) {
  47. printf("%s: %s reg subnode not found!", __func__, dev->name);
  48. return -ENXIO;
  49. }
  50. children = pmic_bind_children(dev, regulators_node, pmic_children_info);
  51. if (!children)
  52. printf("%s: %s - no child found\n", __func__, dev->name);
  53. /* Always return success for this device */
  54. return 0;
  55. }
  56. static struct dm_pmic_ops lp873x_ops = {
  57. .read = lp873x_read,
  58. .write = lp873x_write,
  59. };
  60. static const struct udevice_id lp873x_ids[] = {
  61. { .compatible = "ti,lp8732", .data = LP8732 },
  62. { .compatible = "ti,lp8733" , .data = LP8733 },
  63. { }
  64. };
  65. U_BOOT_DRIVER(pmic_lp873x) = {
  66. .name = "lp873x_pmic",
  67. .id = UCLASS_PMIC,
  68. .of_match = lp873x_ids,
  69. .bind = lp873x_bind,
  70. .ops = &lp873x_ops,
  71. };