2 * @brief SD/SDIO (MCI) registers and control functions
\r
5 * Copyright(C) NXP Semiconductors, 2012
\r
6 * All rights reserved.
\r
9 * Software that is described herein is for illustrative purposes only
\r
10 * which provides customers with programming information regarding the
\r
11 * LPC products. This software is supplied "AS IS" without any warranties of
\r
12 * any kind, and NXP Semiconductors and its licensor disclaim any and
\r
13 * all warranties, express or implied, including all implied warranties of
\r
14 * merchantability, fitness for a particular purpose and non-infringement of
\r
15 * intellectual property rights. NXP Semiconductors assumes no responsibility
\r
16 * or liability for the use of the software, conveys no license or rights under any
\r
17 * patent, copyright, mask work right, or any other intellectual property rights in
\r
18 * or to any products. NXP Semiconductors reserves the right to make changes
\r
19 * in the software without notification. NXP Semiconductors also makes no
\r
20 * representation or warranty that such application will be suitable for the
\r
21 * specified use without further testing or modification.
\r
24 * Permission to use, copy, modify, and distribute this software and its
\r
25 * documentation is hereby granted, under NXP Semiconductors' and its
\r
26 * licensor's relevant copyrights in the software, without fee, provided that it
\r
27 * is used in conjunction with NXP Semiconductors microcontrollers. This
\r
28 * copyright, permission, and disclaimer notice must appear in all copies of
\r
32 #ifndef __SDMMC_001_H_
\r
33 #define __SDMMC_001_H_
\r
35 #include "sys_config.h"
\r
42 /** @defgroup IP_SDMMC_001 IP: SDMMC register block and driver
\r
43 * @ingroup IP_Drivers
\r
48 * @brief SD/MMC & SDIO register block structure
\r
50 typedef struct { /*!< SDMMC Structure */
\r
51 __IO uint32_t CTRL; /*!< Control Register */
\r
52 __IO uint32_t PWREN; /*!< Power Enable Register */
\r
53 __IO uint32_t CLKDIV; /*!< Clock Divider Register */
\r
54 __IO uint32_t CLKSRC; /*!< SD Clock Source Register */
\r
55 __IO uint32_t CLKENA; /*!< Clock Enable Register */
\r
56 __IO uint32_t TMOUT; /*!< Timeout Register */
\r
57 __IO uint32_t CTYPE; /*!< Card Type Register */
\r
58 __IO uint32_t BLKSIZ; /*!< Block Size Register */
\r
59 __IO uint32_t BYTCNT; /*!< Byte Count Register */
\r
60 __IO uint32_t INTMASK; /*!< Interrupt Mask Register */
\r
61 __IO uint32_t CMDARG; /*!< Command Argument Register */
\r
62 __IO uint32_t CMD; /*!< Command Register */
\r
63 __I uint32_t RESP0; /*!< Response Register 0 */
\r
64 __I uint32_t RESP1; /*!< Response Register 1 */
\r
65 __I uint32_t RESP2; /*!< Response Register 2 */
\r
66 __I uint32_t RESP3; /*!< Response Register 3 */
\r
67 __I uint32_t MINTSTS; /*!< Masked Interrupt Status Register */
\r
68 __IO uint32_t RINTSTS; /*!< Raw Interrupt Status Register */
\r
69 __I uint32_t STATUS; /*!< Status Register */
\r
70 __IO uint32_t FIFOTH; /*!< FIFO Threshold Watermark Register */
\r
71 __I uint32_t CDETECT; /*!< Card Detect Register */
\r
72 __I uint32_t WRTPRT; /*!< Write Protect Register */
\r
73 __IO uint32_t GPIO; /*!< General Purpose Input/Output Register */
\r
74 __I uint32_t TCBCNT; /*!< Transferred CIU Card Byte Count Register */
\r
75 __I uint32_t TBBCNT; /*!< Transferred Host to BIU-FIFO Byte Count Register */
\r
76 __IO uint32_t DEBNCE; /*!< Debounce Count Register */
\r
77 __IO uint32_t USRID; /*!< User ID Register */
\r
78 __I uint32_t VERID; /*!< Version ID Register */
\r
79 __I uint32_t RESERVED0;
\r
80 __IO uint32_t UHS_REG; /*!< UHS-1 Register */
\r
81 __IO uint32_t RST_N; /*!< Hardware Reset */
\r
82 __I uint32_t RESERVED1;
\r
83 __IO uint32_t BMOD; /*!< Bus Mode Register */
\r
84 __O uint32_t PLDMND; /*!< Poll Demand Register */
\r
85 __IO uint32_t DBADDR; /*!< Descriptor List Base Address Register */
\r
86 __IO uint32_t IDSTS; /*!< Internal DMAC Status Register */
\r
87 __IO uint32_t IDINTEN; /*!< Internal DMAC Interrupt Enable Register */
\r
88 __I uint32_t DSCADDR; /*!< Current Host Descriptor Address Register */
\r
89 __I uint32_t BUFADDR; /*!< Current Buffer Descriptor Address Register */
\r
92 /** @brief SDIO DMA descriptor control (des0) register defines
\r
94 #define MCI_DMADES0_OWN (1UL << 31) /*!< DMA owns descriptor bit */
\r
95 #define MCI_DMADES0_CES (1 << 30) /*!< Card Error Summary bit */
\r
96 #define MCI_DMADES0_ER (1 << 5) /*!< End of descriptopr ring bit */
\r
97 #define MCI_DMADES0_CH (1 << 4) /*!< Second address chained bit */
\r
98 #define MCI_DMADES0_FS (1 << 3) /*!< First descriptor bit */
\r
99 #define MCI_DMADES0_LD (1 << 2) /*!< Last descriptor bit */
\r
100 #define MCI_DMADES0_DIC (1 << 1) /*!< Disable interrupt on completion bit */
\r
102 /** @brief SDIO DMA descriptor size (des1) register defines
\r
104 #define MCI_DMADES1_BS1(x) (x) /*!< Size of buffer 1 */
\r
105 #define MCI_DMADES1_BS2(x) ((x) << 13) /*!< Size of buffer 2 */
\r
106 #define MCI_DMADES1_MAXTR 4096 /*!< Max transfer size per buffer */
\r
108 /** @brief SDIO control register defines
\r
110 #define MCI_CTRL_USE_INT_DMAC (1 << 25) /*!< Use internal DMA */
\r
111 #define MCI_CTRL_CARDV_MASK (0x7 << 16) /*!< SD_VOLT[2:0} pins output state mask */
\r
112 #define MCI_CTRL_CEATA_INT_EN (1 << 11) /*!< Enable CE-ATA interrupts */
\r
113 #define MCI_CTRL_SEND_AS_CCSD (1 << 10) /*!< Send auto-stop */
\r
114 #define MCI_CTRL_SEND_CCSD (1 << 9) /*!< Send CCSD */
\r
115 #define MCI_CTRL_ABRT_READ_DATA (1 << 8) /*!< Abort read data */
\r
116 #define MCI_CTRL_SEND_IRQ_RESP (1 << 7) /*!< Send auto-IRQ response */
\r
117 #define MCI_CTRL_READ_WAIT (1 << 6) /*!< Assert read-wait for SDIO */
\r
118 #define MCI_CTRL_INT_ENABLE (1 << 4) /*!< Global interrupt enable */
\r
119 #define MCI_CTRL_DMA_RESET (1 << 2) /*!< Reset internal DMA */
\r
120 #define MCI_CTRL_FIFO_RESET (1 << 1) /*!< Reset data FIFO pointers */
\r
121 #define MCI_CTRL_RESET (1 << 0) /*!< Reset controller */
\r
123 /** @brief SDIO Power Enable register defines
\r
125 #define MCI_POWER_ENABLE 0x1 /*!< Enable slot power signal (SD_POW) */
\r
127 /** @brief SDIO Clock divider register defines
\r
129 #define MCI_CLOCK_DIVIDER(dn, d2) ((d2) << ((dn) * 8)) /*!< Set cklock divider */
\r
131 /** @brief SDIO Clock source register defines
\r
133 #define MCI_CLKSRC_CLKDIV0 0
\r
134 #define MCI_CLKSRC_CLKDIV1 1
\r
135 #define MCI_CLKSRC_CLKDIV2 2
\r
136 #define MCI_CLKSRC_CLKDIV3 3
\r
137 #define MCI_CLK_SOURCE(clksrc) (clksrc) /*!< Set cklock divider source */
\r
139 /** @brief SDIO Clock Enable register defines
\r
141 #define MCI_CLKEN_LOW_PWR (1 << 16) /*!< Enable clock idle for slot */
\r
142 #define MCI_CLKEN_ENABLE (1 << 0) /*!< Enable slot clock */
\r
144 /** @brief SDIO time-out register defines
\r
146 #define MCI_TMOUT_DATA(clks) ((clks) << 8) /*!< Data timeout clocks */
\r
147 #define MCI_TMOUT_DATA_MSK 0xFFFFFF00
\r
148 #define MCI_TMOUT_RESP(clks) ((clks) & 0xFF) /*!< Response timeout clocks */
\r
149 #define MCI_TMOUT_RESP_MSK 0xFF
\r
151 /** @brief SDIO card-type register defines
\r
153 #define MCI_CTYPE_8BIT (1 << 16) /*!< Enable 4-bit mode */
\r
154 #define MCI_CTYPE_4BIT (1 << 0) /*!< Enable 8-bit mode */
\r
156 /** @brief SDIO Interrupt status & mask register defines
\r
158 #define MCI_INT_SDIO (1 << 16) /*!< SDIO interrupt */
\r
159 #define MCI_INT_EBE (1 << 15) /*!< End-bit error */
\r
160 #define MCI_INT_ACD (1 << 14) /*!< Auto command done */
\r
161 #define MCI_INT_SBE (1 << 13) /*!< Start bit error */
\r
162 #define MCI_INT_HLE (1 << 12) /*!< Hardware locked error */
\r
163 #define MCI_INT_FRUN (1 << 11) /*!< FIFO overrun/underrun error */
\r
164 #define MCI_INT_HTO (1 << 10) /*!< Host data starvation error */
\r
165 #define MCI_INT_DTO (1 << 9) /*!< Data timeout error */
\r
166 #define MCI_INT_RTO (1 << 8) /*!< Response timeout error */
\r
167 #define MCI_INT_DCRC (1 << 7) /*!< Data CRC error */
\r
168 #define MCI_INT_RCRC (1 << 6) /*!< Response CRC error */
\r
169 #define MCI_INT_RXDR (1 << 5) /*!< RX data ready */
\r
170 #define MCI_INT_TXDR (1 << 4) /*!< TX data needed */
\r
171 #define MCI_INT_DATA_OVER (1 << 3) /*!< Data transfer over */
\r
172 #define MCI_INT_CMD_DONE (1 << 2) /*!< Command done */
\r
173 #define MCI_INT_RESP_ERR (1 << 1) /*!< Command response error */
\r
174 #define MCI_INT_CD (1 << 0) /*!< Card detect */
\r
176 /** @brief SDIO Command register defines
\r
178 #define MCI_CMD_START (1UL << 31) /*!< Start command */
\r
179 #define MCI_CMD_VOLT_SWITCH (1 << 28) /*!< Voltage switch bit */
\r
180 #define MCI_CMD_BOOT_MODE (1 << 27) /*!< Boot mode */
\r
181 #define MCI_CMD_DISABLE_BOOT (1 << 26) /*!< Disable boot */
\r
182 #define MCI_CMD_EXPECT_BOOT_ACK (1 << 25) /*!< Expect boot ack */
\r
183 #define MCI_CMD_ENABLE_BOOT (1 << 24) /*!< Enable boot */
\r
184 #define MCI_CMD_CCS_EXP (1 << 23) /*!< CCS expected */
\r
185 #define MCI_CMD_CEATA_RD (1 << 22) /*!< CE-ATA read in progress */
\r
186 #define MCI_CMD_UPD_CLK (1 << 21) /*!< Update clock register only */
\r
187 #define MCI_CMD_INIT (1 << 15) /*!< Send init sequence */
\r
188 #define MCI_CMD_STOP (1 << 14) /*!< Stop/abort command */
\r
189 #define MCI_CMD_PRV_DAT_WAIT (1 << 13) /*!< Wait before send */
\r
190 #define MCI_CMD_SEND_STOP (1 << 12) /*!< Send auto-stop */
\r
191 #define MCI_CMD_STRM_MODE (1 << 11) /*!< Stream transfer mode */
\r
192 #define MCI_CMD_DAT_WR (1 << 10) /*!< Read(0)/Write(1) selection */
\r
193 #define MCI_CMD_DAT_EXP (1 << 9) /*!< Data expected */
\r
194 #define MCI_CMD_RESP_CRC (1 << 8) /*!< Check response CRC */
\r
195 #define MCI_CMD_RESP_LONG (1 << 7) /*!< Response length */
\r
196 #define MCI_CMD_RESP_EXP (1 << 6) /*!< Response expected */
\r
197 #define MCI_CMD_INDX(n) ((n) & 0x1F)
\r
199 /** @brief SDIO status register definess
\r
201 #define MCI_STS_GET_FCNT(x) (((x) >> 17) & 0x1FF)
\r
203 /** @brief SDIO FIFO threshold defines
\r
205 #define MCI_FIFOTH_TX_WM(x) ((x) & 0xFFF)
\r
206 #define MCI_FIFOTH_RX_WM(x) (((x) & 0xFFF) << 16)
\r
207 #define MCI_FIFOTH_DMA_MTS_1 (0UL << 28)
\r
208 #define MCI_FIFOTH_DMA_MTS_4 (1UL << 28)
\r
209 #define MCI_FIFOTH_DMA_MTS_8 (2UL << 28)
\r
210 #define MCI_FIFOTH_DMA_MTS_16 (3UL << 28)
\r
211 #define MCI_FIFOTH_DMA_MTS_32 (4UL << 28)
\r
212 #define MCI_FIFOTH_DMA_MTS_64 (5UL << 28)
\r
213 #define MCI_FIFOTH_DMA_MTS_128 (6UL << 28)
\r
214 #define MCI_FIFOTH_DMA_MTS_256 (7UL << 28)
\r
216 /** @brief Bus mode register defines
\r
218 #define MCI_BMOD_PBL1 (0 << 8) /*!< Burst length = 1 */
\r
219 #define MCI_BMOD_PBL4 (1 << 8) /*!< Burst length = 4 */
\r
220 #define MCI_BMOD_PBL8 (2 << 8) /*!< Burst length = 8 */
\r
221 #define MCI_BMOD_PBL16 (3 << 8) /*!< Burst length = 16 */
\r
222 #define MCI_BMOD_PBL32 (4 << 8) /*!< Burst length = 32 */
\r
223 #define MCI_BMOD_PBL64 (5 << 8) /*!< Burst length = 64 */
\r
224 #define MCI_BMOD_PBL128 (6 << 8) /*!< Burst length = 128 */
\r
225 #define MCI_BMOD_PBL256 (7 << 8) /*!< Burst length = 256 */
\r
226 #define MCI_BMOD_DE (1 << 7) /*!< Enable internal DMAC */
\r
227 #define MCI_BMOD_DSL(len) ((len) << 2) /*!< Descriptor skip length */
\r
228 #define MCI_BMOD_FB (1 << 1) /*!< Fixed bursts */
\r
229 #define MCI_BMOD_SWR (1 << 0) /*!< Software reset of internal registers */
\r
231 /** @brief Commonly used definitions
\r
233 #define SD_FIFO_SZ 32 /*!< Size of SDIO FIFOs (32-bit wide) */
\r
235 /** Function prototype for SD interface IRQ callback */
\r
236 typedef uint32_t (*MCI_IRQ_CB_FUNC_T)(uint32_t);
\r
238 /** Function prototype for SD detect and write protect status check */
\r
239 typedef int32_t (*PSCHECK_FUNC_T)(void);
\r
241 /** Function prototype for SD slot power enable or slot reset */
\r
242 typedef void (*PS_POWER_FUNC_T)(int32_t enable);
\r
244 /** @brief SDIO chained DMA descriptor
\r
247 volatile uint32_t des0; /*!< Control and status */
\r
248 volatile uint32_t des1; /*!< Buffer size(s) */
\r
249 volatile uint32_t des2; /*!< Buffer address pointer 1 */
\r
250 volatile uint32_t des3; /*!< Buffer address pointer 2 */
\r
253 /** @brief SDIO device type
\r
255 typedef struct _sdif_device {
\r
256 /* MCI_IRQ_CB_FUNC_T irq_cb; */
\r
257 pSDMMC_DMA_T mci_dma_dd[1 + (0x100000 / MCI_DMADES1_MAXTR)];
\r
258 /* uint32_t sdio_clk_rate; */
\r
259 /* uint32_t sdif_slot_clk_rate; */
\r
260 /* int32_t clock_enabled; */
\r
264 * @brief Initializes the MCI card controller
\r
265 * @param pSDMMC Pointer to IP_SDMMC_001_T structure
\r
268 void IP_SDMMC_Init(IP_SDMMC_001_T *pSDMMC);
\r
271 * @brief Close the MCI
\r
272 * @param pSDMMC : Pointer to IP_SDMMC_001_T structure
\r
275 void IP_SDMMC_DeInit(IP_SDMMC_001_T *pSDMMC);
\r
278 * @brief Set block size for transfer
\r
279 * @param pSDMMC : Pointer to IP_SDMMC_001_T structure
\r
280 * @param bytes : block size in bytes
\r
283 void IP_SDMMC_SetBlkSize(IP_SDMMC_001_T *pSDMMC, uint32_t bytes);
\r
286 * @brief Reset card in slot
\r
287 * @param pSDMMC : Pointer to IP_SDMMC_001_T structure
\r
288 * @param reset : Sets SD_RST to passed state
\r
290 * @note Reset card in slot, must manually de-assert reset after assertion
\r
291 * (Uses SD_RST pin, set per reset parameter state)
\r
293 void IP_SDMMC_Reset(IP_SDMMC_001_T *pSDMMC, int32_t reset);
\r
296 * @brief Enable slot power
\r
297 * @param pSDMMC : Pointer to IP_SDMMC_001_T structure
\r
299 * @note Uses SD_POW pin, set to high.
\r
301 STATIC INLINE void IP_SDMMC_PowerOn(IP_SDMMC_001_T *pSDMMC)
\r
307 * @brief Disable slot power
\r
308 * @param pSDMMC : Pointer to IP_SDMMC_001_T structure
\r
310 * @note Uses SD_POW pin, set to low.
\r
312 STATIC INLINE void IP_SDMMC_PowerOff(IP_SDMMC_001_T *pSDMMC)
\r
318 * @brief Detect if write protect is enabled
\r
319 * @param pSDMMC : Pointer to IP_SDMMC_001_T structure
\r
320 * @return Returns 1 if card is write protected, otherwise 0
\r
321 * @note Detect if write protect is enabled
\r
322 * (uses SD_WP pin, returns 1 if card is write protected)
\r
324 STATIC INLINE int32_t IP_SDMMC_CardWpOn(IP_SDMMC_001_T *pSDMMC)
\r
326 return (pSDMMC->WRTPRT & 1);
\r
330 * @brief Detect if an SD card is inserted
\r
331 * @param pSDMMC : Pointer to IP_SDMMC_001_T structure
\r
332 * @return Returns 0 if a card is detected, otherwise 1
\r
333 * @note Detect if an SD card is inserted
\r
334 * (uses SD_CD pin, returns 0 on card detect)
\r
336 STATIC INLINE int32_t IP_SDMMC_CardNDetect(IP_SDMMC_001_T *pSDMMC)
\r
338 return (pSDMMC->CDETECT & 1);
\r
342 * @brief Function to send command to Card interface unit (CIU)
\r
343 * @param pSDMMC : Pointer to IP_SDMMC_001_T structure
\r
344 * @param cmd : Command with all flags set
\r
345 * @param arg : Argument for the command
\r
346 * @return TRUE on times-out, otherwise FALSE
\r
348 int32_t IP_SDMMC_SendCmd(IP_SDMMC_001_T *pSDMMC, uint32_t cmd, uint32_t arg);
\r
351 * @brief Read the response from the last command
\r
352 * @param pSDMMC : Pointer to IP_SDMMC_001_T structure
\r
353 * @param resp : Pointer to response array to fill
\r
356 void IP_SDMMC_GetResponse(IP_SDMMC_001_T *pSDMMC, uint32_t *resp);
\r
359 * @brief Sets the SD bus clock speed
\r
360 * @param pSDMMC : Pointer to IP_SDMMC_001_T structure
\r
361 * @param clk_rate : Input clock rate into the IP block
\r
362 * @param speed : Desired clock speed to the card
\r
365 void IP_SDMMC_SetClock(IP_SDMMC_001_T *pSDMMC, uint32_t clk_rate, uint32_t speed);
\r
368 * @brief Function to set card type
\r
369 * @param pSDMMC : Pointer to IP_SDMMC_001_T structure
\r
370 * @param ctype : card type
\r
373 void IP_SDMMC_SetCardType(IP_SDMMC_001_T *pSDMMC, uint32_t ctype);
\r
376 * @brief Function to clear interrupt & FIFOs
\r
377 * @param pSDMMC : Pointer to IP_SDMMC_001_T structure
\r
380 void IP_SDMMC_SetClearIntFifo(IP_SDMMC_001_T *pSDMMC);
\r
383 * @brief Returns the raw SD interface interrupt status
\r
384 * @param pSDMMC : Pointer to IP_SDMMC_001_T structure
\r
385 * @return Raw interrupt status of Or'ed values MCI_INT_*
\r
387 uint32_t IP_SDMMC_GetRawIntStatus(IP_SDMMC_001_T *pSDMMC);
\r
390 * @brief Sets the raw SD interface interrupt status
\r
391 * @param pSDMMC : Pointer to IP_SDMMC_001_T structure
\r
392 * @param iVal : Raw interrupts to set, Or'ed values MCI_INT_*
\r
395 void IP_SDMMC_SetRawIntStatus(IP_SDMMC_001_T *pSDMMC, uint32_t iVal);
\r
398 * @brief Sets the SD interface interrupt mask
\r
399 * @param pSDMMC : Pointer to IP_SDMMC_001_T structure
\r
400 * @param iVal : Interrupts to enable, Or'ed values MCI_INT_*
\r
403 void IP_SDMMC_SetIntMask(IP_SDMMC_001_T *pSDMMC, uint32_t iVal);
\r
406 * @brief Setup DMA descriptors
\r
407 * @param pSDMMC : Pointer to IP_SDMMC_001_T structure
\r
408 * @param psdif_dev : SD interface device
\r
409 * @param addr : Address of buffer (source or destination)
\r
410 * @param size : size of buffer in bytes (64K max)
\r
413 void IP_SDMMC_DmaSetup(IP_SDMMC_001_T *pSDMMC, sdif_device *psdif_dev, uint32_t addr, uint32_t size);
\r
416 * @brief Set block size and byte count for transfer
\r
417 * @param pSDMMC : Pointer to IP_SDMMC_001_T structure
\r
418 * @param blk_size: block size and byte count in bytes
\r
421 void IP_SDMMC_SetBlkSizeByteCnt(IP_SDMMC_001_T *pSDMMC, uint32_t blk_size);
\r
424 * @brief Set byte count for transfer
\r
425 * @param pSDMMC : Pointer to IP_SDMMC_001_T structure
\r
426 * @param bytes : block size and byte count in bytes
\r
429 void IP_SDMMC_SetByteCnt(IP_SDMMC_001_T *pSDMMC, uint32_t bytes);
\r
439 #endif /* __SDMMC_001_H_ */
\r