blob: e9c904c9f15f842eaf9c0cf80b39fa2072c9fd28 [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>
17#include <dm/ut.h>
18#include <dm/util.h>
19#include <dm/test.h>
20#include <dm/uclass-internal.h>
21#include <power/pmic.h>
22#include <power/sandbox_pmic.h>
23
24DECLARE_GLOBAL_DATA_PTR;
25
26/* Test PMIC get method */
27static int dm_test_power_pmic_get(struct dm_test_state *dms)
28{
29 const char *name = "sandbox_pmic";
30 struct udevice *dev;
31
32 ut_assertok(pmic_get(name, &dev));
33 ut_assertnonnull(dev);
34
35 /* Check PMIC's name */
36 ut_asserteq_str(name, dev->name);
37
38 return 0;
39}
40DM_TEST(dm_test_power_pmic_get, DM_TESTF_SCAN_FDT);
41
42/* Test PMIC I/O */
43static int dm_test_power_pmic_io(struct dm_test_state *dms)
44{
45 const char *name = "sandbox_pmic";
46 uint8_t out_buffer, in_buffer;
47 struct udevice *dev;
48 int reg_count, i;
49
50 ut_assertok(pmic_get(name, &dev));
51
52 reg_count = pmic_reg_count(dev);
53 ut_asserteq(reg_count, SANDBOX_PMIC_REG_COUNT);
54
55 /*
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.
59 */
60 for (i = 0; i < reg_count; i++) {
61 out_buffer = 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);
65 }
66
67 return 0;
68}
69DM_TEST(dm_test_power_pmic_io, DM_TESTF_SCAN_FDT);