Maurus Cuelenaere | 95167e0 | 2008-04-24 20:08:28 +0000 | [diff] [blame] | 1 | /***************************************************************************
|
| 2 | * __________ __ ___.
|
| 3 | * Open \______ \ ____ ____ | | _\_ |__ _______ ___
|
| 4 | * Source | _// _ \_/ ___\| |/ /| __ \ / _ \ \/ /
|
| 5 | * Jukebox | | ( <_> ) \___| < | \_\ ( <_> > < <
|
| 6 | * Firmware |____|_ /\____/ \___ >__|_ \|___ /\____/__/\_ \
|
| 7 | * \/ \/ \/ \/ \/
|
| 8 | * $Id$
|
| 9 | *
|
| 10 | * Copyright (C) 2008 by Maurus Cuelenaere
|
| 11 | *
|
Daniel Stenberg | 2acc0ac | 2008-06-28 18:10:04 +0000 | [diff] [blame^] | 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. |
Maurus Cuelenaere | 95167e0 | 2008-04-24 20:08:28 +0000 | [diff] [blame] | 16 | *
|
| 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 Cuelenaere | a6b31f1 | 2008-05-03 13:43:26 +0000 | [diff] [blame] | 30 | #include "dm320.h"
|
| 31 |
|
| 32 | void sleep_ms(int ms)
|
| 33 | {
|
| 34 | sleep(ms*HZ/1000);
|
| 35 | }
|
Maurus Cuelenaere | 95167e0 | 2008-04-24 20:08:28 +0000 | [diff] [blame] | 36 |
|
Daniel Stenberg | e1bc2d5 | 2008-04-25 21:44:18 +0000 | [diff] [blame] | 37 | void ide_power_enable(bool on)
|
| 38 | {
|
Maurus Cuelenaere | a6b31f1 | 2008-05-03 13:43:26 +0000 | [diff] [blame] | 39 | /* Disabled until figured out what's wrong */
|
Maurus Cuelenaere | 95167e0 | 2008-04-24 20:08:28 +0000 | [diff] [blame] | 40 | #if 0
|
Maurus Cuelenaere | a6b31f1 | 2008-05-03 13:43:26 +0000 | [diff] [blame] | 41 | int old_level = disable_irq_save();
|
Maurus Cuelenaere | 95167e0 | 2008-04-24 20:08:28 +0000 | [diff] [blame] | 42 | if(on)
|
| 43 | {
|
| 44 | IO_GIO_BITSET0 = (1 << 14);
|
| 45 | ata_reset();
|
| 46 | }
|
| 47 | else
|
| 48 | IO_GIO_BITCLR0 = (1 << 14);
|
Maurus Cuelenaere | a6b31f1 | 2008-05-03 13:43:26 +0000 | [diff] [blame] | 49 | restore_irq(old_level);
|
Daniel Stenberg | e1bc2d5 | 2008-04-25 21:44:18 +0000 | [diff] [blame] | 50 | #else
|
| 51 | (void)on;
|
Maurus Cuelenaere | 95167e0 | 2008-04-24 20:08:28 +0000 | [diff] [blame] | 52 | #endif
|
| 53 | }
|
| 54 |
|
Daniel Stenberg | e1bc2d5 | 2008-04-25 21:44:18 +0000 | [diff] [blame] | 55 | inline bool ide_powered()
|
| 56 | {
|
Maurus Cuelenaere | 95167e0 | 2008-04-24 20:08:28 +0000 | [diff] [blame] | 57 | #if 0
|
Daniel Stenberg | e1bc2d5 | 2008-04-25 21:44:18 +0000 | [diff] [blame] | 58 | return (IO_GIO_BITSET0 & (1 << 14));
|
Maurus Cuelenaere | 95167e0 | 2008-04-24 20:08:28 +0000 | [diff] [blame] | 59 | #else
|
| 60 | return true;
|
| 61 | #endif
|
| 62 | }
|
| 63 |
|
| 64 | void ata_reset(void)
|
| 65 | {
|
Maurus Cuelenaere | a6b31f1 | 2008-05-03 13:43:26 +0000 | [diff] [blame] | 66 | int old_level = disable_irq_save();
|
Daniel Stenberg | e1bc2d5 | 2008-04-25 21:44:18 +0000 | [diff] [blame] | 67 | if(!ide_powered())
|
| 68 | {
|
Maurus Cuelenaere | 95167e0 | 2008-04-24 20:08:28 +0000 | [diff] [blame] | 69 | ide_power_enable(true);
|
Maurus Cuelenaere | a6b31f1 | 2008-05-03 13:43:26 +0000 | [diff] [blame] | 70 | sleep_ms(150);
|
Daniel Stenberg | e1bc2d5 | 2008-04-25 21:44:18 +0000 | [diff] [blame] | 71 | }
|
| 72 | else
|
| 73 | {
|
| 74 | IO_GIO_BITSET0 = (1 << 5);
|
| 75 | IO_GIO_BITCLR0 = (1 << 3);
|
Maurus Cuelenaere | a6b31f1 | 2008-05-03 13:43:26 +0000 | [diff] [blame] | 76 | sleep_ms(1);
|
Daniel Stenberg | e1bc2d5 | 2008-04-25 21:44:18 +0000 | [diff] [blame] | 77 | }
|
| 78 | IO_GIO_BITCLR0 = (1 << 5);
|
Maurus Cuelenaere | a6b31f1 | 2008-05-03 13:43:26 +0000 | [diff] [blame] | 79 | sleep_ms(10);
|
Daniel Stenberg | e1bc2d5 | 2008-04-25 21:44:18 +0000 | [diff] [blame] | 80 | IO_GIO_BITSET0 = (1 << 3);
|
| 81 | while(!(ATA_COMMAND & STATUS_RDY))
|
Maurus Cuelenaere | a6b31f1 | 2008-05-03 13:43:26 +0000 | [diff] [blame] | 82 | sleep_ms(10);
|
| 83 | restore_irq(old_level);
|
Maurus Cuelenaere | 95167e0 | 2008-04-24 20:08:28 +0000 | [diff] [blame] | 84 | }
|
| 85 |
|
| 86 | void ata_enable(bool on)
|
| 87 | {
|
Daniel Stenberg | e1bc2d5 | 2008-04-25 21:44:18 +0000 | [diff] [blame] | 88 | (void)on;
|
| 89 | return;
|
Maurus Cuelenaere | 95167e0 | 2008-04-24 20:08:28 +0000 | [diff] [blame] | 90 | }
|
| 91 |
|
| 92 | bool ata_is_coldstart(void)
|
| 93 | {
|
| 94 | return true;
|
| 95 | }
|
| 96 |
|
| 97 | void ata_device_init(void)
|
| 98 | {
|
Maurus Cuelenaere | a6b31f1 | 2008-05-03 13:43:26 +0000 | [diff] [blame] | 99 | IO_INTC_EINT1 |= INTR_EINT1_EXT2; /* enable GIO2 interrupt */
|
Maurus Cuelenaere | 95167e0 | 2008-04-24 20:08:28 +0000 | [diff] [blame] | 100 | //TODO: mimic OF inits...
|
| 101 | return;
|
| 102 | }
|
| 103 |
|
| 104 | void GIO2(void)
|
| 105 | {
|
| 106 | #ifdef DEBUG
|
Maurus Cuelenaere | a6b31f1 | 2008-05-03 13:43:26 +0000 | [diff] [blame] | 107 | logf("GIO2 interrupt...");
|
Maurus Cuelenaere | 95167e0 | 2008-04-24 20:08:28 +0000 | [diff] [blame] | 108 | #endif
|
Maurus Cuelenaere | a6b31f1 | 2008-05-03 13:43:26 +0000 | [diff] [blame] | 109 | IO_INTC_IRQ1 = INTR_IRQ1_EXT2; /* Mask GIO2 interrupt */
|
Maurus Cuelenaere | 95167e0 | 2008-04-24 20:08:28 +0000 | [diff] [blame] | 110 | return;
|
| 111 | }
|