smc911x.h 30 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841
  1. /*------------------------------------------------------------------------
  2. . smc911x.h - macros for SMSC's LAN911{5,6,7,8} single-chip Ethernet device.
  3. .
  4. . Copyright (C) 2005 Sensoria Corp.
  5. . Derived from the unified SMC91x driver by Nicolas Pitre
  6. .
  7. . This program is free software; you can redistribute it and/or modify
  8. . it under the terms of the GNU General Public License as published by
  9. . the Free Software Foundation; either version 2 of the License, or
  10. . (at your option) any later version.
  11. .
  12. . This program is distributed in the hope that it will be useful,
  13. . but WITHOUT ANY WARRANTY; without even the implied warranty of
  14. . MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  15. . GNU General Public License for more details.
  16. .
  17. . You should have received a copy of the GNU General Public License
  18. . along with this program; if not, write to the Free Software
  19. . Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
  20. .
  21. . Information contained in this file was obtained from the LAN9118
  22. . manual from SMC. To get a copy, if you really want one, you can find
  23. . information under www.smsc.com.
  24. .
  25. . Authors
  26. . Dustin McIntire <dustin@sensoria.com>
  27. .
  28. ---------------------------------------------------------------------------*/
  29. #ifndef _SMC911X_H_
  30. #define _SMC911X_H_
  31. /*
  32. * Use the DMA feature on PXA chips
  33. */
  34. #ifdef CONFIG_ARCH_PXA
  35. #define SMC_USE_PXA_DMA 1
  36. #define SMC_USE_16BIT 0
  37. #define SMC_USE_32BIT 1
  38. #define SMC_IRQ_SENSE IRQF_TRIGGER_FALLING
  39. #elif CONFIG_SH_MAGIC_PANEL_R2
  40. #define SMC_USE_SH_DMA 0
  41. #define SMC_USE_16BIT 0
  42. #define SMC_USE_32BIT 1
  43. #define SMC_IRQ_SENSE IRQF_TRIGGER_LOW
  44. #endif
  45. /*
  46. * Define the bus width specific IO macros
  47. */
  48. #if SMC_USE_16BIT
  49. #define SMC_inb(a, r) readb((a) + (r))
  50. #define SMC_inw(a, r) readw((a) + (r))
  51. #define SMC_inl(a, r) ((SMC_inw(a, r) & 0xFFFF)+(SMC_inw(a+2, r)<<16))
  52. #define SMC_outb(v, a, r) writeb(v, (a) + (r))
  53. #define SMC_outw(v, a, r) writew(v, (a) + (r))
  54. #define SMC_outl(v, a, r) \
  55. do{ \
  56. writel(v & 0xFFFF, (a) + (r)); \
  57. writel(v >> 16, (a) + (r) + 2); \
  58. } while (0)
  59. #define SMC_insl(a, r, p, l) readsw((short*)((a) + (r)), p, l*2)
  60. #define SMC_outsl(a, r, p, l) writesw((short*)((a) + (r)), p, l*2)
  61. #elif SMC_USE_32BIT
  62. #define SMC_inb(a, r) readb((a) + (r))
  63. #define SMC_inw(a, r) readw((a) + (r))
  64. #define SMC_inl(a, r) readl((a) + (r))
  65. #define SMC_outb(v, a, r) writeb(v, (a) + (r))
  66. #define SMC_outl(v, a, r) writel(v, (a) + (r))
  67. #define SMC_insl(a, r, p, l) readsl((int*)((a) + (r)), p, l)
  68. #define SMC_outsl(a, r, p, l) writesl((int*)((a) + (r)), p, l)
  69. #endif /* SMC_USE_16BIT */
  70. #if SMC_USE_PXA_DMA
  71. #define SMC_USE_DMA
  72. /*
  73. * Define the request and free functions
  74. * These are unfortunately architecture specific as no generic allocation
  75. * mechanism exits
  76. */
  77. #define SMC_DMA_REQUEST(dev, handler) \
  78. pxa_request_dma(dev->name, DMA_PRIO_LOW, handler, dev)
  79. #define SMC_DMA_FREE(dev, dma) \
  80. pxa_free_dma(dma)
  81. #define SMC_DMA_ACK_IRQ(dev, dma) \
  82. { \
  83. if (DCSR(dma) & DCSR_BUSERR) { \
  84. printk("%s: DMA %d bus error!\n", dev->name, dma); \
  85. } \
  86. DCSR(dma) = DCSR_STARTINTR|DCSR_ENDINTR|DCSR_BUSERR; \
  87. }
  88. /*
  89. * Use a DMA for RX and TX packets.
  90. */
  91. #include <linux/dma-mapping.h>
  92. #include <asm/dma.h>
  93. #include <asm/arch/pxa-regs.h>
  94. static dma_addr_t rx_dmabuf, tx_dmabuf;
  95. static int rx_dmalen, tx_dmalen;
  96. #ifdef SMC_insl
  97. #undef SMC_insl
  98. #define SMC_insl(a, r, p, l) \
  99. smc_pxa_dma_insl(lp->dev, a, lp->physaddr, r, lp->rxdma, p, l)
  100. static inline void
  101. smc_pxa_dma_insl(struct device *dev, u_long ioaddr, u_long physaddr,
  102. int reg, int dma, u_char *buf, int len)
  103. {
  104. /* 64 bit alignment is required for memory to memory DMA */
  105. if ((long)buf & 4) {
  106. *((u32 *)buf) = SMC_inl(ioaddr, reg);
  107. buf += 4;
  108. len--;
  109. }
  110. len *= 4;
  111. rx_dmabuf = dma_map_single(dev, buf, len, DMA_FROM_DEVICE);
  112. rx_dmalen = len;
  113. DCSR(dma) = DCSR_NODESC;
  114. DTADR(dma) = rx_dmabuf;
  115. DSADR(dma) = physaddr + reg;
  116. DCMD(dma) = (DCMD_INCTRGADDR | DCMD_BURST32 |
  117. DCMD_WIDTH4 | DCMD_ENDIRQEN | (DCMD_LENGTH & rx_dmalen));
  118. DCSR(dma) = DCSR_NODESC | DCSR_RUN;
  119. }
  120. #endif
  121. #ifdef SMC_insw
  122. #undef SMC_insw
  123. #define SMC_insw(a, r, p, l) \
  124. smc_pxa_dma_insw(lp->dev, a, lp->physaddr, r, lp->rxdma, p, l)
  125. static inline void
  126. smc_pxa_dma_insw(struct device *dev, u_long ioaddr, u_long physaddr,
  127. int reg, int dma, u_char *buf, int len)
  128. {
  129. /* 64 bit alignment is required for memory to memory DMA */
  130. while ((long)buf & 6) {
  131. *((u16 *)buf) = SMC_inw(ioaddr, reg);
  132. buf += 2;
  133. len--;
  134. }
  135. len *= 2;
  136. rx_dmabuf = dma_map_single(dev, buf, len, DMA_FROM_DEVICE);
  137. rx_dmalen = len;
  138. DCSR(dma) = DCSR_NODESC;
  139. DTADR(dma) = rx_dmabuf;
  140. DSADR(dma) = physaddr + reg;
  141. DCMD(dma) = (DCMD_INCTRGADDR | DCMD_BURST32 |
  142. DCMD_WIDTH2 | DCMD_ENDIRQEN | (DCMD_LENGTH & rx_dmalen));
  143. DCSR(dma) = DCSR_NODESC | DCSR_RUN;
  144. }
  145. #endif
  146. #ifdef SMC_outsl
  147. #undef SMC_outsl
  148. #define SMC_outsl(a, r, p, l) \
  149. smc_pxa_dma_outsl(lp->dev, a, lp->physaddr, r, lp->txdma, p, l)
  150. static inline void
  151. smc_pxa_dma_outsl(struct device *dev, u_long ioaddr, u_long physaddr,
  152. int reg, int dma, u_char *buf, int len)
  153. {
  154. /* 64 bit alignment is required for memory to memory DMA */
  155. if ((long)buf & 4) {
  156. SMC_outl(*((u32 *)buf), ioaddr, reg);
  157. buf += 4;
  158. len--;
  159. }
  160. len *= 4;
  161. tx_dmabuf = dma_map_single(dev, buf, len, DMA_TO_DEVICE);
  162. tx_dmalen = len;
  163. DCSR(dma) = DCSR_NODESC;
  164. DSADR(dma) = tx_dmabuf;
  165. DTADR(dma) = physaddr + reg;
  166. DCMD(dma) = (DCMD_INCSRCADDR | DCMD_BURST32 |
  167. DCMD_WIDTH4 | DCMD_ENDIRQEN | (DCMD_LENGTH & tx_dmalen));
  168. DCSR(dma) = DCSR_NODESC | DCSR_RUN;
  169. }
  170. #endif
  171. #ifdef SMC_outsw
  172. #undef SMC_outsw
  173. #define SMC_outsw(a, r, p, l) \
  174. smc_pxa_dma_outsw(lp->dev, a, lp->physaddr, r, lp->txdma, p, l)
  175. static inline void
  176. smc_pxa_dma_outsw(struct device *dev, u_long ioaddr, u_long physaddr,
  177. int reg, int dma, u_char *buf, int len)
  178. {
  179. /* 64 bit alignment is required for memory to memory DMA */
  180. while ((long)buf & 6) {
  181. SMC_outw(*((u16 *)buf), ioaddr, reg);
  182. buf += 2;
  183. len--;
  184. }
  185. len *= 2;
  186. tx_dmabuf = dma_map_single(dev, buf, len, DMA_TO_DEVICE);
  187. tx_dmalen = len;
  188. DCSR(dma) = DCSR_NODESC;
  189. DSADR(dma) = tx_dmabuf;
  190. DTADR(dma) = physaddr + reg;
  191. DCMD(dma) = (DCMD_INCSRCADDR | DCMD_BURST32 |
  192. DCMD_WIDTH2 | DCMD_ENDIRQEN | (DCMD_LENGTH & tx_dmalen));
  193. DCSR(dma) = DCSR_NODESC | DCSR_RUN;
  194. }
  195. #endif
  196. #endif /* SMC_USE_PXA_DMA */
  197. /* Chip Parameters and Register Definitions */
  198. #define SMC911X_TX_FIFO_LOW_THRESHOLD (1536*2)
  199. #define SMC911X_IO_EXTENT 0x100
  200. #define SMC911X_EEPROM_LEN 7
  201. /* Below are the register offsets and bit definitions
  202. * of the Lan911x memory space
  203. */
  204. #define RX_DATA_FIFO (0x00)
  205. #define TX_DATA_FIFO (0x20)
  206. #define TX_CMD_A_INT_ON_COMP_ (0x80000000)
  207. #define TX_CMD_A_INT_BUF_END_ALGN_ (0x03000000)
  208. #define TX_CMD_A_INT_4_BYTE_ALGN_ (0x00000000)
  209. #define TX_CMD_A_INT_16_BYTE_ALGN_ (0x01000000)
  210. #define TX_CMD_A_INT_32_BYTE_ALGN_ (0x02000000)
  211. #define TX_CMD_A_INT_DATA_OFFSET_ (0x001F0000)
  212. #define TX_CMD_A_INT_FIRST_SEG_ (0x00002000)
  213. #define TX_CMD_A_INT_LAST_SEG_ (0x00001000)
  214. #define TX_CMD_A_BUF_SIZE_ (0x000007FF)
  215. #define TX_CMD_B_PKT_TAG_ (0xFFFF0000)
  216. #define TX_CMD_B_ADD_CRC_DISABLE_ (0x00002000)
  217. #define TX_CMD_B_DISABLE_PADDING_ (0x00001000)
  218. #define TX_CMD_B_PKT_BYTE_LENGTH_ (0x000007FF)
  219. #define RX_STATUS_FIFO (0x40)
  220. #define RX_STS_PKT_LEN_ (0x3FFF0000)
  221. #define RX_STS_ES_ (0x00008000)
  222. #define RX_STS_BCST_ (0x00002000)
  223. #define RX_STS_LEN_ERR_ (0x00001000)
  224. #define RX_STS_RUNT_ERR_ (0x00000800)
  225. #define RX_STS_MCAST_ (0x00000400)
  226. #define RX_STS_TOO_LONG_ (0x00000080)
  227. #define RX_STS_COLL_ (0x00000040)
  228. #define RX_STS_ETH_TYPE_ (0x00000020)
  229. #define RX_STS_WDOG_TMT_ (0x00000010)
  230. #define RX_STS_MII_ERR_ (0x00000008)
  231. #define RX_STS_DRIBBLING_ (0x00000004)
  232. #define RX_STS_CRC_ERR_ (0x00000002)
  233. #define RX_STATUS_FIFO_PEEK (0x44)
  234. #define TX_STATUS_FIFO (0x48)
  235. #define TX_STS_TAG_ (0xFFFF0000)
  236. #define TX_STS_ES_ (0x00008000)
  237. #define TX_STS_LOC_ (0x00000800)
  238. #define TX_STS_NO_CARR_ (0x00000400)
  239. #define TX_STS_LATE_COLL_ (0x00000200)
  240. #define TX_STS_MANY_COLL_ (0x00000100)
  241. #define TX_STS_COLL_CNT_ (0x00000078)
  242. #define TX_STS_MANY_DEFER_ (0x00000004)
  243. #define TX_STS_UNDERRUN_ (0x00000002)
  244. #define TX_STS_DEFERRED_ (0x00000001)
  245. #define TX_STATUS_FIFO_PEEK (0x4C)
  246. #define ID_REV (0x50)
  247. #define ID_REV_CHIP_ID_ (0xFFFF0000) /* RO */
  248. #define ID_REV_REV_ID_ (0x0000FFFF) /* RO */
  249. #define INT_CFG (0x54)
  250. #define INT_CFG_INT_DEAS_ (0xFF000000) /* R/W */
  251. #define INT_CFG_INT_DEAS_CLR_ (0x00004000)
  252. #define INT_CFG_INT_DEAS_STS_ (0x00002000)
  253. #define INT_CFG_IRQ_INT_ (0x00001000) /* RO */
  254. #define INT_CFG_IRQ_EN_ (0x00000100) /* R/W */
  255. #define INT_CFG_IRQ_POL_ (0x00000010) /* R/W Not Affected by SW Reset */
  256. #define INT_CFG_IRQ_TYPE_ (0x00000001) /* R/W Not Affected by SW Reset */
  257. #define INT_STS (0x58)
  258. #define INT_STS_SW_INT_ (0x80000000) /* R/WC */
  259. #define INT_STS_TXSTOP_INT_ (0x02000000) /* R/WC */
  260. #define INT_STS_RXSTOP_INT_ (0x01000000) /* R/WC */
  261. #define INT_STS_RXDFH_INT_ (0x00800000) /* R/WC */
  262. #define INT_STS_RXDF_INT_ (0x00400000) /* R/WC */
  263. #define INT_STS_TX_IOC_ (0x00200000) /* R/WC */
  264. #define INT_STS_RXD_INT_ (0x00100000) /* R/WC */
  265. #define INT_STS_GPT_INT_ (0x00080000) /* R/WC */
  266. #define INT_STS_PHY_INT_ (0x00040000) /* RO */
  267. #define INT_STS_PME_INT_ (0x00020000) /* R/WC */
  268. #define INT_STS_TXSO_ (0x00010000) /* R/WC */
  269. #define INT_STS_RWT_ (0x00008000) /* R/WC */
  270. #define INT_STS_RXE_ (0x00004000) /* R/WC */
  271. #define INT_STS_TXE_ (0x00002000) /* R/WC */
  272. //#define INT_STS_ERX_ (0x00001000) /* R/WC */
  273. #define INT_STS_TDFU_ (0x00000800) /* R/WC */
  274. #define INT_STS_TDFO_ (0x00000400) /* R/WC */
  275. #define INT_STS_TDFA_ (0x00000200) /* R/WC */
  276. #define INT_STS_TSFF_ (0x00000100) /* R/WC */
  277. #define INT_STS_TSFL_ (0x00000080) /* R/WC */
  278. //#define INT_STS_RXDF_ (0x00000040) /* R/WC */
  279. #define INT_STS_RDFO_ (0x00000040) /* R/WC */
  280. #define INT_STS_RDFL_ (0x00000020) /* R/WC */
  281. #define INT_STS_RSFF_ (0x00000010) /* R/WC */
  282. #define INT_STS_RSFL_ (0x00000008) /* R/WC */
  283. #define INT_STS_GPIO2_INT_ (0x00000004) /* R/WC */
  284. #define INT_STS_GPIO1_INT_ (0x00000002) /* R/WC */
  285. #define INT_STS_GPIO0_INT_ (0x00000001) /* R/WC */
  286. #define INT_EN (0x5C)
  287. #define INT_EN_SW_INT_EN_ (0x80000000) /* R/W */
  288. #define INT_EN_TXSTOP_INT_EN_ (0x02000000) /* R/W */
  289. #define INT_EN_RXSTOP_INT_EN_ (0x01000000) /* R/W */
  290. #define INT_EN_RXDFH_INT_EN_ (0x00800000) /* R/W */
  291. //#define INT_EN_RXDF_INT_EN_ (0x00400000) /* R/W */
  292. #define INT_EN_TIOC_INT_EN_ (0x00200000) /* R/W */
  293. #define INT_EN_RXD_INT_EN_ (0x00100000) /* R/W */
  294. #define INT_EN_GPT_INT_EN_ (0x00080000) /* R/W */
  295. #define INT_EN_PHY_INT_EN_ (0x00040000) /* R/W */
  296. #define INT_EN_PME_INT_EN_ (0x00020000) /* R/W */
  297. #define INT_EN_TXSO_EN_ (0x00010000) /* R/W */
  298. #define INT_EN_RWT_EN_ (0x00008000) /* R/W */
  299. #define INT_EN_RXE_EN_ (0x00004000) /* R/W */
  300. #define INT_EN_TXE_EN_ (0x00002000) /* R/W */
  301. //#define INT_EN_ERX_EN_ (0x00001000) /* R/W */
  302. #define INT_EN_TDFU_EN_ (0x00000800) /* R/W */
  303. #define INT_EN_TDFO_EN_ (0x00000400) /* R/W */
  304. #define INT_EN_TDFA_EN_ (0x00000200) /* R/W */
  305. #define INT_EN_TSFF_EN_ (0x00000100) /* R/W */
  306. #define INT_EN_TSFL_EN_ (0x00000080) /* R/W */
  307. //#define INT_EN_RXDF_EN_ (0x00000040) /* R/W */
  308. #define INT_EN_RDFO_EN_ (0x00000040) /* R/W */
  309. #define INT_EN_RDFL_EN_ (0x00000020) /* R/W */
  310. #define INT_EN_RSFF_EN_ (0x00000010) /* R/W */
  311. #define INT_EN_RSFL_EN_ (0x00000008) /* R/W */
  312. #define INT_EN_GPIO2_INT_ (0x00000004) /* R/W */
  313. #define INT_EN_GPIO1_INT_ (0x00000002) /* R/W */
  314. #define INT_EN_GPIO0_INT_ (0x00000001) /* R/W */
  315. #define BYTE_TEST (0x64)
  316. #define FIFO_INT (0x68)
  317. #define FIFO_INT_TX_AVAIL_LEVEL_ (0xFF000000) /* R/W */
  318. #define FIFO_INT_TX_STS_LEVEL_ (0x00FF0000) /* R/W */
  319. #define FIFO_INT_RX_AVAIL_LEVEL_ (0x0000FF00) /* R/W */
  320. #define FIFO_INT_RX_STS_LEVEL_ (0x000000FF) /* R/W */
  321. #define RX_CFG (0x6C)
  322. #define RX_CFG_RX_END_ALGN_ (0xC0000000) /* R/W */
  323. #define RX_CFG_RX_END_ALGN4_ (0x00000000) /* R/W */
  324. #define RX_CFG_RX_END_ALGN16_ (0x40000000) /* R/W */
  325. #define RX_CFG_RX_END_ALGN32_ (0x80000000) /* R/W */
  326. #define RX_CFG_RX_DMA_CNT_ (0x0FFF0000) /* R/W */
  327. #define RX_CFG_RX_DUMP_ (0x00008000) /* R/W */
  328. #define RX_CFG_RXDOFF_ (0x00001F00) /* R/W */
  329. //#define RX_CFG_RXBAD_ (0x00000001) /* R/W */
  330. #define TX_CFG (0x70)
  331. //#define TX_CFG_TX_DMA_LVL_ (0xE0000000) /* R/W */
  332. //#define TX_CFG_TX_DMA_CNT_ (0x0FFF0000) /* R/W Self Clearing */
  333. #define TX_CFG_TXS_DUMP_ (0x00008000) /* Self Clearing */
  334. #define TX_CFG_TXD_DUMP_ (0x00004000) /* Self Clearing */
  335. #define TX_CFG_TXSAO_ (0x00000004) /* R/W */
  336. #define TX_CFG_TX_ON_ (0x00000002) /* R/W */
  337. #define TX_CFG_STOP_TX_ (0x00000001) /* Self Clearing */
  338. #define HW_CFG (0x74)
  339. #define HW_CFG_TTM_ (0x00200000) /* R/W */
  340. #define HW_CFG_SF_ (0x00100000) /* R/W */
  341. #define HW_CFG_TX_FIF_SZ_ (0x000F0000) /* R/W */
  342. #define HW_CFG_TR_ (0x00003000) /* R/W */
  343. #define HW_CFG_PHY_CLK_SEL_ (0x00000060) /* R/W */
  344. #define HW_CFG_PHY_CLK_SEL_INT_PHY_ (0x00000000) /* R/W */
  345. #define HW_CFG_PHY_CLK_SEL_EXT_PHY_ (0x00000020) /* R/W */
  346. #define HW_CFG_PHY_CLK_SEL_CLK_DIS_ (0x00000040) /* R/W */
  347. #define HW_CFG_SMI_SEL_ (0x00000010) /* R/W */
  348. #define HW_CFG_EXT_PHY_DET_ (0x00000008) /* RO */
  349. #define HW_CFG_EXT_PHY_EN_ (0x00000004) /* R/W */
  350. #define HW_CFG_32_16_BIT_MODE_ (0x00000004) /* RO */
  351. #define HW_CFG_SRST_TO_ (0x00000002) /* RO */
  352. #define HW_CFG_SRST_ (0x00000001) /* Self Clearing */
  353. #define RX_DP_CTRL (0x78)
  354. #define RX_DP_CTRL_RX_FFWD_ (0x80000000) /* R/W */
  355. #define RX_DP_CTRL_FFWD_BUSY_ (0x80000000) /* RO */
  356. #define RX_FIFO_INF (0x7C)
  357. #define RX_FIFO_INF_RXSUSED_ (0x00FF0000) /* RO */
  358. #define RX_FIFO_INF_RXDUSED_ (0x0000FFFF) /* RO */
  359. #define TX_FIFO_INF (0x80)
  360. #define TX_FIFO_INF_TSUSED_ (0x00FF0000) /* RO */
  361. #define TX_FIFO_INF_TDFREE_ (0x0000FFFF) /* RO */
  362. #define PMT_CTRL (0x84)
  363. #define PMT_CTRL_PM_MODE_ (0x00003000) /* Self Clearing */
  364. #define PMT_CTRL_PHY_RST_ (0x00000400) /* Self Clearing */
  365. #define PMT_CTRL_WOL_EN_ (0x00000200) /* R/W */
  366. #define PMT_CTRL_ED_EN_ (0x00000100) /* R/W */
  367. #define PMT_CTRL_PME_TYPE_ (0x00000040) /* R/W Not Affected by SW Reset */
  368. #define PMT_CTRL_WUPS_ (0x00000030) /* R/WC */
  369. #define PMT_CTRL_WUPS_NOWAKE_ (0x00000000) /* R/WC */
  370. #define PMT_CTRL_WUPS_ED_ (0x00000010) /* R/WC */
  371. #define PMT_CTRL_WUPS_WOL_ (0x00000020) /* R/WC */
  372. #define PMT_CTRL_WUPS_MULTI_ (0x00000030) /* R/WC */
  373. #define PMT_CTRL_PME_IND_ (0x00000008) /* R/W */
  374. #define PMT_CTRL_PME_POL_ (0x00000004) /* R/W */
  375. #define PMT_CTRL_PME_EN_ (0x00000002) /* R/W Not Affected by SW Reset */
  376. #define PMT_CTRL_READY_ (0x00000001) /* RO */
  377. #define GPIO_CFG (0x88)
  378. #define GPIO_CFG_LED3_EN_ (0x40000000) /* R/W */
  379. #define GPIO_CFG_LED2_EN_ (0x20000000) /* R/W */
  380. #define GPIO_CFG_LED1_EN_ (0x10000000) /* R/W */
  381. #define GPIO_CFG_GPIO2_INT_POL_ (0x04000000) /* R/W */
  382. #define GPIO_CFG_GPIO1_INT_POL_ (0x02000000) /* R/W */
  383. #define GPIO_CFG_GPIO0_INT_POL_ (0x01000000) /* R/W */
  384. #define GPIO_CFG_EEPR_EN_ (0x00700000) /* R/W */
  385. #define GPIO_CFG_GPIOBUF2_ (0x00040000) /* R/W */
  386. #define GPIO_CFG_GPIOBUF1_ (0x00020000) /* R/W */
  387. #define GPIO_CFG_GPIOBUF0_ (0x00010000) /* R/W */
  388. #define GPIO_CFG_GPIODIR2_ (0x00000400) /* R/W */
  389. #define GPIO_CFG_GPIODIR1_ (0x00000200) /* R/W */
  390. #define GPIO_CFG_GPIODIR0_ (0x00000100) /* R/W */
  391. #define GPIO_CFG_GPIOD4_ (0x00000010) /* R/W */
  392. #define GPIO_CFG_GPIOD3_ (0x00000008) /* R/W */
  393. #define GPIO_CFG_GPIOD2_ (0x00000004) /* R/W */
  394. #define GPIO_CFG_GPIOD1_ (0x00000002) /* R/W */
  395. #define GPIO_CFG_GPIOD0_ (0x00000001) /* R/W */
  396. #define GPT_CFG (0x8C)
  397. #define GPT_CFG_TIMER_EN_ (0x20000000) /* R/W */
  398. #define GPT_CFG_GPT_LOAD_ (0x0000FFFF) /* R/W */
  399. #define GPT_CNT (0x90)
  400. #define GPT_CNT_GPT_CNT_ (0x0000FFFF) /* RO */
  401. #define ENDIAN (0x98)
  402. #define FREE_RUN (0x9C)
  403. #define RX_DROP (0xA0)
  404. #define MAC_CSR_CMD (0xA4)
  405. #define MAC_CSR_CMD_CSR_BUSY_ (0x80000000) /* Self Clearing */
  406. #define MAC_CSR_CMD_R_NOT_W_ (0x40000000) /* R/W */
  407. #define MAC_CSR_CMD_CSR_ADDR_ (0x000000FF) /* R/W */
  408. #define MAC_CSR_DATA (0xA8)
  409. #define AFC_CFG (0xAC)
  410. #define AFC_CFG_AFC_HI_ (0x00FF0000) /* R/W */
  411. #define AFC_CFG_AFC_LO_ (0x0000FF00) /* R/W */
  412. #define AFC_CFG_BACK_DUR_ (0x000000F0) /* R/W */
  413. #define AFC_CFG_FCMULT_ (0x00000008) /* R/W */
  414. #define AFC_CFG_FCBRD_ (0x00000004) /* R/W */
  415. #define AFC_CFG_FCADD_ (0x00000002) /* R/W */
  416. #define AFC_CFG_FCANY_ (0x00000001) /* R/W */
  417. #define E2P_CMD (0xB0)
  418. #define E2P_CMD_EPC_BUSY_ (0x80000000) /* Self Clearing */
  419. #define E2P_CMD_EPC_CMD_ (0x70000000) /* R/W */
  420. #define E2P_CMD_EPC_CMD_READ_ (0x00000000) /* R/W */
  421. #define E2P_CMD_EPC_CMD_EWDS_ (0x10000000) /* R/W */
  422. #define E2P_CMD_EPC_CMD_EWEN_ (0x20000000) /* R/W */
  423. #define E2P_CMD_EPC_CMD_WRITE_ (0x30000000) /* R/W */
  424. #define E2P_CMD_EPC_CMD_WRAL_ (0x40000000) /* R/W */
  425. #define E2P_CMD_EPC_CMD_ERASE_ (0x50000000) /* R/W */
  426. #define E2P_CMD_EPC_CMD_ERAL_ (0x60000000) /* R/W */
  427. #define E2P_CMD_EPC_CMD_RELOAD_ (0x70000000) /* R/W */
  428. #define E2P_CMD_EPC_TIMEOUT_ (0x00000200) /* RO */
  429. #define E2P_CMD_MAC_ADDR_LOADED_ (0x00000100) /* RO */
  430. #define E2P_CMD_EPC_ADDR_ (0x000000FF) /* R/W */
  431. #define E2P_DATA (0xB4)
  432. #define E2P_DATA_EEPROM_DATA_ (0x000000FF) /* R/W */
  433. /* end of LAN register offsets and bit definitions */
  434. /*
  435. ****************************************************************************
  436. ****************************************************************************
  437. * MAC Control and Status Register (Indirect Address)
  438. * Offset (through the MAC_CSR CMD and DATA port)
  439. ****************************************************************************
  440. ****************************************************************************
  441. *
  442. */
  443. #define MAC_CR (0x01) /* R/W */
  444. /* MAC_CR - MAC Control Register */
  445. #define MAC_CR_RXALL_ (0x80000000)
  446. // TODO: delete this bit? It is not described in the data sheet.
  447. #define MAC_CR_HBDIS_ (0x10000000)
  448. #define MAC_CR_RCVOWN_ (0x00800000)
  449. #define MAC_CR_LOOPBK_ (0x00200000)
  450. #define MAC_CR_FDPX_ (0x00100000)
  451. #define MAC_CR_MCPAS_ (0x00080000)
  452. #define MAC_CR_PRMS_ (0x00040000)
  453. #define MAC_CR_INVFILT_ (0x00020000)
  454. #define MAC_CR_PASSBAD_ (0x00010000)
  455. #define MAC_CR_HFILT_ (0x00008000)
  456. #define MAC_CR_HPFILT_ (0x00002000)
  457. #define MAC_CR_LCOLL_ (0x00001000)
  458. #define MAC_CR_BCAST_ (0x00000800)
  459. #define MAC_CR_DISRTY_ (0x00000400)
  460. #define MAC_CR_PADSTR_ (0x00000100)
  461. #define MAC_CR_BOLMT_MASK_ (0x000000C0)
  462. #define MAC_CR_DFCHK_ (0x00000020)
  463. #define MAC_CR_TXEN_ (0x00000008)
  464. #define MAC_CR_RXEN_ (0x00000004)
  465. #define ADDRH (0x02) /* R/W mask 0x0000FFFFUL */
  466. #define ADDRL (0x03) /* R/W mask 0xFFFFFFFFUL */
  467. #define HASHH (0x04) /* R/W */
  468. #define HASHL (0x05) /* R/W */
  469. #define MII_ACC (0x06) /* R/W */
  470. #define MII_ACC_PHY_ADDR_ (0x0000F800)
  471. #define MII_ACC_MIIRINDA_ (0x000007C0)
  472. #define MII_ACC_MII_WRITE_ (0x00000002)
  473. #define MII_ACC_MII_BUSY_ (0x00000001)
  474. #define MII_DATA (0x07) /* R/W mask 0x0000FFFFUL */
  475. #define FLOW (0x08) /* R/W */
  476. #define FLOW_FCPT_ (0xFFFF0000)
  477. #define FLOW_FCPASS_ (0x00000004)
  478. #define FLOW_FCEN_ (0x00000002)
  479. #define FLOW_FCBSY_ (0x00000001)
  480. #define VLAN1 (0x09) /* R/W mask 0x0000FFFFUL */
  481. #define VLAN1_VTI1_ (0x0000ffff)
  482. #define VLAN2 (0x0A) /* R/W mask 0x0000FFFFUL */
  483. #define VLAN2_VTI2_ (0x0000ffff)
  484. #define WUFF (0x0B) /* WO */
  485. #define WUCSR (0x0C) /* R/W */
  486. #define WUCSR_GUE_ (0x00000200)
  487. #define WUCSR_WUFR_ (0x00000040)
  488. #define WUCSR_MPR_ (0x00000020)
  489. #define WUCSR_WAKE_EN_ (0x00000004)
  490. #define WUCSR_MPEN_ (0x00000002)
  491. /*
  492. ****************************************************************************
  493. * Chip Specific MII Defines
  494. ****************************************************************************
  495. *
  496. * Phy register offsets and bit definitions
  497. *
  498. */
  499. #define PHY_MODE_CTRL_STS ((u32)17) /* Mode Control/Status Register */
  500. //#define MODE_CTRL_STS_FASTRIP_ ((u16)0x4000)
  501. #define MODE_CTRL_STS_EDPWRDOWN_ ((u16)0x2000)
  502. //#define MODE_CTRL_STS_LOWSQEN_ ((u16)0x0800)
  503. //#define MODE_CTRL_STS_MDPREBP_ ((u16)0x0400)
  504. //#define MODE_CTRL_STS_FARLOOPBACK_ ((u16)0x0200)
  505. //#define MODE_CTRL_STS_FASTEST_ ((u16)0x0100)
  506. //#define MODE_CTRL_STS_REFCLKEN_ ((u16)0x0010)
  507. //#define MODE_CTRL_STS_PHYADBP_ ((u16)0x0008)
  508. //#define MODE_CTRL_STS_FORCE_G_LINK_ ((u16)0x0004)
  509. #define MODE_CTRL_STS_ENERGYON_ ((u16)0x0002)
  510. #define PHY_INT_SRC ((u32)29)
  511. #define PHY_INT_SRC_ENERGY_ON_ ((u16)0x0080)
  512. #define PHY_INT_SRC_ANEG_COMP_ ((u16)0x0040)
  513. #define PHY_INT_SRC_REMOTE_FAULT_ ((u16)0x0020)
  514. #define PHY_INT_SRC_LINK_DOWN_ ((u16)0x0010)
  515. #define PHY_INT_SRC_ANEG_LP_ACK_ ((u16)0x0008)
  516. #define PHY_INT_SRC_PAR_DET_FAULT_ ((u16)0x0004)
  517. #define PHY_INT_SRC_ANEG_PGRX_ ((u16)0x0002)
  518. #define PHY_INT_MASK ((u32)30)
  519. #define PHY_INT_MASK_ENERGY_ON_ ((u16)0x0080)
  520. #define PHY_INT_MASK_ANEG_COMP_ ((u16)0x0040)
  521. #define PHY_INT_MASK_REMOTE_FAULT_ ((u16)0x0020)
  522. #define PHY_INT_MASK_LINK_DOWN_ ((u16)0x0010)
  523. #define PHY_INT_MASK_ANEG_LP_ACK_ ((u16)0x0008)
  524. #define PHY_INT_MASK_PAR_DET_FAULT_ ((u16)0x0004)
  525. #define PHY_INT_MASK_ANEG_PGRX_ ((u16)0x0002)
  526. #define PHY_SPECIAL ((u32)31)
  527. #define PHY_SPECIAL_ANEG_DONE_ ((u16)0x1000)
  528. #define PHY_SPECIAL_RES_ ((u16)0x0040)
  529. #define PHY_SPECIAL_RES_MASK_ ((u16)0x0FE1)
  530. #define PHY_SPECIAL_SPD_ ((u16)0x001C)
  531. #define PHY_SPECIAL_SPD_10HALF_ ((u16)0x0004)
  532. #define PHY_SPECIAL_SPD_10FULL_ ((u16)0x0014)
  533. #define PHY_SPECIAL_SPD_100HALF_ ((u16)0x0008)
  534. #define PHY_SPECIAL_SPD_100FULL_ ((u16)0x0018)
  535. #define LAN911X_INTERNAL_PHY_ID (0x0007C000)
  536. /* Chip ID values */
  537. #define CHIP_9115 0x115
  538. #define CHIP_9116 0x116
  539. #define CHIP_9117 0x117
  540. #define CHIP_9118 0x118
  541. struct chip_id {
  542. u16 id;
  543. char *name;
  544. };
  545. static const struct chip_id chip_ids[] = {
  546. { CHIP_9115, "LAN9115" },
  547. { CHIP_9116, "LAN9116" },
  548. { CHIP_9117, "LAN9117" },
  549. { CHIP_9118, "LAN9118" },
  550. { 0, NULL },
  551. };
  552. #define IS_REV_A(x) ((x & 0xFFFF)==0)
  553. /*
  554. * Macros to abstract register access according to the data bus
  555. * capabilities. Please use those and not the in/out primitives.
  556. */
  557. /* FIFO read/write macros */
  558. #define SMC_PUSH_DATA(p, l) SMC_outsl( ioaddr, TX_DATA_FIFO, p, (l) >> 2 )
  559. #define SMC_PULL_DATA(p, l) SMC_insl ( ioaddr, RX_DATA_FIFO, p, (l) >> 2 )
  560. #define SMC_SET_TX_FIFO(x) SMC_outl( x, ioaddr, TX_DATA_FIFO )
  561. #define SMC_GET_RX_FIFO() SMC_inl( ioaddr, RX_DATA_FIFO )
  562. /* I/O mapped register read/write macros */
  563. #define SMC_GET_TX_STS_FIFO() SMC_inl( ioaddr, TX_STATUS_FIFO )
  564. #define SMC_GET_RX_STS_FIFO() SMC_inl( ioaddr, RX_STATUS_FIFO )
  565. #define SMC_GET_RX_STS_FIFO_PEEK() SMC_inl( ioaddr, RX_STATUS_FIFO_PEEK )
  566. #define SMC_GET_PN() (SMC_inl( ioaddr, ID_REV ) >> 16)
  567. #define SMC_GET_REV() (SMC_inl( ioaddr, ID_REV ) & 0xFFFF)
  568. #define SMC_GET_IRQ_CFG() SMC_inl( ioaddr, INT_CFG )
  569. #define SMC_SET_IRQ_CFG(x) SMC_outl( x, ioaddr, INT_CFG )
  570. #define SMC_GET_INT() SMC_inl( ioaddr, INT_STS )
  571. #define SMC_ACK_INT(x) SMC_outl( x, ioaddr, INT_STS )
  572. #define SMC_GET_INT_EN() SMC_inl( ioaddr, INT_EN )
  573. #define SMC_SET_INT_EN(x) SMC_outl( x, ioaddr, INT_EN )
  574. #define SMC_GET_BYTE_TEST() SMC_inl( ioaddr, BYTE_TEST )
  575. #define SMC_SET_BYTE_TEST(x) SMC_outl( x, ioaddr, BYTE_TEST )
  576. #define SMC_GET_FIFO_INT() SMC_inl( ioaddr, FIFO_INT )
  577. #define SMC_SET_FIFO_INT(x) SMC_outl( x, ioaddr, FIFO_INT )
  578. #define SMC_SET_FIFO_TDA(x) \
  579. do { \
  580. unsigned long __flags; \
  581. int __mask; \
  582. local_irq_save(__flags); \
  583. __mask = SMC_GET_FIFO_INT() & ~(0xFF<<24); \
  584. SMC_SET_FIFO_INT( __mask | (x)<<24 ); \
  585. local_irq_restore(__flags); \
  586. } while (0)
  587. #define SMC_SET_FIFO_TSL(x) \
  588. do { \
  589. unsigned long __flags; \
  590. int __mask; \
  591. local_irq_save(__flags); \
  592. __mask = SMC_GET_FIFO_INT() & ~(0xFF<<16); \
  593. SMC_SET_FIFO_INT( __mask | (((x) & 0xFF)<<16)); \
  594. local_irq_restore(__flags); \
  595. } while (0)
  596. #define SMC_SET_FIFO_RSA(x) \
  597. do { \
  598. unsigned long __flags; \
  599. int __mask; \
  600. local_irq_save(__flags); \
  601. __mask = SMC_GET_FIFO_INT() & ~(0xFF<<8); \
  602. SMC_SET_FIFO_INT( __mask | (((x) & 0xFF)<<8)); \
  603. local_irq_restore(__flags); \
  604. } while (0)
  605. #define SMC_SET_FIFO_RSL(x) \
  606. do { \
  607. unsigned long __flags; \
  608. int __mask; \
  609. local_irq_save(__flags); \
  610. __mask = SMC_GET_FIFO_INT() & ~0xFF; \
  611. SMC_SET_FIFO_INT( __mask | ((x) & 0xFF)); \
  612. local_irq_restore(__flags); \
  613. } while (0)
  614. #define SMC_GET_RX_CFG() SMC_inl( ioaddr, RX_CFG )
  615. #define SMC_SET_RX_CFG(x) SMC_outl( x, ioaddr, RX_CFG )
  616. #define SMC_GET_TX_CFG() SMC_inl( ioaddr, TX_CFG )
  617. #define SMC_SET_TX_CFG(x) SMC_outl( x, ioaddr, TX_CFG )
  618. #define SMC_GET_HW_CFG() SMC_inl( ioaddr, HW_CFG )
  619. #define SMC_SET_HW_CFG(x) SMC_outl( x, ioaddr, HW_CFG )
  620. #define SMC_GET_RX_DP_CTRL() SMC_inl( ioaddr, RX_DP_CTRL )
  621. #define SMC_SET_RX_DP_CTRL(x) SMC_outl( x, ioaddr, RX_DP_CTRL )
  622. #define SMC_GET_PMT_CTRL() SMC_inl( ioaddr, PMT_CTRL )
  623. #define SMC_SET_PMT_CTRL(x) SMC_outl( x, ioaddr, PMT_CTRL )
  624. #define SMC_GET_GPIO_CFG() SMC_inl( ioaddr, GPIO_CFG )
  625. #define SMC_SET_GPIO_CFG(x) SMC_outl( x, ioaddr, GPIO_CFG )
  626. #define SMC_GET_RX_FIFO_INF() SMC_inl( ioaddr, RX_FIFO_INF )
  627. #define SMC_SET_RX_FIFO_INF(x) SMC_outl( x, ioaddr, RX_FIFO_INF )
  628. #define SMC_GET_TX_FIFO_INF() SMC_inl( ioaddr, TX_FIFO_INF )
  629. #define SMC_SET_TX_FIFO_INF(x) SMC_outl( x, ioaddr, TX_FIFO_INF )
  630. #define SMC_GET_GPT_CFG() SMC_inl( ioaddr, GPT_CFG )
  631. #define SMC_SET_GPT_CFG(x) SMC_outl( x, ioaddr, GPT_CFG )
  632. #define SMC_GET_RX_DROP() SMC_inl( ioaddr, RX_DROP )
  633. #define SMC_SET_RX_DROP(x) SMC_outl( x, ioaddr, RX_DROP )
  634. #define SMC_GET_MAC_CMD() SMC_inl( ioaddr, MAC_CSR_CMD )
  635. #define SMC_SET_MAC_CMD(x) SMC_outl( x, ioaddr, MAC_CSR_CMD )
  636. #define SMC_GET_MAC_DATA() SMC_inl( ioaddr, MAC_CSR_DATA )
  637. #define SMC_SET_MAC_DATA(x) SMC_outl( x, ioaddr, MAC_CSR_DATA )
  638. #define SMC_GET_AFC_CFG() SMC_inl( ioaddr, AFC_CFG )
  639. #define SMC_SET_AFC_CFG(x) SMC_outl( x, ioaddr, AFC_CFG )
  640. #define SMC_GET_E2P_CMD() SMC_inl( ioaddr, E2P_CMD )
  641. #define SMC_SET_E2P_CMD(x) SMC_outl( x, ioaddr, E2P_CMD )
  642. #define SMC_GET_E2P_DATA() SMC_inl( ioaddr, E2P_DATA )
  643. #define SMC_SET_E2P_DATA(x) SMC_outl( x, ioaddr, E2P_DATA )
  644. /* MAC register read/write macros */
  645. #define SMC_GET_MAC_CSR(a,v) \
  646. do { \
  647. while (SMC_GET_MAC_CMD() & MAC_CSR_CMD_CSR_BUSY_); \
  648. SMC_SET_MAC_CMD(MAC_CSR_CMD_CSR_BUSY_ | \
  649. MAC_CSR_CMD_R_NOT_W_ | (a) ); \
  650. while (SMC_GET_MAC_CMD() & MAC_CSR_CMD_CSR_BUSY_); \
  651. v = SMC_GET_MAC_DATA(); \
  652. } while (0)
  653. #define SMC_SET_MAC_CSR(a,v) \
  654. do { \
  655. while (SMC_GET_MAC_CMD() & MAC_CSR_CMD_CSR_BUSY_); \
  656. SMC_SET_MAC_DATA(v); \
  657. SMC_SET_MAC_CMD(MAC_CSR_CMD_CSR_BUSY_ | (a) ); \
  658. while (SMC_GET_MAC_CMD() & MAC_CSR_CMD_CSR_BUSY_); \
  659. } while (0)
  660. #define SMC_GET_MAC_CR(x) SMC_GET_MAC_CSR( MAC_CR, x )
  661. #define SMC_SET_MAC_CR(x) SMC_SET_MAC_CSR( MAC_CR, x )
  662. #define SMC_GET_ADDRH(x) SMC_GET_MAC_CSR( ADDRH, x )
  663. #define SMC_SET_ADDRH(x) SMC_SET_MAC_CSR( ADDRH, x )
  664. #define SMC_GET_ADDRL(x) SMC_GET_MAC_CSR( ADDRL, x )
  665. #define SMC_SET_ADDRL(x) SMC_SET_MAC_CSR( ADDRL, x )
  666. #define SMC_GET_HASHH(x) SMC_GET_MAC_CSR( HASHH, x )
  667. #define SMC_SET_HASHH(x) SMC_SET_MAC_CSR( HASHH, x )
  668. #define SMC_GET_HASHL(x) SMC_GET_MAC_CSR( HASHL, x )
  669. #define SMC_SET_HASHL(x) SMC_SET_MAC_CSR( HASHL, x )
  670. #define SMC_GET_MII_ACC(x) SMC_GET_MAC_CSR( MII_ACC, x )
  671. #define SMC_SET_MII_ACC(x) SMC_SET_MAC_CSR( MII_ACC, x )
  672. #define SMC_GET_MII_DATA(x) SMC_GET_MAC_CSR( MII_DATA, x )
  673. #define SMC_SET_MII_DATA(x) SMC_SET_MAC_CSR( MII_DATA, x )
  674. #define SMC_GET_FLOW(x) SMC_GET_MAC_CSR( FLOW, x )
  675. #define SMC_SET_FLOW(x) SMC_SET_MAC_CSR( FLOW, x )
  676. #define SMC_GET_VLAN1(x) SMC_GET_MAC_CSR( VLAN1, x )
  677. #define SMC_SET_VLAN1(x) SMC_SET_MAC_CSR( VLAN1, x )
  678. #define SMC_GET_VLAN2(x) SMC_GET_MAC_CSR( VLAN2, x )
  679. #define SMC_SET_VLAN2(x) SMC_SET_MAC_CSR( VLAN2, x )
  680. #define SMC_SET_WUFF(x) SMC_SET_MAC_CSR( WUFF, x )
  681. #define SMC_GET_WUCSR(x) SMC_GET_MAC_CSR( WUCSR, x )
  682. #define SMC_SET_WUCSR(x) SMC_SET_MAC_CSR( WUCSR, x )
  683. /* PHY register read/write macros */
  684. #define SMC_GET_MII(a,phy,v) \
  685. do { \
  686. u32 __v; \
  687. do { \
  688. SMC_GET_MII_ACC(__v); \
  689. } while ( __v & MII_ACC_MII_BUSY_ ); \
  690. SMC_SET_MII_ACC( ((phy)<<11) | ((a)<<6) | \
  691. MII_ACC_MII_BUSY_); \
  692. do { \
  693. SMC_GET_MII_ACC(__v); \
  694. } while ( __v & MII_ACC_MII_BUSY_ ); \
  695. SMC_GET_MII_DATA(v); \
  696. } while (0)
  697. #define SMC_SET_MII(a,phy,v) \
  698. do { \
  699. u32 __v; \
  700. do { \
  701. SMC_GET_MII_ACC(__v); \
  702. } while ( __v & MII_ACC_MII_BUSY_ ); \
  703. SMC_SET_MII_DATA(v); \
  704. SMC_SET_MII_ACC( ((phy)<<11) | ((a)<<6) | \
  705. MII_ACC_MII_BUSY_ | \
  706. MII_ACC_MII_WRITE_ ); \
  707. do { \
  708. SMC_GET_MII_ACC(__v); \
  709. } while ( __v & MII_ACC_MII_BUSY_ ); \
  710. } while (0)
  711. #define SMC_GET_PHY_BMCR(phy,x) SMC_GET_MII( MII_BMCR, phy, x )
  712. #define SMC_SET_PHY_BMCR(phy,x) SMC_SET_MII( MII_BMCR, phy, x )
  713. #define SMC_GET_PHY_BMSR(phy,x) SMC_GET_MII( MII_BMSR, phy, x )
  714. #define SMC_GET_PHY_ID1(phy,x) SMC_GET_MII( MII_PHYSID1, phy, x )
  715. #define SMC_GET_PHY_ID2(phy,x) SMC_GET_MII( MII_PHYSID2, phy, x )
  716. #define SMC_GET_PHY_MII_ADV(phy,x) SMC_GET_MII( MII_ADVERTISE, phy, x )
  717. #define SMC_SET_PHY_MII_ADV(phy,x) SMC_SET_MII( MII_ADVERTISE, phy, x )
  718. #define SMC_GET_PHY_MII_LPA(phy,x) SMC_GET_MII( MII_LPA, phy, x )
  719. #define SMC_SET_PHY_MII_LPA(phy,x) SMC_SET_MII( MII_LPA, phy, x )
  720. #define SMC_GET_PHY_CTRL_STS(phy,x) SMC_GET_MII( PHY_MODE_CTRL_STS, phy, x )
  721. #define SMC_SET_PHY_CTRL_STS(phy,x) SMC_SET_MII( PHY_MODE_CTRL_STS, phy, x )
  722. #define SMC_GET_PHY_INT_SRC(phy,x) SMC_GET_MII( PHY_INT_SRC, phy, x )
  723. #define SMC_SET_PHY_INT_SRC(phy,x) SMC_SET_MII( PHY_INT_SRC, phy, x )
  724. #define SMC_GET_PHY_INT_MASK(phy,x) SMC_GET_MII( PHY_INT_MASK, phy, x )
  725. #define SMC_SET_PHY_INT_MASK(phy,x) SMC_SET_MII( PHY_INT_MASK, phy, x )
  726. #define SMC_GET_PHY_SPECIAL(phy,x) SMC_GET_MII( PHY_SPECIAL, phy, x )
  727. /* Misc read/write macros */
  728. #ifndef SMC_GET_MAC_ADDR
  729. #define SMC_GET_MAC_ADDR(addr) \
  730. do { \
  731. unsigned int __v; \
  732. \
  733. SMC_GET_MAC_CSR(ADDRL, __v); \
  734. addr[0] = __v; addr[1] = __v >> 8; \
  735. addr[2] = __v >> 16; addr[3] = __v >> 24; \
  736. SMC_GET_MAC_CSR(ADDRH, __v); \
  737. addr[4] = __v; addr[5] = __v >> 8; \
  738. } while (0)
  739. #endif
  740. #define SMC_SET_MAC_ADDR(addr) \
  741. do { \
  742. SMC_SET_MAC_CSR(ADDRL, \
  743. addr[0] | \
  744. (addr[1] << 8) | \
  745. (addr[2] << 16) | \
  746. (addr[3] << 24)); \
  747. SMC_SET_MAC_CSR(ADDRH, addr[4]|(addr[5] << 8));\
  748. } while (0)
  749. #define SMC_WRITE_EEPROM_CMD(cmd, addr) \
  750. do { \
  751. while (SMC_GET_E2P_CMD() & MAC_CSR_CMD_CSR_BUSY_); \
  752. SMC_SET_MAC_CMD(MAC_CSR_CMD_R_NOT_W_ | a ); \
  753. while (SMC_GET_MAC_CMD() & MAC_CSR_CMD_CSR_BUSY_); \
  754. } while (0)
  755. #endif /* _SMC911X_H_ */