1 /* linux/drivers/serial/s3c2440.c
3 * Driver for Samsung S3C2440 and S3C2442 SoC onboard UARTs.
5 * Ben Dooks, Copyright (c) 2003-2005,2008 Simtec Electronics
6 * http://armlinux.simtec.co.uk/
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.
13 #include <linux/module.h>
14 #include <linux/ioport.h>
16 #include <linux/platform_device.h>
17 #include <linux/init.h>
18 #include <linux/serial_core.h>
19 #include <linux/serial.h>
22 #include <mach/hardware.h>
24 #include <plat/regs-serial.h>
25 #include <mach/regs-gpio.h>
30 static int s3c2440_serial_setsource(struct uart_port
*port
,
31 struct s3c24xx_uart_clksrc
*clk
)
33 unsigned long ucon
= rd_regl(port
, S3C2410_UCON
);
35 /* todo - proper fclk<>nonfclk switch. */
37 ucon
&= ~S3C2440_UCON_CLKMASK
;
39 if (strcmp(clk
->name
, "uclk") == 0)
40 ucon
|= S3C2440_UCON_UCLK
;
41 else if (strcmp(clk
->name
, "pclk") == 0)
42 ucon
|= S3C2440_UCON_PCLK
;
43 else if (strcmp(clk
->name
, "fclk") == 0)
44 ucon
|= S3C2440_UCON_FCLK
;
46 printk(KERN_ERR
"unknown clock source %s\n", clk
->name
);
50 wr_regl(port
, S3C2410_UCON
, ucon
);
55 static int s3c2440_serial_getsource(struct uart_port
*port
,
56 struct s3c24xx_uart_clksrc
*clk
)
58 unsigned long ucon
= rd_regl(port
, S3C2410_UCON
);
59 unsigned long ucon0
, ucon1
, ucon2
;
61 switch (ucon
& S3C2440_UCON_CLKMASK
) {
62 case S3C2440_UCON_UCLK
:
67 case S3C2440_UCON_PCLK
:
68 case S3C2440_UCON_PCLK2
:
73 case S3C2440_UCON_FCLK
:
74 /* the fun of calculating the uart divisors on
77 ucon0
= __raw_readl(S3C24XX_VA_UART0
+ S3C2410_UCON
);
78 ucon1
= __raw_readl(S3C24XX_VA_UART1
+ S3C2410_UCON
);
79 ucon2
= __raw_readl(S3C24XX_VA_UART2
+ S3C2410_UCON
);
81 printk("ucons: %08lx, %08lx, %08lx\n", ucon0
, ucon1
, ucon2
);
83 ucon0
&= S3C2440_UCON0_DIVMASK
;
84 ucon1
&= S3C2440_UCON1_DIVMASK
;
85 ucon2
&= S3C2440_UCON2_DIVMASK
;
88 clk
->divisor
= ucon0
>> S3C2440_UCON_DIVSHIFT
;
90 } else if (ucon1
!= 0) {
91 clk
->divisor
= ucon1
>> S3C2440_UCON_DIVSHIFT
;
93 } else if (ucon2
!= 0) {
94 clk
->divisor
= ucon2
>> S3C2440_UCON_DIVSHIFT
;
97 /* manual calims 44, seems to be 9 */
108 static int s3c2440_serial_resetport(struct uart_port
*port
,
109 struct s3c2410_uartcfg
*cfg
)
111 unsigned long ucon
= rd_regl(port
, S3C2410_UCON
);
113 dbg("s3c2440_serial_resetport: port=%p (%08lx), cfg=%p\n",
114 port
, port
->mapbase
, cfg
);
116 /* ensure we don't change the clock settings... */
118 ucon
&= (S3C2440_UCON0_DIVMASK
| (3<<10));
120 wr_regl(port
, S3C2410_UCON
, ucon
| cfg
->ucon
);
121 wr_regl(port
, S3C2410_ULCON
, cfg
->ulcon
);
123 /* reset both fifos */
125 wr_regl(port
, S3C2410_UFCON
, cfg
->ufcon
| S3C2410_UFCON_RESETBOTH
);
126 wr_regl(port
, S3C2410_UFCON
, cfg
->ufcon
);
131 static struct s3c24xx_uart_info s3c2440_uart_inf
= {
132 .name
= "Samsung S3C2440 UART",
133 .type
= PORT_S3C2440
,
135 .rx_fifomask
= S3C2440_UFSTAT_RXMASK
,
136 .rx_fifoshift
= S3C2440_UFSTAT_RXSHIFT
,
137 .rx_fifofull
= S3C2440_UFSTAT_RXFULL
,
138 .tx_fifofull
= S3C2440_UFSTAT_TXFULL
,
139 .tx_fifomask
= S3C2440_UFSTAT_TXMASK
,
140 .tx_fifoshift
= S3C2440_UFSTAT_TXSHIFT
,
141 .get_clksrc
= s3c2440_serial_getsource
,
142 .set_clksrc
= s3c2440_serial_setsource
,
143 .reset_port
= s3c2440_serial_resetport
,
146 /* device management */
148 static int s3c2440_serial_probe(struct platform_device
*dev
)
150 dbg("s3c2440_serial_probe: dev=%p\n", dev
);
151 return s3c24xx_serial_probe(dev
, &s3c2440_uart_inf
);
154 static struct platform_driver s3c2440_serial_driver
= {
155 .probe
= s3c2440_serial_probe
,
156 .remove
= __devexit_p(s3c24xx_serial_remove
),
158 .name
= "s3c2440-uart",
159 .owner
= THIS_MODULE
,
163 s3c24xx_console_init(&s3c2440_serial_driver
, &s3c2440_uart_inf
);
165 static int __init
s3c2440_serial_init(void)
167 return s3c24xx_serial_init(&s3c2440_serial_driver
, &s3c2440_uart_inf
);
170 static void __exit
s3c2440_serial_exit(void)
172 platform_driver_unregister(&s3c2440_serial_driver
);
175 module_init(s3c2440_serial_init
);
176 module_exit(s3c2440_serial_exit
);
178 MODULE_DESCRIPTION("Samsung S3C2440,S3C2442 SoC Serial port driver");
179 MODULE_AUTHOR("Ben Dooks <ben@simtec.co.uk>");
180 MODULE_LICENSE("GPL v2");
181 MODULE_ALIAS("platform:s3c2440-uart");