blob: 88bc813213c687aee442ec1c6706c40817514bd7 [file] [log] [blame]
wdenkac6dbb82003-03-26 11:42:53 +00001/*
2 * INCA-IP internal switch ethernet driver.
3 *
4 * (C) Copyright 2003
5 * Wolfgang Denk, DENX Software Engineering, wd@denx.de.
6 *
7 * See file CREDITS for list of people who contributed to this
8 * project.
9 *
10 * This program is free software; you can redistribute it and/or
11 * modify it under the terms of the GNU General Public License as
12 * published by the Free Software Foundation; either version 2 of
13 * the License, or (at your option) any later version.
14 *
15 * This program is distributed in the hope that it will be useful,
16 * but WITHOUT ANY WARRANTY; without even the implied warranty of
17 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18 * GNU General Public License for more details.
19 *
20 * You should have received a copy of the GNU General Public License
21 * along with this program; if not, write to the Free Software
22 * Foundation, Inc., 59 Temple Place, Suite 330, Boston,
23 * MA 02111-1307 USA
24 */
25
26
27#include <common.h>
28
29#if (CONFIG_COMMANDS & CFG_CMD_NET) && defined(CONFIG_NET_MULTI) \
30 && defined(CONFIG_INCA_IP_SWITCH)
31
32#include <malloc.h>
33#include <net.h>
34#include <asm/inca-ip.h>
35#include <asm/addrspace.h>
36
37
38#define NUM_RX_DESC PKTBUFSRX
39#define NUM_TX_DESC 3
40#define TOUT_LOOP 1000000
41
42
43#define DELAY udelay(10000)
44
45#define DMA_WRITE_REG(reg, value) *((volatile u32 *)reg) = (u32)value;
46#define DMA_READ_REG(reg, value) value = (u32)*((volatile u32*)reg)
47#define SW_WRITE_REG(reg, value) \
wdenk8bde7f72003-06-27 21:31:46 +000048 *((volatile u32*)reg) = (u32)value;\
49 DELAY;\
50 *((volatile u32*)reg) = (u32)value;
wdenkac6dbb82003-03-26 11:42:53 +000051
52#define SW_READ_REG(reg, value) \
wdenk8bde7f72003-06-27 21:31:46 +000053 value = (u32)*((volatile u32*)reg);\
54 DELAY;\
55 value = (u32)*((volatile u32*)reg);
wdenkac6dbb82003-03-26 11:42:53 +000056
57#define INCA_DMA_TX_POLLING_TIME 0x07
58#define INCA_DMA_RX_POLLING_TIME 0x07
59
60#define INCA_DMA_TX_HOLD 0x80000000
61#define INCA_DMA_TX_EOP 0x40000000
62#define INCA_DMA_TX_SOP 0x20000000
63#define INCA_DMA_TX_ICPT 0x10000000
64#define INCA_DMA_TX_IEOP 0x08000000
65
66#define INCA_DMA_RX_C 0x80000000
67#define INCA_DMA_RX_SOP 0x40000000
68#define INCA_DMA_RX_EOP 0x20000000
69
wdenkcf56e112004-02-20 22:02:48 +000070/************************ Auto MDIX settings ************************/
71#define INCA_IP_AUTO_MDIX_LAN_PORTS_DIR INCA_IP_Ports_P1_DIR
wdenk3c74e322004-02-22 23:46:08 +000072#define INCA_IP_AUTO_MDIX_LAN_PORTS_ALTSEL INCA_IP_Ports_P1_ALTSEL
wdenkcf56e112004-02-20 22:02:48 +000073#define INCA_IP_AUTO_MDIX_LAN_PORTS_OUT INCA_IP_Ports_P1_OUT
74#define INCA_IP_AUTO_MDIX_LAN_GPIO_PIN_RXTX 16
75
76#define WAIT_SIGNAL_RETRIES 100
77#define WAIT_LINK_RETRIES 100
78#define LINK_RETRY_DELAY 300 /* ms */
79/********************************************************************/
wdenkac6dbb82003-03-26 11:42:53 +000080
81typedef struct
82{
wdenke0ac62d2003-08-17 18:55:18 +000083 union {
84 struct {
wdenkac6dbb82003-03-26 11:42:53 +000085 volatile u32 HOLD :1;
86 volatile u32 ICpt :1;
87 volatile u32 IEop :1;
88 volatile u32 offset :3;
89 volatile u32 reserved0 :4;
90 volatile u32 NFB :22;
91 }field;
92
93 volatile u32 word;
94 }params;
95
96 volatile u32 nextRxDescPtr;
97
98 volatile u32 RxDataPtr;
99
wdenke0ac62d2003-08-17 18:55:18 +0000100 union {
101 struct {
wdenkac6dbb82003-03-26 11:42:53 +0000102 volatile u32 C :1;
103 volatile u32 Sop :1;
104 volatile u32 Eop :1;
105 volatile u32 reserved3 :12;
106 volatile u32 NBT :17;
107 }field;
108
109 volatile u32 word;
110 }status;
111
112} inca_rx_descriptor_t;
113
114
115typedef struct
116{
wdenke0ac62d2003-08-17 18:55:18 +0000117 union {
118 struct {
wdenkac6dbb82003-03-26 11:42:53 +0000119 volatile u32 HOLD :1;
120 volatile u32 Eop :1;
121 volatile u32 Sop :1;
122 volatile u32 ICpt :1;
123 volatile u32 IEop :1;
124 volatile u32 reserved0 :5;
125 volatile u32 NBA :22;
126 }field;
127
128 volatile u32 word;
129 }params;
130
131 volatile u32 nextTxDescPtr;
132
133 volatile u32 TxDataPtr;
134
135 volatile u32 C :1;
136 volatile u32 reserved3 :31;
137
138} inca_tx_descriptor_t;
139
140
141static inca_rx_descriptor_t rx_ring[NUM_RX_DESC] __attribute__ ((aligned(16)));
142static inca_tx_descriptor_t tx_ring[NUM_TX_DESC] __attribute__ ((aligned(16)));
143
144static int tx_new, rx_new, tx_hold, rx_hold;
145static int tx_old_hold = -1;
146static int initialized = 0;
147
148
149static int inca_switch_init(struct eth_device *dev, bd_t * bis);
150static int inca_switch_send(struct eth_device *dev, volatile void *packet,
151 int length);
152static int inca_switch_recv(struct eth_device *dev);
153static void inca_switch_halt(struct eth_device *dev);
154static void inca_init_switch_chip(void);
155static void inca_dma_init(void);
wdenkcf56e112004-02-20 22:02:48 +0000156static int inca_amdix(void);
wdenkac6dbb82003-03-26 11:42:53 +0000157
158
wdenkac6dbb82003-03-26 11:42:53 +0000159int inca_switch_initialize(bd_t * bis)
160{
161 struct eth_device *dev;
162
163#if 0
164 printf("Entered inca_switch_initialize()\n");
165#endif
166
wdenke0ac62d2003-08-17 18:55:18 +0000167 if (!(dev = (struct eth_device *) malloc (sizeof *dev))) {
wdenkac6dbb82003-03-26 11:42:53 +0000168 printf("Failed to allocate memory\n");
169 return 0;
170 }
171 memset(dev, 0, sizeof(*dev));
172
173 inca_dma_init();
174
175 inca_init_switch_chip();
wdenk3c74e322004-02-22 23:46:08 +0000176
wdenk0c852a22004-02-26 23:01:04 +0000177#if defined(CONFIG_INCA_IP_SWITCH_AMDIX)
wdenkcf56e112004-02-20 22:02:48 +0000178 inca_amdix();
wdenk0c852a22004-02-26 23:01:04 +0000179#endif
wdenkac6dbb82003-03-26 11:42:53 +0000180
181 sprintf(dev->name, "INCA-IP Switch");
182 dev->init = inca_switch_init;
183 dev->halt = inca_switch_halt;
184 dev->send = inca_switch_send;
185 dev->recv = inca_switch_recv;
186
187 eth_register(dev);
188
189#if 0
190 printf("Leaving inca_switch_initialize()\n");
191#endif
192
193 return 1;
194}
195
196
197static int inca_switch_init(struct eth_device *dev, bd_t * bis)
198{
199 int i;
200 u32 v, regValue;
201 u16 wTmp;
202
203#if 0
204 printf("Entering inca_switch_init()\n");
205#endif
206
wdenke0ac62d2003-08-17 18:55:18 +0000207 /* Set MAC address.
208 */
wdenkac6dbb82003-03-26 11:42:53 +0000209 wTmp = (u16)dev->enetaddr[0];
210 regValue = (wTmp << 8) | dev->enetaddr[1];
211
212 SW_WRITE_REG(INCA_IP_Switch_PMAC_SA1, regValue);
213
214 wTmp = (u16)dev->enetaddr[2];
215 regValue = (wTmp << 8) | dev->enetaddr[3];
216 regValue = regValue << 16;
217 wTmp = (u16)dev->enetaddr[4];
218 regValue |= (wTmp<<8) | dev->enetaddr[5];
219
220 SW_WRITE_REG(INCA_IP_Switch_PMAC_SA2, regValue);
221
wdenke0ac62d2003-08-17 18:55:18 +0000222 /* Initialize the descriptor rings.
223 */
wdenkac6dbb82003-03-26 11:42:53 +0000224 for (i = 0; i < NUM_RX_DESC; i++)
225 {
226 inca_rx_descriptor_t * rx_desc = KSEG1ADDR(&rx_ring[i]);
227 memset(rx_desc, 0, sizeof(rx_ring[i]));
228
wdenke0ac62d2003-08-17 18:55:18 +0000229 /* Set maximum size of receive buffer.
230 */
wdenkac6dbb82003-03-26 11:42:53 +0000231 rx_desc->params.field.NFB = PKTSIZE_ALIGN;
232
wdenke0ac62d2003-08-17 18:55:18 +0000233 /* Set the offset of the receive buffer. Zero means
234 * that the offset mechanism is not used.
235 */
wdenkac6dbb82003-03-26 11:42:53 +0000236 rx_desc->params.field.offset = 0;
237
238 /* Check if it is the last descriptor.
239 */
wdenke0ac62d2003-08-17 18:55:18 +0000240 if (i == (NUM_RX_DESC - 1)) {
241 /* Let the last descriptor point to the first
242 * one.
243 */
wdenkac6dbb82003-03-26 11:42:53 +0000244 rx_desc->nextRxDescPtr = KSEG1ADDR((u32)rx_ring);
wdenke0ac62d2003-08-17 18:55:18 +0000245 } else {
246 /* Set the address of the next descriptor.
247 */
wdenkac6dbb82003-03-26 11:42:53 +0000248 rx_desc->nextRxDescPtr = (u32)KSEG1ADDR(&rx_ring[i+1]);
249 }
250
251 rx_desc->RxDataPtr = (u32)KSEG1ADDR(NetRxPackets[i]);
252 }
253
254#if 0
255 printf("rx_ring = 0x%08X 0x%08X\n", (u32)rx_ring, (u32)&rx_ring[0]);
256 printf("tx_ring = 0x%08X 0x%08X\n", (u32)tx_ring, (u32)&tx_ring[0]);
257#endif
258
wdenke0ac62d2003-08-17 18:55:18 +0000259 for (i = 0; i < NUM_TX_DESC; i++) {
wdenkac6dbb82003-03-26 11:42:53 +0000260 inca_tx_descriptor_t * tx_desc = KSEG1ADDR(&tx_ring[i]);
261
262 memset(tx_desc, 0, sizeof(tx_ring[i]));
263
264 tx_desc->params.word = 0;
265 tx_desc->params.field.HOLD = 1;
266 tx_desc->C = 1;
267
268 /* Check if it is the last descriptor.
269 */
wdenke0ac62d2003-08-17 18:55:18 +0000270 if (i == (NUM_TX_DESC - 1)) {
wdenkac6dbb82003-03-26 11:42:53 +0000271 /* Let the last descriptor point to the
272 * first one.
273 */
274 tx_desc->nextTxDescPtr = KSEG1ADDR((u32)tx_ring);
wdenke0ac62d2003-08-17 18:55:18 +0000275 } else {
wdenkac6dbb82003-03-26 11:42:53 +0000276 /* Set the address of the next descriptor.
277 */
278 tx_desc->nextTxDescPtr = (u32)KSEG1ADDR(&tx_ring[i+1]);
279 }
280 }
281
wdenke0ac62d2003-08-17 18:55:18 +0000282 /* Initialize RxDMA.
283 */
wdenkac6dbb82003-03-26 11:42:53 +0000284 DMA_READ_REG(INCA_IP_DMA_DMA_RXISR, v);
285#if 0
286 printf("RX status = 0x%08X\n", v);
287#endif
288
wdenke0ac62d2003-08-17 18:55:18 +0000289 /* Writing to the FRDA of CHANNEL.
290 */
wdenkac6dbb82003-03-26 11:42:53 +0000291 DMA_WRITE_REG(INCA_IP_DMA_DMA_RXFRDA0, (u32)rx_ring);
292
wdenke0ac62d2003-08-17 18:55:18 +0000293 /* Writing to the COMMAND REG.
294 */
wdenkac6dbb82003-03-26 11:42:53 +0000295 DMA_WRITE_REG(INCA_IP_DMA_DMA_RXCCR0,
wdenk8bde7f72003-06-27 21:31:46 +0000296 INCA_IP_DMA_DMA_RXCCR0_INIT);
wdenkac6dbb82003-03-26 11:42:53 +0000297
wdenke0ac62d2003-08-17 18:55:18 +0000298 /* Initialize TxDMA.
299 */
wdenkac6dbb82003-03-26 11:42:53 +0000300 DMA_READ_REG(INCA_IP_DMA_DMA_TXISR, v);
301#if 0
302 printf("TX status = 0x%08X\n", v);
303#endif
304
wdenke0ac62d2003-08-17 18:55:18 +0000305 /* Writing to the FRDA of CHANNEL.
306 */
wdenkac6dbb82003-03-26 11:42:53 +0000307 DMA_WRITE_REG(INCA_IP_DMA_DMA_TXFRDA0, (u32)tx_ring);
308
309 tx_new = rx_new = 0;
310
311 tx_hold = NUM_TX_DESC - 1;
312 rx_hold = NUM_RX_DESC - 1;
313
314#if 0
315 rx_ring[rx_hold].params.field.HOLD = 1;
316#endif
wdenke0ac62d2003-08-17 18:55:18 +0000317 /* enable spanning tree forwarding, enable the CPU port */
318 /* ST_PT:
319 * CPS (CPU port status) 0x3 (forwarding)
320 * LPS (LAN port status) 0x3 (forwarding)
321 * PPS (PC port status) 0x3 (forwarding)
322 */
wdenkac6dbb82003-03-26 11:42:53 +0000323 SW_WRITE_REG(INCA_IP_Switch_ST_PT,0x3f);
324
325#if 0
326 printf("Leaving inca_switch_init()\n");
327#endif
328
329 return 0;
330}
331
332
333static int inca_switch_send(struct eth_device *dev, volatile void *packet,
334 int length)
335{
336 int i;
337 int res = -1;
338 u32 command;
339 u32 regValue;
340 inca_tx_descriptor_t * tx_desc = KSEG1ADDR(&tx_ring[tx_new]);
341
342#if 0
343 printf("Entered inca_switch_send()\n");
344#endif
345
wdenke0ac62d2003-08-17 18:55:18 +0000346 if (length <= 0) {
wdenkac6dbb82003-03-26 11:42:53 +0000347 printf ("%s: bad packet size: %d\n", dev->name, length);
348 goto Done;
349 }
wdenk8bde7f72003-06-27 21:31:46 +0000350
wdenke0ac62d2003-08-17 18:55:18 +0000351 for(i = 0; tx_desc->C == 0; i++) {
352 if (i >= TOUT_LOOP) {
wdenkac6dbb82003-03-26 11:42:53 +0000353 printf("%s: tx error buffer not ready\n", dev->name);
354 goto Done;
355 }
356 }
357
wdenke0ac62d2003-08-17 18:55:18 +0000358 if (tx_old_hold >= 0) {
wdenkac6dbb82003-03-26 11:42:53 +0000359 KSEG1ADDR(&tx_ring[tx_old_hold])->params.field.HOLD = 1;
360 }
361 tx_old_hold = tx_hold;
362
363 tx_desc->params.word =
wdenk8bde7f72003-06-27 21:31:46 +0000364 (INCA_DMA_TX_SOP | INCA_DMA_TX_EOP | INCA_DMA_TX_HOLD);
wdenkac6dbb82003-03-26 11:42:53 +0000365
366 tx_desc->C = 0;
367 tx_desc->TxDataPtr = (u32)packet;
368 tx_desc->params.field.NBA = length;
369
370 KSEG1ADDR(&tx_ring[tx_hold])->params.field.HOLD = 0;
371
372 tx_hold = tx_new;
373 tx_new = (tx_new + 1) % NUM_TX_DESC;
374
375
wdenke0ac62d2003-08-17 18:55:18 +0000376 if (! initialized) {
wdenkac6dbb82003-03-26 11:42:53 +0000377 command = INCA_IP_DMA_DMA_TXCCR0_INIT;
378 initialized = 1;
wdenke0ac62d2003-08-17 18:55:18 +0000379 } else {
wdenkac6dbb82003-03-26 11:42:53 +0000380 command = INCA_IP_DMA_DMA_TXCCR0_HR;
381 }
wdenk8bde7f72003-06-27 21:31:46 +0000382
wdenkac6dbb82003-03-26 11:42:53 +0000383 DMA_READ_REG(INCA_IP_DMA_DMA_TXCCR0, regValue);
384 regValue |= command;
385#if 0
386 printf("regValue = 0x%x\n", regValue);
387#endif
388 DMA_WRITE_REG(INCA_IP_DMA_DMA_TXCCR0, regValue);
389
390#if 1
wdenke0ac62d2003-08-17 18:55:18 +0000391 for(i = 0; KSEG1ADDR(&tx_ring[tx_hold])->C == 0; i++) {
392 if (i >= TOUT_LOOP) {
wdenkac6dbb82003-03-26 11:42:53 +0000393 printf("%s: tx buffer not ready\n", dev->name);
394 goto Done;
395 }
396 }
397#endif
398 res = length;
399Done:
400#if 0
401 printf("Leaving inca_switch_send()\n");
402#endif
403 return res;
404}
405
406
407static int inca_switch_recv(struct eth_device *dev)
408{
409 int length = 0;
410 inca_rx_descriptor_t * rx_desc;
411
412#if 0
413 printf("Entered inca_switch_recv()\n");
414#endif
415
wdenke0ac62d2003-08-17 18:55:18 +0000416 for (;;) {
wdenkac6dbb82003-03-26 11:42:53 +0000417 rx_desc = KSEG1ADDR(&rx_ring[rx_new]);
418
wdenke0ac62d2003-08-17 18:55:18 +0000419 if (rx_desc->status.field.C == 0) {
wdenkac6dbb82003-03-26 11:42:53 +0000420 break;
421 }
422
423#if 0
424 rx_ring[rx_new].params.field.HOLD = 1;
425#endif
426
wdenke0ac62d2003-08-17 18:55:18 +0000427 if (! rx_desc->status.field.Eop) {
wdenkac6dbb82003-03-26 11:42:53 +0000428 printf("Partly received packet!!!\n");
429 break;
430 }
431
432 length = rx_desc->status.field.NBT;
433 rx_desc->status.word &=
wdenk8bde7f72003-06-27 21:31:46 +0000434 ~(INCA_DMA_RX_EOP | INCA_DMA_RX_SOP | INCA_DMA_RX_C);
wdenkac6dbb82003-03-26 11:42:53 +0000435#if 0
436{
437 int i;
438 for (i=0;i<length - 4;i++) {
439 if (i % 16 == 0) printf("\n%04x: ", i);
440 printf("%02X ", NetRxPackets[rx_new][i]);
441 }
442 printf("\n");
443}
444#endif
445
wdenke0ac62d2003-08-17 18:55:18 +0000446 if (length) {
wdenkac6dbb82003-03-26 11:42:53 +0000447#if 0
448 printf("Received %d bytes\n", length);
449#endif
450 NetReceive((void*)KSEG1ADDR(NetRxPackets[rx_new]),
wdenk8bde7f72003-06-27 21:31:46 +0000451 length - 4);
wdenke0ac62d2003-08-17 18:55:18 +0000452 } else {
wdenkac6dbb82003-03-26 11:42:53 +0000453#if 1
454 printf("Zero length!!!\n");
455#endif
456 }
457
458
459 KSEG1ADDR(&rx_ring[rx_hold])->params.field.HOLD = 0;
460
461 rx_hold = rx_new;
462
463 rx_new = (rx_new + 1) % NUM_RX_DESC;
464 }
465
466#if 0
467 printf("Leaving inca_switch_recv()\n");
468#endif
469
470 return length;
471}
472
473
474static void inca_switch_halt(struct eth_device *dev)
475{
476#if 0
477 printf("Entered inca_switch_halt()\n");
478#endif
479
480#if 1
481 initialized = 0;
482#endif
483#if 1
wdenke0ac62d2003-08-17 18:55:18 +0000484 /* Disable forwarding to the CPU port.
485 */
wdenkac6dbb82003-03-26 11:42:53 +0000486 SW_WRITE_REG(INCA_IP_Switch_ST_PT,0xf);
487
wdenke0ac62d2003-08-17 18:55:18 +0000488 /* Close RxDMA channel.
489 */
wdenkac6dbb82003-03-26 11:42:53 +0000490 DMA_WRITE_REG(INCA_IP_DMA_DMA_RXCCR0, INCA_IP_DMA_DMA_RXCCR0_OFF);
491
wdenke0ac62d2003-08-17 18:55:18 +0000492 /* Close TxDMA channel.
493 */
wdenkac6dbb82003-03-26 11:42:53 +0000494 DMA_WRITE_REG(INCA_IP_DMA_DMA_TXCCR0, INCA_IP_DMA_DMA_TXCCR0_OFF);
495
496
497#endif
498#if 0
499 printf("Leaving inca_switch_halt()\n");
500#endif
501}
502
503
504static void inca_init_switch_chip(void)
505{
506 u32 regValue;
507
wdenke0ac62d2003-08-17 18:55:18 +0000508 /* To workaround a problem with collision counter
509 * (see Errata sheet).
510 */
wdenkac6dbb82003-03-26 11:42:53 +0000511 SW_WRITE_REG(INCA_IP_Switch_PC_TX_CTL, 0x00000001);
512 SW_WRITE_REG(INCA_IP_Switch_LAN_TX_CTL, 0x00000001);
513
514#if 1
wdenke0ac62d2003-08-17 18:55:18 +0000515 /* init MDIO configuration:
516 * MDS (Poll speed): 0x01 (4ms)
517 * PHY_LAN_ADDR: 0x06
518 * PHY_PC_ADDR: 0x05
519 * UEP (Use External PHY): 0x00 (Internal PHY is used)
520 * PS (Port Select): 0x00 (PT/UMM for LAN)
521 * PT (PHY Test): 0x00 (no test mode)
522 * UMM (Use MDIO Mode): 0x00 (state machine is disabled)
523 */
wdenkac6dbb82003-03-26 11:42:53 +0000524 SW_WRITE_REG(INCA_IP_Switch_MDIO_CFG, 0x4c50);
525
wdenke0ac62d2003-08-17 18:55:18 +0000526 /* init PHY:
527 * SL (Auto Neg. Speed for LAN)
528 * SP (Auto Neg. Speed for PC)
529 * LL (Link Status for LAN)
530 * LP (Link Status for PC)
531 * DL (Duplex Status for LAN)
532 * DP (Duplex Status for PC)
533 * PL (Auto Neg. Pause Status for LAN)
534 * PP (Auto Neg. Pause Status for PC)
535 */
wdenkac6dbb82003-03-26 11:42:53 +0000536 SW_WRITE_REG (INCA_IP_Switch_EPHY, 0xff);
537
wdenke0ac62d2003-08-17 18:55:18 +0000538 /* MDIO_ACC:
539 * RA (Request/Ack) 0x01 (Request)
540 * RW (Read/Write) 0x01 (Write)
541 * PHY_ADDR 0x05 (PC)
542 * REG_ADDR 0x00 (PHY_BCR: basic control register)
543 * PHY_DATA 0x8000
544 * Reset - software reset
545 * LB (loop back) - normal
546 * SS (speed select) - 10 Mbit/s
547 * ANE (auto neg. enable) - enable
548 * PD (power down) - normal
549 * ISO (isolate) - normal
550 * RAN (restart auto neg.) - normal
551 * DM (duplex mode) - half duplex
552 * CT (collision test) - enable
553 */
554 SW_WRITE_REG(INCA_IP_Switch_MDIO_ACC, 0xc0a09000);
wdenkac6dbb82003-03-26 11:42:53 +0000555
wdenke0ac62d2003-08-17 18:55:18 +0000556 /* MDIO_ACC:
557 * RA (Request/Ack) 0x01 (Request)
558 * RW (Read/Write) 0x01 (Write)
559 * PHY_ADDR 0x06 (LAN)
560 * REG_ADDR 0x00 (PHY_BCR: basic control register)
561 * PHY_DATA 0x8000
562 * Reset - software reset
563 * LB (loop back) - normal
564 * SS (speed select) - 10 Mbit/s
565 * ANE (auto neg. enable) - enable
566 * PD (power down) - normal
567 * ISO (isolate) - normal
568 * RAN (restart auto neg.) - normal
569 * DM (duplex mode) - half duplex
570 * CT (collision test) - enable
571 */
572 SW_WRITE_REG(INCA_IP_Switch_MDIO_ACC, 0xc0c09000);
573
wdenkac6dbb82003-03-26 11:42:53 +0000574#endif
575
wdenke0ac62d2003-08-17 18:55:18 +0000576 /* Make sure the CPU port is disabled for now. We
577 * don't want packets to get stacked for us until
578 * we enable DMA and are prepared to receive them.
579 */
wdenkac6dbb82003-03-26 11:42:53 +0000580 SW_WRITE_REG(INCA_IP_Switch_ST_PT,0xf);
581
582 SW_READ_REG(INCA_IP_Switch_ARL_CTL, regValue);
583
wdenke0ac62d2003-08-17 18:55:18 +0000584 /* CRC GEN is enabled.
585 */
wdenkac6dbb82003-03-26 11:42:53 +0000586 regValue |= 0x00000200;
587 SW_WRITE_REG(INCA_IP_Switch_ARL_CTL, regValue);
588
wdenke0ac62d2003-08-17 18:55:18 +0000589 /* ADD TAG is disabled.
590 */
wdenkac6dbb82003-03-26 11:42:53 +0000591 SW_READ_REG(INCA_IP_Switch_PMAC_HD_CTL, regValue);
592 regValue &= ~0x00000002;
593 SW_WRITE_REG(INCA_IP_Switch_PMAC_HD_CTL, regValue);
594}
595
596
597static void inca_dma_init(void)
598{
wdenke0ac62d2003-08-17 18:55:18 +0000599 /* Switch off all DMA channels.
600 */
wdenkac6dbb82003-03-26 11:42:53 +0000601 DMA_WRITE_REG(INCA_IP_DMA_DMA_RXCCR0, INCA_IP_DMA_DMA_RXCCR0_OFF);
602 DMA_WRITE_REG(INCA_IP_DMA_DMA_RXCCR1, INCA_IP_DMA_DMA_RXCCR1_OFF);
603
604 DMA_WRITE_REG(INCA_IP_DMA_DMA_TXCCR0, INCA_IP_DMA_DMA_RXCCR0_OFF);
605 DMA_WRITE_REG(INCA_IP_DMA_DMA_TXCCR1, INCA_IP_DMA_DMA_TXCCR1_OFF);
606 DMA_WRITE_REG(INCA_IP_DMA_DMA_TXCCR2, INCA_IP_DMA_DMA_TXCCR2_OFF);
607
wdenke0ac62d2003-08-17 18:55:18 +0000608 /* Setup TX channel polling time.
609 */
wdenkac6dbb82003-03-26 11:42:53 +0000610 DMA_WRITE_REG(INCA_IP_DMA_DMA_TXPOLL, INCA_DMA_TX_POLLING_TIME);
611
wdenke0ac62d2003-08-17 18:55:18 +0000612 /* Setup RX channel polling time.
613 */
wdenkac6dbb82003-03-26 11:42:53 +0000614 DMA_WRITE_REG(INCA_IP_DMA_DMA_RXPOLL, INCA_DMA_RX_POLLING_TIME);
615
wdenke0ac62d2003-08-17 18:55:18 +0000616 /* ERRATA: write reset value into the DMA RX IMR register.
617 */
wdenkac6dbb82003-03-26 11:42:53 +0000618 DMA_WRITE_REG(INCA_IP_DMA_DMA_RXIMR, 0xFFFFFFFF);
619
wdenke0ac62d2003-08-17 18:55:18 +0000620 /* Just in case: disable all transmit interrupts also.
621 */
wdenkac6dbb82003-03-26 11:42:53 +0000622 DMA_WRITE_REG(INCA_IP_DMA_DMA_TXIMR, 0xFFFFFFFF);
623
624 DMA_WRITE_REG(INCA_IP_DMA_DMA_TXISR, 0xFFFFFFFF);
625 DMA_WRITE_REG(INCA_IP_DMA_DMA_RXISR, 0xFFFFFFFF);
626}
627
wdenk0c852a22004-02-26 23:01:04 +0000628#if defined(CONFIG_INCA_IP_SWITCH_AMDIX)
wdenkcf56e112004-02-20 22:02:48 +0000629static int inca_amdix(void)
630{
631 u32 regValue = 0;
632 int mdi_flag;
633 int retries;
634
635 /* Setup GPIO pins.
636 */
637 *INCA_IP_AUTO_MDIX_LAN_PORTS_DIR |= (1 << INCA_IP_AUTO_MDIX_LAN_GPIO_PIN_RXTX);
638 *INCA_IP_AUTO_MDIX_LAN_PORTS_ALTSEL |= (1 << INCA_IP_AUTO_MDIX_LAN_GPIO_PIN_RXTX);
639
640 /* Wait for signal.
641 */
642 retries = WAIT_SIGNAL_RETRIES;
643 while (--retries)
644 {
645 SW_WRITE_REG(INCA_IP_Switch_MDIO_ACC,
646 (0x1 << 31) | /* RA */
647 (0x0 << 30) | /* Read */
648 (0x6 << 21) | /* LAN */
649 (17 << 16)); /* PHY_MCSR */
650 do
651 {
652 SW_READ_REG(INCA_IP_Switch_MDIO_ACC, regValue);
653 }
654 while (regValue & (1 << 31));
655
656 if (regValue & (1 << 1))
657 {
658 /* Signal detected */
659 break;
660 }
661 }
662
663 if (!retries)
664 return -1;
665
666 /* Set MDI mode.
667 */
668 *INCA_IP_AUTO_MDIX_LAN_PORTS_OUT &= ~(1 << INCA_IP_AUTO_MDIX_LAN_GPIO_PIN_RXTX);
669 mdi_flag = 1;
670
671 /* Wait for link.
672 */
673 retries = WAIT_LINK_RETRIES;
674 while (--retries)
675 {
676 udelay(LINK_RETRY_DELAY * 1000);
677 SW_WRITE_REG(INCA_IP_Switch_MDIO_ACC,
678 (0x1 << 31) | /* RA */
679 (0x0 << 30) | /* Read */
680 (0x6 << 21) | /* LAN */
681 (1 << 16)); /* PHY_BSR */
682 do
683 {
684 SW_READ_REG(INCA_IP_Switch_MDIO_ACC, regValue);
685 }
686 while (regValue & (1 << 31));
687
688 if (regValue & (1 << 2))
689 {
690 /* Link is up */
691 break;
692 }
693 else if (mdi_flag)
694 {
695 /* Set MDIX mode */
696 *INCA_IP_AUTO_MDIX_LAN_PORTS_OUT |= (1 << INCA_IP_AUTO_MDIX_LAN_GPIO_PIN_RXTX);
697 mdi_flag = 0;
698 }
699 else
700 {
701 /* Set MDI mode */
702 *INCA_IP_AUTO_MDIX_LAN_PORTS_OUT &= ~(1 << INCA_IP_AUTO_MDIX_LAN_GPIO_PIN_RXTX);
703 mdi_flag = 1;
704 }
705 }
706
707 if (!retries)
708 return -1;
709
710 return 0;
711}
wdenk0c852a22004-02-26 23:01:04 +0000712#endif /* CONFIG_INCA_IP_SWITCH_AMDIX */
wdenkcf56e112004-02-20 22:02:48 +0000713
wdenkac6dbb82003-03-26 11:42:53 +0000714#endif