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 
29 	KUNIT_EXPECT_EQ(test, ASPEED_SDHCI_TAP_PARAM_INVERT_CLK | 0,
30 			aspeed_sdhci_phase_to_tap(NULL, rate, 180));
31 	KUNIT_EXPECT_EQ(test, ASPEED_SDHCI_TAP_PARAM_INVERT_CLK | 0,
32 			aspeed_sdhci_phase_to_tap(NULL, rate, 181));
33 	KUNIT_EXPECT_EQ(test, ASPEED_SDHCI_TAP_PARAM_INVERT_CLK | 1,
34 			aspeed_sdhci_phase_to_tap(NULL, rate, 182));
35 	KUNIT_EXPECT_EQ(test, ASPEED_SDHCI_TAP_PARAM_INVERT_CLK | 1,
36 			aspeed_sdhci_phase_to_tap(NULL, rate, 183));
37 	KUNIT_EXPECT_EQ(test, ASPEED_SDHCI_TAP_PARAM_INVERT_CLK | 2,
38 			aspeed_sdhci_phase_to_tap(NULL, rate, 184));
39 	KUNIT_EXPECT_EQ(test, ASPEED_SDHCI_TAP_PARAM_INVERT_CLK | 3,
40 			aspeed_sdhci_phase_to_tap(NULL, rate, 185));
41 	KUNIT_EXPECT_EQ(test, ASPEED_SDHCI_TAP_PARAM_INVERT_CLK | 14,
42 			aspeed_sdhci_phase_to_tap(NULL, rate, 203));
43 	KUNIT_EXPECT_EQ(test, ASPEED_SDHCI_TAP_PARAM_INVERT_CLK | 15,
44 			aspeed_sdhci_phase_to_tap(NULL, rate, 204));
45 	KUNIT_EXPECT_EQ(test, ASPEED_SDHCI_TAP_PARAM_INVERT_CLK | 15,
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 
70 	KUNIT_EXPECT_EQ(test, ASPEED_SDHCI_TAP_PARAM_INVERT_CLK,
71 			aspeed_sdhci_phase_to_tap(NULL, rate, 180));
72 	KUNIT_EXPECT_EQ(test, ASPEED_SDHCI_TAP_PARAM_INVERT_CLK,
73 			aspeed_sdhci_phase_to_tap(NULL, rate, 185));
74 	KUNIT_EXPECT_EQ(test, ASPEED_SDHCI_TAP_PARAM_INVERT_CLK | 1,
75 			aspeed_sdhci_phase_to_tap(NULL, rate, 186));
76 	KUNIT_EXPECT_EQ(test, ASPEED_SDHCI_TAP_PARAM_INVERT_CLK | 1,
77 			aspeed_sdhci_phase_to_tap(NULL, rate, 187));
78 	KUNIT_EXPECT_EQ(test, ASPEED_SDHCI_TAP_PARAM_INVERT_CLK | 14,
79 			aspeed_sdhci_phase_to_tap(NULL, rate, 269));
80 	KUNIT_EXPECT_EQ(test, ASPEED_SDHCI_TAP_PARAM_INVERT_CLK | 15,
81 			aspeed_sdhci_phase_to_tap(NULL, rate, 270));
82 	KUNIT_EXPECT_EQ(test, ASPEED_SDHCI_TAP_PARAM_INVERT_CLK | 15,
83 			aspeed_sdhci_phase_to_tap(NULL, rate, 271));
84 	KUNIT_EXPECT_EQ(test, ASPEED_SDHCI_TAP_PARAM_INVERT_CLK | 15,
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 };
98 
99 kunit_test_suite(aspeed_sdhci_test_suite);
100