Beispiel #1
0
static int ipaq_startup(struct usb_serial *serial)
{
	dbg("%s", __func__);

	/*                                                             
                                                                  
                                         
  */
	if (serial->num_bulk_in < serial->num_ports ||
			serial->num_bulk_out < serial->num_ports)
		return -ENODEV;

	if (serial->dev->actconfig->desc.bConfigurationValue != 1) {
		/*
                                                               
                    
   */

		dev_err(&serial->dev->dev, "active config #%d != 1 ??\n",
			serial->dev->actconfig->desc.bConfigurationValue);
		return -ENODEV;
	}

	dbg("%s - iPAQ module configured for %d ports",
		__FUNCTION__, serial->num_ports);

	return usb_reset_configuration(serial->dev);
}
Beispiel #2
0
static int ipaq_startup(struct usb_serial *serial)
{
	/* Some of the devices in ipaq_id_table[] are composite, and we
	 * shouldn't bind to all the interfaces.  This test will rule out
	 * some obviously invalid possibilities.
	 */
	if (serial->num_bulk_in < serial->num_ports ||
			serial->num_bulk_out < serial->num_ports)
		return -ENODEV;

	if (serial->dev->actconfig->desc.bConfigurationValue != 1) {
		/*
		 * FIXME: HP iPaq rx3715, possibly others, have 1 config that
		 * is labeled as 2
		 */

		dev_err(&serial->dev->dev, "active config #%d != 1 ??\n",
			serial->dev->actconfig->desc.bConfigurationValue);
		return -ENODEV;
	}

	dev_dbg(&serial->dev->dev,
		"%s - iPAQ module configured for %d ports\n", __func__,
		serial->num_ports);

	return usb_reset_configuration(serial->dev);
}
Beispiel #3
0
static int lme2510_probe(struct usb_interface *intf,
		const struct usb_device_id *id)
{
	struct usb_device *udev = interface_to_usbdev(intf);
	int ret = 0;

	usb_reset_configuration(udev);

	usb_set_interface(udev, intf->cur_altsetting->desc.bInterfaceNumber, 1);

	if (udev->speed != USB_SPEED_HIGH) {
		ret = usb_reset_device(udev);
		info("DEV Failed to connect in HIGH SPEED mode");
		return -ENODEV;
	}

	lme_firmware_switch(udev, 0);

	if (0 == dvb_usb_device_init(intf, &lme2510_properties,
				     THIS_MODULE, NULL, adapter_nr)) {
		info("DEV registering device driver");
		return 0;
	}
	if (0 == dvb_usb_device_init(intf, &lme2510c_properties,
				     THIS_MODULE, NULL, adapter_nr)) {
		info("DEV registering device driver");
		return 0;
	}

	info("DEV lme2510 Error");
	return -ENODEV;

}
Beispiel #4
0
/* --------------------------------------------------------------------- */
static int dabusb_probe (struct usb_interface *intf,
			 const struct usb_device_id *id)
{
	struct usb_device *usbdev = interface_to_usbdev(intf);
	int retval;
	pdabusb_t s;

	dbg("dabusb: probe: vendor id 0x%x, device id 0x%x ifnum:%d",
	  usbdev->descriptor.idVendor, usbdev->descriptor.idProduct, intf->altsetting->desc.bInterfaceNumber);

	/* We don't handle multiple configurations */
	if (usbdev->descriptor.bNumConfigurations != 1)
		return -ENODEV;

	if (intf->altsetting->desc.bInterfaceNumber != _DABUSB_IF && usbdev->descriptor.idProduct == 0x9999)
		return -ENODEV;



	s = &dabusb[intf->minor];

	down (&s->mutex);
	s->remove_pending = 0;
	s->usbdev = usbdev;
	s->devnum = intf->minor;

	if (usb_reset_configuration (usbdev) < 0) {
		err("reset_configuration failed");
		goto reject;
	}
	if (usbdev->descriptor.idProduct == 0x2131) {
		dabusb_loadmem (s, NULL);
		goto reject;
	}
	else {
		dabusb_fpga_download (s, NULL);

		if (usb_set_interface (s->usbdev, _DABUSB_IF, 0) < 0) {
			err("set_interface failed");
			goto reject;
		}
	}
	dbg("bound to interface: %d", intf->altsetting->desc.bInterfaceNumber);
	usb_set_intfdata (intf, s);
	up (&s->mutex);

	retval = usb_register_dev(intf, &dabusb_class);
	if (retval) {
		usb_set_intfdata (intf, NULL);
		return -ENOMEM;
	}

	return 0;

      reject:
	up (&s->mutex);
	s->usbdev = NULL;
	return -ENODEV;
}
Beispiel #5
0
static int empeg_startup(struct usb_serial *serial)
{
	int r;

	dbg("%s", __func__);

	if (serial->dev->actconfig->desc.bConfigurationValue != 1) {
		dev_err(&serial->dev->dev, "active config #%d != 1 ??\n",
			serial->dev->actconfig->desc.bConfigurationValue);
		return -ENODEV;
	}
	dbg("%s - reset config", __func__);
	r = usb_reset_configuration(serial->dev);

	/* continue on with initialization */
	return r;
}
Beispiel #6
0
static void chatpad_idata_cb(struct urb *urb)
{
  struct usb_chatpad* chatpad = urb->context;

  printk(KERN_INFO "chatpad_chatpad_cb()\n");
  switch (urb->status) 
  {
    case 0:
      {
        int i = 0;
        printk(KERN_INFO "chatpad_chatpad_cb(): XXXXXXXXXXXXXXXXXXXXX ");
        for(i = 0; i < urb->actual_length; ++i)
        {
          printk("0x%02x ", (int)(((unsigned char*)urb->transfer_buffer)[i]));
        }
        printk("\n");
      }
      break;

    case -ECONNRESET:
    case -ENOENT:
    case -ESHUTDOWN: // triggered when the module get unloaded or device disconnected
      printk(KERN_INFO "chatpad_chatpad_cb(): fail1 %d\n", urb->status);
      return;

    default:
      printk(KERN_INFO "chatpad_chatpad_cb(): fail2 %d\n", urb->status);
      break;
  }

  {
    //struct usb_endpoint_descriptor* ep = &chatpad->intf->cur_altsetting->endpoint[0].desc;
    //usb_reset_endpoint(urb->dev, usb_rcvintpipe(urb->dev, ep->bEndpointAddress));

    //extern int usb_clear_halt(struct usb_device *dev, int pipe);
    int retval = usb_reset_configuration(chatpad->udev);
    printk(KERN_INFO "usb_reset(): %d\n", retval);
  }

  {
    int retval = usb_submit_urb(urb, GFP_ATOMIC);
    if (retval)
      err("%s - usb_submit_urb failed with result %d",
          __func__, retval);
  }
}
Beispiel #7
0
static int lme2510_identify_state(struct dvb_usb_device *d, const char **name)
{
	struct lme2510_state *st = d->priv;

	usb_reset_configuration(d->udev);

	usb_set_interface(d->udev,
		d->props->bInterfaceNumber, 1);

	st->dvb_usb_lme2510_firmware = dvb_usb_lme2510_firmware;

	if (lme2510_return_status(d) == 0x44) {
		*name = lme_firmware_switch(d, 0);
		return COLD;
	}

	return 0;
}
Beispiel #8
0
int protocol_configure_device(struct vfs_device_t *dev)
{
	unsigned int pipe = usb_sndctrlpipe(dev->udev, 0x00);

	int r;

	r = usb_reset_configuration(dev->udev);
	DBG("reset config : %d\n", r);
	usb_reset_endpoint(dev->udev, dev->bulkin_data_endpointAddr);
	usb_reset_endpoint(dev->udev, dev->bulkin_ctrl_endpointAddr);
	usb_reset_endpoint(dev->udev, dev->bulkout_endpointAddr);

	r = usb_control_msg(dev->udev, pipe, 3, 0, 1, 1, NULL, 0, 300 * HZ / 1000);
	DBG("ctrl_io : pipe=%u, result=%d\n", pipe, r);

	usb_set_device_state(dev->udev, USB_STATE_CONFIGURED);

	return r;
}
int st5481_setup_usb(struct st5481_adapter *adapter)
{
	struct usb_device *dev = adapter->usb_dev;
	struct st5481_ctrl *ctrl = &adapter->ctrl;
	struct st5481_intr *intr = &adapter->intr;
	struct usb_interface *intf;
	struct usb_host_interface *altsetting = NULL;
	struct usb_host_endpoint *endpoint;
	int status;
	struct urb *urb;
	u8 *buf;

	DBG(2, "");

	if ((status = usb_reset_configuration(dev)) < 0) {
		WARNING("reset_configuration failed,status=%d", status);
		return status;
	}

	intf = usb_ifnum_to_if(dev, 0);
	if (intf)
		altsetting = usb_altnum_to_altsetting(intf, 3);
	if (!altsetting)
		return -ENXIO;

	
	if (altsetting->desc.bNumEndpoints != 7) {
		WARNING("expecting 7 got %d endpoints!", altsetting->desc.bNumEndpoints);
		return -EINVAL;
	}

	
	altsetting->endpoint[3].desc.wMaxPacketSize = __constant_cpu_to_le16(32);
	altsetting->endpoint[4].desc.wMaxPacketSize = __constant_cpu_to_le16(32);

	
	if ((status = usb_set_interface(dev, 0, 3)) < 0) {
		WARNING("usb_set_interface failed,status=%d", status);
		return status;
	}

	
	urb = usb_alloc_urb(0, GFP_KERNEL);
	if (!urb) {
		return -ENOMEM;
	}
	ctrl->urb = urb;

	
	usb_fill_control_urb(urb, dev,
			     usb_sndctrlpipe(dev, 0),
			     NULL, NULL, 0, usb_ctrl_complete, adapter);


	fifo_init(&ctrl->msg_fifo.f, ARRAY_SIZE(ctrl->msg_fifo.data));

	
	urb = usb_alloc_urb(0, GFP_KERNEL);
	if (!urb) {
		return -ENOMEM;
	}
	intr->urb = urb;

	buf = kmalloc(INT_PKT_SIZE, GFP_KERNEL);
	if (!buf) {
		return -ENOMEM;
	}

	endpoint = &altsetting->endpoint[EP_INT-1];

	
	usb_fill_int_urb(urb, dev,
			 usb_rcvintpipe(dev, endpoint->desc.bEndpointAddress),
			 buf, INT_PKT_SIZE,
			 usb_int_complete, adapter,
			 endpoint->desc.bInterval);

	return 0;
}
Beispiel #10
0
int st5481_setup_usb(struct st5481_adapter *adapter)
{
	struct usb_device *dev = adapter->usb_dev;
	struct st5481_ctrl *ctrl = &adapter->ctrl;
	struct st5481_intr *intr = &adapter->intr;
	struct usb_interface *intf;
	struct usb_host_interface *altsetting = NULL;
	struct usb_host_endpoint *endpoint;
	int status;
	struct urb *urb;
	u8 *buf;
	
	DBG(2,"");
	
	if ((status = usb_reset_configuration (dev)) < 0) {
		WARNING("reset_configuration failed,status=%d",status);
		return status;
	}

	intf = usb_ifnum_to_if(dev, 0);
	if (intf)
		altsetting = usb_altnum_to_altsetting(intf, 3);
	if (!altsetting)
		return -ENXIO;

	// Check if the config is sane
	if ( altsetting->desc.bNumEndpoints != 7 ) {
		WARNING("expecting 7 got %d endpoints!", altsetting->desc.bNumEndpoints);
		return -EINVAL;
	}

	// The descriptor is wrong for some early samples of the ST5481 chip
	altsetting->endpoint[3].desc.wMaxPacketSize = __constant_cpu_to_le16(32);
	altsetting->endpoint[4].desc.wMaxPacketSize = __constant_cpu_to_le16(32);

	// Use alternative setting 3 on interface 0 to have 2B+D
	if ((status = usb_set_interface (dev, 0, 3)) < 0) {
		WARNING("usb_set_interface failed,status=%d",status);
		return status;
	}

	// Allocate URB for control endpoint
	urb = usb_alloc_urb(0, GFP_KERNEL);
	if (!urb) {
		return -ENOMEM;
	}
	ctrl->urb = urb;
	
	// Fill the control URB
	usb_fill_control_urb (urb, dev, 
			  usb_sndctrlpipe(dev, 0),
			  NULL, NULL, 0, usb_ctrl_complete, adapter);

		
	fifo_init(&ctrl->msg_fifo.f, ARRAY_SIZE(ctrl->msg_fifo.data));

	// Allocate URBs and buffers for interrupt endpoint
	urb = usb_alloc_urb(0, GFP_KERNEL);
	if (!urb) { 
		return -ENOMEM;
	}
	intr->urb = urb;
	
	buf = kmalloc(INT_PKT_SIZE, GFP_KERNEL);
	if (!buf) {
		return -ENOMEM;
	}

	endpoint = &altsetting->endpoint[EP_INT-1];
				
	// Fill the interrupt URB
	usb_fill_int_urb(urb, dev,
		     usb_rcvintpipe(dev, endpoint->desc.bEndpointAddress),
		     buf, INT_PKT_SIZE,
		     usb_int_complete, adapter,
		     endpoint->desc.bInterval);
		
	return 0;
}
Beispiel #11
0
static int probe(struct usb_interface *intf, const struct usb_device_id *id)
{
    int r;
    struct usb_device *udev = interface_to_usbdev(intf);
    struct net_device *netdev = NULL;

    print_id(udev);

    if (id->driver_info & DEVICE_INSTALLER)
        return eject_installer(intf);

    switch (udev->speed) {
    case USB_SPEED_LOW:
    case USB_SPEED_FULL:
    case USB_SPEED_HIGH:
        break;
    default:
        dev_dbg_f(&intf->dev, "Unknown USB speed\n");
        r = -ENODEV;
        goto error;
    }

    usb_reset_device(interface_to_usbdev(intf));

    netdev = zd_netdev_alloc(intf);
    if (netdev == NULL) {
        r = -ENOMEM;
        goto error;
    }

    r = upload_firmware(udev, id->driver_info);
    if (r) {
        dev_err(&intf->dev,
                "couldn't load firmware. Error number %d\n", r);
        goto error;
    }

    r = usb_reset_configuration(udev);
    if (r) {
        dev_dbg_f(&intf->dev,
                  "couldn't reset configuration. Error number %d\n", r);
        goto error;
    }

    /* At this point the interrupt endpoint is not generally enabled. We
     * save the USB bandwidth until the network device is opened. But
     * notify that the initialization of the MAC will require the
     * interrupts to be temporary enabled.
     */
    r = zd_mac_init_hw(zd_netdev_mac(netdev), id->driver_info);
    if (r) {
        dev_dbg_f(&intf->dev,
                  "couldn't initialize mac. Error number %d\n", r);
        goto error;
    }

    r = register_netdev(netdev);
    if (r) {
        dev_dbg_f(&intf->dev,
                  "couldn't register netdev. Error number %d\n", r);
        goto error;
    }

    dev_dbg_f(&intf->dev, "successful\n");
    dev_info(&intf->dev,"%s\n", netdev->name);
    return 0;
error:
    usb_reset_device(interface_to_usbdev(intf));
    zd_netdev_free(netdev);
    return r;
}
Beispiel #12
0
static int pcan_usb_plugin(struct usb_interface *interface, 
                           const struct usb_device_id *id)
{
	int err;
	int i, dev_ctrl_count, sizeof_if;
	struct usb_host_interface *iface_desc;
	struct usb_endpoint_descriptor *endpoint;
	struct usb_device *usb_dev = interface_to_usbdev(interface);
	struct pcan_usb_interface *usb_if;
	int (*device_init)(struct pcan_usb_interface *);

	DPRINTK(KERN_DEBUG "%s: %s(0x%04x, 0x%04x, 0x%04x)\n", 
	        DEVICE_NAME, __FUNCTION__,
	        usb_dev->descriptor.idVendor, usb_dev->descriptor.idProduct,
	        usb_dev->descriptor.bcdDevice);

	/* check endpoint addresses (numbers) and associated max data length */
	/* (only from setting 0) */
	/* Since USB-PRO defines also a LIN interface, should reject it when */
	/* adapter plugged: make use of endpoint addresses (no other way...) */
	iface_desc = &interface->altsetting[0];

	DPRINTK(KERN_DEBUG "%s: %s(): bNumEndpoints=%d\n", 
	        DEVICE_NAME, __FUNCTION__, iface_desc->desc.bNumEndpoints);

	for (i=0; i < iface_desc->desc.bNumEndpoints; i++)
	{
		struct usb_endpoint_descriptor *endpoint = &iface_desc->endpoint[i].desc;

		/* Below is the list of valid ep addreses. All other ep address */
		/* is considered as not-CAN interface address => no dev created */
		switch (endpoint->bEndpointAddress)
		{
		case 0x01:
		case 0x81:
		case 0x02:
		case 0x82:
		case 0x03:
		case 0x83:
			break;
		default:
#ifdef DEBUG
			printk(KERN_INFO "%s: %s(): EP address %02x not in CAN range.\n",
			       DEVICE_NAME, __FUNCTION__, endpoint->bEndpointAddress);
			printk(KERN_INFO "%s: %s(): ignoring the whole USB interface\n",
			       DEVICE_NAME, __FUNCTION__);
#endif
			return -ENODEV;
		}
	}

	// take the 1st configuration (it's default)
	if ((err = usb_reset_configuration(usb_dev)) < 0)
	{
		printk(KERN_ERR "%s: usb_set_configuration() failed!\n", DEVICE_NAME);
		return err;
	}

	// only 1 interface is supported
   // Note: HW_USB_PRO: interface#0 for CAN, #1 for LIN
	if ((err = usb_set_interface(usb_dev, 0, 0)) < 0)
	{
		printk(KERN_ERR "%s: usb_set_interface() failed!\n", DEVICE_NAME);
		return err;
	}

	/* Now, according to device id, create as many device as CAN controllers */
	switch (usb_dev->descriptor.idProduct)
	{

#ifdef HW_USB_PRO
	case PCAN_USBPRO_PRODUCT_ID:
		dev_ctrl_count = 2;
		device_init = pcan_usbpro_init;
		break;
#endif

	case PCAN_USB_PRODUCT_ID:
	default:
		dev_ctrl_count = 1;
		device_init = pcan_usb_init;
		break;
	}

	printk(KERN_INFO "%s: new ", DEVICE_NAME);
	if (usb_dev->speed == USB_SPEED_HIGH) printk("high speed ");
	printk("usb adapter with %u CAN controller(s) detected\n", dev_ctrl_count);

	/* create our interface object for the USB device */
	sizeof_if = sizeof(struct pcan_usb_interface) + \
	                                sizeof(struct pcandev) * (dev_ctrl_count-1);

	usb_if = (struct pcan_usb_interface *)kmalloc(sizeof_if, GFP_KERNEL);
	if (usb_if == NULL)
	{
		printk(KERN_ERR "%s: kmalloc(%d) failed!\n", DEVICE_NAME, sizeof_if);
		return err;
	}

	memset(usb_if, '\0', sizeof_if);

	// store pointer to kernel supplied usb_dev
	usb_if->usb_dev = usb_dev;
	usb_if->usb_intf = interface;
	usb_if->dev_ctrl_count = dev_ctrl_count;

	// preset finish flags
	atomic_set(&usb_if->cmd_sync_complete, 0);
	atomic_set(&usb_if->cmd_async_complete, 1);

	// preset active URB counter
	atomic_set(&usb_if->active_urbs, 0);

	init_waitqueue_head(&usb_if->usb_wait_queue);

	/* get endpoint addresses (numbers) and associated max data length */
	/* (only from setting 0) */
#ifdef HW_USB_PRO
/*
 *      Function   Interface   Endpoints            DeviceId
 *      ---------  ---------   -----------------------------------------
 *      Control                0
 *      CAN        0                                "CAN-Device", 
 *                                                  USB\VID_0c72&PID_000d&MI_00
 *                             1=Command,           bidi for both CAN_Ctrller
 *                             2=CAN-Controller 0,  rcv (IN) both CAN-Ctrller,
 *                                                  transmit (OUT) CAN-Ctrl#0,
 *                             3=CAN-Controller 1   transmit (OUT) CAN-Ctrl#1
 *      LIN        1                                "LIN-Device", 
 *                                                  USB\VID_0c72&PID_000d&MI_01
 *                             4=Command,
 *                             5=Controller 0,
 *                             6=Controller 1
 */
#endif
	for (i=0; i < iface_desc->desc.bNumEndpoints; i++)
	{
		PCAN_ENDPOINT *pipe_addr = NULL;

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

		DPRINTK(KERN_DEBUG "%s: %s(): EP[%d]={addr=%d max=%d}\n",
		        DEVICE_NAME, __FUNCTION__, i, endpoint->bEndpointAddress,
		        endpoint->wMaxPacketSize);

		switch (endpoint->bEndpointAddress)
		{
		case 0x01:
			pipe_addr = &usb_if->pipe_cmd_out;
			break;

		case 0x81:
			pipe_addr = &usb_if->pipe_cmd_in;
			break;

		case 0x02:
			switch (usb_dev->descriptor.idProduct)
			{
#ifdef HW_USB_PRO
			case PCAN_USBPRO_PRODUCT_ID:
#endif
			case PCAN_USB_PRODUCT_ID:
			default:
				pipe_addr = &usb_if->dev[0].port.usb.pipe_write;
				break;
			}
			break;

		case 0x82:
			pipe_addr = &usb_if->pipe_read;
			break;

#ifdef HW_USB_PRO
		case 0x03:
			switch (usb_dev->descriptor.idProduct)
			{
			case PCAN_USBPRO_PRODUCT_ID:
				pipe_addr = &usb_if->dev[1].port.usb.pipe_write;
				break;
			}
#endif

		case 0x83:
			/* Unused pipe for PCAN-USB-PRO */
			/* But seems that need to be reset too... */
			/* TBD */
			break;

		default:
			continue;
		}

		if (pipe_addr)
		{
			pipe_addr->ucNumber = endpoint->bEndpointAddress;
			pipe_addr->wDataSz  = le16_to_cpu(endpoint->wMaxPacketSize);
		}

#if LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,30)
		usb_reset_endpoint(usb_dev, endpoint->bEndpointAddress);
#endif
	}

	/* ucRevision needs to be defined before allocating resources (PCAN-USB) */
#if defined(__LITTLE_ENDIAN)
	usb_if->ucHardcodedDevNr = (uint8_t)(usb_if->usb_dev->descriptor.bcdDevice & 0xff);
	usb_if->ucRevision = (uint8_t)(usb_if->usb_dev->descriptor.bcdDevice >> 8);
#elif defined(__BIG_ENDIAN)
	usb_if->ucHardcodedDevNr = (uint8_t)(usb_if->usb_dev->descriptor.bcdDevice >> 8);
	usb_if->ucRevision = (uint8_t)(usb_if->usb_dev->descriptor.bcdDevice & 0xff);
#else
#error "Please fix the endianness defines in <asm/byteorder.h>"
#endif

	DPRINTK(KERN_DEBUG "%s(): ucHardcodedDevNr=0x%02x ucRevision=0x%02X\n", __func__, usb_if->ucHardcodedDevNr, usb_if->ucRevision);

	if ((err = pcan_usb_allocate_resources(usb_if)))
		goto reject;

	usb_set_intfdata(interface, usb_if);

   /* call initialisation callback for entire device */
	device_init(usb_if);

	/* install the reception part for the interface */
	if (!atomic_read(&usb_if->read_data.use_count))
	{
		FILL_BULK_URB(&usb_if->read_data, usb_if->usb_dev,
		              usb_rcvbulkpipe(usb_if->usb_dev, 
		                              usb_if->pipe_read.ucNumber),
		              usb_if->read_buffer_addr[0], usb_if->read_buffer_size, 
		              pcan_usb_read_notify, usb_if);

		// submit urb
		if ((err = __usb_submit_urb(&usb_if->read_data)))
		{
			printk(KERN_ERR "%s: %s() can't submit! (%d)\n", 
		          DEVICE_NAME, __FUNCTION__, err);
			goto reject;
		}

		atomic_inc(&usb_if->active_urbs);
	}

	/* next, initialize each controller */
	for (i=0; i < usb_if->dev_ctrl_count; i++)
	{
		err =	pcan_usb_create_dev(usb_if, i);
		if (err != 0)
		{
			for (; i > 0; i--)
			{
				// TBD pcan_usb_delete_dev();
			}
			break;
		}
	}

reject:
	return err;
}