jmicron.c 5.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223
  1. /*
  2. * Copyright (C) 2006 Red Hat <alan@redhat.com>
  3. *
  4. * May be copied or modified under the terms of the GNU General Public License
  5. */
  6. #include <linux/types.h>
  7. #include <linux/module.h>
  8. #include <linux/pci.h>
  9. #include <linux/delay.h>
  10. #include <linux/hdreg.h>
  11. #include <linux/ide.h>
  12. #include <linux/init.h>
  13. #include <asm/io.h>
  14. typedef enum {
  15. PORT_PATA0 = 0,
  16. PORT_PATA1 = 1,
  17. PORT_SATA = 2,
  18. } port_type;
  19. /**
  20. * ata66_jmicron - Cable check
  21. * @hwif: IDE port
  22. *
  23. * Returns the cable type.
  24. */
  25. static u8 __devinit ata66_jmicron(ide_hwif_t *hwif)
  26. {
  27. struct pci_dev *pdev = hwif->pci_dev;
  28. u32 control;
  29. u32 control5;
  30. int port = hwif->channel;
  31. port_type port_map[2];
  32. pci_read_config_dword(pdev, 0x40, &control);
  33. /* There are two basic mappings. One has the two SATA ports merged
  34. as master/slave and the secondary as PATA, the other has only the
  35. SATA port mapped */
  36. if (control & (1 << 23)) {
  37. port_map[0] = PORT_SATA;
  38. port_map[1] = PORT_PATA0;
  39. } else {
  40. port_map[0] = PORT_SATA;
  41. port_map[1] = PORT_SATA;
  42. }
  43. /* The 365/366 may have this bit set to map the second PATA port
  44. as the internal primary channel */
  45. pci_read_config_dword(pdev, 0x80, &control5);
  46. if (control5 & (1<<24))
  47. port_map[0] = PORT_PATA1;
  48. /* The two ports may then be logically swapped by the firmware */
  49. if (control & (1 << 22))
  50. port = port ^ 1;
  51. /*
  52. * Now we know which physical port we are talking about we can
  53. * actually do our cable checking etc. Thankfully we don't need
  54. * to do the plumbing for other cases.
  55. */
  56. switch (port_map[port])
  57. {
  58. case PORT_PATA0:
  59. if (control & (1 << 3)) /* 40/80 pin primary */
  60. return ATA_CBL_PATA40;
  61. return ATA_CBL_PATA80;
  62. case PORT_PATA1:
  63. if (control5 & (1 << 19)) /* 40/80 pin secondary */
  64. return ATA_CBL_PATA40;
  65. return ATA_CBL_PATA80;
  66. case PORT_SATA:
  67. break;
  68. }
  69. /* Avoid bogus "control reaches end of non-void function" */
  70. return ATA_CBL_PATA80;
  71. }
  72. static void jmicron_tuneproc(ide_drive_t *drive, u8 pio)
  73. {
  74. pio = ide_get_best_pio_mode(drive, pio, 5);
  75. ide_config_drive_speed(drive, XFER_PIO_0 + pio);
  76. }
  77. /**
  78. * jmicron_tune_chipset - set controller timings
  79. * @drive: Drive to set up
  80. * @speed: speed we want to achieve
  81. *
  82. * As the JMicron snoops for timings all we actually need to do is
  83. * set the transfer mode on the device.
  84. */
  85. static int jmicron_tune_chipset(ide_drive_t *drive, const u8 speed)
  86. {
  87. return ide_config_drive_speed(drive, speed);
  88. }
  89. /**
  90. * jmicron_configure_drive_for_dma - set up for DMA transfers
  91. * @drive: drive we are going to set up
  92. *
  93. * As the JMicron snoops for timings all we actually need to do is
  94. * make sure we don't set an invalid mode.
  95. */
  96. static int jmicron_config_drive_for_dma (ide_drive_t *drive)
  97. {
  98. if (ide_tune_dma(drive))
  99. return 0;
  100. jmicron_tuneproc(drive, 255);
  101. return -1;
  102. }
  103. /**
  104. * init_hwif_jmicron - set up hwif structs
  105. * @hwif: interface to set up
  106. *
  107. * Minimal set up is required for the Jmicron hardware.
  108. */
  109. static void __devinit init_hwif_jmicron(ide_hwif_t *hwif)
  110. {
  111. hwif->speedproc = &jmicron_tune_chipset;
  112. hwif->tuneproc = &jmicron_tuneproc;
  113. hwif->drives[0].autotune = 1;
  114. hwif->drives[1].autotune = 1;
  115. if (!hwif->dma_base)
  116. goto fallback;
  117. hwif->atapi_dma = 1;
  118. hwif->ultra_mask = 0x7f;
  119. hwif->mwdma_mask = 0x07;
  120. hwif->ide_dma_check = &jmicron_config_drive_for_dma;
  121. if (hwif->cbl != ATA_CBL_PATA40_SHORT)
  122. hwif->cbl = ata66_jmicron(hwif);
  123. hwif->autodma = 1;
  124. hwif->drives[0].autodma = hwif->autodma;
  125. hwif->drives[1].autodma = hwif->autodma;
  126. return;
  127. fallback:
  128. hwif->autodma = 0;
  129. return;
  130. }
  131. static ide_pci_device_t jmicron_chipset __devinitdata = {
  132. .name = "JMB",
  133. .init_hwif = init_hwif_jmicron,
  134. .autodma = AUTODMA,
  135. .bootable = ON_BOARD,
  136. .enablebits = { { 0x40, 0x01, 0x01 }, { 0x40, 0x10, 0x10 } },
  137. .pio_mask = ATA_PIO5,
  138. };
  139. /**
  140. * jmicron_init_one - pci layer discovery entry
  141. * @dev: PCI device
  142. * @id: ident table entry
  143. *
  144. * Called by the PCI code when it finds a Jmicron controller.
  145. * We then use the IDE PCI generic helper to do most of the work.
  146. */
  147. static int __devinit jmicron_init_one(struct pci_dev *dev, const struct pci_device_id *id)
  148. {
  149. ide_setup_pci_device(dev, &jmicron_chipset);
  150. return 0;
  151. }
  152. /* All JMB PATA controllers have and will continue to have the same
  153. * interface. Matching vendor and device class is enough for all
  154. * current and future controllers if the controller is programmed
  155. * properly.
  156. *
  157. * If libata is configured, jmicron PCI quirk programs the controller
  158. * into the correct mode. If libata isn't configured, match known
  159. * device IDs too to maintain backward compatibility.
  160. */
  161. static struct pci_device_id jmicron_pci_tbl[] = {
  162. #if !defined(CONFIG_ATA) && !defined(CONFIG_ATA_MODULE)
  163. { PCI_VDEVICE(JMICRON, PCI_DEVICE_ID_JMICRON_JMB361) },
  164. { PCI_VDEVICE(JMICRON, PCI_DEVICE_ID_JMICRON_JMB363) },
  165. { PCI_VDEVICE(JMICRON, PCI_DEVICE_ID_JMICRON_JMB365) },
  166. { PCI_VDEVICE(JMICRON, PCI_DEVICE_ID_JMICRON_JMB366) },
  167. { PCI_VDEVICE(JMICRON, PCI_DEVICE_ID_JMICRON_JMB368) },
  168. #endif
  169. { PCI_VENDOR_ID_JMICRON, PCI_ANY_ID, PCI_ANY_ID, PCI_ANY_ID,
  170. PCI_CLASS_STORAGE_IDE << 8, 0xffff00, 0 },
  171. { 0, },
  172. };
  173. MODULE_DEVICE_TABLE(pci, jmicron_pci_tbl);
  174. static struct pci_driver driver = {
  175. .name = "JMicron IDE",
  176. .id_table = jmicron_pci_tbl,
  177. .probe = jmicron_init_one,
  178. };
  179. static int __init jmicron_ide_init(void)
  180. {
  181. return ide_pci_register_driver(&driver);
  182. }
  183. module_init(jmicron_ide_init);
  184. MODULE_AUTHOR("Alan Cox");
  185. MODULE_DESCRIPTION("PCI driver module for the JMicron in legacy modes");
  186. MODULE_LICENSE("GPL");