phy.h 6.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160
  1. #ifndef _PHY_H_
  2. #define _PHY_H_
  3. /*
  4. * Copyright (C) 2010 by Ulrich Prinz (uprinz2@netscape.net)
  5. *
  6. * All rights reserved.
  7. *
  8. * Redistribution and use in source and binary forms, with or without
  9. * modification, are permitted provided that the following conditions
  10. * are met:
  11. *
  12. * 1. Redistributions of source code must retain the above copyright
  13. * notice, this list of conditions and the following disclaimer.
  14. * 2. Redistributions in binary form must reproduce the above copyright
  15. * notice, this list of conditions and the following disclaimer in the
  16. * documentation and/or other materials provided with the distribution.
  17. * 3. Neither the name of the copyright holders nor the names of
  18. * contributors may be used to endorse or promote products derived
  19. * from this software without specific prior written permission.
  20. *
  21. * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
  22. * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
  23. * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
  24. * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
  25. * COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
  26. * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
  27. * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS
  28. * OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED
  29. * AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
  30. * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF
  31. * THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
  32. * SUCH DAMAGE.
  33. *
  34. * For additional information see http://www.ethernut.de/
  35. */
  36. /*
  37. * \verbatim
  38. * $Id: phy_drv.c 3143 2010-09-29 20:13:51Z Astralix $
  39. * \endverbatim
  40. */
  41. /* These are the PHYters OUIs.
  42. * The Organizationally Unique Identifier consists of a vendors model number
  43. * and a model revision number. By IEEE the two highest bits are ignored.
  44. */
  45. /* Special tokens */
  46. #define PHY_AUTO 0x00000000 /* Autodetect chip, not recommended */
  47. #define PHY_ANY 0xFFFFFFFF /* Disable PHY ID check, not recommended) */
  48. /* AMD PHY tranceivers */ /* Boards using this chip / comment: */
  49. #define AM79C875 0x00225540 /* nn. */
  50. /* DAVICOM PHY tranceiver */
  51. #define DM9161 0x0181B880 /* nn. */
  52. #define DM9161A 0x0181B8A0 /* ATMEL EK, eNet-sam7X */
  53. #define DM9161B 0x0181B8B0 /* nn. */
  54. /* DAVICOM EMAC-PHY combinations */
  55. #define DM9000 0x0181B8C0 /* EIR */
  56. #define DM9000A 0x0181B8A0 /* nn. same as DM9161A */
  57. #define DM9000B 0x0181B8B0 /* nn. same as DM9161B */
  58. /* National Semiconductor PHY tranceiver */
  59. #define DP83848 0x20005C90 /* EVK1100, EVK1105, STM3210C-EVAL, STM3220G-EVAL */
  60. #define DP83849 0x20005CA0
  61. /* Micrel PHY tranceiver */
  62. #define KS8721 0x00221610 /* Olimex SAM7-EX256 */
  63. /* Micrel EMAC-PHY combinations */
  64. #define KS8851 0x00008870 /* Located in CIDER (0xC0) register */
  65. /* ST Microelectronics PHY tranceiver */
  66. #define STE100P 0x1C040010 /* Hitex STM32-comStick */
  67. #define ST802RT1 0x02038460 /* STEVAL_PCC0101V2 */
  68. /* SMSC PHY tranceiver */
  69. #define LAN8700 0x0007C0C0 /* Not recommended for new designs! */
  70. #define LAN8700r4 0x0007C0C0 /* revision 4 of the LAN8700 phy */
  71. #define LAN8710 0x0007C0F0 /* nn. / LAN8710 and LAN8720 share same IDs */
  72. #define LAN8720 0x0007C0F0 /* nn. / not a typo, has same OUI as 8710 */
  73. #define LAN8720A 0x0007C0F0 /* revision 1 of the LAN8720 phy */
  74. /* Masks for chip detection */
  75. #define OUIMSK_VEN 0x3FFFC000 /* Mask for manufacturers OUI */
  76. #define OUIMSK_DEV 0x00003FF0 /* Mask for manufacturers model number */
  77. #define OUIMSK_REV 0x0000000F /* Mask for chip revision number */
  78. /* Include nutconf options here as the tokens above need to be defined before */
  79. #include <cfg/phycfg.h>
  80. #define PHY_STATUS_HAS_LINK 0x00000001
  81. #define PHY_STATUS_10M 0x00000002
  82. #define PHY_STATUS_100M 0x00000004
  83. #define PHY_STATUS_1000M 0x00000008
  84. #define PHY_STATUS_FULLDUPLEX 0x00000010
  85. #define PHY_STATUS_AUTONEG_OK 0x00000020
  86. #define PHY_STATUS_CON_UNKNOWN 0x00000040
  87. /* PHY ioctl() Control Tokens */ /* Accepted Values */
  88. #define PHY_CTL_RESET 0x0001 /* 1: Activate reset, wait for completion */
  89. #define PHY_CTL_LOOPBACK 0x0002 /* 1: Enable, 0: disable loopback */
  90. #define PHY_CTL_SPEED 0x0003 /* 10/100: Set interface speed */
  91. #define PHY_CTL_AUTONEG 0x0004 /* 1: Enable, 0: disable Auto-Negotiation */
  92. #define PHY_CTL_POWERDOWN 0x0005 /* 1: Power down, 0: wakeup chip */
  93. #define PHY_CTL_ISOLATE 0x0006 /* 1: Isolate interface, 0: clear isolate state */
  94. #define PHY_CTL_DUPLEX 0x0007 /* 1: Enable full duplex */
  95. #define PHY_CTL_AUTONEG_RE 0x0008 /* 1: Restart autonegotiation process */
  96. #define PHY_GET_LINK 0x0100 /* Request Link Status, 1: link is up */
  97. #define PHY_GET_STATUS 0x0101 /* Request connection status
  98. * PHY_STATUS_HAS_LINK is set when link is up
  99. * PHY_STATUS_10M is set when speed is 10Mbit/s
  100. * PHY_STATUS_100M is set when speed is 100Mbit/s
  101. * PHY_STATUS_1000M is set when speed is 1000Mbit/s
  102. * PHY_STATUS_FULLDUPLEX is set when full duplex is true
  103. * PHY_STATUS_AUTONEG_OK is set when auto negotiation is finished
  104. * PHY_STATUS_CON_UNKNWN is set when speed and duplex is unknown
  105. * The value is 0 when link is not established
  106. * The value is negative on error condition */
  107. #define PHY_GET_POE 0x0102 /* Request PoE status, 1: energy is detected */
  108. #define PHY_GET_REGVAL 0x0103 /* Read value of register (par>>16) from the phy */
  109. #define PHY_SET_REGVAL 0x0104 /* Write value (par & 0xFFFF) to register (par>>16) of the phy */
  110. /*
  111. * Physical Layer Tranceiver - Device Control Block
  112. *
  113. */
  114. typedef struct _PHYDCB PHYDCB;
  115. struct _PHYDCB {
  116. /*
  117. * Vendor OUI ( including model and revision )
  118. */
  119. uint32_t oui;
  120. /*
  121. * Address of chip at MDIO bus
  122. */
  123. uint8_t addr;
  124. /*
  125. * Functionpointer filled by EMAC driver to access
  126. * PHYter for write.
  127. */
  128. void(*mdiow)(uint8_t, uint16_t);
  129. /*
  130. * Functionpointer filled by EMAC driver to access
  131. * PHYter for read.
  132. */
  133. uint16_t(*mdior)(uint8_t);
  134. };
  135. extern uint16_t NutPhyGetStatus(void);
  136. extern int NutPhyCtl( uint16_t ctl, uint32_t *par);
  137. extern int NutRegisterPhy( uint8_t mda, void(*mdiow)(uint8_t, uint16_t), uint16_t(*mdior)(uint8_t));
  138. #endif /* _PHY_H_ */