Nut/OS  5.0.5
API Reference
phy.h
Go to the documentation of this file.
00001 #ifndef _PHY_H_
00002 #define _PHY_H_
00003 
00004 /*
00005  * Copyright (C) 2010 by Ulrich Prinz (uprinz2@netscape.net)
00006  *
00007  * All rights reserved.
00008  *
00009  * Redistribution and use in source and binary forms, with or without
00010  * modification, are permitted provided that the following conditions
00011  * are met:
00012  *
00013  * 1. Redistributions of source code must retain the above copyright
00014  *    notice, this list of conditions and the following disclaimer.
00015  * 2. Redistributions in binary form must reproduce the above copyright
00016  *    notice, this list of conditions and the following disclaimer in the
00017  *    documentation and/or other materials provided with the distribution.
00018  * 3. Neither the name of the copyright holders nor the names of
00019  *    contributors may be used to endorse or promote products derived
00020  *    from this software without specific prior written permission.
00021  *
00022  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
00023  * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
00024  * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
00025  * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
00026  * COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
00027  * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
00028  * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS
00029  * OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED
00030  * AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
00031  * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF
00032  * THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
00033  * SUCH DAMAGE.
00034  *
00035  * For additional information see http://www.ethernut.de/
00036  */
00037 
00038 /*
00039  * \verbatim
00040  * $Id: phy_drv.c 3143 2010-09-29 20:13:51Z Astralix $
00041  * \endverbatim
00042  */
00043 
00044 /* These are the PHYters OUIs.
00045  * The Organizationally Unique Identifier consists of a vendors model number
00046  * and a model revision number. By IEEE the two highest bits are ignored.
00047  */
00048 /* Special tokens */
00049 #define PHY_AUTO    0x00000000  /* Autodetect chip, not recommended */
00050 #define PHY_ANY     0xFFFFFFFF  /* Disable PHY ID check, not recommended) */
00051 
00052 /* AMD PHY tranceivers */       /* Boards using this chip / comment: */
00053 #define AM79C875    0x00225540  /* nn. */
00054 
00055 /* DAVICOM PHY tranceiver */
00056 #define DM9161      0x0181B880  /* nn. */
00057 #define DM9161A     0x0181B8A0  /* ATMEL EK, eNet-sam7X */
00058 #define DM9161B     0x0181B8B0  /* nn. */
00059 /* DAVICOM EMAC-PHY combinations */
00060 #define DM9000      0x0181B8C0  /* EIR */
00061 #define DM9000A     0x0181B8A0  /* nn. same as DM9161A */
00062 #define DM9000B     0x0181B8B0  /* nn. same as DM9161B */
00063 
00064 /* National Semiconductor PHY tranceiver */
00065 #define DP83838     0x20005C90  /* EVK1100, EVK1105 */
00066 #define DP83848     0x20005CA0  /* STM3210C-EVAL */
00067 
00068 /* Micrel PHY tranceiver */
00069 #define KS8721      0x00221610  /* Olimex SAM7-EX256 */
00070 /* Micrel EMAC-PHY combinations */
00071 #define KS8851      0x00008870  /* Located in CIDER (0xC0) register */
00072 
00073 /* ST Microelectronics PHY tranceiver */
00074 #define STE100P     0x1C040010  /* Hitex STM32-comStick */
00075 
00076 /* SMSC PHY tranceiver */
00077 #define LAN8700     0x0007C0C0  /* Not recommended for new designs! */
00078 #define LAN8700r4   0x0007C0C4  /*   revision 4 of the LAN8700 phy */
00079 #define LAN8710     0x0007C0F0  /* nn. / LAN8710 and LAN8720 share same IDs */
00080 #define LAN8720     0x0007C0F0  /* nn. / not a typo, has same OUI as 8710 */
00081 #define LAN8720A    0x0007C0F1  /*   revision 1 of the LAN8720 phy */
00082 
00083 /* Masks for chip detection */
00084 #define OUIMSK_VEN  0x3FFFC000  /* Mask for manufacturers OUI */
00085 #define OUIMSK_DEV  0x00003FF0  /* Mask for manufacturers model number */
00086 #define OUIMSK_REV  0x0000000F  /* Mask for chip revision number */
00087 
00088 /* Include nutconf options here as the tokens above need to be defined before */
00089 
00090 #include <cfg/phycfg.h>
00091 
00092 #define PHY_STATUS_HAS_LINK     0x00000001
00093 #define PHY_STATUS_10M          0x00000002
00094 #define PHY_STATUS_100M         0x00000004
00095 #define PHY_STATUS_1000M        0x00000008
00096 #define PHY_STATUS_FULLDUPLEX   0x00000010
00097 #define PHY_STATUS_AUTONEG_OK   0x00000020
00098 #define PHY_STATUS_CON_UNKNOWN  0x00000040
00099 
00100 /* PHY ioctl() Control Tokens */    /* Accepted Values */
00101 #define PHY_CTL_RESET       0x0001  /* 1: Activate reset, wait for completion */
00102 #define PHY_CTL_LOOPBACK    0x0002  /* 1: Enable, 0: disable loopback */
00103 #define PHY_CTL_SPEED       0x0003  /* 10/100: Set interface speed */
00104 #define PHY_CTL_AUTONEG     0x0004  /* 1: Enable, 0: disable Auto-Negotiation */
00105 #define PHY_CTL_POWERDOWN   0x0005  /* 1: Power down, 0: wakeup chip */
00106 #define PHY_CTL_ISOLATE     0x0006  /* 1: Isolate interface, 0: clear isolate state */
00107 #define PHY_CTL_DUPLEX      0x0007  /* 1: Enable full duplex */
00108 #define PHY_CTL_AUTONEG_RE  0x0008  /* 1: Restart autonegotiation process */
00109 
00110 #define PHY_GET_LINK        0x0100  /* Request Link Status, 1: link is up */
00111 #define PHY_GET_STATUS      0x0101  /* Request connection status
00112                                      *   PHY_STATUS_HAS_LINK   is set when link is up
00113                                      *   PHY_STATUS_10M        is set when speed is 10Mbit/s
00114                                      *   PHY_STATUS_100M       is set when speed is 100Mbit/s
00115                                      *   PHY_STATUS_1000M      is set when speed is 1000Mbit/s
00116                                      *   PHY_STATUS_FULLDUPLEX is set when full duplex is true
00117                                      *   PHY_STATUS_AUTONEG_OK is set when auto negotiation is finished
00118                                      *   PHY_STATUS_CON_UNKNWN is set when speed and duplex is unknown
00119                                      * The value is 0 when link is not established
00120                                      * The value is negative on error condition */
00121 #define PHY_GET_POE         0x0102  /* Request PoE status, 1: energy is detected */
00122 #define PHY_GET_REGVAL      0x0103  /* Read value of register (par>>16) from the phy */
00123 #define PHY_SET_REGVAL      0x0104  /* Write value (par & 0xFFFF) to register (par>>16) of the phy */
00124 
00125 /*
00126  * Physical Layer Tranceiver - Device Control Block
00127  *
00128  */
00129 typedef struct _PHYDCB PHYDCB;
00130 
00131 struct _PHYDCB {
00132     /*
00133      * Vendor OUI ( including model and revision )
00134      */
00135     uint32_t oui;
00136 
00137     /*
00138      * Address of chip at MDIO bus
00139      */
00140     uint8_t  addr;
00141 
00142     /*
00143      * Functionpointer filled by EMAC driver to access
00144      * PHYter for write.
00145      */
00146     void(*mdiow)(uint8_t, uint16_t);
00147 
00148     /*
00149      * Functionpointer filled by EMAC driver to access
00150      * PHYter for read.
00151      */
00152     uint16_t(*mdior)(uint8_t);
00153 };
00154 
00155 extern uint16_t NutPhyGetStatus(void);
00156 extern int NutPhyCtl( uint16_t ctl, uint32_t *par);
00157 extern int NutRegisterPhy( uint8_t mda, void(*mdiow)(uint8_t, uint16_t), uint16_t(*mdior)(uint8_t));
00158 
00159 #endif /* _PHY_H_ */