1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19 #ifndef _SDMMCVAR_H_
20 #define _SDMMCVAR_H_
21
22 #include <sys/queue.h>
23
24 #include <scsi/scsi_all.h>
25 #include <scsi/scsiconf.h>
26
27 #include <dev/sdmmc/sdmmcchip.h>
28 #include <dev/sdmmc/sdmmcreg.h>
29
30 struct sdmmc_csd {
31 int csdver;
32 int mmcver;
33 int capacity;
34 int sector_size;
35 int read_bl_len;
36
37 };
38
39 struct sdmmc_cid {
40 int mid;
41 int oid;
42 char pnm[8];
43 int rev;
44 int psn;
45 int mdt;
46 };
47
48 typedef u_int32_t sdmmc_response[4];
49
50 struct sdmmc_softc;
51
52 struct sdmmc_task {
53 void (*func)(void *arg);
54 void *arg;
55 int onqueue;
56 struct sdmmc_softc *sc;
57 TAILQ_ENTRY(sdmmc_task) next;
58 };
59
60 #define sdmmc_init_task(xtask, xfunc, xarg) do { \
61 (xtask)->func = (xfunc); \
62 (xtask)->arg = (xarg); \
63 (xtask)->onqueue = 0; \
64 (xtask)->sc = NULL; \
65 } while (0)
66
67 #define sdmmc_task_pending(xtask) ((xtask)->onqueue)
68
69 struct sdmmc_command {
70 struct sdmmc_task c_task;
71 u_int16_t c_opcode;
72 u_int32_t c_arg;
73 sdmmc_response c_resp;
74 void *c_data;
75 int c_datalen;
76 int c_blklen;
77 int c_flags;
78 #define SCF_ITSDONE 0x0001
79 #define SCF_CMD(flags) ((flags) & 0x00f0)
80 #define SCF_CMD_AC 0x0000
81 #define SCF_CMD_ADTC 0x0010
82 #define SCF_CMD_BC 0x0020
83 #define SCF_CMD_BCR 0x0030
84 #define SCF_CMD_READ 0x0040
85 #define SCF_RSP_BSY 0x0100
86 #define SCF_RSP_136 0x0200
87 #define SCF_RSP_CRC 0x0400
88 #define SCF_RSP_IDX 0x0800
89 #define SCF_RSP_PRESENT 0x1000
90
91 #define SCF_RSP_R0 0
92 #define SCF_RSP_R1 (SCF_RSP_PRESENT|SCF_RSP_CRC|SCF_RSP_IDX)
93 #define SCF_RSP_R1B (SCF_RSP_PRESENT|SCF_RSP_CRC|SCF_RSP_IDX|SCF_RSP_BSY)
94 #define SCF_RSP_R2 (SCF_RSP_PRESENT|SCF_RSP_CRC|SCF_RSP_136)
95 #define SCF_RSP_R3 (SCF_RSP_PRESENT)
96 #define SCF_RSP_R4 (SCF_RSP_PRESENT)
97 #define SCF_RSP_R5 (SCF_RSP_PRESENT|SCF_RSP_CRC|SCF_RSP_IDX)
98 #define SCF_RSP_R5B (SCF_RSP_PRESENT|SCF_RSP_CRC|SCF_RSP_IDX|SCF_RSP_BSY)
99 #define SCF_RSP_R6 (SCF_RSP_PRESENT|SCF_RSP_CRC|SCF_RSP_IDX)
100 int c_error;
101
102
103 int c_resid;
104 u_char *c_buf;
105 };
106
107
108
109
110
111 struct sdmmc_cis {
112 u_int16_t manufacturer;
113 #define SDMMC_VENDOR_INVALID 0xffff
114 u_int16_t product;
115 #define SDMMC_PRODUCT_INVALID 0xffff
116 u_int8_t function;
117 #define SDMMC_FUNCTION_INVALID 0xff
118 u_char cis1_major;
119 u_char cis1_minor;
120 char cis1_info_buf[256];
121 char *cis1_info[4];
122 };
123
124
125
126
127
128
129
130
131 struct sdmmc_function {
132
133 struct sdmmc_softc *sc;
134 u_int16_t rca;
135 int flags;
136 #define SFF_ERROR 0x0001
137 SIMPLEQ_ENTRY(sdmmc_function) sf_list;
138
139 int number;
140 struct device *child;
141 struct sdmmc_cis cis;
142
143 struct sdmmc_csd csd;
144 struct sdmmc_cid cid;
145 sdmmc_response raw_cid;
146 };
147
148
149
150
151 struct sdmmc_softc {
152 struct device sc_dev;
153 #define SDMMCDEVNAME(sc) ((sc)->sc_dev.dv_xname)
154 sdmmc_chipset_tag_t sct;
155 sdmmc_chipset_handle_t sch;
156 int sc_flags;
157 #define SMF_SD_MODE 0x0001
158 #define SMF_IO_MODE 0x0002
159 #define SMF_MEM_MODE 0x0004
160 #define SMF_CARD_PRESENT 0x0010
161 #define SMF_CARD_ATTACHED 0x0020
162 int sc_function_count;
163 struct sdmmc_function *sc_card;
164 struct sdmmc_function *sc_fn0;
165 SIMPLEQ_HEAD(, sdmmc_function) sf_head;
166 int sc_dying;
167 struct proc *sc_task_thread;
168 TAILQ_HEAD(, sdmmc_task) sc_tskq;
169 struct sdmmc_task sc_discover_task;
170 struct sdmmc_task sc_intr_task;
171 struct lock sc_lock;
172 void *sc_scsibus;
173 TAILQ_HEAD(, sdmmc_intr_handler) sc_intrq;
174 };
175
176
177
178
179 struct sdmmc_attach_args {
180 struct scsi_link scsi_link;
181 struct sdmmc_function *sf;
182 };
183
184 #define IPL_SDMMC IPL_BIO
185 #define splsdmmc() splbio()
186
187 #define SDMMC_LOCK(sc) lockmgr(&(sc)->sc_lock, LK_EXCLUSIVE, NULL)
188 #define SDMMC_UNLOCK(sc) lockmgr(&(sc)->sc_lock, LK_RELEASE, NULL)
189
190 void sdmmc_add_task(struct sdmmc_softc *, struct sdmmc_task *);
191 void sdmmc_del_task(struct sdmmc_task *);
192
193 struct sdmmc_function *sdmmc_function_alloc(struct sdmmc_softc *);
194 void sdmmc_function_free(struct sdmmc_function *);
195 int sdmmc_set_bus_power(struct sdmmc_softc *, u_int32_t, u_int32_t);
196 int sdmmc_mmc_command(struct sdmmc_softc *, struct sdmmc_command *);
197 int sdmmc_app_command(struct sdmmc_softc *, struct sdmmc_command *);
198 void sdmmc_go_idle_state(struct sdmmc_softc *);
199 int sdmmc_select_card(struct sdmmc_softc *, struct sdmmc_function *);
200 int sdmmc_set_relative_addr(struct sdmmc_softc *,
201 struct sdmmc_function *);
202
203 void sdmmc_intr_enable(struct sdmmc_function *);
204 void sdmmc_intr_disable(struct sdmmc_function *);
205 void *sdmmc_intr_establish(struct device *, int (*)(void *),
206 void *, const char *);
207 void sdmmc_intr_disestablish(void *);
208 void sdmmc_intr_task(void *);
209
210 int sdmmc_io_enable(struct sdmmc_softc *);
211 void sdmmc_io_scan(struct sdmmc_softc *);
212 int sdmmc_io_init(struct sdmmc_softc *, struct sdmmc_function *);
213 void sdmmc_io_attach(struct sdmmc_softc *);
214 void sdmmc_io_detach(struct sdmmc_softc *);
215 u_int8_t sdmmc_io_read_1(struct sdmmc_function *, int);
216 u_int16_t sdmmc_io_read_2(struct sdmmc_function *, int);
217 u_int32_t sdmmc_io_read_4(struct sdmmc_function *, int);
218 int sdmmc_io_read_multi_1(struct sdmmc_function *, int, u_char *, int);
219 void sdmmc_io_write_1(struct sdmmc_function *, int, u_int8_t);
220 void sdmmc_io_write_2(struct sdmmc_function *, int, u_int16_t);
221 void sdmmc_io_write_4(struct sdmmc_function *, int, u_int32_t);
222 int sdmmc_io_write_multi_1(struct sdmmc_function *, int, u_char *, int);
223 int sdmmc_io_function_ready(struct sdmmc_function *);
224 int sdmmc_io_function_enable(struct sdmmc_function *);
225 void sdmmc_io_function_disable(struct sdmmc_function *);
226
227 int sdmmc_read_cis(struct sdmmc_function *, struct sdmmc_cis *);
228 void sdmmc_print_cis(struct sdmmc_function *);
229 void sdmmc_check_cis_quirks(struct sdmmc_function *);
230
231 int sdmmc_mem_enable(struct sdmmc_softc *);
232 void sdmmc_mem_scan(struct sdmmc_softc *);
233 int sdmmc_mem_init(struct sdmmc_softc *, struct sdmmc_function *);
234 int sdmmc_mem_read_block(struct sdmmc_function *, int, u_char *, size_t);
235 int sdmmc_mem_write_block(struct sdmmc_function *, int, u_char *, size_t);
236
237
238
239 #include <sys/ioccom.h>
240
241 struct bio_sdmmc_command {
242 void *cookie;
243 struct sdmmc_command cmd;
244 };
245
246 struct bio_sdmmc_debug {
247 void *cookie;
248 int debug;
249 };
250
251 #define SDIOCEXECMMC _IOWR('S',0, struct bio_sdmmc_command)
252 #define SDIOCEXECAPP _IOWR('S',1, struct bio_sdmmc_command)
253 #define SDIOCSETDEBUG _IOWR('S',2, struct bio_sdmmc_debug)
254
255 #endif