* ASIX AX88172/AX88772/AX88178 USB 2.0 Ethernet Driver.
* Copyright (c) 2008, 2011 S.Zharski <imker@gmx.li>
* Distributed under the terms of the MIT license.
*
* Heavily based on code of the
* Driver for USB Ethernet Control Model devices
* Copyright (C) 2008 Michael Lotz <mmlr@mlotz.ch>
* Distributed under the terms of the MIT license.
*
*/
#ifndef _USB_MII_BUS_H_
#define _USB_MII_BUS_H_
#include "Driver.h"
enum MII_Register {
MII_BMCR = 0x00,
MII_BMSR = 0x01,
MII_PHYID0 = 0x02,
MII_PHYID1 = 0x03,
MII_ANAR = 0x04,
MII_ANLPAR = 0x05,
MII_ANER = 0x06
};
enum MII_BMCR {
BMCR_Reset = 0x8000,
BMCR_Loopback = 0x4000,
BMCR_SpeedSelection = 0x2000,
BMCR_ANegEnabled = 0x1000,
BMCR_PowerDown = 0x0800,
BMCR_Isolate = 0x0400,
BMCR_ANegRestart = 0x0200,
BMCR_FullDuplex = 0x0100,
BMCR_CollTest = 0x0080
};
enum MII_BMSR {
BMSR_CAP_100BASE_T4 = 0x8000,
BMSR_CAP_100BASE_TXFD = 0x4000,
BMSR_CAP_100BASE_TXHD = 0x2000,
BMSR_CAP_10BASE_TXFD = 0x1000,
BMSR_CAP_10BASE_TXHD = 0x0800,
BMSR_MFPS = 0x0040,
BMSR_ANC = 0x0020,
BMSR_RF = 0x0010,
BMSR_CAP_AN = 0x0008,
BMSR_Link = 0x0004,
BMSR_Jabber = 0x0002,
BMSR_CAP_Ext = 0x0001
};
enum MII_ANAR {
ANAR_NP = 0x8000,
ANAR_ACK = 0x4000,
ANAR_RF = 0x2000,
ANAR_PAUSE = 0x0400,
ANAR_T4 = 0x0200,
ANAR_TX_FD = 0x0100,
ANAR_TX_HD = 0x0080,
ANAR_10_FD = 0x0040,
ANAR_10_HD = 0x0020,
ANAR_SELECTOR = 0x0001
};
enum MII_ANLPAR {
ANLPAR_NP = 0x8000,
ANLPAR_ACK = 0x4000,
ANLPAR_RF = 0x2000,
ANLPAR_PAUSE = 0x0400,
ANLPAR_T4 = 0x0200,
ANLPAR_TX_FD = 0x0100,
ANLPAR_TX_HD = 0x0080,
ANLPAR_10_FD = 0x0040,
ANLPAR_10_HD = 0x0020,
ANLPAR_SELECTOR = 0x0001
};
enum PHYIndex {
CurrentPHY = -1,
SecondaryPHY = 0,
PrimaryPHY = 1,
PHYsCount = 2
};
enum PHYType {
PHYTypeMask = 0xe0,
PHYNormal = 0x00,
PHYLinkAState = 0x80,
PHYGigabit = 0x20,
PHYNotInstalled = 0xe0,
PHYIDMask = 0x1f,
PHYIDEmbedded = 0x10
};
class MIIBus {
public:
MIIBus();
status_t Init(usb_device device);
status_t InitCheck();
status_t SetupPHY();
uint8 PHYID(PHYIndex phyIndex = CurrentPHY);
uint8 PHYType(PHYIndex phyIndex = CurrentPHY);
PHYIndex ActivePHY() { return fSelectedPHY; }
status_t Read(uint16 miiRegister, uint16 *value,
PHYIndex phyIndex = CurrentPHY);
status_t Write(uint16 miiRegister, uint16 value,
PHYIndex phyIndex = CurrentPHY);
status_t Status(uint16 *status,
PHYIndex phyIndex = CurrentPHY);
status_t Dump();
private:
status_t fStatus;
usb_device fDevice;
uint8 fPHYs[PHYsCount];
PHYIndex fSelectedPHY;
};
#endif