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/delay.h>
12 #include <linux/hdreg.h>
13 #include <linux/ide.h>
14 #include <linux/init.h>
25 * ata66_jmicron - Cable check
28 * Return 1 if the cable is 80pin
31 static int __devinit ata66_jmicron(ide_hwif_t *hwif)
33 struct pci_dev *pdev = hwif->pci_dev;
38 int port = hwif->channel;
39 port_type port_map[2];
41 pci_read_config_dword(pdev, 0x40, &control);
43 /* There are two basic mappings. One has the two SATA ports merged
44 as master/slave and the secondary as PATA, the other has only the
46 if (control & (1 << 23)) {
47 port_map[0] = PORT_SATA;
48 port_map[1] = PORT_PATA0;
50 port_map[0] = PORT_SATA;
51 port_map[1] = PORT_SATA;
54 /* The 365/366 may have this bit set to map the second PATA port
55 as the internal primary channel */
56 pci_read_config_dword(pdev, 0x80, &control5);
57 if (control5 & (1<<24))
58 port_map[0] = PORT_PATA1;
60 /* The two ports may then be logically swapped by the firmware */
61 if (control & (1 << 22))
65 * Now we know which physical port we are talking about we can
66 * actually do our cable checking etc. Thankfully we don't need
67 * to do the plumbing for other cases.
69 switch (port_map[port])
72 if (control & (1 << 3)) /* 40/80 pin primary */
76 if (control5 & (1 << 19)) /* 40/80 pin secondary */
82 return 1; /* Avoid bogus "control reaches end of non-void function" */
85 static void jmicron_tuneproc (ide_drive_t *drive, byte mode_wanted)
91 * config_jmicron_chipset_for_pio - set drive timings
92 * @drive: drive to tune
97 static void config_jmicron_chipset_for_pio (ide_drive_t *drive, byte set_speed)
99 u8 speed = XFER_PIO_0 + ide_get_best_pio_mode(drive, 255, 5, NULL);
101 (void) ide_config_drive_speed(drive, speed);
105 * jmicron_tune_chipset - set controller timings
106 * @drive: Drive to set up
107 * @xferspeed: speed we want to achieve
109 * As the JMicron snoops for timings all we actually need to do is
110 * make sure we don't set an invalid mode. We do need to honour
111 * the cable detect here.
114 static int jmicron_tune_chipset (ide_drive_t *drive, byte xferspeed)
116 u8 speed = ide_rate_filter(drive, xferspeed);
118 return ide_config_drive_speed(drive, speed);
122 * jmicron_configure_drive_for_dma - set up for DMA transfers
123 * @drive: drive we are going to set up
125 * As the JMicron snoops for timings all we actually need to do is
126 * make sure we don't set an invalid mode.
129 static int jmicron_config_drive_for_dma (ide_drive_t *drive)
131 if (ide_tune_dma(drive))
134 config_jmicron_chipset_for_pio(drive, 1);
140 * init_hwif_jmicron - set up hwif structs
141 * @hwif: interface to set up
143 * Minimal set up is required for the Jmicron hardware.
146 static void __devinit init_hwif_jmicron(ide_hwif_t *hwif)
148 hwif->speedproc = &jmicron_tune_chipset;
149 hwif->tuneproc = &jmicron_tuneproc;
151 hwif->drives[0].autotune = 1;
152 hwif->drives[1].autotune = 1;
158 hwif->ultra_mask = 0x7f;
159 hwif->mwdma_mask = 0x07;
161 hwif->ide_dma_check = &jmicron_config_drive_for_dma;
162 if (!(hwif->udma_four))
163 hwif->udma_four = ata66_jmicron(hwif);
166 hwif->drives[0].autodma = hwif->autodma;
167 hwif->drives[1].autodma = hwif->autodma;
174 #define DECLARE_JMB_DEV(name_str) \
177 .init_hwif = init_hwif_jmicron, \
179 .autodma = AUTODMA, \
180 .bootable = ON_BOARD, \
181 .enablebits = { {0x40, 1, 1}, {0x40, 0x10, 0x10} }, \
184 static ide_pci_device_t jmicron_chipsets[] __devinitdata = {
185 /* 0 */ DECLARE_JMB_DEV("JMB361"),
186 /* 1 */ DECLARE_JMB_DEV("JMB363"),
187 /* 2 */ DECLARE_JMB_DEV("JMB365"),
188 /* 3 */ DECLARE_JMB_DEV("JMB366"),
189 /* 4 */ DECLARE_JMB_DEV("JMB368"),
193 * jmicron_init_one - pci layer discovery entry
195 * @id: ident table entry
197 * Called by the PCI code when it finds a Jmicron controller.
198 * We then use the IDE PCI generic helper to do most of the work.
201 static int __devinit jmicron_init_one(struct pci_dev *dev, const struct pci_device_id *id)
203 ide_setup_pci_device(dev, &jmicron_chipsets[id->driver_data]);
207 /* If libata is configured, jmicron PCI quirk will configure it such
208 * that the SATA ports are in AHCI function while the PATA ports are
209 * in a separate IDE function. In such cases, match device class and
210 * attach only to IDE. If libata isn't configured, keep the old
211 * behavior for backward compatibility.
213 #if defined(CONFIG_ATA) || defined(CONFIG_ATA_MODULE)
214 #define JMB_CLASS PCI_CLASS_STORAGE_IDE << 8
215 #define JMB_CLASS_MASK 0xffff00
218 #define JMB_CLASS_MASK 0
221 static struct pci_device_id jmicron_pci_tbl[] = {
222 { PCI_VENDOR_ID_JMICRON, PCI_DEVICE_ID_JMICRON_JMB361,
223 PCI_ANY_ID, PCI_ANY_ID, JMB_CLASS, JMB_CLASS_MASK, 0},
224 { PCI_VENDOR_ID_JMICRON, PCI_DEVICE_ID_JMICRON_JMB363,
225 PCI_ANY_ID, PCI_ANY_ID, JMB_CLASS, JMB_CLASS_MASK, 1},
226 { PCI_VENDOR_ID_JMICRON, PCI_DEVICE_ID_JMICRON_JMB365,
227 PCI_ANY_ID, PCI_ANY_ID, JMB_CLASS, JMB_CLASS_MASK, 2},
228 { PCI_VENDOR_ID_JMICRON, PCI_DEVICE_ID_JMICRON_JMB366,
229 PCI_ANY_ID, PCI_ANY_ID, JMB_CLASS, JMB_CLASS_MASK, 3},
230 { PCI_VENDOR_ID_JMICRON, PCI_DEVICE_ID_JMICRON_JMB368,
231 PCI_ANY_ID, PCI_ANY_ID, JMB_CLASS, JMB_CLASS_MASK, 4},
235 MODULE_DEVICE_TABLE(pci, jmicron_pci_tbl);
237 static struct pci_driver driver = {
238 .name = "JMicron IDE",
239 .id_table = jmicron_pci_tbl,
240 .probe = jmicron_init_one,
243 static int __init jmicron_ide_init(void)
245 return ide_pci_register_driver(&driver);
248 module_init(jmicron_ide_init);
250 MODULE_AUTHOR("Alan Cox");
251 MODULE_DESCRIPTION("PCI driver module for the JMicron in legacy modes");
252 MODULE_LICENSE("GPL");