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 | * |
Kevin Hilman | 4af4016 | 2009-02-04 10:51:40 -0800 | [diff] [blame] | 9 | * Major rework for PM support by Kevin Hilman |
| 10 | * |
Tony Lindgren | 1dbae81 | 2005-11-10 14:26:51 +0000 | [diff] [blame] | 11 | * Based off of arch/arm/mach-omap/omap1/serial.c |
| 12 | * |
Santosh Shilimkar | 4416907 | 2009-05-28 14:16:04 -0700 | [diff] [blame] | 13 | * Copyright (C) 2009 Texas Instruments |
| 14 | * Added OMAP4 support - Santosh Shilimkar <santosh.shilimkar@ti.com |
| 15 | * |
Tony Lindgren | 1dbae81 | 2005-11-10 14:26:51 +0000 | [diff] [blame] | 16 | * This file is subject to the terms and conditions of the GNU General Public |
| 17 | * License. See the file "COPYING" in the main directory of this archive |
| 18 | * for more details. |
| 19 | */ |
| 20 | #include <linux/kernel.h> |
| 21 | #include <linux/init.h> |
Tony Lindgren | 1dbae81 | 2005-11-10 14:26:51 +0000 | [diff] [blame] | 22 | #include <linux/serial_reg.h> |
Russell King | f8ce254 | 2006-01-07 16:15:52 +0000 | [diff] [blame] | 23 | #include <linux/clk.h> |
Russell King | fced80c | 2008-09-06 12:10:45 +0100 | [diff] [blame] | 24 | #include <linux/io.h> |
Santosh Shilimkar | e03d37d | 2010-02-18 08:59:06 +0000 | [diff] [blame] | 25 | #include <linux/delay.h> |
Kevin Hilman | 6f251e9 | 2010-09-27 20:19:38 +0530 | [diff] [blame] | 26 | #include <linux/platform_device.h> |
| 27 | #include <linux/slab.h> |
| 28 | #include <linux/serial_8250.h> |
| 29 | |
| 30 | #ifdef CONFIG_SERIAL_OMAP |
| 31 | #include <plat/omap-serial.h> |
| 32 | #endif |
Tony Lindgren | 1dbae81 | 2005-11-10 14:26:51 +0000 | [diff] [blame] | 33 | |
Tony Lindgren | ce491cf | 2009-10-20 09:40:47 -0700 | [diff] [blame] | 34 | #include <plat/common.h> |
| 35 | #include <plat/board.h> |
| 36 | #include <plat/clock.h> |
| 37 | #include <plat/control.h> |
Kevin Hilman | 6f251e9 | 2010-09-27 20:19:38 +0530 | [diff] [blame] | 38 | #include <plat/dma.h> |
| 39 | #include <plat/omap_hwmod.h> |
| 40 | #include <plat/omap_device.h> |
Tony Lindgren | 1dbae81 | 2005-11-10 14:26:51 +0000 | [diff] [blame] | 41 | |
Kevin Hilman | 4af4016 | 2009-02-04 10:51:40 -0800 | [diff] [blame] | 42 | #include "prm.h" |
| 43 | #include "pm.h" |
Kevin Hilman | 6f251e9 | 2010-09-27 20:19:38 +0530 | [diff] [blame] | 44 | #include "cm.h" |
Kevin Hilman | 4af4016 | 2009-02-04 10:51:40 -0800 | [diff] [blame] | 45 | #include "prm-regbits-34xx.h" |
| 46 | |
vikram pandita | ce13d47 | 2009-12-11 16:16:37 -0800 | [diff] [blame] | 47 | #define UART_OMAP_NO_EMPTY_FIFO_READ_IP_REV 0x52 |
Kevin Hilman | 4af4016 | 2009-02-04 10:51:40 -0800 | [diff] [blame] | 48 | #define UART_OMAP_WER 0x17 /* Wake-up enable register */ |
| 49 | |
Nishanth Menon | 5a927b3 | 2010-08-02 13:18:12 +0300 | [diff] [blame] | 50 | #define UART_ERRATA_FIFO_FULL_ABORT (0x1 << 0) |
Deepak K | 0003450 | 2010-08-02 13:18:12 +0300 | [diff] [blame] | 51 | #define UART_ERRATA_i202_MDR1_ACCESS (0x1 << 1) |
Nishanth Menon | 5a927b3 | 2010-08-02 13:18:12 +0300 | [diff] [blame] | 52 | |
Tony Lindgren | 301fe8e | 2010-02-01 12:34:31 -0800 | [diff] [blame] | 53 | /* |
| 54 | * NOTE: By default the serial timeout is disabled as it causes lost characters |
| 55 | * over the serial ports. This means that the UART clocks will stay on until |
| 56 | * disabled via sysfs. This also causes that any deeper omap sleep states are |
| 57 | * blocked. |
| 58 | */ |
| 59 | #define DEFAULT_TIMEOUT 0 |
Kevin Hilman | 4af4016 | 2009-02-04 10:51:40 -0800 | [diff] [blame] | 60 | |
Kevin Hilman | 6f251e9 | 2010-09-27 20:19:38 +0530 | [diff] [blame] | 61 | #define MAX_UART_HWMOD_NAME_LEN 16 |
| 62 | |
Kevin Hilman | 4af4016 | 2009-02-04 10:51:40 -0800 | [diff] [blame] | 63 | struct omap_uart_state { |
| 64 | int num; |
| 65 | int can_sleep; |
| 66 | struct timer_list timer; |
| 67 | u32 timeout; |
| 68 | |
| 69 | void __iomem *wk_st; |
| 70 | void __iomem *wk_en; |
| 71 | u32 wk_mask; |
| 72 | u32 padconf; |
Kevin Hilman | 6f251e9 | 2010-09-27 20:19:38 +0530 | [diff] [blame] | 73 | u32 dma_enabled; |
Kevin Hilman | 4af4016 | 2009-02-04 10:51:40 -0800 | [diff] [blame] | 74 | |
| 75 | struct clk *ick; |
| 76 | struct clk *fck; |
| 77 | int clocked; |
| 78 | |
Kevin Hilman | 6f251e9 | 2010-09-27 20:19:38 +0530 | [diff] [blame] | 79 | int irq; |
| 80 | int regshift; |
| 81 | int irqflags; |
| 82 | void __iomem *membase; |
| 83 | resource_size_t mapbase; |
| 84 | |
Kevin Hilman | 4af4016 | 2009-02-04 10:51:40 -0800 | [diff] [blame] | 85 | struct list_head node; |
Kevin Hilman | 6f251e9 | 2010-09-27 20:19:38 +0530 | [diff] [blame] | 86 | struct omap_hwmod *oh; |
| 87 | struct platform_device *pdev; |
Kevin Hilman | 4af4016 | 2009-02-04 10:51:40 -0800 | [diff] [blame] | 88 | |
Nishanth Menon | 5a927b3 | 2010-08-02 13:18:12 +0300 | [diff] [blame] | 89 | u32 errata; |
Kevin Hilman | 4af4016 | 2009-02-04 10:51:40 -0800 | [diff] [blame] | 90 | #if defined(CONFIG_ARCH_OMAP3) && defined(CONFIG_PM) |
| 91 | int context_valid; |
| 92 | |
| 93 | /* Registers to be saved/restored for OFF-mode */ |
| 94 | u16 dll; |
| 95 | u16 dlh; |
| 96 | u16 ier; |
| 97 | u16 sysc; |
| 98 | u16 scr; |
| 99 | u16 wer; |
Govindraj R | 5ade4ff | 2010-08-02 13:18:11 +0300 | [diff] [blame] | 100 | u16 mcr; |
Kevin Hilman | 4af4016 | 2009-02-04 10:51:40 -0800 | [diff] [blame] | 101 | #endif |
| 102 | }; |
| 103 | |
Kevin Hilman | 4af4016 | 2009-02-04 10:51:40 -0800 | [diff] [blame] | 104 | static LIST_HEAD(uart_list); |
Kevin Hilman | 6f251e9 | 2010-09-27 20:19:38 +0530 | [diff] [blame] | 105 | static u8 num_uarts; |
Tony Lindgren | 1dbae81 | 2005-11-10 14:26:51 +0000 | [diff] [blame] | 106 | |
Kevin Hilman | 6f251e9 | 2010-09-27 20:19:38 +0530 | [diff] [blame] | 107 | static struct omap_device_pm_latency omap_uart_latency[] = { |
| 108 | { |
| 109 | .deactivate_func = omap_device_idle_hwmods, |
| 110 | .activate_func = omap_device_enable_hwmods, |
| 111 | .flags = OMAP_DEVICE_LATENCY_AUTO_ADJUST, |
| 112 | }, |
| 113 | }; |
| 114 | |
Alexander Shishkin | 9230372 | 2010-01-08 10:29:06 -0800 | [diff] [blame] | 115 | static inline unsigned int __serial_read_reg(struct uart_port *up, |
Kevin Hilman | 6f251e9 | 2010-09-27 20:19:38 +0530 | [diff] [blame] | 116 | int offset) |
Alexander Shishkin | 9230372 | 2010-01-08 10:29:06 -0800 | [diff] [blame] | 117 | { |
| 118 | offset <<= up->regshift; |
| 119 | return (unsigned int)__raw_readb(up->membase + offset); |
| 120 | } |
| 121 | |
Kevin Hilman | 6f251e9 | 2010-09-27 20:19:38 +0530 | [diff] [blame] | 122 | static inline unsigned int serial_read_reg(struct omap_uart_state *uart, |
Tony Lindgren | 1dbae81 | 2005-11-10 14:26:51 +0000 | [diff] [blame] | 123 | int offset) |
| 124 | { |
Kevin Hilman | 6f251e9 | 2010-09-27 20:19:38 +0530 | [diff] [blame] | 125 | offset <<= uart->regshift; |
| 126 | return (unsigned int)__raw_readb(uart->membase + offset); |
Tony Lindgren | 1dbae81 | 2005-11-10 14:26:51 +0000 | [diff] [blame] | 127 | } |
| 128 | |
Santosh Shilimkar | e03d37d | 2010-02-18 08:59:06 +0000 | [diff] [blame] | 129 | static inline void __serial_write_reg(struct uart_port *up, int offset, |
| 130 | int value) |
| 131 | { |
| 132 | offset <<= up->regshift; |
| 133 | __raw_writeb(value, up->membase + offset); |
| 134 | } |
| 135 | |
Kevin Hilman | 6f251e9 | 2010-09-27 20:19:38 +0530 | [diff] [blame] | 136 | static inline void serial_write_reg(struct omap_uart_state *uart, int offset, |
Tony Lindgren | 1dbae81 | 2005-11-10 14:26:51 +0000 | [diff] [blame] | 137 | int value) |
| 138 | { |
Kevin Hilman | 6f251e9 | 2010-09-27 20:19:38 +0530 | [diff] [blame] | 139 | offset <<= uart->regshift; |
| 140 | __raw_writeb(value, uart->membase + offset); |
Tony Lindgren | 1dbae81 | 2005-11-10 14:26:51 +0000 | [diff] [blame] | 141 | } |
| 142 | |
| 143 | /* |
| 144 | * Internal UARTs need to be initialized for the 8250 autoconfig to work |
| 145 | * properly. Note that the TX watermark initialization may not be needed |
| 146 | * once the 8250.c watermark handling code is merged. |
| 147 | */ |
Kevin Hilman | 6f251e9 | 2010-09-27 20:19:38 +0530 | [diff] [blame] | 148 | |
Kevin Hilman | 4af4016 | 2009-02-04 10:51:40 -0800 | [diff] [blame] | 149 | static inline void __init omap_uart_reset(struct omap_uart_state *uart) |
Tony Lindgren | 1dbae81 | 2005-11-10 14:26:51 +0000 | [diff] [blame] | 150 | { |
Kevin Hilman | 6f251e9 | 2010-09-27 20:19:38 +0530 | [diff] [blame] | 151 | serial_write_reg(uart, UART_OMAP_MDR1, 0x07); |
| 152 | serial_write_reg(uart, UART_OMAP_SCR, 0x08); |
| 153 | serial_write_reg(uart, UART_OMAP_MDR1, 0x00); |
Tony Lindgren | 1dbae81 | 2005-11-10 14:26:51 +0000 | [diff] [blame] | 154 | } |
| 155 | |
Kevin Hilman | 4af4016 | 2009-02-04 10:51:40 -0800 | [diff] [blame] | 156 | #if defined(CONFIG_PM) && defined(CONFIG_ARCH_OMAP3) |
| 157 | |
Deepak K | 0003450 | 2010-08-02 13:18:12 +0300 | [diff] [blame] | 158 | /* |
| 159 | * Work Around for Errata i202 (3430 - 1.12, 3630 - 1.6) |
| 160 | * The access to uart register after MDR1 Access |
| 161 | * causes UART to corrupt data. |
| 162 | * |
| 163 | * Need a delay = |
| 164 | * 5 L4 clock cycles + 5 UART functional clock cycle (@48MHz = ~0.2uS) |
| 165 | * give 10 times as much |
| 166 | */ |
| 167 | static void omap_uart_mdr1_errataset(struct omap_uart_state *uart, u8 mdr1_val, |
| 168 | u8 fcr_val) |
| 169 | { |
Deepak K | 0003450 | 2010-08-02 13:18:12 +0300 | [diff] [blame] | 170 | u8 timeout = 255; |
| 171 | |
Kevin Hilman | 6f251e9 | 2010-09-27 20:19:38 +0530 | [diff] [blame] | 172 | serial_write_reg(uart, UART_OMAP_MDR1, mdr1_val); |
Deepak K | 0003450 | 2010-08-02 13:18:12 +0300 | [diff] [blame] | 173 | udelay(2); |
Kevin Hilman | 6f251e9 | 2010-09-27 20:19:38 +0530 | [diff] [blame] | 174 | serial_write_reg(uart, UART_FCR, fcr_val | UART_FCR_CLEAR_XMIT | |
Deepak K | 0003450 | 2010-08-02 13:18:12 +0300 | [diff] [blame] | 175 | UART_FCR_CLEAR_RCVR); |
| 176 | /* |
| 177 | * Wait for FIFO to empty: when empty, RX_FIFO_E bit is 0 and |
| 178 | * TX_FIFO_E bit is 1. |
| 179 | */ |
Kevin Hilman | 6f251e9 | 2010-09-27 20:19:38 +0530 | [diff] [blame] | 180 | while (UART_LSR_THRE != (serial_read_reg(uart, UART_LSR) & |
Deepak K | 0003450 | 2010-08-02 13:18:12 +0300 | [diff] [blame] | 181 | (UART_LSR_THRE | UART_LSR_DR))) { |
| 182 | timeout--; |
| 183 | if (!timeout) { |
| 184 | /* Should *never* happen. we warn and carry on */ |
Kevin Hilman | 6f251e9 | 2010-09-27 20:19:38 +0530 | [diff] [blame] | 185 | dev_crit(&uart->pdev->dev, "Errata i202: timedout %x\n", |
| 186 | serial_read_reg(uart, UART_LSR)); |
Deepak K | 0003450 | 2010-08-02 13:18:12 +0300 | [diff] [blame] | 187 | break; |
| 188 | } |
| 189 | udelay(1); |
| 190 | } |
| 191 | } |
| 192 | |
Kevin Hilman | 4af4016 | 2009-02-04 10:51:40 -0800 | [diff] [blame] | 193 | static void omap_uart_save_context(struct omap_uart_state *uart) |
Jouni Hogander | 6e81176 | 2008-10-06 15:49:15 +0300 | [diff] [blame] | 194 | { |
Kevin Hilman | 4af4016 | 2009-02-04 10:51:40 -0800 | [diff] [blame] | 195 | u16 lcr = 0; |
Kevin Hilman | 4af4016 | 2009-02-04 10:51:40 -0800 | [diff] [blame] | 196 | |
| 197 | if (!enable_off_mode) |
| 198 | return; |
| 199 | |
Kevin Hilman | 6f251e9 | 2010-09-27 20:19:38 +0530 | [diff] [blame] | 200 | lcr = serial_read_reg(uart, UART_LCR); |
| 201 | serial_write_reg(uart, UART_LCR, 0xBF); |
| 202 | uart->dll = serial_read_reg(uart, UART_DLL); |
| 203 | uart->dlh = serial_read_reg(uart, UART_DLM); |
| 204 | serial_write_reg(uart, UART_LCR, lcr); |
| 205 | uart->ier = serial_read_reg(uart, UART_IER); |
| 206 | uart->sysc = serial_read_reg(uart, UART_OMAP_SYSC); |
| 207 | uart->scr = serial_read_reg(uart, UART_OMAP_SCR); |
| 208 | uart->wer = serial_read_reg(uart, UART_OMAP_WER); |
| 209 | serial_write_reg(uart, UART_LCR, 0x80); |
| 210 | uart->mcr = serial_read_reg(uart, UART_MCR); |
| 211 | serial_write_reg(uart, UART_LCR, lcr); |
Kevin Hilman | 4af4016 | 2009-02-04 10:51:40 -0800 | [diff] [blame] | 212 | |
| 213 | uart->context_valid = 1; |
| 214 | } |
| 215 | |
| 216 | static void omap_uart_restore_context(struct omap_uart_state *uart) |
| 217 | { |
| 218 | u16 efr = 0; |
Kevin Hilman | 4af4016 | 2009-02-04 10:51:40 -0800 | [diff] [blame] | 219 | |
| 220 | if (!enable_off_mode) |
| 221 | return; |
| 222 | |
| 223 | if (!uart->context_valid) |
| 224 | return; |
| 225 | |
| 226 | uart->context_valid = 0; |
| 227 | |
Deepak K | 0003450 | 2010-08-02 13:18:12 +0300 | [diff] [blame] | 228 | if (uart->errata & UART_ERRATA_i202_MDR1_ACCESS) |
| 229 | omap_uart_mdr1_errataset(uart, 0x07, 0xA0); |
| 230 | else |
Kevin Hilman | 6f251e9 | 2010-09-27 20:19:38 +0530 | [diff] [blame] | 231 | serial_write_reg(uart, UART_OMAP_MDR1, 0x7); |
| 232 | serial_write_reg(uart, UART_LCR, 0xBF); /* Config B mode */ |
| 233 | efr = serial_read_reg(uart, UART_EFR); |
| 234 | serial_write_reg(uart, UART_EFR, UART_EFR_ECB); |
| 235 | serial_write_reg(uart, UART_LCR, 0x0); /* Operational mode */ |
| 236 | serial_write_reg(uart, UART_IER, 0x0); |
| 237 | serial_write_reg(uart, UART_LCR, 0xBF); /* Config B mode */ |
| 238 | serial_write_reg(uart, UART_DLL, uart->dll); |
| 239 | serial_write_reg(uart, UART_DLM, uart->dlh); |
| 240 | serial_write_reg(uart, UART_LCR, 0x0); /* Operational mode */ |
| 241 | serial_write_reg(uart, UART_IER, uart->ier); |
| 242 | serial_write_reg(uart, UART_LCR, 0x80); |
| 243 | serial_write_reg(uart, UART_MCR, uart->mcr); |
| 244 | serial_write_reg(uart, UART_LCR, 0xBF); /* Config B mode */ |
| 245 | serial_write_reg(uart, UART_EFR, efr); |
| 246 | serial_write_reg(uart, UART_LCR, UART_LCR_WLEN8); |
| 247 | serial_write_reg(uart, UART_OMAP_SCR, uart->scr); |
| 248 | serial_write_reg(uart, UART_OMAP_WER, uart->wer); |
| 249 | serial_write_reg(uart, UART_OMAP_SYSC, uart->sysc); |
Deepak K | 0003450 | 2010-08-02 13:18:12 +0300 | [diff] [blame] | 250 | if (uart->errata & UART_ERRATA_i202_MDR1_ACCESS) |
| 251 | omap_uart_mdr1_errataset(uart, 0x00, 0xA1); |
| 252 | else |
Kevin Hilman | 6f251e9 | 2010-09-27 20:19:38 +0530 | [diff] [blame] | 253 | /* UART 16x mode */ |
| 254 | serial_write_reg(uart, UART_OMAP_MDR1, 0x00); |
Kevin Hilman | 4af4016 | 2009-02-04 10:51:40 -0800 | [diff] [blame] | 255 | } |
| 256 | #else |
| 257 | static inline void omap_uart_save_context(struct omap_uart_state *uart) {} |
| 258 | static inline void omap_uart_restore_context(struct omap_uart_state *uart) {} |
| 259 | #endif /* CONFIG_PM && CONFIG_ARCH_OMAP3 */ |
| 260 | |
| 261 | static inline void omap_uart_enable_clocks(struct omap_uart_state *uart) |
| 262 | { |
| 263 | if (uart->clocked) |
| 264 | return; |
| 265 | |
Kevin Hilman | 6f251e9 | 2010-09-27 20:19:38 +0530 | [diff] [blame] | 266 | omap_device_enable(uart->pdev); |
Kevin Hilman | 4af4016 | 2009-02-04 10:51:40 -0800 | [diff] [blame] | 267 | uart->clocked = 1; |
| 268 | omap_uart_restore_context(uart); |
| 269 | } |
| 270 | |
| 271 | #ifdef CONFIG_PM |
| 272 | |
| 273 | static inline void omap_uart_disable_clocks(struct omap_uart_state *uart) |
| 274 | { |
| 275 | if (!uart->clocked) |
| 276 | return; |
| 277 | |
| 278 | omap_uart_save_context(uart); |
| 279 | uart->clocked = 0; |
Kevin Hilman | 6f251e9 | 2010-09-27 20:19:38 +0530 | [diff] [blame] | 280 | omap_device_idle(uart->pdev); |
Kevin Hilman | 4af4016 | 2009-02-04 10:51:40 -0800 | [diff] [blame] | 281 | } |
| 282 | |
Kevin Hilman | fd455ea | 2009-04-27 12:27:36 -0700 | [diff] [blame] | 283 | static void omap_uart_enable_wakeup(struct omap_uart_state *uart) |
| 284 | { |
| 285 | /* Set wake-enable bit */ |
| 286 | if (uart->wk_en && uart->wk_mask) { |
| 287 | u32 v = __raw_readl(uart->wk_en); |
| 288 | v |= uart->wk_mask; |
| 289 | __raw_writel(v, uart->wk_en); |
| 290 | } |
| 291 | |
| 292 | /* Ensure IOPAD wake-enables are set */ |
| 293 | if (cpu_is_omap34xx() && uart->padconf) { |
| 294 | u16 v = omap_ctrl_readw(uart->padconf); |
| 295 | v |= OMAP3_PADCONF_WAKEUPENABLE0; |
| 296 | omap_ctrl_writew(v, uart->padconf); |
| 297 | } |
| 298 | } |
| 299 | |
| 300 | static void omap_uart_disable_wakeup(struct omap_uart_state *uart) |
| 301 | { |
| 302 | /* Clear wake-enable bit */ |
| 303 | if (uart->wk_en && uart->wk_mask) { |
| 304 | u32 v = __raw_readl(uart->wk_en); |
| 305 | v &= ~uart->wk_mask; |
| 306 | __raw_writel(v, uart->wk_en); |
| 307 | } |
| 308 | |
| 309 | /* Ensure IOPAD wake-enables are cleared */ |
| 310 | if (cpu_is_omap34xx() && uart->padconf) { |
| 311 | u16 v = omap_ctrl_readw(uart->padconf); |
| 312 | v &= ~OMAP3_PADCONF_WAKEUPENABLE0; |
| 313 | omap_ctrl_writew(v, uart->padconf); |
| 314 | } |
| 315 | } |
| 316 | |
Kevin Hilman | 4af4016 | 2009-02-04 10:51:40 -0800 | [diff] [blame] | 317 | static void omap_uart_smart_idle_enable(struct omap_uart_state *uart, |
Kevin Hilman | 6f251e9 | 2010-09-27 20:19:38 +0530 | [diff] [blame] | 318 | int enable) |
Kevin Hilman | 4af4016 | 2009-02-04 10:51:40 -0800 | [diff] [blame] | 319 | { |
Kevin Hilman | 6f251e9 | 2010-09-27 20:19:38 +0530 | [diff] [blame] | 320 | u8 idlemode; |
Kevin Hilman | 4af4016 | 2009-02-04 10:51:40 -0800 | [diff] [blame] | 321 | |
Kevin Hilman | 6f251e9 | 2010-09-27 20:19:38 +0530 | [diff] [blame] | 322 | if (enable) { |
| 323 | /** |
| 324 | * Errata 2.15: [UART]:Cannot Acknowledge Idle Requests |
| 325 | * in Smartidle Mode When Configured for DMA Operations. |
| 326 | */ |
| 327 | if (uart->dma_enabled) |
| 328 | idlemode = HWMOD_IDLEMODE_FORCE; |
| 329 | else |
| 330 | idlemode = HWMOD_IDLEMODE_SMART; |
| 331 | } else { |
| 332 | idlemode = HWMOD_IDLEMODE_NO; |
| 333 | } |
Kevin Hilman | 4af4016 | 2009-02-04 10:51:40 -0800 | [diff] [blame] | 334 | |
Kevin Hilman | 6f251e9 | 2010-09-27 20:19:38 +0530 | [diff] [blame] | 335 | omap_hwmod_set_slave_idlemode(uart->oh, idlemode); |
Kevin Hilman | 4af4016 | 2009-02-04 10:51:40 -0800 | [diff] [blame] | 336 | } |
| 337 | |
| 338 | static void omap_uart_block_sleep(struct omap_uart_state *uart) |
| 339 | { |
| 340 | omap_uart_enable_clocks(uart); |
| 341 | |
| 342 | omap_uart_smart_idle_enable(uart, 0); |
| 343 | uart->can_sleep = 0; |
Jouni Hogander | ba87a9b | 2008-12-09 13:36:50 +0200 | [diff] [blame] | 344 | if (uart->timeout) |
| 345 | mod_timer(&uart->timer, jiffies + uart->timeout); |
| 346 | else |
| 347 | del_timer(&uart->timer); |
Kevin Hilman | 4af4016 | 2009-02-04 10:51:40 -0800 | [diff] [blame] | 348 | } |
| 349 | |
| 350 | static void omap_uart_allow_sleep(struct omap_uart_state *uart) |
| 351 | { |
Kevin Hilman | 6f251e9 | 2010-09-27 20:19:38 +0530 | [diff] [blame] | 352 | if (device_may_wakeup(&uart->pdev->dev)) |
Kevin Hilman | fd455ea | 2009-04-27 12:27:36 -0700 | [diff] [blame] | 353 | omap_uart_enable_wakeup(uart); |
| 354 | else |
| 355 | omap_uart_disable_wakeup(uart); |
| 356 | |
Kevin Hilman | 4af4016 | 2009-02-04 10:51:40 -0800 | [diff] [blame] | 357 | if (!uart->clocked) |
| 358 | return; |
| 359 | |
| 360 | omap_uart_smart_idle_enable(uart, 1); |
| 361 | uart->can_sleep = 1; |
| 362 | del_timer(&uart->timer); |
| 363 | } |
| 364 | |
| 365 | static void omap_uart_idle_timer(unsigned long data) |
| 366 | { |
| 367 | struct omap_uart_state *uart = (struct omap_uart_state *)data; |
| 368 | |
| 369 | omap_uart_allow_sleep(uart); |
| 370 | } |
| 371 | |
| 372 | void omap_uart_prepare_idle(int num) |
| 373 | { |
| 374 | struct omap_uart_state *uart; |
| 375 | |
| 376 | list_for_each_entry(uart, &uart_list, node) { |
| 377 | if (num == uart->num && uart->can_sleep) { |
| 378 | omap_uart_disable_clocks(uart); |
| 379 | return; |
Jouni Hogander | 6e81176 | 2008-10-06 15:49:15 +0300 | [diff] [blame] | 380 | } |
| 381 | } |
| 382 | } |
| 383 | |
Kevin Hilman | 4af4016 | 2009-02-04 10:51:40 -0800 | [diff] [blame] | 384 | void omap_uart_resume_idle(int num) |
| 385 | { |
| 386 | struct omap_uart_state *uart; |
| 387 | |
| 388 | list_for_each_entry(uart, &uart_list, node) { |
| 389 | if (num == uart->num) { |
| 390 | omap_uart_enable_clocks(uart); |
| 391 | |
| 392 | /* Check for IO pad wakeup */ |
| 393 | if (cpu_is_omap34xx() && uart->padconf) { |
| 394 | u16 p = omap_ctrl_readw(uart->padconf); |
| 395 | |
| 396 | if (p & OMAP3_PADCONF_WAKEUPEVENT0) |
| 397 | omap_uart_block_sleep(uart); |
| 398 | } |
| 399 | |
| 400 | /* Check for normal UART wakeup */ |
| 401 | if (__raw_readl(uart->wk_st) & uart->wk_mask) |
| 402 | omap_uart_block_sleep(uart); |
Kevin Hilman | 4af4016 | 2009-02-04 10:51:40 -0800 | [diff] [blame] | 403 | return; |
| 404 | } |
| 405 | } |
| 406 | } |
| 407 | |
| 408 | void omap_uart_prepare_suspend(void) |
| 409 | { |
| 410 | struct omap_uart_state *uart; |
| 411 | |
| 412 | list_for_each_entry(uart, &uart_list, node) { |
| 413 | omap_uart_allow_sleep(uart); |
| 414 | } |
| 415 | } |
| 416 | |
| 417 | int omap_uart_can_sleep(void) |
| 418 | { |
| 419 | struct omap_uart_state *uart; |
| 420 | int can_sleep = 1; |
| 421 | |
| 422 | list_for_each_entry(uart, &uart_list, node) { |
| 423 | if (!uart->clocked) |
| 424 | continue; |
| 425 | |
| 426 | if (!uart->can_sleep) { |
| 427 | can_sleep = 0; |
| 428 | continue; |
| 429 | } |
| 430 | |
| 431 | /* This UART can now safely sleep. */ |
| 432 | omap_uart_allow_sleep(uart); |
| 433 | } |
| 434 | |
| 435 | return can_sleep; |
| 436 | } |
| 437 | |
| 438 | /** |
| 439 | * omap_uart_interrupt() |
| 440 | * |
| 441 | * This handler is used only to detect that *any* UART interrupt has |
| 442 | * occurred. It does _nothing_ to handle the interrupt. Rather, |
| 443 | * any UART interrupt will trigger the inactivity timer so the |
| 444 | * UART will not idle or sleep for its timeout period. |
| 445 | * |
| 446 | **/ |
Kevin Hilman | 6f251e9 | 2010-09-27 20:19:38 +0530 | [diff] [blame] | 447 | /* static int first_interrupt; */ |
Kevin Hilman | 4af4016 | 2009-02-04 10:51:40 -0800 | [diff] [blame] | 448 | static irqreturn_t omap_uart_interrupt(int irq, void *dev_id) |
| 449 | { |
| 450 | struct omap_uart_state *uart = dev_id; |
| 451 | |
| 452 | omap_uart_block_sleep(uart); |
| 453 | |
| 454 | return IRQ_NONE; |
| 455 | } |
| 456 | |
| 457 | static void omap_uart_idle_init(struct omap_uart_state *uart) |
| 458 | { |
Kevin Hilman | 4af4016 | 2009-02-04 10:51:40 -0800 | [diff] [blame] | 459 | int ret; |
| 460 | |
| 461 | uart->can_sleep = 0; |
Kevin Hilman | fd455ea | 2009-04-27 12:27:36 -0700 | [diff] [blame] | 462 | uart->timeout = DEFAULT_TIMEOUT; |
Kevin Hilman | 4af4016 | 2009-02-04 10:51:40 -0800 | [diff] [blame] | 463 | setup_timer(&uart->timer, omap_uart_idle_timer, |
| 464 | (unsigned long) uart); |
Tony Lindgren | 301fe8e | 2010-02-01 12:34:31 -0800 | [diff] [blame] | 465 | if (uart->timeout) |
| 466 | mod_timer(&uart->timer, jiffies + uart->timeout); |
Kevin Hilman | 4af4016 | 2009-02-04 10:51:40 -0800 | [diff] [blame] | 467 | omap_uart_smart_idle_enable(uart, 0); |
| 468 | |
| 469 | if (cpu_is_omap34xx()) { |
| 470 | u32 mod = (uart->num == 2) ? OMAP3430_PER_MOD : CORE_MOD; |
| 471 | u32 wk_mask = 0; |
| 472 | u32 padconf = 0; |
| 473 | |
| 474 | uart->wk_en = OMAP34XX_PRM_REGADDR(mod, PM_WKEN1); |
| 475 | uart->wk_st = OMAP34XX_PRM_REGADDR(mod, PM_WKST1); |
| 476 | switch (uart->num) { |
| 477 | case 0: |
| 478 | wk_mask = OMAP3430_ST_UART1_MASK; |
| 479 | padconf = 0x182; |
| 480 | break; |
| 481 | case 1: |
| 482 | wk_mask = OMAP3430_ST_UART2_MASK; |
| 483 | padconf = 0x17a; |
| 484 | break; |
| 485 | case 2: |
| 486 | wk_mask = OMAP3430_ST_UART3_MASK; |
| 487 | padconf = 0x19e; |
| 488 | break; |
| 489 | } |
| 490 | uart->wk_mask = wk_mask; |
| 491 | uart->padconf = padconf; |
| 492 | } else if (cpu_is_omap24xx()) { |
| 493 | u32 wk_mask = 0; |
| 494 | |
| 495 | if (cpu_is_omap2430()) { |
| 496 | uart->wk_en = OMAP2430_PRM_REGADDR(CORE_MOD, PM_WKEN1); |
| 497 | uart->wk_st = OMAP2430_PRM_REGADDR(CORE_MOD, PM_WKST1); |
| 498 | } else if (cpu_is_omap2420()) { |
| 499 | uart->wk_en = OMAP2420_PRM_REGADDR(CORE_MOD, PM_WKEN1); |
| 500 | uart->wk_st = OMAP2420_PRM_REGADDR(CORE_MOD, PM_WKST1); |
| 501 | } |
| 502 | switch (uart->num) { |
| 503 | case 0: |
| 504 | wk_mask = OMAP24XX_ST_UART1_MASK; |
| 505 | break; |
| 506 | case 1: |
| 507 | wk_mask = OMAP24XX_ST_UART2_MASK; |
| 508 | break; |
| 509 | case 2: |
| 510 | wk_mask = OMAP24XX_ST_UART3_MASK; |
| 511 | break; |
| 512 | } |
| 513 | uart->wk_mask = wk_mask; |
| 514 | } else { |
Nishanth Menon | c54bae1 | 2010-08-02 13:18:11 +0300 | [diff] [blame] | 515 | uart->wk_en = NULL; |
| 516 | uart->wk_st = NULL; |
Kevin Hilman | 4af4016 | 2009-02-04 10:51:40 -0800 | [diff] [blame] | 517 | uart->wk_mask = 0; |
| 518 | uart->padconf = 0; |
| 519 | } |
| 520 | |
Kevin Hilman | 6f251e9 | 2010-09-27 20:19:38 +0530 | [diff] [blame] | 521 | uart->irqflags |= IRQF_SHARED; |
| 522 | ret = request_threaded_irq(uart->irq, NULL, omap_uart_interrupt, |
| 523 | IRQF_SHARED, "serial idle", (void *)uart); |
Kevin Hilman | 4af4016 | 2009-02-04 10:51:40 -0800 | [diff] [blame] | 524 | WARN_ON(ret); |
| 525 | } |
| 526 | |
Tero Kristo | 2466211 | 2009-03-05 16:32:23 +0200 | [diff] [blame] | 527 | void omap_uart_enable_irqs(int enable) |
Jouni Hogander | ba87a9b | 2008-12-09 13:36:50 +0200 | [diff] [blame] | 528 | { |
Tero Kristo | 2466211 | 2009-03-05 16:32:23 +0200 | [diff] [blame] | 529 | int ret; |
| 530 | struct omap_uart_state *uart; |
| 531 | |
| 532 | list_for_each_entry(uart, &uart_list, node) { |
| 533 | if (enable) |
Kevin Hilman | 6f251e9 | 2010-09-27 20:19:38 +0530 | [diff] [blame] | 534 | ret = request_threaded_irq(uart->irq, NULL, |
| 535 | omap_uart_interrupt, |
| 536 | IRQF_SHARED, |
| 537 | "serial idle", |
| 538 | (void *)uart); |
Tero Kristo | 2466211 | 2009-03-05 16:32:23 +0200 | [diff] [blame] | 539 | else |
Kevin Hilman | 6f251e9 | 2010-09-27 20:19:38 +0530 | [diff] [blame] | 540 | free_irq(uart->irq, (void *)uart); |
Tero Kristo | 2466211 | 2009-03-05 16:32:23 +0200 | [diff] [blame] | 541 | } |
Jouni Hogander | ba87a9b | 2008-12-09 13:36:50 +0200 | [diff] [blame] | 542 | } |
| 543 | |
Kevin Hilman | fd455ea | 2009-04-27 12:27:36 -0700 | [diff] [blame] | 544 | static ssize_t sleep_timeout_show(struct device *dev, |
| 545 | struct device_attribute *attr, |
Jouni Hogander | ba87a9b | 2008-12-09 13:36:50 +0200 | [diff] [blame] | 546 | char *buf) |
| 547 | { |
Kevin Hilman | 6f251e9 | 2010-09-27 20:19:38 +0530 | [diff] [blame] | 548 | struct platform_device *pdev = to_platform_device(dev); |
| 549 | struct omap_device *odev = to_omap_device(pdev); |
| 550 | struct omap_uart_state *uart = odev->hwmods[0]->dev_attr; |
Kevin Hilman | fd455ea | 2009-04-27 12:27:36 -0700 | [diff] [blame] | 551 | |
| 552 | return sprintf(buf, "%u\n", uart->timeout / HZ); |
Jouni Hogander | ba87a9b | 2008-12-09 13:36:50 +0200 | [diff] [blame] | 553 | } |
| 554 | |
Kevin Hilman | fd455ea | 2009-04-27 12:27:36 -0700 | [diff] [blame] | 555 | static ssize_t sleep_timeout_store(struct device *dev, |
| 556 | struct device_attribute *attr, |
Jouni Hogander | ba87a9b | 2008-12-09 13:36:50 +0200 | [diff] [blame] | 557 | const char *buf, size_t n) |
| 558 | { |
Kevin Hilman | 6f251e9 | 2010-09-27 20:19:38 +0530 | [diff] [blame] | 559 | struct platform_device *pdev = to_platform_device(dev); |
| 560 | struct omap_device *odev = to_omap_device(pdev); |
| 561 | struct omap_uart_state *uart = odev->hwmods[0]->dev_attr; |
Jouni Hogander | ba87a9b | 2008-12-09 13:36:50 +0200 | [diff] [blame] | 562 | unsigned int value; |
| 563 | |
| 564 | if (sscanf(buf, "%u", &value) != 1) { |
Sergio Aguirre | 10c805e | 2010-03-09 13:22:14 -0600 | [diff] [blame] | 565 | dev_err(dev, "sleep_timeout_store: Invalid value\n"); |
Jouni Hogander | ba87a9b | 2008-12-09 13:36:50 +0200 | [diff] [blame] | 566 | return -EINVAL; |
| 567 | } |
Kevin Hilman | fd455ea | 2009-04-27 12:27:36 -0700 | [diff] [blame] | 568 | |
| 569 | uart->timeout = value * HZ; |
| 570 | if (uart->timeout) |
| 571 | mod_timer(&uart->timer, jiffies + uart->timeout); |
| 572 | else |
| 573 | /* A zero value means disable timeout feature */ |
| 574 | omap_uart_block_sleep(uart); |
| 575 | |
Jouni Hogander | ba87a9b | 2008-12-09 13:36:50 +0200 | [diff] [blame] | 576 | return n; |
| 577 | } |
| 578 | |
Nishanth Menon | bfe6977 | 2010-08-02 13:18:12 +0300 | [diff] [blame] | 579 | static DEVICE_ATTR(sleep_timeout, 0644, sleep_timeout_show, |
| 580 | sleep_timeout_store); |
Kevin Hilman | fd455ea | 2009-04-27 12:27:36 -0700 | [diff] [blame] | 581 | #define DEV_CREATE_FILE(dev, attr) WARN_ON(device_create_file(dev, attr)) |
Kevin Hilman | 4af4016 | 2009-02-04 10:51:40 -0800 | [diff] [blame] | 582 | #else |
| 583 | static inline void omap_uart_idle_init(struct omap_uart_state *uart) {} |
Kevin Hilman | 6f251e9 | 2010-09-27 20:19:38 +0530 | [diff] [blame] | 584 | static void omap_uart_block_sleep(struct omap_uart_state *uart) {} |
Kevin Hilman | fd455ea | 2009-04-27 12:27:36 -0700 | [diff] [blame] | 585 | #define DEV_CREATE_FILE(dev, attr) |
Kevin Hilman | 4af4016 | 2009-02-04 10:51:40 -0800 | [diff] [blame] | 586 | #endif /* CONFIG_PM */ |
| 587 | |
Kevin Hilman | 6f251e9 | 2010-09-27 20:19:38 +0530 | [diff] [blame] | 588 | #ifndef CONFIG_SERIAL_OMAP |
vikram pandita | ce13d47 | 2009-12-11 16:16:37 -0800 | [diff] [blame] | 589 | /* |
| 590 | * Override the default 8250 read handler: mem_serial_in() |
| 591 | * Empty RX fifo read causes an abort on omap3630 and omap4 |
| 592 | * This function makes sure that an empty rx fifo is not read on these silicons |
| 593 | * (OMAP1/2/3430 are not affected) |
| 594 | */ |
| 595 | static unsigned int serial_in_override(struct uart_port *up, int offset) |
| 596 | { |
| 597 | if (UART_RX == offset) { |
| 598 | unsigned int lsr; |
Alexander Shishkin | 9230372 | 2010-01-08 10:29:06 -0800 | [diff] [blame] | 599 | lsr = __serial_read_reg(up, UART_LSR); |
vikram pandita | ce13d47 | 2009-12-11 16:16:37 -0800 | [diff] [blame] | 600 | if (!(lsr & UART_LSR_DR)) |
| 601 | return -EPERM; |
| 602 | } |
Alexander Shishkin | 9230372 | 2010-01-08 10:29:06 -0800 | [diff] [blame] | 603 | |
| 604 | return __serial_read_reg(up, offset); |
vikram pandita | ce13d47 | 2009-12-11 16:16:37 -0800 | [diff] [blame] | 605 | } |
| 606 | |
Santosh Shilimkar | e03d37d | 2010-02-18 08:59:06 +0000 | [diff] [blame] | 607 | static void serial_out_override(struct uart_port *up, int offset, int value) |
| 608 | { |
| 609 | unsigned int status, tmout = 10000; |
| 610 | |
| 611 | status = __serial_read_reg(up, UART_LSR); |
| 612 | while (!(status & UART_LSR_THRE)) { |
| 613 | /* Wait up to 10ms for the character(s) to be sent. */ |
| 614 | if (--tmout == 0) |
| 615 | break; |
| 616 | udelay(1); |
| 617 | status = __serial_read_reg(up, UART_LSR); |
| 618 | } |
| 619 | __serial_write_reg(up, offset, value); |
| 620 | } |
Kevin Hilman | 6f251e9 | 2010-09-27 20:19:38 +0530 | [diff] [blame] | 621 | #endif |
| 622 | |
Paul Walmsley | b3c6df3 | 2009-09-03 20:14:02 +0300 | [diff] [blame] | 623 | void __init omap_serial_early_init(void) |
Tony Lindgren | 1dbae81 | 2005-11-10 14:26:51 +0000 | [diff] [blame] | 624 | { |
Kevin Hilman | 6f251e9 | 2010-09-27 20:19:38 +0530 | [diff] [blame] | 625 | int i = 0; |
Tony Lindgren | 1dbae81 | 2005-11-10 14:26:51 +0000 | [diff] [blame] | 626 | |
Kevin Hilman | 6f251e9 | 2010-09-27 20:19:38 +0530 | [diff] [blame] | 627 | do { |
| 628 | char oh_name[MAX_UART_HWMOD_NAME_LEN]; |
| 629 | struct omap_hwmod *oh; |
| 630 | struct omap_uart_state *uart; |
Thomas Weber | 21b9034 | 2010-02-25 09:40:19 +0000 | [diff] [blame] | 631 | |
Kevin Hilman | 6f251e9 | 2010-09-27 20:19:38 +0530 | [diff] [blame] | 632 | snprintf(oh_name, MAX_UART_HWMOD_NAME_LEN, |
| 633 | "uart%d", i + 1); |
| 634 | oh = omap_hwmod_lookup(oh_name); |
| 635 | if (!oh) |
| 636 | break; |
Tony Lindgren | 1dbae81 | 2005-11-10 14:26:51 +0000 | [diff] [blame] | 637 | |
Kevin Hilman | 6f251e9 | 2010-09-27 20:19:38 +0530 | [diff] [blame] | 638 | uart = kzalloc(sizeof(struct omap_uart_state), GFP_KERNEL); |
| 639 | if (WARN_ON(!uart)) |
| 640 | return; |
Tony Lindgren | 1dbae81 | 2005-11-10 14:26:51 +0000 | [diff] [blame] | 641 | |
Kevin Hilman | 6f251e9 | 2010-09-27 20:19:38 +0530 | [diff] [blame] | 642 | uart->oh = oh; |
| 643 | uart->num = i++; |
| 644 | list_add_tail(&uart->node, &uart_list); |
| 645 | num_uarts++; |
| 646 | |
Tony Lindgren | 84f90c9 | 2009-10-16 09:53:00 -0700 | [diff] [blame] | 647 | /* |
Kevin Hilman | 6f251e9 | 2010-09-27 20:19:38 +0530 | [diff] [blame] | 648 | * NOTE: omap_hwmod_init() has not yet been called, |
| 649 | * so no hwmod functions will work yet. |
Tony Lindgren | 84f90c9 | 2009-10-16 09:53:00 -0700 | [diff] [blame] | 650 | */ |
Tony Lindgren | 84f90c9 | 2009-10-16 09:53:00 -0700 | [diff] [blame] | 651 | |
Kevin Hilman | 6f251e9 | 2010-09-27 20:19:38 +0530 | [diff] [blame] | 652 | /* |
| 653 | * During UART early init, device need to be probed |
| 654 | * to determine SoC specific init before omap_device |
| 655 | * is ready. Therefore, don't allow idle here |
| 656 | */ |
| 657 | uart->oh->flags |= HWMOD_INIT_NO_IDLE | HWMOD_INIT_NO_RESET; |
| 658 | } while (1); |
Paul Walmsley | b3c6df3 | 2009-09-03 20:14:02 +0300 | [diff] [blame] | 659 | } |
| 660 | |
Mika Westerberg | f62349e | 2009-12-11 16:16:35 -0800 | [diff] [blame] | 661 | /** |
| 662 | * omap_serial_init_port() - initialize single serial port |
| 663 | * @port: serial port number (0-3) |
| 664 | * |
| 665 | * This function initialies serial driver for given @port only. |
| 666 | * Platforms can call this function instead of omap_serial_init() |
| 667 | * if they don't plan to use all available UARTs as serial ports. |
| 668 | * |
| 669 | * Don't mix calls to omap_serial_init_port() and omap_serial_init(), |
| 670 | * use only one of the two. |
| 671 | */ |
| 672 | void __init omap_serial_init_port(int port) |
| 673 | { |
| 674 | struct omap_uart_state *uart; |
Kevin Hilman | 6f251e9 | 2010-09-27 20:19:38 +0530 | [diff] [blame] | 675 | struct omap_hwmod *oh; |
| 676 | struct omap_device *od; |
| 677 | void *pdata = NULL; |
| 678 | u32 pdata_size = 0; |
| 679 | char *name; |
| 680 | #ifndef CONFIG_SERIAL_OMAP |
| 681 | struct plat_serial8250_port ports[2] = { |
| 682 | {}, |
| 683 | {.flags = 0}, |
| 684 | }; |
| 685 | struct plat_serial8250_port *p = &ports[0]; |
| 686 | #else |
| 687 | struct omap_uart_port_info omap_up; |
| 688 | #endif |
Mika Westerberg | f62349e | 2009-12-11 16:16:35 -0800 | [diff] [blame] | 689 | |
Kevin Hilman | 6f251e9 | 2010-09-27 20:19:38 +0530 | [diff] [blame] | 690 | if (WARN_ON(port < 0)) |
Sergio Aguirre | e88d556 | 2010-02-27 14:13:43 -0600 | [diff] [blame] | 691 | return; |
Kevin Hilman | 6f251e9 | 2010-09-27 20:19:38 +0530 | [diff] [blame] | 692 | if (WARN_ON(port >= num_uarts)) |
Mika Westerberg | f62349e | 2009-12-11 16:16:35 -0800 | [diff] [blame] | 693 | return; |
| 694 | |
Kevin Hilman | 6f251e9 | 2010-09-27 20:19:38 +0530 | [diff] [blame] | 695 | list_for_each_entry(uart, &uart_list, node) |
| 696 | if (port == uart->num) |
| 697 | break; |
| 698 | |
| 699 | oh = uart->oh; |
| 700 | uart->dma_enabled = 0; |
| 701 | #ifndef CONFIG_SERIAL_OMAP |
| 702 | name = "serial8250"; |
| 703 | |
| 704 | /* |
| 705 | * !! 8250 driver does not use standard IORESOURCE* It |
| 706 | * has it's own custom pdata that can be taken from |
| 707 | * the hwmod resource data. But, this needs to be |
| 708 | * done after the build. |
| 709 | * |
| 710 | * ?? does it have to be done before the register ?? |
| 711 | * YES, because platform_device_data_add() copies |
| 712 | * pdata, it does not use a pointer. |
| 713 | */ |
| 714 | p->flags = UPF_BOOT_AUTOCONF; |
| 715 | p->iotype = UPIO_MEM; |
| 716 | p->regshift = 2; |
| 717 | p->uartclk = OMAP24XX_BASE_BAUD * 16; |
| 718 | p->irq = oh->mpu_irqs[0].irq; |
| 719 | p->mapbase = oh->slaves[0]->addr->pa_start; |
| 720 | p->membase = omap_hwmod_get_mpu_rt_va(oh); |
| 721 | p->irqflags = IRQF_SHARED; |
| 722 | p->private_data = uart; |
Mika Westerberg | f62349e | 2009-12-11 16:16:35 -0800 | [diff] [blame] | 723 | |
vikram pandita | 30e53bc | 2010-02-15 10:03:33 -0800 | [diff] [blame] | 724 | /* |
| 725 | * omap44xx: Never read empty UART fifo |
| 726 | * omap3xxx: Never read empty UART fifo on UARTs |
| 727 | * with IP rev >=0x52 |
| 728 | */ |
Kevin Hilman | 6f251e9 | 2010-09-27 20:19:38 +0530 | [diff] [blame] | 729 | uart->regshift = p->regshift; |
| 730 | uart->membase = p->membase; |
Nishanth Menon | 5a927b3 | 2010-08-02 13:18:12 +0300 | [diff] [blame] | 731 | if (cpu_is_omap44xx()) |
| 732 | uart->errata |= UART_ERRATA_FIFO_FULL_ABORT; |
Kevin Hilman | 6f251e9 | 2010-09-27 20:19:38 +0530 | [diff] [blame] | 733 | else if ((serial_read_reg(uart, UART_OMAP_MVER) & 0xFF) |
Nishanth Menon | 5a927b3 | 2010-08-02 13:18:12 +0300 | [diff] [blame] | 734 | >= UART_OMAP_NO_EMPTY_FIFO_READ_IP_REV) |
| 735 | uart->errata |= UART_ERRATA_FIFO_FULL_ABORT; |
| 736 | |
| 737 | if (uart->errata & UART_ERRATA_FIFO_FULL_ABORT) { |
Kevin Hilman | 6f251e9 | 2010-09-27 20:19:38 +0530 | [diff] [blame] | 738 | p->serial_in = serial_in_override; |
| 739 | p->serial_out = serial_out_override; |
| 740 | } |
| 741 | |
| 742 | pdata = &ports[0]; |
| 743 | pdata_size = 2 * sizeof(struct plat_serial8250_port); |
| 744 | #else |
| 745 | |
| 746 | name = DRIVER_NAME; |
| 747 | |
| 748 | omap_up.dma_enabled = uart->dma_enabled; |
| 749 | omap_up.uartclk = OMAP24XX_BASE_BAUD * 16; |
| 750 | omap_up.mapbase = oh->slaves[0]->addr->pa_start; |
| 751 | omap_up.membase = omap_hwmod_get_mpu_rt_va(oh); |
| 752 | omap_up.irqflags = IRQF_SHARED; |
| 753 | omap_up.flags = UPF_BOOT_AUTOCONF | UPF_SHARE_IRQ; |
| 754 | |
| 755 | pdata = &omap_up; |
| 756 | pdata_size = sizeof(struct omap_uart_port_info); |
| 757 | #endif |
| 758 | |
| 759 | if (WARN_ON(!oh)) |
| 760 | return; |
| 761 | |
| 762 | od = omap_device_build(name, uart->num, oh, pdata, pdata_size, |
| 763 | omap_uart_latency, |
| 764 | ARRAY_SIZE(omap_uart_latency), false); |
| 765 | WARN(IS_ERR(od), "Could not build omap_device for %s: %s.\n", |
| 766 | name, oh->name); |
| 767 | |
| 768 | uart->irq = oh->mpu_irqs[0].irq; |
| 769 | uart->regshift = 2; |
| 770 | uart->mapbase = oh->slaves[0]->addr->pa_start; |
| 771 | uart->membase = omap_hwmod_get_mpu_rt_va(oh); |
| 772 | uart->pdev = &od->pdev; |
| 773 | |
| 774 | oh->dev_attr = uart; |
| 775 | |
| 776 | /* |
| 777 | * Because of early UART probing, UART did not get idled |
| 778 | * on init. Now that omap_device is ready, ensure full idle |
| 779 | * before doing omap_device_enable(). |
| 780 | */ |
| 781 | omap_hwmod_idle(uart->oh); |
| 782 | |
| 783 | omap_device_enable(uart->pdev); |
| 784 | omap_uart_idle_init(uart); |
| 785 | omap_uart_reset(uart); |
| 786 | omap_hwmod_enable_wakeup(uart->oh); |
| 787 | omap_device_idle(uart->pdev); |
| 788 | |
| 789 | /* |
| 790 | * Need to block sleep long enough for interrupt driven |
| 791 | * driver to start. Console driver is in polling mode |
| 792 | * so device needs to be kept enabled while polling driver |
| 793 | * is in use. |
| 794 | */ |
| 795 | if (uart->timeout) |
| 796 | uart->timeout = (30 * HZ); |
| 797 | omap_uart_block_sleep(uart); |
| 798 | uart->timeout = DEFAULT_TIMEOUT; |
| 799 | |
| 800 | if ((cpu_is_omap34xx() && uart->padconf) || |
| 801 | (uart->wk_en && uart->wk_mask)) { |
| 802 | device_init_wakeup(&od->pdev.dev, true); |
| 803 | DEV_CREATE_FILE(&od->pdev.dev, &dev_attr_sleep_timeout); |
Santosh Shilimkar | e03d37d | 2010-02-18 08:59:06 +0000 | [diff] [blame] | 804 | } |
Deepak K | 0003450 | 2010-08-02 13:18:12 +0300 | [diff] [blame] | 805 | |
| 806 | /* Enable the MDR1 errata for OMAP3 */ |
| 807 | if (cpu_is_omap34xx()) |
| 808 | uart->errata |= UART_ERRATA_i202_MDR1_ACCESS; |
Mika Westerberg | f62349e | 2009-12-11 16:16:35 -0800 | [diff] [blame] | 809 | } |
| 810 | |
| 811 | /** |
| 812 | * omap_serial_init() - intialize all supported serial ports |
| 813 | * |
| 814 | * Initializes all available UARTs as serial ports. Platforms |
| 815 | * can call this function when they want to have default behaviour |
| 816 | * for serial ports (e.g initialize them all as serial ports). |
| 817 | */ |
Paul Walmsley | b3c6df3 | 2009-09-03 20:14:02 +0300 | [diff] [blame] | 818 | void __init omap_serial_init(void) |
| 819 | { |
Kevin Hilman | 6f251e9 | 2010-09-27 20:19:38 +0530 | [diff] [blame] | 820 | struct omap_uart_state *uart; |
Paul Walmsley | b3c6df3 | 2009-09-03 20:14:02 +0300 | [diff] [blame] | 821 | |
Kevin Hilman | 6f251e9 | 2010-09-27 20:19:38 +0530 | [diff] [blame] | 822 | list_for_each_entry(uart, &uart_list, node) |
| 823 | omap_serial_init_port(uart->num); |
Tony Lindgren | 1dbae81 | 2005-11-10 14:26:51 +0000 | [diff] [blame] | 824 | } |