wdenk | 4a9cbbe | 2002-08-27 09:48:53 +0000 | [diff] [blame] | 1 | /* |
| 2 | * (C) Copyright 2000, 2001, 2002 |
| 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 | * Hacked for MPC8260 by Murray.Jensen@cmst.csiro.au, 19-Oct-00, with |
Stefan Roese | 88fbf93 | 2010-04-15 16:07:28 +0200 | [diff] [blame] | 24 | * changes based on the file arch/powerpc/mbxboot/m8260_tty.c from the |
wdenk | 4a9cbbe | 2002-08-27 09:48:53 +0000 | [diff] [blame] | 25 | * Linux/PPC sources (m8260_tty.c had no copyright info in it). |
| 26 | */ |
| 27 | |
| 28 | /* |
| 29 | * Minimal serial functions needed to use one of the SMC ports |
| 30 | * as serial console interface. |
| 31 | */ |
| 32 | |
| 33 | #include <common.h> |
| 34 | #include <mpc8260.h> |
| 35 | #include <asm/cpm_8260.h> |
Marek Vasut | 18a4779 | 2012-09-13 01:34:16 +0200 | [diff] [blame] | 36 | #include <serial.h> |
| 37 | #include <linux/compiler.h> |
wdenk | 4a9cbbe | 2002-08-27 09:48:53 +0000 | [diff] [blame] | 38 | |
Wolfgang Denk | 6405a15 | 2006-03-31 18:32:53 +0200 | [diff] [blame] | 39 | DECLARE_GLOBAL_DATA_PTR; |
| 40 | |
wdenk | 4a9cbbe | 2002-08-27 09:48:53 +0000 | [diff] [blame] | 41 | #if defined(CONFIG_CONS_ON_SMC) |
| 42 | |
| 43 | #if CONFIG_CONS_INDEX == 1 /* Console on SMC1 */ |
| 44 | |
| 45 | #define SMC_INDEX 0 |
| 46 | #define PROFF_SMC_BASE PROFF_SMC1_BASE |
| 47 | #define PROFF_SMC PROFF_SMC1 |
| 48 | #define CPM_CR_SMC_PAGE CPM_CR_SMC1_PAGE |
| 49 | #define CPM_CR_SMC_SBLOCK CPM_CR_SMC1_SBLOCK |
| 50 | #define CMXSMR_MASK (CMXSMR_SMC1|CMXSMR_SMC1CS_MSK) |
| 51 | #define CMXSMR_VALUE CMXSMR_SMC1CS_BRG7 |
| 52 | |
| 53 | #elif CONFIG_CONS_INDEX == 2 /* Console on SMC2 */ |
| 54 | |
| 55 | #define SMC_INDEX 1 |
| 56 | #define PROFF_SMC_BASE PROFF_SMC2_BASE |
| 57 | #define PROFF_SMC PROFF_SMC2 |
| 58 | #define CPM_CR_SMC_PAGE CPM_CR_SMC2_PAGE |
| 59 | #define CPM_CR_SMC_SBLOCK CPM_CR_SMC2_SBLOCK |
| 60 | #define CMXSMR_MASK (CMXSMR_SMC2|CMXSMR_SMC2CS_MSK) |
| 61 | #define CMXSMR_VALUE CMXSMR_SMC2CS_BRG8 |
| 62 | |
| 63 | #else |
| 64 | |
| 65 | #error "console not correctly defined" |
| 66 | |
| 67 | #endif |
| 68 | |
Heiko Schocher | 327480a | 2009-01-30 12:55:38 +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 | 4a9cbbe | 2002-08-27 09:48:53 +0000 | [diff] [blame] | 86 | /* map rs_table index to baud rate generator index */ |
| 87 | static unsigned char brg_map[] = { |
| 88 | 6, /* BRG7 for SMC1 */ |
| 89 | 7, /* BRG8 for SMC2 */ |
| 90 | 0, /* BRG1 for SCC1 */ |
| 91 | 1, /* BRG1 for SCC2 */ |
| 92 | 2, /* BRG1 for SCC3 */ |
| 93 | 3, /* BRG1 for SCC4 */ |
| 94 | }; |
| 95 | |
Marek Vasut | 18a4779 | 2012-09-13 01:34:16 +0200 | [diff] [blame] | 96 | static int mpc8260_smc_serial_init(void) |
wdenk | 4a9cbbe | 2002-08-27 09:48:53 +0000 | [diff] [blame] | 97 | { |
Jean-Christophe PLAGNIOL-VILLARD | 0383694 | 2008-10-16 15:01:15 +0200 | [diff] [blame] | 98 | volatile immap_t *im = (immap_t *)CONFIG_SYS_IMMR; |
wdenk | 4a9cbbe | 2002-08-27 09:48:53 +0000 | [diff] [blame] | 99 | volatile smc_t *sp; |
| 100 | volatile smc_uart_t *up; |
wdenk | 4a9cbbe | 2002-08-27 09:48:53 +0000 | [diff] [blame] | 101 | volatile cpm8260_t *cp = &(im->im_cpm); |
| 102 | uint dpaddr; |
Heiko Schocher | 327480a | 2009-01-30 12:55:38 +0100 | [diff] [blame] | 103 | volatile serialbuffer_t *rtx; |
wdenk | 4a9cbbe | 2002-08-27 09:48:53 +0000 | [diff] [blame] | 104 | |
| 105 | /* initialize pointers to SMC */ |
| 106 | |
| 107 | sp = (smc_t *) &(im->im_smc[SMC_INDEX]); |
| 108 | *(ushort *)(&im->im_dprambase[PROFF_SMC_BASE]) = PROFF_SMC; |
| 109 | up = (smc_uart_t *)&im->im_dprambase[PROFF_SMC]; |
| 110 | |
Heiko Schocher | e1873ba | 2009-01-30 12:56:15 +0100 | [diff] [blame] | 111 | /* Disable transmitter/receiver. */ |
wdenk | 4a9cbbe | 2002-08-27 09:48:53 +0000 | [diff] [blame] | 112 | sp->smc_smcmr &= ~(SMCMR_REN | SMCMR_TEN); |
| 113 | |
| 114 | /* NOTE: I/O port pins are set up via the iop_conf_tab[] table */ |
| 115 | |
| 116 | /* Allocate space for two buffer descriptors in the DP ram. |
| 117 | * damm: allocating space after the two buffers for rx/tx data |
| 118 | */ |
Heiko Schocher | 327480a | 2009-01-30 12:55:38 +0100 | [diff] [blame] | 119 | |
| 120 | /* allocate size of struct serialbuffer with bd rx/tx, |
| 121 | * buffer rx/tx and rx index |
| 122 | */ |
| 123 | dpaddr = m8260_cpm_dpalloc((sizeof(serialbuffer_t)), 16); |
wdenk | 4a9cbbe | 2002-08-27 09:48:53 +0000 | [diff] [blame] | 124 | |
Heiko Schocher | 327480a | 2009-01-30 12:55:38 +0100 | [diff] [blame] | 125 | rtx = (serialbuffer_t *)&im->im_dprambase[dpaddr]; |
wdenk | 4a9cbbe | 2002-08-27 09:48:53 +0000 | [diff] [blame] | 126 | |
| 127 | /* Set the physical address of the host memory buffers in |
| 128 | * the buffer descriptors. |
| 129 | */ |
Heiko Schocher | 327480a | 2009-01-30 12:55:38 +0100 | [diff] [blame] | 130 | rtx->rxbd.cbd_bufaddr = (uint) &rtx->rxbuf; |
| 131 | rtx->rxbd.cbd_sc = 0; |
| 132 | |
| 133 | rtx->txbd.cbd_bufaddr = (uint) &rtx->txbuf; |
| 134 | rtx->txbd.cbd_sc = 0; |
wdenk | 4a9cbbe | 2002-08-27 09:48:53 +0000 | [diff] [blame] | 135 | |
Heiko Schocher | e1873ba | 2009-01-30 12:56:15 +0100 | [diff] [blame] | 136 | /* Set up the uart parameters in the parameter ram. */ |
wdenk | 4a9cbbe | 2002-08-27 09:48:53 +0000 | [diff] [blame] | 137 | up->smc_rbase = dpaddr; |
| 138 | up->smc_tbase = dpaddr+sizeof(cbd_t); |
| 139 | up->smc_rfcr = CPMFCR_EB; |
| 140 | up->smc_tfcr = CPMFCR_EB; |
| 141 | up->smc_brklen = 0; |
| 142 | up->smc_brkec = 0; |
| 143 | up->smc_brkcr = 0; |
| 144 | |
| 145 | /* Set UART mode, 8 bit, no parity, one stop. |
| 146 | * Enable receive and transmit. |
| 147 | */ |
| 148 | sp->smc_smcmr = smcr_mk_clen(9) | SMCMR_SM_UART; |
| 149 | |
Heiko Schocher | e1873ba | 2009-01-30 12:56:15 +0100 | [diff] [blame] | 150 | /* Mask all interrupts and remove anything pending. */ |
wdenk | 4a9cbbe | 2002-08-27 09:48:53 +0000 | [diff] [blame] | 151 | sp->smc_smcm = 0; |
| 152 | sp->smc_smce = 0xff; |
| 153 | |
| 154 | /* put the SMC channel into NMSI (non multiplexd serial interface) |
| 155 | * mode and wire either BRG7 to SMC1 or BRG8 to SMC2 (15-17). |
| 156 | */ |
| 157 | im->im_cpmux.cmx_smr = (im->im_cpmux.cmx_smr&~CMXSMR_MASK)|CMXSMR_VALUE; |
| 158 | |
Heiko Schocher | e1873ba | 2009-01-30 12:56:15 +0100 | [diff] [blame] | 159 | /* Set up the baud rate generator. */ |
wdenk | 4a9cbbe | 2002-08-27 09:48:53 +0000 | [diff] [blame] | 160 | serial_setbrg (); |
| 161 | |
Heiko Schocher | e1873ba | 2009-01-30 12:56:15 +0100 | [diff] [blame] | 162 | /* Make the first buffer the only buffer. */ |
Heiko Schocher | 327480a | 2009-01-30 12:55:38 +0100 | [diff] [blame] | 163 | rtx->txbd.cbd_sc |= BD_SC_WRAP; |
| 164 | rtx->rxbd.cbd_sc |= BD_SC_EMPTY | BD_SC_WRAP; |
wdenk | 4a9cbbe | 2002-08-27 09:48:53 +0000 | [diff] [blame] | 165 | |
Heiko Schocher | 327480a | 2009-01-30 12:55:38 +0100 | [diff] [blame] | 166 | /* single/multi character receive. */ |
| 167 | up->smc_mrblr = CONFIG_SYS_SMC_RXBUFLEN; |
| 168 | up->smc_maxidl = CONFIG_SYS_MAXIDLE; |
| 169 | rtx->rxindex = 0; |
wdenk | 4a9cbbe | 2002-08-27 09:48:53 +0000 | [diff] [blame] | 170 | |
Heiko Schocher | e1873ba | 2009-01-30 12:56:15 +0100 | [diff] [blame] | 171 | /* Initialize Tx/Rx parameters. */ |
wdenk | 4a9cbbe | 2002-08-27 09:48:53 +0000 | [diff] [blame] | 172 | |
| 173 | while (cp->cp_cpcr & CPM_CR_FLG) /* wait if cp is busy */ |
| 174 | ; |
| 175 | |
| 176 | cp->cp_cpcr = mk_cr_cmd(CPM_CR_SMC_PAGE, CPM_CR_SMC_SBLOCK, |
| 177 | 0, CPM_CR_INIT_TRX) | CPM_CR_FLG; |
| 178 | |
| 179 | while (cp->cp_cpcr & CPM_CR_FLG) /* wait if cp is busy */ |
| 180 | ; |
| 181 | |
Heiko Schocher | e1873ba | 2009-01-30 12:56:15 +0100 | [diff] [blame] | 182 | /* Enable transmitter/receiver. */ |
wdenk | 4a9cbbe | 2002-08-27 09:48:53 +0000 | [diff] [blame] | 183 | sp->smc_smcmr |= SMCMR_REN | SMCMR_TEN; |
| 184 | |
| 185 | return (0); |
| 186 | } |
| 187 | |
Marek Vasut | 18a4779 | 2012-09-13 01:34:16 +0200 | [diff] [blame] | 188 | static void mpc8260_smc_serial_setbrg(void) |
wdenk | 4a9cbbe | 2002-08-27 09:48:53 +0000 | [diff] [blame] | 189 | { |
wdenk | 4a9cbbe | 2002-08-27 09:48:53 +0000 | [diff] [blame] | 190 | #if defined(CONFIG_CONS_USE_EXTC) |
| 191 | m8260_cpm_extcbrg(brg_map[SMC_INDEX], gd->baudrate, |
| 192 | CONFIG_CONS_EXTC_RATE, CONFIG_CONS_EXTC_PINSEL); |
| 193 | #else |
| 194 | m8260_cpm_setbrg(brg_map[SMC_INDEX], gd->baudrate); |
| 195 | #endif |
| 196 | } |
| 197 | |
Marek Vasut | 18a4779 | 2012-09-13 01:34:16 +0200 | [diff] [blame] | 198 | static void mpc8260_smc_serial_putc(const char c) |
wdenk | 4a9cbbe | 2002-08-27 09:48:53 +0000 | [diff] [blame] | 199 | { |
wdenk | 4a9cbbe | 2002-08-27 09:48:53 +0000 | [diff] [blame] | 200 | volatile smc_uart_t *up; |
Jean-Christophe PLAGNIOL-VILLARD | 0383694 | 2008-10-16 15:01:15 +0200 | [diff] [blame] | 201 | volatile immap_t *im = (immap_t *)CONFIG_SYS_IMMR; |
Heiko Schocher | 327480a | 2009-01-30 12:55:38 +0100 | [diff] [blame] | 202 | volatile serialbuffer_t *rtx; |
wdenk | 4a9cbbe | 2002-08-27 09:48:53 +0000 | [diff] [blame] | 203 | |
| 204 | if (c == '\n') |
| 205 | serial_putc ('\r'); |
| 206 | |
| 207 | up = (smc_uart_t *)&(im->im_dprambase[PROFF_SMC]); |
| 208 | |
Heiko Schocher | 327480a | 2009-01-30 12:55:38 +0100 | [diff] [blame] | 209 | rtx = (serialbuffer_t *)&im->im_dprambase[up->smc_rbase]; |
wdenk | 4a9cbbe | 2002-08-27 09:48:53 +0000 | [diff] [blame] | 210 | |
Heiko Schocher | 327480a | 2009-01-30 12:55:38 +0100 | [diff] [blame] | 211 | /* Wait for last character to go. */ |
| 212 | while (rtx->txbd.cbd_sc & BD_SC_READY & BD_SC_READY) |
wdenk | 4a9cbbe | 2002-08-27 09:48:53 +0000 | [diff] [blame] | 213 | ; |
Heiko Schocher | 327480a | 2009-01-30 12:55:38 +0100 | [diff] [blame] | 214 | rtx->txbuf = c; |
| 215 | rtx->txbd.cbd_datlen = 1; |
| 216 | rtx->txbd.cbd_sc |= BD_SC_READY; |
wdenk | 4a9cbbe | 2002-08-27 09:48:53 +0000 | [diff] [blame] | 217 | } |
| 218 | |
Marek Vasut | 18a4779 | 2012-09-13 01:34:16 +0200 | [diff] [blame] | 219 | static int mpc8260_smc_serial_getc(void) |
wdenk | 4a9cbbe | 2002-08-27 09:48:53 +0000 | [diff] [blame] | 220 | { |
wdenk | 4a9cbbe | 2002-08-27 09:48:53 +0000 | [diff] [blame] | 221 | volatile smc_uart_t *up; |
Jean-Christophe PLAGNIOL-VILLARD | 0383694 | 2008-10-16 15:01:15 +0200 | [diff] [blame] | 222 | volatile immap_t *im = (immap_t *)CONFIG_SYS_IMMR; |
Heiko Schocher | 327480a | 2009-01-30 12:55:38 +0100 | [diff] [blame] | 223 | volatile serialbuffer_t *rtx; |
| 224 | unsigned char c; |
wdenk | 4a9cbbe | 2002-08-27 09:48:53 +0000 | [diff] [blame] | 225 | |
| 226 | up = (smc_uart_t *)&(im->im_dprambase[PROFF_SMC]); |
| 227 | |
Heiko Schocher | 327480a | 2009-01-30 12:55:38 +0100 | [diff] [blame] | 228 | rtx = (serialbuffer_t *)&im->im_dprambase[up->smc_rbase]; |
wdenk | 4a9cbbe | 2002-08-27 09:48:53 +0000 | [diff] [blame] | 229 | |
Heiko Schocher | e1873ba | 2009-01-30 12:56:15 +0100 | [diff] [blame] | 230 | /* Wait for character to show up. */ |
Heiko Schocher | 327480a | 2009-01-30 12:55:38 +0100 | [diff] [blame] | 231 | while (rtx->rxbd.cbd_sc & BD_SC_EMPTY) |
wdenk | 4a9cbbe | 2002-08-27 09:48:53 +0000 | [diff] [blame] | 232 | ; |
wdenk | 4a9cbbe | 2002-08-27 09:48:53 +0000 | [diff] [blame] | 233 | |
Heiko Schocher | 327480a | 2009-01-30 12:55:38 +0100 | [diff] [blame] | 234 | /* the characters are read one by one, |
| 235 | * use the rxindex to know the next char to deliver |
| 236 | */ |
| 237 | c = *(unsigned char *) (rtx->rxbd.cbd_bufaddr + rtx->rxindex); |
| 238 | rtx->rxindex++; |
| 239 | |
| 240 | /* check if all char are readout, then make prepare for next receive */ |
| 241 | if (rtx->rxindex >= rtx->rxbd.cbd_datlen) { |
| 242 | rtx->rxindex = 0; |
| 243 | rtx->rxbd.cbd_sc |= BD_SC_EMPTY; |
| 244 | } |
wdenk | 4a9cbbe | 2002-08-27 09:48:53 +0000 | [diff] [blame] | 245 | return(c); |
| 246 | } |
| 247 | |
Marek Vasut | 18a4779 | 2012-09-13 01:34:16 +0200 | [diff] [blame] | 248 | static int mpc8260_smc_serial_tstc(void) |
wdenk | 4a9cbbe | 2002-08-27 09:48:53 +0000 | [diff] [blame] | 249 | { |
wdenk | 4a9cbbe | 2002-08-27 09:48:53 +0000 | [diff] [blame] | 250 | volatile smc_uart_t *up; |
Jean-Christophe PLAGNIOL-VILLARD | 0383694 | 2008-10-16 15:01:15 +0200 | [diff] [blame] | 251 | volatile immap_t *im = (immap_t *)CONFIG_SYS_IMMR; |
Heiko Schocher | 327480a | 2009-01-30 12:55:38 +0100 | [diff] [blame] | 252 | volatile serialbuffer_t *rtx; |
wdenk | 4a9cbbe | 2002-08-27 09:48:53 +0000 | [diff] [blame] | 253 | |
| 254 | up = (smc_uart_t *)&(im->im_dprambase[PROFF_SMC]); |
Heiko Schocher | 327480a | 2009-01-30 12:55:38 +0100 | [diff] [blame] | 255 | rtx = (serialbuffer_t *)&im->im_dprambase[up->smc_rbase]; |
wdenk | 4a9cbbe | 2002-08-27 09:48:53 +0000 | [diff] [blame] | 256 | |
Heiko Schocher | 327480a | 2009-01-30 12:55:38 +0100 | [diff] [blame] | 257 | return !(rtx->rxbd.cbd_sc & BD_SC_EMPTY); |
wdenk | 4a9cbbe | 2002-08-27 09:48:53 +0000 | [diff] [blame] | 258 | } |
| 259 | |
Marek Vasut | 18a4779 | 2012-09-13 01:34:16 +0200 | [diff] [blame] | 260 | static struct serial_device mpc8260_smc_serial_drv = { |
| 261 | .name = "mpc8260_smc_uart", |
| 262 | .start = mpc8260_smc_serial_init, |
| 263 | .stop = NULL, |
| 264 | .setbrg = mpc8260_smc_serial_setbrg, |
| 265 | .putc = mpc8260_smc_serial_putc, |
Marek Vasut | d9c6449 | 2012-10-06 14:07:02 +0000 | [diff] [blame] | 266 | .puts = default_serial_puts, |
Marek Vasut | 18a4779 | 2012-09-13 01:34:16 +0200 | [diff] [blame] | 267 | .getc = mpc8260_smc_serial_getc, |
| 268 | .tstc = mpc8260_smc_serial_tstc, |
| 269 | }; |
| 270 | |
| 271 | void mpc8260_smc_serial_initialize(void) |
| 272 | { |
| 273 | serial_register(&mpc8260_smc_serial_drv); |
| 274 | } |
| 275 | |
| 276 | __weak struct serial_device *default_serial_console(void) |
| 277 | { |
| 278 | return &mpc8260_smc_serial_drv; |
| 279 | } |
wdenk | 4a9cbbe | 2002-08-27 09:48:53 +0000 | [diff] [blame] | 280 | #endif /* CONFIG_CONS_ON_SMC */ |
| 281 | |
| 282 | #if defined(CONFIG_KGDB_ON_SMC) |
| 283 | |
| 284 | #if defined(CONFIG_CONS_ON_SMC) && CONFIG_KGDB_INDEX == CONFIG_CONS_INDEX |
| 285 | #error Whoops! serial console and kgdb are on the same smc serial port |
| 286 | #endif |
| 287 | |
| 288 | #if CONFIG_KGDB_INDEX == 1 /* KGDB Port on SMC1 */ |
| 289 | |
| 290 | #define KGDB_SMC_INDEX 0 |
| 291 | #define KGDB_PROFF_SMC_BASE PROFF_SMC1_BASE |
| 292 | #define KGDB_PROFF_SMC PROFF_SMC1 |
| 293 | #define KGDB_CPM_CR_SMC_PAGE CPM_CR_SMC1_PAGE |
| 294 | #define KGDB_CPM_CR_SMC_SBLOCK CPM_CR_SMC1_SBLOCK |
| 295 | #define KGDB_CMXSMR_MASK (CMXSMR_SMC1|CMXSMR_SMC1CS_MSK) |
| 296 | #define KGDB_CMXSMR_VALUE CMXSMR_SMC1CS_BRG7 |
| 297 | |
| 298 | #elif CONFIG_KGDB_INDEX == 2 /* KGDB Port on SMC2 */ |
| 299 | |
| 300 | #define KGDB_SMC_INDEX 1 |
| 301 | #define KGDB_PROFF_SMC_BASE PROFF_SMC2_BASE |
| 302 | #define KGDB_PROFF_SMC PROFF_SMC2 |
| 303 | #define KGDB_CPM_CR_SMC_PAGE CPM_CR_SMC2_PAGE |
| 304 | #define KGDB_CPM_CR_SMC_SBLOCK CPM_CR_SMC2_SBLOCK |
| 305 | #define KGDB_CMXSMR_MASK (CMXSMR_SMC2|CMXSMR_SMC2CS_MSK) |
| 306 | #define KGDB_CMXSMR_VALUE CMXSMR_SMC2CS_BRG8 |
| 307 | |
| 308 | #else |
| 309 | |
| 310 | #error "console not correctly defined" |
| 311 | |
| 312 | #endif |
| 313 | |
| 314 | void |
| 315 | kgdb_serial_init (void) |
| 316 | { |
Jean-Christophe PLAGNIOL-VILLARD | 0383694 | 2008-10-16 15:01:15 +0200 | [diff] [blame] | 317 | volatile immap_t *im = (immap_t *)CONFIG_SYS_IMMR; |
wdenk | 4a9cbbe | 2002-08-27 09:48:53 +0000 | [diff] [blame] | 318 | volatile smc_t *sp; |
| 319 | volatile smc_uart_t *up; |
| 320 | volatile cbd_t *tbdf, *rbdf; |
| 321 | volatile cpm8260_t *cp = &(im->im_cpm); |
| 322 | uint dpaddr, speed = CONFIG_KGDB_BAUDRATE; |
| 323 | char *s, *e; |
| 324 | |
| 325 | if ((s = getenv("kgdbrate")) != NULL && *s != '\0') { |
| 326 | ulong rate = simple_strtoul(s, &e, 10); |
| 327 | if (e > s && *e == '\0') |
| 328 | speed = rate; |
| 329 | } |
| 330 | |
| 331 | /* initialize pointers to SMC */ |
| 332 | |
| 333 | sp = (smc_t *) &(im->im_smc[KGDB_SMC_INDEX]); |
| 334 | *(ushort *)(&im->im_dprambase[KGDB_PROFF_SMC_BASE]) = KGDB_PROFF_SMC; |
| 335 | up = (smc_uart_t *)&im->im_dprambase[KGDB_PROFF_SMC]; |
| 336 | |
Heiko Schocher | e1873ba | 2009-01-30 12:56:15 +0100 | [diff] [blame] | 337 | /* Disable transmitter/receiver. */ |
wdenk | 4a9cbbe | 2002-08-27 09:48:53 +0000 | [diff] [blame] | 338 | sp->smc_smcmr &= ~(SMCMR_REN | SMCMR_TEN); |
| 339 | |
| 340 | /* NOTE: I/O port pins are set up via the iop_conf_tab[] table */ |
| 341 | |
| 342 | /* Allocate space for two buffer descriptors in the DP ram. |
| 343 | * damm: allocating space after the two buffers for rx/tx data |
| 344 | */ |
| 345 | |
| 346 | dpaddr = m8260_cpm_dpalloc((2 * sizeof (cbd_t)) + 2, 16); |
| 347 | |
| 348 | /* Set the physical address of the host memory buffers in |
| 349 | * the buffer descriptors. |
| 350 | */ |
| 351 | rbdf = (cbd_t *)&im->im_dprambase[dpaddr]; |
| 352 | rbdf->cbd_bufaddr = (uint) (rbdf+2); |
| 353 | rbdf->cbd_sc = 0; |
| 354 | tbdf = rbdf + 1; |
| 355 | tbdf->cbd_bufaddr = ((uint) (rbdf+2)) + 1; |
| 356 | tbdf->cbd_sc = 0; |
| 357 | |
Heiko Schocher | e1873ba | 2009-01-30 12:56:15 +0100 | [diff] [blame] | 358 | /* Set up the uart parameters in the parameter ram. */ |
wdenk | 4a9cbbe | 2002-08-27 09:48:53 +0000 | [diff] [blame] | 359 | up->smc_rbase = dpaddr; |
| 360 | up->smc_tbase = dpaddr+sizeof(cbd_t); |
| 361 | up->smc_rfcr = CPMFCR_EB; |
| 362 | up->smc_tfcr = CPMFCR_EB; |
| 363 | up->smc_brklen = 0; |
| 364 | up->smc_brkec = 0; |
| 365 | up->smc_brkcr = 0; |
| 366 | |
| 367 | /* Set UART mode, 8 bit, no parity, one stop. |
| 368 | * Enable receive and transmit. |
| 369 | */ |
| 370 | sp->smc_smcmr = smcr_mk_clen(9) | SMCMR_SM_UART; |
| 371 | |
Heiko Schocher | e1873ba | 2009-01-30 12:56:15 +0100 | [diff] [blame] | 372 | /* Mask all interrupts and remove anything pending. */ |
wdenk | 4a9cbbe | 2002-08-27 09:48:53 +0000 | [diff] [blame] | 373 | sp->smc_smcm = 0; |
| 374 | sp->smc_smce = 0xff; |
| 375 | |
| 376 | /* put the SMC channel into NMSI (non multiplexd serial interface) |
| 377 | * mode and wire either BRG7 to SMC1 or BRG8 to SMC2 (15-17). |
| 378 | */ |
| 379 | im->im_cpmux.cmx_smr = |
| 380 | (im->im_cpmux.cmx_smr & ~KGDB_CMXSMR_MASK) | KGDB_CMXSMR_VALUE; |
| 381 | |
Heiko Schocher | e1873ba | 2009-01-30 12:56:15 +0100 | [diff] [blame] | 382 | /* Set up the baud rate generator. */ |
wdenk | 4a9cbbe | 2002-08-27 09:48:53 +0000 | [diff] [blame] | 383 | #if defined(CONFIG_KGDB_USE_EXTC) |
Wolfgang Denk | aaa8595 | 2005-08-06 01:21:19 +0200 | [diff] [blame] | 384 | m8260_cpm_extcbrg(brg_map[KGDB_SMC_INDEX], speed, |
wdenk | 4a9cbbe | 2002-08-27 09:48:53 +0000 | [diff] [blame] | 385 | CONFIG_KGDB_EXTC_RATE, CONFIG_KGDB_EXTC_PINSEL); |
| 386 | #else |
Wolfgang Denk | aaa8595 | 2005-08-06 01:21:19 +0200 | [diff] [blame] | 387 | m8260_cpm_setbrg(brg_map[KGDB_SMC_INDEX], speed); |
wdenk | 4a9cbbe | 2002-08-27 09:48:53 +0000 | [diff] [blame] | 388 | #endif |
| 389 | |
Heiko Schocher | e1873ba | 2009-01-30 12:56:15 +0100 | [diff] [blame] | 390 | /* Make the first buffer the only buffer. */ |
wdenk | 4a9cbbe | 2002-08-27 09:48:53 +0000 | [diff] [blame] | 391 | tbdf->cbd_sc |= BD_SC_WRAP; |
| 392 | rbdf->cbd_sc |= BD_SC_EMPTY | BD_SC_WRAP; |
| 393 | |
Heiko Schocher | e1873ba | 2009-01-30 12:56:15 +0100 | [diff] [blame] | 394 | /* Single character receive. */ |
wdenk | 4a9cbbe | 2002-08-27 09:48:53 +0000 | [diff] [blame] | 395 | up->smc_mrblr = 1; |
| 396 | up->smc_maxidl = 0; |
| 397 | |
Heiko Schocher | e1873ba | 2009-01-30 12:56:15 +0100 | [diff] [blame] | 398 | /* Initialize Tx/Rx parameters. */ |
wdenk | 4a9cbbe | 2002-08-27 09:48:53 +0000 | [diff] [blame] | 399 | |
| 400 | while (cp->cp_cpcr & CPM_CR_FLG) /* wait if cp is busy */ |
| 401 | ; |
| 402 | |
| 403 | cp->cp_cpcr = mk_cr_cmd(KGDB_CPM_CR_SMC_PAGE, KGDB_CPM_CR_SMC_SBLOCK, |
| 404 | 0, CPM_CR_INIT_TRX) | CPM_CR_FLG; |
| 405 | |
| 406 | while (cp->cp_cpcr & CPM_CR_FLG) /* wait if cp is busy */ |
| 407 | ; |
| 408 | |
Heiko Schocher | e1873ba | 2009-01-30 12:56:15 +0100 | [diff] [blame] | 409 | /* Enable transmitter/receiver. */ |
wdenk | 4a9cbbe | 2002-08-27 09:48:53 +0000 | [diff] [blame] | 410 | sp->smc_smcmr |= SMCMR_REN | SMCMR_TEN; |
| 411 | |
| 412 | printf("SMC%d at %dbps ", CONFIG_KGDB_INDEX, speed); |
| 413 | } |
| 414 | |
| 415 | void |
| 416 | putDebugChar(const char c) |
| 417 | { |
| 418 | volatile cbd_t *tbdf; |
| 419 | volatile char *buf; |
| 420 | volatile smc_uart_t *up; |
Jean-Christophe PLAGNIOL-VILLARD | 0383694 | 2008-10-16 15:01:15 +0200 | [diff] [blame] | 421 | volatile immap_t *im = (immap_t *)CONFIG_SYS_IMMR; |
wdenk | 4a9cbbe | 2002-08-27 09:48:53 +0000 | [diff] [blame] | 422 | |
| 423 | if (c == '\n') |
| 424 | putDebugChar ('\r'); |
| 425 | |
| 426 | up = (smc_uart_t *)&(im->im_dprambase[KGDB_PROFF_SMC]); |
| 427 | |
| 428 | tbdf = (cbd_t *)&im->im_dprambase[up->smc_tbase]; |
| 429 | |
Heiko Schocher | e1873ba | 2009-01-30 12:56:15 +0100 | [diff] [blame] | 430 | /* Wait for last character to go. */ |
wdenk | 4a9cbbe | 2002-08-27 09:48:53 +0000 | [diff] [blame] | 431 | buf = (char *)tbdf->cbd_bufaddr; |
| 432 | while (tbdf->cbd_sc & BD_SC_READY) |
| 433 | ; |
| 434 | |
| 435 | *buf = c; |
| 436 | tbdf->cbd_datlen = 1; |
| 437 | tbdf->cbd_sc |= BD_SC_READY; |
| 438 | } |
| 439 | |
| 440 | void |
| 441 | putDebugStr (const char *s) |
| 442 | { |
| 443 | while (*s) { |
| 444 | putDebugChar (*s++); |
| 445 | } |
| 446 | } |
| 447 | |
| 448 | int |
| 449 | getDebugChar(void) |
| 450 | { |
| 451 | volatile cbd_t *rbdf; |
| 452 | volatile unsigned char *buf; |
| 453 | volatile smc_uart_t *up; |
Jean-Christophe PLAGNIOL-VILLARD | 0383694 | 2008-10-16 15:01:15 +0200 | [diff] [blame] | 454 | volatile immap_t *im = (immap_t *)CONFIG_SYS_IMMR; |
wdenk | 4a9cbbe | 2002-08-27 09:48:53 +0000 | [diff] [blame] | 455 | unsigned char c; |
| 456 | |
| 457 | up = (smc_uart_t *)&(im->im_dprambase[KGDB_PROFF_SMC]); |
| 458 | |
| 459 | rbdf = (cbd_t *)&im->im_dprambase[up->smc_rbase]; |
| 460 | |
Heiko Schocher | e1873ba | 2009-01-30 12:56:15 +0100 | [diff] [blame] | 461 | /* Wait for character to show up. */ |
wdenk | 4a9cbbe | 2002-08-27 09:48:53 +0000 | [diff] [blame] | 462 | buf = (unsigned char *)rbdf->cbd_bufaddr; |
| 463 | while (rbdf->cbd_sc & BD_SC_EMPTY) |
| 464 | ; |
| 465 | c = *buf; |
| 466 | rbdf->cbd_sc |= BD_SC_EMPTY; |
| 467 | |
| 468 | return(c); |
| 469 | } |
| 470 | |
| 471 | void |
| 472 | kgdb_interruptible(int yes) |
| 473 | { |
| 474 | return; |
| 475 | } |
| 476 | |
| 477 | #endif /* CONFIG_KGDB_ON_SMC */ |