1 /***************************************************************************
3 * Open \______ \ ____ ____ | | _\_ |__ _______ ___
4 * Source | _// _ \_/ ___\| |/ /| __ \ / _ \ \/ /
5 * Jukebox | | ( <_> ) \___| < | \_\ ( <_> > < <
6 * Firmware |____|_ /\____/ \___ >__|_ \|___ /\____/__/\_ \
10 * Copyright (C) 2006 by Barry Wardell
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.
17 * This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY
18 * KIND, either express or implied.
20 ****************************************************************************/
25 #define ATA_DATA (*((volatile unsigned short*)(IDE_BASE + 0x1e0)))
26 #define ATA_ERROR (*((volatile unsigned char*)(IDE_BASE + 0x1e4)))
27 #define ATA_NSECTOR (*((volatile unsigned char*)(IDE_BASE + 0x1e8)))
28 #define ATA_SECTOR (*((volatile unsigned char*)(IDE_BASE + 0x1ec)))
29 #define ATA_LCYL (*((volatile unsigned char*)(IDE_BASE + 0x1f0)))
30 #define ATA_HCYL (*((volatile unsigned char*)(IDE_BASE + 0x1f4)))
31 #define ATA_SELECT (*((volatile unsigned char*)(IDE_BASE + 0x1f8)))
32 #define ATA_COMMAND (*((volatile unsigned char*)(IDE_BASE + 0x1fc)))
33 #define ATA_CONTROL (*((volatile unsigned char*)(IDE_BASE + 0x3f8)))
35 #define STATUS_BSY 0x80
36 #define STATUS_RDY 0x40
37 #define STATUS_DF 0x20
38 #define STATUS_DRQ 0x08
39 #define STATUS_ERR 0x01
40 #define ERROR_ABRT 0x04
42 #define WRITE_PATTERN1 0xa5
43 #define WRITE_PATTERN2 0x5a
44 #define WRITE_PATTERN3 0xaa
45 #define WRITE_PATTERN4 0x55
47 #define READ_PATTERN1 0xa5
48 #define READ_PATTERN2 0x5a
49 #define READ_PATTERN3 0xaa
50 #define READ_PATTERN4 0x55
52 #define READ_PATTERN1_MASK 0xff
53 #define READ_PATTERN2_MASK 0xff
54 #define READ_PATTERN3_MASK 0xff
55 #define READ_PATTERN4_MASK 0xff
57 #if (CONFIG_CPU == PP5002)
59 #define SET_REG(reg,val) do { reg = (val); \
60 while (!(IDE_CFG_STATUS & 0x40)); \
62 #define SET_16BITREG(reg,val) reg = (val)
64 /* Plain C reading and writing. See comment in ata-as-arm.S */
66 #elif defined CPU_PP502x
68 #define SET_REG(reg,val) reg = (val)
69 #define SET_16BITREG(reg,val) reg = (val)
71 /* asm optimized reading and writing */
72 #define ATA_OPTIMIZED_READING
73 #define ATA_OPTIMIZED_WRITING
74 void copy_read_sectors(unsigned char* buf
, int wordcount
);
75 void copy_write_sectors(const unsigned char* buf
, int wordcount
);
77 #endif /* CONFIG_CPU */
82 bool ata_is_coldstart(void);
83 void ata_device_init(void);
87 /* IDE DMA controller registers */
88 #define IDE_DMA_CONTROL (*(volatile unsigned long *)(0xc3000400))
89 #define IDE_DMA_LENGTH (*(volatile unsigned long *)(0xc3000408))
90 #define IDE_DMA_ADDR (*(volatile unsigned long *)(0xc300040C))
92 /* Maximum multi-word DMA mode supported by the controller */
93 #define ATA_MAX_MWDMA 2
96 /* The PP5020 supports UDMA 4, but it needs cpu boosting and only
97 * improves performance by ~10% with a stock disk.
98 * UDMA 2 is stable at 30 Mhz.
99 * UDMA 1 is stable at 24 Mhz.
101 #if CPUFREQ_NORMAL >= 30000000
102 #define ATA_MAX_UDMA 2
103 #elif CPUFREQ_NORMAL >= 24000000
104 #define ATA_MAX_UDMA 1
106 #error "CPU speeds under 24Mhz have not been tested with DMA"
109 /* The bootloader runs at 24 Mhz and needs a slower mode */
110 #define ATA_MAX_UDMA 1
113 void ata_dma_set_mode(unsigned char mode
);
114 bool ata_dma_setup(void *addr
, unsigned long bytes
, bool write
);
115 bool ata_dma_finish(void);
117 #endif /* HAVE_ATA_DMA */