blob: d16bbb8eff9e340f7670f06d71b2d5f8db848557 [file] [log] [blame]
Siva Durga Prasad Paladugucad14a82018-04-19 12:37:09 +05301// SPDX-License-Identifier: GPL-2.0
2/*
3 * Xilinx ZynqMP SoC Tap Delay Programming
4 *
5 * Copyright (C) 2018 Xilinx, Inc.
6 */
7
8#include <common.h>
Ashok Reddy Soma5fe3f412020-10-23 04:59:04 -06009#include <zynqmp_tap_delay.h>
Siva Durga Prasad Paladugucad14a82018-04-19 12:37:09 +053010#include <asm/arch/sys_proto.h>
Simon Glassdbd79542020-05-10 11:40:11 -060011#include <linux/delay.h>
Ashok Reddy Soma0afdfe32020-10-23 04:58:58 -060012#include <mmc.h>
Siva Durga Prasad Paladugucad14a82018-04-19 12:37:09 +053013
14#define SD_DLL_CTRL 0xFF180358
15#define SD_ITAP_DLY 0xFF180314
16#define SD_OTAP_DLY 0xFF180318
17#define SD0_DLL_RST_MASK 0x00000004
18#define SD0_DLL_RST 0x00000004
19#define SD1_DLL_RST_MASK 0x00040000
20#define SD1_DLL_RST 0x00040000
21#define SD0_ITAPCHGWIN_MASK 0x00000200
22#define SD0_ITAPCHGWIN 0x00000200
23#define SD1_ITAPCHGWIN_MASK 0x02000000
24#define SD1_ITAPCHGWIN 0x02000000
25#define SD0_ITAPDLYENA_MASK 0x00000100
26#define SD0_ITAPDLYENA 0x00000100
27#define SD1_ITAPDLYENA_MASK 0x01000000
28#define SD1_ITAPDLYENA 0x01000000
29#define SD0_ITAPDLYSEL_MASK 0x000000FF
Siva Durga Prasad Paladugucad14a82018-04-19 12:37:09 +053030#define SD1_ITAPDLYSEL_MASK 0x00FF0000
Siva Durga Prasad Paladugucad14a82018-04-19 12:37:09 +053031#define SD0_OTAPDLYSEL_MASK 0x0000003F
Siva Durga Prasad Paladugucad14a82018-04-19 12:37:09 +053032#define SD1_OTAPDLYSEL_MASK 0x003F0000
Siva Durga Prasad Paladugucad14a82018-04-19 12:37:09 +053033
Siva Durga Prasad Paladugucad14a82018-04-19 12:37:09 +053034void zynqmp_dll_reset(u8 deviceid)
35{
36 /* Issue DLL Reset */
37 if (deviceid == 0)
38 zynqmp_mmio_write(SD_DLL_CTRL, SD0_DLL_RST_MASK,
39 SD0_DLL_RST);
40 else
41 zynqmp_mmio_write(SD_DLL_CTRL, SD1_DLL_RST_MASK,
42 SD1_DLL_RST);
43
44 mdelay(1);
45
46 /* Release DLL Reset */
47 if (deviceid == 0)
48 zynqmp_mmio_write(SD_DLL_CTRL, SD0_DLL_RST_MASK, 0x0);
49 else
50 zynqmp_mmio_write(SD_DLL_CTRL, SD1_DLL_RST_MASK, 0x0);
51}
52
Ashok Reddy Soma39a177a2021-07-09 05:53:42 -060053void arasan_zynqmp_set_in_tapdelay(u8 deviceid, u32 itap_delay)
Siva Durga Prasad Paladugucad14a82018-04-19 12:37:09 +053054{
55 if (deviceid == 0) {
Ashok Reddy Soma39a177a2021-07-09 05:53:42 -060056 zynqmp_mmio_write(SD_DLL_CTRL, SD0_DLL_RST_MASK, SD0_DLL_RST);
Ashok Reddy Soma5fe3f412020-10-23 04:59:04 -060057
Ashok Reddy Soma39a177a2021-07-09 05:53:42 -060058 /* Program ITAP delay */
59 zynqmp_mmio_write(SD_ITAP_DLY, SD0_ITAPCHGWIN_MASK,
60 SD0_ITAPCHGWIN);
61 zynqmp_mmio_write(SD_ITAP_DLY, SD0_ITAPDLYENA_MASK,
62 SD0_ITAPDLYENA);
63 zynqmp_mmio_write(SD_ITAP_DLY, SD0_ITAPDLYSEL_MASK, itap_delay);
64 zynqmp_mmio_write(SD_ITAP_DLY, SD0_ITAPCHGWIN_MASK, 0x0);
Siva Durga Prasad Paladugucad14a82018-04-19 12:37:09 +053065
Ashok Reddy Soma5fe3f412020-10-23 04:59:04 -060066 zynqmp_mmio_write(SD_DLL_CTRL, SD0_DLL_RST_MASK, 0x0);
Siva Durga Prasad Paladugucad14a82018-04-19 12:37:09 +053067 } else {
Ashok Reddy Soma39a177a2021-07-09 05:53:42 -060068 zynqmp_mmio_write(SD_DLL_CTRL, SD1_DLL_RST_MASK, SD1_DLL_RST);
69
70 /* Program ITAP delay */
71 zynqmp_mmio_write(SD_ITAP_DLY, SD1_ITAPCHGWIN_MASK,
72 SD1_ITAPCHGWIN);
73 zynqmp_mmio_write(SD_ITAP_DLY, SD1_ITAPDLYENA_MASK,
74 SD1_ITAPDLYENA);
75 zynqmp_mmio_write(SD_ITAP_DLY, SD1_ITAPDLYSEL_MASK,
76 (itap_delay << 16));
77 zynqmp_mmio_write(SD_ITAP_DLY, SD1_ITAPCHGWIN_MASK, 0x0);
78
79 zynqmp_mmio_write(SD_DLL_CTRL, SD1_DLL_RST_MASK, 0x0);
80 }
81}
82
83void arasan_zynqmp_set_out_tapdelay(u8 deviceid, u32 otap_delay)
84{
85 if (deviceid == 0) {
86 zynqmp_mmio_write(SD_DLL_CTRL, SD0_DLL_RST_MASK, SD0_DLL_RST);
87
88 /* Program OTAP delay */
89 zynqmp_mmio_write(SD_OTAP_DLY, SD0_OTAPDLYSEL_MASK, otap_delay);
90
91 zynqmp_mmio_write(SD_DLL_CTRL, SD0_DLL_RST_MASK, 0x0);
92 } else {
93 zynqmp_mmio_write(SD_DLL_CTRL, SD1_DLL_RST_MASK, SD1_DLL_RST);
Siva Durga Prasad Paladugucad14a82018-04-19 12:37:09 +053094
Ashok Reddy Soma39a177a2021-07-09 05:53:42 -060095 /* Program OTAP delay */
96 zynqmp_mmio_write(SD_OTAP_DLY, SD1_OTAPDLYSEL_MASK,
97 (otap_delay << 16));
Siva Durga Prasad Paladugucad14a82018-04-19 12:37:09 +053098
Siva Durga Prasad Paladugucad14a82018-04-19 12:37:09 +053099 zynqmp_mmio_write(SD_DLL_CTRL, SD1_DLL_RST_MASK, 0x0);
Ashok Reddy Soma5fe3f412020-10-23 04:59:04 -0600100 }
Siva Durga Prasad Paladugucad14a82018-04-19 12:37:09 +0530101}