1 // SPDX-License-Identifier: GPL-2.0+
3 * Driver for CPM (SCC/SMC) serial ports; CPM2 definitions
5 * Maintainer: Kumar Gala (galak@kernel.crashing.org) (CPM2)
6 * Pantelis Antoniou (panto@intracom.gr) (CPM1)
8 * Copyright (C) 2004 Freescale Semiconductor, Inc.
9 * (C) 2004 Intracom, S.A.
10 * (C) 2006 MontaVista Software, Inc.
11 * Vitaly Bordug <vbordug@ru.mvista.com>
14 #include <linux/module.h>
15 #include <linux/tty.h>
16 #include <linux/ioport.h>
17 #include <linux/slab.h>
18 #include <linux/serial.h>
19 #include <linux/console.h>
20 #include <linux/sysrq.h>
21 #include <linux/device.h>
22 #include <linux/memblock.h>
23 #include <linux/dma-mapping.h>
27 #include <asm/fs_pd.h>
30 #include <linux/serial_core.h>
31 #include <linux/kernel.h>
35 /**************************************************************/
37 void cpm_line_cr_cmd(struct uart_cpm_port
*port
, int cmd
)
39 cpm_command(port
->command
, cmd
);
42 void __iomem
*cpm_uart_map_pram(struct uart_cpm_port
*port
,
43 struct device_node
*np
)
50 /* Don't remap parameter RAM if it has already been initialized
51 * during console setup.
53 if (IS_SMC(port
) && port
->smcup
)
55 else if (!IS_SMC(port
) && port
->sccup
)
58 if (of_address_to_resource(np
, 1, &res
))
61 len
= resource_size(&res
);
62 pram
= ioremap(res
.start
, len
);
70 printk(KERN_WARNING
"cpm_uart[%d]: device tree references "
71 "SMC pram, using boot loader/wrapper pram mapping. "
72 "Please fix your device tree to reference the pram "
73 "base register instead.\n",
78 offset
= cpm_dpalloc(PROFF_SMC_SIZE
, 64);
79 out_be16(pram
, offset
);
81 return cpm_muram_addr(offset
);
84 void cpm_uart_unmap_pram(struct uart_cpm_port
*port
, void __iomem
*pram
)
91 * Allocate DP-Ram and memory buffers. We need to allocate a transmit and
92 * receive buffer descriptors from dual port ram, and a character
93 * buffer area from host mem. If we are allocating for the console we need
94 * to do it from bootmem
96 int cpm_uart_allocbuf(struct uart_cpm_port
*pinfo
, unsigned int is_con
)
100 unsigned long dp_offset
;
102 dma_addr_t dma_addr
= 0;
104 pr_debug("CPM uart[%d]:allocbuf\n", pinfo
->port
.line
);
106 dpmemsz
= sizeof(cbd_t
) * (pinfo
->rx_nrfifos
+ pinfo
->tx_nrfifos
);
107 dp_offset
= cpm_dpalloc(dpmemsz
, 8);
108 if (IS_ERR_VALUE(dp_offset
)) {
110 "cpm_uart_cpm.c: could not allocate buffer descriptors\n");
114 dp_mem
= cpm_dpram_addr(dp_offset
);
116 memsz
= L1_CACHE_ALIGN(pinfo
->rx_nrfifos
* pinfo
->rx_fifosize
) +
117 L1_CACHE_ALIGN(pinfo
->tx_nrfifos
* pinfo
->tx_fifosize
);
119 mem_addr
= kzalloc(memsz
, GFP_NOWAIT
);
120 dma_addr
= virt_to_bus(mem_addr
);
123 mem_addr
= dma_alloc_coherent(pinfo
->port
.dev
, memsz
, &dma_addr
,
126 if (mem_addr
== NULL
) {
127 cpm_dpfree(dp_offset
);
129 "cpm_uart_cpm.c: could not allocate coherent memory\n");
133 pinfo
->dp_addr
= dp_offset
;
134 pinfo
->mem_addr
= mem_addr
;
135 pinfo
->dma_addr
= dma_addr
;
136 pinfo
->mem_size
= memsz
;
138 pinfo
->rx_buf
= mem_addr
;
139 pinfo
->tx_buf
= pinfo
->rx_buf
+ L1_CACHE_ALIGN(pinfo
->rx_nrfifos
140 * pinfo
->rx_fifosize
);
142 pinfo
->rx_bd_base
= (cbd_t __iomem
*)dp_mem
;
143 pinfo
->tx_bd_base
= pinfo
->rx_bd_base
+ pinfo
->rx_nrfifos
;
148 void cpm_uart_freebuf(struct uart_cpm_port
*pinfo
)
150 dma_free_coherent(pinfo
->port
.dev
, L1_CACHE_ALIGN(pinfo
->rx_nrfifos
*
151 pinfo
->rx_fifosize
) +
152 L1_CACHE_ALIGN(pinfo
->tx_nrfifos
*
153 pinfo
->tx_fifosize
), (void __force
*)pinfo
->mem_addr
,
156 cpm_dpfree(pinfo
->dp_addr
);