atiixp.c 5.7 KB

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