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