1 /*
2  * @ : Copyright (c) 2021 Phytium Information Technology, Inc.
3  *
4  * SPDX-License-Identifier: Apache-2.0.
5  *
6  * @Date: 2021-03-31 14:59:20
7  * @LastEditTime: 2021-04-19 16:17:39
8  * @Description:  This files is for sd ctrl register
9  *
10  * @Modify History: * * Ver   Who        Date         Changes
11  * ----- ------     --------    --------------------------------------
12  */
13 
14 #ifndef _SDCTRL_HW_H
15 #define _SDCTRL_HW_H
16 
17 #include "ft_sdctrl.h"
18 
19 /* Register Offset */
20 
21 #define CONTROLL_SETTING_REG_OFFSET 0x00 /* Controller configuration register */
22 #define ARGUMENT_REG_OFFSET 0x04         /* Parameter register */
23 #define CMD_SETTING_REG_OFFSET 0x08      /* Command register */
24 #define CLOCK_DIV_REG_OFFSET 0x0C        /* Clock division register */
25 #define SOFTWARE_RESET_REG_OFFSET 0x10   /* Reset control register */
26 #define POWER_CONTROLL_REG_OFFSET 0x14   /* Power control register */
27 #define TIMEOUT_CMD_REG_OFFSET 0x18      /* cmd Timeout setting register */
28 #define TIMEOUT_DATA_REG_OFFSET 0x1C     /* Data timeout setting register */
29 #define NORMAL_INT_EN_REG_OFFSET 0x20    /* Interrupt Enable Register */
30 #define ERROR_INT_EN_REG_OFFSET 0x24     /* error Interrupt Enable Register */
31 #define BD_ISR_EN_REG_OFFSET 0x28        /* Data Transfer Interrupt Enable Register */
32 #define CAPABILIES_REG_OFFSET 0x2c       /* capabilies register */
33 #define SD_DRV_REG_OFFSET 0x30           /* SD card driver phase register */
34 #define SD_SAMP_REG_OFFSET 0x34          /* SD card sampling phase register */
35 #define SD_SEN_REG_OFFSET 0x38           /* Card detection controller */
36 #define HDS_AXI_REG_CONF1_OFFSET 0x3c    /* AXI boundary configuration register 1 */
37 #define DAT_IN_M_RX_BD 0x40              /*  SD BD RX address register */
38 #define DAT_IN_M_TX_BD 0x60              /*  SD BD TX address register */
39 #define BLK_CNT_REG 0x80                 /*  Block reads and writes configuration registers */
40 #define HDS_AXI_REG_CONF2 0xa8           /*  AXI boundary configuration register 2 */
41 #define NORMAL_INT_STATUS_REG 0xc0       /*  Interrupt status register */
42 #define ERROR_INT_STATUS_REG 0xc4        /*  ERROR interrupt register */
43 #define BD_ISR_REG 0xc8                  /*  Data Transfer Interrupt Status Register */
44 #define BD_STATUS 0xcc                   /*  BD descriptor register */
45 #define STATUS_REG 0xd0                  /*  state register */
46 #define BLOCK 0xd4                       /*  Block length register */
47 #define CMD_RESP_1 0xe0                  /*  Command response register 1 */
48 #define CMD_RESP_2 0xe4                  /*  Command response register 2 */
49 #define CMD_RESP_3 0xe8                  /*  Command response register 3 */
50 #define CMD_RESP_4 0xec                  /*  Command response register 4 */
51 
52 /* Controller configuration register */
53 #define CONTROLL_SETTING_PERMDR(x) ((x & 3) << 8)  /* Read operation corresponding to the size of the end selection: 00: small end alignment,01: large end alignment,10: SD protocol mode */
54 #define CONTROLL_SETTING_PERMDW(x) ((x & 3) << 10) /* Write operation corresponding to the size of the endian selection: 00: small endian alignment 01: large endian alignment 10: SD protocol mode*/
55 
56 /* Parameter register */
57 #define ARGUMENT_REG(x) (x & 0xffffffff)
58 
59 /* Command register */
60 #define CMD_SETTING_RTS(x) ((x & 3) << 0) /* 0: No response 01: Response byte length 136 10: Response byte length 48 11: Response byte length 48 */
61 #define CMD_SETTING_CRCE (1U << 3)        /* 0: CRC check is not performed on CMD response 1: CRC check is performed on CMD response */
62 #define CMD_SETTING_CICE (1U << 4)        /* 0:CMD 响应时,不执行索引检查 1:CMD 响应时,执行索引检查 */
63 #define CMD_SETTING_CMDW(x) ((x & 3) << 6)
64 #define CMD_SETTING_CMDI(x) ((x & 0x3f) << 8) /* 命令索引 */
65 #define CMD_SETTING_TRTY(x) ((x & 3) << 14)   /* 10: adtc 指令 ,其它: 读写操作 */
66 
67 /* 时钟分频寄存器 */
68 #define CLOCK_DIV_RE(x) (x & 0xffffffff) /* CLKD-时钟分频系数 SD_frequency= 600M/ (2*(clock_d+1)) */
69 
70 /* 复位控制寄存器 */
71 #define SOFTWARE_RESET_SRST (1U)  /* 控制器软复位 */
72 #define SOFTWARE_RESET_BDRST (4U) /* DMA BD 清 0 */
73 #define SOFTWARE_RESET_CFCLF (8U) /* 卡插入拔出状态触发标志清 0 */
74 
75 /* cmd 超时设置寄存器 */
76 #define TIMEOUT_CMD_REG(x) (x & 0xffffffff) /* command 超时参数 */
77 
78 /* 数据超时设置寄存器 */
79 #define TIMEOUT_DATA_REG(x) (x & 0xffffffff) /* data 超时参数 */
80 
81 /* 中断使能寄存器 */
82 #define NORMAL_INT_EN_ECC 1U          /* 命令完成中断使能 */
83 #define NORMAL_INT_EN_ECCRCE 2U       /* 卡拔出中断使能 */
84 #define NORMAL_INT_EN_ECIE (1U << 15) /* 错误中断使能 */
85 
86 /* error 中断使能寄存器 */
87 #define ERROR_INT_EN_CNR (1U << 4)   /* Command response error interrupted */
88 #define ERROR_INT_EN_CIR (1U << 3)   /* 命令索引错误中断使能 */
89 #define ERROR_INT_EN_CCRCE (1U << 1) /* 命令 CRC 错误中断使能 */
90 #define ERROR_INT_EN_CTE (1U << 0)   /* 命令超时中断使能 */
91 
92 /* 数据传输中断使能寄存器 */
93 #define BD_ISR_EN_ETRS (1U << 0)      /* DMA 传输完成中断使能 */
94 #define BD_ISR_EN_EDTE (1U << 3)      /* 数据超时中断使能 */
95 #define BD_ISR_EN_ECMDE (1U << 4)     /* 命令响应错误中断使能 */
96 #define BD_ISR_EN_ETRE (1U << 5)      /* 传输错误中断使能 */
97 #define BD_ISR_EN_ENRCRCE (1U << 6)   /* CRC 校验错误中断使能 */
98 #define BD_ISR_EN_EDATFRAXE (1U << 7) /* AXI 总线错误中断使能 */
99 #define BD_ISR_EN_RESPE (1U << 8)     /* 读 SD 卡操作,AXI BR 通道完成中断 */
100 #define BD_ISR_EN_EDAISE (1U << 15)   /* DMA 错误中断使能 */
101 #define BD_ISR_ALL_MASK (BD_ISR_EN_ETRS | BD_ISR_EN_EDTE |         \
102                          BD_ISR_EN_ECMDE | BD_ISR_EN_ETRE |        \
103                          BD_ISR_EN_ENRCRCE | BD_ISR_EN_EDATFRAXE | \
104                          BD_ISR_EN_RESPE | BD_ISR_EN_EDAISE)
105 
106 /* 状态寄存器 */
107 #define CAPABILIES_REG(x) (x & 0xffffffff)
108 
109 /* SD 卡驱动相位寄存器 */
110 #define SD_DRV_REG(x) (x & 0xffffffff) /* 卡驱动相位配置参数 */
111 
112 /* SD 卡采样相位寄存器 */
113 #define SD_SAMP_REG(x) (x & 0xffffffff) /* 卡采样相位配置参数 */
114 #define SD_SAMP_DEFAULT 11              /* when SD card work in high-speed mode, \
115                                         the best sampling pharse is needed to    \
116                                         get the correct data */
117 #define SD_FRRQ_DIV_DEFAULT 5           /* default freq div */
118 #define SD_CLK_FREQ_400KHZ 400000
119 #define SD_CLK_FREQ_25MHZ 25000000
120 
121 /* 卡检测控制器 */
122 #define SD_SEN_REG_CREFR (1U << 1)                 /* 卡拔出时自动释放 AXI 总线选择 */
123 #define SD_SEN_REG_CRES (1U << 2)                  /* CARD 在位状态标志选择 0: 卡在位-0,不在位-1 1: 卡在位-1,不在位-0 */
124 #define SD_SEN_REG_DEBNCE(x) ((x & 0xffffff) << 8) /* 去抖时钟分频参数 */
125 
126 /* AXI 边界配置寄存器 1 */
127 #define HDS_AXI_REG_CONF1_AWDOMAIN_HDS_M(x) ((x & 0x3) << 0)
128 #define HDS_AXI_REG_CONF1_AWBAR_HDS_M(x) ((x & 0x3) << 2)
129 #define HDS_AXI_REG_CONF1_ARSNOOP_HDS_M(x) ((x & 0xf) << 4)
130 #define HDS_AXI_REG_CONF1_ARREGION_HDS_M(x) ((x & 0xf) << 8)
131 #define HDS_AXI_REG_CONF1_ARDOMAIN_HDS_M(x) ((x & 0x3) << 12)
132 #define HDS_AXI_REG_CONF1_ARBAR_HDS_M(x) ((x & 0x3) << 14)
133 #define HDS_AXI_REG_CONF1_AWSNOOP_HDS_M(x) ((x & 0x7) << 16)
134 #define HDS_AXI_REG_CONF1_AWREGION_HDS_M(x) ((x & 0xF) << 19)
135 
136 /*  SD BD RX 地址寄存器 */
137 #define DAT_IN_M_RX_BD_MASK(x) (x & 0xffffffff) /* dma 读卡地址配置:4 个 cycle ,系统低 4B-系统高 4B-SD 低 4B- SD 高 4B */
138 
139 /*  SD BD TX 地址寄存器 */
140 #define DAT_IN_M_TX_BD_MASK(x) (x & 0xffffffff) /* dma 写卡地址配置:4 个 cycle ,系统低 4B-系统高 4B-SD 低 4B- SD 高 4B */
141 
142 /*  块读写配置寄存器 */
143 #define BLK_CNT(x) (x & 0xffffffff) /* dma block num setting */
144 
145 /*  AXI 边界配置寄存器 2 */
146 #define HDS_AXI_REG_CONF2_D_ARPROT(x) ((x & 0x7) << 27)
147 #define HDS_AXI_REG_CONF2_SD_AWPROT(x) ((x & 0x7) << 24)
148 #define HDS_AXI_REG_CONF2_SD_ARCACHE_M(x) ((x & 0xf) << 20)
149 #define HDS_AXI_REG_CONF2_SD_AWCACHE_M(x) ((x & 0xf) << 16)
150 #define HDS_AXI_REG_CONF2_RESERVED(x) ((x & 0x3) << 14)
151 #define HDS_AXI_REG_CONF2_HDA_ARPRO(x) ((x & 0x7) << 11)
152 #define HDS_AXI_REG_CONF2_HDA_AWPROT(x) ((x & 0x7) << 8)
153 #define HDS_AXI_REG_CONF2_HDA_ARCACHE_M(x) ((x & 0xf) << 4)
154 #define HDS_AXI_REG_CONF2_HDA_AWCACHE_M(x) ((x & 0xf) << 0)
155 
156 /*  中断状态寄存器 */
157 #define NORMAL_INT_STATUS_EI (1U << 15) /* 命令错误中断 */
158 #define NORMAL_INT_STATUS_CR (1U << 1)  /* 卡移除中断 */
159 #define NORMAL_INT_STATUS_CC 1U         /* 命令完成中断 */
160 #define NORMAL_INT_STATUS_ALL_MASK (NORMAL_INT_STATUS_EI | NORMAL_INT_STATUS_CR | NORMAL_INT_STATUS_CC)
161 
162 /*  error 中断寄存器 */
163 #define ERROR_INT_STATUS_CNR (1U << 4)   /* 命令响应错误中断 */
164 #define ERROR_INT_STATUS_CIR (1U << 3)   /* 命令索引错误中断 */
165 #define ERROR_INT_STATUS_CCRCE (1U << 1) /* 命令 CRC 错误中断 */
166 #define ERROR_INT_STATUS_CTE 1U          /* 命令超时错误中断 */
167 #define ERROR_INT_STATUS_ALL_MASK (ERROR_INT_STATUS_CNR | ERROR_INT_STATUS_CIR | ERROR_INT_STATUS_CCRCE | ERROR_INT_STATUS_CTE)
168 
169 /*  数据传输中断状态寄存器 */
170 #define BD_ISR_REG_DAIS (1U << 15)   /* DMA 错误中断*/
171 #define BD_ISR_REG_RESPE (1U << 8)   /* 读 SD 卡操作,AXI BR 通道完成中断*/
172 #define BD_ISR_REG_DATFRAX (1U << 7) /* axi 总线强制释放中断*/
173 #define BD_ISR_REG_NRCRC (1U << 6)   /* 无 CRC 响应中断*/
174 #define BD_ISR_REG_TRE (1U << 5)     /* CRC 响应错误中断*/
175 #define BD_ISR_REG_CMDE (1U << 4)    /* 命令响应错误中断*/
176 #define BD_ISR_REG_DTE (1U << 3)     /* 超时中断*/
177 #define BD_ISR_REG_TRS (1U << 0)     /* DMA 传输完成中断*/
178 
179 /*  bd 描述符寄存器 */
180 #define BD_STATUS_REG(x) (x & 0xffffffff) /*  bd 描述符寄存器 */
181 
182 /*  状态寄存器 */
183 #define STATUS_REG_DATMAST(x) ((x & 0xf) << 27) /* data_master 状态机 */
184 #define STATUS_REG_CDIF (1U << 26)              /* 卡在位标志 */
185 #define STATUS_REG_CDRF (1U << 25)              /* 卡不在位标志 */
186 #define STATUS_REG_CLSL (1U << 24)              /* 命令闲信号 */
187 #define STATUS_REG_DLSL(x) ((x & 0xf) << 20)    /* 线信号 */
188 #define STATUS_REG_CDSL (1U << 19)              /* 卡检测管脚信号 */
189 #define STATUS_REG_CST(x) ((x & 0xf) << 12)     /* cmd_host state 状态机 */
190 #define STATUS_REG_CSM(x) ((x & 0X1F) << 7)
191 #define STATUS_REG_DAT_AVA (1 << 6) /* DAT_AVA 当前命令状态流程运转完  */
192 #define STATUS_REG_CRC_VALID (1 << 5)
193 #define STATUS_REG_CICMD 1U /* RO 0x0 CMD 总线状态 */
194 
195 /*  块长度寄存器 */
196 #define BLOCK_RGE(x) (x & 0xffffffff) /*  块长度寄存器 */
197 
198 /*  命令响应寄存器 1 */
199 #define CMD_RESP_1_REG(x) (x & 0xffffffff)
200 
201 /*  命令响应寄存器 2 */
202 #define CMD_RESP_2_REG(x) (x & 0xffffffff)
203 
204 /*  命令响应寄存器 3 */
205 #define CMD_RESP_3_REG(x) (x & 0xffffffff)
206 
207 /*  命令响应寄存器 4 */
208 #define CMD_RESP_4_REG(x) (x & 0xffffffff)
209 
210 #endif // !
211