Commit b6e4114a authored by Konstantin Shkolnyy's avatar Konstantin Shkolnyy Committed by Sasha Levin

USB: cp210x: relocate private data from USB interface to port

[ Upstream commit e2ae67a3 ]

This change is preparation for implementing a cp2108 bug workaround.
The workaround requires storing some private data. Right now the data is
attached to the USB interface and allocated in the attach() callback.
The bug detection requires USB I/O which is done easier from port_probe()
callback rather than attach(). Since the USB access functions take port
as a parameter, and since the private data is used exclusively by these
functions, it can be allocated in port_probe(). Also, all cp210x devices
have exactly 1 port per USB iterface, so moving private data from the USB
interface to port is trivial.
Signed-off-by: default avatarKonstantin Shkolnyy <konstantin.shkolnyy@gmail.com>
Signed-off-by: default avatarJohan Hovold <johan@kernel.org>
Signed-off-by: default avatarSasha Levin <sasha.levin@oracle.com>
parent ab372348
...@@ -43,8 +43,8 @@ static int cp210x_tiocmset(struct tty_struct *, unsigned int, unsigned int); ...@@ -43,8 +43,8 @@ static int cp210x_tiocmset(struct tty_struct *, unsigned int, unsigned int);
static int cp210x_tiocmset_port(struct usb_serial_port *port, static int cp210x_tiocmset_port(struct usb_serial_port *port,
unsigned int, unsigned int); unsigned int, unsigned int);
static void cp210x_break_ctl(struct tty_struct *, int); static void cp210x_break_ctl(struct tty_struct *, int);
static int cp210x_startup(struct usb_serial *); static int cp210x_port_probe(struct usb_serial_port *);
static void cp210x_release(struct usb_serial *); static int cp210x_port_remove(struct usb_serial_port *);
static void cp210x_dtr_rts(struct usb_serial_port *p, int on); static void cp210x_dtr_rts(struct usb_serial_port *p, int on);
static const struct usb_device_id id_table[] = { static const struct usb_device_id id_table[] = {
...@@ -207,7 +207,7 @@ static const struct usb_device_id id_table[] = { ...@@ -207,7 +207,7 @@ static const struct usb_device_id id_table[] = {
MODULE_DEVICE_TABLE(usb, id_table); MODULE_DEVICE_TABLE(usb, id_table);
struct cp210x_serial_private { struct cp210x_port_private {
__u8 bInterfaceNumber; __u8 bInterfaceNumber;
}; };
...@@ -226,8 +226,8 @@ static struct usb_serial_driver cp210x_device = { ...@@ -226,8 +226,8 @@ static struct usb_serial_driver cp210x_device = {
.set_termios = cp210x_set_termios, .set_termios = cp210x_set_termios,
.tiocmget = cp210x_tiocmget, .tiocmget = cp210x_tiocmget,
.tiocmset = cp210x_tiocmset, .tiocmset = cp210x_tiocmset,
.attach = cp210x_startup, .port_probe = cp210x_port_probe,
.release = cp210x_release, .port_remove = cp210x_port_remove,
.dtr_rts = cp210x_dtr_rts .dtr_rts = cp210x_dtr_rts
}; };
...@@ -321,7 +321,7 @@ static int cp210x_get_config(struct usb_serial_port *port, u8 request, ...@@ -321,7 +321,7 @@ static int cp210x_get_config(struct usb_serial_port *port, u8 request,
unsigned int *data, int size) unsigned int *data, int size)
{ {
struct usb_serial *serial = port->serial; struct usb_serial *serial = port->serial;
struct cp210x_serial_private *spriv = usb_get_serial_data(serial); struct cp210x_port_private *port_priv = usb_get_serial_port_data(port);
__le32 *buf; __le32 *buf;
int result, i, length; int result, i, length;
...@@ -335,7 +335,7 @@ static int cp210x_get_config(struct usb_serial_port *port, u8 request, ...@@ -335,7 +335,7 @@ static int cp210x_get_config(struct usb_serial_port *port, u8 request,
/* Issue the request, attempting to read 'size' bytes */ /* Issue the request, attempting to read 'size' bytes */
result = usb_control_msg(serial->dev, usb_rcvctrlpipe(serial->dev, 0), result = usb_control_msg(serial->dev, usb_rcvctrlpipe(serial->dev, 0),
request, REQTYPE_INTERFACE_TO_HOST, 0x0000, request, REQTYPE_INTERFACE_TO_HOST, 0x0000,
spriv->bInterfaceNumber, buf, size, port_priv->bInterfaceNumber, buf, size,
USB_CTRL_GET_TIMEOUT); USB_CTRL_GET_TIMEOUT);
/* Convert data into an array of integers */ /* Convert data into an array of integers */
...@@ -366,7 +366,7 @@ static int cp210x_set_config(struct usb_serial_port *port, u8 request, ...@@ -366,7 +366,7 @@ static int cp210x_set_config(struct usb_serial_port *port, u8 request,
unsigned int *data, int size) unsigned int *data, int size)
{ {
struct usb_serial *serial = port->serial; struct usb_serial *serial = port->serial;
struct cp210x_serial_private *spriv = usb_get_serial_data(serial); struct cp210x_port_private *port_priv = usb_get_serial_port_data(port);
__le32 *buf; __le32 *buf;
int result, i, length; int result, i, length;
...@@ -385,13 +385,13 @@ static int cp210x_set_config(struct usb_serial_port *port, u8 request, ...@@ -385,13 +385,13 @@ static int cp210x_set_config(struct usb_serial_port *port, u8 request,
result = usb_control_msg(serial->dev, result = usb_control_msg(serial->dev,
usb_sndctrlpipe(serial->dev, 0), usb_sndctrlpipe(serial->dev, 0),
request, REQTYPE_HOST_TO_INTERFACE, 0x0000, request, REQTYPE_HOST_TO_INTERFACE, 0x0000,
spriv->bInterfaceNumber, buf, size, port_priv->bInterfaceNumber, buf, size,
USB_CTRL_SET_TIMEOUT); USB_CTRL_SET_TIMEOUT);
} else { } else {
result = usb_control_msg(serial->dev, result = usb_control_msg(serial->dev,
usb_sndctrlpipe(serial->dev, 0), usb_sndctrlpipe(serial->dev, 0),
request, REQTYPE_HOST_TO_INTERFACE, data[0], request, REQTYPE_HOST_TO_INTERFACE, data[0],
spriv->bInterfaceNumber, NULL, 0, port_priv->bInterfaceNumber, NULL, 0,
USB_CTRL_SET_TIMEOUT); USB_CTRL_SET_TIMEOUT);
} }
...@@ -873,29 +873,32 @@ static void cp210x_break_ctl(struct tty_struct *tty, int break_state) ...@@ -873,29 +873,32 @@ static void cp210x_break_ctl(struct tty_struct *tty, int break_state)
cp210x_set_config(port, CP210X_SET_BREAK, &state, 2); cp210x_set_config(port, CP210X_SET_BREAK, &state, 2);
} }
static int cp210x_startup(struct usb_serial *serial) static int cp210x_port_probe(struct usb_serial_port *port)
{ {
struct usb_serial *serial = port->serial;
struct usb_host_interface *cur_altsetting; struct usb_host_interface *cur_altsetting;
struct cp210x_serial_private *spriv; struct cp210x_port_private *port_priv;
spriv = kzalloc(sizeof(*spriv), GFP_KERNEL); port_priv = kzalloc(sizeof(*port_priv), GFP_KERNEL);
if (!spriv) if (!port_priv)
return -ENOMEM; return -ENOMEM;
cur_altsetting = serial->interface->cur_altsetting; cur_altsetting = serial->interface->cur_altsetting;
spriv->bInterfaceNumber = cur_altsetting->desc.bInterfaceNumber; port_priv->bInterfaceNumber = cur_altsetting->desc.bInterfaceNumber;
usb_set_serial_data(serial, spriv); usb_set_serial_port_data(port, port_priv);
return 0; return 0;
} }
static void cp210x_release(struct usb_serial *serial) static int cp210x_port_remove(struct usb_serial_port *port)
{ {
struct cp210x_serial_private *spriv; struct cp210x_port_private *port_priv;
port_priv = usb_get_serial_port_data(port);
kfree(port_priv);
spriv = usb_get_serial_data(serial); return 0;
kfree(spriv);
} }
module_usb_serial_driver(serial_drivers, id_table); module_usb_serial_driver(serial_drivers, id_table);
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment