pata_cs5535.c 8.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294
  1. /*
  2. * pata-cs5535.c - CS5535 PATA for new ATA layer
  3. * (C) 2005-2006 Red Hat Inc
  4. * Alan Cox <alan@redhat.com>
  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 neccessary
  29. */
  30. #include <linux/kernel.h>
  31. #include <linux/module.h>
  32. #include <linux/pci.h>
  33. #include <linux/init.h>
  34. #include <linux/blkdev.h>
  35. #include <linux/delay.h>
  36. #include <scsi/scsi_host.h>
  37. #include <linux/libata.h>
  38. #include <asm/msr.h>
  39. #define DRV_NAME "cs5535"
  40. #define DRV_VERSION "0.2.11"
  41. /*
  42. * The Geode (Aka Athlon GX now) uses an internal MSR based
  43. * bus system for control. Demented but there you go.
  44. */
  45. #define MSR_ATAC_BASE 0x51300000
  46. #define ATAC_GLD_MSR_CAP (MSR_ATAC_BASE+0)
  47. #define ATAC_GLD_MSR_CONFIG (MSR_ATAC_BASE+0x01)
  48. #define ATAC_GLD_MSR_SMI (MSR_ATAC_BASE+0x02)
  49. #define ATAC_GLD_MSR_ERROR (MSR_ATAC_BASE+0x03)
  50. #define ATAC_GLD_MSR_PM (MSR_ATAC_BASE+0x04)
  51. #define ATAC_GLD_MSR_DIAG (MSR_ATAC_BASE+0x05)
  52. #define ATAC_IO_BAR (MSR_ATAC_BASE+0x08)
  53. #define ATAC_RESET (MSR_ATAC_BASE+0x10)
  54. #define ATAC_CH0D0_PIO (MSR_ATAC_BASE+0x20)
  55. #define ATAC_CH0D0_DMA (MSR_ATAC_BASE+0x21)
  56. #define ATAC_CH0D1_PIO (MSR_ATAC_BASE+0x22)
  57. #define ATAC_CH0D1_DMA (MSR_ATAC_BASE+0x23)
  58. #define ATAC_PCI_ABRTERR (MSR_ATAC_BASE+0x24)
  59. #define ATAC_BM0_CMD_PRIM 0x00
  60. #define ATAC_BM0_STS_PRIM 0x02
  61. #define ATAC_BM0_PRD 0x04
  62. #define CS5535_CABLE_DETECT 0x48
  63. #define CS5535_BAD_PIO(timings) ( (timings&~0x80000000UL)==0x00009172 )
  64. /**
  65. * cs5535_pre_reset - detect cable type
  66. * @ap: Port to detect on
  67. *
  68. * Perform cable detection for ATA66 capable cable. Return a libata
  69. * cable type.
  70. */
  71. static int cs5535_pre_reset(struct ata_port *ap)
  72. {
  73. u8 cable;
  74. struct pci_dev *pdev = to_pci_dev(ap->host->dev);
  75. pci_read_config_byte(pdev, CS5535_CABLE_DETECT, &cable);
  76. if (cable & 1)
  77. ap->cbl = ATA_CBL_PATA80;
  78. else
  79. ap->cbl = ATA_CBL_PATA40;
  80. return ata_std_prereset(ap);
  81. }
  82. /**
  83. * cs5535_error_handler - reset/probe
  84. * @ap: Port to reset
  85. *
  86. * Reset and configure a port
  87. */
  88. static void cs5535_error_handler(struct ata_port *ap)
  89. {
  90. ata_bmdma_drive_eh(ap, cs5535_pre_reset, ata_std_softreset, NULL, ata_std_postreset);
  91. }
  92. /**
  93. * cs5535_set_piomode - PIO setup
  94. * @ap: ATA interface
  95. * @adev: device on the interface
  96. *
  97. * Set our PIO requirements. The CS5535 is pretty clean about all this
  98. */
  99. static void cs5535_set_piomode(struct ata_port *ap, struct ata_device *adev)
  100. {
  101. static const u16 pio_timings[5] = {
  102. 0xF7F4, 0x53F3, 0x13F1, 0x5131, 0x1131
  103. };
  104. static const u16 pio_cmd_timings[5] = {
  105. 0xF7F4, 0x53F3, 0x13F1, 0x5131, 0x1131
  106. };
  107. u32 reg, dummy;
  108. struct ata_device *pair = ata_dev_pair(adev);
  109. int mode = adev->pio_mode - XFER_PIO_0;
  110. int cmdmode = mode;
  111. /* Command timing has to be for the lowest of the pair of devices */
  112. if (pair) {
  113. int pairmode = pair->pio_mode - XFER_PIO_0;
  114. cmdmode = min(mode, pairmode);
  115. /* Write the other drive timing register if it changed */
  116. if (cmdmode < pairmode)
  117. wrmsr(ATAC_CH0D0_PIO + 2 * pair->devno,
  118. pio_cmd_timings[cmdmode] << 16 | pio_timings[pairmode], 0);
  119. }
  120. /* Write the drive timing register */
  121. wrmsr(ATAC_CH0D0_PIO + 2 * adev->devno,
  122. pio_cmd_timings[cmdmode] << 16 | pio_timings[mode], 0);
  123. /* Set the PIO "format 1" bit in the DMA timing register */
  124. rdmsr(ATAC_CH0D0_DMA + 2 * adev->devno, reg, dummy);
  125. wrmsr(ATAC_CH0D0_DMA + 2 * adev->devno, reg | 0x80000000UL, 0);
  126. }
  127. /**
  128. * cs5535_set_dmamode - DMA timing setup
  129. * @ap: ATA interface
  130. * @adev: Device being configured
  131. *
  132. */
  133. static void cs5535_set_dmamode(struct ata_port *ap, struct ata_device *adev)
  134. {
  135. static const u32 udma_timings[5] = {
  136. 0x7F7436A1, 0x7F733481, 0x7F723261, 0x7F713161, 0x7F703061
  137. };
  138. static const u32 mwdma_timings[3] = {
  139. 0x7F0FFFF3, 0x7F035352, 0x7F024241
  140. };
  141. u32 reg, dummy;
  142. int mode = adev->dma_mode;
  143. rdmsr(ATAC_CH0D0_DMA + 2 * adev->devno, reg, dummy);
  144. reg &= 0x80000000UL;
  145. if (mode >= XFER_UDMA_0)
  146. reg |= udma_timings[mode - XFER_UDMA_0];
  147. else
  148. reg |= mwdma_timings[mode - XFER_MW_DMA_0];
  149. wrmsr(ATAC_CH0D0_DMA + 2 * adev->devno, reg, 0);
  150. }
  151. static struct scsi_host_template cs5535_sht = {
  152. .module = THIS_MODULE,
  153. .name = DRV_NAME,
  154. .ioctl = ata_scsi_ioctl,
  155. .queuecommand = ata_scsi_queuecmd,
  156. .can_queue = ATA_DEF_QUEUE,
  157. .this_id = ATA_SHT_THIS_ID,
  158. .sg_tablesize = LIBATA_MAX_PRD,
  159. .cmd_per_lun = ATA_SHT_CMD_PER_LUN,
  160. .emulated = ATA_SHT_EMULATED,
  161. .use_clustering = ATA_SHT_USE_CLUSTERING,
  162. .proc_name = DRV_NAME,
  163. .dma_boundary = ATA_DMA_BOUNDARY,
  164. .slave_configure = ata_scsi_slave_config,
  165. .slave_destroy = ata_scsi_slave_destroy,
  166. .bios_param = ata_std_bios_param,
  167. .resume = ata_scsi_device_resume,
  168. .suspend = ata_scsi_device_suspend,
  169. };
  170. static struct ata_port_operations cs5535_port_ops = {
  171. .port_disable = ata_port_disable,
  172. .set_piomode = cs5535_set_piomode,
  173. .set_dmamode = cs5535_set_dmamode,
  174. .mode_filter = ata_pci_default_filter,
  175. .tf_load = ata_tf_load,
  176. .tf_read = ata_tf_read,
  177. .check_status = ata_check_status,
  178. .exec_command = ata_exec_command,
  179. .dev_select = ata_std_dev_select,
  180. .freeze = ata_bmdma_freeze,
  181. .thaw = ata_bmdma_thaw,
  182. .error_handler = cs5535_error_handler,
  183. .post_internal_cmd = ata_bmdma_post_internal_cmd,
  184. .bmdma_setup = ata_bmdma_setup,
  185. .bmdma_start = ata_bmdma_start,
  186. .bmdma_stop = ata_bmdma_stop,
  187. .bmdma_status = ata_bmdma_status,
  188. .qc_prep = ata_qc_prep,
  189. .qc_issue = ata_qc_issue_prot,
  190. .data_xfer = ata_data_xfer,
  191. .irq_handler = ata_interrupt,
  192. .irq_clear = ata_bmdma_irq_clear,
  193. .irq_on = ata_irq_on,
  194. .irq_ack = ata_irq_ack,
  195. .port_start = ata_port_start,
  196. };
  197. /**
  198. * cs5535_init_one - Initialise a CS5530
  199. * @dev: PCI device
  200. * @id: Entry in match table
  201. *
  202. * Install a driver for the newly found CS5530 companion chip. Most of
  203. * this is just housekeeping. We have to set the chip up correctly and
  204. * turn off various bits of emulation magic.
  205. */
  206. static int cs5535_init_one(struct pci_dev *dev, const struct pci_device_id *id)
  207. {
  208. static struct ata_port_info info = {
  209. .sht = &cs5535_sht,
  210. .flags = ATA_FLAG_SLAVE_POSS|ATA_FLAG_SRST,
  211. .pio_mask = 0x1f,
  212. .mwdma_mask = 0x07,
  213. .udma_mask = 0x1f,
  214. .port_ops = &cs5535_port_ops
  215. };
  216. struct ata_port_info *ports[1] = { &info };
  217. u32 timings, dummy;
  218. /* Check the BIOS set the initial timing clock. If not set the
  219. timings for PIO0 */
  220. rdmsr(ATAC_CH0D0_PIO, timings, dummy);
  221. if (CS5535_BAD_PIO(timings))
  222. wrmsr(ATAC_CH0D0_PIO, 0xF7F4F7F4UL, 0);
  223. rdmsr(ATAC_CH0D1_PIO, timings, dummy);
  224. if (CS5535_BAD_PIO(timings))
  225. wrmsr(ATAC_CH0D1_PIO, 0xF7F4F7F4UL, 0);
  226. return ata_pci_init_one(dev, ports, 1);
  227. }
  228. static const struct pci_device_id cs5535[] = {
  229. { PCI_VDEVICE(NS, 0x002D), },
  230. { },
  231. };
  232. static struct pci_driver cs5535_pci_driver = {
  233. .name = DRV_NAME,
  234. .id_table = cs5535,
  235. .probe = cs5535_init_one,
  236. .remove = ata_pci_remove_one,
  237. .suspend = ata_pci_device_suspend,
  238. .resume = ata_pci_device_resume,
  239. };
  240. static int __init cs5535_init(void)
  241. {
  242. return pci_register_driver(&cs5535_pci_driver);
  243. }
  244. static void __exit cs5535_exit(void)
  245. {
  246. pci_unregister_driver(&cs5535_pci_driver);
  247. }
  248. MODULE_AUTHOR("Alan Cox, Jens Altmann, Wolfgan Zuleger, Alexander Kiausch");
  249. MODULE_DESCRIPTION("low-level driver for the NS/AMD 5530");
  250. MODULE_LICENSE("GPL");
  251. MODULE_DEVICE_TABLE(pci, cs5535);
  252. MODULE_VERSION(DRV_VERSION);
  253. module_init(cs5535_init);
  254. module_exit(cs5535_exit);