Rearrange the MDCT library lookup tables so that codecs can access them. Access...
[kugel-rb.git] / firmware / storage.c
blobcee7d1cc8b3fe44376ffe675b0681a677024670f
1 /***************************************************************************
2 * __________ __ ___.
3 * Open \______ \ ____ ____ | | _\_ |__ _______ ___
4 * Source | _// _ \_/ ___\| |/ /| __ \ / _ \ \/ /
5 * Jukebox | | ( <_> ) \___| < | \_\ ( <_> > < <
6 * Firmware |____|_ /\____/ \___ >__|_ \|___ /\____/__/\_ \
7 * \/ \/ \/ \/ \/
8 * $Id$
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 ****************************************************************************/
21 #include "storage.h"
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)
34 return num_drives;
37 int storage_init(void)
39 int rc=0;
40 int i;
41 num_drives=0;
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);
52 #endif
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);
63 #endif
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);
74 #endif
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);
85 #endif
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);
96 #endif
98 return 0;
101 int storage_read_sectors(int drive, unsigned long start, int count,
102 void* buf)
104 int driver=(storage_drivers[drive] & DRIVER_MASK)>>DRIVER_OFFSET;
105 int ldrive=(storage_drivers[drive] & DRIVE_MASK)>>DRIVE_OFFSET;
107 switch (driver)
109 #if (CONFIG_STORAGE & STORAGE_ATA)
110 case STORAGE_ATA:
111 return ata_read_sectors(ldrive,start,count,buf);
112 #endif
114 #if (CONFIG_STORAGE & STORAGE_MMC)
115 case STORAGE_MMC:
116 return mmc_read_sectors(ldrive,start,count,buf);
117 #endif
119 #if (CONFIG_STORAGE & STORAGE_SD)
120 case STORAGE_SD:
121 return sd_read_sectors(ldrive,start,count,buf);
122 #endif
124 #if (CONFIG_STORAGE & STORAGE_NAND)
125 case STORAGE_NAND:
126 return nand_read_sectors(ldrive,start,count,buf);
127 #endif
129 #if (CONFIG_STORAGE & STORAGE_RAMDISK)
130 case STORAGE_RAMDISK:
131 return ramdisk_read_sectors(ldrive,start,count,buf);
132 #endif
135 return -1;
138 int storage_write_sectors(int drive, unsigned long start, int count,
139 const void* buf)
141 int driver=(storage_drivers[drive] & DRIVER_MASK)>>DRIVER_OFFSET;
142 int ldrive=(storage_drivers[drive] & DRIVE_MASK)>>DRIVE_OFFSET;
144 switch (driver)
146 #if (CONFIG_STORAGE & STORAGE_ATA)
147 case STORAGE_ATA:
148 return ata_write_sectors(ldrive,start,count,buf);
149 #endif
151 #if (CONFIG_STORAGE & STORAGE_MMC)
152 case STORAGE_MMC:
153 return mmc_write_sectors(ldrive,start,count,buf);
154 #endif
156 #if (CONFIG_STORAGE & STORAGE_SD)
157 case STORAGE_SD:
158 return sd_write_sectors(ldrive,start,count,buf);
159 #endif
161 #if (CONFIG_STORAGE & STORAGE_NAND)
162 case STORAGE_NAND:
163 return nand_write_sectors(ldrive,start,count,buf);
164 #endif
166 #if (CONFIG_STORAGE & STORAGE_RAMDISK)
167 case STORAGE_RAMDISK:
168 return ramdisk_write_sectors(ldrive,start,count,buf);
169 #endif
172 return -1;
175 void storage_enable(bool on)
177 #if (CONFIG_STORAGE & STORAGE_ATA)
178 ata_enable(on);
179 #endif
181 #if (CONFIG_STORAGE & STORAGE_MMC)
182 mmc_enable(on);
183 #endif
185 #if (CONFIG_STORAGE & STORAGE_SD)
186 sd_enable(on);
187 #endif
189 #if (CONFIG_STORAGE & STORAGE_NAND)
190 nand_enable(on);
191 #endif
193 #if (CONFIG_STORAGE & STORAGE_RAMDISK)
194 ramdisk_enable(on);
195 #endif
198 void storage_sleep(void)
200 #if (CONFIG_STORAGE & STORAGE_ATA)
201 ata_sleep();
202 #endif
204 #if (CONFIG_STORAGE & STORAGE_MMC)
205 mmc_sleep();
206 #endif
208 #if (CONFIG_STORAGE & STORAGE_SD)
209 sd_sleep();
210 #endif
212 #if (CONFIG_STORAGE & STORAGE_NAND)
213 nand_sleep();
214 #endif
216 #if (CONFIG_STORAGE & STORAGE_RAMDISK)
217 ramdisk_sleep();
218 #endif
221 void storage_sleepnow(void)
223 #if (CONFIG_STORAGE & STORAGE_ATA)
224 ata_sleepnow();
225 #endif
227 #if (CONFIG_STORAGE & STORAGE_MMC)
228 mmc_sleepnow();
229 #endif
231 #if (CONFIG_STORAGE & STORAGE_SD)
232 //sd_sleepnow();
233 #endif
235 #if (CONFIG_STORAGE & STORAGE_NAND)
236 nand_sleepnow();
237 #endif
239 #if (CONFIG_STORAGE & STORAGE_RAMDISK)
240 ramdisk_sleepnow();
241 #endif
244 bool storage_disk_is_active(void)
246 #if (CONFIG_STORAGE & STORAGE_ATA)
247 if (ata_disk_is_active()) return true;
248 #endif
250 #if (CONFIG_STORAGE & STORAGE_MMC)
251 if (mmc_disk_is_active()) return true;
252 #endif
254 #if (CONFIG_STORAGE & STORAGE_SD)
255 //if (sd_disk_is_active()) return true;
256 #endif
258 #if (CONFIG_STORAGE & STORAGE_NAND)
259 //if (nand_disk_is_active()) return true;
260 #endif
262 #if (CONFIG_STORAGE & STORAGE_RAMDISK)
263 if (ramdisk_disk_is_active()) return true;
264 #endif
266 return false;
269 int storage_soft_reset(void)
271 int rc=0;
273 #if (CONFIG_STORAGE & STORAGE_ATA)
274 if ((rc=ata_soft_reset())) return rc;
275 #endif
277 #if (CONFIG_STORAGE & STORAGE_MMC)
278 if ((rc=mmc_soft_reset())) return rc;
279 #endif
281 #if (CONFIG_STORAGE & STORAGE_SD)
282 //if ((rc=sd_soft_reset())) return rc;
283 #endif
285 #if (CONFIG_STORAGE & STORAGE_NAND)
286 //if ((rc=nand_soft_reset())) return rc;
287 #endif
289 #if (CONFIG_STORAGE & STORAGE_RAMDISK)
290 if ((rc=ramdisk_soft_reset())) return rc;
291 #endif
293 return rc;
296 void storage_spin(void)
298 #if (CONFIG_STORAGE & STORAGE_ATA)
299 ata_spin();
300 #endif
302 #if (CONFIG_STORAGE & STORAGE_MMC)
303 mmc_spin();
304 #endif
306 #if (CONFIG_STORAGE & STORAGE_SD)
307 sd_spin();
308 #endif
310 #if (CONFIG_STORAGE & STORAGE_NAND)
311 nand_spin();
312 #endif
314 #if (CONFIG_STORAGE & STORAGE_RAMDISK)
315 ramdisk_spin();
316 #endif
319 void storage_spindown(int seconds)
321 #if (CONFIG_STORAGE & STORAGE_ATA)
322 ata_spindown(seconds);
323 #endif
325 #if (CONFIG_STORAGE & STORAGE_MMC)
326 mmc_spindown(seconds);
327 #endif
329 #if (CONFIG_STORAGE & STORAGE_SD)
330 sd_spindown(seconds);
331 #endif
333 #if (CONFIG_STORAGE & STORAGE_NAND)
334 nand_spindown(seconds);
335 #endif
337 #if (CONFIG_STORAGE & STORAGE_RAMDISK)
338 ramdisk_spindown(seconds);
339 #endif
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);
347 #endif
349 #if (CONFIG_STORAGE & STORAGE_MMC)
350 mmc_set_led_enabled(enabled);
351 #endif
353 #if (CONFIG_STORAGE & STORAGE_SD)
354 sd_set_led_enabled(enabled);
355 #endif
357 #if (CONFIG_STORAGE & STORAGE_NAND)
358 nand_set_led_enabled(enabled);
359 #endif
361 #if (CONFIG_STORAGE & STORAGE_RAMDISK)
362 ramdisk_set_led_enabled(enabled);
363 #endif
365 #endif /* CONFIG_LED == LED_REAL */
367 long storage_last_disk_activity(void)
369 long max=0;
370 long t;
372 #if (CONFIG_STORAGE & STORAGE_ATA)
373 t=ata_last_disk_activity();
374 if (t>max) max=t;
375 #endif
377 #if (CONFIG_STORAGE & STORAGE_MMC)
378 t=mmc_last_disk_activity();
379 if (t>max) max=t;
380 #endif
382 #if (CONFIG_STORAGE & STORAGE_SD)
383 t=sd_last_disk_activity();
384 if (t>max) max=t;
385 #endif
387 #if (CONFIG_STORAGE & STORAGE_NAND)
388 t=nand_last_disk_activity();
389 if (t>max) max=t;
390 #endif
392 #if (CONFIG_STORAGE & STORAGE_RAMDISK)
393 t=ramdisk_last_disk_activity();
394 if (t>max) max=t;
395 #endif
397 return max;
400 int storage_spinup_time(void)
402 int max=0;
403 int t;
405 #if (CONFIG_STORAGE & STORAGE_ATA)
406 t=ata_spinup_time();
407 if (t>max) max=t;
408 #endif
410 #if (CONFIG_STORAGE & STORAGE_MMC)
411 t=mmc_spinup_time();
412 if (t>max) max=t;
413 #endif
415 #if (CONFIG_STORAGE & STORAGE_SD)
416 //t=sd_spinup_time();
417 //if (t>max) max=t;
418 #endif
420 #if (CONFIG_STORAGE & STORAGE_NAND)
421 t=nand_spinup_time();
422 if (t>max) max=t;
423 #endif
425 #if (CONFIG_STORAGE & STORAGE_RAMDISK)
426 t=ramdisk_spinup_time();
427 if (t>max) max=t;
428 #endif
430 return max;
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;
439 switch(driver)
441 #if (CONFIG_STORAGE & STORAGE_ATA)
442 case STORAGE_ATA:
443 return ata_get_info(ldrive,info);
444 #endif
446 #if (CONFIG_STORAGE & STORAGE_MMC)
447 case STORAGE_MMC:
448 return mmc_get_info(ldrive,info);
449 #endif
451 #if (CONFIG_STORAGE & STORAGE_SD)
452 case STORAGE_SD:
453 return sd_get_info(ldrive,info);
454 #endif
456 #if (CONFIG_STORAGE & STORAGE_NAND)
457 case STORAGE_NAND:
458 return nand_get_info(ldrive,info);
459 #endif
461 #if (CONFIG_STORAGE & STORAGE_RAMDISK)
462 case STORAGE_RAMDISK:
463 return ramdisk_get_info(ldrive,info);
464 #endif
467 #endif /* STORAGE_GET_INFO */
469 #ifdef HAVE_HOTSWAP
470 bool storage_removable(int drive)
472 bool ret = false;
474 int driver=(storage_drivers[drive] & DRIVER_MASK)>>DRIVER_OFFSET;
475 int ldrive=(storage_drivers[drive] & DRIVE_MASK)>>DRIVE_OFFSET;
477 switch(driver)
479 #if (CONFIG_STORAGE & STORAGE_ATA)
480 case STORAGE_ATA:
481 ret = ata_removable(ldrive);
482 #endif
484 #if (CONFIG_STORAGE & STORAGE_MMC)
485 case STORAGE_MMC:
486 ret = mmc_removable(ldrive);
487 #endif
489 #if (CONFIG_STORAGE & STORAGE_SD)
490 case STORAGE_SD:
491 ret = sd_removable(ldrive);
492 #endif
494 #if (CONFIG_STORAGE & STORAGE_NAND)
495 case STORAGE_NAND:
496 ret = false;
497 #endif
499 #if (CONFIG_STORAGE & STORAGE_RAMDISK)
500 case STORAGE_RAMDISK:
501 ret = false;
502 #endif
505 return ret;
508 bool storage_present(int drive)
510 bool ret = false;
512 int driver=(storage_drivers[drive] & DRIVER_MASK)>>DRIVER_OFFSET;
513 int ldrive=(storage_drivers[drive] & DRIVE_MASK)>>DRIVE_OFFSET;
515 switch(driver)
517 #if (CONFIG_STORAGE & STORAGE_ATA)
518 case STORAGE_ATA:
519 ret = ata_present(ldrive);
520 #endif
522 #if (CONFIG_STORAGE & STORAGE_MMC)
523 case STORAGE_MMC:
524 ret = mmc_present(ldrive);
525 #endif
527 #if (CONFIG_STORAGE & STORAGE_SD)
528 case STORAGE_SD:
529 ret = sd_present(ldrive);
530 #endif
532 #if (CONFIG_STORAGE & STORAGE_NAND)
533 case STORAGE_NAND:
534 ret = true;
535 #endif
537 #if (CONFIG_STORAGE & STORAGE_RAMDISK)
538 case STORAGE_RAMDISK:
539 ret = true;
540 #endif
543 return ret;
545 #endif