2008-11-26 15:38:10 +00:00
|
|
|
/***************************************************************************
|
|
|
|
* __________ __ ___.
|
|
|
|
* Open \______ \ ____ ____ | | _\_ |__ _______ ___
|
|
|
|
* Source | _// _ \_/ ___\| |/ /| __ \ / _ \ \/ /
|
|
|
|
* Jukebox | | ( <_> ) \___| < | \_\ ( <_> > < <
|
|
|
|
* Firmware |____|_ /\____/ \___ >__|_ \|___ /\____/__/\_ \
|
|
|
|
* \/ \/ \/ \/ \/
|
|
|
|
* $Id$
|
|
|
|
*
|
|
|
|
* Copyright (C) 2008 by Maurus Cuelenaere
|
|
|
|
*
|
2008-06-28 18:10:04 +00:00
|
|
|
* This program is free software; you can redistribute it and/or
|
|
|
|
* modify it under the terms of the GNU General Public License
|
|
|
|
* as published by the Free Software Foundation; either version 2
|
|
|
|
* of the License, or (at your option) any later version.
|
2008-11-26 15:38:10 +00:00
|
|
|
*
|
|
|
|
* This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY
|
|
|
|
* KIND, either express or implied.
|
|
|
|
*
|
|
|
|
****************************************************************************/
|
|
|
|
|
|
|
|
#include "config.h"
|
|
|
|
#include "kernel.h"
|
|
|
|
#include "thread.h"
|
|
|
|
#include "system.h"
|
|
|
|
#include "dma-target.h"
|
|
|
|
#include "dm320.h"
|
2011-01-02 23:02:55 +00:00
|
|
|
#include "ata.h"
|
2008-11-26 15:38:10 +00:00
|
|
|
#include "ata-target.h"
|
2011-01-02 23:09:01 +00:00
|
|
|
#include "ata-defines.h"
|
2008-11-26 15:38:10 +00:00
|
|
|
#include <stdbool.h>
|
|
|
|
|
|
|
|
#define CS1_START 0x50000000
|
|
|
|
#define CS2_START 0x60000000
|
|
|
|
#define SDRAM_START 0x00900000
|
|
|
|
#define FLASH_START 0x00100000
|
|
|
|
#define CF_START 0x40000000
|
|
|
|
#define SSFDC_START 0x48000000
|
|
|
|
|
2011-03-02 08:49:38 +00:00
|
|
|
static struct semaphore transfer_completion_signal;
|
2008-11-26 15:38:10 +00:00
|
|
|
|
|
|
|
static bool dma_in_progress = false;
|
|
|
|
|
|
|
|
void MTC0(void)
|
|
|
|
{
|
|
|
|
IO_INTC_IRQ1 = INTR_IRQ1_MTC0;
|
2011-03-02 08:49:38 +00:00
|
|
|
semaphore_release(&transfer_completion_signal);
|
2008-11-26 15:38:10 +00:00
|
|
|
dma_in_progress = false;
|
|
|
|
}
|
|
|
|
|
|
|
|
void dma_start(const void* addr, size_t size)
|
|
|
|
{
|
|
|
|
/* Compatibility with Gigabeat S in dma_start.c */
|
|
|
|
(void) addr;
|
|
|
|
(void) size;
|
|
|
|
}
|
|
|
|
|
|
|
|
#define ATA_DEST (ATA_IOBASE-CS1_START)
|
|
|
|
void dma_ata_read(unsigned char* buf, int shortcount)
|
|
|
|
{
|
|
|
|
if(dma_in_progress)
|
2011-03-02 08:49:38 +00:00
|
|
|
semaphore_wait(&transfer_completion_signal, TIMEOUT_BLOCK);
|
2008-11-26 15:38:10 +00:00
|
|
|
|
|
|
|
while((unsigned long)buf & 0x1F)
|
|
|
|
{
|
|
|
|
unsigned short tmp;
|
2011-01-02 22:51:47 +00:00
|
|
|
tmp = ATA_IN16(ATA_DATA);
|
2008-11-26 15:38:10 +00:00
|
|
|
*buf++ = tmp & 0xFF;
|
|
|
|
*buf++ = tmp >> 8;
|
|
|
|
shortcount--;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!shortcount)
|
|
|
|
return;
|
|
|
|
|
|
|
|
IO_SDRAM_SDDMASEL = 0x0820; /* 32-byte burst mode transfer */
|
|
|
|
IO_EMIF_DMAMTCSEL = 1; /* Select CS1 */
|
|
|
|
IO_EMIF_AHBADDH = ((unsigned long)buf >> 16) & 0x7FFF; /* Set variable address */
|
|
|
|
IO_EMIF_AHBADDL = (unsigned long)buf & 0xFFFF;
|
|
|
|
IO_EMIF_MTCADDH = ( (1 << 15) | (ATA_DEST >> 16) ); /* Set fixed address */
|
|
|
|
IO_EMIF_MTCADDL = ATA_DEST & 0xFFFF;
|
|
|
|
IO_EMIF_DMASIZE = shortcount/2; /* 16-bits *2 = 1 word */
|
|
|
|
IO_EMIF_DMACTL = 3; /* Select MTC->AHB and start transfer */
|
|
|
|
|
|
|
|
dma_in_progress = true;
|
2011-03-02 08:49:38 +00:00
|
|
|
semaphore_wait(&transfer_completion_signal, TIMEOUT_BLOCK);
|
2008-11-26 15:38:10 +00:00
|
|
|
|
|
|
|
if(shortcount % 2)
|
|
|
|
{
|
|
|
|
unsigned short tmp;
|
2011-01-02 22:51:47 +00:00
|
|
|
tmp = ATA_IN16(ATA_DATA);
|
2008-11-26 15:38:10 +00:00
|
|
|
*buf++ = tmp & 0xFF;
|
|
|
|
*buf++ = tmp >> 8;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void dma_ata_write(unsigned char* buf, int wordcount)
|
|
|
|
{
|
|
|
|
if(dma_in_progress)
|
2011-03-02 08:49:38 +00:00
|
|
|
semaphore_wait(&transfer_completion_signal, TIMEOUT_BLOCK);
|
2008-11-26 15:38:10 +00:00
|
|
|
|
|
|
|
while((unsigned long)buf & 0x1F)
|
|
|
|
{
|
|
|
|
unsigned short tmp;
|
|
|
|
tmp = (unsigned short) *buf++;
|
|
|
|
tmp |= (unsigned short) *buf++ << 8;
|
2011-01-02 22:51:47 +00:00
|
|
|
ATA_OUT16(ATA_DATA, tmp);
|
2008-11-26 15:38:10 +00:00
|
|
|
wordcount--;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!wordcount)
|
|
|
|
return;
|
|
|
|
|
|
|
|
IO_SDRAM_SDDMASEL = 0x0830; /* 32-byte burst mode transfer */
|
|
|
|
IO_EMIF_DMAMTCSEL = 1; /* Select CS1 */
|
|
|
|
IO_EMIF_AHBADDH = ((unsigned long)buf >> 16) & ~(1 << 15); /* Set variable address */
|
|
|
|
IO_EMIF_AHBADDL = (unsigned long)buf & 0xFFFF;
|
|
|
|
IO_EMIF_MTCADDH = ( (1 << 15) | (ATA_DEST >> 16) ); /* Set fixed address */
|
|
|
|
IO_EMIF_MTCADDL = ATA_DEST & 0xFFFF;
|
|
|
|
IO_EMIF_DMASIZE = (wordcount+1)/2;
|
|
|
|
IO_EMIF_DMACTL = 1; /* Select AHB->MTC and start transfer */
|
|
|
|
|
|
|
|
dma_in_progress = true;
|
2011-03-02 08:49:38 +00:00
|
|
|
semaphore_wait(&transfer_completion_signal, TIMEOUT_BLOCK);
|
2008-11-26 15:38:10 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void dma_init(void)
|
|
|
|
{
|
|
|
|
IO_INTC_EINT1 |= INTR_EINT1_MTC0; /* enable MTC interrupt */
|
2011-03-02 08:49:38 +00:00
|
|
|
semaphore_init(&transfer_completion_signal, 1, 0);
|
2008-11-26 15:38:10 +00:00
|
|
|
dma_in_progress = false;
|
|
|
|
}
|