blob: 73f951d65b9302486e03ef9a4605933621f9633d [file] [log] [blame]
Greg Kroah-Hartmane3b3d0f2017-11-06 18:11:51 +01001// SPDX-License-Identifier: GPL-2.0
Jovi Zhang99edb3d2011-03-30 05:30:41 -04002/*
Ben Dooksb4975492008-07-03 12:32:51 +01003 * Driver core for Samsung SoC onboard UARTs.
4 *
Ben Dooksccae9412009-11-13 22:54:14 +00005 * Ben Dooks, Copyright (c) 2003-2008 Simtec Electronics
Ben Dooksb4975492008-07-03 12:32:51 +01006 * http://armlinux.simtec.co.uk/
Greg Kroah-Hartman7c175252019-12-10 15:37:05 +01007 */
Ben Dooksb4975492008-07-03 12:32:51 +01008
9/* Hote on 2410 error handling
10 *
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.
16 *
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
20 *
21 * BJD, 04-Nov-2004
Greg Kroah-Hartman7c175252019-12-10 15:37:05 +010022 */
Ben Dooksb4975492008-07-03 12:32:51 +010023
Robert Baldyga62c37ee2014-12-10 12:49:25 +010024#include <linux/dmaengine.h>
25#include <linux/dma-mapping.h>
26#include <linux/slab.h>
Ben Dooksb4975492008-07-03 12:32:51 +010027#include <linux/module.h>
28#include <linux/ioport.h>
29#include <linux/io.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>
Arnd Bergmann9ee51f02013-04-11 02:04:48 +020038#include <linux/serial_s3c.h>
Ben Dooksb4975492008-07-03 12:32:51 +010039#include <linux/delay.h>
40#include <linux/clk.h>
Ben Dooks30555472008-10-21 14:06:36 +010041#include <linux/cpufreq.h>
Thomas Abraham26c919e2011-11-06 22:10:44 +053042#include <linux/of.h>
Ben Dooksb4975492008-07-03 12:32:51 +010043#include <asm/irq.h>
44
Ben Dooksb4975492008-07-03 12:32:51 +010045/* UART name and device definitions */
46
47#define S3C24XX_SERIAL_NAME "ttySAC"
48#define S3C24XX_SERIAL_MAJOR 204
49#define S3C24XX_SERIAL_MINOR 64
50
Robert Baldyga29bef792014-12-10 12:49:26 +010051#define S3C24XX_TX_PIO 1
52#define S3C24XX_TX_DMA 2
Robert Baldygab543c302014-12-10 12:49:27 +010053#define S3C24XX_RX_PIO 1
54#define S3C24XX_RX_DMA 2
Ben Dooksb4975492008-07-03 12:32:51 +010055
Lucas De Marchi25985ed2011-03-30 22:57:33 -030056/* flag to ignore all characters coming in */
Ben Dooksb4975492008-07-03 12:32:51 +010057#define RXSTAT_DUMMY_READ (0x10000000)
58
Greg Kroah-Hartman43df1702019-12-10 15:37:01 +010059struct s3c24xx_uart_info {
60 char *name;
61 unsigned int type;
62 unsigned int fifosize;
63 unsigned long rx_fifomask;
64 unsigned long rx_fifoshift;
65 unsigned long rx_fifofull;
66 unsigned long tx_fifomask;
67 unsigned long tx_fifoshift;
68 unsigned long tx_fifofull;
69 unsigned int def_clk_sel;
70 unsigned long num_clks;
71 unsigned long clksel_mask;
72 unsigned long clksel_shift;
73
74 /* uart port features */
75
76 unsigned int has_divslot:1;
77};
78
79struct s3c24xx_serial_drv_data {
80 struct s3c24xx_uart_info *info;
81 struct s3c2410_uartcfg *def_cfg;
82 unsigned int fifosize[CONFIG_SERIAL_SAMSUNG_UARTS];
83};
84
85struct s3c24xx_uart_dma {
86 unsigned int rx_chan_id;
87 unsigned int tx_chan_id;
88
89 struct dma_slave_config rx_conf;
90 struct dma_slave_config tx_conf;
91
92 struct dma_chan *rx_chan;
93 struct dma_chan *tx_chan;
94
95 dma_addr_t rx_addr;
96 dma_addr_t tx_addr;
97
98 dma_cookie_t rx_cookie;
99 dma_cookie_t tx_cookie;
100
101 char *rx_buf;
102
103 dma_addr_t tx_transfer_addr;
104
105 size_t rx_size;
106 size_t tx_size;
107
108 struct dma_async_tx_descriptor *tx_desc;
109 struct dma_async_tx_descriptor *rx_desc;
110
111 int tx_bytes_requested;
112 int rx_bytes_requested;
113};
114
115struct s3c24xx_uart_port {
116 unsigned char rx_claimed;
117 unsigned char tx_claimed;
Greg Kroah-Hartman83362402019-12-17 15:02:32 +0100118 unsigned char rx_enabled;
119 unsigned char tx_enabled;
Greg Kroah-Hartman43df1702019-12-10 15:37:01 +0100120 unsigned int pm_level;
121 unsigned long baudclk_rate;
122 unsigned int min_dma_size;
123
124 unsigned int rx_irq;
125 unsigned int tx_irq;
126
127 unsigned int tx_in_progress;
128 unsigned int tx_mode;
129 unsigned int rx_mode;
130
131 struct s3c24xx_uart_info *info;
132 struct clk *clk;
133 struct clk *baudclk;
134 struct uart_port port;
135 struct s3c24xx_serial_drv_data *drv_data;
136
137 /* reference to platform data */
138 struct s3c2410_uartcfg *cfg;
139
140 struct s3c24xx_uart_dma *dma;
141
142#ifdef CONFIG_ARM_S3C24XX_CPUFREQ
143 struct notifier_block freq_transition;
144#endif
145};
146
147/* conversion functions */
148
149#define s3c24xx_dev_to_port(__dev) dev_get_drvdata(__dev)
150
151/* register access controls */
152
153#define portaddr(port, reg) ((port)->membase + (reg))
154#define portaddrl(port, reg) \
155 ((unsigned long *)(unsigned long)((port)->membase + (reg)))
156
157#define rd_regb(port, reg) (readb_relaxed(portaddr(port, reg)))
158#define rd_regl(port, reg) (readl_relaxed(portaddr(port, reg)))
159
160#define wr_regb(port, reg, val) writeb_relaxed(val, portaddr(port, reg))
161#define wr_regl(port, reg, val) writel_relaxed(val, portaddr(port, reg))
162
163/* Byte-order aware bit setting/clearing functions. */
164
165static inline void s3c24xx_set_bit(struct uart_port *port, int idx,
166 unsigned int reg)
167{
168 unsigned long flags;
169 u32 val;
170
171 local_irq_save(flags);
172 val = rd_regl(port, reg);
173 val |= (1 << idx);
174 wr_regl(port, reg, val);
175 local_irq_restore(flags);
176}
177
178static inline void s3c24xx_clear_bit(struct uart_port *port, int idx,
179 unsigned int reg)
180{
181 unsigned long flags;
182 u32 val;
183
184 local_irq_save(flags);
185 val = rd_regl(port, reg);
186 val &= ~(1 << idx);
187 wr_regl(port, reg, val);
188 local_irq_restore(flags);
189}
190
Ben Dooksb4975492008-07-03 12:32:51 +0100191static inline struct s3c24xx_uart_port *to_ourport(struct uart_port *port)
192{
193 return container_of(port, struct s3c24xx_uart_port, port);
194}
195
196/* translate a port to the device name */
197
198static inline const char *s3c24xx_serial_portname(struct uart_port *port)
199{
200 return to_platform_device(port->dev)->name;
201}
202
203static int s3c24xx_serial_txempty_nofifo(struct uart_port *port)
204{
Sachin Kamat9303ac12012-09-05 10:30:11 +0530205 return rd_regl(port, S3C2410_UTRSTAT) & S3C2410_UTRSTAT_TXE;
Ben Dooksb4975492008-07-03 12:32:51 +0100206}
207
Thomas Abraham88bb4ea2011-08-10 15:51:19 +0530208/*
209 * s3c64xx and later SoC's include the interrupt mask and status registers in
210 * the controller itself, unlike the s3c24xx SoC's which have these registers
211 * in the interrupt controller. Check if the port type is s3c64xx or higher.
212 */
213static int s3c24xx_serial_has_interrupt_mask(struct uart_port *port)
214{
215 return to_ourport(port)->info->type == PORT_S3C6400;
216}
217
Ben Dooksb4975492008-07-03 12:32:51 +0100218static void s3c24xx_serial_rx_enable(struct uart_port *port)
219{
Greg Kroah-Hartman83362402019-12-17 15:02:32 +0100220 struct s3c24xx_uart_port *ourport = to_ourport(port);
Ben Dooksb4975492008-07-03 12:32:51 +0100221 unsigned long flags;
222 unsigned int ucon, ufcon;
223 int count = 10000;
224
225 spin_lock_irqsave(&port->lock, flags);
226
227 while (--count && !s3c24xx_serial_txempty_nofifo(port))
228 udelay(100);
229
230 ufcon = rd_regl(port, S3C2410_UFCON);
231 ufcon |= S3C2410_UFCON_RESETRX;
232 wr_regl(port, S3C2410_UFCON, ufcon);
233
234 ucon = rd_regl(port, S3C2410_UCON);
235 ucon |= S3C2410_UCON_RXIRQMODE;
236 wr_regl(port, S3C2410_UCON, ucon);
237
Greg Kroah-Hartman83362402019-12-17 15:02:32 +0100238 ourport->rx_enabled = 1;
Ben Dooksb4975492008-07-03 12:32:51 +0100239 spin_unlock_irqrestore(&port->lock, flags);
240}
241
242static void s3c24xx_serial_rx_disable(struct uart_port *port)
243{
Greg Kroah-Hartman83362402019-12-17 15:02:32 +0100244 struct s3c24xx_uart_port *ourport = to_ourport(port);
Ben Dooksb4975492008-07-03 12:32:51 +0100245 unsigned long flags;
246 unsigned int ucon;
247
248 spin_lock_irqsave(&port->lock, flags);
249
250 ucon = rd_regl(port, S3C2410_UCON);
251 ucon &= ~S3C2410_UCON_RXIRQMODE;
252 wr_regl(port, S3C2410_UCON, ucon);
253
Greg Kroah-Hartman83362402019-12-17 15:02:32 +0100254 ourport->rx_enabled = 0;
Ben Dooksb4975492008-07-03 12:32:51 +0100255 spin_unlock_irqrestore(&port->lock, flags);
256}
257
258static void s3c24xx_serial_stop_tx(struct uart_port *port)
259{
Ben Dooksb73c289c2008-10-21 14:07:04 +0100260 struct s3c24xx_uart_port *ourport = to_ourport(port);
Robert Baldyga29bef792014-12-10 12:49:26 +0100261 struct s3c24xx_uart_dma *dma = ourport->dma;
262 struct circ_buf *xmit = &port->state->xmit;
263 struct dma_tx_state state;
264 int count;
Ben Dooksb73c289c2008-10-21 14:07:04 +0100265
Greg Kroah-Hartman83362402019-12-17 15:02:32 +0100266 if (!ourport->tx_enabled)
Robert Baldyga29bef792014-12-10 12:49:26 +0100267 return;
268
269 if (s3c24xx_serial_has_interrupt_mask(port))
Matthew Leachbbb5ff92016-06-22 17:57:03 +0100270 s3c24xx_set_bit(port, S3C64XX_UINTM_TXD, S3C64XX_UINTM);
Robert Baldyga29bef792014-12-10 12:49:26 +0100271 else
272 disable_irq_nosync(ourport->tx_irq);
273
274 if (dma && dma->tx_chan && ourport->tx_in_progress == S3C24XX_TX_DMA) {
275 dmaengine_pause(dma->tx_chan);
276 dmaengine_tx_status(dma->tx_chan, dma->tx_cookie, &state);
277 dmaengine_terminate_all(dma->tx_chan);
278 dma_sync_single_for_cpu(ourport->port.dev,
279 dma->tx_transfer_addr, dma->tx_size, DMA_TO_DEVICE);
280 async_tx_ack(dma->tx_desc);
281 count = dma->tx_bytes_requested - state.residue;
282 xmit->tail = (xmit->tail + count) & (UART_XMIT_SIZE - 1);
283 port->icount.tx += count;
Ben Dooksb4975492008-07-03 12:32:51 +0100284 }
Robert Baldyga29bef792014-12-10 12:49:26 +0100285
Greg Kroah-Hartman83362402019-12-17 15:02:32 +0100286 ourport->tx_enabled = 0;
Robert Baldyga29bef792014-12-10 12:49:26 +0100287 ourport->tx_in_progress = 0;
288
289 if (port->flags & UPF_CONS_FLOW)
290 s3c24xx_serial_rx_enable(port);
291
292 ourport->tx_mode = 0;
Ben Dooksb4975492008-07-03 12:32:51 +0100293}
294
Robert Baldyga29bef792014-12-10 12:49:26 +0100295static void s3c24xx_serial_start_next_tx(struct s3c24xx_uart_port *ourport);
296
297static void s3c24xx_serial_tx_dma_complete(void *args)
298{
299 struct s3c24xx_uart_port *ourport = args;
300 struct uart_port *port = &ourport->port;
301 struct circ_buf *xmit = &port->state->xmit;
302 struct s3c24xx_uart_dma *dma = ourport->dma;
303 struct dma_tx_state state;
304 unsigned long flags;
305 int count;
306
307
308 dmaengine_tx_status(dma->tx_chan, dma->tx_cookie, &state);
309 count = dma->tx_bytes_requested - state.residue;
310 async_tx_ack(dma->tx_desc);
311
312 dma_sync_single_for_cpu(ourport->port.dev, dma->tx_transfer_addr,
313 dma->tx_size, DMA_TO_DEVICE);
314
315 spin_lock_irqsave(&port->lock, flags);
316
317 xmit->tail = (xmit->tail + count) & (UART_XMIT_SIZE - 1);
318 port->icount.tx += count;
319 ourport->tx_in_progress = 0;
320
321 if (uart_circ_chars_pending(xmit) < WAKEUP_CHARS)
322 uart_write_wakeup(port);
323
324 s3c24xx_serial_start_next_tx(ourport);
325 spin_unlock_irqrestore(&port->lock, flags);
326}
327
328static void enable_tx_dma(struct s3c24xx_uart_port *ourport)
329{
330 struct uart_port *port = &ourport->port;
331 u32 ucon;
332
333 /* Mask Tx interrupt */
334 if (s3c24xx_serial_has_interrupt_mask(port))
Matthew Leachbbb5ff92016-06-22 17:57:03 +0100335 s3c24xx_set_bit(port, S3C64XX_UINTM_TXD, S3C64XX_UINTM);
Robert Baldyga29bef792014-12-10 12:49:26 +0100336 else
337 disable_irq_nosync(ourport->tx_irq);
338
339 /* Enable tx dma mode */
340 ucon = rd_regl(port, S3C2410_UCON);
341 ucon &= ~(S3C64XX_UCON_TXBURST_MASK | S3C64XX_UCON_TXMODE_MASK);
342 ucon |= (dma_get_cache_alignment() >= 16) ?
343 S3C64XX_UCON_TXBURST_16 : S3C64XX_UCON_TXBURST_1;
344 ucon |= S3C64XX_UCON_TXMODE_DMA;
345 wr_regl(port, S3C2410_UCON, ucon);
346
347 ourport->tx_mode = S3C24XX_TX_DMA;
348}
349
350static void enable_tx_pio(struct s3c24xx_uart_port *ourport)
351{
352 struct uart_port *port = &ourport->port;
353 u32 ucon, ufcon;
354
355 /* Set ufcon txtrig */
356 ourport->tx_in_progress = S3C24XX_TX_PIO;
357 ufcon = rd_regl(port, S3C2410_UFCON);
358 wr_regl(port, S3C2410_UFCON, ufcon);
359
360 /* Enable tx pio mode */
361 ucon = rd_regl(port, S3C2410_UCON);
362 ucon &= ~(S3C64XX_UCON_TXMODE_MASK);
363 ucon |= S3C64XX_UCON_TXMODE_CPU;
364 wr_regl(port, S3C2410_UCON, ucon);
365
366 /* Unmask Tx interrupt */
367 if (s3c24xx_serial_has_interrupt_mask(port))
Matthew Leachbbb5ff92016-06-22 17:57:03 +0100368 s3c24xx_clear_bit(port, S3C64XX_UINTM_TXD,
369 S3C64XX_UINTM);
Robert Baldyga29bef792014-12-10 12:49:26 +0100370 else
371 enable_irq(ourport->tx_irq);
372
373 ourport->tx_mode = S3C24XX_TX_PIO;
374}
375
376static void s3c24xx_serial_start_tx_pio(struct s3c24xx_uart_port *ourport)
377{
378 if (ourport->tx_mode != S3C24XX_TX_PIO)
379 enable_tx_pio(ourport);
380}
381
382static int s3c24xx_serial_start_tx_dma(struct s3c24xx_uart_port *ourport,
383 unsigned int count)
384{
385 struct uart_port *port = &ourport->port;
386 struct circ_buf *xmit = &port->state->xmit;
387 struct s3c24xx_uart_dma *dma = ourport->dma;
388
389
390 if (ourport->tx_mode != S3C24XX_TX_DMA)
391 enable_tx_dma(ourport);
392
Robert Baldyga29bef792014-12-10 12:49:26 +0100393 dma->tx_size = count & ~(dma_get_cache_alignment() - 1);
394 dma->tx_transfer_addr = dma->tx_addr + xmit->tail;
395
396 dma_sync_single_for_device(ourport->port.dev, dma->tx_transfer_addr,
397 dma->tx_size, DMA_TO_DEVICE);
398
399 dma->tx_desc = dmaengine_prep_slave_single(dma->tx_chan,
400 dma->tx_transfer_addr, dma->tx_size,
401 DMA_MEM_TO_DEV, DMA_PREP_INTERRUPT);
402 if (!dma->tx_desc) {
403 dev_err(ourport->port.dev, "Unable to get desc for Tx\n");
404 return -EIO;
405 }
406
407 dma->tx_desc->callback = s3c24xx_serial_tx_dma_complete;
408 dma->tx_desc->callback_param = ourport;
409 dma->tx_bytes_requested = dma->tx_size;
410
411 ourport->tx_in_progress = S3C24XX_TX_DMA;
412 dma->tx_cookie = dmaengine_submit(dma->tx_desc);
413 dma_async_issue_pending(dma->tx_chan);
414 return 0;
415}
416
417static void s3c24xx_serial_start_next_tx(struct s3c24xx_uart_port *ourport)
418{
419 struct uart_port *port = &ourport->port;
420 struct circ_buf *xmit = &port->state->xmit;
421 unsigned long count;
422
423 /* Get data size up to the end of buffer */
424 count = CIRC_CNT_TO_END(xmit->head, xmit->tail, UART_XMIT_SIZE);
425
426 if (!count) {
427 s3c24xx_serial_stop_tx(port);
428 return;
429 }
430
Marek Szyprowski81ccb2a2015-07-31 10:58:27 +0200431 if (!ourport->dma || !ourport->dma->tx_chan ||
Robert Baldyga736cd792015-07-31 10:58:28 +0200432 count < ourport->min_dma_size ||
433 xmit->tail & (dma_get_cache_alignment() - 1))
Robert Baldyga29bef792014-12-10 12:49:26 +0100434 s3c24xx_serial_start_tx_pio(ourport);
435 else
436 s3c24xx_serial_start_tx_dma(ourport, count);
437}
438
Krzysztof Kozlowski75781972015-05-02 00:40:04 +0900439static void s3c24xx_serial_start_tx(struct uart_port *port)
Ben Dooksb4975492008-07-03 12:32:51 +0100440{
Ben Dooksb73c289c2008-10-21 14:07:04 +0100441 struct s3c24xx_uart_port *ourport = to_ourport(port);
Robert Baldyga29bef792014-12-10 12:49:26 +0100442 struct circ_buf *xmit = &port->state->xmit;
Ben Dooksb73c289c2008-10-21 14:07:04 +0100443
Greg Kroah-Hartman83362402019-12-17 15:02:32 +0100444 if (!ourport->tx_enabled) {
Ben Dooksb4975492008-07-03 12:32:51 +0100445 if (port->flags & UPF_CONS_FLOW)
446 s3c24xx_serial_rx_disable(port);
447
Greg Kroah-Hartman83362402019-12-17 15:02:32 +0100448 ourport->tx_enabled = 1;
Robert Baldygaba019a32015-01-28 14:44:23 +0100449 if (!ourport->dma || !ourport->dma->tx_chan)
Robert Baldyga29bef792014-12-10 12:49:26 +0100450 s3c24xx_serial_start_tx_pio(ourport);
Robert Baldyga29bef792014-12-10 12:49:26 +0100451 }
452
453 if (ourport->dma && ourport->dma->tx_chan) {
454 if (!uart_circ_empty(xmit) && !ourport->tx_in_progress)
455 s3c24xx_serial_start_next_tx(ourport);
Ben Dooksb4975492008-07-03 12:32:51 +0100456 }
457}
458
Robert Baldygab543c302014-12-10 12:49:27 +0100459static void s3c24xx_uart_copy_rx_to_tty(struct s3c24xx_uart_port *ourport,
460 struct tty_port *tty, int count)
461{
462 struct s3c24xx_uart_dma *dma = ourport->dma;
463 int copied;
464
465 if (!count)
466 return;
467
468 dma_sync_single_for_cpu(ourport->port.dev, dma->rx_addr,
469 dma->rx_size, DMA_FROM_DEVICE);
470
471 ourport->port.icount.rx += count;
472 if (!tty) {
473 dev_err(ourport->port.dev, "No tty port\n");
474 return;
475 }
476 copied = tty_insert_flip_string(tty,
477 ((unsigned char *)(ourport->dma->rx_buf)), count);
478 if (copied != count) {
479 WARN_ON(1);
480 dev_err(ourport->port.dev, "RxData copy to tty layer failed\n");
481 }
482}
483
Ben Dooksb4975492008-07-03 12:32:51 +0100484static void s3c24xx_serial_stop_rx(struct uart_port *port)
485{
Ben Dooksb73c289c2008-10-21 14:07:04 +0100486 struct s3c24xx_uart_port *ourport = to_ourport(port);
Robert Baldygab543c302014-12-10 12:49:27 +0100487 struct s3c24xx_uart_dma *dma = ourport->dma;
488 struct tty_port *t = &port->state->port;
489 struct dma_tx_state state;
490 enum dma_status dma_status;
491 unsigned int received;
Ben Dooksb73c289c2008-10-21 14:07:04 +0100492
Greg Kroah-Hartman83362402019-12-17 15:02:32 +0100493 if (ourport->rx_enabled) {
Greg Kroah-Hartmana05025d2019-12-10 15:37:03 +0100494 dev_dbg(port->dev, "stopping rx\n");
Thomas Abraham88bb4ea2011-08-10 15:51:19 +0530495 if (s3c24xx_serial_has_interrupt_mask(port))
Matthew Leachbbb5ff92016-06-22 17:57:03 +0100496 s3c24xx_set_bit(port, S3C64XX_UINTM_RXD,
497 S3C64XX_UINTM);
Thomas Abraham88bb4ea2011-08-10 15:51:19 +0530498 else
499 disable_irq_nosync(ourport->rx_irq);
Greg Kroah-Hartman83362402019-12-17 15:02:32 +0100500 ourport->rx_enabled = 0;
Ben Dooksb4975492008-07-03 12:32:51 +0100501 }
Robert Baldygab543c302014-12-10 12:49:27 +0100502 if (dma && dma->rx_chan) {
503 dmaengine_pause(dma->tx_chan);
504 dma_status = dmaengine_tx_status(dma->rx_chan,
505 dma->rx_cookie, &state);
506 if (dma_status == DMA_IN_PROGRESS ||
507 dma_status == DMA_PAUSED) {
508 received = dma->rx_bytes_requested - state.residue;
509 dmaengine_terminate_all(dma->rx_chan);
510 s3c24xx_uart_copy_rx_to_tty(ourport, t, received);
511 }
512 }
Ben Dooksb4975492008-07-03 12:32:51 +0100513}
514
Robert Baldygaef4aca72014-11-24 07:56:22 +0100515static inline struct s3c24xx_uart_info
516 *s3c24xx_port_to_info(struct uart_port *port)
Ben Dooksb4975492008-07-03 12:32:51 +0100517{
518 return to_ourport(port)->info;
519}
520
Robert Baldygaef4aca72014-11-24 07:56:22 +0100521static inline struct s3c2410_uartcfg
522 *s3c24xx_port_to_cfg(struct uart_port *port)
Ben Dooksb4975492008-07-03 12:32:51 +0100523{
Thomas Abraham4d84e972011-10-24 11:47:25 +0200524 struct s3c24xx_uart_port *ourport;
525
Ben Dooksb4975492008-07-03 12:32:51 +0100526 if (port->dev == NULL)
527 return NULL;
528
Thomas Abraham4d84e972011-10-24 11:47:25 +0200529 ourport = container_of(port, struct s3c24xx_uart_port, port);
530 return ourport->cfg;
Ben Dooksb4975492008-07-03 12:32:51 +0100531}
532
533static int s3c24xx_serial_rx_fifocnt(struct s3c24xx_uart_port *ourport,
534 unsigned long ufstat)
535{
536 struct s3c24xx_uart_info *info = ourport->info;
537
538 if (ufstat & info->rx_fifofull)
Thomas Abrahamda121502011-11-02 19:23:25 +0900539 return ourport->port.fifosize;
Ben Dooksb4975492008-07-03 12:32:51 +0100540
541 return (ufstat & info->rx_fifomask) >> info->rx_fifoshift;
542}
543
Robert Baldygab543c302014-12-10 12:49:27 +0100544static void s3c64xx_start_rx_dma(struct s3c24xx_uart_port *ourport);
545static void s3c24xx_serial_rx_dma_complete(void *args)
546{
547 struct s3c24xx_uart_port *ourport = args;
548 struct uart_port *port = &ourport->port;
549
550 struct s3c24xx_uart_dma *dma = ourport->dma;
551 struct tty_port *t = &port->state->port;
552 struct tty_struct *tty = tty_port_tty_get(&ourport->port.state->port);
553
554 struct dma_tx_state state;
555 unsigned long flags;
556 int received;
557
558 dmaengine_tx_status(dma->rx_chan, dma->rx_cookie, &state);
559 received = dma->rx_bytes_requested - state.residue;
560 async_tx_ack(dma->rx_desc);
561
562 spin_lock_irqsave(&port->lock, flags);
563
564 if (received)
565 s3c24xx_uart_copy_rx_to_tty(ourport, t, received);
566
567 if (tty) {
568 tty_flip_buffer_push(t);
569 tty_kref_put(tty);
570 }
571
572 s3c64xx_start_rx_dma(ourport);
573
574 spin_unlock_irqrestore(&port->lock, flags);
575}
576
577static void s3c64xx_start_rx_dma(struct s3c24xx_uart_port *ourport)
578{
579 struct s3c24xx_uart_dma *dma = ourport->dma;
580
581 dma_sync_single_for_device(ourport->port.dev, dma->rx_addr,
582 dma->rx_size, DMA_FROM_DEVICE);
583
584 dma->rx_desc = dmaengine_prep_slave_single(dma->rx_chan,
585 dma->rx_addr, dma->rx_size, DMA_DEV_TO_MEM,
586 DMA_PREP_INTERRUPT);
587 if (!dma->rx_desc) {
588 dev_err(ourport->port.dev, "Unable to get desc for Rx\n");
589 return;
590 }
591
592 dma->rx_desc->callback = s3c24xx_serial_rx_dma_complete;
593 dma->rx_desc->callback_param = ourport;
594 dma->rx_bytes_requested = dma->rx_size;
595
596 dma->rx_cookie = dmaengine_submit(dma->rx_desc);
597 dma_async_issue_pending(dma->rx_chan);
598}
Ben Dooksb4975492008-07-03 12:32:51 +0100599
600/* ? - where has parity gone?? */
601#define S3C2410_UERSTAT_PARITY (0x1000)
602
Robert Baldygab543c302014-12-10 12:49:27 +0100603static void enable_rx_dma(struct s3c24xx_uart_port *ourport)
604{
605 struct uart_port *port = &ourport->port;
606 unsigned int ucon;
607
608 /* set Rx mode to DMA mode */
609 ucon = rd_regl(port, S3C2410_UCON);
610 ucon &= ~(S3C64XX_UCON_RXBURST_MASK |
611 S3C64XX_UCON_TIMEOUT_MASK |
612 S3C64XX_UCON_EMPTYINT_EN |
613 S3C64XX_UCON_DMASUS_EN |
614 S3C64XX_UCON_TIMEOUT_EN |
615 S3C64XX_UCON_RXMODE_MASK);
616 ucon |= S3C64XX_UCON_RXBURST_16 |
617 0xf << S3C64XX_UCON_TIMEOUT_SHIFT |
618 S3C64XX_UCON_EMPTYINT_EN |
619 S3C64XX_UCON_TIMEOUT_EN |
620 S3C64XX_UCON_RXMODE_DMA;
621 wr_regl(port, S3C2410_UCON, ucon);
622
623 ourport->rx_mode = S3C24XX_RX_DMA;
624}
625
626static void enable_rx_pio(struct s3c24xx_uart_port *ourport)
627{
628 struct uart_port *port = &ourport->port;
629 unsigned int ucon;
630
631 /* set Rx mode to DMA mode */
632 ucon = rd_regl(port, S3C2410_UCON);
633 ucon &= ~(S3C64XX_UCON_TIMEOUT_MASK |
634 S3C64XX_UCON_EMPTYINT_EN |
635 S3C64XX_UCON_DMASUS_EN |
636 S3C64XX_UCON_TIMEOUT_EN |
637 S3C64XX_UCON_RXMODE_MASK);
638 ucon |= 0xf << S3C64XX_UCON_TIMEOUT_SHIFT |
639 S3C64XX_UCON_TIMEOUT_EN |
640 S3C64XX_UCON_RXMODE_CPU;
641 wr_regl(port, S3C2410_UCON, ucon);
642
643 ourport->rx_mode = S3C24XX_RX_PIO;
644}
645
Robert Baldyga09557c02015-09-15 14:49:00 +0200646static void s3c24xx_serial_rx_drain_fifo(struct s3c24xx_uart_port *ourport);
647
Robert Baldygae4678af2015-09-15 14:48:57 +0200648static irqreturn_t s3c24xx_serial_rx_chars_dma(void *dev_id)
Robert Baldygab543c302014-12-10 12:49:27 +0100649{
Chen Wandun98aee0c2019-11-22 20:04:18 +0800650 unsigned int utrstat, received;
Robert Baldygab543c302014-12-10 12:49:27 +0100651 struct s3c24xx_uart_port *ourport = dev_id;
652 struct uart_port *port = &ourport->port;
653 struct s3c24xx_uart_dma *dma = ourport->dma;
654 struct tty_struct *tty = tty_port_tty_get(&ourport->port.state->port);
655 struct tty_port *t = &port->state->port;
656 unsigned long flags;
657 struct dma_tx_state state;
658
659 utrstat = rd_regl(port, S3C2410_UTRSTAT);
Chen Wandun98aee0c2019-11-22 20:04:18 +0800660 rd_regl(port, S3C2410_UFSTAT);
Robert Baldygab543c302014-12-10 12:49:27 +0100661
662 spin_lock_irqsave(&port->lock, flags);
663
664 if (!(utrstat & S3C2410_UTRSTAT_TIMEOUT)) {
665 s3c64xx_start_rx_dma(ourport);
666 if (ourport->rx_mode == S3C24XX_RX_PIO)
667 enable_rx_dma(ourport);
668 goto finish;
669 }
670
671 if (ourport->rx_mode == S3C24XX_RX_DMA) {
672 dmaengine_pause(dma->rx_chan);
673 dmaengine_tx_status(dma->rx_chan, dma->rx_cookie, &state);
674 dmaengine_terminate_all(dma->rx_chan);
675 received = dma->rx_bytes_requested - state.residue;
676 s3c24xx_uart_copy_rx_to_tty(ourport, t, received);
677
678 enable_rx_pio(ourport);
679 }
680
Robert Baldyga09557c02015-09-15 14:49:00 +0200681 s3c24xx_serial_rx_drain_fifo(ourport);
Robert Baldygab543c302014-12-10 12:49:27 +0100682
683 if (tty) {
684 tty_flip_buffer_push(t);
685 tty_kref_put(tty);
686 }
687
688 wr_regl(port, S3C2410_UTRSTAT, S3C2410_UTRSTAT_TIMEOUT);
689
690finish:
691 spin_unlock_irqrestore(&port->lock, flags);
692
693 return IRQ_HANDLED;
694}
695
Robert Baldyga01732dd2015-09-15 14:48:59 +0200696static void s3c24xx_serial_rx_drain_fifo(struct s3c24xx_uart_port *ourport)
Ben Dooksb4975492008-07-03 12:32:51 +0100697{
Ben Dooksb4975492008-07-03 12:32:51 +0100698 struct uart_port *port = &ourport->port;
Ben Dooksb4975492008-07-03 12:32:51 +0100699 unsigned int ufcon, ch, flag, ufstat, uerstat;
Youngmin Namaba06e92016-03-05 19:36:32 +0900700 unsigned int fifocnt = 0;
Robert Baldyga57850a52014-11-24 07:56:24 +0100701 int max_count = port->fifosize;
Ben Dooksb4975492008-07-03 12:32:51 +0100702
703 while (max_count-- > 0) {
Youngmin Namaba06e92016-03-05 19:36:32 +0900704 /*
705 * Receive all characters known to be in FIFO
706 * before reading FIFO level again
707 */
708 if (fifocnt == 0) {
709 ufstat = rd_regl(port, S3C2410_UFSTAT);
710 fifocnt = s3c24xx_serial_rx_fifocnt(ourport, ufstat);
711 if (fifocnt == 0)
712 break;
713 }
714 fifocnt--;
Ben Dooksb4975492008-07-03 12:32:51 +0100715
716 uerstat = rd_regl(port, S3C2410_UERSTAT);
717 ch = rd_regb(port, S3C2410_URXH);
718
719 if (port->flags & UPF_CONS_FLOW) {
720 int txe = s3c24xx_serial_txempty_nofifo(port);
721
Greg Kroah-Hartman83362402019-12-17 15:02:32 +0100722 if (ourport->rx_enabled) {
Ben Dooksb4975492008-07-03 12:32:51 +0100723 if (!txe) {
Greg Kroah-Hartman83362402019-12-17 15:02:32 +0100724 ourport->rx_enabled = 0;
Ben Dooksb4975492008-07-03 12:32:51 +0100725 continue;
726 }
727 } else {
728 if (txe) {
Youngmin Namaba06e92016-03-05 19:36:32 +0900729 ufcon = rd_regl(port, S3C2410_UFCON);
Ben Dooksb4975492008-07-03 12:32:51 +0100730 ufcon |= S3C2410_UFCON_RESETRX;
731 wr_regl(port, S3C2410_UFCON, ufcon);
Greg Kroah-Hartman83362402019-12-17 15:02:32 +0100732 ourport->rx_enabled = 1;
Robert Baldyga01732dd2015-09-15 14:48:59 +0200733 return;
Ben Dooksb4975492008-07-03 12:32:51 +0100734 }
735 continue;
736 }
737 }
738
739 /* insert the character into the buffer */
740
741 flag = TTY_NORMAL;
742 port->icount.rx++;
743
744 if (unlikely(uerstat & S3C2410_UERSTAT_ANY)) {
Greg Kroah-Hartmana05025d2019-12-10 15:37:03 +0100745 dev_dbg(port->dev,
746 "rxerr: port ch=0x%02x, rxs=0x%08x\n",
747 ch, uerstat);
Ben Dooksb4975492008-07-03 12:32:51 +0100748
749 /* check for break */
750 if (uerstat & S3C2410_UERSTAT_BREAK) {
Greg Kroah-Hartmana05025d2019-12-10 15:37:03 +0100751 dev_dbg(port->dev, "break!\n");
Ben Dooksb4975492008-07-03 12:32:51 +0100752 port->icount.brk++;
753 if (uart_handle_break(port))
Robert Baldyga620bb212015-09-15 14:48:58 +0200754 continue; /* Ignore character */
Ben Dooksb4975492008-07-03 12:32:51 +0100755 }
756
757 if (uerstat & S3C2410_UERSTAT_FRAME)
758 port->icount.frame++;
759 if (uerstat & S3C2410_UERSTAT_OVERRUN)
760 port->icount.overrun++;
761
762 uerstat &= port->read_status_mask;
763
764 if (uerstat & S3C2410_UERSTAT_BREAK)
765 flag = TTY_BREAK;
766 else if (uerstat & S3C2410_UERSTAT_PARITY)
767 flag = TTY_PARITY;
768 else if (uerstat & (S3C2410_UERSTAT_FRAME |
769 S3C2410_UERSTAT_OVERRUN))
770 flag = TTY_FRAME;
771 }
772
773 if (uart_handle_sysrq_char(port, ch))
Robert Baldyga620bb212015-09-15 14:48:58 +0200774 continue; /* Ignore character */
Ben Dooksb4975492008-07-03 12:32:51 +0100775
776 uart_insert_char(port, uerstat, S3C2410_UERSTAT_OVERRUN,
777 ch, flag);
Ben Dooksb4975492008-07-03 12:32:51 +0100778 }
Viresh Kumarf5693ea2013-08-19 20:14:26 +0530779
Jiri Slaby2e124b42013-01-03 15:53:06 +0100780 tty_flip_buffer_push(&port->state->port);
Robert Baldyga01732dd2015-09-15 14:48:59 +0200781}
Ben Dooksb4975492008-07-03 12:32:51 +0100782
Robert Baldyga01732dd2015-09-15 14:48:59 +0200783static irqreturn_t s3c24xx_serial_rx_chars_pio(void *dev_id)
784{
785 struct s3c24xx_uart_port *ourport = dev_id;
786 struct uart_port *port = &ourport->port;
787 unsigned long flags;
788
789 spin_lock_irqsave(&port->lock, flags);
790 s3c24xx_serial_rx_drain_fifo(ourport);
791 spin_unlock_irqrestore(&port->lock, flags);
792
Ben Dooksb4975492008-07-03 12:32:51 +0100793 return IRQ_HANDLED;
794}
795
Robert Baldygab543c302014-12-10 12:49:27 +0100796
797static irqreturn_t s3c24xx_serial_rx_chars(int irq, void *dev_id)
798{
799 struct s3c24xx_uart_port *ourport = dev_id;
800
801 if (ourport->dma && ourport->dma->rx_chan)
Robert Baldygae4678af2015-09-15 14:48:57 +0200802 return s3c24xx_serial_rx_chars_dma(dev_id);
803 return s3c24xx_serial_rx_chars_pio(dev_id);
Robert Baldygab543c302014-12-10 12:49:27 +0100804}
805
Ben Dooksb4975492008-07-03 12:32:51 +0100806static irqreturn_t s3c24xx_serial_tx_chars(int irq, void *id)
807{
808 struct s3c24xx_uart_port *ourport = id;
809 struct uart_port *port = &ourport->port;
Alan Coxebd2c8f2009-09-19 13:13:28 -0700810 struct circ_buf *xmit = &port->state->xmit;
Thomas Abrahamc15c3742012-11-22 18:06:28 +0530811 unsigned long flags;
Robert Baldyga736cd792015-07-31 10:58:28 +0200812 int count, dma_count = 0;
Ben Dooksb4975492008-07-03 12:32:51 +0100813
Thomas Abrahamc15c3742012-11-22 18:06:28 +0530814 spin_lock_irqsave(&port->lock, flags);
815
Robert Baldyga29bef792014-12-10 12:49:26 +0100816 count = CIRC_CNT_TO_END(xmit->head, xmit->tail, UART_XMIT_SIZE);
817
Marek Szyprowski81ccb2a2015-07-31 10:58:27 +0200818 if (ourport->dma && ourport->dma->tx_chan &&
819 count >= ourport->min_dma_size) {
Robert Baldyga736cd792015-07-31 10:58:28 +0200820 int align = dma_get_cache_alignment() -
821 (xmit->tail & (dma_get_cache_alignment() - 1));
822 if (count-align >= ourport->min_dma_size) {
823 dma_count = count-align;
824 count = align;
825 }
Robert Baldyga29bef792014-12-10 12:49:26 +0100826 }
827
Ben Dooksb4975492008-07-03 12:32:51 +0100828 if (port->x_char) {
829 wr_regb(port, S3C2410_UTXH, port->x_char);
830 port->icount.tx++;
831 port->x_char = 0;
832 goto out;
833 }
834
Lucas De Marchi25985ed2011-03-30 22:57:33 -0300835 /* if there isn't anything more to transmit, or the uart is now
Ben Dooksb4975492008-07-03 12:32:51 +0100836 * stopped, disable the uart and exit
Greg Kroah-Hartman7c175252019-12-10 15:37:05 +0100837 */
Ben Dooksb4975492008-07-03 12:32:51 +0100838
839 if (uart_circ_empty(xmit) || uart_tx_stopped(port)) {
840 s3c24xx_serial_stop_tx(port);
841 goto out;
842 }
843
844 /* try and drain the buffer... */
845
Robert Baldyga736cd792015-07-31 10:58:28 +0200846 if (count > port->fifosize) {
847 count = port->fifosize;
848 dma_count = 0;
849 }
850
851 while (!uart_circ_empty(xmit) && count > 0) {
Ben Dooksb4975492008-07-03 12:32:51 +0100852 if (rd_regl(port, S3C2410_UFSTAT) & ourport->info->tx_fifofull)
853 break;
854
855 wr_regb(port, S3C2410_UTXH, xmit->buf[xmit->tail]);
856 xmit->tail = (xmit->tail + 1) & (UART_XMIT_SIZE - 1);
857 port->icount.tx++;
Robert Baldyga736cd792015-07-31 10:58:28 +0200858 count--;
859 }
860
861 if (!count && dma_count) {
862 s3c24xx_serial_start_tx_dma(ourport, dma_count);
863 goto out;
Ben Dooksb4975492008-07-03 12:32:51 +0100864 }
865
Thomas Abrahamc15c3742012-11-22 18:06:28 +0530866 if (uart_circ_chars_pending(xmit) < WAKEUP_CHARS) {
867 spin_unlock(&port->lock);
Ben Dooksb4975492008-07-03 12:32:51 +0100868 uart_write_wakeup(port);
Thomas Abrahamc15c3742012-11-22 18:06:28 +0530869 spin_lock(&port->lock);
870 }
Ben Dooksb4975492008-07-03 12:32:51 +0100871
872 if (uart_circ_empty(xmit))
873 s3c24xx_serial_stop_tx(port);
874
Robert Baldygaef4aca72014-11-24 07:56:22 +0100875out:
Thomas Abrahamc15c3742012-11-22 18:06:28 +0530876 spin_unlock_irqrestore(&port->lock, flags);
Ben Dooksb4975492008-07-03 12:32:51 +0100877 return IRQ_HANDLED;
878}
879
Thomas Abraham88bb4ea2011-08-10 15:51:19 +0530880/* interrupt handler for s3c64xx and later SoC's.*/
881static irqreturn_t s3c64xx_serial_handle_irq(int irq, void *id)
882{
883 struct s3c24xx_uart_port *ourport = id;
884 struct uart_port *port = &ourport->port;
885 unsigned int pend = rd_regl(port, S3C64XX_UINTP);
Thomas Abraham88bb4ea2011-08-10 15:51:19 +0530886 irqreturn_t ret = IRQ_HANDLED;
887
Thomas Abraham88bb4ea2011-08-10 15:51:19 +0530888 if (pend & S3C64XX_UINTM_RXD_MSK) {
889 ret = s3c24xx_serial_rx_chars(irq, id);
890 wr_regl(port, S3C64XX_UINTP, S3C64XX_UINTM_RXD_MSK);
891 }
892 if (pend & S3C64XX_UINTM_TXD_MSK) {
893 ret = s3c24xx_serial_tx_chars(irq, id);
894 wr_regl(port, S3C64XX_UINTP, S3C64XX_UINTM_TXD_MSK);
895 }
Thomas Abraham88bb4ea2011-08-10 15:51:19 +0530896 return ret;
897}
898
Ben Dooksb4975492008-07-03 12:32:51 +0100899static unsigned int s3c24xx_serial_tx_empty(struct uart_port *port)
900{
901 struct s3c24xx_uart_info *info = s3c24xx_port_to_info(port);
902 unsigned long ufstat = rd_regl(port, S3C2410_UFSTAT);
903 unsigned long ufcon = rd_regl(port, S3C2410_UFCON);
904
905 if (ufcon & S3C2410_UFCON_FIFOMODE) {
906 if ((ufstat & info->tx_fifomask) != 0 ||
907 (ufstat & info->tx_fifofull))
908 return 0;
909
910 return 1;
911 }
912
913 return s3c24xx_serial_txempty_nofifo(port);
914}
915
916/* no modem control lines */
917static unsigned int s3c24xx_serial_get_mctrl(struct uart_port *port)
918{
919 unsigned int umstat = rd_regb(port, S3C2410_UMSTAT);
920
921 if (umstat & S3C2410_UMSTAT_CTS)
922 return TIOCM_CAR | TIOCM_DSR | TIOCM_CTS;
923 else
924 return TIOCM_CAR | TIOCM_DSR;
925}
926
927static void s3c24xx_serial_set_mctrl(struct uart_port *port, unsigned int mctrl)
928{
José Miguel Gonçalves2d1e5a42013-09-18 16:52:49 +0100929 unsigned int umcon = rd_regl(port, S3C2410_UMCON);
930
931 if (mctrl & TIOCM_RTS)
932 umcon |= S3C2410_UMCOM_RTS_LOW;
933 else
934 umcon &= ~S3C2410_UMCOM_RTS_LOW;
935
936 wr_regl(port, S3C2410_UMCON, umcon);
Ben Dooksb4975492008-07-03 12:32:51 +0100937}
938
939static void s3c24xx_serial_break_ctl(struct uart_port *port, int break_state)
940{
941 unsigned long flags;
942 unsigned int ucon;
943
944 spin_lock_irqsave(&port->lock, flags);
945
946 ucon = rd_regl(port, S3C2410_UCON);
947
948 if (break_state)
949 ucon |= S3C2410_UCON_SBREAK;
950 else
951 ucon &= ~S3C2410_UCON_SBREAK;
952
953 wr_regl(port, S3C2410_UCON, ucon);
954
955 spin_unlock_irqrestore(&port->lock, flags);
956}
957
Robert Baldyga62c37ee2014-12-10 12:49:25 +0100958static int s3c24xx_serial_request_dma(struct s3c24xx_uart_port *p)
959{
960 struct s3c24xx_uart_dma *dma = p->dma;
Marek Szyprowskid8db8402018-05-17 13:37:14 +0200961 struct dma_slave_caps dma_caps;
962 const char *reason = NULL;
Marek Szyprowski500fcc02017-04-03 08:21:00 +0200963 int ret;
Robert Baldyga62c37ee2014-12-10 12:49:25 +0100964
965 /* Default slave configuration parameters */
966 dma->rx_conf.direction = DMA_DEV_TO_MEM;
967 dma->rx_conf.src_addr_width = DMA_SLAVE_BUSWIDTH_1_BYTE;
968 dma->rx_conf.src_addr = p->port.mapbase + S3C2410_URXH;
Marek Szyprowskiaa2f80e2018-05-10 08:41:13 +0200969 dma->rx_conf.src_maxburst = 1;
Robert Baldyga62c37ee2014-12-10 12:49:25 +0100970
971 dma->tx_conf.direction = DMA_MEM_TO_DEV;
972 dma->tx_conf.dst_addr_width = DMA_SLAVE_BUSWIDTH_1_BYTE;
973 dma->tx_conf.dst_addr = p->port.mapbase + S3C2410_UTXH;
Marek Szyprowskiaa2f80e2018-05-10 08:41:13 +0200974 dma->tx_conf.dst_maxburst = 1;
Robert Baldyga62c37ee2014-12-10 12:49:25 +0100975
Marek Szyprowskiba3d6f82016-12-16 10:56:53 +0100976 dma->rx_chan = dma_request_chan(p->port.dev, "rx");
Robert Baldyga62c37ee2014-12-10 12:49:25 +0100977
Marek Szyprowskid8db8402018-05-17 13:37:14 +0200978 if (IS_ERR(dma->rx_chan)) {
979 reason = "DMA RX channel request failed";
980 ret = PTR_ERR(dma->rx_chan);
981 goto err_warn;
982 }
983
984 ret = dma_get_slave_caps(dma->rx_chan, &dma_caps);
985 if (ret < 0 ||
986 dma_caps.residue_granularity < DMA_RESIDUE_GRANULARITY_BURST) {
987 reason = "insufficient DMA RX engine capabilities";
988 ret = -EOPNOTSUPP;
989 goto err_release_rx;
990 }
Robert Baldyga62c37ee2014-12-10 12:49:25 +0100991
992 dmaengine_slave_config(dma->rx_chan, &dma->rx_conf);
993
Marek Szyprowskiba3d6f82016-12-16 10:56:53 +0100994 dma->tx_chan = dma_request_chan(p->port.dev, "tx");
995 if (IS_ERR(dma->tx_chan)) {
Marek Szyprowskid8db8402018-05-17 13:37:14 +0200996 reason = "DMA TX channel request failed";
Marek Szyprowski500fcc02017-04-03 08:21:00 +0200997 ret = PTR_ERR(dma->tx_chan);
998 goto err_release_rx;
Robert Baldyga62c37ee2014-12-10 12:49:25 +0100999 }
1000
Marek Szyprowskid8db8402018-05-17 13:37:14 +02001001 ret = dma_get_slave_caps(dma->tx_chan, &dma_caps);
1002 if (ret < 0 ||
1003 dma_caps.residue_granularity < DMA_RESIDUE_GRANULARITY_BURST) {
1004 reason = "insufficient DMA TX engine capabilities";
1005 ret = -EOPNOTSUPP;
1006 goto err_release_tx;
1007 }
1008
Robert Baldyga62c37ee2014-12-10 12:49:25 +01001009 dmaengine_slave_config(dma->tx_chan, &dma->tx_conf);
1010
1011 /* RX buffer */
1012 dma->rx_size = PAGE_SIZE;
1013
1014 dma->rx_buf = kmalloc(dma->rx_size, GFP_KERNEL);
Robert Baldyga62c37ee2014-12-10 12:49:25 +01001015 if (!dma->rx_buf) {
Marek Szyprowski500fcc02017-04-03 08:21:00 +02001016 ret = -ENOMEM;
1017 goto err_release_tx;
Robert Baldyga62c37ee2014-12-10 12:49:25 +01001018 }
1019
Marek Szyprowski768d64f2017-04-03 08:20:59 +02001020 dma->rx_addr = dma_map_single(p->port.dev, dma->rx_buf,
Robert Baldyga62c37ee2014-12-10 12:49:25 +01001021 dma->rx_size, DMA_FROM_DEVICE);
Marek Szyprowski500fcc02017-04-03 08:21:00 +02001022 if (dma_mapping_error(p->port.dev, dma->rx_addr)) {
Marek Szyprowskid8db8402018-05-17 13:37:14 +02001023 reason = "DMA mapping error for RX buffer";
Marek Szyprowski500fcc02017-04-03 08:21:00 +02001024 ret = -EIO;
1025 goto err_free_rx;
1026 }
Robert Baldyga62c37ee2014-12-10 12:49:25 +01001027
Robert Baldyga62c37ee2014-12-10 12:49:25 +01001028 /* TX buffer */
Marek Szyprowski768d64f2017-04-03 08:20:59 +02001029 dma->tx_addr = dma_map_single(p->port.dev, p->port.state->xmit.buf,
Robert Baldyga62c37ee2014-12-10 12:49:25 +01001030 UART_XMIT_SIZE, DMA_TO_DEVICE);
Marek Szyprowski500fcc02017-04-03 08:21:00 +02001031 if (dma_mapping_error(p->port.dev, dma->tx_addr)) {
Marek Szyprowskid8db8402018-05-17 13:37:14 +02001032 reason = "DMA mapping error for TX buffer";
Marek Szyprowski500fcc02017-04-03 08:21:00 +02001033 ret = -EIO;
1034 goto err_unmap_rx;
1035 }
Robert Baldyga62c37ee2014-12-10 12:49:25 +01001036
1037 return 0;
Marek Szyprowski500fcc02017-04-03 08:21:00 +02001038
1039err_unmap_rx:
1040 dma_unmap_single(p->port.dev, dma->rx_addr, dma->rx_size,
1041 DMA_FROM_DEVICE);
1042err_free_rx:
1043 kfree(dma->rx_buf);
1044err_release_tx:
1045 dma_release_channel(dma->tx_chan);
1046err_release_rx:
1047 dma_release_channel(dma->rx_chan);
Marek Szyprowskid8db8402018-05-17 13:37:14 +02001048err_warn:
1049 if (reason)
1050 dev_warn(p->port.dev, "%s, DMA will not be used\n", reason);
Marek Szyprowski500fcc02017-04-03 08:21:00 +02001051 return ret;
Robert Baldyga62c37ee2014-12-10 12:49:25 +01001052}
1053
1054static void s3c24xx_serial_release_dma(struct s3c24xx_uart_port *p)
1055{
1056 struct s3c24xx_uart_dma *dma = p->dma;
1057
1058 if (dma->rx_chan) {
1059 dmaengine_terminate_all(dma->rx_chan);
Marek Szyprowski768d64f2017-04-03 08:20:59 +02001060 dma_unmap_single(p->port.dev, dma->rx_addr,
Robert Baldyga62c37ee2014-12-10 12:49:25 +01001061 dma->rx_size, DMA_FROM_DEVICE);
1062 kfree(dma->rx_buf);
1063 dma_release_channel(dma->rx_chan);
1064 dma->rx_chan = NULL;
1065 }
1066
1067 if (dma->tx_chan) {
1068 dmaengine_terminate_all(dma->tx_chan);
Marek Szyprowski768d64f2017-04-03 08:20:59 +02001069 dma_unmap_single(p->port.dev, dma->tx_addr,
Robert Baldyga62c37ee2014-12-10 12:49:25 +01001070 UART_XMIT_SIZE, DMA_TO_DEVICE);
1071 dma_release_channel(dma->tx_chan);
1072 dma->tx_chan = NULL;
1073 }
1074}
1075
Ben Dooksb4975492008-07-03 12:32:51 +01001076static void s3c24xx_serial_shutdown(struct uart_port *port)
1077{
1078 struct s3c24xx_uart_port *ourport = to_ourport(port);
1079
1080 if (ourport->tx_claimed) {
Thomas Abraham88bb4ea2011-08-10 15:51:19 +05301081 if (!s3c24xx_serial_has_interrupt_mask(port))
1082 free_irq(ourport->tx_irq, ourport);
Greg Kroah-Hartman83362402019-12-17 15:02:32 +01001083 ourport->tx_enabled = 0;
Ben Dooksb4975492008-07-03 12:32:51 +01001084 ourport->tx_claimed = 0;
Javier Martinez Canillase91d8632015-03-13 12:38:51 +01001085 ourport->tx_mode = 0;
Ben Dooksb4975492008-07-03 12:32:51 +01001086 }
1087
1088 if (ourport->rx_claimed) {
Thomas Abraham88bb4ea2011-08-10 15:51:19 +05301089 if (!s3c24xx_serial_has_interrupt_mask(port))
1090 free_irq(ourport->rx_irq, ourport);
Ben Dooksb4975492008-07-03 12:32:51 +01001091 ourport->rx_claimed = 0;
Greg Kroah-Hartman83362402019-12-17 15:02:32 +01001092 ourport->rx_enabled = 0;
Ben Dooksb4975492008-07-03 12:32:51 +01001093 }
Ben Dooksb4975492008-07-03 12:32:51 +01001094
Thomas Abraham88bb4ea2011-08-10 15:51:19 +05301095 /* Clear pending interrupts and mask all interrupts */
1096 if (s3c24xx_serial_has_interrupt_mask(port)) {
Tomasz Figab6ad2932013-03-26 15:57:35 +01001097 free_irq(port->irq, ourport);
1098
Thomas Abraham88bb4ea2011-08-10 15:51:19 +05301099 wr_regl(port, S3C64XX_UINTP, 0xf);
1100 wr_regl(port, S3C64XX_UINTM, 0xf);
1101 }
Robert Baldyga62c37ee2014-12-10 12:49:25 +01001102
1103 if (ourport->dma)
1104 s3c24xx_serial_release_dma(ourport);
1105
Robert Baldyga29bef792014-12-10 12:49:26 +01001106 ourport->tx_in_progress = 0;
Thomas Abraham88bb4ea2011-08-10 15:51:19 +05301107}
Ben Dooksb4975492008-07-03 12:32:51 +01001108
1109static int s3c24xx_serial_startup(struct uart_port *port)
1110{
1111 struct s3c24xx_uart_port *ourport = to_ourport(port);
1112 int ret;
1113
Greg Kroah-Hartman83362402019-12-17 15:02:32 +01001114 ourport->rx_enabled = 1;
Ben Dooksb4975492008-07-03 12:32:51 +01001115
Ben Dooksb73c289c2008-10-21 14:07:04 +01001116 ret = request_irq(ourport->rx_irq, s3c24xx_serial_rx_chars, 0,
Ben Dooksb4975492008-07-03 12:32:51 +01001117 s3c24xx_serial_portname(port), ourport);
1118
1119 if (ret != 0) {
Sachin Kamatd20925e2012-09-05 10:30:10 +05301120 dev_err(port->dev, "cannot get irq %d\n", ourport->rx_irq);
Ben Dooksb4975492008-07-03 12:32:51 +01001121 return ret;
1122 }
1123
1124 ourport->rx_claimed = 1;
1125
Greg Kroah-Hartmana05025d2019-12-10 15:37:03 +01001126 dev_dbg(port->dev, "requesting tx irq...\n");
Ben Dooksb4975492008-07-03 12:32:51 +01001127
Greg Kroah-Hartman83362402019-12-17 15:02:32 +01001128 ourport->tx_enabled = 1;
Ben Dooksb4975492008-07-03 12:32:51 +01001129
Ben Dooksb73c289c2008-10-21 14:07:04 +01001130 ret = request_irq(ourport->tx_irq, s3c24xx_serial_tx_chars, 0,
Ben Dooksb4975492008-07-03 12:32:51 +01001131 s3c24xx_serial_portname(port), ourport);
1132
1133 if (ret) {
Sachin Kamatd20925e2012-09-05 10:30:10 +05301134 dev_err(port->dev, "cannot get irq %d\n", ourport->tx_irq);
Ben Dooksb4975492008-07-03 12:32:51 +01001135 goto err;
1136 }
1137
1138 ourport->tx_claimed = 1;
1139
Ben Dooksb4975492008-07-03 12:32:51 +01001140 /* the port reset code should have done the correct
Greg Kroah-Hartman7c175252019-12-10 15:37:05 +01001141 * register setup for the port controls
1142 */
Ben Dooksb4975492008-07-03 12:32:51 +01001143
1144 return ret;
1145
Robert Baldygaef4aca72014-11-24 07:56:22 +01001146err:
Ben Dooksb4975492008-07-03 12:32:51 +01001147 s3c24xx_serial_shutdown(port);
1148 return ret;
1149}
1150
Thomas Abraham88bb4ea2011-08-10 15:51:19 +05301151static int s3c64xx_serial_startup(struct uart_port *port)
1152{
1153 struct s3c24xx_uart_port *ourport = to_ourport(port);
Robert Baldygab543c302014-12-10 12:49:27 +01001154 unsigned long flags;
1155 unsigned int ufcon;
Thomas Abraham88bb4ea2011-08-10 15:51:19 +05301156 int ret;
1157
Tomasz Figab6ad2932013-03-26 15:57:35 +01001158 wr_regl(port, S3C64XX_UINTM, 0xf);
Robert Baldyga62c37ee2014-12-10 12:49:25 +01001159 if (ourport->dma) {
1160 ret = s3c24xx_serial_request_dma(ourport);
1161 if (ret < 0) {
Krzysztof Kozlowskif98c7bc2017-02-25 18:36:44 +02001162 devm_kfree(port->dev, ourport->dma);
1163 ourport->dma = NULL;
Robert Baldyga62c37ee2014-12-10 12:49:25 +01001164 }
1165 }
Tomasz Figab6ad2932013-03-26 15:57:35 +01001166
Thomas Abraham88bb4ea2011-08-10 15:51:19 +05301167 ret = request_irq(port->irq, s3c64xx_serial_handle_irq, IRQF_SHARED,
1168 s3c24xx_serial_portname(port), ourport);
1169 if (ret) {
Sachin Kamatd20925e2012-09-05 10:30:10 +05301170 dev_err(port->dev, "cannot get irq %d\n", port->irq);
Thomas Abraham88bb4ea2011-08-10 15:51:19 +05301171 return ret;
1172 }
1173
1174 /* For compatibility with s3c24xx Soc's */
Greg Kroah-Hartman83362402019-12-17 15:02:32 +01001175 ourport->rx_enabled = 1;
Thomas Abraham88bb4ea2011-08-10 15:51:19 +05301176 ourport->rx_claimed = 1;
Greg Kroah-Hartman83362402019-12-17 15:02:32 +01001177 ourport->tx_enabled = 0;
Thomas Abraham88bb4ea2011-08-10 15:51:19 +05301178 ourport->tx_claimed = 1;
1179
Robert Baldyga29bef792014-12-10 12:49:26 +01001180 spin_lock_irqsave(&port->lock, flags);
1181
1182 ufcon = rd_regl(port, S3C2410_UFCON);
Robert Baldyga31c6ba92015-04-17 08:43:09 +02001183 ufcon |= S3C2410_UFCON_RESETRX | S5PV210_UFCON_RXTRIG8;
1184 if (!uart_console(port))
1185 ufcon |= S3C2410_UFCON_RESETTX;
Robert Baldyga29bef792014-12-10 12:49:26 +01001186 wr_regl(port, S3C2410_UFCON, ufcon);
1187
1188 enable_rx_pio(ourport);
1189
1190 spin_unlock_irqrestore(&port->lock, flags);
1191
Thomas Abraham88bb4ea2011-08-10 15:51:19 +05301192 /* Enable Rx Interrupt */
Matthew Leachbbb5ff92016-06-22 17:57:03 +01001193 s3c24xx_clear_bit(port, S3C64XX_UINTM_RXD, S3C64XX_UINTM);
Robert Baldyga29bef792014-12-10 12:49:26 +01001194
Thomas Abraham88bb4ea2011-08-10 15:51:19 +05301195 return ret;
1196}
1197
Ben Dooksb4975492008-07-03 12:32:51 +01001198/* power power management control */
1199
1200static void s3c24xx_serial_pm(struct uart_port *port, unsigned int level,
1201 unsigned int old)
1202{
1203 struct s3c24xx_uart_port *ourport = to_ourport(port);
Robert Baldyga1ff383a2014-11-24 07:56:21 +01001204 int timeout = 10000;
Ben Dooksb4975492008-07-03 12:32:51 +01001205
Ben Dooks30555472008-10-21 14:06:36 +01001206 ourport->pm_level = level;
1207
Ben Dooksb4975492008-07-03 12:32:51 +01001208 switch (level) {
1209 case 3:
Robert Baldyga1ff383a2014-11-24 07:56:21 +01001210 while (--timeout && !s3c24xx_serial_txempty_nofifo(port))
1211 udelay(100);
1212
Kyoungil Kim7cd88832012-05-20 17:45:54 +09001213 if (!IS_ERR(ourport->baudclk))
Thomas Abraham9484b002012-10-03 07:40:04 +09001214 clk_disable_unprepare(ourport->baudclk);
Ben Dooksb4975492008-07-03 12:32:51 +01001215
Thomas Abraham9484b002012-10-03 07:40:04 +09001216 clk_disable_unprepare(ourport->clk);
Ben Dooksb4975492008-07-03 12:32:51 +01001217 break;
1218
1219 case 0:
Thomas Abraham9484b002012-10-03 07:40:04 +09001220 clk_prepare_enable(ourport->clk);
Ben Dooksb4975492008-07-03 12:32:51 +01001221
Kyoungil Kim7cd88832012-05-20 17:45:54 +09001222 if (!IS_ERR(ourport->baudclk))
Thomas Abraham9484b002012-10-03 07:40:04 +09001223 clk_prepare_enable(ourport->baudclk);
Ben Dooksb4975492008-07-03 12:32:51 +01001224
1225 break;
1226 default:
Sachin Kamatd20925e2012-09-05 10:30:10 +05301227 dev_err(port->dev, "s3c24xx_serial: unknown pm %d\n", level);
Ben Dooksb4975492008-07-03 12:32:51 +01001228 }
1229}
1230
1231/* baud rate calculation
1232 *
1233 * The UARTs on the S3C2410/S3C2440 can take their clocks from a number
1234 * of different sources, including the peripheral clock ("pclk") and an
1235 * external clock ("uclk"). The S3C2440 also adds the core clock ("fclk")
1236 * with a programmable extra divisor.
1237 *
1238 * The following code goes through the clock sources, and calculates the
1239 * baud clocks (and the resultant actual baud rates) and then tries to
1240 * pick the closest one and select that.
1241 *
Greg Kroah-Hartman7c175252019-12-10 15:37:05 +01001242 */
Ben Dooksb4975492008-07-03 12:32:51 +01001243
Thomas Abraham5f5a7a52011-10-24 11:47:46 +02001244#define MAX_CLK_NAME_LENGTH 15
Ben Dooksb4975492008-07-03 12:32:51 +01001245
Thomas Abraham5f5a7a52011-10-24 11:47:46 +02001246static inline int s3c24xx_serial_getsource(struct uart_port *port)
Ben Dooksb4975492008-07-03 12:32:51 +01001247{
1248 struct s3c24xx_uart_info *info = s3c24xx_port_to_info(port);
Thomas Abraham5f5a7a52011-10-24 11:47:46 +02001249 unsigned int ucon;
Ben Dooksb4975492008-07-03 12:32:51 +01001250
Thomas Abraham5f5a7a52011-10-24 11:47:46 +02001251 if (info->num_clks == 1)
Ben Dooksb4975492008-07-03 12:32:51 +01001252 return 0;
1253
Thomas Abraham5f5a7a52011-10-24 11:47:46 +02001254 ucon = rd_regl(port, S3C2410_UCON);
1255 ucon &= info->clksel_mask;
1256 return ucon >> info->clksel_shift;
Ben Dooksb4975492008-07-03 12:32:51 +01001257}
1258
Thomas Abraham5f5a7a52011-10-24 11:47:46 +02001259static void s3c24xx_serial_setsource(struct uart_port *port,
1260 unsigned int clk_sel)
Ben Dooksb4975492008-07-03 12:32:51 +01001261{
Thomas Abraham5f5a7a52011-10-24 11:47:46 +02001262 struct s3c24xx_uart_info *info = s3c24xx_port_to_info(port);
1263 unsigned int ucon;
Ben Dooksb4975492008-07-03 12:32:51 +01001264
Thomas Abraham5f5a7a52011-10-24 11:47:46 +02001265 if (info->num_clks == 1)
1266 return;
Ben Dooksb4975492008-07-03 12:32:51 +01001267
Thomas Abraham5f5a7a52011-10-24 11:47:46 +02001268 ucon = rd_regl(port, S3C2410_UCON);
1269 if ((ucon & info->clksel_mask) >> info->clksel_shift == clk_sel)
1270 return;
Ben Dooksb4975492008-07-03 12:32:51 +01001271
Thomas Abraham5f5a7a52011-10-24 11:47:46 +02001272 ucon &= ~info->clksel_mask;
1273 ucon |= clk_sel << info->clksel_shift;
1274 wr_regl(port, S3C2410_UCON, ucon);
1275}
Ben Dooksb4975492008-07-03 12:32:51 +01001276
Thomas Abraham5f5a7a52011-10-24 11:47:46 +02001277static unsigned int s3c24xx_serial_getclk(struct s3c24xx_uart_port *ourport,
1278 unsigned int req_baud, struct clk **best_clk,
1279 unsigned int *clk_num)
1280{
1281 struct s3c24xx_uart_info *info = ourport->info;
1282 struct clk *clk;
1283 unsigned long rate;
1284 unsigned int cnt, baud, quot, clk_sel, best_quot = 0;
1285 char clkname[MAX_CLK_NAME_LENGTH];
1286 int calc_deviation, deviation = (1 << 30) - 1;
1287
Thomas Abraham5f5a7a52011-10-24 11:47:46 +02001288 clk_sel = (ourport->cfg->clk_sel) ? ourport->cfg->clk_sel :
1289 ourport->info->def_clk_sel;
1290 for (cnt = 0; cnt < info->num_clks; cnt++) {
1291 if (!(clk_sel & (1 << cnt)))
1292 continue;
1293
1294 sprintf(clkname, "clk_uart_baud%d", cnt);
1295 clk = clk_get(ourport->port.dev, clkname);
Kyoungil Kim7cd88832012-05-20 17:45:54 +09001296 if (IS_ERR(clk))
Thomas Abraham5f5a7a52011-10-24 11:47:46 +02001297 continue;
1298
1299 rate = clk_get_rate(clk);
1300 if (!rate)
1301 continue;
1302
1303 if (ourport->info->has_divslot) {
1304 unsigned long div = rate / req_baud;
1305
1306 /* The UDIVSLOT register on the newer UARTs allows us to
1307 * get a divisor adjustment of 1/16th on the baud clock.
1308 *
1309 * We don't keep the UDIVSLOT value (the 16ths we
1310 * calculated by not multiplying the baud by 16) as it
1311 * is easy enough to recalculate.
1312 */
1313
1314 quot = div / 16;
1315 baud = rate / div;
1316 } else {
1317 quot = (rate + (8 * req_baud)) / (16 * req_baud);
1318 baud = rate / (quot * 16);
1319 }
1320 quot--;
1321
1322 calc_deviation = req_baud - baud;
1323 if (calc_deviation < 0)
1324 calc_deviation = -calc_deviation;
1325
1326 if (calc_deviation < deviation) {
1327 *best_clk = clk;
1328 best_quot = quot;
1329 *clk_num = cnt;
1330 deviation = calc_deviation;
Ben Dooksb4975492008-07-03 12:32:51 +01001331 }
1332 }
1333
Thomas Abraham5f5a7a52011-10-24 11:47:46 +02001334 return best_quot;
Ben Dooksb4975492008-07-03 12:32:51 +01001335}
1336
Ben Dooks090f848d2008-12-12 00:24:21 +00001337/* udivslot_table[]
1338 *
1339 * This table takes the fractional value of the baud divisor and gives
1340 * the recommended setting for the UDIVSLOT register.
1341 */
1342static u16 udivslot_table[16] = {
1343 [0] = 0x0000,
1344 [1] = 0x0080,
1345 [2] = 0x0808,
1346 [3] = 0x0888,
1347 [4] = 0x2222,
1348 [5] = 0x4924,
1349 [6] = 0x4A52,
1350 [7] = 0x54AA,
1351 [8] = 0x5555,
1352 [9] = 0xD555,
1353 [10] = 0xD5D5,
1354 [11] = 0xDDD5,
1355 [12] = 0xDDDD,
1356 [13] = 0xDFDD,
1357 [14] = 0xDFDF,
1358 [15] = 0xFFDF,
1359};
1360
Ben Dooksb4975492008-07-03 12:32:51 +01001361static void s3c24xx_serial_set_termios(struct uart_port *port,
1362 struct ktermios *termios,
1363 struct ktermios *old)
1364{
1365 struct s3c2410_uartcfg *cfg = s3c24xx_port_to_cfg(port);
1366 struct s3c24xx_uart_port *ourport = to_ourport(port);
Kyoungil Kim7cd88832012-05-20 17:45:54 +09001367 struct clk *clk = ERR_PTR(-EINVAL);
Ben Dooksb4975492008-07-03 12:32:51 +01001368 unsigned long flags;
Thomas Abraham5f5a7a52011-10-24 11:47:46 +02001369 unsigned int baud, quot, clk_sel = 0;
Ben Dooksb4975492008-07-03 12:32:51 +01001370 unsigned int ulcon;
1371 unsigned int umcon;
Ben Dooks090f848d2008-12-12 00:24:21 +00001372 unsigned int udivslot = 0;
Ben Dooksb4975492008-07-03 12:32:51 +01001373
1374 /*
1375 * We don't support modem control lines.
1376 */
1377 termios->c_cflag &= ~(HUPCL | CMSPAR);
1378 termios->c_cflag |= CLOCAL;
1379
1380 /*
1381 * Ask the core to calculate the divisor for us.
1382 */
1383
Seung-Woo Kimec18f482018-12-14 12:34:09 +01001384 baud = uart_get_baud_rate(port, termios, old, 0, 3000000);
Thomas Abraham5f5a7a52011-10-24 11:47:46 +02001385 quot = s3c24xx_serial_getclk(ourport, baud, &clk, &clk_sel);
Ben Dooksb4975492008-07-03 12:32:51 +01001386 if (baud == 38400 && (port->flags & UPF_SPD_MASK) == UPF_SPD_CUST)
1387 quot = port->custom_divisor;
Kyoungil Kim7cd88832012-05-20 17:45:54 +09001388 if (IS_ERR(clk))
Thomas Abraham5f5a7a52011-10-24 11:47:46 +02001389 return;
Ben Dooksb4975492008-07-03 12:32:51 +01001390
1391 /* check to see if we need to change clock source */
1392
Thomas Abraham5f5a7a52011-10-24 11:47:46 +02001393 if (ourport->baudclk != clk) {
Chanwoo Choib8995f52016-04-21 18:58:31 +09001394 clk_prepare_enable(clk);
1395
Thomas Abraham5f5a7a52011-10-24 11:47:46 +02001396 s3c24xx_serial_setsource(port, clk_sel);
Ben Dooksb4975492008-07-03 12:32:51 +01001397
Kyoungil Kim7cd88832012-05-20 17:45:54 +09001398 if (!IS_ERR(ourport->baudclk)) {
Thomas Abraham9484b002012-10-03 07:40:04 +09001399 clk_disable_unprepare(ourport->baudclk);
Kyoungil Kim7cd88832012-05-20 17:45:54 +09001400 ourport->baudclk = ERR_PTR(-EINVAL);
Ben Dooksb4975492008-07-03 12:32:51 +01001401 }
1402
Ben Dooksb4975492008-07-03 12:32:51 +01001403 ourport->baudclk = clk;
Ben Dooks30555472008-10-21 14:06:36 +01001404 ourport->baudclk_rate = clk ? clk_get_rate(clk) : 0;
Ben Dooksb4975492008-07-03 12:32:51 +01001405 }
1406
Ben Dooks090f848d2008-12-12 00:24:21 +00001407 if (ourport->info->has_divslot) {
1408 unsigned int div = ourport->baudclk_rate / baud;
1409
Jongpill Lee8b526ae2010-07-16 10:19:41 +09001410 if (cfg->has_fracval) {
1411 udivslot = (div & 15);
Greg Kroah-Hartmana05025d2019-12-10 15:37:03 +01001412 dev_dbg(port->dev, "fracval = %04x\n", udivslot);
Jongpill Lee8b526ae2010-07-16 10:19:41 +09001413 } else {
1414 udivslot = udivslot_table[div & 15];
Greg Kroah-Hartmana05025d2019-12-10 15:37:03 +01001415 dev_dbg(port->dev, "udivslot = %04x (div %d)\n",
1416 udivslot, div & 15);
Jongpill Lee8b526ae2010-07-16 10:19:41 +09001417 }
Ben Dooks090f848d2008-12-12 00:24:21 +00001418 }
1419
Ben Dooksb4975492008-07-03 12:32:51 +01001420 switch (termios->c_cflag & CSIZE) {
1421 case CS5:
Greg Kroah-Hartmana05025d2019-12-10 15:37:03 +01001422 dev_dbg(port->dev, "config: 5bits/char\n");
Ben Dooksb4975492008-07-03 12:32:51 +01001423 ulcon = S3C2410_LCON_CS5;
1424 break;
1425 case CS6:
Greg Kroah-Hartmana05025d2019-12-10 15:37:03 +01001426 dev_dbg(port->dev, "config: 6bits/char\n");
Ben Dooksb4975492008-07-03 12:32:51 +01001427 ulcon = S3C2410_LCON_CS6;
1428 break;
1429 case CS7:
Greg Kroah-Hartmana05025d2019-12-10 15:37:03 +01001430 dev_dbg(port->dev, "config: 7bits/char\n");
Ben Dooksb4975492008-07-03 12:32:51 +01001431 ulcon = S3C2410_LCON_CS7;
1432 break;
1433 case CS8:
1434 default:
Greg Kroah-Hartmana05025d2019-12-10 15:37:03 +01001435 dev_dbg(port->dev, "config: 8bits/char\n");
Ben Dooksb4975492008-07-03 12:32:51 +01001436 ulcon = S3C2410_LCON_CS8;
1437 break;
1438 }
1439
1440 /* preserve original lcon IR settings */
1441 ulcon |= (cfg->ulcon & S3C2410_LCON_IRM);
1442
1443 if (termios->c_cflag & CSTOPB)
1444 ulcon |= S3C2410_LCON_STOPB;
1445
Ben Dooksb4975492008-07-03 12:32:51 +01001446 if (termios->c_cflag & PARENB) {
1447 if (termios->c_cflag & PARODD)
1448 ulcon |= S3C2410_LCON_PODD;
1449 else
1450 ulcon |= S3C2410_LCON_PEVEN;
1451 } else {
1452 ulcon |= S3C2410_LCON_PNONE;
1453 }
1454
1455 spin_lock_irqsave(&port->lock, flags);
1456
Greg Kroah-Hartmana05025d2019-12-10 15:37:03 +01001457 dev_dbg(port->dev,
1458 "setting ulcon to %08x, brddiv to %d, udivslot %08x\n",
1459 ulcon, quot, udivslot);
Ben Dooksb4975492008-07-03 12:32:51 +01001460
1461 wr_regl(port, S3C2410_ULCON, ulcon);
1462 wr_regl(port, S3C2410_UBRDIV, quot);
José Miguel Gonçalves2d1e5a42013-09-18 16:52:49 +01001463
Beomho Seo31e93362018-12-14 12:34:08 +01001464 port->status &= ~UPSTAT_AUTOCTS;
1465
José Miguel Gonçalves2d1e5a42013-09-18 16:52:49 +01001466 umcon = rd_regl(port, S3C2410_UMCON);
1467 if (termios->c_cflag & CRTSCTS) {
1468 umcon |= S3C2410_UMCOM_AFC;
1469 /* Disable RTS when RX FIFO contains 63 bytes */
1470 umcon &= ~S3C2412_UMCON_AFC_8;
Beomho Seo31e93362018-12-14 12:34:08 +01001471 port->status = UPSTAT_AUTOCTS;
José Miguel Gonçalves2d1e5a42013-09-18 16:52:49 +01001472 } else {
1473 umcon &= ~S3C2410_UMCOM_AFC;
1474 }
Ben Dooksb4975492008-07-03 12:32:51 +01001475 wr_regl(port, S3C2410_UMCON, umcon);
1476
Ben Dooks090f848d2008-12-12 00:24:21 +00001477 if (ourport->info->has_divslot)
1478 wr_regl(port, S3C2443_DIVSLOT, udivslot);
1479
Greg Kroah-Hartmana05025d2019-12-10 15:37:03 +01001480 dev_dbg(port->dev,
1481 "uart: ulcon = 0x%08x, ucon = 0x%08x, ufcon = 0x%08x\n",
1482 rd_regl(port, S3C2410_ULCON),
1483 rd_regl(port, S3C2410_UCON),
1484 rd_regl(port, S3C2410_UFCON));
Ben Dooksb4975492008-07-03 12:32:51 +01001485
1486 /*
1487 * Update the per-port timeout.
1488 */
1489 uart_update_timeout(port, termios->c_cflag, baud);
1490
1491 /*
1492 * Which character status flags are we interested in?
1493 */
1494 port->read_status_mask = S3C2410_UERSTAT_OVERRUN;
1495 if (termios->c_iflag & INPCK)
Robert Baldygaef4aca72014-11-24 07:56:22 +01001496 port->read_status_mask |= S3C2410_UERSTAT_FRAME |
1497 S3C2410_UERSTAT_PARITY;
Ben Dooksb4975492008-07-03 12:32:51 +01001498 /*
1499 * Which character status flags should we ignore?
1500 */
1501 port->ignore_status_mask = 0;
1502 if (termios->c_iflag & IGNPAR)
1503 port->ignore_status_mask |= S3C2410_UERSTAT_OVERRUN;
1504 if (termios->c_iflag & IGNBRK && termios->c_iflag & IGNPAR)
1505 port->ignore_status_mask |= S3C2410_UERSTAT_FRAME;
1506
1507 /*
1508 * Ignore all characters if CREAD is not set.
1509 */
1510 if ((termios->c_cflag & CREAD) == 0)
1511 port->ignore_status_mask |= RXSTAT_DUMMY_READ;
1512
1513 spin_unlock_irqrestore(&port->lock, flags);
1514}
1515
1516static const char *s3c24xx_serial_type(struct uart_port *port)
1517{
1518 switch (port->type) {
1519 case PORT_S3C2410:
1520 return "S3C2410";
1521 case PORT_S3C2440:
1522 return "S3C2440";
1523 case PORT_S3C2412:
1524 return "S3C2412";
Ben Dooksb690ace2008-10-21 14:07:03 +01001525 case PORT_S3C6400:
1526 return "S3C6400/10";
Ben Dooksb4975492008-07-03 12:32:51 +01001527 default:
1528 return NULL;
1529 }
1530}
1531
1532#define MAP_SIZE (0x100)
1533
1534static void s3c24xx_serial_release_port(struct uart_port *port)
1535{
1536 release_mem_region(port->mapbase, MAP_SIZE);
1537}
1538
1539static int s3c24xx_serial_request_port(struct uart_port *port)
1540{
1541 const char *name = s3c24xx_serial_portname(port);
Greg Kroah-Hartman9fe0d412019-12-10 15:37:06 +01001542
Ben Dooksb4975492008-07-03 12:32:51 +01001543 return request_mem_region(port->mapbase, MAP_SIZE, name) ? 0 : -EBUSY;
1544}
1545
1546static void s3c24xx_serial_config_port(struct uart_port *port, int flags)
1547{
1548 struct s3c24xx_uart_info *info = s3c24xx_port_to_info(port);
1549
1550 if (flags & UART_CONFIG_TYPE &&
1551 s3c24xx_serial_request_port(port) == 0)
1552 port->type = info->type;
1553}
1554
1555/*
1556 * verify the new serial_struct (for TIOCSSERIAL).
1557 */
1558static int
1559s3c24xx_serial_verify_port(struct uart_port *port, struct serial_struct *ser)
1560{
1561 struct s3c24xx_uart_info *info = s3c24xx_port_to_info(port);
1562
1563 if (ser->type != PORT_UNKNOWN && ser->type != info->type)
1564 return -EINVAL;
1565
1566 return 0;
1567}
1568
1569
1570#ifdef CONFIG_SERIAL_SAMSUNG_CONSOLE
1571
1572static struct console s3c24xx_serial_console;
1573
Julien Pichon93b5c032012-09-21 23:22:31 -07001574static int __init s3c24xx_serial_console_init(void)
1575{
1576 register_console(&s3c24xx_serial_console);
1577 return 0;
1578}
1579console_initcall(s3c24xx_serial_console_init);
1580
Ben Dooksb4975492008-07-03 12:32:51 +01001581#define S3C24XX_SERIAL_CONSOLE &s3c24xx_serial_console
1582#else
1583#define S3C24XX_SERIAL_CONSOLE NULL
1584#endif
1585
Arnd Bergmann84f57d92013-04-11 02:04:49 +02001586#if defined(CONFIG_SERIAL_SAMSUNG_CONSOLE) && defined(CONFIG_CONSOLE_POLL)
Julien Pichon93b5c032012-09-21 23:22:31 -07001587static int s3c24xx_serial_get_poll_char(struct uart_port *port);
1588static void s3c24xx_serial_put_poll_char(struct uart_port *port,
1589 unsigned char c);
1590#endif
1591
Ben Dooksb4975492008-07-03 12:32:51 +01001592static struct uart_ops s3c24xx_serial_ops = {
1593 .pm = s3c24xx_serial_pm,
1594 .tx_empty = s3c24xx_serial_tx_empty,
1595 .get_mctrl = s3c24xx_serial_get_mctrl,
1596 .set_mctrl = s3c24xx_serial_set_mctrl,
1597 .stop_tx = s3c24xx_serial_stop_tx,
1598 .start_tx = s3c24xx_serial_start_tx,
1599 .stop_rx = s3c24xx_serial_stop_rx,
Ben Dooksb4975492008-07-03 12:32:51 +01001600 .break_ctl = s3c24xx_serial_break_ctl,
1601 .startup = s3c24xx_serial_startup,
1602 .shutdown = s3c24xx_serial_shutdown,
1603 .set_termios = s3c24xx_serial_set_termios,
1604 .type = s3c24xx_serial_type,
1605 .release_port = s3c24xx_serial_release_port,
1606 .request_port = s3c24xx_serial_request_port,
1607 .config_port = s3c24xx_serial_config_port,
1608 .verify_port = s3c24xx_serial_verify_port,
Arnd Bergmann84f57d92013-04-11 02:04:49 +02001609#if defined(CONFIG_SERIAL_SAMSUNG_CONSOLE) && defined(CONFIG_CONSOLE_POLL)
Julien Pichon93b5c032012-09-21 23:22:31 -07001610 .poll_get_char = s3c24xx_serial_get_poll_char,
1611 .poll_put_char = s3c24xx_serial_put_poll_char,
1612#endif
Ben Dooksb4975492008-07-03 12:32:51 +01001613};
1614
Ben Dooksb4975492008-07-03 12:32:51 +01001615static struct uart_driver s3c24xx_uart_drv = {
1616 .owner = THIS_MODULE,
Darius Augulis2cf0c582011-01-12 14:50:51 +09001617 .driver_name = "s3c2410_serial",
Ben Dooksbdd49152008-11-03 19:51:42 +00001618 .nr = CONFIG_SERIAL_SAMSUNG_UARTS,
Ben Dooksb4975492008-07-03 12:32:51 +01001619 .cons = S3C24XX_SERIAL_CONSOLE,
Darius Augulis2cf0c582011-01-12 14:50:51 +09001620 .dev_name = S3C24XX_SERIAL_NAME,
Ben Dooksb4975492008-07-03 12:32:51 +01001621 .major = S3C24XX_SERIAL_MAJOR,
1622 .minor = S3C24XX_SERIAL_MINOR,
1623};
1624
Robert Baldygaef4aca72014-11-24 07:56:22 +01001625#define __PORT_LOCK_UNLOCKED(i) \
1626 __SPIN_LOCK_UNLOCKED(s3c24xx_serial_ports[i].port.lock)
1627static struct s3c24xx_uart_port
1628s3c24xx_serial_ports[CONFIG_SERIAL_SAMSUNG_UARTS] = {
Ben Dooksb4975492008-07-03 12:32:51 +01001629 [0] = {
1630 .port = {
Robert Baldygaef4aca72014-11-24 07:56:22 +01001631 .lock = __PORT_LOCK_UNLOCKED(0),
Ben Dooksb4975492008-07-03 12:32:51 +01001632 .iotype = UPIO_MEM,
Ben Dooksb4975492008-07-03 12:32:51 +01001633 .uartclk = 0,
1634 .fifosize = 16,
1635 .ops = &s3c24xx_serial_ops,
1636 .flags = UPF_BOOT_AUTOCONF,
1637 .line = 0,
1638 }
1639 },
1640 [1] = {
1641 .port = {
Robert Baldygaef4aca72014-11-24 07:56:22 +01001642 .lock = __PORT_LOCK_UNLOCKED(1),
Ben Dooksb4975492008-07-03 12:32:51 +01001643 .iotype = UPIO_MEM,
Ben Dooksb4975492008-07-03 12:32:51 +01001644 .uartclk = 0,
1645 .fifosize = 16,
1646 .ops = &s3c24xx_serial_ops,
1647 .flags = UPF_BOOT_AUTOCONF,
1648 .line = 1,
1649 }
1650 },
Ben Dooks03d5e772008-11-03 09:21:23 +00001651#if CONFIG_SERIAL_SAMSUNG_UARTS > 2
Ben Dooksb4975492008-07-03 12:32:51 +01001652
1653 [2] = {
1654 .port = {
Robert Baldygaef4aca72014-11-24 07:56:22 +01001655 .lock = __PORT_LOCK_UNLOCKED(2),
Ben Dooksb4975492008-07-03 12:32:51 +01001656 .iotype = UPIO_MEM,
Ben Dooksb4975492008-07-03 12:32:51 +01001657 .uartclk = 0,
1658 .fifosize = 16,
1659 .ops = &s3c24xx_serial_ops,
1660 .flags = UPF_BOOT_AUTOCONF,
1661 .line = 2,
1662 }
Ben Dooks03d5e772008-11-03 09:21:23 +00001663 },
1664#endif
1665#if CONFIG_SERIAL_SAMSUNG_UARTS > 3
1666 [3] = {
1667 .port = {
Robert Baldygaef4aca72014-11-24 07:56:22 +01001668 .lock = __PORT_LOCK_UNLOCKED(3),
Ben Dooks03d5e772008-11-03 09:21:23 +00001669 .iotype = UPIO_MEM,
Ben Dooks03d5e772008-11-03 09:21:23 +00001670 .uartclk = 0,
1671 .fifosize = 16,
1672 .ops = &s3c24xx_serial_ops,
1673 .flags = UPF_BOOT_AUTOCONF,
1674 .line = 3,
1675 }
Ben Dooksb4975492008-07-03 12:32:51 +01001676 }
1677#endif
1678};
Robert Baldygaef4aca72014-11-24 07:56:22 +01001679#undef __PORT_LOCK_UNLOCKED
Ben Dooksb4975492008-07-03 12:32:51 +01001680
1681/* s3c24xx_serial_resetport
1682 *
Thomas Abraham0dfb3b42011-10-24 11:48:21 +02001683 * reset the fifos and other the settings.
Greg Kroah-Hartman7c175252019-12-10 15:37:05 +01001684 */
Ben Dooksb4975492008-07-03 12:32:51 +01001685
Thomas Abraham0dfb3b42011-10-24 11:48:21 +02001686static void s3c24xx_serial_resetport(struct uart_port *port,
1687 struct s3c2410_uartcfg *cfg)
Ben Dooksb4975492008-07-03 12:32:51 +01001688{
1689 struct s3c24xx_uart_info *info = s3c24xx_port_to_info(port);
Thomas Abraham0dfb3b42011-10-24 11:48:21 +02001690 unsigned long ucon = rd_regl(port, S3C2410_UCON);
1691 unsigned int ucon_mask;
Ben Dooksb4975492008-07-03 12:32:51 +01001692
Thomas Abraham0dfb3b42011-10-24 11:48:21 +02001693 ucon_mask = info->clksel_mask;
1694 if (info->type == PORT_S3C2440)
1695 ucon_mask |= S3C2440_UCON0_DIVMASK;
1696
1697 ucon &= ucon_mask;
1698 wr_regl(port, S3C2410_UCON, ucon | cfg->ucon);
1699
1700 /* reset both fifos */
1701 wr_regl(port, S3C2410_UFCON, cfg->ufcon | S3C2410_UFCON_RESETBOTH);
1702 wr_regl(port, S3C2410_UFCON, cfg->ufcon);
1703
1704 /* some delay is required after fifo reset */
1705 udelay(1);
Ben Dooksb4975492008-07-03 12:32:51 +01001706}
1707
Ben Dooks30555472008-10-21 14:06:36 +01001708
Krzysztof Kozlowskiebaa81c2016-06-27 13:59:08 +02001709#ifdef CONFIG_ARM_S3C24XX_CPUFREQ
Ben Dooks30555472008-10-21 14:06:36 +01001710
1711static int s3c24xx_serial_cpufreq_transition(struct notifier_block *nb,
1712 unsigned long val, void *data)
1713{
1714 struct s3c24xx_uart_port *port;
1715 struct uart_port *uport;
1716
1717 port = container_of(nb, struct s3c24xx_uart_port, freq_transition);
1718 uport = &port->port;
1719
1720 /* check to see if port is enabled */
1721
1722 if (port->pm_level != 0)
1723 return 0;
1724
1725 /* try and work out if the baudrate is changing, we can detect
1726 * a change in rate, but we do not have support for detecting
1727 * a disturbance in the clock-rate over the change.
1728 */
1729
Kyoungil Kim25f04ad2012-05-20 17:49:31 +09001730 if (IS_ERR(port->baudclk))
Ben Dooks30555472008-10-21 14:06:36 +01001731 goto exit;
1732
Kyoungil Kim25f04ad2012-05-20 17:49:31 +09001733 if (port->baudclk_rate == clk_get_rate(port->baudclk))
Ben Dooks30555472008-10-21 14:06:36 +01001734 goto exit;
1735
1736 if (val == CPUFREQ_PRECHANGE) {
1737 /* we should really shut the port down whilst the
Greg Kroah-Hartman7c175252019-12-10 15:37:05 +01001738 * frequency change is in progress.
1739 */
Ben Dooks30555472008-10-21 14:06:36 +01001740
1741 } else if (val == CPUFREQ_POSTCHANGE) {
1742 struct ktermios *termios;
1743 struct tty_struct *tty;
1744
Alan Coxebd2c8f2009-09-19 13:13:28 -07001745 if (uport->state == NULL)
Ben Dooks30555472008-10-21 14:06:36 +01001746 goto exit;
Ben Dooks30555472008-10-21 14:06:36 +01001747
Alan Coxebd2c8f2009-09-19 13:13:28 -07001748 tty = uport->state->port.tty;
Ben Dooks30555472008-10-21 14:06:36 +01001749
Ben Dooks7de40c22008-12-14 23:11:02 +00001750 if (tty == NULL)
Ben Dooks30555472008-10-21 14:06:36 +01001751 goto exit;
Ben Dooks30555472008-10-21 14:06:36 +01001752
Alan Coxadc8d742012-07-14 15:31:47 +01001753 termios = &tty->termios;
Ben Dooks30555472008-10-21 14:06:36 +01001754
1755 if (termios == NULL) {
Sachin Kamatd20925e2012-09-05 10:30:10 +05301756 dev_warn(uport->dev, "%s: no termios?\n", __func__);
Ben Dooks30555472008-10-21 14:06:36 +01001757 goto exit;
1758 }
1759
1760 s3c24xx_serial_set_termios(uport, termios, NULL);
1761 }
1762
Robert Baldygaef4aca72014-11-24 07:56:22 +01001763exit:
Ben Dooks30555472008-10-21 14:06:36 +01001764 return 0;
1765}
1766
Robert Baldygaef4aca72014-11-24 07:56:22 +01001767static inline int
1768s3c24xx_serial_cpufreq_register(struct s3c24xx_uart_port *port)
Ben Dooks30555472008-10-21 14:06:36 +01001769{
1770 port->freq_transition.notifier_call = s3c24xx_serial_cpufreq_transition;
1771
1772 return cpufreq_register_notifier(&port->freq_transition,
1773 CPUFREQ_TRANSITION_NOTIFIER);
1774}
1775
Robert Baldygaef4aca72014-11-24 07:56:22 +01001776static inline void
1777s3c24xx_serial_cpufreq_deregister(struct s3c24xx_uart_port *port)
Ben Dooks30555472008-10-21 14:06:36 +01001778{
1779 cpufreq_unregister_notifier(&port->freq_transition,
1780 CPUFREQ_TRANSITION_NOTIFIER);
1781}
1782
1783#else
Robert Baldygaef4aca72014-11-24 07:56:22 +01001784static inline int
1785s3c24xx_serial_cpufreq_register(struct s3c24xx_uart_port *port)
Ben Dooks30555472008-10-21 14:06:36 +01001786{
1787 return 0;
1788}
1789
Robert Baldygaef4aca72014-11-24 07:56:22 +01001790static inline void
1791s3c24xx_serial_cpufreq_deregister(struct s3c24xx_uart_port *port)
Ben Dooks30555472008-10-21 14:06:36 +01001792{
1793}
1794#endif
1795
Stuart Menefy5086e0a2019-02-12 21:40:22 +00001796static int s3c24xx_serial_enable_baudclk(struct s3c24xx_uart_port *ourport)
1797{
1798 struct device *dev = ourport->port.dev;
1799 struct s3c24xx_uart_info *info = ourport->info;
1800 char clk_name[MAX_CLK_NAME_LENGTH];
1801 unsigned int clk_sel;
1802 struct clk *clk;
1803 int clk_num;
1804 int ret;
1805
1806 clk_sel = ourport->cfg->clk_sel ? : info->def_clk_sel;
1807 for (clk_num = 0; clk_num < info->num_clks; clk_num++) {
1808 if (!(clk_sel & (1 << clk_num)))
1809 continue;
1810
1811 sprintf(clk_name, "clk_uart_baud%d", clk_num);
1812 clk = clk_get(dev, clk_name);
1813 if (IS_ERR(clk))
1814 continue;
1815
1816 ret = clk_prepare_enable(clk);
1817 if (ret) {
1818 clk_put(clk);
1819 continue;
1820 }
1821
1822 ourport->baudclk = clk;
1823 ourport->baudclk_rate = clk_get_rate(clk);
1824 s3c24xx_serial_setsource(&ourport->port, clk_num);
1825
1826 return 0;
1827 }
1828
1829 return -EINVAL;
1830}
1831
Ben Dooksb4975492008-07-03 12:32:51 +01001832/* s3c24xx_serial_init_port
1833 *
1834 * initialise a single serial port from the platform device given
1835 */
1836
1837static int s3c24xx_serial_init_port(struct s3c24xx_uart_port *ourport,
Ben Dooksb4975492008-07-03 12:32:51 +01001838 struct platform_device *platdev)
1839{
1840 struct uart_port *port = &ourport->port;
Thomas Abrahamda121502011-11-02 19:23:25 +09001841 struct s3c2410_uartcfg *cfg = ourport->cfg;
Ben Dooksb4975492008-07-03 12:32:51 +01001842 struct resource *res;
1843 int ret;
1844
Ben Dooksb4975492008-07-03 12:32:51 +01001845 if (platdev == NULL)
1846 return -ENODEV;
1847
Ben Dooksb4975492008-07-03 12:32:51 +01001848 if (port->mapbase != 0)
Krzysztof Kozlowskie51e4d82016-06-16 08:27:35 +02001849 return -EINVAL;
Ben Dooksb4975492008-07-03 12:32:51 +01001850
Ben Dooksb4975492008-07-03 12:32:51 +01001851 /* setup info for port */
1852 port->dev = &platdev->dev;
Ben Dooksb4975492008-07-03 12:32:51 +01001853
Thomas Abraham88bb4ea2011-08-10 15:51:19 +05301854 /* Startup sequence is different for s3c64xx and higher SoC's */
1855 if (s3c24xx_serial_has_interrupt_mask(port))
1856 s3c24xx_serial_ops.startup = s3c64xx_serial_startup;
1857
Ben Dooksb4975492008-07-03 12:32:51 +01001858 port->uartclk = 1;
1859
1860 if (cfg->uart_flags & UPF_CONS_FLOW) {
Greg Kroah-Hartmana05025d2019-12-10 15:37:03 +01001861 dev_dbg(port->dev, "enabling flow control\n");
Ben Dooksb4975492008-07-03 12:32:51 +01001862 port->flags |= UPF_CONS_FLOW;
1863 }
1864
1865 /* sort our the physical and virtual addresses for each UART */
1866
1867 res = platform_get_resource(platdev, IORESOURCE_MEM, 0);
1868 if (res == NULL) {
Sachin Kamatd20925e2012-09-05 10:30:10 +05301869 dev_err(port->dev, "failed to find memory resource for uart\n");
Ben Dooksb4975492008-07-03 12:32:51 +01001870 return -EINVAL;
1871 }
1872
Greg Kroah-Hartmana05025d2019-12-10 15:37:03 +01001873 dev_dbg(port->dev, "resource %pR)\n", res);
Ben Dooksb4975492008-07-03 12:32:51 +01001874
Thomas Abraham41147bf2013-01-01 00:21:55 -08001875 port->membase = devm_ioremap(port->dev, res->start, resource_size(res));
1876 if (!port->membase) {
1877 dev_err(port->dev, "failed to remap controller address\n");
1878 return -EBUSY;
1879 }
1880
Ben Dooksb690ace2008-10-21 14:07:03 +01001881 port->mapbase = res->start;
Ben Dooksb4975492008-07-03 12:32:51 +01001882 ret = platform_get_irq(platdev, 0);
1883 if (ret < 0)
1884 port->irq = 0;
Ben Dooksb73c289c2008-10-21 14:07:04 +01001885 else {
Ben Dooksb4975492008-07-03 12:32:51 +01001886 port->irq = ret;
Ben Dooksb73c289c2008-10-21 14:07:04 +01001887 ourport->rx_irq = ret;
1888 ourport->tx_irq = ret + 1;
1889 }
Sachin Kamat9303ac12012-09-05 10:30:11 +05301890
Ben Dooksb73c289c2008-10-21 14:07:04 +01001891 ret = platform_get_irq(platdev, 1);
1892 if (ret > 0)
1893 ourport->tx_irq = ret;
Robert Baldyga658c9d2b72014-12-10 12:49:23 +01001894 /*
1895 * DMA is currently supported only on DT platforms, if DMA properties
1896 * are specified.
1897 */
1898 if (platdev->dev.of_node && of_find_property(platdev->dev.of_node,
1899 "dmas", NULL)) {
1900 ourport->dma = devm_kzalloc(port->dev,
1901 sizeof(*ourport->dma),
1902 GFP_KERNEL);
Krzysztof Kozlowskie51e4d82016-06-16 08:27:35 +02001903 if (!ourport->dma) {
1904 ret = -ENOMEM;
1905 goto err;
1906 }
Robert Baldyga658c9d2b72014-12-10 12:49:23 +01001907 }
Ben Dooksb4975492008-07-03 12:32:51 +01001908
1909 ourport->clk = clk_get(&platdev->dev, "uart");
Chander Kashyap60e93572013-05-28 18:32:07 +05301910 if (IS_ERR(ourport->clk)) {
1911 pr_err("%s: Controller clock not found\n",
1912 dev_name(&platdev->dev));
Krzysztof Kozlowskie51e4d82016-06-16 08:27:35 +02001913 ret = PTR_ERR(ourport->clk);
1914 goto err;
Chander Kashyap60e93572013-05-28 18:32:07 +05301915 }
1916
1917 ret = clk_prepare_enable(ourport->clk);
1918 if (ret) {
1919 pr_err("uart: clock failed to prepare+enable: %d\n", ret);
1920 clk_put(ourport->clk);
Krzysztof Kozlowskie51e4d82016-06-16 08:27:35 +02001921 goto err;
Chander Kashyap60e93572013-05-28 18:32:07 +05301922 }
Ben Dooksb4975492008-07-03 12:32:51 +01001923
Stuart Menefy5086e0a2019-02-12 21:40:22 +00001924 ret = s3c24xx_serial_enable_baudclk(ourport);
1925 if (ret)
1926 pr_warn("uart: failed to enable baudclk\n");
1927
Thomas Abraham88bb4ea2011-08-10 15:51:19 +05301928 /* Keep all interrupts masked and cleared */
1929 if (s3c24xx_serial_has_interrupt_mask(port)) {
1930 wr_regl(port, S3C64XX_UINTM, 0xf);
1931 wr_regl(port, S3C64XX_UINTP, 0xf);
1932 wr_regl(port, S3C64XX_UINTSP, 0xf);
1933 }
1934
Greg Kroah-Hartmana05025d2019-12-10 15:37:03 +01001935 dev_dbg(port->dev, "port: map=%pa, mem=%p, irq=%d (%d,%d), clock=%u\n",
1936 &port->mapbase, port->membase, port->irq,
1937 ourport->rx_irq, ourport->tx_irq, port->uartclk);
Ben Dooksb4975492008-07-03 12:32:51 +01001938
1939 /* reset the fifos (and setup the uart) */
1940 s3c24xx_serial_resetport(port, cfg);
Krzysztof Kozlowskie51e4d82016-06-16 08:27:35 +02001941
Ben Dooksb4975492008-07-03 12:32:51 +01001942 return 0;
Krzysztof Kozlowskie51e4d82016-06-16 08:27:35 +02001943
1944err:
1945 port->mapbase = 0;
1946 return ret;
Ben Dooksb4975492008-07-03 12:32:51 +01001947}
1948
Ben Dooksb4975492008-07-03 12:32:51 +01001949/* Device driver serial port probe */
1950
Greg Kroah-Hartman06674e52019-12-10 15:36:58 +01001951#ifdef CONFIG_OF
Thomas Abraham26c919e2011-11-06 22:10:44 +05301952static const struct of_device_id s3c24xx_uart_dt_match[];
Greg Kroah-Hartman06674e52019-12-10 15:36:58 +01001953#endif
1954
Ben Dooksb4975492008-07-03 12:32:51 +01001955static int probe_index;
1956
Thomas Abraham26c919e2011-11-06 22:10:44 +05301957static inline struct s3c24xx_serial_drv_data *s3c24xx_get_driver_data(
1958 struct platform_device *pdev)
1959{
1960#ifdef CONFIG_OF
1961 if (pdev->dev.of_node) {
1962 const struct of_device_id *match;
Greg Kroah-Hartman9fe0d412019-12-10 15:37:06 +01001963
Thomas Abraham26c919e2011-11-06 22:10:44 +05301964 match = of_match_node(s3c24xx_uart_dt_match, pdev->dev.of_node);
1965 return (struct s3c24xx_serial_drv_data *)match->data;
1966 }
1967#endif
1968 return (struct s3c24xx_serial_drv_data *)
1969 platform_get_device_id(pdev)->driver_data;
1970}
1971
Thomas Abrahamda121502011-11-02 19:23:25 +09001972static int s3c24xx_serial_probe(struct platform_device *pdev)
Ben Dooksb4975492008-07-03 12:32:51 +01001973{
Naveen Krishna Chatradhi4622eb62014-07-14 17:07:18 +05301974 struct device_node *np = pdev->dev.of_node;
Ben Dooksb4975492008-07-03 12:32:51 +01001975 struct s3c24xx_uart_port *ourport;
Tomasz Figa13a9f6c62014-06-26 13:24:34 +02001976 int index = probe_index;
Ben Dooksb4975492008-07-03 12:32:51 +01001977 int ret;
1978
Naveen Krishna Chatradhi4622eb62014-07-14 17:07:18 +05301979 if (np) {
1980 ret = of_alias_get_id(np, "serial");
Tomasz Figa13a9f6c62014-06-26 13:24:34 +02001981 if (ret >= 0)
1982 index = ret;
1983 }
Ben Dooksb4975492008-07-03 12:32:51 +01001984
Geert Uytterhoeven49ee23b2018-02-23 14:38:34 +01001985 if (index >= ARRAY_SIZE(s3c24xx_serial_ports)) {
1986 dev_err(&pdev->dev, "serial%d out of range\n", index);
1987 return -EINVAL;
1988 }
Tomasz Figa13a9f6c62014-06-26 13:24:34 +02001989 ourport = &s3c24xx_serial_ports[index];
Thomas Abrahamda121502011-11-02 19:23:25 +09001990
Thomas Abraham26c919e2011-11-06 22:10:44 +05301991 ourport->drv_data = s3c24xx_get_driver_data(pdev);
1992 if (!ourport->drv_data) {
1993 dev_err(&pdev->dev, "could not find driver data\n");
1994 return -ENODEV;
1995 }
Thomas Abrahamda121502011-11-02 19:23:25 +09001996
Kyoungil Kim7cd88832012-05-20 17:45:54 +09001997 ourport->baudclk = ERR_PTR(-EINVAL);
Thomas Abrahamda121502011-11-02 19:23:25 +09001998 ourport->info = ourport->drv_data->info;
Jingoo Han574de552013-07-30 17:06:57 +09001999 ourport->cfg = (dev_get_platdata(&pdev->dev)) ?
Jingoo Hand4aab202013-09-09 14:10:30 +09002000 dev_get_platdata(&pdev->dev) :
Thomas Abrahamda121502011-11-02 19:23:25 +09002001 ourport->drv_data->def_cfg;
2002
Naveen Krishna Chatradhi4622eb62014-07-14 17:07:18 +05302003 if (np)
2004 of_property_read_u32(np,
Naveen Krishna Chatradhi135f07c2014-07-14 17:07:16 +05302005 "samsung,uart-fifosize", &ourport->port.fifosize);
2006
Robert Baldyga2f1ba722014-11-24 07:56:23 +01002007 if (ourport->drv_data->fifosize[index])
2008 ourport->port.fifosize = ourport->drv_data->fifosize[index];
2009 else if (ourport->info->fifosize)
2010 ourport->port.fifosize = ourport->info->fifosize;
Dmitry Safonov831cb962019-12-13 00:06:36 +00002011 ourport->port.has_sysrq = IS_ENABLED(CONFIG_SERIAL_SAMSUNG_CONSOLE);
Thomas Abrahamda121502011-11-02 19:23:25 +09002012
Marek Szyprowski81ccb2a2015-07-31 10:58:27 +02002013 /*
2014 * DMA transfers must be aligned at least to cache line size,
2015 * so find minimal transfer size suitable for DMA mode
2016 */
2017 ourport->min_dma_size = max_t(int, ourport->port.fifosize,
2018 dma_get_cache_alignment());
2019
Greg Kroah-Hartmana05025d2019-12-10 15:37:03 +01002020 dev_dbg(&pdev->dev, "%s: initialising port %p...\n", __func__, ourport);
Ben Dooksb4975492008-07-03 12:32:51 +01002021
Thomas Abrahamda121502011-11-02 19:23:25 +09002022 ret = s3c24xx_serial_init_port(ourport, pdev);
Ben Dooksb4975492008-07-03 12:32:51 +01002023 if (ret < 0)
Tushar Behera8ad711a2014-06-23 11:32:14 +05302024 return ret;
Ben Dooksb4975492008-07-03 12:32:51 +01002025
Tushar Behera6f134c3c2014-01-20 14:32:34 +05302026 if (!s3c24xx_uart_drv.state) {
2027 ret = uart_register_driver(&s3c24xx_uart_drv);
2028 if (ret < 0) {
2029 pr_err("Failed to register Samsung UART driver\n");
2030 return ret;
2031 }
2032 }
2033
Greg Kroah-Hartmana05025d2019-12-10 15:37:03 +01002034 dev_dbg(&pdev->dev, "%s: adding port\n", __func__);
Ben Dooksb4975492008-07-03 12:32:51 +01002035 uart_add_one_port(&s3c24xx_uart_drv, &ourport->port);
Thomas Abrahamda121502011-11-02 19:23:25 +09002036 platform_set_drvdata(pdev, &ourport->port);
Ben Dooksb4975492008-07-03 12:32:51 +01002037
Heiko Stübner0da33362013-12-05 00:54:38 +01002038 /*
2039 * Deactivate the clock enabled in s3c24xx_serial_init_port here,
2040 * so that a potential re-enablement through the pm-callback overlaps
2041 * and keeps the clock enabled in this case.
2042 */
2043 clk_disable_unprepare(ourport->clk);
Stuart Menefy5086e0a2019-02-12 21:40:22 +00002044 if (!IS_ERR(ourport->baudclk))
2045 clk_disable_unprepare(ourport->baudclk);
Heiko Stübner0da33362013-12-05 00:54:38 +01002046
Ben Dooks30555472008-10-21 14:06:36 +01002047 ret = s3c24xx_serial_cpufreq_register(ourport);
2048 if (ret < 0)
Thomas Abrahamda121502011-11-02 19:23:25 +09002049 dev_err(&pdev->dev, "failed to add cpufreq notifier\n");
Ben Dooks30555472008-10-21 14:06:36 +01002050
Krzysztof Kozlowski926b7b52016-06-16 08:27:36 +02002051 probe_index++;
2052
Ben Dooksb4975492008-07-03 12:32:51 +01002053 return 0;
Ben Dooksb4975492008-07-03 12:32:51 +01002054}
2055
Bill Pembertonae8d8a12012-11-19 13:26:18 -05002056static int s3c24xx_serial_remove(struct platform_device *dev)
Ben Dooksb4975492008-07-03 12:32:51 +01002057{
2058 struct uart_port *port = s3c24xx_dev_to_port(&dev->dev);
2059
2060 if (port) {
Ben Dooks30555472008-10-21 14:06:36 +01002061 s3c24xx_serial_cpufreq_deregister(to_ourport(port));
Ben Dooksb4975492008-07-03 12:32:51 +01002062 uart_remove_one_port(&s3c24xx_uart_drv, port);
2063 }
2064
Tushar Behera6f134c3c2014-01-20 14:32:34 +05302065 uart_unregister_driver(&s3c24xx_uart_drv);
2066
Ben Dooksb4975492008-07-03 12:32:51 +01002067 return 0;
2068}
2069
Ben Dooksb4975492008-07-03 12:32:51 +01002070/* UART power management code */
MyungJoo Hamaef7fe52011-06-29 15:28:24 +09002071#ifdef CONFIG_PM_SLEEP
2072static int s3c24xx_serial_suspend(struct device *dev)
Ben Dooksb4975492008-07-03 12:32:51 +01002073{
MyungJoo Hamaef7fe52011-06-29 15:28:24 +09002074 struct uart_port *port = s3c24xx_dev_to_port(dev);
Ben Dooksb4975492008-07-03 12:32:51 +01002075
2076 if (port)
2077 uart_suspend_port(&s3c24xx_uart_drv, port);
2078
2079 return 0;
2080}
2081
MyungJoo Hamaef7fe52011-06-29 15:28:24 +09002082static int s3c24xx_serial_resume(struct device *dev)
Ben Dooksb4975492008-07-03 12:32:51 +01002083{
MyungJoo Hamaef7fe52011-06-29 15:28:24 +09002084 struct uart_port *port = s3c24xx_dev_to_port(dev);
Ben Dooksb4975492008-07-03 12:32:51 +01002085 struct s3c24xx_uart_port *ourport = to_ourport(port);
2086
2087 if (port) {
Thomas Abraham9484b002012-10-03 07:40:04 +09002088 clk_prepare_enable(ourport->clk);
Marek Szyprowski1ff36522018-09-13 10:21:25 +02002089 if (!IS_ERR(ourport->baudclk))
2090 clk_prepare_enable(ourport->baudclk);
Ben Dooksb4975492008-07-03 12:32:51 +01002091 s3c24xx_serial_resetport(port, s3c24xx_port_to_cfg(port));
Marek Szyprowski1ff36522018-09-13 10:21:25 +02002092 if (!IS_ERR(ourport->baudclk))
2093 clk_disable_unprepare(ourport->baudclk);
Thomas Abraham9484b002012-10-03 07:40:04 +09002094 clk_disable_unprepare(ourport->clk);
Ben Dooksb4975492008-07-03 12:32:51 +01002095
2096 uart_resume_port(&s3c24xx_uart_drv, port);
2097 }
2098
2099 return 0;
2100}
MyungJoo Hamaef7fe52011-06-29 15:28:24 +09002101
Michael Spangd09a7302013-03-27 19:34:24 -04002102static int s3c24xx_serial_resume_noirq(struct device *dev)
2103{
2104 struct uart_port *port = s3c24xx_dev_to_port(dev);
남영민a8a17812017-02-01 19:25:46 +09002105 struct s3c24xx_uart_port *ourport = to_ourport(port);
Michael Spangd09a7302013-03-27 19:34:24 -04002106
2107 if (port) {
2108 /* restore IRQ mask */
2109 if (s3c24xx_serial_has_interrupt_mask(port)) {
2110 unsigned int uintm = 0xf;
Greg Kroah-Hartman9fe0d412019-12-10 15:37:06 +01002111
Greg Kroah-Hartman83362402019-12-17 15:02:32 +01002112 if (ourport->tx_enabled)
Michael Spangd09a7302013-03-27 19:34:24 -04002113 uintm &= ~S3C64XX_UINTM_TXD_MSK;
Greg Kroah-Hartman83362402019-12-17 15:02:32 +01002114 if (ourport->rx_enabled)
Michael Spangd09a7302013-03-27 19:34:24 -04002115 uintm &= ~S3C64XX_UINTM_RXD_MSK;
남영민a8a17812017-02-01 19:25:46 +09002116 clk_prepare_enable(ourport->clk);
Marek Szyprowski1ff36522018-09-13 10:21:25 +02002117 if (!IS_ERR(ourport->baudclk))
2118 clk_prepare_enable(ourport->baudclk);
Michael Spangd09a7302013-03-27 19:34:24 -04002119 wr_regl(port, S3C64XX_UINTM, uintm);
Marek Szyprowski1ff36522018-09-13 10:21:25 +02002120 if (!IS_ERR(ourport->baudclk))
2121 clk_disable_unprepare(ourport->baudclk);
남영민a8a17812017-02-01 19:25:46 +09002122 clk_disable_unprepare(ourport->clk);
Michael Spangd09a7302013-03-27 19:34:24 -04002123 }
2124 }
2125
2126 return 0;
2127}
2128
MyungJoo Hamaef7fe52011-06-29 15:28:24 +09002129static const struct dev_pm_ops s3c24xx_serial_pm_ops = {
2130 .suspend = s3c24xx_serial_suspend,
2131 .resume = s3c24xx_serial_resume,
Michael Spangd09a7302013-03-27 19:34:24 -04002132 .resume_noirq = s3c24xx_serial_resume_noirq,
MyungJoo Hamaef7fe52011-06-29 15:28:24 +09002133};
Kukjin Kimb882fc12011-07-28 08:50:38 +09002134#define SERIAL_SAMSUNG_PM_OPS (&s3c24xx_serial_pm_ops)
2135
MyungJoo Hamaef7fe52011-06-29 15:28:24 +09002136#else /* !CONFIG_PM_SLEEP */
Kukjin Kimb882fc12011-07-28 08:50:38 +09002137
2138#define SERIAL_SAMSUNG_PM_OPS NULL
MyungJoo Hamaef7fe52011-06-29 15:28:24 +09002139#endif /* CONFIG_PM_SLEEP */
Ben Dooksb4975492008-07-03 12:32:51 +01002140
Ben Dooksb4975492008-07-03 12:32:51 +01002141/* Console code */
2142
2143#ifdef CONFIG_SERIAL_SAMSUNG_CONSOLE
2144
2145static struct uart_port *cons_uart;
2146
2147static int
2148s3c24xx_serial_console_txrdy(struct uart_port *port, unsigned int ufcon)
2149{
2150 struct s3c24xx_uart_info *info = s3c24xx_port_to_info(port);
2151 unsigned long ufstat, utrstat;
2152
2153 if (ufcon & S3C2410_UFCON_FIFOMODE) {
Uwe Kleine-König9ddc5b62010-01-20 17:02:24 +01002154 /* fifo mode - check amount of data in fifo registers... */
Ben Dooksb4975492008-07-03 12:32:51 +01002155
2156 ufstat = rd_regl(port, S3C2410_UFSTAT);
2157 return (ufstat & info->tx_fifofull) ? 0 : 1;
2158 }
2159
2160 /* in non-fifo mode, we go and use the tx buffer empty */
2161
2162 utrstat = rd_regl(port, S3C2410_UTRSTAT);
2163 return (utrstat & S3C2410_UTRSTAT_TXE) ? 1 : 0;
2164}
2165
Michael Spang38adbc52013-03-27 19:34:25 -04002166static bool
2167s3c24xx_port_configured(unsigned int ucon)
2168{
2169 /* consider the serial port configured if the tx/rx mode set */
2170 return (ucon & 0xf) != 0;
2171}
2172
Julien Pichon93b5c032012-09-21 23:22:31 -07002173#ifdef CONFIG_CONSOLE_POLL
2174/*
2175 * Console polling routines for writing and reading from the uart while
2176 * in an interrupt or debug context.
2177 */
2178
2179static int s3c24xx_serial_get_poll_char(struct uart_port *port)
2180{
2181 struct s3c24xx_uart_port *ourport = to_ourport(port);
2182 unsigned int ufstat;
2183
2184 ufstat = rd_regl(port, S3C2410_UFSTAT);
2185 if (s3c24xx_serial_rx_fifocnt(ourport, ufstat) == 0)
2186 return NO_POLL_CHAR;
2187
2188 return rd_regb(port, S3C2410_URXH);
2189}
2190
2191static void s3c24xx_serial_put_poll_char(struct uart_port *port,
2192 unsigned char c)
2193{
Doug Andersonbb7f09b2014-04-21 09:40:34 -07002194 unsigned int ufcon = rd_regl(port, S3C2410_UFCON);
2195 unsigned int ucon = rd_regl(port, S3C2410_UCON);
Michael Spang38adbc52013-03-27 19:34:25 -04002196
2197 /* not possible to xmit on unconfigured port */
2198 if (!s3c24xx_port_configured(ucon))
2199 return;
Julien Pichon93b5c032012-09-21 23:22:31 -07002200
2201 while (!s3c24xx_serial_console_txrdy(port, ufcon))
2202 cpu_relax();
Doug Andersonbb7f09b2014-04-21 09:40:34 -07002203 wr_regb(port, S3C2410_UTXH, c);
Julien Pichon93b5c032012-09-21 23:22:31 -07002204}
2205
2206#endif /* CONFIG_CONSOLE_POLL */
2207
Ben Dooksb4975492008-07-03 12:32:51 +01002208static void
2209s3c24xx_serial_console_putchar(struct uart_port *port, int ch)
2210{
Doug Andersonbb7f09b2014-04-21 09:40:34 -07002211 unsigned int ufcon = rd_regl(port, S3C2410_UFCON);
Michael Spang38adbc52013-03-27 19:34:25 -04002212
Ben Dooksb4975492008-07-03 12:32:51 +01002213 while (!s3c24xx_serial_console_txrdy(port, ufcon))
Doug Andersonf94b0572014-04-21 09:40:36 -07002214 cpu_relax();
Doug Andersonbb7f09b2014-04-21 09:40:34 -07002215 wr_regb(port, S3C2410_UTXH, ch);
Ben Dooksb4975492008-07-03 12:32:51 +01002216}
2217
2218static void
2219s3c24xx_serial_console_write(struct console *co, const char *s,
2220 unsigned int count)
2221{
Doug Andersonab88c8d2014-04-21 09:40:35 -07002222 unsigned int ucon = rd_regl(cons_uart, S3C2410_UCON);
2223
2224 /* not possible to xmit on unconfigured port */
2225 if (!s3c24xx_port_configured(ucon))
2226 return;
2227
Ben Dooksb4975492008-07-03 12:32:51 +01002228 uart_console_write(cons_uart, s, count, s3c24xx_serial_console_putchar);
2229}
2230
2231static void __init
2232s3c24xx_serial_get_options(struct uart_port *port, int *baud,
2233 int *parity, int *bits)
2234{
Ben Dooksb4975492008-07-03 12:32:51 +01002235 struct clk *clk;
2236 unsigned int ulcon;
2237 unsigned int ucon;
2238 unsigned int ubrdiv;
2239 unsigned long rate;
Thomas Abraham5f5a7a52011-10-24 11:47:46 +02002240 unsigned int clk_sel;
2241 char clk_name[MAX_CLK_NAME_LENGTH];
Ben Dooksb4975492008-07-03 12:32:51 +01002242
2243 ulcon = rd_regl(port, S3C2410_ULCON);
2244 ucon = rd_regl(port, S3C2410_UCON);
2245 ubrdiv = rd_regl(port, S3C2410_UBRDIV);
2246
Michael Spang38adbc52013-03-27 19:34:25 -04002247 if (s3c24xx_port_configured(ucon)) {
Ben Dooksb4975492008-07-03 12:32:51 +01002248 switch (ulcon & S3C2410_LCON_CSMASK) {
2249 case S3C2410_LCON_CS5:
2250 *bits = 5;
2251 break;
2252 case S3C2410_LCON_CS6:
2253 *bits = 6;
2254 break;
2255 case S3C2410_LCON_CS7:
2256 *bits = 7;
2257 break;
Ben Dooksb4975492008-07-03 12:32:51 +01002258 case S3C2410_LCON_CS8:
Naveen Krishna Chatradhi3bcce592014-07-14 17:07:17 +05302259 default:
Ben Dooksb4975492008-07-03 12:32:51 +01002260 *bits = 8;
2261 break;
2262 }
2263
2264 switch (ulcon & S3C2410_LCON_PMASK) {
2265 case S3C2410_LCON_PEVEN:
2266 *parity = 'e';
2267 break;
2268
2269 case S3C2410_LCON_PODD:
2270 *parity = 'o';
2271 break;
2272
2273 case S3C2410_LCON_PNONE:
2274 default:
2275 *parity = 'n';
2276 }
2277
2278 /* now calculate the baud rate */
2279
Thomas Abraham5f5a7a52011-10-24 11:47:46 +02002280 clk_sel = s3c24xx_serial_getsource(port);
2281 sprintf(clk_name, "clk_uart_baud%d", clk_sel);
Ben Dooksb4975492008-07-03 12:32:51 +01002282
Thomas Abraham5f5a7a52011-10-24 11:47:46 +02002283 clk = clk_get(port->dev, clk_name);
Kyoungil Kim7cd88832012-05-20 17:45:54 +09002284 if (!IS_ERR(clk))
Thomas Abraham5f5a7a52011-10-24 11:47:46 +02002285 rate = clk_get_rate(clk);
Ben Dooksb4975492008-07-03 12:32:51 +01002286 else
2287 rate = 1;
2288
Ben Dooksb4975492008-07-03 12:32:51 +01002289 *baud = rate / (16 * (ubrdiv + 1));
Greg Kroah-Hartmana05025d2019-12-10 15:37:03 +01002290 dev_dbg(port->dev, "calculated baud %d\n", *baud);
Ben Dooksb4975492008-07-03 12:32:51 +01002291 }
2292
2293}
2294
Ben Dooksb4975492008-07-03 12:32:51 +01002295static int __init
2296s3c24xx_serial_console_setup(struct console *co, char *options)
2297{
2298 struct uart_port *port;
2299 int baud = 9600;
2300 int bits = 8;
2301 int parity = 'n';
2302 int flow = 'n';
2303
Ben Dooksb4975492008-07-03 12:32:51 +01002304 /* is this a valid port */
2305
Ben Dooks03d5e772008-11-03 09:21:23 +00002306 if (co->index == -1 || co->index >= CONFIG_SERIAL_SAMSUNG_UARTS)
Ben Dooksb4975492008-07-03 12:32:51 +01002307 co->index = 0;
2308
2309 port = &s3c24xx_serial_ports[co->index].port;
2310
2311 /* is the port configured? */
2312
Thomas Abrahamee430f12011-06-14 19:12:26 +09002313 if (port->mapbase == 0x0)
2314 return -ENODEV;
Ben Dooksb4975492008-07-03 12:32:51 +01002315
2316 cons_uart = port;
2317
Ben Dooksb4975492008-07-03 12:32:51 +01002318 /*
2319 * Check whether an invalid uart number has been specified, and
2320 * if so, search for the first available port that does have
2321 * console support.
2322 */
2323 if (options)
2324 uart_parse_options(options, &baud, &parity, &bits, &flow);
2325 else
2326 s3c24xx_serial_get_options(port, &baud, &parity, &bits);
2327
Greg Kroah-Hartmana05025d2019-12-10 15:37:03 +01002328 dev_dbg(port->dev, "baud %d\n", baud);
Ben Dooksb4975492008-07-03 12:32:51 +01002329
2330 return uart_set_options(port, co, baud, parity, bits, flow);
2331}
2332
Ben Dooksb4975492008-07-03 12:32:51 +01002333static struct console s3c24xx_serial_console = {
2334 .name = S3C24XX_SERIAL_NAME,
2335 .device = uart_console_device,
2336 .flags = CON_PRINTBUFFER,
2337 .index = -1,
2338 .write = s3c24xx_serial_console_write,
Thomas Abraham5822a5d2011-06-14 19:12:26 +09002339 .setup = s3c24xx_serial_console_setup,
2340 .data = &s3c24xx_uart_drv,
Ben Dooksb4975492008-07-03 12:32:51 +01002341};
Ben Dooksb4975492008-07-03 12:32:51 +01002342#endif /* CONFIG_SERIAL_SAMSUNG_CONSOLE */
2343
Thomas Abrahamda121502011-11-02 19:23:25 +09002344#ifdef CONFIG_CPU_S3C2410
2345static struct s3c24xx_serial_drv_data s3c2410_serial_drv_data = {
2346 .info = &(struct s3c24xx_uart_info) {
2347 .name = "Samsung S3C2410 UART",
2348 .type = PORT_S3C2410,
2349 .fifosize = 16,
2350 .rx_fifomask = S3C2410_UFSTAT_RXMASK,
2351 .rx_fifoshift = S3C2410_UFSTAT_RXSHIFT,
2352 .rx_fifofull = S3C2410_UFSTAT_RXFULL,
2353 .tx_fifofull = S3C2410_UFSTAT_TXFULL,
2354 .tx_fifomask = S3C2410_UFSTAT_TXMASK,
2355 .tx_fifoshift = S3C2410_UFSTAT_TXSHIFT,
2356 .def_clk_sel = S3C2410_UCON_CLKSEL0,
2357 .num_clks = 2,
2358 .clksel_mask = S3C2410_UCON_CLKMASK,
2359 .clksel_shift = S3C2410_UCON_CLKSHIFT,
2360 },
2361 .def_cfg = &(struct s3c2410_uartcfg) {
2362 .ucon = S3C2410_UCON_DEFAULT,
2363 .ufcon = S3C2410_UFCON_DEFAULT,
2364 },
2365};
2366#define S3C2410_SERIAL_DRV_DATA ((kernel_ulong_t)&s3c2410_serial_drv_data)
2367#else
2368#define S3C2410_SERIAL_DRV_DATA (kernel_ulong_t)NULL
2369#endif
2370
2371#ifdef CONFIG_CPU_S3C2412
2372static struct s3c24xx_serial_drv_data s3c2412_serial_drv_data = {
2373 .info = &(struct s3c24xx_uart_info) {
2374 .name = "Samsung S3C2412 UART",
2375 .type = PORT_S3C2412,
2376 .fifosize = 64,
2377 .has_divslot = 1,
2378 .rx_fifomask = S3C2440_UFSTAT_RXMASK,
2379 .rx_fifoshift = S3C2440_UFSTAT_RXSHIFT,
2380 .rx_fifofull = S3C2440_UFSTAT_RXFULL,
2381 .tx_fifofull = S3C2440_UFSTAT_TXFULL,
2382 .tx_fifomask = S3C2440_UFSTAT_TXMASK,
2383 .tx_fifoshift = S3C2440_UFSTAT_TXSHIFT,
2384 .def_clk_sel = S3C2410_UCON_CLKSEL2,
2385 .num_clks = 4,
2386 .clksel_mask = S3C2412_UCON_CLKMASK,
2387 .clksel_shift = S3C2412_UCON_CLKSHIFT,
2388 },
2389 .def_cfg = &(struct s3c2410_uartcfg) {
2390 .ucon = S3C2410_UCON_DEFAULT,
2391 .ufcon = S3C2410_UFCON_DEFAULT,
2392 },
2393};
2394#define S3C2412_SERIAL_DRV_DATA ((kernel_ulong_t)&s3c2412_serial_drv_data)
2395#else
2396#define S3C2412_SERIAL_DRV_DATA (kernel_ulong_t)NULL
2397#endif
2398
2399#if defined(CONFIG_CPU_S3C2440) || defined(CONFIG_CPU_S3C2416) || \
Denis 'GNUtoo' Cariklib26469a2012-02-23 08:23:52 +01002400 defined(CONFIG_CPU_S3C2443) || defined(CONFIG_CPU_S3C2442)
Thomas Abrahamda121502011-11-02 19:23:25 +09002401static struct s3c24xx_serial_drv_data s3c2440_serial_drv_data = {
2402 .info = &(struct s3c24xx_uart_info) {
2403 .name = "Samsung S3C2440 UART",
2404 .type = PORT_S3C2440,
2405 .fifosize = 64,
2406 .has_divslot = 1,
2407 .rx_fifomask = S3C2440_UFSTAT_RXMASK,
2408 .rx_fifoshift = S3C2440_UFSTAT_RXSHIFT,
2409 .rx_fifofull = S3C2440_UFSTAT_RXFULL,
2410 .tx_fifofull = S3C2440_UFSTAT_TXFULL,
2411 .tx_fifomask = S3C2440_UFSTAT_TXMASK,
2412 .tx_fifoshift = S3C2440_UFSTAT_TXSHIFT,
2413 .def_clk_sel = S3C2410_UCON_CLKSEL2,
2414 .num_clks = 4,
2415 .clksel_mask = S3C2412_UCON_CLKMASK,
2416 .clksel_shift = S3C2412_UCON_CLKSHIFT,
2417 },
2418 .def_cfg = &(struct s3c2410_uartcfg) {
2419 .ucon = S3C2410_UCON_DEFAULT,
2420 .ufcon = S3C2410_UFCON_DEFAULT,
2421 },
2422};
2423#define S3C2440_SERIAL_DRV_DATA ((kernel_ulong_t)&s3c2440_serial_drv_data)
2424#else
2425#define S3C2440_SERIAL_DRV_DATA (kernel_ulong_t)NULL
2426#endif
2427
Kukjin Kim953b53a2014-07-01 06:32:22 +09002428#if defined(CONFIG_CPU_S3C6400) || defined(CONFIG_CPU_S3C6410)
Thomas Abrahamda121502011-11-02 19:23:25 +09002429static struct s3c24xx_serial_drv_data s3c6400_serial_drv_data = {
2430 .info = &(struct s3c24xx_uart_info) {
2431 .name = "Samsung S3C6400 UART",
2432 .type = PORT_S3C6400,
2433 .fifosize = 64,
2434 .has_divslot = 1,
2435 .rx_fifomask = S3C2440_UFSTAT_RXMASK,
2436 .rx_fifoshift = S3C2440_UFSTAT_RXSHIFT,
2437 .rx_fifofull = S3C2440_UFSTAT_RXFULL,
2438 .tx_fifofull = S3C2440_UFSTAT_TXFULL,
2439 .tx_fifomask = S3C2440_UFSTAT_TXMASK,
2440 .tx_fifoshift = S3C2440_UFSTAT_TXSHIFT,
2441 .def_clk_sel = S3C2410_UCON_CLKSEL2,
2442 .num_clks = 4,
2443 .clksel_mask = S3C6400_UCON_CLKMASK,
2444 .clksel_shift = S3C6400_UCON_CLKSHIFT,
2445 },
2446 .def_cfg = &(struct s3c2410_uartcfg) {
2447 .ucon = S3C2410_UCON_DEFAULT,
2448 .ufcon = S3C2410_UFCON_DEFAULT,
2449 },
2450};
2451#define S3C6400_SERIAL_DRV_DATA ((kernel_ulong_t)&s3c6400_serial_drv_data)
2452#else
2453#define S3C6400_SERIAL_DRV_DATA (kernel_ulong_t)NULL
2454#endif
2455
2456#ifdef CONFIG_CPU_S5PV210
2457static struct s3c24xx_serial_drv_data s5pv210_serial_drv_data = {
2458 .info = &(struct s3c24xx_uart_info) {
2459 .name = "Samsung S5PV210 UART",
2460 .type = PORT_S3C6400,
2461 .has_divslot = 1,
2462 .rx_fifomask = S5PV210_UFSTAT_RXMASK,
2463 .rx_fifoshift = S5PV210_UFSTAT_RXSHIFT,
2464 .rx_fifofull = S5PV210_UFSTAT_RXFULL,
2465 .tx_fifofull = S5PV210_UFSTAT_TXFULL,
2466 .tx_fifomask = S5PV210_UFSTAT_TXMASK,
2467 .tx_fifoshift = S5PV210_UFSTAT_TXSHIFT,
2468 .def_clk_sel = S3C2410_UCON_CLKSEL0,
2469 .num_clks = 2,
2470 .clksel_mask = S5PV210_UCON_CLKMASK,
2471 .clksel_shift = S5PV210_UCON_CLKSHIFT,
2472 },
2473 .def_cfg = &(struct s3c2410_uartcfg) {
2474 .ucon = S5PV210_UCON_DEFAULT,
2475 .ufcon = S5PV210_UFCON_DEFAULT,
2476 },
2477 .fifosize = { 256, 64, 16, 16 },
2478};
2479#define S5PV210_SERIAL_DRV_DATA ((kernel_ulong_t)&s5pv210_serial_drv_data)
2480#else
2481#define S5PV210_SERIAL_DRV_DATA (kernel_ulong_t)NULL
2482#endif
2483
Chander Kashyap33f88132013-06-19 00:29:34 +09002484#if defined(CONFIG_ARCH_EXYNOS)
Chanwoo Choi31ec77a2014-12-02 17:49:54 +09002485#define EXYNOS_COMMON_SERIAL_DRV_DATA \
2486 .info = &(struct s3c24xx_uart_info) { \
2487 .name = "Samsung Exynos UART", \
2488 .type = PORT_S3C6400, \
2489 .has_divslot = 1, \
2490 .rx_fifomask = S5PV210_UFSTAT_RXMASK, \
2491 .rx_fifoshift = S5PV210_UFSTAT_RXSHIFT, \
2492 .rx_fifofull = S5PV210_UFSTAT_RXFULL, \
2493 .tx_fifofull = S5PV210_UFSTAT_TXFULL, \
2494 .tx_fifomask = S5PV210_UFSTAT_TXMASK, \
2495 .tx_fifoshift = S5PV210_UFSTAT_TXSHIFT, \
2496 .def_clk_sel = S3C2410_UCON_CLKSEL0, \
2497 .num_clks = 1, \
2498 .clksel_mask = 0, \
2499 .clksel_shift = 0, \
2500 }, \
2501 .def_cfg = &(struct s3c2410_uartcfg) { \
2502 .ucon = S5PV210_UCON_DEFAULT, \
2503 .ufcon = S5PV210_UFCON_DEFAULT, \
2504 .has_fracval = 1, \
2505 } \
2506
Thomas Abrahamda121502011-11-02 19:23:25 +09002507static struct s3c24xx_serial_drv_data exynos4210_serial_drv_data = {
Chanwoo Choi31ec77a2014-12-02 17:49:54 +09002508 EXYNOS_COMMON_SERIAL_DRV_DATA,
Thomas Abrahamda121502011-11-02 19:23:25 +09002509 .fifosize = { 256, 64, 16, 16 },
2510};
Chanwoo Choi31ec77a2014-12-02 17:49:54 +09002511
2512static struct s3c24xx_serial_drv_data exynos5433_serial_drv_data = {
2513 EXYNOS_COMMON_SERIAL_DRV_DATA,
2514 .fifosize = { 64, 256, 16, 256 },
2515};
2516
Thomas Abrahamda121502011-11-02 19:23:25 +09002517#define EXYNOS4210_SERIAL_DRV_DATA ((kernel_ulong_t)&exynos4210_serial_drv_data)
Chanwoo Choi31ec77a2014-12-02 17:49:54 +09002518#define EXYNOS5433_SERIAL_DRV_DATA ((kernel_ulong_t)&exynos5433_serial_drv_data)
Thomas Abrahamda121502011-11-02 19:23:25 +09002519#else
2520#define EXYNOS4210_SERIAL_DRV_DATA (kernel_ulong_t)NULL
Chanwoo Choi31ec77a2014-12-02 17:49:54 +09002521#define EXYNOS5433_SERIAL_DRV_DATA (kernel_ulong_t)NULL
Thomas Abrahamda121502011-11-02 19:23:25 +09002522#endif
2523
Krzysztof Kozlowski24ee4df2015-05-02 00:40:05 +09002524static const struct platform_device_id s3c24xx_serial_driver_ids[] = {
Thomas Abrahamda121502011-11-02 19:23:25 +09002525 {
2526 .name = "s3c2410-uart",
2527 .driver_data = S3C2410_SERIAL_DRV_DATA,
2528 }, {
2529 .name = "s3c2412-uart",
2530 .driver_data = S3C2412_SERIAL_DRV_DATA,
2531 }, {
2532 .name = "s3c2440-uart",
2533 .driver_data = S3C2440_SERIAL_DRV_DATA,
2534 }, {
2535 .name = "s3c6400-uart",
2536 .driver_data = S3C6400_SERIAL_DRV_DATA,
2537 }, {
2538 .name = "s5pv210-uart",
2539 .driver_data = S5PV210_SERIAL_DRV_DATA,
2540 }, {
2541 .name = "exynos4210-uart",
2542 .driver_data = EXYNOS4210_SERIAL_DRV_DATA,
Chanwoo Choi31ec77a2014-12-02 17:49:54 +09002543 }, {
2544 .name = "exynos5433-uart",
2545 .driver_data = EXYNOS5433_SERIAL_DRV_DATA,
Thomas Abrahamda121502011-11-02 19:23:25 +09002546 },
2547 { },
2548};
2549MODULE_DEVICE_TABLE(platform, s3c24xx_serial_driver_ids);
2550
Thomas Abraham26c919e2011-11-06 22:10:44 +05302551#ifdef CONFIG_OF
2552static const struct of_device_id s3c24xx_uart_dt_match[] = {
Heiko Stübner666ca0b2012-11-22 11:37:44 +01002553 { .compatible = "samsung,s3c2410-uart",
2554 .data = (void *)S3C2410_SERIAL_DRV_DATA },
2555 { .compatible = "samsung,s3c2412-uart",
2556 .data = (void *)S3C2412_SERIAL_DRV_DATA },
2557 { .compatible = "samsung,s3c2440-uart",
2558 .data = (void *)S3C2440_SERIAL_DRV_DATA },
2559 { .compatible = "samsung,s3c6400-uart",
2560 .data = (void *)S3C6400_SERIAL_DRV_DATA },
2561 { .compatible = "samsung,s5pv210-uart",
2562 .data = (void *)S5PV210_SERIAL_DRV_DATA },
Thomas Abraham26c919e2011-11-06 22:10:44 +05302563 { .compatible = "samsung,exynos4210-uart",
Mark Browna169a882011-11-08 17:00:14 +09002564 .data = (void *)EXYNOS4210_SERIAL_DRV_DATA },
Chanwoo Choi31ec77a2014-12-02 17:49:54 +09002565 { .compatible = "samsung,exynos5433-uart",
2566 .data = (void *)EXYNOS5433_SERIAL_DRV_DATA },
Thomas Abraham26c919e2011-11-06 22:10:44 +05302567 {},
2568};
2569MODULE_DEVICE_TABLE(of, s3c24xx_uart_dt_match);
Thomas Abraham26c919e2011-11-06 22:10:44 +05302570#endif
2571
Thomas Abrahamda121502011-11-02 19:23:25 +09002572static struct platform_driver samsung_serial_driver = {
2573 .probe = s3c24xx_serial_probe,
Bill Pemberton2d47b712012-11-19 13:21:34 -05002574 .remove = s3c24xx_serial_remove,
Thomas Abrahamda121502011-11-02 19:23:25 +09002575 .id_table = s3c24xx_serial_driver_ids,
2576 .driver = {
2577 .name = "samsung-uart",
Thomas Abrahamda121502011-11-02 19:23:25 +09002578 .pm = SERIAL_SAMSUNG_PM_OPS,
Sachin Kamat905f4ba2013-01-07 09:50:42 +05302579 .of_match_table = of_match_ptr(s3c24xx_uart_dt_match),
Thomas Abrahamda121502011-11-02 19:23:25 +09002580 },
2581};
2582
Tushar Behera6f134c3c2014-01-20 14:32:34 +05302583module_platform_driver(samsung_serial_driver);
Thomas Abrahamda121502011-11-02 19:23:25 +09002584
Marek Szyprowskic3bda292015-02-02 10:47:35 +01002585#ifdef CONFIG_SERIAL_SAMSUNG_CONSOLE
Tomasz Figab94ba032015-01-23 14:47:41 +01002586/*
2587 * Early console.
2588 */
2589
2590struct samsung_early_console_data {
2591 u32 txfull_mask;
2592};
2593
2594static void samsung_early_busyuart(struct uart_port *port)
2595{
2596 while (!(readl(port->membase + S3C2410_UTRSTAT) & S3C2410_UTRSTAT_TXFE))
2597 ;
2598}
2599
2600static void samsung_early_busyuart_fifo(struct uart_port *port)
2601{
2602 struct samsung_early_console_data *data = port->private_data;
2603
2604 while (readl(port->membase + S3C2410_UFSTAT) & data->txfull_mask)
2605 ;
2606}
2607
2608static void samsung_early_putc(struct uart_port *port, int c)
2609{
2610 if (readl(port->membase + S3C2410_UFCON) & S3C2410_UFCON_FIFOMODE)
2611 samsung_early_busyuart_fifo(port);
2612 else
2613 samsung_early_busyuart(port);
2614
2615 writeb(c, port->membase + S3C2410_UTXH);
2616}
2617
Greg Kroah-Hartman90ece852019-12-10 15:37:04 +01002618static void samsung_early_write(struct console *con, const char *s,
2619 unsigned int n)
Tomasz Figab94ba032015-01-23 14:47:41 +01002620{
2621 struct earlycon_device *dev = con->data;
2622
2623 uart_console_write(&dev->port, s, n, samsung_early_putc);
2624}
2625
2626static int __init samsung_early_console_setup(struct earlycon_device *device,
2627 const char *opt)
2628{
2629 if (!device->port.membase)
2630 return -ENODEV;
2631
2632 device->con->write = samsung_early_write;
2633 return 0;
2634}
2635
2636/* S3C2410 */
2637static struct samsung_early_console_data s3c2410_early_console_data = {
2638 .txfull_mask = S3C2410_UFSTAT_TXFULL,
2639};
2640
2641static int __init s3c2410_early_console_setup(struct earlycon_device *device,
2642 const char *opt)
2643{
2644 device->port.private_data = &s3c2410_early_console_data;
2645 return samsung_early_console_setup(device, opt);
2646}
2647OF_EARLYCON_DECLARE(s3c2410, "samsung,s3c2410-uart",
2648 s3c2410_early_console_setup);
Tomasz Figab94ba032015-01-23 14:47:41 +01002649
2650/* S3C2412, S3C2440, S3C64xx */
2651static struct samsung_early_console_data s3c2440_early_console_data = {
2652 .txfull_mask = S3C2440_UFSTAT_TXFULL,
2653};
2654
2655static int __init s3c2440_early_console_setup(struct earlycon_device *device,
2656 const char *opt)
2657{
2658 device->port.private_data = &s3c2440_early_console_data;
2659 return samsung_early_console_setup(device, opt);
2660}
2661OF_EARLYCON_DECLARE(s3c2412, "samsung,s3c2412-uart",
2662 s3c2440_early_console_setup);
2663OF_EARLYCON_DECLARE(s3c2440, "samsung,s3c2440-uart",
2664 s3c2440_early_console_setup);
2665OF_EARLYCON_DECLARE(s3c6400, "samsung,s3c6400-uart",
2666 s3c2440_early_console_setup);
Tomasz Figab94ba032015-01-23 14:47:41 +01002667
Krzysztof Kozlowskib2097132020-01-04 16:21:04 +01002668/* S5PV210, Exynos */
Tomasz Figab94ba032015-01-23 14:47:41 +01002669static struct samsung_early_console_data s5pv210_early_console_data = {
2670 .txfull_mask = S5PV210_UFSTAT_TXFULL,
2671};
2672
2673static int __init s5pv210_early_console_setup(struct earlycon_device *device,
2674 const char *opt)
2675{
2676 device->port.private_data = &s5pv210_early_console_data;
2677 return samsung_early_console_setup(device, opt);
2678}
2679OF_EARLYCON_DECLARE(s5pv210, "samsung,s5pv210-uart",
2680 s5pv210_early_console_setup);
2681OF_EARLYCON_DECLARE(exynos4210, "samsung,exynos4210-uart",
2682 s5pv210_early_console_setup);
Marek Szyprowskic3bda292015-02-02 10:47:35 +01002683#endif
Tomasz Figab94ba032015-01-23 14:47:41 +01002684
Thomas Abrahamda121502011-11-02 19:23:25 +09002685MODULE_ALIAS("platform:samsung-uart");
Ben Dooksb4975492008-07-03 12:32:51 +01002686MODULE_DESCRIPTION("Samsung SoC Serial port driver");
2687MODULE_AUTHOR("Ben Dooks <ben@simtec.co.uk>");
2688MODULE_LICENSE("GPL v2");