tty: add SPDX identifiers to all remaining files in drivers/tty/
[linux-2.6-block.git] / drivers / tty / serial / cpm_uart / cpm_uart_cpm1.c
CommitLineData
e3b3d0f5 1// SPDX-License-Identifier: GPL-2.0+
1da177e4 2/*
1da177e4
LT
3 * Driver for CPM (SCC/SMC) serial ports; CPM1 definitions
4 *
4c8d3d99 5 * Maintainer: Kumar Gala (galak@kernel.crashing.org) (CPM2)
1da177e4 6 * Pantelis Antoniou (panto@intracom.gr) (CPM1)
311c4627 7 *
1da177e4
LT
8 * Copyright (C) 2004 Freescale Semiconductor, Inc.
9 * (C) 2004 Intracom, S.A.
6e197696 10 * (C) 2006 MontaVista Software, Inc.
0d844065 11 * Vitaly Bordug <vbordug@ru.mvista.com>
1da177e4
LT
12 *
13 * This program is free software; you can redistribute it and/or modify
14 * it under the terms of the GNU General Public License as published by
15 * the Free Software Foundation; either version 2 of the License, or
16 * (at your option) any later version.
17 *
18 * This program is distributed in the hope that it will be useful,
19 * but WITHOUT ANY WARRANTY; without even the implied warranty of
20 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
21 * GNU General Public License for more details.
22 *
23 * You should have received a copy of the GNU General Public License
24 * along with this program; if not, write to the Free Software
25 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
26 *
27 */
28
1da177e4
LT
29#include <linux/module.h>
30#include <linux/tty.h>
5a0e3ad6 31#include <linux/gfp.h>
1da177e4 32#include <linux/ioport.h>
1da177e4
LT
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>
39
40#include <asm/io.h>
41#include <asm/irq.h>
f25222b9 42#include <asm/fs_pd.h>
1da177e4
LT
43
44#include <linux/serial_core.h>
45#include <linux/kernel.h>
46
d464df26 47#include <linux/of.h>
5af50730 48#include <linux/of_address.h>
d464df26 49
1da177e4
LT
50#include "cpm_uart.h"
51
52/**************************************************************/
53
7ae87036
SW
54void cpm_line_cr_cmd(struct uart_cpm_port *port, int cmd)
55{
362f9b6f 56 cpm_command(port->command, cmd);
7ae87036 57}
d464df26
LP
58
59void __iomem *cpm_uart_map_pram(struct uart_cpm_port *port,
60 struct device_node *np)
61{
62 return of_iomap(np, 1);
63}
64
65void cpm_uart_unmap_pram(struct uart_cpm_port *port, void __iomem *pram)
66{
67 iounmap(pram);
68}
69
1da177e4 70/*
311c4627 71 * Allocate DP-Ram and memory buffers. We need to allocate a transmit and
1da177e4
LT
72 * receive buffer descriptors from dual port ram, and a character
73 * buffer area from host mem. If we are allocating for the console we need
74 * to do it from bootmem
75 */
76int cpm_uart_allocbuf(struct uart_cpm_port *pinfo, unsigned int is_con)
77{
78 int dpmemsz, memsz;
79 u8 *dp_mem;
4c35630c 80 unsigned long dp_offset;
1da177e4
LT
81 u8 *mem_addr;
82 dma_addr_t dma_addr = 0;
83
84 pr_debug("CPM uart[%d]:allocbuf\n", pinfo->port.line);
85
86 dpmemsz = sizeof(cbd_t) * (pinfo->rx_nrfifos + pinfo->tx_nrfifos);
87 dp_offset = cpm_dpalloc(dpmemsz, 8);
4c35630c 88 if (IS_ERR_VALUE(dp_offset)) {
1da177e4
LT
89 printk(KERN_ERR
90 "cpm_uart_cpm1.c: could not allocate buffer descriptors\n");
91 return -ENOMEM;
92 }
93 dp_mem = cpm_dpram_addr(dp_offset);
94
95 memsz = L1_CACHE_ALIGN(pinfo->rx_nrfifos * pinfo->rx_fifosize) +
96 L1_CACHE_ALIGN(pinfo->tx_nrfifos * pinfo->tx_fifosize);
97 if (is_con) {
311c4627
KG
98 /* was hostalloc but changed cause it blows away the */
99 /* large tlb mapping when pinning the kernel area */
4e4b7952 100 mem_addr = (u8 *) cpm_dpram_addr(cpm_dpalloc(memsz, 8));
f25222b9 101 dma_addr = (u32)cpm_dpram_phys(mem_addr);
1da177e4 102 } else
8b05cefc 103 mem_addr = dma_alloc_coherent(pinfo->port.dev, memsz, &dma_addr,
1da177e4
LT
104 GFP_KERNEL);
105
106 if (mem_addr == NULL) {
107 cpm_dpfree(dp_offset);
108 printk(KERN_ERR
109 "cpm_uart_cpm1.c: could not allocate coherent memory\n");
110 return -ENOMEM;
111 }
112
113 pinfo->dp_addr = dp_offset;
09b03b6c
VB
114 pinfo->mem_addr = mem_addr; /* virtual address*/
115 pinfo->dma_addr = dma_addr; /* physical address*/
116 pinfo->mem_size = memsz;
1da177e4
LT
117
118 pinfo->rx_buf = mem_addr;
119 pinfo->tx_buf = pinfo->rx_buf + L1_CACHE_ALIGN(pinfo->rx_nrfifos
120 * pinfo->rx_fifosize);
121
c1dcfd9d 122 pinfo->rx_bd_base = (cbd_t __iomem __force *)dp_mem;
1da177e4
LT
123 pinfo->tx_bd_base = pinfo->rx_bd_base + pinfo->rx_nrfifos;
124
125 return 0;
126}
127
128void cpm_uart_freebuf(struct uart_cpm_port *pinfo)
129{
8b05cefc
BB
130 dma_free_coherent(pinfo->port.dev, L1_CACHE_ALIGN(pinfo->rx_nrfifos *
131 pinfo->rx_fifosize) +
1da177e4
LT
132 L1_CACHE_ALIGN(pinfo->tx_nrfifos *
133 pinfo->tx_fifosize), pinfo->mem_addr,
134 pinfo->dma_addr);
135
136 cpm_dpfree(pinfo->dp_addr);
137}