1669a5db4SJeff Garzik /* 2669a5db4SJeff Garzik * ata-it821x.c - IT821x PATA for new ATA layer 3669a5db4SJeff Garzik * (C) 2005 Red Hat Inc 4669a5db4SJeff Garzik * Alan Cox <alan@redhat.com> 5669a5db4SJeff Garzik * 6669a5db4SJeff Garzik * based upon 7669a5db4SJeff Garzik * 8669a5db4SJeff Garzik * it821x.c 9669a5db4SJeff Garzik * 10669a5db4SJeff Garzik * linux/drivers/ide/pci/it821x.c Version 0.09 December 2004 11669a5db4SJeff Garzik * 12669a5db4SJeff Garzik * Copyright (C) 2004 Red Hat <alan@redhat.com> 13669a5db4SJeff Garzik * 14669a5db4SJeff Garzik * May be copied or modified under the terms of the GNU General Public License 15669a5db4SJeff Garzik * Based in part on the ITE vendor provided SCSI driver. 16669a5db4SJeff Garzik * 17669a5db4SJeff Garzik * Documentation available from 18669a5db4SJeff Garzik * http://www.ite.com.tw/pc/IT8212F_V04.pdf 19669a5db4SJeff Garzik * Some other documents are NDA. 20669a5db4SJeff Garzik * 21669a5db4SJeff Garzik * The ITE8212 isn't exactly a standard IDE controller. It has two 22669a5db4SJeff Garzik * modes. In pass through mode then it is an IDE controller. In its smart 23669a5db4SJeff Garzik * mode its actually quite a capable hardware raid controller disguised 24669a5db4SJeff Garzik * as an IDE controller. Smart mode only understands DMA read/write and 25669a5db4SJeff Garzik * identify, none of the fancier commands apply. The IT8211 is identical 26669a5db4SJeff Garzik * in other respects but lacks the raid mode. 27669a5db4SJeff Garzik * 28669a5db4SJeff Garzik * Errata: 29669a5db4SJeff Garzik * o Rev 0x10 also requires master/slave hold the same DMA timings and 30669a5db4SJeff Garzik * cannot do ATAPI MWDMA. 31669a5db4SJeff Garzik * o The identify data for raid volumes lacks CHS info (technically ok) 32669a5db4SJeff Garzik * but also fails to set the LBA28 and other bits. We fix these in 33669a5db4SJeff Garzik * the IDE probe quirk code. 34669a5db4SJeff Garzik * o If you write LBA48 sized I/O's (ie > 256 sector) in smart mode 35669a5db4SJeff Garzik * raid then the controller firmware dies 36669a5db4SJeff Garzik * o Smart mode without RAID doesn't clear all the necessary identify 37669a5db4SJeff Garzik * bits to reduce the command set to the one used 38669a5db4SJeff Garzik * 39669a5db4SJeff Garzik * This has a few impacts on the driver 40669a5db4SJeff Garzik * - In pass through mode we do all the work you would expect 41669a5db4SJeff Garzik * - In smart mode the clocking set up is done by the controller generally 42669a5db4SJeff Garzik * but we must watch the other limits and filter. 43669a5db4SJeff Garzik * - There are a few extra vendor commands that actually talk to the 44669a5db4SJeff Garzik * controller but only work PIO with no IRQ. 45669a5db4SJeff Garzik * 46669a5db4SJeff Garzik * Vendor areas of the identify block in smart mode are used for the 47669a5db4SJeff Garzik * timing and policy set up. Each HDD in raid mode also has a serial 48669a5db4SJeff Garzik * block on the disk. The hardware extra commands are get/set chip status, 49669a5db4SJeff Garzik * rebuild, get rebuild status. 50669a5db4SJeff Garzik * 51669a5db4SJeff Garzik * In Linux the driver supports pass through mode as if the device was 52669a5db4SJeff Garzik * just another IDE controller. If the smart mode is running then 53669a5db4SJeff Garzik * volumes are managed by the controller firmware and each IDE "disk" 54669a5db4SJeff Garzik * is a raid volume. Even more cute - the controller can do automated 55669a5db4SJeff Garzik * hotplug and rebuild. 56669a5db4SJeff Garzik * 57669a5db4SJeff Garzik * The pass through controller itself is a little demented. It has a 58669a5db4SJeff Garzik * flaw that it has a single set of PIO/MWDMA timings per channel so 59669a5db4SJeff Garzik * non UDMA devices restrict each others performance. It also has a 60669a5db4SJeff Garzik * single clock source per channel so mixed UDMA100/133 performance 61669a5db4SJeff Garzik * isn't perfect and we have to pick a clock. Thankfully none of this 62669a5db4SJeff Garzik * matters in smart mode. ATAPI DMA is not currently supported. 63669a5db4SJeff Garzik * 64669a5db4SJeff Garzik * It seems the smart mode is a win for RAID1/RAID10 but otherwise not. 65669a5db4SJeff Garzik * 66669a5db4SJeff Garzik * TODO 67669a5db4SJeff Garzik * - ATAPI and other speed filtering 68669a5db4SJeff Garzik * - Command filter in smart mode 69669a5db4SJeff Garzik * - RAID configuration ioctls 70669a5db4SJeff Garzik */ 71669a5db4SJeff Garzik 72669a5db4SJeff Garzik #include <linux/kernel.h> 73669a5db4SJeff Garzik #include <linux/module.h> 74669a5db4SJeff Garzik #include <linux/pci.h> 75669a5db4SJeff Garzik #include <linux/init.h> 76669a5db4SJeff Garzik #include <linux/blkdev.h> 77669a5db4SJeff Garzik #include <linux/delay.h> 78669a5db4SJeff Garzik #include <scsi/scsi_host.h> 79669a5db4SJeff Garzik #include <linux/libata.h> 80669a5db4SJeff Garzik 81669a5db4SJeff Garzik 82669a5db4SJeff Garzik #define DRV_NAME "pata_it821x" 83f535d53fSAlan #define DRV_VERSION "0.3.3" 84669a5db4SJeff Garzik 85669a5db4SJeff Garzik struct it821x_dev 86669a5db4SJeff Garzik { 87669a5db4SJeff Garzik unsigned int smart:1, /* Are we in smart raid mode */ 88669a5db4SJeff Garzik timing10:1; /* Rev 0x10 */ 89669a5db4SJeff Garzik u8 clock_mode; /* 0, ATA_50 or ATA_66 */ 90669a5db4SJeff Garzik u8 want[2][2]; /* Mode/Pri log for master slave */ 91669a5db4SJeff Garzik /* We need these for switching the clock when DMA goes on/off 92669a5db4SJeff Garzik The high byte is the 66Mhz timing */ 93669a5db4SJeff Garzik u16 pio[2]; /* Cached PIO values */ 94669a5db4SJeff Garzik u16 mwdma[2]; /* Cached MWDMA values */ 95669a5db4SJeff Garzik u16 udma[2]; /* Cached UDMA values (per drive) */ 96669a5db4SJeff Garzik u16 last_device; /* Master or slave loaded ? */ 97669a5db4SJeff Garzik }; 98669a5db4SJeff Garzik 99669a5db4SJeff Garzik #define ATA_66 0 100669a5db4SJeff Garzik #define ATA_50 1 101669a5db4SJeff Garzik #define ATA_ANY 2 102669a5db4SJeff Garzik 103669a5db4SJeff Garzik #define UDMA_OFF 0 104669a5db4SJeff Garzik #define MWDMA_OFF 0 105669a5db4SJeff Garzik 106669a5db4SJeff Garzik /* 107669a5db4SJeff Garzik * We allow users to force the card into non raid mode without 108669a5db4SJeff Garzik * flashing the alternative BIOS. This is also neccessary right now 109669a5db4SJeff Garzik * for embedded platforms that cannot run a PC BIOS but are using this 110669a5db4SJeff Garzik * device. 111669a5db4SJeff Garzik */ 112669a5db4SJeff Garzik 113669a5db4SJeff Garzik static int it8212_noraid; 114669a5db4SJeff Garzik 115669a5db4SJeff Garzik /** 116669a5db4SJeff Garzik * it821x_pre_reset - probe 117669a5db4SJeff Garzik * @ap: ATA port 118669a5db4SJeff Garzik * 119669a5db4SJeff Garzik * Set the cable type 120669a5db4SJeff Garzik */ 121669a5db4SJeff Garzik 122669a5db4SJeff Garzik static int it821x_pre_reset(struct ata_port *ap) 123669a5db4SJeff Garzik { 124669a5db4SJeff Garzik ap->cbl = ATA_CBL_PATA80; 125669a5db4SJeff Garzik return ata_std_prereset(ap); 126669a5db4SJeff Garzik } 127669a5db4SJeff Garzik 128669a5db4SJeff Garzik /** 129669a5db4SJeff Garzik * it821x_error_handler - probe/reset 130669a5db4SJeff Garzik * @ap: ATA port 131669a5db4SJeff Garzik * 132669a5db4SJeff Garzik * Set the cable type and trigger a probe 133669a5db4SJeff Garzik */ 134669a5db4SJeff Garzik 135669a5db4SJeff Garzik static void it821x_error_handler(struct ata_port *ap) 136669a5db4SJeff Garzik { 137669a5db4SJeff Garzik return ata_bmdma_drive_eh(ap, it821x_pre_reset, ata_std_softreset, NULL, ata_std_postreset); 138669a5db4SJeff Garzik } 139669a5db4SJeff Garzik 140669a5db4SJeff Garzik /** 141669a5db4SJeff Garzik * it821x_program - program the PIO/MWDMA registers 142669a5db4SJeff Garzik * @ap: ATA port 143669a5db4SJeff Garzik * @adev: Device to program 144669a5db4SJeff Garzik * @timing: Timing value (66Mhz in top 8bits, 50 in the low 8) 145669a5db4SJeff Garzik * 146669a5db4SJeff Garzik * Program the PIO/MWDMA timing for this channel according to the 147669a5db4SJeff Garzik * current clock. These share the same register so are managed by 148669a5db4SJeff Garzik * the DMA start/stop sequence as with the old driver. 149669a5db4SJeff Garzik */ 150669a5db4SJeff Garzik 151669a5db4SJeff Garzik static void it821x_program(struct ata_port *ap, struct ata_device *adev, u16 timing) 152669a5db4SJeff Garzik { 153669a5db4SJeff Garzik struct pci_dev *pdev = to_pci_dev(ap->host->dev); 154669a5db4SJeff Garzik struct it821x_dev *itdev = ap->private_data; 155669a5db4SJeff Garzik int channel = ap->port_no; 156669a5db4SJeff Garzik u8 conf; 157669a5db4SJeff Garzik 158669a5db4SJeff Garzik /* Program PIO/MWDMA timing bits */ 159669a5db4SJeff Garzik if (itdev->clock_mode == ATA_66) 160669a5db4SJeff Garzik conf = timing >> 8; 161669a5db4SJeff Garzik else 162669a5db4SJeff Garzik conf = timing & 0xFF; 163669a5db4SJeff Garzik pci_write_config_byte(pdev, 0x54 + 4 * channel, conf); 164669a5db4SJeff Garzik } 165669a5db4SJeff Garzik 166669a5db4SJeff Garzik 167669a5db4SJeff Garzik /** 168669a5db4SJeff Garzik * it821x_program_udma - program the UDMA registers 169669a5db4SJeff Garzik * @ap: ATA port 170669a5db4SJeff Garzik * @adev: ATA device to update 171669a5db4SJeff Garzik * @timing: Timing bits. Top 8 are for 66Mhz bottom for 50Mhz 172669a5db4SJeff Garzik * 173669a5db4SJeff Garzik * Program the UDMA timing for this drive according to the 174669a5db4SJeff Garzik * current clock. Handles the dual clocks and also knows about 175669a5db4SJeff Garzik * the errata on the 0x10 revision. The UDMA errata is partly handled 176669a5db4SJeff Garzik * here and partly in start_dma. 177669a5db4SJeff Garzik */ 178669a5db4SJeff Garzik 179669a5db4SJeff Garzik static void it821x_program_udma(struct ata_port *ap, struct ata_device *adev, u16 timing) 180669a5db4SJeff Garzik { 181669a5db4SJeff Garzik struct it821x_dev *itdev = ap->private_data; 182669a5db4SJeff Garzik struct pci_dev *pdev = to_pci_dev(ap->host->dev); 183669a5db4SJeff Garzik int channel = ap->port_no; 184669a5db4SJeff Garzik int unit = adev->devno; 185669a5db4SJeff Garzik u8 conf; 186669a5db4SJeff Garzik 187669a5db4SJeff Garzik /* Program UDMA timing bits */ 188669a5db4SJeff Garzik if (itdev->clock_mode == ATA_66) 189669a5db4SJeff Garzik conf = timing >> 8; 190669a5db4SJeff Garzik else 191669a5db4SJeff Garzik conf = timing & 0xFF; 192669a5db4SJeff Garzik if (itdev->timing10 == 0) 193669a5db4SJeff Garzik pci_write_config_byte(pdev, 0x56 + 4 * channel + unit, conf); 194669a5db4SJeff Garzik else { 195669a5db4SJeff Garzik /* Early revision must be programmed for both together */ 196669a5db4SJeff Garzik pci_write_config_byte(pdev, 0x56 + 4 * channel, conf); 197669a5db4SJeff Garzik pci_write_config_byte(pdev, 0x56 + 4 * channel + 1, conf); 198669a5db4SJeff Garzik } 199669a5db4SJeff Garzik } 200669a5db4SJeff Garzik 201669a5db4SJeff Garzik /** 202669a5db4SJeff Garzik * it821x_clock_strategy 203669a5db4SJeff Garzik * @ap: ATA interface 204669a5db4SJeff Garzik * @adev: ATA device being updated 205669a5db4SJeff Garzik * 206669a5db4SJeff Garzik * Select between the 50 and 66Mhz base clocks to get the best 207669a5db4SJeff Garzik * results for this interface. 208669a5db4SJeff Garzik */ 209669a5db4SJeff Garzik 210669a5db4SJeff Garzik static void it821x_clock_strategy(struct ata_port *ap, struct ata_device *adev) 211669a5db4SJeff Garzik { 212669a5db4SJeff Garzik struct pci_dev *pdev = to_pci_dev(ap->host->dev); 213669a5db4SJeff Garzik struct it821x_dev *itdev = ap->private_data; 214669a5db4SJeff Garzik u8 unit = adev->devno; 215669a5db4SJeff Garzik struct ata_device *pair = ata_dev_pair(adev); 216669a5db4SJeff Garzik 217669a5db4SJeff Garzik int clock, altclock; 218669a5db4SJeff Garzik u8 v; 219669a5db4SJeff Garzik int sel = 0; 220669a5db4SJeff Garzik 221669a5db4SJeff Garzik /* Look for the most wanted clocking */ 222669a5db4SJeff Garzik if (itdev->want[0][0] > itdev->want[1][0]) { 223669a5db4SJeff Garzik clock = itdev->want[0][1]; 224669a5db4SJeff Garzik altclock = itdev->want[1][1]; 225669a5db4SJeff Garzik } else { 226669a5db4SJeff Garzik clock = itdev->want[1][1]; 227669a5db4SJeff Garzik altclock = itdev->want[0][1]; 228669a5db4SJeff Garzik } 229669a5db4SJeff Garzik 230669a5db4SJeff Garzik /* Master doesn't care does the slave ? */ 231669a5db4SJeff Garzik if (clock == ATA_ANY) 232669a5db4SJeff Garzik clock = altclock; 233669a5db4SJeff Garzik 234669a5db4SJeff Garzik /* Nobody cares - keep the same clock */ 235669a5db4SJeff Garzik if (clock == ATA_ANY) 236669a5db4SJeff Garzik return; 237669a5db4SJeff Garzik /* No change */ 238669a5db4SJeff Garzik if (clock == itdev->clock_mode) 239669a5db4SJeff Garzik return; 240669a5db4SJeff Garzik 241669a5db4SJeff Garzik /* Load this into the controller */ 242669a5db4SJeff Garzik if (clock == ATA_66) 243669a5db4SJeff Garzik itdev->clock_mode = ATA_66; 244669a5db4SJeff Garzik else { 245669a5db4SJeff Garzik itdev->clock_mode = ATA_50; 246669a5db4SJeff Garzik sel = 1; 247669a5db4SJeff Garzik } 248669a5db4SJeff Garzik pci_read_config_byte(pdev, 0x50, &v); 249669a5db4SJeff Garzik v &= ~(1 << (1 + ap->port_no)); 250669a5db4SJeff Garzik v |= sel << (1 + ap->port_no); 251669a5db4SJeff Garzik pci_write_config_byte(pdev, 0x50, v); 252669a5db4SJeff Garzik 253669a5db4SJeff Garzik /* 254669a5db4SJeff Garzik * Reprogram the UDMA/PIO of the pair drive for the switch 255669a5db4SJeff Garzik * MWDMA will be dealt with by the dma switcher 256669a5db4SJeff Garzik */ 257669a5db4SJeff Garzik if (pair && itdev->udma[1-unit] != UDMA_OFF) { 258669a5db4SJeff Garzik it821x_program_udma(ap, pair, itdev->udma[1-unit]); 259669a5db4SJeff Garzik it821x_program(ap, pair, itdev->pio[1-unit]); 260669a5db4SJeff Garzik } 261669a5db4SJeff Garzik /* 262669a5db4SJeff Garzik * Reprogram the UDMA/PIO of our drive for the switch. 263669a5db4SJeff Garzik * MWDMA will be dealt with by the dma switcher 264669a5db4SJeff Garzik */ 265669a5db4SJeff Garzik if (itdev->udma[unit] != UDMA_OFF) { 266669a5db4SJeff Garzik it821x_program_udma(ap, adev, itdev->udma[unit]); 267669a5db4SJeff Garzik it821x_program(ap, adev, itdev->pio[unit]); 268669a5db4SJeff Garzik } 269669a5db4SJeff Garzik } 270669a5db4SJeff Garzik 271669a5db4SJeff Garzik /** 272669a5db4SJeff Garzik * it821x_passthru_set_piomode - set PIO mode data 273669a5db4SJeff Garzik * @ap: ATA interface 274669a5db4SJeff Garzik * @adev: ATA device 275669a5db4SJeff Garzik * 276669a5db4SJeff Garzik * Configure for PIO mode. This is complicated as the register is 277669a5db4SJeff Garzik * shared by PIO and MWDMA and for both channels. 278669a5db4SJeff Garzik */ 279669a5db4SJeff Garzik 280669a5db4SJeff Garzik static void it821x_passthru_set_piomode(struct ata_port *ap, struct ata_device *adev) 281669a5db4SJeff Garzik { 282669a5db4SJeff Garzik /* Spec says 89 ref driver uses 88 */ 283669a5db4SJeff Garzik static const u16 pio[] = { 0xAA88, 0xA382, 0xA181, 0x3332, 0x3121 }; 284669a5db4SJeff Garzik static const u8 pio_want[] = { ATA_66, ATA_66, ATA_66, ATA_66, ATA_ANY }; 285669a5db4SJeff Garzik 286669a5db4SJeff Garzik struct it821x_dev *itdev = ap->private_data; 287669a5db4SJeff Garzik int unit = adev->devno; 288669a5db4SJeff Garzik int mode_wanted = adev->pio_mode - XFER_PIO_0; 289669a5db4SJeff Garzik 290669a5db4SJeff Garzik /* We prefer 66Mhz clock for PIO 0-3, don't care for PIO4 */ 291669a5db4SJeff Garzik itdev->want[unit][1] = pio_want[mode_wanted]; 292669a5db4SJeff Garzik itdev->want[unit][0] = 1; /* PIO is lowest priority */ 293669a5db4SJeff Garzik itdev->pio[unit] = pio[mode_wanted]; 294669a5db4SJeff Garzik it821x_clock_strategy(ap, adev); 295669a5db4SJeff Garzik it821x_program(ap, adev, itdev->pio[unit]); 296669a5db4SJeff Garzik } 297669a5db4SJeff Garzik 298669a5db4SJeff Garzik /** 299669a5db4SJeff Garzik * it821x_passthru_set_dmamode - set initial DMA mode data 300669a5db4SJeff Garzik * @ap: ATA interface 301669a5db4SJeff Garzik * @adev: ATA device 302669a5db4SJeff Garzik * 303669a5db4SJeff Garzik * Set up the DMA modes. The actions taken depend heavily on the mode 304669a5db4SJeff Garzik * to use. If UDMA is used as is hopefully the usual case then the 305669a5db4SJeff Garzik * timing register is private and we need only consider the clock. If 306669a5db4SJeff Garzik * we are using MWDMA then we have to manage the setting ourself as 307669a5db4SJeff Garzik * we switch devices and mode. 308669a5db4SJeff Garzik */ 309669a5db4SJeff Garzik 310669a5db4SJeff Garzik static void it821x_passthru_set_dmamode(struct ata_port *ap, struct ata_device *adev) 311669a5db4SJeff Garzik { 312669a5db4SJeff Garzik static const u16 dma[] = { 0x8866, 0x3222, 0x3121 }; 313669a5db4SJeff Garzik static const u8 mwdma_want[] = { ATA_ANY, ATA_66, ATA_ANY }; 314669a5db4SJeff Garzik static const u16 udma[] = { 0x4433, 0x4231, 0x3121, 0x2121, 0x1111, 0x2211, 0x1111 }; 315669a5db4SJeff Garzik static const u8 udma_want[] = { ATA_ANY, ATA_50, ATA_ANY, ATA_66, ATA_66, ATA_50, ATA_66 }; 316669a5db4SJeff Garzik 317669a5db4SJeff Garzik struct pci_dev *pdev = to_pci_dev(ap->host->dev); 318669a5db4SJeff Garzik struct it821x_dev *itdev = ap->private_data; 319669a5db4SJeff Garzik int channel = ap->port_no; 320669a5db4SJeff Garzik int unit = adev->devno; 321669a5db4SJeff Garzik u8 conf; 322669a5db4SJeff Garzik 323669a5db4SJeff Garzik if (adev->dma_mode >= XFER_UDMA_0) { 324669a5db4SJeff Garzik int mode_wanted = adev->dma_mode - XFER_UDMA_0; 325669a5db4SJeff Garzik 326669a5db4SJeff Garzik itdev->want[unit][1] = udma_want[mode_wanted]; 327669a5db4SJeff Garzik itdev->want[unit][0] = 3; /* UDMA is high priority */ 328669a5db4SJeff Garzik itdev->mwdma[unit] = MWDMA_OFF; 329669a5db4SJeff Garzik itdev->udma[unit] = udma[mode_wanted]; 330669a5db4SJeff Garzik if (mode_wanted >= 5) 331669a5db4SJeff Garzik itdev->udma[unit] |= 0x8080; /* UDMA 5/6 select on */ 332669a5db4SJeff Garzik 333669a5db4SJeff Garzik /* UDMA on. Again revision 0x10 must do the pair */ 334669a5db4SJeff Garzik pci_read_config_byte(pdev, 0x50, &conf); 335669a5db4SJeff Garzik if (itdev->timing10) 336669a5db4SJeff Garzik conf &= channel ? 0x9F: 0xE7; 337669a5db4SJeff Garzik else 338669a5db4SJeff Garzik conf &= ~ (1 << (3 + 2 * channel + unit)); 339669a5db4SJeff Garzik pci_write_config_byte(pdev, 0x50, conf); 340669a5db4SJeff Garzik it821x_clock_strategy(ap, adev); 341669a5db4SJeff Garzik it821x_program_udma(ap, adev, itdev->udma[unit]); 342669a5db4SJeff Garzik } else { 343669a5db4SJeff Garzik int mode_wanted = adev->dma_mode - XFER_MW_DMA_0; 344669a5db4SJeff Garzik 345669a5db4SJeff Garzik itdev->want[unit][1] = mwdma_want[mode_wanted]; 346669a5db4SJeff Garzik itdev->want[unit][0] = 2; /* MWDMA is low priority */ 347669a5db4SJeff Garzik itdev->mwdma[unit] = dma[mode_wanted]; 348669a5db4SJeff Garzik itdev->udma[unit] = UDMA_OFF; 349669a5db4SJeff Garzik 350669a5db4SJeff Garzik /* UDMA bits off - Revision 0x10 do them in pairs */ 351669a5db4SJeff Garzik pci_read_config_byte(pdev, 0x50, &conf); 352669a5db4SJeff Garzik if (itdev->timing10) 353669a5db4SJeff Garzik conf |= channel ? 0x60: 0x18; 354669a5db4SJeff Garzik else 355669a5db4SJeff Garzik conf |= 1 << (3 + 2 * channel + unit); 356669a5db4SJeff Garzik pci_write_config_byte(pdev, 0x50, conf); 357669a5db4SJeff Garzik it821x_clock_strategy(ap, adev); 358669a5db4SJeff Garzik } 359669a5db4SJeff Garzik } 360669a5db4SJeff Garzik 361669a5db4SJeff Garzik /** 362669a5db4SJeff Garzik * it821x_passthru_dma_start - DMA start callback 363669a5db4SJeff Garzik * @qc: Command in progress 364669a5db4SJeff Garzik * 365669a5db4SJeff Garzik * Usually drivers set the DMA timing at the point the set_dmamode call 366669a5db4SJeff Garzik * is made. IT821x however requires we load new timings on the 367669a5db4SJeff Garzik * transitions in some cases. 368669a5db4SJeff Garzik */ 369669a5db4SJeff Garzik 370669a5db4SJeff Garzik static void it821x_passthru_bmdma_start(struct ata_queued_cmd *qc) 371669a5db4SJeff Garzik { 372669a5db4SJeff Garzik struct ata_port *ap = qc->ap; 373669a5db4SJeff Garzik struct ata_device *adev = qc->dev; 374669a5db4SJeff Garzik struct it821x_dev *itdev = ap->private_data; 375669a5db4SJeff Garzik int unit = adev->devno; 376669a5db4SJeff Garzik 377669a5db4SJeff Garzik if (itdev->mwdma[unit] != MWDMA_OFF) 378669a5db4SJeff Garzik it821x_program(ap, adev, itdev->mwdma[unit]); 379669a5db4SJeff Garzik else if (itdev->udma[unit] != UDMA_OFF && itdev->timing10) 380669a5db4SJeff Garzik it821x_program_udma(ap, adev, itdev->udma[unit]); 381669a5db4SJeff Garzik ata_bmdma_start(qc); 382669a5db4SJeff Garzik } 383669a5db4SJeff Garzik 384669a5db4SJeff Garzik /** 385669a5db4SJeff Garzik * it821x_passthru_dma_stop - DMA stop callback 386669a5db4SJeff Garzik * @qc: ATA command 387669a5db4SJeff Garzik * 388669a5db4SJeff Garzik * We loaded new timings in dma_start, as a result we need to restore 389669a5db4SJeff Garzik * the PIO timings in dma_stop so that the next command issue gets the 390669a5db4SJeff Garzik * right clock values. 391669a5db4SJeff Garzik */ 392669a5db4SJeff Garzik 393669a5db4SJeff Garzik static void it821x_passthru_bmdma_stop(struct ata_queued_cmd *qc) 394669a5db4SJeff Garzik { 395669a5db4SJeff Garzik struct ata_port *ap = qc->ap; 396669a5db4SJeff Garzik struct ata_device *adev = qc->dev; 397669a5db4SJeff Garzik struct it821x_dev *itdev = ap->private_data; 398669a5db4SJeff Garzik int unit = adev->devno; 399669a5db4SJeff Garzik 400669a5db4SJeff Garzik ata_bmdma_stop(qc); 401669a5db4SJeff Garzik if (itdev->mwdma[unit] != MWDMA_OFF) 402669a5db4SJeff Garzik it821x_program(ap, adev, itdev->pio[unit]); 403669a5db4SJeff Garzik } 404669a5db4SJeff Garzik 405669a5db4SJeff Garzik 406669a5db4SJeff Garzik /** 407669a5db4SJeff Garzik * it821x_passthru_dev_select - Select master/slave 408669a5db4SJeff Garzik * @ap: ATA port 409669a5db4SJeff Garzik * @device: Device number (not pointer) 410669a5db4SJeff Garzik * 411669a5db4SJeff Garzik * Device selection hook. If neccessary perform clock switching 412669a5db4SJeff Garzik */ 413669a5db4SJeff Garzik 414669a5db4SJeff Garzik static void it821x_passthru_dev_select(struct ata_port *ap, 415669a5db4SJeff Garzik unsigned int device) 416669a5db4SJeff Garzik { 417669a5db4SJeff Garzik struct it821x_dev *itdev = ap->private_data; 418669a5db4SJeff Garzik if (itdev && device != itdev->last_device) { 419669a5db4SJeff Garzik struct ata_device *adev = &ap->device[device]; 420669a5db4SJeff Garzik it821x_program(ap, adev, itdev->pio[adev->devno]); 421669a5db4SJeff Garzik itdev->last_device = device; 422669a5db4SJeff Garzik } 423669a5db4SJeff Garzik ata_std_dev_select(ap, device); 424669a5db4SJeff Garzik } 425669a5db4SJeff Garzik 426669a5db4SJeff Garzik /** 427669a5db4SJeff Garzik * it821x_smart_qc_issue_prot - wrap qc issue prot 428669a5db4SJeff Garzik * @qc: command 429669a5db4SJeff Garzik * 430669a5db4SJeff Garzik * Wrap the command issue sequence for the IT821x. We need to 431669a5db4SJeff Garzik * perform out own device selection timing loads before the 432669a5db4SJeff Garzik * usual happenings kick off 433669a5db4SJeff Garzik */ 434669a5db4SJeff Garzik 435669a5db4SJeff Garzik static unsigned int it821x_smart_qc_issue_prot(struct ata_queued_cmd *qc) 436669a5db4SJeff Garzik { 437669a5db4SJeff Garzik switch(qc->tf.command) 438669a5db4SJeff Garzik { 439669a5db4SJeff Garzik /* Commands the firmware supports */ 440669a5db4SJeff Garzik case ATA_CMD_READ: 441669a5db4SJeff Garzik case ATA_CMD_READ_EXT: 442669a5db4SJeff Garzik case ATA_CMD_WRITE: 443669a5db4SJeff Garzik case ATA_CMD_WRITE_EXT: 444669a5db4SJeff Garzik case ATA_CMD_PIO_READ: 445669a5db4SJeff Garzik case ATA_CMD_PIO_READ_EXT: 446669a5db4SJeff Garzik case ATA_CMD_PIO_WRITE: 447669a5db4SJeff Garzik case ATA_CMD_PIO_WRITE_EXT: 448669a5db4SJeff Garzik case ATA_CMD_READ_MULTI: 449669a5db4SJeff Garzik case ATA_CMD_READ_MULTI_EXT: 450669a5db4SJeff Garzik case ATA_CMD_WRITE_MULTI: 451669a5db4SJeff Garzik case ATA_CMD_WRITE_MULTI_EXT: 452669a5db4SJeff Garzik case ATA_CMD_ID_ATA: 453669a5db4SJeff Garzik /* Arguably should just no-op this one */ 454669a5db4SJeff Garzik case ATA_CMD_SET_FEATURES: 455669a5db4SJeff Garzik return ata_qc_issue_prot(qc); 456669a5db4SJeff Garzik } 457669a5db4SJeff Garzik printk(KERN_DEBUG "it821x: can't process command 0x%02X\n", qc->tf.command); 458669a5db4SJeff Garzik return AC_ERR_INVALID; 459669a5db4SJeff Garzik } 460669a5db4SJeff Garzik 461669a5db4SJeff Garzik /** 462669a5db4SJeff Garzik * it821x_passthru_qc_issue_prot - wrap qc issue prot 463669a5db4SJeff Garzik * @qc: command 464669a5db4SJeff Garzik * 465669a5db4SJeff Garzik * Wrap the command issue sequence for the IT821x. We need to 466669a5db4SJeff Garzik * perform out own device selection timing loads before the 467669a5db4SJeff Garzik * usual happenings kick off 468669a5db4SJeff Garzik */ 469669a5db4SJeff Garzik 470669a5db4SJeff Garzik static unsigned int it821x_passthru_qc_issue_prot(struct ata_queued_cmd *qc) 471669a5db4SJeff Garzik { 472669a5db4SJeff Garzik it821x_passthru_dev_select(qc->ap, qc->dev->devno); 473669a5db4SJeff Garzik return ata_qc_issue_prot(qc); 474669a5db4SJeff Garzik } 475669a5db4SJeff Garzik 476669a5db4SJeff Garzik /** 477669a5db4SJeff Garzik * it821x_smart_set_mode - mode setting 478669a5db4SJeff Garzik * @ap: interface to set up 479b229a7b0SAlan * @unused: device that failed (error only) 480669a5db4SJeff Garzik * 481669a5db4SJeff Garzik * Use a non standard set_mode function. We don't want to be tuned. 482669a5db4SJeff Garzik * The BIOS configured everything. Our job is not to fiddle. We 483669a5db4SJeff Garzik * read the dma enabled bits from the PCI configuration of the device 484669a5db4SJeff Garzik * and respect them. 485669a5db4SJeff Garzik */ 486669a5db4SJeff Garzik 487b229a7b0SAlan static int it821x_smart_set_mode(struct ata_port *ap, struct ata_device **unused) 488669a5db4SJeff Garzik { 489669a5db4SJeff Garzik int dma_enabled = 0; 490669a5db4SJeff Garzik int i; 491669a5db4SJeff Garzik 492669a5db4SJeff Garzik /* Bits 5 and 6 indicate if DMA is active on master/slave */ 493669a5db4SJeff Garzik /* It is possible that BMDMA isn't allocated */ 494669a5db4SJeff Garzik if (ap->ioaddr.bmdma_addr) 495669a5db4SJeff Garzik dma_enabled = inb(ap->ioaddr.bmdma_addr + ATA_DMA_CMD); 496669a5db4SJeff Garzik 497669a5db4SJeff Garzik for (i = 0; i < ATA_MAX_DEVICES; i++) { 498669a5db4SJeff Garzik struct ata_device *dev = &ap->device[i]; 499669a5db4SJeff Garzik if (ata_dev_enabled(dev)) { 500669a5db4SJeff Garzik /* We don't really care */ 501669a5db4SJeff Garzik dev->pio_mode = XFER_PIO_0; 502669a5db4SJeff Garzik dev->dma_mode = XFER_MW_DMA_0; 503669a5db4SJeff Garzik /* We do need the right mode information for DMA or PIO 504669a5db4SJeff Garzik and this comes from the current configuration flags */ 505669a5db4SJeff Garzik if (dma_enabled & (1 << (5 + i))) { 506669a5db4SJeff Garzik dev->xfer_mode = XFER_MW_DMA_0; 507669a5db4SJeff Garzik dev->xfer_shift = ATA_SHIFT_MWDMA; 508669a5db4SJeff Garzik dev->flags &= ~ATA_DFLAG_PIO; 509669a5db4SJeff Garzik } else { 510669a5db4SJeff Garzik dev->xfer_mode = XFER_PIO_0; 511669a5db4SJeff Garzik dev->xfer_shift = ATA_SHIFT_PIO; 512669a5db4SJeff Garzik dev->flags |= ATA_DFLAG_PIO; 513669a5db4SJeff Garzik } 514669a5db4SJeff Garzik } 515669a5db4SJeff Garzik } 516b229a7b0SAlan return 0; 517669a5db4SJeff Garzik } 518669a5db4SJeff Garzik 519669a5db4SJeff Garzik /** 520669a5db4SJeff Garzik * it821x_dev_config - Called each device identify 521669a5db4SJeff Garzik * @ap: ATA port 522669a5db4SJeff Garzik * @adev: Device that has just been identified 523669a5db4SJeff Garzik * 524669a5db4SJeff Garzik * Perform the initial setup needed for each device that is chip 525669a5db4SJeff Garzik * special. In our case we need to lock the sector count to avoid 526669a5db4SJeff Garzik * blowing the brains out of the firmware with large LBA48 requests 527669a5db4SJeff Garzik * 528669a5db4SJeff Garzik * FIXME: When FUA appears we need to block FUA too. And SMART and 529669a5db4SJeff Garzik * basically we need to filter commands for this chip. 530669a5db4SJeff Garzik */ 531669a5db4SJeff Garzik 532669a5db4SJeff Garzik static void it821x_dev_config(struct ata_port *ap, struct ata_device *adev) 533669a5db4SJeff Garzik { 5348bfa79fcSTejun Heo unsigned char model_num[ATA_ID_PROD_LEN + 1]; 535669a5db4SJeff Garzik 5368bfa79fcSTejun Heo ata_id_c_string(adev->id, model_num, ATA_ID_PROD, sizeof(model_num)); 537669a5db4SJeff Garzik 538669a5db4SJeff Garzik if (adev->max_sectors > 255) 539669a5db4SJeff Garzik adev->max_sectors = 255; 540669a5db4SJeff Garzik 541669a5db4SJeff Garzik if (strstr(model_num, "Integrated Technology Express")) { 542669a5db4SJeff Garzik /* RAID mode */ 543669a5db4SJeff Garzik printk(KERN_INFO "IT821x %sRAID%d volume", 544669a5db4SJeff Garzik adev->id[147]?"Bootable ":"", 545669a5db4SJeff Garzik adev->id[129]); 546669a5db4SJeff Garzik if (adev->id[129] != 1) 547669a5db4SJeff Garzik printk("(%dK stripe)", adev->id[146]); 548669a5db4SJeff Garzik printk(".\n"); 549669a5db4SJeff Garzik } 550669a5db4SJeff Garzik } 551669a5db4SJeff Garzik 552669a5db4SJeff Garzik 553669a5db4SJeff Garzik /** 554669a5db4SJeff Garzik * it821x_check_atapi_dma - ATAPI DMA handler 555669a5db4SJeff Garzik * @qc: Command we are about to issue 556669a5db4SJeff Garzik * 557669a5db4SJeff Garzik * Decide if this ATAPI command can be issued by DMA on this 558669a5db4SJeff Garzik * controller. Return 0 if it can be. 559669a5db4SJeff Garzik */ 560669a5db4SJeff Garzik 561669a5db4SJeff Garzik static int it821x_check_atapi_dma(struct ata_queued_cmd *qc) 562669a5db4SJeff Garzik { 563669a5db4SJeff Garzik struct ata_port *ap = qc->ap; 564669a5db4SJeff Garzik struct it821x_dev *itdev = ap->private_data; 565669a5db4SJeff Garzik 566669a5db4SJeff Garzik /* No ATAPI DMA in smart mode */ 567669a5db4SJeff Garzik if (itdev->smart) 568669a5db4SJeff Garzik return -EOPNOTSUPP; 569669a5db4SJeff Garzik /* No ATAPI DMA on rev 10 */ 570669a5db4SJeff Garzik if (itdev->timing10) 571669a5db4SJeff Garzik return -EOPNOTSUPP; 572669a5db4SJeff Garzik /* Cool */ 573669a5db4SJeff Garzik return 0; 574669a5db4SJeff Garzik } 575669a5db4SJeff Garzik 576669a5db4SJeff Garzik 577669a5db4SJeff Garzik /** 578669a5db4SJeff Garzik * it821x_port_start - port setup 579669a5db4SJeff Garzik * @ap: ATA port being set up 580669a5db4SJeff Garzik * 581669a5db4SJeff Garzik * The it821x needs to maintain private data structures and also to 582669a5db4SJeff Garzik * use the standard PCI interface which lacks support for this 583669a5db4SJeff Garzik * functionality. We instead set up the private data on the port 584669a5db4SJeff Garzik * start hook, and tear it down on port stop 585669a5db4SJeff Garzik */ 586669a5db4SJeff Garzik 587669a5db4SJeff Garzik static int it821x_port_start(struct ata_port *ap) 588669a5db4SJeff Garzik { 589669a5db4SJeff Garzik struct pci_dev *pdev = to_pci_dev(ap->host->dev); 590669a5db4SJeff Garzik struct it821x_dev *itdev; 591669a5db4SJeff Garzik u8 conf; 592669a5db4SJeff Garzik 593669a5db4SJeff Garzik int ret = ata_port_start(ap); 594669a5db4SJeff Garzik if (ret < 0) 595669a5db4SJeff Garzik return ret; 596669a5db4SJeff Garzik 597*24dc5f33STejun Heo itdev = devm_kzalloc(&pdev->dev, sizeof(struct it821x_dev), GFP_KERNEL); 598*24dc5f33STejun Heo if (itdev == NULL) 599669a5db4SJeff Garzik return -ENOMEM; 600*24dc5f33STejun Heo ap->private_data = itdev; 601669a5db4SJeff Garzik 602669a5db4SJeff Garzik pci_read_config_byte(pdev, 0x50, &conf); 603669a5db4SJeff Garzik 604669a5db4SJeff Garzik if (conf & 1) { 605669a5db4SJeff Garzik itdev->smart = 1; 606669a5db4SJeff Garzik /* Long I/O's although allowed in LBA48 space cause the 607669a5db4SJeff Garzik onboard firmware to enter the twighlight zone */ 608669a5db4SJeff Garzik /* No ATAPI DMA in this mode either */ 609669a5db4SJeff Garzik } 610669a5db4SJeff Garzik /* Pull the current clocks from 0x50 */ 611669a5db4SJeff Garzik if (conf & (1 << (1 + ap->port_no))) 612669a5db4SJeff Garzik itdev->clock_mode = ATA_50; 613669a5db4SJeff Garzik else 614669a5db4SJeff Garzik itdev->clock_mode = ATA_66; 615669a5db4SJeff Garzik 616669a5db4SJeff Garzik itdev->want[0][1] = ATA_ANY; 617669a5db4SJeff Garzik itdev->want[1][1] = ATA_ANY; 618669a5db4SJeff Garzik itdev->last_device = -1; 619669a5db4SJeff Garzik 620669a5db4SJeff Garzik pci_read_config_byte(pdev, PCI_REVISION_ID, &conf); 621669a5db4SJeff Garzik if (conf == 0x10) { 622669a5db4SJeff Garzik itdev->timing10 = 1; 623669a5db4SJeff Garzik /* Need to disable ATAPI DMA for this case */ 624669a5db4SJeff Garzik if (!itdev->smart) 625669a5db4SJeff Garzik printk(KERN_WARNING DRV_NAME": Revision 0x10, workarounds activated.\n"); 626669a5db4SJeff Garzik } 627669a5db4SJeff Garzik 628669a5db4SJeff Garzik return 0; 629669a5db4SJeff Garzik } 630669a5db4SJeff Garzik 631669a5db4SJeff Garzik static struct scsi_host_template it821x_sht = { 632669a5db4SJeff Garzik .module = THIS_MODULE, 633669a5db4SJeff Garzik .name = DRV_NAME, 634669a5db4SJeff Garzik .ioctl = ata_scsi_ioctl, 635669a5db4SJeff Garzik .queuecommand = ata_scsi_queuecmd, 636669a5db4SJeff Garzik .can_queue = ATA_DEF_QUEUE, 637669a5db4SJeff Garzik .this_id = ATA_SHT_THIS_ID, 638669a5db4SJeff Garzik .sg_tablesize = LIBATA_MAX_PRD, 639669a5db4SJeff Garzik .cmd_per_lun = ATA_SHT_CMD_PER_LUN, 640669a5db4SJeff Garzik .emulated = ATA_SHT_EMULATED, 641669a5db4SJeff Garzik .use_clustering = ATA_SHT_USE_CLUSTERING, 642669a5db4SJeff Garzik .proc_name = DRV_NAME, 643669a5db4SJeff Garzik .dma_boundary = ATA_DMA_BOUNDARY, 644669a5db4SJeff Garzik .slave_configure = ata_scsi_slave_config, 645afdfe899STejun Heo .slave_destroy = ata_scsi_slave_destroy, 646669a5db4SJeff Garzik .bios_param = ata_std_bios_param, 647f535d53fSAlan .resume = ata_scsi_device_resume, 648f535d53fSAlan .suspend = ata_scsi_device_suspend, 649669a5db4SJeff Garzik }; 650669a5db4SJeff Garzik 651669a5db4SJeff Garzik static struct ata_port_operations it821x_smart_port_ops = { 652669a5db4SJeff Garzik .set_mode = it821x_smart_set_mode, 653669a5db4SJeff Garzik .port_disable = ata_port_disable, 654669a5db4SJeff Garzik .tf_load = ata_tf_load, 655669a5db4SJeff Garzik .tf_read = ata_tf_read, 656669a5db4SJeff Garzik .mode_filter = ata_pci_default_filter, 657669a5db4SJeff Garzik 658669a5db4SJeff Garzik .check_status = ata_check_status, 659669a5db4SJeff Garzik .check_atapi_dma= it821x_check_atapi_dma, 660669a5db4SJeff Garzik .exec_command = ata_exec_command, 661669a5db4SJeff Garzik .dev_select = ata_std_dev_select, 662669a5db4SJeff Garzik .dev_config = it821x_dev_config, 663669a5db4SJeff Garzik 664669a5db4SJeff Garzik .freeze = ata_bmdma_freeze, 665669a5db4SJeff Garzik .thaw = ata_bmdma_thaw, 666669a5db4SJeff Garzik .error_handler = it821x_error_handler, 667669a5db4SJeff Garzik .post_internal_cmd = ata_bmdma_post_internal_cmd, 668669a5db4SJeff Garzik 669669a5db4SJeff Garzik .bmdma_setup = ata_bmdma_setup, 670669a5db4SJeff Garzik .bmdma_start = ata_bmdma_start, 671669a5db4SJeff Garzik .bmdma_stop = ata_bmdma_stop, 672669a5db4SJeff Garzik .bmdma_status = ata_bmdma_status, 673669a5db4SJeff Garzik 674669a5db4SJeff Garzik .qc_prep = ata_qc_prep, 675669a5db4SJeff Garzik .qc_issue = it821x_smart_qc_issue_prot, 676bda30288SJeff Garzik 677669a5db4SJeff Garzik .data_xfer = ata_pio_data_xfer, 678669a5db4SJeff Garzik 679669a5db4SJeff Garzik .irq_handler = ata_interrupt, 680669a5db4SJeff Garzik .irq_clear = ata_bmdma_irq_clear, 681669a5db4SJeff Garzik 682669a5db4SJeff Garzik .port_start = it821x_port_start, 683669a5db4SJeff Garzik }; 684669a5db4SJeff Garzik 685669a5db4SJeff Garzik static struct ata_port_operations it821x_passthru_port_ops = { 686669a5db4SJeff Garzik .port_disable = ata_port_disable, 687669a5db4SJeff Garzik .set_piomode = it821x_passthru_set_piomode, 688669a5db4SJeff Garzik .set_dmamode = it821x_passthru_set_dmamode, 689669a5db4SJeff Garzik .mode_filter = ata_pci_default_filter, 690669a5db4SJeff Garzik 691669a5db4SJeff Garzik .tf_load = ata_tf_load, 692669a5db4SJeff Garzik .tf_read = ata_tf_read, 693669a5db4SJeff Garzik .check_status = ata_check_status, 694669a5db4SJeff Garzik .exec_command = ata_exec_command, 695669a5db4SJeff Garzik .check_atapi_dma= it821x_check_atapi_dma, 696669a5db4SJeff Garzik .dev_select = it821x_passthru_dev_select, 697669a5db4SJeff Garzik 698669a5db4SJeff Garzik .freeze = ata_bmdma_freeze, 699669a5db4SJeff Garzik .thaw = ata_bmdma_thaw, 700669a5db4SJeff Garzik .error_handler = it821x_error_handler, 701669a5db4SJeff Garzik .post_internal_cmd = ata_bmdma_post_internal_cmd, 702669a5db4SJeff Garzik 703669a5db4SJeff Garzik .bmdma_setup = ata_bmdma_setup, 704669a5db4SJeff Garzik .bmdma_start = it821x_passthru_bmdma_start, 705669a5db4SJeff Garzik .bmdma_stop = it821x_passthru_bmdma_stop, 706669a5db4SJeff Garzik .bmdma_status = ata_bmdma_status, 707669a5db4SJeff Garzik 708669a5db4SJeff Garzik .qc_prep = ata_qc_prep, 709669a5db4SJeff Garzik .qc_issue = it821x_passthru_qc_issue_prot, 710bda30288SJeff Garzik 711669a5db4SJeff Garzik .data_xfer = ata_pio_data_xfer, 712669a5db4SJeff Garzik 713669a5db4SJeff Garzik .irq_clear = ata_bmdma_irq_clear, 714669a5db4SJeff Garzik .irq_handler = ata_interrupt, 715669a5db4SJeff Garzik 716669a5db4SJeff Garzik .port_start = it821x_port_start, 717669a5db4SJeff Garzik }; 718669a5db4SJeff Garzik 719669a5db4SJeff Garzik static void __devinit it821x_disable_raid(struct pci_dev *pdev) 720669a5db4SJeff Garzik { 721669a5db4SJeff Garzik /* Reset local CPU, and set BIOS not ready */ 722669a5db4SJeff Garzik pci_write_config_byte(pdev, 0x5E, 0x01); 723669a5db4SJeff Garzik 724669a5db4SJeff Garzik /* Set to bypass mode, and reset PCI bus */ 725669a5db4SJeff Garzik pci_write_config_byte(pdev, 0x50, 0x00); 726669a5db4SJeff Garzik pci_write_config_word(pdev, PCI_COMMAND, 727669a5db4SJeff Garzik PCI_COMMAND_PARITY | PCI_COMMAND_IO | 728669a5db4SJeff Garzik PCI_COMMAND_MEMORY | PCI_COMMAND_MASTER); 729669a5db4SJeff Garzik pci_write_config_word(pdev, 0x40, 0xA0F3); 730669a5db4SJeff Garzik 731669a5db4SJeff Garzik pci_write_config_dword(pdev,0x4C, 0x02040204); 732669a5db4SJeff Garzik pci_write_config_byte(pdev, 0x42, 0x36); 733669a5db4SJeff Garzik pci_write_config_byte(pdev, PCI_LATENCY_TIMER, 0x20); 734669a5db4SJeff Garzik } 735669a5db4SJeff Garzik 736669a5db4SJeff Garzik 737669a5db4SJeff Garzik static int it821x_init_one(struct pci_dev *pdev, const struct pci_device_id *id) 738669a5db4SJeff Garzik { 739669a5db4SJeff Garzik u8 conf; 740669a5db4SJeff Garzik 741669a5db4SJeff Garzik static struct ata_port_info info_smart = { 742669a5db4SJeff Garzik .sht = &it821x_sht, 743669a5db4SJeff Garzik .flags = ATA_FLAG_SLAVE_POSS | ATA_FLAG_SRST, 744669a5db4SJeff Garzik .pio_mask = 0x1f, 745669a5db4SJeff Garzik .mwdma_mask = 0x07, 746669a5db4SJeff Garzik .port_ops = &it821x_smart_port_ops 747669a5db4SJeff Garzik }; 748669a5db4SJeff Garzik static struct ata_port_info info_passthru = { 749669a5db4SJeff Garzik .sht = &it821x_sht, 750669a5db4SJeff Garzik .flags = ATA_FLAG_SLAVE_POSS | ATA_FLAG_SRST, 751669a5db4SJeff Garzik .pio_mask = 0x1f, 752669a5db4SJeff Garzik .mwdma_mask = 0x07, 753669a5db4SJeff Garzik .udma_mask = 0x7f, 754669a5db4SJeff Garzik .port_ops = &it821x_passthru_port_ops 755669a5db4SJeff Garzik }; 756669a5db4SJeff Garzik static struct ata_port_info *port_info[2]; 757669a5db4SJeff Garzik 758669a5db4SJeff Garzik static char *mode[2] = { "pass through", "smart" }; 759669a5db4SJeff Garzik 760669a5db4SJeff Garzik /* Force the card into bypass mode if so requested */ 761669a5db4SJeff Garzik if (it8212_noraid) { 762669a5db4SJeff Garzik printk(KERN_INFO DRV_NAME ": forcing bypass mode.\n"); 763669a5db4SJeff Garzik it821x_disable_raid(pdev); 764669a5db4SJeff Garzik } 765669a5db4SJeff Garzik pci_read_config_byte(pdev, 0x50, &conf); 766669a5db4SJeff Garzik conf &= 1; 767669a5db4SJeff Garzik 768669a5db4SJeff Garzik printk(KERN_INFO DRV_NAME ": controller in %s mode.\n", mode[conf]); 769669a5db4SJeff Garzik if (conf == 0) 770669a5db4SJeff Garzik port_info[0] = port_info[1] = &info_passthru; 771669a5db4SJeff Garzik else 772669a5db4SJeff Garzik port_info[0] = port_info[1] = &info_smart; 773669a5db4SJeff Garzik 774669a5db4SJeff Garzik return ata_pci_init_one(pdev, port_info, 2); 775669a5db4SJeff Garzik } 776669a5db4SJeff Garzik 777f535d53fSAlan static int it821x_reinit_one(struct pci_dev *pdev) 778f535d53fSAlan { 779f535d53fSAlan /* Resume - turn raid back off if need be */ 780f535d53fSAlan if (it8212_noraid) 781f535d53fSAlan it821x_disable_raid(pdev); 782f535d53fSAlan return ata_pci_device_resume(pdev); 783f535d53fSAlan } 784f535d53fSAlan 7852d2744fcSJeff Garzik static const struct pci_device_id it821x[] = { 7862d2744fcSJeff Garzik { PCI_VDEVICE(ITE, PCI_DEVICE_ID_ITE_8211), }, 7872d2744fcSJeff Garzik { PCI_VDEVICE(ITE, PCI_DEVICE_ID_ITE_8212), }, 7882d2744fcSJeff Garzik 7892d2744fcSJeff Garzik { }, 790669a5db4SJeff Garzik }; 791669a5db4SJeff Garzik 792669a5db4SJeff Garzik static struct pci_driver it821x_pci_driver = { 793669a5db4SJeff Garzik .name = DRV_NAME, 794669a5db4SJeff Garzik .id_table = it821x, 795669a5db4SJeff Garzik .probe = it821x_init_one, 796f535d53fSAlan .remove = ata_pci_remove_one, 797f535d53fSAlan .suspend = ata_pci_device_suspend, 798f535d53fSAlan .resume = it821x_reinit_one, 799669a5db4SJeff Garzik }; 800669a5db4SJeff Garzik 801669a5db4SJeff Garzik static int __init it821x_init(void) 802669a5db4SJeff Garzik { 803669a5db4SJeff Garzik return pci_register_driver(&it821x_pci_driver); 804669a5db4SJeff Garzik } 805669a5db4SJeff Garzik 806669a5db4SJeff Garzik static void __exit it821x_exit(void) 807669a5db4SJeff Garzik { 808669a5db4SJeff Garzik pci_unregister_driver(&it821x_pci_driver); 809669a5db4SJeff Garzik } 810669a5db4SJeff Garzik 811669a5db4SJeff Garzik MODULE_AUTHOR("Alan Cox"); 812669a5db4SJeff Garzik MODULE_DESCRIPTION("low-level driver for the IT8211/IT8212 IDE RAID controller"); 813669a5db4SJeff Garzik MODULE_LICENSE("GPL"); 814669a5db4SJeff Garzik MODULE_DEVICE_TABLE(pci, it821x); 815669a5db4SJeff Garzik MODULE_VERSION(DRV_VERSION); 816669a5db4SJeff Garzik 817669a5db4SJeff Garzik 818669a5db4SJeff Garzik module_param_named(noraid, it8212_noraid, int, S_IRUGO); 819669a5db4SJeff Garzik MODULE_PARM_DESC(it8212_noraid, "Force card into bypass mode"); 820669a5db4SJeff Garzik 821669a5db4SJeff Garzik module_init(it821x_init); 822669a5db4SJeff Garzik module_exit(it821x_exit); 823