diff options
author | Johan Hovold <jhovold@gmail.com> | 2013-05-08 11:51:43 -0400 |
---|---|---|
committer | Greg Kroah-Hartman <gregkh@linuxfoundation.org> | 2013-05-16 20:32:21 -0400 |
commit | dcf0105039660e951dfea348d317043d17988dfc (patch) | |
tree | 17b7748bf83e08da5da530a257a81cc044110e91 /drivers/usb/serial/generic.c | |
parent | 0693196fe7bbb5e6cafd255dfce91ff6d10bc18f (diff) |
USB: serial: add generic wait_until_sent implementation
Add generic wait_until_sent implementation which polls for empty
hardware buffers using the new port-operation tx_empty.
The generic implementation will be used for all sub-drivers that
implement tx_empty but does not define wait_until_sent.
Signed-off-by: Johan Hovold <jhovold@gmail.com>
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
Diffstat (limited to 'drivers/usb/serial/generic.c')
-rw-r--r-- | drivers/usb/serial/generic.c | 31 |
1 files changed, 31 insertions, 0 deletions
diff --git a/drivers/usb/serial/generic.c b/drivers/usb/serial/generic.c index 297665fdd16d..ba45170c78e5 100644 --- a/drivers/usb/serial/generic.c +++ b/drivers/usb/serial/generic.c | |||
@@ -253,6 +253,37 @@ int usb_serial_generic_chars_in_buffer(struct tty_struct *tty) | |||
253 | } | 253 | } |
254 | EXPORT_SYMBOL_GPL(usb_serial_generic_chars_in_buffer); | 254 | EXPORT_SYMBOL_GPL(usb_serial_generic_chars_in_buffer); |
255 | 255 | ||
256 | void usb_serial_generic_wait_until_sent(struct tty_struct *tty, long timeout) | ||
257 | { | ||
258 | struct usb_serial_port *port = tty->driver_data; | ||
259 | unsigned int bps; | ||
260 | unsigned long period; | ||
261 | unsigned long expire; | ||
262 | |||
263 | bps = tty_get_baud_rate(tty); | ||
264 | if (!bps) | ||
265 | bps = 9600; /* B0 */ | ||
266 | /* | ||
267 | * Use a poll-period of roughly the time it takes to send one | ||
268 | * character or at least one jiffy. | ||
269 | */ | ||
270 | period = max_t(unsigned long, (10 * HZ / bps), 1); | ||
271 | period = min_t(unsigned long, period, timeout); | ||
272 | |||
273 | dev_dbg(&port->dev, "%s - timeout = %u ms, period = %u ms\n", | ||
274 | __func__, jiffies_to_msecs(timeout), | ||
275 | jiffies_to_msecs(period)); | ||
276 | expire = jiffies + timeout; | ||
277 | while (!port->serial->type->tx_empty(port)) { | ||
278 | schedule_timeout_interruptible(period); | ||
279 | if (signal_pending(current)) | ||
280 | break; | ||
281 | if (time_after(jiffies, expire)) | ||
282 | break; | ||
283 | } | ||
284 | } | ||
285 | EXPORT_SYMBOL_GPL(usb_serial_generic_wait_until_sent); | ||
286 | |||
256 | static int usb_serial_generic_submit_read_urb(struct usb_serial_port *port, | 287 | static int usb_serial_generic_submit_read_urb(struct usb_serial_port *port, |
257 | int index, gfp_t mem_flags) | 288 | int index, gfp_t mem_flags) |
258 | { | 289 | { |