]> git.sur5r.net Git - freertos/blob - FreeRTOS/Demo/CORTEX_A9_Zynq_ZC702/RTOSDemo_bsp/ps7_cortexa9_0/include/xsdps.h
FreeRTOS source updates:
[freertos] / FreeRTOS / Demo / CORTEX_A9_Zynq_ZC702 / RTOSDemo_bsp / ps7_cortexa9_0 / include / xsdps.h
1 /******************************************************************************
2 *
3 * Copyright (C) 2013 - 2014 Xilinx, Inc.  All rights reserved.
4 *
5 * Permission is hereby granted, free of charge, to any person obtaining a copy
6 * of this software and associated documentation files (the "Software"), to deal
7 * in the Software without restriction, including without limitation the rights
8 * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9 * copies of the Software, and to permit persons to whom the Software is
10 * furnished to do so, subject to the following conditions:
11 *
12 * The above copyright notice and this permission notice shall be included in
13 * all copies or substantial portions of the Software.
14 *
15 * Use of the Software is limited solely to applications:
16 * (a) running on a Xilinx device, or
17 * (b) that interact with a Xilinx device through a bus or interconnect.
18 *
19 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
20 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
21 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
22 * XILINX  BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
23 * WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF
24 * OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
25 * SOFTWARE.
26 *
27 * Except as contained in this notice, the name of the Xilinx shall not be used
28 * in advertising or otherwise to promote the sale, use or other dealings in
29 * this Software without prior written authorization from Xilinx.
30 *
31 ******************************************************************************/
32 /*****************************************************************************/
33 /**
34 *
35 * @file xsdps.h
36 * @addtogroup sdps_v2_1
37 * @{
38 * @details
39 *
40 * This file contains the implementation of XSdPs driver.
41 * This driver is used initialize read from and write to the SD card.
42 * Features such as switching bus width to 4-bit and switching to high speed,
43 * changing clock frequency, block size etc. are supported.
44 * SD 2.0 uses 1/4 bus width and speeds of 25/50KHz. Initialization, however
45 * is done using 1-bit bus width and 400KHz clock frequency.
46 * SD commands are classified as broadcast and addressed. Commands can be
47 * those with response only (using only command line) or
48 * response + data (using command and data lines).
49 * Only one command can be sent at a time. During a data transfer however,
50 * when dsta lines are in use, certain commands (which use only the command
51 * line) can be sent, most often to obtain status.
52 * This driver does not support multi card slots at present.
53 *
54 * Intialization:
55 * This includes initialization on the host controller side to select
56 * clock frequency, bus power and default transfer related parameters.
57 * The default voltage is 3.3V.
58 * On the SD card side, the initialization and identification state diagram is
59 * implemented. This resets the card, gives it a unique address/ID and
60 * identifies key card related specifications.
61 *
62 * Data transfer:
63 * The SD card is put in tranfer state to read from or write to it.
64 * The default block size is 512 bytes and if supported,
65 * default bus width is 4-bit and bus speed is High speed.
66 * The read and write functions are implemented in polled mode using ADMA2.
67 *
68 * At any point, when key parameters such as block size or
69 * clock/speed or bus width are modified, this driver takes care of
70 * maintaining the same selection on host and card.
71 * All error bits in host controller are monitored by the driver and in the
72 * event one of them is set, driver will clear the interrupt status and
73 * communicate failure to the upper layer.
74 *
75 * File system use:
76 * This driver can be used with xilffs library to read and write files to SD.
77 * (Please refer to procedure in diskio.c). The file system read/write example
78 * in polled mode can used for reference.
79 *
80 * There is no example for using SD driver without file system at present.
81 * However, the driver can be used without the file system. The glue layer
82 * in filesytem can be used as reference for the same. The block count
83 * passed to the read/write function in one call is limited by the ADMA2
84 * descriptor table and hence care will have to be taken to call read/write
85 * API's in a loop for large file sizes.
86 *
87 * Interrupt mode is not supported because it offers no improvement when used
88 * with file system.
89 *
90 * eMMC support:
91 * SD driver supports SD and eMMC based on the "enable MMC" parameter in SDK.
92 * The features of eMMC supported by the driver will depend on those supported
93 * by the host controller. The current driver supports read/write on eMMC card
94 * using 4-bit and high speed mode currently.
95 *
96 * Features not supported include - card write protect, password setting,
97 * lock/unlock, interrupts, SDMA mode, programmed I/O mode and
98 * 64-bit addressed ADMA2, erase/pre-erase commands.
99 *
100 * <pre>
101 * MODIFICATION HISTORY:
102 *
103 * Ver   Who    Date     Changes
104 * ----- ---    -------- -----------------------------------------------
105 * 1.00a hk/sg  10/17/13 Initial release
106 * 2.0   hk      03/07/14 Version number revised.
107 * 2.1   hk     04/18/14 Increase sleep for eMMC switch command.
108 *                       Add sleep for microblaze designs. CR# 781117.
109 *
110 * </pre>
111 *
112 ******************************************************************************/
113
114
115 #ifndef SDPS_H_
116 #define SDPS_H_
117
118 #ifdef __cplusplus
119 extern "C" {
120 #endif
121
122 #include "xstatus.h"
123 #include "xsdps_hw.h"
124 #include <string.h>
125
126 /************************** Constant Definitions *****************************/
127
128 /**************************** Type Definitions *******************************/
129 /**
130  * This typedef contains configuration information for the device.
131  */
132 typedef struct {
133         u16 DeviceId;                   /**< Unique ID  of device */
134         u32 BaseAddress;                /**< Base address of the device */
135         u32 InputClockHz;               /**< Input clock frequency */
136 } XSdPs_Config;
137
138 /*
139  * ADMA2 descriptor table
140  */
141 typedef struct {
142         u16 Attribute;          /**< Attributes of descriptor */
143         u16 Length;             /**< Length of current dma transfer */
144         u32 Address;            /**< Address of current dma transfer */
145 } XSdPs_Adma2Descriptor;
146
147 /**
148  * The XSdPs driver instance data. The user is required to allocate a
149  * variable of this type for every SD device in the system. A pointer
150  * to a variable of this type is then passed to the driver API functions.
151  */
152 typedef struct {
153         XSdPs_Config Config;    /**< Configuration structure */
154         u32 IsReady;            /**< Device is initialized and ready */
155         u32 Host_Caps;          /**< Capabilities of host controller */
156         u32 HCS;                /**< High capacity support in card */
157         u32 CardID[4];          /**< Card ID */
158         u32 RelCardAddr;        /**< Relative Card Address */
159         XSdPs_Adma2Descriptor Adma2_DescrTbl[32]; /**< ADMA Descriptors */
160 } XSdPs;
161
162 /***************** Macros (Inline Functions) Definitions *********************/
163
164 /************************** Function Prototypes ******************************/
165 XSdPs_Config *XSdPs_LookupConfig(u16 DeviceId);
166 int XSdPs_CfgInitialize(XSdPs *InstancePtr, XSdPs_Config *ConfigPtr,
167                                 u32 EffectiveAddr);
168 int XSdPs_SdCardInitialize(XSdPs *InstancePtr);
169 int XSdPs_ReadPolled(XSdPs *InstancePtr, u32 Arg, u32 BlkCnt, u8 *Buff);
170 int XSdPs_WritePolled(XSdPs *InstancePtr, u32 Arg, u32 BlkCnt, const u8 *Buff);
171 int XSdPs_SetBlkSize(XSdPs *InstancePtr, u16 BlkSize);
172 int XSdPs_Select_Card (XSdPs *InstancePtr);
173 int XSdPs_Change_ClkFreq(XSdPs *InstancePtr, u32 SelFreq);
174 int XSdPs_Change_BusWidth(XSdPs *InstancePtr);
175 int XSdPs_Change_BusSpeed(XSdPs *InstancePtr);
176 int XSdPs_Get_BusWidth(XSdPs *InstancePtr, u8 *SCR);
177 int XSdPs_Get_BusSpeed(XSdPs *InstancePtr, u8 *ReadBuff);
178 int XSdPs_Pullup(XSdPs *InstancePtr);
179 int XSdPs_MmcCardInitialize(XSdPs *InstancePtr);
180 int XSdPs_Get_Mmc_ExtCsd(XSdPs *InstancePtr, u8 *ReadBuff);
181
182 #ifdef __cplusplus
183 }
184 #endif
185
186 #endif /* SD_H_ */
187 /** @} */