[amazon] Add kernel 2.6.32 support
[openwrt/svn-archive/archive.git] / target / linux / amazon / files / drivers / serial / amazon_asc.c
1 /*
2 * Driver for AMAZONASC serial ports
3 *
4 * Based on drivers/char/serial.c, by Linus Torvalds, Theodore Ts'o.
5 * Based on drivers/serial/serial_s3c2400.c
6 *
7 * This program is free software; you can redistribute it and/or modify
8 * it under the terms of the GNU General Public License as published by
9 * the Free Software Foundation; either version 2 of the License, or
10 * (at your option) any later version.
11 *
12 * This program is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 * GNU General Public License for more details.
16 *
17 * You should have received a copy of the GNU General Public License
18 * along with this program; if not, write to the Free Software
19 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
20 *
21 * Copyright (C) 2004 Infineon IFAP DC COM CPE
22 * Copyright (C) 2007 Felix Fietkau <nbd@openwrt.org>
23 * Copyright (C) 2007 John Crispin <blogic@openwrt.org>
24 */
25
26 #include <linux/module.h>
27 #include <linux/errno.h>
28 #include <linux/signal.h>
29 #include <linux/sched.h>
30 #include <linux/interrupt.h>
31 #include <linux/tty.h>
32 #include <linux/tty_flip.h>
33 #include <linux/major.h>
34 #include <linux/string.h>
35 #include <linux/fcntl.h>
36 #include <linux/ptrace.h>
37 #include <linux/ioport.h>
38 #include <linux/mm.h>
39 #include <linux/slab.h>
40 #include <linux/init.h>
41 #include <linux/circ_buf.h>
42 #include <linux/serial.h>
43 #include <linux/serial_core.h>
44 #include <linux/console.h>
45 #include <linux/sysrq.h>
46 #include <linux/irq.h>
47 #include <linux/platform_device.h>
48
49 #include <asm/system.h>
50 #include <asm/io.h>
51 #include <asm/uaccess.h>
52 #include <asm/bitops.h>
53 #include <asm/amazon/amazon.h>
54 #include <asm/amazon/irq.h>
55 #include <asm/amazon/serial.h>
56
57 #define PORT_AMAZONASC 111
58
59 #include <linux/serial_core.h>
60
61 #define UART_NR 1
62
63 #define UART_DUMMY_UER_RX 1
64
65 #define SERIAL_AMAZONASC_MAJOR TTY_MAJOR
66 #define CALLOUT_AMAZONASC_MAJOR TTYAUX_MAJOR
67 #define SERIAL_AMAZONASC_MINOR 64
68 #define SERIAL_AMAZONASC_NR UART_NR
69
70 static void amazonasc_tx_chars(struct uart_port *port);
71 extern void prom_printf(const char * fmt, ...);
72 static struct uart_port amazonasc_ports[UART_NR];
73 static struct uart_driver amazonasc_reg;
74 static unsigned int uartclk = 0;
75 extern unsigned int amazon_get_fpi_hz(void);
76
77 static void amazonasc_stop_tx(struct uart_port *port)
78 {
79 /* fifo underrun shuts up after firing once */
80 return;
81 }
82
83 static void amazonasc_start_tx(struct uart_port *port)
84 {
85 unsigned long flags;
86
87 local_irq_save(flags);
88 amazonasc_tx_chars(port);
89 local_irq_restore(flags);
90
91 return;
92 }
93
94 static void amazonasc_stop_rx(struct uart_port *port)
95 {
96 /* clear the RX enable bit */
97 amazon_writel(ASCWHBCON_CLRREN, AMAZON_ASC_WHBCON);
98 }
99
100 static void amazonasc_enable_ms(struct uart_port *port)
101 {
102 /* no modem signals */
103 return;
104 }
105
106 #include <linux/version.h>
107
108 static void
109 amazonasc_rx_chars(struct uart_port *port)
110 {
111 #if (LINUX_VERSION_CODE > KERNEL_VERSION(2, 6, 31))
112 struct tty_struct *tty = port->state->port.tty;
113 #else
114 struct tty_struct *tty = port->info->port.tty;
115 #endif
116 unsigned int ch = 0, rsr = 0, fifocnt;
117
118 fifocnt = amazon_readl(AMAZON_ASC_FSTAT) & ASCFSTAT_RXFFLMASK;
119 while (fifocnt--)
120 {
121 u8 flag = TTY_NORMAL;
122 ch = amazon_readl(AMAZON_ASC_RBUF);
123 rsr = (amazon_readl(AMAZON_ASC_CON) & ASCCON_ANY) | UART_DUMMY_UER_RX;
124 tty_flip_buffer_push(tty);
125 port->icount.rx++;
126
127 /*
128 * Note that the error handling code is
129 * out of the main execution path
130 */
131 if (rsr & ASCCON_ANY) {
132 if (rsr & ASCCON_PE) {
133 port->icount.parity++;
134 amazon_writel_masked(AMAZON_ASC_WHBCON, ASCWHBCON_CLRPE, ASCWHBCON_CLRPE);
135 } else if (rsr & ASCCON_FE) {
136 port->icount.frame++;
137 amazon_writel_masked(AMAZON_ASC_WHBCON, ASCWHBCON_CLRFE, ASCWHBCON_CLRFE);
138 }
139 if (rsr & ASCCON_OE) {
140 port->icount.overrun++;
141 amazon_writel_masked(AMAZON_ASC_WHBCON, ASCWHBCON_CLROE, ASCWHBCON_CLROE);
142 }
143
144 rsr &= port->read_status_mask;
145
146 if (rsr & ASCCON_PE)
147 flag = TTY_PARITY;
148 else if (rsr & ASCCON_FE)
149 flag = TTY_FRAME;
150 }
151
152 if ((rsr & port->ignore_status_mask) == 0)
153 tty_insert_flip_char(tty, ch, flag);
154
155 if (rsr & ASCCON_OE)
156 /*
157 * Overrun is special, since it's reported
158 * immediately, and doesn't affect the current
159 * character
160 */
161 tty_insert_flip_char(tty, 0, TTY_OVERRUN);
162 }
163 if (ch != 0)
164 tty_flip_buffer_push(tty);
165
166 return;
167 }
168
169
170 static void amazonasc_tx_chars(struct uart_port *port)
171 {
172 #if (LINUX_VERSION_CODE > KERNEL_VERSION(2, 6, 31))
173 struct circ_buf *xmit = &port->state->xmit;
174 #else
175 struct circ_buf *xmit = &port->info->xmit;
176 #endif
177
178 if (uart_tx_stopped(port)) {
179 amazonasc_stop_tx(port);
180 return;
181 }
182
183 while (((amazon_readl(AMAZON_ASC_FSTAT) & ASCFSTAT_TXFFLMASK)
184 >> ASCFSTAT_TXFFLOFF) != AMAZONASC_TXFIFO_FULL)
185 {
186 if (port->x_char) {
187 amazon_writel(port->x_char, AMAZON_ASC_TBUF);
188 port->icount.tx++;
189 port->x_char = 0;
190 continue;
191 }
192
193 if (uart_circ_empty(xmit))
194 break;
195
196 amazon_writel(xmit->buf[xmit->tail], AMAZON_ASC_TBUF);
197 xmit->tail = (xmit->tail + 1) & (UART_XMIT_SIZE - 1);
198 port->icount.tx++;
199 }
200
201 if (uart_circ_chars_pending(xmit) < WAKEUP_CHARS)
202 uart_write_wakeup(port);
203 }
204
205 static irqreturn_t amazonasc_tx_int(int irq, void *port)
206 {
207 amazon_writel(ASC_IRNCR_TIR, AMAZON_ASC_IRNCR1);
208 amazonasc_start_tx(port);
209
210 /* clear any pending interrupts */
211 amazon_writel_masked(AMAZON_ASC_WHBCON,
212 (ASCWHBCON_CLRPE | ASCWHBCON_CLRFE | ASCWHBCON_CLROE),
213 (ASCWHBCON_CLRPE | ASCWHBCON_CLRFE | ASCWHBCON_CLROE));
214
215 return IRQ_HANDLED;
216 }
217
218 static irqreturn_t amazonasc_er_int(int irq, void *port)
219 {
220 /* clear any pending interrupts */
221 amazon_writel_masked(AMAZON_ASC_WHBCON,
222 (ASCWHBCON_CLRPE | ASCWHBCON_CLRFE | ASCWHBCON_CLROE),
223 (ASCWHBCON_CLRPE | ASCWHBCON_CLRFE | ASCWHBCON_CLROE));
224
225 return IRQ_HANDLED;
226 }
227
228 static irqreturn_t amazonasc_rx_int(int irq, void *port)
229 {
230 amazon_writel(ASC_IRNCR_RIR, AMAZON_ASC_IRNCR1);
231 amazonasc_rx_chars((struct uart_port *) port);
232 return IRQ_HANDLED;
233 }
234
235 static u_int amazonasc_tx_empty(struct uart_port *port)
236 {
237 int status;
238
239 /*
240 * FSTAT tells exactly how many bytes are in the FIFO.
241 * The question is whether we really need to wait for all
242 * 16 bytes to be transmitted before reporting that the
243 * transmitter is empty.
244 */
245 status = amazon_readl(AMAZON_ASC_FSTAT) & ASCFSTAT_TXFFLMASK;
246 return status ? 0 : TIOCSER_TEMT;
247 }
248
249 static u_int amazonasc_get_mctrl(struct uart_port *port)
250 {
251 /* no modem control signals - the readme says to pretend all are set */
252 return TIOCM_CTS|TIOCM_CAR|TIOCM_DSR;
253 }
254
255 static void amazonasc_set_mctrl(struct uart_port *port, u_int mctrl)
256 {
257 /* no modem control - just return */
258 return;
259 }
260
261 static void amazonasc_break_ctl(struct uart_port *port, int break_state)
262 {
263 /* no way to send a break */
264 return;
265 }
266
267 static int amazonasc_startup(struct uart_port *port)
268 {
269 unsigned int con = 0;
270 unsigned long flags;
271 int retval;
272
273 /* this assumes: CON.BRS = CON.FDE = 0 */
274 if (uartclk == 0)
275 uartclk = amazon_get_fpi_hz();
276
277 amazonasc_ports[0].uartclk = uartclk;
278
279 local_irq_save(flags);
280
281 /* this setup was probably already done in u-boot */
282 /* ASC and GPIO Port 1 bits 3 and 4 share the same pins
283 * P1.3 (RX) in, Alternate 10
284 * P1.4 (TX) in, Alternate 10
285 */
286 amazon_writel_masked(AMAZON_GPIO_P1_DIR, 0x18, 0x10); //P1.4 output, P1.3 input
287 amazon_writel_masked(AMAZON_GPIO_P1_ALTSEL0, 0x18, 0x18); //ALTSETL0 11
288 amazon_writel_masked(AMAZON_GPIO_P1_ALTSEL1, 0x18, 0); //ALTSETL1 00
289 amazon_writel_masked(AMAZON_GPIO_P1_OD, 0x18, 0x10);
290
291 /* set up the CLC */
292 amazon_writel_masked(AMAZON_ASC_CLC, AMAZON_ASC_CLC_DISS, 0);
293 amazon_writel_masked(AMAZON_ASC_CLC, ASCCLC_RMCMASK, 1 << ASCCLC_RMCOFFSET);
294
295 /* asynchronous mode */
296 con = ASCCON_M_8ASYNC | ASCCON_FEN | ASCCON_OEN | ASCCON_PEN;
297
298 /* choose the line - there's only one */
299 amazon_writel(0, AMAZON_ASC_PISEL);
300 amazon_writel(((AMAZONASC_TXFIFO_FL << ASCTXFCON_TXFITLOFF) & ASCTXFCON_TXFITLMASK) | ASCTXFCON_TXFEN | ASCTXFCON_TXFFLU,
301 AMAZON_ASC_TXFCON);
302 amazon_writel(((AMAZONASC_RXFIFO_FL << ASCRXFCON_RXFITLOFF) & ASCRXFCON_RXFITLMASK) | ASCRXFCON_RXFEN | ASCRXFCON_RXFFLU,
303 AMAZON_ASC_RXFCON);
304 wmb();
305
306 amazon_writel_masked(AMAZON_ASC_CON, con, con);
307
308 retval = request_irq(AMAZONASC_RIR, amazonasc_rx_int, 0, "asc_rx", port);
309 if (retval){
310 printk("failed to request amazonasc_rx_int\n");
311 return retval;
312 }
313 retval = request_irq(AMAZONASC_TIR, amazonasc_tx_int, 0, "asc_tx", port);
314 if (retval){
315 printk("failed to request amazonasc_tx_int\n");
316 goto err1;
317 }
318
319 retval = request_irq(AMAZONASC_EIR, amazonasc_er_int, 0, "asc_er", port);
320 if (retval){
321 printk("failed to request amazonasc_er_int\n");
322 goto err2;
323 }
324
325 local_irq_restore(flags);
326 return 0;
327
328 err2:
329 free_irq(AMAZONASC_TIR, port);
330
331 err1:
332 free_irq(AMAZONASC_RIR, port);
333 local_irq_restore(flags);
334 return retval;
335 }
336
337 static void amazonasc_shutdown(struct uart_port *port)
338 {
339 free_irq(AMAZONASC_RIR, port);
340 free_irq(AMAZONASC_TIR, port);
341 free_irq(AMAZONASC_EIR, port);
342 /*
343 * disable the baudrate generator to disable the ASC
344 */
345 amazon_writel(0, AMAZON_ASC_CON);
346
347 /* flush and then disable the fifos */
348 amazon_writel_masked(AMAZON_ASC_RXFCON, ASCRXFCON_RXFFLU, ASCRXFCON_RXFFLU);
349 amazon_writel_masked(AMAZON_ASC_RXFCON, ASCRXFCON_RXFEN, 0);
350 amazon_writel_masked(AMAZON_ASC_TXFCON, ASCTXFCON_TXFFLU, ASCTXFCON_TXFFLU);
351 amazon_writel_masked(AMAZON_ASC_TXFCON, ASCTXFCON_TXFEN, 0);
352 }
353
354 static void amazonasc_set_termios(struct uart_port *port, struct ktermios *new, struct ktermios *old)
355 {
356 unsigned int cflag;
357 unsigned int iflag;
358 unsigned int baud, quot;
359 unsigned int con = 0;
360 unsigned long flags;
361
362 cflag = new->c_cflag;
363 iflag = new->c_iflag;
364
365 /* byte size and parity */
366 switch (cflag & CSIZE) {
367 /* 7 bits are always with parity */
368 case CS7: con = ASCCON_M_7ASYNCPAR; break;
369 /* the ASC only suports 7 and 8 bits */
370 case CS5:
371 case CS6:
372 default:
373 if (cflag & PARENB)
374 con = ASCCON_M_8ASYNCPAR;
375 else
376 con = ASCCON_M_8ASYNC;
377 break;
378 }
379 if (cflag & CSTOPB)
380 con |= ASCCON_STP;
381 if (cflag & PARENB) {
382 if (!(cflag & PARODD))
383 con &= ~ASCCON_ODD;
384 else
385 con |= ASCCON_ODD;
386 }
387
388 port->read_status_mask = ASCCON_OE;
389 if (iflag & INPCK)
390 port->read_status_mask |= ASCCON_FE | ASCCON_PE;
391
392 port->ignore_status_mask = 0;
393 if (iflag & IGNPAR)
394 port->ignore_status_mask |= ASCCON_FE | ASCCON_PE;
395
396 if (iflag & IGNBRK) {
397 /*
398 * If we're ignoring parity and break indicators,
399 * ignore overruns too (for real raw support).
400 */
401 if (iflag & IGNPAR)
402 port->ignore_status_mask |= ASCCON_OE;
403 }
404
405 /*
406 * Ignore all characters if CREAD is not set.
407 */
408 if ((cflag & CREAD) == 0)
409 port->ignore_status_mask |= UART_DUMMY_UER_RX;
410
411 /* set error signals - framing, parity and overrun */
412 con |= ASCCON_FEN;
413 con |= ASCCON_OEN;
414 con |= ASCCON_PEN;
415 /* enable the receiver */
416 con |= ASCCON_REN;
417
418 /* block the IRQs */
419 local_irq_save(flags);
420
421 /* set up CON */
422 amazon_writel(con, AMAZON_ASC_CON);
423
424 /* Set baud rate - take a divider of 2 into account */
425 baud = uart_get_baud_rate(port, new, old, 0, port->uartclk/16);
426 quot = uart_get_divisor(port, baud);
427 quot = quot/2 - 1;
428
429 /* the next 3 probably already happened when we set CON above */
430 /* disable the baudrate generator */
431 amazon_writel_masked(AMAZON_ASC_CON, ASCCON_R, 0);
432 /* make sure the fractional divider is off */
433 amazon_writel_masked(AMAZON_ASC_CON, ASCCON_FDE, 0);
434 /* set up to use divisor of 2 */
435 amazon_writel_masked(AMAZON_ASC_CON, ASCCON_BRS, 0);
436 /* now we can write the new baudrate into the register */
437 amazon_writel(quot, AMAZON_ASC_BTR);
438 /* turn the baudrate generator back on */
439 amazon_writel_masked(AMAZON_ASC_CON, ASCCON_R, ASCCON_R);
440
441 local_irq_restore(flags);
442 }
443
444 static const char *amazonasc_type(struct uart_port *port)
445 {
446 return port->type == PORT_AMAZONASC ? "AMAZONASC" : NULL;
447 }
448
449 /*
450 * Release the memory region(s) being used by 'port'
451 */
452 static void amazonasc_release_port(struct uart_port *port)
453 {
454 return;
455 }
456
457 /*
458 * Request the memory region(s) being used by 'port'
459 */
460 static int amazonasc_request_port(struct uart_port *port)
461 {
462 return 0;
463 }
464
465 /*
466 * Configure/autoconfigure the port.
467 */
468 static void amazonasc_config_port(struct uart_port *port, int flags)
469 {
470 if (flags & UART_CONFIG_TYPE) {
471 port->type = PORT_AMAZONASC;
472 amazonasc_request_port(port);
473 }
474 }
475
476 /*
477 * verify the new serial_struct (for TIOCSSERIAL).
478 */
479 static int amazonasc_verify_port(struct uart_port *port, struct serial_struct *ser)
480 {
481 int ret = 0;
482 if (ser->type != PORT_UNKNOWN && ser->type != PORT_AMAZONASC)
483 ret = -EINVAL;
484 if (ser->irq < 0 || ser->irq >= NR_IRQS)
485 ret = -EINVAL;
486 if (ser->baud_base < 9600)
487 ret = -EINVAL;
488 return ret;
489 }
490
491 static struct uart_ops amazonasc_pops = {
492 .tx_empty = amazonasc_tx_empty,
493 .set_mctrl = amazonasc_set_mctrl,
494 .get_mctrl = amazonasc_get_mctrl,
495 .stop_tx = amazonasc_stop_tx,
496 .start_tx = amazonasc_start_tx,
497 .stop_rx = amazonasc_stop_rx,
498 .enable_ms = amazonasc_enable_ms,
499 .break_ctl = amazonasc_break_ctl,
500 .startup = amazonasc_startup,
501 .shutdown = amazonasc_shutdown,
502 .set_termios = amazonasc_set_termios,
503 .type = amazonasc_type,
504 .release_port = amazonasc_release_port,
505 .request_port = amazonasc_request_port,
506 .config_port = amazonasc_config_port,
507 .verify_port = amazonasc_verify_port,
508 };
509
510 static struct uart_port amazonasc_ports[UART_NR] = {
511 {
512 membase: (void *)AMAZON_ASC,
513 mapbase: AMAZON_ASC,
514 iotype: SERIAL_IO_MEM,
515 irq: AMAZONASC_RIR, /* RIR */
516 uartclk: 0, /* filled in dynamically */
517 fifosize: 16,
518 unused: { AMAZONASC_TIR, AMAZONASC_EIR}, /* xmit/error/xmit-buffer-empty IRQ */
519 type: PORT_AMAZONASC,
520 ops: &amazonasc_pops,
521 flags: ASYNC_BOOT_AUTOCONF,
522 },
523 };
524
525 static void amazonasc_console_write(struct console *co, const char *s, u_int count)
526 {
527 int i, fifocnt;
528 unsigned long flags;
529 local_irq_save(flags);
530 for (i = 0; i < count;)
531 {
532 /* wait until the FIFO is not full */
533 do
534 {
535 fifocnt = (amazon_readl(AMAZON_ASC_FSTAT) & ASCFSTAT_TXFFLMASK)
536 >> ASCFSTAT_TXFFLOFF;
537 } while (fifocnt == AMAZONASC_TXFIFO_FULL);
538 if (s[i] == '\0')
539 {
540 break;
541 }
542 if (s[i] == '\n')
543 {
544 amazon_writel('\r', AMAZON_ASC_TBUF);
545 do
546 {
547 fifocnt = (amazon_readl(AMAZON_ASC_FSTAT) &
548 ASCFSTAT_TXFFLMASK) >> ASCFSTAT_TXFFLOFF;
549 } while (fifocnt == AMAZONASC_TXFIFO_FULL);
550 }
551 amazon_writel(s[i], AMAZON_ASC_TBUF);
552 i++;
553 }
554
555 local_irq_restore(flags);
556 }
557
558 static void __init
559 amazonasc_console_get_options(struct uart_port *port, int *baud, int *parity, int *bits)
560 {
561 u_int lcr_h;
562
563 lcr_h = amazon_readl(AMAZON_ASC_CON);
564 /* do this only if the ASC is turned on */
565 if (lcr_h & ASCCON_R) {
566 u_int quot, div, fdiv, frac;
567
568 *parity = 'n';
569 if ((lcr_h & ASCCON_MODEMASK) == ASCCON_M_7ASYNCPAR ||
570 (lcr_h & ASCCON_MODEMASK) == ASCCON_M_8ASYNCPAR) {
571 if (lcr_h & ASCCON_ODD)
572 *parity = 'o';
573 else
574 *parity = 'e';
575 }
576
577 if ((lcr_h & ASCCON_MODEMASK) == ASCCON_M_7ASYNCPAR)
578 *bits = 7;
579 else
580 *bits = 8;
581
582 quot = amazon_readl(AMAZON_ASC_BTR) + 1;
583
584 /* this gets hairy if the fractional divider is used */
585 if (lcr_h & ASCCON_FDE)
586 {
587 div = 1;
588 fdiv = amazon_readl(AMAZON_ASC_FDV);
589 if (fdiv == 0)
590 fdiv = 512;
591 frac = 512;
592 }
593 else
594 {
595 div = lcr_h & ASCCON_BRS ? 3 : 2;
596 fdiv = frac = 1;
597 }
598 /*
599 * This doesn't work exactly because we use integer
600 * math to calculate baud which results in rounding
601 * errors when we try to go from quot -> baud !!
602 * Try to make this work for both the fractional divider
603 * and the simple divider. Also try to avoid rounding
604 * errors using integer math.
605 */
606
607 *baud = frac * (port->uartclk / (div * 512 * 16 * quot));
608 if (*baud > 1100 && *baud < 2400)
609 *baud = 1200;
610 if (*baud > 2300 && *baud < 4800)
611 *baud = 2400;
612 if (*baud > 4700 && *baud < 9600)
613 *baud = 4800;
614 if (*baud > 9500 && *baud < 19200)
615 *baud = 9600;
616 if (*baud > 19000 && *baud < 38400)
617 *baud = 19200;
618 if (*baud > 38400 && *baud < 57600)
619 *baud = 38400;
620 if (*baud > 57600 && *baud < 115200)
621 *baud = 57600;
622 if (*baud > 115200 && *baud < 230400)
623 *baud = 115200;
624 }
625 }
626
627 static int __init amazonasc_console_setup(struct console *co, char *options)
628 {
629 struct uart_port *port;
630 int baud = 115200;
631 int bits = 8;
632 int parity = 'n';
633 int flow = 'n';
634
635 /* this assumes: CON.BRS = CON.FDE = 0 */
636 if (uartclk == 0)
637 uartclk = amazon_get_fpi_hz();
638 co->index = 0;
639 port = &amazonasc_ports[0];
640 amazonasc_ports[0].uartclk = uartclk;
641 amazonasc_ports[0].type = PORT_AMAZONASC;
642
643 if (options){
644 uart_parse_options(options, &baud, &parity, &bits, &flow);
645 }
646
647 return uart_set_options(port, co, baud, parity, bits, flow);
648 }
649
650 static struct uart_driver amazonasc_reg;
651 static struct console amazonasc_console = {
652 name: "ttyS",
653 write: amazonasc_console_write,
654 device: uart_console_device,
655 setup: amazonasc_console_setup,
656 flags: CON_PRINTBUFFER,
657 index: -1,
658 data: &amazonasc_reg,
659 };
660
661 static int __init amazonasc_console_init(void)
662 {
663 register_console(&amazonasc_console);
664 return 0;
665 }
666 console_initcall(amazonasc_console_init);
667
668 static struct uart_driver amazonasc_reg = {
669 .owner = THIS_MODULE,
670 .driver_name = "serial",
671 .dev_name = "ttyS",
672 .major = TTY_MAJOR,
673 .minor = 64,
674 .nr = UART_NR,
675 .cons = &amazonasc_console,
676 };
677
678 static int __init amazon_asc_probe(struct platform_device *dev)
679 {
680 unsigned char res;
681 uart_register_driver(&amazonasc_reg);
682 res = uart_add_one_port(&amazonasc_reg, &amazonasc_ports[0]);
683 return res;
684 }
685
686 static int amazon_asc_remove(struct platform_device *dev)
687 {
688 uart_unregister_driver(&amazonasc_reg);
689 return 0;
690 }
691
692 static struct platform_driver amazon_asc_driver = {
693 .probe = amazon_asc_probe,
694 .remove = amazon_asc_remove,
695 .driver = {
696 .name = "amazon_asc",
697 .owner = THIS_MODULE,
698 },
699 };
700
701 static int __init amazon_asc_init(void)
702 {
703 int ret = platform_driver_register(&amazon_asc_driver);
704 if (ret)
705 printk(KERN_WARNING "amazon_asc: error registering platfom driver!\n");
706 return ret;
707 }
708
709 static void __exit amazon_asc_cleanup(void)
710 {
711 platform_driver_unregister(&amazon_asc_driver);
712 }
713
714 module_init(amazon_asc_init);
715 module_exit(amazon_asc_cleanup);
716
717 MODULE_AUTHOR("Gary Jennejohn, Felix Fietkau, John Crispin");
718 MODULE_DESCRIPTION("MIPS AMAZONASC serial port driver");
719 MODULE_LICENSE("GPL");
720