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.1.1.1 2005/04/29 01:40:43 echo
16 * Project for BCMDT_3.0
18 * Revision 1.14 2004/05/17 13:11:29 starvik
19 * Disable DMA until real serial driver is up
21 * Revision 1.13 2004/05/14 07:58:01 starvik
22 * Merge of changes from 2.4
24 * Revision 1.12 2003/09/11 07:29:49 starvik
25 * Merge of Linux 2.6.0-test5
27 * Revision 1.11 2003/07/07 09:53:36 starvik
28 * Revert all the 2.5.74 merge changes to make the console work again
30 * Revision 1.9 2003/02/17 17:07:23 starvik
31 * Solved the problem with corrupted debug output (from Linux 2.4)
32 * * Wait until DMA, FIFO and pipe is empty before and after transmissions
33 * * Buffer data until a FIFO flush can be triggered.
35 * Revision 1.8 2003/01/22 06:48:36 starvik
36 * Fixed warnings issued by GCC 3.2.1
38 * Revision 1.7 2002/12/12 08:26:32 starvik
39 * Don't use C-comments inside CVS comments
41 * Revision 1.6 2002/12/11 15:42:02 starvik
42 * Extracted v10 (ETRAX 100LX) specific stuff from arch/cris/kernel/
44 * Revision 1.5 2002/11/20 06:58:03 starvik
47 * Revision 1.4 2002/11/19 14:35:24 starvik
48 * Changes from linux 2.4
49 * Changed struct initializer syntax to the currently prefered notation
51 * Revision 1.3 2002/11/06 09:47:03 starvik
52 * Modified for new interrupt macros
54 * Revision 1.2 2002/01/21 15:21:50 bjornw
55 * Update for kdev_t changes
57 * Revision 1.6 2001/04/17 13:58:39 orjanf
58 * * Renamed CONFIG_KGDB to CONFIG_ETRAX_KGDB.
60 * Revision 1.5 2001/03/26 14:22:05 bjornw
61 * Namechange of some config options
63 * Revision 1.4 2000/10/06 12:37:26 bjornw
64 * Use physical addresses when talking to DMA
69 #include <linux/config.h>
70 #include <linux/console.h>
71 #include <linux/init.h>
72 #include <linux/major.h>
73 #include <linux/delay.h>
74 #include <linux/tty.h>
75 #include <asm/system.h>
76 #include <asm/arch/svinto.h>
77 #include <asm/io.h> /* Get SIMCOUT. */
79 /* Which serial-port is our debug port ? */
81 #if defined(CONFIG_ETRAX_DEBUG_PORT0) || defined(CONFIG_ETRAX_DEBUG_PORT_NULL)
82 #define DEBUG_PORT_IDX 0
83 #define DEBUG_OCMD R_DMA_CH6_CMD
84 #define DEBUG_FIRST R_DMA_CH6_FIRST
85 #define DEBUG_OCLRINT R_DMA_CH6_CLR_INTR
86 #define DEBUG_STATUS R_DMA_CH6_STATUS
87 #define DEBUG_READ R_SERIAL0_READ
88 #define DEBUG_WRITE R_SERIAL0_TR_DATA
89 #define DEBUG_TR_CTRL R_SERIAL0_TR_CTRL
90 #define DEBUG_REC_CTRL R_SERIAL0_REC_CTRL
91 #define DEBUG_IRQ IO_STATE(R_IRQ_MASK1_SET, ser0_data, set)
92 #define DEBUG_DMA_IRQ_CLR IO_STATE(R_IRQ_MASK2_CLR, dma6_descr, clr)
95 #ifdef CONFIG_ETRAX_DEBUG_PORT1
96 #define DEBUG_PORT_IDX 1
97 #define DEBUG_OCMD R_DMA_CH8_CMD
98 #define DEBUG_FIRST R_DMA_CH8_FIRST
99 #define DEBUG_OCLRINT R_DMA_CH8_CLR_INTR
100 #define DEBUG_STATUS R_DMA_CH8_STATUS
101 #define DEBUG_READ R_SERIAL1_READ
102 #define DEBUG_WRITE R_SERIAL1_TR_DATA
103 #define DEBUG_TR_CTRL R_SERIAL1_TR_CTRL
104 #define DEBUG_REC_CTRL R_SERIAL1_REC_CTRL
105 #define DEBUG_IRQ IO_STATE(R_IRQ_MASK1_SET, ser1_data, set)
106 #define DEBUG_DMA_IRQ_CLR IO_STATE(R_IRQ_MASK2_CLR, dma8_descr, clr)
109 #ifdef CONFIG_ETRAX_DEBUG_PORT2
110 #define DEBUG_PORT_IDX 2
111 #define DEBUG_OCMD R_DMA_CH2_CMD
112 #define DEBUG_FIRST R_DMA_CH2_FIRST
113 #define DEBUG_OCLRINT R_DMA_CH2_CLR_INTR
114 #define DEBUG_STATUS R_DMA_CH2_STATUS
115 #define DEBUG_READ R_SERIAL2_READ
116 #define DEBUG_WRITE R_SERIAL2_TR_DATA
117 #define DEBUG_TR_CTRL R_SERIAL2_TR_CTRL
118 #define DEBUG_REC_CTRL R_SERIAL2_REC_CTRL
119 #define DEBUG_IRQ IO_STATE(R_IRQ_MASK1_SET, ser2_data, set)
120 #define DEBUG_DMA_IRQ_CLR IO_STATE(R_IRQ_MASK2_CLR, dma2_descr, clr)
123 #ifdef CONFIG_ETRAX_DEBUG_PORT3
124 #define DEBUG_PORT_IDX 3
125 #define DEBUG_OCMD R_DMA_CH4_CMD
126 #define DEBUG_FIRST R_DMA_CH4_FIRST
127 #define DEBUG_OCLRINT R_DMA_CH4_CLR_INTR
128 #define DEBUG_STATUS R_DMA_CH4_STATUS
129 #define DEBUG_READ R_SERIAL3_READ
130 #define DEBUG_WRITE R_SERIAL3_TR_DATA
131 #define DEBUG_TR_CTRL R_SERIAL3_TR_CTRL
132 #define DEBUG_REC_CTRL R_SERIAL3_REC_CTRL
133 #define DEBUG_IRQ IO_STATE(R_IRQ_MASK1_SET, ser3_data, set)
134 #define DEBUG_DMA_IRQ_CLR IO_STATE(R_IRQ_MASK2_CLR, dma4_descr, clr)
137 #define MIN_SIZE 32 /* Size that triggers the FIFO to flush characters to interface */
139 static struct tty_driver *serial_driver;
141 typedef int (*debugport_write_function)(int i, const char *buf, unsigned int len);
143 debugport_write_function debug_write_function = NULL;
146 console_write_direct(struct console *co, const char *buf, unsigned int len)
150 for (i = 0; i < len; i++) {
151 /* Wait until transmitter is ready and send.*/
152 while(!(*DEBUG_READ & IO_MASK(R_SERIAL0_READ, tr_ready)));
153 *DEBUG_WRITE = buf[i];
158 console_write(struct console *co, const char *buf, unsigned int len)
161 #ifdef CONFIG_ETRAX_DEBUG_PORT_NULL
162 /* no debug printout at all */
166 #ifdef CONFIG_SVINTO_SIM
167 /* no use to simulate the serial debug output */
172 #ifdef CONFIG_ETRAX_KGDB
173 /* kgdb needs to output debug info using the gdb protocol */
174 putDebugString(buf, len);
178 local_irq_save(flags);
179 if (debug_write_function)
180 if (debug_write_function(co->index, buf, len))
182 console_write_direct(co, buf, len);
183 local_irq_restore(flags);
186 /* legacy function */
189 console_print_etrax(const char *buf)
191 console_write(NULL, buf, strlen(buf));
194 /* Use polling to get a single character FROM the debug port */
199 unsigned long readval;
202 readval = *DEBUG_READ;
203 } while(!(readval & IO_MASK(R_SERIAL0_READ, data_avail)));
205 return (readval & IO_MASK(R_SERIAL0_READ, data_in));
208 /* Use polling to put a single character to the debug port */
211 putDebugChar(int val)
213 while(!(*DEBUG_READ & IO_MASK(R_SERIAL0_READ, tr_ready))) ;
218 /* Enable irq for receiving chars on the debug port, used by kgdb */
223 *R_IRQ_MASK1_SET = DEBUG_IRQ;
224 /* use R_VECT_MASK directly, since we really bypass Linux normal
225 * IRQ handling in kgdb anyway, we don't need to use enable_irq
227 *R_VECT_MASK_SET = IO_STATE(R_VECT_MASK_SET, serial, set);
229 *DEBUG_REC_CTRL = IO_STATE(R_SERIAL0_REC_CTRL, rec_enable, enable);
232 static struct tty_driver*
233 console_device(struct console *c, int *index)
236 return serial_driver;
240 console_setup(struct console *co, char *options)
245 static struct console sercons = {
247 .write = console_write,
249 .device = console_device,
251 .setup = console_setup,
252 .flags = CON_PRINTBUFFER,
253 .index = DEBUG_PORT_IDX,
259 * Register console (for printk's etc)
263 init_etrax_debug(void)
265 #if CONFIG_ETRAX_DEBUG_PORT_NULL
269 #if DEBUG_PORT_IDX == 0
270 genconfig_shadow &= ~IO_MASK(R_GEN_CONFIG, dma6);
271 genconfig_shadow |= IO_STATE(R_GEN_CONFIG, dma6, unused);
272 #elif DEBUG_PORT_IDX == 1
273 genconfig_shadow &= ~IO_MASK(R_GEN_CONFIG, dma8);
274 genconfig_shadow |= IO_STATE(R_GEN_CONFIG, dma8, usb);
275 #elif DEBUG_PORT_IDX == 2
276 genconfig_shadow &= ~IO_MASK(R_GEN_CONFIG, dma2);
277 genconfig_shadow |= IO_STATE(R_GEN_CONFIG, dma2, par0);
278 #elif DEBUG_PORT_IDX == 3
279 genconfig_shadow &= ~IO_MASK(R_GEN_CONFIG, dma4);
280 genconfig_shadow |= IO_STATE(R_GEN_CONFIG, dma4, par1);
282 *R_GEN_CONFIG = genconfig_shadow;
284 register_console(&sercons);
290 serial_driver = alloc_tty_driver(1);