atiixp.c 5.6 KB

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