pmic.c 1.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869
  1. /*
  2. * Tests for the driver model pmic API
  3. *
  4. * Copyright (c) 2015 Samsung Electronics
  5. * Przemyslaw Marczak <p.marczak@samsung.com>
  6. *
  7. * SPDX-License-Identifier: GPL-2.0+
  8. */
  9. #include <common.h>
  10. #include <errno.h>
  11. #include <dm.h>
  12. #include <fdtdec.h>
  13. #include <malloc.h>
  14. #include <dm/device-internal.h>
  15. #include <dm/root.h>
  16. #include <dm/util.h>
  17. #include <dm/test.h>
  18. #include <dm/uclass-internal.h>
  19. #include <power/pmic.h>
  20. #include <power/sandbox_pmic.h>
  21. #include <test/ut.h>
  22. DECLARE_GLOBAL_DATA_PTR;
  23. /* Test PMIC get method */
  24. static int dm_test_power_pmic_get(struct unit_test_state *uts)
  25. {
  26. const char *name = "sandbox_pmic";
  27. struct udevice *dev;
  28. ut_assertok(pmic_get(name, &dev));
  29. ut_assertnonnull(dev);
  30. /* Check PMIC's name */
  31. ut_asserteq_str(name, dev->name);
  32. return 0;
  33. }
  34. DM_TEST(dm_test_power_pmic_get, DM_TESTF_SCAN_FDT);
  35. /* Test PMIC I/O */
  36. static int dm_test_power_pmic_io(struct unit_test_state *uts)
  37. {
  38. const char *name = "sandbox_pmic";
  39. uint8_t out_buffer, in_buffer;
  40. struct udevice *dev;
  41. int reg_count, i;
  42. ut_assertok(pmic_get(name, &dev));
  43. reg_count = pmic_reg_count(dev);
  44. ut_asserteq(reg_count, SANDBOX_PMIC_REG_COUNT);
  45. /*
  46. * Test PMIC I/O - write and read a loop counter.
  47. * usually we can't write to all PMIC's registers in the real hardware,
  48. * but we can to the sandbox pmic.
  49. */
  50. for (i = 0; i < reg_count; i++) {
  51. out_buffer = i;
  52. ut_assertok(pmic_write(dev, i, &out_buffer, 1));
  53. ut_assertok(pmic_read(dev, i, &in_buffer, 1));
  54. ut_asserteq(out_buffer, in_buffer);
  55. }
  56. return 0;
  57. }
  58. DM_TEST(dm_test_power_pmic_io, DM_TESTF_SCAN_FDT);