当前位置: 首页 > news >正文

rk3568 phy驱动调式_phy寄存器

1,phy调式相关寄存器

root@ubuntu2004:~# cat /sys/bus/mdio_bus/devices/stmmac-0\:00/phy_id
0x001cc916
root@ubuntu2004:~# cat /sys/bus/mdio_bus/devices/stmmac-0\:00/phy_interface
rgmii

root@ubuntu2004:~# cat /sys/bus/mdio_bus/devices/stmmac-0\:00/phy_registers
 0: 0x1040
 1: 0x79ad
 2: 0x1c
 3: 0xc916
 4: 0xde1
 5: 0xcde1
 6: 0x6f
 7: 0x2801
 8: 0x5282
 9: 0x200
10: 0x0
11: 0x0
12: 0x0
13: 0x4003
14: 0x400
15: 0x2000
16: 0x23
17: 0x0
18: 0x0
19: 0x0
20: 0x0
21: 0xe00
22: 0xf00
23: 0xf00
24: 0x311e
25: 0x863
26: 0x31dc
27: 0x2
28: 0x0
29: 0x0
30: 0x0
31: 0xa42
 

写寄存器: 

root@ubuntu2004:~# echo 00 abcd > /sys/bus/mdio_bus/devices/stmmac-0:00/phy_registers 
bash: /sys/bus/mdio_bus/devices/stmmac-0:00/phy_registers : Permission denied

查看权限后修改权限: 

root@ubuntu2004:/sys/bus/mdio_bus/devices/stmmac-0:00# chmod 777 phy_registers
root@ubuntu2004:/sys/bus/mdio_bus/devices/stmmac-0:00# ls -al
-rwxrwxrwx 1 root root 4096 Mar  2 21:06 phy_registers

写测试:

root@untu2004:/sys/bus/mdio_bus/devices/stmmac-0:00# echo 0x00 0x1140 > phy_registers
root@ubuntu2004:/sys/bus/mdio_bus/devices/stmmac-0:00#
root@ubuntu2004:/sys/bus/mdio_bus/devices/stmmac-0:00# cat phy_registers
 0: 0x1140
 1: 0x7989

2,代码分析:rk3568\rk356x-linux\kernel\drivers\net\phy\phy_device.c

读寄存器:

static ssize_t phy_registers_show(struct device *dev, struct device_attribute *attr, char *buf)
{
    struct phy_device *phydev = to_phy_device(dev);
    int index;

    for (index = 0; index < 32; index++)
        sprintf(buf, "%s%2d: 0x%x\n", buf, index,
            phy_read(phydev, index));

    return strlen(buf);
}

写寄存器

 static ssize_t phy_registers_store(struct device *dev, struct device_attribute *attr,
            const char *buf, size_t count){
    struct phy_device *phydev = to_phy_device(dev);
    int index = 0, val = 0;
    char tmp[32];
    char *data;

    if (count >= sizeof(tmp))
        goto out;

    memset(tmp, 0, sizeof(tmp));
    memcpy(tmp, buf, count);

    data = tmp;
    data = strstr(data, " ");
    if (!data)
        goto out;
    *data = 0;
    data++;

    if (kstrtoint(tmp, 0, &index) || index >= 32)
        goto out;

    if (kstrtoint(data, 0, &val) || val > 0xffff)
        goto out;

    pr_info("Set Ethernet PHY register %d to 0x%x\n", (int)index, (int)val);

    phy_write(phydev, index, val);

    return count;

out:
    pr_err("wrong register value input\n");
    pr_err("usage: <reg index> <value>\n");

    return count;
}

查看调用sysfs调用过程

static DEVICE_ATTR_RW(phy_registers);

#define DEVICE_ATTR_RW(_name) \
    struct device_attribute dev_attr_##_name = __ATTR_RW(_name)

#define __ATTR_RW(_name) __ATTR(_name, 0644, _name##_show, _name##_store) 

sys/bus/mdio_bus/devices/stmmac-0\:00/里面的 phy_registers。

device_attribute描述phy_registers的属性,而他有show和store两种操作(读和写)。

/* interface for exporting device attributes */
struct device_attribute {
    struct attribute    attr;
    ssize_t (*show)(struct device *dev, struct device_attribute *attr, char *buf);
    ssize_t (*store)(struct device *dev, struct device_attribute *attr,  const char *buf, size_t count);
};

相关文章:

  • Linux---用户组
  • 精选一百道备赛蓝桥杯——4.冶炼金属
  • SpringMVC-文件上传
  • 游戏引擎学习第163天
  • Codeforces Round 986 (Div. 2)
  • leetcode日记(99)不同的子序列
  • 感受命令行界面的魅力——Linux环境下基础开发工具的使用
  • Leetcode-132.Palindrome Partitioning II [C++][Java]
  • 如何在PyCharm中利用Python对象自动提示提高开发效率?
  • 数学建模 第二节
  • 删除二叉搜索树中的节点
  • 第五章-动态规划
  • 实践 PyTorch 手写数字识别
  • 机试准备第17天
  • Suno的对手Luno:AI音乐开发「上传参考音频 - 方式一:通过二进制流的方式」 —— 「Luno Api系列|AI音乐API」第11篇
  • 【NLP 38、实践 ⑩ NER 命名实体识别任务 Bert 实现】
  • Spring Boot拦截器(Interceptor)与过滤器(Filter)深度解析:区别、实现与实战指南
  • Springboot中的 Mapper 无法找到的 可能原因及解决方案
  • 一个简单的井字棋(Tic-Tac-Toe)游戏的C语言实现
  • 程序化广告行业(20/89):交易模式深度剖析与价值解读
  • 让“五颜六色”面孔讲述上海故事,2025年上海城市推荐官开启选拔
  • 韩国前国务总理韩德洙加入国民力量党
  • 外交部:习近平主席同普京总统达成许多新的重要共识
  • 安徽亳州涡阳县司法局党组书记刘兴连落马
  • 第1现场 | 50多年来首次!印度举行大规模民防演习
  • 李公明︱一周书记:浪漫主义为什么……仍然重要?