aboutsummaryrefslogtreecommitdiffstats
path: root/package/boot/uboot-lantiq/patches/0012-net-switchlib-add-driver-for-Atheros-AR8216.patch
blob: c270b888015d0930959971aac2a9cf504ef833c9 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
From 1a1d61a2faf0390033a3766559ce0e758e15894e Mon Sep 17 00:00:00 2001
From: Luka Perkov <openwrt@lukaperkov.net>
Date: Wed, 29 Aug 2012 22:08:16 +0200
Subject: net: switchlib: add driver for Atheros AR8216

Signed-off-by: Luka Perkov <openwrt@lukaperkov.net>
Signed-off-by: Daniel Schwierzeck <daniel.schwierzeck@gmail.com>

diff --git a/drivers/net/switch/Makefile b/drivers/net/switch/Makefile
index 6b7eeb9..7400897 100644
--- a/drivers/net/switch/Makefile
+++ b/drivers/net/switch/Makefile
@@ -12,6 +12,7 @@ LIB	:= $(obj)libswitch.o
 COBJS-$(CONFIG_SWITCH_MULTI) += switch.o
 COBJS-$(CONFIG_SWITCH_PSB697X) += psb697x.o
 COBJS-$(CONFIG_SWITCH_ADM6996I) += adm6996i.o
+COBJS-$(CONFIG_SWITCH_AR8216) += ar8216.o
 
 COBJS	:= $(COBJS-y)
 SRCS	:= $(COBJS:.o=.c)
diff --git a/drivers/net/switch/ar8216.c b/drivers/net/switch/ar8216.c
new file mode 100644
index 0000000..f1348f0
--- /dev/null
+++ b/drivers/net/switch/ar8216.c
@@ -0,0 +1,114 @@
+/*
+ * Copyright (C) 2012 Luka Perkov <luka@openwrt.org>
+ *
+ * SPDX-License-Identifier:	GPL-2.0+
+ */
+
+#include <common.h>
+#include <malloc.h>
+#include <miiphy.h>
+#include <switch.h>
+#include <netdev.h>
+
+#define BITS(_s, _n)  (((1UL << (_n)) - 1) << _s)
+
+#define AR8216_REG_CTRL			0x0000
+#define   AR8216_CTRL_REVISION		BITS(0, 8)
+#define   AR8216_CTRL_VERSION		BITS(8, 8)
+
+#define AR8216_PROBE_RETRIES		10
+
+static void split_addr(u32 regaddr, u16 *r1, u16 *r2, u16 *page)
+{
+	regaddr >>= 1;
+	*r1 = regaddr & 0x1e;
+
+	regaddr >>= 5;
+	*r2 = regaddr & 0x7;
+
+	regaddr >>= 3;
+	*page = regaddr & 0x1ff;
+}
+
+static int ar8216_mii_read(struct mii_dev *bus, u32 reg)
+{
+	u16 r1, r2, page;
+	u16 lo, hi;
+
+	split_addr(reg, &r1, &r2, &page);
+
+	bus->write(bus, 0x18, MDIO_DEVAD_NONE, 0, page);
+	__udelay(1000);
+
+	lo = bus->read(bus, 0x10 | r2, MDIO_DEVAD_NONE, r1);
+	hi = bus->read(bus, 0x10 | r2, MDIO_DEVAD_NONE, r1 + 1);
+
+	return (hi << 16) | lo;
+}
+
+static void ar8216_mii_write(struct mii_dev *bus, u16 reg, u32 val)
+{
+	u16 r1, r2, r3;
+	u16 lo, hi;
+
+	split_addr((u32) reg, &r1, &r2, &r3);
+
+	bus->write(bus, 0x18, MDIO_DEVAD_NONE, 0, r3);
+	__udelay(1000);
+
+	lo = val & 0xffff;
+	hi = (u16) (val >> 16);
+	bus->write(bus, 0x10 | r2, MDIO_DEVAD_NONE, r1 + 1, hi);
+	bus->write(bus, 0x10 | r2, MDIO_DEVAD_NONE, r1, lo);
+}
+
+static int ar8216_probe(struct switch_device *dev)
+{
+	struct mii_dev *bus = dev->bus;
+	u32 val;
+	u16 id;
+
+	val = ar8216_mii_read(bus, AR8216_REG_CTRL);
+	if (val == ~0)
+		return 1;
+
+	id = val & (AR8216_CTRL_REVISION | AR8216_CTRL_VERSION);
+
+	switch (id) {
+		case 0x0101:
+			return 0;
+		default:
+			return 1;
+	}
+}
+
+static void ar8216_setup(struct switch_device *dev)
+{
+	struct mii_dev *bus = dev->bus;
+
+	ar8216_mii_write(bus, 0x200, 0x200);
+	ar8216_mii_write(bus, 0x300, 0x200);
+	ar8216_mii_write(bus, 0x400, 0x200);
+	ar8216_mii_write(bus, 0x500, 0x200);
+	ar8216_mii_write(bus, 0x600, 0x7d);
+	ar8216_mii_write(bus, 0x38, 0xc000050e);
+	ar8216_mii_write(bus, 0x104, 0x4004);
+	ar8216_mii_write(bus, 0x60, 0xffffffff);
+	ar8216_mii_write(bus, 0x64, 0xaaaaaaaa);
+	ar8216_mii_write(bus, 0x68, 0x55555555);
+	ar8216_mii_write(bus, 0x6c, 0x0);
+	ar8216_mii_write(bus, 0x70, 0x41af);
+}
+
+static struct switch_driver ar8216_drv = {
+	.name = "ar8216",
+};
+
+void switch_ar8216_init(void)
+{
+	/* for archs with manual relocation */
+	ar8216_drv.probe = ar8216_probe;
+	ar8216_drv.setup = ar8216_setup;
+
+	switch_driver_register(&ar8216_drv);
+}
diff --git a/drivers/net/switch/switch.c b/drivers/net/switch/switch.c
index ea3fe9c..3e34a7f 100644
--- a/drivers/net/switch/switch.c
+++ b/drivers/net/switch/switch.c
@@ -23,6 +23,9 @@ void switch_init(void)
 #if defined(CONFIG_SWITCH_ADM6996I)
 	switch_adm6996i_init();
 #endif
+#if defined(CONFIG_SWITCH_AR8216)
+	switch_ar8216_init();
+#endif
 
 	board_switch_init();
 }
diff --git a/include/switch.h b/include/switch.h
index 4b46df0..ae7b123 100644
--- a/include/switch.h
+++ b/include/switch.h
@@ -99,6 +99,7 @@ static inline void switch_setup(struct switch_device *dev)
 /* Init functions for supported Switch drivers */
 extern void switch_psb697x_init(void);
 extern void switch_adm6996i_init(void);
+extern void switch_ar8216_init(void);
 
 #endif /* __SWITCH_H */
 
-- 
1.8.3.2