rename target/linux/generic-2.6 to generic
[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 getPhy(state, mii);
377 return 0;
378 }
379
380
381 /**
382 * These two macros are to simplify the mapping of logical bits to the bits in hardware.
383 * NOTE: these macros will return if there is an error!
384 */
385
386 #define GET_PORT_BITS(state, bits, addr, bit_lookup) \
387 do { \
388 int i, val = getPhy((state), (addr)); \
389 if (val < 0) \
390 return val; \
391 (bits) = 0; \
392 for (i = 0; i < MAX_PORTS; i++) { \
393 if ((bit_lookup)[i] == -1) continue; \
394 if (val & (1<<(bit_lookup)[i])) \
395 (bits) |= (1<<i); \
396 } \
397 } while (0)
398
399 #define SET_PORT_BITS(state, bits, addr, bit_lookup) \
400 do { \
401 int i, val = getPhy((state), (addr)); \
402 if (val < 0) \
403 return val; \
404 for (i = 0; i < MAX_PORTS; i++) { \
405 unsigned int newmask = ((bits)&(1<<i)); \
406 if ((bit_lookup)[i] == -1) continue; \
407 val &= ~(1<<(bit_lookup)[i]); \
408 val |= ((newmask>>i)<<(bit_lookup)[i]); \
409 } \
410 val = setPhy((state), (addr), val); \
411 if (val < 0) \
412 return val; \
413 } while (0)
414
415
416 static int get_model(struct ip17xx_state *state)
417 {
418 int id1, id2;
419 int oui_id, model_no, rev_no, chip_no;
420
421 id1 = ip_phy_read(state, 0, 2);
422 id2 = ip_phy_read(state, 0, 3);
423 oui_id = (id1 << 6) | ((id2 >> 10) & 0x3f);
424 model_no = (id2 >> 4) & 0x3f;
425 rev_no = id2 & 0xf;
426 pr_debug("IP17xx: Identified oui=%06x model=%02x rev=%X\n", oui_id, model_no, rev_no);
427
428 if (oui_id != 0x0090c3) // No other oui_id should have reached us anyway
429 return -ENODEV;
430
431 if (model_no == IP175A.MODEL_NO) {
432 state->regs = &IP175A;
433 } else if (model_no == IP175C.MODEL_NO) {
434 /*
435 * Several models share the same model_no:
436 * 178C has more PHYs, so we try whether the device responds to a read from PHY5
437 * 175D has a new chip ID register
438 * 175C has neither
439 */
440 if (ip_phy_read(state, 5, 2) == 0x0243) {
441 state->regs = &IP178C;
442 } else {
443 chip_no = ip_phy_read(state, 20, 0);
444 pr_debug("IP17xx: Chip ID register reads %04x\n", chip_no);
445 if (chip_no == 0x175d) {
446 state->regs = &IP175D;
447 } else {
448 state->regs = &IP175C;
449 }
450 }
451 } else {
452 pr_warning("IP17xx: Found an unknown IC+ switch with model number %02x, revision %X.\n", model_no, rev_no);
453 return -EPERM;
454 }
455 return 0;
456 }
457
458 /*** Low-level functions for the older models ***/
459
460 /** Only set vlan and router flags in the switch **/
461 static int ip175c_set_flags(struct ip17xx_state *state)
462 {
463 int val;
464
465 if (!REG_SUPP(state->regs->ROUTER_CONTROL_REG)) {
466 return 0;
467 }
468
469 val = getPhy(state, state->regs->ROUTER_CONTROL_REG);
470 if (val < 0) {
471 return val;
472 }
473 if (state->regs->ROUTER_EN_BIT >= 0) {
474 if (state->router_mode) {
475 val |= (1<<state->regs->ROUTER_EN_BIT);
476 } else {
477 val &= (~(1<<state->regs->ROUTER_EN_BIT));
478 }
479 }
480 if (state->regs->TAG_VLAN_BIT >= 0) {
481 if (state->vlan_enabled) {
482 val |= (1<<state->regs->TAG_VLAN_BIT);
483 } else {
484 val &= (~(1<<state->regs->TAG_VLAN_BIT));
485 }
486 }
487 if (state->regs->NUMLAN_GROUPS_BIT >= 0) {
488 val &= (~((state->regs->NUMLAN_GROUPS_MAX-1)<<state->regs->NUMLAN_GROUPS_BIT));
489 if (state->num_vlans > state->regs->NUMLAN_GROUPS_MAX) {
490 val |= state->regs->NUMLAN_GROUPS_MAX << state->regs->NUMLAN_GROUPS_BIT;
491 } else if (state->num_vlans >= 1) {
492 val |= (state->num_vlans-1) << state->regs->NUMLAN_GROUPS_BIT;
493 }
494 }
495 return setPhy(state, state->regs->ROUTER_CONTROL_REG, val);
496 }
497
498 /** Set all VLAN and port state. Usually you should call "correct_vlan_state" first. **/
499 static int ip175c_set_state(struct ip17xx_state *state)
500 {
501 int j;
502 int i;
503 SET_PORT_BITS(state, state->add_tag,
504 state->regs->ADD_TAG_REG, state->regs->ADD_TAG_BIT);
505 SET_PORT_BITS(state, state->remove_tag,
506 state->regs->REMOVE_TAG_REG, state->regs->REMOVE_TAG_BIT);
507
508 if (REG_SUPP(state->regs->VLAN_LOOKUP_REG)) {
509 for (j=0; j<state->regs->NUM_PORTS; j++) {
510 reg addr;
511 const bitnum *bit_lookup = (j%2==0)?
512 state->regs->VLAN_LOOKUP_EVEN_BIT:
513 state->regs->VLAN_LOOKUP_ODD_BIT;
514
515 addr = state->regs->VLAN_LOOKUP_REG;
516 if (state->regs->SIMPLE_VLAN_REGISTERS) {
517 addr.m += j;
518 } else {
519 switch (j) {
520 case 0:
521 case 1:
522 break;
523 case 2:
524 case 3:
525 addr.m+=1;
526 break;
527 case 4:
528 addr.m+=2;
529 break;
530 case 5:
531 addr = state->regs->VLAN_LOOKUP_REG_5;
532 break;
533 default:
534 addr.m = -1; // shouldn't get here, but...
535 break;
536 }
537 }
538 //printf("shareports for %d is %02X\n",j,state->ports[j].shareports);
539 if (REG_SUPP(addr)) {
540 SET_PORT_BITS(state, state->ports[j].shareports, addr, bit_lookup);
541 }
542 }
543 }
544 if (REG_SUPP(state->regs->TAG_VLAN_MASK_REG)) {
545 for (j=0; j<MAX_VLANS; j++) {
546 reg addr = state->regs->TAG_VLAN_MASK_REG;
547 const bitnum *bit_lookup = (j%2==0)?
548 state->regs->TAG_VLAN_MASK_EVEN_BIT:
549 state->regs->TAG_VLAN_MASK_ODD_BIT;
550 unsigned int vlan_mask;
551 if (state->regs->SIMPLE_VLAN_REGISTERS) {
552 addr.m += j;
553 } else {
554 addr.m += j/2;
555 }
556 vlan_mask = state->vlans[j].ports;
557 SET_PORT_BITS(state, vlan_mask, addr, bit_lookup);
558 }
559 }
560
561 for (i=0; i<MAX_PORTS; i++) {
562 if (REG_SUPP(state->regs->VLAN_DEFAULT_TAG_REG[i])) {
563 int err = setPhy(state, state->regs->VLAN_DEFAULT_TAG_REG[i],
564 state->ports[i].pvid);
565 if (err < 0) {
566 return err;
567 }
568 }
569 }
570
571 return ip175c_set_flags(state);
572 }
573
574 /**
575 * Uses only the VLAN port mask and the add tag mask to generate the other fields:
576 * which ports are part of the same VLAN, removing vlan tags, and VLAN tag ids.
577 */
578 static void ip175c_correct_vlan_state(struct ip17xx_state *state)
579 {
580 int i, j;
581 state->num_vlans = 0;
582 for (i=0; i<MAX_VLANS; i++) {
583 if (state->vlans[i].ports != 0) {
584 state->num_vlans = i+1; // Hack -- we need to store the "set" vlans somewhere...
585 }
586 }
587
588 for (i=0; i<state->regs->NUM_PORTS; i++) {
589 unsigned int portmask = (1<<i);
590 if (!state->vlan_enabled) {
591 // Share with everybody!
592 state->ports[i].shareports = (1<<state->regs->NUM_PORTS)-1;
593 continue;
594 }
595 state->ports[i].shareports = portmask;
596 for (j=0; j<MAX_VLANS; j++) {
597 if (state->vlans[j].ports & portmask)
598 state->ports[i].shareports |= state->vlans[j].ports;
599 }
600 }
601 }
602
603 static int ip175c_update_state(struct ip17xx_state *state)
604 {
605 ip175c_correct_vlan_state(state);
606 return ip175c_set_state(state);
607 }
608
609 static int ip175c_set_vlan_mode(struct ip17xx_state *state)
610 {
611 return ip175c_update_state(state);
612 }
613
614 static int ip175c_reset(struct ip17xx_state *state)
615 {
616 int err;
617
618 if (REG_SUPP(state->regs->MODE_REG)) {
619 err = setPhy(state, state->regs->MODE_REG, state->regs->MODE_VAL);
620 if (err < 0)
621 return err;
622 err = getPhy(state, state->regs->MODE_REG);
623 if (err < 0)
624 return err;
625 }
626
627 return ip175c_update_state(state);
628 }
629
630 /*** Low-level functions for IP175D ***/
631
632 static int ip175d_update_state(struct ip17xx_state *state)
633 {
634 unsigned int filter_mask = 0;
635 unsigned int ports[16], add[16], rem[16];
636 int i, j;
637 int err = 0;
638
639 for (i = 0; i < 16; i++) {
640 ports[i] = 0;
641 add[i] = 0;
642 rem[i] = 0;
643 if (!state->vlan_enabled) {
644 err |= ip_phy_write(state, 22, 14+i, i+1); // default tags
645 ports[i] = 0x3f;
646 continue;
647 }
648 if (!state->vlans[i].tag) {
649 // Reset the filter
650 err |= ip_phy_write(state, 22, 14+i, 0); // tag
651 continue;
652 }
653 filter_mask |= 1 << i;
654 err |= ip_phy_write(state, 22, 14+i, state->vlans[i].tag);
655 ports[i] = state->vlans[i].ports;
656 for (j = 0; j < 6; j++) {
657 if (ports[i] & (1 << j)) {
658 if (state->add_tag & (1 << j))
659 add[i] |= 1 << j;
660 if (state->remove_tag & (1 << j))
661 rem[i] |= 1 << j;
662 }
663 }
664 }
665
666 // Port masks, tag adds and removals
667 for (i = 0; i < 8; i++) {
668 err |= ip_phy_write(state, 23, i, ports[2*i] | (ports[2*i+1] << 8));
669 err |= ip_phy_write(state, 23, 8+i, add[2*i] | (add[2*i+1] << 8));
670 err |= ip_phy_write(state, 23, 16+i, rem[2*i] | (rem[2*i+1] << 8));
671 }
672 err |= ip_phy_write(state, 22, 10, filter_mask);
673
674 // Default VLAN tag for each port
675 for (i = 0; i < 6; i++)
676 err |= ip_phy_write(state, 22, 4+i, state->vlans[state->ports[i].pvid].tag);
677
678 return (err ? -EIO : 0);
679 }
680
681 static int ip175d_set_vlan_mode(struct ip17xx_state *state)
682 {
683 int i;
684 int err = 0;
685
686 if (state->vlan_enabled) {
687 // VLAN classification rules: tag-based VLANs, use VID to classify,
688 // drop packets that cannot be classified.
689 err |= ip_phy_write_masked(state, 22, 0, 0x3fff, 0x003f);
690
691 // Ingress rules: CFI=1 dropped, null VID is untagged, VID=1 passed,
692 // VID=0xfff discarded, admin both tagged and untagged, ingress
693 // filters enabled.
694 err |= ip_phy_write_masked(state, 22, 1, 0x0fff, 0x0c3f);
695
696 // Egress rules: IGMP processing off, keep VLAN header off
697 err |= ip_phy_write_masked(state, 22, 2, 0x0fff, 0x0000);
698 } else {
699 // VLAN classification rules: everything off & clear table
700 err |= ip_phy_write_masked(state, 22, 0, 0xbfff, 0x8000);
701
702 // Ingress and egress rules: set to defaults
703 err |= ip_phy_write_masked(state, 22, 1, 0x0fff, 0x0c3f);
704 err |= ip_phy_write_masked(state, 22, 2, 0x0fff, 0x0000);
705 }
706
707 // Reset default VLAN for each port to 0
708 for (i = 0; i < 6; i++)
709 state->ports[i].pvid = 0;
710
711 err |= ip175d_update_state(state);
712
713 return (err ? -EIO : 0);
714 }
715
716 static int ip175d_reset(struct ip17xx_state *state)
717 {
718 int err = 0;
719
720 // Disable the special tagging mode
721 err |= ip_phy_write_masked(state, 21, 22, 0x0003, 0x0000);
722
723 // Set 802.1q protocol type
724 err |= ip_phy_write(state, 22, 3, 0x8100);
725
726 state->vlan_enabled = 0;
727 err |= ip175d_set_vlan_mode(state);
728
729 return (err ? -EIO : 0);
730 }
731
732 /*** High-level functions ***/
733
734 static int ip17xx_get_enable_vlan(struct switch_dev *dev, const struct switch_attr *attr, struct switch_val *val)
735 {
736 struct ip17xx_state *state = dev->priv;
737
738 val->value.i = state->vlan_enabled;
739 return 0;
740 }
741
742 static void ip17xx_reset_vlan_config(struct ip17xx_state *state)
743 {
744 int i;
745
746 state->remove_tag = (state->vlan_enabled ? ((1<<state->regs->NUM_PORTS)-1) : 0x0000);
747 state->add_tag = 0x0000;
748 for (i = 0; i < MAX_VLANS; i++) {
749 state->vlans[i].ports = 0x0000;
750 state->vlans[i].tag = (i ? i : 16);
751 }
752 for (i = 0; i < MAX_PORTS; i++)
753 state->ports[i].pvid = 0;
754 }
755
756 static int ip17xx_set_enable_vlan(struct switch_dev *dev, const struct switch_attr *attr, struct switch_val *val)
757 {
758 struct ip17xx_state *state = dev->priv;
759 int enable;
760
761 enable = val->value.i;
762 if (state->vlan_enabled == enable) {
763 // Do not change any state.
764 return 0;
765 }
766 state->vlan_enabled = enable;
767
768 // Otherwise, if we are switching state, set fields to a known default.
769 ip17xx_reset_vlan_config(state);
770
771 return state->regs->set_vlan_mode(state);
772 }
773
774 static int ip17xx_get_ports(struct switch_dev *dev, struct switch_val *val)
775 {
776 struct ip17xx_state *state = dev->priv;
777 int b;
778 int ind;
779 unsigned int ports;
780
781 if (val->port_vlan >= dev->vlans || val->port_vlan < 0)
782 return -EINVAL;
783
784 ports = state->vlans[val->port_vlan].ports;
785 b = 0;
786 ind = 0;
787 while (b < MAX_PORTS) {
788 if (ports&1) {
789 int istagged = ((state->add_tag >> b) & 1);
790 val->value.ports[ind].id = b;
791 val->value.ports[ind].flags = (istagged << SWITCH_PORT_FLAG_TAGGED);
792 ind++;
793 }
794 b++;
795 ports >>= 1;
796 }
797 val->len = ind;
798
799 return 0;
800 }
801
802 static int ip17xx_set_ports(struct switch_dev *dev, struct switch_val *val)
803 {
804 struct ip17xx_state *state = dev->priv;
805 int i;
806
807 if (val->port_vlan >= dev->vlans || val->port_vlan < 0)
808 return -EINVAL;
809
810 state->vlans[val->port_vlan].ports = 0;
811 for (i = 0; i < val->len; i++) {
812 unsigned int bitmask = (1<<val->value.ports[i].id);
813 state->vlans[val->port_vlan].ports |= bitmask;
814 if (val->value.ports[i].flags & (1<<SWITCH_PORT_FLAG_TAGGED)) {
815 state->add_tag |= bitmask;
816 state->remove_tag &= (~bitmask);
817 } else {
818 state->add_tag &= (~bitmask);
819 state->remove_tag |= bitmask;
820 }
821 }
822
823 return state->regs->update_state(state);
824 }
825
826 static int ip17xx_apply(struct switch_dev *dev)
827 {
828 struct ip17xx_state *state = dev->priv;
829
830 if (REG_SUPP(state->regs->MII_REGISTER_EN)) {
831 int val = getPhy(state, state->regs->MII_REGISTER_EN);
832 if (val < 0) {
833 return val;
834 }
835 val |= (1<<state->regs->MII_REGISTER_EN_BIT);
836 return setPhy(state, state->regs->MII_REGISTER_EN, val);
837 }
838 return 0;
839 }
840
841 static int ip17xx_reset(struct switch_dev *dev)
842 {
843 struct ip17xx_state *state = dev->priv;
844 int i, err;
845
846 if (REG_SUPP(state->regs->RESET_REG)) {
847 err = setPhy(state, state->regs->RESET_REG, state->regs->RESET_VAL);
848 if (err < 0)
849 return err;
850 err = getPhy(state, state->regs->RESET_REG);
851
852 /*
853 * Data sheet specifies reset period to be 2 msec.
854 * (I don't see any mention of the 2ms delay in the IP178C spec, only
855 * in IP175C, but it can't hurt.)
856 */
857 mdelay(2);
858 }
859
860 /* reset switch ports */
861 for (i = 0; i < state->regs->NUM_PORTS-1; i++) {
862 err = ip_phy_write(state, i, MII_BMCR, BMCR_RESET);
863 if (err < 0)
864 return err;
865 }
866
867 state->router_mode = 0;
868 state->vlan_enabled = 0;
869 ip17xx_reset_vlan_config(state);
870
871 return state->regs->reset(state);
872 }
873
874 static int ip17xx_get_tagged(struct switch_dev *dev, const struct switch_attr *attr, struct switch_val *val)
875 {
876 struct ip17xx_state *state = dev->priv;
877
878 if (state->add_tag & (1<<val->port_vlan)) {
879 if (state->remove_tag & (1<<val->port_vlan))
880 val->value.i = 3; // shouldn't ever happen.
881 else
882 val->value.i = 1;
883 } else {
884 if (state->remove_tag & (1<<val->port_vlan))
885 val->value.i = 0;
886 else
887 val->value.i = 2;
888 }
889 return 0;
890 }
891
892 static int ip17xx_set_tagged(struct switch_dev *dev, const struct switch_attr *attr, struct switch_val *val)
893 {
894 struct ip17xx_state *state = dev->priv;
895
896 state->add_tag &= ~(1<<val->port_vlan);
897 state->remove_tag &= ~(1<<val->port_vlan);
898
899 if (val->value.i == 0)
900 state->remove_tag |= (1<<val->port_vlan);
901 if (val->value.i == 1)
902 state->add_tag |= (1<<val->port_vlan);
903
904 return state->regs->update_state(state);
905 }
906
907 /** Get the current phy address */
908 static int ip17xx_get_phy(struct switch_dev *dev, const struct switch_attr *attr, struct switch_val *val)
909 {
910 struct ip17xx_state *state = dev->priv;
911
912 val->value.i = state->proc_mii.p;
913 return 0;
914 }
915
916 /** Set a new phy address for low level access to registers */
917 static int ip17xx_set_phy(struct switch_dev *dev, const struct switch_attr *attr, struct switch_val *val)
918 {
919 struct ip17xx_state *state = dev->priv;
920 int new_reg = val->value.i;
921
922 if (new_reg < 0 || new_reg > 31)
923 state->proc_mii.p = (u16)-1;
924 else
925 state->proc_mii.p = (u16)new_reg;
926 return 0;
927 }
928
929 /** Get the current register number */
930 static int ip17xx_get_reg(struct switch_dev *dev, const struct switch_attr *attr, struct switch_val *val)
931 {
932 struct ip17xx_state *state = dev->priv;
933
934 val->value.i = state->proc_mii.m;
935 return 0;
936 }
937
938 /** Set a new register address for low level access to registers */
939 static int ip17xx_set_reg(struct switch_dev *dev, const struct switch_attr *attr, struct switch_val *val)
940 {
941 struct ip17xx_state *state = dev->priv;
942 int new_reg = val->value.i;
943
944 if (new_reg < 0 || new_reg > 31)
945 state->proc_mii.m = (u16)-1;
946 else
947 state->proc_mii.m = (u16)new_reg;
948 return 0;
949 }
950
951 /** Get the register content of state->proc_mii */
952 static int ip17xx_get_val(struct switch_dev *dev, const struct switch_attr *attr, struct switch_val *val)
953 {
954 struct ip17xx_state *state = dev->priv;
955 int retval = -EINVAL;
956 if (REG_SUPP(state->proc_mii))
957 retval = getPhy(state, state->proc_mii);
958
959 if (retval < 0) {
960 return retval;
961 } else {
962 val->value.i = retval;
963 return 0;
964 }
965 }
966
967 /** Write a value to the register defined by phy/reg above */
968 static int ip17xx_set_val(struct switch_dev *dev, const struct switch_attr *attr, struct switch_val *val)
969 {
970 struct ip17xx_state *state = dev->priv;
971 int myval, err = -EINVAL;
972
973 myval = val->value.i;
974 if (myval <= 0xffff && myval >= 0 && REG_SUPP(state->proc_mii)) {
975 err = setPhy(state, state->proc_mii, (u16)myval);
976 }
977 return err;
978 }
979
980 static int ip17xx_read_name(struct switch_dev *dev, const struct switch_attr *attr, struct switch_val *val)
981 {
982 struct ip17xx_state *state = dev->priv;
983 val->value.s = state->regs->NAME; // Just a const pointer, won't be freed by swconfig.
984 return 0;
985 }
986
987 static int ip17xx_get_tag(struct switch_dev *dev, const struct switch_attr *attr, struct switch_val *val)
988 {
989 struct ip17xx_state *state = dev->priv;
990 int vlan = val->port_vlan;
991
992 if (vlan < 0 || vlan >= MAX_VLANS)
993 return -EINVAL;
994
995 val->value.i = state->vlans[vlan].tag;
996 return 0;
997 }
998
999 static int ip17xx_set_tag(struct switch_dev *dev, const struct switch_attr *attr, struct switch_val *val)
1000 {
1001 struct ip17xx_state *state = dev->priv;
1002 int vlan = val->port_vlan;
1003 int tag = val->value.i;
1004
1005 if (vlan < 0 || vlan >= MAX_VLANS)
1006 return -EINVAL;
1007
1008 if (tag < 0 || tag > 4095)
1009 return -EINVAL;
1010
1011 state->vlans[vlan].tag = tag;
1012 return state->regs->update_state(state);
1013 }
1014
1015 static int ip17xx_set_port_speed(struct switch_dev *dev, const struct switch_attr *attr, struct switch_val *val)
1016 {
1017 struct ip17xx_state *state = dev->priv;
1018 int nr = val->port_vlan;
1019 int ctrl;
1020 int autoneg;
1021 int speed;
1022 if (val->value.i == 100) {
1023 speed = 1;
1024 autoneg = 0;
1025 } else if (val->value.i == 10) {
1026 speed = 0;
1027 autoneg = 0;
1028 } else {
1029 autoneg = 1;
1030 speed = 1;
1031 }
1032
1033 /* Can't set speed for cpu port */
1034 if (nr == state->regs->CPU_PORT)
1035 return -EINVAL;
1036
1037 if (nr >= dev->ports || nr < 0)
1038 return -EINVAL;
1039
1040 ctrl = ip_phy_read(state, nr, 0);
1041 if (ctrl < 0)
1042 return -EIO;
1043
1044 ctrl &= (~(1<<12));
1045 ctrl &= (~(1<<13));
1046 ctrl |= (autoneg<<12);
1047 ctrl |= (speed<<13);
1048
1049 return ip_phy_write(state, nr, 0, ctrl);
1050 }
1051
1052 static int ip17xx_get_port_speed(struct switch_dev *dev, const struct switch_attr *attr, struct switch_val *val)
1053 {
1054 struct ip17xx_state *state = dev->priv;
1055 int nr = val->port_vlan;
1056 int speed, status;
1057
1058 if (nr == state->regs->CPU_PORT) {
1059 val->value.i = 100;
1060 return 0;
1061 }
1062
1063 if (nr >= dev->ports || nr < 0)
1064 return -EINVAL;
1065
1066 status = ip_phy_read(state, nr, 1);
1067 speed = ip_phy_read(state, nr, 18);
1068 if (status < 0 || speed < 0)
1069 return -EIO;
1070
1071 if (status & 4)
1072 val->value.i = ((speed & (1<<11)) ? 100 : 10);
1073 else
1074 val->value.i = 0;
1075
1076 return 0;
1077 }
1078
1079 static int ip17xx_get_port_status(struct switch_dev *dev, const struct switch_attr *attr, struct switch_val *val)
1080 {
1081 struct ip17xx_state *state = dev->priv;
1082 int ctrl, speed, status;
1083 int nr = val->port_vlan;
1084 int len;
1085 char *buf = state->buf; // fixed-length at 80.
1086
1087 if (nr == state->regs->CPU_PORT) {
1088 sprintf(buf, "up, 100 Mbps, cpu port");
1089 val->value.s = buf;
1090 return 0;
1091 }
1092
1093 if (nr >= dev->ports || nr < 0)
1094 return -EINVAL;
1095
1096 ctrl = ip_phy_read(state, nr, 0);
1097 status = ip_phy_read(state, nr, 1);
1098 speed = ip_phy_read(state, nr, 18);
1099 if (ctrl < 0 || status < 0 || speed < 0)
1100 return -EIO;
1101
1102 if (status & 4)
1103 len = sprintf(buf, "up, %d Mbps, %s duplex",
1104 ((speed & (1<<11)) ? 100 : 10),
1105 ((speed & (1<<10)) ? "full" : "half"));
1106 else
1107 len = sprintf(buf, "down");
1108
1109 if (ctrl & (1<<12)) {
1110 len += sprintf(buf+len, ", auto-negotiate");
1111 if (!(status & (1<<5)))
1112 len += sprintf(buf+len, " (in progress)");
1113 } else {
1114 len += sprintf(buf+len, ", fixed speed (%d)",
1115 ((ctrl & (1<<13)) ? 100 : 10));
1116 }
1117
1118 buf[len] = '\0';
1119 val->value.s = buf;
1120 return 0;
1121 }
1122
1123 static int ip17xx_get_pvid(struct switch_dev *dev, int port, int *val)
1124 {
1125 struct ip17xx_state *state = dev->priv;
1126
1127 *val = state->ports[port].pvid;
1128 return 0;
1129 }
1130
1131 static int ip17xx_set_pvid(struct switch_dev *dev, int port, int val)
1132 {
1133 struct ip17xx_state *state = dev->priv;
1134
1135 if (val < 0 || val >= MAX_VLANS)
1136 return -EINVAL;
1137
1138 state->ports[port].pvid = val;
1139 return state->regs->update_state(state);
1140 }
1141
1142
1143 enum Ports {
1144 IP17XX_PORT_STATUS,
1145 IP17XX_PORT_LINK,
1146 IP17XX_PORT_TAGGED,
1147 IP17XX_PORT_PVID,
1148 };
1149
1150 enum Globals {
1151 IP17XX_ENABLE_VLAN,
1152 IP17XX_GET_NAME,
1153 IP17XX_REGISTER_PHY,
1154 IP17XX_REGISTER_MII,
1155 IP17XX_REGISTER_VALUE,
1156 IP17XX_REGISTER_ERRNO,
1157 };
1158
1159 enum Vlans {
1160 IP17XX_VLAN_TAG,
1161 };
1162
1163 static const struct switch_attr ip17xx_global[] = {
1164 [IP17XX_ENABLE_VLAN] = {
1165 .id = IP17XX_ENABLE_VLAN,
1166 .type = SWITCH_TYPE_INT,
1167 .name = "enable_vlan",
1168 .description = "Flag to enable or disable VLANs and tagging",
1169 .get = ip17xx_get_enable_vlan,
1170 .set = ip17xx_set_enable_vlan,
1171 },
1172 [IP17XX_GET_NAME] = {
1173 .id = IP17XX_GET_NAME,
1174 .type = SWITCH_TYPE_STRING,
1175 .description = "Returns the type of IC+ chip.",
1176 .name = "name",
1177 .get = ip17xx_read_name,
1178 .set = NULL,
1179 },
1180 /* jal: added for low level debugging etc. */
1181 [IP17XX_REGISTER_PHY] = {
1182 .id = IP17XX_REGISTER_PHY,
1183 .type = SWITCH_TYPE_INT,
1184 .description = "Direct register access: set PHY (0-4, or 29,30,31)",
1185 .name = "phy",
1186 .get = ip17xx_get_phy,
1187 .set = ip17xx_set_phy,
1188 },
1189 [IP17XX_REGISTER_MII] = {
1190 .id = IP17XX_REGISTER_MII,
1191 .type = SWITCH_TYPE_INT,
1192 .description = "Direct register access: set MII register number (0-31)",
1193 .name = "reg",
1194 .get = ip17xx_get_reg,
1195 .set = ip17xx_set_reg,
1196 },
1197 [IP17XX_REGISTER_VALUE] = {
1198 .id = IP17XX_REGISTER_VALUE,
1199 .type = SWITCH_TYPE_INT,
1200 .description = "Direct register access: read/write to register (0-65535)",
1201 .name = "val",
1202 .get = ip17xx_get_val,
1203 .set = ip17xx_set_val,
1204 },
1205 };
1206
1207 static const struct switch_attr ip17xx_vlan[] = {
1208 [IP17XX_VLAN_TAG] = {
1209 .id = IP17XX_VLAN_TAG,
1210 .type = SWITCH_TYPE_INT,
1211 .description = "VLAN tag (0-4095) [IP175D only]",
1212 .name = "tag",
1213 .get = ip17xx_get_tag,
1214 .set = ip17xx_set_tag,
1215 }
1216 };
1217
1218 static const struct switch_attr ip17xx_port[] = {
1219 [IP17XX_PORT_STATUS] = {
1220 .id = IP17XX_PORT_STATUS,
1221 .type = SWITCH_TYPE_STRING,
1222 .description = "Returns Detailed port status",
1223 .name = "status",
1224 .get = ip17xx_get_port_status,
1225 .set = NULL,
1226 },
1227 [IP17XX_PORT_LINK] = {
1228 .id = IP17XX_PORT_LINK,
1229 .type = SWITCH_TYPE_INT,
1230 .description = "Link speed. Can write 0 for auto-negotiate, or 10 or 100",
1231 .name = "link",
1232 .get = ip17xx_get_port_speed,
1233 .set = ip17xx_set_port_speed,
1234 },
1235 [IP17XX_PORT_TAGGED] = {
1236 .id = IP17XX_PORT_LINK,
1237 .type = SWITCH_TYPE_INT,
1238 .description = "0 = untag, 1 = add tags, 2 = do not alter (This value is reset if vlans are altered)",
1239 .name = "tagged",
1240 .get = ip17xx_get_tagged,
1241 .set = ip17xx_set_tagged,
1242 },
1243 };
1244
1245 static int ip17xx_probe(struct phy_device *pdev)
1246 {
1247 struct ip17xx_state *state;
1248 struct switch_dev *dev;
1249 int err;
1250
1251 /* We only attach to PHY 0, but use all available PHYs */
1252 if (pdev->addr != 0)
1253 return -ENODEV;
1254
1255 state = kzalloc(sizeof(*state), GFP_KERNEL);
1256 if (!state)
1257 return -ENOMEM;
1258
1259 dev = &state->dev;
1260 dev->attr_global.attr = ip17xx_global;
1261 dev->attr_global.n_attr = ARRAY_SIZE(ip17xx_global);
1262 dev->attr_port.attr = ip17xx_port;
1263 dev->attr_port.n_attr = ARRAY_SIZE(ip17xx_port);
1264 dev->attr_vlan.attr = ip17xx_vlan;
1265 dev->attr_vlan.n_attr = ARRAY_SIZE(ip17xx_vlan);
1266
1267 dev->get_port_pvid = ip17xx_get_pvid;
1268 dev->set_port_pvid = ip17xx_set_pvid;
1269 dev->get_vlan_ports = ip17xx_get_ports;
1270 dev->set_vlan_ports = ip17xx_set_ports;
1271 dev->apply_config = ip17xx_apply;
1272 dev->reset_switch = ip17xx_reset;
1273
1274 dev->priv = state;
1275 pdev->priv = state;
1276 state->mii_bus = pdev->bus;
1277
1278 err = get_model(state);
1279 if (err < 0)
1280 goto error;
1281
1282 dev->vlans = MAX_VLANS;
1283 dev->cpu_port = state->regs->CPU_PORT;
1284 dev->ports = state->regs->NUM_PORTS;
1285 dev->name = state->regs->NAME;
1286
1287 pr_info("IP17xx: Found %s at %s\n", dev->name, dev_name(&pdev->dev));
1288 return 0;
1289
1290 error:
1291 kfree(state);
1292 return err;
1293 }
1294
1295 static int ip17xx_config_init(struct phy_device *pdev)
1296 {
1297 struct ip17xx_state *state = pdev->priv;
1298 struct net_device *dev = pdev->attached_dev;
1299 int err;
1300
1301 err = register_switch(&state->dev, dev);
1302 if (err < 0)
1303 return err;
1304
1305 state->registered = true;
1306 ip17xx_reset(&state->dev);
1307 return 0;
1308 }
1309
1310 static void ip17xx_remove(struct phy_device *pdev)
1311 {
1312 struct ip17xx_state *state = pdev->priv;
1313
1314 if (state->registered)
1315 unregister_switch(&state->dev);
1316 kfree(state);
1317 }
1318
1319 static int ip17xx_config_aneg(struct phy_device *pdev)
1320 {
1321 return 0;
1322 }
1323
1324 static int ip17xx_aneg_done(struct phy_device *pdev)
1325 {
1326 return BMSR_ANEGCOMPLETE;
1327 }
1328
1329 static int ip17xx_update_link(struct phy_device *pdev)
1330 {
1331 pdev->link = 1;
1332 return 0;
1333 }
1334
1335 static int ip17xx_read_status(struct phy_device *pdev)
1336 {
1337 pdev->speed = SPEED_100;
1338 pdev->duplex = DUPLEX_FULL;
1339 pdev->pause = pdev->asym_pause = 0;
1340 pdev->link = 1;
1341
1342 return 0;
1343 }
1344
1345 static struct phy_driver ip17xx_driver = {
1346 .name = "IC+ IP17xx",
1347 .phy_id = 0x02430c00,
1348 .phy_id_mask = 0x0ffffc00,
1349 .features = PHY_BASIC_FEATURES,
1350 .probe = ip17xx_probe,
1351 .remove = ip17xx_remove,
1352 .config_init = ip17xx_config_init,
1353 .config_aneg = ip17xx_config_aneg,
1354 .aneg_done = ip17xx_aneg_done,
1355 .update_link = ip17xx_update_link,
1356 .read_status = ip17xx_read_status,
1357 .driver = { .owner = THIS_MODULE },
1358 };
1359
1360 static struct phy_driver ip175a_driver = {
1361 .name = "IC+ IP175A",
1362 .phy_id = 0x02430c50,
1363 .phy_id_mask = 0x0ffffff0,
1364 .features = PHY_BASIC_FEATURES,
1365 .probe = ip17xx_probe,
1366 .remove = ip17xx_remove,
1367 .config_init = ip17xx_config_init,
1368 .config_aneg = ip17xx_config_aneg,
1369 .aneg_done = ip17xx_aneg_done,
1370 .update_link = ip17xx_update_link,
1371 .read_status = ip17xx_read_status,
1372 .driver = { .owner = THIS_MODULE },
1373 };
1374
1375
1376 int __init ip17xx_init(void)
1377 {
1378 int ret;
1379
1380 ret = phy_driver_register(&ip175a_driver);
1381 if (ret < 0)
1382 return ret;
1383
1384 return phy_driver_register(&ip17xx_driver);
1385 }
1386
1387 void __exit ip17xx_exit(void)
1388 {
1389 phy_driver_unregister(&ip17xx_driver);
1390 phy_driver_unregister(&ip175a_driver);
1391 }
1392
1393 MODULE_AUTHOR("Patrick Horn <patrick.horn@gmail.com>");
1394 MODULE_AUTHOR("Felix Fietkau <nbd@openwrt.org>");
1395 MODULE_AUTHOR("Martin Mares <mj@ucw.cz>");
1396 MODULE_LICENSE("GPL");
1397
1398 module_init(ip17xx_init);
1399 module_exit(ip17xx_exit);
This page took 0.111738 seconds and 5 git commands to generate.