blob: 78ca7e8fc10bdbf90fa7b9ede985960fb6b2fda8 [file] [log] [blame]
Tony Lindgren1dbae812005-11-10 14:26:51 +00001/*
Uwe Zeisbergerf30c2262006-10-03 23:01:26 +02002 * arch/arm/mach-omap2/serial.c
Tony Lindgren1dbae812005-11-10 14:26:51 +00003 *
4 * OMAP2 serial support.
5 *
Jouni Hogander6e811762008-10-06 15:49:15 +03006 * Copyright (C) 2005-2008 Nokia Corporation
Tony Lindgren1dbae812005-11-10 14:26:51 +00007 * Author: Paul Mundt <paul.mundt@nokia.com>
8 *
Kevin Hilman4af40162009-02-04 10:51:40 -08009 * Major rework for PM support by Kevin Hilman
10 *
Tony Lindgren1dbae812005-11-10 14:26:51 +000011 * Based off of arch/arm/mach-omap/omap1/serial.c
12 *
Santosh Shilimkar44169072009-05-28 14:16:04 -070013 * Copyright (C) 2009 Texas Instruments
14 * Added OMAP4 support - Santosh Shilimkar <santosh.shilimkar@ti.com
15 *
Tony Lindgren1dbae812005-11-10 14:26:51 +000016 * 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 Kingf8ce2542006-01-07 16:15:52 +000022#include <linux/clk.h>
Russell Kingfced80c2008-09-06 12:10:45 +010023#include <linux/io.h>
Santosh Shilimkare03d37d2010-02-18 08:59:06 +000024#include <linux/delay.h>
Kevin Hilman6f251e92010-09-27 20:19:38 +053025#include <linux/platform_device.h>
26#include <linux/slab.h>
Kevin Hilman3244fcd2010-09-27 20:19:53 +053027#include <linux/pm_runtime.h>
Paul Walmsley0d8e2d02010-11-24 16:49:05 -070028#include <linux/console.h>
Kevin Hilman6f251e92010-09-27 20:19:38 +053029
Kevin Hilman6f251e92010-09-27 20:19:38 +053030#include <plat/omap-serial.h>
Tony Lindgren4e653312011-11-10 22:45:17 +010031#include "common.h"
Tony Lindgrence491cf2009-10-20 09:40:47 -070032#include <plat/board.h>
Kevin Hilman6f251e92010-09-27 20:19:38 +053033#include <plat/dma.h>
34#include <plat/omap_hwmod.h>
35#include <plat/omap_device.h>
Govindraj.Rec3bebc2011-10-11 19:11:27 +053036#include <plat/omap-pm.h>
Tony Lindgren1dbae812005-11-10 14:26:51 +000037
Paul Walmsley59fb6592010-12-21 15:30:55 -070038#include "prm2xxx_3xxx.h"
Kevin Hilman4af40162009-02-04 10:51:40 -080039#include "pm.h"
Paul Walmsley59fb6592010-12-21 15:30:55 -070040#include "cm2xxx_3xxx.h"
Kevin Hilman4af40162009-02-04 10:51:40 -080041#include "prm-regbits-34xx.h"
Paul Walmsley4814ced2010-10-08 11:40:20 -060042#include "control.h"
Tony Lindgren40e44392010-12-22 18:42:35 -080043#include "mux.h"
Kevin Hilman4af40162009-02-04 10:51:40 -080044
Deepak K00034502010-08-02 13:18:12 +030045#define UART_ERRATA_i202_MDR1_ACCESS (0x1 << 1)
Nishanth Menon5a927b32010-08-02 13:18:12 +030046
Tony Lindgren301fe8e2010-02-01 12:34:31 -080047/*
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 Hilman4af40162009-02-04 10:51:40 -080054
Kevin Hilman6f251e92010-09-27 20:19:38 +053055#define MAX_UART_HWMOD_NAME_LEN 16
56
Kevin Hilman4af40162009-02-04 10:51:40 -080057struct omap_uart_state {
58 int num;
59 int can_sleep;
Kevin Hilman4af40162009-02-04 10:51:40 -080060
61 void __iomem *wk_st;
62 void __iomem *wk_en;
63 u32 wk_mask;
Kevin Hilman6f251e92010-09-27 20:19:38 +053064 u32 dma_enabled;
Kevin Hilman4af40162009-02-04 10:51:40 -080065
Kevin Hilman4af40162009-02-04 10:51:40 -080066 int clocked;
67
Kevin Hilman4af40162009-02-04 10:51:40 -080068 struct list_head node;
Kevin Hilman6f251e92010-09-27 20:19:38 +053069 struct omap_hwmod *oh;
70 struct platform_device *pdev;
Kevin Hilman4af40162009-02-04 10:51:40 -080071
Nishanth Menon5a927b32010-08-02 13:18:12 +030072 u32 errata;
Kevin Hilman4af40162009-02-04 10:51:40 -080073};
74
Kevin Hilman4af40162009-02-04 10:51:40 -080075static LIST_HEAD(uart_list);
Kevin Hilman6f251e92010-09-27 20:19:38 +053076static u8 num_uarts;
Tony Lindgren1dbae812005-11-10 14:26:51 +000077
Kevin Hilman4af40162009-02-04 10:51:40 -080078#if defined(CONFIG_PM) && defined(CONFIG_ARCH_OMAP3)
79
Deepak K00034502010-08-02 13:18:12 +030080/*
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 */
89static void omap_uart_mdr1_errataset(struct omap_uart_state *uart, u8 mdr1_val,
90 u8 fcr_val)
91{
Deepak K00034502010-08-02 13:18:12 +030092 u8 timeout = 255;
93
Kevin Hilman6f251e92010-09-27 20:19:38 +053094 serial_write_reg(uart, UART_OMAP_MDR1, mdr1_val);
Deepak K00034502010-08-02 13:18:12 +030095 udelay(2);
Kevin Hilman6f251e92010-09-27 20:19:38 +053096 serial_write_reg(uart, UART_FCR, fcr_val | UART_FCR_CLEAR_XMIT |
Deepak K00034502010-08-02 13:18:12 +030097 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 Hilman6f251e92010-09-27 20:19:38 +0530102 while (UART_LSR_THRE != (serial_read_reg(uart, UART_LSR) &
Deepak K00034502010-08-02 13:18:12 +0300103 (UART_LSR_THRE | UART_LSR_DR))) {
104 timeout--;
105 if (!timeout) {
106 /* Should *never* happen. we warn and carry on */
Kevin Hilman6f251e92010-09-27 20:19:38 +0530107 dev_crit(&uart->pdev->dev, "Errata i202: timedout %x\n",
108 serial_read_reg(uart, UART_LSR));
Deepak K00034502010-08-02 13:18:12 +0300109 break;
110 }
111 udelay(1);
112 }
113}
114
Kevin Hilman4af40162009-02-04 10:51:40 -0800115#endif /* CONFIG_PM && CONFIG_ARCH_OMAP3 */
116
117static inline void omap_uart_enable_clocks(struct omap_uart_state *uart)
118{
119 if (uart->clocked)
120 return;
121
Kevin Hilman6f251e92010-09-27 20:19:38 +0530122 omap_device_enable(uart->pdev);
Kevin Hilman4af40162009-02-04 10:51:40 -0800123 uart->clocked = 1;
124 omap_uart_restore_context(uart);
125}
126
127#ifdef CONFIG_PM
128
129static 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 Hilman6f251e92010-09-27 20:19:38 +0530136 omap_device_idle(uart->pdev);
Kevin Hilman4af40162009-02-04 10:51:40 -0800137}
138
Kevin Hilmanfd455ea2009-04-27 12:27:36 -0700139static 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 Hilmanfd455ea2009-04-27 12:27:36 -0700147}
148
149static 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 Hilmanfd455ea2009-04-27 12:27:36 -0700157}
158
Kevin Hilman4af40162009-02-04 10:51:40 -0800159static void omap_uart_smart_idle_enable(struct omap_uart_state *uart,
Kevin Hilman6f251e92010-09-27 20:19:38 +0530160 int enable)
Kevin Hilman4af40162009-02-04 10:51:40 -0800161{
Kevin Hilman6f251e92010-09-27 20:19:38 +0530162 u8 idlemode;
Kevin Hilman4af40162009-02-04 10:51:40 -0800163
Kevin Hilman6f251e92010-09-27 20:19:38 +0530164 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 Hilman4af40162009-02-04 10:51:40 -0800176
Kevin Hilman6f251e92010-09-27 20:19:38 +0530177 omap_hwmod_set_slave_idlemode(uart->oh, idlemode);
Kevin Hilman4af40162009-02-04 10:51:40 -0800178}
179
180static 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 Hilman4af40162009-02-04 10:51:40 -0800186}
187
Kevin Hilman4af40162009-02-04 10:51:40 -0800188int 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 Hilman4af40162009-02-04 10:51:40 -0800209static void omap_uart_idle_init(struct omap_uart_state *uart)
210{
Kevin Hilman4af40162009-02-04 10:51:40 -0800211 int ret;
212
213 uart->can_sleep = 0;
Kevin Hilman4af40162009-02-04 10:51:40 -0800214 omap_uart_smart_idle_enable(uart, 0);
215
Hemant Pedanekara9203602011-12-13 10:46:44 -0800216 if (cpu_is_omap34xx() && !(cpu_is_ti81xx() || cpu_is_am33xx())) {
Govindraj.R52663ae2010-09-27 20:20:41 +0530217 u32 mod = (uart->num > 1) ? OMAP3430_PER_MOD : CORE_MOD;
Kevin Hilman4af40162009-02-04 10:51:40 -0800218 u32 wk_mask = 0;
Kevin Hilman4af40162009-02-04 10:51:40 -0800219
Paul Walmsleyc4d7e582010-12-21 21:05:14 -0700220 /* XXX These PRM accesses do not belong here */
Kevin Hilman4af40162009-02-04 10:51:40 -0800221 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 Hilman4af40162009-02-04 10:51:40 -0800226 break;
227 case 1:
228 wk_mask = OMAP3430_ST_UART2_MASK;
Kevin Hilman4af40162009-02-04 10:51:40 -0800229 break;
230 case 2:
231 wk_mask = OMAP3430_ST_UART3_MASK;
Kevin Hilman4af40162009-02-04 10:51:40 -0800232 break;
Govindraj.R52663ae2010-09-27 20:20:41 +0530233 case 3:
234 wk_mask = OMAP3630_ST_UART4_MASK;
Govindraj.R52663ae2010-09-27 20:20:41 +0530235 break;
Kevin Hilman4af40162009-02-04 10:51:40 -0800236 }
237 uart->wk_mask = wk_mask;
Kevin Hilman4af40162009-02-04 10:51:40 -0800238 } else if (cpu_is_omap24xx()) {
239 u32 wk_mask = 0;
Kevin Hilmancb74f022010-10-20 23:19:03 +0000240 u32 wk_en = PM_WKEN1, wk_st = PM_WKST1;
Kevin Hilman4af40162009-02-04 10:51:40 -0800241
Kevin Hilman4af40162009-02-04 10:51:40 -0800242 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 Hilmancb74f022010-10-20 23:19:03 +0000250 wk_en = OMAP24XX_PM_WKEN2;
251 wk_st = OMAP24XX_PM_WKST2;
Kevin Hilman4af40162009-02-04 10:51:40 -0800252 wk_mask = OMAP24XX_ST_UART3_MASK;
253 break;
254 }
255 uart->wk_mask = wk_mask;
Kevin Hilmancb74f022010-10-20 23:19:03 +0000256 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 Hilman4af40162009-02-04 10:51:40 -0800263 } else {
Nishanth Menonc54bae12010-08-02 13:18:11 +0300264 uart->wk_en = NULL;
265 uart->wk_st = NULL;
Kevin Hilman4af40162009-02-04 10:51:40 -0800266 uart->wk_mask = 0;
Kevin Hilman4af40162009-02-04 10:51:40 -0800267 }
Kevin Hilman4af40162009-02-04 10:51:40 -0800268}
269
270#else
Santosh Shilimkara1b04cc2010-10-11 11:05:18 +0000271static 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 Hilman4af40162009-02-04 10:51:40 -0800276#endif /* CONFIG_PM */
277
Govindraj.R7496ba32011-11-07 18:55:05 +0530278#ifdef CONFIG_OMAP_MUX
279static 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
300static 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
321static 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
342static 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
355static 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
368static 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
399static void omap_serial_fill_default_pads(struct omap_board_data *bdata) {}
400#endif
401
Tony Lindgren3e16f922011-02-14 15:40:20 -0800402static int __init omap_serial_early_init(void)
Tony Lindgren1dbae812005-11-10 14:26:51 +0000403{
Kevin Hilman6f251e92010-09-27 20:19:38 +0530404 int i = 0;
Tony Lindgren1dbae812005-11-10 14:26:51 +0000405
Kevin Hilman6f251e92010-09-27 20:19:38 +0530406 do {
407 char oh_name[MAX_UART_HWMOD_NAME_LEN];
408 struct omap_hwmod *oh;
409 struct omap_uart_state *uart;
Thomas Weber21b90342010-02-25 09:40:19 +0000410
Kevin Hilman6f251e92010-09-27 20:19:38 +0530411 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 Lindgren1dbae812005-11-10 14:26:51 +0000416
Kevin Hilman6f251e92010-09-27 20:19:38 +0530417 uart = kzalloc(sizeof(struct omap_uart_state), GFP_KERNEL);
418 if (WARN_ON(!uart))
Tony Lindgren3e16f922011-02-14 15:40:20 -0800419 return -ENODEV;
Tony Lindgren1dbae812005-11-10 14:26:51 +0000420
Kevin Hilman6f251e92010-09-27 20:19:38 +0530421 uart->oh = oh;
422 uart->num = i++;
423 list_add_tail(&uart->node, &uart_list);
424 num_uarts++;
425
Tony Lindgren84f90c92009-10-16 09:53:00 -0700426 /*
Paul Walmsley550c8092011-02-28 11:58:14 -0700427 * NOTE: omap_hwmod_setup*() has not yet been called,
Kevin Hilman6f251e92010-09-27 20:19:38 +0530428 * so no hwmod functions will work yet.
Tony Lindgren84f90c92009-10-16 09:53:00 -0700429 */
Tony Lindgren84f90c92009-10-16 09:53:00 -0700430
Kevin Hilman6f251e92010-09-27 20:19:38 +0530431 /*
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 Lindgren3e16f922011-02-14 15:40:20 -0800438
439 return 0;
Paul Walmsleyb3c6df32009-09-03 20:14:02 +0300440}
Tony Lindgren3e16f922011-02-14 15:40:20 -0800441core_initcall(omap_serial_early_init);
Paul Walmsleyb3c6df32009-09-03 20:14:02 +0300442
Mika Westerbergf62349e2009-12-11 16:16:35 -0800443/**
444 * omap_serial_init_port() - initialize single serial port
Tony Lindgren40e44392010-12-22 18:42:35 -0800445 * @bdata: port specific board data pointer
Mika Westerbergf62349e2009-12-11 16:16:35 -0800446 *
Tony Lindgren40e44392010-12-22 18:42:35 -0800447 * This function initialies serial driver for given port only.
Mika Westerbergf62349e2009-12-11 16:16:35 -0800448 * 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 Lindgren40e44392010-12-22 18:42:35 -0800454void __init omap_serial_init_port(struct omap_board_data *bdata)
Mika Westerbergf62349e2009-12-11 16:16:35 -0800455{
456 struct omap_uart_state *uart;
Kevin Hilman6f251e92010-09-27 20:19:38 +0530457 struct omap_hwmod *oh;
Kevin Hilman3528c582011-07-21 13:48:45 -0700458 struct platform_device *pdev;
Kevin Hilman6f251e92010-09-27 20:19:38 +0530459 void *pdata = NULL;
460 u32 pdata_size = 0;
461 char *name;
Kevin Hilman6f251e92010-09-27 20:19:38 +0530462 struct omap_uart_port_info omap_up;
Mika Westerbergf62349e2009-12-11 16:16:35 -0800463
Tony Lindgren40e44392010-12-22 18:42:35 -0800464 if (WARN_ON(!bdata))
Sergio Aguirree88d5562010-02-27 14:13:43 -0600465 return;
Tony Lindgren40e44392010-12-22 18:42:35 -0800466 if (WARN_ON(bdata->id < 0))
467 return;
468 if (WARN_ON(bdata->id >= num_uarts))
Mika Westerbergf62349e2009-12-11 16:16:35 -0800469 return;
470
Kevin Hilman6f251e92010-09-27 20:19:38 +0530471 list_for_each_entry(uart, &uart_list, node)
Tony Lindgren40e44392010-12-22 18:42:35 -0800472 if (bdata->id == uart->num)
Kevin Hilman6f251e92010-09-27 20:19:38 +0530473 break;
474
475 oh = uart->oh;
476 uart->dma_enabled = 0;
Kevin Hilman6f251e92010-09-27 20:19:38 +0530477 name = DRIVER_NAME;
478
479 omap_up.dma_enabled = uart->dma_enabled;
480 omap_up.uartclk = OMAP24XX_BASE_BAUD * 16;
Govindraj.R273558b2011-09-13 14:01:01 +0530481 omap_up.flags = UPF_BOOT_AUTOCONF;
Govindraj.Rec3bebc2011-10-11 19:11:27 +0530482 omap_up.get_context_loss_count = omap_pm_get_dev_context_loss_count;
Kevin Hilman6f251e92010-09-27 20:19:38 +0530483
484 pdata = &omap_up;
485 pdata_size = sizeof(struct omap_uart_port_info);
Kevin Hilman6f251e92010-09-27 20:19:38 +0530486
487 if (WARN_ON(!oh))
488 return;
489
Kevin Hilman3528c582011-07-21 13:48:45 -0700490 pdev = omap_device_build(name, uart->num, oh, pdata, pdata_size,
Benoit Coussonf718e2c2011-08-10 15:30:09 +0200491 NULL, 0, false);
Kevin Hilman3528c582011-07-21 13:48:45 -0700492 WARN(IS_ERR(pdev), "Could not build omap_device for %s: %s.\n",
Kevin Hilman6f251e92010-09-27 20:19:38 +0530493 name, oh->name);
494
Kevin Hilman9f8b6942011-08-01 09:33:13 -0700495 omap_device_disable_idle_on_suspend(pdev);
Tony Lindgren40e44392010-12-22 18:42:35 -0800496 oh->mux = omap_hwmod_mux_init(bdata->pads, bdata->pads_cnt);
497
Kevin Hilman3528c582011-07-21 13:48:45 -0700498 uart->pdev = pdev;
Kevin Hilman6f251e92010-09-27 20:19:38 +0530499
500 oh->dev_attr = uart;
501
Torben Hohnac751ef2011-01-25 15:07:35 -0800502 console_lock(); /* in case the earlycon is on the UART */
Paul Walmsley0d8e2d02010-11-24 16:49:05 -0700503
Kevin Hilman6f251e92010-09-27 20:19:38 +0530504 /*
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 Hilman6f251e92010-09-27 20:19:38 +0530513 omap_hwmod_enable_wakeup(uart->oh);
514 omap_device_idle(uart->pdev);
515
Kevin Hilman6f251e92010-09-27 20:19:38 +0530516 omap_uart_block_sleep(uart);
Torben Hohnac751ef2011-01-25 15:07:35 -0800517 console_unlock();
Paul Walmsley0d8e2d02010-11-24 16:49:05 -0700518
Govindraj.R7496ba32011-11-07 18:55:05 +0530519 if (((cpu_is_omap34xx() || cpu_is_omap44xx()) && bdata->pads) ||
520 (pdata->wk_en && pdata->wk_mask))
Kevin Hilman3528c582011-07-21 13:48:45 -0700521 device_init_wakeup(&pdev->dev, true);
Deepak K00034502010-08-02 13:18:12 +0300522
523 /* Enable the MDR1 errata for OMAP3 */
Hemant Pedanekara9203602011-12-13 10:46:44 -0800524 if (cpu_is_omap34xx() && !(cpu_is_ti81xx() || cpu_is_am33xx()))
Deepak K00034502010-08-02 13:18:12 +0300525 uart->errata |= UART_ERRATA_i202_MDR1_ACCESS;
Mika Westerbergf62349e2009-12-11 16:16:35 -0800526}
527
528/**
Uwe Kleine-Königb5950762010-11-01 15:38:34 -0400529 * omap_serial_init() - initialize all supported serial ports
Mika Westerbergf62349e2009-12-11 16:16:35 -0800530 *
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 Walmsleyb3c6df32009-09-03 20:14:02 +0300535void __init omap_serial_init(void)
536{
Kevin Hilman6f251e92010-09-27 20:19:38 +0530537 struct omap_uart_state *uart;
Tony Lindgren40e44392010-12-22 18:42:35 -0800538 struct omap_board_data bdata;
Paul Walmsleyb3c6df32009-09-03 20:14:02 +0300539
Tony Lindgren40e44392010-12-22 18:42:35 -0800540 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.R7496ba32011-11-07 18:55:05 +0530545
546 if (cpu_is_omap44xx() || cpu_is_omap34xx())
547 omap_serial_fill_default_pads(&bdata);
548
Tony Lindgren40e44392010-12-22 18:42:35 -0800549 omap_serial_init_port(&bdata);
550
551 }
Tony Lindgren1dbae812005-11-10 14:26:51 +0000552}