xref: /nrf52832-nimble/rt-thread/components/drivers/include/drivers/sdio.h (revision 104654410c56c573564690304ae786df310c91fc)
1 /*
2  * Copyright (c) 2006-2018, RT-Thread Development Team
3  *
4  * SPDX-License-Identifier: Apache-2.0
5  *
6  * Change Logs:
7  * Date           Author        Notes
8  * 2012-01-15     weety         first version
9  */
10 
11 #ifndef __SDIO_H__
12 #define __SDIO_H__
13 
14 #include <rtthread.h>
15 #include <drivers/mmcsd_host.h>
16 #include <drivers/mmcsd_card.h>
17 #include <drivers/sdio_func_ids.h>
18 
19 #ifdef __cplusplus
20 extern "C" {
21 #endif
22 
23 /*
24  * Card Common Control Registers (CCCR)
25  */
26 
27 #define SDIO_REG_CCCR_CCCR_REV      0x00
28 
29 #define  SDIO_CCCR_REV_1_00 0   /* CCCR/FBR Version 1.00 */
30 #define  SDIO_CCCR_REV_1_10 1   /* CCCR/FBR Version 1.10 */
31 #define  SDIO_CCCR_REV_1_20 2   /* CCCR/FBR Version 1.20 */
32 #define  SDIO_CCCR_REV_3_00 3   /* CCCR/FBR Version 2.00 */
33 
34 #define  SDIO_SDIO_REV_1_00 0   /* SDIO Spec Version 1.00 */
35 #define  SDIO_SDIO_REV_1_10 1   /* SDIO Spec Version 1.10 */
36 #define  SDIO_SDIO_REV_1_20 2   /* SDIO Spec Version 1.20 */
37 #define  SDIO_SDIO_REV_2_00 3   /* SDIO Spec Version 2.00 */
38 
39 #define SDIO_REG_CCCR_SD_REV        0x01
40 
41 #define  SDIO_SD_REV_1_01   0   /* SD Physical Spec Version 1.01 */
42 #define  SDIO_SD_REV_1_10   1   /* SD Physical Spec Version 1.10 */
43 #define  SDIO_SD_REV_2_00   2   /* SD Physical Spec Version 2.00 */
44 
45 #define SDIO_REG_CCCR_IO_EN         0x02
46 #define SDIO_REG_CCCR_IO_RDY        0x03
47 
48 #define SDIO_REG_CCCR_INT_EN        0x04    /* Function/Master Interrupt Enable */
49 #define SDIO_REG_CCCR_INT_PEND      0x05    /* Function Interrupt Pending */
50 
51 #define SDIO_REG_CCCR_IO_ABORT      0x06    /* function abort/card reset */
52 
53 #define SDIO_REG_CCCR_BUS_IF        0x07    /* bus interface controls */
54 
55 #define  SDIO_BUS_WIDTH_1BIT        0x00
56 #define  SDIO_BUS_WIDTH_4BIT        0x02
57 #define  SDIO_BUS_ECSI              0x20    /* Enable continuous SPI interrupt */
58 #define  SDIO_BUS_SCSI              0x40    /* Support continuous SPI interrupt */
59 
60 #define  SDIO_BUS_ASYNC_INT         0x20
61 
62 #define  SDIO_BUS_CD_DISABLE        0x80   /* disable pull-up on DAT3 (pin 1) */
63 
64 #define SDIO_REG_CCCR_CARD_CAPS     0x08
65 
66 #define  SDIO_CCCR_CAP_SDC  0x01    /* can do CMD52 while data transfer */
67 #define  SDIO_CCCR_CAP_SMB  0x02    /* can do multi-block xfers (CMD53) */
68 #define  SDIO_CCCR_CAP_SRW  0x04    /* supports read-wait protocol */
69 #define  SDIO_CCCR_CAP_SBS  0x08    /* supports suspend/resume */
70 #define  SDIO_CCCR_CAP_S4MI 0x10    /* interrupt during 4-bit CMD53 */
71 #define  SDIO_CCCR_CAP_E4MI 0x20    /* enable ints during 4-bit CMD53 */
72 #define  SDIO_CCCR_CAP_LSC  0x40    /* low speed card */
73 #define  SDIO_CCCR_CAP_4BLS 0x80    /* 4 bit low speed card */
74 
75 #define SDIO_REG_CCCR_CIS_PTR       0x09    /* common CIS pointer (3 bytes) */
76 
77 /* Following 4 regs are valid only if SBS is set */
78 #define SDIO_REG_CCCR_BUS_SUSPEND   0x0c
79 #define SDIO_REG_CCCR_FUNC_SEL      0x0d
80 #define SDIO_REG_CCCR_EXEC_FLAG     0x0e
81 #define SDIO_REG_CCCR_READY_FLAG    0x0f
82 
83 #define SDIO_REG_CCCR_FN0_BLKSIZE   0x10 /* 2bytes, 0x10~0x11 */
84 
85 #define SDIO_REG_CCCR_POWER_CTRL    0x12
86 
87 #define  SDIO_POWER_SMPC            0x01    /* Supports Master Power Control */
88 #define  SDIO_POWER_EMPC            0x02    /* Enable Master Power Control */
89 
90 #define SDIO_REG_CCCR_SPEED         0x13
91 
92 #define  SDIO_SPEED_SHS             0x01    /* Supports High-Speed mode */
93 #define  SDIO_SPEED_EHS             0x02    /* Enable High-Speed mode */
94 
95 /*
96  * Function Basic Registers (FBR)
97  */
98 
99 #define SDIO_REG_FBR_BASE(f)    ((f) * 0x100) /* base of function f's FBRs */
100 
101 #define SDIO_REG_FBR_STD_FUNC_IF    0x00
102 
103 #define  SDIO_FBR_SUPPORTS_CSA      0x40    /* supports Code Storage Area */
104 #define  SDIO_FBR_ENABLE_CSA        0x80    /* enable Code Storage Area */
105 
106 #define SDIO_REG_FBR_STD_IF_EXT     0x01
107 
108 #define SDIO_REG_FBR_POWER          0x02
109 
110 #define  SDIO_FBR_POWER_SPS         0x01    /* Supports Power Selection */
111 #define  SDIO_FBR_POWER_EPS         0x02    /* Enable (low) Power Selection */
112 
113 #define SDIO_REG_FBR_CIS            0x09    /* CIS pointer (3 bytes) */
114 
115 
116 #define SDIO_REG_FBR_CSA            0x0C    /* CSA pointer (3 bytes) */
117 
118 #define SDIO_REG_FBR_CSA_DATA       0x0F
119 
120 #define SDIO_REG_FBR_BLKSIZE        0x10    /* block size (2 bytes) */
121 
122 /* SDIO CIS Tuple code */
123 #define CISTPL_NULL      0x00
124 #define CISTPL_CHECKSUM  0x10
125 #define CISTPL_VERS_1    0x15
126 #define CISTPL_ALTSTR    0x16
127 #define CISTPL_MANFID    0x20
128 #define CISTPL_FUNCID    0x21
129 #define CISTPL_FUNCE     0x22
130 #define CISTPL_SDIO_STD  0x91
131 #define CISTPL_SDIO_EXT  0x92
132 #define CISTPL_END       0xff
133 
134 /* SDIO device id */
135 #define SDIO_ANY_FUNC_ID    0xff
136 #define SDIO_ANY_MAN_ID     0xffff
137 #define SDIO_ANY_PROD_ID    0xffff
138 
139 struct rt_sdio_device_id
140 {
141     rt_uint8_t   func_code;
142     rt_uint16_t  manufacturer;
143     rt_uint16_t  product;
144 };
145 
146 struct rt_sdio_driver
147 {
148     char *name;
149     rt_int32_t (*probe)(struct rt_mmcsd_card *card);
150     rt_int32_t (*remove)(struct rt_mmcsd_card *card);
151     struct rt_sdio_device_id *id;
152 };
153 
154 rt_int32_t sdio_io_send_op_cond(struct rt_mmcsd_host *host,
155                                 rt_uint32_t           ocr,
156                                 rt_uint32_t          *cmd5_resp);
157 rt_int32_t sdio_io_rw_direct(struct rt_mmcsd_card *card,
158                              rt_int32_t            rw,
159                              rt_uint32_t           fn,
160                              rt_uint32_t           reg_addr,
161                              rt_uint8_t           *pdata,
162                              rt_uint8_t            raw);
163 rt_int32_t sdio_io_rw_extended(struct rt_mmcsd_card *card,
164                                rt_int32_t            rw,
165                                rt_uint32_t           fn,
166                                rt_uint32_t           addr,
167                                rt_int32_t            op_code,
168                                rt_uint8_t           *buf,
169                                rt_uint32_t           blocks,
170                                rt_uint32_t           blksize);
171 rt_int32_t sdio_io_rw_extended_block(struct rt_sdio_function *func,
172                               rt_int32_t               rw,
173                               rt_uint32_t              addr,
174                               rt_int32_t               op_code,
175                               rt_uint8_t              *buf,
176                               rt_uint32_t              len);
177 rt_uint8_t sdio_io_readb(struct rt_sdio_function *func,
178                          rt_uint32_t              reg,
179                          rt_int32_t              *err);
180 rt_int32_t sdio_io_writeb(struct rt_sdio_function *func,
181                           rt_uint32_t              reg,
182                           rt_uint8_t               data);
183 rt_uint16_t sdio_io_readw(struct rt_sdio_function *func,
184                           rt_uint32_t              addr,
185                           rt_int32_t              *err);
186 rt_int32_t sdio_io_writew(struct rt_sdio_function *func,
187                           rt_uint16_t              data,
188                           rt_uint32_t              addr);
189 rt_uint32_t sdio_io_readl(struct rt_sdio_function *func,
190                           rt_uint32_t              addr,
191                           rt_int32_t              *err);
192 rt_int32_t sdio_io_writel(struct rt_sdio_function *func,
193                           rt_uint32_t              data,
194                           rt_uint32_t              addr);
195 rt_int32_t sdio_io_read_multi_fifo_b(struct rt_sdio_function *func,
196                                      rt_uint32_t              addr,
197                                      rt_uint8_t              *buf,
198                                      rt_uint32_t              len);
199 rt_int32_t sdio_io_write_multi_fifo_b(struct rt_sdio_function *func,
200                                       rt_uint32_t              addr,
201                                       rt_uint8_t              *buf,
202                                       rt_uint32_t              len);
203 rt_int32_t sdio_io_read_multi_incr_b(struct rt_sdio_function *func,
204                                      rt_uint32_t              addr,
205                                      rt_uint8_t              *buf,
206                                      rt_uint32_t              len);
207 rt_int32_t sdio_io_write_multi_incr_b(struct rt_sdio_function *func,
208                                       rt_uint32_t              addr,
209                                       rt_uint8_t              *buf,
210                                       rt_uint32_t              len);
211 rt_int32_t init_sdio(struct rt_mmcsd_host *host, rt_uint32_t ocr);
212 rt_int32_t sdio_attach_irq(struct rt_sdio_function *func,
213                            rt_sdio_irq_handler_t   *handler);
214 rt_int32_t sdio_detach_irq(struct rt_sdio_function *func);
215 void sdio_irq_wakeup(struct rt_mmcsd_host *host);
216 rt_int32_t sdio_enable_func(struct rt_sdio_function *func);
217 rt_int32_t sdio_disable_func(struct rt_sdio_function *func);
218 void sdio_set_drvdata(struct rt_sdio_function *func, void *data);
219 void* sdio_get_drvdata(struct rt_sdio_function *func);
220 rt_int32_t sdio_set_block_size(struct rt_sdio_function *func,
221                                rt_uint32_t              blksize);
222 rt_int32_t sdio_register_driver(struct rt_sdio_driver *driver);
223 rt_int32_t sdio_unregister_driver(struct rt_sdio_driver *driver);
224 void rt_sdio_init(void);
225 
226 #ifdef __cplusplus
227 }
228 #endif
229 
230 #endif
231 
232