blob: b2061178fca4ac1e46a856ee315ff8132b964cc0 [file] [log] [blame]
Tom Rini10e47792018-05-06 17:58:06 -04001// SPDX-License-Identifier: GPL-2.0+
Przemyslaw Marczakdca94502015-05-13 13:38:33 +02002/*
3 * Tests for the driver model pmic API
4 *
5 * Copyright (c) 2015 Samsung Electronics
6 * Przemyslaw Marczak <p.marczak@samsung.com>
Przemyslaw Marczakdca94502015-05-13 13:38:33 +02007 */
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>
Przemyslaw Marczakdca94502015-05-13 13:38:33 +020016#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>
Joe Hershberger3a77be52015-05-20 14:27:27 -050021#include <test/ut.h>
Przemyslaw Marczakdca94502015-05-13 13:38:33 +020022
Przemyslaw Marczakdca94502015-05-13 13:38:33 +020023/* Test PMIC get method */
Joe Hershberger3a77be52015-05-20 14:27:27 -050024static int dm_test_power_pmic_get(struct unit_test_state *uts)
Przemyslaw Marczakdca94502015-05-13 13:38:33 +020025{
26 const char *name = "sandbox_pmic";
27 struct udevice *dev;
28
29 ut_assertok(pmic_get(name, &dev));
30 ut_assertnonnull(dev);
31
32 /* Check PMIC's name */
33 ut_asserteq_str(name, dev->name);
34
35 return 0;
36}
37DM_TEST(dm_test_power_pmic_get, DM_TESTF_SCAN_FDT);
38
39/* Test PMIC I/O */
Joe Hershberger3a77be52015-05-20 14:27:27 -050040static int dm_test_power_pmic_io(struct unit_test_state *uts)
Przemyslaw Marczakdca94502015-05-13 13:38:33 +020041{
42 const char *name = "sandbox_pmic";
43 uint8_t out_buffer, in_buffer;
44 struct udevice *dev;
45 int reg_count, i;
46
47 ut_assertok(pmic_get(name, &dev));
48
49 reg_count = pmic_reg_count(dev);
50 ut_asserteq(reg_count, SANDBOX_PMIC_REG_COUNT);
51
52 /*
53 * Test PMIC I/O - write and read a loop counter.
54 * usually we can't write to all PMIC's registers in the real hardware,
55 * but we can to the sandbox pmic.
56 */
57 for (i = 0; i < reg_count; i++) {
58 out_buffer = i;
59 ut_assertok(pmic_write(dev, i, &out_buffer, 1));
60 ut_assertok(pmic_read(dev, i, &in_buffer, 1));
61 ut_asserteq(out_buffer, in_buffer);
62 }
63
64 return 0;
65}
66DM_TEST(dm_test_power_pmic_io, DM_TESTF_SCAN_FDT);