serial.c 18 KB

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