xref: /openbmc/linux/drivers/tty/serial/cpm_uart.h (revision 86e281fc)
1 /* SPDX-License-Identifier: GPL-2.0 */
2 /*
3  *  Driver for CPM (SCC/SMC) serial ports
4  *
5  *  Copyright (C) 2004 Freescale Semiconductor, Inc.
6  *
7  *  2006 (c) MontaVista Software, Inc.
8  *	Vitaly Bordug <vbordug@ru.mvista.com>
9  */
10 #ifndef CPM_UART_H
11 #define CPM_UART_H
12 
13 #include <linux/platform_device.h>
14 
15 struct gpio_desc;
16 
17 #if defined(CONFIG_CPM2)
18 #include "asm/cpm2.h"
19 #elif defined(CONFIG_CPM1)
20 #include "asm/cpm1.h"
21 #endif
22 
23 #define DPRAM_BASE	((u8 __iomem *)cpm_muram_addr(0))
24 
25 #define SERIAL_CPM_MAJOR	204
26 #define SERIAL_CPM_MINOR	46
27 
28 #define IS_SMC(pinfo)		(pinfo->flags & FLAG_SMC)
29 #define FLAG_SMC	0x00000002
30 #define FLAG_CONSOLE	0x00000001
31 
32 #define UART_NR		6
33 
34 #define RX_NUM_FIFO	4
35 #define RX_BUF_SIZE	32
36 #define TX_NUM_FIFO	4
37 #define TX_BUF_SIZE	32
38 
39 #define GPIO_CTS	0
40 #define GPIO_RTS	1
41 #define GPIO_DCD	2
42 #define GPIO_DSR	3
43 #define GPIO_DTR	4
44 #define GPIO_RI		5
45 
46 #define NUM_GPIOS	(GPIO_RI+1)
47 
48 struct uart_cpm_port {
49 	struct uart_port	port;
50 	u16			rx_nrfifos;
51 	u16			rx_fifosize;
52 	u16			tx_nrfifos;
53 	u16			tx_fifosize;
54 	smc_t __iomem		*smcp;
55 	smc_uart_t __iomem	*smcup;
56 	scc_t __iomem		*sccp;
57 	scc_uart_t __iomem	*sccup;
58 	cbd_t __iomem		*rx_bd_base;
59 	cbd_t __iomem		*rx_cur;
60 	cbd_t __iomem		*tx_bd_base;
61 	cbd_t __iomem		*tx_cur;
62 	unsigned char		*tx_buf;
63 	unsigned char		*rx_buf;
64 	u32			flags;
65 	struct clk		*clk;
66 	u8			brg;
67 	uint			 dp_addr;
68 	void			*mem_addr;
69 	dma_addr_t		 dma_addr;
70 	u32			mem_size;
71 	/* wait on close if needed */
72 	int			wait_closing;
73 	/* value to combine with opcode to form cpm command */
74 	u32			command;
75 	struct gpio_desc	*gpios[NUM_GPIOS];
76 };
77 
78 /*
79    virtual to phys transtalion
80 */
81 static inline unsigned long cpu2cpm_addr(void *addr,
82                                          struct uart_cpm_port *pinfo)
83 {
84 	int offset;
85 	u32 val = (u32)addr;
86 	u32 mem = (u32)pinfo->mem_addr;
87 	/* sane check */
88 	if (likely(val >= mem && val < mem + pinfo->mem_size)) {
89 		offset = val - mem;
90 		return pinfo->dma_addr + offset;
91 	}
92 	/* something nasty happened */
93 	BUG();
94 	return 0;
95 }
96 
97 static inline void *cpm2cpu_addr(unsigned long addr,
98                                  struct uart_cpm_port *pinfo)
99 {
100 	int offset;
101 	u32 val = addr;
102 	u32 dma = (u32)pinfo->dma_addr;
103 	/* sane check */
104 	if (likely(val >= dma && val < dma + pinfo->mem_size)) {
105 		offset = val - dma;
106 		return pinfo->mem_addr + offset;
107 	}
108 	/* something nasty happened */
109 	BUG();
110 	return NULL;
111 }
112 
113 
114 #endif /* CPM_UART_H */
115