diff options
author | Marc Kleine-Budde <mkl@pengutronix.de> | 2011-02-21 05:24:39 -0500 |
---|---|---|
committer | Marc Kleine-Budde <mkl@pengutronix.de> | 2011-02-21 07:17:41 -0500 |
commit | c9218c3a8231c0a67662d85266698f2f037cac20 (patch) | |
tree | 971c89a63f7b1edc6bbd5117c9b424606e976fb4 /drivers/net/ax88796.c | |
parent | a54dc58511644a22ae0d57d857e154cddf6d7926 (diff) |
ax88796: clean up probe and remove function
This way we can remove the struct resource pointers from the private data.
Signed-off-by: Marc Kleine-Budde <mkl@pengutronix.de>
Diffstat (limited to 'drivers/net/ax88796.c')
-rw-r--r-- | drivers/net/ax88796.c | 75 |
1 files changed, 31 insertions, 44 deletions
diff --git a/drivers/net/ax88796.c b/drivers/net/ax88796.c index fd289e52b2ec..e62d0ba891e8 100644 --- a/drivers/net/ax88796.c +++ b/drivers/net/ax88796.c | |||
@@ -87,8 +87,6 @@ struct ax_device { | |||
87 | 87 | ||
88 | u32 msg_enable; | 88 | u32 msg_enable; |
89 | void __iomem *map2; | 89 | void __iomem *map2; |
90 | struct resource *mem; | ||
91 | struct resource *mem2; | ||
92 | const struct ax_plat_data *plat; | 90 | const struct ax_plat_data *plat; |
93 | 91 | ||
94 | unsigned char running; | 92 | unsigned char running; |
@@ -794,25 +792,24 @@ static int ax_init_dev(struct net_device *dev) | |||
794 | return ret; | 792 | return ret; |
795 | } | 793 | } |
796 | 794 | ||
797 | static int ax_remove(struct platform_device *_dev) | 795 | static int ax_remove(struct platform_device *pdev) |
798 | { | 796 | { |
799 | struct net_device *dev = platform_get_drvdata(_dev); | 797 | struct net_device *dev = platform_get_drvdata(pdev); |
800 | struct ei_device *ei_local = netdev_priv(dev); | 798 | struct ei_device *ei_local = netdev_priv(dev); |
801 | struct ax_device *ax; | 799 | struct ax_device *ax = to_ax_dev(dev); |
802 | 800 | struct resource *mem; | |
803 | ax = to_ax_dev(dev); | ||
804 | 801 | ||
805 | unregister_netdev(dev); | 802 | unregister_netdev(dev); |
806 | free_irq(dev->irq, dev); | 803 | free_irq(dev->irq, dev); |
807 | 804 | ||
808 | iounmap(ei_local->mem); | 805 | iounmap(ei_local->mem); |
809 | release_resource(ax->mem); | 806 | mem = platform_get_resource(pdev, IORESOURCE_MEM, 0); |
810 | kfree(ax->mem); | 807 | release_mem_region(mem->start, resource_size(mem)); |
811 | 808 | ||
812 | if (ax->map2) { | 809 | if (ax->map2) { |
813 | iounmap(ax->map2); | 810 | iounmap(ax->map2); |
814 | release_resource(ax->mem2); | 811 | mem = platform_get_resource(pdev, IORESOURCE_MEM, 1); |
815 | kfree(ax->mem2); | 812 | release_mem_region(mem->start, resource_size(mem)); |
816 | } | 813 | } |
817 | 814 | ||
818 | free_netdev(dev); | 815 | free_netdev(dev); |
@@ -832,8 +829,8 @@ static int ax_probe(struct platform_device *pdev) | |||
832 | struct net_device *dev; | 829 | struct net_device *dev; |
833 | struct ei_device *ei_local; | 830 | struct ei_device *ei_local; |
834 | struct ax_device *ax; | 831 | struct ax_device *ax; |
835 | struct resource *res; | 832 | struct resource *irq, *mem, *mem2; |
836 | size_t size; | 833 | resource_size_t mem_size, mem2_size = 0; |
837 | int ret = 0; | 834 | int ret = 0; |
838 | 835 | ||
839 | dev = ax__alloc_ei_netdev(sizeof(struct ax_device)); | 836 | dev = ax__alloc_ei_netdev(sizeof(struct ax_device)); |
@@ -853,24 +850,24 @@ static int ax_probe(struct platform_device *pdev) | |||
853 | ei_local->rxcr_base = ax->plat->rcr_val; | 850 | ei_local->rxcr_base = ax->plat->rcr_val; |
854 | 851 | ||
855 | /* find the platform resources */ | 852 | /* find the platform resources */ |
856 | res = platform_get_resource(pdev, IORESOURCE_IRQ, 0); | 853 | irq = platform_get_resource(pdev, IORESOURCE_IRQ, 0); |
857 | if (res == NULL) { | 854 | if (!irq) { |
858 | dev_err(&pdev->dev, "no IRQ specified\n"); | 855 | dev_err(&pdev->dev, "no IRQ specified\n"); |
859 | ret = -ENXIO; | 856 | ret = -ENXIO; |
860 | goto exit_mem; | 857 | goto exit_mem; |
861 | } | 858 | } |
862 | 859 | ||
863 | dev->irq = res->start; | 860 | dev->irq = irq->start; |
864 | ax->irqflags = res->flags & IRQF_TRIGGER_MASK; | 861 | ax->irqflags = irq->flags & IRQF_TRIGGER_MASK; |
865 | 862 | ||
866 | res = platform_get_resource(pdev, IORESOURCE_MEM, 0); | 863 | mem = platform_get_resource(pdev, IORESOURCE_MEM, 0); |
867 | if (res == NULL) { | 864 | if (!mem) { |
868 | dev_err(&pdev->dev, "no MEM specified\n"); | 865 | dev_err(&pdev->dev, "no MEM specified\n"); |
869 | ret = -ENXIO; | 866 | ret = -ENXIO; |
870 | goto exit_mem; | 867 | goto exit_mem; |
871 | } | 868 | } |
872 | 869 | ||
873 | size = (res->end - res->start) + 1; | 870 | mem_size = resource_size(mem); |
874 | 871 | ||
875 | /* | 872 | /* |
876 | * setup the register offsets from either the platform data or | 873 | * setup the register offsets from either the platform data or |
@@ -881,50 +878,43 @@ static int ax_probe(struct platform_device *pdev) | |||
881 | else { | 878 | else { |
882 | ei_local->reg_offset = ax->reg_offsets; | 879 | ei_local->reg_offset = ax->reg_offsets; |
883 | for (ret = 0; ret < 0x18; ret++) | 880 | for (ret = 0; ret < 0x18; ret++) |
884 | ax->reg_offsets[ret] = (size / 0x18) * ret; | 881 | ax->reg_offsets[ret] = (mem_size / 0x18) * ret; |
885 | } | 882 | } |
886 | 883 | ||
887 | ax->mem = request_mem_region(res->start, size, pdev->name); | 884 | if (!request_mem_region(mem->start, mem_size, pdev->name)) { |
888 | if (ax->mem == NULL) { | ||
889 | dev_err(&pdev->dev, "cannot reserve registers\n"); | 885 | dev_err(&pdev->dev, "cannot reserve registers\n"); |
890 | ret = -ENXIO; | 886 | ret = -ENXIO; |
891 | goto exit_mem; | 887 | goto exit_mem; |
892 | } | 888 | } |
893 | 889 | ||
894 | ei_local->mem = ioremap(res->start, size); | 890 | ei_local->mem = ioremap(mem->start, mem_size); |
895 | dev->base_addr = (unsigned long)ei_local->mem; | 891 | dev->base_addr = (unsigned long)ei_local->mem; |
896 | 892 | ||
897 | if (ei_local->mem == NULL) { | 893 | if (ei_local->mem == NULL) { |
898 | dev_err(&pdev->dev, "Cannot ioremap area (%08llx,%08llx)\n", | 894 | dev_err(&pdev->dev, "Cannot ioremap area %pR\n", mem); |
899 | (unsigned long long)res->start, | ||
900 | (unsigned long long)res->end); | ||
901 | 895 | ||
902 | ret = -ENXIO; | 896 | ret = -ENXIO; |
903 | goto exit_req; | 897 | goto exit_req; |
904 | } | 898 | } |
905 | 899 | ||
906 | /* look for reset area */ | 900 | /* look for reset area */ |
907 | 901 | mem2 = platform_get_resource(pdev, IORESOURCE_MEM, 1); | |
908 | res = platform_get_resource(pdev, IORESOURCE_MEM, 1); | 902 | if (!mem2) { |
909 | if (res == NULL) { | ||
910 | if (!ax->plat->reg_offsets) { | 903 | if (!ax->plat->reg_offsets) { |
911 | for (ret = 0; ret < 0x20; ret++) | 904 | for (ret = 0; ret < 0x20; ret++) |
912 | ax->reg_offsets[ret] = (size / 0x20) * ret; | 905 | ax->reg_offsets[ret] = (mem_size / 0x20) * ret; |
913 | } | 906 | } |
914 | |||
915 | ax->map2 = NULL; | ||
916 | } else { | 907 | } else { |
917 | size = (res->end - res->start) + 1; | 908 | mem2_size = resource_size(mem2); |
918 | 909 | ||
919 | ax->mem2 = request_mem_region(res->start, size, pdev->name); | 910 | if (!request_mem_region(mem2->start, mem2_size, pdev->name)) { |
920 | if (ax->mem2 == NULL) { | ||
921 | dev_err(&pdev->dev, "cannot reserve registers\n"); | 911 | dev_err(&pdev->dev, "cannot reserve registers\n"); |
922 | ret = -ENXIO; | 912 | ret = -ENXIO; |
923 | goto exit_mem1; | 913 | goto exit_mem1; |
924 | } | 914 | } |
925 | 915 | ||
926 | ax->map2 = ioremap(res->start, size); | 916 | ax->map2 = ioremap(mem2->start, mem2_size); |
927 | if (ax->map2 == NULL) { | 917 | if (!ax->map2) { |
928 | dev_err(&pdev->dev, "cannot map reset register\n"); | 918 | dev_err(&pdev->dev, "cannot map reset register\n"); |
929 | ret = -ENXIO; | 919 | ret = -ENXIO; |
930 | goto exit_mem2; | 920 | goto exit_mem2; |
@@ -934,26 +924,23 @@ static int ax_probe(struct platform_device *pdev) | |||
934 | } | 924 | } |
935 | 925 | ||
936 | /* got resources, now initialise and register device */ | 926 | /* got resources, now initialise and register device */ |
937 | |||
938 | ret = ax_init_dev(dev); | 927 | ret = ax_init_dev(dev); |
939 | if (!ret) | 928 | if (!ret) |
940 | return 0; | 929 | return 0; |
941 | 930 | ||
942 | if (ax->map2 == NULL) | 931 | if (!ax->map2) |
943 | goto exit_mem1; | 932 | goto exit_mem1; |
944 | 933 | ||
945 | iounmap(ax->map2); | 934 | iounmap(ax->map2); |
946 | 935 | ||
947 | exit_mem2: | 936 | exit_mem2: |
948 | release_resource(ax->mem2); | 937 | release_mem_region(mem2->start, mem2_size); |
949 | kfree(ax->mem2); | ||
950 | 938 | ||
951 | exit_mem1: | 939 | exit_mem1: |
952 | iounmap(ei_local->mem); | 940 | iounmap(ei_local->mem); |
953 | 941 | ||
954 | exit_req: | 942 | exit_req: |
955 | release_resource(ax->mem); | 943 | release_mem_region(mem->start, mem_size); |
956 | kfree(ax->mem); | ||
957 | 944 | ||
958 | exit_mem: | 945 | exit_mem: |
959 | free_netdev(dev); | 946 | free_netdev(dev); |