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 char *mv88e6352_probe(struct device *host_dev, int sw_addr)
27 struct mii_bus *bus = dsa_host_dev_to_mii_bus(host_dev);
33 ret = __mv88e6xxx_reg_read(bus, sw_addr, REG_PORT(0), PORT_SWITCH_ID);
35 if ((ret & 0xfff0) == PORT_SWITCH_ID_6172)
36 return "Marvell 88E6172";
37 if ((ret & 0xfff0) == PORT_SWITCH_ID_6176)
38 return "Marvell 88E6176";
39 if (ret == PORT_SWITCH_ID_6320_A1)
40 return "Marvell 88E6320 (A1)";
41 if (ret == PORT_SWITCH_ID_6320_A2)
42 return "Marvell 88e6320 (A2)";
43 if ((ret & 0xfff0) == PORT_SWITCH_ID_6320)
44 return "Marvell 88E6320";
45 if (ret == PORT_SWITCH_ID_6321_A1)
46 return "Marvell 88E6321 (A1)";
47 if (ret == PORT_SWITCH_ID_6321_A2)
48 return "Marvell 88e6321 (A2)";
49 if ((ret & 0xfff0) == PORT_SWITCH_ID_6321)
50 return "Marvell 88E6321";
51 if (ret == PORT_SWITCH_ID_6352_A0)
52 return "Marvell 88E6352 (A0)";
53 if (ret == PORT_SWITCH_ID_6352_A1)
54 return "Marvell 88E6352 (A1)";
55 if ((ret & 0xfff0) == PORT_SWITCH_ID_6352)
56 return "Marvell 88E6352";
62 static int mv88e6352_setup_global(struct dsa_switch *ds)
64 u32 upstream_port = dsa_upstream_port(ds);
68 ret = mv88e6xxx_setup_global(ds);
72 /* Discard packets with excessive collisions,
73 * mask all interrupt sources, enable PPU (bit 14, undocumented).
75 REG_WRITE(REG_GLOBAL, GLOBAL_CONTROL,
76 GLOBAL_CONTROL_PPU_ENABLE | GLOBAL_CONTROL_DISCARD_EXCESS);
78 /* Configure the upstream port, and configure the upstream
79 * port as the port to which ingress and egress monitor frames
82 reg = upstream_port << GLOBAL_MONITOR_CONTROL_INGRESS_SHIFT |
83 upstream_port << GLOBAL_MONITOR_CONTROL_EGRESS_SHIFT |
84 upstream_port << GLOBAL_MONITOR_CONTROL_ARP_SHIFT;
85 REG_WRITE(REG_GLOBAL, GLOBAL_MONITOR_CONTROL, reg);
87 /* Disable remote management for now, and set the switch's
90 REG_WRITE(REG_GLOBAL, 0x1c, ds->index & 0x1f);
95 static int mv88e6352_setup(struct dsa_switch *ds)
97 struct mv88e6xxx_priv_state *ps = ds_to_priv(ds);
100 ret = mv88e6xxx_setup_common(ds);
106 mutex_init(&ps->eeprom_mutex);
108 ret = mv88e6xxx_switch_reset(ds, true);
112 ret = mv88e6352_setup_global(ds);
116 return mv88e6xxx_setup_ports(ds);
119 static int mv88e6352_read_eeprom_word(struct dsa_switch *ds, int addr)
121 struct mv88e6xxx_priv_state *ps = ds_to_priv(ds);
124 mutex_lock(&ps->eeprom_mutex);
126 ret = mv88e6xxx_reg_write(ds, REG_GLOBAL2, GLOBAL2_EEPROM_OP,
127 GLOBAL2_EEPROM_OP_READ |
128 (addr & GLOBAL2_EEPROM_OP_ADDR_MASK));
132 ret = mv88e6xxx_eeprom_busy_wait(ds);
136 ret = mv88e6xxx_reg_read(ds, REG_GLOBAL2, GLOBAL2_EEPROM_DATA);
138 mutex_unlock(&ps->eeprom_mutex);
142 static int mv88e6352_get_eeprom(struct dsa_switch *ds,
143 struct ethtool_eeprom *eeprom, u8 *data)
149 offset = eeprom->offset;
153 eeprom->magic = 0xc3ec4951;
155 ret = mv88e6xxx_eeprom_load_wait(ds);
162 word = mv88e6352_read_eeprom_word(ds, offset >> 1);
166 *data++ = (word >> 8) & 0xff;
176 word = mv88e6352_read_eeprom_word(ds, offset >> 1);
180 *data++ = word & 0xff;
181 *data++ = (word >> 8) & 0xff;
191 word = mv88e6352_read_eeprom_word(ds, offset >> 1);
195 *data++ = word & 0xff;
205 static int mv88e6352_eeprom_is_readonly(struct dsa_switch *ds)
209 ret = mv88e6xxx_reg_read(ds, REG_GLOBAL2, GLOBAL2_EEPROM_OP);
213 if (!(ret & GLOBAL2_EEPROM_OP_WRITE_EN))
219 static int mv88e6352_write_eeprom_word(struct dsa_switch *ds, int addr,
222 struct mv88e6xxx_priv_state *ps = ds_to_priv(ds);
225 mutex_lock(&ps->eeprom_mutex);
227 ret = mv88e6xxx_reg_write(ds, REG_GLOBAL2, GLOBAL2_EEPROM_DATA, data);
231 ret = mv88e6xxx_reg_write(ds, REG_GLOBAL2, GLOBAL2_EEPROM_OP,
232 GLOBAL2_EEPROM_OP_WRITE |
233 (addr & GLOBAL2_EEPROM_OP_ADDR_MASK));
237 ret = mv88e6xxx_eeprom_busy_wait(ds);
239 mutex_unlock(&ps->eeprom_mutex);
243 static int mv88e6352_set_eeprom(struct dsa_switch *ds,
244 struct ethtool_eeprom *eeprom, u8 *data)
250 if (eeprom->magic != 0xc3ec4951)
253 ret = mv88e6352_eeprom_is_readonly(ds);
257 offset = eeprom->offset;
261 ret = mv88e6xxx_eeprom_load_wait(ds);
268 word = mv88e6352_read_eeprom_word(ds, offset >> 1);
272 word = (*data++ << 8) | (word & 0xff);
274 ret = mv88e6352_write_eeprom_word(ds, offset >> 1, word);
287 word |= *data++ << 8;
289 ret = mv88e6352_write_eeprom_word(ds, offset >> 1, word);
301 word = mv88e6352_read_eeprom_word(ds, offset >> 1);
305 word = (word & 0xff00) | *data++;
307 ret = mv88e6352_write_eeprom_word(ds, offset >> 1, word);
319 struct dsa_switch_driver mv88e6352_switch_driver = {
320 .tag_protocol = DSA_TAG_PROTO_EDSA,
321 .priv_size = sizeof(struct mv88e6xxx_priv_state),
322 .probe = mv88e6352_probe,
323 .setup = mv88e6352_setup,
324 .set_addr = mv88e6xxx_set_addr_indirect,
325 .phy_read = mv88e6xxx_phy_read_indirect,
326 .phy_write = mv88e6xxx_phy_write_indirect,
327 .poll_link = mv88e6xxx_poll_link,
328 .get_strings = mv88e6xxx_get_strings,
329 .get_ethtool_stats = mv88e6xxx_get_ethtool_stats,
330 .get_sset_count = mv88e6xxx_get_sset_count,
331 .set_eee = mv88e6xxx_set_eee,
332 .get_eee = mv88e6xxx_get_eee,
333 #ifdef CONFIG_NET_DSA_HWMON
334 .get_temp = mv88e6xxx_get_temp,
335 .get_temp_limit = mv88e6xxx_get_temp_limit,
336 .set_temp_limit = mv88e6xxx_set_temp_limit,
337 .get_temp_alarm = mv88e6xxx_get_temp_alarm,
339 .get_eeprom = mv88e6352_get_eeprom,
340 .set_eeprom = mv88e6352_set_eeprom,
341 .get_regs_len = mv88e6xxx_get_regs_len,
342 .get_regs = mv88e6xxx_get_regs,
343 .port_join_bridge = mv88e6xxx_join_bridge,
344 .port_leave_bridge = mv88e6xxx_leave_bridge,
345 .port_stp_update = mv88e6xxx_port_stp_update,
346 .port_fdb_add = mv88e6xxx_port_fdb_add,
347 .port_fdb_del = mv88e6xxx_port_fdb_del,
348 .port_fdb_getnext = mv88e6xxx_port_fdb_getnext,
351 MODULE_ALIAS("platform:mv88e6172");
352 MODULE_ALIAS("platform:mv88e6176");
353 MODULE_ALIAS("platform:mv88e6320");
354 MODULE_ALIAS("platform:mv88e6321");
355 MODULE_ALIAS("platform:mv88e6352");