864168ffd2992dbbe68e86f8ce38fc2da40a2b2f
[openwrt.git] / target / linux / generic / files / drivers / net / phy / ip17xx.c
1 /*
2 * ip17xx.c: Swconfig configuration for IC+ IP17xx switch family
3 *
4 * Copyright (C) 2008 Patrick Horn <patrick.horn@gmail.com>
5 * Copyright (C) 2008, 2010 Martin Mares <mj@ucw.cz>
6 * Copyright (C) 2009 Felix Fietkau <nbd@openwrt.org>
7 *
8 * This program is free software; you can redistribute it and/or
9 * modify it under the terms of the GNU General Public License
10 * as published by the Free Software Foundation; either version 2
11 * of the License, or (at your option) any later version.
12 *
13 * This program is distributed in the hope that it will be useful,
14 * but WITHOUT ANY WARRANTY; without even the implied warranty of
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 * GNU General Public License for more details.
17 */
18
19 #include <linux/kernel.h>
20 #include <linux/module.h>
21 #include <linux/init.h>
22 #include <linux/list.h>
23 #include <linux/skbuff.h>
24 #include <linux/mii.h>
25 #include <linux/phy.h>
26 #include <linux/delay.h>
27 #include <linux/switch.h>
28 #include <linux/device.h>
29
30 #define MAX_VLANS 16
31 #define MAX_PORTS 9
32 #undef DUMP_MII_IO
33
34 typedef struct ip17xx_reg {
35 u16 p; // phy
36 u16 m; // mii
37 } reg;
38 typedef char bitnum;
39
40 #define NOTSUPPORTED {-1,-1}
41
42 #define REG_SUPP(x) (((x).m != ((u16)-1)) && ((x).p != (u16)-1))
43
44 struct ip17xx_state;
45
46 /*********** CONSTANTS ***********/
47 struct register_mappings {
48 char *NAME;
49 u16 MODEL_NO; // Compare to bits 4-9 of MII register 0,3.
50 bitnum NUM_PORTS;
51 bitnum CPU_PORT;
52
53 /* The default VLAN for each port.
54 Default: 0x0001 for Ports 0,1,2,3
55 0x0002 for Ports 4,5 */
56 reg VLAN_DEFAULT_TAG_REG[MAX_PORTS];
57
58 /* These ports are tagged.
59 Default: 0x00 */
60 reg ADD_TAG_REG;
61 reg REMOVE_TAG_REG;
62 bitnum ADD_TAG_BIT[MAX_PORTS];
63 /* These ports are untagged.
64 Default: 0x00 (i.e. do not alter any VLAN tags...)
65 Maybe set to 0 if user disables VLANs. */
66 bitnum REMOVE_TAG_BIT[MAX_PORTS];
67
68 /* Port M and Port N are on the same VLAN.
69 Default: All ports on all VLANs. */
70 // Use register {29, 19+N/2}
71 reg VLAN_LOOKUP_REG;
72 // Port 5 uses register {30, 18} but same as odd bits.
73 reg VLAN_LOOKUP_REG_5; // in a different register on IP175C.
74 bitnum VLAN_LOOKUP_EVEN_BIT[MAX_PORTS];
75 bitnum VLAN_LOOKUP_ODD_BIT[MAX_PORTS];
76
77 /* This VLAN corresponds to which ports.
78 Default: 0x2f,0x30,0x3f,0x3f... */
79 reg TAG_VLAN_MASK_REG;
80 bitnum TAG_VLAN_MASK_EVEN_BIT[MAX_PORTS];
81 bitnum TAG_VLAN_MASK_ODD_BIT[MAX_PORTS];
82
83 int RESET_VAL;
84 reg RESET_REG;
85
86 reg MODE_REG;
87 int MODE_VAL;
88
89 /* General flags */
90 reg ROUTER_CONTROL_REG;
91 reg VLAN_CONTROL_REG;
92 bitnum TAG_VLAN_BIT;
93 bitnum ROUTER_EN_BIT;
94 bitnum NUMLAN_GROUPS_MAX;
95 bitnum NUMLAN_GROUPS_BIT;
96
97 reg MII_REGISTER_EN;
98 bitnum MII_REGISTER_EN_BIT;
99
100 // set to 1 for 178C, 0 for 175C.
101 bitnum SIMPLE_VLAN_REGISTERS; // 175C has two vlans per register but 178C has only one.
102
103 // Pointers to functions which manipulate hardware state
104 int (*update_state)(struct ip17xx_state *state);
105 int (*set_vlan_mode)(struct ip17xx_state *state);
106 int (*reset)(struct ip17xx_state *state);
107 };
108
109 static int ip175c_update_state(struct ip17xx_state *state);
110 static int ip175c_set_vlan_mode(struct ip17xx_state *state);
111 static int ip175c_reset(struct ip17xx_state *state);
112
113 static const struct register_mappings IP178C = {
114 .NAME = "IP178C",
115 .MODEL_NO = 0x18,
116 .VLAN_DEFAULT_TAG_REG = {
117 {30,3},{30,4},{30,5},{30,6},{30,7},{30,8},
118 {30,9},{30,10},{30,11},
119 },
120
121 .ADD_TAG_REG = {30,12},
122 .ADD_TAG_BIT = {0,1,2,3,4,5,6,7,8},
123 .REMOVE_TAG_REG = {30,13},
124 .REMOVE_TAG_BIT = {4,5,6,7,8,9,10,11,12},
125
126 .SIMPLE_VLAN_REGISTERS = 1,
127
128 .VLAN_LOOKUP_REG = {31,0},// +N
129 .VLAN_LOOKUP_REG_5 = NOTSUPPORTED, // not used with SIMPLE_VLAN_REGISTERS
130 .VLAN_LOOKUP_EVEN_BIT = {0,1,2,3,4,5,6,7,8},
131 .VLAN_LOOKUP_ODD_BIT = {0,1,2,3,4,5,6,7,8},
132
133 .TAG_VLAN_MASK_REG = {30,14}, // +N
134 .TAG_VLAN_MASK_EVEN_BIT = {0,1,2,3,4,5,6,7,8},
135 .TAG_VLAN_MASK_ODD_BIT = {0,1,2,3,4,5,6,7,8},
136
137 .RESET_VAL = 0x55AA,
138 .RESET_REG = {30,0},
139 .MODE_VAL = 0,
140 .MODE_REG = NOTSUPPORTED,
141
142 .ROUTER_CONTROL_REG = {30,30},
143 .ROUTER_EN_BIT = 11,
144 .NUMLAN_GROUPS_MAX = 8,
145 .NUMLAN_GROUPS_BIT = 8, // {0-2}
146
147 .VLAN_CONTROL_REG = {30,13},
148 .TAG_VLAN_BIT = 3,
149
150 .CPU_PORT = 8,
151 .NUM_PORTS = 9,
152
153 .MII_REGISTER_EN = NOTSUPPORTED,
154
155 .update_state = ip175c_update_state,
156 .set_vlan_mode = ip175c_set_vlan_mode,
157 .reset = ip175c_reset,
158 };
159
160 static const struct register_mappings IP175C = {
161 .NAME = "IP175C",
162 .MODEL_NO = 0x18,
163 .VLAN_DEFAULT_TAG_REG = {
164 {29,24},{29,25},{29,26},{29,27},{29,28},{29,30},
165 NOTSUPPORTED,NOTSUPPORTED,NOTSUPPORTED
166 },
167
168 .ADD_TAG_REG = {29,23},
169 .REMOVE_TAG_REG = {29,23},
170 .ADD_TAG_BIT = {11,12,13,14,15,1,-1,-1,-1},
171 .REMOVE_TAG_BIT = {6,7,8,9,10,0,-1,-1,-1},
172
173 .SIMPLE_VLAN_REGISTERS = 0,
174
175 .VLAN_LOOKUP_REG = {29,19},// +N/2
176 .VLAN_LOOKUP_REG_5 = {30,18},
177 .VLAN_LOOKUP_EVEN_BIT = {8,9,10,11,12,15,-1,-1,-1},
178 .VLAN_LOOKUP_ODD_BIT = {0,1,2,3,4,7,-1,-1,-1},
179
180 .TAG_VLAN_MASK_REG = {30,1}, // +N/2
181 .TAG_VLAN_MASK_EVEN_BIT = {0,1,2,3,4,5,-1,-1,-1},
182 .TAG_VLAN_MASK_ODD_BIT = {8,9,10,11,12,13,-1,-1,-1},
183
184 .RESET_VAL = 0x175C,
185 .RESET_REG = {30,0},
186 .MODE_VAL = 0x175C,
187 .MODE_REG = {29,31},
188
189 .ROUTER_CONTROL_REG = {30,9},
190 .ROUTER_EN_BIT = 3,
191 .NUMLAN_GROUPS_MAX = 8,
192 .NUMLAN_GROUPS_BIT = 0, // {0-2}
193
194 .VLAN_CONTROL_REG = {30,9},
195 .TAG_VLAN_BIT = 7,
196
197 .NUM_PORTS = 6,
198 .CPU_PORT = 5,
199
200 .MII_REGISTER_EN = NOTSUPPORTED,
201
202 .update_state = ip175c_update_state,
203 .set_vlan_mode = ip175c_set_vlan_mode,
204 .reset = ip175c_reset,
205 };
206
207 static const struct register_mappings IP175A = {
208 .NAME = "IP175A",
209 .MODEL_NO = 0x05,
210 .VLAN_DEFAULT_TAG_REG = {
211 {0,24},{0,25},{0,26},{0,27},{0,28},NOTSUPPORTED,
212 NOTSUPPORTED,NOTSUPPORTED,NOTSUPPORTED
213 },
214
215 .ADD_TAG_REG = {0,23},
216 .REMOVE_TAG_REG = {0,23},
217 .ADD_TAG_BIT = {11,12,13,14,15,-1,-1,-1,-1},
218 .REMOVE_TAG_BIT = {6,7,8,9,10,-1,-1,-1,-1},
219
220 .SIMPLE_VLAN_REGISTERS = 0,
221
222 // Only programmable via EEPROM
223 .VLAN_LOOKUP_REG = NOTSUPPORTED,// +N/2
224 .VLAN_LOOKUP_REG_5 = NOTSUPPORTED,
225 .VLAN_LOOKUP_EVEN_BIT = {8,9,10,11,12,-1,-1,-1,-1},
226 .VLAN_LOOKUP_ODD_BIT = {0,1,2,3,4,-1,-1,-1,-1},
227
228 .TAG_VLAN_MASK_REG = NOTSUPPORTED, // +N/2,
229 .TAG_VLAN_MASK_EVEN_BIT = {-1,-1,-1,-1,-1,-1,-1,-1,-1},
230 .TAG_VLAN_MASK_ODD_BIT = {-1,-1,-1,-1,-1,-1,-1,-1,-1},
231
232 .RESET_VAL = -1,
233 .RESET_REG = NOTSUPPORTED,
234 .MODE_VAL = 0,
235 .MODE_REG = NOTSUPPORTED,
236
237 .ROUTER_CONTROL_REG = NOTSUPPORTED,
238 .VLAN_CONTROL_REG = NOTSUPPORTED,
239 .TAG_VLAN_BIT = -1,
240 .ROUTER_EN_BIT = -1,
241 .NUMLAN_GROUPS_MAX = -1,
242 .NUMLAN_GROUPS_BIT = -1, // {0-2}
243
244 .NUM_PORTS = 5,
245 .CPU_PORT = 4,
246
247 .MII_REGISTER_EN = {0, 18},
248 .MII_REGISTER_EN_BIT = 7,
249
250 .update_state = ip175c_update_state,
251 .set_vlan_mode = ip175c_set_vlan_mode,
252 .reset = ip175c_reset,
253 };
254
255
256 static int ip175d_update_state(struct ip17xx_state *state);
257 static int ip175d_set_vlan_mode(struct ip17xx_state *state);
258 static int ip175d_reset(struct ip17xx_state *state);
259
260 static const struct register_mappings IP175D = {
261 .NAME = "IP175D",
262 .MODEL_NO = 0x18,
263
264 // The IP175D has a completely different interface, so we leave most
265 // of the registers undefined and switch to different code paths.
266
267 .VLAN_DEFAULT_TAG_REG = {
268 NOTSUPPORTED,NOTSUPPORTED,NOTSUPPORTED,NOTSUPPORTED,
269 NOTSUPPORTED,NOTSUPPORTED,NOTSUPPORTED,NOTSUPPORTED,
270 },
271
272 .ADD_TAG_REG = NOTSUPPORTED,
273 .REMOVE_TAG_REG = NOTSUPPORTED,
274
275 .SIMPLE_VLAN_REGISTERS = 0,
276
277 .VLAN_LOOKUP_REG = NOTSUPPORTED,
278 .VLAN_LOOKUP_REG_5 = NOTSUPPORTED,
279 .TAG_VLAN_MASK_REG = NOTSUPPORTED,
280
281 .RESET_VAL = 0x175D,
282 .RESET_REG = {20,2},
283 .MODE_REG = NOTSUPPORTED,
284
285 .ROUTER_CONTROL_REG = NOTSUPPORTED,
286 .ROUTER_EN_BIT = -1,
287 .NUMLAN_GROUPS_BIT = -1,
288
289 .VLAN_CONTROL_REG = NOTSUPPORTED,
290 .TAG_VLAN_BIT = -1,
291
292 .NUM_PORTS = 6,
293 .CPU_PORT = 5,
294
295 .MII_REGISTER_EN = NOTSUPPORTED,
296
297 .update_state = ip175d_update_state,
298 .set_vlan_mode = ip175d_set_vlan_mode,
299 .reset = ip175d_reset,
300 };
301
302 struct ip17xx_state {
303 struct switch_dev dev;
304 struct mii_bus *mii_bus;
305 bool registered;
306
307 int router_mode; // ROUTER_EN
308 int vlan_enabled; // TAG_VLAN_EN
309 struct port_state {
310 u16 pvid;
311 unsigned int shareports;
312 } ports[MAX_PORTS];
313 unsigned int add_tag;
314 unsigned int remove_tag;
315 int num_vlans;
316 struct vlan_state {
317 unsigned int ports;
318 unsigned int tag; // VLAN tag (IP175D only)
319 } vlans[MAX_VLANS];
320 const struct register_mappings *regs;
321 reg proc_mii; // phy/reg for the low level register access via swconfig
322
323 char buf[80];
324 };
325
326
327 static int ip_phy_read(struct ip17xx_state *state, int port, int reg)
328 {
329 int val = mdiobus_read(state->mii_bus, port, reg);
330 if (val < 0)
331 pr_warning("IP17xx: Unable to get MII register %d,%d: error %d\n", port, reg, -val);
332 #ifdef DUMP_MII_IO
333 else
334 pr_debug("IP17xx: Read MII(%d,%d) -> %04x\n", port, reg, val);
335 #endif
336 return val;
337 }
338
339 static int ip_phy_write(struct ip17xx_state *state, int port, int reg, u16 val)
340 {
341 int err;
342
343 #ifdef DUMP_MII_IO
344 pr_debug("IP17xx: Write MII(%d,%d) <- %04x\n", port, reg, val);
345 #endif
346 err = mdiobus_write(state->mii_bus, port, reg, val);
347 if (err < 0)
348 pr_warning("IP17xx: Unable to write MII register %d,%d: error %d\n", port, reg, -err);
349 return err;
350 }
351
352 static int ip_phy_write_masked(struct ip17xx_state *state, int port, int reg, unsigned int mask, unsigned int data)
353 {
354 int val = ip_phy_read(state, port, reg);
355 if (val < 0)
356 return 0;
357 return ip_phy_write(state, port, reg, (val & ~mask) | data);
358 }
359
360 static int getPhy(struct ip17xx_state *state, reg mii)
361 {
362 if (!REG_SUPP(mii))
363 return -EFAULT;
364 return ip_phy_read(state, mii.p, mii.m);
365 }
366
367 static int setPhy(struct ip17xx_state *state, reg mii, u16 value)
368 {
369 int err;
370
371 if (!REG_SUPP(mii))
372 return -EFAULT;
373 err = ip_phy_write(state, mii.p, mii.m, value);
374 if (err < 0)
375 return err;
376 mdelay(2);
377 getPhy(state, mii);
378 return 0;
379 }
380
381
382 /**
383 * These two macros are to simplify the mapping of logical bits to the bits in hardware.
384 * NOTE: these macros will return if there is an error!
385 */
386
387 #define GET_PORT_BITS(state, bits, addr, bit_lookup) \
388 do { \
389 int i, val = getPhy((state), (addr)); \
390 if (val < 0) \
391 return val; \
392 (bits) = 0; \
393 for (i = 0; i < MAX_PORTS; i++) { \
394 if ((bit_lookup)[i] == -1) continue; \
395 if (val & (1<<(bit_lookup)[i])) \
396 (bits) |= (1<<i); \
397 } \
398 } while (0)
399
400 #define SET_PORT_BITS(state, bits, addr, bit_lookup) \
401 do { \
402 int i, val = getPhy((state), (addr)); \
403 if (val < 0) \
404 return val; \
405 for (i = 0; i < MAX_PORTS; i++) { \
406 unsigned int newmask = ((bits)&(1<<i)); \
407 if ((bit_lookup)[i] == -1) continue; \
408 val &= ~(1<<(bit_lookup)[i]); \
409 val |= ((newmask>>i)<<(bit_lookup)[i]); \
410 } \
411 val = setPhy((state), (addr), val); \
412 if (val < 0) \
413 return val; \
414 } while (0)
415
416
417 static int get_model(struct ip17xx_state *state)
418 {
419 int id1, id2;
420 int oui_id, model_no, rev_no, chip_no;
421
422 id1 = ip_phy_read(state, 0, 2);
423 id2 = ip_phy_read(state, 0, 3);
424 oui_id = (id1 << 6) | ((id2 >> 10) & 0x3f);
425 model_no = (id2 >> 4) & 0x3f;
426 rev_no = id2 & 0xf;
427 pr_debug("IP17xx: Identified oui=%06x model=%02x rev=%X\n", oui_id, model_no, rev_no);
428
429 if (oui_id != 0x0090c3) // No other oui_id should have reached us anyway
430 return -ENODEV;
431
432 if (model_no == IP175A.MODEL_NO) {
433 state->regs = &IP175A;
434 } else if (model_no == IP175C.MODEL_NO) {
435 /*
436 * Several models share the same model_no:
437 * 178C has more PHYs, so we try whether the device responds to a read from PHY5
438 * 175D has a new chip ID register
439 * 175C has neither
440 */
441 if (ip_phy_read(state, 5, 2) == 0x0243) {
442 state->regs = &IP178C;
443 } else {
444 chip_no = ip_phy_read(state, 20, 0);
445 pr_debug("IP17xx: Chip ID register reads %04x\n", chip_no);
446 if (chip_no == 0x175d) {
447 state->regs = &IP175D;
448 } else {
449 state->regs = &IP175C;
450 }
451 }
452 } else {
453 pr_warning("IP17xx: Found an unknown IC+ switch with model number %02x, revision %X.\n", model_no, rev_no);
454 return -EPERM;
455 }
456 return 0;
457 }
458
459 /*** Low-level functions for the older models ***/
460
461 /** Only set vlan and router flags in the switch **/
462 static int ip175c_set_flags(struct ip17xx_state *state)
463 {
464 int val;
465
466 if (!REG_SUPP(state->regs->ROUTER_CONTROL_REG)) {
467 return 0;
468 }
469
470 val = getPhy(state, state->regs->ROUTER_CONTROL_REG);
471 if (val < 0) {
472 return val;
473 }
474 if (state->regs->ROUTER_EN_BIT >= 0) {
475 if (state->router_mode) {
476 val |= (1<<state->regs->ROUTER_EN_BIT);
477 } else {
478 val &= (~(1<<state->regs->ROUTER_EN_BIT));
479 }
480 }
481 if (state->regs->TAG_VLAN_BIT >= 0) {
482 if (state->vlan_enabled) {
483 val |= (1<<state->regs->TAG_VLAN_BIT);
484 } else {
485 val &= (~(1<<state->regs->TAG_VLAN_BIT));
486 }
487 }
488 if (state->regs->NUMLAN_GROUPS_BIT >= 0) {
489 val &= (~((state->regs->NUMLAN_GROUPS_MAX-1)<<state->regs->NUMLAN_GROUPS_BIT));
490 if (state->num_vlans > state->regs->NUMLAN_GROUPS_MAX) {
491 val |= state->regs->NUMLAN_GROUPS_MAX << state->regs->NUMLAN_GROUPS_BIT;
492 } else if (state->num_vlans >= 1) {
493 val |= (state->num_vlans-1) << state->regs->NUMLAN_GROUPS_BIT;
494 }
495 }
496 return setPhy(state, state->regs->ROUTER_CONTROL_REG, val);
497 }
498
499 /** Set all VLAN and port state. Usually you should call "correct_vlan_state" first. **/
500 static int ip175c_set_state(struct ip17xx_state *state)
501 {
502 int j;
503 int i;
504 SET_PORT_BITS(state, state->add_tag,
505 state->regs->ADD_TAG_REG, state->regs->ADD_TAG_BIT);
506 SET_PORT_BITS(state, state->remove_tag,
507 state->regs->REMOVE_TAG_REG, state->regs->REMOVE_TAG_BIT);
508
509 if (REG_SUPP(state->regs->VLAN_LOOKUP_REG)) {
510 for (j=0; j<state->regs->NUM_PORTS; j++) {
511 reg addr;
512 const bitnum *bit_lookup = (j%2==0)?
513 state->regs->VLAN_LOOKUP_EVEN_BIT:
514 state->regs->VLAN_LOOKUP_ODD_BIT;
515
516 addr = state->regs->VLAN_LOOKUP_REG;
517 if (state->regs->SIMPLE_VLAN_REGISTERS) {
518 addr.m += j;
519 } else {
520 switch (j) {
521 case 0:
522 case 1:
523 break;
524 case 2:
525 case 3:
526 addr.m+=1;
527 break;
528 case 4:
529 addr.m+=2;
530 break;
531 case 5:
532 addr = state->regs->VLAN_LOOKUP_REG_5;
533 break;
534 default:
535 addr.m = -1; // shouldn't get here, but...
536 break;
537 }
538 }
539 //printf("shareports for %d is %02X\n",j,state->ports[j].shareports);
540 if (REG_SUPP(addr)) {
541 SET_PORT_BITS(state, state->ports[j].shareports, addr, bit_lookup);
542 }
543 }
544 }
545 if (REG_SUPP(state->regs->TAG_VLAN_MASK_REG)) {
546 for (j=0; j<MAX_VLANS; j++) {
547 reg addr = state->regs->TAG_VLAN_MASK_REG;
548 const bitnum *bit_lookup = (j%2==0)?
549 state->regs->TAG_VLAN_MASK_EVEN_BIT:
550 state->regs->TAG_VLAN_MASK_ODD_BIT;
551 unsigned int vlan_mask;
552 if (state->regs->SIMPLE_VLAN_REGISTERS) {
553 addr.m += j;
554 } else {
555 addr.m += j/2;
556 }
557 vlan_mask = state->vlans[j].ports;
558 SET_PORT_BITS(state, vlan_mask, addr, bit_lookup);
559 }
560 }
561
562 for (i=0; i<MAX_PORTS; i++) {
563 if (REG_SUPP(state->regs->VLAN_DEFAULT_TAG_REG[i])) {
564 int err = setPhy(state, state->regs->VLAN_DEFAULT_TAG_REG[i],
565 state->ports[i].pvid);
566 if (err < 0) {
567 return err;
568 }
569 }
570 }
571
572 return ip175c_set_flags(state);
573 }
574
575 /**
576 * Uses only the VLAN port mask and the add tag mask to generate the other fields:
577 * which ports are part of the same VLAN, removing vlan tags, and VLAN tag ids.
578 */
579 static void ip175c_correct_vlan_state(struct ip17xx_state *state)
580 {
581 int i, j;
582 state->num_vlans = 0;
583 for (i=0; i<MAX_VLANS; i++) {
584 if (state->vlans[i].ports != 0) {
585 state->num_vlans = i+1; // Hack -- we need to store the "set" vlans somewhere...
586 }
587 }
588
589 for (i=0; i<state->regs->NUM_PORTS; i++) {
590 unsigned int portmask = (1<<i);
591 if (!state->vlan_enabled) {
592 // Share with everybody!
593 state->ports[i].shareports = (1<<state->regs->NUM_PORTS)-1;
594 continue;
595 }
596 state->ports[i].shareports = portmask;
597 for (j=0; j<MAX_VLANS; j++) {
598 if (state->vlans[j].ports & portmask)
599 state->ports[i].shareports |= state->vlans[j].ports;
600 }
601 }
602 }
603
604 static int ip175c_update_state(struct ip17xx_state *state)
605 {
606 ip175c_correct_vlan_state(state);
607 return ip175c_set_state(state);
608 }
609
610 static int ip175c_set_vlan_mode(struct ip17xx_state *state)
611 {
612 return ip175c_update_state(state);
613 }
614
615 static int ip175c_reset(struct ip17xx_state *state)
616 {
617 int err;
618
619 if (REG_SUPP(state->regs->MODE_REG)) {
620 err = setPhy(state, state->regs->MODE_REG, state->regs->MODE_VAL);
621 if (err < 0)
622 return err;
623 err = getPhy(state, state->regs->MODE_REG);
624 if (err < 0)
625 return err;
626 }
627
628 return ip175c_update_state(state);
629 }
630
631 /*** Low-level functions for IP175D ***/
632
633 static int ip175d_update_state(struct ip17xx_state *state)
634 {
635 unsigned int filter_mask = 0;
636 unsigned int ports[16], add[16], rem[16];
637 int i, j;
638 int err = 0;
639
640 for (i = 0; i < 16; i++) {
641 ports[i] = 0;
642 add[i] = 0;
643 rem[i] = 0;
644 if (!state->vlan_enabled) {
645 err |= ip_phy_write(state, 22, 14+i, i+1); // default tags
646 ports[i] = 0x3f;
647 continue;
648 }
649 if (!state->vlans[i].tag) {
650 // Reset the filter
651 err |= ip_phy_write(state, 22, 14+i, 0); // tag
652 continue;
653 }
654 filter_mask |= 1 << i;
655 err |= ip_phy_write(state, 22, 14+i, state->vlans[i].tag);
656 ports[i] = state->vlans[i].ports;
657 for (j = 0; j < 6; j++) {
658 if (ports[i] & (1 << j)) {
659 if (state->add_tag & (1 << j))
660 add[i] |= 1 << j;
661 if (state->remove_tag & (1 << j))
662 rem[i] |= 1 << j;
663 }
664 }
665 }
666
667 // Port masks, tag adds and removals
668 for (i = 0; i < 8; i++) {
669 err |= ip_phy_write(state, 23, i, ports[2*i] | (ports[2*i+1] << 8));
670 err |= ip_phy_write(state, 23, 8+i, add[2*i] | (add[2*i+1] << 8));
671 err |= ip_phy_write(state, 23, 16+i, rem[2*i] | (rem[2*i+1] << 8));
672 }
673 err |= ip_phy_write(state, 22, 10, filter_mask);
674
675 // Default VLAN tag for each port
676 for (i = 0; i < 6; i++)
677 err |= ip_phy_write(state, 22, 4+i, state->vlans[state->ports[i].pvid].tag);
678
679 return (err ? -EIO : 0);
680 }
681
682 static int ip175d_set_vlan_mode(struct ip17xx_state *state)
683 {
684 int i;
685 int err = 0;
686
687 if (state->vlan_enabled) {
688 // VLAN classification rules: tag-based VLANs, use VID to classify,
689 // drop packets that cannot be classified.
690 err |= ip_phy_write_masked(state, 22, 0, 0x3fff, 0x003f);
691
692 // Ingress rules: CFI=1 dropped, null VID is untagged, VID=1 passed,
693 // VID=0xfff discarded, admin both tagged and untagged, ingress
694 // filters enabled.
695 err |= ip_phy_write_masked(state, 22, 1, 0x0fff, 0x0c3f);
696
697 // Egress rules: IGMP processing off, keep VLAN header off
698 err |= ip_phy_write_masked(state, 22, 2, 0x0fff, 0x0000);
699 } else {
700 // VLAN classification rules: everything off & clear table
701 err |= ip_phy_write_masked(state, 22, 0, 0xbfff, 0x8000);
702
703 // Ingress and egress rules: set to defaults
704 err |= ip_phy_write_masked(state, 22, 1, 0x0fff, 0x0c3f);
705 err |= ip_phy_write_masked(state, 22, 2, 0x0fff, 0x0000);
706 }
707
708 // Reset default VLAN for each port to 0
709 for (i = 0; i < 6; i++)
710 state->ports[i].pvid = 0;
711
712 err |= ip175d_update_state(state);
713
714 return (err ? -EIO : 0);
715 }
716
717 static int ip175d_reset(struct ip17xx_state *state)
718 {
719 int err = 0;
720
721 // Disable the special tagging mode
722 err |= ip_phy_write_masked(state, 21, 22, 0x0003, 0x0000);
723
724 // Set 802.1q protocol type
725 err |= ip_phy_write(state, 22, 3, 0x8100);
726
727 state->vlan_enabled = 0;
728 err |= ip175d_set_vlan_mode(state);
729
730 return (err ? -EIO : 0);
731 }
732
733 /*** High-level functions ***/
734
735 static int ip17xx_get_enable_vlan(struct switch_dev *dev, const struct switch_attr *attr, struct switch_val *val)
736 {
737 struct ip17xx_state *state = dev->priv;
738
739 val->value.i = state->vlan_enabled;
740 return 0;
741 }
742
743 static void ip17xx_reset_vlan_config(struct ip17xx_state *state)
744 {
745 int i;
746
747 state->remove_tag = (state->vlan_enabled ? ((1<<state->regs->NUM_PORTS)-1) : 0x0000);
748 state->add_tag = 0x0000;
749 for (i = 0; i < MAX_VLANS; i++) {
750 state->vlans[i].ports = 0x0000;
751 state->vlans[i].tag = (i ? i : 16);
752 }
753 for (i = 0; i < MAX_PORTS; i++)
754 state->ports[i].pvid = 0;
755 }
756
757 static int ip17xx_set_enable_vlan(struct switch_dev *dev, const struct switch_attr *attr, struct switch_val *val)
758 {
759 struct ip17xx_state *state = dev->priv;
760 int enable;
761
762 enable = val->value.i;
763 if (state->vlan_enabled == enable) {
764 // Do not change any state.
765 return 0;
766 }
767 state->vlan_enabled = enable;
768
769 // Otherwise, if we are switching state, set fields to a known default.
770 ip17xx_reset_vlan_config(state);
771
772 return state->regs->set_vlan_mode(state);
773 }
774
775 static int ip17xx_get_ports(struct switch_dev *dev, struct switch_val *val)
776 {
777 struct ip17xx_state *state = dev->priv;
778 int b;
779 int ind;
780 unsigned int ports;
781
782 if (val->port_vlan >= dev->vlans || val->port_vlan < 0)
783 return -EINVAL;
784
785 ports = state->vlans[val->port_vlan].ports;
786 b = 0;
787 ind = 0;
788 while (b < MAX_PORTS) {
789 if (ports&1) {
790 int istagged = ((state->add_tag >> b) & 1);
791 val->value.ports[ind].id = b;
792 val->value.ports[ind].flags = (istagged << SWITCH_PORT_FLAG_TAGGED);
793 ind++;
794 }
795 b++;
796 ports >>= 1;
797 }
798 val->len = ind;
799
800 return 0;
801 }
802
803 static int ip17xx_set_ports(struct switch_dev *dev, struct switch_val *val)
804 {
805 struct ip17xx_state *state = dev->priv;
806 int i;
807
808 if (val->port_vlan >= dev->vlans || val->port_vlan < 0)
809 return -EINVAL;
810
811 state->vlans[val->port_vlan].ports = 0;
812 for (i = 0; i < val->len; i++) {
813 unsigned int bitmask = (1<<val->value.ports[i].id);
814 state->vlans[val->port_vlan].ports |= bitmask;
815 if (val->value.ports[i].flags & (1<<SWITCH_PORT_FLAG_TAGGED)) {
816 state->add_tag |= bitmask;
817 state->remove_tag &= (~bitmask);
818 } else {
819 state->add_tag &= (~bitmask);
820 state->remove_tag |= bitmask;
821 }
822 }
823
824 return state->regs->update_state(state);
825 }
826
827 static int ip17xx_apply(struct switch_dev *dev)
828 {
829 struct ip17xx_state *state = dev->priv;
830
831 if (REG_SUPP(state->regs->MII_REGISTER_EN)) {
832 int val = getPhy(state, state->regs->MII_REGISTER_EN);
833 if (val < 0) {
834 return val;
835 }
836 val |= (1<<state->regs->MII_REGISTER_EN_BIT);
837 return setPhy(state, state->regs->MII_REGISTER_EN, val);
838 }
839 return 0;
840 }
841
842 static int ip17xx_reset(struct switch_dev *dev)
843 {
844 struct ip17xx_state *state = dev->priv;
845 int i, err;
846
847 if (REG_SUPP(state->regs->RESET_REG)) {
848 err = setPhy(state, state->regs->RESET_REG, state->regs->RESET_VAL);
849 if (err < 0)
850 return err;
851 err = getPhy(state, state->regs->RESET_REG);
852
853 /*
854 * Data sheet specifies reset period to be 2 msec.
855 * (I don't see any mention of the 2ms delay in the IP178C spec, only
856 * in IP175C, but it can't hurt.)
857 */
858 mdelay(2);
859 }
860
861 /* reset switch ports */
862 for (i = 0; i < state->regs->NUM_PORTS-1; i++) {
863 err = ip_phy_write(state, i, MII_BMCR, BMCR_RESET);
864 if (err < 0)
865 return err;
866 }
867
868 state->router_mode = 0;
869 state->vlan_enabled = 0;
870 ip17xx_reset_vlan_config(state);
871
872 return state->regs->reset(state);
873 }
874
875 static int ip17xx_get_tagged(struct switch_dev *dev, const struct switch_attr *attr, struct switch_val *val)
876 {
877 struct ip17xx_state *state = dev->priv;
878
879 if (state->add_tag & (1<<val->port_vlan)) {
880 if (state->remove_tag & (1<<val->port_vlan))
881 val->value.i = 3; // shouldn't ever happen.
882 else
883 val->value.i = 1;
884 } else {
885 if (state->remove_tag & (1<<val->port_vlan))
886 val->value.i = 0;
887 else
888 val->value.i = 2;
889 }
890 return 0;
891 }
892
893 static int ip17xx_set_tagged(struct switch_dev *dev, const struct switch_attr *attr, struct switch_val *val)
894 {
895 struct ip17xx_state *state = dev->priv;
896
897 state->add_tag &= ~(1<<val->port_vlan);
898 state->remove_tag &= ~(1<<val->port_vlan);
899
900 if (val->value.i == 0)
901 state->remove_tag |= (1<<val->port_vlan);
902 if (val->value.i == 1)
903 state->add_tag |= (1<<val->port_vlan);
904
905 return state->regs->update_state(state);
906 }
907
908 /** Get the current phy address */
909 static int ip17xx_get_phy(struct switch_dev *dev, const struct switch_attr *attr, struct switch_val *val)
910 {
911 struct ip17xx_state *state = dev->priv;
912
913 val->value.i = state->proc_mii.p;
914 return 0;
915 }
916
917 /** Set a new phy address for low level access to registers */
918 static int ip17xx_set_phy(struct switch_dev *dev, const struct switch_attr *attr, struct switch_val *val)
919 {
920 struct ip17xx_state *state = dev->priv;
921 int new_reg = val->value.i;
922
923 if (new_reg < 0 || new_reg > 31)
924 state->proc_mii.p = (u16)-1;
925 else
926 state->proc_mii.p = (u16)new_reg;
927 return 0;
928 }
929
930 /** Get the current register number */
931 static int ip17xx_get_reg(struct switch_dev *dev, const struct switch_attr *attr, struct switch_val *val)
932 {
933 struct ip17xx_state *state = dev->priv;
934
935 val->value.i = state->proc_mii.m;
936 return 0;
937 }
938
939 /** Set a new register address for low level access to registers */
940 static int ip17xx_set_reg(struct switch_dev *dev, const struct switch_attr *attr, struct switch_val *val)
941 {
942 struct ip17xx_state *state = dev->priv;
943 int new_reg = val->value.i;
944
945 if (new_reg < 0 || new_reg > 31)
946 state->proc_mii.m = (u16)-1;
947 else
948 state->proc_mii.m = (u16)new_reg;
949 return 0;
950 }
951
952 /** Get the register content of state->proc_mii */
953 static int ip17xx_get_val(struct switch_dev *dev, const struct switch_attr *attr, struct switch_val *val)
954 {
955 struct ip17xx_state *state = dev->priv;
956 int retval = -EINVAL;
957 if (REG_SUPP(state->proc_mii))
958 retval = getPhy(state, state->proc_mii);
959
960 if (retval < 0) {
961 return retval;
962 } else {
963 val->value.i = retval;
964 return 0;
965 }
966 }
967
968 /** Write a value to the register defined by phy/reg above */
969 static int ip17xx_set_val(struct switch_dev *dev, const struct switch_attr *attr, struct switch_val *val)
970 {
971 struct ip17xx_state *state = dev->priv;
972 int myval, err = -EINVAL;
973
974 myval = val->value.i;
975 if (myval <= 0xffff && myval >= 0 && REG_SUPP(state->proc_mii)) {
976 err = setPhy(state, state->proc_mii, (u16)myval);
977 }
978 return err;
979 }
980
981 static int ip17xx_read_name(struct switch_dev *dev, const struct switch_attr *attr, struct switch_val *val)
982 {
983 struct ip17xx_state *state = dev->priv;
984 val->value.s = state->regs->NAME; // Just a const pointer, won't be freed by swconfig.
985 return 0;
986 }
987
988 static int ip17xx_get_tag(struct switch_dev *dev, const struct switch_attr *attr, struct switch_val *val)
989 {
990 struct ip17xx_state *state = dev->priv;
991 int vlan = val->port_vlan;
992
993 if (vlan < 0 || vlan >= MAX_VLANS)
994 return -EINVAL;
995
996 val->value.i = state->vlans[vlan].tag;
997 return 0;
998 }
999
1000 static int ip17xx_set_tag(struct switch_dev *dev, const struct switch_attr *attr, struct switch_val *val)
1001 {
1002 struct ip17xx_state *state = dev->priv;
1003 int vlan = val->port_vlan;
1004 int tag = val->value.i;
1005
1006 if (vlan < 0 || vlan >= MAX_VLANS)
1007 return -EINVAL;
1008
1009 if (tag < 0 || tag > 4095)
1010 return -EINVAL;
1011
1012 state->vlans[vlan].tag = tag;
1013 return state->regs->update_state(state);
1014 }
1015
1016 static int ip17xx_set_port_speed(struct switch_dev *dev, const struct switch_attr *attr, struct switch_val *val)
1017 {
1018 struct ip17xx_state *state = dev->priv;
1019 int nr = val->port_vlan;
1020 int ctrl;
1021 int autoneg;
1022 int speed;
1023 if (val->value.i == 100) {
1024 speed = 1;
1025 autoneg = 0;
1026 } else if (val->value.i == 10) {
1027 speed = 0;
1028 autoneg = 0;
1029 } else {
1030 autoneg = 1;
1031 speed = 1;
1032 }
1033
1034 /* Can't set speed for cpu port */
1035 if (nr == state->regs->CPU_PORT)
1036 return -EINVAL;
1037
1038 if (nr >= dev->ports || nr < 0)
1039 return -EINVAL;
1040
1041 ctrl = ip_phy_read(state, nr, 0);
1042 if (ctrl < 0)
1043 return -EIO;
1044
1045 ctrl &= (~(1<<12));
1046 ctrl &= (~(1<<13));
1047 ctrl |= (autoneg<<12);
1048 ctrl |= (speed<<13);
1049
1050 return ip_phy_write(state, nr, 0, ctrl);
1051 }
1052
1053 static int ip17xx_get_port_speed(struct switch_dev *dev, const struct switch_attr *attr, struct switch_val *val)
1054 {
1055 struct ip17xx_state *state = dev->priv;
1056 int nr = val->port_vlan;
1057 int speed, status;
1058
1059 if (nr == state->regs->CPU_PORT) {
1060 val->value.i = 100;
1061 return 0;
1062 }
1063
1064 if (nr >= dev->ports || nr < 0)
1065 return -EINVAL;
1066
1067 status = ip_phy_read(state, nr, 1);
1068 speed = ip_phy_read(state, nr, 18);
1069 if (status < 0 || speed < 0)
1070 return -EIO;
1071
1072 if (status & 4)
1073 val->value.i = ((speed & (1<<11)) ? 100 : 10);
1074 else
1075 val->value.i = 0;
1076
1077 return 0;
1078 }
1079
1080 static int ip17xx_get_port_status(struct switch_dev *dev, const struct switch_attr *attr, struct switch_val *val)
1081 {
1082 struct ip17xx_state *state = dev->priv;
1083 int ctrl, speed, status;
1084 int nr = val->port_vlan;
1085 int len;
1086 char *buf = state->buf; // fixed-length at 80.
1087
1088 if (nr == state->regs->CPU_PORT) {
1089 sprintf(buf, "up, 100 Mbps, cpu port");
1090 val->value.s = buf;
1091 return 0;
1092 }
1093
1094 if (nr >= dev->ports || nr < 0)
1095 return -EINVAL;
1096
1097 ctrl = ip_phy_read(state, nr, 0);
1098 status = ip_phy_read(state, nr, 1);
1099 speed = ip_phy_read(state, nr, 18);
1100 if (ctrl < 0 || status < 0 || speed < 0)
1101 return -EIO;
1102
1103 if (status & 4)
1104 len = sprintf(buf, "up, %d Mbps, %s duplex",
1105 ((speed & (1<<11)) ? 100 : 10),
1106 ((speed & (1<<10)) ? "full" : "half"));
1107 else
1108 len = sprintf(buf, "down");
1109
1110 if (ctrl & (1<<12)) {
1111 len += sprintf(buf+len, ", auto-negotiate");
1112 if (!(status & (1<<5)))
1113 len += sprintf(buf+len, " (in progress)");
1114 } else {
1115 len += sprintf(buf+len, ", fixed speed (%d)",
1116 ((ctrl & (1<<13)) ? 100 : 10));
1117 }
1118
1119 buf[len] = '\0';
1120 val->value.s = buf;
1121 return 0;
1122 }
1123
1124 static int ip17xx_get_pvid(struct switch_dev *dev, int port, int *val)
1125 {
1126 struct ip17xx_state *state = dev->priv;
1127
1128 *val = state->ports[port].pvid;
1129 return 0;
1130 }
1131
1132 static int ip17xx_set_pvid(struct switch_dev *dev, int port, int val)
1133 {
1134 struct ip17xx_state *state = dev->priv;
1135
1136 if (val < 0 || val >= MAX_VLANS)
1137 return -EINVAL;
1138
1139 state->ports[port].pvid = val;
1140 return state->regs->update_state(state);
1141 }
1142
1143
1144 enum Ports {
1145 IP17XX_PORT_STATUS,
1146 IP17XX_PORT_LINK,
1147 IP17XX_PORT_TAGGED,
1148 IP17XX_PORT_PVID,
1149 };
1150
1151 enum Globals {
1152 IP17XX_ENABLE_VLAN,
1153 IP17XX_GET_NAME,
1154 IP17XX_REGISTER_PHY,
1155 IP17XX_REGISTER_MII,
1156 IP17XX_REGISTER_VALUE,
1157 IP17XX_REGISTER_ERRNO,
1158 };
1159
1160 enum Vlans {
1161 IP17XX_VLAN_TAG,
1162 };
1163
1164 static const struct switch_attr ip17xx_global[] = {
1165 [IP17XX_ENABLE_VLAN] = {
1166 .id = IP17XX_ENABLE_VLAN,
1167 .type = SWITCH_TYPE_INT,
1168 .name = "enable_vlan",
1169 .description = "Flag to enable or disable VLANs and tagging",
1170 .get = ip17xx_get_enable_vlan,
1171 .set = ip17xx_set_enable_vlan,
1172 },
1173 [IP17XX_GET_NAME] = {
1174 .id = IP17XX_GET_NAME,
1175 .type = SWITCH_TYPE_STRING,
1176 .description = "Returns the type of IC+ chip.",
1177 .name = "name",
1178 .get = ip17xx_read_name,
1179 .set = NULL,
1180 },
1181 /* jal: added for low level debugging etc. */
1182 [IP17XX_REGISTER_PHY] = {
1183 .id = IP17XX_REGISTER_PHY,
1184 .type = SWITCH_TYPE_INT,
1185 .description = "Direct register access: set PHY (0-4, or 29,30,31)",
1186 .name = "phy",
1187 .get = ip17xx_get_phy,
1188 .set = ip17xx_set_phy,
1189 },
1190 [IP17XX_REGISTER_MII] = {
1191 .id = IP17XX_REGISTER_MII,
1192 .type = SWITCH_TYPE_INT,
1193 .description = "Direct register access: set MII register number (0-31)",
1194 .name = "reg",
1195 .get = ip17xx_get_reg,
1196 .set = ip17xx_set_reg,
1197 },
1198 [IP17XX_REGISTER_VALUE] = {
1199 .id = IP17XX_REGISTER_VALUE,
1200 .type = SWITCH_TYPE_INT,
1201 .description = "Direct register access: read/write to register (0-65535)",
1202 .name = "val",
1203 .get = ip17xx_get_val,
1204 .set = ip17xx_set_val,
1205 },
1206 };
1207
1208 static const struct switch_attr ip17xx_vlan[] = {
1209 [IP17XX_VLAN_TAG] = {
1210 .id = IP17XX_VLAN_TAG,
1211 .type = SWITCH_TYPE_INT,
1212 .description = "VLAN tag (0-4095) [IP175D only]",
1213 .name = "tag",
1214 .get = ip17xx_get_tag,
1215 .set = ip17xx_set_tag,
1216 }
1217 };
1218
1219 static const struct switch_attr ip17xx_port[] = {
1220 [IP17XX_PORT_STATUS] = {
1221 .id = IP17XX_PORT_STATUS,
1222 .type = SWITCH_TYPE_STRING,
1223 .description = "Returns Detailed port status",
1224 .name = "status",
1225 .get = ip17xx_get_port_status,
1226 .set = NULL,
1227 },
1228 [IP17XX_PORT_LINK] = {
1229 .id = IP17XX_PORT_LINK,
1230 .type = SWITCH_TYPE_INT,
1231 .description = "Link speed. Can write 0 for auto-negotiate, or 10 or 100",
1232 .name = "link",
1233 .get = ip17xx_get_port_speed,
1234 .set = ip17xx_set_port_speed,
1235 },
1236 [IP17XX_PORT_TAGGED] = {
1237 .id = IP17XX_PORT_LINK,
1238 .type = SWITCH_TYPE_INT,
1239 .description = "0 = untag, 1 = add tags, 2 = do not alter (This value is reset if vlans are altered)",
1240 .name = "tagged",
1241 .get = ip17xx_get_tagged,
1242 .set = ip17xx_set_tagged,
1243 },
1244 };
1245
1246 static int ip17xx_probe(struct phy_device *pdev)
1247 {
1248 struct ip17xx_state *state;
1249 struct switch_dev *dev;
1250 int err;
1251
1252 /* We only attach to PHY 0, but use all available PHYs */
1253 if (pdev->addr != 0)
1254 return -ENODEV;
1255
1256 state = kzalloc(sizeof(*state), GFP_KERNEL);
1257 if (!state)
1258 return -ENOMEM;
1259
1260 dev = &state->dev;
1261 dev->attr_global.attr = ip17xx_global;
1262 dev->attr_global.n_attr = ARRAY_SIZE(ip17xx_global);
1263 dev->attr_port.attr = ip17xx_port;
1264 dev->attr_port.n_attr = ARRAY_SIZE(ip17xx_port);
1265 dev->attr_vlan.attr = ip17xx_vlan;
1266 dev->attr_vlan.n_attr = ARRAY_SIZE(ip17xx_vlan);
1267
1268 dev->get_port_pvid = ip17xx_get_pvid;
1269 dev->set_port_pvid = ip17xx_set_pvid;
1270 dev->get_vlan_ports = ip17xx_get_ports;
1271 dev->set_vlan_ports = ip17xx_set_ports;
1272 dev->apply_config = ip17xx_apply;
1273 dev->reset_switch = ip17xx_reset;
1274
1275 dev->priv = state;
1276 pdev->priv = state;
1277 state->mii_bus = pdev->bus;
1278
1279 err = get_model(state);
1280 if (err < 0)
1281 goto error;
1282
1283 dev->vlans = MAX_VLANS;
1284 dev->cpu_port = state->regs->CPU_PORT;
1285 dev->ports = state->regs->NUM_PORTS;
1286 dev->name = state->regs->NAME;
1287
1288 pr_info("IP17xx: Found %s at %s\n", dev->name, dev_name(&pdev->dev));
1289 return 0;
1290
1291 error:
1292 kfree(state);
1293 return err;
1294 }
1295
1296 static int ip17xx_config_init(struct phy_device *pdev)
1297 {
1298 struct ip17xx_state *state = pdev->priv;
1299 struct net_device *dev = pdev->attached_dev;
1300 int err;
1301
1302 err = register_switch(&state->dev, dev);
1303 if (err < 0)
1304 return err;
1305
1306 state->registered = true;
1307 ip17xx_reset(&state->dev);
1308 return 0;
1309 }
1310
1311 static void ip17xx_remove(struct phy_device *pdev)
1312 {
1313 struct ip17xx_state *state = pdev->priv;
1314
1315 if (state->registered)
1316 unregister_switch(&state->dev);
1317 kfree(state);
1318 }
1319
1320 static int ip17xx_config_aneg(struct phy_device *pdev)
1321 {
1322 return 0;
1323 }
1324
1325 static int ip17xx_aneg_done(struct phy_device *pdev)
1326 {
1327 return BMSR_ANEGCOMPLETE;
1328 }
1329
1330 static int ip17xx_update_link(struct phy_device *pdev)
1331 {
1332 pdev->link = 1;
1333 return 0;
1334 }
1335
1336 static int ip17xx_read_status(struct phy_device *pdev)
1337 {
1338 pdev->speed = SPEED_100;
1339 pdev->duplex = DUPLEX_FULL;
1340 pdev->pause = pdev->asym_pause = 0;
1341 pdev->link = 1;
1342
1343 return 0;
1344 }
1345
1346 static struct phy_driver ip17xx_driver = {
1347 .name = "IC+ IP17xx",
1348 .phy_id = 0x02430c00,
1349 .phy_id_mask = 0x0ffffc00,
1350 .features = PHY_BASIC_FEATURES,
1351 .probe = ip17xx_probe,
1352 .remove = ip17xx_remove,
1353 .config_init = ip17xx_config_init,
1354 .config_aneg = ip17xx_config_aneg,
1355 .aneg_done = ip17xx_aneg_done,
1356 .update_link = ip17xx_update_link,
1357 .read_status = ip17xx_read_status,
1358 .driver = { .owner = THIS_MODULE },
1359 };
1360
1361 static struct phy_driver ip175a_driver = {
1362 .name = "IC+ IP175A",
1363 .phy_id = 0x02430c50,
1364 .phy_id_mask = 0x0ffffff0,
1365 .features = PHY_BASIC_FEATURES,
1366 .probe = ip17xx_probe,
1367 .remove = ip17xx_remove,
1368 .config_init = ip17xx_config_init,
1369 .config_aneg = ip17xx_config_aneg,
1370 .aneg_done = ip17xx_aneg_done,
1371 .update_link = ip17xx_update_link,
1372 .read_status = ip17xx_read_status,
1373 .driver = { .owner = THIS_MODULE },
1374 };
1375
1376
1377 int __init ip17xx_init(void)
1378 {
1379 int ret;
1380
1381 ret = phy_driver_register(&ip175a_driver);
1382 if (ret < 0)
1383 return ret;
1384
1385 return phy_driver_register(&ip17xx_driver);
1386 }
1387
1388 void __exit ip17xx_exit(void)
1389 {
1390 phy_driver_unregister(&ip17xx_driver);
1391 phy_driver_unregister(&ip175a_driver);
1392 }
1393
1394 MODULE_AUTHOR("Patrick Horn <patrick.horn@gmail.com>");
1395 MODULE_AUTHOR("Felix Fietkau <nbd@openwrt.org>");
1396 MODULE_AUTHOR("Martin Mares <mj@ucw.cz>");
1397 MODULE_LICENSE("GPL");
1398
1399 module_init(ip17xx_init);
1400 module_exit(ip17xx_exit);
This page took 0.103468 seconds and 3 git commands to generate.