a848aefb4c74837ecdc4f5394045d1ba44837e2b
[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
65         /* Disable remote management for now, and set the switch's
66          * DSA device number.
67          */
68         return mv88e6xxx_reg_write(ps, REG_GLOBAL, GLOBAL_CONTROL_2,
69                                    ds->index & 0x1f);
70 }
71
72 static int mv88e6171_setup(struct dsa_switch *ds)
73 {
74         struct mv88e6xxx_priv_state *ps = ds_to_priv(ds);
75         int ret;
76
77         ps->ds = ds;
78
79         ret = mv88e6xxx_setup_common(ps);
80         if (ret < 0)
81                 return ret;
82
83         ret = mv88e6171_setup_global(ds);
84         if (ret < 0)
85                 return ret;
86
87         return mv88e6xxx_setup_ports(ds);
88 }
89
90 struct dsa_switch_driver mv88e6171_switch_driver = {
91         .tag_protocol           = DSA_TAG_PROTO_EDSA,
92         .probe                  = mv88e6171_drv_probe,
93         .setup                  = mv88e6171_setup,
94         .set_addr               = mv88e6xxx_set_addr,
95         .phy_read               = mv88e6xxx_phy_read,
96         .phy_write              = mv88e6xxx_phy_write,
97         .set_eee                = mv88e6xxx_set_eee,
98         .get_eee                = mv88e6xxx_get_eee,
99         .get_strings            = mv88e6xxx_get_strings,
100         .get_ethtool_stats      = mv88e6xxx_get_ethtool_stats,
101         .get_sset_count         = mv88e6xxx_get_sset_count,
102         .adjust_link            = mv88e6xxx_adjust_link,
103 #ifdef CONFIG_NET_DSA_HWMON
104         .get_temp               = mv88e6xxx_get_temp,
105         .get_temp_limit         = mv88e6xxx_get_temp_limit,
106         .set_temp_limit         = mv88e6xxx_set_temp_limit,
107         .get_temp_alarm         = mv88e6xxx_get_temp_alarm,
108 #endif
109         .get_eeprom             = mv88e6xxx_get_eeprom,
110         .set_eeprom             = mv88e6xxx_set_eeprom,
111         .get_regs_len           = mv88e6xxx_get_regs_len,
112         .get_regs               = mv88e6xxx_get_regs,
113         .port_bridge_join       = mv88e6xxx_port_bridge_join,
114         .port_bridge_leave      = mv88e6xxx_port_bridge_leave,
115         .port_stp_state_set     = mv88e6xxx_port_stp_state_set,
116         .port_vlan_filtering    = mv88e6xxx_port_vlan_filtering,
117         .port_vlan_prepare      = mv88e6xxx_port_vlan_prepare,
118         .port_vlan_add          = mv88e6xxx_port_vlan_add,
119         .port_vlan_del          = mv88e6xxx_port_vlan_del,
120         .port_vlan_dump         = mv88e6xxx_port_vlan_dump,
121         .port_fdb_prepare       = mv88e6xxx_port_fdb_prepare,
122         .port_fdb_add           = mv88e6xxx_port_fdb_add,
123         .port_fdb_del           = mv88e6xxx_port_fdb_del,
124         .port_fdb_dump          = mv88e6xxx_port_fdb_dump,
125 };
126
127 MODULE_ALIAS("platform:mv88e6171");
128 MODULE_ALIAS("platform:mv88e6175");
129 MODULE_ALIAS("platform:mv88e6350");
130 MODULE_ALIAS("platform:mv88e6351");