atiixp.c 6.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252
  1. /*
  2. * linux/drivers/ide/pci/atiixp.c Version 0.03 Aug 3 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 int save_mdma_mode[4];
  40. static DEFINE_SPINLOCK(atiixp_lock);
  41. static void atiixp_dma_host_on(ide_drive_t *drive)
  42. {
  43. struct pci_dev *dev = drive->hwif->pci_dev;
  44. unsigned long flags;
  45. u16 tmp16;
  46. spin_lock_irqsave(&atiixp_lock, flags);
  47. pci_read_config_word(dev, ATIIXP_IDE_UDMA_CONTROL, &tmp16);
  48. if (save_mdma_mode[drive->dn])
  49. tmp16 &= ~(1 << drive->dn);
  50. else
  51. tmp16 |= (1 << drive->dn);
  52. pci_write_config_word(dev, ATIIXP_IDE_UDMA_CONTROL, tmp16);
  53. spin_unlock_irqrestore(&atiixp_lock, flags);
  54. ide_dma_host_on(drive);
  55. }
  56. static void atiixp_dma_host_off(ide_drive_t *drive)
  57. {
  58. struct pci_dev *dev = drive->hwif->pci_dev;
  59. unsigned long flags;
  60. u16 tmp16;
  61. spin_lock_irqsave(&atiixp_lock, flags);
  62. pci_read_config_word(dev, ATIIXP_IDE_UDMA_CONTROL, &tmp16);
  63. tmp16 &= ~(1 << drive->dn);
  64. pci_write_config_word(dev, ATIIXP_IDE_UDMA_CONTROL, tmp16);
  65. spin_unlock_irqrestore(&atiixp_lock, flags);
  66. ide_dma_host_off(drive);
  67. }
  68. /**
  69. * atiixp_set_pio_mode - set host controller for PIO mode
  70. * @drive: drive
  71. * @pio: PIO mode number
  72. *
  73. * Set the interface PIO mode.
  74. */
  75. static void atiixp_set_pio_mode(ide_drive_t *drive, const u8 pio)
  76. {
  77. struct pci_dev *dev = drive->hwif->pci_dev;
  78. unsigned long flags;
  79. int timing_shift = (drive->dn & 2) ? 16 : 0 + (drive->dn & 1) ? 0 : 8;
  80. u32 pio_timing_data;
  81. u16 pio_mode_data;
  82. spin_lock_irqsave(&atiixp_lock, flags);
  83. pci_read_config_word(dev, ATIIXP_IDE_PIO_MODE, &pio_mode_data);
  84. pio_mode_data &= ~(0x07 << (drive->dn * 4));
  85. pio_mode_data |= (pio << (drive->dn * 4));
  86. pci_write_config_word(dev, ATIIXP_IDE_PIO_MODE, pio_mode_data);
  87. pci_read_config_dword(dev, ATIIXP_IDE_PIO_TIMING, &pio_timing_data);
  88. pio_timing_data &= ~(0xff << timing_shift);
  89. pio_timing_data |= (pio_timing[pio].recover_width << timing_shift) |
  90. (pio_timing[pio].command_width << (timing_shift + 4));
  91. pci_write_config_dword(dev, ATIIXP_IDE_PIO_TIMING, pio_timing_data);
  92. spin_unlock_irqrestore(&atiixp_lock, flags);
  93. }
  94. /**
  95. * atiixp_set_dma_mode - set host controller for DMA mode
  96. * @drive: drive
  97. * @speed: DMA mode
  98. *
  99. * Set a ATIIXP host controller to the desired DMA mode. This involves
  100. * programming the right timing data into the PCI configuration space.
  101. */
  102. static void atiixp_set_dma_mode(ide_drive_t *drive, const u8 speed)
  103. {
  104. struct pci_dev *dev = drive->hwif->pci_dev;
  105. unsigned long flags;
  106. int timing_shift = (drive->dn & 2) ? 16 : 0 + (drive->dn & 1) ? 0 : 8;
  107. u32 tmp32;
  108. u16 tmp16;
  109. if (speed < XFER_MW_DMA_0)
  110. return;
  111. spin_lock_irqsave(&atiixp_lock, flags);
  112. save_mdma_mode[drive->dn] = 0;
  113. if (speed >= XFER_UDMA_0) {
  114. pci_read_config_word(dev, ATIIXP_IDE_UDMA_MODE, &tmp16);
  115. tmp16 &= ~(0x07 << (drive->dn * 4));
  116. tmp16 |= ((speed & 0x07) << (drive->dn * 4));
  117. pci_write_config_word(dev, ATIIXP_IDE_UDMA_MODE, tmp16);
  118. } else {
  119. if ((speed >= XFER_MW_DMA_0) && (speed <= XFER_MW_DMA_2)) {
  120. save_mdma_mode[drive->dn] = speed;
  121. pci_read_config_dword(dev, ATIIXP_IDE_MDMA_TIMING, &tmp32);
  122. tmp32 &= ~(0xff << timing_shift);
  123. tmp32 |= (mdma_timing[speed & 0x03].recover_width << timing_shift) |
  124. (mdma_timing[speed & 0x03].command_width << (timing_shift + 4));
  125. pci_write_config_dword(dev, ATIIXP_IDE_MDMA_TIMING, tmp32);
  126. }
  127. }
  128. spin_unlock_irqrestore(&atiixp_lock, flags);
  129. }
  130. /**
  131. * init_hwif_atiixp - fill in the hwif for the ATIIXP
  132. * @hwif: IDE interface
  133. *
  134. * Set up the ide_hwif_t for the ATIIXP interface according to the
  135. * capabilities of the hardware.
  136. */
  137. static void __devinit init_hwif_atiixp(ide_hwif_t *hwif)
  138. {
  139. u8 udma_mode = 0;
  140. u8 ch = hwif->channel;
  141. struct pci_dev *pdev = hwif->pci_dev;
  142. hwif->set_pio_mode = &atiixp_set_pio_mode;
  143. hwif->set_dma_mode = &atiixp_set_dma_mode;
  144. if (!hwif->dma_base)
  145. return;
  146. pci_read_config_byte(pdev, ATIIXP_IDE_UDMA_MODE + ch, &udma_mode);
  147. if ((udma_mode & 0x07) >= 0x04 || (udma_mode & 0x70) >= 0x40)
  148. hwif->cbl = ATA_CBL_PATA80;
  149. else
  150. hwif->cbl = ATA_CBL_PATA40;
  151. hwif->dma_host_on = &atiixp_dma_host_on;
  152. hwif->dma_host_off = &atiixp_dma_host_off;
  153. }
  154. static const struct ide_port_info atiixp_pci_info[] __devinitdata = {
  155. { /* 0 */
  156. .name = "ATIIXP",
  157. .init_hwif = init_hwif_atiixp,
  158. .enablebits = {{0x48,0x01,0x00}, {0x48,0x08,0x00}},
  159. .host_flags = IDE_HFLAG_LEGACY_IRQS | IDE_HFLAG_BOOTABLE,
  160. .pio_mask = ATA_PIO4,
  161. .mwdma_mask = ATA_MWDMA2,
  162. .udma_mask = ATA_UDMA5,
  163. },{ /* 1 */
  164. .name = "SB600_PATA",
  165. .init_hwif = init_hwif_atiixp,
  166. .enablebits = {{0x48,0x01,0x00}, {0x00,0x00,0x00}},
  167. .host_flags = IDE_HFLAG_SINGLE | IDE_HFLAG_LEGACY_IRQS |
  168. IDE_HFLAG_BOOTABLE,
  169. .pio_mask = ATA_PIO4,
  170. .mwdma_mask = ATA_MWDMA2,
  171. .udma_mask = ATA_UDMA5,
  172. },
  173. };
  174. /**
  175. * atiixp_init_one - called when a ATIIXP is found
  176. * @dev: the atiixp device
  177. * @id: the matching pci id
  178. *
  179. * Called when the PCI registration layer (or the IDE initialization)
  180. * finds a device matching our IDE device tables.
  181. */
  182. static int __devinit atiixp_init_one(struct pci_dev *dev, const struct pci_device_id *id)
  183. {
  184. return ide_setup_pci_device(dev, &atiixp_pci_info[id->driver_data]);
  185. }
  186. static const struct pci_device_id atiixp_pci_tbl[] = {
  187. { PCI_VDEVICE(ATI, PCI_DEVICE_ID_ATI_IXP200_IDE), 0 },
  188. { PCI_VDEVICE(ATI, PCI_DEVICE_ID_ATI_IXP300_IDE), 0 },
  189. { PCI_VDEVICE(ATI, PCI_DEVICE_ID_ATI_IXP400_IDE), 0 },
  190. { PCI_VDEVICE(ATI, PCI_DEVICE_ID_ATI_IXP600_IDE), 1 },
  191. { PCI_VDEVICE(ATI, PCI_DEVICE_ID_ATI_IXP700_IDE), 0 },
  192. { 0, },
  193. };
  194. MODULE_DEVICE_TABLE(pci, atiixp_pci_tbl);
  195. static struct pci_driver driver = {
  196. .name = "ATIIXP_IDE",
  197. .id_table = atiixp_pci_tbl,
  198. .probe = atiixp_init_one,
  199. };
  200. static int __init atiixp_ide_init(void)
  201. {
  202. return ide_pci_register_driver(&driver);
  203. }
  204. module_init(atiixp_ide_init);
  205. MODULE_AUTHOR("HUI YU");
  206. MODULE_DESCRIPTION("PCI driver module for ATI IXP IDE");
  207. MODULE_LICENSE("GPL");