GNU Linux-libre 4.9.330-gnu1
[releases.git] / drivers / tty / serial / meson_uart.c
1 /*
2  *  Based on meson_uart.c, by AMLOGIC, INC.
3  *
4  * Copyright (C) 2014 Carlo Caione <carlo@caione.org>
5  *
6  * This program is free software; you can redistribute it and/or modify it
7  * under the terms of the GNU General Public License version 2 as published
8  * by the Free Software Foundation.
9  *
10  * This program is distributed in the hope that it will be useful,
11  * but WITHOUT ANY WARRANTY; without even the implied warranty of
12  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
13  * GNU General Public License for more details.
14  *
15  */
16
17 #include <linux/clk.h>
18 #include <linux/console.h>
19 #include <linux/delay.h>
20 #include <linux/init.h>
21 #include <linux/io.h>
22 #include <linux/module.h>
23 #include <linux/kernel.h>
24 #include <linux/of.h>
25 #include <linux/platform_device.h>
26 #include <linux/serial.h>
27 #include <linux/serial_core.h>
28 #include <linux/tty.h>
29 #include <linux/tty_flip.h>
30
31 /* Register offsets */
32 #define AML_UART_WFIFO                  0x00
33 #define AML_UART_RFIFO                  0x04
34 #define AML_UART_CONTROL                0x08
35 #define AML_UART_STATUS                 0x0c
36 #define AML_UART_MISC                   0x10
37 #define AML_UART_REG5                   0x14
38
39 /* AML_UART_CONTROL bits */
40 #define AML_UART_TX_EN                  BIT(12)
41 #define AML_UART_RX_EN                  BIT(13)
42 #define AML_UART_TX_RST                 BIT(22)
43 #define AML_UART_RX_RST                 BIT(23)
44 #define AML_UART_CLR_ERR                BIT(24)
45 #define AML_UART_RX_INT_EN              BIT(27)
46 #define AML_UART_TX_INT_EN              BIT(28)
47 #define AML_UART_DATA_LEN_MASK          (0x03 << 20)
48 #define AML_UART_DATA_LEN_8BIT          (0x00 << 20)
49 #define AML_UART_DATA_LEN_7BIT          (0x01 << 20)
50 #define AML_UART_DATA_LEN_6BIT          (0x02 << 20)
51 #define AML_UART_DATA_LEN_5BIT          (0x03 << 20)
52
53 /* AML_UART_STATUS bits */
54 #define AML_UART_PARITY_ERR             BIT(16)
55 #define AML_UART_FRAME_ERR              BIT(17)
56 #define AML_UART_TX_FIFO_WERR           BIT(18)
57 #define AML_UART_RX_EMPTY               BIT(20)
58 #define AML_UART_TX_FULL                BIT(21)
59 #define AML_UART_TX_EMPTY               BIT(22)
60 #define AML_UART_XMIT_BUSY              BIT(25)
61 #define AML_UART_ERR                    (AML_UART_PARITY_ERR | \
62                                          AML_UART_FRAME_ERR  | \
63                                          AML_UART_TX_FIFO_WERR)
64
65 /* AML_UART_CONTROL bits */
66 #define AML_UART_TWO_WIRE_EN            BIT(15)
67 #define AML_UART_PARITY_TYPE            BIT(18)
68 #define AML_UART_PARITY_EN              BIT(19)
69 #define AML_UART_CLEAR_ERR              BIT(24)
70 #define AML_UART_STOP_BIN_LEN_MASK      (0x03 << 16)
71 #define AML_UART_STOP_BIN_1SB           (0x00 << 16)
72 #define AML_UART_STOP_BIN_2SB           (0x01 << 16)
73
74 /* AML_UART_MISC bits */
75 #define AML_UART_XMIT_IRQ(c)            (((c) & 0xff) << 8)
76 #define AML_UART_RECV_IRQ(c)            ((c) & 0xff)
77
78 /* AML_UART_REG5 bits */
79 #define AML_UART_BAUD_MASK              0x7fffff
80 #define AML_UART_BAUD_USE               BIT(23)
81 #define AML_UART_BAUD_XTAL              BIT(24)
82
83 #define AML_UART_PORT_NUM               6
84 #define AML_UART_DEV_NAME               "ttyAML"
85
86
87 static struct uart_driver meson_uart_driver;
88
89 static struct uart_port *meson_ports[AML_UART_PORT_NUM];
90
91 static void meson_uart_set_mctrl(struct uart_port *port, unsigned int mctrl)
92 {
93 }
94
95 static unsigned int meson_uart_get_mctrl(struct uart_port *port)
96 {
97         return TIOCM_CTS;
98 }
99
100 static unsigned int meson_uart_tx_empty(struct uart_port *port)
101 {
102         u32 val;
103
104         val = readl(port->membase + AML_UART_STATUS);
105         val &= (AML_UART_TX_EMPTY | AML_UART_XMIT_BUSY);
106         return (val == AML_UART_TX_EMPTY) ? TIOCSER_TEMT : 0;
107 }
108
109 static void meson_uart_stop_tx(struct uart_port *port)
110 {
111         u32 val;
112
113         val = readl(port->membase + AML_UART_CONTROL);
114         val &= ~AML_UART_TX_INT_EN;
115         writel(val, port->membase + AML_UART_CONTROL);
116 }
117
118 static void meson_uart_stop_rx(struct uart_port *port)
119 {
120         u32 val;
121
122         val = readl(port->membase + AML_UART_CONTROL);
123         val &= ~AML_UART_RX_EN;
124         writel(val, port->membase + AML_UART_CONTROL);
125 }
126
127 static void meson_uart_shutdown(struct uart_port *port)
128 {
129         unsigned long flags;
130         u32 val;
131
132         free_irq(port->irq, port);
133
134         spin_lock_irqsave(&port->lock, flags);
135
136         val = readl(port->membase + AML_UART_CONTROL);
137         val &= ~AML_UART_RX_EN;
138         val &= ~(AML_UART_RX_INT_EN | AML_UART_TX_INT_EN);
139         writel(val, port->membase + AML_UART_CONTROL);
140
141         spin_unlock_irqrestore(&port->lock, flags);
142 }
143
144 static void meson_uart_start_tx(struct uart_port *port)
145 {
146         struct circ_buf *xmit = &port->state->xmit;
147         unsigned int ch;
148         u32 val;
149
150         if (uart_tx_stopped(port)) {
151                 meson_uart_stop_tx(port);
152                 return;
153         }
154
155         while (!(readl(port->membase + AML_UART_STATUS) & AML_UART_TX_FULL)) {
156                 if (port->x_char) {
157                         writel(port->x_char, port->membase + AML_UART_WFIFO);
158                         port->icount.tx++;
159                         port->x_char = 0;
160                         continue;
161                 }
162
163                 if (uart_circ_empty(xmit))
164                         break;
165
166                 ch = xmit->buf[xmit->tail];
167                 writel(ch, port->membase + AML_UART_WFIFO);
168                 xmit->tail = (xmit->tail+1) & (SERIAL_XMIT_SIZE - 1);
169                 port->icount.tx++;
170         }
171
172         if (!uart_circ_empty(xmit)) {
173                 val = readl(port->membase + AML_UART_CONTROL);
174                 val |= AML_UART_TX_INT_EN;
175                 writel(val, port->membase + AML_UART_CONTROL);
176         }
177
178         if (uart_circ_chars_pending(xmit) < WAKEUP_CHARS)
179                 uart_write_wakeup(port);
180 }
181
182 static void meson_receive_chars(struct uart_port *port)
183 {
184         struct tty_port *tport = &port->state->port;
185         char flag;
186         u32 status, ch, mode;
187
188         do {
189                 flag = TTY_NORMAL;
190                 port->icount.rx++;
191                 status = readl(port->membase + AML_UART_STATUS);
192
193                 if (status & AML_UART_ERR) {
194                         if (status & AML_UART_TX_FIFO_WERR)
195                                 port->icount.overrun++;
196                         else if (status & AML_UART_FRAME_ERR)
197                                 port->icount.frame++;
198                         else if (status & AML_UART_PARITY_ERR)
199                                 port->icount.frame++;
200
201                         mode = readl(port->membase + AML_UART_CONTROL);
202                         mode |= AML_UART_CLEAR_ERR;
203                         writel(mode, port->membase + AML_UART_CONTROL);
204
205                         /* It doesn't clear to 0 automatically */
206                         mode &= ~AML_UART_CLEAR_ERR;
207                         writel(mode, port->membase + AML_UART_CONTROL);
208
209                         status &= port->read_status_mask;
210                         if (status & AML_UART_FRAME_ERR)
211                                 flag = TTY_FRAME;
212                         else if (status & AML_UART_PARITY_ERR)
213                                 flag = TTY_PARITY;
214                 }
215
216                 ch = readl(port->membase + AML_UART_RFIFO);
217                 ch &= 0xff;
218
219                 if ((status & port->ignore_status_mask) == 0)
220                         tty_insert_flip_char(tport, ch, flag);
221
222                 if (status & AML_UART_TX_FIFO_WERR)
223                         tty_insert_flip_char(tport, 0, TTY_OVERRUN);
224
225         } while (!(readl(port->membase + AML_UART_STATUS) & AML_UART_RX_EMPTY));
226
227         spin_unlock(&port->lock);
228         tty_flip_buffer_push(tport);
229         spin_lock(&port->lock);
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
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         }
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
256 /*
257  * This function is called only from probe() using a temporary io mapping
258  * in order to perform a reset before setting up the device. Since the
259  * temporarily mapped region was successfully requested, there can be no
260  * console on this port at this time. Hence it is not necessary for this
261  * function to acquire the port->lock. (Since there is no console on this
262  * port at this time, the port->lock is not initialized yet.)
263  */
264 static void meson_uart_reset(struct uart_port *port)
265 {
266         u32 val;
267
268         val = readl(port->membase + AML_UART_CONTROL);
269         val |= (AML_UART_RX_RST | AML_UART_TX_RST | AML_UART_CLR_ERR);
270         writel(val, port->membase + AML_UART_CONTROL);
271
272         val &= ~(AML_UART_RX_RST | AML_UART_TX_RST | AML_UART_CLR_ERR);
273         writel(val, port->membase + AML_UART_CONTROL);
274 }
275
276 static int meson_uart_startup(struct uart_port *port)
277 {
278         unsigned long flags;
279         u32 val;
280         int ret = 0;
281
282         spin_lock_irqsave(&port->lock, flags);
283
284         val = readl(port->membase + AML_UART_CONTROL);
285         val |= AML_UART_CLR_ERR;
286         writel(val, port->membase + AML_UART_CONTROL);
287         val &= ~AML_UART_CLR_ERR;
288         writel(val, port->membase + AML_UART_CONTROL);
289
290         val |= (AML_UART_RX_EN | AML_UART_TX_EN);
291         writel(val, port->membase + AML_UART_CONTROL);
292
293         val |= (AML_UART_RX_INT_EN | AML_UART_TX_INT_EN);
294         writel(val, port->membase + AML_UART_CONTROL);
295
296         val = (AML_UART_RECV_IRQ(1) | AML_UART_XMIT_IRQ(port->fifosize / 2));
297         writel(val, port->membase + AML_UART_MISC);
298
299         spin_unlock_irqrestore(&port->lock, flags);
300
301         ret = request_irq(port->irq, meson_uart_interrupt, 0,
302                           meson_uart_type(port), port);
303
304         return ret;
305 }
306
307 static void meson_uart_change_speed(struct uart_port *port, unsigned long baud)
308 {
309         u32 val;
310
311         while (!meson_uart_tx_empty(port))
312                 cpu_relax();
313
314         val = readl(port->membase + AML_UART_REG5);
315         val &= ~AML_UART_BAUD_MASK;
316         if (port->uartclk == 24000000) {
317                 val = ((port->uartclk / 3) / baud) - 1;
318                 val |= AML_UART_BAUD_XTAL;
319         } else {
320                 val = ((port->uartclk * 10 / (baud * 4) + 5) / 10) - 1;
321         }
322         val |= AML_UART_BAUD_USE;
323         writel(val, port->membase + AML_UART_REG5);
324 }
325
326 static void meson_uart_set_termios(struct uart_port *port,
327                                    struct ktermios *termios,
328                                    struct ktermios *old)
329 {
330         unsigned int cflags, iflags, baud;
331         unsigned long flags;
332         u32 val;
333
334         spin_lock_irqsave(&port->lock, flags);
335
336         cflags = termios->c_cflag;
337         iflags = termios->c_iflag;
338
339         val = readl(port->membase + AML_UART_CONTROL);
340
341         val &= ~AML_UART_DATA_LEN_MASK;
342         switch (cflags & CSIZE) {
343         case CS8:
344                 val |= AML_UART_DATA_LEN_8BIT;
345                 break;
346         case CS7:
347                 val |= AML_UART_DATA_LEN_7BIT;
348                 break;
349         case CS6:
350                 val |= AML_UART_DATA_LEN_6BIT;
351                 break;
352         case CS5:
353                 val |= AML_UART_DATA_LEN_5BIT;
354                 break;
355         }
356
357         if (cflags & PARENB)
358                 val |= AML_UART_PARITY_EN;
359         else
360                 val &= ~AML_UART_PARITY_EN;
361
362         if (cflags & PARODD)
363                 val |= AML_UART_PARITY_TYPE;
364         else
365                 val &= ~AML_UART_PARITY_TYPE;
366
367         val &= ~AML_UART_STOP_BIN_LEN_MASK;
368         if (cflags & CSTOPB)
369                 val |= AML_UART_STOP_BIN_2SB;
370         else
371                 val &= ~AML_UART_STOP_BIN_1SB;
372
373         if (cflags & CRTSCTS)
374                 val &= ~AML_UART_TWO_WIRE_EN;
375         else
376                 val |= AML_UART_TWO_WIRE_EN;
377
378         writel(val, port->membase + AML_UART_CONTROL);
379
380         baud = uart_get_baud_rate(port, termios, old, 9600, 115200);
381         meson_uart_change_speed(port, baud);
382
383         port->read_status_mask = AML_UART_TX_FIFO_WERR;
384         if (iflags & INPCK)
385                 port->read_status_mask |= AML_UART_PARITY_ERR |
386                                           AML_UART_FRAME_ERR;
387
388         port->ignore_status_mask = 0;
389         if (iflags & IGNPAR)
390                 port->ignore_status_mask |= AML_UART_PARITY_ERR |
391                                             AML_UART_FRAME_ERR;
392
393         uart_update_timeout(port, termios->c_cflag, baud);
394         spin_unlock_irqrestore(&port->lock, flags);
395 }
396
397 static int meson_uart_verify_port(struct uart_port *port,
398                                   struct serial_struct *ser)
399 {
400         int ret = 0;
401
402         if (port->type != PORT_MESON)
403                 ret = -EINVAL;
404         if (port->irq != ser->irq)
405                 ret = -EINVAL;
406         if (ser->baud_base < 9600)
407                 ret = -EINVAL;
408         return ret;
409 }
410
411 static int meson_uart_res_size(struct uart_port *port)
412 {
413         struct platform_device *pdev = to_platform_device(port->dev);
414         struct resource *res;
415
416         res = platform_get_resource(pdev, IORESOURCE_MEM, 0);
417         if (!res) {
418                 dev_err(port->dev, "cannot obtain I/O memory region");
419                 return -ENODEV;
420         }
421
422         return resource_size(res);
423 }
424
425 static void meson_uart_release_port(struct uart_port *port)
426 {
427         int size = meson_uart_res_size(port);
428
429         if (port->flags & UPF_IOREMAP) {
430                 devm_release_mem_region(port->dev, port->mapbase, size);
431                 devm_iounmap(port->dev, port->membase);
432                 port->membase = NULL;
433         }
434 }
435
436 static int meson_uart_request_port(struct uart_port *port)
437 {
438         int size = meson_uart_res_size(port);
439
440         if (size < 0)
441                 return size;
442
443         if (!devm_request_mem_region(port->dev, port->mapbase, size,
444                                      dev_name(port->dev))) {
445                 dev_err(port->dev, "Memory region busy\n");
446                 return -EBUSY;
447         }
448
449         if (port->flags & UPF_IOREMAP) {
450                 port->membase = devm_ioremap_nocache(port->dev,
451                                                      port->mapbase,
452                                                      size);
453                 if (port->membase == NULL)
454                         return -ENOMEM;
455         }
456
457         return 0;
458 }
459
460 static void meson_uart_config_port(struct uart_port *port, int flags)
461 {
462         if (flags & UART_CONFIG_TYPE) {
463                 port->type = PORT_MESON;
464                 meson_uart_request_port(port);
465         }
466 }
467
468 static struct uart_ops meson_uart_ops = {
469         .set_mctrl      = meson_uart_set_mctrl,
470         .get_mctrl      = meson_uart_get_mctrl,
471         .tx_empty       = meson_uart_tx_empty,
472         .start_tx       = meson_uart_start_tx,
473         .stop_tx        = meson_uart_stop_tx,
474         .stop_rx        = meson_uart_stop_rx,
475         .startup        = meson_uart_startup,
476         .shutdown       = meson_uart_shutdown,
477         .set_termios    = meson_uart_set_termios,
478         .type           = meson_uart_type,
479         .config_port    = meson_uart_config_port,
480         .request_port   = meson_uart_request_port,
481         .release_port   = meson_uart_release_port,
482         .verify_port    = meson_uart_verify_port,
483 };
484
485 #ifdef CONFIG_SERIAL_MESON_CONSOLE
486
487 static void meson_console_putchar(struct uart_port *port, int ch)
488 {
489         if (!port->membase)
490                 return;
491
492         while (readl(port->membase + AML_UART_STATUS) & AML_UART_TX_FULL)
493                 cpu_relax();
494         writel(ch, port->membase + AML_UART_WFIFO);
495 }
496
497 static void meson_serial_port_write(struct uart_port *port, const char *s,
498                                     u_int count)
499 {
500         unsigned long flags;
501         int locked;
502         u32 val, tmp;
503
504         local_irq_save(flags);
505         if (port->sysrq) {
506                 locked = 0;
507         } else if (oops_in_progress) {
508                 locked = spin_trylock(&port->lock);
509         } else {
510                 spin_lock(&port->lock);
511                 locked = 1;
512         }
513
514         val = readl(port->membase + AML_UART_CONTROL);
515         val |= AML_UART_TX_EN;
516         tmp = val & ~(AML_UART_TX_INT_EN | AML_UART_RX_INT_EN);
517         writel(tmp, port->membase + AML_UART_CONTROL);
518
519         uart_console_write(port, s, count, meson_console_putchar);
520         writel(val, port->membase + AML_UART_CONTROL);
521
522         if (locked)
523                 spin_unlock(&port->lock);
524         local_irq_restore(flags);
525 }
526
527 static void meson_serial_console_write(struct console *co, const char *s,
528                                        u_int count)
529 {
530         struct uart_port *port;
531
532         port = meson_ports[co->index];
533         if (!port)
534                 return;
535
536         meson_serial_port_write(port, s, count);
537 }
538
539 static int meson_serial_console_setup(struct console *co, char *options)
540 {
541         struct uart_port *port;
542         int baud = 115200;
543         int bits = 8;
544         int parity = 'n';
545         int flow = 'n';
546
547         if (co->index < 0 || co->index >= AML_UART_PORT_NUM)
548                 return -EINVAL;
549
550         port = meson_ports[co->index];
551         if (!port || !port->membase)
552                 return -ENODEV;
553
554         if (options)
555                 uart_parse_options(options, &baud, &parity, &bits, &flow);
556
557         return uart_set_options(port, co, baud, parity, bits, flow);
558 }
559
560 static struct console meson_serial_console = {
561         .name           = AML_UART_DEV_NAME,
562         .write          = meson_serial_console_write,
563         .device         = uart_console_device,
564         .setup          = meson_serial_console_setup,
565         .flags          = CON_PRINTBUFFER,
566         .index          = -1,
567         .data           = &meson_uart_driver,
568 };
569
570 static int __init meson_serial_console_init(void)
571 {
572         register_console(&meson_serial_console);
573         return 0;
574 }
575 console_initcall(meson_serial_console_init);
576
577 static void meson_serial_early_console_write(struct console *co,
578                                              const char *s,
579                                              u_int count)
580 {
581         struct earlycon_device *dev = co->data;
582
583         meson_serial_port_write(&dev->port, s, count);
584 }
585
586 static int __init
587 meson_serial_early_console_setup(struct earlycon_device *device, const char *opt)
588 {
589         if (!device->port.membase)
590                 return -ENODEV;
591
592         device->con->write = meson_serial_early_console_write;
593         return 0;
594 }
595 OF_EARLYCON_DECLARE(meson, "amlogic,meson-uart",
596                     meson_serial_early_console_setup);
597
598 #define MESON_SERIAL_CONSOLE    (&meson_serial_console)
599 #else
600 #define MESON_SERIAL_CONSOLE    NULL
601 #endif
602
603 static struct uart_driver meson_uart_driver = {
604         .owner          = THIS_MODULE,
605         .driver_name    = "meson_uart",
606         .dev_name       = AML_UART_DEV_NAME,
607         .nr             = AML_UART_PORT_NUM,
608         .cons           = MESON_SERIAL_CONSOLE,
609 };
610
611 static int meson_uart_probe(struct platform_device *pdev)
612 {
613         struct resource *res_mem, *res_irq;
614         struct uart_port *port;
615         struct clk *clk;
616         int ret = 0;
617
618         if (pdev->dev.of_node)
619                 pdev->id = of_alias_get_id(pdev->dev.of_node, "serial");
620
621         if (pdev->id < 0 || pdev->id >= AML_UART_PORT_NUM)
622                 return -EINVAL;
623
624         res_mem = platform_get_resource(pdev, IORESOURCE_MEM, 0);
625         if (!res_mem)
626                 return -ENODEV;
627
628         res_irq = platform_get_resource(pdev, IORESOURCE_IRQ, 0);
629         if (!res_irq)
630                 return -ENODEV;
631
632         if (meson_ports[pdev->id]) {
633                 dev_err(&pdev->dev, "port %d already allocated\n", pdev->id);
634                 return -EBUSY;
635         }
636
637         port = devm_kzalloc(&pdev->dev, sizeof(struct uart_port), GFP_KERNEL);
638         if (!port)
639                 return -ENOMEM;
640
641         clk = clk_get(&pdev->dev, NULL);
642         if (IS_ERR(clk))
643                 return PTR_ERR(clk);
644
645         port->uartclk = clk_get_rate(clk);
646         port->iotype = UPIO_MEM;
647         port->mapbase = res_mem->start;
648         port->irq = res_irq->start;
649         port->flags = UPF_BOOT_AUTOCONF | UPF_IOREMAP | UPF_LOW_LATENCY;
650         port->dev = &pdev->dev;
651         port->line = pdev->id;
652         port->type = PORT_MESON;
653         port->x_char = 0;
654         port->ops = &meson_uart_ops;
655         port->fifosize = 64;
656
657         meson_ports[pdev->id] = port;
658         platform_set_drvdata(pdev, port);
659
660         /* reset port before registering (and possibly registering console) */
661         if (meson_uart_request_port(port) >= 0) {
662                 meson_uart_reset(port);
663                 meson_uart_release_port(port);
664         }
665
666         ret = uart_add_one_port(&meson_uart_driver, port);
667         if (ret)
668                 meson_ports[pdev->id] = NULL;
669
670         return ret;
671 }
672
673 static int meson_uart_remove(struct platform_device *pdev)
674 {
675         struct uart_port *port;
676
677         port = platform_get_drvdata(pdev);
678         uart_remove_one_port(&meson_uart_driver, port);
679         meson_ports[pdev->id] = NULL;
680
681         return 0;
682 }
683
684
685 static const struct of_device_id meson_uart_dt_match[] = {
686         { .compatible = "amlogic,meson-uart" },
687         { /* sentinel */ },
688 };
689 MODULE_DEVICE_TABLE(of, meson_uart_dt_match);
690
691 static  struct platform_driver meson_uart_platform_driver = {
692         .probe          = meson_uart_probe,
693         .remove         = meson_uart_remove,
694         .driver         = {
695                 .name           = "meson_uart",
696                 .of_match_table = meson_uart_dt_match,
697         },
698 };
699
700 static int __init meson_uart_init(void)
701 {
702         int ret;
703
704         ret = uart_register_driver(&meson_uart_driver);
705         if (ret)
706                 return ret;
707
708         ret = platform_driver_register(&meson_uart_platform_driver);
709         if (ret)
710                 uart_unregister_driver(&meson_uart_driver);
711
712         return ret;
713 }
714
715 static void __exit meson_uart_exit(void)
716 {
717         platform_driver_unregister(&meson_uart_platform_driver);
718         uart_unregister_driver(&meson_uart_driver);
719 }
720
721 module_init(meson_uart_init);
722 module_exit(meson_uart_exit);
723
724 MODULE_AUTHOR("Carlo Caione <carlo@caione.org>");
725 MODULE_DESCRIPTION("Amlogic Meson serial port driver");
726 MODULE_LICENSE("GPL v2");