summaryrefslogtreecommitdiffstats
path: root/firmware/target/arm/sandisk/sansa-e200/ata-e200.c
blob: 8323574d69ee01a43be4e89f15b7b0a299ad1096 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
/***************************************************************************
 *             __________               __   ___.
 *   Open      \______   \ ____   ____ |  | _\_ |__   _______  ___
 *   Source     |       _//  _ \_/ ___\|  |/ /| __ \ /  _ \  \/  /
 *   Jukebox    |    |   (  <_> )  \___|    < | \_\ (  <_> > <  <
 *   Firmware   |____|_  /\____/ \___  >__|_ \|___  /\____/__/\_ \
 *                     \/            \/     \/    \/            \/
 * $Id$
 *
 * Copyright (C) 2006 Daniel Ankers
 *
 * All files in this archive are subject to the GNU General Public License.
 * See the file COPYING in the source tree root for full license agreement.
 *
 * This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY
 * KIND, either express or implied.
 *
 ****************************************************************************/
#include "lcd.h"
#include "ata.h"
#include "ata-target.h"
#include "ata_idle_notify.h"
#include "cpu.h"
#include "system.h"
#include <stdio.h>
#include <stdbool.h>
#include <string.h>
#include "kernel.h"
#include "thread.h"

#define NOINLINE_ATTR __attribute__((noinline)) /* don't inline the loops */

#define BLOCK_SIZE      (512)
#define SECTOR_SIZE     (512)

#define STATUS_REG      (*(volatile unsigned int *)(0x70008204))
#define REG_1           (*(volatile unsigned int *)(0x70008208))
#define UNKNOWN         (*(volatile unsigned int *)(0x70008210))
#define BLOCK_SIZE_REG  (*(volatile unsigned int *)(0x7000821c))
#define BLOCK_COUNT_REG (*(volatile unsigned int *)(0x70008220))
#define REG_5           (*(volatile unsigned int *)(0x70008224))
#define CMD_REG0        (*(volatile unsigned int *)(0x70008228))
#define CMD_REG1        (*(volatile unsigned int *)(0x7000822c))
#define CMD_REG2        (*(volatile unsigned int *)(0x70008230))
#define RESPONSE_REG    (*(volatile unsigned int *)(0x70008234))
#define SD_STATE_REG    (*(volatile unsigned int *)(0x70008238))
#define REG_11          (*(volatile unsigned int *)(0x70008240))
#define REG_12          (*(volatile unsigned int *)(0x70008244))
#define DATA_REG        (*(volatile unsigned int *)(0x70008280))

#define DATA_DONE       (1 << 12)
#define CMD_DONE        (1 << 13)
#define ERROR_BITS      (0x3f)
#define FIFO_FULL       (1 << 7)
#define FIFO_EMPTY      (1 << 6)

/* SD States */
#define IDLE            0
#define READY           1
#define IDENT           2
#define STBY            3
#define TRAN            4
#define DATA            5
#define RCV             6
#define PRG             7
#define DIS             8

#define FIFO_SIZE       16          /* FIFO is 16 words deep */

/* SD Commands */
#define GO_IDLE_STATE   0
#define ALL_SEND_CID    2
#define SEND_RELATIVE_ADDR  3
#define SET_DSR         4
#define SWITCH_FUNC     6
#define SELECT_CARD     7
#define DESELECT_CARD   7
#define SEND_CSD        9
#define SEND_CID        10
#define STOP_TRANSMISSION   12
#define SEND_STATUS     13
#define GO_INACTIVE_STATE   15
#define SET_BLOCKLEN    16
#define READ_SINGLE_BLOCK   17
#define READ_MULTIPLE_BLOCK 18
#define WRITE_BLOCK     24
#define WRITE_MULTIPLE_BLOCK    25
#define ERASE_WR_BLK_START  32
#define ERASE_WR_BLK_END    33
#define ERASE           38

/* Application Specific commands */
#define SET_BUS_WIDTH   6
#define SD_APP_OP_COND  41

#define READ_TIMEOUT    5*HZ
#define WRITE_TIMEOUT   0.5*HZ

static unsigned short identify_info[SECTOR_SIZE];
int ata_spinup_time = 0;
long last_disk_activity = -1;
static bool initialized = false;

static unsigned char current_bank = 0; /* The bank that we are working with */

static tSDCardInfo card_info[2];

/* For multi volume support */
static int current_card = 0;

static struct mutex sd_mtx;

static long sd_stack [DEFAULT_STACK_SIZE/sizeof(long)];

static const char sd_thread_name[] = "sd";
static struct event_queue sd_queue;


/* Private Functions */

bool sd_send_command(unsigned int cmd, unsigned long arg1, unsigned int arg2)
{
    bool result = false;
    do
    {
        CMD_REG0 = cmd;
        CMD_REG1 = (unsigned int)((arg1 & 0xffff0000) >> 16);
        CMD_REG2 = (unsigned int)((arg1 & 0xffff));
        UNKNOWN = arg2;
        while ((STATUS_REG & CMD_DONE) == 0)
        {
            /* Busy wait */
        }
        if ((STATUS_REG & ERROR_BITS) == 0)
        {
            result = true;
        } 
    } while ((STATUS_REG & ERROR_BITS) != 0);
    return result;
}

void sd_read_response(unsigned int *response, int type)
{
    int i;
    int words; /* Number of 16 bit words to read from RESPONSE_REG */
    unsigned int response_from_card[9];
    if(type == 2)
    {
        words = 9; /* R2 types are 8.5 16-bit words long */
    } else {
        words = 3;
    }

    for (i = 0; i < words; i++) /* RESPONSE_REG is read MSB first */
    {
            response_from_card[i] = RESPONSE_REG; /* Read most significant 16-bit word */
    }

    switch (type)
    {
        case 1:
            /* Response type 1 has the following structure:
                Start bit
                Transmission bit
                Command index (6 bits)
                Card Status (32 bits)
                CRC7 (7 bits)
                Stop bit
            */
            /* TODO: Sanity checks */
            response[0] = ((response_from_card[0] & 0xff) << 24)
                       + (response_from_card[1] << 8)
                       + ((response_from_card[2] & 0xff00) >> 8);
            break;
        case 2:
            /* Response type 2 has the following structure:
                Start bit
                Transmission bit
                Reserved (6 bits)
                CSD/CID register (127 bits)
                Stop bit
            */
            response[3] = ((response_from_card[0]&0xff)<<24) +
                           (response_from_card[1]<<8) +
                           ((response_from_card[2]&0xff00)>>8);
            response[2] = ((response_from_card[2]&0xff)<<24) +
                           (response_from_card[3]<<8) +
                           ((response_from_card[4]&0xff00)>>8);
            response[1] = ((response_from_card[4]&0xff)<<24) +
                           (response_from_card[5]<<8) +
                           ((response_from_card[6]&0xff00)>>8);
            response[0] = ((response_from_card[6]&0xff)<<24) +
                           (response_from_card[7]<<8) +
                           ((response_from_card[8]&0xff00)>>8);
            break;
        case 3:
            /* Response type 3 has the following structure:
                Start bit
                Transmission bit
                Reserved (6 bits)
                OCR register (32 bits)
                Reserved (7 bits)
                Stop bit
            */
            response[0] = ((response_from_card[0] & 0xff) << 24)
                       + (response_from_card[1] << 8)
                       + ((response_from_card[2] & 0xff00) >> 8);
        /* Types 4-6 not supported yet */
    }
}

bool sd_send_acommand(unsigned int cmd, unsigned long arg1, unsigned int arg2)
{
    unsigned int returncode;
    if (sd_send_command(55, (card_info[current_card].rca)<<16, 1) == false)
        return false;
    sd_read_response(&returncode, 1);
    if (sd_send_command(cmd, arg1, arg2) == false)
        return false;
    return true;
}

void sd_wait_for_state(tSDCardInfo* card, unsigned int state)
{
    unsigned int response = 0;
    while(((response >> 9) & 0xf) != state)
    {
        sd_send_command(SEND_STATUS, (card->rca) << 16, 1);
        sd_read_response(&response, 1);
        /* TODO: Add a timeout and error handling */
    }
    SD_STATE_REG = state;
}


static void copy_read_sectors(unsigned char* buf, int wordcount) 
        NOINLINE_ATTR ICODE_ATTR;

static void copy_read_sectors(unsigned char* buf, int wordcount)
{
    unsigned int tmp = 0;

    if ( (unsigned long)buf & 1)
    {   /* not 16-bit aligned, copy byte by byte */
        unsigned char* bufend = buf + wordcount*2;
        do
        {
            tmp = DATA_REG;
            *buf++ = tmp & 0xff;
            *buf++ = tmp >> 8;
        } while (buf < bufend); /* tail loop is faster */
    }
    else
    {   /* 16-bit aligned, can do faster copy */
        unsigned short* wbuf = (unsigned short*)buf;
        unsigned short* wbufend = wbuf + wordcount;
        do
        {
            *wbuf = DATA_REG;
        } while (++wbuf < wbufend); /* tail loop is faster */
    }
}

static void copy_write_sectors(const unsigned char* buf, int wordcount)
        NOINLINE_ATTR ICODE_ATTR;

static void copy_write_sectors(const unsigned char* buf, int wordcount)
{
    if ( (unsigned long)buf & 1)
    {   /* not 16-bit aligned, copy byte by byte */
        unsigned short tmp = 0;
        const unsigned char* bufend = buf + wordcount*2;
        do
        {
            tmp = (unsigned short) *buf++;
            tmp |= (unsigned short) *buf++ << 8;
            DATA_REG = tmp;
        } while (buf < bufend); /* tail loop is faster */
    }
    else
    {   /* 16-bit aligned, can do faster copy */
        unsigned short* wbuf = (unsigned short*)buf;
        unsigned short* wbufend = wbuf + wordcount;
        do
        {
            lcd_update();
            DATA_REG = *wbuf;
        } while (++wbuf < wbufend); /* tail loop is faster */
    }
}


void sd_select_bank(unsigned char bank)
{
    unsigned int response;
    unsigned char card_data[512];
    unsigned char* write_buf;
    int i;
    tSDCardInfo *card = &card_info[0]; /* Bank selection will only be done on
                                        the onboard flash */
    if (current_bank != bank)
    {
        memset(card_data, 0, 512);
        sd_wait_for_state(card, TRAN);
        BLOCK_SIZE_REG = 512;
        BLOCK_COUNT_REG = 1;
        sd_send_command(35, 0, 0x1c0d); /* CMD35 is vendor specific */
        sd_read_response(&response, 1);
        SD_STATE_REG = PRG;

        card_data[0] = bank;

        /* Write the card data */
        write_buf = card_data;
        for (i = 0; i < BLOCK_SIZE / 2; i += FIFO_SIZE)
        {
            /* Wait for the FIFO to be empty */
            while((STATUS_REG & FIFO_EMPTY) == 0) {} /* Erm... is this right? */

            copy_write_sectors(write_buf, FIFO_SIZE);

            write_buf += FIFO_SIZE*2; /* Advance one chunk of 16 words */
        }

        while((STATUS_REG & DATA_DONE) == 0) {}
        current_bank = bank;
    }
}

void sd_init_device(void)
{
/* SD Protocol registers */
    unsigned int dummy;
    int i;

    static unsigned int read_bl_len = 0;
    static unsigned int c_size = 0;
    static unsigned int c_size_mult = 0;
    static unsigned long mult = 0;

    unsigned char carddata[512];
    unsigned char *dataptr;
    tSDCardInfo *card = &card_info[0]; /* Init onboard flash only */

/* Initialise card data as blank */
    card->initialized = false;
    card->ocr = 0;
    card->csd[0] = 0;
    card->csd[1] = 0;
    card->csd[2] = 0;
    card->cid[0] = 0;
    card->cid[1] = 0;
    card->cid[2] = 0;
    card->rca = 0;

    card->capacity = 0;
    card->numblocks = 0;
    card->block_size = 0;
    card->block_exp = 0;

/* Enable and initialise controller */
    GPIOG_ENABLE |= (0x3 << 5);
    GPIOG_OUTPUT_EN |= (0x3 << 5);
    GPIOG_OUTPUT_VAL |= (0x3 << 5);
    outl(inl(0x70000088) & ~(0x4), 0x70000088);
    outl(inl(0x7000008c) & ~(0x4), 0x7000008c);
    outl(inl(0x70000080) | 0x4, 0x70000080);
    outl(inl(0x70000084) | 0x4, 0x70000084);
    REG_1 = 6;
    outl(inl(0x70000014) & ~(0x3ffff), 0x70000014);
    outl((inl(0x70000014) & ~(0x3ffff)) | 0x255aa, 0x70000014);
    outl(0x1010, 0x70000034);

    GPIOA_ENABLE |= (1 << 7);
    GPIOA_OUTPUT_EN &= ~(1 << 7);
    GPIOD_ENABLE |= (0x1f);
    GPIOD_OUTPUT_EN |= (0x1f);
    GPIOD_OUTPUT_VAL |= (0x1f);
    outl(inl(0x6000600c) | (1 << 14), 0x6000600c);
    outl(inl(0x60006004) | (1 << 14), 0x60006004);
    outl(inl(0x60006004) & ~(1 << 14), 0x60006004); /* Reset Controller? */
    outl(0, 0x6000b000);
    outl(0, 0x6000a000); /* Init DMA controller? */

/* Init NAND */
    REG_11 |= (1 << 15);
    REG_12 |= (1 << 15);
    REG_12 &= ~(3 << 12);
    REG_12 |= (1 << 13);
    REG_11 &= ~(3 << 12);
    REG_11 |= (1 << 13);

    SD_STATE_REG = TRAN;
    REG_5 = 0xf;

    sd_send_command(GO_IDLE_STATE, 0, 256);
    while ((card->ocr & (1 << 31)) == 0) /* Loop until the card is powered up */
    {
        sd_send_acommand(SD_APP_OP_COND, 0x100000, 3);
        sd_read_response(&(card->ocr), 3);

        if (card->ocr == 0)
        {
            /* TODO: Handle failure */
            while (1) {};
        }
    }

    sd_send_command(ALL_SEND_CID, 0, 2);
    sd_read_response(card->cid, 2);
    sd_send_command(SEND_RELATIVE_ADDR, 0, 1);
    sd_read_response(&card->rca, 1);
    card->rca >>= 16; /* The Relative Card Address is the top 16 bits of the
                        32 bits returned.  Whenever it is used, it gets
                        shifted left by 16 bits, so this step could possibly
                        be skipped. */

    sd_send_command(SEND_CSD, card->rca << 16, 2);
    sd_read_response(card->csd, 2);

    /* Parse disk geometry */
    /* These calculations come from the Sandisk SD card product manual */
    read_bl_len = ((card->csd[2] >> 16) & 0xf);
    c_size = ((card->csd[2] & (0x3ff)) << 2) +
        ((card->csd[1] & (0xc0000000)) >> 30);
    c_size_mult = ((card->csd[1] >> 15) & 0x7);
    mult = (1<<(c_size_mult + 2));
    card->max_read_bl_len = (1<<read_bl_len);
    card->block_size = BLOCK_SIZE;     /* Always use 512 byte blocks */
    card->numblocks = (c_size + 1) * mult * (card->max_read_bl_len / 512);
    card->capacity = card->numblocks * card->block_size;

    REG_1 = 0;
    sd_send_command(SELECT_CARD, card->rca << 16, 129);
    sd_read_response(&dummy, 1); /* I don't think we use the result from this */
    sd_send_acommand(SET_BUS_WIDTH, (card->rca << 16) | 2, 1);
    sd_read_response(&dummy, 1); /* 4 bit wide bus */
    sd_send_command(SET_BLOCKLEN, card->block_size, 1);
    sd_read_response(&dummy, 1);
    BLOCK_SIZE_REG = card->block_size;

    /* If this card is > 4Gb, then we need to enable bank switching */
    if(card->numblocks > 0x7a77ff)
    {
        SD_STATE_REG = TRAN;
        BLOCK_COUNT_REG = 1;
        sd_send_command(SWITCH_FUNC, 0x80ffffef, 0x1c05);
        sd_read_response(&dummy, 1);
        /* Read 512 bytes from the card.
        The first 512 bits contain the status information
        TODO: Do something useful with this! */
        dataptr = carddata;
        for (i = 0; i < BLOCK_SIZE / 2; i += FIFO_SIZE)
        {
            /* Wait for the FIFO to be full */
            while((STATUS_REG & FIFO_FULL) == 0) {}

            copy_read_sectors(dataptr, FIFO_SIZE);

            dataptr += (FIFO_SIZE*2); /* Advance one chunk of 16 words */
        }
    }
    mutex_init(&sd_mtx);
}

/* API Functions */

void ata_led(bool onoff)
{
    (void)onoff;
}

int ata_read_sectors(IF_MV2(int drive,)
                     unsigned long start,
                     int incount,
                     void* inbuf)
{
    int ret = 0;
    long timeout;
    int count;
    void* buf;
    long spinup_start;
    unsigned int dummy;
    unsigned int response;
    unsigned int i;
    tSDCardInfo *card = &card_info[current_card];

    /* TODO: Add DMA support. */

#ifdef HAVE_MULTIVOLUME
    (void)drive; /* unused for now */
#endif
    mutex_lock(&sd_mtx);

    last_disk_activity = current_tick;
    spinup_start = current_tick;

    ata_led(true);

    timeout = current_tick + READ_TIMEOUT;

    /* TODO: Select device */
    if(current_card == 0)
    {
        if(start > 0x7a77ff)
        {
            sd_select_bank(1);
            start-=0x7a77ff;
        } else {
            sd_select_bank(0);
        }
    }

    buf = inbuf;
    count = incount;
    while (TIME_BEFORE(current_tick, timeout)) {
        ret = 0;
        last_disk_activity = current_tick;

        SD_STATE_REG = TRAN;
        BLOCK_COUNT_REG = count;
        sd_send_command(READ_MULTIPLE_BLOCK, start * BLOCK_SIZE, 0x1c25);
        sd_read_response(&dummy, 1);
        /* TODO: Don't assume BLOCK_SIZE == SECTOR_SIZE */

        for (i = 0; i < count * card->block_size / 2; i += FIFO_SIZE)
        {
            /* Wait for the FIFO to be full */
            while((STATUS_REG & FIFO_FULL) == 0) {}

            copy_read_sectors(buf, FIFO_SIZE);

            buf += FIFO_SIZE*2; /* Advance one chunk of 16 words */

            /* TODO: Switch bank if necessary */

            last_disk_activity = current_tick;
        }
        udelay(75);
        sd_send_command(STOP_TRANSMISSION, 0, 1);
        sd_read_response(&dummy, 1);

        response = 0;
        sd_wait_for_state(card, TRAN);
        break;
    }
    ata_led(false);

    mutex_unlock(&sd_mtx);

    return ret;
}


int ata_write_sectors(IF_MV2(int drive,)
                      unsigned long start,
                      int count,
                      const void* buf)
{
/* Write support is not finished yet */
/* TODO: The standard suggests using ACMD23 prior to writing multiple blocks 
   to improve performance */
    unsigned int response;
    void const* write_buf;
    int ret = 0;
    unsigned int i;
    long timeout;
    tSDCardInfo *card = &card_info[current_card];

    mutex_lock(&sd_mtx);
    ata_led(true);
    if(current_card == 0)
    {
        if(start <= 0x7a77ff)
        {
            sd_select_bank(0);
        } else {
            sd_select_bank(1);
            start -= 0x7a77ff;
        }
    }

retry:
    sd_wait_for_state(card, TRAN);
    BLOCK_COUNT_REG = count;
    sd_send_command(WRITE_MULTIPLE_BLOCK, start * SECTOR_SIZE, 0x1c2d);
    sd_read_response(&response, 1);
    write_buf = buf;
    for (i = 0; i < count * card->block_size / 2; i += FIFO_SIZE)
    {
        if(i >= (count * card->block_size / 2)-FIFO_SIZE)
        {
            /* Set SD_STATE_REG to PRG for the last buffer fill */
            SD_STATE_REG = PRG;
        }

        /* Wait for the FIFO to be empty */
        while((STATUS_REG & FIFO_EMPTY) == 0) {}
        /* Perhaps we could use bit 8 of card status (READY_FOR_DATA)? */

        copy_write_sectors(write_buf, FIFO_SIZE);

        write_buf += FIFO_SIZE*2; /* Advance one chunk of 16 words */
        /* TODO: Switch bank if necessary */

        last_disk_activity = current_tick;
    }

    timeout = current_tick + WRITE_TIMEOUT;

    while((STATUS_REG & DATA_DONE) == 0) {
        if(current_tick >= timeout)
        {
            sd_send_command(STOP_TRANSMISSION, 0, 1);
            sd_read_response(&response, 1);
            goto retry;
        }
    }
    sd_send_command(STOP_TRANSMISSION, 0, 1);
    sd_read_response(&response, 1);

    sd_wait_for_state(card, TRAN);
    mutex_unlock(&sd_mtx);
    ata_led(false);
    return ret;
}

static void sd_thread(void)
{
    struct event ev;
    bool idle_notified = false;
    
    while (1) {
        queue_wait_w_tmo(&sd_queue, &ev, HZ);
        switch ( ev.id ) 
        {
            default:
                if (TIME_BEFORE(current_tick, last_disk_activity+(3*HZ)))
                {
                    idle_notified = false;
                }
                else
                {
                    if (!idle_notified)
                    {
                        call_ata_idle_notifys(false);
                        idle_notified = true;
                    }
                }
                break;
        }
    }
}


void ata_spindown(int seconds)
{
    (void)seconds;
}

bool ata_disk_is_active(void)
{
  return 0;
}

void ata_sleep(void)
{
}

void ata_spin(void)
{
}

/* Hardware reset protocol as specified in chapter 9.1, ATA spec draft v5 */
int ata_hard_reset(void)
{
  return 0;
}

int ata_soft_reset(void)
{
  return 0;
}

void ata_enable(bool on)
{
    (void)on;
}

unsigned short* ata_get_identify(void)
{
    return identify_info;
}

int ata_init(void)
{
    sd_init_device();
    if ( !initialized ) 
    {
        queue_init(&sd_queue, true);
        create_thread(sd_thread, sd_stack,
                      sizeof(sd_stack), sd_thread_name IF_PRIO(, PRIORITY_SYSTEM));
        initialized = true;
    }

    return 0;
}