Tom Rini | 83d290c | 2018-05-06 17:58:06 -0400 | [diff] [blame] | 1 | // SPDX-License-Identifier: GPL-2.0+ |
Simon Glass | 6a1c7ce | 2015-07-06 12:54:24 -0600 | [diff] [blame] | 2 | /* |
| 3 | * Copyright (C) 2015 Google, Inc |
Simon Glass | 6a1c7ce | 2015-07-06 12:54:24 -0600 | [diff] [blame] | 4 | */ |
| 5 | |
| 6 | #include <common.h> |
Simon Glass | 6a1c7ce | 2015-07-06 12:54:24 -0600 | [diff] [blame] | 7 | #include <dm.h> |
Stephen Warren | 135aa95 | 2016-06-17 09:44:00 -0600 | [diff] [blame] | 8 | #include <asm/clk.h> |
Simon Glass | 6a1c7ce | 2015-07-06 12:54:24 -0600 | [diff] [blame] | 9 | #include <dm/test.h> |
| 10 | #include <linux/err.h> |
| 11 | #include <test/ut.h> |
| 12 | |
Stephen Warren | 135aa95 | 2016-06-17 09:44:00 -0600 | [diff] [blame] | 13 | static int dm_test_clk(struct unit_test_state *uts) |
Simon Glass | 6a1c7ce | 2015-07-06 12:54:24 -0600 | [diff] [blame] | 14 | { |
Anup Patel | b630d57 | 2019-02-25 08:14:55 +0000 | [diff] [blame] | 15 | struct udevice *dev_fixed, *dev_fixed_factor, *dev_clk, *dev_test; |
Simon Glass | 6a1c7ce | 2015-07-06 12:54:24 -0600 | [diff] [blame] | 16 | ulong rate; |
| 17 | |
Stephen Warren | 135aa95 | 2016-06-17 09:44:00 -0600 | [diff] [blame] | 18 | ut_assertok(uclass_get_device_by_name(UCLASS_CLK, "clk-fixed", |
| 19 | &dev_fixed)); |
Simon Glass | 6a1c7ce | 2015-07-06 12:54:24 -0600 | [diff] [blame] | 20 | |
Anup Patel | b630d57 | 2019-02-25 08:14:55 +0000 | [diff] [blame] | 21 | ut_assertok(uclass_get_device_by_name(UCLASS_CLK, "clk-fixed-factor", |
| 22 | &dev_fixed_factor)); |
| 23 | |
Stephen Warren | 135aa95 | 2016-06-17 09:44:00 -0600 | [diff] [blame] | 24 | ut_assertok(uclass_get_device_by_name(UCLASS_CLK, "clk-sbox", |
| 25 | &dev_clk)); |
| 26 | ut_asserteq(0, sandbox_clk_query_enable(dev_clk, SANDBOX_CLK_ID_SPI)); |
| 27 | ut_asserteq(0, sandbox_clk_query_enable(dev_clk, SANDBOX_CLK_ID_I2C)); |
| 28 | ut_asserteq(0, sandbox_clk_query_rate(dev_clk, SANDBOX_CLK_ID_SPI)); |
| 29 | ut_asserteq(0, sandbox_clk_query_rate(dev_clk, SANDBOX_CLK_ID_I2C)); |
Simon Glass | 6a1c7ce | 2015-07-06 12:54:24 -0600 | [diff] [blame] | 30 | |
Stephen Warren | 135aa95 | 2016-06-17 09:44:00 -0600 | [diff] [blame] | 31 | ut_assertok(uclass_get_device_by_name(UCLASS_MISC, "clk-test", |
| 32 | &dev_test)); |
| 33 | ut_assertok(sandbox_clk_test_get(dev_test)); |
Fabrice Gasnier | 1fe243a | 2018-07-24 16:31:28 +0200 | [diff] [blame] | 34 | ut_assertok(sandbox_clk_test_valid(dev_test)); |
Simon Glass | 6a1c7ce | 2015-07-06 12:54:24 -0600 | [diff] [blame] | 35 | |
Stephen Warren | 135aa95 | 2016-06-17 09:44:00 -0600 | [diff] [blame] | 36 | ut_asserteq(1234, |
| 37 | sandbox_clk_test_get_rate(dev_test, |
| 38 | SANDBOX_CLK_TEST_ID_FIXED)); |
| 39 | ut_asserteq(0, sandbox_clk_test_get_rate(dev_test, |
| 40 | SANDBOX_CLK_TEST_ID_SPI)); |
| 41 | ut_asserteq(0, sandbox_clk_test_get_rate(dev_test, |
| 42 | SANDBOX_CLK_TEST_ID_I2C)); |
Simon Glass | 6a1c7ce | 2015-07-06 12:54:24 -0600 | [diff] [blame] | 43 | |
Stephen Warren | 135aa95 | 2016-06-17 09:44:00 -0600 | [diff] [blame] | 44 | rate = sandbox_clk_test_set_rate(dev_test, SANDBOX_CLK_TEST_ID_FIXED, |
| 45 | 12345); |
| 46 | ut_assert(IS_ERR_VALUE(rate)); |
| 47 | rate = sandbox_clk_test_get_rate(dev_test, SANDBOX_CLK_TEST_ID_FIXED); |
Simon Glass | 6a1c7ce | 2015-07-06 12:54:24 -0600 | [diff] [blame] | 48 | ut_asserteq(1234, rate); |
| 49 | |
Stephen Warren | 135aa95 | 2016-06-17 09:44:00 -0600 | [diff] [blame] | 50 | ut_asserteq(0, sandbox_clk_test_set_rate(dev_test, |
| 51 | SANDBOX_CLK_TEST_ID_SPI, |
| 52 | 1000)); |
| 53 | ut_asserteq(0, sandbox_clk_test_set_rate(dev_test, |
| 54 | SANDBOX_CLK_TEST_ID_I2C, |
| 55 | 2000)); |
| 56 | |
| 57 | ut_asserteq(1000, sandbox_clk_test_get_rate(dev_test, |
| 58 | SANDBOX_CLK_TEST_ID_SPI)); |
| 59 | ut_asserteq(2000, sandbox_clk_test_get_rate(dev_test, |
| 60 | SANDBOX_CLK_TEST_ID_I2C)); |
| 61 | |
| 62 | ut_asserteq(1000, sandbox_clk_test_set_rate(dev_test, |
| 63 | SANDBOX_CLK_TEST_ID_SPI, |
| 64 | 10000)); |
| 65 | ut_asserteq(2000, sandbox_clk_test_set_rate(dev_test, |
| 66 | SANDBOX_CLK_TEST_ID_I2C, |
| 67 | 20000)); |
| 68 | |
| 69 | rate = sandbox_clk_test_set_rate(dev_test, SANDBOX_CLK_TEST_ID_SPI, 0); |
| 70 | ut_assert(IS_ERR_VALUE(rate)); |
| 71 | rate = sandbox_clk_test_set_rate(dev_test, SANDBOX_CLK_TEST_ID_I2C, 0); |
| 72 | ut_assert(IS_ERR_VALUE(rate)); |
| 73 | |
| 74 | ut_asserteq(10000, sandbox_clk_test_get_rate(dev_test, |
| 75 | SANDBOX_CLK_TEST_ID_SPI)); |
| 76 | ut_asserteq(20000, sandbox_clk_test_get_rate(dev_test, |
| 77 | SANDBOX_CLK_TEST_ID_I2C)); |
| 78 | |
| 79 | ut_asserteq(0, sandbox_clk_query_enable(dev_clk, SANDBOX_CLK_ID_SPI)); |
| 80 | ut_asserteq(0, sandbox_clk_query_enable(dev_clk, SANDBOX_CLK_ID_I2C)); |
| 81 | ut_asserteq(10000, sandbox_clk_query_rate(dev_clk, SANDBOX_CLK_ID_SPI)); |
| 82 | ut_asserteq(20000, sandbox_clk_query_rate(dev_clk, SANDBOX_CLK_ID_I2C)); |
| 83 | |
| 84 | ut_assertok(sandbox_clk_test_enable(dev_test, SANDBOX_CLK_TEST_ID_SPI)); |
| 85 | ut_asserteq(1, sandbox_clk_query_enable(dev_clk, SANDBOX_CLK_ID_SPI)); |
| 86 | ut_asserteq(0, sandbox_clk_query_enable(dev_clk, SANDBOX_CLK_ID_I2C)); |
| 87 | |
| 88 | ut_assertok(sandbox_clk_test_enable(dev_test, SANDBOX_CLK_TEST_ID_I2C)); |
| 89 | ut_asserteq(1, sandbox_clk_query_enable(dev_clk, SANDBOX_CLK_ID_SPI)); |
| 90 | ut_asserteq(1, sandbox_clk_query_enable(dev_clk, SANDBOX_CLK_ID_I2C)); |
| 91 | |
| 92 | ut_assertok(sandbox_clk_test_disable(dev_test, |
| 93 | SANDBOX_CLK_TEST_ID_SPI)); |
| 94 | ut_asserteq(0, sandbox_clk_query_enable(dev_clk, SANDBOX_CLK_ID_SPI)); |
| 95 | ut_asserteq(1, sandbox_clk_query_enable(dev_clk, SANDBOX_CLK_ID_I2C)); |
| 96 | |
| 97 | ut_assertok(sandbox_clk_test_disable(dev_test, |
| 98 | SANDBOX_CLK_TEST_ID_I2C)); |
| 99 | ut_asserteq(0, sandbox_clk_query_enable(dev_clk, SANDBOX_CLK_ID_SPI)); |
| 100 | ut_asserteq(0, sandbox_clk_query_enable(dev_clk, SANDBOX_CLK_ID_I2C)); |
| 101 | |
| 102 | ut_assertok(sandbox_clk_test_free(dev_test)); |
Simon Glass | 6a1c7ce | 2015-07-06 12:54:24 -0600 | [diff] [blame] | 103 | |
| 104 | return 0; |
| 105 | } |
Stephen Warren | 135aa95 | 2016-06-17 09:44:00 -0600 | [diff] [blame] | 106 | DM_TEST(dm_test_clk, DM_TESTF_SCAN_FDT); |
Neil Armstrong | 65388d0 | 2018-04-03 11:44:19 +0200 | [diff] [blame] | 107 | |
| 108 | static int dm_test_clk_bulk(struct unit_test_state *uts) |
| 109 | { |
| 110 | struct udevice *dev_clk, *dev_test; |
| 111 | |
| 112 | ut_assertok(uclass_get_device_by_name(UCLASS_CLK, "clk-sbox", |
| 113 | &dev_clk)); |
| 114 | ut_assertok(uclass_get_device_by_name(UCLASS_MISC, "clk-test", |
| 115 | &dev_test)); |
| 116 | ut_assertok(sandbox_clk_test_get_bulk(dev_test)); |
| 117 | |
| 118 | ut_asserteq(0, sandbox_clk_query_enable(dev_clk, SANDBOX_CLK_ID_SPI)); |
| 119 | ut_asserteq(0, sandbox_clk_query_enable(dev_clk, SANDBOX_CLK_ID_I2C)); |
| 120 | |
| 121 | /* Fixed clock does not support enable, thus should not fail */ |
| 122 | ut_assertok(sandbox_clk_test_enable_bulk(dev_test)); |
| 123 | ut_asserteq(1, sandbox_clk_query_enable(dev_clk, SANDBOX_CLK_ID_SPI)); |
| 124 | ut_asserteq(1, sandbox_clk_query_enable(dev_clk, SANDBOX_CLK_ID_I2C)); |
| 125 | |
| 126 | /* Fixed clock does not support disable, thus should not fail */ |
| 127 | ut_assertok(sandbox_clk_test_disable_bulk(dev_test)); |
| 128 | ut_asserteq(0, sandbox_clk_query_enable(dev_clk, SANDBOX_CLK_ID_SPI)); |
| 129 | ut_asserteq(0, sandbox_clk_query_enable(dev_clk, SANDBOX_CLK_ID_I2C)); |
| 130 | |
| 131 | /* Fixed clock does not support enable, thus should not fail */ |
| 132 | ut_assertok(sandbox_clk_test_enable_bulk(dev_test)); |
| 133 | ut_asserteq(1, sandbox_clk_query_enable(dev_clk, SANDBOX_CLK_ID_SPI)); |
| 134 | ut_asserteq(1, sandbox_clk_query_enable(dev_clk, SANDBOX_CLK_ID_I2C)); |
| 135 | |
| 136 | /* Fixed clock does not support disable, thus should not fail */ |
| 137 | ut_assertok(sandbox_clk_test_release_bulk(dev_test)); |
| 138 | ut_asserteq(0, sandbox_clk_query_enable(dev_clk, SANDBOX_CLK_ID_SPI)); |
| 139 | ut_asserteq(0, sandbox_clk_query_enable(dev_clk, SANDBOX_CLK_ID_I2C)); |
| 140 | |
| 141 | return 0; |
| 142 | } |
| 143 | DM_TEST(dm_test_clk_bulk, DM_TESTF_SCAN_FDT); |