blob: 222c01b43174978d62f1c1289212b3ce74f32e52 [file] [log] [blame]
Channagoud Kadabie6f59dc2014-01-06 17:31:39 -08001/* Copyright (c) 2010-2014, The Linux Foundation. All rights reserved.
Channagoud Kadabi672c4c42012-12-20 17:51:45 -08002 *
Ajay Dudanib01e5062011-12-03 23:23:42 -08003 * Redistribution and use in source and binary forms, with or without
4 * modification, are permitted provided that the following conditions are
5 * met:
Channagoud Kadabi672c4c42012-12-20 17:51:45 -08006 * * 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 The Linux Foundation 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.
Ajay Dudanib01e5062011-12-03 23:23:42 -080015 *
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
Channagoud Kadabi46608192013-05-02 10:22:32 -070032#if MMC_SDHCI_SUPPORT
33#include "mmc_sdhci.h"
34#include "mmc_wrapper.h"
35#else
Ajay Dudanib01e5062011-12-03 23:23:42 -080036#ifndef MMC_SLOT
37#define MMC_SLOT 0
38#endif
39
Sundarajan Srinivasand16443b2013-10-02 00:16:06 -070040#define BOARD_KERNEL_PAGESIZE 2048
41
Ajay Dudanib01e5062011-12-03 23:23:42 -080042extern unsigned int mmc_boot_mci_base;
43
44#define MMC_BOOT_MCI_REG(offset) ((mmc_boot_mci_base) + offset)
45
46/*
47 * Define Macros for SDCC Registers
48 */
49#define MMC_BOOT_MCI_POWER MMC_BOOT_MCI_REG(0x000) /* 8 bit */
50
51/* MCICMD output control - 6th bit */
52#ifdef PLATFORM_MSM7X30
53#define MMC_BOOT_MCI_OPEN_DRAIN (1 << 6)
54#define MMC_BOOT_MCI_PWR_OFF 0x00
55#define MMC_BOOT_MCI_PWR_UP 0x01
56#define MMC_BOOT_MCI_PWR_ON 0x01
57#else
58#define MMC_BOOT_MCI_OPEN_DRAIN (1 << 6)
59#define MMC_BOOT_MCI_PWR_OFF 0x00
60#define MMC_BOOT_MCI_PWR_UP 0x02
61#define MMC_BOOT_MCI_PWR_ON 0x03
62#endif
63
64#define MMC_BOOT_MCI_CLK MMC_BOOT_MCI_REG(0x004) /* 16 bits */
65/* Enable MCI bus clock - 0: clock disabled 1: enabled */
66#define MMC_BOOT_MCI_CLK_ENABLE (1 << 8)
Channagoud Kadabie2ec5a42013-03-14 16:30:42 -070067#define MMC_BOOT_MCI_CLK_DISABLE (0 << 8)
Ajay Dudanib01e5062011-12-03 23:23:42 -080068/* Disable clk o/p when bus idle- 0:always enabled 1:enabled when bus active */
69#define MMC_BOOT_MCI_CLK_PWRSAVE (1 << 9)
70/* Enable Widebus mode - 00: 1 bit mode 10:4 bit mode 01/11: 8 bit mode */
71#define MMC_BOOT_MCI_CLK_WIDEBUS_MODE (3 << 10)
72#define MMC_BOOT_MCI_CLK_WIDEBUS_1_BIT 0
73#define MMC_BOOT_MCI_CLK_WIDEBUS_4_BIT (2 << 10)
74#define MMC_BOOT_MCI_CLK_WIDEBUS_8_BIT (1 << 10)
75/* Enable flow control- 0: disable 1: enable */
76#define MMC_BOOT_MCI_CLK_ENA_FLOW (1 << 12)
77/* Set/clear to select rising/falling edge for data/cmd output */
78#define MMC_BOOT_MCI_CLK_INVERT_OUT (1 << 13)
79/* Select to lach data/cmd coming in falling/rising/feedbk/loopbk of MCIclk */
80#define MMC_BOOT_MCI_CLK_IN_FALLING 0x0
81#define MMC_BOOT_MCI_CLK_IN_RISING (1 << 14)
82#define MMC_BOOT_MCI_CLK_IN_FEEDBACK (2 << 14)
83#define MMC_BOOT_MCI_CLK_IN_LOOPBACK (3 << 14)
84
85/* Bus Width */
86#define MMC_BOOT_BUS_WIDTH_1_BIT 0
87#define MMC_BOOT_BUS_WIDTH_4_BIT 2
88#define MMC_BOOT_BUS_WIDTH_8_BIT 3
89
Channagoud Kadabi676c2e32013-04-02 11:39:01 -070090/* Bus width support for DDR mode */
91#define MMC_DDR_BUS_WIDTH_4_BIT 6
92#define MMC_DDR_BUS_WIDTH_8_BIT 7
93
94/* DDR mode select */
95#define MMC_MCI_MODE_SELECT 14
96#define MMC_MCI_DDR_MODE_EN 0x3
97
98#define MMC_DEVICE_TYPE 196
99
Ajay Dudanib01e5062011-12-03 23:23:42 -0800100#define MMC_BOOT_MCI_ARGUMENT MMC_BOOT_MCI_REG(0x008) /* 32 bits */
101
102#define MMC_BOOT_MCI_CMD MMC_BOOT_MCI_REG(0x00C) /* 16 bits */
103/* Command Index: 0 -5 */
104/* Waits for response if set */
105#define MMC_BOOT_MCI_CMD_RESPONSE (1 << 6)
106/* Receives a 136-bit long response if set */
107#define MMC_BOOT_MCI_CMD_LONGRSP (1 << 7)
108/* If set, CPSM disables command timer and waits for interrupt */
109#define MMC_BOOT_MCI_CMD_INTERRUPT (1 << 8)
110/* If set waits for CmdPend before starting to send a command */
111#define MMC_BOOT_MCI_CMD_PENDING (1 << 9)
112/* CPSM is enabled if set */
113#define MMC_BOOT_MCI_CMD_ENABLE (1 << 10)
114/* If set PROG_DONE status bit asserted when busy is de-asserted */
115#define MMC_BOOT_MCI_CMD_PROG_ENA (1 << 11)
116/* To indicate that this is a Command with Data (for SDIO interrupts) */
117#define MMC_BOOT_MCI_CMD_DAT_CMD (1 << 12)
118/* Signals the next command to be an abort (stop) command. Always read 0 */
119#define MMC_BOOT_MCI_CMD_MCIABORT (1 << 13)
120/* Waits for Command Completion Signal if set */
121#define MMC_BOOT_MCI_CMD_CCS_ENABLE (1 << 14)
122/* If set sends CCS disable sequence */
123#define MMC_BOOT_MCI_CMD_CCS_DISABLE (1 << 15)
124
125#define MMC_BOOT_MCI_RESP_CMD MMC_BOOT_MCI_REG(0x010)
126
127#define MMC_BOOT_MCI_RESP_0 MMC_BOOT_MCI_REG(0x014)
128#define MMC_BOOT_MCI_RESP_1 MMC_BOOT_MCI_REG(0x018)
129#define MMC_BOOT_MCI_RESP_2 MMC_BOOT_MCI_REG(0x01C)
130#define MMC_BOOT_MCI_RESP_3 MMC_BOOT_MCI_REG(0x020)
131
132#define MMC_BOOT_MCI_DATA_TIMER MMC_BOOT_MCI_REG(0x024)
133#define MMC_BOOT_MCI_DATA_LENGTH MMC_BOOT_MCI_REG(0x028)
134#define MMC_BOOT_MCI_DATA_CTL MMC_BOOT_MCI_REG(0x02C) /* 16 bits */
135/* Data transfer enabled */
136#define MMC_BOOT_MCI_DATA_ENABLE (1 << 0)
137/* Data transfer direction - 0: controller to card 1:card to controller */
138#define MMC_BOOT_MCI_DATA_DIR (1 << 1)
139/* Data transfer mode - 0: block data transfer 1: stream data transfer */
140#define MMC_BOOT_MCI_DATA_MODE (1 << 2)
141/* Enable DM interface - 0: DM disabled 1: DM enabled */
142#define MMC_BOOT_MCI_DATA_DM_ENABLE (1 << 3)
143/* Data block length in bytes (1-4096) */
144#define MMC_BOOT_MCI_BLKSIZE_POS 4
145#define MMC_BOOT_MCI_DATA_COUNT MMC_BOOT_MCI_REG(0x030)
146#define MMC_BOOT_MCI_STATUS MMC_BOOT_MCI_REG(0x034)
147/* Command response received - CRC check failed */
148#define MMC_BOOT_MCI_STAT_CMD_CRC_FAIL (1 << 0)
149/* Data block sent/received - CRC check failed */
150#define MMC_BOOT_MCI_STAT_DATA_CRC_FAIL (1 << 1)
151/* Command resonse timeout */
152#define MMC_BOOT_MCI_STAT_CMD_TIMEOUT (1 << 2)
153/* Data timeout */
154#define MMC_BOOT_MCI_STAT_DATA_TIMEOUT (1 << 3)
155/* Transmit FIFO underrun error */
156#define MMC_BOOT_MCI_STAT_TX_UNDRUN (1 << 4)
157/* Receive FIFO overrun error */
158#define MMC_BOOT_MCI_STAT_RX_OVRRUN (1 << 5)
159/* Command response received - CRC check passed */
160#define MMC_BOOT_MCI_STAT_CMD_RESP_END (1 << 6)
161/* Command sent - no response required */
162#define MMC_BOOT_MCI_STAT_CMD_SENT (1 << 7)
163/* Data end - data counter zero */
164#define MMC_BOOT_MCI_STAT_DATA_END (1 << 8)
165/* Start bit not detected on all data signals in wide bus mode */
166#define MMC_BOOT_MCI_STAT_START_BIT_ERR (1 << 9)
167/* Data block sent/received - CRC check passed */
168#define MMC_BOOT_MCI_STAT_DATA_BLK_END (1 << 10)
169/* Command transfer in progress */
170#define MMC_BOOT_MCI_STAT_CMD_ACTIVE (1 << 11)
171/* Data transmit in progress */
172#define MMC_BOOT_MCI_STAT_TX_ACTIVE (1 << 12)
173/* Data receive in progress */
174#define MMC_BOOT_MCI_STAT_RX_ACTIVE (1 << 13)
175/* Transmit FIFO half full */
176#define MMC_BOOT_MCI_STAT_TX_FIFO_HFULL (1 << 14)
177/* Receive FIFO half full */
178#define MMC_BOOT_MCI_STAT_RX_FIFO_HFULL (1 << 15)
179/* Transmit FIFO full */
180#define MMC_BOOT_MCI_STAT_TX_FIFO_FULL (1 << 16)
181/* Receive FIFO full */
182#define MMC_BOOT_MCI_STAT_RX_FIFO_FULL (1 << 17)
183/* Transmit FIFO empty */
184#define MMC_BOOT_MCI_STAT_TX_FIFO_EMPTY (1 << 18)
185/* Receive FIFO empty */
186#define MMC_BOOT_MCI_STAT_RX_FIFO_EMPTY (1 << 19)
187/* Data available in transmit FIFO */
188#define MMC_BOOT_MCI_STAT_TX_DATA_AVLBL (1 << 20)
189/* Data available in receive FIFO */
190#define MMC_BOOT_MCI_STAT_RX_DATA_AVLBL (1 << 21)
191/* SDIO interrupt indicator for wake-up */
192#define MMC_BOOT_MCI_STAT_SDIO_INTR (1 << 22)
193/* Programming done */
194#define MMC_BOOT_MCI_STAT_PROG_DONE (1 << 23)
195/* CE-ATA command completion signal detected */
196#define MMC_BOOT_MCI_STAT_ATA_CMD_CMPL (1 << 24)
197/* SDIO interrupt indicator for normal operation */
198#define MMC_BOOT_MCI_STAT_SDIO_INTR_OP (1 << 25)
199/* Commpand completion signal timeout */
200#define MMC_BOOT_MCI_STAT_CCS_TIMEOUT (1 << 26)
201
202#define MMC_BOOT_MCI_STATIC_STATUS (MMC_BOOT_MCI_STAT_CMD_CRC_FAIL| \
203 MMC_BOOT_MCI_STAT_DATA_CRC_FAIL| \
204 MMC_BOOT_MCI_STAT_CMD_TIMEOUT| \
205 MMC_BOOT_MCI_STAT_DATA_TIMEOUT| \
206 MMC_BOOT_MCI_STAT_TX_UNDRUN| \
207 MMC_BOOT_MCI_STAT_RX_OVRRUN| \
208 MMC_BOOT_MCI_STAT_CMD_RESP_END| \
209 MMC_BOOT_MCI_STAT_CMD_SENT| \
210 MMC_BOOT_MCI_STAT_DATA_END| \
211 MMC_BOOT_MCI_STAT_START_BIT_ERR| \
212 MMC_BOOT_MCI_STAT_DATA_BLK_END| \
213 MMC_BOOT_MCI_SDIO_INTR_CLR| \
214 MMC_BOOT_MCI_STAT_PROG_DONE| \
215 MMC_BOOT_MCI_STAT_ATA_CMD_CMPL |\
216 MMC_BOOT_MCI_STAT_CCS_TIMEOUT)
217
218#define MMC_BOOT_MCI_CLEAR MMC_BOOT_MCI_REG(0x038)
219#define MMC_BOOT_MCI_CMD_CRC_FAIL_CLR (1 << 0)
220#define MMC_BOOT_MCI_DATA_CRC_FAIL_CLR (1 << 1)
221#define MMC_BOOT_MCI_CMD_TIMEOUT_CLR (1 << 2)
222#define MMC_BOOT_MCI_DATA_TIMEOUT_CLR (1 << 3)
223#define MMC_BOOT_MCI_TX_UNDERRUN_CLR (1 << 4)
224#define MMC_BOOT_MCI_RX_OVERRUN_CLR (1 << 5)
225#define MMC_BOOT_MCI_CMD_RESP_END_CLR (1 << 6)
226#define MMC_BOOT_MCI_CMD_SENT_CLR (1 << 7)
227#define MMC_BOOT_MCI_DATA_END_CLR (1 << 8)
228#define MMC_BOOT_MCI_START_BIT_ERR_CLR (1 << 9)
229#define MMC_BOOT_MCI_DATA_BLK_END_CLR (1 << 10)
230#define MMC_BOOT_MCI_SDIO_INTR_CLR (1 << 22)
231#define MMC_BOOT_MCI_PROG_DONE_CLR (1 << 23)
232#define MMC_BOOT_MCI_ATA_CMD_COMPLR_CLR (1 << 24)
233#define MMC_BOOT_MCI_CCS_TIMEOUT_CLR (1 << 25)
234
235#define MMC_BOOT_MCI_INT_MASK0 MMC_BOOT_MCI_REG(0x03C)
236#define MMC_BOOT_MCI_CMD_CRC_FAIL_MASK (1 << 0)
237#define MMC_BOOT_MCI_DATA_CRC_FAIL_MASK (1 << 1)
238#define MMC_BOOT_MCI_CMD_TIMEOUT_MASK (1 << 2)
239#define MMC_BOOT_MCI_DATA_TIMEOUT_MASK (1 << 3)
240#define MMC_BOOT_MCI_TX_OVERRUN_MASK (1 << 4)
241#define MMC_BOOT_MCI_RX_OVERRUN_MASK (1 << 5)
242#define MMC_BOOT_MCI_CMD_RESP_END_MASK (1 << 6)
243#define MMC_BOOT_MCI_CMD_SENT_MASK (1 << 7)
244#define MMC_BOOT_MCI_DATA_END_MASK (1 << 8)
245#define MMC_BOOT_MCI_START_BIT_ERR_MASK (1 << 9)
246#define MMC_BOOT_MCI_DATA_BLK_END_MASK (1 << 10)
247#define MMC_BOOT_MCI_CMD_ACTIVE_MASK (1 << 11)
248#define MMC_BOOT_MCI_TX_ACTIVE_MASK (1 << 12)
249#define MMC_BOOT_MCI_RX_ACTIVE_MASK (1 << 13)
250#define MMC_BOOT_MCI_TX_FIFO_HFULL_MASK (1 << 14)
251#define MMC_BOOT_MCI_RX_FIFO_HFULL_MASK (1 << 15)
252#define MMC_BOOT_MCI_TX_FIFO_FULL_MASK (1 << 16)
253#define MMC_BOOT_MCI_RX_FIFO_FULL_MASK (1 << 17)
254#define MMC_BOOT_MCI_TX_FIFO_EMPTY_MASK (1 << 18)
255#define MMC_BOOT_MCI_RX_FIFO_EMPTY_MASK (1 << 19)
256#define MMC_BOOT_MCI_TX_DATA_AVLBL_MASK (1 << 20)
257#define MMC_BOOT_MCI_RX_DATA_AVLBL_MASK (1 << 21)
258#define MMC_BOOT_MCI_SDIO_INT_MASK (1 << 22)
259#define MMC_BOOT_MCI_PROG_DONE_MASK (1 << 23)
260#define MMC_BOOT_MCI_ATA_CMD_COMPL_MASK (1 << 24)
261#define MMC_BOOT_MCI_SDIO_INT_OPER_MASK (1 << 25)
262#define MMC_BOOT_MCI_CCS_TIME_OUT_MASK (1 << 26)
263
264#define MMC_BOOT_MCI_INT_MASK1 MMC_BOOT_MCI_REG(0x040)
265
266#define MMC_BOOT_MCI_FIFO_COUNT MMC_BOOT_MCI_REG(0x044)
267
Channagoud Kadabi672c4c42012-12-20 17:51:45 -0800268#define MMC_BOOT_MCI_VERSION MMC_BOOT_MCI_REG(0x050)
269
Ajay Dudanib01e5062011-12-03 23:23:42 -0800270#define MMC_BOOT_MCI_CCS_TIMER MMC_BOOT_MCI_REG(0x0058)
271
Channagoud Kadabi672c4c42012-12-20 17:51:45 -0800272#define MMC_BOOT_MCI_STATUS2 MMC_BOOT_MCI_REG(0x06C)
273#define MMC_BOOT_MCI_MCLK_REG_WR_ACTIVE (1 << 0)
274
Ajay Dudanib01e5062011-12-03 23:23:42 -0800275#define MMC_BOOT_MCI_FIFO MMC_BOOT_MCI_REG(0x080)
276
277/* Card status */
278#define MMC_BOOT_CARD_STATUS(x) ((x>>9) & 0x0F)
279#define MMC_BOOT_TRAN_STATE 4
280#define MMC_BOOT_PROG_STATE 7
Channagoud Kadabi672c4c42012-12-20 17:51:45 -0800281#define MMC_BOOT_SWITCH_FUNC_ERR_FLAG (1 << 7)
Ajay Dudanib01e5062011-12-03 23:23:42 -0800282
283/* SD Memory Card bus commands */
284#define CMD0_GO_IDLE_STATE 0
285#define CMD1_SEND_OP_COND 1
286#define CMD2_ALL_SEND_CID 2
287#define CMD3_SEND_RELATIVE_ADDR 3
288#define CMD4_SET_DSR 4
Channagoud Kadabi54dd5312013-06-18 18:31:44 -0700289#define CMD5_SLEEP_AWAKE 5
Ajay Dudanib01e5062011-12-03 23:23:42 -0800290#define CMD6_SWITCH_FUNC 6
291#define ACMD6_SET_BUS_WIDTH 6 /* SD card */
292#define CMD7_SELECT_DESELECT_CARD 7
293#define CMD8_SEND_EXT_CSD 8
294#define CMD8_SEND_IF_COND 8 /* SD card */
295#define CMD9_SEND_CSD 9
296#define CMD10_SEND_CID 10
297#define CMD12_STOP_TRANSMISSION 12
298#define CMD13_SEND_STATUS 13
299#define CMD15_GO_INACTIVE_STATUS 15
300#define CMD16_SET_BLOCKLEN 16
301#define CMD17_READ_SINGLE_BLOCK 17
302#define CMD18_READ_MULTIPLE_BLOCK 18
303#define CMD23_SET_BLOCK_COUNT 23
304#define CMD24_WRITE_SINGLE_BLOCK 24
305#define CMD25_WRITE_MULTIPLE_BLOCK 25
306#define CMD28_SET_WRITE_PROTECT 28
307#define CMD29_CLEAR_WRITE_PROTECT 29
308#define CMD31_SEND_WRITE_PROT_TYPE 31
309#define CMD32_ERASE_WR_BLK_START 32
310#define CMD33_ERASE_WR_BLK_END 33
311#define CMD35_ERASE_GROUP_START 35
312#define CMD36_ERASE_GROUP_END 36
313#define CMD38_ERASE 38
314#define ACMD41_SEND_OP_COND 41 /* SD card */
315#define ACMD51_SEND_SCR 51 /* SD card */
316#define CMD55_APP_CMD 55 /* SD card */
317
318/* Switch Function Modes */
319#define MMC_BOOT_SWITCH_FUNC_CHECK 0
320#define MMC_BOOT_SWITCH_FUNC_SET 1
321
322/* OCR Register */
323#define MMC_BOOT_OCR_17_19 (1 << 7)
324#define MMC_BOOT_OCR_27_36 (0x1FF << 15)
325#define MMC_BOOT_OCR_SEC_MODE (2 << 29)
326#define MMC_BOOT_OCR_BUSY (1 << 31)
327
328/* Commands type */
329#define MMC_BOOT_CMD_BCAST (1 << 0)
330#define MMC_BOOT_CMD_BCAST_W_RESP (1 << 1)
331#define MMC_BOOT_CMD_ADDRESS (1 << 2)
332#define MMC_BOOT_CMD_ADDR_DATA_XFER (1 << 3)
333
334/* Response types */
335#define MMC_BOOT_RESP_NONE 0
336#define MMC_BOOT_RESP_R1 (1 << 0)
337#define MMC_BOOT_RESP_R1B (1 << 1)
338#define MMC_BOOT_RESP_R2 (1 << 2)
339#define MMC_BOOT_RESP_R3 (1 << 3)
340#define MMC_BOOT_RESP_R6 (1 << 6)
341#define MMC_BOOT_RESP_R7 (1 << 7)
342
343#define IS_RESP_136_BITS(x) (x & MMC_BOOT_RESP_R2)
344#define CHECK_FOR_BUSY_AT_RESP(x)
345
346/* Card Status bits (R1 register) */
347#define MMC_BOOT_R1_AKE_SEQ_ERROR (1 << 3)
348#define MMC_BOOT_R1_APP_CMD (1 << 5)
349#define MMC_BOOT_R1_RDY_FOR_DATA (1 << 6)
350#define MMC_BOOT_R1_CURR_STATE_IDLE (0 << 9)
351#define MMC_BOOT_R1_CURR_STATE_RDY (1 << 9)
352#define MMC_BOOT_R1_CURR_STATE_IDENT (2 << 9)
353#define MMC_BOOT_R1_CURR_STATE_STBY (3 << 9)
354#define MMC_BOOT_R1_CURR_STATE_TRAN (4 << 9)
355#define MMC_BOOT_R1_CURR_STATE_DATA (5 << 9)
356#define MMC_BOOT_R1_CURR_STATE_RCV (6 << 9)
357#define MMC_BOOT_R1_CURR_STATE_PRG (7 << 9)
358#define MMC_BOOT_R1_CURR_STATE_DIS (8 << 9)
359#define MMC_BOOT_R1_ERASE_RESET (1 << 13)
360#define MMC_BOOT_R1_CARD_ECC_DISABLED (1 << 14)
361#define MMC_BOOT_R1_WP_ERASE_SKIP (1 << 15)
362#define MMC_BOOT_R1_ERROR (1 << 19)
363#define MMC_BOOT_R1_CC_ERROR (1 << 20)
364#define MMC_BOOT_R1_CARD_ECC_FAILED (1 << 21)
365#define MMC_BOOT_R1_ILLEGAL_CMD (1 << 22)
366#define MMC_BOOT_R1_COM_CRC_ERR (1 << 23)
367#define MMC_BOOT_R1_LOCK_UNLOCK_FAIL (1 << 24)
368#define MMC_BOOT_R1_CARD_IS_LOCKED (1 << 25)
369#define MMC_BOOT_R1_WP_VIOLATION (1 << 26)
370#define MMC_BOOT_R1_ERASE_PARAM (1 << 27)
371#define MMC_BOOT_R1_ERASE_SEQ_ERR (1 << 28)
372#define MMC_BOOT_R1_BLOCK_LEN_ERR (1 << 29)
373#define MMC_BOOT_R1_ADDR_ERR (1 << 30)
374#define MMC_BOOT_R1_OUT_OF_RANGE (1 << 31)
375
376/* Macros for Common Errors */
377#define MMC_BOOT_E_SUCCESS 0
378#define MMC_BOOT_E_FAILURE 1
379#define MMC_BOOT_E_TIMEOUT 2
380#define MMC_BOOT_E_INVAL 3
381#define MMC_BOOT_E_CRC_FAIL 4
382#define MMC_BOOT_E_INIT_FAIL 5
383#define MMC_BOOT_E_CMD_INDX_MISMATCH 6
384#define MMC_BOOT_E_RESP_VERIFY_FAIL 7
385#define MMC_BOOT_E_NOT_SUPPORTED 8
386#define MMC_BOOT_E_CARD_BUSY 9
387#define MMC_BOOT_E_MEM_ALLOC_FAIL 10
388#define MMC_BOOT_E_CLK_ENABLE_FAIL 11
389#define MMC_BOOT_E_CMMC_DECODE_FAIL 12
390#define MMC_BOOT_E_CID_DECODE_FAIL 13
391#define MMC_BOOT_E_BLOCKLEN_ERR 14
392#define MMC_BOOT_E_ADDRESS_ERR 15
393#define MMC_BOOT_E_DATA_CRC_FAIL 16
394#define MMC_BOOT_E_DATA_TIMEOUT 17
395#define MMC_BOOT_E_RX_OVRRUN 18
396#define MMC_BOOT_E_VREG_SET_FAILED 19
397#define MMC_BOOT_E_GPIO_CFG_FAIL 20
398#define MMC_BOOT_E_DATA_ADM_ERR 21
399
400/* EXT_CSD */
401#define MMC_BOOT_ACCESS_WRITE 0x3
Channagoud Kadabi0dcccec2013-11-22 14:57:56 -0800402#define MMC_BOOT_SET_BIT 0x1
Ajay Dudanib01e5062011-12-03 23:23:42 -0800403
404#define MMC_BOOT_EXT_USER_WP 171
405#define MMC_BOOT_EXT_ERASE_GROUP_DEF 175
406#define MMC_BOOT_EXT_ERASE_MEM_CONT 181
407#define MMC_BOOT_EXT_CMMC_BUS_WIDTH 183
408#define MMC_BOOT_EXT_CMMC_HS_TIMING 185
409#define MMC_BOOT_EXT_HC_WP_GRP_SIZE 221
410#define MMC_BOOT_EXT_ERASE_TIMEOUT_MULT 223
411#define MMC_BOOT_EXT_HC_ERASE_GRP_SIZE 224
412
413#define IS_BIT_SET_EXT_CSD(val, bit) ((ext_csd_buf[val]) & (1<<(bit)))
414#define IS_ADDR_OUT_OF_RANGE(resp) ((resp >> 31) & 0x01)
415
416#define MMC_BOOT_US_PERM_WP_EN 2
417#define MMC_BOOT_US_PWR_WP_DIS 3
418
419#define MMC_BOOT_US_PERM_WP_DIS (1<<4)
420#define MMC_BOOT_US_PWR_WP_EN 1
421
422/* For SD */
423#define MMC_BOOT_SD_HC_VOLT_SUPPLIED 0x000001AA
424#define MMC_BOOT_SD_NEG_OCR 0x00FF8000
425#define MMC_BOOT_SD_HC_HCS 0x40000000
426#define MMC_BOOT_SD_DEV_READY 0x80000000
427#define MMC_BOOT_SD_SWITCH_HS 0x80FFFFF1
428
Channagoud Kadabi54dd5312013-06-18 18:31:44 -0700429/* Put the card to sleep */
430#define MMC_CARD_SLEEP (1 << 15)
431
Ajay Dudanib01e5062011-12-03 23:23:42 -0800432/* Data structure definitions */
433struct mmc_boot_command {
434 unsigned int cmd_index;
435 unsigned int argument;
436 unsigned int cmd_type;
437
438 unsigned int resp[4];
439 unsigned int resp_type;
440 unsigned int prg_enabled;
441 unsigned int xfer_mode;
442};
443
444#define MMC_BOOT_XFER_MODE_BLOCK 0
445#define MMC_BOOT_XFER_MODE_STREAM 1
446
447/* CSD Register.
448 * Note: not all the fields have been defined here
449 */
Channagoud Kadabi398e1a22013-03-18 12:06:11 -0700450struct mmc_csd {
Ajay Dudanib01e5062011-12-03 23:23:42 -0800451 unsigned int cmmc_structure;
452 unsigned int spec_vers;
453 unsigned int card_cmd_class;
454 unsigned int write_blk_len;
455 unsigned int read_blk_len;
456 unsigned int r2w_factor;
457 unsigned int sector_size;
458 unsigned int c_size_mult;
459 unsigned int c_size;
460 unsigned int nsac_clk_cycle;
461 unsigned int taac_ns;
462 unsigned int tran_speed;
463 unsigned int erase_grp_size;
464 unsigned int erase_grp_mult;
465 unsigned int wp_grp_size;
466 unsigned int wp_grp_enable:1;
467 unsigned int perm_wp:1;
468 unsigned int temp_wp:1;
469 unsigned int erase_blk_len:1;
470 unsigned int read_blk_misalign:1;
471 unsigned int write_blk_misalign:1;
472 unsigned int read_blk_partial:1;
473 unsigned int write_blk_partial:1;
474};
475
476/* CID Register */
Channagoud Kadabi398e1a22013-03-18 12:06:11 -0700477struct mmc_cid {
Ajay Dudanib01e5062011-12-03 23:23:42 -0800478 unsigned int mid; /* 8 bit manufacturer id */
479 unsigned int oid; /* 16 bits 2 character ASCII - OEM ID */
480 unsigned char pnm[7]; /* 6 character ASCII - product name */
481 unsigned int prv; /* 8 bits - product revision */
482 unsigned int psn; /* 32 bits - product serial number */
483 unsigned int month; /* 4 bits manufacturing month */
484 unsigned int year; /* 4 bits manufacturing year */
485};
486
487/* SCR Register */
488struct mmc_boot_scr {
489 unsigned int scr_structure;
490 unsigned int mmc_spec;
491#define MMC_BOOT_SCR_MMC_SPEC_V1_01 0
492#define MMC_BOOT_SCR_MMC_SPEC_V1_10 1
493#define MMC_BOOT_SCR_MMC_SPEC_V2_00 2
494 unsigned int data_stat_after_erase;
495 unsigned int mmc_security;
496#define MMC_BOOT_SCR_NO_SECURITY 0
497#define MMC_BOOT_SCR_SECURITY_UNUSED 1
498#define MMC_BOOT_SCR_SECURITY_V1_01 2
499#define MMC_BOOT_SCR_SECURITY_V2_00 3
500 unsigned int mmc_bus_width;
501#define MMC_BOOT_SCR_BUS_WIDTH_1_BIT (1<<0)
502#define MMC_BOOT_SCR_BUS_WIDTH_4_BIT (1<<2)
503};
504
Channagoud Kadabi398e1a22013-03-18 12:06:11 -0700505struct mmc_card {
Ajay Dudanib01e5062011-12-03 23:23:42 -0800506 unsigned int rca;
507 unsigned int ocr;
508 unsigned long long capacity;
509 unsigned int type;
510#define MMC_BOOT_TYPE_STD_SD 0
511#define MMC_BOOT_TYPE_SDHC 1
512#define MMC_BOOT_TYPE_SDIO 2
513#define MMC_BOOT_TYPE_MMCHC 3
514#define MMC_BOOT_TYPE_STD_MMC 4
515 unsigned int status;
516#define MMC_BOOT_STATUS_INACTIVE 0
517#define MMC_BOOT_STATUS_ACTIVE 1
Channagoud Kadabi96c629e2013-09-10 14:21:30 -0700518 uint32_t block_size;
Ajay Dudanib01e5062011-12-03 23:23:42 -0800519 unsigned int rd_timeout_ns;
520 unsigned int wr_timeout_ns;
521 unsigned int rd_block_len;
522 unsigned int wr_block_len;
523 //unsigned int data_xfer_len;
Channagoud Kadabi398e1a22013-03-18 12:06:11 -0700524 struct mmc_cid cid;
525 struct mmc_csd csd;
Ajay Dudanib01e5062011-12-03 23:23:42 -0800526 struct mmc_boot_scr scr;
527};
528
529#define MMC_BOOT_XFER_MULTI_BLOCK 0
530#define MMC_BOOT_XFER_SINGLE_BLOCK 1
531
Channagoud Kadabi676c2e32013-04-02 11:39:01 -0700532/* Capabilities for the mmc host */
533struct mmc_caps {
534 uint8_t ddr_mode; /* DDR mode support */
535 uint8_t hs200_mode; /* HS200 mode support */
536 uint8_t bus_width; /* bus width */
537 uint32_t hs_clk_rate; /* Clock rate for high speed mode */
538};
539
Channagoud Kadabi398e1a22013-03-18 12:06:11 -0700540struct mmc_host {
Ajay Dudanib01e5062011-12-03 23:23:42 -0800541 unsigned int mclk_rate;
542 unsigned int ocr;
543 unsigned int cmd_retry;
Channagoud Kadabi672c4c42012-12-20 17:51:45 -0800544 uint32_t mmc_cont_version;
Channagoud Kadabi676c2e32013-04-02 11:39:01 -0700545 struct mmc_caps caps;
Ajay Dudanib01e5062011-12-03 23:23:42 -0800546};
547
548/* MACRO used to evoke regcomp */
549#define REGCOMP_CKRTN(regx, str, errhandle) \
550 do { \
551 if(regcomp(regx, str, REG_EXTENDED) != 0) { \
552 printf("Error building regex: %s\n", str); \
553 goto errhandle; \
554 } \
555 } while(0);
556
Ajay Dudanib01e5062011-12-03 23:23:42 -0800557#define PUT_LWORD_TO_BYTE(x, y) do{*(x) = y & 0xff; \
558 *(x+1) = (y >> 8) & 0xff; \
559 *(x+2) = (y >> 16) & 0xff; \
560 *(x+3) = (y >> 24) & 0xff; }while(0)
561
562#define GET_PAR_NUM_FROM_POS(x) (((x & 0x0000FF00) >> 8) + (x & 0x000000FF))
563
564#define OFFSET_STATUS 0x00
565#define OFFSET_TYPE 0x04
566#define OFFSET_FIRST_SEC 0x08
567#define OFFSET_SIZE 0x0C
568#define COPYBUFF_SIZE (1024 * 16)
569#define BINARY_IN_TABLE_SIZE (16 * 512)
570#define MAX_FILE_ENTRIES 20
571
572#define MMC_RCA 2
Channagoud Kadabi54dd5312013-06-18 18:31:44 -0700573#define MMC_CARD_RCA_BIT 16
Ajay Dudanib01e5062011-12-03 23:23:42 -0800574
575/* Can be used to unpack array of upto 32 bits data */
576#define UNPACK_BITS(array, start, len, size_of) \
577 ({ \
578 unsigned int indx = (start) / (size_of); \
579 unsigned int offset = (start) % (size_of); \
580 unsigned int mask = (((len)<(size_of))? 1<<(len):0) - 1; \
581 unsigned int unpck = array[indx] >> offset; \
582 unsigned int indx2 = ((start) + (len) - 1) / (size_of); \
583 if(indx2 > indx) \
584 unpck |= array[indx2] << ((size_of) - offset); \
585 unpck & mask; \
586 })
587
588#define MMC_BOOT_MAX_COMMAND_RETRY 1000
589#define MMC_BOOT_RD_BLOCK_LEN 512
590#define MMC_BOOT_WR_BLOCK_LEN 512
591
592/* We have 16 32-bits FIFO registers */
593#define MMC_BOOT_MCI_FIFO_DEPTH 16
594#define MMC_BOOT_MCI_HFIFO_COUNT ( MMC_BOOT_MCI_FIFO_DEPTH / 2 )
595#define MMC_BOOT_MCI_FIFO_SIZE ( MMC_BOOT_MCI_FIFO_DEPTH * 4 )
596
597#define MAX_PARTITIONS 64
598
599#define MMC_BOOT_CHECK_PATTERN 0xAA /* 10101010b */
600
601#define MMC_CLK_400KHZ 400000
602#define MMC_CLK_144KHZ 144000
603#define MMC_CLK_20MHZ 20000000
604#define MMC_CLK_25MHZ 25000000
605#define MMC_CLK_48MHZ 48000000
606#define MMC_CLK_50MHZ 49152000
Channagoud Kadabi676c2e32013-04-02 11:39:01 -0700607#define MMC_CLK_96MHZ 96000000
Channagoud Kadabifb500f02013-04-22 12:55:48 -0700608#define MMC_CLK_200MHZ 200000000
Ajay Dudanib01e5062011-12-03 23:23:42 -0800609
610#define MMC_CLK_ENABLE 1
611#define MMC_CLK_DISABLE 0
612
Channagoud Kadabie6f59dc2014-01-06 17:31:39 -0800613/* SDHC mode & core sw reset related macros */
614#define MMC_BOOT_MCI_HC_MODE MMC_BOOT_MCI_REG(0x078)
615#define SDHCI_HC_START_BIT 0x0
616#define SDHCI_HC_WIDTH 0x1
617
618#define CORE_SW_RST_START 0x7
619#define CORE_SW_RST_WIDTH 0x1
620
Ajay Dudanib01e5062011-12-03 23:23:42 -0800621unsigned int mmc_boot_main(unsigned char slot, unsigned int base);
Ajay Dudanib01e5062011-12-03 23:23:42 -0800622unsigned int mmc_write(unsigned long long data_addr,
623 unsigned int data_len, unsigned int *in);
624
625unsigned int mmc_read(unsigned long long data_addr, unsigned int *out,
626 unsigned int data_len);
627unsigned mmc_get_psn(void);
628
Neeti Desai5f26aff2011-09-30 10:27:40 -0700629unsigned int mmc_erase_card(unsigned long long data_addr,
Ajay Dudanib01e5062011-12-03 23:23:42 -0800630 unsigned long long data_len);
Neeti Desai5f26aff2011-09-30 10:27:40 -0700631
Channagoud Kadabi672c4c42012-12-20 17:51:45 -0800632void mmc_mclk_reg_wr_delay();
Channagoud Kadabie2ec5a42013-03-14 16:30:42 -0700633void mmc_boot_mci_clk_enable();
634void mmc_boot_mci_clk_disable();
Channagoud Kadabi676c2e32013-04-02 11:39:01 -0700635uint8_t card_supports_ddr_mode();
636uint8_t card_supports_hs200_mode();
Channagoud Kadabi7cf5d042013-04-19 12:58:15 -0700637uint64_t mmc_get_device_capacity();
Channagoud Kadabi54dd5312013-06-18 18:31:44 -0700638void mmc_put_card_to_sleep(void);
Ajay Dudanib01e5062011-12-03 23:23:42 -0800639#endif
Channagoud Kadabi46608192013-05-02 10:22:32 -0700640#endif