Import 2.3.15pre2
[davej-history.git] / drivers / block / buddha.c
blob8086dac560eb67a517e37e3d20060bc046d7fd9f
1 /*
2 * linux/drivers/block/buddha.c -- Amiga Buddha and Catweasel IDE Driver
4 * Copyright (C) 1997 by Geert Uytterhoeven
6 * This driver was written by based on the specifications in README.buddha.
8 * This file is subject to the terms and conditions of the GNU General Public
9 * License. See the file COPYING in the main directory of this archive for
10 * more details.
12 * TODO:
13 * - test it :-)
14 * - tune the timings using the speed-register
17 #include <linux/types.h>
18 #include <linux/mm.h>
19 #include <linux/interrupt.h>
20 #include <linux/blkdev.h>
21 #include <linux/hdreg.h>
22 #include <linux/zorro.h>
23 #include <linux/ide.h>
25 #include <asm/amigahw.h>
26 #include <asm/amigaints.h>
30 * The Buddha has 2 IDE interfaces, the Catweasel has 3
33 #define BUDDHA_NUM_HWIFS 2
34 #define CATWEASEL_NUM_HWIFS 3
38 * Bases of the IDE interfaces (relative to the board address)
41 #define BUDDHA_BASE1 0x800
42 #define BUDDHA_BASE2 0xa00
43 #define BUDDHA_BASE3 0xc00
45 static const u_int buddha_bases[CATWEASEL_NUM_HWIFS] = {
46 BUDDHA_BASE1, BUDDHA_BASE2, BUDDHA_BASE3
51 * Offsets from one of the above bases
54 #define BUDDHA_DATA 0x00
55 #define BUDDHA_ERROR 0x06 /* see err-bits */
56 #define BUDDHA_NSECTOR 0x0a /* nr of sectors to read/write */
57 #define BUDDHA_SECTOR 0x0e /* starting sector */
58 #define BUDDHA_LCYL 0x12 /* starting cylinder */
59 #define BUDDHA_HCYL 0x16 /* high byte of starting cyl */
60 #define BUDDHA_SELECT 0x1a /* 101dhhhh , d=drive, hhhh=head */
61 #define BUDDHA_STATUS 0x1e /* see status-bits */
62 #define BUDDHA_CONTROL 0x11a
64 static int buddha_offsets[IDE_NR_PORTS] = {
65 BUDDHA_DATA, BUDDHA_ERROR, BUDDHA_NSECTOR, BUDDHA_SECTOR, BUDDHA_LCYL,
66 BUDDHA_HCYL, BUDDHA_SELECT, BUDDHA_STATUS, BUDDHA_CONTROL
71 * Other registers
74 #define BUDDHA_IRQ1 0xf00 /* MSB = 1, Harddisk is source of */
75 #define BUDDHA_IRQ2 0xf40 /* interrupt */
76 #define BUDDHA_IRQ3 0xf80
78 static const int buddha_irqports[CATWEASEL_NUM_HWIFS] = {
79 BUDDHA_IRQ1, BUDDHA_IRQ2, BUDDHA_IRQ3
82 #define BUDDHA_IRQ_MR 0xfc0 /* master interrupt enable */
86 * Board information
89 static u_long buddha_board = 0;
90 static int buddha_num_hwifs = -1;
94 * Check and acknowledge the interrupt status
97 static int buddha_ack_intr(ide_hwif_t *hwif)
99 unsigned char ch;
101 ch = inb(hwif->io_ports[IDE_IRQ_OFFSET]);
102 if (!(ch & 0x80))
103 return 0;
104 return 1;
109 * Any Buddha or Catweasel boards present?
112 static int find_buddha(void)
114 u_int key;
115 const struct ConfigDev *cd;
117 buddha_num_hwifs = 0;
118 if ((key = zorro_find(ZORRO_PROD_INDIVIDUAL_COMPUTERS_BUDDHA, 0, 0)))
119 buddha_num_hwifs = BUDDHA_NUM_HWIFS;
120 else if ((key = zorro_find(ZORRO_PROD_INDIVIDUAL_COMPUTERS_CATWEASEL, 0,
121 0)))
122 buddha_num_hwifs = CATWEASEL_NUM_HWIFS;
123 if (key) {
124 cd = zorro_get_board(key);
125 buddha_board = (u_long)cd->cd_BoardAddr;
126 if (buddha_board) {
127 buddha_board = ZTWO_VADDR(buddha_board);
128 /* write to BUDDHA_IRQ_MR to enable the board IRQ */
129 *(char *)(buddha_board+BUDDHA_IRQ_MR) = 0;
130 zorro_config_board(key, 0);
133 return buddha_num_hwifs;
138 * Probe for a Buddha or Catweasel IDE interface
139 * We support only _one_ of them, no multiple boards!
142 void buddha_init(void)
144 hw_regs_t hw;
145 int i, index;
147 if (buddha_num_hwifs < 0 && !find_buddha())
148 return;
150 for (i = 0; i < buddha_num_hwifs; i++) {
151 ide_setup_ports(&hw, (ide_ioreg_t)(buddha_board+buddha_bases[i]),
152 buddha_offsets, 0,
153 (ide_ioreg_t)(buddha_board+buddha_irqports[i]),
154 buddha_ack_intr, IRQ_AMIGA_PORTS);
155 index = ide_register_hw(&hw, NULL);
156 if (index != -1)
157 printk("ide%d: %s IDE interface\n", index,
158 buddha_num_hwifs == BUDDHA_NUM_HWIFS ? "Buddha" :
159 "Catweasel");