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. |
| 9 | * Vitaly Bordug <vbordug@ru.mvista.com> |
| 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 | |
| 19 | #include <linux/config.h> |
Vitaly Bordug | e27987c | 2006-04-25 20:26:41 +0400 | [diff] [blame] | 20 | #include <linux/platform_device.h> |
| 21 | #include <linux/fs_uart_pd.h> |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 22 | |
| 23 | #if defined(CONFIG_CPM2) |
| 24 | #include "cpm_uart_cpm2.h" |
| 25 | #elif defined(CONFIG_8xx) |
| 26 | #include "cpm_uart_cpm1.h" |
| 27 | #endif |
| 28 | |
| 29 | #define SERIAL_CPM_MAJOR 204 |
| 30 | #define SERIAL_CPM_MINOR 46 |
| 31 | |
| 32 | #define IS_SMC(pinfo) (pinfo->flags & FLAG_SMC) |
| 33 | #define IS_DISCARDING(pinfo) (pinfo->flags & FLAG_DISCARDING) |
| 34 | #define FLAG_DISCARDING 0x00000004 /* when set, don't discard */ |
| 35 | #define FLAG_SMC 0x00000002 |
| 36 | #define FLAG_CONSOLE 0x00000001 |
| 37 | |
Vitaly Bordug | e27987c | 2006-04-25 20:26:41 +0400 | [diff] [blame] | 38 | #define UART_SMC1 fsid_smc1_uart |
| 39 | #define UART_SMC2 fsid_smc2_uart |
| 40 | #define UART_SCC1 fsid_scc1_uart |
| 41 | #define UART_SCC2 fsid_scc2_uart |
| 42 | #define UART_SCC3 fsid_scc3_uart |
| 43 | #define UART_SCC4 fsid_scc4_uart |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 44 | |
Vitaly Bordug | e27987c | 2006-04-25 20:26:41 +0400 | [diff] [blame] | 45 | #define UART_NR fs_uart_nr |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 46 | |
| 47 | #define RX_NUM_FIFO 4 |
| 48 | #define RX_BUF_SIZE 32 |
| 49 | #define TX_NUM_FIFO 4 |
| 50 | #define TX_BUF_SIZE 32 |
| 51 | |
Kumar Gala | 311c462 | 2005-08-09 10:08:00 -0700 | [diff] [blame] | 52 | #define SCC_WAIT_CLOSING 100 |
| 53 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 54 | struct uart_cpm_port { |
| 55 | struct uart_port port; |
Kumar Gala | 311c462 | 2005-08-09 10:08:00 -0700 | [diff] [blame] | 56 | u16 rx_nrfifos; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 57 | u16 rx_fifosize; |
Kumar Gala | 311c462 | 2005-08-09 10:08:00 -0700 | [diff] [blame] | 58 | u16 tx_nrfifos; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 59 | u16 tx_fifosize; |
Kumar Gala | 311c462 | 2005-08-09 10:08:00 -0700 | [diff] [blame] | 60 | smc_t *smcp; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 61 | smc_uart_t *smcup; |
| 62 | scc_t *sccp; |
| 63 | scc_uart_t *sccup; |
| 64 | volatile cbd_t *rx_bd_base; |
| 65 | volatile cbd_t *rx_cur; |
| 66 | volatile cbd_t *tx_bd_base; |
| 67 | volatile cbd_t *tx_cur; |
| 68 | unsigned char *tx_buf; |
| 69 | unsigned char *rx_buf; |
| 70 | u32 flags; |
| 71 | void (*set_lineif)(struct uart_cpm_port *); |
| 72 | u8 brg; |
| 73 | uint dp_addr; |
| 74 | void *mem_addr; |
| 75 | dma_addr_t dma_addr; |
Vitaly Bordug | 09b03b6 | 2006-04-25 20:26:46 +0400 | [diff] [blame] | 76 | u32 mem_size; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 77 | /* helpers */ |
| 78 | int baud; |
| 79 | int bits; |
| 80 | /* Keep track of 'odd' SMC2 wirings */ |
| 81 | int is_portb; |
Kumar Gala | 311c462 | 2005-08-09 10:08:00 -0700 | [diff] [blame] | 82 | /* wait on close if needed */ |
| 83 | int wait_closing; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 84 | }; |
| 85 | |
| 86 | extern int cpm_uart_port_map[UART_NR]; |
| 87 | extern int cpm_uart_nr; |
| 88 | extern struct uart_cpm_port cpm_uart_ports[UART_NR]; |
| 89 | |
| 90 | /* these are located in their respective files */ |
| 91 | void cpm_line_cr_cmd(int line, int cmd); |
| 92 | int cpm_uart_init_portdesc(void); |
| 93 | int cpm_uart_allocbuf(struct uart_cpm_port *pinfo, unsigned int is_con); |
| 94 | void cpm_uart_freebuf(struct uart_cpm_port *pinfo); |
| 95 | |
| 96 | void smc1_lineif(struct uart_cpm_port *pinfo); |
| 97 | void smc2_lineif(struct uart_cpm_port *pinfo); |
| 98 | void scc1_lineif(struct uart_cpm_port *pinfo); |
| 99 | void scc2_lineif(struct uart_cpm_port *pinfo); |
| 100 | void scc3_lineif(struct uart_cpm_port *pinfo); |
| 101 | void scc4_lineif(struct uart_cpm_port *pinfo); |
| 102 | |
Vitaly Bordug | 09b03b6 | 2006-04-25 20:26:46 +0400 | [diff] [blame] | 103 | /* |
| 104 | virtual to phys transtalion |
| 105 | */ |
| 106 | static inline unsigned long cpu2cpm_addr(void* addr, struct uart_cpm_port *pinfo) |
| 107 | { |
| 108 | int offset; |
| 109 | u32 val = (u32)addr; |
| 110 | /* sane check */ |
Vitaly Bordug | 6e197696 | 2006-04-29 23:06:00 +0400 | [diff] [blame] | 111 | if (likely((val >= (u32)pinfo->mem_addr)) && |
Vitaly Bordug | 09b03b6 | 2006-04-25 20:26:46 +0400 | [diff] [blame] | 112 | (val<((u32)pinfo->mem_addr + pinfo->mem_size))) { |
| 113 | offset = val - (u32)pinfo->mem_addr; |
| 114 | return pinfo->dma_addr+offset; |
| 115 | } |
Vitaly Bordug | 6e197696 | 2006-04-29 23:06:00 +0400 | [diff] [blame] | 116 | /* something nasty happened */ |
| 117 | BUG(); |
Vitaly Bordug | 09b03b6 | 2006-04-25 20:26:46 +0400 | [diff] [blame] | 118 | return 0; |
| 119 | } |
| 120 | |
| 121 | static inline void *cpm2cpu_addr(unsigned long addr, struct uart_cpm_port *pinfo) |
| 122 | { |
| 123 | int offset; |
| 124 | u32 val = addr; |
| 125 | /* sane check */ |
Vitaly Bordug | 6e197696 | 2006-04-29 23:06:00 +0400 | [diff] [blame] | 126 | if (likely((val >= pinfo->dma_addr) && |
| 127 | (val<(pinfo->dma_addr + pinfo->mem_size)))) { |
Vitaly Bordug | 09b03b6 | 2006-04-25 20:26:46 +0400 | [diff] [blame] | 128 | offset = val - (u32)pinfo->dma_addr; |
| 129 | return (void*)(pinfo->mem_addr+offset); |
| 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 | |
| 136 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 137 | #endif /* CPM_UART_H */ |