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
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
|
/*
* Synopsys DesignWare Multimedia Card Interface driver
* (Based on NXP driver for lpc 31xx)
*
* Copyright (C) 2009 NXP Semiconductors
* Copyright (C) 2009, 2010 Imagination Technologies Ltd.
*
* 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.
*/
#ifndef _DW_MMC_H_
#define _DW_MMC_H_
#define DW_MMC_MAX_TRANSFER_SIZE 4096
#define DW_MMC_SECTOR_SIZE 512
#ifdef CONFIG_MMC_DW_FMP_DM_CRYPT
#define MMC_DW_IDMAC_MULTIPLIER \
(DW_MMC_MAX_TRANSFER_SIZE / DW_MMC_SECTOR_SIZE)
#else
#define MMC_DW_IDMAC_MULTIPLIER 1
#endif
#define DW_MMC_240A 0x240a
#define DW_MMC_260A 0x260a
#define SDMMC_CTRL 0x000
#define SDMMC_PWREN 0x004
#define SDMMC_CLKDIV 0x008
#define SDMMC_CLKSRC 0x00c
#define SDMMC_CLKENA 0x010
#define SDMMC_TMOUT 0x014
#define SDMMC_CTYPE 0x018
#define SDMMC_BLKSIZ 0x01c
#define SDMMC_BYTCNT 0x020
#define SDMMC_INTMASK 0x024
#define SDMMC_CMDARG 0x028
#define SDMMC_CMD 0x02c
#define SDMMC_RESP0 0x030
#define SDMMC_RESP1 0x034
#define SDMMC_RESP2 0x038
#define SDMMC_RESP3 0x03c
#define SDMMC_MINTSTS 0x040
#define SDMMC_RINTSTS 0x044
#define SDMMC_STATUS 0x048
#define SDMMC_FIFOTH 0x04c
#define SDMMC_CDETECT 0x050
#define SDMMC_WRTPRT 0x054
#define SDMMC_GPIO 0x058
#define SDMMC_TCBCNT 0x05c
#define SDMMC_TBBCNT 0x060
#define SDMMC_DEBNCE 0x064
#define SDMMC_USRID 0x068
#define SDMMC_VERID 0x06c
#define SDMMC_HCON 0x070
#define SDMMC_UHS_REG 0x074
#define SDMMC_UHS_DDR_MODE 0x1
#define SDMMC_BMOD 0x080
#define SDMMC_PLDMND 0x084
#define SDMMC_SHA_CMD_IE 0x190
#define SDMMC_SHA_CMD_IS 0x194
#define QRDY_INT_EN BIT(3)
#define QRDY_INT BIT(3)
/*
* Data offset is difference according to Version
* Lower than 2.40a : data register offest is 0x100
*/
#define DATA_OFFSET 0x100
#define DATA_240A_OFFSET 0x200
/* shift bit field */
#define _SBF(f, v) ((v) << (f))
/* Control register defines */
#define SDMMC_CTRL_USE_IDMAC BIT(25)
#define SDMMC_CTRL_CEATA_INT_EN BIT(11)
#define SDMMC_CTRL_SEND_AS_CCSD BIT(10)
#define SDMMC_CTRL_SEND_CCSD BIT(9)
#define SDMMC_CTRL_ABRT_READ_DATA BIT(8)
#define SDMMC_CTRL_SEND_IRQ_RESP BIT(7)
#define SDMMC_CTRL_READ_WAIT BIT(6)
#define SDMMC_CTRL_DMA_ENABLE BIT(5)
#define SDMMC_CTRL_INT_ENABLE BIT(4)
#define SDMMC_CTRL_DMA_RESET BIT(2)
#define SDMMC_CTRL_FIFO_RESET BIT(1)
#define SDMMC_CTRL_RESET BIT(0)
/* Clock Enable register defines */
#define SDMMC_CLKEN_LOW_PWR BIT(16)
#define SDMMC_CLKEN_ENABLE BIT(0)
/* time-out register defines */
#define SDMMC_TMOUT_DATA(n) _SBF(8, (n))
#define SDMMC_TMOUT_DATA_MSK 0xFFFFFF00
#define SDMMC_TMOUT_RESP(n) ((n) & 0xFF)
#define SDMMC_TMOUT_RESP_MSK 0xFF
/* card-type register defines */
#define SDMMC_CTYPE_8BIT BIT(16)
#define SDMMC_CTYPE_4BIT BIT(0)
#define SDMMC_CTYPE_1BIT 0
/* Interrupt status & mask register defines */
#define SDMMC_INT_SDIO(n) BIT(16 + (n))
#define SDMMC_INT_EBE BIT(15)
#define SDMMC_INT_ACD BIT(14)
#define SDMMC_INT_SBE BIT(13)
#define SDMMC_INT_HLE BIT(12)
#define SDMMC_INT_FRUN BIT(11)
#define SDMMC_INT_HTO BIT(10)
#define SDMMC_INT_VOLT_SW BIT(10)
#define SDMMC_INT_DTO BIT(9)
#define SDMMC_INT_RTO BIT(8)
#define SDMMC_INT_DCRC BIT(7)
#define SDMMC_INT_RCRC BIT(6)
#define SDMMC_INT_RXDR BIT(5)
#define SDMMC_INT_TXDR BIT(4)
#define SDMMC_INT_DATA_OVER BIT(3)
#define SDMMC_INT_CMD_DONE BIT(2)
#define SDMMC_INT_RESP_ERR BIT(1)
#define SDMMC_INT_CD BIT(0)
#define SDMMC_INT_ERROR 0xbfc2
/* Command register defines */
#define SDMMC_CMD_START BIT(31)
#define SDMMC_CMD_USE_HOLD_REG BIT(29)
#define SDMMC_VOLT_SWITCH BIT(28)
#define SDMMC_CMD_CCS_EXP BIT(23)
#define SDMMC_CMD_CEATA_RD BIT(22)
#define SDMMC_CMD_UPD_CLK BIT(21)
#define SDMMC_CMD_INIT BIT(15)
#define SDMMC_CMD_STOP BIT(14)
#define SDMMC_CMD_PRV_DAT_WAIT BIT(13)
#define SDMMC_CMD_SEND_STOP BIT(12)
#define SDMMC_CMD_STRM_MODE BIT(11)
#define SDMMC_CMD_DAT_WR BIT(10)
#define SDMMC_CMD_DAT_EXP BIT(9)
#define SDMMC_CMD_RESP_CRC BIT(8)
#define SDMMC_CMD_RESP_LONG BIT(7)
#define SDMMC_CMD_RESP_EXP BIT(6)
#define SDMMC_CMD_INDX(n) ((n) & 0x1F)
/* Status register defines */
#define SDMMC_STATUS_DMA_REQ BIT(31)
#define SDMMC_GET_FCNT(x) (((x)>>17) & 0x1FFF)
#define SDMMC_DATA_BUSY BIT(9)
/* FIFOTH register defines */
#define SDMMC_FIFOTH_DMA_MULTI_TRANS_SIZE 28
#define SDMMC_FIFOTH_RX_WMARK 16
/* Internal DMAC interrupt defines */
#define SDMMC_IDMAC_INT_AI BIT(9)
#define SDMMC_IDMAC_INT_NI BIT(8)
#define SDMMC_IDMAC_INT_CES BIT(5)
#define SDMMC_IDMAC_INT_DU BIT(4)
#define SDMMC_IDMAC_INT_FBE BIT(2)
#define SDMMC_IDMAC_INT_RI BIT(1)
#define SDMMC_IDMAC_INT_TI BIT(0)
/* Internal DMAC bus mode bits */
#define SDMMC_IDMAC_ENABLE BIT(7)
#define SDMMC_IDMAC_FB BIT(1)
#define SDMMC_IDMAC_SWRESET BIT(0)
/* Version ID register define */
#define SDMMC_GET_VERID(x) ((x) & 0xFFFF)
/* Register access macros */
#define mci_readl(dev, reg) \
__raw_readl((dev)->regs + SDMMC_##reg)
#define mci_writel(dev, reg, value) \
__raw_writel((value), (dev)->regs + SDMMC_##reg)
/* timeout */
#define dw_mci_set_timeout(host, value) mci_writel(host, TMOUT, value)
/* 16-bit FIFO access macros */
#define mci_readw(dev, reg) \
__raw_readw((dev)->regs + SDMMC_##reg)
#define mci_writew(dev, reg, value) \
__raw_writew((value), (dev)->regs + SDMMC_##reg)
/* 64-bit FIFO access macros */
#ifdef readq
#ifdef CONFIG_MMC_DW_FORCE_32BIT_SFR_RW
#define mci_readq(dev, reg) ({\
u64 __ret = 0;\
u32* ptr = (u32*)&__ret;\
*ptr++ = __raw_readl((dev)->regs + SDMMC_##reg);\
*ptr = __raw_readl((dev)->regs + SDMMC_##reg + 0x4);\
__ret;\
})
#define mci_writeq(dev, reg, value) ({\
u32 *ptr = (u32*)&(value);\
__raw_writel(*ptr++, (dev)->regs + SDMMC_##reg);\
__raw_writel(*ptr, (dev)->regs + SDMMC_##reg + 0x4);\
})
#else
#define mci_readq(dev, reg) \
__raw_readq((dev)->regs + SDMMC_##reg)
#define mci_writeq(dev, reg, value) \
__raw_writeq((value), (dev)->regs + SDMMC_##reg)
#endif /* CONFIG_MMC_DW_FORCE_32BIT_SFR_RW */
#else
/*
* Dummy readq implementation for architectures that don't define it.
*
* We would assume that none of these architectures would configure
* the IP block with a 64bit FIFO width, so this code will never be
* executed on those machines. Defining these macros here keeps the
* rest of the code free from ifdefs.
*/
#define mci_readq(dev, reg) \
(*(volatile u64 __force *)((dev)->regs + SDMMC_##reg))
#define mci_writeq(dev, reg, value) \
(*(volatile u64 __force *)((dev)->regs + SDMMC_##reg) = (value))
#endif
/*
* platform-dependent miscellaneous control
*
* Input arguments for platform-dependent control may be different
* for each one, respectively. If we would add functions like them
* whenever we need to do that, this common header file(dw_mmc.h)
* will be modified so frequently.
* The following enumeration type is to minimize an amount of changes
* of common files.
*/
enum dw_mci_misc_control {
CTRL_RESTORE_CLKSEL = 0,
CTRL_TURN_ON_2_8V,
CTRL_REQUEST_EXT_IRQ,
CTRL_CHECK_CD,
CTRL_SET_DEF_CAPS,
CTRL_TOGGLE_WINDOWS,
#define DW_MCI_TOGGLE_BLOCK_CD BIT(0)
#define DW_MCI_TOGGLE_ENABLE BIT(31)
#define DW_MCI_TOGGLE_MASK (0x7FFFFFFF)
CTRL_INIT_CLOCK,
};
#define SDMMC_DATA_TMOUT_SHIFT 11
#define SDMMC_RESP_TMOUT 0xFF
#define SDMMC_DATA_TMOUT_CRT 8
#define SDMMC_DATA_TMOUT_EXT 0x7
#define SDMMC_DATA_TMOUT_EXT_SHIFT 8
extern u32 dw_mci_calc_timeout(struct dw_mci *host);
extern int dw_mci_probe(struct dw_mci *host);
extern void dw_mci_remove(struct dw_mci *host);
extern void dw_mci_cmd_reg_summary(struct dw_mci *host);
extern void dw_mci_status_reg_summary(struct dw_mci *host);
#ifdef CONFIG_PM
extern int dw_mci_suspend(struct dw_mci *host);
extern int dw_mci_resume(struct dw_mci *host);
#endif
extern int dw_mci_ciu_clk_en(struct dw_mci *host, bool force_gating);
extern void dw_mci_ciu_clk_dis(struct dw_mci *host);
extern int dw_mci_biu_clk_en(struct dw_mci *host, bool force_gating);
extern void dw_mci_biu_clk_dis(struct dw_mci *host);
/**
* dw_mci driver data - dw-mshc implementation specific driver data.
* @caps: mmc subsystem specified capabilities of the controller(s).
* @init: early implementation specific initialization.
* @setup_clock: implementation specific clock configuration.
* @prepare_command: handle CMD register extensions.
* @set_ios: handle bus specific extensions.
* @parse_dt: parse implementation specific device tree properties.
* @cfg_smu: to configure security management unit
* @execute_tuning: "auto-tune" Clock-In parameters
*
* Provide controller implementation specific extensions. The usage of this
* data structure is fully optional and usage of each member in this structure
* is optional as well.
*/
struct dw_mci_drv_data {
unsigned long *caps;
int (*init)(struct dw_mci *host);
int (*setup_clock)(struct dw_mci *host);
void (*prepare_command)(struct dw_mci *host, u32 *cmdr);
void (*register_dump)(struct dw_mci *host);
void (*set_ios)(struct dw_mci *host, unsigned int tuning, struct mmc_ios *ios);
int (*parse_dt)(struct dw_mci *host);
void (*cfg_smu)(struct dw_mci *host);
int (*execute_tuning)(struct dw_mci *host, u32 opcode);
int (*misc_control)(struct dw_mci *host,
enum dw_mci_misc_control control, void *priv);
void (*register_notifier)(struct dw_mci *host);
void (*unregister_notifier)(struct dw_mci *host);
};
struct dw_mci_sfr_ram_dump {
u32 contrl;
u32 pwren;
u32 clkdiv;
u32 clkena;
u32 clksrc;
u32 tmout;
u32 ctype;
u32 blksiz;
u32 bytcnt;
u32 intmask;
u32 cmdarg;
u32 cmd;
u32 mintsts;
u32 rintsts;
u32 status;
u32 fifoth;
u32 tcbcnt;
u32 tbbcnt;
u32 debnce;
u32 uhs_reg;
u32 bmod;
u32 pldmnd;
u32 dbaddrl;
u32 dbaddru;
u32 dscaddrl;
u32 dscaddru;
u32 bufaddru;
u32 dbaddr;
u32 dscaddr;
u32 bufaddr;
u32 clksel;
u32 idsts64;
u32 idinten64;
u32 force_clk_stop;
u32 cdthrctl;
u32 ddr200_rdqs_en;
u32 ddr200_acync_fifo_ctrl;
u32 ddr200_dline_ctrl;
u32 fmp_emmcp_base;
u32 mpsecurity;
u32 mpstat;
u32 cmd_status;
u32 data_status;
u32 pending_events;
u32 completed_events;
u32 host_state;
u32 cmd_index;
u32 fifo_count;
u32 data_busy;
u32 data_3_state;
u32 fifo_tx_watermark;
u32 fifo_rx_watermark;
};
#endif /* _DW_MMC_H_ */
|