wdenk | c609719 | 2002-11-03 00:24:07 +0000 | [diff] [blame^] | 1 | /* |
| 2 | * Simple serial driver for Cogent motherboard serial ports |
| 3 | * for use during boot |
| 4 | */ |
| 5 | |
| 6 | #include <common.h> |
| 7 | #include <board/cogent/serial.h> |
| 8 | |
| 9 | #if (CMA_MB_CAPS & CMA_MB_CAP_SERPAR) |
| 10 | |
| 11 | #if (defined(CONFIG_8xx) && defined(CONFIG_8xx_CONS_NONE)) || \ |
| 12 | (defined(CONFIG_8260) && defined(CONFIG_CONS_NONE)) |
| 13 | |
| 14 | #if CONFIG_CONS_INDEX == 1 |
| 15 | #define CMA_MB_SERIAL_BASE CMA_MB_SERIALA_BASE |
| 16 | #elif CONFIG_CONS_INDEX == 2 |
| 17 | #define CMA_MB_SERIAL_BASE CMA_MB_SERIALB_BASE |
| 18 | #elif CONFIG_CONS_INDEX == 3 && (CMA_MB_CAPS & CMA_MB_CAP_SER2) |
| 19 | #define CMA_MB_SERIAL_BASE CMA_MB_SER2A_BASE |
| 20 | #elif CONFIG_CONS_INDEX == 4 && (CMA_MB_CAPS & CMA_MB_CAP_SER2) |
| 21 | #define CMA_MB_SERIAL_BASE CMA_MB_SER2B_BASE |
| 22 | #else |
| 23 | #error CONFIG_CONS_INDEX must be configured for Cogent motherboard serial |
| 24 | #endif |
| 25 | |
| 26 | int serial_init (void) |
| 27 | { |
| 28 | /* DECLARE_GLOBAL_DATA_PTR; */ |
| 29 | |
| 30 | cma_mb_serial *mbsp = (cma_mb_serial *)CMA_MB_SERIAL_BASE; |
| 31 | |
| 32 | cma_mb_reg_write(&mbsp->ser_ier, 0x00); /* turn off interrupts */ |
| 33 | serial_setbrg (); |
| 34 | cma_mb_reg_write(&mbsp->ser_lcr, 0x03); /* 8 data, 1 stop, no parity */ |
| 35 | cma_mb_reg_write(&mbsp->ser_mcr, 0x03); /* RTS/DTR */ |
| 36 | cma_mb_reg_write(&mbsp->ser_fcr, 0x07); /* Clear & enable FIFOs */ |
| 37 | |
| 38 | return (0); |
| 39 | } |
| 40 | |
| 41 | void |
| 42 | serial_setbrg (void) |
| 43 | { |
| 44 | DECLARE_GLOBAL_DATA_PTR; |
| 45 | |
| 46 | cma_mb_serial *mbsp = (cma_mb_serial *)CMA_MB_SERIAL_BASE; |
| 47 | unsigned int divisor; |
| 48 | unsigned char lcr; |
| 49 | |
| 50 | if ((divisor = br_to_div(gd->baudrate)) == 0) |
| 51 | divisor = DEFDIV; |
| 52 | |
| 53 | lcr = cma_mb_reg_read(&mbsp->ser_lcr); |
| 54 | cma_mb_reg_write(&mbsp->ser_lcr, lcr|0x80);/* Access baud rate(set DLAB)*/ |
| 55 | cma_mb_reg_write(&mbsp->ser_brl, divisor & 0xff); |
| 56 | cma_mb_reg_write(&mbsp->ser_brh, (divisor >> 8) & 0xff); |
| 57 | cma_mb_reg_write(&mbsp->ser_lcr, lcr); /* unset DLAB */ |
| 58 | } |
| 59 | |
| 60 | void |
| 61 | serial_putc(const char c) |
| 62 | { |
| 63 | cma_mb_serial *mbsp = (cma_mb_serial *)CMA_MB_SERIAL_BASE; |
| 64 | |
| 65 | if (c == '\n') |
| 66 | serial_putc('\r'); |
| 67 | |
| 68 | while ((cma_mb_reg_read(&mbsp->ser_lsr) & LSR_THRE) == 0) |
| 69 | ; |
| 70 | |
| 71 | cma_mb_reg_write(&mbsp->ser_thr, c); |
| 72 | } |
| 73 | |
| 74 | void |
| 75 | serial_puts(const char *s) |
| 76 | { |
| 77 | while (*s != '\0') |
| 78 | serial_putc(*s++); |
| 79 | } |
| 80 | |
| 81 | int |
| 82 | serial_getc(void) |
| 83 | { |
| 84 | cma_mb_serial *mbsp = (cma_mb_serial *)CMA_MB_SERIAL_BASE; |
| 85 | |
| 86 | while ((cma_mb_reg_read(&mbsp->ser_lsr) & LSR_DR) == 0) |
| 87 | ; |
| 88 | |
| 89 | return ((int)cma_mb_reg_read(&mbsp->ser_rhr) & 0x7f); |
| 90 | } |
| 91 | |
| 92 | int |
| 93 | serial_tstc(void) |
| 94 | { |
| 95 | cma_mb_serial *mbsp = (cma_mb_serial *)CMA_MB_SERIAL_BASE; |
| 96 | |
| 97 | return ((cma_mb_reg_read(&mbsp->ser_lsr) & LSR_DR) != 0); |
| 98 | } |
| 99 | |
| 100 | #endif /* CONS_NONE */ |
| 101 | |
| 102 | #if (CONFIG_COMMANDS & CFG_CMD_KGDB) && \ |
| 103 | defined(CONFIG_KGDB_NONE) |
| 104 | |
| 105 | #if CONFIG_KGDB_INDEX == CONFIG_CONS_INDEX |
| 106 | #error Console and kgdb are on the same serial port - this is not supported |
| 107 | #endif |
| 108 | |
| 109 | #if CONFIG_KGDB_INDEX == 1 |
| 110 | #define CMA_MB_KGDB_SER_BASE CMA_MB_SERIALA_BASE |
| 111 | #elif CONFIG_KGDB_INDEX == 2 |
| 112 | #define CMA_MB_KGDB_SER_BASE CMA_MB_SERIALB_BASE |
| 113 | #elif CONFIG_KGDB_INDEX == 3 && (CMA_MB_CAPS & CMA_MB_CAP_SER2) |
| 114 | #define CMA_MB_KGDB_SER_BASE CMA_MB_SER2A_BASE |
| 115 | #elif CONFIG_KGDB_INDEX == 4 && (CMA_MB_CAPS & CMA_MB_CAP_SER2) |
| 116 | #define CMA_MB_KGDB_SER_BASE CMA_MB_SER2B_BASE |
| 117 | #else |
| 118 | #error CONFIG_KGDB_INDEX must be configured for Cogent motherboard serial |
| 119 | #endif |
| 120 | |
| 121 | void |
| 122 | kgdb_serial_init(void) |
| 123 | { |
| 124 | cma_mb_serial *mbsp = (cma_mb_serial *)CMA_MB_KGDB_SER_BASE; |
| 125 | unsigned int divisor; |
| 126 | |
| 127 | if ((divisor = br_to_div(CONFIG_KGDB_BAUDRATE)) == 0) |
| 128 | divisor = DEFDIV; |
| 129 | |
| 130 | cma_mb_reg_write(&mbsp->ser_ier, 0x00); /* turn off interrupts */ |
| 131 | cma_mb_reg_write(&mbsp->ser_lcr, 0x80); /* Access baud rate(set DLAB)*/ |
| 132 | cma_mb_reg_write(&mbsp->ser_brl, divisor & 0xff); |
| 133 | cma_mb_reg_write(&mbsp->ser_brh, (divisor >> 8) & 0xff); |
| 134 | cma_mb_reg_write(&mbsp->ser_lcr, 0x03); /* 8 data, 1 stop, no parity */ |
| 135 | cma_mb_reg_write(&mbsp->ser_mcr, 0x03); /* RTS/DTR */ |
| 136 | cma_mb_reg_write(&mbsp->ser_fcr, 0x07); /* Clear & enable FIFOs */ |
| 137 | |
| 138 | printf("[on cma10x serial port B] "); |
| 139 | } |
| 140 | |
| 141 | void |
| 142 | putDebugChar(int c) |
| 143 | { |
| 144 | cma_mb_serial *mbsp = (cma_mb_serial *)CMA_MB_KGDB_SER_BASE; |
| 145 | |
| 146 | while ((cma_mb_reg_read(&mbsp->ser_lsr) & LSR_THRE) == 0) |
| 147 | ; |
| 148 | |
| 149 | cma_mb_reg_write(&mbsp->ser_thr, c & 0xff); |
| 150 | } |
| 151 | |
| 152 | void |
| 153 | putDebugStr(const char *str) |
| 154 | { |
| 155 | while (*str != '\0') { |
| 156 | if (*str == '\n') |
| 157 | putDebugChar('\r'); |
| 158 | putDebugChar(*str++); |
| 159 | } |
| 160 | } |
| 161 | |
| 162 | int |
| 163 | getDebugChar(void) |
| 164 | { |
| 165 | cma_mb_serial *mbsp = (cma_mb_serial *)CMA_MB_KGDB_SER_BASE; |
| 166 | |
| 167 | while ((cma_mb_reg_read(&mbsp->ser_lsr) & LSR_DR) == 0) |
| 168 | ; |
| 169 | |
| 170 | return ((int)cma_mb_reg_read(&mbsp->ser_rhr) & 0x7f); |
| 171 | } |
| 172 | |
| 173 | void |
| 174 | kgdb_interruptible(int yes) |
| 175 | { |
| 176 | cma_mb_serial *mbsp = (cma_mb_serial *)CMA_MB_KGDB_SER_BASE; |
| 177 | |
| 178 | if (yes == 1) { |
| 179 | printf("kgdb: turning serial ints on\n"); |
| 180 | cma_mb_reg_write(&mbsp->ser_ier, 0xf); |
| 181 | } |
| 182 | else { |
| 183 | printf("kgdb: turning serial ints off\n"); |
| 184 | cma_mb_reg_write(&mbsp->ser_ier, 0x0); |
| 185 | } |
| 186 | } |
| 187 | |
| 188 | #endif /* KGDB && KGDB_NONE */ |
| 189 | |
| 190 | #endif /* CAPS & SERPAR */ |