Simon Glass | 8cc4d82 | 2015-07-06 12:54:24 -0600 | [diff] [blame] | 1 | /* |
| 2 | * Copyright (C) 2015 Google, Inc |
| 3 | * |
| 4 | * SPDX-License-Identifier: GPL-2.0+ |
| 5 | */ |
| 6 | |
| 7 | #include <common.h> |
Simon Glass | 8cc4d82 | 2015-07-06 12:54:24 -0600 | [diff] [blame] | 8 | #include <dm.h> |
Stephen Warren | a962243 | 2016-06-17 09:44:00 -0600 | [diff] [blame^] | 9 | #include <asm/clk.h> |
Simon Glass | 8cc4d82 | 2015-07-06 12:54:24 -0600 | [diff] [blame] | 10 | #include <dm/test.h> |
| 11 | #include <linux/err.h> |
| 12 | #include <test/ut.h> |
| 13 | |
Stephen Warren | a962243 | 2016-06-17 09:44:00 -0600 | [diff] [blame^] | 14 | static int dm_test_clk(struct unit_test_state *uts) |
Simon Glass | 8cc4d82 | 2015-07-06 12:54:24 -0600 | [diff] [blame] | 15 | { |
Stephen Warren | a962243 | 2016-06-17 09:44:00 -0600 | [diff] [blame^] | 16 | struct udevice *dev_fixed, *dev_clk, *dev_test; |
Simon Glass | 8cc4d82 | 2015-07-06 12:54:24 -0600 | [diff] [blame] | 17 | ulong rate; |
| 18 | |
Stephen Warren | a962243 | 2016-06-17 09:44:00 -0600 | [diff] [blame^] | 19 | ut_assertok(uclass_get_device_by_name(UCLASS_CLK, "clk-fixed", |
| 20 | &dev_fixed)); |
Simon Glass | 8cc4d82 | 2015-07-06 12:54:24 -0600 | [diff] [blame] | 21 | |
Stephen Warren | a962243 | 2016-06-17 09:44:00 -0600 | [diff] [blame^] | 22 | ut_assertok(uclass_get_device_by_name(UCLASS_CLK, "clk-sbox", |
| 23 | &dev_clk)); |
| 24 | ut_asserteq(0, sandbox_clk_query_enable(dev_clk, SANDBOX_CLK_ID_SPI)); |
| 25 | ut_asserteq(0, sandbox_clk_query_enable(dev_clk, SANDBOX_CLK_ID_I2C)); |
| 26 | ut_asserteq(0, sandbox_clk_query_rate(dev_clk, SANDBOX_CLK_ID_SPI)); |
| 27 | ut_asserteq(0, sandbox_clk_query_rate(dev_clk, SANDBOX_CLK_ID_I2C)); |
Simon Glass | 8cc4d82 | 2015-07-06 12:54:24 -0600 | [diff] [blame] | 28 | |
Stephen Warren | a962243 | 2016-06-17 09:44:00 -0600 | [diff] [blame^] | 29 | ut_assertok(uclass_get_device_by_name(UCLASS_MISC, "clk-test", |
| 30 | &dev_test)); |
| 31 | ut_assertok(sandbox_clk_test_get(dev_test)); |
Simon Glass | 8cc4d82 | 2015-07-06 12:54:24 -0600 | [diff] [blame] | 32 | |
Stephen Warren | a962243 | 2016-06-17 09:44:00 -0600 | [diff] [blame^] | 33 | ut_asserteq(1234, |
| 34 | sandbox_clk_test_get_rate(dev_test, |
| 35 | SANDBOX_CLK_TEST_ID_FIXED)); |
| 36 | ut_asserteq(0, sandbox_clk_test_get_rate(dev_test, |
| 37 | SANDBOX_CLK_TEST_ID_SPI)); |
| 38 | ut_asserteq(0, sandbox_clk_test_get_rate(dev_test, |
| 39 | SANDBOX_CLK_TEST_ID_I2C)); |
Simon Glass | 8cc4d82 | 2015-07-06 12:54:24 -0600 | [diff] [blame] | 40 | |
Stephen Warren | a962243 | 2016-06-17 09:44:00 -0600 | [diff] [blame^] | 41 | rate = sandbox_clk_test_set_rate(dev_test, SANDBOX_CLK_TEST_ID_FIXED, |
| 42 | 12345); |
| 43 | ut_assert(IS_ERR_VALUE(rate)); |
| 44 | rate = sandbox_clk_test_get_rate(dev_test, SANDBOX_CLK_TEST_ID_FIXED); |
| 45 | ut_asserteq(1234, rate); |
Simon Glass | 8cc4d82 | 2015-07-06 12:54:24 -0600 | [diff] [blame] | 46 | |
Stephen Warren | a962243 | 2016-06-17 09:44:00 -0600 | [diff] [blame^] | 47 | ut_asserteq(0, sandbox_clk_test_set_rate(dev_test, |
| 48 | SANDBOX_CLK_TEST_ID_SPI, |
| 49 | 1000)); |
| 50 | ut_asserteq(0, sandbox_clk_test_set_rate(dev_test, |
| 51 | SANDBOX_CLK_TEST_ID_I2C, |
| 52 | 2000)); |
Simon Glass | 8cc4d82 | 2015-07-06 12:54:24 -0600 | [diff] [blame] | 53 | |
Stephen Warren | a962243 | 2016-06-17 09:44:00 -0600 | [diff] [blame^] | 54 | ut_asserteq(1000, sandbox_clk_test_get_rate(dev_test, |
| 55 | SANDBOX_CLK_TEST_ID_SPI)); |
| 56 | ut_asserteq(2000, sandbox_clk_test_get_rate(dev_test, |
| 57 | SANDBOX_CLK_TEST_ID_I2C)); |
Simon Glass | 8cc4d82 | 2015-07-06 12:54:24 -0600 | [diff] [blame] | 58 | |
Stephen Warren | a962243 | 2016-06-17 09:44:00 -0600 | [diff] [blame^] | 59 | ut_asserteq(1000, sandbox_clk_test_set_rate(dev_test, |
| 60 | SANDBOX_CLK_TEST_ID_SPI, |
| 61 | 10000)); |
| 62 | ut_asserteq(2000, sandbox_clk_test_set_rate(dev_test, |
| 63 | SANDBOX_CLK_TEST_ID_I2C, |
| 64 | 20000)); |
| 65 | |
| 66 | rate = sandbox_clk_test_set_rate(dev_test, SANDBOX_CLK_TEST_ID_SPI, 0); |
| 67 | ut_assert(IS_ERR_VALUE(rate)); |
| 68 | rate = sandbox_clk_test_set_rate(dev_test, SANDBOX_CLK_TEST_ID_I2C, 0); |
| 69 | ut_assert(IS_ERR_VALUE(rate)); |
Simon Glass | 8cc4d82 | 2015-07-06 12:54:24 -0600 | [diff] [blame] | 70 | |
Stephen Warren | a962243 | 2016-06-17 09:44:00 -0600 | [diff] [blame^] | 71 | ut_asserteq(10000, sandbox_clk_test_get_rate(dev_test, |
| 72 | SANDBOX_CLK_TEST_ID_SPI)); |
| 73 | ut_asserteq(20000, sandbox_clk_test_get_rate(dev_test, |
| 74 | SANDBOX_CLK_TEST_ID_I2C)); |
| 75 | |
| 76 | ut_asserteq(0, sandbox_clk_query_enable(dev_clk, SANDBOX_CLK_ID_SPI)); |
| 77 | ut_asserteq(0, sandbox_clk_query_enable(dev_clk, SANDBOX_CLK_ID_I2C)); |
| 78 | ut_asserteq(10000, sandbox_clk_query_rate(dev_clk, SANDBOX_CLK_ID_SPI)); |
| 79 | ut_asserteq(20000, sandbox_clk_query_rate(dev_clk, SANDBOX_CLK_ID_I2C)); |
| 80 | |
| 81 | ut_assertok(sandbox_clk_test_enable(dev_test, SANDBOX_CLK_TEST_ID_SPI)); |
| 82 | ut_asserteq(1, sandbox_clk_query_enable(dev_clk, SANDBOX_CLK_ID_SPI)); |
| 83 | ut_asserteq(0, sandbox_clk_query_enable(dev_clk, SANDBOX_CLK_ID_I2C)); |
| 84 | |
| 85 | ut_assertok(sandbox_clk_test_enable(dev_test, SANDBOX_CLK_TEST_ID_I2C)); |
| 86 | ut_asserteq(1, sandbox_clk_query_enable(dev_clk, SANDBOX_CLK_ID_SPI)); |
| 87 | ut_asserteq(1, sandbox_clk_query_enable(dev_clk, SANDBOX_CLK_ID_I2C)); |
| 88 | |
| 89 | ut_assertok(sandbox_clk_test_disable(dev_test, |
| 90 | SANDBOX_CLK_TEST_ID_SPI)); |
| 91 | ut_asserteq(0, sandbox_clk_query_enable(dev_clk, SANDBOX_CLK_ID_SPI)); |
| 92 | ut_asserteq(1, sandbox_clk_query_enable(dev_clk, SANDBOX_CLK_ID_I2C)); |
| 93 | |
| 94 | ut_assertok(sandbox_clk_test_disable(dev_test, |
| 95 | SANDBOX_CLK_TEST_ID_I2C)); |
| 96 | ut_asserteq(0, sandbox_clk_query_enable(dev_clk, SANDBOX_CLK_ID_SPI)); |
| 97 | ut_asserteq(0, sandbox_clk_query_enable(dev_clk, SANDBOX_CLK_ID_I2C)); |
| 98 | |
| 99 | ut_assertok(sandbox_clk_test_free(dev_test)); |
Simon Glass | 8cc4d82 | 2015-07-06 12:54:24 -0600 | [diff] [blame] | 100 | |
| 101 | return 0; |
| 102 | } |
Stephen Warren | a962243 | 2016-06-17 09:44:00 -0600 | [diff] [blame^] | 103 | DM_TEST(dm_test_clk, DM_TESTF_SCAN_FDT); |