Subversion Repositories freemyipod

Rev

Details | Last modification | View Log | RSS feed

Rev Author Line No. Line
301 theseven 1
/***************************************************************************
2
 *             __________               __   ___.
3
 *   Open      \______   \ ____   ____ |  | _\_ |__   _______  ___
4
 *   Source     |       _//  _ \_/ ___\|  |/ /| __ \ /  _ \  \/  /
5
 *   Jukebox    |    |   (  <_> )  \___|    < | \_\ (  <_> > <  <
6
 *   Firmware   |____|_  /\____/ \___  >__|_ \|___  /\____/__/\_ \
7
 *                     \/            \/     \/    \/            \/
8
 * $Id$
9
 *
10
 * Copyright (C) 2007 Dave Chapman
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 "thread.h"
23
#include "disk.h"
24
#include "storage.h"
339 theseven 25
#include "storage_ata-target.h"
301 theseven 26
#include "timer.h"
27
#include "../ipodnano3g/s5l8702.h"
28
 
29
/** static, private data **/ 
30
uint16_t ata_identify_data[0x100];
31
bool ata_lba48;
32
bool ata_dma;
33
uint64_t ata_total_sectors;
34
static struct mutex ata_mutex;
35
static struct wakeup ata_wakeup;
36
static uint32_t ata_dma_flags;
37
static long ata_last_activity_value = -1;
38
static long ata_sleep_timeout = 20000000;
39
static uint32_t ata_stack[0x80];
40
static bool ata_powered;
41
 
328 theseven 42
#ifdef ATA_HAVE_BBT
43
#include "panic.h"
44
uint16_t ata_bbt[ATA_BBT_PAGES][0x20];
339 theseven 45
uint64_t ata_virtual_sectors;
337 theseven 46
uint32_t ata_last_offset;
47
uint64_t ata_last_phys;
301 theseven 48
 
328 theseven 49
void ata_bbt_read_sectors(uint32_t sector, uint32_t count, void* buffer)
50
{
51
    int rc = ata_rw_sectors_internal(sector, count, buffer, false);
52
    if (IS_ERR(rc))
53
        panicf(PANIC_KILLTHREAD, "ATA: Error %08X while reading BBT (sector %d, count %d)\n",
54
               rc, sector, count);
55
}
56
#endif
57
 
58
 
301 theseven 59
static uint16_t ata_read_cbr(uint32_t volatile* reg)
60
{
317 theseven 61
    while (!(ATA_PIO_READY & 2)) yield();
301 theseven 62
    volatile uint32_t dummy = *reg;
317 theseven 63
    while (!(ATA_PIO_READY & 1)) yield();
301 theseven 64
    return ATA_PIO_RDATA;
65
}
66
 
67
static void ata_write_cbr(uint32_t volatile* reg, uint16_t data)
68
{
317 theseven 69
    while (!(ATA_PIO_READY & 2)) yield();
301 theseven 70
    *reg = data;
71
}
72
 
73
static int ata_wait_for_not_bsy(long timeout)
74
{
75
    long startusec = USEC_TIMER;
76
    while (true)
77
    {
78
        uint8_t csd = ata_read_cbr(&ATA_PIO_CSD);
79
        if (!(csd & BIT(7))) return 0;
80
        if (TIMEOUT_EXPIRED(startusec, timeout)) RET_ERR(0);
81
    }
82
}
83
 
84
static int ata_wait_for_rdy(long timeout)
85
{
86
    long startusec = USEC_TIMER;
87
    PASS_RC(ata_wait_for_not_bsy(timeout), 1, 0);
88
    while (true)
89
    {
90
        uint8_t dad = ata_read_cbr(&ATA_PIO_DAD);
91
        if (dad & BIT(6)) return 0;
92
        if (TIMEOUT_EXPIRED(startusec, timeout)) RET_ERR(1);
93
    }
94
}
95
 
96
static int ata_wait_for_start_of_transfer(long timeout)
97
{
98
    long startusec = USEC_TIMER;
99
    PASS_RC(ata_wait_for_not_bsy(timeout), 2, 0);
100
    while (true)
101
    {
102
        uint8_t dad = ata_read_cbr(&ATA_PIO_DAD);
103
        if (dad & BIT(0)) RET_ERR(1);
104
        if ((dad & (BIT(7) | BIT(3))) == BIT(3)) return 0;
105
        if (TIMEOUT_EXPIRED(startusec, timeout)) RET_ERR(2);
106
    }
107
}
108
 
109
static int ata_wait_for_end_of_transfer(long timeout)
110
{
111
    PASS_RC(ata_wait_for_not_bsy(timeout), 2, 0);
112
    uint8_t dad = ata_read_cbr(&ATA_PIO_DAD);
113
    if (dad & BIT(0)) RET_ERR(1);
114
    if ((dad & (BIT(3) | BITRANGE(5, 7))) == BIT(6)) return 0;
115
    RET_ERR(2);
116
}    
117
 
118
int ata_identify(uint16_t* buf)
119
{
120
    int i;
121
    PASS_RC(ata_wait_for_not_bsy(10000000), 1, 0);
122
    ata_write_cbr(&ATA_PIO_DVR, 0);
123
    ata_write_cbr(&ATA_PIO_CSD, 0xec);
124
    PASS_RC(ata_wait_for_start_of_transfer(10000000), 1, 1);
125
    for (i = 0; i < 0x100; i++)
126
    {
127
        uint16_t word = ata_read_cbr(&ATA_PIO_DTR);
128
        buf[i] = (word >> 8) | (word << 8);
129
    }
130
}
131
 
132
void ata_set_active(void)
133
{
134
    ata_last_activity_value = USEC_TIMER;
135
}
136
 
317 theseven 137
int ata_set_feature(uint32_t feature, uint32_t param)
138
{
139
    PASS_RC(ata_wait_for_rdy(500000), 1, 0);
140
    ata_write_cbr(&ATA_PIO_DVR, 0);
141
    ata_write_cbr(&ATA_PIO_FED, 3);
142
    ata_write_cbr(&ATA_PIO_SCR, param);
143
    ata_write_cbr(&ATA_PIO_CSD, feature);
144
    PASS_RC(ata_wait_for_rdy(500000), 1, 1);
145
    return 0;
146
}
147
 
301 theseven 148
int ata_power_up()
149
{
150
    ata_set_active();
151
    i2c_sendbyte(0, 0xe6, 0x1b, 1);
152
    clockgate_enable(5, true);
153
    ATA_CFG = BIT(0);
154
    sleep(1000);
155
    ATA_CFG = 0;
156
    sleep(6000);
157
    ATA_SWRST = BIT(0);
158
    sleep(500);
159
    ATA_SWRST = 0;
160
    sleep(90000);
161
    ATA_CONTROL = BIT(0);
162
    sleep(200000);
163
    ATA_PIO_TIME = 0x191f7;
164
    ATA_PIO_LHR = 0;
165
    while (!(ATA_PIO_READY & BIT(1))) sleep(100);
166
    PASS_RC(ata_identify(ata_identify_data), 2, 0);
167
    uint32_t piotime = 0x11f3;
168
    uint32_t mdmatime = 0x1c175;
169
    uint32_t udmatime = 0x5071152;
170
    uint32_t param = 0;
171
    ata_dma_flags = 0;
172
    ata_lba48 = ata_identify_data[83] & BIT(10) ? true : false;
173
    if (ata_lba48)
174
        ata_total_sectors = ata_identify_data[100]
175
                          | (((uint64_t)ata_identify_data[101]) << 16)
176
                          | (((uint64_t)ata_identify_data[102]) << 32)
177
                          | (((uint64_t)ata_identify_data[103]) << 48);
178
    else ata_total_sectors = ata_identify_data[60] | (((uint32_t)ata_identify_data[61]) << 16);
328 theseven 179
    ata_total_sectors >>= 3;
301 theseven 180
    if (ata_identify_data[53] & BIT(1))
181
    {
182
        if (ata_identify_data[64] & BIT(1)) piotime = 0x2072;
183
        else if (ata_identify_data[64] & BIT(0)) piotime = 0x7083;
184
    }
185
    if (ata_identify_data[63] & BIT(2))
186
    {
187
        mdmatime = 0x5072;
188
        param = 0x22;
189
    }
190
    else if (ata_identify_data[63] & BIT(1))
191
    {
192
        mdmatime = 0x7083;
193
        param = 0x21;
194
    }
195
    if (ata_identify_data[63] & BITRANGE(0, 2))
196
    {
197
        ata_dma_flags = BIT(3) | BIT(10);
198
        param |= 0x20;
199
    }
200
    if (ata_identify_data[53] & BIT(2))
201
    {
202
        if (ata_identify_data[88] & BIT(4))
203
        {
204
            udmatime = 0x2010a52;
205
            param = 0x44;
206
        }
207
        else if (ata_identify_data[88] & BIT(3))
208
        {
209
            udmatime = 0x2020a52;
210
            param = 0x43;
211
        }
212
        else if (ata_identify_data[88] & BIT(2))
213
        {
214
            udmatime = 0x3030a52;
215
            param = 0x42;
216
        }
217
        else if (ata_identify_data[88] & BIT(1))
218
        {
219
            udmatime = 0x3050a52;
220
            param = 0x41;
221
        }
222
        if (ata_identify_data[88] & BITRANGE(0, 4))
223
        {
224
            ata_dma_flags = BIT(2) | BIT(3) | BIT(9) | BIT(10);
225
            param |= 0x40;
226
        }
227
    }
228
    ata_dma = param ? true : false;
317 theseven 229
    PASS_RC(ata_set_feature(0xef, param), 2, 1);
337 theseven 230
    if (ata_identify_data[82] & BIT(5)) PASS_RC(ata_set_feature(0x02, 0), 2, 2);
231
    if (ata_identify_data[82] & BIT(6)) PASS_RC(ata_set_feature(0x55, 0), 2, 3);
301 theseven 232
    ATA_PIO_TIME = piotime;
233
    ATA_MDMA_TIME = mdmatime;
234
    ATA_UDMA_TIME = udmatime;
235
    ata_powered = true;
236
    ata_set_active();
237
    return 0;
238
}
239
 
240
void ata_power_down()
241
{
242
    ata_powered = false;
243
    ata_wait_for_rdy(1000000);
244
    ata_write_cbr(&ATA_PIO_DVR, 0);
245
    ata_write_cbr(&ATA_PIO_CSD, 0xe0);
246
    ata_wait_for_rdy(1000000);
247
    sleep(30000);
248
    ATA_CONTROL = 0;
317 theseven 249
    while (!(ATA_CONTROL & BIT(1))) yield();
301 theseven 250
    clockgate_enable(5, false);
251
    i2c_sendbyte(0, 0xe6, 0x1b, 0);
252
}
253
 
337 theseven 254
int ata_rw_chunk(uint64_t sector, uint32_t cnt, void* buffer, bool write)
255
{
256
    PASS_RC(ata_wait_for_rdy(100000), 2, 0);
257
    ata_write_cbr(&ATA_PIO_DVR, 0);
258
    if (ata_lba48)
259
    {
260
        ata_write_cbr(&ATA_PIO_SCR, cnt >> 5);
261
        ata_write_cbr(&ATA_PIO_SCR, (cnt << 3) & 0xff);
262
        ata_write_cbr(&ATA_PIO_LHR, (sector >> 37) & 0xff);
263
        ata_write_cbr(&ATA_PIO_LMR, (sector >> 29) & 0xff);
264
        ata_write_cbr(&ATA_PIO_LLR, (sector >> 21) & 0xff);
265
        ata_write_cbr(&ATA_PIO_LHR, (sector >> 13) & 0xff);
266
        ata_write_cbr(&ATA_PIO_LMR, (sector >> 5) & 0xff);
267
        ata_write_cbr(&ATA_PIO_LLR, (sector << 3) & 0xff);
268
        ata_write_cbr(&ATA_PIO_DVR, BIT(6));
269
        if (write) ata_write_cbr(&ATA_PIO_CSD, ata_dma ? 0x35 : 0x39);
270
        else ata_write_cbr(&ATA_PIO_CSD, ata_dma ? 0x25 : 0x29);
271
    }
272
    else
273
    {
274
        ata_write_cbr(&ATA_PIO_SCR, (cnt << 3) & 0xff);
275
        ata_write_cbr(&ATA_PIO_LHR, (sector >> 13) & 0xff);
276
        ata_write_cbr(&ATA_PIO_LMR, (sector >> 5) & 0xff);
277
        ata_write_cbr(&ATA_PIO_LLR, (sector << 3) & 0xff);
278
        ata_write_cbr(&ATA_PIO_DVR, BIT(6) | ((sector >> 21) & 0xf));
279
        if (write) ata_write_cbr(&ATA_PIO_CSD, ata_dma ? 0xca : 0x30);
280
        else ata_write_cbr(&ATA_PIO_CSD, ata_dma ? 0xc8 : 0xc4);
281
    }
282
    if (ata_dma)
283
    {
284
        PASS_RC(ata_wait_for_start_of_transfer(500000), 2, 1);
285
        if (write)
286
        {
287
            ATA_SBUF_START = buffer;
288
            ATA_SBUF_SIZE = SECTOR_SIZE * cnt;
289
            ATA_CFG |= BIT(4);
290
        }
291
        else
292
        {
293
            ATA_TBUF_START = buffer;
294
            ATA_TBUF_SIZE = SECTOR_SIZE * cnt;
295
            ATA_CFG &= ~BIT(4);
296
        }
297
        ATA_XFR_NUM = SECTOR_SIZE * cnt - 1;
298
        ATA_CFG |= ata_dma_flags;
299
        ATA_CFG &= ~(BIT(7) | BIT(8));
300
        wakeup_wait(&ata_wakeup, TIMEOUT_NONE);
301
        ATA_IRQ = BITRANGE(0, 4);
302
        ATA_IRQ_MASK = BIT(0);
303
        ATA_COMMAND = BIT(0);
304
        if (wakeup_wait(&ata_wakeup, 500000) == THREAD_TIMEOUT)
305
        {
306
            ATA_COMMAND = BIT(1);
307
            ATA_CFG &= ~(BITRANGE(2, 3) | BIT(12));
308
            RET_ERR(2);
309
        }
310
        ATA_COMMAND = BIT(1);
311
        ATA_CFG &= ~(BITRANGE(2, 3) | BIT(12));
312
    }
313
    else
314
    {
315
        cnt *= SECTOR_SIZE / 512;
316
        while (cnt--)
317
        {
318
            int i;
319
            PASS_RC(ata_wait_for_start_of_transfer(500000), 2, 1);
320
            if (write)
321
                for (i = 0; i < 256; i++)
322
                    ata_write_cbr(&ATA_PIO_DTR, ((uint16_t*)buffer)[i]);
323
            else
324
                for (i = 0; i < 256; i++)
325
                    ((uint16_t*)buffer)[i] = ata_read_cbr(&ATA_PIO_DTR);
326
            buffer += 512;
327
        }
328
    }
329
    PASS_RC(ata_wait_for_end_of_transfer(100000), 2, 3);
330
    return 0;
331
}
332
 
301 theseven 333
int ata_rw_sectors(uint64_t sector, uint32_t count, void* buffer, bool write)
334
{
328 theseven 335
#ifdef ATA_HAVE_BBT
336
    if (sector + count > ata_virtual_sectors) RET_ERR(0);
337
    while (count)
338
    {
337 theseven 339
        uint32_t offset;
328 theseven 340
        uint32_t l0idx = sector >> 15;
341
        uint32_t l0offs = sector & 0x7fff;
342
        uint32_t cnt = MIN(count, 0x8000 - l0offs);
343
        uint32_t l0data = ata_bbt[0][l0idx << 1];
344
        uint32_t base = ata_bbt[0][(l0idx << 1) | 1] << 12;
337 theseven 345
        if (l0data < 0x8000) offset = l0data + base;
328 theseven 346
        else
347
        {
348
            uint32_t l1idx = (sector >> 10) & 0x1f;
349
            uint32_t l1offs = sector & 0x3ff;
350
            cnt = MIN(count, 0x400 - l1offs);
351
            uint32_t l1data = ata_bbt[l0data & 0x7fff][l1idx];
337 theseven 352
            if (l1data < 0x8000) offset = l1data + base;
328 theseven 353
            else
354
            {
355
                uint32_t l2idx = (sector >> 5) & 0x1f;
356
                uint32_t l2offs = sector & 0x1f;
357
                cnt = MIN(count, 0x20 - l2offs);
358
                uint32_t l2data = ata_bbt[l1data & 0x7fff][l2idx];
337 theseven 359
                if (l2data < 0x8000) offset = l2data + base;
328 theseven 360
                else
361
                {
362
                    uint32_t l3idx = sector & 0x1f;
337 theseven 363
                    uint32_t l3data = ata_bbt[l2data & 0x7fff][l3idx];
328 theseven 364
                    for (cnt = 1; cnt < count && l3idx + cnt < 0x20; cnt++)
337 theseven 365
                        if (ata_bbt[l2data & 0x7fff][l3idx + cnt] != l3data)
328 theseven 366
                            break;
337 theseven 367
                    offset = l3data + base;
328 theseven 368
                }
369
            }
370
        }
337 theseven 371
        uint64_t phys = sector + offset;
372
        if (offset != ata_last_offset && phys - ata_last_phys < 64) ata_soft_reset();
373
        ata_last_offset = offset;
374
        ata_last_phys = phys + cnt;
328 theseven 375
        PASS_RC(ata_rw_sectors_internal(phys, cnt, buffer, write), 0, 0);
376
        buffer += cnt * SECTOR_SIZE;
377
        sector += cnt;
378
        count -= cnt;
379
    }
380
    return 0;
381
}
382
 
383
int ata_rw_sectors_internal(uint64_t sector, uint32_t count, void* buffer, bool write)
384
{
385
#endif
301 theseven 386
    if (sector + count > ata_total_sectors) RET_ERR(0);
387
    if (!ata_powered) ata_power_up();
388
    ata_set_active();
389
    if (ata_dma && write) clean_dcache();
390
    else if (ata_dma) invalidate_dcache();
391
    ATA_COMMAND = BIT(1);
392
    while (count)
393
    {
317 theseven 394
        uint32_t cnt = MIN(ata_lba48 ? 8192 : 32, count);
337 theseven 395
        int rc = -1;
396
        int tries = 3;
397
        while (tries-- && rc)
301 theseven 398
        {
337 theseven 399
            rc = ata_rw_chunk(sector, cnt, buffer, write);
400
            if (rc) ata_soft_reset();
301 theseven 401
        }
337 theseven 402
        if (rc)
301 theseven 403
        {
337 theseven 404
            void* buf = buffer;
405
            int sect;
406
            for (sect = sector; sect < sector + cnt; sect++)
407
            {
408
                rc = -1;
409
                tries = 3;
410
                while (tries-- && rc)
411
                {
412
                    rc = ata_rw_chunk(sect, 1, buf, write);
413
                    if (rc) ata_soft_reset();
414
                }
415
                if (rc) break;
416
                buf += SECTOR_SIZE;
417
            }
301 theseven 418
        }
337 theseven 419
        PASS_RC(rc, 1, 1);
420
        buffer += SECTOR_SIZE * cnt;
301 theseven 421
        sector += cnt;
422
        count -= cnt;
423
    }
424
    ata_set_active();
425
    return 0;
426
}
427
 
428
static void ata_thread(void)
429
{
430
    while (true)
431
    {
432
        mutex_lock(&ata_mutex, TIMEOUT_BLOCK);
433
        if (TIME_AFTER(USEC_TIMER, ata_last_activity_value + ata_sleep_timeout) && ata_powered)
434
            ata_power_down();
435
        mutex_unlock(&ata_mutex);
436
        sleep(1000000);
437
    }
438
}
439
 
440
/* API Functions */
441
int ata_soft_reset()
442
{
443
    mutex_lock(&ata_mutex, TIMEOUT_BLOCK);
444
    if (!ata_powered) ata_power_up();
445
    ata_set_active();
446
    ata_write_cbr(&ATA_PIO_DAD, BIT(1) | BIT(2));
447
    sleep(10);
448
    ata_write_cbr(&ATA_PIO_DAD, 0);
337 theseven 449
    PASS_RC_MTX(ata_wait_for_rdy(60000000), 0, 0, &ata_mutex);
301 theseven 450
    ata_set_active();
451
    mutex_unlock(&ata_mutex);
452
}
453
 
454
int ata_read_sectors(IF_MD2(int drive,) unsigned long start, int incount,
455
                     void* inbuf)
456
{
457
    mutex_lock(&ata_mutex, TIMEOUT_BLOCK);
337 theseven 458
    int rc = ata_rw_sectors(start, incount, inbuf, false);
301 theseven 459
    mutex_unlock(&ata_mutex);
460
    return rc;
461
}
462
 
463
int ata_write_sectors(IF_MD2(int drive,) unsigned long start, int count,
464
                      const void* outbuf)
465
{
466
    mutex_lock(&ata_mutex, TIMEOUT_BLOCK);
337 theseven 467
    int rc = ata_rw_sectors(start, count, (void*)((uint32_t)outbuf), true);
301 theseven 468
    mutex_unlock(&ata_mutex);
469
    return rc;
470
}
471
 
337 theseven 472
void ata_spindown(int seconds)
473
{
474
    ata_sleep_timeout = seconds * 1000000;
475
}
301 theseven 476
 
477
void ata_sleep(void)
478
{
479
    mutex_lock(&ata_mutex, TIMEOUT_BLOCK);
480
    ata_power_down();
481
    mutex_unlock(&ata_mutex);
482
}
483
 
484
void ata_sleepnow(void)
485
{
486
    ata_sleep();
487
}
488
 
489
void ata_close(void)
490
{
491
    ata_sleep();
492
}
493
 
494
void ata_spin(void)
495
{
496
    ata_power_up();
497
}
498
 
499
void ata_get_info(IF_MD2(int drive,) struct storage_info *info)
500
{
501
    (*info).sector_size = SECTOR_SIZE;
328 theseven 502
#ifdef ATA_HAVE_BBT
503
    (*info).num_sectors = ata_virtual_sectors;
504
#else
301 theseven 505
    (*info).num_sectors = ata_total_sectors;
328 theseven 506
#endif
301 theseven 507
    (*info).vendor = "Apple";
508
    (*info).product = "iPod Classic";
509
    (*info).revision = "1.0";
510
}
511
 
512
long ata_last_disk_activity(void)
513
{
514
    return ata_last_activity_value;
515
}
516
 
517
int ata_init(void)
518
{
519
    mutex_init(&ata_mutex);
520
    wakeup_init(&ata_wakeup);
521
    PCON(7) = 0x44444444;
522
    PCON(8) = 0x44444444;
523
    PCON(9) = 0x44444444;
524
    PCON(10) = (PCON(10) & ~0xffff) | 0x4444;
525
    ata_powered = false;
526
    ata_total_sectors = 0;
328 theseven 527
#ifdef ATA_HAVE_BBT
528
    mutex_lock(&ata_mutex, TIMEOUT_BLOCK);
529
    memset(ata_bbt, 0, sizeof(ata_bbt));
530
    ata_power_up();
531
    uint32_t* buf = (uint32_t*)(ata_bbt[ARRAYLEN(ata_bbt) - 64]);
532
    ata_bbt_read_sectors(0, 1, buf);
533
    if (!memcmp(buf, "emBIbbth", 8))
534
    {
339 theseven 535
        ata_virtual_sectors = (((uint64_t)buf[0x1fd]) << 32) | buf[0x1fc];
328 theseven 536
        uint32_t count = buf[0x1ff];
537
        if (count > (ATA_BBT_PAGES >> 6))
337 theseven 538
            panicf(PANIC_KILLTHREAD, "ATA: BBT too big! (%d pages, limit: %d)\n", count << 6, ATA_BBT_PAGES);
328 theseven 539
        uint32_t i;
540
        uint32_t cnt;
541
        for (i = 0; i < count; i += cnt)
542
        {
543
            uint32_t phys = buf[0x200 + i];
544
            for (cnt = 1; cnt < count; cnt++)
545
                if (buf[0x200 + i + cnt] != phys + cnt)
546
                    break;
547
            ata_bbt_read_sectors(phys, cnt, ata_bbt[i << 6]);
548
        }
549
    }
550
    else ata_virtual_sectors = ata_total_sectors;
551
    mutex_unlock(&ata_mutex);
552
#endif
301 theseven 553
    thread_create("ATA idle monitor", ata_thread, ata_stack,
554
                  sizeof(ata_stack), USER_THREAD, 1, true);
555
    return 0;
556
}
557
 
558
#ifdef CONFIG_STORAGE_MULTI
559
int ata_num_drives(int first_drive)
560
{
561
    /* We don't care which logical drive number(s) we have been assigned */
562
    (void)first_drive;
563
 
564
    return 1;
565
}
566
#endif
567
 
568
void INT_ATA()
569
{
570
    uint32_t ata_irq = ATA_IRQ;
571
    ATA_IRQ = ata_irq;
572
    if (ata_irq & ATA_IRQ_MASK) wakeup_signal(&ata_wakeup);
573
    ATA_IRQ_MASK = 0;
574
}