smc911x.h 18 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494
  1. /*
  2. * SMSC LAN9[12]1[567] Network driver
  3. *
  4. * (c) 2007 Pengutronix, Sascha Hauer <s.hauer@pengutronix.de>
  5. *
  6. * See file CREDITS for list of people who contributed to this
  7. * project.
  8. *
  9. * This program is free software; you can redistribute it and/or
  10. * modify it under the terms of the GNU General Public License as
  11. * published by the Free Software Foundation; either version 2 of
  12. * the License, or (at your option) any later version.
  13. *
  14. * This program is distributed in the hope that it will be useful,
  15. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  16. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  17. * GNU General Public License for more details.
  18. *
  19. * You should have received a copy of the GNU General Public License
  20. * along with this program; if not, write to the Free Software
  21. * Foundation, Inc., 59 Temple Place, Suite 330, Boston,
  22. * MA 02111-1307 USA
  23. */
  24. #ifndef _SMC911X_H_
  25. #define _SMC911X_H_
  26. #include <linux/types.h>
  27. #if defined (CONFIG_DRIVER_SMC911X_32_BIT) && \
  28. defined (CONFIG_DRIVER_SMC911X_16_BIT)
  29. #error "SMC911X: Only one of CONFIG_DRIVER_SMC911X_32_BIT and \
  30. CONFIG_DRIVER_SMC911X_16_BIT shall be set"
  31. #endif
  32. #if defined (CONFIG_DRIVER_SMC911X_32_BIT)
  33. static inline u32 __smc911x_reg_read(u32 addr)
  34. {
  35. return *(volatile u32*)addr;
  36. }
  37. u32 smc911x_reg_read(u32 addr) __attribute__((weak, alias("__smc911x_reg_read")));
  38. static inline void __smc911x_reg_write(u32 addr, u32 val)
  39. {
  40. *(volatile u32*)addr = val;
  41. }
  42. void smc911x_reg_write(u32 addr, u32 val) __attribute__((weak, alias("__smc911x_reg_write")));
  43. #elif defined (CONFIG_DRIVER_SMC911X_16_BIT)
  44. static inline u32 smc911x_reg_read(u32 addr)
  45. {
  46. volatile u16 *addr_16 = (u16 *)addr;
  47. return ((*addr_16 & 0x0000ffff) | (*(addr_16 + 1) << 16));
  48. }
  49. static inline void smc911x_reg_write(u32 addr, u32 val)
  50. {
  51. *(volatile u16*)addr = (u16)val;
  52. *(volatile u16*)(addr + 2) = (u16)(val >> 16);
  53. }
  54. #else
  55. #error "SMC911X: undefined bus width"
  56. #endif /* CONFIG_DRIVER_SMC911X_16_BIT */
  57. /* Below are the register offsets and bit definitions
  58. * of the Lan911x memory space
  59. */
  60. #define RX_DATA_FIFO (CONFIG_DRIVER_SMC911X_BASE + 0x00)
  61. #define TX_DATA_FIFO (CONFIG_DRIVER_SMC911X_BASE + 0x20)
  62. #define TX_CMD_A_INT_ON_COMP 0x80000000
  63. #define TX_CMD_A_INT_BUF_END_ALGN 0x03000000
  64. #define TX_CMD_A_INT_4_BYTE_ALGN 0x00000000
  65. #define TX_CMD_A_INT_16_BYTE_ALGN 0x01000000
  66. #define TX_CMD_A_INT_32_BYTE_ALGN 0x02000000
  67. #define TX_CMD_A_INT_DATA_OFFSET 0x001F0000
  68. #define TX_CMD_A_INT_FIRST_SEG 0x00002000
  69. #define TX_CMD_A_INT_LAST_SEG 0x00001000
  70. #define TX_CMD_A_BUF_SIZE 0x000007FF
  71. #define TX_CMD_B_PKT_TAG 0xFFFF0000
  72. #define TX_CMD_B_ADD_CRC_DISABLE 0x00002000
  73. #define TX_CMD_B_DISABLE_PADDING 0x00001000
  74. #define TX_CMD_B_PKT_BYTE_LENGTH 0x000007FF
  75. #define RX_STATUS_FIFO (CONFIG_DRIVER_SMC911X_BASE + 0x40)
  76. #define RX_STS_PKT_LEN 0x3FFF0000
  77. #define RX_STS_ES 0x00008000
  78. #define RX_STS_BCST 0x00002000
  79. #define RX_STS_LEN_ERR 0x00001000
  80. #define RX_STS_RUNT_ERR 0x00000800
  81. #define RX_STS_MCAST 0x00000400
  82. #define RX_STS_TOO_LONG 0x00000080
  83. #define RX_STS_COLL 0x00000040
  84. #define RX_STS_ETH_TYPE 0x00000020
  85. #define RX_STS_WDOG_TMT 0x00000010
  86. #define RX_STS_MII_ERR 0x00000008
  87. #define RX_STS_DRIBBLING 0x00000004
  88. #define RX_STS_CRC_ERR 0x00000002
  89. #define RX_STATUS_FIFO_PEEK (CONFIG_DRIVER_SMC911X_BASE + 0x44)
  90. #define TX_STATUS_FIFO (CONFIG_DRIVER_SMC911X_BASE + 0x48)
  91. #define TX_STS_TAG 0xFFFF0000
  92. #define TX_STS_ES 0x00008000
  93. #define TX_STS_LOC 0x00000800
  94. #define TX_STS_NO_CARR 0x00000400
  95. #define TX_STS_LATE_COLL 0x00000200
  96. #define TX_STS_MANY_COLL 0x00000100
  97. #define TX_STS_COLL_CNT 0x00000078
  98. #define TX_STS_MANY_DEFER 0x00000004
  99. #define TX_STS_UNDERRUN 0x00000002
  100. #define TX_STS_DEFERRED 0x00000001
  101. #define TX_STATUS_FIFO_PEEK (CONFIG_DRIVER_SMC911X_BASE + 0x4C)
  102. #define ID_REV (CONFIG_DRIVER_SMC911X_BASE + 0x50)
  103. #define ID_REV_CHIP_ID 0xFFFF0000 /* RO */
  104. #define ID_REV_REV_ID 0x0000FFFF /* RO */
  105. #define INT_CFG (CONFIG_DRIVER_SMC911X_BASE + 0x54)
  106. #define INT_CFG_INT_DEAS 0xFF000000 /* R/W */
  107. #define INT_CFG_INT_DEAS_CLR 0x00004000
  108. #define INT_CFG_INT_DEAS_STS 0x00002000
  109. #define INT_CFG_IRQ_INT 0x00001000 /* RO */
  110. #define INT_CFG_IRQ_EN 0x00000100 /* R/W */
  111. #define INT_CFG_IRQ_POL 0x00000010 /* R/W Not Affected by SW Reset */
  112. #define INT_CFG_IRQ_TYPE 0x00000001 /* R/W Not Affected by SW Reset */
  113. #define INT_STS (CONFIG_DRIVER_SMC911X_BASE + 0x58)
  114. #define INT_STS_SW_INT 0x80000000 /* R/WC */
  115. #define INT_STS_TXSTOP_INT 0x02000000 /* R/WC */
  116. #define INT_STS_RXSTOP_INT 0x01000000 /* R/WC */
  117. #define INT_STS_RXDFH_INT 0x00800000 /* R/WC */
  118. #define INT_STS_RXDF_INT 0x00400000 /* R/WC */
  119. #define INT_STS_TX_IOC 0x00200000 /* R/WC */
  120. #define INT_STS_RXD_INT 0x00100000 /* R/WC */
  121. #define INT_STS_GPT_INT 0x00080000 /* R/WC */
  122. #define INT_STS_PHY_INT 0x00040000 /* RO */
  123. #define INT_STS_PME_INT 0x00020000 /* R/WC */
  124. #define INT_STS_TXSO 0x00010000 /* R/WC */
  125. #define INT_STS_RWT 0x00008000 /* R/WC */
  126. #define INT_STS_RXE 0x00004000 /* R/WC */
  127. #define INT_STS_TXE 0x00002000 /* R/WC */
  128. /*#define INT_STS_ERX 0x00001000*/ /* R/WC */
  129. #define INT_STS_TDFU 0x00000800 /* R/WC */
  130. #define INT_STS_TDFO 0x00000400 /* R/WC */
  131. #define INT_STS_TDFA 0x00000200 /* R/WC */
  132. #define INT_STS_TSFF 0x00000100 /* R/WC */
  133. #define INT_STS_TSFL 0x00000080 /* R/WC */
  134. /*#define INT_STS_RXDF 0x00000040*/ /* R/WC */
  135. #define INT_STS_RDFO 0x00000040 /* R/WC */
  136. #define INT_STS_RDFL 0x00000020 /* R/WC */
  137. #define INT_STS_RSFF 0x00000010 /* R/WC */
  138. #define INT_STS_RSFL 0x00000008 /* R/WC */
  139. #define INT_STS_GPIO2_INT 0x00000004 /* R/WC */
  140. #define INT_STS_GPIO1_INT 0x00000002 /* R/WC */
  141. #define INT_STS_GPIO0_INT 0x00000001 /* R/WC */
  142. #define INT_EN (CONFIG_DRIVER_SMC911X_BASE + 0x5C)
  143. #define INT_EN_SW_INT_EN 0x80000000 /* R/W */
  144. #define INT_EN_TXSTOP_INT_EN 0x02000000 /* R/W */
  145. #define INT_EN_RXSTOP_INT_EN 0x01000000 /* R/W */
  146. #define INT_EN_RXDFH_INT_EN 0x00800000 /* R/W */
  147. /*#define INT_EN_RXDF_INT_EN 0x00400000*/ /* R/W */
  148. #define INT_EN_TIOC_INT_EN 0x00200000 /* R/W */
  149. #define INT_EN_RXD_INT_EN 0x00100000 /* R/W */
  150. #define INT_EN_GPT_INT_EN 0x00080000 /* R/W */
  151. #define INT_EN_PHY_INT_EN 0x00040000 /* R/W */
  152. #define INT_EN_PME_INT_EN 0x00020000 /* R/W */
  153. #define INT_EN_TXSO_EN 0x00010000 /* R/W */
  154. #define INT_EN_RWT_EN 0x00008000 /* R/W */
  155. #define INT_EN_RXE_EN 0x00004000 /* R/W */
  156. #define INT_EN_TXE_EN 0x00002000 /* R/W */
  157. /*#define INT_EN_ERX_EN 0x00001000*/ /* R/W */
  158. #define INT_EN_TDFU_EN 0x00000800 /* R/W */
  159. #define INT_EN_TDFO_EN 0x00000400 /* R/W */
  160. #define INT_EN_TDFA_EN 0x00000200 /* R/W */
  161. #define INT_EN_TSFF_EN 0x00000100 /* R/W */
  162. #define INT_EN_TSFL_EN 0x00000080 /* R/W */
  163. /*#define INT_EN_RXDF_EN 0x00000040*/ /* R/W */
  164. #define INT_EN_RDFO_EN 0x00000040 /* R/W */
  165. #define INT_EN_RDFL_EN 0x00000020 /* R/W */
  166. #define INT_EN_RSFF_EN 0x00000010 /* R/W */
  167. #define INT_EN_RSFL_EN 0x00000008 /* R/W */
  168. #define INT_EN_GPIO2_INT 0x00000004 /* R/W */
  169. #define INT_EN_GPIO1_INT 0x00000002 /* R/W */
  170. #define INT_EN_GPIO0_INT 0x00000001 /* R/W */
  171. #define BYTE_TEST (CONFIG_DRIVER_SMC911X_BASE + 0x64)
  172. #define FIFO_INT (CONFIG_DRIVER_SMC911X_BASE + 0x68)
  173. #define FIFO_INT_TX_AVAIL_LEVEL 0xFF000000 /* R/W */
  174. #define FIFO_INT_TX_STS_LEVEL 0x00FF0000 /* R/W */
  175. #define FIFO_INT_RX_AVAIL_LEVEL 0x0000FF00 /* R/W */
  176. #define FIFO_INT_RX_STS_LEVEL 0x000000FF /* R/W */
  177. #define RX_CFG (CONFIG_DRIVER_SMC911X_BASE + 0x6C)
  178. #define RX_CFG_RX_END_ALGN 0xC0000000 /* R/W */
  179. #define RX_CFG_RX_END_ALGN4 0x00000000 /* R/W */
  180. #define RX_CFG_RX_END_ALGN16 0x40000000 /* R/W */
  181. #define RX_CFG_RX_END_ALGN32 0x80000000 /* R/W */
  182. #define RX_CFG_RX_DMA_CNT 0x0FFF0000 /* R/W */
  183. #define RX_CFG_RX_DUMP 0x00008000 /* R/W */
  184. #define RX_CFG_RXDOFF 0x00001F00 /* R/W */
  185. /*#define RX_CFG_RXBAD 0x00000001*/ /* R/W */
  186. #define TX_CFG (CONFIG_DRIVER_SMC911X_BASE + 0x70)
  187. /*#define TX_CFG_TX_DMA_LVL 0xE0000000*/ /* R/W */
  188. /*#define TX_CFG_TX_DMA_CNT 0x0FFF0000*/ /* R/W Self Clearing */
  189. #define TX_CFG_TXS_DUMP 0x00008000 /* Self Clearing */
  190. #define TX_CFG_TXD_DUMP 0x00004000 /* Self Clearing */
  191. #define TX_CFG_TXSAO 0x00000004 /* R/W */
  192. #define TX_CFG_TX_ON 0x00000002 /* R/W */
  193. #define TX_CFG_STOP_TX 0x00000001 /* Self Clearing */
  194. #define HW_CFG (CONFIG_DRIVER_SMC911X_BASE + 0x74)
  195. #define HW_CFG_TTM 0x00200000 /* R/W */
  196. #define HW_CFG_SF 0x00100000 /* R/W */
  197. #define HW_CFG_TX_FIF_SZ 0x000F0000 /* R/W */
  198. #define HW_CFG_TR 0x00003000 /* R/W */
  199. #define HW_CFG_PHY_CLK_SEL 0x00000060 /* R/W */
  200. #define HW_CFG_PHY_CLK_SEL_INT_PHY 0x00000000 /* R/W */
  201. #define HW_CFG_PHY_CLK_SEL_EXT_PHY 0x00000020 /* R/W */
  202. #define HW_CFG_PHY_CLK_SEL_CLK_DIS 0x00000040 /* R/W */
  203. #define HW_CFG_SMI_SEL 0x00000010 /* R/W */
  204. #define HW_CFG_EXT_PHY_DET 0x00000008 /* RO */
  205. #define HW_CFG_EXT_PHY_EN 0x00000004 /* R/W */
  206. #define HW_CFG_32_16_BIT_MODE 0x00000004 /* RO */
  207. #define HW_CFG_SRST_TO 0x00000002 /* RO */
  208. #define HW_CFG_SRST 0x00000001 /* Self Clearing */
  209. #define RX_DP_CTRL (CONFIG_DRIVER_SMC911X_BASE + 0x78)
  210. #define RX_DP_CTRL_RX_FFWD 0x80000000 /* R/W */
  211. #define RX_DP_CTRL_FFWD_BUSY 0x80000000 /* RO */
  212. #define RX_FIFO_INF (CONFIG_DRIVER_SMC911X_BASE + 0x7C)
  213. #define RX_FIFO_INF_RXSUSED 0x00FF0000 /* RO */
  214. #define RX_FIFO_INF_RXDUSED 0x0000FFFF /* RO */
  215. #define TX_FIFO_INF (CONFIG_DRIVER_SMC911X_BASE + 0x80)
  216. #define TX_FIFO_INF_TSUSED 0x00FF0000 /* RO */
  217. #define TX_FIFO_INF_TDFREE 0x0000FFFF /* RO */
  218. #define PMT_CTRL (CONFIG_DRIVER_SMC911X_BASE + 0x84)
  219. #define PMT_CTRL_PM_MODE 0x00003000 /* Self Clearing */
  220. #define PMT_CTRL_PHY_RST 0x00000400 /* Self Clearing */
  221. #define PMT_CTRL_WOL_EN 0x00000200 /* R/W */
  222. #define PMT_CTRL_ED_EN 0x00000100 /* R/W */
  223. #define PMT_CTRL_PME_TYPE 0x00000040 /* R/W Not Affected by SW Reset */
  224. #define PMT_CTRL_WUPS 0x00000030 /* R/WC */
  225. #define PMT_CTRL_WUPS_NOWAKE 0x00000000 /* R/WC */
  226. #define PMT_CTRL_WUPS_ED 0x00000010 /* R/WC */
  227. #define PMT_CTRL_WUPS_WOL 0x00000020 /* R/WC */
  228. #define PMT_CTRL_WUPS_MULTI 0x00000030 /* R/WC */
  229. #define PMT_CTRL_PME_IND 0x00000008 /* R/W */
  230. #define PMT_CTRL_PME_POL 0x00000004 /* R/W */
  231. #define PMT_CTRL_PME_EN 0x00000002 /* R/W Not Affected by SW Reset */
  232. #define PMT_CTRL_READY 0x00000001 /* RO */
  233. #define GPIO_CFG (CONFIG_DRIVER_SMC911X_BASE + 0x88)
  234. #define GPIO_CFG_LED3_EN 0x40000000 /* R/W */
  235. #define GPIO_CFG_LED2_EN 0x20000000 /* R/W */
  236. #define GPIO_CFG_LED1_EN 0x10000000 /* R/W */
  237. #define GPIO_CFG_GPIO2_INT_POL 0x04000000 /* R/W */
  238. #define GPIO_CFG_GPIO1_INT_POL 0x02000000 /* R/W */
  239. #define GPIO_CFG_GPIO0_INT_POL 0x01000000 /* R/W */
  240. #define GPIO_CFG_EEPR_EN 0x00700000 /* R/W */
  241. #define GPIO_CFG_GPIOBUF2 0x00040000 /* R/W */
  242. #define GPIO_CFG_GPIOBUF1 0x00020000 /* R/W */
  243. #define GPIO_CFG_GPIOBUF0 0x00010000 /* R/W */
  244. #define GPIO_CFG_GPIODIR2 0x00000400 /* R/W */
  245. #define GPIO_CFG_GPIODIR1 0x00000200 /* R/W */
  246. #define GPIO_CFG_GPIODIR0 0x00000100 /* R/W */
  247. #define GPIO_CFG_GPIOD4 0x00000010 /* R/W */
  248. #define GPIO_CFG_GPIOD3 0x00000008 /* R/W */
  249. #define GPIO_CFG_GPIOD2 0x00000004 /* R/W */
  250. #define GPIO_CFG_GPIOD1 0x00000002 /* R/W */
  251. #define GPIO_CFG_GPIOD0 0x00000001 /* R/W */
  252. #define GPT_CFG (CONFIG_DRIVER_SMC911X_BASE + 0x8C)
  253. #define GPT_CFG_TIMER_EN 0x20000000 /* R/W */
  254. #define GPT_CFG_GPT_LOAD 0x0000FFFF /* R/W */
  255. #define GPT_CNT (CONFIG_DRIVER_SMC911X_BASE + 0x90)
  256. #define GPT_CNT_GPT_CNT 0x0000FFFF /* RO */
  257. #define ENDIAN (CONFIG_DRIVER_SMC911X_BASE + 0x98)
  258. #define FREE_RUN (CONFIG_DRIVER_SMC911X_BASE + 0x9C)
  259. #define RX_DROP (CONFIG_DRIVER_SMC911X_BASE + 0xA0)
  260. #define MAC_CSR_CMD (CONFIG_DRIVER_SMC911X_BASE + 0xA4)
  261. #define MAC_CSR_CMD_CSR_BUSY 0x80000000 /* Self Clearing */
  262. #define MAC_CSR_CMD_R_NOT_W 0x40000000 /* R/W */
  263. #define MAC_CSR_CMD_CSR_ADDR 0x000000FF /* R/W */
  264. #define MAC_CSR_DATA (CONFIG_DRIVER_SMC911X_BASE + 0xA8)
  265. #define AFC_CFG (CONFIG_DRIVER_SMC911X_BASE + 0xAC)
  266. #define AFC_CFG_AFC_HI 0x00FF0000 /* R/W */
  267. #define AFC_CFG_AFC_LO 0x0000FF00 /* R/W */
  268. #define AFC_CFG_BACK_DUR 0x000000F0 /* R/W */
  269. #define AFC_CFG_FCMULT 0x00000008 /* R/W */
  270. #define AFC_CFG_FCBRD 0x00000004 /* R/W */
  271. #define AFC_CFG_FCADD 0x00000002 /* R/W */
  272. #define AFC_CFG_FCANY 0x00000001 /* R/W */
  273. #define E2P_CMD (CONFIG_DRIVER_SMC911X_BASE + 0xB0)
  274. #define E2P_CMD_EPC_BUSY 0x80000000 /* Self Clearing */
  275. #define E2P_CMD_EPC_CMD 0x70000000 /* R/W */
  276. #define E2P_CMD_EPC_CMD_READ 0x00000000 /* R/W */
  277. #define E2P_CMD_EPC_CMD_EWDS 0x10000000 /* R/W */
  278. #define E2P_CMD_EPC_CMD_EWEN 0x20000000 /* R/W */
  279. #define E2P_CMD_EPC_CMD_WRITE 0x30000000 /* R/W */
  280. #define E2P_CMD_EPC_CMD_WRAL 0x40000000 /* R/W */
  281. #define E2P_CMD_EPC_CMD_ERASE 0x50000000 /* R/W */
  282. #define E2P_CMD_EPC_CMD_ERAL 0x60000000 /* R/W */
  283. #define E2P_CMD_EPC_CMD_RELOAD 0x70000000 /* R/W */
  284. #define E2P_CMD_EPC_TIMEOUT 0x00000200 /* RO */
  285. #define E2P_CMD_MAC_ADDR_LOADED 0x00000100 /* RO */
  286. #define E2P_CMD_EPC_ADDR 0x000000FF /* R/W */
  287. #define E2P_DATA (CONFIG_DRIVER_SMC911X_BASE + 0xB4)
  288. #define E2P_DATA_EEPROM_DATA 0x000000FF /* R/W */
  289. /* end of LAN register offsets and bit definitions */
  290. /* MAC Control and Status registers */
  291. #define MAC_CR 0x01 /* R/W */
  292. /* MAC_CR - MAC Control Register */
  293. #define MAC_CR_RXALL 0x80000000
  294. /* TODO: delete this bit? It is not described in the data sheet. */
  295. #define MAC_CR_HBDIS 0x10000000
  296. #define MAC_CR_RCVOWN 0x00800000
  297. #define MAC_CR_LOOPBK 0x00200000
  298. #define MAC_CR_FDPX 0x00100000
  299. #define MAC_CR_MCPAS 0x00080000
  300. #define MAC_CR_PRMS 0x00040000
  301. #define MAC_CR_INVFILT 0x00020000
  302. #define MAC_CR_PASSBAD 0x00010000
  303. #define MAC_CR_HFILT 0x00008000
  304. #define MAC_CR_HPFILT 0x00002000
  305. #define MAC_CR_LCOLL 0x00001000
  306. #define MAC_CR_BCAST 0x00000800
  307. #define MAC_CR_DISRTY 0x00000400
  308. #define MAC_CR_PADSTR 0x00000100
  309. #define MAC_CR_BOLMT_MASK 0x000000C0
  310. #define MAC_CR_DFCHK 0x00000020
  311. #define MAC_CR_TXEN 0x00000008
  312. #define MAC_CR_RXEN 0x00000004
  313. #define ADDRH 0x02 /* R/W mask 0x0000FFFFUL */
  314. #define ADDRL 0x03 /* R/W mask 0xFFFFFFFFUL */
  315. #define HASHH 0x04 /* R/W */
  316. #define HASHL 0x05 /* R/W */
  317. #define MII_ACC 0x06 /* R/W */
  318. #define MII_ACC_PHY_ADDR 0x0000F800
  319. #define MII_ACC_MIIRINDA 0x000007C0
  320. #define MII_ACC_MII_WRITE 0x00000002
  321. #define MII_ACC_MII_BUSY 0x00000001
  322. #define MII_DATA 0x07 /* R/W mask 0x0000FFFFUL */
  323. #define FLOW 0x08 /* R/W */
  324. #define FLOW_FCPT 0xFFFF0000
  325. #define FLOW_FCPASS 0x00000004
  326. #define FLOW_FCEN 0x00000002
  327. #define FLOW_FCBSY 0x00000001
  328. #define VLAN1 0x09 /* R/W mask 0x0000FFFFUL */
  329. #define VLAN1_VTI1 0x0000ffff
  330. #define VLAN2 0x0A /* R/W mask 0x0000FFFFUL */
  331. #define VLAN2_VTI2 0x0000ffff
  332. #define WUFF 0x0B /* WO */
  333. #define WUCSR 0x0C /* R/W */
  334. #define WUCSR_GUE 0x00000200
  335. #define WUCSR_WUFR 0x00000040
  336. #define WUCSR_MPR 0x00000020
  337. #define WUCSR_WAKE_EN 0x00000004
  338. #define WUCSR_MPEN 0x00000002
  339. /* Chip ID values */
  340. #define CHIP_9115 0x115
  341. #define CHIP_9116 0x116
  342. #define CHIP_9117 0x117
  343. #define CHIP_9118 0x118
  344. #define CHIP_9211 0x9211
  345. #define CHIP_9215 0x115a
  346. #define CHIP_9216 0x116a
  347. #define CHIP_9217 0x117a
  348. #define CHIP_9218 0x118a
  349. struct chip_id {
  350. u16 id;
  351. char *name;
  352. };
  353. static const struct chip_id chip_ids[] = {
  354. { CHIP_9115, "LAN9115" },
  355. { CHIP_9116, "LAN9116" },
  356. { CHIP_9117, "LAN9117" },
  357. { CHIP_9118, "LAN9118" },
  358. { CHIP_9211, "LAN9211" },
  359. { CHIP_9215, "LAN9215" },
  360. { CHIP_9216, "LAN9216" },
  361. { CHIP_9217, "LAN9217" },
  362. { CHIP_9218, "LAN9218" },
  363. { 0, NULL },
  364. };
  365. #define DRIVERNAME "smc911x"
  366. static u32 smc911x_get_mac_csr(u8 reg)
  367. {
  368. while (smc911x_reg_read(MAC_CSR_CMD) & MAC_CSR_CMD_CSR_BUSY)
  369. ;
  370. smc911x_reg_write(MAC_CSR_CMD, MAC_CSR_CMD_CSR_BUSY | MAC_CSR_CMD_R_NOT_W | reg);
  371. while (smc911x_reg_read(MAC_CSR_CMD) & MAC_CSR_CMD_CSR_BUSY)
  372. ;
  373. return smc911x_reg_read(MAC_CSR_DATA);
  374. }
  375. static void smc911x_set_mac_csr(u8 reg, u32 data)
  376. {
  377. while (smc911x_reg_read(MAC_CSR_CMD) & MAC_CSR_CMD_CSR_BUSY)
  378. ;
  379. smc911x_reg_write(MAC_CSR_DATA, data);
  380. smc911x_reg_write(MAC_CSR_CMD, MAC_CSR_CMD_CSR_BUSY | reg);
  381. while (smc911x_reg_read(MAC_CSR_CMD) & MAC_CSR_CMD_CSR_BUSY)
  382. ;
  383. }
  384. static int smc911x_detect_chip(void)
  385. {
  386. unsigned long val, i;
  387. val = smc911x_reg_read(BYTE_TEST);
  388. if (val != 0x87654321) {
  389. printf(DRIVERNAME ": Invalid chip endian 0x%08lx\n", val);
  390. return -1;
  391. }
  392. val = smc911x_reg_read(ID_REV) >> 16;
  393. for (i = 0; chip_ids[i].id != 0; i++) {
  394. if (chip_ids[i].id == val) break;
  395. }
  396. if (!chip_ids[i].id) {
  397. printf(DRIVERNAME ": Unknown chip ID %04lx\n", val);
  398. return -1;
  399. }
  400. printf(DRIVERNAME ": detected %s controller\n", chip_ids[i].name);
  401. return 0;
  402. }
  403. static void smc911x_reset(void)
  404. {
  405. int timeout;
  406. /* Take out of PM setting first */
  407. if (smc911x_reg_read(PMT_CTRL) & PMT_CTRL_READY) {
  408. /* Write to the bytetest will take out of powerdown */
  409. smc911x_reg_write(BYTE_TEST, 0x0);
  410. timeout = 10;
  411. while (timeout-- && !(smc911x_reg_read(PMT_CTRL) & PMT_CTRL_READY))
  412. udelay(10);
  413. if (!timeout) {
  414. printf(DRIVERNAME
  415. ": timeout waiting for PM restore\n");
  416. return;
  417. }
  418. }
  419. /* Disable interrupts */
  420. smc911x_reg_write(INT_EN, 0);
  421. smc911x_reg_write(HW_CFG, HW_CFG_SRST);
  422. timeout = 1000;
  423. while (timeout-- && smc911x_reg_read(E2P_CMD) & E2P_CMD_EPC_BUSY)
  424. udelay(10);
  425. if (!timeout) {
  426. printf(DRIVERNAME ": reset timeout\n");
  427. return;
  428. }
  429. /* Reset the FIFO level and flow control settings */
  430. smc911x_set_mac_csr(FLOW, FLOW_FCPT | FLOW_FCEN);
  431. smc911x_reg_write(AFC_CFG, 0x0050287F);
  432. /* Set to LED outputs */
  433. smc911x_reg_write(GPIO_CFG, 0x70070000);
  434. }
  435. #endif