pxa.c 20 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865
  1. /*
  2. * linux/drivers/serial/pxa.c
  3. *
  4. * Based on drivers/serial/8250.c by Russell King.
  5. *
  6. * Author: Nicolas Pitre
  7. * Created: Feb 20, 2003
  8. * Copyright: (C) 2003 Monta Vista Software, Inc.
  9. *
  10. * This program is free software; you can redistribute it and/or modify
  11. * it under the terms of the GNU General Public License as published by
  12. * the Free Software Foundation; either version 2 of the License, or
  13. * (at your option) any later version.
  14. *
  15. * Note 1: This driver is made separate from the already too overloaded
  16. * 8250.c because it needs some kirks of its own and that'll make it
  17. * easier to add DMA support.
  18. *
  19. * Note 2: I'm too sick of device allocation policies for serial ports.
  20. * If someone else wants to request an "official" allocation of major/minor
  21. * for this driver please be my guest. And don't forget that new hardware
  22. * to come from Intel might have more than 3 or 4 of those UARTs. Let's
  23. * hope for a better port registration and dynamic device allocation scheme
  24. * with the serial core maintainer satisfaction to appear soon.
  25. */
  26. #if defined(CONFIG_SERIAL_PXA_CONSOLE) && defined(CONFIG_MAGIC_SYSRQ)
  27. #define SUPPORT_SYSRQ
  28. #endif
  29. #include <linux/module.h>
  30. #include <linux/ioport.h>
  31. #include <linux/init.h>
  32. #include <linux/console.h>
  33. #include <linux/sysrq.h>
  34. #include <linux/serial_reg.h>
  35. #include <linux/circ_buf.h>
  36. #include <linux/delay.h>
  37. #include <linux/interrupt.h>
  38. #include <linux/platform_device.h>
  39. #include <linux/tty.h>
  40. #include <linux/tty_flip.h>
  41. #include <linux/serial_core.h>
  42. #include <asm/io.h>
  43. #include <asm/hardware.h>
  44. #include <asm/irq.h>
  45. #include <asm/arch/pxa-regs.h>
  46. struct uart_pxa_port {
  47. struct uart_port port;
  48. unsigned char ier;
  49. unsigned char lcr;
  50. unsigned char mcr;
  51. unsigned int lsr_break_flag;
  52. unsigned int cken;
  53. char *name;
  54. };
  55. static inline unsigned int serial_in(struct uart_pxa_port *up, int offset)
  56. {
  57. offset <<= 2;
  58. return readl(up->port.membase + offset);
  59. }
  60. static inline void serial_out(struct uart_pxa_port *up, int offset, int value)
  61. {
  62. offset <<= 2;
  63. writel(value, up->port.membase + offset);
  64. }
  65. static void serial_pxa_enable_ms(struct uart_port *port)
  66. {
  67. struct uart_pxa_port *up = (struct uart_pxa_port *)port;
  68. up->ier |= UART_IER_MSI;
  69. serial_out(up, UART_IER, up->ier);
  70. }
  71. static void serial_pxa_stop_tx(struct uart_port *port)
  72. {
  73. struct uart_pxa_port *up = (struct uart_pxa_port *)port;
  74. if (up->ier & UART_IER_THRI) {
  75. up->ier &= ~UART_IER_THRI;
  76. serial_out(up, UART_IER, up->ier);
  77. }
  78. }
  79. static void serial_pxa_stop_rx(struct uart_port *port)
  80. {
  81. struct uart_pxa_port *up = (struct uart_pxa_port *)port;
  82. up->ier &= ~UART_IER_RLSI;
  83. up->port.read_status_mask &= ~UART_LSR_DR;
  84. serial_out(up, UART_IER, up->ier);
  85. }
  86. static inline void
  87. receive_chars(struct uart_pxa_port *up, int *status, struct pt_regs *regs)
  88. {
  89. struct tty_struct *tty = up->port.info->tty;
  90. unsigned int ch, flag;
  91. int max_count = 256;
  92. do {
  93. ch = serial_in(up, UART_RX);
  94. flag = TTY_NORMAL;
  95. up->port.icount.rx++;
  96. if (unlikely(*status & (UART_LSR_BI | UART_LSR_PE |
  97. UART_LSR_FE | UART_LSR_OE))) {
  98. /*
  99. * For statistics only
  100. */
  101. if (*status & UART_LSR_BI) {
  102. *status &= ~(UART_LSR_FE | UART_LSR_PE);
  103. up->port.icount.brk++;
  104. /*
  105. * We do the SysRQ and SAK checking
  106. * here because otherwise the break
  107. * may get masked by ignore_status_mask
  108. * or read_status_mask.
  109. */
  110. if (uart_handle_break(&up->port))
  111. goto ignore_char;
  112. } else if (*status & UART_LSR_PE)
  113. up->port.icount.parity++;
  114. else if (*status & UART_LSR_FE)
  115. up->port.icount.frame++;
  116. if (*status & UART_LSR_OE)
  117. up->port.icount.overrun++;
  118. /*
  119. * Mask off conditions which should be ignored.
  120. */
  121. *status &= up->port.read_status_mask;
  122. #ifdef CONFIG_SERIAL_PXA_CONSOLE
  123. if (up->port.line == up->port.cons->index) {
  124. /* Recover the break flag from console xmit */
  125. *status |= up->lsr_break_flag;
  126. up->lsr_break_flag = 0;
  127. }
  128. #endif
  129. if (*status & UART_LSR_BI) {
  130. flag = TTY_BREAK;
  131. } else if (*status & UART_LSR_PE)
  132. flag = TTY_PARITY;
  133. else if (*status & UART_LSR_FE)
  134. flag = TTY_FRAME;
  135. }
  136. if (uart_handle_sysrq_char(&up->port, ch, regs))
  137. goto ignore_char;
  138. uart_insert_char(&up->port, *status, UART_LSR_OE, ch, flag);
  139. ignore_char:
  140. *status = serial_in(up, UART_LSR);
  141. } while ((*status & UART_LSR_DR) && (max_count-- > 0));
  142. tty_flip_buffer_push(tty);
  143. }
  144. static void transmit_chars(struct uart_pxa_port *up)
  145. {
  146. struct circ_buf *xmit = &up->port.info->xmit;
  147. int count;
  148. if (up->port.x_char) {
  149. serial_out(up, UART_TX, up->port.x_char);
  150. up->port.icount.tx++;
  151. up->port.x_char = 0;
  152. return;
  153. }
  154. if (uart_circ_empty(xmit) || uart_tx_stopped(&up->port)) {
  155. serial_pxa_stop_tx(&up->port);
  156. return;
  157. }
  158. count = up->port.fifosize / 2;
  159. do {
  160. serial_out(up, UART_TX, xmit->buf[xmit->tail]);
  161. xmit->tail = (xmit->tail + 1) & (UART_XMIT_SIZE - 1);
  162. up->port.icount.tx++;
  163. if (uart_circ_empty(xmit))
  164. break;
  165. } while (--count > 0);
  166. if (uart_circ_chars_pending(xmit) < WAKEUP_CHARS)
  167. uart_write_wakeup(&up->port);
  168. if (uart_circ_empty(xmit))
  169. serial_pxa_stop_tx(&up->port);
  170. }
  171. static void serial_pxa_start_tx(struct uart_port *port)
  172. {
  173. struct uart_pxa_port *up = (struct uart_pxa_port *)port;
  174. if (!(up->ier & UART_IER_THRI)) {
  175. up->ier |= UART_IER_THRI;
  176. serial_out(up, UART_IER, up->ier);
  177. }
  178. }
  179. static inline void check_modem_status(struct uart_pxa_port *up)
  180. {
  181. int status;
  182. status = serial_in(up, UART_MSR);
  183. if ((status & UART_MSR_ANY_DELTA) == 0)
  184. return;
  185. if (status & UART_MSR_TERI)
  186. up->port.icount.rng++;
  187. if (status & UART_MSR_DDSR)
  188. up->port.icount.dsr++;
  189. if (status & UART_MSR_DDCD)
  190. uart_handle_dcd_change(&up->port, status & UART_MSR_DCD);
  191. if (status & UART_MSR_DCTS)
  192. uart_handle_cts_change(&up->port, status & UART_MSR_CTS);
  193. wake_up_interruptible(&up->port.info->delta_msr_wait);
  194. }
  195. /*
  196. * This handles the interrupt from one port.
  197. */
  198. static inline irqreturn_t
  199. serial_pxa_irq(int irq, void *dev_id, struct pt_regs *regs)
  200. {
  201. struct uart_pxa_port *up = (struct uart_pxa_port *)dev_id;
  202. unsigned int iir, lsr;
  203. iir = serial_in(up, UART_IIR);
  204. if (iir & UART_IIR_NO_INT)
  205. return IRQ_NONE;
  206. lsr = serial_in(up, UART_LSR);
  207. if (lsr & UART_LSR_DR)
  208. receive_chars(up, &lsr, regs);
  209. check_modem_status(up);
  210. if (lsr & UART_LSR_THRE)
  211. transmit_chars(up);
  212. return IRQ_HANDLED;
  213. }
  214. static unsigned int serial_pxa_tx_empty(struct uart_port *port)
  215. {
  216. struct uart_pxa_port *up = (struct uart_pxa_port *)port;
  217. unsigned long flags;
  218. unsigned int ret;
  219. spin_lock_irqsave(&up->port.lock, flags);
  220. ret = serial_in(up, UART_LSR) & UART_LSR_TEMT ? TIOCSER_TEMT : 0;
  221. spin_unlock_irqrestore(&up->port.lock, flags);
  222. return ret;
  223. }
  224. static unsigned int serial_pxa_get_mctrl(struct uart_port *port)
  225. {
  226. struct uart_pxa_port *up = (struct uart_pxa_port *)port;
  227. unsigned char status;
  228. unsigned int ret;
  229. status = serial_in(up, UART_MSR);
  230. ret = 0;
  231. if (status & UART_MSR_DCD)
  232. ret |= TIOCM_CAR;
  233. if (status & UART_MSR_RI)
  234. ret |= TIOCM_RNG;
  235. if (status & UART_MSR_DSR)
  236. ret |= TIOCM_DSR;
  237. if (status & UART_MSR_CTS)
  238. ret |= TIOCM_CTS;
  239. return ret;
  240. }
  241. static void serial_pxa_set_mctrl(struct uart_port *port, unsigned int mctrl)
  242. {
  243. struct uart_pxa_port *up = (struct uart_pxa_port *)port;
  244. unsigned char mcr = 0;
  245. if (mctrl & TIOCM_RTS)
  246. mcr |= UART_MCR_RTS;
  247. if (mctrl & TIOCM_DTR)
  248. mcr |= UART_MCR_DTR;
  249. if (mctrl & TIOCM_OUT1)
  250. mcr |= UART_MCR_OUT1;
  251. if (mctrl & TIOCM_OUT2)
  252. mcr |= UART_MCR_OUT2;
  253. if (mctrl & TIOCM_LOOP)
  254. mcr |= UART_MCR_LOOP;
  255. mcr |= up->mcr;
  256. serial_out(up, UART_MCR, mcr);
  257. }
  258. static void serial_pxa_break_ctl(struct uart_port *port, int break_state)
  259. {
  260. struct uart_pxa_port *up = (struct uart_pxa_port *)port;
  261. unsigned long flags;
  262. spin_lock_irqsave(&up->port.lock, flags);
  263. if (break_state == -1)
  264. up->lcr |= UART_LCR_SBC;
  265. else
  266. up->lcr &= ~UART_LCR_SBC;
  267. serial_out(up, UART_LCR, up->lcr);
  268. spin_unlock_irqrestore(&up->port.lock, flags);
  269. }
  270. #if 0
  271. static void serial_pxa_dma_init(struct pxa_uart *up)
  272. {
  273. up->rxdma =
  274. pxa_request_dma(up->name, DMA_PRIO_LOW, pxa_receive_dma, up);
  275. if (up->rxdma < 0)
  276. goto out;
  277. up->txdma =
  278. pxa_request_dma(up->name, DMA_PRIO_LOW, pxa_transmit_dma, up);
  279. if (up->txdma < 0)
  280. goto err_txdma;
  281. up->dmadesc = kmalloc(4 * sizeof(pxa_dma_desc), GFP_KERNEL);
  282. if (!up->dmadesc)
  283. goto err_alloc;
  284. /* ... */
  285. err_alloc:
  286. pxa_free_dma(up->txdma);
  287. err_rxdma:
  288. pxa_free_dma(up->rxdma);
  289. out:
  290. return;
  291. }
  292. #endif
  293. static int serial_pxa_startup(struct uart_port *port)
  294. {
  295. struct uart_pxa_port *up = (struct uart_pxa_port *)port;
  296. unsigned long flags;
  297. int retval;
  298. if (port->line == 3) /* HWUART */
  299. up->mcr |= UART_MCR_AFE;
  300. else
  301. up->mcr = 0;
  302. /*
  303. * Allocate the IRQ
  304. */
  305. retval = request_irq(up->port.irq, serial_pxa_irq, 0, up->name, up);
  306. if (retval)
  307. return retval;
  308. /*
  309. * Clear the FIFO buffers and disable them.
  310. * (they will be reenabled in set_termios())
  311. */
  312. serial_out(up, UART_FCR, UART_FCR_ENABLE_FIFO);
  313. serial_out(up, UART_FCR, UART_FCR_ENABLE_FIFO |
  314. UART_FCR_CLEAR_RCVR | UART_FCR_CLEAR_XMIT);
  315. serial_out(up, UART_FCR, 0);
  316. /*
  317. * Clear the interrupt registers.
  318. */
  319. (void) serial_in(up, UART_LSR);
  320. (void) serial_in(up, UART_RX);
  321. (void) serial_in(up, UART_IIR);
  322. (void) serial_in(up, UART_MSR);
  323. /*
  324. * Now, initialize the UART
  325. */
  326. serial_out(up, UART_LCR, UART_LCR_WLEN8);
  327. spin_lock_irqsave(&up->port.lock, flags);
  328. up->port.mctrl |= TIOCM_OUT2;
  329. serial_pxa_set_mctrl(&up->port, up->port.mctrl);
  330. spin_unlock_irqrestore(&up->port.lock, flags);
  331. /*
  332. * Finally, enable interrupts. Note: Modem status interrupts
  333. * are set via set_termios(), which will be occurring imminently
  334. * anyway, so we don't enable them here.
  335. */
  336. up->ier = UART_IER_RLSI | UART_IER_RDI | UART_IER_RTOIE | UART_IER_UUE;
  337. serial_out(up, UART_IER, up->ier);
  338. /*
  339. * And clear the interrupt registers again for luck.
  340. */
  341. (void) serial_in(up, UART_LSR);
  342. (void) serial_in(up, UART_RX);
  343. (void) serial_in(up, UART_IIR);
  344. (void) serial_in(up, UART_MSR);
  345. return 0;
  346. }
  347. static void serial_pxa_shutdown(struct uart_port *port)
  348. {
  349. struct uart_pxa_port *up = (struct uart_pxa_port *)port;
  350. unsigned long flags;
  351. free_irq(up->port.irq, up);
  352. /*
  353. * Disable interrupts from this port
  354. */
  355. up->ier = 0;
  356. serial_out(up, UART_IER, 0);
  357. spin_lock_irqsave(&up->port.lock, flags);
  358. up->port.mctrl &= ~TIOCM_OUT2;
  359. serial_pxa_set_mctrl(&up->port, up->port.mctrl);
  360. spin_unlock_irqrestore(&up->port.lock, flags);
  361. /*
  362. * Disable break condition and FIFOs
  363. */
  364. serial_out(up, UART_LCR, serial_in(up, UART_LCR) & ~UART_LCR_SBC);
  365. serial_out(up, UART_FCR, UART_FCR_ENABLE_FIFO |
  366. UART_FCR_CLEAR_RCVR |
  367. UART_FCR_CLEAR_XMIT);
  368. serial_out(up, UART_FCR, 0);
  369. }
  370. static void
  371. serial_pxa_set_termios(struct uart_port *port, struct termios *termios,
  372. struct termios *old)
  373. {
  374. struct uart_pxa_port *up = (struct uart_pxa_port *)port;
  375. unsigned char cval, fcr = 0;
  376. unsigned long flags;
  377. unsigned int baud, quot;
  378. switch (termios->c_cflag & CSIZE) {
  379. case CS5:
  380. cval = UART_LCR_WLEN5;
  381. break;
  382. case CS6:
  383. cval = UART_LCR_WLEN6;
  384. break;
  385. case CS7:
  386. cval = UART_LCR_WLEN7;
  387. break;
  388. default:
  389. case CS8:
  390. cval = UART_LCR_WLEN8;
  391. break;
  392. }
  393. if (termios->c_cflag & CSTOPB)
  394. cval |= UART_LCR_STOP;
  395. if (termios->c_cflag & PARENB)
  396. cval |= UART_LCR_PARITY;
  397. if (!(termios->c_cflag & PARODD))
  398. cval |= UART_LCR_EPAR;
  399. /*
  400. * Ask the core to calculate the divisor for us.
  401. */
  402. baud = uart_get_baud_rate(port, termios, old, 0, port->uartclk/16);
  403. quot = uart_get_divisor(port, baud);
  404. if ((up->port.uartclk / quot) < (2400 * 16))
  405. fcr = UART_FCR_ENABLE_FIFO | UART_FCR_PXAR1;
  406. else if ((up->port.uartclk / quot) < (230400 * 16))
  407. fcr = UART_FCR_ENABLE_FIFO | UART_FCR_PXAR8;
  408. else
  409. fcr = UART_FCR_ENABLE_FIFO | UART_FCR_PXAR32;
  410. /*
  411. * Ok, we're now changing the port state. Do it with
  412. * interrupts disabled.
  413. */
  414. spin_lock_irqsave(&up->port.lock, flags);
  415. /*
  416. * Ensure the port will be enabled.
  417. * This is required especially for serial console.
  418. */
  419. up->ier |= IER_UUE;
  420. /*
  421. * Update the per-port timeout.
  422. */
  423. uart_update_timeout(port, termios->c_cflag, baud);
  424. up->port.read_status_mask = UART_LSR_OE | UART_LSR_THRE | UART_LSR_DR;
  425. if (termios->c_iflag & INPCK)
  426. up->port.read_status_mask |= UART_LSR_FE | UART_LSR_PE;
  427. if (termios->c_iflag & (BRKINT | PARMRK))
  428. up->port.read_status_mask |= UART_LSR_BI;
  429. /*
  430. * Characters to ignore
  431. */
  432. up->port.ignore_status_mask = 0;
  433. if (termios->c_iflag & IGNPAR)
  434. up->port.ignore_status_mask |= UART_LSR_PE | UART_LSR_FE;
  435. if (termios->c_iflag & IGNBRK) {
  436. up->port.ignore_status_mask |= UART_LSR_BI;
  437. /*
  438. * If we're ignoring parity and break indicators,
  439. * ignore overruns too (for real raw support).
  440. */
  441. if (termios->c_iflag & IGNPAR)
  442. up->port.ignore_status_mask |= UART_LSR_OE;
  443. }
  444. /*
  445. * ignore all characters if CREAD is not set
  446. */
  447. if ((termios->c_cflag & CREAD) == 0)
  448. up->port.ignore_status_mask |= UART_LSR_DR;
  449. /*
  450. * CTS flow control flag and modem status interrupts
  451. */
  452. up->ier &= ~UART_IER_MSI;
  453. if (UART_ENABLE_MS(&up->port, termios->c_cflag))
  454. up->ier |= UART_IER_MSI;
  455. serial_out(up, UART_IER, up->ier);
  456. serial_out(up, UART_LCR, cval | UART_LCR_DLAB);/* set DLAB */
  457. serial_out(up, UART_DLL, quot & 0xff); /* LS of divisor */
  458. serial_out(up, UART_DLM, quot >> 8); /* MS of divisor */
  459. serial_out(up, UART_LCR, cval); /* reset DLAB */
  460. up->lcr = cval; /* Save LCR */
  461. serial_pxa_set_mctrl(&up->port, up->port.mctrl);
  462. serial_out(up, UART_FCR, fcr);
  463. spin_unlock_irqrestore(&up->port.lock, flags);
  464. }
  465. static void
  466. serial_pxa_pm(struct uart_port *port, unsigned int state,
  467. unsigned int oldstate)
  468. {
  469. struct uart_pxa_port *up = (struct uart_pxa_port *)port;
  470. pxa_set_cken(up->cken, !state);
  471. if (!state)
  472. udelay(1);
  473. }
  474. static void serial_pxa_release_port(struct uart_port *port)
  475. {
  476. }
  477. static int serial_pxa_request_port(struct uart_port *port)
  478. {
  479. return 0;
  480. }
  481. static void serial_pxa_config_port(struct uart_port *port, int flags)
  482. {
  483. struct uart_pxa_port *up = (struct uart_pxa_port *)port;
  484. up->port.type = PORT_PXA;
  485. }
  486. static int
  487. serial_pxa_verify_port(struct uart_port *port, struct serial_struct *ser)
  488. {
  489. /* we don't want the core code to modify any port params */
  490. return -EINVAL;
  491. }
  492. static const char *
  493. serial_pxa_type(struct uart_port *port)
  494. {
  495. struct uart_pxa_port *up = (struct uart_pxa_port *)port;
  496. return up->name;
  497. }
  498. #ifdef CONFIG_SERIAL_PXA_CONSOLE
  499. static struct uart_pxa_port serial_pxa_ports[];
  500. static struct uart_driver serial_pxa_reg;
  501. #define BOTH_EMPTY (UART_LSR_TEMT | UART_LSR_THRE)
  502. /*
  503. * Wait for transmitter & holding register to empty
  504. */
  505. static inline void wait_for_xmitr(struct uart_pxa_port *up)
  506. {
  507. unsigned int status, tmout = 10000;
  508. /* Wait up to 10ms for the character(s) to be sent. */
  509. do {
  510. status = serial_in(up, UART_LSR);
  511. if (status & UART_LSR_BI)
  512. up->lsr_break_flag = UART_LSR_BI;
  513. if (--tmout == 0)
  514. break;
  515. udelay(1);
  516. } while ((status & BOTH_EMPTY) != BOTH_EMPTY);
  517. /* Wait up to 1s for flow control if necessary */
  518. if (up->port.flags & UPF_CONS_FLOW) {
  519. tmout = 1000000;
  520. while (--tmout &&
  521. ((serial_in(up, UART_MSR) & UART_MSR_CTS) == 0))
  522. udelay(1);
  523. }
  524. }
  525. static void serial_pxa_console_putchar(struct uart_port *port, int ch)
  526. {
  527. struct uart_pxa_port *up = (struct uart_pxa_port *)port;
  528. wait_for_xmitr(up);
  529. serial_out(up, UART_TX, ch);
  530. }
  531. /*
  532. * Print a string to the serial port trying not to disturb
  533. * any possible real use of the port...
  534. *
  535. * The console_lock must be held when we get here.
  536. */
  537. static void
  538. serial_pxa_console_write(struct console *co, const char *s, unsigned int count)
  539. {
  540. struct uart_pxa_port *up = &serial_pxa_ports[co->index];
  541. unsigned int ier;
  542. /*
  543. * First save the IER then disable the interrupts
  544. */
  545. ier = serial_in(up, UART_IER);
  546. serial_out(up, UART_IER, UART_IER_UUE);
  547. uart_console_write(&up->port, s, count, serial_pxa_console_putchar);
  548. /*
  549. * Finally, wait for transmitter to become empty
  550. * and restore the IER
  551. */
  552. wait_for_xmitr(up);
  553. serial_out(up, UART_IER, ier);
  554. }
  555. static int __init
  556. serial_pxa_console_setup(struct console *co, char *options)
  557. {
  558. struct uart_pxa_port *up;
  559. int baud = 9600;
  560. int bits = 8;
  561. int parity = 'n';
  562. int flow = 'n';
  563. if (co->index == -1 || co->index >= serial_pxa_reg.nr)
  564. co->index = 0;
  565. up = &serial_pxa_ports[co->index];
  566. if (options)
  567. uart_parse_options(options, &baud, &parity, &bits, &flow);
  568. return uart_set_options(&up->port, co, baud, parity, bits, flow);
  569. }
  570. static struct console serial_pxa_console = {
  571. .name = "ttyS",
  572. .write = serial_pxa_console_write,
  573. .device = uart_console_device,
  574. .setup = serial_pxa_console_setup,
  575. .flags = CON_PRINTBUFFER,
  576. .index = -1,
  577. .data = &serial_pxa_reg,
  578. };
  579. static int __init
  580. serial_pxa_console_init(void)
  581. {
  582. register_console(&serial_pxa_console);
  583. return 0;
  584. }
  585. console_initcall(serial_pxa_console_init);
  586. #define PXA_CONSOLE &serial_pxa_console
  587. #else
  588. #define PXA_CONSOLE NULL
  589. #endif
  590. struct uart_ops serial_pxa_pops = {
  591. .tx_empty = serial_pxa_tx_empty,
  592. .set_mctrl = serial_pxa_set_mctrl,
  593. .get_mctrl = serial_pxa_get_mctrl,
  594. .stop_tx = serial_pxa_stop_tx,
  595. .start_tx = serial_pxa_start_tx,
  596. .stop_rx = serial_pxa_stop_rx,
  597. .enable_ms = serial_pxa_enable_ms,
  598. .break_ctl = serial_pxa_break_ctl,
  599. .startup = serial_pxa_startup,
  600. .shutdown = serial_pxa_shutdown,
  601. .set_termios = serial_pxa_set_termios,
  602. .pm = serial_pxa_pm,
  603. .type = serial_pxa_type,
  604. .release_port = serial_pxa_release_port,
  605. .request_port = serial_pxa_request_port,
  606. .config_port = serial_pxa_config_port,
  607. .verify_port = serial_pxa_verify_port,
  608. };
  609. static struct uart_pxa_port serial_pxa_ports[] = {
  610. { /* FFUART */
  611. .name = "FFUART",
  612. .cken = CKEN6_FFUART,
  613. .port = {
  614. .type = PORT_PXA,
  615. .iotype = UPIO_MEM,
  616. .membase = (void *)&FFUART,
  617. .mapbase = __PREG(FFUART),
  618. .irq = IRQ_FFUART,
  619. .uartclk = 921600 * 16,
  620. .fifosize = 64,
  621. .ops = &serial_pxa_pops,
  622. .line = 0,
  623. },
  624. }, { /* BTUART */
  625. .name = "BTUART",
  626. .cken = CKEN7_BTUART,
  627. .port = {
  628. .type = PORT_PXA,
  629. .iotype = UPIO_MEM,
  630. .membase = (void *)&BTUART,
  631. .mapbase = __PREG(BTUART),
  632. .irq = IRQ_BTUART,
  633. .uartclk = 921600 * 16,
  634. .fifosize = 64,
  635. .ops = &serial_pxa_pops,
  636. .line = 1,
  637. },
  638. }, { /* STUART */
  639. .name = "STUART",
  640. .cken = CKEN5_STUART,
  641. .port = {
  642. .type = PORT_PXA,
  643. .iotype = UPIO_MEM,
  644. .membase = (void *)&STUART,
  645. .mapbase = __PREG(STUART),
  646. .irq = IRQ_STUART,
  647. .uartclk = 921600 * 16,
  648. .fifosize = 64,
  649. .ops = &serial_pxa_pops,
  650. .line = 2,
  651. },
  652. }, { /* HWUART */
  653. .name = "HWUART",
  654. .cken = CKEN4_HWUART,
  655. .port = {
  656. .type = PORT_PXA,
  657. .iotype = UPIO_MEM,
  658. .membase = (void *)&HWUART,
  659. .mapbase = __PREG(HWUART),
  660. .irq = IRQ_HWUART,
  661. .uartclk = 921600 * 16,
  662. .fifosize = 64,
  663. .ops = &serial_pxa_pops,
  664. .line = 3,
  665. },
  666. }
  667. };
  668. static struct uart_driver serial_pxa_reg = {
  669. .owner = THIS_MODULE,
  670. .driver_name = "PXA serial",
  671. .dev_name = "ttyS",
  672. .major = TTY_MAJOR,
  673. .minor = 64,
  674. .nr = ARRAY_SIZE(serial_pxa_ports),
  675. .cons = PXA_CONSOLE,
  676. };
  677. static int serial_pxa_suspend(struct platform_device *dev, pm_message_t state)
  678. {
  679. struct uart_pxa_port *sport = platform_get_drvdata(dev);
  680. if (sport)
  681. uart_suspend_port(&serial_pxa_reg, &sport->port);
  682. return 0;
  683. }
  684. static int serial_pxa_resume(struct platform_device *dev)
  685. {
  686. struct uart_pxa_port *sport = platform_get_drvdata(dev);
  687. if (sport)
  688. uart_resume_port(&serial_pxa_reg, &sport->port);
  689. return 0;
  690. }
  691. static int serial_pxa_probe(struct platform_device *dev)
  692. {
  693. serial_pxa_ports[dev->id].port.dev = &dev->dev;
  694. uart_add_one_port(&serial_pxa_reg, &serial_pxa_ports[dev->id].port);
  695. platform_set_drvdata(dev, &serial_pxa_ports[dev->id]);
  696. return 0;
  697. }
  698. static int serial_pxa_remove(struct platform_device *dev)
  699. {
  700. struct uart_pxa_port *sport = platform_get_drvdata(dev);
  701. platform_set_drvdata(dev, NULL);
  702. if (sport)
  703. uart_remove_one_port(&serial_pxa_reg, &sport->port);
  704. return 0;
  705. }
  706. static struct platform_driver serial_pxa_driver = {
  707. .probe = serial_pxa_probe,
  708. .remove = serial_pxa_remove,
  709. .suspend = serial_pxa_suspend,
  710. .resume = serial_pxa_resume,
  711. .driver = {
  712. .name = "pxa2xx-uart",
  713. },
  714. };
  715. int __init serial_pxa_init(void)
  716. {
  717. int ret;
  718. ret = uart_register_driver(&serial_pxa_reg);
  719. if (ret != 0)
  720. return ret;
  721. ret = platform_driver_register(&serial_pxa_driver);
  722. if (ret != 0)
  723. uart_unregister_driver(&serial_pxa_reg);
  724. return ret;
  725. }
  726. void __exit serial_pxa_exit(void)
  727. {
  728. platform_driver_unregister(&serial_pxa_driver);
  729. uart_unregister_driver(&serial_pxa_reg);
  730. }
  731. module_init(serial_pxa_init);
  732. module_exit(serial_pxa_exit);
  733. MODULE_LICENSE("GPL");