1 // SPDX-License-Identifier: GPL-2.0+
2 /* Microchip Sparx5 Switch driver
3  *
4  * Copyright (c) 2021 Microchip Technology Inc. and its subsidiaries.
5  *
6  * The Sparx5 Chip Register Model can be browsed at this location:
7  * https://github.com/microchip-ung/sparx-5_reginfo
8  */
9 #include <linux/module.h>
10 #include <linux/device.h>
11 #include <linux/netdevice.h>
12 #include <linux/platform_device.h>
13 #include <linux/interrupt.h>
14 #include <linux/of.h>
15 #include <linux/of_net.h>
16 #include <linux/of_mdio.h>
17 #include <net/switchdev.h>
18 #include <linux/etherdevice.h>
19 #include <linux/io.h>
20 #include <linux/printk.h>
21 #include <linux/iopoll.h>
22 #include <linux/mfd/syscon.h>
23 #include <linux/regmap.h>
24 #include <linux/types.h>
25 #include <linux/reset.h>
26 
27 #include "sparx5_main_regs.h"
28 #include "sparx5_main.h"
29 #include "sparx5_port.h"
30 
31 #define QLIM_WM(fraction) \
32 	((SPX5_BUFFER_MEMORY / SPX5_BUFFER_CELL_SZ - 100) * (fraction) / 100)
33 #define IO_RANGES 3
34 
35 struct initial_port_config {
36 	u32 portno;
37 	struct device_node *node;
38 	struct sparx5_port_config conf;
39 	struct phy *serdes;
40 };
41 
42 struct sparx5_ram_config {
43 	void __iomem *init_reg;
44 	u32 init_val;
45 };
46 
47 struct sparx5_main_io_resource {
48 	enum sparx5_target id;
49 	phys_addr_t offset;
50 	int range;
51 };
52 
53 static const struct sparx5_main_io_resource sparx5_main_iomap[] =  {
54 	{ TARGET_CPU,                         0, 0 }, /* 0x600000000 */
55 	{ TARGET_FDMA,                  0x80000, 0 }, /* 0x600080000 */
56 	{ TARGET_PCEP,                 0x400000, 0 }, /* 0x600400000 */
57 	{ TARGET_DEV2G5,             0x10004000, 1 }, /* 0x610004000 */
58 	{ TARGET_DEV5G,              0x10008000, 1 }, /* 0x610008000 */
59 	{ TARGET_PCS5G_BR,           0x1000c000, 1 }, /* 0x61000c000 */
60 	{ TARGET_DEV2G5 +  1,        0x10010000, 1 }, /* 0x610010000 */
61 	{ TARGET_DEV5G +  1,         0x10014000, 1 }, /* 0x610014000 */
62 	{ TARGET_PCS5G_BR +  1,      0x10018000, 1 }, /* 0x610018000 */
63 	{ TARGET_DEV2G5 +  2,        0x1001c000, 1 }, /* 0x61001c000 */
64 	{ TARGET_DEV5G +  2,         0x10020000, 1 }, /* 0x610020000 */
65 	{ TARGET_PCS5G_BR +  2,      0x10024000, 1 }, /* 0x610024000 */
66 	{ TARGET_DEV2G5 +  6,        0x10028000, 1 }, /* 0x610028000 */
67 	{ TARGET_DEV5G +  6,         0x1002c000, 1 }, /* 0x61002c000 */
68 	{ TARGET_PCS5G_BR +  6,      0x10030000, 1 }, /* 0x610030000 */
69 	{ TARGET_DEV2G5 +  7,        0x10034000, 1 }, /* 0x610034000 */
70 	{ TARGET_DEV5G +  7,         0x10038000, 1 }, /* 0x610038000 */
71 	{ TARGET_PCS5G_BR +  7,      0x1003c000, 1 }, /* 0x61003c000 */
72 	{ TARGET_DEV2G5 +  8,        0x10040000, 1 }, /* 0x610040000 */
73 	{ TARGET_DEV5G +  8,         0x10044000, 1 }, /* 0x610044000 */
74 	{ TARGET_PCS5G_BR +  8,      0x10048000, 1 }, /* 0x610048000 */
75 	{ TARGET_DEV2G5 +  9,        0x1004c000, 1 }, /* 0x61004c000 */
76 	{ TARGET_DEV5G +  9,         0x10050000, 1 }, /* 0x610050000 */
77 	{ TARGET_PCS5G_BR +  9,      0x10054000, 1 }, /* 0x610054000 */
78 	{ TARGET_DEV2G5 + 10,        0x10058000, 1 }, /* 0x610058000 */
79 	{ TARGET_DEV5G + 10,         0x1005c000, 1 }, /* 0x61005c000 */
80 	{ TARGET_PCS5G_BR + 10,      0x10060000, 1 }, /* 0x610060000 */
81 	{ TARGET_DEV2G5 + 11,        0x10064000, 1 }, /* 0x610064000 */
82 	{ TARGET_DEV5G + 11,         0x10068000, 1 }, /* 0x610068000 */
83 	{ TARGET_PCS5G_BR + 11,      0x1006c000, 1 }, /* 0x61006c000 */
84 	{ TARGET_DEV2G5 + 12,        0x10070000, 1 }, /* 0x610070000 */
85 	{ TARGET_DEV10G,             0x10074000, 1 }, /* 0x610074000 */
86 	{ TARGET_PCS10G_BR,          0x10078000, 1 }, /* 0x610078000 */
87 	{ TARGET_DEV2G5 + 14,        0x1007c000, 1 }, /* 0x61007c000 */
88 	{ TARGET_DEV10G +  2,        0x10080000, 1 }, /* 0x610080000 */
89 	{ TARGET_PCS10G_BR +  2,     0x10084000, 1 }, /* 0x610084000 */
90 	{ TARGET_DEV2G5 + 15,        0x10088000, 1 }, /* 0x610088000 */
91 	{ TARGET_DEV10G +  3,        0x1008c000, 1 }, /* 0x61008c000 */
92 	{ TARGET_PCS10G_BR +  3,     0x10090000, 1 }, /* 0x610090000 */
93 	{ TARGET_DEV2G5 + 16,        0x10094000, 1 }, /* 0x610094000 */
94 	{ TARGET_DEV2G5 + 17,        0x10098000, 1 }, /* 0x610098000 */
95 	{ TARGET_DEV2G5 + 18,        0x1009c000, 1 }, /* 0x61009c000 */
96 	{ TARGET_DEV2G5 + 19,        0x100a0000, 1 }, /* 0x6100a0000 */
97 	{ TARGET_DEV2G5 + 20,        0x100a4000, 1 }, /* 0x6100a4000 */
98 	{ TARGET_DEV2G5 + 21,        0x100a8000, 1 }, /* 0x6100a8000 */
99 	{ TARGET_DEV2G5 + 22,        0x100ac000, 1 }, /* 0x6100ac000 */
100 	{ TARGET_DEV2G5 + 23,        0x100b0000, 1 }, /* 0x6100b0000 */
101 	{ TARGET_DEV2G5 + 32,        0x100b4000, 1 }, /* 0x6100b4000 */
102 	{ TARGET_DEV2G5 + 33,        0x100b8000, 1 }, /* 0x6100b8000 */
103 	{ TARGET_DEV2G5 + 34,        0x100bc000, 1 }, /* 0x6100bc000 */
104 	{ TARGET_DEV2G5 + 35,        0x100c0000, 1 }, /* 0x6100c0000 */
105 	{ TARGET_DEV2G5 + 36,        0x100c4000, 1 }, /* 0x6100c4000 */
106 	{ TARGET_DEV2G5 + 37,        0x100c8000, 1 }, /* 0x6100c8000 */
107 	{ TARGET_DEV2G5 + 38,        0x100cc000, 1 }, /* 0x6100cc000 */
108 	{ TARGET_DEV2G5 + 39,        0x100d0000, 1 }, /* 0x6100d0000 */
109 	{ TARGET_DEV2G5 + 40,        0x100d4000, 1 }, /* 0x6100d4000 */
110 	{ TARGET_DEV2G5 + 41,        0x100d8000, 1 }, /* 0x6100d8000 */
111 	{ TARGET_DEV2G5 + 42,        0x100dc000, 1 }, /* 0x6100dc000 */
112 	{ TARGET_DEV2G5 + 43,        0x100e0000, 1 }, /* 0x6100e0000 */
113 	{ TARGET_DEV2G5 + 44,        0x100e4000, 1 }, /* 0x6100e4000 */
114 	{ TARGET_DEV2G5 + 45,        0x100e8000, 1 }, /* 0x6100e8000 */
115 	{ TARGET_DEV2G5 + 46,        0x100ec000, 1 }, /* 0x6100ec000 */
116 	{ TARGET_DEV2G5 + 47,        0x100f0000, 1 }, /* 0x6100f0000 */
117 	{ TARGET_DEV2G5 + 57,        0x100f4000, 1 }, /* 0x6100f4000 */
118 	{ TARGET_DEV25G +  1,        0x100f8000, 1 }, /* 0x6100f8000 */
119 	{ TARGET_PCS25G_BR +  1,     0x100fc000, 1 }, /* 0x6100fc000 */
120 	{ TARGET_DEV2G5 + 59,        0x10104000, 1 }, /* 0x610104000 */
121 	{ TARGET_DEV25G +  3,        0x10108000, 1 }, /* 0x610108000 */
122 	{ TARGET_PCS25G_BR +  3,     0x1010c000, 1 }, /* 0x61010c000 */
123 	{ TARGET_DEV2G5 + 60,        0x10114000, 1 }, /* 0x610114000 */
124 	{ TARGET_DEV25G +  4,        0x10118000, 1 }, /* 0x610118000 */
125 	{ TARGET_PCS25G_BR +  4,     0x1011c000, 1 }, /* 0x61011c000 */
126 	{ TARGET_DEV2G5 + 64,        0x10124000, 1 }, /* 0x610124000 */
127 	{ TARGET_DEV5G + 12,         0x10128000, 1 }, /* 0x610128000 */
128 	{ TARGET_PCS5G_BR + 12,      0x1012c000, 1 }, /* 0x61012c000 */
129 	{ TARGET_PORT_CONF,          0x10130000, 1 }, /* 0x610130000 */
130 	{ TARGET_DEV2G5 +  3,        0x10404000, 1 }, /* 0x610404000 */
131 	{ TARGET_DEV5G +  3,         0x10408000, 1 }, /* 0x610408000 */
132 	{ TARGET_PCS5G_BR +  3,      0x1040c000, 1 }, /* 0x61040c000 */
133 	{ TARGET_DEV2G5 +  4,        0x10410000, 1 }, /* 0x610410000 */
134 	{ TARGET_DEV5G +  4,         0x10414000, 1 }, /* 0x610414000 */
135 	{ TARGET_PCS5G_BR +  4,      0x10418000, 1 }, /* 0x610418000 */
136 	{ TARGET_DEV2G5 +  5,        0x1041c000, 1 }, /* 0x61041c000 */
137 	{ TARGET_DEV5G +  5,         0x10420000, 1 }, /* 0x610420000 */
138 	{ TARGET_PCS5G_BR +  5,      0x10424000, 1 }, /* 0x610424000 */
139 	{ TARGET_DEV2G5 + 13,        0x10428000, 1 }, /* 0x610428000 */
140 	{ TARGET_DEV10G +  1,        0x1042c000, 1 }, /* 0x61042c000 */
141 	{ TARGET_PCS10G_BR +  1,     0x10430000, 1 }, /* 0x610430000 */
142 	{ TARGET_DEV2G5 + 24,        0x10434000, 1 }, /* 0x610434000 */
143 	{ TARGET_DEV2G5 + 25,        0x10438000, 1 }, /* 0x610438000 */
144 	{ TARGET_DEV2G5 + 26,        0x1043c000, 1 }, /* 0x61043c000 */
145 	{ TARGET_DEV2G5 + 27,        0x10440000, 1 }, /* 0x610440000 */
146 	{ TARGET_DEV2G5 + 28,        0x10444000, 1 }, /* 0x610444000 */
147 	{ TARGET_DEV2G5 + 29,        0x10448000, 1 }, /* 0x610448000 */
148 	{ TARGET_DEV2G5 + 30,        0x1044c000, 1 }, /* 0x61044c000 */
149 	{ TARGET_DEV2G5 + 31,        0x10450000, 1 }, /* 0x610450000 */
150 	{ TARGET_DEV2G5 + 48,        0x10454000, 1 }, /* 0x610454000 */
151 	{ TARGET_DEV10G +  4,        0x10458000, 1 }, /* 0x610458000 */
152 	{ TARGET_PCS10G_BR +  4,     0x1045c000, 1 }, /* 0x61045c000 */
153 	{ TARGET_DEV2G5 + 49,        0x10460000, 1 }, /* 0x610460000 */
154 	{ TARGET_DEV10G +  5,        0x10464000, 1 }, /* 0x610464000 */
155 	{ TARGET_PCS10G_BR +  5,     0x10468000, 1 }, /* 0x610468000 */
156 	{ TARGET_DEV2G5 + 50,        0x1046c000, 1 }, /* 0x61046c000 */
157 	{ TARGET_DEV10G +  6,        0x10470000, 1 }, /* 0x610470000 */
158 	{ TARGET_PCS10G_BR +  6,     0x10474000, 1 }, /* 0x610474000 */
159 	{ TARGET_DEV2G5 + 51,        0x10478000, 1 }, /* 0x610478000 */
160 	{ TARGET_DEV10G +  7,        0x1047c000, 1 }, /* 0x61047c000 */
161 	{ TARGET_PCS10G_BR +  7,     0x10480000, 1 }, /* 0x610480000 */
162 	{ TARGET_DEV2G5 + 52,        0x10484000, 1 }, /* 0x610484000 */
163 	{ TARGET_DEV10G +  8,        0x10488000, 1 }, /* 0x610488000 */
164 	{ TARGET_PCS10G_BR +  8,     0x1048c000, 1 }, /* 0x61048c000 */
165 	{ TARGET_DEV2G5 + 53,        0x10490000, 1 }, /* 0x610490000 */
166 	{ TARGET_DEV10G +  9,        0x10494000, 1 }, /* 0x610494000 */
167 	{ TARGET_PCS10G_BR +  9,     0x10498000, 1 }, /* 0x610498000 */
168 	{ TARGET_DEV2G5 + 54,        0x1049c000, 1 }, /* 0x61049c000 */
169 	{ TARGET_DEV10G + 10,        0x104a0000, 1 }, /* 0x6104a0000 */
170 	{ TARGET_PCS10G_BR + 10,     0x104a4000, 1 }, /* 0x6104a4000 */
171 	{ TARGET_DEV2G5 + 55,        0x104a8000, 1 }, /* 0x6104a8000 */
172 	{ TARGET_DEV10G + 11,        0x104ac000, 1 }, /* 0x6104ac000 */
173 	{ TARGET_PCS10G_BR + 11,     0x104b0000, 1 }, /* 0x6104b0000 */
174 	{ TARGET_DEV2G5 + 56,        0x104b4000, 1 }, /* 0x6104b4000 */
175 	{ TARGET_DEV25G,             0x104b8000, 1 }, /* 0x6104b8000 */
176 	{ TARGET_PCS25G_BR,          0x104bc000, 1 }, /* 0x6104bc000 */
177 	{ TARGET_DEV2G5 + 58,        0x104c4000, 1 }, /* 0x6104c4000 */
178 	{ TARGET_DEV25G +  2,        0x104c8000, 1 }, /* 0x6104c8000 */
179 	{ TARGET_PCS25G_BR +  2,     0x104cc000, 1 }, /* 0x6104cc000 */
180 	{ TARGET_DEV2G5 + 61,        0x104d4000, 1 }, /* 0x6104d4000 */
181 	{ TARGET_DEV25G +  5,        0x104d8000, 1 }, /* 0x6104d8000 */
182 	{ TARGET_PCS25G_BR +  5,     0x104dc000, 1 }, /* 0x6104dc000 */
183 	{ TARGET_DEV2G5 + 62,        0x104e4000, 1 }, /* 0x6104e4000 */
184 	{ TARGET_DEV25G +  6,        0x104e8000, 1 }, /* 0x6104e8000 */
185 	{ TARGET_PCS25G_BR +  6,     0x104ec000, 1 }, /* 0x6104ec000 */
186 	{ TARGET_DEV2G5 + 63,        0x104f4000, 1 }, /* 0x6104f4000 */
187 	{ TARGET_DEV25G +  7,        0x104f8000, 1 }, /* 0x6104f8000 */
188 	{ TARGET_PCS25G_BR +  7,     0x104fc000, 1 }, /* 0x6104fc000 */
189 	{ TARGET_DSM,                0x10504000, 1 }, /* 0x610504000 */
190 	{ TARGET_ASM,                0x10600000, 1 }, /* 0x610600000 */
191 	{ TARGET_GCB,                0x11010000, 2 }, /* 0x611010000 */
192 	{ TARGET_QS,                 0x11030000, 2 }, /* 0x611030000 */
193 	{ TARGET_PTP,                0x11040000, 2 }, /* 0x611040000 */
194 	{ TARGET_ANA_ACL,            0x11050000, 2 }, /* 0x611050000 */
195 	{ TARGET_LRN,                0x11060000, 2 }, /* 0x611060000 */
196 	{ TARGET_VCAP_SUPER,         0x11080000, 2 }, /* 0x611080000 */
197 	{ TARGET_QSYS,               0x110a0000, 2 }, /* 0x6110a0000 */
198 	{ TARGET_QFWD,               0x110b0000, 2 }, /* 0x6110b0000 */
199 	{ TARGET_XQS,                0x110c0000, 2 }, /* 0x6110c0000 */
200 	{ TARGET_CLKGEN,             0x11100000, 2 }, /* 0x611100000 */
201 	{ TARGET_ANA_AC_POL,         0x11200000, 2 }, /* 0x611200000 */
202 	{ TARGET_QRES,               0x11280000, 2 }, /* 0x611280000 */
203 	{ TARGET_EACL,               0x112c0000, 2 }, /* 0x6112c0000 */
204 	{ TARGET_ANA_CL,             0x11400000, 2 }, /* 0x611400000 */
205 	{ TARGET_ANA_L3,             0x11480000, 2 }, /* 0x611480000 */
206 	{ TARGET_HSCH,               0x11580000, 2 }, /* 0x611580000 */
207 	{ TARGET_REW,                0x11600000, 2 }, /* 0x611600000 */
208 	{ TARGET_ANA_L2,             0x11800000, 2 }, /* 0x611800000 */
209 	{ TARGET_ANA_AC,             0x11900000, 2 }, /* 0x611900000 */
210 	{ TARGET_VOP,                0x11a00000, 2 }, /* 0x611a00000 */
211 };
212 
213 static int sparx5_create_targets(struct sparx5 *sparx5)
214 {
215 	struct resource *iores[IO_RANGES];
216 	void __iomem *iomem[IO_RANGES];
217 	void __iomem *begin[IO_RANGES];
218 	int range_id[IO_RANGES];
219 	int idx, jdx;
220 
221 	for (idx = 0, jdx = 0; jdx < ARRAY_SIZE(sparx5_main_iomap); jdx++) {
222 		const struct sparx5_main_io_resource *iomap = &sparx5_main_iomap[jdx];
223 
224 		if (idx == iomap->range) {
225 			range_id[idx] = jdx;
226 			idx++;
227 		}
228 	}
229 	for (idx = 0; idx < IO_RANGES; idx++) {
230 		iores[idx] = platform_get_resource(sparx5->pdev, IORESOURCE_MEM,
231 						   idx);
232 		if (!iores[idx]) {
233 			dev_err(sparx5->dev, "Invalid resource\n");
234 			return -EINVAL;
235 		}
236 		iomem[idx] = devm_ioremap(sparx5->dev,
237 					  iores[idx]->start,
238 					  resource_size(iores[idx]));
239 		if (!iomem[idx]) {
240 			dev_err(sparx5->dev, "Unable to get switch registers: %s\n",
241 				iores[idx]->name);
242 			return -ENOMEM;
243 		}
244 		begin[idx] = iomem[idx] - sparx5_main_iomap[range_id[idx]].offset;
245 	}
246 	for (jdx = 0; jdx < ARRAY_SIZE(sparx5_main_iomap); jdx++) {
247 		const struct sparx5_main_io_resource *iomap = &sparx5_main_iomap[jdx];
248 
249 		sparx5->regs[iomap->id] = begin[iomap->range] + iomap->offset;
250 	}
251 	return 0;
252 }
253 
254 static int sparx5_create_port(struct sparx5 *sparx5,
255 			      struct initial_port_config *config)
256 {
257 	struct sparx5_port *spx5_port;
258 	struct net_device *ndev;
259 	struct phylink *phylink;
260 	int err;
261 
262 	ndev = sparx5_create_netdev(sparx5, config->portno);
263 	if (IS_ERR(ndev)) {
264 		dev_err(sparx5->dev, "Could not create net device: %02u\n",
265 			config->portno);
266 		return PTR_ERR(ndev);
267 	}
268 	spx5_port = netdev_priv(ndev);
269 	spx5_port->of_node = config->node;
270 	spx5_port->serdes = config->serdes;
271 	spx5_port->pvid = NULL_VID;
272 	spx5_port->signd_internal = true;
273 	spx5_port->signd_active_high = true;
274 	spx5_port->signd_enable = true;
275 	spx5_port->max_vlan_tags = SPX5_PORT_MAX_TAGS_NONE;
276 	spx5_port->vlan_type = SPX5_VLAN_PORT_TYPE_UNAWARE;
277 	spx5_port->custom_etype = 0x8880; /* Vitesse */
278 	spx5_port->phylink_pcs.poll = true;
279 	spx5_port->phylink_pcs.ops = &sparx5_phylink_pcs_ops;
280 	spx5_port->is_mrouter = false;
281 	sparx5->ports[config->portno] = spx5_port;
282 
283 	err = sparx5_port_init(sparx5, spx5_port, &config->conf);
284 	if (err) {
285 		dev_err(sparx5->dev, "port init failed\n");
286 		return err;
287 	}
288 	spx5_port->conf = config->conf;
289 
290 	/* Setup VLAN */
291 	sparx5_vlan_port_setup(sparx5, spx5_port->portno);
292 
293 	/* Create a phylink for PHY management.  Also handles SFPs */
294 	spx5_port->phylink_config.dev = &spx5_port->ndev->dev;
295 	spx5_port->phylink_config.type = PHYLINK_NETDEV;
296 	spx5_port->phylink_config.mac_capabilities = MAC_ASYM_PAUSE |
297 		MAC_SYM_PAUSE | MAC_10 | MAC_100 | MAC_1000FD |
298 		MAC_2500FD | MAC_5000FD | MAC_10000FD | MAC_25000FD;
299 
300 	__set_bit(PHY_INTERFACE_MODE_SGMII,
301 		  spx5_port->phylink_config.supported_interfaces);
302 	__set_bit(PHY_INTERFACE_MODE_QSGMII,
303 		  spx5_port->phylink_config.supported_interfaces);
304 	__set_bit(PHY_INTERFACE_MODE_1000BASEX,
305 		  spx5_port->phylink_config.supported_interfaces);
306 	__set_bit(PHY_INTERFACE_MODE_2500BASEX,
307 		  spx5_port->phylink_config.supported_interfaces);
308 
309 	if (spx5_port->conf.bandwidth == SPEED_5000 ||
310 	    spx5_port->conf.bandwidth == SPEED_10000 ||
311 	    spx5_port->conf.bandwidth == SPEED_25000)
312 		__set_bit(PHY_INTERFACE_MODE_5GBASER,
313 			  spx5_port->phylink_config.supported_interfaces);
314 
315 	if (spx5_port->conf.bandwidth == SPEED_10000 ||
316 	    spx5_port->conf.bandwidth == SPEED_25000)
317 		__set_bit(PHY_INTERFACE_MODE_10GBASER,
318 			  spx5_port->phylink_config.supported_interfaces);
319 
320 	if (spx5_port->conf.bandwidth == SPEED_25000)
321 		__set_bit(PHY_INTERFACE_MODE_25GBASER,
322 			  spx5_port->phylink_config.supported_interfaces);
323 
324 	phylink = phylink_create(&spx5_port->phylink_config,
325 				 of_fwnode_handle(config->node),
326 				 config->conf.phy_mode,
327 				 &sparx5_phylink_mac_ops);
328 	if (IS_ERR(phylink))
329 		return PTR_ERR(phylink);
330 
331 	spx5_port->phylink = phylink;
332 
333 	return 0;
334 }
335 
336 static int sparx5_init_ram(struct sparx5 *s5)
337 {
338 	const struct sparx5_ram_config spx5_ram_cfg[] = {
339 		{spx5_reg_get(s5, ANA_AC_STAT_RESET), ANA_AC_STAT_RESET_RESET},
340 		{spx5_reg_get(s5, ASM_STAT_CFG), ASM_STAT_CFG_STAT_CNT_CLR_SHOT},
341 		{spx5_reg_get(s5, QSYS_RAM_INIT), QSYS_RAM_INIT_RAM_INIT},
342 		{spx5_reg_get(s5, REW_RAM_INIT), QSYS_RAM_INIT_RAM_INIT},
343 		{spx5_reg_get(s5, VOP_RAM_INIT), QSYS_RAM_INIT_RAM_INIT},
344 		{spx5_reg_get(s5, ANA_AC_RAM_INIT), QSYS_RAM_INIT_RAM_INIT},
345 		{spx5_reg_get(s5, ASM_RAM_INIT), QSYS_RAM_INIT_RAM_INIT},
346 		{spx5_reg_get(s5, EACL_RAM_INIT), QSYS_RAM_INIT_RAM_INIT},
347 		{spx5_reg_get(s5, VCAP_SUPER_RAM_INIT), QSYS_RAM_INIT_RAM_INIT},
348 		{spx5_reg_get(s5, DSM_RAM_INIT), QSYS_RAM_INIT_RAM_INIT}
349 	};
350 	const struct sparx5_ram_config *cfg;
351 	u32 value, pending, jdx, idx;
352 
353 	for (jdx = 0; jdx < 10; jdx++) {
354 		pending = ARRAY_SIZE(spx5_ram_cfg);
355 		for (idx = 0; idx < ARRAY_SIZE(spx5_ram_cfg); idx++) {
356 			cfg = &spx5_ram_cfg[idx];
357 			if (jdx == 0) {
358 				writel(cfg->init_val, cfg->init_reg);
359 			} else {
360 				value = readl(cfg->init_reg);
361 				if ((value & cfg->init_val) != cfg->init_val)
362 					pending--;
363 			}
364 		}
365 		if (!pending)
366 			break;
367 		usleep_range(USEC_PER_MSEC, 2 * USEC_PER_MSEC);
368 	}
369 
370 	if (pending > 0) {
371 		/* Still initializing, should be complete in
372 		 * less than 1ms
373 		 */
374 		dev_err(s5->dev, "Memory initialization error\n");
375 		return -EINVAL;
376 	}
377 	return 0;
378 }
379 
380 static int sparx5_init_switchcore(struct sparx5 *sparx5)
381 {
382 	u32 value;
383 	int err = 0;
384 
385 	spx5_rmw(EACL_POL_EACL_CFG_EACL_FORCE_INIT_SET(1),
386 		 EACL_POL_EACL_CFG_EACL_FORCE_INIT,
387 		 sparx5,
388 		 EACL_POL_EACL_CFG);
389 
390 	spx5_rmw(EACL_POL_EACL_CFG_EACL_FORCE_INIT_SET(0),
391 		 EACL_POL_EACL_CFG_EACL_FORCE_INIT,
392 		 sparx5,
393 		 EACL_POL_EACL_CFG);
394 
395 	/* Initialize memories, if not done already */
396 	value = spx5_rd(sparx5, HSCH_RESET_CFG);
397 	if (!(value & HSCH_RESET_CFG_CORE_ENA)) {
398 		err = sparx5_init_ram(sparx5);
399 		if (err)
400 			return err;
401 	}
402 
403 	/* Reset counters */
404 	spx5_wr(ANA_AC_STAT_RESET_RESET_SET(1), sparx5, ANA_AC_STAT_RESET);
405 	spx5_wr(ASM_STAT_CFG_STAT_CNT_CLR_SHOT_SET(1), sparx5, ASM_STAT_CFG);
406 
407 	/* Enable switch-core and queue system */
408 	spx5_wr(HSCH_RESET_CFG_CORE_ENA_SET(1), sparx5, HSCH_RESET_CFG);
409 
410 	return 0;
411 }
412 
413 static int sparx5_init_coreclock(struct sparx5 *sparx5)
414 {
415 	enum sparx5_core_clockfreq freq = sparx5->coreclock;
416 	u32 clk_div, clk_period, pol_upd_int, idx;
417 
418 	/* Verify if core clock frequency is supported on target.
419 	 * If 'VTSS_CORE_CLOCK_DEFAULT' then the highest supported
420 	 * freq. is used
421 	 */
422 	switch (sparx5->target_ct) {
423 	case SPX5_TARGET_CT_7546:
424 		if (sparx5->coreclock == SPX5_CORE_CLOCK_DEFAULT)
425 			freq = SPX5_CORE_CLOCK_250MHZ;
426 		else if (sparx5->coreclock != SPX5_CORE_CLOCK_250MHZ)
427 			freq = 0; /* Not supported */
428 		break;
429 	case SPX5_TARGET_CT_7549:
430 	case SPX5_TARGET_CT_7552:
431 	case SPX5_TARGET_CT_7556:
432 		if (sparx5->coreclock == SPX5_CORE_CLOCK_DEFAULT)
433 			freq = SPX5_CORE_CLOCK_500MHZ;
434 		else if (sparx5->coreclock != SPX5_CORE_CLOCK_500MHZ)
435 			freq = 0; /* Not supported */
436 		break;
437 	case SPX5_TARGET_CT_7558:
438 	case SPX5_TARGET_CT_7558TSN:
439 		if (sparx5->coreclock == SPX5_CORE_CLOCK_DEFAULT)
440 			freq = SPX5_CORE_CLOCK_625MHZ;
441 		else if (sparx5->coreclock != SPX5_CORE_CLOCK_625MHZ)
442 			freq = 0; /* Not supported */
443 		break;
444 	case SPX5_TARGET_CT_7546TSN:
445 		if (sparx5->coreclock == SPX5_CORE_CLOCK_DEFAULT)
446 			freq = SPX5_CORE_CLOCK_625MHZ;
447 		break;
448 	case SPX5_TARGET_CT_7549TSN:
449 	case SPX5_TARGET_CT_7552TSN:
450 	case SPX5_TARGET_CT_7556TSN:
451 		if (sparx5->coreclock == SPX5_CORE_CLOCK_DEFAULT)
452 			freq = SPX5_CORE_CLOCK_625MHZ;
453 		else if (sparx5->coreclock == SPX5_CORE_CLOCK_250MHZ)
454 			freq = 0; /* Not supported */
455 		break;
456 	default:
457 		dev_err(sparx5->dev, "Target (%#04x) not supported\n",
458 			sparx5->target_ct);
459 		return -ENODEV;
460 	}
461 
462 	switch (freq) {
463 	case SPX5_CORE_CLOCK_250MHZ:
464 		clk_div = 10;
465 		pol_upd_int = 312;
466 		break;
467 	case SPX5_CORE_CLOCK_500MHZ:
468 		clk_div = 5;
469 		pol_upd_int = 624;
470 		break;
471 	case SPX5_CORE_CLOCK_625MHZ:
472 		clk_div = 4;
473 		pol_upd_int = 780;
474 		break;
475 	default:
476 		dev_err(sparx5->dev, "%d coreclock not supported on (%#04x)\n",
477 			sparx5->coreclock, sparx5->target_ct);
478 		return -EINVAL;
479 	}
480 
481 	/* Update state with chosen frequency */
482 	sparx5->coreclock = freq;
483 
484 	/* Configure the LCPLL */
485 	spx5_rmw(CLKGEN_LCPLL1_CORE_CLK_CFG_CORE_CLK_DIV_SET(clk_div) |
486 		 CLKGEN_LCPLL1_CORE_CLK_CFG_CORE_PRE_DIV_SET(0) |
487 		 CLKGEN_LCPLL1_CORE_CLK_CFG_CORE_ROT_DIR_SET(0) |
488 		 CLKGEN_LCPLL1_CORE_CLK_CFG_CORE_ROT_SEL_SET(0) |
489 		 CLKGEN_LCPLL1_CORE_CLK_CFG_CORE_ROT_ENA_SET(0) |
490 		 CLKGEN_LCPLL1_CORE_CLK_CFG_CORE_CLK_ENA_SET(1),
491 		 CLKGEN_LCPLL1_CORE_CLK_CFG_CORE_CLK_DIV |
492 		 CLKGEN_LCPLL1_CORE_CLK_CFG_CORE_PRE_DIV |
493 		 CLKGEN_LCPLL1_CORE_CLK_CFG_CORE_ROT_DIR |
494 		 CLKGEN_LCPLL1_CORE_CLK_CFG_CORE_ROT_SEL |
495 		 CLKGEN_LCPLL1_CORE_CLK_CFG_CORE_ROT_ENA |
496 		 CLKGEN_LCPLL1_CORE_CLK_CFG_CORE_CLK_ENA,
497 		 sparx5,
498 		 CLKGEN_LCPLL1_CORE_CLK_CFG);
499 
500 	clk_period = sparx5_clk_period(freq);
501 
502 	spx5_rmw(HSCH_SYS_CLK_PER_SYS_CLK_PER_100PS_SET(clk_period / 100),
503 		 HSCH_SYS_CLK_PER_SYS_CLK_PER_100PS,
504 		 sparx5,
505 		 HSCH_SYS_CLK_PER);
506 
507 	spx5_rmw(ANA_AC_POL_BDLB_DLB_CTRL_CLK_PERIOD_01NS_SET(clk_period / 100),
508 		 ANA_AC_POL_BDLB_DLB_CTRL_CLK_PERIOD_01NS,
509 		 sparx5,
510 		 ANA_AC_POL_BDLB_DLB_CTRL);
511 
512 	spx5_rmw(ANA_AC_POL_SLB_DLB_CTRL_CLK_PERIOD_01NS_SET(clk_period / 100),
513 		 ANA_AC_POL_SLB_DLB_CTRL_CLK_PERIOD_01NS,
514 		 sparx5,
515 		 ANA_AC_POL_SLB_DLB_CTRL);
516 
517 	spx5_rmw(LRN_AUTOAGE_CFG_1_CLK_PERIOD_01NS_SET(clk_period / 100),
518 		 LRN_AUTOAGE_CFG_1_CLK_PERIOD_01NS,
519 		 sparx5,
520 		 LRN_AUTOAGE_CFG_1);
521 
522 	for (idx = 0; idx < 3; idx++)
523 		spx5_rmw(GCB_SIO_CLOCK_SYS_CLK_PERIOD_SET(clk_period / 100),
524 			 GCB_SIO_CLOCK_SYS_CLK_PERIOD,
525 			 sparx5,
526 			 GCB_SIO_CLOCK(idx));
527 
528 	spx5_rmw(HSCH_TAS_STATEMACHINE_CFG_REVISIT_DLY_SET
529 		 ((256 * 1000) / clk_period),
530 		 HSCH_TAS_STATEMACHINE_CFG_REVISIT_DLY,
531 		 sparx5,
532 		 HSCH_TAS_STATEMACHINE_CFG);
533 
534 	spx5_rmw(ANA_AC_POL_POL_UPD_INT_CFG_POL_UPD_INT_SET(pol_upd_int),
535 		 ANA_AC_POL_POL_UPD_INT_CFG_POL_UPD_INT,
536 		 sparx5,
537 		 ANA_AC_POL_POL_UPD_INT_CFG);
538 
539 	return 0;
540 }
541 
542 static int sparx5_qlim_set(struct sparx5 *sparx5)
543 {
544 	u32 res, dp, prio;
545 
546 	for (res = 0; res < 2; res++) {
547 		for (prio = 0; prio < 8; prio++)
548 			spx5_wr(0xFFF, sparx5,
549 				QRES_RES_CFG(prio + 630 + res * 1024));
550 
551 		for (dp = 0; dp < 4; dp++)
552 			spx5_wr(0xFFF, sparx5,
553 				QRES_RES_CFG(dp + 638 + res * 1024));
554 	}
555 
556 	/* Set 80,90,95,100% of memory size for top watermarks */
557 	spx5_wr(QLIM_WM(80), sparx5, XQS_QLIMIT_SHR_QLIM_CFG(0));
558 	spx5_wr(QLIM_WM(90), sparx5, XQS_QLIMIT_SHR_CTOP_CFG(0));
559 	spx5_wr(QLIM_WM(95), sparx5, XQS_QLIMIT_SHR_ATOP_CFG(0));
560 	spx5_wr(QLIM_WM(100), sparx5, XQS_QLIMIT_SHR_TOP_CFG(0));
561 
562 	return 0;
563 }
564 
565 /* Some boards needs to map the SGPIO for signal detect explicitly to the
566  * port module
567  */
568 static void sparx5_board_init(struct sparx5 *sparx5)
569 {
570 	int idx;
571 
572 	if (!sparx5->sd_sgpio_remapping)
573 		return;
574 
575 	/* Enable SGPIO Signal Detect remapping */
576 	spx5_rmw(GCB_HW_SGPIO_SD_CFG_SD_MAP_SEL,
577 		 GCB_HW_SGPIO_SD_CFG_SD_MAP_SEL,
578 		 sparx5,
579 		 GCB_HW_SGPIO_SD_CFG);
580 
581 	/* Refer to LOS SGPIO */
582 	for (idx = 0; idx < SPX5_PORTS; idx++)
583 		if (sparx5->ports[idx])
584 			if (sparx5->ports[idx]->conf.sd_sgpio != ~0)
585 				spx5_wr(sparx5->ports[idx]->conf.sd_sgpio,
586 					sparx5,
587 					GCB_HW_SGPIO_TO_SD_MAP_CFG(idx));
588 }
589 
590 static int sparx5_start(struct sparx5 *sparx5)
591 {
592 	u8 broadcast[ETH_ALEN] = {0xff, 0xff, 0xff, 0xff, 0xff, 0xff};
593 	char queue_name[32];
594 	u32 idx;
595 	int err;
596 
597 	/* Setup own UPSIDs */
598 	for (idx = 0; idx < 3; idx++) {
599 		spx5_wr(idx, sparx5, ANA_AC_OWN_UPSID(idx));
600 		spx5_wr(idx, sparx5, ANA_CL_OWN_UPSID(idx));
601 		spx5_wr(idx, sparx5, ANA_L2_OWN_UPSID(idx));
602 		spx5_wr(idx, sparx5, REW_OWN_UPSID(idx));
603 	}
604 
605 	/* Enable CPU ports */
606 	for (idx = SPX5_PORTS; idx < SPX5_PORTS_ALL; idx++)
607 		spx5_rmw(QFWD_SWITCH_PORT_MODE_PORT_ENA_SET(1),
608 			 QFWD_SWITCH_PORT_MODE_PORT_ENA,
609 			 sparx5,
610 			 QFWD_SWITCH_PORT_MODE(idx));
611 
612 	/* Init masks */
613 	sparx5_update_fwd(sparx5);
614 
615 	/* CPU copy CPU pgids */
616 	spx5_wr(ANA_AC_PGID_MISC_CFG_PGID_CPU_COPY_ENA_SET(1),
617 		sparx5, ANA_AC_PGID_MISC_CFG(PGID_CPU));
618 	spx5_wr(ANA_AC_PGID_MISC_CFG_PGID_CPU_COPY_ENA_SET(1),
619 		sparx5, ANA_AC_PGID_MISC_CFG(PGID_BCAST));
620 
621 	/* Recalc injected frame FCS */
622 	for (idx = SPX5_PORT_CPU_0; idx <= SPX5_PORT_CPU_1; idx++)
623 		spx5_rmw(ANA_CL_FILTER_CTRL_FORCE_FCS_UPDATE_ENA_SET(1),
624 			 ANA_CL_FILTER_CTRL_FORCE_FCS_UPDATE_ENA,
625 			 sparx5, ANA_CL_FILTER_CTRL(idx));
626 
627 	/* Init MAC table, ageing */
628 	sparx5_mact_init(sparx5);
629 
630 	/* Init PGID table arbitrator */
631 	sparx5_pgid_init(sparx5);
632 
633 	/* Setup VLANs */
634 	sparx5_vlan_init(sparx5);
635 
636 	/* Add host mode BC address (points only to CPU) */
637 	sparx5_mact_learn(sparx5, PGID_CPU, broadcast, NULL_VID);
638 
639 	/* Enable queue limitation watermarks */
640 	sparx5_qlim_set(sparx5);
641 
642 	err = sparx5_config_auto_calendar(sparx5);
643 	if (err)
644 		return err;
645 
646 	err = sparx5_config_dsm_calendar(sparx5);
647 	if (err)
648 		return err;
649 
650 	/* Init stats */
651 	err = sparx_stats_init(sparx5);
652 	if (err)
653 		return err;
654 
655 	/* Init mact_sw struct */
656 	mutex_init(&sparx5->mact_lock);
657 	INIT_LIST_HEAD(&sparx5->mact_entries);
658 	snprintf(queue_name, sizeof(queue_name), "%s-mact",
659 		 dev_name(sparx5->dev));
660 	sparx5->mact_queue = create_singlethread_workqueue(queue_name);
661 	INIT_DELAYED_WORK(&sparx5->mact_work, sparx5_mact_pull_work);
662 	queue_delayed_work(sparx5->mact_queue, &sparx5->mact_work,
663 			   SPX5_MACT_PULL_DELAY);
664 
665 	mutex_init(&sparx5->mdb_lock);
666 	INIT_LIST_HEAD(&sparx5->mdb_entries);
667 
668 	err = sparx5_register_netdevs(sparx5);
669 	if (err)
670 		return err;
671 
672 	sparx5_board_init(sparx5);
673 	err = sparx5_register_notifier_blocks(sparx5);
674 
675 	/* Start Frame DMA with fallback to register based INJ/XTR */
676 	err = -ENXIO;
677 	if (sparx5->fdma_irq >= 0) {
678 		if (GCB_CHIP_ID_REV_ID_GET(sparx5->chip_id) > 0)
679 			err = devm_request_threaded_irq(sparx5->dev,
680 							sparx5->fdma_irq,
681 							NULL,
682 							sparx5_fdma_handler,
683 							IRQF_ONESHOT,
684 							"sparx5-fdma", sparx5);
685 		if (!err)
686 			err = sparx5_fdma_start(sparx5);
687 		if (err)
688 			sparx5->fdma_irq = -ENXIO;
689 	} else {
690 		sparx5->fdma_irq = -ENXIO;
691 	}
692 	if (err && sparx5->xtr_irq >= 0) {
693 		err = devm_request_irq(sparx5->dev, sparx5->xtr_irq,
694 				       sparx5_xtr_handler, IRQF_SHARED,
695 				       "sparx5-xtr", sparx5);
696 		if (!err)
697 			err = sparx5_manual_injection_mode(sparx5);
698 		if (err)
699 			sparx5->xtr_irq = -ENXIO;
700 	} else {
701 		sparx5->xtr_irq = -ENXIO;
702 	}
703 
704 	if (sparx5->ptp_irq >= 0) {
705 		err = devm_request_threaded_irq(sparx5->dev, sparx5->ptp_irq,
706 						NULL, sparx5_ptp_irq_handler,
707 						IRQF_ONESHOT, "sparx5-ptp",
708 						sparx5);
709 		if (err)
710 			sparx5->ptp_irq = -ENXIO;
711 
712 		sparx5->ptp = 1;
713 	}
714 
715 	return err;
716 }
717 
718 static void sparx5_cleanup_ports(struct sparx5 *sparx5)
719 {
720 	sparx5_unregister_netdevs(sparx5);
721 	sparx5_destroy_netdevs(sparx5);
722 }
723 
724 static int mchp_sparx5_probe(struct platform_device *pdev)
725 {
726 	struct initial_port_config *configs, *config;
727 	struct device_node *np = pdev->dev.of_node;
728 	struct device_node *ports, *portnp;
729 	struct reset_control *reset;
730 	struct sparx5 *sparx5;
731 	int idx = 0, err = 0;
732 
733 	if (!np && !pdev->dev.platform_data)
734 		return -ENODEV;
735 
736 	sparx5 = devm_kzalloc(&pdev->dev, sizeof(*sparx5), GFP_KERNEL);
737 	if (!sparx5)
738 		return -ENOMEM;
739 
740 	platform_set_drvdata(pdev, sparx5);
741 	sparx5->pdev = pdev;
742 	sparx5->dev = &pdev->dev;
743 
744 	/* Do switch core reset if available */
745 	reset = devm_reset_control_get_optional_shared(&pdev->dev, "switch");
746 	if (IS_ERR(reset))
747 		return dev_err_probe(&pdev->dev, PTR_ERR(reset),
748 				     "Failed to get switch reset controller.\n");
749 	reset_control_reset(reset);
750 
751 	/* Default values, some from DT */
752 	sparx5->coreclock = SPX5_CORE_CLOCK_DEFAULT;
753 
754 	ports = of_get_child_by_name(np, "ethernet-ports");
755 	if (!ports) {
756 		dev_err(sparx5->dev, "no ethernet-ports child node found\n");
757 		return -ENODEV;
758 	}
759 	sparx5->port_count = of_get_child_count(ports);
760 
761 	configs = kcalloc(sparx5->port_count,
762 			  sizeof(struct initial_port_config), GFP_KERNEL);
763 	if (!configs) {
764 		err = -ENOMEM;
765 		goto cleanup_pnode;
766 	}
767 
768 	for_each_available_child_of_node(ports, portnp) {
769 		struct sparx5_port_config *conf;
770 		struct phy *serdes;
771 		u32 portno;
772 
773 		err = of_property_read_u32(portnp, "reg", &portno);
774 		if (err) {
775 			dev_err(sparx5->dev, "port reg property error\n");
776 			continue;
777 		}
778 		config = &configs[idx];
779 		conf = &config->conf;
780 		conf->speed = SPEED_UNKNOWN;
781 		conf->bandwidth = SPEED_UNKNOWN;
782 		err = of_get_phy_mode(portnp, &conf->phy_mode);
783 		if (err) {
784 			dev_err(sparx5->dev, "port %u: missing phy-mode\n",
785 				portno);
786 			continue;
787 		}
788 		err = of_property_read_u32(portnp, "microchip,bandwidth",
789 					   &conf->bandwidth);
790 		if (err) {
791 			dev_err(sparx5->dev, "port %u: missing bandwidth\n",
792 				portno);
793 			continue;
794 		}
795 		err = of_property_read_u32(portnp, "microchip,sd-sgpio", &conf->sd_sgpio);
796 		if (err)
797 			conf->sd_sgpio = ~0;
798 		else
799 			sparx5->sd_sgpio_remapping = true;
800 		serdes = devm_of_phy_get(sparx5->dev, portnp, NULL);
801 		if (IS_ERR(serdes)) {
802 			err = dev_err_probe(sparx5->dev, PTR_ERR(serdes),
803 					    "port %u: missing serdes\n",
804 					    portno);
805 			of_node_put(portnp);
806 			goto cleanup_config;
807 		}
808 		config->portno = portno;
809 		config->node = portnp;
810 		config->serdes = serdes;
811 
812 		conf->media = PHY_MEDIA_DAC;
813 		conf->serdes_reset = true;
814 		conf->portmode = conf->phy_mode;
815 		conf->power_down = true;
816 		idx++;
817 	}
818 
819 	err = sparx5_create_targets(sparx5);
820 	if (err)
821 		goto cleanup_config;
822 
823 	if (!of_get_mac_address(np, sparx5->base_mac)) {
824 		dev_info(sparx5->dev, "MAC addr was not set, use random MAC\n");
825 		eth_random_addr(sparx5->base_mac);
826 		sparx5->base_mac[5] = 0;
827 	}
828 
829 	sparx5->fdma_irq = platform_get_irq_byname(sparx5->pdev, "fdma");
830 	sparx5->xtr_irq = platform_get_irq_byname(sparx5->pdev, "xtr");
831 	sparx5->ptp_irq = platform_get_irq_byname(sparx5->pdev, "ptp");
832 
833 	/* Read chip ID to check CPU interface */
834 	sparx5->chip_id = spx5_rd(sparx5, GCB_CHIP_ID);
835 
836 	sparx5->target_ct = (enum spx5_target_chiptype)
837 		GCB_CHIP_ID_PART_ID_GET(sparx5->chip_id);
838 
839 	/* Initialize Switchcore and internal RAMs */
840 	err = sparx5_init_switchcore(sparx5);
841 	if (err) {
842 		dev_err(sparx5->dev, "Switchcore initialization error\n");
843 		goto cleanup_config;
844 	}
845 
846 	/* Initialize the LC-PLL (core clock) and set affected registers */
847 	err = sparx5_init_coreclock(sparx5);
848 	if (err) {
849 		dev_err(sparx5->dev, "LC-PLL initialization error\n");
850 		goto cleanup_config;
851 	}
852 
853 	for (idx = 0; idx < sparx5->port_count; ++idx) {
854 		config = &configs[idx];
855 		if (!config->node)
856 			continue;
857 
858 		err = sparx5_create_port(sparx5, config);
859 		if (err) {
860 			dev_err(sparx5->dev, "port create error\n");
861 			goto cleanup_ports;
862 		}
863 	}
864 
865 	err = sparx5_start(sparx5);
866 	if (err) {
867 		dev_err(sparx5->dev, "Start failed\n");
868 		goto cleanup_ports;
869 	}
870 
871 	err = sparx5_ptp_init(sparx5);
872 	if (err) {
873 		dev_err(sparx5->dev, "PTP failed\n");
874 		goto cleanup_ports;
875 	}
876 	goto cleanup_config;
877 
878 cleanup_ports:
879 	sparx5_cleanup_ports(sparx5);
880 cleanup_config:
881 	kfree(configs);
882 cleanup_pnode:
883 	of_node_put(ports);
884 	return err;
885 }
886 
887 static int mchp_sparx5_remove(struct platform_device *pdev)
888 {
889 	struct sparx5 *sparx5 = platform_get_drvdata(pdev);
890 
891 	if (sparx5->xtr_irq) {
892 		disable_irq(sparx5->xtr_irq);
893 		sparx5->xtr_irq = -ENXIO;
894 	}
895 	if (sparx5->fdma_irq) {
896 		disable_irq(sparx5->fdma_irq);
897 		sparx5->fdma_irq = -ENXIO;
898 	}
899 	sparx5_ptp_deinit(sparx5);
900 	sparx5_fdma_stop(sparx5);
901 	sparx5_cleanup_ports(sparx5);
902 	/* Unregister netdevs */
903 	sparx5_unregister_notifier_blocks(sparx5);
904 
905 	return 0;
906 }
907 
908 static const struct of_device_id mchp_sparx5_match[] = {
909 	{ .compatible = "microchip,sparx5-switch" },
910 	{ }
911 };
912 MODULE_DEVICE_TABLE(of, mchp_sparx5_match);
913 
914 static struct platform_driver mchp_sparx5_driver = {
915 	.probe = mchp_sparx5_probe,
916 	.remove = mchp_sparx5_remove,
917 	.driver = {
918 		.name = "sparx5-switch",
919 		.of_match_table = mchp_sparx5_match,
920 	},
921 };
922 
923 module_platform_driver(mchp_sparx5_driver);
924 
925 MODULE_DESCRIPTION("Microchip Sparx5 switch driver");
926 MODULE_AUTHOR("Steen Hegelund <steen.hegelund@microchip.com>");
927 MODULE_LICENSE("Dual MIT/GPL");
928