Blame view

arch/cris/arch-v32/kernel/debugport.c 4.74 KB
51533b615   Mikael Starvik   [PATCH] CRIS upda...
1
2
3
  /*
   * Copyright (C) 2003, Axis Communications AB.
   */
51533b615   Mikael Starvik   [PATCH] CRIS upda...
4
  #include <linux/console.h>
4729d7733   Jesper Nilsson   CRISv32: Implemen...
5
  #include <linux/kernel.h>
51533b615   Mikael Starvik   [PATCH] CRIS upda...
6
  #include <linux/init.h>
4729d7733   Jesper Nilsson   CRISv32: Implemen...
7
  #include <linux/string.h>
822641026   Jesper Nilsson   CRIS v32: Update ...
8
9
10
11
  #include <hwregs/reg_rdwr.h>
  #include <hwregs/reg_map.h>
  #include <hwregs/ser_defs.h>
  #include <hwregs/dma_defs.h>
556dcee7b   Jesper Nilsson   [CRIS] Move heade...
12
  #include <mach/pinmux.h>
51533b615   Mikael Starvik   [PATCH] CRIS upda...
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
  
  struct dbg_port
  {
  	unsigned char nbr;
  	unsigned long instance;
  	unsigned int started;
  	unsigned long baudrate;
  	unsigned char parity;
  	unsigned int bits;
  };
  
  struct dbg_port ports[] =
  {
    {
      0,
      regi_ser0,
      0,
      115200,
      'N',
      8
    },
    {
      1,
      regi_ser1,
      0,
      115200,
      'N',
      8
    },
    {
      2,
      regi_ser2,
      0,
      115200,
      'N',
      8
    },
    {
      3,
      regi_ser3,
      0,
      115200,
      'N',
      8
822641026   Jesper Nilsson   CRIS v32: Update ...
57
58
59
60
61
62
63
64
65
66
67
    },
  #if CONFIG_ETRAX_SERIAL_PORTS == 5
    {
      4,
      regi_ser4,
      0,
      115200,
      'N',
      8
    },
  #endif
51533b615   Mikael Starvik   [PATCH] CRIS upda...
68
  };
4729d7733   Jesper Nilsson   CRISv32: Implemen...
69

51533b615   Mikael Starvik   [PATCH] CRIS upda...
70
71
  static struct dbg_port *port =
  #if defined(CONFIG_ETRAX_DEBUG_PORT0)
822641026   Jesper Nilsson   CRIS v32: Update ...
72
  	&ports[0];
51533b615   Mikael Starvik   [PATCH] CRIS upda...
73
  #elif defined(CONFIG_ETRAX_DEBUG_PORT1)
822641026   Jesper Nilsson   CRIS v32: Update ...
74
  	&ports[1];
51533b615   Mikael Starvik   [PATCH] CRIS upda...
75
  #elif defined(CONFIG_ETRAX_DEBUG_PORT2)
822641026   Jesper Nilsson   CRIS v32: Update ...
76
  	&ports[2];
51533b615   Mikael Starvik   [PATCH] CRIS upda...
77
  #elif defined(CONFIG_ETRAX_DEBUG_PORT3)
822641026   Jesper Nilsson   CRIS v32: Update ...
78
79
80
  	&ports[3];
  #elif defined(CONFIG_ETRAX_DEBUG_PORT4)
  	&ports[4];
51533b615   Mikael Starvik   [PATCH] CRIS upda...
81
  #else
822641026   Jesper Nilsson   CRIS v32: Update ...
82
  	NULL;
51533b615   Mikael Starvik   [PATCH] CRIS upda...
83
84
85
86
87
  #endif
  
  #ifdef CONFIG_ETRAX_KGDB
  static struct dbg_port *kgdb_port =
  #if defined(CONFIG_ETRAX_KGDB_PORT0)
822641026   Jesper Nilsson   CRIS v32: Update ...
88
  	&ports[0];
51533b615   Mikael Starvik   [PATCH] CRIS upda...
89
  #elif defined(CONFIG_ETRAX_KGDB_PORT1)
822641026   Jesper Nilsson   CRIS v32: Update ...
90
  	&ports[1];
51533b615   Mikael Starvik   [PATCH] CRIS upda...
91
  #elif defined(CONFIG_ETRAX_KGDB_PORT2)
822641026   Jesper Nilsson   CRIS v32: Update ...
92
  	&ports[2];
51533b615   Mikael Starvik   [PATCH] CRIS upda...
93
  #elif defined(CONFIG_ETRAX_KGDB_PORT3)
822641026   Jesper Nilsson   CRIS v32: Update ...
94
95
96
  	&ports[3];
  #elif defined(CONFIG_ETRAX_KGDB_PORT4)
  	&ports[4];
51533b615   Mikael Starvik   [PATCH] CRIS upda...
97
  #else
822641026   Jesper Nilsson   CRIS v32: Update ...
98
  	NULL;
51533b615   Mikael Starvik   [PATCH] CRIS upda...
99
100
  #endif
  #endif
4729d7733   Jesper Nilsson   CRISv32: Implemen...
101
  static void start_port(struct dbg_port *p)
51533b615   Mikael Starvik   [PATCH] CRIS upda...
102
  {
4729d7733   Jesper Nilsson   CRISv32: Implemen...
103
104
105
  	/* Set up serial port registers */
  	reg_ser_rw_tr_ctrl tr_ctrl = {0};
  	reg_ser_rw_tr_dma_en tr_dma_en = {0};
51533b615   Mikael Starvik   [PATCH] CRIS upda...
106

4729d7733   Jesper Nilsson   CRISv32: Implemen...
107
108
109
110
111
  	reg_ser_rw_rec_ctrl rec_ctrl = {0};
  	reg_ser_rw_tr_baud_div tr_baud_div = {0};
  	reg_ser_rw_rec_baud_div rec_baud_div = {0};
  
  	if (!p || p->started)
51533b615   Mikael Starvik   [PATCH] CRIS upda...
112
  		return;
4729d7733   Jesper Nilsson   CRISv32: Implemen...
113

51533b615   Mikael Starvik   [PATCH] CRIS upda...
114
115
116
117
118
119
120
121
  	p->started = 1;
  
  	if (p->nbr == 1)
  		crisv32_pinmux_alloc_fixed(pinmux_ser1);
  	else if (p->nbr == 2)
  		crisv32_pinmux_alloc_fixed(pinmux_ser2);
  	else if (p->nbr == 3)
  		crisv32_pinmux_alloc_fixed(pinmux_ser3);
822641026   Jesper Nilsson   CRIS v32: Update ...
122
123
124
125
  #if CONFIG_ETRAX_SERIAL_PORTS == 5
  	else if (p->nbr == 4)
  		crisv32_pinmux_alloc_fixed(pinmux_ser4);
  #endif
51533b615   Mikael Starvik   [PATCH] CRIS upda...
126

51533b615   Mikael Starvik   [PATCH] CRIS upda...
127
128
129
130
  	tr_ctrl.base_freq = rec_ctrl.base_freq = regk_ser_f29_493;
  	tr_dma_en.en = rec_ctrl.dma_mode = regk_ser_no;
  	tr_baud_div.div = rec_baud_div.div = 29493000 / p->baudrate / 8;
  	tr_ctrl.en = rec_ctrl.en = 1;
4729d7733   Jesper Nilsson   CRISv32: Implemen...
131
  	if (p->parity == 'O') {
51533b615   Mikael Starvik   [PATCH] CRIS upda...
132
133
134
135
  		tr_ctrl.par_en = regk_ser_yes;
  		tr_ctrl.par = regk_ser_odd;
  		rec_ctrl.par_en = regk_ser_yes;
  		rec_ctrl.par = regk_ser_odd;
4729d7733   Jesper Nilsson   CRISv32: Implemen...
136
  	} else if (p->parity == 'E') {
51533b615   Mikael Starvik   [PATCH] CRIS upda...
137
138
139
140
141
  		tr_ctrl.par_en = regk_ser_yes;
  		tr_ctrl.par = regk_ser_even;
  		rec_ctrl.par_en = regk_ser_yes;
  		rec_ctrl.par = regk_ser_odd;
  	}
4729d7733   Jesper Nilsson   CRISv32: Implemen...
142
  	if (p->bits == 7) {
51533b615   Mikael Starvik   [PATCH] CRIS upda...
143
144
145
146
147
148
149
150
151
152
  		tr_ctrl.data_bits = regk_ser_bits7;
  		rec_ctrl.data_bits = regk_ser_bits7;
  	}
  
  	REG_WR (ser, p->instance, rw_tr_baud_div, tr_baud_div);
  	REG_WR (ser, p->instance, rw_rec_baud_div, rec_baud_div);
  	REG_WR (ser, p->instance, rw_tr_dma_en, tr_dma_en);
  	REG_WR (ser, p->instance, rw_tr_ctrl, tr_ctrl);
  	REG_WR (ser, p->instance, rw_rec_ctrl, rec_ctrl);
  }
51533b615   Mikael Starvik   [PATCH] CRIS upda...
153
154
  #ifdef CONFIG_ETRAX_KGDB
  /* Use polling to get a single character from the kernel debug port */
4729d7733   Jesper Nilsson   CRISv32: Implemen...
155
  int getDebugChar(void)
51533b615   Mikael Starvik   [PATCH] CRIS upda...
156
  {
822641026   Jesper Nilsson   CRIS v32: Update ...
157
  	reg_ser_rs_stat_din stat;
51533b615   Mikael Starvik   [PATCH] CRIS upda...
158
159
160
  	reg_ser_rw_ack_intr ack_intr = { 0 };
  
  	do {
822641026   Jesper Nilsson   CRIS v32: Update ...
161
162
  		stat = REG_RD(ser, kgdb_port->instance, rs_stat_din);
  	} while (!stat.dav);
51533b615   Mikael Starvik   [PATCH] CRIS upda...
163
164
  
  	/* Ack the data_avail interrupt. */
822641026   Jesper Nilsson   CRIS v32: Update ...
165
166
  	ack_intr.dav = 1;
  	REG_WR(ser, kgdb_port->instance, rw_ack_intr, ack_intr);
51533b615   Mikael Starvik   [PATCH] CRIS upda...
167
168
169
170
171
  
  	return stat.data;
  }
  
  /* Use polling to put a single character to the kernel debug port */
4729d7733   Jesper Nilsson   CRISv32: Implemen...
172
  void putDebugChar(int val)
51533b615   Mikael Starvik   [PATCH] CRIS upda...
173
  {
822641026   Jesper Nilsson   CRIS v32: Update ...
174
  	reg_ser_r_stat_din stat;
51533b615   Mikael Starvik   [PATCH] CRIS upda...
175
  	do {
822641026   Jesper Nilsson   CRIS v32: Update ...
176
177
178
  		stat = REG_RD(ser, kgdb_port->instance, r_stat_din);
  	} while (!stat.tr_rdy);
  	REG_WR_INT(ser, kgdb_port->instance, rw_dout, val);
51533b615   Mikael Starvik   [PATCH] CRIS upda...
179
180
  }
  #endif /* CONFIG_ETRAX_KGDB */
4729d7733   Jesper Nilsson   CRISv32: Implemen...
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
  static void __init early_putch(int c)
  {
  	reg_ser_r_stat_din stat;
  	/* Wait until transmitter is ready and send. */
  	do
  		stat = REG_RD(ser, port->instance, r_stat_din);
  	while (!stat.tr_rdy);
  	REG_WR_INT(ser, port->instance, rw_dout, c);
  }
  
  static void __init
  early_console_write(struct console *con, const char *s, unsigned n)
  {
  	extern void reset_watchdog(void);
  	int i;
  
  	/* Send data. */
  	for (i = 0; i < n; i++) {
  		/* TODO: the '
  ' -> '
  \r' translation should be done at the
  		   receiver. Remove it when the serial driver removes it.   */
  		if (s[i] == '
  ')
  			early_putch('\r');
  		early_putch(s[i]);
  		reset_watchdog();
  	}
  }
  
  static struct console early_console_dev __initdata = {
  	.name   = "early",
  	.write  = early_console_write,
  	.flags  = CON_PRINTBUFFER | CON_BOOT,
  	.index  = -1
  };
51533b615   Mikael Starvik   [PATCH] CRIS upda...
217
  /* Register console for printk's, etc. */
4729d7733   Jesper Nilsson   CRISv32: Implemen...
218
  int __init init_etrax_debug(void)
51533b615   Mikael Starvik   [PATCH] CRIS upda...
219
  {
51533b615   Mikael Starvik   [PATCH] CRIS upda...
220
          start_port(port);
4729d7733   Jesper Nilsson   CRISv32: Implemen...
221
222
  	/* Register an early console if a debug port was chosen.  */
  	register_console(&early_console_dev);
51533b615   Mikael Starvik   [PATCH] CRIS upda...
223
224
225
226
227
  #ifdef CONFIG_ETRAX_KGDB
  	start_port(kgdb_port);
  #endif /* CONFIG_ETRAX_KGDB */
  	return 0;
  }