atiixp.c 5.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211
  1. /*
  2. * Copyright (C) 2003 ATI Inc. <hyu@ati.com>
  3. * Copyright (C) 2004,2007 Bartlomiej Zolnierkiewicz
  4. */
  5. #include <linux/types.h>
  6. #include <linux/module.h>
  7. #include <linux/kernel.h>
  8. #include <linux/pci.h>
  9. #include <linux/ide.h>
  10. #include <linux/init.h>
  11. #define DRV_NAME "atiixp"
  12. #define ATIIXP_IDE_PIO_TIMING 0x40
  13. #define ATIIXP_IDE_MDMA_TIMING 0x44
  14. #define ATIIXP_IDE_PIO_CONTROL 0x48
  15. #define ATIIXP_IDE_PIO_MODE 0x4a
  16. #define ATIIXP_IDE_UDMA_CONTROL 0x54
  17. #define ATIIXP_IDE_UDMA_MODE 0x56
  18. struct atiixp_ide_timing {
  19. u8 command_width;
  20. u8 recover_width;
  21. };
  22. static struct atiixp_ide_timing pio_timing[] = {
  23. { 0x05, 0x0d },
  24. { 0x04, 0x07 },
  25. { 0x03, 0x04 },
  26. { 0x02, 0x02 },
  27. { 0x02, 0x00 },
  28. };
  29. static struct atiixp_ide_timing mdma_timing[] = {
  30. { 0x07, 0x07 },
  31. { 0x02, 0x01 },
  32. { 0x02, 0x00 },
  33. };
  34. static DEFINE_SPINLOCK(atiixp_lock);
  35. /**
  36. * atiixp_set_pio_mode - set host controller for PIO mode
  37. * @hwif: port
  38. * @drive: drive
  39. *
  40. * Set the interface PIO mode.
  41. */
  42. static void atiixp_set_pio_mode(ide_hwif_t *hwif, ide_drive_t *drive)
  43. {
  44. struct pci_dev *dev = to_pci_dev(hwif->dev);
  45. unsigned long flags;
  46. int timing_shift = (drive->dn ^ 1) * 8;
  47. u32 pio_timing_data;
  48. u16 pio_mode_data;
  49. const u8 pio = drive->pio_mode - XFER_PIO_0;
  50. spin_lock_irqsave(&atiixp_lock, flags);
  51. pci_read_config_word(dev, ATIIXP_IDE_PIO_MODE, &pio_mode_data);
  52. pio_mode_data &= ~(0x07 << (drive->dn * 4));
  53. pio_mode_data |= (pio << (drive->dn * 4));
  54. pci_write_config_word(dev, ATIIXP_IDE_PIO_MODE, pio_mode_data);
  55. pci_read_config_dword(dev, ATIIXP_IDE_PIO_TIMING, &pio_timing_data);
  56. pio_timing_data &= ~(0xff << timing_shift);
  57. pio_timing_data |= (pio_timing[pio].recover_width << timing_shift) |
  58. (pio_timing[pio].command_width << (timing_shift + 4));
  59. pci_write_config_dword(dev, ATIIXP_IDE_PIO_TIMING, pio_timing_data);
  60. spin_unlock_irqrestore(&atiixp_lock, flags);
  61. }
  62. /**
  63. * atiixp_set_dma_mode - set host controller for DMA mode
  64. * @hwif: port
  65. * @drive: drive
  66. *
  67. * Set a ATIIXP host controller to the desired DMA mode. This involves
  68. * programming the right timing data into the PCI configuration space.
  69. */
  70. static void atiixp_set_dma_mode(ide_hwif_t *hwif, ide_drive_t *drive)
  71. {
  72. struct pci_dev *dev = to_pci_dev(hwif->dev);
  73. unsigned long flags;
  74. int timing_shift = (drive->dn ^ 1) * 8;
  75. u32 tmp32;
  76. u16 tmp16;
  77. u16 udma_ctl = 0;
  78. const u8 speed = drive->dma_mode;
  79. spin_lock_irqsave(&atiixp_lock, flags);
  80. pci_read_config_word(dev, ATIIXP_IDE_UDMA_CONTROL, &udma_ctl);
  81. if (speed >= XFER_UDMA_0) {
  82. pci_read_config_word(dev, ATIIXP_IDE_UDMA_MODE, &tmp16);
  83. tmp16 &= ~(0x07 << (drive->dn * 4));
  84. tmp16 |= ((speed & 0x07) << (drive->dn * 4));
  85. pci_write_config_word(dev, ATIIXP_IDE_UDMA_MODE, tmp16);
  86. udma_ctl |= (1 << drive->dn);
  87. } else if (speed >= XFER_MW_DMA_0) {
  88. u8 i = speed & 0x03;
  89. pci_read_config_dword(dev, ATIIXP_IDE_MDMA_TIMING, &tmp32);
  90. tmp32 &= ~(0xff << timing_shift);
  91. tmp32 |= (mdma_timing[i].recover_width << timing_shift) |
  92. (mdma_timing[i].command_width << (timing_shift + 4));
  93. pci_write_config_dword(dev, ATIIXP_IDE_MDMA_TIMING, tmp32);
  94. udma_ctl &= ~(1 << drive->dn);
  95. }
  96. pci_write_config_word(dev, ATIIXP_IDE_UDMA_CONTROL, udma_ctl);
  97. spin_unlock_irqrestore(&atiixp_lock, flags);
  98. }
  99. static u8 atiixp_cable_detect(ide_hwif_t *hwif)
  100. {
  101. struct pci_dev *pdev = to_pci_dev(hwif->dev);
  102. u8 udma_mode = 0, ch = hwif->channel;
  103. pci_read_config_byte(pdev, ATIIXP_IDE_UDMA_MODE + ch, &udma_mode);
  104. if ((udma_mode & 0x07) >= 0x04 || (udma_mode & 0x70) >= 0x40)
  105. return ATA_CBL_PATA80;
  106. else
  107. return ATA_CBL_PATA40;
  108. }
  109. static const struct ide_port_ops atiixp_port_ops = {
  110. .set_pio_mode = atiixp_set_pio_mode,
  111. .set_dma_mode = atiixp_set_dma_mode,
  112. .cable_detect = atiixp_cable_detect,
  113. };
  114. static const struct ide_port_info atiixp_pci_info[] = {
  115. { /* 0: IXP200/300/400/700 */
  116. .name = DRV_NAME,
  117. .enablebits = {{0x48,0x01,0x00}, {0x48,0x08,0x00}},
  118. .port_ops = &atiixp_port_ops,
  119. .pio_mask = ATA_PIO4,
  120. .mwdma_mask = ATA_MWDMA2,
  121. .udma_mask = ATA_UDMA5,
  122. },
  123. { /* 1: IXP600 */
  124. .name = DRV_NAME,
  125. .enablebits = {{0x48,0x01,0x00}, {0x00,0x00,0x00}},
  126. .port_ops = &atiixp_port_ops,
  127. .host_flags = IDE_HFLAG_SINGLE,
  128. .pio_mask = ATA_PIO4,
  129. .mwdma_mask = ATA_MWDMA2,
  130. .udma_mask = ATA_UDMA5,
  131. },
  132. };
  133. /**
  134. * atiixp_init_one - called when a ATIIXP is found
  135. * @dev: the atiixp device
  136. * @id: the matching pci id
  137. *
  138. * Called when the PCI registration layer (or the IDE initialization)
  139. * finds a device matching our IDE device tables.
  140. */
  141. static int atiixp_init_one(struct pci_dev *dev, const struct pci_device_id *id)
  142. {
  143. return ide_pci_init_one(dev, &atiixp_pci_info[id->driver_data], NULL);
  144. }
  145. static const struct pci_device_id atiixp_pci_tbl[] = {
  146. { PCI_VDEVICE(ATI, PCI_DEVICE_ID_ATI_IXP200_IDE), 0 },
  147. { PCI_VDEVICE(ATI, PCI_DEVICE_ID_ATI_IXP300_IDE), 0 },
  148. { PCI_VDEVICE(ATI, PCI_DEVICE_ID_ATI_IXP400_IDE), 0 },
  149. { PCI_VDEVICE(ATI, PCI_DEVICE_ID_ATI_IXP600_IDE), 1 },
  150. { PCI_VDEVICE(ATI, PCI_DEVICE_ID_ATI_IXP700_IDE), 0 },
  151. { PCI_VDEVICE(AMD, PCI_DEVICE_ID_AMD_HUDSON2_IDE), 0 },
  152. { 0, },
  153. };
  154. MODULE_DEVICE_TABLE(pci, atiixp_pci_tbl);
  155. static struct pci_driver atiixp_pci_driver = {
  156. .name = "ATIIXP_IDE",
  157. .id_table = atiixp_pci_tbl,
  158. .probe = atiixp_init_one,
  159. .remove = ide_pci_remove,
  160. .suspend = ide_pci_suspend,
  161. .resume = ide_pci_resume,
  162. };
  163. static int __init atiixp_ide_init(void)
  164. {
  165. return ide_pci_register_driver(&atiixp_pci_driver);
  166. }
  167. static void __exit atiixp_ide_exit(void)
  168. {
  169. pci_unregister_driver(&atiixp_pci_driver);
  170. }
  171. module_init(atiixp_ide_init);
  172. module_exit(atiixp_ide_exit);
  173. MODULE_AUTHOR("HUI YU");
  174. MODULE_DESCRIPTION("PCI driver module for ATI IXP IDE");
  175. MODULE_LICENSE("GPL");