omap-serial.c 47 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743
  1. /*
  2. * Driver for OMAP-UART controller.
  3. * Based on drivers/serial/8250.c
  4. *
  5. * Copyright (C) 2010 Texas Instruments.
  6. *
  7. * Authors:
  8. * Govindraj R <govindraj.raja@ti.com>
  9. * Thara Gopinath <thara@ti.com>
  10. *
  11. * This program is free software; you can redistribute it and/or modify
  12. * it under the terms of the GNU General Public License as published by
  13. * the Free Software Foundation; either version 2 of the License, or
  14. * (at your option) any later version.
  15. *
  16. * Note: This driver is made separate from 8250 driver as we cannot
  17. * over load 8250 driver with omap platform specific configuration for
  18. * features like DMA, it makes easier to implement features like DMA and
  19. * hardware flow control and software flow control configuration with
  20. * this driver as required for the omap-platform.
  21. */
  22. #if defined(CONFIG_SERIAL_OMAP_CONSOLE) && defined(CONFIG_MAGIC_SYSRQ)
  23. #define SUPPORT_SYSRQ
  24. #endif
  25. #include <linux/module.h>
  26. #include <linux/init.h>
  27. #include <linux/console.h>
  28. #include <linux/serial_reg.h>
  29. #include <linux/delay.h>
  30. #include <linux/slab.h>
  31. #include <linux/tty.h>
  32. #include <linux/tty_flip.h>
  33. #include <linux/io.h>
  34. #include <linux/dma-mapping.h>
  35. #include <linux/clk.h>
  36. #include <linux/serial_core.h>
  37. #include <linux/irq.h>
  38. #include <linux/pm_runtime.h>
  39. #include <linux/of.h>
  40. #include <plat/dma.h>
  41. #include <plat/dmtimer.h>
  42. #include <plat/omap-serial.h>
  43. #define DEFAULT_CLK_SPEED 48000000 /* 48Mhz*/
  44. /* SCR register bitmasks */
  45. #define OMAP_UART_SCR_RX_TRIG_GRANU1_MASK (1 << 7)
  46. #define OMAP_UART_SCR_TX_TRIG_GRANU1_MASK (1 << 6)
  47. /* FCR register bitmasks */
  48. #define OMAP_UART_FCR_RX_FIFO_TRIG_SHIFT 6
  49. #define OMAP_UART_FCR_RX_FIFO_TRIG_MASK (0x3 << 6)
  50. #define OMAP_UART_FCR_TX_FIFO_TRIG_SHIFT 4
  51. /* TLR register bitmasks */
  52. #define OMAP_UART_TLR_TX_FIFO_TRIG_DMA_SHIFT 0
  53. static struct uart_omap_port *ui[OMAP_MAX_HSUART_PORTS];
  54. /* Forward declaration of functions */
  55. static void uart_tx_dma_callback(int lch, u16 ch_status, void *data);
  56. static void serial_omap_rxdma_poll(unsigned long uart_no);
  57. static int serial_omap_start_rxdma(struct uart_omap_port *up);
  58. static void serial_omap_mdr1_errataset(struct uart_omap_port *up, u8 mdr1);
  59. static struct workqueue_struct *serial_omap_uart_wq;
  60. static inline unsigned int serial_in(struct uart_omap_port *up, int offset)
  61. {
  62. offset <<= up->port.regshift;
  63. return readw(up->port.membase + offset);
  64. }
  65. static inline void serial_out(struct uart_omap_port *up, int offset, int value)
  66. {
  67. offset <<= up->port.regshift;
  68. writew(value, up->port.membase + offset);
  69. }
  70. static inline void serial_omap_clear_fifos(struct uart_omap_port *up)
  71. {
  72. serial_out(up, UART_FCR, UART_FCR_ENABLE_FIFO);
  73. serial_out(up, UART_FCR, UART_FCR_ENABLE_FIFO |
  74. UART_FCR_CLEAR_RCVR | UART_FCR_CLEAR_XMIT);
  75. serial_out(up, UART_FCR, 0);
  76. }
  77. /**
  78. * serial_omap_block_cpu_low_power_state - prevent MPU pwrdm from leaving ON
  79. * @up: struct uart_omap_port *
  80. *
  81. * Prevent the MPU powerdomain from entering a power state lower than
  82. * ON. (It should be sufficient to prevent it from entering INACTIVE,
  83. * but there is presently no easy way to do this.) This works around
  84. * a suspected silicon bug in the OMAP UART IP blocks. The UARTs should
  85. * wake the PRCM when the transmit FIFO threshold interrupt is raised, but
  86. * they do not. See also serial_omap_allow_cpu_low_power_state(). No
  87. * return value.
  88. */
  89. static void serial_omap_block_cpu_low_power_state(struct uart_omap_port *up)
  90. {
  91. #ifdef CONFIG_CPU_IDLE
  92. up->latency = 1;
  93. schedule_work(&up->qos_work);
  94. #else
  95. up->max_tx_count = 1;
  96. #endif
  97. }
  98. /**
  99. * serial_omap_allow_cpu_low_power_state - remove power state restriction on MPU
  100. * @up: struct uart_omap_port *
  101. *
  102. * Cancel the effects of serial_omap_block_cpu_low_power_state().
  103. * This should allow the MPU powerdomain to enter a power state lower
  104. * than ON, assuming the rest of the kernel is not restricting it.
  105. * This works around a suspected silicon bug in the OMAP UART IP
  106. * blocks. The UARTs should wake the PRCM when the transmit FIFO
  107. * threshold interrupt is raised, but they do not. No return value.
  108. */
  109. static void serial_omap_allow_cpu_low_power_state(struct uart_omap_port *up)
  110. {
  111. #ifdef CONFIG_CPU_IDLE
  112. up->latency = up->calc_latency;
  113. schedule_work(&up->qos_work);
  114. #else
  115. up->max_tx_count = up->port.fifosize / 4;
  116. #endif
  117. }
  118. /*
  119. * serial_omap_get_divisor - calculate divisor value
  120. * @port: uart port info
  121. * @baud: baudrate for which divisor needs to be calculated.
  122. *
  123. * We have written our own function to get the divisor so as to support
  124. * 13x mode. 3Mbps Baudrate as an different divisor.
  125. * Reference OMAP TRM Chapter 17:
  126. * Table 17-1. UART Mode Baud Rates, Divisor Values, and Error Rates
  127. * referring to oversampling - divisor value
  128. * baudrate 460,800 to 3,686,400 all have divisor 13
  129. * except 3,000,000 which has divisor value 16
  130. */
  131. static unsigned int
  132. serial_omap_get_divisor(struct uart_port *port, unsigned int baud)
  133. {
  134. unsigned int divisor;
  135. if (baud > OMAP_MODE13X_SPEED && baud != 3000000)
  136. divisor = 13;
  137. else
  138. divisor = 16;
  139. return port->uartclk/(baud * divisor);
  140. }
  141. static void serial_omap_stop_rxdma(struct uart_omap_port *up)
  142. {
  143. if (up->uart_dma.rx_dma_used) {
  144. del_timer(&up->uart_dma.rx_timer);
  145. omap_stop_dma(up->uart_dma.rx_dma_channel);
  146. omap_free_dma(up->uart_dma.rx_dma_channel);
  147. up->uart_dma.rx_dma_channel = OMAP_UART_DMA_CH_FREE;
  148. up->uart_dma.rx_dma_used = false;
  149. pm_runtime_mark_last_busy(&up->pdev->dev);
  150. pm_runtime_put_autosuspend(&up->pdev->dev);
  151. }
  152. }
  153. static void serial_omap_enable_ms(struct uart_port *port)
  154. {
  155. struct uart_omap_port *up = (struct uart_omap_port *)port;
  156. dev_dbg(up->port.dev, "serial_omap_enable_ms+%d\n", up->port.line);
  157. pm_runtime_get_sync(&up->pdev->dev);
  158. up->ier |= UART_IER_MSI;
  159. serial_out(up, UART_IER, up->ier);
  160. pm_runtime_put(&up->pdev->dev);
  161. }
  162. static void serial_omap_stop_tx(struct uart_port *port)
  163. {
  164. struct uart_omap_port *up = (struct uart_omap_port *)port;
  165. if (up->use_dma &&
  166. up->uart_dma.tx_dma_channel != OMAP_UART_DMA_CH_FREE) {
  167. /*
  168. * Check if dma is still active. If yes do nothing,
  169. * return. Else stop dma
  170. */
  171. if (omap_get_dma_active_status(up->uart_dma.tx_dma_channel))
  172. return;
  173. omap_stop_dma(up->uart_dma.tx_dma_channel);
  174. omap_free_dma(up->uart_dma.tx_dma_channel);
  175. up->uart_dma.tx_dma_channel = OMAP_UART_DMA_CH_FREE;
  176. pm_runtime_mark_last_busy(&up->pdev->dev);
  177. pm_runtime_put_autosuspend(&up->pdev->dev);
  178. }
  179. pm_runtime_get_sync(&up->pdev->dev);
  180. if (up->ier & UART_IER_THRI) {
  181. up->ier &= ~UART_IER_THRI;
  182. serial_out(up, UART_IER, up->ier);
  183. }
  184. if (!up->use_dma)
  185. serial_omap_allow_cpu_low_power_state(up);
  186. pm_runtime_mark_last_busy(&up->pdev->dev);
  187. pm_runtime_put_autosuspend(&up->pdev->dev);
  188. }
  189. static void serial_omap_stop_rx(struct uart_port *port)
  190. {
  191. struct uart_omap_port *up = (struct uart_omap_port *)port;
  192. pm_runtime_get_sync(&up->pdev->dev);
  193. if (up->use_dma)
  194. serial_omap_stop_rxdma(up);
  195. up->ier &= ~UART_IER_RLSI;
  196. up->port.read_status_mask &= ~UART_LSR_DR;
  197. serial_out(up, UART_IER, up->ier);
  198. pm_runtime_mark_last_busy(&up->pdev->dev);
  199. pm_runtime_put_autosuspend(&up->pdev->dev);
  200. }
  201. static inline void receive_chars(struct uart_omap_port *up,
  202. unsigned int *status)
  203. {
  204. struct tty_struct *tty = up->port.state->port.tty;
  205. unsigned int flag, lsr = *status;
  206. unsigned char ch = 0;
  207. int max_count = 256;
  208. do {
  209. if (likely(lsr & UART_LSR_DR))
  210. ch = serial_in(up, UART_RX);
  211. flag = TTY_NORMAL;
  212. up->port.icount.rx++;
  213. if (unlikely(lsr & UART_LSR_BRK_ERROR_BITS)) {
  214. /*
  215. * For statistics only
  216. */
  217. if (lsr & UART_LSR_BI) {
  218. lsr &= ~(UART_LSR_FE | UART_LSR_PE);
  219. up->port.icount.brk++;
  220. /*
  221. * We do the SysRQ and SAK checking
  222. * here because otherwise the break
  223. * may get masked by ignore_status_mask
  224. * or read_status_mask.
  225. */
  226. if (uart_handle_break(&up->port))
  227. goto ignore_char;
  228. } else if (lsr & UART_LSR_PE) {
  229. up->port.icount.parity++;
  230. } else if (lsr & UART_LSR_FE) {
  231. up->port.icount.frame++;
  232. }
  233. if (lsr & UART_LSR_OE)
  234. up->port.icount.overrun++;
  235. /*
  236. * Mask off conditions which should be ignored.
  237. */
  238. lsr &= up->port.read_status_mask;
  239. #ifdef CONFIG_SERIAL_OMAP_CONSOLE
  240. if (up->port.line == up->port.cons->index) {
  241. /* Recover the break flag from console xmit */
  242. lsr |= up->lsr_break_flag;
  243. }
  244. #endif
  245. if (lsr & UART_LSR_BI)
  246. flag = TTY_BREAK;
  247. else if (lsr & UART_LSR_PE)
  248. flag = TTY_PARITY;
  249. else if (lsr & UART_LSR_FE)
  250. flag = TTY_FRAME;
  251. }
  252. if (uart_handle_sysrq_char(&up->port, ch))
  253. goto ignore_char;
  254. uart_insert_char(&up->port, lsr, UART_LSR_OE, ch, flag);
  255. ignore_char:
  256. lsr = serial_in(up, UART_LSR);
  257. } while ((lsr & (UART_LSR_DR | UART_LSR_BI)) && (max_count-- > 0));
  258. spin_unlock(&up->port.lock);
  259. tty_flip_buffer_push(tty);
  260. spin_lock(&up->port.lock);
  261. }
  262. static void transmit_chars(struct uart_omap_port *up)
  263. {
  264. struct circ_buf *xmit = &up->port.state->xmit;
  265. int count;
  266. if (up->port.x_char) {
  267. serial_out(up, UART_TX, up->port.x_char);
  268. up->port.icount.tx++;
  269. up->port.x_char = 0;
  270. return;
  271. }
  272. if (uart_circ_empty(xmit) || uart_tx_stopped(&up->port)) {
  273. serial_omap_stop_tx(&up->port);
  274. return;
  275. }
  276. count = up->max_tx_count;
  277. do {
  278. serial_out(up, UART_TX, xmit->buf[xmit->tail]);
  279. xmit->tail = (xmit->tail + 1) & (UART_XMIT_SIZE - 1);
  280. up->port.icount.tx++;
  281. if (uart_circ_empty(xmit))
  282. break;
  283. } while (--count > 0);
  284. if (uart_circ_chars_pending(xmit) < WAKEUP_CHARS)
  285. uart_write_wakeup(&up->port);
  286. if (uart_circ_empty(xmit))
  287. serial_omap_stop_tx(&up->port);
  288. }
  289. static inline void serial_omap_enable_ier_thri(struct uart_omap_port *up)
  290. {
  291. if (!(up->ier & UART_IER_THRI)) {
  292. up->ier |= UART_IER_THRI;
  293. serial_out(up, UART_IER, up->ier);
  294. }
  295. }
  296. static void serial_omap_start_tx(struct uart_port *port)
  297. {
  298. struct uart_omap_port *up = (struct uart_omap_port *)port;
  299. struct circ_buf *xmit;
  300. unsigned int start;
  301. int ret = 0;
  302. if (!up->use_dma) {
  303. pm_runtime_get_sync(&up->pdev->dev);
  304. serial_omap_block_cpu_low_power_state(up);
  305. serial_omap_enable_ier_thri(up);
  306. pm_runtime_mark_last_busy(&up->pdev->dev);
  307. pm_runtime_put_autosuspend(&up->pdev->dev);
  308. return;
  309. }
  310. if (up->uart_dma.tx_dma_used)
  311. return;
  312. xmit = &up->port.state->xmit;
  313. if (up->uart_dma.tx_dma_channel == OMAP_UART_DMA_CH_FREE) {
  314. pm_runtime_get_sync(&up->pdev->dev);
  315. ret = omap_request_dma(up->uart_dma.uart_dma_tx,
  316. "UART Tx DMA",
  317. (void *)uart_tx_dma_callback, up,
  318. &(up->uart_dma.tx_dma_channel));
  319. if (ret < 0) {
  320. serial_omap_enable_ier_thri(up);
  321. return;
  322. }
  323. }
  324. spin_lock(&(up->uart_dma.tx_lock));
  325. up->uart_dma.tx_dma_used = true;
  326. spin_unlock(&(up->uart_dma.tx_lock));
  327. start = up->uart_dma.tx_buf_dma_phys +
  328. (xmit->tail & (UART_XMIT_SIZE - 1));
  329. up->uart_dma.tx_buf_size = uart_circ_chars_pending(xmit);
  330. /*
  331. * It is a circular buffer. See if the buffer has wounded back.
  332. * If yes it will have to be transferred in two separate dma
  333. * transfers
  334. */
  335. if (start + up->uart_dma.tx_buf_size >=
  336. up->uart_dma.tx_buf_dma_phys + UART_XMIT_SIZE)
  337. up->uart_dma.tx_buf_size =
  338. (up->uart_dma.tx_buf_dma_phys +
  339. UART_XMIT_SIZE) - start;
  340. omap_set_dma_dest_params(up->uart_dma.tx_dma_channel, 0,
  341. OMAP_DMA_AMODE_CONSTANT,
  342. up->uart_dma.uart_base, 0, 0);
  343. omap_set_dma_src_params(up->uart_dma.tx_dma_channel, 0,
  344. OMAP_DMA_AMODE_POST_INC, start, 0, 0);
  345. omap_set_dma_transfer_params(up->uart_dma.tx_dma_channel,
  346. OMAP_DMA_DATA_TYPE_S8,
  347. up->uart_dma.tx_buf_size, 1,
  348. OMAP_DMA_SYNC_ELEMENT,
  349. up->uart_dma.uart_dma_tx, 0);
  350. /* FIXME: Cache maintenance needed here? */
  351. omap_start_dma(up->uart_dma.tx_dma_channel);
  352. }
  353. static unsigned int check_modem_status(struct uart_omap_port *up)
  354. {
  355. unsigned int status;
  356. status = serial_in(up, UART_MSR);
  357. status |= up->msr_saved_flags;
  358. up->msr_saved_flags = 0;
  359. if ((status & UART_MSR_ANY_DELTA) == 0)
  360. return status;
  361. if (status & UART_MSR_ANY_DELTA && up->ier & UART_IER_MSI &&
  362. up->port.state != NULL) {
  363. if (status & UART_MSR_TERI)
  364. up->port.icount.rng++;
  365. if (status & UART_MSR_DDSR)
  366. up->port.icount.dsr++;
  367. if (status & UART_MSR_DDCD)
  368. uart_handle_dcd_change
  369. (&up->port, status & UART_MSR_DCD);
  370. if (status & UART_MSR_DCTS)
  371. uart_handle_cts_change
  372. (&up->port, status & UART_MSR_CTS);
  373. wake_up_interruptible(&up->port.state->port.delta_msr_wait);
  374. }
  375. return status;
  376. }
  377. /**
  378. * serial_omap_irq() - This handles the interrupt from one port
  379. * @irq: uart port irq number
  380. * @dev_id: uart port info
  381. */
  382. static inline irqreturn_t serial_omap_irq(int irq, void *dev_id)
  383. {
  384. struct uart_omap_port *up = dev_id;
  385. unsigned int iir, lsr;
  386. unsigned long flags;
  387. pm_runtime_get_sync(&up->pdev->dev);
  388. iir = serial_in(up, UART_IIR);
  389. if (iir & UART_IIR_NO_INT) {
  390. pm_runtime_mark_last_busy(&up->pdev->dev);
  391. pm_runtime_put_autosuspend(&up->pdev->dev);
  392. return IRQ_NONE;
  393. }
  394. spin_lock_irqsave(&up->port.lock, flags);
  395. lsr = serial_in(up, UART_LSR);
  396. if (iir & UART_IIR_RLSI) {
  397. if (!up->use_dma) {
  398. if (lsr & UART_LSR_DR)
  399. receive_chars(up, &lsr);
  400. } else {
  401. up->ier &= ~(UART_IER_RDI | UART_IER_RLSI);
  402. serial_out(up, UART_IER, up->ier);
  403. if ((serial_omap_start_rxdma(up) != 0) &&
  404. (lsr & UART_LSR_DR))
  405. receive_chars(up, &lsr);
  406. }
  407. }
  408. check_modem_status(up);
  409. if ((lsr & UART_LSR_THRE) && (iir & UART_IIR_THRI))
  410. transmit_chars(up);
  411. spin_unlock_irqrestore(&up->port.lock, flags);
  412. pm_runtime_mark_last_busy(&up->pdev->dev);
  413. pm_runtime_put_autosuspend(&up->pdev->dev);
  414. up->port_activity = jiffies;
  415. return IRQ_HANDLED;
  416. }
  417. static unsigned int serial_omap_tx_empty(struct uart_port *port)
  418. {
  419. struct uart_omap_port *up = (struct uart_omap_port *)port;
  420. unsigned long flags = 0;
  421. unsigned int ret = 0;
  422. pm_runtime_get_sync(&up->pdev->dev);
  423. dev_dbg(up->port.dev, "serial_omap_tx_empty+%d\n", up->port.line);
  424. spin_lock_irqsave(&up->port.lock, flags);
  425. ret = serial_in(up, UART_LSR) & UART_LSR_TEMT ? TIOCSER_TEMT : 0;
  426. spin_unlock_irqrestore(&up->port.lock, flags);
  427. pm_runtime_put(&up->pdev->dev);
  428. return ret;
  429. }
  430. static unsigned int serial_omap_get_mctrl(struct uart_port *port)
  431. {
  432. struct uart_omap_port *up = (struct uart_omap_port *)port;
  433. unsigned int status;
  434. unsigned int ret = 0;
  435. pm_runtime_get_sync(&up->pdev->dev);
  436. status = check_modem_status(up);
  437. pm_runtime_put(&up->pdev->dev);
  438. dev_dbg(up->port.dev, "serial_omap_get_mctrl+%d\n", up->port.line);
  439. if (status & UART_MSR_DCD)
  440. ret |= TIOCM_CAR;
  441. if (status & UART_MSR_RI)
  442. ret |= TIOCM_RNG;
  443. if (status & UART_MSR_DSR)
  444. ret |= TIOCM_DSR;
  445. if (status & UART_MSR_CTS)
  446. ret |= TIOCM_CTS;
  447. return ret;
  448. }
  449. static void serial_omap_set_mctrl(struct uart_port *port, unsigned int mctrl)
  450. {
  451. struct uart_omap_port *up = (struct uart_omap_port *)port;
  452. unsigned char mcr = 0;
  453. dev_dbg(up->port.dev, "serial_omap_set_mctrl+%d\n", up->port.line);
  454. if (mctrl & TIOCM_RTS)
  455. mcr |= UART_MCR_RTS;
  456. if (mctrl & TIOCM_DTR)
  457. mcr |= UART_MCR_DTR;
  458. if (mctrl & TIOCM_OUT1)
  459. mcr |= UART_MCR_OUT1;
  460. if (mctrl & TIOCM_OUT2)
  461. mcr |= UART_MCR_OUT2;
  462. if (mctrl & TIOCM_LOOP)
  463. mcr |= UART_MCR_LOOP;
  464. pm_runtime_get_sync(&up->pdev->dev);
  465. up->mcr = serial_in(up, UART_MCR);
  466. up->mcr |= mcr;
  467. serial_out(up, UART_MCR, up->mcr);
  468. pm_runtime_put(&up->pdev->dev);
  469. }
  470. static void serial_omap_break_ctl(struct uart_port *port, int break_state)
  471. {
  472. struct uart_omap_port *up = (struct uart_omap_port *)port;
  473. unsigned long flags = 0;
  474. dev_dbg(up->port.dev, "serial_omap_break_ctl+%d\n", up->port.line);
  475. pm_runtime_get_sync(&up->pdev->dev);
  476. spin_lock_irqsave(&up->port.lock, flags);
  477. if (break_state == -1)
  478. up->lcr |= UART_LCR_SBC;
  479. else
  480. up->lcr &= ~UART_LCR_SBC;
  481. serial_out(up, UART_LCR, up->lcr);
  482. spin_unlock_irqrestore(&up->port.lock, flags);
  483. pm_runtime_put(&up->pdev->dev);
  484. }
  485. static int serial_omap_startup(struct uart_port *port)
  486. {
  487. struct uart_omap_port *up = (struct uart_omap_port *)port;
  488. unsigned long flags = 0;
  489. int retval;
  490. /*
  491. * Allocate the IRQ
  492. */
  493. retval = request_irq(up->port.irq, serial_omap_irq, up->port.irqflags,
  494. up->name, up);
  495. if (retval)
  496. return retval;
  497. dev_dbg(up->port.dev, "serial_omap_startup+%d\n", up->port.line);
  498. pm_runtime_get_sync(&up->pdev->dev);
  499. /*
  500. * Clear the FIFO buffers and disable them.
  501. * (they will be reenabled in set_termios())
  502. */
  503. serial_omap_clear_fifos(up);
  504. /* For Hardware flow control */
  505. serial_out(up, UART_MCR, UART_MCR_RTS);
  506. /*
  507. * Clear the interrupt registers.
  508. */
  509. (void) serial_in(up, UART_LSR);
  510. if (serial_in(up, UART_LSR) & UART_LSR_DR)
  511. (void) serial_in(up, UART_RX);
  512. (void) serial_in(up, UART_IIR);
  513. (void) serial_in(up, UART_MSR);
  514. /*
  515. * Now, initialize the UART
  516. */
  517. serial_out(up, UART_LCR, UART_LCR_WLEN8);
  518. spin_lock_irqsave(&up->port.lock, flags);
  519. /*
  520. * Most PC uarts need OUT2 raised to enable interrupts.
  521. */
  522. up->port.mctrl |= TIOCM_OUT2;
  523. serial_omap_set_mctrl(&up->port, up->port.mctrl);
  524. spin_unlock_irqrestore(&up->port.lock, flags);
  525. up->msr_saved_flags = 0;
  526. if (up->use_dma) {
  527. free_page((unsigned long)up->port.state->xmit.buf);
  528. up->port.state->xmit.buf = dma_alloc_coherent(NULL,
  529. UART_XMIT_SIZE,
  530. (dma_addr_t *)&(up->uart_dma.tx_buf_dma_phys),
  531. 0);
  532. init_timer(&(up->uart_dma.rx_timer));
  533. up->uart_dma.rx_timer.function = serial_omap_rxdma_poll;
  534. up->uart_dma.rx_timer.data = up->port.line;
  535. /* Currently the buffer size is 4KB. Can increase it */
  536. up->uart_dma.rx_buf = dma_alloc_coherent(NULL,
  537. up->uart_dma.rx_buf_size,
  538. (dma_addr_t *)&(up->uart_dma.rx_buf_dma_phys), 0);
  539. }
  540. /*
  541. * Finally, enable interrupts. Note: Modem status interrupts
  542. * are set via set_termios(), which will be occurring imminently
  543. * anyway, so we don't enable them here.
  544. */
  545. up->ier = UART_IER_RLSI | UART_IER_RDI;
  546. serial_out(up, UART_IER, up->ier);
  547. /* Enable module level wake up */
  548. serial_out(up, UART_OMAP_WER, OMAP_UART_WER_MOD_WKUP);
  549. pm_runtime_mark_last_busy(&up->pdev->dev);
  550. pm_runtime_put_autosuspend(&up->pdev->dev);
  551. up->port_activity = jiffies;
  552. return 0;
  553. }
  554. static void serial_omap_shutdown(struct uart_port *port)
  555. {
  556. struct uart_omap_port *up = (struct uart_omap_port *)port;
  557. unsigned long flags = 0;
  558. dev_dbg(up->port.dev, "serial_omap_shutdown+%d\n", up->port.line);
  559. pm_runtime_get_sync(&up->pdev->dev);
  560. /*
  561. * Disable interrupts from this port
  562. */
  563. up->ier = 0;
  564. serial_out(up, UART_IER, 0);
  565. spin_lock_irqsave(&up->port.lock, flags);
  566. up->port.mctrl &= ~TIOCM_OUT2;
  567. serial_omap_set_mctrl(&up->port, up->port.mctrl);
  568. spin_unlock_irqrestore(&up->port.lock, flags);
  569. /*
  570. * Disable break condition and FIFOs
  571. */
  572. serial_out(up, UART_LCR, serial_in(up, UART_LCR) & ~UART_LCR_SBC);
  573. serial_omap_clear_fifos(up);
  574. /*
  575. * Read data port to reset things, and then free the irq
  576. */
  577. if (serial_in(up, UART_LSR) & UART_LSR_DR)
  578. (void) serial_in(up, UART_RX);
  579. if (up->use_dma) {
  580. dma_free_coherent(up->port.dev,
  581. UART_XMIT_SIZE, up->port.state->xmit.buf,
  582. up->uart_dma.tx_buf_dma_phys);
  583. up->port.state->xmit.buf = NULL;
  584. serial_omap_stop_rx(port);
  585. dma_free_coherent(up->port.dev,
  586. up->uart_dma.rx_buf_size, up->uart_dma.rx_buf,
  587. up->uart_dma.rx_buf_dma_phys);
  588. up->uart_dma.rx_buf = NULL;
  589. }
  590. pm_runtime_put(&up->pdev->dev);
  591. free_irq(up->port.irq, up);
  592. }
  593. static inline void
  594. serial_omap_configure_xonxoff
  595. (struct uart_omap_port *up, struct ktermios *termios)
  596. {
  597. up->lcr = serial_in(up, UART_LCR);
  598. serial_out(up, UART_LCR, UART_LCR_CONF_MODE_B);
  599. up->efr = serial_in(up, UART_EFR);
  600. serial_out(up, UART_EFR, up->efr & ~UART_EFR_ECB);
  601. serial_out(up, UART_XON1, termios->c_cc[VSTART]);
  602. serial_out(up, UART_XOFF1, termios->c_cc[VSTOP]);
  603. /* clear SW control mode bits */
  604. up->efr &= OMAP_UART_SW_CLR;
  605. /*
  606. * IXON Flag:
  607. * Enable XON/XOFF flow control on output.
  608. * Transmit XON1, XOFF1
  609. */
  610. if (termios->c_iflag & IXON)
  611. up->efr |= OMAP_UART_SW_TX;
  612. /*
  613. * IXOFF Flag:
  614. * Enable XON/XOFF flow control on input.
  615. * Receiver compares XON1, XOFF1.
  616. */
  617. if (termios->c_iflag & IXOFF)
  618. up->efr |= OMAP_UART_SW_RX;
  619. serial_out(up, UART_EFR, up->efr | UART_EFR_ECB);
  620. serial_out(up, UART_LCR, UART_LCR_CONF_MODE_A);
  621. up->mcr = serial_in(up, UART_MCR);
  622. /*
  623. * IXANY Flag:
  624. * Enable any character to restart output.
  625. * Operation resumes after receiving any
  626. * character after recognition of the XOFF character
  627. */
  628. if (termios->c_iflag & IXANY)
  629. up->mcr |= UART_MCR_XONANY;
  630. serial_out(up, UART_MCR, up->mcr | UART_MCR_TCRTLR);
  631. serial_out(up, UART_LCR, UART_LCR_CONF_MODE_B);
  632. serial_out(up, UART_TI752_TCR, OMAP_UART_TCR_TRIG);
  633. /* Enable special char function UARTi.EFR_REG[5] and
  634. * load the new software flow control mode IXON or IXOFF
  635. * and restore the UARTi.EFR_REG[4] ENHANCED_EN value.
  636. */
  637. serial_out(up, UART_EFR, up->efr | UART_EFR_SCD);
  638. serial_out(up, UART_LCR, UART_LCR_CONF_MODE_A);
  639. serial_out(up, UART_MCR, up->mcr & ~UART_MCR_TCRTLR);
  640. serial_out(up, UART_LCR, up->lcr);
  641. }
  642. static void serial_omap_uart_qos_work(struct work_struct *work)
  643. {
  644. struct uart_omap_port *up = container_of(work, struct uart_omap_port,
  645. qos_work);
  646. pm_qos_update_request(&up->pm_qos_request, up->latency);
  647. }
  648. static void
  649. serial_omap_set_termios(struct uart_port *port, struct ktermios *termios,
  650. struct ktermios *old)
  651. {
  652. struct uart_omap_port *up = (struct uart_omap_port *)port;
  653. unsigned char cval = 0;
  654. unsigned char efr = 0;
  655. unsigned long flags = 0;
  656. unsigned int baud, quot;
  657. u32 tlr;
  658. switch (termios->c_cflag & CSIZE) {
  659. case CS5:
  660. cval = UART_LCR_WLEN5;
  661. break;
  662. case CS6:
  663. cval = UART_LCR_WLEN6;
  664. break;
  665. case CS7:
  666. cval = UART_LCR_WLEN7;
  667. break;
  668. default:
  669. case CS8:
  670. cval = UART_LCR_WLEN8;
  671. break;
  672. }
  673. if (termios->c_cflag & CSTOPB)
  674. cval |= UART_LCR_STOP;
  675. if (termios->c_cflag & PARENB)
  676. cval |= UART_LCR_PARITY;
  677. if (!(termios->c_cflag & PARODD))
  678. cval |= UART_LCR_EPAR;
  679. /*
  680. * Ask the core to calculate the divisor for us.
  681. */
  682. baud = uart_get_baud_rate(port, termios, old, 0, port->uartclk/13);
  683. quot = serial_omap_get_divisor(port, baud);
  684. /* calculate wakeup latency constraint */
  685. up->calc_latency = (1000000 * up->port.fifosize) /
  686. (1000 * baud / 8);
  687. up->latency = up->calc_latency;
  688. schedule_work(&up->qos_work);
  689. up->dll = quot & 0xff;
  690. up->dlh = quot >> 8;
  691. up->mdr1 = UART_OMAP_MDR1_DISABLE;
  692. up->fcr = UART_FCR_R_TRIG_01 | UART_FCR_T_TRIG_01 |
  693. UART_FCR_ENABLE_FIFO;
  694. if (up->use_dma)
  695. up->fcr |= UART_FCR_DMA_SELECT;
  696. /*
  697. * Ok, we're now changing the port state. Do it with
  698. * interrupts disabled.
  699. */
  700. pm_runtime_get_sync(&up->pdev->dev);
  701. spin_lock_irqsave(&up->port.lock, flags);
  702. /*
  703. * Update the per-port timeout.
  704. */
  705. uart_update_timeout(port, termios->c_cflag, baud);
  706. up->port.read_status_mask = UART_LSR_OE | UART_LSR_THRE | UART_LSR_DR;
  707. if (termios->c_iflag & INPCK)
  708. up->port.read_status_mask |= UART_LSR_FE | UART_LSR_PE;
  709. if (termios->c_iflag & (BRKINT | PARMRK))
  710. up->port.read_status_mask |= UART_LSR_BI;
  711. /*
  712. * Characters to ignore
  713. */
  714. up->port.ignore_status_mask = 0;
  715. if (termios->c_iflag & IGNPAR)
  716. up->port.ignore_status_mask |= UART_LSR_PE | UART_LSR_FE;
  717. if (termios->c_iflag & IGNBRK) {
  718. up->port.ignore_status_mask |= UART_LSR_BI;
  719. /*
  720. * If we're ignoring parity and break indicators,
  721. * ignore overruns too (for real raw support).
  722. */
  723. if (termios->c_iflag & IGNPAR)
  724. up->port.ignore_status_mask |= UART_LSR_OE;
  725. }
  726. /*
  727. * ignore all characters if CREAD is not set
  728. */
  729. if ((termios->c_cflag & CREAD) == 0)
  730. up->port.ignore_status_mask |= UART_LSR_DR;
  731. /*
  732. * Modem status interrupts
  733. */
  734. up->ier &= ~UART_IER_MSI;
  735. if (UART_ENABLE_MS(&up->port, termios->c_cflag))
  736. up->ier |= UART_IER_MSI;
  737. serial_out(up, UART_IER, up->ier);
  738. serial_out(up, UART_LCR, cval); /* reset DLAB */
  739. up->lcr = cval;
  740. up->scr = OMAP_UART_SCR_TX_EMPTY;
  741. /* FIFOs and DMA Settings */
  742. /* FCR can be changed only when the
  743. * baud clock is not running
  744. * DLL_REG and DLH_REG set to 0.
  745. */
  746. serial_out(up, UART_LCR, UART_LCR_CONF_MODE_A);
  747. serial_out(up, UART_DLL, 0);
  748. serial_out(up, UART_DLM, 0);
  749. serial_out(up, UART_LCR, 0);
  750. serial_out(up, UART_LCR, UART_LCR_CONF_MODE_B);
  751. up->efr = serial_in(up, UART_EFR);
  752. serial_out(up, UART_EFR, up->efr | UART_EFR_ECB);
  753. serial_out(up, UART_LCR, UART_LCR_CONF_MODE_A);
  754. up->mcr = serial_in(up, UART_MCR);
  755. serial_out(up, UART_MCR, up->mcr | UART_MCR_TCRTLR);
  756. /* FIFO ENABLE, DMA MODE */
  757. up->scr |= OMAP_UART_SCR_TX_TRIG_GRANU1_MASK;
  758. up->scr |= OMAP_UART_SCR_RX_TRIG_GRANU1_MASK;
  759. if (up->use_dma) {
  760. tlr = 0;
  761. } else {
  762. up->scr &= ~OMAP_UART_SCR_TX_EMPTY;
  763. /* Set receive FIFO threshold to 1 */
  764. up->fcr &= ~OMAP_UART_FCR_RX_FIFO_TRIG_MASK;
  765. up->fcr |= (0x1 << OMAP_UART_FCR_RX_FIFO_TRIG_SHIFT);
  766. /* Set TX FIFO threshold to "63" (actually 1) */
  767. up->fcr |= (0x3 << OMAP_UART_FCR_TX_FIFO_TRIG_SHIFT);
  768. tlr = (0xf << OMAP_UART_TLR_TX_FIFO_TRIG_DMA_SHIFT);
  769. }
  770. serial_out(up, UART_TI752_TLR, tlr);
  771. serial_out(up, UART_FCR, up->fcr);
  772. serial_out(up, UART_LCR, UART_LCR_CONF_MODE_B);
  773. serial_out(up, UART_OMAP_SCR, up->scr);
  774. serial_out(up, UART_EFR, up->efr);
  775. serial_out(up, UART_LCR, UART_LCR_CONF_MODE_A);
  776. serial_out(up, UART_MCR, up->mcr);
  777. /* Protocol, Baud Rate, and Interrupt Settings */
  778. if (up->errata & UART_ERRATA_i202_MDR1_ACCESS)
  779. serial_omap_mdr1_errataset(up, up->mdr1);
  780. else
  781. serial_out(up, UART_OMAP_MDR1, up->mdr1);
  782. serial_out(up, UART_LCR, UART_LCR_CONF_MODE_B);
  783. up->efr = serial_in(up, UART_EFR);
  784. serial_out(up, UART_EFR, up->efr | UART_EFR_ECB);
  785. serial_out(up, UART_LCR, 0);
  786. serial_out(up, UART_IER, 0);
  787. serial_out(up, UART_LCR, UART_LCR_CONF_MODE_B);
  788. serial_out(up, UART_DLL, up->dll); /* LS of divisor */
  789. serial_out(up, UART_DLM, up->dlh); /* MS of divisor */
  790. serial_out(up, UART_LCR, 0);
  791. serial_out(up, UART_IER, up->ier);
  792. serial_out(up, UART_LCR, UART_LCR_CONF_MODE_B);
  793. serial_out(up, UART_EFR, up->efr);
  794. serial_out(up, UART_LCR, cval);
  795. if (baud > 230400 && baud != 3000000)
  796. up->mdr1 = UART_OMAP_MDR1_13X_MODE;
  797. else
  798. up->mdr1 = UART_OMAP_MDR1_16X_MODE;
  799. if (up->errata & UART_ERRATA_i202_MDR1_ACCESS)
  800. serial_omap_mdr1_errataset(up, up->mdr1);
  801. else
  802. serial_out(up, UART_OMAP_MDR1, up->mdr1);
  803. /* Hardware Flow Control Configuration */
  804. if (termios->c_cflag & CRTSCTS) {
  805. efr |= (UART_EFR_CTS | UART_EFR_RTS);
  806. serial_out(up, UART_LCR, UART_LCR_CONF_MODE_A);
  807. up->mcr = serial_in(up, UART_MCR);
  808. serial_out(up, UART_MCR, up->mcr | UART_MCR_TCRTLR);
  809. serial_out(up, UART_LCR, UART_LCR_CONF_MODE_B);
  810. up->efr = serial_in(up, UART_EFR);
  811. serial_out(up, UART_EFR, up->efr | UART_EFR_ECB);
  812. serial_out(up, UART_TI752_TCR, OMAP_UART_TCR_TRIG);
  813. serial_out(up, UART_EFR, efr); /* Enable AUTORTS and AUTOCTS */
  814. serial_out(up, UART_LCR, UART_LCR_CONF_MODE_A);
  815. serial_out(up, UART_MCR, up->mcr | UART_MCR_RTS);
  816. serial_out(up, UART_LCR, cval);
  817. }
  818. serial_omap_set_mctrl(&up->port, up->port.mctrl);
  819. /* Software Flow Control Configuration */
  820. serial_omap_configure_xonxoff(up, termios);
  821. spin_unlock_irqrestore(&up->port.lock, flags);
  822. pm_runtime_put(&up->pdev->dev);
  823. dev_dbg(up->port.dev, "serial_omap_set_termios+%d\n", up->port.line);
  824. }
  825. static void
  826. serial_omap_pm(struct uart_port *port, unsigned int state,
  827. unsigned int oldstate)
  828. {
  829. struct uart_omap_port *up = (struct uart_omap_port *)port;
  830. unsigned char efr;
  831. dev_dbg(up->port.dev, "serial_omap_pm+%d\n", up->port.line);
  832. pm_runtime_get_sync(&up->pdev->dev);
  833. serial_out(up, UART_LCR, UART_LCR_CONF_MODE_B);
  834. efr = serial_in(up, UART_EFR);
  835. serial_out(up, UART_EFR, efr | UART_EFR_ECB);
  836. serial_out(up, UART_LCR, 0);
  837. serial_out(up, UART_IER, (state != 0) ? UART_IERX_SLEEP : 0);
  838. serial_out(up, UART_LCR, UART_LCR_CONF_MODE_B);
  839. serial_out(up, UART_EFR, efr);
  840. serial_out(up, UART_LCR, 0);
  841. if (!device_may_wakeup(&up->pdev->dev)) {
  842. if (!state)
  843. pm_runtime_forbid(&up->pdev->dev);
  844. else
  845. pm_runtime_allow(&up->pdev->dev);
  846. }
  847. pm_runtime_put(&up->pdev->dev);
  848. }
  849. static void serial_omap_release_port(struct uart_port *port)
  850. {
  851. dev_dbg(port->dev, "serial_omap_release_port+\n");
  852. }
  853. static int serial_omap_request_port(struct uart_port *port)
  854. {
  855. dev_dbg(port->dev, "serial_omap_request_port+\n");
  856. return 0;
  857. }
  858. static void serial_omap_config_port(struct uart_port *port, int flags)
  859. {
  860. struct uart_omap_port *up = (struct uart_omap_port *)port;
  861. dev_dbg(up->port.dev, "serial_omap_config_port+%d\n",
  862. up->port.line);
  863. up->port.type = PORT_OMAP;
  864. }
  865. static int
  866. serial_omap_verify_port(struct uart_port *port, struct serial_struct *ser)
  867. {
  868. /* we don't want the core code to modify any port params */
  869. dev_dbg(port->dev, "serial_omap_verify_port+\n");
  870. return -EINVAL;
  871. }
  872. static const char *
  873. serial_omap_type(struct uart_port *port)
  874. {
  875. struct uart_omap_port *up = (struct uart_omap_port *)port;
  876. dev_dbg(up->port.dev, "serial_omap_type+%d\n", up->port.line);
  877. return up->name;
  878. }
  879. #define BOTH_EMPTY (UART_LSR_TEMT | UART_LSR_THRE)
  880. static inline void wait_for_xmitr(struct uart_omap_port *up)
  881. {
  882. unsigned int status, tmout = 10000;
  883. /* Wait up to 10ms for the character(s) to be sent. */
  884. do {
  885. status = serial_in(up, UART_LSR);
  886. if (status & UART_LSR_BI)
  887. up->lsr_break_flag = UART_LSR_BI;
  888. if (--tmout == 0)
  889. break;
  890. udelay(1);
  891. } while ((status & BOTH_EMPTY) != BOTH_EMPTY);
  892. /* Wait up to 1s for flow control if necessary */
  893. if (up->port.flags & UPF_CONS_FLOW) {
  894. tmout = 1000000;
  895. for (tmout = 1000000; tmout; tmout--) {
  896. unsigned int msr = serial_in(up, UART_MSR);
  897. up->msr_saved_flags |= msr & MSR_SAVE_FLAGS;
  898. if (msr & UART_MSR_CTS)
  899. break;
  900. udelay(1);
  901. }
  902. }
  903. }
  904. #ifdef CONFIG_CONSOLE_POLL
  905. static void serial_omap_poll_put_char(struct uart_port *port, unsigned char ch)
  906. {
  907. struct uart_omap_port *up = (struct uart_omap_port *)port;
  908. pm_runtime_get_sync(&up->pdev->dev);
  909. wait_for_xmitr(up);
  910. serial_out(up, UART_TX, ch);
  911. pm_runtime_put(&up->pdev->dev);
  912. }
  913. static int serial_omap_poll_get_char(struct uart_port *port)
  914. {
  915. struct uart_omap_port *up = (struct uart_omap_port *)port;
  916. unsigned int status;
  917. pm_runtime_get_sync(&up->pdev->dev);
  918. status = serial_in(up, UART_LSR);
  919. if (!(status & UART_LSR_DR))
  920. return NO_POLL_CHAR;
  921. status = serial_in(up, UART_RX);
  922. pm_runtime_put(&up->pdev->dev);
  923. return status;
  924. }
  925. #endif /* CONFIG_CONSOLE_POLL */
  926. #ifdef CONFIG_SERIAL_OMAP_CONSOLE
  927. static struct uart_omap_port *serial_omap_console_ports[4];
  928. static struct uart_driver serial_omap_reg;
  929. static void serial_omap_console_putchar(struct uart_port *port, int ch)
  930. {
  931. struct uart_omap_port *up = (struct uart_omap_port *)port;
  932. wait_for_xmitr(up);
  933. serial_out(up, UART_TX, ch);
  934. }
  935. static void
  936. serial_omap_console_write(struct console *co, const char *s,
  937. unsigned int count)
  938. {
  939. struct uart_omap_port *up = serial_omap_console_ports[co->index];
  940. unsigned long flags;
  941. unsigned int ier;
  942. int locked = 1;
  943. pm_runtime_get_sync(&up->pdev->dev);
  944. local_irq_save(flags);
  945. if (up->port.sysrq)
  946. locked = 0;
  947. else if (oops_in_progress)
  948. locked = spin_trylock(&up->port.lock);
  949. else
  950. spin_lock(&up->port.lock);
  951. /*
  952. * First save the IER then disable the interrupts
  953. */
  954. ier = serial_in(up, UART_IER);
  955. serial_out(up, UART_IER, 0);
  956. uart_console_write(&up->port, s, count, serial_omap_console_putchar);
  957. /*
  958. * Finally, wait for transmitter to become empty
  959. * and restore the IER
  960. */
  961. wait_for_xmitr(up);
  962. serial_out(up, UART_IER, ier);
  963. /*
  964. * The receive handling will happen properly because the
  965. * receive ready bit will still be set; it is not cleared
  966. * on read. However, modem control will not, we must
  967. * call it if we have saved something in the saved flags
  968. * while processing with interrupts off.
  969. */
  970. if (up->msr_saved_flags)
  971. check_modem_status(up);
  972. pm_runtime_mark_last_busy(&up->pdev->dev);
  973. pm_runtime_put_autosuspend(&up->pdev->dev);
  974. if (locked)
  975. spin_unlock(&up->port.lock);
  976. local_irq_restore(flags);
  977. }
  978. static int __init
  979. serial_omap_console_setup(struct console *co, char *options)
  980. {
  981. struct uart_omap_port *up;
  982. int baud = 115200;
  983. int bits = 8;
  984. int parity = 'n';
  985. int flow = 'n';
  986. if (serial_omap_console_ports[co->index] == NULL)
  987. return -ENODEV;
  988. up = serial_omap_console_ports[co->index];
  989. if (options)
  990. uart_parse_options(options, &baud, &parity, &bits, &flow);
  991. return uart_set_options(&up->port, co, baud, parity, bits, flow);
  992. }
  993. static struct console serial_omap_console = {
  994. .name = OMAP_SERIAL_NAME,
  995. .write = serial_omap_console_write,
  996. .device = uart_console_device,
  997. .setup = serial_omap_console_setup,
  998. .flags = CON_PRINTBUFFER,
  999. .index = -1,
  1000. .data = &serial_omap_reg,
  1001. };
  1002. static void serial_omap_add_console_port(struct uart_omap_port *up)
  1003. {
  1004. serial_omap_console_ports[up->port.line] = up;
  1005. }
  1006. #define OMAP_CONSOLE (&serial_omap_console)
  1007. #else
  1008. #define OMAP_CONSOLE NULL
  1009. static inline void serial_omap_add_console_port(struct uart_omap_port *up)
  1010. {}
  1011. #endif
  1012. static struct uart_ops serial_omap_pops = {
  1013. .tx_empty = serial_omap_tx_empty,
  1014. .set_mctrl = serial_omap_set_mctrl,
  1015. .get_mctrl = serial_omap_get_mctrl,
  1016. .stop_tx = serial_omap_stop_tx,
  1017. .start_tx = serial_omap_start_tx,
  1018. .stop_rx = serial_omap_stop_rx,
  1019. .enable_ms = serial_omap_enable_ms,
  1020. .break_ctl = serial_omap_break_ctl,
  1021. .startup = serial_omap_startup,
  1022. .shutdown = serial_omap_shutdown,
  1023. .set_termios = serial_omap_set_termios,
  1024. .pm = serial_omap_pm,
  1025. .type = serial_omap_type,
  1026. .release_port = serial_omap_release_port,
  1027. .request_port = serial_omap_request_port,
  1028. .config_port = serial_omap_config_port,
  1029. .verify_port = serial_omap_verify_port,
  1030. #ifdef CONFIG_CONSOLE_POLL
  1031. .poll_put_char = serial_omap_poll_put_char,
  1032. .poll_get_char = serial_omap_poll_get_char,
  1033. #endif
  1034. };
  1035. static struct uart_driver serial_omap_reg = {
  1036. .owner = THIS_MODULE,
  1037. .driver_name = "OMAP-SERIAL",
  1038. .dev_name = OMAP_SERIAL_NAME,
  1039. .nr = OMAP_MAX_HSUART_PORTS,
  1040. .cons = OMAP_CONSOLE,
  1041. };
  1042. #ifdef CONFIG_PM_SLEEP
  1043. static int serial_omap_suspend(struct device *dev)
  1044. {
  1045. struct uart_omap_port *up = dev_get_drvdata(dev);
  1046. if (up) {
  1047. uart_suspend_port(&serial_omap_reg, &up->port);
  1048. flush_work_sync(&up->qos_work);
  1049. }
  1050. return 0;
  1051. }
  1052. static int serial_omap_resume(struct device *dev)
  1053. {
  1054. struct uart_omap_port *up = dev_get_drvdata(dev);
  1055. if (up)
  1056. uart_resume_port(&serial_omap_reg, &up->port);
  1057. return 0;
  1058. }
  1059. #endif
  1060. static void serial_omap_rxdma_poll(unsigned long uart_no)
  1061. {
  1062. struct uart_omap_port *up = ui[uart_no];
  1063. unsigned int curr_dma_pos, curr_transmitted_size;
  1064. int ret = 0;
  1065. curr_dma_pos = omap_get_dma_dst_pos(up->uart_dma.rx_dma_channel);
  1066. if ((curr_dma_pos == up->uart_dma.prev_rx_dma_pos) ||
  1067. (curr_dma_pos == 0)) {
  1068. if (jiffies_to_msecs(jiffies - up->port_activity) <
  1069. up->uart_dma.rx_timeout) {
  1070. mod_timer(&up->uart_dma.rx_timer, jiffies +
  1071. usecs_to_jiffies(up->uart_dma.rx_poll_rate));
  1072. } else {
  1073. serial_omap_stop_rxdma(up);
  1074. up->ier |= (UART_IER_RDI | UART_IER_RLSI);
  1075. serial_out(up, UART_IER, up->ier);
  1076. }
  1077. return;
  1078. }
  1079. curr_transmitted_size = curr_dma_pos -
  1080. up->uart_dma.prev_rx_dma_pos;
  1081. up->port.icount.rx += curr_transmitted_size;
  1082. tty_insert_flip_string(up->port.state->port.tty,
  1083. up->uart_dma.rx_buf +
  1084. (up->uart_dma.prev_rx_dma_pos -
  1085. up->uart_dma.rx_buf_dma_phys),
  1086. curr_transmitted_size);
  1087. tty_flip_buffer_push(up->port.state->port.tty);
  1088. up->uart_dma.prev_rx_dma_pos = curr_dma_pos;
  1089. if (up->uart_dma.rx_buf_size +
  1090. up->uart_dma.rx_buf_dma_phys == curr_dma_pos) {
  1091. ret = serial_omap_start_rxdma(up);
  1092. if (ret < 0) {
  1093. serial_omap_stop_rxdma(up);
  1094. up->ier |= (UART_IER_RDI | UART_IER_RLSI);
  1095. serial_out(up, UART_IER, up->ier);
  1096. }
  1097. } else {
  1098. mod_timer(&up->uart_dma.rx_timer, jiffies +
  1099. usecs_to_jiffies(up->uart_dma.rx_poll_rate));
  1100. }
  1101. up->port_activity = jiffies;
  1102. }
  1103. static void uart_rx_dma_callback(int lch, u16 ch_status, void *data)
  1104. {
  1105. return;
  1106. }
  1107. static int serial_omap_start_rxdma(struct uart_omap_port *up)
  1108. {
  1109. int ret = 0;
  1110. if (up->uart_dma.rx_dma_channel == -1) {
  1111. pm_runtime_get_sync(&up->pdev->dev);
  1112. ret = omap_request_dma(up->uart_dma.uart_dma_rx,
  1113. "UART Rx DMA",
  1114. (void *)uart_rx_dma_callback, up,
  1115. &(up->uart_dma.rx_dma_channel));
  1116. if (ret < 0)
  1117. return ret;
  1118. omap_set_dma_src_params(up->uart_dma.rx_dma_channel, 0,
  1119. OMAP_DMA_AMODE_CONSTANT,
  1120. up->uart_dma.uart_base, 0, 0);
  1121. omap_set_dma_dest_params(up->uart_dma.rx_dma_channel, 0,
  1122. OMAP_DMA_AMODE_POST_INC,
  1123. up->uart_dma.rx_buf_dma_phys, 0, 0);
  1124. omap_set_dma_transfer_params(up->uart_dma.rx_dma_channel,
  1125. OMAP_DMA_DATA_TYPE_S8,
  1126. up->uart_dma.rx_buf_size, 1,
  1127. OMAP_DMA_SYNC_ELEMENT,
  1128. up->uart_dma.uart_dma_rx, 0);
  1129. }
  1130. up->uart_dma.prev_rx_dma_pos = up->uart_dma.rx_buf_dma_phys;
  1131. /* FIXME: Cache maintenance needed here? */
  1132. omap_start_dma(up->uart_dma.rx_dma_channel);
  1133. mod_timer(&up->uart_dma.rx_timer, jiffies +
  1134. usecs_to_jiffies(up->uart_dma.rx_poll_rate));
  1135. up->uart_dma.rx_dma_used = true;
  1136. return ret;
  1137. }
  1138. static void serial_omap_continue_tx(struct uart_omap_port *up)
  1139. {
  1140. struct circ_buf *xmit = &up->port.state->xmit;
  1141. unsigned int start = up->uart_dma.tx_buf_dma_phys
  1142. + (xmit->tail & (UART_XMIT_SIZE - 1));
  1143. if (uart_circ_empty(xmit))
  1144. return;
  1145. up->uart_dma.tx_buf_size = uart_circ_chars_pending(xmit);
  1146. /*
  1147. * It is a circular buffer. See if the buffer has wounded back.
  1148. * If yes it will have to be transferred in two separate dma
  1149. * transfers
  1150. */
  1151. if (start + up->uart_dma.tx_buf_size >=
  1152. up->uart_dma.tx_buf_dma_phys + UART_XMIT_SIZE)
  1153. up->uart_dma.tx_buf_size =
  1154. (up->uart_dma.tx_buf_dma_phys + UART_XMIT_SIZE) - start;
  1155. omap_set_dma_dest_params(up->uart_dma.tx_dma_channel, 0,
  1156. OMAP_DMA_AMODE_CONSTANT,
  1157. up->uart_dma.uart_base, 0, 0);
  1158. omap_set_dma_src_params(up->uart_dma.tx_dma_channel, 0,
  1159. OMAP_DMA_AMODE_POST_INC, start, 0, 0);
  1160. omap_set_dma_transfer_params(up->uart_dma.tx_dma_channel,
  1161. OMAP_DMA_DATA_TYPE_S8,
  1162. up->uart_dma.tx_buf_size, 1,
  1163. OMAP_DMA_SYNC_ELEMENT,
  1164. up->uart_dma.uart_dma_tx, 0);
  1165. /* FIXME: Cache maintenance needed here? */
  1166. omap_start_dma(up->uart_dma.tx_dma_channel);
  1167. }
  1168. static void uart_tx_dma_callback(int lch, u16 ch_status, void *data)
  1169. {
  1170. struct uart_omap_port *up = (struct uart_omap_port *)data;
  1171. struct circ_buf *xmit = &up->port.state->xmit;
  1172. xmit->tail = (xmit->tail + up->uart_dma.tx_buf_size) & \
  1173. (UART_XMIT_SIZE - 1);
  1174. up->port.icount.tx += up->uart_dma.tx_buf_size;
  1175. if (uart_circ_chars_pending(xmit) < WAKEUP_CHARS)
  1176. uart_write_wakeup(&up->port);
  1177. if (uart_circ_empty(xmit)) {
  1178. spin_lock(&(up->uart_dma.tx_lock));
  1179. serial_omap_stop_tx(&up->port);
  1180. up->uart_dma.tx_dma_used = false;
  1181. spin_unlock(&(up->uart_dma.tx_lock));
  1182. } else {
  1183. omap_stop_dma(up->uart_dma.tx_dma_channel);
  1184. serial_omap_continue_tx(up);
  1185. }
  1186. up->port_activity = jiffies;
  1187. return;
  1188. }
  1189. static struct omap_uart_port_info *of_get_uart_port_info(struct device *dev)
  1190. {
  1191. struct omap_uart_port_info *omap_up_info;
  1192. omap_up_info = devm_kzalloc(dev, sizeof(*omap_up_info), GFP_KERNEL);
  1193. if (!omap_up_info)
  1194. return NULL; /* out of memory */
  1195. of_property_read_u32(dev->of_node, "clock-frequency",
  1196. &omap_up_info->uartclk);
  1197. return omap_up_info;
  1198. }
  1199. static int serial_omap_probe(struct platform_device *pdev)
  1200. {
  1201. struct uart_omap_port *up;
  1202. struct resource *mem, *irq, *dma_tx, *dma_rx;
  1203. struct omap_uart_port_info *omap_up_info = pdev->dev.platform_data;
  1204. int ret = -ENOSPC;
  1205. if (pdev->dev.of_node)
  1206. omap_up_info = of_get_uart_port_info(&pdev->dev);
  1207. mem = platform_get_resource(pdev, IORESOURCE_MEM, 0);
  1208. if (!mem) {
  1209. dev_err(&pdev->dev, "no mem resource?\n");
  1210. return -ENODEV;
  1211. }
  1212. irq = platform_get_resource(pdev, IORESOURCE_IRQ, 0);
  1213. if (!irq) {
  1214. dev_err(&pdev->dev, "no irq resource?\n");
  1215. return -ENODEV;
  1216. }
  1217. if (!request_mem_region(mem->start, resource_size(mem),
  1218. pdev->dev.driver->name)) {
  1219. dev_err(&pdev->dev, "memory region already claimed\n");
  1220. return -EBUSY;
  1221. }
  1222. dma_rx = platform_get_resource_byname(pdev, IORESOURCE_DMA, "rx");
  1223. if (!dma_rx) {
  1224. ret = -EINVAL;
  1225. goto err;
  1226. }
  1227. dma_tx = platform_get_resource_byname(pdev, IORESOURCE_DMA, "tx");
  1228. if (!dma_tx) {
  1229. ret = -EINVAL;
  1230. goto err;
  1231. }
  1232. up = kzalloc(sizeof(*up), GFP_KERNEL);
  1233. if (up == NULL) {
  1234. ret = -ENOMEM;
  1235. goto do_release_region;
  1236. }
  1237. up->pdev = pdev;
  1238. up->port.dev = &pdev->dev;
  1239. up->port.type = PORT_OMAP;
  1240. up->port.iotype = UPIO_MEM;
  1241. up->port.irq = irq->start;
  1242. up->port.regshift = 2;
  1243. up->port.fifosize = 64;
  1244. up->port.ops = &serial_omap_pops;
  1245. up->max_tx_count = up->port.fifosize / 4;
  1246. if (pdev->dev.of_node)
  1247. up->port.line = of_alias_get_id(pdev->dev.of_node, "serial");
  1248. else
  1249. up->port.line = pdev->id;
  1250. if (up->port.line < 0) {
  1251. dev_err(&pdev->dev, "failed to get alias/pdev id, errno %d\n",
  1252. up->port.line);
  1253. ret = -ENODEV;
  1254. goto err;
  1255. }
  1256. sprintf(up->name, "OMAP UART%d", up->port.line);
  1257. up->port.mapbase = mem->start;
  1258. up->port.membase = ioremap(mem->start, resource_size(mem));
  1259. if (!up->port.membase) {
  1260. dev_err(&pdev->dev, "can't ioremap UART\n");
  1261. ret = -ENOMEM;
  1262. goto err;
  1263. }
  1264. up->port.flags = omap_up_info->flags;
  1265. up->port.uartclk = omap_up_info->uartclk;
  1266. if (!up->port.uartclk) {
  1267. up->port.uartclk = DEFAULT_CLK_SPEED;
  1268. dev_warn(&pdev->dev, "No clock speed specified: using default:"
  1269. "%d\n", DEFAULT_CLK_SPEED);
  1270. }
  1271. up->uart_dma.uart_base = mem->start;
  1272. up->errata = omap_up_info->errata;
  1273. if (omap_up_info->dma_enabled) {
  1274. up->uart_dma.uart_dma_tx = dma_tx->start;
  1275. up->uart_dma.uart_dma_rx = dma_rx->start;
  1276. up->use_dma = 1;
  1277. up->uart_dma.rx_buf_size = omap_up_info->dma_rx_buf_size;
  1278. up->uart_dma.rx_timeout = omap_up_info->dma_rx_timeout;
  1279. up->uart_dma.rx_poll_rate = omap_up_info->dma_rx_poll_rate;
  1280. spin_lock_init(&(up->uart_dma.tx_lock));
  1281. spin_lock_init(&(up->uart_dma.rx_lock));
  1282. up->uart_dma.tx_dma_channel = OMAP_UART_DMA_CH_FREE;
  1283. up->uart_dma.rx_dma_channel = OMAP_UART_DMA_CH_FREE;
  1284. }
  1285. up->latency = PM_QOS_CPU_DMA_LAT_DEFAULT_VALUE;
  1286. up->calc_latency = PM_QOS_CPU_DMA_LAT_DEFAULT_VALUE;
  1287. pm_qos_add_request(&up->pm_qos_request,
  1288. PM_QOS_CPU_DMA_LATENCY, up->latency);
  1289. serial_omap_uart_wq = create_singlethread_workqueue(up->name);
  1290. INIT_WORK(&up->qos_work, serial_omap_uart_qos_work);
  1291. pm_runtime_use_autosuspend(&pdev->dev);
  1292. pm_runtime_set_autosuspend_delay(&pdev->dev,
  1293. omap_up_info->autosuspend_timeout);
  1294. pm_runtime_irq_safe(&pdev->dev);
  1295. pm_runtime_enable(&pdev->dev);
  1296. pm_runtime_get_sync(&pdev->dev);
  1297. ui[up->port.line] = up;
  1298. serial_omap_add_console_port(up);
  1299. ret = uart_add_one_port(&serial_omap_reg, &up->port);
  1300. if (ret != 0)
  1301. goto do_release_region;
  1302. pm_runtime_put(&pdev->dev);
  1303. platform_set_drvdata(pdev, up);
  1304. return 0;
  1305. err:
  1306. dev_err(&pdev->dev, "[UART%d]: failure [%s]: %d\n",
  1307. pdev->id, __func__, ret);
  1308. do_release_region:
  1309. release_mem_region(mem->start, resource_size(mem));
  1310. return ret;
  1311. }
  1312. static int serial_omap_remove(struct platform_device *dev)
  1313. {
  1314. struct uart_omap_port *up = platform_get_drvdata(dev);
  1315. if (up) {
  1316. pm_runtime_disable(&up->pdev->dev);
  1317. uart_remove_one_port(&serial_omap_reg, &up->port);
  1318. pm_qos_remove_request(&up->pm_qos_request);
  1319. kfree(up);
  1320. }
  1321. platform_set_drvdata(dev, NULL);
  1322. return 0;
  1323. }
  1324. /*
  1325. * Work Around for Errata i202 (2430, 3430, 3630, 4430 and 4460)
  1326. * The access to uart register after MDR1 Access
  1327. * causes UART to corrupt data.
  1328. *
  1329. * Need a delay =
  1330. * 5 L4 clock cycles + 5 UART functional clock cycle (@48MHz = ~0.2uS)
  1331. * give 10 times as much
  1332. */
  1333. static void serial_omap_mdr1_errataset(struct uart_omap_port *up, u8 mdr1)
  1334. {
  1335. u8 timeout = 255;
  1336. serial_out(up, UART_OMAP_MDR1, mdr1);
  1337. udelay(2);
  1338. serial_out(up, UART_FCR, up->fcr | UART_FCR_CLEAR_XMIT |
  1339. UART_FCR_CLEAR_RCVR);
  1340. /*
  1341. * Wait for FIFO to empty: when empty, RX_FIFO_E bit is 0 and
  1342. * TX_FIFO_E bit is 1.
  1343. */
  1344. while (UART_LSR_THRE != (serial_in(up, UART_LSR) &
  1345. (UART_LSR_THRE | UART_LSR_DR))) {
  1346. timeout--;
  1347. if (!timeout) {
  1348. /* Should *never* happen. we warn and carry on */
  1349. dev_crit(&up->pdev->dev, "Errata i202: timedout %x\n",
  1350. serial_in(up, UART_LSR));
  1351. break;
  1352. }
  1353. udelay(1);
  1354. }
  1355. }
  1356. #ifdef CONFIG_PM_RUNTIME
  1357. static void serial_omap_restore_context(struct uart_omap_port *up)
  1358. {
  1359. if (up->errata & UART_ERRATA_i202_MDR1_ACCESS)
  1360. serial_omap_mdr1_errataset(up, UART_OMAP_MDR1_DISABLE);
  1361. else
  1362. serial_out(up, UART_OMAP_MDR1, UART_OMAP_MDR1_DISABLE);
  1363. serial_out(up, UART_LCR, UART_LCR_CONF_MODE_B); /* Config B mode */
  1364. serial_out(up, UART_EFR, UART_EFR_ECB);
  1365. serial_out(up, UART_LCR, 0x0); /* Operational mode */
  1366. serial_out(up, UART_IER, 0x0);
  1367. serial_out(up, UART_LCR, UART_LCR_CONF_MODE_B); /* Config B mode */
  1368. serial_out(up, UART_DLL, up->dll);
  1369. serial_out(up, UART_DLM, up->dlh);
  1370. serial_out(up, UART_LCR, 0x0); /* Operational mode */
  1371. serial_out(up, UART_IER, up->ier);
  1372. serial_out(up, UART_FCR, up->fcr);
  1373. serial_out(up, UART_LCR, UART_LCR_CONF_MODE_A);
  1374. serial_out(up, UART_MCR, up->mcr);
  1375. serial_out(up, UART_LCR, UART_LCR_CONF_MODE_B); /* Config B mode */
  1376. serial_out(up, UART_OMAP_SCR, up->scr);
  1377. serial_out(up, UART_EFR, up->efr);
  1378. serial_out(up, UART_LCR, up->lcr);
  1379. if (up->errata & UART_ERRATA_i202_MDR1_ACCESS)
  1380. serial_omap_mdr1_errataset(up, up->mdr1);
  1381. else
  1382. serial_out(up, UART_OMAP_MDR1, up->mdr1);
  1383. }
  1384. static int serial_omap_runtime_suspend(struct device *dev)
  1385. {
  1386. struct uart_omap_port *up = dev_get_drvdata(dev);
  1387. struct omap_uart_port_info *pdata = dev->platform_data;
  1388. if (!up)
  1389. return -EINVAL;
  1390. if (!pdata || !pdata->enable_wakeup)
  1391. return 0;
  1392. if (pdata->get_context_loss_count)
  1393. up->context_loss_cnt = pdata->get_context_loss_count(dev);
  1394. if (device_may_wakeup(dev)) {
  1395. if (!up->wakeups_enabled) {
  1396. pdata->enable_wakeup(up->pdev, true);
  1397. up->wakeups_enabled = true;
  1398. }
  1399. } else {
  1400. if (up->wakeups_enabled) {
  1401. pdata->enable_wakeup(up->pdev, false);
  1402. up->wakeups_enabled = false;
  1403. }
  1404. }
  1405. /* Errata i291 */
  1406. if (up->use_dma && pdata->set_forceidle &&
  1407. (up->errata & UART_ERRATA_i291_DMA_FORCEIDLE))
  1408. pdata->set_forceidle(up->pdev);
  1409. up->latency = PM_QOS_CPU_DMA_LAT_DEFAULT_VALUE;
  1410. schedule_work(&up->qos_work);
  1411. return 0;
  1412. }
  1413. static int serial_omap_runtime_resume(struct device *dev)
  1414. {
  1415. struct uart_omap_port *up = dev_get_drvdata(dev);
  1416. struct omap_uart_port_info *pdata = dev->platform_data;
  1417. if (up) {
  1418. if (pdata->get_context_loss_count) {
  1419. u32 loss_cnt = pdata->get_context_loss_count(dev);
  1420. if (up->context_loss_cnt != loss_cnt)
  1421. serial_omap_restore_context(up);
  1422. }
  1423. /* Errata i291 */
  1424. if (up->use_dma && pdata->set_noidle &&
  1425. (up->errata & UART_ERRATA_i291_DMA_FORCEIDLE))
  1426. pdata->set_noidle(up->pdev);
  1427. up->latency = up->calc_latency;
  1428. schedule_work(&up->qos_work);
  1429. }
  1430. return 0;
  1431. }
  1432. #endif
  1433. static const struct dev_pm_ops serial_omap_dev_pm_ops = {
  1434. SET_SYSTEM_SLEEP_PM_OPS(serial_omap_suspend, serial_omap_resume)
  1435. SET_RUNTIME_PM_OPS(serial_omap_runtime_suspend,
  1436. serial_omap_runtime_resume, NULL)
  1437. };
  1438. #if defined(CONFIG_OF)
  1439. static const struct of_device_id omap_serial_of_match[] = {
  1440. { .compatible = "ti,omap2-uart" },
  1441. { .compatible = "ti,omap3-uart" },
  1442. { .compatible = "ti,omap4-uart" },
  1443. {},
  1444. };
  1445. MODULE_DEVICE_TABLE(of, omap_serial_of_match);
  1446. #endif
  1447. static struct platform_driver serial_omap_driver = {
  1448. .probe = serial_omap_probe,
  1449. .remove = serial_omap_remove,
  1450. .driver = {
  1451. .name = DRIVER_NAME,
  1452. .pm = &serial_omap_dev_pm_ops,
  1453. .of_match_table = of_match_ptr(omap_serial_of_match),
  1454. },
  1455. };
  1456. static int __init serial_omap_init(void)
  1457. {
  1458. int ret;
  1459. ret = uart_register_driver(&serial_omap_reg);
  1460. if (ret != 0)
  1461. return ret;
  1462. ret = platform_driver_register(&serial_omap_driver);
  1463. if (ret != 0)
  1464. uart_unregister_driver(&serial_omap_reg);
  1465. return ret;
  1466. }
  1467. static void __exit serial_omap_exit(void)
  1468. {
  1469. platform_driver_unregister(&serial_omap_driver);
  1470. uart_unregister_driver(&serial_omap_reg);
  1471. }
  1472. module_init(serial_omap_init);
  1473. module_exit(serial_omap_exit);
  1474. MODULE_DESCRIPTION("OMAP High Speed UART driver");
  1475. MODULE_LICENSE("GPL");
  1476. MODULE_AUTHOR("Texas Instruments Inc");