1 // SPDX-License-Identifier: GPL-2.0+
3 * written by: Kirk Reiser <kirk@braille.uwo.ca>
4 * this version considerably modified by David Borowski, david575@rogers.com
6 * Copyright (C) 1998-99 Kirk Reiser.
7 * Copyright (C) 2003 David Borowski.
9 * this code is specificly written as a driver for the speakup screenreview
10 * package and is not a general device driver.
11 * This driver is for the Aicom Acent PC internal synthesizer.
14 #include <linux/jiffies.h>
15 #include <linux/sched.h>
16 #include <linux/timer.h>
17 #include <linux/kthread.h>
22 #include "speakup_acnt.h" /* local header file for Accent values */
24 #define DRV_VERSION "2.10"
25 #define PROCSPEECH '\r'
27 static int synth_probe(struct spk_synth
*synth
);
28 static void accent_release(void);
29 static const char *synth_immediate(struct spk_synth
*synth
, const char *buf
);
30 static void do_catch_up(struct spk_synth
*synth
);
31 static void synth_flush(struct spk_synth
*synth
);
33 static int synth_port_control
;
34 static int port_forced
;
35 static unsigned int synth_portlist
[] = { 0x2a8, 0 };
37 static struct var_t vars
[] = {
38 { CAPS_START
, .u
.s
= {"\033P8" } },
39 { CAPS_STOP
, .u
.s
= {"\033P5" } },
40 { RATE
, .u
.n
= {"\033R%c", 9, 0, 17, 0, 0, "0123456789abcdefgh" } },
41 { PITCH
, .u
.n
= {"\033P%d", 5, 0, 9, 0, 0, NULL
} },
42 { VOL
, .u
.n
= {"\033A%d", 5, 0, 9, 0, 0, NULL
} },
43 { TONE
, .u
.n
= {"\033V%d", 5, 0, 9, 0, 0, NULL
} },
44 { DIRECT
, .u
.n
= {NULL
, 0, 0, 1, 0, 0, NULL
} },
49 * These attributes will appear in /sys/accessibility/speakup/acntpc.
51 static struct kobj_attribute caps_start_attribute
=
52 __ATTR(caps_start
, 0644, spk_var_show
, spk_var_store
);
53 static struct kobj_attribute caps_stop_attribute
=
54 __ATTR(caps_stop
, 0644, spk_var_show
, spk_var_store
);
55 static struct kobj_attribute pitch_attribute
=
56 __ATTR(pitch
, 0644, spk_var_show
, spk_var_store
);
57 static struct kobj_attribute rate_attribute
=
58 __ATTR(rate
, 0644, spk_var_show
, spk_var_store
);
59 static struct kobj_attribute tone_attribute
=
60 __ATTR(tone
, 0644, spk_var_show
, spk_var_store
);
61 static struct kobj_attribute vol_attribute
=
62 __ATTR(vol
, 0644, spk_var_show
, spk_var_store
);
64 static struct kobj_attribute delay_time_attribute
=
65 __ATTR(delay_time
, 0644, spk_var_show
, spk_var_store
);
66 static struct kobj_attribute direct_attribute
=
67 __ATTR(direct
, 0644, spk_var_show
, spk_var_store
);
68 static struct kobj_attribute full_time_attribute
=
69 __ATTR(full_time
, 0644, spk_var_show
, spk_var_store
);
70 static struct kobj_attribute jiffy_delta_attribute
=
71 __ATTR(jiffy_delta
, 0644, spk_var_show
, spk_var_store
);
72 static struct kobj_attribute trigger_time_attribute
=
73 __ATTR(trigger_time
, 0644, spk_var_show
, spk_var_store
);
76 * Create a group of attributes so that we can create and destroy them all
79 static struct attribute
*synth_attrs
[] = {
80 &caps_start_attribute
.attr
,
81 &caps_stop_attribute
.attr
,
82 &pitch_attribute
.attr
,
86 &delay_time_attribute
.attr
,
87 &direct_attribute
.attr
,
88 &full_time_attribute
.attr
,
89 &jiffy_delta_attribute
.attr
,
90 &trigger_time_attribute
.attr
,
91 NULL
, /* need to NULL terminate the list of attributes */
94 static struct spk_synth synth_acntpc
= {
96 .version
= DRV_VERSION
,
97 .long_name
= "Accent PC",
98 .init
= "\033=X \033Oi\033T2\033=M\033N1\n",
99 .procspeech
= PROCSPEECH
,
100 .clear
= SYNTH_CLEAR
,
105 .startup
= SYNTH_START
,
106 .checkval
= SYNTH_CHECK
,
108 .io_ops
= &spk_serial_io_ops
,
109 .probe
= synth_probe
,
110 .release
= accent_release
,
111 .synth_immediate
= synth_immediate
,
112 .catch_up
= do_catch_up
,
113 .flush
= synth_flush
,
114 .is_alive
= spk_synth_is_alive_nop
,
115 .synth_adjust
= NULL
,
116 .read_buff_add
= NULL
,
125 .attrs
= synth_attrs
,
130 static inline bool synth_writable(void)
132 return inb_p(synth_port_control
) & SYNTH_WRITABLE
;
135 static inline bool synth_full(void)
137 return inb_p(speakup_info
.port_tts
+ UART_RX
) == 'F';
140 static const char *synth_immediate(struct spk_synth
*synth
, const char *buf
)
144 while ((ch
= *buf
)) {
145 int timeout
= SPK_XMITR_TIMEOUT
;
151 while (synth_writable()) {
156 outb_p(ch
, speakup_info
.port_tts
);
162 static void do_catch_up(struct spk_synth
*synth
)
166 unsigned long jiff_max
;
171 struct var_t
*delay_time
;
172 struct var_t
*full_time
;
173 struct var_t
*jiffy_delta
;
175 jiffy_delta
= spk_get_var(JIFFY
);
176 delay_time
= spk_get_var(DELAY
);
177 full_time
= spk_get_var(FULL
);
179 spin_lock_irqsave(&speakup_info
.spinlock
, flags
);
180 jiffy_delta_val
= jiffy_delta
->u
.n
.value
;
181 spin_unlock_irqrestore(&speakup_info
.spinlock
, flags
);
183 jiff_max
= jiffies
+ jiffy_delta_val
;
184 while (!kthread_should_stop()) {
185 spin_lock_irqsave(&speakup_info
.spinlock
, flags
);
186 if (speakup_info
.flushing
) {
187 speakup_info
.flushing
= 0;
188 spin_unlock_irqrestore(&speakup_info
.spinlock
, flags
);
192 synth_buffer_skip_nonlatin1();
193 if (synth_buffer_empty()) {
194 spin_unlock_irqrestore(&speakup_info
.spinlock
, flags
);
197 set_current_state(TASK_INTERRUPTIBLE
);
198 full_time_val
= full_time
->u
.n
.value
;
199 spin_unlock_irqrestore(&speakup_info
.spinlock
, flags
);
201 schedule_timeout(msecs_to_jiffies(full_time_val
));
204 set_current_state(TASK_RUNNING
);
205 timeout
= SPK_XMITR_TIMEOUT
;
206 while (synth_writable()) {
211 spin_lock_irqsave(&speakup_info
.spinlock
, flags
);
212 ch
= synth_buffer_getc();
213 spin_unlock_irqrestore(&speakup_info
.spinlock
, flags
);
216 outb_p(ch
, speakup_info
.port_tts
);
217 if (time_after_eq(jiffies
, jiff_max
) && ch
== SPACE
) {
218 timeout
= SPK_XMITR_TIMEOUT
;
219 while (synth_writable()) {
224 outb_p(PROCSPEECH
, speakup_info
.port_tts
);
225 spin_lock_irqsave(&speakup_info
.spinlock
, flags
);
226 jiffy_delta_val
= jiffy_delta
->u
.n
.value
;
227 delay_time_val
= delay_time
->u
.n
.value
;
228 spin_unlock_irqrestore(&speakup_info
.spinlock
, flags
);
229 schedule_timeout(msecs_to_jiffies(delay_time_val
));
230 jiff_max
= jiffies
+ jiffy_delta_val
;
233 timeout
= SPK_XMITR_TIMEOUT
;
234 while (synth_writable()) {
239 outb_p(PROCSPEECH
, speakup_info
.port_tts
);
242 static void synth_flush(struct spk_synth
*synth
)
244 outb_p(SYNTH_CLEAR
, speakup_info
.port_tts
);
247 static int synth_probe(struct spk_synth
*synth
)
249 unsigned int port_val
= 0;
252 pr_info("Probing for %s.\n", synth
->long_name
);
254 speakup_info
.port_tts
= port_forced
;
255 pr_info("probe forced to %x by kernel command line\n",
256 speakup_info
.port_tts
);
257 if (synth_request_region(speakup_info
.port_tts
- 1,
259 pr_warn("sorry, port already reserved\n");
262 port_val
= inw(speakup_info
.port_tts
- 1);
263 synth_port_control
= speakup_info
.port_tts
- 1;
265 for (i
= 0; synth_portlist
[i
]; i
++) {
266 if (synth_request_region(synth_portlist
[i
],
269 ("request_region: failed with 0x%x, %d\n",
270 synth_portlist
[i
], SYNTH_IO_EXTENT
);
273 port_val
= inw(synth_portlist
[i
]) & 0xfffc;
274 if (port_val
== 0x53fc) {
275 /* 'S' and out&input bits */
276 synth_port_control
= synth_portlist
[i
];
277 speakup_info
.port_tts
= synth_port_control
+ 1;
283 if (port_val
!= 0x53fc) {
284 /* 'S' and out&input bits */
285 pr_info("%s: not found\n", synth
->long_name
);
286 synth_release_region(synth_port_control
, SYNTH_IO_EXTENT
);
287 synth_port_control
= 0;
290 pr_info("%s: %03x-%03x, driver version %s,\n", synth
->long_name
,
291 synth_port_control
, synth_port_control
+ SYNTH_IO_EXTENT
- 1,
297 static void accent_release(void)
299 spk_stop_serial_interrupt();
300 if (speakup_info
.port_tts
)
301 synth_release_region(speakup_info
.port_tts
- 1,
303 speakup_info
.port_tts
= 0;
306 module_param_hw_named(port
, port_forced
, int, ioport
, 0444);
307 module_param_named(start
, synth_acntpc
.startup
, short, 0444);
309 MODULE_PARM_DESC(port
, "Set the port for the synthesizer (override probing).");
310 MODULE_PARM_DESC(start
, "Start the synthesizer once it is loaded.");
312 module_spk_synth(synth_acntpc
);
314 MODULE_AUTHOR("Kirk Reiser <kirk@braille.uwo.ca>");
315 MODULE_AUTHOR("David Borowski");
316 MODULE_DESCRIPTION("Speakup support for Accent PC synthesizer");
317 MODULE_LICENSE("GPL");
318 MODULE_VERSION(DRV_VERSION
);