blob: 305ba9cfebabc9ea7b928ea094bf84ec69aca73b [file] [log] [blame]
Subbaraman Narayanamurthy7c674102011-03-01 19:41:18 -08001/* Copyright (c) 2010-2011, Code Aurora Forum. All rights reserved.
Shashank Mittal52525ff2010-04-13 11:11:10 -07002
3 * Redistribution and use in source and binary forms, with or without
4 * modification, are permitted provided that the following conditions are
5 * met:
6 * * Redistributions of source code must retain the above copyright
7 * notice, this list of conditions and the following disclaimer.
8 * * Redistributions in binary form must reproduce the above
9 * copyright notice, this list of conditions and the following
10 * disclaimer in the documentation and/or other materials provided
11 * with the distribution.
12 * * Neither the name of Code Aurora Forum, Inc. nor the names of its
13 * contributors may be used to endorse or promote products derived
14 * from this software without specific prior written permission.
15 *
16 * THIS SOFTWARE IS PROVIDED "AS IS" AND ANY EXPRESS OR IMPLIED
17 * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
18 * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT
19 * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS
20 * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
21 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
22 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR
23 * BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
24 * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE
25 * OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN
26 * IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
27 */
28
29#ifndef __MMC_H__
30#define __MMC_H__
31
Shashank Mittal52525ff2010-04-13 11:11:10 -070032#ifndef MMC_SLOT
33#define MMC_SLOT 0
34#endif
35
Amol Jadi84a546a2011-03-02 12:09:11 -080036extern unsigned int mmc_boot_mci_base;
37
Subbaraman Narayanamurthy4b43c352010-09-24 13:20:52 -070038#define MMC_BOOT_MCI_REG(offset) ((mmc_boot_mci_base) + offset)
Shashank Mittal52525ff2010-04-13 11:11:10 -070039
40/*
41 * Define Macros for SDCC Registers
42 */
43#define MMC_BOOT_MCI_POWER MMC_BOOT_MCI_REG(0x000) /* 8 bit */
44
45/* MCICMD output control - 6th bit */
46#ifdef PLATFORM_MSM7X30
47#define MMC_BOOT_MCI_OPEN_DRAIN (1 << 6)
48#define MMC_BOOT_MCI_PWR_OFF 0x00
49#define MMC_BOOT_MCI_PWR_UP 0x01
50#define MMC_BOOT_MCI_PWR_ON 0x01
51#else
52#define MMC_BOOT_MCI_OPEN_DRAIN (1 << 6)
53#define MMC_BOOT_MCI_PWR_OFF 0x00
54#define MMC_BOOT_MCI_PWR_UP 0x02
55#define MMC_BOOT_MCI_PWR_ON 0x03
56#endif
57
58#define MMC_BOOT_MCI_CLK MMC_BOOT_MCI_REG(0x004) /* 16 bits */
59/* Enable MCI bus clock - 0: clock disabled 1: enabled */
60#define MMC_BOOT_MCI_CLK_ENABLE (1 << 8)
61/* Disable clk o/p when bus idle- 0:always enabled 1:enabled when bus active */
62#define MMC_BOOT_MCI_CLK_PWRSAVE (1 << 9)
63/* Enable Widebus mode - 00: 1 bit mode 10:4 bit mode 01/11: 8 bit mode */
64#define MMC_BOOT_MCI_CLK_WIDEBUS_MODE (3 << 10)
65#define MMC_BOOT_MCI_CLK_WIDEBUS_1_BIT 0
66#define MMC_BOOT_MCI_CLK_WIDEBUS_4_BIT (2 << 10)
67#define MMC_BOOT_MCI_CLK_WIDEBUS_8_BIT (1 << 10)
68/* Enable flow control- 0: disable 1: enable */
69#define MMC_BOOT_MCI_CLK_ENA_FLOW (1 << 12)
70/* Set/clear to select rising/falling edge for data/cmd output */
71#define MMC_BOOT_MCI_CLK_INVERT_OUT (1 << 13)
72/* Select to lach data/cmd coming in falling/rising/feedbk/loopbk of MCIclk */
73#define MMC_BOOT_MCI_CLK_IN_FALLING 0x0
74#define MMC_BOOT_MCI_CLK_IN_RISING (1 << 14)
75#define MMC_BOOT_MCI_CLK_IN_FEEDBACK (2 << 14)
76#define MMC_BOOT_MCI_CLK_IN_LOOPBACK (3 << 14)
77
78/* Bus Width */
79#define MMC_BOOT_BUS_WIDTH_1_BIT 0
80#define MMC_BOOT_BUS_WIDTH_4_BIT 2
81#define MMC_BOOT_BUS_WIDTH_8_BIT 3
82
83#define MMC_BOOT_MCI_ARGUMENT MMC_BOOT_MCI_REG(0x008) /* 32 bits */
84
85#define MMC_BOOT_MCI_CMD MMC_BOOT_MCI_REG(0x00C) /* 16 bits */
86/* Command Index: 0 -5 */
87/* Waits for response if set */
88#define MMC_BOOT_MCI_CMD_RESPONSE (1 << 6)
89/* Receives a 136-bit long response if set */
90#define MMC_BOOT_MCI_CMD_LONGRSP (1 << 7)
91/* If set, CPSM disables command timer and waits for interrupt */
92#define MMC_BOOT_MCI_CMD_INTERRUPT (1 << 8)
93/* If set waits for CmdPend before starting to send a command */
94#define MMC_BOOT_MCI_CMD_PENDING (1 << 9)
95/* CPSM is enabled if set */
Subbaraman Narayanamurthye9f077b2010-10-20 17:08:17 -070096#define MMC_BOOT_MCI_CMD_ENABLE (1 << 10)
Shashank Mittal52525ff2010-04-13 11:11:10 -070097/* If set PROG_DONE status bit asserted when busy is de-asserted */
98#define MMC_BOOT_MCI_CMD_PROG_ENA (1 << 11)
99/* To indicate that this is a Command with Data (for SDIO interrupts) */
100#define MMC_BOOT_MCI_CMD_DAT_CMD (1 << 12)
101/* Signals the next command to be an abort (stop) command. Always read 0 */
102#define MMC_BOOT_MCI_CMD_MCIABORT (1 << 13)
103/* Waits for Command Completion Signal if set */
104#define MMC_BOOT_MCI_CMD_CCS_ENABLE (1 << 14)
105/* If set sends CCS disable sequence */
106#define MMC_BOOT_MCI_CMD_CCS_DISABLE (1 << 15)
107
108#define MMC_BOOT_MCI_RESP_CMD MMC_BOOT_MCI_REG(0x010)
109
110#define MMC_BOOT_MCI_RESP_0 MMC_BOOT_MCI_REG(0x014)
111#define MMC_BOOT_MCI_RESP_1 MMC_BOOT_MCI_REG(0x018)
112#define MMC_BOOT_MCI_RESP_2 MMC_BOOT_MCI_REG(0x01C)
113#define MMC_BOOT_MCI_RESP_3 MMC_BOOT_MCI_REG(0x020)
114
115#define MMC_BOOT_MCI_DATA_TIMER MMC_BOOT_MCI_REG(0x024)
116#define MMC_BOOT_MCI_DATA_LENGTH MMC_BOOT_MCI_REG(0x028)
117#define MMC_BOOT_MCI_DATA_CTL MMC_BOOT_MCI_REG(0x02C) /* 16 bits */
118/* Data transfer enabled */
119#define MMC_BOOT_MCI_DATA_ENABLE (1 << 0)
120/* Data transfer direction - 0: controller to card 1:card to controller */
121#define MMC_BOOT_MCI_DATA_DIR (1 << 1)
122/* Data transfer mode - 0: block data transfer 1: stream data transfer */
123#define MMC_BOOT_MCI_DATA_MODE (1 << 2)
124/* Enable DM interface - 0: DM disabled 1: DM enabled */
125#define MMC_BOOT_MCI_DATA_DM_ENABLE (1 << 3)
126/* Data block length in bytes (1-4096) */
127#define MMC_BOOT_MCI_BLKSIZE_POS 4
128#define MMC_BOOT_MCI_DATA_COUNT MMC_BOOT_MCI_REG(0x030)
129#define MMC_BOOT_MCI_STATUS MMC_BOOT_MCI_REG(0x034)
130/* Command response received - CRC check failed */
131#define MMC_BOOT_MCI_STAT_CMD_CRC_FAIL (1 << 0)
132/* Data block sent/received - CRC check failed */
133#define MMC_BOOT_MCI_STAT_DATA_CRC_FAIL (1 << 1)
134/* Command resonse timeout */
135#define MMC_BOOT_MCI_STAT_CMD_TIMEOUT (1 << 2)
136/* Data timeout */
137#define MMC_BOOT_MCI_STAT_DATA_TIMEOUT (1 << 3)
138/* Transmit FIFO underrun error */
139#define MMC_BOOT_MCI_STAT_TX_UNDRUN (1 << 4)
140/* Receive FIFO overrun error */
141#define MMC_BOOT_MCI_STAT_RX_OVRRUN (1 << 5)
142/* Command response received - CRC check passed */
143#define MMC_BOOT_MCI_STAT_CMD_RESP_END (1 << 6)
144/* Command sent - no response required */
145#define MMC_BOOT_MCI_STAT_CMD_SENT (1 << 7)
146/* Data end - data counter zero */
147#define MMC_BOOT_MCI_STAT_DATA_END (1 << 8)
148/* Start bit not detected on all data signals in wide bus mode */
149#define MMC_BOOT_MCI_STAT_START_BIT_ERR (1 << 9)
150/* Data block sent/received - CRC check passed */
151#define MMC_BOOT_MCI_STAT_DATA_BLK_END (1 << 10)
152/* Command transfer in progress */
153#define MMC_BOOT_MCI_STAT_CMD_ACTIVE (1 << 11)
154/* Data transmit in progress */
155#define MMC_BOOT_MCI_STAT_TX_ACTIVE (1 << 12)
156/* Data receive in progress */
157#define MMC_BOOT_MCI_STAT_RX_ACTIVE (1 << 13)
158/* Transmit FIFO half full */
159#define MMC_BOOT_MCI_STAT_TX_FIFO_HFULL (1 << 14)
160/* Receive FIFO half full */
161#define MMC_BOOT_MCI_STAT_RX_FIFO_HFULL (1 << 15)
162/* Transmit FIFO full */
163#define MMC_BOOT_MCI_STAT_TX_FIFO_FULL (1 << 16)
164/* Receive FIFO full */
165#define MMC_BOOT_MCI_STAT_RX_FIFO_FULL (1 << 17)
166/* Transmit FIFO empty */
167#define MMC_BOOT_MCI_STAT_TX_FIFO_EMPTY (1 << 18)
168/* Receive FIFO empty */
169#define MMC_BOOT_MCI_STAT_RX_FIFO_EMPTY (1 << 19)
170/* Data available in transmit FIFO */
171#define MMC_BOOT_MCI_STAT_TX_DATA_AVLBL (1 << 20)
172/* Data available in receive FIFO */
173#define MMC_BOOT_MCI_STAT_RX_DATA_AVLBL (1 << 21)
174/* SDIO interrupt indicator for wake-up */
175#define MMC_BOOT_MCI_STAT_SDIO_INTR (1 << 22)
176/* Programming done */
177#define MMC_BOOT_MCI_STAT_PROG_DONE (1 << 23)
178/* CE-ATA command completion signal detected */
179#define MMC_BOOT_MCI_STAT_ATA_CMD_CMPL (1 << 24)
180/* SDIO interrupt indicator for normal operation */
181#define MMC_BOOT_MCI_STAT_SDIO_INTR_OP (1 << 25)
182/* Commpand completion signal timeout */
183#define MMC_BOOT_MCI_STAT_CCS_TIMEOUT (1 << 26)
184
185#define MMC_BOOT_MCI_STATIC_STATUS (MMC_BOOT_MCI_STAT_CMD_CRC_FAIL| \
186 MMC_BOOT_MCI_STAT_DATA_CRC_FAIL| \
187 MMC_BOOT_MCI_STAT_CMD_TIMEOUT| \
188 MMC_BOOT_MCI_STAT_DATA_TIMEOUT| \
189 MMC_BOOT_MCI_STAT_TX_UNDRUN| \
190 MMC_BOOT_MCI_STAT_RX_OVRRUN| \
191 MMC_BOOT_MCI_STAT_CMD_RESP_END| \
192 MMC_BOOT_MCI_STAT_CMD_SENT| \
193 MMC_BOOT_MCI_STAT_DATA_END| \
194 MMC_BOOT_MCI_STAT_START_BIT_ERR| \
195 MMC_BOOT_MCI_STAT_DATA_BLK_END| \
196 MMC_BOOT_MCI_SDIO_INTR_CLR| \
197 MMC_BOOT_MCI_STAT_PROG_DONE| \
198 MMC_BOOT_MCI_STAT_ATA_CMD_CMPL |\
199 MMC_BOOT_MCI_STAT_CCS_TIMEOUT)
200
201#define MMC_BOOT_MCI_CLEAR MMC_BOOT_MCI_REG(0x038)
202#define MMC_BOOT_MCI_CMD_CRC_FAIL_CLR (1 << 0)
203#define MMC_BOOT_MCI_DATA_CRC_FAIL_CLR (1 << 1)
204#define MMC_BOOT_MCI_CMD_TIMEOUT_CLR (1 << 2)
205#define MMC_BOOT_MCI_DATA_TIMEOUT_CLR (1 << 3)
206#define MMC_BOOT_MCI_TX_UNDERRUN_CLR (1 << 4)
207#define MMC_BOOT_MCI_RX_OVERRUN_CLR (1 << 5)
208#define MMC_BOOT_MCI_CMD_RESP_END_CLR (1 << 6)
209#define MMC_BOOT_MCI_CMD_SENT_CLR (1 << 7)
210#define MMC_BOOT_MCI_DATA_END_CLR (1 << 8)
211#define MMC_BOOT_MCI_START_BIT_ERR_CLR (1 << 9)
212#define MMC_BOOT_MCI_DATA_BLK_END_CLR (1 << 10)
213#define MMC_BOOT_MCI_SDIO_INTR_CLR (1 << 22)
214#define MMC_BOOT_MCI_PROG_DONE_CLR (1 << 23)
215#define MMC_BOOT_MCI_ATA_CMD_COMPLR_CLR (1 << 24)
216#define MMC_BOOT_MCI_CCS_TIMEOUT_CLR (1 << 25)
217
218#define MMC_BOOT_MCI_INT_MASK0 MMC_BOOT_MCI_REG(0x03C)
219#define MMC_BOOT_MCI_CMD_CRC_FAIL_MASK (1 << 0)
220#define MMC_BOOT_MCI_DATA_CRC_FAIL_MASK (1 << 1)
221#define MMC_BOOT_MCI_CMD_TIMEOUT_MASK (1 << 2)
222#define MMC_BOOT_MCI_DATA_TIMEOUT_MASK (1 << 3)
223#define MMC_BOOT_MCI_TX_OVERRUN_MASK (1 << 4)
224#define MMC_BOOT_MCI_RX_OVERRUN_MASK (1 << 5)
225#define MMC_BOOT_MCI_CMD_RESP_END_MASK (1 << 6)
226#define MMC_BOOT_MCI_CMD_SENT_MASK (1 << 7)
227#define MMC_BOOT_MCI_DATA_END_MASK (1 << 8)
228#define MMC_BOOT_MCI_START_BIT_ERR_MASK (1 << 9)
229#define MMC_BOOT_MCI_DATA_BLK_END_MASK (1 << 10)
230#define MMC_BOOT_MCI_CMD_ACTIVE_MASK (1 << 11)
231#define MMC_BOOT_MCI_TX_ACTIVE_MASK (1 << 12)
232#define MMC_BOOT_MCI_RX_ACTIVE_MASK (1 << 13)
233#define MMC_BOOT_MCI_TX_FIFO_HFULL_MASK (1 << 14)
234#define MMC_BOOT_MCI_RX_FIFO_HFULL_MASK (1 << 15)
235#define MMC_BOOT_MCI_TX_FIFO_FULL_MASK (1 << 16)
236#define MMC_BOOT_MCI_RX_FIFO_FULL_MASK (1 << 17)
237#define MMC_BOOT_MCI_TX_FIFO_EMPTY_MASK (1 << 18)
238#define MMC_BOOT_MCI_RX_FIFO_EMPTY_MASK (1 << 19)
239#define MMC_BOOT_MCI_TX_DATA_AVLBL_MASK (1 << 20)
240#define MMC_BOOT_MCI_RX_DATA_AVLBL_MASK (1 << 21)
241#define MMC_BOOT_MCI_SDIO_INT_MASK (1 << 22)
242#define MMC_BOOT_MCI_PROG_DONE_MASK (1 << 23)
243#define MMC_BOOT_MCI_ATA_CMD_COMPL_MASK (1 << 24)
244#define MMC_BOOT_MCI_SDIO_INT_OPER_MASK (1 << 25)
245#define MMC_BOOT_MCI_CCS_TIME_OUT_MASK (1 << 26)
246
247#define MMC_BOOT_MCI_INT_MASK1 MMC_BOOT_MCI_REG(0x040)
248
249#define MMC_BOOT_MCI_FIFO_COUNT MMC_BOOT_MCI_REG(0x044)
250
251#define MMC_BOOT_MCI_CCS_TIMER MMC_BOOT_MCI_REG(0x0058)
252
253#define MMC_BOOT_MCI_FIFO MMC_BOOT_MCI_REG(0x080)
254
Subbaraman Narayanamurthy1ea479e2010-10-08 14:54:16 -0700255/* Card status */
256#define MMC_BOOT_CARD_STATUS(x) ((x>>9) & 0x0F)
257#define MMC_BOOT_TRAN_STATE 4
Subbaraman Narayanamurthy7d347742010-10-29 21:24:08 -0700258#define MMC_BOOT_PROG_STATE 7
Subbaraman Narayanamurthy1ea479e2010-10-08 14:54:16 -0700259
Shashank Mittal52525ff2010-04-13 11:11:10 -0700260/* SD Memory Card bus commands */
261#define CMD0_GO_IDLE_STATE 0
262#define CMD1_SEND_OP_COND 1
263#define CMD2_ALL_SEND_CID 2
264#define CMD3_SEND_RELATIVE_ADDR 3
265#define CMD4_SET_DSR 4
266#define CMD6_SWITCH_FUNC 6
Subbaraman Narayanamurthy1ea479e2010-10-08 14:54:16 -0700267#define ACMD6_SET_BUS_WIDTH 6 /* SD card */
Shashank Mittal52525ff2010-04-13 11:11:10 -0700268#define CMD7_SELECT_DESELECT_CARD 7
269#define CMD8_SEND_EXT_CSD 8
Subbaraman Narayanamurthy1ea479e2010-10-08 14:54:16 -0700270#define CMD8_SEND_IF_COND 8 /* SD card */
Shashank Mittal52525ff2010-04-13 11:11:10 -0700271#define CMD9_SEND_CSD 9
272#define CMD10_SEND_CID 10
273#define CMD12_STOP_TRANSMISSION 12
274#define CMD13_SEND_STATUS 13
275#define CMD15_GO_INACTIVE_STATUS 15
276#define CMD16_SET_BLOCKLEN 16
277#define CMD17_READ_SINGLE_BLOCK 17
278#define CMD18_READ_MULTIPLE_BLOCK 18
Amol Jadi3672fef2011-01-24 09:43:50 -0800279#define CMD23_SET_BLOCK_COUNT 23
Shashank Mittal52525ff2010-04-13 11:11:10 -0700280#define CMD24_WRITE_SINGLE_BLOCK 24
281#define CMD25_WRITE_MULTIPLE_BLOCK 25
Subbaraman Narayanamurthye9f077b2010-10-20 17:08:17 -0700282#define CMD28_SET_WRITE_PROTECT 28
283#define CMD29_CLEAR_WRITE_PROTECT 29
284#define CMD31_SEND_WRITE_PROT_TYPE 31
Shashank Mittal52525ff2010-04-13 11:11:10 -0700285#define CMD32_ERASE_WR_BLK_START 32
286#define CMD33_ERASE_WR_BLK_END 33
287#define CMD38_ERASE 38
Subbaraman Narayanamurthy1ea479e2010-10-08 14:54:16 -0700288#define ACMD41_SEND_OP_COND 41 /* SD card */
289#define ACMD51_SEND_SCR 51 /* SD card */
290#define CMD55_APP_CMD 55 /* SD card */
Shashank Mittal52525ff2010-04-13 11:11:10 -0700291
292/* Switch Function Modes */
293#define MMC_BOOT_SWITCH_FUNC_CHECK 0
294#define MMC_BOOT_SWITCH_FUNC_SET 1
295
296/* OCR Register */
297#define MMC_BOOT_OCR_17_19 (1 << 7)
298#define MMC_BOOT_OCR_27_36 (0x1FF << 15)
299#define MMC_BOOT_OCR_SEC_MODE (2 << 29)
300#define MMC_BOOT_OCR_BUSY (1 << 31)
301
302/* Commands type */
303#define MMC_BOOT_CMD_BCAST (1 << 0)
304#define MMC_BOOT_CMD_BCAST_W_RESP (1 << 1)
305#define MMC_BOOT_CMD_ADDRESS (1 << 2)
306#define MMC_BOOT_CMD_ADDR_DATA_XFER (1 << 3)
307
308/* Response types */
309#define MMC_BOOT_RESP_NONE 0
310#define MMC_BOOT_RESP_R1 (1 << 0)
311#define MMC_BOOT_RESP_R1B (1 << 1)
312#define MMC_BOOT_RESP_R2 (1 << 2)
313#define MMC_BOOT_RESP_R3 (1 << 3)
314#define MMC_BOOT_RESP_R6 (1 << 6)
315#define MMC_BOOT_RESP_R7 (1 << 7)
316
317#define IS_RESP_136_BITS(x) (x & MMC_BOOT_RESP_R2)
318#define CHECK_FOR_BUSY_AT_RESP(x)
319
320/* Card Status bits (R1 register) */
321#define MMC_BOOT_R1_AKE_SEQ_ERROR (1 << 3)
322#define MMC_BOOT_R1_APP_CMD (1 << 5)
323#define MMC_BOOT_R1_RDY_FOR_DATA (1 << 6)
324#define MMC_BOOT_R1_CURR_STATE_IDLE (0 << 9)
325#define MMC_BOOT_R1_CURR_STATE_RDY (1 << 9)
326#define MMC_BOOT_R1_CURR_STATE_IDENT (2 << 9)
327#define MMC_BOOT_R1_CURR_STATE_STBY (3 << 9)
328#define MMC_BOOT_R1_CURR_STATE_TRAN (4 << 9)
329#define MMC_BOOT_R1_CURR_STATE_DATA (5 << 9)
330#define MMC_BOOT_R1_CURR_STATE_RCV (6 << 9)
331#define MMC_BOOT_R1_CURR_STATE_PRG (7 << 9)
332#define MMC_BOOT_R1_CURR_STATE_DIS (8 << 9)
333#define MMC_BOOT_R1_ERASE_RESET (1 << 13)
334#define MMC_BOOT_R1_CARD_ECC_DISABLED (1 << 14)
335#define MMC_BOOT_R1_WP_ERASE_SKIP (1 << 15)
336#define MMC_BOOT_R1_ERROR (1 << 19)
337#define MMC_BOOT_R1_CC_ERROR (1 << 20)
338#define MMC_BOOT_R1_CARD_ECC_FAILED (1 << 21)
339#define MMC_BOOT_R1_ILLEGAL_CMD (1 << 22)
340#define MMC_BOOT_R1_COM_CRC_ERR (1 << 23)
341#define MMC_BOOT_R1_LOCK_UNLOCK_FAIL (1 << 24)
342#define MMC_BOOT_R1_CARD_IS_LOCKED (1 << 25)
343#define MMC_BOOT_R1_WP_VIOLATION (1 << 26)
344#define MMC_BOOT_R1_ERASE_PARAM (1 << 27)
345#define MMC_BOOT_R1_ERASE_SEQ_ERR (1 << 28)
346#define MMC_BOOT_R1_BLOCK_LEN_ERR (1 << 29)
347#define MMC_BOOT_R1_ADDR_ERR (1 << 30)
348#define MMC_BOOT_R1_OUT_OF_RANGE (1 << 31)
349
350/* Macros for Common Errors */
351#define MMC_BOOT_E_SUCCESS 0
352#define MMC_BOOT_E_FAILURE 1
353#define MMC_BOOT_E_TIMEOUT 2
354#define MMC_BOOT_E_INVAL 3
355#define MMC_BOOT_E_CRC_FAIL 4
356#define MMC_BOOT_E_INIT_FAIL 5
357#define MMC_BOOT_E_CMD_INDX_MISMATCH 6
358#define MMC_BOOT_E_RESP_VERIFY_FAIL 7
359#define MMC_BOOT_E_NOT_SUPPORTED 8
360#define MMC_BOOT_E_CARD_BUSY 9
361#define MMC_BOOT_E_MEM_ALLOC_FAIL 10
362#define MMC_BOOT_E_CLK_ENABLE_FAIL 11
363#define MMC_BOOT_E_CMMC_DECODE_FAIL 12
364#define MMC_BOOT_E_CID_DECODE_FAIL 13
365#define MMC_BOOT_E_BLOCKLEN_ERR 14
366#define MMC_BOOT_E_ADDRESS_ERR 15
367#define MMC_BOOT_E_DATA_CRC_FAIL 16
368#define MMC_BOOT_E_DATA_TIMEOUT 17
369#define MMC_BOOT_E_RX_OVRRUN 18
370#define MMC_BOOT_E_VREG_SET_FAILED 19
371#define MMC_BOOT_E_GPIO_CFG_FAIL 20
Amol Jadi84a546a2011-03-02 12:09:11 -0800372#define MMC_BOOT_E_DATA_ADM_ERR 21
Shashank Mittal52525ff2010-04-13 11:11:10 -0700373
374/* EXT_CSD */
375#define MMC_BOOT_ACCESS_WRITE 0x3
376#define MMC_BOOT_EXT_CMMC_HS_TIMING 185
377#define MMC_BOOT_EXT_CMMC_BUS_WIDTH 183
378
Subbaraman Narayanamurthye9f077b2010-10-20 17:08:17 -0700379#define MMC_BOOT_EXT_USER_WP 171
380#define MMC_BOOT_EXT_ERASE_GROUP_DEF 175
381#define MMC_BOOT_EXT_HC_WP_GRP_SIZE 221
382#define MMC_BOOT_EXT_HC_ERASE_GRP_SIZE 224
383
384#define IS_BIT_SET_EXT_CSD(val, bit) ((ext_csd_buf[val]) & (1<<(bit)))
385#define IS_ADDR_OUT_OF_RANGE(resp) ((resp >> 31) & 0x01)
386
387#define MMC_BOOT_US_PERM_WP_EN 2
388#define MMC_BOOT_US_PWR_WP_DIS 3
389
390#define MMC_BOOT_US_PERM_WP_DIS (1<<4)
391#define MMC_BOOT_US_PWR_WP_EN 1
392
Subbaraman Narayanamurthy1ea479e2010-10-08 14:54:16 -0700393/* For SD */
394#define MMC_BOOT_SD_HC_VOLT_SUPPLIED 0x000001AA
395#define MMC_BOOT_SD_NEG_OCR 0x00FF8000
396#define MMC_BOOT_SD_HC_HCS 0x40000000
397#define MMC_BOOT_SD_DEV_READY 0x80000000
Subbaraman Narayanamurthy7c674102011-03-01 19:41:18 -0800398#define MMC_BOOT_SD_SWITCH_HS 0x80FFFFF1
Subbaraman Narayanamurthy1ea479e2010-10-08 14:54:16 -0700399
Shashank Mittal52525ff2010-04-13 11:11:10 -0700400/* Data structure definitions */
401struct mmc_boot_command
402{
403 unsigned int cmd_index;
404 unsigned int argument;
405 unsigned int cmd_type;
406
407 unsigned int resp[4];
408 unsigned int resp_type;
409 unsigned int prg_enabled;
410 unsigned int xfer_mode;
411};
412
413#define MMC_BOOT_XFER_MODE_BLOCK 0
414#define MMC_BOOT_XFER_MODE_STREAM 1
415
416/* CSD Register.
417 * Note: not all the fields have been defined here
418 */
419struct mmc_boot_csd
420{
421 unsigned int cmmc_structure;
Amol Jadi3672fef2011-01-24 09:43:50 -0800422 unsigned int spec_vers;
Shashank Mittal52525ff2010-04-13 11:11:10 -0700423 unsigned int card_cmd_class;
424 unsigned int write_blk_len;
425 unsigned int read_blk_len;
426 unsigned int r2w_factor;
427 unsigned int sector_size;
428 unsigned int c_size_mult;
429 unsigned int c_size;
430 unsigned int nsac_clk_cycle;
431 unsigned int taac_ns;
432 unsigned int tran_speed;
Subbaraman Narayanamurthye9f077b2010-10-20 17:08:17 -0700433 unsigned int erase_grp_size;
434 unsigned int erase_grp_mult;
435 unsigned int wp_grp_size;
436 unsigned int wp_grp_enable:1;
437 unsigned int perm_wp:1;
438 unsigned int temp_wp:1;
Shashank Mittal52525ff2010-04-13 11:11:10 -0700439 unsigned int erase_blk_len:1;
440 unsigned int read_blk_misalign:1;
441 unsigned int write_blk_misalign:1;
442 unsigned int read_blk_partial:1;
443 unsigned int write_blk_partial:1;
444};
445
446/* CID Register */
447struct mmc_boot_cid
448{
449 unsigned int mid; /* 8 bit manufacturer id*/
450 unsigned int oid; /* 16 bits 2 character ASCII - OEM ID*/
451 unsigned char pnm[7];/* 6 character ASCII - product name*/
452 unsigned int prv; /* 8 bits - product revision */
453 unsigned int psn; /* 32 bits - product serial number */
454 unsigned int month; /* 4 bits manufacturing month */
455 unsigned int year; /* 4 bits manufacturing year */
456};
457
458/* SCR Register */
459struct mmc_boot_scr
460{
461 unsigned int scr_structure;
462 unsigned int mmc_spec;
463#define MMC_BOOT_SCR_MMC_SPEC_V1_01 0
464#define MMC_BOOT_SCR_MMC_SPEC_V1_10 1
465#define MMC_BOOT_SCR_MMC_SPEC_V2_00 2
466 unsigned int data_stat_after_erase;
467 unsigned int mmc_security;
468#define MMC_BOOT_SCR_NO_SECURITY 0
469#define MMC_BOOT_SCR_SECURITY_UNUSED 1
470#define MMC_BOOT_SCR_SECURITY_V1_01 2
471#define MMC_BOOT_SCR_SECURITY_V2_00 3
472 unsigned int mmc_bus_width;
473#define MMC_BOOT_SCR_BUS_WIDTH_1_BIT (1<<0)
474#define MMC_BOOT_SCR_BUS_WIDTH_4_BIT (1<<2)
475};
476
477struct mmc_boot_card
478{
479 unsigned int rca;
480 unsigned int ocr;
Amol Jadi3672fef2011-01-24 09:43:50 -0800481 unsigned long long capacity;
Shashank Mittal52525ff2010-04-13 11:11:10 -0700482 unsigned int type;
483#define MMC_BOOT_TYPE_STD_SD 0
484#define MMC_BOOT_TYPE_SDHC 1
485#define MMC_BOOT_TYPE_SDIO 2
Subbaraman Narayanamurthy1ea479e2010-10-08 14:54:16 -0700486#define MMC_BOOT_TYPE_MMCHC 3
Shashank Mittal999d4ee2010-12-14 19:12:59 -0800487#define MMC_BOOT_TYPE_STD_MMC 4
Shashank Mittal52525ff2010-04-13 11:11:10 -0700488 unsigned int status;
489#define MMC_BOOT_STATUS_INACTIVE 0
490#define MMC_BOOT_STATUS_ACTIVE 1
491 unsigned int rd_timeout_ns;
492 unsigned int wr_timeout_ns;
493 unsigned int rd_block_len;
494 unsigned int wr_block_len;
495 //unsigned int data_xfer_len;
496 struct mmc_boot_cid cid;
497 struct mmc_boot_csd csd;
498 struct mmc_boot_scr scr;
499};
500
501#define MMC_BOOT_XFER_MULTI_BLOCK 0
502#define MMC_BOOT_XFER_SINGLE_BLOCK 1
503
504struct mmc_boot_host
505{
506 unsigned int mclk_rate;
Shashank Mittal52525ff2010-04-13 11:11:10 -0700507 unsigned int ocr;
508 unsigned int cmd_retry;
Shashank Mittal52525ff2010-04-13 11:11:10 -0700509};
510
511
512/* MACRO used to evoke regcomp */
513#define REGCOMP_CKRTN(regx, str, errhandle) \
514 do { \
515 if(regcomp(regx, str, REG_EXTENDED) != 0) { \
516 printf("Error building regex: %s\n", str); \
517 goto errhandle; \
518 } \
519 } while(0);
520
521
522#define GET_LWORD_FROM_BYTE(x) ((unsigned)*(x) | \
523 ((unsigned)*(x+1) << 8) | \
524 ((unsigned)*(x+2) << 16) | \
525 ((unsigned)*(x+3) << 24))
526
527#define PUT_LWORD_TO_BYTE(x, y) do{*(x) = y & 0xff; \
528 *(x+1) = (y >> 8) & 0xff; \
529 *(x+2) = (y >> 16) & 0xff; \
530 *(x+3) = (y >> 24) & 0xff; }while(0)
531
532#define GET_PAR_NUM_FROM_POS(x) (((x & 0x0000FF00) >> 8) + (x & 0x000000FF))
533
534/* Some useful define used to access the MBR/EBR table */
535#define BLOCK_SIZE 0x200
536#define TABLE_ENTRY_0 0x1BE
537#define TABLE_ENTRY_1 0x1CE
538#define TABLE_ENTRY_2 0x1DE
539#define TABLE_ENTRY_3 0x1EE
540#define TABLE_SIGNATURE 0x1FE
541#define TABLE_ENTRY_SIZE 0x010
542
543#define OFFSET_STATUS 0x00
544#define OFFSET_TYPE 0x04
545#define OFFSET_FIRST_SEC 0x08
546#define OFFSET_SIZE 0x0C
547#define COPYBUFF_SIZE (1024 * 16)
548#define BINARY_IN_TABLE_SIZE (16 * 512)
549#define MAX_FILE_ENTRIES 20
550
Ajay Dudani02704632010-08-30 14:40:07 -0700551#define MMC_MODEM_TYPE 0x06
552#define MMC_MODEM_TYPE2 0x0C
553#define MMC_SBL1_TYPE 0x4D
554#define MMC_SBL2_TYPE 0x51
555#define MMC_SBL3_TYPE 0x45
556#define MMC_RPM_TYPE 0x47
557#define MMC_TZ_TYPE 0x46
Subbaraman Narayanamurthy4dfe44a2010-10-19 15:34:41 -0700558#define MMC_MODEM_ST1_TYPE 0x4A
559#define MMC_MODEM_ST2_TYPE 0x4B
560#define MMC_EFS2_TYPE 0x4E
Ajay Dudani02704632010-08-30 14:40:07 -0700561
562#define MMC_ABOOT_TYPE 0x4C
563#define MMC_BOOT_TYPE 0x48
564#define MMC_SYSTEM_TYPE 0x82
565#define MMC_USERDATA_TYPE 0x83
Shashank Mittal85b91f62010-10-30 10:12:38 -0700566#define MMC_RECOVERY_TYPE 0x60
Subbaraman Narayanamurthy0e445b02011-06-19 21:34:46 -0700567#define MMC_MISC_TYPE 0x63
Shashank Mittal52525ff2010-04-13 11:11:10 -0700568
569#define MMC_RCA 2
570
571struct mbr_entry
572{
573 unsigned dstatus;
574 unsigned dtype ;
575 unsigned dfirstsec;
576 unsigned dsize;
577 unsigned char name[64];
578};
579
580/* Can be used to unpack array of upto 32 bits data */
581#define UNPACK_BITS(array, start, len, size_of) \
582 ({ \
583 unsigned int indx = (start) / (size_of); \
584 unsigned int offset = (start) % (size_of); \
585 unsigned int mask = (((len)<(size_of))? 1<<(len):0) - 1; \
586 unsigned int unpck = array[indx] >> offset; \
587 unsigned int indx2 = ((start) + (len) - 1) / (size_of); \
588 if(indx2 > indx) \
589 unpck |= array[indx2] << ((size_of) - offset); \
590 unpck & mask; \
591 })
592
Amol Jadi58373d42011-05-23 14:21:59 -0700593#define MMC_BOOT_MAX_COMMAND_RETRY 1000
Shashank Mittal52525ff2010-04-13 11:11:10 -0700594#define MMC_BOOT_RD_BLOCK_LEN 512
595#define MMC_BOOT_WR_BLOCK_LEN 512
596
Shashank Mittal7afbf282010-06-02 19:48:31 -0700597/* We have 16 32-bits FIFO registers */
Amol Jadi84a546a2011-03-02 12:09:11 -0800598#define MMC_BOOT_MCI_FIFO_DEPTH 16
599#define MMC_BOOT_MCI_HFIFO_COUNT ( MMC_BOOT_MCI_FIFO_DEPTH / 2 )
600#define MMC_BOOT_MCI_FIFO_SIZE ( MMC_BOOT_MCI_FIFO_DEPTH * 4 )
Shashank Mittal52525ff2010-04-13 11:11:10 -0700601
Shashank Mittal52525ff2010-04-13 11:11:10 -0700602#define MAX_PARTITIONS 64
603
604#define MMC_BOOT_CHECK_PATTERN 0xAA /* 10101010b */
605
606#define MMC_CLK_400KHZ 400000
607#define MMC_CLK_144KHZ 144000
608#define MMC_CLK_20MHZ 20000000
609#define MMC_CLK_25MHZ 25000000
Shashank Mittal7afbf282010-06-02 19:48:31 -0700610#define MMC_CLK_48MHZ 48000000
Shashank Mittal52525ff2010-04-13 11:11:10 -0700611#define MMC_CLK_50MHZ 49152000
612
613#define MMC_CLK_ENABLE 1
614#define MMC_CLK_DISABLE 0
615
Greg Griscod6250552011-06-29 14:40:23 -0700616
617unsigned int mmc_boot_main(unsigned char slot, unsigned int base);
Kinson Chik66552a82011-03-29 15:59:06 -0700618unsigned int mmc_boot_read_from_card( struct mmc_boot_host* host,
619 struct mmc_boot_card* card,
620 unsigned long long data_addr,
621 unsigned int data_len,
622 unsigned int* out );
Greg Griscod6250552011-06-29 14:40:23 -0700623unsigned int mmc_write (unsigned long long data_addr,
624 unsigned int data_len, unsigned int* in);
625unsigned long long mmc_ptn_offset (unsigned char * name);
626unsigned long long mmc_ptn_size (unsigned char * name);
627
628unsigned int mmc_read (unsigned long long data_addr, unsigned int* out,
629 unsigned int data_len);
630
Shashank Mittal52525ff2010-04-13 11:11:10 -0700631#endif
632