1 #include <linux/interrupt.h>
2 #include <linux/ioport.h>
9 static void start_serial_interrupt(int irq
);
11 static const struct old_serial_port rs_table
[] = {
14 static const struct old_serial_port
*serstate
;
17 const struct old_serial_port
*spk_serial_init(int index
)
19 int baud
= 9600, quot
= 0;
20 unsigned int cval
= 0;
21 int cflag
= CREAD
| HUPCL
| CLOCAL
| B9600
| CS8
;
22 const struct old_serial_port
*ser
= rs_table
+ index
;
25 /* Divisor, bytesize and parity */
26 quot
= ser
->baud_base
/ baud
;
27 cval
= cflag
& (CSIZE
| CSTOPB
);
28 #if defined(__powerpc__) || defined(__alpha__)
30 #else /* !__powerpc__ && !__alpha__ */
32 #endif /* !__powerpc__ && !__alpha__ */
34 cval
|= UART_LCR_PARITY
;
35 if (!(cflag
& PARODD
))
36 cval
|= UART_LCR_EPAR
;
37 if (synth_request_region(ser
->port
, 8)) {
38 /* try to take it back. */
39 printk(KERN_INFO
"Ports not available, trying to steal them\n");
40 __release_region(&ioport_resource
, ser
->port
, 8);
41 err
= synth_request_region(ser
->port
, 8);
43 pr_warn("Unable to allocate port at %x, errno %i",
49 /* Disable UART interrupts, set DTR and RTS high
51 outb(cval
| UART_LCR_DLAB
, ser
->port
+ UART_LCR
); /* set DLAB */
52 outb(quot
& 0xff, ser
->port
+ UART_DLL
); /* LS of divisor */
53 outb(quot
>> 8, ser
->port
+ UART_DLM
); /* MS of divisor */
54 outb(cval
, ser
->port
+ UART_LCR
); /* reset DLAB */
56 /* Turn off Interrupts */
57 outb(0, ser
->port
+ UART_IER
);
58 outb(UART_MCR_DTR
| UART_MCR_RTS
, ser
->port
+ UART_MCR
);
60 /* If we read 0xff from the LSR, there is no UART here. */
61 if (inb(ser
->port
+ UART_LSR
) == 0xff) {
62 synth_release_region(ser
->port
, 8);
68 speakup_info
.port_tts
= ser
->port
;
71 start_serial_interrupt(ser
->irq
);
76 static irqreturn_t
synth_readbuf_handler(int irq
, void *dev_id
)
79 /*printk(KERN_ERR "in irq\n"); */
80 /*pr_warn("in IRQ\n"); */
83 while (inb_p(speakup_info
.port_tts
+ UART_LSR
) & UART_LSR_DR
) {
85 c
= inb_p(speakup_info
.port_tts
+UART_RX
);
86 synth
->read_buff_add((u_char
) c
);
87 /*printk(KERN_ERR "c = %d\n", c); */
88 /*pr_warn("C = %d\n", c); */
94 static void start_serial_interrupt(int irq
)
98 if (synth
->read_buff_add
== NULL
)
101 rv
= request_irq(irq
, synth_readbuf_handler
, IRQF_SHARED
,
102 "serial", (void *) synth_readbuf_handler
);
105 printk(KERN_ERR
"Unable to request Speakup serial I R Q\n");
107 outb(UART_MCR_DTR
| UART_MCR_RTS
| UART_MCR_OUT2
,
108 speakup_info
.port_tts
+ UART_MCR
);
109 /* Turn on Interrupts */
110 outb(UART_IER_MSI
|UART_IER_RLSI
|UART_IER_RDI
,
111 speakup_info
.port_tts
+ UART_IER
);
112 inb(speakup_info
.port_tts
+UART_LSR
);
113 inb(speakup_info
.port_tts
+UART_RX
);
114 inb(speakup_info
.port_tts
+UART_IIR
);
115 inb(speakup_info
.port_tts
+UART_MSR
);
116 outb(1, speakup_info
.port_tts
+ UART_FCR
); /* Turn FIFO On */
119 void stop_serial_interrupt(void)
121 if (speakup_info
.port_tts
== 0)
124 if (synth
->read_buff_add
== NULL
)
127 /* Turn off interrupts */
128 outb(0, speakup_info
.port_tts
+UART_IER
);
130 free_irq(serstate
->irq
, (void *) synth_readbuf_handler
);
133 int wait_for_xmitr(void)
135 int tmout
= SPK_XMITR_TIMEOUT
;
136 if ((synth
->alive
) && (timeouts
>= NUM_DISABLE_TIMEOUTS
)) {
137 pr_warn("%s: too many timeouts, deactivating speakup\n",
140 /* No synth any more, so nobody will restart TTYs, and we thus
141 * need to do it ourselves. Now that there is no synth we can
142 * let application flood anyway */
143 speakup_start_ttys();
147 while (spk_serial_tx_busy()) {
149 pr_warn("%s: timed out (tx busy)\n", synth
->long_name
);
155 tmout
= SPK_CTS_TIMEOUT
;
156 while (!((inb_p(speakup_info
.port_tts
+ UART_MSR
)) & UART_MSR_CTS
)) {
159 /* pr_warn("%s: timed out (cts)\n",
160 * synth->long_name); */
170 unsigned char spk_serial_in(void)
172 int tmout
= SPK_SERIAL_TIMEOUT
;
174 while (!(inb_p(speakup_info
.port_tts
+ UART_LSR
) & UART_LSR_DR
)) {
176 pr_warn("time out while waiting for input.\n");
181 return inb_p(speakup_info
.port_tts
+ UART_RX
);
183 EXPORT_SYMBOL_GPL(spk_serial_in
);
185 unsigned char spk_serial_in_nowait(void)
189 lsr
= inb_p(speakup_info
.port_tts
+ UART_LSR
);
190 if (!(lsr
& UART_LSR_DR
))
192 return inb_p(speakup_info
.port_tts
+ UART_RX
);
194 EXPORT_SYMBOL_GPL(spk_serial_in_nowait
);
196 int spk_serial_out(const char ch
)
198 if (synth
->alive
&& wait_for_xmitr()) {
199 outb_p(ch
, speakup_info
.port_tts
);
204 EXPORT_SYMBOL_GPL(spk_serial_out
);
206 void spk_serial_release(void)
208 if (speakup_info
.port_tts
== 0)
210 synth_release_region(speakup_info
.port_tts
, 8);
211 speakup_info
.port_tts
= 0;
213 EXPORT_SYMBOL_GPL(spk_serial_release
);