blob: adc5fe9daafc2185c134a2f5dc4b14c2032ef2ca [file] [log] [blame]
Linus Torvalds1da177e2005-04-16 15:20:36 -07001/*
Bartlomiej Zolnierkiewicz58f189f2008-02-01 23:09:33 +01002 * Macintosh IDE Driver
Linus Torvalds1da177e2005-04-16 15:20:36 -07003 *
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
Linus Torvalds1da177e2005-04-16 15:20:36 -070014#include <linux/types.h>
15#include <linux/mm.h>
16#include <linux/interrupt.h>
17#include <linux/blkdev.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070018#include <linux/delay.h>
19#include <linux/ide.h>
Paul Gortmakerbff78322011-07-03 13:41:29 -040020#include <linux/module.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070021
Linus Torvalds1da177e2005-04-16 15:20:36 -070022#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
Linus Torvalds1da177e2005-04-16 15:20:36 -070033#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
Sergei Shtylyovf4d3ffa2009-06-15 18:52:58 +020057int macide_test_irq(ide_hwif_t *hwif)
Linus Torvalds1da177e2005-04-16 15:20:36 -070058{
Sergei Shtylyoveba89992009-06-15 18:52:57 +020059 if (*ide_ifr & 0x20)
Linus Torvalds1da177e2005-04-16 15:20:36 -070060 return 1;
Linus Torvalds1da177e2005-04-16 15:20:36 -070061 return 0;
62}
63
Sergei Shtylyoveba89992009-06-15 18:52:57 +020064static void macide_clear_irq(ide_drive_t *drive)
65{
66 *ide_ifr &= ~0x20;
67}
68
Bartlomiej Zolnierkiewicz9f36d312009-05-17 19:12:25 +020069static void __init macide_setup_ports(struct ide_hw *hw, unsigned long base,
Sergei Shtylyovf4d3ffa2009-06-15 18:52:58 +020070 int irq)
Bartlomiej Zolnierkiewicz29dd5972008-02-06 02:57:50 +010071{
72 int i;
73
74 memset(hw, 0, sizeof(*hw));
75
76 for (i = 0; i < 8; i++)
Bartlomiej Zolnierkiewicz4c3032d2008-04-27 15:38:32 +020077 hw->io_ports_array[i] = base + i * 4;
Bartlomiej Zolnierkiewicz29dd5972008-02-06 02:57:50 +010078
Bartlomiej Zolnierkiewicz4c3032d2008-04-27 15:38:32 +020079 hw->io_ports.ctl_addr = base + IDE_CONTROL;
Bartlomiej Zolnierkiewicz29dd5972008-02-06 02:57:50 +010080
81 hw->irq = irq;
Bartlomiej Zolnierkiewicz29dd5972008-02-06 02:57:50 +010082}
83
Sergei Shtylyoveba89992009-06-15 18:52:57 +020084static const struct ide_port_ops macide_port_ops = {
85 .clear_irq = macide_clear_irq,
Sergei Shtylyovf4d3ffa2009-06-15 18:52:58 +020086 .test_irq = macide_test_irq,
Sergei Shtylyoveba89992009-06-15 18:52:57 +020087};
88
Bartlomiej Zolnierkiewicz211176c2009-03-27 12:46:18 +010089static const struct ide_port_info macide_port_info = {
Sergei Shtylyoveba89992009-06-15 18:52:57 +020090 .port_ops = &macide_port_ops,
Bartlomiej Zolnierkiewicz09a3e792009-03-27 12:46:23 +010091 .host_flags = IDE_HFLAG_MMIO | IDE_HFLAG_NO_DMA,
Bartlomiej Zolnierkiewicz255115fb2009-03-27 12:46:27 +010092 .irq_flags = IRQF_SHARED,
Bartlomiej Zolnierkiewicz29e52cf2009-05-17 19:12:22 +020093 .chipset = ide_generic,
Bartlomiej Zolnierkiewicz211176c2009-03-27 12:46:18 +010094};
95
Bartlomiej Zolnierkiewiczc99c92c2008-01-26 20:13:09 +010096static const char *mac_ide_name[] =
97 { "Quadra", "Powerbook", "Powerbook Baboon" };
98
Linus Torvalds1da177e2005-04-16 15:20:36 -070099/*
100 * Probe for a Macintosh IDE interface
101 */
102
Bartlomiej Zolnierkiewiczade2daf2008-01-26 20:13:07 +0100103static int __init macide_init(void)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700104{
Bartlomiej Zolnierkiewicz29dd5972008-02-06 02:57:50 +0100105 unsigned long base;
106 int irq;
Bartlomiej Zolnierkiewicz9f36d312009-05-17 19:12:25 +0200107 struct ide_hw hw, *hws[] = { &hw };
Sergei Shtylyoveba89992009-06-15 18:52:57 +0200108 struct ide_port_info d = macide_port_info;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700109
Geert Uytterhoeven3ce92a22008-05-18 20:47:14 +0200110 if (!MACH_IS_MAC)
111 return -ENODEV;
112
Linus Torvalds1da177e2005-04-16 15:20:36 -0700113 switch (macintosh_config->ide_type) {
114 case MAC_IDE_QUADRA:
Bartlomiej Zolnierkiewicz29dd5972008-02-06 02:57:50 +0100115 base = IDE_BASE;
Bartlomiej Zolnierkiewicz29dd5972008-02-06 02:57:50 +0100116 irq = IRQ_NUBUS_F;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700117 break;
118 case MAC_IDE_PB:
Bartlomiej Zolnierkiewicz29dd5972008-02-06 02:57:50 +0100119 base = IDE_BASE;
Bartlomiej Zolnierkiewicz29dd5972008-02-06 02:57:50 +0100120 irq = IRQ_NUBUS_C;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700121 break;
122 case MAC_IDE_BABOON:
Bartlomiej Zolnierkiewicz29dd5972008-02-06 02:57:50 +0100123 base = BABOON_BASE;
Sergei Shtylyoveba89992009-06-15 18:52:57 +0200124 d.port_ops = NULL;
Bartlomiej Zolnierkiewicz29dd5972008-02-06 02:57:50 +0100125 irq = IRQ_BABOON_1;
Bartlomiej Zolnierkiewiczcbb010c2008-01-26 20:13:06 +0100126 break;
127 default:
Bartlomiej Zolnierkiewiczade2daf2008-01-26 20:13:07 +0100128 return -ENODEV;
Bartlomiej Zolnierkiewiczcbb010c2008-01-26 20:13:06 +0100129 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700130
Bartlomiej Zolnierkiewiczc99c92c2008-01-26 20:13:09 +0100131 printk(KERN_INFO "ide: Macintosh %s IDE controller\n",
132 mac_ide_name[macintosh_config->ide_type - 1]);
133
Sergei Shtylyovf4d3ffa2009-06-15 18:52:58 +0200134 macide_setup_ports(&hw, base, irq);
Bartlomiej Zolnierkiewicz29dd5972008-02-06 02:57:50 +0100135
Sergei Shtylyoveba89992009-06-15 18:52:57 +0200136 return ide_host_add(&d, hws, 1, NULL);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700137}
Bartlomiej Zolnierkiewiczade2daf2008-01-26 20:13:07 +0100138
139module_init(macide_init);
Adrian Bunk37c807a2008-04-02 21:22:04 +0200140
141MODULE_LICENSE("GPL");