net: dsa: mv88e6xxx: add number of ports to info
[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_info mv88e6123_table[] = {
21         {
22                 .prod_num = PORT_SWITCH_ID_PROD_NUM_6123,
23                 .family = MV88E6XXX_FAMILY_6165,
24                 .name = "Marvell 88E6123",
25                 .num_ports = 3,
26         }, {
27                 .prod_num = PORT_SWITCH_ID_PROD_NUM_6161,
28                 .family = MV88E6XXX_FAMILY_6165,
29                 .name = "Marvell 88E6161",
30                 .num_ports = 6,
31         }, {
32                 .prod_num = PORT_SWITCH_ID_PROD_NUM_6165,
33                 .family = MV88E6XXX_FAMILY_6165,
34                 .name = "Marvell 88E6165",
35                 .num_ports = 6,
36         }
37 };
38
39 static const char *mv88e6123_drv_probe(struct device *dsa_dev,
40                                        struct device *host_dev, int sw_addr,
41                                        void **priv)
42 {
43         return mv88e6xxx_drv_probe(dsa_dev, host_dev, sw_addr, priv,
44                                    mv88e6123_table,
45                                    ARRAY_SIZE(mv88e6123_table));
46 }
47
48 static int mv88e6123_setup_global(struct dsa_switch *ds)
49 {
50         u32 upstream_port = dsa_upstream_port(ds);
51         int ret;
52         u32 reg;
53
54         ret = mv88e6xxx_setup_global(ds);
55         if (ret)
56                 return ret;
57
58         /* Disable the PHY polling unit (since there won't be any
59          * external PHYs to poll), don't discard packets with
60          * excessive collisions, and mask all interrupt sources.
61          */
62         ret = mv88e6xxx_reg_write(ds, REG_GLOBAL, GLOBAL_CONTROL, 0x0000);
63         if (ret)
64                 return ret;
65
66         /* Configure the upstream port, and configure the upstream
67          * port as the port to which ingress and egress monitor frames
68          * are to be sent.
69          */
70         reg = upstream_port << GLOBAL_MONITOR_CONTROL_INGRESS_SHIFT |
71                 upstream_port << GLOBAL_MONITOR_CONTROL_EGRESS_SHIFT |
72                 upstream_port << GLOBAL_MONITOR_CONTROL_ARP_SHIFT;
73         ret = mv88e6xxx_reg_write(ds, REG_GLOBAL, GLOBAL_MONITOR_CONTROL, reg);
74         if (ret)
75                 return ret;
76
77         /* Disable remote management for now, and set the switch's
78          * DSA device number.
79          */
80         return mv88e6xxx_reg_write(ds, REG_GLOBAL, GLOBAL_CONTROL_2,
81                                    ds->index & 0x1f);
82 }
83
84 static int mv88e6123_setup(struct dsa_switch *ds)
85 {
86         int ret;
87
88         ret = mv88e6xxx_setup_common(ds);
89         if (ret < 0)
90                 return ret;
91
92         ret = mv88e6xxx_switch_reset(ds, false);
93         if (ret < 0)
94                 return ret;
95
96         ret = mv88e6123_setup_global(ds);
97         if (ret < 0)
98                 return ret;
99
100         return mv88e6xxx_setup_ports(ds);
101 }
102
103 struct dsa_switch_driver mv88e6123_switch_driver = {
104         .tag_protocol           = DSA_TAG_PROTO_EDSA,
105         .probe                  = mv88e6123_drv_probe,
106         .setup                  = mv88e6123_setup,
107         .set_addr               = mv88e6xxx_set_addr_indirect,
108         .phy_read               = mv88e6xxx_phy_read,
109         .phy_write              = mv88e6xxx_phy_write,
110         .get_strings            = mv88e6xxx_get_strings,
111         .get_ethtool_stats      = mv88e6xxx_get_ethtool_stats,
112         .get_sset_count         = mv88e6xxx_get_sset_count,
113         .adjust_link            = mv88e6xxx_adjust_link,
114 #ifdef CONFIG_NET_DSA_HWMON
115         .get_temp               = mv88e6xxx_get_temp,
116 #endif
117         .get_regs_len           = mv88e6xxx_get_regs_len,
118         .get_regs               = mv88e6xxx_get_regs,
119 };
120
121 MODULE_ALIAS("platform:mv88e6123");
122 MODULE_ALIAS("platform:mv88e6161");
123 MODULE_ALIAS("platform:mv88e6165");