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_6352_A0)
40 return "Marvell 88E6352 (A0)";
41 if (ret == PORT_SWITCH_ID_6352_A1)
42 return "Marvell 88E6352 (A1)";
43 if ((ret & 0xfff0) == PORT_SWITCH_ID_6352)
44 return "Marvell 88E6352";
50 static int mv88e6352_setup_global(struct dsa_switch *ds)
52 u32 upstream_port = dsa_upstream_port(ds);
56 ret = mv88e6xxx_setup_global(ds);
60 /* Discard packets with excessive collisions,
61 * mask all interrupt sources, enable PPU (bit 14, undocumented).
63 REG_WRITE(REG_GLOBAL, GLOBAL_CONTROL,
64 GLOBAL_CONTROL_PPU_ENABLE | GLOBAL_CONTROL_DISCARD_EXCESS);
66 /* Configure the upstream port, and configure the upstream
67 * port as the port to which ingress and egress monitor frames
70 reg = upstream_port << GLOBAL_MONITOR_CONTROL_INGRESS_SHIFT |
71 upstream_port << GLOBAL_MONITOR_CONTROL_EGRESS_SHIFT |
72 upstream_port << GLOBAL_MONITOR_CONTROL_ARP_SHIFT;
73 REG_WRITE(REG_GLOBAL, GLOBAL_MONITOR_CONTROL, reg);
75 /* Disable remote management for now, and set the switch's
78 REG_WRITE(REG_GLOBAL, 0x1c, ds->index & 0x1f);
83 #ifdef CONFIG_NET_DSA_HWMON
85 static int mv88e6352_get_temp(struct dsa_switch *ds, int *temp)
91 ret = mv88e6xxx_phy_page_read(ds, 0, 6, 27);
95 *temp = (ret & 0xff) - 25;
100 static int mv88e6352_get_temp_limit(struct dsa_switch *ds, int *temp)
106 ret = mv88e6xxx_phy_page_read(ds, 0, 6, 26);
110 *temp = (((ret >> 8) & 0x1f) * 5) - 25;
115 static int mv88e6352_set_temp_limit(struct dsa_switch *ds, int temp)
119 ret = mv88e6xxx_phy_page_read(ds, 0, 6, 26);
122 temp = clamp_val(DIV_ROUND_CLOSEST(temp, 5) + 5, 0, 0x1f);
123 return mv88e6xxx_phy_page_write(ds, 0, 6, 26,
124 (ret & 0xe0ff) | (temp << 8));
127 static int mv88e6352_get_temp_alarm(struct dsa_switch *ds, bool *alarm)
133 ret = mv88e6xxx_phy_page_read(ds, 0, 6, 26);
137 *alarm = !!(ret & 0x40);
141 #endif /* CONFIG_NET_DSA_HWMON */
143 static int mv88e6352_setup(struct dsa_switch *ds)
145 struct mv88e6xxx_priv_state *ps = ds_to_priv(ds);
148 ret = mv88e6xxx_setup_common(ds);
154 mutex_init(&ps->eeprom_mutex);
156 ret = mv88e6xxx_switch_reset(ds, true);
160 ret = mv88e6352_setup_global(ds);
164 return mv88e6xxx_setup_ports(ds);
167 static int mv88e6352_read_eeprom_word(struct dsa_switch *ds, int addr)
169 struct mv88e6xxx_priv_state *ps = ds_to_priv(ds);
172 mutex_lock(&ps->eeprom_mutex);
174 ret = mv88e6xxx_reg_write(ds, REG_GLOBAL2, 0x14,
175 0xc000 | (addr & 0xff));
179 ret = mv88e6xxx_eeprom_busy_wait(ds);
183 ret = mv88e6xxx_reg_read(ds, REG_GLOBAL2, 0x15);
185 mutex_unlock(&ps->eeprom_mutex);
189 static int mv88e6352_get_eeprom(struct dsa_switch *ds,
190 struct ethtool_eeprom *eeprom, u8 *data)
196 offset = eeprom->offset;
200 eeprom->magic = 0xc3ec4951;
202 ret = mv88e6xxx_eeprom_load_wait(ds);
209 word = mv88e6352_read_eeprom_word(ds, offset >> 1);
213 *data++ = (word >> 8) & 0xff;
223 word = mv88e6352_read_eeprom_word(ds, offset >> 1);
227 *data++ = word & 0xff;
228 *data++ = (word >> 8) & 0xff;
238 word = mv88e6352_read_eeprom_word(ds, offset >> 1);
242 *data++ = word & 0xff;
252 static int mv88e6352_eeprom_is_readonly(struct dsa_switch *ds)
256 ret = mv88e6xxx_reg_read(ds, REG_GLOBAL2, 0x14);
266 static int mv88e6352_write_eeprom_word(struct dsa_switch *ds, int addr,
269 struct mv88e6xxx_priv_state *ps = ds_to_priv(ds);
272 mutex_lock(&ps->eeprom_mutex);
274 ret = mv88e6xxx_reg_write(ds, REG_GLOBAL2, 0x15, data);
278 ret = mv88e6xxx_reg_write(ds, REG_GLOBAL2, 0x14,
279 0xb000 | (addr & 0xff));
283 ret = mv88e6xxx_eeprom_busy_wait(ds);
285 mutex_unlock(&ps->eeprom_mutex);
289 static int mv88e6352_set_eeprom(struct dsa_switch *ds,
290 struct ethtool_eeprom *eeprom, u8 *data)
296 if (eeprom->magic != 0xc3ec4951)
299 ret = mv88e6352_eeprom_is_readonly(ds);
303 offset = eeprom->offset;
307 ret = mv88e6xxx_eeprom_load_wait(ds);
314 word = mv88e6352_read_eeprom_word(ds, offset >> 1);
318 word = (*data++ << 8) | (word & 0xff);
320 ret = mv88e6352_write_eeprom_word(ds, offset >> 1, word);
333 word |= *data++ << 8;
335 ret = mv88e6352_write_eeprom_word(ds, offset >> 1, word);
347 word = mv88e6352_read_eeprom_word(ds, offset >> 1);
351 word = (word & 0xff00) | *data++;
353 ret = mv88e6352_write_eeprom_word(ds, offset >> 1, word);
365 struct dsa_switch_driver mv88e6352_switch_driver = {
366 .tag_protocol = DSA_TAG_PROTO_EDSA,
367 .priv_size = sizeof(struct mv88e6xxx_priv_state),
368 .probe = mv88e6352_probe,
369 .setup = mv88e6352_setup,
370 .set_addr = mv88e6xxx_set_addr_indirect,
371 .phy_read = mv88e6xxx_phy_read_indirect,
372 .phy_write = mv88e6xxx_phy_write_indirect,
373 .poll_link = mv88e6xxx_poll_link,
374 .get_strings = mv88e6xxx_get_strings,
375 .get_ethtool_stats = mv88e6xxx_get_ethtool_stats,
376 .get_sset_count = mv88e6xxx_get_sset_count,
377 .set_eee = mv88e6xxx_set_eee,
378 .get_eee = mv88e6xxx_get_eee,
379 #ifdef CONFIG_NET_DSA_HWMON
380 .get_temp = mv88e6352_get_temp,
381 .get_temp_limit = mv88e6352_get_temp_limit,
382 .set_temp_limit = mv88e6352_set_temp_limit,
383 .get_temp_alarm = mv88e6352_get_temp_alarm,
385 .get_eeprom = mv88e6352_get_eeprom,
386 .set_eeprom = mv88e6352_set_eeprom,
387 .get_regs_len = mv88e6xxx_get_regs_len,
388 .get_regs = mv88e6xxx_get_regs,
389 .port_join_bridge = mv88e6xxx_join_bridge,
390 .port_leave_bridge = mv88e6xxx_leave_bridge,
391 .port_stp_update = mv88e6xxx_port_stp_update,
392 .fdb_add = mv88e6xxx_port_fdb_add,
393 .fdb_del = mv88e6xxx_port_fdb_del,
394 .fdb_getnext = mv88e6xxx_port_fdb_getnext,
397 MODULE_ALIAS("platform:mv88e6352");
398 MODULE_ALIAS("platform:mv88e6172");