pata_efar.c 8.9 KB

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