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_info mv88e6352_table[] = {
27 .prod_num = PORT_SWITCH_ID_PROD_NUM_6320,
28 .family = MV88E6XXX_FAMILY_6320,
29 .name = "Marvell 88E6320",
31 .prod_num = PORT_SWITCH_ID_PROD_NUM_6321,
32 .family = MV88E6XXX_FAMILY_6320,
33 .name = "Marvell 88E6321",
35 .prod_num = PORT_SWITCH_ID_PROD_NUM_6172,
36 .family = MV88E6XXX_FAMILY_6352,
37 .name = "Marvell 88E6172",
39 .prod_num = PORT_SWITCH_ID_PROD_NUM_6176,
40 .family = MV88E6XXX_FAMILY_6352,
41 .name = "Marvell 88E6176",
43 .prod_num = PORT_SWITCH_ID_PROD_NUM_6240,
44 .family = MV88E6XXX_FAMILY_6352,
45 .name = "Marvell 88E6240",
47 .prod_num = PORT_SWITCH_ID_PROD_NUM_6352,
48 .family = MV88E6XXX_FAMILY_6352,
49 .name = "Marvell 88E6352",
53 static const char *mv88e6352_drv_probe(struct device *dsa_dev,
54 struct device *host_dev, int sw_addr,
57 return mv88e6xxx_drv_probe(dsa_dev, host_dev, sw_addr, priv,
59 ARRAY_SIZE(mv88e6352_table));
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 ret = mv88e6xxx_reg_write(ds, REG_GLOBAL, GLOBAL_CONTROL,
76 GLOBAL_CONTROL_PPU_ENABLE |
77 GLOBAL_CONTROL_DISCARD_EXCESS);
81 /* Configure the upstream port, and configure the upstream
82 * port as the port to which ingress and egress monitor frames
85 reg = upstream_port << GLOBAL_MONITOR_CONTROL_INGRESS_SHIFT |
86 upstream_port << GLOBAL_MONITOR_CONTROL_EGRESS_SHIFT |
87 upstream_port << GLOBAL_MONITOR_CONTROL_ARP_SHIFT;
88 ret = mv88e6xxx_reg_write(ds, REG_GLOBAL, GLOBAL_MONITOR_CONTROL, reg);
92 /* Disable remote management for now, and set the switch's
95 return mv88e6xxx_reg_write(ds, REG_GLOBAL, 0x1c, ds->index & 0x1f);
98 static int mv88e6352_setup(struct dsa_switch *ds)
100 struct mv88e6xxx_priv_state *ps = ds_to_priv(ds);
103 ret = mv88e6xxx_setup_common(ds);
109 mutex_init(&ps->eeprom_mutex);
111 ret = mv88e6xxx_switch_reset(ds, true);
115 ret = mv88e6352_setup_global(ds);
119 return mv88e6xxx_setup_ports(ds);
122 static int mv88e6352_read_eeprom_word(struct dsa_switch *ds, int addr)
124 struct mv88e6xxx_priv_state *ps = ds_to_priv(ds);
127 mutex_lock(&ps->eeprom_mutex);
129 ret = mv88e6xxx_reg_write(ds, REG_GLOBAL2, GLOBAL2_EEPROM_OP,
130 GLOBAL2_EEPROM_OP_READ |
131 (addr & GLOBAL2_EEPROM_OP_ADDR_MASK));
135 ret = mv88e6xxx_eeprom_busy_wait(ds);
139 ret = mv88e6xxx_reg_read(ds, REG_GLOBAL2, GLOBAL2_EEPROM_DATA);
141 mutex_unlock(&ps->eeprom_mutex);
145 static int mv88e6352_get_eeprom(struct dsa_switch *ds,
146 struct ethtool_eeprom *eeprom, u8 *data)
152 offset = eeprom->offset;
156 eeprom->magic = 0xc3ec4951;
158 ret = mv88e6xxx_eeprom_load_wait(ds);
165 word = mv88e6352_read_eeprom_word(ds, offset >> 1);
169 *data++ = (word >> 8) & 0xff;
179 word = mv88e6352_read_eeprom_word(ds, offset >> 1);
183 *data++ = word & 0xff;
184 *data++ = (word >> 8) & 0xff;
194 word = mv88e6352_read_eeprom_word(ds, offset >> 1);
198 *data++ = word & 0xff;
208 static int mv88e6352_eeprom_is_readonly(struct dsa_switch *ds)
212 ret = mv88e6xxx_reg_read(ds, REG_GLOBAL2, GLOBAL2_EEPROM_OP);
216 if (!(ret & GLOBAL2_EEPROM_OP_WRITE_EN))
222 static int mv88e6352_write_eeprom_word(struct dsa_switch *ds, int addr,
225 struct mv88e6xxx_priv_state *ps = ds_to_priv(ds);
228 mutex_lock(&ps->eeprom_mutex);
230 ret = mv88e6xxx_reg_write(ds, REG_GLOBAL2, GLOBAL2_EEPROM_DATA, data);
234 ret = mv88e6xxx_reg_write(ds, REG_GLOBAL2, GLOBAL2_EEPROM_OP,
235 GLOBAL2_EEPROM_OP_WRITE |
236 (addr & GLOBAL2_EEPROM_OP_ADDR_MASK));
240 ret = mv88e6xxx_eeprom_busy_wait(ds);
242 mutex_unlock(&ps->eeprom_mutex);
246 static int mv88e6352_set_eeprom(struct dsa_switch *ds,
247 struct ethtool_eeprom *eeprom, u8 *data)
253 if (eeprom->magic != 0xc3ec4951)
256 ret = mv88e6352_eeprom_is_readonly(ds);
260 offset = eeprom->offset;
264 ret = mv88e6xxx_eeprom_load_wait(ds);
271 word = mv88e6352_read_eeprom_word(ds, offset >> 1);
275 word = (*data++ << 8) | (word & 0xff);
277 ret = mv88e6352_write_eeprom_word(ds, offset >> 1, word);
290 word |= *data++ << 8;
292 ret = mv88e6352_write_eeprom_word(ds, offset >> 1, word);
304 word = mv88e6352_read_eeprom_word(ds, offset >> 1);
308 word = (word & 0xff00) | *data++;
310 ret = mv88e6352_write_eeprom_word(ds, offset >> 1, word);
322 struct dsa_switch_driver mv88e6352_switch_driver = {
323 .tag_protocol = DSA_TAG_PROTO_EDSA,
324 .probe = mv88e6352_drv_probe,
325 .setup = mv88e6352_setup,
326 .set_addr = mv88e6xxx_set_addr_indirect,
327 .phy_read = mv88e6xxx_phy_read_indirect,
328 .phy_write = mv88e6xxx_phy_write_indirect,
329 .get_strings = mv88e6xxx_get_strings,
330 .get_ethtool_stats = mv88e6xxx_get_ethtool_stats,
331 .get_sset_count = mv88e6xxx_get_sset_count,
332 .adjust_link = mv88e6xxx_adjust_link,
333 .set_eee = mv88e6xxx_set_eee,
334 .get_eee = mv88e6xxx_get_eee,
335 #ifdef CONFIG_NET_DSA_HWMON
336 .get_temp = mv88e6xxx_get_temp,
337 .get_temp_limit = mv88e6xxx_get_temp_limit,
338 .set_temp_limit = mv88e6xxx_set_temp_limit,
339 .get_temp_alarm = mv88e6xxx_get_temp_alarm,
341 .get_eeprom = mv88e6352_get_eeprom,
342 .set_eeprom = mv88e6352_set_eeprom,
343 .get_regs_len = mv88e6xxx_get_regs_len,
344 .get_regs = mv88e6xxx_get_regs,
345 .port_bridge_join = mv88e6xxx_port_bridge_join,
346 .port_bridge_leave = mv88e6xxx_port_bridge_leave,
347 .port_stp_state_set = mv88e6xxx_port_stp_state_set,
348 .port_vlan_filtering = mv88e6xxx_port_vlan_filtering,
349 .port_vlan_prepare = mv88e6xxx_port_vlan_prepare,
350 .port_vlan_add = mv88e6xxx_port_vlan_add,
351 .port_vlan_del = mv88e6xxx_port_vlan_del,
352 .port_vlan_dump = mv88e6xxx_port_vlan_dump,
353 .port_fdb_prepare = mv88e6xxx_port_fdb_prepare,
354 .port_fdb_add = mv88e6xxx_port_fdb_add,
355 .port_fdb_del = mv88e6xxx_port_fdb_del,
356 .port_fdb_dump = mv88e6xxx_port_fdb_dump,
359 MODULE_ALIAS("platform:mv88e6172");
360 MODULE_ALIAS("platform:mv88e6176");
361 MODULE_ALIAS("platform:mv88e6320");
362 MODULE_ALIAS("platform:mv88e6321");
363 MODULE_ALIAS("platform:mv88e6352");