pata_ns87410.c 4.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176
  1. /*
  2. * pata_ns87410.c - National Semiconductor 87410 PATA for new ATA layer
  3. * (C) 2006 Red Hat Inc
  4. *
  5. * This program is free software; you can redistribute it and/or modify
  6. * it under the terms of the GNU General Public License as published by
  7. * the Free Software Foundation; either version 2, or (at your option)
  8. * any later version.
  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. #include <linux/kernel.h>
  20. #include <linux/module.h>
  21. #include <linux/pci.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 "pata_ns87410"
  27. #define DRV_VERSION "0.4.6"
  28. /**
  29. * ns87410_pre_reset - probe begin
  30. * @link: ATA link
  31. * @deadline: deadline jiffies for the operation
  32. *
  33. * Check enabled ports
  34. */
  35. static int ns87410_pre_reset(struct ata_link *link, unsigned long deadline)
  36. {
  37. struct ata_port *ap = link->ap;
  38. struct pci_dev *pdev = to_pci_dev(ap->host->dev);
  39. static const struct pci_bits ns87410_enable_bits[] = {
  40. { 0x43, 1, 0x08, 0x08 },
  41. { 0x47, 1, 0x08, 0x08 }
  42. };
  43. if (!pci_test_config_bits(pdev, &ns87410_enable_bits[ap->port_no]))
  44. return -ENOENT;
  45. return ata_sff_prereset(link, deadline);
  46. }
  47. /**
  48. * ns87410_set_piomode - set initial PIO mode data
  49. * @ap: ATA interface
  50. * @adev: ATA device
  51. *
  52. * Program timing data. This is kept per channel not per device,
  53. * and only affects the data port.
  54. */
  55. static void ns87410_set_piomode(struct ata_port *ap, struct ata_device *adev)
  56. {
  57. struct pci_dev *pdev = to_pci_dev(ap->host->dev);
  58. int port = 0x40 + 4 * ap->port_no;
  59. u8 idetcr, idefr;
  60. struct ata_timing at;
  61. static const u8 activebits[15] = {
  62. 0, 1, 2, 3, 4,
  63. 5, 5, 6, 6, 6,
  64. 6, 7, 7, 7, 7
  65. };
  66. static const u8 recoverbits[12] = {
  67. 0, 1, 2, 3, 4, 5, 6, 6, 7, 7, 7, 7
  68. };
  69. pci_read_config_byte(pdev, port + 3, &idefr);
  70. if (ata_pio_need_iordy(adev))
  71. idefr |= 0x04; /* IORDY enable */
  72. else
  73. idefr &= ~0x04;
  74. if (ata_timing_compute(adev, adev->pio_mode, &at, 30303, 1) < 0) {
  75. dev_err(&pdev->dev, "unknown mode %d\n", adev->pio_mode);
  76. return;
  77. }
  78. at.active = clamp_val(at.active, 2, 16) - 2;
  79. at.setup = clamp_val(at.setup, 1, 4) - 1;
  80. at.recover = clamp_val(at.recover, 1, 12) - 1;
  81. idetcr = (at.setup << 6) | (recoverbits[at.recover] << 3) | activebits[at.active];
  82. pci_write_config_byte(pdev, port, idetcr);
  83. pci_write_config_byte(pdev, port + 3, idefr);
  84. /* We use ap->private_data as a pointer to the device currently
  85. loaded for timing */
  86. ap->private_data = adev;
  87. }
  88. /**
  89. * ns87410_qc_issue - command issue
  90. * @qc: command pending
  91. *
  92. * Called when the libata layer is about to issue a command. We wrap
  93. * this interface so that we can load the correct ATA timings if
  94. * necessary.
  95. */
  96. static unsigned int ns87410_qc_issue(struct ata_queued_cmd *qc)
  97. {
  98. struct ata_port *ap = qc->ap;
  99. struct ata_device *adev = qc->dev;
  100. /* If modes have been configured and the channel data is not loaded
  101. then load it. We have to check if pio_mode is set as the core code
  102. does not set adev->pio_mode to XFER_PIO_0 while probing as would be
  103. logical */
  104. if (adev->pio_mode && adev != ap->private_data)
  105. ns87410_set_piomode(ap, adev);
  106. return ata_sff_qc_issue(qc);
  107. }
  108. static struct scsi_host_template ns87410_sht = {
  109. ATA_PIO_SHT(DRV_NAME),
  110. };
  111. static struct ata_port_operations ns87410_port_ops = {
  112. .inherits = &ata_sff_port_ops,
  113. .qc_issue = ns87410_qc_issue,
  114. .cable_detect = ata_cable_40wire,
  115. .set_piomode = ns87410_set_piomode,
  116. .prereset = ns87410_pre_reset,
  117. };
  118. static int ns87410_init_one(struct pci_dev *dev, const struct pci_device_id *id)
  119. {
  120. static const struct ata_port_info info = {
  121. .flags = ATA_FLAG_SLAVE_POSS,
  122. .pio_mask = ATA_PIO3,
  123. .port_ops = &ns87410_port_ops
  124. };
  125. const struct ata_port_info *ppi[] = { &info, NULL };
  126. return ata_pci_sff_init_one(dev, ppi, &ns87410_sht, NULL, 0);
  127. }
  128. static const struct pci_device_id ns87410[] = {
  129. { PCI_VDEVICE(NS, PCI_DEVICE_ID_NS_87410), },
  130. { },
  131. };
  132. static struct pci_driver ns87410_pci_driver = {
  133. .name = DRV_NAME,
  134. .id_table = ns87410,
  135. .probe = ns87410_init_one,
  136. .remove = ata_pci_remove_one,
  137. #ifdef CONFIG_PM_SLEEP
  138. .suspend = ata_pci_device_suspend,
  139. .resume = ata_pci_device_resume,
  140. #endif
  141. };
  142. module_pci_driver(ns87410_pci_driver);
  143. MODULE_AUTHOR("Alan Cox");
  144. MODULE_DESCRIPTION("low-level driver for Nat Semi 87410");
  145. MODULE_LICENSE("GPL");
  146. MODULE_DEVICE_TABLE(pci, ns87410);
  147. MODULE_VERSION(DRV_VERSION);