Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1 | /* |
| 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 Bordug | 6e197696 | 2006-04-29 23:06:00 +0400 | [diff] [blame] | 8 | * 2006 (c) MontaVista Software, Inc. |
Kumar Gala | 0d84406 | 2008-06-12 07:53:48 -0500 | [diff] [blame] | 9 | * Vitaly Bordug <vbordug@ru.mvista.com> |
Vitaly Bordug | 6e197696 | 2006-04-29 23:06:00 +0400 | [diff] [blame] | 10 | * |
| 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 Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 15 | */ |
| 16 | #ifndef CPM_UART_H |
| 17 | #define CPM_UART_H |
| 18 | |
Vitaly Bordug | e27987c | 2006-04-25 20:26:41 +0400 | [diff] [blame] | 19 | #include <linux/platform_device.h> |
| 20 | #include <linux/fs_uart_pd.h> |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 21 | |
| 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 Gala | 0d84406 | 2008-06-12 07:53:48 -0500 | [diff] [blame] | 31 | #define IS_SMC(pinfo) (pinfo->flags & FLAG_SMC) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 32 | #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 Bordug | e27987c | 2006-04-25 20:26:41 +0400 | [diff] [blame] | 37 | #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 Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 43 | |
Vitaly Bordug | e27987c | 2006-04-25 20:26:41 +0400 | [diff] [blame] | 44 | #define UART_NR fs_uart_nr |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 45 | |
| 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 Gala | 311c462 | 2005-08-09 10:08:00 -0700 | [diff] [blame] | 51 | #define SCC_WAIT_CLOSING 100 |
| 52 | |
Laurent Pinchart | 7485d26 | 2008-07-24 18:36:37 +0200 | [diff] [blame] | 53 | #define GPIO_CTS 0 |
| 54 | #define GPIO_RTS 1 |
| 55 | #define GPIO_DCD 2 |
| 56 | #define GPIO_DSR 3 |
| 57 | #define GPIO_DTR 4 |
| 58 | #define GPIO_RI 5 |
| 59 | |
| 60 | #define NUM_GPIOS (GPIO_RI+1) |
| 61 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 62 | struct uart_cpm_port { |
| 63 | struct uart_port port; |
Kumar Gala | 311c462 | 2005-08-09 10:08:00 -0700 | [diff] [blame] | 64 | u16 rx_nrfifos; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 65 | u16 rx_fifosize; |
Kumar Gala | 311c462 | 2005-08-09 10:08:00 -0700 | [diff] [blame] | 66 | u16 tx_nrfifos; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 67 | u16 tx_fifosize; |
Scott Wood | c1dcfd9 | 2007-07-24 15:53:07 -0500 | [diff] [blame] | 68 | smc_t __iomem *smcp; |
| 69 | smc_uart_t __iomem *smcup; |
| 70 | scc_t __iomem *sccp; |
| 71 | scc_uart_t __iomem *sccup; |
| 72 | cbd_t __iomem *rx_bd_base; |
| 73 | cbd_t __iomem *rx_cur; |
| 74 | cbd_t __iomem *tx_bd_base; |
| 75 | cbd_t __iomem *tx_cur; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 76 | unsigned char *tx_buf; |
| 77 | unsigned char *rx_buf; |
| 78 | u32 flags; |
| 79 | void (*set_lineif)(struct uart_cpm_port *); |
Laurent Pinchart | 8077655 | 2008-07-28 10:42:16 +0200 | [diff] [blame] | 80 | struct clk *clk; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 81 | u8 brg; |
| 82 | uint dp_addr; |
Kumar Gala | 0d84406 | 2008-06-12 07:53:48 -0500 | [diff] [blame] | 83 | void *mem_addr; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 84 | dma_addr_t dma_addr; |
Vitaly Bordug | 09b03b6 | 2006-04-25 20:26:46 +0400 | [diff] [blame] | 85 | u32 mem_size; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 86 | /* helpers */ |
| 87 | int baud; |
| 88 | int bits; |
| 89 | /* Keep track of 'odd' SMC2 wirings */ |
| 90 | int is_portb; |
Kumar Gala | 311c462 | 2005-08-09 10:08:00 -0700 | [diff] [blame] | 91 | /* wait on close if needed */ |
Kumar Gala | 0d84406 | 2008-06-12 07:53:48 -0500 | [diff] [blame] | 92 | int wait_closing; |
Scott Wood | 7ae8703 | 2007-07-17 17:59:06 -0500 | [diff] [blame] | 93 | /* value to combine with opcode to form cpm command */ |
| 94 | u32 command; |
Laurent Pinchart | 7485d26 | 2008-07-24 18:36:37 +0200 | [diff] [blame] | 95 | int gpios[NUM_GPIOS]; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 96 | }; |
| 97 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 98 | extern int cpm_uart_nr; |
| 99 | extern struct uart_cpm_port cpm_uart_ports[UART_NR]; |
| 100 | |
| 101 | /* these are located in their respective files */ |
Scott Wood | 7ae8703 | 2007-07-17 17:59:06 -0500 | [diff] [blame] | 102 | void cpm_line_cr_cmd(struct uart_cpm_port *port, int cmd); |
Laurent Pinchart | d464df2 | 2008-04-10 17:01:27 +0200 | [diff] [blame] | 103 | void __iomem *cpm_uart_map_pram(struct uart_cpm_port *port, |
| 104 | struct device_node *np); |
| 105 | void cpm_uart_unmap_pram(struct uart_cpm_port *port, void __iomem *pram); |
Kumar Gala | 32a56eb | 2007-05-09 23:44:58 -0500 | [diff] [blame] | 106 | int cpm_uart_init_portdesc(void); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 107 | int cpm_uart_allocbuf(struct uart_cpm_port *pinfo, unsigned int is_con); |
| 108 | void cpm_uart_freebuf(struct uart_cpm_port *pinfo); |
| 109 | |
| 110 | void smc1_lineif(struct uart_cpm_port *pinfo); |
| 111 | void smc2_lineif(struct uart_cpm_port *pinfo); |
| 112 | void scc1_lineif(struct uart_cpm_port *pinfo); |
| 113 | void scc2_lineif(struct uart_cpm_port *pinfo); |
| 114 | void scc3_lineif(struct uart_cpm_port *pinfo); |
| 115 | void scc4_lineif(struct uart_cpm_port *pinfo); |
| 116 | |
Vitaly Bordug | 09b03b6 | 2006-04-25 20:26:46 +0400 | [diff] [blame] | 117 | /* |
| 118 | virtual to phys transtalion |
| 119 | */ |
Scott Wood | c1dcfd9 | 2007-07-24 15:53:07 -0500 | [diff] [blame] | 120 | static inline unsigned long cpu2cpm_addr(void *addr, |
| 121 | struct uart_cpm_port *pinfo) |
Vitaly Bordug | 09b03b6 | 2006-04-25 20:26:46 +0400 | [diff] [blame] | 122 | { |
| 123 | int offset; |
| 124 | u32 val = (u32)addr; |
Scott Wood | c1dcfd9 | 2007-07-24 15:53:07 -0500 | [diff] [blame] | 125 | u32 mem = (u32)pinfo->mem_addr; |
Vitaly Bordug | 09b03b6 | 2006-04-25 20:26:46 +0400 | [diff] [blame] | 126 | /* sane check */ |
Scott Wood | c1dcfd9 | 2007-07-24 15:53:07 -0500 | [diff] [blame] | 127 | if (likely(val >= mem && val < mem + pinfo->mem_size)) { |
| 128 | offset = val - mem; |
| 129 | return pinfo->dma_addr + offset; |
Vitaly Bordug | 09b03b6 | 2006-04-25 20:26:46 +0400 | [diff] [blame] | 130 | } |
Vitaly Bordug | 6e197696 | 2006-04-29 23:06:00 +0400 | [diff] [blame] | 131 | /* something nasty happened */ |
| 132 | BUG(); |
Vitaly Bordug | 09b03b6 | 2006-04-25 20:26:46 +0400 | [diff] [blame] | 133 | return 0; |
| 134 | } |
| 135 | |
Scott Wood | c1dcfd9 | 2007-07-24 15:53:07 -0500 | [diff] [blame] | 136 | static inline void *cpm2cpu_addr(unsigned long addr, |
| 137 | struct uart_cpm_port *pinfo) |
Vitaly Bordug | 09b03b6 | 2006-04-25 20:26:46 +0400 | [diff] [blame] | 138 | { |
| 139 | int offset; |
| 140 | u32 val = addr; |
Scott Wood | c1dcfd9 | 2007-07-24 15:53:07 -0500 | [diff] [blame] | 141 | u32 dma = (u32)pinfo->dma_addr; |
Vitaly Bordug | 09b03b6 | 2006-04-25 20:26:46 +0400 | [diff] [blame] | 142 | /* sane check */ |
Scott Wood | c1dcfd9 | 2007-07-24 15:53:07 -0500 | [diff] [blame] | 143 | if (likely(val >= dma && val < dma + pinfo->mem_size)) { |
| 144 | offset = val - dma; |
| 145 | return pinfo->mem_addr + offset; |
Vitaly Bordug | 09b03b6 | 2006-04-25 20:26:46 +0400 | [diff] [blame] | 146 | } |
Vitaly Bordug | 6e197696 | 2006-04-29 23:06:00 +0400 | [diff] [blame] | 147 | /* something nasty happened */ |
| 148 | BUG(); |
Scott Wood | c1dcfd9 | 2007-07-24 15:53:07 -0500 | [diff] [blame] | 149 | return NULL; |
Vitaly Bordug | 09b03b6 | 2006-04-25 20:26:46 +0400 | [diff] [blame] | 150 | } |
| 151 | |
| 152 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 153 | #endif /* CPM_UART_H */ |