• Home
  • History
  • Annotate
  • Line#
  • Navigate
  • Raw
  • Download
  • only in /netgear-WNDR4500v2-V1.0.0.60_1.0.38/src/linux/linux-2.6/arch/mips/brcm-boards/generic/
1/*
2 * Copyright (C) 2010, Broadcom Corporation. All Rights Reserved.
3 *
4 * Permission to use, copy, modify, and/or distribute this software for any
5 * purpose with or without fee is hereby granted, provided that the above
6 * copyright notice and this permission notice appear in all copies.
7 *
8 * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
9 * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
10 * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY
11 * SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
12 * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION
13 * OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN
14 * CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
15 *
16 * Carsten Langgaard, carstenl@mips.com
17 * Copyright (C) 2000 MIPS Technologies, Inc.  All rights reserved.
18 *
19 * ########################################################################
20 *
21 *  This program is free software; you can distribute it and/or modify it
22 *  under the terms of the GNU General Public License (Version 2) as
23 *  published by the Free Software Foundation.
24 *
25 *  This program is distributed in the hope it will be useful, but WITHOUT
26 *  ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
27 *  FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
28 *  for more details.
29 *
30 *  You should have received a copy of the GNU General Public License along
31 *  with this program; if not, write to the Free Software Foundation, Inc.,
32 *  59 Temple Place - Suite 330, Boston MA 02111-1307, USA.
33 *
34 * ########################################################################
35 *
36 * This is the interface to the remote debugger stub.
37 *
38 */
39
40#include <linux/serial.h>
41#include <linux/serial_core.h>
42#include <linux/serialP.h>
43#include <linux/serial_reg.h>
44
45#include <asm/serial.h>
46#include <asm/io.h>
47
48static struct async_struct kdb_port_info = {0};
49
50static __inline__ unsigned int serial_in(struct async_struct *info, int offset)
51{
52	return readb(info->iomem_base + (offset<<info->iomem_reg_shift));
53}
54
55static __inline__ void serial_out(struct async_struct *info, int offset,
56				  int value)
57{
58	writeb(value, info->iomem_base + (offset<<info->iomem_reg_shift));
59}
60
61void rs_kgdb_hook(struct uart_port *ser) {
62	int t;
63
64	kdb_port_info.state = (struct serial_state *)ser;
65	kdb_port_info.magic = SERIAL_MAGIC;
66	kdb_port_info.port = ser->line;
67	kdb_port_info.flags = ser->flags;
68	kdb_port_info.iomem_base = ser->membase;
69	kdb_port_info.iomem_reg_shift = ser->regshift;
70	kdb_port_info.MCR = UART_MCR_DTR | UART_MCR_RTS;
71
72	/*
73	 * Clear all interrupts
74	 */
75	serial_in(&kdb_port_info, UART_LSR);
76	serial_in(&kdb_port_info, UART_RX);
77	serial_in(&kdb_port_info, UART_IIR);
78	serial_in(&kdb_port_info, UART_MSR);
79
80	/*
81	 * Now, initialize the UART
82	 */
83	serial_out(&kdb_port_info, UART_LCR, UART_LCR_WLEN8);	/* reset DLAB */
84	serial_out(&kdb_port_info, UART_MCR, kdb_port_info.MCR);
85
86	/*
87	 * and set the speed of the serial port
88	 * (currently hardwired to 115200 8N1
89	 */
90
91	/* baud rate is fixed to 115200 (is this sufficient?)*/
92	t = ser->uartclk / 115200;
93	/* set DLAB */
94	serial_out(&kdb_port_info, UART_LCR, UART_LCR_WLEN8 | UART_LCR_DLAB);
95	serial_out(&kdb_port_info, UART_DLL, t & 0xff);/* LS of divisor */
96	serial_out(&kdb_port_info, UART_DLM, t >> 8);  /* MS of divisor */
97	/* reset DLAB */
98	serial_out(&kdb_port_info, UART_LCR, UART_LCR_WLEN8);
99}
100
101int putDebugChar(char c)
102{
103
104	if (!kdb_port_info.state) { 	/* need to init device first */
105		return 0;
106	}
107
108	while ((serial_in(&kdb_port_info, UART_LSR) & UART_LSR_THRE) == 0)
109		;
110
111	serial_out(&kdb_port_info, UART_TX, c);
112
113	return 1;
114}
115
116char getDebugChar(void)
117{
118	if (!kdb_port_info.state) { 	/* need to init device first */
119		return 0;
120	}
121
122	while (!(serial_in(&kdb_port_info, UART_LSR) & 1))
123		;
124
125	return(serial_in(&kdb_port_info, UART_RX));
126}
127