Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit fe1ae7fd authored by Alan Cox's avatar Alan Cox Committed by Live-CD User
Browse files

tty: USB serial termios bits



Various drivers have hacks to mangle termios structures. This stems from
the fact there is no nice setup hook for configuring the termios settings
when the port is created

Signed-off-by: default avatarAlan Cox <alan@linux.intel.com>
Signed-off-by: default avatarGreg Kroah-Hartman <gregkh@suse.de>
parent ba15ab0e
Loading
Loading
Loading
Loading
+1 −0
Original line number Original line Diff line number Diff line
@@ -1184,6 +1184,7 @@ int tty_init_termios(struct tty_struct *tty)
	tty->termios->c_ospeed = tty_termios_baud_rate(tty->termios);
	tty->termios->c_ospeed = tty_termios_baud_rate(tty->termios);
	return 0;
	return 0;
}
}
EXPORT_SYMBOL_GPL(tty_init_termios);


/**
/**
 *	tty_driver_install_tty() - install a tty entry in the driver
 *	tty_driver_install_tty() - install a tty entry in the driver
+11 −35
Original line number Original line Diff line number Diff line
@@ -35,11 +35,6 @@ static struct usb_device_id id_table [] = {
};
};
MODULE_DEVICE_TABLE(usb, id_table);
MODULE_DEVICE_TABLE(usb, id_table);


struct ark3116_private {
	spinlock_t lock;
	u8 termios_initialized;
};

static inline void ARK3116_SND(struct usb_serial *serial, int seq,
static inline void ARK3116_SND(struct usb_serial *serial, int seq,
			       __u8 request, __u8 requesttype,
			       __u8 request, __u8 requesttype,
			       __u16 value, __u16 index)
			       __u16 value, __u16 index)
@@ -82,22 +77,11 @@ static inline void ARK3116_RCV_QUIET(struct usb_serial *serial,
static int ark3116_attach(struct usb_serial *serial)
static int ark3116_attach(struct usb_serial *serial)
{
{
	char *buf;
	char *buf;
	struct ark3116_private *priv;
	int i;

	for (i = 0; i < serial->num_ports; ++i) {
		priv = kzalloc(sizeof(struct ark3116_private), GFP_KERNEL);
		if (!priv)
			goto cleanup;
		spin_lock_init(&priv->lock);

		usb_set_serial_port_data(serial->port[i], priv);
	}


	buf = kmalloc(1, GFP_KERNEL);
	buf = kmalloc(1, GFP_KERNEL);
	if (!buf) {
	if (!buf) {
		dbg("error kmalloc -> out of mem?");
		dbg("error kmalloc -> out of mem?");
		goto cleanup;
		return -ENOMEM;
	}
	}


	/* 3 */
	/* 3 */
@@ -149,13 +133,16 @@ static int ark3116_attach(struct usb_serial *serial)


	kfree(buf);
	kfree(buf);
	return 0;
	return 0;

cleanup:
	for (--i; i >= 0; --i) {
		kfree(usb_get_serial_port_data(serial->port[i]));
		usb_set_serial_port_data(serial->port[i], NULL);
}
}
	return -ENOMEM;

static void ark3116_init_termios(struct tty_struct *tty)
{
	struct ktermios *termios = tty->termios;
	*termios = tty_std_termios;
	termios->c_cflag = B9600 | CS8
				      | CREAD | HUPCL | CLOCAL;
	termios->c_ispeed = 9600;
	termios->c_ospeed = 9600;
}
}


static void ark3116_set_termios(struct tty_struct *tty,
static void ark3116_set_termios(struct tty_struct *tty,
@@ -163,10 +150,8 @@ static void ark3116_set_termios(struct tty_struct *tty,
				struct ktermios *old_termios)
				struct ktermios *old_termios)
{
{
	struct usb_serial *serial = port->serial;
	struct usb_serial *serial = port->serial;
	struct ark3116_private *priv = usb_get_serial_port_data(port);
	struct ktermios *termios = tty->termios;
	struct ktermios *termios = tty->termios;
	unsigned int cflag = termios->c_cflag;
	unsigned int cflag = termios->c_cflag;
	unsigned long flags;
	int baud;
	int baud;
	int ark3116_baud;
	int ark3116_baud;
	char *buf;
	char *buf;
@@ -176,16 +161,6 @@ static void ark3116_set_termios(struct tty_struct *tty,


	dbg("%s - port %d", __func__, port->number);
	dbg("%s - port %d", __func__, port->number);


	spin_lock_irqsave(&priv->lock, flags);
	if (!priv->termios_initialized) {
		*termios = tty_std_termios;
		termios->c_cflag = B9600 | CS8
					      | CREAD | HUPCL | CLOCAL;
		termios->c_ispeed = 9600;
		termios->c_ospeed = 9600;
		priv->termios_initialized = 1;
	}
	spin_unlock_irqrestore(&priv->lock, flags);


	cflag = termios->c_cflag;
	cflag = termios->c_cflag;
	termios->c_cflag &= ~(CMSPAR|CRTSCTS);
	termios->c_cflag &= ~(CMSPAR|CRTSCTS);
@@ -454,6 +429,7 @@ static struct usb_serial_driver ark3116_device = {
	.num_ports =		1,
	.num_ports =		1,
	.attach =		ark3116_attach,
	.attach =		ark3116_attach,
	.set_termios =		ark3116_set_termios,
	.set_termios =		ark3116_set_termios,
	.init_termios =		ark3116_init_termios,
	.ioctl =		ark3116_ioctl,
	.ioctl =		ark3116_ioctl,
	.tiocmget =		ark3116_tiocmget,
	.tiocmget =		ark3116_tiocmget,
	.open =			ark3116_open,
	.open =			ark3116_open,
+3 −9
Original line number Original line Diff line number Diff line
@@ -657,15 +657,7 @@ static int cypress_open(struct tty_struct *tty, struct usb_serial_port *port)
	spin_unlock_irqrestore(&priv->lock, flags);
	spin_unlock_irqrestore(&priv->lock, flags);


	/* Set termios */
	/* Set termios */
	result = cypress_write(tty, port, NULL, 0);
	cypress_send(port);

	if (result) {
		dev_err(&port->dev,
			"%s - failed setting the control lines - error %d\n",
							__func__, result);
		return result;
	} else
		dbg("%s - success setting the control lines", __func__);


	if (tty)
	if (tty)
		cypress_set_termios(tty, port, &priv->tmp_termios);
		cypress_set_termios(tty, port, &priv->tmp_termios);
@@ -1003,6 +995,8 @@ static void cypress_set_termios(struct tty_struct *tty,
	dbg("%s - port %d", __func__, port->number);
	dbg("%s - port %d", __func__, port->number);


	spin_lock_irqsave(&priv->lock, flags);
	spin_lock_irqsave(&priv->lock, flags);
	/* We can't clean this one up as we don't know the device type
	   early enough */
	if (!priv->termios_initialized) {
	if (!priv->termios_initialized) {
		if (priv->chiptype == CT_EARTHMATE) {
		if (priv->chiptype == CT_EARTHMATE) {
			*(tty->termios) = tty_std_termios;
			*(tty->termios) = tty_std_termios;
+3 −9
Original line number Original line Diff line number Diff line
@@ -89,8 +89,7 @@ static int empeg_chars_in_buffer(struct tty_struct *tty);
static void empeg_throttle(struct tty_struct *tty);
static void empeg_throttle(struct tty_struct *tty);
static void empeg_unthrottle(struct tty_struct *tty);
static void empeg_unthrottle(struct tty_struct *tty);
static int  empeg_startup(struct usb_serial *serial);
static int  empeg_startup(struct usb_serial *serial);
static void empeg_set_termios(struct tty_struct *tty,
static void empeg_init_termios(struct tty_struct *tty);
		struct usb_serial_port *port, struct ktermios *old_termios);
static void empeg_write_bulk_callback(struct urb *urb);
static void empeg_write_bulk_callback(struct urb *urb);
static void empeg_read_bulk_callback(struct urb *urb);
static void empeg_read_bulk_callback(struct urb *urb);


@@ -122,7 +121,7 @@ static struct usb_serial_driver empeg_device = {
	.throttle =		empeg_throttle,
	.throttle =		empeg_throttle,
	.unthrottle =		empeg_unthrottle,
	.unthrottle =		empeg_unthrottle,
	.attach =		empeg_startup,
	.attach =		empeg_startup,
	.set_termios =		empeg_set_termios,
	.init_termios =		empeg_init_termios,
	.write =		empeg_write,
	.write =		empeg_write,
	.write_room =		empeg_write_room,
	.write_room =		empeg_write_room,
	.chars_in_buffer =	empeg_chars_in_buffer,
	.chars_in_buffer =	empeg_chars_in_buffer,
@@ -148,9 +147,6 @@ static int empeg_open(struct tty_struct *tty,struct usb_serial_port *port)


	dbg("%s - port %d", __func__, port->number);
	dbg("%s - port %d", __func__, port->number);


	/* Force default termio settings */
	empeg_set_termios(tty, port, NULL);

	bytes_in = 0;
	bytes_in = 0;
	bytes_out = 0;
	bytes_out = 0;


@@ -423,11 +419,9 @@ static int empeg_startup(struct usb_serial *serial)
}
}




static void empeg_set_termios(struct tty_struct *tty,
static void empeg_init_termios(struct tty_struct *tty)
		struct usb_serial_port *port, struct ktermios *old_termios)
{
{
	struct ktermios *termios = tty->termios;
	struct ktermios *termios = tty->termios;
	dbg("%s - port %d", __func__, port->number);


	/*
	/*
	 * The empeg-car player wants these particular tty settings.
	 * The empeg-car player wants these particular tty settings.
+14 −17
Original line number Original line Diff line number Diff line
@@ -71,7 +71,6 @@ struct iuu_private {
	spinlock_t lock;	/* store irq state */
	spinlock_t lock;	/* store irq state */
	wait_queue_head_t delta_msr_wait;
	wait_queue_head_t delta_msr_wait;
	u8 line_status;
	u8 line_status;
	u8 termios_initialized;
	int tiostatus;		/* store IUART SIGNAL for tiocmget call */
	int tiostatus;		/* store IUART SIGNAL for tiocmget call */
	u8 reset;		/* if 1 reset is needed */
	u8 reset;		/* if 1 reset is needed */
	int poll;		/* number of poll */
	int poll;		/* number of poll */
@@ -1018,13 +1017,24 @@ static void iuu_close(struct usb_serial_port *port)
	}
	}
}
}


static void iuu_init_termios(struct tty_struct *tty)
{
	*(tty->termios) = tty_std_termios;
	tty->termios->c_cflag = CLOCAL | CREAD | CS8 | B9600
				| TIOCM_CTS | CSTOPB | PARENB;
	tty->termios->c_ispeed = 9600;
	tty->termios->c_ospeed = 9600;
	tty->termios->c_lflag = 0;
	tty->termios->c_oflag = 0;
	tty->termios->c_iflag = 0;
}

static int iuu_open(struct tty_struct *tty, struct usb_serial_port *port)
static int iuu_open(struct tty_struct *tty, struct usb_serial_port *port)
{
{
	struct usb_serial *serial = port->serial;
	struct usb_serial *serial = port->serial;
	u8 *buf;
	u8 *buf;
	int result;
	int result;
	u32 actual;
	u32 actual;
	unsigned long flags;
	struct iuu_private *priv = usb_get_serial_port_data(port);
	struct iuu_private *priv = usb_get_serial_port_data(port);


	dbg("%s -  port %d", __func__, port->number);
	dbg("%s -  port %d", __func__, port->number);
@@ -1063,21 +1073,7 @@ static int iuu_open(struct tty_struct *tty, struct usb_serial_port *port)
			  port->bulk_in_buffer, 512,
			  port->bulk_in_buffer, 512,
			  NULL, NULL);
			  NULL, NULL);


	/* set the termios structure */
	spin_lock_irqsave(&priv->lock, flags);
	if (tty && !priv->termios_initialized) {
		*(tty->termios) = tty_std_termios;
		tty->termios->c_cflag = CLOCAL | CREAD | CS8 | B9600
					| TIOCM_CTS | CSTOPB | PARENB;
		tty->termios->c_ispeed = 9600;
		tty->termios->c_ospeed = 9600;
		tty->termios->c_lflag = 0;
		tty->termios->c_oflag = 0;
		tty->termios->c_iflag = 0;
		priv->termios_initialized = 1;
	priv->poll = 0;
	priv->poll = 0;
	}
	spin_unlock_irqrestore(&priv->lock, flags);


	/* initialize writebuf */
	/* initialize writebuf */
#define FISH(a, b, c, d) do { \
#define FISH(a, b, c, d) do { \
@@ -1200,6 +1196,7 @@ static struct usb_serial_driver iuu_device = {
	.tiocmget = iuu_tiocmget,
	.tiocmget = iuu_tiocmget,
	.tiocmset = iuu_tiocmset,
	.tiocmset = iuu_tiocmset,
	.set_termios = iuu_set_termios,
	.set_termios = iuu_set_termios,
	.init_termios = iuu_init_termios,
	.attach = iuu_startup,
	.attach = iuu_startup,
	.release = iuu_release,
	.release = iuu_release,
};
};
Loading