Jeff Garzik | 669a5db | 2006-08-29 18:12:40 -0400 | [diff] [blame] | 1 | /* |
| 2 | * pata_sis.c - SiS ATA driver |
| 3 | * |
Alan Cox | ab77163 | 2008-10-27 15:09:10 +0000 | [diff] [blame] | 4 | * (C) 2005 Red Hat |
Bartlomiej Zolnierkiewicz | 750c713 | 2009-12-03 20:32:13 +0100 | [diff] [blame] | 5 | * (C) 2007,2009 Bartlomiej Zolnierkiewicz |
Jeff Garzik | 669a5db | 2006-08-29 18:12:40 -0400 | [diff] [blame] | 6 | * |
| 7 | * Based upon linux/drivers/ide/pci/sis5513.c |
| 8 | * Copyright (C) 1999-2000 Andre Hedrick <andre@linux-ide.org> |
| 9 | * Copyright (C) 2002 Lionel Bouton <Lionel.Bouton@inet6.fr>, Maintainer |
| 10 | * Copyright (C) 2003 Vojtech Pavlik <vojtech@suse.cz> |
| 11 | * SiS Taiwan : for direct support and hardware. |
| 12 | * Daniela Engert : for initial ATA100 advices and numerous others. |
| 13 | * John Fremlin, Manfred Spraul, Dave Morgan, Peter Kjellerstedt : |
| 14 | * for checking code correctness, providing patches. |
| 15 | * Original tests and design on the SiS620 chipset. |
| 16 | * ATA100 tests and design on the SiS735 chipset. |
| 17 | * ATA16/33 support from specs |
| 18 | * ATA133 support for SiS961/962 by L.C. Chang <lcchang@sis.com.tw> |
| 19 | * |
| 20 | * |
| 21 | * TODO |
| 22 | * Check MWDMA on drives that don't support MWDMA speed pio cycles ? |
| 23 | * More Testing |
| 24 | */ |
| 25 | |
| 26 | #include <linux/kernel.h> |
| 27 | #include <linux/module.h> |
| 28 | #include <linux/pci.h> |
Jeff Garzik | 669a5db | 2006-08-29 18:12:40 -0400 | [diff] [blame] | 29 | #include <linux/blkdev.h> |
| 30 | #include <linux/delay.h> |
| 31 | #include <linux/device.h> |
| 32 | #include <scsi/scsi_host.h> |
| 33 | #include <linux/libata.h> |
| 34 | #include <linux/ata.h> |
Alan | 4bb64fb | 2007-02-16 01:40:04 -0800 | [diff] [blame] | 35 | #include "sis.h" |
Jeff Garzik | 669a5db | 2006-08-29 18:12:40 -0400 | [diff] [blame] | 36 | |
| 37 | #define DRV_NAME "pata_sis" |
Bartlomiej Zolnierkiewicz | 4761c06 | 2007-07-31 22:02:41 +0200 | [diff] [blame] | 38 | #define DRV_VERSION "0.5.2" |
Jeff Garzik | 669a5db | 2006-08-29 18:12:40 -0400 | [diff] [blame] | 39 | |
| 40 | struct sis_chipset { |
Tejun Heo | 1626aeb | 2007-05-04 12:43:58 +0200 | [diff] [blame] | 41 | u16 device; /* PCI host ID */ |
| 42 | const struct ata_port_info *info; /* Info block */ |
Jeff Garzik | 669a5db | 2006-08-29 18:12:40 -0400 | [diff] [blame] | 43 | /* Probably add family, cable detect type etc here to clean |
| 44 | up code later */ |
| 45 | }; |
| 46 | |
Jakub W. Jozwicki J | 7dcbc1f | 2007-01-09 09:01:19 +0900 | [diff] [blame] | 47 | struct sis_laptop { |
| 48 | u16 device; |
| 49 | u16 subvendor; |
| 50 | u16 subdevice; |
| 51 | }; |
| 52 | |
| 53 | static const struct sis_laptop sis_laptop[] = { |
| 54 | /* devid, subvendor, subdev */ |
| 55 | { 0x5513, 0x1043, 0x1107 }, /* ASUS A6K */ |
Alan Cox | 4f2d47c | 2007-08-22 22:56:43 +0100 | [diff] [blame] | 56 | { 0x5513, 0x1734, 0x105F }, /* FSC Amilo A1630 */ |
Dan McGee | edc7d12 | 2011-09-07 11:23:22 -0500 | [diff] [blame] | 57 | { 0x5513, 0x1071, 0x8640 }, /* EasyNote K5305 */ |
Jakub W. Jozwicki J | 7dcbc1f | 2007-01-09 09:01:19 +0900 | [diff] [blame] | 58 | /* end marker */ |
| 59 | { 0, } |
| 60 | }; |
| 61 | |
| 62 | static int sis_short_ata40(struct pci_dev *dev) |
| 63 | { |
| 64 | const struct sis_laptop *lap = &sis_laptop[0]; |
| 65 | |
| 66 | while (lap->device) { |
| 67 | if (lap->device == dev->device && |
| 68 | lap->subvendor == dev->subsystem_vendor && |
| 69 | lap->subdevice == dev->subsystem_device) |
| 70 | return 1; |
| 71 | lap++; |
| 72 | } |
| 73 | |
| 74 | return 0; |
| 75 | } |
| 76 | |
Jeff Garzik | 669a5db | 2006-08-29 18:12:40 -0400 | [diff] [blame] | 77 | /** |
Dan McGee | edc7d12 | 2011-09-07 11:23:22 -0500 | [diff] [blame] | 78 | * sis_old_port_base - return PCI configuration base for dev |
Jeff Garzik | 669a5db | 2006-08-29 18:12:40 -0400 | [diff] [blame] | 79 | * @adev: device |
| 80 | * |
| 81 | * Returns the base of the PCI configuration registers for this port |
| 82 | * number. |
| 83 | */ |
| 84 | |
Alan Cox | dd668d1 | 2007-05-21 15:00:53 +0100 | [diff] [blame] | 85 | static int sis_old_port_base(struct ata_device *adev) |
Jeff Garzik | 669a5db | 2006-08-29 18:12:40 -0400 | [diff] [blame] | 86 | { |
Dan McGee | edc7d12 | 2011-09-07 11:23:22 -0500 | [diff] [blame] | 87 | return 0x40 + (4 * adev->link->ap->port_no) + (2 * adev->devno); |
Jeff Garzik | 669a5db | 2006-08-29 18:12:40 -0400 | [diff] [blame] | 88 | } |
| 89 | |
| 90 | /** |
Dan McGee | edc7d12 | 2011-09-07 11:23:22 -0500 | [diff] [blame] | 91 | * sis_port_base - return PCI configuration base for dev |
Dan McGee | 023a017 | 2011-09-07 11:23:18 -0500 | [diff] [blame] | 92 | * @adev: device |
| 93 | * |
| 94 | * Returns the base of the PCI configuration registers for this port |
| 95 | * number. |
| 96 | */ |
| 97 | |
| 98 | static int sis_port_base(struct ata_device *adev) |
| 99 | { |
| 100 | struct ata_port *ap = adev->link->ap; |
| 101 | struct pci_dev *pdev = to_pci_dev(ap->host->dev); |
| 102 | int port = 0x40; |
| 103 | u32 reg54; |
| 104 | |
| 105 | /* If bit 30 is set then the registers are mapped at 0x70 not 0x40 */ |
| 106 | pci_read_config_dword(pdev, 0x54, ®54); |
| 107 | if (reg54 & 0x40000000) |
| 108 | port = 0x70; |
| 109 | |
| 110 | return port + (8 * ap->port_no) + (4 * adev->devno); |
| 111 | } |
| 112 | |
| 113 | /** |
Dan McGee | edc7d12 | 2011-09-07 11:23:22 -0500 | [diff] [blame] | 114 | * sis_133_cable_detect - check for 40/80 pin |
Jeff Garzik | 669a5db | 2006-08-29 18:12:40 -0400 | [diff] [blame] | 115 | * @ap: Port |
Tejun Heo | d4b2bab | 2007-02-02 16:50:52 +0900 | [diff] [blame] | 116 | * @deadline: deadline jiffies for the operation |
Jeff Garzik | 669a5db | 2006-08-29 18:12:40 -0400 | [diff] [blame] | 117 | * |
| 118 | * Perform cable detection for the later UDMA133 capable |
| 119 | * SiS chipset. |
| 120 | */ |
| 121 | |
Alan Cox | 2e413f5 | 2007-03-07 16:54:24 +0000 | [diff] [blame] | 122 | static int sis_133_cable_detect(struct ata_port *ap) |
| 123 | { |
| 124 | struct pci_dev *pdev = to_pci_dev(ap->host->dev); |
| 125 | u16 tmp; |
| 126 | |
| 127 | /* The top bit of this register is the cable detect bit */ |
| 128 | pci_read_config_word(pdev, 0x50 + 2 * ap->port_no, &tmp); |
| 129 | if ((tmp & 0x8000) && !sis_short_ata40(pdev)) |
| 130 | return ATA_CBL_PATA40; |
| 131 | return ATA_CBL_PATA80; |
| 132 | } |
| 133 | |
| 134 | /** |
Dan McGee | edc7d12 | 2011-09-07 11:23:22 -0500 | [diff] [blame] | 135 | * sis_66_cable_detect - check for 40/80 pin |
Alan Cox | 2e413f5 | 2007-03-07 16:54:24 +0000 | [diff] [blame] | 136 | * @ap: Port |
| 137 | * |
| 138 | * Perform cable detection on the UDMA66, UDMA100 and early UDMA133 |
| 139 | * SiS IDE controllers. |
| 140 | */ |
| 141 | |
| 142 | static int sis_66_cable_detect(struct ata_port *ap) |
| 143 | { |
| 144 | struct pci_dev *pdev = to_pci_dev(ap->host->dev); |
| 145 | u8 tmp; |
| 146 | |
| 147 | /* Older chips keep cable detect in bits 4/5 of reg 0x48 */ |
| 148 | pci_read_config_byte(pdev, 0x48, &tmp); |
| 149 | tmp >>= ap->port_no; |
| 150 | if ((tmp & 0x10) && !sis_short_ata40(pdev)) |
| 151 | return ATA_CBL_PATA40; |
| 152 | return ATA_CBL_PATA80; |
| 153 | } |
| 154 | |
| 155 | |
| 156 | /** |
Dan McGee | edc7d12 | 2011-09-07 11:23:22 -0500 | [diff] [blame] | 157 | * sis_pre_reset - probe begin |
Tejun Heo | cc0680a | 2007-08-06 18:36:23 +0900 | [diff] [blame] | 158 | * @link: ATA link |
Tejun Heo | d4b2bab | 2007-02-02 16:50:52 +0900 | [diff] [blame] | 159 | * @deadline: deadline jiffies for the operation |
Alan Cox | 2e413f5 | 2007-03-07 16:54:24 +0000 | [diff] [blame] | 160 | * |
| 161 | * Set up cable type and use generic probe init |
| 162 | */ |
| 163 | |
Tejun Heo | cc0680a | 2007-08-06 18:36:23 +0900 | [diff] [blame] | 164 | static int sis_pre_reset(struct ata_link *link, unsigned long deadline) |
Jeff Garzik | 669a5db | 2006-08-29 18:12:40 -0400 | [diff] [blame] | 165 | { |
| 166 | static const struct pci_bits sis_enable_bits[] = { |
| 167 | { 0x4aU, 1U, 0x02UL, 0x02UL }, /* port 0 */ |
| 168 | { 0x4aU, 1U, 0x04UL, 0x04UL }, /* port 1 */ |
| 169 | }; |
Jeff Garzik | 85cd725 | 2006-08-31 00:03:49 -0400 | [diff] [blame] | 170 | |
Tejun Heo | cc0680a | 2007-08-06 18:36:23 +0900 | [diff] [blame] | 171 | struct ata_port *ap = link->ap; |
Jeff Garzik | 669a5db | 2006-08-29 18:12:40 -0400 | [diff] [blame] | 172 | struct pci_dev *pdev = to_pci_dev(ap->host->dev); |
Jeff Garzik | 669a5db | 2006-08-29 18:12:40 -0400 | [diff] [blame] | 173 | |
Alan Cox | c961922 | 2006-09-26 17:53:38 +0100 | [diff] [blame] | 174 | if (!pci_test_config_bits(pdev, &sis_enable_bits[ap->port_no])) |
| 175 | return -ENOENT; |
Tejun Heo | d4b2bab | 2007-02-02 16:50:52 +0900 | [diff] [blame] | 176 | |
Alan Cox | 15ce094 | 2007-05-25 20:50:24 +0100 | [diff] [blame] | 177 | /* Clear the FIFO settings. We can't enable the FIFO until |
| 178 | we know we are poking at a disk */ |
| 179 | pci_write_config_byte(pdev, 0x4B, 0); |
Tejun Heo | 9363c38 | 2008-04-07 22:47:16 +0900 | [diff] [blame] | 180 | return ata_sff_prereset(link, deadline); |
Jeff Garzik | 669a5db | 2006-08-29 18:12:40 -0400 | [diff] [blame] | 181 | } |
| 182 | |
Alan Cox | 2e413f5 | 2007-03-07 16:54:24 +0000 | [diff] [blame] | 183 | |
Jeff Garzik | 669a5db | 2006-08-29 18:12:40 -0400 | [diff] [blame] | 184 | /** |
Dan McGee | edc7d12 | 2011-09-07 11:23:22 -0500 | [diff] [blame] | 185 | * sis_set_fifo - Set RWP fifo bits for this device |
Jeff Garzik | 669a5db | 2006-08-29 18:12:40 -0400 | [diff] [blame] | 186 | * @ap: Port |
| 187 | * @adev: Device |
| 188 | * |
| 189 | * SIS chipsets implement prefetch/postwrite bits for each device |
| 190 | * on both channels. This functionality is not ATAPI compatible and |
| 191 | * must be configured according to the class of device present |
| 192 | */ |
| 193 | |
| 194 | static void sis_set_fifo(struct ata_port *ap, struct ata_device *adev) |
| 195 | { |
| 196 | struct pci_dev *pdev = to_pci_dev(ap->host->dev); |
| 197 | u8 fifoctrl; |
| 198 | u8 mask = 0x11; |
| 199 | |
| 200 | mask <<= (2 * ap->port_no); |
| 201 | mask <<= adev->devno; |
| 202 | |
| 203 | /* This holds various bits including the FIFO control */ |
| 204 | pci_read_config_byte(pdev, 0x4B, &fifoctrl); |
| 205 | fifoctrl &= ~mask; |
| 206 | |
| 207 | /* Enable for ATA (disk) only */ |
| 208 | if (adev->class == ATA_DEV_ATA) |
| 209 | fifoctrl |= mask; |
| 210 | pci_write_config_byte(pdev, 0x4B, fifoctrl); |
| 211 | } |
| 212 | |
| 213 | /** |
| 214 | * sis_old_set_piomode - Initialize host controller PATA PIO timings |
| 215 | * @ap: Port whose timings we are configuring |
| 216 | * @adev: Device we are configuring for. |
| 217 | * |
| 218 | * Set PIO mode for device, in host controller PCI config space. This |
| 219 | * function handles PIO set up for all chips that are pre ATA100 and |
| 220 | * also early ATA100 devices. |
| 221 | * |
| 222 | * LOCKING: |
| 223 | * None (inherited from caller). |
| 224 | */ |
| 225 | |
| 226 | static void sis_old_set_piomode (struct ata_port *ap, struct ata_device *adev) |
| 227 | { |
Dan McGee | edc7d12 | 2011-09-07 11:23:22 -0500 | [diff] [blame] | 228 | struct pci_dev *pdev = to_pci_dev(ap->host->dev); |
Alan Cox | dd668d1 | 2007-05-21 15:00:53 +0100 | [diff] [blame] | 229 | int port = sis_old_port_base(adev); |
Jeff Garzik | 669a5db | 2006-08-29 18:12:40 -0400 | [diff] [blame] | 230 | u8 t1, t2; |
| 231 | int speed = adev->pio_mode - XFER_PIO_0; |
| 232 | |
Dan McGee | c03a476 | 2011-09-07 11:23:21 -0500 | [diff] [blame] | 233 | static const u8 active[] = { 0x00, 0x07, 0x04, 0x03, 0x01 }; |
| 234 | static const u8 recovery[] = { 0x00, 0x06, 0x04, 0x03, 0x03 }; |
Jeff Garzik | 669a5db | 2006-08-29 18:12:40 -0400 | [diff] [blame] | 235 | |
| 236 | sis_set_fifo(ap, adev); |
| 237 | |
| 238 | pci_read_config_byte(pdev, port, &t1); |
| 239 | pci_read_config_byte(pdev, port + 1, &t2); |
| 240 | |
| 241 | t1 &= ~0x0F; /* Clear active/recovery timings */ |
| 242 | t2 &= ~0x07; |
| 243 | |
| 244 | t1 |= active[speed]; |
| 245 | t2 |= recovery[speed]; |
| 246 | |
| 247 | pci_write_config_byte(pdev, port, t1); |
| 248 | pci_write_config_byte(pdev, port + 1, t2); |
| 249 | } |
| 250 | |
| 251 | /** |
Bartlomiej Zolnierkiewicz | 4761c06 | 2007-07-31 22:02:41 +0200 | [diff] [blame] | 252 | * sis_100_set_piomode - Initialize host controller PATA PIO timings |
Jeff Garzik | 669a5db | 2006-08-29 18:12:40 -0400 | [diff] [blame] | 253 | * @ap: Port whose timings we are configuring |
| 254 | * @adev: Device we are configuring for. |
| 255 | * |
| 256 | * Set PIO mode for device, in host controller PCI config space. This |
| 257 | * function handles PIO set up for ATA100 devices and early ATA133. |
| 258 | * |
| 259 | * LOCKING: |
| 260 | * None (inherited from caller). |
| 261 | */ |
| 262 | |
| 263 | static void sis_100_set_piomode (struct ata_port *ap, struct ata_device *adev) |
| 264 | { |
Dan McGee | edc7d12 | 2011-09-07 11:23:22 -0500 | [diff] [blame] | 265 | struct pci_dev *pdev = to_pci_dev(ap->host->dev); |
Alan Cox | dd668d1 | 2007-05-21 15:00:53 +0100 | [diff] [blame] | 266 | int port = sis_old_port_base(adev); |
Jeff Garzik | 669a5db | 2006-08-29 18:12:40 -0400 | [diff] [blame] | 267 | int speed = adev->pio_mode - XFER_PIO_0; |
| 268 | |
Dan McGee | c03a476 | 2011-09-07 11:23:21 -0500 | [diff] [blame] | 269 | static const u8 actrec[] = { 0x00, 0x67, 0x44, 0x33, 0x31 }; |
Jeff Garzik | 669a5db | 2006-08-29 18:12:40 -0400 | [diff] [blame] | 270 | |
| 271 | sis_set_fifo(ap, adev); |
| 272 | |
| 273 | pci_write_config_byte(pdev, port, actrec[speed]); |
| 274 | } |
| 275 | |
| 276 | /** |
Jeff Garzik | 1b52f2a | 2009-12-07 11:41:25 -0500 | [diff] [blame] | 277 | * sis_133_set_piomode - Initialize host controller PATA PIO timings |
Jeff Garzik | 669a5db | 2006-08-29 18:12:40 -0400 | [diff] [blame] | 278 | * @ap: Port whose timings we are configuring |
| 279 | * @adev: Device we are configuring for. |
| 280 | * |
| 281 | * Set PIO mode for device, in host controller PCI config space. This |
Jeff Garzik | 1b52f2a | 2009-12-07 11:41:25 -0500 | [diff] [blame] | 282 | * function handles PIO set up for the later ATA133 devices. |
Jeff Garzik | 669a5db | 2006-08-29 18:12:40 -0400 | [diff] [blame] | 283 | * |
| 284 | * LOCKING: |
| 285 | * None (inherited from caller). |
| 286 | */ |
| 287 | |
Jeff Garzik | 1b52f2a | 2009-12-07 11:41:25 -0500 | [diff] [blame] | 288 | static void sis_133_set_piomode (struct ata_port *ap, struct ata_device *adev) |
Jeff Garzik | 669a5db | 2006-08-29 18:12:40 -0400 | [diff] [blame] | 289 | { |
Dan McGee | edc7d12 | 2011-09-07 11:23:22 -0500 | [diff] [blame] | 290 | struct pci_dev *pdev = to_pci_dev(ap->host->dev); |
Dan McGee | 023a017 | 2011-09-07 11:23:18 -0500 | [diff] [blame] | 291 | int port; |
Jeff Garzik | 669a5db | 2006-08-29 18:12:40 -0400 | [diff] [blame] | 292 | u32 t1; |
Jeff Garzik | 1b52f2a | 2009-12-07 11:41:25 -0500 | [diff] [blame] | 293 | int speed = adev->pio_mode - XFER_PIO_0; |
Jeff Garzik | 669a5db | 2006-08-29 18:12:40 -0400 | [diff] [blame] | 294 | |
Dan McGee | c03a476 | 2011-09-07 11:23:21 -0500 | [diff] [blame] | 295 | static const u32 timing133[] = { |
Jeff Garzik | 669a5db | 2006-08-29 18:12:40 -0400 | [diff] [blame] | 296 | 0x28269000, /* Recovery << 24 | Act << 16 | Ini << 12 */ |
| 297 | 0x0C266000, |
| 298 | 0x04263000, |
| 299 | 0x0C0A3000, |
| 300 | 0x05093000 |
| 301 | }; |
Dan McGee | c03a476 | 2011-09-07 11:23:21 -0500 | [diff] [blame] | 302 | static const u32 timing100[] = { |
Jeff Garzik | 669a5db | 2006-08-29 18:12:40 -0400 | [diff] [blame] | 303 | 0x1E1C6000, /* Recovery << 24 | Act << 16 | Ini << 12 */ |
| 304 | 0x091C4000, |
| 305 | 0x031C2000, |
| 306 | 0x09072000, |
| 307 | 0x04062000 |
| 308 | }; |
| 309 | |
| 310 | sis_set_fifo(ap, adev); |
| 311 | |
Dan McGee | 023a017 | 2011-09-07 11:23:18 -0500 | [diff] [blame] | 312 | port = sis_port_base(adev); |
Jeff Garzik | 669a5db | 2006-08-29 18:12:40 -0400 | [diff] [blame] | 313 | pci_read_config_dword(pdev, port, &t1); |
| 314 | t1 &= 0xC0C00FFF; /* Mask out timing */ |
| 315 | |
| 316 | if (t1 & 0x08) /* 100 or 133 ? */ |
| 317 | t1 |= timing133[speed]; |
| 318 | else |
| 319 | t1 |= timing100[speed]; |
| 320 | pci_write_config_byte(pdev, port, t1); |
| 321 | } |
| 322 | |
| 323 | /** |
| 324 | * sis_old_set_dmamode - Initialize host controller PATA DMA timings |
| 325 | * @ap: Port whose timings we are configuring |
| 326 | * @adev: Device to program |
| 327 | * |
| 328 | * Set UDMA/MWDMA mode for device, in host controller PCI config space. |
| 329 | * Handles pre UDMA and UDMA33 devices. Supports MWDMA as well unlike |
| 330 | * the old ide/pci driver. |
| 331 | * |
| 332 | * LOCKING: |
| 333 | * None (inherited from caller). |
| 334 | */ |
| 335 | |
| 336 | static void sis_old_set_dmamode (struct ata_port *ap, struct ata_device *adev) |
| 337 | { |
Dan McGee | edc7d12 | 2011-09-07 11:23:22 -0500 | [diff] [blame] | 338 | struct pci_dev *pdev = to_pci_dev(ap->host->dev); |
Jeff Garzik | 669a5db | 2006-08-29 18:12:40 -0400 | [diff] [blame] | 339 | int speed = adev->dma_mode - XFER_MW_DMA_0; |
Alan Cox | dd668d1 | 2007-05-21 15:00:53 +0100 | [diff] [blame] | 340 | int drive_pci = sis_old_port_base(adev); |
Jeff Garzik | 669a5db | 2006-08-29 18:12:40 -0400 | [diff] [blame] | 341 | u16 timing; |
| 342 | |
Dan McGee | c03a476 | 2011-09-07 11:23:21 -0500 | [diff] [blame] | 343 | static const u16 mwdma_bits[] = { 0x008, 0x302, 0x301 }; |
| 344 | static const u16 udma_bits[] = { 0xE000, 0xC000, 0xA000 }; |
Jeff Garzik | 669a5db | 2006-08-29 18:12:40 -0400 | [diff] [blame] | 345 | |
| 346 | pci_read_config_word(pdev, drive_pci, &timing); |
| 347 | |
| 348 | if (adev->dma_mode < XFER_UDMA_0) { |
| 349 | /* bits 3-0 hold recovery timing bits 8-10 active timing and |
Lucas De Marchi | 25985ed | 2011-03-30 22:57:33 -0300 | [diff] [blame] | 350 | the higher bits are dependent on the device */ |
Bartlomiej Zolnierkiewicz | 4761c06 | 2007-07-31 22:02:41 +0200 | [diff] [blame] | 351 | timing &= ~0x870F; |
Jeff Garzik | 669a5db | 2006-08-29 18:12:40 -0400 | [diff] [blame] | 352 | timing |= mwdma_bits[speed]; |
Jeff Garzik | 669a5db | 2006-08-29 18:12:40 -0400 | [diff] [blame] | 353 | } else { |
| 354 | /* Bit 15 is UDMA on/off, bit 13-14 are cycle time */ |
| 355 | speed = adev->dma_mode - XFER_UDMA_0; |
| 356 | timing &= ~0x6000; |
| 357 | timing |= udma_bits[speed]; |
| 358 | } |
Bartlomiej Zolnierkiewicz | 4761c06 | 2007-07-31 22:02:41 +0200 | [diff] [blame] | 359 | pci_write_config_word(pdev, drive_pci, timing); |
Jeff Garzik | 669a5db | 2006-08-29 18:12:40 -0400 | [diff] [blame] | 360 | } |
| 361 | |
| 362 | /** |
| 363 | * sis_66_set_dmamode - Initialize host controller PATA DMA timings |
| 364 | * @ap: Port whose timings we are configuring |
| 365 | * @adev: Device to program |
| 366 | * |
| 367 | * Set UDMA/MWDMA mode for device, in host controller PCI config space. |
| 368 | * Handles UDMA66 and early UDMA100 devices. Supports MWDMA as well unlike |
| 369 | * the old ide/pci driver. |
| 370 | * |
| 371 | * LOCKING: |
| 372 | * None (inherited from caller). |
| 373 | */ |
| 374 | |
| 375 | static void sis_66_set_dmamode (struct ata_port *ap, struct ata_device *adev) |
| 376 | { |
Dan McGee | edc7d12 | 2011-09-07 11:23:22 -0500 | [diff] [blame] | 377 | struct pci_dev *pdev = to_pci_dev(ap->host->dev); |
Jeff Garzik | 669a5db | 2006-08-29 18:12:40 -0400 | [diff] [blame] | 378 | int speed = adev->dma_mode - XFER_MW_DMA_0; |
Alan Cox | dd668d1 | 2007-05-21 15:00:53 +0100 | [diff] [blame] | 379 | int drive_pci = sis_old_port_base(adev); |
Jeff Garzik | 669a5db | 2006-08-29 18:12:40 -0400 | [diff] [blame] | 380 | u16 timing; |
| 381 | |
Tejun Heo | edeb614 | 2007-09-21 16:29:05 +0900 | [diff] [blame] | 382 | /* MWDMA 0-2 and UDMA 0-5 */ |
Dan McGee | c03a476 | 2011-09-07 11:23:21 -0500 | [diff] [blame] | 383 | static const u16 mwdma_bits[] = { 0x008, 0x302, 0x301 }; |
| 384 | static const u16 udma_bits[] = { 0xF000, 0xD000, 0xB000, 0xA000, 0x9000, 0x8000 }; |
Jeff Garzik | 669a5db | 2006-08-29 18:12:40 -0400 | [diff] [blame] | 385 | |
| 386 | pci_read_config_word(pdev, drive_pci, &timing); |
| 387 | |
| 388 | if (adev->dma_mode < XFER_UDMA_0) { |
| 389 | /* bits 3-0 hold recovery timing bits 8-10 active timing and |
Lucas De Marchi | 25985ed | 2011-03-30 22:57:33 -0300 | [diff] [blame] | 390 | the higher bits are dependent on the device, bit 15 udma */ |
Alan Cox | dd668d1 | 2007-05-21 15:00:53 +0100 | [diff] [blame] | 391 | timing &= ~0x870F; |
Jeff Garzik | 669a5db | 2006-08-29 18:12:40 -0400 | [diff] [blame] | 392 | timing |= mwdma_bits[speed]; |
| 393 | } else { |
| 394 | /* Bit 15 is UDMA on/off, bit 12-14 are cycle time */ |
| 395 | speed = adev->dma_mode - XFER_UDMA_0; |
Alan Cox | dd668d1 | 2007-05-21 15:00:53 +0100 | [diff] [blame] | 396 | timing &= ~0xF000; |
Jeff Garzik | 669a5db | 2006-08-29 18:12:40 -0400 | [diff] [blame] | 397 | timing |= udma_bits[speed]; |
| 398 | } |
| 399 | pci_write_config_word(pdev, drive_pci, timing); |
| 400 | } |
| 401 | |
| 402 | /** |
| 403 | * sis_100_set_dmamode - Initialize host controller PATA DMA timings |
| 404 | * @ap: Port whose timings we are configuring |
| 405 | * @adev: Device to program |
| 406 | * |
| 407 | * Set UDMA/MWDMA mode for device, in host controller PCI config space. |
Jeff Garzik | 1b52f2a | 2009-12-07 11:41:25 -0500 | [diff] [blame] | 408 | * Handles UDMA66 and early UDMA100 devices. |
Jeff Garzik | 669a5db | 2006-08-29 18:12:40 -0400 | [diff] [blame] | 409 | * |
| 410 | * LOCKING: |
| 411 | * None (inherited from caller). |
| 412 | */ |
| 413 | |
| 414 | static void sis_100_set_dmamode (struct ata_port *ap, struct ata_device *adev) |
| 415 | { |
Dan McGee | edc7d12 | 2011-09-07 11:23:22 -0500 | [diff] [blame] | 416 | struct pci_dev *pdev = to_pci_dev(ap->host->dev); |
Jeff Garzik | 669a5db | 2006-08-29 18:12:40 -0400 | [diff] [blame] | 417 | int speed = adev->dma_mode - XFER_MW_DMA_0; |
Alan Cox | dd668d1 | 2007-05-21 15:00:53 +0100 | [diff] [blame] | 418 | int drive_pci = sis_old_port_base(adev); |
Jeff Garzik | 1b52f2a | 2009-12-07 11:41:25 -0500 | [diff] [blame] | 419 | u8 timing; |
Jeff Garzik | 669a5db | 2006-08-29 18:12:40 -0400 | [diff] [blame] | 420 | |
Dan McGee | c03a476 | 2011-09-07 11:23:21 -0500 | [diff] [blame] | 421 | static const u8 udma_bits[] = { 0x8B, 0x87, 0x85, 0x83, 0x82, 0x81}; |
Jeff Garzik | 669a5db | 2006-08-29 18:12:40 -0400 | [diff] [blame] | 422 | |
Jeff Garzik | 1b52f2a | 2009-12-07 11:41:25 -0500 | [diff] [blame] | 423 | pci_read_config_byte(pdev, drive_pci + 1, &timing); |
Jeff Garzik | 669a5db | 2006-08-29 18:12:40 -0400 | [diff] [blame] | 424 | |
| 425 | if (adev->dma_mode < XFER_UDMA_0) { |
Jeff Garzik | 1b52f2a | 2009-12-07 11:41:25 -0500 | [diff] [blame] | 426 | /* NOT SUPPORTED YET: NEED DATA SHEET. DITTO IN OLD DRIVER */ |
Jeff Garzik | 669a5db | 2006-08-29 18:12:40 -0400 | [diff] [blame] | 427 | } else { |
Alan Cox | dd668d1 | 2007-05-21 15:00:53 +0100 | [diff] [blame] | 428 | /* Bit 7 is UDMA on/off, bit 0-3 are cycle time */ |
Jeff Garzik | 669a5db | 2006-08-29 18:12:40 -0400 | [diff] [blame] | 429 | speed = adev->dma_mode - XFER_UDMA_0; |
Jeff Garzik | 1b52f2a | 2009-12-07 11:41:25 -0500 | [diff] [blame] | 430 | timing &= ~0x8F; |
Jeff Garzik | 669a5db | 2006-08-29 18:12:40 -0400 | [diff] [blame] | 431 | timing |= udma_bits[speed]; |
| 432 | } |
Jeff Garzik | 1b52f2a | 2009-12-07 11:41:25 -0500 | [diff] [blame] | 433 | pci_write_config_byte(pdev, drive_pci + 1, timing); |
Jeff Garzik | 669a5db | 2006-08-29 18:12:40 -0400 | [diff] [blame] | 434 | } |
| 435 | |
| 436 | /** |
| 437 | * sis_133_early_set_dmamode - Initialize host controller PATA DMA timings |
| 438 | * @ap: Port whose timings we are configuring |
| 439 | * @adev: Device to program |
| 440 | * |
| 441 | * Set UDMA/MWDMA mode for device, in host controller PCI config space. |
Bartlomiej Zolnierkiewicz | 4761c06 | 2007-07-31 22:02:41 +0200 | [diff] [blame] | 442 | * Handles early SiS 961 bridges. |
Jeff Garzik | 669a5db | 2006-08-29 18:12:40 -0400 | [diff] [blame] | 443 | * |
| 444 | * LOCKING: |
| 445 | * None (inherited from caller). |
| 446 | */ |
| 447 | |
| 448 | static void sis_133_early_set_dmamode (struct ata_port *ap, struct ata_device *adev) |
| 449 | { |
Dan McGee | edc7d12 | 2011-09-07 11:23:22 -0500 | [diff] [blame] | 450 | struct pci_dev *pdev = to_pci_dev(ap->host->dev); |
Jeff Garzik | 669a5db | 2006-08-29 18:12:40 -0400 | [diff] [blame] | 451 | int speed = adev->dma_mode - XFER_MW_DMA_0; |
Alan Cox | dd668d1 | 2007-05-21 15:00:53 +0100 | [diff] [blame] | 452 | int drive_pci = sis_old_port_base(adev); |
Jeff Garzik | 1b52f2a | 2009-12-07 11:41:25 -0500 | [diff] [blame] | 453 | u8 timing; |
| 454 | /* Low 4 bits are timing */ |
| 455 | static const u8 udma_bits[] = { 0x8F, 0x8A, 0x87, 0x85, 0x83, 0x82, 0x81}; |
Jeff Garzik | 669a5db | 2006-08-29 18:12:40 -0400 | [diff] [blame] | 456 | |
Jeff Garzik | 1b52f2a | 2009-12-07 11:41:25 -0500 | [diff] [blame] | 457 | pci_read_config_byte(pdev, drive_pci + 1, &timing); |
Jeff Garzik | 669a5db | 2006-08-29 18:12:40 -0400 | [diff] [blame] | 458 | |
| 459 | if (adev->dma_mode < XFER_UDMA_0) { |
Jeff Garzik | 1b52f2a | 2009-12-07 11:41:25 -0500 | [diff] [blame] | 460 | /* NOT SUPPORTED YET: NEED DATA SHEET. DITTO IN OLD DRIVER */ |
Jeff Garzik | 669a5db | 2006-08-29 18:12:40 -0400 | [diff] [blame] | 461 | } else { |
Alan Cox | dd668d1 | 2007-05-21 15:00:53 +0100 | [diff] [blame] | 462 | /* Bit 7 is UDMA on/off, bit 0-3 are cycle time */ |
Jeff Garzik | 669a5db | 2006-08-29 18:12:40 -0400 | [diff] [blame] | 463 | speed = adev->dma_mode - XFER_UDMA_0; |
Jeff Garzik | 1b52f2a | 2009-12-07 11:41:25 -0500 | [diff] [blame] | 464 | timing &= ~0x8F; |
Jeff Garzik | 669a5db | 2006-08-29 18:12:40 -0400 | [diff] [blame] | 465 | timing |= udma_bits[speed]; |
| 466 | } |
Jeff Garzik | 1b52f2a | 2009-12-07 11:41:25 -0500 | [diff] [blame] | 467 | pci_write_config_byte(pdev, drive_pci + 1, timing); |
Jeff Garzik | 669a5db | 2006-08-29 18:12:40 -0400 | [diff] [blame] | 468 | } |
| 469 | |
| 470 | /** |
| 471 | * sis_133_set_dmamode - Initialize host controller PATA DMA timings |
| 472 | * @ap: Port whose timings we are configuring |
| 473 | * @adev: Device to program |
| 474 | * |
| 475 | * Set UDMA/MWDMA mode for device, in host controller PCI config space. |
Jeff Garzik | 669a5db | 2006-08-29 18:12:40 -0400 | [diff] [blame] | 476 | * |
| 477 | * LOCKING: |
| 478 | * None (inherited from caller). |
| 479 | */ |
| 480 | |
| 481 | static void sis_133_set_dmamode (struct ata_port *ap, struct ata_device *adev) |
| 482 | { |
Dan McGee | edc7d12 | 2011-09-07 11:23:22 -0500 | [diff] [blame] | 483 | struct pci_dev *pdev = to_pci_dev(ap->host->dev); |
Dan McGee | 023a017 | 2011-09-07 11:23:18 -0500 | [diff] [blame] | 484 | int port; |
Jeff Garzik | 669a5db | 2006-08-29 18:12:40 -0400 | [diff] [blame] | 485 | u32 t1; |
Jeff Garzik | 669a5db | 2006-08-29 18:12:40 -0400 | [diff] [blame] | 486 | |
Dan McGee | 023a017 | 2011-09-07 11:23:18 -0500 | [diff] [blame] | 487 | port = sis_port_base(adev); |
Jeff Garzik | 669a5db | 2006-08-29 18:12:40 -0400 | [diff] [blame] | 488 | pci_read_config_dword(pdev, port, &t1); |
| 489 | |
| 490 | if (adev->dma_mode < XFER_UDMA_0) { |
Dan McGee | 14004f0 | 2011-09-07 11:23:20 -0500 | [diff] [blame] | 491 | /* Recovery << 24 | Act << 16 | Ini << 12, like PIO modes */ |
| 492 | static const u32 timing_u100[] = { 0x19154000, 0x06072000, 0x04062000 }; |
| 493 | static const u32 timing_u133[] = { 0x221C6000, 0x0C0A3000, 0x05093000 }; |
| 494 | int speed = adev->dma_mode - XFER_MW_DMA_0; |
| 495 | |
| 496 | t1 &= 0xC0C00FFF; |
| 497 | /* disable UDMA */ |
Jeff Garzik | 1b52f2a | 2009-12-07 11:41:25 -0500 | [diff] [blame] | 498 | t1 &= ~0x00000004; |
Dan McGee | 14004f0 | 2011-09-07 11:23:20 -0500 | [diff] [blame] | 499 | if (t1 & 0x08) |
| 500 | t1 |= timing_u133[speed]; |
| 501 | else |
| 502 | t1 |= timing_u100[speed]; |
Jeff Garzik | 669a5db | 2006-08-29 18:12:40 -0400 | [diff] [blame] | 503 | } else { |
Dan McGee | 14004f0 | 2011-09-07 11:23:20 -0500 | [diff] [blame] | 504 | /* bits 4- cycle time 8 - cvs time */ |
| 505 | static const u32 timing_u100[] = { 0x6B0, 0x470, 0x350, 0x140, 0x120, 0x110, 0x000 }; |
| 506 | static const u32 timing_u133[] = { 0x9F0, 0x6A0, 0x470, 0x250, 0x230, 0x220, 0x210 }; |
Dan McGee | 023a017 | 2011-09-07 11:23:18 -0500 | [diff] [blame] | 507 | int speed = adev->dma_mode - XFER_UDMA_0; |
Dan McGee | 14004f0 | 2011-09-07 11:23:20 -0500 | [diff] [blame] | 508 | |
Jeff Garzik | 669a5db | 2006-08-29 18:12:40 -0400 | [diff] [blame] | 509 | t1 &= ~0x00000FF0; |
Dan McGee | 14004f0 | 2011-09-07 11:23:20 -0500 | [diff] [blame] | 510 | /* enable UDMA */ |
Jeff Garzik | 669a5db | 2006-08-29 18:12:40 -0400 | [diff] [blame] | 511 | t1 |= 0x00000004; |
| 512 | if (t1 & 0x08) |
| 513 | t1 |= timing_u133[speed]; |
| 514 | else |
| 515 | t1 |= timing_u100[speed]; |
| 516 | } |
| 517 | pci_write_config_dword(pdev, port, t1); |
| 518 | } |
| 519 | |
Dan McGee | f30f9a5 | 2011-09-07 11:23:19 -0500 | [diff] [blame] | 520 | /** |
| 521 | * sis_133_mode_filter - mode selection filter |
| 522 | * @adev: ATA device |
| 523 | * |
| 524 | * Block UDMA6 on devices that do not support it. |
| 525 | */ |
| 526 | |
| 527 | static unsigned long sis_133_mode_filter(struct ata_device *adev, unsigned long mask) |
| 528 | { |
| 529 | struct ata_port *ap = adev->link->ap; |
| 530 | struct pci_dev *pdev = to_pci_dev(ap->host->dev); |
| 531 | int port = sis_port_base(adev); |
| 532 | u32 t1; |
| 533 | |
| 534 | pci_read_config_dword(pdev, port, &t1); |
| 535 | /* if ATA133 is disabled, mask it out */ |
| 536 | if (!(t1 & 0x08)) |
| 537 | mask &= ~(0xC0 << ATA_SHIFT_UDMA); |
| 538 | return mask; |
| 539 | } |
| 540 | |
Jeff Garzik | 669a5db | 2006-08-29 18:12:40 -0400 | [diff] [blame] | 541 | static struct scsi_host_template sis_sht = { |
Tejun Heo | 68d1d07 | 2008-03-25 12:22:49 +0900 | [diff] [blame] | 542 | ATA_BMDMA_SHT(DRV_NAME), |
Jeff Garzik | 669a5db | 2006-08-29 18:12:40 -0400 | [diff] [blame] | 543 | }; |
| 544 | |
Tejun Heo | 029cfd6 | 2008-03-25 12:22:49 +0900 | [diff] [blame] | 545 | static struct ata_port_operations sis_133_for_sata_ops = { |
| 546 | .inherits = &ata_bmdma_port_ops, |
Jeff Garzik | 669a5db | 2006-08-29 18:12:40 -0400 | [diff] [blame] | 547 | .set_piomode = sis_133_set_piomode, |
| 548 | .set_dmamode = sis_133_set_dmamode, |
Tejun Heo | 029cfd6 | 2008-03-25 12:22:49 +0900 | [diff] [blame] | 549 | .cable_detect = sis_133_cable_detect, |
| 550 | }; |
Jeff Garzik | 669a5db | 2006-08-29 18:12:40 -0400 | [diff] [blame] | 551 | |
Tejun Heo | 029cfd6 | 2008-03-25 12:22:49 +0900 | [diff] [blame] | 552 | static struct ata_port_operations sis_base_ops = { |
| 553 | .inherits = &ata_bmdma_port_ops, |
Tejun Heo | a1efdab | 2008-03-25 12:22:50 +0900 | [diff] [blame] | 554 | .prereset = sis_pre_reset, |
Jeff Garzik | 669a5db | 2006-08-29 18:12:40 -0400 | [diff] [blame] | 555 | }; |
| 556 | |
Tejun Heo | 029cfd6 | 2008-03-25 12:22:49 +0900 | [diff] [blame] | 557 | static struct ata_port_operations sis_133_ops = { |
| 558 | .inherits = &sis_base_ops, |
Uwe Koziolek | a3cabb2 | 2007-06-14 23:40:43 +0200 | [diff] [blame] | 559 | .set_piomode = sis_133_set_piomode, |
| 560 | .set_dmamode = sis_133_set_dmamode, |
Uwe Koziolek | a3cabb2 | 2007-06-14 23:40:43 +0200 | [diff] [blame] | 561 | .cable_detect = sis_133_cable_detect, |
Dan McGee | f30f9a5 | 2011-09-07 11:23:19 -0500 | [diff] [blame] | 562 | .mode_filter = sis_133_mode_filter, |
Uwe Koziolek | a3cabb2 | 2007-06-14 23:40:43 +0200 | [diff] [blame] | 563 | }; |
| 564 | |
Tejun Heo | 029cfd6 | 2008-03-25 12:22:49 +0900 | [diff] [blame] | 565 | static struct ata_port_operations sis_133_early_ops = { |
| 566 | .inherits = &sis_base_ops, |
Jeff Garzik | 669a5db | 2006-08-29 18:12:40 -0400 | [diff] [blame] | 567 | .set_piomode = sis_100_set_piomode, |
| 568 | .set_dmamode = sis_133_early_set_dmamode, |
Alan Cox | 2e413f5 | 2007-03-07 16:54:24 +0000 | [diff] [blame] | 569 | .cable_detect = sis_66_cable_detect, |
Jeff Garzik | 669a5db | 2006-08-29 18:12:40 -0400 | [diff] [blame] | 570 | }; |
| 571 | |
Tejun Heo | 029cfd6 | 2008-03-25 12:22:49 +0900 | [diff] [blame] | 572 | static struct ata_port_operations sis_100_ops = { |
| 573 | .inherits = &sis_base_ops, |
Jeff Garzik | 669a5db | 2006-08-29 18:12:40 -0400 | [diff] [blame] | 574 | .set_piomode = sis_100_set_piomode, |
| 575 | .set_dmamode = sis_100_set_dmamode, |
Alan Cox | 2e413f5 | 2007-03-07 16:54:24 +0000 | [diff] [blame] | 576 | .cable_detect = sis_66_cable_detect, |
Jeff Garzik | 669a5db | 2006-08-29 18:12:40 -0400 | [diff] [blame] | 577 | }; |
| 578 | |
Tejun Heo | 029cfd6 | 2008-03-25 12:22:49 +0900 | [diff] [blame] | 579 | static struct ata_port_operations sis_66_ops = { |
| 580 | .inherits = &sis_base_ops, |
Jeff Garzik | 669a5db | 2006-08-29 18:12:40 -0400 | [diff] [blame] | 581 | .set_piomode = sis_old_set_piomode, |
| 582 | .set_dmamode = sis_66_set_dmamode, |
Alan Cox | 2e413f5 | 2007-03-07 16:54:24 +0000 | [diff] [blame] | 583 | .cable_detect = sis_66_cable_detect, |
Jeff Garzik | 669a5db | 2006-08-29 18:12:40 -0400 | [diff] [blame] | 584 | }; |
| 585 | |
Tejun Heo | 029cfd6 | 2008-03-25 12:22:49 +0900 | [diff] [blame] | 586 | static struct ata_port_operations sis_old_ops = { |
| 587 | .inherits = &sis_base_ops, |
Jeff Garzik | 669a5db | 2006-08-29 18:12:40 -0400 | [diff] [blame] | 588 | .set_piomode = sis_old_set_piomode, |
| 589 | .set_dmamode = sis_old_set_dmamode, |
Alan Cox | 2e413f5 | 2007-03-07 16:54:24 +0000 | [diff] [blame] | 590 | .cable_detect = ata_cable_40wire, |
Jeff Garzik | 669a5db | 2006-08-29 18:12:40 -0400 | [diff] [blame] | 591 | }; |
| 592 | |
Tejun Heo | 1626aeb | 2007-05-04 12:43:58 +0200 | [diff] [blame] | 593 | static const struct ata_port_info sis_info = { |
Jeff Garzik | 1d2808f | 2007-05-28 06:59:48 -0400 | [diff] [blame] | 594 | .flags = ATA_FLAG_SLAVE_POSS, |
Erik Inge Bolsø | 14bdef9 | 2009-03-14 21:38:24 +0100 | [diff] [blame] | 595 | .pio_mask = ATA_PIO4, |
| 596 | .mwdma_mask = ATA_MWDMA2, |
| 597 | /* No UDMA */ |
Jeff Garzik | 669a5db | 2006-08-29 18:12:40 -0400 | [diff] [blame] | 598 | .port_ops = &sis_old_ops, |
| 599 | }; |
Tejun Heo | 1626aeb | 2007-05-04 12:43:58 +0200 | [diff] [blame] | 600 | static const struct ata_port_info sis_info33 = { |
Jeff Garzik | 1d2808f | 2007-05-28 06:59:48 -0400 | [diff] [blame] | 601 | .flags = ATA_FLAG_SLAVE_POSS, |
Erik Inge Bolsø | 14bdef9 | 2009-03-14 21:38:24 +0100 | [diff] [blame] | 602 | .pio_mask = ATA_PIO4, |
| 603 | .mwdma_mask = ATA_MWDMA2, |
| 604 | .udma_mask = ATA_UDMA2, |
Jeff Garzik | 669a5db | 2006-08-29 18:12:40 -0400 | [diff] [blame] | 605 | .port_ops = &sis_old_ops, |
| 606 | }; |
Tejun Heo | 1626aeb | 2007-05-04 12:43:58 +0200 | [diff] [blame] | 607 | static const struct ata_port_info sis_info66 = { |
Jeff Garzik | 1d2808f | 2007-05-28 06:59:48 -0400 | [diff] [blame] | 608 | .flags = ATA_FLAG_SLAVE_POSS, |
Erik Inge Bolsø | 14bdef9 | 2009-03-14 21:38:24 +0100 | [diff] [blame] | 609 | .pio_mask = ATA_PIO4, |
| 610 | /* No MWDMA */ |
| 611 | .udma_mask = ATA_UDMA4, |
Jeff Garzik | 669a5db | 2006-08-29 18:12:40 -0400 | [diff] [blame] | 612 | .port_ops = &sis_66_ops, |
| 613 | }; |
Tejun Heo | 1626aeb | 2007-05-04 12:43:58 +0200 | [diff] [blame] | 614 | static const struct ata_port_info sis_info100 = { |
Jeff Garzik | 1d2808f | 2007-05-28 06:59:48 -0400 | [diff] [blame] | 615 | .flags = ATA_FLAG_SLAVE_POSS, |
Erik Inge Bolsø | 14bdef9 | 2009-03-14 21:38:24 +0100 | [diff] [blame] | 616 | .pio_mask = ATA_PIO4, |
| 617 | /* No MWDMA */ |
Jeff Garzik | 669a5db | 2006-08-29 18:12:40 -0400 | [diff] [blame] | 618 | .udma_mask = ATA_UDMA5, |
| 619 | .port_ops = &sis_100_ops, |
| 620 | }; |
Tejun Heo | 1626aeb | 2007-05-04 12:43:58 +0200 | [diff] [blame] | 621 | static const struct ata_port_info sis_info100_early = { |
Jeff Garzik | 1d2808f | 2007-05-28 06:59:48 -0400 | [diff] [blame] | 622 | .flags = ATA_FLAG_SLAVE_POSS, |
Erik Inge Bolsø | 14bdef9 | 2009-03-14 21:38:24 +0100 | [diff] [blame] | 623 | .pio_mask = ATA_PIO4, |
| 624 | /* No MWDMA */ |
Jeff Garzik | 669a5db | 2006-08-29 18:12:40 -0400 | [diff] [blame] | 625 | .udma_mask = ATA_UDMA5, |
Jeff Garzik | 669a5db | 2006-08-29 18:12:40 -0400 | [diff] [blame] | 626 | .port_ops = &sis_66_ops, |
| 627 | }; |
Uwe Koziolek | a3cabb2 | 2007-06-14 23:40:43 +0200 | [diff] [blame] | 628 | static const struct ata_port_info sis_info133 = { |
Jeff Garzik | 1d2808f | 2007-05-28 06:59:48 -0400 | [diff] [blame] | 629 | .flags = ATA_FLAG_SLAVE_POSS, |
Erik Inge Bolsø | 14bdef9 | 2009-03-14 21:38:24 +0100 | [diff] [blame] | 630 | .pio_mask = ATA_PIO4, |
Dan McGee | 14004f0 | 2011-09-07 11:23:20 -0500 | [diff] [blame] | 631 | .mwdma_mask = ATA_MWDMA2, |
Jeff Garzik | 669a5db | 2006-08-29 18:12:40 -0400 | [diff] [blame] | 632 | .udma_mask = ATA_UDMA6, |
| 633 | .port_ops = &sis_133_ops, |
| 634 | }; |
Uwe Koziolek | a3cabb2 | 2007-06-14 23:40:43 +0200 | [diff] [blame] | 635 | const struct ata_port_info sis_info133_for_sata = { |
Sergei Shtylyov | c10f97b | 2011-02-04 22:03:34 +0300 | [diff] [blame] | 636 | .flags = ATA_FLAG_SLAVE_POSS, |
Erik Inge Bolsø | 14bdef9 | 2009-03-14 21:38:24 +0100 | [diff] [blame] | 637 | .pio_mask = ATA_PIO4, |
| 638 | /* No MWDMA */ |
Uwe Koziolek | a3cabb2 | 2007-06-14 23:40:43 +0200 | [diff] [blame] | 639 | .udma_mask = ATA_UDMA6, |
| 640 | .port_ops = &sis_133_for_sata_ops, |
| 641 | }; |
Tejun Heo | 1626aeb | 2007-05-04 12:43:58 +0200 | [diff] [blame] | 642 | static const struct ata_port_info sis_info133_early = { |
Jeff Garzik | 1d2808f | 2007-05-28 06:59:48 -0400 | [diff] [blame] | 643 | .flags = ATA_FLAG_SLAVE_POSS, |
Erik Inge Bolsø | 14bdef9 | 2009-03-14 21:38:24 +0100 | [diff] [blame] | 644 | .pio_mask = ATA_PIO4, |
| 645 | /* No MWDMA */ |
Jeff Garzik | 669a5db | 2006-08-29 18:12:40 -0400 | [diff] [blame] | 646 | .udma_mask = ATA_UDMA6, |
| 647 | .port_ops = &sis_133_early_ops, |
| 648 | }; |
| 649 | |
Alan | 9b14dec | 2007-01-08 16:11:07 +0000 | [diff] [blame] | 650 | /* Privately shared with the SiS180 SATA driver, not for use elsewhere */ |
Uwe Koziolek | a3cabb2 | 2007-06-14 23:40:43 +0200 | [diff] [blame] | 651 | EXPORT_SYMBOL_GPL(sis_info133_for_sata); |
Jeff Garzik | 669a5db | 2006-08-29 18:12:40 -0400 | [diff] [blame] | 652 | |
| 653 | static void sis_fixup(struct pci_dev *pdev, struct sis_chipset *sis) |
| 654 | { |
| 655 | u16 regw; |
| 656 | u8 reg; |
| 657 | |
| 658 | if (sis->info == &sis_info133) { |
| 659 | pci_read_config_word(pdev, 0x50, ®w); |
| 660 | if (regw & 0x08) |
| 661 | pci_write_config_word(pdev, 0x50, regw & ~0x08); |
| 662 | pci_read_config_word(pdev, 0x52, ®w); |
| 663 | if (regw & 0x08) |
| 664 | pci_write_config_word(pdev, 0x52, regw & ~0x08); |
| 665 | return; |
| 666 | } |
| 667 | |
| 668 | if (sis->info == &sis_info133_early || sis->info == &sis_info100) { |
| 669 | /* Fix up latency */ |
| 670 | pci_write_config_byte(pdev, PCI_LATENCY_TIMER, 0x80); |
| 671 | /* Set compatibility bit */ |
| 672 | pci_read_config_byte(pdev, 0x49, ®); |
| 673 | if (!(reg & 0x01)) |
| 674 | pci_write_config_byte(pdev, 0x49, reg | 0x01); |
| 675 | return; |
| 676 | } |
| 677 | |
| 678 | if (sis->info == &sis_info66 || sis->info == &sis_info100_early) { |
| 679 | /* Fix up latency */ |
| 680 | pci_write_config_byte(pdev, PCI_LATENCY_TIMER, 0x80); |
| 681 | /* Set compatibility bit */ |
| 682 | pci_read_config_byte(pdev, 0x52, ®); |
| 683 | if (!(reg & 0x04)) |
| 684 | pci_write_config_byte(pdev, 0x52, reg | 0x04); |
| 685 | return; |
| 686 | } |
| 687 | |
| 688 | if (sis->info == &sis_info33) { |
| 689 | pci_read_config_byte(pdev, PCI_CLASS_PROG, ®); |
| 690 | if (( reg & 0x0F ) != 0x00) |
| 691 | pci_write_config_byte(pdev, PCI_CLASS_PROG, reg & 0xF0); |
| 692 | /* Fall through to ATA16 fixup below */ |
| 693 | } |
| 694 | |
| 695 | if (sis->info == &sis_info || sis->info == &sis_info33) { |
| 696 | /* force per drive recovery and active timings |
| 697 | needed on ATA_33 and below chips */ |
| 698 | pci_read_config_byte(pdev, 0x52, ®); |
| 699 | if (!(reg & 0x08)) |
| 700 | pci_write_config_byte(pdev, 0x52, reg|0x08); |
| 701 | return; |
| 702 | } |
| 703 | |
| 704 | BUG(); |
| 705 | } |
| 706 | |
| 707 | /** |
| 708 | * sis_init_one - Register SiS ATA PCI device with kernel services |
| 709 | * @pdev: PCI device to register |
| 710 | * @ent: Entry in sis_pci_tbl matching with @pdev |
| 711 | * |
Dan McGee | edc7d12 | 2011-09-07 11:23:22 -0500 | [diff] [blame] | 712 | * Called from kernel PCI layer. We probe for combined mode (sigh), |
Jeff Garzik | 669a5db | 2006-08-29 18:12:40 -0400 | [diff] [blame] | 713 | * and then hand over control to libata, for it to do the rest. |
| 714 | * |
| 715 | * LOCKING: |
| 716 | * Inherited from PCI layer (may sleep). |
| 717 | * |
| 718 | * RETURNS: |
| 719 | * Zero on success, or -ERRNO value. |
| 720 | */ |
| 721 | |
| 722 | static int sis_init_one (struct pci_dev *pdev, const struct pci_device_id *ent) |
| 723 | { |
Tejun Heo | 887125e | 2008-03-25 12:22:49 +0900 | [diff] [blame] | 724 | const struct ata_port_info *ppi[] = { NULL, NULL }; |
Jeff Garzik | 669a5db | 2006-08-29 18:12:40 -0400 | [diff] [blame] | 725 | struct pci_dev *host = NULL; |
| 726 | struct sis_chipset *chipset = NULL; |
Alan Cox | f3769e9 | 2007-04-19 11:09:52 +0100 | [diff] [blame] | 727 | struct sis_chipset *sets; |
Tejun Heo | f08048e | 2008-03-25 12:22:47 +0900 | [diff] [blame] | 728 | int rc; |
Jeff Garzik | 669a5db | 2006-08-29 18:12:40 -0400 | [diff] [blame] | 729 | |
| 730 | static struct sis_chipset sis_chipsets[] = { |
Jeff Garzik | f20b16f | 2006-12-11 11:14:06 -0500 | [diff] [blame] | 731 | |
Alan Cox | af323a2 | 2006-09-12 17:15:12 +0100 | [diff] [blame] | 732 | { 0x0968, &sis_info133 }, |
| 733 | { 0x0966, &sis_info133 }, |
| 734 | { 0x0965, &sis_info133 }, |
Jeff Garzik | 669a5db | 2006-08-29 18:12:40 -0400 | [diff] [blame] | 735 | { 0x0745, &sis_info100 }, |
| 736 | { 0x0735, &sis_info100 }, |
| 737 | { 0x0733, &sis_info100 }, |
| 738 | { 0x0635, &sis_info100 }, |
| 739 | { 0x0633, &sis_info100 }, |
| 740 | |
| 741 | { 0x0730, &sis_info100_early }, /* 100 with ATA 66 layout */ |
| 742 | { 0x0550, &sis_info100_early }, /* 100 with ATA 66 layout */ |
| 743 | |
| 744 | { 0x0640, &sis_info66 }, |
| 745 | { 0x0630, &sis_info66 }, |
| 746 | { 0x0620, &sis_info66 }, |
| 747 | { 0x0540, &sis_info66 }, |
| 748 | { 0x0530, &sis_info66 }, |
| 749 | |
| 750 | { 0x5600, &sis_info33 }, |
| 751 | { 0x5598, &sis_info33 }, |
| 752 | { 0x5597, &sis_info33 }, |
| 753 | { 0x5591, &sis_info33 }, |
| 754 | { 0x5582, &sis_info33 }, |
| 755 | { 0x5581, &sis_info33 }, |
| 756 | |
| 757 | { 0x5596, &sis_info }, |
| 758 | { 0x5571, &sis_info }, |
| 759 | { 0x5517, &sis_info }, |
| 760 | { 0x5511, &sis_info }, |
| 761 | |
| 762 | {0} |
| 763 | }; |
| 764 | static struct sis_chipset sis133_early = { |
| 765 | 0x0, &sis_info133_early |
| 766 | }; |
| 767 | static struct sis_chipset sis133 = { |
| 768 | 0x0, &sis_info133 |
| 769 | }; |
| 770 | static struct sis_chipset sis100_early = { |
| 771 | 0x0, &sis_info100_early |
| 772 | }; |
| 773 | static struct sis_chipset sis100 = { |
| 774 | 0x0, &sis_info100 |
| 775 | }; |
| 776 | |
Joe Perches | 06296a1 | 2011-04-15 15:52:00 -0700 | [diff] [blame] | 777 | ata_print_version_once(&pdev->dev, DRV_VERSION); |
Jeff Garzik | 669a5db | 2006-08-29 18:12:40 -0400 | [diff] [blame] | 778 | |
Tejun Heo | f08048e | 2008-03-25 12:22:47 +0900 | [diff] [blame] | 779 | rc = pcim_enable_device(pdev); |
| 780 | if (rc) |
| 781 | return rc; |
Jeff Garzik | 669a5db | 2006-08-29 18:12:40 -0400 | [diff] [blame] | 782 | |
Tejun Heo | f08048e | 2008-03-25 12:22:47 +0900 | [diff] [blame] | 783 | /* We have to find the bridge first */ |
Alan Cox | f3769e9 | 2007-04-19 11:09:52 +0100 | [diff] [blame] | 784 | for (sets = &sis_chipsets[0]; sets->device; sets++) { |
| 785 | host = pci_get_device(PCI_VENDOR_ID_SI, sets->device, NULL); |
Jeff Garzik | 669a5db | 2006-08-29 18:12:40 -0400 | [diff] [blame] | 786 | if (host != NULL) { |
Alan Cox | f3769e9 | 2007-04-19 11:09:52 +0100 | [diff] [blame] | 787 | chipset = sets; /* Match found */ |
| 788 | if (sets->device == 0x630) { /* SIS630 */ |
Auke Kok | 44c1013 | 2007-06-08 15:46:36 -0700 | [diff] [blame] | 789 | if (host->revision >= 0x30) /* 630 ET */ |
Jeff Garzik | 669a5db | 2006-08-29 18:12:40 -0400 | [diff] [blame] | 790 | chipset = &sis100_early; |
| 791 | } |
| 792 | break; |
| 793 | } |
| 794 | } |
| 795 | |
| 796 | /* Look for concealed bridges */ |
Alan Cox | f3769e9 | 2007-04-19 11:09:52 +0100 | [diff] [blame] | 797 | if (chipset == NULL) { |
Jeff Garzik | 669a5db | 2006-08-29 18:12:40 -0400 | [diff] [blame] | 798 | /* Second check */ |
| 799 | u32 idemisc; |
| 800 | u16 trueid; |
| 801 | |
| 802 | /* Disable ID masking and register remapping then |
| 803 | see what the real ID is */ |
| 804 | |
| 805 | pci_read_config_dword(pdev, 0x54, &idemisc); |
| 806 | pci_write_config_dword(pdev, 0x54, idemisc & 0x7fffffff); |
| 807 | pci_read_config_word(pdev, PCI_DEVICE_ID, &trueid); |
| 808 | pci_write_config_dword(pdev, 0x54, idemisc); |
| 809 | |
| 810 | switch(trueid) { |
| 811 | case 0x5518: /* SIS 962/963 */ |
Dan McGee | f30f9a5 | 2011-09-07 11:23:19 -0500 | [diff] [blame] | 812 | dev_info(&pdev->dev, |
| 813 | "SiS 962/963 MuTIOL IDE UDMA133 controller\n"); |
Jeff Garzik | 669a5db | 2006-08-29 18:12:40 -0400 | [diff] [blame] | 814 | chipset = &sis133; |
| 815 | if ((idemisc & 0x40000000) == 0) { |
| 816 | pci_write_config_dword(pdev, 0x54, idemisc | 0x40000000); |
Dan McGee | f30f9a5 | 2011-09-07 11:23:19 -0500 | [diff] [blame] | 817 | dev_info(&pdev->dev, |
| 818 | "Switching to 5513 register mapping\n"); |
Jeff Garzik | 669a5db | 2006-08-29 18:12:40 -0400 | [diff] [blame] | 819 | } |
| 820 | break; |
| 821 | case 0x0180: /* SIS 965/965L */ |
Dan McGee | edc7d12 | 2011-09-07 11:23:22 -0500 | [diff] [blame] | 822 | chipset = &sis133; |
Jeff Garzik | 669a5db | 2006-08-29 18:12:40 -0400 | [diff] [blame] | 823 | break; |
| 824 | case 0x1180: /* SIS 966/966L */ |
Dan McGee | edc7d12 | 2011-09-07 11:23:22 -0500 | [diff] [blame] | 825 | chipset = &sis133; |
Jeff Garzik | 669a5db | 2006-08-29 18:12:40 -0400 | [diff] [blame] | 826 | break; |
| 827 | } |
| 828 | } |
| 829 | |
| 830 | /* Further check */ |
| 831 | if (chipset == NULL) { |
| 832 | struct pci_dev *lpc_bridge; |
| 833 | u16 trueid; |
| 834 | u8 prefctl; |
| 835 | u8 idecfg; |
Jeff Garzik | 669a5db | 2006-08-29 18:12:40 -0400 | [diff] [blame] | 836 | |
| 837 | /* Try the second unmasking technique */ |
| 838 | pci_read_config_byte(pdev, 0x4a, &idecfg); |
| 839 | pci_write_config_byte(pdev, 0x4a, idecfg | 0x10); |
| 840 | pci_read_config_word(pdev, PCI_DEVICE_ID, &trueid); |
| 841 | pci_write_config_byte(pdev, 0x4a, idecfg); |
| 842 | |
| 843 | switch(trueid) { |
| 844 | case 0x5517: |
| 845 | lpc_bridge = pci_get_slot(pdev->bus, 0x10); /* Bus 0 Dev 2 Fn 0 */ |
| 846 | if (lpc_bridge == NULL) |
| 847 | break; |
Jeff Garzik | 669a5db | 2006-08-29 18:12:40 -0400 | [diff] [blame] | 848 | pci_read_config_byte(pdev, 0x49, &prefctl); |
| 849 | pci_dev_put(lpc_bridge); |
| 850 | |
Auke Kok | 44c1013 | 2007-06-08 15:46:36 -0700 | [diff] [blame] | 851 | if (lpc_bridge->revision == 0x10 && (prefctl & 0x80)) { |
Jeff Garzik | 669a5db | 2006-08-29 18:12:40 -0400 | [diff] [blame] | 852 | chipset = &sis133_early; |
| 853 | break; |
| 854 | } |
| 855 | chipset = &sis100; |
| 856 | break; |
| 857 | } |
| 858 | } |
| 859 | pci_dev_put(host); |
| 860 | |
| 861 | /* No chipset info, no support */ |
| 862 | if (chipset == NULL) |
| 863 | return -ENODEV; |
| 864 | |
Tejun Heo | 887125e | 2008-03-25 12:22:49 +0900 | [diff] [blame] | 865 | ppi[0] = chipset->info; |
Jeff Garzik | 669a5db | 2006-08-29 18:12:40 -0400 | [diff] [blame] | 866 | |
| 867 | sis_fixup(pdev, chipset); |
| 868 | |
Tejun Heo | 1c5afdf | 2010-05-19 22:10:22 +0200 | [diff] [blame] | 869 | return ata_pci_bmdma_init_one(pdev, ppi, &sis_sht, chipset, 0); |
Jeff Garzik | 669a5db | 2006-08-29 18:12:40 -0400 | [diff] [blame] | 870 | } |
| 871 | |
Bartlomiej Zolnierkiewicz | 58eb8cd | 2014-05-07 17:17:44 +0200 | [diff] [blame] | 872 | #ifdef CONFIG_PM_SLEEP |
Bartlomiej Zolnierkiewicz | 750c713 | 2009-12-03 20:32:13 +0100 | [diff] [blame] | 873 | static int sis_reinit_one(struct pci_dev *pdev) |
| 874 | { |
Jingoo Han | 0a86e1c | 2013-06-03 14:05:36 +0900 | [diff] [blame] | 875 | struct ata_host *host = pci_get_drvdata(pdev); |
Bartlomiej Zolnierkiewicz | 750c713 | 2009-12-03 20:32:13 +0100 | [diff] [blame] | 876 | int rc; |
| 877 | |
| 878 | rc = ata_pci_device_do_resume(pdev); |
| 879 | if (rc) |
| 880 | return rc; |
| 881 | |
| 882 | sis_fixup(pdev, host->private_data); |
| 883 | |
| 884 | ata_host_resume(host); |
| 885 | return 0; |
| 886 | } |
| 887 | #endif |
| 888 | |
Jeff Garzik | 669a5db | 2006-08-29 18:12:40 -0400 | [diff] [blame] | 889 | static const struct pci_device_id sis_pci_tbl[] = { |
Jeff Garzik | 2d2744f | 2006-09-28 20:21:59 -0400 | [diff] [blame] | 890 | { PCI_VDEVICE(SI, 0x5513), }, /* SiS 5513 */ |
| 891 | { PCI_VDEVICE(SI, 0x5518), }, /* SiS 5518 */ |
Uwe Koziolek | a3cabb2 | 2007-06-14 23:40:43 +0200 | [diff] [blame] | 892 | { PCI_VDEVICE(SI, 0x1180), }, /* SiS 1180 */ |
Jeff Garzik | 2d2744f | 2006-09-28 20:21:59 -0400 | [diff] [blame] | 893 | |
Jeff Garzik | 669a5db | 2006-08-29 18:12:40 -0400 | [diff] [blame] | 894 | { } |
| 895 | }; |
| 896 | |
| 897 | static struct pci_driver sis_pci_driver = { |
| 898 | .name = DRV_NAME, |
| 899 | .id_table = sis_pci_tbl, |
| 900 | .probe = sis_init_one, |
| 901 | .remove = ata_pci_remove_one, |
Bartlomiej Zolnierkiewicz | 58eb8cd | 2014-05-07 17:17:44 +0200 | [diff] [blame] | 902 | #ifdef CONFIG_PM_SLEEP |
Alan | 62d64ae | 2006-11-27 16:27:20 +0000 | [diff] [blame] | 903 | .suspend = ata_pci_device_suspend, |
Bartlomiej Zolnierkiewicz | 750c713 | 2009-12-03 20:32:13 +0100 | [diff] [blame] | 904 | .resume = sis_reinit_one, |
Tejun Heo | 438ac6d | 2007-03-02 17:31:26 +0900 | [diff] [blame] | 905 | #endif |
Jeff Garzik | 669a5db | 2006-08-29 18:12:40 -0400 | [diff] [blame] | 906 | }; |
| 907 | |
Axel Lin | 2fc75da | 2012-04-19 13:43:05 +0800 | [diff] [blame] | 908 | module_pci_driver(sis_pci_driver); |
Jeff Garzik | 669a5db | 2006-08-29 18:12:40 -0400 | [diff] [blame] | 909 | |
| 910 | MODULE_AUTHOR("Alan Cox"); |
| 911 | MODULE_DESCRIPTION("SCSI low-level driver for SiS ATA"); |
| 912 | MODULE_LICENSE("GPL"); |
| 913 | MODULE_DEVICE_TABLE(pci, sis_pci_tbl); |
| 914 | MODULE_VERSION(DRV_VERSION); |