sandbox.c 1.7 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576
  1. // SPDX-License-Identifier: GPL-2.0+
  2. /*
  3. * Copyright (C) 2015 Samsung Electronics
  4. * Przemyslaw Marczak <p.marczak@samsung.com>
  5. */
  6. #include <common.h>
  7. #include <fdtdec.h>
  8. #include <errno.h>
  9. #include <dm.h>
  10. #include <i2c.h>
  11. #include <power/pmic.h>
  12. #include <power/regulator.h>
  13. #include <power/sandbox_pmic.h>
  14. static const struct pmic_child_info pmic_children_info[] = {
  15. { .prefix = SANDBOX_OF_LDO_PREFIX, .driver = SANDBOX_LDO_DRIVER },
  16. { .prefix = SANDBOX_OF_BUCK_PREFIX, .driver = SANDBOX_BUCK_DRIVER },
  17. { },
  18. };
  19. static int sandbox_pmic_reg_count(struct udevice *dev)
  20. {
  21. return SANDBOX_PMIC_REG_COUNT;
  22. }
  23. static int sandbox_pmic_write(struct udevice *dev, uint reg,
  24. const uint8_t *buff, int len)
  25. {
  26. if (dm_i2c_write(dev, reg, buff, len)) {
  27. pr_err("write error to device: %p register: %#x!", dev, reg);
  28. return -EIO;
  29. }
  30. return 0;
  31. }
  32. static int sandbox_pmic_read(struct udevice *dev, uint reg,
  33. uint8_t *buff, int len)
  34. {
  35. if (dm_i2c_read(dev, reg, buff, len)) {
  36. pr_err("read error from device: %p register: %#x!", dev, reg);
  37. return -EIO;
  38. }
  39. return 0;
  40. }
  41. static int sandbox_pmic_bind(struct udevice *dev)
  42. {
  43. if (!pmic_bind_children(dev, dev_ofnode(dev), pmic_children_info))
  44. pr_err("%s:%d PMIC: %s - no child found!", __func__, __LINE__,
  45. dev->name);
  46. /* Always return success for this device - allows for PMIC I/O */
  47. return 0;
  48. }
  49. static struct dm_pmic_ops sandbox_pmic_ops = {
  50. .reg_count = sandbox_pmic_reg_count,
  51. .read = sandbox_pmic_read,
  52. .write = sandbox_pmic_write,
  53. };
  54. static const struct udevice_id sandbox_pmic_ids[] = {
  55. { .compatible = "sandbox,pmic" },
  56. { }
  57. };
  58. U_BOOT_DRIVER(sandbox_pmic) = {
  59. .name = "sandbox_pmic",
  60. .id = UCLASS_PMIC,
  61. .of_match = sandbox_pmic_ids,
  62. .bind = sandbox_pmic_bind,
  63. .ops = &sandbox_pmic_ops,
  64. };