1*c5620aeeSHoratiu Vultur // SPDX-License-Identifier: (GPL-2.0+ OR MIT)
2*c5620aeeSHoratiu Vultur /*
3*c5620aeeSHoratiu Vultur * Copyright (c) 2019 Microsemi Corporation
4*c5620aeeSHoratiu Vultur */
5*c5620aeeSHoratiu Vultur
6*c5620aeeSHoratiu Vultur #include <common.h>
7*c5620aeeSHoratiu Vultur #include <config.h>
8*c5620aeeSHoratiu Vultur #include <dm.h>
9*c5620aeeSHoratiu Vultur #include <dm/of_access.h>
10*c5620aeeSHoratiu Vultur #include <dm/of_addr.h>
11*c5620aeeSHoratiu Vultur #include <fdt_support.h>
12*c5620aeeSHoratiu Vultur #include <linux/io.h>
13*c5620aeeSHoratiu Vultur #include <linux/ioport.h>
14*c5620aeeSHoratiu Vultur #include <miiphy.h>
15*c5620aeeSHoratiu Vultur #include <net.h>
16*c5620aeeSHoratiu Vultur #include <wait_bit.h>
17*c5620aeeSHoratiu Vultur
18*c5620aeeSHoratiu Vultur #include "mscc_miim.h"
19*c5620aeeSHoratiu Vultur #include "mscc_xfer.h"
20*c5620aeeSHoratiu Vultur #include "mscc_mac_table.h"
21*c5620aeeSHoratiu Vultur
22*c5620aeeSHoratiu Vultur #define ANA_PORT_VLAN_CFG(x) (0x00 + 0x80 * (x))
23*c5620aeeSHoratiu Vultur #define ANA_PORT_VLAN_CFG_AWARE_ENA BIT(20)
24*c5620aeeSHoratiu Vultur #define ANA_PORT_VLAN_CFG_POP_CNT(x) ((x) << 18)
25*c5620aeeSHoratiu Vultur #define ANA_PORT_CPU_FWD_CFG(x) (0x50 + 0x80 * (x))
26*c5620aeeSHoratiu Vultur #define ANA_PORT_CPU_FWD_CFG_SRC_COPY_ENA BIT(1)
27*c5620aeeSHoratiu Vultur #define ANA_PORT_PORT_CFG(x) (0x60 + 0x80 * (x))
28*c5620aeeSHoratiu Vultur #define ANA_PORT_PORT_CFG_RECV_ENA BIT(5)
29*c5620aeeSHoratiu Vultur #define ANA_PGID(x) (0x1000 + 4 * (x))
30*c5620aeeSHoratiu Vultur
31*c5620aeeSHoratiu Vultur #define SYS_FRM_AGING 0x8300
32*c5620aeeSHoratiu Vultur
33*c5620aeeSHoratiu Vultur #define SYS_SYSTEM_RST_CFG 0x81b0
34*c5620aeeSHoratiu Vultur #define SYS_SYSTEM_RST_MEM_INIT BIT(0)
35*c5620aeeSHoratiu Vultur #define SYS_SYSTEM_RST_MEM_ENA BIT(1)
36*c5620aeeSHoratiu Vultur #define SYS_SYSTEM_RST_CORE_ENA BIT(2)
37*c5620aeeSHoratiu Vultur #define SYS_PORT_MODE(x) (0x81bc + 0x4 * (x))
38*c5620aeeSHoratiu Vultur #define SYS_PORT_MODE_INCL_INJ_HDR BIT(0)
39*c5620aeeSHoratiu Vultur #define SYS_SWITCH_PORT_MODE(x) (0x8294 + 0x4 * (x))
40*c5620aeeSHoratiu Vultur #define SYS_SWITCH_PORT_MODE_PORT_ENA BIT(3)
41*c5620aeeSHoratiu Vultur #define SYS_EGR_NO_SHARING 0x8378
42*c5620aeeSHoratiu Vultur #define SYS_SCH_CPU 0x85a0
43*c5620aeeSHoratiu Vultur
44*c5620aeeSHoratiu Vultur #define REW_PORT_CFG(x) (0x8 + 0x80 * (x))
45*c5620aeeSHoratiu Vultur #define REW_PORT_CFG_IFH_INSERT_ENA BIT(7)
46*c5620aeeSHoratiu Vultur
47*c5620aeeSHoratiu Vultur #define GCB_DEVCPU_RST_SOFT_CHIP_RST 0x90
48*c5620aeeSHoratiu Vultur #define GCB_DEVCPU_RST_SOFT_CHIP_RST_SOFT_PHY BIT(1)
49*c5620aeeSHoratiu Vultur #define GCB_MISC_STAT 0x11c
50*c5620aeeSHoratiu Vultur #define GCB_MISC_STAT_PHY_READY BIT(3)
51*c5620aeeSHoratiu Vultur
52*c5620aeeSHoratiu Vultur #define QS_XTR_MAP(x) (0x10 + 4 * (x))
53*c5620aeeSHoratiu Vultur #define QS_XTR_MAP_GRP BIT(4)
54*c5620aeeSHoratiu Vultur #define QS_XTR_MAP_ENA BIT(0)
55*c5620aeeSHoratiu Vultur
56*c5620aeeSHoratiu Vultur #define HSIO_PLL5G_CFG_PLL5G_CFG2 0x8
57*c5620aeeSHoratiu Vultur
58*c5620aeeSHoratiu Vultur #define HSIO_RCOMP_CFG_CFG0 0x20
59*c5620aeeSHoratiu Vultur #define HSIO_RCOMP_CFG_CFG0_MODE_SEL(x) ((x) << 8)
60*c5620aeeSHoratiu Vultur #define HSIO_RCOMP_CFG_CFG0_RUN_CAL BIT(12)
61*c5620aeeSHoratiu Vultur #define HSIO_RCOMP_STATUS 0x24
62*c5620aeeSHoratiu Vultur #define HSIO_RCOMP_STATUS_BUSY BIT(12)
63*c5620aeeSHoratiu Vultur #define HSIO_RCOMP_STATUS_RCOMP_M GENMASK(3, 0)
64*c5620aeeSHoratiu Vultur #define HSIO_SERDES6G_ANA_CFG_DES_CFG 0x64
65*c5620aeeSHoratiu Vultur #define HSIO_SERDES6G_ANA_CFG_DES_CFG_BW_ANA(x) ((x) << 1)
66*c5620aeeSHoratiu Vultur #define HSIO_SERDES6G_ANA_CFG_DES_CFG_BW_HYST(x) ((x) << 5)
67*c5620aeeSHoratiu Vultur #define HSIO_SERDES6G_ANA_CFG_DES_CFG_MBTR_CTRL(x) ((x) << 10)
68*c5620aeeSHoratiu Vultur #define HSIO_SERDES6G_ANA_CFG_DES_CFG_PHS_CTRL(x) ((x) << 13)
69*c5620aeeSHoratiu Vultur #define HSIO_SERDES6G_ANA_CFG_IB_CFG 0x68
70*c5620aeeSHoratiu Vultur #define HSIO_SERDES6G_ANA_CFG_IB_CFG_RESISTOR_CTRL(x) (x)
71*c5620aeeSHoratiu Vultur #define HSIO_SERDES6G_ANA_CFG_IB_CFG_VBCOM(x) ((x) << 4)
72*c5620aeeSHoratiu Vultur #define HSIO_SERDES6G_ANA_CFG_IB_CFG_VBAC(x) ((x) << 7)
73*c5620aeeSHoratiu Vultur #define HSIO_SERDES6G_ANA_CFG_IB_CFG_RT(x) ((x) << 9)
74*c5620aeeSHoratiu Vultur #define HSIO_SERDES6G_ANA_CFG_IB_CFG_RF(x) ((x) << 14)
75*c5620aeeSHoratiu Vultur #define HSIO_SERDES6G_ANA_CFG_IB_CFG1 0x6c
76*c5620aeeSHoratiu Vultur #define HSIO_SERDES6G_ANA_CFG_IB_CFG1_RST BIT(0)
77*c5620aeeSHoratiu Vultur #define HSIO_SERDES6G_ANA_CFG_IB_CFG1_ENA_OFFSDC BIT(2)
78*c5620aeeSHoratiu Vultur #define HSIO_SERDES6G_ANA_CFG_IB_CFG1_ENA_OFFSAC BIT(3)
79*c5620aeeSHoratiu Vultur #define HSIO_SERDES6G_ANA_CFG_IB_CFG1_ANEG_MODE BIT(6)
80*c5620aeeSHoratiu Vultur #define HSIO_SERDES6G_ANA_CFG_IB_CFG1_CHF BIT(7)
81*c5620aeeSHoratiu Vultur #define HSIO_SERDES6G_ANA_CFG_IB_CFG1_C(x) ((x) << 8)
82*c5620aeeSHoratiu Vultur #define HSIO_SERDES6G_ANA_CFG_OB_CFG 0x70
83*c5620aeeSHoratiu Vultur #define HSIO_SERDES6G_ANA_CFG_OB_CFG_SR(x) ((x) << 4)
84*c5620aeeSHoratiu Vultur #define HSIO_SERDES6G_ANA_CFG_OB_CFG_SR_H BIT(8)
85*c5620aeeSHoratiu Vultur #define HSIO_SERDES6G_ANA_CFG_OB_CFG_POST0(x) ((x) << 23)
86*c5620aeeSHoratiu Vultur #define HSIO_SERDES6G_ANA_CFG_OB_CFG_POL BIT(29)
87*c5620aeeSHoratiu Vultur #define HSIO_SERDES6G_ANA_CFG_OB_CFG_ENA1V_MODE BIT(30)
88*c5620aeeSHoratiu Vultur #define HSIO_SERDES6G_ANA_CFG_OB_CFG1 0x74
89*c5620aeeSHoratiu Vultur #define HSIO_SERDES6G_ANA_CFG_OB_CFG1_LEV(x) (x)
90*c5620aeeSHoratiu Vultur #define HSIO_SERDES6G_ANA_CFG_OB_CFG1_ENA_CAS(x) ((x) << 6)
91*c5620aeeSHoratiu Vultur #define HSIO_SERDES6G_ANA_CFG_COMMON_CFG 0x7c
92*c5620aeeSHoratiu Vultur #define HSIO_SERDES6G_ANA_CFG_COMMON_CFG_IF_MODE(x) (x)
93*c5620aeeSHoratiu Vultur #define HSIO_SERDES6G_ANA_CFG_COMMON_CFG_ENA_LANE BIT(18)
94*c5620aeeSHoratiu Vultur #define HSIO_SERDES6G_ANA_CFG_COMMON_CFG_SYS_RST BIT(31)
95*c5620aeeSHoratiu Vultur #define HSIO_SERDES6G_ANA_CFG_PLL_CFG 0x80
96*c5620aeeSHoratiu Vultur #define HSIO_SERDES6G_ANA_CFG_PLL_CFG_FSM_ENA BIT(7)
97*c5620aeeSHoratiu Vultur #define HSIO_SERDES6G_ANA_CFG_PLL_CFG_FSM_CTRL_DATA(x) ((x) << 8)
98*c5620aeeSHoratiu Vultur #define HSIO_SERDES6G_ANA_CFG_SER_CFG 0x84
99*c5620aeeSHoratiu Vultur #define HSIO_SERDES6G_DIG_CFG_MISC_CFG 0x88
100*c5620aeeSHoratiu Vultur #define HSIO_SERDES6G_DIG_CFG_MISC_CFG_LANE_RST BIT(0)
101*c5620aeeSHoratiu Vultur #define HSIO_MCB_SERDES6G_CFG 0xac
102*c5620aeeSHoratiu Vultur #define HSIO_MCB_SERDES6G_CFG_WR_ONE_SHOT BIT(31)
103*c5620aeeSHoratiu Vultur #define HSIO_MCB_SERDES6G_CFG_ADDR(x) (x)
104*c5620aeeSHoratiu Vultur
105*c5620aeeSHoratiu Vultur #define DEV_GMII_PORT_MODE_CLK 0x0
106*c5620aeeSHoratiu Vultur #define DEV_GMII_PORT_MODE_CLK_PHY_RST BIT(0)
107*c5620aeeSHoratiu Vultur #define DEV_GMII_MAC_CFG_MAC_ENA 0xc
108*c5620aeeSHoratiu Vultur #define DEV_GMII_MAC_CFG_MAC_ENA_RX_ENA BIT(4)
109*c5620aeeSHoratiu Vultur #define DEV_GMII_MAC_CFG_MAC_ENA_TX_ENA BIT(0)
110*c5620aeeSHoratiu Vultur
111*c5620aeeSHoratiu Vultur #define DEV_PORT_MODE_CLK 0x4
112*c5620aeeSHoratiu Vultur #define DEV_PORT_MODE_CLK_PHY_RST BIT(2)
113*c5620aeeSHoratiu Vultur #define DEV_PORT_MODE_CLK_LINK_SPEED_1000 1
114*c5620aeeSHoratiu Vultur #define DEV_MAC_CFG_MAC_ENA 0x10
115*c5620aeeSHoratiu Vultur #define DEV_MAC_CFG_MAC_ENA_RX_ENA BIT(4)
116*c5620aeeSHoratiu Vultur #define DEV_MAC_CFG_MAC_ENA_TX_ENA BIT(0)
117*c5620aeeSHoratiu Vultur #define DEV_MAC_CFG_MAC_IFG 0x24
118*c5620aeeSHoratiu Vultur #define DEV_MAC_CFG_MAC_IFG_TX_IFG(x) ((x) << 8)
119*c5620aeeSHoratiu Vultur #define DEV_MAC_CFG_MAC_IFG_RX_IFG2(x) ((x) << 4)
120*c5620aeeSHoratiu Vultur #define DEV_MAC_CFG_MAC_IFG_RX_IFG1(x) (x)
121*c5620aeeSHoratiu Vultur #define DEV_PCS1G_CFG_PCS1G_CFG 0x40
122*c5620aeeSHoratiu Vultur #define DEV_PCS1G_CFG_PCS1G_CFG_PCS_ENA BIT(0)
123*c5620aeeSHoratiu Vultur #define DEV_PCS1G_CFG_PCS1G_MODE 0x44
124*c5620aeeSHoratiu Vultur #define DEV_PCS1G_CFG_PCS1G_SD 0x48
125*c5620aeeSHoratiu Vultur #define DEV_PCS1G_CFG_PCS1G_ANEG 0x4c
126*c5620aeeSHoratiu Vultur #define DEV_PCS1G_CFG_PCS1G_ANEG_ADV_ABILITY(x) ((x) << 16)
127*c5620aeeSHoratiu Vultur
128*c5620aeeSHoratiu Vultur #define IFH_INJ_BYPASS BIT(31)
129*c5620aeeSHoratiu Vultur #define IFH_TAG_TYPE_C 0
130*c5620aeeSHoratiu Vultur #define MAC_VID 1
131*c5620aeeSHoratiu Vultur #define CPU_PORT 26
132*c5620aeeSHoratiu Vultur #define INTERNAL_PORT_MSK 0xFFFFFF
133*c5620aeeSHoratiu Vultur #define IFH_LEN 2
134*c5620aeeSHoratiu Vultur #define ETH_ALEN 6
135*c5620aeeSHoratiu Vultur #define PGID_BROADCAST 28
136*c5620aeeSHoratiu Vultur #define PGID_UNICAST 29
137*c5620aeeSHoratiu Vultur #define PGID_SRC 80
138*c5620aeeSHoratiu Vultur
139*c5620aeeSHoratiu Vultur enum luton_target {
140*c5620aeeSHoratiu Vultur PORT0,
141*c5620aeeSHoratiu Vultur PORT1,
142*c5620aeeSHoratiu Vultur PORT2,
143*c5620aeeSHoratiu Vultur PORT3,
144*c5620aeeSHoratiu Vultur PORT4,
145*c5620aeeSHoratiu Vultur PORT5,
146*c5620aeeSHoratiu Vultur PORT6,
147*c5620aeeSHoratiu Vultur PORT7,
148*c5620aeeSHoratiu Vultur PORT8,
149*c5620aeeSHoratiu Vultur PORT9,
150*c5620aeeSHoratiu Vultur PORT10,
151*c5620aeeSHoratiu Vultur PORT11,
152*c5620aeeSHoratiu Vultur PORT12,
153*c5620aeeSHoratiu Vultur PORT13,
154*c5620aeeSHoratiu Vultur PORT14,
155*c5620aeeSHoratiu Vultur PORT15,
156*c5620aeeSHoratiu Vultur PORT16,
157*c5620aeeSHoratiu Vultur PORT17,
158*c5620aeeSHoratiu Vultur PORT18,
159*c5620aeeSHoratiu Vultur PORT19,
160*c5620aeeSHoratiu Vultur PORT20,
161*c5620aeeSHoratiu Vultur PORT21,
162*c5620aeeSHoratiu Vultur PORT22,
163*c5620aeeSHoratiu Vultur PORT23,
164*c5620aeeSHoratiu Vultur SYS,
165*c5620aeeSHoratiu Vultur ANA,
166*c5620aeeSHoratiu Vultur REW,
167*c5620aeeSHoratiu Vultur GCB,
168*c5620aeeSHoratiu Vultur QS,
169*c5620aeeSHoratiu Vultur HSIO,
170*c5620aeeSHoratiu Vultur TARGET_MAX,
171*c5620aeeSHoratiu Vultur };
172*c5620aeeSHoratiu Vultur
173*c5620aeeSHoratiu Vultur #define MAX_PORT (PORT23 - PORT0 + 1)
174*c5620aeeSHoratiu Vultur
175*c5620aeeSHoratiu Vultur #define MIN_INT_PORT PORT0
176*c5620aeeSHoratiu Vultur #define MAX_INT_PORT (PORT11 - PORT0 + 1)
177*c5620aeeSHoratiu Vultur #define MIN_EXT_PORT PORT12
178*c5620aeeSHoratiu Vultur #define MAX_EXT_PORT MAX_PORT
179*c5620aeeSHoratiu Vultur
180*c5620aeeSHoratiu Vultur enum luton_mdio_target {
181*c5620aeeSHoratiu Vultur MIIM,
182*c5620aeeSHoratiu Vultur TARGET_MDIO_MAX,
183*c5620aeeSHoratiu Vultur };
184*c5620aeeSHoratiu Vultur
185*c5620aeeSHoratiu Vultur enum luton_phy_id {
186*c5620aeeSHoratiu Vultur INTERNAL,
187*c5620aeeSHoratiu Vultur EXTERNAL,
188*c5620aeeSHoratiu Vultur NUM_PHY,
189*c5620aeeSHoratiu Vultur };
190*c5620aeeSHoratiu Vultur
191*c5620aeeSHoratiu Vultur struct luton_private {
192*c5620aeeSHoratiu Vultur void __iomem *regs[TARGET_MAX];
193*c5620aeeSHoratiu Vultur struct mii_dev *bus[NUM_PHY];
194*c5620aeeSHoratiu Vultur };
195*c5620aeeSHoratiu Vultur
196*c5620aeeSHoratiu Vultur static const unsigned long luton_regs_qs[] = {
197*c5620aeeSHoratiu Vultur [MSCC_QS_XTR_RD] = 0x18,
198*c5620aeeSHoratiu Vultur [MSCC_QS_XTR_FLUSH] = 0x28,
199*c5620aeeSHoratiu Vultur [MSCC_QS_XTR_DATA_PRESENT] = 0x2c,
200*c5620aeeSHoratiu Vultur [MSCC_QS_INJ_WR] = 0x3c,
201*c5620aeeSHoratiu Vultur [MSCC_QS_INJ_CTRL] = 0x44,
202*c5620aeeSHoratiu Vultur };
203*c5620aeeSHoratiu Vultur
204*c5620aeeSHoratiu Vultur static const unsigned long luton_regs_ana_table[] = {
205*c5620aeeSHoratiu Vultur [MSCC_ANA_TABLES_MACHDATA] = 0x11b0,
206*c5620aeeSHoratiu Vultur [MSCC_ANA_TABLES_MACLDATA] = 0x11b4,
207*c5620aeeSHoratiu Vultur [MSCC_ANA_TABLES_MACACCESS] = 0x11b8,
208*c5620aeeSHoratiu Vultur };
209*c5620aeeSHoratiu Vultur
210*c5620aeeSHoratiu Vultur static struct mscc_miim_dev miim[NUM_PHY];
211*c5620aeeSHoratiu Vultur
luton_mdiobus_init(struct udevice * dev,int mdiobus_id)212*c5620aeeSHoratiu Vultur static struct mii_dev *luton_mdiobus_init(struct udevice *dev,
213*c5620aeeSHoratiu Vultur int mdiobus_id)
214*c5620aeeSHoratiu Vultur {
215*c5620aeeSHoratiu Vultur unsigned long phy_size[NUM_PHY];
216*c5620aeeSHoratiu Vultur phys_addr_t phy_base[NUM_PHY];
217*c5620aeeSHoratiu Vultur struct ofnode_phandle_args phandle;
218*c5620aeeSHoratiu Vultur ofnode eth_node, node, mdio_node;
219*c5620aeeSHoratiu Vultur struct resource res;
220*c5620aeeSHoratiu Vultur struct mii_dev *bus;
221*c5620aeeSHoratiu Vultur fdt32_t faddr;
222*c5620aeeSHoratiu Vultur int i;
223*c5620aeeSHoratiu Vultur
224*c5620aeeSHoratiu Vultur bus = mdio_alloc();
225*c5620aeeSHoratiu Vultur if (!bus)
226*c5620aeeSHoratiu Vultur return NULL;
227*c5620aeeSHoratiu Vultur
228*c5620aeeSHoratiu Vultur /* gather only the first mdio bus */
229*c5620aeeSHoratiu Vultur eth_node = dev_read_first_subnode(dev);
230*c5620aeeSHoratiu Vultur node = ofnode_first_subnode(eth_node);
231*c5620aeeSHoratiu Vultur ofnode_parse_phandle_with_args(node, "phy-handle", NULL, 0, 0,
232*c5620aeeSHoratiu Vultur &phandle);
233*c5620aeeSHoratiu Vultur mdio_node = ofnode_get_parent(phandle.node);
234*c5620aeeSHoratiu Vultur
235*c5620aeeSHoratiu Vultur for (i = 0; i < TARGET_MDIO_MAX; i++) {
236*c5620aeeSHoratiu Vultur if (ofnode_read_resource(mdio_node, i, &res)) {
237*c5620aeeSHoratiu Vultur pr_err("%s: get OF resource failed\n", __func__);
238*c5620aeeSHoratiu Vultur return NULL;
239*c5620aeeSHoratiu Vultur }
240*c5620aeeSHoratiu Vultur
241*c5620aeeSHoratiu Vultur faddr = cpu_to_fdt32(res.start);
242*c5620aeeSHoratiu Vultur phy_base[i] = ofnode_translate_address(mdio_node, &faddr);
243*c5620aeeSHoratiu Vultur phy_size[i] = res.end - res.start;
244*c5620aeeSHoratiu Vultur }
245*c5620aeeSHoratiu Vultur
246*c5620aeeSHoratiu Vultur strcpy(bus->name, "miim-internal");
247*c5620aeeSHoratiu Vultur miim[mdiobus_id].regs = ioremap(phy_base[mdiobus_id],
248*c5620aeeSHoratiu Vultur phy_size[mdiobus_id]);
249*c5620aeeSHoratiu Vultur bus->priv = &miim[mdiobus_id];
250*c5620aeeSHoratiu Vultur bus->read = mscc_miim_read;
251*c5620aeeSHoratiu Vultur bus->write = mscc_miim_write;
252*c5620aeeSHoratiu Vultur
253*c5620aeeSHoratiu Vultur if (mdio_register(bus))
254*c5620aeeSHoratiu Vultur return NULL;
255*c5620aeeSHoratiu Vultur else
256*c5620aeeSHoratiu Vultur return bus;
257*c5620aeeSHoratiu Vultur }
258*c5620aeeSHoratiu Vultur
luton_stop(struct udevice * dev)259*c5620aeeSHoratiu Vultur static void luton_stop(struct udevice *dev)
260*c5620aeeSHoratiu Vultur {
261*c5620aeeSHoratiu Vultur struct luton_private *priv = dev_get_priv(dev);
262*c5620aeeSHoratiu Vultur
263*c5620aeeSHoratiu Vultur /*
264*c5620aeeSHoratiu Vultur * Switch core only reset affects VCORE-III bus and MIPS frequency
265*c5620aeeSHoratiu Vultur * and thereby also the DDR SDRAM controller. The workaround is to
266*c5620aeeSHoratiu Vultur * not to redirect any trafic to the CPU after the data transfer.
267*c5620aeeSHoratiu Vultur */
268*c5620aeeSHoratiu Vultur writel(GENMASK(9, 2), priv->regs[SYS] + SYS_SCH_CPU);
269*c5620aeeSHoratiu Vultur }
270*c5620aeeSHoratiu Vultur
luton_cpu_capture_setup(struct luton_private * priv)271*c5620aeeSHoratiu Vultur static void luton_cpu_capture_setup(struct luton_private *priv)
272*c5620aeeSHoratiu Vultur {
273*c5620aeeSHoratiu Vultur int i;
274*c5620aeeSHoratiu Vultur
275*c5620aeeSHoratiu Vultur /* map the 8 CPU extraction queues to CPU port 26 */
276*c5620aeeSHoratiu Vultur writel(0x0, priv->regs[SYS] + SYS_SCH_CPU);
277*c5620aeeSHoratiu Vultur
278*c5620aeeSHoratiu Vultur for (i = 0; i <= 1; i++) {
279*c5620aeeSHoratiu Vultur /*
280*c5620aeeSHoratiu Vultur * One to one mapping from CPU Queue number to Group extraction
281*c5620aeeSHoratiu Vultur * number
282*c5620aeeSHoratiu Vultur */
283*c5620aeeSHoratiu Vultur writel(QS_XTR_MAP_ENA | (QS_XTR_MAP_GRP * i),
284*c5620aeeSHoratiu Vultur priv->regs[QS] + QS_XTR_MAP(i));
285*c5620aeeSHoratiu Vultur
286*c5620aeeSHoratiu Vultur /* Enable IFH insertion/parsing on CPU ports */
287*c5620aeeSHoratiu Vultur setbits_le32(priv->regs[REW] + REW_PORT_CFG(CPU_PORT + i),
288*c5620aeeSHoratiu Vultur REW_PORT_CFG_IFH_INSERT_ENA);
289*c5620aeeSHoratiu Vultur
290*c5620aeeSHoratiu Vultur /* Enable IFH parsing on CPU port 0 and 1 */
291*c5620aeeSHoratiu Vultur setbits_le32(priv->regs[SYS] + SYS_PORT_MODE(CPU_PORT + i),
292*c5620aeeSHoratiu Vultur SYS_PORT_MODE_INCL_INJ_HDR);
293*c5620aeeSHoratiu Vultur }
294*c5620aeeSHoratiu Vultur
295*c5620aeeSHoratiu Vultur /* Make VLAN aware for CPU traffic */
296*c5620aeeSHoratiu Vultur writel(ANA_PORT_VLAN_CFG_AWARE_ENA |
297*c5620aeeSHoratiu Vultur ANA_PORT_VLAN_CFG_POP_CNT(1) |
298*c5620aeeSHoratiu Vultur MAC_VID,
299*c5620aeeSHoratiu Vultur priv->regs[ANA] + ANA_PORT_VLAN_CFG(CPU_PORT));
300*c5620aeeSHoratiu Vultur
301*c5620aeeSHoratiu Vultur /* Disable learning (only RECV_ENA must be set) */
302*c5620aeeSHoratiu Vultur writel(ANA_PORT_PORT_CFG_RECV_ENA,
303*c5620aeeSHoratiu Vultur priv->regs[ANA] + ANA_PORT_PORT_CFG(CPU_PORT));
304*c5620aeeSHoratiu Vultur
305*c5620aeeSHoratiu Vultur /* Enable switching to/from cpu port */
306*c5620aeeSHoratiu Vultur setbits_le32(priv->regs[SYS] + SYS_SWITCH_PORT_MODE(CPU_PORT),
307*c5620aeeSHoratiu Vultur SYS_SWITCH_PORT_MODE_PORT_ENA);
308*c5620aeeSHoratiu Vultur
309*c5620aeeSHoratiu Vultur setbits_le32(priv->regs[SYS] + SYS_EGR_NO_SHARING, BIT(CPU_PORT));
310*c5620aeeSHoratiu Vultur }
311*c5620aeeSHoratiu Vultur
luton_gmii_port_init(struct luton_private * priv,int port)312*c5620aeeSHoratiu Vultur static void luton_gmii_port_init(struct luton_private *priv, int port)
313*c5620aeeSHoratiu Vultur {
314*c5620aeeSHoratiu Vultur void __iomem *regs = priv->regs[port];
315*c5620aeeSHoratiu Vultur
316*c5620aeeSHoratiu Vultur writel(0, regs + DEV_GMII_PORT_MODE_CLK);
317*c5620aeeSHoratiu Vultur
318*c5620aeeSHoratiu Vultur /* Enable MAC RX and TX */
319*c5620aeeSHoratiu Vultur writel(DEV_GMII_MAC_CFG_MAC_ENA_RX_ENA |
320*c5620aeeSHoratiu Vultur DEV_GMII_MAC_CFG_MAC_ENA_TX_ENA,
321*c5620aeeSHoratiu Vultur regs + DEV_GMII_MAC_CFG_MAC_ENA);
322*c5620aeeSHoratiu Vultur
323*c5620aeeSHoratiu Vultur /* Make VLAN aware for CPU traffic */
324*c5620aeeSHoratiu Vultur writel(ANA_PORT_VLAN_CFG_AWARE_ENA |
325*c5620aeeSHoratiu Vultur ANA_PORT_VLAN_CFG_POP_CNT(1) |
326*c5620aeeSHoratiu Vultur MAC_VID,
327*c5620aeeSHoratiu Vultur priv->regs[ANA] + ANA_PORT_VLAN_CFG(port - PORT0));
328*c5620aeeSHoratiu Vultur
329*c5620aeeSHoratiu Vultur /* Enable switching to/from port */
330*c5620aeeSHoratiu Vultur setbits_le32(priv->regs[SYS] + SYS_SWITCH_PORT_MODE(port - PORT0),
331*c5620aeeSHoratiu Vultur SYS_SWITCH_PORT_MODE_PORT_ENA);
332*c5620aeeSHoratiu Vultur }
333*c5620aeeSHoratiu Vultur
luton_port_init(struct luton_private * priv,int port)334*c5620aeeSHoratiu Vultur static void luton_port_init(struct luton_private *priv, int port)
335*c5620aeeSHoratiu Vultur {
336*c5620aeeSHoratiu Vultur void __iomem *regs = priv->regs[port];
337*c5620aeeSHoratiu Vultur
338*c5620aeeSHoratiu Vultur writel(0, regs + DEV_PORT_MODE_CLK);
339*c5620aeeSHoratiu Vultur
340*c5620aeeSHoratiu Vultur /* Enable MAC RX and TX */
341*c5620aeeSHoratiu Vultur writel(DEV_MAC_CFG_MAC_ENA_RX_ENA |
342*c5620aeeSHoratiu Vultur DEV_MAC_CFG_MAC_ENA_TX_ENA,
343*c5620aeeSHoratiu Vultur regs + DEV_MAC_CFG_MAC_ENA);
344*c5620aeeSHoratiu Vultur
345*c5620aeeSHoratiu Vultur /* Make VLAN aware for CPU traffic */
346*c5620aeeSHoratiu Vultur writel(ANA_PORT_VLAN_CFG_AWARE_ENA |
347*c5620aeeSHoratiu Vultur ANA_PORT_VLAN_CFG_POP_CNT(1) |
348*c5620aeeSHoratiu Vultur MAC_VID,
349*c5620aeeSHoratiu Vultur priv->regs[ANA] + ANA_PORT_VLAN_CFG(port - PORT0));
350*c5620aeeSHoratiu Vultur
351*c5620aeeSHoratiu Vultur /* Enable switching to/from port */
352*c5620aeeSHoratiu Vultur setbits_le32(priv->regs[SYS] + SYS_SWITCH_PORT_MODE(port - PORT0),
353*c5620aeeSHoratiu Vultur SYS_SWITCH_PORT_MODE_PORT_ENA);
354*c5620aeeSHoratiu Vultur }
355*c5620aeeSHoratiu Vultur
luton_ext_port_init(struct luton_private * priv,int port)356*c5620aeeSHoratiu Vultur static void luton_ext_port_init(struct luton_private *priv, int port)
357*c5620aeeSHoratiu Vultur {
358*c5620aeeSHoratiu Vultur void __iomem *regs = priv->regs[port];
359*c5620aeeSHoratiu Vultur
360*c5620aeeSHoratiu Vultur /* Enable PCS */
361*c5620aeeSHoratiu Vultur writel(DEV_PCS1G_CFG_PCS1G_CFG_PCS_ENA,
362*c5620aeeSHoratiu Vultur regs + DEV_PCS1G_CFG_PCS1G_CFG);
363*c5620aeeSHoratiu Vultur
364*c5620aeeSHoratiu Vultur /* Disable Signal Detect */
365*c5620aeeSHoratiu Vultur writel(0, regs + DEV_PCS1G_CFG_PCS1G_SD);
366*c5620aeeSHoratiu Vultur
367*c5620aeeSHoratiu Vultur /* Enable MAC RX and TX */
368*c5620aeeSHoratiu Vultur writel(DEV_MAC_CFG_MAC_ENA_RX_ENA |
369*c5620aeeSHoratiu Vultur DEV_MAC_CFG_MAC_ENA_TX_ENA,
370*c5620aeeSHoratiu Vultur regs + DEV_MAC_CFG_MAC_ENA);
371*c5620aeeSHoratiu Vultur
372*c5620aeeSHoratiu Vultur /* Clear sgmii_mode_ena */
373*c5620aeeSHoratiu Vultur writel(0, regs + DEV_PCS1G_CFG_PCS1G_MODE);
374*c5620aeeSHoratiu Vultur
375*c5620aeeSHoratiu Vultur /*
376*c5620aeeSHoratiu Vultur * Clear sw_resolve_ena(bit 0) and set adv_ability to
377*c5620aeeSHoratiu Vultur * something meaningful just in case
378*c5620aeeSHoratiu Vultur */
379*c5620aeeSHoratiu Vultur writel(DEV_PCS1G_CFG_PCS1G_ANEG_ADV_ABILITY(0x20),
380*c5620aeeSHoratiu Vultur regs + DEV_PCS1G_CFG_PCS1G_ANEG);
381*c5620aeeSHoratiu Vultur
382*c5620aeeSHoratiu Vultur /* Set MAC IFG Gaps */
383*c5620aeeSHoratiu Vultur writel(DEV_MAC_CFG_MAC_IFG_TX_IFG(7) |
384*c5620aeeSHoratiu Vultur DEV_MAC_CFG_MAC_IFG_RX_IFG1(1) |
385*c5620aeeSHoratiu Vultur DEV_MAC_CFG_MAC_IFG_RX_IFG2(5),
386*c5620aeeSHoratiu Vultur regs + DEV_MAC_CFG_MAC_IFG);
387*c5620aeeSHoratiu Vultur
388*c5620aeeSHoratiu Vultur /* Set link speed and release all resets */
389*c5620aeeSHoratiu Vultur writel(DEV_PORT_MODE_CLK_LINK_SPEED_1000,
390*c5620aeeSHoratiu Vultur regs + DEV_PORT_MODE_CLK);
391*c5620aeeSHoratiu Vultur
392*c5620aeeSHoratiu Vultur /* Make VLAN aware for CPU traffic */
393*c5620aeeSHoratiu Vultur writel(ANA_PORT_VLAN_CFG_AWARE_ENA |
394*c5620aeeSHoratiu Vultur ANA_PORT_VLAN_CFG_POP_CNT(1) |
395*c5620aeeSHoratiu Vultur MAC_VID,
396*c5620aeeSHoratiu Vultur priv->regs[ANA] + ANA_PORT_VLAN_CFG(port - PORT0));
397*c5620aeeSHoratiu Vultur
398*c5620aeeSHoratiu Vultur /* Enable switching to/from port */
399*c5620aeeSHoratiu Vultur setbits_le32(priv->regs[SYS] + SYS_SWITCH_PORT_MODE(port - PORT0),
400*c5620aeeSHoratiu Vultur SYS_SWITCH_PORT_MODE_PORT_ENA);
401*c5620aeeSHoratiu Vultur }
402*c5620aeeSHoratiu Vultur
serdes6g_write(struct luton_private * priv,u32 addr)403*c5620aeeSHoratiu Vultur static void serdes6g_write(struct luton_private *priv, u32 addr)
404*c5620aeeSHoratiu Vultur {
405*c5620aeeSHoratiu Vultur u32 data;
406*c5620aeeSHoratiu Vultur
407*c5620aeeSHoratiu Vultur writel(HSIO_MCB_SERDES6G_CFG_WR_ONE_SHOT |
408*c5620aeeSHoratiu Vultur HSIO_MCB_SERDES6G_CFG_ADDR(addr),
409*c5620aeeSHoratiu Vultur priv->regs[HSIO] + HSIO_MCB_SERDES6G_CFG);
410*c5620aeeSHoratiu Vultur
411*c5620aeeSHoratiu Vultur do {
412*c5620aeeSHoratiu Vultur data = readl(priv->regs[HSIO] + HSIO_MCB_SERDES6G_CFG);
413*c5620aeeSHoratiu Vultur } while (data & HSIO_MCB_SERDES6G_CFG_WR_ONE_SHOT);
414*c5620aeeSHoratiu Vultur
415*c5620aeeSHoratiu Vultur mdelay(100);
416*c5620aeeSHoratiu Vultur }
417*c5620aeeSHoratiu Vultur
serdes6g_cfg(struct luton_private * priv)418*c5620aeeSHoratiu Vultur static void serdes6g_cfg(struct luton_private *priv)
419*c5620aeeSHoratiu Vultur {
420*c5620aeeSHoratiu Vultur writel(HSIO_RCOMP_CFG_CFG0_MODE_SEL(0x3) |
421*c5620aeeSHoratiu Vultur HSIO_RCOMP_CFG_CFG0_RUN_CAL,
422*c5620aeeSHoratiu Vultur priv->regs[HSIO] + HSIO_RCOMP_CFG_CFG0);
423*c5620aeeSHoratiu Vultur
424*c5620aeeSHoratiu Vultur while (readl(priv->regs[HSIO] + HSIO_RCOMP_STATUS) &
425*c5620aeeSHoratiu Vultur HSIO_RCOMP_STATUS_BUSY)
426*c5620aeeSHoratiu Vultur ;
427*c5620aeeSHoratiu Vultur
428*c5620aeeSHoratiu Vultur writel(HSIO_SERDES6G_ANA_CFG_OB_CFG_SR(0xb) |
429*c5620aeeSHoratiu Vultur HSIO_SERDES6G_ANA_CFG_OB_CFG_SR_H |
430*c5620aeeSHoratiu Vultur HSIO_SERDES6G_ANA_CFG_OB_CFG_POST0(0x10) |
431*c5620aeeSHoratiu Vultur HSIO_SERDES6G_ANA_CFG_OB_CFG_POL |
432*c5620aeeSHoratiu Vultur HSIO_SERDES6G_ANA_CFG_OB_CFG_ENA1V_MODE,
433*c5620aeeSHoratiu Vultur priv->regs[HSIO] + HSIO_SERDES6G_ANA_CFG_OB_CFG);
434*c5620aeeSHoratiu Vultur writel(HSIO_SERDES6G_ANA_CFG_OB_CFG1_LEV(0x18) |
435*c5620aeeSHoratiu Vultur HSIO_SERDES6G_ANA_CFG_OB_CFG1_ENA_CAS(0x1),
436*c5620aeeSHoratiu Vultur priv->regs[HSIO] + HSIO_SERDES6G_ANA_CFG_OB_CFG1);
437*c5620aeeSHoratiu Vultur writel(HSIO_SERDES6G_ANA_CFG_IB_CFG_RESISTOR_CTRL(0xc) |
438*c5620aeeSHoratiu Vultur HSIO_SERDES6G_ANA_CFG_IB_CFG_VBCOM(0x4) |
439*c5620aeeSHoratiu Vultur HSIO_SERDES6G_ANA_CFG_IB_CFG_VBAC(0x5) |
440*c5620aeeSHoratiu Vultur HSIO_SERDES6G_ANA_CFG_IB_CFG_RT(0xf) |
441*c5620aeeSHoratiu Vultur HSIO_SERDES6G_ANA_CFG_IB_CFG_RF(0x4),
442*c5620aeeSHoratiu Vultur priv->regs[HSIO] + HSIO_SERDES6G_ANA_CFG_IB_CFG);
443*c5620aeeSHoratiu Vultur writel(HSIO_SERDES6G_ANA_CFG_IB_CFG1_RST |
444*c5620aeeSHoratiu Vultur HSIO_SERDES6G_ANA_CFG_IB_CFG1_ENA_OFFSDC |
445*c5620aeeSHoratiu Vultur HSIO_SERDES6G_ANA_CFG_IB_CFG1_ENA_OFFSAC |
446*c5620aeeSHoratiu Vultur HSIO_SERDES6G_ANA_CFG_IB_CFG1_ANEG_MODE |
447*c5620aeeSHoratiu Vultur HSIO_SERDES6G_ANA_CFG_IB_CFG1_CHF |
448*c5620aeeSHoratiu Vultur HSIO_SERDES6G_ANA_CFG_IB_CFG1_C(0x4),
449*c5620aeeSHoratiu Vultur priv->regs[HSIO] + HSIO_SERDES6G_ANA_CFG_IB_CFG1);
450*c5620aeeSHoratiu Vultur writel(HSIO_SERDES6G_ANA_CFG_DES_CFG_BW_ANA(0x5) |
451*c5620aeeSHoratiu Vultur HSIO_SERDES6G_ANA_CFG_DES_CFG_BW_HYST(0x5) |
452*c5620aeeSHoratiu Vultur HSIO_SERDES6G_ANA_CFG_DES_CFG_MBTR_CTRL(0x2) |
453*c5620aeeSHoratiu Vultur HSIO_SERDES6G_ANA_CFG_DES_CFG_PHS_CTRL(0x6),
454*c5620aeeSHoratiu Vultur priv->regs[HSIO] + HSIO_SERDES6G_ANA_CFG_DES_CFG);
455*c5620aeeSHoratiu Vultur writel(HSIO_SERDES6G_ANA_CFG_PLL_CFG_FSM_ENA |
456*c5620aeeSHoratiu Vultur HSIO_SERDES6G_ANA_CFG_PLL_CFG_FSM_CTRL_DATA(0x78),
457*c5620aeeSHoratiu Vultur priv->regs[HSIO] + HSIO_SERDES6G_ANA_CFG_PLL_CFG);
458*c5620aeeSHoratiu Vultur writel(HSIO_SERDES6G_ANA_CFG_COMMON_CFG_IF_MODE(0x30) |
459*c5620aeeSHoratiu Vultur HSIO_SERDES6G_ANA_CFG_COMMON_CFG_ENA_LANE,
460*c5620aeeSHoratiu Vultur priv->regs[HSIO] + HSIO_SERDES6G_ANA_CFG_COMMON_CFG);
461*c5620aeeSHoratiu Vultur /*
462*c5620aeeSHoratiu Vultur * There are 4 serdes6g, configure all except serdes6g0, therefore
463*c5620aeeSHoratiu Vultur * the address is b1110
464*c5620aeeSHoratiu Vultur */
465*c5620aeeSHoratiu Vultur serdes6g_write(priv, 0xe);
466*c5620aeeSHoratiu Vultur
467*c5620aeeSHoratiu Vultur writel(readl(priv->regs[HSIO] + HSIO_SERDES6G_ANA_CFG_COMMON_CFG) |
468*c5620aeeSHoratiu Vultur HSIO_SERDES6G_ANA_CFG_COMMON_CFG_SYS_RST,
469*c5620aeeSHoratiu Vultur priv->regs[HSIO] + HSIO_SERDES6G_ANA_CFG_COMMON_CFG);
470*c5620aeeSHoratiu Vultur serdes6g_write(priv, 0xe);
471*c5620aeeSHoratiu Vultur
472*c5620aeeSHoratiu Vultur clrbits_le32(priv->regs[HSIO] + HSIO_SERDES6G_ANA_CFG_IB_CFG1,
473*c5620aeeSHoratiu Vultur HSIO_SERDES6G_ANA_CFG_IB_CFG1_RST);
474*c5620aeeSHoratiu Vultur writel(HSIO_SERDES6G_DIG_CFG_MISC_CFG_LANE_RST,
475*c5620aeeSHoratiu Vultur priv->regs[HSIO] + HSIO_SERDES6G_DIG_CFG_MISC_CFG);
476*c5620aeeSHoratiu Vultur serdes6g_write(priv, 0xe);
477*c5620aeeSHoratiu Vultur }
478*c5620aeeSHoratiu Vultur
luton_switch_init(struct luton_private * priv)479*c5620aeeSHoratiu Vultur static int luton_switch_init(struct luton_private *priv)
480*c5620aeeSHoratiu Vultur {
481*c5620aeeSHoratiu Vultur setbits_le32(priv->regs[HSIO] + HSIO_PLL5G_CFG_PLL5G_CFG2, BIT(1));
482*c5620aeeSHoratiu Vultur clrbits_le32(priv->regs[HSIO] + HSIO_PLL5G_CFG_PLL5G_CFG2, BIT(1));
483*c5620aeeSHoratiu Vultur
484*c5620aeeSHoratiu Vultur /* Reset switch & memories */
485*c5620aeeSHoratiu Vultur writel(SYS_SYSTEM_RST_MEM_ENA | SYS_SYSTEM_RST_MEM_INIT,
486*c5620aeeSHoratiu Vultur priv->regs[SYS] + SYS_SYSTEM_RST_CFG);
487*c5620aeeSHoratiu Vultur
488*c5620aeeSHoratiu Vultur /* Wait to complete */
489*c5620aeeSHoratiu Vultur if (wait_for_bit_le32(priv->regs[SYS] + SYS_SYSTEM_RST_CFG,
490*c5620aeeSHoratiu Vultur SYS_SYSTEM_RST_MEM_INIT, false, 2000, false)) {
491*c5620aeeSHoratiu Vultur printf("Timeout in memory reset\n");
492*c5620aeeSHoratiu Vultur }
493*c5620aeeSHoratiu Vultur
494*c5620aeeSHoratiu Vultur /* Enable switch core */
495*c5620aeeSHoratiu Vultur setbits_le32(priv->regs[SYS] + SYS_SYSTEM_RST_CFG,
496*c5620aeeSHoratiu Vultur SYS_SYSTEM_RST_CORE_ENA);
497*c5620aeeSHoratiu Vultur
498*c5620aeeSHoratiu Vultur /* Setup the Serdes6g macros */
499*c5620aeeSHoratiu Vultur serdes6g_cfg(priv);
500*c5620aeeSHoratiu Vultur
501*c5620aeeSHoratiu Vultur return 0;
502*c5620aeeSHoratiu Vultur }
503*c5620aeeSHoratiu Vultur
luton_initialize(struct luton_private * priv)504*c5620aeeSHoratiu Vultur static int luton_initialize(struct luton_private *priv)
505*c5620aeeSHoratiu Vultur {
506*c5620aeeSHoratiu Vultur int ret, i;
507*c5620aeeSHoratiu Vultur
508*c5620aeeSHoratiu Vultur /* Initialize switch memories, enable core */
509*c5620aeeSHoratiu Vultur ret = luton_switch_init(priv);
510*c5620aeeSHoratiu Vultur if (ret)
511*c5620aeeSHoratiu Vultur return ret;
512*c5620aeeSHoratiu Vultur
513*c5620aeeSHoratiu Vultur /*
514*c5620aeeSHoratiu Vultur * Disable port-to-port by switching
515*c5620aeeSHoratiu Vultur * Put front ports in "port isolation modes" - i.e. they can't send
516*c5620aeeSHoratiu Vultur * to other ports - via the PGID sorce masks.
517*c5620aeeSHoratiu Vultur */
518*c5620aeeSHoratiu Vultur for (i = 0; i < MAX_PORT; i++)
519*c5620aeeSHoratiu Vultur writel(0, priv->regs[ANA] + ANA_PGID(PGID_SRC + i));
520*c5620aeeSHoratiu Vultur
521*c5620aeeSHoratiu Vultur /* Flush queues */
522*c5620aeeSHoratiu Vultur mscc_flush(priv->regs[QS], luton_regs_qs);
523*c5620aeeSHoratiu Vultur
524*c5620aeeSHoratiu Vultur /* Setup frame ageing - "2 sec" - The unit is 4ns on Luton*/
525*c5620aeeSHoratiu Vultur writel(2000000000 / 4,
526*c5620aeeSHoratiu Vultur priv->regs[SYS] + SYS_FRM_AGING);
527*c5620aeeSHoratiu Vultur
528*c5620aeeSHoratiu Vultur for (i = PORT0; i < MAX_PORT; i++) {
529*c5620aeeSHoratiu Vultur if (i < PORT10)
530*c5620aeeSHoratiu Vultur luton_gmii_port_init(priv, i);
531*c5620aeeSHoratiu Vultur else
532*c5620aeeSHoratiu Vultur if (i == PORT10 || i == PORT11)
533*c5620aeeSHoratiu Vultur luton_port_init(priv, i);
534*c5620aeeSHoratiu Vultur else
535*c5620aeeSHoratiu Vultur luton_ext_port_init(priv, i);
536*c5620aeeSHoratiu Vultur }
537*c5620aeeSHoratiu Vultur
538*c5620aeeSHoratiu Vultur luton_cpu_capture_setup(priv);
539*c5620aeeSHoratiu Vultur
540*c5620aeeSHoratiu Vultur return 0;
541*c5620aeeSHoratiu Vultur }
542*c5620aeeSHoratiu Vultur
luton_write_hwaddr(struct udevice * dev)543*c5620aeeSHoratiu Vultur static int luton_write_hwaddr(struct udevice *dev)
544*c5620aeeSHoratiu Vultur {
545*c5620aeeSHoratiu Vultur struct luton_private *priv = dev_get_priv(dev);
546*c5620aeeSHoratiu Vultur struct eth_pdata *pdata = dev_get_platdata(dev);
547*c5620aeeSHoratiu Vultur
548*c5620aeeSHoratiu Vultur mscc_mac_table_add(priv->regs[ANA], luton_regs_ana_table,
549*c5620aeeSHoratiu Vultur pdata->enetaddr, PGID_UNICAST);
550*c5620aeeSHoratiu Vultur
551*c5620aeeSHoratiu Vultur writel(BIT(CPU_PORT), priv->regs[ANA] + ANA_PGID(PGID_UNICAST));
552*c5620aeeSHoratiu Vultur
553*c5620aeeSHoratiu Vultur return 0;
554*c5620aeeSHoratiu Vultur }
555*c5620aeeSHoratiu Vultur
luton_start(struct udevice * dev)556*c5620aeeSHoratiu Vultur static int luton_start(struct udevice *dev)
557*c5620aeeSHoratiu Vultur {
558*c5620aeeSHoratiu Vultur struct luton_private *priv = dev_get_priv(dev);
559*c5620aeeSHoratiu Vultur struct eth_pdata *pdata = dev_get_platdata(dev);
560*c5620aeeSHoratiu Vultur const unsigned char mac[ETH_ALEN] = { 0xff, 0xff, 0xff, 0xff, 0xff,
561*c5620aeeSHoratiu Vultur 0xff };
562*c5620aeeSHoratiu Vultur int ret;
563*c5620aeeSHoratiu Vultur
564*c5620aeeSHoratiu Vultur ret = luton_initialize(priv);
565*c5620aeeSHoratiu Vultur if (ret)
566*c5620aeeSHoratiu Vultur return ret;
567*c5620aeeSHoratiu Vultur
568*c5620aeeSHoratiu Vultur /* Set MAC address tables entries for CPU redirection */
569*c5620aeeSHoratiu Vultur mscc_mac_table_add(priv->regs[ANA], luton_regs_ana_table,
570*c5620aeeSHoratiu Vultur mac, PGID_BROADCAST);
571*c5620aeeSHoratiu Vultur
572*c5620aeeSHoratiu Vultur writel(BIT(CPU_PORT) | INTERNAL_PORT_MSK,
573*c5620aeeSHoratiu Vultur priv->regs[ANA] + ANA_PGID(PGID_BROADCAST));
574*c5620aeeSHoratiu Vultur
575*c5620aeeSHoratiu Vultur mscc_mac_table_add(priv->regs[ANA], luton_regs_ana_table,
576*c5620aeeSHoratiu Vultur pdata->enetaddr, PGID_UNICAST);
577*c5620aeeSHoratiu Vultur
578*c5620aeeSHoratiu Vultur writel(BIT(CPU_PORT), priv->regs[ANA] + ANA_PGID(PGID_UNICAST));
579*c5620aeeSHoratiu Vultur
580*c5620aeeSHoratiu Vultur return 0;
581*c5620aeeSHoratiu Vultur }
582*c5620aeeSHoratiu Vultur
luton_send(struct udevice * dev,void * packet,int length)583*c5620aeeSHoratiu Vultur static int luton_send(struct udevice *dev, void *packet, int length)
584*c5620aeeSHoratiu Vultur {
585*c5620aeeSHoratiu Vultur struct luton_private *priv = dev_get_priv(dev);
586*c5620aeeSHoratiu Vultur u32 ifh[IFH_LEN];
587*c5620aeeSHoratiu Vultur int port = BIT(0); /* use port 0 */
588*c5620aeeSHoratiu Vultur u32 *buf = packet;
589*c5620aeeSHoratiu Vultur
590*c5620aeeSHoratiu Vultur ifh[0] = IFH_INJ_BYPASS | port;
591*c5620aeeSHoratiu Vultur ifh[1] = (IFH_TAG_TYPE_C << 16);
592*c5620aeeSHoratiu Vultur
593*c5620aeeSHoratiu Vultur return mscc_send(priv->regs[QS], luton_regs_qs,
594*c5620aeeSHoratiu Vultur ifh, IFH_LEN, buf, length);
595*c5620aeeSHoratiu Vultur }
596*c5620aeeSHoratiu Vultur
luton_recv(struct udevice * dev,int flags,uchar ** packetp)597*c5620aeeSHoratiu Vultur static int luton_recv(struct udevice *dev, int flags, uchar **packetp)
598*c5620aeeSHoratiu Vultur {
599*c5620aeeSHoratiu Vultur struct luton_private *priv = dev_get_priv(dev);
600*c5620aeeSHoratiu Vultur u32 *rxbuf = (u32 *)net_rx_packets[0];
601*c5620aeeSHoratiu Vultur int byte_cnt = 0;
602*c5620aeeSHoratiu Vultur
603*c5620aeeSHoratiu Vultur byte_cnt = mscc_recv(priv->regs[QS], luton_regs_qs, rxbuf, IFH_LEN,
604*c5620aeeSHoratiu Vultur true);
605*c5620aeeSHoratiu Vultur
606*c5620aeeSHoratiu Vultur *packetp = net_rx_packets[0];
607*c5620aeeSHoratiu Vultur
608*c5620aeeSHoratiu Vultur return byte_cnt;
609*c5620aeeSHoratiu Vultur }
610*c5620aeeSHoratiu Vultur
luton_probe(struct udevice * dev)611*c5620aeeSHoratiu Vultur static int luton_probe(struct udevice *dev)
612*c5620aeeSHoratiu Vultur {
613*c5620aeeSHoratiu Vultur struct luton_private *priv = dev_get_priv(dev);
614*c5620aeeSHoratiu Vultur int i;
615*c5620aeeSHoratiu Vultur
616*c5620aeeSHoratiu Vultur struct {
617*c5620aeeSHoratiu Vultur enum luton_target id;
618*c5620aeeSHoratiu Vultur char *name;
619*c5620aeeSHoratiu Vultur } reg[] = {
620*c5620aeeSHoratiu Vultur { PORT0, "port0" },
621*c5620aeeSHoratiu Vultur { PORT1, "port1" },
622*c5620aeeSHoratiu Vultur { PORT2, "port2" },
623*c5620aeeSHoratiu Vultur { PORT3, "port3" },
624*c5620aeeSHoratiu Vultur { PORT4, "port4" },
625*c5620aeeSHoratiu Vultur { PORT5, "port5" },
626*c5620aeeSHoratiu Vultur { PORT6, "port6" },
627*c5620aeeSHoratiu Vultur { PORT7, "port7" },
628*c5620aeeSHoratiu Vultur { PORT8, "port8" },
629*c5620aeeSHoratiu Vultur { PORT9, "port9" },
630*c5620aeeSHoratiu Vultur { PORT10, "port10" },
631*c5620aeeSHoratiu Vultur { PORT11, "port11" },
632*c5620aeeSHoratiu Vultur { PORT12, "port12" },
633*c5620aeeSHoratiu Vultur { PORT13, "port13" },
634*c5620aeeSHoratiu Vultur { PORT14, "port14" },
635*c5620aeeSHoratiu Vultur { PORT15, "port15" },
636*c5620aeeSHoratiu Vultur { PORT16, "port16" },
637*c5620aeeSHoratiu Vultur { PORT17, "port17" },
638*c5620aeeSHoratiu Vultur { PORT18, "port18" },
639*c5620aeeSHoratiu Vultur { PORT19, "port19" },
640*c5620aeeSHoratiu Vultur { PORT20, "port20" },
641*c5620aeeSHoratiu Vultur { PORT21, "port21" },
642*c5620aeeSHoratiu Vultur { PORT22, "port22" },
643*c5620aeeSHoratiu Vultur { PORT23, "port23" },
644*c5620aeeSHoratiu Vultur { SYS, "sys" },
645*c5620aeeSHoratiu Vultur { ANA, "ana" },
646*c5620aeeSHoratiu Vultur { REW, "rew" },
647*c5620aeeSHoratiu Vultur { GCB, "gcb" },
648*c5620aeeSHoratiu Vultur { QS, "qs" },
649*c5620aeeSHoratiu Vultur { HSIO, "hsio" },
650*c5620aeeSHoratiu Vultur };
651*c5620aeeSHoratiu Vultur
652*c5620aeeSHoratiu Vultur if (!priv)
653*c5620aeeSHoratiu Vultur return -EINVAL;
654*c5620aeeSHoratiu Vultur
655*c5620aeeSHoratiu Vultur for (i = 0; i < ARRAY_SIZE(reg); i++) {
656*c5620aeeSHoratiu Vultur priv->regs[reg[i].id] = dev_remap_addr_name(dev, reg[i].name);
657*c5620aeeSHoratiu Vultur if (!priv->regs[reg[i].id]) {
658*c5620aeeSHoratiu Vultur debug
659*c5620aeeSHoratiu Vultur ("Error can't get regs base addresses for %s\n",
660*c5620aeeSHoratiu Vultur reg[i].name);
661*c5620aeeSHoratiu Vultur return -ENOMEM;
662*c5620aeeSHoratiu Vultur }
663*c5620aeeSHoratiu Vultur }
664*c5620aeeSHoratiu Vultur
665*c5620aeeSHoratiu Vultur /* Release reset in the CU-PHY */
666*c5620aeeSHoratiu Vultur writel(0, priv->regs[GCB] + GCB_DEVCPU_RST_SOFT_CHIP_RST);
667*c5620aeeSHoratiu Vultur
668*c5620aeeSHoratiu Vultur /* Ports with ext phy don't need to reset clk */
669*c5620aeeSHoratiu Vultur for (i = PORT0; i < MAX_INT_PORT; i++) {
670*c5620aeeSHoratiu Vultur if (i < PORT10)
671*c5620aeeSHoratiu Vultur clrbits_le32(priv->regs[i] + DEV_GMII_PORT_MODE_CLK,
672*c5620aeeSHoratiu Vultur DEV_GMII_PORT_MODE_CLK_PHY_RST);
673*c5620aeeSHoratiu Vultur else
674*c5620aeeSHoratiu Vultur clrbits_le32(priv->regs[i] + DEV_PORT_MODE_CLK,
675*c5620aeeSHoratiu Vultur DEV_PORT_MODE_CLK_PHY_RST);
676*c5620aeeSHoratiu Vultur }
677*c5620aeeSHoratiu Vultur
678*c5620aeeSHoratiu Vultur /* Wait for internal PHY to be ready */
679*c5620aeeSHoratiu Vultur if (wait_for_bit_le32(priv->regs[GCB] + GCB_MISC_STAT,
680*c5620aeeSHoratiu Vultur GCB_MISC_STAT_PHY_READY, true, 500, false))
681*c5620aeeSHoratiu Vultur return -EACCES;
682*c5620aeeSHoratiu Vultur
683*c5620aeeSHoratiu Vultur priv->bus[INTERNAL] = luton_mdiobus_init(dev, INTERNAL);
684*c5620aeeSHoratiu Vultur
685*c5620aeeSHoratiu Vultur for (i = 0; i < MAX_INT_PORT; i++) {
686*c5620aeeSHoratiu Vultur phy_connect(priv->bus[INTERNAL], i, dev,
687*c5620aeeSHoratiu Vultur PHY_INTERFACE_MODE_NONE);
688*c5620aeeSHoratiu Vultur }
689*c5620aeeSHoratiu Vultur
690*c5620aeeSHoratiu Vultur /*
691*c5620aeeSHoratiu Vultur * coma_mode is need on only one phy, because all the other phys
692*c5620aeeSHoratiu Vultur * will be affected.
693*c5620aeeSHoratiu Vultur */
694*c5620aeeSHoratiu Vultur mscc_miim_write(priv->bus[INTERNAL], 0, 0, 31, 0x10);
695*c5620aeeSHoratiu Vultur mscc_miim_write(priv->bus[INTERNAL], 0, 0, 14, 0x800);
696*c5620aeeSHoratiu Vultur mscc_miim_write(priv->bus[INTERNAL], 0, 0, 31, 0);
697*c5620aeeSHoratiu Vultur
698*c5620aeeSHoratiu Vultur return 0;
699*c5620aeeSHoratiu Vultur }
700*c5620aeeSHoratiu Vultur
luton_remove(struct udevice * dev)701*c5620aeeSHoratiu Vultur static int luton_remove(struct udevice *dev)
702*c5620aeeSHoratiu Vultur {
703*c5620aeeSHoratiu Vultur struct luton_private *priv = dev_get_priv(dev);
704*c5620aeeSHoratiu Vultur int i;
705*c5620aeeSHoratiu Vultur
706*c5620aeeSHoratiu Vultur for (i = 0; i < NUM_PHY; i++) {
707*c5620aeeSHoratiu Vultur mdio_unregister(priv->bus[i]);
708*c5620aeeSHoratiu Vultur mdio_free(priv->bus[i]);
709*c5620aeeSHoratiu Vultur }
710*c5620aeeSHoratiu Vultur
711*c5620aeeSHoratiu Vultur return 0;
712*c5620aeeSHoratiu Vultur }
713*c5620aeeSHoratiu Vultur
714*c5620aeeSHoratiu Vultur static const struct eth_ops luton_ops = {
715*c5620aeeSHoratiu Vultur .start = luton_start,
716*c5620aeeSHoratiu Vultur .stop = luton_stop,
717*c5620aeeSHoratiu Vultur .send = luton_send,
718*c5620aeeSHoratiu Vultur .recv = luton_recv,
719*c5620aeeSHoratiu Vultur .write_hwaddr = luton_write_hwaddr,
720*c5620aeeSHoratiu Vultur };
721*c5620aeeSHoratiu Vultur
722*c5620aeeSHoratiu Vultur static const struct udevice_id mscc_luton_ids[] = {
723*c5620aeeSHoratiu Vultur {.compatible = "mscc,vsc7527-switch", },
724*c5620aeeSHoratiu Vultur { /* Sentinel */ }
725*c5620aeeSHoratiu Vultur };
726*c5620aeeSHoratiu Vultur
727*c5620aeeSHoratiu Vultur U_BOOT_DRIVER(luton) = {
728*c5620aeeSHoratiu Vultur .name = "luton-switch",
729*c5620aeeSHoratiu Vultur .id = UCLASS_ETH,
730*c5620aeeSHoratiu Vultur .of_match = mscc_luton_ids,
731*c5620aeeSHoratiu Vultur .probe = luton_probe,
732*c5620aeeSHoratiu Vultur .remove = luton_remove,
733*c5620aeeSHoratiu Vultur .ops = &luton_ops,
734*c5620aeeSHoratiu Vultur .priv_auto_alloc_size = sizeof(struct luton_private),
735*c5620aeeSHoratiu Vultur .platdata_auto_alloc_size = sizeof(struct eth_pdata),
736*c5620aeeSHoratiu Vultur };
737