serial.c 17 KB

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