wdenk | 4a9cbbe | 2002-08-27 09:48:53 +0000 | [diff] [blame] | 1 | /* |
| 2 | * (C) Copyright 2000 |
| 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 | |
| 24 | #include <common.h> |
| 25 | #include <commproc.h> |
| 26 | #include <command.h> |
wdenk | 281e00a | 2004-08-01 22:48:16 +0000 | [diff] [blame] | 27 | #include <serial.h> |
wdenk | d0fb80c | 2003-01-11 09:48:40 +0000 | [diff] [blame] | 28 | #include <watchdog.h> |
Mike Frysinger | 6c768ca | 2011-04-29 18:03:29 +0000 | [diff] [blame] | 29 | #include <linux/compiler.h> |
wdenk | 4a9cbbe | 2002-08-27 09:48:53 +0000 | [diff] [blame] | 30 | |
Wolfgang Denk | d87080b | 2006-03-31 18:32:53 +0200 | [diff] [blame] | 31 | DECLARE_GLOBAL_DATA_PTR; |
| 32 | |
wdenk | 4a9cbbe | 2002-08-27 09:48:53 +0000 | [diff] [blame] | 33 | #if !defined(CONFIG_8xx_CONS_NONE) /* No Console at all */ |
| 34 | |
| 35 | #if defined(CONFIG_8xx_CONS_SMC1) /* Console on SMC1 */ |
| 36 | #define SMC_INDEX 0 |
wdenk | 4a9cbbe | 2002-08-27 09:48:53 +0000 | [diff] [blame] | 37 | #define PROFF_SMC PROFF_SMC1 |
| 38 | #define CPM_CR_CH_SMC CPM_CR_CH_SMC1 |
| 39 | |
| 40 | #elif defined(CONFIG_8xx_CONS_SMC2) /* Console on SMC2 */ |
| 41 | #define SMC_INDEX 1 |
wdenk | 4a9cbbe | 2002-08-27 09:48:53 +0000 | [diff] [blame] | 42 | #define PROFF_SMC PROFF_SMC2 |
| 43 | #define CPM_CR_CH_SMC CPM_CR_CH_SMC2 |
| 44 | |
wdenk | 281e00a | 2004-08-01 22:48:16 +0000 | [diff] [blame] | 45 | #endif /* CONFIG_8xx_CONS_SMCx */ |
| 46 | |
| 47 | #if defined(CONFIG_8xx_CONS_SCC1) /* Console on SCC1 */ |
wdenk | 4a9cbbe | 2002-08-27 09:48:53 +0000 | [diff] [blame] | 48 | #define SCC_INDEX 0 |
| 49 | #define PROFF_SCC PROFF_SCC1 |
| 50 | #define CPM_CR_CH_SCC CPM_CR_CH_SCC1 |
| 51 | |
| 52 | #elif defined(CONFIG_8xx_CONS_SCC2) /* Console on SCC2 */ |
wdenk | 4a9cbbe | 2002-08-27 09:48:53 +0000 | [diff] [blame] | 53 | #define SCC_INDEX 1 |
| 54 | #define PROFF_SCC PROFF_SCC2 |
| 55 | #define CPM_CR_CH_SCC CPM_CR_CH_SCC2 |
| 56 | |
| 57 | #elif defined(CONFIG_8xx_CONS_SCC3) /* Console on SCC3 */ |
wdenk | 4a9cbbe | 2002-08-27 09:48:53 +0000 | [diff] [blame] | 58 | #define SCC_INDEX 2 |
| 59 | #define PROFF_SCC PROFF_SCC3 |
| 60 | #define CPM_CR_CH_SCC CPM_CR_CH_SCC3 |
| 61 | |
| 62 | #elif defined(CONFIG_8xx_CONS_SCC4) /* Console on SCC4 */ |
wdenk | 4a9cbbe | 2002-08-27 09:48:53 +0000 | [diff] [blame] | 63 | #define SCC_INDEX 3 |
| 64 | #define PROFF_SCC PROFF_SCC4 |
| 65 | #define CPM_CR_CH_SCC CPM_CR_CH_SCC4 |
| 66 | |
wdenk | 281e00a | 2004-08-01 22:48:16 +0000 | [diff] [blame] | 67 | #endif /* CONFIG_8xx_CONS_SCCx */ |
wdenk | 4a9cbbe | 2002-08-27 09:48:53 +0000 | [diff] [blame] | 68 | |
Heiko Schocher | 2b3f12c | 2009-02-10 09:31:47 +0100 | [diff] [blame] | 69 | #if !defined(CONFIG_SYS_SMC_RXBUFLEN) |
| 70 | #define CONFIG_SYS_SMC_RXBUFLEN 1 |
| 71 | #define CONFIG_SYS_MAXIDLE 0 |
| 72 | #else |
| 73 | #if !defined(CONFIG_SYS_MAXIDLE) |
| 74 | #error "you must define CONFIG_SYS_MAXIDLE" |
| 75 | #endif |
| 76 | #endif |
| 77 | |
| 78 | typedef volatile struct serialbuffer { |
| 79 | cbd_t rxbd; /* Rx BD */ |
| 80 | cbd_t txbd; /* Tx BD */ |
| 81 | uint rxindex; /* index for next character to read */ |
| 82 | volatile uchar rxbuf[CONFIG_SYS_SMC_RXBUFLEN];/* rx buffers */ |
| 83 | volatile uchar txbuf; /* tx buffers */ |
| 84 | } serialbuffer_t; |
| 85 | |
wdenk | 2535d60 | 2003-07-17 23:16:40 +0000 | [diff] [blame] | 86 | static void serial_setdivisor(volatile cpm8xx_t *cp) |
| 87 | { |
wdenk | 75d1ea7 | 2004-01-31 20:06:54 +0000 | [diff] [blame] | 88 | int divisor=(gd->cpu_clk + 8*gd->baudrate)/16/gd->baudrate; |
wdenk | 2535d60 | 2003-07-17 23:16:40 +0000 | [diff] [blame] | 89 | |
| 90 | if(divisor/16>0x1000) { |
Wolfgang Denk | 8ed44d9 | 2008-10-19 02:35:50 +0200 | [diff] [blame] | 91 | /* bad divisor, assume 50MHz clock and 9600 baud */ |
wdenk | 75d1ea7 | 2004-01-31 20:06:54 +0000 | [diff] [blame] | 92 | divisor=(50*1000*1000 + 8*9600)/16/9600; |
wdenk | 2535d60 | 2003-07-17 23:16:40 +0000 | [diff] [blame] | 93 | } |
| 94 | |
Jean-Christophe PLAGNIOL-VILLARD | 6d0f6bc | 2008-10-16 15:01:15 +0200 | [diff] [blame] | 95 | #ifdef CONFIG_SYS_BRGCLK_PRESCALE |
| 96 | divisor /= CONFIG_SYS_BRGCLK_PRESCALE; |
wdenk | 3bbc899 | 2003-12-07 22:27:15 +0000 | [diff] [blame] | 97 | #endif |
| 98 | |
wdenk | 2535d60 | 2003-07-17 23:16:40 +0000 | [diff] [blame] | 99 | if(divisor<=0x1000) { |
| 100 | cp->cp_brgc1=((divisor-1)<<1) | CPM_BRG_EN; |
| 101 | } else { |
| 102 | cp->cp_brgc1=((divisor/16-1)<<1) | CPM_BRG_EN | CPM_BRG_DIV16; |
| 103 | } |
| 104 | } |
| 105 | |
wdenk | 4a9cbbe | 2002-08-27 09:48:53 +0000 | [diff] [blame] | 106 | #if (defined (CONFIG_8xx_CONS_SMC1) || defined (CONFIG_8xx_CONS_SMC2)) |
| 107 | |
| 108 | /* |
| 109 | * Minimal serial functions needed to use one of the SMC ports |
| 110 | * as serial console interface. |
| 111 | */ |
| 112 | |
wdenk | 281e00a | 2004-08-01 22:48:16 +0000 | [diff] [blame] | 113 | static void smc_setbrg (void) |
| 114 | { |
Jean-Christophe PLAGNIOL-VILLARD | 6d0f6bc | 2008-10-16 15:01:15 +0200 | [diff] [blame] | 115 | volatile immap_t *im = (immap_t *)CONFIG_SYS_IMMR; |
wdenk | 281e00a | 2004-08-01 22:48:16 +0000 | [diff] [blame] | 116 | volatile cpm8xx_t *cp = &(im->im_cpm); |
| 117 | |
| 118 | /* Set up the baud rate generator. |
| 119 | * See 8xx_io/commproc.c for details. |
| 120 | * |
| 121 | * Wire BRG1 to SMCx |
| 122 | */ |
| 123 | |
| 124 | cp->cp_simode = 0x00000000; |
| 125 | |
| 126 | serial_setdivisor(cp); |
| 127 | } |
| 128 | |
| 129 | static int smc_init (void) |
wdenk | 4a9cbbe | 2002-08-27 09:48:53 +0000 | [diff] [blame] | 130 | { |
Jean-Christophe PLAGNIOL-VILLARD | 6d0f6bc | 2008-10-16 15:01:15 +0200 | [diff] [blame] | 131 | volatile immap_t *im = (immap_t *)CONFIG_SYS_IMMR; |
wdenk | 4a9cbbe | 2002-08-27 09:48:53 +0000 | [diff] [blame] | 132 | volatile smc_t *sp; |
| 133 | volatile smc_uart_t *up; |
wdenk | 4a9cbbe | 2002-08-27 09:48:53 +0000 | [diff] [blame] | 134 | volatile cpm8xx_t *cp = &(im->im_cpm); |
| 135 | #if (!defined(CONFIG_8xx_CONS_SMC1)) && (defined(CONFIG_MPC823) || defined(CONFIG_MPC850)) |
| 136 | volatile iop8xx_t *ip = (iop8xx_t *)&(im->im_ioport); |
| 137 | #endif |
| 138 | uint dpaddr; |
Heiko Schocher | 2b3f12c | 2009-02-10 09:31:47 +0100 | [diff] [blame] | 139 | volatile serialbuffer_t *rtx; |
wdenk | 4a9cbbe | 2002-08-27 09:48:53 +0000 | [diff] [blame] | 140 | |
| 141 | /* initialize pointers to SMC */ |
| 142 | |
| 143 | sp = (smc_t *) &(cp->cp_smc[SMC_INDEX]); |
| 144 | up = (smc_uart_t *) &cp->cp_dparam[PROFF_SMC]; |
Jean-Christophe PLAGNIOL-VILLARD | 6d0f6bc | 2008-10-16 15:01:15 +0200 | [diff] [blame] | 145 | #ifdef CONFIG_SYS_SMC_UCODE_PATCH |
Heiko Schocher | b423d05 | 2008-01-11 01:12:07 +0100 | [diff] [blame] | 146 | up = (smc_uart_t *) &cp->cp_dpmem[up->smc_rpbase]; |
| 147 | #else |
| 148 | /* Disable relocation */ |
| 149 | up->smc_rpbase = 0; |
| 150 | #endif |
wdenk | 4a9cbbe | 2002-08-27 09:48:53 +0000 | [diff] [blame] | 151 | |
Heiko Schocher | 255d28e | 2009-02-10 09:32:38 +0100 | [diff] [blame] | 152 | /* Disable transmitter/receiver. */ |
wdenk | 4a9cbbe | 2002-08-27 09:48:53 +0000 | [diff] [blame] | 153 | sp->smc_smcmr &= ~(SMCMR_REN | SMCMR_TEN); |
| 154 | |
Heiko Schocher | 255d28e | 2009-02-10 09:32:38 +0100 | [diff] [blame] | 155 | /* Enable SDMA. */ |
wdenk | 4a9cbbe | 2002-08-27 09:48:53 +0000 | [diff] [blame] | 156 | im->im_siu_conf.sc_sdcr = 1; |
| 157 | |
| 158 | /* clear error conditions */ |
Jean-Christophe PLAGNIOL-VILLARD | 6d0f6bc | 2008-10-16 15:01:15 +0200 | [diff] [blame] | 159 | #ifdef CONFIG_SYS_SDSR |
| 160 | im->im_sdma.sdma_sdsr = CONFIG_SYS_SDSR; |
wdenk | 4a9cbbe | 2002-08-27 09:48:53 +0000 | [diff] [blame] | 161 | #else |
| 162 | im->im_sdma.sdma_sdsr = 0x83; |
| 163 | #endif |
| 164 | |
| 165 | /* clear SDMA interrupt mask */ |
Jean-Christophe PLAGNIOL-VILLARD | 6d0f6bc | 2008-10-16 15:01:15 +0200 | [diff] [blame] | 166 | #ifdef CONFIG_SYS_SDMR |
| 167 | im->im_sdma.sdma_sdmr = CONFIG_SYS_SDMR; |
wdenk | 4a9cbbe | 2002-08-27 09:48:53 +0000 | [diff] [blame] | 168 | #else |
| 169 | im->im_sdma.sdma_sdmr = 0x00; |
| 170 | #endif |
| 171 | |
| 172 | #if defined(CONFIG_8xx_CONS_SMC1) |
Heiko Schocher | 255d28e | 2009-02-10 09:32:38 +0100 | [diff] [blame] | 173 | /* Use Port B for SMC1 instead of other functions. */ |
wdenk | 4a9cbbe | 2002-08-27 09:48:53 +0000 | [diff] [blame] | 174 | cp->cp_pbpar |= 0x000000c0; |
| 175 | cp->cp_pbdir &= ~0x000000c0; |
| 176 | cp->cp_pbodr &= ~0x000000c0; |
| 177 | #else /* CONFIG_8xx_CONS_SMC2 */ |
| 178 | # if defined(CONFIG_MPC823) || defined(CONFIG_MPC850) |
Heiko Schocher | 255d28e | 2009-02-10 09:32:38 +0100 | [diff] [blame] | 179 | /* Use Port A for SMC2 instead of other functions. */ |
wdenk | 4a9cbbe | 2002-08-27 09:48:53 +0000 | [diff] [blame] | 180 | ip->iop_papar |= 0x00c0; |
| 181 | ip->iop_padir &= ~0x00c0; |
| 182 | ip->iop_paodr &= ~0x00c0; |
| 183 | # else /* must be a 860 then */ |
| 184 | /* Use Port B for SMC2 instead of other functions. |
Heiko Schocher | 255d28e | 2009-02-10 09:32:38 +0100 | [diff] [blame] | 185 | */ |
wdenk | 4a9cbbe | 2002-08-27 09:48:53 +0000 | [diff] [blame] | 186 | cp->cp_pbpar |= 0x00000c00; |
| 187 | cp->cp_pbdir &= ~0x00000c00; |
| 188 | cp->cp_pbodr &= ~0x00000c00; |
| 189 | # endif |
| 190 | #endif |
| 191 | |
wdenk | b028f71 | 2003-12-07 21:39:28 +0000 | [diff] [blame] | 192 | #if defined(CONFIG_FADS) || defined(CONFIG_ADS) |
wdenk | 4a9cbbe | 2002-08-27 09:48:53 +0000 | [diff] [blame] | 193 | /* Enable RS232 */ |
| 194 | #if defined(CONFIG_8xx_CONS_SMC1) |
| 195 | *((uint *) BCSR1) &= ~BCSR1_RS232EN_1; |
| 196 | #else |
| 197 | *((uint *) BCSR1) &= ~BCSR1_RS232EN_2; |
| 198 | #endif |
| 199 | #endif /* CONFIG_FADS */ |
| 200 | |
| 201 | #if defined(CONFIG_RPXLITE) || defined(CONFIG_RPXCLASSIC) |
| 202 | /* Enable Monitor Port Transceiver */ |
| 203 | *((uchar *) BCSR0) |= BCSR0_ENMONXCVR ; |
| 204 | #endif /* CONFIG_RPXLITE */ |
| 205 | |
| 206 | /* Set the physical address of the host memory buffers in |
| 207 | * the buffer descriptors. |
| 208 | */ |
| 209 | |
Jean-Christophe PLAGNIOL-VILLARD | 6d0f6bc | 2008-10-16 15:01:15 +0200 | [diff] [blame] | 210 | #ifdef CONFIG_SYS_ALLOC_DPRAM |
Heiko Schocher | 2b3f12c | 2009-02-10 09:31:47 +0100 | [diff] [blame] | 211 | /* allocate |
| 212 | * size of struct serialbuffer with bd rx/tx, buffer rx/tx and rx index |
| 213 | */ |
| 214 | dpaddr = dpram_alloc_align((sizeof(serialbuffer_t)), 8); |
wdenk | 4a9cbbe | 2002-08-27 09:48:53 +0000 | [diff] [blame] | 215 | #else |
| 216 | dpaddr = CPM_SERIAL_BASE ; |
| 217 | #endif |
| 218 | |
Heiko Schocher | 2b3f12c | 2009-02-10 09:31:47 +0100 | [diff] [blame] | 219 | rtx = (serialbuffer_t *)&cp->cp_dpmem[dpaddr]; |
wdenk | 4a9cbbe | 2002-08-27 09:48:53 +0000 | [diff] [blame] | 220 | /* Allocate space for two buffer descriptors in the DP ram. |
| 221 | * For now, this address seems OK, but it may have to |
| 222 | * change with newer versions of the firmware. |
| 223 | * damm: allocating space after the two buffers for rx/tx data |
| 224 | */ |
| 225 | |
Heiko Schocher | 2b3f12c | 2009-02-10 09:31:47 +0100 | [diff] [blame] | 226 | rtx->rxbd.cbd_bufaddr = (uint) &rtx->rxbuf; |
| 227 | rtx->rxbd.cbd_sc = 0; |
| 228 | |
| 229 | rtx->txbd.cbd_bufaddr = (uint) &rtx->txbuf; |
| 230 | rtx->txbd.cbd_sc = 0; |
wdenk | 4a9cbbe | 2002-08-27 09:48:53 +0000 | [diff] [blame] | 231 | |
Heiko Schocher | 255d28e | 2009-02-10 09:32:38 +0100 | [diff] [blame] | 232 | /* Set up the uart parameters in the parameter ram. */ |
wdenk | 4a9cbbe | 2002-08-27 09:48:53 +0000 | [diff] [blame] | 233 | up->smc_rbase = dpaddr; |
| 234 | up->smc_tbase = dpaddr+sizeof(cbd_t); |
| 235 | up->smc_rfcr = SMC_EB; |
| 236 | up->smc_tfcr = SMC_EB; |
Jean-Christophe PLAGNIOL-VILLARD | 6d0f6bc | 2008-10-16 15:01:15 +0200 | [diff] [blame] | 237 | #if defined (CONFIG_SYS_SMC_UCODE_PATCH) |
Heiko Schocher | b423d05 | 2008-01-11 01:12:07 +0100 | [diff] [blame] | 238 | up->smc_rbptr = up->smc_rbase; |
| 239 | up->smc_tbptr = up->smc_tbase; |
| 240 | up->smc_rstate = 0; |
| 241 | up->smc_tstate = 0; |
| 242 | #endif |
wdenk | 4a9cbbe | 2002-08-27 09:48:53 +0000 | [diff] [blame] | 243 | |
| 244 | #if defined(CONFIG_MBX) |
| 245 | board_serial_init(); |
| 246 | #endif /* CONFIG_MBX */ |
| 247 | |
| 248 | /* Set UART mode, 8 bit, no parity, one stop. |
| 249 | * Enable receive and transmit. |
| 250 | */ |
| 251 | sp->smc_smcmr = smcr_mk_clen(9) | SMCMR_SM_UART; |
| 252 | |
| 253 | /* Mask all interrupts and remove anything pending. |
| 254 | */ |
| 255 | sp->smc_smcm = 0; |
| 256 | sp->smc_smce = 0xff; |
| 257 | |
Jean-Christophe PLAGNIOL-VILLARD | 6d0f6bc | 2008-10-16 15:01:15 +0200 | [diff] [blame] | 258 | #ifdef CONFIG_SYS_SPC1920_SMC1_CLK4 |
Markus Klotzbuecher | 8139567 | 2007-01-09 14:57:11 +0100 | [diff] [blame] | 259 | /* clock source is PLD */ |
Wolfgang Denk | 2a8dfe0 | 2007-03-21 23:26:15 +0100 | [diff] [blame] | 260 | |
Markus Klotzbuecher | 8139567 | 2007-01-09 14:57:11 +0100 | [diff] [blame] | 261 | /* set freq to 19200 Baud */ |
Jean-Christophe PLAGNIOL-VILLARD | 6d0f6bc | 2008-10-16 15:01:15 +0200 | [diff] [blame] | 262 | *((volatile uchar *) CONFIG_SYS_SPC1920_PLD_BASE+6) = 0x3; |
Markus Klotzbuecher | 8139567 | 2007-01-09 14:57:11 +0100 | [diff] [blame] | 263 | /* configure clk4 as input */ |
| 264 | im->im_ioport.iop_pdpar |= 0x800; |
| 265 | im->im_ioport.iop_pddir &= ~0x800; |
Wolfgang Denk | f11033e | 2007-01-15 13:41:04 +0100 | [diff] [blame] | 266 | |
Wolfgang Denk | 2a8dfe0 | 2007-03-21 23:26:15 +0100 | [diff] [blame] | 267 | cp->cp_simode = ((cp->cp_simode & ~0xf000) | 0x7000); |
Markus Klotzbuecher | b02d017 | 2006-07-12 08:48:24 +0200 | [diff] [blame] | 268 | #else |
| 269 | /* Set up the baud rate generator */ |
wdenk | 281e00a | 2004-08-01 22:48:16 +0000 | [diff] [blame] | 270 | smc_setbrg (); |
Markus Klotzbuecher | b02d017 | 2006-07-12 08:48:24 +0200 | [diff] [blame] | 271 | #endif |
wdenk | 4a9cbbe | 2002-08-27 09:48:53 +0000 | [diff] [blame] | 272 | |
Heiko Schocher | 255d28e | 2009-02-10 09:32:38 +0100 | [diff] [blame] | 273 | /* Make the first buffer the only buffer. */ |
Heiko Schocher | 2b3f12c | 2009-02-10 09:31:47 +0100 | [diff] [blame] | 274 | rtx->txbd.cbd_sc |= BD_SC_WRAP; |
| 275 | rtx->rxbd.cbd_sc |= BD_SC_EMPTY | BD_SC_WRAP; |
wdenk | 4a9cbbe | 2002-08-27 09:48:53 +0000 | [diff] [blame] | 276 | |
Heiko Schocher | 2b3f12c | 2009-02-10 09:31:47 +0100 | [diff] [blame] | 277 | /* single/multi character receive. */ |
| 278 | up->smc_mrblr = CONFIG_SYS_SMC_RXBUFLEN; |
| 279 | up->smc_maxidl = CONFIG_SYS_MAXIDLE; |
| 280 | rtx->rxindex = 0; |
wdenk | 4a9cbbe | 2002-08-27 09:48:53 +0000 | [diff] [blame] | 281 | |
Heiko Schocher | 255d28e | 2009-02-10 09:32:38 +0100 | [diff] [blame] | 282 | /* Initialize Tx/Rx parameters. */ |
wdenk | 4a9cbbe | 2002-08-27 09:48:53 +0000 | [diff] [blame] | 283 | while (cp->cp_cpcr & CPM_CR_FLG) /* wait if cp is busy */ |
| 284 | ; |
| 285 | |
| 286 | cp->cp_cpcr = mk_cr_cmd(CPM_CR_CH_SMC, CPM_CR_INIT_TRX) | CPM_CR_FLG; |
| 287 | |
| 288 | while (cp->cp_cpcr & CPM_CR_FLG) /* wait if cp is busy */ |
| 289 | ; |
| 290 | |
Heiko Schocher | 255d28e | 2009-02-10 09:32:38 +0100 | [diff] [blame] | 291 | /* Enable transmitter/receiver. */ |
wdenk | 4a9cbbe | 2002-08-27 09:48:53 +0000 | [diff] [blame] | 292 | sp->smc_smcmr |= SMCMR_REN | SMCMR_TEN; |
| 293 | |
| 294 | return (0); |
| 295 | } |
| 296 | |
wdenk | 281e00a | 2004-08-01 22:48:16 +0000 | [diff] [blame] | 297 | static void |
| 298 | smc_putc(const char c) |
wdenk | 4a9cbbe | 2002-08-27 09:48:53 +0000 | [diff] [blame] | 299 | { |
wdenk | 4a9cbbe | 2002-08-27 09:48:53 +0000 | [diff] [blame] | 300 | volatile smc_uart_t *up; |
Jean-Christophe PLAGNIOL-VILLARD | 6d0f6bc | 2008-10-16 15:01:15 +0200 | [diff] [blame] | 301 | volatile immap_t *im = (immap_t *)CONFIG_SYS_IMMR; |
wdenk | 4a9cbbe | 2002-08-27 09:48:53 +0000 | [diff] [blame] | 302 | volatile cpm8xx_t *cpmp = &(im->im_cpm); |
Heiko Schocher | 2b3f12c | 2009-02-10 09:31:47 +0100 | [diff] [blame] | 303 | volatile serialbuffer_t *rtx; |
wdenk | 4a9cbbe | 2002-08-27 09:48:53 +0000 | [diff] [blame] | 304 | |
wdenk | 4532cb6 | 2003-04-27 22:52:51 +0000 | [diff] [blame] | 305 | #ifdef CONFIG_MODEM_SUPPORT |
wdenk | 4532cb6 | 2003-04-27 22:52:51 +0000 | [diff] [blame] | 306 | if (gd->be_quiet) |
| 307 | return; |
| 308 | #endif |
| 309 | |
wdenk | 4a9cbbe | 2002-08-27 09:48:53 +0000 | [diff] [blame] | 310 | if (c == '\n') |
wdenk | 281e00a | 2004-08-01 22:48:16 +0000 | [diff] [blame] | 311 | smc_putc ('\r'); |
wdenk | 4a9cbbe | 2002-08-27 09:48:53 +0000 | [diff] [blame] | 312 | |
| 313 | up = (smc_uart_t *)&cpmp->cp_dparam[PROFF_SMC]; |
Jean-Christophe PLAGNIOL-VILLARD | 6d0f6bc | 2008-10-16 15:01:15 +0200 | [diff] [blame] | 314 | #ifdef CONFIG_SYS_SMC_UCODE_PATCH |
Heiko Schocher | b423d05 | 2008-01-11 01:12:07 +0100 | [diff] [blame] | 315 | up = (smc_uart_t *) &cpmp->cp_dpmem[up->smc_rpbase]; |
| 316 | #endif |
wdenk | 4a9cbbe | 2002-08-27 09:48:53 +0000 | [diff] [blame] | 317 | |
Heiko Schocher | 2b3f12c | 2009-02-10 09:31:47 +0100 | [diff] [blame] | 318 | rtx = (serialbuffer_t *)&cpmp->cp_dpmem[up->smc_rbase]; |
wdenk | 4a9cbbe | 2002-08-27 09:48:53 +0000 | [diff] [blame] | 319 | |
Heiko Schocher | 255d28e | 2009-02-10 09:32:38 +0100 | [diff] [blame] | 320 | /* Wait for last character to go. */ |
Heiko Schocher | 2b3f12c | 2009-02-10 09:31:47 +0100 | [diff] [blame] | 321 | rtx->txbuf = c; |
| 322 | rtx->txbd.cbd_datlen = 1; |
| 323 | rtx->txbd.cbd_sc |= BD_SC_READY; |
wdenk | 4a9cbbe | 2002-08-27 09:48:53 +0000 | [diff] [blame] | 324 | __asm__("eieio"); |
wdenk | d0fb80c | 2003-01-11 09:48:40 +0000 | [diff] [blame] | 325 | |
Heiko Schocher | 2b3f12c | 2009-02-10 09:31:47 +0100 | [diff] [blame] | 326 | while (rtx->txbd.cbd_sc & BD_SC_READY) { |
wdenk | d0fb80c | 2003-01-11 09:48:40 +0000 | [diff] [blame] | 327 | WATCHDOG_RESET (); |
wdenk | 4a9cbbe | 2002-08-27 09:48:53 +0000 | [diff] [blame] | 328 | __asm__("eieio"); |
wdenk | d0fb80c | 2003-01-11 09:48:40 +0000 | [diff] [blame] | 329 | } |
wdenk | 4a9cbbe | 2002-08-27 09:48:53 +0000 | [diff] [blame] | 330 | } |
| 331 | |
wdenk | 281e00a | 2004-08-01 22:48:16 +0000 | [diff] [blame] | 332 | static void |
| 333 | smc_puts (const char *s) |
| 334 | { |
| 335 | while (*s) { |
| 336 | smc_putc (*s++); |
| 337 | } |
| 338 | } |
| 339 | |
| 340 | static int |
| 341 | smc_getc(void) |
wdenk | 4a9cbbe | 2002-08-27 09:48:53 +0000 | [diff] [blame] | 342 | { |
wdenk | 4a9cbbe | 2002-08-27 09:48:53 +0000 | [diff] [blame] | 343 | volatile smc_uart_t *up; |
Jean-Christophe PLAGNIOL-VILLARD | 6d0f6bc | 2008-10-16 15:01:15 +0200 | [diff] [blame] | 344 | volatile immap_t *im = (immap_t *)CONFIG_SYS_IMMR; |
wdenk | 4a9cbbe | 2002-08-27 09:48:53 +0000 | [diff] [blame] | 345 | volatile cpm8xx_t *cpmp = &(im->im_cpm); |
Heiko Schocher | 2b3f12c | 2009-02-10 09:31:47 +0100 | [diff] [blame] | 346 | volatile serialbuffer_t *rtx; |
| 347 | unsigned char c; |
wdenk | 4a9cbbe | 2002-08-27 09:48:53 +0000 | [diff] [blame] | 348 | |
| 349 | up = (smc_uart_t *)&cpmp->cp_dparam[PROFF_SMC]; |
Jean-Christophe PLAGNIOL-VILLARD | 6d0f6bc | 2008-10-16 15:01:15 +0200 | [diff] [blame] | 350 | #ifdef CONFIG_SYS_SMC_UCODE_PATCH |
Heiko Schocher | b423d05 | 2008-01-11 01:12:07 +0100 | [diff] [blame] | 351 | up = (smc_uart_t *) &cpmp->cp_dpmem[up->smc_rpbase]; |
| 352 | #endif |
Heiko Schocher | 2b3f12c | 2009-02-10 09:31:47 +0100 | [diff] [blame] | 353 | rtx = (serialbuffer_t *)&cpmp->cp_dpmem[up->smc_rbase]; |
wdenk | 4a9cbbe | 2002-08-27 09:48:53 +0000 | [diff] [blame] | 354 | |
Heiko Schocher | 255d28e | 2009-02-10 09:32:38 +0100 | [diff] [blame] | 355 | /* Wait for character to show up. */ |
Heiko Schocher | 2b3f12c | 2009-02-10 09:31:47 +0100 | [diff] [blame] | 356 | while (rtx->rxbd.cbd_sc & BD_SC_EMPTY) |
wdenk | d0fb80c | 2003-01-11 09:48:40 +0000 | [diff] [blame] | 357 | WATCHDOG_RESET (); |
| 358 | |
Heiko Schocher | 2b3f12c | 2009-02-10 09:31:47 +0100 | [diff] [blame] | 359 | /* the characters are read one by one, |
| 360 | * use the rxindex to know the next char to deliver |
| 361 | */ |
| 362 | c = *(unsigned char *) (rtx->rxbd.cbd_bufaddr+rtx->rxindex); |
| 363 | rtx->rxindex++; |
wdenk | 4a9cbbe | 2002-08-27 09:48:53 +0000 | [diff] [blame] | 364 | |
Heiko Schocher | 2b3f12c | 2009-02-10 09:31:47 +0100 | [diff] [blame] | 365 | /* check if all char are readout, then make prepare for next receive */ |
| 366 | if (rtx->rxindex >= rtx->rxbd.cbd_datlen) { |
| 367 | rtx->rxindex = 0; |
| 368 | rtx->rxbd.cbd_sc |= BD_SC_EMPTY; |
| 369 | } |
wdenk | 4a9cbbe | 2002-08-27 09:48:53 +0000 | [diff] [blame] | 370 | return(c); |
| 371 | } |
| 372 | |
wdenk | 281e00a | 2004-08-01 22:48:16 +0000 | [diff] [blame] | 373 | static int |
| 374 | smc_tstc(void) |
wdenk | 4a9cbbe | 2002-08-27 09:48:53 +0000 | [diff] [blame] | 375 | { |
wdenk | 4a9cbbe | 2002-08-27 09:48:53 +0000 | [diff] [blame] | 376 | volatile smc_uart_t *up; |
Jean-Christophe PLAGNIOL-VILLARD | 6d0f6bc | 2008-10-16 15:01:15 +0200 | [diff] [blame] | 377 | volatile immap_t *im = (immap_t *)CONFIG_SYS_IMMR; |
wdenk | 4a9cbbe | 2002-08-27 09:48:53 +0000 | [diff] [blame] | 378 | volatile cpm8xx_t *cpmp = &(im->im_cpm); |
Heiko Schocher | 2b3f12c | 2009-02-10 09:31:47 +0100 | [diff] [blame] | 379 | volatile serialbuffer_t *rtx; |
wdenk | 4a9cbbe | 2002-08-27 09:48:53 +0000 | [diff] [blame] | 380 | |
| 381 | up = (smc_uart_t *)&cpmp->cp_dparam[PROFF_SMC]; |
Jean-Christophe PLAGNIOL-VILLARD | 6d0f6bc | 2008-10-16 15:01:15 +0200 | [diff] [blame] | 382 | #ifdef CONFIG_SYS_SMC_UCODE_PATCH |
Heiko Schocher | b423d05 | 2008-01-11 01:12:07 +0100 | [diff] [blame] | 383 | up = (smc_uart_t *) &cpmp->cp_dpmem[up->smc_rpbase]; |
| 384 | #endif |
wdenk | 4a9cbbe | 2002-08-27 09:48:53 +0000 | [diff] [blame] | 385 | |
Heiko Schocher | 2b3f12c | 2009-02-10 09:31:47 +0100 | [diff] [blame] | 386 | rtx = (serialbuffer_t *)&cpmp->cp_dpmem[up->smc_rbase]; |
wdenk | 4a9cbbe | 2002-08-27 09:48:53 +0000 | [diff] [blame] | 387 | |
Heiko Schocher | 2b3f12c | 2009-02-10 09:31:47 +0100 | [diff] [blame] | 388 | return !(rtx->rxbd.cbd_sc & BD_SC_EMPTY); |
wdenk | 4a9cbbe | 2002-08-27 09:48:53 +0000 | [diff] [blame] | 389 | } |
| 390 | |
wdenk | 281e00a | 2004-08-01 22:48:16 +0000 | [diff] [blame] | 391 | struct serial_device serial_smc_device = |
| 392 | { |
| 393 | "serial_smc", |
wdenk | 281e00a | 2004-08-01 22:48:16 +0000 | [diff] [blame] | 394 | smc_init, |
Anatolij Gustschin | fbb0030 | 2010-04-24 19:27:04 +0200 | [diff] [blame] | 395 | NULL, |
wdenk | 281e00a | 2004-08-01 22:48:16 +0000 | [diff] [blame] | 396 | smc_setbrg, |
| 397 | smc_getc, |
| 398 | smc_tstc, |
| 399 | smc_putc, |
| 400 | smc_puts, |
| 401 | }; |
wdenk | 4a9cbbe | 2002-08-27 09:48:53 +0000 | [diff] [blame] | 402 | |
wdenk | 281e00a | 2004-08-01 22:48:16 +0000 | [diff] [blame] | 403 | #endif /* CONFIG_8xx_CONS_SMC1 || CONFIG_8xx_CONS_SMC2 */ |
| 404 | |
| 405 | #if defined(CONFIG_8xx_CONS_SCC1) || defined(CONFIG_8xx_CONS_SCC2) || \ |
| 406 | defined(CONFIG_8xx_CONS_SCC3) || defined(CONFIG_8xx_CONS_SCC4) |
| 407 | |
| 408 | static void |
| 409 | scc_setbrg (void) |
| 410 | { |
Jean-Christophe PLAGNIOL-VILLARD | 6d0f6bc | 2008-10-16 15:01:15 +0200 | [diff] [blame] | 411 | volatile immap_t *im = (immap_t *)CONFIG_SYS_IMMR; |
wdenk | 281e00a | 2004-08-01 22:48:16 +0000 | [diff] [blame] | 412 | volatile cpm8xx_t *cp = &(im->im_cpm); |
| 413 | |
| 414 | /* Set up the baud rate generator. |
| 415 | * See 8xx_io/commproc.c for details. |
| 416 | * |
| 417 | * Wire BRG1 to SCCx |
| 418 | */ |
| 419 | |
| 420 | cp->cp_sicr &= ~(0x000000FF << (8 * SCC_INDEX)); |
| 421 | |
| 422 | serial_setdivisor(cp); |
| 423 | } |
| 424 | |
| 425 | static int scc_init (void) |
wdenk | 4a9cbbe | 2002-08-27 09:48:53 +0000 | [diff] [blame] | 426 | { |
Jean-Christophe PLAGNIOL-VILLARD | 6d0f6bc | 2008-10-16 15:01:15 +0200 | [diff] [blame] | 427 | volatile immap_t *im = (immap_t *)CONFIG_SYS_IMMR; |
wdenk | 4a9cbbe | 2002-08-27 09:48:53 +0000 | [diff] [blame] | 428 | volatile scc_t *sp; |
| 429 | volatile scc_uart_t *up; |
| 430 | volatile cbd_t *tbdf, *rbdf; |
| 431 | volatile cpm8xx_t *cp = &(im->im_cpm); |
| 432 | uint dpaddr; |
| 433 | #if (SCC_INDEX != 2) || !defined(CONFIG_MPC850) |
| 434 | volatile iop8xx_t *ip = (iop8xx_t *)&(im->im_ioport); |
| 435 | #endif |
| 436 | |
| 437 | /* initialize pointers to SCC */ |
| 438 | |
| 439 | sp = (scc_t *) &(cp->cp_scc[SCC_INDEX]); |
| 440 | up = (scc_uart_t *) &cp->cp_dparam[PROFF_SCC]; |
| 441 | |
| 442 | #if defined(CONFIG_LWMON) && defined(CONFIG_8xx_CONS_SCC2) |
| 443 | { /* Disable Ethernet, enable Serial */ |
| 444 | uchar c; |
| 445 | |
| 446 | c = pic_read (0x61); |
| 447 | c &= ~0x40; /* enable COM3 */ |
| 448 | c |= 0x80; /* disable Ethernet */ |
| 449 | pic_write (0x61, c); |
| 450 | |
| 451 | /* enable RTS2 */ |
| 452 | cp->cp_pbpar |= 0x2000; |
| 453 | cp->cp_pbdat |= 0x2000; |
| 454 | cp->cp_pbdir |= 0x2000; |
| 455 | } |
| 456 | #endif /* CONFIG_LWMON */ |
| 457 | |
Heiko Schocher | 255d28e | 2009-02-10 09:32:38 +0100 | [diff] [blame] | 458 | /* Disable transmitter/receiver. */ |
wdenk | 4a9cbbe | 2002-08-27 09:48:53 +0000 | [diff] [blame] | 459 | sp->scc_gsmrl &= ~(SCC_GSMRL_ENR | SCC_GSMRL_ENT); |
| 460 | |
| 461 | #if (SCC_INDEX == 2) && defined(CONFIG_MPC850) |
| 462 | /* |
| 463 | * The MPC850 has SCC3 on Port B |
| 464 | */ |
| 465 | cp->cp_pbpar |= 0x06; |
| 466 | cp->cp_pbdir &= ~0x06; |
| 467 | cp->cp_pbodr &= ~0x06; |
| 468 | |
| 469 | #elif (SCC_INDEX < 2) || !defined(CONFIG_IP860) |
| 470 | /* |
| 471 | * Standard configuration for SCC's is on Part A |
| 472 | */ |
| 473 | ip->iop_papar |= ((3 << (2 * SCC_INDEX))); |
| 474 | ip->iop_padir &= ~((3 << (2 * SCC_INDEX))); |
| 475 | ip->iop_paodr &= ~((3 << (2 * SCC_INDEX))); |
| 476 | #else |
| 477 | /* |
| 478 | * The IP860 has SCC3 and SCC4 on Port D |
| 479 | */ |
| 480 | ip->iop_pdpar |= ((3 << (2 * SCC_INDEX))); |
| 481 | #endif |
| 482 | |
Heiko Schocher | 255d28e | 2009-02-10 09:32:38 +0100 | [diff] [blame] | 483 | /* Allocate space for two buffer descriptors in the DP ram. */ |
wdenk | 4a9cbbe | 2002-08-27 09:48:53 +0000 | [diff] [blame] | 484 | |
Jean-Christophe PLAGNIOL-VILLARD | 6d0f6bc | 2008-10-16 15:01:15 +0200 | [diff] [blame] | 485 | #ifdef CONFIG_SYS_ALLOC_DPRAM |
wdenk | 4a9cbbe | 2002-08-27 09:48:53 +0000 | [diff] [blame] | 486 | dpaddr = dpram_alloc_align (sizeof(cbd_t)*2 + 2, 8) ; |
| 487 | #else |
wdenk | 281e00a | 2004-08-01 22:48:16 +0000 | [diff] [blame] | 488 | dpaddr = CPM_SERIAL2_BASE ; |
wdenk | 4a9cbbe | 2002-08-27 09:48:53 +0000 | [diff] [blame] | 489 | #endif |
| 490 | |
Heiko Schocher | 255d28e | 2009-02-10 09:32:38 +0100 | [diff] [blame] | 491 | /* Enable SDMA. */ |
wdenk | 4a9cbbe | 2002-08-27 09:48:53 +0000 | [diff] [blame] | 492 | im->im_siu_conf.sc_sdcr = 0x0001; |
| 493 | |
| 494 | /* Set the physical address of the host memory buffers in |
| 495 | * the buffer descriptors. |
| 496 | */ |
| 497 | |
| 498 | rbdf = (cbd_t *)&cp->cp_dpmem[dpaddr]; |
| 499 | rbdf->cbd_bufaddr = (uint) (rbdf+2); |
| 500 | rbdf->cbd_sc = 0; |
| 501 | tbdf = rbdf + 1; |
| 502 | tbdf->cbd_bufaddr = ((uint) (rbdf+2)) + 1; |
| 503 | tbdf->cbd_sc = 0; |
| 504 | |
Heiko Schocher | 255d28e | 2009-02-10 09:32:38 +0100 | [diff] [blame] | 505 | /* Set up the baud rate generator. */ |
wdenk | 281e00a | 2004-08-01 22:48:16 +0000 | [diff] [blame] | 506 | scc_setbrg (); |
wdenk | 4a9cbbe | 2002-08-27 09:48:53 +0000 | [diff] [blame] | 507 | |
Heiko Schocher | 255d28e | 2009-02-10 09:32:38 +0100 | [diff] [blame] | 508 | /* Set up the uart parameters in the parameter ram. */ |
wdenk | 4a9cbbe | 2002-08-27 09:48:53 +0000 | [diff] [blame] | 509 | up->scc_genscc.scc_rbase = dpaddr; |
| 510 | up->scc_genscc.scc_tbase = dpaddr+sizeof(cbd_t); |
| 511 | |
Heiko Schocher | 255d28e | 2009-02-10 09:32:38 +0100 | [diff] [blame] | 512 | /* Initialize Tx/Rx parameters. */ |
wdenk | 4a9cbbe | 2002-08-27 09:48:53 +0000 | [diff] [blame] | 513 | while (cp->cp_cpcr & CPM_CR_FLG) /* wait if cp is busy */ |
| 514 | ; |
| 515 | cp->cp_cpcr = mk_cr_cmd(CPM_CR_CH_SCC, CPM_CR_INIT_TRX) | CPM_CR_FLG; |
| 516 | |
| 517 | while (cp->cp_cpcr & CPM_CR_FLG) /* wait if cp is busy */ |
| 518 | ; |
| 519 | |
| 520 | up->scc_genscc.scc_rfcr = SCC_EB | 0x05; |
| 521 | up->scc_genscc.scc_tfcr = SCC_EB | 0x05; |
| 522 | |
| 523 | up->scc_genscc.scc_mrblr = 1; /* Single character receive */ |
| 524 | up->scc_maxidl = 0; /* disable max idle */ |
| 525 | up->scc_brkcr = 1; /* send one break character on stop TX */ |
| 526 | up->scc_parec = 0; |
| 527 | up->scc_frmec = 0; |
| 528 | up->scc_nosec = 0; |
| 529 | up->scc_brkec = 0; |
| 530 | up->scc_uaddr1 = 0; |
| 531 | up->scc_uaddr2 = 0; |
| 532 | up->scc_toseq = 0; |
| 533 | up->scc_char1 = 0x8000; |
| 534 | up->scc_char2 = 0x8000; |
| 535 | up->scc_char3 = 0x8000; |
| 536 | up->scc_char4 = 0x8000; |
| 537 | up->scc_char5 = 0x8000; |
| 538 | up->scc_char6 = 0x8000; |
| 539 | up->scc_char7 = 0x8000; |
| 540 | up->scc_char8 = 0x8000; |
| 541 | up->scc_rccm = 0xc0ff; |
| 542 | |
Heiko Schocher | 255d28e | 2009-02-10 09:32:38 +0100 | [diff] [blame] | 543 | /* Set low latency / small fifo. */ |
wdenk | 4a9cbbe | 2002-08-27 09:48:53 +0000 | [diff] [blame] | 544 | sp->scc_gsmrh = SCC_GSMRH_RFW; |
| 545 | |
| 546 | /* Set SCC(x) clock mode to 16x |
| 547 | * See 8xx_io/commproc.c for details. |
| 548 | * |
| 549 | * Wire BRG1 to SCCn |
| 550 | */ |
| 551 | |
Heiko Schocher | 255d28e | 2009-02-10 09:32:38 +0100 | [diff] [blame] | 552 | /* Set UART mode, clock divider 16 on Tx and Rx */ |
wdenk | 281e00a | 2004-08-01 22:48:16 +0000 | [diff] [blame] | 553 | sp->scc_gsmrl &= ~0xF; |
wdenk | 4a9cbbe | 2002-08-27 09:48:53 +0000 | [diff] [blame] | 554 | sp->scc_gsmrl |= |
| 555 | (SCC_GSMRL_MODE_UART | SCC_GSMRL_TDCR_16 | SCC_GSMRL_RDCR_16); |
| 556 | |
wdenk | 281e00a | 2004-08-01 22:48:16 +0000 | [diff] [blame] | 557 | sp->scc_psmr = 0; |
wdenk | 4a9cbbe | 2002-08-27 09:48:53 +0000 | [diff] [blame] | 558 | sp->scc_psmr |= SCU_PSMR_CL; |
| 559 | |
Heiko Schocher | 255d28e | 2009-02-10 09:32:38 +0100 | [diff] [blame] | 560 | /* Mask all interrupts and remove anything pending. */ |
wdenk | 4a9cbbe | 2002-08-27 09:48:53 +0000 | [diff] [blame] | 561 | sp->scc_sccm = 0; |
| 562 | sp->scc_scce = 0xffff; |
| 563 | sp->scc_dsr = 0x7e7e; |
| 564 | sp->scc_psmr = 0x3000; |
| 565 | |
Heiko Schocher | 255d28e | 2009-02-10 09:32:38 +0100 | [diff] [blame] | 566 | /* Make the first buffer the only buffer. */ |
wdenk | 4a9cbbe | 2002-08-27 09:48:53 +0000 | [diff] [blame] | 567 | tbdf->cbd_sc |= BD_SC_WRAP; |
| 568 | rbdf->cbd_sc |= BD_SC_EMPTY | BD_SC_WRAP; |
| 569 | |
Heiko Schocher | 255d28e | 2009-02-10 09:32:38 +0100 | [diff] [blame] | 570 | /* Enable transmitter/receiver. */ |
wdenk | 4a9cbbe | 2002-08-27 09:48:53 +0000 | [diff] [blame] | 571 | sp->scc_gsmrl |= (SCC_GSMRL_ENR | SCC_GSMRL_ENT); |
| 572 | |
| 573 | return (0); |
| 574 | } |
| 575 | |
wdenk | 281e00a | 2004-08-01 22:48:16 +0000 | [diff] [blame] | 576 | static void |
| 577 | scc_putc(const char c) |
wdenk | 4a9cbbe | 2002-08-27 09:48:53 +0000 | [diff] [blame] | 578 | { |
| 579 | volatile cbd_t *tbdf; |
| 580 | volatile char *buf; |
| 581 | volatile scc_uart_t *up; |
Jean-Christophe PLAGNIOL-VILLARD | 6d0f6bc | 2008-10-16 15:01:15 +0200 | [diff] [blame] | 582 | volatile immap_t *im = (immap_t *)CONFIG_SYS_IMMR; |
wdenk | 4a9cbbe | 2002-08-27 09:48:53 +0000 | [diff] [blame] | 583 | volatile cpm8xx_t *cpmp = &(im->im_cpm); |
| 584 | |
wdenk | 281e00a | 2004-08-01 22:48:16 +0000 | [diff] [blame] | 585 | #ifdef CONFIG_MODEM_SUPPORT |
wdenk | 281e00a | 2004-08-01 22:48:16 +0000 | [diff] [blame] | 586 | if (gd->be_quiet) |
| 587 | return; |
| 588 | #endif |
| 589 | |
wdenk | 4a9cbbe | 2002-08-27 09:48:53 +0000 | [diff] [blame] | 590 | if (c == '\n') |
wdenk | 281e00a | 2004-08-01 22:48:16 +0000 | [diff] [blame] | 591 | scc_putc ('\r'); |
wdenk | 4a9cbbe | 2002-08-27 09:48:53 +0000 | [diff] [blame] | 592 | |
| 593 | up = (scc_uart_t *)&cpmp->cp_dparam[PROFF_SCC]; |
| 594 | |
| 595 | tbdf = (cbd_t *)&cpmp->cp_dpmem[up->scc_genscc.scc_tbase]; |
| 596 | |
Heiko Schocher | 255d28e | 2009-02-10 09:32:38 +0100 | [diff] [blame] | 597 | /* Wait for last character to go. */ |
wdenk | 4a9cbbe | 2002-08-27 09:48:53 +0000 | [diff] [blame] | 598 | |
| 599 | buf = (char *)tbdf->cbd_bufaddr; |
wdenk | 4a9cbbe | 2002-08-27 09:48:53 +0000 | [diff] [blame] | 600 | |
| 601 | *buf = c; |
| 602 | tbdf->cbd_datlen = 1; |
| 603 | tbdf->cbd_sc |= BD_SC_READY; |
| 604 | __asm__("eieio"); |
wdenk | d0fb80c | 2003-01-11 09:48:40 +0000 | [diff] [blame] | 605 | |
| 606 | while (tbdf->cbd_sc & BD_SC_READY) { |
wdenk | 4a9cbbe | 2002-08-27 09:48:53 +0000 | [diff] [blame] | 607 | __asm__("eieio"); |
wdenk | d0fb80c | 2003-01-11 09:48:40 +0000 | [diff] [blame] | 608 | WATCHDOG_RESET (); |
| 609 | } |
wdenk | 4a9cbbe | 2002-08-27 09:48:53 +0000 | [diff] [blame] | 610 | } |
| 611 | |
wdenk | 281e00a | 2004-08-01 22:48:16 +0000 | [diff] [blame] | 612 | static void |
| 613 | scc_puts (const char *s) |
| 614 | { |
| 615 | while (*s) { |
| 616 | scc_putc (*s++); |
| 617 | } |
| 618 | } |
| 619 | |
| 620 | static int |
| 621 | scc_getc(void) |
wdenk | 4a9cbbe | 2002-08-27 09:48:53 +0000 | [diff] [blame] | 622 | { |
| 623 | volatile cbd_t *rbdf; |
| 624 | volatile unsigned char *buf; |
| 625 | volatile scc_uart_t *up; |
Jean-Christophe PLAGNIOL-VILLARD | 6d0f6bc | 2008-10-16 15:01:15 +0200 | [diff] [blame] | 626 | volatile immap_t *im = (immap_t *)CONFIG_SYS_IMMR; |
wdenk | 4a9cbbe | 2002-08-27 09:48:53 +0000 | [diff] [blame] | 627 | volatile cpm8xx_t *cpmp = &(im->im_cpm); |
| 628 | unsigned char c; |
| 629 | |
| 630 | up = (scc_uart_t *)&cpmp->cp_dparam[PROFF_SCC]; |
| 631 | |
| 632 | rbdf = (cbd_t *)&cpmp->cp_dpmem[up->scc_genscc.scc_rbase]; |
| 633 | |
Heiko Schocher | 255d28e | 2009-02-10 09:32:38 +0100 | [diff] [blame] | 634 | /* Wait for character to show up. */ |
wdenk | 4a9cbbe | 2002-08-27 09:48:53 +0000 | [diff] [blame] | 635 | buf = (unsigned char *)rbdf->cbd_bufaddr; |
wdenk | d0fb80c | 2003-01-11 09:48:40 +0000 | [diff] [blame] | 636 | |
wdenk | 4a9cbbe | 2002-08-27 09:48:53 +0000 | [diff] [blame] | 637 | while (rbdf->cbd_sc & BD_SC_EMPTY) |
wdenk | d0fb80c | 2003-01-11 09:48:40 +0000 | [diff] [blame] | 638 | WATCHDOG_RESET (); |
| 639 | |
wdenk | 4a9cbbe | 2002-08-27 09:48:53 +0000 | [diff] [blame] | 640 | c = *buf; |
| 641 | rbdf->cbd_sc |= BD_SC_EMPTY; |
| 642 | |
| 643 | return(c); |
| 644 | } |
| 645 | |
wdenk | 281e00a | 2004-08-01 22:48:16 +0000 | [diff] [blame] | 646 | static int |
| 647 | scc_tstc(void) |
wdenk | 4a9cbbe | 2002-08-27 09:48:53 +0000 | [diff] [blame] | 648 | { |
| 649 | volatile cbd_t *rbdf; |
| 650 | volatile scc_uart_t *up; |
Jean-Christophe PLAGNIOL-VILLARD | 6d0f6bc | 2008-10-16 15:01:15 +0200 | [diff] [blame] | 651 | volatile immap_t *im = (immap_t *)CONFIG_SYS_IMMR; |
wdenk | 4a9cbbe | 2002-08-27 09:48:53 +0000 | [diff] [blame] | 652 | volatile cpm8xx_t *cpmp = &(im->im_cpm); |
| 653 | |
| 654 | up = (scc_uart_t *)&cpmp->cp_dparam[PROFF_SCC]; |
| 655 | |
| 656 | rbdf = (cbd_t *)&cpmp->cp_dpmem[up->scc_genscc.scc_rbase]; |
| 657 | |
| 658 | return(!(rbdf->cbd_sc & BD_SC_EMPTY)); |
| 659 | } |
| 660 | |
wdenk | 281e00a | 2004-08-01 22:48:16 +0000 | [diff] [blame] | 661 | struct serial_device serial_scc_device = |
wdenk | 4a9cbbe | 2002-08-27 09:48:53 +0000 | [diff] [blame] | 662 | { |
wdenk | 281e00a | 2004-08-01 22:48:16 +0000 | [diff] [blame] | 663 | "serial_scc", |
wdenk | 281e00a | 2004-08-01 22:48:16 +0000 | [diff] [blame] | 664 | scc_init, |
Anatolij Gustschin | fbb0030 | 2010-04-24 19:27:04 +0200 | [diff] [blame] | 665 | NULL, |
wdenk | 281e00a | 2004-08-01 22:48:16 +0000 | [diff] [blame] | 666 | scc_setbrg, |
| 667 | scc_getc, |
| 668 | scc_tstc, |
| 669 | scc_putc, |
| 670 | scc_puts, |
| 671 | }; |
| 672 | |
| 673 | #endif /* CONFIG_8xx_CONS_SCCx */ |
| 674 | |
Mike Frysinger | 6c768ca | 2011-04-29 18:03:29 +0000 | [diff] [blame] | 675 | __weak struct serial_device *default_serial_console(void) |
| 676 | { |
| 677 | #if defined(CONFIG_8xx_CONS_SMC1) || defined(CONFIG_8xx_CONS_SMC2) |
| 678 | return &serial_smc_device; |
| 679 | #else |
| 680 | return &serial_scc_device; |
| 681 | #endif |
| 682 | } |
| 683 | |
wdenk | 281e00a | 2004-08-01 22:48:16 +0000 | [diff] [blame] | 684 | #ifdef CONFIG_MODEM_SUPPORT |
| 685 | void disable_putc(void) |
| 686 | { |
wdenk | 281e00a | 2004-08-01 22:48:16 +0000 | [diff] [blame] | 687 | gd->be_quiet = 1; |
wdenk | 4a9cbbe | 2002-08-27 09:48:53 +0000 | [diff] [blame] | 688 | } |
| 689 | |
wdenk | 281e00a | 2004-08-01 22:48:16 +0000 | [diff] [blame] | 690 | void enable_putc(void) |
| 691 | { |
wdenk | 281e00a | 2004-08-01 22:48:16 +0000 | [diff] [blame] | 692 | gd->be_quiet = 0; |
| 693 | } |
| 694 | #endif |
wdenk | 4a9cbbe | 2002-08-27 09:48:53 +0000 | [diff] [blame] | 695 | |
Jon Loeliger | 4431283 | 2007-07-09 19:06:00 -0500 | [diff] [blame] | 696 | #if defined(CONFIG_CMD_KGDB) |
wdenk | 4a9cbbe | 2002-08-27 09:48:53 +0000 | [diff] [blame] | 697 | |
| 698 | void |
| 699 | kgdb_serial_init(void) |
| 700 | { |
wdenk | 281e00a | 2004-08-01 22:48:16 +0000 | [diff] [blame] | 701 | int i = -1; |
| 702 | |
Mike Frysinger | 1c9a560 | 2011-04-29 18:03:31 +0000 | [diff] [blame^] | 703 | if (strcmp(default_serial_console()->name, "serial_smc") == 0) |
wdenk | 281e00a | 2004-08-01 22:48:16 +0000 | [diff] [blame] | 704 | { |
wdenk | 4a9cbbe | 2002-08-27 09:48:53 +0000 | [diff] [blame] | 705 | #if defined(CONFIG_8xx_CONS_SMC1) |
wdenk | 281e00a | 2004-08-01 22:48:16 +0000 | [diff] [blame] | 706 | i = 1; |
wdenk | 4a9cbbe | 2002-08-27 09:48:53 +0000 | [diff] [blame] | 707 | #elif defined(CONFIG_8xx_CONS_SMC2) |
wdenk | 281e00a | 2004-08-01 22:48:16 +0000 | [diff] [blame] | 708 | i = 2; |
wdenk | 4a9cbbe | 2002-08-27 09:48:53 +0000 | [diff] [blame] | 709 | #endif |
wdenk | 281e00a | 2004-08-01 22:48:16 +0000 | [diff] [blame] | 710 | } |
Mike Frysinger | 1c9a560 | 2011-04-29 18:03:31 +0000 | [diff] [blame^] | 711 | else if (strcmp(default_serial_console()->name, "serial_scc") == 0) |
wdenk | 281e00a | 2004-08-01 22:48:16 +0000 | [diff] [blame] | 712 | { |
| 713 | #if defined(CONFIG_8xx_CONS_SCC1) |
| 714 | i = 1; |
| 715 | #elif defined(CONFIG_8xx_CONS_SCC2) |
| 716 | i = 2; |
| 717 | #elif defined(CONFIG_8xx_CONS_SCC3) |
| 718 | i = 3; |
| 719 | #elif defined(CONFIG_8xx_CONS_SCC4) |
| 720 | i = 4; |
| 721 | #endif |
| 722 | } |
| 723 | |
| 724 | if (i >= 0) |
| 725 | { |
Mike Frysinger | 1c9a560 | 2011-04-29 18:03:31 +0000 | [diff] [blame^] | 726 | serial_printf("[on %s%d] ", default_serial_console()->name, i); |
wdenk | 281e00a | 2004-08-01 22:48:16 +0000 | [diff] [blame] | 727 | } |
wdenk | 4a9cbbe | 2002-08-27 09:48:53 +0000 | [diff] [blame] | 728 | } |
| 729 | |
| 730 | void |
| 731 | putDebugChar (int c) |
| 732 | { |
| 733 | serial_putc (c); |
| 734 | } |
| 735 | |
| 736 | void |
| 737 | putDebugStr (const char *str) |
| 738 | { |
| 739 | serial_puts (str); |
| 740 | } |
| 741 | |
| 742 | int |
| 743 | getDebugChar (void) |
| 744 | { |
| 745 | return serial_getc(); |
| 746 | } |
| 747 | |
| 748 | void |
| 749 | kgdb_interruptible (int yes) |
| 750 | { |
| 751 | return; |
| 752 | } |
Jon Loeliger | 068b60a | 2007-07-10 10:27:39 -0500 | [diff] [blame] | 753 | #endif |
wdenk | 4a9cbbe | 2002-08-27 09:48:53 +0000 | [diff] [blame] | 754 | |
| 755 | #endif /* CONFIG_8xx_CONS_NONE */ |