10 static char *serial_version =
"$Revision: 1.25 $";
12 #include <linux/types.h>
13 #include <linux/errno.h>
14 #include <linux/signal.h>
15 #include <linux/sched.h>
18 #include <linux/tty.h>
21 #include <linux/string.h>
22 #include <linux/fcntl.h>
24 #include <linux/slab.h>
26 #include <linux/kernel.h>
28 #include <linux/bitops.h>
31 #include <linux/module.h>
39 #include <arch/system.h>
42 #include <linux/serial.h>
48 #ifdef CONFIG_ETRAX_SERIAL_FAST_TIMER
49 #ifndef CONFIG_ETRAX_FAST_TIMER
50 #error "Enable FAST_TIMER to use SERIAL_FAST_TIMER"
54 #if defined(CONFIG_ETRAX_SERIAL_RX_TIMEOUT_TICKS) && \
55 (CONFIG_ETRAX_SERIAL_RX_TIMEOUT_TICKS == 0)
56 #error "RX_TIMEOUT_TICKS == 0 not allowed, use 1"
59 #if defined(CONFIG_ETRAX_RS485_ON_PA) && defined(CONFIG_ETRAX_RS485_ON_PORT_G)
60 #error "Disable either CONFIG_ETRAX_RS485_ON_PA or CONFIG_ETRAX_RS485_ON_PORT_G"
67 #if defined(LOCAL_HEADERS)
68 #include "serial_compat.h"
74 #define WAKEUP_CHARS 256
88 #define SERIAL_HANDLE_EARLY_ERRORS
91 #define SERIAL_DESCR_BUF_SIZE 256
93 #define SERIAL_PRESCALE_BASE 3125000
94 #define DEF_BAUD_BASE SERIAL_PRESCALE_BASE
98 #define MIN_FLUSH_TIME_USEC 250
110 #define DLOG_INT_TRIG(x)
113 #ifndef DEBUG_LOG_INCLUDED
114 #define DEBUG_LOG(line, string, value)
116 struct debug_log_info
119 unsigned long timer_data;
124 #define DEBUG_LOG_SIZE 4096
126 struct debug_log_info
debug_log[DEBUG_LOG_SIZE];
127 int debug_log_pos = 0;
129 #define DEBUG_LOG(_line, _string, _value) do { \
130 if ((_line) == SERIAL_DEBUG_LINE) {\
131 debug_log_func(_line, _string, _value); \
135 void debug_log_func(
int line,
const char *
string,
int value)
137 if (debug_log_pos < DEBUG_LOG_SIZE) {
139 debug_log[debug_log_pos].timer_data = *R_TIMER_DATA;
149 #ifndef CONFIG_ETRAX_SERIAL_RX_TIMEOUT_TICKS
154 #define CONFIG_ETRAX_SERIAL_RX_TIMEOUT_TICKS 5
159 static void change_speed(
struct e100_serial *
info);
160 static void rs_throttle(
struct tty_struct * tty);
161 static void rs_wait_until_sent(
struct tty_struct *tty,
int timeout);
163 const unsigned char *
buf,
int count);
164 #ifdef CONFIG_ETRAX_RS485
165 static int e100_write_rs485(
struct tty_struct *tty,
166 const unsigned char *
buf,
int count);
168 static int get_lsr_info(
struct e100_serial *
info,
unsigned int *value);
171 #define DEF_BAUD 115200
172 #define STD_FLAGS (ASYNC_BOOT_AUTOCONF | ASYNC_SKIP_TEST)
180 #define REG_DATA_STATUS32 0
181 #define REG_TR_DATA 0
183 #define REG_TR_CTRL 1
184 #define REG_REC_CTRL 2
189 #define SER_RXD_MASK IO_MASK(R_SERIAL0_STATUS, rxd)
190 #define SER_DATA_AVAIL_MASK IO_MASK(R_SERIAL0_STATUS, data_avail)
191 #define SER_FRAMING_ERR_MASK IO_MASK(R_SERIAL0_STATUS, framing_err)
192 #define SER_PAR_ERR_MASK IO_MASK(R_SERIAL0_STATUS, par_err)
193 #define SER_OVERRUN_MASK IO_MASK(R_SERIAL0_STATUS, overrun)
195 #define SER_ERROR_MASK (SER_OVERRUN_MASK | SER_PAR_ERR_MASK | SER_FRAMING_ERR_MASK)
198 #define ERRCODE_SET_BREAK (TTY_BREAK)
199 #define ERRCODE_INSERT 0x100
200 #define ERRCODE_INSERT_BREAK (ERRCODE_INSERT | TTY_BREAK)
202 #define FORCE_EOP(info) *R_SET_EOP = 1U << info->iseteop;
217 static const unsigned long e100_ser_int_mask = 0
218 #ifdef CONFIG_ETRAX_SERIAL_PORT0
219 |
IO_MASK(R_IRQ_MASK1_RD, ser0_data) |
IO_MASK(R_IRQ_MASK1_RD, ser0_ready)
221 #ifdef CONFIG_ETRAX_SERIAL_PORT1
222 |
IO_MASK(R_IRQ_MASK1_RD, ser1_data) |
IO_MASK(R_IRQ_MASK1_RD, ser1_ready)
224 #ifdef CONFIG_ETRAX_SERIAL_PORT2
225 |
IO_MASK(R_IRQ_MASK1_RD, ser2_data) |
IO_MASK(R_IRQ_MASK1_RD, ser2_ready)
227 #ifdef CONFIG_ETRAX_SERIAL_PORT3
228 |
IO_MASK(R_IRQ_MASK1_RD, ser3_data) |
IO_MASK(R_IRQ_MASK1_RD, ser3_ready)
237 static struct e100_serial rs_table[] = {
239 .ioport = (
unsigned char *)R_SERIAL0_CTRL,
241 .oclrintradr = R_DMA_CH6_CLR_INTR,
242 .ofirstadr = R_DMA_CH6_FIRST,
243 .ocmdadr = R_DMA_CH6_CMD,
244 .ostatusadr = R_DMA_CH6_STATUS,
245 .iclrintradr = R_DMA_CH7_CLR_INTR,
246 .ifirstadr = R_DMA_CH7_FIRST,
247 .icmdadr = R_DMA_CH7_CMD,
248 .idescradr = R_DMA_CH7_DESCR,
255 #ifdef CONFIG_ETRAX_SERIAL_PORT0
257 #ifdef CONFIG_ETRAX_SERIAL_PORT0_DMA6_OUT
258 .dma_out_enabled = 1,
261 .dma_out_irq_flags = 0,
262 .dma_out_irq_description =
"serial 0 dma tr",
264 .dma_out_enabled = 0,
266 .dma_out_irq_nbr = 0,
267 .dma_out_irq_flags = 0,
268 .dma_out_irq_description =
NULL,
270 #ifdef CONFIG_ETRAX_SERIAL_PORT0_DMA7_IN
274 .dma_in_irq_flags = 0,
275 .dma_in_irq_description =
"serial 0 dma rec",
280 .dma_in_irq_flags = 0,
281 .dma_in_irq_description =
NULL,
285 .io_if_description =
NULL,
286 .dma_out_enabled = 0,
291 #ifndef CONFIG_SVINTO_SIM
293 .ioport = (
unsigned char *)R_SERIAL1_CTRL,
295 .oclrintradr = R_DMA_CH8_CLR_INTR,
296 .ofirstadr = R_DMA_CH8_FIRST,
297 .ocmdadr = R_DMA_CH8_CMD,
298 .ostatusadr = R_DMA_CH8_STATUS,
299 .iclrintradr = R_DMA_CH9_CLR_INTR,
300 .ifirstadr = R_DMA_CH9_FIRST,
301 .icmdadr = R_DMA_CH9_CMD,
302 .idescradr = R_DMA_CH9_DESCR,
309 #ifdef CONFIG_ETRAX_SERIAL_PORT1
311 .io_if_description =
"ser1",
312 #ifdef CONFIG_ETRAX_SERIAL_PORT1_DMA8_OUT
313 .dma_out_enabled = 1,
316 .dma_out_irq_flags = 0,
317 .dma_out_irq_description =
"serial 1 dma tr",
319 .dma_out_enabled = 0,
321 .dma_out_irq_nbr = 0,
322 .dma_out_irq_flags = 0,
323 .dma_out_irq_description =
NULL,
325 #ifdef CONFIG_ETRAX_SERIAL_PORT1_DMA9_IN
329 .dma_in_irq_flags = 0,
330 .dma_in_irq_description =
"serial 1 dma rec",
336 .dma_in_irq_flags = 0,
337 .dma_in_irq_description =
NULL,
341 .io_if_description =
NULL,
343 .dma_out_enabled = 0,
349 .ioport = (
unsigned char *)R_SERIAL2_CTRL,
351 .oclrintradr = R_DMA_CH2_CLR_INTR,
352 .ofirstadr = R_DMA_CH2_FIRST,
353 .ocmdadr = R_DMA_CH2_CMD,
354 .ostatusadr = R_DMA_CH2_STATUS,
355 .iclrintradr = R_DMA_CH3_CLR_INTR,
356 .ifirstadr = R_DMA_CH3_FIRST,
357 .icmdadr = R_DMA_CH3_CMD,
358 .idescradr = R_DMA_CH3_DESCR,
365 #ifdef CONFIG_ETRAX_SERIAL_PORT2
367 .io_if_description =
"ser2",
368 #ifdef CONFIG_ETRAX_SERIAL_PORT2_DMA2_OUT
369 .dma_out_enabled = 1,
372 .dma_out_irq_flags = 0,
373 .dma_out_irq_description =
"serial 2 dma tr",
375 .dma_out_enabled = 0,
377 .dma_out_irq_nbr = 0,
378 .dma_out_irq_flags = 0,
379 .dma_out_irq_description =
NULL,
381 #ifdef CONFIG_ETRAX_SERIAL_PORT2_DMA3_IN
385 .dma_in_irq_flags = 0,
386 .dma_in_irq_description =
"serial 2 dma rec",
391 .dma_in_irq_flags = 0,
392 .dma_in_irq_description =
NULL,
396 .io_if_description =
NULL,
397 .dma_out_enabled = 0,
403 .ioport = (
unsigned char *)R_SERIAL3_CTRL,
405 .oclrintradr = R_DMA_CH4_CLR_INTR,
406 .ofirstadr = R_DMA_CH4_FIRST,
407 .ocmdadr = R_DMA_CH4_CMD,
408 .ostatusadr = R_DMA_CH4_STATUS,
409 .iclrintradr = R_DMA_CH5_CLR_INTR,
410 .ifirstadr = R_DMA_CH5_FIRST,
411 .icmdadr = R_DMA_CH5_CMD,
412 .idescradr = R_DMA_CH5_DESCR,
419 #ifdef CONFIG_ETRAX_SERIAL_PORT3
421 .io_if_description =
"ser3",
422 #ifdef CONFIG_ETRAX_SERIAL_PORT3_DMA4_OUT
423 .dma_out_enabled = 1,
426 .dma_out_irq_flags = 0,
427 .dma_out_irq_description =
"serial 3 dma tr",
429 .dma_out_enabled = 0,
431 .dma_out_irq_nbr = 0,
432 .dma_out_irq_flags = 0,
433 .dma_out_irq_description =
NULL,
435 #ifdef CONFIG_ETRAX_SERIAL_PORT3_DMA5_IN
439 .dma_in_irq_flags = 0,
440 .dma_in_irq_description =
"serial 3 dma rec",
445 .dma_in_irq_flags = 0,
446 .dma_in_irq_description =
NULL
450 .io_if_description =
NULL,
451 .dma_out_enabled = 0,
459 #define NR_PORTS (sizeof(rs_table)/sizeof(struct e100_serial))
461 #ifdef CONFIG_ETRAX_SERIAL_FAST_TIMER
462 static struct fast_timer fast_timers[
NR_PORTS];
465 #ifdef CONFIG_ETRAX_SERIAL_PROC_ENTRY
466 #define PROCSTAT(x) x
467 struct ser_statistics_type {
469 int early_errors_cnt;
472 unsigned long int processing_flip;
473 unsigned long processing_flip_still_room;
474 unsigned long int timeout_flush_cnt;
481 static struct ser_statistics_type ser_stat[
NR_PORTS];
490 #if defined(CONFIG_ETRAX_RS485)
491 #ifdef CONFIG_ETRAX_FAST_TIMER
492 static struct fast_timer fast_timers_rs485[
NR_PORTS];
494 #if defined(CONFIG_ETRAX_RS485_ON_PA)
495 static int rs485_pa_bit = CONFIG_ETRAX_RS485_ON_PA_BIT;
497 #if defined(CONFIG_ETRAX_RS485_ON_PORT_G)
498 static int rs485_port_g_bit = CONFIG_ETRAX_RS485_ON_PORT_G_BIT;
503 #define E100_STRUCT_PORT(line, pinname) \
504 ((CONFIG_ETRAX_SER##line##_##pinname##_ON_PA_BIT >= 0)? \
505 (R_PORT_PA_DATA): ( \
506 (CONFIG_ETRAX_SER##line##_##pinname##_ON_PB_BIT >= 0)? \
507 (R_PORT_PB_DATA):&dummy_ser[line]))
509 #define E100_STRUCT_SHADOW(line, pinname) \
510 ((CONFIG_ETRAX_SER##line##_##pinname##_ON_PA_BIT >= 0)? \
511 (&port_pa_data_shadow): ( \
512 (CONFIG_ETRAX_SER##line##_##pinname##_ON_PB_BIT >= 0)? \
513 (&port_pb_data_shadow):&dummy_ser[line]))
514 #define E100_STRUCT_MASK(line, pinname) \
515 ((CONFIG_ETRAX_SER##line##_##pinname##_ON_PA_BIT >= 0)? \
516 (1<<CONFIG_ETRAX_SER##line##_##pinname##_ON_PA_BIT): ( \
517 (CONFIG_ETRAX_SER##line##_##pinname##_ON_PB_BIT >= 0)? \
518 (1<<CONFIG_ETRAX_SER##line##_##pinname##_ON_PB_BIT):DUMMY_##pinname##_MASK))
520 #define DUMMY_DTR_MASK 1
521 #define DUMMY_RI_MASK 2
522 #define DUMMY_DSR_MASK 4
523 #define DUMMY_CD_MASK 8
524 static unsigned char dummy_ser[
NR_PORTS] = {0xFF, 0xFF, 0xFF,0xFF};
527 #ifdef CONFIG_ETRAX_SERIAL_PORT0
529 #define SER0_PA_BITSUM (CONFIG_ETRAX_SER0_DTR_ON_PA_BIT+CONFIG_ETRAX_SER0_RI_ON_PA_BIT+CONFIG_ETRAX_SER0_DSR_ON_PA_BIT+CONFIG_ETRAX_SER0_CD_ON_PA_BIT)
531 #if SER0_PA_BITSUM != -4
532 # if CONFIG_ETRAX_SER0_DTR_ON_PA_BIT == -1
533 # ifndef CONFIG_ETRAX_SER0_DTR_RI_DSR_CD_MIXED
534 # define CONFIG_ETRAX_SER0_DTR_RI_DSR_CD_MIXED 1
537 # if CONFIG_ETRAX_SER0_RI_ON_PA_BIT == -1
538 # ifndef CONFIG_ETRAX_SER0_DTR_RI_DSR_CD_MIXED
539 # define CONFIG_ETRAX_SER0_DTR_RI_DSR_CD_MIXED 1
542 # if CONFIG_ETRAX_SER0_DSR_ON_PA_BIT == -1
543 # ifndef CONFIG_ETRAX_SER0_DTR_RI_DSR_CD_MIXED
544 # define CONFIG_ETRAX_SER0_DTR_RI_DSR_CD_MIXED 1
547 # if CONFIG_ETRAX_SER0_CD_ON_PA_BIT == -1
548 # ifndef CONFIG_ETRAX_SER0_DTR_RI_DSR_CD_MIXED
549 # define CONFIG_ETRAX_SER0_DTR_RI_DSR_CD_MIXED 1
554 #define SER0_PB_BITSUM (CONFIG_ETRAX_SER0_DTR_ON_PB_BIT+CONFIG_ETRAX_SER0_RI_ON_PB_BIT+CONFIG_ETRAX_SER0_DSR_ON_PB_BIT+CONFIG_ETRAX_SER0_CD_ON_PB_BIT)
556 #if SER0_PB_BITSUM != -4
557 # if CONFIG_ETRAX_SER0_DTR_ON_PB_BIT == -1
558 # ifndef CONFIG_ETRAX_SER0_DTR_RI_DSR_CD_MIXED
559 # define CONFIG_ETRAX_SER0_DTR_RI_DSR_CD_MIXED 1
562 # if CONFIG_ETRAX_SER0_RI_ON_PB_BIT == -1
563 # ifndef CONFIG_ETRAX_SER0_DTR_RI_DSR_CD_MIXED
564 # define CONFIG_ETRAX_SER0_DTR_RI_DSR_CD_MIXED 1
567 # if CONFIG_ETRAX_SER0_DSR_ON_PB_BIT == -1
568 # ifndef CONFIG_ETRAX_SER0_DTR_RI_DSR_CD_MIXED
569 # define CONFIG_ETRAX_SER0_DTR_RI_DSR_CD_MIXED 1
572 # if CONFIG_ETRAX_SER0_CD_ON_PB_BIT == -1
573 # ifndef CONFIG_ETRAX_SER0_DTR_RI_DSR_CD_MIXED
574 # define CONFIG_ETRAX_SER0_DTR_RI_DSR_CD_MIXED 1
582 #ifdef CONFIG_ETRAX_SERIAL_PORT1
584 #define SER1_PA_BITSUM (CONFIG_ETRAX_SER1_DTR_ON_PA_BIT+CONFIG_ETRAX_SER1_RI_ON_PA_BIT+CONFIG_ETRAX_SER1_DSR_ON_PA_BIT+CONFIG_ETRAX_SER1_CD_ON_PA_BIT)
586 #if SER1_PA_BITSUM != -4
587 # if CONFIG_ETRAX_SER1_DTR_ON_PA_BIT == -1
588 # ifndef CONFIG_ETRAX_SER1_DTR_RI_DSR_CD_MIXED
589 # define CONFIG_ETRAX_SER1_DTR_RI_DSR_CD_MIXED 1
592 # if CONFIG_ETRAX_SER1_RI_ON_PA_BIT == -1
593 # ifndef CONFIG_ETRAX_SER1_DTR_RI_DSR_CD_MIXED
594 # define CONFIG_ETRAX_SER1_DTR_RI_DSR_CD_MIXED 1
597 # if CONFIG_ETRAX_SER1_DSR_ON_PA_BIT == -1
598 # ifndef CONFIG_ETRAX_SER1_DTR_RI_DSR_CD_MIXED
599 # define CONFIG_ETRAX_SER1_DTR_RI_DSR_CD_MIXED 1
602 # if CONFIG_ETRAX_SER1_CD_ON_PA_BIT == -1
603 # ifndef CONFIG_ETRAX_SER1_DTR_RI_DSR_CD_MIXED
604 # define CONFIG_ETRAX_SER1_DTR_RI_DSR_CD_MIXED 1
609 #define SER1_PB_BITSUM (CONFIG_ETRAX_SER1_DTR_ON_PB_BIT+CONFIG_ETRAX_SER1_RI_ON_PB_BIT+CONFIG_ETRAX_SER1_DSR_ON_PB_BIT+CONFIG_ETRAX_SER1_CD_ON_PB_BIT)
611 #if SER1_PB_BITSUM != -4
612 # if CONFIG_ETRAX_SER1_DTR_ON_PB_BIT == -1
613 # ifndef CONFIG_ETRAX_SER1_DTR_RI_DSR_CD_MIXED
614 # define CONFIG_ETRAX_SER1_DTR_RI_DSR_CD_MIXED 1
617 # if CONFIG_ETRAX_SER1_RI_ON_PB_BIT == -1
618 # ifndef CONFIG_ETRAX_SER1_DTR_RI_DSR_CD_MIXED
619 # define CONFIG_ETRAX_SER1_DTR_RI_DSR_CD_MIXED 1
622 # if CONFIG_ETRAX_SER1_DSR_ON_PB_BIT == -1
623 # ifndef CONFIG_ETRAX_SER1_DTR_RI_DSR_CD_MIXED
624 # define CONFIG_ETRAX_SER1_DTR_RI_DSR_CD_MIXED 1
627 # if CONFIG_ETRAX_SER1_CD_ON_PB_BIT == -1
628 # ifndef CONFIG_ETRAX_SER1_DTR_RI_DSR_CD_MIXED
629 # define CONFIG_ETRAX_SER1_DTR_RI_DSR_CD_MIXED 1
636 #ifdef CONFIG_ETRAX_SERIAL_PORT2
638 #define SER2_PA_BITSUM (CONFIG_ETRAX_SER2_DTR_ON_PA_BIT+CONFIG_ETRAX_SER2_RI_ON_PA_BIT+CONFIG_ETRAX_SER2_DSR_ON_PA_BIT+CONFIG_ETRAX_SER2_CD_ON_PA_BIT)
640 #if SER2_PA_BITSUM != -4
641 # if CONFIG_ETRAX_SER2_DTR_ON_PA_BIT == -1
642 # ifndef CONFIG_ETRAX_SER2_DTR_RI_DSR_CD_MIXED
643 # define CONFIG_ETRAX_SER2_DTR_RI_DSR_CD_MIXED 1
646 # if CONFIG_ETRAX_SER2_RI_ON_PA_BIT == -1
647 # ifndef CONFIG_ETRAX_SER2_DTR_RI_DSR_CD_MIXED
648 # define CONFIG_ETRAX_SER2_DTR_RI_DSR_CD_MIXED 1
651 # if CONFIG_ETRAX_SER2_DSR_ON_PA_BIT == -1
652 # ifndef CONFIG_ETRAX_SER2_DTR_RI_DSR_CD_MIXED
653 # define CONFIG_ETRAX_SER2_DTR_RI_DSR_CD_MIXED 1
656 # if CONFIG_ETRAX_SER2_CD_ON_PA_BIT == -1
657 # ifndef CONFIG_ETRAX_SER2_DTR_RI_DSR_CD_MIXED
658 # define CONFIG_ETRAX_SER2_DTR_RI_DSR_CD_MIXED 1
663 #define SER2_PB_BITSUM (CONFIG_ETRAX_SER2_DTR_ON_PB_BIT+CONFIG_ETRAX_SER2_RI_ON_PB_BIT+CONFIG_ETRAX_SER2_DSR_ON_PB_BIT+CONFIG_ETRAX_SER2_CD_ON_PB_BIT)
665 #if SER2_PB_BITSUM != -4
666 # if CONFIG_ETRAX_SER2_DTR_ON_PB_BIT == -1
667 # ifndef CONFIG_ETRAX_SER2_DTR_RI_DSR_CD_MIXED
668 # define CONFIG_ETRAX_SER2_DTR_RI_DSR_CD_MIXED 1
671 # if CONFIG_ETRAX_SER2_RI_ON_PB_BIT == -1
672 # ifndef CONFIG_ETRAX_SER2_DTR_RI_DSR_CD_MIXED
673 # define CONFIG_ETRAX_SER2_DTR_RI_DSR_CD_MIXED 1
676 # if CONFIG_ETRAX_SER2_DSR_ON_PB_BIT == -1
677 # ifndef CONFIG_ETRAX_SER2_DTR_RI_DSR_CD_MIXED
678 # define CONFIG_ETRAX_SER2_DTR_RI_DSR_CD_MIXED 1
681 # if CONFIG_ETRAX_SER2_CD_ON_PB_BIT == -1
682 # ifndef CONFIG_ETRAX_SER2_DTR_RI_DSR_CD_MIXED
683 # define CONFIG_ETRAX_SER2_DTR_RI_DSR_CD_MIXED 1
690 #ifdef CONFIG_ETRAX_SERIAL_PORT3
692 #define SER3_PA_BITSUM (CONFIG_ETRAX_SER3_DTR_ON_PA_BIT+CONFIG_ETRAX_SER3_RI_ON_PA_BIT+CONFIG_ETRAX_SER3_DSR_ON_PA_BIT+CONFIG_ETRAX_SER3_CD_ON_PA_BIT)
694 #if SER3_PA_BITSUM != -4
695 # if CONFIG_ETRAX_SER3_DTR_ON_PA_BIT == -1
696 # ifndef CONFIG_ETRAX_SER3_DTR_RI_DSR_CD_MIXED
697 # define CONFIG_ETRAX_SER3_DTR_RI_DSR_CD_MIXED 1
700 # if CONFIG_ETRAX_SER3_RI_ON_PA_BIT == -1
701 # ifndef CONFIG_ETRAX_SER3_DTR_RI_DSR_CD_MIXED
702 # define CONFIG_ETRAX_SER3_DTR_RI_DSR_CD_MIXED 1
705 # if CONFIG_ETRAX_SER3_DSR_ON_PA_BIT == -1
706 # ifndef CONFIG_ETRAX_SER3_DTR_RI_DSR_CD_MIXED
707 # define CONFIG_ETRAX_SER3_DTR_RI_DSR_CD_MIXED 1
710 # if CONFIG_ETRAX_SER3_CD_ON_PA_BIT == -1
711 # ifndef CONFIG_ETRAX_SER3_DTR_RI_DSR_CD_MIXED
712 # define CONFIG_ETRAX_SER3_DTR_RI_DSR_CD_MIXED 1
717 #define SER3_PB_BITSUM (CONFIG_ETRAX_SER3_DTR_ON_PB_BIT+CONFIG_ETRAX_SER3_RI_ON_PB_BIT+CONFIG_ETRAX_SER3_DSR_ON_PB_BIT+CONFIG_ETRAX_SER3_CD_ON_PB_BIT)
719 #if SER3_PB_BITSUM != -4
720 # if CONFIG_ETRAX_SER3_DTR_ON_PB_BIT == -1
721 # ifndef CONFIG_ETRAX_SER3_DTR_RI_DSR_CD_MIXED
722 # define CONFIG_ETRAX_SER3_DTR_RI_DSR_CD_MIXED 1
725 # if CONFIG_ETRAX_SER3_RI_ON_PB_BIT == -1
726 # ifndef CONFIG_ETRAX_SER3_DTR_RI_DSR_CD_MIXED
727 # define CONFIG_ETRAX_SER3_DTR_RI_DSR_CD_MIXED 1
730 # if CONFIG_ETRAX_SER3_DSR_ON_PB_BIT == -1
731 # ifndef CONFIG_ETRAX_SER3_DTR_RI_DSR_CD_MIXED
732 # define CONFIG_ETRAX_SER3_DTR_RI_DSR_CD_MIXED 1
735 # if CONFIG_ETRAX_SER3_CD_ON_PB_BIT == -1
736 # ifndef CONFIG_ETRAX_SER3_DTR_RI_DSR_CD_MIXED
737 # define CONFIG_ETRAX_SER3_DTR_RI_DSR_CD_MIXED 1
745 #if defined(CONFIG_ETRAX_SER0_DTR_RI_DSR_CD_MIXED) || \
746 defined(CONFIG_ETRAX_SER1_DTR_RI_DSR_CD_MIXED) || \
747 defined(CONFIG_ETRAX_SER2_DTR_RI_DSR_CD_MIXED) || \
748 defined(CONFIG_ETRAX_SER3_DTR_RI_DSR_CD_MIXED)
749 #define CONFIG_ETRAX_SERX_DTR_RI_DSR_CD_MIXED
752 #ifdef CONFIG_ETRAX_SERX_DTR_RI_DSR_CD_MIXED
754 #define CONTROL_PINS_PORT_NOT_USED(line) \
755 &dummy_ser[line], &dummy_ser[line], \
756 &dummy_ser[line], &dummy_ser[line], \
757 &dummy_ser[line], &dummy_ser[line], \
758 &dummy_ser[line], &dummy_ser[line], \
759 DUMMY_DTR_MASK, DUMMY_RI_MASK, DUMMY_DSR_MASK, DUMMY_CD_MASK
766 volatile unsigned char *
ri_port;
770 volatile unsigned char *
cd_port;
783 #ifdef CONFIG_ETRAX_SERIAL_PORT0
799 #ifdef CONFIG_ETRAX_SERIAL_PORT1
815 #ifdef CONFIG_ETRAX_SERIAL_PORT2
831 #ifdef CONFIG_ETRAX_SERIAL_PORT3
848 #define CONTROL_PINS_PORT_NOT_USED(line) \
849 &dummy_ser[line], &dummy_ser[line], \
850 DUMMY_DTR_MASK, DUMMY_RI_MASK, DUMMY_DSR_MASK, DUMMY_CD_MASK
864 #define dtr_port port
865 #define dtr_shadow shadow
867 #define ri_shadow shadow
868 #define dsr_port port
869 #define dsr_shadow shadow
871 #define cd_shadow shadow
877 #ifdef CONFIG_ETRAX_SERIAL_PORT0
890 #ifdef CONFIG_ETRAX_SERIAL_PORT1
903 #ifdef CONFIG_ETRAX_SERIAL_PORT2
916 #ifdef CONFIG_ETRAX_SERIAL_PORT3
929 #define E100_RTS_MASK 0x20
930 #define E100_CTS_MASK 0x40
940 #define E100_RTS_GET(info) ((info)->rx_ctrl & E100_RTS_MASK)
942 #define E100_CTS_GET(info) ((info)->ioport[REG_STATUS] & E100_CTS_MASK)
946 #define E100_DTR_GET(info) ((*e100_modem_pins[(info)->line].dtr_shadow) & e100_modem_pins[(info)->line].dtr_mask)
949 #define E100_RI_GET(info) ((*e100_modem_pins[(info)->line].ri_port) & e100_modem_pins[(info)->line].ri_mask)
950 #define E100_CD_GET(info) ((*e100_modem_pins[(info)->line].cd_port) & e100_modem_pins[(info)->line].cd_mask)
953 #define E100_DSR_GET(info) ((*e100_modem_pins[(info)->line].dsr_port) & e100_modem_pins[(info)->line].dsr_mask)
956 static void update_char_time(
struct e100_serial *
info)
975 info->char_time_usec = ((bits * 1000000) / info->baud) + 1;
976 info->flush_time_usec = 4*info->char_time_usec;
988 cflag_to_baud(
unsigned int cflag)
991 0, 50, 75, 110, 134, 150, 200, 300, 600, 1200, 1800, 2400,
992 4800, 9600, 19200, 38400 };
994 static int ext_baud_table[] = {
995 0, 57600, 115200, 230400, 460800, 921600, 1843200, 6250000,
996 0, 0, 0, 0, 0, 0, 0, 0 };
999 return ext_baud_table[(cflag &
CBAUD) & ~CBAUDEX];
1001 return baud_table[cflag &
CBAUD];
1006 static unsigned char
1007 cflag_to_etrax_baud(
unsigned int cflag)
1011 static char baud_table[] = {
1012 -1, -1, -1, -1, -1, -1, -1, 0, 1, 2, -1, 3, 4, 5, 6, 7 };
1014 static char ext_baud_table[] = {
1015 -1, 8, 9, 10, 11, 12, 13, 14, -1, -1, -1, -1, -1, -1, -1, -1 };
1018 retval = ext_baud_table[(cflag &
CBAUD) & ~CBAUDEX];
1020 retval = baud_table[cflag &
CBAUD];
1023 printk(
KERN_WARNING "serdriver tried setting invalid baud rate, flags %x.\n", cflag);
1027 return retval | (retval << 4);
1041 e100_dtr(
struct e100_serial *
info,
int set)
1043 #ifndef CONFIG_SVINTO_SIM
1044 unsigned char mask = e100_modem_pins[info->line].
dtr_mask;
1046 #ifdef SERIAL_DEBUG_IO
1047 printk(
"ser%i dtr %i mask: 0x%02X\n", info->line,
set, mask);
1048 printk(
"ser%i shadow before 0x%02X get: %i\n",
1049 info->line, *e100_modem_pins[info->line].dtr_shadow,
1054 unsigned long flags;
1057 *e100_modem_pins[info->line].dtr_shadow &= ~mask;
1058 *e100_modem_pins[info->line].dtr_shadow |= (
set ? 0 :
mask);
1059 *e100_modem_pins[info->line].dtr_port = *e100_modem_pins[info->line].dtr_shadow;
1063 #ifdef SERIAL_DEBUG_IO
1064 printk(
"ser%i shadow after 0x%02X get: %i\n",
1065 info->line, *e100_modem_pins[info->line].dtr_shadow,
1075 e100_rts(
struct e100_serial *info,
int set)
1077 #ifndef CONFIG_SVINTO_SIM
1078 unsigned long flags;
1084 #ifdef SERIAL_DEBUG_IO
1085 printk(
"ser%i rts %i\n", info->line,
set);
1093 e100_ri_out(
struct e100_serial *info,
int set)
1095 #ifndef CONFIG_SVINTO_SIM
1098 unsigned char mask = e100_modem_pins[info->line].
ri_mask;
1099 unsigned long flags;
1102 *e100_modem_pins[info->line].ri_shadow &= ~mask;
1103 *e100_modem_pins[info->line].ri_shadow |= (
set ? 0 :
mask);
1104 *e100_modem_pins[info->line].ri_port = *e100_modem_pins[info->line].ri_shadow;
1110 e100_cd_out(
struct e100_serial *info,
int set)
1112 #ifndef CONFIG_SVINTO_SIM
1115 unsigned char mask = e100_modem_pins[info->line].
cd_mask;
1116 unsigned long flags;
1119 *e100_modem_pins[info->line].cd_shadow &= ~mask;
1120 *e100_modem_pins[info->line].cd_shadow |= (
set ? 0 :
mask);
1121 *e100_modem_pins[info->line].cd_port = *e100_modem_pins[info->line].cd_shadow;
1128 e100_disable_rx(
struct e100_serial *info)
1130 #ifndef CONFIG_SVINTO_SIM
1133 (info->rx_ctrl &= ~
IO_MASK(R_SERIAL0_REC_CTRL, rec_enable));
1138 e100_enable_rx(
struct e100_serial *info)
1140 #ifndef CONFIG_SVINTO_SIM
1143 (info->rx_ctrl |=
IO_MASK(R_SERIAL0_REC_CTRL, rec_enable));
1150 e100_disable_rxdma_irq(
struct e100_serial *info)
1152 #ifdef SERIAL_DEBUG_INTR
1153 printk(
"rxdma_irq(%d): 0\n",info->line);
1155 DINTR1(
DEBUG_LOG(info->line,
"IRQ disable_rxdma_irq %i\n", info->line));
1156 *R_IRQ_MASK2_CLR = (info->irq << 2) | (info->irq << 3);
1160 e100_enable_rxdma_irq(
struct e100_serial *info)
1162 #ifdef SERIAL_DEBUG_INTR
1163 printk(
"rxdma_irq(%d): 1\n",info->line);
1165 DINTR1(
DEBUG_LOG(info->line,
"IRQ enable_rxdma_irq %i\n", info->line));
1166 *R_IRQ_MASK2_SET = (info->irq << 2) | (info->irq << 3);
1171 static void e100_disable_txdma_irq(
struct e100_serial *info)
1173 #ifdef SERIAL_DEBUG_INTR
1174 printk(
"txdma_irq(%d): 0\n",info->line);
1176 DINTR1(
DEBUG_LOG(info->line,
"IRQ disable_txdma_irq %i\n", info->line));
1177 *R_IRQ_MASK2_CLR = info->irq;
1180 static void e100_enable_txdma_irq(
struct e100_serial *info)
1182 #ifdef SERIAL_DEBUG_INTR
1183 printk(
"txdma_irq(%d): 1\n",info->line);
1185 DINTR1(
DEBUG_LOG(info->line,
"IRQ enable_txdma_irq %i\n", info->line));
1186 *R_IRQ_MASK2_SET = info->irq;
1189 static void e100_disable_txdma_channel(
struct e100_serial *info)
1191 unsigned long flags;
1197 DFLOW(
DEBUG_LOG(info->line,
"disable_txdma_channel %i\n", info->line));
1198 if (info->line == 0) {
1200 IO_STATE(R_GEN_CONFIG, dma6, serial0)) {
1204 }
else if (info->line == 1) {
1206 IO_STATE(R_GEN_CONFIG, dma8, serial1)) {
1210 }
else if (info->line == 2) {
1212 IO_STATE(R_GEN_CONFIG, dma2, serial2)) {
1216 }
else if (info->line == 3) {
1218 IO_STATE(R_GEN_CONFIG, dma4, serial3)) {
1228 static void e100_enable_txdma_channel(
struct e100_serial *info)
1230 unsigned long flags;
1233 DFLOW(
DEBUG_LOG(info->line,
"enable_txdma_channel %i\n", info->line));
1235 if (info->line == 0) {
1238 }
else if (info->line == 1) {
1241 }
else if (info->line == 2) {
1244 }
else if (info->line == 3) {
1252 static void e100_disable_rxdma_channel(
struct e100_serial *info)
1254 unsigned long flags;
1260 if (info->line == 0) {
1262 IO_STATE(R_GEN_CONFIG, dma7, serial0)) {
1266 }
else if (info->line == 1) {
1268 IO_STATE(R_GEN_CONFIG, dma9, serial1)) {
1272 }
else if (info->line == 2) {
1274 IO_STATE(R_GEN_CONFIG, dma3, serial2)) {
1278 }
else if (info->line == 3) {
1280 IO_STATE(R_GEN_CONFIG, dma5, serial3)) {
1290 static void e100_enable_rxdma_channel(
struct e100_serial *info)
1292 unsigned long flags;
1296 if (info->line == 0) {
1299 }
else if (info->line == 1) {
1302 }
else if (info->line == 2) {
1305 }
else if (info->line == 3) {
1313 #ifdef SERIAL_HANDLE_EARLY_ERRORS
1318 e100_disable_serial_data_irq(
struct e100_serial *info)
1320 #ifdef SERIAL_DEBUG_INTR
1321 printk(
"ser_irq(%d): 0\n",info->line);
1323 DINTR1(
DEBUG_LOG(info->line,
"IRQ disable data_irq %i\n", info->line));
1324 *R_IRQ_MASK1_CLR = (1
U << (8+2*info->line));
1328 e100_enable_serial_data_irq(
struct e100_serial *info)
1330 #ifdef SERIAL_DEBUG_INTR
1331 printk(
"ser_irq(%d): 1\n",info->line);
1334 (1
U << (8+2*info->line)));
1337 *R_IRQ_MASK1_SET = (1
U << (8+2*info->line));
1342 e100_disable_serial_tx_ready_irq(
struct e100_serial *info)
1344 #ifdef SERIAL_DEBUG_INTR
1345 printk(
"ser_tx_irq(%d): 0\n",info->line);
1347 DINTR1(
DEBUG_LOG(info->line,
"IRQ disable ready_irq %i\n", info->line));
1348 *R_IRQ_MASK1_CLR = (1
U << (8+1+2*info->line));
1352 e100_enable_serial_tx_ready_irq(
struct e100_serial *info)
1354 #ifdef SERIAL_DEBUG_INTR
1355 printk(
"ser_tx_irq(%d): 1\n",info->line);
1358 (1
U << (8+1+2*info->line)));
1360 DINTR2(
DEBUG_LOG(info->line,
"IRQ enable ready_irq %i\n", info->line));
1361 *R_IRQ_MASK1_SET = (1
U << (8+1+2*info->line));
1364 static inline void e100_enable_rx_irq(
struct e100_serial *info)
1366 if (info->uses_dma_in)
1367 e100_enable_rxdma_irq(info);
1369 e100_enable_serial_data_irq(info);
1371 static inline void e100_disable_rx_irq(
struct e100_serial *info)
1373 if (info->uses_dma_in)
1374 e100_disable_rxdma_irq(info);
1376 e100_disable_serial_data_irq(info);
1379 #if defined(CONFIG_ETRAX_RS485)
1384 struct e100_serial * info = (
struct e100_serial *)tty->
driver_data;
1386 #
if defined(CONFIG_ETRAX_RS485_ON_PA)
1389 #if defined(CONFIG_ETRAX_RS485_ON_PORT_G)
1391 rs485_port_g_bit, 1);
1393 #if defined(CONFIG_ETRAX_RS485_LTC1387)
1395 CONFIG_ETRAX_RS485_LTC1387_DXEN_PORT_G_BIT, 1);
1397 CONFIG_ETRAX_RS485_LTC1387_RXEN_PORT_G_BIT, 1);
1403 if (info->rs485.delay_rts_before_send >= 1000)
1404 info->rs485.delay_rts_before_send = 1000;
1417 const unsigned char *
buf,
int count)
1419 struct e100_serial * info = (
struct e100_serial *)tty->
driver_data;
1429 count = rs_write(tty, buf, count);
1435 #ifdef CONFIG_ETRAX_FAST_TIMER
1437 static void rs485_toggle_rts_timer_function(
unsigned long data)
1439 struct e100_serial *info = (
struct e100_serial *)data;
1441 fast_timers_rs485[info->line].function =
NULL;
1443 #if defined(CONFIG_ETRAX_RS485_DISABLE_RECEIVER)
1444 e100_enable_rx(info);
1445 e100_enable_rx_irq(info);
1463 struct e100_serial *info = (
struct e100_serial *)tty->
driver_data;
1465 unsigned long flags;
1473 xoff =
IO_FIELD(R_SERIAL0_XOFF, xoff_char,
1476 if (tty->termios.c_iflag &
IXON ) {
1488 struct e100_serial *info = (
struct e100_serial *)tty->
driver_data;
1490 unsigned long flags;
1499 if (tty->termios.c_iflag &
IXON ) {
1504 if (!info->uses_dma_out &&
1505 info->xmit.head != info->xmit.tail && info->xmit.buf)
1506 e100_enable_serial_tx_ready_irq(info);
1537 static void rs_sched_event(
struct e100_serial *info,
int event)
1539 if (info->event & (1 << event))
1541 info->event |= 1 <<
event;
1557 transmit_chars_dma(
struct e100_serial *info)
1559 unsigned int c, sentl;
1562 #ifdef CONFIG_SVINTO_SIM
1568 if (info->xmit.tail)
1569 printk(
"Error in serial.c:transmit_chars-dma(), tail!=0\n");
1570 if (info->xmit.head != info->xmit.tail) {
1571 SIMCOUT(info->xmit.buf + info->xmit.tail,
1575 info->xmit.head = info->xmit.tail;
1576 info->tr_running = 0;
1581 *info->oclrintradr =
1582 IO_STATE(R_DMA_CH6_CLR_INTR, clr_descr,
do) |
1583 IO_STATE(R_DMA_CH6_CLR_INTR, clr_eop,
do);
1585 #ifdef SERIAL_DEBUG_INTR
1586 if (info->line == SERIAL_DEBUG_LINE)
1589 if (!info->tr_running) {
1595 descr = &info->tr_descr;
1610 info->icount.tx += sentl;
1635 info->tr_running = 0;
1637 #if defined(CONFIG_ETRAX_RS485) && defined(CONFIG_ETRAX_FAST_TIMER)
1641 rs485_toggle_rts_timer_function,
1642 (
unsigned long)info,
1643 info->char_time_usec*2,
1665 start_transmit(
struct e100_serial *info)
1668 if (info->line == SERIAL_DEBUG_LINE)
1672 info->tr_descr.sw_len = 0;
1673 info->tr_descr.hw_len = 0;
1674 info->tr_descr.status = 0;
1675 info->tr_running = 1;
1676 if (info->uses_dma_out)
1677 transmit_chars_dma(info);
1679 e100_enable_serial_tx_ready_irq(info);
1682 #ifdef CONFIG_ETRAX_SERIAL_FAST_TIMER
1683 static int serial_fast_timer_started = 0;
1684 static int serial_fast_timer_expired = 0;
1685 static void flush_timeout_function(
unsigned long data);
1686 #define START_FLUSH_FAST_TIMER_TIME(info, string, usec) {\
1687 unsigned long timer_flags; \
1688 local_irq_save(timer_flags); \
1689 if (fast_timers[info->line].function == NULL) { \
1690 serial_fast_timer_started++; \
1691 TIMERD(DEBUG_LOG(info->line, "start_timer %i ", info->line)); \
1692 TIMERD(DEBUG_LOG(info->line, "num started: %i\n", serial_fast_timer_started)); \
1693 start_one_shot_timer(&fast_timers[info->line], \
1694 flush_timeout_function, \
1695 (unsigned long)info, \
1700 TIMERD(DEBUG_LOG(info->line, "timer %i already running\n", info->line)); \
1702 local_irq_restore(timer_flags); \
1704 #define START_FLUSH_FAST_TIMER(info, string) START_FLUSH_FAST_TIMER_TIME(info, string, info->flush_time_usec)
1707 #define START_FLUSH_FAST_TIMER_TIME(info, string, usec)
1708 #define START_FLUSH_FAST_TIMER(info, string)
1711 static struct etrax_recv_buffer *
1712 alloc_recv_buffer(
unsigned int size)
1714 struct etrax_recv_buffer *
buffer;
1719 buffer->next =
NULL;
1727 append_recv_buffer(
struct e100_serial *info,
struct etrax_recv_buffer *
buffer)
1729 unsigned long flags;
1733 if (!info->first_recv_buffer)
1734 info->first_recv_buffer =
buffer;
1736 info->last_recv_buffer->next =
buffer;
1738 info->last_recv_buffer =
buffer;
1740 info->recv_cnt += buffer->length;
1741 if (info->recv_cnt > info->max_recv_cnt)
1742 info->max_recv_cnt = info->recv_cnt;
1748 add_char_and_flag(
struct e100_serial *info,
unsigned char data,
unsigned char flag)
1750 struct etrax_recv_buffer *
buffer;
1751 if (info->uses_dma_in) {
1752 if (!(buffer = alloc_recv_buffer(4)))
1756 buffer->error =
flag;
1757 buffer->buffer[0] =
data;
1759 append_recv_buffer(info, buffer);
1764 tty_insert_flip_char(tty, data, flag);
1771 static unsigned int handle_descr_data(
struct e100_serial *info,
1777 if (info->recv_cnt + recvl > 65536) {
1779 "%s: Too much pending incoming serial data! Dropping %u bytes.\n", __func__, recvl);
1783 buffer->length = recvl;
1787 info->errorcode = 0;
1789 append_recv_buffer(info, buffer);
1792 panic(
"%s: Failed to allocate memory for receive buffer!\n", __func__);
1799 static unsigned int handle_all_descr_data(
struct e100_serial *info)
1803 unsigned int ret = 0;
1807 descr = &info->rec_descr[info->cur_rec_descr];
1812 if (++info->cur_rec_descr == SERIAL_RECV_DESCRIPTORS)
1813 info->cur_rec_descr = 0;
1829 if (info->port.tty->stopped) {
1831 DEBUG_LOG(info->line,
"rx 0x%02X\n", buf[0]);
1832 DEBUG_LOG(info->line,
"rx 0x%02X\n", buf[1]);
1833 DEBUG_LOG(info->line,
"rx 0x%02X\n", buf[2]);
1838 info->icount.rx += recvl;
1840 ret += handle_descr_data(info, descr, recvl);
1846 static void receive_chars_dma(
struct e100_serial *info)
1849 unsigned char rstat;
1851 #ifdef CONFIG_SVINTO_SIM
1859 *info->iclrintradr =
1860 IO_STATE(R_DMA_CH6_CLR_INTR, clr_descr,
do) |
1861 IO_STATE(R_DMA_CH6_CLR_INTR, clr_eop,
do);
1863 tty = info->
port.tty;
1867 #ifdef SERIAL_HANDLE_EARLY_ERRORS
1868 if (info->uses_dma_in)
1869 e100_enable_serial_data_irq(info);
1873 add_char_and_flag(info,
'\0',
TTY_BREAK);
1875 handle_all_descr_data(info);
1879 if (rstat &
IO_MASK(R_SERIAL0_STATUS, xoff_detect) ) {
1887 unsigned char data = info->ioport[
REG_DATA];
1889 PROCSTAT(ser_stat[info->line].errors_cnt++);
1890 DEBUG_LOG(info->line,
"#dERR: s d 0x%04X\n",
1891 ((rstat & SER_ERROR_MASK) << 8) | data);
1898 add_char_and_flag(info, data,
TTY_FRAME);
1907 static int start_recv_dma(
struct e100_serial *info)
1910 struct etrax_recv_buffer *
buffer;
1914 for (i = 0; i < SERIAL_RECV_DESCRIPTORS; i++) {
1916 panic(
"%s: Failed to allocate memory for receive buffer!\n", __func__);
1930 info->cur_rec_descr = 0;
1933 *info->ifirstadr =
virt_to_phys(&descr[info->cur_rec_descr]);
1941 start_receive(
struct e100_serial *info)
1943 #ifdef CONFIG_SVINTO_SIM
1949 if (info->uses_dma_in) {
1952 *info->icmdadr =
IO_STATE(R_DMA_CH6_CMD,
cmd, reset);
1956 start_recv_dma(info);
1974 tr_interrupt(
int irq,
void *
dev_id)
1976 struct e100_serial *
info;
1981 #ifdef CONFIG_SVINTO_SIM
1986 const char *
s =
"What? tr_interrupt in simulator??\n";
1994 ireg = *R_IRQ_MASK2_RD;
1997 info = rs_table +
i;
1998 if (!info->enabled || !info->uses_dma_out)
2001 if (ireg & info->irq) {
2008 PROCSTAT(ser_stat[info->line].tx_dma_ints++);
2010 info->last_tx_active =
jiffies;
2011 transmit_chars_dma(info);
2023 rec_interrupt(
int irq,
void *dev_id)
2025 struct e100_serial *
info;
2030 #ifdef CONFIG_SVINTO_SIM
2035 const char *s =
"What? rec_interrupt in simulator??\n";
2043 ireg = *R_IRQ_MASK2_RD;
2046 info = rs_table +
i;
2047 if (!info->enabled || !info->uses_dma_in)
2050 if (ireg & ((info->irq << 2) | (info->irq << 3))) {
2053 receive_chars_dma(info);
2062 static int force_eop_if_needed(
struct e100_serial *info)
2067 unsigned char rstat = info->ioport[
REG_STATUS];
2070 if (rstat & SER_ERROR_MASK) {
2076 DEBUG_LOG(info->line,
"timeout err: rstat 0x%03X\n",
2077 rstat | (info->line << 8));
2084 rstat | (info->line << 8)));
2088 info->forced_eop = 0;
2096 if (!info->forced_eop) {
2097 info->forced_eop = 1;
2098 PROCSTAT(ser_stat[info->line].timeout_flush_cnt++);
2106 static void flush_to_flip_buffer(
struct e100_serial *info)
2109 struct etrax_recv_buffer *
buffer;
2110 unsigned long flags;
2113 tty = info->
port.tty;
2120 while ((buffer = info->first_recv_buffer) !=
NULL) {
2121 unsigned int count = buffer->length;
2123 tty_insert_flip_string(tty, buffer->buffer, count);
2124 info->recv_cnt -=
count;
2126 if (count == buffer->length) {
2127 info->first_recv_buffer = buffer->next;
2130 buffer->length -=
count;
2131 memmove(buffer->buffer, buffer->buffer + count, buffer->length);
2136 if (!info->first_recv_buffer)
2137 info->last_recv_buffer =
NULL;
2145 static void check_flush_timeout(
struct e100_serial *info)
2148 flush_to_flip_buffer(info);
2152 if (info->first_recv_buffer)
2159 force_eop_if_needed(info);
2162 #ifdef CONFIG_ETRAX_SERIAL_FAST_TIMER
2163 static void flush_timeout_function(
unsigned long data)
2165 struct e100_serial *info = (
struct e100_serial *)data;
2167 fast_timers[info->line].function =
NULL;
2168 serial_fast_timer_expired++;
2170 TIMERD(
DEBUG_LOG(info->line,
"num expired: %i\n", serial_fast_timer_expired));
2171 check_flush_timeout(info);
2184 timed_flush_handler(
unsigned long ptr)
2186 struct e100_serial *
info;
2189 #ifdef CONFIG_SVINTO_SIM
2194 info = rs_table +
i;
2195 if (info->uses_dma_in)
2196 check_flush_timeout(info);
2204 #ifdef SERIAL_HANDLE_EARLY_ERRORS
2275 struct e100_serial * handle_ser_rx_interrupt_no_dma(
struct e100_serial *info)
2277 unsigned long data_read;
2288 if (data_read &
IO_MASK(R_SERIAL0_READ, xoff_detect) ) {
2293 if (data_read & (
IO_MASK(R_SERIAL0_READ, framing_err) |
2294 IO_MASK(R_SERIAL0_READ, par_err) |
2298 info->last_rx_active =
jiffies;
2299 DINTR1(
DEBUG_LOG(info->line,
"ser_rx err stat_data %04X\n", data_read));
2301 if (!log_int_trig1_pos) {
2302 log_int_trig1_pos = log_int_pos;
2303 log_int(rdpc(), 0, 0);
2308 if ( ((data_read &
IO_MASK(R_SERIAL0_READ, data_in)) == 0) &&
2309 (data_read &
IO_MASK(R_SERIAL0_READ, framing_err)) ) {
2314 if (!info->break_detected_cnt) {
2315 DEBUG_LOG(info->line,
"#BRK start\n", 0);
2317 if (data_read &
IO_MASK(R_SERIAL0_READ, rxd)) {
2328 info->break_detected_cnt++;
2333 if (info->break_detected_cnt) {
2334 DEBUG_LOG(info->line,
"EBRK %i\n", info->break_detected_cnt);
2337 unsigned char data =
IO_EXTRACT(R_SERIAL0_READ,
2338 data_in, data_read);
2342 tty_insert_flip_char(tty, 0, flag);
2346 if (data_read &
IO_MASK(R_SERIAL0_READ, par_err)) {
2347 info->icount.parity++;
2350 info->icount.overrun++;
2352 }
else if (data_read &
IO_MASK(R_SERIAL0_READ, framing_err)) {
2353 info->icount.frame++;
2356 tty_insert_flip_char(tty, data, flag);
2357 info->errorcode = 0;
2359 info->break_detected_cnt = 0;
2361 }
else if (data_read &
IO_MASK(R_SERIAL0_READ, data_avail)) {
2364 if (!log_int_trig1_pos) {
2365 if (log_int_pos >= log_int_size) {
2368 log_int_trig0_pos = log_int_pos;
2369 log_int(rdpc(), 0, 0);
2372 tty_insert_flip_char(tty,
2373 IO_EXTRACT(R_SERIAL0_READ, data_in, data_read),
2376 DEBUG_LOG(info->line,
"ser_rx int but no data_avail %08lX\n", data_read);
2382 if (data_read &
IO_MASK(R_SERIAL0_READ, data_avail)) {
2383 DEBUG_LOG(info->line,
"ser_rx %c in loop\n",
IO_EXTRACT(R_SERIAL0_READ, data_in, data_read));
2391 static struct e100_serial* handle_ser_rx_interrupt(
struct e100_serial *info)
2393 unsigned char rstat;
2395 #ifdef SERIAL_DEBUG_INTR
2396 printk(
"Interrupt from serport %d\n", i);
2399 if (!info->uses_dma_in) {
2400 return handle_ser_rx_interrupt_no_dma(info);
2404 if (rstat &
IO_MASK(R_SERIAL0_STATUS, xoff_detect) ) {
2408 if (rstat & SER_ERROR_MASK) {
2412 info->last_rx_active =
jiffies;
2424 if (!info->break_detected_cnt) {
2425 DEBUG_LOG(info->line,
"#BRK start\n", 0);
2438 info->break_detected_cnt++;
2443 if (info->break_detected_cnt) {
2444 DEBUG_LOG(info->line,
"EBRK %i\n", info->break_detected_cnt);
2449 add_char_and_flag(info,
'\0',
TTY_BREAK);
2452 if (rstat & SER_PAR_ERR_MASK) {
2453 info->icount.parity++;
2456 info->icount.overrun++;
2458 }
else if (rstat & SER_FRAMING_ERR_MASK) {
2459 info->icount.frame++;
2460 add_char_and_flag(info, data,
TTY_FRAME);
2463 info->errorcode = 0;
2465 info->break_detected_cnt = 0;
2466 DEBUG_LOG(info->line,
"#iERR s d %04X\n",
2467 ((rstat & SER_ERROR_MASK) << 8) | data);
2469 PROCSTAT(ser_stat[info->line].early_errors_cnt++);
2472 unsigned long curr_time =
jiffies;
2474 if (info->break_detected_cnt) {
2481 (curr_time - info->last_rx_active) * (1000000/
HZ) +
2482 curr_time_u - info->last_rx_active_usec;
2483 if (elapsed_usec < 2*info->char_time_usec) {
2484 DEBUG_LOG(info->line,
"FBRK %i\n", info->line);
2490 DEBUG_LOG(info->line,
"Not end of BRK (V)%i\n", info->line);
2492 DEBUG_LOG(info->line,
"num brk %i\n", info->break_detected_cnt);
2495 #ifdef SERIAL_DEBUG_INTR
2496 printk(
"** OK, disabling ser_interrupts\n");
2498 e100_disable_serial_data_irq(info);
2500 info->break_detected_cnt = 0;
2502 PROCSTAT(ser_stat[info->line].ser_ints_ok_cnt++);
2510 static void handle_ser_tx_interrupt(
struct e100_serial *info)
2512 unsigned long flags;
2515 unsigned char rstat;
2516 DFLOW(
DEBUG_LOG(info->line,
"tx_int: xchar 0x%02X\n", info->x_char));
2525 e100_enable_serial_tx_ready_irq(info);
2529 if (info->uses_dma_out) {
2530 unsigned char rstat;
2537 e100_disable_serial_tx_ready_irq(info);
2538 if (info->port.tty->stopped)
2539 rs_stop(info->port.tty);
2541 e100_enable_txdma_channel(info);
2543 for(i = 6; i > 0; i--)
2546 *info->ocmdadr =
IO_STATE(R_DMA_CH6_CMD,
cmd,
continue);
2551 if (info->xmit.head == info->xmit.tail
2552 || info->port.tty->stopped
2553 || info->port.tty->hw_stopped) {
2555 info->port.tty->stopped));
2556 e100_disable_serial_tx_ready_irq(info);
2557 info->tr_running = 0;
2560 DINTR2(
DEBUG_LOG(info->line,
"tx_int %c\n", info->xmit.buf[info->xmit.tail]));
2563 info->ioport[
REG_TR_DATA] = info->xmit.buf[info->xmit.tail];
2566 if (info->xmit.head == info->xmit.tail) {
2567 #if defined(CONFIG_ETRAX_RS485) && defined(CONFIG_ETRAX_FAST_TIMER)
2571 rs485_toggle_rts_timer_function,
2572 (
unsigned long)info,
2573 info->char_time_usec*2,
2578 info->last_tx_active =
jiffies;
2579 e100_disable_serial_tx_ready_irq(info);
2580 info->tr_running = 0;
2584 e100_enable_serial_tx_ready_irq(info);
2600 ser_interrupt(
int irq,
void *dev_id)
2602 static volatile int tx_started = 0;
2603 struct e100_serial *
info;
2605 unsigned long flags;
2606 unsigned long irq_mask1_rd;
2607 unsigned long data_mask = (1 << (8+2*0));
2609 static volatile unsigned long reentered_ready_mask = 0;
2612 irq_mask1_rd = *R_IRQ_MASK1_RD;
2615 irq_mask1_rd &= e100_ser_int_mask;
2618 if (irq_mask1_rd & data_mask) {
2620 handle_ser_rx_interrupt(info);
2642 unsigned long ready_mask;
2646 irq_mask1_rd &= (
IO_MASK(R_IRQ_MASK1_RD, ser0_ready) |
2647 IO_MASK(R_IRQ_MASK1_RD, ser1_ready) |
2648 IO_MASK(R_IRQ_MASK1_RD, ser2_ready) |
2649 IO_MASK(R_IRQ_MASK1_RD, ser3_ready));
2650 while (irq_mask1_rd) {
2652 *R_IRQ_MASK1_CLR = irq_mask1_rd;
2657 ready_mask = (1 << (8+1+2*0));
2661 if (irq_mask1_rd & ready_mask) {
2663 handle_ser_tx_interrupt(info);
2671 irq_mask1_rd = reentered_ready_mask;
2676 unsigned long ready_mask;
2677 ready_mask = irq_mask1_rd & (
IO_MASK(R_IRQ_MASK1_RD, ser0_ready) |
2678 IO_MASK(R_IRQ_MASK1_RD, ser1_ready) |
2679 IO_MASK(R_IRQ_MASK1_RD, ser2_ready) |
2680 IO_MASK(R_IRQ_MASK1_RD, ser3_ready));
2682 reentered_ready_mask |= ready_mask;
2684 *R_IRQ_MASK1_CLR = ready_mask;
2685 DFLOW(
DEBUG_LOG(SERIAL_DEBUG_LINE,
"ser_int reentered with TX %X\n", ready_mask));
2712 struct e100_serial *
info;
2717 tty = info->
port.tty;
2726 startup(
struct e100_serial * info)
2728 unsigned long flags;
2729 unsigned long xmit_page;
2749 info->xmit.buf = (
unsigned char *) xmit_page;
2751 #ifdef SERIAL_DEBUG_OPEN
2752 printk(
"starting up ttyS%d (xmit_buf 0x%p)...\n", info->line, info->xmit.buf);
2755 #ifdef CONFIG_SVINTO_SIM
2762 info->xmit.head = info->xmit.tail = 0;
2763 info->first_recv_buffer = info->last_recv_buffer =
NULL;
2764 info->recv_cnt = info->max_recv_cnt = 0;
2766 for (i = 0; i < SERIAL_RECV_DESCRIPTORS; i++)
2767 info->rec_descr[i].buf =
NULL;
2783 if (info->dma_in_enabled) {
2784 info->uses_dma_in = 1;
2785 e100_enable_rxdma_channel(info);
2787 *info->icmdadr =
IO_STATE(R_DMA_CH6_CMD,
cmd, reset);
2794 *info->iclrintradr =
2795 IO_STATE(R_DMA_CH6_CLR_INTR, clr_descr,
do) |
2796 IO_STATE(R_DMA_CH6_CLR_INTR, clr_eop,
do);
2798 e100_disable_rxdma_channel(info);
2801 if (info->dma_out_enabled) {
2802 info->uses_dma_out = 1;
2803 e100_enable_txdma_channel(info);
2804 *info->ocmdadr =
IO_STATE(R_DMA_CH6_CMD,
cmd, reset);
2810 *info->oclrintradr =
2811 IO_STATE(R_DMA_CH6_CLR_INTR, clr_descr,
do) |
2812 IO_STATE(R_DMA_CH6_CLR_INTR, clr_eop,
do);
2814 e100_disable_txdma_channel(info);
2820 info->xmit.head = info->xmit.tail = 0;
2821 info->first_recv_buffer = info->last_recv_buffer =
NULL;
2822 info->recv_cnt = info->max_recv_cnt = 0;
2824 for (i = 0; i < SERIAL_RECV_DESCRIPTORS; i++)
2825 info->rec_descr[i].buf = 0;
2832 e100_enable_serial_data_irq(info);
2841 if (info->uses_dma_out)
2842 e100_enable_txdma_irq(info);
2844 e100_enable_rx_irq(info);
2846 info->tr_running = 0;
2850 start_receive(info);
2854 info->tr_descr.sw_len = 0;
2855 info->tr_descr.hw_len = 0;
2856 info->tr_descr.status = 0;
2876 shutdown(
struct e100_serial * info)
2878 unsigned long flags;
2880 struct etrax_recv_buffer *
buffer;
2883 #ifndef CONFIG_SVINTO_SIM
2886 e100_disable_rx(info);
2887 info->ioport[
REG_TR_CTRL] = (info->tx_ctrl &= ~0x40);
2890 if (info->uses_dma_in) {
2891 e100_disable_rxdma_irq(info);
2892 *info->icmdadr =
IO_STATE(R_DMA_CH6_CMD,
cmd, reset);
2893 info->uses_dma_in = 0;
2895 e100_disable_serial_data_irq(info);
2898 if (info->uses_dma_out) {
2899 e100_disable_txdma_irq(info);
2900 info->tr_running = 0;
2901 *info->ocmdadr =
IO_STATE(R_DMA_CH6_CMD,
cmd, reset);
2902 info->uses_dma_out = 0;
2904 e100_disable_serial_tx_ready_irq(info);
2905 info->tr_running = 0;
2913 #ifdef SERIAL_DEBUG_OPEN
2914 printk(
"Shutting down serial port %d (irq %d)....\n", info->line,
2920 if (info->xmit.buf) {
2921 free_page((
unsigned long)info->xmit.buf);
2922 info->xmit.buf =
NULL;
2925 for (i = 0; i < SERIAL_RECV_DESCRIPTORS; i++)
2932 if (!info->port.tty || (info->port.tty->termios.c_cflag &
HUPCL)) {
2949 change_speed(
struct e100_serial *info)
2953 unsigned long flags;
2956 if (!info->port.tty)
2961 cflag = info->port.tty->termios.c_cflag;
2968 u32 mask = 0xFF << (info->line*8);
2969 unsigned long alt_source =
2970 IO_STATE(R_ALT_SER_BAUDRATE, ser0_rec, normal) |
2971 IO_STATE(R_ALT_SER_BAUDRATE, ser0_tr, normal);
2973 DBAUD(
printk(
"Custom baudrate: baud_base/divisor %lu/%i\n",
2974 (
unsigned long)info->baud_base, info->custom_divisor));
2984 DBAUD(
printk(
"Writing SERIAL_PRESCALE: divisor %i\n", divisor));
2988 #ifdef CONFIG_ETRAX_EXTERN_PB6CLK_ENABLED
2989 else if ((info->baud_base==CONFIG_ETRAX_EXTERN_PB6CLK_FREQ/8 &&
2990 info->custom_divisor == 1) ||
2991 (info->baud_base==CONFIG_ETRAX_EXTERN_PB6CLK_FREQ &&
2992 info->custom_divisor == 8)) {
2995 IO_STATE(R_ALT_SER_BAUDRATE, ser0_rec,
extern) |
2996 IO_STATE(R_ALT_SER_BAUDRATE, ser0_tr,
extern);
2997 DBAUD(
printk(
"using external baudrate: %lu\n", CONFIG_ETRAX_EXTERN_PB6CLK_FREQ/8));
2998 info->baud = CONFIG_ETRAX_EXTERN_PB6CLK_FREQ/8;
3007 (
unsigned long)info->baud_base, info->custom_divisor);
3009 r_alt_ser_baudrate_shadow &= ~mask;
3010 r_alt_ser_baudrate_shadow |= (alt_source << (info->line*8));
3015 u32 mask = 0xFF << (info->line*8);
3016 unsigned long alt_source =
3017 IO_STATE(R_ALT_SER_BAUDRATE, ser0_rec, normal) |
3018 IO_STATE(R_ALT_SER_BAUDRATE, ser0_tr, normal);
3019 r_alt_ser_baudrate_shadow &= ~mask;
3020 r_alt_ser_baudrate_shadow |= (alt_source << (info->line*8));
3021 #ifndef CONFIG_SVINTO_SIM
3025 info->baud = cflag_to_baud(cflag);
3026 #ifndef CONFIG_SVINTO_SIM
3027 info->ioport[
REG_BAUD] = cflag_to_etrax_baud(cflag);
3031 #ifndef CONFIG_SVINTO_SIM
3035 info->rx_ctrl &= ~(
IO_MASK(R_SERIAL0_REC_CTRL, rec_bitnr) |
3036 IO_MASK(R_SERIAL0_REC_CTRL, rec_par_en) |
3037 IO_MASK(R_SERIAL0_REC_CTRL, rec_par));
3040 info->tx_ctrl &= ~(
IO_MASK(R_SERIAL0_TR_CTRL, tr_bitnr) |
3041 IO_MASK(R_SERIAL0_TR_CTRL, tr_par_en) |
3042 IO_MASK(R_SERIAL0_TR_CTRL, tr_par) |
3044 IO_MASK(R_SERIAL0_TR_CTRL, auto_cts));
3048 info->tx_ctrl |=
IO_STATE(R_SERIAL0_TR_CTRL, tr_bitnr, tr_7bit);
3049 info->rx_ctrl |=
IO_STATE(R_SERIAL0_REC_CTRL, rec_bitnr, rec_7bit);
3060 info->rx_ctrl |=
IO_STATE(R_SERIAL0_REC_CTRL, rec_par_en,
enable);
3065 info->tx_ctrl |=
IO_STATE(R_SERIAL0_TR_CTRL, tr_stick_par, stick);
3066 info->rx_ctrl |=
IO_STATE(R_SERIAL0_REC_CTRL, rec_stick_par, stick);
3070 info->tx_ctrl |=
IO_STATE(R_SERIAL0_TR_CTRL, tr_par, odd);
3071 info->rx_ctrl |=
IO_STATE(R_SERIAL0_REC_CTRL, rec_par, odd);
3083 info->rx_ctrl |=
IO_STATE(R_SERIAL0_REC_CTRL, rec_enable,
enable);
3091 if (info->port.tty->termios.c_iflag &
IXON ) {
3101 update_char_time(info);
3110 struct e100_serial *info = (
struct e100_serial *)tty->
driver_data;
3111 unsigned long flags;
3113 if (info->tr_running ||
3114 info->xmit.head == info->xmit.tail ||
3120 #ifdef SERIAL_DEBUG_FLOW
3121 printk(
"rs_flush_chars\n");
3127 start_transmit(info);
3131 static int rs_raw_write(
struct tty_struct *tty,
3132 const unsigned char *buf,
int count)
3135 struct e100_serial *info = (
struct e100_serial *)tty->
driver_data;
3136 unsigned long flags;
3140 if (!tty || !info->xmit.
buf)
3143 #ifdef SERIAL_DEBUG_DATA
3144 if (info->line == SERIAL_DEBUG_LINE)
3145 printk(
"rs_raw_write (%d), status %d\n",
3149 #ifdef CONFIG_SVINTO_SIM
3151 SIMCOUT(buf, count);
3177 memcpy(info->xmit.buf + info->xmit.head, buf, c);
3178 info->xmit.head = (info->xmit.head +
c) &
3192 if (info->xmit.head != info->xmit.tail &&
3195 !info->tr_running) {
3196 start_transmit(info);
3204 const unsigned char *buf,
int count)
3206 #if defined(CONFIG_ETRAX_RS485)
3207 struct e100_serial *info = (
struct e100_serial *)tty->
driver_data;
3214 #ifdef CONFIG_ETRAX_FAST_TIMER
3216 fast_timers_rs485[info->line].function =
NULL;
3220 #if defined(CONFIG_ETRAX_RS485_DISABLE_RECEIVER)
3221 e100_disable_rx(info);
3222 e100_enable_rx_irq(info);
3224 if (info->rs485.delay_rts_before_send > 0)
3225 msleep(info->rs485.delay_rts_before_send);
3229 count = rs_raw_write(tty, buf, count);
3231 #if defined(CONFIG_ETRAX_RS485)
3244 #ifdef CONFIG_ETRAX_FAST_TIMER
3250 get_lsr_info(info, &val);
3255 #if defined(CONFIG_ETRAX_RS485_DISABLE_RECEIVER)
3256 e100_enable_rx(info);
3257 e100_enable_rxdma_irq(info);
3271 struct e100_serial *info = (
struct e100_serial *)tty->
driver_data;
3284 struct e100_serial *info = (
struct e100_serial *)tty->
driver_data;
3294 struct e100_serial *info = (
struct e100_serial *)tty->
driver_data;
3295 unsigned long flags;
3298 info->xmit.head = info->xmit.tail = 0;
3313 static void rs_send_xchar(
struct tty_struct *tty,
char ch)
3315 struct e100_serial *info = (
struct e100_serial *)tty->
driver_data;
3316 unsigned long flags;
3318 if (info->uses_dma_out) {
3320 *info->ocmdadr =
IO_STATE(R_DMA_CH6_CMD,
cmd, hold);
3323 e100_disable_txdma_channel(info);
3333 e100_enable_serial_tx_ready_irq(info);
3348 struct e100_serial *info = (
struct e100_serial *)tty->
driver_data;
3349 #ifdef SERIAL_DEBUG_THROTTLE
3353 (
unsigned long)tty->
ldisc.chars_in_buffer(tty));
3358 if (tty->termios.c_cflag & CRTSCTS) {
3370 struct e100_serial *info = (
struct e100_serial *)tty->
driver_data;
3371 #ifdef SERIAL_DEBUG_THROTTLE
3375 (
unsigned long)tty->
ldisc.chars_in_buffer(tty));
3380 if (tty->termios.c_cflag & CRTSCTS) {
3401 get_serial_info(
struct e100_serial * info,
3414 tmp.type = info->type;
3415 tmp.line = info->line;
3416 tmp.port = (
int)info->ioport;
3417 tmp.irq = info->irq;
3418 tmp.flags = info->flags;
3419 tmp.baud_base = info->baud_base;
3420 tmp.close_delay = info->close_delay;
3421 tmp.closing_wait = info->closing_wait;
3422 tmp.custom_divisor = info->custom_divisor;
3429 set_serial_info(
struct e100_serial *info,
3433 struct e100_serial old_info;
3442 if ((new_serial.type != info->type) ||
3443 (new_serial.close_delay != info->close_delay) ||
3449 goto check_and_exit;
3452 if (info->count > 1)
3460 info->baud_base = new_serial.baud_base;
3463 info->custom_divisor = new_serial.custom_divisor;
3464 info->type = new_serial.type;
3465 info->close_delay = new_serial.close_delay;
3466 info->closing_wait = new_serial.closing_wait;
3473 retval = startup(info);
3488 get_lsr_info(
struct e100_serial * info,
unsigned int *value)
3491 #ifndef CONFIG_SVINTO_SIM
3492 unsigned long curr_time =
jiffies;
3494 unsigned long elapsed_usec =
3495 (curr_time - info->last_tx_active) * 1000000/
HZ +
3496 curr_time_usec - info->last_tx_active_usec;
3498 if (info->xmit.head != info->xmit.tail ||
3499 elapsed_usec < 2*info->char_time_usec) {
3509 #ifdef SERIAL_DEBUG_IO
3516 const struct state_str control_state_str[] = {
3528 char *get_control_state_str(
int MLines,
char *s)
3533 while (control_state_str[i].
str !=
NULL) {
3534 if (MLines & control_state_str[i].
state) {
3547 rs_break(
struct tty_struct *tty,
int break_state)
3549 struct e100_serial *info = (
struct e100_serial *)tty->
driver_data;
3550 unsigned long flags;
3556 if (break_state == -1) {
3559 info->tx_ctrl &= 0x3F;
3562 info->tx_ctrl |= (0x80 | 0x40);
3570 rs_tiocmset(
struct tty_struct *tty,
unsigned int set,
unsigned int clear)
3572 struct e100_serial *info = (
struct e100_serial *)tty->
driver_data;
3573 unsigned long flags;
3583 e100_ri_out(info, 0);
3585 e100_cd_out(info, 0);
3587 if (
set & TIOCM_RTS)
3589 if (
set & TIOCM_DTR)
3593 e100_ri_out(info, 1);
3595 e100_cd_out(info, 1);
3604 struct e100_serial *info = (
struct e100_serial *)tty->
driver_data;
3605 unsigned int result;
3606 unsigned long flags;
3620 #ifdef SERIAL_DEBUG_IO
3622 info->line, result, result);
3626 get_control_state_str(result, s);
3637 unsigned int cmd,
unsigned long arg)
3639 struct e100_serial * info = (
struct e100_serial *)tty->
driver_data;
3650 return get_serial_info(info,
3653 return set_serial_info(info,
3656 return get_lsr_info(info, (
unsigned int *) arg);
3660 info,
sizeof(
struct e100_serial)))
3664 #if defined(CONFIG_ETRAX_RS485)
3675 printk(
KERN_DEBUG "The use of this ioctl is deprecated. Use TIOCSRS485 instead\n");
3680 rs485data.delay_rts_before_send = rs485ctrl.delay_rts_before_send;
3681 rs485data.flags = 0;
3683 if (rs485ctrl.enabled)
3688 if (rs485ctrl.rts_on_send)
3693 if (rs485ctrl.rts_after_sent)
3698 return e100_enable_rs485(tty, &rs485data);
3710 return e100_enable_rs485(tty, &rs485data);
3716 &(((
struct e100_serial *)tty->
driver_data)->rs485);
3732 return e100_write_rs485(tty, rs485wr.outc, rs485wr.outc_size);
3745 struct e100_serial *info = (
struct e100_serial *)tty->
driver_data;
3750 if ((old_termios->
c_cflag & CRTSCTS) &&
3751 !(tty->termios.c_cflag &
CRTSCTS)) {
3771 struct e100_serial * info = (
struct e100_serial *)tty->
driver_data;
3772 unsigned long flags;
3786 #ifdef SERIAL_DEBUG_OPEN
3788 info->line, info->count);
3790 if ((tty->
count == 1) && (info->count != 1)) {
3799 "rs_close: bad serial port count; tty->count is 1, "
3800 "info->count is %d\n", info->count);
3803 if (--info->count < 0) {
3804 printk(
KERN_ERR "rs_close: bad serial port count for ttyS%d: %d\n",
3805 info->line, info->count);
3818 info->normal_termios = tty->termios;
3830 #ifdef SERIAL_HANDLE_EARLY_ERRORS
3831 e100_disable_serial_data_irq(info);
3834 #ifndef CONFIG_SVINTO_SIM
3835 e100_disable_rx(info);
3836 e100_disable_rx_irq(info);
3844 rs_wait_until_sent(tty,
HZ);
3849 rs_flush_buffer(tty);
3853 info->port.tty =
NULL;
3854 if (info->blocked_open) {
3855 if (info->close_delay)
3865 #if defined(CONFIG_ETRAX_RS485)
3868 #if defined(CONFIG_ETRAX_RS485_ON_PA)
3871 #if defined(CONFIG_ETRAX_RS485_ON_PORT_G)
3873 rs485_port_g_bit, 0);
3875 #if defined(CONFIG_ETRAX_RS485_LTC1387)
3877 CONFIG_ETRAX_RS485_LTC1387_DXEN_PORT_G_BIT, 0);
3879 CONFIG_ETRAX_RS485_LTC1387_RXEN_PORT_G_BIT, 0);
3887 if (info->dma_in_enabled) {
3888 free_irq(info->dma_in_irq_nbr, info);
3889 cris_free_dma(info->dma_in_nbr, info->dma_in_irq_description);
3890 info->uses_dma_in = 0;
3891 #ifdef SERIAL_DEBUG_OPEN
3893 info->dma_in_irq_description);
3896 if (info->dma_out_enabled) {
3897 free_irq(info->dma_out_irq_nbr, info);
3898 cris_free_dma(info->dma_out_nbr, info->dma_out_irq_description);
3899 info->uses_dma_out = 0;
3900 #ifdef SERIAL_DEBUG_OPEN
3902 info->dma_out_irq_description);
3910 static void rs_wait_until_sent(
struct tty_struct *tty,
int timeout)
3912 unsigned long orig_jiffies;
3913 struct e100_serial *info = (
struct e100_serial *)tty->
driver_data;
3914 unsigned long curr_time = jiffies;
3917 (curr_time - info->last_tx_active) * (1000000/
HZ) +
3918 curr_time_usec - info->last_tx_active_usec;
3925 while (info->xmit.head != info->xmit.tail ||
3926 (*info->ostatusadr & 0x007f) ||
3927 (elapsed_usec < 2*info->char_time_usec)) {
3931 if (timeout &&
time_after(jiffies, orig_jiffies + timeout))
3936 (curr_time - info->last_tx_active) * (1000000/
HZ) +
3937 curr_time_usec - info->last_tx_active_usec;
3948 struct e100_serial * info = (
struct e100_serial *)tty->
driver_data;
3950 rs_flush_buffer(tty);
3955 info->port.tty =
NULL;
3966 struct e100_serial *info)
3969 unsigned long flags;
3971 int do_clocal = 0, extra_count = 0;
3981 #ifdef SERIAL_DO_RESTART
4001 if (tty->termios.c_cflag &
CLOCAL) {
4014 #ifdef SERIAL_DEBUG_OPEN
4015 printk(
"block_til_ready before block: ttyS%d, count = %d\n",
4016 info->line, info->count);
4024 info->blocked_open++;
4034 #ifdef SERIAL_DO_RESTART
4047 if (signal_pending(
current)) {
4051 #ifdef SERIAL_DEBUG_OPEN
4052 printk(
"block_til_ready blocking: ttyS%d, count = %d\n",
4053 info->line, info->count);
4063 info->blocked_open--;
4064 #ifdef SERIAL_DEBUG_OPEN
4065 printk(
"block_til_ready after blocking: ttyS%d, count = %d\n",
4066 info->line, info->count);
4075 deinit_port(
struct e100_serial *info)
4077 if (info->dma_out_enabled) {
4078 cris_free_dma(info->dma_out_nbr, info->dma_out_irq_description);
4079 free_irq(info->dma_out_irq_nbr, info);
4081 if (info->dma_in_enabled) {
4082 cris_free_dma(info->dma_in_nbr, info->dma_in_irq_description);
4083 free_irq(info->dma_in_irq_nbr, info);
4094 struct e100_serial *
info;
4096 int allocated_resources = 0;
4098 info = rs_table + tty->
index;
4102 #ifdef SERIAL_DEBUG_OPEN
4109 info->port.tty = tty;
4120 #ifdef SERIAL_DO_RESTART
4131 if (info->count == 1) {
4132 allocated_resources = 1;
4133 if (info->dma_in_enabled) {
4136 info->dma_in_irq_flags,
4137 info->dma_in_irq_description,
4140 "falling back to non-DMA mode\n",
4141 info->dma_in_irq_description);
4144 info->dma_in_enabled = 0;
4146 info->dma_in_irq_description,
4149 free_irq(info->dma_in_irq_nbr, info);
4151 "falling back to non-DMA mode\n",
4152 info->dma_in_irq_description);
4155 info->dma_in_enabled = 0;
4157 #ifdef SERIAL_DEBUG_OPEN
4160 info->dma_in_irq_description);
4163 if (info->dma_out_enabled) {
4166 info->dma_out_irq_flags,
4167 info->dma_out_irq_description,
4170 "falling back to non-DMA mode\n",
4171 info->dma_out_irq_description);
4174 info->dma_out_enabled = 0;
4176 info->dma_out_irq_description,
4179 free_irq(info->dma_out_irq_nbr, info);
4181 "falling back to non-DMA mode\n",
4182 info->dma_out_irq_description);
4185 info->dma_out_enabled = 0;
4187 #ifdef SERIAL_DEBUG_OPEN
4190 info->dma_out_irq_description);
4199 retval = startup(info);
4201 if (allocated_resources)
4209 retval = block_til_ready(tty, filp, info);
4211 #ifdef SERIAL_DEBUG_OPEN
4212 printk(
"rs_open returning after block_til_ready with %d\n",
4215 if (allocated_resources)
4222 tty->termios = info->normal_termios;
4226 #ifdef SERIAL_DEBUG_OPEN
4227 printk(
"rs_open ttyS%d successful...\n", info->line);
4231 DFLIP(
if (info->line == SERIAL_DEBUG_LINE) {
4232 info->icount.rx = 0;
4238 #ifdef CONFIG_PROC_FS
4243 static void seq_line_info(
struct seq_file *
m,
struct e100_serial *info)
4247 seq_printf(m,
"%d: uart:E100 port:%lX irq:%d",
4248 info->line, (
unsigned long)info->ioport, info->irq);
4257 (
unsigned long)info->icount.tx,
4258 (
unsigned long)info->icount.rx);
4266 (
unsigned long)info->recv_cnt,
4267 (
unsigned long)info->max_recv_cnt);
4270 if (info->port.tty) {
4271 if (info->port.tty->stopped)
4273 (
int)info->port.tty->stopped);
4274 if (info->port.tty->hw_stopped)
4276 (
int)info->port.tty->hw_stopped);
4280 unsigned char rstat = info->ioport[
REG_STATUS];
4281 if (rstat &
IO_MASK(R_SERIAL0_STATUS, xoff_detect))
4287 if (info->icount.frame)
4288 seq_printf(m,
" fe:%lu", (
unsigned long)info->icount.frame);
4290 if (info->icount.parity)
4291 seq_printf(m,
" pe:%lu", (
unsigned long)info->icount.parity);
4293 if (info->icount.brk)
4294 seq_printf(m,
" brk:%lu", (
unsigned long)info->icount.brk);
4296 if (info->icount.overrun)
4297 seq_printf(m,
" oe:%lu", (
unsigned long)info->icount.overrun);
4318 static int crisv10_proc_show(
struct seq_file *m,
void *
v)
4322 seq_printf(m,
"serinfo:1.0 driver:%s\n", serial_version);
4327 seq_line_info(m, &rs_table[i]);
4329 #ifdef DEBUG_LOG_INCLUDED
4330 for (i = 0; i < debug_log_pos; i++) {
4336 seq_printf(m,
"debug_log %i/%i\n", i, DEBUG_LOG_SIZE);
4349 .open = crisv10_proc_open,
4359 static void show_serial_version(
void)
4362 "ETRAX 100LX serial-driver %s, "
4363 "(c) 2000-2004 Axis Communications AB\r\n",
4364 &serial_version[11]);
4373 .flush_chars = rs_flush_chars,
4374 .write_room = rs_write_room,
4375 .chars_in_buffer = rs_chars_in_buffer,
4376 .flush_buffer = rs_flush_buffer,
4378 .throttle = rs_throttle,
4379 .unthrottle = rs_unthrottle,
4380 .set_termios = rs_set_termios,
4384 .break_ctl = rs_break,
4385 .send_xchar = rs_send_xchar,
4386 .wait_until_sent = rs_wait_until_sent,
4387 .tiocmget = rs_tiocmget,
4388 .tiocmset = rs_tiocmset,
4389 #ifdef CONFIG_PROC_FS
4390 .proc_fops = &crisv10_proc_fops,
4397 struct e100_serial *
info;
4403 show_serial_version();
4407 #if !defined(CONFIG_ETRAX_SERIAL_FAST_TIMER)
4408 setup_timer(&flush_timer, timed_flush_handler, 0);
4412 #if defined(CONFIG_ETRAX_RS485)
4413 #if defined(CONFIG_ETRAX_RS485_ON_PA)
4422 #if defined(CONFIG_ETRAX_RS485_ON_PORT_G)
4424 rs485_port_g_bit)) {
4436 driver->
name =
"ttyS";
4452 for (i = 0, info = rs_table; i <
NR_PORTS; i++,info++) {
4453 if (info->enabled) {
4455 info->io_if_description)) {
4457 "Could not allocate IO pins for "
4459 info->io_if_description, i);
4464 info->uses_dma_in = 0;
4465 info->uses_dma_out = 0;
4467 info->port.tty =
NULL;
4468 info->type = PORT_ETRAX;
4469 info->tr_running = 0;
4470 info->forced_eop = 0;
4472 info->custom_divisor = 0;
4474 info->close_delay = 5*
HZ/10;
4475 info->closing_wait = 30*
HZ;
4479 info->blocked_open = 0;
4483 info->xmit.buf =
NULL;
4484 info->xmit.tail = info->xmit.head = 0;
4485 info->first_recv_buffer = info->last_recv_buffer =
NULL;
4486 info->recv_cnt = info->max_recv_cnt = 0;
4487 info->last_tx_active_usec = 0;
4488 info->last_tx_active = 0;
4490 #if defined(CONFIG_ETRAX_RS485)
4494 info->rs485.delay_rts_before_send = 0;
4499 if (info->enabled) {
4501 serial_driver->
name, info->line, info->ioport);
4507 panic(
"Couldn't register serial driver\n");
4509 #ifdef CONFIG_ETRAX_FAST_TIMER
4510 #ifdef CONFIG_ETRAX_SERIAL_FAST_TIMER
4511 memset(fast_timers, 0,
sizeof(fast_timers));
4513 #ifdef CONFIG_ETRAX_RS485
4514 memset(fast_timers_rs485, 0,
sizeof(fast_timers_rs485));
4519 #ifndef CONFIG_SVINTO_SIM
4520 #ifndef CONFIG_ETRAX_KGDB
4526 panic(
"%s: Failed to request irq8", __func__);