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/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. /**
  101. * init_hwif_atiixp - fill in the hwif for the ATIIXP
  102. * @hwif: IDE interface
  103. *
  104. * Set up the ide_hwif_t for the ATIIXP interface according to the
  105. * capabilities of the hardware.
  106. */
  107. static void __devinit init_hwif_atiixp(ide_hwif_t *hwif)
  108. {
  109. struct pci_dev *pdev = to_pci_dev(hwif->dev);
  110. u8 udma_mode = 0, ch = hwif->channel;
  111. hwif->set_pio_mode = &atiixp_set_pio_mode;
  112. hwif->set_dma_mode = &atiixp_set_dma_mode;
  113. if (!hwif->dma_base)
  114. return;
  115. pci_read_config_byte(pdev, ATIIXP_IDE_UDMA_MODE + ch, &udma_mode);
  116. if ((udma_mode & 0x07) >= 0x04 || (udma_mode & 0x70) >= 0x40)
  117. hwif->cbl = ATA_CBL_PATA80;
  118. else
  119. hwif->cbl = ATA_CBL_PATA40;
  120. }
  121. static const struct ide_port_info atiixp_pci_info[] __devinitdata = {
  122. { /* 0 */
  123. .name = "ATIIXP",
  124. .init_hwif = init_hwif_atiixp,
  125. .enablebits = {{0x48,0x01,0x00}, {0x48,0x08,0x00}},
  126. .host_flags = IDE_HFLAG_LEGACY_IRQS | IDE_HFLAG_BOOTABLE,
  127. .pio_mask = ATA_PIO4,
  128. .mwdma_mask = ATA_MWDMA2,
  129. .udma_mask = ATA_UDMA5,
  130. },{ /* 1 */
  131. .name = "SB600_PATA",
  132. .init_hwif = init_hwif_atiixp,
  133. .enablebits = {{0x48,0x01,0x00}, {0x00,0x00,0x00}},
  134. .host_flags = IDE_HFLAG_SINGLE | IDE_HFLAG_LEGACY_IRQS |
  135. IDE_HFLAG_BOOTABLE,
  136. .pio_mask = ATA_PIO4,
  137. .mwdma_mask = ATA_MWDMA2,
  138. .udma_mask = ATA_UDMA5,
  139. },
  140. };
  141. /**
  142. * atiixp_init_one - called when a ATIIXP is found
  143. * @dev: the atiixp device
  144. * @id: the matching pci id
  145. *
  146. * Called when the PCI registration layer (or the IDE initialization)
  147. * finds a device matching our IDE device tables.
  148. */
  149. static int __devinit atiixp_init_one(struct pci_dev *dev, const struct pci_device_id *id)
  150. {
  151. return ide_setup_pci_device(dev, &atiixp_pci_info[id->driver_data]);
  152. }
  153. static const struct pci_device_id atiixp_pci_tbl[] = {
  154. { PCI_VDEVICE(ATI, PCI_DEVICE_ID_ATI_IXP200_IDE), 0 },
  155. { PCI_VDEVICE(ATI, PCI_DEVICE_ID_ATI_IXP300_IDE), 0 },
  156. { PCI_VDEVICE(ATI, PCI_DEVICE_ID_ATI_IXP400_IDE), 0 },
  157. { PCI_VDEVICE(ATI, PCI_DEVICE_ID_ATI_IXP600_IDE), 1 },
  158. { PCI_VDEVICE(ATI, PCI_DEVICE_ID_ATI_IXP700_IDE), 0 },
  159. { 0, },
  160. };
  161. MODULE_DEVICE_TABLE(pci, atiixp_pci_tbl);
  162. static struct pci_driver driver = {
  163. .name = "ATIIXP_IDE",
  164. .id_table = atiixp_pci_tbl,
  165. .probe = atiixp_init_one,
  166. };
  167. static int __init atiixp_ide_init(void)
  168. {
  169. return ide_pci_register_driver(&driver);
  170. }
  171. module_init(atiixp_ide_init);
  172. MODULE_AUTHOR("HUI YU");
  173. MODULE_DESCRIPTION("PCI driver module for ATI IXP IDE");
  174. MODULE_LICENSE("GPL");