]>
git.ipfire.org Git - people/ms/u-boot.git/blob - board/mpl/pati/pati.c
3 * Martin Winistoerfer, martinwinistoerfer@gmx.ch.
5 * Denis Peter, d.peter@mpl.ch
6 * SPDX-License-Identifier: GPL-2.0+
9 /***********************************************************************************
10 * Bits for the SDRAM controller
11 * -----------------------------
13 * CAL: CAS Latency. If cleared to 0 (default) the SDRAM controller asserts TA# on
14 * the 2nd Clock after ACTIVE command (CAS Latency = 2). If set to 1 the SDRAM
15 * controller asserts TA# on the 3rd Clock after ACTIVE command (CAS Latency = 3).
16 * RCD: RCD ACTIVE to READ or WRITE Delay (Ras to Cas Delay). If cleared 0 (default)
17 * tRCD of the SDRAM must equal or less 25ns. If set to 1 tRCD must be equal or less 50ns.
18 * WREC:Write Recovery. If cleared 0 (default) tWR of the SDRAM must equal or less 25ns.
19 * If set to 1 tWR must be equal or less 50ns.
20 * RP: Precharge Command Time. If cleared 0 (default) tRP of the SDRAM must equal or less
21 * 25ns. If set to 1 tRP must be equal or less 50ns.
22 * RC: Auto Refresh to Active Time. If cleared 0 (default) tRC of the SDRAM must equal
23 * or less 75ns. If set to 1 tRC must be equal or less 100ns.
24 * LMR: Bit to set the Mode Register of the SDRAM. If set, the next access to the SDRAM
25 * is the Load Mode Register Command.
26 * IIP: Init in progress. Set to 1 for starting the init sequence
27 * (Precharge All). As long this bit is set, the Precharge All is still in progress.
28 * After command has completed, wait at least for 8 refresh (200usec) before proceed.
29 **********************************************************************************/
34 #include <stdio_dev.h>
40 #if defined(__APPLE__)
41 /* Leading underscore on symbols */
43 #else /* No leading character on symbols */
49 * Macros to generate global absolutes.
51 #define GEN_SYMNAME(str) SYM_CHAR #str
52 #define GEN_VALUE(str) #str
53 #define GEN_ABS(name, value) \
54 asm (".globl " GEN_SYMNAME(name)); \
55 asm (GEN_SYMNAME(name) " = " GEN_VALUE(value))
58 DECLARE_GLOBAL_DATA_PTR
;
60 /************************************************************************
61 * Early debug routines
63 void write_hex (unsigned char i
)
70 serial_putc (cc
+ 55);
72 serial_putc (cc
+ 48);
75 serial_putc (cc
+ 55);
77 serial_putc (cc
+ 48);
80 #if defined(SDRAM_DEBUG)
82 void write_4hex (unsigned long val
)
84 write_hex ((unsigned char) (val
>> 24));
85 write_hex ((unsigned char) (val
>> 16));
86 write_hex ((unsigned char) (val
>> 8));
87 write_hex ((unsigned char) val
);
92 unsigned long in32(unsigned long addr
)
94 unsigned long *p
=(unsigned long *)addr
;
98 void out32(unsigned long addr
,unsigned long data
)
100 unsigned long *p
=(unsigned long *)addr
;
105 unsigned short boardtype
; /* Board revision and Population Options */
106 unsigned char cal
; /* cas Latency 0:CAL=2 1:CAL=3 */
107 unsigned char rcd
; /* ras to cas delay 0:<25ns 1:<50ns*/
108 unsigned char wrec
; /* write recovery 0:<25ns 1:<50ns */
109 unsigned char pr
; /* Precharge Command Time 0:<25ns 1:<50ns */
110 unsigned char rc
; /* Auto Refresh to Active Time 0:<75ns 1:<100ns */
111 unsigned char sz
; /* log binary => Size = (4MByte<<sz) 5 = 128, 4 = 64, 3 = 32, 2 = 16, 1=8 */
114 const sdram_t sdram_table
[] = {
115 { 0x0000, /* PATI Rev A, 16MByte -1 Board */
116 1, /* Case Latenty = 3 */
117 0, /* ras to cas delay 0 (20ns) */
118 0, /* write recovery 0:<25ns 1:<50ns*/
119 0, /* Precharge Command Time 0 (20ns) */
120 0, /* Auto Refresh to Active Time 0 (68) */
121 2 /* log binary => Size 2 = 16MByte, 1=8 */
123 { 0xffff, /* terminator */
133 extern int mem_test (unsigned long start
, unsigned long ramsize
, int quiet
);
140 unsigned char board_rev
;
145 #if defined(SDRAM_DEBUG)
146 reg
=in32(PLD_CONFIG_BASE
+PLD_PART_ID
);
147 puts("\n\nSYSTEM part 0x"); write_4hex(SYSCNTR_PART(reg
));
148 puts(" Vers 0x"); write_4hex(SYSCNTR_ID(reg
));
149 puts("\nSDRAM part 0x"); write_4hex(SDRAM_PART(reg
));
150 puts(" Vers 0x"); write_4hex(SDRAM_ID(reg
));
151 reg
=in32(PLD_CONFIG_BASE
+PLD_BOARD_TIMING
);
152 puts("\nBoard rev. 0x"); write_4hex(SYSCNTR_BREV(reg
));
155 reg
=in32(PLD_CONFIG_BASE
+PLD_BOARD_TIMING
);
156 board_rev
=(unsigned char)(SYSCNTR_BREV(reg
));
159 if(sdram_table
[i
].boardtype
==0xffff) {
160 puts("ERROR, found no table for Board 0x");
161 write_hex(board_rev
);
164 if(sdram_table
[i
].boardtype
==(unsigned char)board_rev
)
168 /* Set CAL, RCD, WREQ, PR and RC Bits */
169 #if defined(SDRAM_DEBUG)
170 puts("Set CAL, RCD, WREQ, PR and RC Bits\n");
173 reg
&= ~(SET_REG_BIT(1,SDRAM_CAL
) | SET_REG_BIT(1,SDRAM_RCD
) | SET_REG_BIT(1,SDRAM_WREQ
) |
174 SET_REG_BIT(1,SDRAM_PR
) | SET_REG_BIT(1,SDRAM_RC
) | SET_REG_BIT(1,SDRAM_LMR
) |
175 SET_REG_BIT(1,SDRAM_IIP
) | SET_REG_BIT(1,SDRAM_RES0
));
177 reg
|= (SET_REG_BIT(sdram_table
[i
].cal
,SDRAM_CAL
) |
178 SET_REG_BIT(sdram_table
[i
].rcd
,SDRAM_RCD
) |
179 SET_REG_BIT(sdram_table
[i
].wrec
,SDRAM_WREQ
) |
180 SET_REG_BIT(sdram_table
[i
].pr
,SDRAM_PR
) |
181 SET_REG_BIT(sdram_table
[i
].rc
,SDRAM_RC
));
183 out32(PLD_CONFIG_BASE
+PLD_BOARD_TIMING
,reg
);
185 #if defined(SDRAM_DEBUG)
186 puts("step 2 set IIP\n");
189 reg
|= SET_REG_BIT(1,SDRAM_IIP
);
191 while (timeout
!=0xffff) {
192 __asm__
volatile("eieio");
193 reg
=in32(PLD_CONFIG_BASE
+PLD_BOARD_TIMING
);
194 if((reg
& SET_REG_BIT(1,SDRAM_IIP
))==0)
199 /* wait for at least 8 refresh */
202 reg
|= SET_REG_BIT(1,SDRAM_LMR
);
203 out32(PLD_CONFIG_BASE
+PLD_BOARD_TIMING
,reg
);
204 __asm__
volatile("eieio");
205 lmr
=0x00000002; /* sequential burst 4 data */
206 if(sdram_table
[i
].cal
==1)
207 lmr
|=0x00000030; /* cal = 3 */
209 lmr
|=0000000020; /* cal = 2 */
210 /* rest standard operation programmed write burst length */
211 /* we have a x32 bit bus to the SDRAM, so shift the addr with 2 */
213 in32(CONFIG_SYS_SDRAM_BASE
+ lmr
);
214 /* ok, we're done, set SDRAM size to log2 value of 4MByte*/
215 gd
->ram_size
= 0x400000 << sdram_table
[i
].sz
;
221 void set_flash_vpp(int ext_vpp
, int ext_wp
, int int_vpp
)
224 reg
=in32(PLD_CONF_REG2
+PLD_CONFIG_BASE
);
225 reg
&= ~(SET_REG_BIT(1,SYSCNTR_CPU_VPP
) |
226 SET_REG_BIT(1,SYSCNTR_FL_VPP
) |
227 SET_REG_BIT(1,SYSCNTR_FL_WP
));
229 reg
|= (SET_REG_BIT(int_vpp
,SYSCNTR_CPU_VPP
) |
230 SET_REG_BIT(ext_vpp
,SYSCNTR_FL_VPP
) |
231 SET_REG_BIT(ext_wp
,SYSCNTR_FL_WP
));
232 out32(PLD_CONF_REG2
+PLD_CONFIG_BASE
,reg
);
237 void show_pld_regs(void)
239 unsigned long reg
,reg1
;
240 reg
=in32(PLD_CONFIG_BASE
+PLD_PART_ID
);
241 printf("\nSYSTEM part %ld, Vers %ld\n",SYSCNTR_PART(reg
),SYSCNTR_ID(reg
));
242 printf("SDRAM part %ld, Vers %ld\n",SDRAM_PART(reg
),SDRAM_ID(reg
));
243 reg
=in32(PLD_CONFIG_BASE
+PLD_BOARD_TIMING
);
244 printf("Board rev. %c\n",(char) (SYSCNTR_BREV(reg
)+'A'));
245 printf("Waitstates %ld\n",GET_SYSCNTR_FLWAIT(reg
));
246 printf("SDRAM: CAL=%ld RCD=%ld WREQ=%ld PR=%ld\n RC=%ld LMR=%ld IIP=%ld\n",
247 GET_REG_BIT(reg
,SDRAM_CAL
),GET_REG_BIT(reg
,SDRAM_RCD
),
248 GET_REG_BIT(reg
,SDRAM_WREQ
),GET_REG_BIT(reg
,SDRAM_PR
),
249 GET_REG_BIT(reg
,SDRAM_RC
),GET_REG_BIT(reg
,SDRAM_LMR
),
250 GET_REG_BIT(reg
,SDRAM_IIP
));
251 reg
=in32(PLD_CONFIG_BASE
+PLD_CONF_REG1
);
252 reg1
=in32(PLD_CONFIG_BASE
+PLD_CONF_REG2
);
253 printf("HW Config: FLAG=%ld IP=%ld index=%ld PRPM=%ld\n ICW=%ld ISB=%ld BDIS=%ld PCIM=%ld\n",
254 GET_REG_BIT(reg
,SYSCNTR_FLAG
),GET_REG_BIT(reg
,SYSCNTR_IP
),
255 GET_SYSCNTR_BOOTIND(reg
),GET_REG_BIT(reg
,SYSCNTR_PRM
),
256 GET_REG_BIT(reg
,SYSCNTR_ICW
),GET_SYSCNTR_ISB(reg
),
257 GET_REG_BIT(reg1
,SYSCNTR_BDIS
),GET_REG_BIT(reg1
,SYSCNTR_PCIM
));
258 printf("Switches: MUX=%ld PCI_DIS=%ld Boot_EN=%ld Config=%ld\n",GET_SDRAM_MUX(reg
),
259 GET_REG_BIT(reg
,SDRAM_PDIS
),GET_REG_BIT(reg1
,SYSCNTR_BOOTEN
),
260 GET_SYSCNTR_CFG(reg1
));
261 printf("Misc: RIP=%ld CPU_VPP=%ld FLSH_VPP=%ld FLSH_WP=%ld\n\n",
262 GET_REG_BIT(reg
,SDRAM_RIP
),GET_REG_BIT(reg1
,SYSCNTR_CPU_VPP
),
263 GET_REG_BIT(reg1
,SYSCNTR_FL_VPP
),GET_REG_BIT(reg1
,SYSCNTR_FL_WP
));
267 /****************************************************************
271 * GPIO7 is Interrupt PLX (Output)
273 * GPIO2 is PLX USERi (Output)
274 * GPIO1 is PLX Interrupt (Input)
275 ****************************************************************/
278 volatile immap_t
* immr
= (immap_t
*) CONFIG_SYS_IMMR
;
279 volatile sysconf5xx_t
*sysconf
= &immr
->im_siu_conf
;
281 reg
=sysconf
->sc_sgpiocr
; /* Data direction register */
283 reg
|= 0x27000000; /* set outpupts */
284 sysconf
->sc_sgpiocr
=reg
; /* Data direction register */
285 reg
=sysconf
->sc_sgpiodt2
; /* Data register */
286 /* set output to 0 */
288 /* set IRQ and USERi to 1 */
290 sysconf
->sc_sgpiodt2
=reg
; /* Data register */
293 void user_led0(int led_on
)
295 volatile immap_t
* immr
= (immap_t
*) CONFIG_SYS_IMMR
;
296 volatile sysconf5xx_t
*sysconf
= &immr
->im_siu_conf
;
298 reg
=sysconf
->sc_sgpiodt2
; /* Data register */
299 if(led_on
) /* set output to 1 */
303 sysconf
->sc_sgpiodt2
=reg
; /* Data register */
306 void user_led1(int led_on
)
308 volatile immap_t
* immr
= (immap_t
*) CONFIG_SYS_IMMR
;
309 volatile sysconf5xx_t
*sysconf
= &immr
->im_siu_conf
;
311 reg
=sysconf
->sc_sgpiodt2
; /* Data register */
312 if(led_on
) /* set output to 1 */
316 sysconf
->sc_sgpiodt2
=reg
; /* Data register */
319 int board_early_init_f(void)
325 /****************************************************************
327 ****************************************************************/
328 int last_stage_init (void)
334 /****************************************************************
336 ****************************************************************/
338 #define BOARD_NAME "PATI"
340 int checkboard (void)
348 reg
=in32(PLD_CONFIG_BASE
+PLD_BOARD_TIMING
);
349 rev
=(char)(SYSCNTR_BREV(reg
)+'A');
350 i
= getenv_f("serial#", s
, 32);
352 puts ("### No HW ID - assuming " BOARD_NAME
);
353 printf(" Rev. %c\n",rev
);
356 s
[sizeof(BOARD_NAME
)-1] = 0;
357 printf ("%s-1 Rev %c SN: %s\n", s
,rev
,
358 &s
[sizeof(BOARD_NAME
)]);
360 set_flash_vpp(1,0,0); /* set Flash VPP */
365 #ifdef CONFIG_SYS_PCI_CON_DEVICE
366 /************************************************************************
371 * PCI Host sends message ALIVE, Local acknowledges with ALIVE
373 * PCI_CON console over PCI:
374 * -------------------------
376 * - uses PCI9056_LOC_TO_PCI_DBELL register to signal that
377 * data is avaible (PCIMSG_CONN)
378 * - uses PCI9056_MAILBOX1 to send data
379 * - uses PCI9056_MAILBOX0 to receive data
381 * - uses PCI9056_PCI_TO_LOC_DBELL register to signal that
382 * data is avaible (PCIMSG_CONN)
383 * - uses PCI9056_MAILBOX0 to send data
384 * - uses PCI9056_MAILBOX1 to receive data
388 * - check if PCICON_TRANSMIT_REG is empty
389 * - write data or'ed with 0x80000000 into the PCICON_TRANSMIT_REG
390 * - write PCIMSG_CONN into the PCICON_DBELL_REG to signal a data
393 * - get an interrupt via the PCICON_ACK_REG register message
395 * - write the data from the PCICON_RECEIVE_REG into the receive
396 * buffer and if the receive buffer is not full, clear the
397 * PCICON_RECEIVE_REG (this allows the counterpart to write more data)
398 * - Clear the interrupt by writing 0xFFFFFFFF to the PCICON_ACK_REG
400 * The PCICON_RECEIVE_REG must be cleared by the routine which reads
401 * the receive buffer if the buffer is not full any more
408 #define PCI_CON_PRINTF(fmt,args...) serial_printf (fmt ,##args)
410 #define PCI_CON_PRINTF(fmt,args...)
414 /*********************************************************
415 * we work only with a receive buffer on eiter side.
416 * Transmit buffer is free, if mailbox is cleared.
417 * Transmit character is or'ed with 0x80000000
418 * PATI receive register MAILBOX0
419 * PATI transmit register MAILBOX1
420 *********************************************************/
421 #define PCICON_RECEIVE_REG PCI9056_MAILBOX0
422 #define PCICON_TRANSMIT_REG PCI9056_MAILBOX1
423 #define PCICON_DBELL_REG PCI9056_LOC_TO_PCI_DBELL
424 #define PCICON_ACK_REG PCI9056_PCI_TO_LOC_DBELL
427 #define PCIMSG_ALIVE 0x1
428 #define PCIMSG_CONN 0x2
429 #define PCIMSG_DISC 0x3
430 #define PCIMSG_CON_DATA 0x5
433 #define PCICON_GET_REG(x) (in32(x + PCI_CONFIG_BASE))
434 #define PCICON_SET_REG(x,y) (out32(x + PCI_CONFIG_BASE,y))
435 #define PCICON_TX_FLAG 0x80000000
438 #define REC_BUFFER_SIZE 0x100
439 int recbuf
[REC_BUFFER_SIZE
];
440 static int r_ptr
= 0;
442 struct stdio_dev pci_con_dev
;
446 void pci_con_put_it(const char c
)
448 /* Test for completition */
451 reg
=PCICON_GET_REG(PCICON_TRANSMIT_REG
);
453 reg
=PCICON_TX_FLAG
+ c
;
454 PCICON_SET_REG(PCICON_TRANSMIT_REG
,reg
);
455 PCICON_SET_REG(PCICON_DBELL_REG
,PCIMSG_CON_DATA
);
458 void pci_con_putc(struct stdio_dev
*dev
, const char c
)
462 pci_con_put_it('\r');
466 int pci_con_getc(struct stdio_dev
*dev
)
470 while(r_ptr
==(volatile int)w_ptr
);
472 if(r_ptr
==REC_BUFFER_SIZE
)
475 diff
=r_ptr
+REC_BUFFER_SIZE
-w_ptr
;
478 if((diff
<(REC_BUFFER_SIZE
-4)) && buff_full
) {
481 PCICON_SET_REG(PCICON_RECEIVE_REG
,0L);
486 int pci_con_tstc(struct stdio_dev
*dev
)
488 if(r_ptr
==(volatile int)w_ptr
)
493 void pci_con_puts(struct stdio_dev
*dev
, const char *s
)
501 void pci_con_init (void)
505 PCICON_SET_REG(PCICON_RECEIVE_REG
,0L);
509 /*******************************************
511 ******************************************/
512 int pci_dorbell_irq(void)
514 unsigned long reg
,data
;
516 reg
=PCICON_GET_REG(PCI9056_INT_CTRL_STAT
);
517 PCI_CON_PRINTF(" PCI9056_INT_CTRL_STAT = %08lX\n",reg
);
520 reg
=PCICON_GET_REG(PCICON_ACK_REG
);
523 PCI_CON_PRINTF(" Alive\n");
524 PCICON_SET_REG(PCICON_DBELL_REG
,PCIMSG_ALIVE
);
527 PCI_CON_PRINTF(" Conn %d",conn
);
531 PCICON_SET_REG(PCICON_RECEIVE_REG
,0L);
533 PCI_CON_PRINTF(" ... %d\n",conn
);
535 case PCIMSG_CON_DATA
:
536 data
=PCICON_GET_REG(PCICON_RECEIVE_REG
);
537 recbuf
[w_ptr
++]=(int)(data
&0xff);
538 PCI_CON_PRINTF(" Data Console %lX, %X %d %d %X\n",data
,((int)(data
&0xFF)),
539 r_ptr
,w_ptr
,recbuf
[w_ptr
-1]);
540 if(w_ptr
==REC_BUFFER_SIZE
)
543 diff
=r_ptr
+REC_BUFFER_SIZE
-w_ptr
;
546 if(diff
>(REC_BUFFER_SIZE
-4))
550 PCICON_SET_REG(PCICON_RECEIVE_REG
,0L);
553 serial_printf(" PCI9056_PCI_TO_LOC_DBELL = %08lX\n",reg
);
556 PCICON_SET_REG(PCICON_ACK_REG
,~0L);
561 void pci_con_connect(void)
565 reg
=PCICON_GET_REG(PCI9056_INT_CTRL_STAT
);
566 /* default 0x0f010180 */
568 reg
|= 0x00030000; /* enable local dorbell */
569 reg
|= 0x00000300; /* enable PCI dorbell */
570 PCICON_SET_REG(PCI9056_INT_CTRL_STAT
, reg
);
571 irq_install_handler (0x2, (interrupt_handler_t
*) pci_dorbell_irq
,NULL
);
572 memset (&pci_con_dev
, 0, sizeof (pci_con_dev
));
573 strcpy (pci_con_dev
.name
, "pci_con");
574 pci_con_dev
.flags
= DEV_FLAGS_OUTPUT
| DEV_FLAGS_INPUT
;
575 pci_con_dev
.putc
= pci_con_putc
;
576 pci_con_dev
.puts
= pci_con_puts
;
577 pci_con_dev
.getc
= pci_con_getc
;
578 pci_con_dev
.tstc
= pci_con_tstc
;
579 stdio_register (&pci_con_dev
);
580 printf("PATI ready for PCI connection, type ctrl-c for exit\n");
583 if((volatile int)conn
)
586 irq_free_handler(0x2);
590 console_assign(stdin
,"pci_con");
591 console_assign(stderr
,"pci_con");
592 console_assign(stdout
,"pci_con");
595 void pci_con_disc(void)
597 console_assign(stdin
,"serial");
598 console_assign(stderr
,"serial");
599 console_assign(stdout
,"serial");
600 PCICON_SET_REG(PCICON_DBELL_REG
,PCIMSG_DISC
);
602 irq_free_handler(0x02);
605 #endif /* #ifdef CONFIG_SYS_PCI_CON_DEVICE */
608 * Absolute environment address for linker file.
610 GEN_ABS(env_start
, CONFIG_ENV_OFFSET
+ CONFIG_SYS_FLASH_BASE
);