uboot-lantiq: update to v2013.10
[openwrt/openwrt.git] / package / boot / uboot-lantiq / patches / 0010-net-switchlib-add-driver-for-Lantiq-PSB697X-switch-f.patch
1 From e2c59cedebf72e4a002134a2932f722b508a5448 Mon Sep 17 00:00:00 2001
2 From: Daniel Schwierzeck <daniel.schwierzeck@gmail.com>
3 Date: Wed, 29 Aug 2012 22:08:15 +0200
4 Subject: net: switchlib: add driver for Lantiq PSB697X 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 31719d8..a426774 100644
10 --- a/drivers/net/switch/Makefile
11 +++ b/drivers/net/switch/Makefile
12 @@ -10,6 +10,7 @@ include $(TOPDIR)/config.mk
13 LIB := $(obj)libswitch.o
14
15 COBJS-$(CONFIG_SWITCH_MULTI) += switch.o
16 +COBJS-$(CONFIG_SWITCH_PSB697X) += psb697x.o
17
18 COBJS := $(COBJS-y)
19 SRCS := $(COBJS:.o=.c)
20 diff --git a/drivers/net/switch/psb697x.c b/drivers/net/switch/psb697x.c
21 new file mode 100644
22 index 0000000..cb6c391
23 --- /dev/null
24 +++ b/drivers/net/switch/psb697x.c
25 @@ -0,0 +1,118 @@
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 PSB697X_CHIPID1 0x2599
38 +#define PSB697X_PORT_COUNT 7
39 +
40 +#define PSB697X_PORT_BASE(p) (p * 0x20)
41 +#define PSB697X_REG_PS(p) (PSB697X_PORT_BASE(p) + 0x00)
42 +#define PSB697X_REG_PBC(p) (PSB697X_PORT_BASE(p) + 0x01)
43 +#define PSB697X_REG_PEC(p) (PSB697X_PORT_BASE(p) + 0x02)
44 +
45 +#define PSB697X_REG_SGC1 0x0E0 /* Switch Global Control Register 1 */
46 +#define PSB697X_REG_SGC2 0x0E1 /* Switch Global Control Register 2 */
47 +#define PSB697X_REG_CMH 0x0E2 /* CPU Port & Mirror Control */
48 +#define PSB697X_REG_MIICR 0x0F5 /* MII Port Control */
49 +#define PSB697X_REG_CI0 0x100 /* Chip Identifier 0 */
50 +#define PSB697X_REG_CI1 0x101 /* Chip Identifier 1 */
51 +#define PSB697X_REG_MIIAC 0x120 /* MII Indirect Access Control */
52 +#define PSB697X_REG_MIIWD 0x121 /* MII Indirect Write Data */
53 +#define PSB697X_REG_MIIRD 0x122 /* MII Indirect Read Data */
54 +
55 +#define PSB697X_REG_PORT_FLP (1 << 2) /* Force link up */
56 +#define PSB697X_REG_PORT_FLD (1 << 1) /* Force link down */
57 +
58 +#define PSB697X_REG_SGC2_SE (1 << 15) /* Switch enable */
59 +
60 +#define PSB697X_REG_CMH_CPN_MASK 0x7
61 +#define PSB697X_REG_CMH_CPN_SHIFT 5
62 +
63 +
64 +static inline int psb697x_mii_read(struct mii_dev *bus, u16 reg)
65 +{
66 + int ret;
67 +
68 + ret = bus->read(bus, (reg >> 5) & 0x1f, MDIO_DEVAD_NONE, reg & 0x1f);
69 +
70 + return ret;
71 +}
72 +
73 +static inline int psb697x_mii_write(struct mii_dev *bus, u16 reg, u16 val)
74 +{
75 + int ret;
76 +
77 + ret = bus->write(bus, (reg >> 5) & 0x1f, MDIO_DEVAD_NONE,
78 + reg & 0x1f, val);
79 +
80 + return ret;
81 +}
82 +
83 +static int psb697x_probe(struct switch_device *dev)
84 +{
85 + struct mii_dev *bus = dev->bus;
86 + int ci1;
87 +
88 + ci1 = psb697x_mii_read(bus, PSB697X_REG_CI1);
89 +
90 + if (ci1 == PSB697X_CHIPID1)
91 + return 0;
92 +
93 + return 1;
94 +}
95 +
96 +static void psb697x_setup(struct switch_device *dev)
97 +{
98 + struct mii_dev *bus = dev->bus;
99 + int i, state;
100 +
101 + /* Enable switch */
102 + psb697x_mii_write(bus, PSB697X_REG_SGC2, PSB697X_REG_SGC2_SE);
103 +
104 + /*
105 + * Force 100 Mbps as default value for CPU ports 5 and 6 to get
106 + * full speed.
107 + */
108 + psb697x_mii_write(bus, PSB697X_REG_MIICR, 0x0773);
109 +
110 + for (i = 0; i < PSB697X_PORT_COUNT; i++) {
111 + state = dev->port_mask & (1 << i);
112 +
113 + /*
114 + * Software workaround from Errata Sheet:
115 + * Force link down and reset internal PHY, keep that state
116 + * for all unconnected ports and disable force link down
117 + * for all connected ports
118 + */
119 + psb697x_mii_write(bus, PSB697X_REG_PBC(i),
120 + PSB697X_REG_PORT_FLD);
121 +
122 + if (i == dev->cpu_port)
123 + /* Force link up for CPU port */
124 + psb697x_mii_write(bus, PSB697X_REG_PBC(i),
125 + PSB697X_REG_PORT_FLP);
126 + else if (state)
127 + /* Disable force link down for active LAN ports */
128 + psb697x_mii_write(bus, PSB697X_REG_PBC(i), 0);
129 + }
130 +}
131 +
132 +static struct switch_driver psb697x_drv = {
133 + .name = "psb697x",
134 +};
135 +
136 +void switch_psb697x_init(void)
137 +{
138 + /* For archs with manual relocation */
139 + psb697x_drv.probe = psb697x_probe;
140 + psb697x_drv.setup = psb697x_setup;
141 +
142 + switch_driver_register(&psb697x_drv);
143 +}
144 diff --git a/drivers/net/switch/switch.c b/drivers/net/switch/switch.c
145 index 0e1d6b7..3d02610 100644
146 --- a/drivers/net/switch/switch.c
147 +++ b/drivers/net/switch/switch.c
148 @@ -17,6 +17,10 @@ void switch_init(void)
149 INIT_LIST_HEAD(&switch_drivers);
150 INIT_LIST_HEAD(&switch_devices);
151
152 +#if defined(CONFIG_SWITCH_PSB697X)
153 + switch_psb697x_init();
154 +#endif
155 +
156 board_switch_init();
157 }
158
159 diff --git a/include/switch.h b/include/switch.h
160 index 4a7ae63..fd3cdbd 100644
161 --- a/include/switch.h
162 +++ b/include/switch.h
163 @@ -97,6 +97,7 @@ static inline void switch_setup(struct switch_device *dev)
164 }
165
166 /* Init functions for supported Switch drivers */
167 +extern void switch_psb697x_init(void);
168
169 #endif /* __SWITCH_H */
170
171 --
172 1.8.3.2
173