diff options
author | Graf Yang <graf.yang@analog.com> | 2009-05-28 23:41:48 -0400 |
---|---|---|
committer | David S. Miller <davem@davemloft.net> | 2009-05-29 18:49:09 -0400 |
commit | 080c82550dc1dc3c0d4207ce32d7a8d0ae96fba5 (patch) | |
tree | 7d649f037a1c33a78e4accf4e63c6f13f9952b6d /drivers/net/bfin_mac.c | |
parent | 015dac8886b5c48d62ebc33a964b9086d6a71bd7 (diff) |
netdev: bfin_mac: add Blackfin MII bus to platform bus to allow DSA access
When we register the MII bus to the platfrom bus, the Distributed Switch
Architecture can hook in transparently.
Signed-off-by: Graf Yang <graf.yang@analog.com>
Signed-off-by: Mike Frysinger <vapier@gentoo.org>
Signed-off-by: David S. Miller <davem@davemloft.net>
Diffstat (limited to 'drivers/net/bfin_mac.c')
-rw-r--r-- | drivers/net/bfin_mac.c | 117 |
1 files changed, 84 insertions, 33 deletions
diff --git a/drivers/net/bfin_mac.c b/drivers/net/bfin_mac.c index f0f1eb929dbb..955a46958b7f 100644 --- a/drivers/net/bfin_mac.c +++ b/drivers/net/bfin_mac.c | |||
@@ -971,7 +971,8 @@ static int __devinit bfin_mac_probe(struct platform_device *pdev) | |||
971 | { | 971 | { |
972 | struct net_device *ndev; | 972 | struct net_device *ndev; |
973 | struct bfin_mac_local *lp; | 973 | struct bfin_mac_local *lp; |
974 | int rc, i; | 974 | struct platform_device *pd; |
975 | int rc; | ||
975 | 976 | ||
976 | ndev = alloc_etherdev(sizeof(struct bfin_mac_local)); | 977 | ndev = alloc_etherdev(sizeof(struct bfin_mac_local)); |
977 | if (!ndev) { | 978 | if (!ndev) { |
@@ -996,13 +997,6 @@ static int __devinit bfin_mac_probe(struct platform_device *pdev) | |||
996 | goto out_err_probe_mac; | 997 | goto out_err_probe_mac; |
997 | } | 998 | } |
998 | 999 | ||
999 | /* set the GPIO pins to Ethernet mode */ | ||
1000 | rc = peripheral_request_list(pin_req, DRV_NAME); | ||
1001 | if (rc) { | ||
1002 | dev_err(&pdev->dev, "Requesting peripherals failed!\n"); | ||
1003 | rc = -EFAULT; | ||
1004 | goto out_err_setup_pin_mux; | ||
1005 | } | ||
1006 | 1000 | ||
1007 | /* | 1001 | /* |
1008 | * Is it valid? (Did bootloader initialize it?) | 1002 | * Is it valid? (Did bootloader initialize it?) |
@@ -1018,26 +1012,14 @@ static int __devinit bfin_mac_probe(struct platform_device *pdev) | |||
1018 | 1012 | ||
1019 | setup_mac_addr(ndev->dev_addr); | 1013 | setup_mac_addr(ndev->dev_addr); |
1020 | 1014 | ||
1021 | /* MDIO bus initial */ | 1015 | if (!pdev->dev.platform_data) { |
1022 | lp->mii_bus = mdiobus_alloc(); | 1016 | dev_err(&pdev->dev, "Cannot get platform device bfin_mii_bus!\n"); |
1023 | if (lp->mii_bus == NULL) | 1017 | rc = -ENODEV; |
1024 | goto out_err_mdiobus_alloc; | 1018 | goto out_err_probe_mac; |
1025 | |||
1026 | lp->mii_bus->priv = ndev; | ||
1027 | lp->mii_bus->read = bfin_mdiobus_read; | ||
1028 | lp->mii_bus->write = bfin_mdiobus_write; | ||
1029 | lp->mii_bus->reset = bfin_mdiobus_reset; | ||
1030 | lp->mii_bus->name = "bfin_mac_mdio"; | ||
1031 | snprintf(lp->mii_bus->id, MII_BUS_ID_SIZE, "0"); | ||
1032 | lp->mii_bus->irq = kmalloc(sizeof(int)*PHY_MAX_ADDR, GFP_KERNEL); | ||
1033 | for (i = 0; i < PHY_MAX_ADDR; ++i) | ||
1034 | lp->mii_bus->irq[i] = PHY_POLL; | ||
1035 | |||
1036 | rc = mdiobus_register(lp->mii_bus); | ||
1037 | if (rc) { | ||
1038 | dev_err(&pdev->dev, "Cannot register MDIO bus!\n"); | ||
1039 | goto out_err_mdiobus_register; | ||
1040 | } | 1019 | } |
1020 | pd = pdev->dev.platform_data; | ||
1021 | lp->mii_bus = platform_get_drvdata(pd); | ||
1022 | lp->mii_bus->priv = ndev; | ||
1041 | 1023 | ||
1042 | rc = mii_probe(ndev); | 1024 | rc = mii_probe(ndev); |
1043 | if (rc) { | 1025 | if (rc) { |
@@ -1079,11 +1061,8 @@ out_err_reg_ndev: | |||
1079 | out_err_request_irq: | 1061 | out_err_request_irq: |
1080 | out_err_mii_probe: | 1062 | out_err_mii_probe: |
1081 | mdiobus_unregister(lp->mii_bus); | 1063 | mdiobus_unregister(lp->mii_bus); |
1082 | out_err_mdiobus_register: | ||
1083 | mdiobus_free(lp->mii_bus); | 1064 | mdiobus_free(lp->mii_bus); |
1084 | out_err_mdiobus_alloc: | ||
1085 | peripheral_free_list(pin_req); | 1065 | peripheral_free_list(pin_req); |
1086 | out_err_setup_pin_mux: | ||
1087 | out_err_probe_mac: | 1066 | out_err_probe_mac: |
1088 | platform_set_drvdata(pdev, NULL); | 1067 | platform_set_drvdata(pdev, NULL); |
1089 | free_netdev(ndev); | 1068 | free_netdev(ndev); |
@@ -1098,8 +1077,7 @@ static int __devexit bfin_mac_remove(struct platform_device *pdev) | |||
1098 | 1077 | ||
1099 | platform_set_drvdata(pdev, NULL); | 1078 | platform_set_drvdata(pdev, NULL); |
1100 | 1079 | ||
1101 | mdiobus_unregister(lp->mii_bus); | 1080 | lp->mii_bus->priv = NULL; |
1102 | mdiobus_free(lp->mii_bus); | ||
1103 | 1081 | ||
1104 | unregister_netdev(ndev); | 1082 | unregister_netdev(ndev); |
1105 | 1083 | ||
@@ -1137,6 +1115,74 @@ static int bfin_mac_resume(struct platform_device *pdev) | |||
1137 | #define bfin_mac_resume NULL | 1115 | #define bfin_mac_resume NULL |
1138 | #endif /* CONFIG_PM */ | 1116 | #endif /* CONFIG_PM */ |
1139 | 1117 | ||
1118 | static int __devinit bfin_mii_bus_probe(struct platform_device *pdev) | ||
1119 | { | ||
1120 | struct mii_bus *miibus; | ||
1121 | int rc, i; | ||
1122 | |||
1123 | /* | ||
1124 | * We are setting up a network card, | ||
1125 | * so set the GPIO pins to Ethernet mode | ||
1126 | */ | ||
1127 | rc = peripheral_request_list(pin_req, DRV_NAME); | ||
1128 | if (rc) { | ||
1129 | dev_err(&pdev->dev, "Requesting peripherals failed!\n"); | ||
1130 | return rc; | ||
1131 | } | ||
1132 | |||
1133 | rc = -ENOMEM; | ||
1134 | miibus = mdiobus_alloc(); | ||
1135 | if (miibus == NULL) | ||
1136 | goto out_err_alloc; | ||
1137 | miibus->read = bfin_mdiobus_read; | ||
1138 | miibus->write = bfin_mdiobus_write; | ||
1139 | miibus->reset = bfin_mdiobus_reset; | ||
1140 | |||
1141 | miibus->parent = &pdev->dev; | ||
1142 | miibus->name = "bfin_mii_bus"; | ||
1143 | snprintf(miibus->id, MII_BUS_ID_SIZE, "0"); | ||
1144 | miibus->irq = kmalloc(sizeof(int)*PHY_MAX_ADDR, GFP_KERNEL); | ||
1145 | if (miibus->irq == NULL) | ||
1146 | goto out_err_alloc; | ||
1147 | for (i = 0; i < PHY_MAX_ADDR; ++i) | ||
1148 | miibus->irq[i] = PHY_POLL; | ||
1149 | |||
1150 | rc = mdiobus_register(miibus); | ||
1151 | if (rc) { | ||
1152 | dev_err(&pdev->dev, "Cannot register MDIO bus!\n"); | ||
1153 | goto out_err_mdiobus_register; | ||
1154 | } | ||
1155 | |||
1156 | platform_set_drvdata(pdev, miibus); | ||
1157 | return 0; | ||
1158 | |||
1159 | out_err_mdiobus_register: | ||
1160 | mdiobus_free(miibus); | ||
1161 | out_err_alloc: | ||
1162 | peripheral_free_list(pin_req); | ||
1163 | |||
1164 | return rc; | ||
1165 | } | ||
1166 | |||
1167 | static int __devexit bfin_mii_bus_remove(struct platform_device *pdev) | ||
1168 | { | ||
1169 | struct mii_bus *miibus = platform_get_drvdata(pdev); | ||
1170 | platform_set_drvdata(pdev, NULL); | ||
1171 | mdiobus_unregister(miibus); | ||
1172 | mdiobus_free(miibus); | ||
1173 | peripheral_free_list(pin_req); | ||
1174 | return 0; | ||
1175 | } | ||
1176 | |||
1177 | static struct platform_driver bfin_mii_bus_driver = { | ||
1178 | .probe = bfin_mii_bus_probe, | ||
1179 | .remove = __devexit_p(bfin_mii_bus_remove), | ||
1180 | .driver = { | ||
1181 | .name = "bfin_mii_bus", | ||
1182 | .owner = THIS_MODULE, | ||
1183 | }, | ||
1184 | }; | ||
1185 | |||
1140 | static struct platform_driver bfin_mac_driver = { | 1186 | static struct platform_driver bfin_mac_driver = { |
1141 | .probe = bfin_mac_probe, | 1187 | .probe = bfin_mac_probe, |
1142 | .remove = __devexit_p(bfin_mac_remove), | 1188 | .remove = __devexit_p(bfin_mac_remove), |
@@ -1150,7 +1196,11 @@ static struct platform_driver bfin_mac_driver = { | |||
1150 | 1196 | ||
1151 | static int __init bfin_mac_init(void) | 1197 | static int __init bfin_mac_init(void) |
1152 | { | 1198 | { |
1153 | return platform_driver_register(&bfin_mac_driver); | 1199 | int ret; |
1200 | ret = platform_driver_register(&bfin_mii_bus_driver); | ||
1201 | if (!ret) | ||
1202 | return platform_driver_register(&bfin_mac_driver); | ||
1203 | return -ENODEV; | ||
1154 | } | 1204 | } |
1155 | 1205 | ||
1156 | module_init(bfin_mac_init); | 1206 | module_init(bfin_mac_init); |
@@ -1158,6 +1208,7 @@ module_init(bfin_mac_init); | |||
1158 | static void __exit bfin_mac_cleanup(void) | 1208 | static void __exit bfin_mac_cleanup(void) |
1159 | { | 1209 | { |
1160 | platform_driver_unregister(&bfin_mac_driver); | 1210 | platform_driver_unregister(&bfin_mac_driver); |
1211 | platform_driver_unregister(&bfin_mii_bus_driver); | ||
1161 | } | 1212 | } |
1162 | 1213 | ||
1163 | module_exit(bfin_mac_cleanup); | 1214 | module_exit(bfin_mac_cleanup); |