转载:http://blog.chinaunix.net/uid-24148050-id-132863.html

1. 简介

The MDIO
interface is a simple, two-wire, serial interface to connect a
management entity and a managed PHY for the purposes of controlling the
PHY and gathering status from the PHY.
   The two lines include the
MDC line [Management Data Clock], and the MDIO line [Management Data
Input/Output]. The clock is point-to-point, while the data line is a
bi-directional multi-drop interface.
   The data line is Tri-state able and can drive 32 devices.

MDIO接口,MAC与PHY间的管理接口(MII是数据接口),有2根线:时钟线MDC,数据线MDIO(双向)

   MDIO工作流程:
    * Preamle(PRE)       在没有传输数据的空闲状态时,数据线MDIO处于高阻态(一直为1)。
    * Start of Frame(ST) MAC驱动MDIO线,出现一个2bit的开始标识码(01)。
    * Operation Code(OP) MAC驱动MDIO线,出现一个2bit数据来标识是读操作(10)还是写操作(01)。
    * PHY Address(PHYAD) MAC驱动MDIO线,出现一个5bit数据标识PHY的地址。
    * Reg Address(REGAD) MAC驱动MDIO线,出现一个5bitPHY寄存器地址。
    * Turnaround(TA)     写操作的话,MAC驱动MDIO线,出现10
                         读操作的话,MDIO pin of MAC must be put in high-impedance state
                                     在第二个周期,PHY驱动MDIO线,出现0

* Data               MDIO串行读出/写入16bit的寄存器数据。

* MDIO恢复成空闲状态,同时MDIO进入高阻状态。

下面是PHY芯片 BCM5461 的一个例子:

2. PowerPC对MDIO的支持

PowerPC操作MDIO时,涉及以下寄存器:
MIIMCFG  配置寄存器
MIIMCOM  命令寄存器
MIIMADD  地址寄存器
MIIMCON  控制寄存器
MIIMSTAT 状态寄存器
MIIMIND  指示寄存器

以MPC8560举例,这些寄存器在CCSR中的位置如下:

2.1 MIIMCFG:配置寄存器

ResetMgmt:   用于重置MDIO模块
MgmtClockSet:时钟设置,是CCB的 2的n次方之一

2.2 MIIMCOM  命令寄存器

ReadCycle: 0->1 触发MDIO读时序

2.3 MIIMADD  地址寄存器

PHYaddr:PHY地址,共5bit,系统最多联31个PHY(地址0为保留)
REGaddr:寄存器地址,共5bit,一个PHY上最多32个寄存器地址(可以使用shadow value技术,访问更多的寄存器)

2.4 MIIMCON  控制寄存器

PHYcontrol:在写流程时,这里存放要写入寄存器的值

2.5 MIIMSTAT 状态寄存器

PHYstatus:读流程时,PHY reg的内容会放到此

2.6 MIIMIND  指示寄存器

NotVal:若置1,表示读流程结束,可以去读MIIMSTAT
Scan:  若置1,表示扫描流程进行中
Busy:  只有置0时,才能进行新的读写流程

3. linux中MDIO的实现

读写PHY寄存器时通过2个函数

phy_read()和phy_write(),

最终调用
int gfar_local_mdio_read(struct gfar_mii *regs, int mii_id, int regnum)
int gfar_local_mdio_write(struct gfar_mii *regs, int mii_id, int regnum, u16 value)

参数regs就是MDIO相关寄存器:

  1. struct gfar_mii {
  2. u32 miimcfg; /* 0x.520 - MII Management Config Register */
  3. u32 miimcom; /* 0x.524 - MII Management Command Register */
  4. u32 miimadd; /* 0x.528 - MII Management Address Register */
  5. u32 miimcon; /* 0x.52c - MII Management Control Register */
  6. u32 miimstat; /* 0x.530 - MII Management Status Register */
  7. u32 miimind; /* 0x.534 - MII Management Indicator Register */
  8. };

参数mii_id,就是PHY的id
参数regnum,就是寄存器地址

上代码,简单不解释

  1. int gfar_local_mdio_read(struct gfar_mii *regs, int mii_id, int regnum)
  2. {
  3. u16 value;
  4. /* Set the PHY address and the register address we want to read */
  5. gfar_write(&regs->miimadd, (mii_id << 8) | regnum);
  6. /* Clear miimcom, and then initiate a read */
  7. gfar_write(&regs->miimcom, 0);
  8. gfar_write(&regs->miimcom, MII_READ_COMMAND);
  9. /* Wait for the transaction to finish */
  10. while (gfar_read(&regs->miimind) & (MIIMIND_NOTVALID | MIIMIND_BUSY))
  11. cpu_relax();
  12. /* Grab the value of the register from miimstat */
  13. value = gfar_read(&regs->miimstat);
  14. return value;
  15. }
  1. int gfar_local_mdio_write(struct gfar_mii *regs, int mii_id,
  2. int regnum, u16 value)
  3. {
  4. /* Set the PHY address and the register address we want to write */
  5. gfar_write(&regs->miimadd, (mii_id << 8) | regnum);
  6. /* Write out the value we want */
  7. gfar_write(&regs->miimcon, value);
  8. /* Wait for the transaction to finish */
  9. while (gfar_read(&regs->miimind) & MIIMIND_BUSY)
  10. cpu_relax();
  11. return 0;
  12. }

MDIO/MDC(SMI)接口的更多相关文章

  1. MDIO/MDC(SMI)接口-leonwang202

    ChinaUnix博客 http://blog.chinaunix.net/uid-24148050-id-132863.html

  2. SMI接口,SMI帧结构,MDC/MDIO

    转载:http://blog.csdn.net/zyboy2000/article/details/7442464 SMI全称是串行管理接口(Serial Management Interface). ...

  3. (二)再议MII、RMII、GMII接口

    概述:         MII (Media Independent Interface(介质无关接口)或称为媒体独立接口,它是IEEE-802.3定义的以太网行业标准.它包括一个数据接口和一个MAC ...

  4. 61.MII、RMII、GMII接口的详细介绍

    概述: MII (Media Independent Interface(介质无关接口)或称为媒体独立接口,它是IEEE-802.3定义的以太网行业标准.它包括一个数据接口和一个MAC和PHY之间的管 ...

  5. MII、RMII、GMII接口的详细介绍

    转载:http://blog.csdn.net/reille/article/details/6312156 概述: MII (Media Independent Interface(介质无关接口)或 ...

  6. MII、RMII、GMII接口的详细介绍【转】

    转自:https://www.cnblogs.com/geekite/p/5204512.html 概述: MII (Media Independent Interface(介质无关接口)或称为媒体独 ...

  7. 006 媒体独立接口(MII,Meida Independent Interface)

    一.MII接口 MII接口Medium Independent Interface MII(Media Independent Interface)即媒体独立接口,MII接口是MAC与PHY连接的标准 ...

  8. RGMII,MII,GMI接口

    简介 RGMII(Reduced Gigabit Media Independent Interface)是Reduced GMII(吉比特介质独立接口).GMII和RGMII均采用8位数据接口,工作 ...

  9. MII、GMII、RMII、SGMII、XGMII 接口区别

    MII即媒体独立接口,也叫介质无关接口.它是IEEE-802.3定义的以太网行业标准.它包括一个数据接口,以及一个MAC和PHY之间的管理接口(图1). 数据接口包括分别用于发送器和接收器的两条独立信 ...

随机推荐

  1. SQL对字符串进行排序

    假设字符串中只由'A'.'B'.'C'.'D'组成,且长度为7.并设函数REPLICATE(<字符串>,<n>)可以创建一个<字符串>的n个副本的字符串,另外还有R ...

  2. Memory Cache(内存缓存)

    当Google测试了Google Search服务的可用性后,发现速度是最影响Web应用的可用性的因素之一.相对于作用相同但是速度慢的应用,用户更喜欢速度快的应用.多来年,Google已经掌握了如何使 ...

  3. linux vim用法总结

    1.跳转到指定行 编辑模式下:输入  ngg或nG(n代表行数) 命令模式下:输入  :n(n代表行数) 2.查找命令 命令模式下输入 / 后面加上查找的内容 例如    :/name     (查找 ...

  4. lipo命令

    工作中,xcode工程遇到一个bug file was built for archive which is not the architecture being linked armv7 找了一些资 ...

  5. MySQL 主从架构配置详解

    无论是哪一种数据库,数据的安全都是至关重要的,因此熟练掌握数据库的安全备份功能,是作为开发人员,特别是后端开发人员的一项必备技能.MySQL 数据库内建的复制功能,可以帮助我们对数据进行异地备份,读写 ...

  6. SAE 合并图片

    $domain = 'picleader'; //图片库的域名 $stgurl = 'http://lemonluoxing-picleader.stor.sinaapp.com/'; //绝对路径 ...

  7. Struts2运行流程分析

    一.Struts2运行流程图: 二.运行流程分析: 1. 请求发送给StrutsPrepareAndExecuteFilter 2.StrutsPrepareAndExecuteFilter询问Act ...

  8. build.gradle 使用tips

    7.查看依赖 gradlew [你想查看的module]:dependencies >dependencies.txt 6.buildToolsVersion build tools版本号 co ...

  9. HDU 3308 LCIS (线段树区间合并)

    题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=3308 题目很好懂,就是单点更新,然后求区间的最长上升子序列. 线段树区间合并问题,注意合并的条件是a[ ...

  10. 使用WPF来创建 Metro UI程序

    本文转载:http://www.cnblogs.com/TianFang/p/3184211.html 这个是我以前网上看到的一篇文章,原文地址是:Building a Metro UI with W ...