max77686.c 2.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990
  1. /*
  2. * Copyright (C) 2014-2015 Samsung Electronics
  3. * Przemyslaw Marczak <p.marczak@samsung.com>
  4. *
  5. * SPDX-License-Identifier: GPL-2.0+
  6. */
  7. #include <common.h>
  8. #include <fdtdec.h>
  9. #include <errno.h>
  10. #include <dm.h>
  11. #include <i2c.h>
  12. #include <power/pmic.h>
  13. #include <power/regulator.h>
  14. #include <power/max77686_pmic.h>
  15. DECLARE_GLOBAL_DATA_PTR;
  16. static const struct pmic_child_info pmic_children_info[] = {
  17. { .prefix = "LDO", .driver = MAX77686_LDO_DRIVER },
  18. { .prefix = "BUCK", .driver = MAX77686_BUCK_DRIVER },
  19. { },
  20. };
  21. static int max77686_reg_count(struct udevice *dev)
  22. {
  23. return MAX77686_NUM_OF_REGS;
  24. }
  25. static int max77686_write(struct udevice *dev, uint reg, const uint8_t *buff,
  26. int len)
  27. {
  28. if (dm_i2c_write(dev, reg, buff, len)) {
  29. pr_err("write error to device: %p register: %#x!", dev, reg);
  30. return -EIO;
  31. }
  32. return 0;
  33. }
  34. static int max77686_read(struct udevice *dev, uint reg, uint8_t *buff, int len)
  35. {
  36. if (dm_i2c_read(dev, reg, buff, len)) {
  37. pr_err("read error from device: %p register: %#x!", dev, reg);
  38. return -EIO;
  39. }
  40. return 0;
  41. }
  42. static int max77686_bind(struct udevice *dev)
  43. {
  44. ofnode regulators_node;
  45. int children;
  46. regulators_node = dev_read_subnode(dev, "voltage-regulators");
  47. if (!ofnode_valid(regulators_node)) {
  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 max77686_ops = {
  60. .reg_count = max77686_reg_count,
  61. .read = max77686_read,
  62. .write = max77686_write,
  63. };
  64. static const struct udevice_id max77686_ids[] = {
  65. { .compatible = "maxim,max77686" },
  66. { }
  67. };
  68. U_BOOT_DRIVER(pmic_max77686) = {
  69. .name = "max77686_pmic",
  70. .id = UCLASS_PMIC,
  71. .of_match = max77686_ids,
  72. .bind = max77686_bind,
  73. .ops = &max77686_ops,
  74. };