/* * This allows to catch within spk_ttyio_ldisc_open whether it is getting set * on for a speakup-driven device.
*/ staticstruct tty_struct *speakup_tty; /* This mutex serializes the use of such global speakup_tty variable */ static DEFINE_MUTEX(speakup_tty_mutex);
staticint ser_to_dev(int ser, dev_t *dev_no)
{ if (ser < 0 || ser > (255 - 64)) {
pr_err("speakup: Invalid ser param. Must be between 0 and 191 inclusive.\n"); return -EINVAL;
}
*dev_no = MKDEV(4, (64 + ser)); return 0;
}
staticint get_dev_to_use(struct spk_synth *synth, dev_t *dev_no)
{ /* use ser only when dev is not specified */ if (strcmp(synth->dev_name, SYNTH_DEFAULT_DEV) ||
synth->ser == SYNTH_DEFAULT_SER) return tty_dev_name_to_number(synth->dev_name, dev_no);
staticint spk_ttyio_initialise_ldisc(struct spk_synth *synth)
{ int ret = 0; struct tty_struct *tty; struct ktermios tmp_termios;
dev_t dev;
ret = get_dev_to_use(synth, &dev); if (ret) return ret;
tty = tty_kopen_exclusive(dev); 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); /* ensure hardware flow control is enabled */
get_termios(tty, &tmp_termios); if (!(tmp_termios.c_cflag & CRTSCTS)) {
tmp_termios.c_cflag |= CRTSCTS;
tty_set_termios(tty, &tmp_termios); /* * check c_cflag to see if it's updated as tty_set_termios * may not return error even when no tty bits are * changed by the request.
*/
get_termios(tty, &tmp_termios); if (!(tmp_termios.c_cflag & CRTSCTS))
pr_warn("speakup: Failed to set hardware flow control\n");
}
pr_err("speakup: Failed to set N_SPEAKUP on tty\n");
tty_lock(tty); if (tty->ops->close)
tty->ops->close(tty, NULL);
tty_unlock(tty);
tty_kclose(tty);
return ret;
}
void spk_ttyio_register_ldisc(void)
{ if (tty_register_ldisc(&spk_ttyio_ldisc_ops))
pr_warn("speakup: Error registering line discipline. Most synths won't work.\n");
}
if (!in_synth->alive || !tty->ops->write) return 0;
ret = tty->ops->write(tty, &ch, 1);
if (ret == 0) /* No room */ return 0;
if (ret > 0) /* Success */ return 1;
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;
}
staticint spk_ttyio_out_unicode(struct spk_synth *in_synth, u16 ch)
{ int ret;
if (ch < 0x80) {
ret = spk_ttyio_out(in_synth, ch);
} elseif (ch < 0x800) {
ret = spk_ttyio_out(in_synth, 0xc0 | (ch >> 6));
ret &= spk_ttyio_out(in_synth, 0x80 | (ch & 0x3f));
} else {
ret = spk_ttyio_out(in_synth, 0xe0 | (ch >> 12));
ret &= spk_ttyio_out(in_synth, 0x80 | ((ch >> 6) & 0x3f));
ret &= spk_ttyio_out(in_synth, 0x80 | (ch & 0x3f));
} return ret;
}
if (!timeout) { if (!try_wait_for_completion(&ldisc_data->completion)) return 0xff;
} elseif (wait_for_completion_timeout(&ldisc_data->completion,
usecs_to_jiffies(timeout)) == 0) {
pr_warn("spk_ttyio: timeout (%d) while waiting for input\n",
timeout); return 0xff;
}
rv = ldisc_data->buf; /* Make sure we have read buf before we set buf_free to let * the producer overwrite it
*/
mb();
ldisc_data->buf_free = true; /* Let TTY push more characters */
tty_flip_buffer_push(tty->port);
Die Informationen auf dieser Webseite wurden
nach bestem Wissen sorgfältig zusammengestellt. Es wird jedoch weder Vollständigkeit, noch Richtigkeit,
noch Qualität der bereit gestellten Informationen zugesichert.
Bemerkung:
Die farbliche Syntaxdarstellung und die Messung sind noch experimentell.