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 .name = "Marvell 88E6320",
30 .prod_num = PORT_SWITCH_ID_PROD_NUM_6321,
31 .name = "Marvell 88E6321",
33 .prod_num = PORT_SWITCH_ID_PROD_NUM_6172,
34 .name = "Marvell 88E6172",
36 .prod_num = PORT_SWITCH_ID_PROD_NUM_6176,
37 .name = "Marvell 88E6176",
39 .prod_num = PORT_SWITCH_ID_PROD_NUM_6240,
40 .name = "Marvell 88E6240",
42 .prod_num = PORT_SWITCH_ID_PROD_NUM_6352,
43 .name = "Marvell 88E6352",
47 static const char *mv88e6352_drv_probe(struct device *dsa_dev,
48 struct device *host_dev, int sw_addr,
51 return mv88e6xxx_drv_probe(dsa_dev, host_dev, sw_addr, priv,
53 ARRAY_SIZE(mv88e6352_table));
56 static int mv88e6352_setup_global(struct dsa_switch *ds)
58 u32 upstream_port = dsa_upstream_port(ds);
62 ret = mv88e6xxx_setup_global(ds);
66 /* Discard packets with excessive collisions,
67 * mask all interrupt sources, enable PPU (bit 14, undocumented).
69 ret = mv88e6xxx_reg_write(ds, REG_GLOBAL, GLOBAL_CONTROL,
70 GLOBAL_CONTROL_PPU_ENABLE |
71 GLOBAL_CONTROL_DISCARD_EXCESS);
75 /* Configure the upstream port, and configure the upstream
76 * port as the port to which ingress and egress monitor frames
79 reg = upstream_port << GLOBAL_MONITOR_CONTROL_INGRESS_SHIFT |
80 upstream_port << GLOBAL_MONITOR_CONTROL_EGRESS_SHIFT |
81 upstream_port << GLOBAL_MONITOR_CONTROL_ARP_SHIFT;
82 ret = mv88e6xxx_reg_write(ds, REG_GLOBAL, GLOBAL_MONITOR_CONTROL, reg);
86 /* Disable remote management for now, and set the switch's
89 return mv88e6xxx_reg_write(ds, REG_GLOBAL, 0x1c, ds->index & 0x1f);
92 static int mv88e6352_setup(struct dsa_switch *ds)
94 struct mv88e6xxx_priv_state *ps = ds_to_priv(ds);
97 ret = mv88e6xxx_setup_common(ds);
103 mutex_init(&ps->eeprom_mutex);
105 ret = mv88e6xxx_switch_reset(ds, true);
109 ret = mv88e6352_setup_global(ds);
113 return mv88e6xxx_setup_ports(ds);
116 static int mv88e6352_read_eeprom_word(struct dsa_switch *ds, int addr)
118 struct mv88e6xxx_priv_state *ps = ds_to_priv(ds);
121 mutex_lock(&ps->eeprom_mutex);
123 ret = mv88e6xxx_reg_write(ds, REG_GLOBAL2, GLOBAL2_EEPROM_OP,
124 GLOBAL2_EEPROM_OP_READ |
125 (addr & GLOBAL2_EEPROM_OP_ADDR_MASK));
129 ret = mv88e6xxx_eeprom_busy_wait(ds);
133 ret = mv88e6xxx_reg_read(ds, REG_GLOBAL2, GLOBAL2_EEPROM_DATA);
135 mutex_unlock(&ps->eeprom_mutex);
139 static int mv88e6352_get_eeprom(struct dsa_switch *ds,
140 struct ethtool_eeprom *eeprom, u8 *data)
146 offset = eeprom->offset;
150 eeprom->magic = 0xc3ec4951;
152 ret = mv88e6xxx_eeprom_load_wait(ds);
159 word = mv88e6352_read_eeprom_word(ds, offset >> 1);
163 *data++ = (word >> 8) & 0xff;
173 word = mv88e6352_read_eeprom_word(ds, offset >> 1);
177 *data++ = word & 0xff;
178 *data++ = (word >> 8) & 0xff;
188 word = mv88e6352_read_eeprom_word(ds, offset >> 1);
192 *data++ = word & 0xff;
202 static int mv88e6352_eeprom_is_readonly(struct dsa_switch *ds)
206 ret = mv88e6xxx_reg_read(ds, REG_GLOBAL2, GLOBAL2_EEPROM_OP);
210 if (!(ret & GLOBAL2_EEPROM_OP_WRITE_EN))
216 static int mv88e6352_write_eeprom_word(struct dsa_switch *ds, int addr,
219 struct mv88e6xxx_priv_state *ps = ds_to_priv(ds);
222 mutex_lock(&ps->eeprom_mutex);
224 ret = mv88e6xxx_reg_write(ds, REG_GLOBAL2, GLOBAL2_EEPROM_DATA, data);
228 ret = mv88e6xxx_reg_write(ds, REG_GLOBAL2, GLOBAL2_EEPROM_OP,
229 GLOBAL2_EEPROM_OP_WRITE |
230 (addr & GLOBAL2_EEPROM_OP_ADDR_MASK));
234 ret = mv88e6xxx_eeprom_busy_wait(ds);
236 mutex_unlock(&ps->eeprom_mutex);
240 static int mv88e6352_set_eeprom(struct dsa_switch *ds,
241 struct ethtool_eeprom *eeprom, u8 *data)
247 if (eeprom->magic != 0xc3ec4951)
250 ret = mv88e6352_eeprom_is_readonly(ds);
254 offset = eeprom->offset;
258 ret = mv88e6xxx_eeprom_load_wait(ds);
265 word = mv88e6352_read_eeprom_word(ds, offset >> 1);
269 word = (*data++ << 8) | (word & 0xff);
271 ret = mv88e6352_write_eeprom_word(ds, offset >> 1, word);
284 word |= *data++ << 8;
286 ret = mv88e6352_write_eeprom_word(ds, offset >> 1, word);
298 word = mv88e6352_read_eeprom_word(ds, offset >> 1);
302 word = (word & 0xff00) | *data++;
304 ret = mv88e6352_write_eeprom_word(ds, offset >> 1, word);
316 struct dsa_switch_driver mv88e6352_switch_driver = {
317 .tag_protocol = DSA_TAG_PROTO_EDSA,
318 .probe = mv88e6352_drv_probe,
319 .setup = mv88e6352_setup,
320 .set_addr = mv88e6xxx_set_addr_indirect,
321 .phy_read = mv88e6xxx_phy_read_indirect,
322 .phy_write = mv88e6xxx_phy_write_indirect,
323 .get_strings = mv88e6xxx_get_strings,
324 .get_ethtool_stats = mv88e6xxx_get_ethtool_stats,
325 .get_sset_count = mv88e6xxx_get_sset_count,
326 .adjust_link = mv88e6xxx_adjust_link,
327 .set_eee = mv88e6xxx_set_eee,
328 .get_eee = mv88e6xxx_get_eee,
329 #ifdef CONFIG_NET_DSA_HWMON
330 .get_temp = mv88e6xxx_get_temp,
331 .get_temp_limit = mv88e6xxx_get_temp_limit,
332 .set_temp_limit = mv88e6xxx_set_temp_limit,
333 .get_temp_alarm = mv88e6xxx_get_temp_alarm,
335 .get_eeprom = mv88e6352_get_eeprom,
336 .set_eeprom = mv88e6352_set_eeprom,
337 .get_regs_len = mv88e6xxx_get_regs_len,
338 .get_regs = mv88e6xxx_get_regs,
339 .port_bridge_join = mv88e6xxx_port_bridge_join,
340 .port_bridge_leave = mv88e6xxx_port_bridge_leave,
341 .port_stp_state_set = mv88e6xxx_port_stp_state_set,
342 .port_vlan_filtering = mv88e6xxx_port_vlan_filtering,
343 .port_vlan_prepare = mv88e6xxx_port_vlan_prepare,
344 .port_vlan_add = mv88e6xxx_port_vlan_add,
345 .port_vlan_del = mv88e6xxx_port_vlan_del,
346 .port_vlan_dump = mv88e6xxx_port_vlan_dump,
347 .port_fdb_prepare = mv88e6xxx_port_fdb_prepare,
348 .port_fdb_add = mv88e6xxx_port_fdb_add,
349 .port_fdb_del = mv88e6xxx_port_fdb_del,
350 .port_fdb_dump = mv88e6xxx_port_fdb_dump,
353 MODULE_ALIAS("platform:mv88e6172");
354 MODULE_ALIAS("platform:mv88e6176");
355 MODULE_ALIAS("platform:mv88e6320");
356 MODULE_ALIAS("platform:mv88e6321");
357 MODULE_ALIAS("platform:mv88e6352");