rk808.c 2.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102
  1. /*
  2. * Copyright (C) 2015 Google, Inc
  3. * Written by Simon Glass <sjg@chromium.org>
  4. *
  5. * SPDX-License-Identifier: GPL-2.0+
  6. */
  7. #include <common.h>
  8. #include <dm.h>
  9. #include <errno.h>
  10. #include <fdtdec.h>
  11. #include <libfdt.h>
  12. #include <power/rk808_pmic.h>
  13. #include <power/pmic.h>
  14. DECLARE_GLOBAL_DATA_PTR;
  15. static const struct pmic_child_info pmic_children_info[] = {
  16. { .prefix = "DCDC_REG", .driver = "rk808_buck"},
  17. { .prefix = "LDO_REG", .driver = "rk808_ldo"},
  18. { .prefix = "SWITCH_REG", .driver = "rk808_switch"},
  19. { },
  20. };
  21. static int rk808_reg_count(struct udevice *dev)
  22. {
  23. return RK808_NUM_OF_REGS;
  24. }
  25. static int rk808_write(struct udevice *dev, uint reg, const uint8_t *buff,
  26. int len)
  27. {
  28. int ret;
  29. ret = dm_i2c_write(dev, reg, buff, len);
  30. if (ret) {
  31. debug("write error to device: %p register: %#x!", dev, reg);
  32. return ret;
  33. }
  34. return 0;
  35. }
  36. static int rk808_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. debug("read error from device: %p register: %#x!", dev, reg);
  42. return ret;
  43. }
  44. return 0;
  45. }
  46. #if CONFIG_IS_ENABLED(PMIC_CHILDREN)
  47. static int rk808_bind(struct udevice *dev)
  48. {
  49. const void *blob = gd->fdt_blob;
  50. int regulators_node;
  51. int children;
  52. regulators_node = fdt_subnode_offset(blob, dev->of_offset,
  53. "regulators");
  54. if (regulators_node <= 0) {
  55. debug("%s: %s regulators subnode not found!", __func__,
  56. dev->name);
  57. return -ENXIO;
  58. }
  59. debug("%s: '%s' - found regulators subnode\n", __func__, dev->name);
  60. children = pmic_bind_children(dev, regulators_node, pmic_children_info);
  61. if (!children)
  62. debug("%s: %s - no child found\n", __func__, dev->name);
  63. /* Always return success for this device */
  64. return 0;
  65. }
  66. #endif
  67. static struct dm_pmic_ops rk808_ops = {
  68. .reg_count = rk808_reg_count,
  69. .read = rk808_read,
  70. .write = rk808_write,
  71. };
  72. static const struct udevice_id rk808_ids[] = {
  73. { .compatible = "rockchip,rk808" },
  74. { }
  75. };
  76. U_BOOT_DRIVER(pmic_rk808) = {
  77. .name = "rk808 pmic",
  78. .id = UCLASS_PMIC,
  79. .of_match = rk808_ids,
  80. #if CONFIG_IS_ENABLED(PMIC_CHILDREN)
  81. .bind = rk808_bind,
  82. #endif
  83. .ops = &rk808_ops,
  84. };