pata_radisys.c 6.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252
  1. /*
  2. * pata_radisys.c - Intel PATA/SATA controllers
  3. *
  4. * (C) 2006 Red Hat <alan@lxorguk.ukuu.org.uk>
  5. *
  6. * Some parts based on ata_piix.c by Jeff Garzik and others.
  7. *
  8. * A PIIX relative, this device has a single ATA channel and no
  9. * slave timings, SITRE or PPE. In that sense it is a close relative
  10. * of the original PIIX. It does however support UDMA 33/66 per channel
  11. * although no other modes/timings. Also lacking is 32bit I/O on the ATA
  12. * port.
  13. */
  14. #include <linux/kernel.h>
  15. #include <linux/module.h>
  16. #include <linux/pci.h>
  17. #include <linux/blkdev.h>
  18. #include <linux/delay.h>
  19. #include <linux/device.h>
  20. #include <scsi/scsi_host.h>
  21. #include <linux/libata.h>
  22. #include <linux/ata.h>
  23. #define DRV_NAME "pata_radisys"
  24. #define DRV_VERSION "0.4.4"
  25. /**
  26. * radisys_set_piomode - Initialize host controller PATA PIO timings
  27. * @ap: ATA port
  28. * @adev: Device whose timings we are configuring
  29. *
  30. * Set PIO mode for device, in host controller PCI config space.
  31. *
  32. * LOCKING:
  33. * None (inherited from caller).
  34. */
  35. static void radisys_set_piomode (struct ata_port *ap, struct ata_device *adev)
  36. {
  37. unsigned int pio = adev->pio_mode - XFER_PIO_0;
  38. struct pci_dev *dev = to_pci_dev(ap->host->dev);
  39. u16 idetm_data;
  40. int control = 0;
  41. /*
  42. * See Intel Document 298600-004 for the timing programing rules
  43. * for PIIX/ICH. Note that the early PIIX does not have the slave
  44. * timing port at 0x44. The Radisys is a relative of the PIIX
  45. * but not the same so be careful.
  46. */
  47. static const /* ISP RTC */
  48. u8 timings[][2] = { { 0, 0 }, /* Check me */
  49. { 0, 0 },
  50. { 1, 1 },
  51. { 2, 2 },
  52. { 3, 3 }, };
  53. if (pio > 0)
  54. control |= 1; /* TIME1 enable */
  55. if (ata_pio_need_iordy(adev))
  56. control |= 2; /* IE IORDY */
  57. pci_read_config_word(dev, 0x40, &idetm_data);
  58. /* Enable IE and TIME as appropriate. Clear the other
  59. drive timing bits */
  60. idetm_data &= 0xCCCC;
  61. idetm_data |= (control << (4 * adev->devno));
  62. idetm_data |= (timings[pio][0] << 12) |
  63. (timings[pio][1] << 8);
  64. pci_write_config_word(dev, 0x40, idetm_data);
  65. /* Track which port is configured */
  66. ap->private_data = adev;
  67. }
  68. /**
  69. * radisys_set_dmamode - Initialize host controller PATA DMA timings
  70. * @ap: Port whose timings we are configuring
  71. * @adev: Device to program
  72. *
  73. * Set MWDMA mode for device, in host controller PCI config space.
  74. *
  75. * LOCKING:
  76. * None (inherited from caller).
  77. */
  78. static void radisys_set_dmamode (struct ata_port *ap, struct ata_device *adev)
  79. {
  80. struct pci_dev *dev = to_pci_dev(ap->host->dev);
  81. u16 idetm_data;
  82. u8 udma_enable;
  83. static const /* ISP RTC */
  84. u8 timings[][2] = { { 0, 0 },
  85. { 0, 0 },
  86. { 1, 1 },
  87. { 2, 2 },
  88. { 3, 3 }, };
  89. /*
  90. * MWDMA is driven by the PIO timings. We must also enable
  91. * IORDY unconditionally.
  92. */
  93. pci_read_config_word(dev, 0x40, &idetm_data);
  94. pci_read_config_byte(dev, 0x48, &udma_enable);
  95. if (adev->dma_mode < XFER_UDMA_0) {
  96. unsigned int mwdma = adev->dma_mode - XFER_MW_DMA_0;
  97. const unsigned int needed_pio[3] = {
  98. XFER_PIO_0, XFER_PIO_3, XFER_PIO_4
  99. };
  100. int pio = needed_pio[mwdma] - XFER_PIO_0;
  101. int control = 3; /* IORDY|TIME0 */
  102. /* If the drive MWDMA is faster than it can do PIO then
  103. we must force PIO0 for PIO cycles. */
  104. if (adev->pio_mode < needed_pio[mwdma])
  105. control = 1;
  106. /* Mask out the relevant control and timing bits we will load. Also
  107. clear the other drive TIME register as a precaution */
  108. idetm_data &= 0xCCCC;
  109. idetm_data |= control << (4 * adev->devno);
  110. idetm_data |= (timings[pio][0] << 12) | (timings[pio][1] << 8);
  111. udma_enable &= ~(1 << adev->devno);
  112. } else {
  113. u8 udma_mode;
  114. /* UDMA66 on: UDMA 33 and 66 are switchable via register 0x4A */
  115. pci_read_config_byte(dev, 0x4A, &udma_mode);
  116. if (adev->xfer_mode == XFER_UDMA_2)
  117. udma_mode &= ~(2 << (adev->devno * 4));
  118. else /* UDMA 4 */
  119. udma_mode |= (2 << (adev->devno * 4));
  120. pci_write_config_byte(dev, 0x4A, udma_mode);
  121. udma_enable |= (1 << adev->devno);
  122. }
  123. pci_write_config_word(dev, 0x40, idetm_data);
  124. pci_write_config_byte(dev, 0x48, udma_enable);
  125. /* Track which port is configured */
  126. ap->private_data = adev;
  127. }
  128. /**
  129. * radisys_qc_issue - command issue
  130. * @qc: command pending
  131. *
  132. * Called when the libata layer is about to issue a command. We wrap
  133. * this interface so that we can load the correct ATA timings if
  134. * necessary. Our logic also clears TIME0/TIME1 for the other device so
  135. * that, even if we get this wrong, cycles to the other device will
  136. * be made PIO0.
  137. */
  138. static unsigned int radisys_qc_issue(struct ata_queued_cmd *qc)
  139. {
  140. struct ata_port *ap = qc->ap;
  141. struct ata_device *adev = qc->dev;
  142. if (adev != ap->private_data) {
  143. /* UDMA timing is not shared */
  144. if (adev->dma_mode < XFER_UDMA_0) {
  145. if (adev->dma_mode)
  146. radisys_set_dmamode(ap, adev);
  147. else if (adev->pio_mode)
  148. radisys_set_piomode(ap, adev);
  149. }
  150. }
  151. return ata_bmdma_qc_issue(qc);
  152. }
  153. static struct scsi_host_template radisys_sht = {
  154. ATA_BMDMA_SHT(DRV_NAME),
  155. };
  156. static struct ata_port_operations radisys_pata_ops = {
  157. .inherits = &ata_bmdma_port_ops,
  158. .qc_issue = radisys_qc_issue,
  159. .cable_detect = ata_cable_unknown,
  160. .set_piomode = radisys_set_piomode,
  161. .set_dmamode = radisys_set_dmamode,
  162. };
  163. /**
  164. * radisys_init_one - Register PIIX ATA PCI device with kernel services
  165. * @pdev: PCI device to register
  166. * @ent: Entry in radisys_pci_tbl matching with @pdev
  167. *
  168. * Called from kernel PCI layer. We probe for combined mode (sigh),
  169. * and then hand over control to libata, for it to do the rest.
  170. *
  171. * LOCKING:
  172. * Inherited from PCI layer (may sleep).
  173. *
  174. * RETURNS:
  175. * Zero on success, or -ERRNO value.
  176. */
  177. static int radisys_init_one (struct pci_dev *pdev, const struct pci_device_id *ent)
  178. {
  179. static const struct ata_port_info info = {
  180. .flags = ATA_FLAG_SLAVE_POSS,
  181. .pio_mask = ATA_PIO4,
  182. .mwdma_mask = ATA_MWDMA12_ONLY,
  183. .udma_mask = ATA_UDMA24_ONLY,
  184. .port_ops = &radisys_pata_ops,
  185. };
  186. const struct ata_port_info *ppi[] = { &info, NULL };
  187. ata_print_version_once(&pdev->dev, DRV_VERSION);
  188. return ata_pci_bmdma_init_one(pdev, ppi, &radisys_sht, NULL, 0);
  189. }
  190. static const struct pci_device_id radisys_pci_tbl[] = {
  191. { PCI_VDEVICE(RADISYS, 0x8201), },
  192. { } /* terminate list */
  193. };
  194. static struct pci_driver radisys_pci_driver = {
  195. .name = DRV_NAME,
  196. .id_table = radisys_pci_tbl,
  197. .probe = radisys_init_one,
  198. .remove = ata_pci_remove_one,
  199. #ifdef CONFIG_PM_SLEEP
  200. .suspend = ata_pci_device_suspend,
  201. .resume = ata_pci_device_resume,
  202. #endif
  203. };
  204. module_pci_driver(radisys_pci_driver);
  205. MODULE_AUTHOR("Alan Cox");
  206. MODULE_DESCRIPTION("SCSI low-level driver for Radisys R82600 controllers");
  207. MODULE_LICENSE("GPL");
  208. MODULE_DEVICE_TABLE(pci, radisys_pci_tbl);
  209. MODULE_VERSION(DRV_VERSION);