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_6320
, "Marvell 88E6320" },
29 { PORT_SWITCH_ID_6320_A1
, "Marvell 88E6320 (A1)" },
30 { PORT_SWITCH_ID_6320_A2
, "Marvell 88e6320 (A2)" },
31 { PORT_SWITCH_ID_6321
, "Marvell 88E6321" },
32 { PORT_SWITCH_ID_6321_A1
, "Marvell 88E6321 (A1)" },
33 { PORT_SWITCH_ID_6321_A2
, "Marvell 88e6321 (A2)" },
34 { PORT_SWITCH_ID_6352
, "Marvell 88E6352" },
35 { PORT_SWITCH_ID_6352_A0
, "Marvell 88E6352 (A0)" },
36 { PORT_SWITCH_ID_6352_A1
, "Marvell 88E6352 (A1)" },
39 static char *mv88e6352_probe(struct device
*host_dev
, int sw_addr
)
41 return mv88e6xxx_lookup_name(host_dev
, sw_addr
, mv88e6352_table
,
42 ARRAY_SIZE(mv88e6352_table
));
45 static int mv88e6352_setup_global(struct dsa_switch
*ds
)
47 u32 upstream_port
= dsa_upstream_port(ds
);
51 ret
= mv88e6xxx_setup_global(ds
);
55 /* Discard packets with excessive collisions,
56 * mask all interrupt sources, enable PPU (bit 14, undocumented).
58 REG_WRITE(REG_GLOBAL
, GLOBAL_CONTROL
,
59 GLOBAL_CONTROL_PPU_ENABLE
| GLOBAL_CONTROL_DISCARD_EXCESS
);
61 /* Configure the upstream port, and configure the upstream
62 * port as the port to which ingress and egress monitor frames
65 reg
= upstream_port
<< GLOBAL_MONITOR_CONTROL_INGRESS_SHIFT
|
66 upstream_port
<< GLOBAL_MONITOR_CONTROL_EGRESS_SHIFT
|
67 upstream_port
<< GLOBAL_MONITOR_CONTROL_ARP_SHIFT
;
68 REG_WRITE(REG_GLOBAL
, GLOBAL_MONITOR_CONTROL
, reg
);
70 /* Disable remote management for now, and set the switch's
73 REG_WRITE(REG_GLOBAL
, 0x1c, ds
->index
& 0x1f);
78 static int mv88e6352_setup(struct dsa_switch
*ds
)
80 struct mv88e6xxx_priv_state
*ps
= ds_to_priv(ds
);
83 ret
= mv88e6xxx_setup_common(ds
);
89 mutex_init(&ps
->eeprom_mutex
);
91 ret
= mv88e6xxx_switch_reset(ds
, true);
95 ret
= mv88e6352_setup_global(ds
);
99 return mv88e6xxx_setup_ports(ds
);
102 static int mv88e6352_read_eeprom_word(struct dsa_switch
*ds
, int addr
)
104 struct mv88e6xxx_priv_state
*ps
= ds_to_priv(ds
);
107 mutex_lock(&ps
->eeprom_mutex
);
109 ret
= mv88e6xxx_reg_write(ds
, REG_GLOBAL2
, GLOBAL2_EEPROM_OP
,
110 GLOBAL2_EEPROM_OP_READ
|
111 (addr
& GLOBAL2_EEPROM_OP_ADDR_MASK
));
115 ret
= mv88e6xxx_eeprom_busy_wait(ds
);
119 ret
= mv88e6xxx_reg_read(ds
, REG_GLOBAL2
, GLOBAL2_EEPROM_DATA
);
121 mutex_unlock(&ps
->eeprom_mutex
);
125 static int mv88e6352_get_eeprom(struct dsa_switch
*ds
,
126 struct ethtool_eeprom
*eeprom
, u8
*data
)
132 offset
= eeprom
->offset
;
136 eeprom
->magic
= 0xc3ec4951;
138 ret
= mv88e6xxx_eeprom_load_wait(ds
);
145 word
= mv88e6352_read_eeprom_word(ds
, offset
>> 1);
149 *data
++ = (word
>> 8) & 0xff;
159 word
= mv88e6352_read_eeprom_word(ds
, offset
>> 1);
163 *data
++ = word
& 0xff;
164 *data
++ = (word
>> 8) & 0xff;
174 word
= mv88e6352_read_eeprom_word(ds
, offset
>> 1);
178 *data
++ = word
& 0xff;
188 static int mv88e6352_eeprom_is_readonly(struct dsa_switch
*ds
)
192 ret
= mv88e6xxx_reg_read(ds
, REG_GLOBAL2
, GLOBAL2_EEPROM_OP
);
196 if (!(ret
& GLOBAL2_EEPROM_OP_WRITE_EN
))
202 static int mv88e6352_write_eeprom_word(struct dsa_switch
*ds
, int addr
,
205 struct mv88e6xxx_priv_state
*ps
= ds_to_priv(ds
);
208 mutex_lock(&ps
->eeprom_mutex
);
210 ret
= mv88e6xxx_reg_write(ds
, REG_GLOBAL2
, GLOBAL2_EEPROM_DATA
, data
);
214 ret
= mv88e6xxx_reg_write(ds
, REG_GLOBAL2
, GLOBAL2_EEPROM_OP
,
215 GLOBAL2_EEPROM_OP_WRITE
|
216 (addr
& GLOBAL2_EEPROM_OP_ADDR_MASK
));
220 ret
= mv88e6xxx_eeprom_busy_wait(ds
);
222 mutex_unlock(&ps
->eeprom_mutex
);
226 static int mv88e6352_set_eeprom(struct dsa_switch
*ds
,
227 struct ethtool_eeprom
*eeprom
, u8
*data
)
233 if (eeprom
->magic
!= 0xc3ec4951)
236 ret
= mv88e6352_eeprom_is_readonly(ds
);
240 offset
= eeprom
->offset
;
244 ret
= mv88e6xxx_eeprom_load_wait(ds
);
251 word
= mv88e6352_read_eeprom_word(ds
, offset
>> 1);
255 word
= (*data
++ << 8) | (word
& 0xff);
257 ret
= mv88e6352_write_eeprom_word(ds
, offset
>> 1, word
);
270 word
|= *data
++ << 8;
272 ret
= mv88e6352_write_eeprom_word(ds
, offset
>> 1, word
);
284 word
= mv88e6352_read_eeprom_word(ds
, offset
>> 1);
288 word
= (word
& 0xff00) | *data
++;
290 ret
= mv88e6352_write_eeprom_word(ds
, offset
>> 1, word
);
302 struct dsa_switch_driver mv88e6352_switch_driver
= {
303 .tag_protocol
= DSA_TAG_PROTO_EDSA
,
304 .priv_size
= sizeof(struct mv88e6xxx_priv_state
),
305 .probe
= mv88e6352_probe
,
306 .setup
= mv88e6352_setup
,
307 .set_addr
= mv88e6xxx_set_addr_indirect
,
308 .phy_read
= mv88e6xxx_phy_read_indirect
,
309 .phy_write
= mv88e6xxx_phy_write_indirect
,
310 .get_strings
= mv88e6xxx_get_strings
,
311 .get_ethtool_stats
= mv88e6xxx_get_ethtool_stats
,
312 .get_sset_count
= mv88e6xxx_get_sset_count
,
313 .adjust_link
= mv88e6xxx_adjust_link
,
314 .set_eee
= mv88e6xxx_set_eee
,
315 .get_eee
= mv88e6xxx_get_eee
,
316 #ifdef CONFIG_NET_DSA_HWMON
317 .get_temp
= mv88e6xxx_get_temp
,
318 .get_temp_limit
= mv88e6xxx_get_temp_limit
,
319 .set_temp_limit
= mv88e6xxx_set_temp_limit
,
320 .get_temp_alarm
= mv88e6xxx_get_temp_alarm
,
322 .get_eeprom
= mv88e6352_get_eeprom
,
323 .set_eeprom
= mv88e6352_set_eeprom
,
324 .get_regs_len
= mv88e6xxx_get_regs_len
,
325 .get_regs
= mv88e6xxx_get_regs
,
326 .port_join_bridge
= mv88e6xxx_port_bridge_join
,
327 .port_leave_bridge
= mv88e6xxx_port_bridge_leave
,
328 .port_stp_update
= mv88e6xxx_port_stp_update
,
329 .port_pvid_get
= mv88e6xxx_port_pvid_get
,
330 .port_vlan_prepare
= mv88e6xxx_port_vlan_prepare
,
331 .port_vlan_add
= mv88e6xxx_port_vlan_add
,
332 .port_vlan_del
= mv88e6xxx_port_vlan_del
,
333 .vlan_getnext
= mv88e6xxx_vlan_getnext
,
334 .port_fdb_prepare
= mv88e6xxx_port_fdb_prepare
,
335 .port_fdb_add
= mv88e6xxx_port_fdb_add
,
336 .port_fdb_del
= mv88e6xxx_port_fdb_del
,
337 .port_fdb_dump
= mv88e6xxx_port_fdb_dump
,
340 MODULE_ALIAS("platform:mv88e6172");
341 MODULE_ALIAS("platform:mv88e6176");
342 MODULE_ALIAS("platform:mv88e6320");
343 MODULE_ALIAS("platform:mv88e6321");
344 MODULE_ALIAS("platform:mv88e6352");