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 #ifdef HAVE_STORAGE_FLUSH
297 int storage_flush(void)
301 #if (CONFIG_STORAGE & STORAGE_ATA)
302 //if ((rc=ata_flush())) return rc;
305 #if (CONFIG_STORAGE & STORAGE_MMC)
306 //if ((rc=mmc_flush())) return rc;
309 #if (CONFIG_STORAGE & STORAGE_SD)
310 //if ((rc=sd_flush())) return rc;
313 #if (CONFIG_STORAGE & STORAGE_NAND)
314 if ((rc
=nand_flush())) return rc
;
317 #if (CONFIG_STORAGE & STORAGE_RAMDISK)
318 //if ((rc=ramdisk_flush())) return rc;
325 void storage_spin(void)
327 #if (CONFIG_STORAGE & STORAGE_ATA)
331 #if (CONFIG_STORAGE & STORAGE_MMC)
335 #if (CONFIG_STORAGE & STORAGE_SD)
339 #if (CONFIG_STORAGE & STORAGE_NAND)
343 #if (CONFIG_STORAGE & STORAGE_RAMDISK)
348 void storage_spindown(int seconds
)
350 #if (CONFIG_STORAGE & STORAGE_ATA)
351 ata_spindown(seconds
);
354 #if (CONFIG_STORAGE & STORAGE_MMC)
355 mmc_spindown(seconds
);
358 #if (CONFIG_STORAGE & STORAGE_SD)
359 sd_spindown(seconds
);
362 #if (CONFIG_STORAGE & STORAGE_NAND)
363 nand_spindown(seconds
);
366 #if (CONFIG_STORAGE & STORAGE_RAMDISK)
367 ramdisk_spindown(seconds
);
371 #if (CONFIG_LED == LED_REAL)
372 void storage_set_led_enabled(bool enabled
)
374 #if (CONFIG_STORAGE & STORAGE_ATA)
375 ata_set_led_enabled(enabled
);
378 #if (CONFIG_STORAGE & STORAGE_MMC)
379 mmc_set_led_enabled(enabled
);
382 #if (CONFIG_STORAGE & STORAGE_SD)
383 sd_set_led_enabled(enabled
);
386 #if (CONFIG_STORAGE & STORAGE_NAND)
387 nand_set_led_enabled(enabled
);
390 #if (CONFIG_STORAGE & STORAGE_RAMDISK)
391 ramdisk_set_led_enabled(enabled
);
394 #endif /* CONFIG_LED == LED_REAL */
396 long storage_last_disk_activity(void)
401 #if (CONFIG_STORAGE & STORAGE_ATA)
402 t
=ata_last_disk_activity();
406 #if (CONFIG_STORAGE & STORAGE_MMC)
407 t
=mmc_last_disk_activity();
411 #if (CONFIG_STORAGE & STORAGE_SD)
412 t
=sd_last_disk_activity();
416 #if (CONFIG_STORAGE & STORAGE_NAND)
417 t
=nand_last_disk_activity();
421 #if (CONFIG_STORAGE & STORAGE_RAMDISK)
422 t
=ramdisk_last_disk_activity();
429 int storage_spinup_time(void)
434 #if (CONFIG_STORAGE & STORAGE_ATA)
439 #if (CONFIG_STORAGE & STORAGE_MMC)
444 #if (CONFIG_STORAGE & STORAGE_SD)
445 //t=sd_spinup_time();
449 #if (CONFIG_STORAGE & STORAGE_NAND)
450 t
=nand_spinup_time();
454 #if (CONFIG_STORAGE & STORAGE_RAMDISK)
455 t
=ramdisk_spinup_time();
462 #ifdef STORAGE_GET_INFO
463 void storage_get_info(int drive
, struct storage_info
*info
)
465 int driver
=(storage_drivers
[drive
] & DRIVER_MASK
)>>DRIVER_OFFSET
;
466 int ldrive
=(storage_drivers
[drive
] & DRIVE_MASK
)>>DRIVE_OFFSET
;
470 #if (CONFIG_STORAGE & STORAGE_ATA)
472 return ata_get_info(ldrive
,info
);
475 #if (CONFIG_STORAGE & STORAGE_MMC)
477 return mmc_get_info(ldrive
,info
);
480 #if (CONFIG_STORAGE & STORAGE_SD)
482 return sd_get_info(ldrive
,info
);
485 #if (CONFIG_STORAGE & STORAGE_NAND)
487 return nand_get_info(ldrive
,info
);
490 #if (CONFIG_STORAGE & STORAGE_RAMDISK)
491 case STORAGE_RAMDISK
:
492 return ramdisk_get_info(ldrive
,info
);
496 #endif /* STORAGE_GET_INFO */
499 bool storage_removable(int drive
)
503 int driver
=(storage_drivers
[drive
] & DRIVER_MASK
)>>DRIVER_OFFSET
;
504 int ldrive
=(storage_drivers
[drive
] & DRIVE_MASK
)>>DRIVE_OFFSET
;
508 #if (CONFIG_STORAGE & STORAGE_ATA)
510 ret
= ata_removable(ldrive
);
513 #if (CONFIG_STORAGE & STORAGE_MMC)
515 ret
= mmc_removable(ldrive
);
518 #if (CONFIG_STORAGE & STORAGE_SD)
520 ret
= sd_removable(ldrive
);
523 #if (CONFIG_STORAGE & STORAGE_NAND)
528 #if (CONFIG_STORAGE & STORAGE_RAMDISK)
529 case STORAGE_RAMDISK
:
537 bool storage_present(int drive
)
541 int driver
=(storage_drivers
[drive
] & DRIVER_MASK
)>>DRIVER_OFFSET
;
542 int ldrive
=(storage_drivers
[drive
] & DRIVE_MASK
)>>DRIVE_OFFSET
;
546 #if (CONFIG_STORAGE & STORAGE_ATA)
548 ret
= ata_present(ldrive
);
551 #if (CONFIG_STORAGE & STORAGE_MMC)
553 ret
= mmc_present(ldrive
);
556 #if (CONFIG_STORAGE & STORAGE_SD)
558 ret
= sd_present(ldrive
);
561 #if (CONFIG_STORAGE & STORAGE_NAND)
566 #if (CONFIG_STORAGE & STORAGE_RAMDISK)
567 case STORAGE_RAMDISK
: