mt7530.h 25 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872
  1. /* SPDX-License-Identifier: GPL-2.0-only */
  2. /*
  3. * Copyright (C) 2017 Sean Wang <[email protected]>
  4. */
  5. #ifndef __MT7530_H
  6. #define __MT7530_H
  7. #define MT7530_NUM_PORTS 7
  8. #define MT7530_NUM_PHYS 5
  9. #define MT7530_NUM_FDB_RECORDS 2048
  10. #define MT7530_ALL_MEMBERS 0xff
  11. #define MTK_HDR_LEN 4
  12. #define MT7530_MAX_MTU (15 * 1024 - ETH_HLEN - ETH_FCS_LEN - MTK_HDR_LEN)
  13. enum mt753x_id {
  14. ID_MT7530 = 0,
  15. ID_MT7621 = 1,
  16. ID_MT7531 = 2,
  17. };
  18. #define NUM_TRGMII_CTRL 5
  19. #define TRGMII_BASE(x) (0x10000 + (x))
  20. /* Registers to ethsys access */
  21. #define ETHSYS_CLKCFG0 0x2c
  22. #define ETHSYS_TRGMII_CLK_SEL362_5 BIT(11)
  23. #define SYSC_REG_RSTCTRL 0x34
  24. #define RESET_MCM BIT(2)
  25. /* Registers to mac forward control for unknown frames */
  26. #define MT7530_MFC 0x10
  27. #define BC_FFP(x) (((x) & 0xff) << 24)
  28. #define BC_FFP_MASK BC_FFP(~0)
  29. #define UNM_FFP(x) (((x) & 0xff) << 16)
  30. #define UNM_FFP_MASK UNM_FFP(~0)
  31. #define UNU_FFP(x) (((x) & 0xff) << 8)
  32. #define UNU_FFP_MASK UNU_FFP(~0)
  33. #define CPU_EN BIT(7)
  34. #define CPU_PORT(x) ((x) << 4)
  35. #define CPU_MASK (0xf << 4)
  36. #define MIRROR_EN BIT(3)
  37. #define MIRROR_PORT(x) ((x) & 0x7)
  38. #define MIRROR_MASK 0x7
  39. /* Registers for CPU forward control */
  40. #define MT7531_CFC 0x4
  41. #define MT7531_MIRROR_EN BIT(19)
  42. #define MT7531_MIRROR_MASK (MIRROR_MASK << 16)
  43. #define MT7531_MIRROR_PORT_GET(x) (((x) >> 16) & MIRROR_MASK)
  44. #define MT7531_MIRROR_PORT_SET(x) (((x) & MIRROR_MASK) << 16)
  45. #define MT7531_CPU_PMAP_MASK GENMASK(7, 0)
  46. #define MT753X_MIRROR_REG(id) (((id) == ID_MT7531) ? \
  47. MT7531_CFC : MT7530_MFC)
  48. #define MT753X_MIRROR_EN(id) (((id) == ID_MT7531) ? \
  49. MT7531_MIRROR_EN : MIRROR_EN)
  50. #define MT753X_MIRROR_MASK(id) (((id) == ID_MT7531) ? \
  51. MT7531_MIRROR_MASK : MIRROR_MASK)
  52. /* Registers for BPDU and PAE frame control*/
  53. #define MT753X_BPC 0x24
  54. #define MT753X_BPDU_PORT_FW_MASK GENMASK(2, 0)
  55. #define MT753X_PAE_PORT_FW_MASK GENMASK(18, 16)
  56. #define MT753X_PAE_PORT_FW(x) FIELD_PREP(MT753X_PAE_PORT_FW_MASK, x)
  57. /* Register for :03 and :0E MAC DA frame control */
  58. #define MT753X_RGAC2 0x2c
  59. #define MT753X_R0E_PORT_FW_MASK GENMASK(18, 16)
  60. #define MT753X_R0E_PORT_FW(x) FIELD_PREP(MT753X_R0E_PORT_FW_MASK, x)
  61. enum mt753x_bpdu_port_fw {
  62. MT753X_BPDU_FOLLOW_MFC,
  63. MT753X_BPDU_CPU_EXCLUDE = 4,
  64. MT753X_BPDU_CPU_INCLUDE = 5,
  65. MT753X_BPDU_CPU_ONLY = 6,
  66. MT753X_BPDU_DROP = 7,
  67. };
  68. /* Registers for address table access */
  69. #define MT7530_ATA1 0x74
  70. #define STATIC_EMP 0
  71. #define STATIC_ENT 3
  72. #define MT7530_ATA2 0x78
  73. #define ATA2_IVL BIT(15)
  74. #define ATA2_FID(x) (((x) & 0x7) << 12)
  75. /* Register for address table write data */
  76. #define MT7530_ATWD 0x7c
  77. /* Register for address table control */
  78. #define MT7530_ATC 0x80
  79. #define ATC_HASH (((x) & 0xfff) << 16)
  80. #define ATC_BUSY BIT(15)
  81. #define ATC_SRCH_END BIT(14)
  82. #define ATC_SRCH_HIT BIT(13)
  83. #define ATC_INVALID BIT(12)
  84. #define ATC_MAT(x) (((x) & 0xf) << 8)
  85. #define ATC_MAT_MACTAB ATC_MAT(0)
  86. enum mt7530_fdb_cmd {
  87. MT7530_FDB_READ = 0,
  88. MT7530_FDB_WRITE = 1,
  89. MT7530_FDB_FLUSH = 2,
  90. MT7530_FDB_START = 4,
  91. MT7530_FDB_NEXT = 5,
  92. };
  93. /* Registers for table search read address */
  94. #define MT7530_TSRA1 0x84
  95. #define MAC_BYTE_0 24
  96. #define MAC_BYTE_1 16
  97. #define MAC_BYTE_2 8
  98. #define MAC_BYTE_3 0
  99. #define MAC_BYTE_MASK 0xff
  100. #define MT7530_TSRA2 0x88
  101. #define MAC_BYTE_4 24
  102. #define MAC_BYTE_5 16
  103. #define CVID 0
  104. #define CVID_MASK 0xfff
  105. #define MT7530_ATRD 0x8C
  106. #define AGE_TIMER 24
  107. #define AGE_TIMER_MASK 0xff
  108. #define PORT_MAP 4
  109. #define PORT_MAP_MASK 0xff
  110. #define ENT_STATUS 2
  111. #define ENT_STATUS_MASK 0x3
  112. /* Register for vlan table control */
  113. #define MT7530_VTCR 0x90
  114. #define VTCR_BUSY BIT(31)
  115. #define VTCR_INVALID BIT(16)
  116. #define VTCR_FUNC(x) (((x) & 0xf) << 12)
  117. #define VTCR_VID ((x) & 0xfff)
  118. enum mt7530_vlan_cmd {
  119. /* Read/Write the specified VID entry from VAWD register based
  120. * on VID.
  121. */
  122. MT7530_VTCR_RD_VID = 0,
  123. MT7530_VTCR_WR_VID = 1,
  124. };
  125. /* Register for setup vlan and acl write data */
  126. #define MT7530_VAWD1 0x94
  127. #define PORT_STAG BIT(31)
  128. /* Independent VLAN Learning */
  129. #define IVL_MAC BIT(30)
  130. /* Egress Tag Consistent */
  131. #define EG_CON BIT(29)
  132. /* Per VLAN Egress Tag Control */
  133. #define VTAG_EN BIT(28)
  134. /* VLAN Member Control */
  135. #define PORT_MEM(x) (((x) & 0xff) << 16)
  136. /* Filter ID */
  137. #define FID(x) (((x) & 0x7) << 1)
  138. /* VLAN Entry Valid */
  139. #define VLAN_VALID BIT(0)
  140. #define PORT_MEM_SHFT 16
  141. #define PORT_MEM_MASK 0xff
  142. enum mt7530_fid {
  143. FID_STANDALONE = 0,
  144. FID_BRIDGED = 1,
  145. };
  146. #define MT7530_VAWD2 0x98
  147. /* Egress Tag Control */
  148. #define ETAG_CTRL_P(p, x) (((x) & 0x3) << ((p) << 1))
  149. #define ETAG_CTRL_P_MASK(p) ETAG_CTRL_P(p, 3)
  150. enum mt7530_vlan_egress_attr {
  151. MT7530_VLAN_EGRESS_UNTAG = 0,
  152. MT7530_VLAN_EGRESS_TAG = 2,
  153. MT7530_VLAN_EGRESS_STACK = 3,
  154. };
  155. /* Register for address age control */
  156. #define MT7530_AAC 0xa0
  157. /* Disable ageing */
  158. #define AGE_DIS BIT(20)
  159. /* Age count */
  160. #define AGE_CNT_MASK GENMASK(19, 12)
  161. #define AGE_CNT_MAX 0xff
  162. #define AGE_CNT(x) (AGE_CNT_MASK & ((x) << 12))
  163. /* Age unit */
  164. #define AGE_UNIT_MASK GENMASK(11, 0)
  165. #define AGE_UNIT_MAX 0xfff
  166. #define AGE_UNIT(x) (AGE_UNIT_MASK & (x))
  167. /* Register for port STP state control */
  168. #define MT7530_SSP_P(x) (0x2000 + ((x) * 0x100))
  169. #define FID_PST(fid, state) (((state) & 0x3) << ((fid) * 2))
  170. #define FID_PST_MASK(fid) FID_PST(fid, 0x3)
  171. enum mt7530_stp_state {
  172. MT7530_STP_DISABLED = 0,
  173. MT7530_STP_BLOCKING = 1,
  174. MT7530_STP_LISTENING = 1,
  175. MT7530_STP_LEARNING = 2,
  176. MT7530_STP_FORWARDING = 3
  177. };
  178. /* Register for port control */
  179. #define MT7530_PCR_P(x) (0x2004 + ((x) * 0x100))
  180. #define PORT_TX_MIR BIT(9)
  181. #define PORT_RX_MIR BIT(8)
  182. #define PORT_VLAN(x) ((x) & 0x3)
  183. enum mt7530_port_mode {
  184. /* Port Matrix Mode: Frames are forwarded by the PCR_MATRIX members. */
  185. MT7530_PORT_MATRIX_MODE = PORT_VLAN(0),
  186. /* Fallback Mode: Forward received frames with ingress ports that do
  187. * not belong to the VLAN member. Frames whose VID is not listed on
  188. * the VLAN table are forwarded by the PCR_MATRIX members.
  189. */
  190. MT7530_PORT_FALLBACK_MODE = PORT_VLAN(1),
  191. /* Security Mode: Discard any frame due to ingress membership
  192. * violation or VID missed on the VLAN table.
  193. */
  194. MT7530_PORT_SECURITY_MODE = PORT_VLAN(3),
  195. };
  196. #define PCR_MATRIX(x) (((x) & 0xff) << 16)
  197. #define PORT_PRI(x) (((x) & 0x7) << 24)
  198. #define EG_TAG(x) (((x) & 0x3) << 28)
  199. #define PCR_MATRIX_MASK PCR_MATRIX(0xff)
  200. #define PCR_MATRIX_CLR PCR_MATRIX(0)
  201. #define PCR_PORT_VLAN_MASK PORT_VLAN(3)
  202. /* Register for port security control */
  203. #define MT7530_PSC_P(x) (0x200c + ((x) * 0x100))
  204. #define SA_DIS BIT(4)
  205. /* Register for port vlan control */
  206. #define MT7530_PVC_P(x) (0x2010 + ((x) * 0x100))
  207. #define PORT_SPEC_TAG BIT(5)
  208. #define PVC_EG_TAG(x) (((x) & 0x7) << 8)
  209. #define PVC_EG_TAG_MASK PVC_EG_TAG(7)
  210. #define VLAN_ATTR(x) (((x) & 0x3) << 6)
  211. #define VLAN_ATTR_MASK VLAN_ATTR(3)
  212. #define ACC_FRM_MASK GENMASK(1, 0)
  213. enum mt7530_vlan_port_eg_tag {
  214. MT7530_VLAN_EG_DISABLED = 0,
  215. MT7530_VLAN_EG_CONSISTENT = 1,
  216. };
  217. enum mt7530_vlan_port_attr {
  218. MT7530_VLAN_USER = 0,
  219. MT7530_VLAN_TRANSPARENT = 3,
  220. };
  221. enum mt7530_vlan_port_acc_frm {
  222. MT7530_VLAN_ACC_ALL = 0,
  223. MT7530_VLAN_ACC_TAGGED = 1,
  224. MT7530_VLAN_ACC_UNTAGGED = 2,
  225. };
  226. #define STAG_VPID (((x) & 0xffff) << 16)
  227. /* Register for port port-and-protocol based vlan 1 control */
  228. #define MT7530_PPBV1_P(x) (0x2014 + ((x) * 0x100))
  229. #define G0_PORT_VID(x) (((x) & 0xfff) << 0)
  230. #define G0_PORT_VID_MASK G0_PORT_VID(0xfff)
  231. #define G0_PORT_VID_DEF G0_PORT_VID(0)
  232. /* Register for port MAC control register */
  233. #define MT7530_PMCR_P(x) (0x3000 + ((x) * 0x100))
  234. #define PMCR_IFG_XMIT(x) (((x) & 0x3) << 18)
  235. #define PMCR_EXT_PHY BIT(17)
  236. #define PMCR_MAC_MODE BIT(16)
  237. #define PMCR_FORCE_MODE BIT(15)
  238. #define PMCR_TX_EN BIT(14)
  239. #define PMCR_RX_EN BIT(13)
  240. #define PMCR_BACKOFF_EN BIT(9)
  241. #define PMCR_BACKPR_EN BIT(8)
  242. #define PMCR_FORCE_EEE1G BIT(7)
  243. #define PMCR_FORCE_EEE100 BIT(6)
  244. #define PMCR_TX_FC_EN BIT(5)
  245. #define PMCR_RX_FC_EN BIT(4)
  246. #define PMCR_FORCE_SPEED_1000 BIT(3)
  247. #define PMCR_FORCE_SPEED_100 BIT(2)
  248. #define PMCR_FORCE_FDX BIT(1)
  249. #define PMCR_FORCE_LNK BIT(0)
  250. #define PMCR_SPEED_MASK (PMCR_FORCE_SPEED_100 | \
  251. PMCR_FORCE_SPEED_1000)
  252. #define MT7531_FORCE_LNK BIT(31)
  253. #define MT7531_FORCE_SPD BIT(30)
  254. #define MT7531_FORCE_DPX BIT(29)
  255. #define MT7531_FORCE_RX_FC BIT(28)
  256. #define MT7531_FORCE_TX_FC BIT(27)
  257. #define MT7531_FORCE_MODE (MT7531_FORCE_LNK | \
  258. MT7531_FORCE_SPD | \
  259. MT7531_FORCE_DPX | \
  260. MT7531_FORCE_RX_FC | \
  261. MT7531_FORCE_TX_FC)
  262. #define PMCR_FORCE_MODE_ID(id) (((id) == ID_MT7531) ? \
  263. MT7531_FORCE_MODE : \
  264. PMCR_FORCE_MODE)
  265. #define PMCR_LINK_SETTINGS_MASK (PMCR_TX_EN | PMCR_FORCE_SPEED_1000 | \
  266. PMCR_RX_EN | PMCR_FORCE_SPEED_100 | \
  267. PMCR_TX_FC_EN | PMCR_RX_FC_EN | \
  268. PMCR_FORCE_FDX | PMCR_FORCE_LNK | \
  269. PMCR_FORCE_EEE1G | PMCR_FORCE_EEE100)
  270. #define PMCR_CPU_PORT_SETTING(id) (PMCR_FORCE_MODE_ID((id)) | \
  271. PMCR_IFG_XMIT(1) | PMCR_MAC_MODE | \
  272. PMCR_BACKOFF_EN | PMCR_BACKPR_EN | \
  273. PMCR_TX_EN | PMCR_RX_EN | \
  274. PMCR_TX_FC_EN | PMCR_RX_FC_EN | \
  275. PMCR_FORCE_SPEED_1000 | \
  276. PMCR_FORCE_FDX | PMCR_FORCE_LNK)
  277. #define MT7530_PMEEECR_P(x) (0x3004 + (x) * 0x100)
  278. #define WAKEUP_TIME_1000(x) (((x) & 0xFF) << 24)
  279. #define WAKEUP_TIME_100(x) (((x) & 0xFF) << 16)
  280. #define LPI_THRESH_MASK GENMASK(15, 4)
  281. #define LPI_THRESH_SHT 4
  282. #define SET_LPI_THRESH(x) (((x) << LPI_THRESH_SHT) & LPI_THRESH_MASK)
  283. #define GET_LPI_THRESH(x) (((x) & LPI_THRESH_MASK) >> LPI_THRESH_SHT)
  284. #define LPI_MODE_EN BIT(0)
  285. #define MT7530_PMSR_P(x) (0x3008 + (x) * 0x100)
  286. #define PMSR_EEE1G BIT(7)
  287. #define PMSR_EEE100M BIT(6)
  288. #define PMSR_RX_FC BIT(5)
  289. #define PMSR_TX_FC BIT(4)
  290. #define PMSR_SPEED_1000 BIT(3)
  291. #define PMSR_SPEED_100 BIT(2)
  292. #define PMSR_SPEED_10 0x00
  293. #define PMSR_SPEED_MASK (PMSR_SPEED_100 | PMSR_SPEED_1000)
  294. #define PMSR_DPX BIT(1)
  295. #define PMSR_LINK BIT(0)
  296. /* Register for port debug count */
  297. #define MT7531_DBG_CNT(x) (0x3018 + (x) * 0x100)
  298. #define MT7531_DIS_CLR BIT(31)
  299. #define MT7530_GMACCR 0x30e0
  300. #define MAX_RX_JUMBO(x) ((x) << 2)
  301. #define MAX_RX_JUMBO_MASK GENMASK(5, 2)
  302. #define MAX_RX_PKT_LEN_MASK GENMASK(1, 0)
  303. #define MAX_RX_PKT_LEN_1522 0x0
  304. #define MAX_RX_PKT_LEN_1536 0x1
  305. #define MAX_RX_PKT_LEN_1552 0x2
  306. #define MAX_RX_PKT_LEN_JUMBO 0x3
  307. /* Register for MIB */
  308. #define MT7530_PORT_MIB_COUNTER(x) (0x4000 + (x) * 0x100)
  309. #define MT7530_MIB_CCR 0x4fe0
  310. #define CCR_MIB_ENABLE BIT(31)
  311. #define CCR_RX_OCT_CNT_GOOD BIT(7)
  312. #define CCR_RX_OCT_CNT_BAD BIT(6)
  313. #define CCR_TX_OCT_CNT_GOOD BIT(5)
  314. #define CCR_TX_OCT_CNT_BAD BIT(4)
  315. #define CCR_MIB_FLUSH (CCR_RX_OCT_CNT_GOOD | \
  316. CCR_RX_OCT_CNT_BAD | \
  317. CCR_TX_OCT_CNT_GOOD | \
  318. CCR_TX_OCT_CNT_BAD)
  319. #define CCR_MIB_ACTIVATE (CCR_MIB_ENABLE | \
  320. CCR_RX_OCT_CNT_GOOD | \
  321. CCR_RX_OCT_CNT_BAD | \
  322. CCR_TX_OCT_CNT_GOOD | \
  323. CCR_TX_OCT_CNT_BAD)
  324. /* MT7531 SGMII register group */
  325. #define MT7531_SGMII_REG_BASE 0x5000
  326. #define MT7531_SGMII_REG(p, r) (MT7531_SGMII_REG_BASE + \
  327. ((p) - 5) * 0x1000 + (r))
  328. /* Register forSGMII PCS_CONTROL_1 */
  329. #define MT7531_PCS_CONTROL_1(p) MT7531_SGMII_REG(p, 0x00)
  330. #define MT7531_SGMII_LINK_STATUS BIT(18)
  331. #define MT7531_SGMII_AN_ENABLE BIT(12)
  332. #define MT7531_SGMII_AN_RESTART BIT(9)
  333. #define MT7531_SGMII_AN_COMPLETE BIT(21)
  334. /* Register for SGMII PCS_SPPED_ABILITY */
  335. #define MT7531_PCS_SPEED_ABILITY(p) MT7531_SGMII_REG(p, 0x08)
  336. #define MT7531_SGMII_TX_CONFIG_MASK GENMASK(15, 0)
  337. #define MT7531_SGMII_TX_CONFIG BIT(0)
  338. /* Register for SGMII_MODE */
  339. #define MT7531_SGMII_MODE(p) MT7531_SGMII_REG(p, 0x20)
  340. #define MT7531_SGMII_REMOTE_FAULT_DIS BIT(8)
  341. #define MT7531_SGMII_IF_MODE_MASK GENMASK(5, 1)
  342. #define MT7531_SGMII_FORCE_DUPLEX BIT(4)
  343. #define MT7531_SGMII_FORCE_SPEED_MASK GENMASK(3, 2)
  344. #define MT7531_SGMII_FORCE_SPEED_1000 BIT(3)
  345. #define MT7531_SGMII_FORCE_SPEED_100 BIT(2)
  346. #define MT7531_SGMII_FORCE_SPEED_10 0
  347. #define MT7531_SGMII_SPEED_DUPLEX_AN BIT(1)
  348. enum mt7531_sgmii_force_duplex {
  349. MT7531_SGMII_FORCE_FULL_DUPLEX = 0,
  350. MT7531_SGMII_FORCE_HALF_DUPLEX = 0x10,
  351. };
  352. /* Fields of QPHY_PWR_STATE_CTRL */
  353. #define MT7531_QPHY_PWR_STATE_CTRL(p) MT7531_SGMII_REG(p, 0xe8)
  354. #define MT7531_SGMII_PHYA_PWD BIT(4)
  355. /* Values of SGMII SPEED */
  356. #define MT7531_PHYA_CTRL_SIGNAL3(p) MT7531_SGMII_REG(p, 0x128)
  357. #define MT7531_RG_TPHY_SPEED_MASK (BIT(2) | BIT(3))
  358. #define MT7531_RG_TPHY_SPEED_1_25G 0x0
  359. #define MT7531_RG_TPHY_SPEED_3_125G BIT(2)
  360. /* Register for system reset */
  361. #define MT7530_SYS_CTRL 0x7000
  362. #define SYS_CTRL_PHY_RST BIT(2)
  363. #define SYS_CTRL_SW_RST BIT(1)
  364. #define SYS_CTRL_REG_RST BIT(0)
  365. /* Register for system interrupt */
  366. #define MT7530_SYS_INT_EN 0x7008
  367. /* Register for system interrupt status */
  368. #define MT7530_SYS_INT_STS 0x700c
  369. /* Register for PHY Indirect Access Control */
  370. #define MT7531_PHY_IAC 0x701C
  371. #define MT7531_PHY_ACS_ST BIT(31)
  372. #define MT7531_MDIO_REG_ADDR_MASK (0x1f << 25)
  373. #define MT7531_MDIO_PHY_ADDR_MASK (0x1f << 20)
  374. #define MT7531_MDIO_CMD_MASK (0x3 << 18)
  375. #define MT7531_MDIO_ST_MASK (0x3 << 16)
  376. #define MT7531_MDIO_RW_DATA_MASK (0xffff)
  377. #define MT7531_MDIO_REG_ADDR(x) (((x) & 0x1f) << 25)
  378. #define MT7531_MDIO_DEV_ADDR(x) (((x) & 0x1f) << 25)
  379. #define MT7531_MDIO_PHY_ADDR(x) (((x) & 0x1f) << 20)
  380. #define MT7531_MDIO_CMD(x) (((x) & 0x3) << 18)
  381. #define MT7531_MDIO_ST(x) (((x) & 0x3) << 16)
  382. enum mt7531_phy_iac_cmd {
  383. MT7531_MDIO_ADDR = 0,
  384. MT7531_MDIO_WRITE = 1,
  385. MT7531_MDIO_READ = 2,
  386. MT7531_MDIO_READ_CL45 = 3,
  387. };
  388. /* MDIO_ST: MDIO start field */
  389. enum mt7531_mdio_st {
  390. MT7531_MDIO_ST_CL45 = 0,
  391. MT7531_MDIO_ST_CL22 = 1,
  392. };
  393. #define MT7531_MDIO_CL22_READ (MT7531_MDIO_ST(MT7531_MDIO_ST_CL22) | \
  394. MT7531_MDIO_CMD(MT7531_MDIO_READ))
  395. #define MT7531_MDIO_CL22_WRITE (MT7531_MDIO_ST(MT7531_MDIO_ST_CL22) | \
  396. MT7531_MDIO_CMD(MT7531_MDIO_WRITE))
  397. #define MT7531_MDIO_CL45_ADDR (MT7531_MDIO_ST(MT7531_MDIO_ST_CL45) | \
  398. MT7531_MDIO_CMD(MT7531_MDIO_ADDR))
  399. #define MT7531_MDIO_CL45_READ (MT7531_MDIO_ST(MT7531_MDIO_ST_CL45) | \
  400. MT7531_MDIO_CMD(MT7531_MDIO_READ))
  401. #define MT7531_MDIO_CL45_WRITE (MT7531_MDIO_ST(MT7531_MDIO_ST_CL45) | \
  402. MT7531_MDIO_CMD(MT7531_MDIO_WRITE))
  403. /* Register for RGMII clock phase */
  404. #define MT7531_CLKGEN_CTRL 0x7500
  405. #define CLK_SKEW_OUT(x) (((x) & 0x3) << 8)
  406. #define CLK_SKEW_OUT_MASK GENMASK(9, 8)
  407. #define CLK_SKEW_IN(x) (((x) & 0x3) << 6)
  408. #define CLK_SKEW_IN_MASK GENMASK(7, 6)
  409. #define RXCLK_NO_DELAY BIT(5)
  410. #define TXCLK_NO_REVERSE BIT(4)
  411. #define GP_MODE(x) (((x) & 0x3) << 1)
  412. #define GP_MODE_MASK GENMASK(2, 1)
  413. #define GP_CLK_EN BIT(0)
  414. enum mt7531_gp_mode {
  415. MT7531_GP_MODE_RGMII = 0,
  416. MT7531_GP_MODE_MII = 1,
  417. MT7531_GP_MODE_REV_MII = 2
  418. };
  419. enum mt7531_clk_skew {
  420. MT7531_CLK_SKEW_NO_CHG = 0,
  421. MT7531_CLK_SKEW_DLY_100PPS = 1,
  422. MT7531_CLK_SKEW_DLY_200PPS = 2,
  423. MT7531_CLK_SKEW_REVERSE = 3,
  424. };
  425. /* Register for hw trap status */
  426. #define MT7530_HWTRAP 0x7800
  427. #define HWTRAP_XTAL_MASK (BIT(10) | BIT(9))
  428. #define HWTRAP_XTAL_25MHZ (BIT(10) | BIT(9))
  429. #define HWTRAP_XTAL_40MHZ (BIT(10))
  430. #define HWTRAP_XTAL_20MHZ (BIT(9))
  431. #define MT7531_HWTRAP 0x7800
  432. #define HWTRAP_XTAL_FSEL_MASK BIT(7)
  433. #define HWTRAP_XTAL_FSEL_25MHZ BIT(7)
  434. #define HWTRAP_XTAL_FSEL_40MHZ 0
  435. /* Unique fields of (M)HWSTRAP for MT7531 */
  436. #define XTAL_FSEL_S 7
  437. #define XTAL_FSEL_M BIT(7)
  438. #define PHY_EN BIT(6)
  439. #define CHG_STRAP BIT(8)
  440. /* Register for hw trap modification */
  441. #define MT7530_MHWTRAP 0x7804
  442. #define MHWTRAP_PHY0_SEL BIT(20)
  443. #define MHWTRAP_MANUAL BIT(16)
  444. #define MHWTRAP_P5_MAC_SEL BIT(13)
  445. #define MHWTRAP_P6_DIS BIT(8)
  446. #define MHWTRAP_P5_RGMII_MODE BIT(7)
  447. #define MHWTRAP_P5_DIS BIT(6)
  448. #define MHWTRAP_PHY_ACCESS BIT(5)
  449. /* Register for TOP signal control */
  450. #define MT7530_TOP_SIG_CTRL 0x7808
  451. #define TOP_SIG_CTRL_NORMAL (BIT(17) | BIT(16))
  452. #define MT7531_TOP_SIG_SR 0x780c
  453. #define PAD_DUAL_SGMII_EN BIT(1)
  454. #define PAD_MCM_SMI_EN BIT(0)
  455. #define MT7530_IO_DRV_CR 0x7810
  456. #define P5_IO_CLK_DRV(x) ((x) & 0x3)
  457. #define P5_IO_DATA_DRV(x) (((x) & 0x3) << 4)
  458. #define MT7531_CHIP_REV 0x781C
  459. #define MT7531_PLLGP_EN 0x7820
  460. #define EN_COREPLL BIT(2)
  461. #define SW_CLKSW BIT(1)
  462. #define SW_PLLGP BIT(0)
  463. #define MT7530_P6ECR 0x7830
  464. #define P6_INTF_MODE_MASK 0x3
  465. #define P6_INTF_MODE(x) ((x) & 0x3)
  466. #define MT7531_PLLGP_CR0 0x78a8
  467. #define RG_COREPLL_EN BIT(22)
  468. #define RG_COREPLL_POSDIV_S 23
  469. #define RG_COREPLL_POSDIV_M 0x3800000
  470. #define RG_COREPLL_SDM_PCW_S 1
  471. #define RG_COREPLL_SDM_PCW_M 0x3ffffe
  472. #define RG_COREPLL_SDM_PCW_CHG BIT(0)
  473. /* Registers for RGMII and SGMII PLL clock */
  474. #define MT7531_ANA_PLLGP_CR2 0x78b0
  475. #define MT7531_ANA_PLLGP_CR5 0x78bc
  476. /* Registers for TRGMII on the both side */
  477. #define MT7530_TRGMII_RCK_CTRL 0x7a00
  478. #define RX_RST BIT(31)
  479. #define RXC_DQSISEL BIT(30)
  480. #define DQSI1_TAP_MASK (0x7f << 8)
  481. #define DQSI0_TAP_MASK 0x7f
  482. #define DQSI1_TAP(x) (((x) & 0x7f) << 8)
  483. #define DQSI0_TAP(x) ((x) & 0x7f)
  484. #define MT7530_TRGMII_RCK_RTT 0x7a04
  485. #define DQS1_GATE BIT(31)
  486. #define DQS0_GATE BIT(30)
  487. #define MT7530_TRGMII_RD(x) (0x7a10 + (x) * 8)
  488. #define BSLIP_EN BIT(31)
  489. #define EDGE_CHK BIT(30)
  490. #define RD_TAP_MASK 0x7f
  491. #define RD_TAP(x) ((x) & 0x7f)
  492. #define MT7530_TRGMII_TXCTRL 0x7a40
  493. #define TRAIN_TXEN BIT(31)
  494. #define TXC_INV BIT(30)
  495. #define TX_RST BIT(28)
  496. #define MT7530_TRGMII_TD_ODT(i) (0x7a54 + 8 * (i))
  497. #define TD_DM_DRVP(x) ((x) & 0xf)
  498. #define TD_DM_DRVN(x) (((x) & 0xf) << 4)
  499. #define MT7530_TRGMII_TCK_CTRL 0x7a78
  500. #define TCK_TAP(x) (((x) & 0xf) << 8)
  501. #define MT7530_P5RGMIIRXCR 0x7b00
  502. #define CSR_RGMII_EDGE_ALIGN BIT(8)
  503. #define CSR_RGMII_RXC_0DEG_CFG(x) ((x) & 0xf)
  504. #define MT7530_P5RGMIITXCR 0x7b04
  505. #define CSR_RGMII_TXC_CFG(x) ((x) & 0x1f)
  506. /* Registers for GPIO mode */
  507. #define MT7531_GPIO_MODE0 0x7c0c
  508. #define MT7531_GPIO0_MASK GENMASK(3, 0)
  509. #define MT7531_GPIO0_INTERRUPT 1
  510. #define MT7531_GPIO_MODE1 0x7c10
  511. #define MT7531_GPIO11_RG_RXD2_MASK GENMASK(15, 12)
  512. #define MT7531_EXT_P_MDC_11 (2 << 12)
  513. #define MT7531_GPIO12_RG_RXD3_MASK GENMASK(19, 16)
  514. #define MT7531_EXT_P_MDIO_12 (2 << 16)
  515. /* Registers for LED GPIO control (MT7530 only)
  516. * All registers follow this pattern:
  517. * [ 2: 0] port 0
  518. * [ 6: 4] port 1
  519. * [10: 8] port 2
  520. * [14:12] port 3
  521. * [18:16] port 4
  522. */
  523. /* LED enable, 0: Disable, 1: Enable (Default) */
  524. #define MT7530_LED_EN 0x7d00
  525. /* LED mode, 0: GPIO mode, 1: PHY mode (Default) */
  526. #define MT7530_LED_IO_MODE 0x7d04
  527. /* GPIO direction, 0: Input, 1: Output */
  528. #define MT7530_LED_GPIO_DIR 0x7d10
  529. /* GPIO output enable, 0: Disable, 1: Enable */
  530. #define MT7530_LED_GPIO_OE 0x7d14
  531. /* GPIO value, 0: Low, 1: High */
  532. #define MT7530_LED_GPIO_DATA 0x7d18
  533. #define MT7530_CREV 0x7ffc
  534. #define CHIP_NAME_SHIFT 16
  535. #define MT7530_ID 0x7530
  536. #define MT7531_CREV 0x781C
  537. #define CHIP_REV_M 0x0f
  538. #define MT7531_ID 0x7531
  539. /* Registers for core PLL access through mmd indirect */
  540. #define CORE_PLL_GROUP2 0x401
  541. #define RG_SYSPLL_EN_NORMAL BIT(15)
  542. #define RG_SYSPLL_VODEN BIT(14)
  543. #define RG_SYSPLL_LF BIT(13)
  544. #define RG_SYSPLL_RST_DLY(x) (((x) & 0x3) << 12)
  545. #define RG_SYSPLL_LVROD_EN BIT(10)
  546. #define RG_SYSPLL_PREDIV(x) (((x) & 0x3) << 8)
  547. #define RG_SYSPLL_POSDIV(x) (((x) & 0x3) << 5)
  548. #define RG_SYSPLL_FBKSEL BIT(4)
  549. #define RT_SYSPLL_EN_AFE_OLT BIT(0)
  550. #define CORE_PLL_GROUP4 0x403
  551. #define RG_SYSPLL_DDSFBK_EN BIT(12)
  552. #define RG_SYSPLL_BIAS_EN BIT(11)
  553. #define RG_SYSPLL_BIAS_LPF_EN BIT(10)
  554. #define MT7531_PHY_PLL_OFF BIT(5)
  555. #define MT7531_PHY_PLL_BYPASS_MODE BIT(4)
  556. #define MT753X_CTRL_PHY_ADDR 0
  557. #define CORE_PLL_GROUP5 0x404
  558. #define RG_LCDDS_PCW_NCPO1(x) ((x) & 0xffff)
  559. #define CORE_PLL_GROUP6 0x405
  560. #define RG_LCDDS_PCW_NCPO0(x) ((x) & 0xffff)
  561. #define CORE_PLL_GROUP7 0x406
  562. #define RG_LCDDS_PWDB BIT(15)
  563. #define RG_LCDDS_ISO_EN BIT(13)
  564. #define RG_LCCDS_C(x) (((x) & 0x7) << 4)
  565. #define RG_LCDDS_PCW_NCPO_CHG BIT(3)
  566. #define CORE_PLL_GROUP10 0x409
  567. #define RG_LCDDS_SSC_DELTA(x) ((x) & 0xfff)
  568. #define CORE_PLL_GROUP11 0x40a
  569. #define RG_LCDDS_SSC_DELTA1(x) ((x) & 0xfff)
  570. #define CORE_GSWPLL_GRP1 0x40d
  571. #define RG_GSWPLL_PREDIV(x) (((x) & 0x3) << 14)
  572. #define RG_GSWPLL_POSDIV_200M(x) (((x) & 0x3) << 12)
  573. #define RG_GSWPLL_EN_PRE BIT(11)
  574. #define RG_GSWPLL_FBKSEL BIT(10)
  575. #define RG_GSWPLL_BP BIT(9)
  576. #define RG_GSWPLL_BR BIT(8)
  577. #define RG_GSWPLL_FBKDIV_200M(x) ((x) & 0xff)
  578. #define CORE_GSWPLL_GRP2 0x40e
  579. #define RG_GSWPLL_POSDIV_500M(x) (((x) & 0x3) << 8)
  580. #define RG_GSWPLL_FBKDIV_500M(x) ((x) & 0xff)
  581. #define CORE_TRGMII_GSW_CLK_CG 0x410
  582. #define REG_GSWCK_EN BIT(0)
  583. #define REG_TRGMIICK_EN BIT(1)
  584. #define MIB_DESC(_s, _o, _n) \
  585. { \
  586. .size = (_s), \
  587. .offset = (_o), \
  588. .name = (_n), \
  589. }
  590. struct mt7530_mib_desc {
  591. unsigned int size;
  592. unsigned int offset;
  593. const char *name;
  594. };
  595. struct mt7530_fdb {
  596. u16 vid;
  597. u8 port_mask;
  598. u8 aging;
  599. u8 mac[6];
  600. bool noarp;
  601. };
  602. /* struct mt7530_port - This is the main data structure for holding the state
  603. * of the port.
  604. * @enable: The status used for show port is enabled or not.
  605. * @pm: The matrix used to show all connections with the port.
  606. * @pvid: The VLAN specified is to be considered a PVID at ingress. Any
  607. * untagged frames will be assigned to the related VLAN.
  608. * @vlan_filtering: The flags indicating whether the port that can recognize
  609. * VLAN-tagged frames.
  610. */
  611. struct mt7530_port {
  612. bool enable;
  613. u32 pm;
  614. u16 pvid;
  615. };
  616. /* Port 5 interface select definitions */
  617. enum p5_interface_select {
  618. P5_DISABLED = 0,
  619. P5_INTF_SEL_PHY_P0,
  620. P5_INTF_SEL_PHY_P4,
  621. P5_INTF_SEL_GMAC5,
  622. P5_INTF_SEL_GMAC5_SGMII,
  623. };
  624. static const char *p5_intf_modes(unsigned int p5_interface)
  625. {
  626. switch (p5_interface) {
  627. case P5_DISABLED:
  628. return "DISABLED";
  629. case P5_INTF_SEL_PHY_P0:
  630. return "PHY P0";
  631. case P5_INTF_SEL_PHY_P4:
  632. return "PHY P4";
  633. case P5_INTF_SEL_GMAC5:
  634. return "GMAC5";
  635. case P5_INTF_SEL_GMAC5_SGMII:
  636. return "GMAC5_SGMII";
  637. default:
  638. return "unknown";
  639. }
  640. }
  641. struct mt7530_priv;
  642. struct mt753x_pcs {
  643. struct phylink_pcs pcs;
  644. struct mt7530_priv *priv;
  645. int port;
  646. };
  647. /* struct mt753x_info - This is the main data structure for holding the specific
  648. * part for each supported device
  649. * @sw_setup: Holding the handler to a device initialization
  650. * @phy_read: Holding the way reading PHY port
  651. * @phy_write: Holding the way writing PHY port
  652. * @pad_setup: Holding the way setting up the bus pad for a certain
  653. * MAC port
  654. * @phy_mode_supported: Check if the PHY type is being supported on a certain
  655. * port
  656. * @mac_port_validate: Holding the way to set addition validate type for a
  657. * certan MAC port
  658. * @mac_port_config: Holding the way setting up the PHY attribute to a
  659. * certain MAC port
  660. */
  661. struct mt753x_info {
  662. enum mt753x_id id;
  663. const struct phylink_pcs_ops *pcs_ops;
  664. int (*sw_setup)(struct dsa_switch *ds);
  665. int (*phy_read)(struct mt7530_priv *priv, int port, int regnum);
  666. int (*phy_write)(struct mt7530_priv *priv, int port, int regnum, u16 val);
  667. int (*pad_setup)(struct dsa_switch *ds, phy_interface_t interface);
  668. int (*cpu_port_config)(struct dsa_switch *ds, int port);
  669. void (*mac_port_get_caps)(struct dsa_switch *ds, int port,
  670. struct phylink_config *config);
  671. void (*mac_port_validate)(struct dsa_switch *ds, int port,
  672. phy_interface_t interface,
  673. unsigned long *supported);
  674. int (*mac_port_config)(struct dsa_switch *ds, int port,
  675. unsigned int mode,
  676. phy_interface_t interface);
  677. };
  678. /* struct mt7530_priv - This is the main data structure for holding the state
  679. * of the driver
  680. * @dev: The device pointer
  681. * @ds: The pointer to the dsa core structure
  682. * @bus: The bus used for the device and built-in PHY
  683. * @rstc: The pointer to reset control used by MCM
  684. * @core_pwr: The power supplied into the core
  685. * @io_pwr: The power supplied into the I/O
  686. * @reset: The descriptor for GPIO line tied to its reset pin
  687. * @mcm: Flag for distinguishing if standalone IC or module
  688. * coupling
  689. * @ports: Holding the state among ports
  690. * @reg_mutex: The lock for protecting among process accessing
  691. * registers
  692. * @p6_interface Holding the current port 6 interface
  693. * @p5_intf_sel: Holding the current port 5 interface select
  694. *
  695. * @irq: IRQ number of the switch
  696. * @irq_domain: IRQ domain of the switch irq_chip
  697. * @irq_enable: IRQ enable bits, synced to SYS_INT_EN
  698. */
  699. struct mt7530_priv {
  700. struct device *dev;
  701. struct dsa_switch *ds;
  702. struct mii_bus *bus;
  703. struct reset_control *rstc;
  704. struct regulator *core_pwr;
  705. struct regulator *io_pwr;
  706. struct gpio_desc *reset;
  707. const struct mt753x_info *info;
  708. unsigned int id;
  709. bool mcm;
  710. phy_interface_t p6_interface;
  711. phy_interface_t p5_interface;
  712. unsigned int p5_intf_sel;
  713. u8 mirror_rx;
  714. u8 mirror_tx;
  715. struct mt7530_port ports[MT7530_NUM_PORTS];
  716. struct mt753x_pcs pcs[MT7530_NUM_PORTS];
  717. /* protect among processes for registers access*/
  718. struct mutex reg_mutex;
  719. int irq;
  720. struct irq_domain *irq_domain;
  721. u32 irq_enable;
  722. };
  723. struct mt7530_hw_vlan_entry {
  724. int port;
  725. u8 old_members;
  726. bool untagged;
  727. };
  728. static inline void mt7530_hw_vlan_entry_init(struct mt7530_hw_vlan_entry *e,
  729. int port, bool untagged)
  730. {
  731. e->port = port;
  732. e->untagged = untagged;
  733. }
  734. typedef void (*mt7530_vlan_op)(struct mt7530_priv *,
  735. struct mt7530_hw_vlan_entry *);
  736. struct mt7530_hw_stats {
  737. const char *string;
  738. u16 reg;
  739. u8 sizeof_stat;
  740. };
  741. struct mt7530_dummy_poll {
  742. struct mt7530_priv *priv;
  743. u32 reg;
  744. };
  745. static inline void INIT_MT7530_DUMMY_POLL(struct mt7530_dummy_poll *p,
  746. struct mt7530_priv *priv, u32 reg)
  747. {
  748. p->priv = priv;
  749. p->reg = reg;
  750. }
  751. #endif /* __MT7530_H */