blob: a5aecffe03ff4abaf9eaceb7f85dee19779d730e [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>
22#include <linux/serial_8250.h>
23#include <linux/serial_reg.h>
Russell Kingf8ce2542006-01-07 16:15:52 +000024#include <linux/clk.h>
Russell Kingfced80c2008-09-06 12:10:45 +010025#include <linux/io.h>
Tony Lindgren1dbae812005-11-10 14:26:51 +000026
Tony Lindgrence491cf2009-10-20 09:40:47 -070027#include <plat/common.h>
28#include <plat/board.h>
29#include <plat/clock.h>
30#include <plat/control.h>
Tony Lindgren1dbae812005-11-10 14:26:51 +000031
Kevin Hilman4af40162009-02-04 10:51:40 -080032#include "prm.h"
33#include "pm.h"
34#include "prm-regbits-34xx.h"
35
36#define UART_OMAP_WER 0x17 /* Wake-up enable register */
37
Jouni Hoganderba87a9b2008-12-09 13:36:50 +020038#define DEFAULT_TIMEOUT (5 * HZ)
Kevin Hilman4af40162009-02-04 10:51:40 -080039
40struct omap_uart_state {
41 int num;
42 int can_sleep;
43 struct timer_list timer;
44 u32 timeout;
45
46 void __iomem *wk_st;
47 void __iomem *wk_en;
48 u32 wk_mask;
49 u32 padconf;
50
51 struct clk *ick;
52 struct clk *fck;
53 int clocked;
54
55 struct plat_serial8250_port *p;
56 struct list_head node;
Kevin Hilmanfd455ea2009-04-27 12:27:36 -070057 struct platform_device pdev;
Kevin Hilman4af40162009-02-04 10:51:40 -080058
59#if defined(CONFIG_ARCH_OMAP3) && defined(CONFIG_PM)
60 int context_valid;
61
62 /* Registers to be saved/restored for OFF-mode */
63 u16 dll;
64 u16 dlh;
65 u16 ier;
66 u16 sysc;
67 u16 scr;
68 u16 wer;
69#endif
70};
71
Kevin Hilman4af40162009-02-04 10:51:40 -080072static LIST_HEAD(uart_list);
Tony Lindgren1dbae812005-11-10 14:26:51 +000073
Kevin Hilmanfd455ea2009-04-27 12:27:36 -070074static struct plat_serial8250_port serial_platform_data0[] = {
Tony Lindgren1dbae812005-11-10 14:26:51 +000075 {
Russell Kinge8a91c92008-09-01 22:07:37 +010076 .mapbase = OMAP_UART1_BASE,
Tony Lindgren1dbae812005-11-10 14:26:51 +000077 .irq = 72,
78 .flags = UPF_BOOT_AUTOCONF,
79 .iotype = UPIO_MEM,
80 .regshift = 2,
Jouni Hogander6e811762008-10-06 15:49:15 +030081 .uartclk = OMAP24XX_BASE_BAUD * 16,
Tony Lindgren1dbae812005-11-10 14:26:51 +000082 }, {
Kevin Hilmanfd455ea2009-04-27 12:27:36 -070083 .flags = 0
84 }
85};
86
87static struct plat_serial8250_port serial_platform_data1[] = {
88 {
Russell Kinge8a91c92008-09-01 22:07:37 +010089 .mapbase = OMAP_UART2_BASE,
Tony Lindgren1dbae812005-11-10 14:26:51 +000090 .irq = 73,
91 .flags = UPF_BOOT_AUTOCONF,
92 .iotype = UPIO_MEM,
93 .regshift = 2,
Jouni Hogander6e811762008-10-06 15:49:15 +030094 .uartclk = OMAP24XX_BASE_BAUD * 16,
Tony Lindgren1dbae812005-11-10 14:26:51 +000095 }, {
Kevin Hilmanfd455ea2009-04-27 12:27:36 -070096 .flags = 0
97 }
98};
99
100static struct plat_serial8250_port serial_platform_data2[] = {
101 {
Russell Kinge8a91c92008-09-01 22:07:37 +0100102 .mapbase = OMAP_UART3_BASE,
Tony Lindgren1dbae812005-11-10 14:26:51 +0000103 .irq = 74,
104 .flags = UPF_BOOT_AUTOCONF,
105 .iotype = UPIO_MEM,
106 .regshift = 2,
Jouni Hogander6e811762008-10-06 15:49:15 +0300107 .uartclk = OMAP24XX_BASE_BAUD * 16,
Tony Lindgren1dbae812005-11-10 14:26:51 +0000108 }, {
109 .flags = 0
110 }
111};
112
Santosh Shilimkar0e3eaad2009-08-22 13:30:11 +0530113#ifdef CONFIG_ARCH_OMAP4
114static struct plat_serial8250_port serial_platform_data3[] = {
115 {
Santosh Shilimkar0e3eaad2009-08-22 13:30:11 +0530116 .mapbase = OMAP_UART4_BASE,
117 .irq = 70,
118 .flags = UPF_BOOT_AUTOCONF,
119 .iotype = UPIO_MEM,
120 .regshift = 2,
121 .uartclk = OMAP24XX_BASE_BAUD * 16,
122 }, {
123 .flags = 0
124 }
125};
126#endif
Tony Lindgren1dbae812005-11-10 14:26:51 +0000127static inline unsigned int serial_read_reg(struct plat_serial8250_port *up,
128 int offset)
129{
130 offset <<= up->regshift;
131 return (unsigned int)__raw_readb(up->membase + offset);
132}
133
134static inline void serial_write_reg(struct plat_serial8250_port *p, int offset,
135 int value)
136{
137 offset <<= p->regshift;
Russell Kinge8a91c92008-09-01 22:07:37 +0100138 __raw_writeb(value, p->membase + offset);
Tony Lindgren1dbae812005-11-10 14:26:51 +0000139}
140
141/*
142 * Internal UARTs need to be initialized for the 8250 autoconfig to work
143 * properly. Note that the TX watermark initialization may not be needed
144 * once the 8250.c watermark handling code is merged.
145 */
Kevin Hilman4af40162009-02-04 10:51:40 -0800146static inline void __init omap_uart_reset(struct omap_uart_state *uart)
Tony Lindgren1dbae812005-11-10 14:26:51 +0000147{
Kevin Hilman4af40162009-02-04 10:51:40 -0800148 struct plat_serial8250_port *p = uart->p;
149
Tony Lindgren1dbae812005-11-10 14:26:51 +0000150 serial_write_reg(p, UART_OMAP_MDR1, 0x07);
151 serial_write_reg(p, UART_OMAP_SCR, 0x08);
152 serial_write_reg(p, UART_OMAP_MDR1, 0x00);
Juha Yrjola671c7232006-12-06 17:13:49 -0800153 serial_write_reg(p, UART_OMAP_SYSC, (0x02 << 3) | (1 << 2) | (1 << 0));
Tony Lindgren1dbae812005-11-10 14:26:51 +0000154}
155
Kevin Hilman4af40162009-02-04 10:51:40 -0800156#if defined(CONFIG_PM) && defined(CONFIG_ARCH_OMAP3)
157
158static int enable_off_mode; /* to be removed by full off-mode patches */
159
160static void omap_uart_save_context(struct omap_uart_state *uart)
Jouni Hogander6e811762008-10-06 15:49:15 +0300161{
Kevin Hilman4af40162009-02-04 10:51:40 -0800162 u16 lcr = 0;
163 struct plat_serial8250_port *p = uart->p;
164
165 if (!enable_off_mode)
166 return;
167
168 lcr = serial_read_reg(p, UART_LCR);
169 serial_write_reg(p, UART_LCR, 0xBF);
170 uart->dll = serial_read_reg(p, UART_DLL);
171 uart->dlh = serial_read_reg(p, UART_DLM);
172 serial_write_reg(p, UART_LCR, lcr);
173 uart->ier = serial_read_reg(p, UART_IER);
174 uart->sysc = serial_read_reg(p, UART_OMAP_SYSC);
175 uart->scr = serial_read_reg(p, UART_OMAP_SCR);
176 uart->wer = serial_read_reg(p, UART_OMAP_WER);
177
178 uart->context_valid = 1;
179}
180
181static void omap_uart_restore_context(struct omap_uart_state *uart)
182{
183 u16 efr = 0;
184 struct plat_serial8250_port *p = uart->p;
185
186 if (!enable_off_mode)
187 return;
188
189 if (!uart->context_valid)
190 return;
191
192 uart->context_valid = 0;
193
194 serial_write_reg(p, UART_OMAP_MDR1, 0x7);
195 serial_write_reg(p, UART_LCR, 0xBF); /* Config B mode */
196 efr = serial_read_reg(p, UART_EFR);
197 serial_write_reg(p, UART_EFR, UART_EFR_ECB);
198 serial_write_reg(p, UART_LCR, 0x0); /* Operational mode */
199 serial_write_reg(p, UART_IER, 0x0);
200 serial_write_reg(p, UART_LCR, 0xBF); /* Config B mode */
201 serial_write_reg(p, UART_DLL, uart->dll);
202 serial_write_reg(p, UART_DLM, uart->dlh);
203 serial_write_reg(p, UART_LCR, 0x0); /* Operational mode */
204 serial_write_reg(p, UART_IER, uart->ier);
205 serial_write_reg(p, UART_FCR, 0xA1);
206 serial_write_reg(p, UART_LCR, 0xBF); /* Config B mode */
207 serial_write_reg(p, UART_EFR, efr);
208 serial_write_reg(p, UART_LCR, UART_LCR_WLEN8);
209 serial_write_reg(p, UART_OMAP_SCR, uart->scr);
210 serial_write_reg(p, UART_OMAP_WER, uart->wer);
211 serial_write_reg(p, UART_OMAP_SYSC, uart->sysc);
212 serial_write_reg(p, UART_OMAP_MDR1, 0x00); /* UART 16x mode */
213}
214#else
215static inline void omap_uart_save_context(struct omap_uart_state *uart) {}
216static inline void omap_uart_restore_context(struct omap_uart_state *uart) {}
217#endif /* CONFIG_PM && CONFIG_ARCH_OMAP3 */
218
219static inline void omap_uart_enable_clocks(struct omap_uart_state *uart)
220{
221 if (uart->clocked)
222 return;
223
224 clk_enable(uart->ick);
225 clk_enable(uart->fck);
226 uart->clocked = 1;
227 omap_uart_restore_context(uart);
228}
229
230#ifdef CONFIG_PM
231
232static inline void omap_uart_disable_clocks(struct omap_uart_state *uart)
233{
234 if (!uart->clocked)
235 return;
236
237 omap_uart_save_context(uart);
238 uart->clocked = 0;
239 clk_disable(uart->ick);
240 clk_disable(uart->fck);
241}
242
Kevin Hilmanfd455ea2009-04-27 12:27:36 -0700243static void omap_uart_enable_wakeup(struct omap_uart_state *uart)
244{
245 /* Set wake-enable bit */
246 if (uart->wk_en && uart->wk_mask) {
247 u32 v = __raw_readl(uart->wk_en);
248 v |= uart->wk_mask;
249 __raw_writel(v, uart->wk_en);
250 }
251
252 /* Ensure IOPAD wake-enables are set */
253 if (cpu_is_omap34xx() && uart->padconf) {
254 u16 v = omap_ctrl_readw(uart->padconf);
255 v |= OMAP3_PADCONF_WAKEUPENABLE0;
256 omap_ctrl_writew(v, uart->padconf);
257 }
258}
259
260static void omap_uart_disable_wakeup(struct omap_uart_state *uart)
261{
262 /* Clear wake-enable bit */
263 if (uart->wk_en && uart->wk_mask) {
264 u32 v = __raw_readl(uart->wk_en);
265 v &= ~uart->wk_mask;
266 __raw_writel(v, uart->wk_en);
267 }
268
269 /* Ensure IOPAD wake-enables are cleared */
270 if (cpu_is_omap34xx() && uart->padconf) {
271 u16 v = omap_ctrl_readw(uart->padconf);
272 v &= ~OMAP3_PADCONF_WAKEUPENABLE0;
273 omap_ctrl_writew(v, uart->padconf);
274 }
275}
276
Kevin Hilman4af40162009-02-04 10:51:40 -0800277static void omap_uart_smart_idle_enable(struct omap_uart_state *uart,
278 int enable)
279{
280 struct plat_serial8250_port *p = uart->p;
281 u16 sysc;
282
283 sysc = serial_read_reg(p, UART_OMAP_SYSC) & 0x7;
284 if (enable)
285 sysc |= 0x2 << 3;
286 else
287 sysc |= 0x1 << 3;
288
289 serial_write_reg(p, UART_OMAP_SYSC, sysc);
290}
291
292static void omap_uart_block_sleep(struct omap_uart_state *uart)
293{
294 omap_uart_enable_clocks(uart);
295
296 omap_uart_smart_idle_enable(uart, 0);
297 uart->can_sleep = 0;
Jouni Hoganderba87a9b2008-12-09 13:36:50 +0200298 if (uart->timeout)
299 mod_timer(&uart->timer, jiffies + uart->timeout);
300 else
301 del_timer(&uart->timer);
Kevin Hilman4af40162009-02-04 10:51:40 -0800302}
303
304static void omap_uart_allow_sleep(struct omap_uart_state *uart)
305{
Kevin Hilmanfd455ea2009-04-27 12:27:36 -0700306 if (device_may_wakeup(&uart->pdev.dev))
307 omap_uart_enable_wakeup(uart);
308 else
309 omap_uart_disable_wakeup(uart);
310
Kevin Hilman4af40162009-02-04 10:51:40 -0800311 if (!uart->clocked)
312 return;
313
314 omap_uart_smart_idle_enable(uart, 1);
315 uart->can_sleep = 1;
316 del_timer(&uart->timer);
317}
318
319static void omap_uart_idle_timer(unsigned long data)
320{
321 struct omap_uart_state *uart = (struct omap_uart_state *)data;
322
323 omap_uart_allow_sleep(uart);
324}
325
326void omap_uart_prepare_idle(int num)
327{
328 struct omap_uart_state *uart;
329
330 list_for_each_entry(uart, &uart_list, node) {
331 if (num == uart->num && uart->can_sleep) {
332 omap_uart_disable_clocks(uart);
333 return;
Jouni Hogander6e811762008-10-06 15:49:15 +0300334 }
335 }
336}
337
Kevin Hilman4af40162009-02-04 10:51:40 -0800338void omap_uart_resume_idle(int num)
339{
340 struct omap_uart_state *uart;
341
342 list_for_each_entry(uart, &uart_list, node) {
343 if (num == uart->num) {
344 omap_uart_enable_clocks(uart);
345
346 /* Check for IO pad wakeup */
347 if (cpu_is_omap34xx() && uart->padconf) {
348 u16 p = omap_ctrl_readw(uart->padconf);
349
350 if (p & OMAP3_PADCONF_WAKEUPEVENT0)
351 omap_uart_block_sleep(uart);
352 }
353
354 /* Check for normal UART wakeup */
355 if (__raw_readl(uart->wk_st) & uart->wk_mask)
356 omap_uart_block_sleep(uart);
Kevin Hilman4af40162009-02-04 10:51:40 -0800357 return;
358 }
359 }
360}
361
362void omap_uart_prepare_suspend(void)
363{
364 struct omap_uart_state *uart;
365
366 list_for_each_entry(uart, &uart_list, node) {
367 omap_uart_allow_sleep(uart);
368 }
369}
370
371int omap_uart_can_sleep(void)
372{
373 struct omap_uart_state *uart;
374 int can_sleep = 1;
375
376 list_for_each_entry(uart, &uart_list, node) {
377 if (!uart->clocked)
378 continue;
379
380 if (!uart->can_sleep) {
381 can_sleep = 0;
382 continue;
383 }
384
385 /* This UART can now safely sleep. */
386 omap_uart_allow_sleep(uart);
387 }
388
389 return can_sleep;
390}
391
392/**
393 * omap_uart_interrupt()
394 *
395 * This handler is used only to detect that *any* UART interrupt has
396 * occurred. It does _nothing_ to handle the interrupt. Rather,
397 * any UART interrupt will trigger the inactivity timer so the
398 * UART will not idle or sleep for its timeout period.
399 *
400 **/
401static irqreturn_t omap_uart_interrupt(int irq, void *dev_id)
402{
403 struct omap_uart_state *uart = dev_id;
404
405 omap_uart_block_sleep(uart);
406
407 return IRQ_NONE;
408}
409
410static void omap_uart_idle_init(struct omap_uart_state *uart)
411{
Kevin Hilman4af40162009-02-04 10:51:40 -0800412 struct plat_serial8250_port *p = uart->p;
413 int ret;
414
415 uart->can_sleep = 0;
Kevin Hilmanfd455ea2009-04-27 12:27:36 -0700416 uart->timeout = DEFAULT_TIMEOUT;
Kevin Hilman4af40162009-02-04 10:51:40 -0800417 setup_timer(&uart->timer, omap_uart_idle_timer,
418 (unsigned long) uart);
419 mod_timer(&uart->timer, jiffies + uart->timeout);
420 omap_uart_smart_idle_enable(uart, 0);
421
422 if (cpu_is_omap34xx()) {
423 u32 mod = (uart->num == 2) ? OMAP3430_PER_MOD : CORE_MOD;
424 u32 wk_mask = 0;
425 u32 padconf = 0;
426
427 uart->wk_en = OMAP34XX_PRM_REGADDR(mod, PM_WKEN1);
428 uart->wk_st = OMAP34XX_PRM_REGADDR(mod, PM_WKST1);
429 switch (uart->num) {
430 case 0:
431 wk_mask = OMAP3430_ST_UART1_MASK;
432 padconf = 0x182;
433 break;
434 case 1:
435 wk_mask = OMAP3430_ST_UART2_MASK;
436 padconf = 0x17a;
437 break;
438 case 2:
439 wk_mask = OMAP3430_ST_UART3_MASK;
440 padconf = 0x19e;
441 break;
442 }
443 uart->wk_mask = wk_mask;
444 uart->padconf = padconf;
445 } else if (cpu_is_omap24xx()) {
446 u32 wk_mask = 0;
447
448 if (cpu_is_omap2430()) {
449 uart->wk_en = OMAP2430_PRM_REGADDR(CORE_MOD, PM_WKEN1);
450 uart->wk_st = OMAP2430_PRM_REGADDR(CORE_MOD, PM_WKST1);
451 } else if (cpu_is_omap2420()) {
452 uart->wk_en = OMAP2420_PRM_REGADDR(CORE_MOD, PM_WKEN1);
453 uart->wk_st = OMAP2420_PRM_REGADDR(CORE_MOD, PM_WKST1);
454 }
455 switch (uart->num) {
456 case 0:
457 wk_mask = OMAP24XX_ST_UART1_MASK;
458 break;
459 case 1:
460 wk_mask = OMAP24XX_ST_UART2_MASK;
461 break;
462 case 2:
463 wk_mask = OMAP24XX_ST_UART3_MASK;
464 break;
465 }
466 uart->wk_mask = wk_mask;
467 } else {
468 uart->wk_en = 0;
469 uart->wk_st = 0;
470 uart->wk_mask = 0;
471 uart->padconf = 0;
472 }
473
Vikram Panditac426df82009-08-28 11:24:08 -0700474 p->irqflags |= IRQF_SHARED;
Kevin Hilman4af40162009-02-04 10:51:40 -0800475 ret = request_irq(p->irq, omap_uart_interrupt, IRQF_SHARED,
476 "serial idle", (void *)uart);
477 WARN_ON(ret);
478}
479
Tero Kristo24662112009-03-05 16:32:23 +0200480void omap_uart_enable_irqs(int enable)
Jouni Hoganderba87a9b2008-12-09 13:36:50 +0200481{
Tero Kristo24662112009-03-05 16:32:23 +0200482 int ret;
483 struct omap_uart_state *uart;
484
485 list_for_each_entry(uart, &uart_list, node) {
486 if (enable)
487 ret = request_irq(uart->p->irq, omap_uart_interrupt,
488 IRQF_SHARED, "serial idle", (void *)uart);
489 else
490 free_irq(uart->p->irq, (void *)uart);
491 }
Jouni Hoganderba87a9b2008-12-09 13:36:50 +0200492}
493
Kevin Hilmanfd455ea2009-04-27 12:27:36 -0700494static ssize_t sleep_timeout_show(struct device *dev,
495 struct device_attribute *attr,
Jouni Hoganderba87a9b2008-12-09 13:36:50 +0200496 char *buf)
497{
Kevin Hilmanfd455ea2009-04-27 12:27:36 -0700498 struct platform_device *pdev = container_of(dev,
499 struct platform_device, dev);
500 struct omap_uart_state *uart = container_of(pdev,
501 struct omap_uart_state, pdev);
502
503 return sprintf(buf, "%u\n", uart->timeout / HZ);
Jouni Hoganderba87a9b2008-12-09 13:36:50 +0200504}
505
Kevin Hilmanfd455ea2009-04-27 12:27:36 -0700506static ssize_t sleep_timeout_store(struct device *dev,
507 struct device_attribute *attr,
Jouni Hoganderba87a9b2008-12-09 13:36:50 +0200508 const char *buf, size_t n)
509{
Kevin Hilmanfd455ea2009-04-27 12:27:36 -0700510 struct platform_device *pdev = container_of(dev,
511 struct platform_device, dev);
512 struct omap_uart_state *uart = container_of(pdev,
513 struct omap_uart_state, pdev);
Jouni Hoganderba87a9b2008-12-09 13:36:50 +0200514 unsigned int value;
515
516 if (sscanf(buf, "%u", &value) != 1) {
517 printk(KERN_ERR "sleep_timeout_store: Invalid value\n");
518 return -EINVAL;
519 }
Kevin Hilmanfd455ea2009-04-27 12:27:36 -0700520
521 uart->timeout = value * HZ;
522 if (uart->timeout)
523 mod_timer(&uart->timer, jiffies + uart->timeout);
524 else
525 /* A zero value means disable timeout feature */
526 omap_uart_block_sleep(uart);
527
Jouni Hoganderba87a9b2008-12-09 13:36:50 +0200528 return n;
529}
530
Kevin Hilmanfd455ea2009-04-27 12:27:36 -0700531DEVICE_ATTR(sleep_timeout, 0644, sleep_timeout_show, sleep_timeout_store);
532#define DEV_CREATE_FILE(dev, attr) WARN_ON(device_create_file(dev, attr))
Kevin Hilman4af40162009-02-04 10:51:40 -0800533#else
534static inline void omap_uart_idle_init(struct omap_uart_state *uart) {}
Kevin Hilmanfd455ea2009-04-27 12:27:36 -0700535#define DEV_CREATE_FILE(dev, attr)
Kevin Hilman4af40162009-02-04 10:51:40 -0800536#endif /* CONFIG_PM */
537
Kevin Hilmanfd455ea2009-04-27 12:27:36 -0700538static struct omap_uart_state omap_uart[OMAP_MAX_NR_PORTS] = {
539 {
540 .pdev = {
541 .name = "serial8250",
542 .id = PLAT8250_DEV_PLATFORM,
543 .dev = {
544 .platform_data = serial_platform_data0,
545 },
546 },
547 }, {
548 .pdev = {
549 .name = "serial8250",
550 .id = PLAT8250_DEV_PLATFORM1,
551 .dev = {
552 .platform_data = serial_platform_data1,
553 },
554 },
555 }, {
556 .pdev = {
557 .name = "serial8250",
558 .id = PLAT8250_DEV_PLATFORM2,
559 .dev = {
560 .platform_data = serial_platform_data2,
561 },
562 },
Vikram Pandita2aa57be2009-05-28 14:03:59 -0700563 },
Santosh Shilimkar0e3eaad2009-08-22 13:30:11 +0530564#ifdef CONFIG_ARCH_OMAP4
565 {
566 .pdev = {
567 .name = "serial8250",
Tony Lindgren61f04ee2009-09-24 16:23:07 -0700568 .id = 3,
Santosh Shilimkar0e3eaad2009-08-22 13:30:11 +0530569 .dev = {
570 .platform_data = serial_platform_data3,
571 },
572 },
573 },
574#endif
Vikram Pandita2aa57be2009-05-28 14:03:59 -0700575};
576
Paul Walmsleyb3c6df32009-09-03 20:14:02 +0300577void __init omap_serial_early_init(void)
Tony Lindgren1dbae812005-11-10 14:26:51 +0000578{
Kevin Hilmanfd455ea2009-04-27 12:27:36 -0700579 int i;
Jouni Hogander6e811762008-10-06 15:49:15 +0300580 char name[16];
Tony Lindgren1dbae812005-11-10 14:26:51 +0000581
582 /*
583 * Make sure the serial ports are muxed on at this point.
584 * You have to mux them off in device drivers later on
585 * if not needed.
586 */
587
Tony Lindgren1dbae812005-11-10 14:26:51 +0000588 for (i = 0; i < OMAP_MAX_NR_PORTS; i++) {
Kevin Hilman4af40162009-02-04 10:51:40 -0800589 struct omap_uart_state *uart = &omap_uart[i];
Kevin Hilmanfd455ea2009-04-27 12:27:36 -0700590 struct platform_device *pdev = &uart->pdev;
591 struct device *dev = &pdev->dev;
592 struct plat_serial8250_port *p = dev->platform_data;
Tony Lindgren1dbae812005-11-10 14:26:51 +0000593
Tony Lindgren84f90c92009-10-16 09:53:00 -0700594 /*
595 * Module 4KB + L4 interconnect 4KB
596 * Static mapping, never released
597 */
598 p->membase = ioremap(p->mapbase, SZ_8K);
599 if (!p->membase) {
600 printk(KERN_ERR "ioremap failed for uart%i\n", i + 1);
601 continue;
602 }
603
Jouni Hogander6e811762008-10-06 15:49:15 +0300604 sprintf(name, "uart%d_ick", i+1);
Kevin Hilman4af40162009-02-04 10:51:40 -0800605 uart->ick = clk_get(NULL, name);
606 if (IS_ERR(uart->ick)) {
Jouni Hogander6e811762008-10-06 15:49:15 +0300607 printk(KERN_ERR "Could not get uart%d_ick\n", i+1);
Kevin Hilman4af40162009-02-04 10:51:40 -0800608 uart->ick = NULL;
609 }
Tony Lindgren1dbae812005-11-10 14:26:51 +0000610
Jouni Hogander6e811762008-10-06 15:49:15 +0300611 sprintf(name, "uart%d_fck", i+1);
Kevin Hilman4af40162009-02-04 10:51:40 -0800612 uart->fck = clk_get(NULL, name);
613 if (IS_ERR(uart->fck)) {
Jouni Hogander6e811762008-10-06 15:49:15 +0300614 printk(KERN_ERR "Could not get uart%d_fck\n", i+1);
Kevin Hilman4af40162009-02-04 10:51:40 -0800615 uart->fck = NULL;
616 }
Tony Lindgren1dbae812005-11-10 14:26:51 +0000617
Santosh Shilimkaraae290f2009-08-22 13:30:12 +0530618 /* FIXME: Remove this once the clkdev is ready */
619 if (!cpu_is_omap44xx()) {
620 if (!uart->ick || !uart->fck)
621 continue;
622 }
Kevin Hilman4af40162009-02-04 10:51:40 -0800623
624 uart->num = i;
625 p->private_data = uart;
626 uart->p = p;
Kevin Hilmanbcf396c2009-06-30 21:02:45 -0700627 list_add_tail(&uart->node, &uart_list);
Kevin Hilman4af40162009-02-04 10:51:40 -0800628
Kevin Hilman47899982009-06-24 10:32:03 -0700629 if (cpu_is_omap44xx())
630 p->irq += 32;
Kevin Hilman4af40162009-02-04 10:51:40 -0800631
632 omap_uart_enable_clocks(uart);
Paul Walmsleyb3c6df32009-09-03 20:14:02 +0300633 }
634}
635
636void __init omap_serial_init(void)
637{
638 int i;
639
640 for (i = 0; i < OMAP_MAX_NR_PORTS; i++) {
641 struct omap_uart_state *uart = &omap_uart[i];
642 struct platform_device *pdev = &uart->pdev;
643 struct device *dev = &pdev->dev;
644
Kevin Hilman4af40162009-02-04 10:51:40 -0800645 omap_uart_reset(uart);
646 omap_uart_idle_init(uart);
Kevin Hilmanfd455ea2009-04-27 12:27:36 -0700647
648 if (WARN_ON(platform_device_register(pdev)))
649 continue;
650 if ((cpu_is_omap34xx() && uart->padconf) ||
651 (uart->wk_en && uart->wk_mask)) {
652 device_init_wakeup(dev, true);
653 DEV_CREATE_FILE(dev, &dev_attr_sleep_timeout);
654 }
Tony Lindgren1dbae812005-11-10 14:26:51 +0000655 }
Tony Lindgren1dbae812005-11-10 14:26:51 +0000656}