Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1 | /* |
Bartlomiej Zolnierkiewicz | 58f189f | 2008-02-01 23:09:33 +0100 | [diff] [blame^] | 2 | * Macintosh IDE Driver |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 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 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 14 | #include <linux/types.h> |
| 15 | #include <linux/mm.h> |
| 16 | #include <linux/interrupt.h> |
| 17 | #include <linux/blkdev.h> |
| 18 | #include <linux/hdreg.h> |
| 19 | #include <linux/delay.h> |
| 20 | #include <linux/ide.h> |
| 21 | |
| 22 | #include <asm/machw.h> |
| 23 | #include <asm/macintosh.h> |
| 24 | #include <asm/macints.h> |
| 25 | #include <asm/mac_baboon.h> |
| 26 | |
| 27 | #define IDE_BASE 0x50F1A000 /* Base address of IDE controller */ |
| 28 | |
| 29 | /* |
| 30 | * Generic IDE registers as offsets from the base |
| 31 | * These match MkLinux so they should be correct. |
| 32 | */ |
| 33 | |
| 34 | #define IDE_DATA 0x00 |
| 35 | #define IDE_ERROR 0x04 /* see err-bits */ |
| 36 | #define IDE_NSECTOR 0x08 /* nr of sectors to read/write */ |
| 37 | #define IDE_SECTOR 0x0c /* starting sector */ |
| 38 | #define IDE_LCYL 0x10 /* starting cylinder */ |
| 39 | #define IDE_HCYL 0x14 /* high byte of starting cyl */ |
| 40 | #define IDE_SELECT 0x18 /* 101dhhhh , d=drive, hhhh=head */ |
| 41 | #define IDE_STATUS 0x1c /* see status-bits */ |
| 42 | #define IDE_CONTROL 0x38 /* control/altstatus */ |
| 43 | |
| 44 | /* |
| 45 | * Mac-specific registers |
| 46 | */ |
| 47 | |
| 48 | /* |
| 49 | * this register is odd; it doesn't seem to do much and it's |
| 50 | * not word-aligned like virtually every other hardware register |
| 51 | * on the Mac... |
| 52 | */ |
| 53 | |
| 54 | #define IDE_IFR 0x101 /* (0x101) IDE interrupt flags on Quadra: |
| 55 | * |
| 56 | * Bit 0+1: some interrupt flags |
| 57 | * Bit 2+3: some interrupt enable |
| 58 | * Bit 4: ?? |
| 59 | * Bit 5: IDE interrupt flag (any hwif) |
| 60 | * Bit 6: maybe IDE interrupt enable (any hwif) ?? |
| 61 | * Bit 7: Any interrupt condition |
| 62 | */ |
| 63 | |
| 64 | volatile unsigned char *ide_ifr = (unsigned char *) (IDE_BASE + IDE_IFR); |
| 65 | |
| 66 | static int macide_offsets[IDE_NR_PORTS] = { |
| 67 | IDE_DATA, IDE_ERROR, IDE_NSECTOR, IDE_SECTOR, IDE_LCYL, |
| 68 | IDE_HCYL, IDE_SELECT, IDE_STATUS, IDE_CONTROL |
| 69 | }; |
| 70 | |
| 71 | int macide_ack_intr(ide_hwif_t* hwif) |
| 72 | { |
| 73 | if (*ide_ifr & 0x20) { |
| 74 | *ide_ifr &= ~0x20; |
| 75 | return 1; |
| 76 | } |
| 77 | return 0; |
| 78 | } |
| 79 | |
Bartlomiej Zolnierkiewicz | c99c92c | 2008-01-26 20:13:09 +0100 | [diff] [blame] | 80 | static const char *mac_ide_name[] = |
| 81 | { "Quadra", "Powerbook", "Powerbook Baboon" }; |
| 82 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 83 | /* |
| 84 | * Probe for a Macintosh IDE interface |
| 85 | */ |
| 86 | |
Bartlomiej Zolnierkiewicz | ade2daf | 2008-01-26 20:13:07 +0100 | [diff] [blame] | 87 | static int __init macide_init(void) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 88 | { |
| 89 | hw_regs_t hw; |
| 90 | ide_hwif_t *hwif; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 91 | |
| 92 | switch (macintosh_config->ide_type) { |
| 93 | case MAC_IDE_QUADRA: |
| 94 | ide_setup_ports(&hw, IDE_BASE, macide_offsets, |
| 95 | 0, 0, macide_ack_intr, |
| 96 | // quadra_ide_iops, |
| 97 | IRQ_NUBUS_F); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 98 | break; |
| 99 | case MAC_IDE_PB: |
| 100 | ide_setup_ports(&hw, IDE_BASE, macide_offsets, |
| 101 | 0, 0, macide_ack_intr, |
| 102 | // macide_pb_iops, |
| 103 | IRQ_NUBUS_C); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 104 | break; |
| 105 | case MAC_IDE_BABOON: |
| 106 | ide_setup_ports(&hw, BABOON_BASE, macide_offsets, |
| 107 | 0, 0, NULL, |
| 108 | // macide_baboon_iops, |
| 109 | IRQ_BABOON_1); |
Bartlomiej Zolnierkiewicz | cbb010c | 2008-01-26 20:13:06 +0100 | [diff] [blame] | 110 | break; |
| 111 | default: |
Bartlomiej Zolnierkiewicz | ade2daf | 2008-01-26 20:13:07 +0100 | [diff] [blame] | 112 | return -ENODEV; |
Bartlomiej Zolnierkiewicz | cbb010c | 2008-01-26 20:13:06 +0100 | [diff] [blame] | 113 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 114 | |
Bartlomiej Zolnierkiewicz | c99c92c | 2008-01-26 20:13:09 +0100 | [diff] [blame] | 115 | printk(KERN_INFO "ide: Macintosh %s IDE controller\n", |
| 116 | mac_ide_name[macintosh_config->ide_type - 1]); |
| 117 | |
Bartlomiej Zolnierkiewicz | cbb010c | 2008-01-26 20:13:06 +0100 | [diff] [blame] | 118 | hwif = ide_find_port(hw.io_ports[IDE_DATA_OFFSET]); |
| 119 | if (hwif) { |
| 120 | u8 index = hwif->index; |
Bartlomiej Zolnierkiewicz | 8ac4ce7 | 2008-01-26 20:13:06 +0100 | [diff] [blame] | 121 | u8 idx[4] = { index, 0xff, 0xff, 0xff }; |
Bartlomiej Zolnierkiewicz | cbb010c | 2008-01-26 20:13:06 +0100 | [diff] [blame] | 122 | |
| 123 | ide_init_port_data(hwif, index); |
| 124 | ide_init_port_hw(hwif, &hw); |
| 125 | |
| 126 | if (macintosh_config->ide_type == MAC_IDE_BABOON && |
| 127 | macintosh_config->ident == MAC_MODEL_PB190) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 128 | /* Fix breakage in ide-disk.c: drive capacity */ |
| 129 | /* is not initialized for drives without a */ |
| 130 | /* hardware ID, and we can't get that without */ |
| 131 | /* probing the drive which freezes a 190. */ |
Bartlomiej Zolnierkiewicz | cbb010c | 2008-01-26 20:13:06 +0100 | [diff] [blame] | 132 | ide_drive_t *drive = &hwif->drives[0]; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 133 | drive->capacity64 = drive->cyl*drive->head*drive->sect; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 134 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 135 | |
Bartlomiej Zolnierkiewicz | 2ad1e55 | 2007-02-17 02:40:25 +0100 | [diff] [blame] | 136 | hwif->mmio = 1; |
Bartlomiej Zolnierkiewicz | 8ac4ce7 | 2008-01-26 20:13:06 +0100 | [diff] [blame] | 137 | |
| 138 | ide_device_add(idx); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 139 | } |
Bartlomiej Zolnierkiewicz | ade2daf | 2008-01-26 20:13:07 +0100 | [diff] [blame] | 140 | |
| 141 | return 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 142 | } |
Bartlomiej Zolnierkiewicz | ade2daf | 2008-01-26 20:13:07 +0100 | [diff] [blame] | 143 | |
| 144 | module_init(macide_init); |