Commit | Line | Data |
---|---|---|
99edb3d1 | 1 | /* |
d8512731 TA |
2 | * 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> | |
21 | ||
22 | #include <asm/irq.h> | |
23 | #include <mach/hardware.h> | |
24 | #include <plat/regs-serial.h> | |
25 | #include "samsung.h" | |
26 | ||
27 | static int s5pv210_serial_setsource(struct uart_port *port, | |
28 | struct s3c24xx_uart_clksrc *clk) | |
29 | { | |
acfdc56d | 30 | struct s3c2410_uartcfg *cfg = port->dev->platform_data; |
d8512731 TA |
31 | unsigned long ucon = rd_regl(port, S3C2410_UCON); |
32 | ||
470f2297 | 33 | if (cfg->flags & NO_NEED_CHECK_CLKSRC) |
acfdc56d JL |
34 | return 0; |
35 | ||
d8512731 TA |
36 | if (strcmp(clk->name, "pclk") == 0) |
37 | ucon &= ~S5PV210_UCON_CLKMASK; | |
38 | else if (strcmp(clk->name, "uclk1") == 0) | |
39 | ucon |= S5PV210_UCON_CLKMASK; | |
40 | else { | |
41 | printk(KERN_ERR "unknown clock source %s\n", clk->name); | |
42 | return -EINVAL; | |
43 | } | |
44 | ||
45 | wr_regl(port, S3C2410_UCON, ucon); | |
46 | return 0; | |
47 | } | |
48 | ||
49 | ||
50 | static int s5pv210_serial_getsource(struct uart_port *port, | |
51 | struct s3c24xx_uart_clksrc *clk) | |
52 | { | |
acfdc56d | 53 | struct s3c2410_uartcfg *cfg = port->dev->platform_data; |
d8512731 TA |
54 | u32 ucon = rd_regl(port, S3C2410_UCON); |
55 | ||
56 | clk->divisor = 1; | |
57 | ||
470f2297 | 58 | if (cfg->flags & NO_NEED_CHECK_CLKSRC) |
acfdc56d JL |
59 | return 0; |
60 | ||
d8512731 TA |
61 | switch (ucon & S5PV210_UCON_CLKMASK) { |
62 | case S5PV210_UCON_PCLK: | |
63 | clk->name = "pclk"; | |
64 | break; | |
65 | case S5PV210_UCON_UCLK: | |
66 | clk->name = "uclk1"; | |
67 | break; | |
68 | } | |
69 | ||
70 | return 0; | |
71 | } | |
72 | ||
73 | static int s5pv210_serial_resetport(struct uart_port *port, | |
74 | struct s3c2410_uartcfg *cfg) | |
75 | { | |
76 | unsigned long ucon = rd_regl(port, S3C2410_UCON); | |
77 | ||
78 | ucon &= S5PV210_UCON_CLKMASK; | |
79 | wr_regl(port, S3C2410_UCON, ucon | cfg->ucon); | |
80 | wr_regl(port, S3C2410_ULCON, cfg->ulcon); | |
81 | ||
82 | /* reset both fifos */ | |
83 | wr_regl(port, S3C2410_UFCON, cfg->ufcon | S3C2410_UFCON_RESETBOTH); | |
84 | wr_regl(port, S3C2410_UFCON, cfg->ufcon); | |
85 | ||
86 | return 0; | |
87 | } | |
88 | ||
89 | #define S5PV210_UART_DEFAULT_INFO(fifo_size) \ | |
90 | .name = "Samsung S5PV210 UART0", \ | |
91 | .type = PORT_S3C6400, \ | |
92 | .fifosize = fifo_size, \ | |
93 | .has_divslot = 1, \ | |
94 | .rx_fifomask = S5PV210_UFSTAT_RXMASK, \ | |
95 | .rx_fifoshift = S5PV210_UFSTAT_RXSHIFT, \ | |
96 | .rx_fifofull = S5PV210_UFSTAT_RXFULL, \ | |
97 | .tx_fifofull = S5PV210_UFSTAT_TXFULL, \ | |
98 | .tx_fifomask = S5PV210_UFSTAT_TXMASK, \ | |
99 | .tx_fifoshift = S5PV210_UFSTAT_TXSHIFT, \ | |
100 | .get_clksrc = s5pv210_serial_getsource, \ | |
101 | .set_clksrc = s5pv210_serial_setsource, \ | |
102 | .reset_port = s5pv210_serial_resetport | |
103 | ||
104 | static struct s3c24xx_uart_info s5p_port_fifo256 = { | |
105 | S5PV210_UART_DEFAULT_INFO(256), | |
106 | }; | |
107 | ||
108 | static struct s3c24xx_uart_info s5p_port_fifo64 = { | |
109 | S5PV210_UART_DEFAULT_INFO(64), | |
110 | }; | |
111 | ||
112 | static struct s3c24xx_uart_info s5p_port_fifo16 = { | |
113 | S5PV210_UART_DEFAULT_INFO(16), | |
114 | }; | |
115 | ||
116 | static struct s3c24xx_uart_info *s5p_uart_inf[] = { | |
117 | [0] = &s5p_port_fifo256, | |
118 | [1] = &s5p_port_fifo64, | |
119 | [2] = &s5p_port_fifo16, | |
120 | [3] = &s5p_port_fifo16, | |
121 | }; | |
122 | ||
123 | /* device management */ | |
124 | static int s5p_serial_probe(struct platform_device *pdev) | |
125 | { | |
126 | return s3c24xx_serial_probe(pdev, s5p_uart_inf[pdev->id]); | |
127 | } | |
128 | ||
5d66ceee | 129 | static struct platform_driver s5p_serial_driver = { |
d8512731 TA |
130 | .probe = s5p_serial_probe, |
131 | .remove = __devexit_p(s3c24xx_serial_remove), | |
132 | .driver = { | |
133 | .name = "s5pv210-uart", | |
134 | .owner = THIS_MODULE, | |
135 | }, | |
136 | }; | |
137 | ||
138 | static int __init s5pv210_serial_console_init(void) | |
139 | { | |
5d66ceee | 140 | return s3c24xx_serial_initconsole(&s5p_serial_driver, s5p_uart_inf); |
d8512731 TA |
141 | } |
142 | ||
143 | console_initcall(s5pv210_serial_console_init); | |
144 | ||
145 | static int __init s5p_serial_init(void) | |
146 | { | |
5d66ceee | 147 | return s3c24xx_serial_init(&s5p_serial_driver, *s5p_uart_inf); |
d8512731 TA |
148 | } |
149 | ||
150 | static void __exit s5p_serial_exit(void) | |
151 | { | |
5d66ceee | 152 | platform_driver_unregister(&s5p_serial_driver); |
d8512731 TA |
153 | } |
154 | ||
155 | module_init(s5p_serial_init); | |
156 | module_exit(s5p_serial_exit); | |
157 | ||
158 | MODULE_LICENSE("GPL"); | |
159 | MODULE_ALIAS("platform:s5pv210-uart"); | |
160 | MODULE_DESCRIPTION("Samsung S5PV210 UART Driver support"); | |
161 | MODULE_AUTHOR("Thomas Abraham <thomas.ab@samsung.com>"); |