blob: 6b58481b8b37c620b73905a5bfbb9fedcb94532d [file] [log] [blame]
Jens Arnold31ffd7b2006-12-03 22:13:44 +00001/***************************************************************************
2 * __________ __ ___.
3 * Open \______ \ ____ ____ | | _\_ |__ _______ ___
4 * Source | _// _ \_/ ___\| |/ /| __ \ / _ \ \/ /
5 * Jukebox | | ( <_> ) \___| < | \_\ ( <_> > < <
6 * Firmware |____|_ /\____/ \___ >__|_ \|___ /\____/__/\_ \
7 * \/ \/ \/ \/ \/
8 * $Id$
9 *
10 * Copyright (C) 2006 by Jens Arnold
11 *
Daniel Stenberg2acc0ac2008-06-28 18:10:04 +000012 * 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.
Jens Arnold31ffd7b2006-12-03 22:13:44 +000016 *
17 * This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY
18 * KIND, either express or implied.
19 *
20 ****************************************************************************/
21
22#include "config.h"
23#include "cpu.h"
24#include <stdbool.h>
25#include "kernel.h"
26#include "system.h"
27#include "ata-target.h"
28#include "hwcompat.h"
29
Jens Arnold28fd4b72006-12-19 09:27:41 +000030#define ATA_CONTROL1 ((volatile unsigned char*)0x06200206)
31#define ATA_CONTROL2 ((volatile unsigned char*)0x06200306)
32
Jens Arnold31ffd7b2006-12-03 22:13:44 +000033volatile unsigned char* ata_control;
Jens Arnold31ffd7b2006-12-03 22:13:44 +000034
35void ata_reset(void)
36{
37 /* state HRR0 */
38 and_b(~0x02, &PADRH); /* assert _RESET */
39 sleep(1); /* > 25us */
40
41 /* state HRR1 */
42 or_b(0x02, &PADRH); /* negate _RESET */
43 sleep(1); /* > 2ms */
44}
45
Jens Arnold31ffd7b2006-12-03 22:13:44 +000046void ata_enable(bool on)
47{
48 if(on)
49 and_b(~0x80, &PADRL); /* enable ATA */
50 else
51 or_b(0x80, &PADRL); /* disable ATA */
52
53 or_b(0x80, &PAIORL);
54}
55
56void ata_device_init(void)
57{
58 or_b(0x02, &PAIORH); /* output for ATA reset */
59 or_b(0x02, &PADRH); /* release ATA reset */
60 PACR2 &= 0xBFFF; /* GPIO function for PA7 (IDE enable) */
Jens Arnold28fd4b72006-12-19 09:27:41 +000061
Jens Arnold8636e692007-04-11 23:51:00 +000062 if (HW_MASK & ATA_ADDRESS_200)
Jens Arnold28fd4b72006-12-19 09:27:41 +000063 ata_control = ATA_CONTROL1;
Jens Arnold28fd4b72006-12-19 09:27:41 +000064 else
Jens Arnold28fd4b72006-12-19 09:27:41 +000065 ata_control = ATA_CONTROL2;
Jens Arnold31ffd7b2006-12-03 22:13:44 +000066}
67
68bool ata_is_coldstart(void)
69{
70 return (PACR2 & 0x4000) != 0;
71}