encx24j600_hw.h 11 KB

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