2 * arch/arm/mach-omap2/serial.c
4 * OMAP2 serial support.
6 * Copyright (C) 2005 Nokia Corporation
7 * Author: Paul Mundt <paul.mundt@nokia.com>
9 * Based off of arch/arm/mach-omap/omap1/serial.c
11 * This file is subject to the terms and conditions of the GNU General Public
12 * License. See the file "COPYING" in the main directory of this archive
15 #include <linux/kernel.h>
16 #include <linux/init.h>
17 #include <linux/serial_8250.h>
18 #include <linux/serial_reg.h>
19 #include <linux/clk.h>
23 #include <asm/arch/common.h>
24 #include <asm/arch/board.h>
26 static struct clk * uart1_ick = NULL;
27 static struct clk * uart1_fck = NULL;
28 static struct clk * uart2_ick = NULL;
29 static struct clk * uart2_fck = NULL;
30 static struct clk * uart3_ick = NULL;
31 static struct clk * uart3_fck = NULL;
33 static struct plat_serial8250_port serial_platform_data[] = {
35 .membase = (char *)IO_ADDRESS(OMAP_UART1_BASE),
36 .mapbase = (unsigned long)OMAP_UART1_BASE,
38 .flags = UPF_BOOT_AUTOCONF,
41 .uartclk = OMAP24XX_BASE_BAUD * 16,
43 .membase = (char *)IO_ADDRESS(OMAP_UART2_BASE),
44 .mapbase = (unsigned long)OMAP_UART2_BASE,
46 .flags = UPF_BOOT_AUTOCONF,
49 .uartclk = OMAP24XX_BASE_BAUD * 16,
51 .membase = (char *)IO_ADDRESS(OMAP_UART3_BASE),
52 .mapbase = (unsigned long)OMAP_UART3_BASE,
54 .flags = UPF_BOOT_AUTOCONF,
57 .uartclk = OMAP24XX_BASE_BAUD * 16,
63 static inline unsigned int serial_read_reg(struct plat_serial8250_port *up,
66 offset <<= up->regshift;
67 return (unsigned int)__raw_readb(up->membase + offset);
70 static inline void serial_write_reg(struct plat_serial8250_port *p, int offset,
73 offset <<= p->regshift;
74 __raw_writeb(value, (unsigned long)(p->membase + offset));
78 * Internal UARTs need to be initialized for the 8250 autoconfig to work
79 * properly. Note that the TX watermark initialization may not be needed
80 * once the 8250.c watermark handling code is merged.
82 static inline void __init omap_serial_reset(struct plat_serial8250_port *p)
84 serial_write_reg(p, UART_OMAP_MDR1, 0x07);
85 serial_write_reg(p, UART_OMAP_SCR, 0x08);
86 serial_write_reg(p, UART_OMAP_MDR1, 0x00);
87 serial_write_reg(p, UART_OMAP_SYSC, (0x02 << 3) | (1 << 2) | (1 << 0));
90 void __init omap_serial_init(void)
93 const struct omap_uart_config *info;
96 * Make sure the serial ports are muxed on at this point.
97 * You have to mux them off in device drivers later on
101 info = omap_get_config(OMAP_TAG_UART, struct omap_uart_config);
106 for (i = 0; i < OMAP_MAX_NR_PORTS; i++) {
107 struct plat_serial8250_port *p = serial_platform_data + i;
109 if (!(info->enabled_uarts & (1 << i))) {
117 uart1_ick = clk_get(NULL, "uart1_ick");
118 if (IS_ERR(uart1_ick))
119 printk("Could not get uart1_ick\n");
121 clk_enable(uart1_ick);
123 uart1_fck = clk_get(NULL, "uart1_fck");
124 if (IS_ERR(uart1_fck))
125 printk("Could not get uart1_fck\n");
127 clk_enable(uart1_fck);
130 uart2_ick = clk_get(NULL, "uart2_ick");
131 if (IS_ERR(uart2_ick))
132 printk("Could not get uart2_ick\n");
134 clk_enable(uart2_ick);
136 uart2_fck = clk_get(NULL, "uart2_fck");
137 if (IS_ERR(uart2_fck))
138 printk("Could not get uart2_fck\n");
140 clk_enable(uart2_fck);
143 uart3_ick = clk_get(NULL, "uart3_ick");
144 if (IS_ERR(uart3_ick))
145 printk("Could not get uart3_ick\n");
147 clk_enable(uart3_ick);
149 uart3_fck = clk_get(NULL, "uart3_fck");
150 if (IS_ERR(uart3_fck))
151 printk("Could not get uart3_fck\n");
153 clk_enable(uart3_fck);
157 omap_serial_reset(p);
161 static struct platform_device serial_device = {
162 .name = "serial8250",
163 .id = PLAT8250_DEV_PLATFORM,
165 .platform_data = serial_platform_data,
169 static int __init omap_init(void)
171 return platform_device_register(&serial_device);
173 arch_initcall(omap_init);