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