b58544de4e8620b9525b2ffcb977034f37faa89b
[firefly-linux-kernel-4.4.55.git] / drivers / tty / serial / arc_uart.c
1 /*
2  * ARC On-Chip(fpga) UART Driver
3  *
4  * Copyright (C) 2010-2012 Synopsys, Inc. (www.synopsys.com)
5  *
6  * This program is free software; you can redistribute it and/or modify
7  * it under the terms of the GNU General Public License version 2 as
8  * published by the Free Software Foundation.
9  *
10  * vineetg: July 10th 2012
11  *  -Decoupled the driver from arch/arc
12  *    +Using platform_get_resource() for irq/membase (thx to bfin_uart.c)
13  *    +Using early_platform_xxx() for early console (thx to mach-shmobile/xxx)
14  *
15  * Vineetg: Aug 21st 2010
16  *  -Is uart_tx_stopped() not done in tty write path as it has already been
17  *   taken care of, in serial core
18  *
19  * Vineetg: Aug 18th 2010
20  *  -New Serial Core based ARC UART driver
21  *  -Derived largely from blackfin driver albiet with some major tweaks
22  *
23  * TODO:
24  *  -check if sysreq works
25  */
26
27 #if defined(CONFIG_SERIAL_ARC_CONSOLE) && defined(CONFIG_MAGIC_SYSRQ)
28 #define SUPPORT_SYSRQ
29 #endif
30
31 #include <linux/module.h>
32 #include <linux/serial.h>
33 #include <linux/console.h>
34 #include <linux/sysrq.h>
35 #include <linux/platform_device.h>
36 #include <linux/tty.h>
37 #include <linux/tty_flip.h>
38 #include <linux/serial_core.h>
39 #include <linux/io.h>
40 #include <linux/of.h>
41 #include <linux/of_platform.h>
42
43 /*************************************
44  * ARC UART Hardware Specs
45  ************************************/
46 #define ARC_UART_TX_FIFO_SIZE  1
47
48 /*
49  * UART Register set (this is not a Standards Compliant IP)
50  * Also each reg is Word aligned, but only 8 bits wide
51  */
52 #define R_ID0   0
53 #define R_ID1   4
54 #define R_ID2   8
55 #define R_ID3   12
56 #define R_DATA  16
57 #define R_STS   20
58 #define R_BAUDL 24
59 #define R_BAUDH 28
60
61 /* Bits for UART Status Reg (R/W) */
62 #define RXIENB  0x04    /* Receive Interrupt Enable */
63 #define TXIENB  0x40    /* Transmit Interrupt Enable */
64
65 #define RXEMPTY 0x20    /* Receive FIFO Empty: No char receivede */
66 #define TXEMPTY 0x80    /* Transmit FIFO Empty, thus char can be written into */
67
68 #define RXFULL  0x08    /* Receive FIFO full */
69 #define RXFULL1 0x10    /* Receive FIFO has space for 1 char (tot space=4) */
70
71 #define RXFERR  0x01    /* Frame Error: Stop Bit not detected */
72 #define RXOERR  0x02    /* OverFlow Err: Char recv but RXFULL still set */
73
74 /* Uart bit fiddling helpers: lowest level */
75 #define RBASE(port, reg)      (port->membase + reg)
76 #define UART_REG_SET(u, r, v) writeb((v), RBASE(u, r))
77 #define UART_REG_GET(u, r)    readb(RBASE(u, r))
78
79 #define UART_REG_OR(u, r, v)  UART_REG_SET(u, r, UART_REG_GET(u, r) | (v))
80 #define UART_REG_CLR(u, r, v) UART_REG_SET(u, r, UART_REG_GET(u, r) & ~(v))
81
82 /* Uart bit fiddling helpers: API level */
83 #define UART_SET_DATA(uart, val)   UART_REG_SET(uart, R_DATA, val)
84 #define UART_GET_DATA(uart)        UART_REG_GET(uart, R_DATA)
85
86 #define UART_SET_BAUDH(uart, val)  UART_REG_SET(uart, R_BAUDH, val)
87 #define UART_SET_BAUDL(uart, val)  UART_REG_SET(uart, R_BAUDL, val)
88
89 #define UART_CLR_STATUS(uart, val) UART_REG_CLR(uart, R_STS, val)
90 #define UART_GET_STATUS(uart)      UART_REG_GET(uart, R_STS)
91
92 #define UART_ALL_IRQ_DISABLE(uart) UART_REG_CLR(uart, R_STS, RXIENB|TXIENB)
93 #define UART_RX_IRQ_DISABLE(uart)  UART_REG_CLR(uart, R_STS, RXIENB)
94 #define UART_TX_IRQ_DISABLE(uart)  UART_REG_CLR(uart, R_STS, TXIENB)
95
96 #define UART_ALL_IRQ_ENABLE(uart)  UART_REG_OR(uart, R_STS, RXIENB|TXIENB)
97 #define UART_RX_IRQ_ENABLE(uart)   UART_REG_OR(uart, R_STS, RXIENB)
98 #define UART_TX_IRQ_ENABLE(uart)   UART_REG_OR(uart, R_STS, TXIENB)
99
100 #define ARC_SERIAL_DEV_NAME     "ttyARC"
101
102 struct arc_uart_port {
103         struct uart_port port;
104         unsigned long baud;
105         int is_emulated;        /* H/w vs. Instruction Set Simulator */
106 };
107
108 #define to_arc_port(uport)  container_of(uport, struct arc_uart_port, port)
109
110 static struct arc_uart_port arc_uart_ports[CONFIG_SERIAL_ARC_NR_PORTS];
111
112 #ifdef CONFIG_SERIAL_ARC_CONSOLE
113 static struct console arc_console;
114 #endif
115
116 #define DRIVER_NAME     "arc-uart"
117
118 static struct uart_driver arc_uart_driver = {
119         .owner          = THIS_MODULE,
120         .driver_name    = DRIVER_NAME,
121         .dev_name       = ARC_SERIAL_DEV_NAME,
122         .major          = 0,
123         .minor          = 0,
124         .nr             = CONFIG_SERIAL_ARC_NR_PORTS,
125 #ifdef CONFIG_SERIAL_ARC_CONSOLE
126         .cons           = &arc_console,
127 #endif
128 };
129
130 static void arc_serial_stop_rx(struct uart_port *port)
131 {
132         UART_RX_IRQ_DISABLE(port);
133 }
134
135 static void arc_serial_stop_tx(struct uart_port *port)
136 {
137         while (!(UART_GET_STATUS(port) & TXEMPTY))
138                 cpu_relax();
139
140         UART_TX_IRQ_DISABLE(port);
141 }
142
143 /*
144  * Return TIOCSER_TEMT when transmitter is not busy.
145  */
146 static unsigned int arc_serial_tx_empty(struct uart_port *port)
147 {
148         unsigned int stat;
149
150         stat = UART_GET_STATUS(port);
151         if (stat & TXEMPTY)
152                 return TIOCSER_TEMT;
153
154         return 0;
155 }
156
157 /*
158  * Driver internal routine, used by both tty(serial core) as well as tx-isr
159  *  -Called under spinlock in either cases
160  *  -also tty->stopped has already been checked
161  *     = by uart_start( ) before calling us
162  *     = tx_ist checks that too before calling
163  */
164 static void arc_serial_tx_chars(struct uart_port *port)
165 {
166         struct circ_buf *xmit = &port->state->xmit;
167         int sent = 0;
168         unsigned char ch;
169
170         if (unlikely(port->x_char)) {
171                 UART_SET_DATA(port, port->x_char);
172                 port->icount.tx++;
173                 port->x_char = 0;
174                 sent = 1;
175         } else if (xmit->tail != xmit->head) {  /* TODO: uart_circ_empty */
176                 ch = xmit->buf[xmit->tail];
177                 xmit->tail = (xmit->tail + 1) & (UART_XMIT_SIZE - 1);
178                 port->icount.tx++;
179                 while (!(UART_GET_STATUS(port) & TXEMPTY))
180                         cpu_relax();
181                 UART_SET_DATA(port, ch);
182                 sent = 1;
183         }
184
185         /*
186          * If num chars in xmit buffer are too few, ask tty layer for more.
187          * By Hard ISR to schedule processing in software interrupt part
188          */
189         if (uart_circ_chars_pending(xmit) < WAKEUP_CHARS)
190                 uart_write_wakeup(port);
191
192         if (sent)
193                 UART_TX_IRQ_ENABLE(port);
194 }
195
196 /*
197  * port is locked and interrupts are disabled
198  * uart_start( ) calls us under the port spinlock irqsave
199  */
200 static void arc_serial_start_tx(struct uart_port *port)
201 {
202         arc_serial_tx_chars(port);
203 }
204
205 static void arc_serial_rx_chars(struct uart_port *port, unsigned int status)
206 {
207         unsigned int ch, flg = 0;
208
209         /*
210          * UART has 4 deep RX-FIFO. Driver's recongnition of this fact
211          * is very subtle. Here's how ...
212          * Upon getting a RX-Intr, such that RX-EMPTY=0, meaning data available,
213          * driver reads the DATA Reg and keeps doing that in a loop, until
214          * RX-EMPTY=1. Multiple chars being avail, with a single Interrupt,
215          * before RX-EMPTY=0, implies some sort of buffering going on in the
216          * controller, which is indeed the Rx-FIFO.
217          */
218         do {
219                 /*
220                  * This could be an Rx Intr for err (no data),
221                  * so check err and clear that Intr first
222                  */
223                 if (unlikely(status & (RXOERR | RXFERR))) {
224                         if (status & RXOERR) {
225                                 port->icount.overrun++;
226                                 flg = TTY_OVERRUN;
227                                 UART_CLR_STATUS(port, RXOERR);
228                         }
229
230                         if (status & RXFERR) {
231                                 port->icount.frame++;
232                                 flg = TTY_FRAME;
233                                 UART_CLR_STATUS(port, RXFERR);
234                         }
235                 } else
236                         flg = TTY_NORMAL;
237
238                 if (status & RXEMPTY)
239                         continue;
240
241                 ch = UART_GET_DATA(port);
242                 port->icount.rx++;
243
244                 if (!(uart_handle_sysrq_char(port, ch)))
245                         uart_insert_char(port, status, RXOERR, ch, flg);
246
247                 spin_unlock(&port->lock);
248                 tty_flip_buffer_push(&port->state->port);
249                 spin_lock(&port->lock);
250         } while (!((status = UART_GET_STATUS(port)) & RXEMPTY));
251 }
252
253 /*
254  * A note on the Interrupt handling state machine of this driver
255  *
256  * kernel printk writes funnel thru the console driver framework and in order
257  * to keep things simple as well as efficient, it writes to UART in polled
258  * mode, in one shot, and exits.
259  *
260  * OTOH, Userland output (via tty layer), uses interrupt based writes as there
261  * can be undeterministic delay between char writes.
262  *
263  * Thus Rx-interrupts are always enabled, while tx-interrupts are by default
264  * disabled.
265  *
266  * When tty has some data to send out, serial core calls driver's start_tx
267  * which
268  *   -checks-if-tty-buffer-has-char-to-send
269  *   -writes-data-to-uart
270  *   -enable-tx-intr
271  *
272  * Once data bits are pushed out, controller raises the Tx-room-avail-Interrupt.
273  * The first thing Tx ISR does is disable further Tx interrupts (as this could
274  * be the last char to send, before settling down into the quiet polled mode).
275  * It then calls the exact routine used by tty layer write to send out any
276  * more char in tty buffer. In case of sending, it re-enables Tx-intr. In case
277  * of no data, it remains disabled.
278  * This is how the transmit state machine is dynamically switched on/off
279  */
280
281 static irqreturn_t arc_serial_isr(int irq, void *dev_id)
282 {
283         struct uart_port *port = dev_id;
284         unsigned int status;
285
286         status = UART_GET_STATUS(port);
287
288         /*
289          * Single IRQ for both Rx (data available) Tx (room available) Interrupt
290          * notifications from the UART Controller.
291          * To demultiplex between the two, we check the relevant bits
292          */
293         if (status & RXIENB) {
294
295                 /* already in ISR, no need of xx_irqsave */
296                 spin_lock(&port->lock);
297                 arc_serial_rx_chars(port, status);
298                 spin_unlock(&port->lock);
299         }
300
301         if ((status & TXIENB) && (status & TXEMPTY)) {
302
303                 /* Unconditionally disable further Tx-Interrupts.
304                  * will be enabled by tx_chars() if needed.
305                  */
306                 UART_TX_IRQ_DISABLE(port);
307
308                 spin_lock(&port->lock);
309
310                 if (!uart_tx_stopped(port))
311                         arc_serial_tx_chars(port);
312
313                 spin_unlock(&port->lock);
314         }
315
316         return IRQ_HANDLED;
317 }
318
319 static unsigned int arc_serial_get_mctrl(struct uart_port *port)
320 {
321         /*
322          * Pretend we have a Modem status reg and following bits are
323          *  always set, to satify the serial core state machine
324          *  (DSR) Data Set Ready
325          *  (CTS) Clear To Send
326          *  (CAR) Carrier Detect
327          */
328         return TIOCM_CTS | TIOCM_DSR | TIOCM_CAR;
329 }
330
331 static void arc_serial_set_mctrl(struct uart_port *port, unsigned int mctrl)
332 {
333         /* MCR not present */
334 }
335
336 static void arc_serial_break_ctl(struct uart_port *port, int break_state)
337 {
338         /* ARC UART doesn't support sending Break signal */
339 }
340
341 static int arc_serial_startup(struct uart_port *port)
342 {
343         /* Before we hook up the ISR, Disable all UART Interrupts */
344         UART_ALL_IRQ_DISABLE(port);
345
346         if (request_irq(port->irq, arc_serial_isr, 0, "arc uart rx-tx", port)) {
347                 dev_warn(port->dev, "Unable to attach ARC UART intr\n");
348                 return -EBUSY;
349         }
350
351         UART_RX_IRQ_ENABLE(port); /* Only Rx IRQ enabled to begin with */
352
353         return 0;
354 }
355
356 /* This is not really needed */
357 static void arc_serial_shutdown(struct uart_port *port)
358 {
359         free_irq(port->irq, port);
360 }
361
362 static void
363 arc_serial_set_termios(struct uart_port *port, struct ktermios *new,
364                        struct ktermios *old)
365 {
366         struct arc_uart_port *uart = to_arc_port(port);
367         unsigned int baud, uartl, uarth, hw_val;
368         unsigned long flags;
369
370         /*
371          * Use the generic handler so that any specially encoded baud rates
372          * such as SPD_xx flags or "%B0" can be handled
373          * Max Baud I suppose will not be more than current 115K * 4
374          * Formula for ARC UART is: hw-val = ((CLK/(BAUD*4)) -1)
375          * spread over two 8-bit registers
376          */
377         baud = uart_get_baud_rate(port, new, old, 0, 460800);
378
379         hw_val = port->uartclk / (uart->baud * 4) - 1;
380         uartl = hw_val & 0xFF;
381         uarth = (hw_val >> 8) & 0xFF;
382
383         /*
384          * UART ISS(Instruction Set simulator) emulation has a subtle bug:
385          * A existing value of Baudh = 0 is used as a indication to startup
386          * it's internal state machine.
387          * Thus if baudh is set to 0, 2 times, it chokes.
388          * This happens with BAUD=115200 and the formaula above
389          * Until that is fixed, when running on ISS, we will set baudh to !0
390          */
391         if (uart->is_emulated)
392                 uarth = 1;
393
394         spin_lock_irqsave(&port->lock, flags);
395
396         UART_ALL_IRQ_DISABLE(port);
397
398         UART_SET_BAUDL(port, uartl);
399         UART_SET_BAUDH(port, uarth);
400
401         UART_RX_IRQ_ENABLE(port);
402
403         /*
404          * UART doesn't support Parity/Hardware Flow Control;
405          * Only supports 8N1 character size
406          */
407         new->c_cflag &= ~(CMSPAR|CRTSCTS|CSIZE);
408         new->c_cflag |= CS8;
409
410         if (old)
411                 tty_termios_copy_hw(new, old);
412
413         /* Don't rewrite B0 */
414         if (tty_termios_baud_rate(new))
415                 tty_termios_encode_baud_rate(new, baud, baud);
416
417         uart_update_timeout(port, new->c_cflag, baud);
418
419         spin_unlock_irqrestore(&port->lock, flags);
420 }
421
422 static const char *arc_serial_type(struct uart_port *port)
423 {
424         return port->type == PORT_ARC ? DRIVER_NAME : NULL;
425 }
426
427 static void arc_serial_release_port(struct uart_port *port)
428 {
429 }
430
431 static int arc_serial_request_port(struct uart_port *port)
432 {
433         return 0;
434 }
435
436 /*
437  * Verify the new serial_struct (for TIOCSSERIAL).
438  */
439 static int
440 arc_serial_verify_port(struct uart_port *port, struct serial_struct *ser)
441 {
442         if (port->type != PORT_UNKNOWN && ser->type != PORT_ARC)
443                 return -EINVAL;
444
445         return 0;
446 }
447
448 /*
449  * Configure/autoconfigure the port.
450  */
451 static void arc_serial_config_port(struct uart_port *port, int flags)
452 {
453         if (flags & UART_CONFIG_TYPE)
454                 port->type = PORT_ARC;
455 }
456
457 #if defined(CONFIG_CONSOLE_POLL) || defined(CONFIG_SERIAL_ARC_CONSOLE)
458
459 static void arc_serial_poll_putchar(struct uart_port *port, int chr)
460 {
461         while (!(UART_GET_STATUS(port) & TXEMPTY))
462                 cpu_relax();
463
464         UART_SET_DATA(port, (unsigned char)chr);
465 }
466 #endif
467
468 #ifdef CONFIG_CONSOLE_POLL
469 static int arc_serial_poll_getchar(struct uart_port *port)
470 {
471         unsigned char chr;
472
473         while (!(UART_GET_STATUS(port) & RXEMPTY))
474                 cpu_relax();
475
476         chr = UART_GET_DATA(port);
477         return chr;
478 }
479 #endif
480
481 static struct uart_ops arc_serial_pops = {
482         .tx_empty       = arc_serial_tx_empty,
483         .set_mctrl      = arc_serial_set_mctrl,
484         .get_mctrl      = arc_serial_get_mctrl,
485         .stop_tx        = arc_serial_stop_tx,
486         .start_tx       = arc_serial_start_tx,
487         .stop_rx        = arc_serial_stop_rx,
488         .break_ctl      = arc_serial_break_ctl,
489         .startup        = arc_serial_startup,
490         .shutdown       = arc_serial_shutdown,
491         .set_termios    = arc_serial_set_termios,
492         .type           = arc_serial_type,
493         .release_port   = arc_serial_release_port,
494         .request_port   = arc_serial_request_port,
495         .config_port    = arc_serial_config_port,
496         .verify_port    = arc_serial_verify_port,
497 #ifdef CONFIG_CONSOLE_POLL
498         .poll_put_char = arc_serial_poll_putchar,
499         .poll_get_char = arc_serial_poll_getchar,
500 #endif
501 };
502
503 static int
504 arc_uart_init_one(struct platform_device *pdev, int dev_id)
505 {
506         struct resource *res, *res2;
507         unsigned long *plat_data;
508         struct arc_uart_port *uart = &arc_uart_ports[dev_id];
509         struct uart_port *port = &uart->port;
510
511         plat_data = dev_get_platdata(&pdev->dev);
512         if (!plat_data)
513                 return -ENODEV;
514
515         uart->is_emulated = !!plat_data[0];     /* workaround ISS bug */
516
517         if (is_early_platform_device(pdev)) {
518                 port->uartclk = plat_data[1];
519                 uart->baud = plat_data[2];
520         } else {
521                 struct device_node *np = pdev->dev.of_node;
522                 u32 val;
523
524                 if (of_property_read_u32(np, "clock-frequency", &val)) {
525                         dev_err(&pdev->dev, "clock-frequency property NOTset\n");
526                         return -EINVAL;
527                 }
528                 port->uartclk = val;
529
530                 if (of_property_read_u32(np, "current-speed", &val)) {
531                         dev_err(&pdev->dev, "current-speed property NOT set\n");
532                         return -EINVAL;
533                 }
534                 uart->baud = val;
535         }
536
537         res = platform_get_resource(pdev, IORESOURCE_MEM, 0);
538         if (!res)
539                 return -ENODEV;
540
541         res2 = platform_get_resource(pdev, IORESOURCE_IRQ, 0);
542         if (!res2)
543                 return -ENODEV;
544
545         port->mapbase = res->start;
546         port->membase = ioremap_nocache(res->start, resource_size(res));
547         if (!port->membase)
548                 /* No point of dev_err since UART itself is hosed here */
549                 return -ENXIO;
550
551         port->irq = res2->start;
552         port->dev = &pdev->dev;
553         port->iotype = UPIO_MEM;
554         port->flags = UPF_BOOT_AUTOCONF;
555         port->line = dev_id;
556         port->ops = &arc_serial_pops;
557
558         port->fifosize = ARC_UART_TX_FIFO_SIZE;
559
560         /*
561          * uart_insert_char( ) uses it in decideding whether to ignore a
562          * char or not. Explicitly setting it here, removes the subtelty
563          */
564         port->ignore_status_mask = 0;
565
566         return 0;
567 }
568
569 #ifdef CONFIG_SERIAL_ARC_CONSOLE
570
571 static int arc_serial_console_setup(struct console *co, char *options)
572 {
573         struct uart_port *port;
574         int baud = 115200;
575         int bits = 8;
576         int parity = 'n';
577         int flow = 'n';
578
579         if (co->index < 0 || co->index >= CONFIG_SERIAL_ARC_NR_PORTS)
580                 return -ENODEV;
581
582         /*
583          * The uart port backing the console (e.g. ttyARC1) might not have been
584          * init yet. If so, defer the console setup to after the port.
585          */
586         port = &arc_uart_ports[co->index].port;
587         if (!port->membase)
588                 return -ENODEV;
589
590         if (options)
591                 uart_parse_options(options, &baud, &parity, &bits, &flow);
592
593         /*
594          * Serial core will call port->ops->set_termios( )
595          * which will set the baud reg
596          */
597         return uart_set_options(port, co, baud, parity, bits, flow);
598 }
599
600 /*
601  * Interrupts are disabled on entering
602  */
603 static void arc_serial_console_write(struct console *co, const char *s,
604                                      unsigned int count)
605 {
606         struct uart_port *port = &arc_uart_ports[co->index].port;
607         unsigned long flags;
608
609         spin_lock_irqsave(&port->lock, flags);
610         uart_console_write(port, s, count, arc_serial_poll_putchar);
611         spin_unlock_irqrestore(&port->lock, flags);
612 }
613
614 static struct console arc_console = {
615         .name   = ARC_SERIAL_DEV_NAME,
616         .write  = arc_serial_console_write,
617         .device = uart_console_device,
618         .setup  = arc_serial_console_setup,
619         .flags  = CON_PRINTBUFFER,
620         .index  = -1,
621         .data   = &arc_uart_driver
622 };
623
624 static __init void early_serial_write(struct console *con, const char *s,
625                                         unsigned int n)
626 {
627         struct uart_port *port = &arc_uart_ports[con->index].port;
628
629         uart_console_write(port, s, n, arc_serial_poll_putchar);
630 }
631
632 static struct console arc_early_serial_console __initdata = {
633         .name = "early_ARCuart",
634         .write = early_serial_write,
635         .flags = CON_PRINTBUFFER | CON_BOOT,
636         .index = -1
637 };
638
639 static int __init arc_serial_probe_earlyprintk(struct platform_device *pdev)
640 {
641         int dev_id = pdev->id < 0 ? 0 : pdev->id;
642         int rc;
643
644         arc_early_serial_console.index = dev_id;
645
646         rc = arc_uart_init_one(pdev, dev_id);
647         if (rc)
648                 panic("early console init failed\n");
649
650         arc_serial_console_setup(&arc_early_serial_console, NULL);
651
652         register_console(&arc_early_serial_console);
653         return 0;
654 }
655 #endif  /* CONFIG_SERIAL_ARC_CONSOLE */
656
657 static int arc_serial_probe(struct platform_device *pdev)
658 {
659         int rc, dev_id;
660         struct device_node *np = pdev->dev.of_node;
661
662         /* no device tree device */
663         if (!np)
664                 return -ENODEV;
665
666         dev_id = of_alias_get_id(np, "serial");
667         if (dev_id < 0)
668                 dev_id = 0;
669
670         rc = arc_uart_init_one(pdev, dev_id);
671         if (rc)
672                 return rc;
673
674         rc = uart_add_one_port(&arc_uart_driver, &arc_uart_ports[dev_id].port);
675         return rc;
676 }
677
678 static int arc_serial_remove(struct platform_device *pdev)
679 {
680         /* This will never be called */
681         return 0;
682 }
683
684 static const struct of_device_id arc_uart_dt_ids[] = {
685         { .compatible = "snps,arc-uart" },
686         { /* Sentinel */ }
687 };
688 MODULE_DEVICE_TABLE(of, arc_uart_dt_ids);
689
690 static struct platform_driver arc_platform_driver = {
691         .probe = arc_serial_probe,
692         .remove = arc_serial_remove,
693         .driver = {
694                 .name = DRIVER_NAME,
695                 .owner = THIS_MODULE,
696                 .of_match_table  = arc_uart_dt_ids,
697          },
698 };
699
700 #ifdef CONFIG_SERIAL_ARC_CONSOLE
701
702 static struct platform_driver early_arc_platform_driver __initdata = {
703         .probe = arc_serial_probe_earlyprintk,
704         .remove = arc_serial_remove,
705         .driver = {
706                 .name = DRIVER_NAME,
707                 .owner = THIS_MODULE,
708          },
709 };
710 /*
711  * Register an early platform driver of "earlyprintk" class.
712  * ARCH platform code installs the driver and probes the early devices
713  * The installation could rely on user specifying earlyprintk=xyx in cmd line
714  * or it could be done independently, for all "earlyprintk" class drivers.
715  * [see arch/arc/plat-arcfpga/platform.c]
716  */
717 early_platform_init("earlyprintk", &early_arc_platform_driver);
718
719 #endif  /* CONFIG_SERIAL_ARC_CONSOLE */
720
721 static int __init arc_serial_init(void)
722 {
723         int ret;
724
725         ret = uart_register_driver(&arc_uart_driver);
726         if (ret)
727                 return ret;
728
729         ret = platform_driver_register(&arc_platform_driver);
730         if (ret)
731                 uart_unregister_driver(&arc_uart_driver);
732
733         return ret;
734 }
735
736 static void __exit arc_serial_exit(void)
737 {
738         platform_driver_unregister(&arc_platform_driver);
739         uart_unregister_driver(&arc_uart_driver);
740 }
741
742 module_init(arc_serial_init);
743 module_exit(arc_serial_exit);
744
745 MODULE_LICENSE("GPL");
746 MODULE_ALIAS("platform:" DRIVER_NAME);
747 MODULE_AUTHOR("Vineet Gupta");
748 MODULE_DESCRIPTION("ARC(Synopsys) On-Chip(fpga) serial driver");