static int ar9170_usb_init_device(struct ar9170_usb *aru)
{
	int err;

	err = ar9170_usb_alloc_rx_irq_urb(aru);
	if (err)
		goto err_out;

	err = ar9170_usb_alloc_rx_bulk_urbs(aru);
	if (err)
		goto err_unrx;

	err = ar9170_usb_upload_firmware(aru);
	if (err) {
		err = ar9170_echo_test(&aru->common, 0x60d43110);
		if (err) {
			/* force user invention, by disabling the device */
			err = usb_driver_set_configuration(aru->udev, -1);
			dev_err(&aru->udev->dev, "device is in a bad state. "
						 "please reconnect it!\n");
			goto err_unrx;
		}
	}

	return 0;

err_unrx:
	ar9170_usb_cancel_urbs(aru);

err_out:
	return err;
}
Beispiel #2
0
static int magic_charge(struct usb_device *udev)
{
    char *dummy_buffer = kzalloc(2, GFP_KERNEL);
    int retval;

    if (!dummy_buffer)
        return -ENOMEM;

    /* send two magic commands and then set the configuration.  The device
     * will then reset itself with the new power usage and should start
     * charging. */

    /* Note, with testing, it only seems that the first message is really
     * needed (at least for the 8700c), but to be safe, we emulate what
     * other operating systems seem to be sending to their device.  We
     * really need to get some specs for this device to be sure about what
     * is going on here.
     */
    dbg(&udev->dev, "Sending first magic command\n");
    retval = usb_control_msg(udev, usb_rcvctrlpipe(udev, 0),
                 0xa5, 0xc0, 0, 1, dummy_buffer, 2, 100);
    if (retval != 2) {
        dev_err(&udev->dev, "First magic command failed: %d.\n",
            retval);
        goto exit;
    }

    dbg(&udev->dev, "Sending second magic command\n");
    retval = usb_control_msg(udev, usb_rcvctrlpipe(udev, 0),
                 0xa2, 0x40, 0, 1, dummy_buffer, 0, 100);
    if (retval != 0) {
        dev_err(&udev->dev, "Second magic command failed: %d.\n",
            retval);
        goto exit;
    }

    dbg(&udev->dev, "Calling set_configuration\n");
    retval = usb_driver_set_configuration(udev, 1);
    if (retval)
        dev_err(&udev->dev, "Set Configuration failed :%d.\n", retval);

exit:
    kfree(dummy_buffer);
    return retval;
}
Beispiel #3
0
static int magic_dual_mode(struct usb_device *udev)
{
    char *dummy_buffer = kzalloc(2, GFP_KERNEL);
    int retval;

    if (!dummy_buffer)
        return -ENOMEM;

    /* send magic command so that the Blackberry Pearl device exposes
     * two interfaces: both the USB mass-storage one and one which can
     * be used for database access. */
    dbg(&udev->dev, "Sending magic pearl command\n");
    retval = usb_control_msg(udev, usb_rcvctrlpipe(udev, 0),
                 0xa9, 0xc0, 1, 1, dummy_buffer, 2, 100);
    dbg(&udev->dev, "Magic pearl command returned %d\n", retval);

    dbg(&udev->dev, "Calling set_configuration\n");
    retval = usb_driver_set_configuration(udev, 1);
    if (retval)
        dev_err(&udev->dev, "Set Configuration failed :%d.\n", retval);

    kfree(dummy_buffer);
    return retval;
}