pata_acpi.c 7.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305
  1. /*
  2. * ACPI PATA driver
  3. *
  4. * (c) 2007 Red Hat <alan@redhat.com>
  5. */
  6. #include <linux/kernel.h>
  7. #include <linux/module.h>
  8. #include <linux/pci.h>
  9. #include <linux/init.h>
  10. #include <linux/blkdev.h>
  11. #include <linux/delay.h>
  12. #include <linux/device.h>
  13. #include <scsi/scsi_host.h>
  14. #include <acpi/acpi_bus.h>
  15. #include <acpi/acnames.h>
  16. #include <acpi/acnamesp.h>
  17. #include <acpi/acparser.h>
  18. #include <acpi/acexcep.h>
  19. #include <acpi/acmacros.h>
  20. #include <acpi/actypes.h>
  21. #include <linux/libata.h>
  22. #include <linux/ata.h>
  23. #define DRV_NAME "pata_acpi"
  24. #define DRV_VERSION "0.2.3"
  25. struct pata_acpi {
  26. struct ata_acpi_gtm gtm;
  27. void *last;
  28. unsigned long mask[2];
  29. };
  30. /**
  31. * pacpi_pre_reset - check for 40/80 pin
  32. * @ap: Port
  33. * @deadline: deadline jiffies for the operation
  34. *
  35. * Perform the PATA port setup we need.
  36. */
  37. static int pacpi_pre_reset(struct ata_link *link, unsigned long deadline)
  38. {
  39. struct ata_port *ap = link->ap;
  40. struct pata_acpi *acpi = ap->private_data;
  41. if (ap->acpi_handle == NULL || ata_acpi_gtm(ap, &acpi->gtm) < 0)
  42. return -ENODEV;
  43. return ata_sff_prereset(link, deadline);
  44. }
  45. /**
  46. * pacpi_cable_detect - cable type detection
  47. * @ap: port to detect
  48. *
  49. * Perform device specific cable detection
  50. */
  51. static int pacpi_cable_detect(struct ata_port *ap)
  52. {
  53. struct pata_acpi *acpi = ap->private_data;
  54. if ((acpi->mask[0] | acpi->mask[1]) & (0xF8 << ATA_SHIFT_UDMA))
  55. return ATA_CBL_PATA80;
  56. else
  57. return ATA_CBL_PATA40;
  58. }
  59. /**
  60. * pacpi_discover_modes - filter non ACPI modes
  61. * @adev: ATA device
  62. * @mask: proposed modes
  63. *
  64. * Try the modes available and see which ones the ACPI method will
  65. * set up sensibly. From this we get a mask of ACPI modes we can use
  66. */
  67. static unsigned long pacpi_discover_modes(struct ata_port *ap, struct ata_device *adev)
  68. {
  69. struct pata_acpi *acpi = ap->private_data;
  70. struct ata_acpi_gtm probe;
  71. unsigned int xfer_mask;
  72. probe = acpi->gtm;
  73. ata_acpi_gtm(ap, &probe);
  74. xfer_mask = ata_acpi_gtm_xfermask(adev, &probe);
  75. if (xfer_mask & (0xF8 << ATA_SHIFT_UDMA))
  76. ap->cbl = ATA_CBL_PATA80;
  77. return xfer_mask;
  78. }
  79. /**
  80. * pacpi_mode_filter - mode filter for ACPI
  81. * @adev: device
  82. * @mask: mask of valid modes
  83. *
  84. * Filter the valid mode list according to our own specific rules, in
  85. * this case the list of discovered valid modes obtained by ACPI probing
  86. */
  87. static unsigned long pacpi_mode_filter(struct ata_device *adev, unsigned long mask)
  88. {
  89. struct pata_acpi *acpi = adev->link->ap->private_data;
  90. return ata_bmdma_mode_filter(adev, mask & acpi->mask[adev->devno]);
  91. }
  92. /**
  93. * pacpi_set_piomode - set initial PIO mode data
  94. * @ap: ATA interface
  95. * @adev: ATA device
  96. */
  97. static void pacpi_set_piomode(struct ata_port *ap, struct ata_device *adev)
  98. {
  99. int unit = adev->devno;
  100. struct pata_acpi *acpi = ap->private_data;
  101. const struct ata_timing *t;
  102. if (!(acpi->gtm.flags & 0x10))
  103. unit = 0;
  104. /* Now stuff the nS values into the structure */
  105. t = ata_timing_find_mode(adev->pio_mode);
  106. acpi->gtm.drive[unit].pio = t->cycle;
  107. ata_acpi_stm(ap, &acpi->gtm);
  108. /* See what mode we actually got */
  109. ata_acpi_gtm(ap, &acpi->gtm);
  110. }
  111. /**
  112. * pacpi_set_dmamode - set initial DMA mode data
  113. * @ap: ATA interface
  114. * @adev: ATA device
  115. */
  116. static void pacpi_set_dmamode(struct ata_port *ap, struct ata_device *adev)
  117. {
  118. int unit = adev->devno;
  119. struct pata_acpi *acpi = ap->private_data;
  120. const struct ata_timing *t;
  121. if (!(acpi->gtm.flags & 0x10))
  122. unit = 0;
  123. /* Now stuff the nS values into the structure */
  124. t = ata_timing_find_mode(adev->dma_mode);
  125. if (adev->dma_mode >= XFER_UDMA_0) {
  126. acpi->gtm.drive[unit].dma = t->udma;
  127. acpi->gtm.flags |= (1 << (2 * unit));
  128. } else {
  129. acpi->gtm.drive[unit].dma = t->cycle;
  130. acpi->gtm.flags &= ~(1 << (2 * unit));
  131. }
  132. ata_acpi_stm(ap, &acpi->gtm);
  133. /* See what mode we actually got */
  134. ata_acpi_gtm(ap, &acpi->gtm);
  135. }
  136. /**
  137. * pacpi_qc_issue - command issue
  138. * @qc: command pending
  139. *
  140. * Called when the libata layer is about to issue a command. We wrap
  141. * this interface so that we can load the correct ATA timings if
  142. * neccessary.
  143. */
  144. static unsigned int pacpi_qc_issue(struct ata_queued_cmd *qc)
  145. {
  146. struct ata_port *ap = qc->ap;
  147. struct ata_device *adev = qc->dev;
  148. struct pata_acpi *acpi = ap->private_data;
  149. if (acpi->gtm.flags & 0x10)
  150. return ata_sff_qc_issue(qc);
  151. if (adev != acpi->last) {
  152. pacpi_set_piomode(ap, adev);
  153. if (ata_dma_enabled(adev))
  154. pacpi_set_dmamode(ap, adev);
  155. acpi->last = adev;
  156. }
  157. return ata_sff_qc_issue(qc);
  158. }
  159. /**
  160. * pacpi_port_start - port setup
  161. * @ap: ATA port being set up
  162. *
  163. * Use the port_start hook to maintain private control structures
  164. */
  165. static int pacpi_port_start(struct ata_port *ap)
  166. {
  167. struct pci_dev *pdev = to_pci_dev(ap->host->dev);
  168. struct pata_acpi *acpi;
  169. int ret;
  170. if (ap->acpi_handle == NULL)
  171. return -ENODEV;
  172. acpi = ap->private_data = devm_kzalloc(&pdev->dev, sizeof(struct pata_acpi), GFP_KERNEL);
  173. if (ap->private_data == NULL)
  174. return -ENOMEM;
  175. acpi->mask[0] = pacpi_discover_modes(ap, &ap->link.device[0]);
  176. acpi->mask[1] = pacpi_discover_modes(ap, &ap->link.device[1]);
  177. ret = ata_sff_port_start(ap);
  178. if (ret < 0)
  179. return ret;
  180. return ret;
  181. }
  182. static struct scsi_host_template pacpi_sht = {
  183. ATA_BMDMA_SHT(DRV_NAME),
  184. };
  185. static struct ata_port_operations pacpi_ops = {
  186. .inherits = &ata_bmdma_port_ops,
  187. .qc_issue = pacpi_qc_issue,
  188. .cable_detect = pacpi_cable_detect,
  189. .mode_filter = pacpi_mode_filter,
  190. .set_piomode = pacpi_set_piomode,
  191. .set_dmamode = pacpi_set_dmamode,
  192. .prereset = pacpi_pre_reset,
  193. .port_start = pacpi_port_start,
  194. };
  195. /**
  196. * pacpi_init_one - Register ACPI ATA PCI device with kernel services
  197. * @pdev: PCI device to register
  198. * @ent: Entry in pacpi_pci_tbl matching with @pdev
  199. *
  200. * Called from kernel PCI layer.
  201. *
  202. * LOCKING:
  203. * Inherited from PCI layer (may sleep).
  204. *
  205. * RETURNS:
  206. * Zero on success, or -ERRNO value.
  207. */
  208. static int pacpi_init_one (struct pci_dev *pdev, const struct pci_device_id *id)
  209. {
  210. static const struct ata_port_info info = {
  211. .flags = ATA_FLAG_SLAVE_POSS | ATA_FLAG_SRST,
  212. .pio_mask = 0x1f,
  213. .mwdma_mask = 0x07,
  214. .udma_mask = 0x7f,
  215. .port_ops = &pacpi_ops,
  216. };
  217. const struct ata_port_info *ppi[] = { &info, NULL };
  218. if (pdev->vendor == PCI_VENDOR_ID_ATI) {
  219. int rc = pcim_enable_device(pdev);
  220. if (rc < 0)
  221. return rc;
  222. pcim_pin_device(pdev);
  223. }
  224. return ata_pci_sff_init_one(pdev, ppi, &pacpi_sht, NULL);
  225. }
  226. static const struct pci_device_id pacpi_pci_tbl[] = {
  227. { PCI_ANY_ID, PCI_ANY_ID, PCI_ANY_ID, PCI_ANY_ID, PCI_CLASS_STORAGE_IDE << 8, 0xFFFFFF00UL, 1},
  228. { } /* terminate list */
  229. };
  230. static struct pci_driver pacpi_pci_driver = {
  231. .name = DRV_NAME,
  232. .id_table = pacpi_pci_tbl,
  233. .probe = pacpi_init_one,
  234. .remove = ata_pci_remove_one,
  235. #ifdef CONFIG_PM
  236. .suspend = ata_pci_device_suspend,
  237. .resume = ata_pci_device_resume,
  238. #endif
  239. };
  240. static int __init pacpi_init(void)
  241. {
  242. return pci_register_driver(&pacpi_pci_driver);
  243. }
  244. static void __exit pacpi_exit(void)
  245. {
  246. pci_unregister_driver(&pacpi_pci_driver);
  247. }
  248. module_init(pacpi_init);
  249. module_exit(pacpi_exit);
  250. MODULE_AUTHOR("Alan Cox");
  251. MODULE_DESCRIPTION("SCSI low-level driver for ATA in ACPI mode");
  252. MODULE_LICENSE("GPL");
  253. MODULE_DEVICE_TABLE(pci, pacpi_pci_tbl);
  254. MODULE_VERSION(DRV_VERSION);