act8846.c 1.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990
  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/act8846_pmic.h>
  13. #include <power/pmic.h>
  14. DECLARE_GLOBAL_DATA_PTR;
  15. static const struct pmic_child_info pmic_children_info[] = {
  16. { .prefix = "REG", .driver = "act8846_reg"},
  17. { },
  18. };
  19. static int act8846_reg_count(struct udevice *dev)
  20. {
  21. return ACT8846_NUM_OF_REGS;
  22. }
  23. static int act8846_write(struct udevice *dev, uint reg, const uint8_t *buff,
  24. int len)
  25. {
  26. if (dm_i2c_write(dev, reg, buff, len)) {
  27. debug("write error to device: %p register: %#x!\n", dev, reg);
  28. return -EIO;
  29. }
  30. return 0;
  31. }
  32. static int act8846_read(struct udevice *dev, uint reg, uint8_t *buff, int len)
  33. {
  34. if (dm_i2c_read(dev, reg, buff, len)) {
  35. debug("read error from device: %p register: %#x!\n", dev, reg);
  36. return -EIO;
  37. }
  38. return 0;
  39. }
  40. static int act8846_bind(struct udevice *dev)
  41. {
  42. const void *blob = gd->fdt_blob;
  43. int regulators_node;
  44. int children;
  45. regulators_node = fdt_subnode_offset(blob, dev->of_offset,
  46. "regulators");
  47. if (regulators_node <= 0) {
  48. debug("%s: %s regulators subnode not found!", __func__,
  49. dev->name);
  50. return -ENXIO;
  51. }
  52. debug("%s: '%s' - found regulators subnode\n", __func__, dev->name);
  53. children = pmic_bind_children(dev, regulators_node, pmic_children_info);
  54. if (!children)
  55. debug("%s: %s - no child found\n", __func__, dev->name);
  56. /* Always return success for this device */
  57. return 0;
  58. }
  59. static struct dm_pmic_ops act8846_ops = {
  60. .reg_count = act8846_reg_count,
  61. .read = act8846_read,
  62. .write = act8846_write,
  63. };
  64. static const struct udevice_id act8846_ids[] = {
  65. { .compatible = "active-semi,act8846" },
  66. { }
  67. };
  68. U_BOOT_DRIVER(pmic_act8846) = {
  69. .name = "act8846 pmic",
  70. .id = UCLASS_PMIC,
  71. .of_match = act8846_ids,
  72. .bind = act8846_bind,
  73. .ops = &act8846_ops,
  74. };