Rafal Jaworowski | d3a02c3 | 2007-07-27 14:43:59 +0200 | [diff] [blame] | 1 | /* |
Detlev Zundel | 00c2716 | 2010-01-21 17:55:58 +0100 | [diff] [blame] | 2 | * (C) Copyright 2000 - 2010 |
Rafal Jaworowski | d3a02c3 | 2007-07-27 14:43:59 +0200 | [diff] [blame] | 3 | * Wolfgang Denk, DENX Software Engineering, wd@denx.de. |
| 4 | * |
| 5 | * See file CREDITS for list of people who contributed to this |
| 6 | * project. |
| 7 | * |
| 8 | * This program is free software; you can redistribute it and/or |
| 9 | * modify it under the terms of the GNU General Public License as |
| 10 | * published by the Free Software Foundation; either version 2 of |
| 11 | * the License, or (at your option) any later version. |
| 12 | * |
| 13 | * This program is distributed in the hope that it will be useful, |
| 14 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 15 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 16 | * GNU General Public License for more details. |
| 17 | * |
| 18 | * You should have received a copy of the GNU General Public License |
| 19 | * along with this program; if not, write to the Free Software |
| 20 | * Foundation, Inc., 59 Temple Place, Suite 330, Boston, |
| 21 | * MA 02111-1307 USA |
| 22 | * |
| 23 | * Based ont the MPC5200 PSC driver. |
| 24 | * Adapted for MPC512x by Jan Wrobel <wrr@semihalf.com> |
| 25 | */ |
| 26 | |
| 27 | /* |
| 28 | * Minimal serial functions needed to use one of the PSC ports |
| 29 | * as serial console interface. |
| 30 | */ |
| 31 | |
| 32 | #include <common.h> |
Wolfgang Denk | b853995 | 2009-05-16 10:47:43 +0200 | [diff] [blame] | 33 | #include <asm/io.h> |
| 34 | #include <asm/processor.h> |
Anatolij Gustschin | ee4aac8 | 2010-04-24 19:27:05 +0200 | [diff] [blame^] | 35 | #include <serial.h> |
Rafal Jaworowski | d3a02c3 | 2007-07-27 14:43:59 +0200 | [diff] [blame] | 36 | |
| 37 | DECLARE_GLOBAL_DATA_PTR; |
| 38 | |
Anatolij Gustschin | ee4aac8 | 2010-04-24 19:27:05 +0200 | [diff] [blame^] | 39 | #if defined(CONFIG_PSC_CONSOLE) || defined(CONFIG_SERIAL_MULTI) |
Rafal Jaworowski | d3a02c3 | 2007-07-27 14:43:59 +0200 | [diff] [blame] | 40 | |
| 41 | static void fifo_init (volatile psc512x_t *psc) |
| 42 | { |
Jean-Christophe PLAGNIOL-VILLARD | 0383694 | 2008-10-16 15:01:15 +0200 | [diff] [blame] | 43 | volatile immap_t *im = (immap_t *) CONFIG_SYS_IMMR; |
Anatolij Gustschin | ee4aac8 | 2010-04-24 19:27:05 +0200 | [diff] [blame^] | 44 | u32 tfsize, rfsize; |
Rafal Jaworowski | d3a02c3 | 2007-07-27 14:43:59 +0200 | [diff] [blame] | 45 | |
| 46 | /* reset Rx & Tx fifo slice */ |
Wolfgang Denk | b853995 | 2009-05-16 10:47:43 +0200 | [diff] [blame] | 47 | out_be32(&psc->rfcmd, PSC_FIFO_RESET_SLICE); |
| 48 | out_be32(&psc->tfcmd, PSC_FIFO_RESET_SLICE); |
Rafal Jaworowski | d3a02c3 | 2007-07-27 14:43:59 +0200 | [diff] [blame] | 49 | |
| 50 | /* disable Tx & Rx FIFO interrupts */ |
Wolfgang Denk | b853995 | 2009-05-16 10:47:43 +0200 | [diff] [blame] | 51 | out_be32(&psc->rfintmask, 0); |
| 52 | out_be32(&psc->tfintmask, 0); |
Rafal Jaworowski | d3a02c3 | 2007-07-27 14:43:59 +0200 | [diff] [blame] | 53 | |
Anatolij Gustschin | ee4aac8 | 2010-04-24 19:27:05 +0200 | [diff] [blame^] | 54 | #if defined(CONFIG_SERIAL_MULTI) |
| 55 | switch (((u32)psc & 0xf00) >> 8) { |
| 56 | case 0: |
| 57 | tfsize = FIFOC_PSC0_TX_SIZE | (FIFOC_PSC0_TX_ADDR << 16); |
| 58 | rfsize = FIFOC_PSC0_RX_SIZE | (FIFOC_PSC0_RX_ADDR << 16); |
| 59 | break; |
| 60 | case 1: |
| 61 | tfsize = FIFOC_PSC1_TX_SIZE | (FIFOC_PSC1_TX_ADDR << 16); |
| 62 | rfsize = FIFOC_PSC1_RX_SIZE | (FIFOC_PSC1_RX_ADDR << 16); |
| 63 | break; |
| 64 | case 2: |
| 65 | tfsize = FIFOC_PSC2_TX_SIZE | (FIFOC_PSC2_TX_ADDR << 16); |
| 66 | rfsize = FIFOC_PSC2_RX_SIZE | (FIFOC_PSC2_RX_ADDR << 16); |
| 67 | break; |
| 68 | case 3: |
| 69 | tfsize = FIFOC_PSC3_TX_SIZE | (FIFOC_PSC3_TX_ADDR << 16); |
| 70 | rfsize = FIFOC_PSC3_RX_SIZE | (FIFOC_PSC3_RX_ADDR << 16); |
| 71 | break; |
| 72 | case 4: |
| 73 | tfsize = FIFOC_PSC4_TX_SIZE | (FIFOC_PSC4_TX_ADDR << 16); |
| 74 | rfsize = FIFOC_PSC4_RX_SIZE | (FIFOC_PSC4_RX_ADDR << 16); |
| 75 | break; |
| 76 | case 5: |
| 77 | tfsize = FIFOC_PSC5_TX_SIZE | (FIFOC_PSC5_TX_ADDR << 16); |
| 78 | rfsize = FIFOC_PSC5_RX_SIZE | (FIFOC_PSC5_RX_ADDR << 16); |
| 79 | break; |
| 80 | case 6: |
| 81 | tfsize = FIFOC_PSC6_TX_SIZE | (FIFOC_PSC6_TX_ADDR << 16); |
| 82 | rfsize = FIFOC_PSC6_RX_SIZE | (FIFOC_PSC6_RX_ADDR << 16); |
| 83 | break; |
| 84 | case 7: |
| 85 | tfsize = FIFOC_PSC7_TX_SIZE | (FIFOC_PSC7_TX_ADDR << 16); |
| 86 | rfsize = FIFOC_PSC7_RX_SIZE | (FIFOC_PSC7_RX_ADDR << 16); |
| 87 | break; |
| 88 | case 8: |
| 89 | tfsize = FIFOC_PSC8_TX_SIZE | (FIFOC_PSC8_TX_ADDR << 16); |
| 90 | rfsize = FIFOC_PSC8_RX_SIZE | (FIFOC_PSC8_RX_ADDR << 16); |
| 91 | break; |
| 92 | case 9: |
| 93 | tfsize = FIFOC_PSC9_TX_SIZE | (FIFOC_PSC9_TX_ADDR << 16); |
| 94 | rfsize = FIFOC_PSC9_RX_SIZE | (FIFOC_PSC9_RX_ADDR << 16); |
| 95 | break; |
| 96 | case 10: |
| 97 | tfsize = FIFOC_PSC10_TX_SIZE | (FIFOC_PSC10_TX_ADDR << 16); |
| 98 | rfsize = FIFOC_PSC10_RX_SIZE | (FIFOC_PSC10_RX_ADDR << 16); |
| 99 | break; |
| 100 | case 11: |
| 101 | tfsize = FIFOC_PSC11_TX_SIZE | (FIFOC_PSC11_TX_ADDR << 16); |
| 102 | rfsize = FIFOC_PSC11_RX_SIZE | (FIFOC_PSC11_RX_ADDR << 16); |
| 103 | break; |
| 104 | default: |
| 105 | return; |
| 106 | } |
| 107 | #else |
| 108 | tfsize = CONSOLE_FIFO_TX_SIZE | (CONSOLE_FIFO_TX_ADDR << 16); |
| 109 | rfsize = CONSOLE_FIFO_RX_SIZE | (CONSOLE_FIFO_RX_ADDR << 16); |
| 110 | #endif |
| 111 | out_be32(&psc->tfsize, tfsize); |
| 112 | out_be32(&psc->rfsize, rfsize); |
Rafal Jaworowski | d3a02c3 | 2007-07-27 14:43:59 +0200 | [diff] [blame] | 113 | |
| 114 | /* enable Tx & Rx FIFO slice */ |
Wolfgang Denk | b853995 | 2009-05-16 10:47:43 +0200 | [diff] [blame] | 115 | out_be32(&psc->rfcmd, PSC_FIFO_ENABLE_SLICE); |
| 116 | out_be32(&psc->tfcmd, PSC_FIFO_ENABLE_SLICE); |
Rafal Jaworowski | d3a02c3 | 2007-07-27 14:43:59 +0200 | [diff] [blame] | 117 | |
Wolfgang Denk | b853995 | 2009-05-16 10:47:43 +0200 | [diff] [blame] | 118 | out_be32(&im->fifoc.fifoc_cmd, FIFOC_DISABLE_CLOCK_GATE); |
Rafal Jaworowski | d3a02c3 | 2007-07-27 14:43:59 +0200 | [diff] [blame] | 119 | __asm__ volatile ("sync"); |
| 120 | } |
| 121 | |
Anatolij Gustschin | ee4aac8 | 2010-04-24 19:27:05 +0200 | [diff] [blame^] | 122 | void serial_setbrg_dev(unsigned int idx) |
Stefan Roese | 6650529 | 2009-06-02 16:53:16 +0200 | [diff] [blame] | 123 | { |
| 124 | volatile immap_t *im = (immap_t *) CONFIG_SYS_IMMR; |
Anatolij Gustschin | ee4aac8 | 2010-04-24 19:27:05 +0200 | [diff] [blame^] | 125 | volatile psc512x_t *psc = (psc512x_t *) &im->psc[idx]; |
Stefan Roese | 6650529 | 2009-06-02 16:53:16 +0200 | [diff] [blame] | 126 | unsigned long baseclk, div; |
Anatolij Gustschin | ee4aac8 | 2010-04-24 19:27:05 +0200 | [diff] [blame^] | 127 | unsigned long baudrate; |
| 128 | char buf[16]; |
| 129 | char *br_env; |
| 130 | |
| 131 | baudrate = gd->baudrate; |
| 132 | if (idx != CONFIG_PSC_CONSOLE) { |
| 133 | /* Allows setting baudrate for other serial devices |
| 134 | * on PSCx using environment. If not specified, use |
| 135 | * the same baudrate as for console. |
| 136 | */ |
| 137 | sprintf(buf, "psc%d_baudrate", idx); |
| 138 | br_env = getenv(buf); |
| 139 | if (br_env) |
| 140 | baudrate = simple_strtoul(br_env, NULL, 10); |
| 141 | |
| 142 | debug("%s: idx %d, baudrate %d\n", __func__, idx, baudrate); |
| 143 | } |
Stefan Roese | 6650529 | 2009-06-02 16:53:16 +0200 | [diff] [blame] | 144 | |
Anatolij Gustschin | ee4aac8 | 2010-04-24 19:27:05 +0200 | [diff] [blame^] | 145 | /* calculate divisor for setting PSC CTUR and CTLR registers */ |
Stefan Roese | 6650529 | 2009-06-02 16:53:16 +0200 | [diff] [blame] | 146 | baseclk = (gd->ips_clk + 8) / 16; |
Anatolij Gustschin | ee4aac8 | 2010-04-24 19:27:05 +0200 | [diff] [blame^] | 147 | div = (baseclk + (baudrate / 2)) / baudrate; |
Stefan Roese | 6650529 | 2009-06-02 16:53:16 +0200 | [diff] [blame] | 148 | |
| 149 | out_8(&psc->ctur, (div >> 8) & 0xff); |
| 150 | out_8(&psc->ctlr, div & 0xff); /* set baudrate */ |
| 151 | } |
| 152 | |
Anatolij Gustschin | ee4aac8 | 2010-04-24 19:27:05 +0200 | [diff] [blame^] | 153 | int serial_init_dev(unsigned int idx) |
Rafal Jaworowski | d3a02c3 | 2007-07-27 14:43:59 +0200 | [diff] [blame] | 154 | { |
Jean-Christophe PLAGNIOL-VILLARD | 0383694 | 2008-10-16 15:01:15 +0200 | [diff] [blame] | 155 | volatile immap_t *im = (immap_t *) CONFIG_SYS_IMMR; |
Anatolij Gustschin | ee4aac8 | 2010-04-24 19:27:05 +0200 | [diff] [blame^] | 156 | volatile psc512x_t *psc = (psc512x_t *) &im->psc[idx]; |
| 157 | #if defined(CONFIG_SERIAL_MULTI) |
| 158 | u32 reg; |
| 159 | |
| 160 | reg = in_be32(&im->clk.sccr[0]); |
| 161 | out_be32(&im->clk.sccr[0], reg | CLOCK_SCCR1_PSC_EN(idx)); |
| 162 | #endif |
Rafal Jaworowski | d3a02c3 | 2007-07-27 14:43:59 +0200 | [diff] [blame] | 163 | |
| 164 | fifo_init (psc); |
| 165 | |
| 166 | /* set MR register to point to MR1 */ |
Wolfgang Denk | b853995 | 2009-05-16 10:47:43 +0200 | [diff] [blame] | 167 | out_8(&psc->command, PSC_SEL_MODE_REG_1); |
Rafal Jaworowski | d3a02c3 | 2007-07-27 14:43:59 +0200 | [diff] [blame] | 168 | |
| 169 | /* disable Tx/Rx */ |
Wolfgang Denk | b853995 | 2009-05-16 10:47:43 +0200 | [diff] [blame] | 170 | out_8(&psc->command, PSC_TX_DISABLE | PSC_RX_DISABLE); |
Rafal Jaworowski | d3a02c3 | 2007-07-27 14:43:59 +0200 | [diff] [blame] | 171 | |
| 172 | /* choose the prescaler by 16 for the Tx/Rx clock generation */ |
Wolfgang Denk | b853995 | 2009-05-16 10:47:43 +0200 | [diff] [blame] | 173 | out_be16(&psc->psc_clock_select, 0xdd00); |
Rafal Jaworowski | d3a02c3 | 2007-07-27 14:43:59 +0200 | [diff] [blame] | 174 | |
| 175 | /* switch to UART mode */ |
Wolfgang Denk | b853995 | 2009-05-16 10:47:43 +0200 | [diff] [blame] | 176 | out_be32(&psc->sicr, 0); |
Rafal Jaworowski | d3a02c3 | 2007-07-27 14:43:59 +0200 | [diff] [blame] | 177 | |
| 178 | /* mode register points to mr1 */ |
| 179 | /* configure parity, bit length and so on in mode register 1*/ |
Wolfgang Denk | b853995 | 2009-05-16 10:47:43 +0200 | [diff] [blame] | 180 | out_8(&psc->mode, PSC_MODE_8_BITS | PSC_MODE_PARNONE); |
Rafal Jaworowski | d3a02c3 | 2007-07-27 14:43:59 +0200 | [diff] [blame] | 181 | /* now, mode register points to mr2 */ |
Wolfgang Denk | b853995 | 2009-05-16 10:47:43 +0200 | [diff] [blame] | 182 | out_8(&psc->mode, PSC_MODE_1_STOPBIT); |
Rafal Jaworowski | d3a02c3 | 2007-07-27 14:43:59 +0200 | [diff] [blame] | 183 | |
Rafal Jaworowski | d3a02c3 | 2007-07-27 14:43:59 +0200 | [diff] [blame] | 184 | /* set baudrate */ |
Anatolij Gustschin | ee4aac8 | 2010-04-24 19:27:05 +0200 | [diff] [blame^] | 185 | serial_setbrg_dev(idx); |
Rafal Jaworowski | d3a02c3 | 2007-07-27 14:43:59 +0200 | [diff] [blame] | 186 | |
| 187 | /* disable all interrupts */ |
Wolfgang Denk | b853995 | 2009-05-16 10:47:43 +0200 | [diff] [blame] | 188 | out_be16(&psc->psc_imr, 0); |
Rafal Jaworowski | d3a02c3 | 2007-07-27 14:43:59 +0200 | [diff] [blame] | 189 | |
| 190 | /* reset and enable Rx/Tx */ |
Wolfgang Denk | b853995 | 2009-05-16 10:47:43 +0200 | [diff] [blame] | 191 | out_8(&psc->command, PSC_RST_RX); |
| 192 | out_8(&psc->command, PSC_RST_TX); |
| 193 | out_8(&psc->command, PSC_RX_ENABLE | PSC_TX_ENABLE); |
Rafal Jaworowski | d3a02c3 | 2007-07-27 14:43:59 +0200 | [diff] [blame] | 194 | |
| 195 | return 0; |
| 196 | } |
| 197 | |
Anatolij Gustschin | ee4aac8 | 2010-04-24 19:27:05 +0200 | [diff] [blame^] | 198 | int serial_uninit_dev(unsigned int idx) |
| 199 | { |
| 200 | volatile immap_t *im = (immap_t *) CONFIG_SYS_IMMR; |
| 201 | volatile psc512x_t *psc = (psc512x_t *) &im->psc[idx]; |
| 202 | u32 reg; |
| 203 | |
| 204 | out_8(&psc->command, PSC_RX_DISABLE | PSC_TX_DISABLE); |
| 205 | reg = in_be32(&im->clk.sccr[0]); |
| 206 | reg &= ~CLOCK_SCCR1_PSC_EN(idx); |
| 207 | out_be32(&im->clk.sccr[0], reg); |
| 208 | |
| 209 | return 0; |
| 210 | } |
| 211 | |
| 212 | void serial_putc_dev(unsigned int idx, const char c) |
Rafal Jaworowski | d3a02c3 | 2007-07-27 14:43:59 +0200 | [diff] [blame] | 213 | { |
Jean-Christophe PLAGNIOL-VILLARD | 0383694 | 2008-10-16 15:01:15 +0200 | [diff] [blame] | 214 | volatile immap_t *im = (immap_t *)CONFIG_SYS_IMMR; |
Anatolij Gustschin | ee4aac8 | 2010-04-24 19:27:05 +0200 | [diff] [blame^] | 215 | volatile psc512x_t *psc = (psc512x_t *) &im->psc[idx]; |
Rafal Jaworowski | d3a02c3 | 2007-07-27 14:43:59 +0200 | [diff] [blame] | 216 | |
| 217 | if (c == '\n') |
Anatolij Gustschin | ee4aac8 | 2010-04-24 19:27:05 +0200 | [diff] [blame^] | 218 | serial_putc_dev(idx, '\r'); |
Rafal Jaworowski | d3a02c3 | 2007-07-27 14:43:59 +0200 | [diff] [blame] | 219 | |
| 220 | /* Wait for last character to go. */ |
Wolfgang Denk | b853995 | 2009-05-16 10:47:43 +0200 | [diff] [blame] | 221 | while (!(in_be16(&psc->psc_status) & PSC_SR_TXEMP)) |
Rafal Jaworowski | d3a02c3 | 2007-07-27 14:43:59 +0200 | [diff] [blame] | 222 | ; |
| 223 | |
Detlev Zundel | 00c2716 | 2010-01-21 17:55:58 +0100 | [diff] [blame] | 224 | out_8(&psc->tfdata_8, c); |
Rafal Jaworowski | d3a02c3 | 2007-07-27 14:43:59 +0200 | [diff] [blame] | 225 | } |
| 226 | |
Anatolij Gustschin | ee4aac8 | 2010-04-24 19:27:05 +0200 | [diff] [blame^] | 227 | void serial_putc_raw_dev(unsigned int idx, const char c) |
Rafal Jaworowski | d3a02c3 | 2007-07-27 14:43:59 +0200 | [diff] [blame] | 228 | { |
Jean-Christophe PLAGNIOL-VILLARD | 0383694 | 2008-10-16 15:01:15 +0200 | [diff] [blame] | 229 | volatile immap_t *im = (immap_t *) CONFIG_SYS_IMMR; |
Anatolij Gustschin | ee4aac8 | 2010-04-24 19:27:05 +0200 | [diff] [blame^] | 230 | volatile psc512x_t *psc = (psc512x_t *) &im->psc[idx]; |
Rafal Jaworowski | d3a02c3 | 2007-07-27 14:43:59 +0200 | [diff] [blame] | 231 | |
| 232 | /* Wait for last character to go. */ |
Wolfgang Denk | b853995 | 2009-05-16 10:47:43 +0200 | [diff] [blame] | 233 | while (!(in_be16(&psc->psc_status) & PSC_SR_TXEMP)) |
Rafal Jaworowski | d3a02c3 | 2007-07-27 14:43:59 +0200 | [diff] [blame] | 234 | ; |
| 235 | |
Detlev Zundel | 00c2716 | 2010-01-21 17:55:58 +0100 | [diff] [blame] | 236 | out_8(&psc->tfdata_8, c); |
Rafal Jaworowski | d3a02c3 | 2007-07-27 14:43:59 +0200 | [diff] [blame] | 237 | } |
| 238 | |
Anatolij Gustschin | ee4aac8 | 2010-04-24 19:27:05 +0200 | [diff] [blame^] | 239 | void serial_puts_dev(unsigned int idx, const char *s) |
Rafal Jaworowski | d3a02c3 | 2007-07-27 14:43:59 +0200 | [diff] [blame] | 240 | { |
Anatolij Gustschin | ee4aac8 | 2010-04-24 19:27:05 +0200 | [diff] [blame^] | 241 | while (*s) |
| 242 | serial_putc_dev(idx, *s++); |
Rafal Jaworowski | d3a02c3 | 2007-07-27 14:43:59 +0200 | [diff] [blame] | 243 | } |
| 244 | |
Anatolij Gustschin | ee4aac8 | 2010-04-24 19:27:05 +0200 | [diff] [blame^] | 245 | int serial_getc_dev(unsigned int idx) |
Rafal Jaworowski | d3a02c3 | 2007-07-27 14:43:59 +0200 | [diff] [blame] | 246 | { |
Jean-Christophe PLAGNIOL-VILLARD | 0383694 | 2008-10-16 15:01:15 +0200 | [diff] [blame] | 247 | volatile immap_t *im = (immap_t *) CONFIG_SYS_IMMR; |
Anatolij Gustschin | ee4aac8 | 2010-04-24 19:27:05 +0200 | [diff] [blame^] | 248 | volatile psc512x_t *psc = (psc512x_t *) &im->psc[idx]; |
Rafal Jaworowski | d3a02c3 | 2007-07-27 14:43:59 +0200 | [diff] [blame] | 249 | |
| 250 | /* Wait for a character to arrive. */ |
Wolfgang Denk | b853995 | 2009-05-16 10:47:43 +0200 | [diff] [blame] | 251 | while (in_be32(&psc->rfstat) & PSC_FIFO_EMPTY) |
Rafal Jaworowski | d3a02c3 | 2007-07-27 14:43:59 +0200 | [diff] [blame] | 252 | ; |
| 253 | |
Detlev Zundel | 00c2716 | 2010-01-21 17:55:58 +0100 | [diff] [blame] | 254 | return in_8(&psc->rfdata_8); |
Rafal Jaworowski | d3a02c3 | 2007-07-27 14:43:59 +0200 | [diff] [blame] | 255 | } |
| 256 | |
Anatolij Gustschin | ee4aac8 | 2010-04-24 19:27:05 +0200 | [diff] [blame^] | 257 | int serial_tstc_dev(unsigned int idx) |
Rafal Jaworowski | d3a02c3 | 2007-07-27 14:43:59 +0200 | [diff] [blame] | 258 | { |
Jean-Christophe PLAGNIOL-VILLARD | 0383694 | 2008-10-16 15:01:15 +0200 | [diff] [blame] | 259 | volatile immap_t *im = (immap_t *) CONFIG_SYS_IMMR; |
Anatolij Gustschin | ee4aac8 | 2010-04-24 19:27:05 +0200 | [diff] [blame^] | 260 | volatile psc512x_t *psc = (psc512x_t *) &im->psc[idx]; |
Rafal Jaworowski | d3a02c3 | 2007-07-27 14:43:59 +0200 | [diff] [blame] | 261 | |
Wolfgang Denk | b853995 | 2009-05-16 10:47:43 +0200 | [diff] [blame] | 262 | return !(in_be32(&psc->rfstat) & PSC_FIFO_EMPTY); |
Rafal Jaworowski | d3a02c3 | 2007-07-27 14:43:59 +0200 | [diff] [blame] | 263 | } |
| 264 | |
Anatolij Gustschin | ee4aac8 | 2010-04-24 19:27:05 +0200 | [diff] [blame^] | 265 | void serial_setrts_dev(unsigned int idx, int s) |
Rafal Jaworowski | d3a02c3 | 2007-07-27 14:43:59 +0200 | [diff] [blame] | 266 | { |
Jean-Christophe PLAGNIOL-VILLARD | 0383694 | 2008-10-16 15:01:15 +0200 | [diff] [blame] | 267 | volatile immap_t *im = (immap_t *) CONFIG_SYS_IMMR; |
Anatolij Gustschin | ee4aac8 | 2010-04-24 19:27:05 +0200 | [diff] [blame^] | 268 | volatile psc512x_t *psc = (psc512x_t *) &im->psc[idx]; |
Rafal Jaworowski | d3a02c3 | 2007-07-27 14:43:59 +0200 | [diff] [blame] | 269 | |
| 270 | if (s) { |
| 271 | /* Assert RTS (become LOW) */ |
Wolfgang Denk | b853995 | 2009-05-16 10:47:43 +0200 | [diff] [blame] | 272 | out_8(&psc->op1, 0x1); |
Rafal Jaworowski | d3a02c3 | 2007-07-27 14:43:59 +0200 | [diff] [blame] | 273 | } |
| 274 | else { |
| 275 | /* Negate RTS (become HIGH) */ |
Wolfgang Denk | b853995 | 2009-05-16 10:47:43 +0200 | [diff] [blame] | 276 | out_8(&psc->op0, 0x1); |
Rafal Jaworowski | d3a02c3 | 2007-07-27 14:43:59 +0200 | [diff] [blame] | 277 | } |
| 278 | } |
| 279 | |
Anatolij Gustschin | ee4aac8 | 2010-04-24 19:27:05 +0200 | [diff] [blame^] | 280 | int serial_getcts_dev(unsigned int idx) |
Rafal Jaworowski | d3a02c3 | 2007-07-27 14:43:59 +0200 | [diff] [blame] | 281 | { |
Jean-Christophe PLAGNIOL-VILLARD | 0383694 | 2008-10-16 15:01:15 +0200 | [diff] [blame] | 282 | volatile immap_t *im = (immap_t *) CONFIG_SYS_IMMR; |
Anatolij Gustschin | ee4aac8 | 2010-04-24 19:27:05 +0200 | [diff] [blame^] | 283 | volatile psc512x_t *psc = (psc512x_t *) &im->psc[idx]; |
Rafal Jaworowski | d3a02c3 | 2007-07-27 14:43:59 +0200 | [diff] [blame] | 284 | |
Wolfgang Denk | b853995 | 2009-05-16 10:47:43 +0200 | [diff] [blame] | 285 | return (in_8(&psc->ip) & 0x1) ? 0 : 1; |
Rafal Jaworowski | d3a02c3 | 2007-07-27 14:43:59 +0200 | [diff] [blame] | 286 | } |
Anatolij Gustschin | ee4aac8 | 2010-04-24 19:27:05 +0200 | [diff] [blame^] | 287 | #endif /* CONFIG_PSC_CONSOLE || CONFIG_SERIAL_MULTI */ |
| 288 | |
| 289 | #if defined(CONFIG_SERIAL_MULTI) |
| 290 | |
| 291 | #define DECLARE_PSC_SERIAL_FUNCTIONS(port) \ |
| 292 | int serial##port##_init(void) \ |
| 293 | { \ |
| 294 | return serial_init_dev(port); \ |
| 295 | } \ |
| 296 | int serial##port##_uninit(void) \ |
| 297 | { \ |
| 298 | return serial_uninit_dev(port); \ |
| 299 | } \ |
| 300 | void serial##port##_setbrg(void) \ |
| 301 | { \ |
| 302 | serial_setbrg_dev(port); \ |
| 303 | } \ |
| 304 | int serial##port##_getc(void) \ |
| 305 | { \ |
| 306 | return serial_getc_dev(port); \ |
| 307 | } \ |
| 308 | int serial##port##_tstc(void) \ |
| 309 | { \ |
| 310 | return serial_tstc_dev(port); \ |
| 311 | } \ |
| 312 | void serial##port##_putc(const char c) \ |
| 313 | { \ |
| 314 | serial_putc_dev(port, c); \ |
| 315 | } \ |
| 316 | void serial##port##_puts(const char *s) \ |
| 317 | { \ |
| 318 | serial_puts_dev(port, s); \ |
| 319 | } |
| 320 | |
| 321 | #define INIT_PSC_SERIAL_STRUCTURE(port, name, bus) { \ |
| 322 | name, \ |
| 323 | bus, \ |
| 324 | serial##port##_init, \ |
| 325 | serial##port##_uninit, \ |
| 326 | serial##port##_setbrg, \ |
| 327 | serial##port##_getc, \ |
| 328 | serial##port##_tstc, \ |
| 329 | serial##port##_putc, \ |
| 330 | serial##port##_puts, \ |
| 331 | } |
| 332 | |
| 333 | #if defined(CONFIG_SYS_PSC1) |
| 334 | DECLARE_PSC_SERIAL_FUNCTIONS(1); |
| 335 | struct serial_device serial1_device = |
| 336 | INIT_PSC_SERIAL_STRUCTURE(1, "psc1", "UART1"); |
| 337 | #endif |
| 338 | |
| 339 | #if defined(CONFIG_SYS_PSC3) |
| 340 | DECLARE_PSC_SERIAL_FUNCTIONS(3); |
| 341 | struct serial_device serial3_device = |
| 342 | INIT_PSC_SERIAL_STRUCTURE(3, "psc3", "UART3"); |
| 343 | #endif |
| 344 | |
| 345 | #if defined(CONFIG_SYS_PSC4) |
| 346 | DECLARE_PSC_SERIAL_FUNCTIONS(4); |
| 347 | struct serial_device serial4_device = |
| 348 | INIT_PSC_SERIAL_STRUCTURE(4, "psc4", "UART4"); |
| 349 | #endif |
| 350 | |
| 351 | #if defined(CONFIG_SYS_PSC6) |
| 352 | DECLARE_PSC_SERIAL_FUNCTIONS(6); |
| 353 | struct serial_device serial6_device = |
| 354 | INIT_PSC_SERIAL_STRUCTURE(6, "psc6", "UART6"); |
| 355 | #endif |
| 356 | |
| 357 | #else |
| 358 | |
| 359 | void serial_setbrg(void) |
| 360 | { |
| 361 | serial_setbrg_dev(CONFIG_PSC_CONSOLE); |
| 362 | } |
| 363 | |
| 364 | int serial_init(void) |
| 365 | { |
| 366 | return serial_init_dev(CONFIG_PSC_CONSOLE); |
| 367 | } |
| 368 | |
| 369 | void serial_putc(const char c) |
| 370 | { |
| 371 | serial_putc_dev(CONFIG_PSC_CONSOLE, c); |
| 372 | } |
| 373 | |
| 374 | void serial_putc_raw(const char c) |
| 375 | { |
| 376 | serial_putc_raw_dev(CONFIG_PSC_CONSOLE, c); |
| 377 | } |
| 378 | |
| 379 | void serial_puts(const char *s) |
| 380 | { |
| 381 | serial_puts_dev(CONFIG_PSC_CONSOLE, s); |
| 382 | } |
| 383 | |
| 384 | int serial_getc(void) |
| 385 | { |
| 386 | return serial_getc_dev(CONFIG_PSC_CONSOLE); |
| 387 | } |
| 388 | |
| 389 | int serial_tstc(void) |
| 390 | { |
| 391 | return serial_tstc_dev(CONFIG_PSC_CONSOLE); |
| 392 | } |
| 393 | |
| 394 | void serial_setrts(int s) |
| 395 | { |
| 396 | return serial_setrts_dev(CONFIG_PSC_CONSOLE, s); |
| 397 | } |
| 398 | |
| 399 | int serial_getcts(void) |
| 400 | { |
| 401 | return serial_getcts_dev(CONFIG_PSC_CONSOLE); |
| 402 | } |
Rafal Jaworowski | d3a02c3 | 2007-07-27 14:43:59 +0200 | [diff] [blame] | 403 | #endif /* CONFIG_PSC_CONSOLE */ |