pata_pdc202xx_old.c 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422
  1. /*
  2. * pata_pdc202xx_old.c - Promise PDC202xx PATA for new ATA layer
  3. * (C) 2005 Red Hat Inc
  4. * Alan Cox <alan@redhat.com>
  5. *
  6. * Based in part on linux/drivers/ide/pci/pdc202xx_old.c
  7. *
  8. * First cut with LBA48/ATAPI
  9. *
  10. * TODO:
  11. * Channel interlock/reset on both required ?
  12. */
  13. #include <linux/kernel.h>
  14. #include <linux/module.h>
  15. #include <linux/pci.h>
  16. #include <linux/init.h>
  17. #include <linux/blkdev.h>
  18. #include <linux/delay.h>
  19. #include <scsi/scsi_host.h>
  20. #include <linux/libata.h>
  21. #define DRV_NAME "pata_pdc202xx_old"
  22. #define DRV_VERSION "0.2.1"
  23. /**
  24. * pdc2024x_pre_reset - probe begin
  25. * @ap: ATA port
  26. *
  27. * Set up cable type and use generic probe init
  28. */
  29. static int pdc2024x_pre_reset(struct ata_port *ap)
  30. {
  31. ap->cbl = ATA_CBL_PATA40;
  32. return ata_std_prereset(ap);
  33. }
  34. static void pdc2024x_error_handler(struct ata_port *ap)
  35. {
  36. ata_bmdma_drive_eh(ap, pdc2024x_pre_reset, ata_std_softreset, NULL, ata_std_postreset);
  37. }
  38. static int pdc2026x_pre_reset(struct ata_port *ap)
  39. {
  40. struct pci_dev *pdev = to_pci_dev(ap->host->dev);
  41. u16 cis;
  42. pci_read_config_word(pdev, 0x50, &cis);
  43. if (cis & (1 << (10 + ap->port_no)))
  44. ap->cbl = ATA_CBL_PATA80;
  45. else
  46. ap->cbl = ATA_CBL_PATA40;
  47. return ata_std_prereset(ap);
  48. }
  49. static void pdc2026x_error_handler(struct ata_port *ap)
  50. {
  51. ata_bmdma_drive_eh(ap, pdc2026x_pre_reset, ata_std_softreset, NULL, ata_std_postreset);
  52. }
  53. /**
  54. * pdc_configure_piomode - set chip PIO timing
  55. * @ap: ATA interface
  56. * @adev: ATA device
  57. * @pio: PIO mode
  58. *
  59. * Called to do the PIO mode setup. Our timing registers are shared
  60. * so a configure_dmamode call will undo any work we do here and vice
  61. * versa
  62. */
  63. static void pdc_configure_piomode(struct ata_port *ap, struct ata_device *adev, int pio)
  64. {
  65. struct pci_dev *pdev = to_pci_dev(ap->host->dev);
  66. int port = 0x60 + 4 * ap->port_no + 2 * adev->devno;
  67. static u16 pio_timing[5] = {
  68. 0x0913, 0x050C , 0x0308, 0x0206, 0x0104
  69. };
  70. u8 r_ap, r_bp;
  71. pci_read_config_byte(pdev, port, &r_ap);
  72. pci_read_config_byte(pdev, port + 1, &r_bp);
  73. r_ap &= ~0x3F; /* Preserve ERRDY_EN, SYNC_IN */
  74. r_bp &= ~0x07;
  75. r_ap |= (pio_timing[pio] >> 8);
  76. r_bp |= (pio_timing[pio] & 0xFF);
  77. if (ata_pio_need_iordy(adev))
  78. r_ap |= 0x20; /* IORDY enable */
  79. if (adev->class == ATA_DEV_ATA)
  80. r_ap |= 0x10; /* FIFO enable */
  81. pci_write_config_byte(pdev, port, r_ap);
  82. pci_write_config_byte(pdev, port + 1, r_bp);
  83. }
  84. /**
  85. * pdc_set_piomode - set initial PIO mode data
  86. * @ap: ATA interface
  87. * @adev: ATA device
  88. *
  89. * Called to do the PIO mode setup. Our timing registers are shared
  90. * but we want to set the PIO timing by default.
  91. */
  92. static void pdc_set_piomode(struct ata_port *ap, struct ata_device *adev)
  93. {
  94. pdc_configure_piomode(ap, adev, adev->pio_mode - XFER_PIO_0);
  95. }
  96. /**
  97. * pdc_configure_dmamode - set DMA mode in chip
  98. * @ap: ATA interface
  99. * @adev: ATA device
  100. *
  101. * Load DMA cycle times into the chip ready for a DMA transfer
  102. * to occur.
  103. */
  104. static void pdc_set_dmamode(struct ata_port *ap, struct ata_device *adev)
  105. {
  106. struct pci_dev *pdev = to_pci_dev(ap->host->dev);
  107. int port = 0x60 + 4 * ap->port_no + 2 * adev->devno;
  108. static u8 udma_timing[6][2] = {
  109. { 0x60, 0x03 }, /* 33 Mhz Clock */
  110. { 0x40, 0x02 },
  111. { 0x20, 0x01 },
  112. { 0x40, 0x02 }, /* 66 Mhz Clock */
  113. { 0x20, 0x01 },
  114. { 0x20, 0x01 }
  115. };
  116. u8 r_bp, r_cp;
  117. pci_read_config_byte(pdev, port + 1, &r_bp);
  118. pci_read_config_byte(pdev, port + 2, &r_cp);
  119. r_bp &= ~0xF0;
  120. r_cp &= ~0x0F;
  121. if (adev->dma_mode >= XFER_UDMA_0) {
  122. int speed = adev->dma_mode - XFER_UDMA_0;
  123. r_bp |= udma_timing[speed][0];
  124. r_cp |= udma_timing[speed][1];
  125. } else {
  126. int speed = adev->dma_mode - XFER_MW_DMA_0;
  127. r_bp |= 0x60;
  128. r_cp |= (5 - speed);
  129. }
  130. pci_write_config_byte(pdev, port + 1, r_bp);
  131. pci_write_config_byte(pdev, port + 2, r_cp);
  132. }
  133. /**
  134. * pdc2026x_bmdma_start - DMA engine begin
  135. * @qc: ATA command
  136. *
  137. * In UDMA3 or higher we have to clock switch for the duration of the
  138. * DMA transfer sequence.
  139. */
  140. static void pdc2026x_bmdma_start(struct ata_queued_cmd *qc)
  141. {
  142. struct ata_port *ap = qc->ap;
  143. struct ata_device *adev = qc->dev;
  144. struct ata_taskfile *tf = &qc->tf;
  145. int sel66 = ap->port_no ? 0x08: 0x02;
  146. unsigned long master = ap->host->ports[0]->ioaddr.bmdma_addr;
  147. unsigned long clock = master + 0x11;
  148. unsigned long atapi_reg = master + 0x20 + (4 * ap->port_no);
  149. u32 len;
  150. /* Check we keep host level locking here */
  151. if (adev->dma_mode >= XFER_UDMA_2)
  152. outb(inb(clock) | sel66, clock);
  153. else
  154. outb(inb(clock) & ~sel66, clock);
  155. /* The DMA clocks may have been trashed by a reset. FIXME: make conditional
  156. and move to qc_issue ? */
  157. pdc_set_dmamode(ap, qc->dev);
  158. /* Cases the state machine will not complete correctly without help */
  159. if ((tf->flags & ATA_TFLAG_LBA48) || tf->protocol == ATA_PROT_ATAPI_DMA)
  160. {
  161. if (tf->flags & ATA_TFLAG_LBA48)
  162. len = qc->nsect * 512;
  163. else
  164. len = qc->nbytes;
  165. if (tf->flags & ATA_TFLAG_WRITE)
  166. len |= 0x06000000;
  167. else
  168. len |= 0x05000000;
  169. outl(len, atapi_reg);
  170. }
  171. /* Activate DMA */
  172. ata_bmdma_start(qc);
  173. }
  174. /**
  175. * pdc2026x_bmdma_end - DMA engine stop
  176. * @qc: ATA command
  177. *
  178. * After a DMA completes we need to put the clock back to 33MHz for
  179. * PIO timings.
  180. */
  181. static void pdc2026x_bmdma_stop(struct ata_queued_cmd *qc)
  182. {
  183. struct ata_port *ap = qc->ap;
  184. struct ata_device *adev = qc->dev;
  185. struct ata_taskfile *tf = &qc->tf;
  186. int sel66 = ap->port_no ? 0x08: 0x02;
  187. /* The clock bits are in the same register for both channels */
  188. unsigned long master = ap->host->ports[0]->ioaddr.bmdma_addr;
  189. unsigned long clock = master + 0x11;
  190. unsigned long atapi_reg = master + 0x20 + (4 * ap->port_no);
  191. /* Cases the state machine will not complete correctly */
  192. if (tf->protocol == ATA_PROT_ATAPI_DMA || ( tf->flags & ATA_TFLAG_LBA48)) {
  193. outl(0, atapi_reg);
  194. outb(inb(clock) & ~sel66, clock);
  195. }
  196. /* Check we keep host level locking here */
  197. /* Flip back to 33Mhz for PIO */
  198. if (adev->dma_mode >= XFER_UDMA_2)
  199. outb(inb(clock) & ~sel66, clock);
  200. ata_bmdma_stop(qc);
  201. }
  202. /**
  203. * pdc2026x_dev_config - device setup hook
  204. * @ap: ATA port
  205. * @adev: newly found device
  206. *
  207. * Perform chip specific early setup. We need to lock the transfer
  208. * sizes to 8bit to avoid making the state engine on the 2026x cards
  209. * barf.
  210. */
  211. static void pdc2026x_dev_config(struct ata_port *ap, struct ata_device *adev)
  212. {
  213. adev->max_sectors = 256;
  214. }
  215. static struct scsi_host_template pdc_sht = {
  216. .module = THIS_MODULE,
  217. .name = DRV_NAME,
  218. .ioctl = ata_scsi_ioctl,
  219. .queuecommand = ata_scsi_queuecmd,
  220. .can_queue = ATA_DEF_QUEUE,
  221. .this_id = ATA_SHT_THIS_ID,
  222. .sg_tablesize = LIBATA_MAX_PRD,
  223. .max_sectors = ATA_MAX_SECTORS,
  224. .cmd_per_lun = ATA_SHT_CMD_PER_LUN,
  225. .emulated = ATA_SHT_EMULATED,
  226. .use_clustering = ATA_SHT_USE_CLUSTERING,
  227. .proc_name = DRV_NAME,
  228. .dma_boundary = ATA_DMA_BOUNDARY,
  229. .slave_configure = ata_scsi_slave_config,
  230. .bios_param = ata_std_bios_param,
  231. };
  232. static struct ata_port_operations pdc2024x_port_ops = {
  233. .port_disable = ata_port_disable,
  234. .set_piomode = pdc_set_piomode,
  235. .set_dmamode = pdc_set_dmamode,
  236. .mode_filter = ata_pci_default_filter,
  237. .tf_load = ata_tf_load,
  238. .tf_read = ata_tf_read,
  239. .check_status = ata_check_status,
  240. .exec_command = ata_exec_command,
  241. .dev_select = ata_std_dev_select,
  242. .freeze = ata_bmdma_freeze,
  243. .thaw = ata_bmdma_thaw,
  244. .error_handler = pdc2024x_error_handler,
  245. .post_internal_cmd = ata_bmdma_post_internal_cmd,
  246. .bmdma_setup = ata_bmdma_setup,
  247. .bmdma_start = ata_bmdma_start,
  248. .bmdma_stop = ata_bmdma_stop,
  249. .bmdma_status = ata_bmdma_status,
  250. .qc_prep = ata_qc_prep,
  251. .qc_issue = ata_qc_issue_prot,
  252. .data_xfer = ata_pio_data_xfer,
  253. .irq_handler = ata_interrupt,
  254. .irq_clear = ata_bmdma_irq_clear,
  255. .port_start = ata_port_start,
  256. .port_stop = ata_port_stop,
  257. .host_stop = ata_host_stop
  258. };
  259. static struct ata_port_operations pdc2026x_port_ops = {
  260. .port_disable = ata_port_disable,
  261. .set_piomode = pdc_set_piomode,
  262. .set_dmamode = pdc_set_dmamode,
  263. .mode_filter = ata_pci_default_filter,
  264. .tf_load = ata_tf_load,
  265. .tf_read = ata_tf_read,
  266. .check_status = ata_check_status,
  267. .exec_command = ata_exec_command,
  268. .dev_select = ata_std_dev_select,
  269. .dev_config = pdc2026x_dev_config,
  270. .freeze = ata_bmdma_freeze,
  271. .thaw = ata_bmdma_thaw,
  272. .error_handler = pdc2026x_error_handler,
  273. .post_internal_cmd = ata_bmdma_post_internal_cmd,
  274. .bmdma_setup = ata_bmdma_setup,
  275. .bmdma_start = pdc2026x_bmdma_start,
  276. .bmdma_stop = pdc2026x_bmdma_stop,
  277. .bmdma_status = ata_bmdma_status,
  278. .qc_prep = ata_qc_prep,
  279. .qc_issue = ata_qc_issue_prot,
  280. .data_xfer = ata_pio_data_xfer,
  281. .irq_handler = ata_interrupt,
  282. .irq_clear = ata_bmdma_irq_clear,
  283. .port_start = ata_port_start,
  284. .port_stop = ata_port_stop,
  285. .host_stop = ata_host_stop
  286. };
  287. static int pdc_init_one(struct pci_dev *dev, const struct pci_device_id *id)
  288. {
  289. static struct ata_port_info info[3] = {
  290. {
  291. .sht = &pdc_sht,
  292. .flags = ATA_FLAG_SLAVE_POSS | ATA_FLAG_SRST,
  293. .pio_mask = 0x1f,
  294. .mwdma_mask = 0x07,
  295. .udma_mask = ATA_UDMA2,
  296. .port_ops = &pdc2024x_port_ops
  297. },
  298. {
  299. .sht = &pdc_sht,
  300. .flags = ATA_FLAG_SLAVE_POSS | ATA_FLAG_SRST,
  301. .pio_mask = 0x1f,
  302. .mwdma_mask = 0x07,
  303. .udma_mask = ATA_UDMA4,
  304. .port_ops = &pdc2026x_port_ops
  305. },
  306. {
  307. .sht = &pdc_sht,
  308. .flags = ATA_FLAG_SLAVE_POSS | ATA_FLAG_SRST,
  309. .pio_mask = 0x1f,
  310. .mwdma_mask = 0x07,
  311. .udma_mask = ATA_UDMA5,
  312. .port_ops = &pdc2026x_port_ops
  313. }
  314. };
  315. static struct ata_port_info *port_info[2];
  316. port_info[0] = port_info[1] = &info[id->driver_data];
  317. if (dev->device == PCI_DEVICE_ID_PROMISE_20265) {
  318. struct pci_dev *bridge = dev->bus->self;
  319. /* Don't grab anything behind a Promise I2O RAID */
  320. if (bridge && bridge->vendor == PCI_VENDOR_ID_INTEL) {
  321. if( bridge->device == PCI_DEVICE_ID_INTEL_I960)
  322. return -ENODEV;
  323. if( bridge->device == PCI_DEVICE_ID_INTEL_I960RM)
  324. return -ENODEV;
  325. }
  326. }
  327. return ata_pci_init_one(dev, port_info, 2);
  328. }
  329. static const struct pci_device_id pdc[] = {
  330. { PCI_VDEVICE(PROMISE, PCI_DEVICE_ID_PROMISE_20246), 0 },
  331. { PCI_VDEVICE(PROMISE, PCI_DEVICE_ID_PROMISE_20262), 1 },
  332. { PCI_VDEVICE(PROMISE, PCI_DEVICE_ID_PROMISE_20263), 1 },
  333. { PCI_VDEVICE(PROMISE, PCI_DEVICE_ID_PROMISE_20265), 2 },
  334. { PCI_VDEVICE(PROMISE, PCI_DEVICE_ID_PROMISE_20267), 2 },
  335. { },
  336. };
  337. static struct pci_driver pdc_pci_driver = {
  338. .name = DRV_NAME,
  339. .id_table = pdc,
  340. .probe = pdc_init_one,
  341. .remove = ata_pci_remove_one
  342. };
  343. static int __init pdc_init(void)
  344. {
  345. return pci_register_driver(&pdc_pci_driver);
  346. }
  347. static void __exit pdc_exit(void)
  348. {
  349. pci_unregister_driver(&pdc_pci_driver);
  350. }
  351. MODULE_AUTHOR("Alan Cox");
  352. MODULE_DESCRIPTION("low-level driver for Promise 2024x and 20262-20267");
  353. MODULE_LICENSE("GPL");
  354. MODULE_DEVICE_TABLE(pci, pdc);
  355. MODULE_VERSION(DRV_VERSION);
  356. module_init(pdc_init);
  357. module_exit(pdc_exit);