diff options
author | Frank Gevaerts <frank@gevaerts.be> | 2009-07-17 22:28:49 +0000 |
---|---|---|
committer | Frank Gevaerts <frank@gevaerts.be> | 2009-07-17 22:28:49 +0000 |
commit | c0a5a67387c4eec3db3bad4da77ba5126faf03c4 (patch) | |
tree | d7e61f6287c5fcdce903489b6b72d474225b98a7 /firmware/storage.c | |
parent | bb3b57f64594ba517e06add4cfeff72b2b06e65b (diff) | |
download | rockbox-c0a5a67387c4eec3db3bad4da77ba5126faf03c4.tar.gz rockbox-c0a5a67387c4eec3db3bad4da77ba5126faf03c4.zip |
Commit FS#9545, storage cleanup and multi-driver support
git-svn-id: svn://svn.rockbox.org/rockbox/trunk@21933 a1c6a512-1295-4272-9138-f99709370657
Diffstat (limited to 'firmware/storage.c')
-rw-r--r-- | firmware/storage.c | 545 |
1 files changed, 545 insertions, 0 deletions
diff --git a/firmware/storage.c b/firmware/storage.c new file mode 100644 index 0000000000..1528d03919 --- /dev/null +++ b/firmware/storage.c | |||
@@ -0,0 +1,545 @@ | |||
1 | /*************************************************************************** | ||
2 | * __________ __ ___. | ||
3 | * Open \______ \ ____ ____ | | _\_ |__ _______ ___ | ||
4 | * Source | _// _ \_/ ___\| |/ /| __ \ / _ \ \/ / | ||
5 | * Jukebox | | ( <_> ) \___| < | \_\ ( <_> > < < | ||
6 | * Firmware |____|_ /\____/ \___ >__|_ \|___ /\____/__/\_ \ | ||
7 | * \/ \/ \/ \/ \/ | ||
8 | * $Id: buffer.c 17847 2008-06-28 18:10:04Z bagder $ | ||
9 | * | ||
10 | * Copyright (C) 2008 by Frank Gevaerts | ||
11 | * | ||
12 | * This program is free software; you can redistribute it and/or | ||
13 | * modify it under the terms of the GNU General Public License | ||
14 | * as published by the Free Software Foundation; either version 2 | ||
15 | * of the License, or (at your option) any later version. | ||
16 | * | ||
17 | * This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY | ||
18 | * KIND, either express or implied. | ||
19 | * | ||
20 | ****************************************************************************/ | ||
21 | #include "storage.h" | ||
22 | |||
23 | #define DRIVER_MASK 0xff000000 | ||
24 | #define DRIVER_OFFSET 24 | ||
25 | #define DRIVE_MASK 0x00ff0000 | ||
26 | #define DRIVE_OFFSET 16 | ||
27 | #define PARTITION_MASK 0x0000ff00 | ||
28 | |||
29 | static unsigned int storage_drivers[NUM_DRIVES]; | ||
30 | static unsigned int num_drives; | ||
31 | |||
32 | int storage_num_drives(void) | ||
33 | { | ||
34 | return num_drives; | ||
35 | } | ||
36 | |||
37 | int storage_init(void) | ||
38 | { | ||
39 | int rc=0; | ||
40 | int i; | ||
41 | num_drives=0; | ||
42 | |||
43 | #if (CONFIG_STORAGE & STORAGE_ATA) | ||
44 | if ((rc=ata_init())) return rc; | ||
45 | |||
46 | int ata_drives = ata_num_drives(num_drives); | ||
47 | for (i=0; i<ata_drives; i++) | ||
48 | { | ||
49 | storage_drivers[num_drives++] = | ||
50 | (STORAGE_ATA<<DRIVER_OFFSET) | (i << DRIVE_OFFSET); | ||
51 | } | ||
52 | #endif | ||
53 | |||
54 | #if (CONFIG_STORAGE & STORAGE_MMC) | ||
55 | if ((rc=mmc_init())) return rc; | ||
56 | |||
57 | int mmc_drives = mmc_num_drives(num_drives); | ||
58 | for (i=0; i<mmc_drives ;i++) | ||
59 | { | ||
60 | storage_drivers[num_drives++] = | ||
61 | (STORAGE_MMC<<DRIVER_OFFSET) | (i << DRIVE_OFFSET); | ||
62 | } | ||
63 | #endif | ||
64 | |||
65 | #if (CONFIG_STORAGE & STORAGE_SD) | ||
66 | if ((rc=sd_init())) return rc; | ||
67 | |||
68 | int sd_drives = sd_num_drives(num_drives); | ||
69 | for (i=0; i<sd_drives; i++) | ||
70 | { | ||
71 | storage_drivers[num_drives++] = | ||
72 | (STORAGE_SD<<DRIVER_OFFSET) | (i << DRIVE_OFFSET); | ||
73 | } | ||
74 | #endif | ||
75 | |||
76 | #if (CONFIG_STORAGE & STORAGE_NAND) | ||
77 | if ((rc=nand_init())) return rc; | ||
78 | |||
79 | int nand_drives = nand_num_drives(num_drives); | ||
80 | for (i=0; i<nand_drives; i++) | ||
81 | { | ||
82 | storage_drivers[num_drives++] = | ||
83 | (STORAGE_NAND<<DRIVER_OFFSET) | (i << DRIVE_OFFSET); | ||
84 | } | ||
85 | #endif | ||
86 | |||
87 | #if (CONFIG_STORAGE & STORAGE_RAMDISK) | ||
88 | if ((rc=ramdisk_init())) return rc; | ||
89 | |||
90 | int ramdisk_drives = ramdisk_num_drives(num_drives); | ||
91 | for (i=0; i<ramdisk_drives; i++) | ||
92 | { | ||
93 | storage_drivers[num_drives++] = | ||
94 | (STORAGE_RAMDISK<<DRIVER_OFFSET) | (i << DRIVE_OFFSET); | ||
95 | } | ||
96 | #endif | ||
97 | |||
98 | return 0; | ||
99 | } | ||
100 | |||
101 | int storage_read_sectors(int drive, unsigned long start, int count, | ||
102 | void* buf) | ||
103 | { | ||
104 | int driver=(storage_drivers[drive] & DRIVER_MASK)>>DRIVER_OFFSET; | ||
105 | int ldrive=(storage_drivers[drive] & DRIVE_MASK)>>DRIVE_OFFSET; | ||
106 | |||
107 | switch (driver) | ||
108 | { | ||
109 | #if (CONFIG_STORAGE & STORAGE_ATA) | ||
110 | case STORAGE_ATA: | ||
111 | return ata_read_sectors(ldrive,start,count,buf); | ||
112 | #endif | ||
113 | |||
114 | #if (CONFIG_STORAGE & STORAGE_MMC) | ||
115 | case STORAGE_MMC: | ||
116 | return mmc_read_sectors(ldrive,start,count,buf); | ||
117 | #endif | ||
118 | |||
119 | #if (CONFIG_STORAGE & STORAGE_SD) | ||
120 | case STORAGE_SD: | ||
121 | return sd_read_sectors(ldrive,start,count,buf); | ||
122 | #endif | ||
123 | |||
124 | #if (CONFIG_STORAGE & STORAGE_NAND) | ||
125 | case STORAGE_NAND: | ||
126 | return nand_read_sectors(ldrive,start,count,buf); | ||
127 | #endif | ||
128 | |||
129 | #if (CONFIG_STORAGE & STORAGE_RAMDISK) | ||
130 | case STORAGE_RAMDISK: | ||
131 | return ramdisk_read_sectors(ldrive,start,count,buf); | ||
132 | #endif | ||
133 | } | ||
134 | |||
135 | return -1; | ||
136 | } | ||
137 | |||
138 | int storage_write_sectors(int drive, unsigned long start, int count, | ||
139 | const void* buf) | ||
140 | { | ||
141 | int driver=(storage_drivers[drive] & DRIVER_MASK)>>DRIVER_OFFSET; | ||
142 | int ldrive=(storage_drivers[drive] & DRIVE_MASK)>>DRIVE_OFFSET; | ||
143 | |||
144 | switch (driver) | ||
145 | { | ||
146 | #if (CONFIG_STORAGE & STORAGE_ATA) | ||
147 | case STORAGE_ATA: | ||
148 | return ata_write_sectors(ldrive,start,count,buf); | ||
149 | #endif | ||
150 | |||
151 | #if (CONFIG_STORAGE & STORAGE_MMC) | ||
152 | case STORAGE_MMC: | ||
153 | return mmc_write_sectors(ldrive,start,count,buf); | ||
154 | #endif | ||
155 | |||
156 | #if (CONFIG_STORAGE & STORAGE_SD) | ||
157 | case STORAGE_SD: | ||
158 | return sd_write_sectors(ldrive,start,count,buf); | ||
159 | #endif | ||
160 | |||
161 | #if (CONFIG_STORAGE & STORAGE_NAND) | ||
162 | case STORAGE_NAND: | ||
163 | return nand_write_sectors(ldrive,start,count,buf); | ||
164 | #endif | ||
165 | |||
166 | #if (CONFIG_STORAGE & STORAGE_RAMDISK) | ||
167 | case STORAGE_RAMDISK: | ||
168 | return ramdisk_write_sectors(ldrive,start,count,buf); | ||
169 | #endif | ||
170 | } | ||
171 | |||
172 | return -1; | ||
173 | } | ||
174 | |||
175 | void storage_enable(bool on) | ||
176 | { | ||
177 | #if (CONFIG_STORAGE & STORAGE_ATA) | ||
178 | ata_enable(on); | ||
179 | #endif | ||
180 | |||
181 | #if (CONFIG_STORAGE & STORAGE_MMC) | ||
182 | mmc_enable(on); | ||
183 | #endif | ||
184 | |||
185 | #if (CONFIG_STORAGE & STORAGE_SD) | ||
186 | sd_enable(on); | ||
187 | #endif | ||
188 | |||
189 | #if (CONFIG_STORAGE & STORAGE_NAND) | ||
190 | nand_enable(on); | ||
191 | #endif | ||
192 | |||
193 | #if (CONFIG_STORAGE & STORAGE_RAMDISK) | ||
194 | ramdisk_enable(on); | ||
195 | #endif | ||
196 | } | ||
197 | |||
198 | void storage_sleep(void) | ||
199 | { | ||
200 | #if (CONFIG_STORAGE & STORAGE_ATA) | ||
201 | ata_sleep(); | ||
202 | #endif | ||
203 | |||
204 | #if (CONFIG_STORAGE & STORAGE_MMC) | ||
205 | mmc_sleep(); | ||
206 | #endif | ||
207 | |||
208 | #if (CONFIG_STORAGE & STORAGE_SD) | ||
209 | sd_sleep(); | ||
210 | #endif | ||
211 | |||
212 | #if (CONFIG_STORAGE & STORAGE_NAND) | ||
213 | nand_sleep(); | ||
214 | #endif | ||
215 | |||
216 | #if (CONFIG_STORAGE & STORAGE_RAMDISK) | ||
217 | ramdisk_sleep(); | ||
218 | #endif | ||
219 | } | ||
220 | |||
221 | void storage_sleepnow(void) | ||
222 | { | ||
223 | #if (CONFIG_STORAGE & STORAGE_ATA) | ||
224 | ata_sleepnow(); | ||
225 | #endif | ||
226 | |||
227 | #if (CONFIG_STORAGE & STORAGE_MMC) | ||
228 | mmc_sleepnow(); | ||
229 | #endif | ||
230 | |||
231 | #if (CONFIG_STORAGE & STORAGE_SD) | ||
232 | //sd_sleepnow(); | ||
233 | #endif | ||
234 | |||
235 | #if (CONFIG_STORAGE & STORAGE_NAND) | ||
236 | nand_sleepnow(); | ||
237 | #endif | ||
238 | |||
239 | #if (CONFIG_STORAGE & STORAGE_RAMDISK) | ||
240 | ramdisk_sleepnow(); | ||
241 | #endif | ||
242 | } | ||
243 | |||
244 | bool storage_disk_is_active(void) | ||
245 | { | ||
246 | #if (CONFIG_STORAGE & STORAGE_ATA) | ||
247 | if (ata_disk_is_active()) return true; | ||
248 | #endif | ||
249 | |||
250 | #if (CONFIG_STORAGE & STORAGE_MMC) | ||
251 | if (mmc_disk_is_active()) return true; | ||
252 | #endif | ||
253 | |||
254 | #if (CONFIG_STORAGE & STORAGE_SD) | ||
255 | //if (sd_disk_is_active()) return true; | ||
256 | #endif | ||
257 | |||
258 | #if (CONFIG_STORAGE & STORAGE_NAND) | ||
259 | if (nand_disk_is_active()) return true; | ||
260 | #endif | ||
261 | |||
262 | #if (CONFIG_STORAGE & STORAGE_RAMDISK) | ||
263 | if (ramdisk_disk_is_active()) return true; | ||
264 | #endif | ||
265 | |||
266 | return false; | ||
267 | } | ||
268 | |||
269 | int storage_soft_reset(void) | ||
270 | { | ||
271 | int rc=0; | ||
272 | |||
273 | #if (CONFIG_STORAGE & STORAGE_ATA) | ||
274 | if ((rc=ata_soft_reset())) return rc; | ||
275 | #endif | ||
276 | |||
277 | #if (CONFIG_STORAGE & STORAGE_MMC) | ||
278 | if ((rc=mmc_soft_reset())) return rc; | ||
279 | #endif | ||
280 | |||
281 | #if (CONFIG_STORAGE & STORAGE_SD) | ||
282 | //if ((rc=sd_soft_reset())) return rc; | ||
283 | #endif | ||
284 | |||
285 | #if (CONFIG_STORAGE & STORAGE_NAND) | ||
286 | if ((rc=nand_soft_reset())) return rc; | ||
287 | #endif | ||
288 | |||
289 | #if (CONFIG_STORAGE & STORAGE_RAMDISK) | ||
290 | if ((rc=ramdisk_soft_reset())) return rc; | ||
291 | #endif | ||
292 | |||
293 | return 0; | ||
294 | } | ||
295 | |||
296 | void storage_spin(void) | ||
297 | { | ||
298 | #if (CONFIG_STORAGE & STORAGE_ATA) | ||
299 | ata_spin(); | ||
300 | #endif | ||
301 | |||
302 | #if (CONFIG_STORAGE & STORAGE_MMC) | ||
303 | mmc_spin(); | ||
304 | #endif | ||
305 | |||
306 | #if (CONFIG_STORAGE & STORAGE_SD) | ||
307 | sd_spin(); | ||
308 | #endif | ||
309 | |||
310 | #if (CONFIG_STORAGE & STORAGE_NAND) | ||
311 | nand_spin(); | ||
312 | #endif | ||
313 | |||
314 | #if (CONFIG_STORAGE & STORAGE_RAMDISK) | ||
315 | ramdisk_spin(); | ||
316 | #endif | ||
317 | } | ||
318 | |||
319 | void storage_spindown(int seconds) | ||
320 | { | ||
321 | #if (CONFIG_STORAGE & STORAGE_ATA) | ||
322 | ata_spindown(seconds); | ||
323 | #endif | ||
324 | |||
325 | #if (CONFIG_STORAGE & STORAGE_MMC) | ||
326 | mmc_spindown(seconds); | ||
327 | #endif | ||
328 | |||
329 | #if (CONFIG_STORAGE & STORAGE_SD) | ||
330 | sd_spindown(seconds); | ||
331 | #endif | ||
332 | |||
333 | #if (CONFIG_STORAGE & STORAGE_NAND) | ||
334 | nand_spindown(seconds); | ||
335 | #endif | ||
336 | |||
337 | #if (CONFIG_STORAGE & STORAGE_RAMDISK) | ||
338 | ramdisk_spindown(seconds); | ||
339 | #endif | ||
340 | } | ||
341 | |||
342 | #if (CONFIG_LED == LED_REAL) | ||
343 | void storage_set_led_enabled(bool enabled) | ||
344 | { | ||
345 | #if (CONFIG_STORAGE & STORAGE_ATA) | ||
346 | ata_set_led_enabled(enabled); | ||
347 | #endif | ||
348 | |||
349 | #if (CONFIG_STORAGE & STORAGE_MMC) | ||
350 | mmc_set_led_enabled(enabled); | ||
351 | #endif | ||
352 | |||
353 | #if (CONFIG_STORAGE & STORAGE_SD) | ||
354 | sd_set_led_enabled(enabled); | ||
355 | #endif | ||
356 | |||
357 | #if (CONFIG_STORAGE & STORAGE_NAND) | ||
358 | nand_set_led_enabled(enabled); | ||
359 | #endif | ||
360 | |||
361 | #if (CONFIG_STORAGE & STORAGE_RAMDISK) | ||
362 | ramdisk_set_led_enabled(enabled); | ||
363 | #endif | ||
364 | } | ||
365 | #endif /* CONFIG_LED == LED_REAL */ | ||
366 | |||
367 | long storage_last_disk_activity(void) | ||
368 | { | ||
369 | long max=0; | ||
370 | long t; | ||
371 | |||
372 | #if (CONFIG_STORAGE & STORAGE_ATA) | ||
373 | t=ata_last_disk_activity(); | ||
374 | if (t>max) max=t; | ||
375 | #endif | ||
376 | |||
377 | #if (CONFIG_STORAGE & STORAGE_MMC) | ||
378 | t=mmc_last_disk_activity(); | ||
379 | if (t>max) max=t; | ||
380 | #endif | ||
381 | |||
382 | #if (CONFIG_STORAGE & STORAGE_SD) | ||
383 | t=sd_last_disk_activity(); | ||
384 | if (t>max) max=t; | ||
385 | #endif | ||
386 | |||
387 | #if (CONFIG_STORAGE & STORAGE_NAND) | ||
388 | t=nand_last_disk_activity(); | ||
389 | if (t>max) max=t; | ||
390 | #endif | ||
391 | |||
392 | #if (CONFIG_STORAGE & STORAGE_RAMDISK) | ||
393 | t=ramdisk_last_disk_activity(); | ||
394 | if (t>max) max=t; | ||
395 | #endif | ||
396 | |||
397 | return max; | ||
398 | } | ||
399 | |||
400 | int storage_spinup_time(void) | ||
401 | { | ||
402 | int max=0; | ||
403 | int t; | ||
404 | |||
405 | #if (CONFIG_STORAGE & STORAGE_ATA) | ||
406 | t=ata_spinup_time(); | ||
407 | if (t>max) max=t; | ||
408 | #endif | ||
409 | |||
410 | #if (CONFIG_STORAGE & STORAGE_MMC) | ||
411 | t=mmc_spinup_time(); | ||
412 | if (t>max) max=t; | ||
413 | #endif | ||
414 | |||
415 | #if (CONFIG_STORAGE & STORAGE_SD) | ||
416 | //t=sd_spinup_time(); | ||
417 | //if (t>max) max=t; | ||
418 | #endif | ||
419 | |||
420 | #if (CONFIG_STORAGE & STORAGE_NAND) | ||
421 | t=nand_spinup_time(); | ||
422 | if (t>max) max=t; | ||
423 | #endif | ||
424 | |||
425 | #if (CONFIG_STORAGE & STORAGE_RAMDISK) | ||
426 | t=ramdisk_spinup_time(); | ||
427 | if (t>max) max=t; | ||
428 | #endif | ||
429 | |||
430 | return max; | ||
431 | } | ||
432 | |||
433 | #ifdef STORAGE_GET_INFO | ||
434 | void storage_get_info(int drive, struct storage_info *info) | ||
435 | { | ||
436 | int driver=(storage_drivers[drive] & DRIVER_MASK)>>DRIVER_OFFSET; | ||
437 | int ldrive=(storage_drivers[drive] & DRIVE_MASK)>>DRIVE_OFFSET; | ||
438 | |||
439 | switch(driver) | ||
440 | { | ||
441 | #if (CONFIG_STORAGE & STORAGE_ATA) | ||
442 | case STORAGE_ATA: | ||
443 | return ata_get_info(ldrive,info); | ||
444 | #endif | ||
445 | |||
446 | #if (CONFIG_STORAGE & STORAGE_MMC) | ||
447 | case STORAGE_MMC: | ||
448 | return mmc_get_info(ldrive,info); | ||
449 | #endif | ||
450 | |||
451 | #if (CONFIG_STORAGE & STORAGE_SD) | ||
452 | case STORAGE_SD: | ||
453 | return sd_get_info(ldrive,info); | ||
454 | #endif | ||
455 | |||
456 | #if (CONFIG_STORAGE & STORAGE_NAND) | ||
457 | case STORAGE_NAND: | ||
458 | return nand_get_info(ldrive,info); | ||
459 | #endif | ||
460 | |||
461 | #if (CONFIG_STORAGE & STORAGE_RAMDISK) | ||
462 | case STORAGE_RAMDISK: | ||
463 | return ramdisk_get_info(ldrive,info); | ||
464 | #endif | ||
465 | } | ||
466 | } | ||
467 | #endif /* STORAGE_GET_INFO */ | ||
468 | |||
469 | #ifdef HAVE_HOTSWAP | ||
470 | bool storage_removable(int drive) | ||
471 | { | ||
472 | bool ret = false; | ||
473 | |||
474 | int driver=(storage_drivers[drive] & DRIVER_MASK)>>DRIVER_OFFSET; | ||
475 | int ldrive=(storage_drivers[drive] & DRIVE_MASK)>>DRIVE_OFFSET; | ||
476 | |||
477 | switch(driver) | ||
478 | { | ||
479 | #if (CONFIG_STORAGE & STORAGE_ATA) | ||
480 | case STORAGE_ATA: | ||
481 | ret = ata_removable(ldrive); | ||
482 | #endif | ||
483 | |||
484 | #if (CONFIG_STORAGE & STORAGE_MMC) | ||
485 | case STORAGE_MMC: | ||
486 | ret = mmc_removable(ldrive); | ||
487 | #endif | ||
488 | |||
489 | #if (CONFIG_STORAGE & STORAGE_SD) | ||
490 | case STORAGE_SD: | ||
491 | ret = sd_removable(ldrive); | ||
492 | #endif | ||
493 | |||
494 | #if (CONFIG_STORAGE & STORAGE_NAND) | ||
495 | case STORAGE_NAND: | ||
496 | ret = false; | ||
497 | #endif | ||
498 | |||
499 | #if (CONFIG_STORAGE & STORAGE_RAMDISK) | ||
500 | case STORAGE_RAMDISK: | ||
501 | ret = false; | ||
502 | #endif | ||
503 | } | ||
504 | |||
505 | return ret; | ||
506 | } | ||
507 | |||
508 | bool storage_present(int drive) | ||
509 | { | ||
510 | bool ret = false; | ||
511 | |||
512 | int driver=(storage_drivers[drive] & DRIVER_MASK)>>DRIVER_OFFSET; | ||
513 | int ldrive=(storage_drivers[drive] & DRIVE_MASK)>>DRIVE_OFFSET; | ||
514 | |||
515 | switch(driver) | ||
516 | { | ||
517 | #if (CONFIG_STORAGE & STORAGE_ATA) | ||
518 | case STORAGE_ATA: | ||
519 | ret = ata_present(ldrive); | ||
520 | #endif | ||
521 | |||
522 | #if (CONFIG_STORAGE & STORAGE_MMC) | ||
523 | case STORAGE_MMC: | ||
524 | ret = mmc_present(ldrive); | ||
525 | #endif | ||
526 | |||
527 | #if (CONFIG_STORAGE & STORAGE_SD) | ||
528 | case STORAGE_SD: | ||
529 | ret = sd_present(ldrive); | ||
530 | #endif | ||
531 | |||
532 | #if (CONFIG_STORAGE & STORAGE_NAND) | ||
533 | case STORAGE_NAND: | ||
534 | ret = true; | ||
535 | #endif | ||
536 | |||
537 | #if (CONFIG_STORAGE & STORAGE_RAMDISK) | ||
538 | case STORAGE_RAMDISK: | ||
539 | ret = true; | ||
540 | #endif | ||
541 | } | ||
542 | |||
543 | return ret; | ||
544 | } | ||
545 | #endif | ||