2 * linux/drivers/serial/cpm_uart.c
4 * Driver for CPM (SCC/SMC) serial ports; core driver
6 * Based on arch/ppc/cpm2_io/uart.c by Dan Malek
7 * Based on ppc8xx.c by Thomas Gleixner
8 * Based on drivers/serial/amba.c by Russell King
10 * Maintainer: Kumar Gala (kumar.gala@freescale.com) (CPM2)
11 * Pantelis Antoniou (panto@intracom.gr) (CPM1)
13 * Copyright (C) 2004 Freescale Semiconductor, Inc.
14 * (C) 2004 Intracom, S.A.
15 * (C) 2005 MontaVista Software, Inc. by Vitaly Bordug <vbordug@ru.mvista.com>
17 * This program is free software; you can redistribute it and/or modify
18 * it under the terms of the GNU General Public License as published by
19 * the Free Software Foundation; either version 2 of the License, or
20 * (at your option) any later version.
22 * This program is distributed in the hope that it will be useful,
23 * but WITHOUT ANY WARRANTY; without even the implied warranty of
24 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
25 * GNU General Public License for more details.
27 * You should have received a copy of the GNU General Public License
28 * along with this program; if not, write to the Free Software
29 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
33 #include <linux/config.h>
34 #include <linux/module.h>
35 #include <linux/tty.h>
36 #include <linux/ioport.h>
37 #include <linux/init.h>
38 #include <linux/serial.h>
39 #include <linux/console.h>
40 #include <linux/sysrq.h>
41 #include <linux/device.h>
42 #include <linux/bootmem.h>
43 #include <linux/dma-mapping.h>
47 #include <asm/delay.h>
49 #if defined(CONFIG_SERIAL_CPM_CONSOLE) && defined(CONFIG_MAGIC_SYSRQ)
53 #include <linux/serial_core.h>
54 #include <linux/kernel.h>
58 /***********************************************************************/
60 /* Track which ports are configured as uarts */
61 int cpm_uart_port_map
[UART_NR
];
62 /* How many ports did we config as uarts */
65 /**************************************************************/
67 static int cpm_uart_tx_pump(struct uart_port
*port
);
68 static void cpm_uart_init_smc(struct uart_cpm_port
*pinfo
);
69 static void cpm_uart_init_scc(struct uart_cpm_port
*pinfo
);
70 static void cpm_uart_initbd(struct uart_cpm_port
*pinfo
);
72 /**************************************************************/
74 static inline unsigned long cpu2cpm_addr(void *addr
)
76 if ((unsigned long)addr
>= CPM_ADDR
)
77 return (unsigned long)addr
;
78 return virt_to_bus(addr
);
81 static inline void *cpm2cpu_addr(unsigned long addr
)
85 return bus_to_virt(addr
);
89 * Check, if transmit buffers are processed
91 static unsigned int cpm_uart_tx_empty(struct uart_port
*port
)
93 struct uart_cpm_port
*pinfo
= (struct uart_cpm_port
*)port
;
94 volatile cbd_t
*bdp
= pinfo
->tx_bd_base
;
98 if (bdp
->cbd_sc
& BD_SC_READY
)
101 if (bdp
->cbd_sc
& BD_SC_WRAP
) {
108 pr_debug("CPM uart[%d]:tx_empty: %d\n", port
->line
, ret
);
113 static void cpm_uart_set_mctrl(struct uart_port
*port
, unsigned int mctrl
)
115 /* Whee. Do nothing. */
118 static unsigned int cpm_uart_get_mctrl(struct uart_port
*port
)
120 /* Whee. Do nothing. */
121 return TIOCM_CAR
| TIOCM_DSR
| TIOCM_CTS
;
127 static void cpm_uart_stop_tx(struct uart_port
*port
)
129 struct uart_cpm_port
*pinfo
= (struct uart_cpm_port
*)port
;
130 volatile smc_t
*smcp
= pinfo
->smcp
;
131 volatile scc_t
*sccp
= pinfo
->sccp
;
133 pr_debug("CPM uart[%d]:stop tx\n", port
->line
);
136 smcp
->smc_smcm
&= ~SMCM_TX
;
138 sccp
->scc_sccm
&= ~UART_SCCM_TX
;
144 static void cpm_uart_start_tx(struct uart_port
*port
)
146 struct uart_cpm_port
*pinfo
= (struct uart_cpm_port
*)port
;
147 volatile smc_t
*smcp
= pinfo
->smcp
;
148 volatile scc_t
*sccp
= pinfo
->sccp
;
150 pr_debug("CPM uart[%d]:start tx\n", port
->line
);
153 if (smcp
->smc_smcm
& SMCM_TX
)
156 if (sccp
->scc_sccm
& UART_SCCM_TX
)
160 if (cpm_uart_tx_pump(port
) != 0) {
162 smcp
->smc_smcm
|= SMCM_TX
;
163 smcp
->smc_smcmr
|= SMCMR_TEN
;
165 sccp
->scc_sccm
|= UART_SCCM_TX
;
166 pinfo
->sccp
->scc_gsmrl
|= SCC_GSMRL_ENT
;
174 static void cpm_uart_stop_rx(struct uart_port
*port
)
176 struct uart_cpm_port
*pinfo
= (struct uart_cpm_port
*)port
;
177 volatile smc_t
*smcp
= pinfo
->smcp
;
178 volatile scc_t
*sccp
= pinfo
->sccp
;
180 pr_debug("CPM uart[%d]:stop rx\n", port
->line
);
183 smcp
->smc_smcm
&= ~SMCM_RX
;
185 sccp
->scc_sccm
&= ~UART_SCCM_RX
;
189 * Enable Modem status interrupts
191 static void cpm_uart_enable_ms(struct uart_port
*port
)
193 pr_debug("CPM uart[%d]:enable ms\n", port
->line
);
199 static void cpm_uart_break_ctl(struct uart_port
*port
, int break_state
)
201 struct uart_cpm_port
*pinfo
= (struct uart_cpm_port
*)port
;
202 int line
= pinfo
- cpm_uart_ports
;
204 pr_debug("CPM uart[%d]:break ctrl, break_state: %d\n", port
->line
,
208 cpm_line_cr_cmd(line
, CPM_CR_STOP_TX
);
210 cpm_line_cr_cmd(line
, CPM_CR_RESTART_TX
);
214 * Transmit characters, refill buffer descriptor, if possible
216 static void cpm_uart_int_tx(struct uart_port
*port
, struct pt_regs
*regs
)
218 pr_debug("CPM uart[%d]:TX INT\n", port
->line
);
220 cpm_uart_tx_pump(port
);
226 static void cpm_uart_int_rx(struct uart_port
*port
, struct pt_regs
*regs
)
229 unsigned char ch
, *cp
;
230 struct tty_struct
*tty
= port
->info
->tty
;
231 struct uart_cpm_port
*pinfo
= (struct uart_cpm_port
*)port
;
236 pr_debug("CPM uart[%d]:RX INT\n", port
->line
);
238 /* Just loop through the closed BDs and copy the characters into
244 status
= bdp
->cbd_sc
;
245 /* If this one is empty, return happy */
246 if (status
& BD_SC_EMPTY
)
249 /* get number of characters, and check spce in flip-buffer */
252 /* If we have not enough room in tty flip buffer, then we try
253 * later, which will be the next rx-interrupt or a timeout
255 if ((tty
->flip
.count
+ i
) >= TTY_FLIPBUF_SIZE
) {
256 tty
->flip
.work
.func((void *)tty
);
257 if ((tty
->flip
.count
+ i
) >= TTY_FLIPBUF_SIZE
) {
258 printk(KERN_WARNING
"TTY_DONT_FLIP set\n");
264 cp
= cpm2cpu_addr(bdp
->cbd_bufaddr
);
266 /* loop through the buffer */
273 (BD_SC_BR
| BD_SC_FR
| BD_SC_PR
| BD_SC_OV
))
275 if (uart_handle_sysrq_char(port
, ch
, regs
))
279 *tty
->flip
.char_buf_ptr
++ = ch
;
280 *tty
->flip
.flag_buf_ptr
++ = flg
;
283 } /* End while (i--) */
285 /* This BD is ready to be used again. Clear status. get next */
286 bdp
->cbd_sc
&= ~(BD_SC_BR
| BD_SC_FR
| BD_SC_PR
| BD_SC_OV
| BD_SC_ID
);
287 bdp
->cbd_sc
|= BD_SC_EMPTY
;
289 if (bdp
->cbd_sc
& BD_SC_WRAP
)
290 bdp
= pinfo
->rx_bd_base
;
296 /* Write back buffer pointer */
297 pinfo
->rx_cur
= (volatile cbd_t
*) bdp
;
299 /* activate BH processing */
300 tty_flip_buffer_push(tty
);
304 /* Error processing */
308 if (status
& BD_SC_BR
)
310 if (status
& BD_SC_PR
)
311 port
->icount
.parity
++;
312 if (status
& BD_SC_FR
)
313 port
->icount
.frame
++;
314 if (status
& BD_SC_OV
)
315 port
->icount
.overrun
++;
317 /* Mask out ignored conditions */
318 status
&= port
->read_status_mask
;
320 /* Handle the remaining ones */
321 if (status
& BD_SC_BR
)
323 else if (status
& BD_SC_PR
)
325 else if (status
& BD_SC_FR
)
328 /* overrun does not affect the current character ! */
329 if (status
& BD_SC_OV
) {
332 /* We skip this buffer */
333 /* CHECK: Is really nothing senseful there */
334 /* ASSUMPTION: it contains nothing valid */
344 * Asynchron mode interrupt handler
346 static irqreturn_t
cpm_uart_int(int irq
, void *data
, struct pt_regs
*regs
)
349 struct uart_port
*port
= (struct uart_port
*)data
;
350 struct uart_cpm_port
*pinfo
= (struct uart_cpm_port
*)port
;
351 volatile smc_t
*smcp
= pinfo
->smcp
;
352 volatile scc_t
*sccp
= pinfo
->sccp
;
354 pr_debug("CPM uart[%d]:IRQ\n", port
->line
);
357 events
= smcp
->smc_smce
;
358 smcp
->smc_smce
= events
;
359 if (events
& SMCM_BRKE
)
360 uart_handle_break(port
);
361 if (events
& SMCM_RX
)
362 cpm_uart_int_rx(port
, regs
);
363 if (events
& SMCM_TX
)
364 cpm_uart_int_tx(port
, regs
);
366 events
= sccp
->scc_scce
;
367 sccp
->scc_scce
= events
;
368 if (events
& UART_SCCM_BRKE
)
369 uart_handle_break(port
);
370 if (events
& UART_SCCM_RX
)
371 cpm_uart_int_rx(port
, regs
);
372 if (events
& UART_SCCM_TX
)
373 cpm_uart_int_tx(port
, regs
);
375 return (events
) ? IRQ_HANDLED
: IRQ_NONE
;
378 static int cpm_uart_startup(struct uart_port
*port
)
381 struct uart_cpm_port
*pinfo
= (struct uart_cpm_port
*)port
;
382 int line
= pinfo
- cpm_uart_ports
;
384 pr_debug("CPM uart[%d]:startup\n", port
->line
);
386 /* Install interrupt handler. */
387 retval
= request_irq(port
->irq
, cpm_uart_int
, 0, "cpm_uart", port
);
393 pinfo
->smcp
->smc_smcm
|= SMCM_RX
;
394 pinfo
->smcp
->smc_smcmr
|= SMCMR_REN
;
396 pinfo
->sccp
->scc_sccm
|= UART_SCCM_RX
;
399 if (!(pinfo
->flags
& FLAG_CONSOLE
))
400 cpm_line_cr_cmd(line
,CPM_CR_INIT_TRX
);
404 inline void cpm_uart_wait_until_send(struct uart_cpm_port
*pinfo
)
406 set_current_state(TASK_UNINTERRUPTIBLE
);
407 schedule_timeout(pinfo
->wait_closing
);
413 static void cpm_uart_shutdown(struct uart_port
*port
)
415 struct uart_cpm_port
*pinfo
= (struct uart_cpm_port
*)port
;
416 int line
= pinfo
- cpm_uart_ports
;
418 pr_debug("CPM uart[%d]:shutdown\n", port
->line
);
420 /* free interrupt handler */
421 free_irq(port
->irq
, port
);
423 /* If the port is not the console, disable Rx and Tx. */
424 if (!(pinfo
->flags
& FLAG_CONSOLE
)) {
425 /* Wait for all the BDs marked sent */
426 while(!cpm_uart_tx_empty(port
)) {
427 set_current_state(TASK_UNINTERRUPTIBLE
);
431 if (pinfo
->wait_closing
)
432 cpm_uart_wait_until_send(pinfo
);
436 volatile smc_t
*smcp
= pinfo
->smcp
;
437 smcp
->smc_smcmr
&= ~(SMCMR_REN
| SMCMR_TEN
);
438 smcp
->smc_smcm
&= ~(SMCM_RX
| SMCM_TX
);
440 volatile scc_t
*sccp
= pinfo
->sccp
;
441 sccp
->scc_gsmrl
&= ~(SCC_GSMRL_ENR
| SCC_GSMRL_ENT
);
442 sccp
->scc_sccm
&= ~(UART_SCCM_TX
| UART_SCCM_RX
);
445 /* Shut them really down and reinit buffer descriptors */
446 cpm_line_cr_cmd(line
, CPM_CR_STOP_TX
);
447 cpm_uart_initbd(pinfo
);
451 static void cpm_uart_set_termios(struct uart_port
*port
,
452 struct termios
*termios
, struct termios
*old
)
456 u16 cval
, scval
, prev_mode
;
458 struct uart_cpm_port
*pinfo
= (struct uart_cpm_port
*)port
;
459 volatile smc_t
*smcp
= pinfo
->smcp
;
460 volatile scc_t
*sccp
= pinfo
->sccp
;
462 pr_debug("CPM uart[%d]:set_termios\n", port
->line
);
464 baud
= uart_get_baud_rate(port
, termios
, old
, 0, port
->uartclk
/ 16);
466 /* Character length programmed into the mode register is the
467 * sum of: 1 start bit, number of data bits, 0 or 1 parity bit,
468 * 1 or 2 stop bits, minus 1.
469 * The value 'bits' counts this for us.
475 switch (termios
->c_cflag
& CSIZE
) {
488 /* Never happens, but GCC is too dumb to figure it out */
495 if (termios
->c_cflag
& CSTOPB
) {
496 cval
|= SMCMR_SL
; /* Two stops */
497 scval
|= SCU_PSMR_SL
;
501 if (termios
->c_cflag
& PARENB
) {
503 scval
|= SCU_PSMR_PEN
;
505 if (!(termios
->c_cflag
& PARODD
)) {
506 cval
|= SMCMR_PM_EVEN
;
507 scval
|= (SCU_PSMR_REVP
| SCU_PSMR_TEVP
);
512 * Set up parity check flag
514 #define RELEVANT_IFLAG(iflag) (iflag & (IGNBRK|BRKINT|IGNPAR|PARMRK|INPCK))
516 port
->read_status_mask
= (BD_SC_EMPTY
| BD_SC_OV
);
517 if (termios
->c_iflag
& INPCK
)
518 port
->read_status_mask
|= BD_SC_FR
| BD_SC_PR
;
519 if ((termios
->c_iflag
& BRKINT
) || (termios
->c_iflag
& PARMRK
))
520 port
->read_status_mask
|= BD_SC_BR
;
523 * Characters to ignore
525 port
->ignore_status_mask
= 0;
526 if (termios
->c_iflag
& IGNPAR
)
527 port
->ignore_status_mask
|= BD_SC_PR
| BD_SC_FR
;
528 if (termios
->c_iflag
& IGNBRK
) {
529 port
->ignore_status_mask
|= BD_SC_BR
;
531 * If we're ignore parity and break indicators, ignore
532 * overruns too. (For real raw support).
534 if (termios
->c_iflag
& IGNPAR
)
535 port
->ignore_status_mask
|= BD_SC_OV
;
538 * !!! ignore all characters if CREAD is not set
540 if ((termios
->c_cflag
& CREAD
) == 0)
541 port
->read_status_mask
&= ~BD_SC_EMPTY
;
543 spin_lock_irqsave(&port
->lock
, flags
);
545 /* Start bit has not been added (so don't, because we would just
546 * subtract it later), and we need to add one for the number of
547 * stops bits (there is always at least one).
551 /* Set the mode register. We want to keep a copy of the
552 * enables, because we want to put them back if they were
555 prev_mode
= smcp
->smc_smcmr
;
556 smcp
->smc_smcmr
= smcr_mk_clen(bits
) | cval
| SMCMR_SM_UART
;
557 smcp
->smc_smcmr
|= (prev_mode
& (SMCMR_REN
| SMCMR_TEN
));
559 sccp
->scc_psmr
= (sbits
<< 12) | scval
;
562 cpm_set_brg(pinfo
->brg
- 1, baud
);
563 spin_unlock_irqrestore(&port
->lock
, flags
);
567 static const char *cpm_uart_type(struct uart_port
*port
)
569 pr_debug("CPM uart[%d]:uart_type\n", port
->line
);
571 return port
->type
== PORT_CPM
? "CPM UART" : NULL
;
575 * verify the new serial_struct (for TIOCSSERIAL).
577 static int cpm_uart_verify_port(struct uart_port
*port
,
578 struct serial_struct
*ser
)
582 pr_debug("CPM uart[%d]:verify_port\n", port
->line
);
584 if (ser
->type
!= PORT_UNKNOWN
&& ser
->type
!= PORT_CPM
)
586 if (ser
->irq
< 0 || ser
->irq
>= NR_IRQS
)
588 if (ser
->baud_base
< 9600)
594 * Transmit characters, refill buffer descriptor, if possible
596 static int cpm_uart_tx_pump(struct uart_port
*port
)
601 struct uart_cpm_port
*pinfo
= (struct uart_cpm_port
*)port
;
602 struct circ_buf
*xmit
= &port
->info
->xmit
;
604 /* Handle xon/xoff */
606 /* Pick next descriptor and fill from buffer */
609 p
= cpm2cpu_addr(bdp
->cbd_bufaddr
);
611 *p
++ = xmit
->buf
[xmit
->tail
];
613 bdp
->cbd_sc
|= BD_SC_READY
;
615 if (bdp
->cbd_sc
& BD_SC_WRAP
)
616 bdp
= pinfo
->tx_bd_base
;
626 if (uart_circ_empty(xmit
) || uart_tx_stopped(port
)) {
627 cpm_uart_stop_tx(port
);
631 /* Pick next descriptor and fill from buffer */
634 while (!(bdp
->cbd_sc
& BD_SC_READY
) && (xmit
->tail
!= xmit
->head
)) {
636 p
= cpm2cpu_addr(bdp
->cbd_bufaddr
);
637 while (count
< pinfo
->tx_fifosize
) {
638 *p
++ = xmit
->buf
[xmit
->tail
];
639 xmit
->tail
= (xmit
->tail
+ 1) & (UART_XMIT_SIZE
- 1);
642 if (xmit
->head
== xmit
->tail
)
645 bdp
->cbd_datlen
= count
;
646 bdp
->cbd_sc
|= BD_SC_READY
;
649 if (bdp
->cbd_sc
& BD_SC_WRAP
)
650 bdp
= pinfo
->tx_bd_base
;
656 if (uart_circ_chars_pending(xmit
) < WAKEUP_CHARS
)
657 uart_write_wakeup(port
);
659 if (uart_circ_empty(xmit
)) {
660 cpm_uart_stop_tx(port
);
668 * init buffer descriptors
670 static void cpm_uart_initbd(struct uart_cpm_port
*pinfo
)
676 pr_debug("CPM uart[%d]:initbd\n", pinfo
->port
.line
);
678 /* Set the physical address of the host memory
679 * buffers in the buffer descriptors, and the
680 * virtual address for us to work with.
682 mem_addr
= pinfo
->mem_addr
;
683 bdp
= pinfo
->rx_cur
= pinfo
->rx_bd_base
;
684 for (i
= 0; i
< (pinfo
->rx_nrfifos
- 1); i
++, bdp
++) {
685 bdp
->cbd_bufaddr
= cpu2cpm_addr(mem_addr
);
686 bdp
->cbd_sc
= BD_SC_EMPTY
| BD_SC_INTRPT
;
687 mem_addr
+= pinfo
->rx_fifosize
;
690 bdp
->cbd_bufaddr
= cpu2cpm_addr(mem_addr
);
691 bdp
->cbd_sc
= BD_SC_WRAP
| BD_SC_EMPTY
| BD_SC_INTRPT
;
693 /* Set the physical address of the host memory
694 * buffers in the buffer descriptors, and the
695 * virtual address for us to work with.
697 mem_addr
= pinfo
->mem_addr
+ L1_CACHE_ALIGN(pinfo
->rx_nrfifos
* pinfo
->rx_fifosize
);
698 bdp
= pinfo
->tx_cur
= pinfo
->tx_bd_base
;
699 for (i
= 0; i
< (pinfo
->tx_nrfifos
- 1); i
++, bdp
++) {
700 bdp
->cbd_bufaddr
= cpu2cpm_addr(mem_addr
);
701 bdp
->cbd_sc
= BD_SC_INTRPT
;
702 mem_addr
+= pinfo
->tx_fifosize
;
705 bdp
->cbd_bufaddr
= cpu2cpm_addr(mem_addr
);
706 bdp
->cbd_sc
= BD_SC_WRAP
| BD_SC_INTRPT
;
709 static void cpm_uart_init_scc(struct uart_cpm_port
*pinfo
)
711 int line
= pinfo
- cpm_uart_ports
;
713 volatile scc_uart_t
*sup
;
715 pr_debug("CPM uart[%d]:init_scc\n", pinfo
->port
.line
);
721 pinfo
->sccup
->scc_genscc
.scc_rbase
= (unsigned char *)pinfo
->rx_bd_base
- DPRAM_BASE
;
722 pinfo
->sccup
->scc_genscc
.scc_tbase
= (unsigned char *)pinfo
->tx_bd_base
- DPRAM_BASE
;
724 /* Set up the uart parameters in the
728 cpm_set_scc_fcr(sup
);
730 sup
->scc_genscc
.scc_mrblr
= pinfo
->rx_fifosize
;
731 sup
->scc_maxidl
= pinfo
->rx_fifosize
;
740 sup
->scc_char1
= 0x8000;
741 sup
->scc_char2
= 0x8000;
742 sup
->scc_char3
= 0x8000;
743 sup
->scc_char4
= 0x8000;
744 sup
->scc_char5
= 0x8000;
745 sup
->scc_char6
= 0x8000;
746 sup
->scc_char7
= 0x8000;
747 sup
->scc_char8
= 0x8000;
748 sup
->scc_rccm
= 0xc0ff;
750 /* Send the CPM an initialize command.
752 cpm_line_cr_cmd(line
, CPM_CR_INIT_TRX
);
754 /* Set UART mode, 8 bit, no parity, one stop.
755 * Enable receive and transmit.
759 (SCC_GSMRL_MODE_UART
| SCC_GSMRL_TDCR_16
| SCC_GSMRL_RDCR_16
);
761 /* Enable rx interrupts and clear all pending events. */
763 scp
->scc_scce
= 0xffff;
764 scp
->scc_dsr
= 0x7e7e;
765 scp
->scc_psmr
= 0x3000;
767 scp
->scc_gsmrl
|= (SCC_GSMRL_ENR
| SCC_GSMRL_ENT
);
770 static void cpm_uart_init_smc(struct uart_cpm_port
*pinfo
)
772 int line
= pinfo
- cpm_uart_ports
;
774 volatile smc_uart_t
*up
;
776 pr_debug("CPM uart[%d]:init_smc\n", pinfo
->port
.line
);
782 pinfo
->smcup
->smc_rbase
= (u_char
*)pinfo
->rx_bd_base
- DPRAM_BASE
;
783 pinfo
->smcup
->smc_tbase
= (u_char
*)pinfo
->tx_bd_base
- DPRAM_BASE
;
786 * In case SMC1 is being relocated...
788 #if defined (CONFIG_I2C_SPI_SMC1_UCODE_PATCH)
789 up
->smc_rbptr
= pinfo
->smcup
->smc_rbase
;
790 up
->smc_tbptr
= pinfo
->smcup
->smc_tbase
;
793 up
->smc_brkcr
= 1; /* number of break chars */
797 /* Set up the uart parameters in the
802 /* Using idle charater time requires some additional tuning. */
803 up
->smc_mrblr
= pinfo
->rx_fifosize
;
804 up
->smc_maxidl
= pinfo
->rx_fifosize
;
809 cpm_line_cr_cmd(line
, CPM_CR_INIT_TRX
);
811 /* Set UART mode, 8 bit, no parity, one stop.
812 * Enable receive and transmit.
814 sp
->smc_smcmr
= smcr_mk_clen(9) | SMCMR_SM_UART
;
816 /* Enable only rx interrupts clear all pending events. */
820 sp
->smc_smcmr
|= (SMCMR_REN
| SMCMR_TEN
);
824 * Initialize port. This is called from early_console stuff
825 * so we have to be careful here !
827 static int cpm_uart_request_port(struct uart_port
*port
)
829 struct uart_cpm_port
*pinfo
= (struct uart_cpm_port
*)port
;
832 pr_debug("CPM uart[%d]:request port\n", port
->line
);
834 if (pinfo
->flags
& FLAG_CONSOLE
)
838 * Setup any port IO, connect any baud rate generators,
839 * etc. This is expected to be handled by board
842 if (pinfo
->set_lineif
)
843 pinfo
->set_lineif(pinfo
);
846 pinfo
->smcp
->smc_smcm
&= ~(SMCM_RX
| SMCM_TX
);
847 pinfo
->smcp
->smc_smcmr
&= ~(SMCMR_REN
| SMCMR_TEN
);
849 pinfo
->sccp
->scc_sccm
&= ~(UART_SCCM_TX
| UART_SCCM_RX
);
850 pinfo
->sccp
->scc_gsmrl
&= ~(SCC_GSMRL_ENR
| SCC_GSMRL_ENT
);
853 ret
= cpm_uart_allocbuf(pinfo
, 0);
858 cpm_uart_initbd(pinfo
);
860 cpm_uart_init_smc(pinfo
);
862 cpm_uart_init_scc(pinfo
);
867 static void cpm_uart_release_port(struct uart_port
*port
)
869 struct uart_cpm_port
*pinfo
= (struct uart_cpm_port
*)port
;
871 if (!(pinfo
->flags
& FLAG_CONSOLE
))
872 cpm_uart_freebuf(pinfo
);
876 * Configure/autoconfigure the port.
878 static void cpm_uart_config_port(struct uart_port
*port
, int flags
)
880 pr_debug("CPM uart[%d]:config_port\n", port
->line
);
882 if (flags
& UART_CONFIG_TYPE
) {
883 port
->type
= PORT_CPM
;
884 cpm_uart_request_port(port
);
887 static struct uart_ops cpm_uart_pops
= {
888 .tx_empty
= cpm_uart_tx_empty
,
889 .set_mctrl
= cpm_uart_set_mctrl
,
890 .get_mctrl
= cpm_uart_get_mctrl
,
891 .stop_tx
= cpm_uart_stop_tx
,
892 .start_tx
= cpm_uart_start_tx
,
893 .stop_rx
= cpm_uart_stop_rx
,
894 .enable_ms
= cpm_uart_enable_ms
,
895 .break_ctl
= cpm_uart_break_ctl
,
896 .startup
= cpm_uart_startup
,
897 .shutdown
= cpm_uart_shutdown
,
898 .set_termios
= cpm_uart_set_termios
,
899 .type
= cpm_uart_type
,
900 .release_port
= cpm_uart_release_port
,
901 .request_port
= cpm_uart_request_port
,
902 .config_port
= cpm_uart_config_port
,
903 .verify_port
= cpm_uart_verify_port
,
906 struct uart_cpm_port cpm_uart_ports
[UART_NR
] = {
910 .ops
= &cpm_uart_pops
,
911 .iotype
= SERIAL_IO_MEM
,
912 .lock
= SPIN_LOCK_UNLOCKED
,
915 .tx_nrfifos
= TX_NUM_FIFO
,
916 .tx_fifosize
= TX_BUF_SIZE
,
917 .rx_nrfifos
= RX_NUM_FIFO
,
918 .rx_fifosize
= RX_BUF_SIZE
,
919 .set_lineif
= smc1_lineif
,
924 .ops
= &cpm_uart_pops
,
925 .iotype
= SERIAL_IO_MEM
,
926 .lock
= SPIN_LOCK_UNLOCKED
,
929 .tx_nrfifos
= TX_NUM_FIFO
,
930 .tx_fifosize
= TX_BUF_SIZE
,
931 .rx_nrfifos
= RX_NUM_FIFO
,
932 .rx_fifosize
= RX_BUF_SIZE
,
933 .set_lineif
= smc2_lineif
,
934 #ifdef CONFIG_SERIAL_CPM_ALT_SMC2
941 .ops
= &cpm_uart_pops
,
942 .iotype
= SERIAL_IO_MEM
,
943 .lock
= SPIN_LOCK_UNLOCKED
,
945 .tx_nrfifos
= TX_NUM_FIFO
,
946 .tx_fifosize
= TX_BUF_SIZE
,
947 .rx_nrfifos
= RX_NUM_FIFO
,
948 .rx_fifosize
= RX_BUF_SIZE
,
949 .set_lineif
= scc1_lineif
,
950 .wait_closing
= SCC_WAIT_CLOSING
,
955 .ops
= &cpm_uart_pops
,
956 .iotype
= SERIAL_IO_MEM
,
957 .lock
= SPIN_LOCK_UNLOCKED
,
959 .tx_nrfifos
= TX_NUM_FIFO
,
960 .tx_fifosize
= TX_BUF_SIZE
,
961 .rx_nrfifos
= RX_NUM_FIFO
,
962 .rx_fifosize
= RX_BUF_SIZE
,
963 .set_lineif
= scc2_lineif
,
964 .wait_closing
= SCC_WAIT_CLOSING
,
969 .ops
= &cpm_uart_pops
,
970 .iotype
= SERIAL_IO_MEM
,
971 .lock
= SPIN_LOCK_UNLOCKED
,
973 .tx_nrfifos
= TX_NUM_FIFO
,
974 .tx_fifosize
= TX_BUF_SIZE
,
975 .rx_nrfifos
= RX_NUM_FIFO
,
976 .rx_fifosize
= RX_BUF_SIZE
,
977 .set_lineif
= scc3_lineif
,
978 .wait_closing
= SCC_WAIT_CLOSING
,
983 .ops
= &cpm_uart_pops
,
984 .iotype
= SERIAL_IO_MEM
,
985 .lock
= SPIN_LOCK_UNLOCKED
,
987 .tx_nrfifos
= TX_NUM_FIFO
,
988 .tx_fifosize
= TX_BUF_SIZE
,
989 .rx_nrfifos
= RX_NUM_FIFO
,
990 .rx_fifosize
= RX_BUF_SIZE
,
991 .set_lineif
= scc4_lineif
,
992 .wait_closing
= SCC_WAIT_CLOSING
,
996 #ifdef CONFIG_SERIAL_CPM_CONSOLE
998 * Print a string to the serial port trying not to disturb
999 * any possible real use of the port...
1001 * Note that this is called with interrupts already disabled
1003 static void cpm_uart_console_write(struct console
*co
, const char *s
,
1006 struct uart_cpm_port
*pinfo
=
1007 &cpm_uart_ports
[cpm_uart_port_map
[co
->index
]];
1009 volatile cbd_t
*bdp
, *bdbase
;
1010 volatile unsigned char *cp
;
1012 /* Get the address of the host memory buffer.
1014 bdp
= pinfo
->tx_cur
;
1015 bdbase
= pinfo
->tx_bd_base
;
1018 * Now, do each character. This is not as bad as it looks
1019 * since this is a holding FIFO and not a transmitting FIFO.
1020 * We could add the complexity of filling the entire transmit
1021 * buffer, but we would just wait longer between accesses......
1023 for (i
= 0; i
< count
; i
++, s
++) {
1024 /* Wait for transmitter fifo to empty.
1025 * Ready indicates output is ready, and xmt is doing
1026 * that, not that it is ready for us to send.
1028 while ((bdp
->cbd_sc
& BD_SC_READY
) != 0)
1031 /* Send the character out.
1032 * If the buffer address is in the CPM DPRAM, don't
1035 cp
= cpm2cpu_addr(bdp
->cbd_bufaddr
);
1039 bdp
->cbd_datlen
= 1;
1040 bdp
->cbd_sc
|= BD_SC_READY
;
1042 if (bdp
->cbd_sc
& BD_SC_WRAP
)
1047 /* if a LF, also do CR... */
1049 while ((bdp
->cbd_sc
& BD_SC_READY
) != 0)
1052 cp
= cpm2cpu_addr(bdp
->cbd_bufaddr
);
1055 bdp
->cbd_datlen
= 1;
1056 bdp
->cbd_sc
|= BD_SC_READY
;
1058 if (bdp
->cbd_sc
& BD_SC_WRAP
)
1066 * Finally, Wait for transmitter & holding register to empty
1067 * and restore the IER
1069 while ((bdp
->cbd_sc
& BD_SC_READY
) != 0)
1072 pinfo
->tx_cur
= (volatile cbd_t
*) bdp
;
1076 * Setup console. Be careful is called early !
1078 static int __init
cpm_uart_console_setup(struct console
*co
, char *options
)
1080 struct uart_port
*port
;
1081 struct uart_cpm_port
*pinfo
;
1089 (struct uart_port
*)&cpm_uart_ports
[cpm_uart_port_map
[co
->index
]];
1090 pinfo
= (struct uart_cpm_port
*)port
;
1092 pinfo
->flags
|= FLAG_CONSOLE
;
1095 uart_parse_options(options
, &baud
, &parity
, &bits
, &flow
);
1097 bd_t
*bd
= (bd_t
*) __res
;
1099 if (bd
->bi_baudrate
)
1100 baud
= bd
->bi_baudrate
;
1106 * Setup any port IO, connect any baud rate generators,
1107 * etc. This is expected to be handled by board
1110 if (pinfo
->set_lineif
)
1111 pinfo
->set_lineif(pinfo
);
1113 if (IS_SMC(pinfo
)) {
1114 pinfo
->smcp
->smc_smcm
&= ~(SMCM_RX
| SMCM_TX
);
1115 pinfo
->smcp
->smc_smcmr
&= ~(SMCMR_REN
| SMCMR_TEN
);
1117 pinfo
->sccp
->scc_sccm
&= ~(UART_SCCM_TX
| UART_SCCM_RX
);
1118 pinfo
->sccp
->scc_gsmrl
&= ~(SCC_GSMRL_ENR
| SCC_GSMRL_ENT
);
1121 ret
= cpm_uart_allocbuf(pinfo
, 1);
1126 cpm_uart_initbd(pinfo
);
1129 cpm_uart_init_smc(pinfo
);
1131 cpm_uart_init_scc(pinfo
);
1133 uart_set_options(port
, co
, baud
, parity
, bits
, flow
);
1138 static struct uart_driver cpm_reg
;
1139 static struct console cpm_scc_uart_console
= {
1141 .write
= cpm_uart_console_write
,
1142 .device
= uart_console_device
,
1143 .setup
= cpm_uart_console_setup
,
1144 .flags
= CON_PRINTBUFFER
,
1149 int __init
cpm_uart_console_init(void)
1151 int ret
= cpm_uart_init_portdesc();
1154 register_console(&cpm_scc_uart_console
);
1158 console_initcall(cpm_uart_console_init
);
1160 #define CPM_UART_CONSOLE &cpm_scc_uart_console
1162 #define CPM_UART_CONSOLE NULL
1165 static struct uart_driver cpm_reg
= {
1166 .owner
= THIS_MODULE
,
1167 .driver_name
= "ttyCPM",
1168 .dev_name
= "ttyCPM",
1169 .major
= SERIAL_CPM_MAJOR
,
1170 .minor
= SERIAL_CPM_MINOR
,
1171 .cons
= CPM_UART_CONSOLE
,
1174 static int __init
cpm_uart_init(void)
1178 printk(KERN_INFO
"Serial: CPM driver $Revision: 0.01 $\n");
1180 #ifndef CONFIG_SERIAL_CPM_CONSOLE
1181 ret
= cpm_uart_init_portdesc();
1186 cpm_reg
.nr
= cpm_uart_nr
;
1187 ret
= uart_register_driver(&cpm_reg
);
1192 for (i
= 0; i
< cpm_uart_nr
; i
++) {
1193 int con
= cpm_uart_port_map
[i
];
1194 cpm_uart_ports
[con
].port
.line
= i
;
1195 cpm_uart_ports
[con
].port
.flags
= UPF_BOOT_AUTOCONF
;
1196 uart_add_one_port(&cpm_reg
, &cpm_uart_ports
[con
].port
);
1202 static void __exit
cpm_uart_exit(void)
1206 for (i
= 0; i
< cpm_uart_nr
; i
++) {
1207 int con
= cpm_uart_port_map
[i
];
1208 uart_remove_one_port(&cpm_reg
, &cpm_uart_ports
[con
].port
);
1211 uart_unregister_driver(&cpm_reg
);
1214 module_init(cpm_uart_init
);
1215 module_exit(cpm_uart_exit
);
1217 MODULE_AUTHOR("Kumar Gala/Antoniou Pantelis");
1218 MODULE_DESCRIPTION("CPM SCC/SMC port driver $Revision: 0.01 $");
1219 MODULE_LICENSE("GPL");
1220 MODULE_ALIAS_CHARDEV(SERIAL_CPM_MAJOR
, SERIAL_CPM_MINOR
);