pata_cs5535.c 5.6 KB

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