Merge tag 'for-linus-4.2-rc0-tag' of git://git.kernel.org/pub/scm/linux/kernel/git...
[deliverable/linux.git] / drivers / net / dsa / mv88e6123_61_65.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 char *mv88e6123_61_65_probe(struct device *host_dev, int sw_addr)
21 {
22 struct mii_bus *bus = dsa_host_dev_to_mii_bus(host_dev);
23 int ret;
24
25 if (bus == NULL)
26 return NULL;
27
28 ret = __mv88e6xxx_reg_read(bus, sw_addr, REG_PORT(0), PORT_SWITCH_ID);
29 if (ret >= 0) {
30 if (ret == PORT_SWITCH_ID_6123_A1)
31 return "Marvell 88E6123 (A1)";
32 if (ret == PORT_SWITCH_ID_6123_A2)
33 return "Marvell 88E6123 (A2)";
34 if ((ret & 0xfff0) == PORT_SWITCH_ID_6123)
35 return "Marvell 88E6123";
36
37 if (ret == PORT_SWITCH_ID_6161_A1)
38 return "Marvell 88E6161 (A1)";
39 if (ret == PORT_SWITCH_ID_6161_A2)
40 return "Marvell 88E6161 (A2)";
41 if ((ret & 0xfff0) == PORT_SWITCH_ID_6161)
42 return "Marvell 88E6161";
43
44 if (ret == PORT_SWITCH_ID_6165_A1)
45 return "Marvell 88E6165 (A1)";
46 if (ret == PORT_SWITCH_ID_6165_A2)
47 return "Marvell 88e6165 (A2)";
48 if ((ret & 0xfff0) == PORT_SWITCH_ID_6165)
49 return "Marvell 88E6165";
50 }
51
52 return NULL;
53 }
54
55 static int mv88e6123_61_65_setup_global(struct dsa_switch *ds)
56 {
57 u32 upstream_port = dsa_upstream_port(ds);
58 int ret;
59 u32 reg;
60
61 ret = mv88e6xxx_setup_global(ds);
62 if (ret)
63 return ret;
64
65 /* Disable the PHY polling unit (since there won't be any
66 * external PHYs to poll), don't discard packets with
67 * excessive collisions, and mask all interrupt sources.
68 */
69 REG_WRITE(REG_GLOBAL, GLOBAL_CONTROL, 0x0000);
70
71 /* Configure the upstream port, and configure the upstream
72 * port as the port to which ingress and egress monitor frames
73 * are to be sent.
74 */
75 reg = upstream_port << GLOBAL_MONITOR_CONTROL_INGRESS_SHIFT |
76 upstream_port << GLOBAL_MONITOR_CONTROL_EGRESS_SHIFT |
77 upstream_port << GLOBAL_MONITOR_CONTROL_ARP_SHIFT;
78 REG_WRITE(REG_GLOBAL, GLOBAL_MONITOR_CONTROL, reg);
79
80 /* Disable remote management for now, and set the switch's
81 * DSA device number.
82 */
83 REG_WRITE(REG_GLOBAL, GLOBAL_CONTROL_2, ds->index & 0x1f);
84
85 return 0;
86 }
87
88 static int mv88e6123_61_65_setup(struct dsa_switch *ds)
89 {
90 struct mv88e6xxx_priv_state *ps = ds_to_priv(ds);
91 int ret;
92
93 ret = mv88e6xxx_setup_common(ds);
94 if (ret < 0)
95 return ret;
96
97 switch (ps->id) {
98 case PORT_SWITCH_ID_6123:
99 ps->num_ports = 3;
100 break;
101 case PORT_SWITCH_ID_6161:
102 case PORT_SWITCH_ID_6165:
103 ps->num_ports = 6;
104 break;
105 default:
106 return -ENODEV;
107 }
108
109 ret = mv88e6xxx_switch_reset(ds, false);
110 if (ret < 0)
111 return ret;
112
113 ret = mv88e6123_61_65_setup_global(ds);
114 if (ret < 0)
115 return ret;
116
117 return mv88e6xxx_setup_ports(ds);
118 }
119
120 struct dsa_switch_driver mv88e6123_61_65_switch_driver = {
121 .tag_protocol = DSA_TAG_PROTO_EDSA,
122 .priv_size = sizeof(struct mv88e6xxx_priv_state),
123 .probe = mv88e6123_61_65_probe,
124 .setup = mv88e6123_61_65_setup,
125 .set_addr = mv88e6xxx_set_addr_indirect,
126 .phy_read = mv88e6xxx_phy_read,
127 .phy_write = mv88e6xxx_phy_write,
128 .poll_link = mv88e6xxx_poll_link,
129 .get_strings = mv88e6xxx_get_strings,
130 .get_ethtool_stats = mv88e6xxx_get_ethtool_stats,
131 .get_sset_count = mv88e6xxx_get_sset_count,
132 #ifdef CONFIG_NET_DSA_HWMON
133 .get_temp = mv88e6xxx_get_temp,
134 #endif
135 .get_regs_len = mv88e6xxx_get_regs_len,
136 .get_regs = mv88e6xxx_get_regs,
137 };
138
139 MODULE_ALIAS("platform:mv88e6123");
140 MODULE_ALIAS("platform:mv88e6161");
141 MODULE_ALIAS("platform:mv88e6165");
This page took 0.048288 seconds and 5 git commands to generate.