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/gfp.h>
33#include <linux/ioport.h>
34#include <linux/init.h>
35#include <linux/serial.h>
36#include <linux/console.h>
37#include <linux/sysrq.h>
38#include <linux/device.h>
39#include <linux/bootmem.h>
40#include <linux/dma-mapping.h>
41
42#include <asm/io.h>
43#include <asm/irq.h>
44#include <asm/fs_pd.h>
45
46#include <linux/serial_core.h>
47#include <linux/kernel.h>
48
49#include <linux/of.h>
50
51#include "cpm_uart.h"
52
53
54
55void cpm_line_cr_cmd(struct uart_cpm_port *port, int cmd)
56{
57 cpm_command(port->command, cmd);
58}
59
60void __iomem *cpm_uart_map_pram(struct uart_cpm_port *port,
61 struct device_node *np)
62{
63 return of_iomap(np, 1);
64}
65
66void cpm_uart_unmap_pram(struct uart_cpm_port *port, void __iomem *pram)
67{
68 iounmap(pram);
69}
70
71
72
73
74
75
76
77int cpm_uart_allocbuf(struct uart_cpm_port *pinfo, unsigned int is_con)
78{
79 int dpmemsz, memsz;
80 u8 *dp_mem;
81 unsigned long dp_offset;
82 u8 *mem_addr;
83 dma_addr_t dma_addr = 0;
84
85 pr_debug("CPM uart[%d]:allocbuf\n", pinfo->port.line);
86
87 dpmemsz = sizeof(cbd_t) * (pinfo->rx_nrfifos + pinfo->tx_nrfifos);
88 dp_offset = cpm_dpalloc(dpmemsz, 8);
89 if (IS_ERR_VALUE(dp_offset)) {
90 printk(KERN_ERR
91 "cpm_uart_cpm1.c: could not allocate buffer descriptors\n");
92 return -ENOMEM;
93 }
94 dp_mem = cpm_dpram_addr(dp_offset);
95
96 memsz = L1_CACHE_ALIGN(pinfo->rx_nrfifos * pinfo->rx_fifosize) +
97 L1_CACHE_ALIGN(pinfo->tx_nrfifos * pinfo->tx_fifosize);
98 if (is_con) {
99
100
101 mem_addr = (u8 *) cpm_dpram_addr(cpm_dpalloc(memsz, 8));
102 dma_addr = (u32)cpm_dpram_phys(mem_addr);
103 } else
104 mem_addr = dma_alloc_coherent(pinfo->port.dev, memsz, &dma_addr,
105 GFP_KERNEL);
106
107 if (mem_addr == NULL) {
108 cpm_dpfree(dp_offset);
109 printk(KERN_ERR
110 "cpm_uart_cpm1.c: could not allocate coherent memory\n");
111 return -ENOMEM;
112 }
113
114 pinfo->dp_addr = dp_offset;
115 pinfo->mem_addr = mem_addr;
116 pinfo->dma_addr = dma_addr;
117 pinfo->mem_size = memsz;
118
119 pinfo->rx_buf = mem_addr;
120 pinfo->tx_buf = pinfo->rx_buf + L1_CACHE_ALIGN(pinfo->rx_nrfifos
121 * pinfo->rx_fifosize);
122
123 pinfo->rx_bd_base = (cbd_t __iomem __force *)dp_mem;
124 pinfo->tx_bd_base = pinfo->rx_bd_base + pinfo->rx_nrfifos;
125
126 return 0;
127}
128
129void cpm_uart_freebuf(struct uart_cpm_port *pinfo)
130{
131 dma_free_coherent(pinfo->port.dev, L1_CACHE_ALIGN(pinfo->rx_nrfifos *
132 pinfo->rx_fifosize) +
133 L1_CACHE_ALIGN(pinfo->tx_nrfifos *
134 pinfo->tx_fifosize), pinfo->mem_addr,
135 pinfo->dma_addr);
136
137 cpm_dpfree(pinfo->dp_addr);
138}
139