serial.c 18 KB

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