2 * st-asc.c: ST Asynchronous serial controller (ASC) driver
4 * Copyright (C) 2003-2013 STMicroelectronics (R&D) Limited
6 * This program is free software; you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License as published by
8 * the Free Software Foundation; either version 2 of the License, or
9 * (at your option) any later version.
13 #if defined(CONFIG_SERIAL_ST_ASC_CONSOLE) && defined(CONFIG_MAGIC_SYSRQ)
17 #include <linux/module.h>
18 #include <linux/serial.h>
19 #include <linux/console.h>
20 #include <linux/sysrq.h>
21 #include <linux/platform_device.h>
23 #include <linux/irq.h>
24 #include <linux/tty.h>
25 #include <linux/tty_flip.h>
26 #include <linux/delay.h>
27 #include <linux/spinlock.h>
28 #include <linux/pm_runtime.h>
30 #include <linux/of_platform.h>
31 #include <linux/serial_core.h>
32 #include <linux/clk.h>
33 #include <linux/gpio/consumer.h>
35 #define DRIVER_NAME "st-asc"
36 #define ASC_SERIAL_NAME "ttyAS"
37 #define ASC_FIFO_SIZE 16
38 #define ASC_MAX_PORTS 8
41 struct uart_port port;
42 struct gpio_desc *rts;
44 unsigned int hw_flow_control:1;
45 unsigned int force_m1:1;
48 static struct asc_port asc_ports[ASC_MAX_PORTS];
49 static struct uart_driver asc_uart_driver;
51 /*---- UART Register definitions ------------------------------*/
53 /* Register offsets */
55 #define ASC_BAUDRATE 0x00
56 #define ASC_TXBUF 0x04
57 #define ASC_RXBUF 0x08
59 #define ASC_INTEN 0x10
61 #define ASC_GUARDTIME 0x18
62 #define ASC_TIMEOUT 0x1C
63 #define ASC_TXRESET 0x20
64 #define ASC_RXRESET 0x24
65 #define ASC_RETRIES 0x28
68 #define ASC_RXBUF_PE 0x100
69 #define ASC_RXBUF_FE 0x200
71 * Some of status comes from higher bits of the character and some come from
72 * the status register. Combining both of them in to single status using dummy
75 #define ASC_RXBUF_DUMMY_RX 0x10000
76 #define ASC_RXBUF_DUMMY_BE 0x20000
77 #define ASC_RXBUF_DUMMY_OE 0x40000
81 #define ASC_CTL_MODE_MSK 0x0007
82 #define ASC_CTL_MODE_8BIT 0x0001
83 #define ASC_CTL_MODE_7BIT_PAR 0x0003
84 #define ASC_CTL_MODE_9BIT 0x0004
85 #define ASC_CTL_MODE_8BIT_WKUP 0x0005
86 #define ASC_CTL_MODE_8BIT_PAR 0x0007
87 #define ASC_CTL_STOP_MSK 0x0018
88 #define ASC_CTL_STOP_HALFBIT 0x0000
89 #define ASC_CTL_STOP_1BIT 0x0008
90 #define ASC_CTL_STOP_1_HALFBIT 0x0010
91 #define ASC_CTL_STOP_2BIT 0x0018
92 #define ASC_CTL_PARITYODD 0x0020
93 #define ASC_CTL_LOOPBACK 0x0040
94 #define ASC_CTL_RUN 0x0080
95 #define ASC_CTL_RXENABLE 0x0100
96 #define ASC_CTL_SCENABLE 0x0200
97 #define ASC_CTL_FIFOENABLE 0x0400
98 #define ASC_CTL_CTSENABLE 0x0800
99 #define ASC_CTL_BAUDMODE 0x1000
103 #define ASC_GUARDTIME_MSK 0x00FF
107 #define ASC_INTEN_RBE 0x0001
108 #define ASC_INTEN_TE 0x0002
109 #define ASC_INTEN_THE 0x0004
110 #define ASC_INTEN_PE 0x0008
111 #define ASC_INTEN_FE 0x0010
112 #define ASC_INTEN_OE 0x0020
113 #define ASC_INTEN_TNE 0x0040
114 #define ASC_INTEN_TOI 0x0080
115 #define ASC_INTEN_RHF 0x0100
119 #define ASC_RETRIES_MSK 0x00FF
123 #define ASC_RXBUF_MSK 0x03FF
127 #define ASC_STA_RBF 0x0001
128 #define ASC_STA_TE 0x0002
129 #define ASC_STA_THE 0x0004
130 #define ASC_STA_PE 0x0008
131 #define ASC_STA_FE 0x0010
132 #define ASC_STA_OE 0x0020
133 #define ASC_STA_TNE 0x0040
134 #define ASC_STA_TOI 0x0080
135 #define ASC_STA_RHF 0x0100
136 #define ASC_STA_TF 0x0200
137 #define ASC_STA_NKD 0x0400
141 #define ASC_TIMEOUT_MSK 0x00FF
145 #define ASC_TXBUF_MSK 0x01FF
147 /*---- Inline function definitions ---------------------------*/
149 static inline struct asc_port *to_asc_port(struct uart_port *port)
151 return container_of(port, struct asc_port, port);
154 static inline u32 asc_in(struct uart_port *port, u32 offset)
157 return readl_relaxed(port->membase + offset);
159 return readl(port->membase + offset);
163 static inline void asc_out(struct uart_port *port, u32 offset, u32 value)
165 #ifdef writel_relaxed
166 writel_relaxed(value, port->membase + offset);
168 writel(value, port->membase + offset);
173 * Some simple utility functions to enable and disable interrupts.
174 * Note that these need to be called with interrupts disabled.
176 static inline void asc_disable_tx_interrupts(struct uart_port *port)
178 u32 intenable = asc_in(port, ASC_INTEN) & ~ASC_INTEN_THE;
179 asc_out(port, ASC_INTEN, intenable);
180 (void)asc_in(port, ASC_INTEN); /* Defeat bus write posting */
183 static inline void asc_enable_tx_interrupts(struct uart_port *port)
185 u32 intenable = asc_in(port, ASC_INTEN) | ASC_INTEN_THE;
186 asc_out(port, ASC_INTEN, intenable);
189 static inline void asc_disable_rx_interrupts(struct uart_port *port)
191 u32 intenable = asc_in(port, ASC_INTEN) & ~ASC_INTEN_RBE;
192 asc_out(port, ASC_INTEN, intenable);
193 (void)asc_in(port, ASC_INTEN); /* Defeat bus write posting */
196 static inline void asc_enable_rx_interrupts(struct uart_port *port)
198 u32 intenable = asc_in(port, ASC_INTEN) | ASC_INTEN_RBE;
199 asc_out(port, ASC_INTEN, intenable);
202 static inline u32 asc_txfifo_is_empty(struct uart_port *port)
204 return asc_in(port, ASC_STA) & ASC_STA_TE;
207 static inline u32 asc_txfifo_is_half_empty(struct uart_port *port)
209 return asc_in(port, ASC_STA) & ASC_STA_THE;
212 static inline const char *asc_port_name(struct uart_port *port)
214 return to_platform_device(port->dev)->name;
217 /*----------------------------------------------------------------------*/
220 * This section contains code to support the use of the ASC as a
221 * generic serial port.
224 static inline unsigned asc_hw_txroom(struct uart_port *port)
226 u32 status = asc_in(port, ASC_STA);
228 if (status & ASC_STA_THE)
229 return port->fifosize / 2;
230 else if (!(status & ASC_STA_TF))
237 * Start transmitting chars.
238 * This is called from both interrupt and task level.
239 * Either way interrupts are disabled.
241 static void asc_transmit_chars(struct uart_port *port)
243 struct circ_buf *xmit = &port->state->xmit;
247 txroom = asc_hw_txroom(port);
249 if ((txroom != 0) && port->x_char) {
252 asc_out(port, ASC_TXBUF, c);
254 txroom = asc_hw_txroom(port);
257 if (uart_tx_stopped(port)) {
259 * We should try and stop the hardware here, but I
260 * don't think the ASC has any way to do that.
262 asc_disable_tx_interrupts(port);
266 if (uart_circ_empty(xmit)) {
267 asc_disable_tx_interrupts(port);
275 c = xmit->buf[xmit->tail];
276 xmit->tail = (xmit->tail + 1) & (UART_XMIT_SIZE - 1);
277 asc_out(port, ASC_TXBUF, c);
280 } while ((txroom > 0) && (!uart_circ_empty(xmit)));
282 if (uart_circ_chars_pending(xmit) < WAKEUP_CHARS)
283 uart_write_wakeup(port);
285 if (uart_circ_empty(xmit))
286 asc_disable_tx_interrupts(port);
289 static void asc_receive_chars(struct uart_port *port)
291 struct tty_port *tport = &port->state->port;
292 unsigned long status, mode;
295 bool ignore_pe = false;
298 * Datasheet states: If the MODE field selects an 8-bit frame then
299 * this [parity error] bit is undefined. Software should ignore this
300 * bit when reading 8-bit frames.
302 mode = asc_in(port, ASC_CTL) & ASC_CTL_MODE_MSK;
303 if (mode == ASC_CTL_MODE_8BIT || mode == ASC_CTL_MODE_8BIT_PAR)
307 pm_wakeup_event(tport->tty->dev, 0);
309 while ((status = asc_in(port, ASC_STA)) & ASC_STA_RBF) {
310 c = asc_in(port, ASC_RXBUF) | ASC_RXBUF_DUMMY_RX;
314 if (status & ASC_STA_OE || c & ASC_RXBUF_FE ||
315 (c & ASC_RXBUF_PE && !ignore_pe)) {
317 if (c & ASC_RXBUF_FE) {
318 if (c == (ASC_RXBUF_FE | ASC_RXBUF_DUMMY_RX)) {
320 if (uart_handle_break(port))
322 c |= ASC_RXBUF_DUMMY_BE;
324 port->icount.frame++;
326 } else if (c & ASC_RXBUF_PE) {
327 port->icount.parity++;
330 * Reading any data from the RX FIFO clears the
331 * overflow error condition.
333 if (status & ASC_STA_OE) {
334 port->icount.overrun++;
335 c |= ASC_RXBUF_DUMMY_OE;
338 c &= port->read_status_mask;
340 if (c & ASC_RXBUF_DUMMY_BE)
342 else if (c & ASC_RXBUF_PE)
344 else if (c & ASC_RXBUF_FE)
348 if (uart_handle_sysrq_char(port, c & 0xff))
351 uart_insert_char(port, c, ASC_RXBUF_DUMMY_OE, c & 0xff, flag);
354 /* Tell the rest of the system the news. New characters! */
355 tty_flip_buffer_push(tport);
358 static irqreturn_t asc_interrupt(int irq, void *ptr)
360 struct uart_port *port = ptr;
363 spin_lock(&port->lock);
365 status = asc_in(port, ASC_STA);
367 if (status & ASC_STA_RBF) {
368 /* Receive FIFO not empty */
369 asc_receive_chars(port);
372 if ((status & ASC_STA_THE) &&
373 (asc_in(port, ASC_INTEN) & ASC_INTEN_THE)) {
374 /* Transmitter FIFO at least half empty */
375 asc_transmit_chars(port);
378 spin_unlock(&port->lock);
383 /*----------------------------------------------------------------------*/
389 static unsigned int asc_tx_empty(struct uart_port *port)
391 return asc_txfifo_is_empty(port) ? TIOCSER_TEMT : 0;
394 static void asc_set_mctrl(struct uart_port *port, unsigned int mctrl)
396 struct asc_port *ascport = to_asc_port(port);
399 * This routine is used for seting signals of: DTR, DCD, CTS and RTS.
400 * We use ASC's hardware for CTS/RTS when hardware flow-control is
401 * enabled, however if the RTS line is required for another purpose,
402 * commonly controlled using HUP from userspace, then we need to toggle
403 * it manually, using GPIO.
405 * Some boards also have DTR and DCD implemented using PIO pins, code to
406 * do this should be hooked in here.
412 /* If HW flow-control is enabled, we can't fiddle with the RTS line */
413 if (asc_in(port, ASC_CTL) & ASC_CTL_CTSENABLE)
416 gpiod_set_value(ascport->rts, mctrl & TIOCM_RTS);
419 static unsigned int asc_get_mctrl(struct uart_port *port)
422 * This routine is used for geting signals of: DTR, DCD, DSR, RI,
425 return TIOCM_CAR | TIOCM_DSR | TIOCM_CTS;
428 /* There are probably characters waiting to be transmitted. */
429 static void asc_start_tx(struct uart_port *port)
431 struct circ_buf *xmit = &port->state->xmit;
433 if (!uart_circ_empty(xmit))
434 asc_enable_tx_interrupts(port);
438 static void asc_stop_tx(struct uart_port *port)
440 asc_disable_tx_interrupts(port);
444 static void asc_stop_rx(struct uart_port *port)
446 asc_disable_rx_interrupts(port);
449 /* Handle breaks - ignored by us */
450 static void asc_break_ctl(struct uart_port *port, int break_state)
452 /* Nothing here yet .. */
456 * Enable port for reception.
458 static int asc_startup(struct uart_port *port)
460 if (request_irq(port->irq, asc_interrupt, 0,
461 asc_port_name(port), port)) {
462 dev_err(port->dev, "cannot allocate irq.\n");
466 asc_transmit_chars(port);
467 asc_enable_rx_interrupts(port);
472 static void asc_shutdown(struct uart_port *port)
474 asc_disable_tx_interrupts(port);
475 asc_disable_rx_interrupts(port);
476 free_irq(port->irq, port);
479 static void asc_pm(struct uart_port *port, unsigned int state,
480 unsigned int oldstate)
482 struct asc_port *ascport = to_asc_port(port);
483 unsigned long flags = 0;
487 case UART_PM_STATE_ON:
488 clk_prepare_enable(ascport->clk);
490 case UART_PM_STATE_OFF:
492 * Disable the ASC baud rate generator, which is as close as
493 * we can come to turning it off. Note this is not called with
494 * the port spinlock held.
496 spin_lock_irqsave(&port->lock, flags);
497 ctl = asc_in(port, ASC_CTL) & ~ASC_CTL_RUN;
498 asc_out(port, ASC_CTL, ctl);
499 spin_unlock_irqrestore(&port->lock, flags);
500 clk_disable_unprepare(ascport->clk);
505 static void asc_set_termios(struct uart_port *port, struct ktermios *termios,
506 struct ktermios *old)
508 struct asc_port *ascport = to_asc_port(port);
514 /* Update termios to reflect hardware capabilities */
515 termios->c_cflag &= ~(CMSPAR |
516 (ascport->hw_flow_control ? 0 : CRTSCTS));
518 port->uartclk = clk_get_rate(ascport->clk);
520 baud = uart_get_baud_rate(port, termios, old, 0, port->uartclk/16);
521 cflag = termios->c_cflag;
523 spin_lock_irqsave(&port->lock, flags);
525 /* read control register */
526 ctrl_val = asc_in(port, ASC_CTL);
528 /* stop serial port and reset value */
529 asc_out(port, ASC_CTL, (ctrl_val & ~ASC_CTL_RUN));
530 ctrl_val = ASC_CTL_RXENABLE | ASC_CTL_FIFOENABLE;
532 /* reset fifo rx & tx */
533 asc_out(port, ASC_TXRESET, 1);
534 asc_out(port, ASC_RXRESET, 1);
536 /* set character length */
537 if ((cflag & CSIZE) == CS7) {
538 ctrl_val |= ASC_CTL_MODE_7BIT_PAR;
540 ctrl_val |= (cflag & PARENB) ? ASC_CTL_MODE_8BIT_PAR :
545 ctrl_val |= (cflag & CSTOPB) ? ASC_CTL_STOP_2BIT : ASC_CTL_STOP_1BIT;
549 ctrl_val |= ASC_CTL_PARITYODD;
551 /* hardware flow control */
552 if ((cflag & CRTSCTS))
553 ctrl_val |= ASC_CTL_CTSENABLE;
555 if ((baud < 19200) && !ascport->force_m1) {
556 asc_out(port, ASC_BAUDRATE, (port->uartclk / (16 * baud)));
559 * MODE 1: recommended for high bit rates (above 19.2K)
561 * baudrate * 16 * 2^16
562 * ASCBaudRate = ------------------------
565 * To keep maths inside 64bits, we divide inputclock by 16.
567 u64 dividend = (u64)baud * (1 << 16);
569 do_div(dividend, port->uartclk / 16);
570 asc_out(port, ASC_BAUDRATE, dividend);
571 ctrl_val |= ASC_CTL_BAUDMODE;
574 uart_update_timeout(port, cflag, baud);
576 ascport->port.read_status_mask = ASC_RXBUF_DUMMY_OE;
577 if (termios->c_iflag & INPCK)
578 ascport->port.read_status_mask |= ASC_RXBUF_FE | ASC_RXBUF_PE;
579 if (termios->c_iflag & (IGNBRK | BRKINT | PARMRK))
580 ascport->port.read_status_mask |= ASC_RXBUF_DUMMY_BE;
583 * Characters to ignore
585 ascport->port.ignore_status_mask = 0;
586 if (termios->c_iflag & IGNPAR)
587 ascport->port.ignore_status_mask |= ASC_RXBUF_FE | ASC_RXBUF_PE;
588 if (termios->c_iflag & IGNBRK) {
589 ascport->port.ignore_status_mask |= ASC_RXBUF_DUMMY_BE;
591 * If we're ignoring parity and break indicators,
592 * ignore overruns too (for real raw support).
594 if (termios->c_iflag & IGNPAR)
595 ascport->port.ignore_status_mask |= ASC_RXBUF_DUMMY_OE;
599 * Ignore all characters if CREAD is not set.
601 if (!(termios->c_cflag & CREAD))
602 ascport->port.ignore_status_mask |= ASC_RXBUF_DUMMY_RX;
604 /* Set the timeout */
605 asc_out(port, ASC_TIMEOUT, 20);
607 /* write final value and enable port */
608 asc_out(port, ASC_CTL, (ctrl_val | ASC_CTL_RUN));
610 spin_unlock_irqrestore(&port->lock, flags);
613 static const char *asc_type(struct uart_port *port)
615 return (port->type == PORT_ASC) ? DRIVER_NAME : NULL;
618 static void asc_release_port(struct uart_port *port)
622 static int asc_request_port(struct uart_port *port)
628 * Called when the port is opened, and UPF_BOOT_AUTOCONF flag is set
629 * Set type field if successful
631 static void asc_config_port(struct uart_port *port, int flags)
633 if ((flags & UART_CONFIG_TYPE))
634 port->type = PORT_ASC;
638 asc_verify_port(struct uart_port *port, struct serial_struct *ser)
640 /* No user changeable parameters */
644 #ifdef CONFIG_CONSOLE_POLL
646 * Console polling routines for writing and reading from the uart while
647 * in an interrupt or debug context (i.e. kgdb).
650 static int asc_get_poll_char(struct uart_port *port)
652 if (!(asc_in(port, ASC_STA) & ASC_STA_RBF))
655 return asc_in(port, ASC_RXBUF);
658 static void asc_put_poll_char(struct uart_port *port, unsigned char c)
660 while (!asc_txfifo_is_half_empty(port))
662 asc_out(port, ASC_TXBUF, c);
665 #endif /* CONFIG_CONSOLE_POLL */
667 /*---------------------------------------------------------------------*/
669 static const struct uart_ops asc_uart_ops = {
670 .tx_empty = asc_tx_empty,
671 .set_mctrl = asc_set_mctrl,
672 .get_mctrl = asc_get_mctrl,
673 .start_tx = asc_start_tx,
674 .stop_tx = asc_stop_tx,
675 .stop_rx = asc_stop_rx,
676 .break_ctl = asc_break_ctl,
677 .startup = asc_startup,
678 .shutdown = asc_shutdown,
679 .set_termios = asc_set_termios,
681 .release_port = asc_release_port,
682 .request_port = asc_request_port,
683 .config_port = asc_config_port,
684 .verify_port = asc_verify_port,
686 #ifdef CONFIG_CONSOLE_POLL
687 .poll_get_char = asc_get_poll_char,
688 .poll_put_char = asc_put_poll_char,
689 #endif /* CONFIG_CONSOLE_POLL */
692 static int asc_init_port(struct asc_port *ascport,
693 struct platform_device *pdev)
695 struct uart_port *port = &ascport->port;
696 struct resource *res;
698 port->iotype = UPIO_MEM;
699 port->flags = UPF_BOOT_AUTOCONF;
700 port->ops = &asc_uart_ops;
701 port->fifosize = ASC_FIFO_SIZE;
702 port->dev = &pdev->dev;
703 port->irq = platform_get_irq(pdev, 0);
705 res = platform_get_resource(pdev, IORESOURCE_MEM, 0);
706 port->membase = devm_ioremap_resource(&pdev->dev, res);
707 if (IS_ERR(port->membase))
708 return PTR_ERR(port->membase);
709 port->mapbase = res->start;
711 spin_lock_init(&port->lock);
713 ascport->clk = devm_clk_get(&pdev->dev, NULL);
715 if (WARN_ON(IS_ERR(ascport->clk)))
717 /* ensure that clk rate is correct by enabling the clk */
718 clk_prepare_enable(ascport->clk);
719 ascport->port.uartclk = clk_get_rate(ascport->clk);
720 WARN_ON(ascport->port.uartclk == 0);
721 clk_disable_unprepare(ascport->clk);
726 static struct asc_port *asc_of_get_asc_port(struct platform_device *pdev)
728 struct device_node *np = pdev->dev.of_node;
734 id = of_alias_get_id(np, ASC_SERIAL_NAME);
739 if (WARN_ON(id >= ASC_MAX_PORTS))
742 asc_ports[id].hw_flow_control = of_property_read_bool(np,
743 "st,hw-flow-control");
744 asc_ports[id].force_m1 = of_property_read_bool(np, "st,force_m1");
745 asc_ports[id].port.line = id;
746 asc_ports[id].rts = NULL;
748 return &asc_ports[id];
752 static const struct of_device_id asc_match[] = {
753 { .compatible = "st,asc", },
757 MODULE_DEVICE_TABLE(of, asc_match);
760 static int asc_serial_probe(struct platform_device *pdev)
763 struct asc_port *ascport;
765 ascport = asc_of_get_asc_port(pdev);
769 ret = asc_init_port(ascport, pdev);
773 ret = uart_add_one_port(&asc_uart_driver, &ascport->port);
777 platform_set_drvdata(pdev, &ascport->port);
782 static int asc_serial_remove(struct platform_device *pdev)
784 struct uart_port *port = platform_get_drvdata(pdev);
786 return uart_remove_one_port(&asc_uart_driver, port);
789 #ifdef CONFIG_PM_SLEEP
790 static int asc_serial_suspend(struct device *dev)
792 struct platform_device *pdev = to_platform_device(dev);
793 struct uart_port *port = platform_get_drvdata(pdev);
795 return uart_suspend_port(&asc_uart_driver, port);
798 static int asc_serial_resume(struct device *dev)
800 struct platform_device *pdev = to_platform_device(dev);
801 struct uart_port *port = platform_get_drvdata(pdev);
803 return uart_resume_port(&asc_uart_driver, port);
806 #endif /* CONFIG_PM_SLEEP */
808 /*----------------------------------------------------------------------*/
810 #ifdef CONFIG_SERIAL_ST_ASC_CONSOLE
811 static void asc_console_putchar(struct uart_port *port, int ch)
813 unsigned int timeout = 1000000;
815 /* Wait for upto 1 second in case flow control is stopping us. */
816 while (--timeout && !asc_txfifo_is_half_empty(port))
819 asc_out(port, ASC_TXBUF, ch);
823 * Print a string to the serial port trying not to disturb
824 * any possible real use of the port...
827 static void asc_console_write(struct console *co, const char *s, unsigned count)
829 struct uart_port *port = &asc_ports[co->index].port;
831 unsigned long timeout = 1000000;
835 local_irq_save(flags);
837 locked = 0; /* asc_interrupt has already claimed the lock */
838 else if (oops_in_progress)
839 locked = spin_trylock(&port->lock);
841 spin_lock(&port->lock);
844 * Disable interrupts so we don't get the IRQ line bouncing
845 * up and down while interrupts are disabled.
847 intenable = asc_in(port, ASC_INTEN);
848 asc_out(port, ASC_INTEN, 0);
849 (void)asc_in(port, ASC_INTEN); /* Defeat bus write posting */
851 uart_console_write(port, s, count, asc_console_putchar);
853 while (--timeout && !asc_txfifo_is_empty(port))
856 asc_out(port, ASC_INTEN, intenable);
859 spin_unlock(&port->lock);
860 local_irq_restore(flags);
863 static int asc_console_setup(struct console *co, char *options)
865 struct asc_port *ascport;
871 if (co->index >= ASC_MAX_PORTS)
874 ascport = &asc_ports[co->index];
877 * This driver does not support early console initialization
878 * (use ARM early printk support instead), so we only expect
879 * this to be called during the uart port registration when the
880 * driver gets probed and the port should be mapped at that point.
882 if (ascport->port.mapbase == 0 || ascport->port.membase == NULL)
886 uart_parse_options(options, &baud, &parity, &bits, &flow);
888 return uart_set_options(&ascport->port, co, baud, parity, bits, flow);
891 static struct console asc_console = {
892 .name = ASC_SERIAL_NAME,
893 .device = uart_console_device,
894 .write = asc_console_write,
895 .setup = asc_console_setup,
896 .flags = CON_PRINTBUFFER,
898 .data = &asc_uart_driver,
901 #define ASC_SERIAL_CONSOLE (&asc_console)
904 #define ASC_SERIAL_CONSOLE NULL
905 #endif /* CONFIG_SERIAL_ST_ASC_CONSOLE */
907 static struct uart_driver asc_uart_driver = {
908 .owner = THIS_MODULE,
909 .driver_name = DRIVER_NAME,
910 .dev_name = ASC_SERIAL_NAME,
914 .cons = ASC_SERIAL_CONSOLE,
917 static const struct dev_pm_ops asc_serial_pm_ops = {
918 SET_SYSTEM_SLEEP_PM_OPS(asc_serial_suspend, asc_serial_resume)
921 static struct platform_driver asc_serial_driver = {
922 .probe = asc_serial_probe,
923 .remove = asc_serial_remove,
926 .pm = &asc_serial_pm_ops,
927 .of_match_table = of_match_ptr(asc_match),
931 static int __init asc_init(void)
934 static char banner[] __initdata =
935 KERN_INFO "STMicroelectronics ASC driver initialized\n";
939 ret = uart_register_driver(&asc_uart_driver);
943 ret = platform_driver_register(&asc_serial_driver);
945 uart_unregister_driver(&asc_uart_driver);
950 static void __exit asc_exit(void)
952 platform_driver_unregister(&asc_serial_driver);
953 uart_unregister_driver(&asc_uart_driver);
956 module_init(asc_init);
957 module_exit(asc_exit);
959 MODULE_ALIAS("platform:" DRIVER_NAME);
960 MODULE_AUTHOR("STMicroelectronics (R&D) Limited");
961 MODULE_DESCRIPTION("STMicroelectronics ASC serial port driver");
962 MODULE_LICENSE("GPL");