wdenk | c609719 | 2002-11-03 00:24:07 +0000 | [diff] [blame] | 1 | /* |
| 2 | * (C) Copyright 2002 |
| 3 | * Wolfgang Denk, DENX Software Engineering, <wd@denx.de> |
| 4 | * |
| 5 | * (C) Copyright 2002 |
| 6 | * Sysgo Real-Time Solutions, GmbH <www.elinos.com> |
| 7 | * Marius Groeger <mgroeger@sysgo.de> |
| 8 | * |
| 9 | * (C) Copyright 2002 |
| 10 | * Sysgo Real-Time Solutions, GmbH <www.elinos.com> |
| 11 | * Alex Zuepke <azu@sysgo.de> |
| 12 | * |
| 13 | * Copyright (C) 1999 2000 2001 Erik Mouw (J.A.K.Mouw@its.tudelft.nl) |
| 14 | * |
| 15 | * This program is free software; you can redistribute it and/or modify |
| 16 | * it under the terms of the GNU General Public License as published by |
| 17 | * the Free Software Foundation; either version 2 of the License, or |
| 18 | * (at your option) any later version. |
| 19 | * |
| 20 | * This program is distributed in the hope that it will be useful, |
| 21 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 22 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 23 | * GNU General Public License for more details. |
| 24 | * |
| 25 | * You should have received a copy of the GNU General Public License |
| 26 | * along with this program; if not, write to the Free Software |
| 27 | * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA |
| 28 | * |
| 29 | */ |
| 30 | |
| 31 | #include <common.h> |
| 32 | #include <asm/arch/pxa-regs.h> |
| 33 | |
| 34 | void serial_setbrg (void) |
| 35 | { |
| 36 | DECLARE_GLOBAL_DATA_PTR; |
| 37 | |
| 38 | unsigned int quot = 0; |
| 39 | |
| 40 | if (gd->baudrate == 1200) |
| 41 | quot = 192; |
| 42 | else if (gd->baudrate == 9600) |
| 43 | quot = 96; |
| 44 | else if (gd->baudrate == 19200) |
| 45 | quot = 48; |
| 46 | else if (gd->baudrate == 38400) |
| 47 | quot = 24; |
| 48 | else if (gd->baudrate == 57600) |
| 49 | quot = 16; |
| 50 | else if (gd->baudrate == 115200) |
| 51 | quot = 8; |
| 52 | else |
| 53 | hang (); |
| 54 | |
| 55 | #ifdef CONFIG_FFUART |
| 56 | |
| 57 | CKEN |= CKEN6_FFUART; |
| 58 | |
| 59 | FFIER = 0; /* Disable for now */ |
| 60 | FFFCR = 0; /* No fifos enabled */ |
| 61 | |
| 62 | /* set baud rate */ |
| 63 | FFLCR = LCR_WLS0 | LCR_WLS1 | LCR_DLAB; |
| 64 | FFDLL = quot & 0xff; |
| 65 | FFDLH = quot >> 8; |
| 66 | FFLCR = LCR_WLS0 | LCR_WLS1; |
| 67 | |
| 68 | FFIER = IER_UUE; /* Enable FFUART */ |
| 69 | |
wdenk | b02744a | 2003-04-05 00:53:31 +0000 | [diff] [blame^] | 70 | #elif defined(CONFIG_BTUART) |
| 71 | CKEN |= CKEN7_BTUART; |
| 72 | |
| 73 | BTIER = 0; |
| 74 | BTFCR = 0; |
| 75 | |
| 76 | /* set baud rate */ |
| 77 | BTLCR = LCR_DLAB; |
| 78 | BTDLL = quot & 0xff; |
| 79 | BTDLH = quot >> 8; |
| 80 | BTLCR = LCR_WLS0 | LCR_WLS1; |
| 81 | |
| 82 | BTIER = IER_UUE; /* Enable BFUART */ |
| 83 | |
| 84 | #elif defined(CONFIG_STUART) |
wdenk | c609719 | 2002-11-03 00:24:07 +0000 | [diff] [blame] | 85 | #error "Bad: not implemented yet!" |
| 86 | #else |
| 87 | #error "Bad: you didn't configured serial ..." |
| 88 | #endif |
| 89 | } |
| 90 | |
| 91 | |
| 92 | /* |
| 93 | * Initialise the serial port with the given baudrate. The settings |
| 94 | * are always 8 data bits, no parity, 1 stop bit, no start bits. |
| 95 | * |
| 96 | */ |
| 97 | int serial_init (void) |
| 98 | { |
| 99 | serial_setbrg (); |
| 100 | |
| 101 | return (0); |
| 102 | } |
| 103 | |
| 104 | |
| 105 | /* |
| 106 | * Output a single byte to the serial port. |
| 107 | */ |
| 108 | void serial_putc (const char c) |
| 109 | { |
| 110 | #ifdef CONFIG_FFUART |
| 111 | /* wait for room in the tx FIFO on FFUART */ |
| 112 | while ((FFLSR & LSR_TEMT) == 0); |
| 113 | |
| 114 | FFTHR = c; |
wdenk | b02744a | 2003-04-05 00:53:31 +0000 | [diff] [blame^] | 115 | #elif defined(CONFIG_BTUART) |
| 116 | while ((BTLSR & LSR_TEMT ) == 0 ); |
| 117 | BTTHR = c; |
| 118 | #elif defined(CONFIG_STUART) |
wdenk | c609719 | 2002-11-03 00:24:07 +0000 | [diff] [blame] | 119 | #endif |
| 120 | |
| 121 | /* If \n, also do \r */ |
| 122 | if (c == '\n') |
| 123 | serial_putc ('\r'); |
| 124 | } |
| 125 | |
| 126 | /* |
| 127 | * Read a single byte from the serial port. Returns 1 on success, 0 |
| 128 | * otherwise. When the function is succesfull, the character read is |
| 129 | * written into its argument c. |
| 130 | */ |
| 131 | int serial_tstc (void) |
| 132 | { |
| 133 | #ifdef CONFIG_FFUART |
| 134 | return FFLSR & LSR_DR; |
wdenk | b02744a | 2003-04-05 00:53:31 +0000 | [diff] [blame^] | 135 | #elif defined(CONFIG_BTUART) |
| 136 | return BTLSR & LSR_DR; |
| 137 | #elif defined(CONFIG_STUART) |
wdenk | c609719 | 2002-11-03 00:24:07 +0000 | [diff] [blame] | 138 | #endif |
| 139 | } |
| 140 | |
| 141 | /* |
| 142 | * Read a single byte from the serial port. Returns 1 on success, 0 |
| 143 | * otherwise. When the function is succesfull, the character read is |
| 144 | * written into its argument c. |
| 145 | */ |
| 146 | int serial_getc (void) |
| 147 | { |
| 148 | #ifdef CONFIG_FFUART |
| 149 | while (!(FFLSR & LSR_DR)); |
| 150 | |
| 151 | return (char) FFRBR & 0xff; |
wdenk | b02744a | 2003-04-05 00:53:31 +0000 | [diff] [blame^] | 152 | #elif defined(CONFIG_BTUART) |
| 153 | while (!(BTLSR & LSR_DR)); |
| 154 | |
| 155 | return (char) BTRBR & 0xff; |
| 156 | #elif defined(CONFIG_STUART) |
wdenk | c609719 | 2002-11-03 00:24:07 +0000 | [diff] [blame] | 157 | #endif |
| 158 | } |
| 159 | |
| 160 | void |
| 161 | serial_puts (const char *s) |
| 162 | { |
| 163 | while (*s) { |
| 164 | serial_putc (*s++); |
| 165 | } |
| 166 | } |