Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1 | #include <linux/config.h> |
| 2 | #include <linux/types.h> |
| 3 | #include <asm/ibm4xx.h> |
| 4 | #include <linux/kernel.h> |
| 5 | |
| 6 | |
| 7 | |
| 8 | #define LSR_DR 0x01 /* Data ready */ |
| 9 | #define LSR_OE 0x02 /* Overrun */ |
| 10 | #define LSR_PE 0x04 /* Parity error */ |
| 11 | #define LSR_FE 0x08 /* Framing error */ |
| 12 | #define LSR_BI 0x10 /* Break */ |
| 13 | #define LSR_THRE 0x20 /* Xmit holding register empty */ |
| 14 | #define LSR_TEMT 0x40 /* Xmitter empty */ |
| 15 | #define LSR_ERR 0x80 /* Error */ |
| 16 | |
| 17 | #include <platforms/4xx/ibm_ocp.h> |
| 18 | |
| 19 | extern struct NS16550* COM_PORTS[]; |
| 20 | #ifndef NULL |
| 21 | #define NULL 0x00 |
| 22 | #endif |
| 23 | |
| 24 | static volatile struct NS16550 *kgdb_debugport = NULL; |
| 25 | |
| 26 | volatile struct NS16550 * |
| 27 | NS16550_init(int chan) |
| 28 | { |
| 29 | volatile struct NS16550 *com_port; |
| 30 | int quot; |
| 31 | #ifdef BASE_BAUD |
| 32 | quot = BASE_BAUD / 9600; |
| 33 | #else |
| 34 | quot = 0x000c; /* 0xc = 9600 baud (on a pc) */ |
| 35 | #endif |
| 36 | |
| 37 | com_port = (struct NS16550 *) COM_PORTS[chan]; |
| 38 | |
| 39 | com_port->lcr = 0x00; |
| 40 | com_port->ier = 0xFF; |
| 41 | com_port->ier = 0x00; |
| 42 | com_port->lcr = com_port->lcr | 0x80; /* Access baud rate */ |
| 43 | com_port->dll = ( quot & 0x00ff ); /* 0xc = 9600 baud */ |
| 44 | com_port->dlm = ( quot & 0xff00 ) >> 8; |
| 45 | com_port->lcr = 0x03; /* 8 data, 1 stop, no parity */ |
| 46 | com_port->mcr = 0x00; /* RTS/DTR */ |
| 47 | com_port->fcr = 0x07; /* Clear & enable FIFOs */ |
| 48 | |
| 49 | return( com_port ); |
| 50 | } |
| 51 | |
| 52 | |
| 53 | void |
| 54 | NS16550_putc(volatile struct NS16550 *com_port, unsigned char c) |
| 55 | { |
| 56 | while ((com_port->lsr & LSR_THRE) == 0) |
| 57 | ; |
| 58 | com_port->thr = c; |
| 59 | return; |
| 60 | } |
| 61 | |
| 62 | unsigned char |
| 63 | NS16550_getc(volatile struct NS16550 *com_port) |
| 64 | { |
| 65 | while ((com_port->lsr & LSR_DR) == 0) |
| 66 | ; |
| 67 | return (com_port->rbr); |
| 68 | } |
| 69 | |
| 70 | unsigned char |
| 71 | NS16550_tstc(volatile struct NS16550 *com_port) |
| 72 | { |
| 73 | return ((com_port->lsr & LSR_DR) != 0); |
| 74 | } |
| 75 | |
| 76 | |
| 77 | #if defined(CONFIG_KGDB_TTYS0) |
| 78 | #define KGDB_PORT 0 |
| 79 | #elif defined(CONFIG_KGDB_TTYS1) |
| 80 | #define KGDB_PORT 1 |
| 81 | #elif defined(CONFIG_KGDB_TTYS2) |
| 82 | #define KGDB_PORT 2 |
| 83 | #elif defined(CONFIG_KGDB_TTYS3) |
| 84 | #define KGDB_PORT 3 |
| 85 | #else |
| 86 | #error "invalid kgdb_tty port" |
| 87 | #endif |
| 88 | |
| 89 | void putDebugChar( unsigned char c ) |
| 90 | { |
| 91 | if ( kgdb_debugport == NULL ) |
| 92 | kgdb_debugport = NS16550_init(KGDB_PORT); |
| 93 | NS16550_putc( kgdb_debugport, c ); |
| 94 | } |
| 95 | |
| 96 | int getDebugChar( void ) |
| 97 | { |
| 98 | if (kgdb_debugport == NULL) |
| 99 | kgdb_debugport = NS16550_init(KGDB_PORT); |
| 100 | |
| 101 | return(NS16550_getc(kgdb_debugport)); |
| 102 | } |
| 103 | |
| 104 | void kgdb_interruptible(int enable) |
| 105 | { |
| 106 | return; |
| 107 | } |
| 108 | |
| 109 | void putDebugString(char* str) |
| 110 | { |
| 111 | while (*str != '\0') { |
| 112 | putDebugChar(*str); |
| 113 | str++; |
| 114 | } |
| 115 | putDebugChar('\r'); |
| 116 | return; |
| 117 | } |
| 118 | |
| 119 | void |
| 120 | kgdb_map_scc(void) |
| 121 | { |
| 122 | printk("kgdb init \n"); |
| 123 | kgdb_debugport = NS16550_init(KGDB_PORT); |
| 124 | } |