Serial: LPC32xx_hsuart: Fix spinlock issues
[linux-2.6.34-lpc32xx.git] / drivers / serial / lpc32xx_hs.c
1 /*
2  * drivers/serial/lpc32xx_hs.c
3  *
4  * Author: Kevin Wells <kevin.wells@nxp.com>
5  *
6  * Copyright (C) 2010 NXP Semiconductors
7  *
8  * This program is free software; you can redistribute it and/or modify
9  * it under the terms of the GNU General Public License as published by
10  * the Free Software Foundation; either version 2 of the License, or
11  * (at your option) any later version.
12  *
13  * This program is distributed in the hope that it will be useful,
14  * but WITHOUT ANY WARRANTY; without even the implied warranty of
15  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
16  * GNU General Public License for more details.
17  */
18
19 #include <linux/module.h>
20 #include <linux/ioport.h>
21 #include <linux/init.h>
22 #include <linux/console.h>
23 #include <linux/sysrq.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/platform_device.h>
29 #include <linux/delay.h>
30 #include <linux/nmi.h>
31 #include <linux/io.h>
32 #include <linux/irq.h>
33
34 /*
35  * High speed UART register offsets
36  */
37 #define LPC32XX_HSUART_FIFO(x)                  (x + 0x00)
38 #define LPC32XX_HSUART_LEVEL(x)                 (x + 0x04)
39 #define LPC32XX_HSUART_IIR(x)                   (x + 0x08)
40 #define LPC32XX_HSUART_CTRL(x)                  (x + 0x0C)
41 #define LPC32XX_HSUART_RATE(x)                  (x + 0x10)
42
43 #define LPC32XX_HSU_BREAK_DATA                  (1 << 10)
44 #define LPC32XX_HSU_ERROR_DATA                  (1 << 9)
45 #define LPC32XX_HSU_RX_EMPTY                    (1 << 8)
46
47 #define LPC32XX_HSU_TX_LEV(n)                   (((n) >> 8) & 0xFF)
48 #define LPC32XX_HSU_RX_LEV(n)                   ((n) & 0xFF)
49
50 #define LPC32XX_HSU_TX_INT_SET                  (1 << 6)
51 #define LPC32XX_HSU_RX_OE_INT                   (1 << 5)
52 #define LPC32XX_HSU_BRK_INT                     (1 << 4)
53 #define LPC32XX_HSU_FE_INT                      (1 << 3)
54 #define LPC32XX_HSU_RX_TIMEOUT_INT              (1 << 2)
55 #define LPC32XX_HSU_RX_TRIG_INT                 (1 << 1)
56 #define LPC32XX_HSU_TX_INT                      (1 << 0)
57
58 #define LPC32XX_HSU_HRTS_INV                    (1 << 21)
59 #define LPC32XX_HSU_HRTS_TRIG_8B                (0x0 << 19)
60 #define LPC32XX_HSU_HRTS_TRIG_16B               (0x1 << 19)
61 #define LPC32XX_HSU_HRTS_TRIG_32B               (0x2 << 19)
62 #define LPC32XX_HSU_HRTS_TRIG_48B               (0x3 << 19)
63 #define LPC32XX_HSU_HRTS_EN                     (1 << 18)
64 #define LPC32XX_HSU_TMO_DISABLED                (0x0 << 16)
65 #define LPC32XX_HSU_TMO_INACT_4B                (0x1 << 16)
66 #define LPC32XX_HSU_TMO_INACT_8B                (0x2 << 16)
67 #define LPC32XX_HSU_TMO_INACT_16B               (0x3 << 16)
68 #define LPC32XX_HSU_HCTS_INV                    (1 << 15)
69 #define LPC32XX_HSU_HCTS_EN                     (1 << 14)
70 #define LPC32XX_HSU_OFFSET(n)                   ((n) << 9)
71 #define LPC32XX_HSU_BREAK                       (1 << 8)
72 #define LPC32XX_HSU_ERR_INT_EN                  (1 << 7)
73 #define LPC32XX_HSU_RX_INT_EN                   (1 << 6)
74 #define LPC32XX_HSU_TX_INT_EN                   (1 << 5)
75 #define LPC32XX_HSU_RX_TL1B                     (0x0 << 2)
76 #define LPC32XX_HSU_RX_TL4B                     (0x1 << 2)
77 #define LPC32XX_HSU_RX_TL8B                     (0x2 << 2)
78 #define LPC32XX_HSU_RX_TL16B                    (0x3 << 2)
79 #define LPC32XX_HSU_RX_TL32B                    (0x4 << 2)
80 #define LPC32XX_HSU_RX_TL48B                    (0x5 << 2)
81 #define LPC32XX_HSU_TX_TLEMPTY                  (0x0 << 0)
82 #define LPC32XX_HSU_TX_TL0B                     (0x0 << 0)
83 #define LPC32XX_HSU_TX_TL4B                     (0x1 << 0)
84 #define LPC32XX_HSU_TX_TL8B                     (0x2 << 0)
85 #define LPC32XX_HSU_TX_TL16B                    (0x3 << 0)
86
87 #define MODNAME "lpc32xx_hsuart"
88
89 struct lpc32xx_hsuart_port {
90         struct uart_port port;
91 };
92
93 #define FIFO_READ_LIMIT 128
94 #define MAX_PORTS 3
95 #define LPC32XX_TTY_NAME "ttyTX"
96 #define LPC32XX_TTY_MINOR_START 196
97 #define LPC32XX_TTY_MAJOR 204
98 static struct lpc32xx_hsuart_port lpc32xx_hs_ports[MAX_PORTS];
99
100 #ifdef CONFIG_SERIAL_HS_LPC32XX_CONSOLE
101 static void wait_for_xmit_empty(struct uart_port *port)
102 {
103         unsigned int timeout = 10000;
104
105         do {
106                 if (LPC32XX_HSU_TX_LEV(__raw_readl(LPC32XX_HSUART_LEVEL(
107                         port->membase))) == 0)
108                         break;
109                 if (--timeout == 0)
110                         break;
111                 udelay(1);
112         } while (1);
113 }
114
115 static void wait_for_xmit_ready(struct uart_port *port)
116 {
117         unsigned int timeout = 10000;
118
119         while (1) {
120                 if (LPC32XX_HSU_TX_LEV(__raw_readl(LPC32XX_HSUART_LEVEL(
121                         port->membase))) < 32)
122                         break;
123                 if (--timeout == 0)
124                         break;
125                 udelay(1);
126         }
127 }
128
129 static void lpc32xx_hsuart_console_putchar(struct uart_port *port, int ch)
130 {
131         wait_for_xmit_ready(port);
132         __raw_writel((u32) ch, LPC32XX_HSUART_FIFO(port->membase));
133 }
134
135 static void lpc32xx_hsuart_console_write(struct console *co, const char *s,
136         unsigned int count) {
137         struct lpc32xx_hsuart_port *up = &lpc32xx_hs_ports[co->index];
138         unsigned long flags;
139         int locked = 1;
140
141         touch_nmi_watchdog();
142         local_irq_save(flags);
143         if (up->port.sysrq)
144                 locked = 0;
145         else if (oops_in_progress)
146                 locked = spin_trylock(&up->port.lock);
147         else
148                 spin_lock(&up->port.lock);
149
150         uart_console_write(&up->port, s, count,
151                 lpc32xx_hsuart_console_putchar);
152         wait_for_xmit_empty(&up->port);
153
154         if (locked)
155                 spin_unlock(&up->port.lock);
156         local_irq_restore(flags);
157 }
158
159 static int __init lpc32xx_hsuart_console_setup(struct console *co,
160         char *options) {
161         struct uart_port *port;
162         int baud = 115200;
163         int bits = 8;
164         int parity = 'n';
165         int flow = 'n';
166
167         if (co->index >= MAX_PORTS)
168                 co->index = 0;
169
170         port = &lpc32xx_hs_ports[co->index].port;
171         if (!port->membase)
172                 return -ENODEV;
173
174         if (options)
175                 uart_parse_options(options, &baud, &parity, &bits, &flow);
176
177         return uart_set_options(port, co, baud, parity, bits, flow);
178 }
179
180 static struct uart_driver lpc32xx_hsuart_reg;
181 static struct console lpc32xx_hsuart_console = {
182         .name           = LPC32XX_TTY_NAME,
183         .write          = lpc32xx_hsuart_console_write,
184         .device         = uart_console_device,
185         .setup          = lpc32xx_hsuart_console_setup,
186         .flags          = CON_PRINTBUFFER,
187         .index          = -1,
188         .data           = &lpc32xx_hsuart_reg,
189 };
190
191 static int __init lpc32xx_hsuart_console_init(void)
192 {
193         register_console(&lpc32xx_hsuart_console);
194         return 0;
195 }
196 console_initcall(lpc32xx_hsuart_console_init);
197
198 #define LPC32XX_HSUART_CONSOLE  (&lpc32xx_hsuart_console)
199 #else
200 #define LPC32XX_HSUART_CONSOLE NULL
201 #endif
202
203 static struct uart_driver lpc32xx_hs_reg = {
204         .owner          = THIS_MODULE,
205         .driver_name    = MODNAME,
206         .dev_name       = LPC32XX_TTY_NAME,
207         .major          = LPC32XX_TTY_MAJOR,
208         .minor          = LPC32XX_TTY_MINOR_START,
209         .nr             = MAX_PORTS,
210         .cons           = LPC32XX_HSUART_CONSOLE,
211 };
212 static int uarts_registered;
213
214 static unsigned int __serial_get_clock_div(unsigned long uartclk,
215         unsigned long rate) {
216         u32 div, goodrate, hsu_rate, l_hsu_rate, comprate;
217         u32 rate_diff;
218
219         /* Find the closest divider to get the desired clock rate */
220         div = uartclk / rate;
221         goodrate = hsu_rate = (div / 14) - 1;
222         if (hsu_rate != 0)
223                 hsu_rate--;
224
225         /* Tweak divider */
226         l_hsu_rate = hsu_rate + 3;
227         rate_diff = 0xFFFFFFFF;
228
229         while (hsu_rate < l_hsu_rate) {
230                 comprate = uartclk / ((hsu_rate + 1) * 14);
231                 if (abs(comprate - rate) < rate_diff) {
232                         goodrate = hsu_rate;
233                         rate_diff = abs(comprate - rate);
234                 }
235
236                 hsu_rate++;
237         }
238         if (hsu_rate > 0xFF)
239                 hsu_rate = 0xFF;
240
241         return goodrate;
242 }
243
244 static void __serial_uart_flush(struct uart_port *port)
245 {
246         u32 tmp;
247         int cnt = 0;
248
249         while ((__raw_readl(LPC32XX_HSUART_LEVEL(port->membase)) > 0) &&
250                 (cnt++ < FIFO_READ_LIMIT))
251                 tmp = __raw_readl(LPC32XX_HSUART_FIFO(port->membase));
252 }
253
254 static void __serial_lpc32xx_rx(struct uart_port *port)
255 {
256         struct tty_struct *tty = port->state->port.tty;
257         unsigned int tmp, flag;
258
259         /* Read data from FIFO and push into terminal */
260         tmp = __raw_readl(LPC32XX_HSUART_FIFO(port->membase));
261         while (!(tmp & LPC32XX_HSU_RX_EMPTY)) {
262                 flag = TTY_NORMAL;
263                 port->icount.rx++;
264
265                 if (tmp & LPC32XX_HSU_ERROR_DATA) {
266                         /* Framing error */
267                         __raw_writel(LPC32XX_HSU_FE_INT,
268                                 LPC32XX_HSUART_IIR(port->membase));
269                         port->icount.frame++;
270                         flag = TTY_FRAME;
271                         tty_insert_flip_char(port->state->port.tty, 0,
272                                 TTY_FRAME);
273                         tty_schedule_flip(port->state->port.tty);
274                 }
275
276                 tty_insert_flip_char(port->state->port.tty, (tmp & 0xFF),
277                         flag);
278
279                 tmp = __raw_readl(LPC32XX_HSUART_FIFO(port->membase));
280         }
281
282         tty_flip_buffer_push(tty);
283 }
284
285 static void __serial_lpc32xx_tx(struct uart_port *port)
286 {
287         struct circ_buf *xmit = &port->state->xmit;
288         unsigned int tmp;
289
290         if (port->x_char) {
291                 __raw_writel((u32) port->x_char,
292                         LPC32XX_HSUART_FIFO(port->membase));
293                 port->icount.tx++;
294                 port->x_char = 0;
295                 return;
296         }
297
298         if (uart_circ_empty(xmit) || uart_tx_stopped(port))
299                 goto exit_tx;
300
301         /* Transfer data */
302         while (LPC32XX_HSU_TX_LEV(__raw_readl(
303                 LPC32XX_HSUART_LEVEL(port->membase))) < 64) {
304                 __raw_writel((u32) xmit->buf[xmit->tail],
305                         LPC32XX_HSUART_FIFO(port->membase));
306                 xmit->tail = (xmit->tail + 1) & (UART_XMIT_SIZE - 1);
307                 port->icount.tx++;
308                 if (uart_circ_empty(xmit))
309                         break;
310         }
311
312         if (uart_circ_chars_pending(xmit) < WAKEUP_CHARS)
313                 uart_write_wakeup(port);
314
315 exit_tx:
316         if (uart_circ_empty(xmit)) {
317                 tmp = __raw_readl(LPC32XX_HSUART_CTRL(port->membase));
318                 tmp &= ~LPC32XX_HSU_TX_INT_EN;
319                 __raw_writel(tmp, LPC32XX_HSUART_CTRL(port->membase));
320         }
321 }
322
323 static irqreturn_t serial_lpc32xx_interrupt(int irq, void *dev_id)
324 {
325         struct uart_port *port = dev_id;
326         u32 status;
327         unsigned long flags;
328
329         local_irq_save(flags);
330
331         /* Read UART status and clear latched interrupts */
332         status = __raw_readl(LPC32XX_HSUART_IIR(port->membase));
333
334         if (status & LPC32XX_HSU_BRK_INT) {
335                 /* Break received */
336                 __raw_writel(LPC32XX_HSU_BRK_INT,
337                         LPC32XX_HSUART_IIR(port->membase));
338                 port->icount.brk++;
339                 uart_handle_break(port);
340         }
341
342         /* Framing error */
343         if (status & LPC32XX_HSU_FE_INT)
344                 __raw_writel(LPC32XX_HSU_FE_INT,
345                         LPC32XX_HSUART_IIR(port->membase));
346
347         if (status & LPC32XX_HSU_RX_OE_INT) {
348                 /* Receive FIFO overrun */
349                 __raw_writel(LPC32XX_HSU_RX_OE_INT,
350                         LPC32XX_HSUART_IIR(port->membase));
351                 port->icount.overrun++;
352                 tty_insert_flip_char(port->state->port.tty, 0, TTY_OVERRUN);
353                 tty_schedule_flip(port->state->port.tty);
354         }
355
356         /* Data received? */
357         if (status & (LPC32XX_HSU_RX_TIMEOUT_INT | LPC32XX_HSU_RX_TRIG_INT))
358                 __serial_lpc32xx_rx(port);
359
360         /* Transmit data request? */
361         if ((status & LPC32XX_HSU_TX_INT) && (!uart_tx_stopped(port))) {
362                 __raw_writel(LPC32XX_HSU_TX_INT,
363                         LPC32XX_HSUART_IIR(port->membase));
364                 __serial_lpc32xx_tx(port);
365         }
366
367         local_irq_restore(flags);
368
369         return IRQ_HANDLED;
370 }
371
372 static unsigned int serial_lpc32xx_tx_empty(struct uart_port *port)
373 {
374         unsigned int ret = 0;
375
376         if (LPC32XX_HSU_TX_LEV(__raw_readl(
377                 LPC32XX_HSUART_LEVEL(port->membase))) == 0)
378                 ret = TIOCSER_TEMT;
379
380         return ret;
381 }
382
383 static void serial_lpc32xx_set_mctrl(struct uart_port *port,
384         unsigned int mctrl) {
385         /* No signals are supported on HS UARTs */
386 }
387
388 static unsigned int serial_lpc32xx_get_mctrl(struct uart_port *port)
389 {
390         /* No signals are supported on HS UARTs */
391         return TIOCM_CAR | TIOCM_DSR | TIOCM_CTS;
392 }
393
394 static void serial_lpc32xx_stop_tx(struct uart_port *port)
395 {
396         unsigned long flags;
397         u32 tmp;
398
399         local_irq_save(flags);
400
401         tmp = __raw_readl(LPC32XX_HSUART_CTRL(port->membase));
402         tmp &= ~LPC32XX_HSU_TX_INT_EN;
403         __raw_writel(tmp, LPC32XX_HSUART_CTRL(port->membase));
404
405         local_irq_restore(flags);
406 }
407
408 static void serial_lpc32xx_start_tx(struct uart_port *port)
409 {
410         unsigned long flags;
411         u32 tmp;
412
413         local_irq_save(flags);
414
415         __serial_lpc32xx_tx(port);
416         tmp = __raw_readl(LPC32XX_HSUART_CTRL(port->membase));
417         tmp |= LPC32XX_HSU_TX_INT_EN;
418         __raw_writel(tmp, LPC32XX_HSUART_CTRL(port->membase));
419
420         local_irq_restore(flags);
421 }
422
423 static void serial_lpc32xx_stop_rx(struct uart_port *port)
424 {
425         unsigned long flags;
426         u32 tmp;
427
428         local_irq_save(flags);
429
430         tmp = __raw_readl(LPC32XX_HSUART_CTRL(port->membase));
431         tmp &= ~(LPC32XX_HSU_RX_INT_EN | LPC32XX_HSU_ERR_INT_EN);
432         __raw_writel(tmp, LPC32XX_HSUART_CTRL(port->membase));
433
434         __raw_writel((LPC32XX_HSU_BRK_INT | LPC32XX_HSU_RX_OE_INT |
435                 LPC32XX_HSU_FE_INT), LPC32XX_HSUART_IIR(port->membase));
436
437         local_irq_restore(flags);
438 }
439
440 static void serial_lpc32xx_enable_ms(struct uart_port *port)
441 {
442         /* Modem status is not supported */
443 }
444
445 static void serial_lpc32xx_break_ctl(struct uart_port *port,
446         int break_state) {
447         unsigned long flags;
448         u32 tmp;
449
450         local_irq_save(flags);
451         tmp = __raw_readl(LPC32XX_HSUART_CTRL(port->membase));
452         if (break_state != 0)
453                 tmp |= LPC32XX_HSU_BREAK;
454         else
455                 tmp &= ~LPC32XX_HSU_BREAK;
456         __raw_writel(tmp, LPC32XX_HSUART_CTRL(port->membase));
457         local_irq_restore(flags);
458 }
459
460 static int serial_lpc32xx_startup(struct uart_port *port)
461 {
462         int retval;
463         u32 tmp;
464
465         __serial_uart_flush(port);
466
467         __raw_writel((LPC32XX_HSU_TX_INT | LPC32XX_HSU_FE_INT |
468                 LPC32XX_HSU_BRK_INT | LPC32XX_HSU_RX_OE_INT),
469                 LPC32XX_HSUART_IIR(port->membase));
470
471         __raw_writel(0xFF, LPC32XX_HSUART_RATE(port->membase));
472
473         /*
474          * Set receiver timeout, HSU offset of 20, no break, no interrupts,
475          * and default FIFO trigger levels
476          */
477         tmp = LPC32XX_HSU_TX_TL8B | LPC32XX_HSU_RX_TL32B |
478                 LPC32XX_HSU_OFFSET(20) | LPC32XX_HSU_TMO_INACT_4B;
479         __raw_writel(tmp, LPC32XX_HSUART_CTRL(port->membase));
480
481         retval = request_irq(port->irq, serial_lpc32xx_interrupt,
482                              0, MODNAME, port);
483         if (retval)
484                 return retval;
485
486         __raw_writel((tmp | LPC32XX_HSU_RX_INT_EN | LPC32XX_HSU_ERR_INT_EN),
487                 LPC32XX_HSUART_CTRL(port->membase));
488
489         return 0;
490 }
491
492 static void serial_lpc32xx_shutdown(struct uart_port *port)
493 {
494         u32 tmp;
495
496         tmp = LPC32XX_HSU_TX_TL8B | LPC32XX_HSU_RX_TL32B |
497                 LPC32XX_HSU_OFFSET(20) | LPC32XX_HSU_TMO_INACT_4B;
498         __raw_writel(tmp, LPC32XX_HSUART_CTRL(port->membase));
499
500         free_irq(port->irq, port);
501 }
502
503 static void serial_lpc32xx_set_termios(struct uart_port *port,
504         struct ktermios *termios, struct ktermios *old)
505 {
506         unsigned long flags;
507         unsigned int baud, quot;
508         u32 tmp;
509
510         /* Always 8-bit, no parity, 1 stop bit */
511         termios->c_cflag &= ~(CSIZE | CSTOPB | PARENB | PARODD);
512         termios->c_cflag |= CS8;
513
514         termios->c_cflag &= ~(HUPCL | CMSPAR | CLOCAL | CRTSCTS);
515
516         baud = uart_get_baud_rate(port, termios, old, 0,
517                 (port->uartclk / 14));
518         quot = __serial_get_clock_div(port->uartclk, baud);
519
520         spin_lock_irqsave(&port->lock, flags);
521
522         /* Ignore characters? */
523         tmp = __raw_readl(LPC32XX_HSUART_CTRL(port->membase));
524         if ((termios->c_cflag & CREAD) == 0)
525                 tmp &= ~(LPC32XX_HSU_RX_INT_EN | LPC32XX_HSU_ERR_INT_EN);
526         else
527                 tmp |= LPC32XX_HSU_RX_INT_EN | LPC32XX_HSU_ERR_INT_EN;
528         __raw_writel(tmp, LPC32XX_HSUART_CTRL(port->membase));
529
530         __raw_writel(quot, LPC32XX_HSUART_RATE(port->membase));
531
532         uart_update_timeout(port, termios->c_cflag, baud);
533
534         spin_unlock_irqrestore(&port->lock, flags);
535 }
536
537 static const char *serial_lpc32xx_type(struct uart_port *port)
538 {
539         return MODNAME;
540 }
541
542 static void serial_lpc32xx_release_port(struct uart_port *port)
543 {
544         if ((port->iotype == UPIO_MEM32) && (port->mapbase)) {
545                 if (port->flags & UPF_IOREMAP) {
546                         iounmap(port->membase);
547                         port->membase = NULL;
548                 }
549
550                 release_mem_region(port->mapbase, SZ_4K);
551         }
552 }
553
554 static int serial_lpc32xx_request_port(struct uart_port *port)
555 {
556         int ret = -ENODEV;
557
558         if ((port->iotype == UPIO_MEM32) && (port->mapbase)) {
559                 ret = 0;
560
561                 if (!request_mem_region(port->mapbase, SZ_4K, MODNAME))
562                         ret = -EBUSY;
563                 else if (port->flags & UPF_IOREMAP) {
564                         port->membase = ioremap(port->mapbase, SZ_4K);
565                         if (!port->membase) {
566                                 release_mem_region(port->mapbase, SZ_4K);
567                                 ret = -ENOMEM;
568                         }
569                 }
570         }
571
572         return ret;
573 }
574
575 static void serial_lpc32xx_config_port(struct uart_port *port, int uflags)
576 {
577         int ret;
578
579         ret = serial_lpc32xx_request_port(port);
580         if (ret < 0)
581                 return;
582         port->type = PORT_UART00;
583         port->fifosize = 64;
584
585         __serial_uart_flush(port);
586
587         __raw_writel((LPC32XX_HSU_TX_INT | LPC32XX_HSU_FE_INT |
588                 LPC32XX_HSU_BRK_INT | LPC32XX_HSU_RX_OE_INT),
589                 LPC32XX_HSUART_IIR(port->membase));
590
591         __raw_writel(0xFF, LPC32XX_HSUART_RATE(port->membase));
592
593         /* Set receiver timeout, HSU offset of 20, no break, no interrupts,
594            and default FIFO trigger levels */
595         __raw_writel(LPC32XX_HSU_TX_TL8B | LPC32XX_HSU_RX_TL32B |
596                 LPC32XX_HSU_OFFSET(20) | LPC32XX_HSU_TMO_INACT_4B,
597                 LPC32XX_HSUART_CTRL(port->membase));
598 }
599
600 static int serial_lpc32xx_verify_port(struct uart_port *port,
601         struct serial_struct *ser)
602 {
603         int ret = 0;
604
605         if (ser->type != PORT_UART00)
606                 ret = -EINVAL;
607
608         return ret;
609 }
610
611 static struct uart_ops serial_lpc32xx_pops = {
612         .tx_empty       = serial_lpc32xx_tx_empty,
613         .set_mctrl      = serial_lpc32xx_set_mctrl,
614         .get_mctrl      = serial_lpc32xx_get_mctrl,
615         .stop_tx        = serial_lpc32xx_stop_tx,
616         .start_tx       = serial_lpc32xx_start_tx,
617         .stop_rx        = serial_lpc32xx_stop_rx,
618         .enable_ms      = serial_lpc32xx_enable_ms,
619         .break_ctl      = serial_lpc32xx_break_ctl,
620         .startup        = serial_lpc32xx_startup,
621         .shutdown       = serial_lpc32xx_shutdown,
622         .set_termios    = serial_lpc32xx_set_termios,
623         .type           = serial_lpc32xx_type,
624         .release_port   = serial_lpc32xx_release_port,
625         .request_port   = serial_lpc32xx_request_port,
626         .config_port    = serial_lpc32xx_config_port,
627         .verify_port    = serial_lpc32xx_verify_port,
628 };
629
630 /*
631  * Register a set of serial devices attached to a platform device
632  */
633 static int __devinit serial_hs_lpc32xx_probe(struct platform_device *pdev)
634 {
635         struct uart_port *p = pdev->dev.platform_data;
636         struct lpc32xx_hsuart_port *pdr;
637         int i, ret = 0;
638
639         uarts_registered = 0;
640         for (i = 0; p && (p->flags != 0); i++) {
641                 pdr = &lpc32xx_hs_ports[i];
642                 memset(pdr, 0, sizeof(struct lpc32xx_hsuart_port));
643
644                 pdr->port.iotype        = p->iotype;
645                 pdr->port.membase       = p->membase;
646                 pdr->port.mapbase       = p->mapbase;
647                 pdr->port.irq           = p->irq;
648                 pdr->port.uartclk       = p->uartclk;
649                 pdr->port.regshift      = p->regshift;
650                 pdr->port.flags         = p->flags | UPF_FIXED_PORT;
651                 pdr->port.dev           = &pdev->dev;
652                 pdr->port.ops           = &serial_lpc32xx_pops;
653                 pdr->port.line          = p->line;
654                 spin_lock_init(&pdr->port.lock);
655
656                 uart_add_one_port(&lpc32xx_hs_reg, &pdr->port);
657                 p++;
658                 uarts_registered++;
659         }
660
661         return ret;
662 }
663
664 /*
665  * Remove serial ports registered against a platform device.
666  */
667 static int __devexit serial_hs_lpc32xx_remove(struct platform_device *pdev)
668 {
669         struct lpc32xx_hsuart_port *p;
670         int i;
671
672         for (i = 0; i < uarts_registered; i++) {
673                 p = &lpc32xx_hs_ports[i];
674
675                 if (p->port.dev == &pdev->dev)
676                         uart_remove_one_port(&lpc32xx_hs_reg, &p->port);
677         }
678
679         platform_set_drvdata(pdev, NULL);
680
681         return 0;
682 }
683
684
685 #if defined (CONFIG_PM)
686 static int serial_hs_lpc32xx_suspend(struct platform_device *dev, pm_message_t state)
687 {
688         int i;
689
690         for (i = 0; i < uarts_registered; i++) {
691                 struct lpc32xx_hsuart_port *p = &lpc32xx_hs_ports[i];
692
693                 if (p->port.type != PORT_UNKNOWN && p->port.dev == &dev->dev)
694                         uart_suspend_port(&lpc32xx_hs_reg, &p->port);
695         }
696
697         return 0;
698 }
699
700 static int serial_hs_lpc32xx_resume(struct platform_device *dev)
701 {
702         int i;
703
704         for (i = 0; i < uarts_registered; i++) {
705                 struct lpc32xx_hsuart_port *p = &lpc32xx_hs_ports[i];
706
707                 if (p->port.type != PORT_UNKNOWN && p->port.dev == &dev->dev)
708                         uart_resume_port(&lpc32xx_hs_reg, &p->port);
709         }
710
711         return 0;
712 }
713 #else
714 #define serial_hs_lpc32xx_suspend       NULL
715 #define serial_hs_lpc32xx_resume        NULL
716 #endif
717
718 static struct platform_driver serial_hs_lpc32xx_driver = {
719         .probe          = serial_hs_lpc32xx_probe,
720         .remove         = __devexit_p(serial_hs_lpc32xx_remove),
721         .suspend        = serial_hs_lpc32xx_suspend,
722         .resume         = serial_hs_lpc32xx_resume,
723         .driver         = {
724                 .name   = MODNAME,
725                 .owner  = THIS_MODULE,
726         },
727 };
728
729 static int __init lpc32xx_hsuart_init(void)
730 {
731         int ret;
732
733         ret = uart_register_driver(&lpc32xx_hs_reg);
734         if (ret == 0) {
735                 ret = platform_driver_register(&serial_hs_lpc32xx_driver);
736                 if (ret)
737                         uart_unregister_driver(&lpc32xx_hs_reg);
738         }
739
740         return ret;
741 }
742
743 static void __exit lpc32xx_hsuart_exit(void)
744 {
745         platform_driver_unregister(&serial_hs_lpc32xx_driver);
746         uart_unregister_driver(&lpc32xx_hs_reg);
747 }
748
749 module_init(lpc32xx_hsuart_init);
750 module_exit(lpc32xx_hsuart_exit);
751
752 MODULE_AUTHOR("Kevin Wells (kevin.wells@nxp.com)");
753 MODULE_DESCRIPTION("NXP LPC32XX High speed UART driver");
754 MODULE_LICENSE("GPL");