blob: a1949d4262cd878c78b215aa5218022dc66cc993 [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
Russell Kinga09e64f2008-08-05 16:14:15 +010027#include <mach/common.h>
28#include <mach/board.h>
Kevin Hilman4af40162009-02-04 10:51:40 -080029#include <mach/clock.h>
30#include <mach/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 }, {
Syed Rafiuddin085b54d2009-07-28 18:57:22 +0530109#ifdef CONFIG_ARCH_OMAP4
Tony Lindgren5328ae32009-09-24 16:23:04 -0700110 .membase = OMAP2_IO_ADDRESS(OMAP_UART4_BASE),
Syed Rafiuddin085b54d2009-07-28 18:57:22 +0530111 .mapbase = OMAP_UART4_BASE,
112 .irq = 70,
113 .flags = UPF_BOOT_AUTOCONF,
114 .iotype = UPIO_MEM,
115 .regshift = 2,
116 .uartclk = OMAP24XX_BASE_BAUD * 16,
117 }, {
118#endif
Tony Lindgren1dbae812005-11-10 14:26:51 +0000119 .flags = 0
120 }
121};
122
Santosh Shilimkar0e3eaad2009-08-22 13:30:11 +0530123#ifdef CONFIG_ARCH_OMAP4
124static struct plat_serial8250_port serial_platform_data3[] = {
125 {
Santosh Shilimkar0e3eaad2009-08-22 13:30:11 +0530126 .mapbase = OMAP_UART4_BASE,
127 .irq = 70,
128 .flags = UPF_BOOT_AUTOCONF,
129 .iotype = UPIO_MEM,
130 .regshift = 2,
131 .uartclk = OMAP24XX_BASE_BAUD * 16,
132 }, {
133 .flags = 0
134 }
135};
136#endif
Tony Lindgren1dbae812005-11-10 14:26:51 +0000137static inline unsigned int serial_read_reg(struct plat_serial8250_port *up,
138 int offset)
139{
140 offset <<= up->regshift;
141 return (unsigned int)__raw_readb(up->membase + offset);
142}
143
144static inline void serial_write_reg(struct plat_serial8250_port *p, int offset,
145 int value)
146{
147 offset <<= p->regshift;
Russell Kinge8a91c92008-09-01 22:07:37 +0100148 __raw_writeb(value, p->membase + offset);
Tony Lindgren1dbae812005-11-10 14:26:51 +0000149}
150
151/*
152 * Internal UARTs need to be initialized for the 8250 autoconfig to work
153 * properly. Note that the TX watermark initialization may not be needed
154 * once the 8250.c watermark handling code is merged.
155 */
Kevin Hilman4af40162009-02-04 10:51:40 -0800156static inline void __init omap_uart_reset(struct omap_uart_state *uart)
Tony Lindgren1dbae812005-11-10 14:26:51 +0000157{
Kevin Hilman4af40162009-02-04 10:51:40 -0800158 struct plat_serial8250_port *p = uart->p;
159
Tony Lindgren1dbae812005-11-10 14:26:51 +0000160 serial_write_reg(p, UART_OMAP_MDR1, 0x07);
161 serial_write_reg(p, UART_OMAP_SCR, 0x08);
162 serial_write_reg(p, UART_OMAP_MDR1, 0x00);
Juha Yrjola671c7232006-12-06 17:13:49 -0800163 serial_write_reg(p, UART_OMAP_SYSC, (0x02 << 3) | (1 << 2) | (1 << 0));
Tony Lindgren1dbae812005-11-10 14:26:51 +0000164}
165
Kevin Hilman4af40162009-02-04 10:51:40 -0800166#if defined(CONFIG_PM) && defined(CONFIG_ARCH_OMAP3)
167
168static int enable_off_mode; /* to be removed by full off-mode patches */
169
170static void omap_uart_save_context(struct omap_uart_state *uart)
Jouni Hogander6e811762008-10-06 15:49:15 +0300171{
Kevin Hilman4af40162009-02-04 10:51:40 -0800172 u16 lcr = 0;
173 struct plat_serial8250_port *p = uart->p;
174
175 if (!enable_off_mode)
176 return;
177
178 lcr = serial_read_reg(p, UART_LCR);
179 serial_write_reg(p, UART_LCR, 0xBF);
180 uart->dll = serial_read_reg(p, UART_DLL);
181 uart->dlh = serial_read_reg(p, UART_DLM);
182 serial_write_reg(p, UART_LCR, lcr);
183 uart->ier = serial_read_reg(p, UART_IER);
184 uart->sysc = serial_read_reg(p, UART_OMAP_SYSC);
185 uart->scr = serial_read_reg(p, UART_OMAP_SCR);
186 uart->wer = serial_read_reg(p, UART_OMAP_WER);
187
188 uart->context_valid = 1;
189}
190
191static void omap_uart_restore_context(struct omap_uart_state *uart)
192{
193 u16 efr = 0;
194 struct plat_serial8250_port *p = uart->p;
195
196 if (!enable_off_mode)
197 return;
198
199 if (!uart->context_valid)
200 return;
201
202 uart->context_valid = 0;
203
204 serial_write_reg(p, UART_OMAP_MDR1, 0x7);
205 serial_write_reg(p, UART_LCR, 0xBF); /* Config B mode */
206 efr = serial_read_reg(p, UART_EFR);
207 serial_write_reg(p, UART_EFR, UART_EFR_ECB);
208 serial_write_reg(p, UART_LCR, 0x0); /* Operational mode */
209 serial_write_reg(p, UART_IER, 0x0);
210 serial_write_reg(p, UART_LCR, 0xBF); /* Config B mode */
211 serial_write_reg(p, UART_DLL, uart->dll);
212 serial_write_reg(p, UART_DLM, uart->dlh);
213 serial_write_reg(p, UART_LCR, 0x0); /* Operational mode */
214 serial_write_reg(p, UART_IER, uart->ier);
215 serial_write_reg(p, UART_FCR, 0xA1);
216 serial_write_reg(p, UART_LCR, 0xBF); /* Config B mode */
217 serial_write_reg(p, UART_EFR, efr);
218 serial_write_reg(p, UART_LCR, UART_LCR_WLEN8);
219 serial_write_reg(p, UART_OMAP_SCR, uart->scr);
220 serial_write_reg(p, UART_OMAP_WER, uart->wer);
221 serial_write_reg(p, UART_OMAP_SYSC, uart->sysc);
222 serial_write_reg(p, UART_OMAP_MDR1, 0x00); /* UART 16x mode */
223}
224#else
225static inline void omap_uart_save_context(struct omap_uart_state *uart) {}
226static inline void omap_uart_restore_context(struct omap_uart_state *uart) {}
227#endif /* CONFIG_PM && CONFIG_ARCH_OMAP3 */
228
229static inline void omap_uart_enable_clocks(struct omap_uart_state *uart)
230{
231 if (uart->clocked)
232 return;
233
234 clk_enable(uart->ick);
235 clk_enable(uart->fck);
236 uart->clocked = 1;
237 omap_uart_restore_context(uart);
238}
239
240#ifdef CONFIG_PM
241
242static inline void omap_uart_disable_clocks(struct omap_uart_state *uart)
243{
244 if (!uart->clocked)
245 return;
246
247 omap_uart_save_context(uart);
248 uart->clocked = 0;
249 clk_disable(uart->ick);
250 clk_disable(uart->fck);
251}
252
Kevin Hilmanfd455ea2009-04-27 12:27:36 -0700253static void omap_uart_enable_wakeup(struct omap_uart_state *uart)
254{
255 /* Set wake-enable bit */
256 if (uart->wk_en && uart->wk_mask) {
257 u32 v = __raw_readl(uart->wk_en);
258 v |= uart->wk_mask;
259 __raw_writel(v, uart->wk_en);
260 }
261
262 /* Ensure IOPAD wake-enables are set */
263 if (cpu_is_omap34xx() && uart->padconf) {
264 u16 v = omap_ctrl_readw(uart->padconf);
265 v |= OMAP3_PADCONF_WAKEUPENABLE0;
266 omap_ctrl_writew(v, uart->padconf);
267 }
268}
269
270static void omap_uart_disable_wakeup(struct omap_uart_state *uart)
271{
272 /* Clear wake-enable bit */
273 if (uart->wk_en && uart->wk_mask) {
274 u32 v = __raw_readl(uart->wk_en);
275 v &= ~uart->wk_mask;
276 __raw_writel(v, uart->wk_en);
277 }
278
279 /* Ensure IOPAD wake-enables are cleared */
280 if (cpu_is_omap34xx() && uart->padconf) {
281 u16 v = omap_ctrl_readw(uart->padconf);
282 v &= ~OMAP3_PADCONF_WAKEUPENABLE0;
283 omap_ctrl_writew(v, uart->padconf);
284 }
285}
286
Kevin Hilman4af40162009-02-04 10:51:40 -0800287static void omap_uart_smart_idle_enable(struct omap_uart_state *uart,
288 int enable)
289{
290 struct plat_serial8250_port *p = uart->p;
291 u16 sysc;
292
293 sysc = serial_read_reg(p, UART_OMAP_SYSC) & 0x7;
294 if (enable)
295 sysc |= 0x2 << 3;
296 else
297 sysc |= 0x1 << 3;
298
299 serial_write_reg(p, UART_OMAP_SYSC, sysc);
300}
301
302static void omap_uart_block_sleep(struct omap_uart_state *uart)
303{
304 omap_uart_enable_clocks(uart);
305
306 omap_uart_smart_idle_enable(uart, 0);
307 uart->can_sleep = 0;
Jouni Hoganderba87a9b2008-12-09 13:36:50 +0200308 if (uart->timeout)
309 mod_timer(&uart->timer, jiffies + uart->timeout);
310 else
311 del_timer(&uart->timer);
Kevin Hilman4af40162009-02-04 10:51:40 -0800312}
313
314static void omap_uart_allow_sleep(struct omap_uart_state *uart)
315{
Kevin Hilmanfd455ea2009-04-27 12:27:36 -0700316 if (device_may_wakeup(&uart->pdev.dev))
317 omap_uart_enable_wakeup(uart);
318 else
319 omap_uart_disable_wakeup(uart);
320
Kevin Hilman4af40162009-02-04 10:51:40 -0800321 if (!uart->clocked)
322 return;
323
324 omap_uart_smart_idle_enable(uart, 1);
325 uart->can_sleep = 1;
326 del_timer(&uart->timer);
327}
328
329static void omap_uart_idle_timer(unsigned long data)
330{
331 struct omap_uart_state *uart = (struct omap_uart_state *)data;
332
333 omap_uart_allow_sleep(uart);
334}
335
336void omap_uart_prepare_idle(int num)
337{
338 struct omap_uart_state *uart;
339
340 list_for_each_entry(uart, &uart_list, node) {
341 if (num == uart->num && uart->can_sleep) {
342 omap_uart_disable_clocks(uart);
343 return;
Jouni Hogander6e811762008-10-06 15:49:15 +0300344 }
345 }
346}
347
Kevin Hilman4af40162009-02-04 10:51:40 -0800348void omap_uart_resume_idle(int num)
349{
350 struct omap_uart_state *uart;
351
352 list_for_each_entry(uart, &uart_list, node) {
353 if (num == uart->num) {
354 omap_uart_enable_clocks(uart);
355
356 /* Check for IO pad wakeup */
357 if (cpu_is_omap34xx() && uart->padconf) {
358 u16 p = omap_ctrl_readw(uart->padconf);
359
360 if (p & OMAP3_PADCONF_WAKEUPEVENT0)
361 omap_uart_block_sleep(uart);
362 }
363
364 /* Check for normal UART wakeup */
365 if (__raw_readl(uart->wk_st) & uart->wk_mask)
366 omap_uart_block_sleep(uart);
Kevin Hilman4af40162009-02-04 10:51:40 -0800367 return;
368 }
369 }
370}
371
372void omap_uart_prepare_suspend(void)
373{
374 struct omap_uart_state *uart;
375
376 list_for_each_entry(uart, &uart_list, node) {
377 omap_uart_allow_sleep(uart);
378 }
379}
380
381int omap_uart_can_sleep(void)
382{
383 struct omap_uart_state *uart;
384 int can_sleep = 1;
385
386 list_for_each_entry(uart, &uart_list, node) {
387 if (!uart->clocked)
388 continue;
389
390 if (!uart->can_sleep) {
391 can_sleep = 0;
392 continue;
393 }
394
395 /* This UART can now safely sleep. */
396 omap_uart_allow_sleep(uart);
397 }
398
399 return can_sleep;
400}
401
402/**
403 * omap_uart_interrupt()
404 *
405 * This handler is used only to detect that *any* UART interrupt has
406 * occurred. It does _nothing_ to handle the interrupt. Rather,
407 * any UART interrupt will trigger the inactivity timer so the
408 * UART will not idle or sleep for its timeout period.
409 *
410 **/
411static irqreturn_t omap_uart_interrupt(int irq, void *dev_id)
412{
413 struct omap_uart_state *uart = dev_id;
414
415 omap_uart_block_sleep(uart);
416
417 return IRQ_NONE;
418}
419
420static void omap_uart_idle_init(struct omap_uart_state *uart)
421{
Kevin Hilman4af40162009-02-04 10:51:40 -0800422 struct plat_serial8250_port *p = uart->p;
423 int ret;
424
425 uart->can_sleep = 0;
Kevin Hilmanfd455ea2009-04-27 12:27:36 -0700426 uart->timeout = DEFAULT_TIMEOUT;
Kevin Hilman4af40162009-02-04 10:51:40 -0800427 setup_timer(&uart->timer, omap_uart_idle_timer,
428 (unsigned long) uart);
429 mod_timer(&uart->timer, jiffies + uart->timeout);
430 omap_uart_smart_idle_enable(uart, 0);
431
432 if (cpu_is_omap34xx()) {
433 u32 mod = (uart->num == 2) ? OMAP3430_PER_MOD : CORE_MOD;
434 u32 wk_mask = 0;
435 u32 padconf = 0;
436
437 uart->wk_en = OMAP34XX_PRM_REGADDR(mod, PM_WKEN1);
438 uart->wk_st = OMAP34XX_PRM_REGADDR(mod, PM_WKST1);
439 switch (uart->num) {
440 case 0:
441 wk_mask = OMAP3430_ST_UART1_MASK;
442 padconf = 0x182;
443 break;
444 case 1:
445 wk_mask = OMAP3430_ST_UART2_MASK;
446 padconf = 0x17a;
447 break;
448 case 2:
449 wk_mask = OMAP3430_ST_UART3_MASK;
450 padconf = 0x19e;
451 break;
452 }
453 uart->wk_mask = wk_mask;
454 uart->padconf = padconf;
455 } else if (cpu_is_omap24xx()) {
456 u32 wk_mask = 0;
457
458 if (cpu_is_omap2430()) {
459 uart->wk_en = OMAP2430_PRM_REGADDR(CORE_MOD, PM_WKEN1);
460 uart->wk_st = OMAP2430_PRM_REGADDR(CORE_MOD, PM_WKST1);
461 } else if (cpu_is_omap2420()) {
462 uart->wk_en = OMAP2420_PRM_REGADDR(CORE_MOD, PM_WKEN1);
463 uart->wk_st = OMAP2420_PRM_REGADDR(CORE_MOD, PM_WKST1);
464 }
465 switch (uart->num) {
466 case 0:
467 wk_mask = OMAP24XX_ST_UART1_MASK;
468 break;
469 case 1:
470 wk_mask = OMAP24XX_ST_UART2_MASK;
471 break;
472 case 2:
473 wk_mask = OMAP24XX_ST_UART3_MASK;
474 break;
475 }
476 uart->wk_mask = wk_mask;
477 } else {
478 uart->wk_en = 0;
479 uart->wk_st = 0;
480 uart->wk_mask = 0;
481 uart->padconf = 0;
482 }
483
Vikram Panditac426df82009-08-28 11:24:08 -0700484 p->irqflags |= IRQF_SHARED;
Kevin Hilman4af40162009-02-04 10:51:40 -0800485 ret = request_irq(p->irq, omap_uart_interrupt, IRQF_SHARED,
486 "serial idle", (void *)uart);
487 WARN_ON(ret);
488}
489
Tero Kristo24662112009-03-05 16:32:23 +0200490void omap_uart_enable_irqs(int enable)
Jouni Hoganderba87a9b2008-12-09 13:36:50 +0200491{
Tero Kristo24662112009-03-05 16:32:23 +0200492 int ret;
493 struct omap_uart_state *uart;
494
495 list_for_each_entry(uart, &uart_list, node) {
496 if (enable)
497 ret = request_irq(uart->p->irq, omap_uart_interrupt,
498 IRQF_SHARED, "serial idle", (void *)uart);
499 else
500 free_irq(uart->p->irq, (void *)uart);
501 }
Jouni Hoganderba87a9b2008-12-09 13:36:50 +0200502}
503
Kevin Hilmanfd455ea2009-04-27 12:27:36 -0700504static ssize_t sleep_timeout_show(struct device *dev,
505 struct device_attribute *attr,
Jouni Hoganderba87a9b2008-12-09 13:36:50 +0200506 char *buf)
507{
Kevin Hilmanfd455ea2009-04-27 12:27:36 -0700508 struct platform_device *pdev = container_of(dev,
509 struct platform_device, dev);
510 struct omap_uart_state *uart = container_of(pdev,
511 struct omap_uart_state, pdev);
512
513 return sprintf(buf, "%u\n", uart->timeout / HZ);
Jouni Hoganderba87a9b2008-12-09 13:36:50 +0200514}
515
Kevin Hilmanfd455ea2009-04-27 12:27:36 -0700516static ssize_t sleep_timeout_store(struct device *dev,
517 struct device_attribute *attr,
Jouni Hoganderba87a9b2008-12-09 13:36:50 +0200518 const char *buf, size_t n)
519{
Kevin Hilmanfd455ea2009-04-27 12:27:36 -0700520 struct platform_device *pdev = container_of(dev,
521 struct platform_device, dev);
522 struct omap_uart_state *uart = container_of(pdev,
523 struct omap_uart_state, pdev);
Jouni Hoganderba87a9b2008-12-09 13:36:50 +0200524 unsigned int value;
525
526 if (sscanf(buf, "%u", &value) != 1) {
527 printk(KERN_ERR "sleep_timeout_store: Invalid value\n");
528 return -EINVAL;
529 }
Kevin Hilmanfd455ea2009-04-27 12:27:36 -0700530
531 uart->timeout = value * HZ;
532 if (uart->timeout)
533 mod_timer(&uart->timer, jiffies + uart->timeout);
534 else
535 /* A zero value means disable timeout feature */
536 omap_uart_block_sleep(uart);
537
Jouni Hoganderba87a9b2008-12-09 13:36:50 +0200538 return n;
539}
540
Kevin Hilmanfd455ea2009-04-27 12:27:36 -0700541DEVICE_ATTR(sleep_timeout, 0644, sleep_timeout_show, sleep_timeout_store);
542#define DEV_CREATE_FILE(dev, attr) WARN_ON(device_create_file(dev, attr))
Kevin Hilman4af40162009-02-04 10:51:40 -0800543#else
544static inline void omap_uart_idle_init(struct omap_uart_state *uart) {}
Kevin Hilmanfd455ea2009-04-27 12:27:36 -0700545#define DEV_CREATE_FILE(dev, attr)
Kevin Hilman4af40162009-02-04 10:51:40 -0800546#endif /* CONFIG_PM */
547
Kevin Hilmanfd455ea2009-04-27 12:27:36 -0700548static struct omap_uart_state omap_uart[OMAP_MAX_NR_PORTS] = {
549 {
550 .pdev = {
551 .name = "serial8250",
552 .id = PLAT8250_DEV_PLATFORM,
553 .dev = {
554 .platform_data = serial_platform_data0,
555 },
556 },
557 }, {
558 .pdev = {
559 .name = "serial8250",
560 .id = PLAT8250_DEV_PLATFORM1,
561 .dev = {
562 .platform_data = serial_platform_data1,
563 },
564 },
565 }, {
566 .pdev = {
567 .name = "serial8250",
568 .id = PLAT8250_DEV_PLATFORM2,
569 .dev = {
570 .platform_data = serial_platform_data2,
571 },
572 },
Vikram Pandita2aa57be2009-05-28 14:03:59 -0700573 },
Santosh Shilimkar0e3eaad2009-08-22 13:30:11 +0530574#ifdef CONFIG_ARCH_OMAP4
575 {
576 .pdev = {
577 .name = "serial8250",
Tony Lindgren61f04ee2009-09-24 16:23:07 -0700578 .id = 3,
Santosh Shilimkar0e3eaad2009-08-22 13:30:11 +0530579 .dev = {
580 .platform_data = serial_platform_data3,
581 },
582 },
583 },
584#endif
Vikram Pandita2aa57be2009-05-28 14:03:59 -0700585};
586
Paul Walmsleyb3c6df32009-09-03 20:14:02 +0300587void __init omap_serial_early_init(void)
Tony Lindgren1dbae812005-11-10 14:26:51 +0000588{
Kevin Hilmanfd455ea2009-04-27 12:27:36 -0700589 int i;
Jouni Hogander6e811762008-10-06 15:49:15 +0300590 char name[16];
Tony Lindgren1dbae812005-11-10 14:26:51 +0000591
592 /*
593 * Make sure the serial ports are muxed on at this point.
594 * You have to mux them off in device drivers later on
595 * if not needed.
596 */
597
Tony Lindgren1dbae812005-11-10 14:26:51 +0000598 for (i = 0; i < OMAP_MAX_NR_PORTS; i++) {
Kevin Hilman4af40162009-02-04 10:51:40 -0800599 struct omap_uart_state *uart = &omap_uart[i];
Kevin Hilmanfd455ea2009-04-27 12:27:36 -0700600 struct platform_device *pdev = &uart->pdev;
601 struct device *dev = &pdev->dev;
602 struct plat_serial8250_port *p = dev->platform_data;
Tony Lindgren1dbae812005-11-10 14:26:51 +0000603
Tony Lindgren84f90c92009-10-16 09:53:00 -0700604 /*
605 * Module 4KB + L4 interconnect 4KB
606 * Static mapping, never released
607 */
608 p->membase = ioremap(p->mapbase, SZ_8K);
609 if (!p->membase) {
610 printk(KERN_ERR "ioremap failed for uart%i\n", i + 1);
611 continue;
612 }
613
Jouni Hogander6e811762008-10-06 15:49:15 +0300614 sprintf(name, "uart%d_ick", i+1);
Kevin Hilman4af40162009-02-04 10:51:40 -0800615 uart->ick = clk_get(NULL, name);
616 if (IS_ERR(uart->ick)) {
Jouni Hogander6e811762008-10-06 15:49:15 +0300617 printk(KERN_ERR "Could not get uart%d_ick\n", i+1);
Kevin Hilman4af40162009-02-04 10:51:40 -0800618 uart->ick = NULL;
619 }
Tony Lindgren1dbae812005-11-10 14:26:51 +0000620
Jouni Hogander6e811762008-10-06 15:49:15 +0300621 sprintf(name, "uart%d_fck", i+1);
Kevin Hilman4af40162009-02-04 10:51:40 -0800622 uart->fck = clk_get(NULL, name);
623 if (IS_ERR(uart->fck)) {
Jouni Hogander6e811762008-10-06 15:49:15 +0300624 printk(KERN_ERR "Could not get uart%d_fck\n", i+1);
Kevin Hilman4af40162009-02-04 10:51:40 -0800625 uart->fck = NULL;
626 }
Tony Lindgren1dbae812005-11-10 14:26:51 +0000627
Santosh Shilimkaraae290f2009-08-22 13:30:12 +0530628 /* FIXME: Remove this once the clkdev is ready */
629 if (!cpu_is_omap44xx()) {
630 if (!uart->ick || !uart->fck)
631 continue;
632 }
Kevin Hilman4af40162009-02-04 10:51:40 -0800633
634 uart->num = i;
635 p->private_data = uart;
636 uart->p = p;
Kevin Hilmanbcf396c2009-06-30 21:02:45 -0700637 list_add_tail(&uart->node, &uart_list);
Kevin Hilman4af40162009-02-04 10:51:40 -0800638
Kevin Hilman47899982009-06-24 10:32:03 -0700639 if (cpu_is_omap44xx())
640 p->irq += 32;
Kevin Hilman4af40162009-02-04 10:51:40 -0800641
642 omap_uart_enable_clocks(uart);
Paul Walmsleyb3c6df32009-09-03 20:14:02 +0300643 }
644}
645
646void __init omap_serial_init(void)
647{
648 int i;
649
650 for (i = 0; i < OMAP_MAX_NR_PORTS; i++) {
651 struct omap_uart_state *uart = &omap_uart[i];
652 struct platform_device *pdev = &uart->pdev;
653 struct device *dev = &pdev->dev;
654
Kevin Hilman4af40162009-02-04 10:51:40 -0800655 omap_uart_reset(uart);
656 omap_uart_idle_init(uart);
Kevin Hilmanfd455ea2009-04-27 12:27:36 -0700657
658 if (WARN_ON(platform_device_register(pdev)))
659 continue;
660 if ((cpu_is_omap34xx() && uart->padconf) ||
661 (uart->wk_en && uart->wk_mask)) {
662 device_init_wakeup(dev, true);
663 DEV_CREATE_FILE(dev, &dev_attr_sleep_timeout);
664 }
Tony Lindgren1dbae812005-11-10 14:26:51 +0000665 }
Tony Lindgren1dbae812005-11-10 14:26:51 +0000666}