Subversion Repositories freemyipod

Rev

Go to most recent revision | Details | Last modification | View Log | RSS feed

Rev Author Line No. Line
54 theseven 1
/***************************************************************************
2
 *             __________               __   ___.
3
 *   Open      \______   \ ____   ____ |  | _\_ |__   _______  ___
4
 *   Source     |       _//  _ \_/ ___\|  |/ /| __ \ /  _ \  \/  /
5
 *   Jukebox    |    |   (  <_> )  \___|    < | \_\ (  <_> > <  <
6
 *   Firmware   |____|_  /\____/ \___  >__|_ \|___  /\____/__/\_ \
7
 *                     \/            \/     \/    \/            \/
8
 * $Id$
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 "global.h"
22
#include "storage.h"
23
 
24
#ifdef CONFIG_STORAGE_MULTI
25
 
26
#define DRIVER_MASK     0xff000000
27
#define DRIVER_OFFSET   24
28
#define DRIVE_MASK      0x00ff0000
29
#define DRIVE_OFFSET    16
30
#define PARTITION_MASK  0x0000ff00
31
 
32
static unsigned int storage_drivers[NUM_DRIVES];
33
static unsigned int num_drives;
34
#endif
35
 
36
 
37
int storage_read_sectors(IF_MD2(int drive,) unsigned long start, int count,
38
                         void* buf)
39
{
40
#ifdef CONFIG_STORAGE_MULTI
41
    int driver=(storage_drivers[drive] & DRIVER_MASK)>>DRIVER_OFFSET;
42
    int ldrive=(storage_drivers[drive] & DRIVE_MASK)>>DRIVE_OFFSET;
43
 
44
    switch (driver)
45
    {
46
#if (CONFIG_STORAGE & STORAGE_ATA)
47
    case STORAGE_ATA:
48
        return ata_read_sectors(IF_MD2(ldrive,) start,count,buf);
49
#endif
50
 
51
#if (CONFIG_STORAGE & STORAGE_MMC)
52
    case STORAGE_MMC:
53
        return mmc_read_sectors(IF_MD2(ldrive,) start,count,buf);
54
#endif
55
 
56
#if (CONFIG_STORAGE & STORAGE_SD)
57
    case STORAGE_SD:
58
        return sd_read_sectors(IF_MD2(ldrive,) start,count,buf);
59
#endif
60
 
61
#if (CONFIG_STORAGE & STORAGE_NAND)
62
    case STORAGE_NAND:
63
        return nand_read_sectors(IF_MD2(ldrive,) start,count,buf);
64
#endif
65
 
66
#if (CONFIG_STORAGE & STORAGE_RAMDISK)
67
    case STORAGE_RAMDISK:
68
        return ramdisk_read_sectors(IF_MD2(ldrive,) start,count,buf);
69
#endif
70
    }
71
 
72
    return -1;
73
#else /* CONFIG_STORAGE_MULTI */
74
    return STORAGE_FUNCTION(read_sectors)(IF_MD2(drive,)start,count,buf);
75
#endif /* CONFIG_STORAGE_MULTI */
76
 
77
}
78
 
116 theseven 79
int storage_read_sectors_md(int drive, unsigned long start, int count, void* buf)
80
{
81
    return storage_read_sectors(IF_MD2(drive,) start, count, buf);
82
}
83
 
54 theseven 84
int storage_write_sectors(IF_MD2(int drive,) unsigned long start, int count,
85
                          const void* buf)
86
{
87
#ifdef CONFIG_STORAGE_MULTI
88
    int driver=(storage_drivers[drive] & DRIVER_MASK)>>DRIVER_OFFSET;
89
    int ldrive=(storage_drivers[drive] & DRIVE_MASK)>>DRIVE_OFFSET;
90
 
91
    switch (driver)
92
    {
93
#if (CONFIG_STORAGE & STORAGE_ATA)
94
    case STORAGE_ATA:
95
        return ata_write_sectors(IF_MD2(ldrive,)start,count,buf);
96
#endif
97
 
98
#if (CONFIG_STORAGE & STORAGE_MMC)
99
    case STORAGE_MMC:
100
        return mmc_write_sectors(IF_MD2(ldrive,)start,count,buf);
101
#endif
102
 
103
#if (CONFIG_STORAGE & STORAGE_SD)
104
    case STORAGE_SD:
105
        return sd_write_sectors(IF_MD2(ldrive,)start,count,buf);
106
#endif
107
 
108
#if (CONFIG_STORAGE & STORAGE_NAND)
109
    case STORAGE_NAND:
110
        return nand_write_sectors(IF_MD2(ldrive,)start,count,buf);
111
#endif
112
 
113
#if (CONFIG_STORAGE & STORAGE_RAMDISK)
114
    case STORAGE_RAMDISK:
115
        return ramdisk_write_sectors(IF_MD2(ldrive,)start,count,buf);
116
#endif
117
    }
118
 
119
    return -1;
120
#else /* CONFIG_STORAGE_MULTI */
121
    return STORAGE_FUNCTION(write_sectors)(IF_MD2(drive,)start,count,buf);
122
#endif /* CONFIG_STORAGE_MULTI */
123
}
124
 
116 theseven 125
int storage_write_sectors_md(int drive, unsigned long start, int count, const void* buf)
126
{
127
    return storage_write_sectors(IF_MD2(drive,) start, count, buf);
128
}
129
 
153 theseven 130
#ifdef STORAGE_GET_INFO
131
void storage_get_info(int drive, struct storage_info *info)
132
{
54 theseven 133
#ifdef CONFIG_STORAGE_MULTI
153 theseven 134
    int driver=(storage_drivers[drive] & DRIVER_MASK)>>DRIVER_OFFSET;
135
    int ldrive=(storage_drivers[drive] & DRIVE_MASK)>>DRIVE_OFFSET;
136
 
137
    switch(driver)
138
    {
139
#if (CONFIG_STORAGE & STORAGE_ATA)
140
    case STORAGE_ATA:
141
        return ata_get_info(ldrive,info);
142
#endif
54 theseven 143
 
153 theseven 144
#if (CONFIG_STORAGE & STORAGE_MMC)
145
    case STORAGE_MMC:
146
        return mmc_get_info(ldrive,info);
147
#endif
148
 
149
#if (CONFIG_STORAGE & STORAGE_SD)
150
    case STORAGE_SD:
151
        return sd_get_info(ldrive,info);
152
#endif
153
 
154
#if (CONFIG_STORAGE & STORAGE_NAND)
155
    case STORAGE_NAND:
156
        return nand_get_info(ldrive,info);
157
#endif
158
 
159
#if (CONFIG_STORAGE & STORAGE_RAMDISK)
160
    case STORAGE_RAMDISK:
161
        return ramdisk_get_info(ldrive,info);
162
#endif
163
    }
164
#else /* CONFIG_STORAGE_MULTI */
165
    return STORAGE_FUNCTION(get_info)(IF_MD2(drive,)info);
166
#endif /* CONFIG_STORAGE_MULTI */
167
}
168
#endif /* STORAGE_GET_INFO */
169
 
170
#ifdef CONFIG_STORAGE_MULTI
171
 
54 theseven 172
int storage_num_drives(void)
173
{
174
    return num_drives;
175
}
176
 
177
int storage_init(void)
178
{
179
    int rc=0;
180
    int i;
181
    num_drives=0;
182
 
183
#if (CONFIG_STORAGE & STORAGE_ATA)
184
    if ((rc=ata_init())) return rc;
185
 
186
    int ata_drives = ata_num_drives(num_drives);
187
    for (i=0; i<ata_drives; i++)
188
    {
189
        storage_drivers[num_drives++] = 
190
            (STORAGE_ATA<<DRIVER_OFFSET) | (i << DRIVE_OFFSET);
191
    }
192
#endif
193
 
194
#if (CONFIG_STORAGE & STORAGE_MMC)
195
    if ((rc=mmc_init())) return rc;
196
 
197
    int mmc_drives = mmc_num_drives(num_drives);
198
    for (i=0; i<mmc_drives ;i++)
199
    {
200
        storage_drivers[num_drives++] =
201
            (STORAGE_MMC<<DRIVER_OFFSET) | (i << DRIVE_OFFSET);
202
    }
203
#endif
204
 
205
#if (CONFIG_STORAGE & STORAGE_SD)
206
    if ((rc=sd_init())) return rc;
207
 
208
    int sd_drives = sd_num_drives(num_drives);
209
    for (i=0; i<sd_drives; i++)
210
    {
211
        storage_drivers[num_drives++] =
212
            (STORAGE_SD<<DRIVER_OFFSET) | (i << DRIVE_OFFSET);
213
    }
214
#endif
215
 
216
#if (CONFIG_STORAGE & STORAGE_NAND)
217
    if ((rc=nand_init())) return rc;
218
 
219
    int nand_drives = nand_num_drives(num_drives);
220
    for (i=0; i<nand_drives; i++)
221
    {
222
        storage_drivers[num_drives++] =
223
            (STORAGE_NAND<<DRIVER_OFFSET) | (i << DRIVE_OFFSET);
224
    }
225
#endif
226
 
227
#if (CONFIG_STORAGE & STORAGE_RAMDISK)
228
    if ((rc=ramdisk_init())) return rc;
229
 
230
    int ramdisk_drives = ramdisk_num_drives(num_drives);
231
    for (i=0; i<ramdisk_drives; i++)
232
    {
233
        storage_drivers[num_drives++] =
234
            (STORAGE_RAMDISK<<DRIVER_OFFSET) | (i << DRIVE_OFFSET);
235
    }
236
#endif
237
 
238
    return 0;
239
}
240
 
241
 
242
void storage_enable(bool on)
243
{
244
#if (CONFIG_STORAGE & STORAGE_ATA)
245
    ata_enable(on);
246
#endif
247
 
248
#if (CONFIG_STORAGE & STORAGE_MMC)
249
    mmc_enable(on);
250
#endif
251
 
252
#if (CONFIG_STORAGE & STORAGE_SD)
253
    sd_enable(on);
254
#endif
255
 
256
#if (CONFIG_STORAGE & STORAGE_NAND)
257
    nand_enable(on);
258
#endif
259
 
260
#if (CONFIG_STORAGE & STORAGE_RAMDISK)
261
    ramdisk_enable(on);
262
#endif
263
}
264
 
265
void storage_sleep(void)
266
{
267
#if (CONFIG_STORAGE & STORAGE_ATA)
268
    ata_sleep();
269
#endif
270
 
271
#if (CONFIG_STORAGE & STORAGE_MMC)
272
    mmc_sleep();
273
#endif
274
 
275
#if (CONFIG_STORAGE & STORAGE_SD)
276
    sd_sleep();
277
#endif
278
 
279
#if (CONFIG_STORAGE & STORAGE_NAND)
280
    nand_sleep();
281
#endif
282
 
283
#if (CONFIG_STORAGE & STORAGE_RAMDISK)
284
    ramdisk_sleep();
285
#endif
286
}
287
 
288
void storage_sleepnow(void)
289
{
290
#if (CONFIG_STORAGE & STORAGE_ATA)
291
    ata_sleepnow();
292
#endif
293
 
294
#if (CONFIG_STORAGE & STORAGE_MMC)
295
    mmc_sleepnow();
296
#endif
297
 
298
#if (CONFIG_STORAGE & STORAGE_SD)
299
    //sd_sleepnow();
300
#endif
301
 
302
#if (CONFIG_STORAGE & STORAGE_NAND)
303
    nand_sleepnow();
304
#endif
305
 
306
#if (CONFIG_STORAGE & STORAGE_RAMDISK)
307
    ramdisk_sleepnow();
308
#endif
309
}
310
 
311
bool storage_disk_is_active(void)
312
{
313
#if (CONFIG_STORAGE & STORAGE_ATA)
314
    if (ata_disk_is_active()) return true;
315
#endif
316
 
317
#if (CONFIG_STORAGE & STORAGE_MMC)
318
    if (mmc_disk_is_active()) return true;
319
#endif
320
 
321
#if (CONFIG_STORAGE & STORAGE_SD)
322
    //if (sd_disk_is_active()) return true;
323
#endif
324
 
325
#if (CONFIG_STORAGE & STORAGE_NAND)
326
    //if (nand_disk_is_active()) return true;
327
#endif
328
 
329
#if (CONFIG_STORAGE & STORAGE_RAMDISK)
330
    if (ramdisk_disk_is_active()) return true;
331
#endif
332
 
333
    return false;
334
}
335
 
336
int storage_soft_reset(void)
337
{
338
    int rc=0;
339
 
340
#if (CONFIG_STORAGE & STORAGE_ATA)
341
    if ((rc=ata_soft_reset())) return rc;
342
#endif
343
 
344
#if (CONFIG_STORAGE & STORAGE_MMC)
345
    if ((rc=mmc_soft_reset())) return rc;
346
#endif
347
 
348
#if (CONFIG_STORAGE & STORAGE_SD)
349
    //if ((rc=sd_soft_reset())) return rc;
350
#endif
351
 
352
#if (CONFIG_STORAGE & STORAGE_NAND)
353
    //if ((rc=nand_soft_reset())) return rc;
354
#endif
355
 
356
#if (CONFIG_STORAGE & STORAGE_RAMDISK)
357
    if ((rc=ramdisk_soft_reset())) return rc;
358
#endif
359
 
360
    return rc;
361
}
362
 
363
#ifdef HAVE_STORAGE_FLUSH
364
int storage_flush(void)
365
{
366
    int rc=0;
367
 
368
#if (CONFIG_STORAGE & STORAGE_ATA)
369
    //if ((rc=ata_flush())) return rc;
370
#endif
371
 
372
#if (CONFIG_STORAGE & STORAGE_MMC)
373
    //if ((rc=mmc_flush())) return rc;
374
#endif
375
 
376
#if (CONFIG_STORAGE & STORAGE_SD)
377
    //if ((rc=sd_flush())) return rc;
378
#endif
379
 
380
#if (CONFIG_STORAGE & STORAGE_NAND)
381
    if ((rc=nand_flush())) return rc;
382
#endif
383
 
384
#if (CONFIG_STORAGE & STORAGE_RAMDISK)
385
    //if ((rc=ramdisk_flush())) return rc;
386
#endif
387
 
388
    return rc;
389
}
390
#endif
391
 
392
void storage_spin(void)
393
{
394
#if (CONFIG_STORAGE & STORAGE_ATA)
395
    ata_spin();
396
#endif
397
 
398
#if (CONFIG_STORAGE & STORAGE_MMC)
399
    mmc_spin();
400
#endif
401
 
402
#if (CONFIG_STORAGE & STORAGE_SD)
403
    sd_spin();
404
#endif
405
 
406
#if (CONFIG_STORAGE & STORAGE_NAND)
407
    nand_spin();
408
#endif
409
 
410
#if (CONFIG_STORAGE & STORAGE_RAMDISK)
411
    ramdisk_spin();
412
#endif
413
}
414
 
415
void storage_spindown(int seconds)
416
{
417
#if (CONFIG_STORAGE & STORAGE_ATA)
418
    ata_spindown(seconds);
419
#endif
420
 
421
#if (CONFIG_STORAGE & STORAGE_MMC)
422
    mmc_spindown(seconds);
423
#endif
424
 
425
#if (CONFIG_STORAGE & STORAGE_SD)
426
    sd_spindown(seconds);
427
#endif
428
 
429
#if (CONFIG_STORAGE & STORAGE_NAND)
430
    nand_spindown(seconds);
431
#endif
432
 
433
#if (CONFIG_STORAGE & STORAGE_RAMDISK)
434
    ramdisk_spindown(seconds);
435
#endif
436
}
437
 
438
#if (CONFIG_LED == LED_REAL)
439
void storage_set_led_enabled(bool enabled)
440
{
441
#if (CONFIG_STORAGE & STORAGE_ATA)
442
    ata_set_led_enabled(enabled);
443
#endif
444
 
445
#if (CONFIG_STORAGE & STORAGE_MMC)
446
    mmc_set_led_enabled(enabled);
447
#endif
448
 
449
#if (CONFIG_STORAGE & STORAGE_SD)
450
    sd_set_led_enabled(enabled);
451
#endif
452
 
453
#if (CONFIG_STORAGE & STORAGE_NAND)
454
    nand_set_led_enabled(enabled);
455
#endif
456
 
457
#if (CONFIG_STORAGE & STORAGE_RAMDISK)
458
    ramdisk_set_led_enabled(enabled);
459
#endif
460
}
461
#endif /* CONFIG_LED == LED_REAL */
462
 
463
long storage_last_disk_activity(void)
464
{
465
    long max=0;
466
    long t;
467
 
468
#if (CONFIG_STORAGE & STORAGE_ATA)
469
    t=ata_last_disk_activity();
470
    if (t>max) max=t;
471
#endif
472
 
473
#if (CONFIG_STORAGE & STORAGE_MMC)
474
    t=mmc_last_disk_activity();
475
    if (t>max) max=t;
476
#endif
477
 
478
#if (CONFIG_STORAGE & STORAGE_SD)
479
    t=sd_last_disk_activity();
480
    if (t>max) max=t;
481
#endif
482
 
483
#if (CONFIG_STORAGE & STORAGE_NAND)
484
    t=nand_last_disk_activity();
485
    if (t>max) max=t;
486
#endif
487
 
488
#if (CONFIG_STORAGE & STORAGE_RAMDISK)
489
    t=ramdisk_last_disk_activity();
490
    if (t>max) max=t;
491
#endif
492
 
493
    return max;
494
}
495
 
496
#ifdef HAVE_HOTSWAP
497
bool storage_removable(int drive)
498
{
499
    int driver=(storage_drivers[drive] & DRIVER_MASK)>>DRIVER_OFFSET;
500
    int ldrive=(storage_drivers[drive] & DRIVE_MASK)>>DRIVE_OFFSET;
501
 
502
    switch(driver)
503
    {
504
#if (CONFIG_STORAGE & STORAGE_ATA)
505
    case STORAGE_ATA:
506
        return ata_removable(ldrive);
507
#endif
508
 
509
#if (CONFIG_STORAGE & STORAGE_MMC)
510
    case STORAGE_MMC:
511
        return mmc_removable(ldrive);
512
#endif
513
 
514
#if (CONFIG_STORAGE & STORAGE_SD)
515
    case STORAGE_SD:
516
        return sd_removable(ldrive);
517
#endif
518
 
519
#if (CONFIG_STORAGE & STORAGE_NAND)
520
    case STORAGE_NAND:
521
        return false;
522
#endif
523
 
524
#if (CONFIG_STORAGE & STORAGE_RAMDISK)
525
    case STORAGE_RAMDISK:
526
        return false;
527
#endif
528
 
529
    default:
530
        return false;
531
    }
532
}
533
 
534
bool storage_present(int drive)
535
{
536
    int driver=(storage_drivers[drive] & DRIVER_MASK)>>DRIVER_OFFSET;
537
    int ldrive=(storage_drivers[drive] & DRIVE_MASK)>>DRIVE_OFFSET;
538
 
539
    switch(driver)
540
    {
541
#if (CONFIG_STORAGE & STORAGE_ATA)
542
    case STORAGE_ATA:
543
        return ata_present(ldrive);
544
#endif
545
 
546
#if (CONFIG_STORAGE & STORAGE_MMC)
547
    case STORAGE_MMC:
548
        return mmc_present(ldrive);
549
#endif
550
 
551
#if (CONFIG_STORAGE & STORAGE_SD)
552
    case STORAGE_SD:
553
        return sd_present(ldrive);
554
#endif
555
 
556
#if (CONFIG_STORAGE & STORAGE_NAND)
557
    case STORAGE_NAND:
558
        return true;
559
#endif
560
 
561
#if (CONFIG_STORAGE & STORAGE_RAMDISK)
562
    case STORAGE_RAMDISK:
563
        return true;
564
#endif
565
 
566
    default:
567
        return false;
568
    }
569
}
570
#endif
571
 
572
#endif /*CONFIG_STORAGE_MULTI*/