You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

内核2.6.29下,mdio-bitbang/mdio-gpio读取PHY寄存器:DTS配置及用户空间方法

Got it, let's walk through exactly how to set up your MPC8308 to read that Clause 45 non-Ethernet PHY using mdio-gpio (which relies on mdio-bitbang) in Linux 2.6.29. I'll cover both the DTS configuration and user-space access methods below.

Device Tree (DTS) Configuration

First, you need to define the MDIO GPIO bus and your PHY in your MPC8308's DTS. Linux 2.6.29 uses an older DTS syntax, so make sure to follow this structure closely:

/* Define the MDIO GPIO bus */
mdio_gpio: mdio-gpio {
    compatible = "mdio-gpio";
    /* MDC = GPIO10, MDIO = GPIO11 (using MPC8308's gpio1 controller) */
    gpios = <&gpio1 10 GPIO_ACTIVE_HIGH>,
            <&gpio1 11 GPIO_ACTIVE_HIGH>;
    #address-cells = <1>;
    #size-cells = <0>;

    /* Your non-Ethernet Clause 45 PHY */
    phy@0 {
        reg = <0>;  /* Adjust this to match your PHY's actual MDIO address */
        compatible = "ethernet-phy-ieee802.3-c45";
        /* Skip Ethernet-specific properties since this isn't an Ethernet PHY */
    };
};

Notes for DTS:

  • Ensure the gpio1 controller node is already defined in your base MPC8308 DTS (it should be present in most default device trees for this chip).
  • The reg value in the phy@0 node is the PHY's address on the MDIO bus—double-check your hardware docs to confirm this.
Driver Loading

Before accessing the PHY, load the required modules. mdio-gpio depends on mdio-bitbang, so loading mdio-gpio will pull in the dependency automatically:

modprobe mdio-gpio

Check dmesg to confirm the driver initialized correctly:

dmesg | grep mdio

You should see messages indicating the MDIO bus and PHY were detected.

User-Space Register Access

Since your PHY uses IEEE 802.3 Clause 45, the old mii-tool (which only supports Clause 22) won't work. Instead, use the sysfs interface or ethtool (sysfs is more straightforward for non-Ethernet PHYs).

The MDIO bus and PHY are exposed under /sys/class/mdio_bus/ once the driver is loaded. Here's how to interact with registers:

  1. Locate your PHY's sysfs path:
    You'll see a directory like /sys/class/mdio_bus/mdio-gpio-0/phy-0/ (the numbers may vary if you have multiple MDIO buses).

  2. Read a Clause 45 register:
    Clause 45 uses a combination of a device address (DEVAD) and register address. Use the c45_read file:

    # Format: echo "<DEVAD> <REG_ADDR>" > [PHY_PATH]/c45_read
    echo "0 0x10" > /sys/class/mdio_bus/mdio-gpio-0/phy-0/c45_read
    # Then read the result
    cat /sys/class/mdio_bus/mdio-gpio-0/phy-0/c45_read
    

    Replace 0 with your PHY's DEVAD and 0x10 with the register you want to read.

  3. Write a Clause 45 register:
    Use the c45_write file with the format <DEVAD> <REG_ADDR> <VALUE>:

    echo "0 0x10 0x1234" > /sys/class/mdio_bus/mdio-gpio-0/phy-0/c45_write
    

Using ethtool

If you prefer using ethtool, you can interact with the PHY by specifying the MDIO bus and PHY address. Note that this may require mapping the bus to a dummy network interface, but in 2.6.29, you can use this syntax:

# Read DEVAD 0, register 0x10 on PHY address 0, MDIO bus 0
ethtool -m eth0 --c45 --devad 0 --register 0x10

Note: If you don't have an Ethernet interface tied to this MDIO bus, sysfs is the more reliable option.

Troubleshooting Tips

  • If GPIO pins aren't behaving, manually set their direction via /sys/class/gpio/ before loading the driver (though mdio-gpio should handle this automatically).
  • Double-check the PHY address in your DTS—mismatched addresses will cause read/write failures.
  • Use dmesg to debug driver initialization or communication errors.

内容的提问来源于stack exchange,提问作者Greg

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.05.21 07:12:22