pdc202xx_old.c 21 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731
  1. /*
  2. * linux/drivers/ide/pci/pdc202xx_old.c Version 0.36 Sept 11, 2002
  3. *
  4. * Copyright (C) 1998-2002 Andre Hedrick <andre@linux-ide.org>
  5. *
  6. * Promise Ultra33 cards with BIOS v1.20 through 1.28 will need this
  7. * compiled into the kernel if you have more than one card installed.
  8. * Note that BIOS v1.29 is reported to fix the problem. Since this is
  9. * safe chipset tuning, including this support is harmless
  10. *
  11. * Promise Ultra66 cards with BIOS v1.11 this
  12. * compiled into the kernel if you have more than one card installed.
  13. *
  14. * Promise Ultra100 cards.
  15. *
  16. * The latest chipset code will support the following ::
  17. * Three Ultra33 controllers and 12 drives.
  18. * 8 are UDMA supported and 4 are limited to DMA mode 2 multi-word.
  19. * The 8/4 ratio is a BIOS code limit by promise.
  20. *
  21. * UNLESS you enable "CONFIG_PDC202XX_BURST"
  22. *
  23. */
  24. /*
  25. * Portions Copyright (C) 1999 Promise Technology, Inc.
  26. * Author: Frank Tiernan (frankt@promise.com)
  27. * Released under terms of General Public License
  28. */
  29. #include <linux/types.h>
  30. #include <linux/module.h>
  31. #include <linux/kernel.h>
  32. #include <linux/delay.h>
  33. #include <linux/timer.h>
  34. #include <linux/mm.h>
  35. #include <linux/ioport.h>
  36. #include <linux/blkdev.h>
  37. #include <linux/hdreg.h>
  38. #include <linux/interrupt.h>
  39. #include <linux/pci.h>
  40. #include <linux/init.h>
  41. #include <linux/ide.h>
  42. #include <asm/io.h>
  43. #include <asm/irq.h>
  44. #define PDC202_DEBUG_CABLE 0
  45. #define PDC202XX_DEBUG_DRIVE_INFO 0
  46. static const char *pdc_quirk_drives[] = {
  47. "QUANTUM FIREBALLlct08 08",
  48. "QUANTUM FIREBALLP KA6.4",
  49. "QUANTUM FIREBALLP KA9.1",
  50. "QUANTUM FIREBALLP LM20.4",
  51. "QUANTUM FIREBALLP KX13.6",
  52. "QUANTUM FIREBALLP KX20.5",
  53. "QUANTUM FIREBALLP KX27.3",
  54. "QUANTUM FIREBALLP LM20.5",
  55. NULL
  56. };
  57. /* A Register */
  58. #define SYNC_ERRDY_EN 0xC0
  59. #define SYNC_IN 0x80 /* control bit, different for master vs. slave drives */
  60. #define ERRDY_EN 0x40 /* control bit, different for master vs. slave drives */
  61. #define IORDY_EN 0x20 /* PIO: IOREADY */
  62. #define PREFETCH_EN 0x10 /* PIO: PREFETCH */
  63. #define PA3 0x08 /* PIO"A" timing */
  64. #define PA2 0x04 /* PIO"A" timing */
  65. #define PA1 0x02 /* PIO"A" timing */
  66. #define PA0 0x01 /* PIO"A" timing */
  67. /* B Register */
  68. #define MB2 0x80 /* DMA"B" timing */
  69. #define MB1 0x40 /* DMA"B" timing */
  70. #define MB0 0x20 /* DMA"B" timing */
  71. #define PB4 0x10 /* PIO_FORCE 1:0 */
  72. #define PB3 0x08 /* PIO"B" timing */ /* PIO flow Control mode */
  73. #define PB2 0x04 /* PIO"B" timing */ /* PIO 4 */
  74. #define PB1 0x02 /* PIO"B" timing */ /* PIO 3 half */
  75. #define PB0 0x01 /* PIO"B" timing */ /* PIO 3 other half */
  76. /* C Register */
  77. #define IORDYp_NO_SPEED 0x4F
  78. #define SPEED_DIS 0x0F
  79. #define DMARQp 0x80
  80. #define IORDYp 0x40
  81. #define DMAR_EN 0x20
  82. #define DMAW_EN 0x10
  83. #define MC3 0x08 /* DMA"C" timing */
  84. #define MC2 0x04 /* DMA"C" timing */
  85. #define MC1 0x02 /* DMA"C" timing */
  86. #define MC0 0x01 /* DMA"C" timing */
  87. static u8 pdc202xx_ratemask (ide_drive_t *drive)
  88. {
  89. u8 mode;
  90. switch(HWIF(drive)->pci_dev->device) {
  91. case PCI_DEVICE_ID_PROMISE_20267:
  92. case PCI_DEVICE_ID_PROMISE_20265:
  93. mode = 3;
  94. break;
  95. case PCI_DEVICE_ID_PROMISE_20263:
  96. case PCI_DEVICE_ID_PROMISE_20262:
  97. mode = 2;
  98. break;
  99. case PCI_DEVICE_ID_PROMISE_20246:
  100. return 1;
  101. default:
  102. return 0;
  103. }
  104. if (!eighty_ninty_three(drive))
  105. mode = min(mode, (u8)1);
  106. return mode;
  107. }
  108. static int check_in_drive_lists (ide_drive_t *drive, const char **list)
  109. {
  110. struct hd_driveid *id = drive->id;
  111. if (pdc_quirk_drives == list) {
  112. while (*list) {
  113. if (strstr(id->model, *list++)) {
  114. return 2;
  115. }
  116. }
  117. } else {
  118. while (*list) {
  119. if (!strcmp(*list++,id->model)) {
  120. return 1;
  121. }
  122. }
  123. }
  124. return 0;
  125. }
  126. static int pdc202xx_tune_chipset (ide_drive_t *drive, u8 xferspeed)
  127. {
  128. ide_hwif_t *hwif = HWIF(drive);
  129. struct pci_dev *dev = hwif->pci_dev;
  130. u8 drive_pci = 0x60 + (drive->dn << 2);
  131. u8 speed = ide_rate_filter(pdc202xx_ratemask(drive), xferspeed);
  132. u32 drive_conf;
  133. u8 AP, BP, CP, DP;
  134. u8 TA = 0, TB = 0, TC = 0;
  135. if (drive->media != ide_disk &&
  136. drive->media != ide_cdrom && speed < XFER_SW_DMA_0)
  137. return -1;
  138. pci_read_config_dword(dev, drive_pci, &drive_conf);
  139. pci_read_config_byte(dev, (drive_pci), &AP);
  140. pci_read_config_byte(dev, (drive_pci)|0x01, &BP);
  141. pci_read_config_byte(dev, (drive_pci)|0x02, &CP);
  142. pci_read_config_byte(dev, (drive_pci)|0x03, &DP);
  143. if (speed < XFER_SW_DMA_0) {
  144. if ((AP & 0x0F) || (BP & 0x07)) {
  145. /* clear PIO modes of lower 8421 bits of A Register */
  146. pci_write_config_byte(dev, (drive_pci), AP &~0x0F);
  147. pci_read_config_byte(dev, (drive_pci), &AP);
  148. /* clear PIO modes of lower 421 bits of B Register */
  149. pci_write_config_byte(dev, (drive_pci)|0x01, BP &~0x07);
  150. pci_read_config_byte(dev, (drive_pci)|0x01, &BP);
  151. pci_read_config_byte(dev, (drive_pci), &AP);
  152. pci_read_config_byte(dev, (drive_pci)|0x01, &BP);
  153. }
  154. } else {
  155. if ((BP & 0xF0) && (CP & 0x0F)) {
  156. /* clear DMA modes of upper 842 bits of B Register */
  157. /* clear PIO forced mode upper 1 bit of B Register */
  158. pci_write_config_byte(dev, (drive_pci)|0x01, BP &~0xF0);
  159. pci_read_config_byte(dev, (drive_pci)|0x01, &BP);
  160. /* clear DMA modes of lower 8421 bits of C Register */
  161. pci_write_config_byte(dev, (drive_pci)|0x02, CP &~0x0F);
  162. pci_read_config_byte(dev, (drive_pci)|0x02, &CP);
  163. }
  164. }
  165. pci_read_config_byte(dev, (drive_pci), &AP);
  166. pci_read_config_byte(dev, (drive_pci)|0x01, &BP);
  167. pci_read_config_byte(dev, (drive_pci)|0x02, &CP);
  168. switch(speed) {
  169. case XFER_UDMA_6: speed = XFER_UDMA_5;
  170. case XFER_UDMA_5:
  171. case XFER_UDMA_4: TB = 0x20; TC = 0x01; break;
  172. case XFER_UDMA_2: TB = 0x20; TC = 0x01; break;
  173. case XFER_UDMA_3:
  174. case XFER_UDMA_1: TB = 0x40; TC = 0x02; break;
  175. case XFER_UDMA_0:
  176. case XFER_MW_DMA_2: TB = 0x60; TC = 0x03; break;
  177. case XFER_MW_DMA_1: TB = 0x60; TC = 0x04; break;
  178. case XFER_MW_DMA_0:
  179. case XFER_SW_DMA_2: TB = 0x60; TC = 0x05; break;
  180. case XFER_SW_DMA_1: TB = 0x80; TC = 0x06; break;
  181. case XFER_SW_DMA_0: TB = 0xC0; TC = 0x0B; break;
  182. case XFER_PIO_4: TA = 0x01; TB = 0x04; break;
  183. case XFER_PIO_3: TA = 0x02; TB = 0x06; break;
  184. case XFER_PIO_2: TA = 0x03; TB = 0x08; break;
  185. case XFER_PIO_1: TA = 0x05; TB = 0x0C; break;
  186. case XFER_PIO_0:
  187. default: TA = 0x09; TB = 0x13; break;
  188. }
  189. if (speed < XFER_SW_DMA_0) {
  190. pci_write_config_byte(dev, (drive_pci), AP|TA);
  191. pci_write_config_byte(dev, (drive_pci)|0x01, BP|TB);
  192. } else {
  193. pci_write_config_byte(dev, (drive_pci)|0x01, BP|TB);
  194. pci_write_config_byte(dev, (drive_pci)|0x02, CP|TC);
  195. }
  196. #if PDC202XX_DEBUG_DRIVE_INFO
  197. printk(KERN_DEBUG "%s: %s drive%d 0x%08x ",
  198. drive->name, ide_xfer_verbose(speed),
  199. drive->dn, drive_conf);
  200. pci_read_config_dword(dev, drive_pci, &drive_conf);
  201. printk("0x%08x\n", drive_conf);
  202. #endif /* PDC202XX_DEBUG_DRIVE_INFO */
  203. return (ide_config_drive_speed(drive, speed));
  204. }
  205. /* 0 1 2 3 4 5 6 7 8
  206. * 960, 480, 390, 300, 240, 180, 120, 90, 60
  207. * 180, 150, 120, 90, 60
  208. * DMA_Speed
  209. * 180, 120, 90, 90, 90, 60, 30
  210. * 11, 5, 4, 3, 2, 1, 0
  211. */
  212. static void config_chipset_for_pio (ide_drive_t *drive, u8 pio)
  213. {
  214. u8 speed = 0;
  215. if (pio == 5) pio = 4;
  216. speed = XFER_PIO_0 + ide_get_best_pio_mode(drive, 255, pio, NULL);
  217. pdc202xx_tune_chipset(drive, speed);
  218. }
  219. static u8 pdc202xx_old_cable_detect (ide_hwif_t *hwif)
  220. {
  221. u16 CIS = 0, mask = (hwif->channel) ? (1<<11) : (1<<10);
  222. pci_read_config_word(hwif->pci_dev, 0x50, &CIS);
  223. return (CIS & mask) ? 1 : 0;
  224. }
  225. /*
  226. * Set the control register to use the 66MHz system
  227. * clock for UDMA 3/4/5 mode operation when necessary.
  228. *
  229. * It may also be possible to leave the 66MHz clock on
  230. * and readjust the timing parameters.
  231. */
  232. static void pdc_old_enable_66MHz_clock(ide_hwif_t *hwif)
  233. {
  234. unsigned long clock_reg = hwif->dma_master + 0x11;
  235. u8 clock = hwif->INB(clock_reg);
  236. hwif->OUTB(clock | (hwif->channel ? 0x08 : 0x02), clock_reg);
  237. }
  238. static void pdc_old_disable_66MHz_clock(ide_hwif_t *hwif)
  239. {
  240. unsigned long clock_reg = hwif->dma_master + 0x11;
  241. u8 clock = hwif->INB(clock_reg);
  242. hwif->OUTB(clock & ~(hwif->channel ? 0x08 : 0x02), clock_reg);
  243. }
  244. static int config_chipset_for_dma (ide_drive_t *drive)
  245. {
  246. struct hd_driveid *id = drive->id;
  247. ide_hwif_t *hwif = HWIF(drive);
  248. struct pci_dev *dev = hwif->pci_dev;
  249. u32 drive_conf = 0;
  250. u8 drive_pci = 0x60 + (drive->dn << 2);
  251. u8 test1 = 0, test2 = 0, speed = -1;
  252. u8 AP = 0, cable = 0;
  253. u8 ultra_66 = ((id->dma_ultra & 0x0010) ||
  254. (id->dma_ultra & 0x0008)) ? 1 : 0;
  255. if (dev->device != PCI_DEVICE_ID_PROMISE_20246)
  256. cable = pdc202xx_old_cable_detect(hwif);
  257. else
  258. ultra_66 = 0;
  259. if (ultra_66 && cable) {
  260. printk(KERN_WARNING "Warning: %s channel requires an 80-pin cable for operation.\n", hwif->channel ? "Secondary":"Primary");
  261. printk(KERN_WARNING "%s reduced to Ultra33 mode.\n", drive->name);
  262. }
  263. if (dev->device != PCI_DEVICE_ID_PROMISE_20246)
  264. pdc_old_disable_66MHz_clock(drive->hwif);
  265. drive_pci = 0x60 + (drive->dn << 2);
  266. pci_read_config_dword(dev, drive_pci, &drive_conf);
  267. if ((drive_conf != 0x004ff304) && (drive_conf != 0x004ff3c4))
  268. goto chipset_is_set;
  269. pci_read_config_byte(dev, drive_pci, &test1);
  270. if (!(test1 & SYNC_ERRDY_EN)) {
  271. if (drive->select.b.unit & 0x01) {
  272. pci_read_config_byte(dev, drive_pci - 4, &test2);
  273. if ((test2 & SYNC_ERRDY_EN) &&
  274. !(test1 & SYNC_ERRDY_EN)) {
  275. pci_write_config_byte(dev, drive_pci,
  276. test1|SYNC_ERRDY_EN);
  277. }
  278. } else {
  279. pci_write_config_byte(dev, drive_pci,
  280. test1|SYNC_ERRDY_EN);
  281. }
  282. }
  283. chipset_is_set:
  284. pci_read_config_byte(dev, (drive_pci), &AP);
  285. if (id->capability & 4) /* IORDY_EN */
  286. pci_write_config_byte(dev, (drive_pci), AP|IORDY_EN);
  287. pci_read_config_byte(dev, (drive_pci), &AP);
  288. if (drive->media == ide_disk) /* PREFETCH_EN */
  289. pci_write_config_byte(dev, (drive_pci), AP|PREFETCH_EN);
  290. speed = ide_dma_speed(drive, pdc202xx_ratemask(drive));
  291. if (!(speed)) {
  292. /* restore original pci-config space */
  293. pci_write_config_dword(dev, drive_pci, drive_conf);
  294. return 0;
  295. }
  296. (void) hwif->speedproc(drive, speed);
  297. return ide_dma_enable(drive);
  298. }
  299. static int pdc202xx_config_drive_xfer_rate (ide_drive_t *drive)
  300. {
  301. ide_hwif_t *hwif = HWIF(drive);
  302. struct hd_driveid *id = drive->id;
  303. drive->init_speed = 0;
  304. if (id && (id->capability & 1) && drive->autodma) {
  305. if (ide_use_dma(drive)) {
  306. if (config_chipset_for_dma(drive))
  307. return hwif->ide_dma_on(drive);
  308. }
  309. goto fast_ata_pio;
  310. } else if ((id->capability & 8) || (id->field_valid & 2)) {
  311. fast_ata_pio:
  312. hwif->tuneproc(drive, 5);
  313. return hwif->ide_dma_off_quietly(drive);
  314. }
  315. /* IORDY not supported */
  316. return 0;
  317. }
  318. static int pdc202xx_quirkproc (ide_drive_t *drive)
  319. {
  320. return ((int) check_in_drive_lists(drive, pdc_quirk_drives));
  321. }
  322. static void pdc202xx_old_ide_dma_start(ide_drive_t *drive)
  323. {
  324. if (drive->current_speed > XFER_UDMA_2)
  325. pdc_old_enable_66MHz_clock(drive->hwif);
  326. if (drive->media != ide_disk || drive->addressing == 1) {
  327. struct request *rq = HWGROUP(drive)->rq;
  328. ide_hwif_t *hwif = HWIF(drive);
  329. unsigned long high_16 = hwif->dma_master;
  330. unsigned long atapi_reg = high_16 + (hwif->channel ? 0x24 : 0x20);
  331. u32 word_count = 0;
  332. u8 clock = hwif->INB(high_16 + 0x11);
  333. hwif->OUTB(clock|(hwif->channel ? 0x08 : 0x02), high_16+0x11);
  334. word_count = (rq->nr_sectors << 8);
  335. word_count = (rq_data_dir(rq) == READ) ?
  336. word_count | 0x05000000 :
  337. word_count | 0x06000000;
  338. hwif->OUTL(word_count, atapi_reg);
  339. }
  340. ide_dma_start(drive);
  341. }
  342. static int pdc202xx_old_ide_dma_end(ide_drive_t *drive)
  343. {
  344. if (drive->media != ide_disk || drive->addressing == 1) {
  345. ide_hwif_t *hwif = HWIF(drive);
  346. unsigned long high_16 = hwif->dma_master;
  347. unsigned long atapi_reg = high_16 + (hwif->channel ? 0x24 : 0x20);
  348. u8 clock = 0;
  349. hwif->OUTL(0, atapi_reg); /* zero out extra */
  350. clock = hwif->INB(high_16 + 0x11);
  351. hwif->OUTB(clock & ~(hwif->channel ? 0x08:0x02), high_16+0x11);
  352. }
  353. if (drive->current_speed > XFER_UDMA_2)
  354. pdc_old_disable_66MHz_clock(drive->hwif);
  355. return __ide_dma_end(drive);
  356. }
  357. static int pdc202xx_old_ide_dma_test_irq(ide_drive_t *drive)
  358. {
  359. ide_hwif_t *hwif = HWIF(drive);
  360. unsigned long high_16 = hwif->dma_master;
  361. u8 dma_stat = hwif->INB(hwif->dma_status);
  362. u8 sc1d = hwif->INB((high_16 + 0x001d));
  363. if (hwif->channel) {
  364. /* bit7: Error, bit6: Interrupting, bit5: FIFO Full, bit4: FIFO Empty */
  365. if ((sc1d & 0x50) == 0x50)
  366. goto somebody_else;
  367. else if ((sc1d & 0x40) == 0x40)
  368. return (dma_stat & 4) == 4;
  369. } else {
  370. /* bit3: Error, bit2: Interrupting, bit1: FIFO Full, bit0: FIFO Empty */
  371. if ((sc1d & 0x05) == 0x05)
  372. goto somebody_else;
  373. else if ((sc1d & 0x04) == 0x04)
  374. return (dma_stat & 4) == 4;
  375. }
  376. somebody_else:
  377. return (dma_stat & 4) == 4; /* return 1 if INTR asserted */
  378. }
  379. static int pdc202xx_ide_dma_lostirq(ide_drive_t *drive)
  380. {
  381. if (HWIF(drive)->resetproc != NULL)
  382. HWIF(drive)->resetproc(drive);
  383. return __ide_dma_lostirq(drive);
  384. }
  385. static int pdc202xx_ide_dma_timeout(ide_drive_t *drive)
  386. {
  387. if (HWIF(drive)->resetproc != NULL)
  388. HWIF(drive)->resetproc(drive);
  389. return __ide_dma_timeout(drive);
  390. }
  391. static void pdc202xx_reset_host (ide_hwif_t *hwif)
  392. {
  393. unsigned long high_16 = hwif->dma_master;
  394. u8 udma_speed_flag = hwif->INB(high_16|0x001f);
  395. hwif->OUTB((udma_speed_flag | 0x10), (high_16|0x001f));
  396. mdelay(100);
  397. hwif->OUTB((udma_speed_flag & ~0x10), (high_16|0x001f));
  398. mdelay(2000); /* 2 seconds ?! */
  399. printk(KERN_WARNING "PDC202XX: %s channel reset.\n",
  400. hwif->channel ? "Secondary" : "Primary");
  401. }
  402. static void pdc202xx_reset (ide_drive_t *drive)
  403. {
  404. ide_hwif_t *hwif = HWIF(drive);
  405. ide_hwif_t *mate = hwif->mate;
  406. pdc202xx_reset_host(hwif);
  407. pdc202xx_reset_host(mate);
  408. hwif->tuneproc(drive, 5);
  409. }
  410. static unsigned int __devinit init_chipset_pdc202xx(struct pci_dev *dev,
  411. const char *name)
  412. {
  413. /* This doesn't appear needed */
  414. if (dev->resource[PCI_ROM_RESOURCE].start) {
  415. pci_write_config_dword(dev, PCI_ROM_ADDRESS,
  416. dev->resource[PCI_ROM_RESOURCE].start | PCI_ROM_ADDRESS_ENABLE);
  417. printk(KERN_INFO "%s: ROM enabled at 0x%08lx\n", name,
  418. (unsigned long)dev->resource[PCI_ROM_RESOURCE].start);
  419. }
  420. return dev->irq;
  421. }
  422. static void __devinit init_hwif_pdc202xx(ide_hwif_t *hwif)
  423. {
  424. struct pci_dev *dev = hwif->pci_dev;
  425. /* PDC20265 has problems with large LBA48 requests */
  426. if ((dev->device == PCI_DEVICE_ID_PROMISE_20267) ||
  427. (dev->device == PCI_DEVICE_ID_PROMISE_20265))
  428. hwif->rqsize = 256;
  429. hwif->autodma = 0;
  430. hwif->tuneproc = &config_chipset_for_pio;
  431. hwif->quirkproc = &pdc202xx_quirkproc;
  432. if (hwif->pci_dev->device != PCI_DEVICE_ID_PROMISE_20246)
  433. hwif->resetproc = &pdc202xx_reset;
  434. hwif->speedproc = &pdc202xx_tune_chipset;
  435. hwif->drives[0].autotune = hwif->drives[1].autotune = 1;
  436. hwif->ultra_mask = 0x3f;
  437. hwif->mwdma_mask = 0x07;
  438. hwif->swdma_mask = 0x07;
  439. hwif->atapi_dma = 1;
  440. hwif->err_stops_fifo = 1;
  441. hwif->ide_dma_check = &pdc202xx_config_drive_xfer_rate;
  442. hwif->ide_dma_lostirq = &pdc202xx_ide_dma_lostirq;
  443. hwif->ide_dma_timeout = &pdc202xx_ide_dma_timeout;
  444. if (hwif->pci_dev->device != PCI_DEVICE_ID_PROMISE_20246) {
  445. if (!(hwif->udma_four))
  446. hwif->udma_four = (pdc202xx_old_cable_detect(hwif)) ? 0 : 1;
  447. hwif->dma_start = &pdc202xx_old_ide_dma_start;
  448. hwif->ide_dma_end = &pdc202xx_old_ide_dma_end;
  449. }
  450. hwif->ide_dma_test_irq = &pdc202xx_old_ide_dma_test_irq;
  451. if (!noautodma)
  452. hwif->autodma = 1;
  453. hwif->drives[0].autodma = hwif->drives[1].autodma = hwif->autodma;
  454. #if PDC202_DEBUG_CABLE
  455. printk(KERN_DEBUG "%s: %s-pin cable\n",
  456. hwif->name, hwif->udma_four ? "80" : "40");
  457. #endif /* PDC202_DEBUG_CABLE */
  458. }
  459. static void __devinit init_dma_pdc202xx(ide_hwif_t *hwif, unsigned long dmabase)
  460. {
  461. u8 udma_speed_flag = 0, primary_mode = 0, secondary_mode = 0;
  462. if (hwif->channel) {
  463. ide_setup_dma(hwif, dmabase, 8);
  464. return;
  465. }
  466. udma_speed_flag = hwif->INB((dmabase|0x1f));
  467. primary_mode = hwif->INB((dmabase|0x1a));
  468. secondary_mode = hwif->INB((dmabase|0x1b));
  469. printk(KERN_INFO "%s: (U)DMA Burst Bit %sABLED " \
  470. "Primary %s Mode " \
  471. "Secondary %s Mode.\n", hwif->cds->name,
  472. (udma_speed_flag & 1) ? "EN" : "DIS",
  473. (primary_mode & 1) ? "MASTER" : "PCI",
  474. (secondary_mode & 1) ? "MASTER" : "PCI" );
  475. #ifdef CONFIG_PDC202XX_BURST
  476. if (!(udma_speed_flag & 1)) {
  477. printk(KERN_INFO "%s: FORCING BURST BIT 0x%02x->0x%02x ",
  478. hwif->cds->name, udma_speed_flag,
  479. (udma_speed_flag|1));
  480. hwif->OUTB(udma_speed_flag|1,(dmabase|0x1f));
  481. printk("%sACTIVE\n",
  482. (hwif->INB(dmabase|0x1f)&1) ? "":"IN");
  483. }
  484. #endif /* CONFIG_PDC202XX_BURST */
  485. #ifdef CONFIG_PDC202XX_MASTER
  486. if (!(primary_mode & 1)) {
  487. printk(KERN_INFO "%s: FORCING PRIMARY MODE BIT "
  488. "0x%02x -> 0x%02x ", hwif->cds->name,
  489. primary_mode, (primary_mode|1));
  490. hwif->OUTB(primary_mode|1, (dmabase|0x1a));
  491. printk("%s\n",
  492. (hwif->INB((dmabase|0x1a)) & 1) ? "MASTER" : "PCI");
  493. }
  494. if (!(secondary_mode & 1)) {
  495. printk(KERN_INFO "%s: FORCING SECONDARY MODE BIT "
  496. "0x%02x -> 0x%02x ", hwif->cds->name,
  497. secondary_mode, (secondary_mode|1));
  498. hwif->OUTB(secondary_mode|1, (dmabase|0x1b));
  499. printk("%s\n",
  500. (hwif->INB((dmabase|0x1b)) & 1) ? "MASTER" : "PCI");
  501. }
  502. #endif /* CONFIG_PDC202XX_MASTER */
  503. ide_setup_dma(hwif, dmabase, 8);
  504. }
  505. static int __devinit init_setup_pdc202ata4(struct pci_dev *dev,
  506. ide_pci_device_t *d)
  507. {
  508. if ((dev->class >> 8) != PCI_CLASS_STORAGE_IDE) {
  509. u8 irq = 0, irq2 = 0;
  510. pci_read_config_byte(dev, PCI_INTERRUPT_LINE, &irq);
  511. /* 0xbc */
  512. pci_read_config_byte(dev, (PCI_INTERRUPT_LINE)|0x80, &irq2);
  513. if (irq != irq2) {
  514. pci_write_config_byte(dev,
  515. (PCI_INTERRUPT_LINE)|0x80, irq); /* 0xbc */
  516. printk(KERN_INFO "%s: pci-config space interrupt "
  517. "mirror fixed.\n", d->name);
  518. }
  519. }
  520. return ide_setup_pci_device(dev, d);
  521. }
  522. static int __devinit init_setup_pdc20265(struct pci_dev *dev,
  523. ide_pci_device_t *d)
  524. {
  525. if ((dev->bus->self) &&
  526. (dev->bus->self->vendor == PCI_VENDOR_ID_INTEL) &&
  527. ((dev->bus->self->device == PCI_DEVICE_ID_INTEL_I960) ||
  528. (dev->bus->self->device == PCI_DEVICE_ID_INTEL_I960RM))) {
  529. printk(KERN_INFO "ide: Skipping Promise PDC20265 "
  530. "attached to I2O RAID controller.\n");
  531. return -ENODEV;
  532. }
  533. return ide_setup_pci_device(dev, d);
  534. }
  535. static int __devinit init_setup_pdc202xx(struct pci_dev *dev,
  536. ide_pci_device_t *d)
  537. {
  538. return ide_setup_pci_device(dev, d);
  539. }
  540. static ide_pci_device_t pdc202xx_chipsets[] __devinitdata = {
  541. { /* 0 */
  542. .name = "PDC20246",
  543. .init_setup = init_setup_pdc202ata4,
  544. .init_chipset = init_chipset_pdc202xx,
  545. .init_hwif = init_hwif_pdc202xx,
  546. .init_dma = init_dma_pdc202xx,
  547. .channels = 2,
  548. .autodma = AUTODMA,
  549. .bootable = OFF_BOARD,
  550. .extra = 16,
  551. },{ /* 1 */
  552. .name = "PDC20262",
  553. .init_setup = init_setup_pdc202ata4,
  554. .init_chipset = init_chipset_pdc202xx,
  555. .init_hwif = init_hwif_pdc202xx,
  556. .init_dma = init_dma_pdc202xx,
  557. .channels = 2,
  558. .autodma = AUTODMA,
  559. .bootable = OFF_BOARD,
  560. .extra = 48,
  561. },{ /* 2 */
  562. .name = "PDC20263",
  563. .init_setup = init_setup_pdc202ata4,
  564. .init_chipset = init_chipset_pdc202xx,
  565. .init_hwif = init_hwif_pdc202xx,
  566. .init_dma = init_dma_pdc202xx,
  567. .channels = 2,
  568. .autodma = AUTODMA,
  569. .bootable = OFF_BOARD,
  570. .extra = 48,
  571. },{ /* 3 */
  572. .name = "PDC20265",
  573. .init_setup = init_setup_pdc20265,
  574. .init_chipset = init_chipset_pdc202xx,
  575. .init_hwif = init_hwif_pdc202xx,
  576. .init_dma = init_dma_pdc202xx,
  577. .channels = 2,
  578. .autodma = AUTODMA,
  579. .bootable = OFF_BOARD,
  580. .extra = 48,
  581. },{ /* 4 */
  582. .name = "PDC20267",
  583. .init_setup = init_setup_pdc202xx,
  584. .init_chipset = init_chipset_pdc202xx,
  585. .init_hwif = init_hwif_pdc202xx,
  586. .init_dma = init_dma_pdc202xx,
  587. .channels = 2,
  588. .autodma = AUTODMA,
  589. .bootable = OFF_BOARD,
  590. .extra = 48,
  591. }
  592. };
  593. /**
  594. * pdc202xx_init_one - called when a PDC202xx is found
  595. * @dev: the pdc202xx device
  596. * @id: the matching pci id
  597. *
  598. * Called when the PCI registration layer (or the IDE initialization)
  599. * finds a device matching our IDE device tables.
  600. */
  601. static int __devinit pdc202xx_init_one(struct pci_dev *dev, const struct pci_device_id *id)
  602. {
  603. ide_pci_device_t *d = &pdc202xx_chipsets[id->driver_data];
  604. return d->init_setup(dev, d);
  605. }
  606. static struct pci_device_id pdc202xx_pci_tbl[] = {
  607. { PCI_VENDOR_ID_PROMISE, PCI_DEVICE_ID_PROMISE_20246, PCI_ANY_ID, PCI_ANY_ID, 0, 0, 0},
  608. { PCI_VENDOR_ID_PROMISE, PCI_DEVICE_ID_PROMISE_20262, PCI_ANY_ID, PCI_ANY_ID, 0, 0, 1},
  609. { PCI_VENDOR_ID_PROMISE, PCI_DEVICE_ID_PROMISE_20263, PCI_ANY_ID, PCI_ANY_ID, 0, 0, 2},
  610. { PCI_VENDOR_ID_PROMISE, PCI_DEVICE_ID_PROMISE_20265, PCI_ANY_ID, PCI_ANY_ID, 0, 0, 3},
  611. { PCI_VENDOR_ID_PROMISE, PCI_DEVICE_ID_PROMISE_20267, PCI_ANY_ID, PCI_ANY_ID, 0, 0, 4},
  612. { 0, },
  613. };
  614. MODULE_DEVICE_TABLE(pci, pdc202xx_pci_tbl);
  615. static struct pci_driver driver = {
  616. .name = "Promise_Old_IDE",
  617. .id_table = pdc202xx_pci_tbl,
  618. .probe = pdc202xx_init_one,
  619. };
  620. static int pdc202xx_ide_init(void)
  621. {
  622. return ide_pci_register_driver(&driver);
  623. }
  624. module_init(pdc202xx_ide_init);
  625. MODULE_AUTHOR("Andre Hedrick, Frank Tiernan");
  626. MODULE_DESCRIPTION("PCI driver module for older Promise IDE");
  627. MODULE_LICENSE("GPL");