pata_hpt3x3.c 5.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237
  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.4.2"
  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. /**
  49. * hpt3x3_set_dmamode - DMA timing setup
  50. * @ap: ATA interface
  51. * @adev: Device being configured
  52. *
  53. * Set up the channel for MWDMA or UDMA modes. Much the same as with
  54. * PIO, load the mode number and then set MWDMA or UDMA flag.
  55. */
  56. static void hpt3x3_set_dmamode(struct ata_port *ap, struct ata_device *adev)
  57. {
  58. struct pci_dev *pdev = to_pci_dev(ap->host->dev);
  59. u32 r1, r2;
  60. int dn = 2 * ap->port_no + adev->devno;
  61. int mode_num = adev->dma_mode & 0x0F;
  62. pci_read_config_dword(pdev, 0x44, &r1);
  63. pci_read_config_dword(pdev, 0x48, &r2);
  64. /* Load the timing number */
  65. r1 &= ~(7 << (3 * dn));
  66. r1 |= (mode_num << (3 * dn));
  67. r2 &= ~(0x11 << dn); /* Clear MWDMA and UDMA bits */
  68. if (adev->dma_mode >= XFER_UDMA_0)
  69. r2 |= 0x01 << dn; /* Ultra mode */
  70. else
  71. r2 |= 0x10 << dn; /* MWDMA */
  72. pci_write_config_dword(pdev, 0x44, r1);
  73. pci_write_config_dword(pdev, 0x48, r2);
  74. }
  75. static struct scsi_host_template hpt3x3_sht = {
  76. .module = THIS_MODULE,
  77. .name = DRV_NAME,
  78. .ioctl = ata_scsi_ioctl,
  79. .queuecommand = ata_scsi_queuecmd,
  80. .can_queue = ATA_DEF_QUEUE,
  81. .this_id = ATA_SHT_THIS_ID,
  82. .sg_tablesize = LIBATA_MAX_PRD,
  83. .cmd_per_lun = ATA_SHT_CMD_PER_LUN,
  84. .emulated = ATA_SHT_EMULATED,
  85. .use_clustering = ATA_SHT_USE_CLUSTERING,
  86. .proc_name = DRV_NAME,
  87. .dma_boundary = ATA_DMA_BOUNDARY,
  88. .slave_configure = ata_scsi_slave_config,
  89. .slave_destroy = ata_scsi_slave_destroy,
  90. .bios_param = ata_std_bios_param,
  91. #ifdef CONFIG_PM
  92. .resume = ata_scsi_device_resume,
  93. .suspend = ata_scsi_device_suspend,
  94. #endif
  95. };
  96. static struct ata_port_operations hpt3x3_port_ops = {
  97. .port_disable = ata_port_disable,
  98. .set_piomode = hpt3x3_set_piomode,
  99. .set_dmamode = hpt3x3_set_dmamode,
  100. .mode_filter = ata_pci_default_filter,
  101. .tf_load = ata_tf_load,
  102. .tf_read = ata_tf_read,
  103. .check_status = ata_check_status,
  104. .exec_command = ata_exec_command,
  105. .dev_select = ata_std_dev_select,
  106. .freeze = ata_bmdma_freeze,
  107. .thaw = ata_bmdma_thaw,
  108. .error_handler = ata_bmdma_error_handler,
  109. .post_internal_cmd = ata_bmdma_post_internal_cmd,
  110. .cable_detect = ata_cable_40wire,
  111. .bmdma_setup = ata_bmdma_setup,
  112. .bmdma_start = ata_bmdma_start,
  113. .bmdma_stop = ata_bmdma_stop,
  114. .bmdma_status = ata_bmdma_status,
  115. .qc_prep = ata_qc_prep,
  116. .qc_issue = ata_qc_issue_prot,
  117. .data_xfer = ata_data_xfer,
  118. .irq_handler = ata_interrupt,
  119. .irq_clear = ata_bmdma_irq_clear,
  120. .irq_on = ata_irq_on,
  121. .irq_ack = ata_irq_ack,
  122. .port_start = ata_port_start,
  123. };
  124. /**
  125. * hpt3x3_init_chipset - chip setup
  126. * @dev: PCI device
  127. *
  128. * Perform the setup required at boot and on resume.
  129. */
  130. static void hpt3x3_init_chipset(struct pci_dev *dev)
  131. {
  132. u16 cmd;
  133. /* Initialize the board */
  134. pci_write_config_word(dev, 0x80, 0x00);
  135. /* Check if it is a 343 or a 363. 363 has COMMAND_MEMORY set */
  136. pci_read_config_word(dev, PCI_COMMAND, &cmd);
  137. if (cmd & PCI_COMMAND_MEMORY)
  138. pci_write_config_byte(dev, PCI_LATENCY_TIMER, 0xF0);
  139. else
  140. pci_write_config_byte(dev, PCI_LATENCY_TIMER, 0x20);
  141. }
  142. /**
  143. * hpt3x3_init_one - Initialise an HPT343/363
  144. * @dev: PCI device
  145. * @id: Entry in match table
  146. *
  147. * Perform basic initialisation. The chip has a quirk that it won't
  148. * function unless it is at XX00. The old ATA driver touched this up
  149. * but we leave it for pci quirks to do properly.
  150. */
  151. static int hpt3x3_init_one(struct pci_dev *dev, const struct pci_device_id *id)
  152. {
  153. static struct ata_port_info info = {
  154. .sht = &hpt3x3_sht,
  155. .flags = ATA_FLAG_SLAVE_POSS|ATA_FLAG_SRST,
  156. .pio_mask = 0x1f,
  157. .mwdma_mask = 0x07,
  158. .udma_mask = 0x07,
  159. .port_ops = &hpt3x3_port_ops
  160. };
  161. static struct ata_port_info *port_info[2] = { &info, &info };
  162. hpt3x3_init_chipset(dev);
  163. /* Now kick off ATA set up */
  164. return ata_pci_init_one(dev, port_info, 2);
  165. }
  166. #ifdef CONFIG_PM
  167. static int hpt3x3_reinit_one(struct pci_dev *dev)
  168. {
  169. hpt3x3_init_chipset(dev);
  170. return ata_pci_device_resume(dev);
  171. }
  172. #endif
  173. static const struct pci_device_id hpt3x3[] = {
  174. { PCI_VDEVICE(TTI, PCI_DEVICE_ID_TTI_HPT343), },
  175. { },
  176. };
  177. static struct pci_driver hpt3x3_pci_driver = {
  178. .name = DRV_NAME,
  179. .id_table = hpt3x3,
  180. .probe = hpt3x3_init_one,
  181. .remove = ata_pci_remove_one,
  182. #ifdef CONFIG_PM
  183. .suspend = ata_pci_device_suspend,
  184. .resume = hpt3x3_reinit_one,
  185. #endif
  186. };
  187. static int __init hpt3x3_init(void)
  188. {
  189. return pci_register_driver(&hpt3x3_pci_driver);
  190. }
  191. static void __exit hpt3x3_exit(void)
  192. {
  193. pci_unregister_driver(&hpt3x3_pci_driver);
  194. }
  195. MODULE_AUTHOR("Alan Cox");
  196. MODULE_DESCRIPTION("low-level driver for the Highpoint HPT343/363");
  197. MODULE_LICENSE("GPL");
  198. MODULE_DEVICE_TABLE(pci, hpt3x3);
  199. MODULE_VERSION(DRV_VERSION);
  200. module_init(hpt3x3_init);
  201. module_exit(hpt3x3_exit);