encx24j600_hw.h 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438
  1. /**
  2. * encx24j600_hw.h: Register definitions
  3. *
  4. */
  5. #ifndef _ENCX24J600_HW_H
  6. #define _ENCX24J600_HW_H
  7. struct encx24j600_context {
  8. struct spi_device *spi;
  9. struct regmap *regmap;
  10. struct regmap *phymap;
  11. struct mutex mutex; /* mutex to protect access to regmap */
  12. int bank;
  13. };
  14. void devm_regmap_init_encx24j600(struct device *dev,
  15. struct encx24j600_context *ctx);
  16. /* Single-byte instructions */
  17. #define BANK_SELECT(bank) (0xC0 | ((bank & (BANK_MASK >> BANK_SHIFT)) << 1))
  18. #define B0SEL 0xC0 /* Bank 0 Select */
  19. #define B1SEL 0xC2 /* Bank 1 Select */
  20. #define B2SEL 0xC4 /* Bank 2 Select */
  21. #define B3SEL 0xC6 /* Bank 3 Select */
  22. #define SETETHRST 0xCA /* System Reset */
  23. #define FCDISABLE 0xE0 /* Flow Control Disable */
  24. #define FCSINGLE 0xE2 /* Flow Control Single */
  25. #define FCMULTIPLE 0xE4 /* Flow Control Multiple */
  26. #define FCCLEAR 0xE6 /* Flow Control Clear */
  27. #define SETPKTDEC 0xCC /* Decrement Packet Counter */
  28. #define DMASTOP 0xD2 /* DMA Stop */
  29. #define DMACKSUM 0xD8 /* DMA Start Checksum */
  30. #define DMACKSUMS 0xDA /* DMA Start Checksum with Seed */
  31. #define DMACOPY 0xDC /* DMA Start Copy */
  32. #define DMACOPYS 0xDE /* DMA Start Copy and Checksum with Seed */
  33. #define SETTXRTS 0xD4 /* Request Packet Transmission */
  34. #define ENABLERX 0xE8 /* Enable RX */
  35. #define DISABLERX 0xEA /* Disable RX */
  36. #define SETEIE 0xEC /* Enable Interrupts */
  37. #define CLREIE 0xEE /* Disable Interrupts */
  38. /* Two byte instructions */
  39. #define RBSEL 0xC8 /* Read Bank Select */
  40. /* Three byte instructions */
  41. #define WGPRDPT 0x60 /* Write EGPRDPT */
  42. #define RGPRDPT 0x62 /* Read EGPRDPT */
  43. #define WRXRDPT 0x64 /* Write ERXRDPT */
  44. #define RRXRDPT 0x66 /* Read ERXRDPT */
  45. #define WUDARDPT 0x68 /* Write EUDARDPT */
  46. #define RUDARDPT 0x6A /* Read EUDARDPT */
  47. #define WGPWRPT 0x6C /* Write EGPWRPT */
  48. #define RGPWRPT 0x6E /* Read EGPWRPT */
  49. #define WRXWRPT 0x70 /* Write ERXWRPT */
  50. #define RRXWRPT 0x72 /* Read ERXWRPT */
  51. #define WUDAWRPT 0x74 /* Write EUDAWRPT */
  52. #define RUDAWRPT 0x76 /* Read EUDAWRPT */
  53. /* n byte instructions */
  54. #define RCRCODE 0x00
  55. #define WCRCODE 0x40
  56. #define BFSCODE 0x80
  57. #define BFCCODE 0xA0
  58. #define RCR(addr) (RCRCODE | (addr & ADDR_MASK)) /* Read Control Register */
  59. #define WCR(addr) (WCRCODE | (addr & ADDR_MASK)) /* Write Control Register */
  60. #define RCRU 0x20 /* Read Control Register Unbanked */
  61. #define WCRU 0x22 /* Write Control Register Unbanked */
  62. #define BFS(addr) (BFSCODE | (addr & ADDR_MASK)) /* Bit Field Set */
  63. #define BFC(addr) (BFCCODE | (addr & ADDR_MASK)) /* Bit Field Clear */
  64. #define BFSU 0x24 /* Bit Field Set Unbanked */
  65. #define BFCU 0x26 /* Bit Field Clear Unbanked */
  66. #define RGPDATA 0x28 /* Read EGPDATA */
  67. #define WGPDATA 0x2A /* Write EGPDATA */
  68. #define RRXDATA 0x2C /* Read ERXDATA */
  69. #define WRXDATA 0x2E /* Write ERXDATA */
  70. #define RUDADATA 0x30 /* Read EUDADATA */
  71. #define WUDADATA 0x32 /* Write EUDADATA */
  72. #define SFR_REG_COUNT 0xA0
  73. /* ENC424J600 Control Registers
  74. * Control register definitions are a combination of address
  75. * and bank number
  76. * - Register address (bits 0-4)
  77. * - Bank number (bits 5-6)
  78. */
  79. #define ADDR_MASK 0x1F
  80. #define BANK_MASK 0x60
  81. #define BANK_SHIFT 5
  82. /* All-bank registers */
  83. #define EUDAST 0x16
  84. #define EUDAND 0x18
  85. #define ESTAT 0x1A
  86. #define EIR 0x1C
  87. #define ECON1 0x1E
  88. /* Bank 0 registers */
  89. #define ETXST (0x00 | 0x00)
  90. #define ETXLEN (0x02 | 0x00)
  91. #define ERXST (0x04 | 0x00)
  92. #define ERXTAIL (0x06 | 0x00)
  93. #define ERXHEAD (0x08 | 0x00)
  94. #define EDMAST (0x0A | 0x00)
  95. #define EDMALEN (0x0C | 0x00)
  96. #define EDMADST (0x0E | 0x00)
  97. #define EDMACS (0x10 | 0x00)
  98. #define ETXSTAT (0x12 | 0x00)
  99. #define ETXWIRE (0x14 | 0x00)
  100. /* Bank 1 registers */
  101. #define EHT1 (0x00 | 0x20)
  102. #define EHT2 (0x02 | 0x20)
  103. #define EHT3 (0x04 | 0x20)
  104. #define EHT4 (0x06 | 0x20)
  105. #define EPMM1 (0x08 | 0x20)
  106. #define EPMM2 (0x0A | 0x20)
  107. #define EPMM3 (0x0C | 0x20)
  108. #define EPMM4 (0x0E | 0x20)
  109. #define EPMCS (0x10 | 0x20)
  110. #define EPMO (0x12 | 0x20)
  111. #define ERXFCON (0x14 | 0x20)
  112. /* Bank 2 registers */
  113. #define MACON1 (0x00 | 0x40)
  114. #define MACON2 (0x02 | 0x40)
  115. #define MABBIPG (0x04 | 0x40)
  116. #define MAIPG (0x06 | 0x40)
  117. #define MACLCON (0x08 | 0x40)
  118. #define MAMXFL (0x0A | 0x40)
  119. #define MICMD (0x12 | 0x40)
  120. #define MIREGADR (0x14 | 0x40)
  121. /* Bank 3 registers */
  122. #define MAADR3 (0x00 | 0x60)
  123. #define MAADR2 (0x02 | 0x60)
  124. #define MAADR1 (0x04 | 0x60)
  125. #define MIWR (0x06 | 0x60)
  126. #define MIRD (0x08 | 0x60)
  127. #define MISTAT (0x0A | 0x60)
  128. #define EPAUS (0x0C | 0x60)
  129. #define ECON2 (0x0E | 0x60)
  130. #define ERXWM (0x10 | 0x60)
  131. #define EIE (0x12 | 0x60)
  132. #define EIDLED (0x14 | 0x60)
  133. /* Unbanked registers */
  134. #define EGPDATA (0x00 | 0x80)
  135. #define ERXDATA (0x02 | 0x80)
  136. #define EUDADATA (0x04 | 0x80)
  137. #define EGPRDPT (0x06 | 0x80)
  138. #define EGPWRPT (0x08 | 0x80)
  139. #define ERXRDPT (0x0A | 0x80)
  140. #define ERXWRPT (0x0C | 0x80)
  141. #define EUDARDPT (0x0E | 0x80)
  142. #define EUDAWRPT (0x10 | 0x80)
  143. /* Register bit definitions */
  144. /* ESTAT */
  145. #define INT (1 << 15)
  146. #define FCIDLE (1 << 14)
  147. #define RXBUSY (1 << 13)
  148. #define CLKRDY (1 << 12)
  149. #define PHYDPX (1 << 10)
  150. #define PHYLNK (1 << 8)
  151. /* EIR */
  152. #define CRYPTEN (1 << 15)
  153. #define MODEXIF (1 << 14)
  154. #define HASHIF (1 << 13)
  155. #define AESIF (1 << 12)
  156. #define LINKIF (1 << 11)
  157. #define PKTIF (1 << 6)
  158. #define DMAIF (1 << 5)
  159. #define TXIF (1 << 3)
  160. #define TXABTIF (1 << 2)
  161. #define RXABTIF (1 << 1)
  162. #define PCFULIF (1 << 0)
  163. /* ECON1 */
  164. #define MODEXST (1 << 15)
  165. #define HASHEN (1 << 14)
  166. #define HASHOP (1 << 13)
  167. #define HASHLST (1 << 12)
  168. #define AESST (1 << 11)
  169. #define AESOP1 (1 << 10)
  170. #define AESOP0 (1 << 9)
  171. #define PKTDEC (1 << 8)
  172. #define FCOP1 (1 << 7)
  173. #define FCOP0 (1 << 6)
  174. #define DMAST (1 << 5)
  175. #define DMACPY (1 << 4)
  176. #define DMACSSD (1 << 3)
  177. #define DMANOCS (1 << 2)
  178. #define TXRTS (1 << 1)
  179. #define RXEN (1 << 0)
  180. /* ETXSTAT */
  181. #define LATECOL (1 << 10)
  182. #define MAXCOL (1 << 9)
  183. #define EXDEFER (1 << 8)
  184. #define ETXSTATL_DEFER (1 << 7)
  185. #define CRCBAD (1 << 4)
  186. #define COLCNT_MASK 0xF
  187. /* ERXFCON */
  188. #define HTEN (1 << 15)
  189. #define MPEN (1 << 14)
  190. #define NOTPM (1 << 12)
  191. #define PMEN3 (1 << 11)
  192. #define PMEN2 (1 << 10)
  193. #define PMEN1 (1 << 9)
  194. #define PMEN0 (1 << 8)
  195. #define CRCEEN (1 << 7)
  196. #define CRCEN (1 << 6)
  197. #define RUNTEEN (1 << 5)
  198. #define RUNTEN (1 << 4)
  199. #define UCEN (1 << 3)
  200. #define NOTMEEN (1 << 2)
  201. #define MCEN (1 << 1)
  202. #define BCEN (1 << 0)
  203. /* MACON1 */
  204. #define LOOPBK (1 << 4)
  205. #define RXPAUS (1 << 2)
  206. #define PASSALL (1 << 1)
  207. /* MACON2 */
  208. #define MACON2_DEFER (1 << 14)
  209. #define BPEN (1 << 13)
  210. #define NOBKOFF (1 << 12)
  211. #define PADCFG2 (1 << 7)
  212. #define PADCFG1 (1 << 6)
  213. #define PADCFG0 (1 << 5)
  214. #define TXCRCEN (1 << 4)
  215. #define PHDREN (1 << 3)
  216. #define HFRMEN (1 << 2)
  217. #define MACON2_RSV1 (1 << 1)
  218. #define FULDPX (1 << 0)
  219. /* MAIPG */
  220. /* value of the high byte is given by the reserved bits,
  221. * value of the low byte is recomended setting of the
  222. * IPG parameter.
  223. */
  224. #define MAIPGH_VAL 0x0C
  225. #define MAIPGL_VAL 0x12
  226. /* MIREGADRH */
  227. #define MIREGADR_VAL (1 << 8)
  228. /* MIREGADRL */
  229. #define PHREG_MASK 0x1F
  230. /* MICMD */
  231. #define MIISCAN (1 << 1)
  232. #define MIIRD (1 << 0)
  233. /* MISTAT */
  234. #define NVALID (1 << 2)
  235. #define SCAN (1 << 1)
  236. #define BUSY (1 << 0)
  237. /* ECON2 */
  238. #define ETHEN (1 << 15)
  239. #define STRCH (1 << 14)
  240. #define TXMAC (1 << 13)
  241. #define SHA1MD5 (1 << 12)
  242. #define COCON3 (1 << 11)
  243. #define COCON2 (1 << 10)
  244. #define COCON1 (1 << 9)
  245. #define COCON0 (1 << 8)
  246. #define AUTOFC (1 << 7)
  247. #define TXRST (1 << 6)
  248. #define RXRST (1 << 5)
  249. #define ETHRST (1 << 4)
  250. #define MODLEN1 (1 << 3)
  251. #define MODLEN0 (1 << 2)
  252. #define AESLEN1 (1 << 1)
  253. #define AESLEN0 (1 << 0)
  254. /* EIE */
  255. #define INTIE (1 << 15)
  256. #define MODEXIE (1 << 14)
  257. #define HASHIE (1 << 13)
  258. #define AESIE (1 << 12)
  259. #define LINKIE (1 << 11)
  260. #define PKTIE (1 << 6)
  261. #define DMAIE (1 << 5)
  262. #define TXIE (1 << 3)
  263. #define TXABTIE (1 << 2)
  264. #define RXABTIE (1 << 1)
  265. #define PCFULIE (1 << 0)
  266. /* EIDLED */
  267. #define LACFG3 (1 << 15)
  268. #define LACFG2 (1 << 14)
  269. #define LACFG1 (1 << 13)
  270. #define LACFG0 (1 << 12)
  271. #define LBCFG3 (1 << 11)
  272. #define LBCFG2 (1 << 10)
  273. #define LBCFG1 (1 << 9)
  274. #define LBCFG0 (1 << 8)
  275. #define DEVID_SHIFT 5
  276. #define DEVID_MASK (0x7 << DEVID_SHIFT)
  277. #define REVID_SHIFT 0
  278. #define REVID_MASK (0x1F << REVID_SHIFT)
  279. /* PHY registers */
  280. #define PHCON1 0x00
  281. #define PHSTAT1 0x01
  282. #define PHANA 0x04
  283. #define PHANLPA 0x05
  284. #define PHANE 0x06
  285. #define PHCON2 0x11
  286. #define PHSTAT2 0x1B
  287. #define PHSTAT3 0x1F
  288. /* PHCON1 */
  289. #define PRST (1 << 15)
  290. #define PLOOPBK (1 << 14)
  291. #define SPD100 (1 << 13)
  292. #define ANEN (1 << 12)
  293. #define PSLEEP (1 << 11)
  294. #define RENEG (1 << 9)
  295. #define PFULDPX (1 << 8)
  296. /* PHSTAT1 */
  297. #define FULL100 (1 << 14)
  298. #define HALF100 (1 << 13)
  299. #define FULL10 (1 << 12)
  300. #define HALF10 (1 << 11)
  301. #define ANDONE (1 << 5)
  302. #define LRFAULT (1 << 4)
  303. #define ANABLE (1 << 3)
  304. #define LLSTAT (1 << 2)
  305. #define EXTREGS (1 << 0)
  306. /* PHSTAT2 */
  307. #define PLRITY (1 << 4)
  308. /* PHSTAT3 */
  309. #define PHY3SPD100 (1 << 3)
  310. #define PHY3DPX (1 << 4)
  311. #define SPDDPX_SHIFT 2
  312. #define SPDDPX_MASK (0x7 << SPDDPX_SHIFT)
  313. /* PHANA */
  314. /* Default value for PHY initialization*/
  315. #define PHANA_DEFAULT 0x05E1
  316. /* PHANE */
  317. #define PDFLT (1 << 4)
  318. #define LPARCD (1 << 1)
  319. #define LPANABL (1 << 0)
  320. #define EUDAST_TEST_VAL 0x1234
  321. #define TSV_SIZE 7
  322. #define ENCX24J600_DEV_ID 0x1
  323. /* Configuration */
  324. /* Led is on when the link is present and driven low
  325. * temporarily when packet is TX'd or RX'd
  326. */
  327. #define LED_A_SETTINGS 0xC
  328. /* Led is on if the link is in 100 Mbps mode */
  329. #define LED_B_SETTINGS 0x8
  330. /* maximum ethernet frame length
  331. * Currently not used as a limit anywhere
  332. * (we're using the "huge frame enable" feature of
  333. * enc424j600).
  334. */
  335. #define MAX_FRAMELEN 1518
  336. /* Size in bytes of the receive buffer in enc424j600.
  337. * Must be word aligned (even).
  338. */
  339. #define RX_BUFFER_SIZE (15 * MAX_FRAMELEN)
  340. /* Start of the general purpose area in sram */
  341. #define SRAM_GP_START 0x0
  342. /* SRAM size */
  343. #define SRAM_SIZE 0x6000
  344. /* Start of the receive buffer */
  345. #define ERXST_VAL (SRAM_SIZE - RX_BUFFER_SIZE)
  346. #define RSV_RXLONGEVDROPEV 16
  347. #define RSV_CARRIEREV 18
  348. #define RSV_CRCERROR 20
  349. #define RSV_LENCHECKERR 21
  350. #define RSV_LENOUTOFRANGE 22
  351. #define RSV_RXOK 23
  352. #define RSV_RXMULTICAST 24
  353. #define RSV_RXBROADCAST 25
  354. #define RSV_DRIBBLENIBBLE 26
  355. #define RSV_RXCONTROLFRAME 27
  356. #define RSV_RXPAUSEFRAME 28
  357. #define RSV_RXUNKNOWNOPCODE 29
  358. #define RSV_RXTYPEVLAN 30
  359. #define RSV_RUNTFILTERMATCH 31
  360. #define RSV_NOTMEFILTERMATCH 32
  361. #define RSV_HASHFILTERMATCH 33
  362. #define RSV_MAGICPKTFILTERMATCH 34
  363. #define RSV_PTRNMTCHFILTERMATCH 35
  364. #define RSV_UNICASTFILTERMATCH 36
  365. #define RSV_SIZE 8
  366. #define RSV_BITMASK(x) (1 << ((x) - 16))
  367. #define RSV_GETBIT(x, y) (((x) & RSV_BITMASK(y)) ? 1 : 0)
  368. struct rsv {
  369. u16 next_packet;
  370. u16 len;
  371. u32 rxstat;
  372. };
  373. /* Put RX buffer at 0 as suggested by the Errata datasheet */
  374. #define RXSTART_INIT ERXST_VAL
  375. #define RXEND_INIT 0x5FFF
  376. int regmap_encx24j600_spi_write(void *context, u8 reg, const u8 *data,
  377. size_t count);
  378. int regmap_encx24j600_spi_read(void *context, u8 reg, u8 *data, size_t count);
  379. #endif