10bbcd225SAndrew Jeffery // SPDX-License-Identifier: GPL-2.0-or-later
20bbcd225SAndrew Jeffery /* Copyright (C) 2020 IBM Corp. */
30bbcd225SAndrew Jeffery
40bbcd225SAndrew Jeffery #include <kunit/test.h>
50bbcd225SAndrew Jeffery
aspeed_sdhci_phase_ddr52(struct kunit * test)60bbcd225SAndrew Jeffery static void aspeed_sdhci_phase_ddr52(struct kunit *test)
70bbcd225SAndrew Jeffery {
80bbcd225SAndrew Jeffery int rate = 52000000;
90bbcd225SAndrew Jeffery
100bbcd225SAndrew Jeffery KUNIT_EXPECT_EQ(test, 0,
110bbcd225SAndrew Jeffery aspeed_sdhci_phase_to_tap(NULL, rate, 0));
120bbcd225SAndrew Jeffery KUNIT_EXPECT_EQ(test, 0,
130bbcd225SAndrew Jeffery aspeed_sdhci_phase_to_tap(NULL, rate, 1));
140bbcd225SAndrew Jeffery KUNIT_EXPECT_EQ(test, 1,
150bbcd225SAndrew Jeffery aspeed_sdhci_phase_to_tap(NULL, rate, 2));
160bbcd225SAndrew Jeffery KUNIT_EXPECT_EQ(test, 1,
170bbcd225SAndrew Jeffery aspeed_sdhci_phase_to_tap(NULL, rate, 3));
180bbcd225SAndrew Jeffery KUNIT_EXPECT_EQ(test, 2,
190bbcd225SAndrew Jeffery aspeed_sdhci_phase_to_tap(NULL, rate, 4));
200bbcd225SAndrew Jeffery KUNIT_EXPECT_EQ(test, 3,
210bbcd225SAndrew Jeffery aspeed_sdhci_phase_to_tap(NULL, rate, 5));
220bbcd225SAndrew Jeffery KUNIT_EXPECT_EQ(test, 14,
230bbcd225SAndrew Jeffery aspeed_sdhci_phase_to_tap(NULL, rate, 23));
240bbcd225SAndrew Jeffery KUNIT_EXPECT_EQ(test, 15,
250bbcd225SAndrew Jeffery aspeed_sdhci_phase_to_tap(NULL, rate, 24));
260bbcd225SAndrew Jeffery KUNIT_EXPECT_EQ(test, 15,
270bbcd225SAndrew Jeffery aspeed_sdhci_phase_to_tap(NULL, rate, 25));
280bbcd225SAndrew Jeffery
2997847240SDavid Gow KUNIT_EXPECT_EQ(test, ASPEED_SDHCI_TAP_PARAM_INVERT_CLK | 0,
300bbcd225SAndrew Jeffery aspeed_sdhci_phase_to_tap(NULL, rate, 180));
3197847240SDavid Gow KUNIT_EXPECT_EQ(test, ASPEED_SDHCI_TAP_PARAM_INVERT_CLK | 0,
320bbcd225SAndrew Jeffery aspeed_sdhci_phase_to_tap(NULL, rate, 181));
3397847240SDavid Gow KUNIT_EXPECT_EQ(test, ASPEED_SDHCI_TAP_PARAM_INVERT_CLK | 1,
340bbcd225SAndrew Jeffery aspeed_sdhci_phase_to_tap(NULL, rate, 182));
3597847240SDavid Gow KUNIT_EXPECT_EQ(test, ASPEED_SDHCI_TAP_PARAM_INVERT_CLK | 1,
360bbcd225SAndrew Jeffery aspeed_sdhci_phase_to_tap(NULL, rate, 183));
3797847240SDavid Gow KUNIT_EXPECT_EQ(test, ASPEED_SDHCI_TAP_PARAM_INVERT_CLK | 2,
380bbcd225SAndrew Jeffery aspeed_sdhci_phase_to_tap(NULL, rate, 184));
3997847240SDavid Gow KUNIT_EXPECT_EQ(test, ASPEED_SDHCI_TAP_PARAM_INVERT_CLK | 3,
400bbcd225SAndrew Jeffery aspeed_sdhci_phase_to_tap(NULL, rate, 185));
4197847240SDavid Gow KUNIT_EXPECT_EQ(test, ASPEED_SDHCI_TAP_PARAM_INVERT_CLK | 14,
420bbcd225SAndrew Jeffery aspeed_sdhci_phase_to_tap(NULL, rate, 203));
4397847240SDavid Gow KUNIT_EXPECT_EQ(test, ASPEED_SDHCI_TAP_PARAM_INVERT_CLK | 15,
440bbcd225SAndrew Jeffery aspeed_sdhci_phase_to_tap(NULL, rate, 204));
4597847240SDavid Gow KUNIT_EXPECT_EQ(test, ASPEED_SDHCI_TAP_PARAM_INVERT_CLK | 15,
460bbcd225SAndrew Jeffery aspeed_sdhci_phase_to_tap(NULL, rate, 205));
470bbcd225SAndrew Jeffery }
480bbcd225SAndrew Jeffery
aspeed_sdhci_phase_hs200(struct kunit * test)490bbcd225SAndrew Jeffery static void aspeed_sdhci_phase_hs200(struct kunit *test)
500bbcd225SAndrew Jeffery {
510bbcd225SAndrew Jeffery int rate = 200000000;
520bbcd225SAndrew Jeffery
530bbcd225SAndrew Jeffery KUNIT_EXPECT_EQ(test, 0,
540bbcd225SAndrew Jeffery aspeed_sdhci_phase_to_tap(NULL, rate, 0));
550bbcd225SAndrew Jeffery KUNIT_EXPECT_EQ(test, 0,
560bbcd225SAndrew Jeffery aspeed_sdhci_phase_to_tap(NULL, rate, 5));
570bbcd225SAndrew Jeffery KUNIT_EXPECT_EQ(test, 1,
580bbcd225SAndrew Jeffery aspeed_sdhci_phase_to_tap(NULL, rate, 6));
590bbcd225SAndrew Jeffery KUNIT_EXPECT_EQ(test, 1,
600bbcd225SAndrew Jeffery aspeed_sdhci_phase_to_tap(NULL, rate, 7));
610bbcd225SAndrew Jeffery KUNIT_EXPECT_EQ(test, 14,
620bbcd225SAndrew Jeffery aspeed_sdhci_phase_to_tap(NULL, rate, 89));
630bbcd225SAndrew Jeffery KUNIT_EXPECT_EQ(test, 15,
640bbcd225SAndrew Jeffery aspeed_sdhci_phase_to_tap(NULL, rate, 90));
650bbcd225SAndrew Jeffery KUNIT_EXPECT_EQ(test, 15,
660bbcd225SAndrew Jeffery aspeed_sdhci_phase_to_tap(NULL, rate, 91));
670bbcd225SAndrew Jeffery KUNIT_EXPECT_EQ(test, 15,
680bbcd225SAndrew Jeffery aspeed_sdhci_phase_to_tap(NULL, rate, 96));
690bbcd225SAndrew Jeffery
7097847240SDavid Gow KUNIT_EXPECT_EQ(test, ASPEED_SDHCI_TAP_PARAM_INVERT_CLK,
710bbcd225SAndrew Jeffery aspeed_sdhci_phase_to_tap(NULL, rate, 180));
7297847240SDavid Gow KUNIT_EXPECT_EQ(test, ASPEED_SDHCI_TAP_PARAM_INVERT_CLK,
730bbcd225SAndrew Jeffery aspeed_sdhci_phase_to_tap(NULL, rate, 185));
7497847240SDavid Gow KUNIT_EXPECT_EQ(test, ASPEED_SDHCI_TAP_PARAM_INVERT_CLK | 1,
750bbcd225SAndrew Jeffery aspeed_sdhci_phase_to_tap(NULL, rate, 186));
7697847240SDavid Gow KUNIT_EXPECT_EQ(test, ASPEED_SDHCI_TAP_PARAM_INVERT_CLK | 1,
770bbcd225SAndrew Jeffery aspeed_sdhci_phase_to_tap(NULL, rate, 187));
7897847240SDavid Gow KUNIT_EXPECT_EQ(test, ASPEED_SDHCI_TAP_PARAM_INVERT_CLK | 14,
790bbcd225SAndrew Jeffery aspeed_sdhci_phase_to_tap(NULL, rate, 269));
8097847240SDavid Gow KUNIT_EXPECT_EQ(test, ASPEED_SDHCI_TAP_PARAM_INVERT_CLK | 15,
810bbcd225SAndrew Jeffery aspeed_sdhci_phase_to_tap(NULL, rate, 270));
8297847240SDavid Gow KUNIT_EXPECT_EQ(test, ASPEED_SDHCI_TAP_PARAM_INVERT_CLK | 15,
830bbcd225SAndrew Jeffery aspeed_sdhci_phase_to_tap(NULL, rate, 271));
8497847240SDavid Gow KUNIT_EXPECT_EQ(test, ASPEED_SDHCI_TAP_PARAM_INVERT_CLK | 15,
850bbcd225SAndrew Jeffery aspeed_sdhci_phase_to_tap(NULL, rate, 276));
860bbcd225SAndrew Jeffery }
870bbcd225SAndrew Jeffery
880bbcd225SAndrew Jeffery static struct kunit_case aspeed_sdhci_test_cases[] = {
890bbcd225SAndrew Jeffery KUNIT_CASE(aspeed_sdhci_phase_ddr52),
900bbcd225SAndrew Jeffery KUNIT_CASE(aspeed_sdhci_phase_hs200),
910bbcd225SAndrew Jeffery {}
920bbcd225SAndrew Jeffery };
930bbcd225SAndrew Jeffery
940bbcd225SAndrew Jeffery static struct kunit_suite aspeed_sdhci_test_suite = {
950bbcd225SAndrew Jeffery .name = "sdhci-of-aspeed",
960bbcd225SAndrew Jeffery .test_cases = aspeed_sdhci_test_cases,
970bbcd225SAndrew Jeffery };
984af307f5SAndrew Jeffery
99*291cd54eSDavid Gow kunit_test_suite(aspeed_sdhci_test_suite);
100