2 * Copyright (C) 2003, Axis Communications AB.
5 #include <linux/console.h>
6 #include <linux/kernel.h>
7 #include <linux/init.h>
8 #include <linux/string.h>
9 #include <hwregs/reg_rdwr.h>
10 #include <hwregs/reg_map.h>
11 #include <hwregs/ser_defs.h>
12 #include <hwregs/dma_defs.h>
13 #include <mach/pinmux.h>
18 unsigned long instance;
20 unsigned long baudrate;
25 struct dbg_port ports[] =
59 #if CONFIG_ETRAX_SERIAL_PORTS == 5
71 static struct dbg_port *port =
72 #if defined(CONFIG_ETRAX_DEBUG_PORT0)
74 #elif defined(CONFIG_ETRAX_DEBUG_PORT1)
76 #elif defined(CONFIG_ETRAX_DEBUG_PORT2)
78 #elif defined(CONFIG_ETRAX_DEBUG_PORT3)
80 #elif defined(CONFIG_ETRAX_DEBUG_PORT4)
86 #ifdef CONFIG_ETRAX_KGDB
87 static struct dbg_port *kgdb_port =
88 #if defined(CONFIG_ETRAX_KGDB_PORT0)
90 #elif defined(CONFIG_ETRAX_KGDB_PORT1)
92 #elif defined(CONFIG_ETRAX_KGDB_PORT2)
94 #elif defined(CONFIG_ETRAX_KGDB_PORT3)
96 #elif defined(CONFIG_ETRAX_KGDB_PORT4)
103 static void start_port(struct dbg_port *p)
105 /* Set up serial port registers */
106 reg_ser_rw_tr_ctrl tr_ctrl = {0};
107 reg_ser_rw_tr_dma_en tr_dma_en = {0};
109 reg_ser_rw_rec_ctrl rec_ctrl = {0};
110 reg_ser_rw_tr_baud_div tr_baud_div = {0};
111 reg_ser_rw_rec_baud_div rec_baud_div = {0};
113 if (!p || p->started)
119 crisv32_pinmux_alloc_fixed(pinmux_ser1);
120 else if (p->nbr == 2)
121 crisv32_pinmux_alloc_fixed(pinmux_ser2);
122 else if (p->nbr == 3)
123 crisv32_pinmux_alloc_fixed(pinmux_ser3);
124 #if CONFIG_ETRAX_SERIAL_PORTS == 5
125 else if (p->nbr == 4)
126 crisv32_pinmux_alloc_fixed(pinmux_ser4);
129 tr_ctrl.base_freq = rec_ctrl.base_freq = regk_ser_f29_493;
130 tr_dma_en.en = rec_ctrl.dma_mode = regk_ser_no;
131 tr_baud_div.div = rec_baud_div.div = 29493000 / p->baudrate / 8;
132 tr_ctrl.en = rec_ctrl.en = 1;
134 if (p->parity == 'O') {
135 tr_ctrl.par_en = regk_ser_yes;
136 tr_ctrl.par = regk_ser_odd;
137 rec_ctrl.par_en = regk_ser_yes;
138 rec_ctrl.par = regk_ser_odd;
139 } else if (p->parity == 'E') {
140 tr_ctrl.par_en = regk_ser_yes;
141 tr_ctrl.par = regk_ser_even;
142 rec_ctrl.par_en = regk_ser_yes;
143 rec_ctrl.par = regk_ser_odd;
147 tr_ctrl.data_bits = regk_ser_bits7;
148 rec_ctrl.data_bits = regk_ser_bits7;
151 REG_WR (ser, p->instance, rw_tr_baud_div, tr_baud_div);
152 REG_WR (ser, p->instance, rw_rec_baud_div, rec_baud_div);
153 REG_WR (ser, p->instance, rw_tr_dma_en, tr_dma_en);
154 REG_WR (ser, p->instance, rw_tr_ctrl, tr_ctrl);
155 REG_WR (ser, p->instance, rw_rec_ctrl, rec_ctrl);
158 #ifdef CONFIG_ETRAX_KGDB
159 /* Use polling to get a single character from the kernel debug port */
160 int getDebugChar(void)
162 reg_ser_rs_stat_din stat;
163 reg_ser_rw_ack_intr ack_intr = { 0 };
166 stat = REG_RD(ser, kgdb_port->instance, rs_stat_din);
169 /* Ack the data_avail interrupt. */
171 REG_WR(ser, kgdb_port->instance, rw_ack_intr, ack_intr);
176 /* Use polling to put a single character to the kernel debug port */
177 void putDebugChar(int val)
179 reg_ser_r_stat_din stat;
181 stat = REG_RD(ser, kgdb_port->instance, r_stat_din);
182 } while (!stat.tr_rdy);
183 REG_WR_INT(ser, kgdb_port->instance, rw_dout, val);
185 #endif /* CONFIG_ETRAX_KGDB */
187 static void __init early_putch(int c)
189 reg_ser_r_stat_din stat;
190 /* Wait until transmitter is ready and send. */
192 stat = REG_RD(ser, port->instance, r_stat_din);
193 while (!stat.tr_rdy);
194 REG_WR_INT(ser, port->instance, rw_dout, c);
198 early_console_write(struct console *con, const char *s, unsigned n)
200 extern void reset_watchdog(void);
204 for (i = 0; i < n; i++) {
205 /* TODO: the '\n' -> '\n\r' translation should be done at the
206 receiver. Remove it when the serial driver removes it. */
214 static struct console early_console_dev __initdata = {
216 .write = early_console_write,
217 .flags = CON_PRINTBUFFER | CON_BOOT,
221 /* Register console for printk's, etc. */
222 int __init init_etrax_debug(void)
226 /* Register an early console if a debug port was chosen. */
227 register_console(&early_console_dev);
229 #ifdef CONFIG_ETRAX_KGDB
230 start_port(kgdb_port);
231 #endif /* CONFIG_ETRAX_KGDB */