pdc202xx_old.c 13 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473
  1. /*
  2. * linux/drivers/ide/pci/pdc202xx_old.c Version 0.52 Aug 27, 2007
  3. *
  4. * Copyright (C) 1998-2002 Andre Hedrick <andre@linux-ide.org>
  5. * Copyright (C) 2006-2007 MontaVista Software, Inc.
  6. * Copyright (C) 2007 Bartlomiej Zolnierkiewicz
  7. *
  8. * Promise Ultra33 cards with BIOS v1.20 through 1.28 will need this
  9. * compiled into the kernel if you have more than one card installed.
  10. * Note that BIOS v1.29 is reported to fix the problem. Since this is
  11. * safe chipset tuning, including this support is harmless
  12. *
  13. * Promise Ultra66 cards with BIOS v1.11 this
  14. * compiled into the kernel if you have more than one card installed.
  15. *
  16. * Promise Ultra100 cards.
  17. *
  18. * The latest chipset code will support the following ::
  19. * Three Ultra33 controllers and 12 drives.
  20. * 8 are UDMA supported and 4 are limited to DMA mode 2 multi-word.
  21. * The 8/4 ratio is a BIOS code limit by promise.
  22. *
  23. * UNLESS you enable "CONFIG_PDC202XX_BURST"
  24. *
  25. */
  26. /*
  27. * Portions Copyright (C) 1999 Promise Technology, Inc.
  28. * Author: Frank Tiernan (frankt@promise.com)
  29. * Released under terms of General Public License
  30. */
  31. #include <linux/types.h>
  32. #include <linux/module.h>
  33. #include <linux/kernel.h>
  34. #include <linux/delay.h>
  35. #include <linux/timer.h>
  36. #include <linux/mm.h>
  37. #include <linux/ioport.h>
  38. #include <linux/blkdev.h>
  39. #include <linux/hdreg.h>
  40. #include <linux/interrupt.h>
  41. #include <linux/pci.h>
  42. #include <linux/init.h>
  43. #include <linux/ide.h>
  44. #include <asm/io.h>
  45. #include <asm/irq.h>
  46. #define PDC202XX_DEBUG_DRIVE_INFO 0
  47. static const char *pdc_quirk_drives[] = {
  48. "QUANTUM FIREBALLlct08 08",
  49. "QUANTUM FIREBALLP KA6.4",
  50. "QUANTUM FIREBALLP KA9.1",
  51. "QUANTUM FIREBALLP LM20.4",
  52. "QUANTUM FIREBALLP KX13.6",
  53. "QUANTUM FIREBALLP KX20.5",
  54. "QUANTUM FIREBALLP KX27.3",
  55. "QUANTUM FIREBALLP LM20.5",
  56. NULL
  57. };
  58. static void pdc_old_disable_66MHz_clock(ide_hwif_t *);
  59. static void pdc202xx_set_mode(ide_drive_t *drive, const u8 speed)
  60. {
  61. ide_hwif_t *hwif = HWIF(drive);
  62. struct pci_dev *dev = hwif->pci_dev;
  63. u8 drive_pci = 0x60 + (drive->dn << 2);
  64. u8 AP = 0, BP = 0, CP = 0;
  65. u8 TA = 0, TB = 0, TC = 0;
  66. #if PDC202XX_DEBUG_DRIVE_INFO
  67. u32 drive_conf = 0;
  68. pci_read_config_dword(dev, drive_pci, &drive_conf);
  69. #endif
  70. /*
  71. * TODO: do this once per channel
  72. */
  73. if (dev->device != PCI_DEVICE_ID_PROMISE_20246)
  74. pdc_old_disable_66MHz_clock(hwif);
  75. pci_read_config_byte(dev, drive_pci, &AP);
  76. pci_read_config_byte(dev, drive_pci + 1, &BP);
  77. pci_read_config_byte(dev, drive_pci + 2, &CP);
  78. switch(speed) {
  79. case XFER_UDMA_5:
  80. case XFER_UDMA_4: TB = 0x20; TC = 0x01; break;
  81. case XFER_UDMA_2: TB = 0x20; TC = 0x01; break;
  82. case XFER_UDMA_3:
  83. case XFER_UDMA_1: TB = 0x40; TC = 0x02; break;
  84. case XFER_UDMA_0:
  85. case XFER_MW_DMA_2: TB = 0x60; TC = 0x03; break;
  86. case XFER_MW_DMA_1: TB = 0x60; TC = 0x04; break;
  87. case XFER_MW_DMA_0: TB = 0xE0; TC = 0x0F; break;
  88. case XFER_PIO_4: TA = 0x01; TB = 0x04; break;
  89. case XFER_PIO_3: TA = 0x02; TB = 0x06; break;
  90. case XFER_PIO_2: TA = 0x03; TB = 0x08; break;
  91. case XFER_PIO_1: TA = 0x05; TB = 0x0C; break;
  92. case XFER_PIO_0:
  93. default: TA = 0x09; TB = 0x13; break;
  94. }
  95. if (speed < XFER_SW_DMA_0) {
  96. /*
  97. * preserve SYNC_INT / ERDDY_EN bits while clearing
  98. * Prefetch_EN / IORDY_EN / PA[3:0] bits of register A
  99. */
  100. AP &= ~0x3f;
  101. if (drive->id->capability & 4)
  102. AP |= 0x20; /* set IORDY_EN bit */
  103. if (drive->media == ide_disk)
  104. AP |= 0x10; /* set Prefetch_EN bit */
  105. /* clear PB[4:0] bits of register B */
  106. BP &= ~0x1f;
  107. pci_write_config_byte(dev, drive_pci, AP | TA);
  108. pci_write_config_byte(dev, drive_pci + 1, BP | TB);
  109. } else {
  110. /* clear MB[2:0] bits of register B */
  111. BP &= ~0xe0;
  112. /* clear MC[3:0] bits of register C */
  113. CP &= ~0x0f;
  114. pci_write_config_byte(dev, drive_pci + 1, BP | TB);
  115. pci_write_config_byte(dev, drive_pci + 2, CP | TC);
  116. }
  117. #if PDC202XX_DEBUG_DRIVE_INFO
  118. printk(KERN_DEBUG "%s: %s drive%d 0x%08x ",
  119. drive->name, ide_xfer_verbose(speed),
  120. drive->dn, drive_conf);
  121. pci_read_config_dword(dev, drive_pci, &drive_conf);
  122. printk("0x%08x\n", drive_conf);
  123. #endif
  124. }
  125. static void pdc202xx_set_pio_mode(ide_drive_t *drive, const u8 pio)
  126. {
  127. pdc202xx_set_mode(drive, XFER_PIO_0 + pio);
  128. }
  129. static u8 pdc202xx_old_cable_detect (ide_hwif_t *hwif)
  130. {
  131. u16 CIS = 0, mask = (hwif->channel) ? (1<<11) : (1<<10);
  132. pci_read_config_word(hwif->pci_dev, 0x50, &CIS);
  133. return (CIS & mask) ? ATA_CBL_PATA40 : ATA_CBL_PATA80;
  134. }
  135. /*
  136. * Set the control register to use the 66MHz system
  137. * clock for UDMA 3/4/5 mode operation when necessary.
  138. *
  139. * FIXME: this register is shared by both channels, some locking is needed
  140. *
  141. * It may also be possible to leave the 66MHz clock on
  142. * and readjust the timing parameters.
  143. */
  144. static void pdc_old_enable_66MHz_clock(ide_hwif_t *hwif)
  145. {
  146. unsigned long clock_reg = hwif->dma_master + 0x11;
  147. u8 clock = inb(clock_reg);
  148. outb(clock | (hwif->channel ? 0x08 : 0x02), clock_reg);
  149. }
  150. static void pdc_old_disable_66MHz_clock(ide_hwif_t *hwif)
  151. {
  152. unsigned long clock_reg = hwif->dma_master + 0x11;
  153. u8 clock = inb(clock_reg);
  154. outb(clock & ~(hwif->channel ? 0x08 : 0x02), clock_reg);
  155. }
  156. static int pdc202xx_quirkproc (ide_drive_t *drive)
  157. {
  158. const char **list, *model = drive->id->model;
  159. for (list = pdc_quirk_drives; *list != NULL; list++)
  160. if (strstr(model, *list) != NULL)
  161. return 2;
  162. return 0;
  163. }
  164. static void pdc202xx_old_ide_dma_start(ide_drive_t *drive)
  165. {
  166. if (drive->current_speed > XFER_UDMA_2)
  167. pdc_old_enable_66MHz_clock(drive->hwif);
  168. if (drive->media != ide_disk || drive->addressing == 1) {
  169. struct request *rq = HWGROUP(drive)->rq;
  170. ide_hwif_t *hwif = HWIF(drive);
  171. unsigned long high_16 = hwif->dma_master;
  172. unsigned long atapi_reg = high_16 + (hwif->channel ? 0x24 : 0x20);
  173. u32 word_count = 0;
  174. u8 clock = inb(high_16 + 0x11);
  175. outb(clock | (hwif->channel ? 0x08 : 0x02), high_16 + 0x11);
  176. word_count = (rq->nr_sectors << 8);
  177. word_count = (rq_data_dir(rq) == READ) ?
  178. word_count | 0x05000000 :
  179. word_count | 0x06000000;
  180. outl(word_count, atapi_reg);
  181. }
  182. ide_dma_start(drive);
  183. }
  184. static int pdc202xx_old_ide_dma_end(ide_drive_t *drive)
  185. {
  186. if (drive->media != ide_disk || drive->addressing == 1) {
  187. ide_hwif_t *hwif = HWIF(drive);
  188. unsigned long high_16 = hwif->dma_master;
  189. unsigned long atapi_reg = high_16 + (hwif->channel ? 0x24 : 0x20);
  190. u8 clock = 0;
  191. outl(0, atapi_reg); /* zero out extra */
  192. clock = inb(high_16 + 0x11);
  193. outb(clock & ~(hwif->channel ? 0x08:0x02), high_16 + 0x11);
  194. }
  195. if (drive->current_speed > XFER_UDMA_2)
  196. pdc_old_disable_66MHz_clock(drive->hwif);
  197. return __ide_dma_end(drive);
  198. }
  199. static int pdc202xx_old_ide_dma_test_irq(ide_drive_t *drive)
  200. {
  201. ide_hwif_t *hwif = HWIF(drive);
  202. unsigned long high_16 = hwif->dma_master;
  203. u8 dma_stat = inb(hwif->dma_status);
  204. u8 sc1d = inb(high_16 + 0x001d);
  205. if (hwif->channel) {
  206. /* bit7: Error, bit6: Interrupting, bit5: FIFO Full, bit4: FIFO Empty */
  207. if ((sc1d & 0x50) == 0x50)
  208. goto somebody_else;
  209. else if ((sc1d & 0x40) == 0x40)
  210. return (dma_stat & 4) == 4;
  211. } else {
  212. /* bit3: Error, bit2: Interrupting, bit1: FIFO Full, bit0: FIFO Empty */
  213. if ((sc1d & 0x05) == 0x05)
  214. goto somebody_else;
  215. else if ((sc1d & 0x04) == 0x04)
  216. return (dma_stat & 4) == 4;
  217. }
  218. somebody_else:
  219. return (dma_stat & 4) == 4; /* return 1 if INTR asserted */
  220. }
  221. static void pdc202xx_dma_lost_irq(ide_drive_t *drive)
  222. {
  223. ide_hwif_t *hwif = HWIF(drive);
  224. if (hwif->resetproc != NULL)
  225. hwif->resetproc(drive);
  226. ide_dma_lost_irq(drive);
  227. }
  228. static void pdc202xx_dma_timeout(ide_drive_t *drive)
  229. {
  230. ide_hwif_t *hwif = HWIF(drive);
  231. if (hwif->resetproc != NULL)
  232. hwif->resetproc(drive);
  233. ide_dma_timeout(drive);
  234. }
  235. static void pdc202xx_reset_host (ide_hwif_t *hwif)
  236. {
  237. unsigned long high_16 = hwif->dma_master;
  238. u8 udma_speed_flag = inb(high_16 | 0x001f);
  239. outb(udma_speed_flag | 0x10, high_16 | 0x001f);
  240. mdelay(100);
  241. outb(udma_speed_flag & ~0x10, high_16 | 0x001f);
  242. mdelay(2000); /* 2 seconds ?! */
  243. printk(KERN_WARNING "PDC202XX: %s channel reset.\n",
  244. hwif->channel ? "Secondary" : "Primary");
  245. }
  246. static void pdc202xx_reset (ide_drive_t *drive)
  247. {
  248. ide_hwif_t *hwif = HWIF(drive);
  249. ide_hwif_t *mate = hwif->mate;
  250. pdc202xx_reset_host(hwif);
  251. pdc202xx_reset_host(mate);
  252. ide_set_max_pio(drive);
  253. }
  254. static unsigned int __devinit init_chipset_pdc202xx(struct pci_dev *dev,
  255. const char *name)
  256. {
  257. return dev->irq;
  258. }
  259. static void __devinit init_hwif_pdc202xx(ide_hwif_t *hwif)
  260. {
  261. hwif->set_pio_mode = &pdc202xx_set_pio_mode;
  262. hwif->set_dma_mode = &pdc202xx_set_mode;
  263. hwif->quirkproc = &pdc202xx_quirkproc;
  264. if (hwif->pci_dev->device != PCI_DEVICE_ID_PROMISE_20246)
  265. hwif->resetproc = &pdc202xx_reset;
  266. if (hwif->dma_base == 0)
  267. return;
  268. hwif->dma_lost_irq = &pdc202xx_dma_lost_irq;
  269. hwif->dma_timeout = &pdc202xx_dma_timeout;
  270. if (hwif->pci_dev->device != PCI_DEVICE_ID_PROMISE_20246) {
  271. if (hwif->cbl != ATA_CBL_PATA40_SHORT)
  272. hwif->cbl = pdc202xx_old_cable_detect(hwif);
  273. hwif->dma_start = &pdc202xx_old_ide_dma_start;
  274. hwif->ide_dma_end = &pdc202xx_old_ide_dma_end;
  275. }
  276. hwif->ide_dma_test_irq = &pdc202xx_old_ide_dma_test_irq;
  277. }
  278. static void __devinit init_dma_pdc202xx(ide_hwif_t *hwif, unsigned long dmabase)
  279. {
  280. u8 udma_speed_flag = 0, primary_mode = 0, secondary_mode = 0;
  281. if (hwif->channel) {
  282. ide_setup_dma(hwif, dmabase, 8);
  283. return;
  284. }
  285. udma_speed_flag = inb(dmabase | 0x1f);
  286. primary_mode = inb(dmabase | 0x1a);
  287. secondary_mode = inb(dmabase | 0x1b);
  288. printk(KERN_INFO "%s: (U)DMA Burst Bit %sABLED " \
  289. "Primary %s Mode " \
  290. "Secondary %s Mode.\n", hwif->cds->name,
  291. (udma_speed_flag & 1) ? "EN" : "DIS",
  292. (primary_mode & 1) ? "MASTER" : "PCI",
  293. (secondary_mode & 1) ? "MASTER" : "PCI" );
  294. #ifdef CONFIG_PDC202XX_BURST
  295. if (!(udma_speed_flag & 1)) {
  296. printk(KERN_INFO "%s: FORCING BURST BIT 0x%02x->0x%02x ",
  297. hwif->cds->name, udma_speed_flag,
  298. (udma_speed_flag|1));
  299. outb(udma_speed_flag | 1, dmabase | 0x1f);
  300. printk("%sACTIVE\n", (inb(dmabase | 0x1f) & 1) ? "" : "IN");
  301. }
  302. #endif /* CONFIG_PDC202XX_BURST */
  303. ide_setup_dma(hwif, dmabase, 8);
  304. }
  305. static void __devinit pdc202ata4_fixup_irq(struct pci_dev *dev,
  306. const char *name)
  307. {
  308. if ((dev->class >> 8) != PCI_CLASS_STORAGE_IDE) {
  309. u8 irq = 0, irq2 = 0;
  310. pci_read_config_byte(dev, PCI_INTERRUPT_LINE, &irq);
  311. /* 0xbc */
  312. pci_read_config_byte(dev, (PCI_INTERRUPT_LINE)|0x80, &irq2);
  313. if (irq != irq2) {
  314. pci_write_config_byte(dev,
  315. (PCI_INTERRUPT_LINE)|0x80, irq); /* 0xbc */
  316. printk(KERN_INFO "%s: PCI config space interrupt "
  317. "mirror fixed\n", name);
  318. }
  319. }
  320. }
  321. #define DECLARE_PDC2026X_DEV(name_str, udma, extra_flags) \
  322. { \
  323. .name = name_str, \
  324. .init_chipset = init_chipset_pdc202xx, \
  325. .init_hwif = init_hwif_pdc202xx, \
  326. .init_dma = init_dma_pdc202xx, \
  327. .extra = 48, \
  328. .host_flags = IDE_HFLAG_ERROR_STOPS_FIFO | \
  329. extra_flags | \
  330. IDE_HFLAG_OFF_BOARD, \
  331. .pio_mask = ATA_PIO4, \
  332. .mwdma_mask = ATA_MWDMA2, \
  333. .udma_mask = udma, \
  334. }
  335. static const struct ide_port_info pdc202xx_chipsets[] __devinitdata = {
  336. { /* 0 */
  337. .name = "PDC20246",
  338. .init_chipset = init_chipset_pdc202xx,
  339. .init_hwif = init_hwif_pdc202xx,
  340. .init_dma = init_dma_pdc202xx,
  341. .extra = 16,
  342. .host_flags = IDE_HFLAG_ERROR_STOPS_FIFO |
  343. IDE_HFLAG_OFF_BOARD,
  344. .pio_mask = ATA_PIO4,
  345. .mwdma_mask = ATA_MWDMA2,
  346. .udma_mask = ATA_UDMA2,
  347. },
  348. /* 1 */ DECLARE_PDC2026X_DEV("PDC20262", ATA_UDMA4, 0),
  349. /* 2 */ DECLARE_PDC2026X_DEV("PDC20263", ATA_UDMA4, 0),
  350. /* 3 */ DECLARE_PDC2026X_DEV("PDC20265", ATA_UDMA5, IDE_HFLAG_RQSIZE_256),
  351. /* 4 */ DECLARE_PDC2026X_DEV("PDC20267", ATA_UDMA5, IDE_HFLAG_RQSIZE_256),
  352. };
  353. /**
  354. * pdc202xx_init_one - called when a PDC202xx is found
  355. * @dev: the pdc202xx device
  356. * @id: the matching pci id
  357. *
  358. * Called when the PCI registration layer (or the IDE initialization)
  359. * finds a device matching our IDE device tables.
  360. */
  361. static int __devinit pdc202xx_init_one(struct pci_dev *dev, const struct pci_device_id *id)
  362. {
  363. const struct ide_port_info *d;
  364. u8 idx = id->driver_data;
  365. d = &pdc202xx_chipsets[idx];
  366. if (idx < 3)
  367. pdc202ata4_fixup_irq(dev, d->name);
  368. if (idx == 3) {
  369. struct pci_dev *bridge = dev->bus->self;
  370. if (bridge &&
  371. bridge->vendor == PCI_VENDOR_ID_INTEL &&
  372. (bridge->device == PCI_DEVICE_ID_INTEL_I960 ||
  373. bridge->device == PCI_DEVICE_ID_INTEL_I960RM)) {
  374. printk(KERN_INFO "ide: Skipping Promise PDC20265 "
  375. "attached to I2O RAID controller\n");
  376. return -ENODEV;
  377. }
  378. }
  379. return ide_setup_pci_device(dev, d);
  380. }
  381. static const struct pci_device_id pdc202xx_pci_tbl[] = {
  382. { PCI_VDEVICE(PROMISE, PCI_DEVICE_ID_PROMISE_20246), 0 },
  383. { PCI_VDEVICE(PROMISE, PCI_DEVICE_ID_PROMISE_20262), 1 },
  384. { PCI_VDEVICE(PROMISE, PCI_DEVICE_ID_PROMISE_20263), 2 },
  385. { PCI_VDEVICE(PROMISE, PCI_DEVICE_ID_PROMISE_20265), 3 },
  386. { PCI_VDEVICE(PROMISE, PCI_DEVICE_ID_PROMISE_20267), 4 },
  387. { 0, },
  388. };
  389. MODULE_DEVICE_TABLE(pci, pdc202xx_pci_tbl);
  390. static struct pci_driver driver = {
  391. .name = "Promise_Old_IDE",
  392. .id_table = pdc202xx_pci_tbl,
  393. .probe = pdc202xx_init_one,
  394. };
  395. static int __init pdc202xx_ide_init(void)
  396. {
  397. return ide_pci_register_driver(&driver);
  398. }
  399. module_init(pdc202xx_ide_init);
  400. MODULE_AUTHOR("Andre Hedrick, Frank Tiernan");
  401. MODULE_DESCRIPTION("PCI driver module for older Promise IDE");
  402. MODULE_LICENSE("GPL");