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