Andrew Victor | 1e6c9c2 | 2006-01-10 16:59:27 +0000 | [diff] [blame] | 1 | /* |
Andrew Victor | c2f5ccf | 2006-12-04 09:37:20 +0100 | [diff] [blame] | 2 | * linux/drivers/char/atmel_serial.c |
Andrew Victor | 1e6c9c2 | 2006-01-10 16:59:27 +0000 | [diff] [blame] | 3 | * |
Haavard Skinnemoen | 7192f92 | 2006-10-04 16:02:05 +0200 | [diff] [blame] | 4 | * Driver for Atmel AT91 / AT32 Serial ports |
Andrew Victor | 1e6c9c2 | 2006-01-10 16:59:27 +0000 | [diff] [blame] | 5 | * Copyright (C) 2003 Rick Bronson |
| 6 | * |
| 7 | * Based on drivers/char/serial_sa1100.c, by Deep Blue Solutions Ltd. |
| 8 | * Based on drivers/char/serial.c, by Linus Torvalds, Theodore Ts'o. |
| 9 | * |
Chip Coldwell | a667061 | 2008-02-08 04:21:06 -0800 | [diff] [blame] | 10 | * DMA support added by Chip Coldwell. |
| 11 | * |
Andrew Victor | 1e6c9c2 | 2006-01-10 16:59:27 +0000 | [diff] [blame] | 12 | * This program is free software; you can redistribute it and/or modify |
| 13 | * it under the terms of the GNU General Public License as published by |
| 14 | * the Free Software Foundation; either version 2 of the License, or |
| 15 | * (at your option) any later version. |
| 16 | * |
| 17 | * This program is distributed in the hope that it will be useful, |
| 18 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 19 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 20 | * GNU General Public License for more details. |
| 21 | * |
| 22 | * You should have received a copy of the GNU General Public License |
| 23 | * along with this program; if not, write to the Free Software |
| 24 | * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA |
| 25 | * |
| 26 | */ |
Andrew Victor | 1e6c9c2 | 2006-01-10 16:59:27 +0000 | [diff] [blame] | 27 | #include <linux/module.h> |
| 28 | #include <linux/tty.h> |
| 29 | #include <linux/ioport.h> |
| 30 | #include <linux/slab.h> |
| 31 | #include <linux/init.h> |
| 32 | #include <linux/serial.h> |
Andrew Victor | afefc41 | 2006-06-19 19:53:19 +0100 | [diff] [blame] | 33 | #include <linux/clk.h> |
Andrew Victor | 1e6c9c2 | 2006-01-10 16:59:27 +0000 | [diff] [blame] | 34 | #include <linux/console.h> |
| 35 | #include <linux/sysrq.h> |
| 36 | #include <linux/tty_flip.h> |
Andrew Victor | afefc41 | 2006-06-19 19:53:19 +0100 | [diff] [blame] | 37 | #include <linux/platform_device.h> |
Chip Coldwell | a667061 | 2008-02-08 04:21:06 -0800 | [diff] [blame] | 38 | #include <linux/dma-mapping.h> |
Andrew Victor | 93a3ddc | 2007-02-08 11:31:22 +0100 | [diff] [blame] | 39 | #include <linux/atmel_pdc.h> |
Guennadi Liakhovetski | fa3218d | 2008-01-29 15:43:13 +0100 | [diff] [blame] | 40 | #include <linux/atmel_serial.h> |
Claudio Scordino | e8faff7 | 2010-05-03 13:31:28 +0100 | [diff] [blame^] | 41 | #include <linux/uaccess.h> |
Andrew Victor | 1e6c9c2 | 2006-01-10 16:59:27 +0000 | [diff] [blame] | 42 | |
| 43 | #include <asm/io.h> |
| 44 | |
Andrew Victor | afefc41 | 2006-06-19 19:53:19 +0100 | [diff] [blame] | 45 | #include <asm/mach/serial_at91.h> |
Russell King | a09e64f | 2008-08-05 16:14:15 +0100 | [diff] [blame] | 46 | #include <mach/board.h> |
Andrew Victor | 93a3ddc | 2007-02-08 11:31:22 +0100 | [diff] [blame] | 47 | |
Haavard Skinnemoen | acca9b8 | 2006-10-04 16:02:09 +0200 | [diff] [blame] | 48 | #ifdef CONFIG_ARM |
Russell King | a09e64f | 2008-08-05 16:14:15 +0100 | [diff] [blame] | 49 | #include <mach/cpu.h> |
| 50 | #include <mach/gpio.h> |
Haavard Skinnemoen | acca9b8 | 2006-10-04 16:02:09 +0200 | [diff] [blame] | 51 | #endif |
Andrew Victor | 1e6c9c2 | 2006-01-10 16:59:27 +0000 | [diff] [blame] | 52 | |
Chip Coldwell | a667061 | 2008-02-08 04:21:06 -0800 | [diff] [blame] | 53 | #define PDC_BUFFER_SIZE 512 |
| 54 | /* Revisit: We should calculate this based on the actual port settings */ |
| 55 | #define PDC_RX_TIMEOUT (3 * 10) /* 3 bytes */ |
| 56 | |
Haavard Skinnemoen | 749c4e6 | 2006-10-04 16:02:02 +0200 | [diff] [blame] | 57 | #if defined(CONFIG_SERIAL_ATMEL_CONSOLE) && defined(CONFIG_MAGIC_SYSRQ) |
Andrew Victor | 1e6c9c2 | 2006-01-10 16:59:27 +0000 | [diff] [blame] | 58 | #define SUPPORT_SYSRQ |
| 59 | #endif |
| 60 | |
| 61 | #include <linux/serial_core.h> |
| 62 | |
Claudio Scordino | e8faff7 | 2010-05-03 13:31:28 +0100 | [diff] [blame^] | 63 | static void atmel_start_rx(struct uart_port *port); |
| 64 | static void atmel_stop_rx(struct uart_port *port); |
| 65 | |
Haavard Skinnemoen | 749c4e6 | 2006-10-04 16:02:02 +0200 | [diff] [blame] | 66 | #ifdef CONFIG_SERIAL_ATMEL_TTYAT |
Andrew Victor | 1e6c9c2 | 2006-01-10 16:59:27 +0000 | [diff] [blame] | 67 | |
| 68 | /* Use device name ttyAT, major 204 and minor 154-169. This is necessary if we |
| 69 | * should coexist with the 8250 driver, such as if we have an external 16C550 |
| 70 | * UART. */ |
Haavard Skinnemoen | 7192f92 | 2006-10-04 16:02:05 +0200 | [diff] [blame] | 71 | #define SERIAL_ATMEL_MAJOR 204 |
Andrew Victor | 1e6c9c2 | 2006-01-10 16:59:27 +0000 | [diff] [blame] | 72 | #define MINOR_START 154 |
Haavard Skinnemoen | 7192f92 | 2006-10-04 16:02:05 +0200 | [diff] [blame] | 73 | #define ATMEL_DEVICENAME "ttyAT" |
Andrew Victor | 1e6c9c2 | 2006-01-10 16:59:27 +0000 | [diff] [blame] | 74 | |
| 75 | #else |
| 76 | |
| 77 | /* Use device name ttyS, major 4, minor 64-68. This is the usual serial port |
| 78 | * name, but it is legally reserved for the 8250 driver. */ |
Haavard Skinnemoen | 7192f92 | 2006-10-04 16:02:05 +0200 | [diff] [blame] | 79 | #define SERIAL_ATMEL_MAJOR TTY_MAJOR |
Andrew Victor | 1e6c9c2 | 2006-01-10 16:59:27 +0000 | [diff] [blame] | 80 | #define MINOR_START 64 |
Haavard Skinnemoen | 7192f92 | 2006-10-04 16:02:05 +0200 | [diff] [blame] | 81 | #define ATMEL_DEVICENAME "ttyS" |
Andrew Victor | 1e6c9c2 | 2006-01-10 16:59:27 +0000 | [diff] [blame] | 82 | |
| 83 | #endif |
| 84 | |
Haavard Skinnemoen | 7192f92 | 2006-10-04 16:02:05 +0200 | [diff] [blame] | 85 | #define ATMEL_ISR_PASS_LIMIT 256 |
Andrew Victor | 1e6c9c2 | 2006-01-10 16:59:27 +0000 | [diff] [blame] | 86 | |
Remy Bohmer | b843aa2 | 2008-02-08 04:21:01 -0800 | [diff] [blame] | 87 | /* UART registers. CR is write-only, hence no GET macro */ |
Haavard Skinnemoen | 544fc72 | 2007-02-12 00:52:15 -0800 | [diff] [blame] | 88 | #define UART_PUT_CR(port,v) __raw_writel(v, (port)->membase + ATMEL_US_CR) |
| 89 | #define UART_GET_MR(port) __raw_readl((port)->membase + ATMEL_US_MR) |
| 90 | #define UART_PUT_MR(port,v) __raw_writel(v, (port)->membase + ATMEL_US_MR) |
| 91 | #define UART_PUT_IER(port,v) __raw_writel(v, (port)->membase + ATMEL_US_IER) |
| 92 | #define UART_PUT_IDR(port,v) __raw_writel(v, (port)->membase + ATMEL_US_IDR) |
| 93 | #define UART_GET_IMR(port) __raw_readl((port)->membase + ATMEL_US_IMR) |
| 94 | #define UART_GET_CSR(port) __raw_readl((port)->membase + ATMEL_US_CSR) |
| 95 | #define UART_GET_CHAR(port) __raw_readl((port)->membase + ATMEL_US_RHR) |
| 96 | #define UART_PUT_CHAR(port,v) __raw_writel(v, (port)->membase + ATMEL_US_THR) |
| 97 | #define UART_GET_BRGR(port) __raw_readl((port)->membase + ATMEL_US_BRGR) |
| 98 | #define UART_PUT_BRGR(port,v) __raw_writel(v, (port)->membase + ATMEL_US_BRGR) |
| 99 | #define UART_PUT_RTOR(port,v) __raw_writel(v, (port)->membase + ATMEL_US_RTOR) |
Claudio Scordino | e8faff7 | 2010-05-03 13:31:28 +0100 | [diff] [blame^] | 100 | #define UART_PUT_TTGR(port, v) __raw_writel(v, (port)->membase + ATMEL_US_TTGR) |
Andrew Victor | 1e6c9c2 | 2006-01-10 16:59:27 +0000 | [diff] [blame] | 101 | |
Andrew Victor | 1e6c9c2 | 2006-01-10 16:59:27 +0000 | [diff] [blame] | 102 | /* PDC registers */ |
Haavard Skinnemoen | 544fc72 | 2007-02-12 00:52:15 -0800 | [diff] [blame] | 103 | #define UART_PUT_PTCR(port,v) __raw_writel(v, (port)->membase + ATMEL_PDC_PTCR) |
| 104 | #define UART_GET_PTSR(port) __raw_readl((port)->membase + ATMEL_PDC_PTSR) |
Andrew Victor | afefc41 | 2006-06-19 19:53:19 +0100 | [diff] [blame] | 105 | |
Haavard Skinnemoen | 544fc72 | 2007-02-12 00:52:15 -0800 | [diff] [blame] | 106 | #define UART_PUT_RPR(port,v) __raw_writel(v, (port)->membase + ATMEL_PDC_RPR) |
| 107 | #define UART_GET_RPR(port) __raw_readl((port)->membase + ATMEL_PDC_RPR) |
| 108 | #define UART_PUT_RCR(port,v) __raw_writel(v, (port)->membase + ATMEL_PDC_RCR) |
| 109 | #define UART_PUT_RNPR(port,v) __raw_writel(v, (port)->membase + ATMEL_PDC_RNPR) |
| 110 | #define UART_PUT_RNCR(port,v) __raw_writel(v, (port)->membase + ATMEL_PDC_RNCR) |
Andrew Victor | 1e6c9c2 | 2006-01-10 16:59:27 +0000 | [diff] [blame] | 111 | |
Haavard Skinnemoen | 544fc72 | 2007-02-12 00:52:15 -0800 | [diff] [blame] | 112 | #define UART_PUT_TPR(port,v) __raw_writel(v, (port)->membase + ATMEL_PDC_TPR) |
| 113 | #define UART_PUT_TCR(port,v) __raw_writel(v, (port)->membase + ATMEL_PDC_TCR) |
Marc Pignat | 39d4c92 | 2008-04-02 13:04:42 -0700 | [diff] [blame] | 114 | #define UART_GET_TCR(port) __raw_readl((port)->membase + ATMEL_PDC_TCR) |
Andrew Victor | 1e6c9c2 | 2006-01-10 16:59:27 +0000 | [diff] [blame] | 115 | |
Haavard Skinnemoen | 71f2e2b | 2006-10-04 16:02:07 +0200 | [diff] [blame] | 116 | static int (*atmel_open_hook)(struct uart_port *); |
| 117 | static void (*atmel_close_hook)(struct uart_port *); |
Andrew Victor | 1e6c9c2 | 2006-01-10 16:59:27 +0000 | [diff] [blame] | 118 | |
Chip Coldwell | a667061 | 2008-02-08 04:21:06 -0800 | [diff] [blame] | 119 | struct atmel_dma_buffer { |
| 120 | unsigned char *buf; |
| 121 | dma_addr_t dma_addr; |
| 122 | unsigned int dma_size; |
| 123 | unsigned int ofs; |
| 124 | }; |
| 125 | |
Remy Bohmer | 1ecc26b | 2008-02-08 04:21:05 -0800 | [diff] [blame] | 126 | struct atmel_uart_char { |
| 127 | u16 status; |
| 128 | u16 ch; |
| 129 | }; |
| 130 | |
| 131 | #define ATMEL_SERIAL_RINGSIZE 1024 |
| 132 | |
Andrew Victor | afefc41 | 2006-06-19 19:53:19 +0100 | [diff] [blame] | 133 | /* |
| 134 | * We wrap our port structure around the generic uart_port. |
| 135 | */ |
Haavard Skinnemoen | 7192f92 | 2006-10-04 16:02:05 +0200 | [diff] [blame] | 136 | struct atmel_uart_port { |
Andrew Victor | afefc41 | 2006-06-19 19:53:19 +0100 | [diff] [blame] | 137 | struct uart_port uart; /* uart */ |
| 138 | struct clk *clk; /* uart clock */ |
Anti Sullin | f05596d | 2008-09-22 13:57:54 -0700 | [diff] [blame] | 139 | int may_wakeup; /* cached value of device_may_wakeup for times we need to disable it */ |
| 140 | u32 backup_imr; /* IMR saved during suspend */ |
Haavard Skinnemoen | 9e6077b | 2007-07-15 23:40:36 -0700 | [diff] [blame] | 141 | int break_active; /* break being received */ |
Remy Bohmer | 1ecc26b | 2008-02-08 04:21:05 -0800 | [diff] [blame] | 142 | |
Chip Coldwell | a667061 | 2008-02-08 04:21:06 -0800 | [diff] [blame] | 143 | short use_dma_rx; /* enable PDC receiver */ |
| 144 | short pdc_rx_idx; /* current PDC RX buffer */ |
| 145 | struct atmel_dma_buffer pdc_rx[2]; /* PDC receier */ |
| 146 | |
| 147 | short use_dma_tx; /* enable PDC transmitter */ |
| 148 | struct atmel_dma_buffer pdc_tx; /* PDC transmitter */ |
| 149 | |
Remy Bohmer | 1ecc26b | 2008-02-08 04:21:05 -0800 | [diff] [blame] | 150 | struct tasklet_struct tasklet; |
| 151 | unsigned int irq_status; |
| 152 | unsigned int irq_status_prev; |
| 153 | |
| 154 | struct circ_buf rx_ring; |
Claudio Scordino | e8faff7 | 2010-05-03 13:31:28 +0100 | [diff] [blame^] | 155 | |
| 156 | struct serial_rs485 rs485; /* rs485 settings */ |
| 157 | unsigned int tx_done_mask; |
Andrew Victor | afefc41 | 2006-06-19 19:53:19 +0100 | [diff] [blame] | 158 | }; |
| 159 | |
Haavard Skinnemoen | 7192f92 | 2006-10-04 16:02:05 +0200 | [diff] [blame] | 160 | static struct atmel_uart_port atmel_ports[ATMEL_MAX_UART]; |
Andrew Victor | afefc41 | 2006-06-19 19:53:19 +0100 | [diff] [blame] | 161 | |
Andrew Victor | 1e6c9c2 | 2006-01-10 16:59:27 +0000 | [diff] [blame] | 162 | #ifdef SUPPORT_SYSRQ |
Haavard Skinnemoen | 7192f92 | 2006-10-04 16:02:05 +0200 | [diff] [blame] | 163 | static struct console atmel_console; |
Andrew Victor | 1e6c9c2 | 2006-01-10 16:59:27 +0000 | [diff] [blame] | 164 | #endif |
| 165 | |
Haavard Skinnemoen | c811ab8 | 2008-02-08 04:21:08 -0800 | [diff] [blame] | 166 | static inline struct atmel_uart_port * |
| 167 | to_atmel_uart_port(struct uart_port *uart) |
| 168 | { |
| 169 | return container_of(uart, struct atmel_uart_port, uart); |
| 170 | } |
| 171 | |
Chip Coldwell | a667061 | 2008-02-08 04:21:06 -0800 | [diff] [blame] | 172 | #ifdef CONFIG_SERIAL_ATMEL_PDC |
| 173 | static bool atmel_use_dma_rx(struct uart_port *port) |
| 174 | { |
Haavard Skinnemoen | c811ab8 | 2008-02-08 04:21:08 -0800 | [diff] [blame] | 175 | struct atmel_uart_port *atmel_port = to_atmel_uart_port(port); |
Chip Coldwell | a667061 | 2008-02-08 04:21:06 -0800 | [diff] [blame] | 176 | |
| 177 | return atmel_port->use_dma_rx; |
| 178 | } |
| 179 | |
| 180 | static bool atmel_use_dma_tx(struct uart_port *port) |
| 181 | { |
Haavard Skinnemoen | c811ab8 | 2008-02-08 04:21:08 -0800 | [diff] [blame] | 182 | struct atmel_uart_port *atmel_port = to_atmel_uart_port(port); |
Chip Coldwell | a667061 | 2008-02-08 04:21:06 -0800 | [diff] [blame] | 183 | |
| 184 | return atmel_port->use_dma_tx; |
| 185 | } |
| 186 | #else |
| 187 | static bool atmel_use_dma_rx(struct uart_port *port) |
| 188 | { |
| 189 | return false; |
| 190 | } |
| 191 | |
| 192 | static bool atmel_use_dma_tx(struct uart_port *port) |
| 193 | { |
| 194 | return false; |
| 195 | } |
| 196 | #endif |
| 197 | |
Claudio Scordino | e8faff7 | 2010-05-03 13:31:28 +0100 | [diff] [blame^] | 198 | /* Enable or disable the rs485 support */ |
| 199 | void atmel_config_rs485(struct uart_port *port, struct serial_rs485 *rs485conf) |
| 200 | { |
| 201 | struct atmel_uart_port *atmel_port = to_atmel_uart_port(port); |
| 202 | unsigned int mode; |
| 203 | |
| 204 | spin_lock(&port->lock); |
| 205 | |
| 206 | /* Disable interrupts */ |
| 207 | UART_PUT_IDR(port, atmel_port->tx_done_mask); |
| 208 | |
| 209 | mode = UART_GET_MR(port); |
| 210 | |
| 211 | /* Resetting serial mode to RS232 (0x0) */ |
| 212 | mode &= ~ATMEL_US_USMODE; |
| 213 | |
| 214 | atmel_port->rs485 = *rs485conf; |
| 215 | |
| 216 | if (rs485conf->flags & SER_RS485_ENABLED) { |
| 217 | dev_dbg(port->dev, "Setting UART to RS485\n"); |
| 218 | atmel_port->tx_done_mask = ATMEL_US_TXEMPTY; |
| 219 | UART_PUT_TTGR(port, rs485conf->delay_rts_before_send); |
| 220 | mode |= ATMEL_US_USMODE_RS485; |
| 221 | } else { |
| 222 | dev_dbg(port->dev, "Setting UART to RS232\n"); |
| 223 | if (atmel_use_dma_tx(port)) |
| 224 | atmel_port->tx_done_mask = ATMEL_US_ENDTX | |
| 225 | ATMEL_US_TXBUFE; |
| 226 | else |
| 227 | atmel_port->tx_done_mask = ATMEL_US_TXRDY; |
| 228 | } |
| 229 | UART_PUT_MR(port, mode); |
| 230 | |
| 231 | /* Enable interrupts */ |
| 232 | UART_PUT_IER(port, atmel_port->tx_done_mask); |
| 233 | |
| 234 | spin_unlock(&port->lock); |
| 235 | |
| 236 | } |
| 237 | |
Andrew Victor | 1e6c9c2 | 2006-01-10 16:59:27 +0000 | [diff] [blame] | 238 | /* |
| 239 | * Return TIOCSER_TEMT when transmitter FIFO and Shift register is empty. |
| 240 | */ |
Haavard Skinnemoen | 7192f92 | 2006-10-04 16:02:05 +0200 | [diff] [blame] | 241 | static u_int atmel_tx_empty(struct uart_port *port) |
Andrew Victor | 1e6c9c2 | 2006-01-10 16:59:27 +0000 | [diff] [blame] | 242 | { |
Haavard Skinnemoen | 7192f92 | 2006-10-04 16:02:05 +0200 | [diff] [blame] | 243 | return (UART_GET_CSR(port) & ATMEL_US_TXEMPTY) ? TIOCSER_TEMT : 0; |
Andrew Victor | 1e6c9c2 | 2006-01-10 16:59:27 +0000 | [diff] [blame] | 244 | } |
| 245 | |
| 246 | /* |
| 247 | * Set state of the modem control output lines |
| 248 | */ |
Haavard Skinnemoen | 7192f92 | 2006-10-04 16:02:05 +0200 | [diff] [blame] | 249 | static void atmel_set_mctrl(struct uart_port *port, u_int mctrl) |
Andrew Victor | 1e6c9c2 | 2006-01-10 16:59:27 +0000 | [diff] [blame] | 250 | { |
| 251 | unsigned int control = 0; |
Andrew Victor | afefc41 | 2006-06-19 19:53:19 +0100 | [diff] [blame] | 252 | unsigned int mode; |
Claudio Scordino | e8faff7 | 2010-05-03 13:31:28 +0100 | [diff] [blame^] | 253 | struct atmel_uart_port *atmel_port = to_atmel_uart_port(port); |
Andrew Victor | 1e6c9c2 | 2006-01-10 16:59:27 +0000 | [diff] [blame] | 254 | |
Andrew Victor | c2f5ccf | 2006-12-04 09:37:20 +0100 | [diff] [blame] | 255 | #ifdef CONFIG_ARCH_AT91RM9200 |
Andrew Victor | 79da7a6 | 2006-11-30 11:58:14 +0100 | [diff] [blame] | 256 | if (cpu_is_at91rm9200()) { |
Andrew Victor | afefc41 | 2006-06-19 19:53:19 +0100 | [diff] [blame] | 257 | /* |
Remy Bohmer | b843aa2 | 2008-02-08 04:21:01 -0800 | [diff] [blame] | 258 | * AT91RM9200 Errata #39: RTS0 is not internally connected |
| 259 | * to PA21. We need to drive the pin manually. |
Andrew Victor | afefc41 | 2006-06-19 19:53:19 +0100 | [diff] [blame] | 260 | */ |
Andrew Victor | 7272991 | 2006-09-27 09:44:11 +0100 | [diff] [blame] | 261 | if (port->mapbase == AT91RM9200_BASE_US0) { |
Andrew Victor | afefc41 | 2006-06-19 19:53:19 +0100 | [diff] [blame] | 262 | if (mctrl & TIOCM_RTS) |
Andrew Victor | 20e6527 | 2006-07-05 14:31:13 +0100 | [diff] [blame] | 263 | at91_set_gpio_value(AT91_PIN_PA21, 0); |
Andrew Victor | afefc41 | 2006-06-19 19:53:19 +0100 | [diff] [blame] | 264 | else |
Andrew Victor | 20e6527 | 2006-07-05 14:31:13 +0100 | [diff] [blame] | 265 | at91_set_gpio_value(AT91_PIN_PA21, 1); |
Andrew Victor | afefc41 | 2006-06-19 19:53:19 +0100 | [diff] [blame] | 266 | } |
Andrew Victor | 1e6c9c2 | 2006-01-10 16:59:27 +0000 | [diff] [blame] | 267 | } |
Haavard Skinnemoen | acca9b8 | 2006-10-04 16:02:09 +0200 | [diff] [blame] | 268 | #endif |
Andrew Victor | 1e6c9c2 | 2006-01-10 16:59:27 +0000 | [diff] [blame] | 269 | |
| 270 | if (mctrl & TIOCM_RTS) |
Haavard Skinnemoen | 7192f92 | 2006-10-04 16:02:05 +0200 | [diff] [blame] | 271 | control |= ATMEL_US_RTSEN; |
Andrew Victor | 1e6c9c2 | 2006-01-10 16:59:27 +0000 | [diff] [blame] | 272 | else |
Haavard Skinnemoen | 7192f92 | 2006-10-04 16:02:05 +0200 | [diff] [blame] | 273 | control |= ATMEL_US_RTSDIS; |
Andrew Victor | 1e6c9c2 | 2006-01-10 16:59:27 +0000 | [diff] [blame] | 274 | |
| 275 | if (mctrl & TIOCM_DTR) |
Haavard Skinnemoen | 7192f92 | 2006-10-04 16:02:05 +0200 | [diff] [blame] | 276 | control |= ATMEL_US_DTREN; |
Andrew Victor | 1e6c9c2 | 2006-01-10 16:59:27 +0000 | [diff] [blame] | 277 | else |
Haavard Skinnemoen | 7192f92 | 2006-10-04 16:02:05 +0200 | [diff] [blame] | 278 | control |= ATMEL_US_DTRDIS; |
Andrew Victor | 1e6c9c2 | 2006-01-10 16:59:27 +0000 | [diff] [blame] | 279 | |
Andrew Victor | afefc41 | 2006-06-19 19:53:19 +0100 | [diff] [blame] | 280 | UART_PUT_CR(port, control); |
| 281 | |
| 282 | /* Local loopback mode? */ |
Haavard Skinnemoen | 7192f92 | 2006-10-04 16:02:05 +0200 | [diff] [blame] | 283 | mode = UART_GET_MR(port) & ~ATMEL_US_CHMODE; |
Andrew Victor | afefc41 | 2006-06-19 19:53:19 +0100 | [diff] [blame] | 284 | if (mctrl & TIOCM_LOOP) |
Haavard Skinnemoen | 7192f92 | 2006-10-04 16:02:05 +0200 | [diff] [blame] | 285 | mode |= ATMEL_US_CHMODE_LOC_LOOP; |
Andrew Victor | afefc41 | 2006-06-19 19:53:19 +0100 | [diff] [blame] | 286 | else |
Haavard Skinnemoen | 7192f92 | 2006-10-04 16:02:05 +0200 | [diff] [blame] | 287 | mode |= ATMEL_US_CHMODE_NORMAL; |
Claudio Scordino | e8faff7 | 2010-05-03 13:31:28 +0100 | [diff] [blame^] | 288 | |
| 289 | /* Resetting serial mode to RS232 (0x0) */ |
| 290 | mode &= ~ATMEL_US_USMODE; |
| 291 | |
| 292 | if (atmel_port->rs485.flags & SER_RS485_ENABLED) { |
| 293 | dev_dbg(port->dev, "Setting UART to RS485\n"); |
| 294 | UART_PUT_TTGR(port, atmel_port->rs485.delay_rts_before_send); |
| 295 | mode |= ATMEL_US_USMODE_RS485; |
| 296 | } else { |
| 297 | dev_dbg(port->dev, "Setting UART to RS232\n"); |
| 298 | } |
Andrew Victor | afefc41 | 2006-06-19 19:53:19 +0100 | [diff] [blame] | 299 | UART_PUT_MR(port, mode); |
Andrew Victor | 1e6c9c2 | 2006-01-10 16:59:27 +0000 | [diff] [blame] | 300 | } |
| 301 | |
| 302 | /* |
| 303 | * Get state of the modem control input lines |
| 304 | */ |
Haavard Skinnemoen | 7192f92 | 2006-10-04 16:02:05 +0200 | [diff] [blame] | 305 | static u_int atmel_get_mctrl(struct uart_port *port) |
Andrew Victor | 1e6c9c2 | 2006-01-10 16:59:27 +0000 | [diff] [blame] | 306 | { |
| 307 | unsigned int status, ret = 0; |
| 308 | |
| 309 | status = UART_GET_CSR(port); |
| 310 | |
| 311 | /* |
| 312 | * The control signals are active low. |
| 313 | */ |
Haavard Skinnemoen | 7192f92 | 2006-10-04 16:02:05 +0200 | [diff] [blame] | 314 | if (!(status & ATMEL_US_DCD)) |
Andrew Victor | 1e6c9c2 | 2006-01-10 16:59:27 +0000 | [diff] [blame] | 315 | ret |= TIOCM_CD; |
Haavard Skinnemoen | 7192f92 | 2006-10-04 16:02:05 +0200 | [diff] [blame] | 316 | if (!(status & ATMEL_US_CTS)) |
Andrew Victor | 1e6c9c2 | 2006-01-10 16:59:27 +0000 | [diff] [blame] | 317 | ret |= TIOCM_CTS; |
Haavard Skinnemoen | 7192f92 | 2006-10-04 16:02:05 +0200 | [diff] [blame] | 318 | if (!(status & ATMEL_US_DSR)) |
Andrew Victor | 1e6c9c2 | 2006-01-10 16:59:27 +0000 | [diff] [blame] | 319 | ret |= TIOCM_DSR; |
Haavard Skinnemoen | 7192f92 | 2006-10-04 16:02:05 +0200 | [diff] [blame] | 320 | if (!(status & ATMEL_US_RI)) |
Andrew Victor | 1e6c9c2 | 2006-01-10 16:59:27 +0000 | [diff] [blame] | 321 | ret |= TIOCM_RI; |
| 322 | |
| 323 | return ret; |
| 324 | } |
| 325 | |
| 326 | /* |
| 327 | * Stop transmitting. |
| 328 | */ |
Haavard Skinnemoen | 7192f92 | 2006-10-04 16:02:05 +0200 | [diff] [blame] | 329 | static void atmel_stop_tx(struct uart_port *port) |
Andrew Victor | 1e6c9c2 | 2006-01-10 16:59:27 +0000 | [diff] [blame] | 330 | { |
Claudio Scordino | e8faff7 | 2010-05-03 13:31:28 +0100 | [diff] [blame^] | 331 | struct atmel_uart_port *atmel_port = to_atmel_uart_port(port); |
| 332 | |
Chip Coldwell | a667061 | 2008-02-08 04:21:06 -0800 | [diff] [blame] | 333 | if (atmel_use_dma_tx(port)) { |
| 334 | /* disable PDC transmit */ |
| 335 | UART_PUT_PTCR(port, ATMEL_PDC_TXTDIS); |
Claudio Scordino | e8faff7 | 2010-05-03 13:31:28 +0100 | [diff] [blame^] | 336 | } |
| 337 | /* Disable interrupts */ |
| 338 | UART_PUT_IDR(port, atmel_port->tx_done_mask); |
| 339 | |
| 340 | if (atmel_port->rs485.flags & SER_RS485_ENABLED) |
| 341 | atmel_start_rx(port); |
Andrew Victor | 1e6c9c2 | 2006-01-10 16:59:27 +0000 | [diff] [blame] | 342 | } |
| 343 | |
| 344 | /* |
| 345 | * Start transmitting. |
| 346 | */ |
Haavard Skinnemoen | 7192f92 | 2006-10-04 16:02:05 +0200 | [diff] [blame] | 347 | static void atmel_start_tx(struct uart_port *port) |
Andrew Victor | 1e6c9c2 | 2006-01-10 16:59:27 +0000 | [diff] [blame] | 348 | { |
Claudio Scordino | e8faff7 | 2010-05-03 13:31:28 +0100 | [diff] [blame^] | 349 | struct atmel_uart_port *atmel_port = to_atmel_uart_port(port); |
| 350 | |
Chip Coldwell | a667061 | 2008-02-08 04:21:06 -0800 | [diff] [blame] | 351 | if (atmel_use_dma_tx(port)) { |
| 352 | if (UART_GET_PTSR(port) & ATMEL_PDC_TXTEN) |
| 353 | /* The transmitter is already running. Yes, we |
| 354 | really need this.*/ |
| 355 | return; |
| 356 | |
Claudio Scordino | e8faff7 | 2010-05-03 13:31:28 +0100 | [diff] [blame^] | 357 | if (atmel_port->rs485.flags & SER_RS485_ENABLED) |
| 358 | atmel_stop_rx(port); |
| 359 | |
Chip Coldwell | a667061 | 2008-02-08 04:21:06 -0800 | [diff] [blame] | 360 | /* re-enable PDC transmit */ |
| 361 | UART_PUT_PTCR(port, ATMEL_PDC_TXTEN); |
Claudio Scordino | e8faff7 | 2010-05-03 13:31:28 +0100 | [diff] [blame^] | 362 | } |
| 363 | /* Enable interrupts */ |
| 364 | UART_PUT_IER(port, atmel_port->tx_done_mask); |
| 365 | } |
| 366 | |
| 367 | /* |
| 368 | * start receiving - port is in process of being opened. |
| 369 | */ |
| 370 | static void atmel_start_rx(struct uart_port *port) |
| 371 | { |
| 372 | UART_PUT_CR(port, ATMEL_US_RSTSTA); /* reset status and receiver */ |
| 373 | |
| 374 | if (atmel_use_dma_rx(port)) { |
| 375 | /* enable PDC controller */ |
| 376 | UART_PUT_IER(port, ATMEL_US_ENDRX | ATMEL_US_TIMEOUT | |
| 377 | port->read_status_mask); |
| 378 | UART_PUT_PTCR(port, ATMEL_PDC_RXTEN); |
| 379 | } else { |
| 380 | UART_PUT_IER(port, ATMEL_US_RXRDY); |
| 381 | } |
Andrew Victor | 1e6c9c2 | 2006-01-10 16:59:27 +0000 | [diff] [blame] | 382 | } |
| 383 | |
| 384 | /* |
| 385 | * Stop receiving - port is in process of being closed. |
| 386 | */ |
Haavard Skinnemoen | 7192f92 | 2006-10-04 16:02:05 +0200 | [diff] [blame] | 387 | static void atmel_stop_rx(struct uart_port *port) |
Andrew Victor | 1e6c9c2 | 2006-01-10 16:59:27 +0000 | [diff] [blame] | 388 | { |
Chip Coldwell | a667061 | 2008-02-08 04:21:06 -0800 | [diff] [blame] | 389 | if (atmel_use_dma_rx(port)) { |
| 390 | /* disable PDC receive */ |
| 391 | UART_PUT_PTCR(port, ATMEL_PDC_RXTDIS); |
Claudio Scordino | e8faff7 | 2010-05-03 13:31:28 +0100 | [diff] [blame^] | 392 | UART_PUT_IDR(port, ATMEL_US_ENDRX | ATMEL_US_TIMEOUT | |
| 393 | port->read_status_mask); |
| 394 | } else { |
Chip Coldwell | a667061 | 2008-02-08 04:21:06 -0800 | [diff] [blame] | 395 | UART_PUT_IDR(port, ATMEL_US_RXRDY); |
Claudio Scordino | e8faff7 | 2010-05-03 13:31:28 +0100 | [diff] [blame^] | 396 | } |
Andrew Victor | 1e6c9c2 | 2006-01-10 16:59:27 +0000 | [diff] [blame] | 397 | } |
| 398 | |
| 399 | /* |
| 400 | * Enable modem status interrupts |
| 401 | */ |
Haavard Skinnemoen | 7192f92 | 2006-10-04 16:02:05 +0200 | [diff] [blame] | 402 | static void atmel_enable_ms(struct uart_port *port) |
Andrew Victor | 1e6c9c2 | 2006-01-10 16:59:27 +0000 | [diff] [blame] | 403 | { |
Remy Bohmer | b843aa2 | 2008-02-08 04:21:01 -0800 | [diff] [blame] | 404 | UART_PUT_IER(port, ATMEL_US_RIIC | ATMEL_US_DSRIC |
| 405 | | ATMEL_US_DCDIC | ATMEL_US_CTSIC); |
Andrew Victor | 1e6c9c2 | 2006-01-10 16:59:27 +0000 | [diff] [blame] | 406 | } |
| 407 | |
| 408 | /* |
| 409 | * Control the transmission of a break signal |
| 410 | */ |
Haavard Skinnemoen | 7192f92 | 2006-10-04 16:02:05 +0200 | [diff] [blame] | 411 | static void atmel_break_ctl(struct uart_port *port, int break_state) |
Andrew Victor | 1e6c9c2 | 2006-01-10 16:59:27 +0000 | [diff] [blame] | 412 | { |
| 413 | if (break_state != 0) |
Haavard Skinnemoen | 7192f92 | 2006-10-04 16:02:05 +0200 | [diff] [blame] | 414 | UART_PUT_CR(port, ATMEL_US_STTBRK); /* start break */ |
Andrew Victor | 1e6c9c2 | 2006-01-10 16:59:27 +0000 | [diff] [blame] | 415 | else |
Haavard Skinnemoen | 7192f92 | 2006-10-04 16:02:05 +0200 | [diff] [blame] | 416 | UART_PUT_CR(port, ATMEL_US_STPBRK); /* stop break */ |
Andrew Victor | 1e6c9c2 | 2006-01-10 16:59:27 +0000 | [diff] [blame] | 417 | } |
| 418 | |
| 419 | /* |
Remy Bohmer | 1ecc26b | 2008-02-08 04:21:05 -0800 | [diff] [blame] | 420 | * Stores the incoming character in the ring buffer |
| 421 | */ |
| 422 | static void |
| 423 | atmel_buffer_rx_char(struct uart_port *port, unsigned int status, |
| 424 | unsigned int ch) |
| 425 | { |
Haavard Skinnemoen | c811ab8 | 2008-02-08 04:21:08 -0800 | [diff] [blame] | 426 | struct atmel_uart_port *atmel_port = to_atmel_uart_port(port); |
Remy Bohmer | 1ecc26b | 2008-02-08 04:21:05 -0800 | [diff] [blame] | 427 | struct circ_buf *ring = &atmel_port->rx_ring; |
| 428 | struct atmel_uart_char *c; |
| 429 | |
| 430 | if (!CIRC_SPACE(ring->head, ring->tail, ATMEL_SERIAL_RINGSIZE)) |
| 431 | /* Buffer overflow, ignore char */ |
| 432 | return; |
| 433 | |
| 434 | c = &((struct atmel_uart_char *)ring->buf)[ring->head]; |
| 435 | c->status = status; |
| 436 | c->ch = ch; |
| 437 | |
| 438 | /* Make sure the character is stored before we update head. */ |
| 439 | smp_wmb(); |
| 440 | |
| 441 | ring->head = (ring->head + 1) & (ATMEL_SERIAL_RINGSIZE - 1); |
| 442 | } |
| 443 | |
| 444 | /* |
Chip Coldwell | a667061 | 2008-02-08 04:21:06 -0800 | [diff] [blame] | 445 | * Deal with parity, framing and overrun errors. |
| 446 | */ |
| 447 | static void atmel_pdc_rxerr(struct uart_port *port, unsigned int status) |
| 448 | { |
| 449 | /* clear error */ |
| 450 | UART_PUT_CR(port, ATMEL_US_RSTSTA); |
| 451 | |
| 452 | if (status & ATMEL_US_RXBRK) { |
| 453 | /* ignore side-effect */ |
| 454 | status &= ~(ATMEL_US_PARE | ATMEL_US_FRAME); |
| 455 | port->icount.brk++; |
| 456 | } |
| 457 | if (status & ATMEL_US_PARE) |
| 458 | port->icount.parity++; |
| 459 | if (status & ATMEL_US_FRAME) |
| 460 | port->icount.frame++; |
| 461 | if (status & ATMEL_US_OVRE) |
| 462 | port->icount.overrun++; |
| 463 | } |
| 464 | |
| 465 | /* |
Andrew Victor | 1e6c9c2 | 2006-01-10 16:59:27 +0000 | [diff] [blame] | 466 | * Characters received (called from interrupt handler) |
| 467 | */ |
David Howells | 7d12e78 | 2006-10-05 14:55:46 +0100 | [diff] [blame] | 468 | static void atmel_rx_chars(struct uart_port *port) |
Andrew Victor | 1e6c9c2 | 2006-01-10 16:59:27 +0000 | [diff] [blame] | 469 | { |
Haavard Skinnemoen | c811ab8 | 2008-02-08 04:21:08 -0800 | [diff] [blame] | 470 | struct atmel_uart_port *atmel_port = to_atmel_uart_port(port); |
Remy Bohmer | 1ecc26b | 2008-02-08 04:21:05 -0800 | [diff] [blame] | 471 | unsigned int status, ch; |
Andrew Victor | 1e6c9c2 | 2006-01-10 16:59:27 +0000 | [diff] [blame] | 472 | |
Andrew Victor | afefc41 | 2006-06-19 19:53:19 +0100 | [diff] [blame] | 473 | status = UART_GET_CSR(port); |
Haavard Skinnemoen | 7192f92 | 2006-10-04 16:02:05 +0200 | [diff] [blame] | 474 | while (status & ATMEL_US_RXRDY) { |
Andrew Victor | 1e6c9c2 | 2006-01-10 16:59:27 +0000 | [diff] [blame] | 475 | ch = UART_GET_CHAR(port); |
| 476 | |
Andrew Victor | 1e6c9c2 | 2006-01-10 16:59:27 +0000 | [diff] [blame] | 477 | /* |
| 478 | * note that the error handling code is |
| 479 | * out of the main execution path |
| 480 | */ |
Haavard Skinnemoen | 9e6077b | 2007-07-15 23:40:36 -0700 | [diff] [blame] | 481 | if (unlikely(status & (ATMEL_US_PARE | ATMEL_US_FRAME |
| 482 | | ATMEL_US_OVRE | ATMEL_US_RXBRK) |
| 483 | || atmel_port->break_active)) { |
Remy Bohmer | 1ecc26b | 2008-02-08 04:21:05 -0800 | [diff] [blame] | 484 | |
Remy Bohmer | b843aa2 | 2008-02-08 04:21:01 -0800 | [diff] [blame] | 485 | /* clear error */ |
| 486 | UART_PUT_CR(port, ATMEL_US_RSTSTA); |
Remy Bohmer | 1ecc26b | 2008-02-08 04:21:05 -0800 | [diff] [blame] | 487 | |
Haavard Skinnemoen | 9e6077b | 2007-07-15 23:40:36 -0700 | [diff] [blame] | 488 | if (status & ATMEL_US_RXBRK |
| 489 | && !atmel_port->break_active) { |
Haavard Skinnemoen | 9e6077b | 2007-07-15 23:40:36 -0700 | [diff] [blame] | 490 | atmel_port->break_active = 1; |
| 491 | UART_PUT_IER(port, ATMEL_US_RXBRK); |
Haavard Skinnemoen | 9e6077b | 2007-07-15 23:40:36 -0700 | [diff] [blame] | 492 | } else { |
| 493 | /* |
| 494 | * This is either the end-of-break |
| 495 | * condition or we've received at |
| 496 | * least one character without RXBRK |
| 497 | * being set. In both cases, the next |
| 498 | * RXBRK will indicate start-of-break. |
| 499 | */ |
| 500 | UART_PUT_IDR(port, ATMEL_US_RXBRK); |
| 501 | status &= ~ATMEL_US_RXBRK; |
| 502 | atmel_port->break_active = 0; |
Andrew Victor | afefc41 | 2006-06-19 19:53:19 +0100 | [diff] [blame] | 503 | } |
Andrew Victor | 1e6c9c2 | 2006-01-10 16:59:27 +0000 | [diff] [blame] | 504 | } |
| 505 | |
Remy Bohmer | 1ecc26b | 2008-02-08 04:21:05 -0800 | [diff] [blame] | 506 | atmel_buffer_rx_char(port, status, ch); |
Andrew Victor | afefc41 | 2006-06-19 19:53:19 +0100 | [diff] [blame] | 507 | status = UART_GET_CSR(port); |
Andrew Victor | 1e6c9c2 | 2006-01-10 16:59:27 +0000 | [diff] [blame] | 508 | } |
| 509 | |
Remy Bohmer | 1ecc26b | 2008-02-08 04:21:05 -0800 | [diff] [blame] | 510 | tasklet_schedule(&atmel_port->tasklet); |
Andrew Victor | 1e6c9c2 | 2006-01-10 16:59:27 +0000 | [diff] [blame] | 511 | } |
| 512 | |
| 513 | /* |
Remy Bohmer | 1ecc26b | 2008-02-08 04:21:05 -0800 | [diff] [blame] | 514 | * Transmit characters (called from tasklet with TXRDY interrupt |
| 515 | * disabled) |
Andrew Victor | 1e6c9c2 | 2006-01-10 16:59:27 +0000 | [diff] [blame] | 516 | */ |
Haavard Skinnemoen | 7192f92 | 2006-10-04 16:02:05 +0200 | [diff] [blame] | 517 | static void atmel_tx_chars(struct uart_port *port) |
Andrew Victor | 1e6c9c2 | 2006-01-10 16:59:27 +0000 | [diff] [blame] | 518 | { |
Alan Cox | ebd2c8f | 2009-09-19 13:13:28 -0700 | [diff] [blame] | 519 | struct circ_buf *xmit = &port->state->xmit; |
Claudio Scordino | e8faff7 | 2010-05-03 13:31:28 +0100 | [diff] [blame^] | 520 | struct atmel_uart_port *atmel_port = to_atmel_uart_port(port); |
Andrew Victor | 1e6c9c2 | 2006-01-10 16:59:27 +0000 | [diff] [blame] | 521 | |
Claudio Scordino | e8faff7 | 2010-05-03 13:31:28 +0100 | [diff] [blame^] | 522 | if (port->x_char && UART_GET_CSR(port) & atmel_port->tx_done_mask) { |
Andrew Victor | 1e6c9c2 | 2006-01-10 16:59:27 +0000 | [diff] [blame] | 523 | UART_PUT_CHAR(port, port->x_char); |
| 524 | port->icount.tx++; |
| 525 | port->x_char = 0; |
Andrew Victor | 1e6c9c2 | 2006-01-10 16:59:27 +0000 | [diff] [blame] | 526 | } |
Remy Bohmer | 1ecc26b | 2008-02-08 04:21:05 -0800 | [diff] [blame] | 527 | if (uart_circ_empty(xmit) || uart_tx_stopped(port)) |
Andrew Victor | 1e6c9c2 | 2006-01-10 16:59:27 +0000 | [diff] [blame] | 528 | return; |
Andrew Victor | 1e6c9c2 | 2006-01-10 16:59:27 +0000 | [diff] [blame] | 529 | |
Claudio Scordino | e8faff7 | 2010-05-03 13:31:28 +0100 | [diff] [blame^] | 530 | while (UART_GET_CSR(port) & atmel_port->tx_done_mask) { |
Andrew Victor | 1e6c9c2 | 2006-01-10 16:59:27 +0000 | [diff] [blame] | 531 | UART_PUT_CHAR(port, xmit->buf[xmit->tail]); |
| 532 | xmit->tail = (xmit->tail + 1) & (UART_XMIT_SIZE - 1); |
| 533 | port->icount.tx++; |
| 534 | if (uart_circ_empty(xmit)) |
| 535 | break; |
| 536 | } |
| 537 | |
| 538 | if (uart_circ_chars_pending(xmit) < WAKEUP_CHARS) |
| 539 | uart_write_wakeup(port); |
| 540 | |
Remy Bohmer | 1ecc26b | 2008-02-08 04:21:05 -0800 | [diff] [blame] | 541 | if (!uart_circ_empty(xmit)) |
Claudio Scordino | e8faff7 | 2010-05-03 13:31:28 +0100 | [diff] [blame^] | 542 | /* Enable interrupts */ |
| 543 | UART_PUT_IER(port, atmel_port->tx_done_mask); |
Andrew Victor | 1e6c9c2 | 2006-01-10 16:59:27 +0000 | [diff] [blame] | 544 | } |
| 545 | |
| 546 | /* |
Remy Bohmer | b843aa2 | 2008-02-08 04:21:01 -0800 | [diff] [blame] | 547 | * receive interrupt handler. |
| 548 | */ |
| 549 | static void |
| 550 | atmel_handle_receive(struct uart_port *port, unsigned int pending) |
| 551 | { |
Haavard Skinnemoen | c811ab8 | 2008-02-08 04:21:08 -0800 | [diff] [blame] | 552 | struct atmel_uart_port *atmel_port = to_atmel_uart_port(port); |
Remy Bohmer | b843aa2 | 2008-02-08 04:21:01 -0800 | [diff] [blame] | 553 | |
Chip Coldwell | a667061 | 2008-02-08 04:21:06 -0800 | [diff] [blame] | 554 | if (atmel_use_dma_rx(port)) { |
| 555 | /* |
| 556 | * PDC receive. Just schedule the tasklet and let it |
| 557 | * figure out the details. |
| 558 | * |
| 559 | * TODO: We're not handling error flags correctly at |
| 560 | * the moment. |
| 561 | */ |
| 562 | if (pending & (ATMEL_US_ENDRX | ATMEL_US_TIMEOUT)) { |
| 563 | UART_PUT_IDR(port, (ATMEL_US_ENDRX |
| 564 | | ATMEL_US_TIMEOUT)); |
| 565 | tasklet_schedule(&atmel_port->tasklet); |
| 566 | } |
| 567 | |
| 568 | if (pending & (ATMEL_US_RXBRK | ATMEL_US_OVRE | |
| 569 | ATMEL_US_FRAME | ATMEL_US_PARE)) |
| 570 | atmel_pdc_rxerr(port, pending); |
| 571 | } |
| 572 | |
Remy Bohmer | b843aa2 | 2008-02-08 04:21:01 -0800 | [diff] [blame] | 573 | /* Interrupt receive */ |
| 574 | if (pending & ATMEL_US_RXRDY) |
| 575 | atmel_rx_chars(port); |
| 576 | else if (pending & ATMEL_US_RXBRK) { |
| 577 | /* |
| 578 | * End of break detected. If it came along with a |
| 579 | * character, atmel_rx_chars will handle it. |
| 580 | */ |
| 581 | UART_PUT_CR(port, ATMEL_US_RSTSTA); |
| 582 | UART_PUT_IDR(port, ATMEL_US_RXBRK); |
| 583 | atmel_port->break_active = 0; |
| 584 | } |
| 585 | } |
| 586 | |
| 587 | /* |
Remy Bohmer | 1ecc26b | 2008-02-08 04:21:05 -0800 | [diff] [blame] | 588 | * transmit interrupt handler. (Transmit is IRQF_NODELAY safe) |
Remy Bohmer | b843aa2 | 2008-02-08 04:21:01 -0800 | [diff] [blame] | 589 | */ |
| 590 | static void |
| 591 | atmel_handle_transmit(struct uart_port *port, unsigned int pending) |
| 592 | { |
Haavard Skinnemoen | c811ab8 | 2008-02-08 04:21:08 -0800 | [diff] [blame] | 593 | struct atmel_uart_port *atmel_port = to_atmel_uart_port(port); |
Remy Bohmer | 1ecc26b | 2008-02-08 04:21:05 -0800 | [diff] [blame] | 594 | |
Claudio Scordino | e8faff7 | 2010-05-03 13:31:28 +0100 | [diff] [blame^] | 595 | if (pending & atmel_port->tx_done_mask) { |
| 596 | /* Either PDC or interrupt transmission */ |
| 597 | UART_PUT_IDR(port, atmel_port->tx_done_mask); |
| 598 | tasklet_schedule(&atmel_port->tasklet); |
Remy Bohmer | 1ecc26b | 2008-02-08 04:21:05 -0800 | [diff] [blame] | 599 | } |
Remy Bohmer | b843aa2 | 2008-02-08 04:21:01 -0800 | [diff] [blame] | 600 | } |
| 601 | |
| 602 | /* |
| 603 | * status flags interrupt handler. |
| 604 | */ |
| 605 | static void |
| 606 | atmel_handle_status(struct uart_port *port, unsigned int pending, |
| 607 | unsigned int status) |
| 608 | { |
Haavard Skinnemoen | c811ab8 | 2008-02-08 04:21:08 -0800 | [diff] [blame] | 609 | struct atmel_uart_port *atmel_port = to_atmel_uart_port(port); |
Remy Bohmer | 1ecc26b | 2008-02-08 04:21:05 -0800 | [diff] [blame] | 610 | |
Remy Bohmer | b843aa2 | 2008-02-08 04:21:01 -0800 | [diff] [blame] | 611 | if (pending & (ATMEL_US_RIIC | ATMEL_US_DSRIC | ATMEL_US_DCDIC |
Remy Bohmer | 1ecc26b | 2008-02-08 04:21:05 -0800 | [diff] [blame] | 612 | | ATMEL_US_CTSIC)) { |
| 613 | atmel_port->irq_status = status; |
| 614 | tasklet_schedule(&atmel_port->tasklet); |
| 615 | } |
Remy Bohmer | b843aa2 | 2008-02-08 04:21:01 -0800 | [diff] [blame] | 616 | } |
| 617 | |
| 618 | /* |
Andrew Victor | 1e6c9c2 | 2006-01-10 16:59:27 +0000 | [diff] [blame] | 619 | * Interrupt handler |
| 620 | */ |
David Howells | 7d12e78 | 2006-10-05 14:55:46 +0100 | [diff] [blame] | 621 | static irqreturn_t atmel_interrupt(int irq, void *dev_id) |
Andrew Victor | 1e6c9c2 | 2006-01-10 16:59:27 +0000 | [diff] [blame] | 622 | { |
| 623 | struct uart_port *port = dev_id; |
| 624 | unsigned int status, pending, pass_counter = 0; |
| 625 | |
Chip Coldwell | a667061 | 2008-02-08 04:21:06 -0800 | [diff] [blame] | 626 | do { |
| 627 | status = UART_GET_CSR(port); |
| 628 | pending = status & UART_GET_IMR(port); |
| 629 | if (!pending) |
| 630 | break; |
| 631 | |
Remy Bohmer | b843aa2 | 2008-02-08 04:21:01 -0800 | [diff] [blame] | 632 | atmel_handle_receive(port, pending); |
| 633 | atmel_handle_status(port, pending, status); |
| 634 | atmel_handle_transmit(port, pending); |
Chip Coldwell | a667061 | 2008-02-08 04:21:06 -0800 | [diff] [blame] | 635 | } while (pass_counter++ < ATMEL_ISR_PASS_LIMIT); |
Andrew Victor | 1e6c9c2 | 2006-01-10 16:59:27 +0000 | [diff] [blame] | 636 | |
Haavard Skinnemoen | 0400b69 | 2008-02-23 15:23:36 -0800 | [diff] [blame] | 637 | return pass_counter ? IRQ_HANDLED : IRQ_NONE; |
Andrew Victor | 1e6c9c2 | 2006-01-10 16:59:27 +0000 | [diff] [blame] | 638 | } |
| 639 | |
Chip Coldwell | a667061 | 2008-02-08 04:21:06 -0800 | [diff] [blame] | 640 | /* |
| 641 | * Called from tasklet with ENDTX and TXBUFE interrupts disabled. |
| 642 | */ |
| 643 | static void atmel_tx_dma(struct uart_port *port) |
| 644 | { |
Haavard Skinnemoen | c811ab8 | 2008-02-08 04:21:08 -0800 | [diff] [blame] | 645 | struct atmel_uart_port *atmel_port = to_atmel_uart_port(port); |
Alan Cox | ebd2c8f | 2009-09-19 13:13:28 -0700 | [diff] [blame] | 646 | struct circ_buf *xmit = &port->state->xmit; |
Chip Coldwell | a667061 | 2008-02-08 04:21:06 -0800 | [diff] [blame] | 647 | struct atmel_dma_buffer *pdc = &atmel_port->pdc_tx; |
| 648 | int count; |
| 649 | |
Michael Trimarchi | ba0657f | 2008-04-02 13:04:41 -0700 | [diff] [blame] | 650 | /* nothing left to transmit? */ |
| 651 | if (UART_GET_TCR(port)) |
| 652 | return; |
| 653 | |
Chip Coldwell | a667061 | 2008-02-08 04:21:06 -0800 | [diff] [blame] | 654 | xmit->tail += pdc->ofs; |
| 655 | xmit->tail &= UART_XMIT_SIZE - 1; |
| 656 | |
| 657 | port->icount.tx += pdc->ofs; |
| 658 | pdc->ofs = 0; |
| 659 | |
Michael Trimarchi | ba0657f | 2008-04-02 13:04:41 -0700 | [diff] [blame] | 660 | /* more to transmit - setup next transfer */ |
Chip Coldwell | a667061 | 2008-02-08 04:21:06 -0800 | [diff] [blame] | 661 | |
Michael Trimarchi | ba0657f | 2008-04-02 13:04:41 -0700 | [diff] [blame] | 662 | /* disable PDC transmit */ |
| 663 | UART_PUT_PTCR(port, ATMEL_PDC_TXTDIS); |
| 664 | |
Itai Levi | 1f14081 | 2009-01-15 13:50:43 -0800 | [diff] [blame] | 665 | if (!uart_circ_empty(xmit) && !uart_tx_stopped(port)) { |
Chip Coldwell | a667061 | 2008-02-08 04:21:06 -0800 | [diff] [blame] | 666 | dma_sync_single_for_device(port->dev, |
| 667 | pdc->dma_addr, |
| 668 | pdc->dma_size, |
| 669 | DMA_TO_DEVICE); |
| 670 | |
| 671 | count = CIRC_CNT_TO_END(xmit->head, xmit->tail, UART_XMIT_SIZE); |
| 672 | pdc->ofs = count; |
| 673 | |
| 674 | UART_PUT_TPR(port, pdc->dma_addr + xmit->tail); |
| 675 | UART_PUT_TCR(port, count); |
Claudio Scordino | e8faff7 | 2010-05-03 13:31:28 +0100 | [diff] [blame^] | 676 | /* re-enable PDC transmit */ |
Chip Coldwell | a667061 | 2008-02-08 04:21:06 -0800 | [diff] [blame] | 677 | UART_PUT_PTCR(port, ATMEL_PDC_TXTEN); |
Claudio Scordino | e8faff7 | 2010-05-03 13:31:28 +0100 | [diff] [blame^] | 678 | /* Enable interrupts */ |
| 679 | UART_PUT_IER(port, atmel_port->tx_done_mask); |
| 680 | } else { |
| 681 | if (atmel_port->rs485.flags & SER_RS485_ENABLED) { |
| 682 | /* DMA done, stop TX, start RX for RS485 */ |
| 683 | atmel_start_rx(port); |
| 684 | } |
Chip Coldwell | a667061 | 2008-02-08 04:21:06 -0800 | [diff] [blame] | 685 | } |
| 686 | |
| 687 | if (uart_circ_chars_pending(xmit) < WAKEUP_CHARS) |
| 688 | uart_write_wakeup(port); |
| 689 | } |
| 690 | |
Remy Bohmer | 1ecc26b | 2008-02-08 04:21:05 -0800 | [diff] [blame] | 691 | static void atmel_rx_from_ring(struct uart_port *port) |
| 692 | { |
Haavard Skinnemoen | c811ab8 | 2008-02-08 04:21:08 -0800 | [diff] [blame] | 693 | struct atmel_uart_port *atmel_port = to_atmel_uart_port(port); |
Remy Bohmer | 1ecc26b | 2008-02-08 04:21:05 -0800 | [diff] [blame] | 694 | struct circ_buf *ring = &atmel_port->rx_ring; |
| 695 | unsigned int flg; |
| 696 | unsigned int status; |
| 697 | |
| 698 | while (ring->head != ring->tail) { |
| 699 | struct atmel_uart_char c; |
| 700 | |
| 701 | /* Make sure c is loaded after head. */ |
| 702 | smp_rmb(); |
| 703 | |
| 704 | c = ((struct atmel_uart_char *)ring->buf)[ring->tail]; |
| 705 | |
| 706 | ring->tail = (ring->tail + 1) & (ATMEL_SERIAL_RINGSIZE - 1); |
| 707 | |
| 708 | port->icount.rx++; |
| 709 | status = c.status; |
| 710 | flg = TTY_NORMAL; |
| 711 | |
| 712 | /* |
| 713 | * note that the error handling code is |
| 714 | * out of the main execution path |
| 715 | */ |
| 716 | if (unlikely(status & (ATMEL_US_PARE | ATMEL_US_FRAME |
| 717 | | ATMEL_US_OVRE | ATMEL_US_RXBRK))) { |
| 718 | if (status & ATMEL_US_RXBRK) { |
| 719 | /* ignore side-effect */ |
| 720 | status &= ~(ATMEL_US_PARE | ATMEL_US_FRAME); |
| 721 | |
| 722 | port->icount.brk++; |
| 723 | if (uart_handle_break(port)) |
| 724 | continue; |
| 725 | } |
| 726 | if (status & ATMEL_US_PARE) |
| 727 | port->icount.parity++; |
| 728 | if (status & ATMEL_US_FRAME) |
| 729 | port->icount.frame++; |
| 730 | if (status & ATMEL_US_OVRE) |
| 731 | port->icount.overrun++; |
| 732 | |
| 733 | status &= port->read_status_mask; |
| 734 | |
| 735 | if (status & ATMEL_US_RXBRK) |
| 736 | flg = TTY_BREAK; |
| 737 | else if (status & ATMEL_US_PARE) |
| 738 | flg = TTY_PARITY; |
| 739 | else if (status & ATMEL_US_FRAME) |
| 740 | flg = TTY_FRAME; |
| 741 | } |
| 742 | |
| 743 | |
| 744 | if (uart_handle_sysrq_char(port, c.ch)) |
| 745 | continue; |
| 746 | |
| 747 | uart_insert_char(port, status, ATMEL_US_OVRE, c.ch, flg); |
| 748 | } |
| 749 | |
| 750 | /* |
| 751 | * Drop the lock here since it might end up calling |
| 752 | * uart_start(), which takes the lock. |
| 753 | */ |
| 754 | spin_unlock(&port->lock); |
Alan Cox | ebd2c8f | 2009-09-19 13:13:28 -0700 | [diff] [blame] | 755 | tty_flip_buffer_push(port->state->port.tty); |
Remy Bohmer | 1ecc26b | 2008-02-08 04:21:05 -0800 | [diff] [blame] | 756 | spin_lock(&port->lock); |
| 757 | } |
| 758 | |
Chip Coldwell | a667061 | 2008-02-08 04:21:06 -0800 | [diff] [blame] | 759 | static void atmel_rx_from_dma(struct uart_port *port) |
| 760 | { |
Haavard Skinnemoen | c811ab8 | 2008-02-08 04:21:08 -0800 | [diff] [blame] | 761 | struct atmel_uart_port *atmel_port = to_atmel_uart_port(port); |
Alan Cox | ebd2c8f | 2009-09-19 13:13:28 -0700 | [diff] [blame] | 762 | struct tty_struct *tty = port->state->port.tty; |
Chip Coldwell | a667061 | 2008-02-08 04:21:06 -0800 | [diff] [blame] | 763 | struct atmel_dma_buffer *pdc; |
| 764 | int rx_idx = atmel_port->pdc_rx_idx; |
| 765 | unsigned int head; |
| 766 | unsigned int tail; |
| 767 | unsigned int count; |
| 768 | |
| 769 | do { |
| 770 | /* Reset the UART timeout early so that we don't miss one */ |
| 771 | UART_PUT_CR(port, ATMEL_US_STTTO); |
| 772 | |
| 773 | pdc = &atmel_port->pdc_rx[rx_idx]; |
| 774 | head = UART_GET_RPR(port) - pdc->dma_addr; |
| 775 | tail = pdc->ofs; |
| 776 | |
| 777 | /* If the PDC has switched buffers, RPR won't contain |
| 778 | * any address within the current buffer. Since head |
| 779 | * is unsigned, we just need a one-way comparison to |
| 780 | * find out. |
| 781 | * |
| 782 | * In this case, we just need to consume the entire |
| 783 | * buffer and resubmit it for DMA. This will clear the |
| 784 | * ENDRX bit as well, so that we can safely re-enable |
| 785 | * all interrupts below. |
| 786 | */ |
| 787 | head = min(head, pdc->dma_size); |
| 788 | |
| 789 | if (likely(head != tail)) { |
| 790 | dma_sync_single_for_cpu(port->dev, pdc->dma_addr, |
| 791 | pdc->dma_size, DMA_FROM_DEVICE); |
| 792 | |
| 793 | /* |
| 794 | * head will only wrap around when we recycle |
| 795 | * the DMA buffer, and when that happens, we |
| 796 | * explicitly set tail to 0. So head will |
| 797 | * always be greater than tail. |
| 798 | */ |
| 799 | count = head - tail; |
| 800 | |
| 801 | tty_insert_flip_string(tty, pdc->buf + pdc->ofs, count); |
| 802 | |
| 803 | dma_sync_single_for_device(port->dev, pdc->dma_addr, |
| 804 | pdc->dma_size, DMA_FROM_DEVICE); |
| 805 | |
| 806 | port->icount.rx += count; |
| 807 | pdc->ofs = head; |
| 808 | } |
| 809 | |
| 810 | /* |
| 811 | * If the current buffer is full, we need to check if |
| 812 | * the next one contains any additional data. |
| 813 | */ |
| 814 | if (head >= pdc->dma_size) { |
| 815 | pdc->ofs = 0; |
| 816 | UART_PUT_RNPR(port, pdc->dma_addr); |
| 817 | UART_PUT_RNCR(port, pdc->dma_size); |
| 818 | |
| 819 | rx_idx = !rx_idx; |
| 820 | atmel_port->pdc_rx_idx = rx_idx; |
| 821 | } |
| 822 | } while (head >= pdc->dma_size); |
| 823 | |
| 824 | /* |
| 825 | * Drop the lock here since it might end up calling |
| 826 | * uart_start(), which takes the lock. |
| 827 | */ |
| 828 | spin_unlock(&port->lock); |
| 829 | tty_flip_buffer_push(tty); |
| 830 | spin_lock(&port->lock); |
| 831 | |
| 832 | UART_PUT_IER(port, ATMEL_US_ENDRX | ATMEL_US_TIMEOUT); |
| 833 | } |
| 834 | |
Remy Bohmer | 1ecc26b | 2008-02-08 04:21:05 -0800 | [diff] [blame] | 835 | /* |
| 836 | * tasklet handling tty stuff outside the interrupt handler. |
| 837 | */ |
| 838 | static void atmel_tasklet_func(unsigned long data) |
| 839 | { |
| 840 | struct uart_port *port = (struct uart_port *)data; |
Haavard Skinnemoen | c811ab8 | 2008-02-08 04:21:08 -0800 | [diff] [blame] | 841 | struct atmel_uart_port *atmel_port = to_atmel_uart_port(port); |
Remy Bohmer | 1ecc26b | 2008-02-08 04:21:05 -0800 | [diff] [blame] | 842 | unsigned int status; |
| 843 | unsigned int status_change; |
| 844 | |
| 845 | /* The interrupt handler does not take the lock */ |
| 846 | spin_lock(&port->lock); |
| 847 | |
Chip Coldwell | a667061 | 2008-02-08 04:21:06 -0800 | [diff] [blame] | 848 | if (atmel_use_dma_tx(port)) |
| 849 | atmel_tx_dma(port); |
| 850 | else |
| 851 | atmel_tx_chars(port); |
Remy Bohmer | 1ecc26b | 2008-02-08 04:21:05 -0800 | [diff] [blame] | 852 | |
| 853 | status = atmel_port->irq_status; |
| 854 | status_change = status ^ atmel_port->irq_status_prev; |
| 855 | |
| 856 | if (status_change & (ATMEL_US_RI | ATMEL_US_DSR |
| 857 | | ATMEL_US_DCD | ATMEL_US_CTS)) { |
| 858 | /* TODO: All reads to CSR will clear these interrupts! */ |
| 859 | if (status_change & ATMEL_US_RI) |
| 860 | port->icount.rng++; |
| 861 | if (status_change & ATMEL_US_DSR) |
| 862 | port->icount.dsr++; |
| 863 | if (status_change & ATMEL_US_DCD) |
| 864 | uart_handle_dcd_change(port, !(status & ATMEL_US_DCD)); |
| 865 | if (status_change & ATMEL_US_CTS) |
| 866 | uart_handle_cts_change(port, !(status & ATMEL_US_CTS)); |
| 867 | |
Alan Cox | bdc04e3 | 2009-09-19 13:13:31 -0700 | [diff] [blame] | 868 | wake_up_interruptible(&port->state->port.delta_msr_wait); |
Remy Bohmer | 1ecc26b | 2008-02-08 04:21:05 -0800 | [diff] [blame] | 869 | |
| 870 | atmel_port->irq_status_prev = status; |
| 871 | } |
| 872 | |
Chip Coldwell | a667061 | 2008-02-08 04:21:06 -0800 | [diff] [blame] | 873 | if (atmel_use_dma_rx(port)) |
| 874 | atmel_rx_from_dma(port); |
| 875 | else |
| 876 | atmel_rx_from_ring(port); |
Remy Bohmer | 1ecc26b | 2008-02-08 04:21:05 -0800 | [diff] [blame] | 877 | |
| 878 | spin_unlock(&port->lock); |
| 879 | } |
| 880 | |
Andrew Victor | 1e6c9c2 | 2006-01-10 16:59:27 +0000 | [diff] [blame] | 881 | /* |
| 882 | * Perform initialization and enable port for reception |
| 883 | */ |
Haavard Skinnemoen | 7192f92 | 2006-10-04 16:02:05 +0200 | [diff] [blame] | 884 | static int atmel_startup(struct uart_port *port) |
Andrew Victor | 1e6c9c2 | 2006-01-10 16:59:27 +0000 | [diff] [blame] | 885 | { |
Haavard Skinnemoen | c811ab8 | 2008-02-08 04:21:08 -0800 | [diff] [blame] | 886 | struct atmel_uart_port *atmel_port = to_atmel_uart_port(port); |
Alan Cox | ebd2c8f | 2009-09-19 13:13:28 -0700 | [diff] [blame] | 887 | struct tty_struct *tty = port->state->port.tty; |
Andrew Victor | 1e6c9c2 | 2006-01-10 16:59:27 +0000 | [diff] [blame] | 888 | int retval; |
| 889 | |
| 890 | /* |
| 891 | * Ensure that no interrupts are enabled otherwise when |
| 892 | * request_irq() is called we could get stuck trying to |
| 893 | * handle an unexpected interrupt |
| 894 | */ |
| 895 | UART_PUT_IDR(port, -1); |
| 896 | |
| 897 | /* |
| 898 | * Allocate the IRQ |
| 899 | */ |
Remy Bohmer | b843aa2 | 2008-02-08 04:21:01 -0800 | [diff] [blame] | 900 | retval = request_irq(port->irq, atmel_interrupt, IRQF_SHARED, |
Haavard Skinnemoen | ae16106 | 2008-02-08 04:21:08 -0800 | [diff] [blame] | 901 | tty ? tty->name : "atmel_serial", port); |
Andrew Victor | 1e6c9c2 | 2006-01-10 16:59:27 +0000 | [diff] [blame] | 902 | if (retval) { |
Haavard Skinnemoen | 7192f92 | 2006-10-04 16:02:05 +0200 | [diff] [blame] | 903 | printk("atmel_serial: atmel_startup - Can't get irq\n"); |
Andrew Victor | 1e6c9c2 | 2006-01-10 16:59:27 +0000 | [diff] [blame] | 904 | return retval; |
| 905 | } |
| 906 | |
| 907 | /* |
Chip Coldwell | a667061 | 2008-02-08 04:21:06 -0800 | [diff] [blame] | 908 | * Initialize DMA (if necessary) |
| 909 | */ |
| 910 | if (atmel_use_dma_rx(port)) { |
| 911 | int i; |
| 912 | |
| 913 | for (i = 0; i < 2; i++) { |
| 914 | struct atmel_dma_buffer *pdc = &atmel_port->pdc_rx[i]; |
| 915 | |
| 916 | pdc->buf = kmalloc(PDC_BUFFER_SIZE, GFP_KERNEL); |
| 917 | if (pdc->buf == NULL) { |
| 918 | if (i != 0) { |
| 919 | dma_unmap_single(port->dev, |
| 920 | atmel_port->pdc_rx[0].dma_addr, |
| 921 | PDC_BUFFER_SIZE, |
| 922 | DMA_FROM_DEVICE); |
| 923 | kfree(atmel_port->pdc_rx[0].buf); |
| 924 | } |
| 925 | free_irq(port->irq, port); |
| 926 | return -ENOMEM; |
| 927 | } |
| 928 | pdc->dma_addr = dma_map_single(port->dev, |
| 929 | pdc->buf, |
| 930 | PDC_BUFFER_SIZE, |
| 931 | DMA_FROM_DEVICE); |
| 932 | pdc->dma_size = PDC_BUFFER_SIZE; |
| 933 | pdc->ofs = 0; |
| 934 | } |
| 935 | |
| 936 | atmel_port->pdc_rx_idx = 0; |
| 937 | |
| 938 | UART_PUT_RPR(port, atmel_port->pdc_rx[0].dma_addr); |
| 939 | UART_PUT_RCR(port, PDC_BUFFER_SIZE); |
| 940 | |
| 941 | UART_PUT_RNPR(port, atmel_port->pdc_rx[1].dma_addr); |
| 942 | UART_PUT_RNCR(port, PDC_BUFFER_SIZE); |
| 943 | } |
| 944 | if (atmel_use_dma_tx(port)) { |
| 945 | struct atmel_dma_buffer *pdc = &atmel_port->pdc_tx; |
Alan Cox | ebd2c8f | 2009-09-19 13:13:28 -0700 | [diff] [blame] | 946 | struct circ_buf *xmit = &port->state->xmit; |
Chip Coldwell | a667061 | 2008-02-08 04:21:06 -0800 | [diff] [blame] | 947 | |
| 948 | pdc->buf = xmit->buf; |
| 949 | pdc->dma_addr = dma_map_single(port->dev, |
| 950 | pdc->buf, |
| 951 | UART_XMIT_SIZE, |
| 952 | DMA_TO_DEVICE); |
| 953 | pdc->dma_size = UART_XMIT_SIZE; |
| 954 | pdc->ofs = 0; |
| 955 | } |
| 956 | |
| 957 | /* |
Andrew Victor | 1e6c9c2 | 2006-01-10 16:59:27 +0000 | [diff] [blame] | 958 | * If there is a specific "open" function (to register |
| 959 | * control line interrupts) |
| 960 | */ |
Haavard Skinnemoen | 71f2e2b | 2006-10-04 16:02:07 +0200 | [diff] [blame] | 961 | if (atmel_open_hook) { |
| 962 | retval = atmel_open_hook(port); |
Andrew Victor | 1e6c9c2 | 2006-01-10 16:59:27 +0000 | [diff] [blame] | 963 | if (retval) { |
| 964 | free_irq(port->irq, port); |
| 965 | return retval; |
| 966 | } |
| 967 | } |
| 968 | |
Atsushi Nemoto | 27c0c8e | 2009-02-18 14:48:28 -0800 | [diff] [blame] | 969 | /* Save current CSR for comparison in atmel_tasklet_func() */ |
| 970 | atmel_port->irq_status_prev = UART_GET_CSR(port); |
| 971 | atmel_port->irq_status = atmel_port->irq_status_prev; |
| 972 | |
Andrew Victor | 1e6c9c2 | 2006-01-10 16:59:27 +0000 | [diff] [blame] | 973 | /* |
| 974 | * Finally, enable the serial port |
| 975 | */ |
Haavard Skinnemoen | 7192f92 | 2006-10-04 16:02:05 +0200 | [diff] [blame] | 976 | UART_PUT_CR(port, ATMEL_US_RSTSTA | ATMEL_US_RSTRX); |
Remy Bohmer | b843aa2 | 2008-02-08 04:21:01 -0800 | [diff] [blame] | 977 | /* enable xmit & rcvr */ |
| 978 | UART_PUT_CR(port, ATMEL_US_TXEN | ATMEL_US_RXEN); |
Andrew Victor | afefc41 | 2006-06-19 19:53:19 +0100 | [diff] [blame] | 979 | |
Chip Coldwell | a667061 | 2008-02-08 04:21:06 -0800 | [diff] [blame] | 980 | if (atmel_use_dma_rx(port)) { |
| 981 | /* set UART timeout */ |
| 982 | UART_PUT_RTOR(port, PDC_RX_TIMEOUT); |
| 983 | UART_PUT_CR(port, ATMEL_US_STTTO); |
| 984 | |
| 985 | UART_PUT_IER(port, ATMEL_US_ENDRX | ATMEL_US_TIMEOUT); |
| 986 | /* enable PDC controller */ |
| 987 | UART_PUT_PTCR(port, ATMEL_PDC_RXTEN); |
| 988 | } else { |
| 989 | /* enable receive only */ |
| 990 | UART_PUT_IER(port, ATMEL_US_RXRDY); |
| 991 | } |
Andrew Victor | afefc41 | 2006-06-19 19:53:19 +0100 | [diff] [blame] | 992 | |
Andrew Victor | 1e6c9c2 | 2006-01-10 16:59:27 +0000 | [diff] [blame] | 993 | return 0; |
| 994 | } |
| 995 | |
| 996 | /* |
| 997 | * Disable the port |
| 998 | */ |
Haavard Skinnemoen | 7192f92 | 2006-10-04 16:02:05 +0200 | [diff] [blame] | 999 | static void atmel_shutdown(struct uart_port *port) |
Andrew Victor | 1e6c9c2 | 2006-01-10 16:59:27 +0000 | [diff] [blame] | 1000 | { |
Haavard Skinnemoen | c811ab8 | 2008-02-08 04:21:08 -0800 | [diff] [blame] | 1001 | struct atmel_uart_port *atmel_port = to_atmel_uart_port(port); |
Chip Coldwell | a667061 | 2008-02-08 04:21:06 -0800 | [diff] [blame] | 1002 | /* |
| 1003 | * Ensure everything is stopped. |
| 1004 | */ |
| 1005 | atmel_stop_rx(port); |
| 1006 | atmel_stop_tx(port); |
| 1007 | |
| 1008 | /* |
| 1009 | * Shut-down the DMA. |
| 1010 | */ |
| 1011 | if (atmel_use_dma_rx(port)) { |
| 1012 | int i; |
| 1013 | |
| 1014 | for (i = 0; i < 2; i++) { |
| 1015 | struct atmel_dma_buffer *pdc = &atmel_port->pdc_rx[i]; |
| 1016 | |
| 1017 | dma_unmap_single(port->dev, |
| 1018 | pdc->dma_addr, |
| 1019 | pdc->dma_size, |
| 1020 | DMA_FROM_DEVICE); |
| 1021 | kfree(pdc->buf); |
| 1022 | } |
| 1023 | } |
| 1024 | if (atmel_use_dma_tx(port)) { |
| 1025 | struct atmel_dma_buffer *pdc = &atmel_port->pdc_tx; |
| 1026 | |
| 1027 | dma_unmap_single(port->dev, |
| 1028 | pdc->dma_addr, |
| 1029 | pdc->dma_size, |
| 1030 | DMA_TO_DEVICE); |
| 1031 | } |
| 1032 | |
Andrew Victor | 1e6c9c2 | 2006-01-10 16:59:27 +0000 | [diff] [blame] | 1033 | /* |
| 1034 | * Disable all interrupts, port and break condition. |
| 1035 | */ |
Haavard Skinnemoen | 7192f92 | 2006-10-04 16:02:05 +0200 | [diff] [blame] | 1036 | UART_PUT_CR(port, ATMEL_US_RSTSTA); |
Andrew Victor | 1e6c9c2 | 2006-01-10 16:59:27 +0000 | [diff] [blame] | 1037 | UART_PUT_IDR(port, -1); |
| 1038 | |
| 1039 | /* |
| 1040 | * Free the interrupt |
| 1041 | */ |
| 1042 | free_irq(port->irq, port); |
| 1043 | |
| 1044 | /* |
| 1045 | * If there is a specific "close" function (to unregister |
| 1046 | * control line interrupts) |
| 1047 | */ |
Haavard Skinnemoen | 71f2e2b | 2006-10-04 16:02:07 +0200 | [diff] [blame] | 1048 | if (atmel_close_hook) |
| 1049 | atmel_close_hook(port); |
Andrew Victor | 1e6c9c2 | 2006-01-10 16:59:27 +0000 | [diff] [blame] | 1050 | } |
| 1051 | |
| 1052 | /* |
Haavard Skinnemoen | 9afd561 | 2008-07-16 21:52:46 +0100 | [diff] [blame] | 1053 | * Flush any TX data submitted for DMA. Called when the TX circular |
| 1054 | * buffer is reset. |
| 1055 | */ |
| 1056 | static void atmel_flush_buffer(struct uart_port *port) |
| 1057 | { |
| 1058 | struct atmel_uart_port *atmel_port = to_atmel_uart_port(port); |
| 1059 | |
| 1060 | if (atmel_use_dma_tx(port)) { |
| 1061 | UART_PUT_TCR(port, 0); |
| 1062 | atmel_port->pdc_tx.ofs = 0; |
| 1063 | } |
| 1064 | } |
| 1065 | |
| 1066 | /* |
Andrew Victor | 1e6c9c2 | 2006-01-10 16:59:27 +0000 | [diff] [blame] | 1067 | * Power / Clock management. |
| 1068 | */ |
Remy Bohmer | b843aa2 | 2008-02-08 04:21:01 -0800 | [diff] [blame] | 1069 | static void atmel_serial_pm(struct uart_port *port, unsigned int state, |
| 1070 | unsigned int oldstate) |
Andrew Victor | 1e6c9c2 | 2006-01-10 16:59:27 +0000 | [diff] [blame] | 1071 | { |
Haavard Skinnemoen | c811ab8 | 2008-02-08 04:21:08 -0800 | [diff] [blame] | 1072 | struct atmel_uart_port *atmel_port = to_atmel_uart_port(port); |
Andrew Victor | afefc41 | 2006-06-19 19:53:19 +0100 | [diff] [blame] | 1073 | |
Andrew Victor | 1e6c9c2 | 2006-01-10 16:59:27 +0000 | [diff] [blame] | 1074 | switch (state) { |
Remy Bohmer | b843aa2 | 2008-02-08 04:21:01 -0800 | [diff] [blame] | 1075 | case 0: |
| 1076 | /* |
| 1077 | * Enable the peripheral clock for this serial port. |
| 1078 | * This is called on uart_open() or a resume event. |
| 1079 | */ |
| 1080 | clk_enable(atmel_port->clk); |
Anti Sullin | f05596d | 2008-09-22 13:57:54 -0700 | [diff] [blame] | 1081 | |
| 1082 | /* re-enable interrupts if we disabled some on suspend */ |
| 1083 | UART_PUT_IER(port, atmel_port->backup_imr); |
Remy Bohmer | b843aa2 | 2008-02-08 04:21:01 -0800 | [diff] [blame] | 1084 | break; |
| 1085 | case 3: |
Anti Sullin | f05596d | 2008-09-22 13:57:54 -0700 | [diff] [blame] | 1086 | /* Back up the interrupt mask and disable all interrupts */ |
| 1087 | atmel_port->backup_imr = UART_GET_IMR(port); |
| 1088 | UART_PUT_IDR(port, -1); |
| 1089 | |
Remy Bohmer | b843aa2 | 2008-02-08 04:21:01 -0800 | [diff] [blame] | 1090 | /* |
| 1091 | * Disable the peripheral clock for this serial port. |
| 1092 | * This is called on uart_close() or a suspend event. |
| 1093 | */ |
| 1094 | clk_disable(atmel_port->clk); |
| 1095 | break; |
| 1096 | default: |
| 1097 | printk(KERN_ERR "atmel_serial: unknown pm %d\n", state); |
Andrew Victor | 1e6c9c2 | 2006-01-10 16:59:27 +0000 | [diff] [blame] | 1098 | } |
| 1099 | } |
| 1100 | |
| 1101 | /* |
| 1102 | * Change the port parameters |
| 1103 | */ |
Remy Bohmer | b843aa2 | 2008-02-08 04:21:01 -0800 | [diff] [blame] | 1104 | static void atmel_set_termios(struct uart_port *port, struct ktermios *termios, |
| 1105 | struct ktermios *old) |
Andrew Victor | 1e6c9c2 | 2006-01-10 16:59:27 +0000 | [diff] [blame] | 1106 | { |
| 1107 | unsigned long flags; |
| 1108 | unsigned int mode, imr, quot, baud; |
Claudio Scordino | e8faff7 | 2010-05-03 13:31:28 +0100 | [diff] [blame^] | 1109 | struct atmel_uart_port *atmel_port = to_atmel_uart_port(port); |
Andrew Victor | 1e6c9c2 | 2006-01-10 16:59:27 +0000 | [diff] [blame] | 1110 | |
Andrew Victor | 03abeac | 2007-05-03 12:26:24 +0100 | [diff] [blame] | 1111 | /* Get current mode register */ |
Remy Bohmer | b843aa2 | 2008-02-08 04:21:01 -0800 | [diff] [blame] | 1112 | mode = UART_GET_MR(port) & ~(ATMEL_US_USCLKS | ATMEL_US_CHRL |
Peter Ma | 8e706c4 | 2009-03-31 10:31:02 -0700 | [diff] [blame] | 1113 | | ATMEL_US_NBSTOP | ATMEL_US_PAR |
| 1114 | | ATMEL_US_USMODE); |
Andrew Victor | 03abeac | 2007-05-03 12:26:24 +0100 | [diff] [blame] | 1115 | |
Remy Bohmer | b843aa2 | 2008-02-08 04:21:01 -0800 | [diff] [blame] | 1116 | baud = uart_get_baud_rate(port, termios, old, 0, port->uartclk / 16); |
Andrew Victor | 1e6c9c2 | 2006-01-10 16:59:27 +0000 | [diff] [blame] | 1117 | quot = uart_get_divisor(port, baud); |
| 1118 | |
Remy Bohmer | b843aa2 | 2008-02-08 04:21:01 -0800 | [diff] [blame] | 1119 | if (quot > 65535) { /* BRGR is 16-bit, so switch to slower clock */ |
Andrew Victor | 03abeac | 2007-05-03 12:26:24 +0100 | [diff] [blame] | 1120 | quot /= 8; |
| 1121 | mode |= ATMEL_US_USCLKS_MCK_DIV8; |
| 1122 | } |
Andrew Victor | 1e6c9c2 | 2006-01-10 16:59:27 +0000 | [diff] [blame] | 1123 | |
| 1124 | /* byte size */ |
| 1125 | switch (termios->c_cflag & CSIZE) { |
| 1126 | case CS5: |
Haavard Skinnemoen | 7192f92 | 2006-10-04 16:02:05 +0200 | [diff] [blame] | 1127 | mode |= ATMEL_US_CHRL_5; |
Andrew Victor | 1e6c9c2 | 2006-01-10 16:59:27 +0000 | [diff] [blame] | 1128 | break; |
| 1129 | case CS6: |
Haavard Skinnemoen | 7192f92 | 2006-10-04 16:02:05 +0200 | [diff] [blame] | 1130 | mode |= ATMEL_US_CHRL_6; |
Andrew Victor | 1e6c9c2 | 2006-01-10 16:59:27 +0000 | [diff] [blame] | 1131 | break; |
| 1132 | case CS7: |
Haavard Skinnemoen | 7192f92 | 2006-10-04 16:02:05 +0200 | [diff] [blame] | 1133 | mode |= ATMEL_US_CHRL_7; |
Andrew Victor | 1e6c9c2 | 2006-01-10 16:59:27 +0000 | [diff] [blame] | 1134 | break; |
| 1135 | default: |
Haavard Skinnemoen | 7192f92 | 2006-10-04 16:02:05 +0200 | [diff] [blame] | 1136 | mode |= ATMEL_US_CHRL_8; |
Andrew Victor | 1e6c9c2 | 2006-01-10 16:59:27 +0000 | [diff] [blame] | 1137 | break; |
| 1138 | } |
| 1139 | |
| 1140 | /* stop bits */ |
| 1141 | if (termios->c_cflag & CSTOPB) |
Haavard Skinnemoen | 7192f92 | 2006-10-04 16:02:05 +0200 | [diff] [blame] | 1142 | mode |= ATMEL_US_NBSTOP_2; |
Andrew Victor | 1e6c9c2 | 2006-01-10 16:59:27 +0000 | [diff] [blame] | 1143 | |
| 1144 | /* parity */ |
| 1145 | if (termios->c_cflag & PARENB) { |
Remy Bohmer | b843aa2 | 2008-02-08 04:21:01 -0800 | [diff] [blame] | 1146 | /* Mark or Space parity */ |
| 1147 | if (termios->c_cflag & CMSPAR) { |
Andrew Victor | 1e6c9c2 | 2006-01-10 16:59:27 +0000 | [diff] [blame] | 1148 | if (termios->c_cflag & PARODD) |
Haavard Skinnemoen | 7192f92 | 2006-10-04 16:02:05 +0200 | [diff] [blame] | 1149 | mode |= ATMEL_US_PAR_MARK; |
Andrew Victor | 1e6c9c2 | 2006-01-10 16:59:27 +0000 | [diff] [blame] | 1150 | else |
Haavard Skinnemoen | 7192f92 | 2006-10-04 16:02:05 +0200 | [diff] [blame] | 1151 | mode |= ATMEL_US_PAR_SPACE; |
Remy Bohmer | b843aa2 | 2008-02-08 04:21:01 -0800 | [diff] [blame] | 1152 | } else if (termios->c_cflag & PARODD) |
Haavard Skinnemoen | 7192f92 | 2006-10-04 16:02:05 +0200 | [diff] [blame] | 1153 | mode |= ATMEL_US_PAR_ODD; |
Andrew Victor | 1e6c9c2 | 2006-01-10 16:59:27 +0000 | [diff] [blame] | 1154 | else |
Haavard Skinnemoen | 7192f92 | 2006-10-04 16:02:05 +0200 | [diff] [blame] | 1155 | mode |= ATMEL_US_PAR_EVEN; |
Remy Bohmer | b843aa2 | 2008-02-08 04:21:01 -0800 | [diff] [blame] | 1156 | } else |
Haavard Skinnemoen | 7192f92 | 2006-10-04 16:02:05 +0200 | [diff] [blame] | 1157 | mode |= ATMEL_US_PAR_NONE; |
Andrew Victor | 1e6c9c2 | 2006-01-10 16:59:27 +0000 | [diff] [blame] | 1158 | |
Peter Ma | 8e706c4 | 2009-03-31 10:31:02 -0700 | [diff] [blame] | 1159 | /* hardware handshake (RTS/CTS) */ |
| 1160 | if (termios->c_cflag & CRTSCTS) |
| 1161 | mode |= ATMEL_US_USMODE_HWHS; |
| 1162 | else |
| 1163 | mode |= ATMEL_US_USMODE_NORMAL; |
| 1164 | |
Andrew Victor | 1e6c9c2 | 2006-01-10 16:59:27 +0000 | [diff] [blame] | 1165 | spin_lock_irqsave(&port->lock, flags); |
| 1166 | |
Haavard Skinnemoen | 7192f92 | 2006-10-04 16:02:05 +0200 | [diff] [blame] | 1167 | port->read_status_mask = ATMEL_US_OVRE; |
Andrew Victor | 1e6c9c2 | 2006-01-10 16:59:27 +0000 | [diff] [blame] | 1168 | if (termios->c_iflag & INPCK) |
Haavard Skinnemoen | 7192f92 | 2006-10-04 16:02:05 +0200 | [diff] [blame] | 1169 | port->read_status_mask |= (ATMEL_US_FRAME | ATMEL_US_PARE); |
Andrew Victor | 1e6c9c2 | 2006-01-10 16:59:27 +0000 | [diff] [blame] | 1170 | if (termios->c_iflag & (BRKINT | PARMRK)) |
Haavard Skinnemoen | 7192f92 | 2006-10-04 16:02:05 +0200 | [diff] [blame] | 1171 | port->read_status_mask |= ATMEL_US_RXBRK; |
Andrew Victor | 1e6c9c2 | 2006-01-10 16:59:27 +0000 | [diff] [blame] | 1172 | |
Chip Coldwell | a667061 | 2008-02-08 04:21:06 -0800 | [diff] [blame] | 1173 | if (atmel_use_dma_rx(port)) |
| 1174 | /* need to enable error interrupts */ |
| 1175 | UART_PUT_IER(port, port->read_status_mask); |
| 1176 | |
Andrew Victor | 1e6c9c2 | 2006-01-10 16:59:27 +0000 | [diff] [blame] | 1177 | /* |
| 1178 | * Characters to ignore |
| 1179 | */ |
| 1180 | port->ignore_status_mask = 0; |
| 1181 | if (termios->c_iflag & IGNPAR) |
Haavard Skinnemoen | 7192f92 | 2006-10-04 16:02:05 +0200 | [diff] [blame] | 1182 | port->ignore_status_mask |= (ATMEL_US_FRAME | ATMEL_US_PARE); |
Andrew Victor | 1e6c9c2 | 2006-01-10 16:59:27 +0000 | [diff] [blame] | 1183 | if (termios->c_iflag & IGNBRK) { |
Haavard Skinnemoen | 7192f92 | 2006-10-04 16:02:05 +0200 | [diff] [blame] | 1184 | port->ignore_status_mask |= ATMEL_US_RXBRK; |
Andrew Victor | 1e6c9c2 | 2006-01-10 16:59:27 +0000 | [diff] [blame] | 1185 | /* |
| 1186 | * If we're ignoring parity and break indicators, |
| 1187 | * ignore overruns too (for real raw support). |
| 1188 | */ |
| 1189 | if (termios->c_iflag & IGNPAR) |
Haavard Skinnemoen | 7192f92 | 2006-10-04 16:02:05 +0200 | [diff] [blame] | 1190 | port->ignore_status_mask |= ATMEL_US_OVRE; |
Andrew Victor | 1e6c9c2 | 2006-01-10 16:59:27 +0000 | [diff] [blame] | 1191 | } |
Remy Bohmer | b843aa2 | 2008-02-08 04:21:01 -0800 | [diff] [blame] | 1192 | /* TODO: Ignore all characters if CREAD is set.*/ |
Andrew Victor | 1e6c9c2 | 2006-01-10 16:59:27 +0000 | [diff] [blame] | 1193 | |
| 1194 | /* update the per-port timeout */ |
| 1195 | uart_update_timeout(port, termios->c_cflag, baud); |
| 1196 | |
Haavard Skinnemoen | 0ccad87 | 2009-06-16 17:02:03 +0100 | [diff] [blame] | 1197 | /* |
| 1198 | * save/disable interrupts. The tty layer will ensure that the |
| 1199 | * transmitter is empty if requested by the caller, so there's |
| 1200 | * no need to wait for it here. |
| 1201 | */ |
Remy Bohmer | b843aa2 | 2008-02-08 04:21:01 -0800 | [diff] [blame] | 1202 | imr = UART_GET_IMR(port); |
| 1203 | UART_PUT_IDR(port, -1); |
Andrew Victor | 1e6c9c2 | 2006-01-10 16:59:27 +0000 | [diff] [blame] | 1204 | |
| 1205 | /* disable receiver and transmitter */ |
Haavard Skinnemoen | 7192f92 | 2006-10-04 16:02:05 +0200 | [diff] [blame] | 1206 | UART_PUT_CR(port, ATMEL_US_TXDIS | ATMEL_US_RXDIS); |
Andrew Victor | 1e6c9c2 | 2006-01-10 16:59:27 +0000 | [diff] [blame] | 1207 | |
Claudio Scordino | e8faff7 | 2010-05-03 13:31:28 +0100 | [diff] [blame^] | 1208 | /* Resetting serial mode to RS232 (0x0) */ |
| 1209 | mode &= ~ATMEL_US_USMODE; |
| 1210 | |
| 1211 | if (atmel_port->rs485.flags & SER_RS485_ENABLED) { |
| 1212 | dev_dbg(port->dev, "Setting UART to RS485\n"); |
| 1213 | UART_PUT_TTGR(port, atmel_port->rs485.delay_rts_before_send); |
| 1214 | mode |= ATMEL_US_USMODE_RS485; |
| 1215 | } else { |
| 1216 | dev_dbg(port->dev, "Setting UART to RS232\n"); |
| 1217 | } |
| 1218 | |
Andrew Victor | 1e6c9c2 | 2006-01-10 16:59:27 +0000 | [diff] [blame] | 1219 | /* set the parity, stop bits and data size */ |
| 1220 | UART_PUT_MR(port, mode); |
| 1221 | |
| 1222 | /* set the baud rate */ |
| 1223 | UART_PUT_BRGR(port, quot); |
Haavard Skinnemoen | 7192f92 | 2006-10-04 16:02:05 +0200 | [diff] [blame] | 1224 | UART_PUT_CR(port, ATMEL_US_RSTSTA | ATMEL_US_RSTRX); |
| 1225 | UART_PUT_CR(port, ATMEL_US_TXEN | ATMEL_US_RXEN); |
Andrew Victor | 1e6c9c2 | 2006-01-10 16:59:27 +0000 | [diff] [blame] | 1226 | |
| 1227 | /* restore interrupts */ |
| 1228 | UART_PUT_IER(port, imr); |
| 1229 | |
| 1230 | /* CTS flow-control and modem-status interrupts */ |
| 1231 | if (UART_ENABLE_MS(port, termios->c_cflag)) |
| 1232 | port->ops->enable_ms(port); |
| 1233 | |
| 1234 | spin_unlock_irqrestore(&port->lock, flags); |
| 1235 | } |
| 1236 | |
| 1237 | /* |
| 1238 | * Return string describing the specified port |
| 1239 | */ |
Haavard Skinnemoen | 7192f92 | 2006-10-04 16:02:05 +0200 | [diff] [blame] | 1240 | static const char *atmel_type(struct uart_port *port) |
Andrew Victor | 1e6c9c2 | 2006-01-10 16:59:27 +0000 | [diff] [blame] | 1241 | { |
Haavard Skinnemoen | 9ab4f88 | 2006-10-04 16:02:06 +0200 | [diff] [blame] | 1242 | return (port->type == PORT_ATMEL) ? "ATMEL_SERIAL" : NULL; |
Andrew Victor | 1e6c9c2 | 2006-01-10 16:59:27 +0000 | [diff] [blame] | 1243 | } |
| 1244 | |
| 1245 | /* |
| 1246 | * Release the memory region(s) being used by 'port'. |
| 1247 | */ |
Haavard Skinnemoen | 7192f92 | 2006-10-04 16:02:05 +0200 | [diff] [blame] | 1248 | static void atmel_release_port(struct uart_port *port) |
Andrew Victor | 1e6c9c2 | 2006-01-10 16:59:27 +0000 | [diff] [blame] | 1249 | { |
Andrew Victor | afefc41 | 2006-06-19 19:53:19 +0100 | [diff] [blame] | 1250 | struct platform_device *pdev = to_platform_device(port->dev); |
| 1251 | int size = pdev->resource[0].end - pdev->resource[0].start + 1; |
| 1252 | |
| 1253 | release_mem_region(port->mapbase, size); |
| 1254 | |
| 1255 | if (port->flags & UPF_IOREMAP) { |
| 1256 | iounmap(port->membase); |
| 1257 | port->membase = NULL; |
| 1258 | } |
Andrew Victor | 1e6c9c2 | 2006-01-10 16:59:27 +0000 | [diff] [blame] | 1259 | } |
| 1260 | |
| 1261 | /* |
| 1262 | * Request the memory region(s) being used by 'port'. |
| 1263 | */ |
Haavard Skinnemoen | 7192f92 | 2006-10-04 16:02:05 +0200 | [diff] [blame] | 1264 | static int atmel_request_port(struct uart_port *port) |
Andrew Victor | 1e6c9c2 | 2006-01-10 16:59:27 +0000 | [diff] [blame] | 1265 | { |
Andrew Victor | afefc41 | 2006-06-19 19:53:19 +0100 | [diff] [blame] | 1266 | struct platform_device *pdev = to_platform_device(port->dev); |
| 1267 | int size = pdev->resource[0].end - pdev->resource[0].start + 1; |
Andrew Victor | 1e6c9c2 | 2006-01-10 16:59:27 +0000 | [diff] [blame] | 1268 | |
Haavard Skinnemoen | 7192f92 | 2006-10-04 16:02:05 +0200 | [diff] [blame] | 1269 | if (!request_mem_region(port->mapbase, size, "atmel_serial")) |
Andrew Victor | afefc41 | 2006-06-19 19:53:19 +0100 | [diff] [blame] | 1270 | return -EBUSY; |
| 1271 | |
| 1272 | if (port->flags & UPF_IOREMAP) { |
| 1273 | port->membase = ioremap(port->mapbase, size); |
| 1274 | if (port->membase == NULL) { |
| 1275 | release_mem_region(port->mapbase, size); |
| 1276 | return -ENOMEM; |
| 1277 | } |
| 1278 | } |
| 1279 | |
| 1280 | return 0; |
Andrew Victor | 1e6c9c2 | 2006-01-10 16:59:27 +0000 | [diff] [blame] | 1281 | } |
| 1282 | |
| 1283 | /* |
| 1284 | * Configure/autoconfigure the port. |
| 1285 | */ |
Haavard Skinnemoen | 7192f92 | 2006-10-04 16:02:05 +0200 | [diff] [blame] | 1286 | static void atmel_config_port(struct uart_port *port, int flags) |
Andrew Victor | 1e6c9c2 | 2006-01-10 16:59:27 +0000 | [diff] [blame] | 1287 | { |
| 1288 | if (flags & UART_CONFIG_TYPE) { |
Haavard Skinnemoen | 9ab4f88 | 2006-10-04 16:02:06 +0200 | [diff] [blame] | 1289 | port->type = PORT_ATMEL; |
Haavard Skinnemoen | 7192f92 | 2006-10-04 16:02:05 +0200 | [diff] [blame] | 1290 | atmel_request_port(port); |
Andrew Victor | 1e6c9c2 | 2006-01-10 16:59:27 +0000 | [diff] [blame] | 1291 | } |
| 1292 | } |
| 1293 | |
| 1294 | /* |
| 1295 | * Verify the new serial_struct (for TIOCSSERIAL). |
| 1296 | */ |
Haavard Skinnemoen | 7192f92 | 2006-10-04 16:02:05 +0200 | [diff] [blame] | 1297 | static int atmel_verify_port(struct uart_port *port, struct serial_struct *ser) |
Andrew Victor | 1e6c9c2 | 2006-01-10 16:59:27 +0000 | [diff] [blame] | 1298 | { |
| 1299 | int ret = 0; |
Haavard Skinnemoen | 9ab4f88 | 2006-10-04 16:02:06 +0200 | [diff] [blame] | 1300 | if (ser->type != PORT_UNKNOWN && ser->type != PORT_ATMEL) |
Andrew Victor | 1e6c9c2 | 2006-01-10 16:59:27 +0000 | [diff] [blame] | 1301 | ret = -EINVAL; |
| 1302 | if (port->irq != ser->irq) |
| 1303 | ret = -EINVAL; |
| 1304 | if (ser->io_type != SERIAL_IO_MEM) |
| 1305 | ret = -EINVAL; |
| 1306 | if (port->uartclk / 16 != ser->baud_base) |
| 1307 | ret = -EINVAL; |
| 1308 | if ((void *)port->mapbase != ser->iomem_base) |
| 1309 | ret = -EINVAL; |
| 1310 | if (port->iobase != ser->port) |
| 1311 | ret = -EINVAL; |
| 1312 | if (ser->hub6 != 0) |
| 1313 | ret = -EINVAL; |
| 1314 | return ret; |
| 1315 | } |
| 1316 | |
Albin Tonnerre | 8fe2d54 | 2009-12-09 12:31:32 -0800 | [diff] [blame] | 1317 | #ifdef CONFIG_CONSOLE_POLL |
| 1318 | static int atmel_poll_get_char(struct uart_port *port) |
| 1319 | { |
| 1320 | while (!(UART_GET_CSR(port) & ATMEL_US_RXRDY)) |
| 1321 | cpu_relax(); |
| 1322 | |
| 1323 | return UART_GET_CHAR(port); |
| 1324 | } |
| 1325 | |
| 1326 | static void atmel_poll_put_char(struct uart_port *port, unsigned char ch) |
| 1327 | { |
| 1328 | while (!(UART_GET_CSR(port) & ATMEL_US_TXRDY)) |
| 1329 | cpu_relax(); |
| 1330 | |
| 1331 | UART_PUT_CHAR(port, ch); |
| 1332 | } |
| 1333 | #endif |
| 1334 | |
Claudio Scordino | e8faff7 | 2010-05-03 13:31:28 +0100 | [diff] [blame^] | 1335 | static int |
| 1336 | atmel_ioctl(struct uart_port *port, unsigned int cmd, unsigned long arg) |
| 1337 | { |
| 1338 | struct serial_rs485 rs485conf; |
| 1339 | |
| 1340 | switch (cmd) { |
| 1341 | case TIOCSRS485: |
| 1342 | if (copy_from_user(&rs485conf, (struct serial_rs485 *) arg, |
| 1343 | sizeof(rs485conf))) |
| 1344 | return -EFAULT; |
| 1345 | |
| 1346 | atmel_config_rs485(port, &rs485conf); |
| 1347 | break; |
| 1348 | |
| 1349 | case TIOCGRS485: |
| 1350 | if (copy_to_user((struct serial_rs485 *) arg, |
| 1351 | &(to_atmel_uart_port(port)->rs485), |
| 1352 | sizeof(rs485conf))) |
| 1353 | return -EFAULT; |
| 1354 | break; |
| 1355 | |
| 1356 | default: |
| 1357 | return -ENOIOCTLCMD; |
| 1358 | } |
| 1359 | return 0; |
| 1360 | } |
| 1361 | |
| 1362 | |
| 1363 | |
Haavard Skinnemoen | 7192f92 | 2006-10-04 16:02:05 +0200 | [diff] [blame] | 1364 | static struct uart_ops atmel_pops = { |
| 1365 | .tx_empty = atmel_tx_empty, |
| 1366 | .set_mctrl = atmel_set_mctrl, |
| 1367 | .get_mctrl = atmel_get_mctrl, |
| 1368 | .stop_tx = atmel_stop_tx, |
| 1369 | .start_tx = atmel_start_tx, |
| 1370 | .stop_rx = atmel_stop_rx, |
| 1371 | .enable_ms = atmel_enable_ms, |
| 1372 | .break_ctl = atmel_break_ctl, |
| 1373 | .startup = atmel_startup, |
| 1374 | .shutdown = atmel_shutdown, |
Haavard Skinnemoen | 9afd561 | 2008-07-16 21:52:46 +0100 | [diff] [blame] | 1375 | .flush_buffer = atmel_flush_buffer, |
Haavard Skinnemoen | 7192f92 | 2006-10-04 16:02:05 +0200 | [diff] [blame] | 1376 | .set_termios = atmel_set_termios, |
| 1377 | .type = atmel_type, |
| 1378 | .release_port = atmel_release_port, |
| 1379 | .request_port = atmel_request_port, |
| 1380 | .config_port = atmel_config_port, |
| 1381 | .verify_port = atmel_verify_port, |
| 1382 | .pm = atmel_serial_pm, |
Claudio Scordino | e8faff7 | 2010-05-03 13:31:28 +0100 | [diff] [blame^] | 1383 | .ioctl = atmel_ioctl, |
Albin Tonnerre | 8fe2d54 | 2009-12-09 12:31:32 -0800 | [diff] [blame] | 1384 | #ifdef CONFIG_CONSOLE_POLL |
| 1385 | .poll_get_char = atmel_poll_get_char, |
| 1386 | .poll_put_char = atmel_poll_put_char, |
| 1387 | #endif |
Andrew Victor | 1e6c9c2 | 2006-01-10 16:59:27 +0000 | [diff] [blame] | 1388 | }; |
| 1389 | |
Andrew Victor | afefc41 | 2006-06-19 19:53:19 +0100 | [diff] [blame] | 1390 | /* |
| 1391 | * Configure the port from the platform device resource info. |
| 1392 | */ |
Remy Bohmer | b843aa2 | 2008-02-08 04:21:01 -0800 | [diff] [blame] | 1393 | static void __devinit atmel_init_port(struct atmel_uart_port *atmel_port, |
| 1394 | struct platform_device *pdev) |
Andrew Victor | 1e6c9c2 | 2006-01-10 16:59:27 +0000 | [diff] [blame] | 1395 | { |
Haavard Skinnemoen | 7192f92 | 2006-10-04 16:02:05 +0200 | [diff] [blame] | 1396 | struct uart_port *port = &atmel_port->uart; |
Haavard Skinnemoen | 73e2798 | 2006-10-04 16:02:04 +0200 | [diff] [blame] | 1397 | struct atmel_uart_data *data = pdev->dev.platform_data; |
Andrew Victor | 1e6c9c2 | 2006-01-10 16:59:27 +0000 | [diff] [blame] | 1398 | |
Claudio Scordino | e8faff7 | 2010-05-03 13:31:28 +0100 | [diff] [blame^] | 1399 | port->iotype = UPIO_MEM; |
| 1400 | port->flags = UPF_BOOT_AUTOCONF; |
| 1401 | port->ops = &atmel_pops; |
| 1402 | port->fifosize = 1; |
| 1403 | port->line = pdev->id; |
| 1404 | port->dev = &pdev->dev; |
Andrew Victor | afefc41 | 2006-06-19 19:53:19 +0100 | [diff] [blame] | 1405 | port->mapbase = pdev->resource[0].start; |
| 1406 | port->irq = pdev->resource[1].start; |
| 1407 | |
Remy Bohmer | 1ecc26b | 2008-02-08 04:21:05 -0800 | [diff] [blame] | 1408 | tasklet_init(&atmel_port->tasklet, atmel_tasklet_func, |
| 1409 | (unsigned long)port); |
| 1410 | |
| 1411 | memset(&atmel_port->rx_ring, 0, sizeof(atmel_port->rx_ring)); |
| 1412 | |
Haavard Skinnemoen | 75d3521 | 2006-10-04 16:02:08 +0200 | [diff] [blame] | 1413 | if (data->regs) |
| 1414 | /* Already mapped by setup code */ |
| 1415 | port->membase = data->regs; |
Andrew Victor | afefc41 | 2006-06-19 19:53:19 +0100 | [diff] [blame] | 1416 | else { |
| 1417 | port->flags |= UPF_IOREMAP; |
| 1418 | port->membase = NULL; |
| 1419 | } |
| 1420 | |
Remy Bohmer | b843aa2 | 2008-02-08 04:21:01 -0800 | [diff] [blame] | 1421 | /* for console, the clock could already be configured */ |
| 1422 | if (!atmel_port->clk) { |
Haavard Skinnemoen | 7192f92 | 2006-10-04 16:02:05 +0200 | [diff] [blame] | 1423 | atmel_port->clk = clk_get(&pdev->dev, "usart"); |
| 1424 | clk_enable(atmel_port->clk); |
| 1425 | port->uartclk = clk_get_rate(atmel_port->clk); |
David Brownell | 06a7f05 | 2008-11-06 12:53:40 -0800 | [diff] [blame] | 1426 | clk_disable(atmel_port->clk); |
| 1427 | /* only enable clock when USART is in use */ |
Andrew Victor | afefc41 | 2006-06-19 19:53:19 +0100 | [diff] [blame] | 1428 | } |
Chip Coldwell | a667061 | 2008-02-08 04:21:06 -0800 | [diff] [blame] | 1429 | |
| 1430 | atmel_port->use_dma_rx = data->use_dma_rx; |
| 1431 | atmel_port->use_dma_tx = data->use_dma_tx; |
Claudio Scordino | e8faff7 | 2010-05-03 13:31:28 +0100 | [diff] [blame^] | 1432 | atmel_port->rs485 = data->rs485; |
| 1433 | /* Use TXEMPTY for interrupt when rs485 else TXRDY or ENDTX|TXBUFE */ |
| 1434 | if (atmel_port->rs485.flags & SER_RS485_ENABLED) |
| 1435 | atmel_port->tx_done_mask = ATMEL_US_TXEMPTY; |
| 1436 | else if (atmel_use_dma_tx(port)) { |
Chip Coldwell | a667061 | 2008-02-08 04:21:06 -0800 | [diff] [blame] | 1437 | port->fifosize = PDC_BUFFER_SIZE; |
Claudio Scordino | e8faff7 | 2010-05-03 13:31:28 +0100 | [diff] [blame^] | 1438 | atmel_port->tx_done_mask = ATMEL_US_ENDTX | ATMEL_US_TXBUFE; |
| 1439 | } else { |
| 1440 | atmel_port->tx_done_mask = ATMEL_US_TXRDY; |
| 1441 | } |
Andrew Victor | 1e6c9c2 | 2006-01-10 16:59:27 +0000 | [diff] [blame] | 1442 | } |
| 1443 | |
Andrew Victor | afefc41 | 2006-06-19 19:53:19 +0100 | [diff] [blame] | 1444 | /* |
| 1445 | * Register board-specific modem-control line handlers. |
| 1446 | */ |
Haavard Skinnemoen | 71f2e2b | 2006-10-04 16:02:07 +0200 | [diff] [blame] | 1447 | void __init atmel_register_uart_fns(struct atmel_port_fns *fns) |
Andrew Victor | 1e6c9c2 | 2006-01-10 16:59:27 +0000 | [diff] [blame] | 1448 | { |
| 1449 | if (fns->enable_ms) |
Haavard Skinnemoen | 7192f92 | 2006-10-04 16:02:05 +0200 | [diff] [blame] | 1450 | atmel_pops.enable_ms = fns->enable_ms; |
Andrew Victor | 1e6c9c2 | 2006-01-10 16:59:27 +0000 | [diff] [blame] | 1451 | if (fns->get_mctrl) |
Haavard Skinnemoen | 7192f92 | 2006-10-04 16:02:05 +0200 | [diff] [blame] | 1452 | atmel_pops.get_mctrl = fns->get_mctrl; |
Andrew Victor | 1e6c9c2 | 2006-01-10 16:59:27 +0000 | [diff] [blame] | 1453 | if (fns->set_mctrl) |
Haavard Skinnemoen | 7192f92 | 2006-10-04 16:02:05 +0200 | [diff] [blame] | 1454 | atmel_pops.set_mctrl = fns->set_mctrl; |
Haavard Skinnemoen | 71f2e2b | 2006-10-04 16:02:07 +0200 | [diff] [blame] | 1455 | atmel_open_hook = fns->open; |
| 1456 | atmel_close_hook = fns->close; |
Haavard Skinnemoen | 7192f92 | 2006-10-04 16:02:05 +0200 | [diff] [blame] | 1457 | atmel_pops.pm = fns->pm; |
| 1458 | atmel_pops.set_wake = fns->set_wake; |
Andrew Victor | 1e6c9c2 | 2006-01-10 16:59:27 +0000 | [diff] [blame] | 1459 | } |
| 1460 | |
Haavard Skinnemoen | 749c4e6 | 2006-10-04 16:02:02 +0200 | [diff] [blame] | 1461 | #ifdef CONFIG_SERIAL_ATMEL_CONSOLE |
Haavard Skinnemoen | 7192f92 | 2006-10-04 16:02:05 +0200 | [diff] [blame] | 1462 | static void atmel_console_putchar(struct uart_port *port, int ch) |
Russell King | d358788 | 2006-03-20 20:00:09 +0000 | [diff] [blame] | 1463 | { |
Haavard Skinnemoen | 7192f92 | 2006-10-04 16:02:05 +0200 | [diff] [blame] | 1464 | while (!(UART_GET_CSR(port) & ATMEL_US_TXRDY)) |
Haavard Skinnemoen | 829dd81 | 2008-02-08 04:21:02 -0800 | [diff] [blame] | 1465 | cpu_relax(); |
Russell King | d358788 | 2006-03-20 20:00:09 +0000 | [diff] [blame] | 1466 | UART_PUT_CHAR(port, ch); |
| 1467 | } |
Andrew Victor | 1e6c9c2 | 2006-01-10 16:59:27 +0000 | [diff] [blame] | 1468 | |
| 1469 | /* |
| 1470 | * Interrupts are disabled on entering |
| 1471 | */ |
Haavard Skinnemoen | 7192f92 | 2006-10-04 16:02:05 +0200 | [diff] [blame] | 1472 | static void atmel_console_write(struct console *co, const char *s, u_int count) |
Andrew Victor | 1e6c9c2 | 2006-01-10 16:59:27 +0000 | [diff] [blame] | 1473 | { |
Haavard Skinnemoen | 7192f92 | 2006-10-04 16:02:05 +0200 | [diff] [blame] | 1474 | struct uart_port *port = &atmel_ports[co->index].uart; |
Claudio Scordino | e8faff7 | 2010-05-03 13:31:28 +0100 | [diff] [blame^] | 1475 | struct atmel_uart_port *atmel_port = to_atmel_uart_port(port); |
Russell King | d358788 | 2006-03-20 20:00:09 +0000 | [diff] [blame] | 1476 | unsigned int status, imr; |
Marc Pignat | 39d4c92 | 2008-04-02 13:04:42 -0700 | [diff] [blame] | 1477 | unsigned int pdc_tx; |
Andrew Victor | 1e6c9c2 | 2006-01-10 16:59:27 +0000 | [diff] [blame] | 1478 | |
| 1479 | /* |
Remy Bohmer | b843aa2 | 2008-02-08 04:21:01 -0800 | [diff] [blame] | 1480 | * First, save IMR and then disable interrupts |
Andrew Victor | 1e6c9c2 | 2006-01-10 16:59:27 +0000 | [diff] [blame] | 1481 | */ |
Remy Bohmer | b843aa2 | 2008-02-08 04:21:01 -0800 | [diff] [blame] | 1482 | imr = UART_GET_IMR(port); |
Claudio Scordino | e8faff7 | 2010-05-03 13:31:28 +0100 | [diff] [blame^] | 1483 | UART_PUT_IDR(port, ATMEL_US_RXRDY | atmel_port->tx_done_mask); |
Andrew Victor | 1e6c9c2 | 2006-01-10 16:59:27 +0000 | [diff] [blame] | 1484 | |
Marc Pignat | 39d4c92 | 2008-04-02 13:04:42 -0700 | [diff] [blame] | 1485 | /* Store PDC transmit status and disable it */ |
| 1486 | pdc_tx = UART_GET_PTSR(port) & ATMEL_PDC_TXTEN; |
| 1487 | UART_PUT_PTCR(port, ATMEL_PDC_TXTDIS); |
| 1488 | |
Haavard Skinnemoen | 7192f92 | 2006-10-04 16:02:05 +0200 | [diff] [blame] | 1489 | uart_console_write(port, s, count, atmel_console_putchar); |
Andrew Victor | 1e6c9c2 | 2006-01-10 16:59:27 +0000 | [diff] [blame] | 1490 | |
| 1491 | /* |
Remy Bohmer | b843aa2 | 2008-02-08 04:21:01 -0800 | [diff] [blame] | 1492 | * Finally, wait for transmitter to become empty |
| 1493 | * and restore IMR |
Andrew Victor | 1e6c9c2 | 2006-01-10 16:59:27 +0000 | [diff] [blame] | 1494 | */ |
| 1495 | do { |
| 1496 | status = UART_GET_CSR(port); |
Haavard Skinnemoen | 7192f92 | 2006-10-04 16:02:05 +0200 | [diff] [blame] | 1497 | } while (!(status & ATMEL_US_TXRDY)); |
Marc Pignat | 39d4c92 | 2008-04-02 13:04:42 -0700 | [diff] [blame] | 1498 | |
| 1499 | /* Restore PDC transmit status */ |
| 1500 | if (pdc_tx) |
| 1501 | UART_PUT_PTCR(port, ATMEL_PDC_TXTEN); |
| 1502 | |
Remy Bohmer | b843aa2 | 2008-02-08 04:21:01 -0800 | [diff] [blame] | 1503 | /* set interrupts back the way they were */ |
| 1504 | UART_PUT_IER(port, imr); |
Andrew Victor | 1e6c9c2 | 2006-01-10 16:59:27 +0000 | [diff] [blame] | 1505 | } |
| 1506 | |
| 1507 | /* |
Remy Bohmer | b843aa2 | 2008-02-08 04:21:01 -0800 | [diff] [blame] | 1508 | * If the port was already initialised (eg, by a boot loader), |
| 1509 | * try to determine the current setup. |
Andrew Victor | 1e6c9c2 | 2006-01-10 16:59:27 +0000 | [diff] [blame] | 1510 | */ |
Remy Bohmer | b843aa2 | 2008-02-08 04:21:01 -0800 | [diff] [blame] | 1511 | static void __init atmel_console_get_options(struct uart_port *port, int *baud, |
| 1512 | int *parity, int *bits) |
Andrew Victor | 1e6c9c2 | 2006-01-10 16:59:27 +0000 | [diff] [blame] | 1513 | { |
| 1514 | unsigned int mr, quot; |
| 1515 | |
Haavard Skinnemoen | 1c0fd82 | 2008-02-08 04:21:03 -0800 | [diff] [blame] | 1516 | /* |
| 1517 | * If the baud rate generator isn't running, the port wasn't |
| 1518 | * initialized by the boot loader. |
| 1519 | */ |
Haavard Skinnemoen | 9c81c5c | 2008-06-05 22:46:39 -0700 | [diff] [blame] | 1520 | quot = UART_GET_BRGR(port) & ATMEL_US_CD; |
Haavard Skinnemoen | 1c0fd82 | 2008-02-08 04:21:03 -0800 | [diff] [blame] | 1521 | if (!quot) |
| 1522 | return; |
Andrew Victor | 1e6c9c2 | 2006-01-10 16:59:27 +0000 | [diff] [blame] | 1523 | |
Haavard Skinnemoen | 7192f92 | 2006-10-04 16:02:05 +0200 | [diff] [blame] | 1524 | mr = UART_GET_MR(port) & ATMEL_US_CHRL; |
| 1525 | if (mr == ATMEL_US_CHRL_8) |
Andrew Victor | 1e6c9c2 | 2006-01-10 16:59:27 +0000 | [diff] [blame] | 1526 | *bits = 8; |
| 1527 | else |
| 1528 | *bits = 7; |
| 1529 | |
Haavard Skinnemoen | 7192f92 | 2006-10-04 16:02:05 +0200 | [diff] [blame] | 1530 | mr = UART_GET_MR(port) & ATMEL_US_PAR; |
| 1531 | if (mr == ATMEL_US_PAR_EVEN) |
Andrew Victor | 1e6c9c2 | 2006-01-10 16:59:27 +0000 | [diff] [blame] | 1532 | *parity = 'e'; |
Haavard Skinnemoen | 7192f92 | 2006-10-04 16:02:05 +0200 | [diff] [blame] | 1533 | else if (mr == ATMEL_US_PAR_ODD) |
Andrew Victor | 1e6c9c2 | 2006-01-10 16:59:27 +0000 | [diff] [blame] | 1534 | *parity = 'o'; |
| 1535 | |
Haavard Skinnemoen | 4d5e392 | 2006-10-04 16:02:11 +0200 | [diff] [blame] | 1536 | /* |
| 1537 | * The serial core only rounds down when matching this to a |
| 1538 | * supported baud rate. Make sure we don't end up slightly |
| 1539 | * lower than one of those, as it would make us fall through |
| 1540 | * to a much lower baud rate than we really want. |
| 1541 | */ |
Haavard Skinnemoen | 4d5e392 | 2006-10-04 16:02:11 +0200 | [diff] [blame] | 1542 | *baud = port->uartclk / (16 * (quot - 1)); |
Andrew Victor | 1e6c9c2 | 2006-01-10 16:59:27 +0000 | [diff] [blame] | 1543 | } |
| 1544 | |
Haavard Skinnemoen | 7192f92 | 2006-10-04 16:02:05 +0200 | [diff] [blame] | 1545 | static int __init atmel_console_setup(struct console *co, char *options) |
Andrew Victor | 1e6c9c2 | 2006-01-10 16:59:27 +0000 | [diff] [blame] | 1546 | { |
Haavard Skinnemoen | 7192f92 | 2006-10-04 16:02:05 +0200 | [diff] [blame] | 1547 | struct uart_port *port = &atmel_ports[co->index].uart; |
Andrew Victor | 1e6c9c2 | 2006-01-10 16:59:27 +0000 | [diff] [blame] | 1548 | int baud = 115200; |
| 1549 | int bits = 8; |
| 1550 | int parity = 'n'; |
| 1551 | int flow = 'n'; |
| 1552 | |
Remy Bohmer | b843aa2 | 2008-02-08 04:21:01 -0800 | [diff] [blame] | 1553 | if (port->membase == NULL) { |
| 1554 | /* Port not initialized yet - delay setup */ |
Andrew Victor | afefc41 | 2006-06-19 19:53:19 +0100 | [diff] [blame] | 1555 | return -ENODEV; |
Remy Bohmer | b843aa2 | 2008-02-08 04:21:01 -0800 | [diff] [blame] | 1556 | } |
Andrew Victor | 1e6c9c2 | 2006-01-10 16:59:27 +0000 | [diff] [blame] | 1557 | |
David Brownell | 06a7f05 | 2008-11-06 12:53:40 -0800 | [diff] [blame] | 1558 | clk_enable(atmel_ports[co->index].clk); |
| 1559 | |
Remy Bohmer | b843aa2 | 2008-02-08 04:21:01 -0800 | [diff] [blame] | 1560 | UART_PUT_IDR(port, -1); |
Haavard Skinnemoen | 7192f92 | 2006-10-04 16:02:05 +0200 | [diff] [blame] | 1561 | UART_PUT_CR(port, ATMEL_US_RSTSTA | ATMEL_US_RSTRX); |
| 1562 | UART_PUT_CR(port, ATMEL_US_TXEN | ATMEL_US_RXEN); |
Andrew Victor | 1e6c9c2 | 2006-01-10 16:59:27 +0000 | [diff] [blame] | 1563 | |
| 1564 | if (options) |
| 1565 | uart_parse_options(options, &baud, &parity, &bits, &flow); |
| 1566 | else |
Haavard Skinnemoen | 7192f92 | 2006-10-04 16:02:05 +0200 | [diff] [blame] | 1567 | atmel_console_get_options(port, &baud, &parity, &bits); |
Andrew Victor | 1e6c9c2 | 2006-01-10 16:59:27 +0000 | [diff] [blame] | 1568 | |
| 1569 | return uart_set_options(port, co, baud, parity, bits, flow); |
| 1570 | } |
| 1571 | |
Haavard Skinnemoen | 7192f92 | 2006-10-04 16:02:05 +0200 | [diff] [blame] | 1572 | static struct uart_driver atmel_uart; |
Andrew Victor | 1e6c9c2 | 2006-01-10 16:59:27 +0000 | [diff] [blame] | 1573 | |
Haavard Skinnemoen | 7192f92 | 2006-10-04 16:02:05 +0200 | [diff] [blame] | 1574 | static struct console atmel_console = { |
| 1575 | .name = ATMEL_DEVICENAME, |
| 1576 | .write = atmel_console_write, |
Andrew Victor | 1e6c9c2 | 2006-01-10 16:59:27 +0000 | [diff] [blame] | 1577 | .device = uart_console_device, |
Haavard Skinnemoen | 7192f92 | 2006-10-04 16:02:05 +0200 | [diff] [blame] | 1578 | .setup = atmel_console_setup, |
Andrew Victor | 1e6c9c2 | 2006-01-10 16:59:27 +0000 | [diff] [blame] | 1579 | .flags = CON_PRINTBUFFER, |
| 1580 | .index = -1, |
Haavard Skinnemoen | 7192f92 | 2006-10-04 16:02:05 +0200 | [diff] [blame] | 1581 | .data = &atmel_uart, |
Andrew Victor | 1e6c9c2 | 2006-01-10 16:59:27 +0000 | [diff] [blame] | 1582 | }; |
| 1583 | |
David Brownell | 06a7f05 | 2008-11-06 12:53:40 -0800 | [diff] [blame] | 1584 | #define ATMEL_CONSOLE_DEVICE (&atmel_console) |
Andrew Victor | 1e6c9c2 | 2006-01-10 16:59:27 +0000 | [diff] [blame] | 1585 | |
Andrew Victor | afefc41 | 2006-06-19 19:53:19 +0100 | [diff] [blame] | 1586 | /* |
| 1587 | * Early console initialization (before VM subsystem initialized). |
| 1588 | */ |
Haavard Skinnemoen | 7192f92 | 2006-10-04 16:02:05 +0200 | [diff] [blame] | 1589 | static int __init atmel_console_init(void) |
Andrew Victor | 1e6c9c2 | 2006-01-10 16:59:27 +0000 | [diff] [blame] | 1590 | { |
Haavard Skinnemoen | 73e2798 | 2006-10-04 16:02:04 +0200 | [diff] [blame] | 1591 | if (atmel_default_console_device) { |
Remy Bohmer | b843aa2 | 2008-02-08 04:21:01 -0800 | [diff] [blame] | 1592 | add_preferred_console(ATMEL_DEVICENAME, |
| 1593 | atmel_default_console_device->id, NULL); |
| 1594 | atmel_init_port(&atmel_ports[atmel_default_console_device->id], |
| 1595 | atmel_default_console_device); |
Haavard Skinnemoen | 7192f92 | 2006-10-04 16:02:05 +0200 | [diff] [blame] | 1596 | register_console(&atmel_console); |
Andrew Victor | afefc41 | 2006-06-19 19:53:19 +0100 | [diff] [blame] | 1597 | } |
Andrew Victor | 1e6c9c2 | 2006-01-10 16:59:27 +0000 | [diff] [blame] | 1598 | |
Andrew Victor | 1e6c9c2 | 2006-01-10 16:59:27 +0000 | [diff] [blame] | 1599 | return 0; |
| 1600 | } |
Remy Bohmer | b843aa2 | 2008-02-08 04:21:01 -0800 | [diff] [blame] | 1601 | |
Haavard Skinnemoen | 7192f92 | 2006-10-04 16:02:05 +0200 | [diff] [blame] | 1602 | console_initcall(atmel_console_init); |
Andrew Victor | 1e6c9c2 | 2006-01-10 16:59:27 +0000 | [diff] [blame] | 1603 | |
Andrew Victor | afefc41 | 2006-06-19 19:53:19 +0100 | [diff] [blame] | 1604 | /* |
| 1605 | * Late console initialization. |
| 1606 | */ |
Haavard Skinnemoen | 7192f92 | 2006-10-04 16:02:05 +0200 | [diff] [blame] | 1607 | static int __init atmel_late_console_init(void) |
Andrew Victor | afefc41 | 2006-06-19 19:53:19 +0100 | [diff] [blame] | 1608 | { |
Remy Bohmer | b843aa2 | 2008-02-08 04:21:01 -0800 | [diff] [blame] | 1609 | if (atmel_default_console_device |
| 1610 | && !(atmel_console.flags & CON_ENABLED)) |
Haavard Skinnemoen | 7192f92 | 2006-10-04 16:02:05 +0200 | [diff] [blame] | 1611 | register_console(&atmel_console); |
Andrew Victor | afefc41 | 2006-06-19 19:53:19 +0100 | [diff] [blame] | 1612 | |
| 1613 | return 0; |
| 1614 | } |
Remy Bohmer | b843aa2 | 2008-02-08 04:21:01 -0800 | [diff] [blame] | 1615 | |
Haavard Skinnemoen | 7192f92 | 2006-10-04 16:02:05 +0200 | [diff] [blame] | 1616 | core_initcall(atmel_late_console_init); |
Andrew Victor | afefc41 | 2006-06-19 19:53:19 +0100 | [diff] [blame] | 1617 | |
Haavard Skinnemoen | dfa7f34 | 2008-02-08 04:21:04 -0800 | [diff] [blame] | 1618 | static inline bool atmel_is_console_port(struct uart_port *port) |
| 1619 | { |
| 1620 | return port->cons && port->cons->index == port->line; |
| 1621 | } |
| 1622 | |
Andrew Victor | 1e6c9c2 | 2006-01-10 16:59:27 +0000 | [diff] [blame] | 1623 | #else |
Haavard Skinnemoen | 7192f92 | 2006-10-04 16:02:05 +0200 | [diff] [blame] | 1624 | #define ATMEL_CONSOLE_DEVICE NULL |
Haavard Skinnemoen | dfa7f34 | 2008-02-08 04:21:04 -0800 | [diff] [blame] | 1625 | |
| 1626 | static inline bool atmel_is_console_port(struct uart_port *port) |
| 1627 | { |
| 1628 | return false; |
| 1629 | } |
Andrew Victor | 1e6c9c2 | 2006-01-10 16:59:27 +0000 | [diff] [blame] | 1630 | #endif |
| 1631 | |
Haavard Skinnemoen | 7192f92 | 2006-10-04 16:02:05 +0200 | [diff] [blame] | 1632 | static struct uart_driver atmel_uart = { |
Remy Bohmer | b843aa2 | 2008-02-08 04:21:01 -0800 | [diff] [blame] | 1633 | .owner = THIS_MODULE, |
| 1634 | .driver_name = "atmel_serial", |
| 1635 | .dev_name = ATMEL_DEVICENAME, |
| 1636 | .major = SERIAL_ATMEL_MAJOR, |
| 1637 | .minor = MINOR_START, |
| 1638 | .nr = ATMEL_MAX_UART, |
| 1639 | .cons = ATMEL_CONSOLE_DEVICE, |
Andrew Victor | 1e6c9c2 | 2006-01-10 16:59:27 +0000 | [diff] [blame] | 1640 | }; |
| 1641 | |
Andrew Victor | afefc41 | 2006-06-19 19:53:19 +0100 | [diff] [blame] | 1642 | #ifdef CONFIG_PM |
Haavard Skinnemoen | f826caa | 2008-02-24 14:34:45 +0100 | [diff] [blame] | 1643 | static bool atmel_serial_clk_will_stop(void) |
| 1644 | { |
| 1645 | #ifdef CONFIG_ARCH_AT91 |
| 1646 | return at91_suspend_entering_slow_clock(); |
| 1647 | #else |
| 1648 | return false; |
| 1649 | #endif |
| 1650 | } |
| 1651 | |
Remy Bohmer | b843aa2 | 2008-02-08 04:21:01 -0800 | [diff] [blame] | 1652 | static int atmel_serial_suspend(struct platform_device *pdev, |
| 1653 | pm_message_t state) |
Andrew Victor | 1e6c9c2 | 2006-01-10 16:59:27 +0000 | [diff] [blame] | 1654 | { |
Andrew Victor | afefc41 | 2006-06-19 19:53:19 +0100 | [diff] [blame] | 1655 | struct uart_port *port = platform_get_drvdata(pdev); |
Haavard Skinnemoen | c811ab8 | 2008-02-08 04:21:08 -0800 | [diff] [blame] | 1656 | struct atmel_uart_port *atmel_port = to_atmel_uart_port(port); |
Andrew Victor | 1e6c9c2 | 2006-01-10 16:59:27 +0000 | [diff] [blame] | 1657 | |
Haavard Skinnemoen | e1c609e | 2008-03-14 14:54:13 +0100 | [diff] [blame] | 1658 | if (atmel_is_console_port(port) && console_suspend_enabled) { |
| 1659 | /* Drain the TX shifter */ |
| 1660 | while (!(UART_GET_CSR(port) & ATMEL_US_TXEMPTY)) |
| 1661 | cpu_relax(); |
| 1662 | } |
| 1663 | |
Anti Sullin | f05596d | 2008-09-22 13:57:54 -0700 | [diff] [blame] | 1664 | /* we can not wake up if we're running on slow clock */ |
| 1665 | atmel_port->may_wakeup = device_may_wakeup(&pdev->dev); |
| 1666 | if (atmel_serial_clk_will_stop()) |
| 1667 | device_set_wakeup_enable(&pdev->dev, 0); |
| 1668 | |
| 1669 | uart_suspend_port(&atmel_uart, port); |
Andrew Victor | 1e6c9c2 | 2006-01-10 16:59:27 +0000 | [diff] [blame] | 1670 | |
| 1671 | return 0; |
| 1672 | } |
| 1673 | |
Haavard Skinnemoen | 7192f92 | 2006-10-04 16:02:05 +0200 | [diff] [blame] | 1674 | static int atmel_serial_resume(struct platform_device *pdev) |
Andrew Victor | afefc41 | 2006-06-19 19:53:19 +0100 | [diff] [blame] | 1675 | { |
| 1676 | struct uart_port *port = platform_get_drvdata(pdev); |
Haavard Skinnemoen | c811ab8 | 2008-02-08 04:21:08 -0800 | [diff] [blame] | 1677 | struct atmel_uart_port *atmel_port = to_atmel_uart_port(port); |
Andrew Victor | afefc41 | 2006-06-19 19:53:19 +0100 | [diff] [blame] | 1678 | |
Anti Sullin | f05596d | 2008-09-22 13:57:54 -0700 | [diff] [blame] | 1679 | uart_resume_port(&atmel_uart, port); |
| 1680 | device_set_wakeup_enable(&pdev->dev, atmel_port->may_wakeup); |
Andrew Victor | afefc41 | 2006-06-19 19:53:19 +0100 | [diff] [blame] | 1681 | |
| 1682 | return 0; |
| 1683 | } |
| 1684 | #else |
Haavard Skinnemoen | 7192f92 | 2006-10-04 16:02:05 +0200 | [diff] [blame] | 1685 | #define atmel_serial_suspend NULL |
| 1686 | #define atmel_serial_resume NULL |
Andrew Victor | afefc41 | 2006-06-19 19:53:19 +0100 | [diff] [blame] | 1687 | #endif |
| 1688 | |
Haavard Skinnemoen | 7192f92 | 2006-10-04 16:02:05 +0200 | [diff] [blame] | 1689 | static int __devinit atmel_serial_probe(struct platform_device *pdev) |
Andrew Victor | afefc41 | 2006-06-19 19:53:19 +0100 | [diff] [blame] | 1690 | { |
Haavard Skinnemoen | 7192f92 | 2006-10-04 16:02:05 +0200 | [diff] [blame] | 1691 | struct atmel_uart_port *port; |
Remy Bohmer | 1ecc26b | 2008-02-08 04:21:05 -0800 | [diff] [blame] | 1692 | void *data; |
Andrew Victor | afefc41 | 2006-06-19 19:53:19 +0100 | [diff] [blame] | 1693 | int ret; |
| 1694 | |
Haavard Skinnemoen | 9d09daf | 2009-10-26 16:50:02 -0700 | [diff] [blame] | 1695 | BUILD_BUG_ON(ATMEL_SERIAL_RINGSIZE & (ATMEL_SERIAL_RINGSIZE - 1)); |
Remy Bohmer | 1ecc26b | 2008-02-08 04:21:05 -0800 | [diff] [blame] | 1696 | |
Haavard Skinnemoen | 7192f92 | 2006-10-04 16:02:05 +0200 | [diff] [blame] | 1697 | port = &atmel_ports[pdev->id]; |
Anti Sullin | f05596d | 2008-09-22 13:57:54 -0700 | [diff] [blame] | 1698 | port->backup_imr = 0; |
| 1699 | |
Haavard Skinnemoen | 7192f92 | 2006-10-04 16:02:05 +0200 | [diff] [blame] | 1700 | atmel_init_port(port, pdev); |
Andrew Victor | afefc41 | 2006-06-19 19:53:19 +0100 | [diff] [blame] | 1701 | |
Chip Coldwell | a667061 | 2008-02-08 04:21:06 -0800 | [diff] [blame] | 1702 | if (!atmel_use_dma_rx(&port->uart)) { |
| 1703 | ret = -ENOMEM; |
Haavard Skinnemoen | 6433471 | 2008-02-08 04:21:07 -0800 | [diff] [blame] | 1704 | data = kmalloc(sizeof(struct atmel_uart_char) |
| 1705 | * ATMEL_SERIAL_RINGSIZE, GFP_KERNEL); |
Chip Coldwell | a667061 | 2008-02-08 04:21:06 -0800 | [diff] [blame] | 1706 | if (!data) |
| 1707 | goto err_alloc_ring; |
| 1708 | port->rx_ring.buf = data; |
| 1709 | } |
Remy Bohmer | 1ecc26b | 2008-02-08 04:21:05 -0800 | [diff] [blame] | 1710 | |
Haavard Skinnemoen | 7192f92 | 2006-10-04 16:02:05 +0200 | [diff] [blame] | 1711 | ret = uart_add_one_port(&atmel_uart, &port->uart); |
Haavard Skinnemoen | dfa7f34 | 2008-02-08 04:21:04 -0800 | [diff] [blame] | 1712 | if (ret) |
| 1713 | goto err_add_port; |
| 1714 | |
Albin Tonnerre | 8da14b5 | 2009-07-29 15:04:18 -0700 | [diff] [blame] | 1715 | #ifdef CONFIG_SERIAL_ATMEL_CONSOLE |
David Brownell | 06a7f05 | 2008-11-06 12:53:40 -0800 | [diff] [blame] | 1716 | if (atmel_is_console_port(&port->uart) |
| 1717 | && ATMEL_CONSOLE_DEVICE->flags & CON_ENABLED) { |
| 1718 | /* |
| 1719 | * The serial core enabled the clock for us, so undo |
| 1720 | * the clk_enable() in atmel_console_setup() |
| 1721 | */ |
| 1722 | clk_disable(port->clk); |
| 1723 | } |
Albin Tonnerre | 8da14b5 | 2009-07-29 15:04:18 -0700 | [diff] [blame] | 1724 | #endif |
David Brownell | 06a7f05 | 2008-11-06 12:53:40 -0800 | [diff] [blame] | 1725 | |
Haavard Skinnemoen | dfa7f34 | 2008-02-08 04:21:04 -0800 | [diff] [blame] | 1726 | device_init_wakeup(&pdev->dev, 1); |
| 1727 | platform_set_drvdata(pdev, port); |
| 1728 | |
| 1729 | return 0; |
| 1730 | |
| 1731 | err_add_port: |
Remy Bohmer | 1ecc26b | 2008-02-08 04:21:05 -0800 | [diff] [blame] | 1732 | kfree(port->rx_ring.buf); |
| 1733 | port->rx_ring.buf = NULL; |
| 1734 | err_alloc_ring: |
Haavard Skinnemoen | dfa7f34 | 2008-02-08 04:21:04 -0800 | [diff] [blame] | 1735 | if (!atmel_is_console_port(&port->uart)) { |
Haavard Skinnemoen | dfa7f34 | 2008-02-08 04:21:04 -0800 | [diff] [blame] | 1736 | clk_put(port->clk); |
| 1737 | port->clk = NULL; |
Andrew Victor | afefc41 | 2006-06-19 19:53:19 +0100 | [diff] [blame] | 1738 | } |
| 1739 | |
| 1740 | return ret; |
| 1741 | } |
| 1742 | |
Haavard Skinnemoen | 7192f92 | 2006-10-04 16:02:05 +0200 | [diff] [blame] | 1743 | static int __devexit atmel_serial_remove(struct platform_device *pdev) |
Andrew Victor | afefc41 | 2006-06-19 19:53:19 +0100 | [diff] [blame] | 1744 | { |
| 1745 | struct uart_port *port = platform_get_drvdata(pdev); |
Haavard Skinnemoen | c811ab8 | 2008-02-08 04:21:08 -0800 | [diff] [blame] | 1746 | struct atmel_uart_port *atmel_port = to_atmel_uart_port(port); |
Andrew Victor | afefc41 | 2006-06-19 19:53:19 +0100 | [diff] [blame] | 1747 | int ret = 0; |
| 1748 | |
Andrew Victor | afefc41 | 2006-06-19 19:53:19 +0100 | [diff] [blame] | 1749 | device_init_wakeup(&pdev->dev, 0); |
| 1750 | platform_set_drvdata(pdev, NULL); |
| 1751 | |
Haavard Skinnemoen | dfa7f34 | 2008-02-08 04:21:04 -0800 | [diff] [blame] | 1752 | ret = uart_remove_one_port(&atmel_uart, port); |
| 1753 | |
Remy Bohmer | 1ecc26b | 2008-02-08 04:21:05 -0800 | [diff] [blame] | 1754 | tasklet_kill(&atmel_port->tasklet); |
| 1755 | kfree(atmel_port->rx_ring.buf); |
| 1756 | |
Haavard Skinnemoen | dfa7f34 | 2008-02-08 04:21:04 -0800 | [diff] [blame] | 1757 | /* "port" is allocated statically, so we shouldn't free it */ |
| 1758 | |
Haavard Skinnemoen | dfa7f34 | 2008-02-08 04:21:04 -0800 | [diff] [blame] | 1759 | clk_put(atmel_port->clk); |
Andrew Victor | afefc41 | 2006-06-19 19:53:19 +0100 | [diff] [blame] | 1760 | |
| 1761 | return ret; |
| 1762 | } |
| 1763 | |
Haavard Skinnemoen | 7192f92 | 2006-10-04 16:02:05 +0200 | [diff] [blame] | 1764 | static struct platform_driver atmel_serial_driver = { |
| 1765 | .probe = atmel_serial_probe, |
| 1766 | .remove = __devexit_p(atmel_serial_remove), |
| 1767 | .suspend = atmel_serial_suspend, |
| 1768 | .resume = atmel_serial_resume, |
Andrew Victor | afefc41 | 2006-06-19 19:53:19 +0100 | [diff] [blame] | 1769 | .driver = { |
Haavard Skinnemoen | 1e8ea80 | 2006-10-04 16:02:03 +0200 | [diff] [blame] | 1770 | .name = "atmel_usart", |
Andrew Victor | afefc41 | 2006-06-19 19:53:19 +0100 | [diff] [blame] | 1771 | .owner = THIS_MODULE, |
| 1772 | }, |
| 1773 | }; |
| 1774 | |
Haavard Skinnemoen | 7192f92 | 2006-10-04 16:02:05 +0200 | [diff] [blame] | 1775 | static int __init atmel_serial_init(void) |
Andrew Victor | afefc41 | 2006-06-19 19:53:19 +0100 | [diff] [blame] | 1776 | { |
| 1777 | int ret; |
| 1778 | |
Haavard Skinnemoen | 7192f92 | 2006-10-04 16:02:05 +0200 | [diff] [blame] | 1779 | ret = uart_register_driver(&atmel_uart); |
Andrew Victor | afefc41 | 2006-06-19 19:53:19 +0100 | [diff] [blame] | 1780 | if (ret) |
| 1781 | return ret; |
| 1782 | |
Haavard Skinnemoen | 7192f92 | 2006-10-04 16:02:05 +0200 | [diff] [blame] | 1783 | ret = platform_driver_register(&atmel_serial_driver); |
Andrew Victor | afefc41 | 2006-06-19 19:53:19 +0100 | [diff] [blame] | 1784 | if (ret) |
Haavard Skinnemoen | 7192f92 | 2006-10-04 16:02:05 +0200 | [diff] [blame] | 1785 | uart_unregister_driver(&atmel_uart); |
Andrew Victor | afefc41 | 2006-06-19 19:53:19 +0100 | [diff] [blame] | 1786 | |
| 1787 | return ret; |
| 1788 | } |
| 1789 | |
Haavard Skinnemoen | 7192f92 | 2006-10-04 16:02:05 +0200 | [diff] [blame] | 1790 | static void __exit atmel_serial_exit(void) |
Andrew Victor | 1e6c9c2 | 2006-01-10 16:59:27 +0000 | [diff] [blame] | 1791 | { |
Haavard Skinnemoen | 7192f92 | 2006-10-04 16:02:05 +0200 | [diff] [blame] | 1792 | platform_driver_unregister(&atmel_serial_driver); |
| 1793 | uart_unregister_driver(&atmel_uart); |
Andrew Victor | 1e6c9c2 | 2006-01-10 16:59:27 +0000 | [diff] [blame] | 1794 | } |
| 1795 | |
Haavard Skinnemoen | 7192f92 | 2006-10-04 16:02:05 +0200 | [diff] [blame] | 1796 | module_init(atmel_serial_init); |
| 1797 | module_exit(atmel_serial_exit); |
Andrew Victor | 1e6c9c2 | 2006-01-10 16:59:27 +0000 | [diff] [blame] | 1798 | |
| 1799 | MODULE_AUTHOR("Rick Bronson"); |
Haavard Skinnemoen | 7192f92 | 2006-10-04 16:02:05 +0200 | [diff] [blame] | 1800 | MODULE_DESCRIPTION("Atmel AT91 / AT32 serial port driver"); |
Andrew Victor | 1e6c9c2 | 2006-01-10 16:59:27 +0000 | [diff] [blame] | 1801 | MODULE_LICENSE("GPL"); |
Kay Sievers | e169c13 | 2008-04-15 14:34:35 -0700 | [diff] [blame] | 1802 | MODULE_ALIAS("platform:atmel_usart"); |