pmic_starfive.c 2.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798
  1. // SPDX-License-Identifier: GPL-2.0+
  2. /*
  3. * Copyright (C) 2023 Starfive, Inc.
  4. * Author: keith.zhao<keith.zhao@statfivetech.com>
  5. */
  6. #include <common.h>
  7. #include <fdtdec.h>
  8. #include <errno.h>
  9. #include <dm.h>
  10. #include <i2c.h>
  11. #include <log.h>
  12. #include <power/pmic.h>
  13. #include <power/regulator.h>
  14. #include <dm/device.h>
  15. #define LP8732 0x0
  16. #define LP8733 0x1
  17. #define LP873X_LDO_NUM 8
  18. /* Drivers name */
  19. #define LP873X_LDO_DRIVER "lp873x_ldo"
  20. #define LP873X_BUCK_DRIVER "lp873x_buck"
  21. #define LP873X_BUCK_VOLT_MASK 0xFF
  22. #define LP873X_BUCK_VOLT_MAX_HEX 0xFF
  23. #define LP873X_BUCK_VOLT_MAX 3360000
  24. #define LP873X_BUCK_MODE_MASK 0x1
  25. #define LP873X_LDO_VOLT_MASK 0x1F
  26. #define LP873X_LDO_VOLT_MAX_HEX 0x19
  27. #define LP873X_LDO_VOLT_MAX 3300000
  28. #define LP873X_LDO_MODE_MASK 0x1
  29. static const struct pmic_child_info pmic_children_info[] = {
  30. { .prefix = "ldo", .driver = LP873X_LDO_DRIVER },
  31. { },
  32. };
  33. static int lp873x_write(struct udevice *dev, uint reg, const uint8_t *buff,
  34. int len)
  35. {
  36. if (dm_i2c_write(dev, reg, buff, len)) {
  37. pr_err("write error to device: %p register: %#x!\n", dev, reg);
  38. return -EIO;
  39. }
  40. return 0;
  41. }
  42. static int lp873x_read(struct udevice *dev, uint reg, uint8_t *buff, int len)
  43. {
  44. if (dm_i2c_read(dev, reg, buff, len)) {
  45. pr_err("read error from device: %p register: %#x!\n", dev, reg);
  46. return -EIO;
  47. }
  48. return 0;
  49. }
  50. static int starfive_bind(struct udevice *dev)
  51. {
  52. ofnode regulators_node;
  53. int children;
  54. regulators_node = dev_read_subnode(dev, "regulators");
  55. if (!ofnode_valid(regulators_node)) {
  56. printf("%s: %s regulators subnode not found!\n", __func__,
  57. dev->name);
  58. return -ENXIO;
  59. }
  60. children = pmic_bind_children(dev, regulators_node, pmic_children_info);
  61. if (!children)
  62. printf("%s: %s - no child found\n", __func__, dev->name);
  63. /* Always return success for this device */
  64. return 0;
  65. }
  66. static struct dm_pmic_ops lp873x_ops = {
  67. .read = lp873x_read,
  68. .write = lp873x_write,
  69. };
  70. static const struct udevice_id starfive_ids[] = {
  71. { .compatible = "starfive,jh7110-evb-regulator", .data = LP8732 },
  72. { }
  73. };
  74. U_BOOT_DRIVER(pmic_starfive) = {
  75. .name = "pmic_starfive",
  76. .id = UCLASS_PMIC,
  77. .of_match = starfive_ids,
  78. .bind = starfive_bind,
  79. .ops = &lp873x_ops,
  80. };