Merge branch 'master' of git://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux-2.6
[pandora-kernel.git] / arch / mips / mips-boards / atlas / atlas_gdb.c
1 /*
2  * Carsten Langgaard, carstenl@mips.com
3  * Copyright (C) 2000 MIPS Technologies, Inc.  All rights reserved.
4  *
5  *  This program is free software; you can distribute it and/or modify it
6  *  under the terms of the GNU General Public License (Version 2) as
7  *  published by the Free Software Foundation.
8  *
9  *  This program is distributed in the hope it will be useful, but WITHOUT
10  *  ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
11  *  FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
12  *  for more details.
13  *
14  *  You should have received a copy of the GNU General Public License along
15  *  with this program; if not, write to the Free Software Foundation, Inc.,
16  *  59 Temple Place - Suite 330, Boston MA 02111-1307, USA.
17  *
18  * This is the interface to the remote debugger stub.
19  */
20 #include <asm/io.h>
21 #include <asm/mips-boards/atlas.h>
22 #include <asm/mips-boards/saa9730_uart.h>
23
24 #define INB(a)     inb((unsigned long)a)
25 #define OUTB(x, a)  outb(x, (unsigned long)a)
26
27 /*
28  * This is the interface to the remote debugger stub
29  * if the Philips part is used for the debug port,
30  * called from the platform setup code.
31  */
32 void *saa9730_base = (void *)ATLAS_SAA9730_REG;
33
34 static int saa9730_kgdb_active = 0;
35
36 #define SAA9730_BAUDCLOCK(baud) (((ATLAS_SAA9730_BAUDCLOCK/(baud))/16)-1)
37
38 int saa9730_kgdb_hook(int speed)
39 {
40         int baudclock;
41         t_uart_saa9730_regmap *kgdb_uart = (t_uart_saa9730_regmap *)(saa9730_base + SAA9730_UART_REGS_ADDR);
42
43         /*
44          * Clear all interrupts
45          */
46         (void) INB(&kgdb_uart->Lsr);
47         (void) INB(&kgdb_uart->Msr);
48         (void) INB(&kgdb_uart->Thr_Rbr);
49         (void) INB(&kgdb_uart->Iir_Fcr);
50
51         /*
52          * Now, initialize the UART
53          */
54         /* 8 data bits, one stop bit, no parity */
55         OUTB(SAA9730_LCR_DATA8, &kgdb_uart->Lcr);
56
57         baudclock = SAA9730_BAUDCLOCK(speed);
58
59         OUTB((baudclock >> 16) & 0xff, &kgdb_uart->BaudDivMsb);
60         OUTB( baudclock        & 0xff, &kgdb_uart->BaudDivLsb);
61
62         /* Set RTS/DTR active */
63         OUTB(SAA9730_MCR_DTR | SAA9730_MCR_RTS, &kgdb_uart->Mcr);
64         saa9730_kgdb_active = 1;
65
66         return speed;
67 }
68
69 int saa9730_putDebugChar(char c)
70 {
71         t_uart_saa9730_regmap *kgdb_uart = (t_uart_saa9730_regmap *)(saa9730_base + SAA9730_UART_REGS_ADDR);
72
73         if (!saa9730_kgdb_active) {     /* need to init device first */
74                 return 0;
75         }
76
77         while (!(INB(&kgdb_uart->Lsr) & SAA9730_LSR_THRE))
78                 ;
79         OUTB(c, &kgdb_uart->Thr_Rbr);
80
81         return 1;
82 }
83
84 char saa9730_getDebugChar(void)
85 {
86         t_uart_saa9730_regmap *kgdb_uart = (t_uart_saa9730_regmap *)(saa9730_base + SAA9730_UART_REGS_ADDR);
87         char c;
88
89         if (!saa9730_kgdb_active) {     /* need to init device first */
90                 return 0;
91         }
92         while (!(INB(&kgdb_uart->Lsr) & SAA9730_LSR_DR))
93                 ;
94
95         c = INB(&kgdb_uart->Thr_Rbr);
96         return(c);
97 }