atiixp.c 5.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208
  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/hdreg.h>
  10. #include <linux/ide.h>
  11. #include <linux/init.h>
  12. #define DRV_NAME "atiixp"
  13. #define ATIIXP_IDE_PIO_TIMING 0x40
  14. #define ATIIXP_IDE_MDMA_TIMING 0x44
  15. #define ATIIXP_IDE_PIO_CONTROL 0x48
  16. #define ATIIXP_IDE_PIO_MODE 0x4a
  17. #define ATIIXP_IDE_UDMA_CONTROL 0x54
  18. #define ATIIXP_IDE_UDMA_MODE 0x56
  19. typedef struct {
  20. u8 command_width;
  21. u8 recover_width;
  22. } atiixp_ide_timing;
  23. static atiixp_ide_timing pio_timing[] = {
  24. { 0x05, 0x0d },
  25. { 0x04, 0x07 },
  26. { 0x03, 0x04 },
  27. { 0x02, 0x02 },
  28. { 0x02, 0x00 },
  29. };
  30. static atiixp_ide_timing mdma_timing[] = {
  31. { 0x07, 0x07 },
  32. { 0x02, 0x01 },
  33. { 0x02, 0x00 },
  34. };
  35. static DEFINE_SPINLOCK(atiixp_lock);
  36. /**
  37. * atiixp_set_pio_mode - set host controller for PIO mode
  38. * @drive: drive
  39. * @pio: PIO mode number
  40. *
  41. * Set the interface PIO mode.
  42. */
  43. static void atiixp_set_pio_mode(ide_drive_t *drive, const u8 pio)
  44. {
  45. struct pci_dev *dev = to_pci_dev(drive->hwif->dev);
  46. unsigned long flags;
  47. int timing_shift = (drive->dn & 2) ? 16 : 0 + (drive->dn & 1) ? 0 : 8;
  48. u32 pio_timing_data;
  49. u16 pio_mode_data;
  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. * @drive: drive
  65. * @speed: DMA mode
  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_drive_t *drive, const u8 speed)
  71. {
  72. struct pci_dev *dev = to_pci_dev(drive->hwif->dev);
  73. unsigned long flags;
  74. int timing_shift = (drive->dn & 2) ? 16 : 0 + (drive->dn & 1) ? 0 : 8;
  75. u32 tmp32;
  76. u16 tmp16;
  77. u16 udma_ctl = 0;
  78. spin_lock_irqsave(&atiixp_lock, flags);
  79. pci_read_config_word(dev, ATIIXP_IDE_UDMA_CONTROL, &udma_ctl);
  80. if (speed >= XFER_UDMA_0) {
  81. pci_read_config_word(dev, ATIIXP_IDE_UDMA_MODE, &tmp16);
  82. tmp16 &= ~(0x07 << (drive->dn * 4));
  83. tmp16 |= ((speed & 0x07) << (drive->dn * 4));
  84. pci_write_config_word(dev, ATIIXP_IDE_UDMA_MODE, tmp16);
  85. udma_ctl |= (1 << drive->dn);
  86. } else if (speed >= XFER_MW_DMA_0) {
  87. u8 i = speed & 0x03;
  88. pci_read_config_dword(dev, ATIIXP_IDE_MDMA_TIMING, &tmp32);
  89. tmp32 &= ~(0xff << timing_shift);
  90. tmp32 |= (mdma_timing[i].recover_width << timing_shift) |
  91. (mdma_timing[i].command_width << (timing_shift + 4));
  92. pci_write_config_dword(dev, ATIIXP_IDE_MDMA_TIMING, tmp32);
  93. udma_ctl &= ~(1 << drive->dn);
  94. }
  95. pci_write_config_word(dev, ATIIXP_IDE_UDMA_CONTROL, udma_ctl);
  96. spin_unlock_irqrestore(&atiixp_lock, flags);
  97. }
  98. static u8 atiixp_cable_detect(ide_hwif_t *hwif)
  99. {
  100. struct pci_dev *pdev = to_pci_dev(hwif->dev);
  101. u8 udma_mode = 0, ch = hwif->channel;
  102. pci_read_config_byte(pdev, ATIIXP_IDE_UDMA_MODE + ch, &udma_mode);
  103. if ((udma_mode & 0x07) >= 0x04 || (udma_mode & 0x70) >= 0x40)
  104. return ATA_CBL_PATA80;
  105. else
  106. return ATA_CBL_PATA40;
  107. }
  108. static const struct ide_port_ops atiixp_port_ops = {
  109. .set_pio_mode = atiixp_set_pio_mode,
  110. .set_dma_mode = atiixp_set_dma_mode,
  111. .cable_detect = atiixp_cable_detect,
  112. };
  113. static const struct ide_port_info atiixp_pci_info[] __devinitdata = {
  114. { /* 0: IXP200/300/400/700 */
  115. .name = DRV_NAME,
  116. .enablebits = {{0x48,0x01,0x00}, {0x48,0x08,0x00}},
  117. .port_ops = &atiixp_port_ops,
  118. .host_flags = IDE_HFLAG_LEGACY_IRQS,
  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 | IDE_HFLAG_LEGACY_IRQS,
  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 __devinit 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. { 0, },
  152. };
  153. MODULE_DEVICE_TABLE(pci, atiixp_pci_tbl);
  154. static struct pci_driver driver = {
  155. .name = "ATIIXP_IDE",
  156. .id_table = atiixp_pci_tbl,
  157. .probe = atiixp_init_one,
  158. .remove = ide_pci_remove,
  159. };
  160. static int __init atiixp_ide_init(void)
  161. {
  162. return ide_pci_register_driver(&driver);
  163. }
  164. static void __exit atiixp_ide_exit(void)
  165. {
  166. pci_unregister_driver(&driver);
  167. }
  168. module_init(atiixp_ide_init);
  169. module_exit(atiixp_ide_exit);
  170. MODULE_AUTHOR("HUI YU");
  171. MODULE_DESCRIPTION("PCI driver module for ATI IXP IDE");
  172. MODULE_LICENSE("GPL");