uboot-lantiq: update to v2013.10
[openwrt/svn-archive/archive.git] / package / boot / uboot-lantiq / patches / 0011-net-switchlib-add-driver-for-Lantiq-ADM6996I-switch-.patch
1 From c291443dc97dadcf0c6afd04688a7d9f79a221b5 Mon Sep 17 00:00:00 2001
2 From: Daniel Schwierzeck <daniel.schwierzeck@gmail.com>
3 Date: Wed, 29 Aug 2012 22:08:16 +0200
4 Subject: net: switchlib: add driver for Lantiq ADM6996I switch family
5
6 Signed-off-by: Daniel Schwierzeck <daniel.schwierzeck@gmail.com>
7
8 diff --git a/drivers/net/switch/Makefile b/drivers/net/switch/Makefile
9 index a426774..6b7eeb9 100644
10 --- a/drivers/net/switch/Makefile
11 +++ b/drivers/net/switch/Makefile
12 @@ -11,6 +11,7 @@ LIB := $(obj)libswitch.o
13
14 COBJS-$(CONFIG_SWITCH_MULTI) += switch.o
15 COBJS-$(CONFIG_SWITCH_PSB697X) += psb697x.o
16 +COBJS-$(CONFIG_SWITCH_ADM6996I) += adm6996i.o
17
18 COBJS := $(COBJS-y)
19 SRCS := $(COBJS:.o=.c)
20 diff --git a/drivers/net/switch/adm6996i.c b/drivers/net/switch/adm6996i.c
21 new file mode 100644
22 index 0000000..46fcdc9
23 --- /dev/null
24 +++ b/drivers/net/switch/adm6996i.c
25 @@ -0,0 +1,115 @@
26 +/*
27 + * Copyright (C) 2011-2013 Daniel Schwierzeck, daniel.schwierzeck@gmail.com
28 + *
29 + * SPDX-License-Identifier: GPL-2.0+
30 + */
31 +
32 +#include <common.h>
33 +#include <malloc.h>
34 +#include <switch.h>
35 +#include <miiphy.h>
36 +
37 +#define ADM6996I_CHIPID0 0x1020
38 +#define ADM6996I_CHIPID1 0x0007
39 +#define ADM6996I_PORT_COUNT 6
40 +
41 +#define ADM6996I_REG_P0BC 0x001 /* P0 Basic Control */
42 +#define ADM6996I_REG_P1BC 0x003 /* P1 Basic Control */
43 +#define ADM6996I_REG_P2BC 0x005 /* P2 Basic Control */
44 +#define ADM6996I_REG_P3BC 0x007 /* P3 Basic Control */
45 +#define ADM6996I_REG_P4BC 0x008 /* P4 Basic Control */
46 +#define ADM6996I_REG_P5BC 0x009 /* P5 Basic Control */
47 +
48 +#define ADM6996I_REG_P0EC 0x002 /* P0 Extended Control */
49 +#define ADM6996I_REG_P1EC 0x002 /* P1 Extended Control */
50 +#define ADM6996I_REG_P2EC 0x004 /* P2 Extended Control */
51 +#define ADM6996I_REG_P3EC 0x004 /* P3 Extended Control */
52 +#define ADM6996I_REG_P4EC 0x006 /* P4 Extended Control */
53 +#define ADM6996I_REG_P5EC 0x006 /* P5 Extended Control */
54 +
55 +#define ADM6996I_REG_SC4 0x012 /* System Control 4 */
56 +
57 +#define ADM6996I_REG_CI0 0xA0 /* Chip Identifier 0 */
58 +#define ADM6996I_REG_CI1 0xA1 /* Chip Identifier 1 */
59 +
60 +#define ADM6996I_REG_PXBC_DEFAULT 0x040F
61 +#define ADM6996I_REG_PXBC_CROSS_EE (1 << 15)
62 +#define ADM6996I_REG_PXBC_PD (1 << 5)
63 +
64 +#define ADM6996I_REG_SC4_DEFAULT 0x3600
65 +#define ADM6996I_REG_SC4_LED_ENABLE (1 << 1)
66 +
67 +#define ADM6996I_REG_CI0_PC_MASK 0xFFF0
68 +#define ADM6996I_REG_CI0_VN_MASK 0xF
69 +#define ADM6996I_REG_CI1_PC_MASK 0xF
70 +
71 +
72 +static inline int adm6996i_mii_read(struct mii_dev *bus, u16 reg)
73 +{
74 + int ret;
75 +
76 + ret = bus->read(bus, (reg >> 5) & 0x1f, MDIO_DEVAD_NONE, reg & 0x1f);
77 +
78 + return ret;
79 +}
80 +
81 +static inline int adm6996i_mii_write(struct mii_dev *bus, u16 reg, u16 val)
82 +{
83 + int ret;
84 +
85 + ret = bus->write(bus, (reg >> 5) & 0x1f, MDIO_DEVAD_NONE,
86 + reg & 0x1f, val);
87 +
88 + return ret;
89 +}
90 +
91 +static int adm6996i_probe(struct switch_device *dev)
92 +{
93 + struct mii_dev *bus = dev->bus;
94 + u16 ci0, ci1;
95 +
96 + ci0 = adm6996i_mii_read(bus, ADM6996I_REG_CI0);
97 + ci1 = adm6996i_mii_read(bus, ADM6996I_REG_CI1);
98 +
99 + ci0 &= ADM6996I_REG_CI0_PC_MASK;
100 + ci1 &= ADM6996I_REG_CI1_PC_MASK;
101 +
102 + if (ci0 == ADM6996I_CHIPID0 && ci1 == ADM6996I_CHIPID1)
103 + return 0;
104 +
105 + return 1;
106 +}
107 +
108 +static void adm6996i_setup(struct switch_device *dev)
109 +{
110 + struct mii_dev *bus = dev->bus;
111 + u16 val;
112 +
113 + /*
114 + * Write default values (Port enable, 100 Mbps, Full Duplex,
115 + * Auto negotiation, Flow control) and enable crossover auto-detect
116 + */
117 + val = ADM6996I_REG_PXBC_DEFAULT | ADM6996I_REG_PXBC_CROSS_EE;
118 + adm6996i_mii_write(bus, ADM6996I_REG_P0BC, val);
119 + adm6996i_mii_write(bus, ADM6996I_REG_P1BC, val);
120 + adm6996i_mii_write(bus, ADM6996I_REG_P2BC, val);
121 + adm6996i_mii_write(bus, ADM6996I_REG_P3BC, val);
122 + adm6996i_mii_write(bus, ADM6996I_REG_P4BC, val);
123 + adm6996i_mii_write(bus, ADM6996I_REG_P5BC, val);
124 +
125 + val = ADM6996I_REG_SC4_DEFAULT | ADM6996I_REG_SC4_LED_ENABLE;
126 + adm6996i_mii_write(bus, ADM6996I_REG_SC4, val);
127 +}
128 +
129 +static struct switch_driver adm6996i_drv = {
130 + .name = "adm6996i",
131 +};
132 +
133 +void switch_adm6996i_init(void)
134 +{
135 + /* For archs with manual relocation */
136 + adm6996i_drv.probe = adm6996i_probe;
137 + adm6996i_drv.setup = adm6996i_setup;
138 +
139 + switch_driver_register(&adm6996i_drv);
140 +}
141 diff --git a/drivers/net/switch/switch.c b/drivers/net/switch/switch.c
142 index 3d02610..ea3fe9c 100644
143 --- a/drivers/net/switch/switch.c
144 +++ b/drivers/net/switch/switch.c
145 @@ -20,6 +20,9 @@ void switch_init(void)
146 #if defined(CONFIG_SWITCH_PSB697X)
147 switch_psb697x_init();
148 #endif
149 +#if defined(CONFIG_SWITCH_ADM6996I)
150 + switch_adm6996i_init();
151 +#endif
152
153 board_switch_init();
154 }
155 diff --git a/include/switch.h b/include/switch.h
156 index fd3cdbd..4b46df0 100644
157 --- a/include/switch.h
158 +++ b/include/switch.h
159 @@ -98,6 +98,7 @@ static inline void switch_setup(struct switch_device *dev)
160
161 /* Init functions for supported Switch drivers */
162 extern void switch_psb697x_init(void);
163 +extern void switch_adm6996i_init(void);
164
165 #endif /* __SWITCH_H */
166
167 --
168 1.8.3.2
169