summaryrefslogtreecommitdiffstats
path: root/package/boot/uboot-lantiq/patches/0021-net-switchlib-add-driver-for-Lantiq-ADM6996I-switch-.patch
blob: 342fa46efdc2d77a14c8496852505e0f3a90fd31 (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
From fcbbb1beb2ae862f5c703c5719ed0e155cbbf82f Mon Sep 17 00:00:00 2001
From: Daniel Schwierzeck <daniel.schwierzeck@gmail.com>
Date: Wed, 29 Aug 2012 22:08:16 +0200
Subject: net: switchlib: add driver for Lantiq ADM6996I switch family

Signed-off-by: Daniel Schwierzeck <daniel.schwierzeck@gmail.com>

--- 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	:= $(COBJS-y)
 SRCS	:= $(COBJS:.o=.c)
--- /dev/null
+++ b/drivers/net/switch/adm6996i.c
@@ -0,0 +1,116 @@
+/*
+ * Copyright (C) 2011-2012 Daniel Schwierzeck, daniel.schwierzeck@gmail.com
+ *
+ * This file is released under the terms of GPL v2 and any later version.
+ * See the file COPYING in the root directory of the source tree for details.
+ */
+
+#include <common.h>
+#include <malloc.h>
+#include <switch.h>
+#include <miiphy.h>
+
+#define ADM6996I_CHIPID0	0x1020
+#define ADM6996I_CHIPID1	0x0007
+#define ADM6996I_PORT_COUNT	6
+
+#define ADM6996I_REG_P0BC	0x001	/* P0 Basic Control */
+#define ADM6996I_REG_P1BC	0x003	/* P1 Basic Control */
+#define ADM6996I_REG_P2BC	0x005	/* P2 Basic Control */
+#define ADM6996I_REG_P3BC	0x007	/* P3 Basic Control */
+#define ADM6996I_REG_P4BC	0x008	/* P4 Basic Control */
+#define ADM6996I_REG_P5BC	0x009	/* P5 Basic Control */
+
+#define ADM6996I_REG_P0EC	0x002	/* P0 Extended Control */
+#define ADM6996I_REG_P1EC	0x002	/* P1 Extended Control */
+#define ADM6996I_REG_P2EC	0x004	/* P2 Extended Control */
+#define ADM6996I_REG_P3EC	0x004	/* P3 Extended Control */
+#define ADM6996I_REG_P4EC	0x006	/* P4 Extended Control */
+#define ADM6996I_REG_P5EC	0x006	/* P5 Extended Control */
+
+#define ADM6996I_REG_SC4	0x012	/* System Control 4 */
+
+#define ADM6996I_REG_CI0	0xA0	/* Chip Identifier 0 */
+#define ADM6996I_REG_CI1	0xA1	/* Chip Identifier 1 */
+
+#define ADM6996I_REG_PXBC_DEFAULT	0x040F
+#define ADM6996I_REG_PXBC_CROSS_EE	(1 << 15)
+#define ADM6996I_REG_PXBC_PD		(1 << 5)
+
+#define ADM6996I_REG_SC4_DEFAULT	0x3600
+#define ADM6996I_REG_SC4_LED_ENABLE	(1 << 1)
+
+#define ADM6996I_REG_CI0_PC_MASK	0xFFF0
+#define ADM6996I_REG_CI0_VN_MASK	0xF
+#define ADM6996I_REG_CI1_PC_MASK	0xF
+
+
+static inline int adm6996i_mii_read(struct mii_dev *bus, u16 reg)
+{
+	int ret;
+
+	ret = bus->read(bus, (reg >> 5) & 0x1f, MDIO_DEVAD_NONE, reg & 0x1f);
+
+	return ret;
+}
+
+static inline int adm6996i_mii_write(struct mii_dev *bus, u16 reg, u16 val)
+{
+	int ret;
+
+	ret = bus->write(bus, (reg >> 5) & 0x1f, MDIO_DEVAD_NONE,
+		reg & 0x1f, val);
+
+	return ret;
+}
+
+static int adm6996i_probe(struct switch_device *dev)
+{
+	struct mii_dev *bus = dev->bus;
+	u16 ci0, ci1;
+
+	ci0 = adm6996i_mii_read(bus, ADM6996I_REG_CI0);
+	ci1 = adm6996i_mii_read(bus, ADM6996I_REG_CI1);
+
+	ci0 &= ADM6996I_REG_CI0_PC_MASK;
+	ci1 &= ADM6996I_REG_CI1_PC_MASK;
+
+	if (ci0 == ADM6996I_CHIPID0 && ci1 == ADM6996I_CHIPID1)
+		return 0;
+
+	return 1;
+}
+
+static void adm6996i_setup(struct switch_device *dev)
+{
+	struct mii_dev *bus = dev->bus;
+	u16 val;
+
+	/*
+	 * Write default values (Port enable, 100 Mbps, Full Duplex,
+	 * Auto negotiation, Flow control) and enable crossover auto-detect
+	 */
+	val = ADM6996I_REG_PXBC_DEFAULT | ADM6996I_REG_PXBC_CROSS_EE;
+	adm6996i_mii_write(bus, ADM6996I_REG_P0BC, val);
+	adm6996i_mii_write(bus, ADM6996I_REG_P1BC, val);
+	adm6996i_mii_write(bus, ADM6996I_REG_P2BC, val);
+	adm6996i_mii_write(bus, ADM6996I_REG_P3BC, val);
+	adm6996i_mii_write(bus, ADM6996I_REG_P4BC, val);
+	adm6996i_mii_write(bus, ADM6996I_REG_P5BC, val);
+
+	val = ADM6996I_REG_SC4_DEFAULT | ADM6996I_REG_SC4_LED_ENABLE;
+	adm6996i_mii_write(bus, ADM6996I_REG_SC4, val);
+}
+
+static struct switch_driver adm6996i_drv = {
+	.name = "adm6996i",
+};
+
+void switch_adm6996i_init(void)
+{
+	/* For archs with manual relocation */
+	adm6996i_drv.probe = adm6996i_probe;
+	adm6996i_drv.setup = adm6996i_setup;
+
+	switch_driver_register(&adm6996i_drv);
+}
--- a/drivers/net/switch/switch.c
+++ b/drivers/net/switch/switch.c
@@ -21,6 +21,9 @@ void switch_init(void)
 #if defined(CONFIG_SWITCH_PSB697X)
 	switch_psb697x_init();
 #endif
+#if defined(CONFIG_SWITCH_ADM6996I)
+	switch_adm6996i_init();
+#endif
 
 	board_switch_init();
 }
--- a/include/switch.h
+++ b/include/switch.h
@@ -91,6 +91,7 @@ static inline void switch_setup(struct s
 
 /* Init functions for supported Switch drivers */
 extern void switch_psb697x_init(void);
+extern void switch_adm6996i_init(void);
 
 #endif /* __SWITCH_H */