serial.c 18 KB

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