pata_it8172.c 8.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288
  1. /*
  2. * pata_it8172.c - IT8172 PATA for new ATA layer
  3. * (C) 2005 Red Hat Inc
  4. * Alan Cox <alan@redhat.com>
  5. *
  6. * Based heavily on
  7. *
  8. * BRIEF MODULE DESCRIPTION
  9. * IT8172 IDE controller support
  10. *
  11. * Copyright 2000 MontaVista Software Inc.
  12. * Author: MontaVista Software, Inc.
  13. * stevel@mvista.com or source@mvista.com
  14. *
  15. * This program is free software; you can redistribute it and/or modify it
  16. * under the terms of the GNU General Public License as published by the
  17. * Free Software Foundation; either version 2 of the License, or (at your
  18. * option) any later version.
  19. *
  20. * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESS OR IMPLIED
  21. * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
  22. * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN
  23. * NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
  24. * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
  25. * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
  26. * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
  27. * ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
  28. * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
  29. * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  30. *
  31. * You should have received a copy of the GNU General Public License along
  32. * with this program; if not, write to the Free Software Foundation, Inc.,
  33. * 675 Mass Ave, Cambridge, MA 02139, USA.
  34. *
  35. * TODO
  36. * Check for errata
  37. * See if we really need to force native mode
  38. * PIO timings (also lacking in original)
  39. */
  40. #include <linux/kernel.h>
  41. #include <linux/module.h>
  42. #include <linux/pci.h>
  43. #include <linux/init.h>
  44. #include <linux/blkdev.h>
  45. #include <linux/delay.h>
  46. #include <scsi/scsi_host.h>
  47. #include <linux/libata.h>
  48. #define DRV_NAME "pata_it8172"
  49. #define DRV_VERSION "0.3.1"
  50. static int it8172_pre_reset(struct ata_port *ap)
  51. {
  52. static const struct pci_bits it8172_enable_bits[] = {
  53. { 0x00, 0, 0x00, 0x00 },
  54. { 0x40, 1, 0x00, 0x01 }
  55. };
  56. struct pci_dev *pdev = to_pci_dev(ap->host->dev);
  57. if (ap->port_no && !pci_test_config_bits(pdev, &it8172_enable_bits[ap->port_no])) {
  58. ata_port_disable(ap);
  59. printk(KERN_INFO "ata%u: port disabled. ignoring.\n", ap->id);
  60. return 0;
  61. }
  62. ap->cbl = ATA_CBL_PATA40;
  63. return ata_std_prereset(ap);
  64. }
  65. static void it8172_error_handler(struct ata_port *ap)
  66. {
  67. ata_bmdma_drive_eh(ap, it8172_pre_reset, ata_std_softreset, NULL, ata_std_postreset);
  68. }
  69. /**
  70. * it8172_set_pio_timing - set initial PIO mode data
  71. * @ap: ATA interface
  72. * @adev: ATA device
  73. *
  74. * Called by both the pio and dma setup functions to set the controller
  75. * timings for PIO transfers. We must load both the mode number and
  76. * timing values into the controller.
  77. */
  78. static void it8172_set_pio_timing(struct ata_port *ap, struct ata_device *adev, int pio)
  79. {
  80. struct pci_dev *pdev = to_pci_dev(ap->host->dev);
  81. u16 reg40;
  82. pci_read_config_word(pdev, 0x40, &reg40);
  83. /*
  84. * FIX! The DIOR/DIOW pulse width and recovery times in port 0x44
  85. * are being left at the default values of 8 PCI clocks (242 nsec
  86. * for a 33 MHz clock). These can be safely shortened at higher
  87. * PIO modes. The DIOR/DIOW pulse width and recovery times only
  88. * apply to PIO modes, not to the DMA modes.
  89. */
  90. /*
  91. * Enable port 0x44. The IT8172G spec is confused; it calls
  92. * this register the "Slave IDE Timing Register", but in fact,
  93. * it controls timing for both master and slave drives.
  94. */
  95. reg40 |= 0x4000;
  96. if (adev->devno) {
  97. reg40 &= 0xC006;
  98. if (pio > 1)
  99. /* Enable prefetch and IORDY sample-point */
  100. reg40 |= 0x0060;
  101. } else {
  102. reg40 &= 0xC060;
  103. if (pio > 1)
  104. /* Enable prefetch and IORDY sample-point */
  105. reg40 |= 0x0006;
  106. }
  107. /* Write back the enables */
  108. pci_write_config_word(pdev, 0x40, reg40);
  109. }
  110. /**
  111. * it8172_set_piomode - set initial PIO mode data
  112. * @ap: ATA interface
  113. * @adev: ATA device
  114. *
  115. * Called to do the PIO mode setup. We use a shared helper for this
  116. * as the DMA setup must also adjust the PIO timing information.
  117. */
  118. static void it8172_set_piomode(struct ata_port *ap, struct ata_device *adev)
  119. {
  120. it8172_set_pio_timing(ap, adev, adev->pio_mode - XFER_PIO_0);
  121. }
  122. /**
  123. * it8172_set_dmamode - set initial DMA mode data
  124. * @ap: ATA interface
  125. * @adev: ATA device
  126. *
  127. * Called to do the DMA mode setup. We must tune an appropriate PIO
  128. * mode to match.
  129. */
  130. static void it8172_set_dmamode(struct ata_port *ap, struct ata_device *adev)
  131. {
  132. struct pci_dev *pdev = to_pci_dev(ap->host->dev);
  133. int dn = (2 * ap->port_no) + adev->devno;
  134. u8 reg48, reg4a;
  135. int pio;
  136. static const int pio_map[] = { 1, 3, 4};
  137. /*
  138. * Setting the DMA cycle time to 2 or 3 PCI clocks (60 and 91 nsec
  139. * at 33 MHz PCI clock) seems to cause BadCRC errors during DMA
  140. * transfers on some drives, even though both numbers meet the minimum
  141. * ATAPI-4 spec of 73 and 54 nsec for UDMA 1 and 2 respectively.
  142. * So the faster times are just commented out here. The good news is
  143. * that the slower cycle time has very little affect on transfer
  144. * performance.
  145. */
  146. pci_read_config_byte(pdev, 0x48, &reg48);
  147. pci_read_config_byte(pdev, 0x4A, &reg4a);
  148. reg4a &= ~(3 << (4 * dn));
  149. if (adev->dma_mode >= XFER_UDMA_0) {
  150. reg48 |= 1 << dn;
  151. #ifdef UDMA_TIMING_SET
  152. reg4a |= ((adev->dma_mode - XFER_UDMA_0) << (4 * dn));
  153. #endif
  154. pio = 4;
  155. } else {
  156. pio = pio_map[adev->dma_mode - XFER_MW_DMA_0];
  157. reg48 &= ~ (1 << dn);
  158. }
  159. pci_write_config_byte(pdev, 0x48, reg48);
  160. pci_write_config_byte(pdev, 0x4A, reg4a);
  161. it8172_set_pio_timing(ap, adev, pio);
  162. }
  163. static struct scsi_host_template it8172_sht = {
  164. .module = THIS_MODULE,
  165. .name = DRV_NAME,
  166. .ioctl = ata_scsi_ioctl,
  167. .queuecommand = ata_scsi_queuecmd,
  168. .can_queue = ATA_DEF_QUEUE,
  169. .this_id = ATA_SHT_THIS_ID,
  170. .sg_tablesize = LIBATA_MAX_PRD,
  171. .max_sectors = ATA_MAX_SECTORS,
  172. .cmd_per_lun = ATA_SHT_CMD_PER_LUN,
  173. .emulated = ATA_SHT_EMULATED,
  174. .use_clustering = ATA_SHT_USE_CLUSTERING,
  175. .proc_name = DRV_NAME,
  176. .dma_boundary = ATA_DMA_BOUNDARY,
  177. .slave_configure = ata_scsi_slave_config,
  178. .bios_param = ata_std_bios_param,
  179. };
  180. static struct ata_port_operations it8172_port_ops = {
  181. .port_disable = ata_port_disable,
  182. .set_piomode = it8172_set_piomode,
  183. .set_dmamode = it8172_set_dmamode,
  184. .mode_filter = ata_pci_default_filter,
  185. .tf_load = ata_tf_load,
  186. .tf_read = ata_tf_read,
  187. .check_status = ata_check_status,
  188. .exec_command = ata_exec_command,
  189. .dev_select = ata_std_dev_select,
  190. .freeze = ata_bmdma_freeze,
  191. .thaw = ata_bmdma_thaw,
  192. .error_handler = it8172_error_handler,
  193. .post_internal_cmd = ata_bmdma_post_internal_cmd,
  194. .bmdma_setup = ata_bmdma_setup,
  195. .bmdma_start = ata_bmdma_start,
  196. .bmdma_stop = ata_bmdma_stop,
  197. .bmdma_status = ata_bmdma_status,
  198. .qc_prep = ata_qc_prep,
  199. .qc_issue = ata_qc_issue_prot,
  200. .eng_timeout = ata_eng_timeout,
  201. .data_xfer = ata_pio_data_xfer,
  202. .irq_handler = ata_interrupt,
  203. .irq_clear = ata_bmdma_irq_clear,
  204. .port_start = ata_port_start,
  205. .port_stop = ata_port_stop,
  206. .host_stop = ata_host_stop
  207. };
  208. static int it8172_init_one(struct pci_dev *dev, const struct pci_device_id *id)
  209. {
  210. static struct ata_port_info info = {
  211. .sht = &it8172_sht,
  212. .flags = ATA_FLAG_SLAVE_POSS | ATA_FLAG_SRST,
  213. .pio_mask = 0x1f,
  214. .mwdma_mask = 0x06, /* No MWDMA0 support */
  215. .udma_mask = 0x7,
  216. .port_ops = &it8172_port_ops
  217. };
  218. static struct ata_port_info *port_info[2] = { &info, &info };
  219. if ((!(PCI_FUNC(dev->devfn) & 1) ||
  220. (!((dev->class >> 8) == PCI_CLASS_STORAGE_IDE))))
  221. return -ENODEV; /* IT8172 is more than an IDE controller */
  222. return ata_pci_init_one(dev, port_info, 2);
  223. }
  224. static struct pci_device_id it8172[] = {
  225. { PCI_DEVICE(PCI_VENDOR_ID_ITE, PCI_DEVICE_ID_ITE_IT8172G), },
  226. { 0, },
  227. };
  228. static struct pci_driver it8172_pci_driver = {
  229. .name = DRV_NAME,
  230. .id_table = it8172,
  231. .probe = it8172_init_one,
  232. .remove = ata_pci_remove_one
  233. };
  234. static int __init it8172_init(void)
  235. {
  236. return pci_register_driver(&it8172_pci_driver);
  237. }
  238. static void __exit it8172_exit(void)
  239. {
  240. pci_unregister_driver(&it8172_pci_driver);
  241. }
  242. MODULE_AUTHOR("Alan Cox");
  243. MODULE_DESCRIPTION("low-level driver for ITE IT8172");
  244. MODULE_LICENSE("GPL");
  245. MODULE_DEVICE_TABLE(pci, it8172);
  246. MODULE_VERSION(DRV_VERSION);
  247. module_init(it8172_init);
  248. module_exit(it8172_exit);