内核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.
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
gpio1controller node is already defined in your base MPC8308 DTS (it should be present in most default device trees for this chip). - The
regvalue in thephy@0node is the PHY's address on the MDIO bus—double-check your hardware docs to confirm this.
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.
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).
Using Sysfs (Recommended)
The MDIO bus and PHY are exposed under /sys/class/mdio_bus/ once the driver is loaded. Here's how to interact with registers:
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).Read a Clause 45 register:
Clause 45 uses a combination of a device address (DEVAD) and register address. Use thec45_readfile:# 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_readReplace
0with your PHY's DEVAD and0x10with the register you want to read.Write a Clause 45 register:
Use thec45_writefile 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 (thoughmdio-gpioshould handle this automatically). - Double-check the PHY address in your DTS—mismatched addresses will cause read/write failures.
- Use
dmesgto debug driver initialization or communication errors.
内容的提问来源于stack exchange,提问作者Greg

