Jens Arnold | 31ffd7b | 2006-12-03 22:13:44 +0000 | [diff] [blame] | 1 | /*************************************************************************** |
| 2 | * __________ __ ___. |
| 3 | * Open \______ \ ____ ____ | | _\_ |__ _______ ___ |
| 4 | * Source | _// _ \_/ ___\| |/ /| __ \ / _ \ \/ / |
| 5 | * Jukebox | | ( <_> ) \___| < | \_\ ( <_> > < < |
| 6 | * Firmware |____|_ /\____/ \___ >__|_ \|___ /\____/__/\_ \ |
| 7 | * \/ \/ \/ \/ \/ |
| 8 | * $Id$ |
| 9 | * |
| 10 | * Copyright (C) 2006 by Jens Arnold |
| 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. |
Jens Arnold | 31ffd7b | 2006-12-03 22:13:44 +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 <stdbool.h> |
| 25 | #include "kernel.h" |
| 26 | #include "system.h" |
| 27 | #include "ata-target.h" |
| 28 | #include "hwcompat.h" |
| 29 | |
Jens Arnold | 28fd4b7 | 2006-12-19 09:27:41 +0000 | [diff] [blame] | 30 | #define ATA_CONTROL1 ((volatile unsigned char*)0x06200206) |
| 31 | #define ATA_CONTROL2 ((volatile unsigned char*)0x06200306) |
| 32 | |
Jens Arnold | 31ffd7b | 2006-12-03 22:13:44 +0000 | [diff] [blame] | 33 | volatile unsigned char* ata_control; |
Jens Arnold | 31ffd7b | 2006-12-03 22:13:44 +0000 | [diff] [blame] | 34 | |
| 35 | void 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 Arnold | 31ffd7b | 2006-12-03 22:13:44 +0000 | [diff] [blame] | 46 | void 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 | |
| 56 | void 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 Arnold | 28fd4b7 | 2006-12-19 09:27:41 +0000 | [diff] [blame] | 61 | |
Jens Arnold | 8636e69 | 2007-04-11 23:51:00 +0000 | [diff] [blame] | 62 | if (HW_MASK & ATA_ADDRESS_200) |
Jens Arnold | 28fd4b7 | 2006-12-19 09:27:41 +0000 | [diff] [blame] | 63 | ata_control = ATA_CONTROL1; |
Jens Arnold | 28fd4b7 | 2006-12-19 09:27:41 +0000 | [diff] [blame] | 64 | else |
Jens Arnold | 28fd4b7 | 2006-12-19 09:27:41 +0000 | [diff] [blame] | 65 | ata_control = ATA_CONTROL2; |
Jens Arnold | 31ffd7b | 2006-12-03 22:13:44 +0000 | [diff] [blame] | 66 | } |
| 67 | |
| 68 | bool ata_is_coldstart(void) |
| 69 | { |
| 70 | return (PACR2 & 0x4000) != 0; |
| 71 | } |