网络指示灯修改
类别
需求
索引类别
网络指示灯状态
问题描述
平台是RT1296,目前百/千兆网络指示灯的状态是一样的(绿灯常亮,橙灯闪烁),为了肉眼可以区分,在网络指示灯的状态修改为在百兆的状态下绿灯灭、橙灯闪烁,千兆网络指示灯状态为绿灯常亮,橙灯闪烁。
代码关联
对应的代码修改部分如下:
//对应DTS的配置
@@ -166,3 +166,9 @@
mute_gpio = <&rtk_misc_gpio 7 1 1>;
status = "okay";
};
+
+// gmac: This configuration is required only for Gigabit network cards.
+&nic {
+ status = "okay";
+ phy-max-speed = <1000>;
+};
diff --git a/drivers/net/ethernet/realtek/r8169soc.c b/drivers/net/ethernet/realtek/r8169soc.c
index 69c7bfa..4f12154 100644
--- a/drivers/net/ethernet/realtek/r8169soc.c
+++ b/drivers/net/ethernet/realtek/r8169soc.c
@@ -885,6 +885,7 @@ struct rtl8169_private {
u32 monitor_en;
u32 macaddr1;
u16 macaddr2;
+ u16 phy_max_speed; /* 100: 100M, 1000: 1000M*/
};
MODULE_AUTHOR("Realtek and the Linux r8169 crew <netdev@vger.kernel.org>");
@@ -1575,17 +1576,22 @@ static void rtl_link_chg_patch(struct rtl8169_private *tp)
if (!netif_running(dev))
return;
//0x000670#$ (最后两位分别控制绿灯和橙灯,最后一位代表绿色指示灯,倒数第二位是代表橙色指示灯,数值代表的意思是网络指示灯闪烁的频率,数值越大闪烁频率越大)
+ if(tp->phy_max_speed == 1000) {
+ if (RTL_R8(PHYstatus) & _1000bpsF) {
+ RTL_W32(LEDSEL, 0x000670e6);
+ } else if (RTL_R8(PHYstatus) & _100bps) {
+ RTL_W32(LEDSEL, 0x000670e0);
+ } else if (RTL_R8(PHYstatus) & _10bps) {
+ RTL_W32(LEDSEL, 0x000670e0);
+ } else {
+ RTL_W32(LEDSEL, 0x00067066);
+ netif_info(tp, ifdown, dev, "xcyan report: Unknown internet speed (<10Mbps or >1000Mbps)\n");
+ }
+ printk("Net card supports 1000M\n");
+ } else {
+ printk("Net card supports 100M\n");
+ }
if (tp->mac_version == RTL_GIGA_MAC_VER_34 ||
tp->mac_version == RTL_GIGA_MAC_VER_38) {
@@ -8081,6 +8087,7 @@ rtl_init_one(struct platform_device *pdev)
int rc;
int rtl_config;
int mac_version;
+ int phy_max_speed;
u32 tmp;
int irq;
int retry;
@@ -8123,6 +8130,9 @@ rtl_init_one(struct platform_device *pdev)
if (of_property_read_u32(pdev->dev.of_node, "ext-phy-id", &ext_phy_id)) {
dprintk("%s can't get RGMII external PHY ID", __func__);
}
//通过设备节点和属性名,获取DTS中的配置
+ if (of_property_read_u32(pdev->dev.of_node, "phy-max-speed", &phy_max_speed)) {
+ dprintk("%s can't get RGMII PHY max speed", __func__);
+ }
if (soc_is_rtk1195() && (realtek_rev() == RTK1195_REV_A)) {
if (of_property_read_u32(pdev->dev.of_node, "rtl-features", &(cfg->features))) {
cfg->features &= ~RTL_FEATURE_GMII;
@@ -8207,6 +8217,7 @@ rtl_init_one(struct platform_device *pdev)
tp->rgmii_rx_delay = rgmii_rx_delay;
tp->ext_phy_id = ext_phy_id;
tp->monitor_en = 0x8020080; /* disable PHY interrupt, disable EEE interrupts, and enable timer monitor */
+ tp->phy_max_speed = phy_max_speed;
mii = &tp->mii;
mii->dev = ndev;
知识拓展
参考资料:
https://www.sohu.com/a/319791719_227417
改进建议
工作记录。。。。。