2 * Tests for the driver model pmic API
4 * Copyright (c) 2015 Samsung Electronics
5 * Przemyslaw Marczak <p.marczak@samsung.com>
7 * SPDX-License-Identifier: GPL-2.0+
15 #include <dm/device-internal.h>
19 #include <dm/uclass-internal.h>
20 #include <power/pmic.h>
21 #include <power/sandbox_pmic.h>
24 DECLARE_GLOBAL_DATA_PTR;
26 /* Test PMIC get method */
27 static int dm_test_power_pmic_get(struct unit_test_state *uts)
29 const char *name = "sandbox_pmic";
32 ut_assertok(pmic_get(name, &dev));
33 ut_assertnonnull(dev);
35 /* Check PMIC's name */
36 ut_asserteq_str(name, dev->name);
40 DM_TEST(dm_test_power_pmic_get, DM_TESTF_SCAN_FDT);
43 static int dm_test_power_pmic_io(struct unit_test_state *uts)
45 const char *name = "sandbox_pmic";
46 uint8_t out_buffer, in_buffer;
50 ut_assertok(pmic_get(name, &dev));
52 reg_count = pmic_reg_count(dev);
53 ut_asserteq(reg_count, SANDBOX_PMIC_REG_COUNT);
56 * Test PMIC I/O - write and read a loop counter.
57 * usually we can't write to all PMIC's registers in the real hardware,
58 * but we can to the sandbox pmic.
60 for (i = 0; i < reg_count; i++) {
62 ut_assertok(pmic_write(dev, i, &out_buffer, 1));
63 ut_assertok(pmic_read(dev, i, &in_buffer, 1));
64 ut_asserteq(out_buffer, in_buffer);
69 DM_TEST(dm_test_power_pmic_io, DM_TESTF_SCAN_FDT);