Loading...
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 | /* * (C) Copyright 2002 * Wolfgang Denk, DENX Software Engineering, <wd@denx.de> * * (C) Copyright 2002 * Sysgo Real-Time Solutions, GmbH <www.elinos.com> * Marius Groeger <mgroeger@sysgo.de> * * (C) Copyright 2002 * Sysgo Real-Time Solutions, GmbH <www.elinos.com> * Alex Zuepke <azu@sysgo.de> * * Copyright (C) 1999 2000 2001 Erik Mouw (J.A.K.Mouw@its.tudelft.nl) * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation; either version 2 of the License, or * (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with this program; if not, write to the Free Software * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA * */ #include <common.h> #include <watchdog.h> #include <serial.h> #include <asm/arch/pxa-regs.h> DECLARE_GLOBAL_DATA_PTR; #define FFUART_INDEX 0 #define BTUART_INDEX 1 #define STUART_INDEX 2 #ifndef CONFIG_SERIAL_MULTI #if defined (CONFIG_FFUART) #define UART_INDEX FFUART_INDEX #elif defined (CONFIG_BTUART) #define UART_INDEX BTUART_INDEX #elif defined (CONFIG_STUART) #define UART_INDEX STUART_INDEX #else #error "Bad: you didn't configure serial ..." #endif #endif void pxa_setbrg_dev (unsigned int uart_index) { unsigned int quot = 0; if (gd->baudrate == 1200) quot = 768; else if (gd->baudrate == 9600) quot = 96; else if (gd->baudrate == 19200) quot = 48; else if (gd->baudrate == 38400) quot = 24; else if (gd->baudrate == 57600) quot = 16; else if (gd->baudrate == 115200) quot = 8; else hang (); switch (uart_index) { case FFUART_INDEX: #ifdef CONFIG_CPU_MONAHANS CKENA |= CKENA_22_FFUART; #else CKEN |= CKEN6_FFUART; #endif /* CONFIG_CPU_MONAHANS */ FFIER = 0; /* Disable for now */ FFFCR = 0; /* No fifos enabled */ /* set baud rate */ FFLCR = LCR_WLS0 | LCR_WLS1 | LCR_DLAB; FFDLL = quot & 0xff; FFDLH = quot >> 8; FFLCR = LCR_WLS0 | LCR_WLS1; FFIER = IER_UUE; /* Enable FFUART */ break; case BTUART_INDEX: #ifdef CONFIG_CPU_MONAHANS CKENA |= CKENA_21_BTUART; #else CKEN |= CKEN7_BTUART; #endif /* CONFIG_CPU_MONAHANS */ BTIER = 0; BTFCR = 0; /* set baud rate */ BTLCR = LCR_DLAB; BTDLL = quot & 0xff; BTDLH = quot >> 8; BTLCR = LCR_WLS0 | LCR_WLS1; BTIER = IER_UUE; /* Enable BFUART */ break; case STUART_INDEX: #ifdef CONFIG_CPU_MONAHANS CKENA |= CKENA_23_STUART; #else CKEN |= CKEN5_STUART; #endif /* CONFIG_CPU_MONAHANS */ STIER = 0; STFCR = 0; /* set baud rate */ STLCR = LCR_DLAB; STDLL = quot & 0xff; STDLH = quot >> 8; STLCR = LCR_WLS0 | LCR_WLS1; STIER = IER_UUE; /* Enable STUART */ break; default: hang(); } } /* * Initialise the serial port with the given baudrate. The settings * are always 8 data bits, no parity, 1 stop bit, no start bits. * */ int pxa_init_dev (unsigned int uart_index) { pxa_setbrg_dev (uart_index); return (0); } /* * Output a single byte to the serial port. */ void pxa_putc_dev (unsigned int uart_index,const char c) { switch (uart_index) { case FFUART_INDEX: /* wait for room in the tx FIFO on FFUART */ while ((FFLSR & LSR_TEMT) == 0) WATCHDOG_RESET (); /* Reset HW Watchdog, if needed */ FFTHR = c; break; case BTUART_INDEX: while ((BTLSR & LSR_TEMT ) == 0 ) WATCHDOG_RESET (); /* Reset HW Watchdog, if needed */ BTTHR = c; break; case STUART_INDEX: while ((STLSR & LSR_TEMT ) == 0 ) WATCHDOG_RESET (); /* Reset HW Watchdog, if needed */ STTHR = c; break; } /* If \n, also do \r */ if (c == '\n') pxa_putc_dev (uart_index,'\r'); } /* * Read a single byte from the serial port. Returns 1 on success, 0 * otherwise. When the function is succesfull, the character read is * written into its argument c. */ int pxa_tstc_dev (unsigned int uart_index) { switch (uart_index) { case FFUART_INDEX: return FFLSR & LSR_DR; case BTUART_INDEX: return BTLSR & LSR_DR; case STUART_INDEX: return STLSR & LSR_DR; } return -1; } /* * Read a single byte from the serial port. Returns 1 on success, 0 * otherwise. When the function is succesfull, the character read is * written into its argument c. */ int pxa_getc_dev (unsigned int uart_index) { switch (uart_index) { case FFUART_INDEX: while (!(FFLSR & LSR_DR)) WATCHDOG_RESET (); /* Reset HW Watchdog, if needed */ return (char) FFRBR & 0xff; case BTUART_INDEX: while (!(BTLSR & LSR_DR)) WATCHDOG_RESET (); /* Reset HW Watchdog, if needed */ return (char) BTRBR & 0xff; case STUART_INDEX: while (!(STLSR & LSR_DR)) WATCHDOG_RESET (); /* Reset HW Watchdog, if needed */ return (char) STRBR & 0xff; } return -1; } void pxa_puts_dev (unsigned int uart_index,const char *s) { while (*s) { pxa_putc_dev (uart_index,*s++); } } #if defined (CONFIG_FFUART) static int ffuart_init(void) { return pxa_init_dev(FFUART_INDEX); } static void ffuart_setbrg(void) { return pxa_setbrg_dev(FFUART_INDEX); } static void ffuart_putc(const char c) { return pxa_putc_dev(FFUART_INDEX,c); } static void ffuart_puts(const char *s) { return pxa_puts_dev(FFUART_INDEX,s); } static int ffuart_getc(void) { return pxa_getc_dev(FFUART_INDEX); } static int ffuart_tstc(void) { return pxa_tstc_dev(FFUART_INDEX); } struct serial_device serial_ffuart_device = { "serial_ffuart", "PXA", ffuart_init, ffuart_setbrg, ffuart_getc, ffuart_tstc, ffuart_putc, ffuart_puts, }; #endif #if defined (CONFIG_BTUART) static int btuart_init(void) { return pxa_init_dev(BTUART_INDEX); } static void btuart_setbrg(void) { return pxa_setbrg_dev(BTUART_INDEX); } static void btuart_putc(const char c) { return pxa_putc_dev(BTUART_INDEX,c); } static void btuart_puts(const char *s) { return pxa_puts_dev(BTUART_INDEX,s); } static int btuart_getc(void) { return pxa_getc_dev(BTUART_INDEX); } static int btuart_tstc(void) { return pxa_tstc_dev(BTUART_INDEX); } struct serial_device serial_btuart_device = { "serial_btuart", "PXA", btuart_init, btuart_setbrg, btuart_getc, btuart_tstc, btuart_putc, btuart_puts, }; #endif #if defined (CONFIG_STUART) static int stuart_init(void) { return pxa_init_dev(STUART_INDEX); } static void stuart_setbrg(void) { return pxa_setbrg_dev(STUART_INDEX); } static void stuart_putc(const char c) { return pxa_putc_dev(STUART_INDEX,c); } static void stuart_puts(const char *s) { return pxa_puts_dev(STUART_INDEX,s); } static int stuart_getc(void) { return pxa_getc_dev(STUART_INDEX); } static int stuart_tstc(void) { return pxa_tstc_dev(STUART_INDEX); } struct serial_device serial_stuart_device = { "serial_stuart", "PXA", stuart_init, stuart_setbrg, stuart_getc, stuart_tstc, stuart_putc, stuart_puts, }; #endif #ifndef CONFIG_SERIAL_MULTI inline int serial_init(void) { return (pxa_init_dev(UART_INDEX)); } void serial_setbrg(void) { pxa_setbrg_dev(UART_INDEX); } int serial_getc(void) { return(pxa_getc_dev(UART_INDEX)); } int serial_tstc(void) { return(pxa_tstc_dev(UART_INDEX)); } void serial_putc(const char c) { pxa_putc_dev(UART_INDEX,c); } void serial_puts(const char *s) { pxa_puts_dev(UART_INDEX,s); } #endif /* CONFIG_SERIAL_MULTI */ |