aboutsummaryrefslogtreecommitdiffstats
path: root/drivers/ata/pata_legacy.c
diff options
context:
space:
mode:
Diffstat (limited to 'drivers/ata/pata_legacy.c')
-rw-r--r--drivers/ata/pata_legacy.c166
1 files changed, 82 insertions, 84 deletions
diff --git a/drivers/ata/pata_legacy.c b/drivers/ata/pata_legacy.c
index 581cb33c6f45..4223e10de6a0 100644
--- a/drivers/ata/pata_legacy.c
+++ b/drivers/ata/pata_legacy.c
@@ -164,14 +164,14 @@ static struct ata_port_operations simple_port_ops = {
164 .qc_prep = ata_qc_prep, 164 .qc_prep = ata_qc_prep,
165 .qc_issue = ata_qc_issue_prot, 165 .qc_issue = ata_qc_issue_prot,
166 166
167 .data_xfer = ata_pio_data_xfer_noirq, 167 .data_xfer = ata_data_xfer_noirq,
168 168
169 .irq_handler = ata_interrupt, 169 .irq_handler = ata_interrupt,
170 .irq_clear = ata_bmdma_irq_clear, 170 .irq_clear = ata_bmdma_irq_clear,
171 .irq_on = ata_irq_on,
172 .irq_ack = ata_irq_ack,
171 173
172 .port_start = ata_port_start, 174 .port_start = ata_port_start,
173 .port_stop = ata_port_stop,
174 .host_stop = ata_host_stop
175}; 175};
176 176
177static struct ata_port_operations legacy_port_ops = { 177static struct ata_port_operations legacy_port_ops = {
@@ -189,14 +189,14 @@ static struct ata_port_operations legacy_port_ops = {
189 .qc_prep = ata_qc_prep, 189 .qc_prep = ata_qc_prep,
190 .qc_issue = ata_qc_issue_prot, 190 .qc_issue = ata_qc_issue_prot,
191 191
192 .data_xfer = ata_pio_data_xfer_noirq, 192 .data_xfer = ata_data_xfer_noirq,
193 193
194 .irq_handler = ata_interrupt, 194 .irq_handler = ata_interrupt,
195 .irq_clear = ata_bmdma_irq_clear, 195 .irq_clear = ata_bmdma_irq_clear,
196 .irq_on = ata_irq_on,
197 .irq_ack = ata_irq_ack,
196 198
197 .port_start = ata_port_start, 199 .port_start = ata_port_start,
198 .port_stop = ata_port_stop,
199 .host_stop = ata_host_stop
200}; 200};
201 201
202/* 202/*
@@ -257,31 +257,33 @@ static void pdc_data_xfer_vlb(struct ata_device *adev, unsigned char *buf, unsig
257 local_irq_save(flags); 257 local_irq_save(flags);
258 258
259 /* Perform the 32bit I/O synchronization sequence */ 259 /* Perform the 32bit I/O synchronization sequence */
260 inb(ap->ioaddr.nsect_addr); 260 ioread8(ap->ioaddr.nsect_addr);
261 inb(ap->ioaddr.nsect_addr); 261 ioread8(ap->ioaddr.nsect_addr);
262 inb(ap->ioaddr.nsect_addr); 262 ioread8(ap->ioaddr.nsect_addr);
263 263
264 /* Now the data */ 264 /* Now the data */
265 265
266 if (write_data) 266 if (write_data)
267 outsl(ap->ioaddr.data_addr, buf, buflen >> 2); 267 iowrite32_rep(ap->ioaddr.data_addr, buf, buflen >> 2);
268 else 268 else
269 insl(ap->ioaddr.data_addr, buf, buflen >> 2); 269 ioread32_rep(ap->ioaddr.data_addr, buf, buflen >> 2);
270 270
271 if (unlikely(slop)) { 271 if (unlikely(slop)) {
272 u32 pad; 272 u32 pad;
273 if (write_data) { 273 if (write_data) {
274 memcpy(&pad, buf + buflen - slop, slop); 274 memcpy(&pad, buf + buflen - slop, slop);
275 outl(le32_to_cpu(pad), ap->ioaddr.data_addr); 275 pad = le32_to_cpu(pad);
276 iowrite32(pad, ap->ioaddr.data_addr);
276 } else { 277 } else {
277 pad = cpu_to_le16(inl(ap->ioaddr.data_addr)); 278 pad = ioread32(ap->ioaddr.data_addr);
279 pad = cpu_to_le16(pad);
278 memcpy(buf + buflen - slop, &pad, slop); 280 memcpy(buf + buflen - slop, &pad, slop);
279 } 281 }
280 } 282 }
281 local_irq_restore(flags); 283 local_irq_restore(flags);
282 } 284 }
283 else 285 else
284 ata_pio_data_xfer_noirq(adev, buf, buflen, write_data); 286 ata_data_xfer_noirq(adev, buf, buflen, write_data);
285} 287}
286 288
287static struct ata_port_operations pdc20230_port_ops = { 289static struct ata_port_operations pdc20230_port_ops = {
@@ -303,10 +305,10 @@ static struct ata_port_operations pdc20230_port_ops = {
303 305
304 .irq_handler = ata_interrupt, 306 .irq_handler = ata_interrupt,
305 .irq_clear = ata_bmdma_irq_clear, 307 .irq_clear = ata_bmdma_irq_clear,
308 .irq_on = ata_irq_on,
309 .irq_ack = ata_irq_ack,
306 310
307 .port_start = ata_port_start, 311 .port_start = ata_port_start,
308 .port_stop = ata_port_stop,
309 .host_stop = ata_host_stop
310}; 312};
311 313
312/* 314/*
@@ -332,8 +334,8 @@ static void ht6560a_set_piomode(struct ata_port *ap, struct ata_device *adev)
332 inb(0x3E6); 334 inb(0x3E6);
333 inb(0x3E6); 335 inb(0x3E6);
334 336
335 outb(recover << 4 | active, ap->ioaddr.device_addr); 337 iowrite8(recover << 4 | active, ap->ioaddr.device_addr);
336 inb(ap->ioaddr.status_addr); 338 ioread8(ap->ioaddr.status_addr);
337} 339}
338 340
339static struct ata_port_operations ht6560a_port_ops = { 341static struct ata_port_operations ht6560a_port_ops = {
@@ -351,14 +353,14 @@ static struct ata_port_operations ht6560a_port_ops = {
351 .qc_prep = ata_qc_prep, 353 .qc_prep = ata_qc_prep,
352 .qc_issue = ata_qc_issue_prot, 354 .qc_issue = ata_qc_issue_prot,
353 355
354 .data_xfer = ata_pio_data_xfer, /* Check vlb/noirq */ 356 .data_xfer = ata_data_xfer, /* Check vlb/noirq */
355 357
356 .irq_handler = ata_interrupt, 358 .irq_handler = ata_interrupt,
357 .irq_clear = ata_bmdma_irq_clear, 359 .irq_clear = ata_bmdma_irq_clear,
360 .irq_on = ata_irq_on,
361 .irq_ack = ata_irq_ack,
358 362
359 .port_start = ata_port_start, 363 .port_start = ata_port_start,
360 .port_stop = ata_port_stop,
361 .host_stop = ata_host_stop
362}; 364};
363 365
364/* 366/*
@@ -387,7 +389,7 @@ static void ht6560b_set_piomode(struct ata_port *ap, struct ata_device *adev)
387 inb(0x3E6); 389 inb(0x3E6);
388 inb(0x3E6); 390 inb(0x3E6);
389 391
390 outb(recover << 4 | active, ap->ioaddr.device_addr); 392 iowrite8(recover << 4 | active, ap->ioaddr.device_addr);
391 393
392 if (adev->class != ATA_DEV_ATA) { 394 if (adev->class != ATA_DEV_ATA) {
393 u8 rconf = inb(0x3E6); 395 u8 rconf = inb(0x3E6);
@@ -396,7 +398,7 @@ static void ht6560b_set_piomode(struct ata_port *ap, struct ata_device *adev)
396 outb(rconf, 0x3E6); 398 outb(rconf, 0x3E6);
397 } 399 }
398 } 400 }
399 inb(ap->ioaddr.status_addr); 401 ioread8(ap->ioaddr.status_addr);
400} 402}
401 403
402static struct ata_port_operations ht6560b_port_ops = { 404static struct ata_port_operations ht6560b_port_ops = {
@@ -414,14 +416,14 @@ static struct ata_port_operations ht6560b_port_ops = {
414 .qc_prep = ata_qc_prep, 416 .qc_prep = ata_qc_prep,
415 .qc_issue = ata_qc_issue_prot, 417 .qc_issue = ata_qc_issue_prot,
416 418
417 .data_xfer = ata_pio_data_xfer, /* FIXME: Check 32bit and noirq */ 419 .data_xfer = ata_data_xfer, /* FIXME: Check 32bit and noirq */
418 420
419 .irq_handler = ata_interrupt, 421 .irq_handler = ata_interrupt,
420 .irq_clear = ata_bmdma_irq_clear, 422 .irq_clear = ata_bmdma_irq_clear,
423 .irq_on = ata_irq_on,
424 .irq_ack = ata_irq_ack,
421 425
422 .port_start = ata_port_start, 426 .port_start = ata_port_start,
423 .port_stop = ata_port_stop,
424 .host_stop = ata_host_stop
425}; 427};
426 428
427/* 429/*
@@ -464,12 +466,12 @@ static void opti82c611a_set_piomode(struct ata_port *ap, struct ata_device *adev
464 u8 rc; 466 u8 rc;
465 467
466 /* Enter configuration mode */ 468 /* Enter configuration mode */
467 inw(ap->ioaddr.error_addr); 469 ioread16(ap->ioaddr.error_addr);
468 inw(ap->ioaddr.error_addr); 470 ioread16(ap->ioaddr.error_addr);
469 outb(3, ap->ioaddr.nsect_addr); 471 iowrite8(3, ap->ioaddr.nsect_addr);
470 472
471 /* Read VLB clock strapping */ 473 /* Read VLB clock strapping */
472 clock = 1000000000 / khz[inb(ap->ioaddr.lbah_addr) & 0x03]; 474 clock = 1000000000 / khz[ioread8(ap->ioaddr.lbah_addr) & 0x03];
473 475
474 /* Get the timing data in cycles */ 476 /* Get the timing data in cycles */
475 ata_timing_compute(adev, adev->pio_mode, &t, clock, 1000); 477 ata_timing_compute(adev, adev->pio_mode, &t, clock, 1000);
@@ -487,33 +489,33 @@ static void opti82c611a_set_piomode(struct ata_port *ap, struct ata_device *adev
487 setup = FIT(t.setup, 1, 4) - 1; 489 setup = FIT(t.setup, 1, 4) - 1;
488 490
489 /* Select the right timing bank for write timing */ 491 /* Select the right timing bank for write timing */
490 rc = inb(ap->ioaddr.lbal_addr); 492 rc = ioread8(ap->ioaddr.lbal_addr);
491 rc &= 0x7F; 493 rc &= 0x7F;
492 rc |= (adev->devno << 7); 494 rc |= (adev->devno << 7);
493 outb(rc, ap->ioaddr.lbal_addr); 495 iowrite8(rc, ap->ioaddr.lbal_addr);
494 496
495 /* Write the timings */ 497 /* Write the timings */
496 outb(active << 4 | recover, ap->ioaddr.error_addr); 498 iowrite8(active << 4 | recover, ap->ioaddr.error_addr);
497 499
498 /* Select the right bank for read timings, also 500 /* Select the right bank for read timings, also
499 load the shared timings for address */ 501 load the shared timings for address */
500 rc = inb(ap->ioaddr.device_addr); 502 rc = ioread8(ap->ioaddr.device_addr);
501 rc &= 0xC0; 503 rc &= 0xC0;
502 rc |= adev->devno; /* Index select */ 504 rc |= adev->devno; /* Index select */
503 rc |= (setup << 4) | 0x04; 505 rc |= (setup << 4) | 0x04;
504 outb(rc, ap->ioaddr.device_addr); 506 iowrite8(rc, ap->ioaddr.device_addr);
505 507
506 /* Load the read timings */ 508 /* Load the read timings */
507 outb(active << 4 | recover, ap->ioaddr.data_addr); 509 iowrite8(active << 4 | recover, ap->ioaddr.data_addr);
508 510
509 /* Ensure the timing register mode is right */ 511 /* Ensure the timing register mode is right */
510 rc = inb (ap->ioaddr.lbal_addr); 512 rc = ioread8(ap->ioaddr.lbal_addr);
511 rc &= 0x73; 513 rc &= 0x73;
512 rc |= 0x84; 514 rc |= 0x84;
513 outb(rc, ap->ioaddr.lbal_addr); 515 iowrite8(rc, ap->ioaddr.lbal_addr);
514 516
515 /* Exit command mode */ 517 /* Exit command mode */
516 outb(0x83, ap->ioaddr.nsect_addr); 518 iowrite8(0x83, ap->ioaddr.nsect_addr);
517} 519}
518 520
519 521
@@ -532,14 +534,14 @@ static struct ata_port_operations opti82c611a_port_ops = {
532 .qc_prep = ata_qc_prep, 534 .qc_prep = ata_qc_prep,
533 .qc_issue = ata_qc_issue_prot, 535 .qc_issue = ata_qc_issue_prot,
534 536
535 .data_xfer = ata_pio_data_xfer, 537 .data_xfer = ata_data_xfer,
536 538
537 .irq_handler = ata_interrupt, 539 .irq_handler = ata_interrupt,
538 .irq_clear = ata_bmdma_irq_clear, 540 .irq_clear = ata_bmdma_irq_clear,
541 .irq_on = ata_irq_on,
542 .irq_ack = ata_irq_ack,
539 543
540 .port_start = ata_port_start, 544 .port_start = ata_port_start,
541 .port_stop = ata_port_stop,
542 .host_stop = ata_host_stop
543}; 545};
544 546
545/* 547/*
@@ -563,9 +565,9 @@ static void opti82c46x_set_piomode(struct ata_port *ap, struct ata_device *adev)
563 sysclk = opti_syscfg(0xAC) & 0xC0; /* BIOS set */ 565 sysclk = opti_syscfg(0xAC) & 0xC0; /* BIOS set */
564 566
565 /* Enter configuration mode */ 567 /* Enter configuration mode */
566 inw(ap->ioaddr.error_addr); 568 ioread16(ap->ioaddr.error_addr);
567 inw(ap->ioaddr.error_addr); 569 ioread16(ap->ioaddr.error_addr);
568 outb(3, ap->ioaddr.nsect_addr); 570 iowrite8(3, ap->ioaddr.nsect_addr);
569 571
570 /* Read VLB clock strapping */ 572 /* Read VLB clock strapping */
571 clock = 1000000000 / khz[sysclk]; 573 clock = 1000000000 / khz[sysclk];
@@ -586,33 +588,33 @@ static void opti82c46x_set_piomode(struct ata_port *ap, struct ata_device *adev)
586 setup = FIT(t.setup, 1, 4) - 1; 588 setup = FIT(t.setup, 1, 4) - 1;
587 589
588 /* Select the right timing bank for write timing */ 590 /* Select the right timing bank for write timing */
589 rc = inb(ap->ioaddr.lbal_addr); 591 rc = ioread8(ap->ioaddr.lbal_addr);
590 rc &= 0x7F; 592 rc &= 0x7F;
591 rc |= (adev->devno << 7); 593 rc |= (adev->devno << 7);
592 outb(rc, ap->ioaddr.lbal_addr); 594 iowrite8(rc, ap->ioaddr.lbal_addr);
593 595
594 /* Write the timings */ 596 /* Write the timings */
595 outb(active << 4 | recover, ap->ioaddr.error_addr); 597 iowrite8(active << 4 | recover, ap->ioaddr.error_addr);
596 598
597 /* Select the right bank for read timings, also 599 /* Select the right bank for read timings, also
598 load the shared timings for address */ 600 load the shared timings for address */
599 rc = inb(ap->ioaddr.device_addr); 601 rc = ioread8(ap->ioaddr.device_addr);
600 rc &= 0xC0; 602 rc &= 0xC0;
601 rc |= adev->devno; /* Index select */ 603 rc |= adev->devno; /* Index select */
602 rc |= (setup << 4) | 0x04; 604 rc |= (setup << 4) | 0x04;
603 outb(rc, ap->ioaddr.device_addr); 605 iowrite8(rc, ap->ioaddr.device_addr);
604 606
605 /* Load the read timings */ 607 /* Load the read timings */
606 outb(active << 4 | recover, ap->ioaddr.data_addr); 608 iowrite8(active << 4 | recover, ap->ioaddr.data_addr);
607 609
608 /* Ensure the timing register mode is right */ 610 /* Ensure the timing register mode is right */
609 rc = inb (ap->ioaddr.lbal_addr); 611 rc = ioread8(ap->ioaddr.lbal_addr);
610 rc &= 0x73; 612 rc &= 0x73;
611 rc |= 0x84; 613 rc |= 0x84;
612 outb(rc, ap->ioaddr.lbal_addr); 614 iowrite8(rc, ap->ioaddr.lbal_addr);
613 615
614 /* Exit command mode */ 616 /* Exit command mode */
615 outb(0x83, ap->ioaddr.nsect_addr); 617 iowrite8(0x83, ap->ioaddr.nsect_addr);
616 618
617 /* We need to know this for quad device on the MVB */ 619 /* We need to know this for quad device on the MVB */
618 ap->host->private_data = ap; 620 ap->host->private_data = ap;
@@ -662,14 +664,14 @@ static struct ata_port_operations opti82c46x_port_ops = {
662 .qc_prep = ata_qc_prep, 664 .qc_prep = ata_qc_prep,
663 .qc_issue = opti82c46x_qc_issue_prot, 665 .qc_issue = opti82c46x_qc_issue_prot,
664 666
665 .data_xfer = ata_pio_data_xfer, 667 .data_xfer = ata_data_xfer,
666 668
667 .irq_handler = ata_interrupt, 669 .irq_handler = ata_interrupt,
668 .irq_clear = ata_bmdma_irq_clear, 670 .irq_clear = ata_bmdma_irq_clear,
671 .irq_on = ata_irq_on,
672 .irq_ack = ata_irq_ack,
669 673
670 .port_start = ata_port_start, 674 .port_start = ata_port_start,
671 .port_stop = ata_port_stop,
672 .host_stop = ata_host_stop
673}; 675};
674 676
675 677
@@ -689,21 +691,26 @@ static __init int legacy_init_one(int port, unsigned long io, unsigned long ctrl
689 struct legacy_data *ld = &legacy_data[nr_legacy_host]; 691 struct legacy_data *ld = &legacy_data[nr_legacy_host];
690 struct ata_probe_ent ae; 692 struct ata_probe_ent ae;
691 struct platform_device *pdev; 693 struct platform_device *pdev;
692 int ret = -EBUSY;
693 struct ata_port_operations *ops = &legacy_port_ops; 694 struct ata_port_operations *ops = &legacy_port_ops;
695 void __iomem *io_addr, *ctrl_addr;
694 int pio_modes = pio_mask; 696 int pio_modes = pio_mask;
695 u32 mask = (1 << port); 697 u32 mask = (1 << port);
696 698 int ret;
697 if (request_region(io, 8, "pata_legacy") == NULL)
698 return -EBUSY;
699 if (request_region(ctrl, 1, "pata_legacy") == NULL)
700 goto fail_io;
701 699
702 pdev = platform_device_register_simple(DRV_NAME, nr_legacy_host, NULL, 0); 700 pdev = platform_device_register_simple(DRV_NAME, nr_legacy_host, NULL, 0);
703 if (IS_ERR(pdev)) { 701 if (IS_ERR(pdev))
704 ret = PTR_ERR(pdev); 702 return PTR_ERR(pdev);
705 goto fail_dev; 703
706 } 704 ret = -EBUSY;
705 if (devm_request_region(&pdev->dev, io, 8, "pata_legacy") == NULL ||
706 devm_request_region(&pdev->dev, ctrl, 1, "pata_legacy") == NULL)
707 goto fail;
708
709 ret = -ENOMEM;
710 io_addr = devm_ioport_map(&pdev->dev, io, 8);
711 ctrl_addr = devm_ioport_map(&pdev->dev, ctrl, 1);
712 if (!io_addr || !ctrl_addr)
713 goto fail;
707 714
708 if (ht6560a & mask) { 715 if (ht6560a & mask) {
709 ops = &ht6560a_port_ops; 716 ops = &ht6560a_port_ops;
@@ -770,27 +777,22 @@ static __init int legacy_init_one(int port, unsigned long io, unsigned long ctrl
770 ae.irq = irq; 777 ae.irq = irq;
771 ae.irq_flags = 0; 778 ae.irq_flags = 0;
772 ae.port_flags = ATA_FLAG_SLAVE_POSS|ATA_FLAG_SRST; 779 ae.port_flags = ATA_FLAG_SLAVE_POSS|ATA_FLAG_SRST;
773 ae.port[0].cmd_addr = io; 780 ae.port[0].cmd_addr = io_addr;
774 ae.port[0].altstatus_addr = ctrl; 781 ae.port[0].altstatus_addr = ctrl_addr;
775 ae.port[0].ctl_addr = ctrl; 782 ae.port[0].ctl_addr = ctrl_addr;
776 ata_std_ports(&ae.port[0]); 783 ata_std_ports(&ae.port[0]);
777 ae.private_data = ld; 784 ae.private_data = ld;
778 785
779 ret = ata_device_add(&ae); 786 ret = -ENODEV;
780 if (ret == 0) { 787 if (!ata_device_add(&ae))
781 ret = -ENODEV;
782 goto fail; 788 goto fail;
783 } 789
784 legacy_host[nr_legacy_host++] = dev_get_drvdata(&pdev->dev); 790 legacy_host[nr_legacy_host++] = dev_get_drvdata(&pdev->dev);
785 ld->platform_dev = pdev; 791 ld->platform_dev = pdev;
786 return 0; 792 return 0;
787 793
788fail: 794fail:
789 platform_device_unregister(pdev); 795 platform_device_unregister(pdev);
790fail_dev:
791 release_region(ctrl, 1);
792fail_io:
793 release_region(io, 8);
794 return ret; 796 return ret;
795} 797}
796 798
@@ -923,15 +925,11 @@ static __exit void legacy_exit(void)
923 925
924 for (i = 0; i < nr_legacy_host; i++) { 926 for (i = 0; i < nr_legacy_host; i++) {
925 struct legacy_data *ld = &legacy_data[i]; 927 struct legacy_data *ld = &legacy_data[i];
926 struct ata_port *ap =legacy_host[i]->ports[0]; 928
927 unsigned long io = ap->ioaddr.cmd_addr; 929 ata_host_detach(legacy_host[i]);
928 unsigned long ctrl = ap->ioaddr.ctl_addr;
929 ata_host_remove(legacy_host[i]);
930 platform_device_unregister(ld->platform_dev); 930 platform_device_unregister(ld->platform_dev);
931 if (ld->timing) 931 if (ld->timing)
932 release_region(ld->timing, 2); 932 release_region(ld->timing, 2);
933 release_region(io, 8);
934 release_region(ctrl, 1);
935 } 933 }
936} 934}
937 935