act8846.c 1.9 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788
  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. ofnode regulators_node;
  43. int children;
  44. regulators_node = dev_read_subnode(dev, "regulators");
  45. if (!ofnode_valid(regulators_node)) {
  46. debug("%s: %s regulators subnode not found!", __func__,
  47. dev->name);
  48. return -ENXIO;
  49. }
  50. debug("%s: '%s' - found regulators subnode\n", __func__, dev->name);
  51. children = pmic_bind_children(dev, regulators_node, pmic_children_info);
  52. if (!children)
  53. debug("%s: %s - no child found\n", __func__, dev->name);
  54. /* Always return success for this device */
  55. return 0;
  56. }
  57. static struct dm_pmic_ops act8846_ops = {
  58. .reg_count = act8846_reg_count,
  59. .read = act8846_read,
  60. .write = act8846_write,
  61. };
  62. static const struct udevice_id act8846_ids[] = {
  63. { .compatible = "active-semi,act8846" },
  64. { }
  65. };
  66. U_BOOT_DRIVER(pmic_act8846) = {
  67. .name = "act8846 pmic",
  68. .id = UCLASS_PMIC,
  69. .of_match = act8846_ids,
  70. .bind = act8846_bind,
  71. .ops = &act8846_ops,
  72. };