Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1 | /* |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2 | * Copyright (C) 2001-2002 Andre Hedrick <andre@linux-ide.org> |
| 3 | * Copyright (C) 2003 Red Hat <alan@redhat.com> |
Sergei Shtylyov | 075cb65 | 2007-02-17 02:40:22 +0100 | [diff] [blame] | 4 | * Copyright (C) 2007 MontaVista Software, Inc. |
Bartlomiej Zolnierkiewicz | 165701d | 2008-04-28 23:44:38 +0200 | [diff] [blame] | 5 | * Copyright (C) 2007-2008 Bartlomiej Zolnierkiewicz |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6 | * |
| 7 | * May be copied or modified under the terms of the GNU General Public License |
| 8 | * |
Jeff Garzik | bf4c796 | 2005-11-18 22:55:47 +0100 | [diff] [blame] | 9 | * Documentation for CMD680: |
| 10 | * http://gkernel.sourceforge.net/specs/sii/sii-0680a-v1.31.pdf.bz2 |
| 11 | * |
| 12 | * Documentation for SiI 3112: |
| 13 | * http://gkernel.sourceforge.net/specs/sii/3112A_SiI-DS-0095-B2.pdf.bz2 |
| 14 | * |
| 15 | * Errata and other documentation only available under NDA. |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 16 | * |
| 17 | * |
| 18 | * FAQ Items: |
| 19 | * If you are using Marvell SATA-IDE adapters with Maxtor drives |
| 20 | * ensure the system is set up for ATA100/UDMA5 not UDMA6. |
| 21 | * |
| 22 | * If you are using WD drives with SATA bridges you must set the |
| 23 | * drive to "Single". "Master" will hang |
| 24 | * |
| 25 | * If you have strange problems with nVidia chipset systems please |
| 26 | * see the SI support documentation and update your system BIOS |
Robert P. J. Day | 3a4fa0a | 2007-10-19 23:10:43 +0200 | [diff] [blame] | 27 | * if necessary |
Alan Cox | 8693d3e | 2007-03-03 17:48:54 +0100 | [diff] [blame] | 28 | * |
| 29 | * The Dell DRAC4 has some interesting features including effectively hot |
| 30 | * unplugging/replugging the virtual CD interface when the DRAC is reset. |
| 31 | * This often causes drivers/ide/siimage to panic but is ok with the rather |
| 32 | * smarter code in libata. |
Bartlomiej Zolnierkiewicz | 328dcbb | 2007-07-20 01:11:54 +0200 | [diff] [blame] | 33 | * |
| 34 | * TODO: |
| 35 | * - IORDY fixes |
| 36 | * - VDMA support |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 37 | */ |
| 38 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 39 | #include <linux/types.h> |
| 40 | #include <linux/module.h> |
| 41 | #include <linux/pci.h> |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 42 | #include <linux/hdreg.h> |
| 43 | #include <linux/ide.h> |
| 44 | #include <linux/init.h> |
| 45 | |
| 46 | #include <asm/io.h> |
| 47 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 48 | /** |
| 49 | * pdev_is_sata - check if device is SATA |
| 50 | * @pdev: PCI device to check |
| 51 | * |
| 52 | * Returns true if this is a SATA controller |
| 53 | */ |
| 54 | |
| 55 | static int pdev_is_sata(struct pci_dev *pdev) |
| 56 | { |
Bartlomiej Zolnierkiewicz | 438c470 | 2007-10-20 00:32:31 +0200 | [diff] [blame] | 57 | #ifdef CONFIG_BLK_DEV_IDE_SATA |
| 58 | switch(pdev->device) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 59 | case PCI_DEVICE_ID_SII_3112: |
| 60 | case PCI_DEVICE_ID_SII_1210SA: |
| 61 | return 1; |
| 62 | case PCI_DEVICE_ID_SII_680: |
| 63 | return 0; |
| 64 | } |
| 65 | BUG(); |
Bartlomiej Zolnierkiewicz | 438c470 | 2007-10-20 00:32:31 +0200 | [diff] [blame] | 66 | #endif |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 67 | return 0; |
| 68 | } |
Bartlomiej Zolnierkiewicz | 438c470 | 2007-10-20 00:32:31 +0200 | [diff] [blame] | 69 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 70 | /** |
| 71 | * is_sata - check if hwif is SATA |
| 72 | * @hwif: interface to check |
| 73 | * |
| 74 | * Returns true if this is a SATA controller |
| 75 | */ |
| 76 | |
| 77 | static inline int is_sata(ide_hwif_t *hwif) |
| 78 | { |
Bartlomiej Zolnierkiewicz | 3650165 | 2008-02-01 23:09:31 +0100 | [diff] [blame] | 79 | return pdev_is_sata(to_pci_dev(hwif->dev)); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 80 | } |
| 81 | |
| 82 | /** |
| 83 | * siimage_selreg - return register base |
| 84 | * @hwif: interface |
| 85 | * @r: config offset |
| 86 | * |
| 87 | * Turn a config register offset into the right address in either |
| 88 | * PCI space or MMIO space to access the control register in question |
| 89 | * Thankfully this is a configuration operation so isnt performance |
| 90 | * criticial. |
| 91 | */ |
| 92 | |
| 93 | static unsigned long siimage_selreg(ide_hwif_t *hwif, int r) |
| 94 | { |
| 95 | unsigned long base = (unsigned long)hwif->hwif_data; |
| 96 | base += 0xA0 + r; |
| 97 | if(hwif->mmio) |
| 98 | base += (hwif->channel << 6); |
| 99 | else |
| 100 | base += (hwif->channel << 4); |
| 101 | return base; |
| 102 | } |
| 103 | |
| 104 | /** |
| 105 | * siimage_seldev - return register base |
| 106 | * @hwif: interface |
| 107 | * @r: config offset |
| 108 | * |
| 109 | * Turn a config register offset into the right address in either |
| 110 | * PCI space or MMIO space to access the control register in question |
| 111 | * including accounting for the unit shift. |
| 112 | */ |
| 113 | |
| 114 | static inline unsigned long siimage_seldev(ide_drive_t *drive, int r) |
| 115 | { |
| 116 | ide_hwif_t *hwif = HWIF(drive); |
| 117 | unsigned long base = (unsigned long)hwif->hwif_data; |
| 118 | base += 0xA0 + r; |
| 119 | if(hwif->mmio) |
| 120 | base += (hwif->channel << 6); |
| 121 | else |
| 122 | base += (hwif->channel << 4); |
| 123 | base |= drive->select.b.unit << drive->select.b.unit; |
| 124 | return base; |
| 125 | } |
| 126 | |
Bartlomiej Zolnierkiewicz | 165701d | 2008-04-28 23:44:38 +0200 | [diff] [blame] | 127 | static u8 sil_ioread8(struct pci_dev *dev, unsigned long addr) |
| 128 | { |
| 129 | u8 tmp = 0; |
| 130 | |
| 131 | if (pci_get_drvdata(dev)) |
| 132 | tmp = readb((void __iomem *)addr); |
| 133 | else |
| 134 | pci_read_config_byte(dev, addr, &tmp); |
| 135 | |
| 136 | return tmp; |
| 137 | } |
| 138 | |
| 139 | static u16 sil_ioread16(struct pci_dev *dev, unsigned long addr) |
| 140 | { |
| 141 | u16 tmp = 0; |
| 142 | |
| 143 | if (pci_get_drvdata(dev)) |
| 144 | tmp = readw((void __iomem *)addr); |
| 145 | else |
| 146 | pci_read_config_word(dev, addr, &tmp); |
| 147 | |
| 148 | return tmp; |
| 149 | } |
| 150 | |
| 151 | static void sil_iowrite8(struct pci_dev *dev, u8 val, unsigned long addr) |
| 152 | { |
| 153 | if (pci_get_drvdata(dev)) |
| 154 | writeb(val, (void __iomem *)addr); |
| 155 | else |
| 156 | pci_write_config_byte(dev, addr, val); |
| 157 | } |
| 158 | |
| 159 | static void sil_iowrite16(struct pci_dev *dev, u16 val, unsigned long addr) |
| 160 | { |
| 161 | if (pci_get_drvdata(dev)) |
| 162 | writew(val, (void __iomem *)addr); |
| 163 | else |
| 164 | pci_write_config_word(dev, addr, val); |
| 165 | } |
| 166 | |
| 167 | static void sil_iowrite32(struct pci_dev *dev, u32 val, unsigned long addr) |
| 168 | { |
| 169 | if (pci_get_drvdata(dev)) |
| 170 | writel(val, (void __iomem *)addr); |
| 171 | else |
| 172 | pci_write_config_dword(dev, addr, val); |
| 173 | } |
| 174 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 175 | /** |
Bartlomiej Zolnierkiewicz | 2d5eaa6 | 2007-05-10 00:01:08 +0200 | [diff] [blame] | 176 | * sil_udma_filter - compute UDMA mask |
| 177 | * @drive: IDE device |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 178 | * |
Bartlomiej Zolnierkiewicz | 2d5eaa6 | 2007-05-10 00:01:08 +0200 | [diff] [blame] | 179 | * Compute the available UDMA speeds for the device on the interface. |
| 180 | * |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 181 | * For the CMD680 this depends on the clocking mode (scsc), for the |
Bartlomiej Zolnierkiewicz | 2d5eaa6 | 2007-05-10 00:01:08 +0200 | [diff] [blame] | 182 | * SI3112 SATA controller life is a bit simpler. |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 183 | */ |
Bartlomiej Zolnierkiewicz | 2d5eaa6 | 2007-05-10 00:01:08 +0200 | [diff] [blame] | 184 | |
Bartlomiej Zolnierkiewicz | 438c470 | 2007-10-20 00:32:31 +0200 | [diff] [blame] | 185 | static u8 sil_pata_udma_filter(ide_drive_t *drive) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 186 | { |
Bartlomiej Zolnierkiewicz | 2d5eaa6 | 2007-05-10 00:01:08 +0200 | [diff] [blame] | 187 | ide_hwif_t *hwif = drive->hwif; |
Bartlomiej Zolnierkiewicz | 3650165 | 2008-02-01 23:09:31 +0100 | [diff] [blame] | 188 | struct pci_dev *dev = to_pci_dev(hwif->dev); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 189 | unsigned long base = (unsigned long) hwif->hwif_data; |
Bartlomiej Zolnierkiewicz | 165701d | 2008-04-28 23:44:38 +0200 | [diff] [blame] | 190 | u8 mask = 0, scsc; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 191 | |
Bartlomiej Zolnierkiewicz | 165701d | 2008-04-28 23:44:38 +0200 | [diff] [blame] | 192 | scsc = sil_ioread8(dev, base + (hwif->mmio ? 0x4A : 0x8A)); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 193 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 194 | if ((scsc & 0x30) == 0x10) /* 133 */ |
Bartlomiej Zolnierkiewicz | 438c470 | 2007-10-20 00:32:31 +0200 | [diff] [blame] | 195 | mask = ATA_UDMA6; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 196 | else if ((scsc & 0x30) == 0x20) /* 2xPCI */ |
Bartlomiej Zolnierkiewicz | 438c470 | 2007-10-20 00:32:31 +0200 | [diff] [blame] | 197 | mask = ATA_UDMA6; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 198 | else if ((scsc & 0x30) == 0x00) /* 100 */ |
Bartlomiej Zolnierkiewicz | 438c470 | 2007-10-20 00:32:31 +0200 | [diff] [blame] | 199 | mask = ATA_UDMA5; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 200 | else /* Disabled ? */ |
| 201 | BUG(); |
Bartlomiej Zolnierkiewicz | 438c470 | 2007-10-20 00:32:31 +0200 | [diff] [blame] | 202 | |
Bartlomiej Zolnierkiewicz | 2d5eaa6 | 2007-05-10 00:01:08 +0200 | [diff] [blame] | 203 | return mask; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 204 | } |
| 205 | |
Bartlomiej Zolnierkiewicz | 438c470 | 2007-10-20 00:32:31 +0200 | [diff] [blame] | 206 | static u8 sil_sata_udma_filter(ide_drive_t *drive) |
| 207 | { |
| 208 | return strstr(drive->id->model, "Maxtor") ? ATA_UDMA5 : ATA_UDMA6; |
| 209 | } |
| 210 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 211 | /** |
Bartlomiej Zolnierkiewicz | 88b2b32 | 2007-10-13 17:47:51 +0200 | [diff] [blame] | 212 | * sil_set_pio_mode - set host controller for PIO mode |
| 213 | * @drive: drive |
| 214 | * @pio: PIO mode number |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 215 | * |
| 216 | * Load the timing settings for this device mode into the |
| 217 | * controller. If we are in PIO mode 3 or 4 turn on IORDY |
| 218 | * monitoring (bit 9). The TF timing is bits 31:16 |
| 219 | */ |
Bartlomiej Zolnierkiewicz | 328dcbb | 2007-07-20 01:11:54 +0200 | [diff] [blame] | 220 | |
Bartlomiej Zolnierkiewicz | 88b2b32 | 2007-10-13 17:47:51 +0200 | [diff] [blame] | 221 | static void sil_set_pio_mode(ide_drive_t *drive, u8 pio) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 222 | { |
Bartlomiej Zolnierkiewicz | 328dcbb | 2007-07-20 01:11:54 +0200 | [diff] [blame] | 223 | const u16 tf_speed[] = { 0x328a, 0x2283, 0x1281, 0x10c3, 0x10c1 }; |
| 224 | const u16 data_speed[] = { 0x328a, 0x2283, 0x1104, 0x10c3, 0x10c1 }; |
| 225 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 226 | ide_hwif_t *hwif = HWIF(drive); |
Bartlomiej Zolnierkiewicz | 165701d | 2008-04-28 23:44:38 +0200 | [diff] [blame] | 227 | struct pci_dev *dev = to_pci_dev(hwif->dev); |
Benjamin Herrenschmidt | a87a87c | 2007-10-19 00:30:05 +0200 | [diff] [blame] | 228 | ide_drive_t *pair = ide_get_paired_drive(drive); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 229 | u32 speedt = 0; |
| 230 | u16 speedp = 0; |
| 231 | unsigned long addr = siimage_seldev(drive, 0x04); |
| 232 | unsigned long tfaddr = siimage_selreg(hwif, 0x02); |
Bartlomiej Zolnierkiewicz | ffe5415 | 2007-10-11 23:54:01 +0200 | [diff] [blame] | 233 | unsigned long base = (unsigned long)hwif->hwif_data; |
Bartlomiej Zolnierkiewicz | 328dcbb | 2007-07-20 01:11:54 +0200 | [diff] [blame] | 234 | u8 tf_pio = pio; |
Bartlomiej Zolnierkiewicz | ffe5415 | 2007-10-11 23:54:01 +0200 | [diff] [blame] | 235 | u8 addr_mask = hwif->channel ? (hwif->mmio ? 0xF4 : 0x84) |
| 236 | : (hwif->mmio ? 0xB4 : 0x80); |
| 237 | u8 mode = 0; |
| 238 | u8 unit = drive->select.b.unit; |
Bartlomiej Zolnierkiewicz | 328dcbb | 2007-07-20 01:11:54 +0200 | [diff] [blame] | 239 | |
| 240 | /* trim *taskfile* PIO to the slowest of the master/slave */ |
| 241 | if (pair->present) { |
Bartlomiej Zolnierkiewicz | 2134758 | 2007-07-20 01:11:58 +0200 | [diff] [blame] | 242 | u8 pair_pio = ide_get_best_pio_mode(pair, 255, 4); |
Bartlomiej Zolnierkiewicz | 328dcbb | 2007-07-20 01:11:54 +0200 | [diff] [blame] | 243 | |
| 244 | if (pair_pio < tf_pio) |
| 245 | tf_pio = pair_pio; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 246 | } |
Sergei Shtylyov | 075cb65 | 2007-02-17 02:40:22 +0100 | [diff] [blame] | 247 | |
Bartlomiej Zolnierkiewicz | 328dcbb | 2007-07-20 01:11:54 +0200 | [diff] [blame] | 248 | /* cheat for now and use the docs */ |
| 249 | speedp = data_speed[pio]; |
| 250 | speedt = tf_speed[tf_pio]; |
| 251 | |
Bartlomiej Zolnierkiewicz | 165701d | 2008-04-28 23:44:38 +0200 | [diff] [blame] | 252 | sil_iowrite16(dev, speedp, addr); |
| 253 | sil_iowrite16(dev, speedt, tfaddr); |
Bartlomiej Zolnierkiewicz | ffe5415 | 2007-10-11 23:54:01 +0200 | [diff] [blame] | 254 | |
Bartlomiej Zolnierkiewicz | 165701d | 2008-04-28 23:44:38 +0200 | [diff] [blame] | 255 | /* now set up IORDY */ |
| 256 | speedp = sil_ioread16(dev, tfaddr - 2); |
| 257 | speedp &= ~0x200; |
| 258 | if (pio > 2) |
| 259 | speedp |= 0x200; |
| 260 | sil_iowrite16(dev, speedp, tfaddr - 2); |
Bartlomiej Zolnierkiewicz | 3650165 | 2008-02-01 23:09:31 +0100 | [diff] [blame] | 261 | |
Bartlomiej Zolnierkiewicz | 165701d | 2008-04-28 23:44:38 +0200 | [diff] [blame] | 262 | mode = sil_ioread8(dev, base + addr_mask); |
| 263 | mode &= ~(unit ? 0x30 : 0x03); |
| 264 | mode |= (unit ? 0x10 : 0x01); |
| 265 | sil_iowrite8(dev, mode, base + addr_mask); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 266 | } |
| 267 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 268 | /** |
Bartlomiej Zolnierkiewicz | 88b2b32 | 2007-10-13 17:47:51 +0200 | [diff] [blame] | 269 | * sil_set_dma_mode - set host controller for DMA mode |
| 270 | * @drive: drive |
| 271 | * @speed: DMA mode |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 272 | * |
Bartlomiej Zolnierkiewicz | 88b2b32 | 2007-10-13 17:47:51 +0200 | [diff] [blame] | 273 | * Tune the SiI chipset for the desired DMA mode. |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 274 | */ |
Bartlomiej Zolnierkiewicz | f212ff2 | 2007-10-11 23:53:59 +0200 | [diff] [blame] | 275 | |
Bartlomiej Zolnierkiewicz | 88b2b32 | 2007-10-13 17:47:51 +0200 | [diff] [blame] | 276 | static void sil_set_dma_mode(ide_drive_t *drive, const u8 speed) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 277 | { |
| 278 | u8 ultra6[] = { 0x0F, 0x0B, 0x07, 0x05, 0x03, 0x02, 0x01 }; |
| 279 | u8 ultra5[] = { 0x0C, 0x07, 0x05, 0x04, 0x02, 0x01 }; |
| 280 | u16 dma[] = { 0x2208, 0x10C2, 0x10C1 }; |
| 281 | |
| 282 | ide_hwif_t *hwif = HWIF(drive); |
Bartlomiej Zolnierkiewicz | 3650165 | 2008-02-01 23:09:31 +0100 | [diff] [blame] | 283 | struct pci_dev *dev = to_pci_dev(hwif->dev); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 284 | u16 ultra = 0, multi = 0; |
| 285 | u8 mode = 0, unit = drive->select.b.unit; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 286 | unsigned long base = (unsigned long)hwif->hwif_data; |
| 287 | u8 scsc = 0, addr_mask = ((hwif->channel) ? |
| 288 | ((hwif->mmio) ? 0xF4 : 0x84) : |
| 289 | ((hwif->mmio) ? 0xB4 : 0x80)); |
| 290 | |
| 291 | unsigned long ma = siimage_seldev(drive, 0x08); |
| 292 | unsigned long ua = siimage_seldev(drive, 0x0C); |
| 293 | |
Bartlomiej Zolnierkiewicz | 165701d | 2008-04-28 23:44:38 +0200 | [diff] [blame] | 294 | scsc = sil_ioread8(dev, base + (hwif->mmio ? 0x4A : 0x8A)); |
| 295 | mode = sil_ioread8(dev, base + addr_mask); |
| 296 | multi = sil_ioread16(dev, ma); |
| 297 | ultra = sil_ioread16(dev, ua); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 298 | |
| 299 | mode &= ~((unit) ? 0x30 : 0x03); |
| 300 | ultra &= ~0x3F; |
| 301 | scsc = ((scsc & 0x30) == 0x00) ? 0 : 1; |
| 302 | |
| 303 | scsc = is_sata(hwif) ? 1 : scsc; |
| 304 | |
Bartlomiej Zolnierkiewicz | 4db90a1 | 2008-01-25 22:17:18 +0100 | [diff] [blame] | 305 | if (speed >= XFER_UDMA_0) { |
| 306 | multi = dma[2]; |
| 307 | ultra |= (scsc ? ultra6[speed - XFER_UDMA_0] : |
| 308 | ultra5[speed - XFER_UDMA_0]); |
| 309 | mode |= (unit ? 0x30 : 0x03); |
| 310 | } else { |
| 311 | multi = dma[speed - XFER_MW_DMA_0]; |
| 312 | mode |= (unit ? 0x20 : 0x02); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 313 | } |
| 314 | |
Bartlomiej Zolnierkiewicz | 165701d | 2008-04-28 23:44:38 +0200 | [diff] [blame] | 315 | sil_iowrite8(dev, mode, base + addr_mask); |
| 316 | sil_iowrite16(dev, multi, ma); |
| 317 | sil_iowrite16(dev, ultra, ua); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 318 | } |
| 319 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 320 | /* returns 1 if dma irq issued, 0 otherwise */ |
Bartlomiej Zolnierkiewicz | 5e37bdc | 2008-04-26 22:25:24 +0200 | [diff] [blame] | 321 | static int siimage_io_dma_test_irq(ide_drive_t *drive) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 322 | { |
| 323 | ide_hwif_t *hwif = HWIF(drive); |
Bartlomiej Zolnierkiewicz | 3650165 | 2008-02-01 23:09:31 +0100 | [diff] [blame] | 324 | struct pci_dev *dev = to_pci_dev(hwif->dev); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 325 | u8 dma_altstat = 0; |
| 326 | unsigned long addr = siimage_selreg(hwif, 1); |
| 327 | |
| 328 | /* return 1 if INTR asserted */ |
| 329 | if ((hwif->INB(hwif->dma_status) & 4) == 4) |
| 330 | return 1; |
| 331 | |
| 332 | /* return 1 if Device INTR asserted */ |
Bartlomiej Zolnierkiewicz | 3650165 | 2008-02-01 23:09:31 +0100 | [diff] [blame] | 333 | pci_read_config_byte(dev, addr, &dma_altstat); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 334 | if (dma_altstat & 8) |
| 335 | return 0; //return 1; |
| 336 | return 0; |
| 337 | } |
| 338 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 339 | /** |
Bartlomiej Zolnierkiewicz | 5e37bdc | 2008-04-26 22:25:24 +0200 | [diff] [blame] | 340 | * siimage_mmio_dma_test_irq - check we caused an IRQ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 341 | * @drive: drive we are testing |
| 342 | * |
| 343 | * Check if we caused an IDE DMA interrupt. We may also have caused |
| 344 | * SATA status interrupts, if so we clean them up and continue. |
| 345 | */ |
Bartlomiej Zolnierkiewicz | 5e37bdc | 2008-04-26 22:25:24 +0200 | [diff] [blame] | 346 | |
| 347 | static int siimage_mmio_dma_test_irq(ide_drive_t *drive) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 348 | { |
| 349 | ide_hwif_t *hwif = HWIF(drive); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 350 | unsigned long addr = siimage_selreg(hwif, 0x1); |
Bartlomiej Zolnierkiewicz | 835457d | 2008-02-02 19:56:45 +0100 | [diff] [blame] | 351 | void __iomem *sata_error_addr |
| 352 | = (void __iomem *)hwif->sata_scr[SATA_ERROR_OFFSET]; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 353 | |
Bartlomiej Zolnierkiewicz | 835457d | 2008-02-02 19:56:45 +0100 | [diff] [blame] | 354 | if (sata_error_addr) { |
Bartlomiej Zolnierkiewicz | 438c470 | 2007-10-20 00:32:31 +0200 | [diff] [blame] | 355 | unsigned long base = (unsigned long)hwif->hwif_data; |
Bartlomiej Zolnierkiewicz | 0ecdca2 | 2007-02-17 02:40:25 +0100 | [diff] [blame] | 356 | u32 ext_stat = readl((void __iomem *)(base + 0x10)); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 357 | u8 watchdog = 0; |
Bartlomiej Zolnierkiewicz | 835457d | 2008-02-02 19:56:45 +0100 | [diff] [blame] | 358 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 359 | if (ext_stat & ((hwif->channel) ? 0x40 : 0x10)) { |
Bartlomiej Zolnierkiewicz | 835457d | 2008-02-02 19:56:45 +0100 | [diff] [blame] | 360 | u32 sata_error = readl(sata_error_addr); |
| 361 | |
| 362 | writel(sata_error, sata_error_addr); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 363 | watchdog = (sata_error & 0x00680000) ? 1 : 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 364 | printk(KERN_WARNING "%s: sata_error = 0x%08x, " |
| 365 | "watchdog = %d, %s\n", |
| 366 | drive->name, sata_error, watchdog, |
Harvey Harrison | eb63963 | 2008-04-26 22:25:20 +0200 | [diff] [blame] | 367 | __func__); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 368 | |
| 369 | } else { |
| 370 | watchdog = (ext_stat & 0x8000) ? 1 : 0; |
| 371 | } |
| 372 | ext_stat >>= 16; |
| 373 | |
| 374 | if (!(ext_stat & 0x0404) && !watchdog) |
| 375 | return 0; |
| 376 | } |
| 377 | |
| 378 | /* return 1 if INTR asserted */ |
Bartlomiej Zolnierkiewicz | 0ecdca2 | 2007-02-17 02:40:25 +0100 | [diff] [blame] | 379 | if ((readb((void __iomem *)hwif->dma_status) & 0x04) == 0x04) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 380 | return 1; |
| 381 | |
| 382 | /* return 1 if Device INTR asserted */ |
Bartlomiej Zolnierkiewicz | 0ecdca2 | 2007-02-17 02:40:25 +0100 | [diff] [blame] | 383 | if ((readb((void __iomem *)addr) & 8) == 8) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 384 | return 0; //return 1; |
| 385 | |
| 386 | return 0; |
| 387 | } |
| 388 | |
Bartlomiej Zolnierkiewicz | 5e37bdc | 2008-04-26 22:25:24 +0200 | [diff] [blame] | 389 | static int siimage_dma_test_irq(ide_drive_t *drive) |
| 390 | { |
| 391 | if (drive->hwif->mmio) |
| 392 | return siimage_mmio_dma_test_irq(drive); |
| 393 | else |
| 394 | return siimage_io_dma_test_irq(drive); |
| 395 | } |
| 396 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 397 | /** |
Bartlomiej Zolnierkiewicz | 438c470 | 2007-10-20 00:32:31 +0200 | [diff] [blame] | 398 | * sil_sata_reset_poll - wait for SATA reset |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 399 | * @drive: drive we are resetting |
| 400 | * |
| 401 | * Poll the SATA phy and see whether it has come back from the dead |
| 402 | * yet. |
| 403 | */ |
Bartlomiej Zolnierkiewicz | 438c470 | 2007-10-20 00:32:31 +0200 | [diff] [blame] | 404 | |
| 405 | static int sil_sata_reset_poll(ide_drive_t *drive) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 406 | { |
Bartlomiej Zolnierkiewicz | 835457d | 2008-02-02 19:56:45 +0100 | [diff] [blame] | 407 | ide_hwif_t *hwif = drive->hwif; |
| 408 | void __iomem *sata_status_addr |
| 409 | = (void __iomem *)hwif->sata_scr[SATA_STATUS_OFFSET]; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 410 | |
Bartlomiej Zolnierkiewicz | 835457d | 2008-02-02 19:56:45 +0100 | [diff] [blame] | 411 | if (sata_status_addr) { |
| 412 | /* SATA Status is available only when in MMIO mode */ |
| 413 | u32 sata_stat = readl(sata_status_addr); |
| 414 | |
| 415 | if ((sata_stat & 0x03) != 0x03) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 416 | printk(KERN_WARNING "%s: reset phy dead, status=0x%08x\n", |
Bartlomiej Zolnierkiewicz | 835457d | 2008-02-02 19:56:45 +0100 | [diff] [blame] | 417 | hwif->name, sata_stat); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 418 | HWGROUP(drive)->polling = 0; |
| 419 | return ide_started; |
| 420 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 421 | } |
Bartlomiej Zolnierkiewicz | 438c470 | 2007-10-20 00:32:31 +0200 | [diff] [blame] | 422 | |
| 423 | return 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 424 | } |
| 425 | |
| 426 | /** |
Bartlomiej Zolnierkiewicz | 438c470 | 2007-10-20 00:32:31 +0200 | [diff] [blame] | 427 | * sil_sata_pre_reset - reset hook |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 428 | * @drive: IDE device being reset |
| 429 | * |
| 430 | * For the SATA devices we need to handle recalibration/geometry |
| 431 | * differently |
| 432 | */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 433 | |
Bartlomiej Zolnierkiewicz | 438c470 | 2007-10-20 00:32:31 +0200 | [diff] [blame] | 434 | static void sil_sata_pre_reset(ide_drive_t *drive) |
| 435 | { |
| 436 | if (drive->media == ide_disk) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 437 | drive->special.b.set_geometry = 0; |
| 438 | drive->special.b.recalibrate = 0; |
| 439 | } |
| 440 | } |
| 441 | |
| 442 | /** |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 443 | * setup_mmio_siimage - switch an SI controller into MMIO |
| 444 | * @dev: PCI device we are configuring |
| 445 | * @name: device name |
| 446 | * |
| 447 | * Attempt to put the device into mmio mode. There are some slight |
| 448 | * complications here with certain systems where the mmio bar isnt |
| 449 | * mapped so we have to be sure we can fall back to I/O. |
| 450 | */ |
| 451 | |
| 452 | static unsigned int setup_mmio_siimage (struct pci_dev *dev, const char *name) |
| 453 | { |
Sergei Shtylyov | c976816 | 2008-04-07 23:30:10 +0200 | [diff] [blame] | 454 | resource_size_t bar5 = pci_resource_start(dev, 5); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 455 | unsigned long barsize = pci_resource_len(dev, 5); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 456 | void __iomem *ioaddr; |
| 457 | |
| 458 | /* |
| 459 | * Drop back to PIO if we can't map the mmio. Some |
| 460 | * systems seem to get terminally confused in the PCI |
| 461 | * spaces. |
| 462 | */ |
Bartlomiej Zolnierkiewicz | 165701d | 2008-04-28 23:44:38 +0200 | [diff] [blame] | 463 | if (!request_mem_region(bar5, barsize, name)) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 464 | printk(KERN_WARNING "siimage: IDE controller MMIO ports not available.\n"); |
| 465 | return 0; |
| 466 | } |
Bartlomiej Zolnierkiewicz | 165701d | 2008-04-28 23:44:38 +0200 | [diff] [blame] | 467 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 468 | ioaddr = ioremap(bar5, barsize); |
| 469 | |
Bartlomiej Zolnierkiewicz | 165701d | 2008-04-28 23:44:38 +0200 | [diff] [blame] | 470 | if (ioaddr == NULL) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 471 | release_mem_region(bar5, barsize); |
| 472 | return 0; |
| 473 | } |
| 474 | |
| 475 | pci_set_master(dev); |
| 476 | pci_set_drvdata(dev, (void *) ioaddr); |
| 477 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 478 | return 1; |
| 479 | } |
| 480 | |
| 481 | /** |
| 482 | * init_chipset_siimage - set up an SI device |
| 483 | * @dev: PCI device |
| 484 | * @name: device name |
| 485 | * |
| 486 | * Perform the initial PCI set up for this device. Attempt to switch |
| 487 | * to 133MHz clocking if the system isn't already set up to do it. |
| 488 | */ |
| 489 | |
| 490 | static unsigned int __devinit init_chipset_siimage(struct pci_dev *dev, const char *name) |
| 491 | { |
Bartlomiej Zolnierkiewicz | 165701d | 2008-04-28 23:44:38 +0200 | [diff] [blame] | 492 | unsigned long base, scsc_addr; |
| 493 | void __iomem *ioaddr = NULL; |
| 494 | u8 rev = dev->revision, tmp = 0, BA5_EN = 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 495 | |
Bartlomiej Zolnierkiewicz | fc212bb | 2007-10-19 00:30:08 +0200 | [diff] [blame] | 496 | pci_write_config_byte(dev, PCI_CACHE_LINE_SIZE, rev ? 1 : 255); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 497 | |
| 498 | pci_read_config_byte(dev, 0x8A, &BA5_EN); |
Bartlomiej Zolnierkiewicz | 165701d | 2008-04-28 23:44:38 +0200 | [diff] [blame] | 499 | |
| 500 | if ((BA5_EN & 0x01) || pci_resource_start(dev, 5)) { |
| 501 | if (setup_mmio_siimage(dev, name)) |
| 502 | ioaddr = pci_get_drvdata(dev); |
| 503 | } |
| 504 | |
| 505 | base = (unsigned long)ioaddr; |
| 506 | |
| 507 | if (ioaddr && pdev_is_sata(dev)) { |
| 508 | u32 tmp32, irq_mask; |
| 509 | |
| 510 | /* make sure IDE0/1 interrupts are not masked */ |
| 511 | irq_mask = (1 << 22) | (1 << 23); |
| 512 | tmp32 = readl(ioaddr + 0x48); |
| 513 | if (tmp32 & irq_mask) { |
| 514 | tmp32 &= ~irq_mask; |
| 515 | writel(tmp32, ioaddr + 0x48); |
| 516 | readl(ioaddr + 0x48); /* flush */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 517 | } |
Bartlomiej Zolnierkiewicz | 165701d | 2008-04-28 23:44:38 +0200 | [diff] [blame] | 518 | writel(0, ioaddr + 0x148); |
| 519 | writel(0, ioaddr + 0x1C8); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 520 | } |
| 521 | |
Bartlomiej Zolnierkiewicz | 165701d | 2008-04-28 23:44:38 +0200 | [diff] [blame] | 522 | sil_iowrite8(dev, 0, base ? (base + 0xB4) : 0x80); |
| 523 | sil_iowrite8(dev, 0, base ? (base + 0xF4) : 0x84); |
| 524 | |
| 525 | scsc_addr = base ? (base + 0x4A) : 0x8A; |
| 526 | tmp = sil_ioread8(dev, scsc_addr); |
| 527 | |
| 528 | switch (tmp & 0x30) { |
| 529 | case 0x00: |
| 530 | /* On 100MHz clocking, try and switch to 133MHz */ |
| 531 | sil_iowrite8(dev, tmp | 0x10, scsc_addr); |
| 532 | break; |
| 533 | case 0x30: |
| 534 | /* Clocking is disabled, attempt to force 133MHz clocking. */ |
| 535 | sil_iowrite8(dev, tmp & ~0x20, scsc_addr); |
| 536 | case 0x10: |
| 537 | /* On 133Mhz clocking. */ |
| 538 | break; |
| 539 | case 0x20: |
| 540 | /* On PCIx2 clocking. */ |
| 541 | break; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 542 | } |
| 543 | |
Bartlomiej Zolnierkiewicz | 165701d | 2008-04-28 23:44:38 +0200 | [diff] [blame] | 544 | tmp = sil_ioread8(dev, scsc_addr); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 545 | |
Bartlomiej Zolnierkiewicz | 165701d | 2008-04-28 23:44:38 +0200 | [diff] [blame] | 546 | sil_iowrite8(dev, 0x72, base + 0xA1); |
| 547 | sil_iowrite16(dev, 0x328A, base + 0xA2); |
| 548 | sil_iowrite32(dev, 0x62DD62DD, base + 0xA4); |
| 549 | sil_iowrite32(dev, 0x43924392, base + 0xA8); |
| 550 | sil_iowrite32(dev, 0x40094009, base + 0xAC); |
| 551 | sil_iowrite8(dev, 0x72, base ? (base + 0xE1) : 0xB1); |
| 552 | sil_iowrite16(dev, 0x328A, base ? (base + 0xE2) : 0xB2); |
| 553 | sil_iowrite32(dev, 0x62DD62DD, base ? (base + 0xE4) : 0xB4); |
| 554 | sil_iowrite32(dev, 0x43924392, base ? (base + 0xE8) : 0xB8); |
| 555 | sil_iowrite32(dev, 0x40094009, base ? (base + 0xEC) : 0xBC); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 556 | |
Bartlomiej Zolnierkiewicz | 165701d | 2008-04-28 23:44:38 +0200 | [diff] [blame] | 557 | if (base && pdev_is_sata(dev)) { |
| 558 | writel(0xFFFF0000, ioaddr + 0x108); |
| 559 | writel(0xFFFF0000, ioaddr + 0x188); |
| 560 | writel(0x00680000, ioaddr + 0x148); |
| 561 | writel(0x00680000, ioaddr + 0x1C8); |
| 562 | } |
| 563 | |
Bartlomiej Zolnierkiewicz | 24cc434 | 2008-04-28 23:44:38 +0200 | [diff] [blame^] | 564 | /* report the clocking mode of the controller */ |
| 565 | if (!pdev_is_sata(dev)) { |
| 566 | static const char *clk_str[] = |
| 567 | { "== 100", "== 133", "== 2X PCI", "DISABLED!" }; |
| 568 | |
| 569 | tmp >>= 4; |
| 570 | printk(KERN_INFO "%s: BASE CLOCK %s\n", name, clk_str[tmp & 3]); |
| 571 | } |
Bartlomiej Zolnierkiewicz | 165701d | 2008-04-28 23:44:38 +0200 | [diff] [blame] | 572 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 573 | return 0; |
| 574 | } |
| 575 | |
| 576 | /** |
| 577 | * init_mmio_iops_siimage - set up the iops for MMIO |
| 578 | * @hwif: interface to set up |
| 579 | * |
| 580 | * The basic setup here is fairly simple, we can use standard MMIO |
| 581 | * operations. However we do have to set the taskfile register offsets |
| 582 | * by hand as there isnt a standard defined layout for them this |
| 583 | * time. |
| 584 | * |
| 585 | * The hardware supports buffered taskfiles and also some rather nice |
Alan Cox | 19c1ef5 | 2006-06-28 04:26:59 -0700 | [diff] [blame] | 586 | * extended PRD tables. For better SI3112 support use the libata driver |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 587 | */ |
| 588 | |
| 589 | static void __devinit init_mmio_iops_siimage(ide_hwif_t *hwif) |
| 590 | { |
Bartlomiej Zolnierkiewicz | 3650165 | 2008-02-01 23:09:31 +0100 | [diff] [blame] | 591 | struct pci_dev *dev = to_pci_dev(hwif->dev); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 592 | void *addr = pci_get_drvdata(dev); |
| 593 | u8 ch = hwif->channel; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 594 | unsigned long base; |
| 595 | |
Bartlomiej Zolnierkiewicz | 4c3032d | 2008-04-27 15:38:32 +0200 | [diff] [blame] | 596 | struct ide_io_ports *io_ports = &hwif->io_ports; |
| 597 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 598 | /* |
| 599 | * Fill in the basic HWIF bits |
| 600 | */ |
| 601 | |
Bartlomiej Zolnierkiewicz | c5dd43e | 2008-04-28 23:44:37 +0200 | [diff] [blame] | 602 | hwif->host_flags |= IDE_HFLAG_MMIO; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 603 | default_hwif_mmiops(hwif); |
| 604 | hwif->hwif_data = addr; |
| 605 | |
| 606 | /* |
| 607 | * Now set up the hw. We have to do this ourselves as |
Michael Opdenacker | 59c5159 | 2007-05-09 08:57:56 +0200 | [diff] [blame] | 608 | * the MMIO layout isnt the same as the standard port |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 609 | * based I/O |
| 610 | */ |
| 611 | |
Bartlomiej Zolnierkiewicz | 4c3032d | 2008-04-27 15:38:32 +0200 | [diff] [blame] | 612 | memset(io_ports, 0, sizeof(*io_ports)); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 613 | |
| 614 | base = (unsigned long)addr; |
| 615 | if (ch) |
| 616 | base += 0xC0; |
| 617 | else |
| 618 | base += 0x80; |
| 619 | |
| 620 | /* |
| 621 | * The buffered task file doesn't have status/control |
| 622 | * so we can't currently use it sanely since we want to |
| 623 | * use LBA48 mode. |
| 624 | */ |
Bartlomiej Zolnierkiewicz | 4c3032d | 2008-04-27 15:38:32 +0200 | [diff] [blame] | 625 | io_ports->data_addr = base; |
| 626 | io_ports->error_addr = base + 1; |
| 627 | io_ports->nsect_addr = base + 2; |
| 628 | io_ports->lbal_addr = base + 3; |
| 629 | io_ports->lbam_addr = base + 4; |
| 630 | io_ports->lbah_addr = base + 5; |
| 631 | io_ports->device_addr = base + 6; |
| 632 | io_ports->status_addr = base + 7; |
| 633 | io_ports->ctl_addr = base + 10; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 634 | |
| 635 | if (pdev_is_sata(dev)) { |
| 636 | base = (unsigned long)addr; |
| 637 | if (ch) |
| 638 | base += 0x80; |
| 639 | hwif->sata_scr[SATA_STATUS_OFFSET] = base + 0x104; |
| 640 | hwif->sata_scr[SATA_ERROR_OFFSET] = base + 0x108; |
| 641 | hwif->sata_scr[SATA_CONTROL_OFFSET] = base + 0x100; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 642 | } |
| 643 | |
Bartlomiej Zolnierkiewicz | 9239b33 | 2007-10-20 00:32:33 +0200 | [diff] [blame] | 644 | hwif->irq = dev->irq; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 645 | |
Bartlomiej Zolnierkiewicz | 9239b33 | 2007-10-20 00:32:33 +0200 | [diff] [blame] | 646 | hwif->dma_base = (unsigned long)addr + (ch ? 0x08 : 0x00); |
Bartlomiej Zolnierkiewicz | 2ad1e55 | 2007-02-17 02:40:25 +0100 | [diff] [blame] | 647 | |
| 648 | hwif->mmio = 1; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 649 | } |
| 650 | |
| 651 | static int is_dev_seagate_sata(ide_drive_t *drive) |
| 652 | { |
| 653 | const char *s = &drive->id->model[0]; |
| 654 | unsigned len; |
| 655 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 656 | len = strnlen(s, sizeof(drive->id->model)); |
| 657 | |
| 658 | if ((len > 4) && (!memcmp(s, "ST", 2))) { |
| 659 | if ((!memcmp(s + len - 2, "AS", 2)) || |
| 660 | (!memcmp(s + len - 3, "ASL", 3))) { |
| 661 | printk(KERN_INFO "%s: applying pessimistic Seagate " |
| 662 | "errata fix\n", drive->name); |
| 663 | return 1; |
| 664 | } |
| 665 | } |
| 666 | return 0; |
| 667 | } |
| 668 | |
| 669 | /** |
Bartlomiej Zolnierkiewicz | f01393e | 2008-01-26 20:13:03 +0100 | [diff] [blame] | 670 | * sil_quirkproc - post probe fixups |
| 671 | * @drive: drive |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 672 | * |
| 673 | * Called after drive probe we use this to decide whether the |
| 674 | * Seagate fixup must be applied. This used to be in init_iops but |
| 675 | * that can occur before we know what drives are present. |
| 676 | */ |
| 677 | |
Bartlomiej Zolnierkiewicz | f01393e | 2008-01-26 20:13:03 +0100 | [diff] [blame] | 678 | static void __devinit sil_quirkproc(ide_drive_t *drive) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 679 | { |
Bartlomiej Zolnierkiewicz | f01393e | 2008-01-26 20:13:03 +0100 | [diff] [blame] | 680 | ide_hwif_t *hwif = drive->hwif; |
| 681 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 682 | /* Try and raise the rqsize */ |
Bartlomiej Zolnierkiewicz | f01393e | 2008-01-26 20:13:03 +0100 | [diff] [blame] | 683 | if (!is_sata(hwif) || !is_dev_seagate_sata(drive)) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 684 | hwif->rqsize = 128; |
| 685 | } |
| 686 | |
| 687 | /** |
| 688 | * init_iops_siimage - set up iops |
| 689 | * @hwif: interface to set up |
| 690 | * |
| 691 | * Do the basic setup for the SIIMAGE hardware interface |
| 692 | * and then do the MMIO setup if we can. This is the first |
| 693 | * look in we get for setting up the hwif so that we |
| 694 | * can get the iops right before using them. |
| 695 | */ |
| 696 | |
| 697 | static void __devinit init_iops_siimage(ide_hwif_t *hwif) |
| 698 | { |
Bartlomiej Zolnierkiewicz | 3650165 | 2008-02-01 23:09:31 +0100 | [diff] [blame] | 699 | struct pci_dev *dev = to_pci_dev(hwif->dev); |
| 700 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 701 | hwif->hwif_data = NULL; |
| 702 | |
| 703 | /* Pessimal until we finish probing */ |
| 704 | hwif->rqsize = 15; |
| 705 | |
Bartlomiej Zolnierkiewicz | 3650165 | 2008-02-01 23:09:31 +0100 | [diff] [blame] | 706 | if (pci_get_drvdata(dev) == NULL) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 707 | return; |
Bartlomiej Zolnierkiewicz | fc212bb | 2007-10-19 00:30:08 +0200 | [diff] [blame] | 708 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 709 | init_mmio_iops_siimage(hwif); |
| 710 | } |
| 711 | |
| 712 | /** |
Bartlomiej Zolnierkiewicz | ac95bee | 2008-04-26 22:25:14 +0200 | [diff] [blame] | 713 | * sil_cable_detect - cable detection |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 714 | * @hwif: interface to check |
| 715 | * |
| 716 | * Check for the presence of an ATA66 capable cable on the |
| 717 | * interface. |
| 718 | */ |
| 719 | |
Bartlomiej Zolnierkiewicz | ac95bee | 2008-04-26 22:25:14 +0200 | [diff] [blame] | 720 | static u8 __devinit sil_cable_detect(ide_hwif_t *hwif) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 721 | { |
Bartlomiej Zolnierkiewicz | 3650165 | 2008-02-01 23:09:31 +0100 | [diff] [blame] | 722 | struct pci_dev *dev = to_pci_dev(hwif->dev); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 723 | unsigned long addr = siimage_selreg(hwif, 0); |
Bartlomiej Zolnierkiewicz | 165701d | 2008-04-28 23:44:38 +0200 | [diff] [blame] | 724 | u8 ata66 = sil_ioread8(dev, addr); |
Bartlomiej Zolnierkiewicz | 49521f9 | 2007-07-09 23:17:58 +0200 | [diff] [blame] | 725 | |
| 726 | return (ata66 & 0x01) ? ATA_CBL_PATA80 : ATA_CBL_PATA40; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 727 | } |
| 728 | |
Bartlomiej Zolnierkiewicz | ac95bee | 2008-04-26 22:25:14 +0200 | [diff] [blame] | 729 | static const struct ide_port_ops sil_pata_port_ops = { |
| 730 | .set_pio_mode = sil_set_pio_mode, |
| 731 | .set_dma_mode = sil_set_dma_mode, |
| 732 | .quirkproc = sil_quirkproc, |
| 733 | .udma_filter = sil_pata_udma_filter, |
| 734 | .cable_detect = sil_cable_detect, |
| 735 | }; |
| 736 | |
| 737 | static const struct ide_port_ops sil_sata_port_ops = { |
| 738 | .set_pio_mode = sil_set_pio_mode, |
| 739 | .set_dma_mode = sil_set_dma_mode, |
| 740 | .reset_poll = sil_sata_reset_poll, |
| 741 | .pre_reset = sil_sata_pre_reset, |
| 742 | .quirkproc = sil_quirkproc, |
| 743 | .udma_filter = sil_sata_udma_filter, |
| 744 | .cable_detect = sil_cable_detect, |
| 745 | }; |
| 746 | |
Bartlomiej Zolnierkiewicz | 5e37bdc | 2008-04-26 22:25:24 +0200 | [diff] [blame] | 747 | static struct ide_dma_ops sil_dma_ops = { |
| 748 | .dma_test_irq = siimage_dma_test_irq, |
| 749 | }; |
| 750 | |
Bartlomiej Zolnierkiewicz | ac95bee | 2008-04-26 22:25:14 +0200 | [diff] [blame] | 751 | #define DECLARE_SII_DEV(name_str, p_ops) \ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 752 | { \ |
| 753 | .name = name_str, \ |
| 754 | .init_chipset = init_chipset_siimage, \ |
| 755 | .init_iops = init_iops_siimage, \ |
Bartlomiej Zolnierkiewicz | ac95bee | 2008-04-26 22:25:14 +0200 | [diff] [blame] | 756 | .port_ops = p_ops, \ |
Bartlomiej Zolnierkiewicz | 5e37bdc | 2008-04-26 22:25:24 +0200 | [diff] [blame] | 757 | .dma_ops = &sil_dma_ops, \ |
Bartlomiej Zolnierkiewicz | 4099d14 | 2007-07-20 01:11:59 +0200 | [diff] [blame] | 758 | .pio_mask = ATA_PIO4, \ |
Bartlomiej Zolnierkiewicz | 5f8b6c3 | 2007-10-19 00:30:07 +0200 | [diff] [blame] | 759 | .mwdma_mask = ATA_MWDMA2, \ |
| 760 | .udma_mask = ATA_UDMA6, \ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 761 | } |
| 762 | |
Bartlomiej Zolnierkiewicz | 8562043 | 2007-10-20 00:32:34 +0200 | [diff] [blame] | 763 | static const struct ide_port_info siimage_chipsets[] __devinitdata = { |
Bartlomiej Zolnierkiewicz | ac95bee | 2008-04-26 22:25:14 +0200 | [diff] [blame] | 764 | /* 0 */ DECLARE_SII_DEV("SiI680", &sil_pata_port_ops), |
| 765 | /* 1 */ DECLARE_SII_DEV("SiI3112 Serial ATA", &sil_sata_port_ops), |
| 766 | /* 2 */ DECLARE_SII_DEV("Adaptec AAR-1210SA", &sil_sata_port_ops) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 767 | }; |
| 768 | |
| 769 | /** |
| 770 | * siimage_init_one - pci layer discovery entry |
| 771 | * @dev: PCI device |
| 772 | * @id: ident table entry |
| 773 | * |
| 774 | * Called by the PCI code when it finds an SI680 or SI3112 controller. |
| 775 | * We then use the IDE PCI generic helper to do most of the work. |
| 776 | */ |
| 777 | |
| 778 | static int __devinit siimage_init_one(struct pci_dev *dev, const struct pci_device_id *id) |
| 779 | { |
Bartlomiej Zolnierkiewicz | 5e37bdc | 2008-04-26 22:25:24 +0200 | [diff] [blame] | 780 | struct ide_port_info d; |
| 781 | u8 idx = id->driver_data; |
| 782 | |
| 783 | d = siimage_chipsets[idx]; |
| 784 | |
| 785 | if (idx) { |
| 786 | static int first = 1; |
| 787 | |
| 788 | if (first) { |
| 789 | printk(KERN_INFO "siimage: For full SATA support you " |
| 790 | "should use the libata sata_sil module.\n"); |
| 791 | first = 0; |
| 792 | } |
| 793 | |
| 794 | d.host_flags |= IDE_HFLAG_NO_ATAPI_DMA; |
| 795 | } |
| 796 | |
| 797 | return ide_setup_pci_device(dev, &d); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 798 | } |
| 799 | |
Bartlomiej Zolnierkiewicz | 9cbcc5e | 2007-10-16 22:29:56 +0200 | [diff] [blame] | 800 | static const struct pci_device_id siimage_pci_tbl[] = { |
| 801 | { PCI_VDEVICE(CMD, PCI_DEVICE_ID_SII_680), 0 }, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 802 | #ifdef CONFIG_BLK_DEV_IDE_SATA |
Bartlomiej Zolnierkiewicz | 9cbcc5e | 2007-10-16 22:29:56 +0200 | [diff] [blame] | 803 | { PCI_VDEVICE(CMD, PCI_DEVICE_ID_SII_3112), 1 }, |
| 804 | { PCI_VDEVICE(CMD, PCI_DEVICE_ID_SII_1210SA), 2 }, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 805 | #endif |
| 806 | { 0, }, |
| 807 | }; |
| 808 | MODULE_DEVICE_TABLE(pci, siimage_pci_tbl); |
| 809 | |
| 810 | static struct pci_driver driver = { |
| 811 | .name = "SiI_IDE", |
| 812 | .id_table = siimage_pci_tbl, |
| 813 | .probe = siimage_init_one, |
| 814 | }; |
| 815 | |
Bartlomiej Zolnierkiewicz | 82ab1ee | 2007-01-27 13:46:56 +0100 | [diff] [blame] | 816 | static int __init siimage_ide_init(void) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 817 | { |
| 818 | return ide_pci_register_driver(&driver); |
| 819 | } |
| 820 | |
| 821 | module_init(siimage_ide_init); |
| 822 | |
| 823 | MODULE_AUTHOR("Andre Hedrick, Alan Cox"); |
| 824 | MODULE_DESCRIPTION("PCI driver module for SiI IDE"); |
| 825 | MODULE_LICENSE("GPL"); |