1 /***************************************************************************
3 * Open \______ \ ____ ____ | | _\_ |__ _______ ___
4 * Source | _// _ \_/ ___\| |/ /| __ \ / _ \ \/ /
5 * Jukebox | | ( <_> ) \___| < | \_\ ( <_> > < <
6 * Firmware |____|_ /\____/ \___ >__|_ \|___ /\____/__/\_ \
10 * Copyright (C) 2007 by Karl Kurbjun
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.
17 * This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY
18 * KIND, either express or implied.
20 ****************************************************************************/
31 #include "ata-target.h"
32 #include "backlight-target.h"
34 /* ARESET on C7C68300 and RESET on ATA interface (Active Low) */
35 #define ATA_RESET_ENABLE (IO_GIO_BITCLR0 = 1 << 10)
36 #define ATA_RESET_DISABLE (IO_GIO_BITSET0 = 1 << 10)
38 /* ATA_EN on C7C68300 */
39 #define USB_ATA_ENABLE (IO_GIO_BITSET0 = 1 << 2)
40 #define USB_ATA_DISABLE (IO_GIO_BITCLR0 = 1 << 2)
45 sleep(1); /* > 25us */
50 /* This function is called before enabling the USB bus */
51 void ata_enable(bool on
)
59 bool ata_is_coldstart(void)
64 void ata_device_init(void)
67 ATA_RESET_DISABLE
; /* Set the pin to disable an active low reset */
68 IO_GIO_DIR0
&=~(1<<10);
72 void copy_read_sectors(unsigned char* buf
, int wordcount
)
74 __buttonlight_trigger();
76 /* Unaligned transfer - slow copy */
77 if ( (unsigned long)buf
& 1)
78 { /* not 16-bit aligned, copy byte by byte */
79 unsigned short tmp
= 0;
80 unsigned char* bufend
= buf
+ wordcount
*2;
84 *buf
++ = tmp
& 0xff; /* I assume big endian */
85 *buf
++ = tmp
>> 8; /* and don't use the SWAB16 macro */
86 } while (buf
< bufend
); /* tail loop is faster */
89 /* This should never happen, but worth watching for */
90 if(wordcount
> (1 << 18))
91 panicf("atd-meg-fx.c: copy_read_sectors: too many sectors per read!");
93 //#define GIGABEAT_DEBUG_ATA
94 #ifdef GIGABEAT_DEBUG_ATA
97 snprintf(str
, sizeof(str
), "ODD DMA to %08x, %d", buf
, wordcount
);
98 lcd_puts(10, line
, str
);
102 /* Reset the channel */
104 /* Wait for DMA controller to be ready */
105 while(DMASKTRIG0
& 0x2)
107 while(DSTAT0
& (1 << 20))
109 /* Source is ATA_DATA, on AHB Bus, Fixed */
110 DISRC0
= (int) 0x18000000;
112 /* Dest mapped to physical address, on AHB bus, increment */
114 if(DIDST0
< 0x30000000)
115 DIDST0
+= 0x30000000;
118 /* DACK/DREQ Sync to AHB, Whole service, No reload, 16-bit transfers */
119 DCON0
= ((1 << 30) | (1<<27) | (1<<22) | (1<<20)) | wordcount
;
121 /* Activate the channel */
124 invalidate_dcache_range((void *)buf
, wordcount
*2);
129 /* Wait for transfer to complete */
130 while((DSTAT0
& 0x000fffff))
132 /* Dump cache for the buffer */