serial.c 17 KB

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