1 | /*===============================================================*\ |
---|
2 | | Project: RTEMS MBX8xx PCMCIA IDE harddisc driver | |
---|
3 | +-----------------------------------------------------------------+ |
---|
4 | | File: pcmcia_ide.c | |
---|
5 | +-----------------------------------------------------------------+ |
---|
6 | | Copyright (c) 2003 IMD | |
---|
7 | | Ingenieurbuero fuer Microcomputertechnik Th. Doerfler | |
---|
8 | | <Thomas.Doerfler@imd-systems.de> | |
---|
9 | | all rights reserved | |
---|
10 | +-----------------------------------------------------------------+ |
---|
11 | | this file contains the BSP layer for PCMCIA IDE access below the| |
---|
12 | | libchip IDE harddisc driver | |
---|
13 | | based on a board specific driver from | |
---|
14 | | Eugeny S. Mints, Oktet | |
---|
15 | | | |
---|
16 | | The license and distribution terms for this file may be | |
---|
17 | | found in the file LICENSE in this distribution or at | |
---|
18 | | http://www.rtems.com/license/LICENSE. | |
---|
19 | | | |
---|
20 | +-----------------------------------------------------------------+ |
---|
21 | | date history ID | |
---|
22 | | ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ | |
---|
23 | | 01.14.03 creation doe | |
---|
24 | \*===============================================================*/ |
---|
25 | |
---|
26 | #include <rtems.h> |
---|
27 | #include <bsp.h> |
---|
28 | #include <bsp/mbx.h> |
---|
29 | #include <mpc8xx.h> |
---|
30 | #include <libchip/ide_ctrl.h> |
---|
31 | #include <libchip/ide_ctrl_cfg.h> |
---|
32 | #include <libchip/ide_ctrl_io.h> |
---|
33 | |
---|
34 | /* #define DATAREG_16BIT */ /* 16 bit mode not yet working */ |
---|
35 | /* #define DEBUG_OUT */ |
---|
36 | /* |
---|
37 | * support functions for PCMCIA IDE IF |
---|
38 | */ |
---|
39 | /*=========================================================================*\ |
---|
40 | | Function: | |
---|
41 | \*-------------------------------------------------------------------------*/ |
---|
42 | boolean mbx8xx_pcmciaide_probe |
---|
43 | ( |
---|
44 | /*-------------------------------------------------------------------------*\ |
---|
45 | | Purpose: | |
---|
46 | | This function should probe, whether a PCMCIA flash disk is available | |
---|
47 | +---------------------------------------------------------------------------+ |
---|
48 | | Input Parameters: | |
---|
49 | \*-------------------------------------------------------------------------*/ |
---|
50 | int minor |
---|
51 | ) |
---|
52 | /*-------------------------------------------------------------------------*\ |
---|
53 | | Return Value: | |
---|
54 | | TRUE, when flash disk available | |
---|
55 | \*=========================================================================*/ |
---|
56 | { |
---|
57 | boolean ide_card_plugged = TRUE; /* assume: we have a card plugged in */ |
---|
58 | |
---|
59 | /* |
---|
60 | * check, that the CD# pins are low -> a PCMCIA card is plugged in |
---|
61 | */ |
---|
62 | if ((m8xx.pipr |
---|
63 | & (M8xx_PCMCIA_PIPR_CACD1 | M8xx_PCMCIA_PIPR_CACD2)) != 0x00) { |
---|
64 | ide_card_plugged = FALSE; |
---|
65 | } |
---|
66 | /* |
---|
67 | * set supply voltage to 3.3V |
---|
68 | * FIXME: this should be depending on state of VS1/2 pins |
---|
69 | * FIXME: there should be a shadow variable for the BSP for CSR2 access |
---|
70 | */ |
---|
71 | *((volatile uint8_t*)MBX_CSR2) = 0xb0; |
---|
72 | /* |
---|
73 | * check card information service whether card is a ATA like disk |
---|
74 | * -> scan for tuple of type 0x21 with content 0x04 0xXX (fixed disk) |
---|
75 | * -> scan for tuple of type 0x22 with content 0x01 0x01 |
---|
76 | */ |
---|
77 | if (ide_card_plugged) { |
---|
78 | #define CIS_BYTE(pos) (((uint8_t*)PCMCIA_ATTRB_ADDR)[(pos)*2]) |
---|
79 | int cis_pos = 0; |
---|
80 | boolean fixed_disk_tuple_found = FALSE; |
---|
81 | boolean ata_disk_tuple_found = FALSE; |
---|
82 | |
---|
83 | while ((cis_pos < 256) && |
---|
84 | (CIS_BYTE(cis_pos) != 0xff) && |
---|
85 | (!fixed_disk_tuple_found || !ata_disk_tuple_found)) { |
---|
86 | /* |
---|
87 | * check for neede tuples |
---|
88 | */ |
---|
89 | if ((CIS_BYTE(cis_pos ) == 0x21) && |
---|
90 | (CIS_BYTE(cis_pos+2) == 0x04)) { |
---|
91 | fixed_disk_tuple_found = TRUE; |
---|
92 | } |
---|
93 | else if ((CIS_BYTE(cis_pos ) == 0x22) && |
---|
94 | (CIS_BYTE(cis_pos+2) == 0x01) && |
---|
95 | (CIS_BYTE(cis_pos+3) == 0x01)) { |
---|
96 | ata_disk_tuple_found = TRUE; |
---|
97 | } |
---|
98 | /* |
---|
99 | * advance using the length field |
---|
100 | */ |
---|
101 | cis_pos += CIS_BYTE(cis_pos+1)+2; |
---|
102 | } |
---|
103 | ide_card_plugged = fixed_disk_tuple_found && ata_disk_tuple_found; |
---|
104 | } |
---|
105 | return ide_card_plugged; |
---|
106 | } |
---|
107 | |
---|
108 | /*=========================================================================*\ |
---|
109 | | Function: | |
---|
110 | \*-------------------------------------------------------------------------*/ |
---|
111 | void mbx8xx_pcmciaide_initialize |
---|
112 | ( |
---|
113 | /*-------------------------------------------------------------------------*\ |
---|
114 | | Purpose: | |
---|
115 | | initialize PCMCIA IDE flash card access | |
---|
116 | +---------------------------------------------------------------------------+ |
---|
117 | | Input Parameters: | |
---|
118 | \*-------------------------------------------------------------------------*/ |
---|
119 | int minor /* controller minor number */ |
---|
120 | ) |
---|
121 | /*-------------------------------------------------------------------------*\ |
---|
122 | | Return Value: | |
---|
123 | | <none> | |
---|
124 | \*=========================================================================*/ |
---|
125 | { |
---|
126 | /* |
---|
127 | * FIXME: enable interrupts, if needed |
---|
128 | */ |
---|
129 | /* |
---|
130 | * FIXME: set programming voltage as requested |
---|
131 | */ |
---|
132 | } |
---|
133 | |
---|
134 | /*=========================================================================*\ |
---|
135 | | Function: | |
---|
136 | \*-------------------------------------------------------------------------*/ |
---|
137 | void mbx8xx_pcmciaide_read_reg |
---|
138 | ( |
---|
139 | /*-------------------------------------------------------------------------*\ |
---|
140 | | Purpose: | |
---|
141 | | read a PCMCIA IDE controller register | |
---|
142 | +---------------------------------------------------------------------------+ |
---|
143 | | Input Parameters: | |
---|
144 | \*-------------------------------------------------------------------------*/ |
---|
145 | int minor, /* controller minor number */ |
---|
146 | int reg, /* register index to access */ |
---|
147 | uint16_t *value /* ptr to return value location */ |
---|
148 | ) |
---|
149 | /*-------------------------------------------------------------------------*\ |
---|
150 | | Return Value: | |
---|
151 | | <none> | |
---|
152 | \*=========================================================================*/ |
---|
153 | { |
---|
154 | uint32_t port = IDE_Controller_Table[minor].port1; |
---|
155 | |
---|
156 | if (reg == IDE_REGISTER_DATA_WORD) { |
---|
157 | #ifdef DATAREG_16BIT |
---|
158 | *value = *(volatile uint16_t*)(port+reg); |
---|
159 | #else |
---|
160 | *value = ((*(volatile uint8_t*)(port+reg) << 8) + |
---|
161 | (*(volatile uint8_t*)(port+reg+1) )); |
---|
162 | #endif |
---|
163 | } |
---|
164 | else { |
---|
165 | *value = *(volatile uint8_t*)(port+reg); |
---|
166 | } |
---|
167 | #ifdef DEBUG_OUT |
---|
168 | printk("mbx8xx_pcmciaide_read_reg(0x%x)=0x%x\r\n",reg,*value & 0xff); |
---|
169 | #endif |
---|
170 | } |
---|
171 | |
---|
172 | /*=========================================================================*\ |
---|
173 | | Function: | |
---|
174 | \*-------------------------------------------------------------------------*/ |
---|
175 | void mbx8xx_pcmciaide_write_reg |
---|
176 | ( |
---|
177 | /*-------------------------------------------------------------------------*\ |
---|
178 | | Purpose: | |
---|
179 | | write a PCMCIA IDE controller register | |
---|
180 | +---------------------------------------------------------------------------+ |
---|
181 | | Input Parameters: | |
---|
182 | \*-------------------------------------------------------------------------*/ |
---|
183 | int minor, /* controller minor number */ |
---|
184 | int reg, /* register index to access */ |
---|
185 | uint16_t value /* value to write */ |
---|
186 | ) |
---|
187 | /*-------------------------------------------------------------------------*\ |
---|
188 | | Return Value: | |
---|
189 | | <none> | |
---|
190 | \*=========================================================================*/ |
---|
191 | { |
---|
192 | uint32_t port = IDE_Controller_Table[minor].port1; |
---|
193 | |
---|
194 | #ifdef DEBUG_OUT |
---|
195 | printk("mbx8xx_pcmciaide_write_reg(0x%x,0x%x)\r\n",reg,value & 0xff); |
---|
196 | #endif |
---|
197 | if (reg == IDE_REGISTER_DATA_WORD) { |
---|
198 | #ifdef DATAREG_16BIT |
---|
199 | *(volatile uint16_t*)(port+reg) = value; |
---|
200 | #else |
---|
201 | *(volatile uint8_t*)(port+reg) = value >> 8; |
---|
202 | *(volatile uint8_t*)(port+reg+1) = value; |
---|
203 | #endif |
---|
204 | } |
---|
205 | else { |
---|
206 | *(volatile uint8_t*)(port+reg)= value; |
---|
207 | } |
---|
208 | } |
---|
209 | |
---|
210 | /*=========================================================================*\ |
---|
211 | | Function: | |
---|
212 | \*-------------------------------------------------------------------------*/ |
---|
213 | void mbx8xx_pcmciaide_read_block |
---|
214 | ( |
---|
215 | /*-------------------------------------------------------------------------*\ |
---|
216 | | Purpose: | |
---|
217 | | read a PCMCIA IDE controller register | |
---|
218 | +---------------------------------------------------------------------------+ |
---|
219 | | Input Parameters: | |
---|
220 | \*-------------------------------------------------------------------------*/ |
---|
221 | int minor, |
---|
222 | uint16_t block_size, |
---|
223 | blkdev_sg_buffer *bufs, |
---|
224 | uint32_t *cbuf, |
---|
225 | uint32_t *pos |
---|
226 | ) |
---|
227 | /*-------------------------------------------------------------------------*\ |
---|
228 | | Return Value: | |
---|
229 | | <none> | |
---|
230 | \*=========================================================================*/ |
---|
231 | { |
---|
232 | uint32_t port = IDE_Controller_Table[minor].port1; |
---|
233 | uint16_t cnt = 0; |
---|
234 | #ifdef DEBUG_OUT |
---|
235 | printk("mbx8xx_pcmciaide_read_block()\r\n"); |
---|
236 | #endif |
---|
237 | #ifdef DATAREG_16BIT |
---|
238 | uint16_t *lbuf = (uint16_t*) |
---|
239 | ((uint8_t*)(bufs[(*cbuf)].buffer) + (*pos)); |
---|
240 | #else |
---|
241 | uint8_t *lbuf = (uint8_t*) |
---|
242 | ((uint8_t*)(bufs[(*cbuf)].buffer) + (*pos)); |
---|
243 | #endif |
---|
244 | uint32_t llength = bufs[(*cbuf)].length; |
---|
245 | |
---|
246 | while (((*(volatile uint8_t*)(port+IDE_REGISTER_STATUS)) |
---|
247 | & IDE_REGISTER_STATUS_DRQ) && |
---|
248 | (cnt < block_size)) { |
---|
249 | #ifdef DATAREG_16BIT |
---|
250 | *lbuf++ = *(volatile uint16_t*)(port+8); /* 16 bit data port */ |
---|
251 | cnt += 2; |
---|
252 | (*pos) += 2; |
---|
253 | #else |
---|
254 | *lbuf++ = *(volatile uint8_t*)(port+IDE_REGISTER_DATA); |
---|
255 | cnt += 1; |
---|
256 | (*pos) += 1; |
---|
257 | #endif |
---|
258 | if ((*pos) == llength) { |
---|
259 | (*pos) = 0; |
---|
260 | (*cbuf)++; |
---|
261 | lbuf = bufs[(*cbuf)].buffer; |
---|
262 | llength = bufs[(*cbuf)].length; |
---|
263 | } |
---|
264 | } |
---|
265 | } |
---|
266 | |
---|
267 | /*=========================================================================*\ |
---|
268 | | Function: | |
---|
269 | \*-------------------------------------------------------------------------*/ |
---|
270 | void mbx8xx_pcmciaide_write_block |
---|
271 | ( |
---|
272 | /*-------------------------------------------------------------------------*\ |
---|
273 | | Purpose: | |
---|
274 | | write a PCMCIA IDE controller register | |
---|
275 | +---------------------------------------------------------------------------+ |
---|
276 | | Input Parameters: | |
---|
277 | \*-------------------------------------------------------------------------*/ |
---|
278 | int minor, |
---|
279 | uint16_t block_size, |
---|
280 | blkdev_sg_buffer *bufs, |
---|
281 | uint32_t *cbuf, |
---|
282 | uint32_t *pos |
---|
283 | ) |
---|
284 | /*-------------------------------------------------------------------------*\ |
---|
285 | | Return Value: | |
---|
286 | | <none> | |
---|
287 | \*=========================================================================*/ |
---|
288 | { |
---|
289 | uint32_t port = IDE_Controller_Table[minor].port1; |
---|
290 | uint16_t cnt = 0; |
---|
291 | |
---|
292 | #ifdef DEBUG_OUT |
---|
293 | printk("mbx8xx_pcmciaide_write_block()\r\n"); |
---|
294 | #endif |
---|
295 | #ifdef DATA_REG_16BIT |
---|
296 | uint16_t *lbuf = (uint16_t*) |
---|
297 | ((uint8_t*)(bufs[(*cbuf)].buffer) + (*pos)); |
---|
298 | #else |
---|
299 | uint8_t *lbuf = (uint8_t*) |
---|
300 | ((uint8_t*)(bufs[(*cbuf)].buffer) + (*pos)); |
---|
301 | #endif |
---|
302 | uint32_t llength = bufs[(*cbuf)].length; |
---|
303 | |
---|
304 | while (((*(volatile uint8_t*)(port+IDE_REGISTER_STATUS)) |
---|
305 | & IDE_REGISTER_STATUS_DRQ) && |
---|
306 | (cnt < block_size)) { |
---|
307 | #ifdef DATAREG_16BIT |
---|
308 | *(volatile uint16_t*)(port+8) = *lbuf++; /* 16 bit data port */ |
---|
309 | cnt += 2; |
---|
310 | (*pos) += 2; |
---|
311 | #else |
---|
312 | *(volatile uint8_t*)(port+IDE_REGISTER_DATA) = *lbuf++; |
---|
313 | cnt += 1; |
---|
314 | (*pos) += 1; |
---|
315 | #endif |
---|
316 | if ((*pos) == llength) { |
---|
317 | (*pos) = 0; |
---|
318 | (*cbuf)++; |
---|
319 | lbuf = bufs[(*cbuf)].buffer; |
---|
320 | llength = bufs[(*cbuf)].length; |
---|
321 | } |
---|
322 | } |
---|
323 | } |
---|
324 | |
---|
325 | /*=========================================================================*\ |
---|
326 | | Function: | |
---|
327 | \*-------------------------------------------------------------------------*/ |
---|
328 | int mbx8xx_pcmciaide_control |
---|
329 | ( |
---|
330 | /*-------------------------------------------------------------------------*\ |
---|
331 | | Purpose: | |
---|
332 | | control interface for controller | |
---|
333 | +---------------------------------------------------------------------------+ |
---|
334 | | Input Parameters: | |
---|
335 | \*-------------------------------------------------------------------------*/ |
---|
336 | int minor, /* controller minor number */ |
---|
337 | uint32_t cmd, /* command to send */ |
---|
338 | void * arg /* optional argument */ |
---|
339 | ) |
---|
340 | /*-------------------------------------------------------------------------*\ |
---|
341 | | Return Value: | |
---|
342 | | <none> | |
---|
343 | \*=========================================================================*/ |
---|
344 | { |
---|
345 | return 0; |
---|
346 | } |
---|
347 | |
---|
348 | /*=========================================================================*\ |
---|
349 | | Function: | |
---|
350 | \*-------------------------------------------------------------------------*/ |
---|
351 | rtems_status_code mbx8xx_pcmciaide_config_io_speed |
---|
352 | ( |
---|
353 | /*-------------------------------------------------------------------------*\ |
---|
354 | | Purpose: | |
---|
355 | | set up transfer speed, if possible | |
---|
356 | +---------------------------------------------------------------------------+ |
---|
357 | | Input Parameters: | |
---|
358 | \*-------------------------------------------------------------------------*/ |
---|
359 | int minor, /* controller minor number */ |
---|
360 | uint8_t modes_avail /* optional argument */ |
---|
361 | ) |
---|
362 | /*-------------------------------------------------------------------------*\ |
---|
363 | | Return Value: | |
---|
364 | | rtems_status_code | |
---|
365 | \*=========================================================================*/ |
---|
366 | { |
---|
367 | return RTEMS_SUCCESSFUL; |
---|
368 | } |
---|
369 | |
---|
370 | /* |
---|
371 | * The following table configures the functions used for IDE drivers |
---|
372 | * in this BSP. |
---|
373 | */ |
---|
374 | |
---|
375 | ide_ctrl_fns_t mbx8xx_pcmciaide_ctrl_fns = { |
---|
376 | mbx8xx_pcmciaide_probe, |
---|
377 | mbx8xx_pcmciaide_initialize, |
---|
378 | mbx8xx_pcmciaide_control, |
---|
379 | mbx8xx_pcmciaide_read_reg, |
---|
380 | mbx8xx_pcmciaide_write_reg, |
---|
381 | mbx8xx_pcmciaide_read_block, |
---|
382 | mbx8xx_pcmciaide_write_block, |
---|
383 | mbx8xx_pcmciaide_config_io_speed |
---|
384 | }; |
---|