2 * drivers/serial/mpc52xx_uart.c
4 * Driver for the PSC of the Freescale MPC52xx PSCs configured as UARTs.
6 * FIXME According to the usermanual the status bits in the status register
7 * are only updated when the peripherals access the FIFO and not when the
8 * CPU access them. So since we use this bits to know when we stop writing
9 * and reading, they may not be updated in-time and a race condition may
10 * exists. But I haven't be able to prove this and I don't care. But if
11 * any problem arises, it might worth checking. The TX/RX FIFO Stats
12 * registers should be used in addition.
13 * Update: Actually, they seem updated ... At least the bits we use.
16 * Maintainer : Sylvain Munaut <tnt@246tNt.com>
18 * Some of the code has been inspired/copied from the 2.4 code written
19 * by Dale Farnsworth <dfarnsworth@mvista.com>.
21 * Copyright (C) 2004 Sylvain Munaut <tnt@246tNt.com>
22 * Copyright (C) 2003 MontaVista, Software, Inc.
24 * This file is licensed under the terms of the GNU General Public License
25 * version 2. This program is licensed "as is" without any warranty of any
26 * kind, whether express or implied.
31 * This drivers uses the OCP model. To load the serial driver for one of the
32 * PSCs, just add this to the core_ocp table :
35 * .vendor = OCP_VENDOR_FREESCALE,
36 * .function = OCP_FUNC_PSC_UART,
38 * .paddr = MPC52xx_PSC1,
39 * .irq = MPC52xx_PSC1_IRQ,
43 * This is for PSC1, replace the paddr and irq according to the PSC you want to
44 * use. The driver all necessary registers to place the PSC in uart mode without
45 * DCD. However, the pin multiplexing aren't changed and should be set either
46 * by the bootloader or in the platform init code.
47 * The index field must be equal to the PSC index ( e.g. 0 for PSC1, 1 for PSC2,
48 * and so on). So the PSC1 is mapped to /dev/ttyS0, PSC2 to /dev/ttyS1 and so
49 * on. But be warned, it's an ABSOLUTE REQUIREMENT ! This is needed mainly for
50 * the console code : without this 1:1 mapping, at early boot time, when we are
51 * parsing the kernel args console=ttyS?, we wouldn't know wich PSC it will be
52 * mapped to because OCP stuff is not yet initialized.
55 #include <linux/config.h>
56 #include <linux/module.h>
57 #include <linux/tty.h>
58 #include <linux/serial.h>
59 #include <linux/sysrq.h>
60 #include <linux/console.h>
62 #include <asm/delay.h>
66 #include <asm/mpc52xx.h>
67 #include <asm/mpc52xx_psc.h>
69 #if defined(CONFIG_SERIAL_MPC52xx_CONSOLE) && defined(CONFIG_MAGIC_SYSRQ)
73 #include <linux/serial_core.h>
77 #define ISR_PASS_LIMIT 256 /* Max number of iteration in the interrupt */
80 static struct uart_port mpc52xx_uart_ports
[MPC52xx_PSC_MAXNUM
];
81 /* Rem: - We use the read_status_mask as a shadow of
82 * psc->mpc52xx_psc_imr
83 * - It's important that is array is all zero on start as we
84 * use it to know if it's initialized or not ! If it's not sure
85 * it's cleared, then a memset(...,0,...) should be added to
89 #define PSC(port) ((struct mpc52xx_psc *)((port)->membase))
92 /* Forward declaration of the interruption handling routine */
93 static irqreturn_t
mpc52xx_uart_int(int irq
,void *dev_id
,struct pt_regs
*regs
);
96 /* Simple macro to test if a port is console or not. This one is taken
97 * for serial_core.c and maybe should be moved to serial_core.h ? */
98 #ifdef CONFIG_SERIAL_CORE_CONSOLE
99 #define uart_console(port) ((port)->cons && (port)->cons->index == (port)->line)
101 #define uart_console(port) (0)
105 /* ======================================================================== */
106 /* UART operations */
107 /* ======================================================================== */
110 mpc52xx_uart_tx_empty(struct uart_port
*port
)
112 int status
= in_be16(&PSC(port
)->mpc52xx_psc_status
);
113 return (status
& MPC52xx_PSC_SR_TXEMP
) ? TIOCSER_TEMT
: 0;
117 mpc52xx_uart_set_mctrl(struct uart_port
*port
, unsigned int mctrl
)
119 /* Not implemented */
123 mpc52xx_uart_get_mctrl(struct uart_port
*port
)
125 /* Not implemented */
126 return TIOCM_CTS
| TIOCM_DSR
| TIOCM_CAR
;
130 mpc52xx_uart_stop_tx(struct uart_port
*port
, unsigned int tty_stop
)
132 /* port->lock taken by caller */
133 port
->read_status_mask
&= ~MPC52xx_PSC_IMR_TXRDY
;
134 out_be16(&PSC(port
)->mpc52xx_psc_imr
,port
->read_status_mask
);
138 mpc52xx_uart_start_tx(struct uart_port
*port
, unsigned int tty_start
)
140 /* port->lock taken by caller */
141 port
->read_status_mask
|= MPC52xx_PSC_IMR_TXRDY
;
142 out_be16(&PSC(port
)->mpc52xx_psc_imr
,port
->read_status_mask
);
146 mpc52xx_uart_send_xchar(struct uart_port
*port
, char ch
)
149 spin_lock_irqsave(&port
->lock
, flags
);
153 /* Make sure tx interrupts are on */
154 /* Truly necessary ??? They should be anyway */
155 port
->read_status_mask
|= MPC52xx_PSC_IMR_TXRDY
;
156 out_be16(&PSC(port
)->mpc52xx_psc_imr
,port
->read_status_mask
);
159 spin_unlock_irqrestore(&port
->lock
, flags
);
163 mpc52xx_uart_stop_rx(struct uart_port
*port
)
165 /* port->lock taken by caller */
166 port
->read_status_mask
&= ~MPC52xx_PSC_IMR_RXRDY
;
167 out_be16(&PSC(port
)->mpc52xx_psc_imr
,port
->read_status_mask
);
171 mpc52xx_uart_enable_ms(struct uart_port
*port
)
173 /* Not implemented */
177 mpc52xx_uart_break_ctl(struct uart_port
*port
, int ctl
)
180 spin_lock_irqsave(&port
->lock
, flags
);
183 out_8(&PSC(port
)->command
,MPC52xx_PSC_START_BRK
);
185 out_8(&PSC(port
)->command
,MPC52xx_PSC_STOP_BRK
);
187 spin_unlock_irqrestore(&port
->lock
, flags
);
191 mpc52xx_uart_startup(struct uart_port
*port
)
193 struct mpc52xx_psc
*psc
= PSC(port
);
195 /* Reset/activate the port, clear and enable interrupts */
196 out_8(&psc
->command
,MPC52xx_PSC_RST_RX
);
197 out_8(&psc
->command
,MPC52xx_PSC_RST_TX
);
199 out_be32(&psc
->sicr
,0); /* UART mode DCD ignored */
201 out_be16(&psc
->mpc52xx_psc_clock_select
, 0xdd00); /* /16 prescaler on */
203 out_8(&psc
->rfcntl
, 0x00);
204 out_be16(&psc
->rfalarm
, 0x1ff);
205 out_8(&psc
->tfcntl
, 0x07);
206 out_be16(&psc
->tfalarm
, 0x80);
208 port
->read_status_mask
|= MPC52xx_PSC_IMR_RXRDY
| MPC52xx_PSC_IMR_TXRDY
;
209 out_be16(&psc
->mpc52xx_psc_imr
,port
->read_status_mask
);
211 out_8(&psc
->command
,MPC52xx_PSC_TX_ENABLE
);
212 out_8(&psc
->command
,MPC52xx_PSC_RX_ENABLE
);
218 mpc52xx_uart_shutdown(struct uart_port
*port
)
220 struct mpc52xx_psc
*psc
= PSC(port
);
222 /* Shut down the port, interrupt and all */
223 out_8(&psc
->command
,MPC52xx_PSC_RST_RX
);
224 out_8(&psc
->command
,MPC52xx_PSC_RST_TX
);
226 port
->read_status_mask
= 0;
227 out_be16(&psc
->mpc52xx_psc_imr
,port
->read_status_mask
);
231 mpc52xx_uart_set_termios(struct uart_port
*port
, struct termios
*new,
234 struct mpc52xx_psc
*psc
= PSC(port
);
236 unsigned char mr1
, mr2
;
238 unsigned int j
, baud
, quot
;
240 /* Prepare what we're gonna write */
243 switch (new->c_cflag
& CSIZE
) {
244 case CS5
: mr1
|= MPC52xx_PSC_MODE_5_BITS
;
246 case CS6
: mr1
|= MPC52xx_PSC_MODE_6_BITS
;
248 case CS7
: mr1
|= MPC52xx_PSC_MODE_7_BITS
;
251 default: mr1
|= MPC52xx_PSC_MODE_8_BITS
;
254 if (new->c_cflag
& PARENB
) {
255 mr1
|= (new->c_cflag
& PARODD
) ?
256 MPC52xx_PSC_MODE_PARODD
: MPC52xx_PSC_MODE_PAREVEN
;
258 mr1
|= MPC52xx_PSC_MODE_PARNONE
;
263 if (new->c_cflag
& CSTOPB
)
264 mr2
|= MPC52xx_PSC_MODE_TWO_STOP
;
266 mr2
|= ((new->c_cflag
& CSIZE
) == CS5
) ?
267 MPC52xx_PSC_MODE_ONE_STOP_5_BITS
:
268 MPC52xx_PSC_MODE_ONE_STOP
;
271 baud
= uart_get_baud_rate(port
, new, old
, 0, port
->uartclk
/16);
272 quot
= uart_get_divisor(port
, baud
);
276 spin_lock_irqsave(&port
->lock
, flags
);
278 /* Update the per-port timeout */
279 uart_update_timeout(port
, new->c_cflag
, baud
);
281 /* Do our best to flush TX & RX, so we don't loose anything */
282 /* But we don't wait indefinitly ! */
283 j
= 5000000; /* Maximum wait */
284 /* FIXME Can't receive chars since set_termios might be called at early
285 * boot for the console, all stuff is not yet ready to receive at that
286 * time and that just makes the kernel oops */
287 /* while (j-- && mpc52xx_uart_int_rx_chars(port)); */
288 while (!(in_be16(&psc
->mpc52xx_psc_status
) & MPC52xx_PSC_SR_TXEMP
) &&
293 printk( KERN_ERR
"mpc52xx_uart.c: "
294 "Unable to flush RX & TX fifos in-time in set_termios."
295 "Some chars may have been lost.\n" );
297 /* Reset the TX & RX */
298 out_8(&psc
->command
,MPC52xx_PSC_RST_RX
);
299 out_8(&psc
->command
,MPC52xx_PSC_RST_TX
);
301 /* Send new mode settings */
302 out_8(&psc
->command
,MPC52xx_PSC_SEL_MODE_REG_1
);
303 out_8(&psc
->mode
,mr1
);
304 out_8(&psc
->mode
,mr2
);
305 out_8(&psc
->ctur
,ctr
>> 8);
306 out_8(&psc
->ctlr
,ctr
& 0xff);
308 /* Reenable TX & RX */
309 out_8(&psc
->command
,MPC52xx_PSC_TX_ENABLE
);
310 out_8(&psc
->command
,MPC52xx_PSC_RX_ENABLE
);
312 /* We're all set, release the lock */
313 spin_unlock_irqrestore(&port
->lock
, flags
);
317 mpc52xx_uart_type(struct uart_port
*port
)
319 return port
->type
== PORT_MPC52xx
? "MPC52xx PSC" : NULL
;
323 mpc52xx_uart_release_port(struct uart_port
*port
)
325 if (port
->flags
& UPF_IOREMAP
) { /* remapped by us ? */
326 iounmap(port
->membase
);
327 port
->membase
= NULL
;
332 mpc52xx_uart_request_port(struct uart_port
*port
)
334 if (port
->flags
& UPF_IOREMAP
) /* Need to remap ? */
335 port
->membase
= ioremap(port
->mapbase
, sizeof(struct mpc52xx_psc
));
337 return port
->membase
!= NULL
? 0 : -EBUSY
;
341 mpc52xx_uart_config_port(struct uart_port
*port
, int flags
)
343 if ( (flags
& UART_CONFIG_TYPE
) &&
344 (mpc52xx_uart_request_port(port
) == 0) )
345 port
->type
= PORT_MPC52xx
;
349 mpc52xx_uart_verify_port(struct uart_port
*port
, struct serial_struct
*ser
)
351 if ( ser
->type
!= PORT_UNKNOWN
&& ser
->type
!= PORT_MPC52xx
)
354 if ( (ser
->irq
!= port
->irq
) ||
355 (ser
->io_type
!= SERIAL_IO_MEM
) ||
356 (ser
->baud_base
!= port
->uartclk
) ||
357 // FIXME Should check addresses/irq as well ?
365 static struct uart_ops mpc52xx_uart_ops
= {
366 .tx_empty
= mpc52xx_uart_tx_empty
,
367 .set_mctrl
= mpc52xx_uart_set_mctrl
,
368 .get_mctrl
= mpc52xx_uart_get_mctrl
,
369 .stop_tx
= mpc52xx_uart_stop_tx
,
370 .start_tx
= mpc52xx_uart_start_tx
,
371 .send_xchar
= mpc52xx_uart_send_xchar
,
372 .stop_rx
= mpc52xx_uart_stop_rx
,
373 .enable_ms
= mpc52xx_uart_enable_ms
,
374 .break_ctl
= mpc52xx_uart_break_ctl
,
375 .startup
= mpc52xx_uart_startup
,
376 .shutdown
= mpc52xx_uart_shutdown
,
377 .set_termios
= mpc52xx_uart_set_termios
,
378 /* .pm = mpc52xx_uart_pm, Not supported yet */
379 /* .set_wake = mpc52xx_uart_set_wake, Not supported yet */
380 .type
= mpc52xx_uart_type
,
381 .release_port
= mpc52xx_uart_release_port
,
382 .request_port
= mpc52xx_uart_request_port
,
383 .config_port
= mpc52xx_uart_config_port
,
384 .verify_port
= mpc52xx_uart_verify_port
388 /* ======================================================================== */
389 /* Interrupt handling */
390 /* ======================================================================== */
393 mpc52xx_uart_int_rx_chars(struct uart_port
*port
, struct pt_regs
*regs
)
395 struct tty_struct
*tty
= port
->info
->tty
;
397 unsigned short status
;
399 /* While we can read, do so ! */
400 while ( (status
= in_be16(&PSC(port
)->mpc52xx_psc_status
)) &
401 MPC52xx_PSC_SR_RXRDY
) {
403 /* If we are full, just stop reading */
404 if (tty
->flip
.count
>= TTY_FLIPBUF_SIZE
)
408 ch
= in_8(&PSC(port
)->mpc52xx_psc_buffer_8
);
410 /* Handle sysreq char */
412 if (uart_handle_sysrq_char(port
, ch
, regs
)) {
419 *tty
->flip
.char_buf_ptr
= ch
;
420 *tty
->flip
.flag_buf_ptr
= 0;
423 if ( status
& (MPC52xx_PSC_SR_PE
|
426 MPC52xx_PSC_SR_OE
) ) {
428 if (status
& MPC52xx_PSC_SR_RB
) {
429 *tty
->flip
.flag_buf_ptr
= TTY_BREAK
;
430 uart_handle_break(port
);
431 } else if (status
& MPC52xx_PSC_SR_PE
)
432 *tty
->flip
.flag_buf_ptr
= TTY_PARITY
;
433 else if (status
& MPC52xx_PSC_SR_FE
)
434 *tty
->flip
.flag_buf_ptr
= TTY_FRAME
;
435 if (status
& MPC52xx_PSC_SR_OE
) {
437 * Overrun is special, since it's
438 * reported immediately, and doesn't
439 * affect the current character
441 if (tty
->flip
.count
< (TTY_FLIPBUF_SIZE
-1)) {
442 tty
->flip
.flag_buf_ptr
++;
443 tty
->flip
.char_buf_ptr
++;
446 *tty
->flip
.flag_buf_ptr
= TTY_OVERRUN
;
449 /* Clear error condition */
450 out_8(&PSC(port
)->command
,MPC52xx_PSC_RST_ERR_STAT
);
454 tty
->flip
.char_buf_ptr
++;
455 tty
->flip
.flag_buf_ptr
++;
460 tty_flip_buffer_push(tty
);
462 return in_be16(&PSC(port
)->mpc52xx_psc_status
) & MPC52xx_PSC_SR_RXRDY
;
466 mpc52xx_uart_int_tx_chars(struct uart_port
*port
)
468 struct circ_buf
*xmit
= &port
->info
->xmit
;
470 /* Process out of band chars */
472 out_8(&PSC(port
)->mpc52xx_psc_buffer_8
, port
->x_char
);
478 /* Nothing to do ? */
479 if (uart_circ_empty(xmit
) || uart_tx_stopped(port
)) {
480 mpc52xx_uart_stop_tx(port
,0);
485 while (in_be16(&PSC(port
)->mpc52xx_psc_status
) & MPC52xx_PSC_SR_TXRDY
) {
486 out_8(&PSC(port
)->mpc52xx_psc_buffer_8
, xmit
->buf
[xmit
->tail
]);
487 xmit
->tail
= (xmit
->tail
+ 1) & (UART_XMIT_SIZE
- 1);
489 if (uart_circ_empty(xmit
))
494 if (uart_circ_chars_pending(xmit
) < WAKEUP_CHARS
)
495 uart_write_wakeup(port
);
497 /* Maybe we're done after all */
498 if (uart_circ_empty(xmit
)) {
499 mpc52xx_uart_stop_tx(port
,0);
507 mpc52xx_uart_int(int irq
, void *dev_id
, struct pt_regs
*regs
)
509 struct uart_port
*port
= (struct uart_port
*) dev_id
;
510 unsigned long pass
= ISR_PASS_LIMIT
;
511 unsigned int keepgoing
;
512 unsigned short status
;
514 if ( irq
!= port
->irq
) {
516 "mpc52xx_uart_int : " \
517 "Received wrong int %d. Waiting for %d\n",
522 spin_lock(&port
->lock
);
524 /* While we have stuff to do, we continue */
526 /* If we don't find anything to do, we stop */
530 status
= in_be16(&PSC(port
)->mpc52xx_psc_isr
);
531 status
&= port
->read_status_mask
;
533 /* Do we need to receive chars ? */
534 /* For this RX interrupts must be on and some chars waiting */
535 if ( status
& MPC52xx_PSC_IMR_RXRDY
)
536 keepgoing
|= mpc52xx_uart_int_rx_chars(port
, regs
);
538 /* Do we need to send chars ? */
539 /* For this, TX must be ready and TX interrupt enabled */
540 if ( status
& MPC52xx_PSC_IMR_TXRDY
)
541 keepgoing
|= mpc52xx_uart_int_tx_chars(port
);
543 /* Limit number of iteration */
549 spin_unlock(&port
->lock
);
555 /* ======================================================================== */
556 /* Console ( if applicable ) */
557 /* ======================================================================== */
559 #ifdef CONFIG_SERIAL_MPC52xx_CONSOLE
562 mpc52xx_console_get_options(struct uart_port
*port
,
563 int *baud
, int *parity
, int *bits
, int *flow
)
565 struct mpc52xx_psc
*psc
= PSC(port
);
568 /* Read the mode registers */
569 out_8(&psc
->command
,MPC52xx_PSC_SEL_MODE_REG_1
);
570 mr1
= in_8(&psc
->mode
);
572 /* CT{U,L}R are write-only ! */
573 *baud
= __res
.bi_baudrate
?
574 __res
.bi_baudrate
: CONFIG_SERIAL_MPC52xx_CONSOLE_BAUD
;
577 switch (mr1
& MPC52xx_PSC_MODE_BITS_MASK
) {
578 case MPC52xx_PSC_MODE_5_BITS
: *bits
= 5; break;
579 case MPC52xx_PSC_MODE_6_BITS
: *bits
= 6; break;
580 case MPC52xx_PSC_MODE_7_BITS
: *bits
= 7; break;
581 case MPC52xx_PSC_MODE_8_BITS
:
585 if (mr1
& MPC52xx_PSC_MODE_PARNONE
)
588 *parity
= mr1
& MPC52xx_PSC_MODE_PARODD
? 'o' : 'e';
592 mpc52xx_console_write(struct console
*co
, const char *s
, unsigned int count
)
594 struct uart_port
*port
= &mpc52xx_uart_ports
[co
->index
];
595 struct mpc52xx_psc
*psc
= PSC(port
);
598 /* Disable interrupts */
599 out_be16(&psc
->mpc52xx_psc_imr
, 0);
601 /* Wait the TX buffer to be empty */
602 j
= 5000000; /* Maximum wait */
603 while (!(in_be16(&psc
->mpc52xx_psc_status
) & MPC52xx_PSC_SR_TXEMP
) &&
607 /* Write all the chars */
608 for ( i
=0 ; i
<count
; i
++ ) {
611 out_8(&psc
->mpc52xx_psc_buffer_8
, *s
);
613 /* Line return handling */
615 out_8(&psc
->mpc52xx_psc_buffer_8
, '\r');
617 /* Wait the TX buffer to be empty */
618 j
= 20000; /* Maximum wait */
619 while (!(in_be16(&psc
->mpc52xx_psc_status
) &
620 MPC52xx_PSC_SR_TXEMP
) && --j
)
624 /* Restore interrupt state */
625 out_be16(&psc
->mpc52xx_psc_imr
, port
->read_status_mask
);
629 mpc52xx_console_setup(struct console
*co
, char *options
)
631 struct uart_port
*port
= &mpc52xx_uart_ports
[co
->index
];
638 if (co
->index
< 0 || co
->index
>= MPC52xx_PSC_MAXNUM
)
641 /* Basic port init. Needed since we use some uart_??? func before
642 * real init for early access */
643 port
->lock
= SPIN_LOCK_UNLOCKED
;
644 port
->uartclk
= __res
.bi_ipbfreq
/ 2; /* Look at CTLR doc */
645 port
->ops
= &mpc52xx_uart_ops
;
646 port
->mapbase
= MPC52xx_PSCx(co
->index
);
648 /* We ioremap ourself */
649 port
->membase
= ioremap(port
->mapbase
, sizeof(struct mpc52xx_psc
));
650 if (port
->membase
== NULL
) {
651 release_mem_region(port
->mapbase
, sizeof(struct mpc52xx_psc
));
655 /* Setup the port parameters accoding to options */
657 uart_parse_options(options
, &baud
, &parity
, &bits
, &flow
);
659 mpc52xx_console_get_options(port
, &baud
, &parity
, &bits
, &flow
);
661 return uart_set_options(port
, co
, baud
, parity
, bits
, flow
);
665 extern struct uart_driver mpc52xx_uart_driver
;
667 static struct console mpc52xx_console
= {
669 .write
= mpc52xx_console_write
,
670 .device
= uart_console_device
,
671 .setup
= mpc52xx_console_setup
,
672 .flags
= CON_PRINTBUFFER
,
673 .index
= -1, /* Specified on the cmdline (e.g. console=ttyS0 ) */
674 .data
= &mpc52xx_uart_driver
,
679 mpc52xx_console_init(void)
681 register_console(&mpc52xx_console
);
685 console_initcall(mpc52xx_console_init
);
687 #define MPC52xx_PSC_CONSOLE &mpc52xx_console
689 #define MPC52xx_PSC_CONSOLE NULL
693 /* ======================================================================== */
695 /* ======================================================================== */
697 static struct uart_driver mpc52xx_uart_driver
= {
698 .owner
= THIS_MODULE
,
699 .driver_name
= "mpc52xx_psc_uart",
701 .devfs_name
= "ttyS",
704 .nr
= MPC52xx_PSC_MAXNUM
,
705 .cons
= MPC52xx_PSC_CONSOLE
,
709 /* ======================================================================== */
711 /* ======================================================================== */
714 mpc52xx_uart_probe(struct ocp_device
*ocp
)
716 struct uart_port
*port
= NULL
;
719 /* Get the corresponding port struct */
720 idx
= ocp
->def
->index
;
721 if (idx
< 0 || idx
>= MPC52xx_PSC_MAXNUM
)
724 port
= &mpc52xx_uart_ports
[idx
];
726 /* Init the port structure */
727 port
->lock
= SPIN_LOCK_UNLOCKED
;
728 port
->mapbase
= ocp
->def
->paddr
;
729 port
->irq
= ocp
->def
->irq
;
730 port
->uartclk
= __res
.bi_ipbfreq
/ 2; /* Look at CTLR doc */
731 port
->fifosize
= 255; /* Should be 512 ! But it can't be */
732 /* stored in a unsigned char */
733 port
->iotype
= UPIO_MEM
;
734 port
->flags
= UPF_BOOT_AUTOCONF
|
735 ( uart_console(port
) ? 0 : UPF_IOREMAP
);
737 port
->ops
= &mpc52xx_uart_ops
;
738 port
->read_status_mask
= 0;
740 /* Requests the mem & irqs */
741 /* Unlike other serial drivers, we reserve the resources here, so we
742 * can detect early if multiple drivers uses the same PSC. Special
743 * care must be taken with the console PSC
746 port
->irq
, mpc52xx_uart_int
,
747 SA_INTERRUPT
| SA_SAMPLE_RANDOM
, "mpc52xx_psc_uart", port
);
751 ret
= request_mem_region(port
->mapbase
, sizeof(struct mpc52xx_psc
),
752 "mpc52xx_psc_uart") != NULL
? 0 : -EBUSY
;
756 /* Add the port to the uart sub-system */
757 ret
= uart_add_one_port(&mpc52xx_uart_driver
, port
);
761 ocp_set_drvdata(ocp
, (void*)port
);
767 free_irq(port
->irq
, mpc52xx_uart_int
);
770 release_mem_region(port
->mapbase
, sizeof(struct mpc52xx_psc
));
773 if (uart_console(port
))
774 printk( "mpc52xx_uart.c: Error during resource alloction for "
775 "the console port !!! Check that the console PSC is "
776 "not used by another OCP driver !!!\n" );
782 mpc52xx_uart_remove(struct ocp_device
*ocp
)
784 struct uart_port
*port
= (struct uart_port
*) ocp_get_drvdata(ocp
);
786 ocp_set_drvdata(ocp
, NULL
);
789 uart_remove_one_port(&mpc52xx_uart_driver
, port
);
790 release_mem_region(port
->mapbase
, sizeof(struct mpc52xx_psc
));
791 free_irq(port
->irq
, mpc52xx_uart_int
);
797 mpc52xx_uart_suspend(struct ocp_device
*ocp
, u32 state
)
799 struct uart_port
*port
= (struct uart_port
*) ocp_get_drvdata(ocp
);
801 uart_suspend_port(&mpc52xx_uart_driver
, port
);
807 mpc52xx_uart_resume(struct ocp_device
*ocp
)
809 struct uart_port
*port
= (struct uart_port
*) ocp_get_drvdata(ocp
);
811 uart_resume_port(&mpc52xx_uart_driver
, port
);
817 static struct ocp_device_id mpc52xx_uart_ids
[] __devinitdata
= {
818 { .vendor
= OCP_VENDOR_FREESCALE
, .function
= OCP_FUNC_PSC_UART
},
819 { .vendor
= OCP_VENDOR_INVALID
/* Terminating entry */ }
822 MODULE_DEVICE_TABLE(ocp
, mpc52xx_uart_ids
);
824 static struct ocp_driver mpc52xx_uart_ocp_driver
= {
825 .name
= "mpc52xx_psc_uart",
826 .id_table
= mpc52xx_uart_ids
,
827 .probe
= mpc52xx_uart_probe
,
828 .remove
= mpc52xx_uart_remove
,
830 .suspend
= mpc52xx_uart_suspend
,
831 .resume
= mpc52xx_uart_resume
,
836 /* ======================================================================== */
838 /* ======================================================================== */
841 mpc52xx_uart_init(void)
845 printk(KERN_INFO
"Serial: MPC52xx PSC driver\n");
847 ret
= uart_register_driver(&mpc52xx_uart_driver
);
851 ret
= ocp_register_driver(&mpc52xx_uart_ocp_driver
);
857 mpc52xx_uart_exit(void)
859 ocp_unregister_driver(&mpc52xx_uart_ocp_driver
);
860 uart_unregister_driver(&mpc52xx_uart_driver
);
864 module_init(mpc52xx_uart_init
);
865 module_exit(mpc52xx_uart_exit
);
867 MODULE_AUTHOR("Sylvain Munaut <tnt@246tNt.com>");
868 MODULE_DESCRIPTION("Freescale MPC52xx PSC UART");
869 MODULE_LICENSE("GPL");