[d7a915da] | 1 | /* |
---|
| 2 | * Console driver for pxa255 full function port by Yang Xi <hiyangxi@gmail.com> |
---|
| 3 | * Copyright (c) 2004 by Jay Monkman <jtm@lopingdog.com> |
---|
| 4 | * |
---|
| 5 | * The license and distribution terms for this file may be |
---|
| 6 | * found in the file LICENSE in this distribution or at |
---|
| 7 | * http://www.rtems.com/license/LICENSE. |
---|
| 8 | * |
---|
| 9 | * $Id$ |
---|
| 10 | */ |
---|
| 11 | |
---|
| 12 | #include <bsp.h> |
---|
| 13 | #include <rtems/libio.h> |
---|
| 14 | #include <termios.h> |
---|
| 15 | |
---|
| 16 | #include <pxa255.h> |
---|
| 17 | #include <ffuart.h> |
---|
| 18 | #include <rtems/bspIo.h> |
---|
| 19 | #include <libchip/serial.h> |
---|
| 20 | #include <libchip/sersupp.h> |
---|
| 21 | |
---|
| 22 | volatile int dbg_dly; |
---|
| 23 | |
---|
| 24 | /* static function prototypes */ |
---|
| 25 | static int ffuart_first_open(int major, int minor, void *arg); |
---|
| 26 | static int ffuart_last_close(int major, int minor, void *arg); |
---|
| 27 | static int ffuart_read(int minor); |
---|
[ae3c037] | 28 | static ssize_t ffuart_write(int minor, const char *buf, size_t len); |
---|
[d7a915da] | 29 | static void ffuart_init(int minor); |
---|
| 30 | static void ffuart_write_polled(int minor, char c); |
---|
| 31 | static int ffuart_set_attributes(int minor, const struct termios *t); |
---|
| 32 | |
---|
| 33 | /* Pointers to functions for handling the UART. */ |
---|
[359e537] | 34 | console_fns ffuart_fns = |
---|
| 35 | { |
---|
[d7a915da] | 36 | libchip_serial_default_probe, |
---|
| 37 | ffuart_first_open, |
---|
| 38 | ffuart_last_close, |
---|
| 39 | ffuart_read, |
---|
| 40 | ffuart_write, |
---|
| 41 | ffuart_init, |
---|
| 42 | ffuart_write_polled, /* not used in this driver */ |
---|
| 43 | ffuart_set_attributes, |
---|
| 44 | FALSE /* TRUE if interrupt driven, FALSE if not. */ |
---|
| 45 | }; |
---|
| 46 | |
---|
| 47 | |
---|
[359e537] | 48 | /* |
---|
[d7a915da] | 49 | * This is called the first time each device is opened. Since |
---|
[359e537] | 50 | * the driver is polled, we don't have to do anything. If the driver |
---|
| 51 | * were interrupt driven, we'd enable interrupts here. |
---|
[d7a915da] | 52 | */ |
---|
[359e537] | 53 | static int ffuart_first_open(int major, int minor, void *arg) |
---|
[d7a915da] | 54 | { |
---|
| 55 | return 0; |
---|
| 56 | } |
---|
| 57 | |
---|
| 58 | |
---|
[359e537] | 59 | /* |
---|
[d7a915da] | 60 | * This is called the last time each device is closed. Since |
---|
[359e537] | 61 | * the driver is polled, we don't have to do anything. If the driver |
---|
| 62 | * were interrupt driven, we'd disable interrupts here. |
---|
[d7a915da] | 63 | */ |
---|
[359e537] | 64 | static int ffuart_last_close(int major, int minor, void *arg) |
---|
[d7a915da] | 65 | { |
---|
| 66 | return 0; |
---|
| 67 | } |
---|
| 68 | |
---|
| 69 | |
---|
| 70 | /* |
---|
| 71 | * Read one character from UART. |
---|
| 72 | * |
---|
| 73 | * return -1 if there's no data, otherwise return |
---|
| 74 | * the character in lowest 8 bits of returned int. |
---|
| 75 | */ |
---|
[359e537] | 76 | static int ffuart_read(int minor) |
---|
[d7a915da] | 77 | { |
---|
| 78 | char c; |
---|
| 79 | console_tbl *console_entry; |
---|
| 80 | ffuart_reg_t *ffuart; |
---|
| 81 | |
---|
| 82 | console_entry = BSP_get_uart_from_minor(minor); |
---|
| 83 | |
---|
| 84 | if (console_entry == NULL) { |
---|
| 85 | return -1; |
---|
| 86 | } |
---|
| 87 | |
---|
| 88 | ffuart = (ffuart_reg_t *)console_entry->ulCtrlPort1; |
---|
| 89 | |
---|
| 90 | if (!(ffuart->lsr & FULL_RECEIVE)) { |
---|
| 91 | return -1; |
---|
| 92 | } |
---|
[359e537] | 93 | |
---|
| 94 | c = ffuart->rbr & 0xff; |
---|
| 95 | |
---|
[d7a915da] | 96 | return c; |
---|
| 97 | } |
---|
| 98 | |
---|
| 99 | |
---|
[359e537] | 100 | /* |
---|
| 101 | * Write buffer to UART |
---|
[d7a915da] | 102 | * |
---|
| 103 | * return 1 on success, -1 on error |
---|
| 104 | */ |
---|
[ae3c037] | 105 | static ssize_t ffuart_write(int minor, const char *buf, size_t len) |
---|
[d7a915da] | 106 | { |
---|
[ae3c037] | 107 | size_t i, x; |
---|
[d7a915da] | 108 | char c; |
---|
| 109 | console_tbl *console_entry; |
---|
| 110 | ffuart_reg_t *ffuart; |
---|
| 111 | |
---|
| 112 | console_entry = BSP_get_uart_from_minor(minor); |
---|
| 113 | |
---|
| 114 | if (console_entry == NULL) { |
---|
| 115 | return -1; |
---|
| 116 | } |
---|
| 117 | |
---|
| 118 | ffuart = (ffuart_reg_t *)console_entry->ulCtrlPort1; |
---|
| 119 | |
---|
| 120 | for (i = 0; i < len; i++) { |
---|
| 121 | |
---|
| 122 | while(1) { |
---|
| 123 | if (ffuart->lsr & SEND_EMPTY) { |
---|
| 124 | break; |
---|
| 125 | } |
---|
| 126 | } |
---|
[359e537] | 127 | |
---|
[d7a915da] | 128 | c = (char) buf[i]; |
---|
[b4e5a619] | 129 | #if ON_SKYEYE != 1 |
---|
[d7a915da] | 130 | if(c=='\n'){ |
---|
| 131 | ffuart->rbr = '\r'; |
---|
| 132 | for (x = 0; x < 100; x++) { |
---|
| 133 | dbg_dly++; /* using a global so this doesn't get optimized out */ |
---|
| 134 | } |
---|
| 135 | while(1){ |
---|
| 136 | if(ffuart->lsr & SEND_EMPTY){ |
---|
| 137 | break; |
---|
| 138 | } |
---|
| 139 | } |
---|
| 140 | } |
---|
[b4e5a619] | 141 | #endif |
---|
[d7a915da] | 142 | ffuart->rbr = c; |
---|
[359e537] | 143 | |
---|
[d7a915da] | 144 | /* the TXRDY flag does not seem to update right away (is this true?) */ |
---|
| 145 | /* so we wait a bit before continuing */ |
---|
| 146 | for (x = 0; x < 100; x++) { |
---|
| 147 | dbg_dly++; /* using a global so this doesn't get optimized out */ |
---|
| 148 | } |
---|
| 149 | } |
---|
[359e537] | 150 | |
---|
[d7a915da] | 151 | return 1; |
---|
| 152 | } |
---|
| 153 | |
---|
| 154 | |
---|
| 155 | static void ffuart_init(int minor) |
---|
| 156 | { |
---|
| 157 | |
---|
[359e537] | 158 | |
---|
[d7a915da] | 159 | console_tbl *console_entry; |
---|
| 160 | ffuart_reg_t *ffuart; |
---|
| 161 | unsigned int divisor; |
---|
| 162 | |
---|
| 163 | console_entry = BSP_get_uart_from_minor(minor); |
---|
| 164 | |
---|
| 165 | |
---|
[359e537] | 166 | |
---|
[d7a915da] | 167 | if (console_entry == NULL) { |
---|
| 168 | return; |
---|
| 169 | } |
---|
[359e537] | 170 | |
---|
[d7a915da] | 171 | ffuart = (ffuart_reg_t *)console_entry->ulCtrlPort1; |
---|
| 172 | ffuart->lcr |= DLAB; |
---|
| 173 | /*Set the Bound*/ |
---|
| 174 | ffuart->lcr |= DLAB; |
---|
| 175 | divisor = FREQUENCY_UART / (115200*16); |
---|
| 176 | ffuart->rbr = divisor & 0xff; |
---|
| 177 | ffuart->ier = (divisor >> 8)&0xff; |
---|
| 178 | /*Disable FIFO*/ |
---|
| 179 | ffuart->iir = 0; |
---|
| 180 | ffuart->lcr &=~DLAB; |
---|
| 181 | /*Enable UART*/ |
---|
| 182 | ffuart->ier = 0x40; |
---|
| 183 | ffuart->lcr = EIGHT_BITS_NOPARITY_1STOPBIT; |
---|
| 184 | |
---|
| 185 | } |
---|
| 186 | |
---|
| 187 | /* I'm not sure this is needed for the shared console driver. */ |
---|
| 188 | static void ffuart_write_polled(int minor, char c) |
---|
| 189 | { |
---|
| 190 | ffuart_write(minor, &c, 1); |
---|
| 191 | } |
---|
| 192 | |
---|
| 193 | /* This is for setting baud rate, bits, etc. */ |
---|
[359e537] | 194 | static int ffuart_set_attributes(int minor, const struct termios *t) |
---|
[d7a915da] | 195 | { |
---|
| 196 | return 0; |
---|
| 197 | } |
---|
| 198 | |
---|
| 199 | /***********************************************************************/ |
---|
| 200 | /* |
---|
| 201 | * The following functions are not used by TERMIOS, but other RTEMS |
---|
| 202 | * functions use them instead. |
---|
| 203 | */ |
---|
| 204 | /***********************************************************************/ |
---|
[359e537] | 205 | /* |
---|
[d7a915da] | 206 | * Read from UART. This is used in the exit code, and can't |
---|
| 207 | * rely on interrupts. |
---|
| 208 | */ |
---|
| 209 | int ffuart_poll_read(int minor) |
---|
| 210 | { |
---|
| 211 | return ffuart_read(minor); |
---|
| 212 | } |
---|
| 213 | |
---|
| 214 | |
---|
| 215 | /* |
---|
[359e537] | 216 | * Write a character to the console. This is used by printk() and |
---|
[d7a915da] | 217 | * maybe other low level functions. It should not use interrupts or any |
---|
| 218 | * RTEMS system calls. It needs to be very simple |
---|
| 219 | */ |
---|
| 220 | static void _BSP_put_char( char c ) { |
---|
| 221 | ffuart_write_polled(0, c); |
---|
| 222 | } |
---|
| 223 | |
---|
[96d8af5b] | 224 | static int _BSP_poll_char(void) { |
---|
| 225 | return ffuart_poll_read(0); |
---|
| 226 | } |
---|
| 227 | |
---|
[010d830] | 228 | BSP_output_char_function_type BSP_output_char = _BSP_put_char; |
---|
[96d8af5b] | 229 | BSP_polling_getchar_function_type BSP_poll_char = _BSP_poll_char; |
---|