pata_pdc202xx_old.c 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423
  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.3"
  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. * pdc202xx_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 pdc202xx_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. * pdc202xx_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 pdc202xx_set_piomode(struct ata_port *ap, struct ata_device *adev)
  93. {
  94. pdc202xx_configure_piomode(ap, adev, adev->pio_mode - XFER_PIO_0);
  95. }
  96. /**
  97. * pdc202xx_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 pdc202xx_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. void __iomem *master = ap->host->ports[0]->ioaddr.bmdma_addr;
  147. void __iomem *clock = master + 0x11;
  148. void __iomem *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. iowrite8(ioread8(clock) | sel66, clock);
  153. else
  154. iowrite8(ioread8(clock) & ~sel66, clock);
  155. /* The DMA clocks may have been trashed by a reset. FIXME: make conditional
  156. and move to qc_issue ? */
  157. pdc202xx_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. len = qc->nbytes;
  162. if (tf->flags & ATA_TFLAG_WRITE)
  163. len |= 0x06000000;
  164. else
  165. len |= 0x05000000;
  166. iowrite32(len, atapi_reg);
  167. }
  168. /* Activate DMA */
  169. ata_bmdma_start(qc);
  170. }
  171. /**
  172. * pdc2026x_bmdma_end - DMA engine stop
  173. * @qc: ATA command
  174. *
  175. * After a DMA completes we need to put the clock back to 33MHz for
  176. * PIO timings.
  177. */
  178. static void pdc2026x_bmdma_stop(struct ata_queued_cmd *qc)
  179. {
  180. struct ata_port *ap = qc->ap;
  181. struct ata_device *adev = qc->dev;
  182. struct ata_taskfile *tf = &qc->tf;
  183. int sel66 = ap->port_no ? 0x08: 0x02;
  184. /* The clock bits are in the same register for both channels */
  185. void __iomem *master = ap->host->ports[0]->ioaddr.bmdma_addr;
  186. void __iomem *clock = master + 0x11;
  187. void __iomem *atapi_reg = master + 0x20 + (4 * ap->port_no);
  188. /* Cases the state machine will not complete correctly */
  189. if (tf->protocol == ATA_PROT_ATAPI_DMA || ( tf->flags & ATA_TFLAG_LBA48)) {
  190. iowrite32(0, atapi_reg);
  191. iowrite8(ioread8(clock) & ~sel66, clock);
  192. }
  193. /* Check we keep host level locking here */
  194. /* Flip back to 33Mhz for PIO */
  195. if (adev->dma_mode >= XFER_UDMA_2)
  196. iowrite8(ioread8(clock) & ~sel66, clock);
  197. ata_bmdma_stop(qc);
  198. }
  199. /**
  200. * pdc2026x_dev_config - device setup hook
  201. * @ap: ATA port
  202. * @adev: newly found device
  203. *
  204. * Perform chip specific early setup. We need to lock the transfer
  205. * sizes to 8bit to avoid making the state engine on the 2026x cards
  206. * barf.
  207. */
  208. static void pdc2026x_dev_config(struct ata_port *ap, struct ata_device *adev)
  209. {
  210. adev->max_sectors = 256;
  211. }
  212. static struct scsi_host_template pdc202xx_sht = {
  213. .module = THIS_MODULE,
  214. .name = DRV_NAME,
  215. .ioctl = ata_scsi_ioctl,
  216. .queuecommand = ata_scsi_queuecmd,
  217. .can_queue = ATA_DEF_QUEUE,
  218. .this_id = ATA_SHT_THIS_ID,
  219. .sg_tablesize = LIBATA_MAX_PRD,
  220. .cmd_per_lun = ATA_SHT_CMD_PER_LUN,
  221. .emulated = ATA_SHT_EMULATED,
  222. .use_clustering = ATA_SHT_USE_CLUSTERING,
  223. .proc_name = DRV_NAME,
  224. .dma_boundary = ATA_DMA_BOUNDARY,
  225. .slave_configure = ata_scsi_slave_config,
  226. .slave_destroy = ata_scsi_slave_destroy,
  227. .bios_param = ata_std_bios_param,
  228. .resume = ata_scsi_device_resume,
  229. .suspend = ata_scsi_device_suspend,
  230. };
  231. static struct ata_port_operations pdc2024x_port_ops = {
  232. .port_disable = ata_port_disable,
  233. .set_piomode = pdc202xx_set_piomode,
  234. .set_dmamode = pdc202xx_set_dmamode,
  235. .mode_filter = ata_pci_default_filter,
  236. .tf_load = ata_tf_load,
  237. .tf_read = ata_tf_read,
  238. .check_status = ata_check_status,
  239. .exec_command = ata_exec_command,
  240. .dev_select = ata_std_dev_select,
  241. .freeze = ata_bmdma_freeze,
  242. .thaw = ata_bmdma_thaw,
  243. .error_handler = pdc2024x_error_handler,
  244. .post_internal_cmd = ata_bmdma_post_internal_cmd,
  245. .bmdma_setup = ata_bmdma_setup,
  246. .bmdma_start = ata_bmdma_start,
  247. .bmdma_stop = ata_bmdma_stop,
  248. .bmdma_status = ata_bmdma_status,
  249. .qc_prep = ata_qc_prep,
  250. .qc_issue = ata_qc_issue_prot,
  251. .data_xfer = ata_data_xfer,
  252. .irq_handler = ata_interrupt,
  253. .irq_clear = ata_bmdma_irq_clear,
  254. .irq_on = ata_irq_on,
  255. .irq_ack = ata_irq_ack,
  256. .port_start = ata_port_start,
  257. };
  258. static struct ata_port_operations pdc2026x_port_ops = {
  259. .port_disable = ata_port_disable,
  260. .set_piomode = pdc202xx_set_piomode,
  261. .set_dmamode = pdc202xx_set_dmamode,
  262. .mode_filter = ata_pci_default_filter,
  263. .tf_load = ata_tf_load,
  264. .tf_read = ata_tf_read,
  265. .check_status = ata_check_status,
  266. .exec_command = ata_exec_command,
  267. .dev_select = ata_std_dev_select,
  268. .dev_config = pdc2026x_dev_config,
  269. .freeze = ata_bmdma_freeze,
  270. .thaw = ata_bmdma_thaw,
  271. .error_handler = pdc2026x_error_handler,
  272. .post_internal_cmd = ata_bmdma_post_internal_cmd,
  273. .bmdma_setup = ata_bmdma_setup,
  274. .bmdma_start = pdc2026x_bmdma_start,
  275. .bmdma_stop = pdc2026x_bmdma_stop,
  276. .bmdma_status = ata_bmdma_status,
  277. .qc_prep = ata_qc_prep,
  278. .qc_issue = ata_qc_issue_prot,
  279. .data_xfer = ata_data_xfer,
  280. .irq_handler = ata_interrupt,
  281. .irq_clear = ata_bmdma_irq_clear,
  282. .irq_on = ata_irq_on,
  283. .irq_ack = ata_irq_ack,
  284. .port_start = ata_port_start,
  285. };
  286. static int pdc202xx_init_one(struct pci_dev *dev, const struct pci_device_id *id)
  287. {
  288. static struct ata_port_info info[3] = {
  289. {
  290. .sht = &pdc202xx_sht,
  291. .flags = ATA_FLAG_SLAVE_POSS | ATA_FLAG_SRST,
  292. .pio_mask = 0x1f,
  293. .mwdma_mask = 0x07,
  294. .udma_mask = ATA_UDMA2,
  295. .port_ops = &pdc2024x_port_ops
  296. },
  297. {
  298. .sht = &pdc202xx_sht,
  299. .flags = ATA_FLAG_SLAVE_POSS | ATA_FLAG_SRST,
  300. .pio_mask = 0x1f,
  301. .mwdma_mask = 0x07,
  302. .udma_mask = ATA_UDMA4,
  303. .port_ops = &pdc2026x_port_ops
  304. },
  305. {
  306. .sht = &pdc202xx_sht,
  307. .flags = ATA_FLAG_SLAVE_POSS | ATA_FLAG_SRST,
  308. .pio_mask = 0x1f,
  309. .mwdma_mask = 0x07,
  310. .udma_mask = ATA_UDMA5,
  311. .port_ops = &pdc2026x_port_ops
  312. }
  313. };
  314. static struct ata_port_info *port_info[2];
  315. port_info[0] = port_info[1] = &info[id->driver_data];
  316. if (dev->device == PCI_DEVICE_ID_PROMISE_20265) {
  317. struct pci_dev *bridge = dev->bus->self;
  318. /* Don't grab anything behind a Promise I2O RAID */
  319. if (bridge && bridge->vendor == PCI_VENDOR_ID_INTEL) {
  320. if( bridge->device == PCI_DEVICE_ID_INTEL_I960)
  321. return -ENODEV;
  322. if( bridge->device == PCI_DEVICE_ID_INTEL_I960RM)
  323. return -ENODEV;
  324. }
  325. }
  326. return ata_pci_init_one(dev, port_info, 2);
  327. }
  328. static const struct pci_device_id pdc202xx[] = {
  329. { PCI_VDEVICE(PROMISE, PCI_DEVICE_ID_PROMISE_20246), 0 },
  330. { PCI_VDEVICE(PROMISE, PCI_DEVICE_ID_PROMISE_20262), 1 },
  331. { PCI_VDEVICE(PROMISE, PCI_DEVICE_ID_PROMISE_20263), 1 },
  332. { PCI_VDEVICE(PROMISE, PCI_DEVICE_ID_PROMISE_20265), 2 },
  333. { PCI_VDEVICE(PROMISE, PCI_DEVICE_ID_PROMISE_20267), 2 },
  334. { },
  335. };
  336. static struct pci_driver pdc202xx_pci_driver = {
  337. .name = DRV_NAME,
  338. .id_table = pdc202xx,
  339. .probe = pdc202xx_init_one,
  340. .remove = ata_pci_remove_one,
  341. .suspend = ata_pci_device_suspend,
  342. .resume = ata_pci_device_resume,
  343. };
  344. static int __init pdc202xx_init(void)
  345. {
  346. return pci_register_driver(&pdc202xx_pci_driver);
  347. }
  348. static void __exit pdc202xx_exit(void)
  349. {
  350. pci_unregister_driver(&pdc202xx_pci_driver);
  351. }
  352. MODULE_AUTHOR("Alan Cox");
  353. MODULE_DESCRIPTION("low-level driver for Promise 2024x and 20262-20267");
  354. MODULE_LICENSE("GPL");
  355. MODULE_DEVICE_TABLE(pci, pdc202xx);
  356. MODULE_VERSION(DRV_VERSION);
  357. module_init(pdc202xx_init);
  358. module_exit(pdc202xx_exit);