uboot-lantiq: update to v2013.10
[openwrt/svn-archive/archive.git] / package / boot / uboot-lantiq / patches / 0012-net-switchlib-add-driver-for-Atheros-AR8216.patch
1 From 1a1d61a2faf0390033a3766559ce0e758e15894e Mon Sep 17 00:00:00 2001
2 From: Luka Perkov <openwrt@lukaperkov.net>
3 Date: Wed, 29 Aug 2012 22:08:16 +0200
4 Subject: net: switchlib: add driver for Atheros AR8216
5
6 Signed-off-by: Luka Perkov <openwrt@lukaperkov.net>
7 Signed-off-by: Daniel Schwierzeck <daniel.schwierzeck@gmail.com>
8
9 diff --git a/drivers/net/switch/Makefile b/drivers/net/switch/Makefile
10 index 6b7eeb9..7400897 100644
11 --- a/drivers/net/switch/Makefile
12 +++ b/drivers/net/switch/Makefile
13 @@ -12,6 +12,7 @@ LIB := $(obj)libswitch.o
14 COBJS-$(CONFIG_SWITCH_MULTI) += switch.o
15 COBJS-$(CONFIG_SWITCH_PSB697X) += psb697x.o
16 COBJS-$(CONFIG_SWITCH_ADM6996I) += adm6996i.o
17 +COBJS-$(CONFIG_SWITCH_AR8216) += ar8216.o
18
19 COBJS := $(COBJS-y)
20 SRCS := $(COBJS:.o=.c)
21 diff --git a/drivers/net/switch/ar8216.c b/drivers/net/switch/ar8216.c
22 new file mode 100644
23 index 0000000..f1348f0
24 --- /dev/null
25 +++ b/drivers/net/switch/ar8216.c
26 @@ -0,0 +1,114 @@
27 +/*
28 + * Copyright (C) 2012 Luka Perkov <luka@openwrt.org>
29 + *
30 + * SPDX-License-Identifier: GPL-2.0+
31 + */
32 +
33 +#include <common.h>
34 +#include <malloc.h>
35 +#include <miiphy.h>
36 +#include <switch.h>
37 +#include <netdev.h>
38 +
39 +#define BITS(_s, _n) (((1UL << (_n)) - 1) << _s)
40 +
41 +#define AR8216_REG_CTRL 0x0000
42 +#define AR8216_CTRL_REVISION BITS(0, 8)
43 +#define AR8216_CTRL_VERSION BITS(8, 8)
44 +
45 +#define AR8216_PROBE_RETRIES 10
46 +
47 +static void split_addr(u32 regaddr, u16 *r1, u16 *r2, u16 *page)
48 +{
49 + regaddr >>= 1;
50 + *r1 = regaddr & 0x1e;
51 +
52 + regaddr >>= 5;
53 + *r2 = regaddr & 0x7;
54 +
55 + regaddr >>= 3;
56 + *page = regaddr & 0x1ff;
57 +}
58 +
59 +static int ar8216_mii_read(struct mii_dev *bus, u32 reg)
60 +{
61 + u16 r1, r2, page;
62 + u16 lo, hi;
63 +
64 + split_addr(reg, &r1, &r2, &page);
65 +
66 + bus->write(bus, 0x18, MDIO_DEVAD_NONE, 0, page);
67 + __udelay(1000);
68 +
69 + lo = bus->read(bus, 0x10 | r2, MDIO_DEVAD_NONE, r1);
70 + hi = bus->read(bus, 0x10 | r2, MDIO_DEVAD_NONE, r1 + 1);
71 +
72 + return (hi << 16) | lo;
73 +}
74 +
75 +static void ar8216_mii_write(struct mii_dev *bus, u16 reg, u32 val)
76 +{
77 + u16 r1, r2, r3;
78 + u16 lo, hi;
79 +
80 + split_addr((u32) reg, &r1, &r2, &r3);
81 +
82 + bus->write(bus, 0x18, MDIO_DEVAD_NONE, 0, r3);
83 + __udelay(1000);
84 +
85 + lo = val & 0xffff;
86 + hi = (u16) (val >> 16);
87 + bus->write(bus, 0x10 | r2, MDIO_DEVAD_NONE, r1 + 1, hi);
88 + bus->write(bus, 0x10 | r2, MDIO_DEVAD_NONE, r1, lo);
89 +}
90 +
91 +static int ar8216_probe(struct switch_device *dev)
92 +{
93 + struct mii_dev *bus = dev->bus;
94 + u32 val;
95 + u16 id;
96 +
97 + val = ar8216_mii_read(bus, AR8216_REG_CTRL);
98 + if (val == ~0)
99 + return 1;
100 +
101 + id = val & (AR8216_CTRL_REVISION | AR8216_CTRL_VERSION);
102 +
103 + switch (id) {
104 + case 0x0101:
105 + return 0;
106 + default:
107 + return 1;
108 + }
109 +}
110 +
111 +static void ar8216_setup(struct switch_device *dev)
112 +{
113 + struct mii_dev *bus = dev->bus;
114 +
115 + ar8216_mii_write(bus, 0x200, 0x200);
116 + ar8216_mii_write(bus, 0x300, 0x200);
117 + ar8216_mii_write(bus, 0x400, 0x200);
118 + ar8216_mii_write(bus, 0x500, 0x200);
119 + ar8216_mii_write(bus, 0x600, 0x7d);
120 + ar8216_mii_write(bus, 0x38, 0xc000050e);
121 + ar8216_mii_write(bus, 0x104, 0x4004);
122 + ar8216_mii_write(bus, 0x60, 0xffffffff);
123 + ar8216_mii_write(bus, 0x64, 0xaaaaaaaa);
124 + ar8216_mii_write(bus, 0x68, 0x55555555);
125 + ar8216_mii_write(bus, 0x6c, 0x0);
126 + ar8216_mii_write(bus, 0x70, 0x41af);
127 +}
128 +
129 +static struct switch_driver ar8216_drv = {
130 + .name = "ar8216",
131 +};
132 +
133 +void switch_ar8216_init(void)
134 +{
135 + /* for archs with manual relocation */
136 + ar8216_drv.probe = ar8216_probe;
137 + ar8216_drv.setup = ar8216_setup;
138 +
139 + switch_driver_register(&ar8216_drv);
140 +}
141 diff --git a/drivers/net/switch/switch.c b/drivers/net/switch/switch.c
142 index ea3fe9c..3e34a7f 100644
143 --- a/drivers/net/switch/switch.c
144 +++ b/drivers/net/switch/switch.c
145 @@ -23,6 +23,9 @@ void switch_init(void)
146 #if defined(CONFIG_SWITCH_ADM6996I)
147 switch_adm6996i_init();
148 #endif
149 +#if defined(CONFIG_SWITCH_AR8216)
150 + switch_ar8216_init();
151 +#endif
152
153 board_switch_init();
154 }
155 diff --git a/include/switch.h b/include/switch.h
156 index 4b46df0..ae7b123 100644
157 --- a/include/switch.h
158 +++ b/include/switch.h
159 @@ -99,6 +99,7 @@ static inline void switch_setup(struct switch_device *dev)
160 /* Init functions for supported Switch drivers */
161 extern void switch_psb697x_init(void);
162 extern void switch_adm6996i_init(void);
163 +extern void switch_ar8216_init(void);
164
165 #endif /* __SWITCH_H */
166
167 --
168 1.8.3.2
169