Tom Rini | 10e4779 | 2018-05-06 17:58:06 -0400 | [diff] [blame] | 1 | // SPDX-License-Identifier: GPL-2.0+ |
Przemyslaw Marczak | dca9450 | 2015-05-13 13:38:33 +0200 | [diff] [blame] | 2 | /* |
| 3 | * Tests for the driver model pmic API |
| 4 | * |
| 5 | * Copyright (c) 2015 Samsung Electronics |
| 6 | * Przemyslaw Marczak <p.marczak@samsung.com> |
Przemyslaw Marczak | dca9450 | 2015-05-13 13:38:33 +0200 | [diff] [blame] | 7 | */ |
| 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 Marczak | dca9450 | 2015-05-13 13:38:33 +0200 | [diff] [blame] | 16 | #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 Hershberger | 3a77be5 | 2015-05-20 14:27:27 -0500 | [diff] [blame] | 21 | #include <test/ut.h> |
Przemyslaw Marczak | dca9450 | 2015-05-13 13:38:33 +0200 | [diff] [blame] | 22 | |
Przemyslaw Marczak | dca9450 | 2015-05-13 13:38:33 +0200 | [diff] [blame] | 23 | /* Test PMIC get method */ |
Lukasz Majewski | d0eb49e | 2018-05-15 16:26:42 +0200 | [diff] [blame^] | 24 | |
| 25 | static inline int power_pmic_get(struct unit_test_state *uts, char *name) |
Przemyslaw Marczak | dca9450 | 2015-05-13 13:38:33 +0200 | [diff] [blame] | 26 | { |
Przemyslaw Marczak | dca9450 | 2015-05-13 13:38:33 +0200 | [diff] [blame] | 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 | } |
Lukasz Majewski | d0eb49e | 2018-05-15 16:26:42 +0200 | [diff] [blame^] | 37 | |
| 38 | /* Test PMIC get method */ |
| 39 | static 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 Marczak | dca9450 | 2015-05-13 13:38:33 +0200 | [diff] [blame] | 45 | DM_TEST(dm_test_power_pmic_get, DM_TESTF_SCAN_FDT); |
| 46 | |
| 47 | /* Test PMIC I/O */ |
Joe Hershberger | 3a77be5 | 2015-05-20 14:27:27 -0500 | [diff] [blame] | 48 | static int dm_test_power_pmic_io(struct unit_test_state *uts) |
Przemyslaw Marczak | dca9450 | 2015-05-13 13:38:33 +0200 | [diff] [blame] | 49 | { |
| 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 | } |
| 74 | DM_TEST(dm_test_power_pmic_io, DM_TESTF_SCAN_FDT); |