import of ftp.dlink.com/GPL/DSMG-600_reB/ppclinux.tar.gz
[linux-2.4.21-pre4.git] / drivers / ide / legacy / gayle.c
1 /*
2  *  linux/drivers/ide/gayle.c -- Amiga Gayle IDE Driver
3  *
4  *     Created 9 Jul 1997 by Geert Uytterhoeven
5  *
6  *  This file is subject to the terms and conditions of the GNU General Public
7  *  License.  See the file COPYING in the main directory of this archive for
8  *  more details.
9  */
10
11 #include <linux/config.h>
12 #include <linux/types.h>
13 #include <linux/mm.h>
14 #include <linux/interrupt.h>
15 #include <linux/blkdev.h>
16 #include <linux/hdreg.h>
17 #include <linux/ide.h>
18 #include <linux/init.h>
19 #include <linux/zorro.h>
20
21 #include <asm/setup.h>
22 #include <asm/amigahw.h>
23 #include <asm/amigaints.h>
24 #include <asm/amigayle.h>
25
26
27     /*
28      *  Bases of the IDE interfaces
29      */
30
31 #define GAYLE_BASE_4000 0xdd2020        /* A4000/A4000T */
32 #define GAYLE_BASE_1200 0xda0000        /* A1200/A600 */
33
34     /*
35      *  Offsets from one of the above bases
36      */
37
38 #define GAYLE_DATA      0x00
39 #define GAYLE_ERROR     0x06            /* see err-bits */
40 #define GAYLE_NSECTOR   0x0a            /* nr of sectors to read/write */
41 #define GAYLE_SECTOR    0x0e            /* starting sector */
42 #define GAYLE_LCYL      0x12            /* starting cylinder */
43 #define GAYLE_HCYL      0x16            /* high byte of starting cyl */
44 #define GAYLE_SELECT    0x1a            /* 101dhhhh , d=drive, hhhh=head */
45 #define GAYLE_STATUS    0x1e            /* see status-bits */
46 #define GAYLE_CONTROL   0x101a
47
48 static int gayle_offsets[IDE_NR_PORTS] __initdata = {
49     GAYLE_DATA, GAYLE_ERROR, GAYLE_NSECTOR, GAYLE_SECTOR, GAYLE_LCYL,
50     GAYLE_HCYL, GAYLE_SELECT, GAYLE_STATUS, -1, -1
51 };
52
53
54     /*
55      *  These are at different offsets from the base
56      */
57
58 #define GAYLE_IRQ_4000  0xdd3020        /* MSB = 1, Harddisk is source of */
59 #define GAYLE_IRQ_1200  0xda9000        /* interrupt */
60
61
62     /*
63      *  Offset of the secondary port for IDE doublers
64      *  Note that GAYLE_CONTROL is NOT available then!
65      */
66
67 #define GAYLE_NEXT_PORT 0x1000
68
69 #ifndef CONFIG_BLK_DEV_IDEDOUBLER
70 #define GAYLE_NUM_HWIFS         1
71 #define GAYLE_NUM_PROBE_HWIFS   GAYLE_NUM_HWIFS
72 #define GAYLE_HAS_CONTROL_REG   1
73 #define GAYLE_IDEREG_SIZE       0x2000
74 #else /* CONFIG_BLK_DEV_IDEDOUBLER */
75 #define GAYLE_NUM_HWIFS         2
76 #define GAYLE_NUM_PROBE_HWIFS   (ide_doubler ? GAYLE_NUM_HWIFS : \
77                                                GAYLE_NUM_HWIFS-1)
78 #define GAYLE_HAS_CONTROL_REG   (!ide_doubler)
79 #define GAYLE_IDEREG_SIZE       (ide_doubler ? 0x1000 : 0x2000)
80 int ide_doubler = 0;    /* support IDE doublers? */
81 #endif /* CONFIG_BLK_DEV_IDEDOUBLER */
82
83
84     /*
85      *  Check and acknowledge the interrupt status
86      */
87
88 static int gayle_ack_intr_a4000(ide_hwif_t *hwif)
89 {
90     unsigned char ch;
91
92     ch = z_readb(hwif->io_ports[IDE_IRQ_OFFSET]);
93     if (!(ch & GAYLE_IRQ_IDE))
94         return 0;
95     return 1;
96 }
97
98 static int gayle_ack_intr_a1200(ide_hwif_t *hwif)
99 {
100     unsigned char ch;
101
102     ch = z_readb(hwif->io_ports[IDE_IRQ_OFFSET]);
103     if (!(ch & GAYLE_IRQ_IDE))
104         return 0;
105     (void)z_readb(hwif->io_ports[IDE_STATUS_OFFSET]);
106     z_writeb(0x7c, hwif->io_ports[IDE_IRQ_OFFSET]);
107     return 1;
108 }
109
110     /*
111      *  Probe for a Gayle IDE interface (and optionally for an IDE doubler)
112      */
113
114 void __init gayle_init(void)
115 {
116     int a4000, i;
117
118     if (!MACH_IS_AMIGA)
119         return;
120
121     if (!(a4000 = AMIGAHW_PRESENT(A4000_IDE)) && !AMIGAHW_PRESENT(A1200_IDE))
122         return;
123
124     for (i = 0; i < GAYLE_NUM_PROBE_HWIFS; i++) {
125         ide_ioreg_t base, ctrlport, irqport;
126         ide_ack_intr_t *ack_intr;
127         hw_regs_t hw;
128         int index;
129         unsigned long phys_base, res_start, res_n;
130
131         if (a4000) {
132             phys_base = GAYLE_BASE_4000;
133             irqport = (ide_ioreg_t)ZTWO_VADDR(GAYLE_IRQ_4000);
134             ack_intr = gayle_ack_intr_a4000;
135         } else {
136             phys_base = GAYLE_BASE_1200;
137             irqport = (ide_ioreg_t)ZTWO_VADDR(GAYLE_IRQ_1200);
138             ack_intr = gayle_ack_intr_a1200;
139         }
140 /*
141  * FIXME: we now have selectable modes between mmio v/s iomio
142  */
143
144         phys_base += i*GAYLE_NEXT_PORT;
145
146         res_start = ((unsigned long)phys_base) & ~(GAYLE_NEXT_PORT-1);
147         res_n = GAYLE_IDEREG_SIZE;
148
149         if (!request_mem_region(res_start, res_n, "IDE"))
150             continue;
151
152         base = (ide_ioreg_t)ZTWO_VADDR(phys_base);
153         ctrlport = GAYLE_HAS_CONTROL_REG ? (base + GAYLE_CONTROL) : 0;
154
155         ide_setup_ports(&hw, base, gayle_offsets,
156                         ctrlport, irqport, ack_intr,
157 //                      gaule_iops,
158                         IRQ_AMIGA_PORTS);
159
160         index = ide_register_hw(&hw, NULL);
161         if (index != -1) {
162             switch (i) {
163                 case 0:
164                     printk("ide%d: Gayle IDE interface (A%d style)\n", index,
165                            a4000 ? 4000 : 1200);
166                     break;
167 #ifdef CONFIG_BLK_DEV_IDEDOUBLER
168                 case 1:
169                     printk("ide%d: IDE doubler\n", index);
170                     break;
171 #endif /* CONFIG_BLK_DEV_IDEDOUBLER */
172             }
173         } else
174             release_mem_region(res_start, res_n);
175
176 #if 1 /* TESTING */
177         if (i == 1) {
178             volatile u_short *addr = (u_short *)base;
179             u_short data;
180             printk("+++ Probing for IDE doubler... ");
181             *addr = 0xffff;
182             data = *addr;
183             printk("probe returned 0x%02x (PLEASE REPORT THIS!!)\n", data);
184         }
185 #endif /* TESTING */
186     }
187 }