1 // SPDX-License-Identifier: GPL-2.0
3 * Driver core for Samsung SoC onboard UARTs.
5 * Ben Dooks, Copyright (c) 2003-2008 Simtec Electronics
6 * http://armlinux.simtec.co.uk/
9 /* Note on 2410 error handling
11 * The s3c2410 manual has a love/hate affair with the contents of the
12 * UERSTAT register in the UART blocks, and keeps marking some of the
13 * error bits as reserved. Having checked with the s3c2410x01,
14 * it copes with BREAKs properly, so I am happy to ignore the RESERVED
15 * feature from the latter versions of the manual.
17 * If it becomes aparrent that latter versions of the 2410 remove these
18 * bits, then action will have to be taken to differentiate the versions
19 * and change the policy on BREAK
24 #include <linux/dmaengine.h>
25 #include <linux/dma-mapping.h>
26 #include <linux/slab.h>
27 #include <linux/module.h>
28 #include <linux/ioport.h>
30 #include <linux/platform_device.h>
31 #include <linux/init.h>
32 #include <linux/sysrq.h>
33 #include <linux/console.h>
34 #include <linux/tty.h>
35 #include <linux/tty_flip.h>
36 #include <linux/serial_core.h>
37 #include <linux/serial.h>
38 #include <linux/serial_s3c.h>
39 #include <linux/delay.h>
40 #include <linux/clk.h>
41 #include <linux/cpufreq.h>
45 /* UART name and device definitions */
47 #define S3C24XX_SERIAL_NAME "ttySAC"
48 #define S3C24XX_SERIAL_MAJOR 204
49 #define S3C24XX_SERIAL_MINOR 64
54 #define UART_NR CONFIG_SERIAL_SAMSUNG_UARTS
57 #define S3C24XX_TX_PIO 1
58 #define S3C24XX_TX_DMA 2
59 #define S3C24XX_RX_PIO 1
60 #define S3C24XX_RX_DMA 2
62 /* flag to ignore all characters coming in */
63 #define RXSTAT_DUMMY_READ (0x10000000)
65 enum s3c24xx_port_type {
71 struct s3c24xx_uart_info {
73 enum s3c24xx_port_type type;
74 unsigned int port_type;
75 unsigned int fifosize;
76 unsigned long rx_fifomask;
77 unsigned long rx_fifoshift;
78 unsigned long rx_fifofull;
79 unsigned long tx_fifomask;
80 unsigned long tx_fifoshift;
81 unsigned long tx_fifofull;
82 unsigned int def_clk_sel;
83 unsigned long num_clks;
84 unsigned long clksel_mask;
85 unsigned long clksel_shift;
86 unsigned long ucon_mask;
88 /* uart port features */
90 unsigned int has_divslot:1;
93 struct s3c24xx_serial_drv_data {
94 const struct s3c24xx_uart_info info;
95 const struct s3c2410_uartcfg def_cfg;
96 const unsigned int fifosize[UART_NR];
99 struct s3c24xx_uart_dma {
100 unsigned int rx_chan_id;
101 unsigned int tx_chan_id;
103 struct dma_slave_config rx_conf;
104 struct dma_slave_config tx_conf;
106 struct dma_chan *rx_chan;
107 struct dma_chan *tx_chan;
112 dma_cookie_t rx_cookie;
113 dma_cookie_t tx_cookie;
117 dma_addr_t tx_transfer_addr;
122 struct dma_async_tx_descriptor *tx_desc;
123 struct dma_async_tx_descriptor *rx_desc;
125 int tx_bytes_requested;
126 int rx_bytes_requested;
129 struct s3c24xx_uart_port {
130 unsigned char rx_claimed;
131 unsigned char tx_claimed;
132 unsigned char rx_enabled;
133 unsigned char tx_enabled;
134 unsigned int pm_level;
135 unsigned long baudclk_rate;
136 unsigned int min_dma_size;
141 unsigned int tx_in_progress;
142 unsigned int tx_mode;
143 unsigned int rx_mode;
145 const struct s3c24xx_uart_info *info;
148 struct uart_port port;
149 const struct s3c24xx_serial_drv_data *drv_data;
151 /* reference to platform data */
152 const struct s3c2410_uartcfg *cfg;
154 struct s3c24xx_uart_dma *dma;
156 #ifdef CONFIG_ARM_S3C24XX_CPUFREQ
157 struct notifier_block freq_transition;
161 static void s3c24xx_serial_tx_chars(struct s3c24xx_uart_port *ourport);
163 /* conversion functions */
165 #define s3c24xx_dev_to_port(__dev) dev_get_drvdata(__dev)
167 /* register access controls */
169 #define portaddr(port, reg) ((port)->membase + (reg))
170 #define portaddrl(port, reg) \
171 ((unsigned long *)(unsigned long)((port)->membase + (reg)))
173 static u32 rd_reg(const struct uart_port *port, u32 reg)
175 switch (port->iotype) {
177 return readb_relaxed(portaddr(port, reg));
179 return readl_relaxed(portaddr(port, reg));
186 #define rd_regl(port, reg) (readl_relaxed(portaddr(port, reg)))
188 static void wr_reg(const struct uart_port *port, u32 reg, u32 val)
190 switch (port->iotype) {
192 writeb_relaxed(val, portaddr(port, reg));
195 writel_relaxed(val, portaddr(port, reg));
200 #define wr_regl(port, reg, val) writel_relaxed(val, portaddr(port, reg))
202 /* Byte-order aware bit setting/clearing functions. */
204 static inline void s3c24xx_set_bit(const struct uart_port *port, int idx,
210 local_irq_save(flags);
211 val = rd_regl(port, reg);
213 wr_regl(port, reg, val);
214 local_irq_restore(flags);
217 static inline void s3c24xx_clear_bit(const struct uart_port *port, int idx,
223 local_irq_save(flags);
224 val = rd_regl(port, reg);
226 wr_regl(port, reg, val);
227 local_irq_restore(flags);
230 static inline struct s3c24xx_uart_port *to_ourport(struct uart_port *port)
232 return container_of(port, struct s3c24xx_uart_port, port);
235 /* translate a port to the device name */
237 static inline const char *s3c24xx_serial_portname(const struct uart_port *port)
239 return to_platform_device(port->dev)->name;
242 static int s3c24xx_serial_txempty_nofifo(const struct uart_port *port)
244 return rd_regl(port, S3C2410_UTRSTAT) & S3C2410_UTRSTAT_TXE;
247 static void s3c24xx_serial_rx_enable(struct uart_port *port)
249 struct s3c24xx_uart_port *ourport = to_ourport(port);
251 unsigned int ucon, ufcon;
254 spin_lock_irqsave(&port->lock, flags);
256 while (--count && !s3c24xx_serial_txempty_nofifo(port))
259 ufcon = rd_regl(port, S3C2410_UFCON);
260 ufcon |= S3C2410_UFCON_RESETRX;
261 wr_regl(port, S3C2410_UFCON, ufcon);
263 ucon = rd_regl(port, S3C2410_UCON);
264 ucon |= S3C2410_UCON_RXIRQMODE;
265 wr_regl(port, S3C2410_UCON, ucon);
267 ourport->rx_enabled = 1;
268 spin_unlock_irqrestore(&port->lock, flags);
271 static void s3c24xx_serial_rx_disable(struct uart_port *port)
273 struct s3c24xx_uart_port *ourport = to_ourport(port);
277 spin_lock_irqsave(&port->lock, flags);
279 ucon = rd_regl(port, S3C2410_UCON);
280 ucon &= ~S3C2410_UCON_RXIRQMODE;
281 wr_regl(port, S3C2410_UCON, ucon);
283 ourport->rx_enabled = 0;
284 spin_unlock_irqrestore(&port->lock, flags);
287 static void s3c24xx_serial_stop_tx(struct uart_port *port)
289 struct s3c24xx_uart_port *ourport = to_ourport(port);
290 struct s3c24xx_uart_dma *dma = ourport->dma;
291 struct circ_buf *xmit = &port->state->xmit;
292 struct dma_tx_state state;
295 if (!ourport->tx_enabled)
298 switch (ourport->info->type) {
300 s3c24xx_set_bit(port, S3C64XX_UINTM_TXD, S3C64XX_UINTM);
303 s3c24xx_clear_bit(port, APPLE_S5L_UCON_TXTHRESH_ENA, S3C2410_UCON);
306 disable_irq_nosync(ourport->tx_irq);
310 if (dma && dma->tx_chan && ourport->tx_in_progress == S3C24XX_TX_DMA) {
311 dmaengine_pause(dma->tx_chan);
312 dmaengine_tx_status(dma->tx_chan, dma->tx_cookie, &state);
313 dmaengine_terminate_all(dma->tx_chan);
314 dma_sync_single_for_cpu(dma->tx_chan->device->dev,
315 dma->tx_transfer_addr, dma->tx_size,
317 async_tx_ack(dma->tx_desc);
318 count = dma->tx_bytes_requested - state.residue;
319 xmit->tail = (xmit->tail + count) & (UART_XMIT_SIZE - 1);
320 port->icount.tx += count;
323 ourport->tx_enabled = 0;
324 ourport->tx_in_progress = 0;
326 if (port->flags & UPF_CONS_FLOW)
327 s3c24xx_serial_rx_enable(port);
329 ourport->tx_mode = 0;
332 static void s3c24xx_serial_start_next_tx(struct s3c24xx_uart_port *ourport);
334 static void s3c24xx_serial_tx_dma_complete(void *args)
336 struct s3c24xx_uart_port *ourport = args;
337 struct uart_port *port = &ourport->port;
338 struct circ_buf *xmit = &port->state->xmit;
339 struct s3c24xx_uart_dma *dma = ourport->dma;
340 struct dma_tx_state state;
344 dmaengine_tx_status(dma->tx_chan, dma->tx_cookie, &state);
345 count = dma->tx_bytes_requested - state.residue;
346 async_tx_ack(dma->tx_desc);
348 dma_sync_single_for_cpu(dma->tx_chan->device->dev,
349 dma->tx_transfer_addr, dma->tx_size,
352 spin_lock_irqsave(&port->lock, flags);
354 xmit->tail = (xmit->tail + count) & (UART_XMIT_SIZE - 1);
355 port->icount.tx += count;
356 ourport->tx_in_progress = 0;
358 if (uart_circ_chars_pending(xmit) < WAKEUP_CHARS)
359 uart_write_wakeup(port);
361 s3c24xx_serial_start_next_tx(ourport);
362 spin_unlock_irqrestore(&port->lock, flags);
365 static void enable_tx_dma(struct s3c24xx_uart_port *ourport)
367 const struct uart_port *port = &ourport->port;
370 /* Mask Tx interrupt */
371 switch (ourport->info->type) {
373 s3c24xx_set_bit(port, S3C64XX_UINTM_TXD, S3C64XX_UINTM);
376 WARN_ON(1); // No DMA
379 disable_irq_nosync(ourport->tx_irq);
383 /* Enable tx dma mode */
384 ucon = rd_regl(port, S3C2410_UCON);
385 ucon &= ~(S3C64XX_UCON_TXBURST_MASK | S3C64XX_UCON_TXMODE_MASK);
386 ucon |= S3C64XX_UCON_TXBURST_1;
387 ucon |= S3C64XX_UCON_TXMODE_DMA;
388 wr_regl(port, S3C2410_UCON, ucon);
390 ourport->tx_mode = S3C24XX_TX_DMA;
393 static void enable_tx_pio(struct s3c24xx_uart_port *ourport)
395 const struct uart_port *port = &ourport->port;
398 /* Set ufcon txtrig */
399 ourport->tx_in_progress = S3C24XX_TX_PIO;
400 ufcon = rd_regl(port, S3C2410_UFCON);
401 wr_regl(port, S3C2410_UFCON, ufcon);
403 /* Enable tx pio mode */
404 ucon = rd_regl(port, S3C2410_UCON);
405 ucon &= ~(S3C64XX_UCON_TXMODE_MASK);
406 ucon |= S3C64XX_UCON_TXMODE_CPU;
407 wr_regl(port, S3C2410_UCON, ucon);
409 /* Unmask Tx interrupt */
410 switch (ourport->info->type) {
412 s3c24xx_clear_bit(port, S3C64XX_UINTM_TXD,
416 ucon |= APPLE_S5L_UCON_TXTHRESH_ENA_MSK;
417 wr_regl(port, S3C2410_UCON, ucon);
420 enable_irq(ourport->tx_irq);
424 ourport->tx_mode = S3C24XX_TX_PIO;
427 * The Apple version only has edge triggered TX IRQs, so we need
428 * to kick off the process by sending some characters here.
430 if (ourport->info->type == TYPE_APPLE_S5L)
431 s3c24xx_serial_tx_chars(ourport);
434 static void s3c24xx_serial_start_tx_pio(struct s3c24xx_uart_port *ourport)
436 if (ourport->tx_mode != S3C24XX_TX_PIO)
437 enable_tx_pio(ourport);
440 static int s3c24xx_serial_start_tx_dma(struct s3c24xx_uart_port *ourport,
443 struct uart_port *port = &ourport->port;
444 struct circ_buf *xmit = &port->state->xmit;
445 struct s3c24xx_uart_dma *dma = ourport->dma;
447 if (ourport->tx_mode != S3C24XX_TX_DMA)
448 enable_tx_dma(ourport);
450 dma->tx_size = count & ~(dma_get_cache_alignment() - 1);
451 dma->tx_transfer_addr = dma->tx_addr + xmit->tail;
453 dma_sync_single_for_device(dma->tx_chan->device->dev,
454 dma->tx_transfer_addr, dma->tx_size,
457 dma->tx_desc = dmaengine_prep_slave_single(dma->tx_chan,
458 dma->tx_transfer_addr, dma->tx_size,
459 DMA_MEM_TO_DEV, DMA_PREP_INTERRUPT);
461 dev_err(ourport->port.dev, "Unable to get desc for Tx\n");
465 dma->tx_desc->callback = s3c24xx_serial_tx_dma_complete;
466 dma->tx_desc->callback_param = ourport;
467 dma->tx_bytes_requested = dma->tx_size;
469 ourport->tx_in_progress = S3C24XX_TX_DMA;
470 dma->tx_cookie = dmaengine_submit(dma->tx_desc);
471 dma_async_issue_pending(dma->tx_chan);
475 static void s3c24xx_serial_start_next_tx(struct s3c24xx_uart_port *ourport)
477 struct uart_port *port = &ourport->port;
478 struct circ_buf *xmit = &port->state->xmit;
481 /* Get data size up to the end of buffer */
482 count = CIRC_CNT_TO_END(xmit->head, xmit->tail, UART_XMIT_SIZE);
485 s3c24xx_serial_stop_tx(port);
489 if (!ourport->dma || !ourport->dma->tx_chan ||
490 count < ourport->min_dma_size ||
491 xmit->tail & (dma_get_cache_alignment() - 1))
492 s3c24xx_serial_start_tx_pio(ourport);
494 s3c24xx_serial_start_tx_dma(ourport, count);
497 static void s3c24xx_serial_start_tx(struct uart_port *port)
499 struct s3c24xx_uart_port *ourport = to_ourport(port);
500 struct circ_buf *xmit = &port->state->xmit;
502 if (!ourport->tx_enabled) {
503 if (port->flags & UPF_CONS_FLOW)
504 s3c24xx_serial_rx_disable(port);
506 ourport->tx_enabled = 1;
507 if (!ourport->dma || !ourport->dma->tx_chan)
508 s3c24xx_serial_start_tx_pio(ourport);
511 if (ourport->dma && ourport->dma->tx_chan) {
512 if (!uart_circ_empty(xmit) && !ourport->tx_in_progress)
513 s3c24xx_serial_start_next_tx(ourport);
517 static void s3c24xx_uart_copy_rx_to_tty(struct s3c24xx_uart_port *ourport,
518 struct tty_port *tty, int count)
520 struct s3c24xx_uart_dma *dma = ourport->dma;
526 dma_sync_single_for_cpu(dma->rx_chan->device->dev, dma->rx_addr,
527 dma->rx_size, DMA_FROM_DEVICE);
529 ourport->port.icount.rx += count;
531 dev_err(ourport->port.dev, "No tty port\n");
534 copied = tty_insert_flip_string(tty,
535 ((unsigned char *)(ourport->dma->rx_buf)), count);
536 if (copied != count) {
538 dev_err(ourport->port.dev, "RxData copy to tty layer failed\n");
542 static void s3c24xx_serial_stop_rx(struct uart_port *port)
544 struct s3c24xx_uart_port *ourport = to_ourport(port);
545 struct s3c24xx_uart_dma *dma = ourport->dma;
546 struct tty_port *t = &port->state->port;
547 struct dma_tx_state state;
548 enum dma_status dma_status;
549 unsigned int received;
551 if (ourport->rx_enabled) {
552 dev_dbg(port->dev, "stopping rx\n");
553 switch (ourport->info->type) {
555 s3c24xx_set_bit(port, S3C64XX_UINTM_RXD,
559 s3c24xx_clear_bit(port, APPLE_S5L_UCON_RXTHRESH_ENA, S3C2410_UCON);
560 s3c24xx_clear_bit(port, APPLE_S5L_UCON_RXTO_ENA, S3C2410_UCON);
563 disable_irq_nosync(ourport->rx_irq);
566 ourport->rx_enabled = 0;
568 if (dma && dma->rx_chan) {
569 dmaengine_pause(dma->tx_chan);
570 dma_status = dmaengine_tx_status(dma->rx_chan,
571 dma->rx_cookie, &state);
572 if (dma_status == DMA_IN_PROGRESS ||
573 dma_status == DMA_PAUSED) {
574 received = dma->rx_bytes_requested - state.residue;
575 dmaengine_terminate_all(dma->rx_chan);
576 s3c24xx_uart_copy_rx_to_tty(ourport, t, received);
581 static inline const struct s3c24xx_uart_info
582 *s3c24xx_port_to_info(struct uart_port *port)
584 return to_ourport(port)->info;
587 static inline const struct s3c2410_uartcfg
588 *s3c24xx_port_to_cfg(const struct uart_port *port)
590 const struct s3c24xx_uart_port *ourport;
592 if (port->dev == NULL)
595 ourport = container_of(port, struct s3c24xx_uart_port, port);
599 static int s3c24xx_serial_rx_fifocnt(const struct s3c24xx_uart_port *ourport,
600 unsigned long ufstat)
602 const struct s3c24xx_uart_info *info = ourport->info;
604 if (ufstat & info->rx_fifofull)
605 return ourport->port.fifosize;
607 return (ufstat & info->rx_fifomask) >> info->rx_fifoshift;
610 static void s3c64xx_start_rx_dma(struct s3c24xx_uart_port *ourport);
611 static void s3c24xx_serial_rx_dma_complete(void *args)
613 struct s3c24xx_uart_port *ourport = args;
614 struct uart_port *port = &ourport->port;
616 struct s3c24xx_uart_dma *dma = ourport->dma;
617 struct tty_port *t = &port->state->port;
618 struct tty_struct *tty = tty_port_tty_get(&ourport->port.state->port);
620 struct dma_tx_state state;
624 dmaengine_tx_status(dma->rx_chan, dma->rx_cookie, &state);
625 received = dma->rx_bytes_requested - state.residue;
626 async_tx_ack(dma->rx_desc);
628 spin_lock_irqsave(&port->lock, flags);
631 s3c24xx_uart_copy_rx_to_tty(ourport, t, received);
634 tty_flip_buffer_push(t);
638 s3c64xx_start_rx_dma(ourport);
640 spin_unlock_irqrestore(&port->lock, flags);
643 static void s3c64xx_start_rx_dma(struct s3c24xx_uart_port *ourport)
645 struct s3c24xx_uart_dma *dma = ourport->dma;
647 dma_sync_single_for_device(dma->rx_chan->device->dev, dma->rx_addr,
648 dma->rx_size, DMA_FROM_DEVICE);
650 dma->rx_desc = dmaengine_prep_slave_single(dma->rx_chan,
651 dma->rx_addr, dma->rx_size, DMA_DEV_TO_MEM,
654 dev_err(ourport->port.dev, "Unable to get desc for Rx\n");
658 dma->rx_desc->callback = s3c24xx_serial_rx_dma_complete;
659 dma->rx_desc->callback_param = ourport;
660 dma->rx_bytes_requested = dma->rx_size;
662 dma->rx_cookie = dmaengine_submit(dma->rx_desc);
663 dma_async_issue_pending(dma->rx_chan);
666 /* ? - where has parity gone?? */
667 #define S3C2410_UERSTAT_PARITY (0x1000)
669 static void enable_rx_dma(struct s3c24xx_uart_port *ourport)
671 struct uart_port *port = &ourport->port;
674 /* set Rx mode to DMA mode */
675 ucon = rd_regl(port, S3C2410_UCON);
676 ucon &= ~(S3C64XX_UCON_RXBURST_MASK |
677 S3C64XX_UCON_TIMEOUT_MASK |
678 S3C64XX_UCON_EMPTYINT_EN |
679 S3C64XX_UCON_DMASUS_EN |
680 S3C64XX_UCON_TIMEOUT_EN |
681 S3C64XX_UCON_RXMODE_MASK);
682 ucon |= S3C64XX_UCON_RXBURST_1 |
683 0xf << S3C64XX_UCON_TIMEOUT_SHIFT |
684 S3C64XX_UCON_EMPTYINT_EN |
685 S3C64XX_UCON_TIMEOUT_EN |
686 S3C64XX_UCON_RXMODE_DMA;
687 wr_regl(port, S3C2410_UCON, ucon);
689 ourport->rx_mode = S3C24XX_RX_DMA;
692 static void enable_rx_pio(struct s3c24xx_uart_port *ourport)
694 struct uart_port *port = &ourport->port;
697 /* set Rx mode to DMA mode */
698 ucon = rd_regl(port, S3C2410_UCON);
699 ucon &= ~S3C64XX_UCON_RXMODE_MASK;
700 ucon |= S3C64XX_UCON_RXMODE_CPU;
702 /* Apple types use these bits for IRQ masks */
703 if (ourport->info->type != TYPE_APPLE_S5L) {
704 ucon &= ~(S3C64XX_UCON_TIMEOUT_MASK |
705 S3C64XX_UCON_EMPTYINT_EN |
706 S3C64XX_UCON_DMASUS_EN |
707 S3C64XX_UCON_TIMEOUT_EN);
708 ucon |= 0xf << S3C64XX_UCON_TIMEOUT_SHIFT |
709 S3C64XX_UCON_TIMEOUT_EN;
711 wr_regl(port, S3C2410_UCON, ucon);
713 ourport->rx_mode = S3C24XX_RX_PIO;
716 static void s3c24xx_serial_rx_drain_fifo(struct s3c24xx_uart_port *ourport);
718 static irqreturn_t s3c24xx_serial_rx_chars_dma(void *dev_id)
720 unsigned int utrstat, received;
721 struct s3c24xx_uart_port *ourport = dev_id;
722 struct uart_port *port = &ourport->port;
723 struct s3c24xx_uart_dma *dma = ourport->dma;
724 struct tty_struct *tty = tty_port_tty_get(&ourport->port.state->port);
725 struct tty_port *t = &port->state->port;
726 struct dma_tx_state state;
728 utrstat = rd_regl(port, S3C2410_UTRSTAT);
729 rd_regl(port, S3C2410_UFSTAT);
731 spin_lock(&port->lock);
733 if (!(utrstat & S3C2410_UTRSTAT_TIMEOUT)) {
734 s3c64xx_start_rx_dma(ourport);
735 if (ourport->rx_mode == S3C24XX_RX_PIO)
736 enable_rx_dma(ourport);
740 if (ourport->rx_mode == S3C24XX_RX_DMA) {
741 dmaengine_pause(dma->rx_chan);
742 dmaengine_tx_status(dma->rx_chan, dma->rx_cookie, &state);
743 dmaengine_terminate_all(dma->rx_chan);
744 received = dma->rx_bytes_requested - state.residue;
745 s3c24xx_uart_copy_rx_to_tty(ourport, t, received);
747 enable_rx_pio(ourport);
750 s3c24xx_serial_rx_drain_fifo(ourport);
753 tty_flip_buffer_push(t);
757 wr_regl(port, S3C2410_UTRSTAT, S3C2410_UTRSTAT_TIMEOUT);
760 spin_unlock(&port->lock);
765 static void s3c24xx_serial_rx_drain_fifo(struct s3c24xx_uart_port *ourport)
767 struct uart_port *port = &ourport->port;
768 unsigned int ufcon, ch, flag, ufstat, uerstat;
769 unsigned int fifocnt = 0;
770 int max_count = port->fifosize;
772 while (max_count-- > 0) {
774 * Receive all characters known to be in FIFO
775 * before reading FIFO level again
778 ufstat = rd_regl(port, S3C2410_UFSTAT);
779 fifocnt = s3c24xx_serial_rx_fifocnt(ourport, ufstat);
785 uerstat = rd_regl(port, S3C2410_UERSTAT);
786 ch = rd_reg(port, S3C2410_URXH);
788 if (port->flags & UPF_CONS_FLOW) {
789 int txe = s3c24xx_serial_txempty_nofifo(port);
791 if (ourport->rx_enabled) {
793 ourport->rx_enabled = 0;
798 ufcon = rd_regl(port, S3C2410_UFCON);
799 ufcon |= S3C2410_UFCON_RESETRX;
800 wr_regl(port, S3C2410_UFCON, ufcon);
801 ourport->rx_enabled = 1;
808 /* insert the character into the buffer */
813 if (unlikely(uerstat & S3C2410_UERSTAT_ANY)) {
815 "rxerr: port ch=0x%02x, rxs=0x%08x\n",
818 /* check for break */
819 if (uerstat & S3C2410_UERSTAT_BREAK) {
820 dev_dbg(port->dev, "break!\n");
822 if (uart_handle_break(port))
823 continue; /* Ignore character */
826 if (uerstat & S3C2410_UERSTAT_FRAME)
827 port->icount.frame++;
828 if (uerstat & S3C2410_UERSTAT_OVERRUN)
829 port->icount.overrun++;
831 uerstat &= port->read_status_mask;
833 if (uerstat & S3C2410_UERSTAT_BREAK)
835 else if (uerstat & S3C2410_UERSTAT_PARITY)
837 else if (uerstat & (S3C2410_UERSTAT_FRAME |
838 S3C2410_UERSTAT_OVERRUN))
842 if (uart_handle_sysrq_char(port, ch))
843 continue; /* Ignore character */
845 uart_insert_char(port, uerstat, S3C2410_UERSTAT_OVERRUN,
849 tty_flip_buffer_push(&port->state->port);
852 static irqreturn_t s3c24xx_serial_rx_chars_pio(void *dev_id)
854 struct s3c24xx_uart_port *ourport = dev_id;
855 struct uart_port *port = &ourport->port;
857 spin_lock(&port->lock);
858 s3c24xx_serial_rx_drain_fifo(ourport);
859 spin_unlock(&port->lock);
864 static irqreturn_t s3c24xx_serial_rx_irq(int irq, void *dev_id)
866 struct s3c24xx_uart_port *ourport = dev_id;
868 if (ourport->dma && ourport->dma->rx_chan)
869 return s3c24xx_serial_rx_chars_dma(dev_id);
870 return s3c24xx_serial_rx_chars_pio(dev_id);
873 static void s3c24xx_serial_tx_chars(struct s3c24xx_uart_port *ourport)
875 struct uart_port *port = &ourport->port;
876 struct circ_buf *xmit = &port->state->xmit;
877 int count, dma_count = 0;
879 count = CIRC_CNT_TO_END(xmit->head, xmit->tail, UART_XMIT_SIZE);
881 if (ourport->dma && ourport->dma->tx_chan &&
882 count >= ourport->min_dma_size) {
883 int align = dma_get_cache_alignment() -
884 (xmit->tail & (dma_get_cache_alignment() - 1));
885 if (count - align >= ourport->min_dma_size) {
886 dma_count = count - align;
892 wr_reg(port, S3C2410_UTXH, port->x_char);
898 /* if there isn't anything more to transmit, or the uart is now
899 * stopped, disable the uart and exit
902 if (uart_circ_empty(xmit) || uart_tx_stopped(port)) {
903 s3c24xx_serial_stop_tx(port);
907 /* try and drain the buffer... */
909 if (count > port->fifosize) {
910 count = port->fifosize;
914 while (!uart_circ_empty(xmit) && count > 0) {
915 if (rd_regl(port, S3C2410_UFSTAT) & ourport->info->tx_fifofull)
918 wr_reg(port, S3C2410_UTXH, xmit->buf[xmit->tail]);
919 xmit->tail = (xmit->tail + 1) & (UART_XMIT_SIZE - 1);
924 if (!count && dma_count) {
925 s3c24xx_serial_start_tx_dma(ourport, dma_count);
929 if (uart_circ_chars_pending(xmit) < WAKEUP_CHARS)
930 uart_write_wakeup(port);
932 if (uart_circ_empty(xmit))
933 s3c24xx_serial_stop_tx(port);
936 static irqreturn_t s3c24xx_serial_tx_irq(int irq, void *id)
938 struct s3c24xx_uart_port *ourport = id;
939 struct uart_port *port = &ourport->port;
941 spin_lock(&port->lock);
943 s3c24xx_serial_tx_chars(ourport);
945 spin_unlock(&port->lock);
949 /* interrupt handler for s3c64xx and later SoC's.*/
950 static irqreturn_t s3c64xx_serial_handle_irq(int irq, void *id)
952 const struct s3c24xx_uart_port *ourport = id;
953 const struct uart_port *port = &ourport->port;
954 unsigned int pend = rd_regl(port, S3C64XX_UINTP);
955 irqreturn_t ret = IRQ_HANDLED;
957 if (pend & S3C64XX_UINTM_RXD_MSK) {
958 ret = s3c24xx_serial_rx_irq(irq, id);
959 wr_regl(port, S3C64XX_UINTP, S3C64XX_UINTM_RXD_MSK);
961 if (pend & S3C64XX_UINTM_TXD_MSK) {
962 ret = s3c24xx_serial_tx_irq(irq, id);
963 wr_regl(port, S3C64XX_UINTP, S3C64XX_UINTM_TXD_MSK);
968 /* interrupt handler for Apple SoC's.*/
969 static irqreturn_t apple_serial_handle_irq(int irq, void *id)
971 const struct s3c24xx_uart_port *ourport = id;
972 const struct uart_port *port = &ourport->port;
973 unsigned int pend = rd_regl(port, S3C2410_UTRSTAT);
974 irqreturn_t ret = IRQ_NONE;
976 if (pend & (APPLE_S5L_UTRSTAT_RXTHRESH | APPLE_S5L_UTRSTAT_RXTO)) {
977 wr_regl(port, S3C2410_UTRSTAT,
978 APPLE_S5L_UTRSTAT_RXTHRESH | APPLE_S5L_UTRSTAT_RXTO);
979 ret = s3c24xx_serial_rx_irq(irq, id);
981 if (pend & APPLE_S5L_UTRSTAT_TXTHRESH) {
982 wr_regl(port, S3C2410_UTRSTAT, APPLE_S5L_UTRSTAT_TXTHRESH);
983 ret = s3c24xx_serial_tx_irq(irq, id);
989 static unsigned int s3c24xx_serial_tx_empty(struct uart_port *port)
991 const struct s3c24xx_uart_info *info = s3c24xx_port_to_info(port);
992 unsigned long ufstat = rd_regl(port, S3C2410_UFSTAT);
993 unsigned long ufcon = rd_regl(port, S3C2410_UFCON);
995 if (ufcon & S3C2410_UFCON_FIFOMODE) {
996 if ((ufstat & info->tx_fifomask) != 0 ||
997 (ufstat & info->tx_fifofull))
1003 return s3c24xx_serial_txempty_nofifo(port);
1006 /* no modem control lines */
1007 static unsigned int s3c24xx_serial_get_mctrl(struct uart_port *port)
1009 unsigned int umstat = rd_reg(port, S3C2410_UMSTAT);
1011 if (umstat & S3C2410_UMSTAT_CTS)
1012 return TIOCM_CAR | TIOCM_DSR | TIOCM_CTS;
1014 return TIOCM_CAR | TIOCM_DSR;
1017 static void s3c24xx_serial_set_mctrl(struct uart_port *port, unsigned int mctrl)
1019 unsigned int umcon = rd_regl(port, S3C2410_UMCON);
1020 unsigned int ucon = rd_regl(port, S3C2410_UCON);
1022 if (mctrl & TIOCM_RTS)
1023 umcon |= S3C2410_UMCOM_RTS_LOW;
1025 umcon &= ~S3C2410_UMCOM_RTS_LOW;
1027 wr_regl(port, S3C2410_UMCON, umcon);
1029 if (mctrl & TIOCM_LOOP)
1030 ucon |= S3C2410_UCON_LOOPBACK;
1032 ucon &= ~S3C2410_UCON_LOOPBACK;
1034 wr_regl(port, S3C2410_UCON, ucon);
1037 static void s3c24xx_serial_break_ctl(struct uart_port *port, int break_state)
1039 unsigned long flags;
1042 spin_lock_irqsave(&port->lock, flags);
1044 ucon = rd_regl(port, S3C2410_UCON);
1047 ucon |= S3C2410_UCON_SBREAK;
1049 ucon &= ~S3C2410_UCON_SBREAK;
1051 wr_regl(port, S3C2410_UCON, ucon);
1053 spin_unlock_irqrestore(&port->lock, flags);
1056 static int s3c24xx_serial_request_dma(struct s3c24xx_uart_port *p)
1058 struct s3c24xx_uart_dma *dma = p->dma;
1059 struct dma_slave_caps dma_caps;
1060 const char *reason = NULL;
1063 /* Default slave configuration parameters */
1064 dma->rx_conf.direction = DMA_DEV_TO_MEM;
1065 dma->rx_conf.src_addr_width = DMA_SLAVE_BUSWIDTH_1_BYTE;
1066 dma->rx_conf.src_addr = p->port.mapbase + S3C2410_URXH;
1067 dma->rx_conf.src_maxburst = 1;
1069 dma->tx_conf.direction = DMA_MEM_TO_DEV;
1070 dma->tx_conf.dst_addr_width = DMA_SLAVE_BUSWIDTH_1_BYTE;
1071 dma->tx_conf.dst_addr = p->port.mapbase + S3C2410_UTXH;
1072 dma->tx_conf.dst_maxburst = 1;
1074 dma->rx_chan = dma_request_chan(p->port.dev, "rx");
1076 if (IS_ERR(dma->rx_chan)) {
1077 reason = "DMA RX channel request failed";
1078 ret = PTR_ERR(dma->rx_chan);
1082 ret = dma_get_slave_caps(dma->rx_chan, &dma_caps);
1084 dma_caps.residue_granularity < DMA_RESIDUE_GRANULARITY_BURST) {
1085 reason = "insufficient DMA RX engine capabilities";
1087 goto err_release_rx;
1090 dmaengine_slave_config(dma->rx_chan, &dma->rx_conf);
1092 dma->tx_chan = dma_request_chan(p->port.dev, "tx");
1093 if (IS_ERR(dma->tx_chan)) {
1094 reason = "DMA TX channel request failed";
1095 ret = PTR_ERR(dma->tx_chan);
1096 goto err_release_rx;
1099 ret = dma_get_slave_caps(dma->tx_chan, &dma_caps);
1101 dma_caps.residue_granularity < DMA_RESIDUE_GRANULARITY_BURST) {
1102 reason = "insufficient DMA TX engine capabilities";
1104 goto err_release_tx;
1107 dmaengine_slave_config(dma->tx_chan, &dma->tx_conf);
1110 dma->rx_size = PAGE_SIZE;
1112 dma->rx_buf = kmalloc(dma->rx_size, GFP_KERNEL);
1115 goto err_release_tx;
1118 dma->rx_addr = dma_map_single(dma->rx_chan->device->dev, dma->rx_buf,
1119 dma->rx_size, DMA_FROM_DEVICE);
1120 if (dma_mapping_error(dma->rx_chan->device->dev, dma->rx_addr)) {
1121 reason = "DMA mapping error for RX buffer";
1127 dma->tx_addr = dma_map_single(dma->tx_chan->device->dev,
1128 p->port.state->xmit.buf, UART_XMIT_SIZE,
1130 if (dma_mapping_error(dma->tx_chan->device->dev, dma->tx_addr)) {
1131 reason = "DMA mapping error for TX buffer";
1139 dma_unmap_single(dma->rx_chan->device->dev, dma->rx_addr,
1140 dma->rx_size, DMA_FROM_DEVICE);
1144 dma_release_channel(dma->tx_chan);
1146 dma_release_channel(dma->rx_chan);
1149 dev_warn(p->port.dev, "%s, DMA will not be used\n", reason);
1153 static void s3c24xx_serial_release_dma(struct s3c24xx_uart_port *p)
1155 struct s3c24xx_uart_dma *dma = p->dma;
1158 dmaengine_terminate_all(dma->rx_chan);
1159 dma_unmap_single(dma->rx_chan->device->dev, dma->rx_addr,
1160 dma->rx_size, DMA_FROM_DEVICE);
1162 dma_release_channel(dma->rx_chan);
1163 dma->rx_chan = NULL;
1167 dmaengine_terminate_all(dma->tx_chan);
1168 dma_unmap_single(dma->tx_chan->device->dev, dma->tx_addr,
1169 UART_XMIT_SIZE, DMA_TO_DEVICE);
1170 dma_release_channel(dma->tx_chan);
1171 dma->tx_chan = NULL;
1175 static void s3c24xx_serial_shutdown(struct uart_port *port)
1177 struct s3c24xx_uart_port *ourport = to_ourport(port);
1179 if (ourport->tx_claimed) {
1180 free_irq(ourport->tx_irq, ourport);
1181 ourport->tx_enabled = 0;
1182 ourport->tx_claimed = 0;
1183 ourport->tx_mode = 0;
1186 if (ourport->rx_claimed) {
1187 free_irq(ourport->rx_irq, ourport);
1188 ourport->rx_claimed = 0;
1189 ourport->rx_enabled = 0;
1193 s3c24xx_serial_release_dma(ourport);
1195 ourport->tx_in_progress = 0;
1198 static void s3c64xx_serial_shutdown(struct uart_port *port)
1200 struct s3c24xx_uart_port *ourport = to_ourport(port);
1202 ourport->tx_enabled = 0;
1203 ourport->tx_mode = 0;
1204 ourport->rx_enabled = 0;
1206 free_irq(port->irq, ourport);
1208 wr_regl(port, S3C64XX_UINTP, 0xf);
1209 wr_regl(port, S3C64XX_UINTM, 0xf);
1212 s3c24xx_serial_release_dma(ourport);
1214 ourport->tx_in_progress = 0;
1217 static void apple_s5l_serial_shutdown(struct uart_port *port)
1219 struct s3c24xx_uart_port *ourport = to_ourport(port);
1223 ucon = rd_regl(port, S3C2410_UCON);
1224 ucon &= ~(APPLE_S5L_UCON_TXTHRESH_ENA_MSK |
1225 APPLE_S5L_UCON_RXTHRESH_ENA_MSK |
1226 APPLE_S5L_UCON_RXTO_ENA_MSK);
1227 wr_regl(port, S3C2410_UCON, ucon);
1229 wr_regl(port, S3C2410_UTRSTAT, APPLE_S5L_UTRSTAT_ALL_FLAGS);
1231 free_irq(port->irq, ourport);
1233 ourport->tx_enabled = 0;
1234 ourport->tx_mode = 0;
1235 ourport->rx_enabled = 0;
1238 s3c24xx_serial_release_dma(ourport);
1240 ourport->tx_in_progress = 0;
1243 static int s3c24xx_serial_startup(struct uart_port *port)
1245 struct s3c24xx_uart_port *ourport = to_ourport(port);
1248 ourport->rx_enabled = 1;
1250 ret = request_irq(ourport->rx_irq, s3c24xx_serial_rx_irq, 0,
1251 s3c24xx_serial_portname(port), ourport);
1254 dev_err(port->dev, "cannot get irq %d\n", ourport->rx_irq);
1258 ourport->rx_claimed = 1;
1260 dev_dbg(port->dev, "requesting tx irq...\n");
1262 ourport->tx_enabled = 1;
1264 ret = request_irq(ourport->tx_irq, s3c24xx_serial_tx_irq, 0,
1265 s3c24xx_serial_portname(port), ourport);
1268 dev_err(port->dev, "cannot get irq %d\n", ourport->tx_irq);
1272 ourport->tx_claimed = 1;
1274 /* the port reset code should have done the correct
1275 * register setup for the port controls
1281 s3c24xx_serial_shutdown(port);
1285 static int s3c64xx_serial_startup(struct uart_port *port)
1287 struct s3c24xx_uart_port *ourport = to_ourport(port);
1288 unsigned long flags;
1292 wr_regl(port, S3C64XX_UINTM, 0xf);
1294 ret = s3c24xx_serial_request_dma(ourport);
1296 devm_kfree(port->dev, ourport->dma);
1297 ourport->dma = NULL;
1301 ret = request_irq(port->irq, s3c64xx_serial_handle_irq, IRQF_SHARED,
1302 s3c24xx_serial_portname(port), ourport);
1304 dev_err(port->dev, "cannot get irq %d\n", port->irq);
1308 /* For compatibility with s3c24xx Soc's */
1309 ourport->rx_enabled = 1;
1310 ourport->tx_enabled = 0;
1312 spin_lock_irqsave(&port->lock, flags);
1314 ufcon = rd_regl(port, S3C2410_UFCON);
1315 ufcon |= S3C2410_UFCON_RESETRX | S5PV210_UFCON_RXTRIG8;
1316 if (!uart_console(port))
1317 ufcon |= S3C2410_UFCON_RESETTX;
1318 wr_regl(port, S3C2410_UFCON, ufcon);
1320 enable_rx_pio(ourport);
1322 spin_unlock_irqrestore(&port->lock, flags);
1324 /* Enable Rx Interrupt */
1325 s3c24xx_clear_bit(port, S3C64XX_UINTM_RXD, S3C64XX_UINTM);
1330 static int apple_s5l_serial_startup(struct uart_port *port)
1332 struct s3c24xx_uart_port *ourport = to_ourport(port);
1333 unsigned long flags;
1337 wr_regl(port, S3C2410_UTRSTAT, APPLE_S5L_UTRSTAT_ALL_FLAGS);
1339 ret = request_irq(port->irq, apple_serial_handle_irq, 0,
1340 s3c24xx_serial_portname(port), ourport);
1342 dev_err(port->dev, "cannot get irq %d\n", port->irq);
1346 /* For compatibility with s3c24xx Soc's */
1347 ourport->rx_enabled = 1;
1348 ourport->tx_enabled = 0;
1350 spin_lock_irqsave(&port->lock, flags);
1352 ufcon = rd_regl(port, S3C2410_UFCON);
1353 ufcon |= S3C2410_UFCON_RESETRX | S5PV210_UFCON_RXTRIG8;
1354 if (!uart_console(port))
1355 ufcon |= S3C2410_UFCON_RESETTX;
1356 wr_regl(port, S3C2410_UFCON, ufcon);
1358 enable_rx_pio(ourport);
1360 spin_unlock_irqrestore(&port->lock, flags);
1362 /* Enable Rx Interrupt */
1363 s3c24xx_set_bit(port, APPLE_S5L_UCON_RXTHRESH_ENA, S3C2410_UCON);
1364 s3c24xx_set_bit(port, APPLE_S5L_UCON_RXTO_ENA, S3C2410_UCON);
1369 /* power power management control */
1371 static void s3c24xx_serial_pm(struct uart_port *port, unsigned int level,
1374 struct s3c24xx_uart_port *ourport = to_ourport(port);
1375 int timeout = 10000;
1377 ourport->pm_level = level;
1381 while (--timeout && !s3c24xx_serial_txempty_nofifo(port))
1384 if (!IS_ERR(ourport->baudclk))
1385 clk_disable_unprepare(ourport->baudclk);
1387 clk_disable_unprepare(ourport->clk);
1391 clk_prepare_enable(ourport->clk);
1393 if (!IS_ERR(ourport->baudclk))
1394 clk_prepare_enable(ourport->baudclk);
1397 dev_err(port->dev, "s3c24xx_serial: unknown pm %d\n", level);
1401 /* baud rate calculation
1403 * The UARTs on the S3C2410/S3C2440 can take their clocks from a number
1404 * of different sources, including the peripheral clock ("pclk") and an
1405 * external clock ("uclk"). The S3C2440 also adds the core clock ("fclk")
1406 * with a programmable extra divisor.
1408 * The following code goes through the clock sources, and calculates the
1409 * baud clocks (and the resultant actual baud rates) and then tries to
1410 * pick the closest one and select that.
1414 #define MAX_CLK_NAME_LENGTH 15
1416 static inline int s3c24xx_serial_getsource(struct uart_port *port)
1418 const struct s3c24xx_uart_info *info = s3c24xx_port_to_info(port);
1421 if (info->num_clks == 1)
1424 ucon = rd_regl(port, S3C2410_UCON);
1425 ucon &= info->clksel_mask;
1426 return ucon >> info->clksel_shift;
1429 static void s3c24xx_serial_setsource(struct uart_port *port,
1430 unsigned int clk_sel)
1432 const struct s3c24xx_uart_info *info = s3c24xx_port_to_info(port);
1435 if (info->num_clks == 1)
1438 ucon = rd_regl(port, S3C2410_UCON);
1439 if ((ucon & info->clksel_mask) >> info->clksel_shift == clk_sel)
1442 ucon &= ~info->clksel_mask;
1443 ucon |= clk_sel << info->clksel_shift;
1444 wr_regl(port, S3C2410_UCON, ucon);
1447 static unsigned int s3c24xx_serial_getclk(struct s3c24xx_uart_port *ourport,
1448 unsigned int req_baud, struct clk **best_clk,
1449 unsigned int *clk_num)
1451 const struct s3c24xx_uart_info *info = ourport->info;
1454 unsigned int cnt, baud, quot, best_quot = 0;
1455 char clkname[MAX_CLK_NAME_LENGTH];
1456 int calc_deviation, deviation = (1 << 30) - 1;
1458 for (cnt = 0; cnt < info->num_clks; cnt++) {
1459 /* Keep selected clock if provided */
1460 if (ourport->cfg->clk_sel &&
1461 !(ourport->cfg->clk_sel & (1 << cnt)))
1464 sprintf(clkname, "clk_uart_baud%d", cnt);
1465 clk = clk_get(ourport->port.dev, clkname);
1469 rate = clk_get_rate(clk);
1473 if (ourport->info->has_divslot) {
1474 unsigned long div = rate / req_baud;
1476 /* The UDIVSLOT register on the newer UARTs allows us to
1477 * get a divisor adjustment of 1/16th on the baud clock.
1479 * We don't keep the UDIVSLOT value (the 16ths we
1480 * calculated by not multiplying the baud by 16) as it
1481 * is easy enough to recalculate.
1487 quot = (rate + (8 * req_baud)) / (16 * req_baud);
1488 baud = rate / (quot * 16);
1492 calc_deviation = req_baud - baud;
1493 if (calc_deviation < 0)
1494 calc_deviation = -calc_deviation;
1496 if (calc_deviation < deviation) {
1500 deviation = calc_deviation;
1509 * This table takes the fractional value of the baud divisor and gives
1510 * the recommended setting for the UDIVSLOT register.
1512 static const u16 udivslot_table[16] = {
1531 static void s3c24xx_serial_set_termios(struct uart_port *port,
1532 struct ktermios *termios,
1533 struct ktermios *old)
1535 const struct s3c2410_uartcfg *cfg = s3c24xx_port_to_cfg(port);
1536 struct s3c24xx_uart_port *ourport = to_ourport(port);
1537 struct clk *clk = ERR_PTR(-EINVAL);
1538 unsigned long flags;
1539 unsigned int baud, quot, clk_sel = 0;
1542 unsigned int udivslot = 0;
1545 * We don't support modem control lines.
1547 termios->c_cflag &= ~(HUPCL | CMSPAR);
1548 termios->c_cflag |= CLOCAL;
1551 * Ask the core to calculate the divisor for us.
1554 baud = uart_get_baud_rate(port, termios, old, 0, 3000000);
1555 quot = s3c24xx_serial_getclk(ourport, baud, &clk, &clk_sel);
1556 if (baud == 38400 && (port->flags & UPF_SPD_MASK) == UPF_SPD_CUST)
1557 quot = port->custom_divisor;
1561 /* check to see if we need to change clock source */
1563 if (ourport->baudclk != clk) {
1564 clk_prepare_enable(clk);
1566 s3c24xx_serial_setsource(port, clk_sel);
1568 if (!IS_ERR(ourport->baudclk)) {
1569 clk_disable_unprepare(ourport->baudclk);
1570 ourport->baudclk = ERR_PTR(-EINVAL);
1573 ourport->baudclk = clk;
1574 ourport->baudclk_rate = clk ? clk_get_rate(clk) : 0;
1577 if (ourport->info->has_divslot) {
1578 unsigned int div = ourport->baudclk_rate / baud;
1580 if (cfg->has_fracval) {
1581 udivslot = (div & 15);
1582 dev_dbg(port->dev, "fracval = %04x\n", udivslot);
1584 udivslot = udivslot_table[div & 15];
1585 dev_dbg(port->dev, "udivslot = %04x (div %d)\n",
1586 udivslot, div & 15);
1590 switch (termios->c_cflag & CSIZE) {
1592 dev_dbg(port->dev, "config: 5bits/char\n");
1593 ulcon = S3C2410_LCON_CS5;
1596 dev_dbg(port->dev, "config: 6bits/char\n");
1597 ulcon = S3C2410_LCON_CS6;
1600 dev_dbg(port->dev, "config: 7bits/char\n");
1601 ulcon = S3C2410_LCON_CS7;
1605 dev_dbg(port->dev, "config: 8bits/char\n");
1606 ulcon = S3C2410_LCON_CS8;
1610 /* preserve original lcon IR settings */
1611 ulcon |= (cfg->ulcon & S3C2410_LCON_IRM);
1613 if (termios->c_cflag & CSTOPB)
1614 ulcon |= S3C2410_LCON_STOPB;
1616 if (termios->c_cflag & PARENB) {
1617 if (termios->c_cflag & PARODD)
1618 ulcon |= S3C2410_LCON_PODD;
1620 ulcon |= S3C2410_LCON_PEVEN;
1622 ulcon |= S3C2410_LCON_PNONE;
1625 spin_lock_irqsave(&port->lock, flags);
1628 "setting ulcon to %08x, brddiv to %d, udivslot %08x\n",
1629 ulcon, quot, udivslot);
1631 wr_regl(port, S3C2410_ULCON, ulcon);
1632 wr_regl(port, S3C2410_UBRDIV, quot);
1634 port->status &= ~UPSTAT_AUTOCTS;
1636 umcon = rd_regl(port, S3C2410_UMCON);
1637 if (termios->c_cflag & CRTSCTS) {
1638 umcon |= S3C2410_UMCOM_AFC;
1639 /* Disable RTS when RX FIFO contains 63 bytes */
1640 umcon &= ~S3C2412_UMCON_AFC_8;
1641 port->status = UPSTAT_AUTOCTS;
1643 umcon &= ~S3C2410_UMCOM_AFC;
1645 wr_regl(port, S3C2410_UMCON, umcon);
1647 if (ourport->info->has_divslot)
1648 wr_regl(port, S3C2443_DIVSLOT, udivslot);
1651 "uart: ulcon = 0x%08x, ucon = 0x%08x, ufcon = 0x%08x\n",
1652 rd_regl(port, S3C2410_ULCON),
1653 rd_regl(port, S3C2410_UCON),
1654 rd_regl(port, S3C2410_UFCON));
1657 * Update the per-port timeout.
1659 uart_update_timeout(port, termios->c_cflag, baud);
1662 * Which character status flags are we interested in?
1664 port->read_status_mask = S3C2410_UERSTAT_OVERRUN;
1665 if (termios->c_iflag & INPCK)
1666 port->read_status_mask |= S3C2410_UERSTAT_FRAME |
1667 S3C2410_UERSTAT_PARITY;
1669 * Which character status flags should we ignore?
1671 port->ignore_status_mask = 0;
1672 if (termios->c_iflag & IGNPAR)
1673 port->ignore_status_mask |= S3C2410_UERSTAT_OVERRUN;
1674 if (termios->c_iflag & IGNBRK && termios->c_iflag & IGNPAR)
1675 port->ignore_status_mask |= S3C2410_UERSTAT_FRAME;
1678 * Ignore all characters if CREAD is not set.
1680 if ((termios->c_cflag & CREAD) == 0)
1681 port->ignore_status_mask |= RXSTAT_DUMMY_READ;
1683 spin_unlock_irqrestore(&port->lock, flags);
1686 static const char *s3c24xx_serial_type(struct uart_port *port)
1688 const struct s3c24xx_uart_port *ourport = to_ourport(port);
1690 switch (ourport->info->type) {
1694 return "S3C6400/10";
1695 case TYPE_APPLE_S5L:
1702 static void s3c24xx_serial_config_port(struct uart_port *port, int flags)
1704 const struct s3c24xx_uart_info *info = s3c24xx_port_to_info(port);
1706 if (flags & UART_CONFIG_TYPE)
1707 port->type = info->port_type;
1711 * verify the new serial_struct (for TIOCSSERIAL).
1714 s3c24xx_serial_verify_port(struct uart_port *port, struct serial_struct *ser)
1716 const struct s3c24xx_uart_info *info = s3c24xx_port_to_info(port);
1718 if (ser->type != PORT_UNKNOWN && ser->type != info->port_type)
1724 #ifdef CONFIG_SERIAL_SAMSUNG_CONSOLE
1726 static struct console s3c24xx_serial_console;
1728 static void __init s3c24xx_serial_register_console(void)
1730 register_console(&s3c24xx_serial_console);
1733 static void s3c24xx_serial_unregister_console(void)
1735 if (s3c24xx_serial_console.flags & CON_ENABLED)
1736 unregister_console(&s3c24xx_serial_console);
1739 #define S3C24XX_SERIAL_CONSOLE &s3c24xx_serial_console
1741 static inline void s3c24xx_serial_register_console(void) { }
1742 static inline void s3c24xx_serial_unregister_console(void) { }
1743 #define S3C24XX_SERIAL_CONSOLE NULL
1746 #if defined(CONFIG_SERIAL_SAMSUNG_CONSOLE) && defined(CONFIG_CONSOLE_POLL)
1747 static int s3c24xx_serial_get_poll_char(struct uart_port *port);
1748 static void s3c24xx_serial_put_poll_char(struct uart_port *port,
1752 static const struct uart_ops s3c24xx_serial_ops = {
1753 .pm = s3c24xx_serial_pm,
1754 .tx_empty = s3c24xx_serial_tx_empty,
1755 .get_mctrl = s3c24xx_serial_get_mctrl,
1756 .set_mctrl = s3c24xx_serial_set_mctrl,
1757 .stop_tx = s3c24xx_serial_stop_tx,
1758 .start_tx = s3c24xx_serial_start_tx,
1759 .stop_rx = s3c24xx_serial_stop_rx,
1760 .break_ctl = s3c24xx_serial_break_ctl,
1761 .startup = s3c24xx_serial_startup,
1762 .shutdown = s3c24xx_serial_shutdown,
1763 .set_termios = s3c24xx_serial_set_termios,
1764 .type = s3c24xx_serial_type,
1765 .config_port = s3c24xx_serial_config_port,
1766 .verify_port = s3c24xx_serial_verify_port,
1767 #if defined(CONFIG_SERIAL_SAMSUNG_CONSOLE) && defined(CONFIG_CONSOLE_POLL)
1768 .poll_get_char = s3c24xx_serial_get_poll_char,
1769 .poll_put_char = s3c24xx_serial_put_poll_char,
1773 static const struct uart_ops s3c64xx_serial_ops = {
1774 .pm = s3c24xx_serial_pm,
1775 .tx_empty = s3c24xx_serial_tx_empty,
1776 .get_mctrl = s3c24xx_serial_get_mctrl,
1777 .set_mctrl = s3c24xx_serial_set_mctrl,
1778 .stop_tx = s3c24xx_serial_stop_tx,
1779 .start_tx = s3c24xx_serial_start_tx,
1780 .stop_rx = s3c24xx_serial_stop_rx,
1781 .break_ctl = s3c24xx_serial_break_ctl,
1782 .startup = s3c64xx_serial_startup,
1783 .shutdown = s3c64xx_serial_shutdown,
1784 .set_termios = s3c24xx_serial_set_termios,
1785 .type = s3c24xx_serial_type,
1786 .config_port = s3c24xx_serial_config_port,
1787 .verify_port = s3c24xx_serial_verify_port,
1788 #if defined(CONFIG_SERIAL_SAMSUNG_CONSOLE) && defined(CONFIG_CONSOLE_POLL)
1789 .poll_get_char = s3c24xx_serial_get_poll_char,
1790 .poll_put_char = s3c24xx_serial_put_poll_char,
1794 static const struct uart_ops apple_s5l_serial_ops = {
1795 .pm = s3c24xx_serial_pm,
1796 .tx_empty = s3c24xx_serial_tx_empty,
1797 .get_mctrl = s3c24xx_serial_get_mctrl,
1798 .set_mctrl = s3c24xx_serial_set_mctrl,
1799 .stop_tx = s3c24xx_serial_stop_tx,
1800 .start_tx = s3c24xx_serial_start_tx,
1801 .stop_rx = s3c24xx_serial_stop_rx,
1802 .break_ctl = s3c24xx_serial_break_ctl,
1803 .startup = apple_s5l_serial_startup,
1804 .shutdown = apple_s5l_serial_shutdown,
1805 .set_termios = s3c24xx_serial_set_termios,
1806 .type = s3c24xx_serial_type,
1807 .config_port = s3c24xx_serial_config_port,
1808 .verify_port = s3c24xx_serial_verify_port,
1809 #if defined(CONFIG_SERIAL_SAMSUNG_CONSOLE) && defined(CONFIG_CONSOLE_POLL)
1810 .poll_get_char = s3c24xx_serial_get_poll_char,
1811 .poll_put_char = s3c24xx_serial_put_poll_char,
1815 static struct uart_driver s3c24xx_uart_drv = {
1816 .owner = THIS_MODULE,
1817 .driver_name = "s3c2410_serial",
1819 .cons = S3C24XX_SERIAL_CONSOLE,
1820 .dev_name = S3C24XX_SERIAL_NAME,
1821 .major = S3C24XX_SERIAL_MAJOR,
1822 .minor = S3C24XX_SERIAL_MINOR,
1825 static struct s3c24xx_uart_port s3c24xx_serial_ports[UART_NR];
1827 static void s3c24xx_serial_init_port_default(int index) {
1828 struct uart_port *port = &s3c24xx_serial_ports[index].port;
1830 spin_lock_init(&port->lock);
1832 port->iotype = UPIO_MEM;
1834 port->fifosize = 16;
1835 port->ops = &s3c24xx_serial_ops;
1836 port->flags = UPF_BOOT_AUTOCONF;
1840 /* s3c24xx_serial_resetport
1842 * reset the fifos and other the settings.
1845 static void s3c24xx_serial_resetport(struct uart_port *port,
1846 const struct s3c2410_uartcfg *cfg)
1848 const struct s3c24xx_uart_info *info = s3c24xx_port_to_info(port);
1849 unsigned long ucon = rd_regl(port, S3C2410_UCON);
1851 ucon &= (info->clksel_mask | info->ucon_mask);
1852 wr_regl(port, S3C2410_UCON, ucon | cfg->ucon);
1854 /* reset both fifos */
1855 wr_regl(port, S3C2410_UFCON, cfg->ufcon | S3C2410_UFCON_RESETBOTH);
1856 wr_regl(port, S3C2410_UFCON, cfg->ufcon);
1858 /* some delay is required after fifo reset */
1862 #ifdef CONFIG_ARM_S3C24XX_CPUFREQ
1864 static int s3c24xx_serial_cpufreq_transition(struct notifier_block *nb,
1865 unsigned long val, void *data)
1867 struct s3c24xx_uart_port *port;
1868 struct uart_port *uport;
1870 port = container_of(nb, struct s3c24xx_uart_port, freq_transition);
1871 uport = &port->port;
1873 /* check to see if port is enabled */
1875 if (port->pm_level != 0)
1878 /* try and work out if the baudrate is changing, we can detect
1879 * a change in rate, but we do not have support for detecting
1880 * a disturbance in the clock-rate over the change.
1883 if (IS_ERR(port->baudclk))
1886 if (port->baudclk_rate == clk_get_rate(port->baudclk))
1889 if (val == CPUFREQ_PRECHANGE) {
1890 /* we should really shut the port down whilst the
1891 * frequency change is in progress.
1894 } else if (val == CPUFREQ_POSTCHANGE) {
1895 struct ktermios *termios;
1896 struct tty_struct *tty;
1898 if (uport->state == NULL)
1901 tty = uport->state->port.tty;
1906 termios = &tty->termios;
1908 if (termios == NULL) {
1909 dev_warn(uport->dev, "%s: no termios?\n", __func__);
1913 s3c24xx_serial_set_termios(uport, termios, NULL);
1921 s3c24xx_serial_cpufreq_register(struct s3c24xx_uart_port *port)
1923 port->freq_transition.notifier_call = s3c24xx_serial_cpufreq_transition;
1925 return cpufreq_register_notifier(&port->freq_transition,
1926 CPUFREQ_TRANSITION_NOTIFIER);
1930 s3c24xx_serial_cpufreq_deregister(struct s3c24xx_uart_port *port)
1932 cpufreq_unregister_notifier(&port->freq_transition,
1933 CPUFREQ_TRANSITION_NOTIFIER);
1938 s3c24xx_serial_cpufreq_register(struct s3c24xx_uart_port *port)
1944 s3c24xx_serial_cpufreq_deregister(struct s3c24xx_uart_port *port)
1949 static int s3c24xx_serial_enable_baudclk(struct s3c24xx_uart_port *ourport)
1951 struct device *dev = ourport->port.dev;
1952 const struct s3c24xx_uart_info *info = ourport->info;
1953 char clk_name[MAX_CLK_NAME_LENGTH];
1954 unsigned int clk_sel;
1959 clk_sel = ourport->cfg->clk_sel ? : info->def_clk_sel;
1960 for (clk_num = 0; clk_num < info->num_clks; clk_num++) {
1961 if (!(clk_sel & (1 << clk_num)))
1964 sprintf(clk_name, "clk_uart_baud%d", clk_num);
1965 clk = clk_get(dev, clk_name);
1969 ret = clk_prepare_enable(clk);
1975 ourport->baudclk = clk;
1976 ourport->baudclk_rate = clk_get_rate(clk);
1977 s3c24xx_serial_setsource(&ourport->port, clk_num);
1985 /* s3c24xx_serial_init_port
1987 * initialise a single serial port from the platform device given
1990 static int s3c24xx_serial_init_port(struct s3c24xx_uart_port *ourport,
1991 struct platform_device *platdev)
1993 struct uart_port *port = &ourport->port;
1994 const struct s3c2410_uartcfg *cfg = ourport->cfg;
1995 struct resource *res;
1998 if (platdev == NULL)
2001 if (port->mapbase != 0)
2004 /* setup info for port */
2005 port->dev = &platdev->dev;
2009 if (cfg->uart_flags & UPF_CONS_FLOW) {
2010 dev_dbg(port->dev, "enabling flow control\n");
2011 port->flags |= UPF_CONS_FLOW;
2014 /* sort our the physical and virtual addresses for each UART */
2016 res = platform_get_resource(platdev, IORESOURCE_MEM, 0);
2018 dev_err(port->dev, "failed to find memory resource for uart\n");
2022 dev_dbg(port->dev, "resource %pR)\n", res);
2024 port->membase = devm_ioremap_resource(port->dev, res);
2025 if (IS_ERR(port->membase)) {
2026 dev_err(port->dev, "failed to remap controller address\n");
2030 port->mapbase = res->start;
2031 ret = platform_get_irq(platdev, 0);
2036 ourport->rx_irq = ret;
2037 ourport->tx_irq = ret + 1;
2040 switch (ourport->info->type) {
2042 ret = platform_get_irq(platdev, 1);
2044 ourport->tx_irq = ret;
2051 * DMA is currently supported only on DT platforms, if DMA properties
2054 if (platdev->dev.of_node && of_find_property(platdev->dev.of_node,
2056 ourport->dma = devm_kzalloc(port->dev,
2057 sizeof(*ourport->dma),
2059 if (!ourport->dma) {
2065 ourport->clk = clk_get(&platdev->dev, "uart");
2066 if (IS_ERR(ourport->clk)) {
2067 pr_err("%s: Controller clock not found\n",
2068 dev_name(&platdev->dev));
2069 ret = PTR_ERR(ourport->clk);
2073 ret = clk_prepare_enable(ourport->clk);
2075 pr_err("uart: clock failed to prepare+enable: %d\n", ret);
2076 clk_put(ourport->clk);
2080 ret = s3c24xx_serial_enable_baudclk(ourport);
2082 pr_warn("uart: failed to enable baudclk\n");
2084 /* Keep all interrupts masked and cleared */
2085 switch (ourport->info->type) {
2087 wr_regl(port, S3C64XX_UINTM, 0xf);
2088 wr_regl(port, S3C64XX_UINTP, 0xf);
2089 wr_regl(port, S3C64XX_UINTSP, 0xf);
2091 case TYPE_APPLE_S5L: {
2094 ucon = rd_regl(port, S3C2410_UCON);
2095 ucon &= ~(APPLE_S5L_UCON_TXTHRESH_ENA_MSK |
2096 APPLE_S5L_UCON_RXTHRESH_ENA_MSK |
2097 APPLE_S5L_UCON_RXTO_ENA_MSK);
2098 wr_regl(port, S3C2410_UCON, ucon);
2100 wr_regl(port, S3C2410_UTRSTAT, APPLE_S5L_UTRSTAT_ALL_FLAGS);
2107 dev_dbg(port->dev, "port: map=%pa, mem=%p, irq=%d (%d,%d), clock=%u\n",
2108 &port->mapbase, port->membase, port->irq,
2109 ourport->rx_irq, ourport->tx_irq, port->uartclk);
2111 /* reset the fifos (and setup the uart) */
2112 s3c24xx_serial_resetport(port, cfg);
2121 /* Device driver serial port probe */
2123 static int probe_index;
2125 static inline const struct s3c24xx_serial_drv_data *
2126 s3c24xx_get_driver_data(struct platform_device *pdev)
2128 if (dev_of_node(&pdev->dev))
2129 return of_device_get_match_data(&pdev->dev);
2131 return (struct s3c24xx_serial_drv_data *)
2132 platform_get_device_id(pdev)->driver_data;
2135 static int s3c24xx_serial_probe(struct platform_device *pdev)
2137 struct device_node *np = pdev->dev.of_node;
2138 struct s3c24xx_uart_port *ourport;
2139 int index = probe_index;
2143 ret = of_alias_get_id(np, "serial");
2148 if (index >= ARRAY_SIZE(s3c24xx_serial_ports)) {
2149 dev_err(&pdev->dev, "serial%d out of range\n", index);
2152 ourport = &s3c24xx_serial_ports[index];
2154 s3c24xx_serial_init_port_default(index);
2156 ourport->drv_data = s3c24xx_get_driver_data(pdev);
2157 if (!ourport->drv_data) {
2158 dev_err(&pdev->dev, "could not find driver data\n");
2162 ourport->baudclk = ERR_PTR(-EINVAL);
2163 ourport->info = &ourport->drv_data->info;
2164 ourport->cfg = (dev_get_platdata(&pdev->dev)) ?
2165 dev_get_platdata(&pdev->dev) :
2166 &ourport->drv_data->def_cfg;
2168 switch (ourport->info->type) {
2170 ourport->port.ops = &s3c24xx_serial_ops;
2173 ourport->port.ops = &s3c64xx_serial_ops;
2175 case TYPE_APPLE_S5L:
2176 ourport->port.ops = &apple_s5l_serial_ops;
2181 of_property_read_u32(np,
2182 "samsung,uart-fifosize", &ourport->port.fifosize);
2184 if (of_property_read_u32(np, "reg-io-width", &prop) == 0) {
2187 ourport->port.iotype = UPIO_MEM;
2190 ourport->port.iotype = UPIO_MEM32;
2193 dev_warn(&pdev->dev, "unsupported reg-io-width (%d)\n",
2200 if (ourport->drv_data->fifosize[index])
2201 ourport->port.fifosize = ourport->drv_data->fifosize[index];
2202 else if (ourport->info->fifosize)
2203 ourport->port.fifosize = ourport->info->fifosize;
2204 ourport->port.has_sysrq = IS_ENABLED(CONFIG_SERIAL_SAMSUNG_CONSOLE);
2207 * DMA transfers must be aligned at least to cache line size,
2208 * so find minimal transfer size suitable for DMA mode
2210 ourport->min_dma_size = max_t(int, ourport->port.fifosize,
2211 dma_get_cache_alignment());
2213 dev_dbg(&pdev->dev, "%s: initialising port %p...\n", __func__, ourport);
2215 ret = s3c24xx_serial_init_port(ourport, pdev);
2219 if (!s3c24xx_uart_drv.state) {
2220 ret = uart_register_driver(&s3c24xx_uart_drv);
2222 pr_err("Failed to register Samsung UART driver\n");
2227 dev_dbg(&pdev->dev, "%s: adding port\n", __func__);
2228 uart_add_one_port(&s3c24xx_uart_drv, &ourport->port);
2229 platform_set_drvdata(pdev, &ourport->port);
2232 * Deactivate the clock enabled in s3c24xx_serial_init_port here,
2233 * so that a potential re-enablement through the pm-callback overlaps
2234 * and keeps the clock enabled in this case.
2236 clk_disable_unprepare(ourport->clk);
2237 if (!IS_ERR(ourport->baudclk))
2238 clk_disable_unprepare(ourport->baudclk);
2240 ret = s3c24xx_serial_cpufreq_register(ourport);
2242 dev_err(&pdev->dev, "failed to add cpufreq notifier\n");
2249 static int s3c24xx_serial_remove(struct platform_device *dev)
2251 struct uart_port *port = s3c24xx_dev_to_port(&dev->dev);
2254 s3c24xx_serial_cpufreq_deregister(to_ourport(port));
2255 uart_remove_one_port(&s3c24xx_uart_drv, port);
2258 uart_unregister_driver(&s3c24xx_uart_drv);
2263 /* UART power management code */
2264 #ifdef CONFIG_PM_SLEEP
2265 static int s3c24xx_serial_suspend(struct device *dev)
2267 struct uart_port *port = s3c24xx_dev_to_port(dev);
2270 uart_suspend_port(&s3c24xx_uart_drv, port);
2275 static int s3c24xx_serial_resume(struct device *dev)
2277 struct uart_port *port = s3c24xx_dev_to_port(dev);
2278 struct s3c24xx_uart_port *ourport = to_ourport(port);
2281 clk_prepare_enable(ourport->clk);
2282 if (!IS_ERR(ourport->baudclk))
2283 clk_prepare_enable(ourport->baudclk);
2284 s3c24xx_serial_resetport(port, s3c24xx_port_to_cfg(port));
2285 if (!IS_ERR(ourport->baudclk))
2286 clk_disable_unprepare(ourport->baudclk);
2287 clk_disable_unprepare(ourport->clk);
2289 uart_resume_port(&s3c24xx_uart_drv, port);
2295 static int s3c24xx_serial_resume_noirq(struct device *dev)
2297 struct uart_port *port = s3c24xx_dev_to_port(dev);
2298 struct s3c24xx_uart_port *ourport = to_ourport(port);
2301 /* restore IRQ mask */
2302 switch (ourport->info->type) {
2303 case TYPE_S3C6400: {
2304 unsigned int uintm = 0xf;
2306 if (ourport->tx_enabled)
2307 uintm &= ~S3C64XX_UINTM_TXD_MSK;
2308 if (ourport->rx_enabled)
2309 uintm &= ~S3C64XX_UINTM_RXD_MSK;
2310 clk_prepare_enable(ourport->clk);
2311 if (!IS_ERR(ourport->baudclk))
2312 clk_prepare_enable(ourport->baudclk);
2313 wr_regl(port, S3C64XX_UINTM, uintm);
2314 if (!IS_ERR(ourport->baudclk))
2315 clk_disable_unprepare(ourport->baudclk);
2316 clk_disable_unprepare(ourport->clk);
2319 case TYPE_APPLE_S5L: {
2323 ret = clk_prepare_enable(ourport->clk);
2325 dev_err(dev, "clk_enable clk failed: %d\n", ret);
2328 if (!IS_ERR(ourport->baudclk)) {
2329 ret = clk_prepare_enable(ourport->baudclk);
2331 dev_err(dev, "clk_enable baudclk failed: %d\n", ret);
2332 clk_disable_unprepare(ourport->clk);
2337 ucon = rd_regl(port, S3C2410_UCON);
2339 ucon &= ~(APPLE_S5L_UCON_TXTHRESH_ENA_MSK |
2340 APPLE_S5L_UCON_RXTHRESH_ENA_MSK |
2341 APPLE_S5L_UCON_RXTO_ENA_MSK);
2343 if (ourport->tx_enabled)
2344 ucon |= APPLE_S5L_UCON_TXTHRESH_ENA_MSK;
2345 if (ourport->rx_enabled)
2346 ucon |= APPLE_S5L_UCON_RXTHRESH_ENA_MSK |
2347 APPLE_S5L_UCON_RXTO_ENA_MSK;
2349 wr_regl(port, S3C2410_UCON, ucon);
2351 if (!IS_ERR(ourport->baudclk))
2352 clk_disable_unprepare(ourport->baudclk);
2353 clk_disable_unprepare(ourport->clk);
2364 static const struct dev_pm_ops s3c24xx_serial_pm_ops = {
2365 .suspend = s3c24xx_serial_suspend,
2366 .resume = s3c24xx_serial_resume,
2367 .resume_noirq = s3c24xx_serial_resume_noirq,
2369 #define SERIAL_SAMSUNG_PM_OPS (&s3c24xx_serial_pm_ops)
2371 #else /* !CONFIG_PM_SLEEP */
2373 #define SERIAL_SAMSUNG_PM_OPS NULL
2374 #endif /* CONFIG_PM_SLEEP */
2378 #ifdef CONFIG_SERIAL_SAMSUNG_CONSOLE
2380 static struct uart_port *cons_uart;
2383 s3c24xx_serial_console_txrdy(struct uart_port *port, unsigned int ufcon)
2385 const struct s3c24xx_uart_info *info = s3c24xx_port_to_info(port);
2386 unsigned long ufstat, utrstat;
2388 if (ufcon & S3C2410_UFCON_FIFOMODE) {
2389 /* fifo mode - check amount of data in fifo registers... */
2391 ufstat = rd_regl(port, S3C2410_UFSTAT);
2392 return (ufstat & info->tx_fifofull) ? 0 : 1;
2395 /* in non-fifo mode, we go and use the tx buffer empty */
2397 utrstat = rd_regl(port, S3C2410_UTRSTAT);
2398 return (utrstat & S3C2410_UTRSTAT_TXE) ? 1 : 0;
2402 s3c24xx_port_configured(unsigned int ucon)
2404 /* consider the serial port configured if the tx/rx mode set */
2405 return (ucon & 0xf) != 0;
2408 #ifdef CONFIG_CONSOLE_POLL
2410 * Console polling routines for writing and reading from the uart while
2411 * in an interrupt or debug context.
2414 static int s3c24xx_serial_get_poll_char(struct uart_port *port)
2416 const struct s3c24xx_uart_port *ourport = to_ourport(port);
2417 unsigned int ufstat;
2419 ufstat = rd_regl(port, S3C2410_UFSTAT);
2420 if (s3c24xx_serial_rx_fifocnt(ourport, ufstat) == 0)
2421 return NO_POLL_CHAR;
2423 return rd_reg(port, S3C2410_URXH);
2426 static void s3c24xx_serial_put_poll_char(struct uart_port *port,
2429 unsigned int ufcon = rd_regl(port, S3C2410_UFCON);
2430 unsigned int ucon = rd_regl(port, S3C2410_UCON);
2432 /* not possible to xmit on unconfigured port */
2433 if (!s3c24xx_port_configured(ucon))
2436 while (!s3c24xx_serial_console_txrdy(port, ufcon))
2438 wr_reg(port, S3C2410_UTXH, c);
2441 #endif /* CONFIG_CONSOLE_POLL */
2444 s3c24xx_serial_console_putchar(struct uart_port *port, unsigned char ch)
2446 unsigned int ufcon = rd_regl(port, S3C2410_UFCON);
2448 while (!s3c24xx_serial_console_txrdy(port, ufcon))
2450 wr_reg(port, S3C2410_UTXH, ch);
2454 s3c24xx_serial_console_write(struct console *co, const char *s,
2457 unsigned int ucon = rd_regl(cons_uart, S3C2410_UCON);
2458 unsigned long flags;
2461 /* not possible to xmit on unconfigured port */
2462 if (!s3c24xx_port_configured(ucon))
2465 if (cons_uart->sysrq)
2467 else if (oops_in_progress)
2468 locked = spin_trylock_irqsave(&cons_uart->lock, flags);
2470 spin_lock_irqsave(&cons_uart->lock, flags);
2472 uart_console_write(cons_uart, s, count, s3c24xx_serial_console_putchar);
2475 spin_unlock_irqrestore(&cons_uart->lock, flags);
2478 /* Shouldn't be __init, as it can be instantiated from other module */
2480 s3c24xx_serial_get_options(struct uart_port *port, int *baud,
2481 int *parity, int *bits)
2486 unsigned int ubrdiv;
2488 unsigned int clk_sel;
2489 char clk_name[MAX_CLK_NAME_LENGTH];
2491 ulcon = rd_regl(port, S3C2410_ULCON);
2492 ucon = rd_regl(port, S3C2410_UCON);
2493 ubrdiv = rd_regl(port, S3C2410_UBRDIV);
2495 if (s3c24xx_port_configured(ucon)) {
2496 switch (ulcon & S3C2410_LCON_CSMASK) {
2497 case S3C2410_LCON_CS5:
2500 case S3C2410_LCON_CS6:
2503 case S3C2410_LCON_CS7:
2506 case S3C2410_LCON_CS8:
2512 switch (ulcon & S3C2410_LCON_PMASK) {
2513 case S3C2410_LCON_PEVEN:
2517 case S3C2410_LCON_PODD:
2521 case S3C2410_LCON_PNONE:
2526 /* now calculate the baud rate */
2528 clk_sel = s3c24xx_serial_getsource(port);
2529 sprintf(clk_name, "clk_uart_baud%d", clk_sel);
2531 clk = clk_get(port->dev, clk_name);
2533 rate = clk_get_rate(clk);
2537 *baud = rate / (16 * (ubrdiv + 1));
2538 dev_dbg(port->dev, "calculated baud %d\n", *baud);
2542 /* Shouldn't be __init, as it can be instantiated from other module */
2544 s3c24xx_serial_console_setup(struct console *co, char *options)
2546 struct uart_port *port;
2552 /* is this a valid port */
2554 if (co->index == -1 || co->index >= UART_NR)
2557 port = &s3c24xx_serial_ports[co->index].port;
2559 /* is the port configured? */
2561 if (port->mapbase == 0x0)
2567 * Check whether an invalid uart number has been specified, and
2568 * if so, search for the first available port that does have
2572 uart_parse_options(options, &baud, &parity, &bits, &flow);
2574 s3c24xx_serial_get_options(port, &baud, &parity, &bits);
2576 dev_dbg(port->dev, "baud %d\n", baud);
2578 return uart_set_options(port, co, baud, parity, bits, flow);
2581 static struct console s3c24xx_serial_console = {
2582 .name = S3C24XX_SERIAL_NAME,
2583 .device = uart_console_device,
2584 .flags = CON_PRINTBUFFER,
2586 .write = s3c24xx_serial_console_write,
2587 .setup = s3c24xx_serial_console_setup,
2588 .data = &s3c24xx_uart_drv,
2590 #endif /* CONFIG_SERIAL_SAMSUNG_CONSOLE */
2592 #ifdef CONFIG_CPU_S3C2410
2593 static const struct s3c24xx_serial_drv_data s3c2410_serial_drv_data = {
2595 .name = "Samsung S3C2410 UART",
2596 .type = TYPE_S3C24XX,
2597 .port_type = PORT_S3C2410,
2599 .rx_fifomask = S3C2410_UFSTAT_RXMASK,
2600 .rx_fifoshift = S3C2410_UFSTAT_RXSHIFT,
2601 .rx_fifofull = S3C2410_UFSTAT_RXFULL,
2602 .tx_fifofull = S3C2410_UFSTAT_TXFULL,
2603 .tx_fifomask = S3C2410_UFSTAT_TXMASK,
2604 .tx_fifoshift = S3C2410_UFSTAT_TXSHIFT,
2605 .def_clk_sel = S3C2410_UCON_CLKSEL0,
2607 .clksel_mask = S3C2410_UCON_CLKMASK,
2608 .clksel_shift = S3C2410_UCON_CLKSHIFT,
2611 .ucon = S3C2410_UCON_DEFAULT,
2612 .ufcon = S3C2410_UFCON_DEFAULT,
2615 #define S3C2410_SERIAL_DRV_DATA (&s3c2410_serial_drv_data)
2617 #define S3C2410_SERIAL_DRV_DATA NULL
2620 #ifdef CONFIG_CPU_S3C2412
2621 static const struct s3c24xx_serial_drv_data s3c2412_serial_drv_data = {
2623 .name = "Samsung S3C2412 UART",
2624 .type = TYPE_S3C24XX,
2625 .port_type = PORT_S3C2412,
2628 .rx_fifomask = S3C2440_UFSTAT_RXMASK,
2629 .rx_fifoshift = S3C2440_UFSTAT_RXSHIFT,
2630 .rx_fifofull = S3C2440_UFSTAT_RXFULL,
2631 .tx_fifofull = S3C2440_UFSTAT_TXFULL,
2632 .tx_fifomask = S3C2440_UFSTAT_TXMASK,
2633 .tx_fifoshift = S3C2440_UFSTAT_TXSHIFT,
2634 .def_clk_sel = S3C2410_UCON_CLKSEL2,
2636 .clksel_mask = S3C2412_UCON_CLKMASK,
2637 .clksel_shift = S3C2412_UCON_CLKSHIFT,
2640 .ucon = S3C2410_UCON_DEFAULT,
2641 .ufcon = S3C2410_UFCON_DEFAULT,
2644 #define S3C2412_SERIAL_DRV_DATA (&s3c2412_serial_drv_data)
2646 #define S3C2412_SERIAL_DRV_DATA NULL
2649 #if defined(CONFIG_CPU_S3C2440) || defined(CONFIG_CPU_S3C2416) || \
2650 defined(CONFIG_CPU_S3C2443) || defined(CONFIG_CPU_S3C2442)
2651 static const struct s3c24xx_serial_drv_data s3c2440_serial_drv_data = {
2653 .name = "Samsung S3C2440 UART",
2654 .type = TYPE_S3C24XX,
2655 .port_type = PORT_S3C2440,
2658 .rx_fifomask = S3C2440_UFSTAT_RXMASK,
2659 .rx_fifoshift = S3C2440_UFSTAT_RXSHIFT,
2660 .rx_fifofull = S3C2440_UFSTAT_RXFULL,
2661 .tx_fifofull = S3C2440_UFSTAT_TXFULL,
2662 .tx_fifomask = S3C2440_UFSTAT_TXMASK,
2663 .tx_fifoshift = S3C2440_UFSTAT_TXSHIFT,
2664 .def_clk_sel = S3C2410_UCON_CLKSEL2,
2666 .clksel_mask = S3C2412_UCON_CLKMASK,
2667 .clksel_shift = S3C2412_UCON_CLKSHIFT,
2668 .ucon_mask = S3C2440_UCON0_DIVMASK,
2671 .ucon = S3C2410_UCON_DEFAULT,
2672 .ufcon = S3C2410_UFCON_DEFAULT,
2675 #define S3C2440_SERIAL_DRV_DATA (&s3c2440_serial_drv_data)
2677 #define S3C2440_SERIAL_DRV_DATA NULL
2680 #if defined(CONFIG_CPU_S3C6400) || defined(CONFIG_CPU_S3C6410)
2681 static const struct s3c24xx_serial_drv_data s3c6400_serial_drv_data = {
2683 .name = "Samsung S3C6400 UART",
2684 .type = TYPE_S3C6400,
2685 .port_type = PORT_S3C6400,
2688 .rx_fifomask = S3C2440_UFSTAT_RXMASK,
2689 .rx_fifoshift = S3C2440_UFSTAT_RXSHIFT,
2690 .rx_fifofull = S3C2440_UFSTAT_RXFULL,
2691 .tx_fifofull = S3C2440_UFSTAT_TXFULL,
2692 .tx_fifomask = S3C2440_UFSTAT_TXMASK,
2693 .tx_fifoshift = S3C2440_UFSTAT_TXSHIFT,
2694 .def_clk_sel = S3C2410_UCON_CLKSEL2,
2696 .clksel_mask = S3C6400_UCON_CLKMASK,
2697 .clksel_shift = S3C6400_UCON_CLKSHIFT,
2700 .ucon = S3C2410_UCON_DEFAULT,
2701 .ufcon = S3C2410_UFCON_DEFAULT,
2704 #define S3C6400_SERIAL_DRV_DATA (&s3c6400_serial_drv_data)
2706 #define S3C6400_SERIAL_DRV_DATA NULL
2709 #ifdef CONFIG_CPU_S5PV210
2710 static const struct s3c24xx_serial_drv_data s5pv210_serial_drv_data = {
2712 .name = "Samsung S5PV210 UART",
2713 .type = TYPE_S3C6400,
2714 .port_type = PORT_S3C6400,
2716 .rx_fifomask = S5PV210_UFSTAT_RXMASK,
2717 .rx_fifoshift = S5PV210_UFSTAT_RXSHIFT,
2718 .rx_fifofull = S5PV210_UFSTAT_RXFULL,
2719 .tx_fifofull = S5PV210_UFSTAT_TXFULL,
2720 .tx_fifomask = S5PV210_UFSTAT_TXMASK,
2721 .tx_fifoshift = S5PV210_UFSTAT_TXSHIFT,
2722 .def_clk_sel = S3C2410_UCON_CLKSEL0,
2724 .clksel_mask = S5PV210_UCON_CLKMASK,
2725 .clksel_shift = S5PV210_UCON_CLKSHIFT,
2728 .ucon = S5PV210_UCON_DEFAULT,
2729 .ufcon = S5PV210_UFCON_DEFAULT,
2731 .fifosize = { 256, 64, 16, 16 },
2733 #define S5PV210_SERIAL_DRV_DATA (&s5pv210_serial_drv_data)
2735 #define S5PV210_SERIAL_DRV_DATA NULL
2738 #if defined(CONFIG_ARCH_EXYNOS)
2739 #define EXYNOS_COMMON_SERIAL_DRV_DATA() \
2741 .name = "Samsung Exynos UART", \
2742 .type = TYPE_S3C6400, \
2743 .port_type = PORT_S3C6400, \
2745 .rx_fifomask = S5PV210_UFSTAT_RXMASK, \
2746 .rx_fifoshift = S5PV210_UFSTAT_RXSHIFT, \
2747 .rx_fifofull = S5PV210_UFSTAT_RXFULL, \
2748 .tx_fifofull = S5PV210_UFSTAT_TXFULL, \
2749 .tx_fifomask = S5PV210_UFSTAT_TXMASK, \
2750 .tx_fifoshift = S5PV210_UFSTAT_TXSHIFT, \
2751 .def_clk_sel = S3C2410_UCON_CLKSEL0, \
2754 .clksel_shift = 0, \
2757 .ucon = S5PV210_UCON_DEFAULT, \
2758 .ufcon = S5PV210_UFCON_DEFAULT, \
2762 static const struct s3c24xx_serial_drv_data exynos4210_serial_drv_data = {
2763 EXYNOS_COMMON_SERIAL_DRV_DATA(),
2764 .fifosize = { 256, 64, 16, 16 },
2767 static const struct s3c24xx_serial_drv_data exynos5433_serial_drv_data = {
2768 EXYNOS_COMMON_SERIAL_DRV_DATA(),
2769 .fifosize = { 64, 256, 16, 256 },
2772 static const struct s3c24xx_serial_drv_data exynos850_serial_drv_data = {
2773 EXYNOS_COMMON_SERIAL_DRV_DATA(),
2774 .fifosize = { 256, 64, 64, 64 },
2777 #define EXYNOS4210_SERIAL_DRV_DATA (&exynos4210_serial_drv_data)
2778 #define EXYNOS5433_SERIAL_DRV_DATA (&exynos5433_serial_drv_data)
2779 #define EXYNOS850_SERIAL_DRV_DATA (&exynos850_serial_drv_data)
2782 #define EXYNOS4210_SERIAL_DRV_DATA NULL
2783 #define EXYNOS5433_SERIAL_DRV_DATA NULL
2784 #define EXYNOS850_SERIAL_DRV_DATA NULL
2787 #ifdef CONFIG_ARCH_APPLE
2788 static const struct s3c24xx_serial_drv_data s5l_serial_drv_data = {
2790 .name = "Apple S5L UART",
2791 .type = TYPE_APPLE_S5L,
2792 .port_type = PORT_8250,
2794 .rx_fifomask = S3C2410_UFSTAT_RXMASK,
2795 .rx_fifoshift = S3C2410_UFSTAT_RXSHIFT,
2796 .rx_fifofull = S3C2410_UFSTAT_RXFULL,
2797 .tx_fifofull = S3C2410_UFSTAT_TXFULL,
2798 .tx_fifomask = S3C2410_UFSTAT_TXMASK,
2799 .tx_fifoshift = S3C2410_UFSTAT_TXSHIFT,
2800 .def_clk_sel = S3C2410_UCON_CLKSEL0,
2804 .ucon_mask = APPLE_S5L_UCON_MASK,
2807 .ucon = APPLE_S5L_UCON_DEFAULT,
2808 .ufcon = S3C2410_UFCON_DEFAULT,
2811 #define S5L_SERIAL_DRV_DATA (&s5l_serial_drv_data)
2813 #define S5L_SERIAL_DRV_DATA NULL
2816 #if defined(CONFIG_ARCH_ARTPEC)
2817 static const struct s3c24xx_serial_drv_data artpec8_serial_drv_data = {
2819 .name = "Axis ARTPEC-8 UART",
2820 .type = TYPE_S3C6400,
2821 .port_type = PORT_S3C6400,
2824 .rx_fifomask = S5PV210_UFSTAT_RXMASK,
2825 .rx_fifoshift = S5PV210_UFSTAT_RXSHIFT,
2826 .rx_fifofull = S5PV210_UFSTAT_RXFULL,
2827 .tx_fifofull = S5PV210_UFSTAT_TXFULL,
2828 .tx_fifomask = S5PV210_UFSTAT_TXMASK,
2829 .tx_fifoshift = S5PV210_UFSTAT_TXSHIFT,
2830 .def_clk_sel = S3C2410_UCON_CLKSEL0,
2836 .ucon = S5PV210_UCON_DEFAULT,
2837 .ufcon = S5PV210_UFCON_DEFAULT,
2841 #define ARTPEC8_SERIAL_DRV_DATA (&artpec8_serial_drv_data)
2843 #define ARTPEC8_SERIAL_DRV_DATA (NULL)
2846 static const struct platform_device_id s3c24xx_serial_driver_ids[] = {
2848 .name = "s3c2410-uart",
2849 .driver_data = (kernel_ulong_t)S3C2410_SERIAL_DRV_DATA,
2851 .name = "s3c2412-uart",
2852 .driver_data = (kernel_ulong_t)S3C2412_SERIAL_DRV_DATA,
2854 .name = "s3c2440-uart",
2855 .driver_data = (kernel_ulong_t)S3C2440_SERIAL_DRV_DATA,
2857 .name = "s3c6400-uart",
2858 .driver_data = (kernel_ulong_t)S3C6400_SERIAL_DRV_DATA,
2860 .name = "s5pv210-uart",
2861 .driver_data = (kernel_ulong_t)S5PV210_SERIAL_DRV_DATA,
2863 .name = "exynos4210-uart",
2864 .driver_data = (kernel_ulong_t)EXYNOS4210_SERIAL_DRV_DATA,
2866 .name = "exynos5433-uart",
2867 .driver_data = (kernel_ulong_t)EXYNOS5433_SERIAL_DRV_DATA,
2870 .driver_data = (kernel_ulong_t)S5L_SERIAL_DRV_DATA,
2872 .name = "exynos850-uart",
2873 .driver_data = (kernel_ulong_t)EXYNOS850_SERIAL_DRV_DATA,
2875 .name = "artpec8-uart",
2876 .driver_data = (kernel_ulong_t)ARTPEC8_SERIAL_DRV_DATA,
2880 MODULE_DEVICE_TABLE(platform, s3c24xx_serial_driver_ids);
2883 static const struct of_device_id s3c24xx_uart_dt_match[] = {
2884 { .compatible = "samsung,s3c2410-uart",
2885 .data = S3C2410_SERIAL_DRV_DATA },
2886 { .compatible = "samsung,s3c2412-uart",
2887 .data = S3C2412_SERIAL_DRV_DATA },
2888 { .compatible = "samsung,s3c2440-uart",
2889 .data = S3C2440_SERIAL_DRV_DATA },
2890 { .compatible = "samsung,s3c6400-uart",
2891 .data = S3C6400_SERIAL_DRV_DATA },
2892 { .compatible = "samsung,s5pv210-uart",
2893 .data = S5PV210_SERIAL_DRV_DATA },
2894 { .compatible = "samsung,exynos4210-uart",
2895 .data = EXYNOS4210_SERIAL_DRV_DATA },
2896 { .compatible = "samsung,exynos5433-uart",
2897 .data = EXYNOS5433_SERIAL_DRV_DATA },
2898 { .compatible = "apple,s5l-uart",
2899 .data = S5L_SERIAL_DRV_DATA },
2900 { .compatible = "samsung,exynos850-uart",
2901 .data = EXYNOS850_SERIAL_DRV_DATA },
2902 { .compatible = "axis,artpec8-uart",
2903 .data = ARTPEC8_SERIAL_DRV_DATA },
2906 MODULE_DEVICE_TABLE(of, s3c24xx_uart_dt_match);
2909 static struct platform_driver samsung_serial_driver = {
2910 .probe = s3c24xx_serial_probe,
2911 .remove = s3c24xx_serial_remove,
2912 .id_table = s3c24xx_serial_driver_ids,
2914 .name = "samsung-uart",
2915 .pm = SERIAL_SAMSUNG_PM_OPS,
2916 .of_match_table = of_match_ptr(s3c24xx_uart_dt_match),
2920 static int __init samsung_serial_init(void)
2924 s3c24xx_serial_register_console();
2926 ret = platform_driver_register(&samsung_serial_driver);
2928 s3c24xx_serial_unregister_console();
2935 static void __exit samsung_serial_exit(void)
2937 platform_driver_unregister(&samsung_serial_driver);
2938 s3c24xx_serial_unregister_console();
2941 module_init(samsung_serial_init);
2942 module_exit(samsung_serial_exit);
2944 #ifdef CONFIG_SERIAL_SAMSUNG_CONSOLE
2949 static void wr_reg_barrier(const struct uart_port *port, u32 reg, u32 val)
2951 switch (port->iotype) {
2953 writeb(val, portaddr(port, reg));
2956 writel(val, portaddr(port, reg));
2961 struct samsung_early_console_data {
2966 static void samsung_early_busyuart(const struct uart_port *port)
2968 while (!(readl(port->membase + S3C2410_UTRSTAT) & S3C2410_UTRSTAT_TXFE))
2972 static void samsung_early_busyuart_fifo(const struct uart_port *port)
2974 const struct samsung_early_console_data *data = port->private_data;
2976 while (readl(port->membase + S3C2410_UFSTAT) & data->txfull_mask)
2980 static void samsung_early_putc(struct uart_port *port, unsigned char c)
2982 if (readl(port->membase + S3C2410_UFCON) & S3C2410_UFCON_FIFOMODE)
2983 samsung_early_busyuart_fifo(port);
2985 samsung_early_busyuart(port);
2987 wr_reg_barrier(port, S3C2410_UTXH, c);
2990 static void samsung_early_write(struct console *con, const char *s,
2993 struct earlycon_device *dev = con->data;
2995 uart_console_write(&dev->port, s, n, samsung_early_putc);
2998 static int samsung_early_read(struct console *con, char *s, unsigned int n)
3000 struct earlycon_device *dev = con->data;
3001 const struct samsung_early_console_data *data = dev->port.private_data;
3002 int ch, ufstat, num_read = 0;
3004 while (num_read < n) {
3005 ufstat = rd_regl(&dev->port, S3C2410_UFSTAT);
3006 if (!(ufstat & data->rxfifo_mask))
3008 ch = rd_reg(&dev->port, S3C2410_URXH);
3009 if (ch == NO_POLL_CHAR)
3018 static int __init samsung_early_console_setup(struct earlycon_device *device,
3021 if (!device->port.membase)
3024 device->con->write = samsung_early_write;
3025 device->con->read = samsung_early_read;
3030 static struct samsung_early_console_data s3c2410_early_console_data = {
3031 .txfull_mask = S3C2410_UFSTAT_TXFULL,
3032 .rxfifo_mask = S3C2410_UFSTAT_RXFULL | S3C2410_UFSTAT_RXMASK,
3035 static int __init s3c2410_early_console_setup(struct earlycon_device *device,
3038 device->port.private_data = &s3c2410_early_console_data;
3039 return samsung_early_console_setup(device, opt);
3042 OF_EARLYCON_DECLARE(s3c2410, "samsung,s3c2410-uart",
3043 s3c2410_early_console_setup);
3045 /* S3C2412, S3C2440, S3C64xx */
3046 static struct samsung_early_console_data s3c2440_early_console_data = {
3047 .txfull_mask = S3C2440_UFSTAT_TXFULL,
3048 .rxfifo_mask = S3C2440_UFSTAT_RXFULL | S3C2440_UFSTAT_RXMASK,
3051 static int __init s3c2440_early_console_setup(struct earlycon_device *device,
3054 device->port.private_data = &s3c2440_early_console_data;
3055 return samsung_early_console_setup(device, opt);
3058 OF_EARLYCON_DECLARE(s3c2412, "samsung,s3c2412-uart",
3059 s3c2440_early_console_setup);
3060 OF_EARLYCON_DECLARE(s3c2440, "samsung,s3c2440-uart",
3061 s3c2440_early_console_setup);
3062 OF_EARLYCON_DECLARE(s3c6400, "samsung,s3c6400-uart",
3063 s3c2440_early_console_setup);
3065 /* S5PV210, Exynos */
3066 static struct samsung_early_console_data s5pv210_early_console_data = {
3067 .txfull_mask = S5PV210_UFSTAT_TXFULL,
3068 .rxfifo_mask = S5PV210_UFSTAT_RXFULL | S5PV210_UFSTAT_RXMASK,
3071 static int __init s5pv210_early_console_setup(struct earlycon_device *device,
3074 device->port.private_data = &s5pv210_early_console_data;
3075 return samsung_early_console_setup(device, opt);
3078 OF_EARLYCON_DECLARE(s5pv210, "samsung,s5pv210-uart",
3079 s5pv210_early_console_setup);
3080 OF_EARLYCON_DECLARE(exynos4210, "samsung,exynos4210-uart",
3081 s5pv210_early_console_setup);
3082 OF_EARLYCON_DECLARE(artpec8, "axis,artpec8-uart",
3083 s5pv210_early_console_setup);
3086 static int __init apple_s5l_early_console_setup(struct earlycon_device *device,
3089 /* Close enough to S3C2410 for earlycon... */
3090 device->port.private_data = &s3c2410_early_console_data;
3093 /* ... but we need to override the existing fixmap entry as nGnRnE */
3094 __set_fixmap(FIX_EARLYCON_MEM_BASE, device->port.mapbase,
3095 __pgprot(PROT_DEVICE_nGnRnE));
3097 return samsung_early_console_setup(device, opt);
3100 OF_EARLYCON_DECLARE(s5l, "apple,s5l-uart", apple_s5l_early_console_setup);
3103 MODULE_ALIAS("platform:samsung-uart");
3104 MODULE_DESCRIPTION("Samsung SoC Serial port driver");
3105 MODULE_AUTHOR("Ben Dooks <ben@simtec.co.uk>");
3106 MODULE_LICENSE("GPL v2");