2 * Simple serial driver for Cogent motherboard serial ports
7 #include <board/cogent/serial.h>
9 #if (CMA_MB_CAPS & CMA_MB_CAP_SERPAR)
11 #if (defined(CONFIG_8xx) && defined(CONFIG_8xx_CONS_NONE)) || \
12 (defined(CONFIG_8260) && defined(CONFIG_CONS_NONE))
14 #if CONFIG_CONS_INDEX == 1
15 #define CMA_MB_SERIAL_BASE CMA_MB_SERIALA_BASE
16 #elif CONFIG_CONS_INDEX == 2
17 #define CMA_MB_SERIAL_BASE CMA_MB_SERIALB_BASE
18 #elif CONFIG_CONS_INDEX == 3 && (CMA_MB_CAPS & CMA_MB_CAP_SER2)
19 #define CMA_MB_SERIAL_BASE CMA_MB_SER2A_BASE
20 #elif CONFIG_CONS_INDEX == 4 && (CMA_MB_CAPS & CMA_MB_CAP_SER2)
21 #define CMA_MB_SERIAL_BASE CMA_MB_SER2B_BASE
23 #error CONFIG_CONS_INDEX must be configured for Cogent motherboard serial
26 int serial_init (void)
28 /* DECLARE_GLOBAL_DATA_PTR; */
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 */
44 DECLARE_GLOBAL_DATA_PTR;
46 cma_mb_serial *mbsp = (cma_mb_serial *)CMA_MB_SERIAL_BASE;
50 if ((divisor = br_to_div(gd->baudrate)) == 0)
53 lcr = cma_mb_reg_read(&mbsp->ser_lcr);
54 cma_mb_reg_write(&mbsp->ser_lcr, lcr|0x80);/* Access baud rate(set DLAB)*/
55 cma_mb_reg_write(&mbsp->ser_brl, divisor & 0xff);
56 cma_mb_reg_write(&mbsp->ser_brh, (divisor >> 8) & 0xff);
57 cma_mb_reg_write(&mbsp->ser_lcr, lcr); /* unset DLAB */
61 serial_putc(const char c)
63 cma_mb_serial *mbsp = (cma_mb_serial *)CMA_MB_SERIAL_BASE;
68 while ((cma_mb_reg_read(&mbsp->ser_lsr) & LSR_THRE) == 0)
71 cma_mb_reg_write(&mbsp->ser_thr, c);
75 serial_puts(const char *s)
84 cma_mb_serial *mbsp = (cma_mb_serial *)CMA_MB_SERIAL_BASE;
86 while ((cma_mb_reg_read(&mbsp->ser_lsr) & LSR_DR) == 0)
89 return ((int)cma_mb_reg_read(&mbsp->ser_rhr) & 0x7f);
95 cma_mb_serial *mbsp = (cma_mb_serial *)CMA_MB_SERIAL_BASE;
97 return ((cma_mb_reg_read(&mbsp->ser_lsr) & LSR_DR) != 0);
100 #endif /* CONS_NONE */
102 #if (CONFIG_COMMANDS & CFG_CMD_KGDB) && \
103 defined(CONFIG_KGDB_NONE)
105 #if CONFIG_KGDB_INDEX == CONFIG_CONS_INDEX
106 #error Console and kgdb are on the same serial port - this is not supported
109 #if CONFIG_KGDB_INDEX == 1
110 #define CMA_MB_KGDB_SER_BASE CMA_MB_SERIALA_BASE
111 #elif CONFIG_KGDB_INDEX == 2
112 #define CMA_MB_KGDB_SER_BASE CMA_MB_SERIALB_BASE
113 #elif CONFIG_KGDB_INDEX == 3 && (CMA_MB_CAPS & CMA_MB_CAP_SER2)
114 #define CMA_MB_KGDB_SER_BASE CMA_MB_SER2A_BASE
115 #elif CONFIG_KGDB_INDEX == 4 && (CMA_MB_CAPS & CMA_MB_CAP_SER2)
116 #define CMA_MB_KGDB_SER_BASE CMA_MB_SER2B_BASE
118 #error CONFIG_KGDB_INDEX must be configured for Cogent motherboard serial
122 kgdb_serial_init(void)
124 cma_mb_serial *mbsp = (cma_mb_serial *)CMA_MB_KGDB_SER_BASE;
125 unsigned int divisor;
127 if ((divisor = br_to_div(CONFIG_KGDB_BAUDRATE)) == 0)
130 cma_mb_reg_write(&mbsp->ser_ier, 0x00); /* turn off interrupts */
131 cma_mb_reg_write(&mbsp->ser_lcr, 0x80); /* Access baud rate(set DLAB)*/
132 cma_mb_reg_write(&mbsp->ser_brl, divisor & 0xff);
133 cma_mb_reg_write(&mbsp->ser_brh, (divisor >> 8) & 0xff);
134 cma_mb_reg_write(&mbsp->ser_lcr, 0x03); /* 8 data, 1 stop, no parity */
135 cma_mb_reg_write(&mbsp->ser_mcr, 0x03); /* RTS/DTR */
136 cma_mb_reg_write(&mbsp->ser_fcr, 0x07); /* Clear & enable FIFOs */
138 printf("[on cma10x serial port B] ");
144 cma_mb_serial *mbsp = (cma_mb_serial *)CMA_MB_KGDB_SER_BASE;
146 while ((cma_mb_reg_read(&mbsp->ser_lsr) & LSR_THRE) == 0)
149 cma_mb_reg_write(&mbsp->ser_thr, c & 0xff);
153 putDebugStr(const char *str)
155 while (*str != '\0') {
158 putDebugChar(*str++);
165 cma_mb_serial *mbsp = (cma_mb_serial *)CMA_MB_KGDB_SER_BASE;
167 while ((cma_mb_reg_read(&mbsp->ser_lsr) & LSR_DR) == 0)
170 return ((int)cma_mb_reg_read(&mbsp->ser_rhr) & 0x7f);
174 kgdb_interruptible(int yes)
176 cma_mb_serial *mbsp = (cma_mb_serial *)CMA_MB_KGDB_SER_BASE;
179 printf("kgdb: turning serial ints on\n");
180 cma_mb_reg_write(&mbsp->ser_ier, 0xf);
183 printf("kgdb: turning serial ints off\n");
184 cma_mb_reg_write(&mbsp->ser_ier, 0x0);
188 #endif /* KGDB && KGDB_NONE */
190 #endif /* CAPS & SERPAR */