Andrew Jeffery | 0bbcd22 | 2021-01-14 13:44:31 +1030 | [diff] [blame] | 1 | // SPDX-License-Identifier: GPL-2.0-or-later |
| 2 | /* Copyright (C) 2020 IBM Corp. */ |
| 3 | |
| 4 | #include <kunit/test.h> |
| 5 | |
| 6 | static void aspeed_sdhci_phase_ddr52(struct kunit *test) |
| 7 | { |
| 8 | int rate = 52000000; |
| 9 | |
| 10 | KUNIT_EXPECT_EQ(test, 0, |
| 11 | aspeed_sdhci_phase_to_tap(NULL, rate, 0)); |
| 12 | KUNIT_EXPECT_EQ(test, 0, |
| 13 | aspeed_sdhci_phase_to_tap(NULL, rate, 1)); |
| 14 | KUNIT_EXPECT_EQ(test, 1, |
| 15 | aspeed_sdhci_phase_to_tap(NULL, rate, 2)); |
| 16 | KUNIT_EXPECT_EQ(test, 1, |
| 17 | aspeed_sdhci_phase_to_tap(NULL, rate, 3)); |
| 18 | KUNIT_EXPECT_EQ(test, 2, |
| 19 | aspeed_sdhci_phase_to_tap(NULL, rate, 4)); |
| 20 | KUNIT_EXPECT_EQ(test, 3, |
| 21 | aspeed_sdhci_phase_to_tap(NULL, rate, 5)); |
| 22 | KUNIT_EXPECT_EQ(test, 14, |
| 23 | aspeed_sdhci_phase_to_tap(NULL, rate, 23)); |
| 24 | KUNIT_EXPECT_EQ(test, 15, |
| 25 | aspeed_sdhci_phase_to_tap(NULL, rate, 24)); |
| 26 | KUNIT_EXPECT_EQ(test, 15, |
| 27 | aspeed_sdhci_phase_to_tap(NULL, rate, 25)); |
| 28 | |
David Gow | 9784724 | 2021-05-13 12:32:00 -0700 | [diff] [blame] | 29 | KUNIT_EXPECT_EQ(test, ASPEED_SDHCI_TAP_PARAM_INVERT_CLK | 0, |
Andrew Jeffery | 0bbcd22 | 2021-01-14 13:44:31 +1030 | [diff] [blame] | 30 | aspeed_sdhci_phase_to_tap(NULL, rate, 180)); |
David Gow | 9784724 | 2021-05-13 12:32:00 -0700 | [diff] [blame] | 31 | KUNIT_EXPECT_EQ(test, ASPEED_SDHCI_TAP_PARAM_INVERT_CLK | 0, |
Andrew Jeffery | 0bbcd22 | 2021-01-14 13:44:31 +1030 | [diff] [blame] | 32 | aspeed_sdhci_phase_to_tap(NULL, rate, 181)); |
David Gow | 9784724 | 2021-05-13 12:32:00 -0700 | [diff] [blame] | 33 | KUNIT_EXPECT_EQ(test, ASPEED_SDHCI_TAP_PARAM_INVERT_CLK | 1, |
Andrew Jeffery | 0bbcd22 | 2021-01-14 13:44:31 +1030 | [diff] [blame] | 34 | aspeed_sdhci_phase_to_tap(NULL, rate, 182)); |
David Gow | 9784724 | 2021-05-13 12:32:00 -0700 | [diff] [blame] | 35 | KUNIT_EXPECT_EQ(test, ASPEED_SDHCI_TAP_PARAM_INVERT_CLK | 1, |
Andrew Jeffery | 0bbcd22 | 2021-01-14 13:44:31 +1030 | [diff] [blame] | 36 | aspeed_sdhci_phase_to_tap(NULL, rate, 183)); |
David Gow | 9784724 | 2021-05-13 12:32:00 -0700 | [diff] [blame] | 37 | KUNIT_EXPECT_EQ(test, ASPEED_SDHCI_TAP_PARAM_INVERT_CLK | 2, |
Andrew Jeffery | 0bbcd22 | 2021-01-14 13:44:31 +1030 | [diff] [blame] | 38 | aspeed_sdhci_phase_to_tap(NULL, rate, 184)); |
David Gow | 9784724 | 2021-05-13 12:32:00 -0700 | [diff] [blame] | 39 | KUNIT_EXPECT_EQ(test, ASPEED_SDHCI_TAP_PARAM_INVERT_CLK | 3, |
Andrew Jeffery | 0bbcd22 | 2021-01-14 13:44:31 +1030 | [diff] [blame] | 40 | aspeed_sdhci_phase_to_tap(NULL, rate, 185)); |
David Gow | 9784724 | 2021-05-13 12:32:00 -0700 | [diff] [blame] | 41 | KUNIT_EXPECT_EQ(test, ASPEED_SDHCI_TAP_PARAM_INVERT_CLK | 14, |
Andrew Jeffery | 0bbcd22 | 2021-01-14 13:44:31 +1030 | [diff] [blame] | 42 | aspeed_sdhci_phase_to_tap(NULL, rate, 203)); |
David Gow | 9784724 | 2021-05-13 12:32:00 -0700 | [diff] [blame] | 43 | KUNIT_EXPECT_EQ(test, ASPEED_SDHCI_TAP_PARAM_INVERT_CLK | 15, |
Andrew Jeffery | 0bbcd22 | 2021-01-14 13:44:31 +1030 | [diff] [blame] | 44 | aspeed_sdhci_phase_to_tap(NULL, rate, 204)); |
David Gow | 9784724 | 2021-05-13 12:32:00 -0700 | [diff] [blame] | 45 | KUNIT_EXPECT_EQ(test, ASPEED_SDHCI_TAP_PARAM_INVERT_CLK | 15, |
Andrew Jeffery | 0bbcd22 | 2021-01-14 13:44:31 +1030 | [diff] [blame] | 46 | aspeed_sdhci_phase_to_tap(NULL, rate, 205)); |
| 47 | } |
| 48 | |
| 49 | static void aspeed_sdhci_phase_hs200(struct kunit *test) |
| 50 | { |
| 51 | int rate = 200000000; |
| 52 | |
| 53 | KUNIT_EXPECT_EQ(test, 0, |
| 54 | aspeed_sdhci_phase_to_tap(NULL, rate, 0)); |
| 55 | KUNIT_EXPECT_EQ(test, 0, |
| 56 | aspeed_sdhci_phase_to_tap(NULL, rate, 5)); |
| 57 | KUNIT_EXPECT_EQ(test, 1, |
| 58 | aspeed_sdhci_phase_to_tap(NULL, rate, 6)); |
| 59 | KUNIT_EXPECT_EQ(test, 1, |
| 60 | aspeed_sdhci_phase_to_tap(NULL, rate, 7)); |
| 61 | KUNIT_EXPECT_EQ(test, 14, |
| 62 | aspeed_sdhci_phase_to_tap(NULL, rate, 89)); |
| 63 | KUNIT_EXPECT_EQ(test, 15, |
| 64 | aspeed_sdhci_phase_to_tap(NULL, rate, 90)); |
| 65 | KUNIT_EXPECT_EQ(test, 15, |
| 66 | aspeed_sdhci_phase_to_tap(NULL, rate, 91)); |
| 67 | KUNIT_EXPECT_EQ(test, 15, |
| 68 | aspeed_sdhci_phase_to_tap(NULL, rate, 96)); |
| 69 | |
David Gow | 9784724 | 2021-05-13 12:32:00 -0700 | [diff] [blame] | 70 | KUNIT_EXPECT_EQ(test, ASPEED_SDHCI_TAP_PARAM_INVERT_CLK, |
Andrew Jeffery | 0bbcd22 | 2021-01-14 13:44:31 +1030 | [diff] [blame] | 71 | aspeed_sdhci_phase_to_tap(NULL, rate, 180)); |
David Gow | 9784724 | 2021-05-13 12:32:00 -0700 | [diff] [blame] | 72 | KUNIT_EXPECT_EQ(test, ASPEED_SDHCI_TAP_PARAM_INVERT_CLK, |
Andrew Jeffery | 0bbcd22 | 2021-01-14 13:44:31 +1030 | [diff] [blame] | 73 | aspeed_sdhci_phase_to_tap(NULL, rate, 185)); |
David Gow | 9784724 | 2021-05-13 12:32:00 -0700 | [diff] [blame] | 74 | KUNIT_EXPECT_EQ(test, ASPEED_SDHCI_TAP_PARAM_INVERT_CLK | 1, |
Andrew Jeffery | 0bbcd22 | 2021-01-14 13:44:31 +1030 | [diff] [blame] | 75 | aspeed_sdhci_phase_to_tap(NULL, rate, 186)); |
David Gow | 9784724 | 2021-05-13 12:32:00 -0700 | [diff] [blame] | 76 | KUNIT_EXPECT_EQ(test, ASPEED_SDHCI_TAP_PARAM_INVERT_CLK | 1, |
Andrew Jeffery | 0bbcd22 | 2021-01-14 13:44:31 +1030 | [diff] [blame] | 77 | aspeed_sdhci_phase_to_tap(NULL, rate, 187)); |
David Gow | 9784724 | 2021-05-13 12:32:00 -0700 | [diff] [blame] | 78 | KUNIT_EXPECT_EQ(test, ASPEED_SDHCI_TAP_PARAM_INVERT_CLK | 14, |
Andrew Jeffery | 0bbcd22 | 2021-01-14 13:44:31 +1030 | [diff] [blame] | 79 | aspeed_sdhci_phase_to_tap(NULL, rate, 269)); |
David Gow | 9784724 | 2021-05-13 12:32:00 -0700 | [diff] [blame] | 80 | KUNIT_EXPECT_EQ(test, ASPEED_SDHCI_TAP_PARAM_INVERT_CLK | 15, |
Andrew Jeffery | 0bbcd22 | 2021-01-14 13:44:31 +1030 | [diff] [blame] | 81 | aspeed_sdhci_phase_to_tap(NULL, rate, 270)); |
David Gow | 9784724 | 2021-05-13 12:32:00 -0700 | [diff] [blame] | 82 | KUNIT_EXPECT_EQ(test, ASPEED_SDHCI_TAP_PARAM_INVERT_CLK | 15, |
Andrew Jeffery | 0bbcd22 | 2021-01-14 13:44:31 +1030 | [diff] [blame] | 83 | aspeed_sdhci_phase_to_tap(NULL, rate, 271)); |
David Gow | 9784724 | 2021-05-13 12:32:00 -0700 | [diff] [blame] | 84 | KUNIT_EXPECT_EQ(test, ASPEED_SDHCI_TAP_PARAM_INVERT_CLK | 15, |
Andrew Jeffery | 0bbcd22 | 2021-01-14 13:44:31 +1030 | [diff] [blame] | 85 | aspeed_sdhci_phase_to_tap(NULL, rate, 276)); |
| 86 | } |
| 87 | |
| 88 | static struct kunit_case aspeed_sdhci_test_cases[] = { |
| 89 | KUNIT_CASE(aspeed_sdhci_phase_ddr52), |
| 90 | KUNIT_CASE(aspeed_sdhci_phase_hs200), |
| 91 | {} |
| 92 | }; |
| 93 | |
| 94 | static struct kunit_suite aspeed_sdhci_test_suite = { |
| 95 | .name = "sdhci-of-aspeed", |
| 96 | .test_cases = aspeed_sdhci_test_cases, |
| 97 | }; |
Andrew Jeffery | 4af307f | 2021-01-22 22:18:52 +1030 | [diff] [blame] | 98 | |
| 99 | static struct kunit_suite *aspeed_sdc_test_suite_array[] = { |
| 100 | &aspeed_sdhci_test_suite, |
| 101 | NULL, |
| 102 | }; |
| 103 | |
| 104 | static struct kunit_suite **aspeed_sdc_test_suites |
| 105 | __used __section(".kunit_test_suites") = aspeed_sdc_test_suite_array; |