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