blob: e284af8071de1d62be80985aa9912be38243e80f [file] [log] [blame]
Ben Dooks05a78962008-05-22 16:36:45 +01001/* linux/drivers/serial/s3c2410.c
Linus Torvalds1da177e2005-04-16 15:20:36 -07002 *
Ben Dooks05a78962008-05-22 16:36:45 +01003 * Driver for Samsung SoC onboard UARTs.
Linus Torvalds1da177e2005-04-16 15:20:36 -07004 *
Ben Dooks05a78962008-05-22 16:36:45 +01005 * Ben Dooks, Copyright (c) 2003-2005 Simtec Electronics
6 * http://armlinux.simtec.co.uk/
Ben Dooks8fe059d2008-05-23 11:48:00 +01007 *
8 * This program is free software; you can redistribute it and/or modify
9 * it under the terms of the GNU General Public License version 2 as
10 * published by the Free Software Foundation.
Linus Torvalds1da177e2005-04-16 15:20:36 -070011*/
12
13/* Note on 2440 fclk clock source handling
14 *
15 * Whilst it is possible to use the fclk as clock source, the method
16 * of properly switching too/from this is currently un-implemented, so
17 * whichever way is configured at startup is the one that will be used.
18*/
19
20/* Hote on 2410 error handling
21 *
22 * The s3c2410 manual has a love/hate affair with the contents of the
23 * UERSTAT register in the UART blocks, and keeps marking some of the
24 * error bits as reserved. Having checked with the s3c2410x01,
25 * it copes with BREAKs properly, so I am happy to ignore the RESERVED
26 * feature from the latter versions of the manual.
27 *
28 * If it becomes aparrent that latter versions of the 2410 remove these
29 * bits, then action will have to be taken to differentiate the versions
30 * and change the policy on BREAK
31 *
32 * BJD, 04-Nov-2004
33*/
34
Linus Torvalds1da177e2005-04-16 15:20:36 -070035
36#if defined(CONFIG_SERIAL_S3C2410_CONSOLE) && defined(CONFIG_MAGIC_SYSRQ)
37#define SUPPORT_SYSRQ
38#endif
39
40#include <linux/module.h>
41#include <linux/ioport.h>
Russell Kingd052d1b2005-10-29 19:07:23 +010042#include <linux/platform_device.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070043#include <linux/init.h>
44#include <linux/sysrq.h>
45#include <linux/console.h>
46#include <linux/tty.h>
47#include <linux/tty_flip.h>
48#include <linux/serial_core.h>
49#include <linux/serial.h>
50#include <linux/delay.h>
Russell Kingf8ce2542006-01-07 16:15:52 +000051#include <linux/clk.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070052
53#include <asm/io.h>
54#include <asm/irq.h>
55
56#include <asm/hardware.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070057
Ben Dooks531b6172007-07-22 16:05:25 +010058#include <asm/plat-s3c/regs-serial.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070059#include <asm/arch/regs-gpio.h>
60
Linus Torvalds1da177e2005-04-16 15:20:36 -070061/* structures */
62
63struct s3c24xx_uart_info {
64 char *name;
65 unsigned int type;
66 unsigned int fifosize;
67 unsigned long rx_fifomask;
68 unsigned long rx_fifoshift;
69 unsigned long rx_fifofull;
70 unsigned long tx_fifomask;
71 unsigned long tx_fifoshift;
72 unsigned long tx_fifofull;
73
74 /* clock source control */
75
76 int (*get_clksrc)(struct uart_port *, struct s3c24xx_uart_clksrc *clk);
77 int (*set_clksrc)(struct uart_port *, struct s3c24xx_uart_clksrc *clk);
78
79 /* uart controls */
80 int (*reset_port)(struct uart_port *, struct s3c2410_uartcfg *);
81};
82
83struct s3c24xx_uart_port {
84 unsigned char rx_claimed;
85 unsigned char tx_claimed;
86
87 struct s3c24xx_uart_info *info;
88 struct s3c24xx_uart_clksrc *clksrc;
89 struct clk *clk;
90 struct clk *baudclk;
91 struct uart_port port;
92};
93
94
95/* configuration defines */
96
97#if 0
98#if 1
99/* send debug to the low-level output routines */
100
101extern void printascii(const char *);
102
103static void
104s3c24xx_serial_dbg(const char *fmt, ...)
105{
106 va_list va;
107 char buff[256];
108
109 va_start(va, fmt);
110 vsprintf(buff, fmt, va);
111 va_end(va);
112
113 printascii(buff);
114}
115
116#define dbg(x...) s3c24xx_serial_dbg(x)
117
118#else
119#define dbg(x...) printk(KERN_DEBUG "s3c24xx: ");
120#endif
121#else /* no debug */
122#define dbg(x...) do {} while(0)
123#endif
124
125/* UART name and device definitions */
126
127#define S3C24XX_SERIAL_NAME "ttySAC"
Linus Torvalds1da177e2005-04-16 15:20:36 -0700128#define S3C24XX_SERIAL_MAJOR 204
129#define S3C24XX_SERIAL_MINOR 64
130
131
132/* conversion functions */
133
134#define s3c24xx_dev_to_port(__dev) (struct uart_port *)dev_get_drvdata(__dev)
135#define s3c24xx_dev_to_cfg(__dev) (struct s3c2410_uartcfg *)((__dev)->platform_data)
136
137/* we can support 3 uarts, but not always use them */
138
Lucas Correia Villa Real5cba7422006-02-08 21:31:54 +0000139#ifdef CONFIG_CPU_S3C2400
140#define NR_PORTS (2)
141#else
Linus Torvalds1da177e2005-04-16 15:20:36 -0700142#define NR_PORTS (3)
Lucas Correia Villa Real5cba7422006-02-08 21:31:54 +0000143#endif
Linus Torvalds1da177e2005-04-16 15:20:36 -0700144
145/* port irq numbers */
146
147#define TX_IRQ(port) ((port)->irq + 1)
148#define RX_IRQ(port) ((port)->irq)
149
150/* register access controls */
151
152#define portaddr(port, reg) ((port)->membase + (reg))
153
154#define rd_regb(port, reg) (__raw_readb(portaddr(port, reg)))
155#define rd_regl(port, reg) (__raw_readl(portaddr(port, reg)))
156
157#define wr_regb(port, reg, val) \
158 do { __raw_writeb(val, portaddr(port, reg)); } while(0)
159
160#define wr_regl(port, reg, val) \
161 do { __raw_writel(val, portaddr(port, reg)); } while(0)
162
163/* macros to change one thing to another */
164
165#define tx_enabled(port) ((port)->unused[0])
166#define rx_enabled(port) ((port)->unused[1])
167
168/* flag to ignore all characters comming in */
169#define RXSTAT_DUMMY_READ (0x10000000)
170
171static inline struct s3c24xx_uart_port *to_ourport(struct uart_port *port)
172{
173 return container_of(port, struct s3c24xx_uart_port, port);
174}
175
176/* translate a port to the device name */
177
Ben Dooksd9dc5802005-06-23 21:56:46 +0100178static inline const char *s3c24xx_serial_portname(struct uart_port *port)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700179{
180 return to_platform_device(port->dev)->name;
181}
182
183static int s3c24xx_serial_txempty_nofifo(struct uart_port *port)
184{
185 return (rd_regl(port, S3C2410_UTRSTAT) & S3C2410_UTRSTAT_TXE);
186}
187
188static void s3c24xx_serial_rx_enable(struct uart_port *port)
189{
190 unsigned long flags;
191 unsigned int ucon, ufcon;
192 int count = 10000;
193
194 spin_lock_irqsave(&port->lock, flags);
195
196 while (--count && !s3c24xx_serial_txempty_nofifo(port))
197 udelay(100);
198
199 ufcon = rd_regl(port, S3C2410_UFCON);
200 ufcon |= S3C2410_UFCON_RESETRX;
201 wr_regl(port, S3C2410_UFCON, ufcon);
202
203 ucon = rd_regl(port, S3C2410_UCON);
204 ucon |= S3C2410_UCON_RXIRQMODE;
205 wr_regl(port, S3C2410_UCON, ucon);
206
207 rx_enabled(port) = 1;
208 spin_unlock_irqrestore(&port->lock, flags);
209}
210
211static void s3c24xx_serial_rx_disable(struct uart_port *port)
212{
213 unsigned long flags;
214 unsigned int ucon;
215
216 spin_lock_irqsave(&port->lock, flags);
217
218 ucon = rd_regl(port, S3C2410_UCON);
219 ucon &= ~S3C2410_UCON_RXIRQMODE;
220 wr_regl(port, S3C2410_UCON, ucon);
221
222 rx_enabled(port) = 0;
223 spin_unlock_irqrestore(&port->lock, flags);
224}
225
Russell Kingb129a8c2005-08-31 10:12:14 +0100226static void s3c24xx_serial_stop_tx(struct uart_port *port)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700227{
228 if (tx_enabled(port)) {
229 disable_irq(TX_IRQ(port));
230 tx_enabled(port) = 0;
231 if (port->flags & UPF_CONS_FLOW)
232 s3c24xx_serial_rx_enable(port);
233 }
234}
235
Russell Kingb129a8c2005-08-31 10:12:14 +0100236static void s3c24xx_serial_start_tx(struct uart_port *port)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700237{
238 if (!tx_enabled(port)) {
239 if (port->flags & UPF_CONS_FLOW)
240 s3c24xx_serial_rx_disable(port);
241
242 enable_irq(TX_IRQ(port));
243 tx_enabled(port) = 1;
244 }
245}
246
247
248static void s3c24xx_serial_stop_rx(struct uart_port *port)
249{
250 if (rx_enabled(port)) {
251 dbg("s3c24xx_serial_stop_rx: port=%p\n", port);
252 disable_irq(RX_IRQ(port));
253 rx_enabled(port) = 0;
254 }
255}
256
257static void s3c24xx_serial_enable_ms(struct uart_port *port)
258{
259}
260
261static inline struct s3c24xx_uart_info *s3c24xx_port_to_info(struct uart_port *port)
262{
263 return to_ourport(port)->info;
264}
265
266static inline struct s3c2410_uartcfg *s3c24xx_port_to_cfg(struct uart_port *port)
267{
268 if (port->dev == NULL)
269 return NULL;
270
271 return (struct s3c2410_uartcfg *)port->dev->platform_data;
272}
273
274static int s3c24xx_serial_rx_fifocnt(struct s3c24xx_uart_port *ourport,
275 unsigned long ufstat)
276{
277 struct s3c24xx_uart_info *info = ourport->info;
278
279 if (ufstat & info->rx_fifofull)
280 return info->fifosize;
281
282 return (ufstat & info->rx_fifomask) >> info->rx_fifoshift;
283}
284
285
286/* ? - where has parity gone?? */
287#define S3C2410_UERSTAT_PARITY (0x1000)
288
289static irqreturn_t
David Howells7d12e782006-10-05 14:55:46 +0100290s3c24xx_serial_rx_chars(int irq, void *dev_id)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700291{
292 struct s3c24xx_uart_port *ourport = dev_id;
293 struct uart_port *port = &ourport->port;
294 struct tty_struct *tty = port->info->tty;
295 unsigned int ufcon, ch, flag, ufstat, uerstat;
296 int max_count = 64;
297
298 while (max_count-- > 0) {
299 ufcon = rd_regl(port, S3C2410_UFCON);
300 ufstat = rd_regl(port, S3C2410_UFSTAT);
301
302 if (s3c24xx_serial_rx_fifocnt(ourport, ufstat) == 0)
303 break;
304
Linus Torvalds1da177e2005-04-16 15:20:36 -0700305 uerstat = rd_regl(port, S3C2410_UERSTAT);
306 ch = rd_regb(port, S3C2410_URXH);
307
308 if (port->flags & UPF_CONS_FLOW) {
309 int txe = s3c24xx_serial_txempty_nofifo(port);
310
311 if (rx_enabled(port)) {
312 if (!txe) {
313 rx_enabled(port) = 0;
314 continue;
315 }
316 } else {
317 if (txe) {
318 ufcon |= S3C2410_UFCON_RESETRX;
319 wr_regl(port, S3C2410_UFCON, ufcon);
320 rx_enabled(port) = 1;
321 goto out;
322 }
323 continue;
324 }
325 }
326
327 /* insert the character into the buffer */
328
329 flag = TTY_NORMAL;
330 port->icount.rx++;
331
Russell King45849282005-04-26 15:29:44 +0100332 if (unlikely(uerstat & S3C2410_UERSTAT_ANY)) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700333 dbg("rxerr: port ch=0x%02x, rxs=0x%08x\n",
334 ch, uerstat);
335
336 /* check for break */
337 if (uerstat & S3C2410_UERSTAT_BREAK) {
338 dbg("break!\n");
339 port->icount.brk++;
340 if (uart_handle_break(port))
341 goto ignore_char;
342 }
343
344 if (uerstat & S3C2410_UERSTAT_FRAME)
345 port->icount.frame++;
346 if (uerstat & S3C2410_UERSTAT_OVERRUN)
347 port->icount.overrun++;
348
349 uerstat &= port->read_status_mask;
350
351 if (uerstat & S3C2410_UERSTAT_BREAK)
352 flag = TTY_BREAK;
353 else if (uerstat & S3C2410_UERSTAT_PARITY)
354 flag = TTY_PARITY;
355 else if (uerstat & ( S3C2410_UERSTAT_FRAME | S3C2410_UERSTAT_OVERRUN))
356 flag = TTY_FRAME;
357 }
358
David Howells7d12e782006-10-05 14:55:46 +0100359 if (uart_handle_sysrq_char(port, ch))
Linus Torvalds1da177e2005-04-16 15:20:36 -0700360 goto ignore_char;
361
Russell King05ab3012005-05-09 23:21:59 +0100362 uart_insert_char(port, uerstat, S3C2410_UERSTAT_OVERRUN, ch, flag);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700363
364 ignore_char:
365 continue;
366 }
367 tty_flip_buffer_push(tty);
368
369 out:
370 return IRQ_HANDLED;
371}
372
David Howells7d12e782006-10-05 14:55:46 +0100373static irqreturn_t s3c24xx_serial_tx_chars(int irq, void *id)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700374{
375 struct s3c24xx_uart_port *ourport = id;
376 struct uart_port *port = &ourport->port;
377 struct circ_buf *xmit = &port->info->xmit;
378 int count = 256;
379
380 if (port->x_char) {
381 wr_regb(port, S3C2410_UTXH, port->x_char);
382 port->icount.tx++;
383 port->x_char = 0;
384 goto out;
385 }
386
387 /* if there isnt anything more to transmit, or the uart is now
388 * stopped, disable the uart and exit
389 */
390
391 if (uart_circ_empty(xmit) || uart_tx_stopped(port)) {
Russell Kingb129a8c2005-08-31 10:12:14 +0100392 s3c24xx_serial_stop_tx(port);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700393 goto out;
394 }
395
396 /* try and drain the buffer... */
397
398 while (!uart_circ_empty(xmit) && count-- > 0) {
399 if (rd_regl(port, S3C2410_UFSTAT) & ourport->info->tx_fifofull)
400 break;
401
402 wr_regb(port, S3C2410_UTXH, xmit->buf[xmit->tail]);
403 xmit->tail = (xmit->tail + 1) & (UART_XMIT_SIZE - 1);
404 port->icount.tx++;
405 }
406
407 if (uart_circ_chars_pending(xmit) < WAKEUP_CHARS)
408 uart_write_wakeup(port);
409
410 if (uart_circ_empty(xmit))
Russell Kingb129a8c2005-08-31 10:12:14 +0100411 s3c24xx_serial_stop_tx(port);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700412
413 out:
414 return IRQ_HANDLED;
415}
416
417static unsigned int s3c24xx_serial_tx_empty(struct uart_port *port)
418{
419 struct s3c24xx_uart_info *info = s3c24xx_port_to_info(port);
420 unsigned long ufstat = rd_regl(port, S3C2410_UFSTAT);
421 unsigned long ufcon = rd_regl(port, S3C2410_UFCON);
422
423 if (ufcon & S3C2410_UFCON_FIFOMODE) {
424 if ((ufstat & info->tx_fifomask) != 0 ||
425 (ufstat & info->tx_fifofull))
426 return 0;
427
428 return 1;
429 }
430
431 return s3c24xx_serial_txempty_nofifo(port);
432}
433
434/* no modem control lines */
435static unsigned int s3c24xx_serial_get_mctrl(struct uart_port *port)
436{
437 unsigned int umstat = rd_regb(port,S3C2410_UMSTAT);
438
439 if (umstat & S3C2410_UMSTAT_CTS)
440 return TIOCM_CAR | TIOCM_DSR | TIOCM_CTS;
441 else
442 return TIOCM_CAR | TIOCM_DSR;
443}
444
445static void s3c24xx_serial_set_mctrl(struct uart_port *port, unsigned int mctrl)
446{
447 /* todo - possibly remove AFC and do manual CTS */
448}
449
450static void s3c24xx_serial_break_ctl(struct uart_port *port, int break_state)
451{
452 unsigned long flags;
453 unsigned int ucon;
454
455 spin_lock_irqsave(&port->lock, flags);
456
457 ucon = rd_regl(port, S3C2410_UCON);
458
459 if (break_state)
460 ucon |= S3C2410_UCON_SBREAK;
461 else
462 ucon &= ~S3C2410_UCON_SBREAK;
463
464 wr_regl(port, S3C2410_UCON, ucon);
465
466 spin_unlock_irqrestore(&port->lock, flags);
467}
468
469static void s3c24xx_serial_shutdown(struct uart_port *port)
470{
471 struct s3c24xx_uart_port *ourport = to_ourport(port);
472
473 if (ourport->tx_claimed) {
474 free_irq(TX_IRQ(port), ourport);
475 tx_enabled(port) = 0;
476 ourport->tx_claimed = 0;
477 }
478
479 if (ourport->rx_claimed) {
480 free_irq(RX_IRQ(port), ourport);
481 ourport->rx_claimed = 0;
482 rx_enabled(port) = 0;
483 }
484}
485
486
487static int s3c24xx_serial_startup(struct uart_port *port)
488{
489 struct s3c24xx_uart_port *ourport = to_ourport(port);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700490 int ret;
491
492 dbg("s3c24xx_serial_startup: port=%p (%08lx,%p)\n",
493 port->mapbase, port->membase);
494
Linus Torvalds1da177e2005-04-16 15:20:36 -0700495 rx_enabled(port) = 1;
496
497 ret = request_irq(RX_IRQ(port),
498 s3c24xx_serial_rx_chars, 0,
499 s3c24xx_serial_portname(port), ourport);
500
501 if (ret != 0) {
502 printk(KERN_ERR "cannot get irq %d\n", RX_IRQ(port));
503 return ret;
504 }
505
506 ourport->rx_claimed = 1;
507
508 dbg("requesting tx irq...\n");
509
510 tx_enabled(port) = 1;
511
512 ret = request_irq(TX_IRQ(port),
513 s3c24xx_serial_tx_chars, 0,
514 s3c24xx_serial_portname(port), ourport);
515
516 if (ret) {
517 printk(KERN_ERR "cannot get irq %d\n", TX_IRQ(port));
518 goto err;
519 }
520
521 ourport->tx_claimed = 1;
522
523 dbg("s3c24xx_serial_startup ok\n");
524
525 /* the port reset code should have done the correct
526 * register setup for the port controls */
527
Linus Torvalds1da177e2005-04-16 15:20:36 -0700528 return ret;
529
530 err:
531 s3c24xx_serial_shutdown(port);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700532 return ret;
533}
534
535/* power power management control */
536
537static void s3c24xx_serial_pm(struct uart_port *port, unsigned int level,
538 unsigned int old)
539{
540 struct s3c24xx_uart_port *ourport = to_ourport(port);
541
542 switch (level) {
543 case 3:
544 if (!IS_ERR(ourport->baudclk) && ourport->baudclk != NULL)
545 clk_disable(ourport->baudclk);
546
547 clk_disable(ourport->clk);
548 break;
549
550 case 0:
551 clk_enable(ourport->clk);
552
553 if (!IS_ERR(ourport->baudclk) && ourport->baudclk != NULL)
554 clk_enable(ourport->baudclk);
555
556 break;
557 default:
558 printk(KERN_ERR "s3c24xx_serial: unknown pm %d\n", level);
559 }
560}
561
562/* baud rate calculation
563 *
564 * The UARTs on the S3C2410/S3C2440 can take their clocks from a number
565 * of different sources, including the peripheral clock ("pclk") and an
566 * external clock ("uclk"). The S3C2440 also adds the core clock ("fclk")
567 * with a programmable extra divisor.
568 *
569 * The following code goes through the clock sources, and calculates the
570 * baud clocks (and the resultant actual baud rates) and then tries to
571 * pick the closest one and select that.
572 *
573*/
574
575
576#define MAX_CLKS (8)
577
578static struct s3c24xx_uart_clksrc tmp_clksrc = {
579 .name = "pclk",
580 .min_baud = 0,
581 .max_baud = 0,
582 .divisor = 1,
583};
584
585static inline int
586s3c24xx_serial_getsource(struct uart_port *port, struct s3c24xx_uart_clksrc *c)
587{
588 struct s3c24xx_uart_info *info = s3c24xx_port_to_info(port);
589
590 return (info->get_clksrc)(port, c);
591}
592
593static inline int
594s3c24xx_serial_setsource(struct uart_port *port, struct s3c24xx_uart_clksrc *c)
595{
596 struct s3c24xx_uart_info *info = s3c24xx_port_to_info(port);
597
598 return (info->set_clksrc)(port, c);
599}
600
601struct baud_calc {
602 struct s3c24xx_uart_clksrc *clksrc;
603 unsigned int calc;
604 unsigned int quot;
605 struct clk *src;
606};
607
608static int s3c24xx_serial_calcbaud(struct baud_calc *calc,
609 struct uart_port *port,
610 struct s3c24xx_uart_clksrc *clksrc,
611 unsigned int baud)
612{
613 unsigned long rate;
614
615 calc->src = clk_get(port->dev, clksrc->name);
616 if (calc->src == NULL || IS_ERR(calc->src))
617 return 0;
618
619 rate = clk_get_rate(calc->src);
620 rate /= clksrc->divisor;
621
622 calc->clksrc = clksrc;
623 calc->quot = (rate + (8 * baud)) / (16 * baud);
624 calc->calc = (rate / (calc->quot * 16));
625
626 calc->quot--;
627 return 1;
628}
629
630static unsigned int s3c24xx_serial_getclk(struct uart_port *port,
631 struct s3c24xx_uart_clksrc **clksrc,
632 struct clk **clk,
633 unsigned int baud)
634{
635 struct s3c2410_uartcfg *cfg = s3c24xx_port_to_cfg(port);
636 struct s3c24xx_uart_clksrc *clkp;
637 struct baud_calc res[MAX_CLKS];
638 struct baud_calc *resptr, *best, *sptr;
639 int i;
640
641 clkp = cfg->clocks;
642 best = NULL;
643
644 if (cfg->clocks_size < 2) {
645 if (cfg->clocks_size == 0)
646 clkp = &tmp_clksrc;
647
648 /* check to see if we're sourcing fclk, and if so we're
649 * going to have to update the clock source
650 */
651
652 if (strcmp(clkp->name, "fclk") == 0) {
653 struct s3c24xx_uart_clksrc src;
654
655 s3c24xx_serial_getsource(port, &src);
656
657 /* check that the port already using fclk, and if
658 * not, then re-select fclk
659 */
660
661 if (strcmp(src.name, clkp->name) == 0) {
662 s3c24xx_serial_setsource(port, clkp);
663 s3c24xx_serial_getsource(port, &src);
664 }
665
666 clkp->divisor = src.divisor;
667 }
668
669 s3c24xx_serial_calcbaud(res, port, clkp, baud);
670 best = res;
671 resptr = best + 1;
672 } else {
673 resptr = res;
674
675 for (i = 0; i < cfg->clocks_size; i++, clkp++) {
676 if (s3c24xx_serial_calcbaud(resptr, port, clkp, baud))
677 resptr++;
678 }
679 }
680
681 /* ok, we now need to select the best clock we found */
682
683 if (!best) {
684 unsigned int deviation = (1<<30)|((1<<30)-1);
685 int calc_deviation;
686
687 for (sptr = res; sptr < resptr; sptr++) {
688 printk(KERN_DEBUG
689 "found clk %p (%s) quot %d, calc %d\n",
690 sptr->clksrc, sptr->clksrc->name,
691 sptr->quot, sptr->calc);
692
693 calc_deviation = baud - sptr->calc;
694 if (calc_deviation < 0)
695 calc_deviation = -calc_deviation;
696
697 if (calc_deviation < deviation) {
698 best = sptr;
699 deviation = calc_deviation;
700 }
701 }
702
703 printk(KERN_DEBUG "best %p (deviation %d)\n", best, deviation);
704 }
705
706 printk(KERN_DEBUG "selected clock %p (%s) quot %d, calc %d\n",
707 best->clksrc, best->clksrc->name, best->quot, best->calc);
708
709 /* store results to pass back */
710
711 *clksrc = best->clksrc;
712 *clk = best->src;
713
714 return best->quot;
715}
716
717static void s3c24xx_serial_set_termios(struct uart_port *port,
Alan Cox606d0992006-12-08 02:38:45 -0800718 struct ktermios *termios,
719 struct ktermios *old)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700720{
721 struct s3c2410_uartcfg *cfg = s3c24xx_port_to_cfg(port);
722 struct s3c24xx_uart_port *ourport = to_ourport(port);
Ben Dooksf04da5d2005-09-25 23:02:49 +0100723 struct s3c24xx_uart_clksrc *clksrc = NULL;
724 struct clk *clk = NULL;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700725 unsigned long flags;
726 unsigned int baud, quot;
727 unsigned int ulcon;
728 unsigned int umcon;
729
730 /*
731 * We don't support modem control lines.
732 */
733 termios->c_cflag &= ~(HUPCL | CMSPAR);
734 termios->c_cflag |= CLOCAL;
735
736 /*
737 * Ask the core to calculate the divisor for us.
738 */
739
740 baud = uart_get_baud_rate(port, termios, old, 0, 115200*8);
741
742 if (baud == 38400 && (port->flags & UPF_SPD_MASK) == UPF_SPD_CUST)
743 quot = port->custom_divisor;
744 else
745 quot = s3c24xx_serial_getclk(port, &clksrc, &clk, baud);
746
747 /* check to see if we need to change clock source */
748
749 if (ourport->clksrc != clksrc || ourport->baudclk != clk) {
750 s3c24xx_serial_setsource(port, clksrc);
751
752 if (ourport->baudclk != NULL && !IS_ERR(ourport->baudclk)) {
753 clk_disable(ourport->baudclk);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700754 ourport->baudclk = NULL;
755 }
756
Linus Torvalds1da177e2005-04-16 15:20:36 -0700757 clk_enable(clk);
758
759 ourport->clksrc = clksrc;
760 ourport->baudclk = clk;
761 }
762
763 switch (termios->c_cflag & CSIZE) {
764 case CS5:
765 dbg("config: 5bits/char\n");
766 ulcon = S3C2410_LCON_CS5;
767 break;
768 case CS6:
769 dbg("config: 6bits/char\n");
770 ulcon = S3C2410_LCON_CS6;
771 break;
772 case CS7:
773 dbg("config: 7bits/char\n");
774 ulcon = S3C2410_LCON_CS7;
775 break;
776 case CS8:
777 default:
778 dbg("config: 8bits/char\n");
779 ulcon = S3C2410_LCON_CS8;
780 break;
781 }
782
783 /* preserve original lcon IR settings */
784 ulcon |= (cfg->ulcon & S3C2410_LCON_IRM);
785
786 if (termios->c_cflag & CSTOPB)
787 ulcon |= S3C2410_LCON_STOPB;
788
789 umcon = (termios->c_cflag & CRTSCTS) ? S3C2410_UMCOM_AFC : 0;
790
791 if (termios->c_cflag & PARENB) {
792 if (termios->c_cflag & PARODD)
793 ulcon |= S3C2410_LCON_PODD;
794 else
795 ulcon |= S3C2410_LCON_PEVEN;
796 } else {
797 ulcon |= S3C2410_LCON_PNONE;
798 }
799
800 spin_lock_irqsave(&port->lock, flags);
801
802 dbg("setting ulcon to %08x, brddiv to %d\n", ulcon, quot);
803
804 wr_regl(port, S3C2410_ULCON, ulcon);
805 wr_regl(port, S3C2410_UBRDIV, quot);
806 wr_regl(port, S3C2410_UMCON, umcon);
807
808 dbg("uart: ulcon = 0x%08x, ucon = 0x%08x, ufcon = 0x%08x\n",
809 rd_regl(port, S3C2410_ULCON),
810 rd_regl(port, S3C2410_UCON),
811 rd_regl(port, S3C2410_UFCON));
812
813 /*
814 * Update the per-port timeout.
815 */
816 uart_update_timeout(port, termios->c_cflag, baud);
817
818 /*
819 * Which character status flags are we interested in?
820 */
821 port->read_status_mask = S3C2410_UERSTAT_OVERRUN;
822 if (termios->c_iflag & INPCK)
823 port->read_status_mask |= S3C2410_UERSTAT_FRAME | S3C2410_UERSTAT_PARITY;
824
825 /*
826 * Which character status flags should we ignore?
827 */
828 port->ignore_status_mask = 0;
829 if (termios->c_iflag & IGNPAR)
830 port->ignore_status_mask |= S3C2410_UERSTAT_OVERRUN;
831 if (termios->c_iflag & IGNBRK && termios->c_iflag & IGNPAR)
832 port->ignore_status_mask |= S3C2410_UERSTAT_FRAME;
833
834 /*
835 * Ignore all characters if CREAD is not set.
836 */
837 if ((termios->c_cflag & CREAD) == 0)
838 port->ignore_status_mask |= RXSTAT_DUMMY_READ;
839
840 spin_unlock_irqrestore(&port->lock, flags);
841}
842
843static const char *s3c24xx_serial_type(struct uart_port *port)
844{
845 switch (port->type) {
846 case PORT_S3C2410:
847 return "S3C2410";
848 case PORT_S3C2440:
849 return "S3C2440";
Ben Dooks73e55cb2006-06-24 21:21:32 +0100850 case PORT_S3C2412:
851 return "S3C2412";
Linus Torvalds1da177e2005-04-16 15:20:36 -0700852 default:
853 return NULL;
854 }
855}
856
857#define MAP_SIZE (0x100)
858
859static void s3c24xx_serial_release_port(struct uart_port *port)
860{
861 release_mem_region(port->mapbase, MAP_SIZE);
862}
863
864static int s3c24xx_serial_request_port(struct uart_port *port)
865{
Ben Dooksd9dc5802005-06-23 21:56:46 +0100866 const char *name = s3c24xx_serial_portname(port);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700867 return request_mem_region(port->mapbase, MAP_SIZE, name) ? 0 : -EBUSY;
868}
869
870static void s3c24xx_serial_config_port(struct uart_port *port, int flags)
871{
872 struct s3c24xx_uart_info *info = s3c24xx_port_to_info(port);
873
874 if (flags & UART_CONFIG_TYPE &&
875 s3c24xx_serial_request_port(port) == 0)
876 port->type = info->type;
877}
878
879/*
880 * verify the new serial_struct (for TIOCSSERIAL).
881 */
882static int
883s3c24xx_serial_verify_port(struct uart_port *port, struct serial_struct *ser)
884{
885 struct s3c24xx_uart_info *info = s3c24xx_port_to_info(port);
886
887 if (ser->type != PORT_UNKNOWN && ser->type != info->type)
888 return -EINVAL;
889
890 return 0;
891}
892
893
894#ifdef CONFIG_SERIAL_S3C2410_CONSOLE
895
896static struct console s3c24xx_serial_console;
897
898#define S3C24XX_SERIAL_CONSOLE &s3c24xx_serial_console
899#else
900#define S3C24XX_SERIAL_CONSOLE NULL
901#endif
902
903static struct uart_ops s3c24xx_serial_ops = {
904 .pm = s3c24xx_serial_pm,
905 .tx_empty = s3c24xx_serial_tx_empty,
906 .get_mctrl = s3c24xx_serial_get_mctrl,
907 .set_mctrl = s3c24xx_serial_set_mctrl,
908 .stop_tx = s3c24xx_serial_stop_tx,
909 .start_tx = s3c24xx_serial_start_tx,
910 .stop_rx = s3c24xx_serial_stop_rx,
911 .enable_ms = s3c24xx_serial_enable_ms,
912 .break_ctl = s3c24xx_serial_break_ctl,
913 .startup = s3c24xx_serial_startup,
914 .shutdown = s3c24xx_serial_shutdown,
915 .set_termios = s3c24xx_serial_set_termios,
916 .type = s3c24xx_serial_type,
917 .release_port = s3c24xx_serial_release_port,
918 .request_port = s3c24xx_serial_request_port,
919 .config_port = s3c24xx_serial_config_port,
920 .verify_port = s3c24xx_serial_verify_port,
921};
922
923
924static struct uart_driver s3c24xx_uart_drv = {
925 .owner = THIS_MODULE,
926 .dev_name = "s3c2410_serial",
927 .nr = 3,
928 .cons = S3C24XX_SERIAL_CONSOLE,
929 .driver_name = S3C24XX_SERIAL_NAME,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700930 .major = S3C24XX_SERIAL_MAJOR,
931 .minor = S3C24XX_SERIAL_MINOR,
932};
933
934static struct s3c24xx_uart_port s3c24xx_serial_ports[NR_PORTS] = {
935 [0] = {
936 .port = {
Milind Arun Choudhary076fa0f2007-05-08 00:30:10 -0700937 .lock = __SPIN_LOCK_UNLOCKED(s3c24xx_serial_ports[0].port.lock),
Linus Torvalds1da177e2005-04-16 15:20:36 -0700938 .iotype = UPIO_MEM,
939 .irq = IRQ_S3CUART_RX0,
940 .uartclk = 0,
941 .fifosize = 16,
942 .ops = &s3c24xx_serial_ops,
943 .flags = UPF_BOOT_AUTOCONF,
944 .line = 0,
945 }
946 },
947 [1] = {
948 .port = {
Milind Arun Choudhary076fa0f2007-05-08 00:30:10 -0700949 .lock = __SPIN_LOCK_UNLOCKED(s3c24xx_serial_ports[1].port.lock),
Linus Torvalds1da177e2005-04-16 15:20:36 -0700950 .iotype = UPIO_MEM,
951 .irq = IRQ_S3CUART_RX1,
952 .uartclk = 0,
953 .fifosize = 16,
954 .ops = &s3c24xx_serial_ops,
955 .flags = UPF_BOOT_AUTOCONF,
956 .line = 1,
957 }
958 },
959#if NR_PORTS > 2
960
961 [2] = {
962 .port = {
Milind Arun Choudhary076fa0f2007-05-08 00:30:10 -0700963 .lock = __SPIN_LOCK_UNLOCKED(s3c24xx_serial_ports[2].port.lock),
Linus Torvalds1da177e2005-04-16 15:20:36 -0700964 .iotype = UPIO_MEM,
965 .irq = IRQ_S3CUART_RX2,
966 .uartclk = 0,
967 .fifosize = 16,
968 .ops = &s3c24xx_serial_ops,
969 .flags = UPF_BOOT_AUTOCONF,
970 .line = 2,
971 }
972 }
973#endif
974};
975
976/* s3c24xx_serial_resetport
977 *
978 * wrapper to call the specific reset for this port (reset the fifos
979 * and the settings)
980*/
981
982static inline int s3c24xx_serial_resetport(struct uart_port * port,
983 struct s3c2410_uartcfg *cfg)
984{
985 struct s3c24xx_uart_info *info = s3c24xx_port_to_info(port);
986
987 return (info->reset_port)(port, cfg);
988}
989
990/* s3c24xx_serial_init_port
991 *
992 * initialise a single serial port from the platform device given
993 */
994
995static int s3c24xx_serial_init_port(struct s3c24xx_uart_port *ourport,
996 struct s3c24xx_uart_info *info,
997 struct platform_device *platdev)
998{
999 struct uart_port *port = &ourport->port;
1000 struct s3c2410_uartcfg *cfg;
1001 struct resource *res;
Roel Kluin681587c2008-04-23 23:59:36 +02001002 int ret;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001003
1004 dbg("s3c24xx_serial_init_port: port=%p, platdev=%p\n", port, platdev);
1005
1006 if (platdev == NULL)
1007 return -ENODEV;
1008
1009 cfg = s3c24xx_dev_to_cfg(&platdev->dev);
1010
1011 if (port->mapbase != 0)
1012 return 0;
1013
1014 if (cfg->hwport > 3)
1015 return -EINVAL;
1016
1017 /* setup info for port */
1018 port->dev = &platdev->dev;
1019 ourport->info = info;
1020
1021 /* copy the info in from provided structure */
1022 ourport->port.fifosize = info->fifosize;
1023
1024 dbg("s3c24xx_serial_init_port: %p (hw %d)...\n", port, cfg->hwport);
1025
1026 port->uartclk = 1;
1027
1028 if (cfg->uart_flags & UPF_CONS_FLOW) {
1029 dbg("s3c24xx_serial_init_port: enabling flow control\n");
1030 port->flags |= UPF_CONS_FLOW;
1031 }
1032
1033 /* sort our the physical and virtual addresses for each UART */
1034
1035 res = platform_get_resource(platdev, IORESOURCE_MEM, 0);
1036 if (res == NULL) {
1037 printk(KERN_ERR "failed to find memory resource for uart\n");
1038 return -EINVAL;
1039 }
1040
1041 dbg("resource %p (%lx..%lx)\n", res, res->start, res->end);
1042
1043 port->mapbase = res->start;
Lucas Correia Villa Real0367a8d2006-01-26 15:20:50 +00001044 port->membase = S3C24XX_VA_UART + (res->start - S3C24XX_PA_UART);
Roel Kluin681587c2008-04-23 23:59:36 +02001045 ret = platform_get_irq(platdev, 0);
1046 if (ret < 0)
David Vrabel48944732006-01-19 17:56:29 +00001047 port->irq = 0;
Roel Kluin681587c2008-04-23 23:59:36 +02001048 else
1049 port->irq = ret;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001050
1051 ourport->clk = clk_get(&platdev->dev, "uart");
1052
Linus Torvalds1da177e2005-04-16 15:20:36 -07001053 dbg("port: map=%08x, mem=%08x, irq=%d, clock=%ld\n",
1054 port->mapbase, port->membase, port->irq, port->uartclk);
1055
1056 /* reset the fifos (and setup the uart) */
1057 s3c24xx_serial_resetport(port, cfg);
1058 return 0;
1059}
1060
1061/* Device driver serial port probe */
1062
1063static int probe_index = 0;
1064
Russell King3ae5eae2005-11-09 22:32:44 +00001065static int s3c24xx_serial_probe(struct platform_device *dev,
Ben Dooks17efa642005-10-12 19:58:06 +01001066 struct s3c24xx_uart_info *info)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001067{
1068 struct s3c24xx_uart_port *ourport;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001069 int ret;
1070
Russell King3ae5eae2005-11-09 22:32:44 +00001071 dbg("s3c24xx_serial_probe(%p, %p) %d\n", dev, info, probe_index);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001072
1073 ourport = &s3c24xx_serial_ports[probe_index];
1074 probe_index++;
1075
Harvey Harrison71cc2c22008-04-30 00:55:10 -07001076 dbg("%s: initialising port %p...\n", __func__, ourport);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001077
1078 ret = s3c24xx_serial_init_port(ourport, info, dev);
1079 if (ret < 0)
1080 goto probe_err;
1081
Harvey Harrison71cc2c22008-04-30 00:55:10 -07001082 dbg("%s: adding port\n", __func__);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001083 uart_add_one_port(&s3c24xx_uart_drv, &ourport->port);
Russell King3ae5eae2005-11-09 22:32:44 +00001084 platform_set_drvdata(dev, &ourport->port);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001085
1086 return 0;
1087
1088 probe_err:
1089 return ret;
1090}
1091
Russell King3ae5eae2005-11-09 22:32:44 +00001092static int s3c24xx_serial_remove(struct platform_device *dev)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001093{
Russell King3ae5eae2005-11-09 22:32:44 +00001094 struct uart_port *port = s3c24xx_dev_to_port(&dev->dev);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001095
1096 if (port)
1097 uart_remove_one_port(&s3c24xx_uart_drv, port);
1098
1099 return 0;
1100}
1101
1102/* UART power management code */
1103
1104#ifdef CONFIG_PM
1105
Russell King3ae5eae2005-11-09 22:32:44 +00001106static int s3c24xx_serial_suspend(struct platform_device *dev, pm_message_t state)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001107{
Russell King3ae5eae2005-11-09 22:32:44 +00001108 struct uart_port *port = s3c24xx_dev_to_port(&dev->dev);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001109
Russell King9480e302005-10-28 09:52:56 -07001110 if (port)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001111 uart_suspend_port(&s3c24xx_uart_drv, port);
1112
1113 return 0;
1114}
1115
Russell King3ae5eae2005-11-09 22:32:44 +00001116static int s3c24xx_serial_resume(struct platform_device *dev)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001117{
Russell King3ae5eae2005-11-09 22:32:44 +00001118 struct uart_port *port = s3c24xx_dev_to_port(&dev->dev);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001119 struct s3c24xx_uart_port *ourport = to_ourport(port);
1120
Russell King9480e302005-10-28 09:52:56 -07001121 if (port) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001122 clk_enable(ourport->clk);
1123 s3c24xx_serial_resetport(port, s3c24xx_port_to_cfg(port));
1124 clk_disable(ourport->clk);
1125
1126 uart_resume_port(&s3c24xx_uart_drv, port);
1127 }
1128
1129 return 0;
1130}
1131
1132#else
1133#define s3c24xx_serial_suspend NULL
1134#define s3c24xx_serial_resume NULL
1135#endif
1136
Russell King3ae5eae2005-11-09 22:32:44 +00001137static int s3c24xx_serial_init(struct platform_driver *drv,
Ben Dooks17efa642005-10-12 19:58:06 +01001138 struct s3c24xx_uart_info *info)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001139{
1140 dbg("s3c24xx_serial_init(%p,%p)\n", drv, info);
Russell King3ae5eae2005-11-09 22:32:44 +00001141 return platform_driver_register(drv);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001142}
1143
1144
1145/* now comes the code to initialise either the s3c2410 or s3c2440 serial
1146 * port information
1147*/
1148
1149/* cpu specific variations on the serial port support */
1150
1151#ifdef CONFIG_CPU_S3C2400
1152
1153static int s3c2400_serial_getsource(struct uart_port *port,
1154 struct s3c24xx_uart_clksrc *clk)
1155{
1156 clk->divisor = 1;
1157 clk->name = "pclk";
1158
1159 return 0;
1160}
1161
1162static int s3c2400_serial_setsource(struct uart_port *port,
1163 struct s3c24xx_uart_clksrc *clk)
1164{
1165 return 0;
1166}
1167
1168static int s3c2400_serial_resetport(struct uart_port *port,
1169 struct s3c2410_uartcfg *cfg)
1170{
1171 dbg("s3c2400_serial_resetport: port=%p (%08lx), cfg=%p\n",
1172 port, port->mapbase, cfg);
1173
1174 wr_regl(port, S3C2410_UCON, cfg->ucon);
1175 wr_regl(port, S3C2410_ULCON, cfg->ulcon);
1176
1177 /* reset both fifos */
1178
1179 wr_regl(port, S3C2410_UFCON, cfg->ufcon | S3C2410_UFCON_RESETBOTH);
1180 wr_regl(port, S3C2410_UFCON, cfg->ufcon);
1181
1182 return 0;
1183}
1184
1185static struct s3c24xx_uart_info s3c2400_uart_inf = {
1186 .name = "Samsung S3C2400 UART",
1187 .type = PORT_S3C2400,
1188 .fifosize = 16,
1189 .rx_fifomask = S3C2410_UFSTAT_RXMASK,
1190 .rx_fifoshift = S3C2410_UFSTAT_RXSHIFT,
1191 .rx_fifofull = S3C2410_UFSTAT_RXFULL,
1192 .tx_fifofull = S3C2410_UFSTAT_TXFULL,
1193 .tx_fifomask = S3C2410_UFSTAT_TXMASK,
1194 .tx_fifoshift = S3C2410_UFSTAT_TXSHIFT,
1195 .get_clksrc = s3c2400_serial_getsource,
1196 .set_clksrc = s3c2400_serial_setsource,
1197 .reset_port = s3c2400_serial_resetport,
1198};
1199
Russell King3ae5eae2005-11-09 22:32:44 +00001200static int s3c2400_serial_probe(struct platform_device *dev)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001201{
1202 return s3c24xx_serial_probe(dev, &s3c2400_uart_inf);
1203}
1204
Russell King3ae5eae2005-11-09 22:32:44 +00001205static struct platform_driver s3c2400_serial_drv = {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001206 .probe = s3c2400_serial_probe,
1207 .remove = s3c24xx_serial_remove,
1208 .suspend = s3c24xx_serial_suspend,
1209 .resume = s3c24xx_serial_resume,
Russell King3ae5eae2005-11-09 22:32:44 +00001210 .driver = {
1211 .name = "s3c2400-uart",
1212 .owner = THIS_MODULE,
1213 },
Linus Torvalds1da177e2005-04-16 15:20:36 -07001214};
1215
1216static inline int s3c2400_serial_init(void)
1217{
1218 return s3c24xx_serial_init(&s3c2400_serial_drv, &s3c2400_uart_inf);
1219}
1220
1221static inline void s3c2400_serial_exit(void)
1222{
Russell King3ae5eae2005-11-09 22:32:44 +00001223 platform_driver_unregister(&s3c2400_serial_drv);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001224}
1225
1226#define s3c2400_uart_inf_at &s3c2400_uart_inf
1227#else
1228
1229static inline int s3c2400_serial_init(void)
1230{
1231 return 0;
1232}
1233
1234static inline void s3c2400_serial_exit(void)
1235{
1236}
1237
1238#define s3c2400_uart_inf_at NULL
1239
1240#endif /* CONFIG_CPU_S3C2400 */
1241
1242/* S3C2410 support */
1243
1244#ifdef CONFIG_CPU_S3C2410
1245
1246static int s3c2410_serial_setsource(struct uart_port *port,
1247 struct s3c24xx_uart_clksrc *clk)
1248{
1249 unsigned long ucon = rd_regl(port, S3C2410_UCON);
1250
1251 if (strcmp(clk->name, "uclk") == 0)
1252 ucon |= S3C2410_UCON_UCLK;
1253 else
1254 ucon &= ~S3C2410_UCON_UCLK;
1255
1256 wr_regl(port, S3C2410_UCON, ucon);
1257 return 0;
1258}
1259
1260static int s3c2410_serial_getsource(struct uart_port *port,
1261 struct s3c24xx_uart_clksrc *clk)
1262{
1263 unsigned long ucon = rd_regl(port, S3C2410_UCON);
1264
1265 clk->divisor = 1;
1266 clk->name = (ucon & S3C2410_UCON_UCLK) ? "uclk" : "pclk";
1267
1268 return 0;
1269}
1270
1271static int s3c2410_serial_resetport(struct uart_port *port,
1272 struct s3c2410_uartcfg *cfg)
1273{
1274 dbg("s3c2410_serial_resetport: port=%p (%08lx), cfg=%p\n",
1275 port, port->mapbase, cfg);
1276
1277 wr_regl(port, S3C2410_UCON, cfg->ucon);
1278 wr_regl(port, S3C2410_ULCON, cfg->ulcon);
1279
1280 /* reset both fifos */
1281
1282 wr_regl(port, S3C2410_UFCON, cfg->ufcon | S3C2410_UFCON_RESETBOTH);
1283 wr_regl(port, S3C2410_UFCON, cfg->ufcon);
1284
1285 return 0;
1286}
1287
1288static struct s3c24xx_uart_info s3c2410_uart_inf = {
1289 .name = "Samsung S3C2410 UART",
1290 .type = PORT_S3C2410,
1291 .fifosize = 16,
1292 .rx_fifomask = S3C2410_UFSTAT_RXMASK,
1293 .rx_fifoshift = S3C2410_UFSTAT_RXSHIFT,
1294 .rx_fifofull = S3C2410_UFSTAT_RXFULL,
1295 .tx_fifofull = S3C2410_UFSTAT_TXFULL,
1296 .tx_fifomask = S3C2410_UFSTAT_TXMASK,
1297 .tx_fifoshift = S3C2410_UFSTAT_TXSHIFT,
1298 .get_clksrc = s3c2410_serial_getsource,
1299 .set_clksrc = s3c2410_serial_setsource,
1300 .reset_port = s3c2410_serial_resetport,
1301};
1302
1303/* device management */
1304
Russell King3ae5eae2005-11-09 22:32:44 +00001305static int s3c2410_serial_probe(struct platform_device *dev)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001306{
1307 return s3c24xx_serial_probe(dev, &s3c2410_uart_inf);
1308}
1309
Russell King3ae5eae2005-11-09 22:32:44 +00001310static struct platform_driver s3c2410_serial_drv = {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001311 .probe = s3c2410_serial_probe,
1312 .remove = s3c24xx_serial_remove,
1313 .suspend = s3c24xx_serial_suspend,
1314 .resume = s3c24xx_serial_resume,
Russell King3ae5eae2005-11-09 22:32:44 +00001315 .driver = {
1316 .name = "s3c2410-uart",
1317 .owner = THIS_MODULE,
1318 },
Linus Torvalds1da177e2005-04-16 15:20:36 -07001319};
1320
1321static inline int s3c2410_serial_init(void)
1322{
1323 return s3c24xx_serial_init(&s3c2410_serial_drv, &s3c2410_uart_inf);
1324}
1325
1326static inline void s3c2410_serial_exit(void)
1327{
Russell King3ae5eae2005-11-09 22:32:44 +00001328 platform_driver_unregister(&s3c2410_serial_drv);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001329}
1330
1331#define s3c2410_uart_inf_at &s3c2410_uart_inf
1332#else
1333
1334static inline int s3c2410_serial_init(void)
1335{
1336 return 0;
1337}
1338
1339static inline void s3c2410_serial_exit(void)
1340{
1341}
1342
1343#define s3c2410_uart_inf_at NULL
1344
1345#endif /* CONFIG_CPU_S3C2410 */
1346
Ben Dooks96ce2382006-06-18 23:06:41 +01001347#if defined(CONFIG_CPU_S3C2440) || defined(CONFIG_CPU_S3C2442)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001348
1349static int s3c2440_serial_setsource(struct uart_port *port,
1350 struct s3c24xx_uart_clksrc *clk)
1351{
1352 unsigned long ucon = rd_regl(port, S3C2410_UCON);
1353
1354 // todo - proper fclk<>nonfclk switch //
1355
1356 ucon &= ~S3C2440_UCON_CLKMASK;
1357
1358 if (strcmp(clk->name, "uclk") == 0)
1359 ucon |= S3C2440_UCON_UCLK;
1360 else if (strcmp(clk->name, "pclk") == 0)
1361 ucon |= S3C2440_UCON_PCLK;
1362 else if (strcmp(clk->name, "fclk") == 0)
1363 ucon |= S3C2440_UCON_FCLK;
1364 else {
1365 printk(KERN_ERR "unknown clock source %s\n", clk->name);
1366 return -EINVAL;
1367 }
1368
1369 wr_regl(port, S3C2410_UCON, ucon);
1370 return 0;
1371}
1372
1373
1374static int s3c2440_serial_getsource(struct uart_port *port,
1375 struct s3c24xx_uart_clksrc *clk)
1376{
1377 unsigned long ucon = rd_regl(port, S3C2410_UCON);
1378 unsigned long ucon0, ucon1, ucon2;
1379
1380 switch (ucon & S3C2440_UCON_CLKMASK) {
1381 case S3C2440_UCON_UCLK:
1382 clk->divisor = 1;
1383 clk->name = "uclk";
1384 break;
1385
1386 case S3C2440_UCON_PCLK:
1387 case S3C2440_UCON_PCLK2:
1388 clk->divisor = 1;
1389 clk->name = "pclk";
1390 break;
1391
1392 case S3C2440_UCON_FCLK:
1393 /* the fun of calculating the uart divisors on
1394 * the s3c2440 */
1395
1396 ucon0 = __raw_readl(S3C24XX_VA_UART0 + S3C2410_UCON);
1397 ucon1 = __raw_readl(S3C24XX_VA_UART1 + S3C2410_UCON);
1398 ucon2 = __raw_readl(S3C24XX_VA_UART2 + S3C2410_UCON);
1399
1400 printk("ucons: %08lx, %08lx, %08lx\n", ucon0, ucon1, ucon2);
1401
1402 ucon0 &= S3C2440_UCON0_DIVMASK;
1403 ucon1 &= S3C2440_UCON1_DIVMASK;
1404 ucon2 &= S3C2440_UCON2_DIVMASK;
1405
1406 if (ucon0 != 0) {
1407 clk->divisor = ucon0 >> S3C2440_UCON_DIVSHIFT;
1408 clk->divisor += 6;
1409 } else if (ucon1 != 0) {
1410 clk->divisor = ucon1 >> S3C2440_UCON_DIVSHIFT;
1411 clk->divisor += 21;
1412 } else if (ucon2 != 0) {
1413 clk->divisor = ucon2 >> S3C2440_UCON_DIVSHIFT;
1414 clk->divisor += 36;
1415 } else {
1416 /* manual calims 44, seems to be 9 */
1417 clk->divisor = 9;
1418 }
1419
1420 clk->name = "fclk";
1421 break;
1422 }
1423
1424 return 0;
1425}
1426
1427static int s3c2440_serial_resetport(struct uart_port *port,
1428 struct s3c2410_uartcfg *cfg)
1429{
1430 unsigned long ucon = rd_regl(port, S3C2410_UCON);
1431
1432 dbg("s3c2440_serial_resetport: port=%p (%08lx), cfg=%p\n",
1433 port, port->mapbase, cfg);
1434
1435 /* ensure we don't change the clock settings... */
1436
1437 ucon &= (S3C2440_UCON0_DIVMASK | (3<<10));
1438
1439 wr_regl(port, S3C2410_UCON, ucon | cfg->ucon);
1440 wr_regl(port, S3C2410_ULCON, cfg->ulcon);
1441
1442 /* reset both fifos */
1443
1444 wr_regl(port, S3C2410_UFCON, cfg->ufcon | S3C2410_UFCON_RESETBOTH);
1445 wr_regl(port, S3C2410_UFCON, cfg->ufcon);
1446
1447 return 0;
1448}
1449
1450static struct s3c24xx_uart_info s3c2440_uart_inf = {
1451 .name = "Samsung S3C2440 UART",
1452 .type = PORT_S3C2440,
1453 .fifosize = 64,
1454 .rx_fifomask = S3C2440_UFSTAT_RXMASK,
1455 .rx_fifoshift = S3C2440_UFSTAT_RXSHIFT,
1456 .rx_fifofull = S3C2440_UFSTAT_RXFULL,
1457 .tx_fifofull = S3C2440_UFSTAT_TXFULL,
1458 .tx_fifomask = S3C2440_UFSTAT_TXMASK,
1459 .tx_fifoshift = S3C2440_UFSTAT_TXSHIFT,
1460 .get_clksrc = s3c2440_serial_getsource,
1461 .set_clksrc = s3c2440_serial_setsource,
1462 .reset_port = s3c2440_serial_resetport,
1463};
1464
1465/* device management */
1466
Russell King3ae5eae2005-11-09 22:32:44 +00001467static int s3c2440_serial_probe(struct platform_device *dev)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001468{
1469 dbg("s3c2440_serial_probe: dev=%p\n", dev);
1470 return s3c24xx_serial_probe(dev, &s3c2440_uart_inf);
1471}
1472
Russell King3ae5eae2005-11-09 22:32:44 +00001473static struct platform_driver s3c2440_serial_drv = {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001474 .probe = s3c2440_serial_probe,
1475 .remove = s3c24xx_serial_remove,
1476 .suspend = s3c24xx_serial_suspend,
1477 .resume = s3c24xx_serial_resume,
Russell King3ae5eae2005-11-09 22:32:44 +00001478 .driver = {
1479 .name = "s3c2440-uart",
1480 .owner = THIS_MODULE,
1481 },
Linus Torvalds1da177e2005-04-16 15:20:36 -07001482};
1483
1484
1485static inline int s3c2440_serial_init(void)
1486{
1487 return s3c24xx_serial_init(&s3c2440_serial_drv, &s3c2440_uart_inf);
1488}
1489
1490static inline void s3c2440_serial_exit(void)
1491{
Russell King3ae5eae2005-11-09 22:32:44 +00001492 platform_driver_unregister(&s3c2440_serial_drv);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001493}
1494
1495#define s3c2440_uart_inf_at &s3c2440_uart_inf
1496#else
1497
1498static inline int s3c2440_serial_init(void)
1499{
1500 return 0;
1501}
1502
1503static inline void s3c2440_serial_exit(void)
1504{
1505}
1506
1507#define s3c2440_uart_inf_at NULL
1508#endif /* CONFIG_CPU_S3C2440 */
1509
Jiri Olsa14527502008-02-04 22:27:48 -08001510#if defined(CONFIG_CPU_S3C2412)
Ben Dooks73e55cb2006-06-24 21:21:32 +01001511
1512static int s3c2412_serial_setsource(struct uart_port *port,
1513 struct s3c24xx_uart_clksrc *clk)
1514{
1515 unsigned long ucon = rd_regl(port, S3C2410_UCON);
1516
1517 ucon &= ~S3C2412_UCON_CLKMASK;
1518
1519 if (strcmp(clk->name, "uclk") == 0)
1520 ucon |= S3C2440_UCON_UCLK;
1521 else if (strcmp(clk->name, "pclk") == 0)
1522 ucon |= S3C2440_UCON_PCLK;
1523 else if (strcmp(clk->name, "usysclk") == 0)
1524 ucon |= S3C2412_UCON_USYSCLK;
1525 else {
1526 printk(KERN_ERR "unknown clock source %s\n", clk->name);
1527 return -EINVAL;
1528 }
1529
1530 wr_regl(port, S3C2410_UCON, ucon);
1531 return 0;
1532}
1533
1534
1535static int s3c2412_serial_getsource(struct uart_port *port,
1536 struct s3c24xx_uart_clksrc *clk)
1537{
1538 unsigned long ucon = rd_regl(port, S3C2410_UCON);
1539
1540 switch (ucon & S3C2412_UCON_CLKMASK) {
1541 case S3C2412_UCON_UCLK:
1542 clk->divisor = 1;
1543 clk->name = "uclk";
1544 break;
1545
1546 case S3C2412_UCON_PCLK:
1547 case S3C2412_UCON_PCLK2:
1548 clk->divisor = 1;
1549 clk->name = "pclk";
1550 break;
1551
1552 case S3C2412_UCON_USYSCLK:
1553 clk->divisor = 1;
1554 clk->name = "usysclk";
1555 break;
1556 }
1557
1558 return 0;
1559}
1560
1561static int s3c2412_serial_resetport(struct uart_port *port,
1562 struct s3c2410_uartcfg *cfg)
1563{
1564 unsigned long ucon = rd_regl(port, S3C2410_UCON);
1565
1566 dbg("%s: port=%p (%08lx), cfg=%p\n",
Harvey Harrison71cc2c22008-04-30 00:55:10 -07001567 __func__, port, port->mapbase, cfg);
Ben Dooks73e55cb2006-06-24 21:21:32 +01001568
1569 /* ensure we don't change the clock settings... */
1570
1571 ucon &= S3C2412_UCON_CLKMASK;
1572
1573 wr_regl(port, S3C2410_UCON, ucon | cfg->ucon);
1574 wr_regl(port, S3C2410_ULCON, cfg->ulcon);
1575
1576 /* reset both fifos */
1577
1578 wr_regl(port, S3C2410_UFCON, cfg->ufcon | S3C2410_UFCON_RESETBOTH);
1579 wr_regl(port, S3C2410_UFCON, cfg->ufcon);
1580
1581 return 0;
1582}
1583
1584static struct s3c24xx_uart_info s3c2412_uart_inf = {
1585 .name = "Samsung S3C2412 UART",
1586 .type = PORT_S3C2412,
1587 .fifosize = 64,
1588 .rx_fifomask = S3C2440_UFSTAT_RXMASK,
1589 .rx_fifoshift = S3C2440_UFSTAT_RXSHIFT,
1590 .rx_fifofull = S3C2440_UFSTAT_RXFULL,
1591 .tx_fifofull = S3C2440_UFSTAT_TXFULL,
1592 .tx_fifomask = S3C2440_UFSTAT_TXMASK,
1593 .tx_fifoshift = S3C2440_UFSTAT_TXSHIFT,
1594 .get_clksrc = s3c2412_serial_getsource,
1595 .set_clksrc = s3c2412_serial_setsource,
1596 .reset_port = s3c2412_serial_resetport,
1597};
1598
1599/* device management */
1600
1601static int s3c2412_serial_probe(struct platform_device *dev)
1602{
1603 dbg("s3c2440_serial_probe: dev=%p\n", dev);
Ben Dooks71aa7052006-09-18 13:30:17 +01001604 return s3c24xx_serial_probe(dev, &s3c2412_uart_inf);
Ben Dooks73e55cb2006-06-24 21:21:32 +01001605}
1606
1607static struct platform_driver s3c2412_serial_drv = {
1608 .probe = s3c2412_serial_probe,
1609 .remove = s3c24xx_serial_remove,
1610 .suspend = s3c24xx_serial_suspend,
1611 .resume = s3c24xx_serial_resume,
1612 .driver = {
1613 .name = "s3c2412-uart",
1614 .owner = THIS_MODULE,
1615 },
1616};
1617
1618
1619static inline int s3c2412_serial_init(void)
1620{
1621 return s3c24xx_serial_init(&s3c2412_serial_drv, &s3c2412_uart_inf);
1622}
1623
1624static inline void s3c2412_serial_exit(void)
1625{
1626 platform_driver_unregister(&s3c2412_serial_drv);
1627}
1628
1629#define s3c2412_uart_inf_at &s3c2412_uart_inf
1630#else
1631
1632static inline int s3c2412_serial_init(void)
1633{
1634 return 0;
1635}
1636
1637static inline void s3c2412_serial_exit(void)
1638{
1639}
1640
1641#define s3c2412_uart_inf_at NULL
1642#endif /* CONFIG_CPU_S3C2440 */
1643
1644
Linus Torvalds1da177e2005-04-16 15:20:36 -07001645/* module initialisation code */
1646
1647static int __init s3c24xx_serial_modinit(void)
1648{
1649 int ret;
1650
1651 ret = uart_register_driver(&s3c24xx_uart_drv);
1652 if (ret < 0) {
1653 printk(KERN_ERR "failed to register UART driver\n");
1654 return -1;
1655 }
1656
1657 s3c2400_serial_init();
1658 s3c2410_serial_init();
Ben Dooks73e55cb2006-06-24 21:21:32 +01001659 s3c2412_serial_init();
Linus Torvalds1da177e2005-04-16 15:20:36 -07001660 s3c2440_serial_init();
1661
1662 return 0;
1663}
1664
1665static void __exit s3c24xx_serial_modexit(void)
1666{
1667 s3c2400_serial_exit();
1668 s3c2410_serial_exit();
Ben Dooks73e55cb2006-06-24 21:21:32 +01001669 s3c2412_serial_exit();
Linus Torvalds1da177e2005-04-16 15:20:36 -07001670 s3c2440_serial_exit();
1671
1672 uart_unregister_driver(&s3c24xx_uart_drv);
1673}
1674
1675
1676module_init(s3c24xx_serial_modinit);
1677module_exit(s3c24xx_serial_modexit);
1678
1679/* Console code */
1680
1681#ifdef CONFIG_SERIAL_S3C2410_CONSOLE
1682
1683static struct uart_port *cons_uart;
1684
1685static int
1686s3c24xx_serial_console_txrdy(struct uart_port *port, unsigned int ufcon)
1687{
1688 struct s3c24xx_uart_info *info = s3c24xx_port_to_info(port);
1689 unsigned long ufstat, utrstat;
1690
1691 if (ufcon & S3C2410_UFCON_FIFOMODE) {
1692 /* fifo mode - check ammount of data in fifo registers... */
1693
1694 ufstat = rd_regl(port, S3C2410_UFSTAT);
1695 return (ufstat & info->tx_fifofull) ? 0 : 1;
1696 }
1697
1698 /* in non-fifo mode, we go and use the tx buffer empty */
1699
1700 utrstat = rd_regl(port, S3C2410_UTRSTAT);
1701 return (utrstat & S3C2410_UTRSTAT_TXE) ? 1 : 0;
1702}
1703
1704static void
Russell Kingd3587882006-03-20 20:00:09 +00001705s3c24xx_serial_console_putchar(struct uart_port *port, int ch)
1706{
1707 unsigned int ufcon = rd_regl(cons_uart, S3C2410_UFCON);
1708 while (!s3c24xx_serial_console_txrdy(port, ufcon))
1709 barrier();
1710 wr_regb(cons_uart, S3C2410_UTXH, ch);
1711}
1712
1713static void
Linus Torvalds1da177e2005-04-16 15:20:36 -07001714s3c24xx_serial_console_write(struct console *co, const char *s,
1715 unsigned int count)
1716{
Russell Kingd3587882006-03-20 20:00:09 +00001717 uart_console_write(cons_uart, s, count, s3c24xx_serial_console_putchar);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001718}
1719
1720static void __init
1721s3c24xx_serial_get_options(struct uart_port *port, int *baud,
1722 int *parity, int *bits)
1723{
1724 struct s3c24xx_uart_clksrc clksrc;
1725 struct clk *clk;
1726 unsigned int ulcon;
1727 unsigned int ucon;
1728 unsigned int ubrdiv;
1729 unsigned long rate;
1730
1731 ulcon = rd_regl(port, S3C2410_ULCON);
1732 ucon = rd_regl(port, S3C2410_UCON);
1733 ubrdiv = rd_regl(port, S3C2410_UBRDIV);
1734
1735 dbg("s3c24xx_serial_get_options: port=%p\n"
1736 "registers: ulcon=%08x, ucon=%08x, ubdriv=%08x\n",
1737 port, ulcon, ucon, ubrdiv);
1738
1739 if ((ucon & 0xf) != 0) {
1740 /* consider the serial port configured if the tx/rx mode set */
1741
1742 switch (ulcon & S3C2410_LCON_CSMASK) {
1743 case S3C2410_LCON_CS5:
1744 *bits = 5;
1745 break;
1746 case S3C2410_LCON_CS6:
1747 *bits = 6;
1748 break;
1749 case S3C2410_LCON_CS7:
1750 *bits = 7;
1751 break;
1752 default:
1753 case S3C2410_LCON_CS8:
1754 *bits = 8;
1755 break;
1756 }
1757
1758 switch (ulcon & S3C2410_LCON_PMASK) {
1759 case S3C2410_LCON_PEVEN:
1760 *parity = 'e';
1761 break;
1762
1763 case S3C2410_LCON_PODD:
1764 *parity = 'o';
1765 break;
1766
1767 case S3C2410_LCON_PNONE:
1768 default:
1769 *parity = 'n';
1770 }
1771
1772 /* now calculate the baud rate */
1773
1774 s3c24xx_serial_getsource(port, &clksrc);
1775
1776 clk = clk_get(port->dev, clksrc.name);
1777 if (!IS_ERR(clk) && clk != NULL)
1778 rate = clk_get_rate(clk) / clksrc.divisor;
1779 else
1780 rate = 1;
1781
1782
1783 *baud = rate / ( 16 * (ubrdiv + 1));
1784 dbg("calculated baud %d\n", *baud);
1785 }
1786
1787}
1788
1789/* s3c24xx_serial_init_ports
1790 *
1791 * initialise the serial ports from the machine provided initialisation
1792 * data.
1793*/
1794
1795static int s3c24xx_serial_init_ports(struct s3c24xx_uart_info *info)
1796{
1797 struct s3c24xx_uart_port *ptr = s3c24xx_serial_ports;
1798 struct platform_device **platdev_ptr;
1799 int i;
1800
1801 dbg("s3c24xx_serial_init_ports: initialising ports...\n");
1802
1803 platdev_ptr = s3c24xx_uart_devs;
1804
1805 for (i = 0; i < NR_PORTS; i++, ptr++, platdev_ptr++) {
1806 s3c24xx_serial_init_port(ptr, info, *platdev_ptr);
1807 }
1808
1809 return 0;
1810}
1811
1812static int __init
1813s3c24xx_serial_console_setup(struct console *co, char *options)
1814{
1815 struct uart_port *port;
1816 int baud = 9600;
1817 int bits = 8;
1818 int parity = 'n';
1819 int flow = 'n';
1820
1821 dbg("s3c24xx_serial_console_setup: co=%p (%d), %s\n",
1822 co, co->index, options);
1823
1824 /* is this a valid port */
1825
1826 if (co->index == -1 || co->index >= NR_PORTS)
1827 co->index = 0;
1828
1829 port = &s3c24xx_serial_ports[co->index].port;
1830
1831 /* is the port configured? */
1832
1833 if (port->mapbase == 0x0) {
1834 co->index = 0;
1835 port = &s3c24xx_serial_ports[co->index].port;
1836 }
1837
1838 cons_uart = port;
1839
1840 dbg("s3c24xx_serial_console_setup: port=%p (%d)\n", port, co->index);
1841
1842 /*
1843 * Check whether an invalid uart number has been specified, and
1844 * if so, search for the first available port that does have
1845 * console support.
1846 */
1847 if (options)
1848 uart_parse_options(options, &baud, &parity, &bits, &flow);
1849 else
1850 s3c24xx_serial_get_options(port, &baud, &parity, &bits);
1851
1852 dbg("s3c24xx_serial_console_setup: baud %d\n", baud);
1853
1854 return uart_set_options(port, co, baud, parity, bits, flow);
1855}
1856
1857/* s3c24xx_serial_initconsole
1858 *
1859 * initialise the console from one of the uart drivers
1860*/
1861
1862static struct console s3c24xx_serial_console =
1863{
1864 .name = S3C24XX_SERIAL_NAME,
1865 .device = uart_console_device,
1866 .flags = CON_PRINTBUFFER,
1867 .index = -1,
1868 .write = s3c24xx_serial_console_write,
1869 .setup = s3c24xx_serial_console_setup
1870};
1871
1872static int s3c24xx_serial_initconsole(void)
1873{
1874 struct s3c24xx_uart_info *info;
1875 struct platform_device *dev = s3c24xx_uart_devs[0];
1876
1877 dbg("s3c24xx_serial_initconsole\n");
1878
1879 /* select driver based on the cpu */
1880
1881 if (dev == NULL) {
1882 printk(KERN_ERR "s3c24xx: no devices for console init\n");
1883 return 0;
1884 }
1885
1886 if (strcmp(dev->name, "s3c2400-uart") == 0) {
1887 info = s3c2400_uart_inf_at;
1888 } else if (strcmp(dev->name, "s3c2410-uart") == 0) {
1889 info = s3c2410_uart_inf_at;
1890 } else if (strcmp(dev->name, "s3c2440-uart") == 0) {
1891 info = s3c2440_uart_inf_at;
Ben Dooks73e55cb2006-06-24 21:21:32 +01001892 } else if (strcmp(dev->name, "s3c2412-uart") == 0) {
1893 info = s3c2412_uart_inf_at;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001894 } else {
1895 printk(KERN_ERR "s3c24xx: no driver for %s\n", dev->name);
1896 return 0;
1897 }
1898
1899 if (info == NULL) {
1900 printk(KERN_ERR "s3c24xx: no driver for console\n");
1901 return 0;
1902 }
1903
1904 s3c24xx_serial_console.data = &s3c24xx_uart_drv;
1905 s3c24xx_serial_init_ports(info);
1906
1907 register_console(&s3c24xx_serial_console);
1908 return 0;
1909}
1910
1911console_initcall(s3c24xx_serial_initconsole);
1912
1913#endif /* CONFIG_SERIAL_S3C2410_CONSOLE */
1914
Ben Dooks8fe059d2008-05-23 11:48:00 +01001915MODULE_LICENSE("GPL v2");
Linus Torvalds1da177e2005-04-16 15:20:36 -07001916MODULE_AUTHOR("Ben Dooks <ben@simtec.co.uk>");
Ben Dooks73e55cb2006-06-24 21:21:32 +01001917MODULE_DESCRIPTION("Samsung S3C2410/S3C2440/S3C2412 Serial port driver");
Kay Sieverse169c132008-04-15 14:34:35 -07001918MODULE_ALIAS("platform:s3c2400-uart");
1919MODULE_ALIAS("platform:s3c2410-uart");
1920MODULE_ALIAS("platform:s3c2412-uart");
1921MODULE_ALIAS("platform:s3c2440-uart");