tty: add SPDX identifiers to all remaining files in drivers/tty/
[linux-2.6-block.git] / drivers / tty / serial / cpm_uart / cpm_uart.h
CommitLineData
e3b3d0f5 1// SPDX-License-Identifier: GPL-2.0
1da177e4 2/*
1da177e4
LT
3 * Driver for CPM (SCC/SMC) serial ports
4 *
5 * Copyright (C) 2004 Freescale Semiconductor, Inc.
6 *
6e197696 7 * 2006 (c) MontaVista Software, Inc.
0d844065 8 * Vitaly Bordug <vbordug@ru.mvista.com>
6e197696
VB
9 *
10 * This file is licensed under the terms of the GNU General Public License
11 * version 2. This program is licensed "as is" without any warranty of any
12 * kind, whether express or implied.
13 *
1da177e4
LT
14 */
15#ifndef CPM_UART_H
16#define CPM_UART_H
17
e27987cd
VB
18#include <linux/platform_device.h>
19#include <linux/fs_uart_pd.h>
1da177e4
LT
20
21#if defined(CONFIG_CPM2)
22#include "cpm_uart_cpm2.h"
49708c9e 23#elif defined(CONFIG_CPM1)
1da177e4
LT
24#include "cpm_uart_cpm1.h"
25#endif
26
27#define SERIAL_CPM_MAJOR 204
28#define SERIAL_CPM_MINOR 46
29
0d844065 30#define IS_SMC(pinfo) (pinfo->flags & FLAG_SMC)
1da177e4
LT
31#define IS_DISCARDING(pinfo) (pinfo->flags & FLAG_DISCARDING)
32#define FLAG_DISCARDING 0x00000004 /* when set, don't discard */
33#define FLAG_SMC 0x00000002
34#define FLAG_CONSOLE 0x00000001
35
e27987cd
VB
36#define UART_SMC1 fsid_smc1_uart
37#define UART_SMC2 fsid_smc2_uart
38#define UART_SCC1 fsid_scc1_uart
39#define UART_SCC2 fsid_scc2_uart
40#define UART_SCC3 fsid_scc3_uart
41#define UART_SCC4 fsid_scc4_uart
1da177e4 42
e27987cd 43#define UART_NR fs_uart_nr
1da177e4
LT
44
45#define RX_NUM_FIFO 4
46#define RX_BUF_SIZE 32
47#define TX_NUM_FIFO 4
48#define TX_BUF_SIZE 32
49
311c4627
KG
50#define SCC_WAIT_CLOSING 100
51
7485d26b
LP
52#define GPIO_CTS 0
53#define GPIO_RTS 1
54#define GPIO_DCD 2
55#define GPIO_DSR 3
56#define GPIO_DTR 4
57#define GPIO_RI 5
58
59#define NUM_GPIOS (GPIO_RI+1)
60
1da177e4
LT
61struct uart_cpm_port {
62 struct uart_port port;
311c4627 63 u16 rx_nrfifos;
1da177e4 64 u16 rx_fifosize;
311c4627 65 u16 tx_nrfifos;
1da177e4 66 u16 tx_fifosize;
c1dcfd9d
SW
67 smc_t __iomem *smcp;
68 smc_uart_t __iomem *smcup;
69 scc_t __iomem *sccp;
70 scc_uart_t __iomem *sccup;
71 cbd_t __iomem *rx_bd_base;
72 cbd_t __iomem *rx_cur;
73 cbd_t __iomem *tx_bd_base;
74 cbd_t __iomem *tx_cur;
1da177e4
LT
75 unsigned char *tx_buf;
76 unsigned char *rx_buf;
77 u32 flags;
80776554 78 struct clk *clk;
1da177e4
LT
79 u8 brg;
80 uint dp_addr;
0d844065 81 void *mem_addr;
1da177e4 82 dma_addr_t dma_addr;
09b03b6c 83 u32 mem_size;
311c4627 84 /* wait on close if needed */
0d844065 85 int wait_closing;
7ae87036
SW
86 /* value to combine with opcode to form cpm command */
87 u32 command;
7485d26b 88 int gpios[NUM_GPIOS];
1da177e4
LT
89};
90
1da177e4
LT
91extern int cpm_uart_nr;
92extern struct uart_cpm_port cpm_uart_ports[UART_NR];
93
94/* these are located in their respective files */
7ae87036 95void cpm_line_cr_cmd(struct uart_cpm_port *port, int cmd);
d464df26
LP
96void __iomem *cpm_uart_map_pram(struct uart_cpm_port *port,
97 struct device_node *np);
98void cpm_uart_unmap_pram(struct uart_cpm_port *port, void __iomem *pram);
32a56ebb 99int cpm_uart_init_portdesc(void);
1da177e4
LT
100int cpm_uart_allocbuf(struct uart_cpm_port *pinfo, unsigned int is_con);
101void cpm_uart_freebuf(struct uart_cpm_port *pinfo);
102
103void smc1_lineif(struct uart_cpm_port *pinfo);
104void smc2_lineif(struct uart_cpm_port *pinfo);
105void scc1_lineif(struct uart_cpm_port *pinfo);
106void scc2_lineif(struct uart_cpm_port *pinfo);
107void scc3_lineif(struct uart_cpm_port *pinfo);
108void scc4_lineif(struct uart_cpm_port *pinfo);
109
09b03b6c
VB
110/*
111 virtual to phys transtalion
112*/
c1dcfd9d
SW
113static inline unsigned long cpu2cpm_addr(void *addr,
114 struct uart_cpm_port *pinfo)
09b03b6c
VB
115{
116 int offset;
117 u32 val = (u32)addr;
c1dcfd9d 118 u32 mem = (u32)pinfo->mem_addr;
09b03b6c 119 /* sane check */
c1dcfd9d
SW
120 if (likely(val >= mem && val < mem + pinfo->mem_size)) {
121 offset = val - mem;
122 return pinfo->dma_addr + offset;
09b03b6c 123 }
6e197696
VB
124 /* something nasty happened */
125 BUG();
09b03b6c
VB
126 return 0;
127}
128
c1dcfd9d
SW
129static inline void *cpm2cpu_addr(unsigned long addr,
130 struct uart_cpm_port *pinfo)
09b03b6c
VB
131{
132 int offset;
133 u32 val = addr;
c1dcfd9d 134 u32 dma = (u32)pinfo->dma_addr;
09b03b6c 135 /* sane check */
c1dcfd9d
SW
136 if (likely(val >= dma && val < dma + pinfo->mem_size)) {
137 offset = val - dma;
138 return pinfo->mem_addr + offset;
09b03b6c 139 }
6e197696
VB
140 /* something nasty happened */
141 BUG();
c1dcfd9d 142 return NULL;
09b03b6c
VB
143}
144
145
1da177e4 146#endif /* CPM_UART_H */