dm writecache: add cond_resched to loop in persistent_memory_claim()
[linux/fpc-iii.git] / drivers / tty / serial / amba-pl010.c
blob3284f34e9dfe145036d60a16ba63351eb84ed15f
1 // SPDX-License-Identifier: GPL-2.0+
2 /*
3 * Driver for AMBA serial ports
5 * Based on drivers/char/serial.c, by Linus Torvalds, Theodore Ts'o.
7 * Copyright 1999 ARM Limited
8 * Copyright (C) 2000 Deep Blue Solutions Ltd.
10 * This is a generic driver for ARM AMBA-type serial ports. They
11 * have a lot of 16550-like features, but are not register compatible.
12 * Note that although they do have CTS, DCD and DSR inputs, they do
13 * not have an RI input, nor do they have DTR or RTS outputs. If
14 * required, these have to be supplied via some other means (eg, GPIO)
15 * and hooked into this driver.
18 #include <linux/module.h>
19 #include <linux/ioport.h>
20 #include <linux/init.h>
21 #include <linux/console.h>
22 #include <linux/sysrq.h>
23 #include <linux/device.h>
24 #include <linux/tty.h>
25 #include <linux/tty_flip.h>
26 #include <linux/serial_core.h>
27 #include <linux/serial.h>
28 #include <linux/amba/bus.h>
29 #include <linux/amba/serial.h>
30 #include <linux/clk.h>
31 #include <linux/slab.h>
32 #include <linux/io.h>
34 #define UART_NR 8
36 #define SERIAL_AMBA_MAJOR 204
37 #define SERIAL_AMBA_MINOR 16
38 #define SERIAL_AMBA_NR UART_NR
40 #define AMBA_ISR_PASS_LIMIT 256
42 #define UART_RX_DATA(s) (((s) & UART01x_FR_RXFE) == 0)
43 #define UART_TX_READY(s) (((s) & UART01x_FR_TXFF) == 0)
45 #define UART_DUMMY_RSR_RX 256
46 #define UART_PORT_SIZE 64
49 * We wrap our port structure around the generic uart_port.
51 struct uart_amba_port {
52 struct uart_port port;
53 struct clk *clk;
54 struct amba_device *dev;
55 struct amba_pl010_data *data;
56 unsigned int old_status;
59 static void pl010_stop_tx(struct uart_port *port)
61 struct uart_amba_port *uap =
62 container_of(port, struct uart_amba_port, port);
63 unsigned int cr;
65 cr = readb(uap->port.membase + UART010_CR);
66 cr &= ~UART010_CR_TIE;
67 writel(cr, uap->port.membase + UART010_CR);
70 static void pl010_start_tx(struct uart_port *port)
72 struct uart_amba_port *uap =
73 container_of(port, struct uart_amba_port, port);
74 unsigned int cr;
76 cr = readb(uap->port.membase + UART010_CR);
77 cr |= UART010_CR_TIE;
78 writel(cr, uap->port.membase + UART010_CR);
81 static void pl010_stop_rx(struct uart_port *port)
83 struct uart_amba_port *uap =
84 container_of(port, struct uart_amba_port, port);
85 unsigned int cr;
87 cr = readb(uap->port.membase + UART010_CR);
88 cr &= ~(UART010_CR_RIE | UART010_CR_RTIE);
89 writel(cr, uap->port.membase + UART010_CR);
92 static void pl010_disable_ms(struct uart_port *port)
94 struct uart_amba_port *uap = (struct uart_amba_port *)port;
95 unsigned int cr;
97 cr = readb(uap->port.membase + UART010_CR);
98 cr &= ~UART010_CR_MSIE;
99 writel(cr, uap->port.membase + UART010_CR);
102 static void pl010_enable_ms(struct uart_port *port)
104 struct uart_amba_port *uap =
105 container_of(port, struct uart_amba_port, port);
106 unsigned int cr;
108 cr = readb(uap->port.membase + UART010_CR);
109 cr |= UART010_CR_MSIE;
110 writel(cr, uap->port.membase + UART010_CR);
113 static void pl010_rx_chars(struct uart_amba_port *uap)
115 unsigned int status, ch, flag, rsr, max_count = 256;
117 status = readb(uap->port.membase + UART01x_FR);
118 while (UART_RX_DATA(status) && max_count--) {
119 ch = readb(uap->port.membase + UART01x_DR);
120 flag = TTY_NORMAL;
122 uap->port.icount.rx++;
125 * Note that the error handling code is
126 * out of the main execution path
128 rsr = readb(uap->port.membase + UART01x_RSR) | UART_DUMMY_RSR_RX;
129 if (unlikely(rsr & UART01x_RSR_ANY)) {
130 writel(0, uap->port.membase + UART01x_ECR);
132 if (rsr & UART01x_RSR_BE) {
133 rsr &= ~(UART01x_RSR_FE | UART01x_RSR_PE);
134 uap->port.icount.brk++;
135 if (uart_handle_break(&uap->port))
136 goto ignore_char;
137 } else if (rsr & UART01x_RSR_PE)
138 uap->port.icount.parity++;
139 else if (rsr & UART01x_RSR_FE)
140 uap->port.icount.frame++;
141 if (rsr & UART01x_RSR_OE)
142 uap->port.icount.overrun++;
144 rsr &= uap->port.read_status_mask;
146 if (rsr & UART01x_RSR_BE)
147 flag = TTY_BREAK;
148 else if (rsr & UART01x_RSR_PE)
149 flag = TTY_PARITY;
150 else if (rsr & UART01x_RSR_FE)
151 flag = TTY_FRAME;
154 if (uart_handle_sysrq_char(&uap->port, ch))
155 goto ignore_char;
157 uart_insert_char(&uap->port, rsr, UART01x_RSR_OE, ch, flag);
159 ignore_char:
160 status = readb(uap->port.membase + UART01x_FR);
162 spin_unlock(&uap->port.lock);
163 tty_flip_buffer_push(&uap->port.state->port);
164 spin_lock(&uap->port.lock);
167 static void pl010_tx_chars(struct uart_amba_port *uap)
169 struct circ_buf *xmit = &uap->port.state->xmit;
170 int count;
172 if (uap->port.x_char) {
173 writel(uap->port.x_char, uap->port.membase + UART01x_DR);
174 uap->port.icount.tx++;
175 uap->port.x_char = 0;
176 return;
178 if (uart_circ_empty(xmit) || uart_tx_stopped(&uap->port)) {
179 pl010_stop_tx(&uap->port);
180 return;
183 count = uap->port.fifosize >> 1;
184 do {
185 writel(xmit->buf[xmit->tail], uap->port.membase + UART01x_DR);
186 xmit->tail = (xmit->tail + 1) & (UART_XMIT_SIZE - 1);
187 uap->port.icount.tx++;
188 if (uart_circ_empty(xmit))
189 break;
190 } while (--count > 0);
192 if (uart_circ_chars_pending(xmit) < WAKEUP_CHARS)
193 uart_write_wakeup(&uap->port);
195 if (uart_circ_empty(xmit))
196 pl010_stop_tx(&uap->port);
199 static void pl010_modem_status(struct uart_amba_port *uap)
201 unsigned int status, delta;
203 writel(0, uap->port.membase + UART010_ICR);
205 status = readb(uap->port.membase + UART01x_FR) & UART01x_FR_MODEM_ANY;
207 delta = status ^ uap->old_status;
208 uap->old_status = status;
210 if (!delta)
211 return;
213 if (delta & UART01x_FR_DCD)
214 uart_handle_dcd_change(&uap->port, status & UART01x_FR_DCD);
216 if (delta & UART01x_FR_DSR)
217 uap->port.icount.dsr++;
219 if (delta & UART01x_FR_CTS)
220 uart_handle_cts_change(&uap->port, status & UART01x_FR_CTS);
222 wake_up_interruptible(&uap->port.state->port.delta_msr_wait);
225 static irqreturn_t pl010_int(int irq, void *dev_id)
227 struct uart_amba_port *uap = dev_id;
228 unsigned int status, pass_counter = AMBA_ISR_PASS_LIMIT;
229 int handled = 0;
231 spin_lock(&uap->port.lock);
233 status = readb(uap->port.membase + UART010_IIR);
234 if (status) {
235 do {
236 if (status & (UART010_IIR_RTIS | UART010_IIR_RIS))
237 pl010_rx_chars(uap);
238 if (status & UART010_IIR_MIS)
239 pl010_modem_status(uap);
240 if (status & UART010_IIR_TIS)
241 pl010_tx_chars(uap);
243 if (pass_counter-- == 0)
244 break;
246 status = readb(uap->port.membase + UART010_IIR);
247 } while (status & (UART010_IIR_RTIS | UART010_IIR_RIS |
248 UART010_IIR_TIS));
249 handled = 1;
252 spin_unlock(&uap->port.lock);
254 return IRQ_RETVAL(handled);
257 static unsigned int pl010_tx_empty(struct uart_port *port)
259 struct uart_amba_port *uap =
260 container_of(port, struct uart_amba_port, port);
261 unsigned int status = readb(uap->port.membase + UART01x_FR);
262 return status & UART01x_FR_BUSY ? 0 : TIOCSER_TEMT;
265 static unsigned int pl010_get_mctrl(struct uart_port *port)
267 struct uart_amba_port *uap =
268 container_of(port, struct uart_amba_port, port);
269 unsigned int result = 0;
270 unsigned int status;
272 status = readb(uap->port.membase + UART01x_FR);
273 if (status & UART01x_FR_DCD)
274 result |= TIOCM_CAR;
275 if (status & UART01x_FR_DSR)
276 result |= TIOCM_DSR;
277 if (status & UART01x_FR_CTS)
278 result |= TIOCM_CTS;
280 return result;
283 static void pl010_set_mctrl(struct uart_port *port, unsigned int mctrl)
285 struct uart_amba_port *uap =
286 container_of(port, struct uart_amba_port, port);
288 if (uap->data)
289 uap->data->set_mctrl(uap->dev, uap->port.membase, mctrl);
292 static void pl010_break_ctl(struct uart_port *port, int break_state)
294 struct uart_amba_port *uap =
295 container_of(port, struct uart_amba_port, port);
296 unsigned long flags;
297 unsigned int lcr_h;
299 spin_lock_irqsave(&uap->port.lock, flags);
300 lcr_h = readb(uap->port.membase + UART010_LCRH);
301 if (break_state == -1)
302 lcr_h |= UART01x_LCRH_BRK;
303 else
304 lcr_h &= ~UART01x_LCRH_BRK;
305 writel(lcr_h, uap->port.membase + UART010_LCRH);
306 spin_unlock_irqrestore(&uap->port.lock, flags);
309 static int pl010_startup(struct uart_port *port)
311 struct uart_amba_port *uap =
312 container_of(port, struct uart_amba_port, port);
313 int retval;
316 * Try to enable the clock producer.
318 retval = clk_prepare_enable(uap->clk);
319 if (retval)
320 goto out;
322 uap->port.uartclk = clk_get_rate(uap->clk);
325 * Allocate the IRQ
327 retval = request_irq(uap->port.irq, pl010_int, 0, "uart-pl010", uap);
328 if (retval)
329 goto clk_dis;
332 * initialise the old status of the modem signals
334 uap->old_status = readb(uap->port.membase + UART01x_FR) & UART01x_FR_MODEM_ANY;
337 * Finally, enable interrupts
339 writel(UART01x_CR_UARTEN | UART010_CR_RIE | UART010_CR_RTIE,
340 uap->port.membase + UART010_CR);
342 return 0;
344 clk_dis:
345 clk_disable_unprepare(uap->clk);
346 out:
347 return retval;
350 static void pl010_shutdown(struct uart_port *port)
352 struct uart_amba_port *uap =
353 container_of(port, struct uart_amba_port, port);
356 * Free the interrupt
358 free_irq(uap->port.irq, uap);
361 * disable all interrupts, disable the port
363 writel(0, uap->port.membase + UART010_CR);
365 /* disable break condition and fifos */
366 writel(readb(uap->port.membase + UART010_LCRH) &
367 ~(UART01x_LCRH_BRK | UART01x_LCRH_FEN),
368 uap->port.membase + UART010_LCRH);
371 * Shut down the clock producer
373 clk_disable_unprepare(uap->clk);
376 static void
377 pl010_set_termios(struct uart_port *port, struct ktermios *termios,
378 struct ktermios *old)
380 struct uart_amba_port *uap =
381 container_of(port, struct uart_amba_port, port);
382 unsigned int lcr_h, old_cr;
383 unsigned long flags;
384 unsigned int baud, quot;
387 * Ask the core to calculate the divisor for us.
389 baud = uart_get_baud_rate(port, termios, old, 0, uap->port.uartclk/16);
390 quot = uart_get_divisor(port, baud);
392 switch (termios->c_cflag & CSIZE) {
393 case CS5:
394 lcr_h = UART01x_LCRH_WLEN_5;
395 break;
396 case CS6:
397 lcr_h = UART01x_LCRH_WLEN_6;
398 break;
399 case CS7:
400 lcr_h = UART01x_LCRH_WLEN_7;
401 break;
402 default: // CS8
403 lcr_h = UART01x_LCRH_WLEN_8;
404 break;
406 if (termios->c_cflag & CSTOPB)
407 lcr_h |= UART01x_LCRH_STP2;
408 if (termios->c_cflag & PARENB) {
409 lcr_h |= UART01x_LCRH_PEN;
410 if (!(termios->c_cflag & PARODD))
411 lcr_h |= UART01x_LCRH_EPS;
413 if (uap->port.fifosize > 1)
414 lcr_h |= UART01x_LCRH_FEN;
416 spin_lock_irqsave(&uap->port.lock, flags);
419 * Update the per-port timeout.
421 uart_update_timeout(port, termios->c_cflag, baud);
423 uap->port.read_status_mask = UART01x_RSR_OE;
424 if (termios->c_iflag & INPCK)
425 uap->port.read_status_mask |= UART01x_RSR_FE | UART01x_RSR_PE;
426 if (termios->c_iflag & (IGNBRK | BRKINT | PARMRK))
427 uap->port.read_status_mask |= UART01x_RSR_BE;
430 * Characters to ignore
432 uap->port.ignore_status_mask = 0;
433 if (termios->c_iflag & IGNPAR)
434 uap->port.ignore_status_mask |= UART01x_RSR_FE | UART01x_RSR_PE;
435 if (termios->c_iflag & IGNBRK) {
436 uap->port.ignore_status_mask |= UART01x_RSR_BE;
438 * If we're ignoring parity and break indicators,
439 * ignore overruns too (for real raw support).
441 if (termios->c_iflag & IGNPAR)
442 uap->port.ignore_status_mask |= UART01x_RSR_OE;
446 * Ignore all characters if CREAD is not set.
448 if ((termios->c_cflag & CREAD) == 0)
449 uap->port.ignore_status_mask |= UART_DUMMY_RSR_RX;
451 /* first, disable everything */
452 old_cr = readb(uap->port.membase + UART010_CR) & ~UART010_CR_MSIE;
454 if (UART_ENABLE_MS(port, termios->c_cflag))
455 old_cr |= UART010_CR_MSIE;
457 writel(0, uap->port.membase + UART010_CR);
459 /* Set baud rate */
460 quot -= 1;
461 writel((quot & 0xf00) >> 8, uap->port.membase + UART010_LCRM);
462 writel(quot & 0xff, uap->port.membase + UART010_LCRL);
465 * ----------v----------v----------v----------v-----
466 * NOTE: MUST BE WRITTEN AFTER UARTLCR_M & UARTLCR_L
467 * ----------^----------^----------^----------^-----
469 writel(lcr_h, uap->port.membase + UART010_LCRH);
470 writel(old_cr, uap->port.membase + UART010_CR);
472 spin_unlock_irqrestore(&uap->port.lock, flags);
475 static void pl010_set_ldisc(struct uart_port *port, struct ktermios *termios)
477 if (termios->c_line == N_PPS) {
478 port->flags |= UPF_HARDPPS_CD;
479 spin_lock_irq(&port->lock);
480 pl010_enable_ms(port);
481 spin_unlock_irq(&port->lock);
482 } else {
483 port->flags &= ~UPF_HARDPPS_CD;
484 if (!UART_ENABLE_MS(port, termios->c_cflag)) {
485 spin_lock_irq(&port->lock);
486 pl010_disable_ms(port);
487 spin_unlock_irq(&port->lock);
492 static const char *pl010_type(struct uart_port *port)
494 return port->type == PORT_AMBA ? "AMBA" : NULL;
498 * Release the memory region(s) being used by 'port'
500 static void pl010_release_port(struct uart_port *port)
502 release_mem_region(port->mapbase, UART_PORT_SIZE);
506 * Request the memory region(s) being used by 'port'
508 static int pl010_request_port(struct uart_port *port)
510 return request_mem_region(port->mapbase, UART_PORT_SIZE, "uart-pl010")
511 != NULL ? 0 : -EBUSY;
515 * Configure/autoconfigure the port.
517 static void pl010_config_port(struct uart_port *port, int flags)
519 if (flags & UART_CONFIG_TYPE) {
520 port->type = PORT_AMBA;
521 pl010_request_port(port);
526 * verify the new serial_struct (for TIOCSSERIAL).
528 static int pl010_verify_port(struct uart_port *port, struct serial_struct *ser)
530 int ret = 0;
531 if (ser->type != PORT_UNKNOWN && ser->type != PORT_AMBA)
532 ret = -EINVAL;
533 if (ser->irq < 0 || ser->irq >= nr_irqs)
534 ret = -EINVAL;
535 if (ser->baud_base < 9600)
536 ret = -EINVAL;
537 return ret;
540 static const struct uart_ops amba_pl010_pops = {
541 .tx_empty = pl010_tx_empty,
542 .set_mctrl = pl010_set_mctrl,
543 .get_mctrl = pl010_get_mctrl,
544 .stop_tx = pl010_stop_tx,
545 .start_tx = pl010_start_tx,
546 .stop_rx = pl010_stop_rx,
547 .enable_ms = pl010_enable_ms,
548 .break_ctl = pl010_break_ctl,
549 .startup = pl010_startup,
550 .shutdown = pl010_shutdown,
551 .set_termios = pl010_set_termios,
552 .set_ldisc = pl010_set_ldisc,
553 .type = pl010_type,
554 .release_port = pl010_release_port,
555 .request_port = pl010_request_port,
556 .config_port = pl010_config_port,
557 .verify_port = pl010_verify_port,
560 static struct uart_amba_port *amba_ports[UART_NR];
562 #ifdef CONFIG_SERIAL_AMBA_PL010_CONSOLE
564 static void pl010_console_putchar(struct uart_port *port, int ch)
566 struct uart_amba_port *uap =
567 container_of(port, struct uart_amba_port, port);
568 unsigned int status;
570 do {
571 status = readb(uap->port.membase + UART01x_FR);
572 barrier();
573 } while (!UART_TX_READY(status));
574 writel(ch, uap->port.membase + UART01x_DR);
577 static void
578 pl010_console_write(struct console *co, const char *s, unsigned int count)
580 struct uart_amba_port *uap = amba_ports[co->index];
581 unsigned int status, old_cr;
583 clk_enable(uap->clk);
586 * First save the CR then disable the interrupts
588 old_cr = readb(uap->port.membase + UART010_CR);
589 writel(UART01x_CR_UARTEN, uap->port.membase + UART010_CR);
591 uart_console_write(&uap->port, s, count, pl010_console_putchar);
594 * Finally, wait for transmitter to become empty
595 * and restore the TCR
597 do {
598 status = readb(uap->port.membase + UART01x_FR);
599 barrier();
600 } while (status & UART01x_FR_BUSY);
601 writel(old_cr, uap->port.membase + UART010_CR);
603 clk_disable(uap->clk);
606 static void __init
607 pl010_console_get_options(struct uart_amba_port *uap, int *baud,
608 int *parity, int *bits)
610 if (readb(uap->port.membase + UART010_CR) & UART01x_CR_UARTEN) {
611 unsigned int lcr_h, quot;
612 lcr_h = readb(uap->port.membase + UART010_LCRH);
614 *parity = 'n';
615 if (lcr_h & UART01x_LCRH_PEN) {
616 if (lcr_h & UART01x_LCRH_EPS)
617 *parity = 'e';
618 else
619 *parity = 'o';
622 if ((lcr_h & 0x60) == UART01x_LCRH_WLEN_7)
623 *bits = 7;
624 else
625 *bits = 8;
627 quot = readb(uap->port.membase + UART010_LCRL) |
628 readb(uap->port.membase + UART010_LCRM) << 8;
629 *baud = uap->port.uartclk / (16 * (quot + 1));
633 static int __init pl010_console_setup(struct console *co, char *options)
635 struct uart_amba_port *uap;
636 int baud = 38400;
637 int bits = 8;
638 int parity = 'n';
639 int flow = 'n';
640 int ret;
643 * Check whether an invalid uart number has been specified, and
644 * if so, search for the first available port that does have
645 * console support.
647 if (co->index >= UART_NR)
648 co->index = 0;
649 uap = amba_ports[co->index];
650 if (!uap)
651 return -ENODEV;
653 ret = clk_prepare(uap->clk);
654 if (ret)
655 return ret;
657 uap->port.uartclk = clk_get_rate(uap->clk);
659 if (options)
660 uart_parse_options(options, &baud, &parity, &bits, &flow);
661 else
662 pl010_console_get_options(uap, &baud, &parity, &bits);
664 return uart_set_options(&uap->port, co, baud, parity, bits, flow);
667 static struct uart_driver amba_reg;
668 static struct console amba_console = {
669 .name = "ttyAM",
670 .write = pl010_console_write,
671 .device = uart_console_device,
672 .setup = pl010_console_setup,
673 .flags = CON_PRINTBUFFER,
674 .index = -1,
675 .data = &amba_reg,
678 #define AMBA_CONSOLE &amba_console
679 #else
680 #define AMBA_CONSOLE NULL
681 #endif
683 static DEFINE_MUTEX(amba_reg_lock);
684 static struct uart_driver amba_reg = {
685 .owner = THIS_MODULE,
686 .driver_name = "ttyAM",
687 .dev_name = "ttyAM",
688 .major = SERIAL_AMBA_MAJOR,
689 .minor = SERIAL_AMBA_MINOR,
690 .nr = UART_NR,
691 .cons = AMBA_CONSOLE,
694 static int pl010_probe(struct amba_device *dev, const struct amba_id *id)
696 struct uart_amba_port *uap;
697 void __iomem *base;
698 int i, ret;
700 for (i = 0; i < ARRAY_SIZE(amba_ports); i++)
701 if (amba_ports[i] == NULL)
702 break;
704 if (i == ARRAY_SIZE(amba_ports))
705 return -EBUSY;
707 uap = devm_kzalloc(&dev->dev, sizeof(struct uart_amba_port),
708 GFP_KERNEL);
709 if (!uap)
710 return -ENOMEM;
712 base = devm_ioremap(&dev->dev, dev->res.start,
713 resource_size(&dev->res));
714 if (!base)
715 return -ENOMEM;
717 uap->clk = devm_clk_get(&dev->dev, NULL);
718 if (IS_ERR(uap->clk))
719 return PTR_ERR(uap->clk);
721 uap->port.dev = &dev->dev;
722 uap->port.mapbase = dev->res.start;
723 uap->port.membase = base;
724 uap->port.iotype = UPIO_MEM;
725 uap->port.irq = dev->irq[0];
726 uap->port.fifosize = 16;
727 uap->port.has_sysrq = IS_ENABLED(CONFIG_SERIAL_AMBA_PL010_CONSOLE);
728 uap->port.ops = &amba_pl010_pops;
729 uap->port.flags = UPF_BOOT_AUTOCONF;
730 uap->port.line = i;
731 uap->dev = dev;
732 uap->data = dev_get_platdata(&dev->dev);
734 amba_ports[i] = uap;
736 amba_set_drvdata(dev, uap);
738 mutex_lock(&amba_reg_lock);
739 if (!amba_reg.state) {
740 ret = uart_register_driver(&amba_reg);
741 if (ret < 0) {
742 mutex_unlock(&amba_reg_lock);
743 dev_err(uap->port.dev,
744 "Failed to register AMBA-PL010 driver\n");
745 return ret;
748 mutex_unlock(&amba_reg_lock);
750 ret = uart_add_one_port(&amba_reg, &uap->port);
751 if (ret)
752 amba_ports[i] = NULL;
754 return ret;
757 static int pl010_remove(struct amba_device *dev)
759 struct uart_amba_port *uap = amba_get_drvdata(dev);
760 int i;
761 bool busy = false;
763 uart_remove_one_port(&amba_reg, &uap->port);
765 for (i = 0; i < ARRAY_SIZE(amba_ports); i++)
766 if (amba_ports[i] == uap)
767 amba_ports[i] = NULL;
768 else if (amba_ports[i])
769 busy = true;
771 if (!busy)
772 uart_unregister_driver(&amba_reg);
774 return 0;
777 #ifdef CONFIG_PM_SLEEP
778 static int pl010_suspend(struct device *dev)
780 struct uart_amba_port *uap = dev_get_drvdata(dev);
782 if (uap)
783 uart_suspend_port(&amba_reg, &uap->port);
785 return 0;
788 static int pl010_resume(struct device *dev)
790 struct uart_amba_port *uap = dev_get_drvdata(dev);
792 if (uap)
793 uart_resume_port(&amba_reg, &uap->port);
795 return 0;
797 #endif
799 static SIMPLE_DEV_PM_OPS(pl010_dev_pm_ops, pl010_suspend, pl010_resume);
801 static const struct amba_id pl010_ids[] = {
803 .id = 0x00041010,
804 .mask = 0x000fffff,
806 { 0, 0 },
809 MODULE_DEVICE_TABLE(amba, pl010_ids);
811 static struct amba_driver pl010_driver = {
812 .drv = {
813 .name = "uart-pl010",
814 .pm = &pl010_dev_pm_ops,
816 .id_table = pl010_ids,
817 .probe = pl010_probe,
818 .remove = pl010_remove,
821 static int __init pl010_init(void)
823 printk(KERN_INFO "Serial: AMBA driver\n");
825 return amba_driver_register(&pl010_driver);
828 static void __exit pl010_exit(void)
830 amba_driver_unregister(&pl010_driver);
833 module_init(pl010_init);
834 module_exit(pl010_exit);
836 MODULE_AUTHOR("ARM Ltd/Deep Blue Solutions Ltd");
837 MODULE_DESCRIPTION("ARM AMBA serial port driver");
838 MODULE_LICENSE("GPL");