summaryrefslogtreecommitdiffstats
path: root/board/mpl/pati/pati.c
blob: 0355b65b841a82070dd72f3da896a35cc8520097 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
/*
 * (C) Copyright 2003
 * Martin Winistoerfer, martinwinistoerfer@gmx.ch.
 * Atapted for PATI
 * Denis Peter, d.peter@mpl.ch
 * See file CREDITS for list of people who contributed to this
 * project.
 *
 * This program is free software; you can redistribute it and/or
 * modify it under the terms of the GNU General Public License as
 * published by the Free Software Foundation; either version 2 of
 * the License, or (at your option) any later version.
 *
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License
 * along with this program; if not, write to the Free Software
 * Foundation, Inc., 59 Temple Place, Suite 330, Boston,
 * MA 02111-1307 USA
 */

/***********************************************************************************
 * Bits for the SDRAM controller
 * -----------------------------
 *
 * CAL:	CAS Latency. If cleared to 0 (default) the SDRAM controller asserts TA# on
 *	the 2nd Clock after ACTIVE command (CAS Latency = 2). If set to 1 the SDRAM
 *	controller asserts TA# on the 3rd Clock after ACTIVE command (CAS Latency = 3).
 * RCD:	RCD ACTIVE to READ or WRITE Delay (Ras to Cas Delay). If cleared 0 (default)
 *	tRCD of the SDRAM must equal or less 25ns. If set to 1 tRCD must be equal or less 50ns.
 * WREC:Write Recovery. If cleared 0 (default) tWR of the SDRAM must equal or less 25ns.
 *	If set to 1 tWR must be equal or less 50ns.
 * RP:	Precharge Command Time. If cleared 0 (default) tRP of the SDRAM must equal or less
 *	25ns. If set to 1 tRP must be equal or less 50ns.
 * RC:	Auto Refresh to Active Time. If cleared 0 (default) tRC of the SDRAM must equal
 *	or less 75ns. If set to 1 tRC must be equal or less 100ns.
 * LMR:	Bit to set the Mode Register of the SDRAM. If set, the next access to the SDRAM
 *	is the Load Mode Register Command.
 * IIP:	Init in progress. Set to 1 for starting the init sequence
 *	(Precharge All). As long this bit is set, the Precharge All is still in progress.
 *	After command has completed, wait at least for 8 refresh (200usec) before proceed.
 **********************************************************************************/

#include <common.h>
#include <mpc5xx.h>
#include <devices.h>
#include <pci_ids.h>
#define PLX9056_LOC
#include "plx9056.h"
#include "pati.h"

#if defined(__APPLE__)
/* Leading underscore on symbols */
#  define SYM_CHAR "_"
#else /* No leading character on symbols */
#  define SYM_CHAR
#endif

#undef SDRAM_DEBUG
/*
 * Macros to generate global absolutes.
 */
#define GEN_SYMNAME(str) SYM_CHAR #str
#define GEN_VALUE(str) #str
#define GEN_ABS(name, value) \
		asm (".globl " GEN_SYMNAME(name)); \
		asm (GEN_SYMNAME(name) " = " GEN_VALUE(value))


/************************************************************************
 * Early debug routines
 */
void write_hex (unsigned char i)
{
	char cc;

	cc = i >> 4;
	cc &= 0xf;
	if (cc > 9)
		serial_putc (cc + 55);
	else
		serial_putc (cc + 48);
	cc = i & 0xf;
	if (cc > 9)
		serial_putc (cc + 55);
	else
		serial_putc (cc + 48);
}

#if defined(SDRAM_DEBUG)

void write_4hex (unsigned long val)
{
	write_hex ((unsigned char) (val >> 24));
	write_hex ((unsigned char) (val >> 16));
	write_hex ((unsigned char) (val >> 8));
	write_hex ((unsigned char) val);
}

#endif

unsigned long in32(unsigned long addr)
{
	unsigned long *p=(unsigned long *)addr;
	return *p;
}

void out32(unsigned long addr,unsigned long data)
{
	unsigned long *p=(unsigned long *)addr;
	*p=data;
}

typedef struct {
	unsigned short boardtype; /* Board revision and Population Options */
	unsigned char cal;		/* cas Latency  0:CAL=2 1:CAL=3 */
	unsigned char rcd;		/* ras to cas delay  0:<25ns 1:<50ns*/
	unsigned char wrec;		/* write recovery 0:<25ns 1:<50ns */
	unsigned char pr;		/* Precharge Command Time 0:<25ns 1:<50ns */
	unsigned char rc;		/* Auto Refresh to Active Time 0:<75ns 1:<100ns */
	unsigned char sz;		/* log binary => Size = (4MByte<<sz) 5 = 128, 4 = 64, 3 = 32, 2 = 16, 1=8 */
} sdram_t;

const sdram_t sdram_table[] = {
	{ 0x0000,	/* PATI Rev A, 16MByte -1 Board */
		1,	/* Case Latenty = 3 */
		0,	/* ras to cas delay  0 (20ns) */
		0,	/* write recovery 0:<25ns 1:<50ns*/
		0,	/* Precharge Command Time 0 (20ns) */
		0,	/* Auto Refresh to Active Time 0 (68) */
		2	/* log binary => Size 2 = 16MByte, 1=8 */
	},
	{ 0xffff, /* terminator */
	  0xff,
	  0xff,
	  0xff,
	  0xff,
	  0xff,
	  0xff }
};


extern int mem_test (unsigned long start, unsigned long ramsize, int quiet);
extern void mem_test_reloc(void);

/*
 * Get RAM size.
 */
long int initdram(int board_type)
{
	unsigned char board_rev;
	unsigned long reg;
	unsigned long lmr;
	int i,timeout;

#if defined(SDRAM_DEBUG)
	reg=in32(PLD_CONFIG_BASE+PLD_PART_ID);
	puts("\n\nSYSTEM part 0x"); write_4hex(SYSCNTR_PART(reg));
	puts(" Vers 0x"); write_4hex(SYSCNTR_ID(reg));
	puts("\nSDRAM  part  0x"); write_4hex(SDRAM_PART(reg));
	puts(" Vers 0x"); write_4hex(SDRAM_ID(reg));
	reg=in32(PLD_CONFIG_BASE+PLD_BOARD_TIMING);
	puts("\nBoard rev.   0x"); write_4hex(SYSCNTR_BREV(reg));
   putc('\n');
#endif
	reg=in32(PLD_CONFIG_BASE+PLD_BOARD_TIMING);
	board_rev=(unsigned char)(SYSCNTR_BREV(reg));
	i=0;
	while(1) {
		if(sdram_table[i].boardtype==0xffff) {
			puts("ERROR, found no table for Board 0x");
			write_hex(board_rev);
			while(1);
		}
		if(sdram_table[i].boardtype==(unsigned char)board_rev)
			break;
		i++;
	}
	/* Set CAL, RCD, WREQ, PR and RC Bits */
#if defined(SDRAM_DEBUG)
	puts("Set CAL, RCD, WREQ, PR and RC Bits\n");
#endif
	/* mask bits */
	reg &= ~(SET_REG_BIT(1,SDRAM_CAL) | SET_REG_BIT(1,SDRAM_RCD) | SET_REG_BIT(1,SDRAM_WREQ) |
				SET_REG_BIT(1,SDRAM_PR)  |  SET_REG_BIT(1,SDRAM_RC) | SET_REG_BIT(1,SDRAM_LMR)  |
				SET_REG_BIT(1,SDRAM_IIP) | SET_REG_BIT(1,SDRAM_RES0));
	/* set bits */
	reg |= (SET_REG_BIT(sdram_table[i].cal,SDRAM_CAL) |
			  SET_REG_BIT(sdram_table[i].rcd,SDRAM_RCD) |
			  SET_REG_BIT(sdram_table[i].wrec,SDRAM_WREQ) |
			  SET_REG_BIT(sdram_table[i].pr,SDRAM_PR) |
			  SET_REG_BIT(sdram_table[i].rc,SDRAM_RC));

	out32(PLD_CONFIG_BASE+PLD_BOARD_TIMING,reg);
	/* step 2 set IIP */
#if defined(SDRAM_DEBUG)
	puts("step 2 set IIP\n");
#endif
	/* step 2 set IIP */
	reg |= SET_REG_BIT(1,SDRAM_IIP);
	timeout=0;
	while (timeout!=0xffff) {
		__asm__ volatile("eieio");
		reg=in32(PLD_CONFIG_BASE+PLD_BOARD_TIMING);
		if((reg & SET_REG_BIT(1,SDRAM_IIP))==0)
			break;
		timeout++;
		udelay(1);
	}
	/* wait for at least 8 refresh */
	udelay(1000);
	/* set LMR */
	reg |= SET_REG_BIT(1,SDRAM_LMR);
	out32(PLD_CONFIG_BASE+PLD_BOARD_TIMING,reg);
	__asm__ volatile("eieio");
	lmr=0x00000002; /* sequential burst 4 data */
	if(sdram_table[i].cal==1)
		lmr|=0x00000030; /* cal = 3 */
	else
		lmr|=0000000020; /* cal = 2 */
	/* rest standard operation programmed write burst length */
	/* we have a x32 bit bus to the SDRAM, so shift the addr with 2 */
	lmr<<=2;
	in32(CFG_SDRAM_BASE + lmr);
	/* ok, we're done, return SDRAM size */
	return ((0x400000 << sdram_table[i].sz));		/* log2 value of 4MByte  */
}


void set_flash_vpp(int ext_vpp, int ext_wp, int int_vpp)
{
	unsigned long reg;
	reg=in32(PLD_CONF_REG2+PLD_CONFIG_BASE);
	reg &= ~(SET_REG_BIT(1,SYSCNTR_CPU_VPP) |
			   SET_REG_BIT(1,SYSCNTR_FL_VPP) |
				SET_REG_BIT(1,SYSCNTR_FL_WP));

	reg |= (SET_REG_BIT(int_vpp,SYSCNTR_CPU_VPP) |
			   SET_REG_BIT(ext_vpp,SYSCNTR_FL_VPP) |
				SET_REG_BIT(ext_wp,SYSCNTR_FL_WP));
	out32(PLD_CONF_REG2+PLD_CONFIG_BASE,reg);
	udelay(100);
}


void show_pld_regs(void)
{
	unsigned long reg,reg1;
	reg=in32(PLD_CONFIG_BASE+PLD_PART_ID);
	printf("\nSYSTEM part %ld, Vers %ld\n",SYSCNTR_PART(reg),SYSCNTR_ID(reg));
	printf("SDRAM  part %ld, Vers %ld\n",SDRAM_PART(reg),SDRAM_ID(reg));
	reg=in32(PLD_CONFIG_BASE+PLD_BOARD_TIMING);
	printf("Board rev.  %c\n",(char) (SYSCNTR_BREV(reg)+'A'));
	printf("Waitstates  %ld\n",GET_SYSCNTR_FLWAIT(reg));
	printf("SDRAM:      CAL=%ld RCD=%ld WREQ=%ld PR=%ld\n            RC=%ld  LMR=%ld IIP=%ld\n",
		GET_REG_BIT(reg,SDRAM_CAL),GET_REG_BIT(reg,SDRAM_RCD),
		GET_REG_BIT(reg,SDRAM_WREQ),GET_REG_BIT(reg,SDRAM_PR),
		GET_REG_BIT(reg,SDRAM_RC),GET_REG_BIT(reg,SDRAM_LMR),
		GET_REG_BIT(reg,SDRAM_IIP));
	reg=in32(PLD_CONFIG_BASE+PLD_CONF_REG1);
	reg1=in32(PLD_CONFIG_BASE+PLD_CONF_REG2);
	printf("HW Config:  FLAG=%ld IP=%ld  index=%ld PRPM=%ld\n            ICW=%ld  ISB=%ld BDIS=%ld  PCIM=%ld\n",
		GET_REG_BIT(reg,SYSCNTR_FLAG),GET_REG_BIT(reg,SYSCNTR_IP),
		GET_SYSCNTR_BOOTIND(reg),GET_REG_BIT(reg,SYSCNTR_PRM),
		GET_REG_BIT(reg,SYSCNTR_ICW),GET_SYSCNTR_ISB(reg),
		GET_REG_BIT(reg1,SYSCNTR_BDIS),GET_REG_BIT(reg1,SYSCNTR_PCIM));
	printf("Switches:   MUX=%ld PCI_DIS=%ld Boot_EN=%ld  Config=%ld\n",GET_SDRAM_MUX(reg),
		GET_REG_BIT(reg,SDRAM_PDIS),GET_REG_BIT(reg1,SYSCNTR_BOOTEN),
		GET_SYSCNTR_CFG(reg1));
	printf("Misc:       RIP=%ld CPU_VPP=%ld FLSH_VPP=%ld FLSH_WP=%ld\n\n",
		GET_REG_BIT(reg,SDRAM_RIP),GET_REG_BIT(reg1,SYSCNTR_CPU_VPP),
		GET_REG_BIT(reg1,SYSCNTR_FL_VPP),GET_REG_BIT(reg1,SYSCNTR_FL_WP));
}


/****************************************************************
 * Setting IOs
 * -----------
 * GPIO6 is User LED1
 * GPIO7 is Interrupt PLX (Output)
 * GPIO5 is User LED0
 * GPIO2 is PLX USERi (Output)
 * GPIO1 is PLX Interrupt (Input)
 ****************************************************************/
 void init_ios(void)
 {
	volatile immap_t * immr = (immap_t *) CFG_IMMR;
	volatile sysconf5xx_t *sysconf = &immr->im_siu_conf;
	unsigned long reg;
	reg=sysconf->sc_sgpiocr; /* Data direction register */
	reg &= ~0x67000000;
	reg |= 0x27000000; /* set outpupts */
	sysconf->sc_sgpiocr=reg; /* Data direction register */
	reg=sysconf->sc_sgpiodt2; /* Data register */
	/* set output to 0 */
	reg &= ~0x27000000;
	/* set IRQ and USERi to 1 */
	reg |= 0x28000000;
	sysconf->sc_sgpiodt2=reg; /* Data register */
}

void user_led0(int led_on)
{
	volatile immap_t * immr = (immap_t *) CFG_IMMR;
	volatile sysconf5xx_t *sysconf = &immr->im_siu_conf;
	unsigned long reg;
	reg=sysconf->sc_sgpiodt2; /* Data register */
	if(led_on)	/* set output to 1 */
		reg |= 0x04000000;
	else
		reg &= ~0x04000000;
	sysconf->sc_sgpiodt2=reg; /* Data register */
}

void user_led1(int led_on)
{
	volatile immap_t * immr = (immap_t *) CFG_IMMR;
	volatile sysconf5xx_t *sysconf = &immr->im_siu_conf;
	unsigned long reg;
	reg=sysconf->sc_sgpiodt2; /* Data register */
	if(led_on)	/* set output to 1 */
		reg |= 0x02000000;
	else
		reg &= ~0x02000000;
	sysconf->sc_sgpiodt2=reg; /* Data register */
}


/****************************************************************
 * Last Stage Init
 ****************************************************************/
int last_stage_init (void)
{
	mem_test_reloc();
	init_ios();
	return 0;
}

/****************************************************************
 * Check the board
 ****************************************************************/

#define BOARD_NAME	"PATI"

int checkboard (void)
{
	unsigned char s[50];
	unsigned long reg;
	char rev;
	int i;

	puts ("\nBoard: ");
	reg=in32(PLD_CONFIG_BASE+PLD_BOARD_TIMING);
	rev=(char)(SYSCNTR_BREV(reg)+'A');
	i = getenv_r ("serial#", s, 32);
	if ((i == -1)) {
		puts ("### No HW ID - assuming " BOARD_NAME);
		printf(" Rev. %c\n",rev);
	}
	else {
		s[sizeof(BOARD_NAME)-1] = 0;
		printf ("%s-1 Rev %c SN: %s\n", s,rev,
				&s[sizeof(BOARD_NAME)]);
	}
	set_flash_vpp(1,0,0); /* set Flash VPP */
	return 0;
}


#ifdef CFG_PCI_CON_DEVICE
/************************************************************************
 * PCI Communication
 *
 * Alive (Pinging):
 * ----------------
 * PCI Host sends message ALIVE, Local acknowledges with ALIVE
 *
 * PCI_CON console over PCI:
 * -------------------------
 * Local side:
 *     - uses PCI9056_LOC_TO_PCI_DBELL register to signal that
 *       data is avaible (PCIMSG_CONN)
 *     - uses PCI9056_MAILBOX1 to send data
 *     - uses PCI9056_MAILBOX0 to receive data
 * PCI side:
 *     - uses PCI9056_PCI_TO_LOC_DBELL register to signal that
 *       data is avaible (PCIMSG_CONN)
 *     - uses PCI9056_MAILBOX0 to send data
 *     - uses PCI9056_MAILBOX1 to receive data
 *
 * How it works:
 *     Send:
 *     - check if PCICON_TRANSMIT_REG is empty
 *     - write data or'ed with 0x80000000 into the PCICON_TRANSMIT_REG
 *     - write PCIMSG_CONN into the PCICON_DBELL_REG to signal a data
 *       is waiting
 *     Receive:
 *     - get an interrupt via the PCICON_ACK_REG register message
 *       PCIMSG_CONN
 *     - write the data from the PCICON_RECEIVE_REG into the receive
 *       buffer and if the receive buffer is not full, clear the
 *       PCICON_RECEIVE_REG (this allows the counterpart to write more data)
 *     - Clear the interrupt by writing 0xFFFFFFFF to the PCICON_ACK_REG
 *
 *     The PCICON_RECEIVE_REG must be cleared by the routine which reads
 *     the receive buffer if the buffer is not full any more
 *
 */

#undef PCI_CON_DEBUG

#ifdef	PCI_CON_DEBUG
#define	PCI_CON_PRINTF(fmt,args...)	serial_printf (fmt ,##args)
#else
#define PCI_CON_PRINTF(fmt,args...)
#endif


/*********************************************************
 * we work only with a receive buffer on eiter side.
 * Transmit buffer is free, if mailbox is cleared.
 * Transmit character is or'ed with 0x80000000
 * PATI receive register MAILBOX0
 * PATI transmit register MAILBOX1
 *********************************************************/
#define PCICON_RECEIVE_REG	PCI9056_MAILBOX0
#define PCICON_TRANSMIT_REG	PCI9056_MAILBOX1
#define PCICON_DBELL_REG	PCI9056_LOC_TO_PCI_DBELL
#define PCICON_ACK_REG		PCI9056_PCI_TO_LOC_DBELL


#define PCIMSG_ALIVE		0x1
#define PCIMSG_CONN		0x2
#define PCIMSG_DISC		0x3
#define PCIMSG_CON_DATA	0x5


#define PCICON_GET_REG(x)	(in32(x + PCI_CONFIG_BASE))
#define PCICON_SET_REG(x,y)	(out32(x + PCI_CONFIG_BASE,y))
#define PCICON_TX_FLAG		0x80000000


#define REC_BUFFER_SIZE	0x100
int recbuf[REC_BUFFER_SIZE];
static int r_ptr = 0;
int w_ptr;
device_t pci_con_dev;
int conn=0;
int buff_full=0;

void pci_con_put_it(const char c)
{
	/* Test for completition */
	unsigned long reg;
	do {
		reg=PCICON_GET_REG(PCICON_TRANSMIT_REG);
	}while(reg);
	reg=PCICON_TX_FLAG + c;
	PCICON_SET_REG(PCICON_TRANSMIT_REG,reg);
	PCICON_SET_REG(PCICON_DBELL_REG,PCIMSG_CON_DATA);
}

void pci_con_putc(const char c)
{
	pci_con_put_it(c);
	if(c == '\n')
		pci_con_put_it('\r');
}


int pci_con_getc(void)
{
	int res;
	int diff;
	while(r_ptr==(volatile int)w_ptr);
	res=recbuf[r_ptr++];
	if(r_ptr==REC_BUFFER_SIZE)
		r_ptr=0;
	if(w_ptr<r_ptr)
		diff=r_ptr+REC_BUFFER_SIZE-w_ptr;
	else
		diff=r_ptr-w_ptr;
	if((diff<(REC_BUFFER_SIZE-4)) && buff_full) {
   		/* clear Mail box */
			buff_full=0;
			PCICON_SET_REG(PCICON_RECEIVE_REG,0L);
	}
	return res;
}

int pci_con_tstc(void)
{
	if(r_ptr==(volatile int)w_ptr)
		return 0;
	return 1;
}

void pci_con_puts (const char *s)
{
	while (*s) {
		pci_con_putc(*s);
		++s;
	}
}

void pci_con_init (void)
{
	w_ptr = 0;
	r_ptr = 0;
	PCICON_SET_REG(PCICON_RECEIVE_REG,0L);
	conn=1;
}

/*******************************************
 * IRQ routine
 ******************************************/
int pci_dorbell_irq(void)
{
	unsigned long reg,data;
	int diff;
	reg=PCICON_GET_REG(PCI9056_INT_CTRL_STAT);
	PCI_CON_PRINTF(" PCI9056_INT_CTRL_STAT = %08lX\n",reg);
	if(reg & (1<<20) ) {
		/* read doorbell */
		reg=PCICON_GET_REG(PCICON_ACK_REG);
		switch(reg) {
			case PCIMSG_ALIVE:
				PCI_CON_PRINTF(" Alive\n");
				PCICON_SET_REG(PCICON_DBELL_REG,PCIMSG_ALIVE);
				break;
			case PCIMSG_CONN:
				PCI_CON_PRINTF(" Conn %d",conn);
				w_ptr = 0;
				r_ptr = 0;
				buff_full=0;
				PCICON_SET_REG(PCICON_RECEIVE_REG,0L);
				conn=1;
				PCI_CON_PRINTF(" ... %d\n",conn);
				break;
			case PCIMSG_CON_DATA:
				data=PCICON_GET_REG(PCICON_RECEIVE_REG);
				recbuf[w_ptr++]=(int)(data&0xff);
				PCI_CON_PRINTF(" Data Console %lX, %X %d %d %X\n",data,((int)(data&0xFF)),
					r_ptr,w_ptr,recbuf[w_ptr-1]);
				if(w_ptr==REC_BUFFER_SIZE)
					w_ptr=0;
				if(w_ptr<r_ptr)
					diff=r_ptr+REC_BUFFER_SIZE-w_ptr;
				else
					diff=r_ptr-w_ptr;
				if(diff>(REC_BUFFER_SIZE-4))
					buff_full=1;
				else
					/* clear Mail box */
					PCICON_SET_REG(PCICON_RECEIVE_REG,0L);
				break;
			default:
				serial_printf(" PCI9056_PCI_TO_LOC_DBELL = %08lX\n",reg);
		}
		/* clear IRQ */
		PCICON_SET_REG(PCICON_ACK_REG,~0L);
	}
	return 0;
}

void pci_con_connect(void)
{
	unsigned long reg;
	conn=0;
	reg=PCICON_GET_REG(PCI9056_INT_CTRL_STAT);
	/* default 0x0f010180 */
	reg &= 0xff000000;
	reg |= 0x00030000; /* enable local dorbell */
	reg |= 0x00000300; /* enable PCI dorbell */
	PCICON_SET_REG(PCI9056_INT_CTRL_STAT , reg);
	irq_install_handler (0x2, (interrupt_handler_t *) pci_dorbell_irq,NULL);
	memset (&pci_con_dev, 0, sizeof (pci_con_dev));
	strcpy (pci_con_dev.name, "pci_con");
	pci_con_dev.flags = DEV_FLAGS_OUTPUT | DEV_FLAGS_INPUT | DEV_FLAGS_SYSTEM;
	pci_con_dev.putc = pci_con_putc;
	pci_con_dev.puts = pci_con_puts;
	pci_con_dev.getc = pci_con_getc;
	pci_con_dev.tstc = pci_con_tstc;
	device_register (&pci_con_dev);
	printf("PATI ready for PCI connection, type ctrl-c for exit\n");
	do {
		udelay(10);
		if((volatile int)conn)
			break;
		if(ctrlc()) {
			irq_free_handler(0x2);
			return;
		}
	}while(1);
	console_assign(stdin,"pci_con");
	console_assign(stderr,"pci_con");
	console_assign(stdout,"pci_con");
}

void pci_con_disc(void)
{
	console_assign(stdin,"serial");
	console_assign(stderr,"serial");
	console_assign(stdout,"serial");
	PCICON_SET_REG(PCICON_DBELL_REG,PCIMSG_DISC);
	/* reconnection */
	irq_free_handler(0x02);
	pci_con_connect();
}
#endif /* #ifdef CFG_PCI_CON_DEVICE */

/*
 * Absolute environment address for linker file.
 */
GEN_ABS(env_start, CFG_ENV_OFFSET + CFG_FLASH_BASE);
OpenPOWER on IntegriCloud