2 * Simple serial driver for Cogent motherboard serial ports
7 #include <board/cogent/serial.h>
9 #include <linux/compiler.h>
11 DECLARE_GLOBAL_DATA_PTR;
13 #if (CMA_MB_CAPS & CMA_MB_CAP_SERPAR)
15 #if (defined(CONFIG_8xx) && defined(CONFIG_8xx_CONS_NONE)) || \
16 (defined(CONFIG_8260) && defined(CONFIG_CONS_NONE))
18 #if CONFIG_CONS_INDEX == 1
19 #define CMA_MB_SERIAL_BASE CMA_MB_SERIALA_BASE
20 #elif CONFIG_CONS_INDEX == 2
21 #define CMA_MB_SERIAL_BASE CMA_MB_SERIALB_BASE
22 #elif CONFIG_CONS_INDEX == 3 && (CMA_MB_CAPS & CMA_MB_CAP_SER2)
23 #define CMA_MB_SERIAL_BASE CMA_MB_SER2A_BASE
24 #elif CONFIG_CONS_INDEX == 4 && (CMA_MB_CAPS & CMA_MB_CAP_SER2)
25 #define CMA_MB_SERIAL_BASE CMA_MB_SER2B_BASE
27 #error CONFIG_CONS_INDEX must be configured for Cogent motherboard serial
30 static int cogent_serial_init(void)
32 cma_mb_serial *mbsp = (cma_mb_serial *) CMA_MB_SERIAL_BASE;
34 cma_mb_reg_write (&mbsp->ser_ier, 0x00); /* turn off interrupts */
36 cma_mb_reg_write (&mbsp->ser_lcr, 0x03); /* 8 data, 1 stop, no parity */
37 cma_mb_reg_write (&mbsp->ser_mcr, 0x03); /* RTS/DTR */
38 cma_mb_reg_write (&mbsp->ser_fcr, 0x07); /* Clear & enable FIFOs */
43 static void cogent_serial_setbrg(void)
45 cma_mb_serial *mbsp = (cma_mb_serial *) CMA_MB_SERIAL_BASE;
49 if ((divisor = br_to_div (gd->baudrate)) == 0)
52 lcr = cma_mb_reg_read (&mbsp->ser_lcr);
53 cma_mb_reg_write (&mbsp->ser_lcr, lcr | 0x80); /* Access baud rate(set DLAB) */
54 cma_mb_reg_write (&mbsp->ser_brl, divisor & 0xff);
55 cma_mb_reg_write (&mbsp->ser_brh, (divisor >> 8) & 0xff);
56 cma_mb_reg_write (&mbsp->ser_lcr, lcr); /* unset DLAB */
59 static void cogent_serial_putc(const char c)
61 cma_mb_serial *mbsp = (cma_mb_serial *) CMA_MB_SERIAL_BASE;
66 while ((cma_mb_reg_read (&mbsp->ser_lsr) & LSR_THRE) == 0);
68 cma_mb_reg_write (&mbsp->ser_thr, c);
71 static void cogent_serial_puts(const char *s)
77 static int cogent_serial_getc(void)
79 cma_mb_serial *mbsp = (cma_mb_serial *) CMA_MB_SERIAL_BASE;
81 while ((cma_mb_reg_read (&mbsp->ser_lsr) & LSR_DR) == 0);
83 return ((int) cma_mb_reg_read (&mbsp->ser_rhr) & 0x7f);
86 static int cogent_serial_tstc(void)
88 cma_mb_serial *mbsp = (cma_mb_serial *) CMA_MB_SERIAL_BASE;
90 return ((cma_mb_reg_read (&mbsp->ser_lsr) & LSR_DR) != 0);
93 #ifdef CONFIG_SERIAL_MULTI
94 static struct serial_device cogent_serial_drv = {
95 .name = "cogent_serial",
96 .start = cogent_serial_init,
98 .setbrg = cogent_serial_setbrg,
99 .putc = cogent_serial_putc,
100 .puts = cogent_serial_puts,
101 .getc = cogent_serial_getc,
102 .tstc = cogent_serial_tstc,
105 void cogent_serial_initialize(void)
107 serial_register(&cogent_serial_drv);
110 __weak struct serial_device *default_serial_console(void)
112 return &cogent_serial_drv;
115 int serial_init(void)
117 return cogent_serial_init();
120 void serial_setbrg(void)
122 cogent_serial_setbrg();
125 void serial_putc(const char c)
127 cogent_serial_putc(c);
130 void serial_puts(const char *s)
132 cogent_serial_puts(s);
135 int serial_getc(void)
137 return cogent_serial_getc();
140 int serial_tstc(void)
142 return cogent_serial_tstc();
145 #endif /* CONS_NONE */
147 #if defined(CONFIG_CMD_KGDB) && \
148 defined(CONFIG_KGDB_NONE)
150 #if CONFIG_KGDB_INDEX == CONFIG_CONS_INDEX
151 #error Console and kgdb are on the same serial port - this is not supported
154 #if CONFIG_KGDB_INDEX == 1
155 #define CMA_MB_KGDB_SER_BASE CMA_MB_SERIALA_BASE
156 #elif CONFIG_KGDB_INDEX == 2
157 #define CMA_MB_KGDB_SER_BASE CMA_MB_SERIALB_BASE
158 #elif CONFIG_KGDB_INDEX == 3 && (CMA_MB_CAPS & CMA_MB_CAP_SER2)
159 #define CMA_MB_KGDB_SER_BASE CMA_MB_SER2A_BASE
160 #elif CONFIG_KGDB_INDEX == 4 && (CMA_MB_CAPS & CMA_MB_CAP_SER2)
161 #define CMA_MB_KGDB_SER_BASE CMA_MB_SER2B_BASE
163 #error CONFIG_KGDB_INDEX must be configured for Cogent motherboard serial
166 void kgdb_serial_init (void)
168 cma_mb_serial *mbsp = (cma_mb_serial *) CMA_MB_KGDB_SER_BASE;
169 unsigned int divisor;
171 if ((divisor = br_to_div (CONFIG_KGDB_BAUDRATE)) == 0)
174 cma_mb_reg_write (&mbsp->ser_ier, 0x00); /* turn off interrupts */
175 cma_mb_reg_write (&mbsp->ser_lcr, 0x80); /* Access baud rate(set DLAB) */
176 cma_mb_reg_write (&mbsp->ser_brl, divisor & 0xff);
177 cma_mb_reg_write (&mbsp->ser_brh, (divisor >> 8) & 0xff);
178 cma_mb_reg_write (&mbsp->ser_lcr, 0x03); /* 8 data, 1 stop, no parity */
179 cma_mb_reg_write (&mbsp->ser_mcr, 0x03); /* RTS/DTR */
180 cma_mb_reg_write (&mbsp->ser_fcr, 0x07); /* Clear & enable FIFOs */
182 printf ("[on cma10x serial port B] ");
185 void putDebugChar (int c)
187 cma_mb_serial *mbsp = (cma_mb_serial *) CMA_MB_KGDB_SER_BASE;
189 while ((cma_mb_reg_read (&mbsp->ser_lsr) & LSR_THRE) == 0);
191 cma_mb_reg_write (&mbsp->ser_thr, c & 0xff);
194 void putDebugStr (const char *str)
196 while (*str != '\0') {
199 putDebugChar (*str++);
203 int getDebugChar (void)
205 cma_mb_serial *mbsp = (cma_mb_serial *) CMA_MB_KGDB_SER_BASE;
207 while ((cma_mb_reg_read (&mbsp->ser_lsr) & LSR_DR) == 0);
209 return ((int) cma_mb_reg_read (&mbsp->ser_rhr) & 0x7f);
212 void kgdb_interruptible (int yes)
214 cma_mb_serial *mbsp = (cma_mb_serial *) CMA_MB_KGDB_SER_BASE;
217 printf ("kgdb: turning serial ints on\n");
218 cma_mb_reg_write (&mbsp->ser_ier, 0xf);
220 printf ("kgdb: turning serial ints off\n");
221 cma_mb_reg_write (&mbsp->ser_ier, 0x0);
225 #endif /* KGDB && KGDB_NONE */
227 #endif /* CAPS & SERPAR */