diff options
author | David Ward <david.ward@ll.mit.edu> | 2015-09-16 12:27:57 -0400 |
---|---|---|
committer | Johan Hovold <johan@kernel.org> | 2015-10-09 06:42:40 -0400 |
commit | 669e729f9fb4e05ff02dfa01cbb8606549c6cb7c (patch) | |
tree | d7edd05b71e03caa3af530da3b79c83ff9306f55 | |
parent | bd8869e86b8a1e5e5b29fad766b2676bb74e5395 (diff) |
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>
-rw-r--r-- | drivers/usb/serial/option.c | 36 | ||||
-rw-r--r-- | drivers/usb/serial/usb-wwan.h | 2 | ||||
-rw-r--r-- | drivers/usb/serial/usb_wwan.c | 42 |
3 files changed, 40 insertions, 40 deletions
diff --git a/drivers/usb/serial/option.c b/drivers/usb/serial/option.c index 4d16c9744f54..edfaec19e1ae 100644 --- a/drivers/usb/serial/option.c +++ b/drivers/usb/serial/option.c | |||
@@ -48,7 +48,6 @@ static int option_probe(struct usb_serial *serial, | |||
48 | const struct usb_device_id *id); | 48 | const struct usb_device_id *id); |
49 | static int option_attach(struct usb_serial *serial); | 49 | static int option_attach(struct usb_serial *serial); |
50 | static void option_release(struct usb_serial *serial); | 50 | static void option_release(struct usb_serial *serial); |
51 | static int option_send_setup(struct usb_serial_port *port); | ||
52 | static void option_instat_callback(struct urb *urb); | 51 | static void option_instat_callback(struct urb *urb); |
53 | 52 | ||
54 | /* Vendor and product IDs */ | 53 | /* Vendor and product IDs */ |
@@ -1890,7 +1889,7 @@ static int option_attach(struct usb_serial *serial) | |||
1890 | 1889 | ||
1891 | if (!blacklist || !test_bit(iface_desc->bInterfaceNumber, | 1890 | if (!blacklist || !test_bit(iface_desc->bInterfaceNumber, |
1892 | &blacklist->sendsetup)) { | 1891 | &blacklist->sendsetup)) { |
1893 | data->send_setup = option_send_setup; | 1892 | data->use_send_setup = 1; |
1894 | } | 1893 | } |
1895 | spin_lock_init(&data->susp_lock); | 1894 | spin_lock_init(&data->susp_lock); |
1896 | 1895 | ||
@@ -1961,39 +1960,6 @@ static void option_instat_callback(struct urb *urb) | |||
1961 | } | 1960 | } |
1962 | } | 1961 | } |
1963 | 1962 | ||
1964 | /** send RTS/DTR state to the port. | ||
1965 | * | ||
1966 | * This is exactly the same as SET_CONTROL_LINE_STATE from the PSTN | ||
1967 | * CDC. | ||
1968 | */ | ||
1969 | static int option_send_setup(struct usb_serial_port *port) | ||
1970 | { | ||
1971 | struct usb_serial *serial = port->serial; | ||
1972 | struct usb_wwan_port_private *portdata; | ||
1973 | int ifNum = serial->interface->cur_altsetting->desc.bInterfaceNumber; | ||
1974 | int val = 0; | ||
1975 | int res; | ||
1976 | |||
1977 | portdata = usb_get_serial_port_data(port); | ||
1978 | |||
1979 | if (portdata->dtr_state) | ||
1980 | val |= 0x01; | ||
1981 | if (portdata->rts_state) | ||
1982 | val |= 0x02; | ||
1983 | |||
1984 | res = usb_autopm_get_interface(serial->interface); | ||
1985 | if (res) | ||
1986 | return res; | ||
1987 | |||
1988 | res = usb_control_msg(serial->dev, usb_sndctrlpipe(serial->dev, 0), | ||
1989 | 0x22, 0x21, val, ifNum, NULL, | ||
1990 | 0, USB_CTRL_SET_TIMEOUT); | ||
1991 | |||
1992 | usb_autopm_put_interface(serial->interface); | ||
1993 | |||
1994 | return res; | ||
1995 | } | ||
1996 | |||
1997 | MODULE_AUTHOR(DRIVER_AUTHOR); | 1963 | MODULE_AUTHOR(DRIVER_AUTHOR); |
1998 | MODULE_DESCRIPTION(DRIVER_DESC); | 1964 | MODULE_DESCRIPTION(DRIVER_DESC); |
1999 | MODULE_LICENSE("GPL"); | 1965 | MODULE_LICENSE("GPL"); |
diff --git a/drivers/usb/serial/usb-wwan.h b/drivers/usb/serial/usb-wwan.h index f22dff58b587..44b25c08c68a 100644 --- a/drivers/usb/serial/usb-wwan.h +++ b/drivers/usb/serial/usb-wwan.h | |||
@@ -34,9 +34,9 @@ extern int usb_wwan_resume(struct usb_serial *serial); | |||
34 | struct usb_wwan_intf_private { | 34 | struct usb_wwan_intf_private { |
35 | spinlock_t susp_lock; | 35 | spinlock_t susp_lock; |
36 | unsigned int suspended:1; | 36 | unsigned int suspended:1; |
37 | unsigned int use_send_setup:1; | ||
37 | int in_flight; | 38 | int in_flight; |
38 | unsigned int open_ports; | 39 | unsigned int open_ports; |
39 | int (*send_setup) (struct usb_serial_port *port); | ||
40 | void *private; | 40 | void *private; |
41 | }; | 41 | }; |
42 | 42 | ||
diff --git a/drivers/usb/serial/usb_wwan.c b/drivers/usb/serial/usb_wwan.c index 825305cb71d9..be9cb61b4d19 100644 --- a/drivers/usb/serial/usb_wwan.c +++ b/drivers/usb/serial/usb_wwan.c | |||
@@ -36,6 +36,40 @@ | |||
36 | #include <linux/serial.h> | 36 | #include <linux/serial.h> |
37 | #include "usb-wwan.h" | 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 | void usb_wwan_dtr_rts(struct usb_serial_port *port, int on) | 73 | void usb_wwan_dtr_rts(struct usb_serial_port *port, int on) |
40 | { | 74 | { |
41 | struct usb_wwan_port_private *portdata; | 75 | struct usb_wwan_port_private *portdata; |
@@ -43,7 +77,7 @@ void usb_wwan_dtr_rts(struct usb_serial_port *port, int on) | |||
43 | 77 | ||
44 | intfdata = usb_get_serial_data(port->serial); | 78 | intfdata = usb_get_serial_data(port->serial); |
45 | 79 | ||
46 | if (!intfdata->send_setup) | 80 | if (!intfdata->use_send_setup) |
47 | return; | 81 | return; |
48 | 82 | ||
49 | portdata = usb_get_serial_port_data(port); | 83 | portdata = usb_get_serial_port_data(port); |
@@ -51,7 +85,7 @@ void usb_wwan_dtr_rts(struct usb_serial_port *port, int on) | |||
51 | portdata->rts_state = on; | 85 | portdata->rts_state = on; |
52 | portdata->dtr_state = on; | 86 | portdata->dtr_state = on; |
53 | 87 | ||
54 | intfdata->send_setup(port); | 88 | usb_wwan_send_setup(port); |
55 | } | 89 | } |
56 | EXPORT_SYMBOL(usb_wwan_dtr_rts); | 90 | EXPORT_SYMBOL(usb_wwan_dtr_rts); |
57 | 91 | ||
@@ -84,7 +118,7 @@ int usb_wwan_tiocmset(struct tty_struct *tty, | |||
84 | portdata = usb_get_serial_port_data(port); | 118 | portdata = usb_get_serial_port_data(port); |
85 | intfdata = usb_get_serial_data(port->serial); | 119 | intfdata = usb_get_serial_data(port->serial); |
86 | 120 | ||
87 | if (!intfdata->send_setup) | 121 | if (!intfdata->use_send_setup) |
88 | return -EINVAL; | 122 | return -EINVAL; |
89 | 123 | ||
90 | /* FIXME: what locks portdata fields ? */ | 124 | /* FIXME: what locks portdata fields ? */ |
@@ -97,7 +131,7 @@ int usb_wwan_tiocmset(struct tty_struct *tty, | |||
97 | portdata->rts_state = 0; | 131 | portdata->rts_state = 0; |
98 | if (clear & TIOCM_DTR) | 132 | if (clear & TIOCM_DTR) |
99 | portdata->dtr_state = 0; | 133 | portdata->dtr_state = 0; |
100 | return intfdata->send_setup(port); | 134 | return usb_wwan_send_setup(port); |
101 | } | 135 | } |
102 | EXPORT_SYMBOL(usb_wwan_tiocmset); | 136 | EXPORT_SYMBOL(usb_wwan_tiocmset); |
103 | 137 | ||