mv88e6123_61_65.c 3.6 KB
Newer Older
1 2
/*
 * net/dsa/mv88e6123_61_65.c - Marvell 88e6123/6161/6165 switch chip support
3
 * Copyright (c) 2008-2009 Marvell Semiconductor
4 5 6 7 8 9 10
 *
 * This program is free software; you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation; either version 2 of the License, or
 * (at your option) any later version.
 */

11 12
#include <linux/delay.h>
#include <linux/jiffies.h>
13
#include <linux/list.h>
14
#include <linux/module.h>
15 16
#include <linux/netdevice.h>
#include <linux/phy.h>
17
#include <net/dsa.h>
18 19
#include "mv88e6xxx.h"

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 24
	int ret;

25 26 27
	if (bus == NULL)
		return NULL;

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 50 51 52 53 54 55 56 57
			return "Marvell 88E6165";
	}

	return NULL;
}

static int mv88e6123_61_65_setup_global(struct dsa_switch *ds)
{
	int ret;
58 59 60 61

	ret = mv88e6xxx_setup_global(ds);
	if (ret)
		return ret;
62

63
	/* Disable the PHY polling unit (since there won't be any
64 65 66 67 68
	 * external PHYs to poll), don't discard packets with
	 * excessive collisions, and mask all interrupt sources.
	 */
	REG_WRITE(REG_GLOBAL, 0x04, 0x0000);

69
	/* Configure the upstream port, and configure the upstream
70 71
	 * port as the port to which ingress and egress monitor frames
	 * are to be sent.
72
	 */
73
	REG_WRITE(REG_GLOBAL, 0x1a, (dsa_upstream_port(ds) * 0x1110));
74

75
	/* Disable remote management for now, and set the switch's
76
	 * DSA device number.
77
	 */
78
	REG_WRITE(REG_GLOBAL, 0x1c, ds->index & 0x1f);
79 80 81 82 83 84

	return 0;
}

static int mv88e6123_61_65_setup(struct dsa_switch *ds)
{
85
	struct mv88e6xxx_priv_state *ps = ds_to_priv(ds);
86 87 88
	int i;
	int ret;

89 90 91
	ret = mv88e6xxx_setup_common(ds);
	if (ret < 0)
		return ret;
92

93
	switch (ps->id) {
94
	case PORT_SWITCH_ID_6123:
95 96
		ps->num_ports = 3;
		break;
97 98
	case PORT_SWITCH_ID_6161:
	case PORT_SWITCH_ID_6165:
99 100 101 102 103 104
		ps->num_ports = 6;
		break;
	default:
		return -ENODEV;
	}

105
	ret = mv88e6xxx_switch_reset(ds, false);
106 107 108 109 110 111 112
	if (ret < 0)
		return ret;

	ret = mv88e6123_61_65_setup_global(ds);
	if (ret < 0)
		return ret;

113
	for (i = 0; i < ps->num_ports; i++) {
114
		ret = mv88e6xxx_setup_port(ds, i);
115 116 117 118 119 120 121
		if (ret < 0)
			return ret;
	}

	return 0;
}

122
struct dsa_switch_driver mv88e6123_61_65_switch_driver = {
123
	.tag_protocol		= DSA_TAG_PROTO_EDSA,
124 125 126 127
	.priv_size		= sizeof(struct mv88e6xxx_priv_state),
	.probe			= mv88e6123_61_65_probe,
	.setup			= mv88e6123_61_65_setup,
	.set_addr		= mv88e6xxx_set_addr_indirect,
128 129
	.phy_read		= mv88e6xxx_phy_read,
	.phy_write		= mv88e6xxx_phy_write,
130
	.poll_link		= mv88e6xxx_poll_link,
131 132 133
	.get_strings		= mv88e6xxx_get_strings,
	.get_ethtool_stats	= mv88e6xxx_get_ethtool_stats,
	.get_sset_count		= mv88e6xxx_get_sset_count,
134
#ifdef CONFIG_NET_DSA_HWMON
135
	.get_temp		= mv88e6xxx_get_temp,
136
#endif
137 138
	.get_regs_len		= mv88e6xxx_get_regs_len,
	.get_regs		= mv88e6xxx_get_regs,
139
};
140 141 142 143

MODULE_ALIAS("platform:mv88e6123");
MODULE_ALIAS("platform:mv88e6161");
MODULE_ALIAS("platform:mv88e6165");