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