pata_sch.c 5.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194
  1. /*
  2. * pata_sch.c - Intel SCH PATA controllers
  3. *
  4. * Copyright (c) 2008 Alek Du <alek.du@intel.com>
  5. *
  6. * This program is free software; you can redistribute it and/or modify
  7. * it under the terms of the GNU General Public License 2 as published
  8. * by the Free Software Foundation.
  9. *
  10. * This program is distributed in the hope that it will be useful,
  11. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  12. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  13. * GNU General Public License for more details.
  14. *
  15. * You should have received a copy of the GNU General Public License
  16. * along with this program; see the file COPYING. If not, write to
  17. * the Free Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA.
  18. *
  19. */
  20. /*
  21. * Supports:
  22. * Intel SCH (AF82US15W, AF82US15L, AF82UL11L) chipsets -- see spec at:
  23. * http://download.intel.com/design/chipsets/embedded/datashts/319537.pdf
  24. */
  25. #include <linux/kernel.h>
  26. #include <linux/module.h>
  27. #include <linux/pci.h>
  28. #include <linux/init.h>
  29. #include <linux/blkdev.h>
  30. #include <linux/delay.h>
  31. #include <linux/device.h>
  32. #include <scsi/scsi_host.h>
  33. #include <linux/libata.h>
  34. #include <linux/dmi.h>
  35. #define DRV_NAME "pata_sch"
  36. #define DRV_VERSION "0.2"
  37. /* see SCH datasheet page 351 */
  38. enum {
  39. D0TIM = 0x80, /* Device 0 Timing Register */
  40. D1TIM = 0x84, /* Device 1 Timing Register */
  41. PM = 0x07, /* PIO Mode Bit Mask */
  42. MDM = (0x03 << 8), /* Multi-word DMA Mode Bit Mask */
  43. UDM = (0x07 << 16), /* Ultra DMA Mode Bit Mask */
  44. PPE = (1 << 30), /* Prefetch/Post Enable */
  45. USD = (1 << 31), /* Use Synchronous DMA */
  46. };
  47. static int sch_init_one(struct pci_dev *pdev,
  48. const struct pci_device_id *ent);
  49. static void sch_set_piomode(struct ata_port *ap, struct ata_device *adev);
  50. static void sch_set_dmamode(struct ata_port *ap, struct ata_device *adev);
  51. static const struct pci_device_id sch_pci_tbl[] = {
  52. /* Intel SCH PATA Controller */
  53. { PCI_VDEVICE(INTEL, PCI_DEVICE_ID_INTEL_SCH_IDE), 0 },
  54. { } /* terminate list */
  55. };
  56. static struct pci_driver sch_pci_driver = {
  57. .name = DRV_NAME,
  58. .id_table = sch_pci_tbl,
  59. .probe = sch_init_one,
  60. .remove = ata_pci_remove_one,
  61. #ifdef CONFIG_PM
  62. .suspend = ata_pci_device_suspend,
  63. .resume = ata_pci_device_resume,
  64. #endif
  65. };
  66. static struct scsi_host_template sch_sht = {
  67. ATA_BMDMA_SHT(DRV_NAME),
  68. };
  69. static struct ata_port_operations sch_pata_ops = {
  70. .inherits = &ata_bmdma_port_ops,
  71. .cable_detect = ata_cable_unknown,
  72. .set_piomode = sch_set_piomode,
  73. .set_dmamode = sch_set_dmamode,
  74. };
  75. static struct ata_port_info sch_port_info = {
  76. .flags = ATA_FLAG_SLAVE_POSS,
  77. .pio_mask = ATA_PIO4,
  78. .mwdma_mask = ATA_MWDMA2,
  79. .udma_mask = ATA_UDMA5,
  80. .port_ops = &sch_pata_ops,
  81. };
  82. MODULE_AUTHOR("Alek Du <alek.du@intel.com>");
  83. MODULE_DESCRIPTION("SCSI low-level driver for Intel SCH PATA controllers");
  84. MODULE_LICENSE("GPL");
  85. MODULE_DEVICE_TABLE(pci, sch_pci_tbl);
  86. MODULE_VERSION(DRV_VERSION);
  87. /**
  88. * sch_set_piomode - Initialize host controller PATA PIO timings
  89. * @ap: Port whose timings we are configuring
  90. * @adev: ATA device
  91. *
  92. * Set PIO mode for device, in host controller PCI config space.
  93. *
  94. * LOCKING:
  95. * None (inherited from caller).
  96. */
  97. static void sch_set_piomode(struct ata_port *ap, struct ata_device *adev)
  98. {
  99. unsigned int pio = adev->pio_mode - XFER_PIO_0;
  100. struct pci_dev *dev = to_pci_dev(ap->host->dev);
  101. unsigned int port = adev->devno ? D1TIM : D0TIM;
  102. unsigned int data;
  103. pci_read_config_dword(dev, port, &data);
  104. /* see SCH datasheet page 351 */
  105. /* set PIO mode */
  106. data &= ~(PM | PPE);
  107. data |= pio;
  108. /* enable PPE for block device */
  109. if (adev->class == ATA_DEV_ATA)
  110. data |= PPE;
  111. pci_write_config_dword(dev, port, data);
  112. }
  113. /**
  114. * sch_set_dmamode - Initialize host controller PATA DMA timings
  115. * @ap: Port whose timings we are configuring
  116. * @adev: ATA device
  117. *
  118. * Set MW/UDMA mode for device, in host controller PCI config space.
  119. *
  120. * LOCKING:
  121. * None (inherited from caller).
  122. */
  123. static void sch_set_dmamode(struct ata_port *ap, struct ata_device *adev)
  124. {
  125. unsigned int dma_mode = adev->dma_mode;
  126. struct pci_dev *dev = to_pci_dev(ap->host->dev);
  127. unsigned int port = adev->devno ? D1TIM : D0TIM;
  128. unsigned int data;
  129. pci_read_config_dword(dev, port, &data);
  130. /* see SCH datasheet page 351 */
  131. if (dma_mode >= XFER_UDMA_0) {
  132. /* enable Synchronous DMA mode */
  133. data |= USD;
  134. data &= ~UDM;
  135. data |= (dma_mode - XFER_UDMA_0) << 16;
  136. } else { /* must be MWDMA mode, since we masked SWDMA already */
  137. data &= ~(USD | MDM);
  138. data |= (dma_mode - XFER_MW_DMA_0) << 8;
  139. }
  140. pci_write_config_dword(dev, port, data);
  141. }
  142. /**
  143. * sch_init_one - Register SCH ATA PCI device with kernel services
  144. * @pdev: PCI device to register
  145. * @ent: Entry in sch_pci_tbl matching with @pdev
  146. *
  147. * LOCKING:
  148. * Inherited from PCI layer (may sleep).
  149. *
  150. * RETURNS:
  151. * Zero on success, or -ERRNO value.
  152. */
  153. static int __devinit sch_init_one(struct pci_dev *pdev,
  154. const struct pci_device_id *ent)
  155. {
  156. const struct ata_port_info *ppi[] = { &sch_port_info, NULL };
  157. ata_print_version_once(&pdev->dev, DRV_VERSION);
  158. return ata_pci_bmdma_init_one(pdev, ppi, &sch_sht, NULL, 0);
  159. }
  160. static int __init sch_init(void)
  161. {
  162. return pci_register_driver(&sch_pci_driver);
  163. }
  164. static void __exit sch_exit(void)
  165. {
  166. pci_unregister_driver(&sch_pci_driver);
  167. }
  168. module_init(sch_init);
  169. module_exit(sch_exit);