xref: /rk3399_ARM-atf/include/drivers/rpi3/sdhost/rpi3_sdhost.h (revision 70b0f2789e93f253bec5cbd2986d0de023c1bdf4)
1 /*
2  * Copyright (c) 2019, Linaro Limited
3  * Copyright (c) 2019, Ying-Chun Liu (PaulLiu) <paul.liu@linaro.org>
4  *
5  * SPDX-License-Identifier: BSD-3-Clause
6  */
7 
8 #ifndef RPI3_SDHOST_H
9 #define	RPI3_SDHOST_H
10 
11 #include <drivers/mmc.h>
12 #include <stdint.h>
13 #include <platform_def.h>
14 
15 struct rpi3_sdhost_params {
16 	uintptr_t	reg_base;
17 	uint32_t	clk_rate;
18 	uint32_t	bus_width;
19 	uint32_t        flags;
20 	uint32_t	current_cmd;
21 	uint8_t		cmdbusy;
22 	uint8_t		mmc_app_cmd;
23 	uint32_t	ns_per_fifo_word;
24 	uint32_t	crc_err_retries;
25 
26 	uint32_t	sdcard_rca;
27 	uint32_t	gpio48_pinselect[6];
28 };
29 
30 void rpi3_sdhost_init(struct rpi3_sdhost_params *params,
31 		      struct mmc_device_info *mmc_dev_info);
32 void rpi3_sdhost_stop(void);
33 
34 /* Registers */
35 #define HC_COMMAND			0x00        /* Command and flags */
36 #define HC_ARGUMENT			0x04
37 #define HC_TIMEOUTCOUNTER		0x08
38 #define HC_CLOCKDIVISOR			0x0c
39 #define HC_RESPONSE_0			0x10
40 #define HC_RESPONSE_1			0x14
41 #define HC_RESPONSE_2			0x18
42 #define HC_RESPONSE_3			0x1c
43 #define HC_HOSTSTATUS			0x20
44 #define HC_POWER			0x30
45 #define HC_DEBUG			0x34
46 #define HC_HOSTCONFIG			0x38
47 #define HC_BLOCKSIZE			0x3c
48 #define HC_DATAPORT			0x40
49 #define HC_BLOCKCOUNT			0x50
50 
51 /* Flags for HC_COMMAND register */
52 #define HC_CMD_ENABLE			0x8000
53 #define HC_CMD_FAILED			0x4000
54 #define HC_CMD_BUSY			0x0800
55 #define HC_CMD_RESPONSE_NONE		0x0400
56 #define HC_CMD_RESPONSE_LONG		0x0200
57 #define HC_CMD_WRITE			0x0080
58 #define HC_CMD_READ			0x0040
59 #define HC_CMD_COMMAND_MASK		0x003f
60 
61 #define HC_CLOCKDIVISOR_MAXVAL		0x07ff
62 #define HC_CLOCKDIVISOR_PREFERVAL	0x027b
63 #define HC_CLOCKDIVISOR_SLOWVAL		0x0148
64 #define HC_CLOCKDIVISOR_STOPVAL		0x01fb
65 
66 /* Flags for HC_HOSTSTATUS register */
67 #define HC_HSTST_HAVEDATA		0x0001
68 #define HC_HSTST_ERROR_FIFO		0x0008
69 #define HC_HSTST_ERROR_CRC7		0x0010
70 #define HC_HSTST_ERROR_CRC16		0x0020
71 #define HC_HSTST_TIMEOUT_CMD		0x0040
72 #define HC_HSTST_TIMEOUT_DATA		0x0080
73 #define HC_HSTST_INT_BLOCK		0x0200
74 #define HC_HSTST_INT_BUSY		0x0400
75 
76 #define HC_HSTST_RESET			0xffff
77 
78 #define HC_HSTST_MASK_ERROR_DATA	(HC_HSTST_ERROR_FIFO | \
79 					 HC_HSTST_ERROR_CRC7 | \
80 					 HC_HSTST_ERROR_CRC16 | \
81 					 HC_HSTST_TIMEOUT_DATA)
82 
83 #define HC_HSTST_MASK_ERROR_ALL		(HC_HSTST_MASK_ERROR_DATA | \
84 					 HC_HSTST_TIMEOUT_CMD)
85 
86 /* Flags for HC_HOSTCONFIG register */
87 #define HC_HSTCF_INTBUS_WIDE		0x0002
88 #define HC_HSTCF_EXTBUS_4BIT		0x0004
89 #define HC_HSTCF_SLOW_CARD		0x0008
90 #define HC_HSTCF_INT_DATA		0x0010
91 #define HC_HSTCF_INT_BLOCK		0x0100
92 #define HC_HSTCF_INT_BUSY		0x0400
93 
94 /* Flags for HC_DEBUG register */
95 #define HC_DBG_FIFO_THRESH_WRITE_SHIFT	9
96 #define HC_DBG_FIFO_THRESH_READ_SHIFT	14
97 #define HC_DBG_FIFO_THRESH_MASK		0x001f
98 #define HC_DBG_FSM_MASK			0xf
99 #define HC_DBG_FSM_IDENTMODE		0x0
100 #define HC_DBG_FSM_DATAMODE		0x1
101 #define HC_DBG_FSM_READDATA		0x2
102 #define HC_DBG_FSM_WRITEDATA		0x3
103 #define HC_DBG_FSM_READWAIT		0x4
104 #define HC_DBG_FSM_READCRC		0x5
105 #define HC_DBG_FSM_WRITECRC		0x6
106 #define HC_DBG_FSM_WRITEWAIT1		0x7
107 #define HC_DBG_FSM_POWERDOWN		0x8
108 #define HC_DBG_FSM_POWERUP		0x9
109 #define HC_DBG_FSM_WRITESTART1		0xa
110 #define HC_DBG_FSM_WRITESTART2		0xb
111 #define HC_DBG_FSM_GENPULSES		0xc
112 #define HC_DBG_FSM_WRITEWAIT2		0xd
113 #define HC_DBG_FSM_STARTPOWDOWN		0xf
114 #define HC_DBG_FORCE_DATA_MODE		0x40000
115 
116 /* Settings */
117 #define HC_FIFO_SIZE			16
118 #define HC_FIFO_THRESH_READ		4
119 #define HC_FIFO_THRESH_WRITE		4
120 
121 #define HC_TIMEOUT_DEFAULT		0x00f00000
122 #define HC_TIMEOUT_IDLE			0x00a00000
123 
124 #endif  /* RPI3_SDHOST_H */
125