jmicron.c 4.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176
  1. /*
  2. * Copyright (C) 2006 Red Hat
  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/ide.h>
  10. #include <linux/init.h>
  11. #define DRV_NAME "jmicron"
  12. typedef enum {
  13. PORT_PATA0 = 0,
  14. PORT_PATA1 = 1,
  15. PORT_SATA = 2,
  16. } port_type;
  17. /**
  18. * jmicron_cable_detect - cable detection
  19. * @hwif: IDE port
  20. *
  21. * Returns the cable type.
  22. */
  23. static u8 jmicron_cable_detect(ide_hwif_t *hwif)
  24. {
  25. struct pci_dev *pdev = to_pci_dev(hwif->dev);
  26. u32 control;
  27. u32 control5;
  28. int port = hwif->channel;
  29. port_type port_map[2];
  30. pci_read_config_dword(pdev, 0x40, &control);
  31. /* There are two basic mappings. One has the two SATA ports merged
  32. as master/slave and the secondary as PATA, the other has only the
  33. SATA port mapped */
  34. if (control & (1 << 23)) {
  35. port_map[0] = PORT_SATA;
  36. port_map[1] = PORT_PATA0;
  37. } else {
  38. port_map[0] = PORT_SATA;
  39. port_map[1] = PORT_SATA;
  40. }
  41. /* The 365/366 may have this bit set to map the second PATA port
  42. as the internal primary channel */
  43. pci_read_config_dword(pdev, 0x80, &control5);
  44. if (control5 & (1<<24))
  45. port_map[0] = PORT_PATA1;
  46. /* The two ports may then be logically swapped by the firmware */
  47. if (control & (1 << 22))
  48. port = port ^ 1;
  49. /*
  50. * Now we know which physical port we are talking about we can
  51. * actually do our cable checking etc. Thankfully we don't need
  52. * to do the plumbing for other cases.
  53. */
  54. switch (port_map[port]) {
  55. case PORT_PATA0:
  56. if (control & (1 << 3)) /* 40/80 pin primary */
  57. return ATA_CBL_PATA40;
  58. return ATA_CBL_PATA80;
  59. case PORT_PATA1:
  60. if (control5 & (1 << 19)) /* 40/80 pin secondary */
  61. return ATA_CBL_PATA40;
  62. return ATA_CBL_PATA80;
  63. case PORT_SATA:
  64. break;
  65. }
  66. /* Avoid bogus "control reaches end of non-void function" */
  67. return ATA_CBL_PATA80;
  68. }
  69. static void jmicron_set_pio_mode(ide_hwif_t *hwif, ide_drive_t *drive)
  70. {
  71. }
  72. /**
  73. * jmicron_set_dma_mode - set host controller for DMA mode
  74. * @hwif: port
  75. * @drive: drive
  76. *
  77. * As the JMicron snoops for timings we don't need to do anything here.
  78. */
  79. static void jmicron_set_dma_mode(ide_hwif_t *hwif, ide_drive_t *drive)
  80. {
  81. }
  82. static const struct ide_port_ops jmicron_port_ops = {
  83. .set_pio_mode = jmicron_set_pio_mode,
  84. .set_dma_mode = jmicron_set_dma_mode,
  85. .cable_detect = jmicron_cable_detect,
  86. };
  87. static const struct ide_port_info jmicron_chipset = {
  88. .name = DRV_NAME,
  89. .enablebits = { { 0x40, 0x01, 0x01 }, { 0x40, 0x10, 0x10 } },
  90. .port_ops = &jmicron_port_ops,
  91. .pio_mask = ATA_PIO5,
  92. .mwdma_mask = ATA_MWDMA2,
  93. .udma_mask = ATA_UDMA6,
  94. };
  95. /**
  96. * jmicron_init_one - pci layer discovery entry
  97. * @dev: PCI device
  98. * @id: ident table entry
  99. *
  100. * Called by the PCI code when it finds a Jmicron controller.
  101. * We then use the IDE PCI generic helper to do most of the work.
  102. */
  103. static int jmicron_init_one(struct pci_dev *dev, const struct pci_device_id *id)
  104. {
  105. return ide_pci_init_one(dev, &jmicron_chipset, NULL);
  106. }
  107. /* All JMB PATA controllers have and will continue to have the same
  108. * interface. Matching vendor and device class is enough for all
  109. * current and future controllers if the controller is programmed
  110. * properly.
  111. *
  112. * If libata is configured, jmicron PCI quirk programs the controller
  113. * into the correct mode. If libata isn't configured, match known
  114. * device IDs too to maintain backward compatibility.
  115. */
  116. static struct pci_device_id jmicron_pci_tbl[] = {
  117. #if !defined(CONFIG_ATA) && !defined(CONFIG_ATA_MODULE)
  118. { PCI_VDEVICE(JMICRON, PCI_DEVICE_ID_JMICRON_JMB361) },
  119. { PCI_VDEVICE(JMICRON, PCI_DEVICE_ID_JMICRON_JMB363) },
  120. { PCI_VDEVICE(JMICRON, PCI_DEVICE_ID_JMICRON_JMB365) },
  121. { PCI_VDEVICE(JMICRON, PCI_DEVICE_ID_JMICRON_JMB366) },
  122. { PCI_VDEVICE(JMICRON, PCI_DEVICE_ID_JMICRON_JMB368) },
  123. #endif
  124. { PCI_VENDOR_ID_JMICRON, PCI_ANY_ID, PCI_ANY_ID, PCI_ANY_ID,
  125. PCI_CLASS_STORAGE_IDE << 8, 0xffff00, 0 },
  126. { 0, },
  127. };
  128. MODULE_DEVICE_TABLE(pci, jmicron_pci_tbl);
  129. static struct pci_driver jmicron_pci_driver = {
  130. .name = "JMicron IDE",
  131. .id_table = jmicron_pci_tbl,
  132. .probe = jmicron_init_one,
  133. .remove = ide_pci_remove,
  134. .suspend = ide_pci_suspend,
  135. .resume = ide_pci_resume,
  136. };
  137. static int __init jmicron_ide_init(void)
  138. {
  139. return ide_pci_register_driver(&jmicron_pci_driver);
  140. }
  141. static void __exit jmicron_ide_exit(void)
  142. {
  143. pci_unregister_driver(&jmicron_pci_driver);
  144. }
  145. module_init(jmicron_ide_init);
  146. module_exit(jmicron_ide_exit);
  147. MODULE_AUTHOR("Alan Cox");
  148. MODULE_DESCRIPTION("PCI driver module for the JMicron in legacy modes");
  149. MODULE_LICENSE("GPL");