aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--Documentation/devicetree/bindings/net/via-rhine.txt17
-rw-r--r--arch/arm/boot/dts/vt8500.dtsi6
-rw-r--r--arch/arm/boot/dts/wm8650.dtsi6
-rw-r--r--arch/arm/boot/dts/wm8850.dtsi6
-rw-r--r--drivers/net/ethernet/via/Kconfig2
-rw-r--r--drivers/net/ethernet/via/via-rhine.c307
6 files changed, 229 insertions, 115 deletions
diff --git a/Documentation/devicetree/bindings/net/via-rhine.txt b/Documentation/devicetree/bindings/net/via-rhine.txt
new file mode 100644
index 000000000000..334eca2bf937
--- /dev/null
+++ b/Documentation/devicetree/bindings/net/via-rhine.txt
@@ -0,0 +1,17 @@
1* VIA Rhine 10/100 Network Controller
2
3Required properties:
4- compatible : Should be "via,vt8500-rhine" for integrated
5 Rhine controllers found in VIA VT8500, WonderMedia WM8950
6 and similar. These are listed as 1106:3106 rev. 0x84 on the
7 virtual PCI bus under vendor-provided kernels
8- reg : Address and length of the io space
9- interrupts : Should contain the controller interrupt line
10
11Examples:
12
13ethernet@d8004000 {
14 compatible = "via,vt8500-rhine";
15 reg = <0xd8004000 0x100>;
16 interrupts = <10>;
17};
diff --git a/arch/arm/boot/dts/vt8500.dtsi b/arch/arm/boot/dts/vt8500.dtsi
index 51d0e912c8f5..1929ad390d88 100644
--- a/arch/arm/boot/dts/vt8500.dtsi
+++ b/arch/arm/boot/dts/vt8500.dtsi
@@ -165,5 +165,11 @@
165 reg = <0xd8100000 0x10000>; 165 reg = <0xd8100000 0x10000>;
166 interrupts = <48>; 166 interrupts = <48>;
167 }; 167 };
168
169 ethernet@d8004000 {
170 compatible = "via,vt8500-rhine";
171 reg = <0xd8004000 0x100>;
172 interrupts = <10>;
173 };
168 }; 174 };
169}; 175};
diff --git a/arch/arm/boot/dts/wm8650.dtsi b/arch/arm/boot/dts/wm8650.dtsi
index 7525982262ac..b1c59a766a13 100644
--- a/arch/arm/boot/dts/wm8650.dtsi
+++ b/arch/arm/boot/dts/wm8650.dtsi
@@ -218,5 +218,11 @@
218 reg = <0xd8100000 0x10000>; 218 reg = <0xd8100000 0x10000>;
219 interrupts = <48>; 219 interrupts = <48>;
220 }; 220 };
221
222 ethernet@d8004000 {
223 compatible = "via,vt8500-rhine";
224 reg = <0xd8004000 0x100>;
225 interrupts = <10>;
226 };
221 }; 227 };
222}; 228};
diff --git a/arch/arm/boot/dts/wm8850.dtsi b/arch/arm/boot/dts/wm8850.dtsi
index d98386dd2882..8fbccfbe75f3 100644
--- a/arch/arm/boot/dts/wm8850.dtsi
+++ b/arch/arm/boot/dts/wm8850.dtsi
@@ -298,5 +298,11 @@
298 bus-width = <4>; 298 bus-width = <4>;
299 sdon-inverted; 299 sdon-inverted;
300 }; 300 };
301
302 ethernet@d8004000 {
303 compatible = "via,vt8500-rhine";
304 reg = <0xd8004000 0x100>;
305 interrupts = <10>;
306 };
301 }; 307 };
302}; 308};
diff --git a/drivers/net/ethernet/via/Kconfig b/drivers/net/ethernet/via/Kconfig
index 8a049a2b4474..f66ddaee0c87 100644
--- a/drivers/net/ethernet/via/Kconfig
+++ b/drivers/net/ethernet/via/Kconfig
@@ -19,7 +19,7 @@ if NET_VENDOR_VIA
19 19
20config VIA_RHINE 20config VIA_RHINE
21 tristate "VIA Rhine support" 21 tristate "VIA Rhine support"
22 depends on PCI 22 depends on (PCI || USE_OF)
23 select CRC32 23 select CRC32
24 select MII 24 select MII
25 ---help--- 25 ---help---
diff --git a/drivers/net/ethernet/via/via-rhine.c b/drivers/net/ethernet/via/via-rhine.c
index 20b83f11004a..4fa92012ceac 100644
--- a/drivers/net/ethernet/via/via-rhine.c
+++ b/drivers/net/ethernet/via/via-rhine.c
@@ -94,6 +94,10 @@ static const int multicast_filter_limit = 32;
94#include <linux/ioport.h> 94#include <linux/ioport.h>
95#include <linux/interrupt.h> 95#include <linux/interrupt.h>
96#include <linux/pci.h> 96#include <linux/pci.h>
97#include <linux/of_address.h>
98#include <linux/of_device.h>
99#include <linux/of_irq.h>
100#include <linux/platform_device.h>
97#include <linux/dma-mapping.h> 101#include <linux/dma-mapping.h>
98#include <linux/netdevice.h> 102#include <linux/netdevice.h>
99#include <linux/etherdevice.h> 103#include <linux/etherdevice.h>
@@ -279,6 +283,15 @@ static DEFINE_PCI_DEVICE_TABLE(rhine_pci_tbl) = {
279}; 283};
280MODULE_DEVICE_TABLE(pci, rhine_pci_tbl); 284MODULE_DEVICE_TABLE(pci, rhine_pci_tbl);
281 285
286/* OpenFirmware identifiers for platform-bus devices
287 * The .data field is currently only used to store chip revision
288 * (for quirks etc.)
289 */
290static struct of_device_id rhine_of_tbl[] = {
291 { .compatible = "via,vt8500-rhine", .data = (void *)0x84 },
292 { } /* terminate list */
293};
294MODULE_DEVICE_TABLE(of, rhine_of_tbl);
282 295
283/* Offsets to the device registers. */ 296/* Offsets to the device registers. */
284enum register_offsets { 297enum register_offsets {
@@ -847,7 +860,8 @@ static void rhine_hw_init(struct net_device *dev, long pioaddr)
847 msleep(5); 860 msleep(5);
848 861
849 /* Reload EEPROM controlled bytes cleared by soft reset */ 862 /* Reload EEPROM controlled bytes cleared by soft reset */
850 rhine_reload_eeprom(pioaddr, dev); 863 if (dev_is_pci(dev->dev.parent))
864 rhine_reload_eeprom(pioaddr, dev);
851} 865}
852 866
853static const struct net_device_ops rhine_netdev_ops = { 867static const struct net_device_ops rhine_netdev_ops = {
@@ -868,125 +882,55 @@ static const struct net_device_ops rhine_netdev_ops = {
868#endif 882#endif
869}; 883};
870 884
871static int rhine_init_one(struct pci_dev *pdev, const struct pci_device_id *ent) 885static int rhine_init_one_common(struct device *hwdev, int revision,
886 long pioaddr, void __iomem *ioaddr, int irq)
872{ 887{
873 struct net_device *dev; 888 struct net_device *dev;
874 struct rhine_private *rp; 889 struct rhine_private *rp;
875 struct device *hwdev = &pdev->dev; 890 int i, rc, phy_id;
876 int revision = pdev->revision;
877 int i, rc;
878 u32 quirks;
879 long pioaddr;
880 long memaddr;
881 void __iomem *ioaddr;
882 int io_size, phy_id;
883 const char *name; 891 const char *name;
884#ifdef USE_MMIO
885 int bar = 1;
886#else
887 int bar = 0;
888#endif
889
890/* when built into the kernel, we only print version if device is found */
891#ifndef MODULE
892 pr_info_once("%s\n", version);
893#endif
894
895 io_size = 256;
896 phy_id = 0;
897 quirks = 0;
898 name = "Rhine";
899 if (revision < VTunknown0) {
900 quirks = rqRhineI;
901 io_size = 128;
902 } else if (revision >= VT6102) {
903 quirks = rqWOL | rqForceReset;
904 if (revision < VT6105) {
905 name = "Rhine II";
906 quirks |= rqStatusWBRace; /* Rhine-II exclusive */
907 } else {
908 phy_id = 1; /* Integrated PHY, phy_id fixed to 1 */
909 if (revision >= VT6105_B0)
910 quirks |= rq6patterns;
911 if (revision < VT6105M)
912 name = "Rhine III";
913 else
914 name = "Rhine III (Management Adapter)";
915 }
916 }
917
918 rc = pci_enable_device(pdev);
919 if (rc)
920 goto err_out;
921 892
922 /* this should always be supported */ 893 /* this should always be supported */
923 rc = dma_set_mask(hwdev, DMA_BIT_MASK(32)); 894 rc = dma_set_mask(hwdev, DMA_BIT_MASK(32));
924 if (rc) { 895 if (rc) {
925 dev_err(hwdev, "32-bit DMA addresses not supported by the card!?\n"); 896 dev_err(hwdev, "32-bit DMA addresses not supported by the card!?\n");
926 goto err_out_pci_disable; 897 goto err_out;
927 }
928
929 /* sanity check */
930 if ((pci_resource_len(pdev, 0) < io_size) ||
931 (pci_resource_len(pdev, 1) < io_size)) {
932 rc = -EIO;
933 dev_err(hwdev, "Insufficient PCI resources, aborting\n");
934 goto err_out_pci_disable;
935 } 898 }
936 899
937 pioaddr = pci_resource_start(pdev, 0);
938 memaddr = pci_resource_start(pdev, 1);
939
940 pci_set_master(pdev);
941
942 dev = alloc_etherdev(sizeof(struct rhine_private)); 900 dev = alloc_etherdev(sizeof(struct rhine_private));
943 if (!dev) { 901 if (!dev) {
944 rc = -ENOMEM; 902 rc = -ENOMEM;
945 goto err_out_pci_disable; 903 goto err_out;
946 } 904 }
947 SET_NETDEV_DEV(dev, hwdev); 905 SET_NETDEV_DEV(dev, hwdev);
948 906
949 rp = netdev_priv(dev); 907 rp = netdev_priv(dev);
950 rp->dev = dev; 908 rp->dev = dev;
951 rp->revision = revision; 909 rp->revision = revision;
952 rp->quirks = quirks;
953 rp->pioaddr = pioaddr; 910 rp->pioaddr = pioaddr;
911 rp->base = ioaddr;
912 rp->irq = irq;
954 rp->msg_enable = netif_msg_init(debug, RHINE_MSG_DEFAULT); 913 rp->msg_enable = netif_msg_init(debug, RHINE_MSG_DEFAULT);
955 914
956 rc = pci_request_regions(pdev, DRV_NAME); 915 phy_id = 0;
957 if (rc) 916 name = "Rhine";
958 goto err_out_free_netdev; 917 if (revision < VTunknown0) {
959 918 rp->quirks = rqRhineI;
960 ioaddr = pci_iomap(pdev, bar, io_size); 919 } else if (revision >= VT6102) {
961 if (!ioaddr) { 920 rp->quirks = rqWOL | rqForceReset;
962 rc = -EIO; 921 if (revision < VT6105) {
963 dev_err(hwdev, 922 name = "Rhine II";
964 "ioremap failed for device %s, region 0x%X @ 0x%lX\n", 923 rp->quirks |= rqStatusWBRace; /* Rhine-II exclusive */
965 dev_name(hwdev), io_size, memaddr); 924 } else {
966 goto err_out_free_res; 925 phy_id = 1; /* Integrated PHY, phy_id fixed to 1 */
967 } 926 if (revision >= VT6105_B0)
968 927 rp->quirks |= rq6patterns;
969#ifdef USE_MMIO 928 if (revision < VT6105M)
970 enable_mmio(pioaddr, quirks); 929 name = "Rhine III";
971 930 else
972 /* Check that selected MMIO registers match the PIO ones */ 931 name = "Rhine III (Management Adapter)";
973 i = 0;
974 while (mmio_verify_registers[i]) {
975 int reg = mmio_verify_registers[i++];
976 unsigned char a = inb(pioaddr+reg);
977 unsigned char b = readb(ioaddr+reg);
978 if (a != b) {
979 rc = -EIO;
980 dev_err(hwdev,
981 "MMIO do not match PIO [%02x] (%02x != %02x)\n",
982 reg, a, b);
983 goto err_out_unmap;
984 } 932 }
985 } 933 }
986#endif /* USE_MMIO */
987
988 rp->base = ioaddr;
989 rp->irq = pdev->irq;
990 934
991 u64_stats_init(&rp->tx_stats.syncp); 935 u64_stats_init(&rp->tx_stats.syncp);
992 u64_stats_init(&rp->rx_stats.syncp); 936 u64_stats_init(&rp->rx_stats.syncp);
@@ -1039,16 +983,10 @@ static int rhine_init_one(struct pci_dev *pdev, const struct pci_device_id *ent)
1039 /* dev->name not defined before register_netdev()! */ 983 /* dev->name not defined before register_netdev()! */
1040 rc = register_netdev(dev); 984 rc = register_netdev(dev);
1041 if (rc) 985 if (rc)
1042 goto err_out_unmap; 986 goto err_out_free_netdev;
1043 987
1044 netdev_info(dev, "VIA %s at 0x%lx, %pM, IRQ %d\n", 988 netdev_info(dev, "VIA %s at 0x%lx, %pM, IRQ %d\n",
1045 name, 989 name, (long)ioaddr, dev->dev_addr, rp->irq);
1046#ifdef USE_MMIO
1047 memaddr,
1048#else
1049 (long)ioaddr,
1050#endif
1051 dev->dev_addr, rp->irq);
1052 990
1053 dev_set_drvdata(hwdev, dev); 991 dev_set_drvdata(hwdev, dev);
1054 992
@@ -1079,18 +1017,126 @@ static int rhine_init_one(struct pci_dev *pdev, const struct pci_device_id *ent)
1079 1017
1080 return 0; 1018 return 0;
1081 1019
1020err_out_free_netdev:
1021 free_netdev(dev);
1022err_out:
1023 return rc;
1024}
1025
1026static int rhine_init_one_pci(struct pci_dev *pdev,
1027 const struct pci_device_id *ent)
1028{
1029 struct device *hwdev = &pdev->dev;
1030 int i, rc;
1031 long pioaddr, memaddr;
1032 void __iomem *ioaddr;
1033 int io_size = pdev->revision < VTunknown0 ? 128 : 256;
1034 u32 quirks = pdev->revision < VTunknown0 ? rqRhineI : 0;
1035#ifdef USE_MMIO
1036 int bar = 1;
1037#else
1038 int bar = 0;
1039#endif
1040
1041/* when built into the kernel, we only print version if device is found */
1042#ifndef MODULE
1043 pr_info_once("%s\n", version);
1044#endif
1045
1046 rc = pci_enable_device(pdev);
1047 if (rc)
1048 goto err_out;
1049
1050 /* sanity check */
1051 if ((pci_resource_len(pdev, 0) < io_size) ||
1052 (pci_resource_len(pdev, 1) < io_size)) {
1053 rc = -EIO;
1054 dev_err(hwdev, "Insufficient PCI resources, aborting\n");
1055 goto err_out_pci_disable;
1056 }
1057
1058 pioaddr = pci_resource_start(pdev, 0);
1059 memaddr = pci_resource_start(pdev, 1);
1060
1061 pci_set_master(pdev);
1062
1063 rc = pci_request_regions(pdev, DRV_NAME);
1064 if (rc)
1065 goto err_out_pci_disable;
1066
1067 ioaddr = pci_iomap(pdev, bar, io_size);
1068 if (!ioaddr) {
1069 rc = -EIO;
1070 dev_err(hwdev,
1071 "ioremap failed for device %s, region 0x%X @ 0x%lX\n",
1072 dev_name(hwdev), io_size, memaddr);
1073 goto err_out_free_res;
1074 }
1075
1076#ifdef USE_MMIO
1077 enable_mmio(pioaddr, quirks);
1078
1079 /* Check that selected MMIO registers match the PIO ones */
1080 i = 0;
1081 while (mmio_verify_registers[i]) {
1082 int reg = mmio_verify_registers[i++];
1083 unsigned char a = inb(pioaddr+reg);
1084 unsigned char b = readb(ioaddr+reg);
1085
1086 if (a != b) {
1087 rc = -EIO;
1088 dev_err(hwdev,
1089 "MMIO do not match PIO [%02x] (%02x != %02x)\n",
1090 reg, a, b);
1091 goto err_out_unmap;
1092 }
1093 }
1094#endif /* USE_MMIO */
1095
1096 rc = rhine_init_one_common(&pdev->dev, pdev->revision,
1097 pioaddr, ioaddr, pdev->irq);
1098 if (!rc)
1099 return 0;
1100
1082err_out_unmap: 1101err_out_unmap:
1083 pci_iounmap(pdev, ioaddr); 1102 pci_iounmap(pdev, ioaddr);
1084err_out_free_res: 1103err_out_free_res:
1085 pci_release_regions(pdev); 1104 pci_release_regions(pdev);
1086err_out_free_netdev:
1087 free_netdev(dev);
1088err_out_pci_disable: 1105err_out_pci_disable:
1089 pci_disable_device(pdev); 1106 pci_disable_device(pdev);
1090err_out: 1107err_out:
1091 return rc; 1108 return rc;
1092} 1109}
1093 1110
1111static int rhine_init_one_platform(struct platform_device *pdev)
1112{
1113 const struct of_device_id *match;
1114 u32 revision;
1115 int irq;
1116 struct resource *res;
1117 void __iomem *ioaddr;
1118
1119 match = of_match_device(rhine_of_tbl, &pdev->dev);
1120 if (!match)
1121 return -EINVAL;
1122
1123 res = platform_get_resource(pdev, IORESOURCE_MEM, 0);
1124 ioaddr = devm_ioremap_resource(&pdev->dev, res);
1125 if (IS_ERR(ioaddr))
1126 return PTR_ERR(ioaddr);
1127
1128 irq = irq_of_parse_and_map(pdev->dev.of_node, 0);
1129 if (!irq)
1130 return -EINVAL;
1131
1132 revision = (u32)match->data;
1133 if (!revision)
1134 return -EINVAL;
1135
1136 return rhine_init_one_common(&pdev->dev, revision,
1137 (long)ioaddr, ioaddr, irq);
1138}
1139
1094static int alloc_ring(struct net_device* dev) 1140static int alloc_ring(struct net_device* dev)
1095{ 1141{
1096 struct rhine_private *rp = netdev_priv(dev); 1142 struct rhine_private *rp = netdev_priv(dev);
@@ -2297,7 +2343,7 @@ static int rhine_close(struct net_device *dev)
2297} 2343}
2298 2344
2299 2345
2300static void rhine_remove_one(struct pci_dev *pdev) 2346static void rhine_remove_one_pci(struct pci_dev *pdev)
2301{ 2347{
2302 struct net_device *dev = pci_get_drvdata(pdev); 2348 struct net_device *dev = pci_get_drvdata(pdev);
2303 struct rhine_private *rp = netdev_priv(dev); 2349 struct rhine_private *rp = netdev_priv(dev);
@@ -2311,7 +2357,21 @@ static void rhine_remove_one(struct pci_dev *pdev)
2311 pci_disable_device(pdev); 2357 pci_disable_device(pdev);
2312} 2358}
2313 2359
2314static void rhine_shutdown (struct pci_dev *pdev) 2360static int rhine_remove_one_platform(struct platform_device *pdev)
2361{
2362 struct net_device *dev = platform_get_drvdata(pdev);
2363 struct rhine_private *rp = netdev_priv(dev);
2364
2365 unregister_netdev(dev);
2366
2367 iounmap(rp->base);
2368
2369 free_netdev(dev);
2370
2371 return 0;
2372}
2373
2374static void rhine_shutdown_pci(struct pci_dev *pdev)
2315{ 2375{
2316 struct net_device *dev = pci_get_drvdata(pdev); 2376 struct net_device *dev = pci_get_drvdata(pdev);
2317 struct rhine_private *rp = netdev_priv(dev); 2377 struct rhine_private *rp = netdev_priv(dev);
@@ -2378,7 +2438,7 @@ static int rhine_suspend(struct device *device)
2378 netif_device_detach(dev); 2438 netif_device_detach(dev);
2379 2439
2380 if (dev_is_pci(device)) 2440 if (dev_is_pci(device))
2381 rhine_shutdown(to_pci_dev(device)); 2441 rhine_shutdown_pci(to_pci_dev(device));
2382 2442
2383 return 0; 2443 return 0;
2384} 2444}
@@ -2418,15 +2478,26 @@ static SIMPLE_DEV_PM_OPS(rhine_pm_ops, rhine_suspend, rhine_resume);
2418 2478
2419#endif /* !CONFIG_PM_SLEEP */ 2479#endif /* !CONFIG_PM_SLEEP */
2420 2480
2421static struct pci_driver rhine_driver = { 2481static struct pci_driver rhine_driver_pci = {
2422 .name = DRV_NAME, 2482 .name = DRV_NAME,
2423 .id_table = rhine_pci_tbl, 2483 .id_table = rhine_pci_tbl,
2424 .probe = rhine_init_one, 2484 .probe = rhine_init_one_pci,
2425 .remove = rhine_remove_one, 2485 .remove = rhine_remove_one_pci,
2426 .shutdown = rhine_shutdown, 2486 .shutdown = rhine_shutdown_pci,
2427 .driver.pm = RHINE_PM_OPS, 2487 .driver.pm = RHINE_PM_OPS,
2428}; 2488};
2429 2489
2490static struct platform_driver rhine_driver_platform = {
2491 .probe = rhine_init_one_platform,
2492 .remove = rhine_remove_one_platform,
2493 .driver = {
2494 .name = DRV_NAME,
2495 .owner = THIS_MODULE,
2496 .of_match_table = rhine_of_tbl,
2497 .pm = RHINE_PM_OPS,
2498 }
2499};
2500
2430static struct dmi_system_id rhine_dmi_table[] __initdata = { 2501static struct dmi_system_id rhine_dmi_table[] __initdata = {
2431 { 2502 {
2432 .ident = "EPIA-M", 2503 .ident = "EPIA-M",
@@ -2447,6 +2518,8 @@ static struct dmi_system_id rhine_dmi_table[] __initdata = {
2447 2518
2448static int __init rhine_init(void) 2519static int __init rhine_init(void)
2449{ 2520{
2521 int ret_pci, ret_platform;
2522
2450/* when a module, this is printed whether or not devices are found in probe */ 2523/* when a module, this is printed whether or not devices are found in probe */
2451#ifdef MODULE 2524#ifdef MODULE
2452 pr_info("%s\n", version); 2525 pr_info("%s\n", version);
@@ -2459,13 +2532,19 @@ static int __init rhine_init(void)
2459 else if (avoid_D3) 2532 else if (avoid_D3)
2460 pr_info("avoid_D3 set\n"); 2533 pr_info("avoid_D3 set\n");
2461 2534
2462 return pci_register_driver(&rhine_driver); 2535 ret_pci = pci_register_driver(&rhine_driver_pci);
2536 ret_platform = platform_driver_register(&rhine_driver_platform);
2537 if ((ret_pci < 0) && (ret_platform < 0))
2538 return ret_pci;
2539
2540 return 0;
2463} 2541}
2464 2542
2465 2543
2466static void __exit rhine_cleanup(void) 2544static void __exit rhine_cleanup(void)
2467{ 2545{
2468 pci_unregister_driver(&rhine_driver); 2546 platform_driver_unregister(&rhine_driver_platform);
2547 pci_unregister_driver(&rhine_driver_pci);
2469} 2548}
2470 2549
2471 2550