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); |
Christophe Leroy | 3459f621 | 2019-05-22 12:17:11 +0000 | [diff] [blame] | 424 | if (IS_SMC(pinfo)) { |
| 425 | out_be32(&pinfo->smcup->smc_rstate, 0); |
| 426 | out_be32(&pinfo->smcup->smc_tstate, 0); |
| 427 | out_be16(&pinfo->smcup->smc_rbptr, |
| 428 | in_be16(&pinfo->smcup->smc_rbase)); |
| 429 | out_be16(&pinfo->smcup->smc_tbptr, |
| 430 | in_be16(&pinfo->smcup->smc_tbase)); |
| 431 | } else { |
| 432 | cpm_line_cr_cmd(pinfo, CPM_CR_INIT_TRX); |
| 433 | } |
Xiaotian Feng | 9ab9212 | 2009-03-06 11:01:23 +0800 | [diff] [blame] | 434 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 435 | /* Install interrupt handler. */ |
| 436 | retval = request_irq(port->irq, cpm_uart_int, 0, "cpm_uart", port); |
| 437 | if (retval) |
| 438 | return retval; |
| 439 | |
| 440 | /* Startup rx-int */ |
| 441 | if (IS_SMC(pinfo)) { |
Scott Wood | c1dcfd9 | 2007-07-24 15:53:07 -0500 | [diff] [blame] | 442 | setbits8(&pinfo->smcp->smc_smcm, SMCM_RX); |
| 443 | setbits16(&pinfo->smcp->smc_smcmr, (SMCMR_REN | SMCMR_TEN)); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 444 | } else { |
Scott Wood | c1dcfd9 | 2007-07-24 15:53:07 -0500 | [diff] [blame] | 445 | setbits16(&pinfo->sccp->scc_sccm, UART_SCCM_RX); |
| 446 | setbits32(&pinfo->sccp->scc_gsmrl, (SCC_GSMRL_ENR | SCC_GSMRL_ENT)); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 447 | } |
| 448 | |
| 449 | return 0; |
| 450 | } |
| 451 | |
Kumar Gala | 311c462 | 2005-08-09 10:08:00 -0700 | [diff] [blame] | 452 | inline void cpm_uart_wait_until_send(struct uart_cpm_port *pinfo) |
| 453 | { |
Kumar Gala | 638861d | 2005-09-03 15:55:37 -0700 | [diff] [blame] | 454 | set_current_state(TASK_UNINTERRUPTIBLE); |
| 455 | schedule_timeout(pinfo->wait_closing); |
Kumar Gala | 311c462 | 2005-08-09 10:08:00 -0700 | [diff] [blame] | 456 | } |
| 457 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 458 | /* |
| 459 | * Shutdown the uart |
| 460 | */ |
| 461 | static void cpm_uart_shutdown(struct uart_port *port) |
| 462 | { |
Fabian Frederick | e789d26 | 2014-10-05 19:01:06 +0200 | [diff] [blame] | 463 | struct uart_cpm_port *pinfo = |
| 464 | container_of(port, struct uart_cpm_port, port); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 465 | |
| 466 | pr_debug("CPM uart[%d]:shutdown\n", port->line); |
| 467 | |
| 468 | /* free interrupt handler */ |
| 469 | free_irq(port->irq, port); |
| 470 | |
| 471 | /* If the port is not the console, disable Rx and Tx. */ |
| 472 | if (!(pinfo->flags & FLAG_CONSOLE)) { |
Kumar Gala | 311c462 | 2005-08-09 10:08:00 -0700 | [diff] [blame] | 473 | /* Wait for all the BDs marked sent */ |
Kumar Gala | 638861d | 2005-09-03 15:55:37 -0700 | [diff] [blame] | 474 | while(!cpm_uart_tx_empty(port)) { |
| 475 | set_current_state(TASK_UNINTERRUPTIBLE); |
Kumar Gala | 311c462 | 2005-08-09 10:08:00 -0700 | [diff] [blame] | 476 | schedule_timeout(2); |
Kumar Gala | 638861d | 2005-09-03 15:55:37 -0700 | [diff] [blame] | 477 | } |
| 478 | |
| 479 | if (pinfo->wait_closing) |
Kumar Gala | 311c462 | 2005-08-09 10:08:00 -0700 | [diff] [blame] | 480 | cpm_uart_wait_until_send(pinfo); |
| 481 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 482 | /* Stop uarts */ |
| 483 | if (IS_SMC(pinfo)) { |
Scott Wood | c1dcfd9 | 2007-07-24 15:53:07 -0500 | [diff] [blame] | 484 | smc_t __iomem *smcp = pinfo->smcp; |
| 485 | clrbits16(&smcp->smc_smcmr, SMCMR_REN | SMCMR_TEN); |
| 486 | clrbits8(&smcp->smc_smcm, SMCM_RX | SMCM_TX); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 487 | } else { |
Scott Wood | c1dcfd9 | 2007-07-24 15:53:07 -0500 | [diff] [blame] | 488 | scc_t __iomem *sccp = pinfo->sccp; |
| 489 | clrbits32(&sccp->scc_gsmrl, SCC_GSMRL_ENR | SCC_GSMRL_ENT); |
| 490 | clrbits16(&sccp->scc_sccm, UART_SCCM_TX | UART_SCCM_RX); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 491 | } |
| 492 | |
| 493 | /* Shut them really down and reinit buffer descriptors */ |
Nye Liu | ae2d4c3 | 2008-07-23 21:29:50 -0700 | [diff] [blame] | 494 | if (IS_SMC(pinfo)) { |
| 495 | out_be16(&pinfo->smcup->smc_brkcr, 0); |
Scott Wood | 7ae8703 | 2007-07-17 17:59:06 -0500 | [diff] [blame] | 496 | cpm_line_cr_cmd(pinfo, CPM_CR_STOP_TX); |
Nye Liu | ae2d4c3 | 2008-07-23 21:29:50 -0700 | [diff] [blame] | 497 | } else { |
| 498 | out_be16(&pinfo->sccup->scc_brkcr, 0); |
Scott Wood | 7ae8703 | 2007-07-17 17:59:06 -0500 | [diff] [blame] | 499 | cpm_line_cr_cmd(pinfo, CPM_CR_GRA_STOP_TX); |
Nye Liu | ae2d4c3 | 2008-07-23 21:29:50 -0700 | [diff] [blame] | 500 | } |
Vitaly Bordug | 61f5657 | 2006-04-29 22:32:44 +0400 | [diff] [blame] | 501 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 502 | cpm_uart_initbd(pinfo); |
| 503 | } |
| 504 | } |
| 505 | |
| 506 | static void cpm_uart_set_termios(struct uart_port *port, |
Scott Wood | 1bda8f3 | 2007-05-08 12:19:21 -0500 | [diff] [blame] | 507 | struct ktermios *termios, |
| 508 | struct ktermios *old) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 509 | { |
| 510 | int baud; |
| 511 | unsigned long flags; |
| 512 | u16 cval, scval, prev_mode; |
| 513 | int bits, sbits; |
Fabian Frederick | e789d26 | 2014-10-05 19:01:06 +0200 | [diff] [blame] | 514 | struct uart_cpm_port *pinfo = |
| 515 | container_of(port, struct uart_cpm_port, port); |
Scott Wood | c1dcfd9 | 2007-07-24 15:53:07 -0500 | [diff] [blame] | 516 | smc_t __iomem *smcp = pinfo->smcp; |
| 517 | scc_t __iomem *sccp = pinfo->sccp; |
Christophe Leroy | 6e62bdc | 2012-09-24 08:39:44 +0200 | [diff] [blame] | 518 | int maxidl; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 519 | |
| 520 | pr_debug("CPM uart[%d]:set_termios\n", port->line); |
| 521 | |
| 522 | baud = uart_get_baud_rate(port, termios, old, 0, port->uartclk / 16); |
Christophe Leroy | 59733ef | 2012-09-24 08:19:03 +0200 | [diff] [blame] | 523 | if (baud < HW_BUF_SPD_THRESHOLD || |
Jiri Slaby | d6c53c0 | 2013-01-03 15:53:05 +0100 | [diff] [blame] | 524 | (pinfo->port.state && pinfo->port.state->port.low_latency)) |
Baurzhan Ismagulov | 5b04ec4 | 2010-11-11 10:53:03 +0100 | [diff] [blame] | 525 | pinfo->rx_fifosize = 1; |
| 526 | else |
| 527 | pinfo->rx_fifosize = RX_BUF_SIZE; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 528 | |
Christophe Leroy | 6e62bdc | 2012-09-24 08:39:44 +0200 | [diff] [blame] | 529 | /* MAXIDL is the timeout after which a receive buffer is closed |
| 530 | * when not full if no more characters are received. |
| 531 | * We calculate it from the baudrate so that the duration is |
| 532 | * always the same at standard rates: about 4ms. |
| 533 | */ |
| 534 | maxidl = baud / 2400; |
| 535 | if (maxidl < 1) |
| 536 | maxidl = 1; |
| 537 | if (maxidl > 0x10) |
| 538 | maxidl = 0x10; |
| 539 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 540 | /* Character length programmed into the mode register is the |
| 541 | * sum of: 1 start bit, number of data bits, 0 or 1 parity bit, |
| 542 | * 1 or 2 stop bits, minus 1. |
| 543 | * The value 'bits' counts this for us. |
| 544 | */ |
| 545 | cval = 0; |
| 546 | scval = 0; |
| 547 | |
| 548 | /* byte size */ |
| 549 | switch (termios->c_cflag & CSIZE) { |
| 550 | case CS5: |
| 551 | bits = 5; |
| 552 | break; |
| 553 | case CS6: |
| 554 | bits = 6; |
| 555 | break; |
| 556 | case CS7: |
| 557 | bits = 7; |
| 558 | break; |
| 559 | case CS8: |
| 560 | bits = 8; |
| 561 | break; |
| 562 | /* Never happens, but GCC is too dumb to figure it out */ |
| 563 | default: |
| 564 | bits = 8; |
| 565 | break; |
| 566 | } |
| 567 | sbits = bits - 5; |
| 568 | |
| 569 | if (termios->c_cflag & CSTOPB) { |
| 570 | cval |= SMCMR_SL; /* Two stops */ |
| 571 | scval |= SCU_PSMR_SL; |
| 572 | bits++; |
| 573 | } |
| 574 | |
| 575 | if (termios->c_cflag & PARENB) { |
| 576 | cval |= SMCMR_PEN; |
| 577 | scval |= SCU_PSMR_PEN; |
| 578 | bits++; |
| 579 | if (!(termios->c_cflag & PARODD)) { |
| 580 | cval |= SMCMR_PM_EVEN; |
| 581 | scval |= (SCU_PSMR_REVP | SCU_PSMR_TEVP); |
| 582 | } |
| 583 | } |
| 584 | |
| 585 | /* |
Laurent Pinchart | dc32081 | 2008-07-02 10:58:45 +0200 | [diff] [blame] | 586 | * Update the timeout |
| 587 | */ |
| 588 | uart_update_timeout(port, termios->c_cflag, baud); |
| 589 | |
| 590 | /* |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 591 | * Set up parity check flag |
| 592 | */ |
| 593 | #define RELEVANT_IFLAG(iflag) (iflag & (IGNBRK|BRKINT|IGNPAR|PARMRK|INPCK)) |
| 594 | |
| 595 | port->read_status_mask = (BD_SC_EMPTY | BD_SC_OV); |
| 596 | if (termios->c_iflag & INPCK) |
| 597 | port->read_status_mask |= BD_SC_FR | BD_SC_PR; |
| 598 | if ((termios->c_iflag & BRKINT) || (termios->c_iflag & PARMRK)) |
| 599 | port->read_status_mask |= BD_SC_BR; |
| 600 | |
| 601 | /* |
| 602 | * Characters to ignore |
| 603 | */ |
| 604 | port->ignore_status_mask = 0; |
| 605 | if (termios->c_iflag & IGNPAR) |
| 606 | port->ignore_status_mask |= BD_SC_PR | BD_SC_FR; |
| 607 | if (termios->c_iflag & IGNBRK) { |
| 608 | port->ignore_status_mask |= BD_SC_BR; |
| 609 | /* |
| 610 | * If we're ignore parity and break indicators, ignore |
| 611 | * overruns too. (For real raw support). |
| 612 | */ |
| 613 | if (termios->c_iflag & IGNPAR) |
| 614 | port->ignore_status_mask |= BD_SC_OV; |
| 615 | } |
| 616 | /* |
| 617 | * !!! ignore all characters if CREAD is not set |
| 618 | */ |
| 619 | if ((termios->c_cflag & CREAD) == 0) |
| 620 | port->read_status_mask &= ~BD_SC_EMPTY; |
Kumar Gala | 311c462 | 2005-08-09 10:08:00 -0700 | [diff] [blame] | 621 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 622 | spin_lock_irqsave(&port->lock, flags); |
| 623 | |
| 624 | /* Start bit has not been added (so don't, because we would just |
| 625 | * subtract it later), and we need to add one for the number of |
| 626 | * stops bits (there is always at least one). |
| 627 | */ |
| 628 | bits++; |
| 629 | if (IS_SMC(pinfo)) { |
Baurzhan Ismagulov | 5b04ec4 | 2010-11-11 10:53:03 +0100 | [diff] [blame] | 630 | /* |
| 631 | * MRBLR can be changed while an SMC/SCC is operating only |
| 632 | * if it is done in a single bus cycle with one 16-bit move |
| 633 | * (not two 8-bit bus cycles back-to-back). This occurs when |
| 634 | * the cp shifts control to the next RxBD, so the change does |
| 635 | * not take effect immediately. To guarantee the exact RxBD |
| 636 | * on which the change occurs, change MRBLR only while the |
| 637 | * SMC/SCC receiver is disabled. |
| 638 | */ |
| 639 | out_be16(&pinfo->smcup->smc_mrblr, pinfo->rx_fifosize); |
Christophe Leroy | 6e62bdc | 2012-09-24 08:39:44 +0200 | [diff] [blame] | 640 | out_be16(&pinfo->smcup->smc_maxidl, maxidl); |
Baurzhan Ismagulov | 5b04ec4 | 2010-11-11 10:53:03 +0100 | [diff] [blame] | 641 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 642 | /* Set the mode register. We want to keep a copy of the |
| 643 | * enables, because we want to put them back if they were |
| 644 | * present. |
| 645 | */ |
Nye Liu | ae2d4c3 | 2008-07-23 21:29:50 -0700 | [diff] [blame] | 646 | prev_mode = in_be16(&smcp->smc_smcmr) & (SMCMR_REN | SMCMR_TEN); |
| 647 | /* Output in *one* operation, so we don't interrupt RX/TX if they |
| 648 | * were already enabled. */ |
| 649 | out_be16(&smcp->smc_smcmr, smcr_mk_clen(bits) | cval | |
| 650 | SMCMR_SM_UART | prev_mode); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 651 | } else { |
Baurzhan Ismagulov | 5b04ec4 | 2010-11-11 10:53:03 +0100 | [diff] [blame] | 652 | out_be16(&pinfo->sccup->scc_genscc.scc_mrblr, pinfo->rx_fifosize); |
Christophe Leroy | 6e62bdc | 2012-09-24 08:39:44 +0200 | [diff] [blame] | 653 | out_be16(&pinfo->sccup->scc_maxidl, maxidl); |
Scott Wood | c1dcfd9 | 2007-07-24 15:53:07 -0500 | [diff] [blame] | 654 | out_be16(&sccp->scc_psmr, (sbits << 12) | scval); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 655 | } |
| 656 | |
Laurent Pinchart | 8077655 | 2008-07-28 10:42:16 +0200 | [diff] [blame] | 657 | if (pinfo->clk) |
| 658 | clk_set_rate(pinfo->clk, baud); |
| 659 | else |
| 660 | cpm_set_brg(pinfo->brg - 1, baud); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 661 | spin_unlock_irqrestore(&port->lock, flags); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 662 | } |
| 663 | |
| 664 | static const char *cpm_uart_type(struct uart_port *port) |
| 665 | { |
| 666 | pr_debug("CPM uart[%d]:uart_type\n", port->line); |
| 667 | |
| 668 | return port->type == PORT_CPM ? "CPM UART" : NULL; |
| 669 | } |
| 670 | |
| 671 | /* |
| 672 | * verify the new serial_struct (for TIOCSSERIAL). |
| 673 | */ |
| 674 | static int cpm_uart_verify_port(struct uart_port *port, |
| 675 | struct serial_struct *ser) |
| 676 | { |
| 677 | int ret = 0; |
| 678 | |
| 679 | pr_debug("CPM uart[%d]:verify_port\n", port->line); |
| 680 | |
| 681 | if (ser->type != PORT_UNKNOWN && ser->type != PORT_CPM) |
| 682 | ret = -EINVAL; |
Yinghai Lu | a62c413 | 2008-08-19 20:49:55 -0700 | [diff] [blame] | 683 | if (ser->irq < 0 || ser->irq >= nr_irqs) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 684 | ret = -EINVAL; |
| 685 | if (ser->baud_base < 9600) |
| 686 | ret = -EINVAL; |
| 687 | return ret; |
| 688 | } |
| 689 | |
| 690 | /* |
| 691 | * Transmit characters, refill buffer descriptor, if possible |
| 692 | */ |
| 693 | static int cpm_uart_tx_pump(struct uart_port *port) |
| 694 | { |
Scott Wood | c1dcfd9 | 2007-07-24 15:53:07 -0500 | [diff] [blame] | 695 | cbd_t __iomem *bdp; |
| 696 | u8 *p; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 697 | int count; |
Fabian Frederick | e789d26 | 2014-10-05 19:01:06 +0200 | [diff] [blame] | 698 | struct uart_cpm_port *pinfo = |
| 699 | container_of(port, struct uart_cpm_port, port); |
Benjamin Herrenschmidt | 09dd3fc | 2009-09-24 16:05:52 +1000 | [diff] [blame] | 700 | struct circ_buf *xmit = &port->state->xmit; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 701 | |
| 702 | /* Handle xon/xoff */ |
| 703 | if (port->x_char) { |
| 704 | /* Pick next descriptor and fill from buffer */ |
| 705 | bdp = pinfo->tx_cur; |
| 706 | |
Scott Wood | c1dcfd9 | 2007-07-24 15:53:07 -0500 | [diff] [blame] | 707 | p = cpm2cpu_addr(in_be32(&bdp->cbd_bufaddr), pinfo); |
Kumar Gala | 311c462 | 2005-08-09 10:08:00 -0700 | [diff] [blame] | 708 | |
Aristeu Sergio Rozanski Filho | 03929c7 | 2005-12-29 19:18:49 -0200 | [diff] [blame] | 709 | *p++ = port->x_char; |
Scott Wood | c1dcfd9 | 2007-07-24 15:53:07 -0500 | [diff] [blame] | 710 | |
| 711 | out_be16(&bdp->cbd_datlen, 1); |
| 712 | setbits16(&bdp->cbd_sc, BD_SC_READY); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 713 | /* Get next BD. */ |
Scott Wood | c1dcfd9 | 2007-07-24 15:53:07 -0500 | [diff] [blame] | 714 | if (in_be16(&bdp->cbd_sc) & BD_SC_WRAP) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 715 | bdp = pinfo->tx_bd_base; |
| 716 | else |
| 717 | bdp++; |
| 718 | pinfo->tx_cur = bdp; |
| 719 | |
| 720 | port->icount.tx++; |
| 721 | port->x_char = 0; |
| 722 | return 1; |
| 723 | } |
| 724 | |
| 725 | if (uart_circ_empty(xmit) || uart_tx_stopped(port)) { |
Russell King | b129a8c | 2005-08-31 10:12:14 +0100 | [diff] [blame] | 726 | cpm_uart_stop_tx(port); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 727 | return 0; |
| 728 | } |
| 729 | |
| 730 | /* Pick next descriptor and fill from buffer */ |
| 731 | bdp = pinfo->tx_cur; |
| 732 | |
Scott Wood | c1dcfd9 | 2007-07-24 15:53:07 -0500 | [diff] [blame] | 733 | while (!(in_be16(&bdp->cbd_sc) & BD_SC_READY) && |
| 734 | xmit->tail != xmit->head) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 735 | count = 0; |
Scott Wood | c1dcfd9 | 2007-07-24 15:53:07 -0500 | [diff] [blame] | 736 | p = cpm2cpu_addr(in_be32(&bdp->cbd_bufaddr), pinfo); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 737 | while (count < pinfo->tx_fifosize) { |
| 738 | *p++ = xmit->buf[xmit->tail]; |
| 739 | xmit->tail = (xmit->tail + 1) & (UART_XMIT_SIZE - 1); |
| 740 | port->icount.tx++; |
| 741 | count++; |
| 742 | if (xmit->head == xmit->tail) |
| 743 | break; |
| 744 | } |
Scott Wood | c1dcfd9 | 2007-07-24 15:53:07 -0500 | [diff] [blame] | 745 | out_be16(&bdp->cbd_datlen, count); |
| 746 | setbits16(&bdp->cbd_sc, BD_SC_READY); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 747 | /* Get next BD. */ |
Scott Wood | c1dcfd9 | 2007-07-24 15:53:07 -0500 | [diff] [blame] | 748 | if (in_be16(&bdp->cbd_sc) & BD_SC_WRAP) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 749 | bdp = pinfo->tx_bd_base; |
| 750 | else |
| 751 | bdp++; |
| 752 | } |
| 753 | pinfo->tx_cur = bdp; |
| 754 | |
| 755 | if (uart_circ_chars_pending(xmit) < WAKEUP_CHARS) |
| 756 | uart_write_wakeup(port); |
| 757 | |
| 758 | if (uart_circ_empty(xmit)) { |
Russell King | b129a8c | 2005-08-31 10:12:14 +0100 | [diff] [blame] | 759 | cpm_uart_stop_tx(port); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 760 | return 0; |
| 761 | } |
| 762 | |
| 763 | return 1; |
| 764 | } |
| 765 | |
| 766 | /* |
| 767 | * init buffer descriptors |
| 768 | */ |
| 769 | static void cpm_uart_initbd(struct uart_cpm_port *pinfo) |
| 770 | { |
| 771 | int i; |
| 772 | u8 *mem_addr; |
Scott Wood | c1dcfd9 | 2007-07-24 15:53:07 -0500 | [diff] [blame] | 773 | cbd_t __iomem *bdp; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 774 | |
| 775 | pr_debug("CPM uart[%d]:initbd\n", pinfo->port.line); |
| 776 | |
| 777 | /* Set the physical address of the host memory |
| 778 | * buffers in the buffer descriptors, and the |
| 779 | * virtual address for us to work with. |
| 780 | */ |
| 781 | mem_addr = pinfo->mem_addr; |
| 782 | bdp = pinfo->rx_cur = pinfo->rx_bd_base; |
| 783 | for (i = 0; i < (pinfo->rx_nrfifos - 1); i++, bdp++) { |
Scott Wood | c1dcfd9 | 2007-07-24 15:53:07 -0500 | [diff] [blame] | 784 | out_be32(&bdp->cbd_bufaddr, cpu2cpm_addr(mem_addr, pinfo)); |
| 785 | out_be16(&bdp->cbd_sc, BD_SC_EMPTY | BD_SC_INTRPT); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 786 | mem_addr += pinfo->rx_fifosize; |
| 787 | } |
Kumar Gala | 311c462 | 2005-08-09 10:08:00 -0700 | [diff] [blame] | 788 | |
Scott Wood | c1dcfd9 | 2007-07-24 15:53:07 -0500 | [diff] [blame] | 789 | out_be32(&bdp->cbd_bufaddr, cpu2cpm_addr(mem_addr, pinfo)); |
| 790 | 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] | 791 | |
| 792 | /* Set the physical address of the host memory |
| 793 | * buffers in the buffer descriptors, and the |
| 794 | * virtual address for us to work with. |
| 795 | */ |
| 796 | mem_addr = pinfo->mem_addr + L1_CACHE_ALIGN(pinfo->rx_nrfifos * pinfo->rx_fifosize); |
| 797 | bdp = pinfo->tx_cur = pinfo->tx_bd_base; |
| 798 | for (i = 0; i < (pinfo->tx_nrfifos - 1); i++, bdp++) { |
Scott Wood | c1dcfd9 | 2007-07-24 15:53:07 -0500 | [diff] [blame] | 799 | out_be32(&bdp->cbd_bufaddr, cpu2cpm_addr(mem_addr, pinfo)); |
| 800 | out_be16(&bdp->cbd_sc, BD_SC_INTRPT); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 801 | mem_addr += pinfo->tx_fifosize; |
| 802 | } |
Kumar Gala | 311c462 | 2005-08-09 10:08:00 -0700 | [diff] [blame] | 803 | |
Scott Wood | c1dcfd9 | 2007-07-24 15:53:07 -0500 | [diff] [blame] | 804 | out_be32(&bdp->cbd_bufaddr, cpu2cpm_addr(mem_addr, pinfo)); |
| 805 | out_be16(&bdp->cbd_sc, BD_SC_WRAP | BD_SC_INTRPT); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 806 | } |
| 807 | |
| 808 | static void cpm_uart_init_scc(struct uart_cpm_port *pinfo) |
| 809 | { |
Scott Wood | c1dcfd9 | 2007-07-24 15:53:07 -0500 | [diff] [blame] | 810 | scc_t __iomem *scp; |
| 811 | scc_uart_t __iomem *sup; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 812 | |
| 813 | pr_debug("CPM uart[%d]:init_scc\n", pinfo->port.line); |
| 814 | |
| 815 | scp = pinfo->sccp; |
| 816 | sup = pinfo->sccup; |
| 817 | |
| 818 | /* Store address */ |
Scott Wood | c1dcfd9 | 2007-07-24 15:53:07 -0500 | [diff] [blame] | 819 | out_be16(&pinfo->sccup->scc_genscc.scc_rbase, |
| 820 | (u8 __iomem *)pinfo->rx_bd_base - DPRAM_BASE); |
| 821 | out_be16(&pinfo->sccup->scc_genscc.scc_tbase, |
| 822 | (u8 __iomem *)pinfo->tx_bd_base - DPRAM_BASE); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 823 | |
| 824 | /* Set up the uart parameters in the |
| 825 | * parameter ram. |
| 826 | */ |
| 827 | |
| 828 | cpm_set_scc_fcr(sup); |
| 829 | |
Scott Wood | c1dcfd9 | 2007-07-24 15:53:07 -0500 | [diff] [blame] | 830 | out_be16(&sup->scc_genscc.scc_mrblr, pinfo->rx_fifosize); |
Christophe Leroy | fbbb9d9 | 2012-09-24 08:20:18 +0200 | [diff] [blame] | 831 | out_be16(&sup->scc_maxidl, 0x10); |
Scott Wood | c1dcfd9 | 2007-07-24 15:53:07 -0500 | [diff] [blame] | 832 | out_be16(&sup->scc_brkcr, 1); |
| 833 | out_be16(&sup->scc_parec, 0); |
| 834 | out_be16(&sup->scc_frmec, 0); |
| 835 | out_be16(&sup->scc_nosec, 0); |
| 836 | out_be16(&sup->scc_brkec, 0); |
| 837 | out_be16(&sup->scc_uaddr1, 0); |
| 838 | out_be16(&sup->scc_uaddr2, 0); |
| 839 | out_be16(&sup->scc_toseq, 0); |
| 840 | out_be16(&sup->scc_char1, 0x8000); |
| 841 | out_be16(&sup->scc_char2, 0x8000); |
| 842 | out_be16(&sup->scc_char3, 0x8000); |
| 843 | out_be16(&sup->scc_char4, 0x8000); |
| 844 | out_be16(&sup->scc_char5, 0x8000); |
| 845 | out_be16(&sup->scc_char6, 0x8000); |
| 846 | out_be16(&sup->scc_char7, 0x8000); |
| 847 | out_be16(&sup->scc_char8, 0x8000); |
| 848 | out_be16(&sup->scc_rccm, 0xc0ff); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 849 | |
| 850 | /* Send the CPM an initialize command. |
| 851 | */ |
Scott Wood | 7ae8703 | 2007-07-17 17:59:06 -0500 | [diff] [blame] | 852 | cpm_line_cr_cmd(pinfo, CPM_CR_INIT_TRX); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 853 | |
| 854 | /* Set UART mode, 8 bit, no parity, one stop. |
| 855 | * Enable receive and transmit. |
| 856 | */ |
Scott Wood | c1dcfd9 | 2007-07-24 15:53:07 -0500 | [diff] [blame] | 857 | out_be32(&scp->scc_gsmrh, 0); |
| 858 | out_be32(&scp->scc_gsmrl, |
| 859 | SCC_GSMRL_MODE_UART | SCC_GSMRL_TDCR_16 | SCC_GSMRL_RDCR_16); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 860 | |
| 861 | /* Enable rx interrupts and clear all pending events. */ |
Scott Wood | c1dcfd9 | 2007-07-24 15:53:07 -0500 | [diff] [blame] | 862 | out_be16(&scp->scc_sccm, 0); |
| 863 | out_be16(&scp->scc_scce, 0xffff); |
| 864 | out_be16(&scp->scc_dsr, 0x7e7e); |
| 865 | out_be16(&scp->scc_psmr, 0x3000); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 866 | |
Scott Wood | c1dcfd9 | 2007-07-24 15:53:07 -0500 | [diff] [blame] | 867 | setbits32(&scp->scc_gsmrl, SCC_GSMRL_ENR | SCC_GSMRL_ENT); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 868 | } |
| 869 | |
| 870 | static void cpm_uart_init_smc(struct uart_cpm_port *pinfo) |
| 871 | { |
Scott Wood | c1dcfd9 | 2007-07-24 15:53:07 -0500 | [diff] [blame] | 872 | smc_t __iomem *sp; |
| 873 | smc_uart_t __iomem *up; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 874 | |
| 875 | pr_debug("CPM uart[%d]:init_smc\n", pinfo->port.line); |
| 876 | |
| 877 | sp = pinfo->smcp; |
| 878 | up = pinfo->smcup; |
| 879 | |
| 880 | /* Store address */ |
Scott Wood | c1dcfd9 | 2007-07-24 15:53:07 -0500 | [diff] [blame] | 881 | out_be16(&pinfo->smcup->smc_rbase, |
| 882 | (u8 __iomem *)pinfo->rx_bd_base - DPRAM_BASE); |
| 883 | out_be16(&pinfo->smcup->smc_tbase, |
| 884 | (u8 __iomem *)pinfo->tx_bd_base - DPRAM_BASE); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 885 | |
| 886 | /* |
Christophe Leroy | 3459f621 | 2019-05-22 12:17:11 +0000 | [diff] [blame] | 887 | * In case SMC is being relocated... |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 888 | */ |
Scott Wood | c1dcfd9 | 2007-07-24 15:53:07 -0500 | [diff] [blame] | 889 | out_be16(&up->smc_rbptr, in_be16(&pinfo->smcup->smc_rbase)); |
| 890 | out_be16(&up->smc_tbptr, in_be16(&pinfo->smcup->smc_tbase)); |
| 891 | out_be32(&up->smc_rstate, 0); |
| 892 | out_be32(&up->smc_tstate, 0); |
| 893 | out_be16(&up->smc_brkcr, 1); /* number of break chars */ |
| 894 | out_be16(&up->smc_brkec, 0); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 895 | |
| 896 | /* Set up the uart parameters in the |
| 897 | * parameter ram. |
| 898 | */ |
| 899 | cpm_set_smc_fcr(up); |
| 900 | |
Thomas Weber | b770ffd | 2010-07-19 08:22:43 +0200 | [diff] [blame] | 901 | /* Using idle character time requires some additional tuning. */ |
Scott Wood | c1dcfd9 | 2007-07-24 15:53:07 -0500 | [diff] [blame] | 902 | out_be16(&up->smc_mrblr, pinfo->rx_fifosize); |
Christophe Leroy | fbbb9d9 | 2012-09-24 08:20:18 +0200 | [diff] [blame] | 903 | out_be16(&up->smc_maxidl, 0x10); |
Scott Wood | c1dcfd9 | 2007-07-24 15:53:07 -0500 | [diff] [blame] | 904 | out_be16(&up->smc_brklen, 0); |
| 905 | out_be16(&up->smc_brkec, 0); |
| 906 | out_be16(&up->smc_brkcr, 1); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 907 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 908 | /* Set UART mode, 8 bit, no parity, one stop. |
| 909 | * Enable receive and transmit. |
| 910 | */ |
Scott Wood | c1dcfd9 | 2007-07-24 15:53:07 -0500 | [diff] [blame] | 911 | out_be16(&sp->smc_smcmr, smcr_mk_clen(9) | SMCMR_SM_UART); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 912 | |
| 913 | /* Enable only rx interrupts clear all pending events. */ |
Scott Wood | c1dcfd9 | 2007-07-24 15:53:07 -0500 | [diff] [blame] | 914 | out_8(&sp->smc_smcm, 0); |
| 915 | out_8(&sp->smc_smce, 0xff); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 916 | |
Scott Wood | c1dcfd9 | 2007-07-24 15:53:07 -0500 | [diff] [blame] | 917 | setbits16(&sp->smc_smcmr, SMCMR_REN | SMCMR_TEN); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 918 | } |
| 919 | |
| 920 | /* |
| 921 | * Initialize port. This is called from early_console stuff |
| 922 | * so we have to be careful here ! |
| 923 | */ |
| 924 | static int cpm_uart_request_port(struct uart_port *port) |
| 925 | { |
Fabian Frederick | e789d26 | 2014-10-05 19:01:06 +0200 | [diff] [blame] | 926 | struct uart_cpm_port *pinfo = |
| 927 | container_of(port, struct uart_cpm_port, port); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 928 | int ret; |
| 929 | |
| 930 | pr_debug("CPM uart[%d]:request port\n", port->line); |
| 931 | |
| 932 | if (pinfo->flags & FLAG_CONSOLE) |
| 933 | return 0; |
| 934 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 935 | if (IS_SMC(pinfo)) { |
Scott Wood | c1dcfd9 | 2007-07-24 15:53:07 -0500 | [diff] [blame] | 936 | clrbits8(&pinfo->smcp->smc_smcm, SMCM_RX | SMCM_TX); |
| 937 | clrbits16(&pinfo->smcp->smc_smcmr, SMCMR_REN | SMCMR_TEN); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 938 | } else { |
Scott Wood | c1dcfd9 | 2007-07-24 15:53:07 -0500 | [diff] [blame] | 939 | clrbits16(&pinfo->sccp->scc_sccm, UART_SCCM_TX | UART_SCCM_RX); |
| 940 | clrbits32(&pinfo->sccp->scc_gsmrl, SCC_GSMRL_ENR | SCC_GSMRL_ENT); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 941 | } |
| 942 | |
| 943 | ret = cpm_uart_allocbuf(pinfo, 0); |
| 944 | |
| 945 | if (ret) |
| 946 | return ret; |
| 947 | |
| 948 | cpm_uart_initbd(pinfo); |
Kumar Gala | 311c462 | 2005-08-09 10:08:00 -0700 | [diff] [blame] | 949 | if (IS_SMC(pinfo)) |
| 950 | cpm_uart_init_smc(pinfo); |
| 951 | else |
| 952 | cpm_uart_init_scc(pinfo); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 953 | |
| 954 | return 0; |
| 955 | } |
| 956 | |
| 957 | static void cpm_uart_release_port(struct uart_port *port) |
| 958 | { |
Fabian Frederick | e789d26 | 2014-10-05 19:01:06 +0200 | [diff] [blame] | 959 | struct uart_cpm_port *pinfo = |
| 960 | container_of(port, struct uart_cpm_port, port); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 961 | |
| 962 | if (!(pinfo->flags & FLAG_CONSOLE)) |
| 963 | cpm_uart_freebuf(pinfo); |
| 964 | } |
| 965 | |
| 966 | /* |
| 967 | * Configure/autoconfigure the port. |
| 968 | */ |
| 969 | static void cpm_uart_config_port(struct uart_port *port, int flags) |
| 970 | { |
| 971 | pr_debug("CPM uart[%d]:config_port\n", port->line); |
| 972 | |
| 973 | if (flags & UART_CONFIG_TYPE) { |
| 974 | port->type = PORT_CPM; |
| 975 | cpm_uart_request_port(port); |
| 976 | } |
| 977 | } |
Jason Wessel | 8e21d04 | 2008-07-23 11:30:16 -0500 | [diff] [blame] | 978 | |
Dongdong Deng | 8cd774ad | 2010-06-17 11:13:40 +0800 | [diff] [blame] | 979 | #if defined(CONFIG_CONSOLE_POLL) || defined(CONFIG_SERIAL_CPM_CONSOLE) |
| 980 | /* |
| 981 | * Write a string to the serial port |
| 982 | * Note that this is called with interrupts already disabled |
| 983 | */ |
| 984 | static void cpm_uart_early_write(struct uart_cpm_port *pinfo, |
Daniel Thompson | 2fe686e | 2014-05-29 09:48:43 +0100 | [diff] [blame] | 985 | const char *string, u_int count, bool handle_linefeed) |
Dongdong Deng | 8cd774ad | 2010-06-17 11:13:40 +0800 | [diff] [blame] | 986 | { |
| 987 | unsigned int i; |
| 988 | cbd_t __iomem *bdp, *bdbase; |
| 989 | unsigned char *cpm_outp_addr; |
| 990 | |
| 991 | /* Get the address of the host memory buffer. |
| 992 | */ |
| 993 | bdp = pinfo->tx_cur; |
| 994 | bdbase = pinfo->tx_bd_base; |
| 995 | |
| 996 | /* |
| 997 | * Now, do each character. This is not as bad as it looks |
| 998 | * since this is a holding FIFO and not a transmitting FIFO. |
| 999 | * We could add the complexity of filling the entire transmit |
| 1000 | * buffer, but we would just wait longer between accesses...... |
| 1001 | */ |
| 1002 | for (i = 0; i < count; i++, string++) { |
| 1003 | /* Wait for transmitter fifo to empty. |
| 1004 | * Ready indicates output is ready, and xmt is doing |
| 1005 | * that, not that it is ready for us to send. |
| 1006 | */ |
| 1007 | while ((in_be16(&bdp->cbd_sc) & BD_SC_READY) != 0) |
| 1008 | ; |
| 1009 | |
| 1010 | /* Send the character out. |
| 1011 | * If the buffer address is in the CPM DPRAM, don't |
| 1012 | * convert it. |
| 1013 | */ |
| 1014 | cpm_outp_addr = cpm2cpu_addr(in_be32(&bdp->cbd_bufaddr), |
| 1015 | pinfo); |
| 1016 | *cpm_outp_addr = *string; |
| 1017 | |
| 1018 | out_be16(&bdp->cbd_datlen, 1); |
| 1019 | setbits16(&bdp->cbd_sc, BD_SC_READY); |
| 1020 | |
| 1021 | if (in_be16(&bdp->cbd_sc) & BD_SC_WRAP) |
| 1022 | bdp = bdbase; |
| 1023 | else |
| 1024 | bdp++; |
| 1025 | |
| 1026 | /* if a LF, also do CR... */ |
Daniel Thompson | 2fe686e | 2014-05-29 09:48:43 +0100 | [diff] [blame] | 1027 | if (handle_linefeed && *string == 10) { |
Dongdong Deng | 8cd774ad | 2010-06-17 11:13:40 +0800 | [diff] [blame] | 1028 | while ((in_be16(&bdp->cbd_sc) & BD_SC_READY) != 0) |
| 1029 | ; |
| 1030 | |
| 1031 | cpm_outp_addr = cpm2cpu_addr(in_be32(&bdp->cbd_bufaddr), |
| 1032 | pinfo); |
| 1033 | *cpm_outp_addr = 13; |
| 1034 | |
| 1035 | out_be16(&bdp->cbd_datlen, 1); |
| 1036 | setbits16(&bdp->cbd_sc, BD_SC_READY); |
| 1037 | |
| 1038 | if (in_be16(&bdp->cbd_sc) & BD_SC_WRAP) |
| 1039 | bdp = bdbase; |
| 1040 | else |
| 1041 | bdp++; |
| 1042 | } |
| 1043 | } |
| 1044 | |
| 1045 | /* |
| 1046 | * Finally, Wait for transmitter & holding register to empty |
| 1047 | * and restore the IER |
| 1048 | */ |
| 1049 | while ((in_be16(&bdp->cbd_sc) & BD_SC_READY) != 0) |
| 1050 | ; |
| 1051 | |
| 1052 | pinfo->tx_cur = bdp; |
| 1053 | } |
| 1054 | #endif |
| 1055 | |
Jason Wessel | 8e21d04 | 2008-07-23 11:30:16 -0500 | [diff] [blame] | 1056 | #ifdef CONFIG_CONSOLE_POLL |
| 1057 | /* Serial polling routines for writing and reading from the uart while |
| 1058 | * in an interrupt or debug context. |
| 1059 | */ |
| 1060 | |
| 1061 | #define GDB_BUF_SIZE 512 /* power of 2, please */ |
| 1062 | |
| 1063 | static char poll_buf[GDB_BUF_SIZE]; |
| 1064 | static char *pollp; |
| 1065 | static int poll_chars; |
| 1066 | |
| 1067 | static int poll_wait_key(char *obuf, struct uart_cpm_port *pinfo) |
| 1068 | { |
| 1069 | u_char c, *cp; |
| 1070 | volatile cbd_t *bdp; |
| 1071 | int i; |
| 1072 | |
| 1073 | /* Get the address of the host memory buffer. |
| 1074 | */ |
| 1075 | bdp = pinfo->rx_cur; |
Christophe Leroy | 96d39a0 | 2018-09-14 10:32:50 +0000 | [diff] [blame] | 1076 | if (bdp->cbd_sc & BD_SC_EMPTY) |
| 1077 | return NO_POLL_CHAR; |
Jason Wessel | 8e21d04 | 2008-07-23 11:30:16 -0500 | [diff] [blame] | 1078 | |
| 1079 | /* If the buffer address is in the CPM DPRAM, don't |
| 1080 | * convert it. |
| 1081 | */ |
| 1082 | cp = cpm2cpu_addr(bdp->cbd_bufaddr, pinfo); |
| 1083 | |
| 1084 | if (obuf) { |
| 1085 | i = c = bdp->cbd_datlen; |
| 1086 | while (i-- > 0) |
| 1087 | *obuf++ = *cp++; |
| 1088 | } else |
| 1089 | c = *cp; |
| 1090 | bdp->cbd_sc &= ~(BD_SC_BR | BD_SC_FR | BD_SC_PR | BD_SC_OV | BD_SC_ID); |
| 1091 | bdp->cbd_sc |= BD_SC_EMPTY; |
| 1092 | |
| 1093 | if (bdp->cbd_sc & BD_SC_WRAP) |
| 1094 | bdp = pinfo->rx_bd_base; |
| 1095 | else |
| 1096 | bdp++; |
| 1097 | pinfo->rx_cur = (cbd_t *)bdp; |
| 1098 | |
| 1099 | return (int)c; |
| 1100 | } |
| 1101 | |
| 1102 | static int cpm_get_poll_char(struct uart_port *port) |
| 1103 | { |
Fabian Frederick | e789d26 | 2014-10-05 19:01:06 +0200 | [diff] [blame] | 1104 | struct uart_cpm_port *pinfo = |
| 1105 | container_of(port, struct uart_cpm_port, port); |
Jason Wessel | 8e21d04 | 2008-07-23 11:30:16 -0500 | [diff] [blame] | 1106 | |
| 1107 | if (!serial_polled) { |
| 1108 | serial_polled = 1; |
| 1109 | poll_chars = 0; |
| 1110 | } |
| 1111 | if (poll_chars <= 0) { |
Christophe Leroy | 96d39a0 | 2018-09-14 10:32:50 +0000 | [diff] [blame] | 1112 | int ret = poll_wait_key(poll_buf, pinfo); |
| 1113 | |
| 1114 | if (ret == NO_POLL_CHAR) |
| 1115 | return ret; |
| 1116 | poll_chars = ret; |
Jason Wessel | 8e21d04 | 2008-07-23 11:30:16 -0500 | [diff] [blame] | 1117 | pollp = poll_buf; |
| 1118 | } |
| 1119 | poll_chars--; |
| 1120 | return *pollp++; |
| 1121 | } |
| 1122 | |
| 1123 | static void cpm_put_poll_char(struct uart_port *port, |
| 1124 | unsigned char c) |
| 1125 | { |
Fabian Frederick | e789d26 | 2014-10-05 19:01:06 +0200 | [diff] [blame] | 1126 | struct uart_cpm_port *pinfo = |
| 1127 | container_of(port, struct uart_cpm_port, port); |
Jason Wessel | 8e21d04 | 2008-07-23 11:30:16 -0500 | [diff] [blame] | 1128 | static char ch[2]; |
| 1129 | |
| 1130 | ch[0] = (char)c; |
Daniel Thompson | 2fe686e | 2014-05-29 09:48:43 +0100 | [diff] [blame] | 1131 | cpm_uart_early_write(pinfo, ch, 1, false); |
Jason Wessel | 8e21d04 | 2008-07-23 11:30:16 -0500 | [diff] [blame] | 1132 | } |
| 1133 | #endif /* CONFIG_CONSOLE_POLL */ |
| 1134 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1135 | static struct uart_ops cpm_uart_pops = { |
| 1136 | .tx_empty = cpm_uart_tx_empty, |
| 1137 | .set_mctrl = cpm_uart_set_mctrl, |
| 1138 | .get_mctrl = cpm_uart_get_mctrl, |
| 1139 | .stop_tx = cpm_uart_stop_tx, |
| 1140 | .start_tx = cpm_uart_start_tx, |
| 1141 | .stop_rx = cpm_uart_stop_rx, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1142 | .break_ctl = cpm_uart_break_ctl, |
| 1143 | .startup = cpm_uart_startup, |
| 1144 | .shutdown = cpm_uart_shutdown, |
| 1145 | .set_termios = cpm_uart_set_termios, |
| 1146 | .type = cpm_uart_type, |
| 1147 | .release_port = cpm_uart_release_port, |
| 1148 | .request_port = cpm_uart_request_port, |
| 1149 | .config_port = cpm_uart_config_port, |
| 1150 | .verify_port = cpm_uart_verify_port, |
Jason Wessel | 8e21d04 | 2008-07-23 11:30:16 -0500 | [diff] [blame] | 1151 | #ifdef CONFIG_CONSOLE_POLL |
| 1152 | .poll_get_char = cpm_get_poll_char, |
| 1153 | .poll_put_char = cpm_put_poll_char, |
| 1154 | #endif |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1155 | }; |
| 1156 | |
Scott Wood | 7ae8703 | 2007-07-17 17:59:06 -0500 | [diff] [blame] | 1157 | struct uart_cpm_port cpm_uart_ports[UART_NR]; |
| 1158 | |
Scott Wood | c1dcfd9 | 2007-07-24 15:53:07 -0500 | [diff] [blame] | 1159 | static int cpm_uart_init_port(struct device_node *np, |
| 1160 | struct uart_cpm_port *pinfo) |
Scott Wood | 7ae8703 | 2007-07-17 17:59:06 -0500 | [diff] [blame] | 1161 | { |
| 1162 | const u32 *data; |
Scott Wood | c1dcfd9 | 2007-07-24 15:53:07 -0500 | [diff] [blame] | 1163 | void __iomem *mem, *pram; |
Scott Wood | 7ae8703 | 2007-07-17 17:59:06 -0500 | [diff] [blame] | 1164 | int len; |
| 1165 | int ret; |
Laurent Pinchart | 7485d26 | 2008-07-24 18:36:37 +0200 | [diff] [blame] | 1166 | int i; |
Scott Wood | 7ae8703 | 2007-07-17 17:59:06 -0500 | [diff] [blame] | 1167 | |
Laurent Pinchart | 8077655 | 2008-07-28 10:42:16 +0200 | [diff] [blame] | 1168 | data = of_get_property(np, "clock", NULL); |
| 1169 | if (data) { |
| 1170 | struct clk *clk = clk_get(NULL, (const char*)data); |
| 1171 | if (!IS_ERR(clk)) |
| 1172 | pinfo->clk = clk; |
Scott Wood | 7ae8703 | 2007-07-17 17:59:06 -0500 | [diff] [blame] | 1173 | } |
Laurent Pinchart | 8077655 | 2008-07-28 10:42:16 +0200 | [diff] [blame] | 1174 | if (!pinfo->clk) { |
| 1175 | data = of_get_property(np, "fsl,cpm-brg", &len); |
| 1176 | if (!data || len != 4) { |
| 1177 | printk(KERN_ERR "CPM UART %s has no/invalid " |
| 1178 | "fsl,cpm-brg property.\n", np->name); |
| 1179 | return -EINVAL; |
| 1180 | } |
| 1181 | pinfo->brg = *data; |
| 1182 | } |
Scott Wood | 7ae8703 | 2007-07-17 17:59:06 -0500 | [diff] [blame] | 1183 | |
| 1184 | data = of_get_property(np, "fsl,cpm-command", &len); |
| 1185 | if (!data || len != 4) { |
| 1186 | printk(KERN_ERR "CPM UART %s has no/invalid " |
| 1187 | "fsl,cpm-command property.\n", np->name); |
| 1188 | return -EINVAL; |
| 1189 | } |
| 1190 | pinfo->command = *data; |
| 1191 | |
| 1192 | mem = of_iomap(np, 0); |
| 1193 | if (!mem) |
| 1194 | return -ENOMEM; |
| 1195 | |
Scott Wood | 7ae8703 | 2007-07-17 17:59:06 -0500 | [diff] [blame] | 1196 | if (of_device_is_compatible(np, "fsl,cpm1-scc-uart") || |
| 1197 | of_device_is_compatible(np, "fsl,cpm2-scc-uart")) { |
| 1198 | pinfo->sccp = mem; |
Laurent Pinchart | d464df2 | 2008-04-10 17:01:27 +0200 | [diff] [blame] | 1199 | pinfo->sccup = pram = cpm_uart_map_pram(pinfo, np); |
Scott Wood | 7ae8703 | 2007-07-17 17:59:06 -0500 | [diff] [blame] | 1200 | } else if (of_device_is_compatible(np, "fsl,cpm1-smc-uart") || |
| 1201 | of_device_is_compatible(np, "fsl,cpm2-smc-uart")) { |
| 1202 | pinfo->flags |= FLAG_SMC; |
| 1203 | pinfo->smcp = mem; |
Laurent Pinchart | d464df2 | 2008-04-10 17:01:27 +0200 | [diff] [blame] | 1204 | pinfo->smcup = pram = cpm_uart_map_pram(pinfo, np); |
Scott Wood | 7ae8703 | 2007-07-17 17:59:06 -0500 | [diff] [blame] | 1205 | } else { |
| 1206 | ret = -ENODEV; |
Laurent Pinchart | d464df2 | 2008-04-10 17:01:27 +0200 | [diff] [blame] | 1207 | goto out_mem; |
| 1208 | } |
| 1209 | |
| 1210 | if (!pram) { |
| 1211 | ret = -ENOMEM; |
| 1212 | goto out_mem; |
Scott Wood | 7ae8703 | 2007-07-17 17:59:06 -0500 | [diff] [blame] | 1213 | } |
| 1214 | |
| 1215 | pinfo->tx_nrfifos = TX_NUM_FIFO; |
| 1216 | pinfo->tx_fifosize = TX_BUF_SIZE; |
| 1217 | pinfo->rx_nrfifos = RX_NUM_FIFO; |
| 1218 | pinfo->rx_fifosize = RX_BUF_SIZE; |
| 1219 | |
| 1220 | pinfo->port.uartclk = ppc_proc_freq; |
| 1221 | pinfo->port.mapbase = (unsigned long)mem; |
| 1222 | pinfo->port.type = PORT_CPM; |
| 1223 | pinfo->port.ops = &cpm_uart_pops, |
| 1224 | pinfo->port.iotype = UPIO_MEM; |
Laurent Pinchart | dc32081 | 2008-07-02 10:58:45 +0200 | [diff] [blame] | 1225 | pinfo->port.fifosize = pinfo->tx_nrfifos * pinfo->tx_fifosize; |
Scott Wood | 7ae8703 | 2007-07-17 17:59:06 -0500 | [diff] [blame] | 1226 | spin_lock_init(&pinfo->port.lock); |
| 1227 | |
Thierry Reding | f757849 | 2013-09-18 15:24:44 +0200 | [diff] [blame] | 1228 | pinfo->port.irq = irq_of_parse_and_map(np, 0); |
Scott Wood | 7ae8703 | 2007-07-17 17:59:06 -0500 | [diff] [blame] | 1229 | if (pinfo->port.irq == NO_IRQ) { |
| 1230 | ret = -EINVAL; |
| 1231 | goto out_pram; |
| 1232 | } |
| 1233 | |
Christophe Leroy | a416bfa | 2013-08-21 17:59:24 +0200 | [diff] [blame] | 1234 | for (i = 0; i < NUM_GPIOS; i++) { |
| 1235 | int gpio; |
| 1236 | |
| 1237 | pinfo->gpios[i] = -1; |
| 1238 | |
| 1239 | gpio = of_get_gpio(np, i); |
| 1240 | |
| 1241 | if (gpio_is_valid(gpio)) { |
| 1242 | ret = gpio_request(gpio, "cpm_uart"); |
| 1243 | if (ret) { |
| 1244 | pr_err("can't request gpio #%d: %d\n", i, ret); |
| 1245 | continue; |
| 1246 | } |
| 1247 | if (i == GPIO_RTS || i == GPIO_DTR) |
| 1248 | ret = gpio_direction_output(gpio, 0); |
| 1249 | else |
| 1250 | ret = gpio_direction_input(gpio); |
| 1251 | if (ret) { |
| 1252 | pr_err("can't set direction for gpio #%d: %d\n", |
| 1253 | i, ret); |
| 1254 | gpio_free(gpio); |
| 1255 | continue; |
| 1256 | } |
| 1257 | pinfo->gpios[i] = gpio; |
| 1258 | } |
| 1259 | } |
Laurent Pinchart | 7485d26 | 2008-07-24 18:36:37 +0200 | [diff] [blame] | 1260 | |
Scott Wood | 4d8107f | 2009-04-03 16:15:49 -0500 | [diff] [blame] | 1261 | #ifdef CONFIG_PPC_EARLY_DEBUG_CPM |
| 1262 | udbg_putc = NULL; |
| 1263 | #endif |
| 1264 | |
Scott Wood | 7ae8703 | 2007-07-17 17:59:06 -0500 | [diff] [blame] | 1265 | return cpm_uart_request_port(&pinfo->port); |
| 1266 | |
| 1267 | out_pram: |
Laurent Pinchart | d464df2 | 2008-04-10 17:01:27 +0200 | [diff] [blame] | 1268 | cpm_uart_unmap_pram(pinfo, pram); |
Scott Wood | 7ae8703 | 2007-07-17 17:59:06 -0500 | [diff] [blame] | 1269 | out_mem: |
| 1270 | iounmap(mem); |
| 1271 | return ret; |
| 1272 | } |
| 1273 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1274 | #ifdef CONFIG_SERIAL_CPM_CONSOLE |
| 1275 | /* |
| 1276 | * Print a string to the serial port trying not to disturb |
| 1277 | * any possible real use of the port... |
| 1278 | * |
| 1279 | * Note that this is called with interrupts already disabled |
| 1280 | */ |
| 1281 | static void cpm_uart_console_write(struct console *co, const char *s, |
| 1282 | u_int count) |
| 1283 | { |
Scott Wood | 7ae8703 | 2007-07-17 17:59:06 -0500 | [diff] [blame] | 1284 | struct uart_cpm_port *pinfo = &cpm_uart_ports[co->index]; |
Rune Torgersen | 491a7a4 | 2008-05-20 14:39:17 -0500 | [diff] [blame] | 1285 | unsigned long flags; |
| 1286 | int nolock = oops_in_progress; |
| 1287 | |
| 1288 | if (unlikely(nolock)) { |
| 1289 | local_irq_save(flags); |
| 1290 | } else { |
| 1291 | spin_lock_irqsave(&pinfo->port.lock, flags); |
| 1292 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1293 | |
Daniel Thompson | 2fe686e | 2014-05-29 09:48:43 +0100 | [diff] [blame] | 1294 | cpm_uart_early_write(pinfo, s, count, true); |
Rune Torgersen | 491a7a4 | 2008-05-20 14:39:17 -0500 | [diff] [blame] | 1295 | |
| 1296 | if (unlikely(nolock)) { |
| 1297 | local_irq_restore(flags); |
| 1298 | } else { |
| 1299 | spin_unlock_irqrestore(&pinfo->port.lock, flags); |
| 1300 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1301 | } |
| 1302 | |
Vitaly Bordug | e27987c | 2006-04-25 20:26:41 +0400 | [diff] [blame] | 1303 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1304 | static int __init cpm_uart_console_setup(struct console *co, char *options) |
| 1305 | { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1306 | int baud = 38400; |
| 1307 | int bits = 8; |
| 1308 | int parity = 'n'; |
| 1309 | int flow = 'n'; |
| 1310 | int ret; |
Scott Wood | 7ae8703 | 2007-07-17 17:59:06 -0500 | [diff] [blame] | 1311 | struct uart_cpm_port *pinfo; |
| 1312 | struct uart_port *port; |
| 1313 | |
Scott Wood | 7ae8703 | 2007-07-17 17:59:06 -0500 | [diff] [blame] | 1314 | struct device_node *np = NULL; |
| 1315 | int i = 0; |
| 1316 | |
| 1317 | if (co->index >= UART_NR) { |
| 1318 | printk(KERN_ERR "cpm_uart: console index %d too high\n", |
| 1319 | co->index); |
| 1320 | return -ENODEV; |
| 1321 | } |
| 1322 | |
| 1323 | do { |
| 1324 | np = of_find_node_by_type(np, "serial"); |
| 1325 | if (!np) |
| 1326 | return -ENODEV; |
| 1327 | |
| 1328 | if (!of_device_is_compatible(np, "fsl,cpm1-smc-uart") && |
| 1329 | !of_device_is_compatible(np, "fsl,cpm1-scc-uart") && |
| 1330 | !of_device_is_compatible(np, "fsl,cpm2-smc-uart") && |
| 1331 | !of_device_is_compatible(np, "fsl,cpm2-scc-uart")) |
| 1332 | i--; |
| 1333 | } while (i++ != co->index); |
| 1334 | |
| 1335 | pinfo = &cpm_uart_ports[co->index]; |
| 1336 | |
| 1337 | pinfo->flags |= FLAG_CONSOLE; |
| 1338 | port = &pinfo->port; |
| 1339 | |
| 1340 | ret = cpm_uart_init_port(np, pinfo); |
| 1341 | of_node_put(np); |
| 1342 | if (ret) |
| 1343 | return ret; |
| 1344 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1345 | if (options) { |
| 1346 | uart_parse_options(options, &baud, &parity, &bits, &flow); |
| 1347 | } else { |
Vitaly Bordug | 3dd0dcb | 2006-09-21 17:27:15 +0400 | [diff] [blame] | 1348 | if ((baud = uart_baudrate()) == -1) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1349 | baud = 9600; |
| 1350 | } |
| 1351 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1352 | if (IS_SMC(pinfo)) { |
Nye Liu | ae2d4c3 | 2008-07-23 21:29:50 -0700 | [diff] [blame] | 1353 | out_be16(&pinfo->smcup->smc_brkcr, 0); |
| 1354 | cpm_line_cr_cmd(pinfo, CPM_CR_STOP_TX); |
Scott Wood | c1dcfd9 | 2007-07-24 15:53:07 -0500 | [diff] [blame] | 1355 | clrbits8(&pinfo->smcp->smc_smcm, SMCM_RX | SMCM_TX); |
| 1356 | clrbits16(&pinfo->smcp->smc_smcmr, SMCMR_REN | SMCMR_TEN); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1357 | } else { |
Nye Liu | ae2d4c3 | 2008-07-23 21:29:50 -0700 | [diff] [blame] | 1358 | out_be16(&pinfo->sccup->scc_brkcr, 0); |
| 1359 | cpm_line_cr_cmd(pinfo, CPM_CR_GRA_STOP_TX); |
Scott Wood | c1dcfd9 | 2007-07-24 15:53:07 -0500 | [diff] [blame] | 1360 | clrbits16(&pinfo->sccp->scc_sccm, UART_SCCM_TX | UART_SCCM_RX); |
| 1361 | clrbits32(&pinfo->sccp->scc_gsmrl, SCC_GSMRL_ENR | SCC_GSMRL_ENT); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1362 | } |
| 1363 | |
| 1364 | ret = cpm_uart_allocbuf(pinfo, 1); |
| 1365 | |
| 1366 | if (ret) |
| 1367 | return ret; |
| 1368 | |
| 1369 | cpm_uart_initbd(pinfo); |
| 1370 | |
| 1371 | if (IS_SMC(pinfo)) |
| 1372 | cpm_uart_init_smc(pinfo); |
| 1373 | else |
| 1374 | cpm_uart_init_scc(pinfo); |
| 1375 | |
| 1376 | uart_set_options(port, co, baud, parity, bits, flow); |
Scott Wood | d948a29 | 2007-07-17 18:09:33 -0500 | [diff] [blame] | 1377 | cpm_line_cr_cmd(pinfo, CPM_CR_RESTART_TX); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1378 | |
| 1379 | return 0; |
| 1380 | } |
| 1381 | |
Kumar Gala | 36d2f5a | 2005-08-09 10:08:02 -0700 | [diff] [blame] | 1382 | static struct uart_driver cpm_reg; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1383 | static struct console cpm_scc_uart_console = { |
Kumar Gala | 36d2f5a | 2005-08-09 10:08:02 -0700 | [diff] [blame] | 1384 | .name = "ttyCPM", |
| 1385 | .write = cpm_uart_console_write, |
| 1386 | .device = uart_console_device, |
| 1387 | .setup = cpm_uart_console_setup, |
| 1388 | .flags = CON_PRINTBUFFER, |
| 1389 | .index = -1, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1390 | .data = &cpm_reg, |
| 1391 | }; |
| 1392 | |
Scott Wood | c1dcfd9 | 2007-07-24 15:53:07 -0500 | [diff] [blame] | 1393 | static int __init cpm_uart_console_init(void) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1394 | { |
Vitaly Bordug | e27987c | 2006-04-25 20:26:41 +0400 | [diff] [blame] | 1395 | register_console(&cpm_scc_uart_console); |
| 1396 | return 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1397 | } |
| 1398 | |
| 1399 | console_initcall(cpm_uart_console_init); |
| 1400 | |
| 1401 | #define CPM_UART_CONSOLE &cpm_scc_uart_console |
| 1402 | #else |
| 1403 | #define CPM_UART_CONSOLE NULL |
| 1404 | #endif |
| 1405 | |
| 1406 | static struct uart_driver cpm_reg = { |
| 1407 | .owner = THIS_MODULE, |
| 1408 | .driver_name = "ttyCPM", |
| 1409 | .dev_name = "ttyCPM", |
| 1410 | .major = SERIAL_CPM_MAJOR, |
| 1411 | .minor = SERIAL_CPM_MINOR, |
| 1412 | .cons = CPM_UART_CONSOLE, |
Scott Wood | 7ae8703 | 2007-07-17 17:59:06 -0500 | [diff] [blame] | 1413 | .nr = UART_NR, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1414 | }; |
Scott Wood | 7ae8703 | 2007-07-17 17:59:06 -0500 | [diff] [blame] | 1415 | |
Scott Wood | 7ae8703 | 2007-07-17 17:59:06 -0500 | [diff] [blame] | 1416 | static int probe_index; |
| 1417 | |
Bill Pemberton | 9671f09 | 2012-11-19 13:21:50 -0500 | [diff] [blame] | 1418 | static int cpm_uart_probe(struct platform_device *ofdev) |
Scott Wood | 7ae8703 | 2007-07-17 17:59:06 -0500 | [diff] [blame] | 1419 | { |
| 1420 | int index = probe_index++; |
| 1421 | struct uart_cpm_port *pinfo = &cpm_uart_ports[index]; |
| 1422 | int ret; |
| 1423 | |
| 1424 | pinfo->port.line = index; |
| 1425 | |
| 1426 | if (index >= UART_NR) |
| 1427 | return -ENODEV; |
| 1428 | |
Jingoo Han | 696faed | 2013-05-23 19:39:36 +0900 | [diff] [blame] | 1429 | platform_set_drvdata(ofdev, pinfo); |
Scott Wood | 7ae8703 | 2007-07-17 17:59:06 -0500 | [diff] [blame] | 1430 | |
Scott Wood | bd86ef3 | 2009-04-03 15:48:44 -0500 | [diff] [blame] | 1431 | /* initialize the device pointer for the port */ |
| 1432 | pinfo->port.dev = &ofdev->dev; |
| 1433 | |
Grant Likely | 61c7a08 | 2010-04-13 16:12:29 -0700 | [diff] [blame] | 1434 | ret = cpm_uart_init_port(ofdev->dev.of_node, pinfo); |
Scott Wood | 7ae8703 | 2007-07-17 17:59:06 -0500 | [diff] [blame] | 1435 | if (ret) |
| 1436 | return ret; |
| 1437 | |
| 1438 | return uart_add_one_port(&cpm_reg, &pinfo->port); |
| 1439 | } |
| 1440 | |
Bill Pemberton | ae8d8a1 | 2012-11-19 13:26:18 -0500 | [diff] [blame] | 1441 | static int cpm_uart_remove(struct platform_device *ofdev) |
Scott Wood | 7ae8703 | 2007-07-17 17:59:06 -0500 | [diff] [blame] | 1442 | { |
Jingoo Han | 696faed | 2013-05-23 19:39:36 +0900 | [diff] [blame] | 1443 | struct uart_cpm_port *pinfo = platform_get_drvdata(ofdev); |
Scott Wood | 7ae8703 | 2007-07-17 17:59:06 -0500 | [diff] [blame] | 1444 | return uart_remove_one_port(&cpm_reg, &pinfo->port); |
| 1445 | } |
| 1446 | |
Fabian Frederick | ed0bb23 | 2015-03-16 20:17:11 +0100 | [diff] [blame] | 1447 | static const struct of_device_id cpm_uart_match[] = { |
Scott Wood | 7ae8703 | 2007-07-17 17:59:06 -0500 | [diff] [blame] | 1448 | { |
| 1449 | .compatible = "fsl,cpm1-smc-uart", |
| 1450 | }, |
| 1451 | { |
| 1452 | .compatible = "fsl,cpm1-scc-uart", |
| 1453 | }, |
| 1454 | { |
| 1455 | .compatible = "fsl,cpm2-smc-uart", |
| 1456 | }, |
| 1457 | { |
| 1458 | .compatible = "fsl,cpm2-scc-uart", |
| 1459 | }, |
| 1460 | {} |
| 1461 | }; |
Luis de Bethencourt | 618bbaa | 2015-09-18 20:03:14 +0200 | [diff] [blame] | 1462 | MODULE_DEVICE_TABLE(of, cpm_uart_match); |
Scott Wood | 7ae8703 | 2007-07-17 17:59:06 -0500 | [diff] [blame] | 1463 | |
Grant Likely | 793218d | 2011-02-22 21:10:26 -0700 | [diff] [blame] | 1464 | static struct platform_driver cpm_uart_driver = { |
Grant Likely | 4018294 | 2010-04-13 16:13:02 -0700 | [diff] [blame] | 1465 | .driver = { |
| 1466 | .name = "cpm_uart", |
Grant Likely | 4018294 | 2010-04-13 16:13:02 -0700 | [diff] [blame] | 1467 | .of_match_table = cpm_uart_match, |
| 1468 | }, |
Scott Wood | 7ae8703 | 2007-07-17 17:59:06 -0500 | [diff] [blame] | 1469 | .probe = cpm_uart_probe, |
| 1470 | .remove = cpm_uart_remove, |
| 1471 | }; |
| 1472 | |
| 1473 | static int __init cpm_uart_init(void) |
| 1474 | { |
| 1475 | int ret = uart_register_driver(&cpm_reg); |
| 1476 | if (ret) |
| 1477 | return ret; |
| 1478 | |
Grant Likely | 793218d | 2011-02-22 21:10:26 -0700 | [diff] [blame] | 1479 | ret = platform_driver_register(&cpm_uart_driver); |
Scott Wood | 7ae8703 | 2007-07-17 17:59:06 -0500 | [diff] [blame] | 1480 | if (ret) |
| 1481 | uart_unregister_driver(&cpm_reg); |
| 1482 | |
| 1483 | return ret; |
| 1484 | } |
| 1485 | |
| 1486 | static void __exit cpm_uart_exit(void) |
| 1487 | { |
Grant Likely | 793218d | 2011-02-22 21:10:26 -0700 | [diff] [blame] | 1488 | platform_driver_unregister(&cpm_uart_driver); |
Scott Wood | 7ae8703 | 2007-07-17 17:59:06 -0500 | [diff] [blame] | 1489 | uart_unregister_driver(&cpm_reg); |
| 1490 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1491 | |
| 1492 | module_init(cpm_uart_init); |
| 1493 | module_exit(cpm_uart_exit); |
| 1494 | |
| 1495 | MODULE_AUTHOR("Kumar Gala/Antoniou Pantelis"); |
| 1496 | MODULE_DESCRIPTION("CPM SCC/SMC port driver $Revision: 0.01 $"); |
| 1497 | MODULE_LICENSE("GPL"); |
| 1498 | MODULE_ALIAS_CHARDEV(SERIAL_CPM_MAJOR, SERIAL_CPM_MINOR); |