RK3566 Android 11平台上适配YT8512C 100M PHY

2023-12-30 07:52

本文主要是介绍RK3566 Android 11平台上适配YT8512C 100M PHY,希望对大家解决编程问题提供一定的参考价值,需要的开发者们随着小编来一起学习吧!

 

RK3566代码之前适配的1000M IC RTL8211F ,
现在需要在之前的基础上修改PHY IC 为裕泰的YT8512C
----------------------------------------------------------------------+//将1000M 的配置关掉,改为100M 配置,查看RK3566 资料关于以太网的配置即可知道如何修改
#if 0
&gmac1 {phy-mode = "rgmii";clock_in_out = "input";snps,reset-gpio = <&gpio4 RK_PC2 GPIO_ACTIVE_LOW>;snps,reset-active-low;/* Reset time is 20ms, 100ms for rtl8211f */snps,reset-delays-us = <0 20000 100000>;assigned-clocks = <&cru SCLK_GMAC1_RX_TX>, <&cru SCLK_GMAC1>;assigned-clock-parents =  <&cru SCLK_GMAC1_RGMII_SPEED>, <&gmac1_clkin>;assigned-clock-rates = <0>, <125000000>;pinctrl-names = "default";pinctrl-0 = <&gmac1m1_miim&gmac1m1_tx_bus2&gmac1m1_rx_bus2&gmac1m1_rgmii_clk&gmac1m1_rgmii_bus&gmac1m1_clkinout>;tx_delay = <0x4b>;rx_delay = <0x2b>;phy-handle = <&rgmii_phy1>;status = "okay";
};
#else
//gmac1m0
&gmac1_clkin {clock-frequency = <50000000>;
};
&gmac1 {phy-mode = "rmii";clock_in_out = "input";snps,reset-gpio = <&gpio4 RK_PC2 GPIO_ACTIVE_LOW>;snps,reset-active-low;/* Reset time is 20ms, 100ms for rtl8211f */snps,reset-delays-us = <0 20000 100000>;assigned-clocks = <&cru SCLK_GMAC1_RX_TX>, <&cru SCLK_GMAC1>;assigned-clock-parents = <&cru SCLK_GMAC1_RMII_SPEED>, <&gmac1_clkin>;//assigned-clock-rates = <0>, <50000000>;pinctrl-names = "default";pinctrl-0 = <&gmac1m0_miim&gmac1m0_clkinout&gmac1m0_tx_bus2&gmac1m0_rx_bus2>;//tx_delay = <0x4f>;//rx_delay = <0x26>;phy-handle = <&rmii_phy1>;status = "okay";
};#endif+//rgmii 1000M 改为100M
-&mdio1 {
-	rgmii_phy1: phy@0 {
-		compatible = "ethernet-phy-ieee802.3-c22";
-		reg = <0x0>;
-	};
-};+&mdio1 {
+	rmii_phy1: phy@0 {
+		compatible = "ethernet-phy-ieee802.3-c22";
+		reg = <0x0>;
+	};
+};//修改1000M 为100M ETH 的VDDIO 需要从1.8V 改为3.3V
&pmu_io_domains {status = "okay";pmuio2-supply = <&vcc_3v3>;vccio1-supply = <&vcc_3v3>;vccio3-supply = <&vcc_3v3>;vccio4-supply = <&vcc_1v8>;vccio5-supply = <&vcc_3v3>;-vccio6-supply = <&vcc_1v8>;+vccio6-supply = <&vcc_3v3>;vccio7-supply = <&vcc_3v3>;
};-----------------------------
[   23.957084] rk_gmac-dwmac fe010000.ethernet eth0: No Safety Features support found
[   23.957124] rk_gmac-dwmac fe010000.ethernet eth0: IEEE 1588-2008 Advanced Timestamp supported
[   23.958316] rk_gmac-dwmac fe010000.ethernet eth0: registered PTP clock
[   23.960237] IPv6: ADDRCONF(NETDEV_UP): eth0: link is not ready[ 1609.817567] rk_gmac-dwmac fe010000.ethernet eth0: Link is Up - 100Mbps/Full - flow control rx/tx
[ 1609.817709] IPv6: ADDRCONF(NETDEV_CHANGE): eth0: link becomes ready
-----------------------------
参照文档修改,发现以太网初始化正常,节点eth0 正常生成,也能够ping通数据2.接下来需要修改 以太网的网络接口状态灯:根据数据规格书:LED0 0x40c0寄存器写0x30 LED1 0x40c3寄存器写0x1300commit bd71fd55f47f18acb35f8974ebaf6dd696ba7738
Author: amediatech <jiangsai@amediatech.cn>
Date:   Wed Dec 27 17:53:17 2023 +0800modify led controldiff --git a/kernel/drivers/net/ethernet/stmicro/stmmac/stmmac_main.c b/kernel/drivers/net/ethernet/stmicro/stmmac/stmmac_main.c
index e75d44b987..f1f304e6f2 100644
--- a/kernel/drivers/net/ethernet/stmicro/stmmac/stmmac_main.c
+++ b/kernel/drivers/net/ethernet/stmicro/stmmac/stmmac_main.c
@@ -26,6 +26,7 @@#include <linux/clk.h>#include <linux/kernel.h>
+#include <linux/version.h>#include <linux/interrupt.h>#include <linux/ip.h>#include <linux/tcp.h>
@@ -57,7 +58,21 @@#define	STMMAC_ALIGN(x)		ALIGN(ALIGN(x, SMP_CACHE_BYTES), 16)#define	TSO_MAX_BUFF_SIZE	(SZ_16K - 1)
-
+#define REG_DEBUG_ADDR_OFFSET           0x1e
+#define REG_DEBUG_DATA                  0x1f
+#define YT8512_LED0_ACT_BLK_IND         0x1000
+#define YT8512_LED0_DIS_LED_AN_TRY      0x0001
+#define YT8512_LED0_BT_BLK_EN           0x0002
+#define YT8512_LED0_HT_BLK_EN           0x0004
+#define YT8512_LED0_COL_BLK_EN          0x0008
+#define YT8512_LED0_BT_ON_EN            0x0010
+#define YT8512_LED1_BT_ON_EN            0x0010
+#define YT8512_LED1_TXACT_BLK_EN        0x0100
+#define YT8512_LED1_RXACT_BLK_EN        0x0200
+#define YT8512_EXTREG_LED0              0x40c0
+#define YT8512_EXTREG_LED1              0x40c3
+//#define RTL_8211F_PHY_ID        0x001cc916
+#define YT8512C_PHY_ID	0x00000128/* Module parameters */#define TX_TIMEO	5000static int watchdog = TX_TIMEO;
@@ -4270,6 +4285,122 @@ static int stmmac_hw_init(struct stmmac_priv *priv)return 0;}
+#if (KERNEL_VERSION(5, 5, 0) > LINUX_VERSION_CODE)
+static inline void phy_lock_mdio_bus(struct phy_device *phydev)
+{
+#if (KERNEL_VERSION(4, 5, 0) > LINUX_VERSION_CODE)
+    mutex_lock(&phydev->bus->mdio_lock);
+#else
+    mutex_lock(&phydev->mdio.bus->mdio_lock);
+#endif
+}
+ 
+static inline void phy_unlock_mdio_bus(struct phy_device *phydev)
+{
+#if (KERNEL_VERSION(4, 5, 0) > LINUX_VERSION_CODE)
+    mutex_unlock(&phydev->bus->mdio_lock);
+#else
+    mutex_unlock(&phydev->mdio.bus->mdio_lock);
+#endif
+}
+#endif
+
+#if (KERNEL_VERSION(4, 16, 0) > LINUX_VERSION_CODE)
+static inline int __phy_read(struct phy_device *phydev, u32 regnum)
+{
+#if (KERNEL_VERSION(4, 5, 0) > LINUX_VERSION_CODE)
+        struct mii_bus *bus = phydev->bus;
+        int addr = phydev->addr;
+        return bus->read(bus, phydev->addr, regnum);
+#else
+        struct mii_bus *bus = phydev->mdio.bus;
+        int addr = phydev->mdio.addr;
+#endif
+        return bus->read(bus, addr, regnum);
+}
+
+static inline int __phy_write(struct phy_device *phydev, u32 regnum, u16 val)
+{
+#if (KERNEL_VERSION(4, 5, 0) > LINUX_VERSION_CODE)
+        struct mii_bus *bus = phydev->bus;
+        int addr = phydev->addr;
+#else
+        struct mii_bus *bus = phydev->mdio.bus;
+        int addr = phydev->mdio.addr;
+#endif
+        return bus->write(bus, addr, regnum, val);
+}
+#endif
+
+static int ytphy_read_ext(struct phy_device *phydev, u32 regnum)
+{
+    int ret;
+    
+    phy_lock_mdio_bus(phydev);
+    ret = __phy_write(phydev, REG_DEBUG_ADDR_OFFSET, regnum);
+    if (ret < 0)
+        goto err_handle;
+ 
+    ret = __phy_read(phydev, REG_DEBUG_DATA);
+    if (ret < 0)
+        goto err_handle;
+    
+err_handle:
+    phy_unlock_mdio_bus(phydev);
+    return ret;
+}
+ 
+static int ytphy_write_ext(struct phy_device *phydev, u32 regnum, u16 val)
+{
+    int ret;
+ 
+    phy_lock_mdio_bus(phydev);
+    ret = __phy_write(phydev, REG_DEBUG_ADDR_OFFSET, regnum);
+    if (ret < 0)
+        goto err_handle;
+ 
+    ret = __phy_write(phydev, REG_DEBUG_DATA, val);
+    if (ret < 0)
+        goto err_handle;
+    
+err_handle:
+    phy_unlock_mdio_bus(phydev);
+    return ret;
+}
+
+
+static int phy_yt8512c_led_fixup(struct phy_device *phydev)
+{
+	int ret;
+	int val;
+	int mask;
+	printk("-------------------------%s in.\n", __func__);
+	val = ytphy_read_ext(phydev, YT8512_EXTREG_LED0); //GREEN
+	printk("--------------------YT8512_EXTREG_LED0 read val is %d.\n",val);  //785 = 0x311;
+	if (val < 0)
+		return val;
+	//need set 0x30
+    	val |= YT8512_LED0_ACT_BLK_IND;
+	mask = YT8512_LED0_DIS_LED_AN_TRY | YT8512_LED0_BT_BLK_EN | 
+		YT8512_LED0_HT_BLK_EN | YT8512_LED0_COL_BLK_EN | 
+		YT8512_LED0_BT_ON_EN;
+	val &= ~mask;
+	printk("--------------------YT8512_EXTREG_LED0 write val is %d.\n",val);  //800 = 0x320
+	ret = ytphy_write_ext(phydev, YT8512_EXTREG_LED0, 0x30);
+	if (ret < 0)
+		return ret;
+	val = ytphy_read_ext(phydev, YT8512_EXTREG_LED1); //YELLOW 
+	printk("--------------------YT8512_EXTREG_LED1 read val is %d.\n",val);
+	if (val < 0)
+		return val;
+	//need set LED1 0x1300
+	val |= YT8512_LED1_BT_ON_EN;
+	mask = YT8512_LED1_TXACT_BLK_EN | YT8512_LED1_RXACT_BLK_EN;
+	val &= ~mask;
+	printk("--------------------YT8512_EXTREG_LED1 write val is %d.\n",val);
+	ret = ytphy_write_ext(phydev, YT8512_EXTREG_LED1, 0x1300);
+	return ret;
+}/*** stmmac_dvr_probe
@@ -4463,7 +4594,10 @@ int stmmac_dvr_probe(struct device *device,netdev_warn(priv->dev, "%s: failed debugFS registration\n",__func__);#endif
-
+ret = phy_register_fixup_for_uid(YT8512C_PHY_ID, 0xffffffff, phy_yt8512c_led_fixup);
+if (ret){
+		printk("Cannot register PHY board fixup.\n");
+	}return ret;error_netdev_register:

这篇关于RK3566 Android 11平台上适配YT8512C 100M PHY的文章就介绍到这儿,希望我们推荐的文章对编程师们有所帮助!



http://www.chinasem.cn/article/552193

相关文章

Android中Dialog的使用详解

《Android中Dialog的使用详解》Dialog(对话框)是Android中常用的UI组件,用于临时显示重要信息或获取用户输入,本文给大家介绍Android中Dialog的使用,感兴趣的朋友一起... 目录android中Dialog的使用详解1. 基本Dialog类型1.1 AlertDialog(

Android Kotlin 高阶函数详解及其在协程中的应用小结

《AndroidKotlin高阶函数详解及其在协程中的应用小结》高阶函数是Kotlin中的一个重要特性,它能够将函数作为一等公民(First-ClassCitizen),使得代码更加简洁、灵活和可... 目录1. 引言2. 什么是高阶函数?3. 高阶函数的基础用法3.1 传递函数作为参数3.2 Lambda

Android自定义Scrollbar的两种实现方式

《Android自定义Scrollbar的两种实现方式》本文介绍两种实现自定义滚动条的方法,分别通过ItemDecoration方案和独立View方案实现滚动条定制化,文章通过代码示例讲解的非常详细,... 目录方案一:ItemDecoration实现(推荐用于RecyclerView)实现原理完整代码实现

Android App安装列表获取方法(实践方案)

《AndroidApp安装列表获取方法(实践方案)》文章介绍了Android11及以上版本获取应用列表的方案调整,包括权限配置、白名单配置和action配置三种方式,并提供了相应的Java和Kotl... 目录前言实现方案         方案概述一、 androidManifest 三种配置方式

Android WebView无法加载H5页面的常见问题和解决方法

《AndroidWebView无法加载H5页面的常见问题和解决方法》AndroidWebView是一种视图组件,使得Android应用能够显示网页内容,它基于Chromium,具备现代浏览器的许多功... 目录1. WebView 简介2. 常见问题3. 网络权限设置4. 启用 JavaScript5. D

Android如何获取当前CPU频率和占用率

《Android如何获取当前CPU频率和占用率》最近在优化App的性能,需要获取当前CPU视频频率和占用率,所以本文小编就来和大家总结一下如何在Android中获取当前CPU频率和占用率吧... 最近在优化 App 的性能,需要获取当前 CPU视频频率和占用率,通过查询资料,大致思路如下:目前没有标准的

Android开发中gradle下载缓慢的问题级解决方法

《Android开发中gradle下载缓慢的问题级解决方法》本文介绍了解决Android开发中Gradle下载缓慢问题的几种方法,本文给大家介绍的非常详细,感兴趣的朋友跟随小编一起看看吧... 目录一、网络环境优化二、Gradle版本与配置优化三、其他优化措施针对android开发中Gradle下载缓慢的问

Android 悬浮窗开发示例((动态权限请求 | 前台服务和通知 | 悬浮窗创建 )

《Android悬浮窗开发示例((动态权限请求|前台服务和通知|悬浮窗创建)》本文介绍了Android悬浮窗的实现效果,包括动态权限请求、前台服务和通知的使用,悬浮窗权限需要动态申请并引导... 目录一、悬浮窗 动态权限请求1、动态请求权限2、悬浮窗权限说明3、检查动态权限4、申请动态权限5、权限设置完毕后

Android里面的Service种类以及启动方式

《Android里面的Service种类以及启动方式》Android中的Service分为前台服务和后台服务,前台服务需要亮身份牌并显示通知,后台服务则有启动方式选择,包括startService和b... 目录一句话总结:一、Service 的两种类型:1. 前台服务(必须亮身份牌)2. 后台服务(偷偷干

Android kotlin语言实现删除文件的解决方案

《Androidkotlin语言实现删除文件的解决方案》:本文主要介绍Androidkotlin语言实现删除文件的解决方案,在项目开发过程中,尤其是需要跨平台协作的项目,那么删除用户指定的文件的... 目录一、前言二、适用环境三、模板内容1.权限申请2.Activity中的模板一、前言在项目开发过程中,尤