pdc202xx_old.c 25 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892
  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/config.h>
  30. #include <linux/types.h>
  31. #include <linux/module.h>
  32. #include <linux/kernel.h>
  33. #include <linux/delay.h>
  34. #include <linux/timer.h>
  35. #include <linux/mm.h>
  36. #include <linux/ioport.h>
  37. #include <linux/blkdev.h>
  38. #include <linux/hdreg.h>
  39. #include <linux/interrupt.h>
  40. #include <linux/pci.h>
  41. #include <linux/init.h>
  42. #include <linux/ide.h>
  43. #include <asm/io.h>
  44. #include <asm/irq.h>
  45. #define PDC202_DEBUG_CABLE 0
  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. /* A Register */
  59. #define SYNC_ERRDY_EN 0xC0
  60. #define SYNC_IN 0x80 /* control bit, different for master vs. slave drives */
  61. #define ERRDY_EN 0x40 /* control bit, different for master vs. slave drives */
  62. #define IORDY_EN 0x20 /* PIO: IOREADY */
  63. #define PREFETCH_EN 0x10 /* PIO: PREFETCH */
  64. #define PA3 0x08 /* PIO"A" timing */
  65. #define PA2 0x04 /* PIO"A" timing */
  66. #define PA1 0x02 /* PIO"A" timing */
  67. #define PA0 0x01 /* PIO"A" timing */
  68. /* B Register */
  69. #define MB2 0x80 /* DMA"B" timing */
  70. #define MB1 0x40 /* DMA"B" timing */
  71. #define MB0 0x20 /* DMA"B" timing */
  72. #define PB4 0x10 /* PIO_FORCE 1:0 */
  73. #define PB3 0x08 /* PIO"B" timing */ /* PIO flow Control mode */
  74. #define PB2 0x04 /* PIO"B" timing */ /* PIO 4 */
  75. #define PB1 0x02 /* PIO"B" timing */ /* PIO 3 half */
  76. #define PB0 0x01 /* PIO"B" timing */ /* PIO 3 other half */
  77. /* C Register */
  78. #define IORDYp_NO_SPEED 0x4F
  79. #define SPEED_DIS 0x0F
  80. #define DMARQp 0x80
  81. #define IORDYp 0x40
  82. #define DMAR_EN 0x20
  83. #define DMAW_EN 0x10
  84. #define MC3 0x08 /* DMA"C" timing */
  85. #define MC2 0x04 /* DMA"C" timing */
  86. #define MC1 0x02 /* DMA"C" timing */
  87. #define MC0 0x01 /* DMA"C" timing */
  88. #if 0
  89. unsigned long bibma = pci_resource_start(dev, 4);
  90. u8 hi = 0, lo = 0;
  91. u8 sc1c = inb_p((u16)bibma + 0x1c);
  92. u8 sc1e = inb_p((u16)bibma + 0x1e);
  93. u8 sc1f = inb_p((u16)bibma + 0x1f);
  94. p += sprintf(p, "Host Mode : %s\n",
  95. (sc1f & 0x08) ? "Tri-Stated" : "Normal");
  96. p += sprintf(p, "Bus Clocking : %s\n",
  97. ((sc1f & 0xC0) == 0xC0) ? "100 External" :
  98. ((sc1f & 0x80) == 0x80) ? "66 External" :
  99. ((sc1f & 0x40) == 0x40) ? "33 External" : "33 PCI Internal");
  100. p += sprintf(p, "IO pad select : %s mA\n",
  101. ((sc1c & 0x03) == 0x03) ? "10" :
  102. ((sc1c & 0x02) == 0x02) ? "8" :
  103. ((sc1c & 0x01) == 0x01) ? "6" :
  104. ((sc1c & 0x00) == 0x00) ? "4" : "??");
  105. hi = sc1e >> 4;
  106. lo = sc1e & 0xf;
  107. p += sprintf(p, "Status Polling Period : %d\n", hi);
  108. p += sprintf(p, "Interrupt Check Status Polling Delay : %d\n", lo);
  109. #endif
  110. static u8 pdc202xx_ratemask (ide_drive_t *drive)
  111. {
  112. u8 mode;
  113. switch(HWIF(drive)->pci_dev->device) {
  114. case PCI_DEVICE_ID_PROMISE_20267:
  115. case PCI_DEVICE_ID_PROMISE_20265:
  116. mode = 3;
  117. break;
  118. case PCI_DEVICE_ID_PROMISE_20263:
  119. case PCI_DEVICE_ID_PROMISE_20262:
  120. mode = 2;
  121. break;
  122. case PCI_DEVICE_ID_PROMISE_20246:
  123. return 1;
  124. default:
  125. return 0;
  126. }
  127. if (!eighty_ninty_three(drive))
  128. mode = min(mode, (u8)1);
  129. return mode;
  130. }
  131. static int check_in_drive_lists (ide_drive_t *drive, const char **list)
  132. {
  133. struct hd_driveid *id = drive->id;
  134. if (pdc_quirk_drives == list) {
  135. while (*list) {
  136. if (strstr(id->model, *list++)) {
  137. return 2;
  138. }
  139. }
  140. } else {
  141. while (*list) {
  142. if (!strcmp(*list++,id->model)) {
  143. return 1;
  144. }
  145. }
  146. }
  147. return 0;
  148. }
  149. static int pdc202xx_tune_chipset (ide_drive_t *drive, u8 xferspeed)
  150. {
  151. ide_hwif_t *hwif = HWIF(drive);
  152. struct pci_dev *dev = hwif->pci_dev;
  153. u8 drive_pci = 0x60 + (drive->dn << 2);
  154. u8 speed = ide_rate_filter(pdc202xx_ratemask(drive), xferspeed);
  155. u32 drive_conf;
  156. u8 AP, BP, CP, DP;
  157. u8 TA = 0, TB = 0, TC = 0;
  158. if ((drive->media != ide_disk) && (speed < XFER_SW_DMA_0))
  159. return -1;
  160. pci_read_config_dword(dev, drive_pci, &drive_conf);
  161. pci_read_config_byte(dev, (drive_pci), &AP);
  162. pci_read_config_byte(dev, (drive_pci)|0x01, &BP);
  163. pci_read_config_byte(dev, (drive_pci)|0x02, &CP);
  164. pci_read_config_byte(dev, (drive_pci)|0x03, &DP);
  165. if (speed < XFER_SW_DMA_0) {
  166. if ((AP & 0x0F) || (BP & 0x07)) {
  167. /* clear PIO modes of lower 8421 bits of A Register */
  168. pci_write_config_byte(dev, (drive_pci), AP &~0x0F);
  169. pci_read_config_byte(dev, (drive_pci), &AP);
  170. /* clear PIO modes of lower 421 bits of B Register */
  171. pci_write_config_byte(dev, (drive_pci)|0x01, BP &~0x07);
  172. pci_read_config_byte(dev, (drive_pci)|0x01, &BP);
  173. pci_read_config_byte(dev, (drive_pci), &AP);
  174. pci_read_config_byte(dev, (drive_pci)|0x01, &BP);
  175. }
  176. } else {
  177. if ((BP & 0xF0) && (CP & 0x0F)) {
  178. /* clear DMA modes of upper 842 bits of B Register */
  179. /* clear PIO forced mode upper 1 bit of B Register */
  180. pci_write_config_byte(dev, (drive_pci)|0x01, BP &~0xF0);
  181. pci_read_config_byte(dev, (drive_pci)|0x01, &BP);
  182. /* clear DMA modes of lower 8421 bits of C Register */
  183. pci_write_config_byte(dev, (drive_pci)|0x02, CP &~0x0F);
  184. pci_read_config_byte(dev, (drive_pci)|0x02, &CP);
  185. }
  186. }
  187. pci_read_config_byte(dev, (drive_pci), &AP);
  188. pci_read_config_byte(dev, (drive_pci)|0x01, &BP);
  189. pci_read_config_byte(dev, (drive_pci)|0x02, &CP);
  190. switch(speed) {
  191. case XFER_UDMA_6: speed = XFER_UDMA_5;
  192. case XFER_UDMA_5:
  193. case XFER_UDMA_4: TB = 0x20; TC = 0x01; break;
  194. case XFER_UDMA_2: TB = 0x20; TC = 0x01; break;
  195. case XFER_UDMA_3:
  196. case XFER_UDMA_1: TB = 0x40; TC = 0x02; break;
  197. case XFER_UDMA_0:
  198. case XFER_MW_DMA_2: TB = 0x60; TC = 0x03; break;
  199. case XFER_MW_DMA_1: TB = 0x60; TC = 0x04; break;
  200. case XFER_MW_DMA_0:
  201. case XFER_SW_DMA_2: TB = 0x60; TC = 0x05; break;
  202. case XFER_SW_DMA_1: TB = 0x80; TC = 0x06; break;
  203. case XFER_SW_DMA_0: TB = 0xC0; TC = 0x0B; break;
  204. case XFER_PIO_4: TA = 0x01; TB = 0x04; break;
  205. case XFER_PIO_3: TA = 0x02; TB = 0x06; break;
  206. case XFER_PIO_2: TA = 0x03; TB = 0x08; break;
  207. case XFER_PIO_1: TA = 0x05; TB = 0x0C; break;
  208. case XFER_PIO_0:
  209. default: TA = 0x09; TB = 0x13; break;
  210. }
  211. if (speed < XFER_SW_DMA_0) {
  212. pci_write_config_byte(dev, (drive_pci), AP|TA);
  213. pci_write_config_byte(dev, (drive_pci)|0x01, BP|TB);
  214. } else {
  215. pci_write_config_byte(dev, (drive_pci)|0x01, BP|TB);
  216. pci_write_config_byte(dev, (drive_pci)|0x02, CP|TC);
  217. }
  218. #if PDC202XX_DEBUG_DRIVE_INFO
  219. printk(KERN_DEBUG "%s: %s drive%d 0x%08x ",
  220. drive->name, ide_xfer_verbose(speed),
  221. drive->dn, drive_conf);
  222. pci_read_config_dword(dev, drive_pci, &drive_conf);
  223. printk("0x%08x\n", drive_conf);
  224. #endif /* PDC202XX_DEBUG_DRIVE_INFO */
  225. return (ide_config_drive_speed(drive, speed));
  226. }
  227. /* 0 1 2 3 4 5 6 7 8
  228. * 960, 480, 390, 300, 240, 180, 120, 90, 60
  229. * 180, 150, 120, 90, 60
  230. * DMA_Speed
  231. * 180, 120, 90, 90, 90, 60, 30
  232. * 11, 5, 4, 3, 2, 1, 0
  233. */
  234. static void config_chipset_for_pio (ide_drive_t *drive, u8 pio)
  235. {
  236. u8 speed = 0;
  237. if (pio == 5) pio = 4;
  238. speed = XFER_PIO_0 + ide_get_best_pio_mode(drive, 255, pio, NULL);
  239. pdc202xx_tune_chipset(drive, speed);
  240. }
  241. static u8 pdc202xx_old_cable_detect (ide_hwif_t *hwif)
  242. {
  243. u16 CIS = 0, mask = (hwif->channel) ? (1<<11) : (1<<10);
  244. pci_read_config_word(hwif->pci_dev, 0x50, &CIS);
  245. return (CIS & mask) ? 1 : 0;
  246. }
  247. /*
  248. * Set the control register to use the 66MHz system
  249. * clock for UDMA 3/4/5 mode operation when necessary.
  250. *
  251. * It may also be possible to leave the 66MHz clock on
  252. * and readjust the timing parameters.
  253. */
  254. static void pdc_old_enable_66MHz_clock(ide_hwif_t *hwif)
  255. {
  256. unsigned long clock_reg = hwif->dma_master + 0x11;
  257. u8 clock = hwif->INB(clock_reg);
  258. hwif->OUTB(clock | (hwif->channel ? 0x08 : 0x02), clock_reg);
  259. }
  260. static void pdc_old_disable_66MHz_clock(ide_hwif_t *hwif)
  261. {
  262. unsigned long clock_reg = hwif->dma_master + 0x11;
  263. u8 clock = hwif->INB(clock_reg);
  264. hwif->OUTB(clock & ~(hwif->channel ? 0x08 : 0x02), clock_reg);
  265. }
  266. static int config_chipset_for_dma (ide_drive_t *drive)
  267. {
  268. struct hd_driveid *id = drive->id;
  269. ide_hwif_t *hwif = HWIF(drive);
  270. struct pci_dev *dev = hwif->pci_dev;
  271. u32 drive_conf = 0;
  272. u8 drive_pci = 0x60 + (drive->dn << 2);
  273. u8 test1 = 0, test2 = 0, speed = -1;
  274. u8 AP = 0, cable = 0;
  275. u8 ultra_66 = ((id->dma_ultra & 0x0010) ||
  276. (id->dma_ultra & 0x0008)) ? 1 : 0;
  277. if (dev->device != PCI_DEVICE_ID_PROMISE_20246)
  278. cable = pdc202xx_old_cable_detect(hwif);
  279. else
  280. ultra_66 = 0;
  281. if (ultra_66 && cable) {
  282. printk(KERN_WARNING "Warning: %s channel requires an 80-pin cable for operation.\n", hwif->channel ? "Secondary":"Primary");
  283. printk(KERN_WARNING "%s reduced to Ultra33 mode.\n", drive->name);
  284. }
  285. if (dev->device != PCI_DEVICE_ID_PROMISE_20246)
  286. pdc_old_disable_66MHz_clock(drive->hwif);
  287. drive_pci = 0x60 + (drive->dn << 2);
  288. pci_read_config_dword(dev, drive_pci, &drive_conf);
  289. if ((drive_conf != 0x004ff304) && (drive_conf != 0x004ff3c4))
  290. goto chipset_is_set;
  291. pci_read_config_byte(dev, drive_pci, &test1);
  292. if (!(test1 & SYNC_ERRDY_EN)) {
  293. if (drive->select.b.unit & 0x01) {
  294. pci_read_config_byte(dev, drive_pci - 4, &test2);
  295. if ((test2 & SYNC_ERRDY_EN) &&
  296. !(test1 & SYNC_ERRDY_EN)) {
  297. pci_write_config_byte(dev, drive_pci,
  298. test1|SYNC_ERRDY_EN);
  299. }
  300. } else {
  301. pci_write_config_byte(dev, drive_pci,
  302. test1|SYNC_ERRDY_EN);
  303. }
  304. }
  305. chipset_is_set:
  306. if (drive->media == ide_disk) {
  307. pci_read_config_byte(dev, (drive_pci), &AP);
  308. if (id->capability & 4) /* IORDY_EN */
  309. pci_write_config_byte(dev, (drive_pci), AP|IORDY_EN);
  310. pci_read_config_byte(dev, (drive_pci), &AP);
  311. if (drive->media == ide_disk) /* PREFETCH_EN */
  312. pci_write_config_byte(dev, (drive_pci), AP|PREFETCH_EN);
  313. }
  314. speed = ide_dma_speed(drive, pdc202xx_ratemask(drive));
  315. if (!(speed)) {
  316. /* restore original pci-config space */
  317. pci_write_config_dword(dev, drive_pci, drive_conf);
  318. hwif->tuneproc(drive, 5);
  319. return 0;
  320. }
  321. (void) hwif->speedproc(drive, speed);
  322. return ide_dma_enable(drive);
  323. }
  324. static int pdc202xx_config_drive_xfer_rate (ide_drive_t *drive)
  325. {
  326. ide_hwif_t *hwif = HWIF(drive);
  327. struct hd_driveid *id = drive->id;
  328. drive->init_speed = 0;
  329. if (id && (id->capability & 1) && drive->autodma) {
  330. if (ide_use_dma(drive)) {
  331. if (config_chipset_for_dma(drive))
  332. return hwif->ide_dma_on(drive);
  333. }
  334. goto fast_ata_pio;
  335. } else if ((id->capability & 8) || (id->field_valid & 2)) {
  336. fast_ata_pio:
  337. hwif->tuneproc(drive, 5);
  338. return hwif->ide_dma_off_quietly(drive);
  339. }
  340. /* IORDY not supported */
  341. return 0;
  342. }
  343. static int pdc202xx_quirkproc (ide_drive_t *drive)
  344. {
  345. return ((int) check_in_drive_lists(drive, pdc_quirk_drives));
  346. }
  347. static void pdc202xx_old_ide_dma_start(ide_drive_t *drive)
  348. {
  349. if (drive->current_speed > XFER_UDMA_2)
  350. pdc_old_enable_66MHz_clock(drive->hwif);
  351. if (drive->addressing == 1) {
  352. struct request *rq = HWGROUP(drive)->rq;
  353. ide_hwif_t *hwif = HWIF(drive);
  354. // struct pci_dev *dev = hwif->pci_dev;
  355. // unsgned long high_16 = pci_resource_start(dev, 4);
  356. unsigned long high_16 = hwif->dma_master;
  357. unsigned long atapi_reg = high_16 + (hwif->channel ? 0x24 : 0x20);
  358. u32 word_count = 0;
  359. u8 clock = hwif->INB(high_16 + 0x11);
  360. hwif->OUTB(clock|(hwif->channel ? 0x08 : 0x02), high_16+0x11);
  361. word_count = (rq->nr_sectors << 8);
  362. word_count = (rq_data_dir(rq) == READ) ?
  363. word_count | 0x05000000 :
  364. word_count | 0x06000000;
  365. hwif->OUTL(word_count, atapi_reg);
  366. }
  367. ide_dma_start(drive);
  368. }
  369. static int pdc202xx_old_ide_dma_end(ide_drive_t *drive)
  370. {
  371. if (drive->addressing == 1) {
  372. ide_hwif_t *hwif = HWIF(drive);
  373. // unsigned long high_16 = pci_resource_start(hwif->pci_dev, 4);
  374. unsigned long high_16 = hwif->dma_master;
  375. unsigned long atapi_reg = high_16 + (hwif->channel ? 0x24 : 0x20);
  376. u8 clock = 0;
  377. hwif->OUTL(0, atapi_reg); /* zero out extra */
  378. clock = hwif->INB(high_16 + 0x11);
  379. hwif->OUTB(clock & ~(hwif->channel ? 0x08:0x02), high_16+0x11);
  380. }
  381. if (drive->current_speed > XFER_UDMA_2)
  382. pdc_old_disable_66MHz_clock(drive->hwif);
  383. return __ide_dma_end(drive);
  384. }
  385. static int pdc202xx_old_ide_dma_test_irq(ide_drive_t *drive)
  386. {
  387. ide_hwif_t *hwif = HWIF(drive);
  388. // struct pci_dev *dev = hwif->pci_dev;
  389. // unsigned long high_16 = pci_resource_start(dev, 4);
  390. unsigned long high_16 = hwif->dma_master;
  391. u8 dma_stat = hwif->INB(hwif->dma_status);
  392. u8 sc1d = hwif->INB((high_16 + 0x001d));
  393. if (hwif->channel) {
  394. /* bit7: Error, bit6: Interrupting, bit5: FIFO Full, bit4: FIFO Empty */
  395. if ((sc1d & 0x50) == 0x50)
  396. goto somebody_else;
  397. else if ((sc1d & 0x40) == 0x40)
  398. return (dma_stat & 4) == 4;
  399. } else {
  400. /* bit3: Error, bit2: Interrupting, bit1: FIFO Full, bit0: FIFO Empty */
  401. if ((sc1d & 0x05) == 0x05)
  402. goto somebody_else;
  403. else if ((sc1d & 0x04) == 0x04)
  404. return (dma_stat & 4) == 4;
  405. }
  406. somebody_else:
  407. return (dma_stat & 4) == 4; /* return 1 if INTR asserted */
  408. }
  409. static int pdc202xx_ide_dma_lostirq(ide_drive_t *drive)
  410. {
  411. if (HWIF(drive)->resetproc != NULL)
  412. HWIF(drive)->resetproc(drive);
  413. return __ide_dma_lostirq(drive);
  414. }
  415. static int pdc202xx_ide_dma_timeout(ide_drive_t *drive)
  416. {
  417. if (HWIF(drive)->resetproc != NULL)
  418. HWIF(drive)->resetproc(drive);
  419. return __ide_dma_timeout(drive);
  420. }
  421. static void pdc202xx_reset_host (ide_hwif_t *hwif)
  422. {
  423. #ifdef CONFIG_BLK_DEV_IDEDMA
  424. // unsigned long high_16 = hwif->dma_base - (8*(hwif->channel));
  425. unsigned long high_16 = hwif->dma_master;
  426. #else /* !CONFIG_BLK_DEV_IDEDMA */
  427. unsigned long high_16 = pci_resource_start(hwif->pci_dev, 4);
  428. #endif /* CONFIG_BLK_DEV_IDEDMA */
  429. u8 udma_speed_flag = hwif->INB(high_16|0x001f);
  430. hwif->OUTB((udma_speed_flag | 0x10), (high_16|0x001f));
  431. mdelay(100);
  432. hwif->OUTB((udma_speed_flag & ~0x10), (high_16|0x001f));
  433. mdelay(2000); /* 2 seconds ?! */
  434. printk(KERN_WARNING "PDC202XX: %s channel reset.\n",
  435. hwif->channel ? "Secondary" : "Primary");
  436. }
  437. static void pdc202xx_reset (ide_drive_t *drive)
  438. {
  439. ide_hwif_t *hwif = HWIF(drive);
  440. ide_hwif_t *mate = hwif->mate;
  441. pdc202xx_reset_host(hwif);
  442. pdc202xx_reset_host(mate);
  443. #if 0
  444. /*
  445. * FIXME: Have to kick all the drives again :-/
  446. * What a pain in the ACE!
  447. */
  448. if (hwif->present) {
  449. u16 hunit = 0;
  450. for (hunit = 0; hunit < MAX_DRIVES; ++hunit) {
  451. ide_drive_t *hdrive = &hwif->drives[hunit];
  452. if (hdrive->present) {
  453. if (hwif->ide_dma_check)
  454. hwif->ide_dma_check(hdrive);
  455. else
  456. hwif->tuneproc(hdrive, 5);
  457. }
  458. }
  459. }
  460. if (mate->present) {
  461. u16 munit = 0;
  462. for (munit = 0; munit < MAX_DRIVES; ++munit) {
  463. ide_drive_t *mdrive = &mate->drives[munit];
  464. if (mdrive->present) {
  465. if (mate->ide_dma_check)
  466. mate->ide_dma_check(mdrive);
  467. else
  468. mate->tuneproc(mdrive, 5);
  469. }
  470. }
  471. }
  472. #else
  473. hwif->tuneproc(drive, 5);
  474. #endif
  475. }
  476. /*
  477. * Since SUN Cobalt is attempting to do this operation, I should disclose
  478. * this has been a long time ago Thu Jul 27 16:40:57 2000 was the patch date
  479. * HOTSWAP ATA Infrastructure.
  480. */
  481. static int pdc202xx_tristate (ide_drive_t * drive, int state)
  482. {
  483. ide_hwif_t *hwif = HWIF(drive);
  484. // unsigned long high_16 = hwif->dma_base - (8*(hwif->channel));
  485. unsigned long high_16 = hwif->dma_master;
  486. u8 sc1f = hwif->INB(high_16|0x001f);
  487. if (!hwif)
  488. return -EINVAL;
  489. // hwif->bus_state = state;
  490. if (state) {
  491. hwif->OUTB(sc1f | 0x08, (high_16|0x001f));
  492. } else {
  493. hwif->OUTB(sc1f & ~0x08, (high_16|0x001f));
  494. }
  495. return 0;
  496. }
  497. static unsigned int __devinit init_chipset_pdc202xx(struct pci_dev *dev, const char *name)
  498. {
  499. if (dev->resource[PCI_ROM_RESOURCE].start) {
  500. pci_write_config_dword(dev, PCI_ROM_ADDRESS,
  501. dev->resource[PCI_ROM_RESOURCE].start | PCI_ROM_ADDRESS_ENABLE);
  502. printk(KERN_INFO "%s: ROM enabled at 0x%08lx\n",
  503. name, dev->resource[PCI_ROM_RESOURCE].start);
  504. }
  505. /*
  506. * software reset - this is required because the bios
  507. * will set UDMA timing on if the hdd supports it. The
  508. * user may want to turn udma off. A bug in the pdc20262
  509. * is that it cannot handle a downgrade in timing from
  510. * UDMA to DMA. Disk accesses after issuing a set
  511. * feature command will result in errors. A software
  512. * reset leaves the timing registers intact,
  513. * but resets the drives.
  514. */
  515. #if 0
  516. if ((dev->device == PCI_DEVICE_ID_PROMISE_20267) ||
  517. (dev->device == PCI_DEVICE_ID_PROMISE_20265) ||
  518. (dev->device == PCI_DEVICE_ID_PROMISE_20263) ||
  519. (dev->device == PCI_DEVICE_ID_PROMISE_20262)) {
  520. unsigned long high_16 = pci_resource_start(dev, 4);
  521. byte udma_speed_flag = inb(high_16 + 0x001f);
  522. outb(udma_speed_flag | 0x10, high_16 + 0x001f);
  523. mdelay(100);
  524. outb(udma_speed_flag & ~0x10, high_16 + 0x001f);
  525. mdelay(2000); /* 2 seconds ?! */
  526. }
  527. #endif
  528. return dev->irq;
  529. }
  530. static void __devinit init_hwif_pdc202xx(ide_hwif_t *hwif)
  531. {
  532. struct pci_dev *dev = hwif->pci_dev;
  533. /* PDC20265 has problems with large LBA48 requests */
  534. if ((dev->device == PCI_DEVICE_ID_PROMISE_20267) ||
  535. (dev->device == PCI_DEVICE_ID_PROMISE_20265))
  536. hwif->rqsize = 256;
  537. hwif->autodma = 0;
  538. hwif->tuneproc = &config_chipset_for_pio;
  539. hwif->quirkproc = &pdc202xx_quirkproc;
  540. if (hwif->pci_dev->device != PCI_DEVICE_ID_PROMISE_20246) {
  541. hwif->busproc = &pdc202xx_tristate;
  542. hwif->resetproc = &pdc202xx_reset;
  543. }
  544. hwif->speedproc = &pdc202xx_tune_chipset;
  545. hwif->drives[0].autotune = hwif->drives[1].autotune = 1;
  546. hwif->ultra_mask = 0x3f;
  547. hwif->mwdma_mask = 0x07;
  548. hwif->swdma_mask = 0x07;
  549. hwif->ide_dma_check = &pdc202xx_config_drive_xfer_rate;
  550. hwif->ide_dma_lostirq = &pdc202xx_ide_dma_lostirq;
  551. hwif->ide_dma_timeout = &pdc202xx_ide_dma_timeout;
  552. if (hwif->pci_dev->device != PCI_DEVICE_ID_PROMISE_20246) {
  553. if (!(hwif->udma_four))
  554. hwif->udma_four = (pdc202xx_old_cable_detect(hwif)) ? 0 : 1;
  555. hwif->dma_start = &pdc202xx_old_ide_dma_start;
  556. hwif->ide_dma_end = &pdc202xx_old_ide_dma_end;
  557. }
  558. hwif->ide_dma_test_irq = &pdc202xx_old_ide_dma_test_irq;
  559. if (!noautodma)
  560. hwif->autodma = 1;
  561. hwif->drives[0].autodma = hwif->drives[1].autodma = hwif->autodma;
  562. #if PDC202_DEBUG_CABLE
  563. printk(KERN_DEBUG "%s: %s-pin cable\n",
  564. hwif->name, hwif->udma_four ? "80" : "40");
  565. #endif /* PDC202_DEBUG_CABLE */
  566. }
  567. static void __devinit init_dma_pdc202xx(ide_hwif_t *hwif, unsigned long dmabase)
  568. {
  569. u8 udma_speed_flag = 0, primary_mode = 0, secondary_mode = 0;
  570. if (hwif->channel) {
  571. ide_setup_dma(hwif, dmabase, 8);
  572. return;
  573. }
  574. udma_speed_flag = hwif->INB((dmabase|0x1f));
  575. primary_mode = hwif->INB((dmabase|0x1a));
  576. secondary_mode = hwif->INB((dmabase|0x1b));
  577. printk(KERN_INFO "%s: (U)DMA Burst Bit %sABLED " \
  578. "Primary %s Mode " \
  579. "Secondary %s Mode.\n", hwif->cds->name,
  580. (udma_speed_flag & 1) ? "EN" : "DIS",
  581. (primary_mode & 1) ? "MASTER" : "PCI",
  582. (secondary_mode & 1) ? "MASTER" : "PCI" );
  583. #ifdef CONFIG_PDC202XX_BURST
  584. if (!(udma_speed_flag & 1)) {
  585. printk(KERN_INFO "%s: FORCING BURST BIT 0x%02x->0x%02x ",
  586. hwif->cds->name, udma_speed_flag,
  587. (udma_speed_flag|1));
  588. hwif->OUTB(udma_speed_flag|1,(dmabase|0x1f));
  589. printk("%sACTIVE\n",
  590. (hwif->INB(dmabase|0x1f)&1) ? "":"IN");
  591. }
  592. #endif /* CONFIG_PDC202XX_BURST */
  593. #ifdef CONFIG_PDC202XX_MASTER
  594. if (!(primary_mode & 1)) {
  595. printk(KERN_INFO "%s: FORCING PRIMARY MODE BIT "
  596. "0x%02x -> 0x%02x ", hwif->cds->name,
  597. primary_mode, (primary_mode|1));
  598. hwif->OUTB(primary_mode|1, (dmabase|0x1a));
  599. printk("%s\n",
  600. (hwif->INB((dmabase|0x1a)) & 1) ? "MASTER" : "PCI");
  601. }
  602. if (!(secondary_mode & 1)) {
  603. printk(KERN_INFO "%s: FORCING SECONDARY MODE BIT "
  604. "0x%02x -> 0x%02x ", hwif->cds->name,
  605. secondary_mode, (secondary_mode|1));
  606. hwif->OUTB(secondary_mode|1, (dmabase|0x1b));
  607. printk("%s\n",
  608. (hwif->INB((dmabase|0x1b)) & 1) ? "MASTER" : "PCI");
  609. }
  610. #endif /* CONFIG_PDC202XX_MASTER */
  611. ide_setup_dma(hwif, dmabase, 8);
  612. }
  613. static int __devinit init_setup_pdc202ata4(struct pci_dev *dev,
  614. ide_pci_device_t *d)
  615. {
  616. if ((dev->class >> 8) != PCI_CLASS_STORAGE_IDE) {
  617. u8 irq = 0, irq2 = 0;
  618. pci_read_config_byte(dev, PCI_INTERRUPT_LINE, &irq);
  619. /* 0xbc */
  620. pci_read_config_byte(dev, (PCI_INTERRUPT_LINE)|0x80, &irq2);
  621. if (irq != irq2) {
  622. pci_write_config_byte(dev,
  623. (PCI_INTERRUPT_LINE)|0x80, irq); /* 0xbc */
  624. printk(KERN_INFO "%s: pci-config space interrupt "
  625. "mirror fixed.\n", d->name);
  626. }
  627. }
  628. #if 0
  629. if (dev->device == PCI_DEVICE_ID_PROMISE_20262)
  630. if (e->reg && (pci_read_config_byte(dev, e->reg, &tmp) ||
  631. (tmp & e->mask) != e->val))
  632. if (d->enablebits[0].reg != d->enablebits[1].reg) {
  633. d->enablebits[0].reg = d->enablebits[1].reg;
  634. d->enablebits[0].mask = d->enablebits[1].mask;
  635. d->enablebits[0].val = d->enablebits[1].val;
  636. }
  637. #endif
  638. return ide_setup_pci_device(dev, d);
  639. }
  640. static int __devinit init_setup_pdc20265(struct pci_dev *dev,
  641. ide_pci_device_t *d)
  642. {
  643. if ((dev->bus->self) &&
  644. (dev->bus->self->vendor == PCI_VENDOR_ID_INTEL) &&
  645. ((dev->bus->self->device == PCI_DEVICE_ID_INTEL_I960) ||
  646. (dev->bus->self->device == PCI_DEVICE_ID_INTEL_I960RM))) {
  647. printk(KERN_INFO "ide: Skipping Promise PDC20265 "
  648. "attached to I2O RAID controller.\n");
  649. return -ENODEV;
  650. }
  651. #if 0
  652. {
  653. u8 pri = 0, sec = 0;
  654. if (e->reg && (pci_read_config_byte(dev, e->reg, &tmp) ||
  655. (tmp & e->mask) != e->val))
  656. if (d->enablebits[0].reg != d->enablebits[1].reg) {
  657. d->enablebits[0].reg = d->enablebits[1].reg;
  658. d->enablebits[0].mask = d->enablebits[1].mask;
  659. d->enablebits[0].val = d->enablebits[1].val;
  660. }
  661. }
  662. #endif
  663. return ide_setup_pci_device(dev, d);
  664. }
  665. static int __devinit init_setup_pdc202xx(struct pci_dev *dev,
  666. ide_pci_device_t *d)
  667. {
  668. return ide_setup_pci_device(dev, d);
  669. }
  670. static ide_pci_device_t pdc202xx_chipsets[] __devinitdata = {
  671. { /* 0 */
  672. .name = "PDC20246",
  673. .init_setup = init_setup_pdc202ata4,
  674. .init_chipset = init_chipset_pdc202xx,
  675. .init_hwif = init_hwif_pdc202xx,
  676. .init_dma = init_dma_pdc202xx,
  677. .channels = 2,
  678. .autodma = AUTODMA,
  679. #ifndef CONFIG_PDC202XX_FORCE
  680. .enablebits = {{0x50,0x02,0x02}, {0x50,0x04,0x04}},
  681. #endif
  682. .bootable = OFF_BOARD,
  683. .extra = 16,
  684. },{ /* 1 */
  685. .name = "PDC20262",
  686. .init_setup = init_setup_pdc202ata4,
  687. .init_chipset = init_chipset_pdc202xx,
  688. .init_hwif = init_hwif_pdc202xx,
  689. .init_dma = init_dma_pdc202xx,
  690. .channels = 2,
  691. .autodma = AUTODMA,
  692. #ifndef CONFIG_PDC202XX_FORCE
  693. .enablebits = {{0x50,0x02,0x02}, {0x50,0x04,0x04}},
  694. #endif
  695. .bootable = OFF_BOARD,
  696. .extra = 48,
  697. .flags = IDEPCI_FLAG_FORCE_PDC,
  698. },{ /* 2 */
  699. .name = "PDC20263",
  700. .init_setup = init_setup_pdc202ata4,
  701. .init_chipset = init_chipset_pdc202xx,
  702. .init_hwif = init_hwif_pdc202xx,
  703. .init_dma = init_dma_pdc202xx,
  704. .channels = 2,
  705. .autodma = AUTODMA,
  706. #ifndef CONFIG_PDC202XX_FORCE
  707. .enablebits = {{0x50,0x02,0x02}, {0x50,0x04,0x04}},
  708. #endif
  709. .bootable = OFF_BOARD,
  710. .extra = 48,
  711. },{ /* 3 */
  712. .name = "PDC20265",
  713. .init_setup = init_setup_pdc20265,
  714. .init_chipset = init_chipset_pdc202xx,
  715. .init_hwif = init_hwif_pdc202xx,
  716. .init_dma = init_dma_pdc202xx,
  717. .channels = 2,
  718. .autodma = AUTODMA,
  719. #ifndef CONFIG_PDC202XX_FORCE
  720. .enablebits = {{0x50,0x02,0x02}, {0x50,0x04,0x04}},
  721. #endif
  722. .bootable = OFF_BOARD,
  723. .extra = 48,
  724. .flags = IDEPCI_FLAG_FORCE_PDC,
  725. },{ /* 4 */
  726. .name = "PDC20267",
  727. .init_setup = init_setup_pdc202xx,
  728. .init_chipset = init_chipset_pdc202xx,
  729. .init_hwif = init_hwif_pdc202xx,
  730. .init_dma = init_dma_pdc202xx,
  731. .channels = 2,
  732. .autodma = AUTODMA,
  733. #ifndef CONFIG_PDC202XX_FORCE
  734. .enablebits = {{0x50,0x02,0x02}, {0x50,0x04,0x04}},
  735. #endif
  736. .bootable = OFF_BOARD,
  737. .extra = 48,
  738. }
  739. };
  740. /**
  741. * pdc202xx_init_one - called when a PDC202xx is found
  742. * @dev: the pdc202xx device
  743. * @id: the matching pci id
  744. *
  745. * Called when the PCI registration layer (or the IDE initialization)
  746. * finds a device matching our IDE device tables.
  747. */
  748. static int __devinit pdc202xx_init_one(struct pci_dev *dev, const struct pci_device_id *id)
  749. {
  750. ide_pci_device_t *d = &pdc202xx_chipsets[id->driver_data];
  751. return d->init_setup(dev, d);
  752. }
  753. static struct pci_device_id pdc202xx_pci_tbl[] = {
  754. { PCI_VENDOR_ID_PROMISE, PCI_DEVICE_ID_PROMISE_20246, PCI_ANY_ID, PCI_ANY_ID, 0, 0, 0},
  755. { PCI_VENDOR_ID_PROMISE, PCI_DEVICE_ID_PROMISE_20262, PCI_ANY_ID, PCI_ANY_ID, 0, 0, 1},
  756. { PCI_VENDOR_ID_PROMISE, PCI_DEVICE_ID_PROMISE_20263, PCI_ANY_ID, PCI_ANY_ID, 0, 0, 2},
  757. { PCI_VENDOR_ID_PROMISE, PCI_DEVICE_ID_PROMISE_20265, PCI_ANY_ID, PCI_ANY_ID, 0, 0, 3},
  758. { PCI_VENDOR_ID_PROMISE, PCI_DEVICE_ID_PROMISE_20267, PCI_ANY_ID, PCI_ANY_ID, 0, 0, 4},
  759. { 0, },
  760. };
  761. MODULE_DEVICE_TABLE(pci, pdc202xx_pci_tbl);
  762. static struct pci_driver driver = {
  763. .name = "Promise_Old_IDE",
  764. .id_table = pdc202xx_pci_tbl,
  765. .probe = pdc202xx_init_one,
  766. };
  767. static int pdc202xx_ide_init(void)
  768. {
  769. return ide_pci_register_driver(&driver);
  770. }
  771. module_init(pdc202xx_ide_init);
  772. MODULE_AUTHOR("Andre Hedrick, Frank Tiernan");
  773. MODULE_DESCRIPTION("PCI driver module for older Promise IDE");
  774. MODULE_LICENSE("GPL");