diff options
author | Sergei Shtylyov <sshtylyov@ru.mvista.com> | 2007-05-05 16:03:49 -0400 |
---|---|---|
committer | Bartlomiej Zolnierkiewicz <bzolnier@gmail.com> | 2007-05-05 16:03:49 -0400 |
commit | 60e7a82f1acb76af05d81e93ca0f65fdd52c23c2 (patch) | |
tree | be3868264f513cbb2979dc6059aa0cb525b62365 /drivers/ide | |
parent | 688a87d145e04f6761c63e7f2e19fd9b3e4ca060 (diff) |
cmd64x: fix multiword and remove single-word DMA support
Fix the multiword DMA and drop the single-word DMA support (which nobody will
miss, I think). In order to do it, a number of changes was necessary:
- rename program_drive_counts() to program_cycle_times(), pass to it cycle's
total/active times instead of the clock counts, and convert them into the
active/recovery clocks there instead of cmd64x_tune_pio() -- this causes
quantize_timing() to also move;
- contrarywise, move all the code handling the address setup timing into
cmd64x_tune_pio(), so that setting MWDMA mode wouldn't change address setup;
- remove from the speedproc() method the bogus code pretending to set the DMA
timings by twiddling bits in the BMIDE status register, handle setting MWDMA
by just calling program_cycle_times(); while at it, improve the style of that
whole switch statement;
- stop fiddling with the DMA capable bits in the speedproc() method -- they do
not enable DMA, and are properly dealt with by the dma_host_{on,off} methods;
- don't set hwif->swdma_mask in the init_hwif() method anymore.
In addition to those changes, do the following:
- in cmd64x_tune_pio(), when writing to ARTTIM23 register preserve the interrupt
status bit, eliminate local_irq_{save|restore}() around this code as there's
*no* actual race with the interrupt handler, and move cmdprintk() to a more
fitting place -- after ide_get_best_pio_mode() call;
- make {arttim|drwtim}_regs arrays single-dimensional, indexed with drive->dn;
- rename {setup|recovery}_counts[] into more fitting {setup|recovery}_values[];
- in the speedproc() method, get rid of the duplicate reads/writes from/to the
UDIDETCRx registers and of the extra variable used to store the transfer mode
value after filtering, use another method of determining master/slave drive,
and cleanup useless parens;
- beautify cmdprintk() output here and there.
While at it, remove meaningless comment about the driver being used only on
UltraSPARC and long non-relevant RCS tag. :-)
Signed-off-by: Sergei Shtylyov <sshtylyov@ru.mvista.com>
Signed-off-by: Bartlomiej Zolnierkiewicz <bzolnier@gmail.com>
Diffstat (limited to 'drivers/ide')
-rw-r--r-- | drivers/ide/pci/cmd64x.c | 248 |
1 files changed, 117 insertions, 131 deletions
diff --git a/drivers/ide/pci/cmd64x.c b/drivers/ide/pci/cmd64x.c index 561197f7b5bb..336d02f58010 100644 --- a/drivers/ide/pci/cmd64x.c +++ b/drivers/ide/pci/cmd64x.c | |||
@@ -1,10 +1,7 @@ | |||
1 | /* $Id: cmd64x.c,v 1.21 2000/01/30 23:23:16 | 1 | /* |
2 | * | 2 | * linux/drivers/ide/pci/cmd64x.c Version 1.43 Mar 10, 2007 |
3 | * linux/drivers/ide/pci/cmd64x.c Version 1.42 Feb 8, 2007 | ||
4 | * | 3 | * |
5 | * cmd64x.c: Enable interrupts at initialization time on Ultra/PCI machines. | 4 | * cmd64x.c: Enable interrupts at initialization time on Ultra/PCI machines. |
6 | * Note, this driver is not used at all on other systems because | ||
7 | * there the "BIOS" has done all of the following already. | ||
8 | * Due to massive hardware bugs, UltraDMA is only supported | 5 | * Due to massive hardware bugs, UltraDMA is only supported |
9 | * on the 646U2 and not on the 646U. | 6 | * on the 646U2 and not on the 646U. |
10 | * | 7 | * |
@@ -195,116 +192,103 @@ static u8 quantize_timing(int timing, int quant) | |||
195 | } | 192 | } |
196 | 193 | ||
197 | /* | 194 | /* |
198 | * This routine writes the prepared setup/active/recovery counts | 195 | * This routine calculates active/recovery counts and then writes them into |
199 | * for a drive into the cmd646 chipset registers to active them. | 196 | * the chipset registers. |
200 | */ | 197 | */ |
201 | static void program_drive_counts (ide_drive_t *drive, int setup_count, int active_count, int recovery_count) | 198 | static void program_cycle_times (ide_drive_t *drive, int cycle_time, int active_time) |
202 | { | 199 | { |
203 | unsigned long flags; | 200 | struct pci_dev *dev = HWIF(drive)->pci_dev; |
204 | struct pci_dev *dev = HWIF(drive)->pci_dev; | 201 | int clock_time = 1000 / system_bus_clock(); |
205 | ide_drive_t *drives = HWIF(drive)->drives; | 202 | u8 cycle_count, active_count, recovery_count, drwtim; |
206 | u8 temp_b; | 203 | static const u8 recovery_values[] = |
207 | static const u8 setup_counts[] = {0x40, 0x40, 0x40, 0x80, 0, 0xc0}; | ||
208 | static const u8 recovery_counts[] = | ||
209 | {15, 15, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 0}; | 204 | {15, 15, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 0}; |
210 | static const u8 arttim_regs[2][2] = { | 205 | static const u8 drwtim_regs[4] = {DRWTIM0, DRWTIM1, DRWTIM2, DRWTIM3}; |
211 | { ARTTIM0, ARTTIM1 }, | 206 | |
212 | { ARTTIM23, ARTTIM23 } | 207 | cmdprintk("program_cycle_times parameters: total=%d, active=%d\n", |
213 | }; | 208 | cycle_time, active_time); |
214 | static const u8 drwtim_regs[2][2] = { | 209 | |
215 | { DRWTIM0, DRWTIM1 }, | 210 | cycle_count = quantize_timing( cycle_time, clock_time); |
216 | { DRWTIM2, DRWTIM3 } | 211 | active_count = quantize_timing(active_time, clock_time); |
217 | }; | 212 | recovery_count = cycle_count - active_count; |
218 | int channel = (int) HWIF(drive)->channel; | 213 | |
219 | int slave = (drives != drive); /* Is this really the best way to determine this?? */ | ||
220 | |||
221 | cmdprintk("program_drive_count parameters = s(%d),a(%d),r(%d),p(%d)\n", | ||
222 | setup_count, active_count, recovery_count, drive->present); | ||
223 | /* | 214 | /* |
224 | * Set up address setup count registers. | 215 | * In case we've got too long recovery phase, try to lengthen |
225 | * Primary interface has individual count/timing registers for | 216 | * the active phase |
226 | * each drive. Secondary interface has one common set of registers, | ||
227 | * for address setup so we merge these timings, using the slowest | ||
228 | * value. | ||
229 | */ | 217 | */ |
230 | if (channel) { | 218 | if (recovery_count > 16) { |
231 | drive->drive_data = setup_count; | 219 | active_count += recovery_count - 16; |
232 | setup_count = max(drives[0].drive_data, | 220 | recovery_count = 16; |
233 | drives[1].drive_data); | ||
234 | cmdprintk("Secondary interface, setup_count = %d\n", | ||
235 | setup_count); | ||
236 | } | 221 | } |
222 | if (active_count > 16) /* shouldn't actually happen... */ | ||
223 | active_count = 16; | ||
224 | |||
225 | cmdprintk("Final counts: total=%d, active=%d, recovery=%d\n", | ||
226 | cycle_count, active_count, recovery_count); | ||
237 | 227 | ||
238 | /* | 228 | /* |
239 | * Convert values to internal chipset representation | 229 | * Convert values to internal chipset representation |
240 | */ | 230 | */ |
241 | setup_count = (setup_count > 5) ? 0xc0 : (int) setup_counts[setup_count]; | 231 | recovery_count = recovery_values[recovery_count]; |
242 | active_count &= 0xf; /* Remember, max value is 16 */ | 232 | active_count &= 0x0f; |
243 | recovery_count = (int) recovery_counts[recovery_count]; | ||
244 | |||
245 | cmdprintk("Final values = %d,%d,%d\n", | ||
246 | setup_count, active_count, recovery_count); | ||
247 | 233 | ||
248 | /* | 234 | /* Program the active/recovery counts into the DRWTIM register */ |
249 | * Now that everything is ready, program the new timings | 235 | drwtim = (active_count << 4) | recovery_count; |
250 | */ | 236 | (void) pci_write_config_byte(dev, drwtim_regs[drive->dn], drwtim); |
251 | local_irq_save(flags); | 237 | cmdprintk("Write 0x%02x to reg 0x%x\n", drwtim, drwtim_regs[drive->dn]); |
252 | /* | ||
253 | * Program the address_setup clocks into ARTTIM reg, | ||
254 | * and then the active/recovery counts into the DRWTIM reg | ||
255 | */ | ||
256 | (void) pci_read_config_byte(dev, arttim_regs[channel][slave], &temp_b); | ||
257 | (void) pci_write_config_byte(dev, arttim_regs[channel][slave], | ||
258 | ((u8) setup_count) | (temp_b & 0x3f)); | ||
259 | (void) pci_write_config_byte(dev, drwtim_regs[channel][slave], | ||
260 | (u8) ((active_count << 4) | recovery_count)); | ||
261 | cmdprintk ("Write %x to %x\n", | ||
262 | ((u8) setup_count) | (temp_b & 0x3f), | ||
263 | arttim_regs[channel][slave]); | ||
264 | cmdprintk ("Write %x to %x\n", | ||
265 | (u8) ((active_count << 4) | recovery_count), | ||
266 | drwtim_regs[channel][slave]); | ||
267 | local_irq_restore(flags); | ||
268 | } | 238 | } |
269 | 239 | ||
270 | /* | 240 | /* |
271 | * This routine selects drive's best PIO mode, calculates setup/active/recovery | 241 | * This routine selects drive's best PIO mode and writes into the chipset |
272 | * counts, and then writes them into the chipset registers. | 242 | * registers setup/active/recovery timings. |
273 | */ | 243 | */ |
274 | static u8 cmd64x_tune_pio (ide_drive_t *drive, u8 mode_wanted) | 244 | static u8 cmd64x_tune_pio (ide_drive_t *drive, u8 mode_wanted) |
275 | { | 245 | { |
276 | int setup_time, active_time, cycle_time; | 246 | ide_hwif_t *hwif = HWIF(drive); |
277 | u8 cycle_count, setup_count, active_count, recovery_count; | 247 | struct pci_dev *dev = hwif->pci_dev; |
278 | u8 pio_mode; | ||
279 | int clock_time = 1000 / system_bus_clock(); | ||
280 | ide_pio_data_t pio; | 248 | ide_pio_data_t pio; |
281 | 249 | u8 pio_mode, setup_count, arttim = 0; | |
250 | static const u8 setup_values[] = {0x40, 0x40, 0x40, 0x80, 0, 0xc0}; | ||
251 | static const u8 arttim_regs[4] = {ARTTIM0, ARTTIM1, ARTTIM23, ARTTIM23}; | ||
282 | pio_mode = ide_get_best_pio_mode(drive, mode_wanted, 5, &pio); | 252 | pio_mode = ide_get_best_pio_mode(drive, mode_wanted, 5, &pio); |
283 | cycle_time = pio.cycle_time; | ||
284 | 253 | ||
285 | setup_time = ide_pio_timings[pio_mode].setup_time; | 254 | cmdprintk("%s: PIO mode wanted %d, selected %d (%d ns)%s\n", |
286 | active_time = ide_pio_timings[pio_mode].active_time; | 255 | drive->name, mode_wanted, pio_mode, pio.cycle_time, |
256 | pio.overridden ? " (overriding vendor mode)" : ""); | ||
287 | 257 | ||
288 | setup_count = quantize_timing( setup_time, clock_time); | 258 | program_cycle_times(drive, pio.cycle_time, |
289 | cycle_count = quantize_timing( cycle_time, clock_time); | 259 | ide_pio_timings[pio_mode].active_time); |
290 | active_count = quantize_timing(active_time, clock_time); | ||
291 | 260 | ||
292 | recovery_count = cycle_count - active_count; | 261 | setup_count = quantize_timing(ide_pio_timings[pio_mode].setup_time, |
293 | /* program_drive_counts() takes care of zero recovery cycles */ | 262 | 1000 / system_bus_clock()); |
294 | if (recovery_count > 16) { | 263 | |
295 | active_count += recovery_count - 16; | 264 | /* |
296 | recovery_count = 16; | 265 | * The primary channel has individual address setup timing registers |
266 | * for each drive and the hardware selects the slowest timing itself. | ||
267 | * The secondary channel has one common register and we have to select | ||
268 | * the slowest address setup timing ourselves. | ||
269 | */ | ||
270 | if (hwif->channel) { | ||
271 | ide_drive_t *drives = hwif->drives; | ||
272 | |||
273 | drive->drive_data = setup_count; | ||
274 | setup_count = max(drives[0].drive_data, drives[1].drive_data); | ||
297 | } | 275 | } |
298 | if (active_count > 16) | ||
299 | active_count = 16; /* maximum allowed by cmd64x */ | ||
300 | 276 | ||
301 | program_drive_counts (drive, setup_count, active_count, recovery_count); | 277 | if (setup_count > 5) /* shouldn't actually happen... */ |
278 | setup_count = 5; | ||
279 | cmdprintk("Final address setup count: %d\n", setup_count); | ||
302 | 280 | ||
303 | cmdprintk("%s: PIO mode wanted %d, selected %d (%dns)%s, " | 281 | /* |
304 | "clocks=%d/%d/%d\n", | 282 | * Program the address setup clocks into the ARTTIM registers. |
305 | drive->name, mode_wanted, pio_mode, cycle_time, | 283 | * Avoid clearing the secondary channel's interrupt bit. |
306 | pio.overridden ? " (overriding vendor mode)" : "", | 284 | */ |
307 | setup_count, active_count, recovery_count); | 285 | (void) pci_read_config_byte (dev, arttim_regs[drive->dn], &arttim); |
286 | if (hwif->channel) | ||
287 | arttim &= ~ARTTIM23_INTR_CH1; | ||
288 | arttim &= ~0xc0; | ||
289 | arttim |= setup_values[setup_count]; | ||
290 | (void) pci_write_config_byte(dev, arttim_regs[drive->dn], arttim); | ||
291 | cmdprintk("Write 0x%02x to reg 0x%x\n", arttim, arttim_regs[drive->dn]); | ||
308 | 292 | ||
309 | return pio_mode; | 293 | return pio_mode; |
310 | } | 294 | } |
@@ -376,61 +360,64 @@ static u8 cmd64x_ratemask (ide_drive_t *drive) | |||
376 | return mode; | 360 | return mode; |
377 | } | 361 | } |
378 | 362 | ||
379 | static int cmd64x_tune_chipset (ide_drive_t *drive, u8 xferspeed) | 363 | static int cmd64x_tune_chipset (ide_drive_t *drive, u8 speed) |
380 | { | 364 | { |
381 | ide_hwif_t *hwif = HWIF(drive); | 365 | ide_hwif_t *hwif = HWIF(drive); |
382 | struct pci_dev *dev = hwif->pci_dev; | 366 | struct pci_dev *dev = hwif->pci_dev; |
367 | u8 unit = drive->dn & 0x01; | ||
368 | u8 regU = 0, pciU = hwif->channel ? UDIDETCR1 : UDIDETCR0; | ||
383 | 369 | ||
384 | u8 unit = (drive->select.b.unit & 0x01); | 370 | speed = ide_rate_filter(cmd64x_ratemask(drive), speed); |
385 | u8 regU = 0, pciU = (hwif->channel) ? UDIDETCR1 : UDIDETCR0; | ||
386 | u8 regD = 0, pciD = (hwif->channel) ? BMIDESR1 : BMIDESR0; | ||
387 | |||
388 | u8 speed = ide_rate_filter(cmd64x_ratemask(drive), xferspeed); | ||
389 | 371 | ||
390 | if (speed >= XFER_SW_DMA_0) { | 372 | if (speed >= XFER_SW_DMA_0) { |
391 | (void) pci_read_config_byte(dev, pciD, ®D); | ||
392 | (void) pci_read_config_byte(dev, pciU, ®U); | 373 | (void) pci_read_config_byte(dev, pciU, ®U); |
393 | regD &= ~(unit ? 0x40 : 0x20); | ||
394 | regU &= ~(unit ? 0xCA : 0x35); | 374 | regU &= ~(unit ? 0xCA : 0x35); |
395 | (void) pci_write_config_byte(dev, pciD, regD); | ||
396 | (void) pci_write_config_byte(dev, pciU, regU); | ||
397 | (void) pci_read_config_byte(dev, pciD, ®D); | ||
398 | (void) pci_read_config_byte(dev, pciU, ®U); | ||
399 | } | 375 | } |
400 | 376 | ||
401 | switch(speed) { | 377 | switch(speed) { |
402 | case XFER_UDMA_5: regU |= (unit ? 0x0A : 0x05); break; | 378 | case XFER_UDMA_5: |
403 | case XFER_UDMA_4: regU |= (unit ? 0x4A : 0x15); break; | 379 | regU |= unit ? 0x0A : 0x05; |
404 | case XFER_UDMA_3: regU |= (unit ? 0x8A : 0x25); break; | 380 | break; |
405 | case XFER_UDMA_2: regU |= (unit ? 0x42 : 0x11); break; | 381 | case XFER_UDMA_4: |
406 | case XFER_UDMA_1: regU |= (unit ? 0x82 : 0x21); break; | 382 | regU |= unit ? 0x4A : 0x15; |
407 | case XFER_UDMA_0: regU |= (unit ? 0xC2 : 0x31); break; | 383 | break; |
408 | case XFER_MW_DMA_2: regD |= (unit ? 0x40 : 0x10); break; | 384 | case XFER_UDMA_3: |
409 | case XFER_MW_DMA_1: regD |= (unit ? 0x80 : 0x20); break; | 385 | regU |= unit ? 0x8A : 0x25; |
410 | case XFER_MW_DMA_0: regD |= (unit ? 0xC0 : 0x30); break; | 386 | break; |
411 | case XFER_SW_DMA_2: regD |= (unit ? 0x40 : 0x10); break; | 387 | case XFER_UDMA_2: |
412 | case XFER_SW_DMA_1: regD |= (unit ? 0x80 : 0x20); break; | 388 | regU |= unit ? 0x42 : 0x11; |
413 | case XFER_SW_DMA_0: regD |= (unit ? 0xC0 : 0x30); break; | 389 | break; |
414 | case XFER_PIO_5: | 390 | case XFER_UDMA_1: |
415 | case XFER_PIO_4: | 391 | regU |= unit ? 0x82 : 0x21; |
416 | case XFER_PIO_3: | 392 | break; |
417 | case XFER_PIO_2: | 393 | case XFER_UDMA_0: |
418 | case XFER_PIO_1: | 394 | regU |= unit ? 0xC2 : 0x31; |
419 | case XFER_PIO_0: | 395 | break; |
420 | (void) cmd64x_tune_pio(drive, speed - XFER_PIO_0); | 396 | case XFER_MW_DMA_2: |
421 | break; | 397 | program_cycle_times(drive, 120, 70); |
422 | 398 | break; | |
423 | default: | 399 | case XFER_MW_DMA_1: |
424 | return 1; | 400 | program_cycle_times(drive, 150, 80); |
401 | break; | ||
402 | case XFER_MW_DMA_0: | ||
403 | program_cycle_times(drive, 480, 215); | ||
404 | break; | ||
405 | case XFER_PIO_5: | ||
406 | case XFER_PIO_4: | ||
407 | case XFER_PIO_3: | ||
408 | case XFER_PIO_2: | ||
409 | case XFER_PIO_1: | ||
410 | case XFER_PIO_0: | ||
411 | (void) cmd64x_tune_pio(drive, speed - XFER_PIO_0); | ||
412 | break; | ||
413 | default: | ||
414 | return 1; | ||
425 | } | 415 | } |
426 | 416 | ||
427 | if (speed >= XFER_SW_DMA_0) { | 417 | if (speed >= XFER_SW_DMA_0) |
428 | (void) pci_write_config_byte(dev, pciU, regU); | 418 | (void) pci_write_config_byte(dev, pciU, regU); |
429 | regD |= (unit ? 0x40 : 0x20); | ||
430 | (void) pci_write_config_byte(dev, pciD, regD); | ||
431 | } | ||
432 | 419 | ||
433 | return (ide_config_drive_speed(drive, speed)); | 420 | return ide_config_drive_speed(drive, speed); |
434 | } | 421 | } |
435 | 422 | ||
436 | static int config_chipset_for_dma (ide_drive_t *drive) | 423 | static int config_chipset_for_dma (ide_drive_t *drive) |
@@ -665,7 +652,6 @@ static void __devinit init_hwif_cmd64x(ide_hwif_t *hwif) | |||
665 | 652 | ||
666 | hwif->ultra_mask = 0x3f; | 653 | hwif->ultra_mask = 0x3f; |
667 | hwif->mwdma_mask = 0x07; | 654 | hwif->mwdma_mask = 0x07; |
668 | hwif->swdma_mask = 0x07; | ||
669 | 655 | ||
670 | if (dev->device == PCI_DEVICE_ID_CMD_643) | 656 | if (dev->device == PCI_DEVICE_ID_CMD_643) |
671 | hwif->ultra_mask = 0x80; | 657 | hwif->ultra_mask = 0x80; |