2 * net/dsa/mv88e6352.c - Marvell 88e6352 switch chip support
4 * Copyright (c) 2014 Guenter Roeck
6 * Derived from mv88e6123_61_65.c
7 * Copyright (c) 2008-2009 Marvell Semiconductor
9 * This program is free software; you can redistribute it and/or modify
10 * it under the terms of the GNU General Public License as published by
11 * the Free Software Foundation; either version 2 of the License, or
12 * (at your option) any later version.
15 #include <linux/delay.h>
16 #include <linux/jiffies.h>
17 #include <linux/list.h>
18 #include <linux/module.h>
19 #include <linux/netdevice.h>
20 #include <linux/platform_device.h>
21 #include <linux/phy.h>
23 #include "mv88e6xxx.h"
25 static const struct mv88e6xxx_switch_id mv88e6352_table[] = {
26 { PORT_SWITCH_ID_6172, "Marvell 88E6172" },
27 { PORT_SWITCH_ID_6176, "Marvell 88E6176" },
28 { PORT_SWITCH_ID_6240, "Marvell 88E6240" },
29 { PORT_SWITCH_ID_6320, "Marvell 88E6320" },
30 { PORT_SWITCH_ID_6320_A1, "Marvell 88E6320 (A1)" },
31 { PORT_SWITCH_ID_6320_A2, "Marvell 88e6320 (A2)" },
32 { PORT_SWITCH_ID_6321, "Marvell 88E6321" },
33 { PORT_SWITCH_ID_6321_A1, "Marvell 88E6321 (A1)" },
34 { PORT_SWITCH_ID_6321_A2, "Marvell 88e6321 (A2)" },
35 { PORT_SWITCH_ID_6352, "Marvell 88E6352" },
36 { PORT_SWITCH_ID_6352_A0, "Marvell 88E6352 (A0)" },
37 { PORT_SWITCH_ID_6352_A1, "Marvell 88E6352 (A1)" },
40 static char *mv88e6352_drv_probe(struct device *dsa_dev,
41 struct device *host_dev,
42 int sw_addr, void **priv)
44 return mv88e6xxx_drv_probe(dsa_dev, host_dev, sw_addr, priv,
46 ARRAY_SIZE(mv88e6352_table));
49 static int mv88e6352_setup_global(struct dsa_switch *ds)
51 u32 upstream_port = dsa_upstream_port(ds);
55 ret = mv88e6xxx_setup_global(ds);
59 /* Discard packets with excessive collisions,
60 * mask all interrupt sources, enable PPU (bit 14, undocumented).
62 REG_WRITE(REG_GLOBAL, GLOBAL_CONTROL,
63 GLOBAL_CONTROL_PPU_ENABLE | GLOBAL_CONTROL_DISCARD_EXCESS);
65 /* Configure the upstream port, and configure the upstream
66 * port as the port to which ingress and egress monitor frames
69 reg = upstream_port << GLOBAL_MONITOR_CONTROL_INGRESS_SHIFT |
70 upstream_port << GLOBAL_MONITOR_CONTROL_EGRESS_SHIFT |
71 upstream_port << GLOBAL_MONITOR_CONTROL_ARP_SHIFT;
72 REG_WRITE(REG_GLOBAL, GLOBAL_MONITOR_CONTROL, reg);
74 /* Disable remote management for now, and set the switch's
77 REG_WRITE(REG_GLOBAL, 0x1c, ds->index & 0x1f);
82 static int mv88e6352_setup(struct dsa_switch *ds)
84 struct mv88e6xxx_priv_state *ps = ds_to_priv(ds);
89 ret = mv88e6xxx_setup_common(ds);
95 mutex_init(&ps->eeprom_mutex);
97 ret = mv88e6xxx_switch_reset(ds, true);
101 ret = mv88e6352_setup_global(ds);
105 return mv88e6xxx_setup_ports(ds);
108 static int mv88e6352_read_eeprom_word(struct dsa_switch *ds, int addr)
110 struct mv88e6xxx_priv_state *ps = ds_to_priv(ds);
113 mutex_lock(&ps->eeprom_mutex);
115 ret = mv88e6xxx_reg_write(ds, REG_GLOBAL2, GLOBAL2_EEPROM_OP,
116 GLOBAL2_EEPROM_OP_READ |
117 (addr & GLOBAL2_EEPROM_OP_ADDR_MASK));
121 ret = mv88e6xxx_eeprom_busy_wait(ds);
125 ret = mv88e6xxx_reg_read(ds, REG_GLOBAL2, GLOBAL2_EEPROM_DATA);
127 mutex_unlock(&ps->eeprom_mutex);
131 static int mv88e6352_get_eeprom(struct dsa_switch *ds,
132 struct ethtool_eeprom *eeprom, u8 *data)
138 offset = eeprom->offset;
142 eeprom->magic = 0xc3ec4951;
144 ret = mv88e6xxx_eeprom_load_wait(ds);
151 word = mv88e6352_read_eeprom_word(ds, offset >> 1);
155 *data++ = (word >> 8) & 0xff;
165 word = mv88e6352_read_eeprom_word(ds, offset >> 1);
169 *data++ = word & 0xff;
170 *data++ = (word >> 8) & 0xff;
180 word = mv88e6352_read_eeprom_word(ds, offset >> 1);
184 *data++ = word & 0xff;
194 static int mv88e6352_eeprom_is_readonly(struct dsa_switch *ds)
198 ret = mv88e6xxx_reg_read(ds, REG_GLOBAL2, GLOBAL2_EEPROM_OP);
202 if (!(ret & GLOBAL2_EEPROM_OP_WRITE_EN))
208 static int mv88e6352_write_eeprom_word(struct dsa_switch *ds, int addr,
211 struct mv88e6xxx_priv_state *ps = ds_to_priv(ds);
214 mutex_lock(&ps->eeprom_mutex);
216 ret = mv88e6xxx_reg_write(ds, REG_GLOBAL2, GLOBAL2_EEPROM_DATA, data);
220 ret = mv88e6xxx_reg_write(ds, REG_GLOBAL2, GLOBAL2_EEPROM_OP,
221 GLOBAL2_EEPROM_OP_WRITE |
222 (addr & GLOBAL2_EEPROM_OP_ADDR_MASK));
226 ret = mv88e6xxx_eeprom_busy_wait(ds);
228 mutex_unlock(&ps->eeprom_mutex);
232 static int mv88e6352_set_eeprom(struct dsa_switch *ds,
233 struct ethtool_eeprom *eeprom, u8 *data)
239 if (eeprom->magic != 0xc3ec4951)
242 ret = mv88e6352_eeprom_is_readonly(ds);
246 offset = eeprom->offset;
250 ret = mv88e6xxx_eeprom_load_wait(ds);
257 word = mv88e6352_read_eeprom_word(ds, offset >> 1);
261 word = (*data++ << 8) | (word & 0xff);
263 ret = mv88e6352_write_eeprom_word(ds, offset >> 1, word);
276 word |= *data++ << 8;
278 ret = mv88e6352_write_eeprom_word(ds, offset >> 1, word);
290 word = mv88e6352_read_eeprom_word(ds, offset >> 1);
294 word = (word & 0xff00) | *data++;
296 ret = mv88e6352_write_eeprom_word(ds, offset >> 1, word);
308 struct dsa_switch_driver mv88e6352_switch_driver = {
309 .tag_protocol = DSA_TAG_PROTO_EDSA,
310 .probe = mv88e6352_drv_probe,
311 .setup = mv88e6352_setup,
312 .set_addr = mv88e6xxx_set_addr_indirect,
313 .phy_read = mv88e6xxx_phy_read_indirect,
314 .phy_write = mv88e6xxx_phy_write_indirect,
315 .get_strings = mv88e6xxx_get_strings,
316 .get_ethtool_stats = mv88e6xxx_get_ethtool_stats,
317 .get_sset_count = mv88e6xxx_get_sset_count,
318 .adjust_link = mv88e6xxx_adjust_link,
319 .set_eee = mv88e6xxx_set_eee,
320 .get_eee = mv88e6xxx_get_eee,
321 #ifdef CONFIG_NET_DSA_HWMON
322 .get_temp = mv88e6xxx_get_temp,
323 .get_temp_limit = mv88e6xxx_get_temp_limit,
324 .set_temp_limit = mv88e6xxx_set_temp_limit,
325 .get_temp_alarm = mv88e6xxx_get_temp_alarm,
327 .get_eeprom = mv88e6352_get_eeprom,
328 .set_eeprom = mv88e6352_set_eeprom,
329 .get_regs_len = mv88e6xxx_get_regs_len,
330 .get_regs = mv88e6xxx_get_regs,
331 .port_bridge_join = mv88e6xxx_port_bridge_join,
332 .port_bridge_leave = mv88e6xxx_port_bridge_leave,
333 .port_stp_state_set = mv88e6xxx_port_stp_state_set,
334 .port_vlan_filtering = mv88e6xxx_port_vlan_filtering,
335 .port_vlan_prepare = mv88e6xxx_port_vlan_prepare,
336 .port_vlan_add = mv88e6xxx_port_vlan_add,
337 .port_vlan_del = mv88e6xxx_port_vlan_del,
338 .port_vlan_dump = mv88e6xxx_port_vlan_dump,
339 .port_fdb_prepare = mv88e6xxx_port_fdb_prepare,
340 .port_fdb_add = mv88e6xxx_port_fdb_add,
341 .port_fdb_del = mv88e6xxx_port_fdb_del,
342 .port_fdb_dump = mv88e6xxx_port_fdb_dump,
345 MODULE_ALIAS("platform:mv88e6172");
346 MODULE_ALIAS("platform:mv88e6176");
347 MODULE_ALIAS("platform:mv88e6320");
348 MODULE_ALIAS("platform:mv88e6321");
349 MODULE_ALIAS("platform:mv88e6352");