xref: /rk3399_rockchip-uboot/include/sdhci.h (revision af62a55785b95c1d52fc538387aaf66ffae1513c)
1*af62a557SLei Wen /*
2*af62a557SLei Wen  * Copyright 2011, Marvell Semiconductor Inc.
3*af62a557SLei Wen  * Lei Wen <leiwen@marvell.com>
4*af62a557SLei Wen  *
5*af62a557SLei Wen  * See file CREDITS for list of people who contributed to this
6*af62a557SLei Wen  * project.
7*af62a557SLei Wen  *
8*af62a557SLei Wen  * This program is free software; you can redistribute it and/or
9*af62a557SLei Wen  * modify it under the terms of the GNU General Public License as
10*af62a557SLei Wen  * published by the Free Software Foundation; either version 2 of
11*af62a557SLei Wen  * the License, or (at your option) any later version.
12*af62a557SLei Wen  *
13*af62a557SLei Wen  * This program is distributed in the hope that it will be useful,
14*af62a557SLei Wen  * but WITHOUT ANY WARRANTY; without even the implied warranty of
15*af62a557SLei Wen  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
16*af62a557SLei Wen  * GNU General Public License for more details.
17*af62a557SLei Wen  *
18*af62a557SLei Wen  * You should have received a copy of the GNU General Public License
19*af62a557SLei Wen  * along with this program; if not, write to the Free Software
20*af62a557SLei Wen  * Foundation, Inc., 59 Temple Place, Suite 330, Boston,
21*af62a557SLei Wen  * MA 02111-1307 USA
22*af62a557SLei Wen  *
23*af62a557SLei Wen  * Back ported to the 8xx platform (from the 8260 platform) by
24*af62a557SLei Wen  * Murray.Jensen@cmst.csiro.au, 27-Jan-01.
25*af62a557SLei Wen  */
26*af62a557SLei Wen #ifndef __SDHCI_HW_H
27*af62a557SLei Wen #define __SDHCI_HW_H
28*af62a557SLei Wen 
29*af62a557SLei Wen #include <asm/io.h>
30*af62a557SLei Wen /*
31*af62a557SLei Wen  * Controller registers
32*af62a557SLei Wen  */
33*af62a557SLei Wen 
34*af62a557SLei Wen #define SDHCI_DMA_ADDRESS	0x00
35*af62a557SLei Wen 
36*af62a557SLei Wen #define SDHCI_BLOCK_SIZE	0x04
37*af62a557SLei Wen #define  SDHCI_MAKE_BLKSZ(dma, blksz) (((dma & 0x7) << 12) | (blksz & 0xFFF))
38*af62a557SLei Wen 
39*af62a557SLei Wen #define SDHCI_BLOCK_COUNT	0x06
40*af62a557SLei Wen 
41*af62a557SLei Wen #define SDHCI_ARGUMENT		0x08
42*af62a557SLei Wen 
43*af62a557SLei Wen #define SDHCI_TRANSFER_MODE	0x0C
44*af62a557SLei Wen #define  SDHCI_TRNS_DMA		0x01
45*af62a557SLei Wen #define  SDHCI_TRNS_BLK_CNT_EN	0x02
46*af62a557SLei Wen #define  SDHCI_TRNS_ACMD12	0x04
47*af62a557SLei Wen #define  SDHCI_TRNS_READ	0x10
48*af62a557SLei Wen #define  SDHCI_TRNS_MULTI	0x20
49*af62a557SLei Wen 
50*af62a557SLei Wen #define SDHCI_COMMAND		0x0E
51*af62a557SLei Wen #define  SDHCI_CMD_RESP_MASK	0x03
52*af62a557SLei Wen #define  SDHCI_CMD_CRC		0x08
53*af62a557SLei Wen #define  SDHCI_CMD_INDEX	0x10
54*af62a557SLei Wen #define  SDHCI_CMD_DATA		0x20
55*af62a557SLei Wen #define  SDHCI_CMD_ABORTCMD	0xC0
56*af62a557SLei Wen 
57*af62a557SLei Wen #define  SDHCI_CMD_RESP_NONE	0x00
58*af62a557SLei Wen #define  SDHCI_CMD_RESP_LONG	0x01
59*af62a557SLei Wen #define  SDHCI_CMD_RESP_SHORT	0x02
60*af62a557SLei Wen #define  SDHCI_CMD_RESP_SHORT_BUSY 0x03
61*af62a557SLei Wen 
62*af62a557SLei Wen #define SDHCI_MAKE_CMD(c, f) (((c & 0xff) << 8) | (f & 0xff))
63*af62a557SLei Wen #define SDHCI_GET_CMD(c) ((c>>8) & 0x3f)
64*af62a557SLei Wen 
65*af62a557SLei Wen #define SDHCI_RESPONSE		0x10
66*af62a557SLei Wen 
67*af62a557SLei Wen #define SDHCI_BUFFER		0x20
68*af62a557SLei Wen 
69*af62a557SLei Wen #define SDHCI_PRESENT_STATE	0x24
70*af62a557SLei Wen #define  SDHCI_CMD_INHIBIT	0x00000001
71*af62a557SLei Wen #define  SDHCI_DATA_INHIBIT	0x00000002
72*af62a557SLei Wen #define  SDHCI_DOING_WRITE	0x00000100
73*af62a557SLei Wen #define  SDHCI_DOING_READ	0x00000200
74*af62a557SLei Wen #define  SDHCI_SPACE_AVAILABLE	0x00000400
75*af62a557SLei Wen #define  SDHCI_DATA_AVAILABLE	0x00000800
76*af62a557SLei Wen #define  SDHCI_CARD_PRESENT	0x00010000
77*af62a557SLei Wen #define  SDHCI_WRITE_PROTECT	0x00080000
78*af62a557SLei Wen 
79*af62a557SLei Wen #define SDHCI_HOST_CONTROL	0x28
80*af62a557SLei Wen #define  SDHCI_CTRL_LED		0x01
81*af62a557SLei Wen #define  SDHCI_CTRL_4BITBUS	0x02
82*af62a557SLei Wen #define  SDHCI_CTRL_HISPD	0x04
83*af62a557SLei Wen #define  SDHCI_CTRL_DMA_MASK	0x18
84*af62a557SLei Wen #define   SDHCI_CTRL_SDMA	0x00
85*af62a557SLei Wen #define   SDHCI_CTRL_ADMA1	0x08
86*af62a557SLei Wen #define   SDHCI_CTRL_ADMA32	0x10
87*af62a557SLei Wen #define   SDHCI_CTRL_ADMA64	0x18
88*af62a557SLei Wen #define   SDHCI_CTRL_8BITBUS	0x20
89*af62a557SLei Wen 
90*af62a557SLei Wen #define SDHCI_POWER_CONTROL	0x29
91*af62a557SLei Wen #define  SDHCI_POWER_ON		0x01
92*af62a557SLei Wen #define  SDHCI_POWER_180	0x0A
93*af62a557SLei Wen #define  SDHCI_POWER_300	0x0C
94*af62a557SLei Wen #define  SDHCI_POWER_330	0x0E
95*af62a557SLei Wen 
96*af62a557SLei Wen #define SDHCI_BLOCK_GAP_CONTROL	0x2A
97*af62a557SLei Wen 
98*af62a557SLei Wen #define SDHCI_WAKE_UP_CONTROL	0x2B
99*af62a557SLei Wen #define  SDHCI_WAKE_ON_INT	0x01
100*af62a557SLei Wen #define  SDHCI_WAKE_ON_INSERT	0x02
101*af62a557SLei Wen #define  SDHCI_WAKE_ON_REMOVE	0x04
102*af62a557SLei Wen 
103*af62a557SLei Wen #define SDHCI_CLOCK_CONTROL	0x2C
104*af62a557SLei Wen #define  SDHCI_DIVIDER_SHIFT	8
105*af62a557SLei Wen #define  SDHCI_DIVIDER_HI_SHIFT	6
106*af62a557SLei Wen #define  SDHCI_DIV_MASK	0xFF
107*af62a557SLei Wen #define  SDHCI_DIV_MASK_LEN	8
108*af62a557SLei Wen #define  SDHCI_DIV_HI_MASK	0x300
109*af62a557SLei Wen #define  SDHCI_CLOCK_CARD_EN	0x0004
110*af62a557SLei Wen #define  SDHCI_CLOCK_INT_STABLE	0x0002
111*af62a557SLei Wen #define  SDHCI_CLOCK_INT_EN	0x0001
112*af62a557SLei Wen 
113*af62a557SLei Wen #define SDHCI_TIMEOUT_CONTROL	0x2E
114*af62a557SLei Wen 
115*af62a557SLei Wen #define SDHCI_SOFTWARE_RESET	0x2F
116*af62a557SLei Wen #define  SDHCI_RESET_ALL	0x01
117*af62a557SLei Wen #define  SDHCI_RESET_CMD	0x02
118*af62a557SLei Wen #define  SDHCI_RESET_DATA	0x04
119*af62a557SLei Wen 
120*af62a557SLei Wen #define SDHCI_INT_STATUS	0x30
121*af62a557SLei Wen #define SDHCI_INT_ENABLE	0x34
122*af62a557SLei Wen #define SDHCI_SIGNAL_ENABLE	0x38
123*af62a557SLei Wen #define  SDHCI_INT_RESPONSE	0x00000001
124*af62a557SLei Wen #define  SDHCI_INT_DATA_END	0x00000002
125*af62a557SLei Wen #define  SDHCI_INT_DMA_END	0x00000008
126*af62a557SLei Wen #define  SDHCI_INT_SPACE_AVAIL	0x00000010
127*af62a557SLei Wen #define  SDHCI_INT_DATA_AVAIL	0x00000020
128*af62a557SLei Wen #define  SDHCI_INT_CARD_INSERT	0x00000040
129*af62a557SLei Wen #define  SDHCI_INT_CARD_REMOVE	0x00000080
130*af62a557SLei Wen #define  SDHCI_INT_CARD_INT	0x00000100
131*af62a557SLei Wen #define  SDHCI_INT_ERROR	0x00008000
132*af62a557SLei Wen #define  SDHCI_INT_TIMEOUT	0x00010000
133*af62a557SLei Wen #define  SDHCI_INT_CRC		0x00020000
134*af62a557SLei Wen #define  SDHCI_INT_END_BIT	0x00040000
135*af62a557SLei Wen #define  SDHCI_INT_INDEX	0x00080000
136*af62a557SLei Wen #define  SDHCI_INT_DATA_TIMEOUT	0x00100000
137*af62a557SLei Wen #define  SDHCI_INT_DATA_CRC	0x00200000
138*af62a557SLei Wen #define  SDHCI_INT_DATA_END_BIT	0x00400000
139*af62a557SLei Wen #define  SDHCI_INT_BUS_POWER	0x00800000
140*af62a557SLei Wen #define  SDHCI_INT_ACMD12ERR	0x01000000
141*af62a557SLei Wen #define  SDHCI_INT_ADMA_ERROR	0x02000000
142*af62a557SLei Wen 
143*af62a557SLei Wen #define  SDHCI_INT_NORMAL_MASK	0x00007FFF
144*af62a557SLei Wen #define  SDHCI_INT_ERROR_MASK	0xFFFF8000
145*af62a557SLei Wen 
146*af62a557SLei Wen #define  SDHCI_INT_CMD_MASK	(SDHCI_INT_RESPONSE | SDHCI_INT_TIMEOUT | \
147*af62a557SLei Wen 		SDHCI_INT_CRC | SDHCI_INT_END_BIT | SDHCI_INT_INDEX)
148*af62a557SLei Wen #define  SDHCI_INT_DATA_MASK	(SDHCI_INT_DATA_END | SDHCI_INT_DMA_END | \
149*af62a557SLei Wen 		SDHCI_INT_DATA_AVAIL | SDHCI_INT_SPACE_AVAIL | \
150*af62a557SLei Wen 		SDHCI_INT_DATA_TIMEOUT | SDHCI_INT_DATA_CRC | \
151*af62a557SLei Wen 		SDHCI_INT_DATA_END_BIT | SDHCI_INT_ADMA_ERROR)
152*af62a557SLei Wen #define SDHCI_INT_ALL_MASK	((unsigned int)-1)
153*af62a557SLei Wen 
154*af62a557SLei Wen #define SDHCI_ACMD12_ERR	0x3C
155*af62a557SLei Wen 
156*af62a557SLei Wen /* 3E-3F reserved */
157*af62a557SLei Wen 
158*af62a557SLei Wen #define SDHCI_CAPABILITIES	0x40
159*af62a557SLei Wen #define  SDHCI_TIMEOUT_CLK_MASK	0x0000003F
160*af62a557SLei Wen #define  SDHCI_TIMEOUT_CLK_SHIFT 0
161*af62a557SLei Wen #define  SDHCI_TIMEOUT_CLK_UNIT	0x00000080
162*af62a557SLei Wen #define  SDHCI_CLOCK_BASE_MASK	0x00003F00
163*af62a557SLei Wen #define  SDHCI_CLOCK_V3_BASE_MASK	0x0000FF00
164*af62a557SLei Wen #define  SDHCI_CLOCK_BASE_SHIFT	8
165*af62a557SLei Wen #define  SDHCI_MAX_BLOCK_MASK	0x00030000
166*af62a557SLei Wen #define  SDHCI_MAX_BLOCK_SHIFT  16
167*af62a557SLei Wen #define  SDHCI_CAN_DO_8BIT	0x00040000
168*af62a557SLei Wen #define  SDHCI_CAN_DO_ADMA2	0x00080000
169*af62a557SLei Wen #define  SDHCI_CAN_DO_ADMA1	0x00100000
170*af62a557SLei Wen #define  SDHCI_CAN_DO_HISPD	0x00200000
171*af62a557SLei Wen #define  SDHCI_CAN_DO_SDMA	0x00400000
172*af62a557SLei Wen #define  SDHCI_CAN_VDD_330	0x01000000
173*af62a557SLei Wen #define  SDHCI_CAN_VDD_300	0x02000000
174*af62a557SLei Wen #define  SDHCI_CAN_VDD_180	0x04000000
175*af62a557SLei Wen #define  SDHCI_CAN_64BIT	0x10000000
176*af62a557SLei Wen 
177*af62a557SLei Wen #define SDHCI_CAPABILITIES_1	0x44
178*af62a557SLei Wen 
179*af62a557SLei Wen #define SDHCI_MAX_CURRENT	0x48
180*af62a557SLei Wen 
181*af62a557SLei Wen /* 4C-4F reserved for more max current */
182*af62a557SLei Wen 
183*af62a557SLei Wen #define SDHCI_SET_ACMD12_ERROR	0x50
184*af62a557SLei Wen #define SDHCI_SET_INT_ERROR	0x52
185*af62a557SLei Wen 
186*af62a557SLei Wen #define SDHCI_ADMA_ERROR	0x54
187*af62a557SLei Wen 
188*af62a557SLei Wen /* 55-57 reserved */
189*af62a557SLei Wen 
190*af62a557SLei Wen #define SDHCI_ADMA_ADDRESS	0x58
191*af62a557SLei Wen 
192*af62a557SLei Wen /* 60-FB reserved */
193*af62a557SLei Wen 
194*af62a557SLei Wen #define SDHCI_SLOT_INT_STATUS	0xFC
195*af62a557SLei Wen 
196*af62a557SLei Wen #define SDHCI_HOST_VERSION	0xFE
197*af62a557SLei Wen #define  SDHCI_VENDOR_VER_MASK	0xFF00
198*af62a557SLei Wen #define  SDHCI_VENDOR_VER_SHIFT	8
199*af62a557SLei Wen #define  SDHCI_SPEC_VER_MASK	0x00FF
200*af62a557SLei Wen #define  SDHCI_SPEC_VER_SHIFT	0
201*af62a557SLei Wen #define   SDHCI_SPEC_100	0
202*af62a557SLei Wen #define   SDHCI_SPEC_200	1
203*af62a557SLei Wen #define   SDHCI_SPEC_300	2
204*af62a557SLei Wen 
205*af62a557SLei Wen /*
206*af62a557SLei Wen  * End of controller registers.
207*af62a557SLei Wen  */
208*af62a557SLei Wen 
209*af62a557SLei Wen #define SDHCI_MAX_DIV_SPEC_200	256
210*af62a557SLei Wen #define SDHCI_MAX_DIV_SPEC_300	2046
211*af62a557SLei Wen 
212*af62a557SLei Wen /*
213*af62a557SLei Wen  * quirks
214*af62a557SLei Wen  */
215*af62a557SLei Wen #define SDHCI_QUIRK_32BIT_DMA_ADDR	(1 << 0)
216*af62a557SLei Wen 
217*af62a557SLei Wen /*
218*af62a557SLei Wen  * Host SDMA buffer boundary. Valid values from 4K to 512K in powers of 2.
219*af62a557SLei Wen  */
220*af62a557SLei Wen #define SDHCI_DEFAULT_BOUNDARY_SIZE	(512 * 1024)
221*af62a557SLei Wen #define SDHCI_DEFAULT_BOUNDARY_ARG	(7)
222*af62a557SLei Wen struct sdhci_ops {
223*af62a557SLei Wen #ifdef CONFIG_MMC_SDHCI_IO_ACCESSORS
224*af62a557SLei Wen 	u32             (*read_l)(struct sdhci_host *host, int reg);
225*af62a557SLei Wen 	u16             (*read_w)(struct sdhci_host *host, int reg);
226*af62a557SLei Wen 	u8              (*read_b)(struct sdhci_host *host, int reg);
227*af62a557SLei Wen 	void            (*write_l)(struct sdhci_host *host, u32 val, int reg);
228*af62a557SLei Wen 	void            (*write_w)(struct sdhci_host *host, u16 val, int reg);
229*af62a557SLei Wen 	void            (*write_b)(struct sdhci_host *host, u8 val, int reg);
230*af62a557SLei Wen #endif
231*af62a557SLei Wen };
232*af62a557SLei Wen 
233*af62a557SLei Wen struct sdhci_host {
234*af62a557SLei Wen 	char *name;
235*af62a557SLei Wen 	void *ioaddr;
236*af62a557SLei Wen 	unsigned int quirks;
237*af62a557SLei Wen 	unsigned int version;
238*af62a557SLei Wen 	unsigned int clock;
239*af62a557SLei Wen 	const struct sdhci_ops *ops;
240*af62a557SLei Wen };
241*af62a557SLei Wen 
242*af62a557SLei Wen #ifdef CONFIG_MMC_SDHCI_IO_ACCESSORS
243*af62a557SLei Wen 
244*af62a557SLei Wen static inline void sdhci_writel(struct sdhci_host *host, u32 val, int reg)
245*af62a557SLei Wen {
246*af62a557SLei Wen 	if (unlikely(host->ops->write_l))
247*af62a557SLei Wen 		host->ops->write_l(host, val, reg);
248*af62a557SLei Wen 	else
249*af62a557SLei Wen 		writel(val, host->ioaddr + reg);
250*af62a557SLei Wen }
251*af62a557SLei Wen 
252*af62a557SLei Wen static inline void sdhci_writew(struct sdhci_host *host, u16 val, int reg)
253*af62a557SLei Wen {
254*af62a557SLei Wen 	if (unlikely(host->ops->write_w))
255*af62a557SLei Wen 		host->ops->write_w(host, val, reg);
256*af62a557SLei Wen 	else
257*af62a557SLei Wen 		writew(val, host->ioaddr + reg);
258*af62a557SLei Wen }
259*af62a557SLei Wen 
260*af62a557SLei Wen static inline void sdhci_writeb(struct sdhci_host *host, u8 val, int reg)
261*af62a557SLei Wen {
262*af62a557SLei Wen 	if (unlikely(host->ops->write_b))
263*af62a557SLei Wen 		host->ops->write_b(host, val, reg);
264*af62a557SLei Wen 	else
265*af62a557SLei Wen 		writeb(val, host->ioaddr + reg);
266*af62a557SLei Wen }
267*af62a557SLei Wen 
268*af62a557SLei Wen static inline u32 sdhci_readl(struct sdhci_host *host, int reg)
269*af62a557SLei Wen {
270*af62a557SLei Wen 	if (unlikely(host->ops->read_l))
271*af62a557SLei Wen 		return host->ops->read_l(host, reg);
272*af62a557SLei Wen 	else
273*af62a557SLei Wen 		return readl(host->ioaddr + reg);
274*af62a557SLei Wen }
275*af62a557SLei Wen 
276*af62a557SLei Wen static inline u16 sdhci_readw(struct sdhci_host *host, int reg)
277*af62a557SLei Wen {
278*af62a557SLei Wen 	if (unlikely(host->ops->read_w))
279*af62a557SLei Wen 		return host->ops->read_w(host, reg);
280*af62a557SLei Wen 	else
281*af62a557SLei Wen 		return readw(host->ioaddr + reg);
282*af62a557SLei Wen }
283*af62a557SLei Wen 
284*af62a557SLei Wen static inline u8 sdhci_readb(struct sdhci_host *host, int reg)
285*af62a557SLei Wen {
286*af62a557SLei Wen 	if (unlikely(host->ops->read_b))
287*af62a557SLei Wen 		return host->ops->read_b(host, reg);
288*af62a557SLei Wen 	else
289*af62a557SLei Wen 		return readb(host->ioaddr + reg);
290*af62a557SLei Wen }
291*af62a557SLei Wen 
292*af62a557SLei Wen #else
293*af62a557SLei Wen 
294*af62a557SLei Wen static inline void sdhci_writel(struct sdhci_host *host, u32 val, int reg)
295*af62a557SLei Wen {
296*af62a557SLei Wen 	writel(val, host->ioaddr + reg);
297*af62a557SLei Wen }
298*af62a557SLei Wen 
299*af62a557SLei Wen static inline void sdhci_writew(struct sdhci_host *host, u16 val, int reg)
300*af62a557SLei Wen {
301*af62a557SLei Wen 	writew(val, host->ioaddr + reg);
302*af62a557SLei Wen }
303*af62a557SLei Wen 
304*af62a557SLei Wen static inline void sdhci_writeb(struct sdhci_host *host, u8 val, int reg)
305*af62a557SLei Wen {
306*af62a557SLei Wen 	writeb(val, host->ioaddr + reg);
307*af62a557SLei Wen }
308*af62a557SLei Wen static inline u32 sdhci_readl(struct sdhci_host *host, int reg)
309*af62a557SLei Wen {
310*af62a557SLei Wen 	return readl(host->ioaddr + reg);
311*af62a557SLei Wen }
312*af62a557SLei Wen 
313*af62a557SLei Wen static inline u16 sdhci_readw(struct sdhci_host *host, int reg)
314*af62a557SLei Wen {
315*af62a557SLei Wen 	return readw(host->ioaddr + reg);
316*af62a557SLei Wen }
317*af62a557SLei Wen 
318*af62a557SLei Wen static inline u8 sdhci_readb(struct sdhci_host *host, int reg)
319*af62a557SLei Wen {
320*af62a557SLei Wen 	return readb(host->ioaddr + reg);
321*af62a557SLei Wen }
322*af62a557SLei Wen #endif
323*af62a557SLei Wen 
324*af62a557SLei Wen int add_sdhci(struct sdhci_host *host, u32 max_clk, u32 min_clk);
325*af62a557SLei Wen #endif /* __SDHCI_HW_H */
326