adapt all kind of board
[firefly-linux-kernel-4.4.55.git] / drivers / serial / rk2818_serial.c
1 /*
2  * drivers/serial/rk2818_serial.c - driver for rk2818 serial device and console
3  *
4  * Copyright (C) 2010 ROCKCHIP, Inc.
5  *
6  * This software is licensed under the terms of the GNU General Public
7  * License version 2, as published by the Free Software Foundation, and
8  * may be copied, distributed, and modified under those terms.
9  *
10  * This program is distributed in the hope that it will be useful,
11  * but WITHOUT ANY WARRANTY; without even the implied warranty of
12  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
13  * GNU General Public License for more details.
14  */
15
16
17 #if defined(CONFIG_SERIAL_RK2818_CONSOLE) && defined(CONFIG_MAGIC_SYSRQ)
18 #define SUPPORT_SYSRQ
19 #endif
20
21 #include <linux/hrtimer.h>
22 #include <linux/module.h>
23 #include <linux/io.h>
24 #include <linux/ioport.h>
25 #include <linux/irq.h>
26 #include <linux/init.h>
27 #include <linux/console.h>
28 #include <linux/tty.h>
29 #include <linux/tty_flip.h>
30 #include <linux/serial_core.h>
31 #include <linux/serial.h>
32 #include <linux/clk.h>
33 #include <linux/platform_device.h>
34 #include <mach/iomux.h>
35 #include <mach/gpio.h>
36 #include <mach/board.h>
37 #include "rk2818_serial.h"
38
39 /*
40  * We wrap our port structure around the generic uart_port.
41  */
42 struct rk2818_port {
43         struct uart_port        uart;
44         char                    name[16];
45         struct clk              *clk;
46         unsigned int            imr;
47 };
48
49 #define UART_TO_RK2818(uart_port)       ((struct rk2818_port *) uart_port)
50 #define RK2818_SERIAL_MAJOR      TTY_MAJOR
51 #define RK2818_SERIAL_MINOR      64      
52
53
54 static inline void rk2818_uart_write(struct uart_port *port, unsigned int val,
55                              unsigned int off)
56 {
57         __raw_writel(val, port->membase + off);
58 }
59
60 static inline unsigned int rk2818_uart_read(struct uart_port *port, unsigned int off)
61 {
62         return __raw_readl(port->membase + off);
63 }
64
65 static int rk2818_set_baud_rate(struct uart_port *port, unsigned int baud)
66 {
67         unsigned int uartTemp;
68         
69         rk2818_uart_write(port,rk2818_uart_read(port,UART_LCR) | LCR_DLA_EN,UART_LCR);
70     uartTemp = port->uartclk / (16 * baud);
71     rk2818_uart_write(port,uartTemp & 0xff,UART_DLL);
72     rk2818_uart_write(port,(uartTemp>>8) & 0xff,UART_DLH);
73     rk2818_uart_write(port,rk2818_uart_read(port,UART_LCR) & (~LCR_DLA_EN),UART_LCR);
74         return baud;
75 }
76
77 /*
78  * ÅжϷ¢ËÍ»º³åÇøÊÇ·ñΪ¿Õ
79  *ÏÈÒÔFIFO´ò¿ª×ö£¬ºóÃæ¿ÉÒÔ×ö³ÉFIFO¹Ø»òFIFO¿ª¡£
80  */
81 static u_int rk2818_serial_tx_empty(struct uart_port *port)
82 {
83     while(!(rk2818_uart_read(port,UART_USR)&UART_TRANSMIT_FIFO_EMPTY))
84         cpu_relax();
85         if(rk2818_uart_read(port,UART_USR)&UART_TRANSMIT_FIFO_EMPTY)
86         {
87         return (1);///1£º¿Õ
88         }else{
89         return (0);///0:·Ç¿Õ
90         }
91 }
92
93 /*
94  * Power / Clock management.
95  */
96 static void rk2818_serial_pm(struct uart_port *port, unsigned int state,
97                             unsigned int oldstate)
98 {
99         struct rk2818_port *rk2818_port = UART_TO_RK2818(port);
100
101         switch (state) {
102         case 0:
103                 /*
104                  * Enable the peripheral clock for this serial port.
105                  * This is called on uart_open() or a resume event.
106                  */
107                 clk_enable(rk2818_port->clk);
108                 break;
109         case 3:
110                 /*
111                  * Disable the peripheral clock for this serial port.
112                  * This is called on uart_close() or a suspend event.
113                  */
114                 clk_disable(rk2818_port->clk);
115                 break;
116         default:
117                 printk(KERN_ERR "rk2818_serial: unknown pm %d\n", state);
118         }
119 }
120
121 /*
122  * Return string describing the specified port
123  */
124 static const char *rk2818_serial_type(struct uart_port *port)
125 {
126         return (port->type == PORT_RK2818) ? "RK2818_SERIAL" : NULL;
127 }
128
129 static void rk2818_serial_enable_ms(struct uart_port *port)
130 {
131   #ifdef DEBUG_LHH
132   printk("Enter::%s\n",__FUNCTION__);
133   #endif
134 }
135
136 /* no modem control lines */
137 static unsigned int rk2818_serial_get_mctrl(struct uart_port *port)
138 {
139         unsigned int result = 0;
140         unsigned int status;
141         
142         status = rk2818_uart_read(port,UART_MSR);
143         if (status & UART_MSR_URCTS)
144         {                       
145                 result = TIOCM_CAR | TIOCM_DSR | TIOCM_CTS;
146                 printk("UART_GET_MSR:0x%x\n",result);
147         }else{                  
148                 result = TIOCM_CAR | TIOCM_DSR;
149                 printk("UART_GET_MSR:0x%x\n",result);
150         }
151         return result;
152 }
153
154 static void rk2818_serial_set_mctrl(struct uart_port *port, unsigned int mctrl)
155 {        
156         #ifdef DEBUG_LHH
157         printk("Enter::%s\n",__FUNCTION__);
158         #endif 
159 }
160
161 /*
162  * Stop transmitting.
163  */
164 static void rk2818_serial_stop_tx(struct uart_port *port)
165 {
166         #ifdef DEBUG_LHH
167         printk("Enter::%s\n",__FUNCTION__);
168         #endif
169 }
170
171 /*
172  * Start transmitting.
173  */
174 static void rk2818_serial_start_tx(struct uart_port *port)
175 {
176         struct circ_buf *xmit = &port->state->xmit;
177         while(!(uart_circ_empty(xmit)))
178         {
179                 while (!(rk2818_uart_read(port,UART_USR) & UART_TRANSMIT_FIFO_NOT_FULL)){
180             rk2818_uart_write(port,UART_IER_RECV_DATA_AVAIL_INT_ENABLE|UART_IER_SEND_EMPTY_INT_ENABLE,UART_IER);
181             return;
182         }
183         rk2818_uart_write(port,xmit->buf[xmit->tail],UART_THR);
184                 xmit->tail = (xmit->tail + 1) & (UART_XMIT_SIZE - 1);
185                 port->icount.tx++;
186         }
187         if((uart_circ_empty(xmit)))
188                 rk2818_uart_write(port,UART_IER_RECV_DATA_AVAIL_INT_ENABLE,UART_IER);
189         if (uart_circ_chars_pending(xmit) < WAKEUP_CHARS)
190                 uart_write_wakeup(port);        
191 }
192
193 /*
194  * Stop receiving - port is in process of being closed.
195  */
196 static void rk2818_serial_stop_rx(struct uart_port *port)
197 {
198     #ifdef DEBUG_LHH
199     printk("Enter::%s\n",__FUNCTION__);
200     #endif
201 }
202
203 /*
204  * Control the transmission of a break signal
205  */
206 static void rk2818_serial_break_ctl(struct uart_port *port, int break_state)
207 {
208     unsigned int temp;
209     temp = rk2818_uart_read(port,UART_LCR);
210     if (break_state != 0)       
211         temp = temp & (~BREAK_CONTROL_BIT);/* start break */
212         else
213         temp = temp | BREAK_CONTROL_BIT; /* stop break */
214     rk2818_uart_write(port,temp,UART_LCR);      
215 }
216
217
218 /*
219  * Characters received (called from interrupt handler)
220  */
221 static void rk2818_rx_chars(struct uart_port *port)
222 {
223         unsigned int ch, flag;
224         while((rk2818_uart_read(port,UART_USR) & UART_RECEIVE_FIFO_NOT_EMPTY) == UART_RECEIVE_FIFO_NOT_EMPTY)
225         {
226                 u32 lsr = rk2818_uart_read(port, UART_LSR);
227             ch = rk2818_uart_read(port,UART_RBR);
228             flag = TTY_NORMAL;
229                 port->icount.rx++;
230                 if (lsr & UART_BREAK_INT_BIT) {
231                         port->icount.brk++;
232                         if (uart_handle_break(port))
233                                 continue;
234                 }
235                 if (uart_handle_sysrq_char(port, ch))
236                 {
237                         continue;
238                 } 
239                 uart_insert_char(port, 0, 0, ch, flag);
240         }
241         tty_flip_buffer_push(port->state->port.tty);
242         
243 }
244
245 /*
246  * Interrupt handler
247  */
248 static irqreturn_t rk2818_uart_interrupt(int irq, void *dev_id)
249 {       
250         struct uart_port *port = dev_id;
251         unsigned int status, pending;
252         
253         status = rk2818_uart_read(port,UART_IIR); 
254         pending = status & 0x0f;
255     if((pending == UART_IIR_RECV_AVAILABLE) || (pending == UART_IIR_CHAR_TIMEOUT))
256                 rk2818_rx_chars(port);
257         if(pending == UART_IIR_THR_EMPTY)
258                 rk2818_serial_start_tx(port);           
259         return IRQ_HANDLED;     
260 }
261
262 /*
263  * Disable the port
264  */
265 static void rk2818_serial_shutdown(struct uart_port *port)
266 {
267    struct rk2818_port *rk2818_port = UART_TO_RK2818(port);
268    rk2818_uart_write(port,0x00,UART_IER);
269    clk_disable(rk2818_port->clk);
270    free_irq(port->irq, port);
271 }
272 /*
273  * Perform initialization and enable port for reception
274  */
275 static int rk2818_serial_startup(struct uart_port *port)
276 {
277         struct rk2818_port *rk2818_port = UART_TO_RK2818(port);
278         struct tty_struct *tty = port->state->port.tty; 
279         int retval;     
280                 
281         retval = request_irq(port->irq,rk2818_uart_interrupt,IRQF_SHARED,
282                      tty ? tty->name : "rk2818_serial",port);
283         if(retval)
284         {
285                 printk("\nrk2818_serial_startup err \n");       
286                 rk2818_serial_shutdown(port);
287                 return  retval;
288         }       
289         clk_enable(rk2818_port->clk);
290         rk2818_uart_write(port,0xf1,UART_FCR);
291         rk2818_uart_write(port,0x01,UART_SFE);///enable fifo
292     rk2818_uart_write(port,UART_IER_RECV_DATA_AVAIL_INT_ENABLE,UART_IER);  //enable uart recevice IRQ
293         return 0;
294 }
295
296 /*
297  * Change the port parameters
298  */
299 static void rk2818_serial_set_termios(struct uart_port *port, struct ktermios *termios,
300                               struct ktermios *old)
301 {
302     unsigned long flags;
303     unsigned int mode, baud;
304         unsigned int umcon,fcr;
305     /* Get current mode register */
306     mode = rk2818_uart_read(port,UART_LCR) & (BREAK_CONTROL_BIT | EVEN_PARITY_SELECT | PARITY_ENABLED
307                        | ONE_HALF_OR_TWO_BIT | UART_DATABIT_MASK);  
308     
309     baud = uart_get_baud_rate(port, termios, old, 0, port->uartclk / 16);
310     /* byte size */
311     switch (termios->c_cflag & CSIZE) {
312     case CS5:
313         mode |= LCR_WLS_5;
314         break;
315     case CS6:
316         mode |= LCR_WLS_6;
317         break;
318     case CS7:
319         mode |= LCR_WLS_7;
320         break;
321     default:
322         mode |= LCR_WLS_8;
323         break;
324     }
325     
326     /* stop bits */
327     if (termios->c_cflag & CSTOPB)
328         mode |= ONE_STOP_BIT;
329     
330     /* parity */
331     if (termios->c_cflag & PARENB) 
332     {
333         mode |= PARITY_ENABLED;
334         if (termios->c_cflag & PARODD)
335             mode |= ODD_PARITY;
336         else
337             mode |= EVEN_PARITY;
338     }
339     spin_lock_irqsave(&port->lock, flags);
340         if(termios->c_cflag & CRTSCTS)                               
341         {        
342                         /*¿ªÆôuart0Ó²¼þÁ÷¿Ø*/
343                 printk("start CRTSCTS control and baudrate is %d\n",baud);
344                 umcon=rk2818_uart_read(port,UART_MCR);
345                 printk("UART_GET_MCR umcon=0x%x\n",umcon);
346                 umcon |= UART_MCR_AFCEN;
347                 umcon |= UART_MCR_URRTS;
348                 umcon &=~UART_SIR_ENABLE;
349                 rk2818_uart_write(port,umcon,UART_MCR);
350                 printk("UART_GET_MCR umcon=0x%x\n",umcon);
351                 fcr=rk2818_uart_read(port,UART_FCR);
352                 printk("UART_GET_MCR fcr=0x%x\n",fcr);
353                 fcr |= UART_FCR_FIFO_ENABLE;
354                 rk2818_uart_write(port,fcr,UART_FCR);           
355                 printk("UART_GET_MCR fcr=0x%x\n",fcr);
356         }
357     mode = mode | LCR_DLA_EN;
358     while(rk2818_uart_read(port,UART_USR)&UART_USR_BUSY)
359         cpu_relax(); 
360     rk2818_uart_write(port,mode,UART_LCR);
361     baud = rk2818_set_baud_rate(port, baud);
362     uart_update_timeout(port, termios->c_cflag, baud);
363     spin_unlock_irqrestore(&port->lock, flags);
364 }
365
366
367 static void rk2818_serial_release_port(struct uart_port *port)
368 {
369     struct platform_device *pdev = to_platform_device(port->dev);
370         struct resource *resource;
371         resource_size_t size;
372
373         resource = platform_get_resource(pdev, IORESOURCE_MEM, 0);
374         if (unlikely(!resource))
375                 return;
376         size = resource->end - resource->start + 1;
377
378         release_mem_region(port->mapbase, size);
379         iounmap(port->membase);
380         port->membase = NULL;
381 }
382
383 static int rk2818_serial_request_port(struct uart_port *port)
384 {
385         struct platform_device *pdev = to_platform_device(port->dev);
386         struct resource *resource;
387         resource_size_t size;
388
389         resource = platform_get_resource(pdev, IORESOURCE_MEM, 0);
390         if (unlikely(!resource))
391                 return -ENXIO;
392         size = resource->end - resource->start + 1;
393
394         if (unlikely(!request_mem_region(port->mapbase, size, "rk2818_serial")))
395                 return -EBUSY;
396
397         port->membase = ioremap(port->mapbase, size);
398         if (!port->membase) {
399                 release_mem_region(port->mapbase, size);
400                 return -EBUSY;
401         }
402
403         return 0;
404 }                     
405
406 /*
407  * Configure/autoconfigure the port.
408  */
409 static void rk2818_serial_config_port(struct uart_port *port, int flags)
410 {
411         if (flags & UART_CONFIG_TYPE) {
412                 port->type = PORT_RK2818;
413                 rk2818_serial_request_port(port);
414         }
415 }
416
417 /*
418  * Verify the new serial_struct (for TIOCSSERIAL).
419  */
420 static int rk2818_serial_verify_port(struct uart_port *port, struct serial_struct *ser)
421 {
422         int ret = 0;
423         if (ser->type != PORT_UNKNOWN && ser->type != PORT_RK2818)
424                 ret = -EINVAL;
425         if (port->irq != ser->irq)
426                 ret = -EINVAL;
427         if (ser->io_type != SERIAL_IO_MEM)
428                 ret = -EINVAL;
429         if (port->uartclk / 16 != ser->baud_base)
430                 ret = -EINVAL;
431         if ((void *)port->mapbase != ser->iomem_base)
432                 ret = -EINVAL;
433         if (port->iobase != ser->port)
434                 ret = -EINVAL;
435         if (ser->hub6 != 0)
436                 ret = -EINVAL;
437         return ret;
438 }
439
440 #ifdef CONFIG_CONSOLE_POLL
441 /*
442  * Console polling routines for writing and reading from the uart while
443  * in an interrupt or debug context.
444  */
445
446 static int rk2818_serial_poll_get_char(struct uart_port *port)
447 {
448         while (!((rk2818_uart_read(port, UART_USR) & UART_RECEIVE_FIFO_NOT_EMPTY) == UART_RECEIVE_FIFO_NOT_EMPTY))
449                 barrier();
450         return rk2818_uart_read(port, UART_RBR);
451 }
452
453 static void rk2818_serial_poll_put_char(struct uart_port *port, unsigned char c)
454 {
455         while (!(rk2818_uart_read(port, UART_USR) & UART_TRANSMIT_FIFO_NOT_FULL))
456                 barrier();
457         rk2818_uart_write(port, c, UART_THR);
458 }
459 #endif /* CONFIG_CONSOLE_POLL */
460
461 static struct uart_ops rk2818_uart_pops = {
462         .tx_empty = rk2818_serial_tx_empty,
463         .set_mctrl = rk2818_serial_set_mctrl,
464         .get_mctrl = rk2818_serial_get_mctrl,
465         .stop_tx = rk2818_serial_stop_tx,
466         .start_tx = rk2818_serial_start_tx,
467         .stop_rx = rk2818_serial_stop_rx,
468         .enable_ms = rk2818_serial_enable_ms,
469         .break_ctl = rk2818_serial_break_ctl,
470         .startup = rk2818_serial_startup,
471         .shutdown = rk2818_serial_shutdown,
472         .set_termios = rk2818_serial_set_termios,
473         .type = rk2818_serial_type,
474         .release_port = rk2818_serial_release_port,
475         .request_port = rk2818_serial_request_port,
476         .config_port = rk2818_serial_config_port,
477         .verify_port = rk2818_serial_verify_port,
478         .pm = rk2818_serial_pm,
479 #ifdef CONFIG_CONSOLE_POLL
480         .poll_get_char = rk2818_serial_poll_get_char,
481         .poll_put_char = rk2818_serial_poll_put_char,
482 #endif
483 };
484
485
486 static struct rk2818_port rk2818_uart_ports[] = {
487         {
488                 .uart = {
489                         .iotype = UPIO_MEM,
490                         .ops = &rk2818_uart_pops,
491                         .flags = UPF_BOOT_AUTOCONF,
492                         .fifosize = 32,
493                         .line = 0,
494                 },
495         },
496         {
497                 .uart = {
498                         .iotype = UPIO_MEM,
499                         .ops = &rk2818_uart_pops,
500                         .flags = UPF_BOOT_AUTOCONF,
501                         .fifosize = 32,
502                         .line = 1,
503                 },
504         },
505         {
506                 .uart = {
507                         .iotype = UPIO_MEM,
508                         .ops = &rk2818_uart_pops,
509                         .flags = UPF_BOOT_AUTOCONF,
510                         .fifosize = 32,
511                         .line = 2,
512                 },
513         },
514         {
515                 .uart = {
516                         .iotype = UPIO_MEM,
517                         .ops = &rk2818_uart_pops,
518                         .flags = UPF_BOOT_AUTOCONF,
519                         .fifosize = 32,
520                         .line = 3,
521                 },
522         },
523 };
524
525 #define UART_NR ARRAY_SIZE(rk2818_uart_ports)
526
527 static inline struct uart_port *get_port_from_line(unsigned int line)
528 {
529         return &rk2818_uart_ports[line].uart;
530 }
531
532 #ifdef CONFIG_SERIAL_RK2818_CONSOLE
533 static void rk2818_console_putchar(struct uart_port *port, int ch)
534 {
535     while (!(rk2818_uart_read(port,UART_USR) & UART_TRANSMIT_FIFO_NOT_FULL))
536                 cpu_relax();
537         rk2818_uart_write(port,ch,UART_THR);    
538 }
539
540 /*
541  * Interrupts are disabled on entering
542  */
543 static void rk2818_console_write(struct console *co, const char *s, u_int count)
544 {
545         struct uart_port *port;
546         struct rk2818_port *rk2818_port;
547
548         BUG_ON(co->index < 0 || co->index >= UART_NR);
549
550         port = get_port_from_line(co->index);
551         rk2818_port = UART_TO_RK2818(port);
552
553         spin_lock(&port->lock);
554         uart_console_write(port, s, count, rk2818_console_putchar);
555         spin_unlock(&port->lock);
556 }
557
558 static int __init rk2818_console_setup(struct console *co, char *options)
559 {
560         struct uart_port *port;
561         int baud, flow, bits, parity;
562         
563         if (unlikely(co->index >= UART_NR || co->index < 0))
564                 return -ENXIO;
565
566         port = get_port_from_line(co->index);
567
568         if (unlikely(!port->membase))
569                 return -ENXIO;
570
571         port->cons = co;
572
573         //rk2818_init_clock(port);
574
575         if (options)
576                 uart_parse_options(options, &baud, &parity, &bits, &flow);
577
578         bits = 8;
579         parity = 'n';
580         flow = 'n';     
581         rk2818_uart_write(port,rk2818_uart_read(port,UART_LCR) | LCR_WLS_8 | PARITY_DISABLED | ONE_STOP_BIT,UART_LCR);  /* 8N1 */
582         if (baud < 300 || baud > 115200)
583                 baud = 115200;
584         rk2818_set_baud_rate(port, baud);
585
586         printk(KERN_INFO "rk2818_serial: console setup on port %d\n", port->line);
587
588         return uart_set_options(port, co, baud, parity, bits, flow);    
589 }
590
591 static struct uart_driver rk2818_uart_driver;
592
593 static struct console rk2818_console = {
594         .name = "ttyS",
595         .write = rk2818_console_write,
596         .device = uart_console_device,
597         .setup = rk2818_console_setup,
598         .flags = CON_PRINTBUFFER,
599         .index = 1,  
600         .data = &rk2818_uart_driver,
601 };
602
603 #define RK2818_CONSOLE  (&rk2818_console)
604
605 #else
606 #define RK2818_CONSOLE  NULL
607 #endif
608
609 static struct uart_driver rk2818_uart_driver = {
610         .owner = THIS_MODULE,
611         .driver_name = "rk2818_serial",
612         .dev_name = "ttyS",
613         .nr = UART_NR,
614         .cons = RK2818_CONSOLE,
615         .major          = RK2818_SERIAL_MAJOR,  
616         .minor          = RK2818_SERIAL_MINOR,
617 };
618
619 static int __devinit rk2818_serial_probe(struct platform_device *pdev)
620 {
621         struct rk2818_port *rk2818_port;
622         struct resource *resource;
623         struct uart_port *port;
624     struct rk2818_serial_platform_data *pdata = pdev->dev.platform_data;
625                 
626         if (unlikely(pdev->id < 0 || pdev->id >= UART_NR))
627                 return -ENXIO;
628
629         printk(KERN_INFO "rk2818_serial: detected port %d\n", pdev->id);
630
631         if (pdata && pdata->io_init)
632                 pdata->io_init();
633     
634         port = get_port_from_line(pdev->id);
635         port->dev = &pdev->dev;
636         rk2818_port = UART_TO_RK2818(port);
637
638         rk2818_port->clk = clk_get(&pdev->dev, "uart");
639         if (unlikely(IS_ERR(rk2818_port->clk)))
640                 return PTR_ERR(rk2818_port->clk);
641         port->uartclk = clk_get_rate(rk2818_port->clk);
642
643         resource = platform_get_resource(pdev, IORESOURCE_MEM, 0);
644         if (unlikely(!resource))
645                 return -ENXIO;
646         port->mapbase = resource->start;
647
648         port->irq = platform_get_irq(pdev, 0);
649         if (unlikely(port->irq < 0))
650                 return -ENXIO;
651
652         platform_set_drvdata(pdev, port);
653
654         return uart_add_one_port(&rk2818_uart_driver, port);    
655 }
656
657 static int __devexit rk2818_serial_remove(struct platform_device *pdev)
658 {
659         struct rk2818_port *rk2818_port = platform_get_drvdata(pdev);
660
661         clk_put(rk2818_port->clk);
662
663         return 0;
664 }
665
666 static struct platform_driver rk2818_platform_driver = {
667         .remove = rk2818_serial_remove,
668         .driver = {
669                 .name = "rk2818_serial",
670                 .owner = THIS_MODULE,
671         },
672 };
673
674 static int __init rk2818_serial_init(void)
675 {
676         int ret;
677         ret = uart_register_driver(&rk2818_uart_driver);
678         if (unlikely(ret))
679                 return ret;
680
681         ret = platform_driver_probe(&rk2818_platform_driver, rk2818_serial_probe);
682         if (unlikely(ret))
683                 uart_unregister_driver(&rk2818_uart_driver);
684
685         printk(KERN_INFO "rk2818_serial: driver initialized\n");
686
687         return ret;
688 }
689
690 static void __exit rk2818_serial_exit(void)
691 {
692         #ifdef CONFIG_SERIAL_RK2818_CONSOLE
693         unregister_console(&rk2818_console);
694         #endif
695         platform_driver_unregister(&rk2818_platform_driver);
696         uart_unregister_driver(&rk2818_uart_driver);
697 }
698
699 /*
700  * While this can be a module, if builtin it's most likely the console
701  * So let's leave module_exit but move module_init to an earlier place
702  */
703 arch_initcall(rk2818_serial_init);
704 module_exit(rk2818_serial_exit);
705
706 MODULE_AUTHOR("lhh lhh@rock-chips.com");
707 MODULE_DESCRIPTION("Rockchip RK2818 Serial port driver");
708 MODULE_LICENSE("GPL");