blob: 29dc6f529058538291b782e75aa5dddbb754eed5 [file] [log] [blame]
Tony Lindgren1dbae812005-11-10 14:26:51 +00001/*
Uwe Zeisbergerf30c2262006-10-03 23:01:26 +02002 * arch/arm/mach-omap2/serial.c
Tony Lindgren1dbae812005-11-10 14:26:51 +00003 *
4 * OMAP2 serial support.
5 *
Jouni Hogander6e811762008-10-06 15:49:15 +03006 * Copyright (C) 2005-2008 Nokia Corporation
Tony Lindgren1dbae812005-11-10 14:26:51 +00007 * Author: Paul Mundt <paul.mundt@nokia.com>
8 *
9 * Based off of arch/arm/mach-omap/omap1/serial.c
10 *
Santosh Shilimkar44169072009-05-28 14:16:04 -070011 * Copyright (C) 2009 Texas Instruments
12 * Added OMAP4 support - Santosh Shilimkar <santosh.shilimkar@ti.com
13 *
Tony Lindgren1dbae812005-11-10 14:26:51 +000014 * This file is subject to the terms and conditions of the GNU General Public
15 * License. See the file "COPYING" in the main directory of this archive
16 * for more details.
17 */
18#include <linux/kernel.h>
19#include <linux/init.h>
20#include <linux/serial_8250.h>
21#include <linux/serial_reg.h>
Russell Kingf8ce2542006-01-07 16:15:52 +000022#include <linux/clk.h>
Russell Kingfced80c2008-09-06 12:10:45 +010023#include <linux/io.h>
Tony Lindgren1dbae812005-11-10 14:26:51 +000024
Russell Kinga09e64f2008-08-05 16:14:15 +010025#include <mach/common.h>
26#include <mach/board.h>
Tony Lindgren1dbae812005-11-10 14:26:51 +000027
Jouni Hogander6e811762008-10-06 15:49:15 +030028static struct clk *uart_ick[OMAP_MAX_NR_PORTS];
29static struct clk *uart_fck[OMAP_MAX_NR_PORTS];
Tony Lindgren1dbae812005-11-10 14:26:51 +000030
31static struct plat_serial8250_port serial_platform_data[] = {
32 {
Russell Kinge8a91c92008-09-01 22:07:37 +010033 .membase = IO_ADDRESS(OMAP_UART1_BASE),
34 .mapbase = OMAP_UART1_BASE,
Tony Lindgren1dbae812005-11-10 14:26:51 +000035 .irq = 72,
36 .flags = UPF_BOOT_AUTOCONF,
37 .iotype = UPIO_MEM,
38 .regshift = 2,
Jouni Hogander6e811762008-10-06 15:49:15 +030039 .uartclk = OMAP24XX_BASE_BAUD * 16,
Tony Lindgren1dbae812005-11-10 14:26:51 +000040 }, {
Russell Kinge8a91c92008-09-01 22:07:37 +010041 .membase = IO_ADDRESS(OMAP_UART2_BASE),
42 .mapbase = OMAP_UART2_BASE,
Tony Lindgren1dbae812005-11-10 14:26:51 +000043 .irq = 73,
44 .flags = UPF_BOOT_AUTOCONF,
45 .iotype = UPIO_MEM,
46 .regshift = 2,
Jouni Hogander6e811762008-10-06 15:49:15 +030047 .uartclk = OMAP24XX_BASE_BAUD * 16,
Tony Lindgren1dbae812005-11-10 14:26:51 +000048 }, {
Russell Kinge8a91c92008-09-01 22:07:37 +010049 .membase = IO_ADDRESS(OMAP_UART3_BASE),
50 .mapbase = OMAP_UART3_BASE,
Tony Lindgren1dbae812005-11-10 14:26:51 +000051 .irq = 74,
52 .flags = UPF_BOOT_AUTOCONF,
53 .iotype = UPIO_MEM,
54 .regshift = 2,
Jouni Hogander6e811762008-10-06 15:49:15 +030055 .uartclk = OMAP24XX_BASE_BAUD * 16,
Tony Lindgren1dbae812005-11-10 14:26:51 +000056 }, {
57 .flags = 0
58 }
59};
60
61static inline unsigned int serial_read_reg(struct plat_serial8250_port *up,
62 int offset)
63{
64 offset <<= up->regshift;
65 return (unsigned int)__raw_readb(up->membase + offset);
66}
67
68static inline void serial_write_reg(struct plat_serial8250_port *p, int offset,
69 int value)
70{
71 offset <<= p->regshift;
Russell Kinge8a91c92008-09-01 22:07:37 +010072 __raw_writeb(value, p->membase + offset);
Tony Lindgren1dbae812005-11-10 14:26:51 +000073}
74
75/*
76 * Internal UARTs need to be initialized for the 8250 autoconfig to work
77 * properly. Note that the TX watermark initialization may not be needed
78 * once the 8250.c watermark handling code is merged.
79 */
80static inline void __init omap_serial_reset(struct plat_serial8250_port *p)
81{
82 serial_write_reg(p, UART_OMAP_MDR1, 0x07);
83 serial_write_reg(p, UART_OMAP_SCR, 0x08);
84 serial_write_reg(p, UART_OMAP_MDR1, 0x00);
Juha Yrjola671c7232006-12-06 17:13:49 -080085 serial_write_reg(p, UART_OMAP_SYSC, (0x02 << 3) | (1 << 2) | (1 << 0));
Tony Lindgren1dbae812005-11-10 14:26:51 +000086}
87
Jouni Hogander6e811762008-10-06 15:49:15 +030088void omap_serial_enable_clocks(int enable)
89{
90 int i;
91 for (i = 0; i < OMAP_MAX_NR_PORTS; i++) {
92 if (uart_ick[i] && uart_fck[i]) {
93 if (enable) {
94 clk_enable(uart_ick[i]);
95 clk_enable(uart_fck[i]);
96 } else {
97 clk_disable(uart_ick[i]);
98 clk_disable(uart_fck[i]);
99 }
100 }
101 }
102}
103
Vikram Pandita2aa57be2009-05-28 14:03:59 -0700104static struct platform_device serial_device = {
105 .name = "serial8250",
106 .id = PLAT8250_DEV_PLATFORM,
107 .dev = {
108 .platform_data = serial_platform_data,
109 },
110};
111
Jouni Hogander6e811762008-10-06 15:49:15 +0300112void __init omap_serial_init(void)
Tony Lindgren1dbae812005-11-10 14:26:51 +0000113{
114 int i;
115 const struct omap_uart_config *info;
Jouni Hogander6e811762008-10-06 15:49:15 +0300116 char name[16];
Tony Lindgren1dbae812005-11-10 14:26:51 +0000117
118 /*
119 * Make sure the serial ports are muxed on at this point.
120 * You have to mux them off in device drivers later on
121 * if not needed.
122 */
123
Jouni Hogander6e811762008-10-06 15:49:15 +0300124 info = omap_get_config(OMAP_TAG_UART, struct omap_uart_config);
Tony Lindgren1dbae812005-11-10 14:26:51 +0000125
126 if (info == NULL)
127 return;
Santosh Shilimkar44169072009-05-28 14:16:04 -0700128 if (cpu_is_omap44xx()) {
129 for (i = 0; i < OMAP_MAX_NR_PORTS; i++)
130 serial_platform_data[i].irq += 32;
131 }
Tony Lindgren1dbae812005-11-10 14:26:51 +0000132
133 for (i = 0; i < OMAP_MAX_NR_PORTS; i++) {
134 struct plat_serial8250_port *p = serial_platform_data + i;
135
136 if (!(info->enabled_uarts & (1 << i))) {
Russell Kingc0fc18c2008-09-05 15:10:27 +0100137 p->membase = NULL;
Tony Lindgren1dbae812005-11-10 14:26:51 +0000138 p->mapbase = 0;
139 continue;
140 }
141
Jouni Hogander6e811762008-10-06 15:49:15 +0300142 sprintf(name, "uart%d_ick", i+1);
143 uart_ick[i] = clk_get(NULL, name);
144 if (IS_ERR(uart_ick[i])) {
145 printk(KERN_ERR "Could not get uart%d_ick\n", i+1);
146 uart_ick[i] = NULL;
147 } else
148 clk_enable(uart_ick[i]);
Tony Lindgren1dbae812005-11-10 14:26:51 +0000149
Jouni Hogander6e811762008-10-06 15:49:15 +0300150 sprintf(name, "uart%d_fck", i+1);
151 uart_fck[i] = clk_get(NULL, name);
152 if (IS_ERR(uart_fck[i])) {
153 printk(KERN_ERR "Could not get uart%d_fck\n", i+1);
154 uart_fck[i] = NULL;
155 } else
156 clk_enable(uart_fck[i]);
Tony Lindgren1dbae812005-11-10 14:26:51 +0000157
158 omap_serial_reset(p);
159 }
Tony Lindgren1dbae812005-11-10 14:26:51 +0000160
Vikram Pandita2aa57be2009-05-28 14:03:59 -0700161 platform_device_register(&serial_device);
Tony Lindgren1dbae812005-11-10 14:26:51 +0000162}