File: /usr/src/linux/arch/cris/kernel/debugport.c
1 /* Serialport functions for debugging
2 *
3 * Copyright (c) 2000 Axis Communications AB
4 *
5 * Authors: Bjorn Wesen
6 *
7 * Exports:
8 * console_print_etrax(char *buf)
9 * int getDebugChar()
10 * putDebugChar(int)
11 * enableDebugIRQ()
12 * init_etrax_debug()
13 *
14 * $Log: debugport.c,v $
15 * Revision 1.6 2001/04/17 13:58:39 orjanf
16 * * Renamed CONFIG_KGDB to CONFIG_ETRAX_KGDB.
17 *
18 * Revision 1.5 2001/03/26 14:22:05 bjornw
19 * Namechange of some config options
20 *
21 * Revision 1.4 2000/10/06 12:37:26 bjornw
22 * Use physical addresses when talking to DMA
23 *
24 *
25 */
26
27 #include <linux/config.h>
28 #include <linux/console.h>
29 #include <linux/init.h>
30 #include <linux/major.h>
31
32 #include <asm/system.h>
33 #include <asm/svinto.h>
34 #include <asm/io.h> /* Get SIMCOUT. */
35
36 /* Which serial-port is our debug port ? */
37
38 #if defined(CONFIG_ETRAX_DEBUG_PORT0) || defined(CONFIG_ETRAX_DEBUG_PORT_NULL)
39 #define DEBUG_PORT_IDX 0
40 #define DEBUG_OCMD R_DMA_CH6_CMD
41 #define DEBUG_FIRST R_DMA_CH6_FIRST
42 #define DEBUG_OCLRINT R_DMA_CH6_CLR_INTR
43 #define DEBUG_STATUS R_DMA_CH6_STATUS
44 #define DEBUG_READ R_SERIAL0_READ
45 #define DEBUG_WRITE R_SERIAL0_TR_DATA
46 #define DEBUG_TR_CTRL R_SERIAL0_TR_CTRL
47 #define DEBUG_REC_CTRL R_SERIAL0_REC_CTRL
48 #define DEBUG_IRQ IO_STATE(R_IRQ_MASK1_SET, ser0_data, set)
49 #define DEBUG_DMA_IRQ_CLR IO_STATE(R_IRQ_MASK2_CLR, dma6_descr, clr)
50 #endif
51
52 #ifdef CONFIG_ETRAX_DEBUG_PORT1
53 #define DEBUG_PORT_IDX 1
54 #define DEBUG_OCMD R_DMA_CH8_CMD
55 #define DEBUG_FIRST R_DMA_CH8_FIRST
56 #define DEBUG_OCLRINT R_DMA_CH8_CLR_INTR
57 #define DEBUG_STATUS R_DMA_CH8_STATUS
58 #define DEBUG_READ R_SERIAL1_READ
59 #define DEBUG_WRITE R_SERIAL1_TR_DATA
60 #define DEBUG_TR_CTRL R_SERIAL1_TR_CTRL
61 #define DEBUG_REC_CTRL R_SERIAL1_REC_CTRL
62 #define DEBUG_IRQ IO_STATE(R_IRQ_MASK1_SET, ser1_data, set)
63 #define DEBUG_DMA_IRQ_CLR IO_STATE(R_IRQ_MASK2_CLR, dma8_descr, clr)
64 #endif
65
66 #ifdef CONFIG_ETRAX_DEBUG_PORT2
67 #define DEBUG_PORT_IDX 2
68 #define DEBUG_OCMD R_DMA_CH2_CMD
69 #define DEBUG_FIRST R_DMA_CH2_FIRST
70 #define DEBUG_OCLRINT R_DMA_CH2_CLR_INTR
71 #define DEBUG_STATUS R_DMA_CH2_STATUS
72 #define DEBUG_READ R_SERIAL2_READ
73 #define DEBUG_WRITE R_SERIAL2_TR_DATA
74 #define DEBUG_TR_CTRL R_SERIAL2_TR_CTRL
75 #define DEBUG_REC_CTRL R_SERIAL2_REC_CTRL
76 #define DEBUG_IRQ IO_STATE(R_IRQ_MASK1_SET, ser2_data, set)
77 #define DEBUG_DMA_IRQ_CLR IO_STATE(R_IRQ_MASK2_CLR, dma2_descr, clr)
78 #endif
79
80 #ifdef CONFIG_ETRAX_DEBUG_PORT3
81 #define DEBUG_PORT_IDX 3
82 #define DEBUG_OCMD R_DMA_CH4_CMD
83 #define DEBUG_FIRST R_DMA_CH4_FIRST
84 #define DEBUG_OCLRINT R_DMA_CH4_CLR_INTR
85 #define DEBUG_STATUS R_DMA_CH4_STATUS
86 #define DEBUG_READ R_SERIAL3_READ
87 #define DEBUG_WRITE R_SERIAL3_TR_DATA
88 #define DEBUG_TR_CTRL R_SERIAL3_TR_CTRL
89 #define DEBUG_REC_CTRL R_SERIAL3_REC_CTRL
90 #define DEBUG_IRQ IO_STATE(R_IRQ_MASK1_SET, ser3_data, set)
91 #define DEBUG_DMA_IRQ_CLR IO_STATE(R_IRQ_MASK2_CLR, dma4_descr, clr)
92 #endif
93
94 /* Write a string of count length to the console (debug port) using DMA, polled
95 * for completion. Interrupts are disabled during the whole process. Some
96 * caution needs to be taken to not interfere with ttyS business on this port.
97 */
98
99 static void
100 console_write(struct console *co, const char *buf, unsigned int len)
101 {
102 static struct etrax_dma_descr descr;
103 unsigned long flags;
104 int in_progress;
105
106 #ifdef CONFIG_ETRAX_DEBUG_PORT_NULL
107 /* no debug printout at all */
108 return;
109 #endif
110
111 #ifdef CONFIG_SVINTO_SIM
112 /* no use to simulate the serial debug output */
113 SIMCOUT(buf,len);
114 return;
115 #endif
116
117 save_flags(flags);
118 cli();
119
120 #ifdef CONFIG_ETRAX_KGDB
121 /* kgdb needs to output debug info using the gdb protocol */
122 putDebugString(buf, len);
123 restore_flags(flags);
124 return;
125 #endif
126
127 /* make sure the transmitter is enabled.
128 * NOTE: this overrides any setting done in ttySx, to 8N1, no auto-CTS.
129 * in the future, move the tr/rec_ctrl shadows from etrax100ser.c to
130 * shadows.c and use it here as well...
131 */
132
133 *DEBUG_TR_CTRL = 0x40;
134
135 /* if the tty has some ongoing business, remember it */
136
137 in_progress = *DEBUG_OCMD & 7;
138
139 if(in_progress) {
140 /* wait until the output dma channel is ready */
141
142 while(*DEBUG_OCMD & 7) /* nothing */ ;
143 }
144
145 descr.ctrl = d_eol;
146 descr.sw_len = len;
147 descr.buf = __pa(buf);
148
149 *DEBUG_FIRST = __pa(&descr); /* write to R_DMAx_FIRST */
150 *DEBUG_OCMD = 1; /* dma command start -> R_DMAx_CMD */
151
152 /* wait until the output dma channel is ready again */
153
154 while(*DEBUG_OCMD & 7) /* nothing */;
155
156 /* clear pending interrupts so we don't get a surprise below */
157
158 if(in_progress)
159 *DEBUG_OCLRINT = 2; /* only clear EOP, leave DESCR for the tty */
160 else
161 *DEBUG_OCLRINT = 3; /* clear both EOP and DESCR */
162
163 while(*DEBUG_STATUS & 0x7f); /* wait until output FIFO is empty as well */
164
165 restore_flags(flags);
166 }
167
168 /* legacy function */
169
170 void
171 console_print_etrax(const char *buf)
172 {
173 console_write(NULL, buf, strlen(buf));
174 }
175
176 /* Use polling to get a single character FROM the debug port */
177
178 int
179 getDebugChar(void)
180 {
181 unsigned long readval;
182
183 do {
184 readval = *DEBUG_READ;
185 } while(!(readval & IO_MASK(R_SERIAL0_READ, data_avail)));
186
187 return (readval & IO_MASK(R_SERIAL0_READ, data_in));
188 }
189
190 /* Use polling to put a single character to the debug port */
191
192 void
193 putDebugChar(int val)
194 {
195 while(!(*DEBUG_READ & IO_MASK(R_SERIAL0_READ, tr_ready))) ;
196 ;
197 *DEBUG_WRITE = val;
198 }
199
200 /* Enable irq for receiving chars on the debug port, used by kgdb */
201
202 void
203 enableDebugIRQ(void)
204 {
205 *R_IRQ_MASK1_SET = DEBUG_IRQ;
206 /* use R_VECT_MASK directly, since we really bypass Linux normal
207 * IRQ handling in kgdb anyway, we don't need to use enable_irq
208 */
209 *R_VECT_MASK_SET = IO_STATE(R_VECT_MASK_SET, serial, set);
210
211 *DEBUG_REC_CTRL = IO_STATE(R_SERIAL0_REC_CTRL, rec_enable, enable);
212 }
213
214 static kdev_t
215 console_device(struct console *c)
216 {
217 return MKDEV(TTY_MAJOR, 64 + c->index);
218 }
219
220 static int __init
221 console_setup(struct console *co, char *options)
222 {
223 return 0;
224 }
225
226 static struct console sercons = {
227 "ttyS",
228 console_write,
229 NULL,
230 console_device,
231 NULL,
232 NULL,
233 console_setup,
234 CON_PRINTBUFFER,
235 DEBUG_PORT_IDX,
236 0,
237 NULL
238 };
239
240 /*
241 * Register console (for printk's etc)
242 */
243
244 void __init
245 init_etrax_debug(void)
246 {
247 register_console(&sercons);
248 }
249