phy控制器驱动【cpu无mdio控制器】

当CPU没有内置MDIO控制器时,可以通过GPIO模拟MDIO总线与PHY设备进行通信。下面是如何实现PHY控制器驱动的步骤:

1. 设计GPIO MDIO时序

首先,必须了解MDIO协议的基本时序要求:

  • MDC(管理时钟):用于时钟信号。
  • MDIO(管理数据):用于数据传输。

在没有MDIO控制器的情况下,使用两个GPIO引脚分别模拟MDC和MDIO。可以通过GPIO设置高低电平来实现MDIO的时序。

2. GPIO引脚初始化

初始化用于MDIO和MDC的GPIO引脚,并设置为输出或输入模式。

#include <linux/gpio.h>
#include <linux/delay.h>

#define MDIO_PIN  17  // MDIO GPIO引脚
#define MDC_PIN   18  // MDC GPIO引脚

void init_gpio(void) {
    gpio_request(MDIO_PIN, "MDIO");
    gpio_request(MDC_PIN, "MDC");
    gpio_direction_output(MDIO_PIN, 1);  // 默认高电平
    gpio_direction_output(MDC_PIN, 1);   // 默认高电平
}

3. 定义时钟脉冲函数

生成MDC脉冲信号,通常为高低电平切换的延迟,以便满足MDIO时序要求。

void mdc_pulse(void) {
    gpio_set_value(MDC_PIN, 1); // 设置MDC为高
    udelay(1);                   // 延时
    gpio_set_value(MDC_PIN, 0); // 设置MDC为低
    ude
MSYS: DMEM request: [emac0_buff]:0x00000812 MSYS: DMEM request: [emac0_buff]:0x00000812 success, CPU phy:@0x23846000, virt:@0xC3846000 libphy: mdio: probed mdio_bus mdio-bus@emac0: /soc/emac0/mdio-bus@emac0/ethernet-phy@0 has invalid PHY address mdio_bus mdio-bus@emac0: scan phy ethernet-phy at address 0 mdio_bus mdio-bus@emac0: scan phy ethernet-phy at address 1 mdio_bus mdio-bus@emac0: scan phy ethernet-phy at address 2 mdio_bus mdio-bus@emac0: scan phy ethernet-phy at address 3 mdio_bus mdio-bus@emac0: scan phy ethernet-phy at address 4 mdio_bus mdio-bus@emac0: scan phy ethernet-phy at address 5 mdio_bus mdio-bus@emac0: scan phy ethernet-phy at address 6 mdio_bus mdio-bus@emac0: scan phy ethernet-phy at address 7 mdio_bus mdio-bus@emac0: scan phy ethernet-phy at address 8 mdio_bus mdio-bus@emac0: scan phy ethernet-phy at address 9 mdio_bus mdio-bus@emac0: scan phy ethernet-phy at address 10 mdio_bus mdio-bus@emac0: scan phy ethernet-phy at address 11 mdio_bus mdio-bus@emac0: scan phy ethernet-phy at address 12 mdio_bus mdio-bus@emac0: scan phy ethernet-phy at address 13 mdio_bus mdio-bus@emac0: scan phy ethernet-phy at address 14 mdio_bus mdio-bus@emac0: scan phy ethernet-phy at address 15 mdio_bus mdio-bus@emac0: scan phy ethernet-phy at address 16 mdio_bus mdio-bus@emac0: scan phy ethernet-phy at address 17 mdio_bus mdio-bus@emac0: scan phy ethernet-phy at address 18 mdio_bus mdio-bus@emac0: scan phy ethernet-phy at address 19 mdio_bus mdio-bus@emac0: scan phy ethernet-phy at address 20 mdio_bus mdio-bus@emac0: scan phy ethernet-phy at address 21 mdio_bus mdio-bus@emac0: scan phy ethernet-phy at address 22 mdio_bus mdio-bus@emac0: scan phy ethernet-phy at address 23 mdio_bus mdio-bus@emac0: scan phy ethernet-phy at address 24 mdio_bus mdio-bus@emac0: scan phy ethernet-phy at address 25 mdio_bus mdio-bus@emac0: scan phy ethernet-phy at address 26 mdio_bus mdio-bus@emac0: scan phy ethernet-phy at address 27 mdio_bus mdio-bus@emac0: scan phy ethernet-phy at address 28 mdio_bus mdio-bus@emac0: scan phy ethernet-phy at address 29 mdio_bus mdio-bus@emac0: scan phy ethernet-phy at address 30 mdio_bus mdio-bus@emac0: scan phy ethernet-phy at address 31 [emac_phy_connect][3592] connected mac emac0 to PHY at mdio-bus@emac0:00 [uid=11112222, driver=SStar 10/100 Ethernet Phy] MSYS: DMEM request: [emac1_buff]:0x00060812 MSYS: DMEM request: [emac1_buff]:0x00060812 success, CPU phy:@0x23850000, virt:@0xC3850000 libphy: mdio: probed mdio_bus mdio-bus@emac1: /soc/emac1/mdio-bus@emac1/ethernet-phy@1 has invalid PHY address mdio_bus mdio-bus@emac1: scan phy ethernet-phy at address 0 mdio_bus mdio-bus@emac1: scan phy ethernet-phy at address 1 mdio_bus mdio-bus@emac1: scan phy ethernet-phy at address 2 mdio_bus mdio-bus@emac1: scan phy ethernet-phy at address 3 mdio_bus mdio-bus@emac1: scan phy ethernet-phy at address 4 mdio_bus mdio-bus@emac1: scan phy ethernet-phy at address 5 mdio_bus mdio-bus@emac1: scan phy ethernet-phy at address 6 mdio_bus mdio-bus@emac1: scan phy ethernet-phy at address 7 mdio_bus mdio-bus@emac1: scan phy ethernet-phy at address 8 mdio_bus mdio-bus@emac1: scan phy ethernet-phy at address 9 mdio_bus mdio-bus@emac1: scan phy ethernet-phy at address 10 mdio_bus mdio-bus@emac1: scan phy ethernet-phy at address 11 mdio_bus mdio-bus@emac1: scan phy ethernet-phy at address 12 mdio_bus mdio-bus@emac1: scan phy ethernet-phy at address 13 mdio_bus mdio-bus@emac1: scan phy ethernet-phy at address 14 mdio_bus mdio-bus@emac1: scan phy ethernet-phy at address 15 mdio_bus mdio-bus@emac1: scan phy ethernet-phy at address 16 mdio_bus mdio-bus@emac1: scan phy ethernet-phy at address 17 mdio_bus mdio-bus@emac1: scan phy ethernet-phy at address 18 mdio_bus mdio-bus@emac1: scan phy ethernet-phy at address 19 mdio_bus mdio-bus@emac1: scan phy ethernet-phy at address 20 mdio_bus mdio-bus@emac1: scan phy ethernet-phy at address 21 mdio_bus mdio-bus@emac1: scan phy ethernet-phy at address 22 mdio_bus mdio-bus@emac1: scan phy ethernet-phy at address 23 mdio_bus mdio-bus@emac1: scan phy ethernet-phy at address 24 mdio_bus mdio-bus@emac1: scan phy ethernet-phy at address 25 mdio_bus mdio-bus@emac1: scan phy ethernet-phy at address 26 mdio_bus mdio-bus@emac1: scan phy ethernet-phy at address 27 mdio_bus mdio-bus@emac1: scan phy ethernet-phy at address 28 mdio_bus mdio-bus@emac1: scan phy ethernet-phy at address 29 mdio_bus mdio-bus@emac1: scan phy ethernet-phy at address 30 mdio_bus mdio-bus@emac1: scan phy ethernet-phy at address 31 [emac_phy_connect][3592] connected mac emac1 to PHY at mdio-bus@emac1:00 [uid=00000000, driver=Generic PHY] MSYS: DMEM request: [AESDMA_ENG]:0x00001000 MSYS: DMEM request: [AESDMA_ENG]:0x00001000 success, CPU phy:@0x23847000, virt:@0xC3847000 MSYS: DMEM request: [AESDMA_ENG1]:0x00001000 MSYS: DMEM request: [AESDMA_ENG1]:0x00001000 success, CPU phy:@0x23848000, virt:@0xC3848000 [ms_cpufreq_init] Current clk=799999872 mstar_spinand_probe: mstar_spinand enableClock MSYS: DMEM request: [BDMA]:0x00000840 MSYS: DMEM request: [BDMA]:0x00000840 success, CPU phy:@0x23849000, virt:@0xC3849000 [emac_phy_link_adjust] EMAC Link Down [emac_phy_link_adjust] EMAC Link Down [emac_phy_link_adjust] EMAC Link Up
10-30
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值