opti621.c 7.5 KB

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