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> |
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> |
Santosh Shilimkar | e03d37d | 2010-02-18 08:59:06 +0000 | [diff] [blame] | 24 | #include <linux/delay.h> |
Kevin Hilman | 6f251e9 | 2010-09-27 20:19:38 +0530 | [diff] [blame] | 25 | #include <linux/platform_device.h> |
| 26 | #include <linux/slab.h> |
Kevin Hilman | 3244fcd | 2010-09-27 20:19:53 +0530 | [diff] [blame] | 27 | #include <linux/pm_runtime.h> |
Paul Walmsley | 0d8e2d0 | 2010-11-24 16:49:05 -0700 | [diff] [blame] | 28 | #include <linux/console.h> |
Kevin Hilman | 6f251e9 | 2010-09-27 20:19:38 +0530 | [diff] [blame] | 29 | |
Kevin Hilman | 6f251e9 | 2010-09-27 20:19:38 +0530 | [diff] [blame] | 30 | #include <plat/omap-serial.h> |
Tony Lindgren | 4e65331 | 2011-11-10 22:45:17 +0100 | [diff] [blame] | 31 | #include "common.h" |
Tony Lindgren | ce491cf | 2009-10-20 09:40:47 -0700 | [diff] [blame] | 32 | #include <plat/board.h> |
Kevin Hilman | 6f251e9 | 2010-09-27 20:19:38 +0530 | [diff] [blame] | 33 | #include <plat/dma.h> |
| 34 | #include <plat/omap_hwmod.h> |
| 35 | #include <plat/omap_device.h> |
Tony Lindgren | 1dbae81 | 2005-11-10 14:26:51 +0000 | [diff] [blame] | 36 | |
Paul Walmsley | 59fb659 | 2010-12-21 15:30:55 -0700 | [diff] [blame] | 37 | #include "prm2xxx_3xxx.h" |
Kevin Hilman | 4af4016 | 2009-02-04 10:51:40 -0800 | [diff] [blame] | 38 | #include "pm.h" |
Paul Walmsley | 59fb659 | 2010-12-21 15:30:55 -0700 | [diff] [blame] | 39 | #include "cm2xxx_3xxx.h" |
Kevin Hilman | 4af4016 | 2009-02-04 10:51:40 -0800 | [diff] [blame] | 40 | #include "prm-regbits-34xx.h" |
Paul Walmsley | 4814ced | 2010-10-08 11:40:20 -0600 | [diff] [blame] | 41 | #include "control.h" |
Tony Lindgren | 40e4439 | 2010-12-22 18:42:35 -0800 | [diff] [blame] | 42 | #include "mux.h" |
Kevin Hilman | 4af4016 | 2009-02-04 10:51:40 -0800 | [diff] [blame] | 43 | |
| 44 | #define UART_OMAP_WER 0x17 /* Wake-up enable register */ |
| 45 | |
Deepak K | 0003450 | 2010-08-02 13:18:12 +0300 | [diff] [blame] | 46 | #define UART_ERRATA_i202_MDR1_ACCESS (0x1 << 1) |
Nishanth Menon | 5a927b3 | 2010-08-02 13:18:12 +0300 | [diff] [blame] | 47 | |
Tony Lindgren | 301fe8e | 2010-02-01 12:34:31 -0800 | [diff] [blame] | 48 | /* |
| 49 | * NOTE: By default the serial timeout is disabled as it causes lost characters |
| 50 | * over the serial ports. This means that the UART clocks will stay on until |
| 51 | * disabled via sysfs. This also causes that any deeper omap sleep states are |
| 52 | * blocked. |
| 53 | */ |
| 54 | #define DEFAULT_TIMEOUT 0 |
Kevin Hilman | 4af4016 | 2009-02-04 10:51:40 -0800 | [diff] [blame] | 55 | |
Kevin Hilman | 6f251e9 | 2010-09-27 20:19:38 +0530 | [diff] [blame] | 56 | #define MAX_UART_HWMOD_NAME_LEN 16 |
| 57 | |
Kevin Hilman | 4af4016 | 2009-02-04 10:51:40 -0800 | [diff] [blame] | 58 | struct omap_uart_state { |
| 59 | int num; |
| 60 | int can_sleep; |
| 61 | struct timer_list timer; |
| 62 | u32 timeout; |
| 63 | |
| 64 | void __iomem *wk_st; |
| 65 | void __iomem *wk_en; |
| 66 | u32 wk_mask; |
| 67 | u32 padconf; |
Kevin Hilman | 6f251e9 | 2010-09-27 20:19:38 +0530 | [diff] [blame] | 68 | u32 dma_enabled; |
Kevin Hilman | 4af4016 | 2009-02-04 10:51:40 -0800 | [diff] [blame] | 69 | |
| 70 | struct clk *ick; |
| 71 | struct clk *fck; |
| 72 | int clocked; |
| 73 | |
Kevin Hilman | 6f251e9 | 2010-09-27 20:19:38 +0530 | [diff] [blame] | 74 | int irq; |
| 75 | int regshift; |
| 76 | int irqflags; |
| 77 | void __iomem *membase; |
| 78 | resource_size_t mapbase; |
| 79 | |
Kevin Hilman | 4af4016 | 2009-02-04 10:51:40 -0800 | [diff] [blame] | 80 | struct list_head node; |
Kevin Hilman | 6f251e9 | 2010-09-27 20:19:38 +0530 | [diff] [blame] | 81 | struct omap_hwmod *oh; |
| 82 | struct platform_device *pdev; |
Kevin Hilman | 4af4016 | 2009-02-04 10:51:40 -0800 | [diff] [blame] | 83 | |
Nishanth Menon | 5a927b3 | 2010-08-02 13:18:12 +0300 | [diff] [blame] | 84 | u32 errata; |
Kevin Hilman | 4af4016 | 2009-02-04 10:51:40 -0800 | [diff] [blame] | 85 | #if defined(CONFIG_ARCH_OMAP3) && defined(CONFIG_PM) |
| 86 | int context_valid; |
| 87 | |
| 88 | /* Registers to be saved/restored for OFF-mode */ |
| 89 | u16 dll; |
| 90 | u16 dlh; |
| 91 | u16 ier; |
| 92 | u16 sysc; |
| 93 | u16 scr; |
| 94 | u16 wer; |
Govindraj R | 5ade4ff | 2010-08-02 13:18:11 +0300 | [diff] [blame] | 95 | u16 mcr; |
Kevin Hilman | 4af4016 | 2009-02-04 10:51:40 -0800 | [diff] [blame] | 96 | #endif |
| 97 | }; |
| 98 | |
Kevin Hilman | 4af4016 | 2009-02-04 10:51:40 -0800 | [diff] [blame] | 99 | static LIST_HEAD(uart_list); |
Kevin Hilman | 6f251e9 | 2010-09-27 20:19:38 +0530 | [diff] [blame] | 100 | static u8 num_uarts; |
Tony Lindgren | 1dbae81 | 2005-11-10 14:26:51 +0000 | [diff] [blame] | 101 | |
Alexander Shishkin | 9230372 | 2010-01-08 10:29:06 -0800 | [diff] [blame] | 102 | static inline unsigned int __serial_read_reg(struct uart_port *up, |
Kevin Hilman | 6f251e9 | 2010-09-27 20:19:38 +0530 | [diff] [blame] | 103 | int offset) |
Alexander Shishkin | 9230372 | 2010-01-08 10:29:06 -0800 | [diff] [blame] | 104 | { |
| 105 | offset <<= up->regshift; |
| 106 | return (unsigned int)__raw_readb(up->membase + offset); |
| 107 | } |
| 108 | |
Kevin Hilman | 6f251e9 | 2010-09-27 20:19:38 +0530 | [diff] [blame] | 109 | static inline unsigned int serial_read_reg(struct omap_uart_state *uart, |
Tony Lindgren | 1dbae81 | 2005-11-10 14:26:51 +0000 | [diff] [blame] | 110 | int offset) |
| 111 | { |
Kevin Hilman | 6f251e9 | 2010-09-27 20:19:38 +0530 | [diff] [blame] | 112 | offset <<= uart->regshift; |
| 113 | return (unsigned int)__raw_readb(uart->membase + offset); |
Tony Lindgren | 1dbae81 | 2005-11-10 14:26:51 +0000 | [diff] [blame] | 114 | } |
| 115 | |
Santosh Shilimkar | e03d37d | 2010-02-18 08:59:06 +0000 | [diff] [blame] | 116 | static inline void __serial_write_reg(struct uart_port *up, int offset, |
| 117 | int value) |
| 118 | { |
| 119 | offset <<= up->regshift; |
| 120 | __raw_writeb(value, up->membase + offset); |
| 121 | } |
| 122 | |
Kevin Hilman | 6f251e9 | 2010-09-27 20:19:38 +0530 | [diff] [blame] | 123 | 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] | 124 | int value) |
| 125 | { |
Kevin Hilman | 6f251e9 | 2010-09-27 20:19:38 +0530 | [diff] [blame] | 126 | offset <<= uart->regshift; |
| 127 | __raw_writeb(value, uart->membase + offset); |
Tony Lindgren | 1dbae81 | 2005-11-10 14:26:51 +0000 | [diff] [blame] | 128 | } |
| 129 | |
| 130 | /* |
| 131 | * Internal UARTs need to be initialized for the 8250 autoconfig to work |
| 132 | * properly. Note that the TX watermark initialization may not be needed |
| 133 | * once the 8250.c watermark handling code is merged. |
| 134 | */ |
Kevin Hilman | 6f251e9 | 2010-09-27 20:19:38 +0530 | [diff] [blame] | 135 | |
Kevin Hilman | 4af4016 | 2009-02-04 10:51:40 -0800 | [diff] [blame] | 136 | static inline void __init omap_uart_reset(struct omap_uart_state *uart) |
Tony Lindgren | 1dbae81 | 2005-11-10 14:26:51 +0000 | [diff] [blame] | 137 | { |
Andrei Emeltchenko | 498cb95 | 2010-11-30 14:11:49 -0800 | [diff] [blame] | 138 | serial_write_reg(uart, UART_OMAP_MDR1, UART_OMAP_MDR1_DISABLE); |
Kevin Hilman | 6f251e9 | 2010-09-27 20:19:38 +0530 | [diff] [blame] | 139 | serial_write_reg(uart, UART_OMAP_SCR, 0x08); |
Andrei Emeltchenko | 498cb95 | 2010-11-30 14:11:49 -0800 | [diff] [blame] | 140 | serial_write_reg(uart, UART_OMAP_MDR1, UART_OMAP_MDR1_16X_MODE); |
Tony Lindgren | 1dbae81 | 2005-11-10 14:26:51 +0000 | [diff] [blame] | 141 | } |
| 142 | |
Kevin Hilman | 4af4016 | 2009-02-04 10:51:40 -0800 | [diff] [blame] | 143 | #if defined(CONFIG_PM) && defined(CONFIG_ARCH_OMAP3) |
| 144 | |
Deepak K | 0003450 | 2010-08-02 13:18:12 +0300 | [diff] [blame] | 145 | /* |
| 146 | * Work Around for Errata i202 (3430 - 1.12, 3630 - 1.6) |
| 147 | * The access to uart register after MDR1 Access |
| 148 | * causes UART to corrupt data. |
| 149 | * |
| 150 | * Need a delay = |
| 151 | * 5 L4 clock cycles + 5 UART functional clock cycle (@48MHz = ~0.2uS) |
| 152 | * give 10 times as much |
| 153 | */ |
| 154 | static void omap_uart_mdr1_errataset(struct omap_uart_state *uart, u8 mdr1_val, |
| 155 | u8 fcr_val) |
| 156 | { |
Deepak K | 0003450 | 2010-08-02 13:18:12 +0300 | [diff] [blame] | 157 | u8 timeout = 255; |
| 158 | |
Kevin Hilman | 6f251e9 | 2010-09-27 20:19:38 +0530 | [diff] [blame] | 159 | serial_write_reg(uart, UART_OMAP_MDR1, mdr1_val); |
Deepak K | 0003450 | 2010-08-02 13:18:12 +0300 | [diff] [blame] | 160 | udelay(2); |
Kevin Hilman | 6f251e9 | 2010-09-27 20:19:38 +0530 | [diff] [blame] | 161 | serial_write_reg(uart, UART_FCR, fcr_val | UART_FCR_CLEAR_XMIT | |
Deepak K | 0003450 | 2010-08-02 13:18:12 +0300 | [diff] [blame] | 162 | UART_FCR_CLEAR_RCVR); |
| 163 | /* |
| 164 | * Wait for FIFO to empty: when empty, RX_FIFO_E bit is 0 and |
| 165 | * TX_FIFO_E bit is 1. |
| 166 | */ |
Kevin Hilman | 6f251e9 | 2010-09-27 20:19:38 +0530 | [diff] [blame] | 167 | while (UART_LSR_THRE != (serial_read_reg(uart, UART_LSR) & |
Deepak K | 0003450 | 2010-08-02 13:18:12 +0300 | [diff] [blame] | 168 | (UART_LSR_THRE | UART_LSR_DR))) { |
| 169 | timeout--; |
| 170 | if (!timeout) { |
| 171 | /* Should *never* happen. we warn and carry on */ |
Kevin Hilman | 6f251e9 | 2010-09-27 20:19:38 +0530 | [diff] [blame] | 172 | dev_crit(&uart->pdev->dev, "Errata i202: timedout %x\n", |
| 173 | serial_read_reg(uart, UART_LSR)); |
Deepak K | 0003450 | 2010-08-02 13:18:12 +0300 | [diff] [blame] | 174 | break; |
| 175 | } |
| 176 | udelay(1); |
| 177 | } |
| 178 | } |
| 179 | |
Kevin Hilman | 4af4016 | 2009-02-04 10:51:40 -0800 | [diff] [blame] | 180 | static void omap_uart_save_context(struct omap_uart_state *uart) |
Jouni Hogander | 6e81176 | 2008-10-06 15:49:15 +0300 | [diff] [blame] | 181 | { |
Kevin Hilman | 4af4016 | 2009-02-04 10:51:40 -0800 | [diff] [blame] | 182 | u16 lcr = 0; |
Kevin Hilman | 4af4016 | 2009-02-04 10:51:40 -0800 | [diff] [blame] | 183 | |
| 184 | if (!enable_off_mode) |
| 185 | return; |
| 186 | |
Kevin Hilman | 6f251e9 | 2010-09-27 20:19:38 +0530 | [diff] [blame] | 187 | lcr = serial_read_reg(uart, UART_LCR); |
Andrei Emeltchenko | 662b083a | 2010-11-30 14:11:49 -0800 | [diff] [blame] | 188 | serial_write_reg(uart, UART_LCR, UART_LCR_CONF_MODE_B); |
Kevin Hilman | 6f251e9 | 2010-09-27 20:19:38 +0530 | [diff] [blame] | 189 | uart->dll = serial_read_reg(uart, UART_DLL); |
| 190 | uart->dlh = serial_read_reg(uart, UART_DLM); |
| 191 | serial_write_reg(uart, UART_LCR, lcr); |
| 192 | uart->ier = serial_read_reg(uart, UART_IER); |
| 193 | uart->sysc = serial_read_reg(uart, UART_OMAP_SYSC); |
| 194 | uart->scr = serial_read_reg(uart, UART_OMAP_SCR); |
| 195 | uart->wer = serial_read_reg(uart, UART_OMAP_WER); |
Andrei Emeltchenko | 662b083a | 2010-11-30 14:11:49 -0800 | [diff] [blame] | 196 | serial_write_reg(uart, UART_LCR, UART_LCR_CONF_MODE_A); |
Kevin Hilman | 6f251e9 | 2010-09-27 20:19:38 +0530 | [diff] [blame] | 197 | uart->mcr = serial_read_reg(uart, UART_MCR); |
| 198 | serial_write_reg(uart, UART_LCR, lcr); |
Kevin Hilman | 4af4016 | 2009-02-04 10:51:40 -0800 | [diff] [blame] | 199 | |
| 200 | uart->context_valid = 1; |
| 201 | } |
| 202 | |
| 203 | static void omap_uart_restore_context(struct omap_uart_state *uart) |
| 204 | { |
| 205 | u16 efr = 0; |
Kevin Hilman | 4af4016 | 2009-02-04 10:51:40 -0800 | [diff] [blame] | 206 | |
| 207 | if (!enable_off_mode) |
| 208 | return; |
| 209 | |
| 210 | if (!uart->context_valid) |
| 211 | return; |
| 212 | |
| 213 | uart->context_valid = 0; |
| 214 | |
Deepak K | 0003450 | 2010-08-02 13:18:12 +0300 | [diff] [blame] | 215 | if (uart->errata & UART_ERRATA_i202_MDR1_ACCESS) |
Andrei Emeltchenko | 498cb95 | 2010-11-30 14:11:49 -0800 | [diff] [blame] | 216 | omap_uart_mdr1_errataset(uart, UART_OMAP_MDR1_DISABLE, 0xA0); |
Deepak K | 0003450 | 2010-08-02 13:18:12 +0300 | [diff] [blame] | 217 | else |
Andrei Emeltchenko | 498cb95 | 2010-11-30 14:11:49 -0800 | [diff] [blame] | 218 | serial_write_reg(uart, UART_OMAP_MDR1, UART_OMAP_MDR1_DISABLE); |
| 219 | |
Andrei Emeltchenko | 662b083a | 2010-11-30 14:11:49 -0800 | [diff] [blame] | 220 | serial_write_reg(uart, UART_LCR, UART_LCR_CONF_MODE_B); |
Kevin Hilman | 6f251e9 | 2010-09-27 20:19:38 +0530 | [diff] [blame] | 221 | efr = serial_read_reg(uart, UART_EFR); |
| 222 | serial_write_reg(uart, UART_EFR, UART_EFR_ECB); |
| 223 | serial_write_reg(uart, UART_LCR, 0x0); /* Operational mode */ |
| 224 | serial_write_reg(uart, UART_IER, 0x0); |
Andrei Emeltchenko | 662b083a | 2010-11-30 14:11:49 -0800 | [diff] [blame] | 225 | serial_write_reg(uart, UART_LCR, UART_LCR_CONF_MODE_B); |
Kevin Hilman | 6f251e9 | 2010-09-27 20:19:38 +0530 | [diff] [blame] | 226 | serial_write_reg(uart, UART_DLL, uart->dll); |
| 227 | serial_write_reg(uart, UART_DLM, uart->dlh); |
| 228 | serial_write_reg(uart, UART_LCR, 0x0); /* Operational mode */ |
| 229 | serial_write_reg(uart, UART_IER, uart->ier); |
Andrei Emeltchenko | 662b083a | 2010-11-30 14:11:49 -0800 | [diff] [blame] | 230 | serial_write_reg(uart, UART_LCR, UART_LCR_CONF_MODE_A); |
Kevin Hilman | 6f251e9 | 2010-09-27 20:19:38 +0530 | [diff] [blame] | 231 | serial_write_reg(uart, UART_MCR, uart->mcr); |
Andrei Emeltchenko | 662b083a | 2010-11-30 14:11:49 -0800 | [diff] [blame] | 232 | serial_write_reg(uart, UART_LCR, UART_LCR_CONF_MODE_B); |
Kevin Hilman | 6f251e9 | 2010-09-27 20:19:38 +0530 | [diff] [blame] | 233 | serial_write_reg(uart, UART_EFR, efr); |
| 234 | serial_write_reg(uart, UART_LCR, UART_LCR_WLEN8); |
| 235 | serial_write_reg(uart, UART_OMAP_SCR, uart->scr); |
| 236 | serial_write_reg(uart, UART_OMAP_WER, uart->wer); |
| 237 | serial_write_reg(uart, UART_OMAP_SYSC, uart->sysc); |
Andrei Emeltchenko | 498cb95 | 2010-11-30 14:11:49 -0800 | [diff] [blame] | 238 | |
Deepak K | 0003450 | 2010-08-02 13:18:12 +0300 | [diff] [blame] | 239 | if (uart->errata & UART_ERRATA_i202_MDR1_ACCESS) |
Andrei Emeltchenko | 498cb95 | 2010-11-30 14:11:49 -0800 | [diff] [blame] | 240 | omap_uart_mdr1_errataset(uart, UART_OMAP_MDR1_16X_MODE, 0xA1); |
Deepak K | 0003450 | 2010-08-02 13:18:12 +0300 | [diff] [blame] | 241 | else |
Kevin Hilman | 6f251e9 | 2010-09-27 20:19:38 +0530 | [diff] [blame] | 242 | /* UART 16x mode */ |
Andrei Emeltchenko | 498cb95 | 2010-11-30 14:11:49 -0800 | [diff] [blame] | 243 | serial_write_reg(uart, UART_OMAP_MDR1, |
| 244 | UART_OMAP_MDR1_16X_MODE); |
Kevin Hilman | 4af4016 | 2009-02-04 10:51:40 -0800 | [diff] [blame] | 245 | } |
| 246 | #else |
| 247 | static inline void omap_uart_save_context(struct omap_uart_state *uart) {} |
| 248 | static inline void omap_uart_restore_context(struct omap_uart_state *uart) {} |
| 249 | #endif /* CONFIG_PM && CONFIG_ARCH_OMAP3 */ |
| 250 | |
| 251 | static inline void omap_uart_enable_clocks(struct omap_uart_state *uart) |
| 252 | { |
| 253 | if (uart->clocked) |
| 254 | return; |
| 255 | |
Kevin Hilman | 6f251e9 | 2010-09-27 20:19:38 +0530 | [diff] [blame] | 256 | omap_device_enable(uart->pdev); |
Kevin Hilman | 4af4016 | 2009-02-04 10:51:40 -0800 | [diff] [blame] | 257 | uart->clocked = 1; |
| 258 | omap_uart_restore_context(uart); |
| 259 | } |
| 260 | |
| 261 | #ifdef CONFIG_PM |
| 262 | |
| 263 | static inline void omap_uart_disable_clocks(struct omap_uart_state *uart) |
| 264 | { |
| 265 | if (!uart->clocked) |
| 266 | return; |
| 267 | |
| 268 | omap_uart_save_context(uart); |
| 269 | uart->clocked = 0; |
Kevin Hilman | 6f251e9 | 2010-09-27 20:19:38 +0530 | [diff] [blame] | 270 | omap_device_idle(uart->pdev); |
Kevin Hilman | 4af4016 | 2009-02-04 10:51:40 -0800 | [diff] [blame] | 271 | } |
| 272 | |
Kevin Hilman | fd455ea | 2009-04-27 12:27:36 -0700 | [diff] [blame] | 273 | static void omap_uart_enable_wakeup(struct omap_uart_state *uart) |
| 274 | { |
| 275 | /* Set wake-enable bit */ |
| 276 | if (uart->wk_en && uart->wk_mask) { |
| 277 | u32 v = __raw_readl(uart->wk_en); |
| 278 | v |= uart->wk_mask; |
| 279 | __raw_writel(v, uart->wk_en); |
| 280 | } |
| 281 | |
| 282 | /* Ensure IOPAD wake-enables are set */ |
| 283 | if (cpu_is_omap34xx() && uart->padconf) { |
| 284 | u16 v = omap_ctrl_readw(uart->padconf); |
| 285 | v |= OMAP3_PADCONF_WAKEUPENABLE0; |
| 286 | omap_ctrl_writew(v, uart->padconf); |
| 287 | } |
| 288 | } |
| 289 | |
| 290 | static void omap_uart_disable_wakeup(struct omap_uart_state *uart) |
| 291 | { |
| 292 | /* Clear wake-enable bit */ |
| 293 | if (uart->wk_en && uart->wk_mask) { |
| 294 | u32 v = __raw_readl(uart->wk_en); |
| 295 | v &= ~uart->wk_mask; |
| 296 | __raw_writel(v, uart->wk_en); |
| 297 | } |
| 298 | |
| 299 | /* Ensure IOPAD wake-enables are cleared */ |
| 300 | if (cpu_is_omap34xx() && uart->padconf) { |
| 301 | u16 v = omap_ctrl_readw(uart->padconf); |
| 302 | v &= ~OMAP3_PADCONF_WAKEUPENABLE0; |
| 303 | omap_ctrl_writew(v, uart->padconf); |
| 304 | } |
| 305 | } |
| 306 | |
Kevin Hilman | 4af4016 | 2009-02-04 10:51:40 -0800 | [diff] [blame] | 307 | static void omap_uart_smart_idle_enable(struct omap_uart_state *uart, |
Kevin Hilman | 6f251e9 | 2010-09-27 20:19:38 +0530 | [diff] [blame] | 308 | int enable) |
Kevin Hilman | 4af4016 | 2009-02-04 10:51:40 -0800 | [diff] [blame] | 309 | { |
Kevin Hilman | 6f251e9 | 2010-09-27 20:19:38 +0530 | [diff] [blame] | 310 | u8 idlemode; |
Kevin Hilman | 4af4016 | 2009-02-04 10:51:40 -0800 | [diff] [blame] | 311 | |
Kevin Hilman | 6f251e9 | 2010-09-27 20:19:38 +0530 | [diff] [blame] | 312 | if (enable) { |
| 313 | /** |
| 314 | * Errata 2.15: [UART]:Cannot Acknowledge Idle Requests |
| 315 | * in Smartidle Mode When Configured for DMA Operations. |
| 316 | */ |
| 317 | if (uart->dma_enabled) |
| 318 | idlemode = HWMOD_IDLEMODE_FORCE; |
| 319 | else |
| 320 | idlemode = HWMOD_IDLEMODE_SMART; |
| 321 | } else { |
| 322 | idlemode = HWMOD_IDLEMODE_NO; |
| 323 | } |
Kevin Hilman | 4af4016 | 2009-02-04 10:51:40 -0800 | [diff] [blame] | 324 | |
Kevin Hilman | 6f251e9 | 2010-09-27 20:19:38 +0530 | [diff] [blame] | 325 | omap_hwmod_set_slave_idlemode(uart->oh, idlemode); |
Kevin Hilman | 4af4016 | 2009-02-04 10:51:40 -0800 | [diff] [blame] | 326 | } |
| 327 | |
| 328 | static void omap_uart_block_sleep(struct omap_uart_state *uart) |
| 329 | { |
| 330 | omap_uart_enable_clocks(uart); |
| 331 | |
| 332 | omap_uart_smart_idle_enable(uart, 0); |
| 333 | uart->can_sleep = 0; |
Jouni Hogander | ba87a9b | 2008-12-09 13:36:50 +0200 | [diff] [blame] | 334 | if (uart->timeout) |
| 335 | mod_timer(&uart->timer, jiffies + uart->timeout); |
| 336 | else |
| 337 | del_timer(&uart->timer); |
Kevin Hilman | 4af4016 | 2009-02-04 10:51:40 -0800 | [diff] [blame] | 338 | } |
| 339 | |
| 340 | static void omap_uart_allow_sleep(struct omap_uart_state *uart) |
| 341 | { |
Kevin Hilman | 6f251e9 | 2010-09-27 20:19:38 +0530 | [diff] [blame] | 342 | if (device_may_wakeup(&uart->pdev->dev)) |
Kevin Hilman | fd455ea | 2009-04-27 12:27:36 -0700 | [diff] [blame] | 343 | omap_uart_enable_wakeup(uart); |
| 344 | else |
| 345 | omap_uart_disable_wakeup(uart); |
| 346 | |
Kevin Hilman | 4af4016 | 2009-02-04 10:51:40 -0800 | [diff] [blame] | 347 | if (!uart->clocked) |
| 348 | return; |
| 349 | |
| 350 | omap_uart_smart_idle_enable(uart, 1); |
| 351 | uart->can_sleep = 1; |
| 352 | del_timer(&uart->timer); |
| 353 | } |
| 354 | |
| 355 | static void omap_uart_idle_timer(unsigned long data) |
| 356 | { |
| 357 | struct omap_uart_state *uart = (struct omap_uart_state *)data; |
| 358 | |
| 359 | omap_uart_allow_sleep(uart); |
| 360 | } |
| 361 | |
Kevin Hilman | 4af4016 | 2009-02-04 10:51:40 -0800 | [diff] [blame] | 362 | int omap_uart_can_sleep(void) |
| 363 | { |
| 364 | struct omap_uart_state *uart; |
| 365 | int can_sleep = 1; |
| 366 | |
| 367 | list_for_each_entry(uart, &uart_list, node) { |
| 368 | if (!uart->clocked) |
| 369 | continue; |
| 370 | |
| 371 | if (!uart->can_sleep) { |
| 372 | can_sleep = 0; |
| 373 | continue; |
| 374 | } |
| 375 | |
| 376 | /* This UART can now safely sleep. */ |
| 377 | omap_uart_allow_sleep(uart); |
| 378 | } |
| 379 | |
| 380 | return can_sleep; |
| 381 | } |
| 382 | |
| 383 | /** |
| 384 | * omap_uart_interrupt() |
| 385 | * |
| 386 | * This handler is used only to detect that *any* UART interrupt has |
| 387 | * occurred. It does _nothing_ to handle the interrupt. Rather, |
| 388 | * any UART interrupt will trigger the inactivity timer so the |
| 389 | * UART will not idle or sleep for its timeout period. |
| 390 | * |
| 391 | **/ |
Kevin Hilman | 6f251e9 | 2010-09-27 20:19:38 +0530 | [diff] [blame] | 392 | /* static int first_interrupt; */ |
Kevin Hilman | 4af4016 | 2009-02-04 10:51:40 -0800 | [diff] [blame] | 393 | static irqreturn_t omap_uart_interrupt(int irq, void *dev_id) |
| 394 | { |
| 395 | struct omap_uart_state *uart = dev_id; |
| 396 | |
| 397 | omap_uart_block_sleep(uart); |
| 398 | |
| 399 | return IRQ_NONE; |
| 400 | } |
| 401 | |
| 402 | static void omap_uart_idle_init(struct omap_uart_state *uart) |
| 403 | { |
Kevin Hilman | 4af4016 | 2009-02-04 10:51:40 -0800 | [diff] [blame] | 404 | int ret; |
| 405 | |
| 406 | uart->can_sleep = 0; |
Kevin Hilman | fd455ea | 2009-04-27 12:27:36 -0700 | [diff] [blame] | 407 | uart->timeout = DEFAULT_TIMEOUT; |
Kevin Hilman | 4af4016 | 2009-02-04 10:51:40 -0800 | [diff] [blame] | 408 | setup_timer(&uart->timer, omap_uart_idle_timer, |
| 409 | (unsigned long) uart); |
Tony Lindgren | 301fe8e | 2010-02-01 12:34:31 -0800 | [diff] [blame] | 410 | if (uart->timeout) |
| 411 | mod_timer(&uart->timer, jiffies + uart->timeout); |
Kevin Hilman | 4af4016 | 2009-02-04 10:51:40 -0800 | [diff] [blame] | 412 | omap_uart_smart_idle_enable(uart, 0); |
| 413 | |
Hemant Pedanekar | a920360 | 2011-12-13 10:46:44 -0800 | [diff] [blame] | 414 | if (cpu_is_omap34xx() && !(cpu_is_ti81xx() || cpu_is_am33xx())) { |
Govindraj.R | 52663ae | 2010-09-27 20:20:41 +0530 | [diff] [blame] | 415 | u32 mod = (uart->num > 1) ? OMAP3430_PER_MOD : CORE_MOD; |
Kevin Hilman | 4af4016 | 2009-02-04 10:51:40 -0800 | [diff] [blame] | 416 | u32 wk_mask = 0; |
| 417 | u32 padconf = 0; |
| 418 | |
Paul Walmsley | c4d7e58 | 2010-12-21 21:05:14 -0700 | [diff] [blame] | 419 | /* XXX These PRM accesses do not belong here */ |
Kevin Hilman | 4af4016 | 2009-02-04 10:51:40 -0800 | [diff] [blame] | 420 | uart->wk_en = OMAP34XX_PRM_REGADDR(mod, PM_WKEN1); |
| 421 | uart->wk_st = OMAP34XX_PRM_REGADDR(mod, PM_WKST1); |
| 422 | switch (uart->num) { |
| 423 | case 0: |
| 424 | wk_mask = OMAP3430_ST_UART1_MASK; |
| 425 | padconf = 0x182; |
| 426 | break; |
| 427 | case 1: |
| 428 | wk_mask = OMAP3430_ST_UART2_MASK; |
| 429 | padconf = 0x17a; |
| 430 | break; |
| 431 | case 2: |
| 432 | wk_mask = OMAP3430_ST_UART3_MASK; |
| 433 | padconf = 0x19e; |
| 434 | break; |
Govindraj.R | 52663ae | 2010-09-27 20:20:41 +0530 | [diff] [blame] | 435 | case 3: |
| 436 | wk_mask = OMAP3630_ST_UART4_MASK; |
| 437 | padconf = 0x0d2; |
| 438 | break; |
Kevin Hilman | 4af4016 | 2009-02-04 10:51:40 -0800 | [diff] [blame] | 439 | } |
| 440 | uart->wk_mask = wk_mask; |
| 441 | uart->padconf = padconf; |
| 442 | } else if (cpu_is_omap24xx()) { |
| 443 | u32 wk_mask = 0; |
Kevin Hilman | cb74f02 | 2010-10-20 23:19:03 +0000 | [diff] [blame] | 444 | u32 wk_en = PM_WKEN1, wk_st = PM_WKST1; |
Kevin Hilman | 4af4016 | 2009-02-04 10:51:40 -0800 | [diff] [blame] | 445 | |
Kevin Hilman | 4af4016 | 2009-02-04 10:51:40 -0800 | [diff] [blame] | 446 | switch (uart->num) { |
| 447 | case 0: |
| 448 | wk_mask = OMAP24XX_ST_UART1_MASK; |
| 449 | break; |
| 450 | case 1: |
| 451 | wk_mask = OMAP24XX_ST_UART2_MASK; |
| 452 | break; |
| 453 | case 2: |
Kevin Hilman | cb74f02 | 2010-10-20 23:19:03 +0000 | [diff] [blame] | 454 | wk_en = OMAP24XX_PM_WKEN2; |
| 455 | wk_st = OMAP24XX_PM_WKST2; |
Kevin Hilman | 4af4016 | 2009-02-04 10:51:40 -0800 | [diff] [blame] | 456 | wk_mask = OMAP24XX_ST_UART3_MASK; |
| 457 | break; |
| 458 | } |
| 459 | uart->wk_mask = wk_mask; |
Kevin Hilman | cb74f02 | 2010-10-20 23:19:03 +0000 | [diff] [blame] | 460 | if (cpu_is_omap2430()) { |
| 461 | uart->wk_en = OMAP2430_PRM_REGADDR(CORE_MOD, wk_en); |
| 462 | uart->wk_st = OMAP2430_PRM_REGADDR(CORE_MOD, wk_st); |
| 463 | } else if (cpu_is_omap2420()) { |
| 464 | uart->wk_en = OMAP2420_PRM_REGADDR(CORE_MOD, wk_en); |
| 465 | uart->wk_st = OMAP2420_PRM_REGADDR(CORE_MOD, wk_st); |
| 466 | } |
Kevin Hilman | 4af4016 | 2009-02-04 10:51:40 -0800 | [diff] [blame] | 467 | } else { |
Nishanth Menon | c54bae1 | 2010-08-02 13:18:11 +0300 | [diff] [blame] | 468 | uart->wk_en = NULL; |
| 469 | uart->wk_st = NULL; |
Kevin Hilman | 4af4016 | 2009-02-04 10:51:40 -0800 | [diff] [blame] | 470 | uart->wk_mask = 0; |
| 471 | uart->padconf = 0; |
| 472 | } |
| 473 | |
Kevin Hilman | 6f251e9 | 2010-09-27 20:19:38 +0530 | [diff] [blame] | 474 | uart->irqflags |= IRQF_SHARED; |
| 475 | ret = request_threaded_irq(uart->irq, NULL, omap_uart_interrupt, |
| 476 | IRQF_SHARED, "serial idle", (void *)uart); |
Kevin Hilman | 4af4016 | 2009-02-04 10:51:40 -0800 | [diff] [blame] | 477 | WARN_ON(ret); |
| 478 | } |
| 479 | |
Kevin Hilman | fd455ea | 2009-04-27 12:27:36 -0700 | [diff] [blame] | 480 | static ssize_t sleep_timeout_show(struct device *dev, |
| 481 | struct device_attribute *attr, |
Jouni Hogander | ba87a9b | 2008-12-09 13:36:50 +0200 | [diff] [blame] | 482 | char *buf) |
| 483 | { |
Kevin Hilman | 6f251e9 | 2010-09-27 20:19:38 +0530 | [diff] [blame] | 484 | struct platform_device *pdev = to_platform_device(dev); |
| 485 | struct omap_device *odev = to_omap_device(pdev); |
| 486 | struct omap_uart_state *uart = odev->hwmods[0]->dev_attr; |
Kevin Hilman | fd455ea | 2009-04-27 12:27:36 -0700 | [diff] [blame] | 487 | |
| 488 | return sprintf(buf, "%u\n", uart->timeout / HZ); |
Jouni Hogander | ba87a9b | 2008-12-09 13:36:50 +0200 | [diff] [blame] | 489 | } |
| 490 | |
Kevin Hilman | fd455ea | 2009-04-27 12:27:36 -0700 | [diff] [blame] | 491 | static ssize_t sleep_timeout_store(struct device *dev, |
| 492 | struct device_attribute *attr, |
Jouni Hogander | ba87a9b | 2008-12-09 13:36:50 +0200 | [diff] [blame] | 493 | const char *buf, size_t n) |
| 494 | { |
Kevin Hilman | 6f251e9 | 2010-09-27 20:19:38 +0530 | [diff] [blame] | 495 | struct platform_device *pdev = to_platform_device(dev); |
| 496 | struct omap_device *odev = to_omap_device(pdev); |
| 497 | struct omap_uart_state *uart = odev->hwmods[0]->dev_attr; |
Jouni Hogander | ba87a9b | 2008-12-09 13:36:50 +0200 | [diff] [blame] | 498 | unsigned int value; |
| 499 | |
| 500 | if (sscanf(buf, "%u", &value) != 1) { |
Sergio Aguirre | 10c805e | 2010-03-09 13:22:14 -0600 | [diff] [blame] | 501 | dev_err(dev, "sleep_timeout_store: Invalid value\n"); |
Jouni Hogander | ba87a9b | 2008-12-09 13:36:50 +0200 | [diff] [blame] | 502 | return -EINVAL; |
| 503 | } |
Kevin Hilman | fd455ea | 2009-04-27 12:27:36 -0700 | [diff] [blame] | 504 | |
| 505 | uart->timeout = value * HZ; |
| 506 | if (uart->timeout) |
| 507 | mod_timer(&uart->timer, jiffies + uart->timeout); |
| 508 | else |
| 509 | /* A zero value means disable timeout feature */ |
| 510 | omap_uart_block_sleep(uart); |
| 511 | |
Jouni Hogander | ba87a9b | 2008-12-09 13:36:50 +0200 | [diff] [blame] | 512 | return n; |
| 513 | } |
| 514 | |
Nishanth Menon | bfe6977 | 2010-08-02 13:18:12 +0300 | [diff] [blame] | 515 | static DEVICE_ATTR(sleep_timeout, 0644, sleep_timeout_show, |
| 516 | sleep_timeout_store); |
Kevin Hilman | fd455ea | 2009-04-27 12:27:36 -0700 | [diff] [blame] | 517 | #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] | 518 | #else |
| 519 | static inline void omap_uart_idle_init(struct omap_uart_state *uart) {} |
Santosh Shilimkar | a1b04cc | 2010-10-11 11:05:18 +0000 | [diff] [blame] | 520 | static void omap_uart_block_sleep(struct omap_uart_state *uart) |
| 521 | { |
| 522 | /* Needed to enable UART clocks when built without CONFIG_PM */ |
| 523 | omap_uart_enable_clocks(uart); |
| 524 | } |
Kevin Hilman | fd455ea | 2009-04-27 12:27:36 -0700 | [diff] [blame] | 525 | #define DEV_CREATE_FILE(dev, attr) |
Kevin Hilman | 4af4016 | 2009-02-04 10:51:40 -0800 | [diff] [blame] | 526 | #endif /* CONFIG_PM */ |
| 527 | |
Tony Lindgren | 3e16f92 | 2011-02-14 15:40:20 -0800 | [diff] [blame] | 528 | static int __init omap_serial_early_init(void) |
Tony Lindgren | 1dbae81 | 2005-11-10 14:26:51 +0000 | [diff] [blame] | 529 | { |
Kevin Hilman | 6f251e9 | 2010-09-27 20:19:38 +0530 | [diff] [blame] | 530 | int i = 0; |
Tony Lindgren | 1dbae81 | 2005-11-10 14:26:51 +0000 | [diff] [blame] | 531 | |
Kevin Hilman | 6f251e9 | 2010-09-27 20:19:38 +0530 | [diff] [blame] | 532 | do { |
| 533 | char oh_name[MAX_UART_HWMOD_NAME_LEN]; |
| 534 | struct omap_hwmod *oh; |
| 535 | struct omap_uart_state *uart; |
Thomas Weber | 21b9034 | 2010-02-25 09:40:19 +0000 | [diff] [blame] | 536 | |
Kevin Hilman | 6f251e9 | 2010-09-27 20:19:38 +0530 | [diff] [blame] | 537 | snprintf(oh_name, MAX_UART_HWMOD_NAME_LEN, |
| 538 | "uart%d", i + 1); |
| 539 | oh = omap_hwmod_lookup(oh_name); |
| 540 | if (!oh) |
| 541 | break; |
Tony Lindgren | 1dbae81 | 2005-11-10 14:26:51 +0000 | [diff] [blame] | 542 | |
Kevin Hilman | 6f251e9 | 2010-09-27 20:19:38 +0530 | [diff] [blame] | 543 | uart = kzalloc(sizeof(struct omap_uart_state), GFP_KERNEL); |
| 544 | if (WARN_ON(!uart)) |
Tony Lindgren | 3e16f92 | 2011-02-14 15:40:20 -0800 | [diff] [blame] | 545 | return -ENODEV; |
Tony Lindgren | 1dbae81 | 2005-11-10 14:26:51 +0000 | [diff] [blame] | 546 | |
Kevin Hilman | 6f251e9 | 2010-09-27 20:19:38 +0530 | [diff] [blame] | 547 | uart->oh = oh; |
| 548 | uart->num = i++; |
| 549 | list_add_tail(&uart->node, &uart_list); |
| 550 | num_uarts++; |
| 551 | |
Tony Lindgren | 84f90c9 | 2009-10-16 09:53:00 -0700 | [diff] [blame] | 552 | /* |
Paul Walmsley | 550c809 | 2011-02-28 11:58:14 -0700 | [diff] [blame] | 553 | * NOTE: omap_hwmod_setup*() has not yet been called, |
Kevin Hilman | 6f251e9 | 2010-09-27 20:19:38 +0530 | [diff] [blame] | 554 | * so no hwmod functions will work yet. |
Tony Lindgren | 84f90c9 | 2009-10-16 09:53:00 -0700 | [diff] [blame] | 555 | */ |
Tony Lindgren | 84f90c9 | 2009-10-16 09:53:00 -0700 | [diff] [blame] | 556 | |
Kevin Hilman | 6f251e9 | 2010-09-27 20:19:38 +0530 | [diff] [blame] | 557 | /* |
| 558 | * During UART early init, device need to be probed |
| 559 | * to determine SoC specific init before omap_device |
| 560 | * is ready. Therefore, don't allow idle here |
| 561 | */ |
| 562 | uart->oh->flags |= HWMOD_INIT_NO_IDLE | HWMOD_INIT_NO_RESET; |
| 563 | } while (1); |
Tony Lindgren | 3e16f92 | 2011-02-14 15:40:20 -0800 | [diff] [blame] | 564 | |
| 565 | return 0; |
Paul Walmsley | b3c6df3 | 2009-09-03 20:14:02 +0300 | [diff] [blame] | 566 | } |
Tony Lindgren | 3e16f92 | 2011-02-14 15:40:20 -0800 | [diff] [blame] | 567 | core_initcall(omap_serial_early_init); |
Paul Walmsley | b3c6df3 | 2009-09-03 20:14:02 +0300 | [diff] [blame] | 568 | |
Mika Westerberg | f62349e | 2009-12-11 16:16:35 -0800 | [diff] [blame] | 569 | /** |
| 570 | * omap_serial_init_port() - initialize single serial port |
Tony Lindgren | 40e4439 | 2010-12-22 18:42:35 -0800 | [diff] [blame] | 571 | * @bdata: port specific board data pointer |
Mika Westerberg | f62349e | 2009-12-11 16:16:35 -0800 | [diff] [blame] | 572 | * |
Tony Lindgren | 40e4439 | 2010-12-22 18:42:35 -0800 | [diff] [blame] | 573 | * This function initialies serial driver for given port only. |
Mika Westerberg | f62349e | 2009-12-11 16:16:35 -0800 | [diff] [blame] | 574 | * Platforms can call this function instead of omap_serial_init() |
| 575 | * if they don't plan to use all available UARTs as serial ports. |
| 576 | * |
| 577 | * Don't mix calls to omap_serial_init_port() and omap_serial_init(), |
| 578 | * use only one of the two. |
| 579 | */ |
Tony Lindgren | 40e4439 | 2010-12-22 18:42:35 -0800 | [diff] [blame] | 580 | void __init omap_serial_init_port(struct omap_board_data *bdata) |
Mika Westerberg | f62349e | 2009-12-11 16:16:35 -0800 | [diff] [blame] | 581 | { |
| 582 | struct omap_uart_state *uart; |
Kevin Hilman | 6f251e9 | 2010-09-27 20:19:38 +0530 | [diff] [blame] | 583 | struct omap_hwmod *oh; |
Kevin Hilman | 3528c58 | 2011-07-21 13:48:45 -0700 | [diff] [blame] | 584 | struct platform_device *pdev; |
Kevin Hilman | 6f251e9 | 2010-09-27 20:19:38 +0530 | [diff] [blame] | 585 | void *pdata = NULL; |
| 586 | u32 pdata_size = 0; |
| 587 | char *name; |
Kevin Hilman | 6f251e9 | 2010-09-27 20:19:38 +0530 | [diff] [blame] | 588 | struct omap_uart_port_info omap_up; |
Mika Westerberg | f62349e | 2009-12-11 16:16:35 -0800 | [diff] [blame] | 589 | |
Tony Lindgren | 40e4439 | 2010-12-22 18:42:35 -0800 | [diff] [blame] | 590 | if (WARN_ON(!bdata)) |
Sergio Aguirre | e88d556 | 2010-02-27 14:13:43 -0600 | [diff] [blame] | 591 | return; |
Tony Lindgren | 40e4439 | 2010-12-22 18:42:35 -0800 | [diff] [blame] | 592 | if (WARN_ON(bdata->id < 0)) |
| 593 | return; |
| 594 | if (WARN_ON(bdata->id >= num_uarts)) |
Mika Westerberg | f62349e | 2009-12-11 16:16:35 -0800 | [diff] [blame] | 595 | return; |
| 596 | |
Kevin Hilman | 6f251e9 | 2010-09-27 20:19:38 +0530 | [diff] [blame] | 597 | list_for_each_entry(uart, &uart_list, node) |
Tony Lindgren | 40e4439 | 2010-12-22 18:42:35 -0800 | [diff] [blame] | 598 | if (bdata->id == uart->num) |
Kevin Hilman | 6f251e9 | 2010-09-27 20:19:38 +0530 | [diff] [blame] | 599 | break; |
| 600 | |
| 601 | oh = uart->oh; |
| 602 | uart->dma_enabled = 0; |
Kevin Hilman | 6f251e9 | 2010-09-27 20:19:38 +0530 | [diff] [blame] | 603 | name = DRIVER_NAME; |
| 604 | |
| 605 | omap_up.dma_enabled = uart->dma_enabled; |
| 606 | omap_up.uartclk = OMAP24XX_BASE_BAUD * 16; |
| 607 | omap_up.mapbase = oh->slaves[0]->addr->pa_start; |
| 608 | omap_up.membase = omap_hwmod_get_mpu_rt_va(oh); |
| 609 | omap_up.irqflags = IRQF_SHARED; |
| 610 | omap_up.flags = UPF_BOOT_AUTOCONF | UPF_SHARE_IRQ; |
| 611 | |
| 612 | pdata = &omap_up; |
| 613 | pdata_size = sizeof(struct omap_uart_port_info); |
Kevin Hilman | 6f251e9 | 2010-09-27 20:19:38 +0530 | [diff] [blame] | 614 | |
| 615 | if (WARN_ON(!oh)) |
| 616 | return; |
| 617 | |
Kevin Hilman | 3528c58 | 2011-07-21 13:48:45 -0700 | [diff] [blame] | 618 | pdev = omap_device_build(name, uart->num, oh, pdata, pdata_size, |
Benoit Cousson | f718e2c | 2011-08-10 15:30:09 +0200 | [diff] [blame] | 619 | NULL, 0, false); |
Kevin Hilman | 3528c58 | 2011-07-21 13:48:45 -0700 | [diff] [blame] | 620 | WARN(IS_ERR(pdev), "Could not build omap_device for %s: %s.\n", |
Kevin Hilman | 6f251e9 | 2010-09-27 20:19:38 +0530 | [diff] [blame] | 621 | name, oh->name); |
| 622 | |
Kevin Hilman | 9f8b694 | 2011-08-01 09:33:13 -0700 | [diff] [blame] | 623 | omap_device_disable_idle_on_suspend(pdev); |
Tony Lindgren | 40e4439 | 2010-12-22 18:42:35 -0800 | [diff] [blame] | 624 | oh->mux = omap_hwmod_mux_init(bdata->pads, bdata->pads_cnt); |
| 625 | |
Kevin Hilman | 6f251e9 | 2010-09-27 20:19:38 +0530 | [diff] [blame] | 626 | uart->irq = oh->mpu_irqs[0].irq; |
| 627 | uart->regshift = 2; |
| 628 | uart->mapbase = oh->slaves[0]->addr->pa_start; |
| 629 | uart->membase = omap_hwmod_get_mpu_rt_va(oh); |
Kevin Hilman | 3528c58 | 2011-07-21 13:48:45 -0700 | [diff] [blame] | 630 | uart->pdev = pdev; |
Kevin Hilman | 6f251e9 | 2010-09-27 20:19:38 +0530 | [diff] [blame] | 631 | |
| 632 | oh->dev_attr = uart; |
| 633 | |
Torben Hohn | ac751ef | 2011-01-25 15:07:35 -0800 | [diff] [blame] | 634 | console_lock(); /* in case the earlycon is on the UART */ |
Paul Walmsley | 0d8e2d0 | 2010-11-24 16:49:05 -0700 | [diff] [blame] | 635 | |
Kevin Hilman | 6f251e9 | 2010-09-27 20:19:38 +0530 | [diff] [blame] | 636 | /* |
| 637 | * Because of early UART probing, UART did not get idled |
| 638 | * on init. Now that omap_device is ready, ensure full idle |
| 639 | * before doing omap_device_enable(). |
| 640 | */ |
| 641 | omap_hwmod_idle(uart->oh); |
| 642 | |
| 643 | omap_device_enable(uart->pdev); |
| 644 | omap_uart_idle_init(uart); |
| 645 | omap_uart_reset(uart); |
| 646 | omap_hwmod_enable_wakeup(uart->oh); |
| 647 | omap_device_idle(uart->pdev); |
| 648 | |
| 649 | /* |
| 650 | * Need to block sleep long enough for interrupt driven |
| 651 | * driver to start. Console driver is in polling mode |
| 652 | * so device needs to be kept enabled while polling driver |
| 653 | * is in use. |
| 654 | */ |
| 655 | if (uart->timeout) |
| 656 | uart->timeout = (30 * HZ); |
| 657 | omap_uart_block_sleep(uart); |
| 658 | uart->timeout = DEFAULT_TIMEOUT; |
| 659 | |
Torben Hohn | ac751ef | 2011-01-25 15:07:35 -0800 | [diff] [blame] | 660 | console_unlock(); |
Paul Walmsley | 0d8e2d0 | 2010-11-24 16:49:05 -0700 | [diff] [blame] | 661 | |
Kevin Hilman | 6f251e9 | 2010-09-27 20:19:38 +0530 | [diff] [blame] | 662 | if ((cpu_is_omap34xx() && uart->padconf) || |
| 663 | (uart->wk_en && uart->wk_mask)) { |
Kevin Hilman | 3528c58 | 2011-07-21 13:48:45 -0700 | [diff] [blame] | 664 | device_init_wakeup(&pdev->dev, true); |
| 665 | DEV_CREATE_FILE(&pdev->dev, &dev_attr_sleep_timeout); |
Santosh Shilimkar | e03d37d | 2010-02-18 08:59:06 +0000 | [diff] [blame] | 666 | } |
Deepak K | 0003450 | 2010-08-02 13:18:12 +0300 | [diff] [blame] | 667 | |
| 668 | /* Enable the MDR1 errata for OMAP3 */ |
Hemant Pedanekar | a920360 | 2011-12-13 10:46:44 -0800 | [diff] [blame] | 669 | if (cpu_is_omap34xx() && !(cpu_is_ti81xx() || cpu_is_am33xx())) |
Deepak K | 0003450 | 2010-08-02 13:18:12 +0300 | [diff] [blame] | 670 | uart->errata |= UART_ERRATA_i202_MDR1_ACCESS; |
Mika Westerberg | f62349e | 2009-12-11 16:16:35 -0800 | [diff] [blame] | 671 | } |
| 672 | |
| 673 | /** |
Uwe Kleine-König | b595076 | 2010-11-01 15:38:34 -0400 | [diff] [blame] | 674 | * omap_serial_init() - initialize all supported serial ports |
Mika Westerberg | f62349e | 2009-12-11 16:16:35 -0800 | [diff] [blame] | 675 | * |
| 676 | * Initializes all available UARTs as serial ports. Platforms |
| 677 | * can call this function when they want to have default behaviour |
| 678 | * for serial ports (e.g initialize them all as serial ports). |
| 679 | */ |
Paul Walmsley | b3c6df3 | 2009-09-03 20:14:02 +0300 | [diff] [blame] | 680 | void __init omap_serial_init(void) |
| 681 | { |
Kevin Hilman | 6f251e9 | 2010-09-27 20:19:38 +0530 | [diff] [blame] | 682 | struct omap_uart_state *uart; |
Tony Lindgren | 40e4439 | 2010-12-22 18:42:35 -0800 | [diff] [blame] | 683 | struct omap_board_data bdata; |
Paul Walmsley | b3c6df3 | 2009-09-03 20:14:02 +0300 | [diff] [blame] | 684 | |
Tony Lindgren | 40e4439 | 2010-12-22 18:42:35 -0800 | [diff] [blame] | 685 | list_for_each_entry(uart, &uart_list, node) { |
| 686 | bdata.id = uart->num; |
| 687 | bdata.flags = 0; |
| 688 | bdata.pads = NULL; |
| 689 | bdata.pads_cnt = 0; |
| 690 | omap_serial_init_port(&bdata); |
| 691 | |
| 692 | } |
Tony Lindgren | 1dbae81 | 2005-11-10 14:26:51 +0000 | [diff] [blame] | 693 | } |