blob: 776e6ef3e29c45d5cad5b938b5fc7c911fc67c51 [file] [log] [blame]
Lennert Buytenhek91da11f2008-10-07 13:44:02 +00001/*
2 * net/dsa/mv88e6123_61_65.c - Marvell 88e6123/6161/6165 switch chip support
Lennert Buytenheke84665c2009-03-20 09:52:09 +00003 * Copyright (c) 2008-2009 Marvell Semiconductor
Lennert Buytenhek91da11f2008-10-07 13:44:02 +00004 *
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
Barry Grussling19b2f972013-01-08 16:05:54 +000011#include <linux/delay.h>
12#include <linux/jiffies.h>
Lennert Buytenhek91da11f2008-10-07 13:44:02 +000013#include <linux/list.h>
Paul Gortmaker2bbba272012-01-24 10:41:40 +000014#include <linux/module.h>
Lennert Buytenhek91da11f2008-10-07 13:44:02 +000015#include <linux/netdevice.h>
16#include <linux/phy.h>
Ben Hutchingsc8f0b862011-11-27 17:06:08 +000017#include <net/dsa.h>
Lennert Buytenhek91da11f2008-10-07 13:44:02 +000018#include "mv88e6xxx.h"
19
Vivien Didelotf6271e62016-04-17 13:23:59 -040020static const struct mv88e6xxx_info mv88e6123_table[] = {
21 {
22 .prod_num = PORT_SWITCH_ID_PROD_NUM_6123,
Vivien Didelot22356472016-04-17 13:24:00 -040023 .family = MV88E6XXX_FAMILY_6165,
Vivien Didelotf6271e62016-04-17 13:23:59 -040024 .name = "Marvell 88E6123",
25 }, {
26 .prod_num = PORT_SWITCH_ID_PROD_NUM_6161,
Vivien Didelot22356472016-04-17 13:24:00 -040027 .family = MV88E6XXX_FAMILY_6165,
Vivien Didelotf6271e62016-04-17 13:23:59 -040028 .name = "Marvell 88E6161",
29 }, {
30 .prod_num = PORT_SWITCH_ID_PROD_NUM_6165,
Vivien Didelot22356472016-04-17 13:24:00 -040031 .family = MV88E6XXX_FAMILY_6165,
Vivien Didelotf6271e62016-04-17 13:23:59 -040032 .name = "Marvell 88E6165",
33 }
Vivien Didelotb9b37712015-10-30 19:39:48 -040034};
35
Vivien Didelot0209d142016-04-17 13:23:55 -040036static const char *mv88e6123_drv_probe(struct device *dsa_dev,
37 struct device *host_dev, int sw_addr,
38 void **priv)
Lennert Buytenhek91da11f2008-10-07 13:44:02 +000039{
Andrew Lunna77d43f2016-04-13 02:40:42 +020040 return mv88e6xxx_drv_probe(dsa_dev, host_dev, sw_addr, priv,
41 mv88e6123_table,
42 ARRAY_SIZE(mv88e6123_table));
Lennert Buytenhek91da11f2008-10-07 13:44:02 +000043}
44
Andrew Lunnca3dfa52016-03-12 00:01:36 +010045static int mv88e6123_setup_global(struct dsa_switch *ds)
Lennert Buytenhek91da11f2008-10-07 13:44:02 +000046{
Andrew Lunn15966a22015-05-06 01:09:49 +020047 u32 upstream_port = dsa_upstream_port(ds);
Lennert Buytenhek91da11f2008-10-07 13:44:02 +000048 int ret;
Andrew Lunn15966a22015-05-06 01:09:49 +020049 u32 reg;
Andrew Lunn54d792f2015-05-06 01:09:47 +020050
51 ret = mv88e6xxx_setup_global(ds);
52 if (ret)
53 return ret;
Lennert Buytenhek91da11f2008-10-07 13:44:02 +000054
Barry Grussling3675c8d2013-01-08 16:05:53 +000055 /* Disable the PHY polling unit (since there won't be any
Lennert Buytenhek91da11f2008-10-07 13:44:02 +000056 * external PHYs to poll), don't discard packets with
57 * excessive collisions, and mask all interrupt sources.
58 */
Andrew Lunn48ace4e2016-04-14 23:47:12 +020059 ret = mv88e6xxx_reg_write(ds, REG_GLOBAL, GLOBAL_CONTROL, 0x0000);
60 if (ret)
61 return ret;
Lennert Buytenhek91da11f2008-10-07 13:44:02 +000062
Barry Grussling3675c8d2013-01-08 16:05:53 +000063 /* Configure the upstream port, and configure the upstream
Lennert Buytenheke84665c2009-03-20 09:52:09 +000064 * port as the port to which ingress and egress monitor frames
65 * are to be sent.
Lennert Buytenhek91da11f2008-10-07 13:44:02 +000066 */
Andrew Lunn15966a22015-05-06 01:09:49 +020067 reg = upstream_port << GLOBAL_MONITOR_CONTROL_INGRESS_SHIFT |
68 upstream_port << GLOBAL_MONITOR_CONTROL_EGRESS_SHIFT |
69 upstream_port << GLOBAL_MONITOR_CONTROL_ARP_SHIFT;
Andrew Lunn48ace4e2016-04-14 23:47:12 +020070 ret = mv88e6xxx_reg_write(ds, REG_GLOBAL, GLOBAL_MONITOR_CONTROL, reg);
71 if (ret)
72 return ret;
Lennert Buytenhek91da11f2008-10-07 13:44:02 +000073
Barry Grussling3675c8d2013-01-08 16:05:53 +000074 /* Disable remote management for now, and set the switch's
Lennert Buytenheke84665c2009-03-20 09:52:09 +000075 * DSA device number.
Lennert Buytenhek91da11f2008-10-07 13:44:02 +000076 */
Andrew Lunn48ace4e2016-04-14 23:47:12 +020077 return mv88e6xxx_reg_write(ds, REG_GLOBAL, GLOBAL_CONTROL_2,
78 ds->index & 0x1f);
Lennert Buytenhek91da11f2008-10-07 13:44:02 +000079}
80
Andrew Lunnca3dfa52016-03-12 00:01:36 +010081static int mv88e6123_setup(struct dsa_switch *ds)
Lennert Buytenhek91da11f2008-10-07 13:44:02 +000082{
Guenter Roeck14ef6ad2015-04-02 04:06:32 +020083 struct mv88e6xxx_priv_state *ps = ds_to_priv(ds);
Lennert Buytenhek91da11f2008-10-07 13:44:02 +000084 int ret;
85
Guenter Roeckacdaffc2015-03-26 18:36:28 -070086 ret = mv88e6xxx_setup_common(ds);
87 if (ret < 0)
88 return ret;
Lennert Buytenhek91da11f2008-10-07 13:44:02 +000089
Guenter Roeck14ef6ad2015-04-02 04:06:32 +020090 switch (ps->id) {
Andrew Lunncca8b132015-04-02 04:06:39 +020091 case PORT_SWITCH_ID_6123:
Guenter Roeck14ef6ad2015-04-02 04:06:32 +020092 ps->num_ports = 3;
93 break;
Andrew Lunncca8b132015-04-02 04:06:39 +020094 case PORT_SWITCH_ID_6161:
95 case PORT_SWITCH_ID_6165:
Guenter Roeck14ef6ad2015-04-02 04:06:32 +020096 ps->num_ports = 6;
97 break;
98 default:
99 return -ENODEV;
100 }
101
Andrew Lunn143a8302015-04-02 04:06:34 +0200102 ret = mv88e6xxx_switch_reset(ds, false);
Lennert Buytenhek91da11f2008-10-07 13:44:02 +0000103 if (ret < 0)
104 return ret;
105
Andrew Lunnca3dfa52016-03-12 00:01:36 +0100106 ret = mv88e6123_setup_global(ds);
Lennert Buytenhek91da11f2008-10-07 13:44:02 +0000107 if (ret < 0)
108 return ret;
109
Andrew Lunndbde9e62015-05-06 01:09:48 +0200110 return mv88e6xxx_setup_ports(ds);
Lennert Buytenhek91da11f2008-10-07 13:44:02 +0000111}
112
Andrew Lunnca3dfa52016-03-12 00:01:36 +0100113struct dsa_switch_driver mv88e6123_switch_driver = {
Florian Fainelliac7a04c2014-09-11 21:18:09 -0700114 .tag_protocol = DSA_TAG_PROTO_EDSA,
Andrew Lunne49bad32016-04-13 02:40:43 +0200115 .probe = mv88e6123_drv_probe,
Andrew Lunnca3dfa52016-03-12 00:01:36 +0100116 .setup = mv88e6123_setup,
Lennert Buytenhek91da11f2008-10-07 13:44:02 +0000117 .set_addr = mv88e6xxx_set_addr_indirect,
Andrew Lunnfd3a0ee2015-04-02 04:06:36 +0200118 .phy_read = mv88e6xxx_phy_read,
119 .phy_write = mv88e6xxx_phy_write,
Andrew Lunne413e7e2015-04-02 04:06:38 +0200120 .get_strings = mv88e6xxx_get_strings,
121 .get_ethtool_stats = mv88e6xxx_get_ethtool_stats,
122 .get_sset_count = mv88e6xxx_get_sset_count,
Andrew Lunndea87022015-08-31 15:56:47 +0200123 .adjust_link = mv88e6xxx_adjust_link,
Guenter Roeck87e5f662014-10-29 10:45:00 -0700124#ifdef CONFIG_NET_DSA_HWMON
Andrew Lunneaa23762014-11-15 22:24:51 +0100125 .get_temp = mv88e6xxx_get_temp,
Guenter Roeck87e5f662014-10-29 10:45:00 -0700126#endif
Guenter Roecka1ab91f2014-10-29 10:45:05 -0700127 .get_regs_len = mv88e6xxx_get_regs_len,
128 .get_regs = mv88e6xxx_get_regs,
Lennert Buytenhek91da11f2008-10-07 13:44:02 +0000129};
Ben Hutchings3d825ed2011-11-25 14:37:16 +0000130
131MODULE_ALIAS("platform:mv88e6123");
132MODULE_ALIAS("platform:mv88e6161");
133MODULE_ALIAS("platform:mv88e6165");