pata_hpt3x3.c 6.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260
  1. /*
  2. * pata_hpt3x3 - HPT3x3 driver
  3. * (c) Copyright 2005-2006 Red Hat
  4. *
  5. * Was pata_hpt34x but the naming was confusing as it supported the
  6. * 343 and 363 so it has been renamed.
  7. *
  8. * Based on:
  9. * linux/drivers/ide/pci/hpt34x.c Version 0.40 Sept 10, 2002
  10. * Copyright (C) 1998-2000 Andre Hedrick <andre@linux-ide.org>
  11. *
  12. * May be copied or modified under the terms of the GNU General Public
  13. * License
  14. */
  15. #include <linux/kernel.h>
  16. #include <linux/module.h>
  17. #include <linux/pci.h>
  18. #include <linux/init.h>
  19. #include <linux/blkdev.h>
  20. #include <linux/delay.h>
  21. #include <scsi/scsi_host.h>
  22. #include <linux/libata.h>
  23. #define DRV_NAME "pata_hpt3x3"
  24. #define DRV_VERSION "0.5.3"
  25. /**
  26. * hpt3x3_set_piomode - PIO setup
  27. * @ap: ATA interface
  28. * @adev: device on the interface
  29. *
  30. * Set our PIO requirements. This is fairly simple on the HPT3x3 as
  31. * all we have to do is clear the MWDMA and UDMA bits then load the
  32. * mode number.
  33. */
  34. static void hpt3x3_set_piomode(struct ata_port *ap, struct ata_device *adev)
  35. {
  36. struct pci_dev *pdev = to_pci_dev(ap->host->dev);
  37. u32 r1, r2;
  38. int dn = 2 * ap->port_no + adev->devno;
  39. pci_read_config_dword(pdev, 0x44, &r1);
  40. pci_read_config_dword(pdev, 0x48, &r2);
  41. /* Load the PIO timing number */
  42. r1 &= ~(7 << (3 * dn));
  43. r1 |= (adev->pio_mode - XFER_PIO_0) << (3 * dn);
  44. r2 &= ~(0x11 << dn); /* Clear MWDMA and UDMA bits */
  45. pci_write_config_dword(pdev, 0x44, r1);
  46. pci_write_config_dword(pdev, 0x48, r2);
  47. }
  48. #if defined(CONFIG_PATA_HPT3X3_DMA)
  49. /**
  50. * hpt3x3_set_dmamode - DMA timing setup
  51. * @ap: ATA interface
  52. * @adev: Device being configured
  53. *
  54. * Set up the channel for MWDMA or UDMA modes. Much the same as with
  55. * PIO, load the mode number and then set MWDMA or UDMA flag.
  56. *
  57. * 0x44 : bit 0-2 master mode, 3-5 slave mode, etc
  58. * 0x48 : bit 4/0 DMA/UDMA bit 5/1 for slave etc
  59. */
  60. static void hpt3x3_set_dmamode(struct ata_port *ap, struct ata_device *adev)
  61. {
  62. struct pci_dev *pdev = to_pci_dev(ap->host->dev);
  63. u32 r1, r2;
  64. int dn = 2 * ap->port_no + adev->devno;
  65. int mode_num = adev->dma_mode & 0x0F;
  66. pci_read_config_dword(pdev, 0x44, &r1);
  67. pci_read_config_dword(pdev, 0x48, &r2);
  68. /* Load the timing number */
  69. r1 &= ~(7 << (3 * dn));
  70. r1 |= (mode_num << (3 * dn));
  71. r2 &= ~(0x11 << dn); /* Clear MWDMA and UDMA bits */
  72. if (adev->dma_mode >= XFER_UDMA_0)
  73. r2 |= (0x10 << dn); /* Ultra mode */
  74. else
  75. r2 |= (0x01 << dn); /* MWDMA */
  76. pci_write_config_dword(pdev, 0x44, r1);
  77. pci_write_config_dword(pdev, 0x48, r2);
  78. }
  79. #endif /* CONFIG_PATA_HPT3X3_DMA */
  80. /**
  81. * hpt3x3_atapi_dma - ATAPI DMA check
  82. * @qc: Queued command
  83. *
  84. * Just say no - we don't do ATAPI DMA
  85. */
  86. static int hpt3x3_atapi_dma(struct ata_queued_cmd *qc)
  87. {
  88. return 1;
  89. }
  90. static struct scsi_host_template hpt3x3_sht = {
  91. ATA_BMDMA_SHT(DRV_NAME),
  92. };
  93. static struct ata_port_operations hpt3x3_port_ops = {
  94. .inherits = &ata_bmdma_port_ops,
  95. .check_atapi_dma= hpt3x3_atapi_dma,
  96. .cable_detect = ata_cable_40wire,
  97. .set_piomode = hpt3x3_set_piomode,
  98. #if defined(CONFIG_PATA_HPT3X3_DMA)
  99. .set_dmamode = hpt3x3_set_dmamode,
  100. #endif
  101. };
  102. /**
  103. * hpt3x3_init_chipset - chip setup
  104. * @dev: PCI device
  105. *
  106. * Perform the setup required at boot and on resume.
  107. */
  108. static void hpt3x3_init_chipset(struct pci_dev *dev)
  109. {
  110. u16 cmd;
  111. /* Initialize the board */
  112. pci_write_config_word(dev, 0x80, 0x00);
  113. /* Check if it is a 343 or a 363. 363 has COMMAND_MEMORY set */
  114. pci_read_config_word(dev, PCI_COMMAND, &cmd);
  115. if (cmd & PCI_COMMAND_MEMORY)
  116. pci_write_config_byte(dev, PCI_LATENCY_TIMER, 0xF0);
  117. else
  118. pci_write_config_byte(dev, PCI_LATENCY_TIMER, 0x20);
  119. }
  120. /**
  121. * hpt3x3_init_one - Initialise an HPT343/363
  122. * @pdev: PCI device
  123. * @id: Entry in match table
  124. *
  125. * Perform basic initialisation. We set the device up so we access all
  126. * ports via BAR4. This is neccessary to work around errata.
  127. */
  128. static int hpt3x3_init_one(struct pci_dev *pdev, const struct pci_device_id *id)
  129. {
  130. static int printed_version;
  131. static const struct ata_port_info info = {
  132. .flags = ATA_FLAG_SLAVE_POSS,
  133. .pio_mask = 0x1f,
  134. #if defined(CONFIG_PATA_HPT3X3_DMA)
  135. /* Further debug needed */
  136. .mwdma_mask = 0x07,
  137. .udma_mask = 0x07,
  138. #endif
  139. .port_ops = &hpt3x3_port_ops
  140. };
  141. /* Register offsets of taskfiles in BAR4 area */
  142. static const u8 offset_cmd[2] = { 0x20, 0x28 };
  143. static const u8 offset_ctl[2] = { 0x36, 0x3E };
  144. const struct ata_port_info *ppi[] = { &info, NULL };
  145. struct ata_host *host;
  146. int i, rc;
  147. void __iomem *base;
  148. hpt3x3_init_chipset(pdev);
  149. if (!printed_version++)
  150. dev_printk(KERN_DEBUG, &pdev->dev, "version " DRV_VERSION "\n");
  151. host = ata_host_alloc_pinfo(&pdev->dev, ppi, 2);
  152. if (!host)
  153. return -ENOMEM;
  154. /* acquire resources and fill host */
  155. rc = pcim_enable_device(pdev);
  156. if (rc)
  157. return rc;
  158. /* Everything is relative to BAR4 if we set up this way */
  159. rc = pcim_iomap_regions(pdev, 1 << 4, DRV_NAME);
  160. if (rc == -EBUSY)
  161. pcim_pin_device(pdev);
  162. if (rc)
  163. return rc;
  164. host->iomap = pcim_iomap_table(pdev);
  165. rc = pci_set_dma_mask(pdev, ATA_DMA_MASK);
  166. if (rc)
  167. return rc;
  168. rc = pci_set_consistent_dma_mask(pdev, ATA_DMA_MASK);
  169. if (rc)
  170. return rc;
  171. base = host->iomap[4]; /* Bus mastering base */
  172. for (i = 0; i < host->n_ports; i++) {
  173. struct ata_port *ap = host->ports[i];
  174. struct ata_ioports *ioaddr = &ap->ioaddr;
  175. ioaddr->cmd_addr = base + offset_cmd[i];
  176. ioaddr->altstatus_addr =
  177. ioaddr->ctl_addr = base + offset_ctl[i];
  178. ioaddr->scr_addr = NULL;
  179. ata_sff_std_ports(ioaddr);
  180. ioaddr->bmdma_addr = base + 8 * i;
  181. ata_port_pbar_desc(ap, 4, -1, "ioport");
  182. ata_port_pbar_desc(ap, 4, offset_cmd[i], "cmd");
  183. }
  184. pci_set_master(pdev);
  185. return ata_host_activate(host, pdev->irq, ata_sff_interrupt,
  186. IRQF_SHARED, &hpt3x3_sht);
  187. }
  188. #ifdef CONFIG_PM
  189. static int hpt3x3_reinit_one(struct pci_dev *dev)
  190. {
  191. hpt3x3_init_chipset(dev);
  192. return ata_pci_device_resume(dev);
  193. }
  194. #endif
  195. static const struct pci_device_id hpt3x3[] = {
  196. { PCI_VDEVICE(TTI, PCI_DEVICE_ID_TTI_HPT343), },
  197. { },
  198. };
  199. static struct pci_driver hpt3x3_pci_driver = {
  200. .name = DRV_NAME,
  201. .id_table = hpt3x3,
  202. .probe = hpt3x3_init_one,
  203. .remove = ata_pci_remove_one,
  204. #ifdef CONFIG_PM
  205. .suspend = ata_pci_device_suspend,
  206. .resume = hpt3x3_reinit_one,
  207. #endif
  208. };
  209. static int __init hpt3x3_init(void)
  210. {
  211. return pci_register_driver(&hpt3x3_pci_driver);
  212. }
  213. static void __exit hpt3x3_exit(void)
  214. {
  215. pci_unregister_driver(&hpt3x3_pci_driver);
  216. }
  217. MODULE_AUTHOR("Alan Cox");
  218. MODULE_DESCRIPTION("low-level driver for the Highpoint HPT343/363");
  219. MODULE_LICENSE("GPL");
  220. MODULE_DEVICE_TABLE(pci, hpt3x3);
  221. MODULE_VERSION(DRV_VERSION);
  222. module_init(hpt3x3_init);
  223. module_exit(hpt3x3_exit);