1 ###############################################################################
3 # Virtual DMA driver for MN10300 serial ports
5 # Copyright (C) 2007 Red Hat, Inc. All Rights Reserved.
6 # Written by David Howells (dhowells@redhat.com)
8 # This program is free software; you can redistribute it and/or
9 # modify it under the terms of the GNU General Public Licence
10 # as published by the Free Software Foundation; either version
11 # 2 of the Licence, or (at your option) any later version.
13 ###############################################################################
14 #include <linux/sys.h>
15 #include <linux/linkage.h>
18 #include <asm/cpu-regs.h>
19 #include <asm/frame.inc>
20 #include <asm/timer-regs.h>
21 #include <proc/cache.h>
22 #include <unit/timex.h>
23 #include "mn10300-serial.h"
34 ###############################################################################
36 # serial port interrupt virtual DMA entry point
37 # - intended to run at interrupt priority 1 (not affected by local_irq_disable)
39 ###############################################################################
40 .balign L1_CACHE_BYTES
41 ENTRY(mn10300_serial_vdma_interrupt)
42 # or EPSW_IE,psw # permit overriding by
43 # debugging interrupts
44 movm [d2,d3,a2,a3,exreg0],(sp)
46 movhu (IAGR),a2 # see if which interrupt is
50 add mn10300_serial_int_tbl,a2
57 ###############################################################################
59 # serial port receive interrupt virtual DMA entry point
60 # - intended to run at interrupt priority 1 (not affected by local_irq_disable)
61 # - stores data/status byte pairs in the ring buffer
62 # - induces a scheduler tick timer interrupt when done, which we then subvert
64 # A3 struct mn10300_serial_port *
67 ###############################################################################
68 ENTRY(mn10300_serial_vdma_rx_handler)
71 movbu d2,(e3) # ACK the interrupt
77 and MNSC_BUFFER_SIZE-1,d3
80 beq mnsc_vdma_rx_overflow
82 mov (__rx_buffer,a3),d2
89 bset MNSCx_RX_AVAIL,(__intr_flags,a3)
93 mov GxICR_LEVEL_6|GxICR_ENABLE|GxICR_REQUEST|GxICR_DETECT,d2
94 movhu d2,(a2) # request a slow interrupt
97 movm (sp),[d2,d3,a2,a3,exreg0]
100 mnsc_vdma_rx_overflow:
101 bset MNSCx_RX_OVERF,(__intr_flags,a3)
102 bra mnsc_vdma_rx_done
104 ###############################################################################
106 # serial port transmit interrupt virtual DMA entry point
107 # - intended to run at interrupt priority 1 (not affected by local_irq_disable)
108 # - retrieves data bytes from the ring buffer and passes them to the serial port
109 # - induces a scheduler tick timer interrupt when done, which we then subvert
110 # A3 struct mn10300_serial_port *
113 ###############################################################################
114 .balign L1_CACHE_BYTES
115 ENTRY(mn10300_serial_vdma_tx_handler)
118 movbu d2,(e3) # ACK the interrupt
119 movhu (e3),d2 # flush
121 btst 0x01,(__tx_break,a3) # handle transmit break request
122 bne mnsc_vdma_tx_break
124 movbu (SCxSTR,e2),d2 # don't try and transmit a char if the
125 # buffer is not empty
126 btst SC01STR_TBF,d2 # (may have tried to jumpstart)
127 bne mnsc_vdma_tx_noint
129 movbu (__tx_xchar,a3),d2 # handle hi-pri XON/XOFF
131 bne mnsc_vdma_tx_xchar
133 mov (__uart_state,a3),a2 # see if the TTY Tx queue has anything in it
134 mov (__xmit_tail,a2),d3
135 mov (__xmit_head,a2),d2
137 beq mnsc_vdma_tx_empty
139 mov (__xmit_buffer,a2),d2 # get a char from the buffer and
142 movbu d2,(SCxTXB,e2) # Tx
144 inc d3 # advance the buffer pointer
145 and __UART_XMIT_SIZE-1,d3
146 mov (__xmit_head,a2),d2
147 mov d3,(__xmit_tail,a2)
149 sub d3,d2 # see if we've written everything
150 beq mnsc_vdma_tx_empty
152 and __UART_XMIT_SIZE-1,d2 # see if we just made a hole
153 cmp __UART_XMIT_SIZE-2,d2
154 beq mnsc_vdma_tx_made_hole
158 mov GxICR_LEVEL_6|GxICR_ENABLE|GxICR_REQUEST|GxICR_DETECT,d2
159 movhu d2,(a2) # request a slow interrupt
160 movhu (a2),d2 # flush
163 movm (sp),[d2,d3,a2,a3,exreg0]
167 mov +(NUM2GxICR_LEVEL(CONFIG_MN10300_SERIAL_IRQ_LEVEL)|GxICR_DETECT),d2
168 movhu d2,(e3) # disable the interrupt
169 movhu (e3),d2 # flush
171 bset MNSCx_TX_EMPTY,(__intr_flags,a3)
172 bra mnsc_vdma_tx_done
175 movhu (SCxCTR,e2),d2 # turn on break mode
178 mov +(NUM2GxICR_LEVEL(CONFIG_MN10300_SERIAL_IRQ_LEVEL)|GxICR_DETECT),d2
179 movhu d2,(e3) # disable transmit interrupts on this
181 movhu (e3),d2 # flush
182 bra mnsc_vdma_tx_noint
185 bclr 0xff,(__tx_xchar,a3)
187 bra mnsc_vdma_tx_done
189 mnsc_vdma_tx_made_hole:
190 bset MNSCx_TX_SPACE,(__intr_flags,a3)
191 bra mnsc_vdma_tx_done