lan91c111.h 16 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407
  1. /****************************************************************************
  2. * drivers/net/lan91c111.h
  3. *
  4. * Copyright (C) 2018 Pinecone Inc. All rights reserved.
  5. * Author: Xiang Xiao <xiaoxiang@pinecone.net>
  6. *
  7. * Redistribution and use in source and binary forms, with or without
  8. * modification, are permitted provided that the following conditions
  9. * are met:
  10. *
  11. * 1. Redistributions of source code must retain the above copyright
  12. * notice, this list of conditions and the following disclaimer.
  13. * 2. Redistributions in binary form must reproduce the above copyright
  14. * notice, this list of conditions and the following disclaimer in
  15. * the documentation and/or other materials provided with the
  16. * distribution.
  17. * 3. Neither the name NuttX nor the names of its contributors may be
  18. * used to endorse or promote products derived from this software
  19. * 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
  30. * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
  31. * ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
  32. * POSSIBILITY OF SUCH DAMAGE.
  33. *
  34. ****************************************************************************/
  35. #ifndef __DRIVERS_NET_LAN91C111_H
  36. #define __DRIVERS_NET_LAN91C111_H
  37. /****************************************************************************
  38. * Included Files
  39. ****************************************************************************/
  40. #include <nuttx/net/mii.h>
  41. /****************************************************************************
  42. * Pre-processor Definitions
  43. ****************************************************************************/
  44. /* Bank Select Register:
  45. *
  46. * yyyy yyyy 0000 00xx
  47. * xx = bank number
  48. * yyyy yyyy = 0x33, for identification purposes.
  49. */
  50. #define BANK_SELECT 14
  51. /* Transmit Control Register */
  52. /* BANK 0 */
  53. #define TCR_REG 0x0000
  54. #define TCR_ENABLE 0x0001 /* When 1 we can transmit */
  55. #define TCR_LOOP 0x0002 /* Controls output pin LBK */
  56. #define TCR_FORCOL 0x0004 /* When 1 will force a collision */
  57. #define TCR_PAD_EN 0x0080 /* When 1 will pad tx frames < 64 bytes w/0 */
  58. #define TCR_NOCRC 0x0100 /* When 1 will not append CRC to tx frames */
  59. #define TCR_MON_CSN 0x0400 /* When 1 tx monitors carrier */
  60. #define TCR_FDUPLX 0x0800 /* When 1 enables full duplex operation */
  61. #define TCR_STP_SQET 0x1000 /* When 1 stops tx if Signal Quality Error */
  62. #define TCR_EPH_LOOP 0x2000 /* When 1 enables EPH block loopback */
  63. #define TCR_SWFDUP 0x8000 /* When 1 enables Switched Full Duplex mode */
  64. #define TCR_CLEAR 0 /* do NOTHING */
  65. /* the default settings for the TCR register : */
  66. #define TCR_DEFAULT (TCR_ENABLE | TCR_PAD_EN)
  67. /* EPH Status Register */
  68. /* BANK 0 */
  69. #define EPH_STATUS_REG 0x0002
  70. #define ES_TX_SUC 0x0001 /* Last TX was successful */
  71. #define ES_SNGL_COL 0x0002 /* Single collision detected for last tx */
  72. #define ES_MUL_COL 0x0004 /* Multiple collisions detected for last tx */
  73. #define ES_LTX_MULT 0x0008 /* Last tx was a multicast */
  74. #define ES_16COL 0x0010 /* 16 Collisions Reached */
  75. #define ES_SQET 0x0020 /* Signal Quality Error Test */
  76. #define ES_LTXBRD 0x0040 /* Last tx was a broadcast */
  77. #define ES_TXDEFR 0x0080 /* Transmit Deferred */
  78. #define ES_LATCOL 0x0200 /* Late collision detected on last tx */
  79. #define ES_LOSTCARR 0x0400 /* Lost Carrier Sense */
  80. #define ES_EXC_DEF 0x0800 /* Excessive Deferral */
  81. #define ES_CTR_ROL 0x1000 /* Counter Roll Over indication */
  82. #define ES_LINK_OK 0x4000 /* Driven by inverted value of nLNK pin */
  83. #define ES_TXUNRN 0x8000 /* Tx Underrun */
  84. #define ES_ERRORS (ES_TXUNRN | ES_LOSTCARR | ES_LATCOL | ES_SQET | ES_16COL)
  85. /* Receive Control Register */
  86. /* BANK 0 */
  87. #define RCR_REG 0x0004
  88. #define RCR_RX_ABORT 0x0001 /* Set if a rx frame was aborted */
  89. #define RCR_PRMS 0x0002 /* Enable promiscuous mode */
  90. #define RCR_ALMUL 0x0004 /* When set accepts all multicast frames */
  91. #define RCR_RXEN 0x0100 /* IFF this is set, we can receive packets */
  92. #define RCR_STRIP_CRC 0x0200 /* When set strips CRC from rx packets */
  93. #define RCR_ABORT_ENB 0x2000 /* When set will abort rx on collision */
  94. #define RCR_FILT_CAR 0x4000 /* When set filters leading 12 bit s of carrier */
  95. #define RCR_SOFTRST 0x8000 /* resets the chip */
  96. /* the normal settings for the RCR register : */
  97. #ifdef CONFIG_NET_PROMISCUOUS
  98. # define RCR_DEFAULT (RCR_STRIP_CRC | RCR_RXEN | RCR_PRMS)
  99. #else
  100. # define RCR_DEFAULT (RCR_STRIP_CRC | RCR_RXEN)
  101. #endif
  102. #define RCR_CLEAR 0x0 /* set it to a base state */
  103. /* Counter Register */
  104. /* BANK 0 */
  105. #define COUNTER_REG 0x0006
  106. /* Memory Information Register */
  107. /* BANK 0 */
  108. #define MIR_REG 0x0008
  109. #define MIR_FREE_MASK 0xff00
  110. /* Receive/Phy Control Register */
  111. /* BANK 0 */
  112. #define RPC_REG 0x000A
  113. #define RPC_SPEED 0x2000 /* When 1 PHY is in 100Mbps mode. */
  114. #define RPC_DPLX 0x1000 /* When 1 PHY is in Full-Duplex Mode */
  115. #define RPC_ANEG 0x0800 /* When 1 PHY is in Auto-Negotiate Mode */
  116. #define RPC_LSXA_SHFT 5 /* Bits to shift LS2A,LS1A,LS0A to lsb */
  117. #define RPC_LSXB_SHFT 2 /* Bits to get LS2B,LS1B,LS0B to lsb */
  118. #define RPC_LED_100_10 0x00 /* LED = 100Mbps OR's with 10Mbps link detect */
  119. #define RPC_LED_RES 0x01 /* LED = Reserved */
  120. #define RPC_LED_10 0x02 /* LED = 10Mbps link detect */
  121. #define RPC_LED_FD 0x03 /* LED = Full Duplex Mode */
  122. #define RPC_LED_TX_RX 0x04 /* LED = TX or RX packet occurred */
  123. #define RPC_LED_100 0x05 /* LED = 100Mbps link dectect */
  124. #define RPC_LED_TX 0x06 /* LED = TX packet occurred */
  125. #define RPC_LED_RX 0x07 /* LED = RX packet occurred */
  126. #define RPC_DEFAULT (RPC_ANEG | RPC_SPEED | RPC_DPLX \
  127. | (RPC_LED_100_10 << RPC_LSXA_SHFT) \
  128. | (RPC_LED_TX_RX << RPC_LSXB_SHFT))
  129. /* Bank 0 0x000C is reserved */
  130. /* Bank Select Register */
  131. /* All Banks */
  132. #define BSR_REG 0x000E
  133. /* Configuration Reg */
  134. /* BANK 1 */
  135. #define CONFIG_REG 0x0100
  136. #define CONFIG_EXT_PHY 0x0200 /* 1=external MII, 0=internal Phy */
  137. #define CONFIG_GPCNTRL 0x0400 /* Inverse value drives pin nCNTRL */
  138. #define CONFIG_NO_WAIT 0x1000 /* When 1 no extra wait states on ISA bus */
  139. #define CONFIG_EPH_POWER_EN 0x8000 /* When 0 EPH is placed into low power mode. */
  140. /* Default is powered-up, Internal Phy, Wait States, and pin nCNTRL=low */
  141. #define CONFIG_DEFAULT (CONFIG_EPH_POWER_EN)
  142. #define CONFIG_CLEAR 0
  143. /* Base Address Register */
  144. /* BANK 1 */
  145. #define BASE_REG 0x0102
  146. /* Individual Address Registers */
  147. /* BANK 1 */
  148. #define ADDR0_REG 0x0104
  149. #define ADDR1_REG 0x0106
  150. #define ADDR2_REG 0x0108
  151. /* General Purpose Register */
  152. /* BANK 1 */
  153. #define GP_REG 0x010A
  154. /* Control Register */
  155. /* BANK 1 */
  156. #define CTL_REG 0x010C
  157. #define CTL_RCV_BAD 0x4000 /* When 1 bad CRC packets are received */
  158. #define CTL_AUTO_RELEASE 0x0800 /* When 1 tx pages are released automatically */
  159. #define CTL_LE_ENABLE 0x0080 /* When 1 enables Link Error interrupt */
  160. #define CTL_CR_ENABLE 0x0040 /* When 1 enables Counter Rollover interrupt */
  161. #define CTL_TE_ENABLE 0x0020 /* When 1 enables Transmit Error interrupt */
  162. #define CTL_EEPROM_SELECT 0x0004 /* Controls EEPROM reload & store */
  163. #define CTL_RELOAD 0x0002 /* When set reads EEPROM into registers */
  164. #define CTL_STORE 0x0001 /* When set stores registers into EEPROM */
  165. #define CTL_DEFAULT (CTL_AUTO_RELEASE)
  166. #define CTL_CLEAR 0
  167. /* MMU Command Register */
  168. /* BANK 2 */
  169. #define MMU_CMD_REG 0x0200
  170. #define MC_BUSY 1 /* When 1 the last release has not completed */
  171. #define MC_NOP (0<<5) /* No Op */
  172. #define MC_ALLOC (1<<5) /* OR with number of 256 byte packets */
  173. #define MC_RESET (2<<5) /* Reset MMU to initial state */
  174. #define MC_REMOVE (3<<5) /* Remove the current rx packet */
  175. #define MC_RELEASE (4<<5) /* Remove and release the current rx packet */
  176. #define MC_FREEPKT (5<<5) /* Release packet in PNR register */
  177. #define MC_ENQUEUE (6<<5) /* Enqueue the packet for transmit */
  178. #define MC_RSTTXFIFO (7<<5) /* Reset the TX FIFOs */
  179. /* Packet Number Register */
  180. /* BANK 2 */
  181. #define PN_REG 0x0202
  182. /* Allocation Result Register */
  183. /* BANK 2 */
  184. #define AR_REG 0x0203
  185. #define AR_FAILED 0x80 /* Allocation Failed */
  186. /* TX FIFO Ports Register */
  187. /* BANK 2 */
  188. #define TXFIFO_REG 0x0204
  189. #define TXFIFO_TEMPTY 0x80 /* TX FIFO Empty */
  190. /* RX FIFO Ports Register */
  191. /* BANK 2 */
  192. #define RXFIFO_REG 0x0205
  193. #define RXFIFO_REMPTY 0x80 /* RX FIFO Empty */
  194. #define FIFO_REG 0x0204
  195. /* Pointer Register */
  196. /* BANK 2 */
  197. #define PTR_REG 0x0206
  198. #define PTR_RCV 0x8000 /* 1=Receive area, 0=Transmit area */
  199. #define PTR_AUTOINC 0x4000 /* Auto increment the pointer on each access */
  200. #define PTR_READ 0x2000 /* When 1 the operation is a read */
  201. #define PTR_NOTEMPTY 0x0800 /* When 1 _do not_ write fifo DATA REG */
  202. /* Data Register */
  203. /* BANK 2 */
  204. #define DATA_REG 0x0208
  205. /* Interrupt Status/Acknowledge Register */
  206. /* BANK 2 */
  207. #define INT_REG 0x020C
  208. /* Interrupt Mask Register */
  209. /* BANK 2 */
  210. #define IM_REG 0x020D
  211. #define IM_MDINT 0x80 /* PHY MI Register 18 Interrupt */
  212. #define IM_ERCV_INT 0x40 /* Early Receive Interrupt */
  213. #define IM_EPH_INT 0x20 /* Set by Etheret Protocol Handler section */
  214. #define IM_RX_OVRN_INT 0x10 /* Set by Receiver Overruns */
  215. #define IM_ALLOC_INT 0x08 /* Set when allocation request is completed */
  216. #define IM_TX_EMPTY_INT 0x04 /* Set if the TX FIFO goes empty */
  217. #define IM_TX_INT 0x02 /* Transmit Interrrupt */
  218. #define IM_RCV_INT 0x01 /* Receive Interrupt */
  219. /* Multicast Table Registers */
  220. /* BANK 3 */
  221. #define MCAST_REG1 0x0300
  222. #define MCAST_REG2 0x0302
  223. #define MCAST_REG3 0x0304
  224. #define MCAST_REG4 0x0306
  225. /* Management Interface Register (MII) */
  226. /* BANK 3 */
  227. #define MII_REG 0x0308
  228. #define MII_MSK_CRS100 0x4000 /* Disables CRS100 detection during tx half dup */
  229. #define MII_MDOE 0x0008 /* MII Output Enable */
  230. #define MII_MCLK 0x0004 /* MII Clock, pin MDCLK */
  231. #define MII_MDI 0x0002 /* MII Input, pin MDI */
  232. #define MII_MDO 0x0001 /* MII Output, pin MDO */
  233. /* Revision Register */
  234. /* BANK 3 */
  235. /* ( hi: chip id low: rev # ) */
  236. #define REV_REG 0x030A
  237. /* Early RCV Register */
  238. /* BANK 3 */
  239. /* this is NOT on SMC9192 */
  240. #define ERCV_REG 0x030C
  241. #define ERCV_RCV_DISCRD 0x0080 /* When 1 discards a packet being received */
  242. #define ERCV_THRESHOLD 0x001F /* ERCV Threshold Mask */
  243. /* External Register */
  244. /* BANK 7 */
  245. #define EXT_REG 0x0700
  246. #define CHIP_9192 3
  247. #define CHIP_9194 4
  248. #define CHIP_9195 5
  249. #define CHIP_9196 6
  250. #define CHIP_91100 7
  251. #define CHIP_91100FD 8
  252. #define CHIP_91111FD 9
  253. /* Transmit status bits */
  254. /* Same as ES_xxx */
  255. /* Transmit control bits */
  256. #define TC_ODD 0x20
  257. #define TC_CRC 0x10
  258. /* Receive status bits */
  259. #define RS_ALGNERR 0x8000
  260. #define RS_BRODCAST 0x4000
  261. #define RS_BADCRC 0x2000
  262. #define RS_ODDFRAME 0x1000
  263. #define RS_TOOLONG 0x0800
  264. #define RS_TOOSHORT 0x0400
  265. #define RS_MULTICAST 0x0001
  266. #define RS_ERRORS (RS_ALGNERR | RS_BADCRC | RS_TOOLONG | RS_TOOSHORT)
  267. /* Receive control bits */
  268. #define RC_ODD 0x20
  269. /* PHY IDs
  270. * LAN83C183 == LAN91C111 Internal PHY
  271. */
  272. #define PHY_LAN83C183 0x0016F840
  273. #define PHY_LAN83C180 0x02821C50
  274. /* LPA full duplex flags */
  275. #define MII_LPA_FULL (MII_LPA_10BASETXFULL | MII_LPA_100BASETXFULL)
  276. /* PHY Register Addresses (LAN91C111 Internal PHY)
  277. *
  278. * Generic PHY registers can be found in <nuttx/net/mii.h>
  279. *
  280. * These phy registers are specific to our on-board phy.
  281. */
  282. /* PHY Configuration Register 1 */
  283. #define PHY_CFG1_REG 0x10
  284. #define PHY_CFG1_LNKDIS 0x8000 /* 1=Rx Link Detect Function disabled */
  285. #define PHY_CFG1_XMTDIS 0x4000 /* 1=TP Transmitter Disabled */
  286. #define PHY_CFG1_XMTPDN 0x2000 /* 1=TP Transmitter Powered Down */
  287. #define PHY_CFG1_BYPSCR 0x0400 /* 1=Bypass scrambler/descrambler */
  288. #define PHY_CFG1_UNSCDS 0x0200 /* 1=Unscramble Idle Reception Disable */
  289. #define PHY_CFG1_EQLZR 0x0100 /* 1=Rx Equalizer Disabled */
  290. #define PHY_CFG1_CABLE 0x0080 /* 1=STP(150ohm), 0=UTP(100ohm) */
  291. #define PHY_CFG1_RLVL0 0x0040 /* 1=Rx Squelch level reduced by 4.5db */
  292. #define PHY_CFG1_TLVL_SHIFT 2 /* Transmit Output Level Adjust */
  293. #define PHY_CFG1_TLVL_MASK 0x003C
  294. #define PHY_CFG1_TRF_MASK 0x0003 /* Transmitter Rise/Fall time */
  295. /* PHY Configuration Register 2 */
  296. #define PHY_CFG2_REG 0x11
  297. #define PHY_CFG2_APOLDIS 0x0020 /* 1=Auto Polarity Correction disabled */
  298. #define PHY_CFG2_JABDIS 0x0010 /* 1=Jabber disabled */
  299. #define PHY_CFG2_MREG 0x0008 /* 1=Multiple register access (MII mgt) */
  300. #define PHY_CFG2_INTMDIO 0x0004 /* 1=Interrupt signaled with MDIO pulseo */
  301. /* PHY Status Output (and Interrupt status) Register */
  302. #define PHY_INT_REG 0x12 /* Status Output (Interrupt Status) */
  303. #define PHY_INT_INT 0x8000 /* 1=bits have changed since last read */
  304. #define PHY_INT_LNKFAIL 0x4000 /* 1=Link Not detected */
  305. #define PHY_INT_LOSSSYNC 0x2000 /* 1=Descrambler has lost sync */
  306. #define PHY_INT_CWRD 0x1000 /* 1=Invalid 4B5B code detected on rx */
  307. #define PHY_INT_SSD 0x0800 /* 1=No Start Of Stream detected on rx */
  308. #define PHY_INT_ESD 0x0400 /* 1=No End Of Stream detected on rx */
  309. #define PHY_INT_RPOL 0x0200 /* 1=Reverse Polarity detected */
  310. #define PHY_INT_JAB 0x0100 /* 1=Jabber detected */
  311. #define PHY_INT_SPDDET 0x0080 /* 1=100Base-TX mode, 0=10Base-T mode */
  312. #define PHY_INT_DPLXDET 0x0040 /* 1=Device in Full Duplex */
  313. /* PHY Interrupt/Status Mask Register */
  314. #define PHY_MASK_REG 0x13 /* Interrupt Mask */
  315. /* Uses the same bit definitions as PHY_INT_REG */
  316. #endif /* __DRIVERS_NET_LAN91C111_H */