0cd0e4ac12a658d5f60ecdcdd86c3c75c35ac89d
[firefly-linux-kernel-4.4.55.git] / drivers / tty / serial / sc26xx.c
1 /*
2  * SC268xx.c: Serial driver for Philiphs SC2681/SC2692 devices.
3  *
4  * Copyright (C) 2006,2007 Thomas Bogendörfer (tsbogend@alpha.franken.de)
5  */
6
7 #include <linux/module.h>
8 #include <linux/kernel.h>
9 #include <linux/errno.h>
10 #include <linux/tty.h>
11 #include <linux/tty_flip.h>
12 #include <linux/major.h>
13 #include <linux/circ_buf.h>
14 #include <linux/serial.h>
15 #include <linux/sysrq.h>
16 #include <linux/console.h>
17 #include <linux/spinlock.h>
18 #include <linux/slab.h>
19 #include <linux/delay.h>
20 #include <linux/init.h>
21 #include <linux/platform_device.h>
22 #include <linux/irq.h>
23 #include <linux/io.h>
24
25 #warning "Please try migrate to use new driver SCCNXP and report the status" \
26          "in the linux-serial mailing list."
27
28 #if defined(CONFIG_MAGIC_SYSRQ)
29 #define SUPPORT_SYSRQ
30 #endif
31
32 #include <linux/serial_core.h>
33
34 #define SC26XX_MAJOR         204
35 #define SC26XX_MINOR_START   205
36 #define SC26XX_NR            2
37
38 struct uart_sc26xx_port {
39         struct uart_port      port[2];
40         u8     dsr_mask[2];
41         u8     cts_mask[2];
42         u8     dcd_mask[2];
43         u8     ri_mask[2];
44         u8     dtr_mask[2];
45         u8     rts_mask[2];
46         u8     imr;
47 };
48
49 /* register common to both ports */
50 #define RD_ISR      0x14
51 #define RD_IPR      0x34
52
53 #define WR_ACR      0x10
54 #define WR_IMR      0x14
55 #define WR_OPCR     0x34
56 #define WR_OPR_SET  0x38
57 #define WR_OPR_CLR  0x3C
58
59 /* access common register */
60 #define READ_SC(p, r)        readb((p)->membase + RD_##r)
61 #define WRITE_SC(p, r, v)    writeb((v), (p)->membase + WR_##r)
62
63 /* register per port */
64 #define RD_PORT_MRx 0x00
65 #define RD_PORT_SR  0x04
66 #define RD_PORT_RHR 0x0c
67
68 #define WR_PORT_MRx 0x00
69 #define WR_PORT_CSR 0x04
70 #define WR_PORT_CR  0x08
71 #define WR_PORT_THR 0x0c
72
73 /* SR bits */
74 #define SR_BREAK    (1 << 7)
75 #define SR_FRAME    (1 << 6)
76 #define SR_PARITY   (1 << 5)
77 #define SR_OVERRUN  (1 << 4)
78 #define SR_TXRDY    (1 << 2)
79 #define SR_RXRDY    (1 << 0)
80
81 #define CR_RES_MR   (1 << 4)
82 #define CR_RES_RX   (2 << 4)
83 #define CR_RES_TX   (3 << 4)
84 #define CR_STRT_BRK (6 << 4)
85 #define CR_STOP_BRK (7 << 4)
86 #define CR_DIS_TX   (1 << 3)
87 #define CR_ENA_TX   (1 << 2)
88 #define CR_DIS_RX   (1 << 1)
89 #define CR_ENA_RX   (1 << 0)
90
91 /* ISR bits */
92 #define ISR_RXRDYB  (1 << 5)
93 #define ISR_TXRDYB  (1 << 4)
94 #define ISR_RXRDYA  (1 << 1)
95 #define ISR_TXRDYA  (1 << 0)
96
97 /* IMR bits */
98 #define IMR_RXRDY   (1 << 1)
99 #define IMR_TXRDY   (1 << 0)
100
101 /* access port register */
102 static inline u8 read_sc_port(struct uart_port *p, u8 reg)
103 {
104         return readb(p->membase + p->line * 0x20 + reg);
105 }
106
107 static inline void write_sc_port(struct uart_port *p, u8 reg, u8 val)
108 {
109         writeb(val, p->membase + p->line * 0x20 + reg);
110 }
111
112 #define READ_SC_PORT(p, r)     read_sc_port(p, RD_PORT_##r)
113 #define WRITE_SC_PORT(p, r, v) write_sc_port(p, WR_PORT_##r, v)
114
115 static void sc26xx_enable_irq(struct uart_port *port, int mask)
116 {
117         struct uart_sc26xx_port *up;
118         int line = port->line;
119
120         port -= line;
121         up = container_of(port, struct uart_sc26xx_port, port[0]);
122
123         up->imr |= mask << (line * 4);
124         WRITE_SC(port, IMR, up->imr);
125 }
126
127 static void sc26xx_disable_irq(struct uart_port *port, int mask)
128 {
129         struct uart_sc26xx_port *up;
130         int line = port->line;
131
132         port -= line;
133         up = container_of(port, struct uart_sc26xx_port, port[0]);
134
135         up->imr &= ~(mask << (line * 4));
136         WRITE_SC(port, IMR, up->imr);
137 }
138
139 static struct tty_struct *receive_chars(struct uart_port *port)
140 {
141         struct tty_port *tport = NULL;
142         struct tty_struct *tty = NULL;
143         int limit = 10000;
144         unsigned char ch;
145         char flag;
146         u8 status;
147
148         /* FIXME what is this trying to achieve? */
149         if (port->state != NULL) {              /* Unopened serial console */
150                 tport = &port->state->port;
151                 tty = tport->tty;
152         }
153
154         while (limit-- > 0) {
155                 status = READ_SC_PORT(port, SR);
156                 if (!(status & SR_RXRDY))
157                         break;
158                 ch = READ_SC_PORT(port, RHR);
159
160                 flag = TTY_NORMAL;
161                 port->icount.rx++;
162
163                 if (unlikely(status & (SR_BREAK | SR_FRAME |
164                                        SR_PARITY | SR_OVERRUN))) {
165                         if (status & SR_BREAK) {
166                                 status &= ~(SR_PARITY | SR_FRAME);
167                                 port->icount.brk++;
168                                 if (uart_handle_break(port))
169                                         continue;
170                         } else if (status & SR_PARITY)
171                                 port->icount.parity++;
172                         else if (status & SR_FRAME)
173                                 port->icount.frame++;
174                         if (status & SR_OVERRUN)
175                                 port->icount.overrun++;
176
177                         status &= port->read_status_mask;
178                         if (status & SR_BREAK)
179                                 flag = TTY_BREAK;
180                         else if (status & SR_PARITY)
181                                 flag = TTY_PARITY;
182                         else if (status & SR_FRAME)
183                                 flag = TTY_FRAME;
184                 }
185
186                 if (uart_handle_sysrq_char(port, ch))
187                         continue;
188
189                 if (status & port->ignore_status_mask)
190                         continue;
191
192                 tty_insert_flip_char(tport, ch, flag);
193         }
194         return tty;
195 }
196
197 static void transmit_chars(struct uart_port *port)
198 {
199         struct circ_buf *xmit;
200
201         if (!port->state)
202                 return;
203
204         xmit = &port->state->xmit;
205         if (uart_circ_empty(xmit) || uart_tx_stopped(port)) {
206                 sc26xx_disable_irq(port, IMR_TXRDY);
207                 return;
208         }
209         while (!uart_circ_empty(xmit)) {
210                 if (!(READ_SC_PORT(port, SR) & SR_TXRDY))
211                         break;
212
213                 WRITE_SC_PORT(port, THR, xmit->buf[xmit->tail]);
214                 xmit->tail = (xmit->tail + 1) & (UART_XMIT_SIZE - 1);
215                 port->icount.tx++;
216         }
217         if (uart_circ_chars_pending(xmit) < WAKEUP_CHARS)
218                 uart_write_wakeup(port);
219 }
220
221 static irqreturn_t sc26xx_interrupt(int irq, void *dev_id)
222 {
223         struct uart_sc26xx_port *up = dev_id;
224         struct tty_struct *tty;
225         unsigned long flags;
226         u8 isr;
227
228         spin_lock_irqsave(&up->port[0].lock, flags);
229
230         tty = NULL;
231         isr = READ_SC(&up->port[0], ISR);
232         if (isr & ISR_TXRDYA)
233             transmit_chars(&up->port[0]);
234         if (isr & ISR_RXRDYA)
235             tty = receive_chars(&up->port[0]);
236
237         spin_unlock(&up->port[0].lock);
238
239         if (tty)
240                 tty_flip_buffer_push(tty);
241
242         spin_lock(&up->port[1].lock);
243
244         tty = NULL;
245         if (isr & ISR_TXRDYB)
246             transmit_chars(&up->port[1]);
247         if (isr & ISR_RXRDYB)
248             tty = receive_chars(&up->port[1]);
249
250         spin_unlock_irqrestore(&up->port[1].lock, flags);
251
252         if (tty)
253                 tty_flip_buffer_push(tty);
254
255         return IRQ_HANDLED;
256 }
257
258 /* port->lock is not held.  */
259 static unsigned int sc26xx_tx_empty(struct uart_port *port)
260 {
261         return (READ_SC_PORT(port, SR) & SR_TXRDY) ? TIOCSER_TEMT : 0;
262 }
263
264 /* port->lock held by caller.  */
265 static void sc26xx_set_mctrl(struct uart_port *port, unsigned int mctrl)
266 {
267         struct uart_sc26xx_port *up;
268         int line = port->line;
269
270         port -= line;
271         up = container_of(port, struct uart_sc26xx_port, port[0]);
272
273         if (up->dtr_mask[line]) {
274                 if (mctrl & TIOCM_DTR)
275                         WRITE_SC(port, OPR_SET, up->dtr_mask[line]);
276                 else
277                         WRITE_SC(port, OPR_CLR, up->dtr_mask[line]);
278         }
279         if (up->rts_mask[line]) {
280                 if (mctrl & TIOCM_RTS)
281                         WRITE_SC(port, OPR_SET, up->rts_mask[line]);
282                 else
283                         WRITE_SC(port, OPR_CLR, up->rts_mask[line]);
284         }
285 }
286
287 /* port->lock is held by caller and interrupts are disabled.  */
288 static unsigned int sc26xx_get_mctrl(struct uart_port *port)
289 {
290         struct uart_sc26xx_port *up;
291         int line = port->line;
292         unsigned int mctrl = TIOCM_DSR | TIOCM_CTS | TIOCM_CAR;
293         u8 ipr;
294
295         port -= line;
296         up = container_of(port, struct uart_sc26xx_port, port[0]);
297         ipr = READ_SC(port, IPR) ^ 0xff;
298
299         if (up->dsr_mask[line]) {
300                 mctrl &= ~TIOCM_DSR;
301                 mctrl |= ipr & up->dsr_mask[line] ? TIOCM_DSR : 0;
302         }
303         if (up->cts_mask[line]) {
304                 mctrl &= ~TIOCM_CTS;
305                 mctrl |= ipr & up->cts_mask[line] ? TIOCM_CTS : 0;
306         }
307         if (up->dcd_mask[line]) {
308                 mctrl &= ~TIOCM_CAR;
309                 mctrl |= ipr & up->dcd_mask[line] ? TIOCM_CAR : 0;
310         }
311         if (up->ri_mask[line]) {
312                 mctrl &= ~TIOCM_RNG;
313                 mctrl |= ipr & up->ri_mask[line] ? TIOCM_RNG : 0;
314         }
315         return mctrl;
316 }
317
318 /* port->lock held by caller.  */
319 static void sc26xx_stop_tx(struct uart_port *port)
320 {
321         return;
322 }
323
324 /* port->lock held by caller.  */
325 static void sc26xx_start_tx(struct uart_port *port)
326 {
327         struct circ_buf *xmit = &port->state->xmit;
328
329         while (!uart_circ_empty(xmit)) {
330                 if (!(READ_SC_PORT(port, SR) & SR_TXRDY)) {
331                         sc26xx_enable_irq(port, IMR_TXRDY);
332                         break;
333                 }
334                 WRITE_SC_PORT(port, THR, xmit->buf[xmit->tail]);
335                 xmit->tail = (xmit->tail + 1) & (UART_XMIT_SIZE - 1);
336                 port->icount.tx++;
337         }
338 }
339
340 /* port->lock held by caller.  */
341 static void sc26xx_stop_rx(struct uart_port *port)
342 {
343 }
344
345 /* port->lock held by caller.  */
346 static void sc26xx_enable_ms(struct uart_port *port)
347 {
348 }
349
350 /* port->lock is not held.  */
351 static void sc26xx_break_ctl(struct uart_port *port, int break_state)
352 {
353         if (break_state == -1)
354                 WRITE_SC_PORT(port, CR, CR_STRT_BRK);
355         else
356                 WRITE_SC_PORT(port, CR, CR_STOP_BRK);
357 }
358
359 /* port->lock is not held.  */
360 static int sc26xx_startup(struct uart_port *port)
361 {
362         sc26xx_disable_irq(port, IMR_TXRDY | IMR_RXRDY);
363         WRITE_SC(port, OPCR, 0);
364
365         /* reset tx and rx */
366         WRITE_SC_PORT(port, CR, CR_RES_RX);
367         WRITE_SC_PORT(port, CR, CR_RES_TX);
368
369         /* start rx/tx */
370         WRITE_SC_PORT(port, CR, CR_ENA_TX | CR_ENA_RX);
371
372         /* enable irqs */
373         sc26xx_enable_irq(port, IMR_RXRDY);
374         return 0;
375 }
376
377 /* port->lock is not held.  */
378 static void sc26xx_shutdown(struct uart_port *port)
379 {
380         /* disable interrupst */
381         sc26xx_disable_irq(port, IMR_TXRDY | IMR_RXRDY);
382
383         /* stop tx/rx */
384         WRITE_SC_PORT(port, CR, CR_DIS_TX | CR_DIS_RX);
385 }
386
387 /* port->lock is not held.  */
388 static void sc26xx_set_termios(struct uart_port *port, struct ktermios *termios,
389                               struct ktermios *old)
390 {
391         unsigned int baud = uart_get_baud_rate(port, termios, old, 0, 4000000);
392         unsigned int quot = uart_get_divisor(port, baud);
393         unsigned int iflag, cflag;
394         unsigned long flags;
395         u8 mr1, mr2, csr;
396
397         spin_lock_irqsave(&port->lock, flags);
398
399         while ((READ_SC_PORT(port, SR) & ((1 << 3) | (1 << 2))) != 0xc)
400                 udelay(2);
401
402         WRITE_SC_PORT(port, CR, CR_DIS_TX | CR_DIS_RX);
403
404         iflag = termios->c_iflag;
405         cflag = termios->c_cflag;
406
407         port->read_status_mask = SR_OVERRUN;
408         if (iflag & INPCK)
409                 port->read_status_mask |= SR_PARITY | SR_FRAME;
410         if (iflag & (BRKINT | PARMRK))
411                 port->read_status_mask |= SR_BREAK;
412
413         port->ignore_status_mask = 0;
414         if (iflag & IGNBRK)
415                 port->ignore_status_mask |= SR_BREAK;
416         if ((cflag & CREAD) == 0)
417                 port->ignore_status_mask |= SR_BREAK | SR_FRAME |
418                                             SR_PARITY | SR_OVERRUN;
419
420         switch (cflag & CSIZE) {
421         case CS5:
422                 mr1 = 0x00;
423                 break;
424         case CS6:
425                 mr1 = 0x01;
426                 break;
427         case CS7:
428                 mr1 = 0x02;
429                 break;
430         default:
431         case CS8:
432                 mr1 = 0x03;
433                 break;
434         }
435         mr2 = 0x07;
436         if (cflag & CSTOPB)
437                 mr2 = 0x0f;
438         if (cflag & PARENB) {
439                 if (cflag & PARODD)
440                         mr1 |= (1 << 2);
441         } else
442                 mr1 |= (2 << 3);
443
444         switch (baud) {
445         case 50:
446                 csr = 0x00;
447                 break;
448         case 110:
449                 csr = 0x11;
450                 break;
451         case 134:
452                 csr = 0x22;
453                 break;
454         case 200:
455                 csr = 0x33;
456                 break;
457         case 300:
458                 csr = 0x44;
459                 break;
460         case 600:
461                 csr = 0x55;
462                 break;
463         case 1200:
464                 csr = 0x66;
465                 break;
466         case 2400:
467                 csr = 0x88;
468                 break;
469         case 4800:
470                 csr = 0x99;
471                 break;
472         default:
473         case 9600:
474                 csr = 0xbb;
475                 break;
476         case 19200:
477                 csr = 0xcc;
478                 break;
479         }
480
481         WRITE_SC_PORT(port, CR, CR_RES_MR);
482         WRITE_SC_PORT(port, MRx, mr1);
483         WRITE_SC_PORT(port, MRx, mr2);
484
485         WRITE_SC(port, ACR, 0x80);
486         WRITE_SC_PORT(port, CSR, csr);
487
488         /* reset tx and rx */
489         WRITE_SC_PORT(port, CR, CR_RES_RX);
490         WRITE_SC_PORT(port, CR, CR_RES_TX);
491
492         WRITE_SC_PORT(port, CR, CR_ENA_TX | CR_ENA_RX);
493         while ((READ_SC_PORT(port, SR) & ((1 << 3) | (1 << 2))) != 0xc)
494                 udelay(2);
495
496         /* XXX */
497         uart_update_timeout(port, cflag,
498                             (port->uartclk / (16 * quot)));
499
500         spin_unlock_irqrestore(&port->lock, flags);
501 }
502
503 static const char *sc26xx_type(struct uart_port *port)
504 {
505         return "SC26XX";
506 }
507
508 static void sc26xx_release_port(struct uart_port *port)
509 {
510 }
511
512 static int sc26xx_request_port(struct uart_port *port)
513 {
514         return 0;
515 }
516
517 static void sc26xx_config_port(struct uart_port *port, int flags)
518 {
519 }
520
521 static int sc26xx_verify_port(struct uart_port *port, struct serial_struct *ser)
522 {
523         return -EINVAL;
524 }
525
526 static struct uart_ops sc26xx_ops = {
527         .tx_empty       = sc26xx_tx_empty,
528         .set_mctrl      = sc26xx_set_mctrl,
529         .get_mctrl      = sc26xx_get_mctrl,
530         .stop_tx        = sc26xx_stop_tx,
531         .start_tx       = sc26xx_start_tx,
532         .stop_rx        = sc26xx_stop_rx,
533         .enable_ms      = sc26xx_enable_ms,
534         .break_ctl      = sc26xx_break_ctl,
535         .startup        = sc26xx_startup,
536         .shutdown       = sc26xx_shutdown,
537         .set_termios    = sc26xx_set_termios,
538         .type           = sc26xx_type,
539         .release_port   = sc26xx_release_port,
540         .request_port   = sc26xx_request_port,
541         .config_port    = sc26xx_config_port,
542         .verify_port    = sc26xx_verify_port,
543 };
544
545 static struct uart_port *sc26xx_port;
546
547 #ifdef CONFIG_SERIAL_SC26XX_CONSOLE
548 static void sc26xx_console_putchar(struct uart_port *port, char c)
549 {
550         unsigned long flags;
551         int limit = 1000000;
552
553         spin_lock_irqsave(&port->lock, flags);
554
555         while (limit-- > 0) {
556                 if (READ_SC_PORT(port, SR) & SR_TXRDY) {
557                         WRITE_SC_PORT(port, THR, c);
558                         break;
559                 }
560                 udelay(2);
561         }
562
563         spin_unlock_irqrestore(&port->lock, flags);
564 }
565
566 static void sc26xx_console_write(struct console *con, const char *s, unsigned n)
567 {
568         struct uart_port *port = sc26xx_port;
569         int i;
570
571         for (i = 0; i < n; i++) {
572                 if (*s == '\n')
573                         sc26xx_console_putchar(port, '\r');
574                 sc26xx_console_putchar(port, *s++);
575         }
576 }
577
578 static int __init sc26xx_console_setup(struct console *con, char *options)
579 {
580         struct uart_port *port = sc26xx_port;
581         int baud = 9600;
582         int bits = 8;
583         int parity = 'n';
584         int flow = 'n';
585
586         if (port->type != PORT_SC26XX)
587                 return -1;
588
589         printk(KERN_INFO "Console: ttySC%d (SC26XX)\n", con->index);
590         if (options)
591                 uart_parse_options(options, &baud, &parity, &bits, &flow);
592
593         return uart_set_options(port, con, baud, parity, bits, flow);
594 }
595
596 static struct uart_driver sc26xx_reg;
597 static struct console sc26xx_console = {
598         .name   =       "ttySC",
599         .write  =       sc26xx_console_write,
600         .device =       uart_console_device,
601         .setup  =       sc26xx_console_setup,
602         .flags  =       CON_PRINTBUFFER,
603         .index  =       -1,
604         .data   =       &sc26xx_reg,
605 };
606 #define SC26XX_CONSOLE   &sc26xx_console
607 #else
608 #define SC26XX_CONSOLE   NULL
609 #endif
610
611 static struct uart_driver sc26xx_reg = {
612         .owner                  = THIS_MODULE,
613         .driver_name            = "SC26xx",
614         .dev_name               = "ttySC",
615         .major                  = SC26XX_MAJOR,
616         .minor                  = SC26XX_MINOR_START,
617         .nr                     = SC26XX_NR,
618         .cons                   = SC26XX_CONSOLE,
619 };
620
621 static u8 sc26xx_flags2mask(unsigned int flags, unsigned int bitpos)
622 {
623         unsigned int bit = (flags >> bitpos) & 15;
624
625         return bit ? (1 << (bit - 1)) : 0;
626 }
627
628 static void sc26xx_init_masks(struct uart_sc26xx_port *up,
629                                         int line, unsigned int data)
630 {
631         up->dtr_mask[line] = sc26xx_flags2mask(data,  0);
632         up->rts_mask[line] = sc26xx_flags2mask(data,  4);
633         up->dsr_mask[line] = sc26xx_flags2mask(data,  8);
634         up->cts_mask[line] = sc26xx_flags2mask(data, 12);
635         up->dcd_mask[line] = sc26xx_flags2mask(data, 16);
636         up->ri_mask[line]  = sc26xx_flags2mask(data, 20);
637 }
638
639 static int sc26xx_probe(struct platform_device *dev)
640 {
641         struct resource *res;
642         struct uart_sc26xx_port *up;
643         unsigned int *sc26xx_data = dev->dev.platform_data;
644         int err;
645
646         res = platform_get_resource(dev, IORESOURCE_MEM, 0);
647         if (!res)
648                 return -ENODEV;
649
650         up = kzalloc(sizeof *up, GFP_KERNEL);
651         if (unlikely(!up))
652                 return -ENOMEM;
653
654         up->port[0].line = 0;
655         up->port[0].ops = &sc26xx_ops;
656         up->port[0].type = PORT_SC26XX;
657         up->port[0].uartclk = (29491200 / 16); /* arbitrary */
658
659         up->port[0].mapbase = res->start;
660         up->port[0].membase = ioremap_nocache(up->port[0].mapbase, 0x40);
661         up->port[0].iotype = UPIO_MEM;
662         up->port[0].irq = platform_get_irq(dev, 0);
663
664         up->port[0].dev = &dev->dev;
665
666         sc26xx_init_masks(up, 0, sc26xx_data[0]);
667
668         sc26xx_port = &up->port[0];
669
670         up->port[1].line = 1;
671         up->port[1].ops = &sc26xx_ops;
672         up->port[1].type = PORT_SC26XX;
673         up->port[1].uartclk = (29491200 / 16); /* arbitrary */
674
675         up->port[1].mapbase = up->port[0].mapbase;
676         up->port[1].membase = up->port[0].membase;
677         up->port[1].iotype = UPIO_MEM;
678         up->port[1].irq = up->port[0].irq;
679
680         up->port[1].dev = &dev->dev;
681
682         sc26xx_init_masks(up, 1, sc26xx_data[1]);
683
684         err = uart_register_driver(&sc26xx_reg);
685         if (err)
686                 goto out_free_port;
687
688         sc26xx_reg.tty_driver->name_base = sc26xx_reg.minor;
689
690         err = uart_add_one_port(&sc26xx_reg, &up->port[0]);
691         if (err)
692                 goto out_unregister_driver;
693
694         err = uart_add_one_port(&sc26xx_reg, &up->port[1]);
695         if (err)
696                 goto out_remove_port0;
697
698         err = request_irq(up->port[0].irq, sc26xx_interrupt, 0, "sc26xx", up);
699         if (err)
700                 goto out_remove_ports;
701
702         dev_set_drvdata(&dev->dev, up);
703         return 0;
704
705 out_remove_ports:
706         uart_remove_one_port(&sc26xx_reg, &up->port[1]);
707 out_remove_port0:
708         uart_remove_one_port(&sc26xx_reg, &up->port[0]);
709
710 out_unregister_driver:
711         uart_unregister_driver(&sc26xx_reg);
712
713 out_free_port:
714         kfree(up);
715         sc26xx_port = NULL;
716         return err;
717 }
718
719
720 static int __exit sc26xx_driver_remove(struct platform_device *dev)
721 {
722         struct uart_sc26xx_port *up = dev_get_drvdata(&dev->dev);
723
724         free_irq(up->port[0].irq, up);
725
726         uart_remove_one_port(&sc26xx_reg, &up->port[0]);
727         uart_remove_one_port(&sc26xx_reg, &up->port[1]);
728
729         uart_unregister_driver(&sc26xx_reg);
730
731         kfree(up);
732         sc26xx_port = NULL;
733
734         dev_set_drvdata(&dev->dev, NULL);
735         return 0;
736 }
737
738 static struct platform_driver sc26xx_driver = {
739         .probe  = sc26xx_probe,
740         .remove = sc26xx_driver_remove,
741         .driver = {
742                 .name   = "SC26xx",
743                 .owner  = THIS_MODULE,
744         },
745 };
746
747 module_platform_driver(sc26xx_driver);
748
749 MODULE_AUTHOR("Thomas Bogendörfer");
750 MODULE_DESCRIPTION("SC681/SC2692 serial driver");
751 MODULE_VERSION("1.0");
752 MODULE_LICENSE("GPL");
753 MODULE_ALIAS("platform:SC26xx");