blob: 0e5d6719248e3a06bb3c9e90fd7d436202f182c2 [file] [log] [blame]
Przemyslaw Marczake8f339e2015-05-13 13:38:33 +02001/*
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
10#include <common.h>
11#include <errno.h>
12#include <dm.h>
13#include <fdtdec.h>
14#include <malloc.h>
15#include <dm/device-internal.h>
16#include <dm/root.h>
Przemyslaw Marczake8f339e2015-05-13 13:38:33 +020017#include <dm/util.h>
18#include <dm/test.h>
19#include <dm/uclass-internal.h>
20#include <power/pmic.h>
21#include <power/sandbox_pmic.h>
Joe Hershbergere721b882015-05-20 14:27:27 -050022#include <test/ut.h>
Przemyslaw Marczake8f339e2015-05-13 13:38:33 +020023
Przemyslaw Marczake8f339e2015-05-13 13:38:33 +020024/* Test PMIC get method */
Joe Hershbergere721b882015-05-20 14:27:27 -050025static int dm_test_power_pmic_get(struct unit_test_state *uts)
Przemyslaw Marczake8f339e2015-05-13 13:38:33 +020026{
27 const char *name = "sandbox_pmic";
28 struct udevice *dev;
29
30 ut_assertok(pmic_get(name, &dev));
31 ut_assertnonnull(dev);
32
33 /* Check PMIC's name */
34 ut_asserteq_str(name, dev->name);
35
36 return 0;
37}
38DM_TEST(dm_test_power_pmic_get, DM_TESTF_SCAN_FDT);
39
40/* Test PMIC I/O */
Joe Hershbergere721b882015-05-20 14:27:27 -050041static int dm_test_power_pmic_io(struct unit_test_state *uts)
Przemyslaw Marczake8f339e2015-05-13 13:38:33 +020042{
43 const char *name = "sandbox_pmic";
44 uint8_t out_buffer, in_buffer;
45 struct udevice *dev;
46 int reg_count, i;
47
48 ut_assertok(pmic_get(name, &dev));
49
50 reg_count = pmic_reg_count(dev);
51 ut_asserteq(reg_count, SANDBOX_PMIC_REG_COUNT);
52
53 /*
54 * Test PMIC I/O - write and read a loop counter.
55 * usually we can't write to all PMIC's registers in the real hardware,
56 * but we can to the sandbox pmic.
57 */
58 for (i = 0; i < reg_count; i++) {
59 out_buffer = i;
60 ut_assertok(pmic_write(dev, i, &out_buffer, 1));
61 ut_assertok(pmic_read(dev, i, &in_buffer, 1));
62 ut_asserteq(out_buffer, in_buffer);
63 }
64
65 return 0;
66}
67DM_TEST(dm_test_power_pmic_io, DM_TESTF_SCAN_FDT);