ede4c6f0b31ad63252f3ea803b8b7d5ec643d2d9
[cascardo/linux.git] / drivers / net / dsa / mv88e6123.c
1 /*
2  * net/dsa/mv88e6123_61_65.c - Marvell 88e6123/6161/6165 switch chip support
3  * Copyright (c) 2008-2009 Marvell Semiconductor
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_switch_id mv88e6123_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
32 static char *mv88e6123_probe(struct device *dsa_dev, struct device *host_dev,
33                              int sw_addr)
34 {
35         return mv88e6xxx_lookup_name(host_dev, sw_addr, mv88e6123_table,
36                                      ARRAY_SIZE(mv88e6123_table));
37 }
38
39 static int mv88e6123_setup_global(struct dsa_switch *ds)
40 {
41         u32 upstream_port = dsa_upstream_port(ds);
42         int ret;
43         u32 reg;
44
45         ret = mv88e6xxx_setup_global(ds);
46         if (ret)
47                 return ret;
48
49         /* Disable the PHY polling unit (since there won't be any
50          * external PHYs to poll), don't discard packets with
51          * excessive collisions, and mask all interrupt sources.
52          */
53         REG_WRITE(REG_GLOBAL, GLOBAL_CONTROL, 0x0000);
54
55         /* Configure the upstream port, and configure the upstream
56          * port as the port to which ingress and egress monitor frames
57          * are to be sent.
58          */
59         reg = upstream_port << GLOBAL_MONITOR_CONTROL_INGRESS_SHIFT |
60                 upstream_port << GLOBAL_MONITOR_CONTROL_EGRESS_SHIFT |
61                 upstream_port << GLOBAL_MONITOR_CONTROL_ARP_SHIFT;
62         REG_WRITE(REG_GLOBAL, GLOBAL_MONITOR_CONTROL, reg);
63
64         /* Disable remote management for now, and set the switch's
65          * DSA device number.
66          */
67         REG_WRITE(REG_GLOBAL, GLOBAL_CONTROL_2, ds->index & 0x1f);
68
69         return 0;
70 }
71
72 static int mv88e6123_setup(struct dsa_switch *ds)
73 {
74         struct mv88e6xxx_priv_state *ps = ds_to_priv(ds);
75         int ret;
76
77         ret = mv88e6xxx_setup_common(ds);
78         if (ret < 0)
79                 return ret;
80
81         switch (ps->id) {
82         case PORT_SWITCH_ID_6123:
83                 ps->num_ports = 3;
84                 break;
85         case PORT_SWITCH_ID_6161:
86         case PORT_SWITCH_ID_6165:
87                 ps->num_ports = 6;
88                 break;
89         default:
90                 return -ENODEV;
91         }
92
93         ret = mv88e6xxx_switch_reset(ds, false);
94         if (ret < 0)
95                 return ret;
96
97         ret = mv88e6123_setup_global(ds);
98         if (ret < 0)
99                 return ret;
100
101         return mv88e6xxx_setup_ports(ds);
102 }
103
104 struct dsa_switch_driver mv88e6123_switch_driver = {
105         .tag_protocol           = DSA_TAG_PROTO_EDSA,
106         .priv_size              = sizeof(struct mv88e6xxx_priv_state),
107         .probe                  = mv88e6123_probe,
108         .setup                  = mv88e6123_setup,
109         .set_addr               = mv88e6xxx_set_addr_indirect,
110         .phy_read               = mv88e6xxx_phy_read,
111         .phy_write              = mv88e6xxx_phy_write,
112         .get_strings            = mv88e6xxx_get_strings,
113         .get_ethtool_stats      = mv88e6xxx_get_ethtool_stats,
114         .get_sset_count         = mv88e6xxx_get_sset_count,
115         .adjust_link            = mv88e6xxx_adjust_link,
116 #ifdef CONFIG_NET_DSA_HWMON
117         .get_temp               = mv88e6xxx_get_temp,
118 #endif
119         .get_regs_len           = mv88e6xxx_get_regs_len,
120         .get_regs               = mv88e6xxx_get_regs,
121 };
122
123 MODULE_ALIAS("platform:mv88e6123");
124 MODULE_ALIAS("platform:mv88e6161");
125 MODULE_ALIAS("platform:mv88e6165");