1/*
2 *  Macintosh IDE Driver
3 *
4 *     Copyright (C) 1998 by Michael Schmitz
5 *
6 *  This driver was written based on information obtained from the MacOS IDE
7 *  driver binary by Mikael Forselius
8 *
9 *  This file is subject to the terms and conditions of the GNU General Public
10 *  License.  See the file COPYING in the main directory of this archive for
11 *  more details.
12 */
13
14#include <linux/types.h>
15#include <linux/mm.h>
16#include <linux/interrupt.h>
17#include <linux/blkdev.h>
18#include <linux/delay.h>
19#include <linux/ide.h>
20#include <linux/module.h>
21
22#include <asm/macintosh.h>
23#include <asm/macints.h>
24#include <asm/mac_baboon.h>
25
26#define IDE_BASE 0x50F1A000	/* Base address of IDE controller */
27
28/*
29 * Generic IDE registers as offsets from the base
30 * These match MkLinux so they should be correct.
31 */
32
33#define IDE_CONTROL	0x38	/* control/altstatus */
34
35/*
36 * Mac-specific registers
37 */
38
39/*
40 * this register is odd; it doesn't seem to do much and it's
41 * not word-aligned like virtually every other hardware register
42 * on the Mac...
43 */
44
45#define IDE_IFR		0x101	/* (0x101) IDE interrupt flags on Quadra:
46				 *
47				 * Bit 0+1: some interrupt flags
48				 * Bit 2+3: some interrupt enable
49				 * Bit 4:   ??
50				 * Bit 5:   IDE interrupt flag (any hwif)
51				 * Bit 6:   maybe IDE interrupt enable (any hwif) ??
52				 * Bit 7:   Any interrupt condition
53				 */
54
55volatile unsigned char *ide_ifr = (unsigned char *) (IDE_BASE + IDE_IFR);
56
57int macide_test_irq(ide_hwif_t *hwif)
58{
59	if (*ide_ifr & 0x20)
60		return 1;
61	return 0;
62}
63
64static void macide_clear_irq(ide_drive_t *drive)
65{
66	*ide_ifr &= ~0x20;
67}
68
69static void __init macide_setup_ports(struct ide_hw *hw, unsigned long base,
70				      int irq)
71{
72	int i;
73
74	memset(hw, 0, sizeof(*hw));
75
76	for (i = 0; i < 8; i++)
77		hw->io_ports_array[i] = base + i * 4;
78
79	hw->io_ports.ctl_addr = base + IDE_CONTROL;
80
81	hw->irq = irq;
82}
83
84static const struct ide_port_ops macide_port_ops = {
85	.clear_irq		= macide_clear_irq,
86	.test_irq		= macide_test_irq,
87};
88
89static const struct ide_port_info macide_port_info = {
90	.port_ops		= &macide_port_ops,
91	.host_flags		= IDE_HFLAG_MMIO | IDE_HFLAG_NO_DMA,
92	.irq_flags		= IRQF_SHARED,
93	.chipset		= ide_generic,
94};
95
96static const char *mac_ide_name[] =
97	{ "Quadra", "Powerbook", "Powerbook Baboon" };
98
99/*
100 * Probe for a Macintosh IDE interface
101 */
102
103static int __init macide_init(void)
104{
105	unsigned long base;
106	int irq;
107	struct ide_hw hw, *hws[] = { &hw };
108	struct ide_port_info d = macide_port_info;
109
110	if (!MACH_IS_MAC)
111		return -ENODEV;
112
113	switch (macintosh_config->ide_type) {
114	case MAC_IDE_QUADRA:
115		base = IDE_BASE;
116		irq = IRQ_NUBUS_F;
117		break;
118	case MAC_IDE_PB:
119		base = IDE_BASE;
120		irq = IRQ_NUBUS_C;
121		break;
122	case MAC_IDE_BABOON:
123		base = BABOON_BASE;
124		d.port_ops = NULL;
125		irq = IRQ_BABOON_1;
126		break;
127	default:
128		return -ENODEV;
129	}
130
131	printk(KERN_INFO "ide: Macintosh %s IDE controller\n",
132			 mac_ide_name[macintosh_config->ide_type - 1]);
133
134	macide_setup_ports(&hw, base, irq);
135
136	return ide_host_add(&d, hws, 1, NULL);
137}
138
139module_init(macide_init);
140
141MODULE_LICENSE("GPL");
142