2 * Simple serial driver for Cogent motherboard serial ports
7 #include <board/cogent/serial.h>
9 DECLARE_GLOBAL_DATA_PTR
;
11 #if (CMA_MB_CAPS & CMA_MB_CAP_SERPAR)
13 #if (defined(CONFIG_8xx) && defined(CONFIG_8xx_CONS_NONE)) || \
14 (defined(CONFIG_8260) && defined(CONFIG_CONS_NONE))
16 #if CONFIG_CONS_INDEX == 1
17 #define CMA_MB_SERIAL_BASE CMA_MB_SERIALA_BASE
18 #elif CONFIG_CONS_INDEX == 2
19 #define CMA_MB_SERIAL_BASE CMA_MB_SERIALB_BASE
20 #elif CONFIG_CONS_INDEX == 3 && (CMA_MB_CAPS & CMA_MB_CAP_SER2)
21 #define CMA_MB_SERIAL_BASE CMA_MB_SER2A_BASE
22 #elif CONFIG_CONS_INDEX == 4 && (CMA_MB_CAPS & CMA_MB_CAP_SER2)
23 #define CMA_MB_SERIAL_BASE CMA_MB_SER2B_BASE
25 #error CONFIG_CONS_INDEX must be configured for Cogent motherboard serial
28 int serial_init (void)
30 cma_mb_serial
*mbsp
= (cma_mb_serial
*) CMA_MB_SERIAL_BASE
;
32 cma_mb_reg_write (&mbsp
->ser_ier
, 0x00); /* turn off interrupts */
34 cma_mb_reg_write (&mbsp
->ser_lcr
, 0x03); /* 8 data, 1 stop, no parity */
35 cma_mb_reg_write (&mbsp
->ser_mcr
, 0x03); /* RTS/DTR */
36 cma_mb_reg_write (&mbsp
->ser_fcr
, 0x07); /* Clear & enable FIFOs */
41 void serial_setbrg (void)
43 cma_mb_serial
*mbsp
= (cma_mb_serial
*) CMA_MB_SERIAL_BASE
;
47 if ((divisor
= br_to_div (gd
->baudrate
)) == 0)
50 lcr
= cma_mb_reg_read (&mbsp
->ser_lcr
);
51 cma_mb_reg_write (&mbsp
->ser_lcr
, lcr
| 0x80); /* Access baud rate(set DLAB) */
52 cma_mb_reg_write (&mbsp
->ser_brl
, divisor
& 0xff);
53 cma_mb_reg_write (&mbsp
->ser_brh
, (divisor
>> 8) & 0xff);
54 cma_mb_reg_write (&mbsp
->ser_lcr
, lcr
); /* unset DLAB */
57 void serial_putc (const char c
)
59 cma_mb_serial
*mbsp
= (cma_mb_serial
*) CMA_MB_SERIAL_BASE
;
64 while ((cma_mb_reg_read (&mbsp
->ser_lsr
) & LSR_THRE
) == 0);
66 cma_mb_reg_write (&mbsp
->ser_thr
, c
);
69 void serial_puts (const char *s
)
75 int serial_getc (void)
77 cma_mb_serial
*mbsp
= (cma_mb_serial
*) CMA_MB_SERIAL_BASE
;
79 while ((cma_mb_reg_read (&mbsp
->ser_lsr
) & LSR_DR
) == 0);
81 return ((int) cma_mb_reg_read (&mbsp
->ser_rhr
) & 0x7f);
84 int serial_tstc (void)
86 cma_mb_serial
*mbsp
= (cma_mb_serial
*) CMA_MB_SERIAL_BASE
;
88 return ((cma_mb_reg_read (&mbsp
->ser_lsr
) & LSR_DR
) != 0);
91 #endif /* CONS_NONE */
93 #if defined(CONFIG_CMD_KGDB) && \
94 defined(CONFIG_KGDB_NONE)
96 #if CONFIG_KGDB_INDEX == CONFIG_CONS_INDEX
97 #error Console and kgdb are on the same serial port - this is not supported
100 #if CONFIG_KGDB_INDEX == 1
101 #define CMA_MB_KGDB_SER_BASE CMA_MB_SERIALA_BASE
102 #elif CONFIG_KGDB_INDEX == 2
103 #define CMA_MB_KGDB_SER_BASE CMA_MB_SERIALB_BASE
104 #elif CONFIG_KGDB_INDEX == 3 && (CMA_MB_CAPS & CMA_MB_CAP_SER2)
105 #define CMA_MB_KGDB_SER_BASE CMA_MB_SER2A_BASE
106 #elif CONFIG_KGDB_INDEX == 4 && (CMA_MB_CAPS & CMA_MB_CAP_SER2)
107 #define CMA_MB_KGDB_SER_BASE CMA_MB_SER2B_BASE
109 #error CONFIG_KGDB_INDEX must be configured for Cogent motherboard serial
112 void kgdb_serial_init (void)
114 cma_mb_serial
*mbsp
= (cma_mb_serial
*) CMA_MB_KGDB_SER_BASE
;
115 unsigned int divisor
;
117 if ((divisor
= br_to_div (CONFIG_KGDB_BAUDRATE
)) == 0)
120 cma_mb_reg_write (&mbsp
->ser_ier
, 0x00); /* turn off interrupts */
121 cma_mb_reg_write (&mbsp
->ser_lcr
, 0x80); /* Access baud rate(set DLAB) */
122 cma_mb_reg_write (&mbsp
->ser_brl
, divisor
& 0xff);
123 cma_mb_reg_write (&mbsp
->ser_brh
, (divisor
>> 8) & 0xff);
124 cma_mb_reg_write (&mbsp
->ser_lcr
, 0x03); /* 8 data, 1 stop, no parity */
125 cma_mb_reg_write (&mbsp
->ser_mcr
, 0x03); /* RTS/DTR */
126 cma_mb_reg_write (&mbsp
->ser_fcr
, 0x07); /* Clear & enable FIFOs */
128 printf ("[on cma10x serial port B] ");
131 void putDebugChar (int c
)
133 cma_mb_serial
*mbsp
= (cma_mb_serial
*) CMA_MB_KGDB_SER_BASE
;
135 while ((cma_mb_reg_read (&mbsp
->ser_lsr
) & LSR_THRE
) == 0);
137 cma_mb_reg_write (&mbsp
->ser_thr
, c
& 0xff);
140 void putDebugStr (const char *str
)
142 while (*str
!= '\0') {
145 putDebugChar (*str
++);
149 int getDebugChar (void)
151 cma_mb_serial
*mbsp
= (cma_mb_serial
*) CMA_MB_KGDB_SER_BASE
;
153 while ((cma_mb_reg_read (&mbsp
->ser_lsr
) & LSR_DR
) == 0);
155 return ((int) cma_mb_reg_read (&mbsp
->ser_rhr
) & 0x7f);
158 void kgdb_interruptible (int yes
)
160 cma_mb_serial
*mbsp
= (cma_mb_serial
*) CMA_MB_KGDB_SER_BASE
;
163 printf ("kgdb: turning serial ints on\n");
164 cma_mb_reg_write (&mbsp
->ser_ier
, 0xf);
166 printf ("kgdb: turning serial ints off\n");
167 cma_mb_reg_write (&mbsp
->ser_ier
, 0x0);
171 #endif /* KGDB && KGDB_NONE */
173 #endif /* CAPS & SERPAR */