pata_efar.c 9.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355
  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_std_prereset(link, deadline);
  43. }
  44. /**
  45. * efar_probe_reset - Probe specified port on PATA host controller
  46. * @ap: Port to probe
  47. *
  48. * LOCKING:
  49. * None (inherited from caller).
  50. */
  51. static void efar_error_handler(struct ata_port *ap)
  52. {
  53. ata_bmdma_drive_eh(ap, efar_pre_reset, ata_std_softreset, NULL, ata_std_postreset);
  54. }
  55. /**
  56. * efar_cable_detect - check for 40/80 pin
  57. * @ap: Port
  58. *
  59. * Perform cable detection for the EFAR ATA interface. This is
  60. * different to the PIIX arrangement
  61. */
  62. static int efar_cable_detect(struct ata_port *ap)
  63. {
  64. struct pci_dev *pdev = to_pci_dev(ap->host->dev);
  65. u8 tmp;
  66. pci_read_config_byte(pdev, 0x47, &tmp);
  67. if (tmp & (2 >> ap->port_no))
  68. return ATA_CBL_PATA40;
  69. return ATA_CBL_PATA80;
  70. }
  71. /**
  72. * efar_set_piomode - Initialize host controller PATA PIO timings
  73. * @ap: Port whose timings we are configuring
  74. * @adev: um
  75. *
  76. * Set PIO mode for device, in host controller PCI config space.
  77. *
  78. * LOCKING:
  79. * None (inherited from caller).
  80. */
  81. static void efar_set_piomode (struct ata_port *ap, struct ata_device *adev)
  82. {
  83. unsigned int pio = adev->pio_mode - XFER_PIO_0;
  84. struct pci_dev *dev = to_pci_dev(ap->host->dev);
  85. unsigned int idetm_port= ap->port_no ? 0x42 : 0x40;
  86. u16 idetm_data;
  87. int control = 0;
  88. /*
  89. * See Intel Document 298600-004 for the timing programing rules
  90. * for PIIX/ICH. The EFAR is a clone so very similar
  91. */
  92. static const /* ISP RTC */
  93. u8 timings[][2] = { { 0, 0 },
  94. { 0, 0 },
  95. { 1, 0 },
  96. { 2, 1 },
  97. { 2, 3 }, };
  98. if (pio > 2)
  99. control |= 1; /* TIME1 enable */
  100. if (ata_pio_need_iordy(adev)) /* PIO 3/4 require IORDY */
  101. control |= 2; /* IE enable */
  102. /* Intel specifies that the PPE functionality is for disk only */
  103. if (adev->class == ATA_DEV_ATA)
  104. control |= 4; /* PPE enable */
  105. pci_read_config_word(dev, idetm_port, &idetm_data);
  106. /* Enable PPE, IE and TIME as appropriate */
  107. if (adev->devno == 0) {
  108. idetm_data &= 0xCCF0;
  109. idetm_data |= control;
  110. idetm_data |= (timings[pio][0] << 12) |
  111. (timings[pio][1] << 8);
  112. } else {
  113. int shift = 4 * ap->port_no;
  114. u8 slave_data;
  115. idetm_data &= 0xCC0F;
  116. idetm_data |= (control << 4);
  117. /* Slave timing in seperate register */
  118. pci_read_config_byte(dev, 0x44, &slave_data);
  119. slave_data &= 0x0F << shift;
  120. slave_data |= ((timings[pio][0] << 2) | timings[pio][1]) << shift;
  121. pci_write_config_byte(dev, 0x44, slave_data);
  122. }
  123. idetm_data |= 0x4000; /* Ensure SITRE is enabled */
  124. pci_write_config_word(dev, idetm_port, idetm_data);
  125. }
  126. /**
  127. * efar_set_dmamode - Initialize host controller PATA DMA timings
  128. * @ap: Port whose timings we are configuring
  129. * @adev: Device to program
  130. *
  131. * Set UDMA/MWDMA mode for device, in host controller PCI config space.
  132. *
  133. * LOCKING:
  134. * None (inherited from caller).
  135. */
  136. static void efar_set_dmamode (struct ata_port *ap, struct ata_device *adev)
  137. {
  138. struct pci_dev *dev = to_pci_dev(ap->host->dev);
  139. u8 master_port = ap->port_no ? 0x42 : 0x40;
  140. u16 master_data;
  141. u8 speed = adev->dma_mode;
  142. int devid = adev->devno + 2 * ap->port_no;
  143. u8 udma_enable;
  144. static const /* ISP RTC */
  145. u8 timings[][2] = { { 0, 0 },
  146. { 0, 0 },
  147. { 1, 0 },
  148. { 2, 1 },
  149. { 2, 3 }, };
  150. pci_read_config_word(dev, master_port, &master_data);
  151. pci_read_config_byte(dev, 0x48, &udma_enable);
  152. if (speed >= XFER_UDMA_0) {
  153. unsigned int udma = adev->dma_mode - XFER_UDMA_0;
  154. u16 udma_timing;
  155. udma_enable |= (1 << devid);
  156. /* Load the UDMA mode number */
  157. pci_read_config_word(dev, 0x4A, &udma_timing);
  158. udma_timing &= ~(7 << (4 * devid));
  159. udma_timing |= udma << (4 * devid);
  160. pci_write_config_word(dev, 0x4A, udma_timing);
  161. } else {
  162. /*
  163. * MWDMA is driven by the PIO timings. We must also enable
  164. * IORDY unconditionally along with TIME1. PPE has already
  165. * been set when the PIO timing was set.
  166. */
  167. unsigned int mwdma = adev->dma_mode - XFER_MW_DMA_0;
  168. unsigned int control;
  169. u8 slave_data;
  170. const unsigned int needed_pio[3] = {
  171. XFER_PIO_0, XFER_PIO_3, XFER_PIO_4
  172. };
  173. int pio = needed_pio[mwdma] - XFER_PIO_0;
  174. control = 3; /* IORDY|TIME1 */
  175. /* If the drive MWDMA is faster than it can do PIO then
  176. we must force PIO into PIO0 */
  177. if (adev->pio_mode < needed_pio[mwdma])
  178. /* Enable DMA timing only */
  179. control |= 8; /* PIO cycles in PIO0 */
  180. if (adev->devno) { /* Slave */
  181. master_data &= 0xFF4F; /* Mask out IORDY|TIME1|DMAONLY */
  182. master_data |= control << 4;
  183. pci_read_config_byte(dev, 0x44, &slave_data);
  184. slave_data &= (0x0F + 0xE1 * ap->port_no);
  185. /* Load the matching timing */
  186. slave_data |= ((timings[pio][0] << 2) | timings[pio][1]) << (ap->port_no ? 4 : 0);
  187. pci_write_config_byte(dev, 0x44, slave_data);
  188. } else { /* Master */
  189. master_data &= 0xCCF4; /* Mask out IORDY|TIME1|DMAONLY
  190. and master timing bits */
  191. master_data |= control;
  192. master_data |=
  193. (timings[pio][0] << 12) |
  194. (timings[pio][1] << 8);
  195. }
  196. udma_enable &= ~(1 << devid);
  197. pci_write_config_word(dev, master_port, master_data);
  198. }
  199. pci_write_config_byte(dev, 0x48, udma_enable);
  200. }
  201. static struct scsi_host_template efar_sht = {
  202. .module = THIS_MODULE,
  203. .name = DRV_NAME,
  204. .ioctl = ata_scsi_ioctl,
  205. .queuecommand = ata_scsi_queuecmd,
  206. .can_queue = ATA_DEF_QUEUE,
  207. .this_id = ATA_SHT_THIS_ID,
  208. .sg_tablesize = LIBATA_MAX_PRD,
  209. .cmd_per_lun = ATA_SHT_CMD_PER_LUN,
  210. .emulated = ATA_SHT_EMULATED,
  211. .use_clustering = ATA_SHT_USE_CLUSTERING,
  212. .proc_name = DRV_NAME,
  213. .dma_boundary = ATA_DMA_BOUNDARY,
  214. .slave_configure = ata_scsi_slave_config,
  215. .slave_destroy = ata_scsi_slave_destroy,
  216. .bios_param = ata_std_bios_param,
  217. };
  218. static const struct ata_port_operations efar_ops = {
  219. .set_piomode = efar_set_piomode,
  220. .set_dmamode = efar_set_dmamode,
  221. .mode_filter = ata_pci_default_filter,
  222. .tf_load = ata_tf_load,
  223. .tf_read = ata_tf_read,
  224. .check_status = ata_check_status,
  225. .exec_command = ata_exec_command,
  226. .dev_select = ata_std_dev_select,
  227. .freeze = ata_bmdma_freeze,
  228. .thaw = ata_bmdma_thaw,
  229. .error_handler = efar_error_handler,
  230. .post_internal_cmd = ata_bmdma_post_internal_cmd,
  231. .cable_detect = efar_cable_detect,
  232. .bmdma_setup = ata_bmdma_setup,
  233. .bmdma_start = ata_bmdma_start,
  234. .bmdma_stop = ata_bmdma_stop,
  235. .bmdma_status = ata_bmdma_status,
  236. .qc_prep = ata_qc_prep,
  237. .qc_issue = ata_qc_issue_prot,
  238. .data_xfer = ata_data_xfer,
  239. .irq_handler = ata_interrupt,
  240. .irq_clear = ata_bmdma_irq_clear,
  241. .irq_on = ata_irq_on,
  242. .port_start = ata_sff_port_start,
  243. };
  244. /**
  245. * efar_init_one - Register EFAR ATA PCI device with kernel services
  246. * @pdev: PCI device to register
  247. * @ent: Entry in efar_pci_tbl matching with @pdev
  248. *
  249. * Called from kernel PCI layer.
  250. *
  251. * LOCKING:
  252. * Inherited from PCI layer (may sleep).
  253. *
  254. * RETURNS:
  255. * Zero on success, or -ERRNO value.
  256. */
  257. static int efar_init_one (struct pci_dev *pdev, const struct pci_device_id *ent)
  258. {
  259. static int printed_version;
  260. static const struct ata_port_info info = {
  261. .sht = &efar_sht,
  262. .flags = ATA_FLAG_SLAVE_POSS,
  263. .pio_mask = 0x1f, /* pio0-4 */
  264. .mwdma_mask = 0x07, /* mwdma1-2 */
  265. .udma_mask = 0x0f, /* UDMA 66 */
  266. .port_ops = &efar_ops,
  267. };
  268. const struct ata_port_info *ppi[] = { &info, NULL };
  269. if (!printed_version++)
  270. dev_printk(KERN_DEBUG, &pdev->dev,
  271. "version " DRV_VERSION "\n");
  272. return ata_pci_init_one(pdev, ppi);
  273. }
  274. static const struct pci_device_id efar_pci_tbl[] = {
  275. { PCI_VDEVICE(EFAR, 0x9130), },
  276. { } /* terminate list */
  277. };
  278. static struct pci_driver efar_pci_driver = {
  279. .name = DRV_NAME,
  280. .id_table = efar_pci_tbl,
  281. .probe = efar_init_one,
  282. .remove = ata_pci_remove_one,
  283. #ifdef CONFIG_PM
  284. .suspend = ata_pci_device_suspend,
  285. .resume = ata_pci_device_resume,
  286. #endif
  287. };
  288. static int __init efar_init(void)
  289. {
  290. return pci_register_driver(&efar_pci_driver);
  291. }
  292. static void __exit efar_exit(void)
  293. {
  294. pci_unregister_driver(&efar_pci_driver);
  295. }
  296. module_init(efar_init);
  297. module_exit(efar_exit);
  298. MODULE_AUTHOR("Alan Cox");
  299. MODULE_DESCRIPTION("SCSI low-level driver for EFAR PIIX clones");
  300. MODULE_LICENSE("GPL");
  301. MODULE_DEVICE_TABLE(pci, efar_pci_tbl);
  302. MODULE_VERSION(DRV_VERSION);