amba-pl010.c 18 KB

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