blob: fd95d4d7c1f065164f31b5f6f344d19d3ecb235d [file] [log] [blame]
MD Danish Anwar89d709b2024-04-04 12:38:00 +05301/* SPDX-License-Identifier: GPL-2.0 */
2
3/* PRU-ICSS MII_RT register definitions
4 *
5 * Copyright (C) 2015-2024 Texas Instruments Incorporated - https://www.ti.com
6 */
7
8#ifndef __NET_PRUSS_MII_RT_H__
9#define __NET_PRUSS_MII_RT_H__
10
11#include <regmap.h>
12
13/* PRUSS_MII_RT Registers */
14#define PRUSS_MII_RT_RXCFG0 0x0
15#define PRUSS_MII_RT_RXCFG1 0x4
16#define PRUSS_MII_RT_TXCFG0 0x10
17#define PRUSS_MII_RT_TXCFG1 0x14
18#define PRUSS_MII_RT_TX_CRC0 0x20
19#define PRUSS_MII_RT_TX_CRC1 0x24
20#define PRUSS_MII_RT_TX_IPG0 0x30
21#define PRUSS_MII_RT_TX_IPG1 0x34
22#define PRUSS_MII_RT_PRS0 0x38
23#define PRUSS_MII_RT_PRS1 0x3c
24#define PRUSS_MII_RT_RX_FRMS0 0x40
25#define PRUSS_MII_RT_RX_FRMS1 0x44
26#define PRUSS_MII_RT_RX_PCNT0 0x48
27#define PRUSS_MII_RT_RX_PCNT1 0x4c
28#define PRUSS_MII_RT_RX_ERR0 0x50
29#define PRUSS_MII_RT_RX_ERR1 0x54
30
31/* PRUSS_MII_RT_RXCFG0/1 bits */
32#define PRUSS_MII_RT_RXCFG_RX_ENABLE BIT(0)
33#define PRUSS_MII_RT_RXCFG_RX_DATA_RDY_MODE_DIS BIT(1)
34#define PRUSS_MII_RT_RXCFG_RX_CUT_PREAMBLE BIT(2)
35#define PRUSS_MII_RT_RXCFG_RX_MUX_SEL BIT(3)
36#define PRUSS_MII_RT_RXCFG_RX_L2_EN BIT(4)
37#define PRUSS_MII_RT_RXCFG_RX_BYTE_SWAP BIT(5)
38#define PRUSS_MII_RT_RXCFG_RX_AUTO_FWD_PRE BIT(6)
39#define PRUSS_MII_RT_RXCFG_RX_L2_EOF_SCLR_DIS BIT(9)
40
41/* PRUSS_MII_RT_TXCFG0/1 bits */
42#define PRUSS_MII_RT_TXCFG_TX_ENABLE BIT(0)
43#define PRUSS_MII_RT_TXCFG_TX_AUTO_PREAMBLE BIT(1)
44#define PRUSS_MII_RT_TXCFG_TX_EN_MODE BIT(2)
45#define PRUSS_MII_RT_TXCFG_TX_BYTE_SWAP BIT(3)
46#define PRUSS_MII_RT_TXCFG_TX_MUX_SEL BIT(8)
47#define PRUSS_MII_RT_TXCFG_PRE_TX_AUTO_SEQUENCE BIT(9)
48#define PRUSS_MII_RT_TXCFG_PRE_TX_AUTO_ESC_ERR BIT(10)
49#define PRUSS_MII_RT_TXCFG_TX_32_MODE_EN BIT(11)
50#define PRUSS_MII_RT_TXCFG_TX_IPG_WIRE_CLK_EN BIT(12) /* SR2.0 onwards */
51
52#define PRUSS_MII_RT_TXCFG_TX_START_DELAY_SHIFT 16
53#define PRUSS_MII_RT_TXCFG_TX_START_DELAY_MASK GENMASK(25, 16)
54
55#define PRUSS_MII_RT_TXCFG_TX_CLK_DELAY_SHIFT 28
56#define PRUSS_MII_RT_TXCFG_TX_CLK_DELAY_MASK GENMASK(30, 28)
57
58/* PRUSS_MII_RT_TX_IPG0/1 bits */
59#define PRUSS_MII_RT_TX_IPG_IPG_SHIFT 0
60#define PRUSS_MII_RT_TX_IPG_IPG_MASK GENMASK(9, 0)
61
62/* PRUSS_MII_RT_PRS0/1 bits */
63#define PRUSS_MII_RT_PRS_COL BIT(0)
64#define PRUSS_MII_RT_PRS_CRS BIT(1)
65
66/* PRUSS_MII_RT_RX_FRMS0/1 bits */
67#define PRUSS_MII_RT_RX_FRMS_MIN_FRM_SHIFT 0
68#define PRUSS_MII_RT_RX_FRMS_MIN_FRM_MASK GENMASK(15, 0)
69
70#define PRUSS_MII_RT_RX_FRMS_MAX_FRM_SHIFT 16
71#define PRUSS_MII_RT_RX_FRMS_MAX_FRM_MASK GENMASK(31, 16)
72
73/* Min/Max in MII_RT_RX_FRMS */
74/* For EMAC and Switch */
75#define PRUSS_MII_RT_RX_FRMS_MAX (VLAN_ETH_FRAME_LEN + ETH_FCS_LEN)
76#define PRUSS_MII_RT_RX_FRMS_MIN_FRM (64)
77
78/* for HSR and PRP */
79#define PRUSS_MII_RT_RX_FRMS_MAX_FRM_LRE (PRUSS_MII_RT_RX_FRMS_MAX + \
80 ICSS_LRE_TAG_RCT_SIZE)
81/* PRUSS_MII_RT_RX_PCNT0/1 bits */
82#define PRUSS_MII_RT_RX_PCNT_MIN_PCNT_SHIFT 0
83#define PRUSS_MII_RT_RX_PCNT_MIN_PCNT_MASK GENMASK(3, 0)
84
85#define PRUSS_MII_RT_RX_PCNT_MAX_PCNT_SHIFT 4
86#define PRUSS_MII_RT_RX_PCNT_MAX_PCNT_MASK GENMASK(7, 4)
87
88/* PRUSS_MII_RT_RX_ERR0/1 bits */
89#define PRUSS_MII_RT_RX_ERR_MIN_PCNT_ERR BIT(0)
90#define PRUSS_MII_RT_RX_ERR_MAX_PCNT_ERR BIT(1)
91#define PRUSS_MII_RT_RX_ERR_MIN_FRM_ERR BIT(2)
92#define PRUSS_MII_RT_RX_ERR_MAX_FRM_ERR BIT(3)
93
94#define ICSSG_CFG_OFFSET 0
95#define RGMII_CFG_OFFSET 4
96
97/* Constant to choose between MII0 and MII1 */
98#define ICSS_MII0 0
99#define ICSS_MII1 1
100
101/* ICSSG_CFG Register bits */
102#define ICSSG_CFG_SGMII_MODE BIT(16)
103#define ICSSG_CFG_TX_PRU_EN BIT(11)
104#define ICSSG_CFG_RX_SFD_TX_SOF_EN BIT(10)
105#define ICSSG_CFG_RTU_PRU_PSI_SHARE_EN BIT(9)
106#define ICSSG_CFG_IEP1_TX_EN BIT(8)
107#define ICSSG_CFG_MII1_MODE GENMASK(6, 5)
108#define ICSSG_CFG_MII1_MODE_SHIFT 5
109#define ICSSG_CFG_MII0_MODE GENMASK(4, 3)
110#define ICSSG_CFG_MII0_MODE_SHIFT 3
111#define ICSSG_CFG_RX_L2_G_EN BIT(2)
112#define ICSSG_CFG_TX_L2_EN BIT(1)
113#define ICSSG_CFG_TX_L1_EN BIT(0)
114
115enum mii_mode { MII_MODE_MII = 0, MII_MODE_RGMII, MII_MODE_SGMII };
116
117/* RGMII CFG Register bits */
118#define RGMII_CFG_INBAND_EN_MII0 BIT(16)
119#define RGMII_CFG_GIG_EN_MII0 BIT(17)
120#define RGMII_CFG_INBAND_EN_MII1 BIT(20)
121#define RGMII_CFG_GIG_EN_MII1 BIT(21)
122#define RGMII_CFG_FULL_DUPLEX_MII0 BIT(18)
123#define RGMII_CFG_FULL_DUPLEX_MII1 BIT(22)
124#define RGMII_CFG_SPEED_MII0 GENMASK(2, 1)
125#define RGMII_CFG_SPEED_MII1 GENMASK(6, 5)
126#define RGMII_CFG_SPEED_MII0_SHIFT 1
127#define RGMII_CFG_SPEED_MII1_SHIFT 5
128#define RGMII_CFG_FULLDUPLEX_MII0 BIT(3)
129#define RGMII_CFG_FULLDUPLEX_MII1 BIT(7)
130#define RGMII_CFG_FULLDUPLEX_MII0_SHIFT 3
131#define RGMII_CFG_FULLDUPLEX_MII1_SHIFT 7
132#define RGMII_CFG_SPEED_10M 0
133#define RGMII_CFG_SPEED_100M 1
134#define RGMII_CFG_SPEED_1G 2
135
136static inline void icssg_mii_update_ipg(struct regmap *mii_rt, int mii, u32 ipg)
137{
138 u32 val;
139
140 if (mii == ICSS_MII0) {
141 regmap_write(mii_rt, PRUSS_MII_RT_TX_IPG0, ipg);
142 } else {
143 /* Errata workaround: IEP1 is not read by h/w unless IEP0 is written */
144 regmap_read(mii_rt, PRUSS_MII_RT_TX_IPG0, &val);
145 regmap_write(mii_rt, PRUSS_MII_RT_TX_IPG1, ipg);
146 regmap_write(mii_rt, PRUSS_MII_RT_TX_IPG0, val);
147 }
148}
149
150static inline void icssg_update_rgmii_cfg(struct regmap *miig_rt, int speed,
151 bool full_duplex, int slice, struct prueth_priv *priv)
152{
153 u32 gig_en_mask, gig_val = 0, full_duplex_mask, full_duplex_val = 0;
154 u32 inband_en_mask, inband_val = 0;
155
156 gig_en_mask = (slice == ICSS_MII0) ? RGMII_CFG_GIG_EN_MII0 :
157 RGMII_CFG_GIG_EN_MII1;
158 if (speed == SPEED_1000)
159 gig_val = gig_en_mask;
160 regmap_update_bits(miig_rt, RGMII_CFG_OFFSET, gig_en_mask, gig_val);
161
162 inband_en_mask = (slice == ICSS_MII0) ? RGMII_CFG_INBAND_EN_MII0 :
163 RGMII_CFG_INBAND_EN_MII1;
164 if (speed == SPEED_10 && phy_interface_is_rgmii(priv->phydev))
165 inband_val = inband_en_mask;
166 regmap_update_bits(miig_rt, RGMII_CFG_OFFSET, inband_en_mask, inband_val);
167
168 full_duplex_mask = (slice == ICSS_MII0) ? RGMII_CFG_FULL_DUPLEX_MII0 :
169 RGMII_CFG_FULL_DUPLEX_MII1;
170 if (full_duplex)
171 full_duplex_val = full_duplex_mask;
172 regmap_update_bits(miig_rt, RGMII_CFG_OFFSET, full_duplex_mask,
173 full_duplex_val);
174}
175
176static inline void icssg_miig_set_interface_mode(struct regmap *miig_rt, int mii, int phy_if)
177{
178 u32 val, mask, shift;
179
180 mask = mii == ICSS_MII0 ? ICSSG_CFG_MII0_MODE : ICSSG_CFG_MII1_MODE;
181 shift = mii == ICSS_MII0 ? ICSSG_CFG_MII0_MODE_SHIFT : ICSSG_CFG_MII1_MODE_SHIFT;
182
183 val = MII_MODE_RGMII;
184 if (phy_if == PHY_INTERFACE_MODE_MII)
185 val = MII_MODE_MII;
186
187 val <<= shift;
188 regmap_update_bits(miig_rt, ICSSG_CFG_OFFSET, mask, val);
189 regmap_read(miig_rt, ICSSG_CFG_OFFSET, &val);
190}
191
192#endif /* __NET_PRUSS_MII_RT_H__ */