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 (galak@kernel.crashing.org) (CPM2)
11 * Pantelis Antoniou (panto@intracom.gr) (CPM1)
13 * Copyright (C) 2004 Freescale Semiconductor, Inc.
14 * (C) 2004 Intracom, S.A.
15 * (C) 2005-2006 MontaVista Software, Inc.
16 * Vitaly Bordug <vbordug@ru.mvista.com>
18 * This program is free software; you can redistribute it and/or modify
19 * it under the terms of the GNU General Public License as published by
20 * the Free Software Foundation; either version 2 of the License, or
21 * (at your option) any later version.
23 * This program is distributed in the hope that it will be useful,
24 * but WITHOUT ANY WARRANTY; without even the implied warranty of
25 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
26 * GNU General Public License for more details.
28 * You should have received a copy of the GNU General Public License
29 * along with this program; if not, write to the Free Software
30 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
34 #include <linux/config.h>
35 #include <linux/module.h>
36 #include <linux/tty.h>
37 #include <linux/ioport.h>
38 #include <linux/init.h>
39 #include <linux/serial.h>
40 #include <linux/console.h>
41 #include <linux/sysrq.h>
42 #include <linux/device.h>
43 #include <linux/bootmem.h>
44 #include <linux/dma-mapping.h>
45 #include <linux/fs_uart_pd.h>
49 #include <asm/delay.h>
51 #if defined(CONFIG_SERIAL_CPM_CONSOLE) && defined(CONFIG_MAGIC_SYSRQ)
55 #include <linux/serial_core.h>
56 #include <linux/kernel.h>
60 /***********************************************************************/
62 /* Track which ports are configured as uarts */
63 int cpm_uart_port_map
[UART_NR
];
64 /* How many ports did we config as uarts */
67 /**************************************************************/
69 static int cpm_uart_tx_pump(struct uart_port
*port
);
70 static void cpm_uart_init_smc(struct uart_cpm_port
*pinfo
);
71 static void cpm_uart_init_scc(struct uart_cpm_port
*pinfo
);
72 static void cpm_uart_initbd(struct uart_cpm_port
*pinfo
);
74 /**************************************************************/
77 /* Place-holder for board-specific stuff */
78 struct platform_device
* __attribute__ ((weak
)) __init
79 early_uart_get_pdev(int index
)
85 static void cpm_uart_count(void)
88 #ifdef CONFIG_SERIAL_CPM_SMC1
89 cpm_uart_port_map
[cpm_uart_nr
++] = UART_SMC1
;
91 #ifdef CONFIG_SERIAL_CPM_SMC2
92 cpm_uart_port_map
[cpm_uart_nr
++] = UART_SMC2
;
94 #ifdef CONFIG_SERIAL_CPM_SCC1
95 cpm_uart_port_map
[cpm_uart_nr
++] = UART_SCC1
;
97 #ifdef CONFIG_SERIAL_CPM_SCC2
98 cpm_uart_port_map
[cpm_uart_nr
++] = UART_SCC2
;
100 #ifdef CONFIG_SERIAL_CPM_SCC3
101 cpm_uart_port_map
[cpm_uart_nr
++] = UART_SCC3
;
103 #ifdef CONFIG_SERIAL_CPM_SCC4
104 cpm_uart_port_map
[cpm_uart_nr
++] = UART_SCC4
;
108 /* Get UART number by its id */
109 static int cpm_uart_id2nr(int id
)
113 for (i
=0; i
<UART_NR
; i
++) {
114 if (cpm_uart_port_map
[i
] == id
)
119 /* not found or invalid argument */
124 * Check, if transmit buffers are processed
126 static unsigned int cpm_uart_tx_empty(struct uart_port
*port
)
128 struct uart_cpm_port
*pinfo
= (struct uart_cpm_port
*)port
;
129 volatile cbd_t
*bdp
= pinfo
->tx_bd_base
;
133 if (bdp
->cbd_sc
& BD_SC_READY
)
136 if (bdp
->cbd_sc
& BD_SC_WRAP
) {
143 pr_debug("CPM uart[%d]:tx_empty: %d\n", port
->line
, ret
);
148 static void cpm_uart_set_mctrl(struct uart_port
*port
, unsigned int mctrl
)
150 /* Whee. Do nothing. */
153 static unsigned int cpm_uart_get_mctrl(struct uart_port
*port
)
155 /* Whee. Do nothing. */
156 return TIOCM_CAR
| TIOCM_DSR
| TIOCM_CTS
;
162 static void cpm_uart_stop_tx(struct uart_port
*port
)
164 struct uart_cpm_port
*pinfo
= (struct uart_cpm_port
*)port
;
165 volatile smc_t
*smcp
= pinfo
->smcp
;
166 volatile scc_t
*sccp
= pinfo
->sccp
;
168 pr_debug("CPM uart[%d]:stop tx\n", port
->line
);
171 smcp
->smc_smcm
&= ~SMCM_TX
;
173 sccp
->scc_sccm
&= ~UART_SCCM_TX
;
179 static void cpm_uart_start_tx(struct uart_port
*port
)
181 struct uart_cpm_port
*pinfo
= (struct uart_cpm_port
*)port
;
182 volatile smc_t
*smcp
= pinfo
->smcp
;
183 volatile scc_t
*sccp
= pinfo
->sccp
;
185 pr_debug("CPM uart[%d]:start tx\n", port
->line
);
188 if (smcp
->smc_smcm
& SMCM_TX
)
191 if (sccp
->scc_sccm
& UART_SCCM_TX
)
195 if (cpm_uart_tx_pump(port
) != 0) {
197 smcp
->smc_smcm
|= SMCM_TX
;
198 smcp
->smc_smcmr
|= SMCMR_TEN
;
200 sccp
->scc_sccm
|= UART_SCCM_TX
;
201 pinfo
->sccp
->scc_gsmrl
|= SCC_GSMRL_ENT
;
209 static void cpm_uart_stop_rx(struct uart_port
*port
)
211 struct uart_cpm_port
*pinfo
= (struct uart_cpm_port
*)port
;
212 volatile smc_t
*smcp
= pinfo
->smcp
;
213 volatile scc_t
*sccp
= pinfo
->sccp
;
215 pr_debug("CPM uart[%d]:stop rx\n", port
->line
);
218 smcp
->smc_smcm
&= ~SMCM_RX
;
220 sccp
->scc_sccm
&= ~UART_SCCM_RX
;
224 * Enable Modem status interrupts
226 static void cpm_uart_enable_ms(struct uart_port
*port
)
228 pr_debug("CPM uart[%d]:enable ms\n", port
->line
);
234 static void cpm_uart_break_ctl(struct uart_port
*port
, int break_state
)
236 struct uart_cpm_port
*pinfo
= (struct uart_cpm_port
*)port
;
237 int line
= pinfo
- cpm_uart_ports
;
239 pr_debug("CPM uart[%d]:break ctrl, break_state: %d\n", port
->line
,
243 cpm_line_cr_cmd(line
, CPM_CR_STOP_TX
);
245 cpm_line_cr_cmd(line
, CPM_CR_RESTART_TX
);
249 * Transmit characters, refill buffer descriptor, if possible
251 static void cpm_uart_int_tx(struct uart_port
*port
, struct pt_regs
*regs
)
253 pr_debug("CPM uart[%d]:TX INT\n", port
->line
);
255 cpm_uart_tx_pump(port
);
261 static void cpm_uart_int_rx(struct uart_port
*port
, struct pt_regs
*regs
)
264 unsigned char ch
, *cp
;
265 struct tty_struct
*tty
= port
->info
->tty
;
266 struct uart_cpm_port
*pinfo
= (struct uart_cpm_port
*)port
;
271 pr_debug("CPM uart[%d]:RX INT\n", port
->line
);
273 /* Just loop through the closed BDs and copy the characters into
279 status
= bdp
->cbd_sc
;
280 /* If this one is empty, return happy */
281 if (status
& BD_SC_EMPTY
)
284 /* get number of characters, and check spce in flip-buffer */
287 /* If we have not enough room in tty flip buffer, then we try
288 * later, which will be the next rx-interrupt or a timeout
290 if(tty_buffer_request_room(tty
, i
) < i
) {
291 printk(KERN_WARNING
"No room in flip buffer\n");
296 cp
= cpm2cpu_addr(bdp
->cbd_bufaddr
, pinfo
);
298 /* loop through the buffer */
305 (BD_SC_BR
| BD_SC_FR
| BD_SC_PR
| BD_SC_OV
))
307 if (uart_handle_sysrq_char(port
, ch
, regs
))
311 tty_insert_flip_char(tty
, ch
, flg
);
313 } /* End while (i--) */
315 /* This BD is ready to be used again. Clear status. get next */
316 bdp
->cbd_sc
&= ~(BD_SC_BR
| BD_SC_FR
| BD_SC_PR
| BD_SC_OV
| BD_SC_ID
);
317 bdp
->cbd_sc
|= BD_SC_EMPTY
;
319 if (bdp
->cbd_sc
& BD_SC_WRAP
)
320 bdp
= pinfo
->rx_bd_base
;
326 /* Write back buffer pointer */
327 pinfo
->rx_cur
= (volatile cbd_t
*) bdp
;
329 /* activate BH processing */
330 tty_flip_buffer_push(tty
);
334 /* Error processing */
338 if (status
& BD_SC_BR
)
340 if (status
& BD_SC_PR
)
341 port
->icount
.parity
++;
342 if (status
& BD_SC_FR
)
343 port
->icount
.frame
++;
344 if (status
& BD_SC_OV
)
345 port
->icount
.overrun
++;
347 /* Mask out ignored conditions */
348 status
&= port
->read_status_mask
;
350 /* Handle the remaining ones */
351 if (status
& BD_SC_BR
)
353 else if (status
& BD_SC_PR
)
355 else if (status
& BD_SC_FR
)
358 /* overrun does not affect the current character ! */
359 if (status
& BD_SC_OV
) {
362 /* We skip this buffer */
363 /* CHECK: Is really nothing senseful there */
364 /* ASSUMPTION: it contains nothing valid */
374 * Asynchron mode interrupt handler
376 static irqreturn_t
cpm_uart_int(int irq
, void *data
, struct pt_regs
*regs
)
379 struct uart_port
*port
= (struct uart_port
*)data
;
380 struct uart_cpm_port
*pinfo
= (struct uart_cpm_port
*)port
;
381 volatile smc_t
*smcp
= pinfo
->smcp
;
382 volatile scc_t
*sccp
= pinfo
->sccp
;
384 pr_debug("CPM uart[%d]:IRQ\n", port
->line
);
387 events
= smcp
->smc_smce
;
388 smcp
->smc_smce
= events
;
389 if (events
& SMCM_BRKE
)
390 uart_handle_break(port
);
391 if (events
& SMCM_RX
)
392 cpm_uart_int_rx(port
, regs
);
393 if (events
& SMCM_TX
)
394 cpm_uart_int_tx(port
, regs
);
396 events
= sccp
->scc_scce
;
397 sccp
->scc_scce
= events
;
398 if (events
& UART_SCCM_BRKE
)
399 uart_handle_break(port
);
400 if (events
& UART_SCCM_RX
)
401 cpm_uart_int_rx(port
, regs
);
402 if (events
& UART_SCCM_TX
)
403 cpm_uart_int_tx(port
, regs
);
405 return (events
) ? IRQ_HANDLED
: IRQ_NONE
;
408 static int cpm_uart_startup(struct uart_port
*port
)
411 struct uart_cpm_port
*pinfo
= (struct uart_cpm_port
*)port
;
412 int line
= pinfo
- cpm_uart_ports
;
414 pr_debug("CPM uart[%d]:startup\n", port
->line
);
416 /* Install interrupt handler. */
417 retval
= request_irq(port
->irq
, cpm_uart_int
, 0, "cpm_uart", port
);
423 pinfo
->smcp
->smc_smcm
|= SMCM_RX
;
424 pinfo
->smcp
->smc_smcmr
|= SMCMR_REN
;
426 pinfo
->sccp
->scc_sccm
|= UART_SCCM_RX
;
429 if (!(pinfo
->flags
& FLAG_CONSOLE
))
430 cpm_line_cr_cmd(line
,CPM_CR_INIT_TRX
);
434 inline void cpm_uart_wait_until_send(struct uart_cpm_port
*pinfo
)
436 set_current_state(TASK_UNINTERRUPTIBLE
);
437 schedule_timeout(pinfo
->wait_closing
);
443 static void cpm_uart_shutdown(struct uart_port
*port
)
445 struct uart_cpm_port
*pinfo
= (struct uart_cpm_port
*)port
;
446 int line
= pinfo
- cpm_uart_ports
;
448 pr_debug("CPM uart[%d]:shutdown\n", port
->line
);
450 /* free interrupt handler */
451 free_irq(port
->irq
, port
);
453 /* If the port is not the console, disable Rx and Tx. */
454 if (!(pinfo
->flags
& FLAG_CONSOLE
)) {
455 /* Wait for all the BDs marked sent */
456 while(!cpm_uart_tx_empty(port
)) {
457 set_current_state(TASK_UNINTERRUPTIBLE
);
461 if (pinfo
->wait_closing
)
462 cpm_uart_wait_until_send(pinfo
);
466 volatile smc_t
*smcp
= pinfo
->smcp
;
467 smcp
->smc_smcmr
&= ~(SMCMR_REN
| SMCMR_TEN
);
468 smcp
->smc_smcm
&= ~(SMCM_RX
| SMCM_TX
);
470 volatile scc_t
*sccp
= pinfo
->sccp
;
471 sccp
->scc_gsmrl
&= ~(SCC_GSMRL_ENR
| SCC_GSMRL_ENT
);
472 sccp
->scc_sccm
&= ~(UART_SCCM_TX
| UART_SCCM_RX
);
475 /* Shut them really down and reinit buffer descriptors */
477 cpm_line_cr_cmd(line
, CPM_CR_STOP_TX
);
479 cpm_line_cr_cmd(line
, CPM_CR_GRA_STOP_TX
);
481 cpm_uart_initbd(pinfo
);
485 static void cpm_uart_set_termios(struct uart_port
*port
,
486 struct termios
*termios
, struct termios
*old
)
490 u16 cval
, scval
, prev_mode
;
492 struct uart_cpm_port
*pinfo
= (struct uart_cpm_port
*)port
;
493 volatile smc_t
*smcp
= pinfo
->smcp
;
494 volatile scc_t
*sccp
= pinfo
->sccp
;
496 pr_debug("CPM uart[%d]:set_termios\n", port
->line
);
498 baud
= uart_get_baud_rate(port
, termios
, old
, 0, port
->uartclk
/ 16);
500 /* Character length programmed into the mode register is the
501 * sum of: 1 start bit, number of data bits, 0 or 1 parity bit,
502 * 1 or 2 stop bits, minus 1.
503 * The value 'bits' counts this for us.
509 switch (termios
->c_cflag
& CSIZE
) {
522 /* Never happens, but GCC is too dumb to figure it out */
529 if (termios
->c_cflag
& CSTOPB
) {
530 cval
|= SMCMR_SL
; /* Two stops */
531 scval
|= SCU_PSMR_SL
;
535 if (termios
->c_cflag
& PARENB
) {
537 scval
|= SCU_PSMR_PEN
;
539 if (!(termios
->c_cflag
& PARODD
)) {
540 cval
|= SMCMR_PM_EVEN
;
541 scval
|= (SCU_PSMR_REVP
| SCU_PSMR_TEVP
);
546 * Set up parity check flag
548 #define RELEVANT_IFLAG(iflag) (iflag & (IGNBRK|BRKINT|IGNPAR|PARMRK|INPCK))
550 port
->read_status_mask
= (BD_SC_EMPTY
| BD_SC_OV
);
551 if (termios
->c_iflag
& INPCK
)
552 port
->read_status_mask
|= BD_SC_FR
| BD_SC_PR
;
553 if ((termios
->c_iflag
& BRKINT
) || (termios
->c_iflag
& PARMRK
))
554 port
->read_status_mask
|= BD_SC_BR
;
557 * Characters to ignore
559 port
->ignore_status_mask
= 0;
560 if (termios
->c_iflag
& IGNPAR
)
561 port
->ignore_status_mask
|= BD_SC_PR
| BD_SC_FR
;
562 if (termios
->c_iflag
& IGNBRK
) {
563 port
->ignore_status_mask
|= BD_SC_BR
;
565 * If we're ignore parity and break indicators, ignore
566 * overruns too. (For real raw support).
568 if (termios
->c_iflag
& IGNPAR
)
569 port
->ignore_status_mask
|= BD_SC_OV
;
572 * !!! ignore all characters if CREAD is not set
574 if ((termios
->c_cflag
& CREAD
) == 0)
575 port
->read_status_mask
&= ~BD_SC_EMPTY
;
577 spin_lock_irqsave(&port
->lock
, flags
);
579 /* Start bit has not been added (so don't, because we would just
580 * subtract it later), and we need to add one for the number of
581 * stops bits (there is always at least one).
585 /* Set the mode register. We want to keep a copy of the
586 * enables, because we want to put them back if they were
589 prev_mode
= smcp
->smc_smcmr
;
590 smcp
->smc_smcmr
= smcr_mk_clen(bits
) | cval
| SMCMR_SM_UART
;
591 smcp
->smc_smcmr
|= (prev_mode
& (SMCMR_REN
| SMCMR_TEN
));
593 sccp
->scc_psmr
= (sbits
<< 12) | scval
;
596 cpm_set_brg(pinfo
->brg
- 1, baud
);
597 spin_unlock_irqrestore(&port
->lock
, flags
);
601 static const char *cpm_uart_type(struct uart_port
*port
)
603 pr_debug("CPM uart[%d]:uart_type\n", port
->line
);
605 return port
->type
== PORT_CPM
? "CPM UART" : NULL
;
609 * verify the new serial_struct (for TIOCSSERIAL).
611 static int cpm_uart_verify_port(struct uart_port
*port
,
612 struct serial_struct
*ser
)
616 pr_debug("CPM uart[%d]:verify_port\n", port
->line
);
618 if (ser
->type
!= PORT_UNKNOWN
&& ser
->type
!= PORT_CPM
)
620 if (ser
->irq
< 0 || ser
->irq
>= NR_IRQS
)
622 if (ser
->baud_base
< 9600)
628 * Transmit characters, refill buffer descriptor, if possible
630 static int cpm_uart_tx_pump(struct uart_port
*port
)
635 struct uart_cpm_port
*pinfo
= (struct uart_cpm_port
*)port
;
636 struct circ_buf
*xmit
= &port
->info
->xmit
;
638 /* Handle xon/xoff */
640 /* Pick next descriptor and fill from buffer */
643 p
= cpm2cpu_addr(bdp
->cbd_bufaddr
, pinfo
);
647 bdp
->cbd_sc
|= BD_SC_READY
;
649 if (bdp
->cbd_sc
& BD_SC_WRAP
)
650 bdp
= pinfo
->tx_bd_base
;
660 if (uart_circ_empty(xmit
) || uart_tx_stopped(port
)) {
661 cpm_uart_stop_tx(port
);
665 /* Pick next descriptor and fill from buffer */
668 while (!(bdp
->cbd_sc
& BD_SC_READY
) && (xmit
->tail
!= xmit
->head
)) {
670 p
= cpm2cpu_addr(bdp
->cbd_bufaddr
, pinfo
);
671 while (count
< pinfo
->tx_fifosize
) {
672 *p
++ = xmit
->buf
[xmit
->tail
];
673 xmit
->tail
= (xmit
->tail
+ 1) & (UART_XMIT_SIZE
- 1);
676 if (xmit
->head
== xmit
->tail
)
679 bdp
->cbd_datlen
= count
;
680 bdp
->cbd_sc
|= BD_SC_READY
;
683 if (bdp
->cbd_sc
& BD_SC_WRAP
)
684 bdp
= pinfo
->tx_bd_base
;
690 if (uart_circ_chars_pending(xmit
) < WAKEUP_CHARS
)
691 uart_write_wakeup(port
);
693 if (uart_circ_empty(xmit
)) {
694 cpm_uart_stop_tx(port
);
702 * init buffer descriptors
704 static void cpm_uart_initbd(struct uart_cpm_port
*pinfo
)
710 pr_debug("CPM uart[%d]:initbd\n", pinfo
->port
.line
);
712 /* Set the physical address of the host memory
713 * buffers in the buffer descriptors, and the
714 * virtual address for us to work with.
716 mem_addr
= pinfo
->mem_addr
;
717 bdp
= pinfo
->rx_cur
= pinfo
->rx_bd_base
;
718 for (i
= 0; i
< (pinfo
->rx_nrfifos
- 1); i
++, bdp
++) {
719 bdp
->cbd_bufaddr
= cpu2cpm_addr(mem_addr
, pinfo
);
720 bdp
->cbd_sc
= BD_SC_EMPTY
| BD_SC_INTRPT
;
721 mem_addr
+= pinfo
->rx_fifosize
;
724 bdp
->cbd_bufaddr
= cpu2cpm_addr(mem_addr
, pinfo
);
725 bdp
->cbd_sc
= BD_SC_WRAP
| BD_SC_EMPTY
| BD_SC_INTRPT
;
727 /* Set the physical address of the host memory
728 * buffers in the buffer descriptors, and the
729 * virtual address for us to work with.
731 mem_addr
= pinfo
->mem_addr
+ L1_CACHE_ALIGN(pinfo
->rx_nrfifos
* pinfo
->rx_fifosize
);
732 bdp
= pinfo
->tx_cur
= pinfo
->tx_bd_base
;
733 for (i
= 0; i
< (pinfo
->tx_nrfifos
- 1); i
++, bdp
++) {
734 bdp
->cbd_bufaddr
= cpu2cpm_addr(mem_addr
, pinfo
);
735 bdp
->cbd_sc
= BD_SC_INTRPT
;
736 mem_addr
+= pinfo
->tx_fifosize
;
739 bdp
->cbd_bufaddr
= cpu2cpm_addr(mem_addr
, pinfo
);
740 bdp
->cbd_sc
= BD_SC_WRAP
| BD_SC_INTRPT
;
743 static void cpm_uart_init_scc(struct uart_cpm_port
*pinfo
)
745 int line
= pinfo
- cpm_uart_ports
;
747 volatile scc_uart_t
*sup
;
749 pr_debug("CPM uart[%d]:init_scc\n", pinfo
->port
.line
);
755 pinfo
->sccup
->scc_genscc
.scc_rbase
= (unsigned char *)pinfo
->rx_bd_base
- DPRAM_BASE
;
756 pinfo
->sccup
->scc_genscc
.scc_tbase
= (unsigned char *)pinfo
->tx_bd_base
- DPRAM_BASE
;
758 /* Set up the uart parameters in the
762 cpm_set_scc_fcr(sup
);
764 sup
->scc_genscc
.scc_mrblr
= pinfo
->rx_fifosize
;
765 sup
->scc_maxidl
= pinfo
->rx_fifosize
;
774 sup
->scc_char1
= 0x8000;
775 sup
->scc_char2
= 0x8000;
776 sup
->scc_char3
= 0x8000;
777 sup
->scc_char4
= 0x8000;
778 sup
->scc_char5
= 0x8000;
779 sup
->scc_char6
= 0x8000;
780 sup
->scc_char7
= 0x8000;
781 sup
->scc_char8
= 0x8000;
782 sup
->scc_rccm
= 0xc0ff;
784 /* Send the CPM an initialize command.
786 cpm_line_cr_cmd(line
, CPM_CR_INIT_TRX
);
788 /* Set UART mode, 8 bit, no parity, one stop.
789 * Enable receive and transmit.
793 (SCC_GSMRL_MODE_UART
| SCC_GSMRL_TDCR_16
| SCC_GSMRL_RDCR_16
);
795 /* Enable rx interrupts and clear all pending events. */
797 scp
->scc_scce
= 0xffff;
798 scp
->scc_dsr
= 0x7e7e;
799 scp
->scc_psmr
= 0x3000;
801 scp
->scc_gsmrl
|= (SCC_GSMRL_ENR
| SCC_GSMRL_ENT
);
804 static void cpm_uart_init_smc(struct uart_cpm_port
*pinfo
)
806 int line
= pinfo
- cpm_uart_ports
;
808 volatile smc_uart_t
*up
;
810 pr_debug("CPM uart[%d]:init_smc\n", pinfo
->port
.line
);
816 pinfo
->smcup
->smc_rbase
= (u_char
*)pinfo
->rx_bd_base
- DPRAM_BASE
;
817 pinfo
->smcup
->smc_tbase
= (u_char
*)pinfo
->tx_bd_base
- DPRAM_BASE
;
820 * In case SMC1 is being relocated...
822 #if defined (CONFIG_I2C_SPI_SMC1_UCODE_PATCH)
823 up
->smc_rbptr
= pinfo
->smcup
->smc_rbase
;
824 up
->smc_tbptr
= pinfo
->smcup
->smc_tbase
;
827 up
->smc_brkcr
= 1; /* number of break chars */
831 /* Set up the uart parameters in the
836 /* Using idle charater time requires some additional tuning. */
837 up
->smc_mrblr
= pinfo
->rx_fifosize
;
838 up
->smc_maxidl
= pinfo
->rx_fifosize
;
843 cpm_line_cr_cmd(line
, CPM_CR_INIT_TRX
);
845 /* Set UART mode, 8 bit, no parity, one stop.
846 * Enable receive and transmit.
848 sp
->smc_smcmr
= smcr_mk_clen(9) | SMCMR_SM_UART
;
850 /* Enable only rx interrupts clear all pending events. */
854 sp
->smc_smcmr
|= (SMCMR_REN
| SMCMR_TEN
);
858 * Initialize port. This is called from early_console stuff
859 * so we have to be careful here !
861 static int cpm_uart_request_port(struct uart_port
*port
)
863 struct uart_cpm_port
*pinfo
= (struct uart_cpm_port
*)port
;
866 pr_debug("CPM uart[%d]:request port\n", port
->line
);
868 if (pinfo
->flags
& FLAG_CONSOLE
)
872 pinfo
->smcp
->smc_smcm
&= ~(SMCM_RX
| SMCM_TX
);
873 pinfo
->smcp
->smc_smcmr
&= ~(SMCMR_REN
| SMCMR_TEN
);
875 pinfo
->sccp
->scc_sccm
&= ~(UART_SCCM_TX
| UART_SCCM_RX
);
876 pinfo
->sccp
->scc_gsmrl
&= ~(SCC_GSMRL_ENR
| SCC_GSMRL_ENT
);
879 ret
= cpm_uart_allocbuf(pinfo
, 0);
884 cpm_uart_initbd(pinfo
);
886 cpm_uart_init_smc(pinfo
);
888 cpm_uart_init_scc(pinfo
);
893 static void cpm_uart_release_port(struct uart_port
*port
)
895 struct uart_cpm_port
*pinfo
= (struct uart_cpm_port
*)port
;
897 if (!(pinfo
->flags
& FLAG_CONSOLE
))
898 cpm_uart_freebuf(pinfo
);
902 * Configure/autoconfigure the port.
904 static void cpm_uart_config_port(struct uart_port
*port
, int flags
)
906 pr_debug("CPM uart[%d]:config_port\n", port
->line
);
908 if (flags
& UART_CONFIG_TYPE
) {
909 port
->type
= PORT_CPM
;
910 cpm_uart_request_port(port
);
913 static struct uart_ops cpm_uart_pops
= {
914 .tx_empty
= cpm_uart_tx_empty
,
915 .set_mctrl
= cpm_uart_set_mctrl
,
916 .get_mctrl
= cpm_uart_get_mctrl
,
917 .stop_tx
= cpm_uart_stop_tx
,
918 .start_tx
= cpm_uart_start_tx
,
919 .stop_rx
= cpm_uart_stop_rx
,
920 .enable_ms
= cpm_uart_enable_ms
,
921 .break_ctl
= cpm_uart_break_ctl
,
922 .startup
= cpm_uart_startup
,
923 .shutdown
= cpm_uart_shutdown
,
924 .set_termios
= cpm_uart_set_termios
,
925 .type
= cpm_uart_type
,
926 .release_port
= cpm_uart_release_port
,
927 .request_port
= cpm_uart_request_port
,
928 .config_port
= cpm_uart_config_port
,
929 .verify_port
= cpm_uart_verify_port
,
932 struct uart_cpm_port cpm_uart_ports
[UART_NR
] = {
936 .ops
= &cpm_uart_pops
,
938 .lock
= SPIN_LOCK_UNLOCKED
,
941 .tx_nrfifos
= TX_NUM_FIFO
,
942 .tx_fifosize
= TX_BUF_SIZE
,
943 .rx_nrfifos
= RX_NUM_FIFO
,
944 .rx_fifosize
= RX_BUF_SIZE
,
945 .set_lineif
= smc1_lineif
,
950 .ops
= &cpm_uart_pops
,
952 .lock
= SPIN_LOCK_UNLOCKED
,
955 .tx_nrfifos
= TX_NUM_FIFO
,
956 .tx_fifosize
= TX_BUF_SIZE
,
957 .rx_nrfifos
= RX_NUM_FIFO
,
958 .rx_fifosize
= RX_BUF_SIZE
,
959 .set_lineif
= smc2_lineif
,
960 #ifdef CONFIG_SERIAL_CPM_ALT_SMC2
967 .ops
= &cpm_uart_pops
,
969 .lock
= SPIN_LOCK_UNLOCKED
,
971 .tx_nrfifos
= TX_NUM_FIFO
,
972 .tx_fifosize
= TX_BUF_SIZE
,
973 .rx_nrfifos
= RX_NUM_FIFO
,
974 .rx_fifosize
= RX_BUF_SIZE
,
975 .set_lineif
= scc1_lineif
,
976 .wait_closing
= SCC_WAIT_CLOSING
,
981 .ops
= &cpm_uart_pops
,
983 .lock
= SPIN_LOCK_UNLOCKED
,
985 .tx_nrfifos
= TX_NUM_FIFO
,
986 .tx_fifosize
= TX_BUF_SIZE
,
987 .rx_nrfifos
= RX_NUM_FIFO
,
988 .rx_fifosize
= RX_BUF_SIZE
,
989 .set_lineif
= scc2_lineif
,
990 .wait_closing
= SCC_WAIT_CLOSING
,
995 .ops
= &cpm_uart_pops
,
997 .lock
= SPIN_LOCK_UNLOCKED
,
999 .tx_nrfifos
= TX_NUM_FIFO
,
1000 .tx_fifosize
= TX_BUF_SIZE
,
1001 .rx_nrfifos
= RX_NUM_FIFO
,
1002 .rx_fifosize
= RX_BUF_SIZE
,
1003 .set_lineif
= scc3_lineif
,
1004 .wait_closing
= SCC_WAIT_CLOSING
,
1009 .ops
= &cpm_uart_pops
,
1011 .lock
= SPIN_LOCK_UNLOCKED
,
1013 .tx_nrfifos
= TX_NUM_FIFO
,
1014 .tx_fifosize
= TX_BUF_SIZE
,
1015 .rx_nrfifos
= RX_NUM_FIFO
,
1016 .rx_fifosize
= RX_BUF_SIZE
,
1017 .set_lineif
= scc4_lineif
,
1018 .wait_closing
= SCC_WAIT_CLOSING
,
1022 int cpm_uart_drv_get_platform_data(struct platform_device
*pdev
, int is_con
)
1025 struct fs_uart_platform_info
*pdata
= pdev
->dev
.platform_data
;
1026 int idx
= pdata
->fs_no
; /* It is UART_SMCx or UART_SCCx index */
1027 struct uart_cpm_port
*pinfo
;
1031 line
= cpm_uart_id2nr(idx
);
1033 printk(KERN_ERR
"%s(): port %d is not registered", __FUNCTION__
, idx
);
1037 pinfo
= (struct uart_cpm_port
*) &cpm_uart_ports
[idx
];
1039 pinfo
->brg
= pdata
->brg
;
1042 pinfo
->port
.line
= line
;
1043 pinfo
->port
.flags
= UPF_BOOT_AUTOCONF
;
1046 if (!(r
= platform_get_resource_byname(pdev
, IORESOURCE_MEM
, "regs")))
1050 if (!(r
= platform_get_resource_byname(pdev
, IORESOURCE_MEM
, "pram")))
1054 if(idx
> fsid_smc2_uart
) {
1055 pinfo
->sccp
= (scc_t
*)mem
;
1056 pinfo
->sccup
= (scc_uart_t
*)pram
;
1058 pinfo
->smcp
= (smc_t
*)mem
;
1059 pinfo
->smcup
= (smc_uart_t
*)pram
;
1061 pinfo
->tx_nrfifos
= pdata
->tx_num_fifo
;
1062 pinfo
->tx_fifosize
= pdata
->tx_buf_size
;
1064 pinfo
->rx_nrfifos
= pdata
->rx_num_fifo
;
1065 pinfo
->rx_fifosize
= pdata
->rx_buf_size
;
1067 pinfo
->port
.uartclk
= pdata
->uart_clk
;
1068 pinfo
->port
.mapbase
= (unsigned long)mem
;
1069 pinfo
->port
.irq
= platform_get_irq(pdev
, 0);
1074 #ifdef CONFIG_SERIAL_CPM_CONSOLE
1076 * Print a string to the serial port trying not to disturb
1077 * any possible real use of the port...
1079 * Note that this is called with interrupts already disabled
1081 static void cpm_uart_console_write(struct console
*co
, const char *s
,
1084 struct uart_cpm_port
*pinfo
=
1085 &cpm_uart_ports
[cpm_uart_port_map
[co
->index
]];
1087 volatile cbd_t
*bdp
, *bdbase
;
1088 volatile unsigned char *cp
;
1090 /* Get the address of the host memory buffer.
1092 bdp
= pinfo
->tx_cur
;
1093 bdbase
= pinfo
->tx_bd_base
;
1096 * Now, do each character. This is not as bad as it looks
1097 * since this is a holding FIFO and not a transmitting FIFO.
1098 * We could add the complexity of filling the entire transmit
1099 * buffer, but we would just wait longer between accesses......
1101 for (i
= 0; i
< count
; i
++, s
++) {
1102 /* Wait for transmitter fifo to empty.
1103 * Ready indicates output is ready, and xmt is doing
1104 * that, not that it is ready for us to send.
1106 while ((bdp
->cbd_sc
& BD_SC_READY
) != 0)
1109 /* Send the character out.
1110 * If the buffer address is in the CPM DPRAM, don't
1113 cp
= cpm2cpu_addr(bdp
->cbd_bufaddr
, pinfo
);
1117 bdp
->cbd_datlen
= 1;
1118 bdp
->cbd_sc
|= BD_SC_READY
;
1120 if (bdp
->cbd_sc
& BD_SC_WRAP
)
1125 /* if a LF, also do CR... */
1127 while ((bdp
->cbd_sc
& BD_SC_READY
) != 0)
1130 cp
= cpm2cpu_addr(bdp
->cbd_bufaddr
, pinfo
);
1133 bdp
->cbd_datlen
= 1;
1134 bdp
->cbd_sc
|= BD_SC_READY
;
1136 if (bdp
->cbd_sc
& BD_SC_WRAP
)
1144 * Finally, Wait for transmitter & holding register to empty
1145 * and restore the IER
1147 while ((bdp
->cbd_sc
& BD_SC_READY
) != 0)
1150 pinfo
->tx_cur
= (volatile cbd_t
*) bdp
;
1154 static int __init
cpm_uart_console_setup(struct console
*co
, char *options
)
1156 struct uart_port
*port
;
1157 struct uart_cpm_port
*pinfo
;
1164 struct fs_uart_platform_info
*pdata
;
1165 struct platform_device
* pdev
= early_uart_get_pdev(co
->index
);
1168 pr_info("cpm_uart: console: compat mode\n");
1169 /* compatibility - will be cleaned up */
1170 cpm_uart_init_portdesc();
1174 (struct uart_port
*)&cpm_uart_ports
[cpm_uart_port_map
[co
->index
]];
1175 pinfo
= (struct uart_cpm_port
*)port
;
1177 if (pinfo
->set_lineif
)
1178 pinfo
->set_lineif(pinfo
);
1180 pdata
= pdev
->dev
.platform_data
;
1182 if (pdata
->init_ioports
)
1183 pdata
->init_ioports();
1185 cpm_uart_drv_get_platform_data(pdev
, 1);
1188 pinfo
->flags
|= FLAG_CONSOLE
;
1191 uart_parse_options(options
, &baud
, &parity
, &bits
, &flow
);
1193 bd_t
*bd
= (bd_t
*) __res
;
1195 if (bd
->bi_baudrate
)
1196 baud
= bd
->bi_baudrate
;
1201 if (IS_SMC(pinfo
)) {
1202 pinfo
->smcp
->smc_smcm
&= ~(SMCM_RX
| SMCM_TX
);
1203 pinfo
->smcp
->smc_smcmr
&= ~(SMCMR_REN
| SMCMR_TEN
);
1205 pinfo
->sccp
->scc_sccm
&= ~(UART_SCCM_TX
| UART_SCCM_RX
);
1206 pinfo
->sccp
->scc_gsmrl
&= ~(SCC_GSMRL_ENR
| SCC_GSMRL_ENT
);
1209 ret
= cpm_uart_allocbuf(pinfo
, 1);
1214 cpm_uart_initbd(pinfo
);
1217 cpm_uart_init_smc(pinfo
);
1219 cpm_uart_init_scc(pinfo
);
1221 uart_set_options(port
, co
, baud
, parity
, bits
, flow
);
1226 static struct uart_driver cpm_reg
;
1227 static struct console cpm_scc_uart_console
= {
1229 .write
= cpm_uart_console_write
,
1230 .device
= uart_console_device
,
1231 .setup
= cpm_uart_console_setup
,
1232 .flags
= CON_PRINTBUFFER
,
1237 int __init
cpm_uart_console_init(void)
1239 register_console(&cpm_scc_uart_console
);
1243 console_initcall(cpm_uart_console_init
);
1245 #define CPM_UART_CONSOLE &cpm_scc_uart_console
1247 #define CPM_UART_CONSOLE NULL
1250 static struct uart_driver cpm_reg
= {
1251 .owner
= THIS_MODULE
,
1252 .driver_name
= "ttyCPM",
1253 .dev_name
= "ttyCPM",
1254 .major
= SERIAL_CPM_MAJOR
,
1255 .minor
= SERIAL_CPM_MINOR
,
1256 .cons
= CPM_UART_CONSOLE
,
1258 static int cpm_uart_drv_probe(struct device
*dev
)
1260 struct platform_device
*pdev
= to_platform_device(dev
);
1261 struct fs_uart_platform_info
*pdata
;
1265 printk(KERN_ERR
"CPM UART: platform data missing!\n");
1269 pdata
= pdev
->dev
.platform_data
;
1270 pr_debug("cpm_uart_drv_probe: Adding CPM UART %d\n", cpm_uart_id2nr(pdata
->fs_no
));
1272 if ((ret
= cpm_uart_drv_get_platform_data(pdev
, 0)))
1275 if (pdata
->init_ioports
)
1276 pdata
->init_ioports();
1278 ret
= uart_add_one_port(&cpm_reg
, &cpm_uart_ports
[pdata
->fs_no
].port
);
1283 static int cpm_uart_drv_remove(struct device
*dev
)
1285 struct platform_device
*pdev
= to_platform_device(dev
);
1286 struct fs_uart_platform_info
*pdata
= pdev
->dev
.platform_data
;
1288 pr_debug("cpm_uart_drv_remove: Removing CPM UART %d\n",
1289 cpm_uart_id2nr(pdata
->fs_no
));
1291 uart_remove_one_port(&cpm_reg
, &cpm_uart_ports
[pdata
->fs_no
].port
);
1295 static struct device_driver cpm_smc_uart_driver
= {
1296 .name
= "fsl-cpm-smc:uart",
1297 .bus
= &platform_bus_type
,
1298 .probe
= cpm_uart_drv_probe
,
1299 .remove
= cpm_uart_drv_remove
,
1302 static struct device_driver cpm_scc_uart_driver
= {
1303 .name
= "fsl-cpm-scc:uart",
1304 .bus
= &platform_bus_type
,
1305 .probe
= cpm_uart_drv_probe
,
1306 .remove
= cpm_uart_drv_remove
,
1310 This is supposed to match uart devices on platform bus,
1312 static int match_is_uart (struct device
* dev
, void* data
)
1314 struct platform_device
* pdev
= container_of(dev
, struct platform_device
, dev
);
1316 /* this was setfunc as uart */
1317 if(strstr(pdev
->name
,":uart")) {
1324 static int cpm_uart_init(void) {
1329 printk(KERN_INFO
"Serial: CPM driver $Revision: 0.02 $\n");
1331 /* lookup the bus for uart devices */
1332 dev
= bus_find_device(&platform_bus_type
, NULL
, 0, match_is_uart
);
1334 /* There are devices on the bus - all should be OK */
1337 cpm_reg
.nr
= cpm_uart_nr
;
1339 if (!(ret
= uart_register_driver(&cpm_reg
))) {
1340 if ((ret
= driver_register(&cpm_smc_uart_driver
))) {
1341 uart_unregister_driver(&cpm_reg
);
1344 if ((ret
= driver_register(&cpm_scc_uart_driver
))) {
1345 driver_unregister(&cpm_scc_uart_driver
);
1346 uart_unregister_driver(&cpm_reg
);
1350 /* No capable platform devices found - falling back to legacy mode */
1351 pr_info("cpm_uart: WARNING: no UART devices found on platform bus!\n");
1353 "cpm_uart: the driver will guess configuration, but this mode is no longer supported.\n");
1354 #ifndef CONFIG_SERIAL_CPM_CONSOLE
1355 ret
= cpm_uart_init_portdesc();
1360 cpm_reg
.nr
= cpm_uart_nr
;
1361 ret
= uart_register_driver(&cpm_reg
);
1366 for (i
= 0; i
< cpm_uart_nr
; i
++) {
1367 int con
= cpm_uart_port_map
[i
];
1368 cpm_uart_ports
[con
].port
.line
= i
;
1369 cpm_uart_ports
[con
].port
.flags
= UPF_BOOT_AUTOCONF
;
1370 uart_add_one_port(&cpm_reg
, &cpm_uart_ports
[con
].port
);
1377 static void __exit
cpm_uart_exit(void)
1379 driver_unregister(&cpm_scc_uart_driver
);
1380 driver_unregister(&cpm_smc_uart_driver
);
1381 uart_unregister_driver(&cpm_reg
);
1384 module_init(cpm_uart_init
);
1385 module_exit(cpm_uart_exit
);
1387 MODULE_AUTHOR("Kumar Gala/Antoniou Pantelis");
1388 MODULE_DESCRIPTION("CPM SCC/SMC port driver $Revision: 0.01 $");
1389 MODULE_LICENSE("GPL");
1390 MODULE_ALIAS_CHARDEV(SERIAL_CPM_MAJOR
, SERIAL_CPM_MINOR
);