summaryrefslogtreecommitdiff
path: root/board/st/u8500/mmc.h
blob: 069aced00b4cac53544707390c5a8db33062ff1f (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
/*
 * Copyright (C) ST-Ericsson SA 2009
 *
 * See file CREDITS for list of people who contributed to this
 * project.
 *
 * This program is free software; you can redistribute it and/or
 * modify it under the terms of the GNU General Public License as
 * published by the Free Software Foundation; either version 2 of
 * the License, or (at your option) any later version.
 *
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License
 * along with this program; if not, write to the Free Software
 * Foundation, Inc., 59 Temple Place, Suite 330, Boston,
 * MA 02111-1307 USA
 */
#ifndef _MMC_H_
#define _MMC_H_

#include <common.h>
#include "asm-arm/arch-stw8500/mmc.h"

/*---------------------------------------------------------------------------
 * Enums
 *---------------------------------------------------------------------------*/

extern char *mmc_error_name[];

#define t_mmc_irq_src u32

typedef enum {
    MMC_CMD_CRC_FAIL_INT            = 0x00000001,
    MMC_DATA_CRC_FAIL_INT           = 0x00000002,
    MMC_CMD_TIMEOUT_INT             = 0x00000004,
    MMC_DATA_TIMEOUT_INT            = 0x00000008,
    MMC_TX_UNDERRUN_INT             = 0x00000010,
    MMC_RX_OVERRUN_INT              = 0x00000020,
    MMC_CMD_RESP_OK_INT             = 0x00000040,
    MMC_CMD_SENT_INT                = 0x00000080,
    MMC_DATA_END_INT                = 0x00000100,
    MMC_DATA_BLOCK_OK_INT           = 0x00000400,
    MMC_CMD_ACTIVE_INT              = 0x00000800,
    MMC_TX_ACTIVE_INT               = 0x00001000,
    MMC_RX_ACTIVE_INT               = 0x00002000,
    MMC_TX_FIFO_HALF_EMPTY_INT      = 0x00004000,
    MMC_RX_FIFO_HALF_FULL_INT       = 0x00008000,
    MMC_TX_FIFO_FULL_INT            = 0x00010000,
    MMC_RX_FIFO_FULL_INT            = 0x00020000,
    MMC_TX_FIFO_EMPTY_INT           = 0x00040000,
    MMC_RX_FIFO_EMPTY_INT           = 0x00080000,
    MMC_TX_DATA_AVLBL_INT           = 0x00100000,
    MMC_RX_DATA_AVLBL_INT           = 0x00200000,
    MMC_ALL_STATIC_IT               = 0x000005FF,
    MMC_ALL_IT                      = 0x003FFDFF

} t_mmc_interrupt;

typedef enum {
    MMC_DISABLE  = 0,
    MMC_ENABLE
} t_mmc_state;


typedef enum {
    MMC_POWER_OFF = 0x0,
    MMC_POWER_UP  = 0x2,
    MMC_POWER_ON  = 0x3
} t_mmc_power_state;

typedef enum {
    MMC_PUSH_PULL = 0,
    MMC_OPEN_DRAIN  
} t_mmc_bus_mode;

typedef enum {
    MMC_GO_IDLE_STATE              = 0,
    MMC_SEND_OP_COND               = 1,
    MMC_ALL_SEND_CID               = 2,
    MMC_SET_REL_ADDR               = 3,      
    MMC_SET_DSR                    = 4,      
    MMC_SEL_DESEL_CARD             = 7, 
    MMC_SEND_CSD                   = 9,
    MMC_SEND_CID                   = 10, 
    MMC_READ_DAT_UNTIL_STOP        = 11,
    MMC_STOP_TRANSMISSION          = 12,  
    MMC_SEND_STATUS                = 13, 
    MMC_GO_INACTIVE_STATE          = 15,
    MMC_SET_BLOCKLEN               = 16,
    MMC_READ_SINGLE_BLOCK          = 17,
    MMC_READ_MULT_BLOCK            = 18,
    MMC_WRITE_DAT_UNTIL_STOP       = 20,
    MMC_SET_BLOCK_COUNT            = 23,
    MMC_WRITE_SINGLE_BLOCK         = 24,   
    MMC_WRITE_MULT_BLOCK           = 25,
    MMC_PROG_CID                   = 26, 
    MMC_PROG_CSD                   = 27,
    MMC_SET_WRITE_PROT             = 28,
    MMC_CLR_WRITE_PROT             = 29,  
    MMC_SEND_WRITE_PROT            = 30,
    MMC_ERASE_GRP_START            = 35,  
    MMC_ERASE_GRP_END              = 36,
    MMC_ERASE                      = 38,
    MMC_FAST_IO                    = 39, 
    MMC_GO_IRQ_STATE               = 40, 
    SD_SEND_OP_COND                = 41,
    MMC_LOCK_UNLOCK                = 42, 
    MMC_APP_CMD                    = 55,
    MMC_GEN_CMD                    = 56,
    MMC_NO_CMD                     = 64
} t_mmc_command_index;

typedef enum {
    MMC_SHORT_RESP = 0,
    MMC_LONG_RESP
} t_mmc_response_type;


typedef enum {
    MMC_WRITE= 0,
    MMC_READ
} t_mmc_transfer_direction;

typedef enum {
    MMC_BLOCK = 0,
    MMC_STREAM
} t_mmc_transfer_type;

typedef enum {
    POLLING_MODE = 0,
    INTERRUPT_MODE,
    DMA_MODE
} t_mmc_device_mode;

/*---------------------------------------------------------------------------
 * Structures
 *---------------------------------------------------------------------------*/

typedef struct {
    t_mmc_bus_mode mode;
    t_mmc_state rodctrl;
} t_mmc_bus_configuration;

typedef struct {
    t_mmc_state pwrsave;
    t_mmc_state bypass;
    t_mmc_state widebus;
} t_mmc_clock_control;

typedef struct {
    t_bool IsRespExpected;
    t_bool IsLongResp;
    t_bool IsInterruptMode;
    t_bool IsPending;
    t_mmc_state cmdpath;
} t_mmc_command_control;


#define t_mmc_event   u32

#define t_mmc_filter_mode u32
#define NO_FILTER_MODE		0

typedef enum 
{
    MMC_NEW = 0,
    MMC_OLD
} t_mmc_irq_status_usage;

typedef struct 
{
    t_mmc_irq_status_usage usage;
    u32 IRQStatus;
    u32 EventStatus;
} t_mmc_irq_status;

typedef enum {

    MMC_MULTIMEDIA_CARD,
    MMC_SECURE_DIGITAL_CARD,
    MMC_SECURE_DIGITAL_IO_CARD,
    MMC_HIGH_SPEED_MULTIMEDIA_CARD,
    MMC_SECURE_DIGITAL_IO_COMBO_CARD

} t_mmc_card_type;

typedef struct {
    u32 CID[4];
    u32 CSD[4];
    u16 RCA;
    t_mmc_card_type card_type;
    u8 padding;
    u8 sdio_cccr[4]; /* I/O ready, CCCR/SDIO revision, SD Specification revision, and Card Capability registers */
    int	blockaddressed;
} t_mmc_card_info;

typedef struct {
    t_mmc_error error;
    u16 transferred_bytes;
} t_mmc_last_transfer_info;	    	

typedef enum {
    NO_TRANSFER    = 0,
    TRANSFER_IN_PROGRESS
} t_mmc_transfer_state;

typedef enum {
    WRITE_PROT_WHOLE_CARD_TEMP = 0,
    WRITE_PROT_WHOLE_CARD_PERM,
    WRITE_PROT_SINGLE_GROUP
} t_mmc_write_protect_type;

/*---------------------------------------------------------------------------
 *  Functions Prototype                                                   
 *---------------------------------------------------------------------------*/


t_mmc_error		mmc_init (u8,t_logical_address) ;

t_mmc_error 		mmc_setpowerstate(t_mmc_power_state);
t_mmc_power_state 	mmc_getpowerstate(void);
t_mmc_error 		mmc_setoperatingvoltage(u8);
u8 			mmc_getoperatingvoltage (void);
t_mmc_error 		mmc_configbus(t_mmc_bus_configuration);

t_mmc_error 		mmc_setclock(t_mmc_state);
t_mmc_error 		mmc_configclockcontrol(t_mmc_clock_control);
t_mmc_error 		mmc_setclockfrequency(u8);
t_mmc_error 		mmc_sendcommand(t_mmc_command_index, u32,t_mmc_command_control) ;
t_mmc_command_index 	mmc_getcommandresponse(void) ;
t_mmc_error 		mmc_getresponse(t_mmc_response_type, u32*) ;
t_mmc_error 		mmc_setdatapath(t_mmc_state);
t_mmc_error 		mmc_setdatatimeout(u32);
t_mmc_error 		mmc_setdatalength(u16);
t_mmc_error 		mmc_setdatablocklength(u8);
t_mmc_error 		mmc_settransferdirection(t_mmc_transfer_direction) ;
t_mmc_error 		mmc_settransfertype(t_mmc_transfer_type);
t_mmc_error 		mmc_handledma(t_mmc_state);
u16 			mmc_getdatacounter(void);

t_mmc_error		mmc_selectsdcard(u8);
t_mmc_error 		mmc_poweron(u8) ;
t_mmc_error 		mmc_poweroff(u8);
t_mmc_error 		mmc_initializeCards(u8);
t_mmc_error  	    	mmc_getcardinfo(u8, t_mmc_card_info *) ;
t_mmc_error 		mmc_setdevicemode(t_mmc_device_mode);
t_mmc_error 		mmc_readbytes(u8, u32, u32*, u16) ;
t_mmc_error 		mmc_readblocks(u8, u32, u32*, u16, u16) ;
t_mmc_error 		mmc_writebytes(u8, u32, u32* , u16) ;
t_mmc_error 		mmc_writeblocks(u8, u32, u32*, u16, u16) ;
t_mmc_transfer_state    mmc_gettransferstate(void);
t_mmc_error  		mmc_erase(u8, u32, u32) ;

u8 convert_from_bytes_to_power_of_two (u16 no_of_bytes);

/*New Interrupt strategy(M1 functions)*/
void			mmc_acknowledgementevent(t_mmc_event *);

#endif /* _MMC_H_ */