1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30#include <linux/module.h>
31#include <linux/tty.h>
32#include <linux/ioport.h>
33#include <linux/init.h>
34#include <linux/serial.h>
35#include <linux/console.h>
36#include <linux/sysrq.h>
37#include <linux/device.h>
38#include <linux/bootmem.h>
39#include <linux/dma-mapping.h>
40
41#include <asm/io.h>
42#include <asm/irq.h>
43#include <asm/fs_pd.h>
44
45#include <linux/serial_core.h>
46#include <linux/kernel.h>
47
48#include <linux/of.h>
49
50#include "cpm_uart.h"
51
52
53
54void cpm_line_cr_cmd(struct uart_cpm_port *port, int cmd)
55{
56 cpm_command(port->command, cmd);
57}
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
70
71
72
73
74
75
76int cpm_uart_allocbuf(struct uart_cpm_port *pinfo, unsigned int is_con)
77{
78 int dpmemsz, memsz;
79 u8 *dp_mem;
80 unsigned long dp_offset;
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);
88 if (IS_ERR_VALUE(dp_offset)) {
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) {
98
99
100 mem_addr = (u8 *) cpm_dpram_addr(cpm_dpalloc(memsz, 8));
101 dma_addr = (u32)cpm_dpram_phys(mem_addr);
102 } else
103 mem_addr = dma_alloc_coherent(pinfo->port.dev, memsz, &dma_addr,
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;
114 pinfo->mem_addr = mem_addr;
115 pinfo->dma_addr = dma_addr;
116 pinfo->mem_size = memsz;
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
122 pinfo->rx_bd_base = (cbd_t __iomem __force *)dp_mem;
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{
130 dma_free_coherent(pinfo->port.dev, L1_CACHE_ALIGN(pinfo->rx_nrfifos *
131 pinfo->rx_fifosize) +
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}
138