pata_oldpiix.c 7.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273
  1. /*
  2. * pata_oldpiix.c - Intel PATA/SATA controllers
  3. *
  4. * (C) 2005 Red Hat
  5. *
  6. * Some parts based on ata_piix.c by Jeff Garzik and others.
  7. *
  8. * Early PIIX differs significantly from the later PIIX as it lacks
  9. * SITRE and the slave timing registers. This means that you have to
  10. * set timing per channel, or be clever. Libata tells us whenever it
  11. * does drive selection and we use this to reload the timings.
  12. *
  13. * Because of these behaviour differences PIIX gets its own driver module.
  14. */
  15. #include <linux/kernel.h>
  16. #include <linux/module.h>
  17. #include <linux/pci.h>
  18. #include <linux/blkdev.h>
  19. #include <linux/delay.h>
  20. #include <linux/device.h>
  21. #include <scsi/scsi_host.h>
  22. #include <linux/libata.h>
  23. #include <linux/ata.h>
  24. #define DRV_NAME "pata_oldpiix"
  25. #define DRV_VERSION "0.5.5"
  26. /**
  27. * oldpiix_pre_reset - probe begin
  28. * @link: ATA link
  29. * @deadline: deadline jiffies for the operation
  30. *
  31. * Set up cable type and use generic probe init
  32. */
  33. static int oldpiix_pre_reset(struct ata_link *link, unsigned long deadline)
  34. {
  35. struct ata_port *ap = link->ap;
  36. struct pci_dev *pdev = to_pci_dev(ap->host->dev);
  37. static const struct pci_bits oldpiix_enable_bits[] = {
  38. { 0x41U, 1U, 0x80UL, 0x80UL }, /* port 0 */
  39. { 0x43U, 1U, 0x80UL, 0x80UL }, /* port 1 */
  40. };
  41. if (!pci_test_config_bits(pdev, &oldpiix_enable_bits[ap->port_no]))
  42. return -ENOENT;
  43. return ata_sff_prereset(link, deadline);
  44. }
  45. /**
  46. * oldpiix_set_piomode - Initialize host controller PATA PIO timings
  47. * @ap: Port whose timings we are configuring
  48. * @adev: Device whose timings we are configuring
  49. *
  50. * Set PIO mode for device, in host controller PCI config space.
  51. *
  52. * LOCKING:
  53. * None (inherited from caller).
  54. */
  55. static void oldpiix_set_piomode (struct ata_port *ap, struct ata_device *adev)
  56. {
  57. unsigned int pio = adev->pio_mode - XFER_PIO_0;
  58. struct pci_dev *dev = to_pci_dev(ap->host->dev);
  59. unsigned int idetm_port= ap->port_no ? 0x42 : 0x40;
  60. u16 idetm_data;
  61. int control = 0;
  62. /*
  63. * See Intel Document 298600-004 for the timing programing rules
  64. * for PIIX/ICH. Note that the early PIIX does not have the slave
  65. * timing port at 0x44.
  66. */
  67. static const /* ISP RTC */
  68. u8 timings[][2] = { { 0, 0 },
  69. { 0, 0 },
  70. { 1, 0 },
  71. { 2, 1 },
  72. { 2, 3 }, };
  73. if (pio > 1)
  74. control |= 1; /* TIME */
  75. if (ata_pio_need_iordy(adev))
  76. control |= 2; /* IE */
  77. /* Intel specifies that the prefetch/posting is for disk only */
  78. if (adev->class == ATA_DEV_ATA)
  79. control |= 4; /* PPE */
  80. pci_read_config_word(dev, idetm_port, &idetm_data);
  81. /*
  82. * Set PPE, IE and TIME as appropriate.
  83. * Clear the other drive's timing bits.
  84. */
  85. if (adev->devno == 0) {
  86. idetm_data &= 0xCCE0;
  87. idetm_data |= control;
  88. } else {
  89. idetm_data &= 0xCC0E;
  90. idetm_data |= (control << 4);
  91. }
  92. idetm_data |= (timings[pio][0] << 12) |
  93. (timings[pio][1] << 8);
  94. pci_write_config_word(dev, idetm_port, idetm_data);
  95. /* Track which port is configured */
  96. ap->private_data = adev;
  97. }
  98. /**
  99. * oldpiix_set_dmamode - Initialize host controller PATA DMA timings
  100. * @ap: Port whose timings we are configuring
  101. * @adev: Device to program
  102. *
  103. * Set MWDMA mode for device, in host controller PCI config space.
  104. *
  105. * LOCKING:
  106. * None (inherited from caller).
  107. */
  108. static void oldpiix_set_dmamode (struct ata_port *ap, struct ata_device *adev)
  109. {
  110. struct pci_dev *dev = to_pci_dev(ap->host->dev);
  111. u8 idetm_port = ap->port_no ? 0x42 : 0x40;
  112. u16 idetm_data;
  113. static const /* ISP RTC */
  114. u8 timings[][2] = { { 0, 0 },
  115. { 0, 0 },
  116. { 1, 0 },
  117. { 2, 1 },
  118. { 2, 3 }, };
  119. /*
  120. * MWDMA is driven by the PIO timings. We must also enable
  121. * IORDY unconditionally along with TIME1. PPE has already
  122. * been set when the PIO timing was set.
  123. */
  124. unsigned int mwdma = adev->dma_mode - XFER_MW_DMA_0;
  125. unsigned int control;
  126. const unsigned int needed_pio[3] = {
  127. XFER_PIO_0, XFER_PIO_3, XFER_PIO_4
  128. };
  129. int pio = needed_pio[mwdma] - XFER_PIO_0;
  130. pci_read_config_word(dev, idetm_port, &idetm_data);
  131. control = 3; /* IORDY|TIME0 */
  132. /* Intel specifies that the PPE functionality is for disk only */
  133. if (adev->class == ATA_DEV_ATA)
  134. control |= 4; /* PPE enable */
  135. /* If the drive MWDMA is faster than it can do PIO then
  136. we must force PIO into PIO0 */
  137. if (adev->pio_mode < needed_pio[mwdma])
  138. /* Enable DMA timing only */
  139. control |= 8; /* PIO cycles in PIO0 */
  140. /* Mask out the relevant control and timing bits we will load. Also
  141. clear the other drive TIME register as a precaution */
  142. if (adev->devno == 0) {
  143. idetm_data &= 0xCCE0;
  144. idetm_data |= control;
  145. } else {
  146. idetm_data &= 0xCC0E;
  147. idetm_data |= (control << 4);
  148. }
  149. idetm_data |= (timings[pio][0] << 12) | (timings[pio][1] << 8);
  150. pci_write_config_word(dev, idetm_port, idetm_data);
  151. /* Track which port is configured */
  152. ap->private_data = adev;
  153. }
  154. /**
  155. * oldpiix_qc_issue - command issue
  156. * @qc: command pending
  157. *
  158. * Called when the libata layer is about to issue a command. We wrap
  159. * this interface so that we can load the correct ATA timings if
  160. * necessary. Our logic also clears TIME0/TIME1 for the other device so
  161. * that, even if we get this wrong, cycles to the other device will
  162. * be made PIO0.
  163. */
  164. static unsigned int oldpiix_qc_issue(struct ata_queued_cmd *qc)
  165. {
  166. struct ata_port *ap = qc->ap;
  167. struct ata_device *adev = qc->dev;
  168. if (adev != ap->private_data) {
  169. oldpiix_set_piomode(ap, adev);
  170. if (ata_dma_enabled(adev))
  171. oldpiix_set_dmamode(ap, adev);
  172. }
  173. return ata_bmdma_qc_issue(qc);
  174. }
  175. static struct scsi_host_template oldpiix_sht = {
  176. ATA_BMDMA_SHT(DRV_NAME),
  177. };
  178. static struct ata_port_operations oldpiix_pata_ops = {
  179. .inherits = &ata_bmdma_port_ops,
  180. .qc_issue = oldpiix_qc_issue,
  181. .cable_detect = ata_cable_40wire,
  182. .set_piomode = oldpiix_set_piomode,
  183. .set_dmamode = oldpiix_set_dmamode,
  184. .prereset = oldpiix_pre_reset,
  185. };
  186. /**
  187. * oldpiix_init_one - Register PIIX ATA PCI device with kernel services
  188. * @pdev: PCI device to register
  189. * @ent: Entry in oldpiix_pci_tbl matching with @pdev
  190. *
  191. * Called from kernel PCI layer. We probe for combined mode (sigh),
  192. * and then hand over control to libata, for it to do the rest.
  193. *
  194. * LOCKING:
  195. * Inherited from PCI layer (may sleep).
  196. *
  197. * RETURNS:
  198. * Zero on success, or -ERRNO value.
  199. */
  200. static int oldpiix_init_one (struct pci_dev *pdev, const struct pci_device_id *ent)
  201. {
  202. static const struct ata_port_info info = {
  203. .flags = ATA_FLAG_SLAVE_POSS,
  204. .pio_mask = ATA_PIO4,
  205. .mwdma_mask = ATA_MWDMA12_ONLY,
  206. .port_ops = &oldpiix_pata_ops,
  207. };
  208. const struct ata_port_info *ppi[] = { &info, NULL };
  209. ata_print_version_once(&pdev->dev, DRV_VERSION);
  210. return ata_pci_bmdma_init_one(pdev, ppi, &oldpiix_sht, NULL, 0);
  211. }
  212. static const struct pci_device_id oldpiix_pci_tbl[] = {
  213. { PCI_VDEVICE(INTEL, 0x1230), },
  214. { } /* terminate list */
  215. };
  216. static struct pci_driver oldpiix_pci_driver = {
  217. .name = DRV_NAME,
  218. .id_table = oldpiix_pci_tbl,
  219. .probe = oldpiix_init_one,
  220. .remove = ata_pci_remove_one,
  221. #ifdef CONFIG_PM_SLEEP
  222. .suspend = ata_pci_device_suspend,
  223. .resume = ata_pci_device_resume,
  224. #endif
  225. };
  226. module_pci_driver(oldpiix_pci_driver);
  227. MODULE_AUTHOR("Alan Cox");
  228. MODULE_DESCRIPTION("SCSI low-level driver for early PIIX series controllers");
  229. MODULE_LICENSE("GPL");
  230. MODULE_DEVICE_TABLE(pci, oldpiix_pci_tbl);
  231. MODULE_VERSION(DRV_VERSION);