Commit | Line | Data |
---|---|---|
bbb3bbdb AC |
1 | |
2 | /* | |
3 | * Copyright (C) 2006 Red Hat <alan@redhat.com> | |
4 | * | |
5 | * May be copied or modified under the terms of the GNU General Public License | |
6 | */ | |
7 | ||
bbb3bbdb AC |
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> | |
15 | ||
16 | #include <asm/io.h> | |
17 | ||
18 | typedef enum { | |
19 | PORT_PATA0 = 0, | |
20 | PORT_PATA1 = 1, | |
21 | PORT_SATA = 2, | |
22 | } port_type; | |
23 | ||
bbb3bbdb AC |
24 | /** |
25 | * ata66_jmicron - Cable check | |
26 | * @hwif: IDE port | |
27 | * | |
49521f97 | 28 | * Returns the cable type. |
bbb3bbdb AC |
29 | */ |
30 | ||
49521f97 | 31 | static u8 __devinit ata66_jmicron(ide_hwif_t *hwif) |
bbb3bbdb AC |
32 | { |
33 | struct pci_dev *pdev = hwif->pci_dev; | |
34 | ||
35 | u32 control; | |
36 | u32 control5; | |
37 | ||
38 | int port = hwif->channel; | |
39 | port_type port_map[2]; | |
40 | ||
41 | pci_read_config_dword(pdev, 0x40, &control); | |
42 | ||
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 | |
45 | SATA port mapped */ | |
46 | if (control & (1 << 23)) { | |
47 | port_map[0] = PORT_SATA; | |
48 | port_map[1] = PORT_PATA0; | |
49 | } else { | |
50 | port_map[0] = PORT_SATA; | |
51 | port_map[1] = PORT_SATA; | |
52 | } | |
53 | ||
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; | |
59 | ||
60 | /* The two ports may then be logically swapped by the firmware */ | |
61 | if (control & (1 << 22)) | |
62 | port = port ^ 1; | |
63 | ||
64 | /* | |
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. | |
68 | */ | |
69 | switch (port_map[port]) | |
70 | { | |
71 | case PORT_PATA0: | |
72 | if (control & (1 << 3)) /* 40/80 pin primary */ | |
49521f97 BZ |
73 | return ATA_CBL_PATA40; |
74 | return ATA_CBL_PATA80; | |
bbb3bbdb AC |
75 | case PORT_PATA1: |
76 | if (control5 & (1 << 19)) /* 40/80 pin secondary */ | |
49521f97 BZ |
77 | return ATA_CBL_PATA40; |
78 | return ATA_CBL_PATA80; | |
bbb3bbdb | 79 | case PORT_SATA: |
a51545ab | 80 | break; |
bbb3bbdb | 81 | } |
49521f97 BZ |
82 | /* Avoid bogus "control reaches end of non-void function" */ |
83 | return ATA_CBL_PATA80; | |
bbb3bbdb AC |
84 | } |
85 | ||
8b6b33be | 86 | static void jmicron_tuneproc(ide_drive_t *drive, u8 pio) |
bbb3bbdb | 87 | { |
8b6b33be BZ |
88 | pio = ide_get_best_pio_mode(drive, pio, 5); |
89 | ide_config_drive_speed(drive, XFER_PIO_0 + pio); | |
bbb3bbdb AC |
90 | } |
91 | ||
92 | /** | |
93 | * jmicron_tune_chipset - set controller timings | |
94 | * @drive: Drive to set up | |
95 | * @xferspeed: speed we want to achieve | |
96 | * | |
97 | * As the JMicron snoops for timings all we actually need to do is | |
98 | * make sure we don't set an invalid mode. We do need to honour | |
99 | * the cable detect here. | |
100 | */ | |
101 | ||
102 | static int jmicron_tune_chipset (ide_drive_t *drive, byte xferspeed) | |
103 | { | |
2d5eaa6d | 104 | u8 speed = ide_rate_filter(drive, xferspeed); |
bbb3bbdb AC |
105 | |
106 | return ide_config_drive_speed(drive, speed); | |
107 | } | |
108 | ||
bbb3bbdb AC |
109 | /** |
110 | * jmicron_configure_drive_for_dma - set up for DMA transfers | |
111 | * @drive: drive we are going to set up | |
112 | * | |
113 | * As the JMicron snoops for timings all we actually need to do is | |
114 | * make sure we don't set an invalid mode. | |
115 | */ | |
116 | ||
117 | static int jmicron_config_drive_for_dma (ide_drive_t *drive) | |
118 | { | |
29e744d0 | 119 | if (ide_tune_dma(drive)) |
3608b5d7 | 120 | return 0; |
bbb3bbdb | 121 | |
8b6b33be | 122 | jmicron_tuneproc(drive, 255); |
3608b5d7 BZ |
123 | |
124 | return -1; | |
bbb3bbdb AC |
125 | } |
126 | ||
127 | /** | |
128 | * init_hwif_jmicron - set up hwif structs | |
129 | * @hwif: interface to set up | |
130 | * | |
131 | * Minimal set up is required for the Jmicron hardware. | |
132 | */ | |
133 | ||
134 | static void __devinit init_hwif_jmicron(ide_hwif_t *hwif) | |
135 | { | |
136 | hwif->speedproc = &jmicron_tune_chipset; | |
137 | hwif->tuneproc = &jmicron_tuneproc; | |
138 | ||
139 | hwif->drives[0].autotune = 1; | |
140 | hwif->drives[1].autotune = 1; | |
141 | ||
142 | if (!hwif->dma_base) | |
143 | goto fallback; | |
144 | ||
145 | hwif->atapi_dma = 1; | |
146 | hwif->ultra_mask = 0x7f; | |
147 | hwif->mwdma_mask = 0x07; | |
148 | ||
149 | hwif->ide_dma_check = &jmicron_config_drive_for_dma; | |
49521f97 BZ |
150 | |
151 | if (hwif->cbl != ATA_CBL_PATA40_SHORT) | |
152 | hwif->cbl = ata66_jmicron(hwif); | |
bbb3bbdb AC |
153 | |
154 | hwif->autodma = 1; | |
155 | hwif->drives[0].autodma = hwif->autodma; | |
156 | hwif->drives[1].autodma = hwif->autodma; | |
157 | return; | |
158 | fallback: | |
159 | hwif->autodma = 0; | |
160 | return; | |
161 | } | |
162 | ||
163 | #define DECLARE_JMB_DEV(name_str) \ | |
164 | { \ | |
165 | .name = name_str, \ | |
166 | .init_hwif = init_hwif_jmicron, \ | |
bbb3bbdb AC |
167 | .autodma = AUTODMA, \ |
168 | .bootable = ON_BOARD, \ | |
169 | .enablebits = { {0x40, 1, 1}, {0x40, 0x10, 0x10} }, \ | |
4099d143 | 170 | .pio_mask = ATA_PIO5, \ |
bbb3bbdb AC |
171 | } |
172 | ||
173 | static ide_pci_device_t jmicron_chipsets[] __devinitdata = { | |
174 | /* 0 */ DECLARE_JMB_DEV("JMB361"), | |
175 | /* 1 */ DECLARE_JMB_DEV("JMB363"), | |
176 | /* 2 */ DECLARE_JMB_DEV("JMB365"), | |
177 | /* 3 */ DECLARE_JMB_DEV("JMB366"), | |
178 | /* 4 */ DECLARE_JMB_DEV("JMB368"), | |
179 | }; | |
180 | ||
181 | /** | |
182 | * jmicron_init_one - pci layer discovery entry | |
183 | * @dev: PCI device | |
184 | * @id: ident table entry | |
185 | * | |
186 | * Called by the PCI code when it finds a Jmicron controller. | |
187 | * We then use the IDE PCI generic helper to do most of the work. | |
188 | */ | |
189 | ||
190 | static int __devinit jmicron_init_one(struct pci_dev *dev, const struct pci_device_id *id) | |
191 | { | |
192 | ide_setup_pci_device(dev, &jmicron_chipsets[id->driver_data]); | |
193 | return 0; | |
194 | } | |
195 | ||
ebbc2031 TH |
196 | /* If libata is configured, jmicron PCI quirk will configure it such |
197 | * that the SATA ports are in AHCI function while the PATA ports are | |
198 | * in a separate IDE function. In such cases, match device class and | |
199 | * attach only to IDE. If libata isn't configured, keep the old | |
200 | * behavior for backward compatibility. | |
201 | */ | |
202 | #if defined(CONFIG_ATA) || defined(CONFIG_ATA_MODULE) | |
203 | #define JMB_CLASS PCI_CLASS_STORAGE_IDE << 8 | |
204 | #define JMB_CLASS_MASK 0xffff00 | |
205 | #else | |
206 | #define JMB_CLASS 0 | |
207 | #define JMB_CLASS_MASK 0 | |
208 | #endif | |
209 | ||
bbb3bbdb | 210 | static struct pci_device_id jmicron_pci_tbl[] = { |
ebbc2031 TH |
211 | { PCI_VENDOR_ID_JMICRON, PCI_DEVICE_ID_JMICRON_JMB361, |
212 | PCI_ANY_ID, PCI_ANY_ID, JMB_CLASS, JMB_CLASS_MASK, 0}, | |
213 | { PCI_VENDOR_ID_JMICRON, PCI_DEVICE_ID_JMICRON_JMB363, | |
214 | PCI_ANY_ID, PCI_ANY_ID, JMB_CLASS, JMB_CLASS_MASK, 1}, | |
215 | { PCI_VENDOR_ID_JMICRON, PCI_DEVICE_ID_JMICRON_JMB365, | |
216 | PCI_ANY_ID, PCI_ANY_ID, JMB_CLASS, JMB_CLASS_MASK, 2}, | |
217 | { PCI_VENDOR_ID_JMICRON, PCI_DEVICE_ID_JMICRON_JMB366, | |
218 | PCI_ANY_ID, PCI_ANY_ID, JMB_CLASS, JMB_CLASS_MASK, 3}, | |
219 | { PCI_VENDOR_ID_JMICRON, PCI_DEVICE_ID_JMICRON_JMB368, | |
220 | PCI_ANY_ID, PCI_ANY_ID, JMB_CLASS, JMB_CLASS_MASK, 4}, | |
bbb3bbdb AC |
221 | { 0, }, |
222 | }; | |
223 | ||
224 | MODULE_DEVICE_TABLE(pci, jmicron_pci_tbl); | |
225 | ||
226 | static struct pci_driver driver = { | |
227 | .name = "JMicron IDE", | |
228 | .id_table = jmicron_pci_tbl, | |
229 | .probe = jmicron_init_one, | |
230 | }; | |
231 | ||
232 | static int __init jmicron_ide_init(void) | |
233 | { | |
234 | return ide_pci_register_driver(&driver); | |
235 | } | |
236 | ||
237 | module_init(jmicron_ide_init); | |
238 | ||
239 | MODULE_AUTHOR("Alan Cox"); | |
240 | MODULE_DESCRIPTION("PCI driver module for the JMicron in legacy modes"); | |
241 | MODULE_LICENSE("GPL"); |