Linux 4.16.11
[linux/fpc-iii.git] / drivers / tty / serial / lantiq.c
blob044128277248b0298a67667c872b96dfc11fe472
1 // SPDX-License-Identifier: GPL-2.0
2 /*
3 * Based on drivers/char/serial.c, by Linus Torvalds, Theodore Ts'o.
5 * Copyright (C) 2004 Infineon IFAP DC COM CPE
6 * Copyright (C) 2007 Felix Fietkau <nbd@openwrt.org>
7 * Copyright (C) 2007 John Crispin <john@phrozen.org>
8 * Copyright (C) 2010 Thomas Langer, <thomas.langer@lantiq.com>
9 */
11 #include <linux/slab.h>
12 #include <linux/ioport.h>
13 #include <linux/init.h>
14 #include <linux/console.h>
15 #include <linux/sysrq.h>
16 #include <linux/device.h>
17 #include <linux/tty.h>
18 #include <linux/tty_flip.h>
19 #include <linux/serial_core.h>
20 #include <linux/serial.h>
21 #include <linux/of_platform.h>
22 #include <linux/of_address.h>
23 #include <linux/of_irq.h>
24 #include <linux/io.h>
25 #include <linux/clk.h>
26 #include <linux/gpio.h>
28 #include <lantiq_soc.h>
30 #define PORT_LTQ_ASC 111
31 #define MAXPORTS 2
32 #define UART_DUMMY_UER_RX 1
33 #define DRVNAME "lantiq,asc"
34 #ifdef __BIG_ENDIAN
35 #define LTQ_ASC_TBUF (0x0020 + 3)
36 #define LTQ_ASC_RBUF (0x0024 + 3)
37 #else
38 #define LTQ_ASC_TBUF 0x0020
39 #define LTQ_ASC_RBUF 0x0024
40 #endif
41 #define LTQ_ASC_FSTAT 0x0048
42 #define LTQ_ASC_WHBSTATE 0x0018
43 #define LTQ_ASC_STATE 0x0014
44 #define LTQ_ASC_IRNCR 0x00F8
45 #define LTQ_ASC_CLC 0x0000
46 #define LTQ_ASC_ID 0x0008
47 #define LTQ_ASC_PISEL 0x0004
48 #define LTQ_ASC_TXFCON 0x0044
49 #define LTQ_ASC_RXFCON 0x0040
50 #define LTQ_ASC_CON 0x0010
51 #define LTQ_ASC_BG 0x0050
52 #define LTQ_ASC_IRNREN 0x00F4
54 #define ASC_IRNREN_TX 0x1
55 #define ASC_IRNREN_RX 0x2
56 #define ASC_IRNREN_ERR 0x4
57 #define ASC_IRNREN_TX_BUF 0x8
58 #define ASC_IRNCR_TIR 0x1
59 #define ASC_IRNCR_RIR 0x2
60 #define ASC_IRNCR_EIR 0x4
62 #define ASCOPT_CSIZE 0x3
63 #define TXFIFO_FL 1
64 #define RXFIFO_FL 1
65 #define ASCCLC_DISS 0x2
66 #define ASCCLC_RMCMASK 0x0000FF00
67 #define ASCCLC_RMCOFFSET 8
68 #define ASCCON_M_8ASYNC 0x0
69 #define ASCCON_M_7ASYNC 0x2
70 #define ASCCON_ODD 0x00000020
71 #define ASCCON_STP 0x00000080
72 #define ASCCON_BRS 0x00000100
73 #define ASCCON_FDE 0x00000200
74 #define ASCCON_R 0x00008000
75 #define ASCCON_FEN 0x00020000
76 #define ASCCON_ROEN 0x00080000
77 #define ASCCON_TOEN 0x00100000
78 #define ASCSTATE_PE 0x00010000
79 #define ASCSTATE_FE 0x00020000
80 #define ASCSTATE_ROE 0x00080000
81 #define ASCSTATE_ANY (ASCSTATE_ROE|ASCSTATE_PE|ASCSTATE_FE)
82 #define ASCWHBSTATE_CLRREN 0x00000001
83 #define ASCWHBSTATE_SETREN 0x00000002
84 #define ASCWHBSTATE_CLRPE 0x00000004
85 #define ASCWHBSTATE_CLRFE 0x00000008
86 #define ASCWHBSTATE_CLRROE 0x00000020
87 #define ASCTXFCON_TXFEN 0x0001
88 #define ASCTXFCON_TXFFLU 0x0002
89 #define ASCTXFCON_TXFITLMASK 0x3F00
90 #define ASCTXFCON_TXFITLOFF 8
91 #define ASCRXFCON_RXFEN 0x0001
92 #define ASCRXFCON_RXFFLU 0x0002
93 #define ASCRXFCON_RXFITLMASK 0x3F00
94 #define ASCRXFCON_RXFITLOFF 8
95 #define ASCFSTAT_RXFFLMASK 0x003F
96 #define ASCFSTAT_TXFFLMASK 0x3F00
97 #define ASCFSTAT_TXFREEMASK 0x3F000000
98 #define ASCFSTAT_TXFREEOFF 24
100 static void lqasc_tx_chars(struct uart_port *port);
101 static struct ltq_uart_port *lqasc_port[MAXPORTS];
102 static struct uart_driver lqasc_reg;
103 static DEFINE_SPINLOCK(ltq_asc_lock);
105 struct ltq_uart_port {
106 struct uart_port port;
107 /* clock used to derive divider */
108 struct clk *fpiclk;
109 /* clock gating of the ASC core */
110 struct clk *clk;
111 unsigned int tx_irq;
112 unsigned int rx_irq;
113 unsigned int err_irq;
116 static inline struct
117 ltq_uart_port *to_ltq_uart_port(struct uart_port *port)
119 return container_of(port, struct ltq_uart_port, port);
122 static void
123 lqasc_stop_tx(struct uart_port *port)
125 return;
128 static void
129 lqasc_start_tx(struct uart_port *port)
131 unsigned long flags;
132 spin_lock_irqsave(&ltq_asc_lock, flags);
133 lqasc_tx_chars(port);
134 spin_unlock_irqrestore(&ltq_asc_lock, flags);
135 return;
138 static void
139 lqasc_stop_rx(struct uart_port *port)
141 ltq_w32(ASCWHBSTATE_CLRREN, port->membase + LTQ_ASC_WHBSTATE);
144 static int
145 lqasc_rx_chars(struct uart_port *port)
147 struct tty_port *tport = &port->state->port;
148 unsigned int ch = 0, rsr = 0, fifocnt;
150 fifocnt = ltq_r32(port->membase + LTQ_ASC_FSTAT) & ASCFSTAT_RXFFLMASK;
151 while (fifocnt--) {
152 u8 flag = TTY_NORMAL;
153 ch = ltq_r8(port->membase + LTQ_ASC_RBUF);
154 rsr = (ltq_r32(port->membase + LTQ_ASC_STATE)
155 & ASCSTATE_ANY) | UART_DUMMY_UER_RX;
156 tty_flip_buffer_push(tport);
157 port->icount.rx++;
160 * Note that the error handling code is
161 * out of the main execution path
163 if (rsr & ASCSTATE_ANY) {
164 if (rsr & ASCSTATE_PE) {
165 port->icount.parity++;
166 ltq_w32_mask(0, ASCWHBSTATE_CLRPE,
167 port->membase + LTQ_ASC_WHBSTATE);
168 } else if (rsr & ASCSTATE_FE) {
169 port->icount.frame++;
170 ltq_w32_mask(0, ASCWHBSTATE_CLRFE,
171 port->membase + LTQ_ASC_WHBSTATE);
173 if (rsr & ASCSTATE_ROE) {
174 port->icount.overrun++;
175 ltq_w32_mask(0, ASCWHBSTATE_CLRROE,
176 port->membase + LTQ_ASC_WHBSTATE);
179 rsr &= port->read_status_mask;
181 if (rsr & ASCSTATE_PE)
182 flag = TTY_PARITY;
183 else if (rsr & ASCSTATE_FE)
184 flag = TTY_FRAME;
187 if ((rsr & port->ignore_status_mask) == 0)
188 tty_insert_flip_char(tport, ch, flag);
190 if (rsr & ASCSTATE_ROE)
192 * Overrun is special, since it's reported
193 * immediately, and doesn't affect the current
194 * character
196 tty_insert_flip_char(tport, 0, TTY_OVERRUN);
199 if (ch != 0)
200 tty_flip_buffer_push(tport);
202 return 0;
205 static void
206 lqasc_tx_chars(struct uart_port *port)
208 struct circ_buf *xmit = &port->state->xmit;
209 if (uart_tx_stopped(port)) {
210 lqasc_stop_tx(port);
211 return;
214 while (((ltq_r32(port->membase + LTQ_ASC_FSTAT) &
215 ASCFSTAT_TXFREEMASK) >> ASCFSTAT_TXFREEOFF) != 0) {
216 if (port->x_char) {
217 ltq_w8(port->x_char, port->membase + LTQ_ASC_TBUF);
218 port->icount.tx++;
219 port->x_char = 0;
220 continue;
223 if (uart_circ_empty(xmit))
224 break;
226 ltq_w8(port->state->xmit.buf[port->state->xmit.tail],
227 port->membase + LTQ_ASC_TBUF);
228 xmit->tail = (xmit->tail + 1) & (UART_XMIT_SIZE - 1);
229 port->icount.tx++;
232 if (uart_circ_chars_pending(xmit) < WAKEUP_CHARS)
233 uart_write_wakeup(port);
236 static irqreturn_t
237 lqasc_tx_int(int irq, void *_port)
239 unsigned long flags;
240 struct uart_port *port = (struct uart_port *)_port;
241 spin_lock_irqsave(&ltq_asc_lock, flags);
242 ltq_w32(ASC_IRNCR_TIR, port->membase + LTQ_ASC_IRNCR);
243 spin_unlock_irqrestore(&ltq_asc_lock, flags);
244 lqasc_start_tx(port);
245 return IRQ_HANDLED;
248 static irqreturn_t
249 lqasc_err_int(int irq, void *_port)
251 unsigned long flags;
252 struct uart_port *port = (struct uart_port *)_port;
253 spin_lock_irqsave(&ltq_asc_lock, flags);
254 /* clear any pending interrupts */
255 ltq_w32_mask(0, ASCWHBSTATE_CLRPE | ASCWHBSTATE_CLRFE |
256 ASCWHBSTATE_CLRROE, port->membase + LTQ_ASC_WHBSTATE);
257 spin_unlock_irqrestore(&ltq_asc_lock, flags);
258 return IRQ_HANDLED;
261 static irqreturn_t
262 lqasc_rx_int(int irq, void *_port)
264 unsigned long flags;
265 struct uart_port *port = (struct uart_port *)_port;
266 spin_lock_irqsave(&ltq_asc_lock, flags);
267 ltq_w32(ASC_IRNCR_RIR, port->membase + LTQ_ASC_IRNCR);
268 lqasc_rx_chars(port);
269 spin_unlock_irqrestore(&ltq_asc_lock, flags);
270 return IRQ_HANDLED;
273 static unsigned int
274 lqasc_tx_empty(struct uart_port *port)
276 int status;
277 status = ltq_r32(port->membase + LTQ_ASC_FSTAT) & ASCFSTAT_TXFFLMASK;
278 return status ? 0 : TIOCSER_TEMT;
281 static unsigned int
282 lqasc_get_mctrl(struct uart_port *port)
284 return TIOCM_CTS | TIOCM_CAR | TIOCM_DSR;
287 static void
288 lqasc_set_mctrl(struct uart_port *port, u_int mctrl)
292 static void
293 lqasc_break_ctl(struct uart_port *port, int break_state)
297 static int
298 lqasc_startup(struct uart_port *port)
300 struct ltq_uart_port *ltq_port = to_ltq_uart_port(port);
301 int retval;
303 if (!IS_ERR(ltq_port->clk))
304 clk_enable(ltq_port->clk);
305 port->uartclk = clk_get_rate(ltq_port->fpiclk);
307 ltq_w32_mask(ASCCLC_DISS | ASCCLC_RMCMASK, (1 << ASCCLC_RMCOFFSET),
308 port->membase + LTQ_ASC_CLC);
310 ltq_w32(0, port->membase + LTQ_ASC_PISEL);
311 ltq_w32(
312 ((TXFIFO_FL << ASCTXFCON_TXFITLOFF) & ASCTXFCON_TXFITLMASK) |
313 ASCTXFCON_TXFEN | ASCTXFCON_TXFFLU,
314 port->membase + LTQ_ASC_TXFCON);
315 ltq_w32(
316 ((RXFIFO_FL << ASCRXFCON_RXFITLOFF) & ASCRXFCON_RXFITLMASK)
317 | ASCRXFCON_RXFEN | ASCRXFCON_RXFFLU,
318 port->membase + LTQ_ASC_RXFCON);
319 /* make sure other settings are written to hardware before
320 * setting enable bits
322 wmb();
323 ltq_w32_mask(0, ASCCON_M_8ASYNC | ASCCON_FEN | ASCCON_TOEN |
324 ASCCON_ROEN, port->membase + LTQ_ASC_CON);
326 retval = request_irq(ltq_port->tx_irq, lqasc_tx_int,
327 0, "asc_tx", port);
328 if (retval) {
329 pr_err("failed to request lqasc_tx_int\n");
330 return retval;
333 retval = request_irq(ltq_port->rx_irq, lqasc_rx_int,
334 0, "asc_rx", port);
335 if (retval) {
336 pr_err("failed to request lqasc_rx_int\n");
337 goto err1;
340 retval = request_irq(ltq_port->err_irq, lqasc_err_int,
341 0, "asc_err", port);
342 if (retval) {
343 pr_err("failed to request lqasc_err_int\n");
344 goto err2;
347 ltq_w32(ASC_IRNREN_RX | ASC_IRNREN_ERR | ASC_IRNREN_TX,
348 port->membase + LTQ_ASC_IRNREN);
349 return 0;
351 err2:
352 free_irq(ltq_port->rx_irq, port);
353 err1:
354 free_irq(ltq_port->tx_irq, port);
355 return retval;
358 static void
359 lqasc_shutdown(struct uart_port *port)
361 struct ltq_uart_port *ltq_port = to_ltq_uart_port(port);
362 free_irq(ltq_port->tx_irq, port);
363 free_irq(ltq_port->rx_irq, port);
364 free_irq(ltq_port->err_irq, port);
366 ltq_w32(0, port->membase + LTQ_ASC_CON);
367 ltq_w32_mask(ASCRXFCON_RXFEN, ASCRXFCON_RXFFLU,
368 port->membase + LTQ_ASC_RXFCON);
369 ltq_w32_mask(ASCTXFCON_TXFEN, ASCTXFCON_TXFFLU,
370 port->membase + LTQ_ASC_TXFCON);
371 if (!IS_ERR(ltq_port->clk))
372 clk_disable(ltq_port->clk);
375 static void
376 lqasc_set_termios(struct uart_port *port,
377 struct ktermios *new, struct ktermios *old)
379 unsigned int cflag;
380 unsigned int iflag;
381 unsigned int divisor;
382 unsigned int baud;
383 unsigned int con = 0;
384 unsigned long flags;
386 cflag = new->c_cflag;
387 iflag = new->c_iflag;
389 switch (cflag & CSIZE) {
390 case CS7:
391 con = ASCCON_M_7ASYNC;
392 break;
394 case CS5:
395 case CS6:
396 default:
397 new->c_cflag &= ~ CSIZE;
398 new->c_cflag |= CS8;
399 con = ASCCON_M_8ASYNC;
400 break;
403 cflag &= ~CMSPAR; /* Mark/Space parity is not supported */
405 if (cflag & CSTOPB)
406 con |= ASCCON_STP;
408 if (cflag & PARENB) {
409 if (!(cflag & PARODD))
410 con &= ~ASCCON_ODD;
411 else
412 con |= ASCCON_ODD;
415 port->read_status_mask = ASCSTATE_ROE;
416 if (iflag & INPCK)
417 port->read_status_mask |= ASCSTATE_FE | ASCSTATE_PE;
419 port->ignore_status_mask = 0;
420 if (iflag & IGNPAR)
421 port->ignore_status_mask |= ASCSTATE_FE | ASCSTATE_PE;
423 if (iflag & IGNBRK) {
425 * If we're ignoring parity and break indicators,
426 * ignore overruns too (for real raw support).
428 if (iflag & IGNPAR)
429 port->ignore_status_mask |= ASCSTATE_ROE;
432 if ((cflag & CREAD) == 0)
433 port->ignore_status_mask |= UART_DUMMY_UER_RX;
435 /* set error signals - framing, parity and overrun, enable receiver */
436 con |= ASCCON_FEN | ASCCON_TOEN | ASCCON_ROEN;
438 spin_lock_irqsave(&ltq_asc_lock, flags);
440 /* set up CON */
441 ltq_w32_mask(0, con, port->membase + LTQ_ASC_CON);
443 /* Set baud rate - take a divider of 2 into account */
444 baud = uart_get_baud_rate(port, new, old, 0, port->uartclk / 16);
445 divisor = uart_get_divisor(port, baud);
446 divisor = divisor / 2 - 1;
448 /* disable the baudrate generator */
449 ltq_w32_mask(ASCCON_R, 0, port->membase + LTQ_ASC_CON);
451 /* make sure the fractional divider is off */
452 ltq_w32_mask(ASCCON_FDE, 0, port->membase + LTQ_ASC_CON);
454 /* set up to use divisor of 2 */
455 ltq_w32_mask(ASCCON_BRS, 0, port->membase + LTQ_ASC_CON);
457 /* now we can write the new baudrate into the register */
458 ltq_w32(divisor, port->membase + LTQ_ASC_BG);
460 /* turn the baudrate generator back on */
461 ltq_w32_mask(0, ASCCON_R, port->membase + LTQ_ASC_CON);
463 /* enable rx */
464 ltq_w32(ASCWHBSTATE_SETREN, port->membase + LTQ_ASC_WHBSTATE);
466 spin_unlock_irqrestore(&ltq_asc_lock, flags);
468 /* Don't rewrite B0 */
469 if (tty_termios_baud_rate(new))
470 tty_termios_encode_baud_rate(new, baud, baud);
472 uart_update_timeout(port, cflag, baud);
475 static const char*
476 lqasc_type(struct uart_port *port)
478 if (port->type == PORT_LTQ_ASC)
479 return DRVNAME;
480 else
481 return NULL;
484 static void
485 lqasc_release_port(struct uart_port *port)
487 struct platform_device *pdev = to_platform_device(port->dev);
489 if (port->flags & UPF_IOREMAP) {
490 devm_iounmap(&pdev->dev, port->membase);
491 port->membase = NULL;
495 static int
496 lqasc_request_port(struct uart_port *port)
498 struct platform_device *pdev = to_platform_device(port->dev);
499 struct resource *res;
500 int size;
502 res = platform_get_resource(pdev, IORESOURCE_MEM, 0);
503 if (!res) {
504 dev_err(&pdev->dev, "cannot obtain I/O memory region");
505 return -ENODEV;
507 size = resource_size(res);
509 res = devm_request_mem_region(&pdev->dev, res->start,
510 size, dev_name(&pdev->dev));
511 if (!res) {
512 dev_err(&pdev->dev, "cannot request I/O memory region");
513 return -EBUSY;
516 if (port->flags & UPF_IOREMAP) {
517 port->membase = devm_ioremap_nocache(&pdev->dev,
518 port->mapbase, size);
519 if (port->membase == NULL)
520 return -ENOMEM;
522 return 0;
525 static void
526 lqasc_config_port(struct uart_port *port, int flags)
528 if (flags & UART_CONFIG_TYPE) {
529 port->type = PORT_LTQ_ASC;
530 lqasc_request_port(port);
534 static int
535 lqasc_verify_port(struct uart_port *port,
536 struct serial_struct *ser)
538 int ret = 0;
539 if (ser->type != PORT_UNKNOWN && ser->type != PORT_LTQ_ASC)
540 ret = -EINVAL;
541 if (ser->irq < 0 || ser->irq >= NR_IRQS)
542 ret = -EINVAL;
543 if (ser->baud_base < 9600)
544 ret = -EINVAL;
545 return ret;
548 static const struct uart_ops lqasc_pops = {
549 .tx_empty = lqasc_tx_empty,
550 .set_mctrl = lqasc_set_mctrl,
551 .get_mctrl = lqasc_get_mctrl,
552 .stop_tx = lqasc_stop_tx,
553 .start_tx = lqasc_start_tx,
554 .stop_rx = lqasc_stop_rx,
555 .break_ctl = lqasc_break_ctl,
556 .startup = lqasc_startup,
557 .shutdown = lqasc_shutdown,
558 .set_termios = lqasc_set_termios,
559 .type = lqasc_type,
560 .release_port = lqasc_release_port,
561 .request_port = lqasc_request_port,
562 .config_port = lqasc_config_port,
563 .verify_port = lqasc_verify_port,
566 static void
567 lqasc_console_putchar(struct uart_port *port, int ch)
569 int fifofree;
571 if (!port->membase)
572 return;
574 do {
575 fifofree = (ltq_r32(port->membase + LTQ_ASC_FSTAT)
576 & ASCFSTAT_TXFREEMASK) >> ASCFSTAT_TXFREEOFF;
577 } while (fifofree == 0);
578 ltq_w8(ch, port->membase + LTQ_ASC_TBUF);
581 static void lqasc_serial_port_write(struct uart_port *port, const char *s,
582 u_int count)
584 unsigned long flags;
586 spin_lock_irqsave(&ltq_asc_lock, flags);
587 uart_console_write(port, s, count, lqasc_console_putchar);
588 spin_unlock_irqrestore(&ltq_asc_lock, flags);
591 static void
592 lqasc_console_write(struct console *co, const char *s, u_int count)
594 struct ltq_uart_port *ltq_port;
596 if (co->index >= MAXPORTS)
597 return;
599 ltq_port = lqasc_port[co->index];
600 if (!ltq_port)
601 return;
603 lqasc_serial_port_write(&ltq_port->port, s, count);
606 static int __init
607 lqasc_console_setup(struct console *co, char *options)
609 struct ltq_uart_port *ltq_port;
610 struct uart_port *port;
611 int baud = 115200;
612 int bits = 8;
613 int parity = 'n';
614 int flow = 'n';
616 if (co->index >= MAXPORTS)
617 return -ENODEV;
619 ltq_port = lqasc_port[co->index];
620 if (!ltq_port)
621 return -ENODEV;
623 port = &ltq_port->port;
625 if (!IS_ERR(ltq_port->clk))
626 clk_enable(ltq_port->clk);
628 port->uartclk = clk_get_rate(ltq_port->fpiclk);
630 if (options)
631 uart_parse_options(options, &baud, &parity, &bits, &flow);
632 return uart_set_options(port, co, baud, parity, bits, flow);
635 static struct console lqasc_console = {
636 .name = "ttyLTQ",
637 .write = lqasc_console_write,
638 .device = uart_console_device,
639 .setup = lqasc_console_setup,
640 .flags = CON_PRINTBUFFER,
641 .index = -1,
642 .data = &lqasc_reg,
645 static int __init
646 lqasc_console_init(void)
648 register_console(&lqasc_console);
649 return 0;
651 console_initcall(lqasc_console_init);
653 static void lqasc_serial_early_console_write(struct console *co,
654 const char *s,
655 u_int count)
657 struct earlycon_device *dev = co->data;
659 lqasc_serial_port_write(&dev->port, s, count);
662 static int __init
663 lqasc_serial_early_console_setup(struct earlycon_device *device,
664 const char *opt)
666 if (!device->port.membase)
667 return -ENODEV;
669 device->con->write = lqasc_serial_early_console_write;
670 return 0;
672 OF_EARLYCON_DECLARE(lantiq, DRVNAME, lqasc_serial_early_console_setup);
674 static struct uart_driver lqasc_reg = {
675 .owner = THIS_MODULE,
676 .driver_name = DRVNAME,
677 .dev_name = "ttyLTQ",
678 .major = 0,
679 .minor = 0,
680 .nr = MAXPORTS,
681 .cons = &lqasc_console,
684 static int __init
685 lqasc_probe(struct platform_device *pdev)
687 struct device_node *node = pdev->dev.of_node;
688 struct ltq_uart_port *ltq_port;
689 struct uart_port *port;
690 struct resource *mmres, irqres[3];
691 int line = 0;
692 int ret;
694 mmres = platform_get_resource(pdev, IORESOURCE_MEM, 0);
695 ret = of_irq_to_resource_table(node, irqres, 3);
696 if (!mmres || (ret != 3)) {
697 dev_err(&pdev->dev,
698 "failed to get memory/irq for serial port\n");
699 return -ENODEV;
702 /* check if this is the console port */
703 if (mmres->start != CPHYSADDR(LTQ_EARLY_ASC))
704 line = 1;
706 if (lqasc_port[line]) {
707 dev_err(&pdev->dev, "port %d already allocated\n", line);
708 return -EBUSY;
711 ltq_port = devm_kzalloc(&pdev->dev, sizeof(struct ltq_uart_port),
712 GFP_KERNEL);
713 if (!ltq_port)
714 return -ENOMEM;
716 port = &ltq_port->port;
718 port->iotype = SERIAL_IO_MEM;
719 port->flags = UPF_BOOT_AUTOCONF | UPF_IOREMAP;
720 port->ops = &lqasc_pops;
721 port->fifosize = 16;
722 port->type = PORT_LTQ_ASC,
723 port->line = line;
724 port->dev = &pdev->dev;
725 /* unused, just to be backward-compatible */
726 port->irq = irqres[0].start;
727 port->mapbase = mmres->start;
729 ltq_port->fpiclk = clk_get_fpi();
730 if (IS_ERR(ltq_port->fpiclk)) {
731 pr_err("failed to get fpi clk\n");
732 return -ENOENT;
735 /* not all asc ports have clock gates, lets ignore the return code */
736 ltq_port->clk = clk_get(&pdev->dev, NULL);
738 ltq_port->tx_irq = irqres[0].start;
739 ltq_port->rx_irq = irqres[1].start;
740 ltq_port->err_irq = irqres[2].start;
742 lqasc_port[line] = ltq_port;
743 platform_set_drvdata(pdev, ltq_port);
745 ret = uart_add_one_port(&lqasc_reg, port);
747 return ret;
750 static const struct of_device_id ltq_asc_match[] = {
751 { .compatible = DRVNAME },
755 static struct platform_driver lqasc_driver = {
756 .driver = {
757 .name = DRVNAME,
758 .of_match_table = ltq_asc_match,
762 int __init
763 init_lqasc(void)
765 int ret;
767 ret = uart_register_driver(&lqasc_reg);
768 if (ret != 0)
769 return ret;
771 ret = platform_driver_probe(&lqasc_driver, lqasc_probe);
772 if (ret != 0)
773 uart_unregister_driver(&lqasc_reg);
775 return ret;
777 device_initcall(init_lqasc);