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