2 * Copyright 2004, Broadcom Corporation
5 * THIS SOFTWARE IS OFFERED "AS IS", AND BROADCOM GRANTS NO WARRANTIES OF ANY
6 * KIND, EXPRESS OR IMPLIED, BY STATUTE, COMMUNICATION OR OTHERWISE. BROADCOM
7 * SPECIFICALLY DISCLAIMS ANY IMPLIED WARRANTIES OF MERCHANTABILITY, FITNESS
8 * FOR A SPECIFIC PURPOSE OR NONINFRINGEMENT CONCERNING THIS SOFTWARE.
10 * Carsten Langgaard, carstenl@mips.com
11 * Copyright (C) 2000 MIPS Technologies, Inc. All rights reserved.
13 * ########################################################################
15 * This program is free software; you can distribute it and/or modify it
16 * under the terms of the GNU General Public License (Version 2) as
17 * published by the Free Software Foundation.
19 * This program is distributed in the hope it will be useful, but WITHOUT
20 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
21 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
24 * You should have received a copy of the GNU General Public License along
25 * with this program; if not, write to the Free Software Foundation, Inc.,
26 * 59 Temple Place - Suite 330, Boston MA 02111-1307, USA.
28 * ########################################################################
30 * This is the interface to the remote debugger stub.
34 #include <linux/serialP.h>
35 #include <linux/serial_reg.h>
37 #include <asm/serial.h>
40 static struct async_struct kdb_port_info
= {0};
42 static __inline__
unsigned int serial_in(struct async_struct
*info
, int offset
)
44 return readb((unsigned long) info
->iomem_base
+
45 (offset
<<info
->iomem_reg_shift
));
48 static __inline__
void serial_out(struct async_struct
*info
, int offset
,
51 writeb(value
, (unsigned long) info
->iomem_base
+
52 (offset
<<info
->iomem_reg_shift
));
55 void rs_kgdb_hook(struct serial_state
*ser
) {
58 kdb_port_info
.state
= ser
;
59 kdb_port_info
.magic
= SERIAL_MAGIC
;
60 kdb_port_info
.port
= ser
->port
;
61 kdb_port_info
.flags
= ser
->flags
;
62 kdb_port_info
.iomem_base
= ser
->iomem_base
;
63 kdb_port_info
.iomem_reg_shift
= ser
->iomem_reg_shift
;
64 kdb_port_info
.MCR
= UART_MCR_DTR
| UART_MCR_RTS
;
67 * Clear all interrupts
69 serial_in(&kdb_port_info
, UART_LSR
);
70 serial_in(&kdb_port_info
, UART_RX
);
71 serial_in(&kdb_port_info
, UART_IIR
);
72 serial_in(&kdb_port_info
, UART_MSR
);
75 * Now, initialize the UART
77 serial_out(&kdb_port_info
, UART_LCR
, UART_LCR_WLEN8
); /* reset DLAB */
78 serial_out(&kdb_port_info
, UART_MCR
, kdb_port_info
.MCR
);
81 * and set the speed of the serial port
82 * (currently hardwired to 115200 8N1
85 /* baud rate is fixed to 115200 (is this sufficient?)*/
86 t
= kdb_port_info
.state
->baud_base
/ 115200;
88 serial_out(&kdb_port_info
, UART_LCR
, UART_LCR_WLEN8
| UART_LCR_DLAB
);
89 serial_out(&kdb_port_info
, UART_DLL
, t
& 0xff);/* LS of divisor */
90 serial_out(&kdb_port_info
, UART_DLM
, t
>> 8); /* MS of divisor */
92 serial_out(&kdb_port_info
, UART_LCR
, UART_LCR_WLEN8
);
95 int putDebugChar(char c
)
98 if (!kdb_port_info
.state
) { /* need to init device first */
102 while ((serial_in(&kdb_port_info
, UART_LSR
) & UART_LSR_THRE
) == 0)
105 serial_out(&kdb_port_info
, UART_TX
, c
);
110 char getDebugChar(void)
112 if (!kdb_port_info
.state
) { /* need to init device first */
116 while (!(serial_in(&kdb_port_info
, UART_LSR
) & 1))
119 return(serial_in(&kdb_port_info
, UART_RX
));