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