Blame view
drivers/ide/sl82c105.c
9.52 KB
09c434b8a treewide: Add SPD... |
1 |
// SPDX-License-Identifier: GPL-2.0-only |
1da177e4c Linux-2.6.12-rc2 |
2 |
/* |
1da177e4c Linux-2.6.12-rc2 |
3 4 5 6 7 8 9 10 11 12 |
* SL82C105/Winbond 553 IDE driver * * Maintainer unknown. * * Drive tuning added from Rebel.com's kernel sources * -- Russell King (15/11/98) linux@arm.linux.org.uk * * Merge in Russell's HW workarounds, fix various problems * with the timing registers setup. * -- Benjamin Herrenschmidt (01/11/03) benh@kernel.crashing.org |
e93df705a sl82c105: rework ... |
13 |
* |
75c2d7d71 sl82c105: add pri... |
14 |
* Copyright (C) 2006-2007,2009 MontaVista Software, Inc. <source@mvista.com> |
6ae8b1efc sl82c105: program... |
15 |
* Copyright (C) 2007 Bartlomiej Zolnierkiewicz |
1da177e4c Linux-2.6.12-rc2 |
16 |
*/ |
1da177e4c Linux-2.6.12-rc2 |
17 18 19 |
#include <linux/types.h> #include <linux/module.h> #include <linux/kernel.h> |
1da177e4c Linux-2.6.12-rc2 |
20 21 22 23 |
#include <linux/pci.h> #include <linux/ide.h> #include <asm/io.h> |
1da177e4c Linux-2.6.12-rc2 |
24 |
|
ced3ec8aa ide: prefix messa... |
25 |
#define DRV_NAME "sl82c105" |
1da177e4c Linux-2.6.12-rc2 |
26 27 28 29 30 31 32 33 34 35 36 37 |
/* * SL82C105 PCI config register 0x40 bits. */ #define CTRL_IDE_IRQB (1 << 30) #define CTRL_IDE_IRQA (1 << 28) #define CTRL_LEGIRQ (1 << 11) #define CTRL_P1F16 (1 << 5) #define CTRL_P1EN (1 << 4) #define CTRL_P0F16 (1 << 1) #define CTRL_P0EN (1 << 0) /* |
e93df705a sl82c105: rework ... |
38 39 |
* Convert a PIO mode and cycle time to the required on/off times * for the interface. This has protection against runaway timings. |
1da177e4c Linux-2.6.12-rc2 |
40 |
*/ |
7dd00083b ide: add ide_pio_... |
41 |
static unsigned int get_pio_timings(ide_drive_t *drive, u8 pio) |
1da177e4c Linux-2.6.12-rc2 |
42 |
{ |
3f847571a sl82c105: convert... |
43 |
struct ide_timing *t = ide_timing_find_mode(XFER_PIO_0 + pio); |
e93df705a sl82c105: rework ... |
44 |
unsigned int cmd_on, cmd_off; |
2229833c1 ide: add ide_dev_... |
45 |
u8 iordy = 0; |
1da177e4c Linux-2.6.12-rc2 |
46 |
|
3f847571a sl82c105: convert... |
47 |
cmd_on = (t->active + 29) / 30; |
7dd00083b ide: add ide_pio_... |
48 |
cmd_off = (ide_pio_cycle_time(drive, pio) - 30 * cmd_on + 29) / 30; |
1da177e4c Linux-2.6.12-rc2 |
49 |
|
1da177e4c Linux-2.6.12-rc2 |
50 51 |
if (cmd_on == 0) cmd_on = 1; |
1da177e4c Linux-2.6.12-rc2 |
52 53 |
if (cmd_off == 0) cmd_off = 1; |
c9ef59ff0 ide: IORDY handli... |
54 |
if (ide_pio_need_iordy(drive, pio)) |
2229833c1 ide: add ide_dev_... |
55 56 57 |
iordy = 0x40; return (cmd_on - 1) << 8 | (cmd_off - 1) | iordy; |
1da177e4c Linux-2.6.12-rc2 |
58 59 60 |
} /* |
e93df705a sl82c105: rework ... |
61 |
* Configure the chipset for PIO mode. |
1da177e4c Linux-2.6.12-rc2 |
62 |
*/ |
e085b3cae ide: change ->set... |
63 |
static void sl82c105_set_pio_mode(ide_hwif_t *hwif, ide_drive_t *drive) |
1da177e4c Linux-2.6.12-rc2 |
64 |
{ |
e085b3cae ide: change ->set... |
65 |
struct pci_dev *dev = to_pci_dev(hwif->dev); |
5bfb151f1 ide: do not acces... |
66 |
unsigned long timings = (unsigned long)ide_get_drivedata(drive); |
e93df705a sl82c105: rework ... |
67 |
int reg = 0x44 + drive->dn * 4; |
e93df705a sl82c105: rework ... |
68 |
u16 drv_ctrl; |
e085b3cae ide: change ->set... |
69 |
const u8 pio = drive->pio_mode - XFER_PIO_0; |
1da177e4c Linux-2.6.12-rc2 |
70 |
|
7dd00083b ide: add ide_pio_... |
71 |
drv_ctrl = get_pio_timings(drive, pio); |
46cedc9b7 sl82c105: add spe... |
72 73 74 75 76 |
/* * Store the PIO timings so that we can restore them * in case DMA will be turned off... */ |
5bfb151f1 ide: do not acces... |
77 78 79 |
timings &= 0xffff0000; timings |= drv_ctrl; ide_set_drivedata(drive, (void *)timings); |
1da177e4c Linux-2.6.12-rc2 |
80 |
|
6ae8b1efc sl82c105: program... |
81 82 |
pci_write_config_word(dev, reg, drv_ctrl); pci_read_config_word (dev, reg, &drv_ctrl); |
e93df705a sl82c105: rework ... |
83 84 85 |
printk(KERN_DEBUG "%s: selected %s (%dns) (%04X) ", drive->name, |
7dd00083b ide: add ide_pio_... |
86 87 |
ide_xfer_verbose(pio + XFER_PIO_0), ide_pio_cycle_time(drive, pio), drv_ctrl); |
1da177e4c Linux-2.6.12-rc2 |
88 89 90 |
} /* |
88b2b32ba ide: move ide_con... |
91 |
* Configure the chipset for DMA mode. |
46cedc9b7 sl82c105: add spe... |
92 |
*/ |
8776168ca ide: change ->set... |
93 |
static void sl82c105_set_dma_mode(ide_hwif_t *hwif, ide_drive_t *drive) |
46cedc9b7 sl82c105: add spe... |
94 95 |
{ static u16 mwdma_timings[] = {0x0707, 0x0201, 0x0200}; |
5bfb151f1 ide: do not acces... |
96 |
unsigned long timings = (unsigned long)ide_get_drivedata(drive); |
46cedc9b7 sl82c105: add spe... |
97 |
u16 drv_ctrl; |
8776168ca ide: change ->set... |
98 |
const u8 speed = drive->dma_mode; |
46cedc9b7 sl82c105: add spe... |
99 |
|
4db90a145 ide: add IDE_HFLA... |
100 |
drv_ctrl = mwdma_timings[speed - XFER_MW_DMA_0]; |
46cedc9b7 sl82c105: add spe... |
101 |
|
4db90a145 ide: add IDE_HFLA... |
102 103 104 105 |
/* * Store the DMA timings so that we can actually program * them when DMA will be turned on... */ |
5bfb151f1 ide: do not acces... |
106 107 108 |
timings &= 0x0000ffff; timings |= (unsigned long)drv_ctrl << 16; ide_set_drivedata(drive, (void *)timings); |
46cedc9b7 sl82c105: add spe... |
109 |
} |
3779f818a sl82c105: impleme... |
110 111 112 113 114 115 116 117 118 |
static int sl82c105_test_irq(ide_hwif_t *hwif) { struct pci_dev *dev = to_pci_dev(hwif->dev); u32 val, mask = hwif->channel ? CTRL_IDE_IRQB : CTRL_IDE_IRQA; pci_read_config_dword(dev, 0x40, &val); return (val & mask) ? 1 : 0; } |
46cedc9b7 sl82c105: add spe... |
119 |
/* |
1da177e4c Linux-2.6.12-rc2 |
120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 |
* The SL82C105 holds off all IDE interrupts while in DMA mode until * all DMA activity is completed. Sometimes this causes problems (eg, * when the drive wants to report an error condition). * * 0x7e is a "chip testing" register. Bit 2 resets the DMA controller * state machine. We need to kick this to work around various bugs. */ static inline void sl82c105_reset_host(struct pci_dev *dev) { u16 val; pci_read_config_word(dev, 0x7e, &val); pci_write_config_word(dev, 0x7e, val | (1 << 2)); pci_write_config_word(dev, 0x7e, val & ~(1 << 2)); } /* * If we get an IRQ timeout, it might be that the DMA state machine * got confused. Fix from Todd Inglett. Details from Winbond. * * This function is called when the IDE timer expires, the drive * indicates that it is READY, and we were waiting for DMA to complete. */ |
841d2a9bf ide: make void an... |
143 |
static void sl82c105_dma_lost_irq(ide_drive_t *drive) |
1da177e4c Linux-2.6.12-rc2 |
144 |
{ |
898ec223f ide: remove HWIF(... |
145 |
ide_hwif_t *hwif = drive->hwif; |
36501650e ide: keep pointer... |
146 |
struct pci_dev *dev = to_pci_dev(hwif->dev); |
688a87d14 sl82c105: DMA sup... |
147 148 |
u32 val, mask = hwif->channel ? CTRL_IDE_IRQB : CTRL_IDE_IRQA; u8 dma_cmd; |
1da177e4c Linux-2.6.12-rc2 |
149 |
|
75c2d7d71 sl82c105: add pri... |
150 151 |
printk(KERN_WARNING "sl82c105: lost IRQ, resetting host "); |
1da177e4c Linux-2.6.12-rc2 |
152 153 154 155 156 157 |
/* * Check the raw interrupt from the drive. */ pci_read_config_dword(dev, 0x40, &val); if (val & mask) |
75c2d7d71 sl82c105: add pri... |
158 159 160 |
printk(KERN_INFO "sl82c105: drive was requesting IRQ, " "but host lost it "); |
1da177e4c Linux-2.6.12-rc2 |
161 162 163 164 165 |
/* * Was DMA enabled? If so, disable it - we're resetting the * host. The IDE layer will be handling the drive for us. */ |
cab7f8eda ide: remove ->dma... |
166 |
dma_cmd = inb(hwif->dma_base + ATA_DMA_CMD); |
688a87d14 sl82c105: DMA sup... |
167 |
if (dma_cmd & 1) { |
cab7f8eda ide: remove ->dma... |
168 |
outb(dma_cmd & ~1, hwif->dma_base + ATA_DMA_CMD); |
75c2d7d71 sl82c105: add pri... |
169 170 |
printk(KERN_INFO "sl82c105: DMA was enabled "); |
1da177e4c Linux-2.6.12-rc2 |
171 172 173 |
} sl82c105_reset_host(dev); |
1da177e4c Linux-2.6.12-rc2 |
174 175 176 177 178 179 180 181 182 183 |
} /* * ATAPI devices can cause the SL82C105 DMA state machine to go gaga. * Winbond recommend that the DMA state machine is reset prior to * setting the bus master DMA enable bit. * * The generic IDE core will have disabled the BMEN bit before this * function is called. */ |
688a87d14 sl82c105: DMA sup... |
184 |
static void sl82c105_dma_start(ide_drive_t *drive) |
1da177e4c Linux-2.6.12-rc2 |
185 |
{ |
898ec223f ide: remove HWIF(... |
186 |
ide_hwif_t *hwif = drive->hwif; |
36501650e ide: keep pointer... |
187 |
struct pci_dev *dev = to_pci_dev(hwif->dev); |
6ae8b1efc sl82c105: program... |
188 |
int reg = 0x44 + drive->dn * 4; |
5bfb151f1 ide: do not acces... |
189 190 |
pci_write_config_word(dev, reg, (unsigned long)ide_get_drivedata(drive) >> 16); |
1da177e4c Linux-2.6.12-rc2 |
191 192 193 194 |
sl82c105_reset_host(dev); ide_dma_start(drive); } |
35c9b4daf ide: add ->dma_cl... |
195 |
static void sl82c105_dma_clear(ide_drive_t *drive) |
1da177e4c Linux-2.6.12-rc2 |
196 |
{ |
36501650e ide: keep pointer... |
197 |
struct pci_dev *dev = to_pci_dev(drive->hwif->dev); |
36501650e ide: keep pointer... |
198 |
sl82c105_reset_host(dev); |
1da177e4c Linux-2.6.12-rc2 |
199 |
} |
6ae8b1efc sl82c105: program... |
200 |
static int sl82c105_dma_end(ide_drive_t *drive) |
1da177e4c Linux-2.6.12-rc2 |
201 |
{ |
36501650e ide: keep pointer... |
202 |
struct pci_dev *dev = to_pci_dev(drive->hwif->dev); |
e93df705a sl82c105: rework ... |
203 |
int reg = 0x44 + drive->dn * 4; |
f9288e152 sl82c105: remove ... |
204 |
int ret = ide_dma_end(drive); |
7469aaf6a ide: make ide_hwi... |
205 |
|
5bfb151f1 ide: do not acces... |
206 207 |
pci_write_config_word(dev, reg, (unsigned long)ide_get_drivedata(drive)); |
e93df705a sl82c105: rework ... |
208 |
|
6ae8b1efc sl82c105: program... |
209 |
return ret; |
1da177e4c Linux-2.6.12-rc2 |
210 211 212 |
} /* |
1da177e4c Linux-2.6.12-rc2 |
213 |
* ATA reset will clear the 16 bits mode in the control |
08590556d sl82c105: remove ... |
214 |
* register, we need to reprogram it |
1da177e4c Linux-2.6.12-rc2 |
215 216 217 |
*/ static void sl82c105_resetproc(ide_drive_t *drive) { |
36501650e ide: keep pointer... |
218 |
struct pci_dev *dev = to_pci_dev(drive->hwif->dev); |
1da177e4c Linux-2.6.12-rc2 |
219 |
u32 val; |
1da177e4c Linux-2.6.12-rc2 |
220 |
pci_read_config_dword(dev, 0x40, &val); |
08590556d sl82c105: remove ... |
221 222 |
val |= (CTRL_P1F16 | CTRL_P0F16); pci_write_config_dword(dev, 0x40, val); |
1da177e4c Linux-2.6.12-rc2 |
223 |
} |
1da177e4c Linux-2.6.12-rc2 |
224 225 226 227 228 |
/* * Return the revision of the Winbond bridge * which this function is part of. */ |
6c6106416 sl82c105: check b... |
229 |
static u8 sl82c105_bridge_revision(struct pci_dev *dev) |
1da177e4c Linux-2.6.12-rc2 |
230 231 |
{ struct pci_dev *bridge; |
1da177e4c Linux-2.6.12-rc2 |
232 233 234 235 |
/* * The bridge should be part of the same device, but function 0. */ |
8c016394e sl82c105: depreca... |
236 237 238 |
bridge = pci_get_domain_bus_and_slot(pci_domain_nr(dev->bus), dev->bus->number, PCI_DEVFN(PCI_SLOT(dev->devfn), 0)); |
1da177e4c Linux-2.6.12-rc2 |
239 240 241 242 243 244 245 246 |
if (!bridge) return -1; /* * Make sure it is a Winbond 553 and is an ISA bridge. */ if (bridge->vendor != PCI_VENDOR_ID_WINBOND || bridge->device != PCI_DEVICE_ID_WINBOND_83C553 || |
640b31bf1 sl82c105: Switch ... |
247 248 |
bridge->class >> 8 != PCI_CLASS_BRIDGE_ISA) { pci_dev_put(bridge); |
1da177e4c Linux-2.6.12-rc2 |
249 |
return -1; |
640b31bf1 sl82c105: Switch ... |
250 |
} |
1da177e4c Linux-2.6.12-rc2 |
251 252 253 |
/* * We need to find function 0's revision, not function 1 */ |
640b31bf1 sl82c105: Switch ... |
254 |
pci_dev_put(bridge); |
1da177e4c Linux-2.6.12-rc2 |
255 |
|
44c10138f PCI: Change all d... |
256 |
return bridge->revision; |
1da177e4c Linux-2.6.12-rc2 |
257 258 259 260 261 262 263 264 265 266 |
} /* * Enable the PCI device * * --BenH: It's arch fixup code that should enable channels that * have not been enabled by firmware. I decided we can still enable * channel 0 here at least, but channel 1 has to be enabled by * firmware or arch code. We still set both to 16 bits mode. */ |
2ed0ef543 ide: fix ->init_c... |
267 |
static int init_chipset_sl82c105(struct pci_dev *dev) |
1da177e4c Linux-2.6.12-rc2 |
268 269 |
{ u32 val; |
1da177e4c Linux-2.6.12-rc2 |
270 271 272 |
pci_read_config_dword(dev, 0x40, &val); val |= CTRL_P0EN | CTRL_P0F16 | CTRL_P1F16; pci_write_config_dword(dev, 0x40, val); |
2ed0ef543 ide: fix ->init_c... |
273 |
return 0; |
1da177e4c Linux-2.6.12-rc2 |
274 |
} |
ac95beedf ide: add struct i... |
275 276 277 278 |
static const struct ide_port_ops sl82c105_port_ops = { .set_pio_mode = sl82c105_set_pio_mode, .set_dma_mode = sl82c105_set_dma_mode, .resetproc = sl82c105_resetproc, |
3779f818a sl82c105: impleme... |
279 |
.test_irq = sl82c105_test_irq, |
ac95beedf ide: add struct i... |
280 |
}; |
f37afdaca ide: constify str... |
281 282 283 |
static const struct ide_dma_ops sl82c105_dma_ops = { .dma_host_set = ide_dma_host_set, .dma_setup = ide_dma_setup, |
5e37bdc08 ide: add struct i... |
284 285 |
.dma_start = sl82c105_dma_start, .dma_end = sl82c105_dma_end, |
f37afdaca ide: constify str... |
286 |
.dma_test_irq = ide_dma_test_irq, |
5e37bdc08 ide: add struct i... |
287 |
.dma_lost_irq = sl82c105_dma_lost_irq, |
22117d6ea ide: add ->dma_ti... |
288 |
.dma_timer_expiry = ide_dma_sff_timer_expiry, |
35c9b4daf ide: add ->dma_cl... |
289 |
.dma_clear = sl82c105_dma_clear, |
592b53152 ide: move read_sf... |
290 |
.dma_sff_read_status = ide_dma_sff_read_status, |
5e37bdc08 ide: add struct i... |
291 |
}; |
fe31edc8a Drivers: ide: rem... |
292 |
static const struct ide_port_info sl82c105_chipset = { |
ced3ec8aa ide: prefix messa... |
293 |
.name = DRV_NAME, |
1da177e4c Linux-2.6.12-rc2 |
294 |
.init_chipset = init_chipset_sl82c105, |
1da177e4c Linux-2.6.12-rc2 |
295 |
.enablebits = {{0x40,0x01,0x01}, {0x40,0x10,0x10}}, |
ac95beedf ide: add struct i... |
296 |
.port_ops = &sl82c105_port_ops, |
5e37bdc08 ide: add struct i... |
297 |
.dma_ops = &sl82c105_dma_ops, |
caea7602f ide: add IDE_HFLA... |
298 299 |
.host_flags = IDE_HFLAG_IO_32BIT | IDE_HFLAG_UNMASK_IRQS | |
1fd189059 ide: add IDE_HFLA... |
300 |
IDE_HFLAG_SERIALIZE_DMA | |
5e71d9c5a ide: IDE_HFLAG_BO... |
301 |
IDE_HFLAG_NO_AUTODMA, |
4099d1432 ide: add PIO masks |
302 |
.pio_mask = ATA_PIO5, |
6c6106416 sl82c105: check b... |
303 |
.mwdma_mask = ATA_MWDMA2, |
1da177e4c Linux-2.6.12-rc2 |
304 |
}; |
fe31edc8a Drivers: ide: rem... |
305 |
static int sl82c105_init_one(struct pci_dev *dev, const struct pci_device_id *id) |
1da177e4c Linux-2.6.12-rc2 |
306 |
{ |
6c6106416 sl82c105: check b... |
307 308 309 310 311 312 313 314 |
struct ide_port_info d = sl82c105_chipset; u8 rev = sl82c105_bridge_revision(dev); if (rev <= 5) { /* * Never ever EVER under any circumstances enable * DMA when the bridge is this old. */ |
ced3ec8aa ide: prefix messa... |
315 |
printk(KERN_INFO DRV_NAME ": Winbond W83C553 bridge " |
6c6106416 sl82c105: check b... |
316 317 |
"revision %d, BM-DMA disabled ", rev); |
5e37bdc08 ide: add struct i... |
318 |
d.dma_ops = NULL; |
6c6106416 sl82c105: check b... |
319 |
d.mwdma_mask = 0; |
1fd189059 ide: add IDE_HFLA... |
320 |
d.host_flags &= ~IDE_HFLAG_SERIALIZE_DMA; |
6c6106416 sl82c105: check b... |
321 |
} |
6cdf6eb35 ide: add ->dev an... |
322 |
return ide_pci_init_one(dev, &d, NULL); |
1da177e4c Linux-2.6.12-rc2 |
323 |
} |
9cbcc5e3c ide: use PCI_VDEV... |
324 325 |
static const struct pci_device_id sl82c105_pci_tbl[] = { { PCI_VDEVICE(WINBOND, PCI_DEVICE_ID_WINBOND_82C105), 0 }, |
1da177e4c Linux-2.6.12-rc2 |
326 327 328 |
{ 0, }, }; MODULE_DEVICE_TABLE(pci, sl82c105_pci_tbl); |
a9ab09e26 ide: use unique n... |
329 |
static struct pci_driver sl82c105_pci_driver = { |
1da177e4c Linux-2.6.12-rc2 |
330 331 332 |
.name = "W82C105_IDE", .id_table = sl82c105_pci_tbl, .probe = sl82c105_init_one, |
6ce719989 sl82c105: add ->r... |
333 |
.remove = ide_pci_remove, |
feb22b7f8 ide: add proper P... |
334 335 |
.suspend = ide_pci_suspend, .resume = ide_pci_resume, |
1da177e4c Linux-2.6.12-rc2 |
336 |
}; |
82ab1eece ide: add missing ... |
337 |
static int __init sl82c105_ide_init(void) |
1da177e4c Linux-2.6.12-rc2 |
338 |
{ |
a9ab09e26 ide: use unique n... |
339 |
return ide_pci_register_driver(&sl82c105_pci_driver); |
1da177e4c Linux-2.6.12-rc2 |
340 |
} |
6ce719989 sl82c105: add ->r... |
341 342 |
static void __exit sl82c105_ide_exit(void) { |
a9ab09e26 ide: use unique n... |
343 |
pci_unregister_driver(&sl82c105_pci_driver); |
6ce719989 sl82c105: add ->r... |
344 |
} |
1da177e4c Linux-2.6.12-rc2 |
345 |
module_init(sl82c105_ide_init); |
6ce719989 sl82c105: add ->r... |
346 |
module_exit(sl82c105_ide_exit); |
1da177e4c Linux-2.6.12-rc2 |
347 348 349 |
MODULE_DESCRIPTION("PCI driver module for W82C105 IDE"); MODULE_LICENSE("GPL"); |