Linux目录下相关目录为:
linux-2.6.30/Documentation/networking/phy.txt 关于PHY的介绍
linux-2.6.30/drivers/net/phy/davicom.c DAVICOM芯片相关
linux-2.6.30/include/linux/phy.h phy头文件定义
davicom.c 文件的部分代码如下:
static struct phy_driver dm9161e_driver = {
.phy_id = 0x0181b880,
.name = "Davicom DM9161E",
.phy_id_mask = 0x0ffffff0,
.features = PHY_BASIC_FEATURES,
.config_init = dm9161_config_init,
.config_aneg = dm9161_config_aneg,
.read_status = genphy_read_status,
.driver = { .owner = THIS_MODULE,},
};
static struct phy_driver dm9161a_driver = {
.phy_id = 0x0181b8a0,
.name = "Davicom DM9161A",
.phy_id_mask = 0x0ffffff0,
.features = PHY_BASIC_FEATURES,
.config_init = dm9161_config_init,
.config_aneg = dm9161_config_aneg,
.read_status = genphy_read_status,
.driver = { .owner = THIS_MODULE,},
};
static struct phy_driver dm9131_driver = {
.phy_id = 0x00181b80,
.name = "Davicom DM9131",
.phy_id_mask = 0x0ffffff0,
.features = PHY_BASIC_FEATURES,
.flags = PHY_HAS_INTERRUPT,
.config_aneg = genphy_config_aneg,
.read_status = genphy_read_status,
.ack_interrupt = dm9161_ack_interrupt,
.config_intr = dm9161_config_intr,
.driver = { .owner = THIS_MODULE,},
};
static int __init davicom_init(void)
{
int ret;
ret = phy_driver_register(&dm9161e_driver);
if (ret)
goto err1;
ret = phy_driver_register(&dm9161a_driver);
if (ret)
goto err2;
ret = phy_driver_register(&dm9131_driver);
if (ret)
goto err3;
return 0;
err3:
phy_driver_unregister(&dm9161a_driver);
err2:
phy_driver_unregister(&dm9161e_driver);
err1:
return ret;
}
static void __exit davicom_exit(void)
{
phy_driver_unregister(&dm9161e_driver);
phy_driver_unregister(&dm9161a_driver);
phy_driver_unregister(&dm9131_driver);
}
module_init(davicom_init);
module_exit(davicom_exit);
在Linux内核配置中,选择DAVICOM公司PHY芯片的支持。
make menuconfig
Device Drivers-->Network device Support-->PHY Device support and infrastructure-->Drivers for DAVICOM Phy
这样在Linux的初始化中,会加载DAVICOM PHY芯片驱动module_init(davicom_init)。
所以如果需要再添加别的DM9161系列的PHY芯片支持,做的工作还是比较简单的。
第一:建立一个struct phy_driver的结构体:
static struct phy_driver dm9161c_driver = {
.phy_id = 0x.................,
.name = "Davicom DM9161C",
.phy_id_mask = 0x0ffffff0,
.features = PHY_BASIC_FEATURES,
.config_init = dm9161_config_init,
.config_aneg = dm9161_config_aneg,
.read_status = genphy_read_status,
.driver = { .owner = THIS_MODULE,},
};
第二:static int __init davicom_init(void)函数中增加相应的注册函数 ret = phy_driver_register(&dm9161c_driver),并添加相关的错误处理
第三:static void __exit davicom_exit(void)函数中添加卸载函数.