Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1 | /* |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2 | * Copyright (C) 1996-1998 Linus Torvalds & authors (see below) |
| 3 | */ |
| 4 | |
| 5 | /* |
| 6 | * Authors: |
| 7 | * Jaromir Koutek <miri@punknet.cz>, |
| 8 | * Jan Harkes <jaharkes@cwi.nl>, |
| 9 | * Mark Lord <mlord@pobox.com> |
| 10 | * Some parts of code are from ali14xx.c and from rz1000.c. |
| 11 | * |
| 12 | * OPTi is trademark of OPTi, Octek is trademark of Octek. |
| 13 | * |
| 14 | * I used docs from OPTi databook, from ftp.opti.com, file 9123-0002.ps |
| 15 | * and disassembled/traced setupvic.exe (DOS program). |
| 16 | * It increases kernel code about 2 kB. |
| 17 | * I don't have this card no more, but I hope I can get some in case |
| 18 | * of needed development. |
| 19 | * My card is Octek PIDE 1.01 (on card) or OPTiViC (program). |
| 20 | * It has a place for a secondary connector in circuit, but nothing |
| 21 | * is there. Also BIOS says no address for |
| 22 | * secondary controller (see bellow in ide_init_opti621). |
| 23 | * I've only tested this on my system, which only has one disk. |
| 24 | * It's Western Digital WDAC2850, with PIO mode 3. The PCI bus |
| 25 | * is at 20 MHz (I have DX2/80, I tried PCI at 40, but I got random |
| 26 | * lockups). I tried the OCTEK double speed CD-ROM and |
| 27 | * it does not work! But I can't boot DOS also, so it's probably |
| 28 | * hardware fault. I have connected Conner 80MB, the Seagate 850MB (no |
| 29 | * problems) and Seagate 1GB (as slave, WD as master). My experiences |
| 30 | * with the third, 1GB drive: I got 3MB/s (hdparm), but sometimes |
| 31 | * it slows to about 100kB/s! I don't know why and I have |
| 32 | * not this drive now, so I can't try it again. |
| 33 | * I write this driver because I lost the paper ("manual") with |
| 34 | * settings of jumpers on the card and I have to boot Linux with |
| 35 | * Loadlin except LILO, cause I have to run the setupvic.exe program |
| 36 | * already or I get disk errors (my test: rpm -Vf |
| 37 | * /usr/X11R6/bin/XF86_SVGA - or any big file). |
| 38 | * Some numbers from hdparm -t /dev/hda: |
| 39 | * Timing buffer-cache reads: 32 MB in 3.02 seconds =10.60 MB/sec |
| 40 | * Timing buffered disk reads: 16 MB in 5.52 seconds = 2.90 MB/sec |
| 41 | * I have 4 Megs/s before, but I don't know why (maybe changes |
| 42 | * in hdparm test). |
| 43 | * After release of 0.1, I got some successful reports, so it might work. |
| 44 | * |
| 45 | * The main problem with OPTi is that some timings for master |
| 46 | * and slave must be the same. For example, if you have master |
| 47 | * PIO 3 and slave PIO 0, driver have to set some timings of |
Bartlomiej Zolnierkiewicz | 26bcb87 | 2007-10-11 23:54:00 +0200 | [diff] [blame] | 48 | * master for PIO 0. Second problem is that opti621_set_pio_mode |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 49 | * got only one drive to set, but have to set both drives. |
| 50 | * This is solved in compute_pios. If you don't set |
| 51 | * the second drive, compute_pios use ide_get_best_pio_mode |
| 52 | * for autoselect mode (you can change it to PIO 0, if you want). |
| 53 | * If you then set the second drive to another PIO, the old value |
| 54 | * (automatically selected) will be overrided by yours. |
| 55 | * There is a 25/33MHz switch in configuration |
Bartlomiej Zolnierkiewicz | 73f1ad8 | 2008-04-27 15:38:29 +0200 | [diff] [blame] | 56 | * register, but driver is written for use at any frequency. |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 57 | * |
| 58 | * Version 0.1, Nov 8, 1996 |
Paolo Ciarrocchi | 4eb68a2 | 2008-04-26 17:36:41 +0200 | [diff] [blame] | 59 | * by Jaromir Koutek, for 2.1.8. |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 60 | * Initial version of driver. |
Paolo Ciarrocchi | 4eb68a2 | 2008-04-26 17:36:41 +0200 | [diff] [blame] | 61 | * |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 62 | * Version 0.2 |
| 63 | * Number 0.2 skipped. |
| 64 | * |
| 65 | * Version 0.3, Nov 29, 1997 |
| 66 | * by Mark Lord (probably), for 2.1.68 |
| 67 | * Updates for use with new IDE block driver. |
| 68 | * |
| 69 | * Version 0.4, Dec 14, 1997 |
| 70 | * by Jan Harkes |
| 71 | * Fixed some errors and cleaned the code. |
| 72 | * |
| 73 | * Version 0.5, Jan 2, 1998 |
| 74 | * by Jaromir Koutek |
| 75 | * Updates for use with (again) new IDE block driver. |
| 76 | * Update of documentation. |
Paolo Ciarrocchi | 4eb68a2 | 2008-04-26 17:36:41 +0200 | [diff] [blame] | 77 | * |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 78 | * Version 0.6, Jan 2, 1999 |
| 79 | * by Jaromir Koutek |
| 80 | * Reversed to version 0.3 of the driver, because |
| 81 | * 0.5 doesn't work. |
| 82 | */ |
| 83 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 84 | #include <linux/types.h> |
| 85 | #include <linux/module.h> |
| 86 | #include <linux/kernel.h> |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 87 | #include <linux/pci.h> |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 88 | #include <linux/ide.h> |
| 89 | |
| 90 | #include <asm/io.h> |
| 91 | |
Bartlomiej Zolnierkiewicz | ced3ec8 | 2008-07-24 22:53:32 +0200 | [diff] [blame] | 92 | #define DRV_NAME "opti621" |
| 93 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 94 | #define READ_REG 0 /* index of Read cycle timing register */ |
| 95 | #define WRITE_REG 1 /* index of Write cycle timing register */ |
| 96 | #define CNTRL_REG 3 /* index of Control register */ |
| 97 | #define STRAP_REG 5 /* index of Strap register */ |
| 98 | #define MISC_REG 6 /* index of Miscellaneous register */ |
| 99 | |
| 100 | static int reg_base; |
| 101 | |
Bartlomiej Zolnierkiewicz | e65dde7 | 2007-10-20 00:32:35 +0200 | [diff] [blame] | 102 | static DEFINE_SPINLOCK(opti621_lock); |
| 103 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 104 | /* Write value to register reg, base of register |
| 105 | * is at reg_base (0x1f0 primary, 0x170 secondary, |
| 106 | * if not changed by PCI configuration). |
| 107 | * This is from setupvic.exe program. |
| 108 | */ |
Bartlomiej Zolnierkiewicz | 0ecdca2 | 2007-02-17 02:40:25 +0100 | [diff] [blame] | 109 | static void write_reg(u8 value, int reg) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 110 | { |
Bartlomiej Zolnierkiewicz | 0ecdca2 | 2007-02-17 02:40:25 +0100 | [diff] [blame] | 111 | inw(reg_base + 1); |
| 112 | inw(reg_base + 1); |
| 113 | outb(3, reg_base + 2); |
| 114 | outb(value, reg_base + reg); |
| 115 | outb(0x83, reg_base + 2); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 116 | } |
| 117 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 118 | /* Read value from register reg, base of register |
| 119 | * is at reg_base (0x1f0 primary, 0x170 secondary, |
| 120 | * if not changed by PCI configuration). |
| 121 | * This is from setupvic.exe program. |
| 122 | */ |
Bartlomiej Zolnierkiewicz | 0ecdca2 | 2007-02-17 02:40:25 +0100 | [diff] [blame] | 123 | static u8 read_reg(int reg) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 124 | { |
| 125 | u8 ret = 0; |
| 126 | |
Bartlomiej Zolnierkiewicz | 0ecdca2 | 2007-02-17 02:40:25 +0100 | [diff] [blame] | 127 | inw(reg_base + 1); |
| 128 | inw(reg_base + 1); |
| 129 | outb(3, reg_base + 2); |
| 130 | ret = inb(reg_base + reg); |
| 131 | outb(0x83, reg_base + 2); |
| 132 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 133 | return ret; |
| 134 | } |
| 135 | |
Bartlomiej Zolnierkiewicz | 26bcb87 | 2007-10-11 23:54:00 +0200 | [diff] [blame] | 136 | static void opti621_set_pio_mode(ide_drive_t *drive, const u8 pio) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 137 | { |
Bartlomiej Zolnierkiewicz | 6c98718 | 2008-06-15 21:00:22 +0200 | [diff] [blame] | 138 | ide_hwif_t *hwif = drive->hwif; |
Bartlomiej Zolnierkiewicz | 7e59ea2 | 2008-10-10 22:39:26 +0200 | [diff] [blame] | 139 | ide_drive_t *pair = ide_get_pair_dev(drive); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 140 | unsigned long flags; |
Joao Ramos | 5bfb151f | 2009-06-15 22:13:44 +0200 | [diff] [blame] | 141 | unsigned long mode = XFER_PIO_0 + pio, pair_mode; |
Bartlomiej Zolnierkiewicz | 810253d | 2008-06-15 21:00:22 +0200 | [diff] [blame] | 142 | u8 tim, misc, addr_pio = pio, clk; |
| 143 | |
| 144 | /* DRDY is default 2 (by OPTi Databook) */ |
Bartlomiej Zolnierkiewicz | 80a65fc | 2008-06-15 21:00:22 +0200 | [diff] [blame] | 145 | static const u8 addr_timings[2][5] = { |
| 146 | { 0x20, 0x10, 0x00, 0x00, 0x00 }, /* 33 MHz */ |
| 147 | { 0x10, 0x10, 0x00, 0x00, 0x00 }, /* 25 MHz */ |
Bartlomiej Zolnierkiewicz | 810253d | 2008-06-15 21:00:22 +0200 | [diff] [blame] | 148 | }; |
Bartlomiej Zolnierkiewicz | 80a65fc | 2008-06-15 21:00:22 +0200 | [diff] [blame] | 149 | static const u8 data_rec_timings[2][5] = { |
| 150 | { 0x5b, 0x45, 0x32, 0x21, 0x20 }, /* 33 MHz */ |
| 151 | { 0x48, 0x34, 0x21, 0x10, 0x10 } /* 25 MHz */ |
Bartlomiej Zolnierkiewicz | 810253d | 2008-06-15 21:00:22 +0200 | [diff] [blame] | 152 | }; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 153 | |
Joao Ramos | 5bfb151f | 2009-06-15 22:13:44 +0200 | [diff] [blame] | 154 | ide_set_drivedata(drive, (void *)mode); |
Bartlomiej Zolnierkiewicz | 6c98718 | 2008-06-15 21:00:22 +0200 | [diff] [blame] | 155 | |
Bartlomiej Zolnierkiewicz | 7e59ea2 | 2008-10-10 22:39:26 +0200 | [diff] [blame] | 156 | if (pair) { |
Joao Ramos | 5bfb151f | 2009-06-15 22:13:44 +0200 | [diff] [blame] | 157 | pair_mode = (unsigned long)ide_get_drivedata(pair); |
| 158 | if (pair_mode && pair_mode < mode) |
| 159 | addr_pio = pair_mode - XFER_PIO_0; |
Bartlomiej Zolnierkiewicz | 6c98718 | 2008-06-15 21:00:22 +0200 | [diff] [blame] | 160 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 161 | |
Bartlomiej Zolnierkiewicz | 21bd33a | 2008-06-15 21:00:22 +0200 | [diff] [blame] | 162 | spin_lock_irqsave(&opti621_lock, flags); |
| 163 | |
| 164 | reg_base = hwif->io_ports.data_addr; |
| 165 | |
| 166 | /* allow Register-B */ |
| 167 | outb(0xc0, reg_base + CNTRL_REG); |
| 168 | /* hmm, setupvic.exe does this ;-) */ |
| 169 | outb(0xff, reg_base + 5); |
| 170 | /* if reads 0xff, adapter not exist? */ |
| 171 | (void)inb(reg_base + CNTRL_REG); |
| 172 | /* if reads 0xc0, no interface exist? */ |
| 173 | read_reg(CNTRL_REG); |
| 174 | |
| 175 | /* check CLK speed */ |
| 176 | clk = read_reg(STRAP_REG) & 1; |
| 177 | |
| 178 | printk(KERN_INFO "%s: CLK = %d MHz\n", hwif->name, clk ? 25 : 33); |
| 179 | |
Bartlomiej Zolnierkiewicz | 810253d | 2008-06-15 21:00:22 +0200 | [diff] [blame] | 180 | tim = data_rec_timings[clk][pio]; |
| 181 | misc = addr_timings[clk][addr_pio]; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 182 | |
Bartlomiej Zolnierkiewicz | 6c98718 | 2008-06-15 21:00:22 +0200 | [diff] [blame] | 183 | /* select Index-0/1 for Register-A/B */ |
Bartlomiej Zolnierkiewicz | 123995b | 2008-10-13 21:39:40 +0200 | [diff] [blame] | 184 | write_reg(drive->dn & 1, MISC_REG); |
Bartlomiej Zolnierkiewicz | 0ecdca2 | 2007-02-17 02:40:25 +0100 | [diff] [blame] | 185 | /* set read cycle timings */ |
Bartlomiej Zolnierkiewicz | 810253d | 2008-06-15 21:00:22 +0200 | [diff] [blame] | 186 | write_reg(tim, READ_REG); |
Bartlomiej Zolnierkiewicz | 0ecdca2 | 2007-02-17 02:40:25 +0100 | [diff] [blame] | 187 | /* set write cycle timings */ |
Bartlomiej Zolnierkiewicz | 810253d | 2008-06-15 21:00:22 +0200 | [diff] [blame] | 188 | write_reg(tim, WRITE_REG); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 189 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 190 | /* use Register-A for drive 0 */ |
| 191 | /* use Register-B for drive 1 */ |
Bartlomiej Zolnierkiewicz | 0ecdca2 | 2007-02-17 02:40:25 +0100 | [diff] [blame] | 192 | write_reg(0x85, CNTRL_REG); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 193 | |
| 194 | /* set address setup, DRDY timings, */ |
| 195 | /* and read prefetch for both drives */ |
Bartlomiej Zolnierkiewicz | 0ecdca2 | 2007-02-17 02:40:25 +0100 | [diff] [blame] | 196 | write_reg(misc, MISC_REG); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 197 | |
Bartlomiej Zolnierkiewicz | e65dde7 | 2007-10-20 00:32:35 +0200 | [diff] [blame] | 198 | spin_unlock_irqrestore(&opti621_lock, flags); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 199 | } |
| 200 | |
Bartlomiej Zolnierkiewicz | ac95bee | 2008-04-26 22:25:14 +0200 | [diff] [blame] | 201 | static const struct ide_port_ops opti621_port_ops = { |
Bartlomiej Zolnierkiewicz | ac95bee | 2008-04-26 22:25:14 +0200 | [diff] [blame] | 202 | .set_pio_mode = opti621_set_pio_mode, |
| 203 | }; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 204 | |
Bartlomiej Zolnierkiewicz | 80a65fc | 2008-06-15 21:00:22 +0200 | [diff] [blame] | 205 | static const struct ide_port_info opti621_chipset __devinitdata = { |
Bartlomiej Zolnierkiewicz | ced3ec8 | 2008-07-24 22:53:32 +0200 | [diff] [blame] | 206 | .name = DRV_NAME, |
Bartlomiej Zolnierkiewicz | 80a65fc | 2008-06-15 21:00:22 +0200 | [diff] [blame] | 207 | .enablebits = { {0x45, 0x80, 0x00}, {0x40, 0x08, 0x00} }, |
| 208 | .port_ops = &opti621_port_ops, |
| 209 | .host_flags = IDE_HFLAG_NO_DMA, |
| 210 | .pio_mask = ATA_PIO4, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 211 | }; |
| 212 | |
| 213 | static int __devinit opti621_init_one(struct pci_dev *dev, const struct pci_device_id *id) |
| 214 | { |
Bartlomiej Zolnierkiewicz | 6cdf6eb | 2008-07-24 22:53:14 +0200 | [diff] [blame] | 215 | return ide_pci_init_one(dev, &opti621_chipset, NULL); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 216 | } |
| 217 | |
Bartlomiej Zolnierkiewicz | 9cbcc5e | 2007-10-16 22:29:56 +0200 | [diff] [blame] | 218 | static const struct pci_device_id opti621_pci_tbl[] = { |
| 219 | { PCI_VDEVICE(OPTI, PCI_DEVICE_ID_OPTI_82C621), 0 }, |
Bartlomiej Zolnierkiewicz | 80a65fc | 2008-06-15 21:00:22 +0200 | [diff] [blame] | 220 | { PCI_VDEVICE(OPTI, PCI_DEVICE_ID_OPTI_82C825), 0 }, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 221 | { 0, }, |
| 222 | }; |
| 223 | MODULE_DEVICE_TABLE(pci, opti621_pci_tbl); |
| 224 | |
Bartlomiej Zolnierkiewicz | a9ab09e2 | 2008-10-13 21:39:41 +0200 | [diff] [blame] | 225 | static struct pci_driver opti621_pci_driver = { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 226 | .name = "Opti621_IDE", |
| 227 | .id_table = opti621_pci_tbl, |
| 228 | .probe = opti621_init_one, |
Bartlomiej Zolnierkiewicz | adc7f85 | 2008-07-24 22:53:23 +0200 | [diff] [blame] | 229 | .remove = ide_pci_remove, |
Bartlomiej Zolnierkiewicz | feb22b7 | 2008-10-10 22:39:32 +0200 | [diff] [blame] | 230 | .suspend = ide_pci_suspend, |
| 231 | .resume = ide_pci_resume, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 232 | }; |
| 233 | |
Bartlomiej Zolnierkiewicz | 82ab1ee | 2007-01-27 13:46:56 +0100 | [diff] [blame] | 234 | static int __init opti621_ide_init(void) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 235 | { |
Bartlomiej Zolnierkiewicz | a9ab09e2 | 2008-10-13 21:39:41 +0200 | [diff] [blame] | 236 | return ide_pci_register_driver(&opti621_pci_driver); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 237 | } |
| 238 | |
Bartlomiej Zolnierkiewicz | adc7f85 | 2008-07-24 22:53:23 +0200 | [diff] [blame] | 239 | static void __exit opti621_ide_exit(void) |
| 240 | { |
Bartlomiej Zolnierkiewicz | a9ab09e2 | 2008-10-13 21:39:41 +0200 | [diff] [blame] | 241 | pci_unregister_driver(&opti621_pci_driver); |
Bartlomiej Zolnierkiewicz | adc7f85 | 2008-07-24 22:53:23 +0200 | [diff] [blame] | 242 | } |
| 243 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 244 | module_init(opti621_ide_init); |
Bartlomiej Zolnierkiewicz | adc7f85 | 2008-07-24 22:53:23 +0200 | [diff] [blame] | 245 | module_exit(opti621_ide_exit); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 246 | |
| 247 | MODULE_AUTHOR("Jaromir Koutek, Jan Harkes, Mark Lord"); |
| 248 | MODULE_DESCRIPTION("PCI driver module for Opti621 IDE"); |
| 249 | MODULE_LICENSE("GPL"); |