act8846.c 1.8 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485
  1. // SPDX-License-Identifier: GPL-2.0+
  2. /*
  3. * Copyright (C) 2015 Google, Inc
  4. * Written by Simon Glass <sjg@chromium.org>
  5. */
  6. #include <common.h>
  7. #include <dm.h>
  8. #include <errno.h>
  9. #include <fdtdec.h>
  10. #include <linux/libfdt.h>
  11. #include <power/act8846_pmic.h>
  12. #include <power/pmic.h>
  13. static const struct pmic_child_info pmic_children_info[] = {
  14. { .prefix = "REG", .driver = "act8846_reg"},
  15. { },
  16. };
  17. static int act8846_reg_count(struct udevice *dev)
  18. {
  19. return ACT8846_NUM_OF_REGS;
  20. }
  21. static int act8846_write(struct udevice *dev, uint reg, const uint8_t *buff,
  22. int len)
  23. {
  24. if (dm_i2c_write(dev, reg, buff, len)) {
  25. debug("write error to device: %p register: %#x!\n", dev, reg);
  26. return -EIO;
  27. }
  28. return 0;
  29. }
  30. static int act8846_read(struct udevice *dev, uint reg, uint8_t *buff, int len)
  31. {
  32. if (dm_i2c_read(dev, reg, buff, len)) {
  33. debug("read error from device: %p register: %#x!\n", dev, reg);
  34. return -EIO;
  35. }
  36. return 0;
  37. }
  38. static int act8846_bind(struct udevice *dev)
  39. {
  40. ofnode regulators_node;
  41. int children;
  42. regulators_node = dev_read_subnode(dev, "regulators");
  43. if (!ofnode_valid(regulators_node)) {
  44. debug("%s: %s regulators subnode not found!", __func__,
  45. dev->name);
  46. return -ENXIO;
  47. }
  48. debug("%s: '%s' - found regulators subnode\n", __func__, dev->name);
  49. children = pmic_bind_children(dev, regulators_node, pmic_children_info);
  50. if (!children)
  51. debug("%s: %s - no child found\n", __func__, dev->name);
  52. /* Always return success for this device */
  53. return 0;
  54. }
  55. static struct dm_pmic_ops act8846_ops = {
  56. .reg_count = act8846_reg_count,
  57. .read = act8846_read,
  58. .write = act8846_write,
  59. };
  60. static const struct udevice_id act8846_ids[] = {
  61. { .compatible = "active-semi,act8846" },
  62. { }
  63. };
  64. U_BOOT_DRIVER(pmic_act8846) = {
  65. .name = "act8846 pmic",
  66. .id = UCLASS_PMIC,
  67. .of_match = act8846_ids,
  68. .bind = act8846_bind,
  69. .ops = &act8846_ops,
  70. };