转:http://minglu2000.spaces.live.com/blog/cns!C66FB7FDEE9C6239!111.entry
AT91RM9200DK开发板中DM9161的一个小问题
原先一直没有z注意,在将AT91RM9200与PC机用网线连接,系统上电启动后,一切工作正常.但是断开后,再启动系统,接上网线,发现网络芯片不正常工作.我一直把它当做硬件工作不好(想想真傻).
当仔细研究是才发现,在AT91RM9200中处理DM9161时需要两个中断,一个中断是用来处理正常的发送接收等的功能的,而另外一个,则可以完成网线是否连接处理的.(一片网络芯片用了两个中断,好奢侈!!呵呵)
仔细阅读了源代码并结合电路图才找到解决的办法.
在源代码中有一个函数enable_phyirq(),其完整代码如下:
static void enable_phyirq(struct net_device *dev, AT91PS_EMAC regs)
{
struct at91_private *lp = (struct at91_private *) dev->priv;
unsigned int dsintr;
if (lp->phy_type == MII_RTL8201_ID) /* RTL8201 does not have an interrupt */
return;
#ifdef CONFIG_MACH_CSB337
(void) at91rm9200_gpio_request_irq(AT91C_ID_PIOC, 2, 1, at91ether_phy_interrupt, dev);
#else
(void) at91rm9200_gpio_request_irq(AT91C_ID_PIOC, 4, 1, at91ether_phy_interrupt, dev);
#endif
spin_lock_irq(&lp->lock);
enable_mdi(regs);
if (lp->phy_type == MII_DM9161_ID) { /* for Davicom PHY */
read_phy(regs, lp->phy_address, MII_DSINTR_REG, &dsintr);
dsintr = dsintr & ~0xf00; /* clear bits 8..11 */
write_phy(regs, lp->phy_address, MII_DSINTR_REG, dsintr);
}
else if (lp->phy_type == MII_LXT971A_ID) { /* for Intel PHY */
read_phy(regs, lp->phy_address, MII_ISINTE_REG, &dsintr);
dsintr = dsintr | 0xf2; /* set bits 1, 4..7 */
write_phy(regs, lp->phy_address, MII_ISINTE_REG, dsintr);
}
disable_mdi(regs);
spin_unlock_irq(&lp->lock);
}
在这里,我们需要对申请的中断根据自己的电路图进行设置,因为我用的是PB29,因为此脚和IRQ0复用,所以我在此可以有两种修改的方法:
1:把
#ifdef CONFIG_MACH_CSB337
(void) at91rm9200_gpio_request_irq(AT91C_ID_PIOC, 2, 1, at91ether_phy_interrupt, dev);
#else
(void) at91rm9200_gpio_request_irq(AT91C_ID_PIOC, 4, 1, at91ether_phy_interrupt, dev);
#endif
改为:
#ifdef CONFIG_MACH_CSB337
(void) at91rm9200_gpio_request_irq(AT91C_ID_PIOC, 2, 1, at91ether_phy_interrupt, dev);
#else
(void) at91rm9200_gpio_request_irq(AT91C_ID_PIOB, 29, 1, at91ether_phy_interrupt, dev);
#endif
2: 去掉
#ifdef CONFIG_MACH_CSB337
(void) at91rm9200_gpio_request_irq(AT91C_ID_PIOC, 2, 1, at91ether_phy_interrupt, dev);
#else
(void) at91rm9200_gpio_request_irq(AT91C_ID_PIOC, 4, 1, at91ether_phy_interrupt, dev);
#endif
添加
if (request_irq(25,&at91ether_phy_interrupt,SA_INTERRUPT,dev->name,dev))
return -EAGAIN;
如此修改以后,就不会出现我碰到的问题了.
当仔细研究是才发现,在AT91RM9200中处理DM9161时需要两个中断,一个中断是用来处理正常的发送接收等的功能的,而另外一个,则可以完成网线是否连接处理的.(一片网络芯片用了两个中断,好奢侈!!呵呵)
仔细阅读了源代码并结合电路图才找到解决的办法.
在源代码中有一个函数enable_phyirq(),其完整代码如下:
static void enable_phyirq(struct net_device *dev, AT91PS_EMAC regs)
{
struct at91_private *lp = (struct at91_private *) dev->priv;
unsigned int dsintr;
if (lp->phy_type == MII_RTL8201_ID) /* RTL8201 does not have an interrupt */
return;
#ifdef CONFIG_MACH_CSB337
(void) at91rm9200_gpio_request_irq(AT91C_ID_PIOC, 2, 1, at91ether_phy_interrupt, dev);
#else
(void) at91rm9200_gpio_request_irq(AT91C_ID_PIOC, 4, 1, at91ether_phy_interrupt, dev);
#endif
spin_lock_irq(&lp->lock);
enable_mdi(regs);
if (lp->phy_type == MII_DM9161_ID) { /* for Davicom PHY */
read_phy(regs, lp->phy_address, MII_DSINTR_REG, &dsintr);
dsintr = dsintr & ~0xf00; /* clear bits 8..11 */
write_phy(regs, lp->phy_address, MII_DSINTR_REG, dsintr);
}
else if (lp->phy_type == MII_LXT971A_ID) { /* for Intel PHY */
read_phy(regs, lp->phy_address, MII_ISINTE_REG, &dsintr);
dsintr = dsintr | 0xf2; /* set bits 1, 4..7 */
write_phy(regs, lp->phy_address, MII_ISINTE_REG, dsintr);
}
disable_mdi(regs);
spin_unlock_irq(&lp->lock);
}
在这里,我们需要对申请的中断根据自己的电路图进行设置,因为我用的是PB29,因为此脚和IRQ0复用,所以我在此可以有两种修改的方法:
1:把
#ifdef CONFIG_MACH_CSB337
(void) at91rm9200_gpio_request_irq(AT91C_ID_PIOC, 2, 1, at91ether_phy_interrupt, dev);
#else
(void) at91rm9200_gpio_request_irq(AT91C_ID_PIOC, 4, 1, at91ether_phy_interrupt, dev);
#endif
改为:
#ifdef CONFIG_MACH_CSB337
(void) at91rm9200_gpio_request_irq(AT91C_ID_PIOC, 2, 1, at91ether_phy_interrupt, dev);
#else
(void) at91rm9200_gpio_request_irq(AT91C_ID_PIOB, 29, 1, at91ether_phy_interrupt, dev);
#endif
2: 去掉
#ifdef CONFIG_MACH_CSB337
(void) at91rm9200_gpio_request_irq(AT91C_ID_PIOC, 2, 1, at91ether_phy_interrupt, dev);
#else
(void) at91rm9200_gpio_request_irq(AT91C_ID_PIOC, 4, 1, at91ether_phy_interrupt, dev);
#endif
添加
if (request_irq(25,&at91ether_phy_interrupt,SA_INTERRUPT,dev->name,dev))
return -EAGAIN;
如此修改以后,就不会出现我碰到的问题了.