Changeset 12063


Ignore:
Timestamp:
05/08/09 15:46:41 (4 years ago)
Author:
BrainSlayer
Message:

latest sierra driver

File:
1 edited

Legend:

Unmodified
Added
Removed
  • src/linux/xscale/linux-2.6.23/drivers/usb/serial/sierra.c

    r11999 r12063  
    33 
    44  Copyright (C) 2006, 2007, 2008  Kevin Lloyd <klloyd@sierrawireless.com> 
     5  
     6  Copyright (C) 2008, 2009 Elina Pasheva, Matthew Safar, Rory Filer 
     7                           <linux@sierrawireless.com> 
    58 
    69  IMPORTANT DISCLAIMER: This driver is not commercially supported by 
     
    1619  Back ported to kernel 2.6.23 
    1720*/ 
    18  
    19 #define DRIVER_VERSION "v.1.3.1b" 
    20 #define DRIVER_AUTHOR "Kevin Lloyd <klloyd@sierrawireless.com>" 
     21/* Uncomment to log function calls */ 
     22/*#define DEBUG*/ 
     23#define DRIVER_VERSION "v.1.7.0" 
     24#define DRIVER_AUTHOR "Kevin Lloyd, Elina Pasheva, Matthew Safar, Rory Filer" 
    2125#define DRIVER_DESC "USB Driver for Sierra Wireless USB modems" 
    2226 
     
    2933#include <linux/usb.h> 
    3034#include <linux/usb/serial.h> 
    31 #include <linux/usb/ch9.h> 
    3235 
    3336#define SWIMS_USB_REQUEST_SetPower      0x00 
     
    3639#define SWIMS_SET_MODE_Modem            0x0001 
    3740 
    38 /* per port private data */ 
    3941#define N_IN_URB        8 
    4042#define N_OUT_URB       64 
    4143#define IN_BUFLEN       4096 
    4244 
    43  
    44 #define MAX_TRANSFER (PAGE_SIZE - 512) 
     45#define MAX_TRANSFER            (PAGE_SIZE - 512) 
     46/* MAX_TRANSFER is chosen so that the VM is not stressed by 
     47   allocations > PAGE_SIZE and the number of packets in a page 
     48   is an integer 512 is the largest possible packet on EHCI */ 
    4549 
    4650static int debug; 
    4751static int nmea; 
    4852static int truinstall = 1; 
     53static int suspend_support; 
    4954 
    5055enum devicetype { 
    51         DEVICE_3_PORT =         0, 
    52         DEVICE_1_PORT =         1, 
    53         DEVICE_INSTALLER =      2, 
     56        DEVICE_MODEM =          0, 
     57        DEVICE_INSTALLER =      1, 
    5458}; 
    5559 
     60/* list of interface numbers - used for constructing interface blacklists */ 
     61struct list { 
     62        const u32 listlen; /* number of interface numbers on list */ 
     63        const u8  *list;   /* pointer to the array holding the numbers */ 
     64}; 
     65 
     66/* static device type specific data */ 
     67struct sierra_device_static_info { 
     68        const enum devicetype   dev_type; 
     69        const struct list       iface_blacklist; 
     70}; 
     71 
    5672static int sierra_set_power_state(struct usb_device *udev, __u16 swiState) 
    5773{ 
    5874        int result; 
    59         dev_dbg(&udev->dev, "%s", __func__); 
     75        dev_dbg(&udev->dev, "%s\n", __func__); 
    6076        result = usb_control_msg(udev, usb_sndctrlpipe(udev, 0), 
    6177                        SWIMS_USB_REQUEST_SetPower,     /* __u8 request      */ 
     
    7288{ 
    7389        int result; 
    74         dev_dbg(&udev->dev, "%s", "DEVICE MODE SWITCH\n"); 
     90        dev_dbg(&udev->dev, "%s\n", "DEVICE MODE SWITCH"); 
    7591        result = usb_control_msg(udev, usb_sndctrlpipe(udev, 0), 
    7692                        SWIMS_USB_REQUEST_SetMode,      /* __u8 request      */ 
     
    87103{ 
    88104        int result; 
    89         dev_dbg(&udev->dev, "%s", __func__); 
     105        dev_dbg(&udev->dev, "%s\n", __func__); 
    90106        result = usb_control_msg(udev, usb_sndctrlpipe(udev, 0), 
    91107                        SWIMS_USB_REQUEST_SetNmea,      /* __u8 request      */ 
     
    101117static int sierra_calc_num_ports(struct usb_serial *serial) 
    102118{ 
    103         int result; 
    104         int *num_ports = usb_get_serial_data(serial); 
    105         dev_dbg(&serial->dev->dev, "%s", __func__); 
    106  
    107         result = *num_ports; 
    108  
    109         if (result) { 
    110                 kfree(num_ports); 
    111                 usb_set_serial_data(serial, NULL); 
    112         } 
    113  
    114         return result; 
     119        int num_ports = 0; 
     120        u8 ifnum, numendpoints; 
     121         
     122        dev_dbg(&serial->dev->dev, "%s\n", __func__); 
     123         
     124        ifnum = serial->interface->cur_altsetting->desc.bInterfaceNumber; 
     125        numendpoints = serial->interface->cur_altsetting->desc.bNumEndpoints; 
     126         
     127        /* Dummy interface present on some SKUs should be ignored */ 
     128        if (ifnum == 0x99) 
     129                num_ports = 0; 
     130        else if (numendpoints <= 3) 
     131                num_ports = 1; 
     132        else 
     133                num_ports = (numendpoints-1)/2; 
     134        return num_ports; 
     135} 
     136 
     137static int is_blacklisted(const u8 ifnum, const struct list *blacklist) 
     138{ 
     139        const u8  *list; 
     140        int i; 
     141         
     142        if (blacklist) { 
     143                list = blacklist->list; 
     144                 
     145                for (i=0; i < blacklist->listlen; i++) { 
     146                        if (list[i] == ifnum) 
     147                                return 1; 
     148                } 
     149        } 
     150        return 0; 
    115151} 
    116152 
     
    120156        struct usb_interface *p_interface; 
    121157        struct usb_host_interface *p_host_interface; 
    122         dev_dbg(&serial->dev->dev, "%s", __func__); 
     158        dev_dbg(&serial->dev->dev, "%s\n", __func__); 
    123159 
    124160        /* Get the interface structure pointer from the serial struct */ 
     
    139175                        const struct usb_device_id *id) 
    140176{ 
     177        const struct sierra_device_static_info * info;   
    141178        int result = 0; 
    142179        struct usb_device *udev; 
    143         int *num_ports; 
    144         u8 ifnum, ifclass, numendpoints; 
    145  
    146         dev_dbg(&serial->dev->dev, "%s", __func__); 
    147  
    148         num_ports = kmalloc(sizeof(*num_ports), GFP_KERNEL); 
    149         if (!num_ports) 
    150                 return -ENOMEM; 
    151  
    152         ifnum = serial->interface->cur_altsetting->desc.bInterfaceNumber; 
     180        u8 ifnum, ifclass;  
     181 
     182        udev = serial->dev; 
     183        dev_dbg(&udev->dev, "%s\n", __func__); 
     184 
     185        /* Check TRU-Install first */ 
     186        info = (const struct sierra_device_static_info *)id->driver_info; 
    153187        ifclass = serial->interface->cur_altsetting->desc.bInterfaceClass; 
    154         numendpoints = serial->interface->cur_altsetting->desc.bNumEndpoints; 
    155         udev = serial->dev; 
    156  
    157         /* Figure out the interface number from the serial structure */ 
     188        if (ifclass == USB_CLASS_MASS_STORAGE) { 
     189                /* If TRU-Install support is enabled, force to modem mode */ 
     190                if (truinstall && info && info->dev_type == DEVICE_INSTALLER) { 
     191                        dev_dbg(&udev->dev, "%s\n", "FOUND TRU-INSTALL DEVICE"); 
     192                        result = sierra_set_ms_mode(udev, SWIMS_SET_MODE_Modem); 
     193                } 
     194                return -ENODEV; 
     195        } 
     196         
    158197        ifnum = sierra_calc_interface(serial); 
    159  
     198        if (info && is_blacklisted(ifnum, &info->iface_blacklist)) { 
     199                dev_dbg(&serial->dev->dev, 
     200                        "Ignoring blacklisted interface #%d\n", ifnum); 
     201                return -ENODEV; 
     202        } 
     203         
    160204        /* 
    161205         * If this interface supports more than 1 alternate 
     
    168212                usb_set_interface(udev, ifnum, 1); 
    169213        } 
    170  
    171         if (ifclass == USB_CLASS_MASS_STORAGE) { 
    172                 /* If TRU-Install support is enabled, force to modem mode */ 
    173                 if (truinstall && id->driver_info == DEVICE_INSTALLER) { 
    174                         dev_dbg(&udev->dev, "%s", "FOUND TRU-INSTALL DEVICE\n"); 
    175                         result = sierra_set_ms_mode(udev, SWIMS_SET_MODE_Modem); 
    176                 } 
    177                 kfree(num_ports); 
    178                 return -EIO; 
    179         /* Dummy interface present on some SKUs should be ignored */ 
    180         } else if (ifnum == 0x99) 
    181                 *num_ports = 0; 
    182         else if (numendpoints <= 3) 
    183                 *num_ports = 1; 
    184         else 
    185                 *num_ports = (numendpoints-1)/2; 
    186  
    187         /* 
    188          * save off our num_ports info so that we can use it in the 
    189          * calc_num_ports callback 
     214        /* Be careful here, The ifnum, ifclass etc. might be incorrect, because 
     215         * of the usb_set_interface call. (all obtained using  
     216         * serial->interface->cur_altsetting that was changed by that call) 
    190217         */ 
    191         usb_set_serial_data(serial, (void *)num_ports); 
    192  
     218         
    193219        return result; 
    194220} 
     221 
     222static const struct sierra_device_static_info tru_inst_info = { 
     223        .dev_type = DEVICE_INSTALLER, 
     224}; 
     225 
     226static const u8 direct_ip_non_serial_ifaces[] = { 7, 8, 9, 10, 11 }; 
     227static const struct sierra_device_static_info direct_ip_interface_blacklist = { 
     228        .dev_type = DEVICE_MODEM, 
     229        .iface_blacklist = { 
     230                .listlen = ARRAY_SIZE( direct_ip_non_serial_ifaces ), 
     231                .list = direct_ip_non_serial_ifaces, 
     232        }, 
     233}; 
    195234 
    196235static struct usb_device_id id_table [] = { 
     
    226265        { USB_DEVICE(0x1199, 0x683A) }, /* Sierra Wireless MC8785 */ 
    227266        { USB_DEVICE(0x1199, 0x683B) }, /* Sierra Wireless MC8785 Composite */ 
    228         { USB_DEVICE(0x1199, 0x683C) }, /* Sierra Wireless MC8790 */ 
    229         { USB_DEVICE(0x1199, 0x683D) }, /* Sierra Wireless MC8790 */ 
    230         { USB_DEVICE(0x1199, 0x683E) }, /* Sierra Wireless MC8790 */ 
     267        /* Sierra Wireless MC8790, MC8791, MC8792 Composite */ 
     268        { USB_DEVICE(0x1199, 0x683C) },  
     269        { USB_DEVICE(0x1199, 0x683D) }, /* Sierra Wireless MC8791 Composite */ 
     270        /* Sierra Wireless MC8790, MC8791, MC8792 */ 
     271        { USB_DEVICE(0x1199, 0x683E) }, 
    231272        { USB_DEVICE(0x1199, 0x6850) }, /* Sierra Wireless AirCard 880 */ 
    232273        { USB_DEVICE(0x1199, 0x6851) }, /* Sierra Wireless AirCard 881 */ 
     
    248289        { USB_DEVICE(0x1199, 0x0112) }, /* Sierra Wireless AirCard 580 */ 
    249290        { USB_DEVICE(0x0F3D, 0x0112) }, /* Airprime/Sierra PC 5220 */ 
    250         { USB_DEVICE(0x1199, 0x68A3) }, /* Sierra Wireless Direct IP modems */ 
    251         { USB_DEVICE(0x05C6, 0x6613) }, /* Onda H600/ZTE MF330 */ 
    252  
    253         { USB_DEVICE(0x1199, 0x0FFF), .driver_info = DEVICE_INSTALLER}, 
     291 
     292        { USB_DEVICE(0x1199, 0x0FFF), 
     293                .driver_info = (kernel_ulong_t)&tru_inst_info 
     294        }, 
     295         
     296        { USB_DEVICE(0x1199, 0x68A3),   /* Sierra Wireless Direct IP modems */ 
     297                .driver_info = (kernel_ulong_t)&direct_ip_interface_blacklist  
     298        }, 
     299         
    254300        { } 
    255301}; 
    256302MODULE_DEVICE_TABLE(usb, id_table); 
    257303 
    258 static struct usb_driver sierra_driver = { 
    259         .name       = "sierra", 
    260         .probe      = usb_serial_probe, 
    261         .disconnect = usb_serial_disconnect, 
    262         .id_table   = id_table, 
    263 }; 
    264  
     304/* per port private data */ 
    265305struct sierra_port_private { 
    266306        spinlock_t lock;        /* lock the structure */ 
     
    269309        /* Input endpoints and buffers for this port */ 
    270310        struct urb *in_urbs[N_IN_URB]; 
    271         char *in_buffer[N_IN_URB]; 
    272311 
    273312        /* Settings for the port */ 
     
    286325        __u16 interface = 0; 
    287326 
    288         dbg("%s", __FUNCTION__); 
     327        dev_dbg(&port->dev, "%s\n", __func__); 
    289328 
    290329        portdata = usb_get_serial_port_data(port); 
    291330 
    292331        if (port->tty) { 
     332 
    293333                int val = 0; 
    294334                if (portdata->dtr_state) 
     
    296336                if (portdata->rts_state) 
    297337                        val |= 0x02; 
    298  
     338                         
    299339                /* If composite device then properly report interface */ 
    300                 if (serial->num_ports == 1) 
     340                if (serial->num_ports == 1) { 
    301341                        interface = sierra_calc_interface(serial); 
     342                        /* Control message is send only to interfaces with  
     343                         * interrupt_in endpoints 
     344                         */ 
     345                        if(port->interrupt_in_urb) { 
     346                                /* send control message */ 
     347                                return usb_control_msg(serial->dev, 
     348                                        usb_rcvctrlpipe(serial->dev, 0), 
     349                                        0x22, 0x21, val, interface, 
     350                                        NULL, 0, USB_CTRL_SET_TIMEOUT); 
     351                        } 
     352                } 
    302353 
    303354                /* Otherwise the need to do non-composite mapping */ 
     
    309360                        else if (port->bulk_out_endpointAddress == 5) 
    310361                                interface = 2; 
    311                 } 
    312  
    313                 return usb_control_msg(serial->dev, 
     362 
     363                        return usb_control_msg(serial->dev, 
    314364                                usb_rcvctrlpipe(serial->dev, 0), 
    315365                                0x22, 0x21, val, interface, 
    316366                                NULL, 0, USB_CTRL_SET_TIMEOUT); 
     367 
     368                } 
    317369        } 
    318370 
     
    323375                        struct ktermios *old_termios) 
    324376{ 
    325         dev_dbg(&port->dev, "%s", __func__); 
     377        dev_dbg(&port->dev, "%s\n", __func__); 
    326378        sierra_send_setup(port); 
    327379} 
     
    332384        struct sierra_port_private *portdata; 
    333385 
     386        dev_dbg(&port->dev, "%s\n", __func__); 
    334387        portdata = usb_get_serial_port_data(port); 
    335388 
     
    362415        return sierra_send_setup(port); 
    363416} 
     417static void sierra_release_urb(struct urb *urb) 
     418{ 
     419        struct usb_serial_port *port; 
     420        if (urb) { 
     421                port =  urb->context; 
     422                dev_dbg(&port->dev, "%s: %p\n", __func__, urb);  
     423                if (urb->transfer_buffer) 
     424                        kfree(urb->transfer_buffer); 
     425                usb_free_urb(urb); 
     426        } 
     427} 
    364428 
    365429static void sierra_outdat_callback(struct urb *urb) 
     
    370434        unsigned long flags; 
    371435 
    372         dev_dbg(&port->dev, "%s - port %d", __func__, port->number); 
     436        dev_dbg(&port->dev, "%s - port %d\n", __func__, port->number); 
    373437 
    374438        /* free up the transfer buffer, as usb_free_urb() does not do this */ 
     
    377441        if (status) 
    378442                dev_dbg(&port->dev, "%s - nonzero write bulk status " 
    379                     "received: %d", __func__, status); 
     443                    "received: %d\n", __func__, status); 
    380444 
    381445        spin_lock_irqsave(&portdata->lock, flags); 
     
    397461        size_t writesize = min((size_t)count, (size_t)MAX_TRANSFER); 
    398462        int retval = 0; 
    399          
    400         if (count==0) 
    401             return 0; 
     463 
     464        /* verify that we actually have some data to write */ 
     465        if (count == 0) 
     466                return 0; 
    402467 
    403468        portdata = usb_get_serial_port_data(port); 
    404469 
    405         dev_dbg(&port->dev, "%s: write (%d chars)", __func__, count); 
     470        dev_dbg(&port->dev, "%s: write (%d bytes)\n", __func__, writesize); 
    406471 
    407472        spin_lock_irqsave(&portdata->lock, flags); 
     
    428493        } 
    429494 
    430         memcpy(buffer, buf, writesize); 
     495        memcpy(buffer, buf, writesize);  
    431496 
    432497        usb_serial_debug_data(debug, &port->dev, __func__, writesize, buffer); 
     
    436501                                          port->bulk_out_endpointAddress), 
    437502                          buffer, writesize, sierra_outdat_callback, port); 
     503 
     504        /* Handle the need to send a zero length packet */ 
     505        urb->transfer_flags |= URB_ZERO_PACKET; 
    438506 
    439507        /* send it down the pipe */ 
     
    448516         * really free it when it is finished with it */ 
    449517        usb_free_urb(urb); 
    450  
     518         
    451519        return writesize; 
    452520error: 
     
    470538        int status = urb->status; 
    471539 
    472         dbg("%s: %p", __func__, urb); 
    473  
    474540        endpoint = usb_pipeendpoint(urb->pipe); 
    475541        port =  urb->context; 
     542         
     543        dev_dbg(&port->dev, "%s: %p\n", __func__, urb);  
    476544 
    477545        if (status) { 
    478546                dev_dbg(&port->dev, "%s: nonzero status: %d on" 
    479                     " endpoint %02x.", __func__, status, endpoint); 
     547                        " endpoint %02x\n", __func__, status, endpoint); 
    480548        } else { 
    481549                tty = port->tty; 
     
    484552                        tty_insert_flip_string(tty, data, urb->actual_length); 
    485553                        tty_flip_buffer_push(tty); 
     554                        usb_serial_debug_data(debug, &port->dev, __func__,  
     555                                urb->actual_length, data); 
    486556                } else { 
    487557                        dev_dbg(&port->dev, "%s: empty read urb" 
    488                                 " received", __func__); 
    489                 } 
    490  
    491                 /* Resubmit urb so we continue receiving */ 
    492                 if (port->open_count && status != -ESHUTDOWN) { 
    493                         err = usb_submit_urb(urb, GFP_ATOMIC); 
    494                         if (err) 
    495                                 dev_err(&port->dev, "resubmit read urb failed." 
    496                                         "(%d)\n", err); 
    497                 } 
    498         } 
     558                                " received\n", __func__); 
     559                } 
     560        } 
     561 
     562        /* Resubmit urb so we continue receiving */ 
     563        if (port->open_count && status != -ESHUTDOWN && status != -ENOENT) { 
     564                err = usb_submit_urb(urb, GFP_ATOMIC); 
     565                if (err) 
     566                        dev_err(&port->dev, "resubmit read urb failed." 
     567                                "(%d)\n", err); 
     568        } 
     569         
    499570        return; 
    500571} 
     
    508579        struct usb_serial *serial = port->serial; 
    509580 
    510         dev_dbg(&port->dev, "%s", __func__); 
    511         dev_dbg(&port->dev, "%s: urb %p port %p has data %p", __func__, 
     581        dev_dbg(&port->dev, "%s: urb %p port %p has data %p\n", __func__, 
    512582                urb, port, portdata); 
    513583 
     
    528598                                        sizeof(struct usb_ctrlrequest)); 
    529599 
    530                         dev_dbg(&port->dev, "%s: signal x%x", __func__, 
     600                        dev_dbg(&port->dev, "%s: signal x%x\n", __func__, 
    531601                                signals); 
    532602 
     
    541611                                tty_hangup(port->tty); 
    542612                } else { 
    543                         dev_dbg(&port->dev, "%s: type %x req %x", 
     613                        dev_dbg(&port->dev, "%s: type %x req %x\n", 
    544614                                __func__, req_pkt->bRequestType, 
    545615                                req_pkt->bRequest); 
    546616                } 
    547617        } else 
    548                 dev_dbg(&port->dev, "%s: error %d", __func__, status); 
     618                dev_dbg(&port->dev, "%s: error %d\n", __func__, status); 
    549619 
    550620        /* Resubmit urb so we continue receiving IRQ data */ 
    551         if (status != -ESHUTDOWN) { 
     621        if (port->open_count && status != -ESHUTDOWN && status != -ENOENT) { 
    552622                urb->dev = serial->dev; 
    553623                err = usb_submit_urb(urb, GFP_ATOMIC); 
    554624                if (err) 
    555                         dev_dbg(&port->dev, "%s: resubmit intr urb " 
    556                                 "failed. (%d)", __func__, err); 
     625                        dev_err(&port->dev, "%s: resubmit intr urb " 
     626                                "failed. (%d)\n", __func__, err); 
    557627        } 
    558628} 
     
    563633        unsigned long flags; 
    564634 
    565         dev_dbg(&port->dev, "%s - port %d", __func__, port->number); 
     635        dev_dbg(&port->dev, "%s - port %d\n", __func__, port->number); 
    566636 
    567637        /* try to give a good number back based on if we have any free urbs at 
     
    578648} 
    579649 
     650static void sierra_stop_rx_urbs(struct usb_serial_port *port) 
     651{ 
     652        int i; 
     653        struct sierra_port_private *portdata = usb_get_serial_port_data(port); 
     654         
     655        for (i = 0; i < ARRAY_SIZE(portdata->in_urbs); i++) { 
     656                usb_kill_urb(portdata->in_urbs[i]); 
     657        } 
     658        usb_kill_urb(port->interrupt_in_urb); 
     659} 
     660 
     661static int sierra_submit_rx_urbs(struct usb_serial_port *port) 
     662{ 
     663        int ok_cnt; 
     664        int err = -EINVAL; 
     665        int i; 
     666        struct urb * urb; 
     667        struct sierra_port_private *portdata = usb_get_serial_port_data(port); 
     668 
     669        ok_cnt = 0; 
     670        for (i = 0; i < ARRAY_SIZE(portdata->in_urbs); i++) { 
     671                urb = portdata->in_urbs[i]; 
     672                if (!urb) 
     673                        continue; 
     674                err = usb_submit_urb(urb, GFP_KERNEL); 
     675                if (err) { 
     676                        dev_err(&port->dev, "%s: submit urb failed: %d\n", 
     677                                __func__, err ); 
     678                } else { 
     679                        ok_cnt ++; 
     680                } 
     681        } 
     682 
     683        if (ok_cnt && port->interrupt_in_urb) { 
     684                err = usb_submit_urb(port->interrupt_in_urb, GFP_KERNEL); 
     685                if (err) { 
     686                        dev_err(&port->dev, "%s: submit intr urb failed: %d\n", 
     687                                __func__, err ); 
     688                } 
     689        } 
     690 
     691        if (ok_cnt > 0) /* at least one rx urb submitted */ 
     692                return 0; 
     693        else 
     694                return err; 
     695} 
     696 
     697static struct urb *sierra_setup_urb(struct usb_serial *serial, int endpoint, 
     698                                        int dir, void *ctx, int len, 
     699                                        usb_complete_t callback) 
     700{ 
     701        struct urb      *urb; 
     702        u8              *buf; 
     703         
     704        if (endpoint == -1) 
     705                return NULL; 
     706 
     707        urb = usb_alloc_urb( 0, GFP_KERNEL ); 
     708        if (urb == NULL) { 
     709                dev_dbg(&serial->dev->dev, "%s: alloc for endpoint %d failed\n",  
     710                        __func__, endpoint); 
     711                return NULL; 
     712        } 
     713         
     714        buf = kmalloc(len, GFP_KERNEL); 
     715        if (buf) 
     716        { 
     717                /* Fill URB using supplied data */ 
     718                usb_fill_bulk_urb(urb, serial->dev, 
     719                        usb_sndbulkpipe(serial->dev, endpoint) | dir, 
     720                        buf, len, callback, ctx); 
     721 
     722                /* debug */ 
     723                dev_dbg(&serial->dev->dev,"%s %c u:%p d:%p\n", __func__,  
     724                                dir == USB_DIR_IN?'i':'o', urb, buf ); 
     725        } else { 
     726                dev_dbg(&serial->dev->dev,"%s %c u:%p d:%p\n", __func__,  
     727                                dir == USB_DIR_IN?'i':'o', urb, buf ); 
     728 
     729                sierra_release_urb(urb); 
     730                urb = NULL; 
     731        } 
     732         
     733        return urb; 
     734} 
     735 
     736static void sierra_close(struct usb_serial_port *port, struct file *filp) 
     737{ 
     738        int i; 
     739        struct usb_serial *serial = port->serial; 
     740        struct sierra_port_private *portdata; 
     741 
     742        dev_dbg(&port->dev, "%s\n", __func__); 
     743        portdata = usb_get_serial_port_data(port); 
     744 
     745        portdata->rts_state = 0; 
     746        portdata->dtr_state = 0; 
     747 
     748        if (serial->dev) { 
     749                sierra_send_setup(port); 
     750 
     751                /* Stop reading urbs */ 
     752                sierra_stop_rx_urbs(port); 
     753                /* .. and release them */ 
     754                for (i = 0; i < N_IN_URB; i++) { 
     755                        sierra_release_urb(portdata->in_urbs[i]); 
     756                        portdata->in_urbs[i] = NULL; 
     757                } 
     758        } 
     759 
     760        port->tty = NULL; 
     761} 
     762 
    580763static int sierra_open(struct usb_serial_port *port, struct file *filp) 
    581764{ 
     
    583766        struct usb_serial *serial = port->serial; 
    584767        int i; 
     768        int err; 
     769        int endpoint; 
    585770        struct urb *urb; 
    586         int result; 
    587771 
    588772        portdata = usb_get_serial_port_data(port); 
    589773 
    590         dev_dbg(&port->dev, "%s", __func__); 
     774        dev_dbg(&port->dev, "%s\n", __func__); 
    591775 
    592776        /* Set some sane defaults */ 
    593777        portdata->rts_state = 1; 
    594778        portdata->dtr_state = 1; 
    595  
    596         /* Reset low level data toggle and start reading from endpoints */ 
    597         for (i = 0; i < N_IN_URB; i++) { 
    598                 urb = portdata->in_urbs[i]; 
    599                 if (!urb) 
    600                         continue; 
    601                 if (urb->dev != serial->dev) { 
    602                         dev_dbg(&port->dev, "%s: dev %p != %p", 
    603                                  __func__, urb->dev, serial->dev); 
    604                         continue; 
    605                 } 
    606  
    607                 /* 
    608                  * make sure endpoint data toggle is synchronized with the 
    609                  * device 
    610                  */ 
    611                 usb_clear_halt(urb->dev, urb->pipe); 
    612  
    613                 result = usb_submit_urb(urb, GFP_KERNEL); 
    614                 if (result) { 
    615                         dev_err(&port->dev, "submit urb %d failed (%d) %d\n", 
    616                                 i, result, urb->transfer_buffer_length); 
    617                 } 
    618         } 
    619  
    620         port->tty->low_latency = 1; 
    621  
     779         
     780        if (port->tty) { 
     781                port->tty->low_latency = 1; 
     782        } 
     783 
     784        spin_lock_init(&portdata->lock); 
     785         
     786        endpoint = port->bulk_in_endpointAddress; 
     787         
     788        for (i = 0; i < ARRAY_SIZE(portdata->in_urbs); i++) { 
     789                urb = sierra_setup_urb(serial, endpoint, USB_DIR_IN, port, 
     790                                        IN_BUFLEN, sierra_indat_callback); 
     791                portdata->in_urbs[i] = urb; 
     792        } 
     793        /* clear halt condition */ 
     794        usb_clear_halt(serial->dev,  
     795                        usb_sndbulkpipe(serial->dev, endpoint) | USB_DIR_IN); 
     796                 
     797        err = sierra_submit_rx_urbs(port); 
     798        if (err) { 
     799                /* get rid of everything as in close */ 
     800                sierra_close(port, filp); 
     801                return err; 
     802        } 
    622803        sierra_send_setup(port); 
    623804 
    624         /* start up the interrupt endpoint if we have one */ 
    625         if (port->interrupt_in_urb) { 
    626                 result = usb_submit_urb(port->interrupt_in_urb, GFP_KERNEL); 
    627                 if (result) 
    628                         dev_err(&port->dev, "submit irq_in urb failed %d\n", 
    629                                 result); 
    630         } 
    631805        return 0; 
    632 } 
    633  
    634 static void sierra_close(struct usb_serial_port *port, struct file *filp) 
    635 { 
    636         int i; 
    637         struct usb_serial *serial = port->serial; 
    638         struct sierra_port_private *portdata; 
    639  
    640         dev_dbg(&port->dev, "%s", __func__); 
    641         portdata = usb_get_serial_port_data(port); 
    642  
    643         portdata->rts_state = 0; 
    644         portdata->dtr_state = 0; 
    645  
    646         if (serial->dev) { 
    647                 sierra_send_setup(port); 
    648  
    649                 /* Stop reading/writing urbs */ 
    650                 for (i = 0; i < N_IN_URB; i++) 
    651                         usb_kill_urb(portdata->in_urbs[i]); 
    652         } 
    653  
    654         usb_kill_urb(port->interrupt_in_urb); 
    655  
    656         port->tty = NULL; 
    657806} 
    658807 
     
    661810        struct usb_serial_port *port; 
    662811        struct sierra_port_private *portdata; 
    663         struct urb *urb; 
    664812        int i; 
    665         int j; 
    666  
    667         dev_dbg(&serial->dev->dev, "%s", __func__); 
     813 
     814        dev_dbg(&serial->dev->dev, "%s\n", __func__); 
    668815 
    669816        /* Set Device mode to D0 */ 
     
    680827                if (!portdata) { 
    681828                        dev_dbg(&port->dev, "%s: kmalloc for " 
    682                                 "sierra_port_private (%d) failed!.", 
     829                                "sierra_port_private (%d) failed!\n", 
    683830                                __func__, i); 
    684831                        return -ENOMEM; 
    685832                } 
    686                 spin_lock_init(&portdata->lock); 
    687                 for (j = 0; j < N_IN_URB; j++) { 
    688                         portdata->in_buffer[j] = kmalloc(IN_BUFLEN, GFP_KERNEL); 
    689                         if (!portdata->in_buffer[j]) { 
    690                                 for (--j; j >= 0; j--) 
    691                                         kfree(portdata->in_buffer[j]); 
    692                                 kfree(portdata); 
    693                                 return -ENOMEM; 
    694                         } 
    695                 } 
    696  
     833                /* Set the port private data pointer */ 
    697834                usb_set_serial_port_data(port, portdata); 
    698  
    699                 /* initialize the in urbs */ 
    700                 for (j = 0; j < N_IN_URB; ++j) { 
    701                         urb = usb_alloc_urb(0, GFP_KERNEL); 
    702                         if (urb == NULL) { 
    703                                 dev_dbg(&port->dev, "%s: alloc for in " 
    704                                         "port failed.", __func__); 
    705                                 continue; 
    706                         } 
    707                         /* Fill URB using supplied data. */ 
    708                         usb_fill_bulk_urb(urb, serial->dev, 
    709                                           usb_rcvbulkpipe(serial->dev, 
    710                                                 port->bulk_in_endpointAddress), 
    711                                           portdata->in_buffer[j], IN_BUFLEN, 
    712                                           sierra_indat_callback, port); 
    713                         portdata->in_urbs[j] = urb; 
    714                 } 
    715835        } 
    716836 
     
    720840static void sierra_shutdown(struct usb_serial *serial) 
    721841{ 
    722         int i, j; 
     842        int i; 
    723843        struct usb_serial_port *port; 
    724844        struct sierra_port_private *portdata; 
    725845 
    726         dev_dbg(&serial->dev->dev, "%s", __func__); 
     846        dev_dbg(&serial->dev->dev, "%s\n", __func__); 
    727847 
    728848        for (i = 0; i < serial->num_ports; ++i) { 
     
    733853                if (!portdata) 
    734854                        continue; 
    735  
    736                 for (j = 0; j < N_IN_URB; j++) { 
    737                         usb_kill_urb(portdata->in_urbs[j]); 
    738                         usb_free_urb(portdata->in_urbs[j]); 
    739                         kfree(portdata->in_buffer[j]); 
    740                 } 
    741855                kfree(portdata); 
    742856                usb_set_serial_port_data(port, NULL); 
    743857        } 
    744858} 
     859 
     860int sierra_suspend(struct usb_serial *serial, pm_message_t message) 
     861{ 
     862        int i; 
     863 
     864        dev_dbg(&serial->dev->dev, "%s\n", __func__); 
     865 
     866        /* The dummy interface doesn't prevent suspended state */ 
     867        if (serial->num_ports == 0) 
     868                return 0; 
     869 
     870        if (!suspend_support) 
     871                return -EOPNOTSUPP; 
     872 
     873        for (i=0; i < serial->num_ports ; i++) { 
     874                sierra_stop_rx_urbs(serial->port[i]); 
     875        } 
     876        return 0; 
     877} 
     878 
     879int sierra_resume(struct usb_serial *serial) 
     880{ 
     881        int i; 
     882 
     883        dev_dbg(&serial->dev->dev, "%s\n", __func__); 
     884 
     885        for (i=0; i < serial->num_ports ; i++) { 
     886                sierra_submit_rx_urbs(serial->port[i]); 
     887        } 
     888 
     889        return 0; 
     890} 
     891 
     892static struct usb_driver sierra_driver = { 
     893        .name       = "sierra", 
     894        .probe      = usb_serial_probe, 
     895        .disconnect = usb_serial_disconnect, 
     896        .suspend    = usb_serial_suspend, 
     897        .resume     = usb_serial_resume, 
     898        .id_table   = id_table, 
     899 
     900        .no_dynamic_id        = 1, 
     901        .supports_autosuspend = 1, 
     902}; 
    745903 
    746904static struct usb_serial_driver sierra_device = { 
     
    767925        .shutdown          = sierra_shutdown, 
    768926        .read_int_callback = sierra_instat_callback, 
     927        .suspend           = sierra_suspend, 
     928        .resume            = sierra_resume, 
    769929}; 
    770930 
     
    814974module_param(debug, bool, S_IRUGO | S_IWUSR); 
    815975MODULE_PARM_DESC(debug, "Debug messages"); 
     976 
     977module_param(suspend_support, bool, S_IRUGO | S_IWUSR); 
     978MODULE_PARM_DESC(suspend_support, "Selective Suspend support"); 
Note: See TracChangeset for help on using the changeset viewer.