blob: 5c76e0ae0582f63b2659cbc72384da822744d2b3 [file] [log] [blame]
Linus Torvalds1da177e2005-04-16 15:20:36 -07001/*
2 * linux/drivers/serial/cpm_uart.h
3 *
4 * Driver for CPM (SCC/SMC) serial ports
5 *
6 * Copyright (C) 2004 Freescale Semiconductor, Inc.
7 *
Vitaly Bordug6e1976962006-04-29 23:06:00 +04008 * 2006 (c) MontaVista Software, Inc.
Kumar Gala0d844062008-06-12 07:53:48 -05009 * Vitaly Bordug <vbordug@ru.mvista.com>
Vitaly Bordug6e1976962006-04-29 23:06:00 +040010 *
11 * This file is licensed under the terms of the GNU General Public License
12 * version 2. This program is licensed "as is" without any warranty of any
13 * kind, whether express or implied.
14 *
Linus Torvalds1da177e2005-04-16 15:20:36 -070015 */
16#ifndef CPM_UART_H
17#define CPM_UART_H
18
Vitaly Borduge27987c2006-04-25 20:26:41 +040019#include <linux/platform_device.h>
20#include <linux/fs_uart_pd.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070021
22#if defined(CONFIG_CPM2)
23#include "cpm_uart_cpm2.h"
24#elif defined(CONFIG_8xx)
25#include "cpm_uart_cpm1.h"
26#endif
27
28#define SERIAL_CPM_MAJOR 204
29#define SERIAL_CPM_MINOR 46
30
Kumar Gala0d844062008-06-12 07:53:48 -050031#define IS_SMC(pinfo) (pinfo->flags & FLAG_SMC)
Linus Torvalds1da177e2005-04-16 15:20:36 -070032#define IS_DISCARDING(pinfo) (pinfo->flags & FLAG_DISCARDING)
33#define FLAG_DISCARDING 0x00000004 /* when set, don't discard */
34#define FLAG_SMC 0x00000002
35#define FLAG_CONSOLE 0x00000001
36
Vitaly Borduge27987c2006-04-25 20:26:41 +040037#define UART_SMC1 fsid_smc1_uart
38#define UART_SMC2 fsid_smc2_uart
39#define UART_SCC1 fsid_scc1_uart
40#define UART_SCC2 fsid_scc2_uart
41#define UART_SCC3 fsid_scc3_uart
42#define UART_SCC4 fsid_scc4_uart
Linus Torvalds1da177e2005-04-16 15:20:36 -070043
Vitaly Borduge27987c2006-04-25 20:26:41 +040044#define UART_NR fs_uart_nr
Linus Torvalds1da177e2005-04-16 15:20:36 -070045
46#define RX_NUM_FIFO 4
47#define RX_BUF_SIZE 32
48#define TX_NUM_FIFO 4
49#define TX_BUF_SIZE 32
50
Kumar Gala311c4622005-08-09 10:08:00 -070051#define SCC_WAIT_CLOSING 100
52
Linus Torvalds1da177e2005-04-16 15:20:36 -070053struct uart_cpm_port {
54 struct uart_port port;
Kumar Gala311c4622005-08-09 10:08:00 -070055 u16 rx_nrfifos;
Linus Torvalds1da177e2005-04-16 15:20:36 -070056 u16 rx_fifosize;
Kumar Gala311c4622005-08-09 10:08:00 -070057 u16 tx_nrfifos;
Linus Torvalds1da177e2005-04-16 15:20:36 -070058 u16 tx_fifosize;
Scott Woodc1dcfd92007-07-24 15:53:07 -050059 smc_t __iomem *smcp;
60 smc_uart_t __iomem *smcup;
61 scc_t __iomem *sccp;
62 scc_uart_t __iomem *sccup;
63 cbd_t __iomem *rx_bd_base;
64 cbd_t __iomem *rx_cur;
65 cbd_t __iomem *tx_bd_base;
66 cbd_t __iomem *tx_cur;
Linus Torvalds1da177e2005-04-16 15:20:36 -070067 unsigned char *tx_buf;
68 unsigned char *rx_buf;
69 u32 flags;
70 void (*set_lineif)(struct uart_cpm_port *);
71 u8 brg;
72 uint dp_addr;
Kumar Gala0d844062008-06-12 07:53:48 -050073 void *mem_addr;
Linus Torvalds1da177e2005-04-16 15:20:36 -070074 dma_addr_t dma_addr;
Vitaly Bordug09b03b62006-04-25 20:26:46 +040075 u32 mem_size;
Linus Torvalds1da177e2005-04-16 15:20:36 -070076 /* helpers */
77 int baud;
78 int bits;
79 /* Keep track of 'odd' SMC2 wirings */
80 int is_portb;
Kumar Gala311c4622005-08-09 10:08:00 -070081 /* wait on close if needed */
Kumar Gala0d844062008-06-12 07:53:48 -050082 int wait_closing;
Scott Wood7ae87032007-07-17 17:59:06 -050083 /* value to combine with opcode to form cpm command */
84 u32 command;
Linus Torvalds1da177e2005-04-16 15:20:36 -070085};
86
Linus Torvalds1da177e2005-04-16 15:20:36 -070087extern int cpm_uart_nr;
88extern struct uart_cpm_port cpm_uart_ports[UART_NR];
89
90/* these are located in their respective files */
Scott Wood7ae87032007-07-17 17:59:06 -050091void cpm_line_cr_cmd(struct uart_cpm_port *port, int cmd);
Laurent Pinchartd464df22008-04-10 17:01:27 +020092void __iomem *cpm_uart_map_pram(struct uart_cpm_port *port,
93 struct device_node *np);
94void cpm_uart_unmap_pram(struct uart_cpm_port *port, void __iomem *pram);
Kumar Gala32a56eb2007-05-09 23:44:58 -050095int cpm_uart_init_portdesc(void);
Linus Torvalds1da177e2005-04-16 15:20:36 -070096int cpm_uart_allocbuf(struct uart_cpm_port *pinfo, unsigned int is_con);
97void cpm_uart_freebuf(struct uart_cpm_port *pinfo);
98
99void smc1_lineif(struct uart_cpm_port *pinfo);
100void smc2_lineif(struct uart_cpm_port *pinfo);
101void scc1_lineif(struct uart_cpm_port *pinfo);
102void scc2_lineif(struct uart_cpm_port *pinfo);
103void scc3_lineif(struct uart_cpm_port *pinfo);
104void scc4_lineif(struct uart_cpm_port *pinfo);
105
Vitaly Bordug09b03b62006-04-25 20:26:46 +0400106/*
107 virtual to phys transtalion
108*/
Scott Woodc1dcfd92007-07-24 15:53:07 -0500109static inline unsigned long cpu2cpm_addr(void *addr,
110 struct uart_cpm_port *pinfo)
Vitaly Bordug09b03b62006-04-25 20:26:46 +0400111{
112 int offset;
113 u32 val = (u32)addr;
Scott Woodc1dcfd92007-07-24 15:53:07 -0500114 u32 mem = (u32)pinfo->mem_addr;
Vitaly Bordug09b03b62006-04-25 20:26:46 +0400115 /* sane check */
Scott Woodc1dcfd92007-07-24 15:53:07 -0500116 if (likely(val >= mem && val < mem + pinfo->mem_size)) {
117 offset = val - mem;
118 return pinfo->dma_addr + offset;
Vitaly Bordug09b03b62006-04-25 20:26:46 +0400119 }
Vitaly Bordug6e1976962006-04-29 23:06:00 +0400120 /* something nasty happened */
121 BUG();
Vitaly Bordug09b03b62006-04-25 20:26:46 +0400122 return 0;
123}
124
Scott Woodc1dcfd92007-07-24 15:53:07 -0500125static inline void *cpm2cpu_addr(unsigned long addr,
126 struct uart_cpm_port *pinfo)
Vitaly Bordug09b03b62006-04-25 20:26:46 +0400127{
128 int offset;
129 u32 val = addr;
Scott Woodc1dcfd92007-07-24 15:53:07 -0500130 u32 dma = (u32)pinfo->dma_addr;
Vitaly Bordug09b03b62006-04-25 20:26:46 +0400131 /* sane check */
Scott Woodc1dcfd92007-07-24 15:53:07 -0500132 if (likely(val >= dma && val < dma + pinfo->mem_size)) {
133 offset = val - dma;
134 return pinfo->mem_addr + offset;
Vitaly Bordug09b03b62006-04-25 20:26:46 +0400135 }
Vitaly Bordug6e1976962006-04-29 23:06:00 +0400136 /* something nasty happened */
137 BUG();
Scott Woodc1dcfd92007-07-24 15:53:07 -0500138 return NULL;
Vitaly Bordug09b03b62006-04-25 20:26:46 +0400139}
140
141
Linus Torvalds1da177e2005-04-16 15:20:36 -0700142#endif /* CPM_UART_H */