serial.c 17 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728
  1. /*
  2. * arch/arm/mach-omap2/serial.c
  3. *
  4. * OMAP2 serial support.
  5. *
  6. * Copyright (C) 2005-2008 Nokia Corporation
  7. * Author: Paul Mundt <paul.mundt@nokia.com>
  8. *
  9. * Major rework for PM support by Kevin Hilman
  10. *
  11. * Based off of arch/arm/mach-omap/omap1/serial.c
  12. *
  13. * Copyright (C) 2009 Texas Instruments
  14. * Added OMAP4 support - Santosh Shilimkar <santosh.shilimkar@ti.com
  15. *
  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>
  22. #include <linux/serial_8250.h>
  23. #include <linux/serial_reg.h>
  24. #include <linux/clk.h>
  25. #include <linux/io.h>
  26. #include <plat/common.h>
  27. #include <plat/board.h>
  28. #include <plat/clock.h>
  29. #include <plat/control.h>
  30. #include "prm.h"
  31. #include "pm.h"
  32. #include "prm-regbits-34xx.h"
  33. #define UART_OMAP_NO_EMPTY_FIFO_READ_IP_REV 0x52
  34. #define UART_OMAP_WER 0x17 /* Wake-up enable register */
  35. #define DEFAULT_TIMEOUT (5 * HZ)
  36. struct omap_uart_state {
  37. int num;
  38. int can_sleep;
  39. struct timer_list timer;
  40. u32 timeout;
  41. void __iomem *wk_st;
  42. void __iomem *wk_en;
  43. u32 wk_mask;
  44. u32 padconf;
  45. struct clk *ick;
  46. struct clk *fck;
  47. int clocked;
  48. struct plat_serial8250_port *p;
  49. struct list_head node;
  50. struct platform_device pdev;
  51. #if defined(CONFIG_ARCH_OMAP3) && defined(CONFIG_PM)
  52. int context_valid;
  53. /* Registers to be saved/restored for OFF-mode */
  54. u16 dll;
  55. u16 dlh;
  56. u16 ier;
  57. u16 sysc;
  58. u16 scr;
  59. u16 wer;
  60. #endif
  61. };
  62. static LIST_HEAD(uart_list);
  63. static struct plat_serial8250_port serial_platform_data0[] = {
  64. {
  65. .irq = 72,
  66. .flags = UPF_BOOT_AUTOCONF,
  67. .iotype = UPIO_MEM,
  68. .regshift = 2,
  69. .uartclk = OMAP24XX_BASE_BAUD * 16,
  70. }, {
  71. .flags = 0
  72. }
  73. };
  74. static struct plat_serial8250_port serial_platform_data1[] = {
  75. {
  76. .irq = 73,
  77. .flags = UPF_BOOT_AUTOCONF,
  78. .iotype = UPIO_MEM,
  79. .regshift = 2,
  80. .uartclk = OMAP24XX_BASE_BAUD * 16,
  81. }, {
  82. .flags = 0
  83. }
  84. };
  85. static struct plat_serial8250_port serial_platform_data2[] = {
  86. {
  87. .irq = 74,
  88. .flags = UPF_BOOT_AUTOCONF,
  89. .iotype = UPIO_MEM,
  90. .regshift = 2,
  91. .uartclk = OMAP24XX_BASE_BAUD * 16,
  92. }, {
  93. .flags = 0
  94. }
  95. };
  96. #ifdef CONFIG_ARCH_OMAP4
  97. static struct plat_serial8250_port serial_platform_data3[] = {
  98. {
  99. .irq = 70,
  100. .flags = UPF_BOOT_AUTOCONF,
  101. .iotype = UPIO_MEM,
  102. .regshift = 2,
  103. .uartclk = OMAP24XX_BASE_BAUD * 16,
  104. }, {
  105. .flags = 0
  106. }
  107. };
  108. #endif
  109. void __init omap2_set_globals_uart(struct omap_globals *omap2_globals)
  110. {
  111. serial_platform_data0[0].mapbase = omap2_globals->uart1_phys;
  112. serial_platform_data1[0].mapbase = omap2_globals->uart2_phys;
  113. serial_platform_data2[0].mapbase = omap2_globals->uart3_phys;
  114. #ifdef CONFIG_ARCH_OMAP4
  115. serial_platform_data3[0].mapbase = omap2_globals->uart4_phys;
  116. #endif
  117. }
  118. static inline unsigned int __serial_read_reg(struct uart_port *up,
  119. int offset)
  120. {
  121. offset <<= up->regshift;
  122. return (unsigned int)__raw_readb(up->membase + offset);
  123. }
  124. static inline unsigned int serial_read_reg(struct plat_serial8250_port *up,
  125. int offset)
  126. {
  127. offset <<= up->regshift;
  128. return (unsigned int)__raw_readb(up->membase + offset);
  129. }
  130. static inline void serial_write_reg(struct plat_serial8250_port *p, int offset,
  131. int value)
  132. {
  133. offset <<= p->regshift;
  134. __raw_writeb(value, p->membase + offset);
  135. }
  136. /*
  137. * Internal UARTs need to be initialized for the 8250 autoconfig to work
  138. * properly. Note that the TX watermark initialization may not be needed
  139. * once the 8250.c watermark handling code is merged.
  140. */
  141. static inline void __init omap_uart_reset(struct omap_uart_state *uart)
  142. {
  143. struct plat_serial8250_port *p = uart->p;
  144. serial_write_reg(p, UART_OMAP_MDR1, 0x07);
  145. serial_write_reg(p, UART_OMAP_SCR, 0x08);
  146. serial_write_reg(p, UART_OMAP_MDR1, 0x00);
  147. serial_write_reg(p, UART_OMAP_SYSC, (0x02 << 3) | (1 << 2) | (1 << 0));
  148. }
  149. #if defined(CONFIG_PM) && defined(CONFIG_ARCH_OMAP3)
  150. static void omap_uart_save_context(struct omap_uart_state *uart)
  151. {
  152. u16 lcr = 0;
  153. struct plat_serial8250_port *p = uart->p;
  154. if (!enable_off_mode)
  155. return;
  156. lcr = serial_read_reg(p, UART_LCR);
  157. serial_write_reg(p, UART_LCR, 0xBF);
  158. uart->dll = serial_read_reg(p, UART_DLL);
  159. uart->dlh = serial_read_reg(p, UART_DLM);
  160. serial_write_reg(p, UART_LCR, lcr);
  161. uart->ier = serial_read_reg(p, UART_IER);
  162. uart->sysc = serial_read_reg(p, UART_OMAP_SYSC);
  163. uart->scr = serial_read_reg(p, UART_OMAP_SCR);
  164. uart->wer = serial_read_reg(p, UART_OMAP_WER);
  165. uart->context_valid = 1;
  166. }
  167. static void omap_uart_restore_context(struct omap_uart_state *uart)
  168. {
  169. u16 efr = 0;
  170. struct plat_serial8250_port *p = uart->p;
  171. if (!enable_off_mode)
  172. return;
  173. if (!uart->context_valid)
  174. return;
  175. uart->context_valid = 0;
  176. serial_write_reg(p, UART_OMAP_MDR1, 0x7);
  177. serial_write_reg(p, UART_LCR, 0xBF); /* Config B mode */
  178. efr = serial_read_reg(p, UART_EFR);
  179. serial_write_reg(p, UART_EFR, UART_EFR_ECB);
  180. serial_write_reg(p, UART_LCR, 0x0); /* Operational mode */
  181. serial_write_reg(p, UART_IER, 0x0);
  182. serial_write_reg(p, UART_LCR, 0xBF); /* Config B mode */
  183. serial_write_reg(p, UART_DLL, uart->dll);
  184. serial_write_reg(p, UART_DLM, uart->dlh);
  185. serial_write_reg(p, UART_LCR, 0x0); /* Operational mode */
  186. serial_write_reg(p, UART_IER, uart->ier);
  187. serial_write_reg(p, UART_FCR, 0xA1);
  188. serial_write_reg(p, UART_LCR, 0xBF); /* Config B mode */
  189. serial_write_reg(p, UART_EFR, efr);
  190. serial_write_reg(p, UART_LCR, UART_LCR_WLEN8);
  191. serial_write_reg(p, UART_OMAP_SCR, uart->scr);
  192. serial_write_reg(p, UART_OMAP_WER, uart->wer);
  193. serial_write_reg(p, UART_OMAP_SYSC, uart->sysc);
  194. serial_write_reg(p, UART_OMAP_MDR1, 0x00); /* UART 16x mode */
  195. }
  196. #else
  197. static inline void omap_uart_save_context(struct omap_uart_state *uart) {}
  198. static inline void omap_uart_restore_context(struct omap_uart_state *uart) {}
  199. #endif /* CONFIG_PM && CONFIG_ARCH_OMAP3 */
  200. static inline void omap_uart_enable_clocks(struct omap_uart_state *uart)
  201. {
  202. if (uart->clocked)
  203. return;
  204. clk_enable(uart->ick);
  205. clk_enable(uart->fck);
  206. uart->clocked = 1;
  207. omap_uart_restore_context(uart);
  208. }
  209. #ifdef CONFIG_PM
  210. static inline void omap_uart_disable_clocks(struct omap_uart_state *uart)
  211. {
  212. if (!uart->clocked)
  213. return;
  214. omap_uart_save_context(uart);
  215. uart->clocked = 0;
  216. clk_disable(uart->ick);
  217. clk_disable(uart->fck);
  218. }
  219. static void omap_uart_enable_wakeup(struct omap_uart_state *uart)
  220. {
  221. /* Set wake-enable bit */
  222. if (uart->wk_en && uart->wk_mask) {
  223. u32 v = __raw_readl(uart->wk_en);
  224. v |= uart->wk_mask;
  225. __raw_writel(v, uart->wk_en);
  226. }
  227. /* Ensure IOPAD wake-enables are set */
  228. if (cpu_is_omap34xx() && uart->padconf) {
  229. u16 v = omap_ctrl_readw(uart->padconf);
  230. v |= OMAP3_PADCONF_WAKEUPENABLE0;
  231. omap_ctrl_writew(v, uart->padconf);
  232. }
  233. }
  234. static void omap_uart_disable_wakeup(struct omap_uart_state *uart)
  235. {
  236. /* Clear wake-enable bit */
  237. if (uart->wk_en && uart->wk_mask) {
  238. u32 v = __raw_readl(uart->wk_en);
  239. v &= ~uart->wk_mask;
  240. __raw_writel(v, uart->wk_en);
  241. }
  242. /* Ensure IOPAD wake-enables are cleared */
  243. if (cpu_is_omap34xx() && uart->padconf) {
  244. u16 v = omap_ctrl_readw(uart->padconf);
  245. v &= ~OMAP3_PADCONF_WAKEUPENABLE0;
  246. omap_ctrl_writew(v, uart->padconf);
  247. }
  248. }
  249. static void omap_uart_smart_idle_enable(struct omap_uart_state *uart,
  250. int enable)
  251. {
  252. struct plat_serial8250_port *p = uart->p;
  253. u16 sysc;
  254. sysc = serial_read_reg(p, UART_OMAP_SYSC) & 0x7;
  255. if (enable)
  256. sysc |= 0x2 << 3;
  257. else
  258. sysc |= 0x1 << 3;
  259. serial_write_reg(p, UART_OMAP_SYSC, sysc);
  260. }
  261. static void omap_uart_block_sleep(struct omap_uart_state *uart)
  262. {
  263. omap_uart_enable_clocks(uart);
  264. omap_uart_smart_idle_enable(uart, 0);
  265. uart->can_sleep = 0;
  266. if (uart->timeout)
  267. mod_timer(&uart->timer, jiffies + uart->timeout);
  268. else
  269. del_timer(&uart->timer);
  270. }
  271. static void omap_uart_allow_sleep(struct omap_uart_state *uart)
  272. {
  273. if (device_may_wakeup(&uart->pdev.dev))
  274. omap_uart_enable_wakeup(uart);
  275. else
  276. omap_uart_disable_wakeup(uart);
  277. if (!uart->clocked)
  278. return;
  279. omap_uart_smart_idle_enable(uart, 1);
  280. uart->can_sleep = 1;
  281. del_timer(&uart->timer);
  282. }
  283. static void omap_uart_idle_timer(unsigned long data)
  284. {
  285. struct omap_uart_state *uart = (struct omap_uart_state *)data;
  286. omap_uart_allow_sleep(uart);
  287. }
  288. void omap_uart_prepare_idle(int num)
  289. {
  290. struct omap_uart_state *uart;
  291. list_for_each_entry(uart, &uart_list, node) {
  292. if (num == uart->num && uart->can_sleep) {
  293. omap_uart_disable_clocks(uart);
  294. return;
  295. }
  296. }
  297. }
  298. void omap_uart_resume_idle(int num)
  299. {
  300. struct omap_uart_state *uart;
  301. list_for_each_entry(uart, &uart_list, node) {
  302. if (num == uart->num) {
  303. omap_uart_enable_clocks(uart);
  304. /* Check for IO pad wakeup */
  305. if (cpu_is_omap34xx() && uart->padconf) {
  306. u16 p = omap_ctrl_readw(uart->padconf);
  307. if (p & OMAP3_PADCONF_WAKEUPEVENT0)
  308. omap_uart_block_sleep(uart);
  309. }
  310. /* Check for normal UART wakeup */
  311. if (__raw_readl(uart->wk_st) & uart->wk_mask)
  312. omap_uart_block_sleep(uart);
  313. return;
  314. }
  315. }
  316. }
  317. void omap_uart_prepare_suspend(void)
  318. {
  319. struct omap_uart_state *uart;
  320. list_for_each_entry(uart, &uart_list, node) {
  321. omap_uart_allow_sleep(uart);
  322. }
  323. }
  324. int omap_uart_can_sleep(void)
  325. {
  326. struct omap_uart_state *uart;
  327. int can_sleep = 1;
  328. list_for_each_entry(uart, &uart_list, node) {
  329. if (!uart->clocked)
  330. continue;
  331. if (!uart->can_sleep) {
  332. can_sleep = 0;
  333. continue;
  334. }
  335. /* This UART can now safely sleep. */
  336. omap_uart_allow_sleep(uart);
  337. }
  338. return can_sleep;
  339. }
  340. /**
  341. * omap_uart_interrupt()
  342. *
  343. * This handler is used only to detect that *any* UART interrupt has
  344. * occurred. It does _nothing_ to handle the interrupt. Rather,
  345. * any UART interrupt will trigger the inactivity timer so the
  346. * UART will not idle or sleep for its timeout period.
  347. *
  348. **/
  349. static irqreturn_t omap_uart_interrupt(int irq, void *dev_id)
  350. {
  351. struct omap_uart_state *uart = dev_id;
  352. omap_uart_block_sleep(uart);
  353. return IRQ_NONE;
  354. }
  355. static void omap_uart_idle_init(struct omap_uart_state *uart)
  356. {
  357. struct plat_serial8250_port *p = uart->p;
  358. int ret;
  359. uart->can_sleep = 0;
  360. uart->timeout = DEFAULT_TIMEOUT;
  361. setup_timer(&uart->timer, omap_uart_idle_timer,
  362. (unsigned long) uart);
  363. mod_timer(&uart->timer, jiffies + uart->timeout);
  364. omap_uart_smart_idle_enable(uart, 0);
  365. if (cpu_is_omap34xx()) {
  366. u32 mod = (uart->num == 2) ? OMAP3430_PER_MOD : CORE_MOD;
  367. u32 wk_mask = 0;
  368. u32 padconf = 0;
  369. uart->wk_en = OMAP34XX_PRM_REGADDR(mod, PM_WKEN1);
  370. uart->wk_st = OMAP34XX_PRM_REGADDR(mod, PM_WKST1);
  371. switch (uart->num) {
  372. case 0:
  373. wk_mask = OMAP3430_ST_UART1_MASK;
  374. padconf = 0x182;
  375. break;
  376. case 1:
  377. wk_mask = OMAP3430_ST_UART2_MASK;
  378. padconf = 0x17a;
  379. break;
  380. case 2:
  381. wk_mask = OMAP3430_ST_UART3_MASK;
  382. padconf = 0x19e;
  383. break;
  384. }
  385. uart->wk_mask = wk_mask;
  386. uart->padconf = padconf;
  387. } else if (cpu_is_omap24xx()) {
  388. u32 wk_mask = 0;
  389. if (cpu_is_omap2430()) {
  390. uart->wk_en = OMAP2430_PRM_REGADDR(CORE_MOD, PM_WKEN1);
  391. uart->wk_st = OMAP2430_PRM_REGADDR(CORE_MOD, PM_WKST1);
  392. } else if (cpu_is_omap2420()) {
  393. uart->wk_en = OMAP2420_PRM_REGADDR(CORE_MOD, PM_WKEN1);
  394. uart->wk_st = OMAP2420_PRM_REGADDR(CORE_MOD, PM_WKST1);
  395. }
  396. switch (uart->num) {
  397. case 0:
  398. wk_mask = OMAP24XX_ST_UART1_MASK;
  399. break;
  400. case 1:
  401. wk_mask = OMAP24XX_ST_UART2_MASK;
  402. break;
  403. case 2:
  404. wk_mask = OMAP24XX_ST_UART3_MASK;
  405. break;
  406. }
  407. uart->wk_mask = wk_mask;
  408. } else {
  409. uart->wk_en = 0;
  410. uart->wk_st = 0;
  411. uart->wk_mask = 0;
  412. uart->padconf = 0;
  413. }
  414. p->irqflags |= IRQF_SHARED;
  415. ret = request_irq(p->irq, omap_uart_interrupt, IRQF_SHARED,
  416. "serial idle", (void *)uart);
  417. WARN_ON(ret);
  418. }
  419. void omap_uart_enable_irqs(int enable)
  420. {
  421. int ret;
  422. struct omap_uart_state *uart;
  423. list_for_each_entry(uart, &uart_list, node) {
  424. if (enable)
  425. ret = request_irq(uart->p->irq, omap_uart_interrupt,
  426. IRQF_SHARED, "serial idle", (void *)uart);
  427. else
  428. free_irq(uart->p->irq, (void *)uart);
  429. }
  430. }
  431. static ssize_t sleep_timeout_show(struct device *dev,
  432. struct device_attribute *attr,
  433. char *buf)
  434. {
  435. struct platform_device *pdev = container_of(dev,
  436. struct platform_device, dev);
  437. struct omap_uart_state *uart = container_of(pdev,
  438. struct omap_uart_state, pdev);
  439. return sprintf(buf, "%u\n", uart->timeout / HZ);
  440. }
  441. static ssize_t sleep_timeout_store(struct device *dev,
  442. struct device_attribute *attr,
  443. const char *buf, size_t n)
  444. {
  445. struct platform_device *pdev = container_of(dev,
  446. struct platform_device, dev);
  447. struct omap_uart_state *uart = container_of(pdev,
  448. struct omap_uart_state, pdev);
  449. unsigned int value;
  450. if (sscanf(buf, "%u", &value) != 1) {
  451. printk(KERN_ERR "sleep_timeout_store: Invalid value\n");
  452. return -EINVAL;
  453. }
  454. uart->timeout = value * HZ;
  455. if (uart->timeout)
  456. mod_timer(&uart->timer, jiffies + uart->timeout);
  457. else
  458. /* A zero value means disable timeout feature */
  459. omap_uart_block_sleep(uart);
  460. return n;
  461. }
  462. DEVICE_ATTR(sleep_timeout, 0644, sleep_timeout_show, sleep_timeout_store);
  463. #define DEV_CREATE_FILE(dev, attr) WARN_ON(device_create_file(dev, attr))
  464. #else
  465. static inline void omap_uart_idle_init(struct omap_uart_state *uart) {}
  466. #define DEV_CREATE_FILE(dev, attr)
  467. #endif /* CONFIG_PM */
  468. static struct omap_uart_state omap_uart[] = {
  469. {
  470. .pdev = {
  471. .name = "serial8250",
  472. .id = PLAT8250_DEV_PLATFORM,
  473. .dev = {
  474. .platform_data = serial_platform_data0,
  475. },
  476. },
  477. }, {
  478. .pdev = {
  479. .name = "serial8250",
  480. .id = PLAT8250_DEV_PLATFORM1,
  481. .dev = {
  482. .platform_data = serial_platform_data1,
  483. },
  484. },
  485. }, {
  486. .pdev = {
  487. .name = "serial8250",
  488. .id = PLAT8250_DEV_PLATFORM2,
  489. .dev = {
  490. .platform_data = serial_platform_data2,
  491. },
  492. },
  493. },
  494. #ifdef CONFIG_ARCH_OMAP4
  495. {
  496. .pdev = {
  497. .name = "serial8250",
  498. .id = 3,
  499. .dev = {
  500. .platform_data = serial_platform_data3,
  501. },
  502. },
  503. },
  504. #endif
  505. };
  506. /*
  507. * Override the default 8250 read handler: mem_serial_in()
  508. * Empty RX fifo read causes an abort on omap3630 and omap4
  509. * This function makes sure that an empty rx fifo is not read on these silicons
  510. * (OMAP1/2/3430 are not affected)
  511. */
  512. static unsigned int serial_in_override(struct uart_port *up, int offset)
  513. {
  514. if (UART_RX == offset) {
  515. unsigned int lsr;
  516. lsr = __serial_read_reg(up, UART_LSR);
  517. if (!(lsr & UART_LSR_DR))
  518. return -EPERM;
  519. }
  520. return __serial_read_reg(up, offset);
  521. }
  522. void __init omap_serial_early_init(void)
  523. {
  524. int i;
  525. char name[16];
  526. /*
  527. * Make sure the serial ports are muxed on at this point.
  528. * You have to mux them off in device drivers later on
  529. * if not needed.
  530. */
  531. for (i = 0; i < ARRAY_SIZE(omap_uart); i++) {
  532. struct omap_uart_state *uart = &omap_uart[i];
  533. struct platform_device *pdev = &uart->pdev;
  534. struct device *dev = &pdev->dev;
  535. struct plat_serial8250_port *p = dev->platform_data;
  536. /*
  537. * Module 4KB + L4 interconnect 4KB
  538. * Static mapping, never released
  539. */
  540. p->membase = ioremap(p->mapbase, SZ_8K);
  541. if (!p->membase) {
  542. printk(KERN_ERR "ioremap failed for uart%i\n", i + 1);
  543. continue;
  544. }
  545. sprintf(name, "uart%d_ick", i+1);
  546. uart->ick = clk_get(NULL, name);
  547. if (IS_ERR(uart->ick)) {
  548. printk(KERN_ERR "Could not get uart%d_ick\n", i+1);
  549. uart->ick = NULL;
  550. }
  551. sprintf(name, "uart%d_fck", i+1);
  552. uart->fck = clk_get(NULL, name);
  553. if (IS_ERR(uart->fck)) {
  554. printk(KERN_ERR "Could not get uart%d_fck\n", i+1);
  555. uart->fck = NULL;
  556. }
  557. /* FIXME: Remove this once the clkdev is ready */
  558. if (!cpu_is_omap44xx()) {
  559. if (!uart->ick || !uart->fck)
  560. continue;
  561. }
  562. uart->num = i;
  563. p->private_data = uart;
  564. uart->p = p;
  565. if (cpu_is_omap44xx())
  566. p->irq += 32;
  567. }
  568. }
  569. /**
  570. * omap_serial_init_port() - initialize single serial port
  571. * @port: serial port number (0-3)
  572. *
  573. * This function initialies serial driver for given @port only.
  574. * Platforms can call this function instead of omap_serial_init()
  575. * if they don't plan to use all available UARTs as serial ports.
  576. *
  577. * Don't mix calls to omap_serial_init_port() and omap_serial_init(),
  578. * use only one of the two.
  579. */
  580. void __init omap_serial_init_port(int port)
  581. {
  582. struct omap_uart_state *uart;
  583. struct platform_device *pdev;
  584. struct device *dev;
  585. BUG_ON(port < 0);
  586. BUG_ON(port >= ARRAY_SIZE(omap_uart));
  587. uart = &omap_uart[port];
  588. pdev = &uart->pdev;
  589. dev = &pdev->dev;
  590. omap_uart_enable_clocks(uart);
  591. omap_uart_reset(uart);
  592. omap_uart_idle_init(uart);
  593. list_add_tail(&uart->node, &uart_list);
  594. if (WARN_ON(platform_device_register(pdev)))
  595. return;
  596. if ((cpu_is_omap34xx() && uart->padconf) ||
  597. (uart->wk_en && uart->wk_mask)) {
  598. device_init_wakeup(dev, true);
  599. DEV_CREATE_FILE(dev, &dev_attr_sleep_timeout);
  600. }
  601. /* omap44xx: Never read empty UART fifo
  602. * omap3xxx: Never read empty UART fifo on UARTs
  603. * with IP rev >=0x52
  604. */
  605. if (cpu_is_omap44xx())
  606. uart->p->serial_in = serial_in_override;
  607. else if ((serial_read_reg(uart->p, UART_OMAP_MVER) & 0xFF)
  608. >= UART_OMAP_NO_EMPTY_FIFO_READ_IP_REV)
  609. uart->p->serial_in = serial_in_override;
  610. }
  611. /**
  612. * omap_serial_init() - intialize all supported serial ports
  613. *
  614. * Initializes all available UARTs as serial ports. Platforms
  615. * can call this function when they want to have default behaviour
  616. * for serial ports (e.g initialize them all as serial ports).
  617. */
  618. void __init omap_serial_init(void)
  619. {
  620. int i;
  621. for (i = 0; i < ARRAY_SIZE(omap_uart); i++)
  622. omap_serial_init_port(i);
  623. }