aboutsummaryrefslogtreecommitdiffstats
path: root/drivers/usb/serial/ipw.c
diff options
context:
space:
mode:
Diffstat (limited to 'drivers/usb/serial/ipw.c')
-rw-r--r--drivers/usb/serial/ipw.c184
1 files changed, 10 insertions, 174 deletions
diff --git a/drivers/usb/serial/ipw.c b/drivers/usb/serial/ipw.c
index e1d07840cee6..ca77e88836bd 100644
--- a/drivers/usb/serial/ipw.c
+++ b/drivers/usb/serial/ipw.c
@@ -34,7 +34,6 @@
34 * DCD, DTR, RTS, CTS which are currently faked. 34 * DCD, DTR, RTS, CTS which are currently faked.
35 * It's good enough for PPP at this point. It's based off all kinds of 35 * It's good enough for PPP at this point. It's based off all kinds of
36 * code found in usb/serial and usb/class 36 * code found in usb/serial and usb/class
37 *
38 */ 37 */
39 38
40#include <linux/kernel.h> 39#include <linux/kernel.h>
@@ -52,7 +51,7 @@
52/* 51/*
53 * Version Information 52 * Version Information
54 */ 53 */
55#define DRIVER_VERSION "v0.3" 54#define DRIVER_VERSION "v0.4"
56#define DRIVER_AUTHOR "Roelf Diedericks" 55#define DRIVER_AUTHOR "Roelf Diedericks"
57#define DRIVER_DESC "IPWireless tty driver" 56#define DRIVER_DESC "IPWireless tty driver"
58 57
@@ -65,8 +64,6 @@
65/* Message sizes */ 64/* Message sizes */
66#define EVENT_BUFFER_SIZE 0xFF 65#define EVENT_BUFFER_SIZE 0xFF
67#define CHAR2INT16(c1, c0) (((u32)((c1) & 0xff) << 8) + (u32)((c0) & 0xff)) 66#define CHAR2INT16(c1, c0) (((u32)((c1) & 0xff) << 8) + (u32)((c0) & 0xff))
68#define NUM_BULK_URBS 24
69#define NUM_CONTROL_URBS 16
70 67
71/* vendor/product pairs that are known work with this driver*/ 68/* vendor/product pairs that are known work with this driver*/
72#define IPW_VID 0x0bc3 69#define IPW_VID 0x0bc3
@@ -151,47 +148,6 @@ static struct usb_driver usb_ipw_driver = {
151 148
152static int debug; 149static int debug;
153 150
154static void ipw_read_bulk_callback(struct urb *urb)
155{
156 struct usb_serial_port *port = urb->context;
157 unsigned char *data = urb->transfer_buffer;
158 struct tty_struct *tty;
159 int result;
160 int status = urb->status;
161
162 dbg("%s - port %d", __func__, port->number);
163
164 if (status) {
165 dbg("%s - nonzero read bulk status received: %d",
166 __func__, status);
167 return;
168 }
169
170 usb_serial_debug_data(debug, &port->dev, __func__,
171 urb->actual_length, data);
172
173 tty = tty_port_tty_get(&port->port);
174 if (tty && urb->actual_length) {
175 tty_insert_flip_string(tty, data, urb->actual_length);
176 tty_flip_buffer_push(tty);
177 }
178 tty_kref_put(tty);
179
180 /* Continue trying to always read */
181 usb_fill_bulk_urb(port->read_urb, port->serial->dev,
182 usb_rcvbulkpipe(port->serial->dev,
183 port->bulk_in_endpointAddress),
184 port->read_urb->transfer_buffer,
185 port->read_urb->transfer_buffer_length,
186 ipw_read_bulk_callback, port);
187 result = usb_submit_urb(port->read_urb, GFP_ATOMIC);
188 if (result)
189 dev_err(&port->dev,
190 "%s - failed resubmitting read urb, error %d\n",
191 __func__, result);
192 return;
193}
194
195static int ipw_open(struct tty_struct *tty, struct usb_serial_port *port) 151static int ipw_open(struct tty_struct *tty, struct usb_serial_port *port)
196{ 152{
197 struct usb_device *dev = port->serial->dev; 153 struct usb_device *dev = port->serial->dev;
@@ -229,15 +185,7 @@ static int ipw_open(struct tty_struct *tty, struct usb_serial_port *port)
229 185
230 /*--2: Start reading from the device */ 186 /*--2: Start reading from the device */
231 dbg("%s: setting up bulk read callback", __func__); 187 dbg("%s: setting up bulk read callback", __func__);
232 usb_fill_bulk_urb(port->read_urb, dev, 188 usb_serial_generic_open(tty, port);
233 usb_rcvbulkpipe(dev, port->bulk_in_endpointAddress),
234 port->bulk_in_buffer,
235 port->bulk_in_size,
236 ipw_read_bulk_callback, port);
237 result = usb_submit_urb(port->read_urb, GFP_KERNEL);
238 if (result < 0)
239 dbg("%s - usb_submit_urb(read bulk) failed with status %d",
240 __func__, result);
241 189
242 /*--3: Tell the modem to open the floodgates on the rx bulk channel */ 190 /*--3: Tell the modem to open the floodgates on the rx bulk channel */
243 dbg("%s:asking modem for RxRead (RXBULK_ON)", __func__); 191 dbg("%s:asking modem for RxRead (RXBULK_ON)", __func__);
@@ -267,35 +215,6 @@ static int ipw_open(struct tty_struct *tty, struct usb_serial_port *port)
267 dev_err(&port->dev, 215 dev_err(&port->dev,
268 "initial flowcontrol failed (error = %d)\n", result); 216 "initial flowcontrol failed (error = %d)\n", result);
269 217
270
271 /*--5: raise the dtr */
272 dbg("%s:raising dtr", __func__);
273 result = usb_control_msg(dev, usb_sndctrlpipe(dev, 0),
274 IPW_SIO_SET_PIN,
275 USB_TYPE_VENDOR | USB_RECIP_INTERFACE | USB_DIR_OUT,
276 IPW_PIN_SETDTR,
277 0,
278 NULL,
279 0,
280 200000);
281 if (result < 0)
282 dev_err(&port->dev,
283 "setting dtr failed (error = %d)\n", result);
284
285 /*--6: raise the rts */
286 dbg("%s:raising rts", __func__);
287 result = usb_control_msg(dev, usb_sndctrlpipe(dev, 0),
288 IPW_SIO_SET_PIN,
289 USB_TYPE_VENDOR | USB_RECIP_INTERFACE | USB_DIR_OUT,
290 IPW_PIN_SETRTS,
291 0,
292 NULL,
293 0,
294 200000);
295 if (result < 0)
296 dev_err(&port->dev,
297 "setting dtr failed (error = %d)\n", result);
298
299 kfree(buf_flow_init); 218 kfree(buf_flow_init);
300 return 0; 219 return 0;
301} 220}
@@ -305,8 +224,8 @@ static void ipw_dtr_rts(struct usb_serial_port *port, int on)
305 struct usb_device *dev = port->serial->dev; 224 struct usb_device *dev = port->serial->dev;
306 int result; 225 int result;
307 226
308 /*--1: drop the dtr */ 227 dbg("%s: on = %d", __func__, on);
309 dbg("%s:dropping dtr", __func__); 228
310 result = usb_control_msg(dev, usb_sndctrlpipe(dev, 0), 229 result = usb_control_msg(dev, usb_sndctrlpipe(dev, 0),
311 IPW_SIO_SET_PIN, 230 IPW_SIO_SET_PIN,
312 USB_TYPE_VENDOR | USB_RECIP_INTERFACE | USB_DIR_OUT, 231 USB_TYPE_VENDOR | USB_RECIP_INTERFACE | USB_DIR_OUT,
@@ -316,22 +235,20 @@ static void ipw_dtr_rts(struct usb_serial_port *port, int on)
316 0, 235 0,
317 200000); 236 200000);
318 if (result < 0) 237 if (result < 0)
319 dev_err(&port->dev, "dropping dtr failed (error = %d)\n", 238 dev_err(&port->dev, "setting dtr failed (error = %d)\n",
320 result); 239 result);
321 240
322 /*--2: drop the rts */
323 dbg("%s:dropping rts", __func__);
324 result = usb_control_msg(dev, usb_sndctrlpipe(dev, 0), 241 result = usb_control_msg(dev, usb_sndctrlpipe(dev, 0),
325 IPW_SIO_SET_PIN, USB_TYPE_VENDOR | 242 IPW_SIO_SET_PIN, USB_TYPE_VENDOR |
326 USB_RECIP_INTERFACE | USB_DIR_OUT, 243 USB_RECIP_INTERFACE | USB_DIR_OUT,
327 on ? IPW_PIN_SETRTS : IPW_PIN_CLRRTS, 244 on ? IPW_PIN_SETRTS : IPW_PIN_CLRRTS,
328 0, 245 0,
329 NULL, 246 NULL,
330 0, 247 0,
331 200000); 248 200000);
332 if (result < 0) 249 if (result < 0)
333 dev_err(&port->dev, 250 dev_err(&port->dev, "setting rts failed (error = %d)\n",
334 "dropping rts failed (error = %d)\n", result); 251 result);
335} 252}
336 253
337static void ipw_close(struct usb_serial_port *port) 254static void ipw_close(struct usb_serial_port *port)
@@ -368,83 +285,7 @@ static void ipw_close(struct usb_serial_port *port)
368 dev_err(&port->dev, 285 dev_err(&port->dev,
369 "Disabling bulk RxRead failed (error = %d)\n", result); 286 "Disabling bulk RxRead failed (error = %d)\n", result);
370 287
371 /* shutdown any in-flight urbs that we know about */ 288 usb_serial_generic_close(port);
372 usb_kill_urb(port->read_urb);
373 usb_kill_urb(port->write_urb);
374}
375
376static void ipw_write_bulk_callback(struct urb *urb)
377{
378 struct usb_serial_port *port = urb->context;
379 int status = urb->status;
380
381 dbg("%s", __func__);
382
383 port->write_urb_busy = 0;
384
385 if (status)
386 dbg("%s - nonzero write bulk status received: %d",
387 __func__, status);
388
389 usb_serial_port_softint(port);
390}
391
392static int ipw_write(struct tty_struct *tty, struct usb_serial_port *port,
393 const unsigned char *buf, int count)
394{
395 struct usb_device *dev = port->serial->dev;
396 int ret;
397
398 dbg("%s: TOP: count=%d, in_interrupt=%ld", __func__,
399 count, in_interrupt());
400
401 if (count == 0) {
402 dbg("%s - write request of 0 bytes", __func__);
403 return 0;
404 }
405
406 spin_lock_bh(&port->lock);
407 if (port->write_urb_busy) {
408 spin_unlock_bh(&port->lock);
409 dbg("%s - already writing", __func__);
410 return 0;
411 }
412 port->write_urb_busy = 1;
413 spin_unlock_bh(&port->lock);
414
415 count = min(count, port->bulk_out_size);
416 memcpy(port->bulk_out_buffer, buf, count);
417
418 dbg("%s count now:%d", __func__, count);
419
420 usb_fill_bulk_urb(port->write_urb, dev,
421 usb_sndbulkpipe(dev, port->bulk_out_endpointAddress),
422 port->write_urb->transfer_buffer,
423 count,
424 ipw_write_bulk_callback,
425 port);
426
427 ret = usb_submit_urb(port->write_urb, GFP_ATOMIC);
428 if (ret != 0) {
429 port->write_urb_busy = 0;
430 dbg("%s - usb_submit_urb(write bulk) failed with error = %d",
431 __func__, ret);
432 return ret;
433 }
434
435 dbg("%s returning %d", __func__, count);
436 return count;
437}
438
439static int ipw_probe(struct usb_serial_port *port)
440{
441 return 0;
442}
443
444static int ipw_disconnect(struct usb_serial_port *port)
445{
446 usb_set_serial_port_data(port, NULL);
447 return 0;
448} 289}
449 290
450static struct usb_serial_driver ipw_device = { 291static struct usb_serial_driver ipw_device = {
@@ -453,17 +294,12 @@ static struct usb_serial_driver ipw_device = {
453 .name = "ipw", 294 .name = "ipw",
454 }, 295 },
455 .description = "IPWireless converter", 296 .description = "IPWireless converter",
456 .usb_driver = &usb_ipw_driver, 297 .usb_driver = &usb_ipw_driver,
457 .id_table = usb_ipw_ids, 298 .id_table = usb_ipw_ids,
458 .num_ports = 1, 299 .num_ports = 1,
459 .open = ipw_open, 300 .open = ipw_open,
460 .close = ipw_close, 301 .close = ipw_close,
461 .dtr_rts = ipw_dtr_rts, 302 .dtr_rts = ipw_dtr_rts,
462 .port_probe = ipw_probe,
463 .port_remove = ipw_disconnect,
464 .write = ipw_write,
465 .write_bulk_callback = ipw_write_bulk_callback,
466 .read_bulk_callback = ipw_read_bulk_callback,
467}; 303};
468 304
469 305