blob: 422ea3e416850cbefa82f16704422d5f32944f72 [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
24DECLARE_GLOBAL_DATA_PTR;
25
26/* Test PMIC get method */
Joe Hershbergere721b882015-05-20 14:27:27 -050027static int dm_test_power_pmic_get(struct unit_test_state *uts)
Przemyslaw Marczake8f339e2015-05-13 13:38:33 +020028{
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 */
Joe Hershbergere721b882015-05-20 14:27:27 -050043static int dm_test_power_pmic_io(struct unit_test_state *uts)
Przemyslaw Marczake8f339e2015-05-13 13:38:33 +020044{
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);