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 * Returns the cable type.
31 static u8 __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 */
73 return ATA_CBL_PATA40
;
74 return ATA_CBL_PATA80
;
76 if (control5
& (1 << 19)) /* 40/80 pin secondary */
77 return ATA_CBL_PATA40
;
78 return ATA_CBL_PATA80
;
82 /* Avoid bogus "control reaches end of non-void function" */
83 return ATA_CBL_PATA80
;
86 static void jmicron_set_pio_mode(ide_drive_t
*drive
, const u8 pio
)
91 * jmicron_set_dma_mode - set host controller for DMA mode
95 * As the JMicron snoops for timings we don't need to do anything here.
98 static void jmicron_set_dma_mode(ide_drive_t
*drive
, const u8 mode
)
103 * jmicron_configure_drive_for_dma - set up for DMA transfers
104 * @drive: drive we are going to set up
106 * As the JMicron snoops for timings all we actually need to do is
107 * make sure we don't set an invalid mode.
110 static int jmicron_config_drive_for_dma (ide_drive_t
*drive
)
112 if (ide_tune_dma(drive
))
115 ide_set_max_pio(drive
);
121 * init_hwif_jmicron - set up hwif structs
122 * @hwif: interface to set up
124 * Minimal set up is required for the Jmicron hardware.
127 static void __devinit
init_hwif_jmicron(ide_hwif_t
*hwif
)
129 hwif
->set_pio_mode
= &jmicron_set_pio_mode
;
130 hwif
->set_dma_mode
= &jmicron_set_dma_mode
;
132 hwif
->drives
[0].autotune
= 1;
133 hwif
->drives
[1].autotune
= 1;
139 hwif
->ultra_mask
= 0x7f;
140 hwif
->mwdma_mask
= 0x07;
142 hwif
->ide_dma_check
= &jmicron_config_drive_for_dma
;
144 if (hwif
->cbl
!= ATA_CBL_PATA40_SHORT
)
145 hwif
->cbl
= ata66_jmicron(hwif
);
148 hwif
->drives
[0].autodma
= hwif
->autodma
;
149 hwif
->drives
[1].autodma
= hwif
->autodma
;
156 static ide_pci_device_t jmicron_chipset __devinitdata
= {
158 .init_hwif
= init_hwif_jmicron
,
160 .bootable
= ON_BOARD
,
161 .enablebits
= { { 0x40, 0x01, 0x01 }, { 0x40, 0x10, 0x10 } },
162 .pio_mask
= ATA_PIO5
,
166 * jmicron_init_one - pci layer discovery entry
168 * @id: ident table entry
170 * Called by the PCI code when it finds a Jmicron controller.
171 * We then use the IDE PCI generic helper to do most of the work.
174 static int __devinit
jmicron_init_one(struct pci_dev
*dev
, const struct pci_device_id
*id
)
176 ide_setup_pci_device(dev
, &jmicron_chipset
);
180 /* All JMB PATA controllers have and will continue to have the same
181 * interface. Matching vendor and device class is enough for all
182 * current and future controllers if the controller is programmed
185 * If libata is configured, jmicron PCI quirk programs the controller
186 * into the correct mode. If libata isn't configured, match known
187 * device IDs too to maintain backward compatibility.
189 static struct pci_device_id jmicron_pci_tbl
[] = {
190 #if !defined(CONFIG_ATA) && !defined(CONFIG_ATA_MODULE)
191 { PCI_VDEVICE(JMICRON
, PCI_DEVICE_ID_JMICRON_JMB361
) },
192 { PCI_VDEVICE(JMICRON
, PCI_DEVICE_ID_JMICRON_JMB363
) },
193 { PCI_VDEVICE(JMICRON
, PCI_DEVICE_ID_JMICRON_JMB365
) },
194 { PCI_VDEVICE(JMICRON
, PCI_DEVICE_ID_JMICRON_JMB366
) },
195 { PCI_VDEVICE(JMICRON
, PCI_DEVICE_ID_JMICRON_JMB368
) },
197 { PCI_VENDOR_ID_JMICRON
, PCI_ANY_ID
, PCI_ANY_ID
, PCI_ANY_ID
,
198 PCI_CLASS_STORAGE_IDE
<< 8, 0xffff00, 0 },
202 MODULE_DEVICE_TABLE(pci
, jmicron_pci_tbl
);
204 static struct pci_driver driver
= {
205 .name
= "JMicron IDE",
206 .id_table
= jmicron_pci_tbl
,
207 .probe
= jmicron_init_one
,
210 static int __init
jmicron_ide_init(void)
212 return ide_pci_register_driver(&driver
);
215 module_init(jmicron_ide_init
);
217 MODULE_AUTHOR("Alan Cox");
218 MODULE_DESCRIPTION("PCI driver module for the JMicron in legacy modes");
219 MODULE_LICENSE("GPL");