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> |
Govindraj.R | ec3bebc | 2011-10-11 19:11:27 +0530 | [diff] [blame^] | 36 | #include <plat/omap-pm.h> |
Tony Lindgren | 1dbae81 | 2005-11-10 14:26:51 +0000 | [diff] [blame] | 37 | |
Paul Walmsley | 59fb659 | 2010-12-21 15:30:55 -0700 | [diff] [blame] | 38 | #include "prm2xxx_3xxx.h" |
Kevin Hilman | 4af4016 | 2009-02-04 10:51:40 -0800 | [diff] [blame] | 39 | #include "pm.h" |
Paul Walmsley | 59fb659 | 2010-12-21 15:30:55 -0700 | [diff] [blame] | 40 | #include "cm2xxx_3xxx.h" |
Kevin Hilman | 4af4016 | 2009-02-04 10:51:40 -0800 | [diff] [blame] | 41 | #include "prm-regbits-34xx.h" |
Paul Walmsley | 4814ced | 2010-10-08 11:40:20 -0600 | [diff] [blame] | 42 | #include "control.h" |
Tony Lindgren | 40e4439 | 2010-12-22 18:42:35 -0800 | [diff] [blame] | 43 | #include "mux.h" |
Kevin Hilman | 4af4016 | 2009-02-04 10:51:40 -0800 | [diff] [blame] | 44 | |
Deepak K | 0003450 | 2010-08-02 13:18:12 +0300 | [diff] [blame] | 45 | #define UART_ERRATA_i202_MDR1_ACCESS (0x1 << 1) |
Nishanth Menon | 5a927b3 | 2010-08-02 13:18:12 +0300 | [diff] [blame] | 46 | |
Tony Lindgren | 301fe8e | 2010-02-01 12:34:31 -0800 | [diff] [blame] | 47 | /* |
| 48 | * NOTE: By default the serial timeout is disabled as it causes lost characters |
| 49 | * over the serial ports. This means that the UART clocks will stay on until |
| 50 | * disabled via sysfs. This also causes that any deeper omap sleep states are |
| 51 | * blocked. |
| 52 | */ |
| 53 | #define DEFAULT_TIMEOUT 0 |
Kevin Hilman | 4af4016 | 2009-02-04 10:51:40 -0800 | [diff] [blame] | 54 | |
Kevin Hilman | 6f251e9 | 2010-09-27 20:19:38 +0530 | [diff] [blame] | 55 | #define MAX_UART_HWMOD_NAME_LEN 16 |
| 56 | |
Kevin Hilman | 4af4016 | 2009-02-04 10:51:40 -0800 | [diff] [blame] | 57 | struct omap_uart_state { |
| 58 | int num; |
| 59 | int can_sleep; |
Kevin Hilman | 4af4016 | 2009-02-04 10:51:40 -0800 | [diff] [blame] | 60 | |
| 61 | void __iomem *wk_st; |
| 62 | void __iomem *wk_en; |
| 63 | u32 wk_mask; |
Kevin Hilman | 6f251e9 | 2010-09-27 20:19:38 +0530 | [diff] [blame] | 64 | u32 dma_enabled; |
Kevin Hilman | 4af4016 | 2009-02-04 10:51:40 -0800 | [diff] [blame] | 65 | |
Kevin Hilman | 4af4016 | 2009-02-04 10:51:40 -0800 | [diff] [blame] | 66 | int clocked; |
| 67 | |
Kevin Hilman | 4af4016 | 2009-02-04 10:51:40 -0800 | [diff] [blame] | 68 | struct list_head node; |
Kevin Hilman | 6f251e9 | 2010-09-27 20:19:38 +0530 | [diff] [blame] | 69 | struct omap_hwmod *oh; |
| 70 | struct platform_device *pdev; |
Kevin Hilman | 4af4016 | 2009-02-04 10:51:40 -0800 | [diff] [blame] | 71 | |
Nishanth Menon | 5a927b3 | 2010-08-02 13:18:12 +0300 | [diff] [blame] | 72 | u32 errata; |
Kevin Hilman | 4af4016 | 2009-02-04 10:51:40 -0800 | [diff] [blame] | 73 | }; |
| 74 | |
Kevin Hilman | 4af4016 | 2009-02-04 10:51:40 -0800 | [diff] [blame] | 75 | static LIST_HEAD(uart_list); |
Kevin Hilman | 6f251e9 | 2010-09-27 20:19:38 +0530 | [diff] [blame] | 76 | static u8 num_uarts; |
Tony Lindgren | 1dbae81 | 2005-11-10 14:26:51 +0000 | [diff] [blame] | 77 | |
Kevin Hilman | 4af4016 | 2009-02-04 10:51:40 -0800 | [diff] [blame] | 78 | #if defined(CONFIG_PM) && defined(CONFIG_ARCH_OMAP3) |
| 79 | |
Deepak K | 0003450 | 2010-08-02 13:18:12 +0300 | [diff] [blame] | 80 | /* |
| 81 | * Work Around for Errata i202 (3430 - 1.12, 3630 - 1.6) |
| 82 | * The access to uart register after MDR1 Access |
| 83 | * causes UART to corrupt data. |
| 84 | * |
| 85 | * Need a delay = |
| 86 | * 5 L4 clock cycles + 5 UART functional clock cycle (@48MHz = ~0.2uS) |
| 87 | * give 10 times as much |
| 88 | */ |
| 89 | static void omap_uart_mdr1_errataset(struct omap_uart_state *uart, u8 mdr1_val, |
| 90 | u8 fcr_val) |
| 91 | { |
Deepak K | 0003450 | 2010-08-02 13:18:12 +0300 | [diff] [blame] | 92 | u8 timeout = 255; |
| 93 | |
Kevin Hilman | 6f251e9 | 2010-09-27 20:19:38 +0530 | [diff] [blame] | 94 | serial_write_reg(uart, UART_OMAP_MDR1, mdr1_val); |
Deepak K | 0003450 | 2010-08-02 13:18:12 +0300 | [diff] [blame] | 95 | udelay(2); |
Kevin Hilman | 6f251e9 | 2010-09-27 20:19:38 +0530 | [diff] [blame] | 96 | serial_write_reg(uart, UART_FCR, fcr_val | UART_FCR_CLEAR_XMIT | |
Deepak K | 0003450 | 2010-08-02 13:18:12 +0300 | [diff] [blame] | 97 | UART_FCR_CLEAR_RCVR); |
| 98 | /* |
| 99 | * Wait for FIFO to empty: when empty, RX_FIFO_E bit is 0 and |
| 100 | * TX_FIFO_E bit is 1. |
| 101 | */ |
Kevin Hilman | 6f251e9 | 2010-09-27 20:19:38 +0530 | [diff] [blame] | 102 | while (UART_LSR_THRE != (serial_read_reg(uart, UART_LSR) & |
Deepak K | 0003450 | 2010-08-02 13:18:12 +0300 | [diff] [blame] | 103 | (UART_LSR_THRE | UART_LSR_DR))) { |
| 104 | timeout--; |
| 105 | if (!timeout) { |
| 106 | /* Should *never* happen. we warn and carry on */ |
Kevin Hilman | 6f251e9 | 2010-09-27 20:19:38 +0530 | [diff] [blame] | 107 | dev_crit(&uart->pdev->dev, "Errata i202: timedout %x\n", |
| 108 | serial_read_reg(uart, UART_LSR)); |
Deepak K | 0003450 | 2010-08-02 13:18:12 +0300 | [diff] [blame] | 109 | break; |
| 110 | } |
| 111 | udelay(1); |
| 112 | } |
| 113 | } |
| 114 | |
Kevin Hilman | 4af4016 | 2009-02-04 10:51:40 -0800 | [diff] [blame] | 115 | #endif /* CONFIG_PM && CONFIG_ARCH_OMAP3 */ |
| 116 | |
| 117 | static inline void omap_uart_enable_clocks(struct omap_uart_state *uart) |
| 118 | { |
| 119 | if (uart->clocked) |
| 120 | return; |
| 121 | |
Kevin Hilman | 6f251e9 | 2010-09-27 20:19:38 +0530 | [diff] [blame] | 122 | omap_device_enable(uart->pdev); |
Kevin Hilman | 4af4016 | 2009-02-04 10:51:40 -0800 | [diff] [blame] | 123 | uart->clocked = 1; |
| 124 | omap_uart_restore_context(uart); |
| 125 | } |
| 126 | |
| 127 | #ifdef CONFIG_PM |
| 128 | |
| 129 | static inline void omap_uart_disable_clocks(struct omap_uart_state *uart) |
| 130 | { |
| 131 | if (!uart->clocked) |
| 132 | return; |
| 133 | |
| 134 | omap_uart_save_context(uart); |
| 135 | uart->clocked = 0; |
Kevin Hilman | 6f251e9 | 2010-09-27 20:19:38 +0530 | [diff] [blame] | 136 | omap_device_idle(uart->pdev); |
Kevin Hilman | 4af4016 | 2009-02-04 10:51:40 -0800 | [diff] [blame] | 137 | } |
| 138 | |
Kevin Hilman | fd455ea | 2009-04-27 12:27:36 -0700 | [diff] [blame] | 139 | static void omap_uart_enable_wakeup(struct omap_uart_state *uart) |
| 140 | { |
| 141 | /* Set wake-enable bit */ |
| 142 | if (uart->wk_en && uart->wk_mask) { |
| 143 | u32 v = __raw_readl(uart->wk_en); |
| 144 | v |= uart->wk_mask; |
| 145 | __raw_writel(v, uart->wk_en); |
| 146 | } |
Kevin Hilman | fd455ea | 2009-04-27 12:27:36 -0700 | [diff] [blame] | 147 | } |
| 148 | |
| 149 | static void omap_uart_disable_wakeup(struct omap_uart_state *uart) |
| 150 | { |
| 151 | /* Clear wake-enable bit */ |
| 152 | if (uart->wk_en && uart->wk_mask) { |
| 153 | u32 v = __raw_readl(uart->wk_en); |
| 154 | v &= ~uart->wk_mask; |
| 155 | __raw_writel(v, uart->wk_en); |
| 156 | } |
Kevin Hilman | fd455ea | 2009-04-27 12:27:36 -0700 | [diff] [blame] | 157 | } |
| 158 | |
Kevin Hilman | 4af4016 | 2009-02-04 10:51:40 -0800 | [diff] [blame] | 159 | static void omap_uart_smart_idle_enable(struct omap_uart_state *uart, |
Kevin Hilman | 6f251e9 | 2010-09-27 20:19:38 +0530 | [diff] [blame] | 160 | int enable) |
Kevin Hilman | 4af4016 | 2009-02-04 10:51:40 -0800 | [diff] [blame] | 161 | { |
Kevin Hilman | 6f251e9 | 2010-09-27 20:19:38 +0530 | [diff] [blame] | 162 | u8 idlemode; |
Kevin Hilman | 4af4016 | 2009-02-04 10:51:40 -0800 | [diff] [blame] | 163 | |
Kevin Hilman | 6f251e9 | 2010-09-27 20:19:38 +0530 | [diff] [blame] | 164 | if (enable) { |
| 165 | /** |
| 166 | * Errata 2.15: [UART]:Cannot Acknowledge Idle Requests |
| 167 | * in Smartidle Mode When Configured for DMA Operations. |
| 168 | */ |
| 169 | if (uart->dma_enabled) |
| 170 | idlemode = HWMOD_IDLEMODE_FORCE; |
| 171 | else |
| 172 | idlemode = HWMOD_IDLEMODE_SMART; |
| 173 | } else { |
| 174 | idlemode = HWMOD_IDLEMODE_NO; |
| 175 | } |
Kevin Hilman | 4af4016 | 2009-02-04 10:51:40 -0800 | [diff] [blame] | 176 | |
Kevin Hilman | 6f251e9 | 2010-09-27 20:19:38 +0530 | [diff] [blame] | 177 | omap_hwmod_set_slave_idlemode(uart->oh, idlemode); |
Kevin Hilman | 4af4016 | 2009-02-04 10:51:40 -0800 | [diff] [blame] | 178 | } |
| 179 | |
| 180 | static void omap_uart_block_sleep(struct omap_uart_state *uart) |
| 181 | { |
| 182 | omap_uart_enable_clocks(uart); |
| 183 | |
| 184 | omap_uart_smart_idle_enable(uart, 0); |
| 185 | uart->can_sleep = 0; |
Kevin Hilman | 4af4016 | 2009-02-04 10:51:40 -0800 | [diff] [blame] | 186 | } |
| 187 | |
Kevin Hilman | 4af4016 | 2009-02-04 10:51:40 -0800 | [diff] [blame] | 188 | int omap_uart_can_sleep(void) |
| 189 | { |
| 190 | struct omap_uart_state *uart; |
| 191 | int can_sleep = 1; |
| 192 | |
| 193 | list_for_each_entry(uart, &uart_list, node) { |
| 194 | if (!uart->clocked) |
| 195 | continue; |
| 196 | |
| 197 | if (!uart->can_sleep) { |
| 198 | can_sleep = 0; |
| 199 | continue; |
| 200 | } |
| 201 | |
| 202 | /* This UART can now safely sleep. */ |
| 203 | omap_uart_allow_sleep(uart); |
| 204 | } |
| 205 | |
| 206 | return can_sleep; |
| 207 | } |
| 208 | |
Kevin Hilman | 4af4016 | 2009-02-04 10:51:40 -0800 | [diff] [blame] | 209 | static void omap_uart_idle_init(struct omap_uart_state *uart) |
| 210 | { |
Kevin Hilman | 4af4016 | 2009-02-04 10:51:40 -0800 | [diff] [blame] | 211 | int ret; |
| 212 | |
| 213 | uart->can_sleep = 0; |
Kevin Hilman | 4af4016 | 2009-02-04 10:51:40 -0800 | [diff] [blame] | 214 | omap_uart_smart_idle_enable(uart, 0); |
| 215 | |
Hemant Pedanekar | a920360 | 2011-12-13 10:46:44 -0800 | [diff] [blame] | 216 | if (cpu_is_omap34xx() && !(cpu_is_ti81xx() || cpu_is_am33xx())) { |
Govindraj.R | 52663ae | 2010-09-27 20:20:41 +0530 | [diff] [blame] | 217 | u32 mod = (uart->num > 1) ? OMAP3430_PER_MOD : CORE_MOD; |
Kevin Hilman | 4af4016 | 2009-02-04 10:51:40 -0800 | [diff] [blame] | 218 | u32 wk_mask = 0; |
Kevin Hilman | 4af4016 | 2009-02-04 10:51:40 -0800 | [diff] [blame] | 219 | |
Paul Walmsley | c4d7e58 | 2010-12-21 21:05:14 -0700 | [diff] [blame] | 220 | /* XXX These PRM accesses do not belong here */ |
Kevin Hilman | 4af4016 | 2009-02-04 10:51:40 -0800 | [diff] [blame] | 221 | uart->wk_en = OMAP34XX_PRM_REGADDR(mod, PM_WKEN1); |
| 222 | uart->wk_st = OMAP34XX_PRM_REGADDR(mod, PM_WKST1); |
| 223 | switch (uart->num) { |
| 224 | case 0: |
| 225 | wk_mask = OMAP3430_ST_UART1_MASK; |
Kevin Hilman | 4af4016 | 2009-02-04 10:51:40 -0800 | [diff] [blame] | 226 | break; |
| 227 | case 1: |
| 228 | wk_mask = OMAP3430_ST_UART2_MASK; |
Kevin Hilman | 4af4016 | 2009-02-04 10:51:40 -0800 | [diff] [blame] | 229 | break; |
| 230 | case 2: |
| 231 | wk_mask = OMAP3430_ST_UART3_MASK; |
Kevin Hilman | 4af4016 | 2009-02-04 10:51:40 -0800 | [diff] [blame] | 232 | break; |
Govindraj.R | 52663ae | 2010-09-27 20:20:41 +0530 | [diff] [blame] | 233 | case 3: |
| 234 | wk_mask = OMAP3630_ST_UART4_MASK; |
Govindraj.R | 52663ae | 2010-09-27 20:20:41 +0530 | [diff] [blame] | 235 | break; |
Kevin Hilman | 4af4016 | 2009-02-04 10:51:40 -0800 | [diff] [blame] | 236 | } |
| 237 | uart->wk_mask = wk_mask; |
Kevin Hilman | 4af4016 | 2009-02-04 10:51:40 -0800 | [diff] [blame] | 238 | } else if (cpu_is_omap24xx()) { |
| 239 | u32 wk_mask = 0; |
Kevin Hilman | cb74f02 | 2010-10-20 23:19:03 +0000 | [diff] [blame] | 240 | u32 wk_en = PM_WKEN1, wk_st = PM_WKST1; |
Kevin Hilman | 4af4016 | 2009-02-04 10:51:40 -0800 | [diff] [blame] | 241 | |
Kevin Hilman | 4af4016 | 2009-02-04 10:51:40 -0800 | [diff] [blame] | 242 | switch (uart->num) { |
| 243 | case 0: |
| 244 | wk_mask = OMAP24XX_ST_UART1_MASK; |
| 245 | break; |
| 246 | case 1: |
| 247 | wk_mask = OMAP24XX_ST_UART2_MASK; |
| 248 | break; |
| 249 | case 2: |
Kevin Hilman | cb74f02 | 2010-10-20 23:19:03 +0000 | [diff] [blame] | 250 | wk_en = OMAP24XX_PM_WKEN2; |
| 251 | wk_st = OMAP24XX_PM_WKST2; |
Kevin Hilman | 4af4016 | 2009-02-04 10:51:40 -0800 | [diff] [blame] | 252 | wk_mask = OMAP24XX_ST_UART3_MASK; |
| 253 | break; |
| 254 | } |
| 255 | uart->wk_mask = wk_mask; |
Kevin Hilman | cb74f02 | 2010-10-20 23:19:03 +0000 | [diff] [blame] | 256 | if (cpu_is_omap2430()) { |
| 257 | uart->wk_en = OMAP2430_PRM_REGADDR(CORE_MOD, wk_en); |
| 258 | uart->wk_st = OMAP2430_PRM_REGADDR(CORE_MOD, wk_st); |
| 259 | } else if (cpu_is_omap2420()) { |
| 260 | uart->wk_en = OMAP2420_PRM_REGADDR(CORE_MOD, wk_en); |
| 261 | uart->wk_st = OMAP2420_PRM_REGADDR(CORE_MOD, wk_st); |
| 262 | } |
Kevin Hilman | 4af4016 | 2009-02-04 10:51:40 -0800 | [diff] [blame] | 263 | } else { |
Nishanth Menon | c54bae1 | 2010-08-02 13:18:11 +0300 | [diff] [blame] | 264 | uart->wk_en = NULL; |
| 265 | uart->wk_st = NULL; |
Kevin Hilman | 4af4016 | 2009-02-04 10:51:40 -0800 | [diff] [blame] | 266 | uart->wk_mask = 0; |
Kevin Hilman | 4af4016 | 2009-02-04 10:51:40 -0800 | [diff] [blame] | 267 | } |
Kevin Hilman | 4af4016 | 2009-02-04 10:51:40 -0800 | [diff] [blame] | 268 | } |
| 269 | |
| 270 | #else |
Santosh Shilimkar | a1b04cc | 2010-10-11 11:05:18 +0000 | [diff] [blame] | 271 | static void omap_uart_block_sleep(struct omap_uart_state *uart) |
| 272 | { |
| 273 | /* Needed to enable UART clocks when built without CONFIG_PM */ |
| 274 | omap_uart_enable_clocks(uart); |
| 275 | } |
Kevin Hilman | 4af4016 | 2009-02-04 10:51:40 -0800 | [diff] [blame] | 276 | #endif /* CONFIG_PM */ |
| 277 | |
Govindraj.R | 7496ba3 | 2011-11-07 18:55:05 +0530 | [diff] [blame] | 278 | #ifdef CONFIG_OMAP_MUX |
| 279 | static struct omap_device_pad default_uart1_pads[] __initdata = { |
| 280 | { |
| 281 | .name = "uart1_cts.uart1_cts", |
| 282 | .enable = OMAP_PIN_INPUT_PULLUP | OMAP_MUX_MODE0, |
| 283 | }, |
| 284 | { |
| 285 | .name = "uart1_rts.uart1_rts", |
| 286 | .enable = OMAP_PIN_OUTPUT | OMAP_MUX_MODE0, |
| 287 | }, |
| 288 | { |
| 289 | .name = "uart1_tx.uart1_tx", |
| 290 | .enable = OMAP_PIN_OUTPUT | OMAP_MUX_MODE0, |
| 291 | }, |
| 292 | { |
| 293 | .name = "uart1_rx.uart1_rx", |
| 294 | .flags = OMAP_DEVICE_PAD_REMUX | OMAP_DEVICE_PAD_WAKEUP, |
| 295 | .enable = OMAP_PIN_INPUT_PULLUP | OMAP_MUX_MODE0, |
| 296 | .idle = OMAP_PIN_INPUT_PULLUP | OMAP_MUX_MODE0, |
| 297 | }, |
| 298 | }; |
| 299 | |
| 300 | static struct omap_device_pad default_uart2_pads[] __initdata = { |
| 301 | { |
| 302 | .name = "uart2_cts.uart2_cts", |
| 303 | .enable = OMAP_PIN_INPUT_PULLUP | OMAP_MUX_MODE0, |
| 304 | }, |
| 305 | { |
| 306 | .name = "uart2_rts.uart2_rts", |
| 307 | .enable = OMAP_PIN_OUTPUT | OMAP_MUX_MODE0, |
| 308 | }, |
| 309 | { |
| 310 | .name = "uart2_tx.uart2_tx", |
| 311 | .enable = OMAP_PIN_OUTPUT | OMAP_MUX_MODE0, |
| 312 | }, |
| 313 | { |
| 314 | .name = "uart2_rx.uart2_rx", |
| 315 | .flags = OMAP_DEVICE_PAD_REMUX | OMAP_DEVICE_PAD_WAKEUP, |
| 316 | .enable = OMAP_PIN_INPUT_PULLUP | OMAP_MUX_MODE0, |
| 317 | .idle = OMAP_PIN_INPUT_PULLUP | OMAP_MUX_MODE0, |
| 318 | }, |
| 319 | }; |
| 320 | |
| 321 | static struct omap_device_pad default_uart3_pads[] __initdata = { |
| 322 | { |
| 323 | .name = "uart3_cts_rctx.uart3_cts_rctx", |
| 324 | .enable = OMAP_PIN_INPUT_PULLUP | OMAP_MUX_MODE0, |
| 325 | }, |
| 326 | { |
| 327 | .name = "uart3_rts_sd.uart3_rts_sd", |
| 328 | .enable = OMAP_PIN_OUTPUT | OMAP_MUX_MODE0, |
| 329 | }, |
| 330 | { |
| 331 | .name = "uart3_tx_irtx.uart3_tx_irtx", |
| 332 | .enable = OMAP_PIN_OUTPUT | OMAP_MUX_MODE0, |
| 333 | }, |
| 334 | { |
| 335 | .name = "uart3_rx_irrx.uart3_rx_irrx", |
| 336 | .flags = OMAP_DEVICE_PAD_REMUX | OMAP_DEVICE_PAD_WAKEUP, |
| 337 | .enable = OMAP_PIN_INPUT | OMAP_MUX_MODE0, |
| 338 | .idle = OMAP_PIN_INPUT | OMAP_MUX_MODE0, |
| 339 | }, |
| 340 | }; |
| 341 | |
| 342 | static struct omap_device_pad default_omap36xx_uart4_pads[] __initdata = { |
| 343 | { |
| 344 | .name = "gpmc_wait2.uart4_tx", |
| 345 | .enable = OMAP_PIN_OUTPUT | OMAP_MUX_MODE0, |
| 346 | }, |
| 347 | { |
| 348 | .name = "gpmc_wait3.uart4_rx", |
| 349 | .flags = OMAP_DEVICE_PAD_REMUX | OMAP_DEVICE_PAD_WAKEUP, |
| 350 | .enable = OMAP_PIN_INPUT | OMAP_MUX_MODE2, |
| 351 | .idle = OMAP_PIN_INPUT | OMAP_MUX_MODE2, |
| 352 | }, |
| 353 | }; |
| 354 | |
| 355 | static struct omap_device_pad default_omap4_uart4_pads[] __initdata = { |
| 356 | { |
| 357 | .name = "uart4_tx.uart4_tx", |
| 358 | .enable = OMAP_PIN_OUTPUT | OMAP_MUX_MODE0, |
| 359 | }, |
| 360 | { |
| 361 | .name = "uart4_rx.uart4_rx", |
| 362 | .flags = OMAP_DEVICE_PAD_REMUX | OMAP_DEVICE_PAD_WAKEUP, |
| 363 | .enable = OMAP_PIN_INPUT | OMAP_MUX_MODE0, |
| 364 | .idle = OMAP_PIN_INPUT | OMAP_MUX_MODE0, |
| 365 | }, |
| 366 | }; |
| 367 | |
| 368 | static void omap_serial_fill_default_pads(struct omap_board_data *bdata) |
| 369 | { |
| 370 | switch (bdata->id) { |
| 371 | case 0: |
| 372 | bdata->pads = default_uart1_pads; |
| 373 | bdata->pads_cnt = ARRAY_SIZE(default_uart1_pads); |
| 374 | break; |
| 375 | case 1: |
| 376 | bdata->pads = default_uart2_pads; |
| 377 | bdata->pads_cnt = ARRAY_SIZE(default_uart2_pads); |
| 378 | break; |
| 379 | case 2: |
| 380 | bdata->pads = default_uart3_pads; |
| 381 | bdata->pads_cnt = ARRAY_SIZE(default_uart3_pads); |
| 382 | break; |
| 383 | case 3: |
| 384 | if (cpu_is_omap44xx()) { |
| 385 | bdata->pads = default_omap4_uart4_pads; |
| 386 | bdata->pads_cnt = |
| 387 | ARRAY_SIZE(default_omap4_uart4_pads); |
| 388 | } else if (cpu_is_omap3630()) { |
| 389 | bdata->pads = default_omap36xx_uart4_pads; |
| 390 | bdata->pads_cnt = |
| 391 | ARRAY_SIZE(default_omap36xx_uart4_pads); |
| 392 | } |
| 393 | break; |
| 394 | default: |
| 395 | break; |
| 396 | } |
| 397 | } |
| 398 | #else |
| 399 | static void omap_serial_fill_default_pads(struct omap_board_data *bdata) {} |
| 400 | #endif |
| 401 | |
Tony Lindgren | 3e16f92 | 2011-02-14 15:40:20 -0800 | [diff] [blame] | 402 | static int __init omap_serial_early_init(void) |
Tony Lindgren | 1dbae81 | 2005-11-10 14:26:51 +0000 | [diff] [blame] | 403 | { |
Kevin Hilman | 6f251e9 | 2010-09-27 20:19:38 +0530 | [diff] [blame] | 404 | int i = 0; |
Tony Lindgren | 1dbae81 | 2005-11-10 14:26:51 +0000 | [diff] [blame] | 405 | |
Kevin Hilman | 6f251e9 | 2010-09-27 20:19:38 +0530 | [diff] [blame] | 406 | do { |
| 407 | char oh_name[MAX_UART_HWMOD_NAME_LEN]; |
| 408 | struct omap_hwmod *oh; |
| 409 | struct omap_uart_state *uart; |
Thomas Weber | 21b9034 | 2010-02-25 09:40:19 +0000 | [diff] [blame] | 410 | |
Kevin Hilman | 6f251e9 | 2010-09-27 20:19:38 +0530 | [diff] [blame] | 411 | snprintf(oh_name, MAX_UART_HWMOD_NAME_LEN, |
| 412 | "uart%d", i + 1); |
| 413 | oh = omap_hwmod_lookup(oh_name); |
| 414 | if (!oh) |
| 415 | break; |
Tony Lindgren | 1dbae81 | 2005-11-10 14:26:51 +0000 | [diff] [blame] | 416 | |
Kevin Hilman | 6f251e9 | 2010-09-27 20:19:38 +0530 | [diff] [blame] | 417 | uart = kzalloc(sizeof(struct omap_uart_state), GFP_KERNEL); |
| 418 | if (WARN_ON(!uart)) |
Tony Lindgren | 3e16f92 | 2011-02-14 15:40:20 -0800 | [diff] [blame] | 419 | return -ENODEV; |
Tony Lindgren | 1dbae81 | 2005-11-10 14:26:51 +0000 | [diff] [blame] | 420 | |
Kevin Hilman | 6f251e9 | 2010-09-27 20:19:38 +0530 | [diff] [blame] | 421 | uart->oh = oh; |
| 422 | uart->num = i++; |
| 423 | list_add_tail(&uart->node, &uart_list); |
| 424 | num_uarts++; |
| 425 | |
Tony Lindgren | 84f90c9 | 2009-10-16 09:53:00 -0700 | [diff] [blame] | 426 | /* |
Paul Walmsley | 550c809 | 2011-02-28 11:58:14 -0700 | [diff] [blame] | 427 | * NOTE: omap_hwmod_setup*() has not yet been called, |
Kevin Hilman | 6f251e9 | 2010-09-27 20:19:38 +0530 | [diff] [blame] | 428 | * so no hwmod functions will work yet. |
Tony Lindgren | 84f90c9 | 2009-10-16 09:53:00 -0700 | [diff] [blame] | 429 | */ |
Tony Lindgren | 84f90c9 | 2009-10-16 09:53:00 -0700 | [diff] [blame] | 430 | |
Kevin Hilman | 6f251e9 | 2010-09-27 20:19:38 +0530 | [diff] [blame] | 431 | /* |
| 432 | * During UART early init, device need to be probed |
| 433 | * to determine SoC specific init before omap_device |
| 434 | * is ready. Therefore, don't allow idle here |
| 435 | */ |
| 436 | uart->oh->flags |= HWMOD_INIT_NO_IDLE | HWMOD_INIT_NO_RESET; |
| 437 | } while (1); |
Tony Lindgren | 3e16f92 | 2011-02-14 15:40:20 -0800 | [diff] [blame] | 438 | |
| 439 | return 0; |
Paul Walmsley | b3c6df3 | 2009-09-03 20:14:02 +0300 | [diff] [blame] | 440 | } |
Tony Lindgren | 3e16f92 | 2011-02-14 15:40:20 -0800 | [diff] [blame] | 441 | core_initcall(omap_serial_early_init); |
Paul Walmsley | b3c6df3 | 2009-09-03 20:14:02 +0300 | [diff] [blame] | 442 | |
Mika Westerberg | f62349e | 2009-12-11 16:16:35 -0800 | [diff] [blame] | 443 | /** |
| 444 | * omap_serial_init_port() - initialize single serial port |
Tony Lindgren | 40e4439 | 2010-12-22 18:42:35 -0800 | [diff] [blame] | 445 | * @bdata: port specific board data pointer |
Mika Westerberg | f62349e | 2009-12-11 16:16:35 -0800 | [diff] [blame] | 446 | * |
Tony Lindgren | 40e4439 | 2010-12-22 18:42:35 -0800 | [diff] [blame] | 447 | * This function initialies serial driver for given port only. |
Mika Westerberg | f62349e | 2009-12-11 16:16:35 -0800 | [diff] [blame] | 448 | * Platforms can call this function instead of omap_serial_init() |
| 449 | * if they don't plan to use all available UARTs as serial ports. |
| 450 | * |
| 451 | * Don't mix calls to omap_serial_init_port() and omap_serial_init(), |
| 452 | * use only one of the two. |
| 453 | */ |
Tony Lindgren | 40e4439 | 2010-12-22 18:42:35 -0800 | [diff] [blame] | 454 | void __init omap_serial_init_port(struct omap_board_data *bdata) |
Mika Westerberg | f62349e | 2009-12-11 16:16:35 -0800 | [diff] [blame] | 455 | { |
| 456 | struct omap_uart_state *uart; |
Kevin Hilman | 6f251e9 | 2010-09-27 20:19:38 +0530 | [diff] [blame] | 457 | struct omap_hwmod *oh; |
Kevin Hilman | 3528c58 | 2011-07-21 13:48:45 -0700 | [diff] [blame] | 458 | struct platform_device *pdev; |
Kevin Hilman | 6f251e9 | 2010-09-27 20:19:38 +0530 | [diff] [blame] | 459 | void *pdata = NULL; |
| 460 | u32 pdata_size = 0; |
| 461 | char *name; |
Kevin Hilman | 6f251e9 | 2010-09-27 20:19:38 +0530 | [diff] [blame] | 462 | struct omap_uart_port_info omap_up; |
Mika Westerberg | f62349e | 2009-12-11 16:16:35 -0800 | [diff] [blame] | 463 | |
Tony Lindgren | 40e4439 | 2010-12-22 18:42:35 -0800 | [diff] [blame] | 464 | if (WARN_ON(!bdata)) |
Sergio Aguirre | e88d556 | 2010-02-27 14:13:43 -0600 | [diff] [blame] | 465 | return; |
Tony Lindgren | 40e4439 | 2010-12-22 18:42:35 -0800 | [diff] [blame] | 466 | if (WARN_ON(bdata->id < 0)) |
| 467 | return; |
| 468 | if (WARN_ON(bdata->id >= num_uarts)) |
Mika Westerberg | f62349e | 2009-12-11 16:16:35 -0800 | [diff] [blame] | 469 | return; |
| 470 | |
Kevin Hilman | 6f251e9 | 2010-09-27 20:19:38 +0530 | [diff] [blame] | 471 | list_for_each_entry(uart, &uart_list, node) |
Tony Lindgren | 40e4439 | 2010-12-22 18:42:35 -0800 | [diff] [blame] | 472 | if (bdata->id == uart->num) |
Kevin Hilman | 6f251e9 | 2010-09-27 20:19:38 +0530 | [diff] [blame] | 473 | break; |
| 474 | |
| 475 | oh = uart->oh; |
| 476 | uart->dma_enabled = 0; |
Kevin Hilman | 6f251e9 | 2010-09-27 20:19:38 +0530 | [diff] [blame] | 477 | name = DRIVER_NAME; |
| 478 | |
| 479 | omap_up.dma_enabled = uart->dma_enabled; |
| 480 | omap_up.uartclk = OMAP24XX_BASE_BAUD * 16; |
Govindraj.R | 273558b | 2011-09-13 14:01:01 +0530 | [diff] [blame] | 481 | omap_up.flags = UPF_BOOT_AUTOCONF; |
Govindraj.R | ec3bebc | 2011-10-11 19:11:27 +0530 | [diff] [blame^] | 482 | omap_up.get_context_loss_count = omap_pm_get_dev_context_loss_count; |
Kevin Hilman | 6f251e9 | 2010-09-27 20:19:38 +0530 | [diff] [blame] | 483 | |
| 484 | pdata = &omap_up; |
| 485 | pdata_size = sizeof(struct omap_uart_port_info); |
Kevin Hilman | 6f251e9 | 2010-09-27 20:19:38 +0530 | [diff] [blame] | 486 | |
| 487 | if (WARN_ON(!oh)) |
| 488 | return; |
| 489 | |
Kevin Hilman | 3528c58 | 2011-07-21 13:48:45 -0700 | [diff] [blame] | 490 | pdev = omap_device_build(name, uart->num, oh, pdata, pdata_size, |
Benoit Cousson | f718e2c | 2011-08-10 15:30:09 +0200 | [diff] [blame] | 491 | NULL, 0, false); |
Kevin Hilman | 3528c58 | 2011-07-21 13:48:45 -0700 | [diff] [blame] | 492 | 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] | 493 | name, oh->name); |
| 494 | |
Kevin Hilman | 9f8b694 | 2011-08-01 09:33:13 -0700 | [diff] [blame] | 495 | omap_device_disable_idle_on_suspend(pdev); |
Tony Lindgren | 40e4439 | 2010-12-22 18:42:35 -0800 | [diff] [blame] | 496 | oh->mux = omap_hwmod_mux_init(bdata->pads, bdata->pads_cnt); |
| 497 | |
Kevin Hilman | 3528c58 | 2011-07-21 13:48:45 -0700 | [diff] [blame] | 498 | uart->pdev = pdev; |
Kevin Hilman | 6f251e9 | 2010-09-27 20:19:38 +0530 | [diff] [blame] | 499 | |
| 500 | oh->dev_attr = uart; |
| 501 | |
Torben Hohn | ac751ef | 2011-01-25 15:07:35 -0800 | [diff] [blame] | 502 | console_lock(); /* in case the earlycon is on the UART */ |
Paul Walmsley | 0d8e2d0 | 2010-11-24 16:49:05 -0700 | [diff] [blame] | 503 | |
Kevin Hilman | 6f251e9 | 2010-09-27 20:19:38 +0530 | [diff] [blame] | 504 | /* |
| 505 | * Because of early UART probing, UART did not get idled |
| 506 | * on init. Now that omap_device is ready, ensure full idle |
| 507 | * before doing omap_device_enable(). |
| 508 | */ |
| 509 | omap_hwmod_idle(uart->oh); |
| 510 | |
| 511 | omap_device_enable(uart->pdev); |
| 512 | omap_uart_idle_init(uart); |
Kevin Hilman | 6f251e9 | 2010-09-27 20:19:38 +0530 | [diff] [blame] | 513 | omap_hwmod_enable_wakeup(uart->oh); |
| 514 | omap_device_idle(uart->pdev); |
| 515 | |
Kevin Hilman | 6f251e9 | 2010-09-27 20:19:38 +0530 | [diff] [blame] | 516 | omap_uart_block_sleep(uart); |
Torben Hohn | ac751ef | 2011-01-25 15:07:35 -0800 | [diff] [blame] | 517 | console_unlock(); |
Paul Walmsley | 0d8e2d0 | 2010-11-24 16:49:05 -0700 | [diff] [blame] | 518 | |
Govindraj.R | 7496ba3 | 2011-11-07 18:55:05 +0530 | [diff] [blame] | 519 | if (((cpu_is_omap34xx() || cpu_is_omap44xx()) && bdata->pads) || |
| 520 | (pdata->wk_en && pdata->wk_mask)) |
Kevin Hilman | 3528c58 | 2011-07-21 13:48:45 -0700 | [diff] [blame] | 521 | device_init_wakeup(&pdev->dev, true); |
Deepak K | 0003450 | 2010-08-02 13:18:12 +0300 | [diff] [blame] | 522 | |
| 523 | /* Enable the MDR1 errata for OMAP3 */ |
Hemant Pedanekar | a920360 | 2011-12-13 10:46:44 -0800 | [diff] [blame] | 524 | if (cpu_is_omap34xx() && !(cpu_is_ti81xx() || cpu_is_am33xx())) |
Deepak K | 0003450 | 2010-08-02 13:18:12 +0300 | [diff] [blame] | 525 | uart->errata |= UART_ERRATA_i202_MDR1_ACCESS; |
Mika Westerberg | f62349e | 2009-12-11 16:16:35 -0800 | [diff] [blame] | 526 | } |
| 527 | |
| 528 | /** |
Uwe Kleine-König | b595076 | 2010-11-01 15:38:34 -0400 | [diff] [blame] | 529 | * omap_serial_init() - initialize all supported serial ports |
Mika Westerberg | f62349e | 2009-12-11 16:16:35 -0800 | [diff] [blame] | 530 | * |
| 531 | * Initializes all available UARTs as serial ports. Platforms |
| 532 | * can call this function when they want to have default behaviour |
| 533 | * for serial ports (e.g initialize them all as serial ports). |
| 534 | */ |
Paul Walmsley | b3c6df3 | 2009-09-03 20:14:02 +0300 | [diff] [blame] | 535 | void __init omap_serial_init(void) |
| 536 | { |
Kevin Hilman | 6f251e9 | 2010-09-27 20:19:38 +0530 | [diff] [blame] | 537 | struct omap_uart_state *uart; |
Tony Lindgren | 40e4439 | 2010-12-22 18:42:35 -0800 | [diff] [blame] | 538 | struct omap_board_data bdata; |
Paul Walmsley | b3c6df3 | 2009-09-03 20:14:02 +0300 | [diff] [blame] | 539 | |
Tony Lindgren | 40e4439 | 2010-12-22 18:42:35 -0800 | [diff] [blame] | 540 | list_for_each_entry(uart, &uart_list, node) { |
| 541 | bdata.id = uart->num; |
| 542 | bdata.flags = 0; |
| 543 | bdata.pads = NULL; |
| 544 | bdata.pads_cnt = 0; |
Govindraj.R | 7496ba3 | 2011-11-07 18:55:05 +0530 | [diff] [blame] | 545 | |
| 546 | if (cpu_is_omap44xx() || cpu_is_omap34xx()) |
| 547 | omap_serial_fill_default_pads(&bdata); |
| 548 | |
Tony Lindgren | 40e4439 | 2010-12-22 18:42:35 -0800 | [diff] [blame] | 549 | omap_serial_init_port(&bdata); |
| 550 | |
| 551 | } |
Tony Lindgren | 1dbae81 | 2005-11-10 14:26:51 +0000 | [diff] [blame] | 552 | } |