Subversion Repositories freemyipod

Rev

Rev 301 | Show entire file | Ignore whitespace | Details | Blame | Last modification | View Log | RSS feed

Rev 301 Rev 316
Line 236... Line 236...
236
    if (ata_dma && write) clean_dcache();
236
    if (ata_dma && write) clean_dcache();
237
    else if (ata_dma) invalidate_dcache();
237
    else if (ata_dma) invalidate_dcache();
238
    ATA_COMMAND = BIT(1);
238
    ATA_COMMAND = BIT(1);
239
    while (count)
239
    while (count)
240
    {
240
    {
241
        uint32_t cnt = MIN(64, count);
241
        uint32_t cnt = MIN(32, count);
242
        PASS_RC(ata_wait_for_rdy(100000), 2, 0);
242
        PASS_RC(ata_wait_for_rdy(100000), 2, 0);
243
        ata_write_cbr(&ATA_PIO_DVR, 0);
243
        ata_write_cbr(&ATA_PIO_DVR, 0);
244
        if (ata_lba48)
244
        if (ata_lba48)
245
        {
245
        {
246
            ata_write_cbr(&ATA_PIO_SCR, cnt >> 5);
246
            ata_write_cbr(&ATA_PIO_SCR, cnt >> 5);
Line 267... Line 267...
267
        }
267
        }
268
        sector += cnt;
268
        sector += cnt;
269
        count -= cnt;
269
        count -= cnt;
270
        if (ata_dma)
270
        if (ata_dma)
271
        {
271
        {
-
 
272
            PASS_RC(ata_wait_for_start_of_transfer(10000000), 2, 1);
272
            if (write)
273
            if (write)
273
            {
274
            {
274
                ATA_SBUF_START = buffer;
275
                ATA_SBUF_START = buffer;
275
                ATA_SBUF_SIZE = SECTOR_SIZE * cnt;
276
                ATA_SBUF_SIZE = SECTOR_SIZE * cnt;
276
                ATA_CFG |= BIT(4);
277
                ATA_CFG |= BIT(4);
Line 286... Line 287...
286
            ATA_CFG &= ~(BIT(7) | BIT(8));
287
            ATA_CFG &= ~(BIT(7) | BIT(8));
287
            wakeup_wait(&ata_wakeup, TIMEOUT_NONE);
288
            wakeup_wait(&ata_wakeup, TIMEOUT_NONE);
288
            ATA_IRQ = BITRANGE(0, 4);
289
            ATA_IRQ = BITRANGE(0, 4);
289
            ATA_IRQ_MASK = BIT(0);
290
            ATA_IRQ_MASK = BIT(0);
290
            ATA_COMMAND = BIT(0);
291
            ATA_COMMAND = BIT(0);
291
            if (wakeup_wait(&ata_wakeup, 3000000) == THREAD_TIMEOUT)
292
            if (wakeup_wait(&ata_wakeup, 10000000) == THREAD_TIMEOUT)
292
            {
293
            {
293
                ATA_COMMAND = BIT(1);
294
                ATA_COMMAND = BIT(1);
294
                ATA_CFG &= ~(BITRANGE(2, 3) | BIT(12));
295
                ATA_CFG &= ~(BITRANGE(2, 3) | BIT(12));
295
                RET_ERR(2);
296
                RET_ERR(2);
296
            }
297
            }
Line 302... Line 303...
302
        {
303
        {
303
            cnt *= SECTOR_SIZE / 512;
304
            cnt *= SECTOR_SIZE / 512;
304
            while (cnt--)
305
            while (cnt--)
305
            {
306
            {
306
                int i;
307
                int i;
307
                PASS_RC(ata_wait_for_start_of_transfer(3000000), 2, 1);
308
                PASS_RC(ata_wait_for_start_of_transfer(10000000), 2, 1);
308
                if (write)
309
                if (write)
309
                    for (i = 0; i < 256; i++)
310
                    for (i = 0; i < 256; i++)
310
                        ata_write_cbr(&ATA_PIO_DTR, ((uint16_t*)buffer)[i]);
311
                        ata_write_cbr(&ATA_PIO_DTR, ((uint16_t*)buffer)[i]);
311
                else
312
                else
312
                    for (i = 0; i < 256; i++)
313
                    for (i = 0; i < 256; i++)
Line 348... Line 349...
348
 
349
 
349
int ata_read_sectors(IF_MD2(int drive,) unsigned long start, int incount,
350
int ata_read_sectors(IF_MD2(int drive,) unsigned long start, int incount,
350
                     void* inbuf)
351
                     void* inbuf)
351
{
352
{
352
    mutex_lock(&ata_mutex, TIMEOUT_BLOCK);
353
    mutex_lock(&ata_mutex, TIMEOUT_BLOCK);
353
    int tries = 5;
354
    int tries = 3;
354
    int rc = -1;
355
    int rc = -1;
355
    while (--tries && rc)
356
    while (--tries && rc)
356
    {
357
    {
357
        rc = ata_rw_sectors(start, incount, inbuf, false);
358
        rc = ata_rw_sectors(start, incount, inbuf, false);
358
        if (rc) ata_soft_reset();
359
        if (rc) ata_soft_reset();
Line 363... Line 364...
363
 
364
 
364
int ata_write_sectors(IF_MD2(int drive,) unsigned long start, int count,
365
int ata_write_sectors(IF_MD2(int drive,) unsigned long start, int count,
365
                      const void* outbuf)
366
                      const void* outbuf)
366
{
367
{
367
    mutex_lock(&ata_mutex, TIMEOUT_BLOCK);
368
    mutex_lock(&ata_mutex, TIMEOUT_BLOCK);
368
    int tries = 5;
369
    int tries = 3;
369
    int rc = -1;
370
    int rc = -1;
370
    while (--tries && rc)
371
    while (--tries && rc)
371
    {
372
    {
372
        rc = ata_rw_sectors(start, count, (void*)((uint32_t)outbuf), true);
373
        rc = ata_rw_sectors(start, count, (void*)((uint32_t)outbuf), true);
373
        if (rc) ata_soft_reset();
374
        if (rc) ata_soft_reset();