1 /******************************************************************************
2 Copyright (c) 2007, Infineon Technologies. All rights reserved.
5 Because the program is licensed free of charge, there is no warranty for
6 the program, to the extent permitted by applicable law. Except when
7 otherwise stated in writing the copyright holders and/or other parties
8 provide the program "as is" without warranty of any kind, either
9 expressed or implied, including, but not limited to, the implied
10 warranties of merchantability and fitness for a particular purpose. The
11 entire risk as to the quality and performance of the program is with
12 you. should the program prove defective, you assume the cost of all
13 necessary servicing, repair or correction.
15 In no event unless required by applicable law or agreed to in writing
16 will any copyright holder, or any other party who may modify and/or
17 redistribute the program as permitted above, be liable to you for
18 damages, including any general, special, incidental or consequential
19 damages arising out of the use or inability to use the program
20 (including but not limited to loss of data or data being rendered
21 inaccurate or losses sustained by you or third parties or a failure of
22 the program to operate with any other programs), even if such holder or
23 other party has been advised of the possibility of such damages.
24 ******************************************************************************
25 Module : switchip_setup.c
27 Description : Basic setup of embedded ethernet switch "SwitchIP"
28 Remarks: andreas.schmidt@infineon.com
30 *****************************************************************************/
32 /* TODO: get rid of #ifdef CONFIG_LANTIQ_MACH_EASY336 */
34 #include <linux/kernel.h>
35 #include <linux/module.h>
36 #include <linux/version.h>
37 #include <linux/init.h>
38 #include <linux/delay.h>
39 #include <linux/workqueue.h>
40 #include <linux/time.h>
46 #include <lantiq_soc.h>
48 static struct svip_reg_sys1
*const sys1
= (struct svip_reg_sys1
*)LTQ_SYS1_BASE
;
49 static struct svip_reg_es
*const es
= (struct svip_reg_es
*)LTQ_ES_BASE
;
51 /* PHY Organizationally Unique Identifier (OUI) */
52 #define PHY_OUI_PMC 0x00E004
53 #define PHY_OUI_VITESSE 0x008083
54 #define PHY_OUI_DEFAULT 0xFFFFFF
56 unsigned short switchip_phy_read(unsigned int phyaddr
, unsigned int regaddr
);
57 void switchip_phy_write(unsigned int phyaddr
, unsigned int regaddr
,
60 static int phy_address
[2] = {0, 1};
62 static void switchip_mdio_poll_init(void);
63 static void _switchip_mdio_poll(struct work_struct
*work
);
65 /* struct workqueue_struct mdio_poll_task; */
66 static struct workqueue_struct
*mdio_poll_workqueue
;
67 DECLARE_DELAYED_WORK(mdio_poll_work
, _switchip_mdio_poll
);
68 static int old_link_status
[2] = {-1, -1};
71 * Autonegotiation check.
72 * This funtion checks for link changes. If a link change has occured it will
73 * update certain switch registers.
75 static void _switchip_check_phy_status(int port
)
80 reg1
= switchip_phy_read(phy_address
[port
], 1);
81 if ((reg1
== 0xFFFF) || (reg1
== 0x0000))
82 return; /* no PHY connected */
84 new_link_status
= reg1
& 4;
85 if (old_link_status
[port
] ^ new_link_status
) {
86 /* link status change */
87 if (!new_link_status
) {
89 es_w32_mask(LTQ_ES_P0_CTL_REG_FLP
, 0, p0_ctl
);
91 es_w32_mask(LTQ_ES_P0_CTL_REG_FLP
, 0, p1_ctl
);
93 /* read again; link bit is latched low! */
94 reg1
= switchip_phy_read(phy_address
[port
], 1);
95 new_link_status
= reg1
& 4;
98 if (new_link_status
) {
99 unsigned short reg0
, reg4
, reg5
, reg9
, reg10
;
100 int phy_pause
, phy_speed
, phy_duplex
;
101 int aneg_enable
, aneg_cmpt
;
103 reg0
= switchip_phy_read(phy_address
[port
], 0);
104 reg4
= switchip_phy_read(phy_address
[port
], 4);
105 aneg_enable
= reg0
& 0x1000;
106 aneg_cmpt
= reg1
& 0x20;
108 if (aneg_enable
&& aneg_cmpt
) {
109 reg5
= switchip_phy_read(phy_address
[port
], 5);
111 #ifdef CONFIG_LANTIQ_MACH_EASY336
113 /* PMC Sierra supports 1Gigabit FD,
114 * only. On successful
115 * auto-negotiation, we are sure this
116 * is what the LP can. */
117 phy_pause
= ((reg4
& reg5
) & 0x0080) >> 7;
122 case PHY_OUI_VITESSE
:
123 case PHY_OUI_DEFAULT
:
124 reg9
= switchip_phy_read(phy_address
[port
], 9);
125 reg10
= switchip_phy_read(phy_address
[port
], 10);
127 /* Check if advertise and partner
129 phy_pause
= ((reg4
& reg5
) & 0x0400) >> 10;
131 /* Find the best mode both partners
133 * Priority: 1GB-FD, 1GB-HD, 100MB-FD,
134 * 100MB-HD, 10MB-FD, 10MB-HD */
135 phy_speed
= ((((reg9
<<2) & reg10
)
137 (((reg4
& reg5
) & 0x01e0) >> 5);
139 if (phy_speed
>= 0x0020) {
142 } else if (phy_speed
>= 0x0010) {
145 } else if (phy_speed
>= 0x0008) {
148 } else if (phy_speed
>= 0x0004) {
151 } else if (phy_speed
>= 0x0002) {
160 phy_pause
= (reg4
& 0x0400) >> 10;
161 phy_speed
= (reg0
& 0x40 ? 2 : (reg0
>> 13)&1);
162 phy_duplex
= (reg0
>> 8)&1;
166 /* parallel detection or fixed speed */
167 phy_pause
= (reg4
& 0x0400) >> 10;
168 phy_speed
= (reg0
& 0x40 ? 2 : (reg0
>> 13)&1);
169 phy_duplex
= (reg0
>> 8)&1;
173 es_w32_mask(LTQ_ES_RGMII_CTL_REG_P0SPD
,
174 LTQ_ES_RGMII_CTL_REG_P0SPD_VAL(phy_speed
),
176 es_w32_mask(LTQ_ES_RGMII_CTL_REG_P0DUP
,
177 LTQ_ES_RGMII_CTL_REG_P0DUP_VAL(phy_duplex
),
179 es_w32_mask(LTQ_ES_RGMII_CTL_REG_P0FCE
,
180 LTQ_ES_RGMII_CTL_REG_P0FCE_VAL(phy_pause
),
183 es_w32_mask(0, LTQ_ES_P0_CTL_REG_FLP
, p0_ctl
);
185 es_w32_mask(LTQ_ES_RGMII_CTL_REG_P1SPD
,
186 LTQ_ES_RGMII_CTL_REG_P1SPD_VAL(phy_speed
),
188 es_w32_mask(LTQ_ES_RGMII_CTL_REG_P1DUP
,
189 LTQ_ES_RGMII_CTL_REG_P1DUP_VAL(phy_duplex
),
191 es_w32_mask(LTQ_ES_RGMII_CTL_REG_P1FCE
,
192 LTQ_ES_RGMII_CTL_REG_P0FCE_VAL(phy_pause
),
195 es_w32_mask(1, LTQ_ES_P0_CTL_REG_FLP
, p1_ctl
);
199 old_link_status
[port
] = new_link_status
;
202 static void _switchip_mdio_poll(struct work_struct
*work
)
204 if (es_r32(sw_gctl0
) & LTQ_ES_SW_GCTL0_REG_SE
) {
205 _switchip_check_phy_status(0);
206 _switchip_check_phy_status(1);
209 queue_delayed_work(mdio_poll_workqueue
, &mdio_poll_work
, HZ
/2);
212 static void switchip_mdio_poll_init(void)
214 mdio_poll_workqueue
= create_workqueue("SVIP MDIP poll");
215 INIT_DELAYED_WORK(&mdio_poll_work
, _switchip_mdio_poll
);
217 queue_delayed_work(mdio_poll_workqueue
, &mdio_poll_work
, HZ
/2);
221 unsigned short switchip_phy_read(unsigned int phyaddr
, unsigned int regaddr
)
223 /* TODO: protect MDIO access with semaphore */
224 es_w32(LTQ_ES_MDIO_CTL_REG_MBUSY
225 | LTQ_ES_MDIO_CTL_REG_OP_VAL(2) /* read operation */
226 | LTQ_ES_MDIO_CTL_REG_PHYAD_VAL(phyaddr
)
227 | LTQ_ES_MDIO_CTL_REG_REGAD_VAL(regaddr
), mdio_ctl
);
228 while (es_r32(mdio_ctl
) & LTQ_ES_MDIO_CTL_REG_MBUSY
);
230 return es_r32(mdio_data
) & 0xFFFF;
232 EXPORT_SYMBOL(switchip_phy_read
);
234 void switchip_phy_write(unsigned int phyaddr
, unsigned int regaddr
,
237 /* TODO: protect MDIO access with semaphore */
238 es_w32(LTQ_ES_MDIO_CTL_REG_WD_VAL(data
)
239 | LTQ_ES_MDIO_CTL_REG_MBUSY
240 | LTQ_ES_MDIO_CTL_REG_OP_VAL(1) /* write operation */
241 | LTQ_ES_MDIO_CTL_REG_PHYAD_VAL(phyaddr
)
242 | LTQ_ES_MDIO_CTL_REG_REGAD_VAL(regaddr
), mdio_ctl
);
243 while (es_r32(mdio_ctl
) & LTQ_ES_MDIO_CTL_REG_MBUSY
);
247 EXPORT_SYMBOL(switchip_phy_write
);
249 const static u32 switch_reset_offset_000
[] = {
250 /*b8000000:*/ 0xffffffff, 0x00000001, 0x00000001, 0x00000003,
251 /*b8000010:*/ 0x04070001, 0x04070001, 0x04070001, 0xffffffff,
252 /*b8000020:*/ 0x00001be8, 0x00001be8, 0x00001be8, 0xffffffff,
253 /*b8000030:*/ 0x00000000, 0x00000000, 0x00080004, 0x00020001,
254 /*b8000040:*/ 0x00000000, 0x00000000, 0x00080004, 0x00020001,
255 /*b8000050:*/ 0x00000000, 0x00000000, 0x00080004, 0x00020001,
256 /*b8000060:*/ 0x00000000, 0x00000000, 0x00081000, 0x001f7777,
257 /*b8000070:*/ 0x00000000, 0x00000000, 0x0c00ac2b, 0x0000fa50,
258 /*b8000080:*/ 0x00001000, 0x00001800, 0x00000000, 0x00000000,
259 /*b8000090:*/ 0x00000000, 0x00000000, 0x00000000, 0x00000000,
260 /*b80000a0:*/ 0x00000000, 0x00000050, 0x00000010, 0x00000000,
261 /*b80000b0:*/ 0x00000000, 0x00000000, 0x00000000, 0x00000000,
262 /*b80000c0:*/ 0x00000000, 0x00000000, 0x00000000, 0x00000000,
263 /*b80000d0:*/ 0xffffffff, 0x00000000, 0x00000000
265 const static u32 switch_reset_offset_100
[] = {
266 /*b8000100:*/ 0x00000000, 0x00000000, 0x00000000, 0x00000000,
267 /*b8000110:*/ 0x00000000, 0x00000000, 0x00000000, 0x00000000,
268 /*b8000120:*/ 0x00000000, 0x00000000, 0x00000000, 0x00000000,
269 /*b8000130:*/ 0x00000000, 0x00000000, 0x00000000, 0x00000000,
270 /*b8000140:*/ 0x00000000, 0x00000000, 0x00000000, 0x00000000,
271 /*b8000150:*/ 0x00000000, 0x00000000, 0x00000000, 0x00000000,
272 /*b8000160:*/ 0x00000000, 0x00000000, 0x00000000, 0x00000000,
273 /*b8000170:*/ 0x00000000, 0x00000000, 0x00000000, 0x00000000,
274 /*b8000180:*/ 0x00000000, 0x00000000, 0x00000000, 0x00000000,
275 /*b8000190:*/ 0x00000000, 0x00000000, 0x00000000, 0x00000000,
276 /*b80001a0:*/ 0x00000000, 0x00000000, 0x00000000, 0x00000000,
277 /*b80001b0:*/ 0x00000000, 0x00000000
283 void switchip_reset(void)
285 volatile unsigned int *reg
;
286 volatile unsigned int rdreg
;
289 sys1_w32(SYS1_CLKENR_ETHSW
, clkenr
);
293 es_w32_mask(0, LTQ_ES_P0_CTL_REG_SPS_VAL(1), p0_ctl
);
295 es_w32_mask(0, LTQ_ES_P0_CTL_REG_SPS_VAL(1), p1_ctl
);
297 es_w32_mask(0, LTQ_ES_P0_CTL_REG_SPS_VAL(1), p2_ctl
);
299 /**************************************
300 * BEGIN: Procedure to clear MAC table
301 **************************************/
302 for (i
= 0; i
< 3; i
++) {
305 /* check if access engine is available */
306 while (es_r32(adr_tb_st2
) & LTQ_ES_ADR_TB_ST2_REG_BUSY
);
308 /* initialise to first address */
309 es_w32(LTQ_ES_ADR_TB_CTL2_REG_CMD_VAL(3)
310 | LTQ_ES_ADR_TB_CTL2_REG_AC_VAL(0), adr_tb_ctl2
);
312 /* wait while busy */
313 while (es_r32(adr_tb_st2
) & LTQ_ES_ADR_TB_ST2_REG_BUSY
);
315 /* setup the portmap */
316 es_w32_mask(0, LTQ_ES_ADR_TB_CTL1_REG_PMAP_VAL(1 << i
),
320 /* search for addresses by port */
321 es_w32(LTQ_ES_ADR_TB_CTL2_REG_CMD_VAL(2)
322 | LTQ_ES_ADR_TB_CTL2_REG_AC_VAL(9), adr_tb_ctl2
);
324 /* wait while busy */
325 while (es_r32(adr_tb_st2
) & LTQ_ES_ADR_TB_ST2_REG_BUSY
);
327 result
= LTQ_ES_ADR_TB_ST2_REG_RSLT_GET(es_r32(adr_tb_st2
));
328 if (result
== 0x101) {
329 printk(KERN_ERR
"%s, cmd error\n", __func__
);
332 /* if Command OK, address found... */
334 unsigned char mac
[6];
336 mac
[5] = (es_r32(adr_tb_st0
) >> 0) & 0xff;
337 mac
[4] = (es_r32(adr_tb_st0
) >> 8) & 0xff;
338 mac
[3] = (es_r32(adr_tb_st0
) >> 16) & 0xff;
339 mac
[2] = (es_r32(adr_tb_st0
) >> 24) & 0xff;
340 mac
[1] = (es_r32(adr_tb_st1
) >> 0) & 0xff;
341 mac
[0] = (es_r32(adr_tb_st1
) >> 8) & 0xff;
344 es_w32((mac
[5] << 0) |
347 (mac
[2] << 24), adr_tb_ctl0
);
348 es_w32(LTQ_ES_ADR_TB_CTL1_REG_PMAP_VAL(1<<i
) |
349 LTQ_ES_ADR_TB_CTL1_REG_FID_VAL(0) |
351 (mac
[1] << 0), adr_tb_ctl1
);
354 es_w32(LTQ_ES_ADR_TB_CTL2_REG_CMD_VAL(1) |
355 LTQ_ES_ADR_TB_CTL2_REG_AC_VAL(15),
358 /* wait, while busy */
359 while (es_r32(adr_tb_st2
) &
360 LTQ_ES_ADR_TB_ST2_REG_BUSY
);
362 } while (result
== 0);
364 /**************************************
365 * END: Procedure to clear MAC table
366 **************************************/
368 /* reset RMON counters */
369 es_w32(LTQ_ES_RMON_CTL_REG_BAS
| LTQ_ES_RMON_CTL_REG_CAC_VAL(3),
372 /* bring all registers to reset state */
374 for (i
= 0; i
< ARRAY_SIZE(switch_reset_offset_000
); i
++) {
375 if ((reg
== LTQ_ES_PS_REG
) ||
376 (reg
>= LTQ_ES_ADR_TB_CTL0_REG
&&
377 reg
<= LTQ_ES_ADR_TB_ST2_REG
))
380 if (switch_reset_offset_000
[i
] != 0xFFFFFFFF) {
381 /* write reset value to register */
382 *reg
= switch_reset_offset_000
[i
];
383 /* read register value back */
385 if (reg
== LTQ_ES_SW_GCTL1_REG
)
386 rdreg
&= ~LTQ_ES_SW_GCTL1_REG_BISTDN
;
387 /* compare read value with written one */
388 if (rdreg
!= switch_reset_offset_000
[i
]) {
389 printk(KERN_ERR
"%s,%d: reg %08x mismatch "
390 "[has:%08x, expect:%08x]\n",
392 (unsigned int)reg
, rdreg
,
393 switch_reset_offset_000
[i
]);
399 reg
= LTQ_ES_VLAN_FLT0_REG
;
400 for (i
= 0; i
< ARRAY_SIZE(switch_reset_offset_100
); i
++) {
401 *reg
= switch_reset_offset_100
[i
];
403 if (rdreg
!= switch_reset_offset_100
[i
]) {
404 printk(KERN_ERR
"%s,%d: reg %08x mismatch "
405 "[has:%08x, expect:%08x]\n", __func__
, __LINE__
,
406 (unsigned int)reg
, rdreg
,
407 switch_reset_offset_100
[i
]);
412 EXPORT_SYMBOL(switchip_reset
);
414 static u32
get_phy_oui(unsigned char phy_addr
)
417 int i
, bit
, byte
, shift
, w
;
420 /* read PHY identifier registers 1 and 2 */
421 reg_id
[0] = switchip_phy_read(phy_addr
, 2);
422 reg_id
[1] = switchip_phy_read(phy_addr
, 3);
428 for (i
= 0, bit
= 10; i
<= 21; i
++, bit
++) {
429 oui
|= ((reg_id
[w
] & (1<<bit
)) ? 1 : 0) << shift
;
439 if (w
== 1 && bit
== 15) {
448 * Switch Initialization.
450 int switchip_init(void)
452 int eth_port
, phy_present
= 0;
455 sys1_w32(SYS1_CLKENR_ETHSW
, clkenr
);
458 /* Enable Switch, if not already done so */
459 if ((es_r32(sw_gctl0
) & LTQ_ES_SW_GCTL0_REG_SE
) == 0)
460 es_w32_mask(0, LTQ_ES_SW_GCTL0_REG_SE
, sw_gctl0
);
461 /* Wait for completion of MBIST */
462 while (LTQ_ES_SW_GCTL1_REG_BISTDN_GET(es_r32(sw_gctl1
)) == 0);
466 mode
= LTQ_ES_RGMII_CTL_REG_IS_GET(es_r32(rgmii_ctl
));
467 eth_port
= (mode
== 2 ? 1 : 0);
469 /* Set the primary port(port toward backplane) as sniffer port,
470 changing from P2 which is the reset setting */
471 es_w32_mask(LTQ_ES_SW_GCTL0_REG_SNIFFPN
,
472 LTQ_ES_SW_GCTL0_REG_SNIFFPN_VAL(eth_port
),
475 /* Point MDIO state machine to invalid PHY addresses 8 and 9 */
476 es_w32_mask(0, LTQ_ES_SW_GCTL0_REG_PHYBA
, sw_gctl0
);
478 /* Add CRC for packets from DMA to PMAC.
479 Remove CRC for packets from PMAC to DMA. */
480 es_w32(LTQ_ES_PMAC_HD_CTL_RC
| LTQ_ES_PMAC_HD_CTL_AC
, pmac_hd_ctl
);
482 phy_oui
= get_phy_oui(0);
484 #ifdef CONFIG_LANTIQ_MACH_EASY336
486 phy_address
[0] = (mode
== 2 ? -1 : 2);
487 phy_address
[1] = (mode
== 2 ? 2 : -1);
490 case PHY_OUI_VITESSE
:
492 phy_oui
= PHY_OUI_DEFAULT
;
493 phy_address
[0] = (mode
== 2 ? 1 : 0);
494 phy_address
[1] = (mode
== 2 ? 0 : 1);
498 /****** PORT 0 *****/
499 reg
= switchip_phy_read(phy_address
[0], 1);
500 if ((reg
!= 0x0000) && (reg
!= 0xffff)) {
503 /* Set Rx- and TxDelay in case of RGMII */
505 case 0: /* *RGMII,RGMII */
506 case 2: /* RGMII,*GMII */
507 /* program clock delay in PHY, not in SVIP */
509 es_w32_mask(LTQ_ES_RGMII_CTL_REG_P0RDLY
, 0, rgmii_ctl
);
510 es_w32_mask(LTQ_ES_RGMII_CTL_REG_P0TDLY
, 0, rgmii_ctl
);
511 if (phy_oui
== PHY_OUI_VITESSE
||
512 phy_oui
== PHY_OUI_DEFAULT
) {
513 switchip_phy_write(phy_address
[0], 31, 0x0001);
514 switchip_phy_write(phy_address
[0], 28, 0xA000);
515 switchip_phy_write(phy_address
[0], 31, 0x0000);
520 if (phy_oui
== PHY_OUI_VITESSE
||
521 phy_oui
== PHY_OUI_DEFAULT
) {
522 /* Program PHY advertisements and
523 * restart auto-negotiation */
524 switchip_phy_write(phy_address
[0], 4, 0x05E1);
525 switchip_phy_write(phy_address
[0], 9, 0x0300);
526 switchip_phy_write(phy_address
[0], 0, 0x3300);
528 reg
= switchip_phy_read(phy_address
[1], 0);
529 reg
|= 0x1000; /* auto-negotiation enable */
530 switchip_phy_write(phy_address
[1], 0, reg
);
531 reg
|= 0x0200; /* auto-negotiation restart */
532 switchip_phy_write(phy_address
[1], 0, reg
);
535 /* Force SWITCH link with highest capability:
537 * 1G FD for GMII/RGMII
540 case 1: /* *MII,MII */
541 case 3: /* *MII,RGMII */
542 es_w32_mask(0, LTQ_ES_RGMII_CTL_REG_P0SPD_VAL(1),
544 es_w32_mask(0, LTQ_ES_RGMII_CTL_REG_P0DUP_VAL(1),
547 case 0: /* *RGMII,RGMII */
548 case 2: /* RGMII,*GMII */
549 es_w32_mask(0, LTQ_ES_RGMII_CTL_REG_P0SPD_VAL(2),
551 es_w32_mask(0, LTQ_ES_RGMII_CTL_REG_P0DUP_VAL(1),
554 es_w32_mask(LTQ_ES_RGMII_CTL_REG_P0RDLY
, 0, rgmii_ctl
);
555 es_w32_mask(0, LTQ_ES_RGMII_CTL_REG_P0TDLY_VAL(2),
560 es_w32_mask(0, LTQ_ES_P0_CTL_REG_FLP
, p0_ctl
);
563 /****** PORT 1 *****/
564 reg
= switchip_phy_read(phy_address
[1], 1);
565 if ((reg
!= 0x0000) && (reg
!= 0xffff)) {
568 /* Set Rx- and TxDelay in case of RGMII */
570 case 0: /* *RGMII,RGMII */
571 case 3: /* *MII,RGMII */
572 /* program clock delay in PHY, not in SVIP */
574 es_w32_mask(LTQ_ES_RGMII_CTL_REG_P1RDLY
, 0, rgmii_ctl
);
575 es_w32_mask(LTQ_ES_RGMII_CTL_REG_P1TDLY
, 0, rgmii_ctl
);
576 if (phy_oui
== PHY_OUI_VITESSE
||
577 phy_oui
== PHY_OUI_DEFAULT
) {
578 switchip_phy_write(phy_address
[1], 31, 0x0001);
579 switchip_phy_write(phy_address
[1], 28, 0xA000);
580 switchip_phy_write(phy_address
[1], 31, 0x0000);
583 case 2: /* RGMII,*GMII */
585 es_w32_mask(0, LTQ_ES_RGMII_CTL_REG_P1SPD_VAL(2),
587 es_w32_mask(0, LTQ_ES_RGMII_CTL_REG_P1DUP
, rgmii_ctl
);
588 #ifdef CONFIG_LANTIQ_MACH_EASY336
589 if (phy_oui
== PHY_OUI_PMC
) {
590 switchip_phy_write(phy_address
[1], 24, 0x0510);
591 switchip_phy_write(phy_address
[1], 17, 0xA38C);
592 switchip_phy_write(phy_address
[1], 17, 0xA384);
599 /* Program PHY advertisements and restart auto-negotiation */
600 if (phy_oui
== PHY_OUI_VITESSE
||
601 phy_oui
== PHY_OUI_DEFAULT
) {
602 switchip_phy_write(phy_address
[1], 4, 0x05E1);
603 switchip_phy_write(phy_address
[1], 9, 0x0300);
604 switchip_phy_write(phy_address
[1], 0, 0x3300);
606 reg
= switchip_phy_read(phy_address
[1], 0);
607 reg
|= 0x1000; /* auto-negotiation enable */
608 switchip_phy_write(phy_address
[1], 0, reg
);
609 reg
|= 0x0200; /* auto-negotiation restart */
610 switchip_phy_write(phy_address
[1], 0, reg
);
613 /* Force SWITCH link with highest capability:
615 * 1G FD for GMII/RGMII
618 case 1: /* *MII,MII */
619 es_w32_mask(0, LTQ_ES_RGMII_CTL_REG_P1SPD_VAL(1),
621 es_w32_mask(0, LTQ_ES_RGMII_CTL_REG_P1DUP
, rgmii_ctl
);
623 case 0: /* *RGMII,RGMII */
624 case 3: /* *MII,RGMII */
625 es_w32_mask(0, LTQ_ES_RGMII_CTL_REG_P1SPD_VAL(2),
627 es_w32_mask(0, LTQ_ES_RGMII_CTL_REG_P1DUP
, rgmii_ctl
);
628 es_w32_mask(LTQ_ES_RGMII_CTL_REG_P1RDLY
, 0, rgmii_ctl
);
629 es_w32_mask(0, LTQ_ES_RGMII_CTL_REG_P1TDLY_VAL(2),
632 case 2: /* RGMII,*GMII */
633 es_w32_mask(0, LTQ_ES_RGMII_CTL_REG_P1SPD_VAL(2),
635 es_w32_mask(0, LTQ_ES_RGMII_CTL_REG_P1DUP
, rgmii_ctl
);
638 es_w32_mask(0, LTQ_ES_P0_CTL_REG_FLP
, p0_ctl
);
642 * Allow unknown unicast/multicast and broadcasts
646 es_w32_mask(0, LTQ_ES_SW_GCTL1_REG_UP_VAL(7), sw_gctl1
);
647 es_w32_mask(0, LTQ_ES_SW_GCTL1_REG_BP_VAL(7), sw_gctl1
);
648 es_w32_mask(0, LTQ_ES_SW_GCTL1_REG_MP_VAL(7), sw_gctl1
);
649 es_w32_mask(0, LTQ_ES_SW_GCTL1_REG_RP_VAL(7), sw_gctl1
);
651 /* Enable LAN port(s) */
653 es_w32_mask(LTQ_ES_P0_CTL_REG_SPS
, 0, p0_ctl
);
655 es_w32_mask(LTQ_ES_P0_CTL_REG_SPS
, 0, p1_ctl
);
656 /* Enable CPU Port (Forwarding State) */
657 es_w32_mask(LTQ_ES_P0_CTL_REG_SPS
, 0, p2_ctl
);
660 switchip_mdio_poll_init();
664 EXPORT_SYMBOL(switchip_init
);
666 device_initcall(switchip_init
);