1 /***************************************************************************
3 * Open \______ \ ____ ____ | | _\_ |__ _______ ___
4 * Source | _// _ \_/ ___\| |/ /| __ \ / _ \ \/ /
5 * Jukebox | | ( <_> ) \___| < | \_\ ( <_> > < <
6 * Firmware |____|_ /\____/ \___ >__|_ \|___ /\____/__/\_ \
10 * Copyright (C) 2008 by Frank Gevaerts
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.
17 * This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY
18 * KIND, either express or implied.
20 ****************************************************************************/
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
29 static unsigned int storage_drivers
[NUM_DRIVES
];
30 static unsigned int num_drives
;
32 int storage_num_drives(void)
37 int storage_init(void)
43 #if (CONFIG_STORAGE & STORAGE_ATA)
44 if ((rc
=ata_init())) return rc
;
46 int ata_drives
= ata_num_drives(num_drives
);
47 for (i
=0; i
<ata_drives
; i
++)
49 storage_drivers
[num_drives
++] =
50 (STORAGE_ATA
<<DRIVER_OFFSET
) | (i
<< DRIVE_OFFSET
);
54 #if (CONFIG_STORAGE & STORAGE_MMC)
55 if ((rc
=mmc_init())) return rc
;
57 int mmc_drives
= mmc_num_drives(num_drives
);
58 for (i
=0; i
<mmc_drives
;i
++)
60 storage_drivers
[num_drives
++] =
61 (STORAGE_MMC
<<DRIVER_OFFSET
) | (i
<< DRIVE_OFFSET
);
65 #if (CONFIG_STORAGE & STORAGE_SD)
66 if ((rc
=sd_init())) return rc
;
68 int sd_drives
= sd_num_drives(num_drives
);
69 for (i
=0; i
<sd_drives
; i
++)
71 storage_drivers
[num_drives
++] =
72 (STORAGE_SD
<<DRIVER_OFFSET
) | (i
<< DRIVE_OFFSET
);
76 #if (CONFIG_STORAGE & STORAGE_NAND)
77 if ((rc
=nand_init())) return rc
;
79 int nand_drives
= nand_num_drives(num_drives
);
80 for (i
=0; i
<nand_drives
; i
++)
82 storage_drivers
[num_drives
++] =
83 (STORAGE_NAND
<<DRIVER_OFFSET
) | (i
<< DRIVE_OFFSET
);
87 #if (CONFIG_STORAGE & STORAGE_RAMDISK)
88 if ((rc
=ramdisk_init())) return rc
;
90 int ramdisk_drives
= ramdisk_num_drives(num_drives
);
91 for (i
=0; i
<ramdisk_drives
; i
++)
93 storage_drivers
[num_drives
++] =
94 (STORAGE_RAMDISK
<<DRIVER_OFFSET
) | (i
<< DRIVE_OFFSET
);
101 int storage_read_sectors(int drive
, unsigned long start
, int count
,
104 int driver
=(storage_drivers
[drive
] & DRIVER_MASK
)>>DRIVER_OFFSET
;
105 int ldrive
=(storage_drivers
[drive
] & DRIVE_MASK
)>>DRIVE_OFFSET
;
109 #if (CONFIG_STORAGE & STORAGE_ATA)
111 return ata_read_sectors(ldrive
,start
,count
,buf
);
114 #if (CONFIG_STORAGE & STORAGE_MMC)
116 return mmc_read_sectors(ldrive
,start
,count
,buf
);
119 #if (CONFIG_STORAGE & STORAGE_SD)
121 return sd_read_sectors(ldrive
,start
,count
,buf
);
124 #if (CONFIG_STORAGE & STORAGE_NAND)
126 return nand_read_sectors(ldrive
,start
,count
,buf
);
129 #if (CONFIG_STORAGE & STORAGE_RAMDISK)
130 case STORAGE_RAMDISK
:
131 return ramdisk_read_sectors(ldrive
,start
,count
,buf
);
138 int storage_write_sectors(int drive
, unsigned long start
, int count
,
141 int driver
=(storage_drivers
[drive
] & DRIVER_MASK
)>>DRIVER_OFFSET
;
142 int ldrive
=(storage_drivers
[drive
] & DRIVE_MASK
)>>DRIVE_OFFSET
;
146 #if (CONFIG_STORAGE & STORAGE_ATA)
148 return ata_write_sectors(ldrive
,start
,count
,buf
);
151 #if (CONFIG_STORAGE & STORAGE_MMC)
153 return mmc_write_sectors(ldrive
,start
,count
,buf
);
156 #if (CONFIG_STORAGE & STORAGE_SD)
158 return sd_write_sectors(ldrive
,start
,count
,buf
);
161 #if (CONFIG_STORAGE & STORAGE_NAND)
163 return nand_write_sectors(ldrive
,start
,count
,buf
);
166 #if (CONFIG_STORAGE & STORAGE_RAMDISK)
167 case STORAGE_RAMDISK
:
168 return ramdisk_write_sectors(ldrive
,start
,count
,buf
);
175 void storage_enable(bool on
)
177 #if (CONFIG_STORAGE & STORAGE_ATA)
181 #if (CONFIG_STORAGE & STORAGE_MMC)
185 #if (CONFIG_STORAGE & STORAGE_SD)
189 #if (CONFIG_STORAGE & STORAGE_NAND)
193 #if (CONFIG_STORAGE & STORAGE_RAMDISK)
198 void storage_sleep(void)
200 #if (CONFIG_STORAGE & STORAGE_ATA)
204 #if (CONFIG_STORAGE & STORAGE_MMC)
208 #if (CONFIG_STORAGE & STORAGE_SD)
212 #if (CONFIG_STORAGE & STORAGE_NAND)
216 #if (CONFIG_STORAGE & STORAGE_RAMDISK)
221 void storage_sleepnow(void)
223 #if (CONFIG_STORAGE & STORAGE_ATA)
227 #if (CONFIG_STORAGE & STORAGE_MMC)
231 #if (CONFIG_STORAGE & STORAGE_SD)
235 #if (CONFIG_STORAGE & STORAGE_NAND)
239 #if (CONFIG_STORAGE & STORAGE_RAMDISK)
244 bool storage_disk_is_active(void)
246 #if (CONFIG_STORAGE & STORAGE_ATA)
247 if (ata_disk_is_active()) return true;
250 #if (CONFIG_STORAGE & STORAGE_MMC)
251 if (mmc_disk_is_active()) return true;
254 #if (CONFIG_STORAGE & STORAGE_SD)
255 //if (sd_disk_is_active()) return true;
258 #if (CONFIG_STORAGE & STORAGE_NAND)
259 //if (nand_disk_is_active()) return true;
262 #if (CONFIG_STORAGE & STORAGE_RAMDISK)
263 if (ramdisk_disk_is_active()) return true;
269 int storage_soft_reset(void)
273 #if (CONFIG_STORAGE & STORAGE_ATA)
274 if ((rc
=ata_soft_reset())) return rc
;
277 #if (CONFIG_STORAGE & STORAGE_MMC)
278 if ((rc
=mmc_soft_reset())) return rc
;
281 #if (CONFIG_STORAGE & STORAGE_SD)
282 //if ((rc=sd_soft_reset())) return rc;
285 #if (CONFIG_STORAGE & STORAGE_NAND)
286 //if ((rc=nand_soft_reset())) return rc;
289 #if (CONFIG_STORAGE & STORAGE_RAMDISK)
290 if ((rc
=ramdisk_soft_reset())) return rc
;
296 void storage_spin(void)
298 #if (CONFIG_STORAGE & STORAGE_ATA)
302 #if (CONFIG_STORAGE & STORAGE_MMC)
306 #if (CONFIG_STORAGE & STORAGE_SD)
310 #if (CONFIG_STORAGE & STORAGE_NAND)
314 #if (CONFIG_STORAGE & STORAGE_RAMDISK)
319 void storage_spindown(int seconds
)
321 #if (CONFIG_STORAGE & STORAGE_ATA)
322 ata_spindown(seconds
);
325 #if (CONFIG_STORAGE & STORAGE_MMC)
326 mmc_spindown(seconds
);
329 #if (CONFIG_STORAGE & STORAGE_SD)
330 sd_spindown(seconds
);
333 #if (CONFIG_STORAGE & STORAGE_NAND)
334 nand_spindown(seconds
);
337 #if (CONFIG_STORAGE & STORAGE_RAMDISK)
338 ramdisk_spindown(seconds
);
342 #if (CONFIG_LED == LED_REAL)
343 void storage_set_led_enabled(bool enabled
)
345 #if (CONFIG_STORAGE & STORAGE_ATA)
346 ata_set_led_enabled(enabled
);
349 #if (CONFIG_STORAGE & STORAGE_MMC)
350 mmc_set_led_enabled(enabled
);
353 #if (CONFIG_STORAGE & STORAGE_SD)
354 sd_set_led_enabled(enabled
);
357 #if (CONFIG_STORAGE & STORAGE_NAND)
358 nand_set_led_enabled(enabled
);
361 #if (CONFIG_STORAGE & STORAGE_RAMDISK)
362 ramdisk_set_led_enabled(enabled
);
365 #endif /* CONFIG_LED == LED_REAL */
367 long storage_last_disk_activity(void)
372 #if (CONFIG_STORAGE & STORAGE_ATA)
373 t
=ata_last_disk_activity();
377 #if (CONFIG_STORAGE & STORAGE_MMC)
378 t
=mmc_last_disk_activity();
382 #if (CONFIG_STORAGE & STORAGE_SD)
383 t
=sd_last_disk_activity();
387 #if (CONFIG_STORAGE & STORAGE_NAND)
388 t
=nand_last_disk_activity();
392 #if (CONFIG_STORAGE & STORAGE_RAMDISK)
393 t
=ramdisk_last_disk_activity();
400 int storage_spinup_time(void)
405 #if (CONFIG_STORAGE & STORAGE_ATA)
410 #if (CONFIG_STORAGE & STORAGE_MMC)
415 #if (CONFIG_STORAGE & STORAGE_SD)
416 //t=sd_spinup_time();
420 #if (CONFIG_STORAGE & STORAGE_NAND)
421 t
=nand_spinup_time();
425 #if (CONFIG_STORAGE & STORAGE_RAMDISK)
426 t
=ramdisk_spinup_time();
433 #ifdef STORAGE_GET_INFO
434 void storage_get_info(int drive
, struct storage_info
*info
)
436 int driver
=(storage_drivers
[drive
] & DRIVER_MASK
)>>DRIVER_OFFSET
;
437 int ldrive
=(storage_drivers
[drive
] & DRIVE_MASK
)>>DRIVE_OFFSET
;
441 #if (CONFIG_STORAGE & STORAGE_ATA)
443 return ata_get_info(ldrive
,info
);
446 #if (CONFIG_STORAGE & STORAGE_MMC)
448 return mmc_get_info(ldrive
,info
);
451 #if (CONFIG_STORAGE & STORAGE_SD)
453 return sd_get_info(ldrive
,info
);
456 #if (CONFIG_STORAGE & STORAGE_NAND)
458 return nand_get_info(ldrive
,info
);
461 #if (CONFIG_STORAGE & STORAGE_RAMDISK)
462 case STORAGE_RAMDISK
:
463 return ramdisk_get_info(ldrive
,info
);
467 #endif /* STORAGE_GET_INFO */
470 bool storage_removable(int drive
)
474 int driver
=(storage_drivers
[drive
] & DRIVER_MASK
)>>DRIVER_OFFSET
;
475 int ldrive
=(storage_drivers
[drive
] & DRIVE_MASK
)>>DRIVE_OFFSET
;
479 #if (CONFIG_STORAGE & STORAGE_ATA)
481 ret
= ata_removable(ldrive
);
484 #if (CONFIG_STORAGE & STORAGE_MMC)
486 ret
= mmc_removable(ldrive
);
489 #if (CONFIG_STORAGE & STORAGE_SD)
491 ret
= sd_removable(ldrive
);
494 #if (CONFIG_STORAGE & STORAGE_NAND)
499 #if (CONFIG_STORAGE & STORAGE_RAMDISK)
500 case STORAGE_RAMDISK
:
508 bool storage_present(int drive
)
512 int driver
=(storage_drivers
[drive
] & DRIVER_MASK
)>>DRIVER_OFFSET
;
513 int ldrive
=(storage_drivers
[drive
] & DRIVE_MASK
)>>DRIVE_OFFSET
;
517 #if (CONFIG_STORAGE & STORAGE_ATA)
519 ret
= ata_present(ldrive
);
522 #if (CONFIG_STORAGE & STORAGE_MMC)
524 ret
= mmc_present(ldrive
);
527 #if (CONFIG_STORAGE & STORAGE_SD)
529 ret
= sd_present(ldrive
);
532 #if (CONFIG_STORAGE & STORAGE_NAND)
537 #if (CONFIG_STORAGE & STORAGE_RAMDISK)
538 case STORAGE_RAMDISK
: