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 */ |
Joe Hershberger | 3a77be5 | 2015-05-20 14:27:27 -0500 | [diff] [blame] | 24 | static int dm_test_power_pmic_get(struct unit_test_state *uts) |
Przemyslaw Marczak | dca9450 | 2015-05-13 13:38:33 +0200 | [diff] [blame] | 25 | { |
| 26 | const char *name = "sandbox_pmic"; |
| 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 | } |
| 37 | DM_TEST(dm_test_power_pmic_get, DM_TESTF_SCAN_FDT); |
| 38 | |
| 39 | /* Test PMIC I/O */ |
Joe Hershberger | 3a77be5 | 2015-05-20 14:27:27 -0500 | [diff] [blame] | 40 | static int dm_test_power_pmic_io(struct unit_test_state *uts) |
Przemyslaw Marczak | dca9450 | 2015-05-13 13:38:33 +0200 | [diff] [blame] | 41 | { |
| 42 | const char *name = "sandbox_pmic"; |
| 43 | uint8_t out_buffer, in_buffer; |
| 44 | struct udevice *dev; |
| 45 | int reg_count, i; |
| 46 | |
| 47 | ut_assertok(pmic_get(name, &dev)); |
| 48 | |
| 49 | reg_count = pmic_reg_count(dev); |
| 50 | ut_asserteq(reg_count, SANDBOX_PMIC_REG_COUNT); |
| 51 | |
| 52 | /* |
| 53 | * Test PMIC I/O - write and read a loop counter. |
| 54 | * usually we can't write to all PMIC's registers in the real hardware, |
| 55 | * but we can to the sandbox pmic. |
| 56 | */ |
| 57 | for (i = 0; i < reg_count; i++) { |
| 58 | out_buffer = i; |
| 59 | ut_assertok(pmic_write(dev, i, &out_buffer, 1)); |
| 60 | ut_assertok(pmic_read(dev, i, &in_buffer, 1)); |
| 61 | ut_asserteq(out_buffer, in_buffer); |
| 62 | } |
| 63 | |
| 64 | return 0; |
| 65 | } |
| 66 | DM_TEST(dm_test_power_pmic_io, DM_TESTF_SCAN_FDT); |