2 * linux/drivers/serial/cpm_uart_cpm2.c
4 * Driver for CPM (SCC/SMC) serial ports; CPM2 definitions
6 * Maintainer: Kumar Gala (galak@kernel.crashing.org) (CPM2)
7 * Pantelis Antoniou (panto@intracom.gr) (CPM1)
9 * Copyright (C) 2004 Freescale Semiconductor, Inc.
10 * (C) 2004 Intracom, S.A.
11 * (C) 2006 MontaVista Software, Inc.
12 * Vitaly Bordug <vbordug@ru.mvista.com>
14 * This program is free software; you can redistribute it and/or modify
15 * it under the terms of the GNU General Public License as published by
16 * the Free Software Foundation; either version 2 of the License, or
17 * (at your option) any later version.
19 * This program is distributed in the hope that it will be useful,
20 * but WITHOUT ANY WARRANTY; without even the implied warranty of
21 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
22 * GNU General Public License for more details.
24 * You should have received a copy of the GNU General Public License
25 * along with this program; if not, write to the Free Software
26 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
30 #include <linux/module.h>
31 #include <linux/tty.h>
32 #include <linux/ioport.h>
33 #include <linux/slab.h>
34 #include <linux/init.h>
35 #include <linux/serial.h>
36 #include <linux/console.h>
37 #include <linux/sysrq.h>
38 #include <linux/device.h>
39 #include <linux/bootmem.h>
40 #include <linux/dma-mapping.h>
44 #include <asm/fs_pd.h>
47 #include <linux/serial_core.h>
48 #include <linux/kernel.h>
52 /**************************************************************/
54 void cpm_line_cr_cmd(struct uart_cpm_port
*port
, int cmd
)
56 cpm_command(port
->command
, cmd
);
59 void __iomem
*cpm_uart_map_pram(struct uart_cpm_port
*port
,
60 struct device_node
*np
)
67 /* Don't remap parameter RAM if it has already been initialized
68 * during console setup.
70 if (IS_SMC(port
) && port
->smcup
)
72 else if (!IS_SMC(port
) && port
->sccup
)
75 if (of_address_to_resource(np
, 1, &res
))
78 len
= resource_size(&res
);
79 pram
= ioremap(res
.start
, len
);
87 printk(KERN_WARNING
"cpm_uart[%d]: device tree references "
88 "SMC pram, using boot loader/wrapper pram mapping. "
89 "Please fix your device tree to reference the pram "
90 "base register instead.\n",
95 offset
= cpm_dpalloc(PROFF_SMC_SIZE
, 64);
96 out_be16(pram
, offset
);
98 return cpm_muram_addr(offset
);
101 void cpm_uart_unmap_pram(struct uart_cpm_port
*port
, void __iomem
*pram
)
108 * Allocate DP-Ram and memory buffers. We need to allocate a transmit and
109 * receive buffer descriptors from dual port ram, and a character
110 * buffer area from host mem. If we are allocating for the console we need
111 * to do it from bootmem
113 int cpm_uart_allocbuf(struct uart_cpm_port
*pinfo
, unsigned int is_con
)
117 unsigned long dp_offset
;
119 dma_addr_t dma_addr
= 0;
121 pr_debug("CPM uart[%d]:allocbuf\n", pinfo
->port
.line
);
123 dpmemsz
= sizeof(cbd_t
) * (pinfo
->rx_nrfifos
+ pinfo
->tx_nrfifos
);
124 dp_offset
= cpm_dpalloc(dpmemsz
, 8);
125 if (IS_ERR_VALUE(dp_offset
)) {
127 "cpm_uart_cpm.c: could not allocate buffer descriptors\n");
131 dp_mem
= cpm_dpram_addr(dp_offset
);
133 memsz
= L1_CACHE_ALIGN(pinfo
->rx_nrfifos
* pinfo
->rx_fifosize
) +
134 L1_CACHE_ALIGN(pinfo
->tx_nrfifos
* pinfo
->tx_fifosize
);
136 mem_addr
= kzalloc(memsz
, GFP_NOWAIT
);
137 dma_addr
= virt_to_bus(mem_addr
);
140 mem_addr
= dma_alloc_coherent(pinfo
->port
.dev
, memsz
, &dma_addr
,
143 if (mem_addr
== NULL
) {
144 cpm_dpfree(dp_offset
);
146 "cpm_uart_cpm.c: could not allocate coherent memory\n");
150 pinfo
->dp_addr
= dp_offset
;
151 pinfo
->mem_addr
= mem_addr
;
152 pinfo
->dma_addr
= dma_addr
;
153 pinfo
->mem_size
= memsz
;
155 pinfo
->rx_buf
= mem_addr
;
156 pinfo
->tx_buf
= pinfo
->rx_buf
+ L1_CACHE_ALIGN(pinfo
->rx_nrfifos
157 * pinfo
->rx_fifosize
);
159 pinfo
->rx_bd_base
= (cbd_t __iomem
*)dp_mem
;
160 pinfo
->tx_bd_base
= pinfo
->rx_bd_base
+ pinfo
->rx_nrfifos
;
165 void cpm_uart_freebuf(struct uart_cpm_port
*pinfo
)
167 dma_free_coherent(pinfo
->port
.dev
, L1_CACHE_ALIGN(pinfo
->rx_nrfifos
*
168 pinfo
->rx_fifosize
) +
169 L1_CACHE_ALIGN(pinfo
->tx_nrfifos
*
170 pinfo
->tx_fifosize
), (void __force
*)pinfo
->mem_addr
,
173 cpm_dpfree(pinfo
->dp_addr
);