Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

[ARM] ecard: add ecardm_iomap() / ecardm_iounmap()

Add devres ecardm_iomap() and ecardm_iounmap() for Acorn expansion
cards. Convert all expansion card drivers to use them.

Signed-off-by: Russell King <rmk+kernel@arm.linux.org.uk>

authored by

Russell King and committed by
Russell King
10bdaaa0 c7b87f3d

+53 -118
+18 -1
arch/arm/kernel/ecard.c
··· 41 41 #include <linux/init.h> 42 42 #include <linux/mutex.h> 43 43 #include <linux/kthread.h> 44 + #include <linux/io.h> 44 45 45 46 #include <asm/dma.h> 46 47 #include <asm/ecard.h> 47 48 #include <asm/hardware.h> 48 - #include <asm/io.h> 49 49 #include <asm/irq.h> 50 50 #include <asm/mmu_context.h> 51 51 #include <asm/mach/irq.h> ··· 965 965 ec->ops = ops; 966 966 } 967 967 EXPORT_SYMBOL(ecard_setirq); 968 + 969 + void __iomem *ecardm_iomap(struct expansion_card *ec, unsigned int res, 970 + unsigned long offset, unsigned long maxsize) 971 + { 972 + unsigned long start = ecard_resource_start(ec, res); 973 + unsigned long end = ecard_resource_end(ec, res); 974 + 975 + if (offset > (end - start)) 976 + return NULL; 977 + 978 + start += offset; 979 + if (maxsize && end - start > maxsize) 980 + end = start + maxsize; 981 + 982 + return devm_ioremap(&ec->dev, start, end - start); 983 + } 984 + EXPORT_SYMBOL(ecardm_iomap); 968 985 969 986 /* 970 987 * Probe for an expansion card.
+9 -26
drivers/ata/pata_icside.c
··· 425 425 struct pata_icside_state *state = ae->private_data; 426 426 void __iomem *base; 427 427 428 - base = ioremap(ecard_resource_start(ec, ECARD_RES_MEMC), 429 - ecard_resource_len(ec, ECARD_RES_MEMC)); 428 + base = ecardm_iomap(info->ec, ECARD_RES_MEMC, 0, 0); 430 429 if (!base) 431 430 return -ENOMEM; 432 431 ··· 452 453 struct pata_icside_state *state = ae->private_data; 453 454 void __iomem *ioc_base, *easi_base; 454 455 unsigned int sel = 0; 455 - int ret; 456 456 457 - ioc_base = ioremap(ecard_resource_start(ec, ECARD_RES_IOCFAST), 458 - ecard_resource_len(ec, ECARD_RES_IOCFAST)); 459 - if (!ioc_base) { 460 - ret = -ENOMEM; 461 - goto out; 462 - } 457 + ioc_base = ecardm_iomap(ec, ECARD_RES_IOCFAST, 0, 0); 458 + if (!ioc_base) 459 + return -ENOMEM; 463 460 464 461 easi_base = ioc_base; 465 462 466 463 if (ecard_resource_flags(ec, ECARD_RES_EASI)) { 467 - easi_base = ioremap(ecard_resource_start(ec, ECARD_RES_EASI), 468 - ecard_resource_len(ec, ECARD_RES_EASI)); 469 - if (!easi_base) { 470 - ret = -ENOMEM; 471 - goto unmap_slot; 472 - } 464 + easi_base = ecardm_iomap(ec, ECARD_RES_EASI, 0, 0); 465 + if (!easi_base) 466 + return -ENOMEM; 473 467 474 468 /* 475 469 * Enable access to the EASI region. ··· 499 507 500 508 return icside_dma_init(ae, ec); 501 509 502 - unmap_slot: 503 - iounmap(ioc_base); 504 - out: 505 - return ret; 506 510 } 507 511 508 512 static int __devinit ··· 522 534 state->type = ICS_TYPE_NOTYPE; 523 535 state->dma = NO_DMA; 524 536 525 - idmem = ioremap(ecard_resource_start(ec, ECARD_RES_IOCFAST), 526 - ecard_resource_len(ec, ECARD_RES_IOCFAST)); 537 + idmem = ecardm_iomap(ec, ECARD_RES_IOCFAST, 0, 0); 527 538 if (idmem) { 528 539 unsigned int type; 529 540 ··· 530 543 type |= (readb(idmem + ICS_IDENT_OFFSET + 4) & 1) << 1; 531 544 type |= (readb(idmem + ICS_IDENT_OFFSET + 8) & 1) << 2; 532 545 type |= (readb(idmem + ICS_IDENT_OFFSET + 12) & 1) << 3; 533 - iounmap(idmem); 546 + ecardm_iounmap(ec, idmem); 534 547 535 548 state->type = type; 536 549 } ··· 625 638 */ 626 639 if (state->dma != NO_DMA) 627 640 free_dma(state->dma); 628 - if (state->ioc_base) 629 - iounmap(state->ioc_base); 630 - if (state->ioc_base != state->irq_port) 631 - iounmap(state->irq_port); 632 641 633 642 kfree(state); 634 643 ecard_release_resources(ec);
+8 -24
drivers/ide/arm/icside.c
··· 565 565 ide_hwif_t *hwif; 566 566 void __iomem *base; 567 567 568 - base = ioremap(ecard_resource_start(ec, ECARD_RES_MEMC), 569 - ecard_resource_len(ec, ECARD_RES_MEMC)); 568 + base = ecardm_iomap(ec, ECARD_RES_MEMC, 0, 0); 570 569 if (!base) 571 570 return -ENOMEM; 572 571 ··· 582 583 icside_irqdisable_arcin_v5(ec, 0); 583 584 584 585 hwif = icside_setup(base, &icside_cardinfo_v5, ec); 585 - if (!hwif) { 586 - iounmap(base); 586 + if (!hwif) 587 587 return -ENODEV; 588 - } 589 588 590 589 state->hwif[0] = hwif; 591 590 ··· 602 605 unsigned int sel = 0; 603 606 int ret; 604 607 605 - ioc_base = ioremap(ecard_resource_start(ec, ECARD_RES_IOCFAST), 606 - ecard_resource_len(ec, ECARD_RES_IOCFAST)); 608 + ioc_base = ecardm_iomap(ec, ECARD_RES_IOCFAST, 0, 0); 607 609 if (!ioc_base) { 608 610 ret = -ENOMEM; 609 611 goto out; ··· 611 615 easi_base = ioc_base; 612 616 613 617 if (ecard_resource_flags(ec, ECARD_RES_EASI)) { 614 - easi_base = ioremap(ecard_resource_start(ec, ECARD_RES_EASI), 615 - ecard_resource_len(ec, ECARD_RES_EASI)); 618 + easi_base = ecardm_iomap(ec, ECARD_RES_EASI, 0, 0); 616 619 if (!easi_base) { 617 620 ret = -ENOMEM; 618 - goto unmap_slot; 621 + goto out; 619 622 } 620 623 621 624 /* ··· 643 648 644 649 if (!hwif || !mate) { 645 650 ret = -ENODEV; 646 - goto unmap_port; 651 + goto out; 647 652 } 648 653 649 654 state->hwif[0] = hwif; ··· 680 685 681 686 return 0; 682 687 683 - unmap_port: 684 - if (easi_base != ioc_base) 685 - iounmap(easi_base); 686 - unmap_slot: 687 - iounmap(ioc_base); 688 688 out: 689 689 return ret; 690 690 } ··· 705 715 state->type = ICS_TYPE_NOTYPE; 706 716 state->dev = &ec->dev; 707 717 708 - idmem = ioremap(ecard_resource_start(ec, ECARD_RES_IOCFAST), 709 - ecard_resource_len(ec, ECARD_RES_IOCFAST)); 718 + idmem = ecardm_iomap(ec, ECARD_RES_IOCFAST, 0, 0); 710 719 if (idmem) { 711 720 unsigned int type; 712 721 ··· 713 724 type |= (readb(idmem + ICS_IDENT_OFFSET + 4) & 1) << 1; 714 725 type |= (readb(idmem + ICS_IDENT_OFFSET + 8) & 1) << 2; 715 726 type |= (readb(idmem + ICS_IDENT_OFFSET + 12) & 1) << 3; 716 - iounmap(idmem); 727 + ecardm_iounmap(ec, idmem); 717 728 718 729 state->type = type; 719 730 } ··· 781 792 } 782 793 783 794 ecard_set_drvdata(ec, NULL); 784 - 785 - if (state->ioc_base) 786 - iounmap(state->ioc_base); 787 - if (state->ioc_base != state->irq_port) 788 - iounmap(state->irq_port); 789 795 790 796 kfree(state); 791 797 ecard_release_resources(ec);
+1 -4
drivers/ide/arm/rapide.c
··· 63 63 if (ret) 64 64 goto out; 65 65 66 - base = ioremap(ecard_resource_start(ec, ECARD_RES_MEMC), 67 - ecard_resource_len(ec, ECARD_RES_MEMC)); 66 + base = ecardm_iomap(ec, ECARD_RES_MEMC, 0, 0); 68 67 if (!base) { 69 68 ret = -ENOMEM; 70 69 goto release; ··· 80 81 goto out; 81 82 } 82 83 83 - iounmap(base); 84 84 release: 85 85 ecard_release_resources(ec); 86 86 out: ··· 94 96 95 97 /* there must be a better way */ 96 98 ide_unregister(hwif - ide_hwifs); 97 - iounmap(hwif->hwif_data); 98 99 ecard_release_resources(ec); 99 100 } 100 101
+1 -5
drivers/net/arm/ether1.c
··· 1014 1014 SET_NETDEV_DEV(dev, &ec->dev); 1015 1015 1016 1016 dev->irq = ec->irq; 1017 - priv(dev)->base = ioremap(ecard_resource_start(ec, ECARD_RES_IOCFAST), 1018 - ecard_resource_len(ec, ECARD_RES_IOCFAST)); 1017 + priv(dev)->base = ecardm_iomap(ec, ECARD_RES_IOCFAST, 0, 0); 1019 1018 if (!priv(dev)->base) { 1020 1019 ret = -ENOMEM; 1021 1020 goto free; ··· 1055 1056 return 0; 1056 1057 1057 1058 free: 1058 - if (priv(dev)->base) 1059 - iounmap(priv(dev)->base); 1060 1059 free_netdev(dev); 1061 1060 release: 1062 1061 ecard_release_resources(ec); ··· 1069 1072 ecard_set_drvdata(ec, NULL); 1070 1073 1071 1074 unregister_netdev(dev); 1072 - iounmap(priv(dev)->base); 1073 1075 free_netdev(dev); 1074 1076 ecard_release_resources(ec); 1075 1077 }
+1 -5
drivers/net/arm/ether3.c
··· 793 793 SET_MODULE_OWNER(dev); 794 794 SET_NETDEV_DEV(dev, &ec->dev); 795 795 796 - priv(dev)->base = ioremap(ecard_resource_start(ec, ECARD_RES_MEMC), 797 - ecard_resource_len(ec, ECARD_RES_MEMC)); 796 + priv(dev)->base = ecardm_iomap(ec, ECARD_RES_MEMC, 0, 0); 798 797 if (!priv(dev)->base) { 799 798 ret = -ENOMEM; 800 799 goto free; ··· 868 869 return 0; 869 870 870 871 free: 871 - if (priv(dev)->base) 872 - iounmap(priv(dev)->base); 873 872 free_netdev(dev); 874 873 release: 875 874 ecard_release_resources(ec); ··· 882 885 ecard_set_drvdata(ec, NULL); 883 886 884 887 unregister_netdev(dev); 885 - iounmap(priv(dev)->base); 886 888 free_netdev(dev); 887 889 ecard_release_resources(ec); 888 890 }
+2 -11
drivers/net/arm/etherh.c
··· 686 686 eh->supported = data->supported; 687 687 eh->ctrl = 0; 688 688 eh->id = ec->cid.product; 689 - eh->memc = ioremap(ecard_resource_start(ec, ECARD_RES_MEMC), PAGE_SIZE); 689 + eh->memc = ecardm_iomap(ec, ECARD_RES_MEMC, 0, PAGE_SIZE); 690 690 if (!eh->memc) { 691 691 ret = -ENOMEM; 692 692 goto free; ··· 694 694 695 695 eh->ctrl_port = eh->memc; 696 696 if (data->ctrl_ioc) { 697 - eh->ioc_fast = ioremap(ecard_resource_start(ec, ECARD_RES_IOCFAST), PAGE_SIZE); 697 + eh->ioc_fast = ecardm_iomap(ec, ECARD_RES_IOCFAST, 0, PAGE_SIZE); 698 698 if (!eh->ioc_fast) { 699 699 ret = -ENOMEM; 700 700 goto free; ··· 758 758 return 0; 759 759 760 760 free: 761 - if (eh->ioc_fast) 762 - iounmap(eh->ioc_fast); 763 - if (eh->memc) 764 - iounmap(eh->memc); 765 761 free_netdev(dev); 766 762 release: 767 763 ecard_release_resources(ec); ··· 768 772 static void __devexit etherh_remove(struct expansion_card *ec) 769 773 { 770 774 struct net_device *dev = ecard_get_drvdata(ec); 771 - struct etherh_priv *eh = etherh_priv(dev); 772 775 773 776 ecard_set_drvdata(ec, NULL); 774 777 775 778 unregister_netdev(dev); 776 - 777 - if (eh->ioc_fast) 778 - iounmap(eh->ioc_fast); 779 - iounmap(eh->memc); 780 779 781 780 free_netdev(dev); 782 781
+2 -10
drivers/scsi/arm/arxescsi.c
··· 281 281 { 282 282 struct Scsi_Host *host; 283 283 struct arxescsi_info *info; 284 - unsigned long resbase, reslen; 285 284 void __iomem *base; 286 285 int ret; 287 286 ··· 288 289 if (ret) 289 290 goto out; 290 291 291 - resbase = ecard_resource_start(ec, ECARD_RES_MEMC); 292 - reslen = ecard_resource_len(ec, ECARD_RES_MEMC); 293 - base = ioremap(resbase, reslen); 292 + base = ecardm_iomap(ec, ECARD_RES_MEMC, 0, 0); 294 293 if (!base) { 295 294 ret = -ENOMEM; 296 295 goto out_region; ··· 297 300 host = scsi_host_alloc(&arxescsi_template, sizeof(struct arxescsi_info)); 298 301 if (!host) { 299 302 ret = -ENOMEM; 300 - goto out_unmap; 303 + goto out_region; 301 304 } 302 305 303 306 info = (struct arxescsi_info *)host->hostdata; ··· 334 337 fas216_release(host); 335 338 out_unregister: 336 339 scsi_host_put(host); 337 - out_unmap: 338 - iounmap(base); 339 340 out_region: 340 341 ecard_release_resources(ec); 341 342 out: ··· 343 348 static void __devexit arxescsi_remove(struct expansion_card *ec) 344 349 { 345 350 struct Scsi_Host *host = ecard_get_drvdata(ec); 346 - struct arxescsi_info *info = (struct arxescsi_info *)host->hostdata; 347 351 348 352 ecard_set_drvdata(ec, NULL); 349 353 fas216_remove(host); 350 - 351 - iounmap(info->base); 352 354 353 355 fas216_release(host); 354 356 scsi_host_put(host);
+2 -10
drivers/scsi/arm/cumana_2.c
··· 401 401 { 402 402 struct Scsi_Host *host; 403 403 struct cumanascsi2_info *info; 404 - unsigned long resbase, reslen; 405 404 void __iomem *base; 406 405 int ret; 407 406 ··· 408 409 if (ret) 409 410 goto out; 410 411 411 - resbase = ecard_resource_start(ec, ECARD_RES_MEMC); 412 - reslen = ecard_resource_len(ec, ECARD_RES_MEMC); 413 - base = ioremap(resbase, reslen); 412 + base = ecardm_iomap(ec, ECARD_RES_MEMC, 0, 0); 414 413 if (!base) { 415 414 ret = -ENOMEM; 416 415 goto out_region; ··· 418 421 sizeof(struct cumanascsi2_info)); 419 422 if (!host) { 420 423 ret = -ENOMEM; 421 - goto out_unmap; 424 + goto out_region; 422 425 } 423 426 424 427 ecard_set_drvdata(ec, host); ··· 487 490 out_free: 488 491 scsi_host_put(host); 489 492 490 - out_unmap: 491 - iounmap(base); 492 - 493 493 out_region: 494 494 ecard_release_resources(ec); 495 495 ··· 505 511 if (info->info.scsi.dma != NO_DMA) 506 512 free_dma(info->info.scsi.dma); 507 513 free_irq(ec->irq, info); 508 - 509 - iounmap(info->base); 510 514 511 515 fas216_release(host); 512 516 scsi_host_put(host);
+2 -10
drivers/scsi/arm/eesox.c
··· 519 519 { 520 520 struct Scsi_Host *host; 521 521 struct eesoxscsi_info *info; 522 - unsigned long resbase, reslen; 523 522 void __iomem *base; 524 523 int ret; 525 524 ··· 526 527 if (ret) 527 528 goto out; 528 529 529 - resbase = ecard_resource_start(ec, ECARD_RES_IOCFAST); 530 - reslen = ecard_resource_len(ec, ECARD_RES_IOCFAST); 531 - base = ioremap(resbase, reslen); 530 + base = ecardm_iomap(ec, ECARD_RES_IOCFAST, 0, 0); 532 531 if (!base) { 533 532 ret = -ENOMEM; 534 533 goto out_region; ··· 536 539 sizeof(struct eesoxscsi_info)); 537 540 if (!host) { 538 541 ret = -ENOMEM; 539 - goto out_unmap; 542 + goto out_region; 540 543 } 541 544 542 545 ecard_set_drvdata(ec, host); ··· 609 612 device_remove_file(&ec->dev, &dev_attr_bus_term); 610 613 scsi_host_put(host); 611 614 612 - out_unmap: 613 - iounmap(base); 614 - 615 615 out_region: 616 616 ecard_release_resources(ec); 617 617 ··· 629 635 free_irq(ec->irq, info); 630 636 631 637 device_remove_file(&ec->dev, &dev_attr_bus_term); 632 - 633 - iounmap(info->base); 634 638 635 639 fas216_release(host); 636 640 scsi_host_put(host);
+2 -10
drivers/scsi/arm/powertec.c
··· 313 313 { 314 314 struct Scsi_Host *host; 315 315 struct powertec_info *info; 316 - unsigned long resbase, reslen; 317 316 void __iomem *base; 318 317 int ret; 319 318 ··· 320 321 if (ret) 321 322 goto out; 322 323 323 - resbase = ecard_resource_start(ec, ECARD_RES_IOCFAST); 324 - reslen = ecard_resource_len(ec, ECARD_RES_IOCFAST); 325 - base = ioremap(resbase, reslen); 324 + base = ecardm_iomap(ec, ECARD_RES_IOCFAST, 0, 0); 326 325 if (!base) { 327 326 ret = -ENOMEM; 328 327 goto out_region; ··· 330 333 sizeof (struct powertec_info)); 331 334 if (!host) { 332 335 ret = -ENOMEM; 333 - goto out_unmap; 336 + goto out_region; 334 337 } 335 338 336 339 ecard_set_drvdata(ec, host); ··· 401 404 device_remove_file(&ec->dev, &dev_attr_bus_term); 402 405 scsi_host_put(host); 403 406 404 - out_unmap: 405 - iounmap(base); 406 - 407 407 out_region: 408 408 ecard_release_resources(ec); 409 409 ··· 421 427 if (info->info.scsi.dma != NO_DMA) 422 428 free_dma(info->info.scsi.dma); 423 429 free_irq(ec->irq, info); 424 - 425 - iounmap(info->base); 426 430 427 431 fas216_release(host); 428 432 scsi_host_put(host);
+1 -2
drivers/serial/8250_acorn.c
··· 54 54 info->num_ports = type->num_ports; 55 55 56 56 bus_addr = ecard_resource_start(ec, type->type); 57 - info->vaddr = ioremap(bus_addr, ecard_resource_len(ec, type->type)); 57 + info->vaddr = ecardm_iomap(ec, type->type, 0, 0); 58 58 if (!info->vaddr) { 59 59 kfree(info); 60 60 return -ENOMEM; ··· 91 91 if (info->ports[i] > 0) 92 92 serial8250_unregister_port(info->ports[i]); 93 93 94 - iounmap(info->vaddr); 95 94 kfree(info); 96 95 } 97 96
+4
include/asm-arm/ecard.h
··· 226 226 extern int ecard_request_resources(struct expansion_card *ec); 227 227 extern void ecard_release_resources(struct expansion_card *ec); 228 228 229 + void __iomem *ecardm_iomap(struct expansion_card *ec, unsigned int res, 230 + unsigned long offset, unsigned long maxsize); 231 + #define ecardm_iounmap(__ec, __addr) devm_iounmap(&(__ec)->dev, __addr) 232 + 229 233 extern struct bus_type ecard_bus_type; 230 234 231 235 #define ECARD_DEV(_d) container_of((_d), struct expansion_card, dev)