From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: by befuddled.reisers.ca (Postfix, from userid 65534) id 0A4451F0A34; Sat, 25 Feb 2017 14:27:18 -0500 (EST) Received: from mail-wm0-x243.google.com (mail-wm0-x243.google.com [IPv6:2a00:1450:400c:c09::243]) by befuddled.reisers.ca (Postfix) with ESMTPS id 2B0431F0A3E for ; Sat, 25 Feb 2017 14:27:00 -0500 (EST) Received: by mail-wm0-x243.google.com with SMTP id m70so7689532wma.1 for ; Sat, 25 Feb 2017 11:27:00 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=date:from:to:cc:subject:message-id:mime-version:content-disposition :in-reply-to:user-agent; bh=nuD6z8HIo6WFjYzZCSaj2Oac0LUPpdBPIECtddkh9GE=; b=h4Yjb6rYdzcTczGQIsbp9ATe4jiC7AH/aeWrl9Cjs6WIlr5J6bPL4X3TZOYfnzOH7l CTnfsS8nKptL36E4I3AJYJtOiC5JPv+rQ/oDjGVJxdjrNJ1Dc6OQtGc8Y7Zrq3vGi7Px rSzIA320cjcHbt8mHsOIqWgizIkHLGVdrrC7SE4k2wIIEa0XHHrheZfXfRaBzHHlhdvm DuKf0qsj+IZB92KLoY0z+QyOHAakOPdWtKgb6WPPykSka2CYALx6VWNwJntVm6zTEsjS t6uU7RJ9qt8+e9Ragxuvo1YptCPIeamxvxgBBqOlwx4m1f69Vdb0ODQhaXD8Kp1nDDFC XUVQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:date:from:to:cc:subject:message-id:mime-version :content-disposition:in-reply-to:user-agent; bh=nuD6z8HIo6WFjYzZCSaj2Oac0LUPpdBPIECtddkh9GE=; b=ZjoP/4WCiRzedqw/+nFcgVBwb+0+aYtAEjnU4z2glZflBXLKE/OBxWdDRbtaXg1O/d dXVlXRyq+I0Dcz4fgE7fz3kDbFWUBxX1lS5jTyi79GaAIE6m9MaVlGeHiu+/9D5s9ih6 nA2hXprcJ1RLZ2aphVxkcuXBtdjJ4bHJY4UlkXEKFa7a+nWwTttW3xK71kUqU2NX2Fnw ueTKZR7uFDw85PfbKGIFdl1Jf9ybaIGooJwUOSe5X34z1qlYxO8geRClJ/JyXkA+cPei psXUNj5B04911lmJS+rujZvWB4sIKLERhKBpVFhVd0LVFDeJwVDGoZTiOd8Gw4/kb4rm 3oug== X-Gm-Message-State: AMke39l0u8/QslLXIRQad7LbC1Z47uVlMr64svTrn1Zb/NGwq1WD5ksR1Yvi5PNErFEBuA== X-Received: by 10.28.48.78 with SMTP id w75mr7936684wmw.55.1488050819133; Sat, 25 Feb 2017 11:26:59 -0800 (PST) Received: from sanghar (cpc91372-watf11-2-0-cust614.15-2.cable.virginm.net. [86.14.2.103]) by smtp.gmail.com with ESMTPSA id d29sm7412071wmi.19.2017.02.25.11.26.58 (version=TLS1 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Sat, 25 Feb 2017 11:26:58 -0800 (PST) Date: Sat, 25 Feb 2017 19:26:57 +0000 From: Okash Khawaja To: samuel.thibault@ens-lyon.org Cc: speakup@linux-speakup.org Subject: [patch 4/6] staging: speakup: Add spk_ttyio Message-ID: <20170225192657.GA4513@sanghar> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20170225192526.GA4507@sanghar> User-Agent: Mutt/1.7.2 (2016-11-26) X-Bogosity: Ham, tests=bogofilter, spamicity=0.000000, version=1.2.4 X-BeenThere: speakup@linux-speakup.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: "Speakup is a screen review system for Linux." List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Sat, 25 Feb 2017 19:27:19 -0000 This adds spk_ttyio.c file. It contains a set of functions which implement those methods in spk_synth struct which relate to sending bytes out using serial comms. Implementations in this file perform the same function but using TTY subsystem instead. Currently synths access serial ports, directly poking standard ISA ports by trying to steal them from serial driver. Some ISA cards actually need this way of doing it, but most other synthesizers don't, and can actually work by using the proper TTY subsystem through a new N_SPEAKUP line discipline. So this adds the methods for drivers to switch to accessing serial ports through the TTY subsystem, whenever appropriate. Signed-off-by: Okash Khawaja Index: linux-stable/drivers/staging/speakup/Makefile =================================================================== --- linux-stable.orig/drivers/staging/speakup/Makefile +++ linux-stable/drivers/staging/speakup/Makefile @@ -25,6 +25,7 @@ kobjects.o \ selection.o \ serialio.o \ + spk_ttyio.o \ synth.o \ thread.o \ varhandlers.o Index: linux-stable/drivers/staging/speakup/spk_priv.h =================================================================== --- linux-stable.orig/drivers/staging/speakup/spk_priv.h +++ linux-stable/drivers/staging/speakup/spk_priv.h @@ -46,7 +46,9 @@ unsigned char spk_serial_in(void); unsigned char spk_serial_in_nowait(void); int spk_serial_out(struct spk_synth *in_synth, const char ch); +int spk_ttyio_out(struct spk_synth *in_synth, const char ch); void spk_serial_release(void); +void spk_ttyio_release(void); char synth_buffer_getc(void); char synth_buffer_peek(void); @@ -58,7 +60,9 @@ const char *buf, size_t count); int spk_serial_synth_probe(struct spk_synth *synth); +int spk_ttyio_synth_probe(struct spk_synth *synth); const char *spk_synth_immediate(struct spk_synth *synth, const char *buff); +const char *spk_ttyio_immediate(struct spk_synth *synth, const char *buff); void spk_do_catch_up(struct spk_synth *synth); void spk_synth_flush(struct spk_synth *synth); int spk_synth_is_alive_nop(struct spk_synth *synth); Index: linux-stable/drivers/staging/speakup/spk_ttyio.c =================================================================== --- /dev/null +++ linux-stable/drivers/staging/speakup/spk_ttyio.c @@ -0,0 +1,148 @@ +#include +#include + +#include "speakup.h" +#include "spk_types.h" + +struct tty_struct *speakup_tty; +EXPORT_SYMBOL_GPL(speakup_tty); + +static int spk_ttyio_ldisc_open(struct tty_struct *tty) +{ + if (tty->ops->write == NULL) + return -EOPNOTSUPP; + speakup_tty = tty; + + return 0; +} + +static void spk_ttyio_ldisc_close(struct tty_struct *tty) +{ + speakup_tty = NULL; +} + +static struct tty_ldisc_ops spk_ttyio_ldisc_ops = { + .owner = THIS_MODULE, + .magic = TTY_LDISC_MAGIC, + .name = "speakup_ldisc", + .open = spk_ttyio_ldisc_open, + .close = spk_ttyio_ldisc_close, +}; + +static int spk_ttyio_initialise_ldisc(void) +{ + int ret = 0; + struct tty_struct *tty; + + ret = tty_register_ldisc(N_SPEAKUP, &spk_ttyio_ldisc_ops); + if (ret) { + pr_err("speakup_test_init(): Error registering line discipline.\n"); + return ret; + } + + tty = tty_open_by_driver(MKDEV(4, 64), NULL, NULL); + if (IS_ERR(tty)) + return PTR_ERR(tty); + + if (tty->ops->open) + ret = tty->ops->open(tty, NULL); + else + ret = -ENODEV; + + if (ret) { + tty_unlock(tty); + return ret; + } + + clear_bit(TTY_HUPPED, &tty->flags); + tty_unlock(tty); + + ret = tty_set_ldisc(tty, N_SPEAKUP); + + return ret; +} + +int spk_ttyio_synth_probe(struct spk_synth *synth) +{ + int rv = spk_ttyio_initialise_ldisc(); + + if (rv) + return rv; + + synth->alive = 1; + + return 0; +} +EXPORT_SYMBOL_GPL(spk_ttyio_synth_probe); + +void spk_ttyio_release(void) +{ + int idx; + + if (!speakup_tty) + return; + + tty_lock(speakup_tty); + idx = speakup_tty->index; + +#if 0 + if (tty_release_checks(tty, idx)) { + tty_unlock(tty); + return 0; + } +#endif + + if (speakup_tty->ops->close) + speakup_tty->ops->close(speakup_tty, NULL); + + tty_ldisc_flush(speakup_tty); + tty_unlock(speakup_tty); + tty_ldisc_release(speakup_tty); +#if 0 + tty_flush_works(tty); +#endif +#if 0 + mutex_lock(&tty_mutex); + release_tty(tty, idx); + mutex_unlock(&tty_mutex); +#endif +} +EXPORT_SYMBOL_GPL(spk_ttyio_release); + +int spk_ttyio_out(struct spk_synth *in_synth, const char ch) +{ + if (in_synth->alive && speakup_tty && speakup_tty->ops->write) { + int ret = speakup_tty->ops->write(speakup_tty, &ch, 1); + if (ret == 0) + /* No room */ + return 0; + if (ret < 0) { + pr_warn("%s: I/O error, deactivating speakup\n", in_synth->long_name); + /* No synth any more, so nobody will restart TTYs, and we thus + * need to do it ourselves. Now that there is no synth we can + * let application flood anyway + */ + in_synth->alive = 0; + speakup_start_ttys(); + return 0; + } + return 1; + } + return 0; +} +EXPORT_SYMBOL_GPL(spk_ttyio_out); + +const char *spk_ttyio_immediate(struct spk_synth *synth, const char *buff) +{ + u_char ch; + + while ((ch = *buff)) { + if (ch == '\n') + ch = synth->procspeech; + if (tty_write_room(speakup_tty) < 1 || !spk_ttyio_out(synth, ch)) + return buff; + buff++; + } + return NULL; +} +EXPORT_SYMBOL_GPL(spk_ttyio_immediate); Index: linux-stable/include/uapi/linux/tty.h =================================================================== --- linux-stable.orig/include/uapi/linux/tty.h +++ linux-stable/include/uapi/linux/tty.h @@ -35,5 +35,6 @@ #define N_TRACESINK 23 /* Trace data routing for MIPI P1149.7 */ #define N_TRACEROUTER 24 /* Trace data routing for MIPI P1149.7 */ #define N_NCI 25 /* NFC NCI UART */ +#define N_SPEAKUP 26 /* Speakup communication with synths*/ #endif /* _UAPI_LINUX_TTY_H */ Index: linux-stable/drivers/tty/tty_ldisc.c =================================================================== --- linux-stable.orig/drivers/tty/tty_ldisc.c +++ linux-stable/drivers/tty/tty_ldisc.c @@ -603,6 +603,8 @@ return retval; } +EXPORT_SYMBOL(tty_set_ldisc); + /** * tty_ldisc_kill - teardown ldisc * @tty: tty being released @@ -795,6 +797,8 @@ tty_ldisc_debug(tty, "released\n"); } +EXPORT_SYMBOL(tty_ldisc_release); + /** * tty_ldisc_init - ldisc setup for new tty * @tty: tty being allocated