summaryrefslogtreecommitdiffstats
path: root/drivers/staging/speakup/devsynth.c
diff options
context:
space:
mode:
authorWilliam Hubbs <w.d.hubbs@gmail.com>2010-10-07 13:20:02 -0500
committerGreg Kroah-Hartman <gregkh@suse.de>2010-10-07 19:22:31 -0700
commitc6e3fd22cd538365bfeb82997d5b89562e077d42 (patch)
tree5eaa170c9003abc7b24ab340ccabe889cba47992 /drivers/staging/speakup/devsynth.c
parente59fe083f683ca2ca56abefad290d110808a6fb5 (diff)
downloadop-kernel-dev-c6e3fd22cd538365bfeb82997d5b89562e077d42.zip
op-kernel-dev-c6e3fd22cd538365bfeb82997d5b89562e077d42.tar.gz
Staging: add speakup to the staging directory
Speakup is a kernel based screen review package for the linux operating system. It allows blind users to interact with applications on the linux console by means of synthetic speech. The authors and maintainers of this code include the following: Kirk Reiser, Andy Berdan, John Covici, Brian and David Borowski, Christopher Brannon, Samuel Thibault and William Hubbs. Signed-off-by: William Hubbs <w.d.hubbs@gmail.com> Signed-off-by: Samuel Thibault <samuel.thibault@ens-lyon.org> Signed-off-by: Greg Kroah-Hartman <gregkh@suse.de>
Diffstat (limited to 'drivers/staging/speakup/devsynth.c')
-rw-r--r--drivers/staging/speakup/devsynth.c92
1 files changed, 92 insertions, 0 deletions
diff --git a/drivers/staging/speakup/devsynth.c b/drivers/staging/speakup/devsynth.c
new file mode 100644
index 0000000..a465653
--- /dev/null
+++ b/drivers/staging/speakup/devsynth.c
@@ -0,0 +1,92 @@
+#include <linux/errno.h>
+#include <linux/miscdevice.h> /* for misc_register, and SYNTH_MINOR */
+#include <linux/types.h>
+#include <linux/uaccess.h>
+
+#include "speakup.h"
+#include "spk_priv.h"
+
+#ifndef SYNTH_MINOR
+#define SYNTH_MINOR 25
+#endif
+
+static int misc_registered;
+static int dev_opened;
+
+static ssize_t speakup_file_write(struct file *fp, const char *buffer,
+ size_t nbytes, loff_t *ppos)
+{
+ size_t count = nbytes;
+ const char *ptr = buffer;
+ int bytes;
+ unsigned long flags;
+ u_char buf[256];
+ if (synth == NULL)
+ return -ENODEV;
+ while (count > 0) {
+ bytes = min_t(size_t, count, sizeof(buf));
+ if (copy_from_user(buf, ptr, bytes))
+ return -EFAULT;
+ count -= bytes;
+ ptr += bytes;
+ spk_lock(flags);
+ synth_write(buf, bytes);
+ spk_unlock(flags);
+ }
+ return (ssize_t) nbytes;
+}
+
+static ssize_t speakup_file_read(struct file *fp, char *buf, size_t nbytes, loff_t *ppos)
+{
+ return 0;
+}
+
+static int speakup_file_open(struct inode *ip, struct file *fp)
+{
+ if (synth == NULL)
+ return -ENODEV;
+ if (xchg(&dev_opened, 1))
+ return -EBUSY;
+ return 0;
+}
+
+static int speakup_file_release(struct inode *ip, struct file *fp)
+{
+ dev_opened = 0;
+ return 0;
+}
+
+static struct file_operations synth_fops = {
+ .read = speakup_file_read,
+ .write = speakup_file_write,
+ .open = speakup_file_open,
+ .release = speakup_file_release,
+};
+
+static struct miscdevice synth_device = {
+ .minor = SYNTH_MINOR,
+ .name = "synth",
+ .fops = &synth_fops,
+};
+
+void speakup_register_devsynth(void)
+{
+ if (misc_registered != 0)
+ return;
+/* zero it so if register fails, deregister will not ref invalid ptrs */
+ if (misc_register(&synth_device))
+ pr_warn("Couldn't initialize miscdevice /dev/synth.\n");
+ else {
+ pr_info("initialized device: /dev/synth, node (MAJOR %d, MINOR %d)\n", MISC_MAJOR, SYNTH_MINOR);
+ misc_registered = 1;
+ }
+}
+
+void speakup_unregister_devsynth(void)
+{
+ if (!misc_registered)
+ return;
+ pr_info("speakup: unregistering synth device /dev/synth\n");
+ misc_deregister(&synth_device);
+ misc_registered = 0;
+}
OpenPOWER on IntegriCloud