usbatm xusbatm.c,1.6,1.7
kagan at infradead.org
kagan at infradead.org
Thu Apr 21 08:45:33 EDT 2005
Update of /home/cvs/usbatm
In directory phoenix.infradead.org:/tmp/cvs-serv21096
Modified Files:
xusbatm.c
Log Message:
Add support for multi-interface devices.
Index: xusbatm.c
===================================================================
RCS file: /home/cvs/usbatm/xusbatm.c,v
retrieving revision 1.6
retrieving revision 1.7
diff -u -r1.6 -r1.7
--- xusbatm.c 9 Apr 2005 07:25:15 -0000 1.6
+++ xusbatm.c 21 Apr 2005 12:45:29 -0000 1.7
@@ -37,11 +37,8 @@
XUSBATM_PARM(vendor, unsigned short, ushort, "USB device vendor");
XUSBATM_PARM(product, unsigned short, ushort, "USB device product");
-/*
XUSBATM_PARM(rx_intf, unsigned char, byte, "rx interface number (default 0)");
XUSBATM_PARM(tx_intf, unsigned char, byte, "tx interface number (default 0)");
-*/
-
XUSBATM_PARM(rx_endpoint, unsigned char, byte, "rx endpoint number");
XUSBATM_PARM(tx_endpoint, unsigned char, byte, "tx endpoint number");
XUSBATM_PARM(rx_padding, unsigned char, byte, "rx padding (default 0)");
@@ -51,13 +48,60 @@
static struct usbatm_driver xusbatm_drivers[XUSBATM_DRIVERS_MAX];
static struct usb_device_id xusbatm_usb_ids[XUSBATM_DRIVERS_MAX + 1];
+static struct usb_driver xusbatm_usb_driver;
-/*
static int xusbatm_bind(struct usbatm_data *usbatm_instance,
struct usb_interface *intf, const struct usb_device_id *id,
int *need_heavy_init)
{
- dbg("xusbatm_bind");
+ struct usb_device *usb_dev = interface_to_usbdev(intf);
+ struct usb_interface *rx_if, *tx_if;
+ unsigned long drv_ix = id - xusbatm_usb_ids;
+ int ifnum = intf->altsetting->desc.bInterfaceNumber;
+ int ret;
+
+ usb_dbg(usbatm_instance, "%s: binding driver %d: vendor %#x product %#x"
+ " rx: intf %d ep %#x padd %d tx: intf %d ep %#x padd %d\n",
+ __func__, drv_ix, vendor[drv_ix], product[drv_ix],
+ rx_intf[drv_ix], rx_endpoint[drv_ix], rx_padding[drv_ix],
+ tx_intf[drv_ix], tx_endpoint[drv_ix], tx_padding[drv_ix]);
+
+ rx_if = usb_ifnum_to_if(usb_dev, rx_intf[drv_ix]);
+ if (!rx_if) {
+ usb_err(usbatm_instance, "%s: interface #%d unavailable\n",
+ __func__, rx_intf[drv_ix]);
+ return -ENODEV;
+ }
+ tx_if = usb_ifnum_to_if(usb_dev, tx_intf[drv_ix]);
+ if (!tx_if) {
+ usb_err(usbatm_instance, "%s: interface #%d unavailable\n",
+ __func__, tx_intf[drv_ix]);
+ return -ENODEV;
+ }
+
+ if (rx_intf[drv_ix] != ifnum) {
+ ret = usb_driver_claim_interface(&xusbatm_usb_driver,
+ rx_if, usbatm_instance);
+ if (!ret) {
+ usb_err(usbatm_instance, "%s: failed to claim interface #%d (%d)\n",
+ __func__, rx_intf[drv_ix], ret);
+ return ret;
+ }
+ }
+
+ if (tx_intf[drv_ix] != ifnum && tx_intf[drv_ix] != rx_intf[drv_ix]) {
+ ret = usb_driver_claim_interface(&xusbatm_usb_driver,
+ tx_if, usbatm_instance);
+ if (!ret) {
+ usb_err(usbatm_instance, "%s: failed to claim interface #%d (%d)\n",
+ __func__, tx_intf[drv_ix], ret);
+ if (rx_intf[drv_ix] != ifnum) {
+ usb_set_intfdata(rx_if, NULL);
+ usb_driver_release_interface(&xusbatm_usb_driver, rx_if);
+ }
+ return ret;
+ }
+ }
return 0;
}
@@ -65,14 +109,24 @@
static void xusbatm_unbind(struct usbatm_data *usbatm_instance,
struct usb_interface *intf)
{
- dbg("xusbatm_unbind");
+ struct usb_device *usb_dev = interface_to_usbdev(intf);
+ const int num_ifs = usb_dev->actconfig->desc.bNumInterfaces;
+ struct usb_interface *cur_if;
+ int i;
+ usb_dbg(usbatm_instance, "%s entered\n", __func__);
+
+ for(i = 0; i < num_ifs; i++)
+ if ((cur_if = usb_ifnum_to_if(usb_dev, i))) {
+ usb_set_intfdata(cur_if, NULL);
+ usb_driver_release_interface(&xusbatm_usb_driver, cur_if);
+ }
+
}
-*/
static int xusbatm_atm_start(struct usbatm_data *usbatm_instance,
struct atm_dev *atm_dev)
{
- atm_dbg(usbatm_instance, "%s entered\n", __func__);
+ atm_dbg(usbatm_instance, "%s entered\n", __func__);
/* use random MAC as we've no way to get it from the device */
random_ether_addr(atm_dev->esi);
@@ -84,13 +138,13 @@
static int xusbatm_usb_probe(struct usb_interface *intf,
const struct usb_device_id *id)
{
- return usbatm_usb_probe(intf, id,
+ return usbatm_usb_probe(intf, id,
xusbatm_drivers + (id - xusbatm_usb_ids));
}
static struct usb_driver xusbatm_usb_driver = {
.owner = THIS_MODULE,
- .name = xusbatm_driver_name,
+ .name = xusbatm_driver_name,
.probe = xusbatm_usb_probe,
.disconnect = usbatm_usb_disconnect,
.id_table = xusbatm_usb_ids
@@ -118,10 +172,8 @@
xusbatm_drivers[i].owner = THIS_MODULE;
xusbatm_drivers[i].driver_name = xusbatm_driver_name;
- /*
xusbatm_drivers[i].bind = xusbatm_bind;
xusbatm_drivers[i].unbind = xusbatm_unbind;
- */
xusbatm_drivers[i].atm_start = xusbatm_atm_start;
xusbatm_drivers[i].in = rx_endpoint[i];
xusbatm_drivers[i].out = tx_endpoint[i];
More information about the Usbatm-commits
mailing list