Greg Kroah-Hartman | e3b3d0f | 2017-11-06 18:11:51 +0100 | [diff] [blame] | 1 | // SPDX-License-Identifier: GPL-2.0 |
Carlo Caione | ff7693d | 2014-08-17 12:49:49 +0200 | [diff] [blame] | 2 | /* |
| 3 | * Based on meson_uart.c, by AMLOGIC, INC. |
| 4 | * |
| 5 | * Copyright (C) 2014 Carlo Caione <carlo@caione.org> |
Carlo Caione | ff7693d | 2014-08-17 12:49:49 +0200 | [diff] [blame] | 6 | */ |
| 7 | |
| 8 | #include <linux/clk.h> |
| 9 | #include <linux/console.h> |
| 10 | #include <linux/delay.h> |
| 11 | #include <linux/init.h> |
| 12 | #include <linux/io.h> |
Julien Masson | 8412ba1 | 2020-01-21 18:22:52 +0100 | [diff] [blame] | 13 | #include <linux/iopoll.h> |
Carlo Caione | ff7693d | 2014-08-17 12:49:49 +0200 | [diff] [blame] | 14 | #include <linux/module.h> |
| 15 | #include <linux/kernel.h> |
| 16 | #include <linux/of.h> |
| 17 | #include <linux/platform_device.h> |
| 18 | #include <linux/serial.h> |
| 19 | #include <linux/serial_core.h> |
| 20 | #include <linux/tty.h> |
| 21 | #include <linux/tty_flip.h> |
| 22 | |
| 23 | /* Register offsets */ |
| 24 | #define AML_UART_WFIFO 0x00 |
| 25 | #define AML_UART_RFIFO 0x04 |
| 26 | #define AML_UART_CONTROL 0x08 |
| 27 | #define AML_UART_STATUS 0x0c |
| 28 | #define AML_UART_MISC 0x10 |
| 29 | #define AML_UART_REG5 0x14 |
| 30 | |
| 31 | /* AML_UART_CONTROL bits */ |
| 32 | #define AML_UART_TX_EN BIT(12) |
| 33 | #define AML_UART_RX_EN BIT(13) |
Martin Blumenstingl | 44137e4 | 2017-11-17 19:18:00 +0100 | [diff] [blame] | 34 | #define AML_UART_TWO_WIRE_EN BIT(15) |
Martin Blumenstingl | f859722 | 2017-11-17 19:18:01 +0100 | [diff] [blame] | 35 | #define AML_UART_STOP_BIT_LEN_MASK (0x03 << 16) |
| 36 | #define AML_UART_STOP_BIT_1SB (0x00 << 16) |
| 37 | #define AML_UART_STOP_BIT_2SB (0x01 << 16) |
Martin Blumenstingl | 44137e4 | 2017-11-17 19:18:00 +0100 | [diff] [blame] | 38 | #define AML_UART_PARITY_TYPE BIT(18) |
| 39 | #define AML_UART_PARITY_EN BIT(19) |
Carlo Caione | ff7693d | 2014-08-17 12:49:49 +0200 | [diff] [blame] | 40 | #define AML_UART_TX_RST BIT(22) |
| 41 | #define AML_UART_RX_RST BIT(23) |
Martin Blumenstingl | 44137e4 | 2017-11-17 19:18:00 +0100 | [diff] [blame] | 42 | #define AML_UART_CLEAR_ERR BIT(24) |
Carlo Caione | ff7693d | 2014-08-17 12:49:49 +0200 | [diff] [blame] | 43 | #define AML_UART_RX_INT_EN BIT(27) |
| 44 | #define AML_UART_TX_INT_EN BIT(28) |
| 45 | #define AML_UART_DATA_LEN_MASK (0x03 << 20) |
| 46 | #define AML_UART_DATA_LEN_8BIT (0x00 << 20) |
| 47 | #define AML_UART_DATA_LEN_7BIT (0x01 << 20) |
| 48 | #define AML_UART_DATA_LEN_6BIT (0x02 << 20) |
| 49 | #define AML_UART_DATA_LEN_5BIT (0x03 << 20) |
| 50 | |
| 51 | /* AML_UART_STATUS bits */ |
| 52 | #define AML_UART_PARITY_ERR BIT(16) |
| 53 | #define AML_UART_FRAME_ERR BIT(17) |
| 54 | #define AML_UART_TX_FIFO_WERR BIT(18) |
| 55 | #define AML_UART_RX_EMPTY BIT(20) |
| 56 | #define AML_UART_TX_FULL BIT(21) |
| 57 | #define AML_UART_TX_EMPTY BIT(22) |
Ben Dooks | 8867973 | 2015-11-18 14:41:13 +0000 | [diff] [blame] | 58 | #define AML_UART_XMIT_BUSY BIT(25) |
Carlo Caione | ff7693d | 2014-08-17 12:49:49 +0200 | [diff] [blame] | 59 | #define AML_UART_ERR (AML_UART_PARITY_ERR | \ |
| 60 | AML_UART_FRAME_ERR | \ |
| 61 | AML_UART_TX_FIFO_WERR) |
| 62 | |
Carlo Caione | ff7693d | 2014-08-17 12:49:49 +0200 | [diff] [blame] | 63 | /* AML_UART_MISC bits */ |
| 64 | #define AML_UART_XMIT_IRQ(c) (((c) & 0xff) << 8) |
| 65 | #define AML_UART_RECV_IRQ(c) ((c) & 0xff) |
| 66 | |
| 67 | /* AML_UART_REG5 bits */ |
| 68 | #define AML_UART_BAUD_MASK 0x7fffff |
| 69 | #define AML_UART_BAUD_USE BIT(23) |
Andreas Färber | 146f380 | 2016-02-08 13:49:42 +0100 | [diff] [blame] | 70 | #define AML_UART_BAUD_XTAL BIT(24) |
Carlo Caione | ff7693d | 2014-08-17 12:49:49 +0200 | [diff] [blame] | 71 | |
Loys Ollivier | a26988e | 2019-01-14 17:54:26 +0100 | [diff] [blame] | 72 | #define AML_UART_PORT_NUM 12 |
| 73 | #define AML_UART_PORT_OFFSET 6 |
Carlo Caione | ff7693d | 2014-08-17 12:49:49 +0200 | [diff] [blame] | 74 | #define AML_UART_DEV_NAME "ttyAML" |
| 75 | |
Julien Masson | 8412ba1 | 2020-01-21 18:22:52 +0100 | [diff] [blame] | 76 | #define AML_UART_POLL_USEC 5 |
| 77 | #define AML_UART_TIMEOUT_USEC 10000 |
Carlo Caione | ff7693d | 2014-08-17 12:49:49 +0200 | [diff] [blame] | 78 | |
| 79 | static struct uart_driver meson_uart_driver; |
| 80 | |
| 81 | static struct uart_port *meson_ports[AML_UART_PORT_NUM]; |
| 82 | |
| 83 | static void meson_uart_set_mctrl(struct uart_port *port, unsigned int mctrl) |
| 84 | { |
| 85 | } |
| 86 | |
| 87 | static unsigned int meson_uart_get_mctrl(struct uart_port *port) |
| 88 | { |
| 89 | return TIOCM_CTS; |
| 90 | } |
| 91 | |
| 92 | static unsigned int meson_uart_tx_empty(struct uart_port *port) |
| 93 | { |
| 94 | u32 val; |
| 95 | |
| 96 | val = readl(port->membase + AML_UART_STATUS); |
Ben Dooks | 8867973 | 2015-11-18 14:41:13 +0000 | [diff] [blame] | 97 | val &= (AML_UART_TX_EMPTY | AML_UART_XMIT_BUSY); |
| 98 | return (val == AML_UART_TX_EMPTY) ? TIOCSER_TEMT : 0; |
Carlo Caione | ff7693d | 2014-08-17 12:49:49 +0200 | [diff] [blame] | 99 | } |
| 100 | |
| 101 | static void meson_uart_stop_tx(struct uart_port *port) |
| 102 | { |
| 103 | u32 val; |
| 104 | |
| 105 | val = readl(port->membase + AML_UART_CONTROL); |
Ben Dooks | 855ddca | 2015-11-18 14:41:15 +0000 | [diff] [blame] | 106 | val &= ~AML_UART_TX_INT_EN; |
Carlo Caione | ff7693d | 2014-08-17 12:49:49 +0200 | [diff] [blame] | 107 | writel(val, port->membase + AML_UART_CONTROL); |
| 108 | } |
| 109 | |
| 110 | static void meson_uart_stop_rx(struct uart_port *port) |
| 111 | { |
| 112 | u32 val; |
| 113 | |
| 114 | val = readl(port->membase + AML_UART_CONTROL); |
| 115 | val &= ~AML_UART_RX_EN; |
| 116 | writel(val, port->membase + AML_UART_CONTROL); |
| 117 | } |
| 118 | |
| 119 | static void meson_uart_shutdown(struct uart_port *port) |
| 120 | { |
| 121 | unsigned long flags; |
| 122 | u32 val; |
| 123 | |
| 124 | free_irq(port->irq, port); |
| 125 | |
| 126 | spin_lock_irqsave(&port->lock, flags); |
| 127 | |
| 128 | val = readl(port->membase + AML_UART_CONTROL); |
Ben Dooks | 855ddca | 2015-11-18 14:41:15 +0000 | [diff] [blame] | 129 | val &= ~AML_UART_RX_EN; |
Carlo Caione | ff7693d | 2014-08-17 12:49:49 +0200 | [diff] [blame] | 130 | val &= ~(AML_UART_RX_INT_EN | AML_UART_TX_INT_EN); |
| 131 | writel(val, port->membase + AML_UART_CONTROL); |
| 132 | |
| 133 | spin_unlock_irqrestore(&port->lock, flags); |
| 134 | } |
| 135 | |
| 136 | static void meson_uart_start_tx(struct uart_port *port) |
| 137 | { |
| 138 | struct circ_buf *xmit = &port->state->xmit; |
| 139 | unsigned int ch; |
Ben Dooks | f1dd05c | 2015-11-18 14:41:18 +0000 | [diff] [blame] | 140 | u32 val; |
Carlo Caione | ff7693d | 2014-08-17 12:49:49 +0200 | [diff] [blame] | 141 | |
| 142 | if (uart_tx_stopped(port)) { |
| 143 | meson_uart_stop_tx(port); |
| 144 | return; |
| 145 | } |
| 146 | |
| 147 | while (!(readl(port->membase + AML_UART_STATUS) & AML_UART_TX_FULL)) { |
| 148 | if (port->x_char) { |
| 149 | writel(port->x_char, port->membase + AML_UART_WFIFO); |
| 150 | port->icount.tx++; |
| 151 | port->x_char = 0; |
| 152 | continue; |
| 153 | } |
| 154 | |
| 155 | if (uart_circ_empty(xmit)) |
| 156 | break; |
| 157 | |
| 158 | ch = xmit->buf[xmit->tail]; |
| 159 | writel(ch, port->membase + AML_UART_WFIFO); |
| 160 | xmit->tail = (xmit->tail+1) & (SERIAL_XMIT_SIZE - 1); |
| 161 | port->icount.tx++; |
| 162 | } |
| 163 | |
Ben Dooks | f1dd05c | 2015-11-18 14:41:18 +0000 | [diff] [blame] | 164 | if (!uart_circ_empty(xmit)) { |
| 165 | val = readl(port->membase + AML_UART_CONTROL); |
| 166 | val |= AML_UART_TX_INT_EN; |
| 167 | writel(val, port->membase + AML_UART_CONTROL); |
| 168 | } |
| 169 | |
Carlo Caione | ff7693d | 2014-08-17 12:49:49 +0200 | [diff] [blame] | 170 | if (uart_circ_chars_pending(xmit) < WAKEUP_CHARS) |
| 171 | uart_write_wakeup(port); |
| 172 | } |
| 173 | |
| 174 | static void meson_receive_chars(struct uart_port *port) |
| 175 | { |
| 176 | struct tty_port *tport = &port->state->port; |
| 177 | char flag; |
Yixun Lan | b86ac22 | 2017-09-06 21:52:39 +0800 | [diff] [blame] | 178 | u32 ostatus, status, ch, mode; |
Carlo Caione | ff7693d | 2014-08-17 12:49:49 +0200 | [diff] [blame] | 179 | |
| 180 | do { |
| 181 | flag = TTY_NORMAL; |
| 182 | port->icount.rx++; |
Yixun Lan | b86ac22 | 2017-09-06 21:52:39 +0800 | [diff] [blame] | 183 | ostatus = status = readl(port->membase + AML_UART_STATUS); |
Carlo Caione | ff7693d | 2014-08-17 12:49:49 +0200 | [diff] [blame] | 184 | |
| 185 | if (status & AML_UART_ERR) { |
| 186 | if (status & AML_UART_TX_FIFO_WERR) |
| 187 | port->icount.overrun++; |
| 188 | else if (status & AML_UART_FRAME_ERR) |
| 189 | port->icount.frame++; |
| 190 | else if (status & AML_UART_PARITY_ERR) |
| 191 | port->icount.frame++; |
| 192 | |
| 193 | mode = readl(port->membase + AML_UART_CONTROL); |
| 194 | mode |= AML_UART_CLEAR_ERR; |
| 195 | writel(mode, port->membase + AML_UART_CONTROL); |
| 196 | |
| 197 | /* It doesn't clear to 0 automatically */ |
| 198 | mode &= ~AML_UART_CLEAR_ERR; |
| 199 | writel(mode, port->membase + AML_UART_CONTROL); |
| 200 | |
| 201 | status &= port->read_status_mask; |
| 202 | if (status & AML_UART_FRAME_ERR) |
| 203 | flag = TTY_FRAME; |
| 204 | else if (status & AML_UART_PARITY_ERR) |
| 205 | flag = TTY_PARITY; |
| 206 | } |
| 207 | |
| 208 | ch = readl(port->membase + AML_UART_RFIFO); |
| 209 | ch &= 0xff; |
| 210 | |
Yixun Lan | b86ac22 | 2017-09-06 21:52:39 +0800 | [diff] [blame] | 211 | if ((ostatus & AML_UART_FRAME_ERR) && (ch == 0)) { |
| 212 | port->icount.brk++; |
| 213 | flag = TTY_BREAK; |
| 214 | if (uart_handle_break(port)) |
| 215 | continue; |
| 216 | } |
| 217 | |
| 218 | if (uart_handle_sysrq_char(port, ch)) |
| 219 | continue; |
| 220 | |
Carlo Caione | ff7693d | 2014-08-17 12:49:49 +0200 | [diff] [blame] | 221 | if ((status & port->ignore_status_mask) == 0) |
| 222 | tty_insert_flip_char(tport, ch, flag); |
| 223 | |
| 224 | if (status & AML_UART_TX_FIFO_WERR) |
| 225 | tty_insert_flip_char(tport, 0, TTY_OVERRUN); |
| 226 | |
| 227 | } while (!(readl(port->membase + AML_UART_STATUS) & AML_UART_RX_EMPTY)); |
| 228 | |
Carlo Caione | ff7693d | 2014-08-17 12:49:49 +0200 | [diff] [blame] | 229 | tty_flip_buffer_push(tport); |
Carlo Caione | ff7693d | 2014-08-17 12:49:49 +0200 | [diff] [blame] | 230 | } |
| 231 | |
| 232 | static irqreturn_t meson_uart_interrupt(int irq, void *dev_id) |
| 233 | { |
| 234 | struct uart_port *port = (struct uart_port *)dev_id; |
| 235 | |
| 236 | spin_lock(&port->lock); |
| 237 | |
| 238 | if (!(readl(port->membase + AML_UART_STATUS) & AML_UART_RX_EMPTY)) |
| 239 | meson_receive_chars(port); |
| 240 | |
Ben Dooks | 3946965 | 2015-11-18 14:41:19 +0000 | [diff] [blame] | 241 | if (!(readl(port->membase + AML_UART_STATUS) & AML_UART_TX_FULL)) { |
| 242 | if (readl(port->membase + AML_UART_CONTROL) & AML_UART_TX_INT_EN) |
| 243 | meson_uart_start_tx(port); |
| 244 | } |
Carlo Caione | ff7693d | 2014-08-17 12:49:49 +0200 | [diff] [blame] | 245 | |
| 246 | spin_unlock(&port->lock); |
| 247 | |
| 248 | return IRQ_HANDLED; |
| 249 | } |
| 250 | |
| 251 | static const char *meson_uart_type(struct uart_port *port) |
| 252 | { |
| 253 | return (port->type == PORT_MESON) ? "meson_uart" : NULL; |
| 254 | } |
| 255 | |
Ben Dooks | 00661dd | 2015-11-18 14:41:12 +0000 | [diff] [blame] | 256 | static void meson_uart_reset(struct uart_port *port) |
Carlo Caione | ff7693d | 2014-08-17 12:49:49 +0200 | [diff] [blame] | 257 | { |
| 258 | u32 val; |
Carlo Caione | ff7693d | 2014-08-17 12:49:49 +0200 | [diff] [blame] | 259 | |
| 260 | val = readl(port->membase + AML_UART_CONTROL); |
Martin Blumenstingl | c0f0b8c | 2017-11-17 19:17:59 +0100 | [diff] [blame] | 261 | val |= (AML_UART_RX_RST | AML_UART_TX_RST | AML_UART_CLEAR_ERR); |
Carlo Caione | ff7693d | 2014-08-17 12:49:49 +0200 | [diff] [blame] | 262 | writel(val, port->membase + AML_UART_CONTROL); |
| 263 | |
Martin Blumenstingl | c0f0b8c | 2017-11-17 19:17:59 +0100 | [diff] [blame] | 264 | val &= ~(AML_UART_RX_RST | AML_UART_TX_RST | AML_UART_CLEAR_ERR); |
Carlo Caione | ff7693d | 2014-08-17 12:49:49 +0200 | [diff] [blame] | 265 | writel(val, port->membase + AML_UART_CONTROL); |
Ben Dooks | 00661dd | 2015-11-18 14:41:12 +0000 | [diff] [blame] | 266 | } |
| 267 | |
| 268 | static int meson_uart_startup(struct uart_port *port) |
| 269 | { |
| 270 | u32 val; |
| 271 | int ret = 0; |
| 272 | |
| 273 | val = readl(port->membase + AML_UART_CONTROL); |
Martin Blumenstingl | c0f0b8c | 2017-11-17 19:17:59 +0100 | [diff] [blame] | 274 | val |= AML_UART_CLEAR_ERR; |
Ben Dooks | 00661dd | 2015-11-18 14:41:12 +0000 | [diff] [blame] | 275 | writel(val, port->membase + AML_UART_CONTROL); |
Martin Blumenstingl | c0f0b8c | 2017-11-17 19:17:59 +0100 | [diff] [blame] | 276 | val &= ~AML_UART_CLEAR_ERR; |
Ben Dooks | 00661dd | 2015-11-18 14:41:12 +0000 | [diff] [blame] | 277 | writel(val, port->membase + AML_UART_CONTROL); |
Carlo Caione | ff7693d | 2014-08-17 12:49:49 +0200 | [diff] [blame] | 278 | |
| 279 | val |= (AML_UART_RX_EN | AML_UART_TX_EN); |
| 280 | writel(val, port->membase + AML_UART_CONTROL); |
| 281 | |
| 282 | val |= (AML_UART_RX_INT_EN | AML_UART_TX_INT_EN); |
| 283 | writel(val, port->membase + AML_UART_CONTROL); |
| 284 | |
| 285 | val = (AML_UART_RECV_IRQ(1) | AML_UART_XMIT_IRQ(port->fifosize / 2)); |
| 286 | writel(val, port->membase + AML_UART_MISC); |
| 287 | |
| 288 | ret = request_irq(port->irq, meson_uart_interrupt, 0, |
Heiner Kallweit | 8b7a6b2 | 2017-04-19 22:18:16 +0200 | [diff] [blame] | 289 | port->name, port); |
Carlo Caione | ff7693d | 2014-08-17 12:49:49 +0200 | [diff] [blame] | 290 | |
| 291 | return ret; |
| 292 | } |
| 293 | |
| 294 | static void meson_uart_change_speed(struct uart_port *port, unsigned long baud) |
| 295 | { |
| 296 | u32 val; |
| 297 | |
Ben Dooks | f1f5c14 | 2015-11-18 14:41:16 +0000 | [diff] [blame] | 298 | while (!meson_uart_tx_empty(port)) |
Carlo Caione | ff7693d | 2014-08-17 12:49:49 +0200 | [diff] [blame] | 299 | cpu_relax(); |
| 300 | |
Andreas Färber | 146f380 | 2016-02-08 13:49:42 +0100 | [diff] [blame] | 301 | if (port->uartclk == 24000000) { |
| 302 | val = ((port->uartclk / 3) / baud) - 1; |
| 303 | val |= AML_UART_BAUD_XTAL; |
| 304 | } else { |
| 305 | val = ((port->uartclk * 10 / (baud * 4) + 5) / 10) - 1; |
| 306 | } |
Carlo Caione | ff7693d | 2014-08-17 12:49:49 +0200 | [diff] [blame] | 307 | val |= AML_UART_BAUD_USE; |
| 308 | writel(val, port->membase + AML_UART_REG5); |
| 309 | } |
| 310 | |
| 311 | static void meson_uart_set_termios(struct uart_port *port, |
| 312 | struct ktermios *termios, |
| 313 | struct ktermios *old) |
| 314 | { |
| 315 | unsigned int cflags, iflags, baud; |
| 316 | unsigned long flags; |
| 317 | u32 val; |
| 318 | |
| 319 | spin_lock_irqsave(&port->lock, flags); |
| 320 | |
| 321 | cflags = termios->c_cflag; |
| 322 | iflags = termios->c_iflag; |
| 323 | |
| 324 | val = readl(port->membase + AML_UART_CONTROL); |
| 325 | |
| 326 | val &= ~AML_UART_DATA_LEN_MASK; |
| 327 | switch (cflags & CSIZE) { |
| 328 | case CS8: |
| 329 | val |= AML_UART_DATA_LEN_8BIT; |
| 330 | break; |
| 331 | case CS7: |
| 332 | val |= AML_UART_DATA_LEN_7BIT; |
| 333 | break; |
| 334 | case CS6: |
| 335 | val |= AML_UART_DATA_LEN_6BIT; |
| 336 | break; |
| 337 | case CS5: |
| 338 | val |= AML_UART_DATA_LEN_5BIT; |
| 339 | break; |
| 340 | } |
| 341 | |
| 342 | if (cflags & PARENB) |
| 343 | val |= AML_UART_PARITY_EN; |
| 344 | else |
| 345 | val &= ~AML_UART_PARITY_EN; |
| 346 | |
| 347 | if (cflags & PARODD) |
| 348 | val |= AML_UART_PARITY_TYPE; |
| 349 | else |
| 350 | val &= ~AML_UART_PARITY_TYPE; |
| 351 | |
Martin Blumenstingl | f859722 | 2017-11-17 19:18:01 +0100 | [diff] [blame] | 352 | val &= ~AML_UART_STOP_BIT_LEN_MASK; |
Carlo Caione | ff7693d | 2014-08-17 12:49:49 +0200 | [diff] [blame] | 353 | if (cflags & CSTOPB) |
Martin Blumenstingl | f859722 | 2017-11-17 19:18:01 +0100 | [diff] [blame] | 354 | val |= AML_UART_STOP_BIT_2SB; |
Carlo Caione | ff7693d | 2014-08-17 12:49:49 +0200 | [diff] [blame] | 355 | else |
Martin Blumenstingl | f859722 | 2017-11-17 19:18:01 +0100 | [diff] [blame] | 356 | val |= AML_UART_STOP_BIT_1SB; |
Carlo Caione | ff7693d | 2014-08-17 12:49:49 +0200 | [diff] [blame] | 357 | |
| 358 | if (cflags & CRTSCTS) |
| 359 | val &= ~AML_UART_TWO_WIRE_EN; |
| 360 | else |
| 361 | val |= AML_UART_TWO_WIRE_EN; |
| 362 | |
| 363 | writel(val, port->membase + AML_UART_CONTROL); |
| 364 | |
Thomas Rohloff | 9b11f19 | 2017-11-05 20:36:30 +0100 | [diff] [blame] | 365 | baud = uart_get_baud_rate(port, termios, old, 50, 4000000); |
Carlo Caione | ff7693d | 2014-08-17 12:49:49 +0200 | [diff] [blame] | 366 | meson_uart_change_speed(port, baud); |
| 367 | |
| 368 | port->read_status_mask = AML_UART_TX_FIFO_WERR; |
| 369 | if (iflags & INPCK) |
| 370 | port->read_status_mask |= AML_UART_PARITY_ERR | |
| 371 | AML_UART_FRAME_ERR; |
| 372 | |
| 373 | port->ignore_status_mask = 0; |
| 374 | if (iflags & IGNPAR) |
| 375 | port->ignore_status_mask |= AML_UART_PARITY_ERR | |
| 376 | AML_UART_FRAME_ERR; |
| 377 | |
| 378 | uart_update_timeout(port, termios->c_cflag, baud); |
| 379 | spin_unlock_irqrestore(&port->lock, flags); |
| 380 | } |
| 381 | |
| 382 | static int meson_uart_verify_port(struct uart_port *port, |
| 383 | struct serial_struct *ser) |
| 384 | { |
| 385 | int ret = 0; |
| 386 | |
| 387 | if (port->type != PORT_MESON) |
| 388 | ret = -EINVAL; |
| 389 | if (port->irq != ser->irq) |
| 390 | ret = -EINVAL; |
| 391 | if (ser->baud_base < 9600) |
| 392 | ret = -EINVAL; |
| 393 | return ret; |
| 394 | } |
| 395 | |
| 396 | static void meson_uart_release_port(struct uart_port *port) |
| 397 | { |
Heiner Kallweit | 1b1ecaa | 2017-04-19 22:17:50 +0200 | [diff] [blame] | 398 | devm_iounmap(port->dev, port->membase); |
| 399 | port->membase = NULL; |
| 400 | devm_release_mem_region(port->dev, port->mapbase, port->mapsize); |
Carlo Caione | ff7693d | 2014-08-17 12:49:49 +0200 | [diff] [blame] | 401 | } |
| 402 | |
| 403 | static int meson_uart_request_port(struct uart_port *port) |
| 404 | { |
Heiner Kallweit | ff3b9ca | 2017-04-19 22:17:47 +0200 | [diff] [blame] | 405 | if (!devm_request_mem_region(port->dev, port->mapbase, port->mapsize, |
Carlo Caione | ff7693d | 2014-08-17 12:49:49 +0200 | [diff] [blame] | 406 | dev_name(port->dev))) { |
| 407 | dev_err(port->dev, "Memory region busy\n"); |
| 408 | return -EBUSY; |
| 409 | } |
| 410 | |
Christoph Hellwig | 4bdc0d6 | 2020-01-06 09:43:50 +0100 | [diff] [blame] | 411 | port->membase = devm_ioremap(port->dev, port->mapbase, |
Heiner Kallweit | 1b1ecaa | 2017-04-19 22:17:50 +0200 | [diff] [blame] | 412 | port->mapsize); |
| 413 | if (!port->membase) |
| 414 | return -ENOMEM; |
Carlo Caione | ff7693d | 2014-08-17 12:49:49 +0200 | [diff] [blame] | 415 | |
| 416 | return 0; |
| 417 | } |
| 418 | |
| 419 | static void meson_uart_config_port(struct uart_port *port, int flags) |
| 420 | { |
| 421 | if (flags & UART_CONFIG_TYPE) { |
| 422 | port->type = PORT_MESON; |
| 423 | meson_uart_request_port(port); |
| 424 | } |
| 425 | } |
| 426 | |
Julien Masson | 8412ba1 | 2020-01-21 18:22:52 +0100 | [diff] [blame] | 427 | #ifdef CONFIG_CONSOLE_POLL |
| 428 | /* |
| 429 | * Console polling routines for writing and reading from the uart while |
| 430 | * in an interrupt or debug context (i.e. kgdb). |
| 431 | */ |
| 432 | |
| 433 | static int meson_uart_poll_get_char(struct uart_port *port) |
| 434 | { |
| 435 | u32 c; |
| 436 | unsigned long flags; |
| 437 | |
| 438 | spin_lock_irqsave(&port->lock, flags); |
| 439 | |
| 440 | if (readl(port->membase + AML_UART_STATUS) & AML_UART_RX_EMPTY) |
| 441 | c = NO_POLL_CHAR; |
| 442 | else |
| 443 | c = readl(port->membase + AML_UART_RFIFO); |
| 444 | |
| 445 | spin_unlock_irqrestore(&port->lock, flags); |
| 446 | |
| 447 | return c; |
| 448 | } |
| 449 | |
| 450 | static void meson_uart_poll_put_char(struct uart_port *port, unsigned char c) |
| 451 | { |
| 452 | unsigned long flags; |
| 453 | u32 reg; |
| 454 | int ret; |
| 455 | |
| 456 | spin_lock_irqsave(&port->lock, flags); |
| 457 | |
| 458 | /* Wait until FIFO is empty or timeout */ |
| 459 | ret = readl_poll_timeout_atomic(port->membase + AML_UART_STATUS, reg, |
| 460 | reg & AML_UART_TX_EMPTY, |
| 461 | AML_UART_POLL_USEC, |
| 462 | AML_UART_TIMEOUT_USEC); |
| 463 | if (ret == -ETIMEDOUT) { |
| 464 | dev_err(port->dev, "Timeout waiting for UART TX EMPTY\n"); |
| 465 | goto out; |
| 466 | } |
| 467 | |
| 468 | /* Write the character */ |
| 469 | writel(c, port->membase + AML_UART_WFIFO); |
| 470 | |
| 471 | /* Wait until FIFO is empty or timeout */ |
| 472 | ret = readl_poll_timeout_atomic(port->membase + AML_UART_STATUS, reg, |
| 473 | reg & AML_UART_TX_EMPTY, |
| 474 | AML_UART_POLL_USEC, |
| 475 | AML_UART_TIMEOUT_USEC); |
| 476 | if (ret == -ETIMEDOUT) |
| 477 | dev_err(port->dev, "Timeout waiting for UART TX EMPTY\n"); |
| 478 | |
| 479 | out: |
| 480 | spin_unlock_irqrestore(&port->lock, flags); |
| 481 | } |
| 482 | |
| 483 | #endif /* CONFIG_CONSOLE_POLL */ |
| 484 | |
Julia Lawall | 921469f | 2017-08-13 08:21:40 +0200 | [diff] [blame] | 485 | static const struct uart_ops meson_uart_ops = { |
Carlo Caione | ff7693d | 2014-08-17 12:49:49 +0200 | [diff] [blame] | 486 | .set_mctrl = meson_uart_set_mctrl, |
| 487 | .get_mctrl = meson_uart_get_mctrl, |
| 488 | .tx_empty = meson_uart_tx_empty, |
| 489 | .start_tx = meson_uart_start_tx, |
| 490 | .stop_tx = meson_uart_stop_tx, |
| 491 | .stop_rx = meson_uart_stop_rx, |
| 492 | .startup = meson_uart_startup, |
| 493 | .shutdown = meson_uart_shutdown, |
| 494 | .set_termios = meson_uart_set_termios, |
| 495 | .type = meson_uart_type, |
| 496 | .config_port = meson_uart_config_port, |
| 497 | .request_port = meson_uart_request_port, |
| 498 | .release_port = meson_uart_release_port, |
| 499 | .verify_port = meson_uart_verify_port, |
Julien Masson | 8412ba1 | 2020-01-21 18:22:52 +0100 | [diff] [blame] | 500 | #ifdef CONFIG_CONSOLE_POLL |
| 501 | .poll_get_char = meson_uart_poll_get_char, |
| 502 | .poll_put_char = meson_uart_poll_put_char, |
| 503 | #endif |
Carlo Caione | ff7693d | 2014-08-17 12:49:49 +0200 | [diff] [blame] | 504 | }; |
| 505 | |
| 506 | #ifdef CONFIG_SERIAL_MESON_CONSOLE |
Arnd Bergmann | 5fa4acc | 2017-05-22 15:37:03 +0200 | [diff] [blame] | 507 | static void meson_uart_enable_tx_engine(struct uart_port *port) |
| 508 | { |
| 509 | u32 val; |
| 510 | |
| 511 | val = readl(port->membase + AML_UART_CONTROL); |
| 512 | val |= AML_UART_TX_EN; |
| 513 | writel(val, port->membase + AML_UART_CONTROL); |
| 514 | } |
Carlo Caione | ff7693d | 2014-08-17 12:49:49 +0200 | [diff] [blame] | 515 | |
| 516 | static void meson_console_putchar(struct uart_port *port, int ch) |
| 517 | { |
| 518 | if (!port->membase) |
| 519 | return; |
| 520 | |
| 521 | while (readl(port->membase + AML_UART_STATUS) & AML_UART_TX_FULL) |
| 522 | cpu_relax(); |
| 523 | writel(ch, port->membase + AML_UART_WFIFO); |
| 524 | } |
| 525 | |
Andreas Färber | 736d553 | 2016-03-06 12:21:24 +0100 | [diff] [blame] | 526 | static void meson_serial_port_write(struct uart_port *port, const char *s, |
| 527 | u_int count) |
Carlo Caione | ff7693d | 2014-08-17 12:49:49 +0200 | [diff] [blame] | 528 | { |
Carlo Caione | ff7693d | 2014-08-17 12:49:49 +0200 | [diff] [blame] | 529 | unsigned long flags; |
| 530 | int locked; |
Ben Dooks | 2561f06 | 2015-11-18 14:41:17 +0000 | [diff] [blame] | 531 | u32 val, tmp; |
Carlo Caione | ff7693d | 2014-08-17 12:49:49 +0200 | [diff] [blame] | 532 | |
Carlo Caione | ff7693d | 2014-08-17 12:49:49 +0200 | [diff] [blame] | 533 | local_irq_save(flags); |
| 534 | if (port->sysrq) { |
| 535 | locked = 0; |
| 536 | } else if (oops_in_progress) { |
| 537 | locked = spin_trylock(&port->lock); |
| 538 | } else { |
| 539 | spin_lock(&port->lock); |
| 540 | locked = 1; |
| 541 | } |
| 542 | |
Ben Dooks | 41788f0 | 2015-11-18 14:41:14 +0000 | [diff] [blame] | 543 | val = readl(port->membase + AML_UART_CONTROL); |
Ben Dooks | 2561f06 | 2015-11-18 14:41:17 +0000 | [diff] [blame] | 544 | tmp = val & ~(AML_UART_TX_INT_EN | AML_UART_RX_INT_EN); |
| 545 | writel(tmp, port->membase + AML_UART_CONTROL); |
Ben Dooks | 41788f0 | 2015-11-18 14:41:14 +0000 | [diff] [blame] | 546 | |
Carlo Caione | ff7693d | 2014-08-17 12:49:49 +0200 | [diff] [blame] | 547 | uart_console_write(port, s, count, meson_console_putchar); |
Ben Dooks | 2561f06 | 2015-11-18 14:41:17 +0000 | [diff] [blame] | 548 | writel(val, port->membase + AML_UART_CONTROL); |
Carlo Caione | ff7693d | 2014-08-17 12:49:49 +0200 | [diff] [blame] | 549 | |
| 550 | if (locked) |
| 551 | spin_unlock(&port->lock); |
| 552 | local_irq_restore(flags); |
| 553 | } |
| 554 | |
Andreas Färber | 736d553 | 2016-03-06 12:21:24 +0100 | [diff] [blame] | 555 | static void meson_serial_console_write(struct console *co, const char *s, |
| 556 | u_int count) |
| 557 | { |
| 558 | struct uart_port *port; |
| 559 | |
| 560 | port = meson_ports[co->index]; |
| 561 | if (!port) |
| 562 | return; |
| 563 | |
| 564 | meson_serial_port_write(port, s, count); |
| 565 | } |
| 566 | |
Carlo Caione | ff7693d | 2014-08-17 12:49:49 +0200 | [diff] [blame] | 567 | static int meson_serial_console_setup(struct console *co, char *options) |
| 568 | { |
| 569 | struct uart_port *port; |
| 570 | int baud = 115200; |
| 571 | int bits = 8; |
| 572 | int parity = 'n'; |
| 573 | int flow = 'n'; |
| 574 | |
| 575 | if (co->index < 0 || co->index >= AML_UART_PORT_NUM) |
| 576 | return -EINVAL; |
| 577 | |
| 578 | port = meson_ports[co->index]; |
| 579 | if (!port || !port->membase) |
| 580 | return -ENODEV; |
| 581 | |
Heiner Kallweit | ba50f1d | 2017-04-19 22:17:44 +0200 | [diff] [blame] | 582 | meson_uart_enable_tx_engine(port); |
| 583 | |
Carlo Caione | ff7693d | 2014-08-17 12:49:49 +0200 | [diff] [blame] | 584 | if (options) |
| 585 | uart_parse_options(options, &baud, &parity, &bits, &flow); |
| 586 | |
| 587 | return uart_set_options(port, co, baud, parity, bits, flow); |
| 588 | } |
| 589 | |
| 590 | static struct console meson_serial_console = { |
| 591 | .name = AML_UART_DEV_NAME, |
| 592 | .write = meson_serial_console_write, |
| 593 | .device = uart_console_device, |
| 594 | .setup = meson_serial_console_setup, |
| 595 | .flags = CON_PRINTBUFFER, |
| 596 | .index = -1, |
| 597 | .data = &meson_uart_driver, |
| 598 | }; |
| 599 | |
| 600 | static int __init meson_serial_console_init(void) |
| 601 | { |
| 602 | register_console(&meson_serial_console); |
| 603 | return 0; |
| 604 | } |
Carlo Caione | ff7693d | 2014-08-17 12:49:49 +0200 | [diff] [blame] | 605 | |
Andreas Färber | 736d553 | 2016-03-06 12:21:24 +0100 | [diff] [blame] | 606 | static void meson_serial_early_console_write(struct console *co, |
| 607 | const char *s, |
| 608 | u_int count) |
| 609 | { |
| 610 | struct earlycon_device *dev = co->data; |
| 611 | |
| 612 | meson_serial_port_write(&dev->port, s, count); |
| 613 | } |
| 614 | |
| 615 | static int __init |
| 616 | meson_serial_early_console_setup(struct earlycon_device *device, const char *opt) |
| 617 | { |
| 618 | if (!device->port.membase) |
| 619 | return -ENODEV; |
| 620 | |
Heiner Kallweit | ba50f1d | 2017-04-19 22:17:44 +0200 | [diff] [blame] | 621 | meson_uart_enable_tx_engine(&device->port); |
Andreas Färber | 736d553 | 2016-03-06 12:21:24 +0100 | [diff] [blame] | 622 | device->con->write = meson_serial_early_console_write; |
| 623 | return 0; |
| 624 | } |
Helmut Klein | 9f60e0e | 2017-06-14 10:29:15 +0200 | [diff] [blame] | 625 | /* Legacy bindings, should be removed when no more used */ |
Andreas Färber | 736d553 | 2016-03-06 12:21:24 +0100 | [diff] [blame] | 626 | OF_EARLYCON_DECLARE(meson, "amlogic,meson-uart", |
| 627 | meson_serial_early_console_setup); |
Helmut Klein | 9f60e0e | 2017-06-14 10:29:15 +0200 | [diff] [blame] | 628 | /* Stable bindings */ |
| 629 | OF_EARLYCON_DECLARE(meson, "amlogic,meson-ao-uart", |
| 630 | meson_serial_early_console_setup); |
Andreas Färber | 736d553 | 2016-03-06 12:21:24 +0100 | [diff] [blame] | 631 | |
Carlo Caione | ff7693d | 2014-08-17 12:49:49 +0200 | [diff] [blame] | 632 | #define MESON_SERIAL_CONSOLE (&meson_serial_console) |
| 633 | #else |
Kevin Hilman | 87a0b9f | 2020-12-10 16:57:44 -0800 | [diff] [blame] | 634 | static int __init meson_serial_console_init(void) { |
| 635 | return 0; |
| 636 | } |
Carlo Caione | ff7693d | 2014-08-17 12:49:49 +0200 | [diff] [blame] | 637 | #define MESON_SERIAL_CONSOLE NULL |
| 638 | #endif |
| 639 | |
| 640 | static struct uart_driver meson_uart_driver = { |
| 641 | .owner = THIS_MODULE, |
| 642 | .driver_name = "meson_uart", |
| 643 | .dev_name = AML_UART_DEV_NAME, |
| 644 | .nr = AML_UART_PORT_NUM, |
| 645 | .cons = MESON_SERIAL_CONSOLE, |
| 646 | }; |
| 647 | |
Helmut Klein | 9f60e0e | 2017-06-14 10:29:15 +0200 | [diff] [blame] | 648 | static inline struct clk *meson_uart_probe_clock(struct device *dev, |
| 649 | const char *id) |
| 650 | { |
| 651 | struct clk *clk = NULL; |
| 652 | int ret; |
| 653 | |
| 654 | clk = devm_clk_get(dev, id); |
| 655 | if (IS_ERR(clk)) |
| 656 | return clk; |
| 657 | |
| 658 | ret = clk_prepare_enable(clk); |
| 659 | if (ret) { |
| 660 | dev_err(dev, "couldn't enable clk\n"); |
| 661 | return ERR_PTR(ret); |
| 662 | } |
| 663 | |
| 664 | devm_add_action_or_reset(dev, |
| 665 | (void(*)(void *))clk_disable_unprepare, |
| 666 | clk); |
| 667 | |
| 668 | return clk; |
| 669 | } |
| 670 | |
| 671 | /* |
| 672 | * This function gets clocks in the legacy non-stable DT bindings. |
| 673 | * This code will be remove once all the platforms switch to the |
| 674 | * new DT bindings. |
| 675 | */ |
| 676 | static int meson_uart_probe_clocks_legacy(struct platform_device *pdev, |
| 677 | struct uart_port *port) |
| 678 | { |
| 679 | struct clk *clk = NULL; |
| 680 | |
| 681 | clk = meson_uart_probe_clock(&pdev->dev, NULL); |
| 682 | if (IS_ERR(clk)) |
| 683 | return PTR_ERR(clk); |
| 684 | |
| 685 | port->uartclk = clk_get_rate(clk); |
| 686 | |
| 687 | return 0; |
| 688 | } |
| 689 | |
| 690 | static int meson_uart_probe_clocks(struct platform_device *pdev, |
| 691 | struct uart_port *port) |
| 692 | { |
| 693 | struct clk *clk_xtal = NULL; |
| 694 | struct clk *clk_pclk = NULL; |
| 695 | struct clk *clk_baud = NULL; |
| 696 | |
| 697 | clk_pclk = meson_uart_probe_clock(&pdev->dev, "pclk"); |
| 698 | if (IS_ERR(clk_pclk)) |
| 699 | return PTR_ERR(clk_pclk); |
| 700 | |
| 701 | clk_xtal = meson_uart_probe_clock(&pdev->dev, "xtal"); |
| 702 | if (IS_ERR(clk_xtal)) |
| 703 | return PTR_ERR(clk_xtal); |
| 704 | |
| 705 | clk_baud = meson_uart_probe_clock(&pdev->dev, "baud"); |
| 706 | if (IS_ERR(clk_baud)) |
| 707 | return PTR_ERR(clk_baud); |
| 708 | |
| 709 | port->uartclk = clk_get_rate(clk_baud); |
| 710 | |
| 711 | return 0; |
| 712 | } |
| 713 | |
Carlo Caione | ff7693d | 2014-08-17 12:49:49 +0200 | [diff] [blame] | 714 | static int meson_uart_probe(struct platform_device *pdev) |
| 715 | { |
| 716 | struct resource *res_mem, *res_irq; |
| 717 | struct uart_port *port; |
Neil Armstrong | 27d44e0 | 2021-05-18 09:58:32 +0200 | [diff] [blame] | 718 | u32 fifosize = 64; /* Default is 64, 128 for EE UART_0 */ |
Carlo Caione | ff7693d | 2014-08-17 12:49:49 +0200 | [diff] [blame] | 719 | int ret = 0; |
| 720 | |
| 721 | if (pdev->dev.of_node) |
| 722 | pdev->id = of_alias_get_id(pdev->dev.of_node, "serial"); |
| 723 | |
Loys Ollivier | a26988e | 2019-01-14 17:54:26 +0100 | [diff] [blame] | 724 | if (pdev->id < 0) { |
Colin Ian King | 021212f | 2021-04-26 11:11:06 +0100 | [diff] [blame] | 725 | int id; |
| 726 | |
Loys Ollivier | a26988e | 2019-01-14 17:54:26 +0100 | [diff] [blame] | 727 | for (id = AML_UART_PORT_OFFSET; id < AML_UART_PORT_NUM; id++) { |
| 728 | if (!meson_ports[id]) { |
| 729 | pdev->id = id; |
| 730 | break; |
| 731 | } |
| 732 | } |
| 733 | } |
| 734 | |
Carlo Caione | ff7693d | 2014-08-17 12:49:49 +0200 | [diff] [blame] | 735 | if (pdev->id < 0 || pdev->id >= AML_UART_PORT_NUM) |
| 736 | return -EINVAL; |
| 737 | |
| 738 | res_mem = platform_get_resource(pdev, IORESOURCE_MEM, 0); |
| 739 | if (!res_mem) |
| 740 | return -ENODEV; |
| 741 | |
| 742 | res_irq = platform_get_resource(pdev, IORESOURCE_IRQ, 0); |
| 743 | if (!res_irq) |
| 744 | return -ENODEV; |
| 745 | |
Neil Armstrong | 27d44e0 | 2021-05-18 09:58:32 +0200 | [diff] [blame] | 746 | of_property_read_u32(pdev->dev.of_node, "fifo-size", &fifosize); |
| 747 | |
Carlo Caione | ff7693d | 2014-08-17 12:49:49 +0200 | [diff] [blame] | 748 | if (meson_ports[pdev->id]) { |
| 749 | dev_err(&pdev->dev, "port %d already allocated\n", pdev->id); |
| 750 | return -EBUSY; |
| 751 | } |
| 752 | |
| 753 | port = devm_kzalloc(&pdev->dev, sizeof(struct uart_port), GFP_KERNEL); |
| 754 | if (!port) |
| 755 | return -ENOMEM; |
| 756 | |
Helmut Klein | 9f60e0e | 2017-06-14 10:29:15 +0200 | [diff] [blame] | 757 | /* Use legacy way until all platforms switch to new bindings */ |
| 758 | if (of_device_is_compatible(pdev->dev.of_node, "amlogic,meson-uart")) |
| 759 | ret = meson_uart_probe_clocks_legacy(pdev, port); |
| 760 | else |
| 761 | ret = meson_uart_probe_clocks(pdev, port); |
Carlo Caione | ff7693d | 2014-08-17 12:49:49 +0200 | [diff] [blame] | 762 | |
Helmut Klein | 9f60e0e | 2017-06-14 10:29:15 +0200 | [diff] [blame] | 763 | if (ret) |
| 764 | return ret; |
| 765 | |
Carlo Caione | ff7693d | 2014-08-17 12:49:49 +0200 | [diff] [blame] | 766 | port->iotype = UPIO_MEM; |
| 767 | port->mapbase = res_mem->start; |
Heiner Kallweit | ff3b9ca | 2017-04-19 22:17:47 +0200 | [diff] [blame] | 768 | port->mapsize = resource_size(res_mem); |
Carlo Caione | ff7693d | 2014-08-17 12:49:49 +0200 | [diff] [blame] | 769 | port->irq = res_irq->start; |
Heiner Kallweit | 1b1ecaa | 2017-04-19 22:17:50 +0200 | [diff] [blame] | 770 | port->flags = UPF_BOOT_AUTOCONF | UPF_LOW_LATENCY; |
Dmitry Safonov | dca3ac8 | 2019-12-13 00:06:20 +0000 | [diff] [blame] | 771 | port->has_sysrq = IS_ENABLED(CONFIG_SERIAL_MESON_CONSOLE); |
Carlo Caione | ff7693d | 2014-08-17 12:49:49 +0200 | [diff] [blame] | 772 | port->dev = &pdev->dev; |
| 773 | port->line = pdev->id; |
| 774 | port->type = PORT_MESON; |
| 775 | port->x_char = 0; |
| 776 | port->ops = &meson_uart_ops; |
Neil Armstrong | 27d44e0 | 2021-05-18 09:58:32 +0200 | [diff] [blame] | 777 | port->fifosize = fifosize; |
Carlo Caione | ff7693d | 2014-08-17 12:49:49 +0200 | [diff] [blame] | 778 | |
| 779 | meson_ports[pdev->id] = port; |
| 780 | platform_set_drvdata(pdev, port); |
| 781 | |
Ben Dooks | 00661dd | 2015-11-18 14:41:12 +0000 | [diff] [blame] | 782 | /* reset port before registering (and possibly registering console) */ |
| 783 | if (meson_uart_request_port(port) >= 0) { |
| 784 | meson_uart_reset(port); |
| 785 | meson_uart_release_port(port); |
| 786 | } |
| 787 | |
Carlo Caione | ff7693d | 2014-08-17 12:49:49 +0200 | [diff] [blame] | 788 | ret = uart_add_one_port(&meson_uart_driver, port); |
| 789 | if (ret) |
| 790 | meson_ports[pdev->id] = NULL; |
| 791 | |
| 792 | return ret; |
| 793 | } |
| 794 | |
| 795 | static int meson_uart_remove(struct platform_device *pdev) |
| 796 | { |
| 797 | struct uart_port *port; |
| 798 | |
| 799 | port = platform_get_drvdata(pdev); |
| 800 | uart_remove_one_port(&meson_uart_driver, port); |
| 801 | meson_ports[pdev->id] = NULL; |
| 802 | |
| 803 | return 0; |
| 804 | } |
| 805 | |
Carlo Caione | ff7693d | 2014-08-17 12:49:49 +0200 | [diff] [blame] | 806 | static const struct of_device_id meson_uart_dt_match[] = { |
Helmut Klein | 9f60e0e | 2017-06-14 10:29:15 +0200 | [diff] [blame] | 807 | /* Legacy bindings, should be removed when no more used */ |
Carlo Caione | ff7693d | 2014-08-17 12:49:49 +0200 | [diff] [blame] | 808 | { .compatible = "amlogic,meson-uart" }, |
Helmut Klein | 9f60e0e | 2017-06-14 10:29:15 +0200 | [diff] [blame] | 809 | /* Stable bindings */ |
| 810 | { .compatible = "amlogic,meson6-uart" }, |
| 811 | { .compatible = "amlogic,meson8-uart" }, |
| 812 | { .compatible = "amlogic,meson8b-uart" }, |
| 813 | { .compatible = "amlogic,meson-gx-uart" }, |
Carlo Caione | ff7693d | 2014-08-17 12:49:49 +0200 | [diff] [blame] | 814 | { /* sentinel */ }, |
| 815 | }; |
| 816 | MODULE_DEVICE_TABLE(of, meson_uart_dt_match); |
| 817 | |
| 818 | static struct platform_driver meson_uart_platform_driver = { |
| 819 | .probe = meson_uart_probe, |
| 820 | .remove = meson_uart_remove, |
| 821 | .driver = { |
Carlo Caione | ff7693d | 2014-08-17 12:49:49 +0200 | [diff] [blame] | 822 | .name = "meson_uart", |
| 823 | .of_match_table = meson_uart_dt_match, |
| 824 | }, |
| 825 | }; |
| 826 | |
| 827 | static int __init meson_uart_init(void) |
| 828 | { |
| 829 | int ret; |
| 830 | |
Kevin Hilman | 87a0b9f | 2020-12-10 16:57:44 -0800 | [diff] [blame] | 831 | ret = meson_serial_console_init(); |
| 832 | if (ret) |
| 833 | return ret; |
| 834 | |
Carlo Caione | ff7693d | 2014-08-17 12:49:49 +0200 | [diff] [blame] | 835 | ret = uart_register_driver(&meson_uart_driver); |
| 836 | if (ret) |
| 837 | return ret; |
| 838 | |
| 839 | ret = platform_driver_register(&meson_uart_platform_driver); |
| 840 | if (ret) |
| 841 | uart_unregister_driver(&meson_uart_driver); |
| 842 | |
| 843 | return ret; |
| 844 | } |
| 845 | |
| 846 | static void __exit meson_uart_exit(void) |
| 847 | { |
| 848 | platform_driver_unregister(&meson_uart_platform_driver); |
| 849 | uart_unregister_driver(&meson_uart_driver); |
| 850 | } |
| 851 | |
| 852 | module_init(meson_uart_init); |
| 853 | module_exit(meson_uart_exit); |
| 854 | |
| 855 | MODULE_AUTHOR("Carlo Caione <carlo@caione.org>"); |
| 856 | MODULE_DESCRIPTION("Amlogic Meson serial port driver"); |
| 857 | MODULE_LICENSE("GPL v2"); |