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
6 Signed-off-by: Daniel Schwierzeck <daniel.schwierzeck@gmail.com>
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
14 COBJS-$(CONFIG_SWITCH_MULTI) += switch.o
15 COBJS-$(CONFIG_SWITCH_PSB697X) += psb697x.o
16 +COBJS-$(CONFIG_SWITCH_ADM6996I) += adm6996i.o
19 SRCS := $(COBJS:.o=.c)
20 diff --git a/drivers/net/switch/adm6996i.c b/drivers/net/switch/adm6996i.c
22 index 0000000..46fcdc9
24 +++ b/drivers/net/switch/adm6996i.c
27 + * Copyright (C) 2011-2013 Daniel Schwierzeck, daniel.schwierzeck@gmail.com
29 + * SPDX-License-Identifier: GPL-2.0+
37 +#define ADM6996I_CHIPID0 0x1020
38 +#define ADM6996I_CHIPID1 0x0007
39 +#define ADM6996I_PORT_COUNT 6
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 */
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 */
55 +#define ADM6996I_REG_SC4 0x012 /* System Control 4 */
57 +#define ADM6996I_REG_CI0 0xA0 /* Chip Identifier 0 */
58 +#define ADM6996I_REG_CI1 0xA1 /* Chip Identifier 1 */
60 +#define ADM6996I_REG_PXBC_DEFAULT 0x040F
61 +#define ADM6996I_REG_PXBC_CROSS_EE (1 << 15)
62 +#define ADM6996I_REG_PXBC_PD (1 << 5)
64 +#define ADM6996I_REG_SC4_DEFAULT 0x3600
65 +#define ADM6996I_REG_SC4_LED_ENABLE (1 << 1)
67 +#define ADM6996I_REG_CI0_PC_MASK 0xFFF0
68 +#define ADM6996I_REG_CI0_VN_MASK 0xF
69 +#define ADM6996I_REG_CI1_PC_MASK 0xF
72 +static inline int adm6996i_mii_read(struct mii_dev *bus, u16 reg)
76 + ret = bus->read(bus, (reg >> 5) & 0x1f, MDIO_DEVAD_NONE, reg & 0x1f);
81 +static inline int adm6996i_mii_write(struct mii_dev *bus, u16 reg, u16 val)
85 + ret = bus->write(bus, (reg >> 5) & 0x1f, MDIO_DEVAD_NONE,
91 +static int adm6996i_probe(struct switch_device *dev)
93 + struct mii_dev *bus = dev->bus;
96 + ci0 = adm6996i_mii_read(bus, ADM6996I_REG_CI0);
97 + ci1 = adm6996i_mii_read(bus, ADM6996I_REG_CI1);
99 + ci0 &= ADM6996I_REG_CI0_PC_MASK;
100 + ci1 &= ADM6996I_REG_CI1_PC_MASK;
102 + if (ci0 == ADM6996I_CHIPID0 && ci1 == ADM6996I_CHIPID1)
108 +static void adm6996i_setup(struct switch_device *dev)
110 + struct mii_dev *bus = dev->bus;
114 + * Write default values (Port enable, 100 Mbps, Full Duplex,
115 + * Auto negotiation, Flow control) and enable crossover auto-detect
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);
125 + val = ADM6996I_REG_SC4_DEFAULT | ADM6996I_REG_SC4_LED_ENABLE;
126 + adm6996i_mii_write(bus, ADM6996I_REG_SC4, val);
129 +static struct switch_driver adm6996i_drv = {
130 + .name = "adm6996i",
133 +void switch_adm6996i_init(void)
135 + /* For archs with manual relocation */
136 + adm6996i_drv.probe = adm6996i_probe;
137 + adm6996i_drv.setup = adm6996i_setup;
139 + switch_driver_register(&adm6996i_drv);
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();
149 +#if defined(CONFIG_SWITCH_ADM6996I)
150 + switch_adm6996i_init();
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)
161 /* Init functions for supported Switch drivers */
162 extern void switch_psb697x_init(void);
163 +extern void switch_adm6996i_init(void);
165 #endif /* __SWITCH_H */