palmas.c 2.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899
  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/palmas.h>
  14. #include <dm/device.h>
  15. static const struct pmic_child_info pmic_children_info[] = {
  16. { .prefix = "ldo", .driver = PALMAS_LDO_DRIVER },
  17. { .prefix = "smps", .driver = PALMAS_SMPS_DRIVER },
  18. { },
  19. };
  20. static int palmas_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 palmas_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 palmas_bind(struct udevice *dev)
  38. {
  39. ofnode pmic_node = ofnode_null(), regulators_node;
  40. ofnode subnode;
  41. int children;
  42. dev_for_each_subnode(subnode, dev) {
  43. const char *name;
  44. char *temp;
  45. name = ofnode_get_name(subnode);
  46. temp = strstr(name, "pmic");
  47. if (temp) {
  48. pmic_node = subnode;
  49. break;
  50. }
  51. }
  52. if (!ofnode_valid(pmic_node)) {
  53. debug("%s: %s pmic subnode not found!", __func__, dev->name);
  54. return -ENXIO;
  55. }
  56. regulators_node = ofnode_find_subnode(pmic_node, "regulators");
  57. if (!ofnode_valid(regulators_node)) {
  58. debug("%s: %s reg subnode not found!", __func__, dev->name);
  59. return -ENXIO;
  60. }
  61. children = pmic_bind_children(dev, regulators_node, pmic_children_info);
  62. if (!children)
  63. debug("%s: %s - no child found\n", __func__, dev->name);
  64. /* Always return success for this device */
  65. return 0;
  66. }
  67. static struct dm_pmic_ops palmas_ops = {
  68. .read = palmas_read,
  69. .write = palmas_write,
  70. };
  71. static const struct udevice_id palmas_ids[] = {
  72. { .compatible = "ti,tps659038", .data = TPS659038 },
  73. { .compatible = "ti,tps65917" , .data = TPS65917 },
  74. { }
  75. };
  76. U_BOOT_DRIVER(pmic_palmas) = {
  77. .name = "palmas_pmic",
  78. .id = UCLASS_PMIC,
  79. .of_match = palmas_ids,
  80. .bind = palmas_bind,
  81. .ops = &palmas_ops,
  82. };