blob: 0c4dd4bfbe0c58a2e57848e4f845c8b706d20ab1 [file] [log] [blame]
Maurus Cuelenaere95167e02008-04-24 20:08:28 +00001/***************************************************************************
2 * __________ __ ___.
3 * Open \______ \ ____ ____ | | _\_ |__ _______ ___
4 * Source | _// _ \_/ ___\| |/ /| __ \ / _ \ \/ /
5 * Jukebox | | ( <_> ) \___| < | \_\ ( <_> > < <
6 * Firmware |____|_ /\____/ \___ >__|_ \|___ /\____/__/\_ \
7 * \/ \/ \/ \/ \/
8 * $Id$
9 *
10 * Copyright (C) 2008 by Maurus Cuelenaere
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.
Maurus Cuelenaere95167e02008-04-24 20:08:28 +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 "kernel.h"
25#include "thread.h"
26#include "system.h"
27#include "power.h"
28#include "panic.h"
29#include "ata-target.h"
Maurus Cuelenaerea6b31f12008-05-03 13:43:26 +000030#include "dm320.h"
31
32void sleep_ms(int ms)
33{
34 sleep(ms*HZ/1000);
35}
Maurus Cuelenaere95167e02008-04-24 20:08:28 +000036
Daniel Stenberge1bc2d52008-04-25 21:44:18 +000037void ide_power_enable(bool on)
38{
Maurus Cuelenaerea6b31f12008-05-03 13:43:26 +000039/* Disabled until figured out what's wrong */
Maurus Cuelenaere95167e02008-04-24 20:08:28 +000040#if 0
Maurus Cuelenaerea6b31f12008-05-03 13:43:26 +000041 int old_level = disable_irq_save();
Maurus Cuelenaere95167e02008-04-24 20:08:28 +000042 if(on)
43 {
44 IO_GIO_BITSET0 = (1 << 14);
45 ata_reset();
46 }
47 else
48 IO_GIO_BITCLR0 = (1 << 14);
Maurus Cuelenaerea6b31f12008-05-03 13:43:26 +000049 restore_irq(old_level);
Daniel Stenberge1bc2d52008-04-25 21:44:18 +000050#else
51 (void)on;
Maurus Cuelenaere95167e02008-04-24 20:08:28 +000052#endif
53}
54
Daniel Stenberge1bc2d52008-04-25 21:44:18 +000055inline bool ide_powered()
56{
Maurus Cuelenaere95167e02008-04-24 20:08:28 +000057#if 0
Daniel Stenberge1bc2d52008-04-25 21:44:18 +000058 return (IO_GIO_BITSET0 & (1 << 14));
Maurus Cuelenaere95167e02008-04-24 20:08:28 +000059#else
60 return true;
61#endif
62}
63
64void ata_reset(void)
65{
Maurus Cuelenaerea6b31f12008-05-03 13:43:26 +000066 int old_level = disable_irq_save();
Daniel Stenberge1bc2d52008-04-25 21:44:18 +000067 if(!ide_powered())
68 {
Maurus Cuelenaere95167e02008-04-24 20:08:28 +000069 ide_power_enable(true);
Maurus Cuelenaerea6b31f12008-05-03 13:43:26 +000070 sleep_ms(150);
Daniel Stenberge1bc2d52008-04-25 21:44:18 +000071 }
72 else
73 {
74 IO_GIO_BITSET0 = (1 << 5);
75 IO_GIO_BITCLR0 = (1 << 3);
Maurus Cuelenaerea6b31f12008-05-03 13:43:26 +000076 sleep_ms(1);
Daniel Stenberge1bc2d52008-04-25 21:44:18 +000077 }
78 IO_GIO_BITCLR0 = (1 << 5);
Maurus Cuelenaerea6b31f12008-05-03 13:43:26 +000079 sleep_ms(10);
Daniel Stenberge1bc2d52008-04-25 21:44:18 +000080 IO_GIO_BITSET0 = (1 << 3);
81 while(!(ATA_COMMAND & STATUS_RDY))
Maurus Cuelenaerea6b31f12008-05-03 13:43:26 +000082 sleep_ms(10);
83 restore_irq(old_level);
Maurus Cuelenaere95167e02008-04-24 20:08:28 +000084}
85
86void ata_enable(bool on)
87{
Daniel Stenberge1bc2d52008-04-25 21:44:18 +000088 (void)on;
89 return;
Maurus Cuelenaere95167e02008-04-24 20:08:28 +000090}
91
92bool ata_is_coldstart(void)
93{
94 return true;
95}
96
97void ata_device_init(void)
98{
Maurus Cuelenaerea6b31f12008-05-03 13:43:26 +000099 IO_INTC_EINT1 |= INTR_EINT1_EXT2; /* enable GIO2 interrupt */
Maurus Cuelenaere95167e02008-04-24 20:08:28 +0000100 //TODO: mimic OF inits...
101 return;
102}
103
104void GIO2(void)
105{
106#ifdef DEBUG
Maurus Cuelenaerea6b31f12008-05-03 13:43:26 +0000107 logf("GIO2 interrupt...");
Maurus Cuelenaere95167e02008-04-24 20:08:28 +0000108#endif
Maurus Cuelenaerea6b31f12008-05-03 13:43:26 +0000109 IO_INTC_IRQ1 = INTR_IRQ1_EXT2; /* Mask GIO2 interrupt */
Maurus Cuelenaere95167e02008-04-24 20:08:28 +0000110 return;
111}