aboutsummaryrefslogtreecommitdiffstats
path: root/drivers
diff options
context:
space:
mode:
authorArnd Bergmann <arnd@arndb.de>2011-12-16 09:32:28 -0500
committerArnd Bergmann <arnd@arndb.de>2011-12-16 09:32:28 -0500
commit06d123e0984424505eedd09981f1bafc3c38de78 (patch)
tree4aa75853378becf583d9514f068045056f45c367 /drivers
parent4966eba037bd0841cdb458907f27b71d4dcfd5d4 (diff)
parent2839038bb1a72ed7ef3c39521e0ca981c9cb1534 (diff)
Merge branch 'at91/macb' into next/drivers
Diffstat (limited to 'drivers')
-rw-r--r--drivers/net/ethernet/cadence/at91_ether.c23
-rw-r--r--drivers/net/ethernet/cadence/macb.c73
-rw-r--r--drivers/net/ethernet/cadence/macb.h2
3 files changed, 80 insertions, 18 deletions
diff --git a/drivers/net/ethernet/cadence/at91_ether.c b/drivers/net/ethernet/cadence/at91_ether.c
index dfeb46cb3f7..1a5b6efa012 100644
--- a/drivers/net/ethernet/cadence/at91_ether.c
+++ b/drivers/net/ethernet/cadence/at91_ether.c
@@ -256,8 +256,7 @@ static void enable_phyirq(struct net_device *dev)
256 unsigned int dsintr, irq_number; 256 unsigned int dsintr, irq_number;
257 int status; 257 int status;
258 258
259 irq_number = lp->board_data.phy_irq_pin; 259 if (!gpio_is_valid(lp->board_data.phy_irq_pin)) {
260 if (!irq_number) {
261 /* 260 /*
262 * PHY doesn't have an IRQ pin (RTL8201, DP83847, AC101L), 261 * PHY doesn't have an IRQ pin (RTL8201, DP83847, AC101L),
263 * or board does not have it connected. 262 * or board does not have it connected.
@@ -266,6 +265,7 @@ static void enable_phyirq(struct net_device *dev)
266 return; 265 return;
267 } 266 }
268 267
268 irq_number = lp->board_data.phy_irq_pin;
269 status = request_irq(irq_number, at91ether_phy_interrupt, 0, dev->name, dev); 269 status = request_irq(irq_number, at91ether_phy_interrupt, 0, dev->name, dev);
270 if (status) { 270 if (status) {
271 printk(KERN_ERR "at91_ether: PHY IRQ %d request failed - status %d!\n", irq_number, status); 271 printk(KERN_ERR "at91_ether: PHY IRQ %d request failed - status %d!\n", irq_number, status);
@@ -320,8 +320,7 @@ static void disable_phyirq(struct net_device *dev)
320 unsigned int dsintr; 320 unsigned int dsintr;
321 unsigned int irq_number; 321 unsigned int irq_number;
322 322
323 irq_number = lp->board_data.phy_irq_pin; 323 if (!gpio_is_valid(lp->board_data.phy_irq_pin)) {
324 if (!irq_number) {
325 del_timer_sync(&lp->check_timer); 324 del_timer_sync(&lp->check_timer);
326 return; 325 return;
327 } 326 }
@@ -366,6 +365,7 @@ static void disable_phyirq(struct net_device *dev)
366 disable_mdi(); 365 disable_mdi();
367 spin_unlock_irq(&lp->lock); 366 spin_unlock_irq(&lp->lock);
368 367
368 irq_number = lp->board_data.phy_irq_pin;
369 free_irq(irq_number, dev); /* Free interrupt handler */ 369 free_irq(irq_number, dev); /* Free interrupt handler */
370} 370}
371 371
@@ -1078,7 +1078,7 @@ static int __init at91ether_setup(unsigned long phy_type, unsigned short phy_add
1078 netif_carrier_off(dev); /* will be enabled in open() */ 1078 netif_carrier_off(dev); /* will be enabled in open() */
1079 1079
1080 /* If board has no PHY IRQ, use a timer to poll the PHY */ 1080 /* If board has no PHY IRQ, use a timer to poll the PHY */
1081 if (!lp->board_data.phy_irq_pin) { 1081 if (!gpio_is_valid(lp->board_data.phy_irq_pin)) {
1082 init_timer(&lp->check_timer); 1082 init_timer(&lp->check_timer);
1083 lp->check_timer.data = (unsigned long)dev; 1083 lp->check_timer.data = (unsigned long)dev;
1084 lp->check_timer.function = at91ether_check_link; 1084 lp->check_timer.function = at91ether_check_link;
@@ -1170,7 +1170,8 @@ static int __devexit at91ether_remove(struct platform_device *pdev)
1170 struct net_device *dev = platform_get_drvdata(pdev); 1170 struct net_device *dev = platform_get_drvdata(pdev);
1171 struct at91_private *lp = netdev_priv(dev); 1171 struct at91_private *lp = netdev_priv(dev);
1172 1172
1173 if (lp->board_data.phy_irq_pin >= 32) 1173 if (gpio_is_valid(lp->board_data.phy_irq_pin) &&
1174 lp->board_data.phy_irq_pin >= 32)
1174 gpio_free(lp->board_data.phy_irq_pin); 1175 gpio_free(lp->board_data.phy_irq_pin);
1175 1176
1176 unregister_netdev(dev); 1177 unregister_netdev(dev);
@@ -1189,11 +1190,12 @@ static int at91ether_suspend(struct platform_device *pdev, pm_message_t mesg)
1189{ 1190{
1190 struct net_device *net_dev = platform_get_drvdata(pdev); 1191 struct net_device *net_dev = platform_get_drvdata(pdev);
1191 struct at91_private *lp = netdev_priv(net_dev); 1192 struct at91_private *lp = netdev_priv(net_dev);
1192 int phy_irq = lp->board_data.phy_irq_pin;
1193 1193
1194 if (netif_running(net_dev)) { 1194 if (netif_running(net_dev)) {
1195 if (phy_irq) 1195 if (gpio_is_valid(lp->board_data.phy_irq_pin)) {
1196 int phy_irq = lp->board_data.phy_irq_pin;
1196 disable_irq(phy_irq); 1197 disable_irq(phy_irq);
1198 }
1197 1199
1198 netif_stop_queue(net_dev); 1200 netif_stop_queue(net_dev);
1199 netif_device_detach(net_dev); 1201 netif_device_detach(net_dev);
@@ -1207,7 +1209,6 @@ static int at91ether_resume(struct platform_device *pdev)
1207{ 1209{
1208 struct net_device *net_dev = platform_get_drvdata(pdev); 1210 struct net_device *net_dev = platform_get_drvdata(pdev);
1209 struct at91_private *lp = netdev_priv(net_dev); 1211 struct at91_private *lp = netdev_priv(net_dev);
1210 int phy_irq = lp->board_data.phy_irq_pin;
1211 1212
1212 if (netif_running(net_dev)) { 1213 if (netif_running(net_dev)) {
1213 clk_enable(lp->ether_clk); 1214 clk_enable(lp->ether_clk);
@@ -1215,8 +1216,10 @@ static int at91ether_resume(struct platform_device *pdev)
1215 netif_device_attach(net_dev); 1216 netif_device_attach(net_dev);
1216 netif_start_queue(net_dev); 1217 netif_start_queue(net_dev);
1217 1218
1218 if (phy_irq) 1219 if (gpio_is_valid(lp->board_data.phy_irq_pin)) {
1220 int phy_irq = lp->board_data.phy_irq_pin;
1219 enable_irq(phy_irq); 1221 enable_irq(phy_irq);
1222 }
1220 } 1223 }
1221 return 0; 1224 return 0;
1222} 1225}
diff --git a/drivers/net/ethernet/cadence/macb.c b/drivers/net/ethernet/cadence/macb.c
index 64d61461bdc..baf1a0d88d8 100644
--- a/drivers/net/ethernet/cadence/macb.c
+++ b/drivers/net/ethernet/cadence/macb.c
@@ -23,6 +23,8 @@
23#include <linux/platform_data/macb.h> 23#include <linux/platform_data/macb.h>
24#include <linux/platform_device.h> 24#include <linux/platform_device.h>
25#include <linux/phy.h> 25#include <linux/phy.h>
26#include <linux/of_device.h>
27#include <linux/of_net.h>
26 28
27#include "macb.h" 29#include "macb.h"
28 30
@@ -191,7 +193,6 @@ static int macb_mii_probe(struct net_device *dev)
191{ 193{
192 struct macb *bp = netdev_priv(dev); 194 struct macb *bp = netdev_priv(dev);
193 struct phy_device *phydev; 195 struct phy_device *phydev;
194 struct macb_platform_data *pdata;
195 int ret; 196 int ret;
196 197
197 phydev = phy_find_first(bp->mii_bus); 198 phydev = phy_find_first(bp->mii_bus);
@@ -200,14 +201,11 @@ static int macb_mii_probe(struct net_device *dev)
200 return -1; 201 return -1;
201 } 202 }
202 203
203 pdata = bp->pdev->dev.platform_data;
204 /* TODO : add pin_irq */ 204 /* TODO : add pin_irq */
205 205
206 /* attach the mac to the phy */ 206 /* attach the mac to the phy */
207 ret = phy_connect_direct(dev, phydev, &macb_handle_link_change, 0, 207 ret = phy_connect_direct(dev, phydev, &macb_handle_link_change, 0,
208 pdata && pdata->is_rmii ? 208 bp->phy_interface);
209 PHY_INTERFACE_MODE_RMII :
210 PHY_INTERFACE_MODE_MII);
211 if (ret) { 209 if (ret) {
212 netdev_err(dev, "Could not attach to PHY\n"); 210 netdev_err(dev, "Could not attach to PHY\n");
213 return ret; 211 return ret;
@@ -1244,6 +1242,52 @@ static const struct net_device_ops macb_netdev_ops = {
1244#endif 1242#endif
1245}; 1243};
1246 1244
1245#if defined(CONFIG_OF)
1246static const struct of_device_id macb_dt_ids[] = {
1247 { .compatible = "cdns,at32ap7000-macb" },
1248 { .compatible = "cdns,at91sam9260-macb" },
1249 { .compatible = "cdns,macb" },
1250 { .compatible = "cdns,pc302-gem" },
1251 { .compatible = "cdns,gem" },
1252 { /* sentinel */ }
1253};
1254
1255MODULE_DEVICE_TABLE(of, macb_dt_ids);
1256
1257static int __devinit macb_get_phy_mode_dt(struct platform_device *pdev)
1258{
1259 struct device_node *np = pdev->dev.of_node;
1260
1261 if (np)
1262 return of_get_phy_mode(np);
1263
1264 return -ENODEV;
1265}
1266
1267static int __devinit macb_get_hwaddr_dt(struct macb *bp)
1268{
1269 struct device_node *np = bp->pdev->dev.of_node;
1270 if (np) {
1271 const char *mac = of_get_mac_address(np);
1272 if (mac) {
1273 memcpy(bp->dev->dev_addr, mac, ETH_ALEN);
1274 return 0;
1275 }
1276 }
1277
1278 return -ENODEV;
1279}
1280#else
1281static int __devinit macb_get_phy_mode_dt(struct platform_device *pdev)
1282{
1283 return -ENODEV;
1284}
1285static int __devinit macb_get_hwaddr_dt(struct macb *bp)
1286{
1287 return -ENODEV;
1288}
1289#endif
1290
1247static int __init macb_probe(struct platform_device *pdev) 1291static int __init macb_probe(struct platform_device *pdev)
1248{ 1292{
1249 struct macb_platform_data *pdata; 1293 struct macb_platform_data *pdata;
@@ -1318,10 +1362,22 @@ static int __init macb_probe(struct platform_device *pdev)
1318 config |= macb_dbw(bp); 1362 config |= macb_dbw(bp);
1319 macb_writel(bp, NCFGR, config); 1363 macb_writel(bp, NCFGR, config);
1320 1364
1321 macb_get_hwaddr(bp); 1365 err = macb_get_hwaddr_dt(bp);
1322 pdata = pdev->dev.platform_data; 1366 if (err < 0)
1367 macb_get_hwaddr(bp);
1368
1369 err = macb_get_phy_mode_dt(pdev);
1370 if (err < 0) {
1371 pdata = pdev->dev.platform_data;
1372 if (pdata && pdata->is_rmii)
1373 bp->phy_interface = PHY_INTERFACE_MODE_RMII;
1374 else
1375 bp->phy_interface = PHY_INTERFACE_MODE_MII;
1376 } else {
1377 bp->phy_interface = err;
1378 }
1323 1379
1324 if (pdata && pdata->is_rmii) 1380 if (bp->phy_interface == PHY_INTERFACE_MODE_RMII)
1325#if defined(CONFIG_ARCH_AT91) 1381#if defined(CONFIG_ARCH_AT91)
1326 macb_or_gem_writel(bp, USRIO, (MACB_BIT(RMII) | 1382 macb_or_gem_writel(bp, USRIO, (MACB_BIT(RMII) |
1327 MACB_BIT(CLKEN))); 1383 MACB_BIT(CLKEN)));
@@ -1444,6 +1500,7 @@ static struct platform_driver macb_driver = {
1444 .driver = { 1500 .driver = {
1445 .name = "macb", 1501 .name = "macb",
1446 .owner = THIS_MODULE, 1502 .owner = THIS_MODULE,
1503 .of_match_table = of_match_ptr(macb_dt_ids),
1447 }, 1504 },
1448}; 1505};
1449 1506
diff --git a/drivers/net/ethernet/cadence/macb.h b/drivers/net/ethernet/cadence/macb.h
index 193107884a5..335e288f531 100644
--- a/drivers/net/ethernet/cadence/macb.h
+++ b/drivers/net/ethernet/cadence/macb.h
@@ -532,6 +532,8 @@ struct macb {
532 unsigned int link; 532 unsigned int link;
533 unsigned int speed; 533 unsigned int speed;
534 unsigned int duplex; 534 unsigned int duplex;
535
536 phy_interface_t phy_interface;
535}; 537};
536 538
537static inline bool macb_is_gem(struct macb *bp) 539static inline bool macb_is_gem(struct macb *bp)