amba-pl010.c 18 KB

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