iMX257获取PHY的link状态

处理器:iMX257

以太网PHY:KSZ8041NL

操作系统:linux 2.6.31


获取PHY link状态,主要通过访问iMX257 FEC功能块的MMFR寄存器(使用方法参考IMX25RM 25.3.5.6节)。步骤如下:

1)用户驱动向MMFR寄存器写入读对应寄存器命令,如01_10_00000_00001_10_0000000000000000。

2)fec驱动响应FEC_ENET_MII中断,读取PHY的0x01寄存器的值,提取link status。

3)用户驱动等待fec发出的完成标志位,读取link status。


用户驱动:
#define FEC_REG_BASE_ADDR    0x50038000
#define FEC_REG_SPACE    0x100
#define REG_MMFR    0x40
fec_reg_base_addr = (unsigned long) ioremap(FEC_REG_BASE_ADDR, FEC_REG_SPACE);

//net link is up when return 1, down when return 0
static void netlink_checking(unsigned short *netlink_stat) {
flag_usrRead = 1;
__raw_writel(0x60060000, (fec_reg_base_addr + REG_MMFR));
udelay(2);
if(flag_PhyStateReady )
{
printk ("lxi_front_panel, flag_PhyStateReady = %d, state_PhyLink = %d", flag_PhyStateReady, state_PhyLink);
flag_usrRead = 0;
*netlink_stat = state_PhyLink;
flag_PhyStateReady  = 0;
}
}


内核程序fec.h中增加全局变量定义:
unsigned int flag_usrRead = 0;
unsigned int flag_PhyStateReady = 0;
unsigned int state_PhyLink = 0;
EXPORT_SYMBOL(flag_usrRead);
EXPORT_SYMBOL(flag_PhyStateReady);
EXPORT_SYMBOL(state_PhyLink);


内核程序fec.c中断服务程序增加代码:
if (int_events & FEC_ENET_MII) {
   ret = IRQ_HANDLED;
 
   if (flag_usrRead == 1)
    {
int_mii_data = readl(fep->hwp + FEC_MII_DATA);
printk("int_mii_data = %x\n",int_mii_data);
state_PhyLink = (int_mii_data >> 2) & 0x1;
flag_PhyStateReady = 1;
printk("state_PhyLink = %d; flag_PhyStateReady = %d\n",state_PhyLink,flag_PhyStateReady);
    }
   else

fec_enet_mii(dev);
}


阅读更多
想对作者说点什么? 我来说一句
相关热词

没有更多推荐了,返回首页

关闭
关闭
关闭