- 论坛徽章:
- 0
|
[patch]Add mii function for AT91SAM9263's EMAC
g-bios添加了MII CORE层后,修改了AT91SAM9263网卡驱动相关代码。
signed-off-by: voidjackjiang <voidjack@163.com>
--------------------------------------------------------------------------------------
From 25fd823fa78accd54cb06741955727f896fee39a Mon Sep 17 00:00:00 2001
From: Jack Jiang <voidjack.jiang@gmail.com>
Date: Tue, 17 Nov 2009 22:51:33 +0800
Subject: [PATCH 3/3] Add mii function for AT92SAM9263's EMAC
---
device/net/eth_at91.c | 90 +++++++++++++++++++++++++++----------------------
1 files changed, 50 insertions(+), 40 deletions(-)
diff --git a/device/net/eth_at91.c b/device/net/eth_at91.c
index c7388c0..3465191 100644
--- a/device/net/eth_at91.c
+++ b/device/net/eth_at91.c
@@ -1,5 +1,6 @@
#include <stdio.h>
#include <core/types.h>
+#include <core/errno.h>
#include <core/io.h>
#include <core/init.h>
#include <core/list.h>
@@ -142,13 +143,12 @@ static int EmacRecv(struct NetDevice * pNetDev)
return 0;
}
-static UINT16 EmacMdioRead(UINT32 nReg)
+static UINT16 EmacMdioRead(UINT8 bPhyAddr, UINT8 bPhyReg)
{
UINT32 dwNetCtrl;
UINT32 dwFrame;
-
- dwFrame = (1 << 30) | (2 << 28) | (0 << 23) | (nReg << 18) | (2 << 16);
+ dwFrame = (1 << 30) | (2 << 28) | (bPhyAddr << 23) | (bPhyReg << 18) | (2 << 16);
EmacWrite(EMAC_MAN, dwFrame);
while (!(EmacRead(EMAC_NSR) & EMAC_IDLE));
@@ -158,13 +158,11 @@ static UINT16 EmacMdioRead(UINT32 nReg)
return (UINT16)(dwFrame & 0xffff);
}
-static int EmacMdioWrite(UINT32 nReg, UINT16 hVal)
+static void EmacMdioWrite(UINT16 hVal, UINT8 bPhyAddr, UINT8 bPhyReg)
{
- EmacWrite(EMAC_MAN, (1 << 30) | (1 << 28) | (0 << 23) | (nReg << 18) | (2 << 16) | hVal);
+ EmacWrite(EMAC_MAN, (1 << 30) | (1 << 28) | (bPhyAddr << 23) | (bPhyReg << 18) | (2 << 16) | hVal);
while (!(EmacRead(EMAC_NSR) & EMAC_IDLE));
-
- return 0;
}
static int __INIT__ EmacInitRingBuff(struct At91Emac *pEmac)
@@ -205,7 +203,7 @@ static int __INIT__ EmacInitRingBuff(struct At91Emac *pEmac)
EmacWrite(EMAC_TBQP, (UINT32)pEmac->pTxQueue);
DPRINT("RX buff = 0x%08x, TX buff = 0x%08x\n",
- pEmac->pRxQueue, pEmac->pTxQueue);
+ pEmac->pRxQueue, pEmac->pTxQueue);
return 0;
}
@@ -236,26 +234,6 @@ static void __INIT__ EmacInit(struct At91Emac *pEmac)
EmacWrite(EMAC_USRIO, 0x3);
}
-static void __INIT__ EmacPhyReset(void)
-{
- UINT16 hVal;
- int nTimeOut = 100;
-
- EmacMdioWrite(MII_REG_BMC, MII_PHY_RESET);
-
- while (nTimeOut > 0)
- {
- hVal = EmacMdioRead(MII_REG_BMC);
- if (!(hVal & MII_PHY_RESET))
- return;
-
- udelay(10);
- nTimeOut--;
- }
-
- printf("PHY reset failed!\n");
-}
-
static int EmacSetMacAddr(struct NetDevice *pNetDev, const BYTE vbMacAddr[])
{
EmacWrite(EMAC_SA1B, *(UINT32 *)pNetDev->vbMacAddr);
@@ -268,9 +246,9 @@ static int __INIT__ EmacProbe(void)
{
UINT16 hSpeed, hMode;
struct NetDevice *pNetDev;
+ struct PhyDevice *pPhyDev;
struct At91Emac *pEmac;
-
pNetDev = GkNetDevNew(sizeof(*pEmac));
pEmac = pNetDev->pChip;
@@ -278,23 +256,55 @@ static int __INIT__ EmacProbe(void)
EmacInit(pEmac);
- EmacPhyReset();
+ pPhyDev = GkPhyDevNew();
+ if (!pPhyDev)
+ {
+ return -EIO;
+ }
- while (1) // fixme
+ pPhyDev->PhyRead = EmacMdioRead;
+ pPhyDev->PhyWrite = EmacMdioWrite;
+
+ if (GkPhyDevRegister(pPhyDev) < 0)
{
- hMode = EmacMdioRead(MII_REG_BMS);
- if (hMode & 0x24)
- break;
+ return -EIO;
}
- if(hMode & 0x20)
- printf("Auto negotiation ok!\n");
- if(hMode & 0x4)
- printf("Link ok!\n");
+ GkPhyResetPhy();
- hSpeed = EmacMdioRead(MII_REG_STAT);
+ printf("Detecting ethernet speed ... ");
- printf("hSpeed = 0x%04x\n", hSpeed);
+ hSpeed = GkPhyGetLinkStatus();
+
+ if (hSpeed < 0)
+ {
+ printf("NOT linked, please check the cable!\n");
+ }
+ else
+ {
+ switch(hSpeed)
+ {
+ case ETHER_SPEED_10M_HD:
+ printf("10M Half Duplex activated!\n");
+ break;
+
+ case ETHER_SPEED_10M_FD:
+ printf("10M Full Duplex activated!\n");
+ break;
+
+ case ETHER_SPEED_100M_HD:
+ printf("100M Half Duplex activated!\n");
+ break;
+
+ case ETHER_SPEED_100M_FD:
+ printf("100M Full Duplex activated!\n");
+ break;
+
+ default:
+ printf("Unknown speed (%d)!\n", hSpeed);
+ break;
+ }
+ }
pNetDev->SendPacket = EmacSendPacket;
pNetDev->SetMacAddr = EmacSetMacAddr;
--
1.6.3.3 |
|