ata_generic.c 6.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214
  1. /*
  2. * ata_generic.c - Generic PATA/SATA controller driver.
  3. * Copyright 2005 Red Hat Inc <alan@redhat.com>, all rights reserved.
  4. *
  5. * Elements from ide/pci/generic.c
  6. * Copyright (C) 2001-2002 Andre Hedrick <andre@linux-ide.org>
  7. * Portions (C) Copyright 2002 Red Hat Inc <alan@redhat.com>
  8. *
  9. * May be copied or modified under the terms of the GNU General Public License
  10. *
  11. * Driver for PCI IDE interfaces implementing the standard bus mastering
  12. * interface functionality. This assumes the BIOS did the drive set up and
  13. * tuning for us. By default we do not grab all IDE class devices as they
  14. * may have other drivers or need fixups to avoid problems. Instead we keep
  15. * a default list of stuff without documentation/driver that appears to
  16. * work.
  17. */
  18. #include <linux/kernel.h>
  19. #include <linux/module.h>
  20. #include <linux/pci.h>
  21. #include <linux/init.h>
  22. #include <linux/blkdev.h>
  23. #include <linux/delay.h>
  24. #include <scsi/scsi_host.h>
  25. #include <linux/libata.h>
  26. #define DRV_NAME "ata_generic"
  27. #define DRV_VERSION "0.2.15"
  28. /*
  29. * A generic parallel ATA driver using libata
  30. */
  31. /**
  32. * generic_set_mode - mode setting
  33. * @link: link to set up
  34. * @unused: returned device on error
  35. *
  36. * Use a non standard set_mode function. We don't want to be tuned.
  37. * The BIOS configured everything. Our job is not to fiddle. We
  38. * read the dma enabled bits from the PCI configuration of the device
  39. * and respect them.
  40. */
  41. static int generic_set_mode(struct ata_link *link, struct ata_device **unused)
  42. {
  43. struct ata_port *ap = link->ap;
  44. int dma_enabled = 0;
  45. struct ata_device *dev;
  46. struct pci_dev *pdev = to_pci_dev(ap->host->dev);
  47. /* Bits 5 and 6 indicate if DMA is active on master/slave */
  48. if (ap->ioaddr.bmdma_addr)
  49. dma_enabled = ioread8(ap->ioaddr.bmdma_addr + ATA_DMA_STATUS);
  50. if (pdev->vendor == PCI_VENDOR_ID_CENATEK)
  51. dma_enabled = 0xFF;
  52. ata_link_for_each_dev(dev, link) {
  53. if (!ata_dev_enabled(dev))
  54. continue;
  55. /* We don't really care */
  56. dev->pio_mode = XFER_PIO_0;
  57. dev->dma_mode = XFER_MW_DMA_0;
  58. /* We do need the right mode information for DMA or PIO
  59. and this comes from the current configuration flags */
  60. if (dma_enabled & (1 << (5 + dev->devno))) {
  61. unsigned int xfer_mask = ata_id_xfermask(dev->id);
  62. const char *name;
  63. if (xfer_mask & (ATA_MASK_MWDMA | ATA_MASK_UDMA))
  64. name = ata_mode_string(xfer_mask);
  65. else {
  66. /* SWDMA perhaps? */
  67. name = "DMA";
  68. xfer_mask |= ata_xfer_mode2mask(XFER_MW_DMA_0);
  69. }
  70. ata_dev_printk(dev, KERN_INFO, "configured for %s\n",
  71. name);
  72. dev->xfer_mode = ata_xfer_mask2mode(xfer_mask);
  73. dev->xfer_shift = ata_xfer_mode2shift(dev->xfer_mode);
  74. dev->flags &= ~ATA_DFLAG_PIO;
  75. } else {
  76. ata_dev_printk(dev, KERN_INFO, "configured for PIO\n");
  77. dev->xfer_mode = XFER_PIO_0;
  78. dev->xfer_shift = ATA_SHIFT_PIO;
  79. dev->flags |= ATA_DFLAG_PIO;
  80. }
  81. }
  82. return 0;
  83. }
  84. static struct scsi_host_template generic_sht = {
  85. ATA_BMDMA_SHT(DRV_NAME),
  86. };
  87. static struct ata_port_operations generic_port_ops = {
  88. .inherits = &ata_bmdma_port_ops,
  89. .cable_detect = ata_cable_unknown,
  90. .set_mode = generic_set_mode,
  91. };
  92. static int all_generic_ide; /* Set to claim all devices */
  93. /**
  94. * ata_generic_init - attach generic IDE
  95. * @dev: PCI device found
  96. * @id: match entry
  97. *
  98. * Called each time a matching IDE interface is found. We check if the
  99. * interface is one we wish to claim and if so we perform any chip
  100. * specific hacks then let the ATA layer do the heavy lifting.
  101. */
  102. static int ata_generic_init_one(struct pci_dev *dev, const struct pci_device_id *id)
  103. {
  104. u16 command;
  105. static const struct ata_port_info info = {
  106. .flags = ATA_FLAG_SLAVE_POSS,
  107. .pio_mask = 0x1f,
  108. .mwdma_mask = 0x07,
  109. .udma_mask = ATA_UDMA5,
  110. .port_ops = &generic_port_ops
  111. };
  112. const struct ata_port_info *ppi[] = { &info, NULL };
  113. /* Don't use the generic entry unless instructed to do so */
  114. if (id->driver_data == 1 && all_generic_ide == 0)
  115. return -ENODEV;
  116. /* Devices that need care */
  117. if (dev->vendor == PCI_VENDOR_ID_UMC &&
  118. dev->device == PCI_DEVICE_ID_UMC_UM8886A &&
  119. (!(PCI_FUNC(dev->devfn) & 1)))
  120. return -ENODEV;
  121. if (dev->vendor == PCI_VENDOR_ID_OPTI &&
  122. dev->device == PCI_DEVICE_ID_OPTI_82C558 &&
  123. (!(PCI_FUNC(dev->devfn) & 1)))
  124. return -ENODEV;
  125. /* Don't re-enable devices in generic mode or we will break some
  126. motherboards with disabled and unused IDE controllers */
  127. pci_read_config_word(dev, PCI_COMMAND, &command);
  128. if (!(command & PCI_COMMAND_IO))
  129. return -ENODEV;
  130. if (dev->vendor == PCI_VENDOR_ID_AL)
  131. ata_pci_bmdma_clear_simplex(dev);
  132. if (dev->vendor == PCI_VENDOR_ID_ATI) {
  133. int rc = pcim_enable_device(dev);
  134. if (rc < 0)
  135. return rc;
  136. pcim_pin_device(dev);
  137. }
  138. return ata_pci_sff_init_one(dev, ppi, &generic_sht, NULL);
  139. }
  140. static struct pci_device_id ata_generic[] = {
  141. { PCI_DEVICE(PCI_VENDOR_ID_PCTECH, PCI_DEVICE_ID_PCTECH_SAMURAI_IDE), },
  142. { PCI_DEVICE(PCI_VENDOR_ID_HOLTEK, PCI_DEVICE_ID_HOLTEK_6565), },
  143. { PCI_DEVICE(PCI_VENDOR_ID_UMC, PCI_DEVICE_ID_UMC_UM8673F), },
  144. { PCI_DEVICE(PCI_VENDOR_ID_UMC, PCI_DEVICE_ID_UMC_UM8886A), },
  145. { PCI_DEVICE(PCI_VENDOR_ID_UMC, PCI_DEVICE_ID_UMC_UM8886BF), },
  146. { PCI_DEVICE(PCI_VENDOR_ID_HINT, PCI_DEVICE_ID_HINT_VXPROII_IDE), },
  147. { PCI_DEVICE(PCI_VENDOR_ID_VIA, PCI_DEVICE_ID_VIA_82C561), },
  148. { PCI_DEVICE(PCI_VENDOR_ID_OPTI, PCI_DEVICE_ID_OPTI_82C558), },
  149. { PCI_DEVICE(PCI_VENDOR_ID_CENATEK,PCI_DEVICE_ID_CENATEK_IDE), },
  150. { PCI_DEVICE(PCI_VENDOR_ID_TOSHIBA,PCI_DEVICE_ID_TOSHIBA_PICCOLO), },
  151. { PCI_DEVICE(PCI_VENDOR_ID_TOSHIBA,PCI_DEVICE_ID_TOSHIBA_PICCOLO_1), },
  152. { PCI_DEVICE(PCI_VENDOR_ID_TOSHIBA,PCI_DEVICE_ID_TOSHIBA_PICCOLO_2), },
  153. /* Must come last. If you add entries adjust this table appropriately */
  154. { PCI_ANY_ID, PCI_ANY_ID, PCI_ANY_ID, PCI_ANY_ID, PCI_CLASS_STORAGE_IDE << 8, 0xFFFFFF00UL, 1},
  155. { 0, },
  156. };
  157. static struct pci_driver ata_generic_pci_driver = {
  158. .name = DRV_NAME,
  159. .id_table = ata_generic,
  160. .probe = ata_generic_init_one,
  161. .remove = ata_pci_remove_one,
  162. #ifdef CONFIG_PM
  163. .suspend = ata_pci_device_suspend,
  164. .resume = ata_pci_device_resume,
  165. #endif
  166. };
  167. static int __init ata_generic_init(void)
  168. {
  169. return pci_register_driver(&ata_generic_pci_driver);
  170. }
  171. static void __exit ata_generic_exit(void)
  172. {
  173. pci_unregister_driver(&ata_generic_pci_driver);
  174. }
  175. MODULE_AUTHOR("Alan Cox");
  176. MODULE_DESCRIPTION("low-level driver for generic ATA");
  177. MODULE_LICENSE("GPL");
  178. MODULE_DEVICE_TABLE(pci, ata_generic);
  179. MODULE_VERSION(DRV_VERSION);
  180. module_init(ata_generic_init);
  181. module_exit(ata_generic_exit);
  182. module_param(all_generic_ide, int, 0);