palmas.c 2.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104
  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/palmas.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 = PALMAS_LDO_DRIVER },
  19. { .prefix = "smps", .driver = PALMAS_SMPS_DRIVER },
  20. { },
  21. };
  22. static int palmas_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 palmas_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 palmas_bind(struct udevice *dev)
  40. {
  41. int pmic_node = -1, regulators_node;
  42. const void *blob = gd->fdt_blob;
  43. int children;
  44. int node = dev->of_offset;
  45. int subnode, len;
  46. fdt_for_each_subnode(subnode, blob, node) {
  47. const char *name;
  48. char *temp;
  49. name = fdt_get_name(blob, subnode, &len);
  50. temp = strstr(name, "pmic");
  51. if (temp) {
  52. pmic_node = subnode;
  53. break;
  54. }
  55. }
  56. if (pmic_node <= 0) {
  57. debug("%s: %s pmic subnode not found!", __func__, dev->name);
  58. return -ENXIO;
  59. }
  60. regulators_node = fdt_subnode_offset(blob, pmic_node, "regulators");
  61. if (regulators_node <= 0) {
  62. debug("%s: %s reg subnode not found!", __func__, dev->name);
  63. return -ENXIO;
  64. }
  65. children = pmic_bind_children(dev, regulators_node, pmic_children_info);
  66. if (!children)
  67. debug("%s: %s - no child found\n", __func__, dev->name);
  68. /* Always return success for this device */
  69. return 0;
  70. }
  71. static struct dm_pmic_ops palmas_ops = {
  72. .read = palmas_read,
  73. .write = palmas_write,
  74. };
  75. static const struct udevice_id palmas_ids[] = {
  76. { .compatible = "ti,tps659038", .data = TPS659038 },
  77. { .compatible = "ti,tps65917" , .data = TPS65917 },
  78. { }
  79. };
  80. U_BOOT_DRIVER(pmic_palmas) = {
  81. .name = "palmas_pmic",
  82. .id = UCLASS_PMIC,
  83. .of_match = palmas_ids,
  84. .bind = palmas_bind,
  85. .ops = &palmas_ops,
  86. };