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