linux 3g 模块总usb总断开链接,USB 3G卡热插拔那些事3------usb serial驱动

int usb_serial_probe(struct usb_interface *interface,

const struct usb_device_id *id)

{

struct usb_device *dev = interface_to_usbdev (interface);

struct usb_serial *serial = NULL;

struct usb_serial_port *port;

struct usb_host_interface *iface_desc;

struct usb_endpoint_descriptor *endpoint;

struct usb_endpoint_descriptor *interrupt_in_endpoint[MAX_NUM_PORTS];

struct usb_endpoint_descriptor *interrupt_out_endpoint[MAX_NUM_PORTS];

struct usb_endpoint_descriptor *bulk_in_endpoint[MAX_NUM_PORTS];

struct usb_endpoint_descriptor *bulk_out_endpoint[MAX_NUM_PORTS];

struct usb_serial_driver *type = NULL;

int retval;

int minor;

int buffer_size;

int i;

int num_interrupt_in = 0;

int num_interrupt_out = 0;

int num_bulk_in = 0;

int num_bulk_out = 0;

int num_ports = 0;

int max_endpoints;

type = search_serial_device(interface);

if (!type) {

dbg("none matched");

return -ENODEV;

}

serial = create_serial (dev, interface, type);

if (!serial) {

dev_err(&interface->dev, "%s - out of memory\n", __FUNCTION__);

return -ENOMEM;

}

/* if this device type has a probe function, call it */

if (type->probe) {

const struct usb_device_id *id;

if (!try_module_get(type->driver.owner)) {

dev_err(&interface->dev, "module get failed, exiting\n");

kfree (serial);

return -EIO;

}

id = usb_match_id(interface, type->id_table);

retval = type->probe(serial, id);

module_put(type->driver.owner);

if (retval) {

dbg ("sub driver rejected device");

kfree (serial);

return retval;

}

}

/* descriptor matches, let's find the endpoints needed */

/* check out the endpoints */

iface_desc = interface->cur_altsetting;

for (i = 0; i < iface_desc->desc.bNumEndpoints; i) {

endpoint = &iface_desc->endpoint[i].desc;

if ((endpoint->bEndpointAddress & 0x80) &&

((endpoint->bmAttributes & 3) == 0x02)) {

/* we found a bulk in endpoint */

dbg("found bulk in on endpoint %d", i);

bulk_in_endpoint[num_bulk_in] = endpoint;

num_bulk_in;

}

if (((endpoint->bEndpointAddress & 0x80) == 0x00) &&

((endpoint->bmAttributes & 3) == 0x02)) {

/* we found a bulk out endpoint */

dbg("found bulk out on endpoint %d", i);

bulk_out_endpoint[num_bulk_out] = endpoint;

num_bulk_out;

}

if ((endpoint->bEndpointAddress & 0x80) &&

((endpoint->bmAttributes & 3) == 0x03)) {

/* we found a interrupt in endpoint */

dbg("found interrupt in on endpoint %d", i);

interrupt_in_endpoint[num_interrupt_in] = endpoint;

num_interrupt_in;

}

if (((endpoint->bEndpointAddress & 0x80) == 0x00) &&

((endpoint->bmAttributes & 3) == 0x03)) {

/* we found an interrupt out endpoint */

dbg("found interrupt out on endpoint %d", i);

interrupt_out_endpoint[num_interrupt_out] = endpoint;

num_interrupt_out;

}

}

#if defined(CONFIG_USB_SERIAL_PL2303) || defined(CONFIG_USB_SERIAL_PL2303_MODULE)

/* BEGIN HORRIBLE HACK FOR PL2303 */

/* this is needed due to the looney way its endpoints are set up */

if (((le16_to_cpu(dev->descriptor.idVendor) == PL2303_VENDOR_ID) &&

(le16_to_cpu(dev->descriptor.idProduct) == PL2303_PRODUCT_ID)) ||

((le16_to_cpu(dev->descriptor.idVendor) == ATEN_VENDOR_ID) &&

(le16_to_cpu(dev->descriptor.idProduct) == ATEN_PRODUCT_ID))) {

if (interface != dev->actconfig->interface[0]) {

/* check out the endpoints of the other interface*/

iface_desc = dev->actconfig->interface[0]->cur_altsetting;

for (i = 0; i < iface_desc->desc.bNumEndpoints; i) {

endpoint = &iface_desc->endpoint[i].desc;

if ((endpoint->bEndpointAddress & 0x80) &&

((endpoint->bmAttributes & 3) == 0x03)) {

/* we found a interrupt in endpoint */

dbg("found interrupt in for Prolific device on separate interface");

interrupt_in_endpoint[num_interrupt_in] = endpoint;

num_interrupt_in;

}

}

}

/* Now make sure the PL-2303 is configured correctly.

* If not, give up now and hope this hack will work

* properly during a later invocation of usb_serial_probe

*/

if (num_bulk_in == 0 || num_bulk_out == 0) {

dev_info(&interface->dev, "PL-2303 hack: descriptors matched but endpoints did not\n");

kfree (serial);

return -ENODEV;

}

}

/* END HORRIBLE HACK FOR PL2303 */

#endif

/* found all that we need */

dev_info(&interface->dev, "%s converter detected\n", type->description);

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值