]> git.proxmox.com Git - mirror_ubuntu-hirsute-kernel.git/blame - drivers/staging/speakup/speakup_soft.c
Staging: add speakup to the staging directory
[mirror_ubuntu-hirsute-kernel.git] / drivers / staging / speakup / speakup_soft.c
CommitLineData
c6e3fd22
WH
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>
4 *
5 * Copyright (C) 2003 Kirk Reiser.
6 *
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.
11 *
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.
16 *
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
20 *
21 * this code is specificly written as a driver for the speakup screenreview
22 * package and is not a general device driver. */
23
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 */
28
29#include "spk_priv.h"
30#include "speakup.h"
31
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
36
37static int softsynth_probe(struct spk_synth *synth);
38static void softsynth_release(void);
39static int softsynth_is_alive(struct spk_synth *synth);
40static unsigned char get_index(void);
41
42static struct miscdevice synth_device;
43static int initialized = 0;
44static int misc_registered;
45
46static 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 }},
57 V_LAST_VAR
58};
59
60/*
61 * These attributes will appear in /sys/accessibility/speakup/soft.
62 */
63static struct kobj_attribute caps_start_attribute =
64 __ATTR(caps_start, USER_RW, spk_var_show, spk_var_store);
65static struct kobj_attribute caps_stop_attribute =
66 __ATTR(caps_stop, USER_RW, spk_var_show, spk_var_store);
67static struct kobj_attribute freq_attribute =
68 __ATTR(freq, USER_RW, spk_var_show, spk_var_store);
69//static struct kobj_attribute lang_attribute =
70// __ATTR(lang, USER_RW, spk_var_show, spk_var_store);
71static struct kobj_attribute pitch_attribute =
72 __ATTR(pitch, USER_RW, spk_var_show, spk_var_store);
73static struct kobj_attribute punct_attribute =
74 __ATTR(punct, USER_RW, spk_var_show, spk_var_store);
75static struct kobj_attribute rate_attribute =
76 __ATTR(rate, USER_RW, spk_var_show, spk_var_store);
77static struct kobj_attribute tone_attribute =
78 __ATTR(tone, USER_RW, spk_var_show, spk_var_store);
79static struct kobj_attribute voice_attribute =
80 __ATTR(voice, USER_RW, spk_var_show, spk_var_store);
81static struct kobj_attribute vol_attribute =
82 __ATTR(vol, USER_RW, spk_var_show, spk_var_store);
83
84static struct kobj_attribute delay_time_attribute =
85 __ATTR(delay_time, ROOT_W, spk_var_show, spk_var_store);
86static struct kobj_attribute direct_attribute =
87 __ATTR(direct, USER_RW, spk_var_show, spk_var_store);
88static struct kobj_attribute full_time_attribute =
89 __ATTR(full_time, ROOT_W, spk_var_show, spk_var_store);
90static struct kobj_attribute jiffy_delta_attribute =
91 __ATTR(jiffy_delta, ROOT_W, spk_var_show, spk_var_store);
92static struct kobj_attribute trigger_time_attribute =
93 __ATTR(trigger_time, ROOT_W, spk_var_show, spk_var_store);
94
95/*
96 * Create a group of attributes so that we can create and destroy them all
97 * at once.
98 */
99static struct attribute *synth_attrs[] = {
100 &caps_start_attribute.attr,
101 &caps_stop_attribute.attr,
102 &freq_attribute.attr,
103// &lang_attribute.attr,
104 &pitch_attribute.attr,
105 &punct_attribute.attr,
106 &rate_attribute.attr,
107 &tone_attribute.attr,
108 &voice_attribute.attr,
109 &vol_attribute.attr,
110 &delay_time_attribute.attr,
111 &direct_attribute.attr,
112 &full_time_attribute.attr,
113 &jiffy_delta_attribute.attr,
114 &trigger_time_attribute.attr,
115 NULL, /* need to NULL terminate the list of attributes */
116};
117
118static struct spk_synth synth_soft = {
119 .name = "soft",
120 .version = DRV_VERSION,
121 .long_name = "software synth",
122 .init = "\01@\x01\x31y\n",
123 .procspeech = PROCSPEECH,
124 .delay = 0,
125 .trigger = 0,
126 .jiffies = 0,
127 .full = 0,
128 .startup = SYNTH_START,
129 .checkval = SYNTH_CHECK,
130 .vars = vars,
131 .probe = softsynth_probe,
132 .release = softsynth_release,
133 .synth_immediate = NULL,
134 .catch_up = NULL,
135 .flush = NULL,
136 .is_alive = softsynth_is_alive,
137 .synth_adjust = NULL,
138 .read_buff_add = NULL,
139 .get_index = get_index,
140 .indexing = {
141 .command = "\x01%di",
142 .lowindex = 1,
143 .highindex = 5,
144 .currindex = 1,
145 },
146 .attributes = {
147 .attrs = synth_attrs,
148 .name = "soft",
149 },
150};
151
152static char *get_initstring(void)
153{
154 static char buf[40];
155 char *cp;
156 struct var_t *var;
157
158 memset(buf, 0, sizeof(buf));
159 cp = buf;
160 var = synth_soft.vars;
161 while (var->var_id != MAXVARS) {
162 if (var->var_id != CAPS_START && var->var_id != CAPS_STOP
163 && var->var_id != DIRECT)
164 cp = cp + sprintf(cp, var->u.n.synth_fmt, var->u.n.value);
165 var++;
166 }
167 cp = cp + sprintf(cp, "\n");
168 return buf;
169}
170
171static int softsynth_open(struct inode *inode, struct file *fp)
172{
173 unsigned long flags;
174 /*if ((fp->f_flags & O_ACCMODE) != O_RDONLY) */
175 /* return -EPERM; */
176 spk_lock(flags);
177 if (synth_soft.alive) {
178 spk_unlock(flags);
179 return -EBUSY;
180 }
181 synth_soft.alive = 1;
182 spk_unlock(flags);
183 return 0;
184}
185
186static int softsynth_close(struct inode *inode, struct file *fp)
187{
188 unsigned long flags;
189 spk_lock(flags);
190 synth_soft.alive = 0;
191 initialized = 0;
192 spk_unlock(flags);
193 /* Make sure we let applications go before leaving */
194 speakup_start_ttys();
195 return 0;
196}
197
198static ssize_t softsynth_read(struct file *fp, char *buf, size_t count,
199 loff_t *pos)
200{
201 int chars_sent = 0;
202 char *cp;
203 char *init;
204 char ch;
205 int empty;
206 unsigned long flags;
207 DEFINE_WAIT(wait);
208
209 spk_lock(flags);
210 while (1) {
211 prepare_to_wait(&speakup_event, &wait, TASK_INTERRUPTIBLE);
212 if (!synth_buffer_empty() || speakup_info.flushing)
213 break;
214 spk_unlock(flags);
215 if (fp->f_flags & O_NONBLOCK) {
216 finish_wait(&speakup_event, &wait);
217 return -EAGAIN;
218 }
219 if (signal_pending(current)) {
220 finish_wait(&speakup_event, &wait);
221 return -ERESTARTSYS;
222 }
223 schedule();
224 spk_lock(flags);
225 }
226 finish_wait(&speakup_event, &wait);
227
228 cp = buf;
229 init = get_initstring();
230 while (chars_sent < count) {
231 if (speakup_info.flushing) {
232 speakup_info.flushing = 0;
233 ch = '\x18';
234 } else if (synth_buffer_empty()) {
235 break;
236 } else if (! initialized) {
237 if (*init) {
238 ch = *init;
239 init++;
240 } else {
241 initialized = 1;
242 }
243 } else {
244 ch = synth_buffer_getc();
245 }
246 spk_unlock(flags);
247 if (copy_to_user(cp, &ch, 1))
248 return -EFAULT;
249 spk_lock(flags);
250 chars_sent++;
251 cp++;
252 }
253 *pos += chars_sent;
254 empty = synth_buffer_empty();
255 spk_unlock(flags);
256 if (empty) {
257 speakup_start_ttys();
258 *pos = 0;
259 }
260 return chars_sent;
261}
262
263static int last_index = 0;
264
265static ssize_t softsynth_write(struct file *fp, const char *buf, size_t count,
266 loff_t *pos)
267{
268 char indbuf[5];
269 if (count >= sizeof(indbuf))
270 return -EINVAL;
271
272 if (copy_from_user(indbuf, buf, count))
273 return -EFAULT;
274 indbuf[4] = 0;
275
276 last_index = simple_strtoul(indbuf, NULL, 0);
277 return count;
278}
279
280static unsigned int softsynth_poll(struct file *fp,
281 struct poll_table_struct *wait)
282{
283 unsigned long flags;
284 int ret = 0;
285 poll_wait(fp, &speakup_event, wait);
286
287 spk_lock(flags);
288 if (! synth_buffer_empty() || speakup_info.flushing)
289 ret = POLLIN | POLLRDNORM;
290 spk_unlock(flags);
291 return ret;
292}
293
294static unsigned char get_index(void)
295{
296 int rv;
297 rv = last_index;
298 last_index = 0;
299 return rv;
300}
301
302static struct file_operations softsynth_fops = {
303 .owner = THIS_MODULE,
304 .poll = softsynth_poll,
305 .read = softsynth_read,
306 .write = softsynth_write,
307 .open = softsynth_open,
308 .release = softsynth_close,
309};
310
311
312static int softsynth_probe(struct spk_synth *synth)
313{
314
315 if (misc_registered != 0)
316 return 0;
317 memset(&synth_device, 0, sizeof(synth_device));
318 synth_device.minor = SOFTSYNTH_MINOR;
319 synth_device.name = "softsynth";
320 synth_device.fops = &softsynth_fops;
321 if (misc_register(&synth_device)) {
322 pr_warn("Couldn't initialize miscdevice /dev/softsynth.\n");
323 return -ENODEV;
324 }
325
326 misc_registered = 1;
327 pr_info("initialized device: /dev/softsynth, node (MAJOR 10, MINOR 26)\n");
328 return 0;
329}
330
331static void softsynth_release(void)
332{
333 misc_deregister(&synth_device);
334 misc_registered = 0;
335 pr_info("unregistered /dev/softsynth\n");
336}
337
338static int softsynth_is_alive(struct spk_synth *synth)
339{
340 if (synth_soft.alive)
341 return 1;
342 return 0;
343}
344
345module_param_named(start, synth_soft.startup, short, S_IRUGO);
346
347MODULE_PARM_DESC(start, "Start the synthesizer once it is loaded.");
348
349
350static int __init soft_init(void)
351{
352 return synth_add(&synth_soft);
353}
354
355static void __exit soft_exit(void)
356{
357 synth_remove(&synth_soft);
358}
359
360module_init(soft_init);
361module_exit(soft_exit);
362MODULE_AUTHOR("Kirk Reiser <kirk@braille.uwo.ca>");
363MODULE_DESCRIPTION("Speakup userspace software synthesizer support");
364MODULE_LICENSE("GPL");
365MODULE_VERSION(DRV_VERSION);
366