Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1 | /* |
| 2 | * linux/drivers/serial/cpm_uart.c |
| 3 | * |
| 4 | * Driver for CPM (SCC/SMC) serial ports; core driver |
| 5 | * |
| 6 | * Based on arch/ppc/cpm2_io/uart.c by Dan Malek |
| 7 | * Based on ppc8xx.c by Thomas Gleixner |
| 8 | * Based on drivers/serial/amba.c by Russell King |
| 9 | * |
Kumar Gala | 4c8d3d9 | 2005-11-13 16:06:30 -0800 | [diff] [blame] | 10 | * Maintainer: Kumar Gala (galak@kernel.crashing.org) (CPM2) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 11 | * Pantelis Antoniou (panto@intracom.gr) (CPM1) |
Kumar Gala | 311c462 | 2005-08-09 10:08:00 -0700 | [diff] [blame] | 12 | * |
Scott Wood | 7ae8703 | 2007-07-17 17:59:06 -0500 | [diff] [blame] | 13 | * Copyright (C) 2004, 2007 Freescale Semiconductor, Inc. |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 14 | * (C) 2004 Intracom, S.A. |
Vitaly Bordug | 6e197696 | 2006-04-29 23:06:00 +0400 | [diff] [blame] | 15 | * (C) 2005-2006 MontaVista Software, Inc. |
Kumar Gala | 0d84406 | 2008-06-12 07:53:48 -0500 | [diff] [blame] | 16 | * Vitaly Bordug <vbordug@ru.mvista.com> |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 17 | * |
| 18 | * This program is free software; you can redistribute it and/or modify |
| 19 | * it under the terms of the GNU General Public License as published by |
| 20 | * the Free Software Foundation; either version 2 of the License, or |
| 21 | * (at your option) any later version. |
| 22 | * |
| 23 | * This program is distributed in the hope that it will be useful, |
| 24 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 25 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 26 | * GNU General Public License for more details. |
| 27 | * |
| 28 | * You should have received a copy of the GNU General Public License |
| 29 | * along with this program; if not, write to the Free Software |
| 30 | * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA |
| 31 | * |
| 32 | */ |
| 33 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 34 | #include <linux/module.h> |
| 35 | #include <linux/tty.h> |
| 36 | #include <linux/ioport.h> |
| 37 | #include <linux/init.h> |
| 38 | #include <linux/serial.h> |
| 39 | #include <linux/console.h> |
| 40 | #include <linux/sysrq.h> |
| 41 | #include <linux/device.h> |
| 42 | #include <linux/bootmem.h> |
| 43 | #include <linux/dma-mapping.h> |
Vitaly Bordug | e27987c | 2006-04-25 20:26:41 +0400 | [diff] [blame] | 44 | #include <linux/fs_uart_pd.h> |
Kumar Gala | 0b2a2e5 | 2008-06-12 08:05:09 -0500 | [diff] [blame^] | 45 | #include <linux/of_platform.h> |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 46 | |
| 47 | #include <asm/io.h> |
| 48 | #include <asm/irq.h> |
| 49 | #include <asm/delay.h> |
Vitaly Bordug | 3dd0dcb | 2006-09-21 17:27:15 +0400 | [diff] [blame] | 50 | #include <asm/fs_pd.h> |
Scott Wood | 7ae8703 | 2007-07-17 17:59:06 -0500 | [diff] [blame] | 51 | #include <asm/udbg.h> |
| 52 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 53 | #if defined(CONFIG_SERIAL_CPM_CONSOLE) && defined(CONFIG_MAGIC_SYSRQ) |
| 54 | #define SUPPORT_SYSRQ |
| 55 | #endif |
| 56 | |
| 57 | #include <linux/serial_core.h> |
| 58 | #include <linux/kernel.h> |
| 59 | |
| 60 | #include "cpm_uart.h" |
| 61 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 62 | |
| 63 | /**************************************************************/ |
| 64 | |
| 65 | static int cpm_uart_tx_pump(struct uart_port *port); |
| 66 | static void cpm_uart_init_smc(struct uart_cpm_port *pinfo); |
| 67 | static void cpm_uart_init_scc(struct uart_cpm_port *pinfo); |
| 68 | static void cpm_uart_initbd(struct uart_cpm_port *pinfo); |
| 69 | |
| 70 | /**************************************************************/ |
| 71 | |
| 72 | /* |
Kumar Gala | 311c462 | 2005-08-09 10:08:00 -0700 | [diff] [blame] | 73 | * Check, if transmit buffers are processed |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 74 | */ |
| 75 | static unsigned int cpm_uart_tx_empty(struct uart_port *port) |
| 76 | { |
| 77 | struct uart_cpm_port *pinfo = (struct uart_cpm_port *)port; |
Scott Wood | c1dcfd9 | 2007-07-24 15:53:07 -0500 | [diff] [blame] | 78 | cbd_t __iomem *bdp = pinfo->tx_bd_base; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 79 | int ret = 0; |
| 80 | |
| 81 | while (1) { |
Scott Wood | c1dcfd9 | 2007-07-24 15:53:07 -0500 | [diff] [blame] | 82 | if (in_be16(&bdp->cbd_sc) & BD_SC_READY) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 83 | break; |
| 84 | |
Scott Wood | c1dcfd9 | 2007-07-24 15:53:07 -0500 | [diff] [blame] | 85 | if (in_be16(&bdp->cbd_sc) & BD_SC_WRAP) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 86 | ret = TIOCSER_TEMT; |
| 87 | break; |
| 88 | } |
| 89 | bdp++; |
| 90 | } |
| 91 | |
| 92 | pr_debug("CPM uart[%d]:tx_empty: %d\n", port->line, ret); |
| 93 | |
| 94 | return ret; |
| 95 | } |
| 96 | |
| 97 | static void cpm_uart_set_mctrl(struct uart_port *port, unsigned int mctrl) |
| 98 | { |
| 99 | /* Whee. Do nothing. */ |
| 100 | } |
| 101 | |
| 102 | static unsigned int cpm_uart_get_mctrl(struct uart_port *port) |
| 103 | { |
| 104 | /* Whee. Do nothing. */ |
| 105 | return TIOCM_CAR | TIOCM_DSR | TIOCM_CTS; |
| 106 | } |
| 107 | |
| 108 | /* |
| 109 | * Stop transmitter |
| 110 | */ |
Russell King | b129a8c | 2005-08-31 10:12:14 +0100 | [diff] [blame] | 111 | static void cpm_uart_stop_tx(struct uart_port *port) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 112 | { |
| 113 | struct uart_cpm_port *pinfo = (struct uart_cpm_port *)port; |
Scott Wood | c1dcfd9 | 2007-07-24 15:53:07 -0500 | [diff] [blame] | 114 | smc_t __iomem *smcp = pinfo->smcp; |
| 115 | scc_t __iomem *sccp = pinfo->sccp; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 116 | |
| 117 | pr_debug("CPM uart[%d]:stop tx\n", port->line); |
| 118 | |
| 119 | if (IS_SMC(pinfo)) |
Scott Wood | c1dcfd9 | 2007-07-24 15:53:07 -0500 | [diff] [blame] | 120 | clrbits8(&smcp->smc_smcm, SMCM_TX); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 121 | else |
Scott Wood | c1dcfd9 | 2007-07-24 15:53:07 -0500 | [diff] [blame] | 122 | clrbits16(&sccp->scc_sccm, UART_SCCM_TX); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 123 | } |
| 124 | |
| 125 | /* |
| 126 | * Start transmitter |
| 127 | */ |
Russell King | b129a8c | 2005-08-31 10:12:14 +0100 | [diff] [blame] | 128 | static void cpm_uart_start_tx(struct uart_port *port) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 129 | { |
| 130 | struct uart_cpm_port *pinfo = (struct uart_cpm_port *)port; |
Scott Wood | c1dcfd9 | 2007-07-24 15:53:07 -0500 | [diff] [blame] | 131 | smc_t __iomem *smcp = pinfo->smcp; |
| 132 | scc_t __iomem *sccp = pinfo->sccp; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 133 | |
| 134 | pr_debug("CPM uart[%d]:start tx\n", port->line); |
| 135 | |
| 136 | if (IS_SMC(pinfo)) { |
Scott Wood | c1dcfd9 | 2007-07-24 15:53:07 -0500 | [diff] [blame] | 137 | if (in_8(&smcp->smc_smcm) & SMCM_TX) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 138 | return; |
| 139 | } else { |
Scott Wood | c1dcfd9 | 2007-07-24 15:53:07 -0500 | [diff] [blame] | 140 | if (in_be16(&sccp->scc_sccm) & UART_SCCM_TX) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 141 | return; |
| 142 | } |
| 143 | |
| 144 | if (cpm_uart_tx_pump(port) != 0) { |
Kumar Gala | 311c462 | 2005-08-09 10:08:00 -0700 | [diff] [blame] | 145 | if (IS_SMC(pinfo)) { |
Scott Wood | c1dcfd9 | 2007-07-24 15:53:07 -0500 | [diff] [blame] | 146 | setbits8(&smcp->smc_smcm, SMCM_TX); |
Kumar Gala | 311c462 | 2005-08-09 10:08:00 -0700 | [diff] [blame] | 147 | } else { |
Scott Wood | c1dcfd9 | 2007-07-24 15:53:07 -0500 | [diff] [blame] | 148 | setbits16(&sccp->scc_sccm, UART_SCCM_TX); |
Kumar Gala | 311c462 | 2005-08-09 10:08:00 -0700 | [diff] [blame] | 149 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 150 | } |
| 151 | } |
| 152 | |
| 153 | /* |
Kumar Gala | 311c462 | 2005-08-09 10:08:00 -0700 | [diff] [blame] | 154 | * Stop receiver |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 155 | */ |
| 156 | static void cpm_uart_stop_rx(struct uart_port *port) |
| 157 | { |
| 158 | struct uart_cpm_port *pinfo = (struct uart_cpm_port *)port; |
Scott Wood | c1dcfd9 | 2007-07-24 15:53:07 -0500 | [diff] [blame] | 159 | smc_t __iomem *smcp = pinfo->smcp; |
| 160 | scc_t __iomem *sccp = pinfo->sccp; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 161 | |
| 162 | pr_debug("CPM uart[%d]:stop rx\n", port->line); |
| 163 | |
| 164 | if (IS_SMC(pinfo)) |
Scott Wood | c1dcfd9 | 2007-07-24 15:53:07 -0500 | [diff] [blame] | 165 | clrbits8(&smcp->smc_smcm, SMCM_RX); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 166 | else |
Scott Wood | c1dcfd9 | 2007-07-24 15:53:07 -0500 | [diff] [blame] | 167 | clrbits16(&sccp->scc_sccm, UART_SCCM_RX); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 168 | } |
| 169 | |
| 170 | /* |
| 171 | * Enable Modem status interrupts |
| 172 | */ |
| 173 | static void cpm_uart_enable_ms(struct uart_port *port) |
| 174 | { |
| 175 | pr_debug("CPM uart[%d]:enable ms\n", port->line); |
| 176 | } |
| 177 | |
| 178 | /* |
Kumar Gala | 311c462 | 2005-08-09 10:08:00 -0700 | [diff] [blame] | 179 | * Generate a break. |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 180 | */ |
| 181 | static void cpm_uart_break_ctl(struct uart_port *port, int break_state) |
| 182 | { |
| 183 | struct uart_cpm_port *pinfo = (struct uart_cpm_port *)port; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 184 | |
| 185 | pr_debug("CPM uart[%d]:break ctrl, break_state: %d\n", port->line, |
| 186 | break_state); |
| 187 | |
| 188 | if (break_state) |
Scott Wood | 7ae8703 | 2007-07-17 17:59:06 -0500 | [diff] [blame] | 189 | cpm_line_cr_cmd(pinfo, CPM_CR_STOP_TX); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 190 | else |
Scott Wood | 7ae8703 | 2007-07-17 17:59:06 -0500 | [diff] [blame] | 191 | cpm_line_cr_cmd(pinfo, CPM_CR_RESTART_TX); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 192 | } |
| 193 | |
| 194 | /* |
| 195 | * Transmit characters, refill buffer descriptor, if possible |
| 196 | */ |
David Howells | 7d12e78 | 2006-10-05 14:55:46 +0100 | [diff] [blame] | 197 | static void cpm_uart_int_tx(struct uart_port *port) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 198 | { |
| 199 | pr_debug("CPM uart[%d]:TX INT\n", port->line); |
| 200 | |
| 201 | cpm_uart_tx_pump(port); |
| 202 | } |
| 203 | |
| 204 | /* |
| 205 | * Receive characters |
| 206 | */ |
David Howells | 7d12e78 | 2006-10-05 14:55:46 +0100 | [diff] [blame] | 207 | static void cpm_uart_int_rx(struct uart_port *port) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 208 | { |
| 209 | int i; |
Scott Wood | c1dcfd9 | 2007-07-24 15:53:07 -0500 | [diff] [blame] | 210 | unsigned char ch; |
| 211 | u8 *cp; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 212 | struct tty_struct *tty = port->info->tty; |
| 213 | struct uart_cpm_port *pinfo = (struct uart_cpm_port *)port; |
Scott Wood | c1dcfd9 | 2007-07-24 15:53:07 -0500 | [diff] [blame] | 214 | cbd_t __iomem *bdp; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 215 | u16 status; |
| 216 | unsigned int flg; |
| 217 | |
| 218 | pr_debug("CPM uart[%d]:RX INT\n", port->line); |
| 219 | |
| 220 | /* Just loop through the closed BDs and copy the characters into |
| 221 | * the buffer. |
| 222 | */ |
| 223 | bdp = pinfo->rx_cur; |
| 224 | for (;;) { |
| 225 | /* get status */ |
Scott Wood | c1dcfd9 | 2007-07-24 15:53:07 -0500 | [diff] [blame] | 226 | status = in_be16(&bdp->cbd_sc); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 227 | /* If this one is empty, return happy */ |
| 228 | if (status & BD_SC_EMPTY) |
| 229 | break; |
| 230 | |
| 231 | /* get number of characters, and check spce in flip-buffer */ |
Scott Wood | c1dcfd9 | 2007-07-24 15:53:07 -0500 | [diff] [blame] | 232 | i = in_be16(&bdp->cbd_datlen); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 233 | |
Kumar Gala | 311c462 | 2005-08-09 10:08:00 -0700 | [diff] [blame] | 234 | /* If we have not enough room in tty flip buffer, then we try |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 235 | * later, which will be the next rx-interrupt or a timeout |
| 236 | */ |
Vitaly Bordug | 76a5543 | 2006-02-08 21:40:13 +0000 | [diff] [blame] | 237 | if(tty_buffer_request_room(tty, i) < i) { |
| 238 | printk(KERN_WARNING "No room in flip buffer\n"); |
| 239 | return; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 240 | } |
| 241 | |
| 242 | /* get pointer */ |
Scott Wood | c1dcfd9 | 2007-07-24 15:53:07 -0500 | [diff] [blame] | 243 | cp = cpm2cpu_addr(in_be32(&bdp->cbd_bufaddr), pinfo); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 244 | |
| 245 | /* loop through the buffer */ |
| 246 | while (i-- > 0) { |
| 247 | ch = *cp++; |
| 248 | port->icount.rx++; |
| 249 | flg = TTY_NORMAL; |
| 250 | |
| 251 | if (status & |
| 252 | (BD_SC_BR | BD_SC_FR | BD_SC_PR | BD_SC_OV)) |
| 253 | goto handle_error; |
David Howells | 7d12e78 | 2006-10-05 14:55:46 +0100 | [diff] [blame] | 254 | if (uart_handle_sysrq_char(port, ch)) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 255 | continue; |
| 256 | |
| 257 | error_return: |
Vitaly Bordug | 76a5543 | 2006-02-08 21:40:13 +0000 | [diff] [blame] | 258 | tty_insert_flip_char(tty, ch, flg); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 259 | |
| 260 | } /* End while (i--) */ |
| 261 | |
| 262 | /* This BD is ready to be used again. Clear status. get next */ |
Scott Wood | c1dcfd9 | 2007-07-24 15:53:07 -0500 | [diff] [blame] | 263 | clrbits16(&bdp->cbd_sc, BD_SC_BR | BD_SC_FR | BD_SC_PR | |
| 264 | BD_SC_OV | BD_SC_ID); |
| 265 | setbits16(&bdp->cbd_sc, BD_SC_EMPTY); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 266 | |
Scott Wood | c1dcfd9 | 2007-07-24 15:53:07 -0500 | [diff] [blame] | 267 | if (in_be16(&bdp->cbd_sc) & BD_SC_WRAP) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 268 | bdp = pinfo->rx_bd_base; |
| 269 | else |
| 270 | bdp++; |
Kumar Gala | 311c462 | 2005-08-09 10:08:00 -0700 | [diff] [blame] | 271 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 272 | } /* End for (;;) */ |
| 273 | |
| 274 | /* Write back buffer pointer */ |
Scott Wood | c1dcfd9 | 2007-07-24 15:53:07 -0500 | [diff] [blame] | 275 | pinfo->rx_cur = bdp; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 276 | |
| 277 | /* activate BH processing */ |
| 278 | tty_flip_buffer_push(tty); |
| 279 | |
| 280 | return; |
| 281 | |
| 282 | /* Error processing */ |
| 283 | |
| 284 | handle_error: |
| 285 | /* Statistics */ |
| 286 | if (status & BD_SC_BR) |
| 287 | port->icount.brk++; |
| 288 | if (status & BD_SC_PR) |
| 289 | port->icount.parity++; |
| 290 | if (status & BD_SC_FR) |
| 291 | port->icount.frame++; |
| 292 | if (status & BD_SC_OV) |
| 293 | port->icount.overrun++; |
| 294 | |
| 295 | /* Mask out ignored conditions */ |
| 296 | status &= port->read_status_mask; |
| 297 | |
| 298 | /* Handle the remaining ones */ |
| 299 | if (status & BD_SC_BR) |
| 300 | flg = TTY_BREAK; |
| 301 | else if (status & BD_SC_PR) |
| 302 | flg = TTY_PARITY; |
| 303 | else if (status & BD_SC_FR) |
| 304 | flg = TTY_FRAME; |
| 305 | |
| 306 | /* overrun does not affect the current character ! */ |
| 307 | if (status & BD_SC_OV) { |
| 308 | ch = 0; |
| 309 | flg = TTY_OVERRUN; |
| 310 | /* We skip this buffer */ |
| 311 | /* CHECK: Is really nothing senseful there */ |
| 312 | /* ASSUMPTION: it contains nothing valid */ |
| 313 | i = 0; |
| 314 | } |
| 315 | #ifdef SUPPORT_SYSRQ |
| 316 | port->sysrq = 0; |
| 317 | #endif |
| 318 | goto error_return; |
| 319 | } |
| 320 | |
| 321 | /* |
| 322 | * Asynchron mode interrupt handler |
| 323 | */ |
David Howells | 7d12e78 | 2006-10-05 14:55:46 +0100 | [diff] [blame] | 324 | static irqreturn_t cpm_uart_int(int irq, void *data) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 325 | { |
| 326 | u8 events; |
Jeff Garzik | 15aafa2 | 2008-02-06 01:36:20 -0800 | [diff] [blame] | 327 | struct uart_port *port = data; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 328 | struct uart_cpm_port *pinfo = (struct uart_cpm_port *)port; |
Scott Wood | c1dcfd9 | 2007-07-24 15:53:07 -0500 | [diff] [blame] | 329 | smc_t __iomem *smcp = pinfo->smcp; |
| 330 | scc_t __iomem *sccp = pinfo->sccp; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 331 | |
| 332 | pr_debug("CPM uart[%d]:IRQ\n", port->line); |
| 333 | |
| 334 | if (IS_SMC(pinfo)) { |
Scott Wood | c1dcfd9 | 2007-07-24 15:53:07 -0500 | [diff] [blame] | 335 | events = in_8(&smcp->smc_smce); |
| 336 | out_8(&smcp->smc_smce, events); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 337 | if (events & SMCM_BRKE) |
| 338 | uart_handle_break(port); |
| 339 | if (events & SMCM_RX) |
David Howells | 7d12e78 | 2006-10-05 14:55:46 +0100 | [diff] [blame] | 340 | cpm_uart_int_rx(port); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 341 | if (events & SMCM_TX) |
David Howells | 7d12e78 | 2006-10-05 14:55:46 +0100 | [diff] [blame] | 342 | cpm_uart_int_tx(port); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 343 | } else { |
Scott Wood | c1dcfd9 | 2007-07-24 15:53:07 -0500 | [diff] [blame] | 344 | events = in_be16(&sccp->scc_scce); |
| 345 | out_be16(&sccp->scc_scce, events); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 346 | if (events & UART_SCCM_BRKE) |
| 347 | uart_handle_break(port); |
| 348 | if (events & UART_SCCM_RX) |
David Howells | 7d12e78 | 2006-10-05 14:55:46 +0100 | [diff] [blame] | 349 | cpm_uart_int_rx(port); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 350 | if (events & UART_SCCM_TX) |
David Howells | 7d12e78 | 2006-10-05 14:55:46 +0100 | [diff] [blame] | 351 | cpm_uart_int_tx(port); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 352 | } |
| 353 | return (events) ? IRQ_HANDLED : IRQ_NONE; |
| 354 | } |
| 355 | |
| 356 | static int cpm_uart_startup(struct uart_port *port) |
| 357 | { |
| 358 | int retval; |
| 359 | struct uart_cpm_port *pinfo = (struct uart_cpm_port *)port; |
| 360 | |
| 361 | pr_debug("CPM uart[%d]:startup\n", port->line); |
| 362 | |
| 363 | /* Install interrupt handler. */ |
| 364 | retval = request_irq(port->irq, cpm_uart_int, 0, "cpm_uart", port); |
| 365 | if (retval) |
| 366 | return retval; |
| 367 | |
| 368 | /* Startup rx-int */ |
| 369 | if (IS_SMC(pinfo)) { |
Scott Wood | c1dcfd9 | 2007-07-24 15:53:07 -0500 | [diff] [blame] | 370 | setbits8(&pinfo->smcp->smc_smcm, SMCM_RX); |
| 371 | setbits16(&pinfo->smcp->smc_smcmr, (SMCMR_REN | SMCMR_TEN)); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 372 | } else { |
Scott Wood | c1dcfd9 | 2007-07-24 15:53:07 -0500 | [diff] [blame] | 373 | setbits16(&pinfo->sccp->scc_sccm, UART_SCCM_RX); |
| 374 | setbits32(&pinfo->sccp->scc_gsmrl, (SCC_GSMRL_ENR | SCC_GSMRL_ENT)); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 375 | } |
| 376 | |
Kumar Gala | 311c462 | 2005-08-09 10:08:00 -0700 | [diff] [blame] | 377 | if (!(pinfo->flags & FLAG_CONSOLE)) |
Scott Wood | 7ae8703 | 2007-07-17 17:59:06 -0500 | [diff] [blame] | 378 | cpm_line_cr_cmd(pinfo, CPM_CR_INIT_TRX); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 379 | return 0; |
| 380 | } |
| 381 | |
Kumar Gala | 311c462 | 2005-08-09 10:08:00 -0700 | [diff] [blame] | 382 | inline void cpm_uart_wait_until_send(struct uart_cpm_port *pinfo) |
| 383 | { |
Kumar Gala | 638861d | 2005-09-03 15:55:37 -0700 | [diff] [blame] | 384 | set_current_state(TASK_UNINTERRUPTIBLE); |
| 385 | schedule_timeout(pinfo->wait_closing); |
Kumar Gala | 311c462 | 2005-08-09 10:08:00 -0700 | [diff] [blame] | 386 | } |
| 387 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 388 | /* |
| 389 | * Shutdown the uart |
| 390 | */ |
| 391 | static void cpm_uart_shutdown(struct uart_port *port) |
| 392 | { |
| 393 | struct uart_cpm_port *pinfo = (struct uart_cpm_port *)port; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 394 | |
| 395 | pr_debug("CPM uart[%d]:shutdown\n", port->line); |
| 396 | |
| 397 | /* free interrupt handler */ |
| 398 | free_irq(port->irq, port); |
| 399 | |
| 400 | /* If the port is not the console, disable Rx and Tx. */ |
| 401 | if (!(pinfo->flags & FLAG_CONSOLE)) { |
Kumar Gala | 311c462 | 2005-08-09 10:08:00 -0700 | [diff] [blame] | 402 | /* Wait for all the BDs marked sent */ |
Kumar Gala | 638861d | 2005-09-03 15:55:37 -0700 | [diff] [blame] | 403 | while(!cpm_uart_tx_empty(port)) { |
| 404 | set_current_state(TASK_UNINTERRUPTIBLE); |
Kumar Gala | 311c462 | 2005-08-09 10:08:00 -0700 | [diff] [blame] | 405 | schedule_timeout(2); |
Kumar Gala | 638861d | 2005-09-03 15:55:37 -0700 | [diff] [blame] | 406 | } |
| 407 | |
| 408 | if (pinfo->wait_closing) |
Kumar Gala | 311c462 | 2005-08-09 10:08:00 -0700 | [diff] [blame] | 409 | cpm_uart_wait_until_send(pinfo); |
| 410 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 411 | /* Stop uarts */ |
| 412 | if (IS_SMC(pinfo)) { |
Scott Wood | c1dcfd9 | 2007-07-24 15:53:07 -0500 | [diff] [blame] | 413 | smc_t __iomem *smcp = pinfo->smcp; |
| 414 | clrbits16(&smcp->smc_smcmr, SMCMR_REN | SMCMR_TEN); |
| 415 | clrbits8(&smcp->smc_smcm, SMCM_RX | SMCM_TX); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 416 | } else { |
Scott Wood | c1dcfd9 | 2007-07-24 15:53:07 -0500 | [diff] [blame] | 417 | scc_t __iomem *sccp = pinfo->sccp; |
| 418 | clrbits32(&sccp->scc_gsmrl, SCC_GSMRL_ENR | SCC_GSMRL_ENT); |
| 419 | clrbits16(&sccp->scc_sccm, UART_SCCM_TX | UART_SCCM_RX); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 420 | } |
| 421 | |
| 422 | /* Shut them really down and reinit buffer descriptors */ |
Vitaly Bordug | 61f5657 | 2006-04-29 22:32:44 +0400 | [diff] [blame] | 423 | if (IS_SMC(pinfo)) |
Scott Wood | 7ae8703 | 2007-07-17 17:59:06 -0500 | [diff] [blame] | 424 | cpm_line_cr_cmd(pinfo, CPM_CR_STOP_TX); |
Vitaly Bordug | 61f5657 | 2006-04-29 22:32:44 +0400 | [diff] [blame] | 425 | else |
Scott Wood | 7ae8703 | 2007-07-17 17:59:06 -0500 | [diff] [blame] | 426 | cpm_line_cr_cmd(pinfo, CPM_CR_GRA_STOP_TX); |
Vitaly Bordug | 61f5657 | 2006-04-29 22:32:44 +0400 | [diff] [blame] | 427 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 428 | cpm_uart_initbd(pinfo); |
| 429 | } |
| 430 | } |
| 431 | |
| 432 | static void cpm_uart_set_termios(struct uart_port *port, |
Scott Wood | 1bda8f3 | 2007-05-08 12:19:21 -0500 | [diff] [blame] | 433 | struct ktermios *termios, |
| 434 | struct ktermios *old) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 435 | { |
| 436 | int baud; |
| 437 | unsigned long flags; |
| 438 | u16 cval, scval, prev_mode; |
| 439 | int bits, sbits; |
| 440 | struct uart_cpm_port *pinfo = (struct uart_cpm_port *)port; |
Scott Wood | c1dcfd9 | 2007-07-24 15:53:07 -0500 | [diff] [blame] | 441 | smc_t __iomem *smcp = pinfo->smcp; |
| 442 | scc_t __iomem *sccp = pinfo->sccp; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 443 | |
| 444 | pr_debug("CPM uart[%d]:set_termios\n", port->line); |
| 445 | |
| 446 | baud = uart_get_baud_rate(port, termios, old, 0, port->uartclk / 16); |
| 447 | |
| 448 | /* Character length programmed into the mode register is the |
| 449 | * sum of: 1 start bit, number of data bits, 0 or 1 parity bit, |
| 450 | * 1 or 2 stop bits, minus 1. |
| 451 | * The value 'bits' counts this for us. |
| 452 | */ |
| 453 | cval = 0; |
| 454 | scval = 0; |
| 455 | |
| 456 | /* byte size */ |
| 457 | switch (termios->c_cflag & CSIZE) { |
| 458 | case CS5: |
| 459 | bits = 5; |
| 460 | break; |
| 461 | case CS6: |
| 462 | bits = 6; |
| 463 | break; |
| 464 | case CS7: |
| 465 | bits = 7; |
| 466 | break; |
| 467 | case CS8: |
| 468 | bits = 8; |
| 469 | break; |
| 470 | /* Never happens, but GCC is too dumb to figure it out */ |
| 471 | default: |
| 472 | bits = 8; |
| 473 | break; |
| 474 | } |
| 475 | sbits = bits - 5; |
| 476 | |
| 477 | if (termios->c_cflag & CSTOPB) { |
| 478 | cval |= SMCMR_SL; /* Two stops */ |
| 479 | scval |= SCU_PSMR_SL; |
| 480 | bits++; |
| 481 | } |
| 482 | |
| 483 | if (termios->c_cflag & PARENB) { |
| 484 | cval |= SMCMR_PEN; |
| 485 | scval |= SCU_PSMR_PEN; |
| 486 | bits++; |
| 487 | if (!(termios->c_cflag & PARODD)) { |
| 488 | cval |= SMCMR_PM_EVEN; |
| 489 | scval |= (SCU_PSMR_REVP | SCU_PSMR_TEVP); |
| 490 | } |
| 491 | } |
| 492 | |
| 493 | /* |
| 494 | * Set up parity check flag |
| 495 | */ |
| 496 | #define RELEVANT_IFLAG(iflag) (iflag & (IGNBRK|BRKINT|IGNPAR|PARMRK|INPCK)) |
| 497 | |
| 498 | port->read_status_mask = (BD_SC_EMPTY | BD_SC_OV); |
| 499 | if (termios->c_iflag & INPCK) |
| 500 | port->read_status_mask |= BD_SC_FR | BD_SC_PR; |
| 501 | if ((termios->c_iflag & BRKINT) || (termios->c_iflag & PARMRK)) |
| 502 | port->read_status_mask |= BD_SC_BR; |
| 503 | |
| 504 | /* |
| 505 | * Characters to ignore |
| 506 | */ |
| 507 | port->ignore_status_mask = 0; |
| 508 | if (termios->c_iflag & IGNPAR) |
| 509 | port->ignore_status_mask |= BD_SC_PR | BD_SC_FR; |
| 510 | if (termios->c_iflag & IGNBRK) { |
| 511 | port->ignore_status_mask |= BD_SC_BR; |
| 512 | /* |
| 513 | * If we're ignore parity and break indicators, ignore |
| 514 | * overruns too. (For real raw support). |
| 515 | */ |
| 516 | if (termios->c_iflag & IGNPAR) |
| 517 | port->ignore_status_mask |= BD_SC_OV; |
| 518 | } |
| 519 | /* |
| 520 | * !!! ignore all characters if CREAD is not set |
| 521 | */ |
| 522 | if ((termios->c_cflag & CREAD) == 0) |
| 523 | port->read_status_mask &= ~BD_SC_EMPTY; |
Kumar Gala | 311c462 | 2005-08-09 10:08:00 -0700 | [diff] [blame] | 524 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 525 | spin_lock_irqsave(&port->lock, flags); |
| 526 | |
| 527 | /* Start bit has not been added (so don't, because we would just |
| 528 | * subtract it later), and we need to add one for the number of |
| 529 | * stops bits (there is always at least one). |
| 530 | */ |
| 531 | bits++; |
| 532 | if (IS_SMC(pinfo)) { |
| 533 | /* Set the mode register. We want to keep a copy of the |
| 534 | * enables, because we want to put them back if they were |
| 535 | * present. |
| 536 | */ |
Scott Wood | c1dcfd9 | 2007-07-24 15:53:07 -0500 | [diff] [blame] | 537 | prev_mode = in_be16(&smcp->smc_smcmr); |
| 538 | out_be16(&smcp->smc_smcmr, smcr_mk_clen(bits) | cval | SMCMR_SM_UART); |
| 539 | setbits16(&smcp->smc_smcmr, (prev_mode & (SMCMR_REN | SMCMR_TEN))); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 540 | } else { |
Scott Wood | c1dcfd9 | 2007-07-24 15:53:07 -0500 | [diff] [blame] | 541 | out_be16(&sccp->scc_psmr, (sbits << 12) | scval); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 542 | } |
| 543 | |
| 544 | cpm_set_brg(pinfo->brg - 1, baud); |
| 545 | spin_unlock_irqrestore(&port->lock, flags); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 546 | } |
| 547 | |
| 548 | static const char *cpm_uart_type(struct uart_port *port) |
| 549 | { |
| 550 | pr_debug("CPM uart[%d]:uart_type\n", port->line); |
| 551 | |
| 552 | return port->type == PORT_CPM ? "CPM UART" : NULL; |
| 553 | } |
| 554 | |
| 555 | /* |
| 556 | * verify the new serial_struct (for TIOCSSERIAL). |
| 557 | */ |
| 558 | static int cpm_uart_verify_port(struct uart_port *port, |
| 559 | struct serial_struct *ser) |
| 560 | { |
| 561 | int ret = 0; |
| 562 | |
| 563 | pr_debug("CPM uart[%d]:verify_port\n", port->line); |
| 564 | |
| 565 | if (ser->type != PORT_UNKNOWN && ser->type != PORT_CPM) |
| 566 | ret = -EINVAL; |
| 567 | if (ser->irq < 0 || ser->irq >= NR_IRQS) |
| 568 | ret = -EINVAL; |
| 569 | if (ser->baud_base < 9600) |
| 570 | ret = -EINVAL; |
| 571 | return ret; |
| 572 | } |
| 573 | |
| 574 | /* |
| 575 | * Transmit characters, refill buffer descriptor, if possible |
| 576 | */ |
| 577 | static int cpm_uart_tx_pump(struct uart_port *port) |
| 578 | { |
Scott Wood | c1dcfd9 | 2007-07-24 15:53:07 -0500 | [diff] [blame] | 579 | cbd_t __iomem *bdp; |
| 580 | u8 *p; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 581 | int count; |
| 582 | struct uart_cpm_port *pinfo = (struct uart_cpm_port *)port; |
| 583 | struct circ_buf *xmit = &port->info->xmit; |
| 584 | |
| 585 | /* Handle xon/xoff */ |
| 586 | if (port->x_char) { |
| 587 | /* Pick next descriptor and fill from buffer */ |
| 588 | bdp = pinfo->tx_cur; |
| 589 | |
Scott Wood | c1dcfd9 | 2007-07-24 15:53:07 -0500 | [diff] [blame] | 590 | p = cpm2cpu_addr(in_be32(&bdp->cbd_bufaddr), pinfo); |
Kumar Gala | 311c462 | 2005-08-09 10:08:00 -0700 | [diff] [blame] | 591 | |
Aristeu Sergio Rozanski Filho | 03929c7 | 2005-12-29 19:18:49 -0200 | [diff] [blame] | 592 | *p++ = port->x_char; |
Scott Wood | c1dcfd9 | 2007-07-24 15:53:07 -0500 | [diff] [blame] | 593 | |
| 594 | out_be16(&bdp->cbd_datlen, 1); |
| 595 | setbits16(&bdp->cbd_sc, BD_SC_READY); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 596 | /* Get next BD. */ |
Scott Wood | c1dcfd9 | 2007-07-24 15:53:07 -0500 | [diff] [blame] | 597 | if (in_be16(&bdp->cbd_sc) & BD_SC_WRAP) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 598 | bdp = pinfo->tx_bd_base; |
| 599 | else |
| 600 | bdp++; |
| 601 | pinfo->tx_cur = bdp; |
| 602 | |
| 603 | port->icount.tx++; |
| 604 | port->x_char = 0; |
| 605 | return 1; |
| 606 | } |
| 607 | |
| 608 | if (uart_circ_empty(xmit) || uart_tx_stopped(port)) { |
Russell King | b129a8c | 2005-08-31 10:12:14 +0100 | [diff] [blame] | 609 | cpm_uart_stop_tx(port); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 610 | return 0; |
| 611 | } |
| 612 | |
| 613 | /* Pick next descriptor and fill from buffer */ |
| 614 | bdp = pinfo->tx_cur; |
| 615 | |
Scott Wood | c1dcfd9 | 2007-07-24 15:53:07 -0500 | [diff] [blame] | 616 | while (!(in_be16(&bdp->cbd_sc) & BD_SC_READY) && |
| 617 | xmit->tail != xmit->head) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 618 | count = 0; |
Scott Wood | c1dcfd9 | 2007-07-24 15:53:07 -0500 | [diff] [blame] | 619 | p = cpm2cpu_addr(in_be32(&bdp->cbd_bufaddr), pinfo); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 620 | while (count < pinfo->tx_fifosize) { |
| 621 | *p++ = xmit->buf[xmit->tail]; |
| 622 | xmit->tail = (xmit->tail + 1) & (UART_XMIT_SIZE - 1); |
| 623 | port->icount.tx++; |
| 624 | count++; |
| 625 | if (xmit->head == xmit->tail) |
| 626 | break; |
| 627 | } |
Scott Wood | c1dcfd9 | 2007-07-24 15:53:07 -0500 | [diff] [blame] | 628 | out_be16(&bdp->cbd_datlen, count); |
| 629 | setbits16(&bdp->cbd_sc, BD_SC_READY); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 630 | /* Get next BD. */ |
Scott Wood | c1dcfd9 | 2007-07-24 15:53:07 -0500 | [diff] [blame] | 631 | if (in_be16(&bdp->cbd_sc) & BD_SC_WRAP) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 632 | bdp = pinfo->tx_bd_base; |
| 633 | else |
| 634 | bdp++; |
| 635 | } |
| 636 | pinfo->tx_cur = bdp; |
| 637 | |
| 638 | if (uart_circ_chars_pending(xmit) < WAKEUP_CHARS) |
| 639 | uart_write_wakeup(port); |
| 640 | |
| 641 | if (uart_circ_empty(xmit)) { |
Russell King | b129a8c | 2005-08-31 10:12:14 +0100 | [diff] [blame] | 642 | cpm_uart_stop_tx(port); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 643 | return 0; |
| 644 | } |
| 645 | |
| 646 | return 1; |
| 647 | } |
| 648 | |
| 649 | /* |
| 650 | * init buffer descriptors |
| 651 | */ |
| 652 | static void cpm_uart_initbd(struct uart_cpm_port *pinfo) |
| 653 | { |
| 654 | int i; |
| 655 | u8 *mem_addr; |
Scott Wood | c1dcfd9 | 2007-07-24 15:53:07 -0500 | [diff] [blame] | 656 | cbd_t __iomem *bdp; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 657 | |
| 658 | pr_debug("CPM uart[%d]:initbd\n", pinfo->port.line); |
| 659 | |
| 660 | /* Set the physical address of the host memory |
| 661 | * buffers in the buffer descriptors, and the |
| 662 | * virtual address for us to work with. |
| 663 | */ |
| 664 | mem_addr = pinfo->mem_addr; |
| 665 | bdp = pinfo->rx_cur = pinfo->rx_bd_base; |
| 666 | for (i = 0; i < (pinfo->rx_nrfifos - 1); i++, bdp++) { |
Scott Wood | c1dcfd9 | 2007-07-24 15:53:07 -0500 | [diff] [blame] | 667 | out_be32(&bdp->cbd_bufaddr, cpu2cpm_addr(mem_addr, pinfo)); |
| 668 | out_be16(&bdp->cbd_sc, BD_SC_EMPTY | BD_SC_INTRPT); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 669 | mem_addr += pinfo->rx_fifosize; |
| 670 | } |
Kumar Gala | 311c462 | 2005-08-09 10:08:00 -0700 | [diff] [blame] | 671 | |
Scott Wood | c1dcfd9 | 2007-07-24 15:53:07 -0500 | [diff] [blame] | 672 | out_be32(&bdp->cbd_bufaddr, cpu2cpm_addr(mem_addr, pinfo)); |
| 673 | out_be16(&bdp->cbd_sc, BD_SC_WRAP | BD_SC_EMPTY | BD_SC_INTRPT); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 674 | |
| 675 | /* Set the physical address of the host memory |
| 676 | * buffers in the buffer descriptors, and the |
| 677 | * virtual address for us to work with. |
| 678 | */ |
| 679 | mem_addr = pinfo->mem_addr + L1_CACHE_ALIGN(pinfo->rx_nrfifos * pinfo->rx_fifosize); |
| 680 | bdp = pinfo->tx_cur = pinfo->tx_bd_base; |
| 681 | for (i = 0; i < (pinfo->tx_nrfifos - 1); i++, bdp++) { |
Scott Wood | c1dcfd9 | 2007-07-24 15:53:07 -0500 | [diff] [blame] | 682 | out_be32(&bdp->cbd_bufaddr, cpu2cpm_addr(mem_addr, pinfo)); |
| 683 | out_be16(&bdp->cbd_sc, BD_SC_INTRPT); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 684 | mem_addr += pinfo->tx_fifosize; |
| 685 | } |
Kumar Gala | 311c462 | 2005-08-09 10:08:00 -0700 | [diff] [blame] | 686 | |
Scott Wood | c1dcfd9 | 2007-07-24 15:53:07 -0500 | [diff] [blame] | 687 | out_be32(&bdp->cbd_bufaddr, cpu2cpm_addr(mem_addr, pinfo)); |
| 688 | out_be16(&bdp->cbd_sc, BD_SC_WRAP | BD_SC_INTRPT); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 689 | } |
| 690 | |
| 691 | static void cpm_uart_init_scc(struct uart_cpm_port *pinfo) |
| 692 | { |
Scott Wood | c1dcfd9 | 2007-07-24 15:53:07 -0500 | [diff] [blame] | 693 | scc_t __iomem *scp; |
| 694 | scc_uart_t __iomem *sup; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 695 | |
| 696 | pr_debug("CPM uart[%d]:init_scc\n", pinfo->port.line); |
| 697 | |
| 698 | scp = pinfo->sccp; |
| 699 | sup = pinfo->sccup; |
| 700 | |
| 701 | /* Store address */ |
Scott Wood | c1dcfd9 | 2007-07-24 15:53:07 -0500 | [diff] [blame] | 702 | out_be16(&pinfo->sccup->scc_genscc.scc_rbase, |
| 703 | (u8 __iomem *)pinfo->rx_bd_base - DPRAM_BASE); |
| 704 | out_be16(&pinfo->sccup->scc_genscc.scc_tbase, |
| 705 | (u8 __iomem *)pinfo->tx_bd_base - DPRAM_BASE); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 706 | |
| 707 | /* Set up the uart parameters in the |
| 708 | * parameter ram. |
| 709 | */ |
| 710 | |
| 711 | cpm_set_scc_fcr(sup); |
| 712 | |
Scott Wood | c1dcfd9 | 2007-07-24 15:53:07 -0500 | [diff] [blame] | 713 | out_be16(&sup->scc_genscc.scc_mrblr, pinfo->rx_fifosize); |
| 714 | out_be16(&sup->scc_maxidl, pinfo->rx_fifosize); |
| 715 | out_be16(&sup->scc_brkcr, 1); |
| 716 | out_be16(&sup->scc_parec, 0); |
| 717 | out_be16(&sup->scc_frmec, 0); |
| 718 | out_be16(&sup->scc_nosec, 0); |
| 719 | out_be16(&sup->scc_brkec, 0); |
| 720 | out_be16(&sup->scc_uaddr1, 0); |
| 721 | out_be16(&sup->scc_uaddr2, 0); |
| 722 | out_be16(&sup->scc_toseq, 0); |
| 723 | out_be16(&sup->scc_char1, 0x8000); |
| 724 | out_be16(&sup->scc_char2, 0x8000); |
| 725 | out_be16(&sup->scc_char3, 0x8000); |
| 726 | out_be16(&sup->scc_char4, 0x8000); |
| 727 | out_be16(&sup->scc_char5, 0x8000); |
| 728 | out_be16(&sup->scc_char6, 0x8000); |
| 729 | out_be16(&sup->scc_char7, 0x8000); |
| 730 | out_be16(&sup->scc_char8, 0x8000); |
| 731 | out_be16(&sup->scc_rccm, 0xc0ff); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 732 | |
| 733 | /* Send the CPM an initialize command. |
| 734 | */ |
Scott Wood | 7ae8703 | 2007-07-17 17:59:06 -0500 | [diff] [blame] | 735 | cpm_line_cr_cmd(pinfo, CPM_CR_INIT_TRX); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 736 | |
| 737 | /* Set UART mode, 8 bit, no parity, one stop. |
| 738 | * Enable receive and transmit. |
| 739 | */ |
Scott Wood | c1dcfd9 | 2007-07-24 15:53:07 -0500 | [diff] [blame] | 740 | out_be32(&scp->scc_gsmrh, 0); |
| 741 | out_be32(&scp->scc_gsmrl, |
| 742 | SCC_GSMRL_MODE_UART | SCC_GSMRL_TDCR_16 | SCC_GSMRL_RDCR_16); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 743 | |
| 744 | /* Enable rx interrupts and clear all pending events. */ |
Scott Wood | c1dcfd9 | 2007-07-24 15:53:07 -0500 | [diff] [blame] | 745 | out_be16(&scp->scc_sccm, 0); |
| 746 | out_be16(&scp->scc_scce, 0xffff); |
| 747 | out_be16(&scp->scc_dsr, 0x7e7e); |
| 748 | out_be16(&scp->scc_psmr, 0x3000); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 749 | |
Scott Wood | c1dcfd9 | 2007-07-24 15:53:07 -0500 | [diff] [blame] | 750 | setbits32(&scp->scc_gsmrl, SCC_GSMRL_ENR | SCC_GSMRL_ENT); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 751 | } |
| 752 | |
| 753 | static void cpm_uart_init_smc(struct uart_cpm_port *pinfo) |
| 754 | { |
Scott Wood | c1dcfd9 | 2007-07-24 15:53:07 -0500 | [diff] [blame] | 755 | smc_t __iomem *sp; |
| 756 | smc_uart_t __iomem *up; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 757 | |
| 758 | pr_debug("CPM uart[%d]:init_smc\n", pinfo->port.line); |
| 759 | |
| 760 | sp = pinfo->smcp; |
| 761 | up = pinfo->smcup; |
| 762 | |
| 763 | /* Store address */ |
Scott Wood | c1dcfd9 | 2007-07-24 15:53:07 -0500 | [diff] [blame] | 764 | out_be16(&pinfo->smcup->smc_rbase, |
| 765 | (u8 __iomem *)pinfo->rx_bd_base - DPRAM_BASE); |
| 766 | out_be16(&pinfo->smcup->smc_tbase, |
| 767 | (u8 __iomem *)pinfo->tx_bd_base - DPRAM_BASE); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 768 | |
| 769 | /* |
| 770 | * In case SMC1 is being relocated... |
| 771 | */ |
| 772 | #if defined (CONFIG_I2C_SPI_SMC1_UCODE_PATCH) |
Scott Wood | c1dcfd9 | 2007-07-24 15:53:07 -0500 | [diff] [blame] | 773 | out_be16(&up->smc_rbptr, in_be16(&pinfo->smcup->smc_rbase)); |
| 774 | out_be16(&up->smc_tbptr, in_be16(&pinfo->smcup->smc_tbase)); |
| 775 | out_be32(&up->smc_rstate, 0); |
| 776 | out_be32(&up->smc_tstate, 0); |
| 777 | out_be16(&up->smc_brkcr, 1); /* number of break chars */ |
| 778 | out_be16(&up->smc_brkec, 0); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 779 | #endif |
| 780 | |
| 781 | /* Set up the uart parameters in the |
| 782 | * parameter ram. |
| 783 | */ |
| 784 | cpm_set_smc_fcr(up); |
| 785 | |
| 786 | /* Using idle charater time requires some additional tuning. */ |
Scott Wood | c1dcfd9 | 2007-07-24 15:53:07 -0500 | [diff] [blame] | 787 | out_be16(&up->smc_mrblr, pinfo->rx_fifosize); |
| 788 | out_be16(&up->smc_maxidl, pinfo->rx_fifosize); |
| 789 | out_be16(&up->smc_brklen, 0); |
| 790 | out_be16(&up->smc_brkec, 0); |
| 791 | out_be16(&up->smc_brkcr, 1); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 792 | |
Scott Wood | 7ae8703 | 2007-07-17 17:59:06 -0500 | [diff] [blame] | 793 | cpm_line_cr_cmd(pinfo, CPM_CR_INIT_TRX); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 794 | |
| 795 | /* Set UART mode, 8 bit, no parity, one stop. |
| 796 | * Enable receive and transmit. |
| 797 | */ |
Scott Wood | c1dcfd9 | 2007-07-24 15:53:07 -0500 | [diff] [blame] | 798 | out_be16(&sp->smc_smcmr, smcr_mk_clen(9) | SMCMR_SM_UART); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 799 | |
| 800 | /* Enable only rx interrupts clear all pending events. */ |
Scott Wood | c1dcfd9 | 2007-07-24 15:53:07 -0500 | [diff] [blame] | 801 | out_8(&sp->smc_smcm, 0); |
| 802 | out_8(&sp->smc_smce, 0xff); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 803 | |
Scott Wood | c1dcfd9 | 2007-07-24 15:53:07 -0500 | [diff] [blame] | 804 | setbits16(&sp->smc_smcmr, SMCMR_REN | SMCMR_TEN); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 805 | } |
| 806 | |
| 807 | /* |
| 808 | * Initialize port. This is called from early_console stuff |
| 809 | * so we have to be careful here ! |
| 810 | */ |
| 811 | static int cpm_uart_request_port(struct uart_port *port) |
| 812 | { |
| 813 | struct uart_cpm_port *pinfo = (struct uart_cpm_port *)port; |
| 814 | int ret; |
| 815 | |
| 816 | pr_debug("CPM uart[%d]:request port\n", port->line); |
| 817 | |
| 818 | if (pinfo->flags & FLAG_CONSOLE) |
| 819 | return 0; |
| 820 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 821 | if (IS_SMC(pinfo)) { |
Scott Wood | c1dcfd9 | 2007-07-24 15:53:07 -0500 | [diff] [blame] | 822 | clrbits8(&pinfo->smcp->smc_smcm, SMCM_RX | SMCM_TX); |
| 823 | clrbits16(&pinfo->smcp->smc_smcmr, SMCMR_REN | SMCMR_TEN); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 824 | } else { |
Scott Wood | c1dcfd9 | 2007-07-24 15:53:07 -0500 | [diff] [blame] | 825 | clrbits16(&pinfo->sccp->scc_sccm, UART_SCCM_TX | UART_SCCM_RX); |
| 826 | clrbits32(&pinfo->sccp->scc_gsmrl, SCC_GSMRL_ENR | SCC_GSMRL_ENT); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 827 | } |
| 828 | |
| 829 | ret = cpm_uart_allocbuf(pinfo, 0); |
| 830 | |
| 831 | if (ret) |
| 832 | return ret; |
| 833 | |
| 834 | cpm_uart_initbd(pinfo); |
Kumar Gala | 311c462 | 2005-08-09 10:08:00 -0700 | [diff] [blame] | 835 | if (IS_SMC(pinfo)) |
| 836 | cpm_uart_init_smc(pinfo); |
| 837 | else |
| 838 | cpm_uart_init_scc(pinfo); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 839 | |
| 840 | return 0; |
| 841 | } |
| 842 | |
| 843 | static void cpm_uart_release_port(struct uart_port *port) |
| 844 | { |
| 845 | struct uart_cpm_port *pinfo = (struct uart_cpm_port *)port; |
| 846 | |
| 847 | if (!(pinfo->flags & FLAG_CONSOLE)) |
| 848 | cpm_uart_freebuf(pinfo); |
| 849 | } |
| 850 | |
| 851 | /* |
| 852 | * Configure/autoconfigure the port. |
| 853 | */ |
| 854 | static void cpm_uart_config_port(struct uart_port *port, int flags) |
| 855 | { |
| 856 | pr_debug("CPM uart[%d]:config_port\n", port->line); |
| 857 | |
| 858 | if (flags & UART_CONFIG_TYPE) { |
| 859 | port->type = PORT_CPM; |
| 860 | cpm_uart_request_port(port); |
| 861 | } |
| 862 | } |
| 863 | static struct uart_ops cpm_uart_pops = { |
| 864 | .tx_empty = cpm_uart_tx_empty, |
| 865 | .set_mctrl = cpm_uart_set_mctrl, |
| 866 | .get_mctrl = cpm_uart_get_mctrl, |
| 867 | .stop_tx = cpm_uart_stop_tx, |
| 868 | .start_tx = cpm_uart_start_tx, |
| 869 | .stop_rx = cpm_uart_stop_rx, |
| 870 | .enable_ms = cpm_uart_enable_ms, |
| 871 | .break_ctl = cpm_uart_break_ctl, |
| 872 | .startup = cpm_uart_startup, |
| 873 | .shutdown = cpm_uart_shutdown, |
| 874 | .set_termios = cpm_uart_set_termios, |
| 875 | .type = cpm_uart_type, |
| 876 | .release_port = cpm_uart_release_port, |
| 877 | .request_port = cpm_uart_request_port, |
| 878 | .config_port = cpm_uart_config_port, |
| 879 | .verify_port = cpm_uart_verify_port, |
| 880 | }; |
| 881 | |
Scott Wood | 7ae8703 | 2007-07-17 17:59:06 -0500 | [diff] [blame] | 882 | struct uart_cpm_port cpm_uart_ports[UART_NR]; |
| 883 | |
Scott Wood | c1dcfd9 | 2007-07-24 15:53:07 -0500 | [diff] [blame] | 884 | static int cpm_uart_init_port(struct device_node *np, |
| 885 | struct uart_cpm_port *pinfo) |
Scott Wood | 7ae8703 | 2007-07-17 17:59:06 -0500 | [diff] [blame] | 886 | { |
| 887 | const u32 *data; |
Scott Wood | c1dcfd9 | 2007-07-24 15:53:07 -0500 | [diff] [blame] | 888 | void __iomem *mem, *pram; |
Scott Wood | 7ae8703 | 2007-07-17 17:59:06 -0500 | [diff] [blame] | 889 | int len; |
| 890 | int ret; |
| 891 | |
| 892 | data = of_get_property(np, "fsl,cpm-brg", &len); |
| 893 | if (!data || len != 4) { |
| 894 | printk(KERN_ERR "CPM UART %s has no/invalid " |
| 895 | "fsl,cpm-brg property.\n", np->name); |
| 896 | return -EINVAL; |
| 897 | } |
| 898 | pinfo->brg = *data; |
| 899 | |
| 900 | data = of_get_property(np, "fsl,cpm-command", &len); |
| 901 | if (!data || len != 4) { |
| 902 | printk(KERN_ERR "CPM UART %s has no/invalid " |
| 903 | "fsl,cpm-command property.\n", np->name); |
| 904 | return -EINVAL; |
| 905 | } |
| 906 | pinfo->command = *data; |
| 907 | |
| 908 | mem = of_iomap(np, 0); |
| 909 | if (!mem) |
| 910 | return -ENOMEM; |
| 911 | |
Scott Wood | 7ae8703 | 2007-07-17 17:59:06 -0500 | [diff] [blame] | 912 | if (of_device_is_compatible(np, "fsl,cpm1-scc-uart") || |
| 913 | of_device_is_compatible(np, "fsl,cpm2-scc-uart")) { |
| 914 | pinfo->sccp = mem; |
Laurent Pinchart | d464df2 | 2008-04-10 17:01:27 +0200 | [diff] [blame] | 915 | pinfo->sccup = pram = cpm_uart_map_pram(pinfo, np); |
Scott Wood | 7ae8703 | 2007-07-17 17:59:06 -0500 | [diff] [blame] | 916 | } else if (of_device_is_compatible(np, "fsl,cpm1-smc-uart") || |
| 917 | of_device_is_compatible(np, "fsl,cpm2-smc-uart")) { |
| 918 | pinfo->flags |= FLAG_SMC; |
| 919 | pinfo->smcp = mem; |
Laurent Pinchart | d464df2 | 2008-04-10 17:01:27 +0200 | [diff] [blame] | 920 | pinfo->smcup = pram = cpm_uart_map_pram(pinfo, np); |
Scott Wood | 7ae8703 | 2007-07-17 17:59:06 -0500 | [diff] [blame] | 921 | } else { |
| 922 | ret = -ENODEV; |
Laurent Pinchart | d464df2 | 2008-04-10 17:01:27 +0200 | [diff] [blame] | 923 | goto out_mem; |
| 924 | } |
| 925 | |
| 926 | if (!pram) { |
| 927 | ret = -ENOMEM; |
| 928 | goto out_mem; |
Scott Wood | 7ae8703 | 2007-07-17 17:59:06 -0500 | [diff] [blame] | 929 | } |
| 930 | |
| 931 | pinfo->tx_nrfifos = TX_NUM_FIFO; |
| 932 | pinfo->tx_fifosize = TX_BUF_SIZE; |
| 933 | pinfo->rx_nrfifos = RX_NUM_FIFO; |
| 934 | pinfo->rx_fifosize = RX_BUF_SIZE; |
| 935 | |
| 936 | pinfo->port.uartclk = ppc_proc_freq; |
| 937 | pinfo->port.mapbase = (unsigned long)mem; |
| 938 | pinfo->port.type = PORT_CPM; |
| 939 | pinfo->port.ops = &cpm_uart_pops, |
| 940 | pinfo->port.iotype = UPIO_MEM; |
| 941 | spin_lock_init(&pinfo->port.lock); |
| 942 | |
| 943 | pinfo->port.irq = of_irq_to_resource(np, 0, NULL); |
| 944 | if (pinfo->port.irq == NO_IRQ) { |
| 945 | ret = -EINVAL; |
| 946 | goto out_pram; |
| 947 | } |
| 948 | |
| 949 | return cpm_uart_request_port(&pinfo->port); |
| 950 | |
| 951 | out_pram: |
Laurent Pinchart | d464df2 | 2008-04-10 17:01:27 +0200 | [diff] [blame] | 952 | cpm_uart_unmap_pram(pinfo, pram); |
Scott Wood | 7ae8703 | 2007-07-17 17:59:06 -0500 | [diff] [blame] | 953 | out_mem: |
| 954 | iounmap(mem); |
| 955 | return ret; |
| 956 | } |
| 957 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 958 | #ifdef CONFIG_SERIAL_CPM_CONSOLE |
| 959 | /* |
| 960 | * Print a string to the serial port trying not to disturb |
| 961 | * any possible real use of the port... |
| 962 | * |
| 963 | * Note that this is called with interrupts already disabled |
| 964 | */ |
| 965 | static void cpm_uart_console_write(struct console *co, const char *s, |
| 966 | u_int count) |
| 967 | { |
Scott Wood | 7ae8703 | 2007-07-17 17:59:06 -0500 | [diff] [blame] | 968 | struct uart_cpm_port *pinfo = &cpm_uart_ports[co->index]; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 969 | unsigned int i; |
Scott Wood | c1dcfd9 | 2007-07-24 15:53:07 -0500 | [diff] [blame] | 970 | cbd_t __iomem *bdp, *bdbase; |
| 971 | unsigned char *cp; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 972 | |
| 973 | /* Get the address of the host memory buffer. |
| 974 | */ |
| 975 | bdp = pinfo->tx_cur; |
| 976 | bdbase = pinfo->tx_bd_base; |
| 977 | |
| 978 | /* |
| 979 | * Now, do each character. This is not as bad as it looks |
| 980 | * since this is a holding FIFO and not a transmitting FIFO. |
| 981 | * We could add the complexity of filling the entire transmit |
| 982 | * buffer, but we would just wait longer between accesses...... |
| 983 | */ |
| 984 | for (i = 0; i < count; i++, s++) { |
| 985 | /* Wait for transmitter fifo to empty. |
| 986 | * Ready indicates output is ready, and xmt is doing |
| 987 | * that, not that it is ready for us to send. |
| 988 | */ |
Scott Wood | c1dcfd9 | 2007-07-24 15:53:07 -0500 | [diff] [blame] | 989 | while ((in_be16(&bdp->cbd_sc) & BD_SC_READY) != 0) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 990 | ; |
| 991 | |
| 992 | /* Send the character out. |
| 993 | * If the buffer address is in the CPM DPRAM, don't |
| 994 | * convert it. |
| 995 | */ |
Scott Wood | c1dcfd9 | 2007-07-24 15:53:07 -0500 | [diff] [blame] | 996 | cp = cpm2cpu_addr(in_be32(&bdp->cbd_bufaddr), pinfo); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 997 | *cp = *s; |
| 998 | |
Scott Wood | c1dcfd9 | 2007-07-24 15:53:07 -0500 | [diff] [blame] | 999 | out_be16(&bdp->cbd_datlen, 1); |
| 1000 | setbits16(&bdp->cbd_sc, BD_SC_READY); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1001 | |
Scott Wood | c1dcfd9 | 2007-07-24 15:53:07 -0500 | [diff] [blame] | 1002 | if (in_be16(&bdp->cbd_sc) & BD_SC_WRAP) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1003 | bdp = bdbase; |
| 1004 | else |
| 1005 | bdp++; |
| 1006 | |
| 1007 | /* if a LF, also do CR... */ |
| 1008 | if (*s == 10) { |
Scott Wood | c1dcfd9 | 2007-07-24 15:53:07 -0500 | [diff] [blame] | 1009 | while ((in_be16(&bdp->cbd_sc) & BD_SC_READY) != 0) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1010 | ; |
| 1011 | |
Scott Wood | c1dcfd9 | 2007-07-24 15:53:07 -0500 | [diff] [blame] | 1012 | cp = cpm2cpu_addr(in_be32(&bdp->cbd_bufaddr), pinfo); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1013 | *cp = 13; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1014 | |
Scott Wood | c1dcfd9 | 2007-07-24 15:53:07 -0500 | [diff] [blame] | 1015 | out_be16(&bdp->cbd_datlen, 1); |
| 1016 | setbits16(&bdp->cbd_sc, BD_SC_READY); |
| 1017 | |
| 1018 | if (in_be16(&bdp->cbd_sc) & BD_SC_WRAP) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1019 | bdp = bdbase; |
| 1020 | else |
| 1021 | bdp++; |
| 1022 | } |
| 1023 | } |
| 1024 | |
| 1025 | /* |
| 1026 | * Finally, Wait for transmitter & holding register to empty |
| 1027 | * and restore the IER |
| 1028 | */ |
Scott Wood | c1dcfd9 | 2007-07-24 15:53:07 -0500 | [diff] [blame] | 1029 | while ((in_be16(&bdp->cbd_sc) & BD_SC_READY) != 0) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1030 | ; |
| 1031 | |
Scott Wood | c1dcfd9 | 2007-07-24 15:53:07 -0500 | [diff] [blame] | 1032 | pinfo->tx_cur = bdp; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1033 | } |
| 1034 | |
Vitaly Bordug | e27987c | 2006-04-25 20:26:41 +0400 | [diff] [blame] | 1035 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1036 | static int __init cpm_uart_console_setup(struct console *co, char *options) |
| 1037 | { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1038 | int baud = 38400; |
| 1039 | int bits = 8; |
| 1040 | int parity = 'n'; |
| 1041 | int flow = 'n'; |
| 1042 | int ret; |
Scott Wood | 7ae8703 | 2007-07-17 17:59:06 -0500 | [diff] [blame] | 1043 | struct uart_cpm_port *pinfo; |
| 1044 | struct uart_port *port; |
| 1045 | |
Scott Wood | 7ae8703 | 2007-07-17 17:59:06 -0500 | [diff] [blame] | 1046 | struct device_node *np = NULL; |
| 1047 | int i = 0; |
| 1048 | |
| 1049 | if (co->index >= UART_NR) { |
| 1050 | printk(KERN_ERR "cpm_uart: console index %d too high\n", |
| 1051 | co->index); |
| 1052 | return -ENODEV; |
| 1053 | } |
| 1054 | |
| 1055 | do { |
| 1056 | np = of_find_node_by_type(np, "serial"); |
| 1057 | if (!np) |
| 1058 | return -ENODEV; |
| 1059 | |
| 1060 | if (!of_device_is_compatible(np, "fsl,cpm1-smc-uart") && |
| 1061 | !of_device_is_compatible(np, "fsl,cpm1-scc-uart") && |
| 1062 | !of_device_is_compatible(np, "fsl,cpm2-smc-uart") && |
| 1063 | !of_device_is_compatible(np, "fsl,cpm2-scc-uart")) |
| 1064 | i--; |
| 1065 | } while (i++ != co->index); |
| 1066 | |
| 1067 | pinfo = &cpm_uart_ports[co->index]; |
| 1068 | |
| 1069 | pinfo->flags |= FLAG_CONSOLE; |
| 1070 | port = &pinfo->port; |
| 1071 | |
| 1072 | ret = cpm_uart_init_port(np, pinfo); |
| 1073 | of_node_put(np); |
| 1074 | if (ret) |
| 1075 | return ret; |
| 1076 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1077 | if (options) { |
| 1078 | uart_parse_options(options, &baud, &parity, &bits, &flow); |
| 1079 | } else { |
Vitaly Bordug | 3dd0dcb | 2006-09-21 17:27:15 +0400 | [diff] [blame] | 1080 | if ((baud = uart_baudrate()) == -1) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1081 | baud = 9600; |
| 1082 | } |
| 1083 | |
Scott Wood | 7ae8703 | 2007-07-17 17:59:06 -0500 | [diff] [blame] | 1084 | #ifdef CONFIG_PPC_EARLY_DEBUG_CPM |
| 1085 | udbg_putc = NULL; |
| 1086 | #endif |
| 1087 | |
Scott Wood | d948a29 | 2007-07-17 18:09:33 -0500 | [diff] [blame] | 1088 | cpm_line_cr_cmd(pinfo, CPM_CR_STOP_TX); |
| 1089 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1090 | if (IS_SMC(pinfo)) { |
Scott Wood | c1dcfd9 | 2007-07-24 15:53:07 -0500 | [diff] [blame] | 1091 | clrbits8(&pinfo->smcp->smc_smcm, SMCM_RX | SMCM_TX); |
| 1092 | clrbits16(&pinfo->smcp->smc_smcmr, SMCMR_REN | SMCMR_TEN); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1093 | } else { |
Scott Wood | c1dcfd9 | 2007-07-24 15:53:07 -0500 | [diff] [blame] | 1094 | clrbits16(&pinfo->sccp->scc_sccm, UART_SCCM_TX | UART_SCCM_RX); |
| 1095 | clrbits32(&pinfo->sccp->scc_gsmrl, SCC_GSMRL_ENR | SCC_GSMRL_ENT); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1096 | } |
| 1097 | |
| 1098 | ret = cpm_uart_allocbuf(pinfo, 1); |
| 1099 | |
| 1100 | if (ret) |
| 1101 | return ret; |
| 1102 | |
| 1103 | cpm_uart_initbd(pinfo); |
| 1104 | |
| 1105 | if (IS_SMC(pinfo)) |
| 1106 | cpm_uart_init_smc(pinfo); |
| 1107 | else |
| 1108 | cpm_uart_init_scc(pinfo); |
| 1109 | |
| 1110 | uart_set_options(port, co, baud, parity, bits, flow); |
Scott Wood | d948a29 | 2007-07-17 18:09:33 -0500 | [diff] [blame] | 1111 | cpm_line_cr_cmd(pinfo, CPM_CR_RESTART_TX); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1112 | |
| 1113 | return 0; |
| 1114 | } |
| 1115 | |
Kumar Gala | 36d2f5a | 2005-08-09 10:08:02 -0700 | [diff] [blame] | 1116 | static struct uart_driver cpm_reg; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1117 | static struct console cpm_scc_uart_console = { |
Kumar Gala | 36d2f5a | 2005-08-09 10:08:02 -0700 | [diff] [blame] | 1118 | .name = "ttyCPM", |
| 1119 | .write = cpm_uart_console_write, |
| 1120 | .device = uart_console_device, |
| 1121 | .setup = cpm_uart_console_setup, |
| 1122 | .flags = CON_PRINTBUFFER, |
| 1123 | .index = -1, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1124 | .data = &cpm_reg, |
| 1125 | }; |
| 1126 | |
Scott Wood | c1dcfd9 | 2007-07-24 15:53:07 -0500 | [diff] [blame] | 1127 | static int __init cpm_uart_console_init(void) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1128 | { |
Vitaly Bordug | e27987c | 2006-04-25 20:26:41 +0400 | [diff] [blame] | 1129 | register_console(&cpm_scc_uart_console); |
| 1130 | return 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1131 | } |
| 1132 | |
| 1133 | console_initcall(cpm_uart_console_init); |
| 1134 | |
| 1135 | #define CPM_UART_CONSOLE &cpm_scc_uart_console |
| 1136 | #else |
| 1137 | #define CPM_UART_CONSOLE NULL |
| 1138 | #endif |
| 1139 | |
| 1140 | static struct uart_driver cpm_reg = { |
| 1141 | .owner = THIS_MODULE, |
| 1142 | .driver_name = "ttyCPM", |
| 1143 | .dev_name = "ttyCPM", |
| 1144 | .major = SERIAL_CPM_MAJOR, |
| 1145 | .minor = SERIAL_CPM_MINOR, |
| 1146 | .cons = CPM_UART_CONSOLE, |
Scott Wood | 7ae8703 | 2007-07-17 17:59:06 -0500 | [diff] [blame] | 1147 | .nr = UART_NR, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1148 | }; |
Scott Wood | 7ae8703 | 2007-07-17 17:59:06 -0500 | [diff] [blame] | 1149 | |
Scott Wood | 7ae8703 | 2007-07-17 17:59:06 -0500 | [diff] [blame] | 1150 | static int probe_index; |
| 1151 | |
| 1152 | static int __devinit cpm_uart_probe(struct of_device *ofdev, |
| 1153 | const struct of_device_id *match) |
| 1154 | { |
| 1155 | int index = probe_index++; |
| 1156 | struct uart_cpm_port *pinfo = &cpm_uart_ports[index]; |
| 1157 | int ret; |
| 1158 | |
| 1159 | pinfo->port.line = index; |
| 1160 | |
| 1161 | if (index >= UART_NR) |
| 1162 | return -ENODEV; |
| 1163 | |
| 1164 | dev_set_drvdata(&ofdev->dev, pinfo); |
| 1165 | |
| 1166 | ret = cpm_uart_init_port(ofdev->node, pinfo); |
| 1167 | if (ret) |
| 1168 | return ret; |
| 1169 | |
| 1170 | return uart_add_one_port(&cpm_reg, &pinfo->port); |
| 1171 | } |
| 1172 | |
| 1173 | static int __devexit cpm_uart_remove(struct of_device *ofdev) |
| 1174 | { |
| 1175 | struct uart_cpm_port *pinfo = dev_get_drvdata(&ofdev->dev); |
| 1176 | return uart_remove_one_port(&cpm_reg, &pinfo->port); |
| 1177 | } |
| 1178 | |
| 1179 | static struct of_device_id cpm_uart_match[] = { |
| 1180 | { |
| 1181 | .compatible = "fsl,cpm1-smc-uart", |
| 1182 | }, |
| 1183 | { |
| 1184 | .compatible = "fsl,cpm1-scc-uart", |
| 1185 | }, |
| 1186 | { |
| 1187 | .compatible = "fsl,cpm2-smc-uart", |
| 1188 | }, |
| 1189 | { |
| 1190 | .compatible = "fsl,cpm2-scc-uart", |
| 1191 | }, |
| 1192 | {} |
| 1193 | }; |
| 1194 | |
| 1195 | static struct of_platform_driver cpm_uart_driver = { |
| 1196 | .name = "cpm_uart", |
| 1197 | .match_table = cpm_uart_match, |
| 1198 | .probe = cpm_uart_probe, |
| 1199 | .remove = cpm_uart_remove, |
| 1200 | }; |
| 1201 | |
| 1202 | static int __init cpm_uart_init(void) |
| 1203 | { |
| 1204 | int ret = uart_register_driver(&cpm_reg); |
| 1205 | if (ret) |
| 1206 | return ret; |
| 1207 | |
| 1208 | ret = of_register_platform_driver(&cpm_uart_driver); |
| 1209 | if (ret) |
| 1210 | uart_unregister_driver(&cpm_reg); |
| 1211 | |
| 1212 | return ret; |
| 1213 | } |
| 1214 | |
| 1215 | static void __exit cpm_uart_exit(void) |
| 1216 | { |
| 1217 | of_unregister_platform_driver(&cpm_uart_driver); |
| 1218 | uart_unregister_driver(&cpm_reg); |
| 1219 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1220 | |
| 1221 | module_init(cpm_uart_init); |
| 1222 | module_exit(cpm_uart_exit); |
| 1223 | |
| 1224 | MODULE_AUTHOR("Kumar Gala/Antoniou Pantelis"); |
| 1225 | MODULE_DESCRIPTION("CPM SCC/SMC port driver $Revision: 0.01 $"); |
| 1226 | MODULE_LICENSE("GPL"); |
| 1227 | MODULE_ALIAS_CHARDEV(SERIAL_CPM_MAJOR, SERIAL_CPM_MINOR); |