Jeff Garzik | 669a5db | 2006-08-29 18:12:40 -0400 | [diff] [blame] | 1 | /* |
| 2 | * pata_via.c - VIA PATA for new ATA layer |
| 3 | * (C) 2005-2006 Red Hat Inc |
Jeff Garzik | 669a5db | 2006-08-29 18:12:40 -0400 | [diff] [blame] | 4 | * |
| 5 | * Documentation |
| 6 | * Most chipset documentation available under NDA only |
| 7 | * |
| 8 | * VIA version guide |
| 9 | * VIA VT82C561 - early design, uses ata_generic currently |
| 10 | * VIA VT82C576 - MWDMA, 33Mhz |
| 11 | * VIA VT82C586 - MWDMA, 33Mhz |
| 12 | * VIA VT82C586a - Added UDMA to 33Mhz |
| 13 | * VIA VT82C586b - UDMA33 |
| 14 | * VIA VT82C596a - Nonfunctional UDMA66 |
| 15 | * VIA VT82C596b - Working UDMA66 |
| 16 | * VIA VT82C686 - Nonfunctional UDMA66 |
| 17 | * VIA VT82C686a - Working UDMA66 |
| 18 | * VIA VT82C686b - Updated to UDMA100 |
| 19 | * VIA VT8231 - UDMA100 |
| 20 | * VIA VT8233 - UDMA100 |
| 21 | * VIA VT8233a - UDMA133 |
| 22 | * VIA VT8233c - UDMA100 |
| 23 | * VIA VT8235 - UDMA133 |
| 24 | * VIA VT8237 - UDMA133 |
Bartlomiej Zolnierkiewicz | 460f531 | 2010-01-18 18:17:12 +0100 | [diff] [blame] | 25 | * VIA VT8237A - UDMA133 |
Alan | 05c39e5 | 2007-01-31 17:14:38 +0000 | [diff] [blame] | 26 | * VIA VT8237S - UDMA133 |
Alan | 75f609d | 2006-12-04 16:38:25 +0000 | [diff] [blame] | 27 | * VIA VT8251 - UDMA133 |
Jeff Garzik | 669a5db | 2006-08-29 18:12:40 -0400 | [diff] [blame] | 28 | * |
| 29 | * Most registers remain compatible across chips. Others start reserved |
| 30 | * and acquire sensible semantics if set to 1 (eg cable detect). A few |
| 31 | * exceptions exist, notably around the FIFO settings. |
| 32 | * |
| 33 | * One additional quirk of the VIA design is that like ALi they use few |
| 34 | * PCI IDs for a lot of chips. |
| 35 | * |
| 36 | * Based heavily on: |
| 37 | * |
| 38 | * Version 3.38 |
| 39 | * |
| 40 | * VIA IDE driver for Linux. Supported southbridges: |
| 41 | * |
| 42 | * vt82c576, vt82c586, vt82c586a, vt82c586b, vt82c596a, vt82c596b, |
| 43 | * vt82c686, vt82c686a, vt82c686b, vt8231, vt8233, vt8233c, vt8233a, |
| 44 | * vt8235, vt8237 |
| 45 | * |
| 46 | * Copyright (c) 2000-2002 Vojtech Pavlik |
| 47 | * |
| 48 | * Based on the work of: |
| 49 | * Michel Aubry |
| 50 | * Jeff Garzik |
| 51 | * Andre Hedrick |
| 52 | |
| 53 | */ |
| 54 | |
| 55 | #include <linux/kernel.h> |
| 56 | #include <linux/module.h> |
| 57 | #include <linux/pci.h> |
| 58 | #include <linux/init.h> |
| 59 | #include <linux/blkdev.h> |
| 60 | #include <linux/delay.h> |
Tejun Heo | 5a0e3ad | 2010-03-24 17:04:11 +0900 | [diff] [blame] | 61 | #include <linux/gfp.h> |
Jeff Garzik | 669a5db | 2006-08-29 18:12:40 -0400 | [diff] [blame] | 62 | #include <scsi/scsi_host.h> |
| 63 | #include <linux/libata.h> |
Alan Cox | cf5792d | 2007-05-23 22:39:01 +0100 | [diff] [blame] | 64 | #include <linux/dmi.h> |
Jeff Garzik | 669a5db | 2006-08-29 18:12:40 -0400 | [diff] [blame] | 65 | |
| 66 | #define DRV_NAME "pata_via" |
Alan Cox | b4746ed | 2009-04-17 12:21:21 +0100 | [diff] [blame] | 67 | #define DRV_VERSION "0.3.4" |
Jeff Garzik | 669a5db | 2006-08-29 18:12:40 -0400 | [diff] [blame] | 68 | |
Jeff Garzik | 669a5db | 2006-08-29 18:12:40 -0400 | [diff] [blame] | 69 | enum { |
Bartlomiej Zolnierkiewicz | 460f531 | 2010-01-18 18:17:12 +0100 | [diff] [blame] | 70 | VIA_BAD_PREQ = 0x01, /* Crashes if PREQ# till DDACK# set */ |
| 71 | VIA_BAD_CLK66 = 0x02, /* 66 MHz clock doesn't work correctly */ |
| 72 | VIA_SET_FIFO = 0x04, /* Needs to have FIFO split set */ |
| 73 | VIA_NO_UNMASK = 0x08, /* Doesn't work with IRQ unmasking on */ |
| 74 | VIA_BAD_ID = 0x10, /* Has wrong vendor ID (0x1107) */ |
| 75 | VIA_BAD_AST = 0x20, /* Don't touch Address Setup Timing */ |
| 76 | VIA_NO_ENABLES = 0x40, /* Has no enablebits */ |
| 77 | VIA_SATA_PATA = 0x80, /* SATA/PATA combined configuration */ |
Jeff Garzik | 669a5db | 2006-08-29 18:12:40 -0400 | [diff] [blame] | 78 | }; |
| 79 | |
JosephChan@via.com.tw | e4d866c | 2009-01-23 15:37:39 +0800 | [diff] [blame] | 80 | enum { |
| 81 | VIA_IDFLAG_SINGLE = (1 << 0), /* single channel controller) */ |
| 82 | }; |
| 83 | |
Jeff Garzik | 669a5db | 2006-08-29 18:12:40 -0400 | [diff] [blame] | 84 | /* |
| 85 | * VIA SouthBridge chips. |
| 86 | */ |
| 87 | |
| 88 | static const struct via_isa_bridge { |
| 89 | const char *name; |
| 90 | u16 id; |
| 91 | u8 rev_min; |
| 92 | u8 rev_max; |
Bartlomiej Zolnierkiewicz | 460f531 | 2010-01-18 18:17:12 +0100 | [diff] [blame] | 93 | u8 udma_mask; |
| 94 | u8 flags; |
Jeff Garzik | 669a5db | 2006-08-29 18:12:40 -0400 | [diff] [blame] | 95 | } via_isa_bridges[] = { |
Bartlomiej Zolnierkiewicz | 460f531 | 2010-01-18 18:17:12 +0100 | [diff] [blame] | 96 | { "vx855", PCI_DEVICE_ID_VIA_VX855, 0x00, 0x2f, ATA_UDMA6, VIA_BAD_AST | VIA_SATA_PATA }, |
| 97 | { "vx800", PCI_DEVICE_ID_VIA_VX800, 0x00, 0x2f, ATA_UDMA6, VIA_BAD_AST | VIA_SATA_PATA }, |
| 98 | { "vt8261", PCI_DEVICE_ID_VIA_8261, 0x00, 0x2f, ATA_UDMA6, VIA_BAD_AST }, |
| 99 | { "vt8237s", PCI_DEVICE_ID_VIA_8237S, 0x00, 0x2f, ATA_UDMA6, VIA_BAD_AST }, |
| 100 | { "vt8251", PCI_DEVICE_ID_VIA_8251, 0x00, 0x2f, ATA_UDMA6, VIA_BAD_AST }, |
| 101 | { "cx700", PCI_DEVICE_ID_VIA_CX700, 0x00, 0x2f, ATA_UDMA6, VIA_BAD_AST | VIA_SATA_PATA }, |
| 102 | { "vt6410", PCI_DEVICE_ID_VIA_6410, 0x00, 0x2f, ATA_UDMA6, VIA_BAD_AST | VIA_NO_ENABLES }, |
| 103 | { "vt6415", PCI_DEVICE_ID_VIA_6415, 0x00, 0xff, ATA_UDMA6, VIA_BAD_AST | VIA_NO_ENABLES }, |
| 104 | { "vt8237a", PCI_DEVICE_ID_VIA_8237A, 0x00, 0x2f, ATA_UDMA6, VIA_BAD_AST }, |
| 105 | { "vt8237", PCI_DEVICE_ID_VIA_8237, 0x00, 0x2f, ATA_UDMA6, VIA_BAD_AST }, |
| 106 | { "vt8235", PCI_DEVICE_ID_VIA_8235, 0x00, 0x2f, ATA_UDMA6, VIA_BAD_AST }, |
| 107 | { "vt8233a", PCI_DEVICE_ID_VIA_8233A, 0x00, 0x2f, ATA_UDMA6, VIA_BAD_AST }, |
| 108 | { "vt8233c", PCI_DEVICE_ID_VIA_8233C_0, 0x00, 0x2f, ATA_UDMA5, }, |
| 109 | { "vt8233", PCI_DEVICE_ID_VIA_8233_0, 0x00, 0x2f, ATA_UDMA5, }, |
| 110 | { "vt8231", PCI_DEVICE_ID_VIA_8231, 0x00, 0x2f, ATA_UDMA5, }, |
| 111 | { "vt82c686b", PCI_DEVICE_ID_VIA_82C686, 0x40, 0x4f, ATA_UDMA5, }, |
| 112 | { "vt82c686a", PCI_DEVICE_ID_VIA_82C686, 0x10, 0x2f, ATA_UDMA4, }, |
| 113 | { "vt82c686", PCI_DEVICE_ID_VIA_82C686, 0x00, 0x0f, ATA_UDMA2, VIA_BAD_CLK66 }, |
| 114 | { "vt82c596b", PCI_DEVICE_ID_VIA_82C596, 0x10, 0x2f, ATA_UDMA4, }, |
| 115 | { "vt82c596a", PCI_DEVICE_ID_VIA_82C596, 0x00, 0x0f, ATA_UDMA2, VIA_BAD_CLK66 }, |
| 116 | { "vt82c586b", PCI_DEVICE_ID_VIA_82C586_0, 0x47, 0x4f, ATA_UDMA2, VIA_SET_FIFO }, |
| 117 | { "vt82c586b", PCI_DEVICE_ID_VIA_82C586_0, 0x40, 0x46, ATA_UDMA2, VIA_SET_FIFO | VIA_BAD_PREQ }, |
| 118 | { "vt82c586b", PCI_DEVICE_ID_VIA_82C586_0, 0x30, 0x3f, ATA_UDMA2, VIA_SET_FIFO }, |
| 119 | { "vt82c586a", PCI_DEVICE_ID_VIA_82C586_0, 0x20, 0x2f, ATA_UDMA2, VIA_SET_FIFO }, |
| 120 | { "vt82c586", PCI_DEVICE_ID_VIA_82C586_0, 0x00, 0x0f, 0x00, VIA_SET_FIFO }, |
| 121 | { "vt82c576", PCI_DEVICE_ID_VIA_82C576, 0x00, 0x2f, 0x00, VIA_SET_FIFO | VIA_NO_UNMASK }, |
| 122 | { "vt82c576", PCI_DEVICE_ID_VIA_82C576, 0x00, 0x2f, 0x00, VIA_SET_FIFO | VIA_NO_UNMASK | VIA_BAD_ID }, |
| 123 | { "vtxxxx", PCI_DEVICE_ID_VIA_ANON, 0x00, 0x2f, ATA_UDMA6, VIA_BAD_AST }, |
Jeff Garzik | 669a5db | 2006-08-29 18:12:40 -0400 | [diff] [blame] | 124 | { NULL } |
| 125 | }; |
| 126 | |
Tejun Heo | 6d0e194 | 2011-08-04 11:15:07 +0200 | [diff] [blame] | 127 | static const struct dmi_system_id no_atapi_dma_dmi_table[] = { |
| 128 | { |
| 129 | .ident = "AVERATEC 3200", |
| 130 | .matches = { |
| 131 | DMI_MATCH(DMI_BOARD_VENDOR, "AVERATEC"), |
| 132 | DMI_MATCH(DMI_BOARD_NAME, "3200"), |
| 133 | }, |
| 134 | }, |
| 135 | { } |
| 136 | }; |
| 137 | |
Alan Cox | b4746ed | 2009-04-17 12:21:21 +0100 | [diff] [blame] | 138 | struct via_port { |
| 139 | u8 cached_device; |
| 140 | }; |
Alan Cox | cf5792d | 2007-05-23 22:39:01 +0100 | [diff] [blame] | 141 | |
| 142 | /* |
| 143 | * Cable special cases |
| 144 | */ |
| 145 | |
Jeff Garzik | 1855256 | 2007-10-03 15:15:40 -0400 | [diff] [blame] | 146 | static const struct dmi_system_id cable_dmi_table[] = { |
Alan Cox | cf5792d | 2007-05-23 22:39:01 +0100 | [diff] [blame] | 147 | { |
| 148 | .ident = "Acer Ferrari 3400", |
| 149 | .matches = { |
| 150 | DMI_MATCH(DMI_BOARD_VENDOR, "Acer,Inc."), |
| 151 | DMI_MATCH(DMI_BOARD_NAME, "Ferrari 3400"), |
| 152 | }, |
| 153 | }, |
| 154 | { } |
| 155 | }; |
| 156 | |
| 157 | static int via_cable_override(struct pci_dev *pdev) |
| 158 | { |
| 159 | /* Systems by DMI */ |
| 160 | if (dmi_check_system(cable_dmi_table)) |
| 161 | return 1; |
Alan Cox | 9edbdbe | 2007-08-22 22:57:48 +0100 | [diff] [blame] | 162 | /* Arima W730-K8/Targa Visionary 811/... */ |
| 163 | if (pdev->subsystem_vendor == 0x161F && pdev->subsystem_device == 0x2032) |
| 164 | return 1; |
Alan Cox | cf5792d | 2007-05-23 22:39:01 +0100 | [diff] [blame] | 165 | return 0; |
| 166 | } |
| 167 | |
| 168 | |
Jeff Garzik | 669a5db | 2006-08-29 18:12:40 -0400 | [diff] [blame] | 169 | /** |
| 170 | * via_cable_detect - cable detection |
| 171 | * @ap: ATA port |
| 172 | * |
| 173 | * Perform cable detection. Actually for the VIA case the BIOS |
| 174 | * already did this for us. We read the values provided by the |
| 175 | * BIOS. If you are using an 8235 in a non-PC configuration you |
| 176 | * may need to update this code. |
| 177 | * |
| 178 | * Hotplug also impacts on this. |
| 179 | */ |
| 180 | |
| 181 | static int via_cable_detect(struct ata_port *ap) { |
Alan Cox | 97cb81c | 2007-03-07 16:56:54 +0000 | [diff] [blame] | 182 | const struct via_isa_bridge *config = ap->host->private_data; |
Jeff Garzik | 669a5db | 2006-08-29 18:12:40 -0400 | [diff] [blame] | 183 | struct pci_dev *pdev = to_pci_dev(ap->host->dev); |
| 184 | u32 ata66; |
| 185 | |
Alan Cox | cf5792d | 2007-05-23 22:39:01 +0100 | [diff] [blame] | 186 | if (via_cable_override(pdev)) |
| 187 | return ATA_CBL_PATA40_SHORT; |
| 188 | |
Tejun Heo | 7585eb1 | 2008-02-07 10:18:53 +0900 | [diff] [blame] | 189 | if ((config->flags & VIA_SATA_PATA) && ap->port_no == 0) |
| 190 | return ATA_CBL_SATA; |
| 191 | |
Alan Cox | 97cb81c | 2007-03-07 16:56:54 +0000 | [diff] [blame] | 192 | /* Early chips are 40 wire */ |
Bartlomiej Zolnierkiewicz | 460f531 | 2010-01-18 18:17:12 +0100 | [diff] [blame] | 193 | if (config->udma_mask < ATA_UDMA4) |
Alan Cox | 97cb81c | 2007-03-07 16:56:54 +0000 | [diff] [blame] | 194 | return ATA_CBL_PATA40; |
| 195 | /* UDMA 66 chips have only drive side logic */ |
Bartlomiej Zolnierkiewicz | 460f531 | 2010-01-18 18:17:12 +0100 | [diff] [blame] | 196 | else if (config->udma_mask < ATA_UDMA5) |
Alan Cox | 97cb81c | 2007-03-07 16:56:54 +0000 | [diff] [blame] | 197 | return ATA_CBL_PATA_UNK; |
| 198 | /* UDMA 100 or later */ |
Jeff Garzik | 669a5db | 2006-08-29 18:12:40 -0400 | [diff] [blame] | 199 | pci_read_config_dword(pdev, 0x50, &ata66); |
| 200 | /* Check both the drive cable reporting bits, we might not have |
| 201 | two drives */ |
| 202 | if (ata66 & (0x10100000 >> (16 * ap->port_no))) |
| 203 | return ATA_CBL_PATA80; |
Alan Cox | 7d73a36 | 2007-07-26 18:38:06 +0100 | [diff] [blame] | 204 | /* Check with ACPI so we can spot BIOS reported SATA bridges */ |
Tejun Heo | 021ee9a | 2007-12-18 16:33:06 +0900 | [diff] [blame] | 205 | if (ata_acpi_init_gtm(ap) && |
| 206 | ata_acpi_cbl_80wire(ap, ata_acpi_init_gtm(ap))) |
Alan Cox | 7d73a36 | 2007-07-26 18:38:06 +0100 | [diff] [blame] | 207 | return ATA_CBL_PATA80; |
Alan Cox | 97cb81c | 2007-03-07 16:56:54 +0000 | [diff] [blame] | 208 | return ATA_CBL_PATA40; |
Jeff Garzik | 669a5db | 2006-08-29 18:12:40 -0400 | [diff] [blame] | 209 | } |
| 210 | |
Tejun Heo | cc0680a | 2007-08-06 18:36:23 +0900 | [diff] [blame] | 211 | static int via_pre_reset(struct ata_link *link, unsigned long deadline) |
Jeff Garzik | 669a5db | 2006-08-29 18:12:40 -0400 | [diff] [blame] | 212 | { |
Tejun Heo | cc0680a | 2007-08-06 18:36:23 +0900 | [diff] [blame] | 213 | struct ata_port *ap = link->ap; |
Jeff Garzik | 669a5db | 2006-08-29 18:12:40 -0400 | [diff] [blame] | 214 | const struct via_isa_bridge *config = ap->host->private_data; |
| 215 | |
| 216 | if (!(config->flags & VIA_NO_ENABLES)) { |
| 217 | static const struct pci_bits via_enable_bits[] = { |
| 218 | { 0x40, 1, 0x02, 0x02 }, |
| 219 | { 0x40, 1, 0x01, 0x01 } |
| 220 | }; |
Jeff Garzik | 669a5db | 2006-08-29 18:12:40 -0400 | [diff] [blame] | 221 | struct pci_dev *pdev = to_pci_dev(ap->host->dev); |
Alan Cox | c961922 | 2006-09-26 17:53:38 +0100 | [diff] [blame] | 222 | if (!pci_test_config_bits(pdev, &via_enable_bits[ap->port_no])) |
| 223 | return -ENOENT; |
Jeff Garzik | 669a5db | 2006-08-29 18:12:40 -0400 | [diff] [blame] | 224 | } |
Tejun Heo | d4b2bab | 2007-02-02 16:50:52 +0900 | [diff] [blame] | 225 | |
Tejun Heo | 9363c38 | 2008-04-07 22:47:16 +0900 | [diff] [blame] | 226 | return ata_sff_prereset(link, deadline); |
Jeff Garzik | 669a5db | 2006-08-29 18:12:40 -0400 | [diff] [blame] | 227 | } |
| 228 | |
| 229 | |
| 230 | /** |
Bartlomiej Zolnierkiewicz | f777582 | 2010-01-18 18:17:03 +0100 | [diff] [blame] | 231 | * via_do_set_mode - set transfer mode data |
Jeff Garzik | 669a5db | 2006-08-29 18:12:40 -0400 | [diff] [blame] | 232 | * @ap: ATA interface |
| 233 | * @adev: ATA device |
| 234 | * @mode: ATA mode being programmed |
Jeff Garzik | 669a5db | 2006-08-29 18:12:40 -0400 | [diff] [blame] | 235 | * @set_ast: Set to program address setup |
| 236 | * @udma_type: UDMA mode/format of registers |
| 237 | * |
| 238 | * Program the VIA registers for DMA and PIO modes. Uses the ata timing |
| 239 | * support in order to compute modes. |
| 240 | * |
| 241 | * FIXME: Hotplug will require we serialize multiple mode changes |
| 242 | * on the two channels. |
| 243 | */ |
| 244 | |
Bartlomiej Zolnierkiewicz | 460f531 | 2010-01-18 18:17:12 +0100 | [diff] [blame] | 245 | static void via_do_set_mode(struct ata_port *ap, struct ata_device *adev, |
| 246 | int mode, int set_ast, int udma_type) |
Jeff Garzik | 669a5db | 2006-08-29 18:12:40 -0400 | [diff] [blame] | 247 | { |
| 248 | struct pci_dev *pdev = to_pci_dev(ap->host->dev); |
| 249 | struct ata_device *peer = ata_dev_pair(adev); |
| 250 | struct ata_timing t, p; |
Bartlomiej Zolnierkiewicz | 460f531 | 2010-01-18 18:17:12 +0100 | [diff] [blame] | 251 | static int via_clock = 33333; /* Bus clock in kHZ */ |
Jeff Garzik | 669a5db | 2006-08-29 18:12:40 -0400 | [diff] [blame] | 252 | unsigned long T = 1000000000 / via_clock; |
Bartlomiej Zolnierkiewicz | 460f531 | 2010-01-18 18:17:12 +0100 | [diff] [blame] | 253 | unsigned long UT = T; |
Jeff Garzik | 669a5db | 2006-08-29 18:12:40 -0400 | [diff] [blame] | 254 | int ut; |
| 255 | int offset = 3 - (2*ap->port_no) - adev->devno; |
| 256 | |
Bartlomiej Zolnierkiewicz | 460f531 | 2010-01-18 18:17:12 +0100 | [diff] [blame] | 257 | switch (udma_type) { |
| 258 | case ATA_UDMA4: |
| 259 | UT = T / 2; break; |
| 260 | case ATA_UDMA5: |
| 261 | UT = T / 3; break; |
| 262 | case ATA_UDMA6: |
| 263 | UT = T / 4; break; |
| 264 | } |
| 265 | |
Jeff Garzik | 669a5db | 2006-08-29 18:12:40 -0400 | [diff] [blame] | 266 | /* Calculate the timing values we require */ |
| 267 | ata_timing_compute(adev, mode, &t, T, UT); |
| 268 | |
| 269 | /* We share 8bit timing so we must merge the constraints */ |
| 270 | if (peer) { |
| 271 | if (peer->pio_mode) { |
| 272 | ata_timing_compute(peer, peer->pio_mode, &p, T, UT); |
| 273 | ata_timing_merge(&p, &t, &t, ATA_TIMING_8BIT); |
| 274 | } |
| 275 | } |
| 276 | |
| 277 | /* Address setup is programmable but breaks on UDMA133 setups */ |
| 278 | if (set_ast) { |
| 279 | u8 setup; /* 2 bits per drive */ |
| 280 | int shift = 2 * offset; |
| 281 | |
| 282 | pci_read_config_byte(pdev, 0x4C, &setup); |
| 283 | setup &= ~(3 << shift); |
Bartlomiej Zolnierkiewicz | f777582 | 2010-01-18 18:17:03 +0100 | [diff] [blame] | 284 | setup |= (clamp_val(t.setup, 1, 4) - 1) << shift; |
Jeff Garzik | 669a5db | 2006-08-29 18:12:40 -0400 | [diff] [blame] | 285 | pci_write_config_byte(pdev, 0x4C, setup); |
| 286 | } |
| 287 | |
| 288 | /* Load the PIO mode bits */ |
| 289 | pci_write_config_byte(pdev, 0x4F - ap->port_no, |
Harvey Harrison | 07633b5 | 2008-05-14 16:17:00 -0700 | [diff] [blame] | 290 | ((clamp_val(t.act8b, 1, 16) - 1) << 4) | (clamp_val(t.rec8b, 1, 16) - 1)); |
Jeff Garzik | 669a5db | 2006-08-29 18:12:40 -0400 | [diff] [blame] | 291 | pci_write_config_byte(pdev, 0x48 + offset, |
Harvey Harrison | 07633b5 | 2008-05-14 16:17:00 -0700 | [diff] [blame] | 292 | ((clamp_val(t.active, 1, 16) - 1) << 4) | (clamp_val(t.recover, 1, 16) - 1)); |
Jeff Garzik | 669a5db | 2006-08-29 18:12:40 -0400 | [diff] [blame] | 293 | |
| 294 | /* Load the UDMA bits according to type */ |
Bartlomiej Zolnierkiewicz | 460f531 | 2010-01-18 18:17:12 +0100 | [diff] [blame] | 295 | switch (udma_type) { |
| 296 | case ATA_UDMA2: |
| 297 | default: |
| 298 | ut = t.udma ? (0xe0 | (clamp_val(t.udma, 2, 5) - 2)) : 0x03; |
| 299 | break; |
| 300 | case ATA_UDMA4: |
| 301 | ut = t.udma ? (0xe8 | (clamp_val(t.udma, 2, 9) - 2)) : 0x0f; |
| 302 | break; |
| 303 | case ATA_UDMA5: |
| 304 | ut = t.udma ? (0xe0 | (clamp_val(t.udma, 2, 9) - 2)) : 0x07; |
| 305 | break; |
| 306 | case ATA_UDMA6: |
| 307 | ut = t.udma ? (0xe0 | (clamp_val(t.udma, 2, 9) - 2)) : 0x07; |
| 308 | break; |
Jeff Garzik | 669a5db | 2006-08-29 18:12:40 -0400 | [diff] [blame] | 309 | } |
Laurent Riffard | 08ebd43 | 2007-09-02 21:01:32 +0200 | [diff] [blame] | 310 | |
Jeff Garzik | 669a5db | 2006-08-29 18:12:40 -0400 | [diff] [blame] | 311 | /* Set UDMA unless device is not UDMA capable */ |
Bartlomiej Zolnierkiewicz | c4d8a20 | 2009-12-03 20:32:13 +0100 | [diff] [blame] | 312 | if (udma_type) { |
| 313 | u8 udma_etc; |
Laurent Riffard | 08ebd43 | 2007-09-02 21:01:32 +0200 | [diff] [blame] | 314 | |
Bartlomiej Zolnierkiewicz | c4d8a20 | 2009-12-03 20:32:13 +0100 | [diff] [blame] | 315 | pci_read_config_byte(pdev, 0x50 + offset, &udma_etc); |
Laurent Riffard | 08ebd43 | 2007-09-02 21:01:32 +0200 | [diff] [blame] | 316 | |
Bartlomiej Zolnierkiewicz | c4d8a20 | 2009-12-03 20:32:13 +0100 | [diff] [blame] | 317 | /* clear transfer mode bit */ |
| 318 | udma_etc &= ~0x20; |
| 319 | |
| 320 | if (t.udma) { |
| 321 | /* preserve 80-wire cable detection bit */ |
| 322 | udma_etc &= 0x10; |
| 323 | udma_etc |= ut; |
| 324 | } |
| 325 | |
| 326 | pci_write_config_byte(pdev, 0x50 + offset, udma_etc); |
Laurent Riffard | 08ebd43 | 2007-09-02 21:01:32 +0200 | [diff] [blame] | 327 | } |
Jeff Garzik | 669a5db | 2006-08-29 18:12:40 -0400 | [diff] [blame] | 328 | } |
| 329 | |
| 330 | static void via_set_piomode(struct ata_port *ap, struct ata_device *adev) |
| 331 | { |
| 332 | const struct via_isa_bridge *config = ap->host->private_data; |
| 333 | int set_ast = (config->flags & VIA_BAD_AST) ? 0 : 1; |
Jeff Garzik | 669a5db | 2006-08-29 18:12:40 -0400 | [diff] [blame] | 334 | |
Bartlomiej Zolnierkiewicz | 460f531 | 2010-01-18 18:17:12 +0100 | [diff] [blame] | 335 | via_do_set_mode(ap, adev, adev->pio_mode, set_ast, config->udma_mask); |
Jeff Garzik | 669a5db | 2006-08-29 18:12:40 -0400 | [diff] [blame] | 336 | } |
| 337 | |
| 338 | static void via_set_dmamode(struct ata_port *ap, struct ata_device *adev) |
| 339 | { |
| 340 | const struct via_isa_bridge *config = ap->host->private_data; |
| 341 | int set_ast = (config->flags & VIA_BAD_AST) ? 0 : 1; |
Jeff Garzik | 669a5db | 2006-08-29 18:12:40 -0400 | [diff] [blame] | 342 | |
Bartlomiej Zolnierkiewicz | 460f531 | 2010-01-18 18:17:12 +0100 | [diff] [blame] | 343 | via_do_set_mode(ap, adev, adev->dma_mode, set_ast, config->udma_mask); |
Jeff Garzik | 669a5db | 2006-08-29 18:12:40 -0400 | [diff] [blame] | 344 | } |
| 345 | |
JosephChan@via.com.tw | bfce5e0 | 2008-07-30 12:32:48 -0700 | [diff] [blame] | 346 | /** |
Alan Cox | 10734fc | 2009-11-30 13:22:43 +0000 | [diff] [blame] | 347 | * via_mode_filter - filter buggy device/mode pairs |
| 348 | * @dev: ATA device |
| 349 | * @mask: Mode bitmask |
| 350 | * |
| 351 | * We need to apply some minimal filtering for old controllers and at least |
| 352 | * one breed of Transcend SSD. Return the updated mask. |
| 353 | */ |
| 354 | |
| 355 | static unsigned long via_mode_filter(struct ata_device *dev, unsigned long mask) |
| 356 | { |
| 357 | struct ata_host *host = dev->link->ap->host; |
| 358 | const struct via_isa_bridge *config = host->private_data; |
| 359 | unsigned char model_num[ATA_ID_PROD_LEN + 1]; |
| 360 | |
| 361 | if (config->id == PCI_DEVICE_ID_VIA_82C586_0) { |
| 362 | ata_id_c_string(dev->id, model_num, ATA_ID_PROD, sizeof(model_num)); |
| 363 | if (strcmp(model_num, "TS64GSSD25-M") == 0) { |
Joe Perches | a9a79df | 2011-04-15 15:51:59 -0700 | [diff] [blame] | 364 | ata_dev_warn(dev, |
| 365 | "disabling UDMA mode due to reported lockups with this device\n"); |
Alan Cox | 10734fc | 2009-11-30 13:22:43 +0000 | [diff] [blame] | 366 | mask &= ~ ATA_MASK_UDMA; |
| 367 | } |
| 368 | } |
Tejun Heo | 6d0e194 | 2011-08-04 11:15:07 +0200 | [diff] [blame] | 369 | |
| 370 | if (dev->class == ATA_DEV_ATAPI && |
| 371 | dmi_check_system(no_atapi_dma_dmi_table)) { |
| 372 | ata_dev_warn(dev, "controller locks up on ATAPI DMA, forcing PIO\n"); |
| 373 | mask &= ATA_MASK_PIO; |
| 374 | } |
| 375 | |
Tejun Heo | c708765 | 2010-05-10 21:41:34 +0200 | [diff] [blame] | 376 | return mask; |
Alan Cox | 10734fc | 2009-11-30 13:22:43 +0000 | [diff] [blame] | 377 | } |
| 378 | |
| 379 | /** |
Tejun Heo | ff04715 | 2008-07-31 18:02:35 +0900 | [diff] [blame] | 380 | * via_tf_load - send taskfile registers to host controller |
JosephChan@via.com.tw | bfce5e0 | 2008-07-30 12:32:48 -0700 | [diff] [blame] | 381 | * @ap: Port to which output is sent |
| 382 | * @tf: ATA taskfile register set |
| 383 | * |
| 384 | * Outputs ATA taskfile to standard ATA host controller. |
| 385 | * |
| 386 | * Note: This is to fix the internal bug of via chipsets, which |
Tejun Heo | ff04715 | 2008-07-31 18:02:35 +0900 | [diff] [blame] | 387 | * will reset the device register after changing the IEN bit on |
| 388 | * ctl register |
JosephChan@via.com.tw | bfce5e0 | 2008-07-30 12:32:48 -0700 | [diff] [blame] | 389 | */ |
Tejun Heo | ff04715 | 2008-07-31 18:02:35 +0900 | [diff] [blame] | 390 | static void via_tf_load(struct ata_port *ap, const struct ata_taskfile *tf) |
JosephChan@via.com.tw | bfce5e0 | 2008-07-30 12:32:48 -0700 | [diff] [blame] | 391 | { |
Alan Cox | b4746ed | 2009-04-17 12:21:21 +0100 | [diff] [blame] | 392 | struct ata_ioports *ioaddr = &ap->ioaddr; |
| 393 | struct via_port *vp = ap->private_data; |
| 394 | unsigned int is_addr = tf->flags & ATA_TFLAG_ISADDR; |
| 395 | int newctl = 0; |
JosephChan@via.com.tw | bfce5e0 | 2008-07-30 12:32:48 -0700 | [diff] [blame] | 396 | |
Alan Cox | b4746ed | 2009-04-17 12:21:21 +0100 | [diff] [blame] | 397 | if (tf->ctl != ap->last_ctl) { |
| 398 | iowrite8(tf->ctl, ioaddr->ctl_addr); |
| 399 | ap->last_ctl = tf->ctl; |
| 400 | ata_wait_idle(ap); |
| 401 | newctl = 1; |
JosephChan@via.com.tw | bfce5e0 | 2008-07-30 12:32:48 -0700 | [diff] [blame] | 402 | } |
Alan Cox | b4746ed | 2009-04-17 12:21:21 +0100 | [diff] [blame] | 403 | |
| 404 | if (tf->flags & ATA_TFLAG_DEVICE) { |
| 405 | iowrite8(tf->device, ioaddr->device_addr); |
| 406 | vp->cached_device = tf->device; |
| 407 | } else if (newctl) |
| 408 | iowrite8(vp->cached_device, ioaddr->device_addr); |
| 409 | |
| 410 | if (is_addr && (tf->flags & ATA_TFLAG_LBA48)) { |
| 411 | WARN_ON_ONCE(!ioaddr->ctl_addr); |
| 412 | iowrite8(tf->hob_feature, ioaddr->feature_addr); |
| 413 | iowrite8(tf->hob_nsect, ioaddr->nsect_addr); |
| 414 | iowrite8(tf->hob_lbal, ioaddr->lbal_addr); |
| 415 | iowrite8(tf->hob_lbam, ioaddr->lbam_addr); |
| 416 | iowrite8(tf->hob_lbah, ioaddr->lbah_addr); |
| 417 | VPRINTK("hob: feat 0x%X nsect 0x%X, lba 0x%X 0x%X 0x%X\n", |
| 418 | tf->hob_feature, |
| 419 | tf->hob_nsect, |
| 420 | tf->hob_lbal, |
| 421 | tf->hob_lbam, |
| 422 | tf->hob_lbah); |
| 423 | } |
| 424 | |
| 425 | if (is_addr) { |
| 426 | iowrite8(tf->feature, ioaddr->feature_addr); |
| 427 | iowrite8(tf->nsect, ioaddr->nsect_addr); |
| 428 | iowrite8(tf->lbal, ioaddr->lbal_addr); |
| 429 | iowrite8(tf->lbam, ioaddr->lbam_addr); |
| 430 | iowrite8(tf->lbah, ioaddr->lbah_addr); |
| 431 | VPRINTK("feat 0x%X nsect 0x%X lba 0x%X 0x%X 0x%X\n", |
| 432 | tf->feature, |
| 433 | tf->nsect, |
| 434 | tf->lbal, |
| 435 | tf->lbam, |
| 436 | tf->lbah); |
| 437 | } |
Tejun Heo | 40c6023 | 2010-09-09 17:13:31 +0200 | [diff] [blame] | 438 | |
| 439 | ata_wait_idle(ap); |
Alan Cox | b4746ed | 2009-04-17 12:21:21 +0100 | [diff] [blame] | 440 | } |
| 441 | |
| 442 | static int via_port_start(struct ata_port *ap) |
| 443 | { |
| 444 | struct via_port *vp; |
| 445 | struct pci_dev *pdev = to_pci_dev(ap->host->dev); |
| 446 | |
Tejun Heo | c708765 | 2010-05-10 21:41:34 +0200 | [diff] [blame] | 447 | int ret = ata_bmdma_port_start(ap); |
Alan Cox | b4746ed | 2009-04-17 12:21:21 +0100 | [diff] [blame] | 448 | if (ret < 0) |
| 449 | return ret; |
| 450 | |
| 451 | vp = devm_kzalloc(&pdev->dev, sizeof(struct via_port), GFP_KERNEL); |
| 452 | if (vp == NULL) |
| 453 | return -ENOMEM; |
| 454 | ap->private_data = vp; |
| 455 | return 0; |
JosephChan@via.com.tw | bfce5e0 | 2008-07-30 12:32:48 -0700 | [diff] [blame] | 456 | } |
| 457 | |
Jeff Garzik | 669a5db | 2006-08-29 18:12:40 -0400 | [diff] [blame] | 458 | static struct scsi_host_template via_sht = { |
Tejun Heo | 68d1d07 | 2008-03-25 12:22:49 +0900 | [diff] [blame] | 459 | ATA_BMDMA_SHT(DRV_NAME), |
Jeff Garzik | 669a5db | 2006-08-29 18:12:40 -0400 | [diff] [blame] | 460 | }; |
| 461 | |
| 462 | static struct ata_port_operations via_port_ops = { |
Tejun Heo | 029cfd6 | 2008-03-25 12:22:49 +0900 | [diff] [blame] | 463 | .inherits = &ata_bmdma_port_ops, |
| 464 | .cable_detect = via_cable_detect, |
Jeff Garzik | 669a5db | 2006-08-29 18:12:40 -0400 | [diff] [blame] | 465 | .set_piomode = via_set_piomode, |
| 466 | .set_dmamode = via_set_dmamode, |
Tejun Heo | a1efdab | 2008-03-25 12:22:50 +0900 | [diff] [blame] | 467 | .prereset = via_pre_reset, |
Tejun Heo | ff04715 | 2008-07-31 18:02:35 +0900 | [diff] [blame] | 468 | .sff_tf_load = via_tf_load, |
Alan Cox | b4746ed | 2009-04-17 12:21:21 +0100 | [diff] [blame] | 469 | .port_start = via_port_start, |
Alan Cox | 10734fc | 2009-11-30 13:22:43 +0000 | [diff] [blame] | 470 | .mode_filter = via_mode_filter, |
Jeff Garzik | 669a5db | 2006-08-29 18:12:40 -0400 | [diff] [blame] | 471 | }; |
| 472 | |
| 473 | static struct ata_port_operations via_port_ops_noirq = { |
Tejun Heo | 029cfd6 | 2008-03-25 12:22:49 +0900 | [diff] [blame] | 474 | .inherits = &via_port_ops, |
Tejun Heo | 5682ed3 | 2008-04-07 22:47:16 +0900 | [diff] [blame] | 475 | .sff_data_xfer = ata_sff_data_xfer_noirq, |
Jeff Garzik | 669a5db | 2006-08-29 18:12:40 -0400 | [diff] [blame] | 476 | }; |
| 477 | |
| 478 | /** |
Alan | 627d2d3 | 2006-11-27 16:19:36 +0000 | [diff] [blame] | 479 | * via_config_fifo - set up the FIFO |
| 480 | * @pdev: PCI device |
| 481 | * @flags: configuration flags |
| 482 | * |
Robert P. J. Day | 3a4fa0a | 2007-10-19 23:10:43 +0200 | [diff] [blame] | 483 | * Set the FIFO properties for this device if necessary. Used both on |
Alan | 627d2d3 | 2006-11-27 16:19:36 +0000 | [diff] [blame] | 484 | * set up and on and the resume path |
| 485 | */ |
| 486 | |
| 487 | static void via_config_fifo(struct pci_dev *pdev, unsigned int flags) |
| 488 | { |
| 489 | u8 enable; |
Jeff Garzik | f20b16f | 2006-12-11 11:14:06 -0500 | [diff] [blame] | 490 | |
Alan | 627d2d3 | 2006-11-27 16:19:36 +0000 | [diff] [blame] | 491 | /* 0x40 low bits indicate enabled channels */ |
| 492 | pci_read_config_byte(pdev, 0x40 , &enable); |
| 493 | enable &= 3; |
Jeff Garzik | f20b16f | 2006-12-11 11:14:06 -0500 | [diff] [blame] | 494 | |
Alan | 627d2d3 | 2006-11-27 16:19:36 +0000 | [diff] [blame] | 495 | if (flags & VIA_SET_FIFO) { |
Andrew Morton | 7372086 | 2006-12-20 13:09:10 -0500 | [diff] [blame] | 496 | static const u8 fifo_setting[4] = {0x00, 0x60, 0x00, 0x20}; |
Alan | 627d2d3 | 2006-11-27 16:19:36 +0000 | [diff] [blame] | 497 | u8 fifo; |
| 498 | |
| 499 | pci_read_config_byte(pdev, 0x43, &fifo); |
| 500 | |
| 501 | /* Clear PREQ# until DDACK# for errata */ |
| 502 | if (flags & VIA_BAD_PREQ) |
| 503 | fifo &= 0x7F; |
| 504 | else |
| 505 | fifo &= 0x9f; |
| 506 | /* Turn on FIFO for enabled channels */ |
| 507 | fifo |= fifo_setting[enable]; |
| 508 | pci_write_config_byte(pdev, 0x43, fifo); |
| 509 | } |
| 510 | } |
| 511 | |
| 512 | /** |
Jeff Garzik | 669a5db | 2006-08-29 18:12:40 -0400 | [diff] [blame] | 513 | * via_init_one - discovery callback |
Alan | 627d2d3 | 2006-11-27 16:19:36 +0000 | [diff] [blame] | 514 | * @pdev: PCI device |
Jeff Garzik | 669a5db | 2006-08-29 18:12:40 -0400 | [diff] [blame] | 515 | * @id: PCI table info |
| 516 | * |
| 517 | * A VIA IDE interface has been discovered. Figure out what revision |
| 518 | * and perform configuration work before handing it to the ATA layer |
| 519 | */ |
| 520 | |
| 521 | static int via_init_one(struct pci_dev *pdev, const struct pci_device_id *id) |
| 522 | { |
| 523 | /* Early VIA without UDMA support */ |
Tejun Heo | 1626aeb | 2007-05-04 12:43:58 +0200 | [diff] [blame] | 524 | static const struct ata_port_info via_mwdma_info = { |
Tejun Heo | 464cf17 | 2007-05-27 15:10:40 +0200 | [diff] [blame] | 525 | .flags = ATA_FLAG_SLAVE_POSS, |
Erik Inge Bolsø | 14bdef9 | 2009-03-14 21:38:24 +0100 | [diff] [blame] | 526 | .pio_mask = ATA_PIO4, |
| 527 | .mwdma_mask = ATA_MWDMA2, |
Jeff Garzik | 669a5db | 2006-08-29 18:12:40 -0400 | [diff] [blame] | 528 | .port_ops = &via_port_ops |
| 529 | }; |
| 530 | /* Ditto with IRQ masking required */ |
Tejun Heo | 1626aeb | 2007-05-04 12:43:58 +0200 | [diff] [blame] | 531 | static const struct ata_port_info via_mwdma_info_borked = { |
Tejun Heo | 464cf17 | 2007-05-27 15:10:40 +0200 | [diff] [blame] | 532 | .flags = ATA_FLAG_SLAVE_POSS, |
Erik Inge Bolsø | 14bdef9 | 2009-03-14 21:38:24 +0100 | [diff] [blame] | 533 | .pio_mask = ATA_PIO4, |
| 534 | .mwdma_mask = ATA_MWDMA2, |
Jeff Garzik | 669a5db | 2006-08-29 18:12:40 -0400 | [diff] [blame] | 535 | .port_ops = &via_port_ops_noirq, |
| 536 | }; |
| 537 | /* VIA UDMA 33 devices (and borked 66) */ |
Tejun Heo | 1626aeb | 2007-05-04 12:43:58 +0200 | [diff] [blame] | 538 | static const struct ata_port_info via_udma33_info = { |
Tejun Heo | 464cf17 | 2007-05-27 15:10:40 +0200 | [diff] [blame] | 539 | .flags = ATA_FLAG_SLAVE_POSS, |
Erik Inge Bolsø | 14bdef9 | 2009-03-14 21:38:24 +0100 | [diff] [blame] | 540 | .pio_mask = ATA_PIO4, |
| 541 | .mwdma_mask = ATA_MWDMA2, |
Jeff Garzik | bf6263a | 2007-07-09 12:16:50 -0400 | [diff] [blame] | 542 | .udma_mask = ATA_UDMA2, |
Jeff Garzik | 669a5db | 2006-08-29 18:12:40 -0400 | [diff] [blame] | 543 | .port_ops = &via_port_ops |
| 544 | }; |
| 545 | /* VIA UDMA 66 devices */ |
Tejun Heo | 1626aeb | 2007-05-04 12:43:58 +0200 | [diff] [blame] | 546 | static const struct ata_port_info via_udma66_info = { |
Tejun Heo | 464cf17 | 2007-05-27 15:10:40 +0200 | [diff] [blame] | 547 | .flags = ATA_FLAG_SLAVE_POSS, |
Erik Inge Bolsø | 14bdef9 | 2009-03-14 21:38:24 +0100 | [diff] [blame] | 548 | .pio_mask = ATA_PIO4, |
| 549 | .mwdma_mask = ATA_MWDMA2, |
Jeff Garzik | bf6263a | 2007-07-09 12:16:50 -0400 | [diff] [blame] | 550 | .udma_mask = ATA_UDMA4, |
Jeff Garzik | 669a5db | 2006-08-29 18:12:40 -0400 | [diff] [blame] | 551 | .port_ops = &via_port_ops |
| 552 | }; |
| 553 | /* VIA UDMA 100 devices */ |
Tejun Heo | 1626aeb | 2007-05-04 12:43:58 +0200 | [diff] [blame] | 554 | static const struct ata_port_info via_udma100_info = { |
Tejun Heo | 464cf17 | 2007-05-27 15:10:40 +0200 | [diff] [blame] | 555 | .flags = ATA_FLAG_SLAVE_POSS, |
Erik Inge Bolsø | 14bdef9 | 2009-03-14 21:38:24 +0100 | [diff] [blame] | 556 | .pio_mask = ATA_PIO4, |
| 557 | .mwdma_mask = ATA_MWDMA2, |
Jeff Garzik | bf6263a | 2007-07-09 12:16:50 -0400 | [diff] [blame] | 558 | .udma_mask = ATA_UDMA5, |
Jeff Garzik | 669a5db | 2006-08-29 18:12:40 -0400 | [diff] [blame] | 559 | .port_ops = &via_port_ops |
| 560 | }; |
| 561 | /* UDMA133 with bad AST (All current 133) */ |
Tejun Heo | 1626aeb | 2007-05-04 12:43:58 +0200 | [diff] [blame] | 562 | static const struct ata_port_info via_udma133_info = { |
Tejun Heo | 464cf17 | 2007-05-27 15:10:40 +0200 | [diff] [blame] | 563 | .flags = ATA_FLAG_SLAVE_POSS, |
Erik Inge Bolsø | 14bdef9 | 2009-03-14 21:38:24 +0100 | [diff] [blame] | 564 | .pio_mask = ATA_PIO4, |
| 565 | .mwdma_mask = ATA_MWDMA2, |
Jeff Garzik | bf6263a | 2007-07-09 12:16:50 -0400 | [diff] [blame] | 566 | .udma_mask = ATA_UDMA6, /* FIXME: should check north bridge */ |
Jeff Garzik | 669a5db | 2006-08-29 18:12:40 -0400 | [diff] [blame] | 567 | .port_ops = &via_port_ops |
| 568 | }; |
Tejun Heo | 887125e | 2008-03-25 12:22:49 +0900 | [diff] [blame] | 569 | const struct ata_port_info *ppi[] = { NULL, NULL }; |
Jiri Slaby | 7095e3e | 2009-11-04 17:11:03 +0100 | [diff] [blame] | 570 | struct pci_dev *isa; |
Jeff Garzik | 669a5db | 2006-08-29 18:12:40 -0400 | [diff] [blame] | 571 | const struct via_isa_bridge *config; |
Jeff Garzik | 669a5db | 2006-08-29 18:12:40 -0400 | [diff] [blame] | 572 | u8 enable; |
| 573 | u32 timing; |
JosephChan@via.com.tw | e4d866c | 2009-01-23 15:37:39 +0800 | [diff] [blame] | 574 | unsigned long flags = id->driver_data; |
Tejun Heo | f08048e | 2008-03-25 12:22:47 +0900 | [diff] [blame] | 575 | int rc; |
Jeff Garzik | 669a5db | 2006-08-29 18:12:40 -0400 | [diff] [blame] | 576 | |
Joe Perches | 06296a1 | 2011-04-15 15:52:00 -0700 | [diff] [blame] | 577 | ata_print_version_once(&pdev->dev, DRV_VERSION); |
Jeff Garzik | 669a5db | 2006-08-29 18:12:40 -0400 | [diff] [blame] | 578 | |
Tejun Heo | f08048e | 2008-03-25 12:22:47 +0900 | [diff] [blame] | 579 | rc = pcim_enable_device(pdev); |
| 580 | if (rc) |
| 581 | return rc; |
| 582 | |
JosephChan@via.com.tw | e4d866c | 2009-01-23 15:37:39 +0800 | [diff] [blame] | 583 | if (flags & VIA_IDFLAG_SINGLE) |
| 584 | ppi[1] = &ata_dummy_port_info; |
| 585 | |
Jeff Garzik | 669a5db | 2006-08-29 18:12:40 -0400 | [diff] [blame] | 586 | /* To find out how the IDE will behave and what features we |
| 587 | actually have to look at the bridge not the IDE controller */ |
JosephChan@via.com.tw | e4d866c | 2009-01-23 15:37:39 +0800 | [diff] [blame] | 588 | for (config = via_isa_bridges; config->id != PCI_DEVICE_ID_VIA_ANON; |
| 589 | config++) |
Jeff Garzik | 669a5db | 2006-08-29 18:12:40 -0400 | [diff] [blame] | 590 | if ((isa = pci_get_device(PCI_VENDOR_ID_VIA + |
| 591 | !!(config->flags & VIA_BAD_ID), |
| 592 | config->id, NULL))) { |
Jiri Slaby | 7095e3e | 2009-11-04 17:11:03 +0100 | [diff] [blame] | 593 | u8 rev = isa->revision; |
Jeff Garzik | 669a5db | 2006-08-29 18:12:40 -0400 | [diff] [blame] | 594 | pci_dev_put(isa); |
Jeff Garzik | 669a5db | 2006-08-29 18:12:40 -0400 | [diff] [blame] | 595 | |
JosephChan@via.com.tw | bc8a673 | 2010-03-25 20:51:47 +0800 | [diff] [blame] | 596 | if ((id->device == 0x0415 || id->device == 0x3164) && |
| 597 | (config->id != id->device)) |
| 598 | continue; |
| 599 | |
Jiri Slaby | 7095e3e | 2009-11-04 17:11:03 +0100 | [diff] [blame] | 600 | if (rev >= config->rev_min && rev <= config->rev_max) |
| 601 | break; |
| 602 | } |
Jeff Garzik | 669a5db | 2006-08-29 18:12:40 -0400 | [diff] [blame] | 603 | |
Alan Cox | 11f6400 | 2008-04-29 14:10:57 +0100 | [diff] [blame] | 604 | if (!(config->flags & VIA_NO_ENABLES)) { |
| 605 | /* 0x40 low bits indicate enabled channels */ |
| 606 | pci_read_config_byte(pdev, 0x40 , &enable); |
| 607 | enable &= 3; |
| 608 | if (enable == 0) |
| 609 | return -ENODEV; |
Jeff Garzik | 669a5db | 2006-08-29 18:12:40 -0400 | [diff] [blame] | 610 | } |
| 611 | |
| 612 | /* Initialise the FIFO for the enabled channels. */ |
Alan | 627d2d3 | 2006-11-27 16:19:36 +0000 | [diff] [blame] | 613 | via_config_fifo(pdev, config->flags); |
Jeff Garzik | f20b16f | 2006-12-11 11:14:06 -0500 | [diff] [blame] | 614 | |
Jeff Garzik | 669a5db | 2006-08-29 18:12:40 -0400 | [diff] [blame] | 615 | /* Clock set up */ |
Bartlomiej Zolnierkiewicz | 460f531 | 2010-01-18 18:17:12 +0100 | [diff] [blame] | 616 | switch (config->udma_mask) { |
| 617 | case 0x00: |
| 618 | if (config->flags & VIA_NO_UNMASK) |
| 619 | ppi[0] = &via_mwdma_info_borked; |
| 620 | else |
| 621 | ppi[0] = &via_mwdma_info; |
| 622 | break; |
| 623 | case ATA_UDMA2: |
| 624 | ppi[0] = &via_udma33_info; |
| 625 | break; |
| 626 | case ATA_UDMA4: |
| 627 | ppi[0] = &via_udma66_info; |
| 628 | break; |
| 629 | case ATA_UDMA5: |
| 630 | ppi[0] = &via_udma100_info; |
| 631 | break; |
| 632 | case ATA_UDMA6: |
| 633 | ppi[0] = &via_udma133_info; |
| 634 | break; |
| 635 | default: |
| 636 | WARN_ON(1); |
| 637 | return -ENODEV; |
| 638 | } |
Jeff Garzik | 669a5db | 2006-08-29 18:12:40 -0400 | [diff] [blame] | 639 | |
| 640 | if (config->flags & VIA_BAD_CLK66) { |
| 641 | /* Disable the 66MHz clock on problem devices */ |
| 642 | pci_read_config_dword(pdev, 0x50, &timing); |
| 643 | timing &= ~0x80008; |
| 644 | pci_write_config_dword(pdev, 0x50, timing); |
| 645 | } |
| 646 | |
| 647 | /* We have established the device type, now fire it up */ |
Tejun Heo | 1c5afdf | 2010-05-19 22:10:22 +0200 | [diff] [blame] | 648 | return ata_pci_bmdma_init_one(pdev, ppi, &via_sht, (void *)config, 0); |
Jeff Garzik | 669a5db | 2006-08-29 18:12:40 -0400 | [diff] [blame] | 649 | } |
| 650 | |
Tejun Heo | 438ac6d | 2007-03-02 17:31:26 +0900 | [diff] [blame] | 651 | #ifdef CONFIG_PM |
Alan | 627d2d3 | 2006-11-27 16:19:36 +0000 | [diff] [blame] | 652 | /** |
| 653 | * via_reinit_one - reinit after resume |
| 654 | * @pdev; PCI device |
| 655 | * |
| 656 | * Called when the VIA PATA device is resumed. We must then |
| 657 | * reconfigure the fifo and other setup we may have altered. In |
| 658 | * addition the kernel needs to have the resume methods on PCI |
| 659 | * quirk supported. |
| 660 | */ |
| 661 | |
| 662 | static int via_reinit_one(struct pci_dev *pdev) |
| 663 | { |
| 664 | u32 timing; |
| 665 | struct ata_host *host = dev_get_drvdata(&pdev->dev); |
| 666 | const struct via_isa_bridge *config = host->private_data; |
Tejun Heo | f08048e | 2008-03-25 12:22:47 +0900 | [diff] [blame] | 667 | int rc; |
| 668 | |
| 669 | rc = ata_pci_device_do_resume(pdev); |
| 670 | if (rc) |
| 671 | return rc; |
Jeff Garzik | f20b16f | 2006-12-11 11:14:06 -0500 | [diff] [blame] | 672 | |
Alan | 627d2d3 | 2006-11-27 16:19:36 +0000 | [diff] [blame] | 673 | via_config_fifo(pdev, config->flags); |
| 674 | |
Bartlomiej Zolnierkiewicz | 460f531 | 2010-01-18 18:17:12 +0100 | [diff] [blame] | 675 | if (config->udma_mask == ATA_UDMA4) { |
Alan | 627d2d3 | 2006-11-27 16:19:36 +0000 | [diff] [blame] | 676 | /* The 66 MHz devices require we enable the clock */ |
| 677 | pci_read_config_dword(pdev, 0x50, &timing); |
| 678 | timing |= 0x80008; |
| 679 | pci_write_config_dword(pdev, 0x50, timing); |
| 680 | } |
| 681 | if (config->flags & VIA_BAD_CLK66) { |
| 682 | /* Disable the 66MHz clock on problem devices */ |
| 683 | pci_read_config_dword(pdev, 0x50, &timing); |
| 684 | timing &= ~0x80008; |
| 685 | pci_write_config_dword(pdev, 0x50, timing); |
| 686 | } |
Tejun Heo | f08048e | 2008-03-25 12:22:47 +0900 | [diff] [blame] | 687 | |
| 688 | ata_host_resume(host); |
| 689 | return 0; |
Alan | 627d2d3 | 2006-11-27 16:19:36 +0000 | [diff] [blame] | 690 | } |
Tejun Heo | 438ac6d | 2007-03-02 17:31:26 +0900 | [diff] [blame] | 691 | #endif |
Alan | 627d2d3 | 2006-11-27 16:19:36 +0000 | [diff] [blame] | 692 | |
Jeff Garzik | 669a5db | 2006-08-29 18:12:40 -0400 | [diff] [blame] | 693 | static const struct pci_device_id via[] = { |
Zlatko Calusic | 5955c7a | 2009-02-18 01:33:34 +0100 | [diff] [blame] | 694 | { PCI_VDEVICE(VIA, 0x0415), }, |
Jeff Garzik | 52df0ee | 2007-05-25 05:02:06 -0400 | [diff] [blame] | 695 | { PCI_VDEVICE(VIA, 0x0571), }, |
| 696 | { PCI_VDEVICE(VIA, 0x0581), }, |
| 697 | { PCI_VDEVICE(VIA, 0x1571), }, |
| 698 | { PCI_VDEVICE(VIA, 0x3164), }, |
| 699 | { PCI_VDEVICE(VIA, 0x5324), }, |
JosephChan@via.com.tw | e4d866c | 2009-01-23 15:37:39 +0800 | [diff] [blame] | 700 | { PCI_VDEVICE(VIA, 0xC409), VIA_IDFLAG_SINGLE }, |
JosephChan@via.com.tw | 4f1deba | 2010-03-19 14:08:11 +0800 | [diff] [blame] | 701 | { PCI_VDEVICE(VIA, 0x9001), VIA_IDFLAG_SINGLE }, |
Jeff Garzik | 2d2744f | 2006-09-28 20:21:59 -0400 | [diff] [blame] | 702 | |
| 703 | { }, |
Jeff Garzik | 669a5db | 2006-08-29 18:12:40 -0400 | [diff] [blame] | 704 | }; |
| 705 | |
| 706 | static struct pci_driver via_pci_driver = { |
Jeff Garzik | 2d2744f | 2006-09-28 20:21:59 -0400 | [diff] [blame] | 707 | .name = DRV_NAME, |
Jeff Garzik | 669a5db | 2006-08-29 18:12:40 -0400 | [diff] [blame] | 708 | .id_table = via, |
| 709 | .probe = via_init_one, |
Alan | 627d2d3 | 2006-11-27 16:19:36 +0000 | [diff] [blame] | 710 | .remove = ata_pci_remove_one, |
Tejun Heo | 438ac6d | 2007-03-02 17:31:26 +0900 | [diff] [blame] | 711 | #ifdef CONFIG_PM |
Alan | 627d2d3 | 2006-11-27 16:19:36 +0000 | [diff] [blame] | 712 | .suspend = ata_pci_device_suspend, |
| 713 | .resume = via_reinit_one, |
Tejun Heo | 438ac6d | 2007-03-02 17:31:26 +0900 | [diff] [blame] | 714 | #endif |
Jeff Garzik | 669a5db | 2006-08-29 18:12:40 -0400 | [diff] [blame] | 715 | }; |
| 716 | |
| 717 | static int __init via_init(void) |
| 718 | { |
| 719 | return pci_register_driver(&via_pci_driver); |
| 720 | } |
| 721 | |
Jeff Garzik | 669a5db | 2006-08-29 18:12:40 -0400 | [diff] [blame] | 722 | static void __exit via_exit(void) |
| 723 | { |
| 724 | pci_unregister_driver(&via_pci_driver); |
| 725 | } |
| 726 | |
Jeff Garzik | 669a5db | 2006-08-29 18:12:40 -0400 | [diff] [blame] | 727 | MODULE_AUTHOR("Alan Cox"); |
| 728 | MODULE_DESCRIPTION("low-level driver for VIA PATA"); |
| 729 | MODULE_LICENSE("GPL"); |
| 730 | MODULE_DEVICE_TABLE(pci, via); |
| 731 | MODULE_VERSION(DRV_VERSION); |
| 732 | |
| 733 | module_init(via_init); |
| 734 | module_exit(via_exit); |