aboutsummaryrefslogtreecommitdiffstats
path: root/drivers/isdn/gigaset/usb-gigaset.c
diff options
context:
space:
mode:
authorTilman Schmidt <tilman@imap.cc>2009-10-25 05:30:07 -0400
committerDavid S. Miller <davem@davemloft.net>2009-10-29 04:37:10 -0400
commit2032e2c2309de02cd67b1d26aa701c2a57c4639f (patch)
treeee0f953f4afb7d98e3e27a32310d92bf0765b00b /drivers/isdn/gigaset/usb-gigaset.c
parent4dd8230acd20cb456cae02696b3da2986faad258 (diff)
usb_gigaset: code cleanup
Reorganize the code of the Gigaset M10x driver to make it more readable, less redundant, better aligned to the style of other parts of the driver, and cause fewer checkpatch.pl complaints. Impact: code reorganization, no functional change Signed-off-by: Tilman Schmidt <tilman@imap.cc> Signed-off-by: David S. Miller <davem@davemloft.net>
Diffstat (limited to 'drivers/isdn/gigaset/usb-gigaset.c')
-rw-r--r--drivers/isdn/gigaset/usb-gigaset.c69
1 files changed, 34 insertions, 35 deletions
diff --git a/drivers/isdn/gigaset/usb-gigaset.c b/drivers/isdn/gigaset/usb-gigaset.c
index 4deb1ab0dbf8..f56b2a83793e 100644
--- a/drivers/isdn/gigaset/usb-gigaset.c
+++ b/drivers/isdn/gigaset/usb-gigaset.c
@@ -43,14 +43,14 @@ MODULE_PARM_DESC(cidmode, "Call-ID mode");
43#define GIGASET_MODULENAME "usb_gigaset" 43#define GIGASET_MODULENAME "usb_gigaset"
44#define GIGASET_DEVNAME "ttyGU" 44#define GIGASET_DEVNAME "ttyGU"
45 45
46#define IF_WRITEBUF 2000 //FIXME // WAKEUP_CHARS: 256 46#define IF_WRITEBUF 2000 /* arbitrary limit */
47 47
48/* Values for the Gigaset M105 Data */ 48/* Values for the Gigaset M105 Data */
49#define USB_M105_VENDOR_ID 0x0681 49#define USB_M105_VENDOR_ID 0x0681
50#define USB_M105_PRODUCT_ID 0x0009 50#define USB_M105_PRODUCT_ID 0x0009
51 51
52/* table of devices that work with this driver */ 52/* table of devices that work with this driver */
53static const struct usb_device_id gigaset_table [] = { 53static const struct usb_device_id gigaset_table[] = {
54 { USB_DEVICE(USB_M105_VENDOR_ID, USB_M105_PRODUCT_ID) }, 54 { USB_DEVICE(USB_M105_VENDOR_ID, USB_M105_PRODUCT_ID) },
55 { } /* Terminating entry */ 55 { } /* Terminating entry */
56}; 56};
@@ -97,8 +97,8 @@ MODULE_DEVICE_TABLE(usb, gigaset_table);
97 * 41 19 -- -- -- -- 06 00 00 00 00 xx 11 13 97 * 41 19 -- -- -- -- 06 00 00 00 00 xx 11 13
98 * Used after every "configuration sequence" (RQ 12, RQs 01/03/13). 98 * Used after every "configuration sequence" (RQ 12, RQs 01/03/13).
99 * xx is usually 0x00 but was 0x7e before starting data transfer 99 * xx is usually 0x00 but was 0x7e before starting data transfer
100 * in unimodem mode. So, this might be an array of characters that need 100 * in unimodem mode. So, this might be an array of characters that
101 * special treatment ("commit all bufferd data"?), 11=^Q, 13=^S. 101 * need special treatment ("commit all bufferd data"?), 11=^Q, 13=^S.
102 * 102 *
103 * Unimodem mode: use "modprobe ppp_async flag_time=0" as the device _needs_ two 103 * Unimodem mode: use "modprobe ppp_async flag_time=0" as the device _needs_ two
104 * flags per packet. 104 * flags per packet.
@@ -114,7 +114,7 @@ static int gigaset_suspend(struct usb_interface *intf, pm_message_t message);
114static int gigaset_resume(struct usb_interface *intf); 114static int gigaset_resume(struct usb_interface *intf);
115static int gigaset_pre_reset(struct usb_interface *intf); 115static int gigaset_pre_reset(struct usb_interface *intf);
116 116
117static struct gigaset_driver *driver = NULL; 117static struct gigaset_driver *driver;
118 118
119/* usb specific object needed to register this driver with the usb subsystem */ 119/* usb specific object needed to register this driver with the usb subsystem */
120static struct usb_driver gigaset_usb_driver = { 120static struct usb_driver gigaset_usb_driver = {
@@ -141,6 +141,7 @@ struct usb_cardstate {
141 struct urb *bulk_out_urb; 141 struct urb *bulk_out_urb;
142 142
143 /* Input buffer */ 143 /* Input buffer */
144 unsigned char *rcvbuf;
144 int rcvbuf_size; 145 int rcvbuf_size;
145 struct urb *read_urb; 146 struct urb *read_urb;
146 __u8 int_in_endpointAddr; 147 __u8 int_in_endpointAddr;
@@ -164,13 +165,11 @@ static int gigaset_set_modem_ctrl(struct cardstate *cs, unsigned old_state,
164 val = tiocm_to_gigaset(new_state); 165 val = tiocm_to_gigaset(new_state);
165 166
166 gig_dbg(DEBUG_USBREQ, "set flags 0x%02x with mask 0x%02x", val, mask); 167 gig_dbg(DEBUG_USBREQ, "set flags 0x%02x with mask 0x%02x", val, mask);
167 // don't use this in an interrupt/BH
168 r = usb_control_msg(udev, usb_sndctrlpipe(udev, 0), 7, 0x41, 168 r = usb_control_msg(udev, usb_sndctrlpipe(udev, 0), 7, 0x41,
169 (val & 0xff) | ((mask & 0xff) << 8), 0, 169 (val & 0xff) | ((mask & 0xff) << 8), 0,
170 NULL, 0, 2000 /* timeout? */); 170 NULL, 0, 2000 /* timeout? */);
171 if (r < 0) 171 if (r < 0)
172 return r; 172 return r;
173 //..
174 return 0; 173 return 0;
175} 174}
176 175
@@ -220,7 +219,6 @@ static int gigaset_baud_rate(struct cardstate *cs, unsigned cflag)
220 cflag &= CBAUD; 219 cflag &= CBAUD;
221 220
222 switch (cflag) { 221 switch (cflag) {
223 //FIXME more values?
224 case B300: rate = 300; break; 222 case B300: rate = 300; break;
225 case B600: rate = 600; break; 223 case B600: rate = 600; break;
226 case B1200: rate = 1200; break; 224 case B1200: rate = 1200; break;
@@ -273,7 +271,7 @@ static int gigaset_set_line_ctrl(struct cardstate *cs, unsigned cflag)
273 /* set the number of stop bits */ 271 /* set the number of stop bits */
274 if (cflag & CSTOPB) { 272 if (cflag & CSTOPB) {
275 if ((cflag & CSIZE) == CS5) 273 if ((cflag & CSIZE) == CS5)
276 val |= 1; /* 1.5 stop bits */ //FIXME is this okay? 274 val |= 1; /* 1.5 stop bits */
277 else 275 else
278 val |= 2; /* 2 stop bits */ 276 val |= 2; /* 2 stop bits */
279 } 277 }
@@ -282,7 +280,7 @@ static int gigaset_set_line_ctrl(struct cardstate *cs, unsigned cflag)
282} 280}
283 281
284 282
285 /*================================================================================================================*/ 283/*============================================================================*/
286static int gigaset_init_bchannel(struct bc_state *bcs) 284static int gigaset_init_bchannel(struct bc_state *bcs)
287{ 285{
288 /* nothing to do for M10x */ 286 /* nothing to do for M10x */
@@ -344,7 +342,6 @@ static void gigaset_modem_fill(unsigned long data)
344 if (write_modem(cs) < 0) { 342 if (write_modem(cs) < 0) {
345 gig_dbg(DEBUG_OUTPUT, 343 gig_dbg(DEBUG_OUTPUT,
346 "modem_fill: write_modem failed"); 344 "modem_fill: write_modem failed");
347 // FIXME should we tell the LL?
348 again = 1; /* no callback will be called! */ 345 again = 1; /* no callback will be called! */
349 } 346 }
350 } 347 }
@@ -356,8 +353,8 @@ static void gigaset_modem_fill(unsigned long data)
356 */ 353 */
357static void gigaset_read_int_callback(struct urb *urb) 354static void gigaset_read_int_callback(struct urb *urb)
358{ 355{
359 struct inbuf_t *inbuf = urb->context; 356 struct cardstate *cs = urb->context;
360 struct cardstate *cs = inbuf->cs; 357 struct inbuf_t *inbuf = cs->inbuf;
361 int status = urb->status; 358 int status = urb->status;
362 int r; 359 int r;
363 unsigned numbytes; 360 unsigned numbytes;
@@ -368,7 +365,7 @@ static void gigaset_read_int_callback(struct urb *urb)
368 numbytes = urb->actual_length; 365 numbytes = urb->actual_length;
369 366
370 if (numbytes) { 367 if (numbytes) {
371 src = inbuf->rcvbuf; 368 src = cs->hw.usb->rcvbuf;
372 if (unlikely(*src)) 369 if (unlikely(*src))
373 dev_warn(cs->dev, 370 dev_warn(cs->dev,
374 "%s: There was no leading 0, but 0x%02x!\n", 371 "%s: There was no leading 0, but 0x%02x!\n",
@@ -440,7 +437,7 @@ static int send_cb(struct cardstate *cs, struct cmdbuf_t *cb)
440 struct cmdbuf_t *tcb; 437 struct cmdbuf_t *tcb;
441 unsigned long flags; 438 unsigned long flags;
442 int count; 439 int count;
443 int status = -ENOENT; // FIXME 440 int status = -ENOENT;
444 struct usb_cardstate *ucs = cs->hw.usb; 441 struct usb_cardstate *ucs = cs->hw.usb;
445 442
446 do { 443 do {
@@ -480,7 +477,9 @@ static int send_cb(struct cardstate *cs, struct cmdbuf_t *cb)
480 ucs->busy = 1; 477 ucs->busy = 1;
481 478
482 spin_lock_irqsave(&cs->lock, flags); 479 spin_lock_irqsave(&cs->lock, flags);
483 status = cs->connected ? usb_submit_urb(ucs->bulk_out_urb, GFP_ATOMIC) : -ENODEV; 480 status = cs->connected ?
481 usb_submit_urb(ucs->bulk_out_urb, GFP_ATOMIC) :
482 -ENODEV;
484 spin_unlock_irqrestore(&cs->lock, flags); 483 spin_unlock_irqrestore(&cs->lock, flags);
485 484
486 if (status) { 485 if (status) {
@@ -510,8 +509,8 @@ static int gigaset_write_cmd(struct cardstate *cs, const unsigned char *buf,
510 509
511 if (len <= 0) 510 if (len <= 0)
512 return 0; 511 return 0;
513 512 cb = kmalloc(sizeof(struct cmdbuf_t) + len, GFP_ATOMIC);
514 if (!(cb = kmalloc(sizeof(struct cmdbuf_t) + len, GFP_ATOMIC))) { 513 if (!cb) {
515 dev_err(cs->dev, "%s: out of memory\n", __func__); 514 dev_err(cs->dev, "%s: out of memory\n", __func__);
516 return -ENOMEM; 515 return -ENOMEM;
517 } 516 }
@@ -637,9 +636,7 @@ static int write_modem(struct cardstate *cs)
637 return -EINVAL; 636 return -EINVAL;
638 } 637 }
639 638
640 /* Copy data to bulk out buffer and // FIXME copying not necessary 639 /* Copy data to bulk out buffer and transmit data */
641 * transmit data
642 */
643 count = min(bcs->tx_skb->len, (unsigned) ucs->bulk_out_size); 640 count = min(bcs->tx_skb->len, (unsigned) ucs->bulk_out_size);
644 skb_copy_from_linear_data(bcs->tx_skb, ucs->bulk_out_buffer, count); 641 skb_copy_from_linear_data(bcs->tx_skb, ucs->bulk_out_buffer, count);
645 skb_pull(bcs->tx_skb, count); 642 skb_pull(bcs->tx_skb, count);
@@ -650,7 +647,8 @@ static int write_modem(struct cardstate *cs)
650 if (cs->connected) { 647 if (cs->connected) {
651 usb_fill_bulk_urb(ucs->bulk_out_urb, ucs->udev, 648 usb_fill_bulk_urb(ucs->bulk_out_urb, ucs->udev,
652 usb_sndbulkpipe(ucs->udev, 649 usb_sndbulkpipe(ucs->udev,
653 ucs->bulk_out_endpointAddr & 0x0f), 650 ucs->bulk_out_endpointAddr &
651 0x0f),
654 ucs->bulk_out_buffer, count, 652 ucs->bulk_out_buffer, count,
655 gigaset_write_bulk_callback, cs); 653 gigaset_write_bulk_callback, cs);
656 ret = usb_submit_urb(ucs->bulk_out_urb, GFP_ATOMIC); 654 ret = usb_submit_urb(ucs->bulk_out_urb, GFP_ATOMIC);
@@ -666,7 +664,7 @@ static int write_modem(struct cardstate *cs)
666 664
667 if (!bcs->tx_skb->len) { 665 if (!bcs->tx_skb->len) {
668 /* skb sent completely */ 666 /* skb sent completely */
669 gigaset_skb_sent(bcs, bcs->tx_skb); //FIXME also, when ret<0? 667 gigaset_skb_sent(bcs, bcs->tx_skb);
670 668
671 gig_dbg(DEBUG_INTR, "kfree skb (Adr: %lx)!", 669 gig_dbg(DEBUG_INTR, "kfree skb (Adr: %lx)!",
672 (unsigned long) bcs->tx_skb); 670 (unsigned long) bcs->tx_skb);
@@ -763,8 +761,8 @@ static int gigaset_probe(struct usb_interface *interface,
763 buffer_size = le16_to_cpu(endpoint->wMaxPacketSize); 761 buffer_size = le16_to_cpu(endpoint->wMaxPacketSize);
764 ucs->rcvbuf_size = buffer_size; 762 ucs->rcvbuf_size = buffer_size;
765 ucs->int_in_endpointAddr = endpoint->bEndpointAddress; 763 ucs->int_in_endpointAddr = endpoint->bEndpointAddress;
766 cs->inbuf[0].rcvbuf = kmalloc(buffer_size, GFP_KERNEL); 764 ucs->rcvbuf = kmalloc(buffer_size, GFP_KERNEL);
767 if (!cs->inbuf[0].rcvbuf) { 765 if (!ucs->rcvbuf) {
768 dev_err(cs->dev, "Couldn't allocate rcvbuf\n"); 766 dev_err(cs->dev, "Couldn't allocate rcvbuf\n");
769 retval = -ENOMEM; 767 retval = -ENOMEM;
770 goto error; 768 goto error;
@@ -773,9 +771,9 @@ static int gigaset_probe(struct usb_interface *interface,
773 usb_fill_int_urb(ucs->read_urb, udev, 771 usb_fill_int_urb(ucs->read_urb, udev,
774 usb_rcvintpipe(udev, 772 usb_rcvintpipe(udev,
775 endpoint->bEndpointAddress & 0x0f), 773 endpoint->bEndpointAddress & 0x0f),
776 cs->inbuf[0].rcvbuf, buffer_size, 774 ucs->rcvbuf, buffer_size,
777 gigaset_read_int_callback, 775 gigaset_read_int_callback,
778 cs->inbuf + 0, endpoint->bInterval); 776 cs, endpoint->bInterval);
779 777
780 retval = usb_submit_urb(ucs->read_urb, GFP_KERNEL); 778 retval = usb_submit_urb(ucs->read_urb, GFP_KERNEL);
781 if (retval) { 779 if (retval) {
@@ -789,7 +787,7 @@ static int gigaset_probe(struct usb_interface *interface,
789 787
790 if (!gigaset_start(cs)) { 788 if (!gigaset_start(cs)) {
791 tasklet_kill(&cs->write_tasklet); 789 tasklet_kill(&cs->write_tasklet);
792 retval = -ENODEV; //FIXME 790 retval = -ENODEV;
793 goto error; 791 goto error;
794 } 792 }
795 return 0; 793 return 0;
@@ -798,11 +796,11 @@ error:
798 usb_kill_urb(ucs->read_urb); 796 usb_kill_urb(ucs->read_urb);
799 kfree(ucs->bulk_out_buffer); 797 kfree(ucs->bulk_out_buffer);
800 usb_free_urb(ucs->bulk_out_urb); 798 usb_free_urb(ucs->bulk_out_urb);
801 kfree(cs->inbuf[0].rcvbuf); 799 kfree(ucs->rcvbuf);
802 usb_free_urb(ucs->read_urb); 800 usb_free_urb(ucs->read_urb);
803 usb_set_intfdata(interface, NULL); 801 usb_set_intfdata(interface, NULL);
804 ucs->read_urb = ucs->bulk_out_urb = NULL; 802 ucs->read_urb = ucs->bulk_out_urb = NULL;
805 cs->inbuf[0].rcvbuf = ucs->bulk_out_buffer = NULL; 803 ucs->rcvbuf = ucs->bulk_out_buffer = NULL;
806 usb_put_dev(ucs->udev); 804 usb_put_dev(ucs->udev);
807 ucs->udev = NULL; 805 ucs->udev = NULL;
808 ucs->interface = NULL; 806 ucs->interface = NULL;
@@ -831,10 +829,10 @@ static void gigaset_disconnect(struct usb_interface *interface)
831 829
832 kfree(ucs->bulk_out_buffer); 830 kfree(ucs->bulk_out_buffer);
833 usb_free_urb(ucs->bulk_out_urb); 831 usb_free_urb(ucs->bulk_out_urb);
834 kfree(cs->inbuf[0].rcvbuf); 832 kfree(ucs->rcvbuf);
835 usb_free_urb(ucs->read_urb); 833 usb_free_urb(ucs->read_urb);
836 ucs->read_urb = ucs->bulk_out_urb = NULL; 834 ucs->read_urb = ucs->bulk_out_urb = NULL;
837 cs->inbuf[0].rcvbuf = ucs->bulk_out_buffer = NULL; 835 ucs->rcvbuf = ucs->bulk_out_buffer = NULL;
838 836
839 usb_put_dev(ucs->udev); 837 usb_put_dev(ucs->udev);
840 ucs->interface = NULL; 838 ucs->interface = NULL;
@@ -916,9 +914,10 @@ static int __init usb_gigaset_init(void)
916 int result; 914 int result;
917 915
918 /* allocate memory for our driver state and intialize it */ 916 /* allocate memory for our driver state and intialize it */
919 if ((driver = gigaset_initdriver(GIGASET_MINOR, GIGASET_MINORS, 917 driver = gigaset_initdriver(GIGASET_MINOR, GIGASET_MINORS,
920 GIGASET_MODULENAME, GIGASET_DEVNAME, 918 GIGASET_MODULENAME, GIGASET_DEVNAME,
921 &ops, THIS_MODULE)) == NULL) 919 &ops, THIS_MODULE);
920 if (driver == NULL)
922 goto error; 921 goto error;
923 922
924 /* register this driver with the USB subsystem */ 923 /* register this driver with the USB subsystem */