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.9 2003/02/17 07:10:34 starvik
16 * Last merge was incomplete
18 * Revision 1.8 2003/02/17 06:59:00 starvik
19 * Merged printk corruption fix
21 * Revision 1.7.4.1 2003/01/27 10:21:57 starvik
22 * Solved the problem with corrupted debug output
23 * * Wait until DMA, FIFO and pipe is empty before and after transmissions
24 * * Buffer data until a FIFO flush can be triggered.
26 * Revision 1.7 2002/04/23 15:35:50 bjornw
27 * Cleaned up sercons struct and removed the waitkey ptr (2.4.19-pre)
29 * Revision 1.6 2001/04/17 13:58:39 orjanf
30 * * Renamed CONFIG_KGDB to CONFIG_ETRAX_KGDB.
32 * Revision 1.5 2001/03/26 14:22:05 bjornw
33 * Namechange of some config options
35 * Revision 1.4 2000/10/06 12:37:26 bjornw
36 * Use physical addresses when talking to DMA
41 #include <linux/config.h>
42 #include <linux/console.h>
43 #include <linux/init.h>
44 #include <linux/major.h>
45 #include <linux/delay.h>
47 #include <asm/system.h>
48 #include <asm/svinto.h>
49 #include <asm/io.h> /* Get SIMCOUT. */
51 /* Which serial-port is our debug port ? */
53 #if defined(CONFIG_ETRAX_DEBUG_PORT0) || defined(CONFIG_ETRAX_DEBUG_PORT_NULL)
54 #define DEBUG_PORT_IDX 0
55 #define DEBUG_OCMD R_DMA_CH6_CMD
56 #define DEBUG_FIRST R_DMA_CH6_FIRST
57 #define DEBUG_OCLRINT R_DMA_CH6_CLR_INTR
58 #define DEBUG_STATUS R_DMA_CH6_STATUS
59 #define DEBUG_READ R_SERIAL0_READ
60 #define DEBUG_WRITE R_SERIAL0_TR_DATA
61 #define DEBUG_TR_CTRL R_SERIAL0_TR_CTRL
62 #define DEBUG_REC_CTRL R_SERIAL0_REC_CTRL
63 #define DEBUG_IRQ IO_STATE(R_IRQ_MASK1_SET, ser0_data, set)
64 #define DEBUG_DMA_IRQ_CLR IO_STATE(R_IRQ_MASK2_CLR, dma6_descr, clr)
67 #ifdef CONFIG_ETRAX_DEBUG_PORT1
68 #define DEBUG_PORT_IDX 1
69 #define DEBUG_OCMD R_DMA_CH8_CMD
70 #define DEBUG_FIRST R_DMA_CH8_FIRST
71 #define DEBUG_OCLRINT R_DMA_CH8_CLR_INTR
72 #define DEBUG_STATUS R_DMA_CH8_STATUS
73 #define DEBUG_READ R_SERIAL1_READ
74 #define DEBUG_WRITE R_SERIAL1_TR_DATA
75 #define DEBUG_TR_CTRL R_SERIAL1_TR_CTRL
76 #define DEBUG_REC_CTRL R_SERIAL1_REC_CTRL
77 #define DEBUG_IRQ IO_STATE(R_IRQ_MASK1_SET, ser1_data, set)
78 #define DEBUG_DMA_IRQ_CLR IO_STATE(R_IRQ_MASK2_CLR, dma8_descr, clr)
81 #ifdef CONFIG_ETRAX_DEBUG_PORT2
82 #define DEBUG_PORT_IDX 2
83 #define DEBUG_OCMD R_DMA_CH2_CMD
84 #define DEBUG_FIRST R_DMA_CH2_FIRST
85 #define DEBUG_OCLRINT R_DMA_CH2_CLR_INTR
86 #define DEBUG_STATUS R_DMA_CH2_STATUS
87 #define DEBUG_READ R_SERIAL2_READ
88 #define DEBUG_WRITE R_SERIAL2_TR_DATA
89 #define DEBUG_TR_CTRL R_SERIAL2_TR_CTRL
90 #define DEBUG_REC_CTRL R_SERIAL2_REC_CTRL
91 #define DEBUG_IRQ IO_STATE(R_IRQ_MASK1_SET, ser2_data, set)
92 #define DEBUG_DMA_IRQ_CLR IO_STATE(R_IRQ_MASK2_CLR, dma2_descr, clr)
95 #ifdef CONFIG_ETRAX_DEBUG_PORT3
96 #define DEBUG_PORT_IDX 3
97 #define DEBUG_OCMD R_DMA_CH4_CMD
98 #define DEBUG_FIRST R_DMA_CH4_FIRST
99 #define DEBUG_OCLRINT R_DMA_CH4_CLR_INTR
100 #define DEBUG_STATUS R_DMA_CH4_STATUS
101 #define DEBUG_READ R_SERIAL3_READ
102 #define DEBUG_WRITE R_SERIAL3_TR_DATA
103 #define DEBUG_TR_CTRL R_SERIAL3_TR_CTRL
104 #define DEBUG_REC_CTRL R_SERIAL3_REC_CTRL
105 #define DEBUG_IRQ IO_STATE(R_IRQ_MASK1_SET, ser3_data, set)
106 #define DEBUG_DMA_IRQ_CLR IO_STATE(R_IRQ_MASK2_CLR, dma4_descr, clr)
109 #define MIN_SIZE 32 /* Size that triggers the FIFO to flush characters to interface */
111 /* Write a string of count length to the console (debug port) using DMA, polled
112 * for completion. Interrupts are disabled during the whole process. Some
113 * caution needs to be taken to not interfere with ttyS business on this port.
117 console_write(struct console *co, const char *buf, unsigned int len)
119 static struct etrax_dma_descr descr;
120 static struct etrax_dma_descr descr2;
121 static char tmp_buf[MIN_SIZE];
122 static int tmp_size = 0;
126 #ifdef CONFIG_ETRAX_DEBUG_PORT_NULL
127 /* no debug printout at all */
131 #ifdef CONFIG_SVINTO_SIM
132 /* no use to simulate the serial debug output */
140 #ifdef CONFIG_ETRAX_KGDB
141 /* kgdb needs to output debug info using the gdb protocol */
142 putDebugString(buf, len);
143 restore_flags(flags);
146 /* To make this work together with the real serial port driver
147 * we have to make sure that everything is flushed when we leave
148 * here. The following steps are made to assure this:
149 * 1. Wait until DMA stops, FIFO is empty and serial port pipeline empty.
150 * 2. Write at least half the FIFO to trigger flush to serial port.
151 * 3. Wait until DMA stops, FIFO is empty and serial port pipeline empty.
154 /* Do we have enough characters to make the DMA/FIFO happy? */
155 if (tmp_size + len < MIN_SIZE)
157 int size = min((int)(MIN_SIZE - tmp_size),(int)len);
158 memcpy(&tmp_buf[tmp_size], buf, size);
162 /* Pad with space if complete line */
163 if (tmp_buf[tmp_size-1] == '\n')
165 memset(&tmp_buf[tmp_size-1], ' ', MIN_SIZE - tmp_size);
166 tmp_buf[MIN_SIZE - 1] = '\n';
172 /* Wait for more characters */
173 restore_flags(flags);
178 /* make sure the transmitter is enabled.
179 * NOTE: this overrides any setting done in ttySx, to 8N1, no auto-CTS.
180 * in the future, move the tr/rec_ctrl shadows from etrax100ser.c to
181 * shadows.c and use it here as well...
184 *DEBUG_TR_CTRL = 0x40;
185 while(*DEBUG_OCMD & 7); /* Until DMA is not running */
186 while(*DEBUG_STATUS & 0x7f); /* wait until output FIFO is empty as well */
187 udelay(200); /* Wait for last two characters to leave the serial transmitter */
191 descr.ctrl = len ? 0 : d_eop | d_wait | d_eol;
192 descr.sw_len = tmp_size;
193 descr.buf = virt_to_phys(tmp_buf);
194 descr.next = virt_to_phys(&descr2);
195 descr2.ctrl = d_eop | d_wait | d_eol;
197 descr2.buf = virt_to_phys((char*)buf);
201 descr.ctrl = d_eop | d_wait | d_eol;
203 descr.buf = virt_to_phys((char*)buf);
206 *DEBUG_FIRST = virt_to_phys(&descr); /* write to R_DMAx_FIRST */
207 *DEBUG_OCMD = 1; /* dma command start -> R_DMAx_CMD */
209 /* wait until the output dma channel is ready again */
210 while(*DEBUG_OCMD & 7);
211 while(*DEBUG_STATUS & 0x7f);
215 restore_flags(flags);
218 /* legacy function */
221 console_print_etrax(const char *buf)
223 console_write(NULL, buf, strlen(buf));
226 /* Use polling to get a single character FROM the debug port */
231 unsigned long readval;
234 readval = *DEBUG_READ;
235 } while(!(readval & IO_MASK(R_SERIAL0_READ, data_avail)));
237 return (readval & IO_MASK(R_SERIAL0_READ, data_in));
240 /* Use polling to put a single character to the debug port */
243 putDebugChar(int val)
245 while(!(*DEBUG_READ & IO_MASK(R_SERIAL0_READ, tr_ready))) ;
250 /* Enable irq for receiving chars on the debug port, used by kgdb */
255 *R_IRQ_MASK1_SET = DEBUG_IRQ;
256 /* use R_VECT_MASK directly, since we really bypass Linux normal
257 * IRQ handling in kgdb anyway, we don't need to use enable_irq
259 *R_VECT_MASK_SET = IO_STATE(R_VECT_MASK_SET, serial, set);
261 *DEBUG_REC_CTRL = IO_STATE(R_SERIAL0_REC_CTRL, rec_enable, enable);
265 console_device(struct console *c)
267 return MKDEV(TTY_MAJOR, 64 + c->index);
271 console_setup(struct console *co, char *options)
276 static struct console sercons = {
278 write: console_write,
280 device : console_device,
282 setup : console_setup,
283 flags : CON_PRINTBUFFER,
284 index : DEBUG_PORT_IDX,
290 * Register console (for printk's etc)
294 init_etrax_debug(void)
296 register_console(&sercons);