generic: rtl8366: get rid of private rtl8366{s,rb} structs
[openwrt.git] / target / linux / generic / files / drivers / net / phy / rtl8366rb.c
1 /*
2 * Platform driver for the Realtek RTL8366S ethernet switch
3 *
4 * Copyright (C) 2009-2010 Gabor Juhos <juhosg@openwrt.org>
5 * Copyright (C) 2010 Antti Seppälä <a.seppala@gmail.com>
6 *
7 * This program is free software; you can redistribute it and/or modify it
8 * under the terms of the GNU General Public License version 2 as published
9 * by the Free Software Foundation.
10 */
11
12 #include <linux/kernel.h>
13 #include <linux/module.h>
14 #include <linux/init.h>
15 #include <linux/platform_device.h>
16 #include <linux/delay.h>
17 #include <linux/skbuff.h>
18 #include <linux/rtl8366rb.h>
19
20 #include "rtl8366_smi.h"
21
22 #define RTL8366RB_DRIVER_DESC "Realtek RTL8366RB ethernet switch driver"
23 #define RTL8366RB_DRIVER_VER "0.2.2"
24
25 #define RTL8366RB_PHY_NO_MAX 4
26 #define RTL8366RB_PHY_PAGE_MAX 7
27 #define RTL8366RB_PHY_ADDR_MAX 31
28
29 /* Switch Global Configuration register */
30 #define RTL8366RB_SGCR 0x0000
31 #define RTL8366RB_SGCR_EN_BC_STORM_CTRL BIT(0)
32 #define RTL8366RB_SGCR_MAX_LENGTH(_x) (_x << 4)
33 #define RTL8366RB_SGCR_MAX_LENGTH_MASK RTL8366RB_SGCR_MAX_LENGTH(0x3)
34 #define RTL8366RB_SGCR_MAX_LENGTH_1522 RTL8366RB_SGCR_MAX_LENGTH(0x0)
35 #define RTL8366RB_SGCR_MAX_LENGTH_1536 RTL8366RB_SGCR_MAX_LENGTH(0x1)
36 #define RTL8366RB_SGCR_MAX_LENGTH_1552 RTL8366RB_SGCR_MAX_LENGTH(0x2)
37 #define RTL8366RB_SGCR_MAX_LENGTH_9216 RTL8366RB_SGCR_MAX_LENGTH(0x3)
38 #define RTL8366RB_SGCR_EN_VLAN BIT(13)
39 #define RTL8366RB_SGCR_EN_VLAN_4KTB BIT(14)
40
41 /* Port Enable Control register */
42 #define RTL8366RB_PECR 0x0001
43
44 /* Switch Security Control registers */
45 #define RTL8366RB_SSCR0 0x0002
46 #define RTL8366RB_SSCR1 0x0003
47 #define RTL8366RB_SSCR2 0x0004
48 #define RTL8366RB_SSCR2_DROP_UNKNOWN_DA BIT(0)
49
50 #define RTL8366RB_RESET_CTRL_REG 0x0100
51 #define RTL8366RB_CHIP_CTRL_RESET_HW 1
52 #define RTL8366RB_CHIP_CTRL_RESET_SW (1 << 1)
53
54 #define RTL8366RB_CHIP_VERSION_CTRL_REG 0x050A
55 #define RTL8366RB_CHIP_VERSION_MASK 0xf
56 #define RTL8366RB_CHIP_ID_REG 0x0509
57 #define RTL8366RB_CHIP_ID_8366 0x5937
58
59 /* PHY registers control */
60 #define RTL8366RB_PHY_ACCESS_CTRL_REG 0x8000
61 #define RTL8366RB_PHY_ACCESS_DATA_REG 0x8002
62
63 #define RTL8366RB_PHY_CTRL_READ 1
64 #define RTL8366RB_PHY_CTRL_WRITE 0
65
66 #define RTL8366RB_PHY_REG_MASK 0x1f
67 #define RTL8366RB_PHY_PAGE_OFFSET 5
68 #define RTL8366RB_PHY_PAGE_MASK (0xf << 5)
69 #define RTL8366RB_PHY_NO_OFFSET 9
70 #define RTL8366RB_PHY_NO_MASK (0x1f << 9)
71
72 #define RTL8366RB_VLAN_INGRESS_CTRL2_REG 0x037f
73
74 /* LED control registers */
75 #define RTL8366RB_LED_BLINKRATE_REG 0x0430
76 #define RTL8366RB_LED_BLINKRATE_BIT 0
77 #define RTL8366RB_LED_BLINKRATE_MASK 0x0007
78
79 #define RTL8366RB_LED_CTRL_REG 0x0431
80 #define RTL8366RB_LED_0_1_CTRL_REG 0x0432
81 #define RTL8366RB_LED_2_3_CTRL_REG 0x0433
82
83 #define RTL8366RB_MIB_COUNT 33
84 #define RTL8366RB_GLOBAL_MIB_COUNT 1
85 #define RTL8366RB_MIB_COUNTER_PORT_OFFSET 0x0050
86 #define RTL8366RB_MIB_COUNTER_BASE 0x1000
87 #define RTL8366RB_MIB_CTRL_REG 0x13F0
88 #define RTL8366RB_MIB_CTRL_USER_MASK 0x0FFC
89 #define RTL8366RB_MIB_CTRL_BUSY_MASK BIT(0)
90 #define RTL8366RB_MIB_CTRL_RESET_MASK BIT(1)
91 #define RTL8366RB_MIB_CTRL_PORT_RESET(_p) BIT(2 + (_p))
92 #define RTL8366RB_MIB_CTRL_GLOBAL_RESET BIT(11)
93
94 #define RTL8366RB_PORT_VLAN_CTRL_BASE 0x0063
95 #define RTL8366RB_PORT_VLAN_CTRL_REG(_p) \
96 (RTL8366RB_PORT_VLAN_CTRL_BASE + (_p) / 4)
97 #define RTL8366RB_PORT_VLAN_CTRL_MASK 0xf
98 #define RTL8366RB_PORT_VLAN_CTRL_SHIFT(_p) (4 * ((_p) % 4))
99
100
101 #define RTL8366RB_VLAN_TABLE_READ_BASE 0x018C
102 #define RTL8366RB_VLAN_TABLE_WRITE_BASE 0x0185
103
104
105 #define RTL8366RB_TABLE_ACCESS_CTRL_REG 0x0180
106 #define RTL8366RB_TABLE_VLAN_READ_CTRL 0x0E01
107 #define RTL8366RB_TABLE_VLAN_WRITE_CTRL 0x0F01
108
109 #define RTL8366RB_VLAN_MC_BASE(_x) (0x0020 + (_x) * 3)
110
111
112 #define RTL8366RB_PORT_LINK_STATUS_BASE 0x0014
113 #define RTL8366RB_PORT_STATUS_SPEED_MASK 0x0003
114 #define RTL8366RB_PORT_STATUS_DUPLEX_MASK 0x0004
115 #define RTL8366RB_PORT_STATUS_LINK_MASK 0x0010
116 #define RTL8366RB_PORT_STATUS_TXPAUSE_MASK 0x0020
117 #define RTL8366RB_PORT_STATUS_RXPAUSE_MASK 0x0040
118 #define RTL8366RB_PORT_STATUS_AN_MASK 0x0080
119
120
121 #define RTL8366RB_PORT_NUM_CPU 5
122 #define RTL8366RB_NUM_PORTS 6
123 #define RTL8366RB_NUM_VLANS 16
124 #define RTL8366RB_NUM_LEDGROUPS 4
125 #define RTL8366RB_NUM_VIDS 4096
126 #define RTL8366RB_PRIORITYMAX 7
127 #define RTL8366RB_FIDMAX 7
128
129
130 #define RTL8366RB_PORT_1 (1 << 0) /* In userspace port 0 */
131 #define RTL8366RB_PORT_2 (1 << 1) /* In userspace port 1 */
132 #define RTL8366RB_PORT_3 (1 << 2) /* In userspace port 2 */
133 #define RTL8366RB_PORT_4 (1 << 3) /* In userspace port 3 */
134 #define RTL8366RB_PORT_5 (1 << 4) /* In userspace port 4 */
135
136 #define RTL8366RB_PORT_CPU (1 << 5) /* CPU port */
137
138 #define RTL8366RB_PORT_ALL (RTL8366RB_PORT_1 | \
139 RTL8366RB_PORT_2 | \
140 RTL8366RB_PORT_3 | \
141 RTL8366RB_PORT_4 | \
142 RTL8366RB_PORT_5 | \
143 RTL8366RB_PORT_CPU)
144
145 #define RTL8366RB_PORT_ALL_BUT_CPU (RTL8366RB_PORT_1 | \
146 RTL8366RB_PORT_2 | \
147 RTL8366RB_PORT_3 | \
148 RTL8366RB_PORT_4 | \
149 RTL8366RB_PORT_5)
150
151 #define RTL8366RB_PORT_ALL_EXTERNAL (RTL8366RB_PORT_1 | \
152 RTL8366RB_PORT_2 | \
153 RTL8366RB_PORT_3 | \
154 RTL8366RB_PORT_4)
155
156 #define RTL8366RB_PORT_ALL_INTERNAL RTL8366RB_PORT_CPU
157
158 #define RTL8366RB_VLAN_VID_MASK 0xfff
159 #define RTL8366RB_VLAN_PRIORITY_SHIFT 12
160 #define RTL8366RB_VLAN_PRIORITY_MASK 0x7
161 #define RTL8366RB_VLAN_UNTAG_SHIFT 8
162 #define RTL8366RB_VLAN_UNTAG_MASK 0xff
163 #define RTL8366RB_VLAN_MEMBER_MASK 0xff
164 #define RTL8366RB_VLAN_FID_MASK 0x7
165
166 static struct rtl8366_mib_counter rtl8366rb_mib_counters[] = {
167 { 0, 0, 4, "IfInOctets" },
168 { 0, 4, 4, "EtherStatsOctets" },
169 { 0, 8, 2, "EtherStatsUnderSizePkts" },
170 { 0, 10, 2, "EtherFragments" },
171 { 0, 12, 2, "EtherStatsPkts64Octets" },
172 { 0, 14, 2, "EtherStatsPkts65to127Octets" },
173 { 0, 16, 2, "EtherStatsPkts128to255Octets" },
174 { 0, 18, 2, "EtherStatsPkts256to511Octets" },
175 { 0, 20, 2, "EtherStatsPkts512to1023Octets" },
176 { 0, 22, 2, "EtherStatsPkts1024to1518Octets" },
177 { 0, 24, 2, "EtherOversizeStats" },
178 { 0, 26, 2, "EtherStatsJabbers" },
179 { 0, 28, 2, "IfInUcastPkts" },
180 { 0, 30, 2, "EtherStatsMulticastPkts" },
181 { 0, 32, 2, "EtherStatsBroadcastPkts" },
182 { 0, 34, 2, "EtherStatsDropEvents" },
183 { 0, 36, 2, "Dot3StatsFCSErrors" },
184 { 0, 38, 2, "Dot3StatsSymbolErrors" },
185 { 0, 40, 2, "Dot3InPauseFrames" },
186 { 0, 42, 2, "Dot3ControlInUnknownOpcodes" },
187 { 0, 44, 4, "IfOutOctets" },
188 { 0, 48, 2, "Dot3StatsSingleCollisionFrames" },
189 { 0, 50, 2, "Dot3StatMultipleCollisionFrames" },
190 { 0, 52, 2, "Dot3sDeferredTransmissions" },
191 { 0, 54, 2, "Dot3StatsLateCollisions" },
192 { 0, 56, 2, "EtherStatsCollisions" },
193 { 0, 58, 2, "Dot3StatsExcessiveCollisions" },
194 { 0, 60, 2, "Dot3OutPauseFrames" },
195 { 0, 62, 2, "Dot1dBasePortDelayExceededDiscards" },
196 { 0, 64, 2, "Dot1dTpPortInDiscards" },
197 { 0, 66, 2, "IfOutUcastPkts" },
198 { 0, 68, 2, "IfOutMulticastPkts" },
199 { 0, 70, 2, "IfOutBroadcastPkts" },
200 };
201
202 #define REG_WR(_smi, _reg, _val) \
203 do { \
204 err = rtl8366_smi_write_reg(_smi, _reg, _val); \
205 if (err) \
206 return err; \
207 } while (0)
208
209 #define REG_RMW(_smi, _reg, _mask, _val) \
210 do { \
211 err = rtl8366_smi_rmwr(_smi, _reg, _mask, _val); \
212 if (err) \
213 return err; \
214 } while (0)
215
216 static int rtl8366rb_reset_chip(struct rtl8366_smi *smi)
217 {
218 int timeout = 10;
219 u32 data;
220
221 rtl8366_smi_write_reg(smi, RTL8366RB_RESET_CTRL_REG,
222 RTL8366RB_CHIP_CTRL_RESET_HW);
223 do {
224 msleep(1);
225 if (rtl8366_smi_read_reg(smi, RTL8366RB_RESET_CTRL_REG, &data))
226 return -EIO;
227
228 if (!(data & RTL8366RB_CHIP_CTRL_RESET_HW))
229 break;
230 } while (--timeout);
231
232 if (!timeout) {
233 printk("Timeout waiting for the switch to reset\n");
234 return -EIO;
235 }
236
237 return 0;
238 }
239
240 static int rtl8366rb_hw_init(struct rtl8366_smi *smi)
241 {
242 int err;
243
244 /* set maximum packet length to 1536 bytes */
245 REG_RMW(smi, RTL8366RB_SGCR, RTL8366RB_SGCR_MAX_LENGTH_MASK,
246 RTL8366RB_SGCR_MAX_LENGTH_1536);
247
248 /* enable all ports */
249 REG_WR(smi, RTL8366RB_PECR, 0);
250
251 /* disable learning for all ports */
252 REG_WR(smi, RTL8366RB_SSCR0, RTL8366RB_PORT_ALL);
253
254 /* disable auto ageing for all ports */
255 REG_WR(smi, RTL8366RB_SSCR1, RTL8366RB_PORT_ALL);
256
257 /*
258 * discard VLAN tagged packets if the port is not a member of
259 * the VLAN with which the packets is associated.
260 */
261 REG_WR(smi, RTL8366RB_VLAN_INGRESS_CTRL2_REG, RTL8366RB_PORT_ALL);
262
263 /* don't drop packets whose DA has not been learned */
264 REG_RMW(smi, RTL8366RB_SSCR2, RTL8366RB_SSCR2_DROP_UNKNOWN_DA, 0);
265
266 return 0;
267 }
268
269 static int rtl8366rb_read_phy_reg(struct rtl8366_smi *smi,
270 u32 phy_no, u32 page, u32 addr, u32 *data)
271 {
272 u32 reg;
273 int ret;
274
275 if (phy_no > RTL8366RB_PHY_NO_MAX)
276 return -EINVAL;
277
278 if (page > RTL8366RB_PHY_PAGE_MAX)
279 return -EINVAL;
280
281 if (addr > RTL8366RB_PHY_ADDR_MAX)
282 return -EINVAL;
283
284 ret = rtl8366_smi_write_reg(smi, RTL8366RB_PHY_ACCESS_CTRL_REG,
285 RTL8366RB_PHY_CTRL_READ);
286 if (ret)
287 return ret;
288
289 reg = 0x8000 | (1 << (phy_no + RTL8366RB_PHY_NO_OFFSET)) |
290 ((page << RTL8366RB_PHY_PAGE_OFFSET) & RTL8366RB_PHY_PAGE_MASK) |
291 (addr & RTL8366RB_PHY_REG_MASK);
292
293 ret = rtl8366_smi_write_reg(smi, reg, 0);
294 if (ret)
295 return ret;
296
297 ret = rtl8366_smi_read_reg(smi, RTL8366RB_PHY_ACCESS_DATA_REG, data);
298 if (ret)
299 return ret;
300
301 return 0;
302 }
303
304 static int rtl8366rb_write_phy_reg(struct rtl8366_smi *smi,
305 u32 phy_no, u32 page, u32 addr, u32 data)
306 {
307 u32 reg;
308 int ret;
309
310 if (phy_no > RTL8366RB_PHY_NO_MAX)
311 return -EINVAL;
312
313 if (page > RTL8366RB_PHY_PAGE_MAX)
314 return -EINVAL;
315
316 if (addr > RTL8366RB_PHY_ADDR_MAX)
317 return -EINVAL;
318
319 ret = rtl8366_smi_write_reg(smi, RTL8366RB_PHY_ACCESS_CTRL_REG,
320 RTL8366RB_PHY_CTRL_WRITE);
321 if (ret)
322 return ret;
323
324 reg = 0x8000 | (1 << (phy_no + RTL8366RB_PHY_NO_OFFSET)) |
325 ((page << RTL8366RB_PHY_PAGE_OFFSET) & RTL8366RB_PHY_PAGE_MASK) |
326 (addr & RTL8366RB_PHY_REG_MASK);
327
328 ret = rtl8366_smi_write_reg(smi, reg, data);
329 if (ret)
330 return ret;
331
332 return 0;
333 }
334
335 static int rtl8366rb_get_mib_counter(struct rtl8366_smi *smi, int counter,
336 int port, unsigned long long *val)
337 {
338 int i;
339 int err;
340 u32 addr, data;
341 u64 mibvalue;
342
343 if (port > RTL8366RB_NUM_PORTS || counter >= RTL8366RB_MIB_COUNT)
344 return -EINVAL;
345
346 addr = RTL8366RB_MIB_COUNTER_BASE +
347 RTL8366RB_MIB_COUNTER_PORT_OFFSET * (port) +
348 rtl8366rb_mib_counters[counter].offset;
349
350 /*
351 * Writing access counter address first
352 * then ASIC will prepare 64bits counter wait for being retrived
353 */
354 data = 0; /* writing data will be discard by ASIC */
355 err = rtl8366_smi_write_reg(smi, addr, data);
356 if (err)
357 return err;
358
359 /* read MIB control register */
360 err = rtl8366_smi_read_reg(smi, RTL8366RB_MIB_CTRL_REG, &data);
361 if (err)
362 return err;
363
364 if (data & RTL8366RB_MIB_CTRL_BUSY_MASK)
365 return -EBUSY;
366
367 if (data & RTL8366RB_MIB_CTRL_RESET_MASK)
368 return -EIO;
369
370 mibvalue = 0;
371 for (i = rtl8366rb_mib_counters[counter].length; i > 0; i--) {
372 err = rtl8366_smi_read_reg(smi, addr + (i - 1), &data);
373 if (err)
374 return err;
375
376 mibvalue = (mibvalue << 16) | (data & 0xFFFF);
377 }
378
379 *val = mibvalue;
380 return 0;
381 }
382
383 static int rtl8366rb_get_vlan_4k(struct rtl8366_smi *smi, u32 vid,
384 struct rtl8366_vlan_4k *vlan4k)
385 {
386 u32 data[3];
387 int err;
388 int i;
389
390 memset(vlan4k, '\0', sizeof(struct rtl8366_vlan_4k));
391
392 if (vid >= RTL8366RB_NUM_VIDS)
393 return -EINVAL;
394
395 /* write VID */
396 err = rtl8366_smi_write_reg(smi, RTL8366RB_VLAN_TABLE_WRITE_BASE,
397 vid & RTL8366RB_VLAN_VID_MASK);
398 if (err)
399 return err;
400
401 /* write table access control word */
402 err = rtl8366_smi_write_reg(smi, RTL8366RB_TABLE_ACCESS_CTRL_REG,
403 RTL8366RB_TABLE_VLAN_READ_CTRL);
404 if (err)
405 return err;
406
407 for (i = 0; i < 3; i++) {
408 err = rtl8366_smi_read_reg(smi,
409 RTL8366RB_VLAN_TABLE_READ_BASE + i,
410 &data[i]);
411 if (err)
412 return err;
413 }
414
415 vlan4k->vid = vid;
416 vlan4k->untag = (data[1] >> RTL8366RB_VLAN_UNTAG_SHIFT) &
417 RTL8366RB_VLAN_UNTAG_MASK;
418 vlan4k->member = data[1] & RTL8366RB_VLAN_MEMBER_MASK;
419 vlan4k->fid = data[2] & RTL8366RB_VLAN_FID_MASK;
420
421 return 0;
422 }
423
424 static int rtl8366rb_set_vlan_4k(struct rtl8366_smi *smi,
425 const struct rtl8366_vlan_4k *vlan4k)
426 {
427 u32 data[3];
428 int err;
429 int i;
430
431 if (vlan4k->vid >= RTL8366RB_NUM_VIDS ||
432 vlan4k->member > RTL8366RB_PORT_ALL ||
433 vlan4k->untag > RTL8366RB_PORT_ALL ||
434 vlan4k->fid > RTL8366RB_FIDMAX)
435 return -EINVAL;
436
437 data[0] = vlan4k->vid & RTL8366RB_VLAN_VID_MASK;
438 data[1] = (vlan4k->member & RTL8366RB_VLAN_MEMBER_MASK) |
439 ((vlan4k->untag & RTL8366RB_VLAN_UNTAG_MASK) <<
440 RTL8366RB_VLAN_UNTAG_SHIFT);
441 data[2] = vlan4k->fid & RTL8366RB_VLAN_FID_MASK;
442
443 for (i = 0; i < 3; i++) {
444 err = rtl8366_smi_write_reg(smi,
445 RTL8366RB_VLAN_TABLE_WRITE_BASE + i,
446 data[i]);
447 if (err)
448 return err;
449 }
450
451 /* write table access control word */
452 err = rtl8366_smi_write_reg(smi, RTL8366RB_TABLE_ACCESS_CTRL_REG,
453 RTL8366RB_TABLE_VLAN_WRITE_CTRL);
454
455 return err;
456 }
457
458 static int rtl8366rb_get_vlan_mc(struct rtl8366_smi *smi, u32 index,
459 struct rtl8366_vlan_mc *vlanmc)
460 {
461 u32 data[3];
462 int err;
463 int i;
464
465 memset(vlanmc, '\0', sizeof(struct rtl8366_vlan_mc));
466
467 if (index >= RTL8366RB_NUM_VLANS)
468 return -EINVAL;
469
470 for (i = 0; i < 3; i++) {
471 err = rtl8366_smi_read_reg(smi,
472 RTL8366RB_VLAN_MC_BASE(index) + i,
473 &data[i]);
474 if (err)
475 return err;
476 }
477
478 vlanmc->vid = data[0] & RTL8366RB_VLAN_VID_MASK;
479 vlanmc->priority = (data[0] >> RTL8366RB_VLAN_PRIORITY_SHIFT) &
480 RTL8366RB_VLAN_PRIORITY_MASK;
481 vlanmc->untag = (data[1] >> RTL8366RB_VLAN_UNTAG_SHIFT) &
482 RTL8366RB_VLAN_UNTAG_MASK;
483 vlanmc->member = data[1] & RTL8366RB_VLAN_MEMBER_MASK;
484 vlanmc->fid = data[2] & RTL8366RB_VLAN_FID_MASK;
485
486 return 0;
487 }
488
489 static int rtl8366rb_set_vlan_mc(struct rtl8366_smi *smi, u32 index,
490 const struct rtl8366_vlan_mc *vlanmc)
491 {
492 u32 data[3];
493 int err;
494 int i;
495
496 if (index >= RTL8366RB_NUM_VLANS ||
497 vlanmc->vid >= RTL8366RB_NUM_VIDS ||
498 vlanmc->priority > RTL8366RB_PRIORITYMAX ||
499 vlanmc->member > RTL8366RB_PORT_ALL ||
500 vlanmc->untag > RTL8366RB_PORT_ALL ||
501 vlanmc->fid > RTL8366RB_FIDMAX)
502 return -EINVAL;
503
504 data[0] = (vlanmc->vid & RTL8366RB_VLAN_VID_MASK) |
505 ((vlanmc->priority & RTL8366RB_VLAN_PRIORITY_MASK) <<
506 RTL8366RB_VLAN_PRIORITY_SHIFT);
507 data[1] = (vlanmc->member & RTL8366RB_VLAN_MEMBER_MASK) |
508 ((vlanmc->untag & RTL8366RB_VLAN_UNTAG_MASK) <<
509 RTL8366RB_VLAN_UNTAG_SHIFT);
510 data[2] = vlanmc->fid & RTL8366RB_VLAN_FID_MASK;
511
512 for (i = 0; i < 3; i++) {
513 err = rtl8366_smi_write_reg(smi,
514 RTL8366RB_VLAN_MC_BASE(index) + i,
515 data[i]);
516 if (err)
517 return err;
518 }
519
520 return 0;
521 }
522
523 static int rtl8366rb_get_mc_index(struct rtl8366_smi *smi, int port, int *val)
524 {
525 u32 data;
526 int err;
527
528 if (port >= RTL8366RB_NUM_PORTS)
529 return -EINVAL;
530
531 err = rtl8366_smi_read_reg(smi, RTL8366RB_PORT_VLAN_CTRL_REG(port),
532 &data);
533 if (err)
534 return err;
535
536 *val = (data >> RTL8366RB_PORT_VLAN_CTRL_SHIFT(port)) &
537 RTL8366RB_PORT_VLAN_CTRL_MASK;
538
539 return 0;
540
541 }
542
543 static int rtl8366rb_set_mc_index(struct rtl8366_smi *smi, int port, int index)
544 {
545 if (port >= RTL8366RB_NUM_PORTS || index >= RTL8366RB_NUM_VLANS)
546 return -EINVAL;
547
548 return rtl8366_smi_rmwr(smi, RTL8366RB_PORT_VLAN_CTRL_REG(port),
549 RTL8366RB_PORT_VLAN_CTRL_MASK <<
550 RTL8366RB_PORT_VLAN_CTRL_SHIFT(port),
551 (index & RTL8366RB_PORT_VLAN_CTRL_MASK) <<
552 RTL8366RB_PORT_VLAN_CTRL_SHIFT(port));
553 }
554
555 static int rtl8366rb_vlan_set_vlan(struct rtl8366_smi *smi, int enable)
556 {
557 return rtl8366_smi_rmwr(smi, RTL8366RB_SGCR, RTL8366RB_SGCR_EN_VLAN,
558 (enable) ? RTL8366RB_SGCR_EN_VLAN : 0);
559 }
560
561 static int rtl8366rb_vlan_set_4ktable(struct rtl8366_smi *smi, int enable)
562 {
563 return rtl8366_smi_rmwr(smi, RTL8366RB_SGCR,
564 RTL8366RB_SGCR_EN_VLAN_4KTB,
565 (enable) ? RTL8366RB_SGCR_EN_VLAN_4KTB : 0);
566 }
567
568 static int rtl8366rb_sw_reset_mibs(struct switch_dev *dev,
569 const struct switch_attr *attr,
570 struct switch_val *val)
571 {
572 struct rtl8366_smi *smi = sw_to_rtl8366_smi(dev);
573
574 return rtl8366_smi_rmwr(smi, RTL8366RB_MIB_CTRL_REG, 0,
575 RTL8366RB_MIB_CTRL_GLOBAL_RESET);
576 }
577
578 static int rtl8366rb_sw_get_vlan_enable(struct switch_dev *dev,
579 const struct switch_attr *attr,
580 struct switch_val *val)
581 {
582 struct rtl8366_smi *smi = sw_to_rtl8366_smi(dev);
583 u32 data;
584
585 if (attr->ofs == 1) {
586 rtl8366_smi_read_reg(smi, RTL8366RB_SGCR, &data);
587
588 if (data & RTL8366RB_SGCR_EN_VLAN)
589 val->value.i = 1;
590 else
591 val->value.i = 0;
592 } else if (attr->ofs == 2) {
593 rtl8366_smi_read_reg(smi, RTL8366RB_SGCR, &data);
594
595 if (data & RTL8366RB_SGCR_EN_VLAN_4KTB)
596 val->value.i = 1;
597 else
598 val->value.i = 0;
599 }
600
601 return 0;
602 }
603
604 static int rtl8366rb_sw_get_blinkrate(struct switch_dev *dev,
605 const struct switch_attr *attr,
606 struct switch_val *val)
607 {
608 struct rtl8366_smi *smi = sw_to_rtl8366_smi(dev);
609 u32 data;
610
611 rtl8366_smi_read_reg(smi, RTL8366RB_LED_BLINKRATE_REG, &data);
612
613 val->value.i = (data & (RTL8366RB_LED_BLINKRATE_MASK));
614
615 return 0;
616 }
617
618 static int rtl8366rb_sw_set_blinkrate(struct switch_dev *dev,
619 const struct switch_attr *attr,
620 struct switch_val *val)
621 {
622 struct rtl8366_smi *smi = sw_to_rtl8366_smi(dev);
623
624 if (val->value.i >= 6)
625 return -EINVAL;
626
627 return rtl8366_smi_rmwr(smi, RTL8366RB_LED_BLINKRATE_REG,
628 RTL8366RB_LED_BLINKRATE_MASK,
629 val->value.i);
630 }
631
632 static int rtl8366rb_sw_set_vlan_enable(struct switch_dev *dev,
633 const struct switch_attr *attr,
634 struct switch_val *val)
635 {
636 struct rtl8366_smi *smi = sw_to_rtl8366_smi(dev);
637
638 if (attr->ofs == 1)
639 return rtl8366rb_vlan_set_vlan(smi, val->value.i);
640 else
641 return rtl8366rb_vlan_set_4ktable(smi, val->value.i);
642 }
643
644 static const char *rtl8366rb_speed_str(unsigned speed)
645 {
646 switch (speed) {
647 case 0:
648 return "10baseT";
649 case 1:
650 return "100baseT";
651 case 2:
652 return "1000baseT";
653 }
654
655 return "unknown";
656 }
657
658 static int rtl8366rb_sw_get_port_link(struct switch_dev *dev,
659 const struct switch_attr *attr,
660 struct switch_val *val)
661 {
662 struct rtl8366_smi *smi = sw_to_rtl8366_smi(dev);
663 u32 len = 0, data = 0;
664
665 if (val->port_vlan >= RTL8366RB_NUM_PORTS)
666 return -EINVAL;
667
668 memset(smi->buf, '\0', sizeof(smi->buf));
669 rtl8366_smi_read_reg(smi, RTL8366RB_PORT_LINK_STATUS_BASE +
670 (val->port_vlan / 2), &data);
671
672 if (val->port_vlan % 2)
673 data = data >> 8;
674
675 if (data & RTL8366RB_PORT_STATUS_LINK_MASK) {
676 len = snprintf(smi->buf, sizeof(smi->buf),
677 "port:%d link:up speed:%s %s-duplex %s%s%s",
678 val->port_vlan,
679 rtl8366rb_speed_str(data &
680 RTL8366RB_PORT_STATUS_SPEED_MASK),
681 (data & RTL8366RB_PORT_STATUS_DUPLEX_MASK) ?
682 "full" : "half",
683 (data & RTL8366RB_PORT_STATUS_TXPAUSE_MASK) ?
684 "tx-pause ": "",
685 (data & RTL8366RB_PORT_STATUS_RXPAUSE_MASK) ?
686 "rx-pause " : "",
687 (data & RTL8366RB_PORT_STATUS_AN_MASK) ?
688 "nway ": "");
689 } else {
690 len = snprintf(smi->buf, sizeof(smi->buf), "port:%d link: down",
691 val->port_vlan);
692 }
693
694 val->value.s = smi->buf;
695 val->len = len;
696
697 return 0;
698 }
699
700 static int rtl8366rb_sw_get_vlan_info(struct switch_dev *dev,
701 const struct switch_attr *attr,
702 struct switch_val *val)
703 {
704 int i;
705 u32 len = 0;
706 struct rtl8366_vlan_4k vlan4k;
707 struct rtl8366_smi *smi = sw_to_rtl8366_smi(dev);
708 char *buf = smi->buf;
709 int err;
710
711 if (val->port_vlan == 0 || val->port_vlan >= RTL8366RB_NUM_VLANS)
712 return -EINVAL;
713
714 memset(buf, '\0', sizeof(smi->buf));
715
716 err = rtl8366rb_get_vlan_4k(smi, val->port_vlan, &vlan4k);
717 if (err)
718 return err;
719
720 len += snprintf(buf + len, sizeof(smi->buf) - len,
721 "VLAN %d: Ports: '", vlan4k.vid);
722
723 for (i = 0; i < RTL8366RB_NUM_PORTS; i++) {
724 if (!(vlan4k.member & (1 << i)))
725 continue;
726
727 len += snprintf(buf + len, sizeof(smi->buf) - len, "%d%s", i,
728 (vlan4k.untag & (1 << i)) ? "" : "t");
729 }
730
731 len += snprintf(buf + len, sizeof(smi->buf) - len,
732 "', members=%04x, untag=%04x, fid=%u",
733 vlan4k.member, vlan4k.untag, vlan4k.fid);
734
735 val->value.s = buf;
736 val->len = len;
737
738 return 0;
739 }
740
741 static int rtl8366rb_sw_set_port_led(struct switch_dev *dev,
742 const struct switch_attr *attr,
743 struct switch_val *val)
744 {
745 struct rtl8366_smi *smi = sw_to_rtl8366_smi(dev);
746 u32 data;
747 u32 mask;
748 u32 reg;
749
750 if (val->port_vlan >= RTL8366RB_NUM_PORTS)
751 return -EINVAL;
752
753 if (val->port_vlan == RTL8366RB_PORT_NUM_CPU) {
754 reg = RTL8366RB_LED_BLINKRATE_REG;
755 mask = 0xF << 4;
756 data = val->value.i << 4;
757 } else {
758 reg = RTL8366RB_LED_CTRL_REG;
759 mask = 0xF << (val->port_vlan * 4),
760 data = val->value.i << (val->port_vlan * 4);
761 }
762
763 return rtl8366_smi_rmwr(smi, RTL8366RB_LED_BLINKRATE_REG, mask, data);
764 }
765
766 static int rtl8366rb_sw_get_port_led(struct switch_dev *dev,
767 const struct switch_attr *attr,
768 struct switch_val *val)
769 {
770 struct rtl8366_smi *smi = sw_to_rtl8366_smi(dev);
771 u32 data = 0;
772
773 if (val->port_vlan >= RTL8366RB_NUM_LEDGROUPS)
774 return -EINVAL;
775
776 rtl8366_smi_read_reg(smi, RTL8366RB_LED_CTRL_REG, &data);
777 val->value.i = (data >> (val->port_vlan * 4)) & 0x000F;
778
779 return 0;
780 }
781
782 static int rtl8366rb_sw_reset_port_mibs(struct switch_dev *dev,
783 const struct switch_attr *attr,
784 struct switch_val *val)
785 {
786 struct rtl8366_smi *smi = sw_to_rtl8366_smi(dev);
787
788 if (val->port_vlan >= RTL8366RB_NUM_PORTS)
789 return -EINVAL;
790
791 return rtl8366_smi_rmwr(smi, RTL8366RB_MIB_CTRL_REG, 0,
792 RTL8366RB_MIB_CTRL_PORT_RESET(val->port_vlan));
793 }
794
795 static int rtl8366rb_sw_get_port_mib(struct switch_dev *dev,
796 const struct switch_attr *attr,
797 struct switch_val *val)
798 {
799 struct rtl8366_smi *smi = sw_to_rtl8366_smi(dev);
800 int i, len = 0;
801 unsigned long long counter = 0;
802 char *buf = smi->buf;
803
804 if (val->port_vlan >= RTL8366RB_NUM_PORTS)
805 return -EINVAL;
806
807 len += snprintf(buf + len, sizeof(smi->buf) - len,
808 "Port %d MIB counters\n",
809 val->port_vlan);
810
811 for (i = 0; i < ARRAY_SIZE(rtl8366rb_mib_counters); ++i) {
812 len += snprintf(buf + len, sizeof(smi->buf) - len,
813 "%-36s: ", rtl8366rb_mib_counters[i].name);
814 if (!rtl8366rb_get_mib_counter(smi, i, val->port_vlan, &counter))
815 len += snprintf(buf + len, sizeof(smi->buf) - len,
816 "%llu\n", counter);
817 else
818 len += snprintf(buf + len, sizeof(smi->buf) - len,
819 "%s\n", "error");
820 }
821
822 val->value.s = buf;
823 val->len = len;
824 return 0;
825 }
826
827 static int rtl8366rb_sw_get_vlan_ports(struct switch_dev *dev,
828 struct switch_val *val)
829 {
830 struct rtl8366_smi *smi = sw_to_rtl8366_smi(dev);
831 struct switch_port *port;
832 struct rtl8366_vlan_4k vlan4k;
833 int i;
834
835 if (val->port_vlan == 0 || val->port_vlan >= RTL8366RB_NUM_VLANS)
836 return -EINVAL;
837
838 rtl8366rb_get_vlan_4k(smi, val->port_vlan, &vlan4k);
839
840 port = &val->value.ports[0];
841 val->len = 0;
842 for (i = 0; i < RTL8366RB_NUM_PORTS; i++) {
843 if (!(vlan4k.member & BIT(i)))
844 continue;
845
846 port->id = i;
847 port->flags = (vlan4k.untag & BIT(i)) ?
848 0 : BIT(SWITCH_PORT_FLAG_TAGGED);
849 val->len++;
850 port++;
851 }
852 return 0;
853 }
854
855 static int rtl8366rb_sw_set_vlan_ports(struct switch_dev *dev,
856 struct switch_val *val)
857 {
858 struct rtl8366_smi *smi = sw_to_rtl8366_smi(dev);
859 struct switch_port *port;
860 u32 member = 0;
861 u32 untag = 0;
862 int i;
863
864 if (val->port_vlan == 0 || val->port_vlan >= RTL8366RB_NUM_VLANS)
865 return -EINVAL;
866
867 port = &val->value.ports[0];
868 for (i = 0; i < val->len; i++, port++) {
869 member |= BIT(port->id);
870
871 if (!(port->flags & BIT(SWITCH_PORT_FLAG_TAGGED)))
872 untag |= BIT(port->id);
873 }
874
875 return rtl8366_set_vlan(smi, val->port_vlan, member, untag, 0);
876 }
877
878 static int rtl8366rb_sw_get_port_pvid(struct switch_dev *dev, int port, int *val)
879 {
880 struct rtl8366_smi *smi = sw_to_rtl8366_smi(dev);
881 return rtl8366_get_pvid(smi, port, val);
882 }
883
884 static int rtl8366rb_sw_set_port_pvid(struct switch_dev *dev, int port, int val)
885 {
886 struct rtl8366_smi *smi = sw_to_rtl8366_smi(dev);
887 return rtl8366_set_pvid(smi, port, val);
888 }
889
890 static int rtl8366rb_sw_reset_switch(struct switch_dev *dev)
891 {
892 struct rtl8366_smi *smi = sw_to_rtl8366_smi(dev);
893 int err;
894
895 err = rtl8366rb_reset_chip(smi);
896 if (err)
897 return err;
898
899 err = rtl8366rb_hw_init(smi);
900 if (err)
901 return err;
902
903 return rtl8366_reset_vlan(smi);
904 }
905
906 static struct switch_attr rtl8366rb_globals[] = {
907 {
908 .type = SWITCH_TYPE_INT,
909 .name = "enable_vlan",
910 .description = "Enable VLAN mode",
911 .set = rtl8366rb_sw_set_vlan_enable,
912 .get = rtl8366rb_sw_get_vlan_enable,
913 .max = 1,
914 .ofs = 1
915 }, {
916 .type = SWITCH_TYPE_INT,
917 .name = "enable_vlan4k",
918 .description = "Enable VLAN 4K mode",
919 .set = rtl8366rb_sw_set_vlan_enable,
920 .get = rtl8366rb_sw_get_vlan_enable,
921 .max = 1,
922 .ofs = 2
923 }, {
924 .type = SWITCH_TYPE_NOVAL,
925 .name = "reset_mibs",
926 .description = "Reset all MIB counters",
927 .set = rtl8366rb_sw_reset_mibs,
928 }, {
929 .type = SWITCH_TYPE_INT,
930 .name = "blinkrate",
931 .description = "Get/Set LED blinking rate (0 = 43ms, 1 = 84ms,"
932 " 2 = 120ms, 3 = 170ms, 4 = 340ms, 5 = 670ms)",
933 .set = rtl8366rb_sw_set_blinkrate,
934 .get = rtl8366rb_sw_get_blinkrate,
935 .max = 5
936 },
937 };
938
939 static struct switch_attr rtl8366rb_port[] = {
940 {
941 .type = SWITCH_TYPE_STRING,
942 .name = "link",
943 .description = "Get port link information",
944 .max = 1,
945 .set = NULL,
946 .get = rtl8366rb_sw_get_port_link,
947 }, {
948 .type = SWITCH_TYPE_NOVAL,
949 .name = "reset_mib",
950 .description = "Reset single port MIB counters",
951 .set = rtl8366rb_sw_reset_port_mibs,
952 }, {
953 .type = SWITCH_TYPE_STRING,
954 .name = "mib",
955 .description = "Get MIB counters for port",
956 .max = 33,
957 .set = NULL,
958 .get = rtl8366rb_sw_get_port_mib,
959 }, {
960 .type = SWITCH_TYPE_INT,
961 .name = "led",
962 .description = "Get/Set port group (0 - 3) led mode (0 - 15)",
963 .max = 15,
964 .set = rtl8366rb_sw_set_port_led,
965 .get = rtl8366rb_sw_get_port_led,
966 },
967 };
968
969 static struct switch_attr rtl8366rb_vlan[] = {
970 {
971 .type = SWITCH_TYPE_STRING,
972 .name = "info",
973 .description = "Get vlan information",
974 .max = 1,
975 .set = NULL,
976 .get = rtl8366rb_sw_get_vlan_info,
977 },
978 };
979
980 /* template */
981 static struct switch_dev rtl8366_switch_dev = {
982 .name = "RTL8366S",
983 .cpu_port = RTL8366RB_PORT_NUM_CPU,
984 .ports = RTL8366RB_NUM_PORTS,
985 .vlans = RTL8366RB_NUM_VLANS,
986 .attr_global = {
987 .attr = rtl8366rb_globals,
988 .n_attr = ARRAY_SIZE(rtl8366rb_globals),
989 },
990 .attr_port = {
991 .attr = rtl8366rb_port,
992 .n_attr = ARRAY_SIZE(rtl8366rb_port),
993 },
994 .attr_vlan = {
995 .attr = rtl8366rb_vlan,
996 .n_attr = ARRAY_SIZE(rtl8366rb_vlan),
997 },
998
999 .get_vlan_ports = rtl8366rb_sw_get_vlan_ports,
1000 .set_vlan_ports = rtl8366rb_sw_set_vlan_ports,
1001 .get_port_pvid = rtl8366rb_sw_get_port_pvid,
1002 .set_port_pvid = rtl8366rb_sw_set_port_pvid,
1003 .reset_switch = rtl8366rb_sw_reset_switch,
1004 };
1005
1006 static int rtl8366rb_switch_init(struct rtl8366_smi *smi)
1007 {
1008 struct switch_dev *dev = &smi->sw_dev;
1009 int err;
1010
1011 memcpy(dev, &rtl8366_switch_dev, sizeof(struct switch_dev));
1012 dev->priv = smi;
1013 dev->devname = dev_name(smi->parent);
1014
1015 err = register_switch(dev, NULL);
1016 if (err)
1017 dev_err(smi->parent, "switch registration failed\n");
1018
1019 return err;
1020 }
1021
1022 static void rtl8366rb_switch_cleanup(struct rtl8366_smi *smi)
1023 {
1024 unregister_switch(&smi->sw_dev);
1025 }
1026
1027 static int rtl8366rb_mii_read(struct mii_bus *bus, int addr, int reg)
1028 {
1029 struct rtl8366_smi *smi = bus->priv;
1030 u32 val = 0;
1031 int err;
1032
1033 err = rtl8366rb_read_phy_reg(smi, addr, 0, reg, &val);
1034 if (err)
1035 return 0xffff;
1036
1037 return val;
1038 }
1039
1040 static int rtl8366rb_mii_write(struct mii_bus *bus, int addr, int reg, u16 val)
1041 {
1042 struct rtl8366_smi *smi = bus->priv;
1043 u32 t;
1044 int err;
1045
1046 err = rtl8366rb_write_phy_reg(smi, addr, 0, reg, val);
1047 /* flush write */
1048 (void) rtl8366rb_read_phy_reg(smi, addr, 0, reg, &t);
1049
1050 return err;
1051 }
1052
1053 static int rtl8366rb_mii_bus_match(struct mii_bus *bus)
1054 {
1055 return (bus->read == rtl8366rb_mii_read &&
1056 bus->write == rtl8366rb_mii_write);
1057 }
1058
1059 static int rtl8366rb_setup(struct rtl8366_smi *smi)
1060 {
1061 int ret;
1062
1063 ret = rtl8366rb_reset_chip(smi);
1064 if (ret)
1065 return ret;
1066
1067 ret = rtl8366rb_hw_init(smi);
1068 return ret;
1069 }
1070
1071 static int rtl8366rb_detect(struct rtl8366_smi *smi)
1072 {
1073 u32 chip_id = 0;
1074 u32 chip_ver = 0;
1075 int ret;
1076
1077 ret = rtl8366_smi_read_reg(smi, RTL8366RB_CHIP_ID_REG, &chip_id);
1078 if (ret) {
1079 dev_err(smi->parent, "unable to read chip id\n");
1080 return ret;
1081 }
1082
1083 switch (chip_id) {
1084 case RTL8366RB_CHIP_ID_8366:
1085 break;
1086 default:
1087 dev_err(smi->parent, "unknown chip id (%04x)\n", chip_id);
1088 return -ENODEV;
1089 }
1090
1091 ret = rtl8366_smi_read_reg(smi, RTL8366RB_CHIP_VERSION_CTRL_REG,
1092 &chip_ver);
1093 if (ret) {
1094 dev_err(smi->parent, "unable to read chip version\n");
1095 return ret;
1096 }
1097
1098 dev_info(smi->parent, "RTL%04x ver. %u chip found\n",
1099 chip_id, chip_ver & RTL8366RB_CHIP_VERSION_MASK);
1100
1101 return 0;
1102 }
1103
1104 static struct rtl8366_smi_ops rtl8366rb_smi_ops = {
1105 .detect = rtl8366rb_detect,
1106 .mii_read = rtl8366rb_mii_read,
1107 .mii_write = rtl8366rb_mii_write,
1108
1109 .get_vlan_mc = rtl8366rb_get_vlan_mc,
1110 .set_vlan_mc = rtl8366rb_set_vlan_mc,
1111 .get_vlan_4k = rtl8366rb_get_vlan_4k,
1112 .set_vlan_4k = rtl8366rb_set_vlan_4k,
1113 .get_mc_index = rtl8366rb_get_mc_index,
1114 .set_mc_index = rtl8366rb_set_mc_index,
1115 .get_mib_counter = rtl8366rb_get_mib_counter,
1116 };
1117
1118 static int __init rtl8366rb_probe(struct platform_device *pdev)
1119 {
1120 static int rtl8366_smi_version_printed;
1121 struct rtl8366rb_platform_data *pdata;
1122 struct rtl8366_smi *smi;
1123 int err;
1124
1125 if (!rtl8366_smi_version_printed++)
1126 printk(KERN_NOTICE RTL8366RB_DRIVER_DESC
1127 " version " RTL8366RB_DRIVER_VER"\n");
1128
1129 pdata = pdev->dev.platform_data;
1130 if (!pdata) {
1131 dev_err(&pdev->dev, "no platform data specified\n");
1132 err = -EINVAL;
1133 goto err_out;
1134 }
1135
1136 smi = kzalloc(sizeof(*smi), GFP_KERNEL);
1137 if (!smi) {
1138 dev_err(&pdev->dev, "no memory for private data\n");
1139 err = -ENOMEM;
1140 goto err_out;
1141 }
1142
1143 smi->parent = &pdev->dev;
1144 smi->gpio_sda = pdata->gpio_sda;
1145 smi->gpio_sck = pdata->gpio_sck;
1146 smi->ops = &rtl8366rb_smi_ops;
1147 smi->cpu_port = RTL8366RB_PORT_NUM_CPU;
1148 smi->num_ports = RTL8366RB_NUM_PORTS;
1149 smi->num_vlan_mc = RTL8366RB_NUM_VLANS;
1150 smi->mib_counters = rtl8366rb_mib_counters;
1151 smi->num_mib_counters = ARRAY_SIZE(rtl8366rb_mib_counters);
1152
1153 err = rtl8366_smi_init(smi);
1154 if (err)
1155 goto err_free_smi;
1156
1157 platform_set_drvdata(pdev, smi);
1158
1159 err = rtl8366rb_setup(smi);
1160 if (err)
1161 goto err_clear_drvdata;
1162
1163 err = rtl8366rb_switch_init(smi);
1164 if (err)
1165 goto err_clear_drvdata;
1166
1167 return 0;
1168
1169 err_clear_drvdata:
1170 platform_set_drvdata(pdev, NULL);
1171 rtl8366_smi_cleanup(smi);
1172 err_free_smi:
1173 kfree(smi);
1174 err_out:
1175 return err;
1176 }
1177
1178 static int rtl8366rb_phy_config_init(struct phy_device *phydev)
1179 {
1180 if (!rtl8366rb_mii_bus_match(phydev->bus))
1181 return -EINVAL;
1182
1183 return 0;
1184 }
1185
1186 static int rtl8366rb_phy_config_aneg(struct phy_device *phydev)
1187 {
1188 return 0;
1189 }
1190
1191 static struct phy_driver rtl8366rb_phy_driver = {
1192 .phy_id = 0x001cc960,
1193 .name = "Realtek RTL8366RB",
1194 .phy_id_mask = 0x1ffffff0,
1195 .features = PHY_GBIT_FEATURES,
1196 .config_aneg = rtl8366rb_phy_config_aneg,
1197 .config_init = rtl8366rb_phy_config_init,
1198 .read_status = genphy_read_status,
1199 .driver = {
1200 .owner = THIS_MODULE,
1201 },
1202 };
1203
1204 static int __devexit rtl8366rb_remove(struct platform_device *pdev)
1205 {
1206 struct rtl8366_smi *smi = platform_get_drvdata(pdev);
1207
1208 if (smi) {
1209 rtl8366rb_switch_cleanup(smi);
1210 platform_set_drvdata(pdev, NULL);
1211 rtl8366_smi_cleanup(smi);
1212 kfree(smi);
1213 }
1214
1215 return 0;
1216 }
1217
1218 static struct platform_driver rtl8366rb_driver = {
1219 .driver = {
1220 .name = RTL8366RB_DRIVER_NAME,
1221 .owner = THIS_MODULE,
1222 },
1223 .probe = rtl8366rb_probe,
1224 .remove = __devexit_p(rtl8366rb_remove),
1225 };
1226
1227 static int __init rtl8366rb_module_init(void)
1228 {
1229 int ret;
1230 ret = platform_driver_register(&rtl8366rb_driver);
1231 if (ret)
1232 return ret;
1233
1234 ret = phy_driver_register(&rtl8366rb_phy_driver);
1235 if (ret)
1236 goto err_platform_unregister;
1237
1238 return 0;
1239
1240 err_platform_unregister:
1241 platform_driver_unregister(&rtl8366rb_driver);
1242 return ret;
1243 }
1244 module_init(rtl8366rb_module_init);
1245
1246 static void __exit rtl8366rb_module_exit(void)
1247 {
1248 phy_driver_unregister(&rtl8366rb_phy_driver);
1249 platform_driver_unregister(&rtl8366rb_driver);
1250 }
1251 module_exit(rtl8366rb_module_exit);
1252
1253 MODULE_DESCRIPTION(RTL8366RB_DRIVER_DESC);
1254 MODULE_VERSION(RTL8366RB_DRIVER_VER);
1255 MODULE_AUTHOR("Gabor Juhos <juhosg@openwrt.org>");
1256 MODULE_AUTHOR("Antti Seppälä <a.seppala@gmail.com>");
1257 MODULE_LICENSE("GPL v2");
1258 MODULE_ALIAS("platform:" RTL8366RB_DRIVER_NAME);
This page took 0.092812 seconds and 5 git commands to generate.