pata_cs5535.c 6.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215
  1. /*
  2. * pata-cs5535.c - CS5535 PATA for new ATA layer
  3. * (C) 2005-2006 Red Hat Inc
  4. * Alan Cox <alan@lxorguk.ukuu.org.uk>
  5. *
  6. * based upon cs5535.c from AMD <Jens.Altmann@amd.com> as cleaned up and
  7. * made readable and Linux style by Wolfgang Zuleger <wolfgang.zuleger@gmx.de>
  8. * and Alexander Kiausch <alex.kiausch@t-online.de>
  9. *
  10. * This program is free software; you can redistribute it and/or modify
  11. * it under the terms of the GNU General Public License version 2 as
  12. * published by the Free Software Foundation.
  13. *
  14. * This program is distributed in the hope that it will be useful,
  15. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  16. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  17. * GNU General Public License for more details.
  18. *
  19. * You should have received a copy of the GNU General Public License
  20. * along with this program; if not, write to the Free Software
  21. * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
  22. *
  23. * Loosely based on the piix & svwks drivers.
  24. *
  25. * Documentation:
  26. * Available from AMD web site.
  27. * TODO
  28. * Review errata to see if serializing is necessary
  29. */
  30. #include <linux/kernel.h>
  31. #include <linux/module.h>
  32. #include <linux/pci.h>
  33. #include <linux/blkdev.h>
  34. #include <linux/delay.h>
  35. #include <scsi/scsi_host.h>
  36. #include <linux/libata.h>
  37. #include <asm/msr.h>
  38. #define DRV_NAME "pata_cs5535"
  39. #define DRV_VERSION "0.2.12"
  40. /*
  41. * The Geode (Aka Athlon GX now) uses an internal MSR based
  42. * bus system for control. Demented but there you go.
  43. */
  44. #define MSR_ATAC_BASE 0x51300000
  45. #define ATAC_GLD_MSR_CAP (MSR_ATAC_BASE+0)
  46. #define ATAC_GLD_MSR_CONFIG (MSR_ATAC_BASE+0x01)
  47. #define ATAC_GLD_MSR_SMI (MSR_ATAC_BASE+0x02)
  48. #define ATAC_GLD_MSR_ERROR (MSR_ATAC_BASE+0x03)
  49. #define ATAC_GLD_MSR_PM (MSR_ATAC_BASE+0x04)
  50. #define ATAC_GLD_MSR_DIAG (MSR_ATAC_BASE+0x05)
  51. #define ATAC_IO_BAR (MSR_ATAC_BASE+0x08)
  52. #define ATAC_RESET (MSR_ATAC_BASE+0x10)
  53. #define ATAC_CH0D0_PIO (MSR_ATAC_BASE+0x20)
  54. #define ATAC_CH0D0_DMA (MSR_ATAC_BASE+0x21)
  55. #define ATAC_CH0D1_PIO (MSR_ATAC_BASE+0x22)
  56. #define ATAC_CH0D1_DMA (MSR_ATAC_BASE+0x23)
  57. #define ATAC_PCI_ABRTERR (MSR_ATAC_BASE+0x24)
  58. #define ATAC_BM0_CMD_PRIM 0x00
  59. #define ATAC_BM0_STS_PRIM 0x02
  60. #define ATAC_BM0_PRD 0x04
  61. #define CS5535_CABLE_DETECT 0x48
  62. /**
  63. * cs5535_cable_detect - detect cable type
  64. * @ap: Port to detect on
  65. *
  66. * Perform cable detection for ATA66 capable cable. Return a libata
  67. * cable type.
  68. */
  69. static int cs5535_cable_detect(struct ata_port *ap)
  70. {
  71. u8 cable;
  72. struct pci_dev *pdev = to_pci_dev(ap->host->dev);
  73. pci_read_config_byte(pdev, CS5535_CABLE_DETECT, &cable);
  74. if (cable & 1)
  75. return ATA_CBL_PATA80;
  76. else
  77. return ATA_CBL_PATA40;
  78. }
  79. /**
  80. * cs5535_set_piomode - PIO setup
  81. * @ap: ATA interface
  82. * @adev: device on the interface
  83. *
  84. * Set our PIO requirements. The CS5535 is pretty clean about all this
  85. */
  86. static void cs5535_set_piomode(struct ata_port *ap, struct ata_device *adev)
  87. {
  88. static const u16 pio_timings[5] = {
  89. 0xF7F4, 0xF173, 0x8141, 0x5131, 0x1131
  90. };
  91. static const u16 pio_cmd_timings[5] = {
  92. 0xF7F4, 0x53F3, 0x13F1, 0x5131, 0x1131
  93. };
  94. u32 reg, dummy;
  95. struct ata_device *pair = ata_dev_pair(adev);
  96. int mode = adev->pio_mode - XFER_PIO_0;
  97. int cmdmode = mode;
  98. /* Command timing has to be for the lowest of the pair of devices */
  99. if (pair) {
  100. int pairmode = pair->pio_mode - XFER_PIO_0;
  101. cmdmode = min(mode, pairmode);
  102. /* Write the other drive timing register if it changed */
  103. if (cmdmode < pairmode)
  104. wrmsr(ATAC_CH0D0_PIO + 2 * pair->devno,
  105. pio_cmd_timings[cmdmode] << 16 | pio_timings[pairmode], 0);
  106. }
  107. /* Write the drive timing register */
  108. wrmsr(ATAC_CH0D0_PIO + 2 * adev->devno,
  109. pio_cmd_timings[cmdmode] << 16 | pio_timings[mode], 0);
  110. /* Set the PIO "format 1" bit in the DMA timing register */
  111. rdmsr(ATAC_CH0D0_DMA + 2 * adev->devno, reg, dummy);
  112. wrmsr(ATAC_CH0D0_DMA + 2 * adev->devno, reg | 0x80000000UL, 0);
  113. }
  114. /**
  115. * cs5535_set_dmamode - DMA timing setup
  116. * @ap: ATA interface
  117. * @adev: Device being configured
  118. *
  119. */
  120. static void cs5535_set_dmamode(struct ata_port *ap, struct ata_device *adev)
  121. {
  122. static const u32 udma_timings[5] = {
  123. 0x7F7436A1, 0x7F733481, 0x7F723261, 0x7F713161, 0x7F703061
  124. };
  125. static const u32 mwdma_timings[3] = {
  126. 0x7F0FFFF3, 0x7F035352, 0x7F024241
  127. };
  128. u32 reg, dummy;
  129. int mode = adev->dma_mode;
  130. rdmsr(ATAC_CH0D0_DMA + 2 * adev->devno, reg, dummy);
  131. reg &= 0x80000000UL;
  132. if (mode >= XFER_UDMA_0)
  133. reg |= udma_timings[mode - XFER_UDMA_0];
  134. else
  135. reg |= mwdma_timings[mode - XFER_MW_DMA_0];
  136. wrmsr(ATAC_CH0D0_DMA + 2 * adev->devno, reg, 0);
  137. }
  138. static struct scsi_host_template cs5535_sht = {
  139. ATA_BMDMA_SHT(DRV_NAME),
  140. };
  141. static struct ata_port_operations cs5535_port_ops = {
  142. .inherits = &ata_bmdma_port_ops,
  143. .cable_detect = cs5535_cable_detect,
  144. .set_piomode = cs5535_set_piomode,
  145. .set_dmamode = cs5535_set_dmamode,
  146. };
  147. /**
  148. * cs5535_init_one - Initialise a CS5530
  149. * @dev: PCI device
  150. * @id: Entry in match table
  151. *
  152. * Install a driver for the newly found CS5530 companion chip. Most of
  153. * this is just housekeeping. We have to set the chip up correctly and
  154. * turn off various bits of emulation magic.
  155. */
  156. static int cs5535_init_one(struct pci_dev *dev, const struct pci_device_id *id)
  157. {
  158. static const struct ata_port_info info = {
  159. .flags = ATA_FLAG_SLAVE_POSS,
  160. .pio_mask = ATA_PIO4,
  161. .mwdma_mask = ATA_MWDMA2,
  162. .udma_mask = ATA_UDMA4,
  163. .port_ops = &cs5535_port_ops
  164. };
  165. const struct ata_port_info *ppi[] = { &info, &ata_dummy_port_info };
  166. return ata_pci_bmdma_init_one(dev, ppi, &cs5535_sht, NULL, 0);
  167. }
  168. static const struct pci_device_id cs5535[] = {
  169. { PCI_VDEVICE(NS, PCI_DEVICE_ID_NS_CS5535_IDE), },
  170. { PCI_VDEVICE(AMD, PCI_DEVICE_ID_AMD_CS5535_IDE), },
  171. { },
  172. };
  173. static struct pci_driver cs5535_pci_driver = {
  174. .name = DRV_NAME,
  175. .id_table = cs5535,
  176. .probe = cs5535_init_one,
  177. .remove = ata_pci_remove_one,
  178. #ifdef CONFIG_PM_SLEEP
  179. .suspend = ata_pci_device_suspend,
  180. .resume = ata_pci_device_resume,
  181. #endif
  182. };
  183. module_pci_driver(cs5535_pci_driver);
  184. MODULE_AUTHOR("Alan Cox, Jens Altmann, Wolfgan Zuleger, Alexander Kiausch");
  185. MODULE_DESCRIPTION("low-level driver for the NS/AMD 5535");
  186. MODULE_LICENSE("GPL");
  187. MODULE_DEVICE_TABLE(pci, cs5535);
  188. MODULE_VERSION(DRV_VERSION);