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