net/at91_ether: use gpio_is_valid for phy IRQ line

Use the generic gpiolib gpio_is_valid() function to test
if the phy IRQ line GPIO is actually provided.

For non-connected or non-existing phy IRQ lines, -EINVAL
value is used for phy_irq_pin field of struct at91_eth_data.

Signed-off-by: Nicolas Ferre <nicolas.ferre@atmel.com>
Acked-by: Jean-Christophe PLAGNIOL-VILLARD <plagnioj@jcrosoft.com>
Acked-by: David S. Miller <davem@davemloft.net>
This commit is contained in:
Nicolas Ferre 2011-11-24 22:21:14 +01:00
parent 0d4f99d8b7
commit 2839038bb1
1 changed files with 13 additions and 10 deletions

View File

@ -256,8 +256,7 @@ static void enable_phyirq(struct net_device *dev)
unsigned int dsintr, irq_number; unsigned int dsintr, irq_number;
int status; int status;
irq_number = lp->board_data.phy_irq_pin; if (!gpio_is_valid(lp->board_data.phy_irq_pin)) {
if (!irq_number) {
/* /*
* PHY doesn't have an IRQ pin (RTL8201, DP83847, AC101L), * PHY doesn't have an IRQ pin (RTL8201, DP83847, AC101L),
* or board does not have it connected. * or board does not have it connected.
@ -266,6 +265,7 @@ static void enable_phyirq(struct net_device *dev)
return; return;
} }
irq_number = lp->board_data.phy_irq_pin;
status = request_irq(irq_number, at91ether_phy_interrupt, 0, dev->name, dev); status = request_irq(irq_number, at91ether_phy_interrupt, 0, dev->name, dev);
if (status) { if (status) {
printk(KERN_ERR "at91_ether: PHY IRQ %d request failed - status %d!\n", irq_number, status); 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)
unsigned int dsintr; unsigned int dsintr;
unsigned int irq_number; unsigned int irq_number;
irq_number = lp->board_data.phy_irq_pin; if (!gpio_is_valid(lp->board_data.phy_irq_pin)) {
if (!irq_number) {
del_timer_sync(&lp->check_timer); del_timer_sync(&lp->check_timer);
return; return;
} }
@ -366,6 +365,7 @@ static void disable_phyirq(struct net_device *dev)
disable_mdi(); disable_mdi();
spin_unlock_irq(&lp->lock); spin_unlock_irq(&lp->lock);
irq_number = lp->board_data.phy_irq_pin;
free_irq(irq_number, dev); /* Free interrupt handler */ free_irq(irq_number, dev); /* Free interrupt handler */
} }
@ -1078,7 +1078,7 @@ static int __init at91ether_setup(unsigned long phy_type, unsigned short phy_add
netif_carrier_off(dev); /* will be enabled in open() */ netif_carrier_off(dev); /* will be enabled in open() */
/* If board has no PHY IRQ, use a timer to poll the PHY */ /* If board has no PHY IRQ, use a timer to poll the PHY */
if (!lp->board_data.phy_irq_pin) { if (!gpio_is_valid(lp->board_data.phy_irq_pin)) {
init_timer(&lp->check_timer); init_timer(&lp->check_timer);
lp->check_timer.data = (unsigned long)dev; lp->check_timer.data = (unsigned long)dev;
lp->check_timer.function = at91ether_check_link; lp->check_timer.function = at91ether_check_link;
@ -1170,7 +1170,8 @@ static int __devexit at91ether_remove(struct platform_device *pdev)
struct net_device *dev = platform_get_drvdata(pdev); struct net_device *dev = platform_get_drvdata(pdev);
struct at91_private *lp = netdev_priv(dev); struct at91_private *lp = netdev_priv(dev);
if (lp->board_data.phy_irq_pin >= 32) if (gpio_is_valid(lp->board_data.phy_irq_pin) &&
lp->board_data.phy_irq_pin >= 32)
gpio_free(lp->board_data.phy_irq_pin); gpio_free(lp->board_data.phy_irq_pin);
unregister_netdev(dev); unregister_netdev(dev);
@ -1189,11 +1190,12 @@ static int at91ether_suspend(struct platform_device *pdev, pm_message_t mesg)
{ {
struct net_device *net_dev = platform_get_drvdata(pdev); struct net_device *net_dev = platform_get_drvdata(pdev);
struct at91_private *lp = netdev_priv(net_dev); struct at91_private *lp = netdev_priv(net_dev);
int phy_irq = lp->board_data.phy_irq_pin;
if (netif_running(net_dev)) { if (netif_running(net_dev)) {
if (phy_irq) if (gpio_is_valid(lp->board_data.phy_irq_pin)) {
int phy_irq = lp->board_data.phy_irq_pin;
disable_irq(phy_irq); disable_irq(phy_irq);
}
netif_stop_queue(net_dev); netif_stop_queue(net_dev);
netif_device_detach(net_dev); netif_device_detach(net_dev);
@ -1207,7 +1209,6 @@ static int at91ether_resume(struct platform_device *pdev)
{ {
struct net_device *net_dev = platform_get_drvdata(pdev); struct net_device *net_dev = platform_get_drvdata(pdev);
struct at91_private *lp = netdev_priv(net_dev); struct at91_private *lp = netdev_priv(net_dev);
int phy_irq = lp->board_data.phy_irq_pin;
if (netif_running(net_dev)) { if (netif_running(net_dev)) {
clk_enable(lp->ether_clk); clk_enable(lp->ether_clk);
@ -1215,9 +1216,11 @@ static int at91ether_resume(struct platform_device *pdev)
netif_device_attach(net_dev); netif_device_attach(net_dev);
netif_start_queue(net_dev); netif_start_queue(net_dev);
if (phy_irq) if (gpio_is_valid(lp->board_data.phy_irq_pin)) {
int phy_irq = lp->board_data.phy_irq_pin;
enable_irq(phy_irq); enable_irq(phy_irq);
} }
}
return 0; return 0;
} }