Tony Lindgren | 1dbae81 | 2005-11-10 14:26:51 +0000 | [diff] [blame] | 1 | /* |
Uwe Zeisberger | f30c226 | 2006-10-03 23:01:26 +0200 | [diff] [blame] | 2 | * arch/arm/mach-omap2/serial.c |
Tony Lindgren | 1dbae81 | 2005-11-10 14:26:51 +0000 | [diff] [blame] | 3 | * |
| 4 | * OMAP2 serial support. |
| 5 | * |
Jouni Hogander | 6e81176 | 2008-10-06 15:49:15 +0300 | [diff] [blame] | 6 | * Copyright (C) 2005-2008 Nokia Corporation |
Tony Lindgren | 1dbae81 | 2005-11-10 14:26:51 +0000 | [diff] [blame] | 7 | * Author: Paul Mundt <paul.mundt@nokia.com> |
| 8 | * |
| 9 | * Based off of arch/arm/mach-omap/omap1/serial.c |
| 10 | * |
Santosh Shilimkar | 4416907 | 2009-05-28 14:16:04 -0700 | [diff] [blame^] | 11 | * Copyright (C) 2009 Texas Instruments |
| 12 | * Added OMAP4 support - Santosh Shilimkar <santosh.shilimkar@ti.com |
| 13 | * |
Tony Lindgren | 1dbae81 | 2005-11-10 14:26:51 +0000 | [diff] [blame] | 14 | * 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 King | f8ce254 | 2006-01-07 16:15:52 +0000 | [diff] [blame] | 22 | #include <linux/clk.h> |
Russell King | fced80c | 2008-09-06 12:10:45 +0100 | [diff] [blame] | 23 | #include <linux/io.h> |
Tony Lindgren | 1dbae81 | 2005-11-10 14:26:51 +0000 | [diff] [blame] | 24 | |
Russell King | a09e64f | 2008-08-05 16:14:15 +0100 | [diff] [blame] | 25 | #include <mach/common.h> |
| 26 | #include <mach/board.h> |
Tony Lindgren | 1dbae81 | 2005-11-10 14:26:51 +0000 | [diff] [blame] | 27 | |
Jouni Hogander | 6e81176 | 2008-10-06 15:49:15 +0300 | [diff] [blame] | 28 | static struct clk *uart_ick[OMAP_MAX_NR_PORTS]; |
| 29 | static struct clk *uart_fck[OMAP_MAX_NR_PORTS]; |
Tony Lindgren | 1dbae81 | 2005-11-10 14:26:51 +0000 | [diff] [blame] | 30 | |
| 31 | static struct plat_serial8250_port serial_platform_data[] = { |
| 32 | { |
Russell King | e8a91c9 | 2008-09-01 22:07:37 +0100 | [diff] [blame] | 33 | .membase = IO_ADDRESS(OMAP_UART1_BASE), |
| 34 | .mapbase = OMAP_UART1_BASE, |
Tony Lindgren | 1dbae81 | 2005-11-10 14:26:51 +0000 | [diff] [blame] | 35 | .irq = 72, |
| 36 | .flags = UPF_BOOT_AUTOCONF, |
| 37 | .iotype = UPIO_MEM, |
| 38 | .regshift = 2, |
Jouni Hogander | 6e81176 | 2008-10-06 15:49:15 +0300 | [diff] [blame] | 39 | .uartclk = OMAP24XX_BASE_BAUD * 16, |
Tony Lindgren | 1dbae81 | 2005-11-10 14:26:51 +0000 | [diff] [blame] | 40 | }, { |
Russell King | e8a91c9 | 2008-09-01 22:07:37 +0100 | [diff] [blame] | 41 | .membase = IO_ADDRESS(OMAP_UART2_BASE), |
| 42 | .mapbase = OMAP_UART2_BASE, |
Tony Lindgren | 1dbae81 | 2005-11-10 14:26:51 +0000 | [diff] [blame] | 43 | .irq = 73, |
| 44 | .flags = UPF_BOOT_AUTOCONF, |
| 45 | .iotype = UPIO_MEM, |
| 46 | .regshift = 2, |
Jouni Hogander | 6e81176 | 2008-10-06 15:49:15 +0300 | [diff] [blame] | 47 | .uartclk = OMAP24XX_BASE_BAUD * 16, |
Tony Lindgren | 1dbae81 | 2005-11-10 14:26:51 +0000 | [diff] [blame] | 48 | }, { |
Russell King | e8a91c9 | 2008-09-01 22:07:37 +0100 | [diff] [blame] | 49 | .membase = IO_ADDRESS(OMAP_UART3_BASE), |
| 50 | .mapbase = OMAP_UART3_BASE, |
Tony Lindgren | 1dbae81 | 2005-11-10 14:26:51 +0000 | [diff] [blame] | 51 | .irq = 74, |
| 52 | .flags = UPF_BOOT_AUTOCONF, |
| 53 | .iotype = UPIO_MEM, |
| 54 | .regshift = 2, |
Jouni Hogander | 6e81176 | 2008-10-06 15:49:15 +0300 | [diff] [blame] | 55 | .uartclk = OMAP24XX_BASE_BAUD * 16, |
Tony Lindgren | 1dbae81 | 2005-11-10 14:26:51 +0000 | [diff] [blame] | 56 | }, { |
| 57 | .flags = 0 |
| 58 | } |
| 59 | }; |
| 60 | |
| 61 | static 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 | |
| 68 | static inline void serial_write_reg(struct plat_serial8250_port *p, int offset, |
| 69 | int value) |
| 70 | { |
| 71 | offset <<= p->regshift; |
Russell King | e8a91c9 | 2008-09-01 22:07:37 +0100 | [diff] [blame] | 72 | __raw_writeb(value, p->membase + offset); |
Tony Lindgren | 1dbae81 | 2005-11-10 14:26:51 +0000 | [diff] [blame] | 73 | } |
| 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 | */ |
| 80 | static 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 Yrjola | 671c723 | 2006-12-06 17:13:49 -0800 | [diff] [blame] | 85 | serial_write_reg(p, UART_OMAP_SYSC, (0x02 << 3) | (1 << 2) | (1 << 0)); |
Tony Lindgren | 1dbae81 | 2005-11-10 14:26:51 +0000 | [diff] [blame] | 86 | } |
| 87 | |
Jouni Hogander | 6e81176 | 2008-10-06 15:49:15 +0300 | [diff] [blame] | 88 | void 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 Pandita | 2aa57be | 2009-05-28 14:03:59 -0700 | [diff] [blame] | 104 | static 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 Hogander | 6e81176 | 2008-10-06 15:49:15 +0300 | [diff] [blame] | 112 | void __init omap_serial_init(void) |
Tony Lindgren | 1dbae81 | 2005-11-10 14:26:51 +0000 | [diff] [blame] | 113 | { |
| 114 | int i; |
| 115 | const struct omap_uart_config *info; |
Jouni Hogander | 6e81176 | 2008-10-06 15:49:15 +0300 | [diff] [blame] | 116 | char name[16]; |
Tony Lindgren | 1dbae81 | 2005-11-10 14:26:51 +0000 | [diff] [blame] | 117 | |
| 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 Hogander | 6e81176 | 2008-10-06 15:49:15 +0300 | [diff] [blame] | 124 | info = omap_get_config(OMAP_TAG_UART, struct omap_uart_config); |
Tony Lindgren | 1dbae81 | 2005-11-10 14:26:51 +0000 | [diff] [blame] | 125 | |
| 126 | if (info == NULL) |
| 127 | return; |
Santosh Shilimkar | 4416907 | 2009-05-28 14:16:04 -0700 | [diff] [blame^] | 128 | if (cpu_is_omap44xx()) { |
| 129 | for (i = 0; i < OMAP_MAX_NR_PORTS; i++) |
| 130 | serial_platform_data[i].irq += 32; |
| 131 | } |
Tony Lindgren | 1dbae81 | 2005-11-10 14:26:51 +0000 | [diff] [blame] | 132 | |
| 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 King | c0fc18c | 2008-09-05 15:10:27 +0100 | [diff] [blame] | 137 | p->membase = NULL; |
Tony Lindgren | 1dbae81 | 2005-11-10 14:26:51 +0000 | [diff] [blame] | 138 | p->mapbase = 0; |
| 139 | continue; |
| 140 | } |
| 141 | |
Jouni Hogander | 6e81176 | 2008-10-06 15:49:15 +0300 | [diff] [blame] | 142 | 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 Lindgren | 1dbae81 | 2005-11-10 14:26:51 +0000 | [diff] [blame] | 149 | |
Jouni Hogander | 6e81176 | 2008-10-06 15:49:15 +0300 | [diff] [blame] | 150 | 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 Lindgren | 1dbae81 | 2005-11-10 14:26:51 +0000 | [diff] [blame] | 157 | |
| 158 | omap_serial_reset(p); |
| 159 | } |
Tony Lindgren | 1dbae81 | 2005-11-10 14:26:51 +0000 | [diff] [blame] | 160 | |
Vikram Pandita | 2aa57be | 2009-05-28 14:03:59 -0700 | [diff] [blame] | 161 | platform_device_register(&serial_device); |
Tony Lindgren | 1dbae81 | 2005-11-10 14:26:51 +0000 | [diff] [blame] | 162 | } |