Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

USB: usb_wwan/option: generalize option_send_setup for other drivers

Only the option driver implements the send_setup callback; it uses the
SET_CONTROL_LINE_STATE request in CDC ACM to generate DTR/RTS signals
on the port. This is not driver-specific though and is needed by other
drivers, so move the function to the usb_wwan driver (with formatting
tweaks), and replace the callback pointer with a flag that enables the
request.

Suggested-by: Bjørn Mork <bjorn@mork.no>
Suggested-by: Johan Hovold <johan@kernel.org>
Signed-off-by: David Ward <david.ward@ll.mit.edu>
Signed-off-by: Johan Hovold <johan@kernel.org>

authored by

David Ward and committed by
Johan Hovold
669e729f bd8869e8

+40 -40
+1 -35
drivers/usb/serial/option.c
··· 48 48 const struct usb_device_id *id); 49 49 static int option_attach(struct usb_serial *serial); 50 50 static void option_release(struct usb_serial *serial); 51 - static int option_send_setup(struct usb_serial_port *port); 52 51 static void option_instat_callback(struct urb *urb); 53 52 54 53 /* Vendor and product IDs */ ··· 1889 1890 1890 1891 if (!blacklist || !test_bit(iface_desc->bInterfaceNumber, 1891 1892 &blacklist->sendsetup)) { 1892 - data->send_setup = option_send_setup; 1893 + data->use_send_setup = 1; 1893 1894 } 1894 1895 spin_lock_init(&data->susp_lock); 1895 1896 ··· 1958 1959 dev_dbg(dev, "%s: resubmit intr urb failed. (%d)\n", 1959 1960 __func__, err); 1960 1961 } 1961 - } 1962 - 1963 - /** send RTS/DTR state to the port. 1964 - * 1965 - * This is exactly the same as SET_CONTROL_LINE_STATE from the PSTN 1966 - * CDC. 1967 - */ 1968 - static int option_send_setup(struct usb_serial_port *port) 1969 - { 1970 - struct usb_serial *serial = port->serial; 1971 - struct usb_wwan_port_private *portdata; 1972 - int ifNum = serial->interface->cur_altsetting->desc.bInterfaceNumber; 1973 - int val = 0; 1974 - int res; 1975 - 1976 - portdata = usb_get_serial_port_data(port); 1977 - 1978 - if (portdata->dtr_state) 1979 - val |= 0x01; 1980 - if (portdata->rts_state) 1981 - val |= 0x02; 1982 - 1983 - res = usb_autopm_get_interface(serial->interface); 1984 - if (res) 1985 - return res; 1986 - 1987 - res = usb_control_msg(serial->dev, usb_sndctrlpipe(serial->dev, 0), 1988 - 0x22, 0x21, val, ifNum, NULL, 1989 - 0, USB_CTRL_SET_TIMEOUT); 1990 - 1991 - usb_autopm_put_interface(serial->interface); 1992 - 1993 - return res; 1994 1962 } 1995 1963 1996 1964 MODULE_AUTHOR(DRIVER_AUTHOR);
+1 -1
drivers/usb/serial/usb-wwan.h
··· 34 34 struct usb_wwan_intf_private { 35 35 spinlock_t susp_lock; 36 36 unsigned int suspended:1; 37 + unsigned int use_send_setup:1; 37 38 int in_flight; 38 39 unsigned int open_ports; 39 - int (*send_setup) (struct usb_serial_port *port); 40 40 void *private; 41 41 }; 42 42
+38 -4
drivers/usb/serial/usb_wwan.c
··· 36 36 #include <linux/serial.h> 37 37 #include "usb-wwan.h" 38 38 39 + /* 40 + * Generate DTR/RTS signals on the port using the SET_CONTROL_LINE_STATE request 41 + * in CDC ACM. 42 + */ 43 + static int usb_wwan_send_setup(struct usb_serial_port *port) 44 + { 45 + struct usb_serial *serial = port->serial; 46 + struct usb_wwan_port_private *portdata; 47 + int val = 0; 48 + int ifnum; 49 + int res; 50 + 51 + portdata = usb_get_serial_port_data(port); 52 + 53 + if (portdata->dtr_state) 54 + val |= 0x01; 55 + if (portdata->rts_state) 56 + val |= 0x02; 57 + 58 + ifnum = serial->interface->cur_altsetting->desc.bInterfaceNumber; 59 + 60 + res = usb_autopm_get_interface(serial->interface); 61 + if (res) 62 + return res; 63 + 64 + res = usb_control_msg(serial->dev, usb_sndctrlpipe(serial->dev, 0), 65 + 0x22, 0x21, val, ifnum, NULL, 0, 66 + USB_CTRL_SET_TIMEOUT); 67 + 68 + usb_autopm_put_interface(port->serial->interface); 69 + 70 + return res; 71 + } 72 + 39 73 void usb_wwan_dtr_rts(struct usb_serial_port *port, int on) 40 74 { 41 75 struct usb_wwan_port_private *portdata; ··· 77 43 78 44 intfdata = usb_get_serial_data(port->serial); 79 45 80 - if (!intfdata->send_setup) 46 + if (!intfdata->use_send_setup) 81 47 return; 82 48 83 49 portdata = usb_get_serial_port_data(port); ··· 85 51 portdata->rts_state = on; 86 52 portdata->dtr_state = on; 87 53 88 - intfdata->send_setup(port); 54 + usb_wwan_send_setup(port); 89 55 } 90 56 EXPORT_SYMBOL(usb_wwan_dtr_rts); 91 57 ··· 118 84 portdata = usb_get_serial_port_data(port); 119 85 intfdata = usb_get_serial_data(port->serial); 120 86 121 - if (!intfdata->send_setup) 87 + if (!intfdata->use_send_setup) 122 88 return -EINVAL; 123 89 124 90 /* FIXME: what locks portdata fields ? */ ··· 131 97 portdata->rts_state = 0; 132 98 if (clear & TIOCM_DTR) 133 99 portdata->dtr_state = 0; 134 - return intfdata->send_setup(port); 100 + return usb_wwan_send_setup(port); 135 101 } 136 102 EXPORT_SYMBOL(usb_wwan_tiocmset); 137 103