blob: d4fcf4570d955c5ee637870cfa5a276aab63a5a8 [file] [log] [blame]
Lennert Buytenhek91da11f2008-10-07 13:44:02 +00001/*
2 * net/dsa/mv88e6123_61_65.c - Marvell 88e6123/6161/6165 switch chip support
Lennert Buytenheke84665c2009-03-20 09:52:09 +00003 * Copyright (c) 2008-2009 Marvell Semiconductor
Lennert Buytenhek91da11f2008-10-07 13:44:02 +00004 *
5 * This program is free software; you can redistribute it and/or modify
6 * it under the terms of the GNU General Public License as published by
7 * the Free Software Foundation; either version 2 of the License, or
8 * (at your option) any later version.
9 */
10
Barry Grussling19b2f972013-01-08 16:05:54 +000011#include <linux/delay.h>
12#include <linux/jiffies.h>
Lennert Buytenhek91da11f2008-10-07 13:44:02 +000013#include <linux/list.h>
Paul Gortmaker2bbba272012-01-24 10:41:40 +000014#include <linux/module.h>
Lennert Buytenhek91da11f2008-10-07 13:44:02 +000015#include <linux/netdevice.h>
16#include <linux/phy.h>
Ben Hutchingsc8f0b862011-11-27 17:06:08 +000017#include <net/dsa.h>
Lennert Buytenhek91da11f2008-10-07 13:44:02 +000018#include "mv88e6xxx.h"
19
Vivien Didelotb9b37712015-10-30 19:39:48 -040020static const struct mv88e6xxx_switch_id mv88e6123_61_65_table[] = {
21 { PORT_SWITCH_ID_6123, "Marvell 88E6123" },
22 { PORT_SWITCH_ID_6123_A1, "Marvell 88E6123 (A1)" },
23 { PORT_SWITCH_ID_6123_A2, "Marvell 88E6123 (A2)" },
24 { PORT_SWITCH_ID_6161, "Marvell 88E6161" },
25 { PORT_SWITCH_ID_6161_A1, "Marvell 88E6161 (A1)" },
26 { PORT_SWITCH_ID_6161_A2, "Marvell 88E6161 (A2)" },
27 { PORT_SWITCH_ID_6165, "Marvell 88E6165" },
28 { PORT_SWITCH_ID_6165_A1, "Marvell 88E6165 (A1)" },
29 { PORT_SWITCH_ID_6165_A2, "Marvell 88e6165 (A2)" },
30};
31
Alexander Duyckb4d23942014-09-15 13:00:27 -040032static char *mv88e6123_61_65_probe(struct device *host_dev, int sw_addr)
Lennert Buytenhek91da11f2008-10-07 13:44:02 +000033{
Vivien Didelotb9b37712015-10-30 19:39:48 -040034 return mv88e6xxx_lookup_name(host_dev, sw_addr, mv88e6123_61_65_table,
35 ARRAY_SIZE(mv88e6123_61_65_table));
Lennert Buytenhek91da11f2008-10-07 13:44:02 +000036}
37
Lennert Buytenhek91da11f2008-10-07 13:44:02 +000038static int mv88e6123_61_65_setup_global(struct dsa_switch *ds)
39{
Andrew Lunn15966a22015-05-06 01:09:49 +020040 u32 upstream_port = dsa_upstream_port(ds);
Lennert Buytenhek91da11f2008-10-07 13:44:02 +000041 int ret;
Andrew Lunn15966a22015-05-06 01:09:49 +020042 u32 reg;
Andrew Lunn54d792f2015-05-06 01:09:47 +020043
44 ret = mv88e6xxx_setup_global(ds);
45 if (ret)
46 return ret;
Lennert Buytenhek91da11f2008-10-07 13:44:02 +000047
Barry Grussling3675c8d2013-01-08 16:05:53 +000048 /* Disable the PHY polling unit (since there won't be any
Lennert Buytenhek91da11f2008-10-07 13:44:02 +000049 * external PHYs to poll), don't discard packets with
50 * excessive collisions, and mask all interrupt sources.
51 */
Andrew Lunn15966a22015-05-06 01:09:49 +020052 REG_WRITE(REG_GLOBAL, GLOBAL_CONTROL, 0x0000);
Lennert Buytenhek91da11f2008-10-07 13:44:02 +000053
Barry Grussling3675c8d2013-01-08 16:05:53 +000054 /* Configure the upstream port, and configure the upstream
Lennert Buytenheke84665c2009-03-20 09:52:09 +000055 * port as the port to which ingress and egress monitor frames
56 * are to be sent.
Lennert Buytenhek91da11f2008-10-07 13:44:02 +000057 */
Andrew Lunn15966a22015-05-06 01:09:49 +020058 reg = upstream_port << GLOBAL_MONITOR_CONTROL_INGRESS_SHIFT |
59 upstream_port << GLOBAL_MONITOR_CONTROL_EGRESS_SHIFT |
60 upstream_port << GLOBAL_MONITOR_CONTROL_ARP_SHIFT;
61 REG_WRITE(REG_GLOBAL, GLOBAL_MONITOR_CONTROL, reg);
Lennert Buytenhek91da11f2008-10-07 13:44:02 +000062
Barry Grussling3675c8d2013-01-08 16:05:53 +000063 /* Disable remote management for now, and set the switch's
Lennert Buytenheke84665c2009-03-20 09:52:09 +000064 * DSA device number.
Lennert Buytenhek91da11f2008-10-07 13:44:02 +000065 */
Andrew Lunn15966a22015-05-06 01:09:49 +020066 REG_WRITE(REG_GLOBAL, GLOBAL_CONTROL_2, ds->index & 0x1f);
Lennert Buytenhek91da11f2008-10-07 13:44:02 +000067
Lennert Buytenhek91da11f2008-10-07 13:44:02 +000068 return 0;
69}
70
Lennert Buytenhek91da11f2008-10-07 13:44:02 +000071static int mv88e6123_61_65_setup(struct dsa_switch *ds)
72{
Guenter Roeck14ef6ad2015-04-02 04:06:32 +020073 struct mv88e6xxx_priv_state *ps = ds_to_priv(ds);
Lennert Buytenhek91da11f2008-10-07 13:44:02 +000074 int ret;
75
Guenter Roeckacdaffc2015-03-26 18:36:28 -070076 ret = mv88e6xxx_setup_common(ds);
77 if (ret < 0)
78 return ret;
Lennert Buytenhek91da11f2008-10-07 13:44:02 +000079
Guenter Roeck14ef6ad2015-04-02 04:06:32 +020080 switch (ps->id) {
Andrew Lunncca8b132015-04-02 04:06:39 +020081 case PORT_SWITCH_ID_6123:
Guenter Roeck14ef6ad2015-04-02 04:06:32 +020082 ps->num_ports = 3;
83 break;
Andrew Lunncca8b132015-04-02 04:06:39 +020084 case PORT_SWITCH_ID_6161:
85 case PORT_SWITCH_ID_6165:
Guenter Roeck14ef6ad2015-04-02 04:06:32 +020086 ps->num_ports = 6;
87 break;
88 default:
89 return -ENODEV;
90 }
91
Andrew Lunn143a8302015-04-02 04:06:34 +020092 ret = mv88e6xxx_switch_reset(ds, false);
Lennert Buytenhek91da11f2008-10-07 13:44:02 +000093 if (ret < 0)
94 return ret;
95
Lennert Buytenhek91da11f2008-10-07 13:44:02 +000096 ret = mv88e6123_61_65_setup_global(ds);
97 if (ret < 0)
98 return ret;
99
Andrew Lunndbde9e62015-05-06 01:09:48 +0200100 return mv88e6xxx_setup_ports(ds);
Lennert Buytenhek91da11f2008-10-07 13:44:02 +0000101}
102
Ben Hutchings98e67302011-11-25 14:36:19 +0000103struct dsa_switch_driver mv88e6123_61_65_switch_driver = {
Florian Fainelliac7a04c2014-09-11 21:18:09 -0700104 .tag_protocol = DSA_TAG_PROTO_EDSA,
Lennert Buytenhek91da11f2008-10-07 13:44:02 +0000105 .priv_size = sizeof(struct mv88e6xxx_priv_state),
106 .probe = mv88e6123_61_65_probe,
107 .setup = mv88e6123_61_65_setup,
108 .set_addr = mv88e6xxx_set_addr_indirect,
Andrew Lunnfd3a0ee2015-04-02 04:06:36 +0200109 .phy_read = mv88e6xxx_phy_read,
110 .phy_write = mv88e6xxx_phy_write,
Andrew Lunne413e7e2015-04-02 04:06:38 +0200111 .get_strings = mv88e6xxx_get_strings,
112 .get_ethtool_stats = mv88e6xxx_get_ethtool_stats,
113 .get_sset_count = mv88e6xxx_get_sset_count,
Andrew Lunndea87022015-08-31 15:56:47 +0200114 .adjust_link = mv88e6xxx_adjust_link,
Guenter Roeck87e5f662014-10-29 10:45:00 -0700115#ifdef CONFIG_NET_DSA_HWMON
Andrew Lunneaa23762014-11-15 22:24:51 +0100116 .get_temp = mv88e6xxx_get_temp,
Guenter Roeck87e5f662014-10-29 10:45:00 -0700117#endif
Guenter Roecka1ab91f2014-10-29 10:45:05 -0700118 .get_regs_len = mv88e6xxx_get_regs_len,
119 .get_regs = mv88e6xxx_get_regs,
Lennert Buytenhek91da11f2008-10-07 13:44:02 +0000120};
Ben Hutchings3d825ed2011-11-25 14:37:16 +0000121
122MODULE_ALIAS("platform:mv88e6123");
123MODULE_ALIAS("platform:mv88e6161");
124MODULE_ALIAS("platform:mv88e6165");