3 * Copyright (C) 2006 Red Hat <alan@redhat.com>
5 * May be copied or modified under the terms of the GNU General Public License
8 #include <linux/types.h>
9 #include <linux/module.h>
10 #include <linux/pci.h>
11 #include <linux/hdreg.h>
12 #include <linux/ide.h>
13 #include <linux/init.h>
22 * jmicron_cable_detect - cable detection
25 * Returns the cable type.
28 static u8 __devinit jmicron_cable_detect(ide_hwif_t *hwif)
30 struct pci_dev *pdev = to_pci_dev(hwif->dev);
35 int port = hwif->channel;
36 port_type port_map[2];
38 pci_read_config_dword(pdev, 0x40, &control);
40 /* There are two basic mappings. One has the two SATA ports merged
41 as master/slave and the secondary as PATA, the other has only the
43 if (control & (1 << 23)) {
44 port_map[0] = PORT_SATA;
45 port_map[1] = PORT_PATA0;
47 port_map[0] = PORT_SATA;
48 port_map[1] = PORT_SATA;
51 /* The 365/366 may have this bit set to map the second PATA port
52 as the internal primary channel */
53 pci_read_config_dword(pdev, 0x80, &control5);
54 if (control5 & (1<<24))
55 port_map[0] = PORT_PATA1;
57 /* The two ports may then be logically swapped by the firmware */
58 if (control & (1 << 22))
62 * Now we know which physical port we are talking about we can
63 * actually do our cable checking etc. Thankfully we don't need
64 * to do the plumbing for other cases.
66 switch (port_map[port]) {
68 if (control & (1 << 3)) /* 40/80 pin primary */
69 return ATA_CBL_PATA40;
70 return ATA_CBL_PATA80;
72 if (control5 & (1 << 19)) /* 40/80 pin secondary */
73 return ATA_CBL_PATA40;
74 return ATA_CBL_PATA80;
78 /* Avoid bogus "control reaches end of non-void function" */
79 return ATA_CBL_PATA80;
82 static void jmicron_set_pio_mode(ide_drive_t *drive, const u8 pio)
87 * jmicron_set_dma_mode - set host controller for DMA mode
91 * As the JMicron snoops for timings we don't need to do anything here.
94 static void jmicron_set_dma_mode(ide_drive_t *drive, const u8 mode)
98 static const struct ide_port_ops jmicron_port_ops = {
99 .set_pio_mode = jmicron_set_pio_mode,
100 .set_dma_mode = jmicron_set_dma_mode,
101 .cable_detect = jmicron_cable_detect,
104 static const struct ide_port_info jmicron_chipset __devinitdata = {
106 .enablebits = { { 0x40, 0x01, 0x01 }, { 0x40, 0x10, 0x10 } },
107 .port_ops = &jmicron_port_ops,
108 .pio_mask = ATA_PIO5,
109 .mwdma_mask = ATA_MWDMA2,
110 .udma_mask = ATA_UDMA6,
114 * jmicron_init_one - pci layer discovery entry
116 * @id: ident table entry
118 * Called by the PCI code when it finds a Jmicron controller.
119 * We then use the IDE PCI generic helper to do most of the work.
122 static int __devinit jmicron_init_one(struct pci_dev *dev, const struct pci_device_id *id)
124 return ide_setup_pci_device(dev, &jmicron_chipset);
127 /* All JMB PATA controllers have and will continue to have the same
128 * interface. Matching vendor and device class is enough for all
129 * current and future controllers if the controller is programmed
132 * If libata is configured, jmicron PCI quirk programs the controller
133 * into the correct mode. If libata isn't configured, match known
134 * device IDs too to maintain backward compatibility.
136 static struct pci_device_id jmicron_pci_tbl[] = {
137 #if !defined(CONFIG_ATA) && !defined(CONFIG_ATA_MODULE)
138 { PCI_VDEVICE(JMICRON, PCI_DEVICE_ID_JMICRON_JMB361) },
139 { PCI_VDEVICE(JMICRON, PCI_DEVICE_ID_JMICRON_JMB363) },
140 { PCI_VDEVICE(JMICRON, PCI_DEVICE_ID_JMICRON_JMB365) },
141 { PCI_VDEVICE(JMICRON, PCI_DEVICE_ID_JMICRON_JMB366) },
142 { PCI_VDEVICE(JMICRON, PCI_DEVICE_ID_JMICRON_JMB368) },
144 { PCI_VENDOR_ID_JMICRON, PCI_ANY_ID, PCI_ANY_ID, PCI_ANY_ID,
145 PCI_CLASS_STORAGE_IDE << 8, 0xffff00, 0 },
149 MODULE_DEVICE_TABLE(pci, jmicron_pci_tbl);
151 static struct pci_driver driver = {
152 .name = "JMicron IDE",
153 .id_table = jmicron_pci_tbl,
154 .probe = jmicron_init_one,
157 static int __init jmicron_ide_init(void)
159 return ide_pci_register_driver(&driver);
162 module_init(jmicron_ide_init);
164 MODULE_AUTHOR("Alan Cox");
165 MODULE_DESCRIPTION("PCI driver module for the JMicron in legacy modes");
166 MODULE_LICENSE("GPL");