Orange Pi5 kernel

Deprecated Linux kernel 5.10.110 for OrangePi 5/5B/5+ boards

3 Commits   0 Branches   0 Tags
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   1) // SPDX-License-Identifier: GPL-2.0
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   2) #include <linux/types.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   3) #include <linux/ctype.h>	/* for isdigit() and friends */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   4) #include <linux/fs.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   5) #include <linux/mm.h>		/* for verify_area */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   6) #include <linux/errno.h>	/* for -EBUSY */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   7) #include <linux/ioport.h>	/* for check_region, request_region */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   8) #include <linux/interrupt.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   9) #include <linux/delay.h>	/* for loops_per_sec */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  10) #include <linux/kmod.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  11) #include <linux/jiffies.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  12) #include <linux/uaccess.h>	/* for copy_from_user */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  13) #include <linux/sched.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  14) #include <linux/timer.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  15) #include <linux/kthread.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  16) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  17) #include "spk_priv.h"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  18) #include "speakup.h"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  19) #include "serialio.h"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  20) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  21) static LIST_HEAD(synths);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  22) struct spk_synth *synth;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  23) char spk_pitch_buff[32] = "";
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  24) static int module_status;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  25) bool spk_quiet_boot;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  26) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  27) struct speakup_info_t speakup_info = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  28) 	/*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  29) 	 * This spinlock is used to protect the entire speakup machinery, and
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  30) 	 * must be taken at each kernel->speakup transition and released at
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  31) 	 * each corresponding speakup->kernel transition.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  32) 	 *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  33) 	 * The progression thread only interferes with the speakup machinery
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  34) 	 * through the synth buffer, so only needs to take the lock
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  35) 	 * while tinkering with the buffer.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  36) 	 *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  37) 	 * We use spin_lock/trylock_irqsave and spin_unlock_irqrestore with this
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  38) 	 * spinlock because speakup needs to disable the keyboard IRQ.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  39) 	 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  40) 	.spinlock = __SPIN_LOCK_UNLOCKED(speakup_info.spinlock),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  41) 	.flushing = 0,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  42) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  43) EXPORT_SYMBOL_GPL(speakup_info);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  44) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  45) static int do_synth_init(struct spk_synth *in_synth);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  46) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  47) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  48)  * Main loop of the progression thread: keep eating from the buffer
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  49)  * and push to the serial port, waiting as needed
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  50)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  51)  * For devices that have a "full" notification mechanism, the driver can
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  52)  * adapt the loop the way they prefer.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  53)  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  54) static void _spk_do_catch_up(struct spk_synth *synth, int unicode)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  55) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  56) 	u16 ch;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  57) 	unsigned long flags;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  58) 	unsigned long jiff_max;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  59) 	struct var_t *delay_time;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  60) 	struct var_t *full_time;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  61) 	struct var_t *jiffy_delta;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  62) 	int jiffy_delta_val;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  63) 	int delay_time_val;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  64) 	int full_time_val;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  65) 	int ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  66) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  67) 	jiffy_delta = spk_get_var(JIFFY);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  68) 	full_time = spk_get_var(FULL);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  69) 	delay_time = spk_get_var(DELAY);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  70) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  71) 	spin_lock_irqsave(&speakup_info.spinlock, flags);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  72) 	jiffy_delta_val = jiffy_delta->u.n.value;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  73) 	spin_unlock_irqrestore(&speakup_info.spinlock, flags);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  74) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  75) 	jiff_max = jiffies + jiffy_delta_val;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  76) 	while (!kthread_should_stop()) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  77) 		spin_lock_irqsave(&speakup_info.spinlock, flags);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  78) 		if (speakup_info.flushing) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  79) 			speakup_info.flushing = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  80) 			spin_unlock_irqrestore(&speakup_info.spinlock, flags);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  81) 			synth->flush(synth);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  82) 			continue;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  83) 		}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  84) 		if (!unicode)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  85) 			synth_buffer_skip_nonlatin1();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  86) 		if (synth_buffer_empty()) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  87) 			spin_unlock_irqrestore(&speakup_info.spinlock, flags);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  88) 			break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  89) 		}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  90) 		ch = synth_buffer_peek();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  91) 		set_current_state(TASK_INTERRUPTIBLE);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  92) 		full_time_val = full_time->u.n.value;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  93) 		spin_unlock_irqrestore(&speakup_info.spinlock, flags);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  94) 		if (ch == '\n')
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  95) 			ch = synth->procspeech;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  96) 		if (unicode)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  97) 			ret = synth->io_ops->synth_out_unicode(synth, ch);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  98) 		else
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  99) 			ret = synth->io_ops->synth_out(synth, ch);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 100) 		if (!ret) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 101) 			schedule_timeout(msecs_to_jiffies(full_time_val));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 102) 			continue;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 103) 		}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 104) 		if (time_after_eq(jiffies, jiff_max) && (ch == SPACE)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 105) 			spin_lock_irqsave(&speakup_info.spinlock, flags);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 106) 			jiffy_delta_val = jiffy_delta->u.n.value;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 107) 			delay_time_val = delay_time->u.n.value;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 108) 			full_time_val = full_time->u.n.value;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 109) 			spin_unlock_irqrestore(&speakup_info.spinlock, flags);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 110) 			if (synth->io_ops->synth_out(synth, synth->procspeech))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 111) 				schedule_timeout(
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 112) 					msecs_to_jiffies(delay_time_val));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 113) 			else
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 114) 				schedule_timeout(
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 115) 					msecs_to_jiffies(full_time_val));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 116) 			jiff_max = jiffies + jiffy_delta_val;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 117) 		}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 118) 		set_current_state(TASK_RUNNING);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 119) 		spin_lock_irqsave(&speakup_info.spinlock, flags);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 120) 		synth_buffer_getc();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 121) 		spin_unlock_irqrestore(&speakup_info.spinlock, flags);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 122) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 123) 	synth->io_ops->synth_out(synth, synth->procspeech);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 124) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 125) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 126) void spk_do_catch_up(struct spk_synth *synth)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 127) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 128) 	_spk_do_catch_up(synth, 0);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 129) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 130) EXPORT_SYMBOL_GPL(spk_do_catch_up);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 131) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 132) void spk_do_catch_up_unicode(struct spk_synth *synth)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 133) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 134) 	_spk_do_catch_up(synth, 1);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 135) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 136) EXPORT_SYMBOL_GPL(spk_do_catch_up_unicode);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 137) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 138) void spk_synth_flush(struct spk_synth *synth)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 139) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 140) 	synth->io_ops->flush_buffer();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 141) 	synth->io_ops->synth_out(synth, synth->clear);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 142) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 143) EXPORT_SYMBOL_GPL(spk_synth_flush);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 144) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 145) unsigned char spk_synth_get_index(struct spk_synth *synth)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 146) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 147) 	return synth->io_ops->synth_in_nowait();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 148) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 149) EXPORT_SYMBOL_GPL(spk_synth_get_index);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 150) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 151) int spk_synth_is_alive_nop(struct spk_synth *synth)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 152) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 153) 	synth->alive = 1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 154) 	return 1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 155) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 156) EXPORT_SYMBOL_GPL(spk_synth_is_alive_nop);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 157) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 158) int spk_synth_is_alive_restart(struct spk_synth *synth)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 159) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 160) 	if (synth->alive)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 161) 		return 1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 162) 	if (synth->io_ops->wait_for_xmitr(synth) > 0) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 163) 		/* restart */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 164) 		synth->alive = 1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 165) 		synth_printf("%s", synth->init);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 166) 		return 2; /* reenabled */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 167) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 168) 	pr_warn("%s: can't restart synth\n", synth->long_name);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 169) 	return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 170) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 171) EXPORT_SYMBOL_GPL(spk_synth_is_alive_restart);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 172) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 173) static void thread_wake_up(struct timer_list *unused)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 174) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 175) 	wake_up_interruptible_all(&speakup_event);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 176) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 177) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 178) static DEFINE_TIMER(thread_timer, thread_wake_up);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 179) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 180) void synth_start(void)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 181) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 182) 	struct var_t *trigger_time;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 183) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 184) 	if (!synth->alive) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 185) 		synth_buffer_clear();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 186) 		return;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 187) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 188) 	trigger_time = spk_get_var(TRIGGER);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 189) 	if (!timer_pending(&thread_timer))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 190) 		mod_timer(&thread_timer, jiffies +
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 191) 			msecs_to_jiffies(trigger_time->u.n.value));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 192) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 193) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 194) void spk_do_flush(void)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 195) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 196) 	if (!synth)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 197) 		return;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 198) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 199) 	speakup_info.flushing = 1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 200) 	synth_buffer_clear();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 201) 	if (synth->alive) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 202) 		if (spk_pitch_shift) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 203) 			synth_printf("%s", spk_pitch_buff);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 204) 			spk_pitch_shift = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 205) 		}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 206) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 207) 	wake_up_interruptible_all(&speakup_event);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 208) 	wake_up_process(speakup_task);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 209) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 210) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 211) void synth_write(const char *buf, size_t count)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 212) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 213) 	while (count--)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 214) 		synth_buffer_add(*buf++);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 215) 	synth_start();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 216) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 217) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 218) void synth_printf(const char *fmt, ...)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 219) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 220) 	va_list args;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 221) 	unsigned char buf[160], *p;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 222) 	int r;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 223) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 224) 	va_start(args, fmt);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 225) 	r = vsnprintf(buf, sizeof(buf), fmt, args);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 226) 	va_end(args);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 227) 	if (r > sizeof(buf) - 1)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 228) 		r = sizeof(buf) - 1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 229) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 230) 	p = buf;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 231) 	while (r--)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 232) 		synth_buffer_add(*p++);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 233) 	synth_start();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 234) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 235) EXPORT_SYMBOL_GPL(synth_printf);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 236) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 237) void synth_putwc(u16 wc)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 238) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 239) 	synth_buffer_add(wc);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 240) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 241) EXPORT_SYMBOL_GPL(synth_putwc);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 242) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 243) void synth_putwc_s(u16 wc)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 244) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 245) 	synth_buffer_add(wc);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 246) 	synth_start();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 247) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 248) EXPORT_SYMBOL_GPL(synth_putwc_s);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 249) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 250) void synth_putws(const u16 *buf)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 251) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 252) 	const u16 *p;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 253) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 254) 	for (p = buf; *p; p++)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 255) 		synth_buffer_add(*p);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 256) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 257) EXPORT_SYMBOL_GPL(synth_putws);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 258) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 259) void synth_putws_s(const u16 *buf)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 260) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 261) 	synth_putws(buf);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 262) 	synth_start();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 263) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 264) EXPORT_SYMBOL_GPL(synth_putws_s);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 265) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 266) static int index_count;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 267) static int sentence_count;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 268) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 269) void spk_reset_index_count(int sc)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 270) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 271) 	static int first = 1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 272) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 273) 	if (first)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 274) 		first = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 275) 	else
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 276) 		synth->get_index(synth);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 277) 	index_count = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 278) 	sentence_count = sc;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 279) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 280) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 281) int synth_supports_indexing(void)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 282) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 283) 	if (synth->get_index)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 284) 		return 1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 285) 	return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 286) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 287) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 288) void synth_insert_next_index(int sent_num)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 289) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 290) 	int out;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 291) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 292) 	if (synth->alive) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 293) 		if (sent_num == 0) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 294) 			synth->indexing.currindex++;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 295) 			index_count++;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 296) 			if (synth->indexing.currindex >
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 297) 					synth->indexing.highindex)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 298) 				synth->indexing.currindex =
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 299) 					synth->indexing.lowindex;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 300) 		}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 301) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 302) 		out = synth->indexing.currindex * 10 + sent_num;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 303) 		synth_printf(synth->indexing.command, out, out);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 304) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 305) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 306) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 307) void spk_get_index_count(int *linecount, int *sentcount)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 308) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 309) 	int ind = synth->get_index(synth);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 310) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 311) 	if (ind) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 312) 		sentence_count = ind % 10;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 313) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 314) 		if ((ind / 10) <= synth->indexing.currindex)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 315) 			index_count = synth->indexing.currindex - (ind / 10);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 316) 		else
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 317) 			index_count = synth->indexing.currindex
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 318) 				- synth->indexing.lowindex
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 319) 				+ synth->indexing.highindex - (ind / 10) + 1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 320) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 321) 	*sentcount = sentence_count;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 322) 	*linecount = index_count;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 323) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 324) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 325) static struct resource synth_res;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 326) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 327) int synth_request_region(unsigned long start, unsigned long n)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 328) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 329) 	struct resource *parent = &ioport_resource;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 330) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 331) 	memset(&synth_res, 0, sizeof(synth_res));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 332) 	synth_res.name = synth->name;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 333) 	synth_res.start = start;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 334) 	synth_res.end = start + n - 1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 335) 	synth_res.flags = IORESOURCE_BUSY;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 336) 	return request_resource(parent, &synth_res);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 337) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 338) EXPORT_SYMBOL_GPL(synth_request_region);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 339) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 340) int synth_release_region(unsigned long start, unsigned long n)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 341) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 342) 	return release_resource(&synth_res);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 343) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 344) EXPORT_SYMBOL_GPL(synth_release_region);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 345) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 346) struct var_t synth_time_vars[] = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 347) 	{ DELAY, .u.n = {NULL, 100, 100, 2000, 0, 0, NULL } },
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 348) 	{ TRIGGER, .u.n = {NULL, 20, 10, 2000, 0, 0, NULL } },
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 349) 	{ JIFFY, .u.n = {NULL, 50, 20, 200, 0, 0, NULL } },
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 350) 	{ FULL, .u.n = {NULL, 400, 200, 60000, 0, 0, NULL } },
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 351) 	V_LAST_VAR
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 352) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 353) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 354) /* called by: speakup_init() */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 355) int synth_init(char *synth_name)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 356) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 357) 	int ret = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 358) 	struct spk_synth *tmp, *synth = NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 359) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 360) 	if (!synth_name)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 361) 		return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 362) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 363) 	if (strcmp(synth_name, "none") == 0) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 364) 		mutex_lock(&spk_mutex);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 365) 		synth_release();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 366) 		mutex_unlock(&spk_mutex);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 367) 		return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 368) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 369) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 370) 	mutex_lock(&spk_mutex);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 371) 	/* First, check if we already have it loaded. */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 372) 	list_for_each_entry(tmp, &synths, node) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 373) 		if (strcmp(tmp->name, synth_name) == 0)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 374) 			synth = tmp;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 375) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 376) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 377) 	/* If we got one, initialize it now. */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 378) 	if (synth)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 379) 		ret = do_synth_init(synth);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 380) 	else
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 381) 		ret = -ENODEV;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 382) 	mutex_unlock(&spk_mutex);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 383) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 384) 	return ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 385) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 386) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 387) /* called by: synth_add() */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 388) static int do_synth_init(struct spk_synth *in_synth)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 389) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 390) 	struct var_t *var;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 391) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 392) 	synth_release();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 393) 	if (in_synth->checkval != SYNTH_CHECK)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 394) 		return -EINVAL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 395) 	synth = in_synth;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 396) 	synth->alive = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 397) 	pr_warn("synth probe\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 398) 	if (synth->probe(synth) < 0) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 399) 		pr_warn("%s: device probe failed\n", in_synth->name);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 400) 		synth = NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 401) 		return -ENODEV;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 402) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 403) 	synth_time_vars[0].u.n.value =
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 404) 		synth_time_vars[0].u.n.default_val = synth->delay;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 405) 	synth_time_vars[1].u.n.value =
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 406) 		synth_time_vars[1].u.n.default_val = synth->trigger;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 407) 	synth_time_vars[2].u.n.value =
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 408) 		synth_time_vars[2].u.n.default_val = synth->jiffies;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 409) 	synth_time_vars[3].u.n.value =
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 410) 		synth_time_vars[3].u.n.default_val = synth->full;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 411) 	synth_printf("%s", synth->init);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 412) 	for (var = synth->vars;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 413) 		(var->var_id >= 0) && (var->var_id < MAXVARS); var++)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 414) 		speakup_register_var(var);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 415) 	if (!spk_quiet_boot)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 416) 		synth_printf("%s found\n", synth->long_name);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 417) 	if (synth->attributes.name &&
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 418) 	    sysfs_create_group(speakup_kobj, &synth->attributes) < 0)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 419) 		return -ENOMEM;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 420) 	synth_flags = synth->flags;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 421) 	wake_up_interruptible_all(&speakup_event);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 422) 	if (speakup_task)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 423) 		wake_up_process(speakup_task);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 424) 	return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 425) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 426) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 427) void synth_release(void)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 428) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 429) 	struct var_t *var;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 430) 	unsigned long flags;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 431) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 432) 	if (!synth)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 433) 		return;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 434) 	spin_lock_irqsave(&speakup_info.spinlock, flags);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 435) 	pr_info("releasing synth %s\n", synth->name);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 436) 	synth->alive = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 437) 	del_timer(&thread_timer);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 438) 	spin_unlock_irqrestore(&speakup_info.spinlock, flags);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 439) 	if (synth->attributes.name)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 440) 		sysfs_remove_group(speakup_kobj, &synth->attributes);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 441) 	for (var = synth->vars; var->var_id != MAXVARS; var++)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 442) 		speakup_unregister_var(var->var_id);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 443) 	synth->release();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 444) 	synth = NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 445) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 446) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 447) /* called by: all_driver_init() */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 448) int synth_add(struct spk_synth *in_synth)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 449) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 450) 	int status = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 451) 	struct spk_synth *tmp;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 452) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 453) 	mutex_lock(&spk_mutex);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 454) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 455) 	list_for_each_entry(tmp, &synths, node) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 456) 		if (tmp == in_synth) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 457) 			mutex_unlock(&spk_mutex);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 458) 			return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 459) 		}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 460) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 461) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 462) 	if (in_synth->startup)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 463) 		status = do_synth_init(in_synth);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 464) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 465) 	if (!status)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 466) 		list_add_tail(&in_synth->node, &synths);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 467) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 468) 	mutex_unlock(&spk_mutex);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 469) 	return status;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 470) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 471) EXPORT_SYMBOL_GPL(synth_add);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 472) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 473) void synth_remove(struct spk_synth *in_synth)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 474) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 475) 	mutex_lock(&spk_mutex);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 476) 	if (synth == in_synth)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 477) 		synth_release();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 478) 	list_del(&in_synth->node);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 479) 	module_status = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 480) 	mutex_unlock(&spk_mutex);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 481) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 482) EXPORT_SYMBOL_GPL(synth_remove);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 483) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 484) struct spk_synth *synth_current(void)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 485) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 486) 	return synth;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 487) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 488) EXPORT_SYMBOL_GPL(synth_current);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 489) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 490) short spk_punc_masks[] = { 0, SOME, MOST, PUNC, PUNC | B_SYM };