sandbox.c 1.8 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879
  1. /*
  2. * Copyright (C) 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/sandbox_pmic.h>
  15. DECLARE_GLOBAL_DATA_PTR;
  16. static const struct pmic_child_info pmic_children_info[] = {
  17. { .prefix = SANDBOX_OF_LDO_PREFIX, .driver = SANDBOX_LDO_DRIVER },
  18. { .prefix = SANDBOX_OF_BUCK_PREFIX, .driver = SANDBOX_BUCK_DRIVER },
  19. { },
  20. };
  21. static int sandbox_pmic_reg_count(struct udevice *dev)
  22. {
  23. return SANDBOX_PMIC_REG_COUNT;
  24. }
  25. static int sandbox_pmic_write(struct udevice *dev, uint reg,
  26. const uint8_t *buff, int len)
  27. {
  28. if (dm_i2c_write(dev, reg, buff, len)) {
  29. error("write error to device: %p register: %#x!", dev, reg);
  30. return -EIO;
  31. }
  32. return 0;
  33. }
  34. static int sandbox_pmic_read(struct udevice *dev, uint reg,
  35. uint8_t *buff, int len)
  36. {
  37. if (dm_i2c_read(dev, reg, buff, len)) {
  38. error("read error from device: %p register: %#x!", dev, reg);
  39. return -EIO;
  40. }
  41. return 0;
  42. }
  43. static int sandbox_pmic_bind(struct udevice *dev)
  44. {
  45. if (!pmic_bind_children(dev, dev->of_offset, pmic_children_info))
  46. error("%s:%d PMIC: %s - no child found!", __func__, __LINE__,
  47. dev->name);
  48. /* Always return success for this device - allows for PMIC I/O */
  49. return 0;
  50. }
  51. static struct dm_pmic_ops sandbox_pmic_ops = {
  52. .reg_count = sandbox_pmic_reg_count,
  53. .read = sandbox_pmic_read,
  54. .write = sandbox_pmic_write,
  55. };
  56. static const struct udevice_id sandbox_pmic_ids[] = {
  57. { .compatible = "sandbox,pmic" },
  58. { }
  59. };
  60. U_BOOT_DRIVER(sandbox_pmic) = {
  61. .name = "sandbox_pmic",
  62. .id = UCLASS_PMIC,
  63. .of_match = sandbox_pmic_ids,
  64. .bind = sandbox_pmic_bind,
  65. .ops = &sandbox_pmic_ops,
  66. };