1 /* Serialport functions for debugging
3 * Copyright (c) 2000 Axis Communications AB
8 * console_print_etrax(char *buf)
14 * $Log: debugport.c,v $
15 * Revision 1.11 2003/07/07 09:53:36 starvik
16 * Revert all the 2.5.74 merge changes to make the console work again
18 * Revision 1.9 2003/02/17 17:07:23 starvik
19 * Solved the problem with corrupted debug output (from Linux 2.4)
20 * * Wait until DMA, FIFO and pipe is empty before and after transmissions
21 * * Buffer data until a FIFO flush can be triggered.
23 * Revision 1.8 2003/01/22 06:48:36 starvik
24 * Fixed warnings issued by GCC 3.2.1
26 * Revision 1.7 2002/12/12 08:26:32 starvik
27 * Don't use C-comments inside CVS comments
29 * Revision 1.6 2002/12/11 15:42:02 starvik
30 * Extracted v10 (ETRAX 100LX) specific stuff from arch/cris/kernel/
32 * Revision 1.5 2002/11/20 06:58:03 starvik
35 * Revision 1.4 2002/11/19 14:35:24 starvik
36 * Changes from linux 2.4
37 * Changed struct initializer syntax to the currently prefered notation
39 * Revision 1.3 2002/11/06 09:47:03 starvik
40 * Modified for new interrupt macros
42 * Revision 1.2 2002/01/21 15:21:50 bjornw
43 * Update for kdev_t changes
45 * Revision 1.6 2001/04/17 13:58:39 orjanf
46 * * Renamed CONFIG_KGDB to CONFIG_ETRAX_KGDB.
48 * Revision 1.5 2001/03/26 14:22:05 bjornw
49 * Namechange of some config options
51 * Revision 1.4 2000/10/06 12:37:26 bjornw
52 * Use physical addresses when talking to DMA
57 #include <linux/config.h>
58 #include <linux/console.h>
59 #include <linux/init.h>
60 #include <linux/major.h>
61 #include <linux/delay.h>
63 #include <asm/system.h>
64 #include <asm/arch/svinto.h>
65 #include <asm/io.h> /* Get SIMCOUT. */
67 /* Which serial-port is our debug port ? */
69 #if defined(CONFIG_ETRAX_DEBUG_PORT0) || defined(CONFIG_ETRAX_DEBUG_PORT_NULL)
70 #define DEBUG_PORT_IDX 0
71 #define DEBUG_OCMD R_DMA_CH6_CMD
72 #define DEBUG_FIRST R_DMA_CH6_FIRST
73 #define DEBUG_OCLRINT R_DMA_CH6_CLR_INTR
74 #define DEBUG_STATUS R_DMA_CH6_STATUS
75 #define DEBUG_READ R_SERIAL0_READ
76 #define DEBUG_WRITE R_SERIAL0_TR_DATA
77 #define DEBUG_TR_CTRL R_SERIAL0_TR_CTRL
78 #define DEBUG_REC_CTRL R_SERIAL0_REC_CTRL
79 #define DEBUG_IRQ IO_STATE(R_IRQ_MASK1_SET, ser0_data, set)
80 #define DEBUG_DMA_IRQ_CLR IO_STATE(R_IRQ_MASK2_CLR, dma6_descr, clr)
83 #ifdef CONFIG_ETRAX_DEBUG_PORT1
84 #define DEBUG_PORT_IDX 1
85 #define DEBUG_OCMD R_DMA_CH8_CMD
86 #define DEBUG_FIRST R_DMA_CH8_FIRST
87 #define DEBUG_OCLRINT R_DMA_CH8_CLR_INTR
88 #define DEBUG_STATUS R_DMA_CH8_STATUS
89 #define DEBUG_READ R_SERIAL1_READ
90 #define DEBUG_WRITE R_SERIAL1_TR_DATA
91 #define DEBUG_TR_CTRL R_SERIAL1_TR_CTRL
92 #define DEBUG_REC_CTRL R_SERIAL1_REC_CTRL
93 #define DEBUG_IRQ IO_STATE(R_IRQ_MASK1_SET, ser1_data, set)
94 #define DEBUG_DMA_IRQ_CLR IO_STATE(R_IRQ_MASK2_CLR, dma8_descr, clr)
97 #ifdef CONFIG_ETRAX_DEBUG_PORT2
98 #define DEBUG_PORT_IDX 2
99 #define DEBUG_OCMD R_DMA_CH2_CMD
100 #define DEBUG_FIRST R_DMA_CH2_FIRST
101 #define DEBUG_OCLRINT R_DMA_CH2_CLR_INTR
102 #define DEBUG_STATUS R_DMA_CH2_STATUS
103 #define DEBUG_READ R_SERIAL2_READ
104 #define DEBUG_WRITE R_SERIAL2_TR_DATA
105 #define DEBUG_TR_CTRL R_SERIAL2_TR_CTRL
106 #define DEBUG_REC_CTRL R_SERIAL2_REC_CTRL
107 #define DEBUG_IRQ IO_STATE(R_IRQ_MASK1_SET, ser2_data, set)
108 #define DEBUG_DMA_IRQ_CLR IO_STATE(R_IRQ_MASK2_CLR, dma2_descr, clr)
111 #ifdef CONFIG_ETRAX_DEBUG_PORT3
112 #define DEBUG_PORT_IDX 3
113 #define DEBUG_OCMD R_DMA_CH4_CMD
114 #define DEBUG_FIRST R_DMA_CH4_FIRST
115 #define DEBUG_OCLRINT R_DMA_CH4_CLR_INTR
116 #define DEBUG_STATUS R_DMA_CH4_STATUS
117 #define DEBUG_READ R_SERIAL3_READ
118 #define DEBUG_WRITE R_SERIAL3_TR_DATA
119 #define DEBUG_TR_CTRL R_SERIAL3_TR_CTRL
120 #define DEBUG_REC_CTRL R_SERIAL3_REC_CTRL
121 #define DEBUG_IRQ IO_STATE(R_IRQ_MASK1_SET, ser3_data, set)
122 #define DEBUG_DMA_IRQ_CLR IO_STATE(R_IRQ_MASK2_CLR, dma4_descr, clr)
125 #define MIN_SIZE 32 /* Size that triggers the FIFO to flush characters to interface */
127 /* Write a string of count length to the console (debug port) using DMA, polled
128 * for completion. Interrupts are disabled during the whole process. Some
129 * caution needs to be taken to not interfere with ttyS business on this port.
133 console_write(struct console *co, const char *buf, unsigned int len)
136 static struct etrax_dma_descr descr;
137 static struct etrax_dma_descr descr2;
138 static char tmp_buf[MIN_SIZE];
139 static int tmp_size = 0;
143 #ifdef CONFIG_ETRAX_DEBUG_PORT_NULL
144 /* no debug printout at all */
148 #ifdef CONFIG_SVINTO_SIM
149 /* no use to simulate the serial debug output */
154 local_save_flags(flags);
157 #ifdef CONFIG_ETRAX_KGDB
158 /* kgdb needs to output debug info using the gdb protocol */
159 putDebugString(buf, len);
160 local_irq_restore(flags);
164 /* To make this work together with the real serial port driver
165 * we have to make sure that everything is flushed when we leave
166 * here. The following steps are made to assure this:
167 * 1. Wait until DMA stops, FIFO is empty and serial port pipeline empty.
168 * 2. Write at least half the FIFO to trigger flush to serial port.
169 * 3. Wait until DMA stops, FIFO is empty and serial port pipeline empty.
172 /* Do we have enough characters to make the DMA/FIFO happy? */
173 if (tmp_size + len < MIN_SIZE)
175 int size = min((int)(MIN_SIZE - tmp_size),(int)len);
176 memcpy(&tmp_buf[tmp_size], buf, size);
180 /* Pad with space if complete line */
181 if (tmp_buf[tmp_size-1] == '\n')
183 memset(&tmp_buf[tmp_size-1], ' ', MIN_SIZE - tmp_size);
184 tmp_buf[MIN_SIZE - 1] = '\n';
190 /* Wait for more characters */
191 local_irq_restore(flags);
196 /* make sure the transmitter is enabled.
197 * NOTE: this overrides any setting done in ttySx, to 8N1, no auto-CTS.
198 * in the future, move the tr/rec_ctrl shadows from etrax100ser.c to
199 * shadows.c and use it here as well...
202 *DEBUG_TR_CTRL = 0x40;
203 while(*DEBUG_OCMD & 7); /* Until DMA is not running */
204 while(*DEBUG_STATUS & 0x7f); /* wait until output FIFO is empty as well */
205 udelay(200); /* Wait for last two characters to leave the serial transmitter */
209 descr.ctrl = len ? 0 : d_eop | d_wait | d_eol;
210 descr.sw_len = tmp_size;
211 descr.buf = virt_to_phys(tmp_buf);
212 descr.next = virt_to_phys(&descr2);
213 descr2.ctrl = d_eop | d_wait | d_eol;
215 descr2.buf = virt_to_phys((char*)buf);
219 descr.ctrl = d_eop | d_wait | d_eol;
221 descr.buf = virt_to_phys((char*)buf);
224 *DEBUG_FIRST = virt_to_phys(&descr); /* write to R_DMAx_FIRST */
225 *DEBUG_OCMD = 1; /* dma command start -> R_DMAx_CMD */
227 /* wait until the output dma channel is ready again */
228 while(*DEBUG_OCMD & 7);
229 while(*DEBUG_STATUS & 0x7f);
233 local_irq_restore(flags);
236 /* legacy function */
239 console_print_etrax(const char *buf)
241 console_write(NULL, buf, strlen(buf));
244 /* Use polling to get a single character FROM the debug port */
249 unsigned long readval;
252 readval = *DEBUG_READ;
253 } while(!(readval & IO_MASK(R_SERIAL0_READ, data_avail)));
255 return (readval & IO_MASK(R_SERIAL0_READ, data_in));
258 /* Use polling to put a single character to the debug port */
261 putDebugChar(int val)
263 while(!(*DEBUG_READ & IO_MASK(R_SERIAL0_READ, tr_ready))) ;
268 /* Enable irq for receiving chars on the debug port, used by kgdb */
273 *R_IRQ_MASK1_SET = DEBUG_IRQ;
274 /* use R_VECT_MASK directly, since we really bypass Linux normal
275 * IRQ handling in kgdb anyway, we don't need to use enable_irq
277 *R_VECT_MASK_SET = IO_STATE(R_VECT_MASK_SET, serial, set);
279 *DEBUG_REC_CTRL = IO_STATE(R_SERIAL0_REC_CTRL, rec_enable, enable);
283 console_device(struct console *c)
285 return mk_kdev(TTY_MAJOR, 64 + c->index);
289 console_setup(struct console *co, char *options)
294 static struct console sercons = {
296 .write = console_write,
298 .device = console_device,
300 .setup = console_setup,
301 .flags = CON_PRINTBUFFER,
302 .index = DEBUG_PORT_IDX,
308 * Register console (for printk's etc)
312 init_etrax_debug(void)
314 register_console(&sercons);