stpmu1.c 2.0 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495
  1. // SPDX-License-Identifier: GPL-2.0+ OR BSD-3-Clause
  2. /*
  3. * Copyright (C) 2018, STMicroelectronics - All Rights Reserved
  4. */
  5. #include <common.h>
  6. #include <dm.h>
  7. #include <errno.h>
  8. #include <i2c.h>
  9. #include <power/pmic.h>
  10. #include <power/stpmu1.h>
  11. #define STMPU1_NUM_OF_REGS 0x100
  12. #ifndef CONFIG_SPL_BUILD
  13. static const struct pmic_child_info stpmu1_children_info[] = {
  14. { .prefix = "ldo", .driver = "stpmu1_ldo" },
  15. { .prefix = "buck", .driver = "stpmu1_buck" },
  16. { .prefix = "vref_ddr", .driver = "stpmu1_vref_ddr" },
  17. { .prefix = "pwr_sw", .driver = "stpmu1_pwr_sw" },
  18. { .prefix = "boost", .driver = "stpmu1_boost" },
  19. { },
  20. };
  21. #endif /* CONFIG_SPL_BUILD */
  22. static int stpmu1_reg_count(struct udevice *dev)
  23. {
  24. return STMPU1_NUM_OF_REGS;
  25. }
  26. static int stpmu1_write(struct udevice *dev, uint reg, const uint8_t *buff,
  27. int len)
  28. {
  29. int ret;
  30. ret = dm_i2c_write(dev, reg, buff, len);
  31. if (ret)
  32. dev_err(dev, "%s: failed to write register %#x :%d",
  33. __func__, reg, ret);
  34. return ret;
  35. }
  36. static int stpmu1_read(struct udevice *dev, uint reg, uint8_t *buff, int len)
  37. {
  38. int ret;
  39. ret = dm_i2c_read(dev, reg, buff, len);
  40. if (ret)
  41. dev_err(dev, "%s: failed to read register %#x : %d",
  42. __func__, reg, ret);
  43. return ret;
  44. }
  45. static int stpmu1_bind(struct udevice *dev)
  46. {
  47. #ifndef CONFIG_SPL_BUILD
  48. ofnode regulators_node;
  49. int children;
  50. regulators_node = dev_read_subnode(dev, "regulators");
  51. if (!ofnode_valid(regulators_node)) {
  52. dev_dbg(dev, "regulators subnode not found!");
  53. return -ENXIO;
  54. }
  55. dev_dbg(dev, "found regulators subnode\n");
  56. children = pmic_bind_children(dev, regulators_node,
  57. stpmu1_children_info);
  58. if (!children)
  59. dev_dbg(dev, "no child found\n");
  60. #endif /* CONFIG_SPL_BUILD */
  61. return 0;
  62. }
  63. static struct dm_pmic_ops stpmu1_ops = {
  64. .reg_count = stpmu1_reg_count,
  65. .read = stpmu1_read,
  66. .write = stpmu1_write,
  67. };
  68. static const struct udevice_id stpmu1_ids[] = {
  69. { .compatible = "st,stpmu1" },
  70. { }
  71. };
  72. U_BOOT_DRIVER(pmic_stpmu1) = {
  73. .name = "stpmu1_pmic",
  74. .id = UCLASS_PMIC,
  75. .of_match = stpmu1_ids,
  76. .bind = stpmu1_bind,
  77. .ops = &stpmu1_ops,
  78. };