atiixp.c 5.6 KB

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