blob: c24bd3b0a12cd19cd1a25e0c9b14c2f09a004a80 [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 */
Lukasz Majewskid0eb49e2018-05-15 16:26:42 +020024
25static inline int power_pmic_get(struct unit_test_state *uts, char *name)
Przemyslaw Marczakdca94502015-05-13 13:38:33 +020026{
Przemyslaw Marczakdca94502015-05-13 13:38:33 +020027 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}
Lukasz Majewskid0eb49e2018-05-15 16:26:42 +020037
38/* Test PMIC get method */
39static int dm_test_power_pmic_get(struct unit_test_state *uts)
40{
41 power_pmic_get(uts, "sandbox_pmic");
42
43 return 0;
44}
Przemyslaw Marczakdca94502015-05-13 13:38:33 +020045DM_TEST(dm_test_power_pmic_get, DM_TESTF_SCAN_FDT);
46
47/* Test PMIC I/O */
Joe Hershberger3a77be52015-05-20 14:27:27 -050048static int dm_test_power_pmic_io(struct unit_test_state *uts)
Przemyslaw Marczakdca94502015-05-13 13:38:33 +020049{
50 const char *name = "sandbox_pmic";
51 uint8_t out_buffer, in_buffer;
52 struct udevice *dev;
53 int reg_count, i;
54
55 ut_assertok(pmic_get(name, &dev));
56
57 reg_count = pmic_reg_count(dev);
58 ut_asserteq(reg_count, SANDBOX_PMIC_REG_COUNT);
59
60 /*
61 * Test PMIC I/O - write and read a loop counter.
62 * usually we can't write to all PMIC's registers in the real hardware,
63 * but we can to the sandbox pmic.
64 */
65 for (i = 0; i < reg_count; i++) {
66 out_buffer = i;
67 ut_assertok(pmic_write(dev, i, &out_buffer, 1));
68 ut_assertok(pmic_read(dev, i, &in_buffer, 1));
69 ut_asserteq(out_buffer, in_buffer);
70 }
71
72 return 0;
73}
74DM_TEST(dm_test_power_pmic_io, DM_TESTF_SCAN_FDT);