blob: 8b0b888a1b7671f119df2dbbf0dd7146226fe9f2 [file] [log] [blame]
Jovi Zhang99edb3d2011-03-30 05:30:41 -04001/*
Thomas Abrahamd8512732010-01-22 10:50:42 +09002 * Copyright (c) 2010 Samsung Electronics Co., Ltd.
3 * http://www.samsung.com/
4 *
5 * Based on drivers/serial/s3c6400.c
6 *
7 * Driver for Samsung S5PV210 SoC UARTs.
8 *
9 * This program is free software; you can redistribute it and/or modify
10 * it under the terms of the GNU General Public License version 2 as
11 * published by the Free Software Foundation.
12*/
13
14#include <linux/module.h>
15#include <linux/ioport.h>
16#include <linux/io.h>
17#include <linux/platform_device.h>
18#include <linux/init.h>
19#include <linux/serial_core.h>
20#include <linux/serial.h>
Jongpill Lee40eb0de2011-06-22 17:50:25 +090021#include <linux/delay.h>
Thomas Abrahamd8512732010-01-22 10:50:42 +090022
23#include <asm/irq.h>
24#include <mach/hardware.h>
25#include <plat/regs-serial.h>
26#include "samsung.h"
27
28static int s5pv210_serial_setsource(struct uart_port *port,
29 struct s3c24xx_uart_clksrc *clk)
30{
Jongpill Leeacfdc562010-07-16 15:07:37 +090031 struct s3c2410_uartcfg *cfg = port->dev->platform_data;
Thomas Abrahamd8512732010-01-22 10:50:42 +090032 unsigned long ucon = rd_regl(port, S3C2410_UCON);
33
Boojin Kim470f2292011-05-27 19:04:03 -070034 if (cfg->flags & NO_NEED_CHECK_CLKSRC)
Jongpill Leeacfdc562010-07-16 15:07:37 +090035 return 0;
36
Thomas Abrahamd8512732010-01-22 10:50:42 +090037 if (strcmp(clk->name, "pclk") == 0)
38 ucon &= ~S5PV210_UCON_CLKMASK;
39 else if (strcmp(clk->name, "uclk1") == 0)
40 ucon |= S5PV210_UCON_CLKMASK;
41 else {
42 printk(KERN_ERR "unknown clock source %s\n", clk->name);
43 return -EINVAL;
44 }
45
46 wr_regl(port, S3C2410_UCON, ucon);
47 return 0;
48}
49
50
51static int s5pv210_serial_getsource(struct uart_port *port,
52 struct s3c24xx_uart_clksrc *clk)
53{
Jongpill Leeacfdc562010-07-16 15:07:37 +090054 struct s3c2410_uartcfg *cfg = port->dev->platform_data;
Thomas Abrahamd8512732010-01-22 10:50:42 +090055 u32 ucon = rd_regl(port, S3C2410_UCON);
56
57 clk->divisor = 1;
58
Boojin Kim470f2292011-05-27 19:04:03 -070059 if (cfg->flags & NO_NEED_CHECK_CLKSRC)
Jongpill Leeacfdc562010-07-16 15:07:37 +090060 return 0;
61
Thomas Abrahamd8512732010-01-22 10:50:42 +090062 switch (ucon & S5PV210_UCON_CLKMASK) {
63 case S5PV210_UCON_PCLK:
64 clk->name = "pclk";
65 break;
66 case S5PV210_UCON_UCLK:
67 clk->name = "uclk1";
68 break;
69 }
70
71 return 0;
72}
73
74static int s5pv210_serial_resetport(struct uart_port *port,
75 struct s3c2410_uartcfg *cfg)
76{
77 unsigned long ucon = rd_regl(port, S3C2410_UCON);
78
79 ucon &= S5PV210_UCON_CLKMASK;
80 wr_regl(port, S3C2410_UCON, ucon | cfg->ucon);
81 wr_regl(port, S3C2410_ULCON, cfg->ulcon);
82
83 /* reset both fifos */
84 wr_regl(port, S3C2410_UFCON, cfg->ufcon | S3C2410_UFCON_RESETBOTH);
85 wr_regl(port, S3C2410_UFCON, cfg->ufcon);
86
Jongpill Lee40eb0de2011-06-22 17:50:25 +090087 /* It is need to delay When reset FIFO register */
88 udelay(1);
89
Thomas Abrahamd8512732010-01-22 10:50:42 +090090 return 0;
91}
92
93#define S5PV210_UART_DEFAULT_INFO(fifo_size) \
94 .name = "Samsung S5PV210 UART0", \
95 .type = PORT_S3C6400, \
96 .fifosize = fifo_size, \
97 .has_divslot = 1, \
98 .rx_fifomask = S5PV210_UFSTAT_RXMASK, \
99 .rx_fifoshift = S5PV210_UFSTAT_RXSHIFT, \
100 .rx_fifofull = S5PV210_UFSTAT_RXFULL, \
101 .tx_fifofull = S5PV210_UFSTAT_TXFULL, \
102 .tx_fifomask = S5PV210_UFSTAT_TXMASK, \
103 .tx_fifoshift = S5PV210_UFSTAT_TXSHIFT, \
104 .get_clksrc = s5pv210_serial_getsource, \
105 .set_clksrc = s5pv210_serial_setsource, \
106 .reset_port = s5pv210_serial_resetport
107
108static struct s3c24xx_uart_info s5p_port_fifo256 = {
109 S5PV210_UART_DEFAULT_INFO(256),
110};
111
112static struct s3c24xx_uart_info s5p_port_fifo64 = {
113 S5PV210_UART_DEFAULT_INFO(64),
114};
115
116static struct s3c24xx_uart_info s5p_port_fifo16 = {
117 S5PV210_UART_DEFAULT_INFO(16),
118};
119
120static struct s3c24xx_uart_info *s5p_uart_inf[] = {
121 [0] = &s5p_port_fifo256,
122 [1] = &s5p_port_fifo64,
123 [2] = &s5p_port_fifo16,
124 [3] = &s5p_port_fifo16,
125};
126
127/* device management */
128static int s5p_serial_probe(struct platform_device *pdev)
129{
130 return s3c24xx_serial_probe(pdev, s5p_uart_inf[pdev->id]);
131}
132
Marek Szyprowski5d66cee2010-05-28 19:21:11 +0900133static struct platform_driver s5p_serial_driver = {
Thomas Abrahamd8512732010-01-22 10:50:42 +0900134 .probe = s5p_serial_probe,
135 .remove = __devexit_p(s3c24xx_serial_remove),
136 .driver = {
137 .name = "s5pv210-uart",
138 .owner = THIS_MODULE,
139 },
140};
141
Thomas Abrahamd8512732010-01-22 10:50:42 +0900142static int __init s5p_serial_init(void)
143{
Marek Szyprowski5d66cee2010-05-28 19:21:11 +0900144 return s3c24xx_serial_init(&s5p_serial_driver, *s5p_uart_inf);
Thomas Abrahamd8512732010-01-22 10:50:42 +0900145}
146
147static void __exit s5p_serial_exit(void)
148{
Marek Szyprowski5d66cee2010-05-28 19:21:11 +0900149 platform_driver_unregister(&s5p_serial_driver);
Thomas Abrahamd8512732010-01-22 10:50:42 +0900150}
151
152module_init(s5p_serial_init);
153module_exit(s5p_serial_exit);
154
155MODULE_LICENSE("GPL");
156MODULE_ALIAS("platform:s5pv210-uart");
157MODULE_DESCRIPTION("Samsung S5PV210 UART Driver support");
158MODULE_AUTHOR("Thomas Abraham <thomas.ab@samsung.com>");