uec_phy.h 7.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244
  1. /*
  2. * Copyright (C) 2005, 2011 Freescale Semiconductor, Inc.
  3. *
  4. * Author: Shlomi Gridish <gridish@freescale.com>
  5. *
  6. * Description: UCC ethernet driver -- PHY handling
  7. * Driver for UEC on QE
  8. * Based on 8260_io/fcc_enet.c
  9. *
  10. * This program is free software; you can redistribute it and/or modify it
  11. * under the terms of the GNU General Public License as published by the
  12. * Free Software Foundation; either version 2 of the License, or (at your
  13. * option) any later version.
  14. *
  15. */
  16. #ifndef __UEC_PHY_H__
  17. #define __UEC_PHY_H__
  18. #define MII_end ((u32)-2)
  19. #define MII_read ((u32)-1)
  20. #define MIIMIND_BUSY 0x00000001
  21. #define MIIMIND_NOTVALID 0x00000004
  22. #define UGETH_AN_TIMEOUT 2000
  23. /* Cicada Extended Control Register 1 */
  24. #define MII_CIS8201_EXT_CON1 0x17
  25. #define MII_CIS8201_EXTCON1_INIT 0x0000
  26. /* Cicada Interrupt Mask Register */
  27. #define MII_CIS8201_IMASK 0x19
  28. #define MII_CIS8201_IMASK_IEN 0x8000
  29. #define MII_CIS8201_IMASK_SPEED 0x4000
  30. #define MII_CIS8201_IMASK_LINK 0x2000
  31. #define MII_CIS8201_IMASK_DUPLEX 0x1000
  32. #define MII_CIS8201_IMASK_MASK 0xf000
  33. /* Cicada Interrupt Status Register */
  34. #define MII_CIS8201_ISTAT 0x1a
  35. #define MII_CIS8201_ISTAT_STATUS 0x8000
  36. #define MII_CIS8201_ISTAT_SPEED 0x4000
  37. #define MII_CIS8201_ISTAT_LINK 0x2000
  38. #define MII_CIS8201_ISTAT_DUPLEX 0x1000
  39. /* Cicada Auxiliary Control/Status Register */
  40. #define MII_CIS8201_AUX_CONSTAT 0x1c
  41. #define MII_CIS8201_AUXCONSTAT_INIT 0x0004
  42. #define MII_CIS8201_AUXCONSTAT_DUPLEX 0x0020
  43. #define MII_CIS8201_AUXCONSTAT_SPEED 0x0018
  44. #define MII_CIS8201_AUXCONSTAT_GBIT 0x0010
  45. #define MII_CIS8201_AUXCONSTAT_100 0x0008
  46. /* 88E1011 PHY Status Register */
  47. #define MII_M1011_PHY_SPEC_STATUS 0x11
  48. #define MII_M1011_PHY_SPEC_STATUS_1000 0x8000
  49. #define MII_M1011_PHY_SPEC_STATUS_100 0x4000
  50. #define MII_M1011_PHY_SPEC_STATUS_SPD_MASK 0xc000
  51. #define MII_M1011_PHY_SPEC_STATUS_FULLDUPLEX 0x2000
  52. #define MII_M1011_PHY_SPEC_STATUS_RESOLVED 0x0800
  53. #define MII_M1011_PHY_SPEC_STATUS_LINK 0x0400
  54. #define MII_M1011_IEVENT 0x13
  55. #define MII_M1011_IEVENT_CLEAR 0x0000
  56. #define MII_M1011_IMASK 0x12
  57. #define MII_M1011_IMASK_INIT 0x6400
  58. #define MII_M1011_IMASK_CLEAR 0x0000
  59. /* 88E1111 PHY Register */
  60. #define MII_M1111_PHY_EXT_CR 0x14
  61. #define MII_M1111_RX_DELAY 0x80
  62. #define MII_M1111_TX_DELAY 0x2
  63. #define MII_M1111_PHY_EXT_SR 0x1b
  64. #define MII_M1111_HWCFG_MODE_MASK 0xf
  65. #define MII_M1111_HWCFG_MODE_RGMII 0xb
  66. #define MII_DM9161_SCR 0x10
  67. #define MII_DM9161_SCR_INIT 0x0610
  68. #define MII_DM9161_SCR_RMII_INIT 0x0710
  69. /* DM9161 Specified Configuration and Status Register */
  70. #define MII_DM9161_SCSR 0x11
  71. #define MII_DM9161_SCSR_100F 0x8000
  72. #define MII_DM9161_SCSR_100H 0x4000
  73. #define MII_DM9161_SCSR_10F 0x2000
  74. #define MII_DM9161_SCSR_10H 0x1000
  75. /* DM9161 Interrupt Register */
  76. #define MII_DM9161_INTR 0x15
  77. #define MII_DM9161_INTR_PEND 0x8000
  78. #define MII_DM9161_INTR_DPLX_MASK 0x0800
  79. #define MII_DM9161_INTR_SPD_MASK 0x0400
  80. #define MII_DM9161_INTR_LINK_MASK 0x0200
  81. #define MII_DM9161_INTR_MASK 0x0100
  82. #define MII_DM9161_INTR_DPLX_CHANGE 0x0010
  83. #define MII_DM9161_INTR_SPD_CHANGE 0x0008
  84. #define MII_DM9161_INTR_LINK_CHANGE 0x0004
  85. #define MII_DM9161_INTR_INIT 0x0000
  86. #define MII_DM9161_INTR_STOP \
  87. (MII_DM9161_INTR_DPLX_MASK | MII_DM9161_INTR_SPD_MASK \
  88. | MII_DM9161_INTR_LINK_MASK | MII_DM9161_INTR_MASK)
  89. /* DM9161 10BT Configuration/Status */
  90. #define MII_DM9161_10BTCSR 0x12
  91. #define MII_DM9161_10BTCSR_INIT 0x7800
  92. #define MII_BASIC_FEATURES (SUPPORTED_10baseT_Half | \
  93. SUPPORTED_10baseT_Full | \
  94. SUPPORTED_100baseT_Half | \
  95. SUPPORTED_100baseT_Full | \
  96. SUPPORTED_Autoneg | \
  97. SUPPORTED_TP | \
  98. SUPPORTED_MII)
  99. #define MII_GBIT_FEATURES (MII_BASIC_FEATURES | \
  100. SUPPORTED_1000baseT_Half | \
  101. SUPPORTED_1000baseT_Full)
  102. #define MII_READ_COMMAND 0x00000001
  103. #define MII_INTERRUPT_DISABLED 0x0
  104. #define MII_INTERRUPT_ENABLED 0x1
  105. #define SPEED_10 10
  106. #define SPEED_100 100
  107. #define SPEED_1000 1000
  108. /* Duplex, half or full. */
  109. #define DUPLEX_HALF 0x00
  110. #define DUPLEX_FULL 0x01
  111. /* Indicates what features are supported by the interface. */
  112. #define SUPPORTED_10baseT_Half (1 << 0)
  113. #define SUPPORTED_10baseT_Full (1 << 1)
  114. #define SUPPORTED_100baseT_Half (1 << 2)
  115. #define SUPPORTED_100baseT_Full (1 << 3)
  116. #define SUPPORTED_1000baseT_Half (1 << 4)
  117. #define SUPPORTED_1000baseT_Full (1 << 5)
  118. #define SUPPORTED_Autoneg (1 << 6)
  119. #define SUPPORTED_TP (1 << 7)
  120. #define SUPPORTED_AUI (1 << 8)
  121. #define SUPPORTED_MII (1 << 9)
  122. #define SUPPORTED_FIBRE (1 << 10)
  123. #define SUPPORTED_BNC (1 << 11)
  124. #define SUPPORTED_10000baseT_Full (1 << 12)
  125. #define ADVERTISED_10baseT_Half (1 << 0)
  126. #define ADVERTISED_10baseT_Full (1 << 1)
  127. #define ADVERTISED_100baseT_Half (1 << 2)
  128. #define ADVERTISED_100baseT_Full (1 << 3)
  129. #define ADVERTISED_1000baseT_Half (1 << 4)
  130. #define ADVERTISED_1000baseT_Full (1 << 5)
  131. #define ADVERTISED_Autoneg (1 << 6)
  132. #define ADVERTISED_TP (1 << 7)
  133. #define ADVERTISED_AUI (1 << 8)
  134. #define ADVERTISED_MII (1 << 9)
  135. #define ADVERTISED_FIBRE (1 << 10)
  136. #define ADVERTISED_BNC (1 << 11)
  137. #define ADVERTISED_10000baseT_Full (1 << 12)
  138. /* Taken from mii_if_info and sungem_phy.h */
  139. struct uec_mii_info {
  140. /* Information about the PHY type */
  141. /* And management functions */
  142. struct phy_info *phyinfo;
  143. struct eth_device *dev;
  144. /* forced speed & duplex (no autoneg)
  145. * partner speed & duplex & pause (autoneg)
  146. */
  147. int speed;
  148. int duplex;
  149. int pause;
  150. /* The most recently read link state */
  151. int link;
  152. /* Enabled Interrupts */
  153. u32 interrupts;
  154. u32 advertising;
  155. int autoneg;
  156. int mii_id;
  157. /* private data pointer */
  158. /* For use by PHYs to maintain extra state */
  159. void *priv;
  160. /* Provided by ethernet driver */
  161. int (*mdio_read) (struct eth_device * dev, int mii_id, int reg);
  162. void (*mdio_write) (struct eth_device * dev, int mii_id, int reg,
  163. int val);
  164. };
  165. /* struct phy_info: a structure which defines attributes for a PHY
  166. *
  167. * id will contain a number which represents the PHY. During
  168. * startup, the driver will poll the PHY to find out what its
  169. * UID--as defined by registers 2 and 3--is. The 32-bit result
  170. * gotten from the PHY will be ANDed with phy_id_mask to
  171. * discard any bits which may change based on revision numbers
  172. * unimportant to functionality
  173. *
  174. * There are 6 commands which take a ugeth_mii_info structure.
  175. * Each PHY must declare config_aneg, and read_status.
  176. */
  177. struct phy_info {
  178. u32 phy_id;
  179. char *name;
  180. unsigned int phy_id_mask;
  181. u32 features;
  182. /* Called to initialize the PHY */
  183. int (*init) (struct uec_mii_info * mii_info);
  184. /* Called to suspend the PHY for power */
  185. int (*suspend) (struct uec_mii_info * mii_info);
  186. /* Reconfigures autonegotiation (or disables it) */
  187. int (*config_aneg) (struct uec_mii_info * mii_info);
  188. /* Determines the negotiated speed and duplex */
  189. int (*read_status) (struct uec_mii_info * mii_info);
  190. /* Clears any pending interrupts */
  191. int (*ack_interrupt) (struct uec_mii_info * mii_info);
  192. /* Enables or disables interrupts */
  193. int (*config_intr) (struct uec_mii_info * mii_info);
  194. /* Clears up any memory if needed */
  195. void (*close) (struct uec_mii_info * mii_info);
  196. };
  197. struct phy_info *uec_get_phy_info (struct uec_mii_info *mii_info);
  198. void uec_write_phy_reg (struct eth_device *dev, int mii_id, int regnum,
  199. int value);
  200. int uec_read_phy_reg (struct eth_device *dev, int mii_id, int regnum);
  201. void mii_clear_phy_interrupt (struct uec_mii_info *mii_info);
  202. void mii_configure_phy_interrupt (struct uec_mii_info *mii_info,
  203. u32 interrupts);
  204. #endif /* __UEC_PHY_H__ */