amba-pl010.c 18 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802
  1. /*
  2. * linux/drivers/char/amba.c
  3. *
  4. * Driver for AMBA serial ports
  5. *
  6. * Based on drivers/char/serial.c, by Linus Torvalds, Theodore Ts'o.
  7. *
  8. * Copyright 1999 ARM Limited
  9. * Copyright (C) 2000 Deep Blue Solutions Ltd.
  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. * This program is distributed in the hope that it will be useful,
  17. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  18. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  19. * GNU General Public License for more details.
  20. *
  21. * You should have received a copy of the GNU General Public License
  22. * along with this program; if not, write to the Free Software
  23. * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
  24. *
  25. * $Id: amba.c,v 1.41 2002/07/28 10:03:27 rmk Exp $
  26. *
  27. * This is a generic driver for ARM AMBA-type serial ports. They
  28. * have a lot of 16550-like features, but are not register compatible.
  29. * Note that although they do have CTS, DCD and DSR inputs, they do
  30. * not have an RI input, nor do they have DTR or RTS outputs. If
  31. * required, these have to be supplied via some other means (eg, GPIO)
  32. * and hooked into this driver.
  33. */
  34. #include <linux/config.h>
  35. #if defined(CONFIG_SERIAL_AMBA_PL010_CONSOLE) && defined(CONFIG_MAGIC_SYSRQ)
  36. #define SUPPORT_SYSRQ
  37. #endif
  38. #include <linux/module.h>
  39. #include <linux/ioport.h>
  40. #include <linux/init.h>
  41. #include <linux/console.h>
  42. #include <linux/sysrq.h>
  43. #include <linux/device.h>
  44. #include <linux/tty.h>
  45. #include <linux/tty_flip.h>
  46. #include <linux/serial_core.h>
  47. #include <linux/serial.h>
  48. #include <linux/amba/bus.h>
  49. #include <linux/amba/serial.h>
  50. #include <asm/io.h>
  51. #include <asm/irq.h>
  52. #include <asm/hardware.h>
  53. #define UART_NR 2
  54. #define SERIAL_AMBA_MAJOR 204
  55. #define SERIAL_AMBA_MINOR 16
  56. #define SERIAL_AMBA_NR UART_NR
  57. #define AMBA_ISR_PASS_LIMIT 256
  58. #define UART_RX_DATA(s) (((s) & UART01x_FR_RXFE) == 0)
  59. #define UART_TX_READY(s) (((s) & UART01x_FR_TXFF) == 0)
  60. #define UART_DUMMY_RSR_RX /*256*/0
  61. #define UART_PORT_SIZE 64
  62. /*
  63. * On the Integrator platform, the port RTS and DTR are provided by
  64. * bits in the following SC_CTRLS register bits:
  65. * RTS DTR
  66. * UART0 7 6
  67. * UART1 5 4
  68. */
  69. #define SC_CTRLC (IO_ADDRESS(INTEGRATOR_SC_BASE) + INTEGRATOR_SC_CTRLC_OFFSET)
  70. #define SC_CTRLS (IO_ADDRESS(INTEGRATOR_SC_BASE) + INTEGRATOR_SC_CTRLS_OFFSET)
  71. /*
  72. * We wrap our port structure around the generic uart_port.
  73. */
  74. struct uart_amba_port {
  75. struct uart_port port;
  76. unsigned int dtr_mask;
  77. unsigned int rts_mask;
  78. unsigned int old_status;
  79. };
  80. static void pl010_stop_tx(struct uart_port *port)
  81. {
  82. unsigned int cr;
  83. cr = readb(port->membase + UART010_CR);
  84. cr &= ~UART010_CR_TIE;
  85. writel(cr, port->membase + UART010_CR);
  86. }
  87. static void pl010_start_tx(struct uart_port *port)
  88. {
  89. unsigned int cr;
  90. cr = readb(port->membase + UART010_CR);
  91. cr |= UART010_CR_TIE;
  92. writel(cr, port->membase + UART010_CR);
  93. }
  94. static void pl010_stop_rx(struct uart_port *port)
  95. {
  96. unsigned int cr;
  97. cr = readb(port->membase + UART010_CR);
  98. cr &= ~(UART010_CR_RIE | UART010_CR_RTIE);
  99. writel(cr, port->membase + UART010_CR);
  100. }
  101. static void pl010_enable_ms(struct uart_port *port)
  102. {
  103. unsigned int cr;
  104. cr = readb(port->membase + UART010_CR);
  105. cr |= UART010_CR_MSIE;
  106. writel(cr, port->membase + UART010_CR);
  107. }
  108. static void
  109. #ifdef SUPPORT_SYSRQ
  110. pl010_rx_chars(struct uart_port *port, struct pt_regs *regs)
  111. #else
  112. pl010_rx_chars(struct uart_port *port)
  113. #endif
  114. {
  115. struct tty_struct *tty = port->info->tty;
  116. unsigned int status, ch, flag, rsr, max_count = 256;
  117. status = readb(port->membase + UART01x_FR);
  118. while (UART_RX_DATA(status) && max_count--) {
  119. ch = readb(port->membase + UART01x_DR);
  120. flag = TTY_NORMAL;
  121. port->icount.rx++;
  122. /*
  123. * Note that the error handling code is
  124. * out of the main execution path
  125. */
  126. rsr = readb(port->membase + UART01x_RSR) | UART_DUMMY_RSR_RX;
  127. if (unlikely(rsr & UART01x_RSR_ANY)) {
  128. if (rsr & UART01x_RSR_BE) {
  129. rsr &= ~(UART01x_RSR_FE | UART01x_RSR_PE);
  130. port->icount.brk++;
  131. if (uart_handle_break(port))
  132. goto ignore_char;
  133. } else if (rsr & UART01x_RSR_PE)
  134. port->icount.parity++;
  135. else if (rsr & UART01x_RSR_FE)
  136. port->icount.frame++;
  137. if (rsr & UART01x_RSR_OE)
  138. port->icount.overrun++;
  139. rsr &= port->read_status_mask;
  140. if (rsr & UART01x_RSR_BE)
  141. flag = TTY_BREAK;
  142. else if (rsr & UART01x_RSR_PE)
  143. flag = TTY_PARITY;
  144. else if (rsr & UART01x_RSR_FE)
  145. flag = TTY_FRAME;
  146. }
  147. if (uart_handle_sysrq_char(port, ch, regs))
  148. goto ignore_char;
  149. uart_insert_char(port, rsr, UART01x_RSR_OE, ch, flag);
  150. ignore_char:
  151. status = readb(port->membase + UART01x_FR);
  152. }
  153. tty_flip_buffer_push(tty);
  154. return;
  155. }
  156. static void pl010_tx_chars(struct uart_port *port)
  157. {
  158. struct circ_buf *xmit = &port->info->xmit;
  159. int count;
  160. if (port->x_char) {
  161. writel(port->x_char, port->membase + UART01x_DR);
  162. port->icount.tx++;
  163. port->x_char = 0;
  164. return;
  165. }
  166. if (uart_circ_empty(xmit) || uart_tx_stopped(port)) {
  167. pl010_stop_tx(port);
  168. return;
  169. }
  170. count = port->fifosize >> 1;
  171. do {
  172. writel(xmit->buf[xmit->tail], port->membase + UART01x_DR);
  173. xmit->tail = (xmit->tail + 1) & (UART_XMIT_SIZE - 1);
  174. port->icount.tx++;
  175. if (uart_circ_empty(xmit))
  176. break;
  177. } while (--count > 0);
  178. if (uart_circ_chars_pending(xmit) < WAKEUP_CHARS)
  179. uart_write_wakeup(port);
  180. if (uart_circ_empty(xmit))
  181. pl010_stop_tx(port);
  182. }
  183. static void pl010_modem_status(struct uart_port *port)
  184. {
  185. struct uart_amba_port *uap = (struct uart_amba_port *)port;
  186. unsigned int status, delta;
  187. writel(0, uap->port.membase + UART010_ICR);
  188. status = readb(uap->port.membase + UART01x_FR) & UART01x_FR_MODEM_ANY;
  189. delta = status ^ uap->old_status;
  190. uap->old_status = status;
  191. if (!delta)
  192. return;
  193. if (delta & UART01x_FR_DCD)
  194. uart_handle_dcd_change(&uap->port, status & UART01x_FR_DCD);
  195. if (delta & UART01x_FR_DSR)
  196. uap->port.icount.dsr++;
  197. if (delta & UART01x_FR_CTS)
  198. uart_handle_cts_change(&uap->port, status & UART01x_FR_CTS);
  199. wake_up_interruptible(&uap->port.info->delta_msr_wait);
  200. }
  201. static irqreturn_t pl010_int(int irq, void *dev_id, struct pt_regs *regs)
  202. {
  203. struct uart_port *port = dev_id;
  204. unsigned int status, pass_counter = AMBA_ISR_PASS_LIMIT;
  205. int handled = 0;
  206. spin_lock(&port->lock);
  207. status = readb(port->membase + UART010_IIR);
  208. if (status) {
  209. do {
  210. if (status & (UART010_IIR_RTIS | UART010_IIR_RIS))
  211. #ifdef SUPPORT_SYSRQ
  212. pl010_rx_chars(port, regs);
  213. #else
  214. pl010_rx_chars(port);
  215. #endif
  216. if (status & UART010_IIR_MIS)
  217. pl010_modem_status(port);
  218. if (status & UART010_IIR_TIS)
  219. pl010_tx_chars(port);
  220. if (pass_counter-- == 0)
  221. break;
  222. status = readb(port->membase + UART010_IIR);
  223. } while (status & (UART010_IIR_RTIS | UART010_IIR_RIS |
  224. UART010_IIR_TIS));
  225. handled = 1;
  226. }
  227. spin_unlock(&port->lock);
  228. return IRQ_RETVAL(handled);
  229. }
  230. static unsigned int pl010_tx_empty(struct uart_port *port)
  231. {
  232. return readb(port->membase + UART01x_FR) & UART01x_FR_BUSY ? 0 : TIOCSER_TEMT;
  233. }
  234. static unsigned int pl010_get_mctrl(struct uart_port *port)
  235. {
  236. unsigned int result = 0;
  237. unsigned int status;
  238. status = readb(port->membase + UART01x_FR);
  239. if (status & UART01x_FR_DCD)
  240. result |= TIOCM_CAR;
  241. if (status & UART01x_FR_DSR)
  242. result |= TIOCM_DSR;
  243. if (status & UART01x_FR_CTS)
  244. result |= TIOCM_CTS;
  245. return result;
  246. }
  247. static void pl010_set_mctrl(struct uart_port *port, unsigned int mctrl)
  248. {
  249. struct uart_amba_port *uap = (struct uart_amba_port *)port;
  250. unsigned int ctrls = 0, ctrlc = 0;
  251. if (mctrl & TIOCM_RTS)
  252. ctrlc |= uap->rts_mask;
  253. else
  254. ctrls |= uap->rts_mask;
  255. if (mctrl & TIOCM_DTR)
  256. ctrlc |= uap->dtr_mask;
  257. else
  258. ctrls |= uap->dtr_mask;
  259. __raw_writel(ctrls, SC_CTRLS);
  260. __raw_writel(ctrlc, SC_CTRLC);
  261. }
  262. static void pl010_break_ctl(struct uart_port *port, int break_state)
  263. {
  264. unsigned long flags;
  265. unsigned int lcr_h;
  266. spin_lock_irqsave(&port->lock, flags);
  267. lcr_h = readb(port->membase + UART010_LCRH);
  268. if (break_state == -1)
  269. lcr_h |= UART01x_LCRH_BRK;
  270. else
  271. lcr_h &= ~UART01x_LCRH_BRK;
  272. writel(lcr_h, port->membase + UART010_LCRH);
  273. spin_unlock_irqrestore(&port->lock, flags);
  274. }
  275. static int pl010_startup(struct uart_port *port)
  276. {
  277. struct uart_amba_port *uap = (struct uart_amba_port *)port;
  278. int retval;
  279. /*
  280. * Allocate the IRQ
  281. */
  282. retval = request_irq(port->irq, pl010_int, 0, "uart-pl010", port);
  283. if (retval)
  284. return retval;
  285. /*
  286. * initialise the old status of the modem signals
  287. */
  288. uap->old_status = readb(port->membase + UART01x_FR) & UART01x_FR_MODEM_ANY;
  289. /*
  290. * Finally, enable interrupts
  291. */
  292. writel(UART01x_CR_UARTEN | UART010_CR_RIE | UART010_CR_RTIE,
  293. port->membase + UART010_CR);
  294. return 0;
  295. }
  296. static void pl010_shutdown(struct uart_port *port)
  297. {
  298. /*
  299. * Free the interrupt
  300. */
  301. free_irq(port->irq, port);
  302. /*
  303. * disable all interrupts, disable the port
  304. */
  305. writel(0, port->membase + UART010_CR);
  306. /* disable break condition and fifos */
  307. writel(readb(port->membase + UART010_LCRH) &
  308. ~(UART01x_LCRH_BRK | UART01x_LCRH_FEN),
  309. port->membase + UART010_LCRH);
  310. }
  311. static void
  312. pl010_set_termios(struct uart_port *port, struct termios *termios,
  313. struct termios *old)
  314. {
  315. unsigned int lcr_h, old_cr;
  316. unsigned long flags;
  317. unsigned int baud, quot;
  318. /*
  319. * Ask the core to calculate the divisor for us.
  320. */
  321. baud = uart_get_baud_rate(port, termios, old, 0, port->uartclk/16);
  322. quot = uart_get_divisor(port, baud);
  323. switch (termios->c_cflag & CSIZE) {
  324. case CS5:
  325. lcr_h = UART01x_LCRH_WLEN_5;
  326. break;
  327. case CS6:
  328. lcr_h = UART01x_LCRH_WLEN_6;
  329. break;
  330. case CS7:
  331. lcr_h = UART01x_LCRH_WLEN_7;
  332. break;
  333. default: // CS8
  334. lcr_h = UART01x_LCRH_WLEN_8;
  335. break;
  336. }
  337. if (termios->c_cflag & CSTOPB)
  338. lcr_h |= UART01x_LCRH_STP2;
  339. if (termios->c_cflag & PARENB) {
  340. lcr_h |= UART01x_LCRH_PEN;
  341. if (!(termios->c_cflag & PARODD))
  342. lcr_h |= UART01x_LCRH_EPS;
  343. }
  344. if (port->fifosize > 1)
  345. lcr_h |= UART01x_LCRH_FEN;
  346. spin_lock_irqsave(&port->lock, flags);
  347. /*
  348. * Update the per-port timeout.
  349. */
  350. uart_update_timeout(port, termios->c_cflag, baud);
  351. port->read_status_mask = UART01x_RSR_OE;
  352. if (termios->c_iflag & INPCK)
  353. port->read_status_mask |= UART01x_RSR_FE | UART01x_RSR_PE;
  354. if (termios->c_iflag & (BRKINT | PARMRK))
  355. port->read_status_mask |= UART01x_RSR_BE;
  356. /*
  357. * Characters to ignore
  358. */
  359. port->ignore_status_mask = 0;
  360. if (termios->c_iflag & IGNPAR)
  361. port->ignore_status_mask |= UART01x_RSR_FE | UART01x_RSR_PE;
  362. if (termios->c_iflag & IGNBRK) {
  363. port->ignore_status_mask |= UART01x_RSR_BE;
  364. /*
  365. * If we're ignoring parity and break indicators,
  366. * ignore overruns too (for real raw support).
  367. */
  368. if (termios->c_iflag & IGNPAR)
  369. port->ignore_status_mask |= UART01x_RSR_OE;
  370. }
  371. /*
  372. * Ignore all characters if CREAD is not set.
  373. */
  374. if ((termios->c_cflag & CREAD) == 0)
  375. port->ignore_status_mask |= UART_DUMMY_RSR_RX;
  376. /* first, disable everything */
  377. old_cr = readb(port->membase + UART010_CR) & ~UART010_CR_MSIE;
  378. if (UART_ENABLE_MS(port, termios->c_cflag))
  379. old_cr |= UART010_CR_MSIE;
  380. writel(0, port->membase + UART010_CR);
  381. /* Set baud rate */
  382. quot -= 1;
  383. writel((quot & 0xf00) >> 8, port->membase + UART010_LCRM);
  384. writel(quot & 0xff, port->membase + UART010_LCRL);
  385. /*
  386. * ----------v----------v----------v----------v-----
  387. * NOTE: MUST BE WRITTEN AFTER UARTLCR_M & UARTLCR_L
  388. * ----------^----------^----------^----------^-----
  389. */
  390. writel(lcr_h, port->membase + UART010_LCRH);
  391. writel(old_cr, port->membase + UART010_CR);
  392. spin_unlock_irqrestore(&port->lock, flags);
  393. }
  394. static const char *pl010_type(struct uart_port *port)
  395. {
  396. return port->type == PORT_AMBA ? "AMBA" : NULL;
  397. }
  398. /*
  399. * Release the memory region(s) being used by 'port'
  400. */
  401. static void pl010_release_port(struct uart_port *port)
  402. {
  403. release_mem_region(port->mapbase, UART_PORT_SIZE);
  404. }
  405. /*
  406. * Request the memory region(s) being used by 'port'
  407. */
  408. static int pl010_request_port(struct uart_port *port)
  409. {
  410. return request_mem_region(port->mapbase, UART_PORT_SIZE, "uart-pl010")
  411. != NULL ? 0 : -EBUSY;
  412. }
  413. /*
  414. * Configure/autoconfigure the port.
  415. */
  416. static void pl010_config_port(struct uart_port *port, int flags)
  417. {
  418. if (flags & UART_CONFIG_TYPE) {
  419. port->type = PORT_AMBA;
  420. pl010_request_port(port);
  421. }
  422. }
  423. /*
  424. * verify the new serial_struct (for TIOCSSERIAL).
  425. */
  426. static int pl010_verify_port(struct uart_port *port, struct serial_struct *ser)
  427. {
  428. int ret = 0;
  429. if (ser->type != PORT_UNKNOWN && ser->type != PORT_AMBA)
  430. ret = -EINVAL;
  431. if (ser->irq < 0 || ser->irq >= NR_IRQS)
  432. ret = -EINVAL;
  433. if (ser->baud_base < 9600)
  434. ret = -EINVAL;
  435. return ret;
  436. }
  437. static struct uart_ops amba_pl010_pops = {
  438. .tx_empty = pl010_tx_empty,
  439. .set_mctrl = pl010_set_mctrl,
  440. .get_mctrl = pl010_get_mctrl,
  441. .stop_tx = pl010_stop_tx,
  442. .start_tx = pl010_start_tx,
  443. .stop_rx = pl010_stop_rx,
  444. .enable_ms = pl010_enable_ms,
  445. .break_ctl = pl010_break_ctl,
  446. .startup = pl010_startup,
  447. .shutdown = pl010_shutdown,
  448. .set_termios = pl010_set_termios,
  449. .type = pl010_type,
  450. .release_port = pl010_release_port,
  451. .request_port = pl010_request_port,
  452. .config_port = pl010_config_port,
  453. .verify_port = pl010_verify_port,
  454. };
  455. static struct uart_amba_port amba_ports[UART_NR] = {
  456. {
  457. .port = {
  458. .membase = (void *)IO_ADDRESS(INTEGRATOR_UART0_BASE),
  459. .mapbase = INTEGRATOR_UART0_BASE,
  460. .iotype = UPIO_MEM,
  461. .irq = IRQ_UARTINT0,
  462. .uartclk = 14745600,
  463. .fifosize = 16,
  464. .ops = &amba_pl010_pops,
  465. .flags = UPF_BOOT_AUTOCONF,
  466. .line = 0,
  467. },
  468. .dtr_mask = 1 << 5,
  469. .rts_mask = 1 << 4,
  470. },
  471. {
  472. .port = {
  473. .membase = (void *)IO_ADDRESS(INTEGRATOR_UART1_BASE),
  474. .mapbase = INTEGRATOR_UART1_BASE,
  475. .iotype = UPIO_MEM,
  476. .irq = IRQ_UARTINT1,
  477. .uartclk = 14745600,
  478. .fifosize = 16,
  479. .ops = &amba_pl010_pops,
  480. .flags = UPF_BOOT_AUTOCONF,
  481. .line = 1,
  482. },
  483. .dtr_mask = 1 << 7,
  484. .rts_mask = 1 << 6,
  485. }
  486. };
  487. #ifdef CONFIG_SERIAL_AMBA_PL010_CONSOLE
  488. static void pl010_console_putchar(struct uart_port *port, int ch)
  489. {
  490. unsigned int status;
  491. do {
  492. status = readb(port->membase + UART01x_FR);
  493. barrier();
  494. } while (!UART_TX_READY(status));
  495. writel(ch, port->membase + UART01x_DR);
  496. }
  497. static void
  498. pl010_console_write(struct console *co, const char *s, unsigned int count)
  499. {
  500. struct uart_port *port = &amba_ports[co->index].port;
  501. unsigned int status, old_cr;
  502. /*
  503. * First save the CR then disable the interrupts
  504. */
  505. old_cr = readb(port->membase + UART010_CR);
  506. writel(UART01x_CR_UARTEN, port->membase + UART010_CR);
  507. uart_console_write(port, s, count, pl010_console_putchar);
  508. /*
  509. * Finally, wait for transmitter to become empty
  510. * and restore the TCR
  511. */
  512. do {
  513. status = readb(port->membase + UART01x_FR);
  514. barrier();
  515. } while (status & UART01x_FR_BUSY);
  516. writel(old_cr, port->membase + UART010_CR);
  517. }
  518. static void __init
  519. pl010_console_get_options(struct uart_port *port, int *baud,
  520. int *parity, int *bits)
  521. {
  522. if (readb(port->membase + UART010_CR) & UART01x_CR_UARTEN) {
  523. unsigned int lcr_h, quot;
  524. lcr_h = readb(port->membase + UART010_LCRH);
  525. *parity = 'n';
  526. if (lcr_h & UART01x_LCRH_PEN) {
  527. if (lcr_h & UART01x_LCRH_EPS)
  528. *parity = 'e';
  529. else
  530. *parity = 'o';
  531. }
  532. if ((lcr_h & 0x60) == UART01x_LCRH_WLEN_7)
  533. *bits = 7;
  534. else
  535. *bits = 8;
  536. quot = readb(port->membase + UART010_LCRL) | readb(port->membase + UART010_LCRM) << 8;
  537. *baud = port->uartclk / (16 * (quot + 1));
  538. }
  539. }
  540. static int __init pl010_console_setup(struct console *co, char *options)
  541. {
  542. struct uart_port *port;
  543. int baud = 38400;
  544. int bits = 8;
  545. int parity = 'n';
  546. int flow = 'n';
  547. /*
  548. * Check whether an invalid uart number has been specified, and
  549. * if so, search for the first available port that does have
  550. * console support.
  551. */
  552. if (co->index >= UART_NR)
  553. co->index = 0;
  554. port = &amba_ports[co->index].port;
  555. if (options)
  556. uart_parse_options(options, &baud, &parity, &bits, &flow);
  557. else
  558. pl010_console_get_options(port, &baud, &parity, &bits);
  559. return uart_set_options(port, co, baud, parity, bits, flow);
  560. }
  561. static struct uart_driver amba_reg;
  562. static struct console amba_console = {
  563. .name = "ttyAM",
  564. .write = pl010_console_write,
  565. .device = uart_console_device,
  566. .setup = pl010_console_setup,
  567. .flags = CON_PRINTBUFFER,
  568. .index = -1,
  569. .data = &amba_reg,
  570. };
  571. static int __init amba_console_init(void)
  572. {
  573. /*
  574. * All port initializations are done statically
  575. */
  576. register_console(&amba_console);
  577. return 0;
  578. }
  579. console_initcall(amba_console_init);
  580. static int __init amba_late_console_init(void)
  581. {
  582. if (!(amba_console.flags & CON_ENABLED))
  583. register_console(&amba_console);
  584. return 0;
  585. }
  586. late_initcall(amba_late_console_init);
  587. #define AMBA_CONSOLE &amba_console
  588. #else
  589. #define AMBA_CONSOLE NULL
  590. #endif
  591. static struct uart_driver amba_reg = {
  592. .owner = THIS_MODULE,
  593. .driver_name = "ttyAM",
  594. .dev_name = "ttyAM",
  595. .major = SERIAL_AMBA_MAJOR,
  596. .minor = SERIAL_AMBA_MINOR,
  597. .nr = UART_NR,
  598. .cons = AMBA_CONSOLE,
  599. };
  600. static int pl010_probe(struct amba_device *dev, void *id)
  601. {
  602. int i;
  603. for (i = 0; i < UART_NR; i++) {
  604. if (amba_ports[i].port.mapbase != dev->res.start)
  605. continue;
  606. amba_ports[i].port.dev = &dev->dev;
  607. uart_add_one_port(&amba_reg, &amba_ports[i].port);
  608. amba_set_drvdata(dev, &amba_ports[i]);
  609. break;
  610. }
  611. return 0;
  612. }
  613. static int pl010_remove(struct amba_device *dev)
  614. {
  615. struct uart_amba_port *uap = amba_get_drvdata(dev);
  616. if (uap)
  617. uart_remove_one_port(&amba_reg, &uap->port);
  618. amba_set_drvdata(dev, NULL);
  619. return 0;
  620. }
  621. static int pl010_suspend(struct amba_device *dev, pm_message_t state)
  622. {
  623. struct uart_amba_port *uap = amba_get_drvdata(dev);
  624. if (uap)
  625. uart_suspend_port(&amba_reg, &uap->port);
  626. return 0;
  627. }
  628. static int pl010_resume(struct amba_device *dev)
  629. {
  630. struct uart_amba_port *uap = amba_get_drvdata(dev);
  631. if (uap)
  632. uart_resume_port(&amba_reg, &uap->port);
  633. return 0;
  634. }
  635. static struct amba_id pl010_ids[] __initdata = {
  636. {
  637. .id = 0x00041010,
  638. .mask = 0x000fffff,
  639. },
  640. { 0, 0 },
  641. };
  642. static struct amba_driver pl010_driver = {
  643. .drv = {
  644. .name = "uart-pl010",
  645. },
  646. .id_table = pl010_ids,
  647. .probe = pl010_probe,
  648. .remove = pl010_remove,
  649. .suspend = pl010_suspend,
  650. .resume = pl010_resume,
  651. };
  652. static int __init pl010_init(void)
  653. {
  654. int ret;
  655. printk(KERN_INFO "Serial: AMBA driver $Revision: 1.41 $\n");
  656. ret = uart_register_driver(&amba_reg);
  657. if (ret == 0) {
  658. ret = amba_driver_register(&pl010_driver);
  659. if (ret)
  660. uart_unregister_driver(&amba_reg);
  661. }
  662. return ret;
  663. }
  664. static void __exit pl010_exit(void)
  665. {
  666. amba_driver_unregister(&pl010_driver);
  667. uart_unregister_driver(&amba_reg);
  668. }
  669. module_init(pl010_init);
  670. module_exit(pl010_exit);
  671. MODULE_AUTHOR("ARM Ltd/Deep Blue Solutions Ltd");
  672. MODULE_DESCRIPTION("ARM AMBA serial port driver $Revision: 1.41 $");
  673. MODULE_LICENSE("GPL");