2007-09-21 15:51:53 +00:00
|
|
|
/***************************************************************************
|
|
|
|
* __________ __ ___.
|
|
|
|
* Open \______ \ ____ ____ | | _\_ |__ _______ ___
|
|
|
|
* Source | _// _ \_/ ___\| |/ /| __ \ / _ \ \/ /
|
|
|
|
* Jukebox | | ( <_> ) \___| < | \_\ ( <_> > < <
|
|
|
|
* Firmware |____|_ /\____/ \___ >__|_ \|___ /\____/__/\_ \
|
|
|
|
* \/ \/ \/ \/ \/
|
|
|
|
* $Id$
|
|
|
|
*
|
|
|
|
* Copyright (C) 2007 by Will Robertson
|
|
|
|
*
|
|
|
|
* 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 "config.h"
|
|
|
|
#include "cpu.h"
|
|
|
|
#include "kernel.h"
|
|
|
|
#include "thread.h"
|
|
|
|
#include "system.h"
|
|
|
|
#include "power.h"
|
|
|
|
#include "panic.h"
|
2008-05-05 10:53:06 +00:00
|
|
|
#include "ata.h"
|
2008-05-05 11:21:04 +00:00
|
|
|
#include "ata-target.h"
|
2008-05-05 10:53:06 +00:00
|
|
|
#include "clkctl-imx31.h"
|
|
|
|
|
|
|
|
static const struct ata_pio_timings
|
|
|
|
{
|
|
|
|
uint16_t time_2w; /* t2 during write */
|
|
|
|
uint16_t time_2r; /* t2 during read */
|
|
|
|
uint8_t time_1; /* t1 */
|
|
|
|
uint8_t time_pio_rdx; /* trd */
|
|
|
|
uint8_t time_4; /* t4 */
|
|
|
|
uint8_t time_9; /* t9 */
|
|
|
|
} pio_timings[5] =
|
|
|
|
{
|
|
|
|
[0] = /* PIO mode 0 */
|
|
|
|
{
|
|
|
|
.time_1 = 70,
|
|
|
|
.time_2w = 290,
|
|
|
|
.time_2r = 290,
|
|
|
|
.time_4 = 30,
|
|
|
|
.time_9 = 20
|
|
|
|
},
|
|
|
|
[1] = /* PIO mode 1 */
|
|
|
|
{
|
|
|
|
.time_1 = 50,
|
|
|
|
.time_2w = 290,
|
|
|
|
.time_2r = 290,
|
|
|
|
.time_4 = 20,
|
|
|
|
.time_9 = 15
|
|
|
|
},
|
|
|
|
[2] = /* PIO mode 2 */
|
|
|
|
{
|
|
|
|
.time_1 = 30,
|
|
|
|
.time_2w = 290,
|
|
|
|
.time_2r = 290,
|
|
|
|
.time_4 = 15,
|
|
|
|
.time_9 = 10
|
|
|
|
},
|
|
|
|
[3] = /* PIO mode 3 */
|
|
|
|
{
|
|
|
|
.time_1 = 30,
|
|
|
|
.time_2w = 80,
|
|
|
|
.time_2r = 80,
|
|
|
|
.time_4 = 10,
|
|
|
|
.time_9 = 10
|
|
|
|
},
|
|
|
|
[4] = /* PIO mode 4 */
|
|
|
|
{
|
|
|
|
.time_1 = 25,
|
|
|
|
.time_2w = 70,
|
|
|
|
.time_2r = 70,
|
|
|
|
.time_4 = 10,
|
|
|
|
.time_9 = 10
|
|
|
|
},
|
|
|
|
};
|
|
|
|
|
2008-05-05 11:21:04 +00:00
|
|
|
static bool initialized = false;
|
|
|
|
|
2008-05-05 10:53:06 +00:00
|
|
|
/* Setup the timing for PIO mode */
|
|
|
|
static void ata_set_pio_mode(int mode)
|
|
|
|
{
|
|
|
|
const struct ata_pio_timings * const timings = &pio_timings[mode];
|
|
|
|
|
|
|
|
/* T = period in nanoseconds */
|
|
|
|
int T = 1000 * 1000 * 1000 / imx31_clkctl_get_ata_clk();
|
|
|
|
|
|
|
|
while (!(ATA_INTERRUPT_PENDING & ATA_CONTROLLER_IDLE));
|
|
|
|
|
|
|
|
ATA_TIME_OFF = 3;
|
|
|
|
ATA_TIME_ON = 3;
|
|
|
|
|
|
|
|
ATA_TIME_1 = (timings->time_1 + T) / T;
|
|
|
|
ATA_TIME_2W = (timings->time_2w + T) / T;
|
|
|
|
ATA_TIME_2R = (timings->time_2r + T) / T;
|
|
|
|
ATA_TIME_AX = (35 + T) / T; /* tA */
|
|
|
|
ATA_TIME_PIO_RDX = 1;
|
|
|
|
ATA_TIME_4 = (timings->time_4 + T) / T;
|
|
|
|
ATA_TIME_9 = (timings->time_9 + T) / T;
|
|
|
|
}
|
2007-09-21 15:51:53 +00:00
|
|
|
|
|
|
|
void ata_reset(void)
|
|
|
|
{
|
2008-02-08 06:34:11 +00:00
|
|
|
ATA_INTF_CONTROL &= ~ATA_ATA_RST;
|
2007-09-21 15:51:53 +00:00
|
|
|
sleep(1);
|
2008-02-08 06:34:11 +00:00
|
|
|
ATA_INTF_CONTROL |= ATA_ATA_RST;
|
2007-09-21 15:51:53 +00:00
|
|
|
sleep(1);
|
2008-02-08 06:34:11 +00:00
|
|
|
|
|
|
|
while (!(ATA_INTERRUPT_PENDING & ATA_CONTROLLER_IDLE));
|
2007-09-21 15:51:53 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/* This function is called before enabling the USB bus */
|
|
|
|
void ata_enable(bool on)
|
|
|
|
{
|
|
|
|
(void)on;
|
|
|
|
}
|
|
|
|
|
|
|
|
bool ata_is_coldstart(void)
|
|
|
|
{
|
2008-02-08 06:34:11 +00:00
|
|
|
return true;
|
2007-09-21 15:51:53 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void ata_device_init(void)
|
|
|
|
{
|
2008-02-08 06:34:11 +00:00
|
|
|
ATA_INTF_CONTROL |= ATA_ATA_RST; /* Make sure we're not in reset mode */
|
|
|
|
|
2008-05-05 11:21:04 +00:00
|
|
|
if (!initialized)
|
|
|
|
{
|
|
|
|
initialized = true;
|
|
|
|
/* Setup mode 0 by default */
|
|
|
|
ata_set_pio_mode(0);
|
|
|
|
/* mode may be switched later once identify info is ready in which
|
|
|
|
* case the main driver calls back */
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
/* identify info will be ready */
|
|
|
|
ata_identify_ready();
|
|
|
|
}
|
2007-09-21 15:51:53 +00:00
|
|
|
}
|
|
|
|
|
2008-05-05 10:53:06 +00:00
|
|
|
void ata_identify_ready(void)
|
2007-09-21 15:51:53 +00:00
|
|
|
{
|
2008-05-05 10:53:06 +00:00
|
|
|
const unsigned short* identify_info = ata_get_identify();
|
|
|
|
int mode = 0;
|
|
|
|
|
|
|
|
if (identify_info[53] & (1 << 1))
|
|
|
|
{
|
|
|
|
/* Set up advanced timings */
|
|
|
|
if (identify_info[64] & (1 << 1))
|
|
|
|
mode = 4; /* Mode 0, 1, 2, 3, 4 */
|
|
|
|
else if (identify_info[64] & (1 << 0))
|
|
|
|
mode = 3; /* Mode 0, 1, 2, 3 */
|
|
|
|
else
|
|
|
|
mode = 2; /* Mode 0, 1, 2 */
|
|
|
|
}
|
|
|
|
|
|
|
|
/* If mode changed, actually set the timings */
|
|
|
|
if (mode != 0)
|
|
|
|
{
|
|
|
|
ata_set_pio_mode(mode);
|
|
|
|
}
|
2007-09-21 15:51:53 +00:00
|
|
|
}
|