5b85c1953c51bd607857ad2707bccb14e73b1c12
[platform/kernel/linux-starfive.git] / drivers / tty / serial / s3c2412.c
1 /*
2  * Driver for Samsung S3C2412 and S3C2413 SoC onboard UARTs.
3  *
4  * Ben Dooks, Copyright (c) 2003-2008 Simtec Electronics
5  *      http://armlinux.simtec.co.uk/
6  *
7  * This program is free software; you can redistribute it and/or modify
8  * it under the terms of the GNU General Public License version 2 as
9  * published by the Free Software Foundation.
10 */
11
12 #include <linux/module.h>
13 #include <linux/ioport.h>
14 #include <linux/io.h>
15 #include <linux/platform_device.h>
16 #include <linux/init.h>
17 #include <linux/serial_core.h>
18 #include <linux/serial.h>
19
20 #include <asm/irq.h>
21 #include <mach/hardware.h>
22
23 #include <plat/regs-serial.h>
24 #include <mach/regs-gpio.h>
25
26 #include "samsung.h"
27
28 static int s3c2412_serial_resetport(struct uart_port *port,
29                                     struct s3c2410_uartcfg *cfg)
30 {
31         unsigned long ucon = rd_regl(port, S3C2410_UCON);
32
33         dbg("%s: port=%p (%08lx), cfg=%p\n",
34             __func__, port, port->mapbase, cfg);
35
36         /* ensure we don't change the clock settings... */
37
38         ucon &= S3C2412_UCON_CLKMASK;
39
40         wr_regl(port, S3C2410_UCON,  ucon | cfg->ucon);
41         wr_regl(port, S3C2410_ULCON, cfg->ulcon);
42
43         /* reset both fifos */
44
45         wr_regl(port, S3C2410_UFCON, cfg->ufcon | S3C2410_UFCON_RESETBOTH);
46         wr_regl(port, S3C2410_UFCON, cfg->ufcon);
47
48         return 0;
49 }
50
51 static struct s3c24xx_uart_info s3c2412_uart_inf = {
52         .name           = "Samsung S3C2412 UART",
53         .type           = PORT_S3C2412,
54         .fifosize       = 64,
55         .has_divslot    = 1,
56         .rx_fifomask    = S3C2440_UFSTAT_RXMASK,
57         .rx_fifoshift   = S3C2440_UFSTAT_RXSHIFT,
58         .rx_fifofull    = S3C2440_UFSTAT_RXFULL,
59         .tx_fifofull    = S3C2440_UFSTAT_TXFULL,
60         .tx_fifomask    = S3C2440_UFSTAT_TXMASK,
61         .tx_fifoshift   = S3C2440_UFSTAT_TXSHIFT,
62         .def_clk_sel    = S3C2410_UCON_CLKSEL2,
63         .num_clks       = 4,
64         .clksel_mask    = S3C2412_UCON_CLKMASK,
65         .clksel_shift   = S3C2412_UCON_CLKSHIFT,
66         .reset_port     = s3c2412_serial_resetport,
67 };
68
69 /* device management */
70
71 static int s3c2412_serial_probe(struct platform_device *dev)
72 {
73         dbg("s3c2440_serial_probe: dev=%p\n", dev);
74         return s3c24xx_serial_probe(dev, &s3c2412_uart_inf);
75 }
76
77 static struct platform_driver s3c2412_serial_driver = {
78         .probe          = s3c2412_serial_probe,
79         .remove         = __devexit_p(s3c24xx_serial_remove),
80         .driver         = {
81                 .name   = "s3c2412-uart",
82                 .owner  = THIS_MODULE,
83         },
84 };
85
86 static inline int s3c2412_serial_init(void)
87 {
88         return s3c24xx_serial_init(&s3c2412_serial_driver, &s3c2412_uart_inf);
89 }
90
91 static inline void s3c2412_serial_exit(void)
92 {
93         platform_driver_unregister(&s3c2412_serial_driver);
94 }
95
96 module_init(s3c2412_serial_init);
97 module_exit(s3c2412_serial_exit);
98
99 MODULE_DESCRIPTION("Samsung S3C2412,S3C2413 SoC Serial port driver");
100 MODULE_AUTHOR("Ben Dooks <ben@simtec.co.uk>");
101 MODULE_LICENSE("GPL v2");
102 MODULE_ALIAS("platform:s3c2412-uart");