mt7530.h 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403
  1. /*
  2. * Copyright (C) 2017 Sean Wang <sean.wang@mediatek.com>
  3. *
  4. * This program is free software; you can redistribute it and/or modify
  5. * it under the terms of the GNU General Public License version 2 as
  6. * published by the Free Software Foundation.
  7. *
  8. * This program is distributed in the hope that it will be useful,
  9. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  10. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  11. * GNU General Public License for more details.
  12. */
  13. #ifndef __MT7530_H
  14. #define __MT7530_H
  15. #define MT7530_NUM_PORTS 7
  16. #define MT7530_CPU_PORT 6
  17. #define MT7530_NUM_FDB_RECORDS 2048
  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 UNM_FFP(x) (((x) & 0xff) << 16)
  29. #define UNU_FFP(x) (((x) & 0xff) << 8)
  30. #define UNU_FFP_MASK UNU_FFP(~0)
  31. /* Registers for address table access */
  32. #define MT7530_ATA1 0x74
  33. #define STATIC_EMP 0
  34. #define STATIC_ENT 3
  35. #define MT7530_ATA2 0x78
  36. /* Register for address table write data */
  37. #define MT7530_ATWD 0x7c
  38. /* Register for address table control */
  39. #define MT7530_ATC 0x80
  40. #define ATC_HASH (((x) & 0xfff) << 16)
  41. #define ATC_BUSY BIT(15)
  42. #define ATC_SRCH_END BIT(14)
  43. #define ATC_SRCH_HIT BIT(13)
  44. #define ATC_INVALID BIT(12)
  45. #define ATC_MAT(x) (((x) & 0xf) << 8)
  46. #define ATC_MAT_MACTAB ATC_MAT(0)
  47. enum mt7530_fdb_cmd {
  48. MT7530_FDB_READ = 0,
  49. MT7530_FDB_WRITE = 1,
  50. MT7530_FDB_FLUSH = 2,
  51. MT7530_FDB_START = 4,
  52. MT7530_FDB_NEXT = 5,
  53. };
  54. /* Registers for table search read address */
  55. #define MT7530_TSRA1 0x84
  56. #define MAC_BYTE_0 24
  57. #define MAC_BYTE_1 16
  58. #define MAC_BYTE_2 8
  59. #define MAC_BYTE_3 0
  60. #define MAC_BYTE_MASK 0xff
  61. #define MT7530_TSRA2 0x88
  62. #define MAC_BYTE_4 24
  63. #define MAC_BYTE_5 16
  64. #define CVID 0
  65. #define CVID_MASK 0xfff
  66. #define MT7530_ATRD 0x8C
  67. #define AGE_TIMER 24
  68. #define AGE_TIMER_MASK 0xff
  69. #define PORT_MAP 4
  70. #define PORT_MAP_MASK 0xff
  71. #define ENT_STATUS 2
  72. #define ENT_STATUS_MASK 0x3
  73. /* Register for vlan table control */
  74. #define MT7530_VTCR 0x90
  75. #define VTCR_BUSY BIT(31)
  76. #define VTCR_FUNC (((x) & 0xf) << 12)
  77. #define VTCR_FUNC_RD_VID 0x1
  78. #define VTCR_FUNC_WR_VID 0x2
  79. #define VTCR_FUNC_INV_VID 0x3
  80. #define VTCR_FUNC_VAL_VID 0x4
  81. #define VTCR_VID ((x) & 0xfff)
  82. /* Register for setup vlan and acl write data */
  83. #define MT7530_VAWD1 0x94
  84. #define PORT_STAG BIT(31)
  85. #define IVL_MAC BIT(30)
  86. #define PORT_MEM(x) (((x) & 0xff) << 16)
  87. #define VALID BIT(1)
  88. #define MT7530_VAWD2 0x98
  89. /* Register for port STP state control */
  90. #define MT7530_SSP_P(x) (0x2000 + ((x) * 0x100))
  91. #define FID_PST(x) ((x) & 0x3)
  92. #define FID_PST_MASK FID_PST(0x3)
  93. enum mt7530_stp_state {
  94. MT7530_STP_DISABLED = 0,
  95. MT7530_STP_BLOCKING = 1,
  96. MT7530_STP_LISTENING = 1,
  97. MT7530_STP_LEARNING = 2,
  98. MT7530_STP_FORWARDING = 3
  99. };
  100. /* Register for port control */
  101. #define MT7530_PCR_P(x) (0x2004 + ((x) * 0x100))
  102. #define PORT_VLAN(x) ((x) & 0x3)
  103. #define PCR_MATRIX(x) (((x) & 0xff) << 16)
  104. #define PORT_PRI(x) (((x) & 0x7) << 24)
  105. #define EG_TAG(x) (((x) & 0x3) << 28)
  106. #define PCR_MATRIX_MASK PCR_MATRIX(0xff)
  107. #define PCR_MATRIX_CLR PCR_MATRIX(0)
  108. /* Register for port security control */
  109. #define MT7530_PSC_P(x) (0x200c + ((x) * 0x100))
  110. #define SA_DIS BIT(4)
  111. /* Register for port vlan control */
  112. #define MT7530_PVC_P(x) (0x2010 + ((x) * 0x100))
  113. #define PORT_SPEC_TAG BIT(5)
  114. #define VLAN_ATTR(x) (((x) & 0x3) << 6)
  115. #define STAG_VPID (((x) & 0xffff) << 16)
  116. /* Register for port port-and-protocol based vlan 1 control */
  117. #define MT7530_PPBV1_P(x) (0x2014 + ((x) * 0x100))
  118. /* Register for port MAC control register */
  119. #define MT7530_PMCR_P(x) (0x3000 + ((x) * 0x100))
  120. #define PMCR_IFG_XMIT(x) (((x) & 0x3) << 18)
  121. #define PMCR_MAC_MODE BIT(16)
  122. #define PMCR_FORCE_MODE BIT(15)
  123. #define PMCR_TX_EN BIT(14)
  124. #define PMCR_RX_EN BIT(13)
  125. #define PMCR_BACKOFF_EN BIT(9)
  126. #define PMCR_BACKPR_EN BIT(8)
  127. #define PMCR_TX_FC_EN BIT(5)
  128. #define PMCR_RX_FC_EN BIT(4)
  129. #define PMCR_FORCE_SPEED_1000 BIT(3)
  130. #define PMCR_FORCE_SPEED_100 BIT(2)
  131. #define PMCR_FORCE_FDX BIT(1)
  132. #define PMCR_FORCE_LNK BIT(0)
  133. #define PMCR_COMMON_LINK (PMCR_IFG_XMIT(1) | PMCR_MAC_MODE | \
  134. PMCR_BACKOFF_EN | PMCR_BACKPR_EN | \
  135. PMCR_TX_EN | PMCR_RX_EN | \
  136. PMCR_TX_FC_EN | PMCR_RX_FC_EN)
  137. #define PMCR_CPUP_LINK (PMCR_COMMON_LINK | PMCR_FORCE_MODE | \
  138. PMCR_FORCE_SPEED_1000 | \
  139. PMCR_FORCE_FDX | \
  140. PMCR_FORCE_LNK)
  141. #define PMCR_USERP_LINK PMCR_COMMON_LINK
  142. #define PMCR_FIXED_LINK (PMCR_IFG_XMIT(1) | PMCR_MAC_MODE | \
  143. PMCR_FORCE_MODE | PMCR_TX_EN | \
  144. PMCR_RX_EN | PMCR_BACKPR_EN | \
  145. PMCR_BACKOFF_EN | \
  146. PMCR_FORCE_SPEED_1000 | \
  147. PMCR_FORCE_FDX | \
  148. PMCR_FORCE_LNK)
  149. #define PMCR_FIXED_LINK_FC (PMCR_FIXED_LINK | \
  150. PMCR_TX_FC_EN | PMCR_RX_FC_EN)
  151. #define MT7530_PMSR_P(x) (0x3008 + (x) * 0x100)
  152. /* Register for MIB */
  153. #define MT7530_PORT_MIB_COUNTER(x) (0x4000 + (x) * 0x100)
  154. #define MT7530_MIB_CCR 0x4fe0
  155. #define CCR_MIB_ENABLE BIT(31)
  156. #define CCR_RX_OCT_CNT_GOOD BIT(7)
  157. #define CCR_RX_OCT_CNT_BAD BIT(6)
  158. #define CCR_TX_OCT_CNT_GOOD BIT(5)
  159. #define CCR_TX_OCT_CNT_BAD BIT(4)
  160. #define CCR_MIB_FLUSH (CCR_RX_OCT_CNT_GOOD | \
  161. CCR_RX_OCT_CNT_BAD | \
  162. CCR_TX_OCT_CNT_GOOD | \
  163. CCR_TX_OCT_CNT_BAD)
  164. #define CCR_MIB_ACTIVATE (CCR_MIB_ENABLE | \
  165. CCR_RX_OCT_CNT_GOOD | \
  166. CCR_RX_OCT_CNT_BAD | \
  167. CCR_TX_OCT_CNT_GOOD | \
  168. CCR_TX_OCT_CNT_BAD)
  169. /* Register for system reset */
  170. #define MT7530_SYS_CTRL 0x7000
  171. #define SYS_CTRL_PHY_RST BIT(2)
  172. #define SYS_CTRL_SW_RST BIT(1)
  173. #define SYS_CTRL_REG_RST BIT(0)
  174. /* Register for hw trap status */
  175. #define MT7530_HWTRAP 0x7800
  176. /* Register for hw trap modification */
  177. #define MT7530_MHWTRAP 0x7804
  178. #define MHWTRAP_MANUAL BIT(16)
  179. #define MHWTRAP_P5_MAC_SEL BIT(13)
  180. #define MHWTRAP_P6_DIS BIT(8)
  181. #define MHWTRAP_P5_RGMII_MODE BIT(7)
  182. #define MHWTRAP_P5_DIS BIT(6)
  183. #define MHWTRAP_PHY_ACCESS BIT(5)
  184. /* Register for TOP signal control */
  185. #define MT7530_TOP_SIG_CTRL 0x7808
  186. #define TOP_SIG_CTRL_NORMAL (BIT(17) | BIT(16))
  187. #define MT7530_IO_DRV_CR 0x7810
  188. #define P5_IO_CLK_DRV(x) ((x) & 0x3)
  189. #define P5_IO_DATA_DRV(x) (((x) & 0x3) << 4)
  190. #define MT7530_P6ECR 0x7830
  191. #define P6_INTF_MODE_MASK 0x3
  192. #define P6_INTF_MODE(x) ((x) & 0x3)
  193. /* Registers for TRGMII on the both side */
  194. #define MT7530_TRGMII_RCK_CTRL 0x7a00
  195. #define GSW_TRGMII_RCK_CTRL 0x300
  196. #define RX_RST BIT(31)
  197. #define RXC_DQSISEL BIT(30)
  198. #define DQSI1_TAP_MASK (0x7f << 8)
  199. #define DQSI0_TAP_MASK 0x7f
  200. #define DQSI1_TAP(x) (((x) & 0x7f) << 8)
  201. #define DQSI0_TAP(x) ((x) & 0x7f)
  202. #define MT7530_TRGMII_RCK_RTT 0x7a04
  203. #define GSW_TRGMII_RCK_RTT 0x304
  204. #define DQS1_GATE BIT(31)
  205. #define DQS0_GATE BIT(30)
  206. #define MT7530_TRGMII_RD(x) (0x7a10 + (x) * 8)
  207. #define GSW_TRGMII_RD(x) (0x310 + (x) * 8)
  208. #define BSLIP_EN BIT(31)
  209. #define EDGE_CHK BIT(30)
  210. #define RD_TAP_MASK 0x7f
  211. #define RD_TAP(x) ((x) & 0x7f)
  212. #define GSW_TRGMII_TXCTRL 0x340
  213. #define MT7530_TRGMII_TXCTRL 0x7a40
  214. #define TRAIN_TXEN BIT(31)
  215. #define TXC_INV BIT(30)
  216. #define TX_RST BIT(28)
  217. #define MT7530_TRGMII_TD_ODT(i) (0x7a54 + 8 * (i))
  218. #define GSW_TRGMII_TD_ODT(i) (0x354 + 8 * (i))
  219. #define TD_DM_DRVP(x) ((x) & 0xf)
  220. #define TD_DM_DRVN(x) (((x) & 0xf) << 4)
  221. #define GSW_INTF_MODE 0x390
  222. #define INTF_MODE_TRGMII BIT(1)
  223. #define MT7530_TRGMII_TCK_CTRL 0x7a78
  224. #define TCK_TAP(x) (((x) & 0xf) << 8)
  225. #define MT7530_P5RGMIIRXCR 0x7b00
  226. #define CSR_RGMII_EDGE_ALIGN BIT(8)
  227. #define CSR_RGMII_RXC_0DEG_CFG(x) ((x) & 0xf)
  228. #define MT7530_P5RGMIITXCR 0x7b04
  229. #define CSR_RGMII_TXC_CFG(x) ((x) & 0x1f)
  230. #define MT7530_CREV 0x7ffc
  231. #define CHIP_NAME_SHIFT 16
  232. #define MT7530_ID 0x7530
  233. /* Registers for core PLL access through mmd indirect */
  234. #define CORE_PLL_GROUP2 0x401
  235. #define RG_SYSPLL_EN_NORMAL BIT(15)
  236. #define RG_SYSPLL_VODEN BIT(14)
  237. #define RG_SYSPLL_LF BIT(13)
  238. #define RG_SYSPLL_RST_DLY(x) (((x) & 0x3) << 12)
  239. #define RG_SYSPLL_LVROD_EN BIT(10)
  240. #define RG_SYSPLL_PREDIV(x) (((x) & 0x3) << 8)
  241. #define RG_SYSPLL_POSDIV(x) (((x) & 0x3) << 5)
  242. #define RG_SYSPLL_FBKSEL BIT(4)
  243. #define RT_SYSPLL_EN_AFE_OLT BIT(0)
  244. #define CORE_PLL_GROUP4 0x403
  245. #define RG_SYSPLL_DDSFBK_EN BIT(12)
  246. #define RG_SYSPLL_BIAS_EN BIT(11)
  247. #define RG_SYSPLL_BIAS_LPF_EN BIT(10)
  248. #define CORE_PLL_GROUP5 0x404
  249. #define RG_LCDDS_PCW_NCPO1(x) ((x) & 0xffff)
  250. #define CORE_PLL_GROUP6 0x405
  251. #define RG_LCDDS_PCW_NCPO0(x) ((x) & 0xffff)
  252. #define CORE_PLL_GROUP7 0x406
  253. #define RG_LCDDS_PWDB BIT(15)
  254. #define RG_LCDDS_ISO_EN BIT(13)
  255. #define RG_LCCDS_C(x) (((x) & 0x7) << 4)
  256. #define RG_LCDDS_PCW_NCPO_CHG BIT(3)
  257. #define CORE_PLL_GROUP10 0x409
  258. #define RG_LCDDS_SSC_DELTA(x) ((x) & 0xfff)
  259. #define CORE_PLL_GROUP11 0x40a
  260. #define RG_LCDDS_SSC_DELTA1(x) ((x) & 0xfff)
  261. #define CORE_GSWPLL_GRP1 0x40d
  262. #define RG_GSWPLL_PREDIV(x) (((x) & 0x3) << 14)
  263. #define RG_GSWPLL_POSDIV_200M(x) (((x) & 0x3) << 12)
  264. #define RG_GSWPLL_EN_PRE BIT(11)
  265. #define RG_GSWPLL_FBKSEL BIT(10)
  266. #define RG_GSWPLL_BP BIT(9)
  267. #define RG_GSWPLL_BR BIT(8)
  268. #define RG_GSWPLL_FBKDIV_200M(x) ((x) & 0xff)
  269. #define CORE_GSWPLL_GRP2 0x40e
  270. #define RG_GSWPLL_POSDIV_500M(x) (((x) & 0x3) << 8)
  271. #define RG_GSWPLL_FBKDIV_500M(x) ((x) & 0xff)
  272. #define CORE_TRGMII_GSW_CLK_CG 0x410
  273. #define REG_GSWCK_EN BIT(0)
  274. #define REG_TRGMIICK_EN BIT(1)
  275. #define MIB_DESC(_s, _o, _n) \
  276. { \
  277. .size = (_s), \
  278. .offset = (_o), \
  279. .name = (_n), \
  280. }
  281. struct mt7530_mib_desc {
  282. unsigned int size;
  283. unsigned int offset;
  284. const char *name;
  285. };
  286. struct mt7530_fdb {
  287. u16 vid;
  288. u8 port_mask;
  289. u8 aging;
  290. u8 mac[6];
  291. bool noarp;
  292. };
  293. struct mt7530_port {
  294. bool enable;
  295. u32 pm;
  296. };
  297. /* struct mt7530_priv - This is the main data structure for holding the state
  298. * of the driver
  299. * @dev: The device pointer
  300. * @ds: The pointer to the dsa core structure
  301. * @bus: The bus used for the device and built-in PHY
  302. * @rstc: The pointer to reset control used by MCM
  303. * @ethernet: The regmap used for access TRGMII-based registers
  304. * @core_pwr: The power supplied into the core
  305. * @io_pwr: The power supplied into the I/O
  306. * @reset: The descriptor for GPIO line tied to its reset pin
  307. * @mcm: Flag for distinguishing if standalone IC or module
  308. * coupling
  309. * @ports: Holding the state among ports
  310. * @reg_mutex: The lock for protecting among process accessing
  311. * registers
  312. */
  313. struct mt7530_priv {
  314. struct device *dev;
  315. struct dsa_switch *ds;
  316. struct mii_bus *bus;
  317. struct reset_control *rstc;
  318. struct regmap *ethernet;
  319. struct regulator *core_pwr;
  320. struct regulator *io_pwr;
  321. struct gpio_desc *reset;
  322. bool mcm;
  323. struct mt7530_port ports[MT7530_NUM_PORTS];
  324. /* protect among processes for registers access*/
  325. struct mutex reg_mutex;
  326. };
  327. struct mt7530_hw_stats {
  328. const char *string;
  329. u16 reg;
  330. u8 sizeof_stat;
  331. };
  332. struct mt7530_dummy_poll {
  333. struct mt7530_priv *priv;
  334. u32 reg;
  335. };
  336. static inline void INIT_MT7530_DUMMY_POLL(struct mt7530_dummy_poll *p,
  337. struct mt7530_priv *priv, u32 reg)
  338. {
  339. p->priv = priv;
  340. p->reg = reg;
  341. }
  342. #endif /* __MT7530_H */