blob: 1ed4f86291f29e36aee667f40014f2b550c7eb3f [file] [log] [blame]
Andrew Jeffery0bbcd222021-01-14 13:44:31 +10301// SPDX-License-Identifier: GPL-2.0-or-later
2/* Copyright (C) 2020 IBM Corp. */
3
4#include <kunit/test.h>
5
6static 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 Gow97847242021-05-13 12:32:00 -070029 KUNIT_EXPECT_EQ(test, ASPEED_SDHCI_TAP_PARAM_INVERT_CLK | 0,
Andrew Jeffery0bbcd222021-01-14 13:44:31 +103030 aspeed_sdhci_phase_to_tap(NULL, rate, 180));
David Gow97847242021-05-13 12:32:00 -070031 KUNIT_EXPECT_EQ(test, ASPEED_SDHCI_TAP_PARAM_INVERT_CLK | 0,
Andrew Jeffery0bbcd222021-01-14 13:44:31 +103032 aspeed_sdhci_phase_to_tap(NULL, rate, 181));
David Gow97847242021-05-13 12:32:00 -070033 KUNIT_EXPECT_EQ(test, ASPEED_SDHCI_TAP_PARAM_INVERT_CLK | 1,
Andrew Jeffery0bbcd222021-01-14 13:44:31 +103034 aspeed_sdhci_phase_to_tap(NULL, rate, 182));
David Gow97847242021-05-13 12:32:00 -070035 KUNIT_EXPECT_EQ(test, ASPEED_SDHCI_TAP_PARAM_INVERT_CLK | 1,
Andrew Jeffery0bbcd222021-01-14 13:44:31 +103036 aspeed_sdhci_phase_to_tap(NULL, rate, 183));
David Gow97847242021-05-13 12:32:00 -070037 KUNIT_EXPECT_EQ(test, ASPEED_SDHCI_TAP_PARAM_INVERT_CLK | 2,
Andrew Jeffery0bbcd222021-01-14 13:44:31 +103038 aspeed_sdhci_phase_to_tap(NULL, rate, 184));
David Gow97847242021-05-13 12:32:00 -070039 KUNIT_EXPECT_EQ(test, ASPEED_SDHCI_TAP_PARAM_INVERT_CLK | 3,
Andrew Jeffery0bbcd222021-01-14 13:44:31 +103040 aspeed_sdhci_phase_to_tap(NULL, rate, 185));
David Gow97847242021-05-13 12:32:00 -070041 KUNIT_EXPECT_EQ(test, ASPEED_SDHCI_TAP_PARAM_INVERT_CLK | 14,
Andrew Jeffery0bbcd222021-01-14 13:44:31 +103042 aspeed_sdhci_phase_to_tap(NULL, rate, 203));
David Gow97847242021-05-13 12:32:00 -070043 KUNIT_EXPECT_EQ(test, ASPEED_SDHCI_TAP_PARAM_INVERT_CLK | 15,
Andrew Jeffery0bbcd222021-01-14 13:44:31 +103044 aspeed_sdhci_phase_to_tap(NULL, rate, 204));
David Gow97847242021-05-13 12:32:00 -070045 KUNIT_EXPECT_EQ(test, ASPEED_SDHCI_TAP_PARAM_INVERT_CLK | 15,
Andrew Jeffery0bbcd222021-01-14 13:44:31 +103046 aspeed_sdhci_phase_to_tap(NULL, rate, 205));
47}
48
49static 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 Gow97847242021-05-13 12:32:00 -070070 KUNIT_EXPECT_EQ(test, ASPEED_SDHCI_TAP_PARAM_INVERT_CLK,
Andrew Jeffery0bbcd222021-01-14 13:44:31 +103071 aspeed_sdhci_phase_to_tap(NULL, rate, 180));
David Gow97847242021-05-13 12:32:00 -070072 KUNIT_EXPECT_EQ(test, ASPEED_SDHCI_TAP_PARAM_INVERT_CLK,
Andrew Jeffery0bbcd222021-01-14 13:44:31 +103073 aspeed_sdhci_phase_to_tap(NULL, rate, 185));
David Gow97847242021-05-13 12:32:00 -070074 KUNIT_EXPECT_EQ(test, ASPEED_SDHCI_TAP_PARAM_INVERT_CLK | 1,
Andrew Jeffery0bbcd222021-01-14 13:44:31 +103075 aspeed_sdhci_phase_to_tap(NULL, rate, 186));
David Gow97847242021-05-13 12:32:00 -070076 KUNIT_EXPECT_EQ(test, ASPEED_SDHCI_TAP_PARAM_INVERT_CLK | 1,
Andrew Jeffery0bbcd222021-01-14 13:44:31 +103077 aspeed_sdhci_phase_to_tap(NULL, rate, 187));
David Gow97847242021-05-13 12:32:00 -070078 KUNIT_EXPECT_EQ(test, ASPEED_SDHCI_TAP_PARAM_INVERT_CLK | 14,
Andrew Jeffery0bbcd222021-01-14 13:44:31 +103079 aspeed_sdhci_phase_to_tap(NULL, rate, 269));
David Gow97847242021-05-13 12:32:00 -070080 KUNIT_EXPECT_EQ(test, ASPEED_SDHCI_TAP_PARAM_INVERT_CLK | 15,
Andrew Jeffery0bbcd222021-01-14 13:44:31 +103081 aspeed_sdhci_phase_to_tap(NULL, rate, 270));
David Gow97847242021-05-13 12:32:00 -070082 KUNIT_EXPECT_EQ(test, ASPEED_SDHCI_TAP_PARAM_INVERT_CLK | 15,
Andrew Jeffery0bbcd222021-01-14 13:44:31 +103083 aspeed_sdhci_phase_to_tap(NULL, rate, 271));
David Gow97847242021-05-13 12:32:00 -070084 KUNIT_EXPECT_EQ(test, ASPEED_SDHCI_TAP_PARAM_INVERT_CLK | 15,
Andrew Jeffery0bbcd222021-01-14 13:44:31 +103085 aspeed_sdhci_phase_to_tap(NULL, rate, 276));
86}
87
88static struct kunit_case aspeed_sdhci_test_cases[] = {
89 KUNIT_CASE(aspeed_sdhci_phase_ddr52),
90 KUNIT_CASE(aspeed_sdhci_phase_hs200),
91 {}
92};
93
94static struct kunit_suite aspeed_sdhci_test_suite = {
95 .name = "sdhci-of-aspeed",
96 .test_cases = aspeed_sdhci_test_cases,
97};
Andrew Jeffery4af307f2021-01-22 22:18:52 +103098
99static struct kunit_suite *aspeed_sdc_test_suite_array[] = {
100 &aspeed_sdhci_test_suite,
101 NULL,
102};
103
104static struct kunit_suite **aspeed_sdc_test_suites
105 __used __section(".kunit_test_suites") = aspeed_sdc_test_suite_array;