diff options
author | Okash Khawaja <okash.khawaja@gmail.com> | 2017-04-29 20:52:58 +0100 |
---|---|---|
committer | Greg Kroah-Hartman <gregkh@linuxfoundation.org> | 2017-05-15 12:31:43 +0200 |
commit | ca693dcd5c02645063210e2352ff4909d9ddc7e9 (patch) | |
tree | 35d64c9b7b31a3babba861d56af0410281bd7ff3 /drivers/staging/speakup | |
parent | 2a3e1437c1e3f5ef30d2bb533ca083d5da9c86f2 (diff) |
staging: speakup: make input functionality swappable
This moves functions which take input from external synth, into struct
spk_io_ops. The calling code then uses serial implementation of those methods
through spk_io_ops. That way we can add a parallel TTY-based implementation and
simply replace serial with TTY. That is what the next patch in this series does.
speakup_decext.c has get_last_char function which reads the most recent
available character from the synth. This patch changes that by defining
read_buff_add callback method of spk_syth and letting that update the last_char
global character read from the synth. read_buff_add is called from ISR, so
there is a possibility for last_char to be stale. Therefore it is marked as
volatile. It also pulls a repeated get_index implementation into synth.c, to
be used as a utility function.
Signed-off-by: Okash Khawaja <okash.khawaja@gmail.com>
Reviewed-by: Samuel Thibault <samuel.thibault@ens-lyon.org>
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
Diffstat (limited to 'drivers/staging/speakup')
-rw-r--r-- | drivers/staging/speakup/serialio.c | 10 | ||||
-rw-r--r-- | drivers/staging/speakup/speakup_audptr.c | 4 | ||||
-rw-r--r-- | drivers/staging/speakup/speakup_decext.c | 14 | ||||
-rw-r--r-- | drivers/staging/speakup/speakup_dectlk.c | 4 | ||||
-rw-r--r-- | drivers/staging/speakup/speakup_dtlk.c | 2 | ||||
-rw-r--r-- | drivers/staging/speakup/speakup_ltlk.c | 4 | ||||
-rw-r--r-- | drivers/staging/speakup/speakup_soft.c | 4 | ||||
-rw-r--r-- | drivers/staging/speakup/speakup_spkout.c | 2 | ||||
-rw-r--r-- | drivers/staging/speakup/spk_priv.h | 3 | ||||
-rw-r--r-- | drivers/staging/speakup/spk_types.h | 4 | ||||
-rw-r--r-- | drivers/staging/speakup/synth.c | 10 |
11 files changed, 33 insertions, 28 deletions
diff --git a/drivers/staging/speakup/serialio.c b/drivers/staging/speakup/serialio.c index ba060d0ceca2..5f96b5ba7acb 100644 --- a/drivers/staging/speakup/serialio.c +++ b/drivers/staging/speakup/serialio.c @@ -28,11 +28,15 @@ static int timeouts; static int spk_serial_out(struct spk_synth *in_synth, const char ch); static void spk_serial_send_xchar(char ch); static void spk_serial_tiocmset(unsigned int set, unsigned int clear); +static unsigned char spk_serial_in(void); +static unsigned char spk_serial_in_nowait(void); struct spk_io_ops spk_serial_io_ops = { .synth_out = spk_serial_out, .send_xchar = spk_serial_send_xchar, .tiocmset = spk_serial_tiocmset, + .synth_in = spk_serial_in, + .synth_in_nowait = spk_serial_in_nowait, }; EXPORT_SYMBOL_GPL(spk_serial_io_ops); @@ -240,7 +244,7 @@ int spk_wait_for_xmitr(struct spk_synth *in_synth) return 1; } -unsigned char spk_serial_in(void) +static unsigned char spk_serial_in(void) { int tmout = SPK_SERIAL_TIMEOUT; @@ -253,9 +257,8 @@ unsigned char spk_serial_in(void) } return inb_p(speakup_info.port_tts + UART_RX); } -EXPORT_SYMBOL_GPL(spk_serial_in); -unsigned char spk_serial_in_nowait(void) +static unsigned char spk_serial_in_nowait(void) { unsigned char lsr; @@ -264,7 +267,6 @@ unsigned char spk_serial_in_nowait(void) return 0; return inb_p(speakup_info.port_tts + UART_RX); } -EXPORT_SYMBOL_GPL(spk_serial_in_nowait); static int spk_serial_out(struct spk_synth *in_synth, const char ch) { diff --git a/drivers/staging/speakup/speakup_audptr.c b/drivers/staging/speakup/speakup_audptr.c index 6880352a7b74..800677bc1dad 100644 --- a/drivers/staging/speakup/speakup_audptr.c +++ b/drivers/staging/speakup/speakup_audptr.c @@ -138,11 +138,11 @@ static void synth_version(struct spk_synth *synth) char synth_id[40] = ""; synth->synth_immediate(synth, "\x05[Q]"); - synth_id[test] = spk_serial_in(); + synth_id[test] = synth->io_ops->synth_in(); if (synth_id[test] == 'A') { do { /* read version string from synth */ - synth_id[++test] = spk_serial_in(); + synth_id[++test] = synth->io_ops->synth_in(); } while (synth_id[test] != '\n' && test < 32); synth_id[++test] = 0x00; } diff --git a/drivers/staging/speakup/speakup_decext.c b/drivers/staging/speakup/speakup_decext.c index c564bf8e1531..da73b7649936 100644 --- a/drivers/staging/speakup/speakup_decext.c +++ b/drivers/staging/speakup/speakup_decext.c @@ -30,20 +30,16 @@ #define DRV_VERSION "2.14" #define SYNTH_CLEAR 0x03 #define PROCSPEECH 0x0b -static unsigned char last_char; +static volatile unsigned char last_char; -static inline u_char get_last_char(void) +static void read_buff_add(u_char ch) { - u_char avail = inb_p(speakup_info.port_tts + UART_LSR) & UART_LSR_DR; - - if (avail) - last_char = inb_p(speakup_info.port_tts + UART_RX); - return last_char; + last_char = ch; } static inline bool synth_full(void) { - return get_last_char() == 0x13; + return last_char == 0x13; } static void do_catch_up(struct spk_synth *synth); @@ -135,7 +131,7 @@ static struct spk_synth synth_decext = { .flush = synth_flush, .is_alive = spk_synth_is_alive_restart, .synth_adjust = NULL, - .read_buff_add = NULL, + .read_buff_add = read_buff_add, .get_index = NULL, .indexing = { .command = NULL, diff --git a/drivers/staging/speakup/speakup_dectlk.c b/drivers/staging/speakup/speakup_dectlk.c index 0cdbd5e9b36b..74acd527dc86 100644 --- a/drivers/staging/speakup/speakup_dectlk.c +++ b/drivers/staging/speakup/speakup_dectlk.c @@ -42,7 +42,7 @@ static inline int synth_full(void) static void do_catch_up(struct spk_synth *synth); static void synth_flush(struct spk_synth *synth); static void read_buff_add(u_char c); -static unsigned char get_index(void); +static unsigned char get_index(struct spk_synth *synth); static int in_escape; static int is_flushing; @@ -163,7 +163,7 @@ static int is_indnum(u_char *ch) static u_char lastind; -static unsigned char get_index(void) +static unsigned char get_index(struct spk_synth *synth) { u_char rv; diff --git a/drivers/staging/speakup/speakup_dtlk.c b/drivers/staging/speakup/speakup_dtlk.c index 33180937222d..8999e3eb5c26 100644 --- a/drivers/staging/speakup/speakup_dtlk.c +++ b/drivers/staging/speakup/speakup_dtlk.c @@ -138,7 +138,7 @@ static struct spk_synth synth_dtlk = { .is_alive = spk_synth_is_alive_nop, .synth_adjust = NULL, .read_buff_add = NULL, - .get_index = spk_serial_in_nowait, + .get_index = spk_synth_get_index, .indexing = { .command = "\x01%di", .lowindex = 1, diff --git a/drivers/staging/speakup/speakup_ltlk.c b/drivers/staging/speakup/speakup_ltlk.c index 11275f49bea4..bd4ac63730b7 100644 --- a/drivers/staging/speakup/speakup_ltlk.c +++ b/drivers/staging/speakup/speakup_ltlk.c @@ -120,7 +120,7 @@ static struct spk_synth synth_ltlk = { .is_alive = spk_synth_is_alive_restart, .synth_adjust = NULL, .read_buff_add = NULL, - .get_index = spk_serial_in_nowait, + .get_index = spk_synth_get_index, .indexing = { .command = "\x01%di", .lowindex = 1, @@ -141,7 +141,7 @@ static void synth_interrogate(struct spk_synth *synth) synth->synth_immediate(synth, "\x18\x01?"); for (i = 0; i < 50; i++) { - buf[i] = spk_serial_in(); + buf[i] = synth->io_ops->synth_in(); if (i > 2 && buf[i] == 0x7f) break; } diff --git a/drivers/staging/speakup/speakup_soft.c b/drivers/staging/speakup/speakup_soft.c index e454f5685f70..d99daf69e501 100644 --- a/drivers/staging/speakup/speakup_soft.c +++ b/drivers/staging/speakup/speakup_soft.c @@ -36,7 +36,7 @@ static int softsynth_probe(struct spk_synth *synth); static void softsynth_release(void); static int softsynth_is_alive(struct spk_synth *synth); -static unsigned char get_index(void); +static unsigned char get_index(struct spk_synth *synth); static struct miscdevice synth_device, synthu_device; static int init_pos; @@ -340,7 +340,7 @@ static unsigned int softsynth_poll(struct file *fp, struct poll_table_struct *wa return ret; } -static unsigned char get_index(void) +static unsigned char get_index(struct spk_synth *synth) { int rv; diff --git a/drivers/staging/speakup/speakup_spkout.c b/drivers/staging/speakup/speakup_spkout.c index d95c375a0736..5160e4afdbef 100644 --- a/drivers/staging/speakup/speakup_spkout.c +++ b/drivers/staging/speakup/speakup_spkout.c @@ -111,7 +111,7 @@ static struct spk_synth synth_spkout = { .is_alive = spk_synth_is_alive_restart, .synth_adjust = NULL, .read_buff_add = NULL, - .get_index = spk_serial_in_nowait, + .get_index = spk_synth_get_index, .indexing = { .command = "\x05[%c", .lowindex = 1, diff --git a/drivers/staging/speakup/spk_priv.h b/drivers/staging/speakup/spk_priv.h index 995f586bddcd..6895373902de 100644 --- a/drivers/staging/speakup/spk_priv.h +++ b/drivers/staging/speakup/spk_priv.h @@ -43,8 +43,6 @@ const struct old_serial_port *spk_serial_init(int index); void spk_stop_serial_interrupt(void); int spk_wait_for_xmitr(struct spk_synth *in_synth); -unsigned char spk_serial_in(void); -unsigned char spk_serial_in_nowait(void); void spk_serial_release(void); void synth_buffer_skip_nonlatin1(void); @@ -61,6 +59,7 @@ int spk_serial_synth_probe(struct spk_synth *synth); const char *spk_serial_synth_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); +unsigned char spk_synth_get_index(struct spk_synth *synth); int spk_synth_is_alive_nop(struct spk_synth *synth); int spk_synth_is_alive_restart(struct spk_synth *synth); __printf(1, 2) diff --git a/drivers/staging/speakup/spk_types.h b/drivers/staging/speakup/spk_types.h index c156975392c8..ad7b9480a37f 100644 --- a/drivers/staging/speakup/spk_types.h +++ b/drivers/staging/speakup/spk_types.h @@ -152,6 +152,8 @@ struct spk_io_ops { int (*synth_out)(struct spk_synth *synth, const char ch); void (*send_xchar)(char ch); void (*tiocmset)(unsigned int set, unsigned int clear); + unsigned char (*synth_in)(void); + unsigned char (*synth_in_nowait)(void); }; struct spk_synth { @@ -182,7 +184,7 @@ struct spk_synth { int (*is_alive)(struct spk_synth *synth); int (*synth_adjust)(struct st_var_header *var); void (*read_buff_add)(u_char); - unsigned char (*get_index)(void); + unsigned char (*get_index)(struct spk_synth *synth); struct synth_indexing indexing; int alive; struct attribute_group attributes; diff --git a/drivers/staging/speakup/synth.c b/drivers/staging/speakup/synth.c index 352e9eebc3de..9c2aa1b8b0ac 100644 --- a/drivers/staging/speakup/synth.c +++ b/drivers/staging/speakup/synth.c @@ -124,6 +124,12 @@ void spk_synth_flush(struct spk_synth *synth) } EXPORT_SYMBOL_GPL(spk_synth_flush); +unsigned char spk_synth_get_index(struct spk_synth *synth) +{ + return synth->io_ops->synth_in_nowait(); +} +EXPORT_SYMBOL_GPL(spk_synth_get_index); + int spk_synth_is_alive_nop(struct spk_synth *synth) { synth->alive = 1; @@ -249,7 +255,7 @@ void spk_reset_index_count(int sc) if (first) first = 0; else - synth->get_index(); + synth->get_index(synth); index_count = 0; sentence_count = sc; } @@ -282,7 +288,7 @@ void synth_insert_next_index(int sent_num) void spk_get_index_count(int *linecount, int *sentcount) { - int ind = synth->get_index(); + int ind = synth->get_index(synth); if (ind) { sentence_count = ind % 10; |