Thomas Abraham | d851273 | 2010-01-22 10:50:42 +0900 | [diff] [blame] | 1 | /* linux/drivers/serial/s5pv210.c |
| 2 | * |
| 3 | * Copyright (c) 2010 Samsung Electronics Co., Ltd. |
| 4 | * http://www.samsung.com/ |
| 5 | * |
| 6 | * Based on drivers/serial/s3c6400.c |
| 7 | * |
| 8 | * Driver for Samsung S5PV210 SoC UARTs. |
| 9 | * |
| 10 | * This program is free software; you can redistribute it and/or modify |
| 11 | * it under the terms of the GNU General Public License version 2 as |
| 12 | * published by the Free Software Foundation. |
| 13 | */ |
| 14 | |
| 15 | #include <linux/module.h> |
| 16 | #include <linux/ioport.h> |
| 17 | #include <linux/io.h> |
| 18 | #include <linux/platform_device.h> |
| 19 | #include <linux/init.h> |
| 20 | #include <linux/serial_core.h> |
| 21 | #include <linux/serial.h> |
| 22 | |
| 23 | #include <asm/irq.h> |
| 24 | #include <mach/hardware.h> |
| 25 | #include <plat/regs-serial.h> |
| 26 | #include "samsung.h" |
| 27 | |
| 28 | static int s5pv210_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, "pclk") == 0) |
| 34 | ucon &= ~S5PV210_UCON_CLKMASK; |
| 35 | else if (strcmp(clk->name, "uclk1") == 0) |
| 36 | ucon |= S5PV210_UCON_CLKMASK; |
| 37 | else { |
| 38 | printk(KERN_ERR "unknown clock source %s\n", clk->name); |
| 39 | return -EINVAL; |
| 40 | } |
| 41 | |
| 42 | wr_regl(port, S3C2410_UCON, ucon); |
| 43 | return 0; |
| 44 | } |
| 45 | |
| 46 | |
| 47 | static int s5pv210_serial_getsource(struct uart_port *port, |
| 48 | struct s3c24xx_uart_clksrc *clk) |
| 49 | { |
| 50 | u32 ucon = rd_regl(port, S3C2410_UCON); |
| 51 | |
| 52 | clk->divisor = 1; |
| 53 | |
| 54 | switch (ucon & S5PV210_UCON_CLKMASK) { |
| 55 | case S5PV210_UCON_PCLK: |
| 56 | clk->name = "pclk"; |
| 57 | break; |
| 58 | case S5PV210_UCON_UCLK: |
| 59 | clk->name = "uclk1"; |
| 60 | break; |
| 61 | } |
| 62 | |
| 63 | return 0; |
| 64 | } |
| 65 | |
| 66 | static int s5pv210_serial_resetport(struct uart_port *port, |
| 67 | struct s3c2410_uartcfg *cfg) |
| 68 | { |
| 69 | unsigned long ucon = rd_regl(port, S3C2410_UCON); |
| 70 | |
| 71 | ucon &= S5PV210_UCON_CLKMASK; |
| 72 | wr_regl(port, S3C2410_UCON, ucon | cfg->ucon); |
| 73 | wr_regl(port, S3C2410_ULCON, cfg->ulcon); |
| 74 | |
| 75 | /* reset both fifos */ |
| 76 | wr_regl(port, S3C2410_UFCON, cfg->ufcon | S3C2410_UFCON_RESETBOTH); |
| 77 | wr_regl(port, S3C2410_UFCON, cfg->ufcon); |
| 78 | |
| 79 | return 0; |
| 80 | } |
| 81 | |
| 82 | #define S5PV210_UART_DEFAULT_INFO(fifo_size) \ |
| 83 | .name = "Samsung S5PV210 UART0", \ |
| 84 | .type = PORT_S3C6400, \ |
| 85 | .fifosize = fifo_size, \ |
| 86 | .has_divslot = 1, \ |
| 87 | .rx_fifomask = S5PV210_UFSTAT_RXMASK, \ |
| 88 | .rx_fifoshift = S5PV210_UFSTAT_RXSHIFT, \ |
| 89 | .rx_fifofull = S5PV210_UFSTAT_RXFULL, \ |
| 90 | .tx_fifofull = S5PV210_UFSTAT_TXFULL, \ |
| 91 | .tx_fifomask = S5PV210_UFSTAT_TXMASK, \ |
| 92 | .tx_fifoshift = S5PV210_UFSTAT_TXSHIFT, \ |
| 93 | .get_clksrc = s5pv210_serial_getsource, \ |
| 94 | .set_clksrc = s5pv210_serial_setsource, \ |
| 95 | .reset_port = s5pv210_serial_resetport |
| 96 | |
| 97 | static struct s3c24xx_uart_info s5p_port_fifo256 = { |
| 98 | S5PV210_UART_DEFAULT_INFO(256), |
| 99 | }; |
| 100 | |
| 101 | static struct s3c24xx_uart_info s5p_port_fifo64 = { |
| 102 | S5PV210_UART_DEFAULT_INFO(64), |
| 103 | }; |
| 104 | |
| 105 | static struct s3c24xx_uart_info s5p_port_fifo16 = { |
| 106 | S5PV210_UART_DEFAULT_INFO(16), |
| 107 | }; |
| 108 | |
| 109 | static struct s3c24xx_uart_info *s5p_uart_inf[] = { |
| 110 | [0] = &s5p_port_fifo256, |
| 111 | [1] = &s5p_port_fifo64, |
| 112 | [2] = &s5p_port_fifo16, |
| 113 | [3] = &s5p_port_fifo16, |
| 114 | }; |
| 115 | |
| 116 | /* device management */ |
| 117 | static int s5p_serial_probe(struct platform_device *pdev) |
| 118 | { |
| 119 | return s3c24xx_serial_probe(pdev, s5p_uart_inf[pdev->id]); |
| 120 | } |
| 121 | |
| 122 | static struct platform_driver s5p_serial_drv = { |
| 123 | .probe = s5p_serial_probe, |
| 124 | .remove = __devexit_p(s3c24xx_serial_remove), |
| 125 | .driver = { |
| 126 | .name = "s5pv210-uart", |
| 127 | .owner = THIS_MODULE, |
| 128 | }, |
| 129 | }; |
| 130 | |
| 131 | static int __init s5pv210_serial_console_init(void) |
| 132 | { |
| 133 | return s3c24xx_serial_initconsole(&s5p_serial_drv, s5p_uart_inf); |
| 134 | } |
| 135 | |
| 136 | console_initcall(s5pv210_serial_console_init); |
| 137 | |
| 138 | static int __init s5p_serial_init(void) |
| 139 | { |
| 140 | return s3c24xx_serial_init(&s5p_serial_drv, *s5p_uart_inf); |
| 141 | } |
| 142 | |
| 143 | static void __exit s5p_serial_exit(void) |
| 144 | { |
| 145 | platform_driver_unregister(&s5p_serial_drv); |
| 146 | } |
| 147 | |
| 148 | module_init(s5p_serial_init); |
| 149 | module_exit(s5p_serial_exit); |
| 150 | |
| 151 | MODULE_LICENSE("GPL"); |
| 152 | MODULE_ALIAS("platform:s5pv210-uart"); |
| 153 | MODULE_DESCRIPTION("Samsung S5PV210 UART Driver support"); |
| 154 | MODULE_AUTHOR("Thomas Abraham <thomas.ab@samsung.com>"); |