net: dsa: mv88e6xxx: factorize switch reset
[cascardo/linux.git] / drivers / net / dsa / mv88e6171.c
1 /* net/dsa/mv88e6171.c - Marvell 88e6171 switch chip support
2  * Copyright (c) 2008-2009 Marvell Semiconductor
3  * Copyright (c) 2014 Claudio Leite <leitec@staticky.com>
4  *
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
11 #include <linux/delay.h>
12 #include <linux/jiffies.h>
13 #include <linux/list.h>
14 #include <linux/module.h>
15 #include <linux/netdevice.h>
16 #include <linux/phy.h>
17 #include <net/dsa.h>
18 #include "mv88e6xxx.h"
19
20 static const struct mv88e6xxx_info mv88e6171_table[] = {
21         {
22                 .prod_num = PORT_SWITCH_ID_PROD_NUM_6171,
23                 .family = MV88E6XXX_FAMILY_6351,
24                 .name = "Marvell 88E6171",
25                 .num_databases = 4096,
26                 .num_ports = 7,
27                 .flags = MV88E6XXX_FLAGS_FAMILY_6351,
28         }, {
29                 .prod_num = PORT_SWITCH_ID_PROD_NUM_6175,
30                 .family = MV88E6XXX_FAMILY_6351,
31                 .name = "Marvell 88E6175",
32                 .num_databases = 4096,
33                 .num_ports = 7,
34                 .flags = MV88E6XXX_FLAGS_FAMILY_6351,
35         }, {
36                 .prod_num = PORT_SWITCH_ID_PROD_NUM_6350,
37                 .family = MV88E6XXX_FAMILY_6351,
38                 .name = "Marvell 88E6350",
39                 .num_databases = 4096,
40                 .num_ports = 7,
41                 .flags = MV88E6XXX_FLAGS_FAMILY_6351,
42         }, {
43                 .prod_num = PORT_SWITCH_ID_PROD_NUM_6351,
44                 .family = MV88E6XXX_FAMILY_6351,
45                 .name = "Marvell 88E6351",
46                 .num_databases = 4096,
47                 .num_ports = 7,
48                 .flags = MV88E6XXX_FLAGS_FAMILY_6351,
49         }
50 };
51
52 static const char *mv88e6171_drv_probe(struct device *dsa_dev,
53                                        struct device *host_dev, int sw_addr,
54                                        void **priv)
55 {
56         return mv88e6xxx_drv_probe(dsa_dev, host_dev, sw_addr, priv,
57                                    mv88e6171_table,
58                                    ARRAY_SIZE(mv88e6171_table));
59 }
60
61 static int mv88e6171_setup_global(struct dsa_switch *ds)
62 {
63         struct mv88e6xxx_priv_state *ps = ds_to_priv(ds);
64         u32 upstream_port = dsa_upstream_port(ds);
65         int ret;
66         u32 reg;
67
68         ret = mv88e6xxx_setup_global(ds);
69         if (ret)
70                 return ret;
71
72         /* Discard packets with excessive collisions, mask all
73          * interrupt sources, enable PPU.
74          */
75         ret = mv88e6xxx_reg_write(ps, REG_GLOBAL, GLOBAL_CONTROL,
76                                   GLOBAL_CONTROL_PPU_ENABLE |
77                                   GLOBAL_CONTROL_DISCARD_EXCESS);
78         if (ret)
79                 return ret;
80
81         /* Configure the upstream port, and configure the upstream
82          * port as the port to which ingress and egress monitor frames
83          * are to be sent.
84          */
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                 upstream_port << GLOBAL_MONITOR_CONTROL_MIRROR_SHIFT;
89         ret = mv88e6xxx_reg_write(ps, REG_GLOBAL, GLOBAL_MONITOR_CONTROL, reg);
90         if (ret)
91                 return ret;
92
93         /* Disable remote management for now, and set the switch's
94          * DSA device number.
95          */
96         return mv88e6xxx_reg_write(ps, REG_GLOBAL, GLOBAL_CONTROL_2,
97                                    ds->index & 0x1f);
98 }
99
100 static int mv88e6171_setup(struct dsa_switch *ds)
101 {
102         struct mv88e6xxx_priv_state *ps = ds_to_priv(ds);
103         int ret;
104
105         ps->ds = ds;
106
107         ret = mv88e6xxx_setup_common(ps);
108         if (ret < 0)
109                 return ret;
110
111         ret = mv88e6171_setup_global(ds);
112         if (ret < 0)
113                 return ret;
114
115         return mv88e6xxx_setup_ports(ds);
116 }
117
118 struct dsa_switch_driver mv88e6171_switch_driver = {
119         .tag_protocol           = DSA_TAG_PROTO_EDSA,
120         .probe                  = mv88e6171_drv_probe,
121         .setup                  = mv88e6171_setup,
122         .set_addr               = mv88e6xxx_set_addr,
123         .phy_read               = mv88e6xxx_phy_read,
124         .phy_write              = mv88e6xxx_phy_write,
125         .set_eee                = mv88e6xxx_set_eee,
126         .get_eee                = mv88e6xxx_get_eee,
127         .get_strings            = mv88e6xxx_get_strings,
128         .get_ethtool_stats      = mv88e6xxx_get_ethtool_stats,
129         .get_sset_count         = mv88e6xxx_get_sset_count,
130         .adjust_link            = mv88e6xxx_adjust_link,
131 #ifdef CONFIG_NET_DSA_HWMON
132         .get_temp               = mv88e6xxx_get_temp,
133         .get_temp_limit         = mv88e6xxx_get_temp_limit,
134         .set_temp_limit         = mv88e6xxx_set_temp_limit,
135         .get_temp_alarm         = mv88e6xxx_get_temp_alarm,
136 #endif
137         .get_eeprom             = mv88e6xxx_get_eeprom,
138         .set_eeprom             = mv88e6xxx_set_eeprom,
139         .get_regs_len           = mv88e6xxx_get_regs_len,
140         .get_regs               = mv88e6xxx_get_regs,
141         .port_bridge_join       = mv88e6xxx_port_bridge_join,
142         .port_bridge_leave      = mv88e6xxx_port_bridge_leave,
143         .port_stp_state_set     = mv88e6xxx_port_stp_state_set,
144         .port_vlan_filtering    = mv88e6xxx_port_vlan_filtering,
145         .port_vlan_prepare      = mv88e6xxx_port_vlan_prepare,
146         .port_vlan_add          = mv88e6xxx_port_vlan_add,
147         .port_vlan_del          = mv88e6xxx_port_vlan_del,
148         .port_vlan_dump         = mv88e6xxx_port_vlan_dump,
149         .port_fdb_prepare       = mv88e6xxx_port_fdb_prepare,
150         .port_fdb_add           = mv88e6xxx_port_fdb_add,
151         .port_fdb_del           = mv88e6xxx_port_fdb_del,
152         .port_fdb_dump          = mv88e6xxx_port_fdb_dump,
153 };
154
155 MODULE_ALIAS("platform:mv88e6171");
156 MODULE_ALIAS("platform:mv88e6175");
157 MODULE_ALIAS("platform:mv88e6350");
158 MODULE_ALIAS("platform:mv88e6351");