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 ret = mv88e6xxx_reg_write(ds, REG_GLOBAL, GLOBAL_CONTROL,
63 GLOBAL_CONTROL_PPU_ENABLE |
64 GLOBAL_CONTROL_DISCARD_EXCESS);
68 /* Configure the upstream port, and configure the upstream
69 * port as the port to which ingress and egress monitor frames
72 reg = upstream_port << GLOBAL_MONITOR_CONTROL_INGRESS_SHIFT |
73 upstream_port << GLOBAL_MONITOR_CONTROL_EGRESS_SHIFT |
74 upstream_port << GLOBAL_MONITOR_CONTROL_ARP_SHIFT;
75 ret = mv88e6xxx_reg_write(ds, REG_GLOBAL, GLOBAL_MONITOR_CONTROL, reg);
79 /* Disable remote management for now, and set the switch's
82 return mv88e6xxx_reg_write(ds, REG_GLOBAL, 0x1c, ds->index & 0x1f);
85 static int mv88e6352_setup(struct dsa_switch *ds)
87 struct mv88e6xxx_priv_state *ps = ds_to_priv(ds);
92 ret = mv88e6xxx_setup_common(ds);
98 mutex_init(&ps->eeprom_mutex);
100 ret = mv88e6xxx_switch_reset(ds, true);
104 ret = mv88e6352_setup_global(ds);
108 return mv88e6xxx_setup_ports(ds);
111 static int mv88e6352_read_eeprom_word(struct dsa_switch *ds, int addr)
113 struct mv88e6xxx_priv_state *ps = ds_to_priv(ds);
116 mutex_lock(&ps->eeprom_mutex);
118 ret = mv88e6xxx_reg_write(ds, REG_GLOBAL2, GLOBAL2_EEPROM_OP,
119 GLOBAL2_EEPROM_OP_READ |
120 (addr & GLOBAL2_EEPROM_OP_ADDR_MASK));
124 ret = mv88e6xxx_eeprom_busy_wait(ds);
128 ret = mv88e6xxx_reg_read(ds, REG_GLOBAL2, GLOBAL2_EEPROM_DATA);
130 mutex_unlock(&ps->eeprom_mutex);
134 static int mv88e6352_get_eeprom(struct dsa_switch *ds,
135 struct ethtool_eeprom *eeprom, u8 *data)
141 offset = eeprom->offset;
145 eeprom->magic = 0xc3ec4951;
147 ret = mv88e6xxx_eeprom_load_wait(ds);
154 word = mv88e6352_read_eeprom_word(ds, offset >> 1);
158 *data++ = (word >> 8) & 0xff;
168 word = mv88e6352_read_eeprom_word(ds, offset >> 1);
172 *data++ = word & 0xff;
173 *data++ = (word >> 8) & 0xff;
183 word = mv88e6352_read_eeprom_word(ds, offset >> 1);
187 *data++ = word & 0xff;
197 static int mv88e6352_eeprom_is_readonly(struct dsa_switch *ds)
201 ret = mv88e6xxx_reg_read(ds, REG_GLOBAL2, GLOBAL2_EEPROM_OP);
205 if (!(ret & GLOBAL2_EEPROM_OP_WRITE_EN))
211 static int mv88e6352_write_eeprom_word(struct dsa_switch *ds, int addr,
214 struct mv88e6xxx_priv_state *ps = ds_to_priv(ds);
217 mutex_lock(&ps->eeprom_mutex);
219 ret = mv88e6xxx_reg_write(ds, REG_GLOBAL2, GLOBAL2_EEPROM_DATA, data);
223 ret = mv88e6xxx_reg_write(ds, REG_GLOBAL2, GLOBAL2_EEPROM_OP,
224 GLOBAL2_EEPROM_OP_WRITE |
225 (addr & GLOBAL2_EEPROM_OP_ADDR_MASK));
229 ret = mv88e6xxx_eeprom_busy_wait(ds);
231 mutex_unlock(&ps->eeprom_mutex);
235 static int mv88e6352_set_eeprom(struct dsa_switch *ds,
236 struct ethtool_eeprom *eeprom, u8 *data)
242 if (eeprom->magic != 0xc3ec4951)
245 ret = mv88e6352_eeprom_is_readonly(ds);
249 offset = eeprom->offset;
253 ret = mv88e6xxx_eeprom_load_wait(ds);
260 word = mv88e6352_read_eeprom_word(ds, offset >> 1);
264 word = (*data++ << 8) | (word & 0xff);
266 ret = mv88e6352_write_eeprom_word(ds, offset >> 1, word);
279 word |= *data++ << 8;
281 ret = mv88e6352_write_eeprom_word(ds, offset >> 1, word);
293 word = mv88e6352_read_eeprom_word(ds, offset >> 1);
297 word = (word & 0xff00) | *data++;
299 ret = mv88e6352_write_eeprom_word(ds, offset >> 1, word);
311 struct dsa_switch_driver mv88e6352_switch_driver = {
312 .tag_protocol = DSA_TAG_PROTO_EDSA,
313 .probe = mv88e6352_drv_probe,
314 .setup = mv88e6352_setup,
315 .set_addr = mv88e6xxx_set_addr_indirect,
316 .phy_read = mv88e6xxx_phy_read_indirect,
317 .phy_write = mv88e6xxx_phy_write_indirect,
318 .get_strings = mv88e6xxx_get_strings,
319 .get_ethtool_stats = mv88e6xxx_get_ethtool_stats,
320 .get_sset_count = mv88e6xxx_get_sset_count,
321 .adjust_link = mv88e6xxx_adjust_link,
322 .set_eee = mv88e6xxx_set_eee,
323 .get_eee = mv88e6xxx_get_eee,
324 #ifdef CONFIG_NET_DSA_HWMON
325 .get_temp = mv88e6xxx_get_temp,
326 .get_temp_limit = mv88e6xxx_get_temp_limit,
327 .set_temp_limit = mv88e6xxx_set_temp_limit,
328 .get_temp_alarm = mv88e6xxx_get_temp_alarm,
330 .get_eeprom = mv88e6352_get_eeprom,
331 .set_eeprom = mv88e6352_set_eeprom,
332 .get_regs_len = mv88e6xxx_get_regs_len,
333 .get_regs = mv88e6xxx_get_regs,
334 .port_bridge_join = mv88e6xxx_port_bridge_join,
335 .port_bridge_leave = mv88e6xxx_port_bridge_leave,
336 .port_stp_state_set = mv88e6xxx_port_stp_state_set,
337 .port_vlan_filtering = mv88e6xxx_port_vlan_filtering,
338 .port_vlan_prepare = mv88e6xxx_port_vlan_prepare,
339 .port_vlan_add = mv88e6xxx_port_vlan_add,
340 .port_vlan_del = mv88e6xxx_port_vlan_del,
341 .port_vlan_dump = mv88e6xxx_port_vlan_dump,
342 .port_fdb_prepare = mv88e6xxx_port_fdb_prepare,
343 .port_fdb_add = mv88e6xxx_port_fdb_add,
344 .port_fdb_del = mv88e6xxx_port_fdb_del,
345 .port_fdb_dump = mv88e6xxx_port_fdb_dump,
348 MODULE_ALIAS("platform:mv88e6172");
349 MODULE_ALIAS("platform:mv88e6176");
350 MODULE_ALIAS("platform:mv88e6320");
351 MODULE_ALIAS("platform:mv88e6321");
352 MODULE_ALIAS("platform:mv88e6352");