pata_efar.c 7.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303
  1. /*
  2. * pata_efar.c - EFAR PIIX clone controller driver
  3. *
  4. * (C) 2005 Red Hat <alan@redhat.com>
  5. *
  6. * Some parts based on ata_piix.c by Jeff Garzik and others.
  7. *
  8. * The EFAR is a PIIX4 clone with UDMA66 support. Unlike the later
  9. * Intel ICH controllers the EFAR widened the UDMA mode register bits
  10. * and doesn't require the funky clock selection.
  11. */
  12. #include <linux/kernel.h>
  13. #include <linux/module.h>
  14. #include <linux/pci.h>
  15. #include <linux/init.h>
  16. #include <linux/blkdev.h>
  17. #include <linux/delay.h>
  18. #include <linux/device.h>
  19. #include <scsi/scsi_host.h>
  20. #include <linux/libata.h>
  21. #include <linux/ata.h>
  22. #define DRV_NAME "pata_efar"
  23. #define DRV_VERSION "0.4.4"
  24. /**
  25. * efar_pre_reset - Enable bits
  26. * @link: ATA link
  27. * @deadline: deadline jiffies for the operation
  28. *
  29. * Perform cable detection for the EFAR ATA interface. This is
  30. * different to the PIIX arrangement
  31. */
  32. static int efar_pre_reset(struct ata_link *link, unsigned long deadline)
  33. {
  34. static const struct pci_bits efar_enable_bits[] = {
  35. { 0x41U, 1U, 0x80UL, 0x80UL }, /* port 0 */
  36. { 0x43U, 1U, 0x80UL, 0x80UL }, /* port 1 */
  37. };
  38. struct ata_port *ap = link->ap;
  39. struct pci_dev *pdev = to_pci_dev(ap->host->dev);
  40. if (!pci_test_config_bits(pdev, &efar_enable_bits[ap->port_no]))
  41. return -ENOENT;
  42. return ata_sff_prereset(link, deadline);
  43. }
  44. /**
  45. * efar_cable_detect - check for 40/80 pin
  46. * @ap: Port
  47. *
  48. * Perform cable detection for the EFAR ATA interface. This is
  49. * different to the PIIX arrangement
  50. */
  51. static int efar_cable_detect(struct ata_port *ap)
  52. {
  53. struct pci_dev *pdev = to_pci_dev(ap->host->dev);
  54. u8 tmp;
  55. pci_read_config_byte(pdev, 0x47, &tmp);
  56. if (tmp & (2 >> ap->port_no))
  57. return ATA_CBL_PATA40;
  58. return ATA_CBL_PATA80;
  59. }
  60. /**
  61. * efar_set_piomode - Initialize host controller PATA PIO timings
  62. * @ap: Port whose timings we are configuring
  63. * @adev: um
  64. *
  65. * Set PIO mode for device, in host controller PCI config space.
  66. *
  67. * LOCKING:
  68. * None (inherited from caller).
  69. */
  70. static void efar_set_piomode (struct ata_port *ap, struct ata_device *adev)
  71. {
  72. unsigned int pio = adev->pio_mode - XFER_PIO_0;
  73. struct pci_dev *dev = to_pci_dev(ap->host->dev);
  74. unsigned int idetm_port= ap->port_no ? 0x42 : 0x40;
  75. u16 idetm_data;
  76. int control = 0;
  77. /*
  78. * See Intel Document 298600-004 for the timing programing rules
  79. * for PIIX/ICH. The EFAR is a clone so very similar
  80. */
  81. static const /* ISP RTC */
  82. u8 timings[][2] = { { 0, 0 },
  83. { 0, 0 },
  84. { 1, 0 },
  85. { 2, 1 },
  86. { 2, 3 }, };
  87. if (pio > 2)
  88. control |= 1; /* TIME1 enable */
  89. if (ata_pio_need_iordy(adev)) /* PIO 3/4 require IORDY */
  90. control |= 2; /* IE enable */
  91. /* Intel specifies that the PPE functionality is for disk only */
  92. if (adev->class == ATA_DEV_ATA)
  93. control |= 4; /* PPE enable */
  94. pci_read_config_word(dev, idetm_port, &idetm_data);
  95. /* Enable PPE, IE and TIME as appropriate */
  96. if (adev->devno == 0) {
  97. idetm_data &= 0xCCF0;
  98. idetm_data |= control;
  99. idetm_data |= (timings[pio][0] << 12) |
  100. (timings[pio][1] << 8);
  101. } else {
  102. int shift = 4 * ap->port_no;
  103. u8 slave_data;
  104. idetm_data &= 0xCC0F;
  105. idetm_data |= (control << 4);
  106. /* Slave timing in separate register */
  107. pci_read_config_byte(dev, 0x44, &slave_data);
  108. slave_data &= 0x0F << shift;
  109. slave_data |= ((timings[pio][0] << 2) | timings[pio][1]) << shift;
  110. pci_write_config_byte(dev, 0x44, slave_data);
  111. }
  112. idetm_data |= 0x4000; /* Ensure SITRE is enabled */
  113. pci_write_config_word(dev, idetm_port, idetm_data);
  114. }
  115. /**
  116. * efar_set_dmamode - Initialize host controller PATA DMA timings
  117. * @ap: Port whose timings we are configuring
  118. * @adev: Device to program
  119. *
  120. * Set UDMA/MWDMA mode for device, in host controller PCI config space.
  121. *
  122. * LOCKING:
  123. * None (inherited from caller).
  124. */
  125. static void efar_set_dmamode (struct ata_port *ap, struct ata_device *adev)
  126. {
  127. struct pci_dev *dev = to_pci_dev(ap->host->dev);
  128. u8 master_port = ap->port_no ? 0x42 : 0x40;
  129. u16 master_data;
  130. u8 speed = adev->dma_mode;
  131. int devid = adev->devno + 2 * ap->port_no;
  132. u8 udma_enable;
  133. static const /* ISP RTC */
  134. u8 timings[][2] = { { 0, 0 },
  135. { 0, 0 },
  136. { 1, 0 },
  137. { 2, 1 },
  138. { 2, 3 }, };
  139. pci_read_config_word(dev, master_port, &master_data);
  140. pci_read_config_byte(dev, 0x48, &udma_enable);
  141. if (speed >= XFER_UDMA_0) {
  142. unsigned int udma = adev->dma_mode - XFER_UDMA_0;
  143. u16 udma_timing;
  144. udma_enable |= (1 << devid);
  145. /* Load the UDMA mode number */
  146. pci_read_config_word(dev, 0x4A, &udma_timing);
  147. udma_timing &= ~(7 << (4 * devid));
  148. udma_timing |= udma << (4 * devid);
  149. pci_write_config_word(dev, 0x4A, udma_timing);
  150. } else {
  151. /*
  152. * MWDMA is driven by the PIO timings. We must also enable
  153. * IORDY unconditionally along with TIME1. PPE has already
  154. * been set when the PIO timing was set.
  155. */
  156. unsigned int mwdma = adev->dma_mode - XFER_MW_DMA_0;
  157. unsigned int control;
  158. u8 slave_data;
  159. const unsigned int needed_pio[3] = {
  160. XFER_PIO_0, XFER_PIO_3, XFER_PIO_4
  161. };
  162. int pio = needed_pio[mwdma] - XFER_PIO_0;
  163. control = 3; /* IORDY|TIME1 */
  164. /* If the drive MWDMA is faster than it can do PIO then
  165. we must force PIO into PIO0 */
  166. if (adev->pio_mode < needed_pio[mwdma])
  167. /* Enable DMA timing only */
  168. control |= 8; /* PIO cycles in PIO0 */
  169. if (adev->devno) { /* Slave */
  170. master_data &= 0xFF4F; /* Mask out IORDY|TIME1|DMAONLY */
  171. master_data |= control << 4;
  172. pci_read_config_byte(dev, 0x44, &slave_data);
  173. slave_data &= (0x0F + 0xE1 * ap->port_no);
  174. /* Load the matching timing */
  175. slave_data |= ((timings[pio][0] << 2) | timings[pio][1]) << (ap->port_no ? 4 : 0);
  176. pci_write_config_byte(dev, 0x44, slave_data);
  177. } else { /* Master */
  178. master_data &= 0xCCF4; /* Mask out IORDY|TIME1|DMAONLY
  179. and master timing bits */
  180. master_data |= control;
  181. master_data |=
  182. (timings[pio][0] << 12) |
  183. (timings[pio][1] << 8);
  184. }
  185. udma_enable &= ~(1 << devid);
  186. pci_write_config_word(dev, master_port, master_data);
  187. }
  188. pci_write_config_byte(dev, 0x48, udma_enable);
  189. }
  190. static struct scsi_host_template efar_sht = {
  191. ATA_BMDMA_SHT(DRV_NAME),
  192. };
  193. static struct ata_port_operations efar_ops = {
  194. .inherits = &ata_bmdma_port_ops,
  195. .cable_detect = efar_cable_detect,
  196. .set_piomode = efar_set_piomode,
  197. .set_dmamode = efar_set_dmamode,
  198. .prereset = efar_pre_reset,
  199. };
  200. /**
  201. * efar_init_one - Register EFAR ATA PCI device with kernel services
  202. * @pdev: PCI device to register
  203. * @ent: Entry in efar_pci_tbl matching with @pdev
  204. *
  205. * Called from kernel PCI layer.
  206. *
  207. * LOCKING:
  208. * Inherited from PCI layer (may sleep).
  209. *
  210. * RETURNS:
  211. * Zero on success, or -ERRNO value.
  212. */
  213. static int efar_init_one (struct pci_dev *pdev, const struct pci_device_id *ent)
  214. {
  215. static int printed_version;
  216. static const struct ata_port_info info = {
  217. .flags = ATA_FLAG_SLAVE_POSS,
  218. .pio_mask = 0x1f, /* pio0-4 */
  219. .mwdma_mask = 0x07, /* mwdma1-2 */
  220. .udma_mask = 0x0f, /* UDMA 66 */
  221. .port_ops = &efar_ops,
  222. };
  223. const struct ata_port_info *ppi[] = { &info, NULL };
  224. if (!printed_version++)
  225. dev_printk(KERN_DEBUG, &pdev->dev,
  226. "version " DRV_VERSION "\n");
  227. return ata_pci_sff_init_one(pdev, ppi, &efar_sht, NULL);
  228. }
  229. static const struct pci_device_id efar_pci_tbl[] = {
  230. { PCI_VDEVICE(EFAR, 0x9130), },
  231. { } /* terminate list */
  232. };
  233. static struct pci_driver efar_pci_driver = {
  234. .name = DRV_NAME,
  235. .id_table = efar_pci_tbl,
  236. .probe = efar_init_one,
  237. .remove = ata_pci_remove_one,
  238. #ifdef CONFIG_PM
  239. .suspend = ata_pci_device_suspend,
  240. .resume = ata_pci_device_resume,
  241. #endif
  242. };
  243. static int __init efar_init(void)
  244. {
  245. return pci_register_driver(&efar_pci_driver);
  246. }
  247. static void __exit efar_exit(void)
  248. {
  249. pci_unregister_driver(&efar_pci_driver);
  250. }
  251. module_init(efar_init);
  252. module_exit(efar_exit);
  253. MODULE_AUTHOR("Alan Cox");
  254. MODULE_DESCRIPTION("SCSI low-level driver for EFAR PIIX clones");
  255. MODULE_LICENSE("GPL");
  256. MODULE_DEVICE_TABLE(pci, efar_pci_tbl);
  257. MODULE_VERSION(DRV_VERSION);