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) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   3)  * written by David Borowski
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   4)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   5)  * Copyright (C) 2003 David Borowski.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   6)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   7)  * specificly written as a driver for the speakup screenreview
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   8)  * package it's not a general device driver.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   9)  * This driver is for the Keynote Gold internal synthesizer.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  10)  */
^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/sched.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  13) #include <linux/timer.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  14) #include <linux/kthread.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  15) #include <linux/serial_reg.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) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  20) #define DRV_VERSION "2.10"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  21) #define SYNTH_IO_EXTENT	0x04
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  22) #define SWAIT udelay(70)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  23) #define PROCSPEECH 0x1f
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  24) #define SYNTH_CLEAR 0x03
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  25) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  26) static int synth_probe(struct spk_synth *synth);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  27) static void keynote_release(void);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  28) static const char *synth_immediate(struct spk_synth *synth, const char *buf);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  29) static void do_catch_up(struct spk_synth *synth);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  30) static void synth_flush(struct spk_synth *synth);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  31) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  32) static int synth_port;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  33) static int port_forced;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  34) static unsigned int synth_portlist[] = { 0x2a8, 0 };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  35) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  36) static struct var_t vars[] = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  37) 	{ CAPS_START, .u.s = {"[f130]" } },
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  38) 	{ CAPS_STOP, .u.s = {"[f90]" } },
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  39) 	{ RATE, .u.n = {"\04%c ", 8, 0, 10, 81, -8, NULL } },
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  40) 	{ PITCH, .u.n = {"[f%d]", 5, 0, 9, 40, 10, NULL } },
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  41) 	{ DIRECT, .u.n = {NULL, 0, 0, 1, 0, 0, NULL } },
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  42) 	V_LAST_VAR
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  43) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  44) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  45) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  46)  * These attributes will appear in /sys/accessibility/speakup/keypc.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  47)  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  48) static struct kobj_attribute caps_start_attribute =
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  49) 	__ATTR(caps_start, 0644, spk_var_show, spk_var_store);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  50) static struct kobj_attribute caps_stop_attribute =
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  51) 	__ATTR(caps_stop, 0644, spk_var_show, spk_var_store);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  52) static struct kobj_attribute pitch_attribute =
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  53) 	__ATTR(pitch, 0644, spk_var_show, spk_var_store);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  54) static struct kobj_attribute rate_attribute =
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  55) 	__ATTR(rate, 0644, spk_var_show, spk_var_store);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  56) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  57) static struct kobj_attribute delay_time_attribute =
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  58) 	__ATTR(delay_time, 0644, spk_var_show, spk_var_store);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  59) static struct kobj_attribute direct_attribute =
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  60) 	__ATTR(direct, 0644, spk_var_show, spk_var_store);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  61) static struct kobj_attribute full_time_attribute =
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  62) 	__ATTR(full_time, 0644, spk_var_show, spk_var_store);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  63) static struct kobj_attribute jiffy_delta_attribute =
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  64) 	__ATTR(jiffy_delta, 0644, spk_var_show, spk_var_store);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  65) static struct kobj_attribute trigger_time_attribute =
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  66) 	__ATTR(trigger_time, 0644, spk_var_show, spk_var_store);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  67) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  68) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  69)  * Create a group of attributes so that we can create and destroy them all
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  70)  * at once.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  71)  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  72) static struct attribute *synth_attrs[] = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  73) 	&caps_start_attribute.attr,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  74) 	&caps_stop_attribute.attr,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  75) 	&pitch_attribute.attr,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  76) 	&rate_attribute.attr,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  77) 	&delay_time_attribute.attr,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  78) 	&direct_attribute.attr,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  79) 	&full_time_attribute.attr,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  80) 	&jiffy_delta_attribute.attr,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  81) 	&trigger_time_attribute.attr,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  82) 	NULL,	/* need to NULL terminate the list of attributes */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  83) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  84) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  85) static struct spk_synth synth_keypc = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  86) 	.name = "keypc",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  87) 	.version = DRV_VERSION,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  88) 	.long_name = "Keynote PC",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  89) 	.init = "[t][n7,1][n8,0]",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  90) 	.procspeech = PROCSPEECH,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  91) 	.clear = SYNTH_CLEAR,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  92) 	.delay = 500,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  93) 	.trigger = 50,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  94) 	.jiffies = 50,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  95) 	.full = 1000,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  96) 	.startup = SYNTH_START,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  97) 	.checkval = SYNTH_CHECK,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  98) 	.vars = vars,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  99) 	.io_ops = &spk_serial_io_ops,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 100) 	.probe = synth_probe,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 101) 	.release = keynote_release,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 102) 	.synth_immediate = synth_immediate,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 103) 	.catch_up = do_catch_up,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 104) 	.flush = synth_flush,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 105) 	.is_alive = spk_synth_is_alive_nop,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 106) 	.synth_adjust = NULL,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 107) 	.read_buff_add = NULL,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 108) 	.get_index = NULL,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 109) 	.indexing = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 110) 		.command = NULL,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 111) 		.lowindex = 0,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 112) 		.highindex = 0,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 113) 		.currindex = 0,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 114) 	},
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 115) 	.attributes = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 116) 		.attrs = synth_attrs,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 117) 		.name = "keypc",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 118) 	},
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 119) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 120) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 121) static inline bool synth_writable(void)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 122) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 123) 	return (inb_p(synth_port + UART_RX) & 0x10) != 0;
^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) static inline bool synth_full(void)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 127) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 128) 	return (inb_p(synth_port + UART_RX) & 0x80) == 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 129) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 130) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 131) static char *oops(void)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 132) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 133) 	int s1, s2, s3, s4;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 134) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 135) 	s1 = inb_p(synth_port);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 136) 	s2 = inb_p(synth_port + 1);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 137) 	s3 = inb_p(synth_port + 2);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 138) 	s4 = inb_p(synth_port + 3);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 139) 	pr_warn("synth timeout %d %d %d %d\n", s1, s2, s3, s4);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 140) 	return NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 141) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 142) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 143) static const char *synth_immediate(struct spk_synth *synth, const char *buf)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 144) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 145) 	u_char ch;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 146) 	int timeout;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 147) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 148) 	while ((ch = *buf)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 149) 		if (ch == '\n')
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 150) 			ch = PROCSPEECH;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 151) 		if (synth_full())
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 152) 			return buf;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 153) 		timeout = 1000;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 154) 		while (synth_writable())
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 155) 			if (--timeout <= 0)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 156) 				return oops();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 157) 		outb_p(ch, synth_port);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 158) 		udelay(70);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 159) 		buf++;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 160) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 161) 	return NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 162) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 163) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 164) static void do_catch_up(struct spk_synth *synth)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 165) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 166) 	u_char ch;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 167) 	int timeout;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 168) 	unsigned long flags;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 169) 	unsigned long jiff_max;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 170) 	struct var_t *jiffy_delta;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 171) 	struct var_t *delay_time;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 172) 	struct var_t *full_time;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 173) 	int delay_time_val;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 174) 	int full_time_val;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 175) 	int jiffy_delta_val;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 176) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 177) 	jiffy_delta = spk_get_var(JIFFY);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 178) 	delay_time = spk_get_var(DELAY);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 179) 	full_time = spk_get_var(FULL);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 180) 	spin_lock_irqsave(&speakup_info.spinlock, flags);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 181) 	jiffy_delta_val = jiffy_delta->u.n.value;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 182) 	spin_unlock_irqrestore(&speakup_info.spinlock, flags);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 183) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 184) 	jiff_max = jiffies + jiffy_delta_val;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 185) 	while (!kthread_should_stop()) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 186) 		spin_lock_irqsave(&speakup_info.spinlock, flags);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 187) 		if (speakup_info.flushing) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 188) 			speakup_info.flushing = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 189) 			spin_unlock_irqrestore(&speakup_info.spinlock, flags);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 190) 			synth->flush(synth);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 191) 			continue;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 192) 		}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 193) 		synth_buffer_skip_nonlatin1();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 194) 		if (synth_buffer_empty()) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 195) 			spin_unlock_irqrestore(&speakup_info.spinlock, flags);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 196) 			break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 197) 		}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 198) 		set_current_state(TASK_INTERRUPTIBLE);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 199) 		full_time_val = full_time->u.n.value;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 200) 		spin_unlock_irqrestore(&speakup_info.spinlock, flags);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 201) 		if (synth_full()) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 202) 			schedule_timeout(msecs_to_jiffies(full_time_val));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 203) 			continue;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 204) 		}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 205) 		set_current_state(TASK_RUNNING);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 206) 		timeout = 1000;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 207) 		while (synth_writable())
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 208) 			if (--timeout <= 0)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 209) 				break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 210) 		if (timeout <= 0) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 211) 			oops();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 212) 			break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 213) 		}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 214) 		spin_lock_irqsave(&speakup_info.spinlock, flags);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 215) 		ch = synth_buffer_getc();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 216) 		spin_unlock_irqrestore(&speakup_info.spinlock, flags);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 217) 		if (ch == '\n')
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 218) 			ch = PROCSPEECH;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 219) 		outb_p(ch, synth_port);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 220) 		SWAIT;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 221) 		if (time_after_eq(jiffies, jiff_max) && (ch == SPACE)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 222) 			timeout = 1000;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 223) 			while (synth_writable())
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 224) 				if (--timeout <= 0)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 225) 					break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 226) 			if (timeout <= 0) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 227) 				oops();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 228) 				break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 229) 			}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 230) 			outb_p(PROCSPEECH, synth_port);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 231) 			spin_lock_irqsave(&speakup_info.spinlock, flags);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 232) 			jiffy_delta_val = jiffy_delta->u.n.value;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 233) 			delay_time_val = delay_time->u.n.value;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 234) 			spin_unlock_irqrestore(&speakup_info.spinlock, flags);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 235) 			schedule_timeout(msecs_to_jiffies(delay_time_val));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 236) 			jiff_max = jiffies + jiffy_delta_val;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 237) 		}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 238) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 239) 	timeout = 1000;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 240) 	while (synth_writable())
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 241) 		if (--timeout <= 0)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 242) 			break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 243) 	if (timeout <= 0)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 244) 		oops();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 245) 	else
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 246) 		outb_p(PROCSPEECH, synth_port);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 247) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 248) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 249) static void synth_flush(struct spk_synth *synth)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 250) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 251) 	outb_p(SYNTH_CLEAR, synth_port);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 252) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 253) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 254) static int synth_probe(struct spk_synth *synth)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 255) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 256) 	unsigned int port_val = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 257) 	int i = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 258) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 259) 	pr_info("Probing for %s.\n", synth->long_name);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 260) 	if (port_forced) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 261) 		synth_port = port_forced;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 262) 		pr_info("probe forced to %x by kernel command line\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 263) 			synth_port);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 264) 		if (synth_request_region(synth_port - 1, SYNTH_IO_EXTENT)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 265) 			pr_warn("sorry, port already reserved\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 266) 			return -EBUSY;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 267) 		}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 268) 		port_val = inb(synth_port);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 269) 	} else {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 270) 		for (i = 0; synth_portlist[i]; i++) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 271) 			if (synth_request_region(synth_portlist[i],
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 272) 						 SYNTH_IO_EXTENT)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 273) 				pr_warn
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 274) 				    ("request_region: failed with 0x%x, %d\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 275) 				     synth_portlist[i], SYNTH_IO_EXTENT);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 276) 				continue;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 277) 			}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 278) 			port_val = inb(synth_portlist[i]);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 279) 			if (port_val == 0x80) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 280) 				synth_port = synth_portlist[i];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 281) 				break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 282) 			}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 283) 		}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 284) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 285) 	if (port_val != 0x80) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 286) 		pr_info("%s: not found\n", synth->long_name);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 287) 		synth_release_region(synth_port, SYNTH_IO_EXTENT);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 288) 		synth_port = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 289) 		return -ENODEV;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 290) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 291) 	pr_info("%s: %03x-%03x, driver version %s,\n", synth->long_name,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 292) 		synth_port, synth_port + SYNTH_IO_EXTENT - 1,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 293) 		synth->version);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 294) 	synth->alive = 1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 295) 	return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 296) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 297) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 298) static void keynote_release(void)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 299) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 300) 	spk_stop_serial_interrupt();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 301) 	if (synth_port)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 302) 		synth_release_region(synth_port, SYNTH_IO_EXTENT);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 303) 	synth_port = 0;
^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) module_param_hw_named(port, port_forced, int, ioport, 0444);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 307) module_param_named(start, synth_keypc.startup, short, 0444);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 308) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 309) MODULE_PARM_DESC(port, "Set the port for the synthesizer (override probing).");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 310) MODULE_PARM_DESC(start, "Start the synthesizer once it is loaded.");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 311) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 312) module_spk_synth(synth_keypc);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 313) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 314) MODULE_AUTHOR("David Borowski");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 315) MODULE_DESCRIPTION("Speakup support for Keynote Gold PC synthesizers");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 316) MODULE_LICENSE("GPL");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 317) MODULE_VERSION(DRV_VERSION);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 318)