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
 
54 theseven 130
#ifdef CONFIG_STORAGE_MULTI
131
 
132
int storage_num_drives(void)
133
{
134
    return num_drives;
135
}
136
 
137
int storage_init(void)
138
{
139
    int rc=0;
140
    int i;
141
    num_drives=0;
142
 
143
#if (CONFIG_STORAGE & STORAGE_ATA)
144
    if ((rc=ata_init())) return rc;
145
 
146
    int ata_drives = ata_num_drives(num_drives);
147
    for (i=0; i<ata_drives; i++)
148
    {
149
        storage_drivers[num_drives++] = 
150
            (STORAGE_ATA<<DRIVER_OFFSET) | (i << DRIVE_OFFSET);
151
    }
152
#endif
153
 
154
#if (CONFIG_STORAGE & STORAGE_MMC)
155
    if ((rc=mmc_init())) return rc;
156
 
157
    int mmc_drives = mmc_num_drives(num_drives);
158
    for (i=0; i<mmc_drives ;i++)
159
    {
160
        storage_drivers[num_drives++] =
161
            (STORAGE_MMC<<DRIVER_OFFSET) | (i << DRIVE_OFFSET);
162
    }
163
#endif
164
 
165
#if (CONFIG_STORAGE & STORAGE_SD)
166
    if ((rc=sd_init())) return rc;
167
 
168
    int sd_drives = sd_num_drives(num_drives);
169
    for (i=0; i<sd_drives; i++)
170
    {
171
        storage_drivers[num_drives++] =
172
            (STORAGE_SD<<DRIVER_OFFSET) | (i << DRIVE_OFFSET);
173
    }
174
#endif
175
 
176
#if (CONFIG_STORAGE & STORAGE_NAND)
177
    if ((rc=nand_init())) return rc;
178
 
179
    int nand_drives = nand_num_drives(num_drives);
180
    for (i=0; i<nand_drives; i++)
181
    {
182
        storage_drivers[num_drives++] =
183
            (STORAGE_NAND<<DRIVER_OFFSET) | (i << DRIVE_OFFSET);
184
    }
185
#endif
186
 
187
#if (CONFIG_STORAGE & STORAGE_RAMDISK)
188
    if ((rc=ramdisk_init())) return rc;
189
 
190
    int ramdisk_drives = ramdisk_num_drives(num_drives);
191
    for (i=0; i<ramdisk_drives; i++)
192
    {
193
        storage_drivers[num_drives++] =
194
            (STORAGE_RAMDISK<<DRIVER_OFFSET) | (i << DRIVE_OFFSET);
195
    }
196
#endif
197
 
198
    return 0;
199
}
200
 
201
 
202
void storage_enable(bool on)
203
{
204
#if (CONFIG_STORAGE & STORAGE_ATA)
205
    ata_enable(on);
206
#endif
207
 
208
#if (CONFIG_STORAGE & STORAGE_MMC)
209
    mmc_enable(on);
210
#endif
211
 
212
#if (CONFIG_STORAGE & STORAGE_SD)
213
    sd_enable(on);
214
#endif
215
 
216
#if (CONFIG_STORAGE & STORAGE_NAND)
217
    nand_enable(on);
218
#endif
219
 
220
#if (CONFIG_STORAGE & STORAGE_RAMDISK)
221
    ramdisk_enable(on);
222
#endif
223
}
224
 
225
void storage_sleep(void)
226
{
227
#if (CONFIG_STORAGE & STORAGE_ATA)
228
    ata_sleep();
229
#endif
230
 
231
#if (CONFIG_STORAGE & STORAGE_MMC)
232
    mmc_sleep();
233
#endif
234
 
235
#if (CONFIG_STORAGE & STORAGE_SD)
236
    sd_sleep();
237
#endif
238
 
239
#if (CONFIG_STORAGE & STORAGE_NAND)
240
    nand_sleep();
241
#endif
242
 
243
#if (CONFIG_STORAGE & STORAGE_RAMDISK)
244
    ramdisk_sleep();
245
#endif
246
}
247
 
248
void storage_sleepnow(void)
249
{
250
#if (CONFIG_STORAGE & STORAGE_ATA)
251
    ata_sleepnow();
252
#endif
253
 
254
#if (CONFIG_STORAGE & STORAGE_MMC)
255
    mmc_sleepnow();
256
#endif
257
 
258
#if (CONFIG_STORAGE & STORAGE_SD)
259
    //sd_sleepnow();
260
#endif
261
 
262
#if (CONFIG_STORAGE & STORAGE_NAND)
263
    nand_sleepnow();
264
#endif
265
 
266
#if (CONFIG_STORAGE & STORAGE_RAMDISK)
267
    ramdisk_sleepnow();
268
#endif
269
}
270
 
271
bool storage_disk_is_active(void)
272
{
273
#if (CONFIG_STORAGE & STORAGE_ATA)
274
    if (ata_disk_is_active()) return true;
275
#endif
276
 
277
#if (CONFIG_STORAGE & STORAGE_MMC)
278
    if (mmc_disk_is_active()) return true;
279
#endif
280
 
281
#if (CONFIG_STORAGE & STORAGE_SD)
282
    //if (sd_disk_is_active()) return true;
283
#endif
284
 
285
#if (CONFIG_STORAGE & STORAGE_NAND)
286
    //if (nand_disk_is_active()) return true;
287
#endif
288
 
289
#if (CONFIG_STORAGE & STORAGE_RAMDISK)
290
    if (ramdisk_disk_is_active()) return true;
291
#endif
292
 
293
    return false;
294
}
295
 
296
int storage_soft_reset(void)
297
{
298
    int rc=0;
299
 
300
#if (CONFIG_STORAGE & STORAGE_ATA)
301
    if ((rc=ata_soft_reset())) return rc;
302
#endif
303
 
304
#if (CONFIG_STORAGE & STORAGE_MMC)
305
    if ((rc=mmc_soft_reset())) return rc;
306
#endif
307
 
308
#if (CONFIG_STORAGE & STORAGE_SD)
309
    //if ((rc=sd_soft_reset())) return rc;
310
#endif
311
 
312
#if (CONFIG_STORAGE & STORAGE_NAND)
313
    //if ((rc=nand_soft_reset())) return rc;
314
#endif
315
 
316
#if (CONFIG_STORAGE & STORAGE_RAMDISK)
317
    if ((rc=ramdisk_soft_reset())) return rc;
318
#endif
319
 
320
    return rc;
321
}
322
 
323
#ifdef HAVE_STORAGE_FLUSH
324
int storage_flush(void)
325
{
326
    int rc=0;
327
 
328
#if (CONFIG_STORAGE & STORAGE_ATA)
329
    //if ((rc=ata_flush())) return rc;
330
#endif
331
 
332
#if (CONFIG_STORAGE & STORAGE_MMC)
333
    //if ((rc=mmc_flush())) return rc;
334
#endif
335
 
336
#if (CONFIG_STORAGE & STORAGE_SD)
337
    //if ((rc=sd_flush())) return rc;
338
#endif
339
 
340
#if (CONFIG_STORAGE & STORAGE_NAND)
341
    if ((rc=nand_flush())) return rc;
342
#endif
343
 
344
#if (CONFIG_STORAGE & STORAGE_RAMDISK)
345
    //if ((rc=ramdisk_flush())) return rc;
346
#endif
347
 
348
    return rc;
349
}
350
#endif
351
 
352
void storage_spin(void)
353
{
354
#if (CONFIG_STORAGE & STORAGE_ATA)
355
    ata_spin();
356
#endif
357
 
358
#if (CONFIG_STORAGE & STORAGE_MMC)
359
    mmc_spin();
360
#endif
361
 
362
#if (CONFIG_STORAGE & STORAGE_SD)
363
    sd_spin();
364
#endif
365
 
366
#if (CONFIG_STORAGE & STORAGE_NAND)
367
    nand_spin();
368
#endif
369
 
370
#if (CONFIG_STORAGE & STORAGE_RAMDISK)
371
    ramdisk_spin();
372
#endif
373
}
374
 
375
void storage_spindown(int seconds)
376
{
377
#if (CONFIG_STORAGE & STORAGE_ATA)
378
    ata_spindown(seconds);
379
#endif
380
 
381
#if (CONFIG_STORAGE & STORAGE_MMC)
382
    mmc_spindown(seconds);
383
#endif
384
 
385
#if (CONFIG_STORAGE & STORAGE_SD)
386
    sd_spindown(seconds);
387
#endif
388
 
389
#if (CONFIG_STORAGE & STORAGE_NAND)
390
    nand_spindown(seconds);
391
#endif
392
 
393
#if (CONFIG_STORAGE & STORAGE_RAMDISK)
394
    ramdisk_spindown(seconds);
395
#endif
396
}
397
 
398
#if (CONFIG_LED == LED_REAL)
399
void storage_set_led_enabled(bool enabled)
400
{
401
#if (CONFIG_STORAGE & STORAGE_ATA)
402
    ata_set_led_enabled(enabled);
403
#endif
404
 
405
#if (CONFIG_STORAGE & STORAGE_MMC)
406
    mmc_set_led_enabled(enabled);
407
#endif
408
 
409
#if (CONFIG_STORAGE & STORAGE_SD)
410
    sd_set_led_enabled(enabled);
411
#endif
412
 
413
#if (CONFIG_STORAGE & STORAGE_NAND)
414
    nand_set_led_enabled(enabled);
415
#endif
416
 
417
#if (CONFIG_STORAGE & STORAGE_RAMDISK)
418
    ramdisk_set_led_enabled(enabled);
419
#endif
420
}
421
#endif /* CONFIG_LED == LED_REAL */
422
 
423
long storage_last_disk_activity(void)
424
{
425
    long max=0;
426
    long t;
427
 
428
#if (CONFIG_STORAGE & STORAGE_ATA)
429
    t=ata_last_disk_activity();
430
    if (t>max) max=t;
431
#endif
432
 
433
#if (CONFIG_STORAGE & STORAGE_MMC)
434
    t=mmc_last_disk_activity();
435
    if (t>max) max=t;
436
#endif
437
 
438
#if (CONFIG_STORAGE & STORAGE_SD)
439
    t=sd_last_disk_activity();
440
    if (t>max) max=t;
441
#endif
442
 
443
#if (CONFIG_STORAGE & STORAGE_NAND)
444
    t=nand_last_disk_activity();
445
    if (t>max) max=t;
446
#endif
447
 
448
#if (CONFIG_STORAGE & STORAGE_RAMDISK)
449
    t=ramdisk_last_disk_activity();
450
    if (t>max) max=t;
451
#endif
452
 
453
    return max;
454
}
455
 
456
#ifdef STORAGE_GET_INFO
457
void storage_get_info(int drive, struct storage_info *info)
458
{
459
    int driver=(storage_drivers[drive] & DRIVER_MASK)>>DRIVER_OFFSET;
460
    int ldrive=(storage_drivers[drive] & DRIVE_MASK)>>DRIVE_OFFSET;
461
 
462
    switch(driver)
463
    {
464
#if (CONFIG_STORAGE & STORAGE_ATA)
465
    case STORAGE_ATA:
466
        return ata_get_info(ldrive,info);
467
#endif
468
 
469
#if (CONFIG_STORAGE & STORAGE_MMC)
470
    case STORAGE_MMC:
471
        return mmc_get_info(ldrive,info);
472
#endif
473
 
474
#if (CONFIG_STORAGE & STORAGE_SD)
475
    case STORAGE_SD:
476
        return sd_get_info(ldrive,info);
477
#endif
478
 
479
#if (CONFIG_STORAGE & STORAGE_NAND)
480
    case STORAGE_NAND:
481
        return nand_get_info(ldrive,info);
482
#endif
483
 
484
#if (CONFIG_STORAGE & STORAGE_RAMDISK)
485
    case STORAGE_RAMDISK:
486
        return ramdisk_get_info(ldrive,info);
487
#endif
488
    }
489
}
490
#endif /* STORAGE_GET_INFO */
491
 
492
#ifdef HAVE_HOTSWAP
493
bool storage_removable(int drive)
494
{
495
    int driver=(storage_drivers[drive] & DRIVER_MASK)>>DRIVER_OFFSET;
496
    int ldrive=(storage_drivers[drive] & DRIVE_MASK)>>DRIVE_OFFSET;
497
 
498
    switch(driver)
499
    {
500
#if (CONFIG_STORAGE & STORAGE_ATA)
501
    case STORAGE_ATA:
502
        return ata_removable(ldrive);
503
#endif
504
 
505
#if (CONFIG_STORAGE & STORAGE_MMC)
506
    case STORAGE_MMC:
507
        return mmc_removable(ldrive);
508
#endif
509
 
510
#if (CONFIG_STORAGE & STORAGE_SD)
511
    case STORAGE_SD:
512
        return sd_removable(ldrive);
513
#endif
514
 
515
#if (CONFIG_STORAGE & STORAGE_NAND)
516
    case STORAGE_NAND:
517
        return false;
518
#endif
519
 
520
#if (CONFIG_STORAGE & STORAGE_RAMDISK)
521
    case STORAGE_RAMDISK:
522
        return false;
523
#endif
524
 
525
    default:
526
        return false;
527
    }
528
}
529
 
530
bool storage_present(int drive)
531
{
532
    int driver=(storage_drivers[drive] & DRIVER_MASK)>>DRIVER_OFFSET;
533
    int ldrive=(storage_drivers[drive] & DRIVE_MASK)>>DRIVE_OFFSET;
534
 
535
    switch(driver)
536
    {
537
#if (CONFIG_STORAGE & STORAGE_ATA)
538
    case STORAGE_ATA:
539
        return ata_present(ldrive);
540
#endif
541
 
542
#if (CONFIG_STORAGE & STORAGE_MMC)
543
    case STORAGE_MMC:
544
        return mmc_present(ldrive);
545
#endif
546
 
547
#if (CONFIG_STORAGE & STORAGE_SD)
548
    case STORAGE_SD:
549
        return sd_present(ldrive);
550
#endif
551
 
552
#if (CONFIG_STORAGE & STORAGE_NAND)
553
    case STORAGE_NAND:
554
        return true;
555
#endif
556
 
557
#if (CONFIG_STORAGE & STORAGE_RAMDISK)
558
    case STORAGE_RAMDISK:
559
        return true;
560
#endif
561
 
562
    default:
563
        return false;
564
    }
565
}
566
#endif
567
 
568
#endif /*CONFIG_STORAGE_MULTI*/