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/init.h>
33 #include <linux/serial.h>
34 #include <linux/console.h>
35 #include <linux/sysrq.h>
36 #include <linux/device.h>
37 #include <linux/bootmem.h>
38 #include <linux/dma-mapping.h>
42 #include <asm/fs_pd.h>
45 #include <linux/serial_core.h>
46 #include <linux/kernel.h>
50 /**************************************************************/
52 void cpm_line_cr_cmd(struct uart_cpm_port
*port
, int cmd
)
54 cpm_command(port
->command
, cmd
);
57 void __iomem
*cpm_uart_map_pram(struct uart_cpm_port
*port
,
58 struct device_node
*np
)
65 /* Don't remap parameter RAM if it has already been initialized
66 * during console setup.
68 if (IS_SMC(port
) && port
->smcup
)
70 else if (!IS_SMC(port
) && port
->sccup
)
73 if (of_address_to_resource(np
, 1, &res
))
76 len
= resource_size(&res
);
77 pram
= ioremap(res
.start
, len
);
85 printk(KERN_WARNING
"cpm_uart[%d]: device tree references "
86 "SMC pram, using boot loader/wrapper pram mapping. "
87 "Please fix your device tree to reference the pram "
88 "base register instead.\n",
93 offset
= cpm_dpalloc(PROFF_SMC_SIZE
, 64);
94 out_be16(pram
, offset
);
96 return cpm_muram_addr(offset
);
99 void cpm_uart_unmap_pram(struct uart_cpm_port
*port
, void __iomem
*pram
)
106 * Allocate DP-Ram and memory buffers. We need to allocate a transmit and
107 * receive buffer descriptors from dual port ram, and a character
108 * buffer area from host mem. If we are allocating for the console we need
109 * to do it from bootmem
111 int cpm_uart_allocbuf(struct uart_cpm_port
*pinfo
, unsigned int is_con
)
115 unsigned long dp_offset
;
117 dma_addr_t dma_addr
= 0;
119 pr_debug("CPM uart[%d]:allocbuf\n", pinfo
->port
.line
);
121 dpmemsz
= sizeof(cbd_t
) * (pinfo
->rx_nrfifos
+ pinfo
->tx_nrfifos
);
122 dp_offset
= cpm_dpalloc(dpmemsz
, 8);
123 if (IS_ERR_VALUE(dp_offset
)) {
125 "cpm_uart_cpm.c: could not allocate buffer descriptors\n");
129 dp_mem
= cpm_dpram_addr(dp_offset
);
131 memsz
= L1_CACHE_ALIGN(pinfo
->rx_nrfifos
* pinfo
->rx_fifosize
) +
132 L1_CACHE_ALIGN(pinfo
->tx_nrfifos
* pinfo
->tx_fifosize
);
134 mem_addr
= kzalloc(memsz
, GFP_NOWAIT
);
135 dma_addr
= virt_to_bus(mem_addr
);
138 mem_addr
= dma_alloc_coherent(pinfo
->port
.dev
, memsz
, &dma_addr
,
141 if (mem_addr
== NULL
) {
142 cpm_dpfree(dp_offset
);
144 "cpm_uart_cpm.c: could not allocate coherent memory\n");
148 pinfo
->dp_addr
= dp_offset
;
149 pinfo
->mem_addr
= mem_addr
;
150 pinfo
->dma_addr
= dma_addr
;
151 pinfo
->mem_size
= memsz
;
153 pinfo
->rx_buf
= mem_addr
;
154 pinfo
->tx_buf
= pinfo
->rx_buf
+ L1_CACHE_ALIGN(pinfo
->rx_nrfifos
155 * pinfo
->rx_fifosize
);
157 pinfo
->rx_bd_base
= (cbd_t __iomem
*)dp_mem
;
158 pinfo
->tx_bd_base
= pinfo
->rx_bd_base
+ pinfo
->rx_nrfifos
;
163 void cpm_uart_freebuf(struct uart_cpm_port
*pinfo
)
165 dma_free_coherent(pinfo
->port
.dev
, L1_CACHE_ALIGN(pinfo
->rx_nrfifos
*
166 pinfo
->rx_fifosize
) +
167 L1_CACHE_ALIGN(pinfo
->tx_nrfifos
*
168 pinfo
->tx_fifosize
), (void __force
*)pinfo
->mem_addr
,
171 cpm_dpfree(pinfo
->dp_addr
);