blob: ce22344b94e73929e67c43f39418776e4c88c08b [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 .membase = IO_ADDRESS(OMAP_UART1_BASE),
77 .mapbase = OMAP_UART1_BASE,
Tony Lindgren1dbae812005-11-10 14:26:51 +000078 .irq = 72,
79 .flags = UPF_BOOT_AUTOCONF,
80 .iotype = UPIO_MEM,
81 .regshift = 2,
Jouni Hogander6e811762008-10-06 15:49:15 +030082 .uartclk = OMAP24XX_BASE_BAUD * 16,
Tony Lindgren1dbae812005-11-10 14:26:51 +000083 }, {
Kevin Hilmanfd455ea2009-04-27 12:27:36 -070084 .flags = 0
85 }
86};
87
88static struct plat_serial8250_port serial_platform_data1[] = {
89 {
Russell Kinge8a91c92008-09-01 22:07:37 +010090 .membase = IO_ADDRESS(OMAP_UART2_BASE),
91 .mapbase = OMAP_UART2_BASE,
Tony Lindgren1dbae812005-11-10 14:26:51 +000092 .irq = 73,
93 .flags = UPF_BOOT_AUTOCONF,
94 .iotype = UPIO_MEM,
95 .regshift = 2,
Jouni Hogander6e811762008-10-06 15:49:15 +030096 .uartclk = OMAP24XX_BASE_BAUD * 16,
Tony Lindgren1dbae812005-11-10 14:26:51 +000097 }, {
Kevin Hilmanfd455ea2009-04-27 12:27:36 -070098 .flags = 0
99 }
100};
101
102static struct plat_serial8250_port serial_platform_data2[] = {
103 {
Russell Kinge8a91c92008-09-01 22:07:37 +0100104 .membase = IO_ADDRESS(OMAP_UART3_BASE),
105 .mapbase = OMAP_UART3_BASE,
Tony Lindgren1dbae812005-11-10 14:26:51 +0000106 .irq = 74,
107 .flags = UPF_BOOT_AUTOCONF,
108 .iotype = UPIO_MEM,
109 .regshift = 2,
Jouni Hogander6e811762008-10-06 15:49:15 +0300110 .uartclk = OMAP24XX_BASE_BAUD * 16,
Tony Lindgren1dbae812005-11-10 14:26:51 +0000111 }, {
Syed Rafiuddin085b54d2009-07-28 18:57:22 +0530112#ifdef CONFIG_ARCH_OMAP4
113 .membase = IO_ADDRESS(OMAP_UART4_BASE),
114 .mapbase = OMAP_UART4_BASE,
115 .irq = 70,
116 .flags = UPF_BOOT_AUTOCONF,
117 .iotype = UPIO_MEM,
118 .regshift = 2,
119 .uartclk = OMAP24XX_BASE_BAUD * 16,
120 }, {
121#endif
Tony Lindgren1dbae812005-11-10 14:26:51 +0000122 .flags = 0
123 }
124};
125
126static inline unsigned int serial_read_reg(struct plat_serial8250_port *up,
127 int offset)
128{
129 offset <<= up->regshift;
130 return (unsigned int)__raw_readb(up->membase + offset);
131}
132
133static inline void serial_write_reg(struct plat_serial8250_port *p, int offset,
134 int value)
135{
136 offset <<= p->regshift;
Russell Kinge8a91c92008-09-01 22:07:37 +0100137 __raw_writeb(value, p->membase + offset);
Tony Lindgren1dbae812005-11-10 14:26:51 +0000138}
139
140/*
141 * Internal UARTs need to be initialized for the 8250 autoconfig to work
142 * properly. Note that the TX watermark initialization may not be needed
143 * once the 8250.c watermark handling code is merged.
144 */
Kevin Hilman4af40162009-02-04 10:51:40 -0800145static inline void __init omap_uart_reset(struct omap_uart_state *uart)
Tony Lindgren1dbae812005-11-10 14:26:51 +0000146{
Kevin Hilman4af40162009-02-04 10:51:40 -0800147 struct plat_serial8250_port *p = uart->p;
148
Tony Lindgren1dbae812005-11-10 14:26:51 +0000149 serial_write_reg(p, UART_OMAP_MDR1, 0x07);
150 serial_write_reg(p, UART_OMAP_SCR, 0x08);
151 serial_write_reg(p, UART_OMAP_MDR1, 0x00);
Juha Yrjola671c7232006-12-06 17:13:49 -0800152 serial_write_reg(p, UART_OMAP_SYSC, (0x02 << 3) | (1 << 2) | (1 << 0));
Tony Lindgren1dbae812005-11-10 14:26:51 +0000153}
154
Kevin Hilman4af40162009-02-04 10:51:40 -0800155#if defined(CONFIG_PM) && defined(CONFIG_ARCH_OMAP3)
156
157static int enable_off_mode; /* to be removed by full off-mode patches */
158
159static void omap_uart_save_context(struct omap_uart_state *uart)
Jouni Hogander6e811762008-10-06 15:49:15 +0300160{
Kevin Hilman4af40162009-02-04 10:51:40 -0800161 u16 lcr = 0;
162 struct plat_serial8250_port *p = uart->p;
163
164 if (!enable_off_mode)
165 return;
166
167 lcr = serial_read_reg(p, UART_LCR);
168 serial_write_reg(p, UART_LCR, 0xBF);
169 uart->dll = serial_read_reg(p, UART_DLL);
170 uart->dlh = serial_read_reg(p, UART_DLM);
171 serial_write_reg(p, UART_LCR, lcr);
172 uart->ier = serial_read_reg(p, UART_IER);
173 uart->sysc = serial_read_reg(p, UART_OMAP_SYSC);
174 uart->scr = serial_read_reg(p, UART_OMAP_SCR);
175 uart->wer = serial_read_reg(p, UART_OMAP_WER);
176
177 uart->context_valid = 1;
178}
179
180static void omap_uart_restore_context(struct omap_uart_state *uart)
181{
182 u16 efr = 0;
183 struct plat_serial8250_port *p = uart->p;
184
185 if (!enable_off_mode)
186 return;
187
188 if (!uart->context_valid)
189 return;
190
191 uart->context_valid = 0;
192
193 serial_write_reg(p, UART_OMAP_MDR1, 0x7);
194 serial_write_reg(p, UART_LCR, 0xBF); /* Config B mode */
195 efr = serial_read_reg(p, UART_EFR);
196 serial_write_reg(p, UART_EFR, UART_EFR_ECB);
197 serial_write_reg(p, UART_LCR, 0x0); /* Operational mode */
198 serial_write_reg(p, UART_IER, 0x0);
199 serial_write_reg(p, UART_LCR, 0xBF); /* Config B mode */
200 serial_write_reg(p, UART_DLL, uart->dll);
201 serial_write_reg(p, UART_DLM, uart->dlh);
202 serial_write_reg(p, UART_LCR, 0x0); /* Operational mode */
203 serial_write_reg(p, UART_IER, uart->ier);
204 serial_write_reg(p, UART_FCR, 0xA1);
205 serial_write_reg(p, UART_LCR, 0xBF); /* Config B mode */
206 serial_write_reg(p, UART_EFR, efr);
207 serial_write_reg(p, UART_LCR, UART_LCR_WLEN8);
208 serial_write_reg(p, UART_OMAP_SCR, uart->scr);
209 serial_write_reg(p, UART_OMAP_WER, uart->wer);
210 serial_write_reg(p, UART_OMAP_SYSC, uart->sysc);
211 serial_write_reg(p, UART_OMAP_MDR1, 0x00); /* UART 16x mode */
212}
213#else
214static inline void omap_uart_save_context(struct omap_uart_state *uart) {}
215static inline void omap_uart_restore_context(struct omap_uart_state *uart) {}
216#endif /* CONFIG_PM && CONFIG_ARCH_OMAP3 */
217
218static inline void omap_uart_enable_clocks(struct omap_uart_state *uart)
219{
220 if (uart->clocked)
221 return;
222
223 clk_enable(uart->ick);
224 clk_enable(uart->fck);
225 uart->clocked = 1;
226 omap_uart_restore_context(uart);
227}
228
229#ifdef CONFIG_PM
230
231static inline void omap_uart_disable_clocks(struct omap_uart_state *uart)
232{
233 if (!uart->clocked)
234 return;
235
236 omap_uart_save_context(uart);
237 uart->clocked = 0;
238 clk_disable(uart->ick);
239 clk_disable(uart->fck);
240}
241
Kevin Hilmanfd455ea2009-04-27 12:27:36 -0700242static void omap_uart_enable_wakeup(struct omap_uart_state *uart)
243{
244 /* Set wake-enable bit */
245 if (uart->wk_en && uart->wk_mask) {
246 u32 v = __raw_readl(uart->wk_en);
247 v |= uart->wk_mask;
248 __raw_writel(v, uart->wk_en);
249 }
250
251 /* Ensure IOPAD wake-enables are set */
252 if (cpu_is_omap34xx() && uart->padconf) {
253 u16 v = omap_ctrl_readw(uart->padconf);
254 v |= OMAP3_PADCONF_WAKEUPENABLE0;
255 omap_ctrl_writew(v, uart->padconf);
256 }
257}
258
259static void omap_uart_disable_wakeup(struct omap_uart_state *uart)
260{
261 /* Clear wake-enable bit */
262 if (uart->wk_en && uart->wk_mask) {
263 u32 v = __raw_readl(uart->wk_en);
264 v &= ~uart->wk_mask;
265 __raw_writel(v, uart->wk_en);
266 }
267
268 /* Ensure IOPAD wake-enables are cleared */
269 if (cpu_is_omap34xx() && uart->padconf) {
270 u16 v = omap_ctrl_readw(uart->padconf);
271 v &= ~OMAP3_PADCONF_WAKEUPENABLE0;
272 omap_ctrl_writew(v, uart->padconf);
273 }
274}
275
Kevin Hilman4af40162009-02-04 10:51:40 -0800276static void omap_uart_smart_idle_enable(struct omap_uart_state *uart,
277 int enable)
278{
279 struct plat_serial8250_port *p = uart->p;
280 u16 sysc;
281
282 sysc = serial_read_reg(p, UART_OMAP_SYSC) & 0x7;
283 if (enable)
284 sysc |= 0x2 << 3;
285 else
286 sysc |= 0x1 << 3;
287
288 serial_write_reg(p, UART_OMAP_SYSC, sysc);
289}
290
291static void omap_uart_block_sleep(struct omap_uart_state *uart)
292{
293 omap_uart_enable_clocks(uart);
294
295 omap_uart_smart_idle_enable(uart, 0);
296 uart->can_sleep = 0;
Jouni Hoganderba87a9b2008-12-09 13:36:50 +0200297 if (uart->timeout)
298 mod_timer(&uart->timer, jiffies + uart->timeout);
299 else
300 del_timer(&uart->timer);
Kevin Hilman4af40162009-02-04 10:51:40 -0800301}
302
303static void omap_uart_allow_sleep(struct omap_uart_state *uart)
304{
Kevin Hilmanfd455ea2009-04-27 12:27:36 -0700305 if (device_may_wakeup(&uart->pdev.dev))
306 omap_uart_enable_wakeup(uart);
307 else
308 omap_uart_disable_wakeup(uart);
309
Kevin Hilman4af40162009-02-04 10:51:40 -0800310 if (!uart->clocked)
311 return;
312
313 omap_uart_smart_idle_enable(uart, 1);
314 uart->can_sleep = 1;
315 del_timer(&uart->timer);
316}
317
318static void omap_uart_idle_timer(unsigned long data)
319{
320 struct omap_uart_state *uart = (struct omap_uart_state *)data;
321
322 omap_uart_allow_sleep(uart);
323}
324
325void omap_uart_prepare_idle(int num)
326{
327 struct omap_uart_state *uart;
328
329 list_for_each_entry(uart, &uart_list, node) {
330 if (num == uart->num && uart->can_sleep) {
331 omap_uart_disable_clocks(uart);
332 return;
Jouni Hogander6e811762008-10-06 15:49:15 +0300333 }
334 }
335}
336
Kevin Hilman4af40162009-02-04 10:51:40 -0800337void omap_uart_resume_idle(int num)
338{
339 struct omap_uart_state *uart;
340
341 list_for_each_entry(uart, &uart_list, node) {
342 if (num == uart->num) {
343 omap_uart_enable_clocks(uart);
344
345 /* Check for IO pad wakeup */
346 if (cpu_is_omap34xx() && uart->padconf) {
347 u16 p = omap_ctrl_readw(uart->padconf);
348
349 if (p & OMAP3_PADCONF_WAKEUPEVENT0)
350 omap_uart_block_sleep(uart);
351 }
352
353 /* Check for normal UART wakeup */
354 if (__raw_readl(uart->wk_st) & uart->wk_mask)
355 omap_uart_block_sleep(uart);
Kevin Hilman4af40162009-02-04 10:51:40 -0800356 return;
357 }
358 }
359}
360
361void omap_uart_prepare_suspend(void)
362{
363 struct omap_uart_state *uart;
364
365 list_for_each_entry(uart, &uart_list, node) {
366 omap_uart_allow_sleep(uart);
367 }
368}
369
370int omap_uart_can_sleep(void)
371{
372 struct omap_uart_state *uart;
373 int can_sleep = 1;
374
375 list_for_each_entry(uart, &uart_list, node) {
376 if (!uart->clocked)
377 continue;
378
379 if (!uart->can_sleep) {
380 can_sleep = 0;
381 continue;
382 }
383
384 /* This UART can now safely sleep. */
385 omap_uart_allow_sleep(uart);
386 }
387
388 return can_sleep;
389}
390
391/**
392 * omap_uart_interrupt()
393 *
394 * This handler is used only to detect that *any* UART interrupt has
395 * occurred. It does _nothing_ to handle the interrupt. Rather,
396 * any UART interrupt will trigger the inactivity timer so the
397 * UART will not idle or sleep for its timeout period.
398 *
399 **/
400static irqreturn_t omap_uart_interrupt(int irq, void *dev_id)
401{
402 struct omap_uart_state *uart = dev_id;
403
404 omap_uart_block_sleep(uart);
405
406 return IRQ_NONE;
407}
408
409static void omap_uart_idle_init(struct omap_uart_state *uart)
410{
Kevin Hilman4af40162009-02-04 10:51:40 -0800411 struct plat_serial8250_port *p = uart->p;
412 int ret;
413
414 uart->can_sleep = 0;
Kevin Hilmanfd455ea2009-04-27 12:27:36 -0700415 uart->timeout = DEFAULT_TIMEOUT;
Kevin Hilman4af40162009-02-04 10:51:40 -0800416 setup_timer(&uart->timer, omap_uart_idle_timer,
417 (unsigned long) uart);
418 mod_timer(&uart->timer, jiffies + uart->timeout);
419 omap_uart_smart_idle_enable(uart, 0);
420
421 if (cpu_is_omap34xx()) {
422 u32 mod = (uart->num == 2) ? OMAP3430_PER_MOD : CORE_MOD;
423 u32 wk_mask = 0;
424 u32 padconf = 0;
425
426 uart->wk_en = OMAP34XX_PRM_REGADDR(mod, PM_WKEN1);
427 uart->wk_st = OMAP34XX_PRM_REGADDR(mod, PM_WKST1);
428 switch (uart->num) {
429 case 0:
430 wk_mask = OMAP3430_ST_UART1_MASK;
431 padconf = 0x182;
432 break;
433 case 1:
434 wk_mask = OMAP3430_ST_UART2_MASK;
435 padconf = 0x17a;
436 break;
437 case 2:
438 wk_mask = OMAP3430_ST_UART3_MASK;
439 padconf = 0x19e;
440 break;
441 }
442 uart->wk_mask = wk_mask;
443 uart->padconf = padconf;
444 } else if (cpu_is_omap24xx()) {
445 u32 wk_mask = 0;
446
447 if (cpu_is_omap2430()) {
448 uart->wk_en = OMAP2430_PRM_REGADDR(CORE_MOD, PM_WKEN1);
449 uart->wk_st = OMAP2430_PRM_REGADDR(CORE_MOD, PM_WKST1);
450 } else if (cpu_is_omap2420()) {
451 uart->wk_en = OMAP2420_PRM_REGADDR(CORE_MOD, PM_WKEN1);
452 uart->wk_st = OMAP2420_PRM_REGADDR(CORE_MOD, PM_WKST1);
453 }
454 switch (uart->num) {
455 case 0:
456 wk_mask = OMAP24XX_ST_UART1_MASK;
457 break;
458 case 1:
459 wk_mask = OMAP24XX_ST_UART2_MASK;
460 break;
461 case 2:
462 wk_mask = OMAP24XX_ST_UART3_MASK;
463 break;
464 }
465 uart->wk_mask = wk_mask;
466 } else {
467 uart->wk_en = 0;
468 uart->wk_st = 0;
469 uart->wk_mask = 0;
470 uart->padconf = 0;
471 }
472
Kevin Hilman4af40162009-02-04 10:51:40 -0800473 p->flags |= UPF_SHARE_IRQ;
474 ret = request_irq(p->irq, omap_uart_interrupt, IRQF_SHARED,
475 "serial idle", (void *)uart);
476 WARN_ON(ret);
477}
478
Tero Kristo24662112009-03-05 16:32:23 +0200479void omap_uart_enable_irqs(int enable)
Jouni Hoganderba87a9b2008-12-09 13:36:50 +0200480{
Tero Kristo24662112009-03-05 16:32:23 +0200481 int ret;
482 struct omap_uart_state *uart;
483
484 list_for_each_entry(uart, &uart_list, node) {
485 if (enable)
486 ret = request_irq(uart->p->irq, omap_uart_interrupt,
487 IRQF_SHARED, "serial idle", (void *)uart);
488 else
489 free_irq(uart->p->irq, (void *)uart);
490 }
Jouni Hoganderba87a9b2008-12-09 13:36:50 +0200491}
492
Kevin Hilmanfd455ea2009-04-27 12:27:36 -0700493static ssize_t sleep_timeout_show(struct device *dev,
494 struct device_attribute *attr,
Jouni Hoganderba87a9b2008-12-09 13:36:50 +0200495 char *buf)
496{
Kevin Hilmanfd455ea2009-04-27 12:27:36 -0700497 struct platform_device *pdev = container_of(dev,
498 struct platform_device, dev);
499 struct omap_uart_state *uart = container_of(pdev,
500 struct omap_uart_state, pdev);
501
502 return sprintf(buf, "%u\n", uart->timeout / HZ);
Jouni Hoganderba87a9b2008-12-09 13:36:50 +0200503}
504
Kevin Hilmanfd455ea2009-04-27 12:27:36 -0700505static ssize_t sleep_timeout_store(struct device *dev,
506 struct device_attribute *attr,
Jouni Hoganderba87a9b2008-12-09 13:36:50 +0200507 const char *buf, size_t n)
508{
Kevin Hilmanfd455ea2009-04-27 12:27:36 -0700509 struct platform_device *pdev = container_of(dev,
510 struct platform_device, dev);
511 struct omap_uart_state *uart = container_of(pdev,
512 struct omap_uart_state, pdev);
Jouni Hoganderba87a9b2008-12-09 13:36:50 +0200513 unsigned int value;
514
515 if (sscanf(buf, "%u", &value) != 1) {
516 printk(KERN_ERR "sleep_timeout_store: Invalid value\n");
517 return -EINVAL;
518 }
Kevin Hilmanfd455ea2009-04-27 12:27:36 -0700519
520 uart->timeout = value * HZ;
521 if (uart->timeout)
522 mod_timer(&uart->timer, jiffies + uart->timeout);
523 else
524 /* A zero value means disable timeout feature */
525 omap_uart_block_sleep(uart);
526
Jouni Hoganderba87a9b2008-12-09 13:36:50 +0200527 return n;
528}
529
Kevin Hilmanfd455ea2009-04-27 12:27:36 -0700530DEVICE_ATTR(sleep_timeout, 0644, sleep_timeout_show, sleep_timeout_store);
531#define DEV_CREATE_FILE(dev, attr) WARN_ON(device_create_file(dev, attr))
Kevin Hilman4af40162009-02-04 10:51:40 -0800532#else
533static inline void omap_uart_idle_init(struct omap_uart_state *uart) {}
Kevin Hilmanfd455ea2009-04-27 12:27:36 -0700534#define DEV_CREATE_FILE(dev, attr)
Kevin Hilman4af40162009-02-04 10:51:40 -0800535#endif /* CONFIG_PM */
536
Kevin Hilmanfd455ea2009-04-27 12:27:36 -0700537static struct omap_uart_state omap_uart[OMAP_MAX_NR_PORTS] = {
538 {
539 .pdev = {
540 .name = "serial8250",
541 .id = PLAT8250_DEV_PLATFORM,
542 .dev = {
543 .platform_data = serial_platform_data0,
544 },
545 },
546 }, {
547 .pdev = {
548 .name = "serial8250",
549 .id = PLAT8250_DEV_PLATFORM1,
550 .dev = {
551 .platform_data = serial_platform_data1,
552 },
553 },
554 }, {
555 .pdev = {
556 .name = "serial8250",
557 .id = PLAT8250_DEV_PLATFORM2,
558 .dev = {
559 .platform_data = serial_platform_data2,
560 },
561 },
Vikram Pandita2aa57be2009-05-28 14:03:59 -0700562 },
563};
564
Jouni Hogander6e811762008-10-06 15:49:15 +0300565void __init omap_serial_init(void)
Tony Lindgren1dbae812005-11-10 14:26:51 +0000566{
Kevin Hilmanfd455ea2009-04-27 12:27:36 -0700567 int i;
Tony Lindgren1dbae812005-11-10 14:26:51 +0000568 const struct omap_uart_config *info;
Jouni Hogander6e811762008-10-06 15:49:15 +0300569 char name[16];
Tony Lindgren1dbae812005-11-10 14:26:51 +0000570
571 /*
572 * Make sure the serial ports are muxed on at this point.
573 * You have to mux them off in device drivers later on
574 * if not needed.
575 */
576
Jouni Hogander6e811762008-10-06 15:49:15 +0300577 info = omap_get_config(OMAP_TAG_UART, struct omap_uart_config);
Tony Lindgren1dbae812005-11-10 14:26:51 +0000578
579 if (info == NULL)
580 return;
581
582 for (i = 0; i < OMAP_MAX_NR_PORTS; i++) {
Kevin Hilman4af40162009-02-04 10:51:40 -0800583 struct omap_uart_state *uart = &omap_uart[i];
Kevin Hilmanfd455ea2009-04-27 12:27:36 -0700584 struct platform_device *pdev = &uart->pdev;
585 struct device *dev = &pdev->dev;
586 struct plat_serial8250_port *p = dev->platform_data;
Tony Lindgren1dbae812005-11-10 14:26:51 +0000587
588 if (!(info->enabled_uarts & (1 << i))) {
Russell Kingc0fc18c2008-09-05 15:10:27 +0100589 p->membase = NULL;
Tony Lindgren1dbae812005-11-10 14:26:51 +0000590 p->mapbase = 0;
591 continue;
592 }
593
Jouni Hogander6e811762008-10-06 15:49:15 +0300594 sprintf(name, "uart%d_ick", i+1);
Kevin Hilman4af40162009-02-04 10:51:40 -0800595 uart->ick = clk_get(NULL, name);
596 if (IS_ERR(uart->ick)) {
Jouni Hogander6e811762008-10-06 15:49:15 +0300597 printk(KERN_ERR "Could not get uart%d_ick\n", i+1);
Kevin Hilman4af40162009-02-04 10:51:40 -0800598 uart->ick = NULL;
599 }
Tony Lindgren1dbae812005-11-10 14:26:51 +0000600
Jouni Hogander6e811762008-10-06 15:49:15 +0300601 sprintf(name, "uart%d_fck", i+1);
Kevin Hilman4af40162009-02-04 10:51:40 -0800602 uart->fck = clk_get(NULL, name);
603 if (IS_ERR(uart->fck)) {
Jouni Hogander6e811762008-10-06 15:49:15 +0300604 printk(KERN_ERR "Could not get uart%d_fck\n", i+1);
Kevin Hilman4af40162009-02-04 10:51:40 -0800605 uart->fck = NULL;
606 }
Tony Lindgren1dbae812005-11-10 14:26:51 +0000607
Kevin Hilman4af40162009-02-04 10:51:40 -0800608 if (!uart->ick || !uart->fck)
609 continue;
610
611 uart->num = i;
612 p->private_data = uart;
613 uart->p = p;
Kevin Hilmanbcf396c2009-06-30 21:02:45 -0700614 list_add_tail(&uart->node, &uart_list);
Kevin Hilman4af40162009-02-04 10:51:40 -0800615
Kevin Hilman47899982009-06-24 10:32:03 -0700616 if (cpu_is_omap44xx())
617 p->irq += 32;
Kevin Hilman4af40162009-02-04 10:51:40 -0800618
619 omap_uart_enable_clocks(uart);
620 omap_uart_reset(uart);
621 omap_uart_idle_init(uart);
Kevin Hilmanfd455ea2009-04-27 12:27:36 -0700622
623 if (WARN_ON(platform_device_register(pdev)))
624 continue;
625 if ((cpu_is_omap34xx() && uart->padconf) ||
626 (uart->wk_en && uart->wk_mask)) {
627 device_init_wakeup(dev, true);
628 DEV_CREATE_FILE(dev, &dev_attr_sleep_timeout);
629 }
Tony Lindgren1dbae812005-11-10 14:26:51 +0000630 }
Tony Lindgren1dbae812005-11-10 14:26:51 +0000631}