blob: cf34d26ff6cdd642849fe61ae0f60af71ed04f94 [file] [log] [blame]
Linus Torvalds1da177e2005-04-16 15:20:36 -07001/*
Linus Torvalds1da177e2005-04-16 15:20:36 -07002 * Driver for CPM (SCC/SMC) serial ports
3 *
4 * Copyright (C) 2004 Freescale Semiconductor, Inc.
5 *
Vitaly Bordug6e1976962006-04-29 23:06:00 +04006 * 2006 (c) MontaVista Software, Inc.
Kumar Gala0d844062008-06-12 07:53:48 -05007 * Vitaly Bordug <vbordug@ru.mvista.com>
Vitaly Bordug6e1976962006-04-29 23:06:00 +04008 *
9 * This file is licensed under the terms of the GNU General Public License
10 * version 2. This program is licensed "as is" without any warranty of any
11 * kind, whether express or implied.
12 *
Linus Torvalds1da177e2005-04-16 15:20:36 -070013 */
14#ifndef CPM_UART_H
15#define CPM_UART_H
16
Vitaly Borduge27987c2006-04-25 20:26:41 +040017#include <linux/platform_device.h>
18#include <linux/fs_uart_pd.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070019
20#if defined(CONFIG_CPM2)
21#include "cpm_uart_cpm2.h"
22#elif defined(CONFIG_8xx)
23#include "cpm_uart_cpm1.h"
24#endif
25
26#define SERIAL_CPM_MAJOR 204
27#define SERIAL_CPM_MINOR 46
28
Kumar Gala0d844062008-06-12 07:53:48 -050029#define IS_SMC(pinfo) (pinfo->flags & FLAG_SMC)
Linus Torvalds1da177e2005-04-16 15:20:36 -070030#define IS_DISCARDING(pinfo) (pinfo->flags & FLAG_DISCARDING)
31#define FLAG_DISCARDING 0x00000004 /* when set, don't discard */
32#define FLAG_SMC 0x00000002
33#define FLAG_CONSOLE 0x00000001
34
Vitaly Borduge27987c2006-04-25 20:26:41 +040035#define UART_SMC1 fsid_smc1_uart
36#define UART_SMC2 fsid_smc2_uart
37#define UART_SCC1 fsid_scc1_uart
38#define UART_SCC2 fsid_scc2_uart
39#define UART_SCC3 fsid_scc3_uart
40#define UART_SCC4 fsid_scc4_uart
Linus Torvalds1da177e2005-04-16 15:20:36 -070041
Vitaly Borduge27987c2006-04-25 20:26:41 +040042#define UART_NR fs_uart_nr
Linus Torvalds1da177e2005-04-16 15:20:36 -070043
44#define RX_NUM_FIFO 4
45#define RX_BUF_SIZE 32
46#define TX_NUM_FIFO 4
47#define TX_BUF_SIZE 32
48
Kumar Gala311c4622005-08-09 10:08:00 -070049#define SCC_WAIT_CLOSING 100
50
Laurent Pinchart7485d262008-07-24 18:36:37 +020051#define GPIO_CTS 0
52#define GPIO_RTS 1
53#define GPIO_DCD 2
54#define GPIO_DSR 3
55#define GPIO_DTR 4
56#define GPIO_RI 5
57
58#define NUM_GPIOS (GPIO_RI+1)
59
Linus Torvalds1da177e2005-04-16 15:20:36 -070060struct uart_cpm_port {
61 struct uart_port port;
Kumar Gala311c4622005-08-09 10:08:00 -070062 u16 rx_nrfifos;
Linus Torvalds1da177e2005-04-16 15:20:36 -070063 u16 rx_fifosize;
Kumar Gala311c4622005-08-09 10:08:00 -070064 u16 tx_nrfifos;
Linus Torvalds1da177e2005-04-16 15:20:36 -070065 u16 tx_fifosize;
Scott Woodc1dcfd92007-07-24 15:53:07 -050066 smc_t __iomem *smcp;
67 smc_uart_t __iomem *smcup;
68 scc_t __iomem *sccp;
69 scc_uart_t __iomem *sccup;
70 cbd_t __iomem *rx_bd_base;
71 cbd_t __iomem *rx_cur;
72 cbd_t __iomem *tx_bd_base;
73 cbd_t __iomem *tx_cur;
Linus Torvalds1da177e2005-04-16 15:20:36 -070074 unsigned char *tx_buf;
75 unsigned char *rx_buf;
76 u32 flags;
Laurent Pinchart80776552008-07-28 10:42:16 +020077 struct clk *clk;
Linus Torvalds1da177e2005-04-16 15:20:36 -070078 u8 brg;
79 uint dp_addr;
Kumar Gala0d844062008-06-12 07:53:48 -050080 void *mem_addr;
Linus Torvalds1da177e2005-04-16 15:20:36 -070081 dma_addr_t dma_addr;
Vitaly Bordug09b03b62006-04-25 20:26:46 +040082 u32 mem_size;
Kumar Gala311c4622005-08-09 10:08:00 -070083 /* wait on close if needed */
Kumar Gala0d844062008-06-12 07:53:48 -050084 int wait_closing;
Scott Wood7ae87032007-07-17 17:59:06 -050085 /* value to combine with opcode to form cpm command */
86 u32 command;
Laurent Pinchart7485d262008-07-24 18:36:37 +020087 int gpios[NUM_GPIOS];
Linus Torvalds1da177e2005-04-16 15:20:36 -070088};
89
Linus Torvalds1da177e2005-04-16 15:20:36 -070090extern int cpm_uart_nr;
91extern struct uart_cpm_port cpm_uart_ports[UART_NR];
92
93/* these are located in their respective files */
Scott Wood7ae87032007-07-17 17:59:06 -050094void cpm_line_cr_cmd(struct uart_cpm_port *port, int cmd);
Laurent Pinchartd464df22008-04-10 17:01:27 +020095void __iomem *cpm_uart_map_pram(struct uart_cpm_port *port,
96 struct device_node *np);
97void cpm_uart_unmap_pram(struct uart_cpm_port *port, void __iomem *pram);
Kumar Gala32a56eb2007-05-09 23:44:58 -050098int cpm_uart_init_portdesc(void);
Linus Torvalds1da177e2005-04-16 15:20:36 -070099int cpm_uart_allocbuf(struct uart_cpm_port *pinfo, unsigned int is_con);
100void cpm_uart_freebuf(struct uart_cpm_port *pinfo);
101
102void smc1_lineif(struct uart_cpm_port *pinfo);
103void smc2_lineif(struct uart_cpm_port *pinfo);
104void scc1_lineif(struct uart_cpm_port *pinfo);
105void scc2_lineif(struct uart_cpm_port *pinfo);
106void scc3_lineif(struct uart_cpm_port *pinfo);
107void scc4_lineif(struct uart_cpm_port *pinfo);
108
Vitaly Bordug09b03b62006-04-25 20:26:46 +0400109/*
110 virtual to phys transtalion
111*/
Scott Woodc1dcfd92007-07-24 15:53:07 -0500112static inline unsigned long cpu2cpm_addr(void *addr,
113 struct uart_cpm_port *pinfo)
Vitaly Bordug09b03b62006-04-25 20:26:46 +0400114{
115 int offset;
116 u32 val = (u32)addr;
Scott Woodc1dcfd92007-07-24 15:53:07 -0500117 u32 mem = (u32)pinfo->mem_addr;
Vitaly Bordug09b03b62006-04-25 20:26:46 +0400118 /* sane check */
Scott Woodc1dcfd92007-07-24 15:53:07 -0500119 if (likely(val >= mem && val < mem + pinfo->mem_size)) {
120 offset = val - mem;
121 return pinfo->dma_addr + offset;
Vitaly Bordug09b03b62006-04-25 20:26:46 +0400122 }
Vitaly Bordug6e1976962006-04-29 23:06:00 +0400123 /* something nasty happened */
124 BUG();
Vitaly Bordug09b03b62006-04-25 20:26:46 +0400125 return 0;
126}
127
Scott Woodc1dcfd92007-07-24 15:53:07 -0500128static inline void *cpm2cpu_addr(unsigned long addr,
129 struct uart_cpm_port *pinfo)
Vitaly Bordug09b03b62006-04-25 20:26:46 +0400130{
131 int offset;
132 u32 val = addr;
Scott Woodc1dcfd92007-07-24 15:53:07 -0500133 u32 dma = (u32)pinfo->dma_addr;
Vitaly Bordug09b03b62006-04-25 20:26:46 +0400134 /* sane check */
Scott Woodc1dcfd92007-07-24 15:53:07 -0500135 if (likely(val >= dma && val < dma + pinfo->mem_size)) {
136 offset = val - dma;
137 return pinfo->mem_addr + offset;
Vitaly Bordug09b03b62006-04-25 20:26:46 +0400138 }
Vitaly Bordug6e1976962006-04-29 23:06:00 +0400139 /* something nasty happened */
140 BUG();
Scott Woodc1dcfd92007-07-24 15:53:07 -0500141 return NULL;
Vitaly Bordug09b03b62006-04-25 20:26:46 +0400142}
143
144
Linus Torvalds1da177e2005-04-16 15:20:36 -0700145#endif /* CPM_UART_H */