blob: bffe6ff9b1589d5d7a35bb5726d2476f2a5dead5 [file] [log] [blame]
Jovi Zhang99edb3d2011-03-30 05:30:41 -04001/*
Ben Dooksb4975492008-07-03 12:32:51 +01002 * Driver for Samsung S3C2410 SoC onboard UARTs.
Linus Torvalds1da177e2005-04-16 15:20:36 -07003 *
Ben Dooksccae9412009-11-13 22:54:14 +00004 * Ben Dooks, Copyright (c) 2003-2008 Simtec Electronics
Ben Dooks05a78962008-05-22 16:36:45 +01005 * http://armlinux.simtec.co.uk/
Ben Dooks8fe059d2008-05-23 11:48:00 +01006 *
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.
Linus Torvalds1da177e2005-04-16 15:20:36 -070010*/
11
Linus Torvalds1da177e2005-04-16 15:20:36 -070012#include <linux/module.h>
13#include <linux/ioport.h>
Ben Dooksb4975492008-07-03 12:32:51 +010014#include <linux/io.h>
Russell Kingd052d1b2005-10-29 19:07:23 +010015#include <linux/platform_device.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070016#include <linux/init.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070017#include <linux/serial_core.h>
18#include <linux/serial.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070019
Linus Torvalds1da177e2005-04-16 15:20:36 -070020#include <asm/irq.h>
Russell Kinga09e64f2008-08-05 16:14:15 +010021#include <mach/hardware.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070022
Ben Dooksa2b7ba92008-10-07 22:26:09 +010023#include <plat/regs-serial.h>
Russell Kinga09e64f2008-08-05 16:14:15 +010024#include <mach/regs-gpio.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070025
Ben Dooksb4975492008-07-03 12:32:51 +010026#include "samsung.h"
Linus Torvalds1da177e2005-04-16 15:20:36 -070027
28static int s3c2410_serial_setsource(struct uart_port *port,
29 struct s3c24xx_uart_clksrc *clk)
30{
31 unsigned long ucon = rd_regl(port, S3C2410_UCON);
32
33 if (strcmp(clk->name, "uclk") == 0)
34 ucon |= S3C2410_UCON_UCLK;
35 else
36 ucon &= ~S3C2410_UCON_UCLK;
37
38 wr_regl(port, S3C2410_UCON, ucon);
39 return 0;
40}
41
42static int s3c2410_serial_getsource(struct uart_port *port,
43 struct s3c24xx_uart_clksrc *clk)
44{
45 unsigned long ucon = rd_regl(port, S3C2410_UCON);
46
47 clk->divisor = 1;
48 clk->name = (ucon & S3C2410_UCON_UCLK) ? "uclk" : "pclk";
49
50 return 0;
51}
52
53static int s3c2410_serial_resetport(struct uart_port *port,
54 struct s3c2410_uartcfg *cfg)
55{
56 dbg("s3c2410_serial_resetport: port=%p (%08lx), cfg=%p\n",
57 port, port->mapbase, cfg);
58
59 wr_regl(port, S3C2410_UCON, cfg->ucon);
60 wr_regl(port, S3C2410_ULCON, cfg->ulcon);
61
62 /* reset both fifos */
63
64 wr_regl(port, S3C2410_UFCON, cfg->ufcon | S3C2410_UFCON_RESETBOTH);
65 wr_regl(port, S3C2410_UFCON, cfg->ufcon);
66
67 return 0;
68}
69
70static struct s3c24xx_uart_info s3c2410_uart_inf = {
71 .name = "Samsung S3C2410 UART",
72 .type = PORT_S3C2410,
73 .fifosize = 16,
74 .rx_fifomask = S3C2410_UFSTAT_RXMASK,
75 .rx_fifoshift = S3C2410_UFSTAT_RXSHIFT,
76 .rx_fifofull = S3C2410_UFSTAT_RXFULL,
77 .tx_fifofull = S3C2410_UFSTAT_TXFULL,
78 .tx_fifomask = S3C2410_UFSTAT_TXMASK,
79 .tx_fifoshift = S3C2410_UFSTAT_TXSHIFT,
80 .get_clksrc = s3c2410_serial_getsource,
81 .set_clksrc = s3c2410_serial_setsource,
82 .reset_port = s3c2410_serial_resetport,
83};
84
Russell King3ae5eae2005-11-09 22:32:44 +000085static int s3c2410_serial_probe(struct platform_device *dev)
Linus Torvalds1da177e2005-04-16 15:20:36 -070086{
87 return s3c24xx_serial_probe(dev, &s3c2410_uart_inf);
88}
89
Ramax Lo8fe70a52009-07-09 16:28:33 +080090static struct platform_driver s3c2410_serial_driver = {
Linus Torvalds1da177e2005-04-16 15:20:36 -070091 .probe = s3c2410_serial_probe,
Peter Korsgaard90ceb9642009-06-22 18:42:49 +010092 .remove = __devexit_p(s3c24xx_serial_remove),
Russell King3ae5eae2005-11-09 22:32:44 +000093 .driver = {
94 .name = "s3c2410-uart",
95 .owner = THIS_MODULE,
96 },
Linus Torvalds1da177e2005-04-16 15:20:36 -070097};
98
Ramax Lo8fe70a52009-07-09 16:28:33 +080099s3c24xx_console_init(&s3c2410_serial_driver, &s3c2410_uart_inf);
Ben Dooksb4975492008-07-03 12:32:51 +0100100
101static int __init s3c2410_serial_init(void)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700102{
Ramax Lo8fe70a52009-07-09 16:28:33 +0800103 return s3c24xx_serial_init(&s3c2410_serial_driver, &s3c2410_uart_inf);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700104}
105
Ben Dooksb4975492008-07-03 12:32:51 +0100106static void __exit s3c2410_serial_exit(void)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700107{
Ramax Lo8fe70a52009-07-09 16:28:33 +0800108 platform_driver_unregister(&s3c2410_serial_driver);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700109}
110
Ben Dooksb4975492008-07-03 12:32:51 +0100111module_init(s3c2410_serial_init);
112module_exit(s3c2410_serial_exit);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700113
Ben Dooks8fe059d2008-05-23 11:48:00 +0100114MODULE_LICENSE("GPL v2");
Linus Torvalds1da177e2005-04-16 15:20:36 -0700115MODULE_AUTHOR("Ben Dooks <ben@simtec.co.uk>");
Ben Dooksb4975492008-07-03 12:32:51 +0100116MODULE_DESCRIPTION("Samsung S3C2410 SoC Serial port driver");
Kay Sieverse169c132008-04-15 14:34:35 -0700117MODULE_ALIAS("platform:s3c2410-uart");