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 AMBA serial ports |
| 3 | * |
| 4 | * Based on drivers/char/serial.c, by Linus Torvalds, Theodore Ts'o. |
| 5 | * |
| 6 | * Copyright 1999 ARM Limited |
| 7 | * Copyright (C) 2000 Deep Blue Solutions Ltd. |
Russell King | 68b65f7 | 2010-12-22 17:24:39 +0000 | [diff] [blame] | 8 | * Copyright (C) 2010 ST-Ericsson SA |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 9 | * |
| 10 | * This program is free software; you can redistribute it and/or modify |
| 11 | * it under the terms of the GNU General Public License as published by |
| 12 | * the Free Software Foundation; either version 2 of the License, or |
| 13 | * (at your option) any later version. |
| 14 | * |
| 15 | * This program is distributed in the hope that it will be useful, |
| 16 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 17 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 18 | * GNU General Public License for more details. |
| 19 | * |
| 20 | * You should have received a copy of the GNU General Public License |
| 21 | * along with this program; if not, write to the Free Software |
| 22 | * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA |
| 23 | * |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 24 | * This is a generic driver for ARM AMBA-type serial ports. They |
| 25 | * have a lot of 16550-like features, but are not register compatible. |
| 26 | * Note that although they do have CTS, DCD and DSR inputs, they do |
| 27 | * not have an RI input, nor do they have DTR or RTS outputs. If |
| 28 | * required, these have to be supplied via some other means (eg, GPIO) |
| 29 | * and hooked into this driver. |
| 30 | */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 31 | |
Chanho Min | cb06ff1 | 2013-03-27 18:38:11 +0900 | [diff] [blame] | 32 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 33 | #if defined(CONFIG_SERIAL_AMBA_PL011_CONSOLE) && defined(CONFIG_MAGIC_SYSRQ) |
| 34 | #define SUPPORT_SYSRQ |
| 35 | #endif |
| 36 | |
| 37 | #include <linux/module.h> |
| 38 | #include <linux/ioport.h> |
| 39 | #include <linux/init.h> |
| 40 | #include <linux/console.h> |
| 41 | #include <linux/sysrq.h> |
| 42 | #include <linux/device.h> |
| 43 | #include <linux/tty.h> |
| 44 | #include <linux/tty_flip.h> |
| 45 | #include <linux/serial_core.h> |
| 46 | #include <linux/serial.h> |
Russell King | a62c80e | 2006-01-07 13:52:45 +0000 | [diff] [blame] | 47 | #include <linux/amba/bus.h> |
| 48 | #include <linux/amba/serial.h> |
Russell King | f8ce254 | 2006-01-07 16:15:52 +0000 | [diff] [blame] | 49 | #include <linux/clk.h> |
Tejun Heo | 5a0e3ad | 2010-03-24 17:04:11 +0900 | [diff] [blame] | 50 | #include <linux/slab.h> |
Russell King | 68b65f7 | 2010-12-22 17:24:39 +0000 | [diff] [blame] | 51 | #include <linux/dmaengine.h> |
| 52 | #include <linux/dma-mapping.h> |
| 53 | #include <linux/scatterlist.h> |
Shreshtha Kumar Sahu | c16d51a | 2011-06-13 10:11:33 +0200 | [diff] [blame] | 54 | #include <linux/delay.h> |
Viresh Kumar | 258aea7 | 2012-02-01 16:12:19 +0530 | [diff] [blame] | 55 | #include <linux/types.h> |
Matthew Leach | 32614aa | 2012-08-28 16:41:28 +0100 | [diff] [blame] | 56 | #include <linux/of.h> |
| 57 | #include <linux/of_device.h> |
Shawn Guo | 258e055 | 2012-05-06 22:53:35 +0800 | [diff] [blame] | 58 | #include <linux/pinctrl/consumer.h> |
Alessandro Rubini | cb70706 | 2012-06-24 12:46:37 +0100 | [diff] [blame] | 59 | #include <linux/sizes.h> |
Linus Walleij | de60958 | 2012-10-15 13:36:01 +0200 | [diff] [blame] | 60 | #include <linux/io.h> |
Graeme Gregory | 3db9ab0 | 2015-05-21 17:26:24 +0100 | [diff] [blame] | 61 | #include <linux/acpi.h> |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 62 | |
Russell King | 9f25bc5 | 2015-11-03 14:51:13 +0000 | [diff] [blame^] | 63 | #include "amba-pl011.h" |
| 64 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 65 | #define UART_NR 14 |
| 66 | |
| 67 | #define SERIAL_AMBA_MAJOR 204 |
| 68 | #define SERIAL_AMBA_MINOR 64 |
| 69 | #define SERIAL_AMBA_NR UART_NR |
| 70 | |
| 71 | #define AMBA_ISR_PASS_LIMIT 256 |
| 72 | |
Russell King | b63d4f0 | 2005-11-19 11:10:35 +0000 | [diff] [blame] | 73 | #define UART_DR_ERROR (UART011_DR_OE|UART011_DR_BE|UART011_DR_PE|UART011_DR_FE) |
| 74 | #define UART_DUMMY_DR_RX (1 << 16) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 75 | |
Alessandro Rubini | 5926a29 | 2009-06-04 17:43:04 +0100 | [diff] [blame] | 76 | /* There is by now at least one vendor with differing details, so handle it */ |
| 77 | struct vendor_data { |
| 78 | unsigned int ifls; |
Linus Walleij | ec489aa | 2010-06-02 08:13:52 +0100 | [diff] [blame] | 79 | unsigned int lcrh_tx; |
| 80 | unsigned int lcrh_rx; |
Linus Walleij | ac3e3fb | 2010-06-02 20:40:22 +0100 | [diff] [blame] | 81 | bool oversampling; |
Russell King | 38d6243 | 2010-12-22 17:59:16 +0000 | [diff] [blame] | 82 | bool dma_threshold; |
Rajanikanth H.V | 4fd0690 | 2012-03-26 11:17:02 +0200 | [diff] [blame] | 83 | bool cts_event_workaround; |
Andre Przywara | 71eec48 | 2015-05-21 17:26:21 +0100 | [diff] [blame] | 84 | bool always_enabled; |
Andre Przywara | cefc2d1 | 2015-05-21 17:26:22 +0100 | [diff] [blame] | 85 | bool fixed_options; |
Jongsung Kim | 78506f2 | 2013-04-15 14:45:25 +0900 | [diff] [blame] | 86 | |
Jongsung Kim | ea33640 | 2013-05-10 18:05:35 +0900 | [diff] [blame] | 87 | unsigned int (*get_fifosize)(struct amba_device *dev); |
Alessandro Rubini | 5926a29 | 2009-06-04 17:43:04 +0100 | [diff] [blame] | 88 | }; |
| 89 | |
Jongsung Kim | ea33640 | 2013-05-10 18:05:35 +0900 | [diff] [blame] | 90 | static unsigned int get_fifosize_arm(struct amba_device *dev) |
Jongsung Kim | 78506f2 | 2013-04-15 14:45:25 +0900 | [diff] [blame] | 91 | { |
Jongsung Kim | ea33640 | 2013-05-10 18:05:35 +0900 | [diff] [blame] | 92 | return amba_rev(dev) < 3 ? 16 : 32; |
Jongsung Kim | 78506f2 | 2013-04-15 14:45:25 +0900 | [diff] [blame] | 93 | } |
| 94 | |
Alessandro Rubini | 5926a29 | 2009-06-04 17:43:04 +0100 | [diff] [blame] | 95 | static struct vendor_data vendor_arm = { |
| 96 | .ifls = UART011_IFLS_RX4_8|UART011_IFLS_TX4_8, |
Russell King | 9f25bc5 | 2015-11-03 14:51:13 +0000 | [diff] [blame^] | 97 | .lcrh_tx = REG_LCRH, |
| 98 | .lcrh_rx = REG_LCRH, |
Linus Walleij | ac3e3fb | 2010-06-02 20:40:22 +0100 | [diff] [blame] | 99 | .oversampling = false, |
Russell King | 38d6243 | 2010-12-22 17:59:16 +0000 | [diff] [blame] | 100 | .dma_threshold = false, |
Rajanikanth H.V | 4fd0690 | 2012-03-26 11:17:02 +0200 | [diff] [blame] | 101 | .cts_event_workaround = false, |
Andre Przywara | 71eec48 | 2015-05-21 17:26:21 +0100 | [diff] [blame] | 102 | .always_enabled = false, |
Andre Przywara | cefc2d1 | 2015-05-21 17:26:22 +0100 | [diff] [blame] | 103 | .fixed_options = false, |
Jongsung Kim | 78506f2 | 2013-04-15 14:45:25 +0900 | [diff] [blame] | 104 | .get_fifosize = get_fifosize_arm, |
Alessandro Rubini | 5926a29 | 2009-06-04 17:43:04 +0100 | [diff] [blame] | 105 | }; |
| 106 | |
Andre Przywara | 0dd1e24 | 2015-05-21 17:26:23 +0100 | [diff] [blame] | 107 | static struct vendor_data vendor_sbsa = { |
| 108 | .oversampling = false, |
| 109 | .dma_threshold = false, |
| 110 | .cts_event_workaround = false, |
| 111 | .always_enabled = true, |
| 112 | .fixed_options = true, |
| 113 | }; |
| 114 | |
Jongsung Kim | ea33640 | 2013-05-10 18:05:35 +0900 | [diff] [blame] | 115 | static unsigned int get_fifosize_st(struct amba_device *dev) |
Jongsung Kim | 78506f2 | 2013-04-15 14:45:25 +0900 | [diff] [blame] | 116 | { |
| 117 | return 64; |
| 118 | } |
| 119 | |
Alessandro Rubini | 5926a29 | 2009-06-04 17:43:04 +0100 | [diff] [blame] | 120 | static struct vendor_data vendor_st = { |
| 121 | .ifls = UART011_IFLS_RX_HALF|UART011_IFLS_TX_HALF, |
Russell King | 9f25bc5 | 2015-11-03 14:51:13 +0000 | [diff] [blame^] | 122 | .lcrh_tx = REG_ST_LCRH_TX, |
| 123 | .lcrh_rx = REG_ST_LCRH_RX, |
Linus Walleij | ac3e3fb | 2010-06-02 20:40:22 +0100 | [diff] [blame] | 124 | .oversampling = true, |
Russell King | 38d6243 | 2010-12-22 17:59:16 +0000 | [diff] [blame] | 125 | .dma_threshold = true, |
Rajanikanth H.V | 4fd0690 | 2012-03-26 11:17:02 +0200 | [diff] [blame] | 126 | .cts_event_workaround = true, |
Andre Przywara | 71eec48 | 2015-05-21 17:26:21 +0100 | [diff] [blame] | 127 | .always_enabled = false, |
Andre Przywara | cefc2d1 | 2015-05-21 17:26:22 +0100 | [diff] [blame] | 128 | .fixed_options = false, |
Jongsung Kim | 78506f2 | 2013-04-15 14:45:25 +0900 | [diff] [blame] | 129 | .get_fifosize = get_fifosize_st, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 130 | }; |
| 131 | |
Russell King | 68b65f7 | 2010-12-22 17:24:39 +0000 | [diff] [blame] | 132 | /* Deals with DMA transactions */ |
Linus Walleij | ead76f3 | 2011-02-24 13:21:08 +0100 | [diff] [blame] | 133 | |
| 134 | struct pl011_sgbuf { |
| 135 | struct scatterlist sg; |
| 136 | char *buf; |
| 137 | }; |
| 138 | |
| 139 | struct pl011_dmarx_data { |
| 140 | struct dma_chan *chan; |
| 141 | struct completion complete; |
| 142 | bool use_buf_b; |
| 143 | struct pl011_sgbuf sgbuf_a; |
| 144 | struct pl011_sgbuf sgbuf_b; |
| 145 | dma_cookie_t cookie; |
| 146 | bool running; |
Chanho Min | cb06ff1 | 2013-03-27 18:38:11 +0900 | [diff] [blame] | 147 | struct timer_list timer; |
| 148 | unsigned int last_residue; |
| 149 | unsigned long last_jiffies; |
| 150 | bool auto_poll_rate; |
| 151 | unsigned int poll_rate; |
| 152 | unsigned int poll_timeout; |
Linus Walleij | ead76f3 | 2011-02-24 13:21:08 +0100 | [diff] [blame] | 153 | }; |
| 154 | |
Russell King | 68b65f7 | 2010-12-22 17:24:39 +0000 | [diff] [blame] | 155 | struct pl011_dmatx_data { |
| 156 | struct dma_chan *chan; |
| 157 | struct scatterlist sg; |
| 158 | char *buf; |
| 159 | bool queued; |
| 160 | }; |
| 161 | |
Russell King | c19f12b | 2010-12-22 17:48:26 +0000 | [diff] [blame] | 162 | /* |
| 163 | * We wrap our port structure around the generic uart_port. |
| 164 | */ |
| 165 | struct uart_amba_port { |
| 166 | struct uart_port port; |
| 167 | struct clk *clk; |
| 168 | const struct vendor_data *vendor; |
Russell King | 68b65f7 | 2010-12-22 17:24:39 +0000 | [diff] [blame] | 169 | unsigned int dmacr; /* dma control reg */ |
Russell King | c19f12b | 2010-12-22 17:48:26 +0000 | [diff] [blame] | 170 | unsigned int im; /* interrupt mask */ |
| 171 | unsigned int old_status; |
Russell King | ffca2b1 | 2010-12-22 17:13:05 +0000 | [diff] [blame] | 172 | unsigned int fifosize; /* vendor-specific */ |
Russell King | c19f12b | 2010-12-22 17:48:26 +0000 | [diff] [blame] | 173 | unsigned int lcrh_tx; /* vendor-specific */ |
| 174 | unsigned int lcrh_rx; /* vendor-specific */ |
Shreshtha Kumar Sahu | d8d8ffa | 2012-01-18 15:53:59 +0530 | [diff] [blame] | 175 | unsigned int old_cr; /* state during shutdown */ |
Russell King | c19f12b | 2010-12-22 17:48:26 +0000 | [diff] [blame] | 176 | bool autorts; |
Andre Przywara | cefc2d1 | 2015-05-21 17:26:22 +0100 | [diff] [blame] | 177 | unsigned int fixed_baud; /* vendor-set fixed baud rate */ |
Russell King | c19f12b | 2010-12-22 17:48:26 +0000 | [diff] [blame] | 178 | char type[12]; |
Russell King | 68b65f7 | 2010-12-22 17:24:39 +0000 | [diff] [blame] | 179 | #ifdef CONFIG_DMA_ENGINE |
| 180 | /* DMA stuff */ |
Linus Walleij | ead76f3 | 2011-02-24 13:21:08 +0100 | [diff] [blame] | 181 | bool using_tx_dma; |
| 182 | bool using_rx_dma; |
| 183 | struct pl011_dmarx_data dmarx; |
Russell King | 68b65f7 | 2010-12-22 17:24:39 +0000 | [diff] [blame] | 184 | struct pl011_dmatx_data dmatx; |
Jorge Ramirez-Ortiz | 1c9be31 | 2015-03-06 13:05:40 -0500 | [diff] [blame] | 185 | bool dma_probed; |
Russell King | 68b65f7 | 2010-12-22 17:24:39 +0000 | [diff] [blame] | 186 | #endif |
Russell King | c19f12b | 2010-12-22 17:48:26 +0000 | [diff] [blame] | 187 | }; |
| 188 | |
Russell King | 9f25bc5 | 2015-11-03 14:51:13 +0000 | [diff] [blame^] | 189 | static unsigned int pl011_reg_to_offset(const struct uart_amba_port *uap, |
| 190 | unsigned int reg) |
| 191 | { |
| 192 | return reg; |
| 193 | } |
| 194 | |
Russell King | b2a4e24 | 2015-11-03 14:51:03 +0000 | [diff] [blame] | 195 | static unsigned int pl011_read(const struct uart_amba_port *uap, |
| 196 | unsigned int reg) |
Russell King | 7583633 | 2015-11-03 14:50:58 +0000 | [diff] [blame] | 197 | { |
Russell King | 9f25bc5 | 2015-11-03 14:51:13 +0000 | [diff] [blame^] | 198 | return readw(uap->port.membase + pl011_reg_to_offset(uap, reg)); |
Russell King | 7583633 | 2015-11-03 14:50:58 +0000 | [diff] [blame] | 199 | } |
| 200 | |
Russell King | b2a4e24 | 2015-11-03 14:51:03 +0000 | [diff] [blame] | 201 | static void pl011_write(unsigned int val, const struct uart_amba_port *uap, |
| 202 | unsigned int reg) |
Russell King | 7583633 | 2015-11-03 14:50:58 +0000 | [diff] [blame] | 203 | { |
Russell King | 9f25bc5 | 2015-11-03 14:51:13 +0000 | [diff] [blame^] | 204 | writew(val, uap->port.membase + pl011_reg_to_offset(uap, reg)); |
Russell King | 7583633 | 2015-11-03 14:50:58 +0000 | [diff] [blame] | 205 | } |
| 206 | |
Russell King | 68b65f7 | 2010-12-22 17:24:39 +0000 | [diff] [blame] | 207 | /* |
Linus Walleij | 29772c4 | 2011-02-24 13:21:36 +0100 | [diff] [blame] | 208 | * Reads up to 256 characters from the FIFO or until it's empty and |
| 209 | * inserts them into the TTY layer. Returns the number of characters |
| 210 | * read from the FIFO. |
| 211 | */ |
| 212 | static int pl011_fifo_to_tty(struct uart_amba_port *uap) |
| 213 | { |
Timur Tabi | 71a5cd8 | 2015-10-07 15:27:16 -0500 | [diff] [blame] | 214 | u16 status; |
| 215 | unsigned int ch, flag, max_count = 256; |
Linus Walleij | 29772c4 | 2011-02-24 13:21:36 +0100 | [diff] [blame] | 216 | int fifotaken = 0; |
| 217 | |
| 218 | while (max_count--) { |
Russell King | 9f25bc5 | 2015-11-03 14:51:13 +0000 | [diff] [blame^] | 219 | status = pl011_read(uap, REG_FR); |
Linus Walleij | 29772c4 | 2011-02-24 13:21:36 +0100 | [diff] [blame] | 220 | if (status & UART01x_FR_RXFE) |
| 221 | break; |
| 222 | |
| 223 | /* Take chars from the FIFO and update status */ |
Russell King | 9f25bc5 | 2015-11-03 14:51:13 +0000 | [diff] [blame^] | 224 | ch = pl011_read(uap, REG_DR) | UART_DUMMY_DR_RX; |
Linus Walleij | 29772c4 | 2011-02-24 13:21:36 +0100 | [diff] [blame] | 225 | flag = TTY_NORMAL; |
| 226 | uap->port.icount.rx++; |
| 227 | fifotaken++; |
| 228 | |
| 229 | if (unlikely(ch & UART_DR_ERROR)) { |
| 230 | if (ch & UART011_DR_BE) { |
| 231 | ch &= ~(UART011_DR_FE | UART011_DR_PE); |
| 232 | uap->port.icount.brk++; |
| 233 | if (uart_handle_break(&uap->port)) |
| 234 | continue; |
| 235 | } else if (ch & UART011_DR_PE) |
| 236 | uap->port.icount.parity++; |
| 237 | else if (ch & UART011_DR_FE) |
| 238 | uap->port.icount.frame++; |
| 239 | if (ch & UART011_DR_OE) |
| 240 | uap->port.icount.overrun++; |
| 241 | |
| 242 | ch &= uap->port.read_status_mask; |
| 243 | |
| 244 | if (ch & UART011_DR_BE) |
| 245 | flag = TTY_BREAK; |
| 246 | else if (ch & UART011_DR_PE) |
| 247 | flag = TTY_PARITY; |
| 248 | else if (ch & UART011_DR_FE) |
| 249 | flag = TTY_FRAME; |
| 250 | } |
| 251 | |
| 252 | if (uart_handle_sysrq_char(&uap->port, ch & 255)) |
| 253 | continue; |
| 254 | |
| 255 | uart_insert_char(&uap->port, ch, UART011_DR_OE, ch, flag); |
| 256 | } |
| 257 | |
| 258 | return fifotaken; |
| 259 | } |
| 260 | |
| 261 | |
| 262 | /* |
Russell King | 68b65f7 | 2010-12-22 17:24:39 +0000 | [diff] [blame] | 263 | * All the DMA operation mode stuff goes inside this ifdef. |
| 264 | * This assumes that you have a generic DMA device interface, |
| 265 | * no custom DMA interfaces are supported. |
| 266 | */ |
| 267 | #ifdef CONFIG_DMA_ENGINE |
| 268 | |
| 269 | #define PL011_DMA_BUFFER_SIZE PAGE_SIZE |
| 270 | |
Linus Walleij | ead76f3 | 2011-02-24 13:21:08 +0100 | [diff] [blame] | 271 | static int pl011_sgbuf_init(struct dma_chan *chan, struct pl011_sgbuf *sg, |
| 272 | enum dma_data_direction dir) |
| 273 | { |
Chanho Min | cb06ff1 | 2013-03-27 18:38:11 +0900 | [diff] [blame] | 274 | dma_addr_t dma_addr; |
| 275 | |
| 276 | sg->buf = dma_alloc_coherent(chan->device->dev, |
| 277 | PL011_DMA_BUFFER_SIZE, &dma_addr, GFP_KERNEL); |
Linus Walleij | ead76f3 | 2011-02-24 13:21:08 +0100 | [diff] [blame] | 278 | if (!sg->buf) |
| 279 | return -ENOMEM; |
| 280 | |
Chanho Min | cb06ff1 | 2013-03-27 18:38:11 +0900 | [diff] [blame] | 281 | sg_init_table(&sg->sg, 1); |
| 282 | sg_set_page(&sg->sg, phys_to_page(dma_addr), |
| 283 | PL011_DMA_BUFFER_SIZE, offset_in_page(dma_addr)); |
| 284 | sg_dma_address(&sg->sg) = dma_addr; |
Andrew Jackson | c64be92 | 2014-11-07 14:14:43 +0000 | [diff] [blame] | 285 | sg_dma_len(&sg->sg) = PL011_DMA_BUFFER_SIZE; |
Linus Walleij | ead76f3 | 2011-02-24 13:21:08 +0100 | [diff] [blame] | 286 | |
Linus Walleij | ead76f3 | 2011-02-24 13:21:08 +0100 | [diff] [blame] | 287 | return 0; |
| 288 | } |
| 289 | |
| 290 | static void pl011_sgbuf_free(struct dma_chan *chan, struct pl011_sgbuf *sg, |
| 291 | enum dma_data_direction dir) |
| 292 | { |
| 293 | if (sg->buf) { |
Chanho Min | cb06ff1 | 2013-03-27 18:38:11 +0900 | [diff] [blame] | 294 | dma_free_coherent(chan->device->dev, |
| 295 | PL011_DMA_BUFFER_SIZE, sg->buf, |
| 296 | sg_dma_address(&sg->sg)); |
Linus Walleij | ead76f3 | 2011-02-24 13:21:08 +0100 | [diff] [blame] | 297 | } |
| 298 | } |
| 299 | |
Jorge Ramirez-Ortiz | 1c9be31 | 2015-03-06 13:05:40 -0500 | [diff] [blame] | 300 | static void pl011_dma_probe(struct uart_amba_port *uap) |
Russell King | 68b65f7 | 2010-12-22 17:24:39 +0000 | [diff] [blame] | 301 | { |
| 302 | /* DMA is the sole user of the platform data right now */ |
Jingoo Han | 574de55 | 2013-07-30 17:06:57 +0900 | [diff] [blame] | 303 | struct amba_pl011_data *plat = dev_get_platdata(uap->port.dev); |
Jorge Ramirez-Ortiz | 1c9be31 | 2015-03-06 13:05:40 -0500 | [diff] [blame] | 304 | struct device *dev = uap->port.dev; |
Russell King | 68b65f7 | 2010-12-22 17:24:39 +0000 | [diff] [blame] | 305 | struct dma_slave_config tx_conf = { |
Russell King | 9f25bc5 | 2015-11-03 14:51:13 +0000 | [diff] [blame^] | 306 | .dst_addr = uap->port.mapbase + |
| 307 | pl011_reg_to_offset(uap, REG_DR), |
Russell King | 68b65f7 | 2010-12-22 17:24:39 +0000 | [diff] [blame] | 308 | .dst_addr_width = DMA_SLAVE_BUSWIDTH_1_BYTE, |
Vinod Koul | a485df4 | 2011-10-14 10:47:38 +0530 | [diff] [blame] | 309 | .direction = DMA_MEM_TO_DEV, |
Russell King | 68b65f7 | 2010-12-22 17:24:39 +0000 | [diff] [blame] | 310 | .dst_maxburst = uap->fifosize >> 1, |
Viresh Kumar | 258aea7 | 2012-02-01 16:12:19 +0530 | [diff] [blame] | 311 | .device_fc = false, |
Russell King | 68b65f7 | 2010-12-22 17:24:39 +0000 | [diff] [blame] | 312 | }; |
| 313 | struct dma_chan *chan; |
| 314 | dma_cap_mask_t mask; |
| 315 | |
Jorge Ramirez-Ortiz | 1c9be31 | 2015-03-06 13:05:40 -0500 | [diff] [blame] | 316 | uap->dma_probed = true; |
| 317 | chan = dma_request_slave_channel_reason(dev, "tx"); |
| 318 | if (IS_ERR(chan)) { |
| 319 | if (PTR_ERR(chan) == -EPROBE_DEFER) { |
Jorge Ramirez-Ortiz | 1c9be31 | 2015-03-06 13:05:40 -0500 | [diff] [blame] | 320 | uap->dma_probed = false; |
| 321 | return; |
| 322 | } |
Russell King | 68b65f7 | 2010-12-22 17:24:39 +0000 | [diff] [blame] | 323 | |
Arnd Bergmann | 787b0c1 | 2013-01-28 16:24:37 +0000 | [diff] [blame] | 324 | /* We need platform data */ |
| 325 | if (!plat || !plat->dma_filter) { |
| 326 | dev_info(uap->port.dev, "no DMA platform data\n"); |
| 327 | return; |
| 328 | } |
| 329 | |
| 330 | /* Try to acquire a generic DMA engine slave TX channel */ |
| 331 | dma_cap_zero(mask); |
| 332 | dma_cap_set(DMA_SLAVE, mask); |
| 333 | |
| 334 | chan = dma_request_channel(mask, plat->dma_filter, |
| 335 | plat->dma_tx_param); |
| 336 | if (!chan) { |
| 337 | dev_err(uap->port.dev, "no TX DMA channel!\n"); |
| 338 | return; |
| 339 | } |
Russell King | 68b65f7 | 2010-12-22 17:24:39 +0000 | [diff] [blame] | 340 | } |
| 341 | |
| 342 | dmaengine_slave_config(chan, &tx_conf); |
| 343 | uap->dmatx.chan = chan; |
| 344 | |
| 345 | dev_info(uap->port.dev, "DMA channel TX %s\n", |
| 346 | dma_chan_name(uap->dmatx.chan)); |
Linus Walleij | ead76f3 | 2011-02-24 13:21:08 +0100 | [diff] [blame] | 347 | |
| 348 | /* Optionally make use of an RX channel as well */ |
Arnd Bergmann | 787b0c1 | 2013-01-28 16:24:37 +0000 | [diff] [blame] | 349 | chan = dma_request_slave_channel(dev, "rx"); |
Rob Herring | 0d3c673 | 2014-04-18 17:19:57 -0500 | [diff] [blame] | 350 | |
Arnd Bergmann | 787b0c1 | 2013-01-28 16:24:37 +0000 | [diff] [blame] | 351 | if (!chan && plat->dma_rx_param) { |
| 352 | chan = dma_request_channel(mask, plat->dma_filter, plat->dma_rx_param); |
| 353 | |
| 354 | if (!chan) { |
| 355 | dev_err(uap->port.dev, "no RX DMA channel!\n"); |
| 356 | return; |
| 357 | } |
| 358 | } |
| 359 | |
| 360 | if (chan) { |
Linus Walleij | ead76f3 | 2011-02-24 13:21:08 +0100 | [diff] [blame] | 361 | struct dma_slave_config rx_conf = { |
Russell King | 9f25bc5 | 2015-11-03 14:51:13 +0000 | [diff] [blame^] | 362 | .src_addr = uap->port.mapbase + |
| 363 | pl011_reg_to_offset(uap, REG_DR), |
Linus Walleij | ead76f3 | 2011-02-24 13:21:08 +0100 | [diff] [blame] | 364 | .src_addr_width = DMA_SLAVE_BUSWIDTH_1_BYTE, |
Vinod Koul | a485df4 | 2011-10-14 10:47:38 +0530 | [diff] [blame] | 365 | .direction = DMA_DEV_TO_MEM, |
Guennadi Liakhovetski | b2aeb77 | 2014-04-12 19:47:17 +0200 | [diff] [blame] | 366 | .src_maxburst = uap->fifosize >> 2, |
Viresh Kumar | 258aea7 | 2012-02-01 16:12:19 +0530 | [diff] [blame] | 367 | .device_fc = false, |
Linus Walleij | ead76f3 | 2011-02-24 13:21:08 +0100 | [diff] [blame] | 368 | }; |
Andrew Jackson | 2d3b7d6 | 2014-11-07 14:14:47 +0000 | [diff] [blame] | 369 | struct dma_slave_caps caps; |
Linus Walleij | ead76f3 | 2011-02-24 13:21:08 +0100 | [diff] [blame] | 370 | |
Andrew Jackson | 2d3b7d6 | 2014-11-07 14:14:47 +0000 | [diff] [blame] | 371 | /* |
| 372 | * Some DMA controllers provide information on their capabilities. |
| 373 | * If the controller does, check for suitable residue processing |
| 374 | * otherwise assime all is well. |
| 375 | */ |
| 376 | if (0 == dma_get_slave_caps(chan, &caps)) { |
| 377 | if (caps.residue_granularity == |
| 378 | DMA_RESIDUE_GRANULARITY_DESCRIPTOR) { |
| 379 | dma_release_channel(chan); |
| 380 | dev_info(uap->port.dev, |
| 381 | "RX DMA disabled - no residue processing\n"); |
| 382 | return; |
| 383 | } |
| 384 | } |
Linus Walleij | ead76f3 | 2011-02-24 13:21:08 +0100 | [diff] [blame] | 385 | dmaengine_slave_config(chan, &rx_conf); |
| 386 | uap->dmarx.chan = chan; |
| 387 | |
Andrew Jackson | 98267d3 | 2014-11-07 14:14:23 +0000 | [diff] [blame] | 388 | uap->dmarx.auto_poll_rate = false; |
Greg Kroah-Hartman | 8f898bf | 2013-12-17 09:33:18 -0800 | [diff] [blame] | 389 | if (plat && plat->dma_rx_poll_enable) { |
Chanho Min | cb06ff1 | 2013-03-27 18:38:11 +0900 | [diff] [blame] | 390 | /* Set poll rate if specified. */ |
| 391 | if (plat->dma_rx_poll_rate) { |
| 392 | uap->dmarx.auto_poll_rate = false; |
| 393 | uap->dmarx.poll_rate = plat->dma_rx_poll_rate; |
| 394 | } else { |
| 395 | /* |
| 396 | * 100 ms defaults to poll rate if not |
| 397 | * specified. This will be adjusted with |
| 398 | * the baud rate at set_termios. |
| 399 | */ |
| 400 | uap->dmarx.auto_poll_rate = true; |
| 401 | uap->dmarx.poll_rate = 100; |
| 402 | } |
| 403 | /* 3 secs defaults poll_timeout if not specified. */ |
| 404 | if (plat->dma_rx_poll_timeout) |
| 405 | uap->dmarx.poll_timeout = |
| 406 | plat->dma_rx_poll_timeout; |
| 407 | else |
| 408 | uap->dmarx.poll_timeout = 3000; |
Andrew Jackson | 98267d3 | 2014-11-07 14:14:23 +0000 | [diff] [blame] | 409 | } else if (!plat && dev->of_node) { |
| 410 | uap->dmarx.auto_poll_rate = of_property_read_bool( |
| 411 | dev->of_node, "auto-poll"); |
| 412 | if (uap->dmarx.auto_poll_rate) { |
| 413 | u32 x; |
Chanho Min | cb06ff1 | 2013-03-27 18:38:11 +0900 | [diff] [blame] | 414 | |
Andrew Jackson | 98267d3 | 2014-11-07 14:14:23 +0000 | [diff] [blame] | 415 | if (0 == of_property_read_u32(dev->of_node, |
| 416 | "poll-rate-ms", &x)) |
| 417 | uap->dmarx.poll_rate = x; |
| 418 | else |
| 419 | uap->dmarx.poll_rate = 100; |
| 420 | if (0 == of_property_read_u32(dev->of_node, |
| 421 | "poll-timeout-ms", &x)) |
| 422 | uap->dmarx.poll_timeout = x; |
| 423 | else |
| 424 | uap->dmarx.poll_timeout = 3000; |
| 425 | } |
| 426 | } |
Linus Walleij | ead76f3 | 2011-02-24 13:21:08 +0100 | [diff] [blame] | 427 | dev_info(uap->port.dev, "DMA channel RX %s\n", |
| 428 | dma_chan_name(uap->dmarx.chan)); |
| 429 | } |
Russell King | 68b65f7 | 2010-12-22 17:24:39 +0000 | [diff] [blame] | 430 | } |
| 431 | |
Russell King | 68b65f7 | 2010-12-22 17:24:39 +0000 | [diff] [blame] | 432 | static void pl011_dma_remove(struct uart_amba_port *uap) |
| 433 | { |
Russell King | 68b65f7 | 2010-12-22 17:24:39 +0000 | [diff] [blame] | 434 | if (uap->dmatx.chan) |
| 435 | dma_release_channel(uap->dmatx.chan); |
Linus Walleij | ead76f3 | 2011-02-24 13:21:08 +0100 | [diff] [blame] | 436 | if (uap->dmarx.chan) |
| 437 | dma_release_channel(uap->dmarx.chan); |
Russell King | 68b65f7 | 2010-12-22 17:24:39 +0000 | [diff] [blame] | 438 | } |
| 439 | |
Dave Martin | 734745c | 2015-03-04 12:27:33 +0000 | [diff] [blame] | 440 | /* Forward declare these for the refill routine */ |
Russell King | 68b65f7 | 2010-12-22 17:24:39 +0000 | [diff] [blame] | 441 | static int pl011_dma_tx_refill(struct uart_amba_port *uap); |
Dave Martin | 734745c | 2015-03-04 12:27:33 +0000 | [diff] [blame] | 442 | static void pl011_start_tx_pio(struct uart_amba_port *uap); |
Russell King | 68b65f7 | 2010-12-22 17:24:39 +0000 | [diff] [blame] | 443 | |
| 444 | /* |
| 445 | * The current DMA TX buffer has been sent. |
| 446 | * Try to queue up another DMA buffer. |
| 447 | */ |
| 448 | static void pl011_dma_tx_callback(void *data) |
| 449 | { |
| 450 | struct uart_amba_port *uap = data; |
| 451 | struct pl011_dmatx_data *dmatx = &uap->dmatx; |
| 452 | unsigned long flags; |
| 453 | u16 dmacr; |
| 454 | |
| 455 | spin_lock_irqsave(&uap->port.lock, flags); |
| 456 | if (uap->dmatx.queued) |
| 457 | dma_unmap_sg(dmatx->chan->device->dev, &dmatx->sg, 1, |
| 458 | DMA_TO_DEVICE); |
| 459 | |
| 460 | dmacr = uap->dmacr; |
| 461 | uap->dmacr = dmacr & ~UART011_TXDMAE; |
Russell King | 9f25bc5 | 2015-11-03 14:51:13 +0000 | [diff] [blame^] | 462 | pl011_write(uap->dmacr, uap, REG_DMACR); |
Russell King | 68b65f7 | 2010-12-22 17:24:39 +0000 | [diff] [blame] | 463 | |
| 464 | /* |
| 465 | * If TX DMA was disabled, it means that we've stopped the DMA for |
| 466 | * some reason (eg, XOFF received, or we want to send an X-char.) |
| 467 | * |
| 468 | * Note: we need to be careful here of a potential race between DMA |
| 469 | * and the rest of the driver - if the driver disables TX DMA while |
| 470 | * a TX buffer completing, we must update the tx queued status to |
| 471 | * get further refills (hence we check dmacr). |
| 472 | */ |
| 473 | if (!(dmacr & UART011_TXDMAE) || uart_tx_stopped(&uap->port) || |
| 474 | uart_circ_empty(&uap->port.state->xmit)) { |
| 475 | uap->dmatx.queued = false; |
| 476 | spin_unlock_irqrestore(&uap->port.lock, flags); |
| 477 | return; |
| 478 | } |
| 479 | |
Dave Martin | 734745c | 2015-03-04 12:27:33 +0000 | [diff] [blame] | 480 | if (pl011_dma_tx_refill(uap) <= 0) |
Russell King | 68b65f7 | 2010-12-22 17:24:39 +0000 | [diff] [blame] | 481 | /* |
| 482 | * We didn't queue a DMA buffer for some reason, but we |
| 483 | * have data pending to be sent. Re-enable the TX IRQ. |
| 484 | */ |
Dave Martin | 734745c | 2015-03-04 12:27:33 +0000 | [diff] [blame] | 485 | pl011_start_tx_pio(uap); |
| 486 | |
Russell King | 68b65f7 | 2010-12-22 17:24:39 +0000 | [diff] [blame] | 487 | spin_unlock_irqrestore(&uap->port.lock, flags); |
| 488 | } |
| 489 | |
| 490 | /* |
| 491 | * Try to refill the TX DMA buffer. |
| 492 | * Locking: called with port lock held and IRQs disabled. |
| 493 | * Returns: |
| 494 | * 1 if we queued up a TX DMA buffer. |
| 495 | * 0 if we didn't want to handle this by DMA |
| 496 | * <0 on error |
| 497 | */ |
| 498 | static int pl011_dma_tx_refill(struct uart_amba_port *uap) |
| 499 | { |
| 500 | struct pl011_dmatx_data *dmatx = &uap->dmatx; |
| 501 | struct dma_chan *chan = dmatx->chan; |
| 502 | struct dma_device *dma_dev = chan->device; |
| 503 | struct dma_async_tx_descriptor *desc; |
| 504 | struct circ_buf *xmit = &uap->port.state->xmit; |
| 505 | unsigned int count; |
| 506 | |
| 507 | /* |
| 508 | * Try to avoid the overhead involved in using DMA if the |
| 509 | * transaction fits in the first half of the FIFO, by using |
| 510 | * the standard interrupt handling. This ensures that we |
| 511 | * issue a uart_write_wakeup() at the appropriate time. |
| 512 | */ |
| 513 | count = uart_circ_chars_pending(xmit); |
| 514 | if (count < (uap->fifosize >> 1)) { |
| 515 | uap->dmatx.queued = false; |
| 516 | return 0; |
| 517 | } |
| 518 | |
| 519 | /* |
| 520 | * Bodge: don't send the last character by DMA, as this |
| 521 | * will prevent XON from notifying us to restart DMA. |
| 522 | */ |
| 523 | count -= 1; |
| 524 | |
| 525 | /* Else proceed to copy the TX chars to the DMA buffer and fire DMA */ |
| 526 | if (count > PL011_DMA_BUFFER_SIZE) |
| 527 | count = PL011_DMA_BUFFER_SIZE; |
| 528 | |
| 529 | if (xmit->tail < xmit->head) |
| 530 | memcpy(&dmatx->buf[0], &xmit->buf[xmit->tail], count); |
| 531 | else { |
| 532 | size_t first = UART_XMIT_SIZE - xmit->tail; |
Andrew Jackson | e2a545a | 2014-11-07 14:14:39 +0000 | [diff] [blame] | 533 | size_t second; |
| 534 | |
| 535 | if (first > count) |
| 536 | first = count; |
| 537 | second = count - first; |
Russell King | 68b65f7 | 2010-12-22 17:24:39 +0000 | [diff] [blame] | 538 | |
| 539 | memcpy(&dmatx->buf[0], &xmit->buf[xmit->tail], first); |
| 540 | if (second) |
| 541 | memcpy(&dmatx->buf[first], &xmit->buf[0], second); |
| 542 | } |
| 543 | |
| 544 | dmatx->sg.length = count; |
| 545 | |
| 546 | if (dma_map_sg(dma_dev->dev, &dmatx->sg, 1, DMA_TO_DEVICE) != 1) { |
| 547 | uap->dmatx.queued = false; |
| 548 | dev_dbg(uap->port.dev, "unable to map TX DMA\n"); |
| 549 | return -EBUSY; |
| 550 | } |
| 551 | |
Alexandre Bounine | 1605282 | 2012-03-08 16:11:18 -0500 | [diff] [blame] | 552 | desc = dmaengine_prep_slave_sg(chan, &dmatx->sg, 1, DMA_MEM_TO_DEV, |
Russell King | 68b65f7 | 2010-12-22 17:24:39 +0000 | [diff] [blame] | 553 | DMA_PREP_INTERRUPT | DMA_CTRL_ACK); |
| 554 | if (!desc) { |
| 555 | dma_unmap_sg(dma_dev->dev, &dmatx->sg, 1, DMA_TO_DEVICE); |
| 556 | uap->dmatx.queued = false; |
| 557 | /* |
| 558 | * If DMA cannot be used right now, we complete this |
| 559 | * transaction via IRQ and let the TTY layer retry. |
| 560 | */ |
| 561 | dev_dbg(uap->port.dev, "TX DMA busy\n"); |
| 562 | return -EBUSY; |
| 563 | } |
| 564 | |
| 565 | /* Some data to go along to the callback */ |
| 566 | desc->callback = pl011_dma_tx_callback; |
| 567 | desc->callback_param = uap; |
| 568 | |
| 569 | /* All errors should happen at prepare time */ |
| 570 | dmaengine_submit(desc); |
| 571 | |
| 572 | /* Fire the DMA transaction */ |
| 573 | dma_dev->device_issue_pending(chan); |
| 574 | |
| 575 | uap->dmacr |= UART011_TXDMAE; |
Russell King | 9f25bc5 | 2015-11-03 14:51:13 +0000 | [diff] [blame^] | 576 | pl011_write(uap->dmacr, uap, REG_DMACR); |
Russell King | 68b65f7 | 2010-12-22 17:24:39 +0000 | [diff] [blame] | 577 | uap->dmatx.queued = true; |
| 578 | |
| 579 | /* |
| 580 | * Now we know that DMA will fire, so advance the ring buffer |
| 581 | * with the stuff we just dispatched. |
| 582 | */ |
| 583 | xmit->tail = (xmit->tail + count) & (UART_XMIT_SIZE - 1); |
| 584 | uap->port.icount.tx += count; |
| 585 | |
| 586 | if (uart_circ_chars_pending(xmit) < WAKEUP_CHARS) |
| 587 | uart_write_wakeup(&uap->port); |
| 588 | |
| 589 | return 1; |
| 590 | } |
| 591 | |
| 592 | /* |
| 593 | * We received a transmit interrupt without a pending X-char but with |
| 594 | * pending characters. |
| 595 | * Locking: called with port lock held and IRQs disabled. |
| 596 | * Returns: |
| 597 | * false if we want to use PIO to transmit |
| 598 | * true if we queued a DMA buffer |
| 599 | */ |
| 600 | static bool pl011_dma_tx_irq(struct uart_amba_port *uap) |
| 601 | { |
Linus Walleij | ead76f3 | 2011-02-24 13:21:08 +0100 | [diff] [blame] | 602 | if (!uap->using_tx_dma) |
Russell King | 68b65f7 | 2010-12-22 17:24:39 +0000 | [diff] [blame] | 603 | return false; |
| 604 | |
| 605 | /* |
| 606 | * If we already have a TX buffer queued, but received a |
| 607 | * TX interrupt, it will be because we've just sent an X-char. |
| 608 | * Ensure the TX DMA is enabled and the TX IRQ is disabled. |
| 609 | */ |
| 610 | if (uap->dmatx.queued) { |
| 611 | uap->dmacr |= UART011_TXDMAE; |
Russell King | 9f25bc5 | 2015-11-03 14:51:13 +0000 | [diff] [blame^] | 612 | pl011_write(uap->dmacr, uap, REG_DMACR); |
Russell King | 68b65f7 | 2010-12-22 17:24:39 +0000 | [diff] [blame] | 613 | uap->im &= ~UART011_TXIM; |
Russell King | 9f25bc5 | 2015-11-03 14:51:13 +0000 | [diff] [blame^] | 614 | pl011_write(uap->im, uap, REG_IMSC); |
Russell King | 68b65f7 | 2010-12-22 17:24:39 +0000 | [diff] [blame] | 615 | return true; |
| 616 | } |
| 617 | |
| 618 | /* |
| 619 | * We don't have a TX buffer queued, so try to queue one. |
Lucas De Marchi | 25985ed | 2011-03-30 22:57:33 -0300 | [diff] [blame] | 620 | * If we successfully queued a buffer, mask the TX IRQ. |
Russell King | 68b65f7 | 2010-12-22 17:24:39 +0000 | [diff] [blame] | 621 | */ |
| 622 | if (pl011_dma_tx_refill(uap) > 0) { |
| 623 | uap->im &= ~UART011_TXIM; |
Russell King | 9f25bc5 | 2015-11-03 14:51:13 +0000 | [diff] [blame^] | 624 | pl011_write(uap->im, uap, REG_IMSC); |
Russell King | 68b65f7 | 2010-12-22 17:24:39 +0000 | [diff] [blame] | 625 | return true; |
| 626 | } |
| 627 | return false; |
| 628 | } |
| 629 | |
| 630 | /* |
| 631 | * Stop the DMA transmit (eg, due to received XOFF). |
| 632 | * Locking: called with port lock held and IRQs disabled. |
| 633 | */ |
| 634 | static inline void pl011_dma_tx_stop(struct uart_amba_port *uap) |
| 635 | { |
| 636 | if (uap->dmatx.queued) { |
| 637 | uap->dmacr &= ~UART011_TXDMAE; |
Russell King | 9f25bc5 | 2015-11-03 14:51:13 +0000 | [diff] [blame^] | 638 | pl011_write(uap->dmacr, uap, REG_DMACR); |
Russell King | 68b65f7 | 2010-12-22 17:24:39 +0000 | [diff] [blame] | 639 | } |
| 640 | } |
| 641 | |
| 642 | /* |
| 643 | * Try to start a DMA transmit, or in the case of an XON/OFF |
| 644 | * character queued for send, try to get that character out ASAP. |
| 645 | * Locking: called with port lock held and IRQs disabled. |
| 646 | * Returns: |
| 647 | * false if we want the TX IRQ to be enabled |
| 648 | * true if we have a buffer queued |
| 649 | */ |
| 650 | static inline bool pl011_dma_tx_start(struct uart_amba_port *uap) |
| 651 | { |
| 652 | u16 dmacr; |
| 653 | |
Linus Walleij | ead76f3 | 2011-02-24 13:21:08 +0100 | [diff] [blame] | 654 | if (!uap->using_tx_dma) |
Russell King | 68b65f7 | 2010-12-22 17:24:39 +0000 | [diff] [blame] | 655 | return false; |
| 656 | |
| 657 | if (!uap->port.x_char) { |
| 658 | /* no X-char, try to push chars out in DMA mode */ |
| 659 | bool ret = true; |
| 660 | |
| 661 | if (!uap->dmatx.queued) { |
| 662 | if (pl011_dma_tx_refill(uap) > 0) { |
| 663 | uap->im &= ~UART011_TXIM; |
Russell King | 9f25bc5 | 2015-11-03 14:51:13 +0000 | [diff] [blame^] | 664 | pl011_write(uap->im, uap, REG_IMSC); |
Dave Martin | 734745c | 2015-03-04 12:27:33 +0000 | [diff] [blame] | 665 | } else |
Russell King | 68b65f7 | 2010-12-22 17:24:39 +0000 | [diff] [blame] | 666 | ret = false; |
Russell King | 68b65f7 | 2010-12-22 17:24:39 +0000 | [diff] [blame] | 667 | } else if (!(uap->dmacr & UART011_TXDMAE)) { |
| 668 | uap->dmacr |= UART011_TXDMAE; |
Russell King | 9f25bc5 | 2015-11-03 14:51:13 +0000 | [diff] [blame^] | 669 | pl011_write(uap->dmacr, uap, REG_DMACR); |
Russell King | 68b65f7 | 2010-12-22 17:24:39 +0000 | [diff] [blame] | 670 | } |
| 671 | return ret; |
| 672 | } |
| 673 | |
| 674 | /* |
| 675 | * We have an X-char to send. Disable DMA to prevent it loading |
| 676 | * the TX fifo, and then see if we can stuff it into the FIFO. |
| 677 | */ |
| 678 | dmacr = uap->dmacr; |
| 679 | uap->dmacr &= ~UART011_TXDMAE; |
Russell King | 9f25bc5 | 2015-11-03 14:51:13 +0000 | [diff] [blame^] | 680 | pl011_write(uap->dmacr, uap, REG_DMACR); |
Russell King | 68b65f7 | 2010-12-22 17:24:39 +0000 | [diff] [blame] | 681 | |
Russell King | 9f25bc5 | 2015-11-03 14:51:13 +0000 | [diff] [blame^] | 682 | if (pl011_read(uap, REG_FR) & UART01x_FR_TXFF) { |
Russell King | 68b65f7 | 2010-12-22 17:24:39 +0000 | [diff] [blame] | 683 | /* |
| 684 | * No space in the FIFO, so enable the transmit interrupt |
| 685 | * so we know when there is space. Note that once we've |
| 686 | * loaded the character, we should just re-enable DMA. |
| 687 | */ |
| 688 | return false; |
| 689 | } |
| 690 | |
Russell King | 9f25bc5 | 2015-11-03 14:51:13 +0000 | [diff] [blame^] | 691 | pl011_write(uap->port.x_char, uap, REG_DR); |
Russell King | 68b65f7 | 2010-12-22 17:24:39 +0000 | [diff] [blame] | 692 | uap->port.icount.tx++; |
| 693 | uap->port.x_char = 0; |
| 694 | |
| 695 | /* Success - restore the DMA state */ |
| 696 | uap->dmacr = dmacr; |
Russell King | 9f25bc5 | 2015-11-03 14:51:13 +0000 | [diff] [blame^] | 697 | pl011_write(dmacr, uap, REG_DMACR); |
Russell King | 68b65f7 | 2010-12-22 17:24:39 +0000 | [diff] [blame] | 698 | |
| 699 | return true; |
| 700 | } |
| 701 | |
| 702 | /* |
| 703 | * Flush the transmit buffer. |
| 704 | * Locking: called with port lock held and IRQs disabled. |
| 705 | */ |
| 706 | static void pl011_dma_flush_buffer(struct uart_port *port) |
Fabio Estevam | b83286b | 2013-08-09 17:58:51 -0300 | [diff] [blame] | 707 | __releases(&uap->port.lock) |
| 708 | __acquires(&uap->port.lock) |
Russell King | 68b65f7 | 2010-12-22 17:24:39 +0000 | [diff] [blame] | 709 | { |
Daniel Thompson | a5820c2 | 2014-09-03 12:51:55 +0100 | [diff] [blame] | 710 | struct uart_amba_port *uap = |
| 711 | container_of(port, struct uart_amba_port, port); |
Russell King | 68b65f7 | 2010-12-22 17:24:39 +0000 | [diff] [blame] | 712 | |
Linus Walleij | ead76f3 | 2011-02-24 13:21:08 +0100 | [diff] [blame] | 713 | if (!uap->using_tx_dma) |
Russell King | 68b65f7 | 2010-12-22 17:24:39 +0000 | [diff] [blame] | 714 | return; |
| 715 | |
| 716 | /* Avoid deadlock with the DMA engine callback */ |
| 717 | spin_unlock(&uap->port.lock); |
| 718 | dmaengine_terminate_all(uap->dmatx.chan); |
| 719 | spin_lock(&uap->port.lock); |
| 720 | if (uap->dmatx.queued) { |
| 721 | dma_unmap_sg(uap->dmatx.chan->device->dev, &uap->dmatx.sg, 1, |
| 722 | DMA_TO_DEVICE); |
| 723 | uap->dmatx.queued = false; |
| 724 | uap->dmacr &= ~UART011_TXDMAE; |
Russell King | 9f25bc5 | 2015-11-03 14:51:13 +0000 | [diff] [blame^] | 725 | pl011_write(uap->dmacr, uap, REG_DMACR); |
Russell King | 68b65f7 | 2010-12-22 17:24:39 +0000 | [diff] [blame] | 726 | } |
| 727 | } |
| 728 | |
Linus Walleij | ead76f3 | 2011-02-24 13:21:08 +0100 | [diff] [blame] | 729 | static void pl011_dma_rx_callback(void *data); |
| 730 | |
| 731 | static int pl011_dma_rx_trigger_dma(struct uart_amba_port *uap) |
| 732 | { |
| 733 | struct dma_chan *rxchan = uap->dmarx.chan; |
Linus Walleij | ead76f3 | 2011-02-24 13:21:08 +0100 | [diff] [blame] | 734 | struct pl011_dmarx_data *dmarx = &uap->dmarx; |
| 735 | struct dma_async_tx_descriptor *desc; |
| 736 | struct pl011_sgbuf *sgbuf; |
| 737 | |
| 738 | if (!rxchan) |
| 739 | return -EIO; |
| 740 | |
| 741 | /* Start the RX DMA job */ |
| 742 | sgbuf = uap->dmarx.use_buf_b ? |
| 743 | &uap->dmarx.sgbuf_b : &uap->dmarx.sgbuf_a; |
Alexandre Bounine | 1605282 | 2012-03-08 16:11:18 -0500 | [diff] [blame] | 744 | desc = dmaengine_prep_slave_sg(rxchan, &sgbuf->sg, 1, |
Vinod Koul | a485df4 | 2011-10-14 10:47:38 +0530 | [diff] [blame] | 745 | DMA_DEV_TO_MEM, |
Linus Walleij | ead76f3 | 2011-02-24 13:21:08 +0100 | [diff] [blame] | 746 | DMA_PREP_INTERRUPT | DMA_CTRL_ACK); |
| 747 | /* |
| 748 | * If the DMA engine is busy and cannot prepare a |
| 749 | * channel, no big deal, the driver will fall back |
| 750 | * to interrupt mode as a result of this error code. |
| 751 | */ |
| 752 | if (!desc) { |
| 753 | uap->dmarx.running = false; |
| 754 | dmaengine_terminate_all(rxchan); |
| 755 | return -EBUSY; |
| 756 | } |
| 757 | |
| 758 | /* Some data to go along to the callback */ |
| 759 | desc->callback = pl011_dma_rx_callback; |
| 760 | desc->callback_param = uap; |
| 761 | dmarx->cookie = dmaengine_submit(desc); |
| 762 | dma_async_issue_pending(rxchan); |
| 763 | |
| 764 | uap->dmacr |= UART011_RXDMAE; |
Russell King | 9f25bc5 | 2015-11-03 14:51:13 +0000 | [diff] [blame^] | 765 | pl011_write(uap->dmacr, uap, REG_DMACR); |
Linus Walleij | ead76f3 | 2011-02-24 13:21:08 +0100 | [diff] [blame] | 766 | uap->dmarx.running = true; |
| 767 | |
| 768 | uap->im &= ~UART011_RXIM; |
Russell King | 9f25bc5 | 2015-11-03 14:51:13 +0000 | [diff] [blame^] | 769 | pl011_write(uap->im, uap, REG_IMSC); |
Linus Walleij | ead76f3 | 2011-02-24 13:21:08 +0100 | [diff] [blame] | 770 | |
| 771 | return 0; |
| 772 | } |
| 773 | |
| 774 | /* |
| 775 | * This is called when either the DMA job is complete, or |
| 776 | * the FIFO timeout interrupt occurred. This must be called |
| 777 | * with the port spinlock uap->port.lock held. |
| 778 | */ |
| 779 | static void pl011_dma_rx_chars(struct uart_amba_port *uap, |
| 780 | u32 pending, bool use_buf_b, |
| 781 | bool readfifo) |
| 782 | { |
Jiri Slaby | 05c7cd3 | 2013-01-03 15:53:04 +0100 | [diff] [blame] | 783 | struct tty_port *port = &uap->port.state->port; |
Linus Walleij | ead76f3 | 2011-02-24 13:21:08 +0100 | [diff] [blame] | 784 | struct pl011_sgbuf *sgbuf = use_buf_b ? |
| 785 | &uap->dmarx.sgbuf_b : &uap->dmarx.sgbuf_a; |
Linus Walleij | ead76f3 | 2011-02-24 13:21:08 +0100 | [diff] [blame] | 786 | int dma_count = 0; |
| 787 | u32 fifotaken = 0; /* only used for vdbg() */ |
| 788 | |
Chanho Min | cb06ff1 | 2013-03-27 18:38:11 +0900 | [diff] [blame] | 789 | struct pl011_dmarx_data *dmarx = &uap->dmarx; |
| 790 | int dmataken = 0; |
| 791 | |
| 792 | if (uap->dmarx.poll_rate) { |
| 793 | /* The data can be taken by polling */ |
| 794 | dmataken = sgbuf->sg.length - dmarx->last_residue; |
| 795 | /* Recalculate the pending size */ |
| 796 | if (pending >= dmataken) |
| 797 | pending -= dmataken; |
| 798 | } |
| 799 | |
| 800 | /* Pick the remain data from the DMA */ |
Linus Walleij | ead76f3 | 2011-02-24 13:21:08 +0100 | [diff] [blame] | 801 | if (pending) { |
Linus Walleij | ead76f3 | 2011-02-24 13:21:08 +0100 | [diff] [blame] | 802 | |
| 803 | /* |
| 804 | * First take all chars in the DMA pipe, then look in the FIFO. |
| 805 | * Note that tty_insert_flip_buf() tries to take as many chars |
| 806 | * as it can. |
| 807 | */ |
Chanho Min | cb06ff1 | 2013-03-27 18:38:11 +0900 | [diff] [blame] | 808 | dma_count = tty_insert_flip_string(port, sgbuf->buf + dmataken, |
| 809 | pending); |
Linus Walleij | ead76f3 | 2011-02-24 13:21:08 +0100 | [diff] [blame] | 810 | |
| 811 | uap->port.icount.rx += dma_count; |
| 812 | if (dma_count < pending) |
| 813 | dev_warn(uap->port.dev, |
| 814 | "couldn't insert all characters (TTY is full?)\n"); |
| 815 | } |
| 816 | |
Chanho Min | cb06ff1 | 2013-03-27 18:38:11 +0900 | [diff] [blame] | 817 | /* Reset the last_residue for Rx DMA poll */ |
| 818 | if (uap->dmarx.poll_rate) |
| 819 | dmarx->last_residue = sgbuf->sg.length; |
| 820 | |
Linus Walleij | ead76f3 | 2011-02-24 13:21:08 +0100 | [diff] [blame] | 821 | /* |
| 822 | * Only continue with trying to read the FIFO if all DMA chars have |
| 823 | * been taken first. |
| 824 | */ |
| 825 | if (dma_count == pending && readfifo) { |
| 826 | /* Clear any error flags */ |
Russell King | 7583633 | 2015-11-03 14:50:58 +0000 | [diff] [blame] | 827 | pl011_write(UART011_OEIS | UART011_BEIS | UART011_PEIS | |
Russell King | 9f25bc5 | 2015-11-03 14:51:13 +0000 | [diff] [blame^] | 828 | UART011_FEIS, uap, REG_ICR); |
Linus Walleij | ead76f3 | 2011-02-24 13:21:08 +0100 | [diff] [blame] | 829 | |
| 830 | /* |
| 831 | * If we read all the DMA'd characters, and we had an |
Linus Walleij | 29772c4 | 2011-02-24 13:21:36 +0100 | [diff] [blame] | 832 | * incomplete buffer, that could be due to an rx error, or |
| 833 | * maybe we just timed out. Read any pending chars and check |
| 834 | * the error status. |
| 835 | * |
| 836 | * Error conditions will only occur in the FIFO, these will |
| 837 | * trigger an immediate interrupt and stop the DMA job, so we |
| 838 | * will always find the error in the FIFO, never in the DMA |
| 839 | * buffer. |
Linus Walleij | ead76f3 | 2011-02-24 13:21:08 +0100 | [diff] [blame] | 840 | */ |
Linus Walleij | 29772c4 | 2011-02-24 13:21:36 +0100 | [diff] [blame] | 841 | fifotaken = pl011_fifo_to_tty(uap); |
Linus Walleij | ead76f3 | 2011-02-24 13:21:08 +0100 | [diff] [blame] | 842 | } |
| 843 | |
| 844 | spin_unlock(&uap->port.lock); |
| 845 | dev_vdbg(uap->port.dev, |
| 846 | "Took %d chars from DMA buffer and %d chars from the FIFO\n", |
| 847 | dma_count, fifotaken); |
Jiri Slaby | 2e124b4 | 2013-01-03 15:53:06 +0100 | [diff] [blame] | 848 | tty_flip_buffer_push(port); |
Linus Walleij | ead76f3 | 2011-02-24 13:21:08 +0100 | [diff] [blame] | 849 | spin_lock(&uap->port.lock); |
| 850 | } |
| 851 | |
| 852 | static void pl011_dma_rx_irq(struct uart_amba_port *uap) |
| 853 | { |
| 854 | struct pl011_dmarx_data *dmarx = &uap->dmarx; |
| 855 | struct dma_chan *rxchan = dmarx->chan; |
| 856 | struct pl011_sgbuf *sgbuf = dmarx->use_buf_b ? |
| 857 | &dmarx->sgbuf_b : &dmarx->sgbuf_a; |
| 858 | size_t pending; |
| 859 | struct dma_tx_state state; |
| 860 | enum dma_status dmastat; |
| 861 | |
| 862 | /* |
| 863 | * Pause the transfer so we can trust the current counter, |
| 864 | * do this before we pause the PL011 block, else we may |
| 865 | * overflow the FIFO. |
| 866 | */ |
| 867 | if (dmaengine_pause(rxchan)) |
| 868 | dev_err(uap->port.dev, "unable to pause DMA transfer\n"); |
| 869 | dmastat = rxchan->device->device_tx_status(rxchan, |
| 870 | dmarx->cookie, &state); |
| 871 | if (dmastat != DMA_PAUSED) |
| 872 | dev_err(uap->port.dev, "unable to pause DMA transfer\n"); |
| 873 | |
| 874 | /* Disable RX DMA - incoming data will wait in the FIFO */ |
| 875 | uap->dmacr &= ~UART011_RXDMAE; |
Russell King | 9f25bc5 | 2015-11-03 14:51:13 +0000 | [diff] [blame^] | 876 | pl011_write(uap->dmacr, uap, REG_DMACR); |
Linus Walleij | ead76f3 | 2011-02-24 13:21:08 +0100 | [diff] [blame] | 877 | uap->dmarx.running = false; |
| 878 | |
| 879 | pending = sgbuf->sg.length - state.residue; |
| 880 | BUG_ON(pending > PL011_DMA_BUFFER_SIZE); |
| 881 | /* Then we terminate the transfer - we now know our residue */ |
| 882 | dmaengine_terminate_all(rxchan); |
| 883 | |
| 884 | /* |
| 885 | * This will take the chars we have so far and insert |
| 886 | * into the framework. |
| 887 | */ |
| 888 | pl011_dma_rx_chars(uap, pending, dmarx->use_buf_b, true); |
| 889 | |
| 890 | /* Switch buffer & re-trigger DMA job */ |
| 891 | dmarx->use_buf_b = !dmarx->use_buf_b; |
| 892 | if (pl011_dma_rx_trigger_dma(uap)) { |
| 893 | dev_dbg(uap->port.dev, "could not retrigger RX DMA job " |
| 894 | "fall back to interrupt mode\n"); |
| 895 | uap->im |= UART011_RXIM; |
Russell King | 9f25bc5 | 2015-11-03 14:51:13 +0000 | [diff] [blame^] | 896 | pl011_write(uap->im, uap, REG_IMSC); |
Linus Walleij | ead76f3 | 2011-02-24 13:21:08 +0100 | [diff] [blame] | 897 | } |
| 898 | } |
| 899 | |
| 900 | static void pl011_dma_rx_callback(void *data) |
| 901 | { |
| 902 | struct uart_amba_port *uap = data; |
| 903 | struct pl011_dmarx_data *dmarx = &uap->dmarx; |
Chanho Min | 6dc01aa | 2012-02-20 10:24:40 +0900 | [diff] [blame] | 904 | struct dma_chan *rxchan = dmarx->chan; |
Linus Walleij | ead76f3 | 2011-02-24 13:21:08 +0100 | [diff] [blame] | 905 | bool lastbuf = dmarx->use_buf_b; |
Chanho Min | 6dc01aa | 2012-02-20 10:24:40 +0900 | [diff] [blame] | 906 | struct pl011_sgbuf *sgbuf = dmarx->use_buf_b ? |
| 907 | &dmarx->sgbuf_b : &dmarx->sgbuf_a; |
| 908 | size_t pending; |
| 909 | struct dma_tx_state state; |
Linus Walleij | ead76f3 | 2011-02-24 13:21:08 +0100 | [diff] [blame] | 910 | int ret; |
| 911 | |
| 912 | /* |
| 913 | * This completion interrupt occurs typically when the |
| 914 | * RX buffer is totally stuffed but no timeout has yet |
| 915 | * occurred. When that happens, we just want the RX |
| 916 | * routine to flush out the secondary DMA buffer while |
| 917 | * we immediately trigger the next DMA job. |
| 918 | */ |
| 919 | spin_lock_irq(&uap->port.lock); |
Chanho Min | 6dc01aa | 2012-02-20 10:24:40 +0900 | [diff] [blame] | 920 | /* |
| 921 | * Rx data can be taken by the UART interrupts during |
| 922 | * the DMA irq handler. So we check the residue here. |
| 923 | */ |
| 924 | rxchan->device->device_tx_status(rxchan, dmarx->cookie, &state); |
| 925 | pending = sgbuf->sg.length - state.residue; |
| 926 | BUG_ON(pending > PL011_DMA_BUFFER_SIZE); |
| 927 | /* Then we terminate the transfer - we now know our residue */ |
| 928 | dmaengine_terminate_all(rxchan); |
| 929 | |
Linus Walleij | ead76f3 | 2011-02-24 13:21:08 +0100 | [diff] [blame] | 930 | uap->dmarx.running = false; |
| 931 | dmarx->use_buf_b = !lastbuf; |
| 932 | ret = pl011_dma_rx_trigger_dma(uap); |
| 933 | |
Chanho Min | 6dc01aa | 2012-02-20 10:24:40 +0900 | [diff] [blame] | 934 | pl011_dma_rx_chars(uap, pending, lastbuf, false); |
Linus Walleij | ead76f3 | 2011-02-24 13:21:08 +0100 | [diff] [blame] | 935 | spin_unlock_irq(&uap->port.lock); |
| 936 | /* |
| 937 | * Do this check after we picked the DMA chars so we don't |
| 938 | * get some IRQ immediately from RX. |
| 939 | */ |
| 940 | if (ret) { |
| 941 | dev_dbg(uap->port.dev, "could not retrigger RX DMA job " |
| 942 | "fall back to interrupt mode\n"); |
| 943 | uap->im |= UART011_RXIM; |
Russell King | 9f25bc5 | 2015-11-03 14:51:13 +0000 | [diff] [blame^] | 944 | pl011_write(uap->im, uap, REG_IMSC); |
Linus Walleij | ead76f3 | 2011-02-24 13:21:08 +0100 | [diff] [blame] | 945 | } |
| 946 | } |
| 947 | |
| 948 | /* |
| 949 | * Stop accepting received characters, when we're shutting down or |
| 950 | * suspending this port. |
| 951 | * Locking: called with port lock held and IRQs disabled. |
| 952 | */ |
| 953 | static inline void pl011_dma_rx_stop(struct uart_amba_port *uap) |
| 954 | { |
| 955 | /* FIXME. Just disable the DMA enable */ |
| 956 | uap->dmacr &= ~UART011_RXDMAE; |
Russell King | 9f25bc5 | 2015-11-03 14:51:13 +0000 | [diff] [blame^] | 957 | pl011_write(uap->dmacr, uap, REG_DMACR); |
Linus Walleij | ead76f3 | 2011-02-24 13:21:08 +0100 | [diff] [blame] | 958 | } |
Russell King | 68b65f7 | 2010-12-22 17:24:39 +0000 | [diff] [blame] | 959 | |
Chanho Min | cb06ff1 | 2013-03-27 18:38:11 +0900 | [diff] [blame] | 960 | /* |
| 961 | * Timer handler for Rx DMA polling. |
| 962 | * Every polling, It checks the residue in the dma buffer and transfer |
| 963 | * data to the tty. Also, last_residue is updated for the next polling. |
| 964 | */ |
| 965 | static void pl011_dma_rx_poll(unsigned long args) |
| 966 | { |
| 967 | struct uart_amba_port *uap = (struct uart_amba_port *)args; |
| 968 | struct tty_port *port = &uap->port.state->port; |
| 969 | struct pl011_dmarx_data *dmarx = &uap->dmarx; |
| 970 | struct dma_chan *rxchan = uap->dmarx.chan; |
| 971 | unsigned long flags = 0; |
| 972 | unsigned int dmataken = 0; |
| 973 | unsigned int size = 0; |
| 974 | struct pl011_sgbuf *sgbuf; |
| 975 | int dma_count; |
| 976 | struct dma_tx_state state; |
| 977 | |
| 978 | sgbuf = dmarx->use_buf_b ? &uap->dmarx.sgbuf_b : &uap->dmarx.sgbuf_a; |
| 979 | rxchan->device->device_tx_status(rxchan, dmarx->cookie, &state); |
| 980 | if (likely(state.residue < dmarx->last_residue)) { |
| 981 | dmataken = sgbuf->sg.length - dmarx->last_residue; |
| 982 | size = dmarx->last_residue - state.residue; |
| 983 | dma_count = tty_insert_flip_string(port, sgbuf->buf + dmataken, |
| 984 | size); |
| 985 | if (dma_count == size) |
| 986 | dmarx->last_residue = state.residue; |
| 987 | dmarx->last_jiffies = jiffies; |
| 988 | } |
| 989 | tty_flip_buffer_push(port); |
| 990 | |
| 991 | /* |
| 992 | * If no data is received in poll_timeout, the driver will fall back |
| 993 | * to interrupt mode. We will retrigger DMA at the first interrupt. |
| 994 | */ |
| 995 | if (jiffies_to_msecs(jiffies - dmarx->last_jiffies) |
| 996 | > uap->dmarx.poll_timeout) { |
| 997 | |
| 998 | spin_lock_irqsave(&uap->port.lock, flags); |
| 999 | pl011_dma_rx_stop(uap); |
Guennadi Liakhovetski | c25a1ad | 2013-12-10 14:54:47 +0100 | [diff] [blame] | 1000 | uap->im |= UART011_RXIM; |
Russell King | 9f25bc5 | 2015-11-03 14:51:13 +0000 | [diff] [blame^] | 1001 | pl011_write(uap->im, uap, REG_IMSC); |
Chanho Min | cb06ff1 | 2013-03-27 18:38:11 +0900 | [diff] [blame] | 1002 | spin_unlock_irqrestore(&uap->port.lock, flags); |
| 1003 | |
| 1004 | uap->dmarx.running = false; |
| 1005 | dmaengine_terminate_all(rxchan); |
| 1006 | del_timer(&uap->dmarx.timer); |
| 1007 | } else { |
| 1008 | mod_timer(&uap->dmarx.timer, |
| 1009 | jiffies + msecs_to_jiffies(uap->dmarx.poll_rate)); |
| 1010 | } |
| 1011 | } |
| 1012 | |
Russell King | 68b65f7 | 2010-12-22 17:24:39 +0000 | [diff] [blame] | 1013 | static void pl011_dma_startup(struct uart_amba_port *uap) |
| 1014 | { |
Linus Walleij | ead76f3 | 2011-02-24 13:21:08 +0100 | [diff] [blame] | 1015 | int ret; |
| 1016 | |
Jorge Ramirez-Ortiz | 1c9be31 | 2015-03-06 13:05:40 -0500 | [diff] [blame] | 1017 | if (!uap->dma_probed) |
| 1018 | pl011_dma_probe(uap); |
| 1019 | |
Russell King | 68b65f7 | 2010-12-22 17:24:39 +0000 | [diff] [blame] | 1020 | if (!uap->dmatx.chan) |
| 1021 | return; |
| 1022 | |
Andrew Jackson | 4c0be45 | 2014-11-07 14:14:35 +0000 | [diff] [blame] | 1023 | uap->dmatx.buf = kmalloc(PL011_DMA_BUFFER_SIZE, GFP_KERNEL | __GFP_DMA); |
Russell King | 68b65f7 | 2010-12-22 17:24:39 +0000 | [diff] [blame] | 1024 | if (!uap->dmatx.buf) { |
| 1025 | dev_err(uap->port.dev, "no memory for DMA TX buffer\n"); |
| 1026 | uap->port.fifosize = uap->fifosize; |
| 1027 | return; |
| 1028 | } |
| 1029 | |
| 1030 | sg_init_one(&uap->dmatx.sg, uap->dmatx.buf, PL011_DMA_BUFFER_SIZE); |
| 1031 | |
| 1032 | /* The DMA buffer is now the FIFO the TTY subsystem can use */ |
| 1033 | uap->port.fifosize = PL011_DMA_BUFFER_SIZE; |
Linus Walleij | ead76f3 | 2011-02-24 13:21:08 +0100 | [diff] [blame] | 1034 | uap->using_tx_dma = true; |
Russell King | 68b65f7 | 2010-12-22 17:24:39 +0000 | [diff] [blame] | 1035 | |
Linus Walleij | ead76f3 | 2011-02-24 13:21:08 +0100 | [diff] [blame] | 1036 | if (!uap->dmarx.chan) |
| 1037 | goto skip_rx; |
| 1038 | |
| 1039 | /* Allocate and map DMA RX buffers */ |
| 1040 | ret = pl011_sgbuf_init(uap->dmarx.chan, &uap->dmarx.sgbuf_a, |
| 1041 | DMA_FROM_DEVICE); |
| 1042 | if (ret) { |
| 1043 | dev_err(uap->port.dev, "failed to init DMA %s: %d\n", |
| 1044 | "RX buffer A", ret); |
| 1045 | goto skip_rx; |
| 1046 | } |
| 1047 | |
| 1048 | ret = pl011_sgbuf_init(uap->dmarx.chan, &uap->dmarx.sgbuf_b, |
| 1049 | DMA_FROM_DEVICE); |
| 1050 | if (ret) { |
| 1051 | dev_err(uap->port.dev, "failed to init DMA %s: %d\n", |
| 1052 | "RX buffer B", ret); |
| 1053 | pl011_sgbuf_free(uap->dmarx.chan, &uap->dmarx.sgbuf_a, |
| 1054 | DMA_FROM_DEVICE); |
| 1055 | goto skip_rx; |
| 1056 | } |
| 1057 | |
| 1058 | uap->using_rx_dma = true; |
| 1059 | |
| 1060 | skip_rx: |
Russell King | 68b65f7 | 2010-12-22 17:24:39 +0000 | [diff] [blame] | 1061 | /* Turn on DMA error (RX/TX will be enabled on demand) */ |
| 1062 | uap->dmacr |= UART011_DMAONERR; |
Russell King | 9f25bc5 | 2015-11-03 14:51:13 +0000 | [diff] [blame^] | 1063 | pl011_write(uap->dmacr, uap, REG_DMACR); |
Russell King | 38d6243 | 2010-12-22 17:59:16 +0000 | [diff] [blame] | 1064 | |
| 1065 | /* |
| 1066 | * ST Micro variants has some specific dma burst threshold |
| 1067 | * compensation. Set this to 16 bytes, so burst will only |
| 1068 | * be issued above/below 16 bytes. |
| 1069 | */ |
| 1070 | if (uap->vendor->dma_threshold) |
Russell King | 7583633 | 2015-11-03 14:50:58 +0000 | [diff] [blame] | 1071 | pl011_write(ST_UART011_DMAWM_RX_16 | ST_UART011_DMAWM_TX_16, |
Russell King | 9f25bc5 | 2015-11-03 14:51:13 +0000 | [diff] [blame^] | 1072 | uap, REG_ST_DMAWM); |
Linus Walleij | ead76f3 | 2011-02-24 13:21:08 +0100 | [diff] [blame] | 1073 | |
| 1074 | if (uap->using_rx_dma) { |
| 1075 | if (pl011_dma_rx_trigger_dma(uap)) |
| 1076 | dev_dbg(uap->port.dev, "could not trigger initial " |
| 1077 | "RX DMA job, fall back to interrupt mode\n"); |
Chanho Min | cb06ff1 | 2013-03-27 18:38:11 +0900 | [diff] [blame] | 1078 | if (uap->dmarx.poll_rate) { |
| 1079 | init_timer(&(uap->dmarx.timer)); |
| 1080 | uap->dmarx.timer.function = pl011_dma_rx_poll; |
| 1081 | uap->dmarx.timer.data = (unsigned long)uap; |
| 1082 | mod_timer(&uap->dmarx.timer, |
| 1083 | jiffies + |
| 1084 | msecs_to_jiffies(uap->dmarx.poll_rate)); |
| 1085 | uap->dmarx.last_residue = PL011_DMA_BUFFER_SIZE; |
| 1086 | uap->dmarx.last_jiffies = jiffies; |
| 1087 | } |
Linus Walleij | ead76f3 | 2011-02-24 13:21:08 +0100 | [diff] [blame] | 1088 | } |
Russell King | 68b65f7 | 2010-12-22 17:24:39 +0000 | [diff] [blame] | 1089 | } |
| 1090 | |
| 1091 | static void pl011_dma_shutdown(struct uart_amba_port *uap) |
| 1092 | { |
Linus Walleij | ead76f3 | 2011-02-24 13:21:08 +0100 | [diff] [blame] | 1093 | if (!(uap->using_tx_dma || uap->using_rx_dma)) |
Russell King | 68b65f7 | 2010-12-22 17:24:39 +0000 | [diff] [blame] | 1094 | return; |
| 1095 | |
| 1096 | /* Disable RX and TX DMA */ |
Russell King | 9f25bc5 | 2015-11-03 14:51:13 +0000 | [diff] [blame^] | 1097 | while (pl011_read(uap, REG_FR) & UART01x_FR_BUSY) |
Russell King | 68b65f7 | 2010-12-22 17:24:39 +0000 | [diff] [blame] | 1098 | barrier(); |
| 1099 | |
| 1100 | spin_lock_irq(&uap->port.lock); |
| 1101 | uap->dmacr &= ~(UART011_DMAONERR | UART011_RXDMAE | UART011_TXDMAE); |
Russell King | 9f25bc5 | 2015-11-03 14:51:13 +0000 | [diff] [blame^] | 1102 | pl011_write(uap->dmacr, uap, REG_DMACR); |
Russell King | 68b65f7 | 2010-12-22 17:24:39 +0000 | [diff] [blame] | 1103 | spin_unlock_irq(&uap->port.lock); |
| 1104 | |
Linus Walleij | ead76f3 | 2011-02-24 13:21:08 +0100 | [diff] [blame] | 1105 | if (uap->using_tx_dma) { |
| 1106 | /* In theory, this should already be done by pl011_dma_flush_buffer */ |
| 1107 | dmaengine_terminate_all(uap->dmatx.chan); |
| 1108 | if (uap->dmatx.queued) { |
| 1109 | dma_unmap_sg(uap->dmatx.chan->device->dev, &uap->dmatx.sg, 1, |
| 1110 | DMA_TO_DEVICE); |
| 1111 | uap->dmatx.queued = false; |
| 1112 | } |
| 1113 | |
| 1114 | kfree(uap->dmatx.buf); |
| 1115 | uap->using_tx_dma = false; |
Russell King | 68b65f7 | 2010-12-22 17:24:39 +0000 | [diff] [blame] | 1116 | } |
| 1117 | |
Linus Walleij | ead76f3 | 2011-02-24 13:21:08 +0100 | [diff] [blame] | 1118 | if (uap->using_rx_dma) { |
| 1119 | dmaengine_terminate_all(uap->dmarx.chan); |
| 1120 | /* Clean up the RX DMA */ |
| 1121 | pl011_sgbuf_free(uap->dmarx.chan, &uap->dmarx.sgbuf_a, DMA_FROM_DEVICE); |
| 1122 | pl011_sgbuf_free(uap->dmarx.chan, &uap->dmarx.sgbuf_b, DMA_FROM_DEVICE); |
Chanho Min | cb06ff1 | 2013-03-27 18:38:11 +0900 | [diff] [blame] | 1123 | if (uap->dmarx.poll_rate) |
| 1124 | del_timer_sync(&uap->dmarx.timer); |
Linus Walleij | ead76f3 | 2011-02-24 13:21:08 +0100 | [diff] [blame] | 1125 | uap->using_rx_dma = false; |
| 1126 | } |
Russell King | 68b65f7 | 2010-12-22 17:24:39 +0000 | [diff] [blame] | 1127 | } |
| 1128 | |
Linus Walleij | ead76f3 | 2011-02-24 13:21:08 +0100 | [diff] [blame] | 1129 | static inline bool pl011_dma_rx_available(struct uart_amba_port *uap) |
| 1130 | { |
| 1131 | return uap->using_rx_dma; |
| 1132 | } |
| 1133 | |
| 1134 | static inline bool pl011_dma_rx_running(struct uart_amba_port *uap) |
| 1135 | { |
| 1136 | return uap->using_rx_dma && uap->dmarx.running; |
| 1137 | } |
| 1138 | |
Russell King | 68b65f7 | 2010-12-22 17:24:39 +0000 | [diff] [blame] | 1139 | #else |
| 1140 | /* Blank functions if the DMA engine is not available */ |
Jorge Ramirez-Ortiz | 1c9be31 | 2015-03-06 13:05:40 -0500 | [diff] [blame] | 1141 | static inline void pl011_dma_probe(struct uart_amba_port *uap) |
Russell King | 68b65f7 | 2010-12-22 17:24:39 +0000 | [diff] [blame] | 1142 | { |
| 1143 | } |
| 1144 | |
| 1145 | static inline void pl011_dma_remove(struct uart_amba_port *uap) |
| 1146 | { |
| 1147 | } |
| 1148 | |
| 1149 | static inline void pl011_dma_startup(struct uart_amba_port *uap) |
| 1150 | { |
| 1151 | } |
| 1152 | |
| 1153 | static inline void pl011_dma_shutdown(struct uart_amba_port *uap) |
| 1154 | { |
| 1155 | } |
| 1156 | |
| 1157 | static inline bool pl011_dma_tx_irq(struct uart_amba_port *uap) |
| 1158 | { |
| 1159 | return false; |
| 1160 | } |
| 1161 | |
| 1162 | static inline void pl011_dma_tx_stop(struct uart_amba_port *uap) |
| 1163 | { |
| 1164 | } |
| 1165 | |
| 1166 | static inline bool pl011_dma_tx_start(struct uart_amba_port *uap) |
| 1167 | { |
| 1168 | return false; |
| 1169 | } |
| 1170 | |
Linus Walleij | ead76f3 | 2011-02-24 13:21:08 +0100 | [diff] [blame] | 1171 | static inline void pl011_dma_rx_irq(struct uart_amba_port *uap) |
| 1172 | { |
| 1173 | } |
| 1174 | |
| 1175 | static inline void pl011_dma_rx_stop(struct uart_amba_port *uap) |
| 1176 | { |
| 1177 | } |
| 1178 | |
| 1179 | static inline int pl011_dma_rx_trigger_dma(struct uart_amba_port *uap) |
| 1180 | { |
| 1181 | return -EIO; |
| 1182 | } |
| 1183 | |
| 1184 | static inline bool pl011_dma_rx_available(struct uart_amba_port *uap) |
| 1185 | { |
| 1186 | return false; |
| 1187 | } |
| 1188 | |
| 1189 | static inline bool pl011_dma_rx_running(struct uart_amba_port *uap) |
| 1190 | { |
| 1191 | return false; |
| 1192 | } |
| 1193 | |
Russell King | 68b65f7 | 2010-12-22 17:24:39 +0000 | [diff] [blame] | 1194 | #define pl011_dma_flush_buffer NULL |
| 1195 | #endif |
| 1196 | |
Russell King | b129a8c | 2005-08-31 10:12:14 +0100 | [diff] [blame] | 1197 | static void pl011_stop_tx(struct uart_port *port) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1198 | { |
Daniel Thompson | a5820c2 | 2014-09-03 12:51:55 +0100 | [diff] [blame] | 1199 | struct uart_amba_port *uap = |
| 1200 | container_of(port, struct uart_amba_port, port); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1201 | |
| 1202 | uap->im &= ~UART011_TXIM; |
Russell King | 9f25bc5 | 2015-11-03 14:51:13 +0000 | [diff] [blame^] | 1203 | pl011_write(uap->im, uap, REG_IMSC); |
Russell King | 68b65f7 | 2010-12-22 17:24:39 +0000 | [diff] [blame] | 1204 | pl011_dma_tx_stop(uap); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1205 | } |
| 1206 | |
Dave Martin | 1e84d22 | 2015-04-27 16:49:05 +0100 | [diff] [blame] | 1207 | static void pl011_tx_chars(struct uart_amba_port *uap, bool from_irq); |
Dave Martin | 734745c | 2015-03-04 12:27:33 +0000 | [diff] [blame] | 1208 | |
| 1209 | /* Start TX with programmed I/O only (no DMA) */ |
| 1210 | static void pl011_start_tx_pio(struct uart_amba_port *uap) |
| 1211 | { |
| 1212 | uap->im |= UART011_TXIM; |
Russell King | 9f25bc5 | 2015-11-03 14:51:13 +0000 | [diff] [blame^] | 1213 | pl011_write(uap->im, uap, REG_IMSC); |
Dave Martin | 1e84d22 | 2015-04-27 16:49:05 +0100 | [diff] [blame] | 1214 | pl011_tx_chars(uap, false); |
Dave Martin | 734745c | 2015-03-04 12:27:33 +0000 | [diff] [blame] | 1215 | } |
| 1216 | |
Russell King | b129a8c | 2005-08-31 10:12:14 +0100 | [diff] [blame] | 1217 | static void pl011_start_tx(struct uart_port *port) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1218 | { |
Daniel Thompson | a5820c2 | 2014-09-03 12:51:55 +0100 | [diff] [blame] | 1219 | struct uart_amba_port *uap = |
| 1220 | container_of(port, struct uart_amba_port, port); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1221 | |
Dave Martin | 734745c | 2015-03-04 12:27:33 +0000 | [diff] [blame] | 1222 | if (!pl011_dma_tx_start(uap)) |
| 1223 | pl011_start_tx_pio(uap); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1224 | } |
| 1225 | |
| 1226 | static void pl011_stop_rx(struct uart_port *port) |
| 1227 | { |
Daniel Thompson | a5820c2 | 2014-09-03 12:51:55 +0100 | [diff] [blame] | 1228 | struct uart_amba_port *uap = |
| 1229 | container_of(port, struct uart_amba_port, port); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1230 | |
| 1231 | uap->im &= ~(UART011_RXIM|UART011_RTIM|UART011_FEIM| |
| 1232 | UART011_PEIM|UART011_BEIM|UART011_OEIM); |
Russell King | 9f25bc5 | 2015-11-03 14:51:13 +0000 | [diff] [blame^] | 1233 | pl011_write(uap->im, uap, REG_IMSC); |
Linus Walleij | ead76f3 | 2011-02-24 13:21:08 +0100 | [diff] [blame] | 1234 | |
| 1235 | pl011_dma_rx_stop(uap); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1236 | } |
| 1237 | |
| 1238 | static void pl011_enable_ms(struct uart_port *port) |
| 1239 | { |
Daniel Thompson | a5820c2 | 2014-09-03 12:51:55 +0100 | [diff] [blame] | 1240 | struct uart_amba_port *uap = |
| 1241 | container_of(port, struct uart_amba_port, port); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1242 | |
| 1243 | uap->im |= UART011_RIMIM|UART011_CTSMIM|UART011_DCDMIM|UART011_DSRMIM; |
Russell King | 9f25bc5 | 2015-11-03 14:51:13 +0000 | [diff] [blame^] | 1244 | pl011_write(uap->im, uap, REG_IMSC); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1245 | } |
| 1246 | |
David Howells | 7d12e78 | 2006-10-05 14:55:46 +0100 | [diff] [blame] | 1247 | static void pl011_rx_chars(struct uart_amba_port *uap) |
Fabio Estevam | b83286b | 2013-08-09 17:58:51 -0300 | [diff] [blame] | 1248 | __releases(&uap->port.lock) |
| 1249 | __acquires(&uap->port.lock) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1250 | { |
Linus Walleij | 29772c4 | 2011-02-24 13:21:36 +0100 | [diff] [blame] | 1251 | pl011_fifo_to_tty(uap); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1252 | |
Thomas Gleixner | 2389b27 | 2007-05-29 21:53:50 +0100 | [diff] [blame] | 1253 | spin_unlock(&uap->port.lock); |
Jiri Slaby | 2e124b4 | 2013-01-03 15:53:06 +0100 | [diff] [blame] | 1254 | tty_flip_buffer_push(&uap->port.state->port); |
Linus Walleij | ead76f3 | 2011-02-24 13:21:08 +0100 | [diff] [blame] | 1255 | /* |
| 1256 | * If we were temporarily out of DMA mode for a while, |
| 1257 | * attempt to switch back to DMA mode again. |
| 1258 | */ |
| 1259 | if (pl011_dma_rx_available(uap)) { |
| 1260 | if (pl011_dma_rx_trigger_dma(uap)) { |
| 1261 | dev_dbg(uap->port.dev, "could not trigger RX DMA job " |
| 1262 | "fall back to interrupt mode again\n"); |
| 1263 | uap->im |= UART011_RXIM; |
Russell King | 9f25bc5 | 2015-11-03 14:51:13 +0000 | [diff] [blame^] | 1264 | pl011_write(uap->im, uap, REG_IMSC); |
Chanho Min | cb06ff1 | 2013-03-27 18:38:11 +0900 | [diff] [blame] | 1265 | } else { |
Chanho Min | 89fa28d | 2013-04-03 11:10:37 +0900 | [diff] [blame] | 1266 | #ifdef CONFIG_DMA_ENGINE |
Chanho Min | cb06ff1 | 2013-03-27 18:38:11 +0900 | [diff] [blame] | 1267 | /* Start Rx DMA poll */ |
| 1268 | if (uap->dmarx.poll_rate) { |
| 1269 | uap->dmarx.last_jiffies = jiffies; |
| 1270 | uap->dmarx.last_residue = PL011_DMA_BUFFER_SIZE; |
| 1271 | mod_timer(&uap->dmarx.timer, |
| 1272 | jiffies + |
| 1273 | msecs_to_jiffies(uap->dmarx.poll_rate)); |
| 1274 | } |
Chanho Min | 89fa28d | 2013-04-03 11:10:37 +0900 | [diff] [blame] | 1275 | #endif |
Chanho Min | cb06ff1 | 2013-03-27 18:38:11 +0900 | [diff] [blame] | 1276 | } |
Linus Walleij | ead76f3 | 2011-02-24 13:21:08 +0100 | [diff] [blame] | 1277 | } |
Thomas Gleixner | 2389b27 | 2007-05-29 21:53:50 +0100 | [diff] [blame] | 1278 | spin_lock(&uap->port.lock); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1279 | } |
| 1280 | |
Dave Martin | 1e84d22 | 2015-04-27 16:49:05 +0100 | [diff] [blame] | 1281 | static bool pl011_tx_char(struct uart_amba_port *uap, unsigned char c, |
| 1282 | bool from_irq) |
Dave Martin | 734745c | 2015-03-04 12:27:33 +0000 | [diff] [blame] | 1283 | { |
Dave Martin | 1e84d22 | 2015-04-27 16:49:05 +0100 | [diff] [blame] | 1284 | if (unlikely(!from_irq) && |
Russell King | 9f25bc5 | 2015-11-03 14:51:13 +0000 | [diff] [blame^] | 1285 | pl011_read(uap, REG_FR) & UART01x_FR_TXFF) |
Dave Martin | 1e84d22 | 2015-04-27 16:49:05 +0100 | [diff] [blame] | 1286 | return false; /* unable to transmit character */ |
| 1287 | |
Russell King | 9f25bc5 | 2015-11-03 14:51:13 +0000 | [diff] [blame^] | 1288 | pl011_write(c, uap, REG_DR); |
Dave Martin | 734745c | 2015-03-04 12:27:33 +0000 | [diff] [blame] | 1289 | uap->port.icount.tx++; |
| 1290 | |
Dave Martin | 1e84d22 | 2015-04-27 16:49:05 +0100 | [diff] [blame] | 1291 | return true; |
Dave Martin | 734745c | 2015-03-04 12:27:33 +0000 | [diff] [blame] | 1292 | } |
| 1293 | |
Dave Martin | 1e84d22 | 2015-04-27 16:49:05 +0100 | [diff] [blame] | 1294 | static void pl011_tx_chars(struct uart_amba_port *uap, bool from_irq) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1295 | { |
Alan Cox | ebd2c8f | 2009-09-19 13:13:28 -0700 | [diff] [blame] | 1296 | struct circ_buf *xmit = &uap->port.state->xmit; |
Dave Martin | 1e84d22 | 2015-04-27 16:49:05 +0100 | [diff] [blame] | 1297 | int count = uap->fifosize >> 1; |
Dave Martin | 734745c | 2015-03-04 12:27:33 +0000 | [diff] [blame] | 1298 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1299 | if (uap->port.x_char) { |
Dave Martin | 1e84d22 | 2015-04-27 16:49:05 +0100 | [diff] [blame] | 1300 | if (!pl011_tx_char(uap, uap->port.x_char, from_irq)) |
| 1301 | return; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1302 | uap->port.x_char = 0; |
Dave Martin | 734745c | 2015-03-04 12:27:33 +0000 | [diff] [blame] | 1303 | --count; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1304 | } |
| 1305 | if (uart_circ_empty(xmit) || uart_tx_stopped(&uap->port)) { |
Russell King | b129a8c | 2005-08-31 10:12:14 +0100 | [diff] [blame] | 1306 | pl011_stop_tx(&uap->port); |
Dave Martin | 1e84d22 | 2015-04-27 16:49:05 +0100 | [diff] [blame] | 1307 | return; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1308 | } |
| 1309 | |
Russell King | 68b65f7 | 2010-12-22 17:24:39 +0000 | [diff] [blame] | 1310 | /* If we are using DMA mode, try to send some characters. */ |
| 1311 | if (pl011_dma_tx_irq(uap)) |
Dave Martin | 1e84d22 | 2015-04-27 16:49:05 +0100 | [diff] [blame] | 1312 | return; |
Russell King | 68b65f7 | 2010-12-22 17:24:39 +0000 | [diff] [blame] | 1313 | |
Dave Martin | 1e84d22 | 2015-04-27 16:49:05 +0100 | [diff] [blame] | 1314 | do { |
| 1315 | if (likely(from_irq) && count-- == 0) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1316 | break; |
Dave Martin | 1e84d22 | 2015-04-27 16:49:05 +0100 | [diff] [blame] | 1317 | |
| 1318 | if (!pl011_tx_char(uap, xmit->buf[xmit->tail], from_irq)) |
| 1319 | break; |
| 1320 | |
| 1321 | xmit->tail = (xmit->tail + 1) & (UART_XMIT_SIZE - 1); |
| 1322 | } while (!uart_circ_empty(xmit)); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1323 | |
| 1324 | if (uart_circ_chars_pending(xmit) < WAKEUP_CHARS) |
| 1325 | uart_write_wakeup(&uap->port); |
| 1326 | |
Dave Martin | 1e84d22 | 2015-04-27 16:49:05 +0100 | [diff] [blame] | 1327 | if (uart_circ_empty(xmit)) |
Russell King | b129a8c | 2005-08-31 10:12:14 +0100 | [diff] [blame] | 1328 | pl011_stop_tx(&uap->port); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1329 | } |
| 1330 | |
| 1331 | static void pl011_modem_status(struct uart_amba_port *uap) |
| 1332 | { |
| 1333 | unsigned int status, delta; |
| 1334 | |
Russell King | 9f25bc5 | 2015-11-03 14:51:13 +0000 | [diff] [blame^] | 1335 | status = pl011_read(uap, REG_FR) & UART01x_FR_MODEM_ANY; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1336 | |
| 1337 | delta = status ^ uap->old_status; |
| 1338 | uap->old_status = status; |
| 1339 | |
| 1340 | if (!delta) |
| 1341 | return; |
| 1342 | |
| 1343 | if (delta & UART01x_FR_DCD) |
| 1344 | uart_handle_dcd_change(&uap->port, status & UART01x_FR_DCD); |
| 1345 | |
Greg Kroah-Hartman | 062a68a | 2015-09-04 09:11:24 -0700 | [diff] [blame] | 1346 | if (delta & UART01x_FR_DSR) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1347 | uap->port.icount.dsr++; |
| 1348 | |
Greg Kroah-Hartman | 062a68a | 2015-09-04 09:11:24 -0700 | [diff] [blame] | 1349 | if (delta & UART01x_FR_CTS) |
| 1350 | uart_handle_cts_change(&uap->port, status & UART01x_FR_CTS); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1351 | |
Alan Cox | bdc04e3 | 2009-09-19 13:13:31 -0700 | [diff] [blame] | 1352 | wake_up_interruptible(&uap->port.state->port.delta_msr_wait); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1353 | } |
| 1354 | |
Andre Przywara | 9c4ef4b | 2015-05-21 17:26:20 +0100 | [diff] [blame] | 1355 | static void check_apply_cts_event_workaround(struct uart_amba_port *uap) |
| 1356 | { |
| 1357 | unsigned int dummy_read; |
| 1358 | |
| 1359 | if (!uap->vendor->cts_event_workaround) |
| 1360 | return; |
| 1361 | |
| 1362 | /* workaround to make sure that all bits are unlocked.. */ |
Russell King | 9f25bc5 | 2015-11-03 14:51:13 +0000 | [diff] [blame^] | 1363 | pl011_write(0x00, uap, REG_ICR); |
Andre Przywara | 9c4ef4b | 2015-05-21 17:26:20 +0100 | [diff] [blame] | 1364 | |
| 1365 | /* |
| 1366 | * WA: introduce 26ns(1 uart clk) delay before W1C; |
| 1367 | * single apb access will incur 2 pclk(133.12Mhz) delay, |
| 1368 | * so add 2 dummy reads |
| 1369 | */ |
Russell King | 9f25bc5 | 2015-11-03 14:51:13 +0000 | [diff] [blame^] | 1370 | dummy_read = pl011_read(uap, REG_ICR); |
| 1371 | dummy_read = pl011_read(uap, REG_ICR); |
Andre Przywara | 9c4ef4b | 2015-05-21 17:26:20 +0100 | [diff] [blame] | 1372 | } |
| 1373 | |
David Howells | 7d12e78 | 2006-10-05 14:55:46 +0100 | [diff] [blame] | 1374 | static irqreturn_t pl011_int(int irq, void *dev_id) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1375 | { |
| 1376 | struct uart_amba_port *uap = dev_id; |
Russell King | 963cc98 | 2010-12-22 17:16:09 +0000 | [diff] [blame] | 1377 | unsigned long flags; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1378 | unsigned int status, pass_counter = AMBA_ISR_PASS_LIMIT; |
Andre Przywara | 075167e | 2015-05-21 17:26:19 +0100 | [diff] [blame] | 1379 | u16 imsc; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1380 | int handled = 0; |
| 1381 | |
Russell King | 963cc98 | 2010-12-22 17:16:09 +0000 | [diff] [blame] | 1382 | spin_lock_irqsave(&uap->port.lock, flags); |
Russell King | 9f25bc5 | 2015-11-03 14:51:13 +0000 | [diff] [blame^] | 1383 | imsc = pl011_read(uap, REG_IMSC); |
| 1384 | status = pl011_read(uap, REG_RIS) & imsc; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1385 | if (status) { |
| 1386 | do { |
Andre Przywara | 9c4ef4b | 2015-05-21 17:26:20 +0100 | [diff] [blame] | 1387 | check_apply_cts_event_workaround(uap); |
Greg Kroah-Hartman | f11c984 | 2015-09-04 09:13:39 -0700 | [diff] [blame] | 1388 | |
Russell King | 7583633 | 2015-11-03 14:50:58 +0000 | [diff] [blame] | 1389 | pl011_write(status & ~(UART011_TXIS|UART011_RTIS| |
| 1390 | UART011_RXIS), |
Russell King | 9f25bc5 | 2015-11-03 14:51:13 +0000 | [diff] [blame^] | 1391 | uap, REG_ICR); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1392 | |
Linus Walleij | ead76f3 | 2011-02-24 13:21:08 +0100 | [diff] [blame] | 1393 | if (status & (UART011_RTIS|UART011_RXIS)) { |
| 1394 | if (pl011_dma_rx_running(uap)) |
| 1395 | pl011_dma_rx_irq(uap); |
| 1396 | else |
| 1397 | pl011_rx_chars(uap); |
| 1398 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1399 | if (status & (UART011_DSRMIS|UART011_DCDMIS| |
| 1400 | UART011_CTSMIS|UART011_RIMIS)) |
| 1401 | pl011_modem_status(uap); |
Dave Martin | 1e84d22 | 2015-04-27 16:49:05 +0100 | [diff] [blame] | 1402 | if (status & UART011_TXIS) |
| 1403 | pl011_tx_chars(uap, true); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1404 | |
Rajanikanth H.V | 4fd0690 | 2012-03-26 11:17:02 +0200 | [diff] [blame] | 1405 | if (pass_counter-- == 0) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1406 | break; |
| 1407 | |
Russell King | 9f25bc5 | 2015-11-03 14:51:13 +0000 | [diff] [blame^] | 1408 | status = pl011_read(uap, REG_RIS) & imsc; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1409 | } while (status != 0); |
| 1410 | handled = 1; |
| 1411 | } |
| 1412 | |
Russell King | 963cc98 | 2010-12-22 17:16:09 +0000 | [diff] [blame] | 1413 | spin_unlock_irqrestore(&uap->port.lock, flags); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1414 | |
| 1415 | return IRQ_RETVAL(handled); |
| 1416 | } |
| 1417 | |
Linus Walleij | e643f87 | 2012-06-17 15:44:19 +0200 | [diff] [blame] | 1418 | static unsigned int pl011_tx_empty(struct uart_port *port) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1419 | { |
Daniel Thompson | a5820c2 | 2014-09-03 12:51:55 +0100 | [diff] [blame] | 1420 | struct uart_amba_port *uap = |
| 1421 | container_of(port, struct uart_amba_port, port); |
Russell King | 9f25bc5 | 2015-11-03 14:51:13 +0000 | [diff] [blame^] | 1422 | unsigned int status = pl011_read(uap, REG_FR); |
Greg Kroah-Hartman | 062a68a | 2015-09-04 09:11:24 -0700 | [diff] [blame] | 1423 | return status & (UART01x_FR_BUSY|UART01x_FR_TXFF) ? 0 : TIOCSER_TEMT; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1424 | } |
| 1425 | |
Linus Walleij | e643f87 | 2012-06-17 15:44:19 +0200 | [diff] [blame] | 1426 | static unsigned int pl011_get_mctrl(struct uart_port *port) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1427 | { |
Daniel Thompson | a5820c2 | 2014-09-03 12:51:55 +0100 | [diff] [blame] | 1428 | struct uart_amba_port *uap = |
| 1429 | container_of(port, struct uart_amba_port, port); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1430 | unsigned int result = 0; |
Russell King | 9f25bc5 | 2015-11-03 14:51:13 +0000 | [diff] [blame^] | 1431 | unsigned int status = pl011_read(uap, REG_FR); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1432 | |
Jiri Slaby | 5159f40 | 2007-10-18 23:40:31 -0700 | [diff] [blame] | 1433 | #define TIOCMBIT(uartbit, tiocmbit) \ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1434 | if (status & uartbit) \ |
| 1435 | result |= tiocmbit |
| 1436 | |
Jiri Slaby | 5159f40 | 2007-10-18 23:40:31 -0700 | [diff] [blame] | 1437 | TIOCMBIT(UART01x_FR_DCD, TIOCM_CAR); |
Greg Kroah-Hartman | 062a68a | 2015-09-04 09:11:24 -0700 | [diff] [blame] | 1438 | TIOCMBIT(UART01x_FR_DSR, TIOCM_DSR); |
| 1439 | TIOCMBIT(UART01x_FR_CTS, TIOCM_CTS); |
| 1440 | TIOCMBIT(UART011_FR_RI, TIOCM_RNG); |
Jiri Slaby | 5159f40 | 2007-10-18 23:40:31 -0700 | [diff] [blame] | 1441 | #undef TIOCMBIT |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1442 | return result; |
| 1443 | } |
| 1444 | |
| 1445 | static void pl011_set_mctrl(struct uart_port *port, unsigned int mctrl) |
| 1446 | { |
Daniel Thompson | a5820c2 | 2014-09-03 12:51:55 +0100 | [diff] [blame] | 1447 | struct uart_amba_port *uap = |
| 1448 | container_of(port, struct uart_amba_port, port); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1449 | unsigned int cr; |
| 1450 | |
Russell King | 9f25bc5 | 2015-11-03 14:51:13 +0000 | [diff] [blame^] | 1451 | cr = pl011_read(uap, REG_CR); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1452 | |
Jiri Slaby | 5159f40 | 2007-10-18 23:40:31 -0700 | [diff] [blame] | 1453 | #define TIOCMBIT(tiocmbit, uartbit) \ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1454 | if (mctrl & tiocmbit) \ |
| 1455 | cr |= uartbit; \ |
| 1456 | else \ |
| 1457 | cr &= ~uartbit |
| 1458 | |
Jiri Slaby | 5159f40 | 2007-10-18 23:40:31 -0700 | [diff] [blame] | 1459 | TIOCMBIT(TIOCM_RTS, UART011_CR_RTS); |
| 1460 | TIOCMBIT(TIOCM_DTR, UART011_CR_DTR); |
| 1461 | TIOCMBIT(TIOCM_OUT1, UART011_CR_OUT1); |
| 1462 | TIOCMBIT(TIOCM_OUT2, UART011_CR_OUT2); |
| 1463 | TIOCMBIT(TIOCM_LOOP, UART011_CR_LBE); |
Rabin Vincent | 3b43816 | 2010-02-12 06:43:11 +0100 | [diff] [blame] | 1464 | |
| 1465 | if (uap->autorts) { |
| 1466 | /* We need to disable auto-RTS if we want to turn RTS off */ |
| 1467 | TIOCMBIT(TIOCM_RTS, UART011_CR_RTSEN); |
| 1468 | } |
Jiri Slaby | 5159f40 | 2007-10-18 23:40:31 -0700 | [diff] [blame] | 1469 | #undef TIOCMBIT |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1470 | |
Russell King | 9f25bc5 | 2015-11-03 14:51:13 +0000 | [diff] [blame^] | 1471 | pl011_write(cr, uap, REG_CR); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1472 | } |
| 1473 | |
| 1474 | static void pl011_break_ctl(struct uart_port *port, int break_state) |
| 1475 | { |
Daniel Thompson | a5820c2 | 2014-09-03 12:51:55 +0100 | [diff] [blame] | 1476 | struct uart_amba_port *uap = |
| 1477 | container_of(port, struct uart_amba_port, port); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1478 | unsigned long flags; |
| 1479 | unsigned int lcr_h; |
| 1480 | |
| 1481 | spin_lock_irqsave(&uap->port.lock, flags); |
Russell King | b2a4e24 | 2015-11-03 14:51:03 +0000 | [diff] [blame] | 1482 | lcr_h = pl011_read(uap, uap->lcrh_tx); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1483 | if (break_state == -1) |
| 1484 | lcr_h |= UART01x_LCRH_BRK; |
| 1485 | else |
| 1486 | lcr_h &= ~UART01x_LCRH_BRK; |
Russell King | b2a4e24 | 2015-11-03 14:51:03 +0000 | [diff] [blame] | 1487 | pl011_write(lcr_h, uap, uap->lcrh_tx); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1488 | spin_unlock_irqrestore(&uap->port.lock, flags); |
| 1489 | } |
| 1490 | |
Jason Wessel | 84b5ae1 | 2008-02-20 13:33:39 -0600 | [diff] [blame] | 1491 | #ifdef CONFIG_CONSOLE_POLL |
Anton Vorontsov | 5c8124a | 2012-09-24 14:27:55 -0700 | [diff] [blame] | 1492 | |
| 1493 | static void pl011_quiesce_irqs(struct uart_port *port) |
| 1494 | { |
Daniel Thompson | a5820c2 | 2014-09-03 12:51:55 +0100 | [diff] [blame] | 1495 | struct uart_amba_port *uap = |
| 1496 | container_of(port, struct uart_amba_port, port); |
Anton Vorontsov | 5c8124a | 2012-09-24 14:27:55 -0700 | [diff] [blame] | 1497 | |
Russell King | 9f25bc5 | 2015-11-03 14:51:13 +0000 | [diff] [blame^] | 1498 | pl011_write(pl011_read(uap, REG_MIS), uap, REG_ICR); |
Anton Vorontsov | 5c8124a | 2012-09-24 14:27:55 -0700 | [diff] [blame] | 1499 | /* |
| 1500 | * There is no way to clear TXIM as this is "ready to transmit IRQ", so |
| 1501 | * we simply mask it. start_tx() will unmask it. |
| 1502 | * |
| 1503 | * Note we can race with start_tx(), and if the race happens, the |
| 1504 | * polling user might get another interrupt just after we clear it. |
| 1505 | * But it should be OK and can happen even w/o the race, e.g. |
| 1506 | * controller immediately got some new data and raised the IRQ. |
| 1507 | * |
| 1508 | * And whoever uses polling routines assumes that it manages the device |
| 1509 | * (including tx queue), so we're also fine with start_tx()'s caller |
| 1510 | * side. |
| 1511 | */ |
Russell King | 9f25bc5 | 2015-11-03 14:51:13 +0000 | [diff] [blame^] | 1512 | pl011_write(pl011_read(uap, REG_IMSC) & ~UART011_TXIM, uap, |
| 1513 | REG_IMSC); |
Anton Vorontsov | 5c8124a | 2012-09-24 14:27:55 -0700 | [diff] [blame] | 1514 | } |
| 1515 | |
Linus Walleij | e643f87 | 2012-06-17 15:44:19 +0200 | [diff] [blame] | 1516 | static int pl011_get_poll_char(struct uart_port *port) |
Jason Wessel | 84b5ae1 | 2008-02-20 13:33:39 -0600 | [diff] [blame] | 1517 | { |
Daniel Thompson | a5820c2 | 2014-09-03 12:51:55 +0100 | [diff] [blame] | 1518 | struct uart_amba_port *uap = |
| 1519 | container_of(port, struct uart_amba_port, port); |
Jason Wessel | 84b5ae1 | 2008-02-20 13:33:39 -0600 | [diff] [blame] | 1520 | unsigned int status; |
| 1521 | |
Anton Vorontsov | 5c8124a | 2012-09-24 14:27:55 -0700 | [diff] [blame] | 1522 | /* |
| 1523 | * The caller might need IRQs lowered, e.g. if used with KDB NMI |
| 1524 | * debugger. |
| 1525 | */ |
| 1526 | pl011_quiesce_irqs(port); |
| 1527 | |
Russell King | 9f25bc5 | 2015-11-03 14:51:13 +0000 | [diff] [blame^] | 1528 | status = pl011_read(uap, REG_FR); |
Jason Wessel | f5316b4 | 2010-05-20 21:04:22 -0500 | [diff] [blame] | 1529 | if (status & UART01x_FR_RXFE) |
| 1530 | return NO_POLL_CHAR; |
Jason Wessel | 84b5ae1 | 2008-02-20 13:33:39 -0600 | [diff] [blame] | 1531 | |
Russell King | 9f25bc5 | 2015-11-03 14:51:13 +0000 | [diff] [blame^] | 1532 | return pl011_read(uap, REG_DR); |
Jason Wessel | 84b5ae1 | 2008-02-20 13:33:39 -0600 | [diff] [blame] | 1533 | } |
| 1534 | |
Linus Walleij | e643f87 | 2012-06-17 15:44:19 +0200 | [diff] [blame] | 1535 | static void pl011_put_poll_char(struct uart_port *port, |
Jason Wessel | 84b5ae1 | 2008-02-20 13:33:39 -0600 | [diff] [blame] | 1536 | unsigned char ch) |
| 1537 | { |
Daniel Thompson | a5820c2 | 2014-09-03 12:51:55 +0100 | [diff] [blame] | 1538 | struct uart_amba_port *uap = |
| 1539 | container_of(port, struct uart_amba_port, port); |
Jason Wessel | 84b5ae1 | 2008-02-20 13:33:39 -0600 | [diff] [blame] | 1540 | |
Russell King | 9f25bc5 | 2015-11-03 14:51:13 +0000 | [diff] [blame^] | 1541 | while (pl011_read(uap, REG_FR) & UART01x_FR_TXFF) |
Jason Wessel | 84b5ae1 | 2008-02-20 13:33:39 -0600 | [diff] [blame] | 1542 | barrier(); |
| 1543 | |
Russell King | 9f25bc5 | 2015-11-03 14:51:13 +0000 | [diff] [blame^] | 1544 | pl011_write(ch, uap, REG_DR); |
Jason Wessel | 84b5ae1 | 2008-02-20 13:33:39 -0600 | [diff] [blame] | 1545 | } |
| 1546 | |
| 1547 | #endif /* CONFIG_CONSOLE_POLL */ |
| 1548 | |
Anton Vorontsov | b3564c2 | 2012-09-24 14:27:54 -0700 | [diff] [blame] | 1549 | static int pl011_hwinit(struct uart_port *port) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1550 | { |
Daniel Thompson | a5820c2 | 2014-09-03 12:51:55 +0100 | [diff] [blame] | 1551 | struct uart_amba_port *uap = |
| 1552 | container_of(port, struct uart_amba_port, port); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1553 | int retval; |
| 1554 | |
Linus Walleij | 78d80c5 | 2012-05-23 21:18:46 +0200 | [diff] [blame] | 1555 | /* Optionaly enable pins to be muxed in and configured */ |
Linus Walleij | 2b996fc | 2013-06-05 15:36:42 +0200 | [diff] [blame] | 1556 | pinctrl_pm_select_default_state(port->dev); |
Linus Walleij | 78d80c5 | 2012-05-23 21:18:46 +0200 | [diff] [blame] | 1557 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1558 | /* |
| 1559 | * Try to enable the clock producer. |
| 1560 | */ |
Julia Lawall | 1c4c439 | 2012-08-26 18:01:01 +0200 | [diff] [blame] | 1561 | retval = clk_prepare_enable(uap->clk); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1562 | if (retval) |
Tushar Behera | 7f6d942 | 2014-06-26 15:35:35 +0530 | [diff] [blame] | 1563 | return retval; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1564 | |
| 1565 | uap->port.uartclk = clk_get_rate(uap->clk); |
| 1566 | |
Linus Walleij | 9b96fba | 2012-03-13 13:27:23 +0100 | [diff] [blame] | 1567 | /* Clear pending error and receive interrupts */ |
Russell King | 7583633 | 2015-11-03 14:50:58 +0000 | [diff] [blame] | 1568 | pl011_write(UART011_OEIS | UART011_BEIS | UART011_PEIS | |
| 1569 | UART011_FEIS | UART011_RTIS | UART011_RXIS, |
Russell King | 9f25bc5 | 2015-11-03 14:51:13 +0000 | [diff] [blame^] | 1570 | uap, REG_ICR); |
Linus Walleij | 9b96fba | 2012-03-13 13:27:23 +0100 | [diff] [blame] | 1571 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1572 | /* |
Anton Vorontsov | b3564c2 | 2012-09-24 14:27:54 -0700 | [diff] [blame] | 1573 | * Save interrupts enable mask, and enable RX interrupts in case if |
| 1574 | * the interrupt is used for NMI entry. |
| 1575 | */ |
Russell King | 9f25bc5 | 2015-11-03 14:51:13 +0000 | [diff] [blame^] | 1576 | uap->im = pl011_read(uap, REG_IMSC); |
| 1577 | pl011_write(UART011_RTIM | UART011_RXIM, uap, REG_IMSC); |
Anton Vorontsov | b3564c2 | 2012-09-24 14:27:54 -0700 | [diff] [blame] | 1578 | |
Jingoo Han | 574de55 | 2013-07-30 17:06:57 +0900 | [diff] [blame] | 1579 | if (dev_get_platdata(uap->port.dev)) { |
Anton Vorontsov | b3564c2 | 2012-09-24 14:27:54 -0700 | [diff] [blame] | 1580 | struct amba_pl011_data *plat; |
| 1581 | |
Jingoo Han | 574de55 | 2013-07-30 17:06:57 +0900 | [diff] [blame] | 1582 | plat = dev_get_platdata(uap->port.dev); |
Anton Vorontsov | b3564c2 | 2012-09-24 14:27:54 -0700 | [diff] [blame] | 1583 | if (plat->init) |
| 1584 | plat->init(); |
| 1585 | } |
| 1586 | return 0; |
Anton Vorontsov | b3564c2 | 2012-09-24 14:27:54 -0700 | [diff] [blame] | 1587 | } |
| 1588 | |
Russell King | 7fe9a5a | 2015-11-03 14:51:08 +0000 | [diff] [blame] | 1589 | static bool pl011_split_lcrh(const struct uart_amba_port *uap) |
| 1590 | { |
Russell King | 9f25bc5 | 2015-11-03 14:51:13 +0000 | [diff] [blame^] | 1591 | return pl011_reg_to_offset(uap, uap->lcrh_rx) != |
| 1592 | pl011_reg_to_offset(uap, uap->lcrh_tx); |
Russell King | 7fe9a5a | 2015-11-03 14:51:08 +0000 | [diff] [blame] | 1593 | } |
| 1594 | |
Jon Medhurst | b60f2f6 | 2013-12-10 10:18:59 +0000 | [diff] [blame] | 1595 | static void pl011_write_lcr_h(struct uart_amba_port *uap, unsigned int lcr_h) |
| 1596 | { |
Russell King | b2a4e24 | 2015-11-03 14:51:03 +0000 | [diff] [blame] | 1597 | pl011_write(lcr_h, uap, uap->lcrh_rx); |
Russell King | 7fe9a5a | 2015-11-03 14:51:08 +0000 | [diff] [blame] | 1598 | if (pl011_split_lcrh(uap)) { |
Jon Medhurst | b60f2f6 | 2013-12-10 10:18:59 +0000 | [diff] [blame] | 1599 | int i; |
| 1600 | /* |
| 1601 | * Wait 10 PCLKs before writing LCRH_TX register, |
| 1602 | * to get this delay write read only register 10 times |
| 1603 | */ |
| 1604 | for (i = 0; i < 10; ++i) |
Russell King | 9f25bc5 | 2015-11-03 14:51:13 +0000 | [diff] [blame^] | 1605 | pl011_write(0xff, uap, REG_MIS); |
Russell King | b2a4e24 | 2015-11-03 14:51:03 +0000 | [diff] [blame] | 1606 | pl011_write(lcr_h, uap, uap->lcrh_tx); |
Jon Medhurst | b60f2f6 | 2013-12-10 10:18:59 +0000 | [diff] [blame] | 1607 | } |
| 1608 | } |
| 1609 | |
Andre Przywara | 867b8e8 | 2015-05-21 17:26:15 +0100 | [diff] [blame] | 1610 | static int pl011_allocate_irq(struct uart_amba_port *uap) |
| 1611 | { |
Russell King | 9f25bc5 | 2015-11-03 14:51:13 +0000 | [diff] [blame^] | 1612 | pl011_write(uap->im, uap, REG_IMSC); |
Andre Przywara | 867b8e8 | 2015-05-21 17:26:15 +0100 | [diff] [blame] | 1613 | |
| 1614 | return request_irq(uap->port.irq, pl011_int, 0, "uart-pl011", uap); |
| 1615 | } |
| 1616 | |
| 1617 | /* |
| 1618 | * Enable interrupts, only timeouts when using DMA |
| 1619 | * if initial RX DMA job failed, start in interrupt mode |
| 1620 | * as well. |
| 1621 | */ |
| 1622 | static void pl011_enable_interrupts(struct uart_amba_port *uap) |
| 1623 | { |
| 1624 | spin_lock_irq(&uap->port.lock); |
| 1625 | |
| 1626 | /* Clear out any spuriously appearing RX interrupts */ |
Russell King | 9f25bc5 | 2015-11-03 14:51:13 +0000 | [diff] [blame^] | 1627 | pl011_write(UART011_RTIS | UART011_RXIS, uap, REG_ICR); |
Andre Przywara | 867b8e8 | 2015-05-21 17:26:15 +0100 | [diff] [blame] | 1628 | uap->im = UART011_RTIM; |
| 1629 | if (!pl011_dma_rx_running(uap)) |
| 1630 | uap->im |= UART011_RXIM; |
Russell King | 9f25bc5 | 2015-11-03 14:51:13 +0000 | [diff] [blame^] | 1631 | pl011_write(uap->im, uap, REG_IMSC); |
Andre Przywara | 867b8e8 | 2015-05-21 17:26:15 +0100 | [diff] [blame] | 1632 | spin_unlock_irq(&uap->port.lock); |
| 1633 | } |
| 1634 | |
Anton Vorontsov | b3564c2 | 2012-09-24 14:27:54 -0700 | [diff] [blame] | 1635 | static int pl011_startup(struct uart_port *port) |
| 1636 | { |
Daniel Thompson | a5820c2 | 2014-09-03 12:51:55 +0100 | [diff] [blame] | 1637 | struct uart_amba_port *uap = |
| 1638 | container_of(port, struct uart_amba_port, port); |
Dave Martin | 734745c | 2015-03-04 12:27:33 +0000 | [diff] [blame] | 1639 | unsigned int cr; |
Anton Vorontsov | b3564c2 | 2012-09-24 14:27:54 -0700 | [diff] [blame] | 1640 | int retval; |
| 1641 | |
| 1642 | retval = pl011_hwinit(port); |
| 1643 | if (retval) |
| 1644 | goto clk_dis; |
| 1645 | |
Andre Przywara | 867b8e8 | 2015-05-21 17:26:15 +0100 | [diff] [blame] | 1646 | retval = pl011_allocate_irq(uap); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1647 | if (retval) |
| 1648 | goto clk_dis; |
| 1649 | |
Russell King | 9f25bc5 | 2015-11-03 14:51:13 +0000 | [diff] [blame^] | 1650 | pl011_write(uap->vendor->ifls, uap, REG_IFLS); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1651 | |
Jon Medhurst | fe43390 | 2013-12-10 10:18:58 +0000 | [diff] [blame] | 1652 | spin_lock_irq(&uap->port.lock); |
| 1653 | |
Shreshtha Kumar Sahu | d8d8ffa | 2012-01-18 15:53:59 +0530 | [diff] [blame] | 1654 | /* restore RTS and DTR */ |
| 1655 | cr = uap->old_cr & (UART011_CR_RTS | UART011_CR_DTR); |
| 1656 | cr |= UART01x_CR_UARTEN | UART011_CR_RXE | UART011_CR_TXE; |
Russell King | 9f25bc5 | 2015-11-03 14:51:13 +0000 | [diff] [blame^] | 1657 | pl011_write(cr, uap, REG_CR); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1658 | |
Jon Medhurst | fe43390 | 2013-12-10 10:18:58 +0000 | [diff] [blame] | 1659 | spin_unlock_irq(&uap->port.lock); |
| 1660 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1661 | /* |
| 1662 | * initialise the old status of the modem signals |
| 1663 | */ |
Russell King | 9f25bc5 | 2015-11-03 14:51:13 +0000 | [diff] [blame^] | 1664 | uap->old_status = pl011_read(uap, REG_FR) & UART01x_FR_MODEM_ANY; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1665 | |
Russell King | 68b65f7 | 2010-12-22 17:24:39 +0000 | [diff] [blame] | 1666 | /* Startup DMA */ |
| 1667 | pl011_dma_startup(uap); |
| 1668 | |
Andre Przywara | 867b8e8 | 2015-05-21 17:26:15 +0100 | [diff] [blame] | 1669 | pl011_enable_interrupts(uap); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1670 | |
| 1671 | return 0; |
| 1672 | |
| 1673 | clk_dis: |
Julia Lawall | 1c4c439 | 2012-08-26 18:01:01 +0200 | [diff] [blame] | 1674 | clk_disable_unprepare(uap->clk); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1675 | return retval; |
| 1676 | } |
| 1677 | |
Andre Przywara | 0dd1e24 | 2015-05-21 17:26:23 +0100 | [diff] [blame] | 1678 | static int sbsa_uart_startup(struct uart_port *port) |
| 1679 | { |
| 1680 | struct uart_amba_port *uap = |
| 1681 | container_of(port, struct uart_amba_port, port); |
| 1682 | int retval; |
| 1683 | |
| 1684 | retval = pl011_hwinit(port); |
| 1685 | if (retval) |
| 1686 | return retval; |
| 1687 | |
| 1688 | retval = pl011_allocate_irq(uap); |
| 1689 | if (retval) |
| 1690 | return retval; |
| 1691 | |
| 1692 | /* The SBSA UART does not support any modem status lines. */ |
| 1693 | uap->old_status = 0; |
| 1694 | |
| 1695 | pl011_enable_interrupts(uap); |
| 1696 | |
| 1697 | return 0; |
| 1698 | } |
| 1699 | |
Linus Walleij | ec489aa | 2010-06-02 08:13:52 +0100 | [diff] [blame] | 1700 | static void pl011_shutdown_channel(struct uart_amba_port *uap, |
| 1701 | unsigned int lcrh) |
| 1702 | { |
Greg Kroah-Hartman | f11c984 | 2015-09-04 09:13:39 -0700 | [diff] [blame] | 1703 | unsigned long val; |
Linus Walleij | ec489aa | 2010-06-02 08:13:52 +0100 | [diff] [blame] | 1704 | |
Russell King | b2a4e24 | 2015-11-03 14:51:03 +0000 | [diff] [blame] | 1705 | val = pl011_read(uap, lcrh); |
Greg Kroah-Hartman | f11c984 | 2015-09-04 09:13:39 -0700 | [diff] [blame] | 1706 | val &= ~(UART01x_LCRH_BRK | UART01x_LCRH_FEN); |
Russell King | b2a4e24 | 2015-11-03 14:51:03 +0000 | [diff] [blame] | 1707 | pl011_write(val, uap, lcrh); |
Linus Walleij | ec489aa | 2010-06-02 08:13:52 +0100 | [diff] [blame] | 1708 | } |
| 1709 | |
Andre Przywara | 95166a3 | 2015-05-21 17:26:16 +0100 | [diff] [blame] | 1710 | /* |
| 1711 | * disable the port. It should not disable RTS and DTR. |
| 1712 | * Also RTS and DTR state should be preserved to restore |
| 1713 | * it during startup(). |
| 1714 | */ |
| 1715 | static void pl011_disable_uart(struct uart_amba_port *uap) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1716 | { |
Shreshtha Kumar Sahu | d8d8ffa | 2012-01-18 15:53:59 +0530 | [diff] [blame] | 1717 | unsigned int cr; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1718 | |
Rabin Vincent | 3b43816 | 2010-02-12 06:43:11 +0100 | [diff] [blame] | 1719 | uap->autorts = false; |
Jon Medhurst | fe43390 | 2013-12-10 10:18:58 +0000 | [diff] [blame] | 1720 | spin_lock_irq(&uap->port.lock); |
Russell King | 9f25bc5 | 2015-11-03 14:51:13 +0000 | [diff] [blame^] | 1721 | cr = pl011_read(uap, REG_CR); |
Shreshtha Kumar Sahu | d8d8ffa | 2012-01-18 15:53:59 +0530 | [diff] [blame] | 1722 | uap->old_cr = cr; |
| 1723 | cr &= UART011_CR_RTS | UART011_CR_DTR; |
| 1724 | cr |= UART01x_CR_UARTEN | UART011_CR_TXE; |
Russell King | 9f25bc5 | 2015-11-03 14:51:13 +0000 | [diff] [blame^] | 1725 | pl011_write(cr, uap, REG_CR); |
Jon Medhurst | fe43390 | 2013-12-10 10:18:58 +0000 | [diff] [blame] | 1726 | spin_unlock_irq(&uap->port.lock); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1727 | |
| 1728 | /* |
| 1729 | * disable break condition and fifos |
| 1730 | */ |
Linus Walleij | ec489aa | 2010-06-02 08:13:52 +0100 | [diff] [blame] | 1731 | pl011_shutdown_channel(uap, uap->lcrh_rx); |
Russell King | 7fe9a5a | 2015-11-03 14:51:08 +0000 | [diff] [blame] | 1732 | if (pl011_split_lcrh(uap)) |
Linus Walleij | ec489aa | 2010-06-02 08:13:52 +0100 | [diff] [blame] | 1733 | pl011_shutdown_channel(uap, uap->lcrh_tx); |
Andre Przywara | 95166a3 | 2015-05-21 17:26:16 +0100 | [diff] [blame] | 1734 | } |
| 1735 | |
| 1736 | static void pl011_disable_interrupts(struct uart_amba_port *uap) |
| 1737 | { |
| 1738 | spin_lock_irq(&uap->port.lock); |
| 1739 | |
| 1740 | /* mask all interrupts and clear all pending ones */ |
| 1741 | uap->im = 0; |
Russell King | 9f25bc5 | 2015-11-03 14:51:13 +0000 | [diff] [blame^] | 1742 | pl011_write(uap->im, uap, REG_IMSC); |
| 1743 | pl011_write(0xffff, uap, REG_ICR); |
Andre Przywara | 95166a3 | 2015-05-21 17:26:16 +0100 | [diff] [blame] | 1744 | |
| 1745 | spin_unlock_irq(&uap->port.lock); |
| 1746 | } |
| 1747 | |
| 1748 | static void pl011_shutdown(struct uart_port *port) |
| 1749 | { |
| 1750 | struct uart_amba_port *uap = |
| 1751 | container_of(port, struct uart_amba_port, port); |
| 1752 | |
| 1753 | pl011_disable_interrupts(uap); |
| 1754 | |
| 1755 | pl011_dma_shutdown(uap); |
| 1756 | |
| 1757 | free_irq(uap->port.irq, uap); |
| 1758 | |
| 1759 | pl011_disable_uart(uap); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1760 | |
| 1761 | /* |
| 1762 | * Shut down the clock producer |
| 1763 | */ |
Julia Lawall | 1c4c439 | 2012-08-26 18:01:01 +0200 | [diff] [blame] | 1764 | clk_disable_unprepare(uap->clk); |
Linus Walleij | 78d80c5 | 2012-05-23 21:18:46 +0200 | [diff] [blame] | 1765 | /* Optionally let pins go into sleep states */ |
Linus Walleij | 2b996fc | 2013-06-05 15:36:42 +0200 | [diff] [blame] | 1766 | pinctrl_pm_select_sleep_state(port->dev); |
Shreshtha Kumar Sahu | c16d51a | 2011-06-13 10:11:33 +0200 | [diff] [blame] | 1767 | |
Jingoo Han | 574de55 | 2013-07-30 17:06:57 +0900 | [diff] [blame] | 1768 | if (dev_get_platdata(uap->port.dev)) { |
Shreshtha Kumar Sahu | c16d51a | 2011-06-13 10:11:33 +0200 | [diff] [blame] | 1769 | struct amba_pl011_data *plat; |
| 1770 | |
Jingoo Han | 574de55 | 2013-07-30 17:06:57 +0900 | [diff] [blame] | 1771 | plat = dev_get_platdata(uap->port.dev); |
Shreshtha Kumar Sahu | c16d51a | 2011-06-13 10:11:33 +0200 | [diff] [blame] | 1772 | if (plat->exit) |
| 1773 | plat->exit(); |
| 1774 | } |
| 1775 | |
Peter Hurley | 36f339d | 2014-11-06 09:06:12 -0500 | [diff] [blame] | 1776 | if (uap->port.ops->flush_buffer) |
| 1777 | uap->port.ops->flush_buffer(port); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1778 | } |
| 1779 | |
Andre Przywara | 0dd1e24 | 2015-05-21 17:26:23 +0100 | [diff] [blame] | 1780 | static void sbsa_uart_shutdown(struct uart_port *port) |
| 1781 | { |
| 1782 | struct uart_amba_port *uap = |
| 1783 | container_of(port, struct uart_amba_port, port); |
| 1784 | |
| 1785 | pl011_disable_interrupts(uap); |
| 1786 | |
| 1787 | free_irq(uap->port.irq, uap); |
| 1788 | |
| 1789 | if (uap->port.ops->flush_buffer) |
| 1790 | uap->port.ops->flush_buffer(port); |
| 1791 | } |
| 1792 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1793 | static void |
Andre Przywara | ef5a935 | 2015-05-21 17:26:17 +0100 | [diff] [blame] | 1794 | pl011_setup_status_masks(struct uart_port *port, struct ktermios *termios) |
| 1795 | { |
| 1796 | port->read_status_mask = UART011_DR_OE | 255; |
| 1797 | if (termios->c_iflag & INPCK) |
| 1798 | port->read_status_mask |= UART011_DR_FE | UART011_DR_PE; |
| 1799 | if (termios->c_iflag & (IGNBRK | BRKINT | PARMRK)) |
| 1800 | port->read_status_mask |= UART011_DR_BE; |
| 1801 | |
| 1802 | /* |
| 1803 | * Characters to ignore |
| 1804 | */ |
| 1805 | port->ignore_status_mask = 0; |
| 1806 | if (termios->c_iflag & IGNPAR) |
| 1807 | port->ignore_status_mask |= UART011_DR_FE | UART011_DR_PE; |
| 1808 | if (termios->c_iflag & IGNBRK) { |
| 1809 | port->ignore_status_mask |= UART011_DR_BE; |
| 1810 | /* |
| 1811 | * If we're ignoring parity and break indicators, |
| 1812 | * ignore overruns too (for real raw support). |
| 1813 | */ |
| 1814 | if (termios->c_iflag & IGNPAR) |
| 1815 | port->ignore_status_mask |= UART011_DR_OE; |
| 1816 | } |
| 1817 | |
| 1818 | /* |
| 1819 | * Ignore all characters if CREAD is not set. |
| 1820 | */ |
| 1821 | if ((termios->c_cflag & CREAD) == 0) |
| 1822 | port->ignore_status_mask |= UART_DUMMY_DR_RX; |
| 1823 | } |
| 1824 | |
| 1825 | static void |
Alan Cox | 606d099 | 2006-12-08 02:38:45 -0800 | [diff] [blame] | 1826 | pl011_set_termios(struct uart_port *port, struct ktermios *termios, |
| 1827 | struct ktermios *old) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1828 | { |
Daniel Thompson | a5820c2 | 2014-09-03 12:51:55 +0100 | [diff] [blame] | 1829 | struct uart_amba_port *uap = |
| 1830 | container_of(port, struct uart_amba_port, port); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1831 | unsigned int lcr_h, old_cr; |
| 1832 | unsigned long flags; |
Russell King | c19f12b | 2010-12-22 17:48:26 +0000 | [diff] [blame] | 1833 | unsigned int baud, quot, clkdiv; |
| 1834 | |
| 1835 | if (uap->vendor->oversampling) |
| 1836 | clkdiv = 8; |
| 1837 | else |
| 1838 | clkdiv = 16; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1839 | |
| 1840 | /* |
| 1841 | * Ask the core to calculate the divisor for us. |
| 1842 | */ |
Linus Walleij | ac3e3fb | 2010-06-02 20:40:22 +0100 | [diff] [blame] | 1843 | baud = uart_get_baud_rate(port, termios, old, 0, |
Russell King | c19f12b | 2010-12-22 17:48:26 +0000 | [diff] [blame] | 1844 | port->uartclk / clkdiv); |
Chanho Min | 89fa28d | 2013-04-03 11:10:37 +0900 | [diff] [blame] | 1845 | #ifdef CONFIG_DMA_ENGINE |
Chanho Min | cb06ff1 | 2013-03-27 18:38:11 +0900 | [diff] [blame] | 1846 | /* |
| 1847 | * Adjust RX DMA polling rate with baud rate if not specified. |
| 1848 | */ |
| 1849 | if (uap->dmarx.auto_poll_rate) |
| 1850 | uap->dmarx.poll_rate = DIV_ROUND_UP(10000000, baud); |
Chanho Min | 89fa28d | 2013-04-03 11:10:37 +0900 | [diff] [blame] | 1851 | #endif |
Linus Walleij | ac3e3fb | 2010-06-02 20:40:22 +0100 | [diff] [blame] | 1852 | |
| 1853 | if (baud > port->uartclk/16) |
| 1854 | quot = DIV_ROUND_CLOSEST(port->uartclk * 8, baud); |
| 1855 | else |
| 1856 | quot = DIV_ROUND_CLOSEST(port->uartclk * 4, baud); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1857 | |
| 1858 | switch (termios->c_cflag & CSIZE) { |
| 1859 | case CS5: |
| 1860 | lcr_h = UART01x_LCRH_WLEN_5; |
| 1861 | break; |
| 1862 | case CS6: |
| 1863 | lcr_h = UART01x_LCRH_WLEN_6; |
| 1864 | break; |
| 1865 | case CS7: |
| 1866 | lcr_h = UART01x_LCRH_WLEN_7; |
| 1867 | break; |
| 1868 | default: // CS8 |
| 1869 | lcr_h = UART01x_LCRH_WLEN_8; |
| 1870 | break; |
| 1871 | } |
| 1872 | if (termios->c_cflag & CSTOPB) |
| 1873 | lcr_h |= UART01x_LCRH_STP2; |
| 1874 | if (termios->c_cflag & PARENB) { |
| 1875 | lcr_h |= UART01x_LCRH_PEN; |
| 1876 | if (!(termios->c_cflag & PARODD)) |
| 1877 | lcr_h |= UART01x_LCRH_EPS; |
| 1878 | } |
Russell King | ffca2b1 | 2010-12-22 17:13:05 +0000 | [diff] [blame] | 1879 | if (uap->fifosize > 1) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1880 | lcr_h |= UART01x_LCRH_FEN; |
| 1881 | |
| 1882 | spin_lock_irqsave(&port->lock, flags); |
| 1883 | |
| 1884 | /* |
| 1885 | * Update the per-port timeout. |
| 1886 | */ |
| 1887 | uart_update_timeout(port, termios->c_cflag, baud); |
| 1888 | |
Andre Przywara | ef5a935 | 2015-05-21 17:26:17 +0100 | [diff] [blame] | 1889 | pl011_setup_status_masks(port, termios); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1890 | |
| 1891 | if (UART_ENABLE_MS(port, termios->c_cflag)) |
| 1892 | pl011_enable_ms(port); |
| 1893 | |
| 1894 | /* first, disable everything */ |
Russell King | 9f25bc5 | 2015-11-03 14:51:13 +0000 | [diff] [blame^] | 1895 | old_cr = pl011_read(uap, REG_CR); |
| 1896 | pl011_write(0, uap, REG_CR); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1897 | |
Rabin Vincent | 3b43816 | 2010-02-12 06:43:11 +0100 | [diff] [blame] | 1898 | if (termios->c_cflag & CRTSCTS) { |
| 1899 | if (old_cr & UART011_CR_RTS) |
| 1900 | old_cr |= UART011_CR_RTSEN; |
| 1901 | |
| 1902 | old_cr |= UART011_CR_CTSEN; |
| 1903 | uap->autorts = true; |
| 1904 | } else { |
| 1905 | old_cr &= ~(UART011_CR_CTSEN | UART011_CR_RTSEN); |
| 1906 | uap->autorts = false; |
| 1907 | } |
| 1908 | |
Russell King | c19f12b | 2010-12-22 17:48:26 +0000 | [diff] [blame] | 1909 | if (uap->vendor->oversampling) { |
| 1910 | if (baud > port->uartclk / 16) |
Linus Walleij | ac3e3fb | 2010-06-02 20:40:22 +0100 | [diff] [blame] | 1911 | old_cr |= ST_UART011_CR_OVSFACT; |
| 1912 | else |
| 1913 | old_cr &= ~ST_UART011_CR_OVSFACT; |
| 1914 | } |
| 1915 | |
Linus Walleij | c5dd553 | 2012-09-26 17:21:36 +0200 | [diff] [blame] | 1916 | /* |
| 1917 | * Workaround for the ST Micro oversampling variants to |
| 1918 | * increase the bitrate slightly, by lowering the divisor, |
| 1919 | * to avoid delayed sampling of start bit at high speeds, |
| 1920 | * else we see data corruption. |
| 1921 | */ |
| 1922 | if (uap->vendor->oversampling) { |
| 1923 | if ((baud >= 3000000) && (baud < 3250000) && (quot > 1)) |
| 1924 | quot -= 1; |
| 1925 | else if ((baud > 3250000) && (quot > 2)) |
| 1926 | quot -= 2; |
| 1927 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1928 | /* Set baud rate */ |
Russell King | 9f25bc5 | 2015-11-03 14:51:13 +0000 | [diff] [blame^] | 1929 | pl011_write(quot & 0x3f, uap, REG_FBRD); |
| 1930 | pl011_write(quot >> 6, uap, REG_IBRD); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1931 | |
| 1932 | /* |
| 1933 | * ----------v----------v----------v----------v----- |
Linus Walleij | c5dd553 | 2012-09-26 17:21:36 +0200 | [diff] [blame] | 1934 | * NOTE: lcrh_tx and lcrh_rx MUST BE WRITTEN AFTER |
Russell King | 9f25bc5 | 2015-11-03 14:51:13 +0000 | [diff] [blame^] | 1935 | * REG_FBRD & REG_IBRD. |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1936 | * ----------^----------^----------^----------^----- |
| 1937 | */ |
Jon Medhurst | b60f2f6 | 2013-12-10 10:18:59 +0000 | [diff] [blame] | 1938 | pl011_write_lcr_h(uap, lcr_h); |
Russell King | 9f25bc5 | 2015-11-03 14:51:13 +0000 | [diff] [blame^] | 1939 | pl011_write(old_cr, uap, REG_CR); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1940 | |
| 1941 | spin_unlock_irqrestore(&port->lock, flags); |
| 1942 | } |
| 1943 | |
Andre Przywara | 0dd1e24 | 2015-05-21 17:26:23 +0100 | [diff] [blame] | 1944 | static void |
| 1945 | sbsa_uart_set_termios(struct uart_port *port, struct ktermios *termios, |
| 1946 | struct ktermios *old) |
| 1947 | { |
| 1948 | struct uart_amba_port *uap = |
| 1949 | container_of(port, struct uart_amba_port, port); |
| 1950 | unsigned long flags; |
| 1951 | |
| 1952 | tty_termios_encode_baud_rate(termios, uap->fixed_baud, uap->fixed_baud); |
| 1953 | |
| 1954 | /* The SBSA UART only supports 8n1 without hardware flow control. */ |
| 1955 | termios->c_cflag &= ~(CSIZE | CSTOPB | PARENB | PARODD); |
| 1956 | termios->c_cflag &= ~(CMSPAR | CRTSCTS); |
| 1957 | termios->c_cflag |= CS8 | CLOCAL; |
| 1958 | |
| 1959 | spin_lock_irqsave(&port->lock, flags); |
| 1960 | uart_update_timeout(port, CS8, uap->fixed_baud); |
| 1961 | pl011_setup_status_masks(port, termios); |
| 1962 | spin_unlock_irqrestore(&port->lock, flags); |
| 1963 | } |
| 1964 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1965 | static const char *pl011_type(struct uart_port *port) |
| 1966 | { |
Daniel Thompson | a5820c2 | 2014-09-03 12:51:55 +0100 | [diff] [blame] | 1967 | struct uart_amba_port *uap = |
| 1968 | container_of(port, struct uart_amba_port, port); |
Russell King | e8a7ba8 | 2010-12-28 09:16:54 +0000 | [diff] [blame] | 1969 | return uap->port.type == PORT_AMBA ? uap->type : NULL; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1970 | } |
| 1971 | |
| 1972 | /* |
| 1973 | * Release the memory region(s) being used by 'port' |
| 1974 | */ |
Linus Walleij | e643f87 | 2012-06-17 15:44:19 +0200 | [diff] [blame] | 1975 | static void pl011_release_port(struct uart_port *port) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1976 | { |
| 1977 | release_mem_region(port->mapbase, SZ_4K); |
| 1978 | } |
| 1979 | |
| 1980 | /* |
| 1981 | * Request the memory region(s) being used by 'port' |
| 1982 | */ |
Linus Walleij | e643f87 | 2012-06-17 15:44:19 +0200 | [diff] [blame] | 1983 | static int pl011_request_port(struct uart_port *port) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1984 | { |
| 1985 | return request_mem_region(port->mapbase, SZ_4K, "uart-pl011") |
| 1986 | != NULL ? 0 : -EBUSY; |
| 1987 | } |
| 1988 | |
| 1989 | /* |
| 1990 | * Configure/autoconfigure the port. |
| 1991 | */ |
Linus Walleij | e643f87 | 2012-06-17 15:44:19 +0200 | [diff] [blame] | 1992 | static void pl011_config_port(struct uart_port *port, int flags) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1993 | { |
| 1994 | if (flags & UART_CONFIG_TYPE) { |
| 1995 | port->type = PORT_AMBA; |
Linus Walleij | e643f87 | 2012-06-17 15:44:19 +0200 | [diff] [blame] | 1996 | pl011_request_port(port); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1997 | } |
| 1998 | } |
| 1999 | |
| 2000 | /* |
| 2001 | * verify the new serial_struct (for TIOCSSERIAL). |
| 2002 | */ |
Linus Walleij | e643f87 | 2012-06-17 15:44:19 +0200 | [diff] [blame] | 2003 | static int pl011_verify_port(struct uart_port *port, struct serial_struct *ser) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2004 | { |
| 2005 | int ret = 0; |
| 2006 | if (ser->type != PORT_UNKNOWN && ser->type != PORT_AMBA) |
| 2007 | ret = -EINVAL; |
Yinghai Lu | a62c413 | 2008-08-19 20:49:55 -0700 | [diff] [blame] | 2008 | if (ser->irq < 0 || ser->irq >= nr_irqs) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2009 | ret = -EINVAL; |
| 2010 | if (ser->baud_base < 9600) |
| 2011 | ret = -EINVAL; |
| 2012 | return ret; |
| 2013 | } |
| 2014 | |
| 2015 | static struct uart_ops amba_pl011_pops = { |
Linus Walleij | e643f87 | 2012-06-17 15:44:19 +0200 | [diff] [blame] | 2016 | .tx_empty = pl011_tx_empty, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2017 | .set_mctrl = pl011_set_mctrl, |
Linus Walleij | e643f87 | 2012-06-17 15:44:19 +0200 | [diff] [blame] | 2018 | .get_mctrl = pl011_get_mctrl, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2019 | .stop_tx = pl011_stop_tx, |
| 2020 | .start_tx = pl011_start_tx, |
| 2021 | .stop_rx = pl011_stop_rx, |
| 2022 | .enable_ms = pl011_enable_ms, |
| 2023 | .break_ctl = pl011_break_ctl, |
| 2024 | .startup = pl011_startup, |
| 2025 | .shutdown = pl011_shutdown, |
Russell King | 68b65f7 | 2010-12-22 17:24:39 +0000 | [diff] [blame] | 2026 | .flush_buffer = pl011_dma_flush_buffer, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2027 | .set_termios = pl011_set_termios, |
| 2028 | .type = pl011_type, |
Linus Walleij | e643f87 | 2012-06-17 15:44:19 +0200 | [diff] [blame] | 2029 | .release_port = pl011_release_port, |
| 2030 | .request_port = pl011_request_port, |
| 2031 | .config_port = pl011_config_port, |
| 2032 | .verify_port = pl011_verify_port, |
Jason Wessel | 84b5ae1 | 2008-02-20 13:33:39 -0600 | [diff] [blame] | 2033 | #ifdef CONFIG_CONSOLE_POLL |
Anton Vorontsov | b3564c2 | 2012-09-24 14:27:54 -0700 | [diff] [blame] | 2034 | .poll_init = pl011_hwinit, |
Linus Walleij | e643f87 | 2012-06-17 15:44:19 +0200 | [diff] [blame] | 2035 | .poll_get_char = pl011_get_poll_char, |
| 2036 | .poll_put_char = pl011_put_poll_char, |
Jason Wessel | 84b5ae1 | 2008-02-20 13:33:39 -0600 | [diff] [blame] | 2037 | #endif |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2038 | }; |
| 2039 | |
Andre Przywara | 0dd1e24 | 2015-05-21 17:26:23 +0100 | [diff] [blame] | 2040 | static void sbsa_uart_set_mctrl(struct uart_port *port, unsigned int mctrl) |
| 2041 | { |
| 2042 | } |
| 2043 | |
| 2044 | static unsigned int sbsa_uart_get_mctrl(struct uart_port *port) |
| 2045 | { |
| 2046 | return 0; |
| 2047 | } |
| 2048 | |
| 2049 | static const struct uart_ops sbsa_uart_pops = { |
| 2050 | .tx_empty = pl011_tx_empty, |
| 2051 | .set_mctrl = sbsa_uart_set_mctrl, |
| 2052 | .get_mctrl = sbsa_uart_get_mctrl, |
| 2053 | .stop_tx = pl011_stop_tx, |
| 2054 | .start_tx = pl011_start_tx, |
| 2055 | .stop_rx = pl011_stop_rx, |
| 2056 | .startup = sbsa_uart_startup, |
| 2057 | .shutdown = sbsa_uart_shutdown, |
| 2058 | .set_termios = sbsa_uart_set_termios, |
| 2059 | .type = pl011_type, |
| 2060 | .release_port = pl011_release_port, |
| 2061 | .request_port = pl011_request_port, |
| 2062 | .config_port = pl011_config_port, |
| 2063 | .verify_port = pl011_verify_port, |
| 2064 | #ifdef CONFIG_CONSOLE_POLL |
| 2065 | .poll_init = pl011_hwinit, |
| 2066 | .poll_get_char = pl011_get_poll_char, |
| 2067 | .poll_put_char = pl011_put_poll_char, |
| 2068 | #endif |
| 2069 | }; |
| 2070 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2071 | static struct uart_amba_port *amba_ports[UART_NR]; |
| 2072 | |
| 2073 | #ifdef CONFIG_SERIAL_AMBA_PL011_CONSOLE |
| 2074 | |
Russell King | d358788 | 2006-03-20 20:00:09 +0000 | [diff] [blame] | 2075 | static void pl011_console_putchar(struct uart_port *port, int ch) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2076 | { |
Daniel Thompson | a5820c2 | 2014-09-03 12:51:55 +0100 | [diff] [blame] | 2077 | struct uart_amba_port *uap = |
| 2078 | container_of(port, struct uart_amba_port, port); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2079 | |
Russell King | 9f25bc5 | 2015-11-03 14:51:13 +0000 | [diff] [blame^] | 2080 | while (pl011_read(uap, REG_FR) & UART01x_FR_TXFF) |
Russell King | d358788 | 2006-03-20 20:00:09 +0000 | [diff] [blame] | 2081 | barrier(); |
Russell King | 9f25bc5 | 2015-11-03 14:51:13 +0000 | [diff] [blame^] | 2082 | pl011_write(ch, uap, REG_DR); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2083 | } |
| 2084 | |
| 2085 | static void |
| 2086 | pl011_console_write(struct console *co, const char *s, unsigned int count) |
| 2087 | { |
| 2088 | struct uart_amba_port *uap = amba_ports[co->index]; |
Andre Przywara | 71eec48 | 2015-05-21 17:26:21 +0100 | [diff] [blame] | 2089 | unsigned int status, old_cr = 0, new_cr; |
Rabin Vincent | ef605fd | 2012-01-17 11:52:28 +0100 | [diff] [blame] | 2090 | unsigned long flags; |
| 2091 | int locked = 1; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2092 | |
| 2093 | clk_enable(uap->clk); |
| 2094 | |
Rabin Vincent | ef605fd | 2012-01-17 11:52:28 +0100 | [diff] [blame] | 2095 | local_irq_save(flags); |
| 2096 | if (uap->port.sysrq) |
| 2097 | locked = 0; |
| 2098 | else if (oops_in_progress) |
| 2099 | locked = spin_trylock(&uap->port.lock); |
| 2100 | else |
| 2101 | spin_lock(&uap->port.lock); |
| 2102 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2103 | /* |
| 2104 | * First save the CR then disable the interrupts |
| 2105 | */ |
Andre Przywara | 71eec48 | 2015-05-21 17:26:21 +0100 | [diff] [blame] | 2106 | if (!uap->vendor->always_enabled) { |
Russell King | 9f25bc5 | 2015-11-03 14:51:13 +0000 | [diff] [blame^] | 2107 | old_cr = pl011_read(uap, REG_CR); |
Andre Przywara | 71eec48 | 2015-05-21 17:26:21 +0100 | [diff] [blame] | 2108 | new_cr = old_cr & ~UART011_CR_CTSEN; |
| 2109 | new_cr |= UART01x_CR_UARTEN | UART011_CR_TXE; |
Russell King | 9f25bc5 | 2015-11-03 14:51:13 +0000 | [diff] [blame^] | 2110 | pl011_write(new_cr, uap, REG_CR); |
Andre Przywara | 71eec48 | 2015-05-21 17:26:21 +0100 | [diff] [blame] | 2111 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2112 | |
Russell King | d358788 | 2006-03-20 20:00:09 +0000 | [diff] [blame] | 2113 | uart_console_write(&uap->port, s, count, pl011_console_putchar); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2114 | |
| 2115 | /* |
| 2116 | * Finally, wait for transmitter to become empty |
| 2117 | * and restore the TCR |
| 2118 | */ |
| 2119 | do { |
Russell King | 9f25bc5 | 2015-11-03 14:51:13 +0000 | [diff] [blame^] | 2120 | status = pl011_read(uap, REG_FR); |
Greg Kroah-Hartman | 062a68a | 2015-09-04 09:11:24 -0700 | [diff] [blame] | 2121 | } while (status & UART01x_FR_BUSY); |
Andre Przywara | 71eec48 | 2015-05-21 17:26:21 +0100 | [diff] [blame] | 2122 | if (!uap->vendor->always_enabled) |
Russell King | 9f25bc5 | 2015-11-03 14:51:13 +0000 | [diff] [blame^] | 2123 | pl011_write(old_cr, uap, REG_CR); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2124 | |
Rabin Vincent | ef605fd | 2012-01-17 11:52:28 +0100 | [diff] [blame] | 2125 | if (locked) |
| 2126 | spin_unlock(&uap->port.lock); |
| 2127 | local_irq_restore(flags); |
| 2128 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2129 | clk_disable(uap->clk); |
| 2130 | } |
| 2131 | |
| 2132 | static void __init |
| 2133 | pl011_console_get_options(struct uart_amba_port *uap, int *baud, |
| 2134 | int *parity, int *bits) |
| 2135 | { |
Russell King | 9f25bc5 | 2015-11-03 14:51:13 +0000 | [diff] [blame^] | 2136 | if (pl011_read(uap, REG_CR) & UART01x_CR_UARTEN) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2137 | unsigned int lcr_h, ibrd, fbrd; |
| 2138 | |
Russell King | b2a4e24 | 2015-11-03 14:51:03 +0000 | [diff] [blame] | 2139 | lcr_h = pl011_read(uap, uap->lcrh_tx); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2140 | |
| 2141 | *parity = 'n'; |
| 2142 | if (lcr_h & UART01x_LCRH_PEN) { |
| 2143 | if (lcr_h & UART01x_LCRH_EPS) |
| 2144 | *parity = 'e'; |
| 2145 | else |
| 2146 | *parity = 'o'; |
| 2147 | } |
| 2148 | |
| 2149 | if ((lcr_h & 0x60) == UART01x_LCRH_WLEN_7) |
| 2150 | *bits = 7; |
| 2151 | else |
| 2152 | *bits = 8; |
| 2153 | |
Russell King | 9f25bc5 | 2015-11-03 14:51:13 +0000 | [diff] [blame^] | 2154 | ibrd = pl011_read(uap, REG_IBRD); |
| 2155 | fbrd = pl011_read(uap, REG_FBRD); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2156 | |
| 2157 | *baud = uap->port.uartclk * 4 / (64 * ibrd + fbrd); |
Linus Walleij | ac3e3fb | 2010-06-02 20:40:22 +0100 | [diff] [blame] | 2158 | |
Russell King | c19f12b | 2010-12-22 17:48:26 +0000 | [diff] [blame] | 2159 | if (uap->vendor->oversampling) { |
Russell King | 9f25bc5 | 2015-11-03 14:51:13 +0000 | [diff] [blame^] | 2160 | if (pl011_read(uap, REG_CR) |
Linus Walleij | ac3e3fb | 2010-06-02 20:40:22 +0100 | [diff] [blame] | 2161 | & ST_UART011_CR_OVSFACT) |
| 2162 | *baud *= 2; |
| 2163 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2164 | } |
| 2165 | } |
| 2166 | |
| 2167 | static int __init pl011_console_setup(struct console *co, char *options) |
| 2168 | { |
| 2169 | struct uart_amba_port *uap; |
| 2170 | int baud = 38400; |
| 2171 | int bits = 8; |
| 2172 | int parity = 'n'; |
| 2173 | int flow = 'n'; |
Russell King | 4b4851c | 2011-09-22 11:35:30 +0100 | [diff] [blame] | 2174 | int ret; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2175 | |
| 2176 | /* |
| 2177 | * Check whether an invalid uart number has been specified, and |
| 2178 | * if so, search for the first available port that does have |
| 2179 | * console support. |
| 2180 | */ |
| 2181 | if (co->index >= UART_NR) |
| 2182 | co->index = 0; |
| 2183 | uap = amba_ports[co->index]; |
Russell King | d28122a | 2007-01-22 18:59:42 +0000 | [diff] [blame] | 2184 | if (!uap) |
| 2185 | return -ENODEV; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2186 | |
Linus Walleij | 78d80c5 | 2012-05-23 21:18:46 +0200 | [diff] [blame] | 2187 | /* Allow pins to be muxed in and configured */ |
Linus Walleij | 2b996fc | 2013-06-05 15:36:42 +0200 | [diff] [blame] | 2188 | pinctrl_pm_select_default_state(uap->port.dev); |
Linus Walleij | 78d80c5 | 2012-05-23 21:18:46 +0200 | [diff] [blame] | 2189 | |
Russell King | 4b4851c | 2011-09-22 11:35:30 +0100 | [diff] [blame] | 2190 | ret = clk_prepare(uap->clk); |
| 2191 | if (ret) |
| 2192 | return ret; |
| 2193 | |
Jingoo Han | 574de55 | 2013-07-30 17:06:57 +0900 | [diff] [blame] | 2194 | if (dev_get_platdata(uap->port.dev)) { |
Shreshtha Kumar Sahu | c16d51a | 2011-06-13 10:11:33 +0200 | [diff] [blame] | 2195 | struct amba_pl011_data *plat; |
| 2196 | |
Jingoo Han | 574de55 | 2013-07-30 17:06:57 +0900 | [diff] [blame] | 2197 | plat = dev_get_platdata(uap->port.dev); |
Shreshtha Kumar Sahu | c16d51a | 2011-06-13 10:11:33 +0200 | [diff] [blame] | 2198 | if (plat->init) |
| 2199 | plat->init(); |
| 2200 | } |
| 2201 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2202 | uap->port.uartclk = clk_get_rate(uap->clk); |
| 2203 | |
Andre Przywara | cefc2d1 | 2015-05-21 17:26:22 +0100 | [diff] [blame] | 2204 | if (uap->vendor->fixed_options) { |
| 2205 | baud = uap->fixed_baud; |
| 2206 | } else { |
| 2207 | if (options) |
| 2208 | uart_parse_options(options, |
| 2209 | &baud, &parity, &bits, &flow); |
| 2210 | else |
| 2211 | pl011_console_get_options(uap, &baud, &parity, &bits); |
| 2212 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2213 | |
| 2214 | return uart_set_options(&uap->port, co, baud, parity, bits, flow); |
| 2215 | } |
| 2216 | |
Vincent Sanders | 2d93486 | 2005-09-14 22:36:03 +0100 | [diff] [blame] | 2217 | static struct uart_driver amba_reg; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2218 | static struct console amba_console = { |
| 2219 | .name = "ttyAMA", |
| 2220 | .write = pl011_console_write, |
| 2221 | .device = uart_console_device, |
| 2222 | .setup = pl011_console_setup, |
| 2223 | .flags = CON_PRINTBUFFER, |
| 2224 | .index = -1, |
| 2225 | .data = &amba_reg, |
| 2226 | }; |
| 2227 | |
| 2228 | #define AMBA_CONSOLE (&amba_console) |
Rob Herring | 0d3c673 | 2014-04-18 17:19:57 -0500 | [diff] [blame] | 2229 | |
| 2230 | static void pl011_putc(struct uart_port *port, int c) |
| 2231 | { |
Russell King | 9f25bc5 | 2015-11-03 14:51:13 +0000 | [diff] [blame^] | 2232 | while (readl(port->membase + REG_FR) & UART01x_FR_TXFF) |
Rob Herring | 0d3c673 | 2014-04-18 17:19:57 -0500 | [diff] [blame] | 2233 | ; |
Russell King | 9f25bc5 | 2015-11-03 14:51:13 +0000 | [diff] [blame^] | 2234 | writeb(c, port->membase + REG_DR); |
| 2235 | while (readl(port->membase + REG_FR) & UART01x_FR_BUSY) |
Rob Herring | 0d3c673 | 2014-04-18 17:19:57 -0500 | [diff] [blame] | 2236 | ; |
| 2237 | } |
| 2238 | |
| 2239 | static void pl011_early_write(struct console *con, const char *s, unsigned n) |
| 2240 | { |
| 2241 | struct earlycon_device *dev = con->data; |
| 2242 | |
| 2243 | uart_console_write(&dev->port, s, n, pl011_putc); |
| 2244 | } |
| 2245 | |
| 2246 | static int __init pl011_early_console_setup(struct earlycon_device *device, |
| 2247 | const char *opt) |
| 2248 | { |
| 2249 | if (!device->port.membase) |
| 2250 | return -ENODEV; |
| 2251 | |
| 2252 | device->con->write = pl011_early_write; |
| 2253 | return 0; |
| 2254 | } |
| 2255 | EARLYCON_DECLARE(pl011, pl011_early_console_setup); |
Rob Herring | 45e0f0f | 2014-03-27 08:08:03 -0500 | [diff] [blame] | 2256 | OF_EARLYCON_DECLARE(pl011, "arm,pl011", pl011_early_console_setup); |
Rob Herring | 0d3c673 | 2014-04-18 17:19:57 -0500 | [diff] [blame] | 2257 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2258 | #else |
| 2259 | #define AMBA_CONSOLE NULL |
| 2260 | #endif |
| 2261 | |
| 2262 | static struct uart_driver amba_reg = { |
| 2263 | .owner = THIS_MODULE, |
| 2264 | .driver_name = "ttyAMA", |
| 2265 | .dev_name = "ttyAMA", |
| 2266 | .major = SERIAL_AMBA_MAJOR, |
| 2267 | .minor = SERIAL_AMBA_MINOR, |
| 2268 | .nr = UART_NR, |
| 2269 | .cons = AMBA_CONSOLE, |
| 2270 | }; |
| 2271 | |
Matthew Leach | 32614aa | 2012-08-28 16:41:28 +0100 | [diff] [blame] | 2272 | static int pl011_probe_dt_alias(int index, struct device *dev) |
| 2273 | { |
| 2274 | struct device_node *np; |
| 2275 | static bool seen_dev_with_alias = false; |
| 2276 | static bool seen_dev_without_alias = false; |
| 2277 | int ret = index; |
| 2278 | |
| 2279 | if (!IS_ENABLED(CONFIG_OF)) |
| 2280 | return ret; |
| 2281 | |
| 2282 | np = dev->of_node; |
| 2283 | if (!np) |
| 2284 | return ret; |
| 2285 | |
| 2286 | ret = of_alias_get_id(np, "serial"); |
| 2287 | if (IS_ERR_VALUE(ret)) { |
| 2288 | seen_dev_without_alias = true; |
| 2289 | ret = index; |
| 2290 | } else { |
| 2291 | seen_dev_with_alias = true; |
| 2292 | if (ret >= ARRAY_SIZE(amba_ports) || amba_ports[ret] != NULL) { |
| 2293 | dev_warn(dev, "requested serial port %d not available.\n", ret); |
| 2294 | ret = index; |
| 2295 | } |
| 2296 | } |
| 2297 | |
| 2298 | if (seen_dev_with_alias && seen_dev_without_alias) |
| 2299 | dev_warn(dev, "aliased and non-aliased serial devices found in device tree. Serial port enumeration may be unpredictable.\n"); |
| 2300 | |
| 2301 | return ret; |
| 2302 | } |
| 2303 | |
Andre Przywara | 49bb3c8 | 2015-05-21 17:26:14 +0100 | [diff] [blame] | 2304 | /* unregisters the driver also if no more ports are left */ |
| 2305 | static void pl011_unregister_port(struct uart_amba_port *uap) |
| 2306 | { |
| 2307 | int i; |
| 2308 | bool busy = false; |
| 2309 | |
| 2310 | for (i = 0; i < ARRAY_SIZE(amba_ports); i++) { |
| 2311 | if (amba_ports[i] == uap) |
| 2312 | amba_ports[i] = NULL; |
| 2313 | else if (amba_ports[i]) |
| 2314 | busy = true; |
| 2315 | } |
| 2316 | pl011_dma_remove(uap); |
| 2317 | if (!busy) |
| 2318 | uart_unregister_driver(&amba_reg); |
| 2319 | } |
| 2320 | |
Andre Przywara | 3873e2d | 2015-05-21 17:26:18 +0100 | [diff] [blame] | 2321 | static int pl011_find_free_port(void) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2322 | { |
Andre Przywara | 3873e2d | 2015-05-21 17:26:18 +0100 | [diff] [blame] | 2323 | int i; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2324 | |
| 2325 | for (i = 0; i < ARRAY_SIZE(amba_ports); i++) |
| 2326 | if (amba_ports[i] == NULL) |
Andre Przywara | 3873e2d | 2015-05-21 17:26:18 +0100 | [diff] [blame] | 2327 | return i; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2328 | |
Andre Przywara | 3873e2d | 2015-05-21 17:26:18 +0100 | [diff] [blame] | 2329 | return -EBUSY; |
| 2330 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2331 | |
Andre Przywara | 3873e2d | 2015-05-21 17:26:18 +0100 | [diff] [blame] | 2332 | static int pl011_setup_port(struct device *dev, struct uart_amba_port *uap, |
| 2333 | struct resource *mmiobase, int index) |
| 2334 | { |
| 2335 | void __iomem *base; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2336 | |
Andre Przywara | 3873e2d | 2015-05-21 17:26:18 +0100 | [diff] [blame] | 2337 | base = devm_ioremap_resource(dev, mmiobase); |
Krzysztof Kozlowski | 97a60ea | 2015-07-09 22:21:41 +0900 | [diff] [blame] | 2338 | if (IS_ERR(base)) |
| 2339 | return PTR_ERR(base); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2340 | |
Andre Przywara | 3873e2d | 2015-05-21 17:26:18 +0100 | [diff] [blame] | 2341 | index = pl011_probe_dt_alias(index, dev); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2342 | |
Shreshtha Kumar Sahu | d8d8ffa | 2012-01-18 15:53:59 +0530 | [diff] [blame] | 2343 | uap->old_cr = 0; |
Andre Przywara | 3873e2d | 2015-05-21 17:26:18 +0100 | [diff] [blame] | 2344 | uap->port.dev = dev; |
| 2345 | uap->port.mapbase = mmiobase->start; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2346 | uap->port.membase = base; |
| 2347 | uap->port.iotype = UPIO_MEM; |
Russell King | ffca2b1 | 2010-12-22 17:13:05 +0000 | [diff] [blame] | 2348 | uap->port.fifosize = uap->fifosize; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2349 | uap->port.flags = UPF_BOOT_AUTOCONF; |
Andre Przywara | 3873e2d | 2015-05-21 17:26:18 +0100 | [diff] [blame] | 2350 | uap->port.line = index; |
| 2351 | |
| 2352 | amba_ports[index] = uap; |
| 2353 | |
| 2354 | return 0; |
| 2355 | } |
| 2356 | |
| 2357 | static int pl011_register_port(struct uart_amba_port *uap) |
| 2358 | { |
| 2359 | int ret; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2360 | |
Linus Walleij | c3d8b76 | 2012-03-21 20:15:18 +0100 | [diff] [blame] | 2361 | /* Ensure interrupts from this UART are masked and cleared */ |
Russell King | 9f25bc5 | 2015-11-03 14:51:13 +0000 | [diff] [blame^] | 2362 | pl011_write(0, uap, REG_IMSC); |
| 2363 | pl011_write(0xffff, uap, REG_ICR); |
Linus Walleij | c3d8b76 | 2012-03-21 20:15:18 +0100 | [diff] [blame] | 2364 | |
Tushar Behera | ef2889f | 2014-01-20 14:32:35 +0530 | [diff] [blame] | 2365 | if (!amba_reg.state) { |
| 2366 | ret = uart_register_driver(&amba_reg); |
| 2367 | if (ret < 0) { |
Andre Przywara | 3873e2d | 2015-05-21 17:26:18 +0100 | [diff] [blame] | 2368 | dev_err(uap->port.dev, |
Jorge Ramirez-Ortiz | 1c9be31 | 2015-03-06 13:05:40 -0500 | [diff] [blame] | 2369 | "Failed to register AMBA-PL011 driver\n"); |
Tushar Behera | ef2889f | 2014-01-20 14:32:35 +0530 | [diff] [blame] | 2370 | return ret; |
| 2371 | } |
| 2372 | } |
| 2373 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2374 | ret = uart_add_one_port(&amba_reg, &uap->port); |
Andre Przywara | 49bb3c8 | 2015-05-21 17:26:14 +0100 | [diff] [blame] | 2375 | if (ret) |
| 2376 | pl011_unregister_port(uap); |
Tushar Behera | 7f6d942 | 2014-06-26 15:35:35 +0530 | [diff] [blame] | 2377 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2378 | return ret; |
| 2379 | } |
| 2380 | |
Andre Przywara | 3873e2d | 2015-05-21 17:26:18 +0100 | [diff] [blame] | 2381 | static int pl011_probe(struct amba_device *dev, const struct amba_id *id) |
| 2382 | { |
| 2383 | struct uart_amba_port *uap; |
| 2384 | struct vendor_data *vendor = id->data; |
| 2385 | int portnr, ret; |
| 2386 | |
| 2387 | portnr = pl011_find_free_port(); |
| 2388 | if (portnr < 0) |
| 2389 | return portnr; |
| 2390 | |
| 2391 | uap = devm_kzalloc(&dev->dev, sizeof(struct uart_amba_port), |
| 2392 | GFP_KERNEL); |
| 2393 | if (!uap) |
| 2394 | return -ENOMEM; |
| 2395 | |
| 2396 | uap->clk = devm_clk_get(&dev->dev, NULL); |
| 2397 | if (IS_ERR(uap->clk)) |
| 2398 | return PTR_ERR(uap->clk); |
| 2399 | |
| 2400 | uap->vendor = vendor; |
| 2401 | uap->lcrh_rx = vendor->lcrh_rx; |
| 2402 | uap->lcrh_tx = vendor->lcrh_tx; |
| 2403 | uap->fifosize = vendor->get_fifosize(dev); |
| 2404 | uap->port.irq = dev->irq[0]; |
| 2405 | uap->port.ops = &amba_pl011_pops; |
| 2406 | |
| 2407 | snprintf(uap->type, sizeof(uap->type), "PL011 rev%u", amba_rev(dev)); |
| 2408 | |
| 2409 | ret = pl011_setup_port(&dev->dev, uap, &dev->res, portnr); |
| 2410 | if (ret) |
| 2411 | return ret; |
| 2412 | |
| 2413 | amba_set_drvdata(dev, uap); |
| 2414 | |
| 2415 | return pl011_register_port(uap); |
| 2416 | } |
| 2417 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2418 | static int pl011_remove(struct amba_device *dev) |
| 2419 | { |
| 2420 | struct uart_amba_port *uap = amba_get_drvdata(dev); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2421 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2422 | uart_remove_one_port(&amba_reg, &uap->port); |
Andre Przywara | 49bb3c8 | 2015-05-21 17:26:14 +0100 | [diff] [blame] | 2423 | pl011_unregister_port(uap); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2424 | return 0; |
| 2425 | } |
| 2426 | |
Ulf Hansson | d0ce850 | 2013-12-03 11:04:28 +0100 | [diff] [blame] | 2427 | #ifdef CONFIG_PM_SLEEP |
| 2428 | static int pl011_suspend(struct device *dev) |
Leo Chen | b736b89 | 2009-07-28 23:43:33 +0100 | [diff] [blame] | 2429 | { |
Ulf Hansson | d0ce850 | 2013-12-03 11:04:28 +0100 | [diff] [blame] | 2430 | struct uart_amba_port *uap = dev_get_drvdata(dev); |
Leo Chen | b736b89 | 2009-07-28 23:43:33 +0100 | [diff] [blame] | 2431 | |
| 2432 | if (!uap) |
| 2433 | return -EINVAL; |
| 2434 | |
| 2435 | return uart_suspend_port(&amba_reg, &uap->port); |
| 2436 | } |
| 2437 | |
Ulf Hansson | d0ce850 | 2013-12-03 11:04:28 +0100 | [diff] [blame] | 2438 | static int pl011_resume(struct device *dev) |
Leo Chen | b736b89 | 2009-07-28 23:43:33 +0100 | [diff] [blame] | 2439 | { |
Ulf Hansson | d0ce850 | 2013-12-03 11:04:28 +0100 | [diff] [blame] | 2440 | struct uart_amba_port *uap = dev_get_drvdata(dev); |
Leo Chen | b736b89 | 2009-07-28 23:43:33 +0100 | [diff] [blame] | 2441 | |
| 2442 | if (!uap) |
| 2443 | return -EINVAL; |
| 2444 | |
| 2445 | return uart_resume_port(&amba_reg, &uap->port); |
| 2446 | } |
| 2447 | #endif |
| 2448 | |
Ulf Hansson | d0ce850 | 2013-12-03 11:04:28 +0100 | [diff] [blame] | 2449 | static SIMPLE_DEV_PM_OPS(pl011_dev_pm_ops, pl011_suspend, pl011_resume); |
| 2450 | |
Andre Przywara | 0dd1e24 | 2015-05-21 17:26:23 +0100 | [diff] [blame] | 2451 | static int sbsa_uart_probe(struct platform_device *pdev) |
| 2452 | { |
| 2453 | struct uart_amba_port *uap; |
| 2454 | struct resource *r; |
| 2455 | int portnr, ret; |
| 2456 | int baudrate; |
| 2457 | |
| 2458 | /* |
| 2459 | * Check the mandatory baud rate parameter in the DT node early |
| 2460 | * so that we can easily exit with the error. |
| 2461 | */ |
| 2462 | if (pdev->dev.of_node) { |
| 2463 | struct device_node *np = pdev->dev.of_node; |
| 2464 | |
| 2465 | ret = of_property_read_u32(np, "current-speed", &baudrate); |
| 2466 | if (ret) |
| 2467 | return ret; |
| 2468 | } else { |
| 2469 | baudrate = 115200; |
| 2470 | } |
| 2471 | |
| 2472 | portnr = pl011_find_free_port(); |
| 2473 | if (portnr < 0) |
| 2474 | return portnr; |
| 2475 | |
| 2476 | uap = devm_kzalloc(&pdev->dev, sizeof(struct uart_amba_port), |
| 2477 | GFP_KERNEL); |
| 2478 | if (!uap) |
| 2479 | return -ENOMEM; |
| 2480 | |
| 2481 | uap->vendor = &vendor_sbsa; |
| 2482 | uap->fifosize = 32; |
| 2483 | uap->port.irq = platform_get_irq(pdev, 0); |
| 2484 | uap->port.ops = &sbsa_uart_pops; |
| 2485 | uap->fixed_baud = baudrate; |
| 2486 | |
| 2487 | snprintf(uap->type, sizeof(uap->type), "SBSA"); |
| 2488 | |
| 2489 | r = platform_get_resource(pdev, IORESOURCE_MEM, 0); |
| 2490 | |
| 2491 | ret = pl011_setup_port(&pdev->dev, uap, r, portnr); |
| 2492 | if (ret) |
| 2493 | return ret; |
| 2494 | |
| 2495 | platform_set_drvdata(pdev, uap); |
| 2496 | |
| 2497 | return pl011_register_port(uap); |
| 2498 | } |
| 2499 | |
| 2500 | static int sbsa_uart_remove(struct platform_device *pdev) |
| 2501 | { |
| 2502 | struct uart_amba_port *uap = platform_get_drvdata(pdev); |
| 2503 | |
| 2504 | uart_remove_one_port(&amba_reg, &uap->port); |
| 2505 | pl011_unregister_port(uap); |
| 2506 | return 0; |
| 2507 | } |
| 2508 | |
| 2509 | static const struct of_device_id sbsa_uart_of_match[] = { |
| 2510 | { .compatible = "arm,sbsa-uart", }, |
| 2511 | {}, |
| 2512 | }; |
| 2513 | MODULE_DEVICE_TABLE(of, sbsa_uart_of_match); |
| 2514 | |
Graeme Gregory | 3db9ab0 | 2015-05-21 17:26:24 +0100 | [diff] [blame] | 2515 | static const struct acpi_device_id sbsa_uart_acpi_match[] = { |
| 2516 | { "ARMH0011", 0 }, |
| 2517 | {}, |
| 2518 | }; |
| 2519 | MODULE_DEVICE_TABLE(acpi, sbsa_uart_acpi_match); |
| 2520 | |
Andre Przywara | 0dd1e24 | 2015-05-21 17:26:23 +0100 | [diff] [blame] | 2521 | static struct platform_driver arm_sbsa_uart_platform_driver = { |
| 2522 | .probe = sbsa_uart_probe, |
| 2523 | .remove = sbsa_uart_remove, |
| 2524 | .driver = { |
| 2525 | .name = "sbsa-uart", |
| 2526 | .of_match_table = of_match_ptr(sbsa_uart_of_match), |
Graeme Gregory | 3db9ab0 | 2015-05-21 17:26:24 +0100 | [diff] [blame] | 2527 | .acpi_match_table = ACPI_PTR(sbsa_uart_acpi_match), |
Andre Przywara | 0dd1e24 | 2015-05-21 17:26:23 +0100 | [diff] [blame] | 2528 | }, |
| 2529 | }; |
| 2530 | |
Russell King | 2c39c9e | 2010-07-27 08:50:16 +0100 | [diff] [blame] | 2531 | static struct amba_id pl011_ids[] = { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2532 | { |
| 2533 | .id = 0x00041011, |
| 2534 | .mask = 0x000fffff, |
Alessandro Rubini | 5926a29 | 2009-06-04 17:43:04 +0100 | [diff] [blame] | 2535 | .data = &vendor_arm, |
| 2536 | }, |
| 2537 | { |
| 2538 | .id = 0x00380802, |
| 2539 | .mask = 0x00ffffff, |
| 2540 | .data = &vendor_st, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2541 | }, |
| 2542 | { 0, 0 }, |
| 2543 | }; |
| 2544 | |
Dave Martin | 60f7a33 | 2011-10-05 15:15:22 +0100 | [diff] [blame] | 2545 | MODULE_DEVICE_TABLE(amba, pl011_ids); |
| 2546 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2547 | static struct amba_driver pl011_driver = { |
| 2548 | .drv = { |
| 2549 | .name = "uart-pl011", |
Ulf Hansson | d0ce850 | 2013-12-03 11:04:28 +0100 | [diff] [blame] | 2550 | .pm = &pl011_dev_pm_ops, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2551 | }, |
| 2552 | .id_table = pl011_ids, |
| 2553 | .probe = pl011_probe, |
| 2554 | .remove = pl011_remove, |
| 2555 | }; |
| 2556 | |
| 2557 | static int __init pl011_init(void) |
| 2558 | { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2559 | printk(KERN_INFO "Serial: AMBA PL011 UART driver\n"); |
| 2560 | |
Andre Przywara | 0dd1e24 | 2015-05-21 17:26:23 +0100 | [diff] [blame] | 2561 | if (platform_driver_register(&arm_sbsa_uart_platform_driver)) |
| 2562 | pr_warn("could not register SBSA UART platform driver\n"); |
Greg Kroah-Hartman | 062a68a | 2015-09-04 09:11:24 -0700 | [diff] [blame] | 2563 | return amba_driver_register(&pl011_driver); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2564 | } |
| 2565 | |
| 2566 | static void __exit pl011_exit(void) |
| 2567 | { |
Andre Przywara | 0dd1e24 | 2015-05-21 17:26:23 +0100 | [diff] [blame] | 2568 | platform_driver_unregister(&arm_sbsa_uart_platform_driver); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2569 | amba_driver_unregister(&pl011_driver); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2570 | } |
| 2571 | |
Alessandro Rubini | 4dd9e74 | 2009-05-05 05:54:13 +0100 | [diff] [blame] | 2572 | /* |
| 2573 | * While this can be a module, if builtin it's most likely the console |
| 2574 | * So let's leave module_exit but move module_init to an earlier place |
| 2575 | */ |
| 2576 | arch_initcall(pl011_init); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2577 | module_exit(pl011_exit); |
| 2578 | |
| 2579 | MODULE_AUTHOR("ARM Ltd/Deep Blue Solutions Ltd"); |
| 2580 | MODULE_DESCRIPTION("ARM AMBA serial port driver"); |
| 2581 | MODULE_LICENSE("GPL"); |