1 /* speakup_soft.c - speakup driver to register and make available
2 * a user space device for software synthesizers. written by: Kirk
3 * Reiser <kirk@braille.uwo.ca>
5 * Copyright (C) 2003 Kirk Reiser.
7 * This program is free software; you can redistribute it and/or modify
8 * it under the terms of the GNU General Public License as published by
9 * the Free Software Foundation; either version 2 of the License, or
10 * (at your option) any later version.
12 * This program is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 * GNU General Public License for more details.
17 * You should have received a copy of the GNU General Public License
18 * along with this program; if not, write to the Free Software
19 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
21 * this code is specificly written as a driver for the speakup screenreview
22 * package and is not a general device driver. */
24 #include <linux/unistd.h>
25 #include <linux/miscdevice.h> /* for misc_register, and SYNTH_MINOR */
26 #include <linux/poll.h> /* for poll_wait() */
27 #include <linux/sched.h> /* schedule(), signal_pending(), TASK_INTERRUPTIBLE */
32 #define DRV_VERSION "2.6"
33 #define SOFTSYNTH_MINOR 26 /* might as well give it one more than /dev/synth */
34 #define PROCSPEECH 0x0d
35 #define CLEAR_SYNTH 0x18
37 static int softsynth_probe(struct spk_synth
*synth
);
38 static void softsynth_release(void);
39 static int softsynth_is_alive(struct spk_synth
*synth
);
40 static unsigned char get_index(void);
42 static struct miscdevice synth_device
;
43 static int initialized
;
44 static int misc_registered
;
46 static struct var_t vars
[] = {
47 { CAPS_START
, .u
.s
= {"\x01+3p" } },
48 { CAPS_STOP
, .u
.s
= {"\x01-3p" } },
49 { RATE
, .u
.n
= {"\x01%ds", 5, 0, 9, 0, 0, NULL
} },
50 { PITCH
, .u
.n
= {"\x01%dp", 5, 0, 9, 0, 0, NULL
} },
51 { VOL
, .u
.n
= {"\x01%dv", 5, 0, 9, 0, 0, NULL
} },
52 { TONE
, .u
.n
= {"\x01%dx", 1, 0, 2, 0, 0, NULL
} },
53 { PUNCT
, .u
.n
= {"\x01%db", 0, 0, 2, 0, 0, NULL
} },
54 { VOICE
, .u
.n
= {"\x01%do", 0, 0, 7, 0, 0, NULL
} },
55 { FREQUENCY
, .u
.n
= {"\x01%df", 5, 0, 9, 0, 0, NULL
} },
56 { DIRECT
, .u
.n
= {NULL
, 0, 0, 1, 0, 0, NULL
} },
61 * These attributes will appear in /sys/accessibility/speakup/soft.
63 static struct kobj_attribute caps_start_attribute
=
64 __ATTR(caps_start
, USER_RW
, spk_var_show
, spk_var_store
);
65 static struct kobj_attribute caps_stop_attribute
=
66 __ATTR(caps_stop
, USER_RW
, spk_var_show
, spk_var_store
);
67 static struct kobj_attribute freq_attribute
=
68 __ATTR(freq
, USER_RW
, spk_var_show
, spk_var_store
);
69 static struct kobj_attribute pitch_attribute
=
70 __ATTR(pitch
, USER_RW
, spk_var_show
, spk_var_store
);
71 static struct kobj_attribute punct_attribute
=
72 __ATTR(punct
, USER_RW
, spk_var_show
, spk_var_store
);
73 static struct kobj_attribute rate_attribute
=
74 __ATTR(rate
, USER_RW
, spk_var_show
, spk_var_store
);
75 static struct kobj_attribute tone_attribute
=
76 __ATTR(tone
, USER_RW
, spk_var_show
, spk_var_store
);
77 static struct kobj_attribute voice_attribute
=
78 __ATTR(voice
, USER_RW
, spk_var_show
, spk_var_store
);
79 static struct kobj_attribute vol_attribute
=
80 __ATTR(vol
, USER_RW
, spk_var_show
, spk_var_store
);
83 * We should uncomment the following definition, when we agree on a
84 * method of passing a language designation to the software synthesizer.
85 * static struct kobj_attribute lang_attribute =
86 * __ATTR(lang, USER_RW, spk_var_show, spk_var_store);
89 static struct kobj_attribute delay_time_attribute
=
90 __ATTR(delay_time
, ROOT_W
, spk_var_show
, spk_var_store
);
91 static struct kobj_attribute direct_attribute
=
92 __ATTR(direct
, USER_RW
, spk_var_show
, spk_var_store
);
93 static struct kobj_attribute full_time_attribute
=
94 __ATTR(full_time
, ROOT_W
, spk_var_show
, spk_var_store
);
95 static struct kobj_attribute jiffy_delta_attribute
=
96 __ATTR(jiffy_delta
, ROOT_W
, spk_var_show
, spk_var_store
);
97 static struct kobj_attribute trigger_time_attribute
=
98 __ATTR(trigger_time
, ROOT_W
, spk_var_show
, spk_var_store
);
101 * Create a group of attributes so that we can create and destroy them all
104 static struct attribute
*synth_attrs
[] = {
105 &caps_start_attribute
.attr
,
106 &caps_stop_attribute
.attr
,
107 &freq_attribute
.attr
,
108 /* &lang_attribute.attr, */
109 &pitch_attribute
.attr
,
110 &punct_attribute
.attr
,
111 &rate_attribute
.attr
,
112 &tone_attribute
.attr
,
113 &voice_attribute
.attr
,
115 &delay_time_attribute
.attr
,
116 &direct_attribute
.attr
,
117 &full_time_attribute
.attr
,
118 &jiffy_delta_attribute
.attr
,
119 &trigger_time_attribute
.attr
,
120 NULL
, /* need to NULL terminate the list of attributes */
123 static struct spk_synth synth_soft
= {
125 .version
= DRV_VERSION
,
126 .long_name
= "software synth",
127 .init
= "\01@\x01\x31y\n",
128 .procspeech
= PROCSPEECH
,
133 .startup
= SYNTH_START
,
134 .checkval
= SYNTH_CHECK
,
136 .probe
= softsynth_probe
,
137 .release
= softsynth_release
,
138 .synth_immediate
= NULL
,
141 .is_alive
= softsynth_is_alive
,
142 .synth_adjust
= NULL
,
143 .read_buff_add
= NULL
,
144 .get_index
= get_index
,
146 .command
= "\x01%di",
152 .attrs
= synth_attrs
,
157 static char *get_initstring(void)
163 memset(buf
, 0, sizeof(buf
));
165 var
= synth_soft
.vars
;
166 while (var
->var_id
!= MAXVARS
) {
167 if (var
->var_id
!= CAPS_START
&& var
->var_id
!= CAPS_STOP
168 && var
->var_id
!= DIRECT
)
169 cp
= cp
+ sprintf(cp
, var
->u
.n
.synth_fmt
,
173 cp
= cp
+ sprintf(cp
, "\n");
177 static int softsynth_open(struct inode
*inode
, struct file
*fp
)
180 /*if ((fp->f_flags & O_ACCMODE) != O_RDONLY) */
183 if (synth_soft
.alive
) {
187 synth_soft
.alive
= 1;
192 static int softsynth_close(struct inode
*inode
, struct file
*fp
)
196 synth_soft
.alive
= 0;
199 /* Make sure we let applications go before leaving */
200 speakup_start_ttys();
204 static ssize_t
softsynth_read(struct file
*fp
, char *buf
, size_t count
,
217 prepare_to_wait(&speakup_event
, &wait
, TASK_INTERRUPTIBLE
);
218 if (!synth_buffer_empty() || speakup_info
.flushing
)
221 if (fp
->f_flags
& O_NONBLOCK
) {
222 finish_wait(&speakup_event
, &wait
);
225 if (signal_pending(current
)) {
226 finish_wait(&speakup_event
, &wait
);
232 finish_wait(&speakup_event
, &wait
);
235 init
= get_initstring();
236 while (chars_sent
< count
) {
237 if (speakup_info
.flushing
) {
238 speakup_info
.flushing
= 0;
240 } else if (synth_buffer_empty()) {
242 } else if (!initialized
) {
250 ch
= synth_buffer_getc();
253 if (copy_to_user(cp
, &ch
, 1))
260 empty
= synth_buffer_empty();
263 speakup_start_ttys();
269 static int last_index
;
271 static ssize_t
softsynth_write(struct file
*fp
, const char *buf
, size_t count
,
274 unsigned long supplied_index
= 0;
277 converted
= kstrtoul_from_user(buf
, count
, 0, &supplied_index
);
282 last_index
= supplied_index
;
286 static unsigned int softsynth_poll(struct file
*fp
,
287 struct poll_table_struct
*wait
)
291 poll_wait(fp
, &speakup_event
, wait
);
294 if (!synth_buffer_empty() || speakup_info
.flushing
)
295 ret
= POLLIN
| POLLRDNORM
;
300 static unsigned char get_index(void)
308 static const struct file_operations softsynth_fops
= {
309 .owner
= THIS_MODULE
,
310 .poll
= softsynth_poll
,
311 .read
= softsynth_read
,
312 .write
= softsynth_write
,
313 .open
= softsynth_open
,
314 .release
= softsynth_close
,
318 static int softsynth_probe(struct spk_synth
*synth
)
321 if (misc_registered
!= 0)
323 memset(&synth_device
, 0, sizeof(synth_device
));
324 synth_device
.minor
= SOFTSYNTH_MINOR
;
325 synth_device
.name
= "softsynth";
326 synth_device
.fops
= &softsynth_fops
;
327 if (misc_register(&synth_device
)) {
328 pr_warn("Couldn't initialize miscdevice /dev/softsynth.\n");
333 pr_info("initialized device: /dev/softsynth, node (MAJOR 10, MINOR 26)\n");
337 static void softsynth_release(void)
339 misc_deregister(&synth_device
);
341 pr_info("unregistered /dev/softsynth\n");
344 static int softsynth_is_alive(struct spk_synth
*synth
)
346 if (synth_soft
.alive
)
351 module_param_named(start
, synth_soft
.startup
, short, S_IRUGO
);
353 MODULE_PARM_DESC(start
, "Start the synthesizer once it is loaded.");
356 static int __init
soft_init(void)
358 return synth_add(&synth_soft
);
361 static void __exit
soft_exit(void)
363 synth_remove(&synth_soft
);
366 module_init(soft_init
);
367 module_exit(soft_exit
);
368 MODULE_AUTHOR("Kirk Reiser <kirk@braille.uwo.ca>");
369 MODULE_DESCRIPTION("Speakup userspace software synthesizer support");
370 MODULE_LICENSE("GPL");
371 MODULE_VERSION(DRV_VERSION
);