init from v2.6.32.60
[mach-moxart.git] / drivers / usb / misc / isight_firmware.c
blob6199f12d01414a5661018cc4e7c97b5a4a4d5742
1 /*
2 * Driver for loading USB isight firmware
4 * Copyright (C) 2008 Matthew Garrett <mjg@redhat.com>
6 * This program is free software; you can redistribute it and/or modify it
7 * under the terms of the GNU General Public License as published by the Free
8 * Software Foundation, version 2.
10 * The USB isight cameras in recent Apples are roughly compatible with the USB
11 * video class specification, and can be driven by uvcvideo. However, they
12 * need firmware to be loaded beforehand. After firmware loading, the device
13 * detaches from the USB bus and reattaches with a new device ID. It can then
14 * be claimed by the uvc driver.
16 * The firmware is non-free and must be extracted by the user. Tools to do this
17 * are available at http://bersace03.free.fr/ift/
19 * The isight firmware loading was reverse engineered by Johannes Berg
20 * <johannes@sipsolutions.de>, and this driver is based on code by Ronald
21 * Bultje <rbultje@ronald.bitfreak.net>
24 #include <linux/usb.h>
25 #include <linux/firmware.h>
26 #include <linux/errno.h>
27 #include <linux/module.h>
29 static struct usb_device_id id_table[] = {
30 {USB_DEVICE(0x05ac, 0x8300)},
31 {},
34 MODULE_DEVICE_TABLE(usb, id_table);
36 static int isight_firmware_load(struct usb_interface *intf,
37 const struct usb_device_id *id)
39 struct usb_device *dev = interface_to_usbdev(intf);
40 int llen, len, req, ret = 0;
41 const struct firmware *firmware;
42 unsigned char *buf = kmalloc(50, GFP_KERNEL);
43 unsigned char data[4];
44 const u8 *ptr;
46 if (!buf)
47 return -ENOMEM;
49 if (request_firmware(&firmware, "isight.fw", &dev->dev) != 0) {
50 printk(KERN_ERR "Unable to load isight firmware\n");
51 ret = -ENODEV;
52 goto out;
55 ptr = firmware->data;
57 buf[0] = 0x01;
58 if (usb_control_msg
59 (dev, usb_sndctrlpipe(dev, 0), 0xa0, 0x40, 0xe600, 0, buf, 1,
60 300) != 1) {
61 printk(KERN_ERR
62 "Failed to initialise isight firmware loader\n");
63 ret = -ENODEV;
64 goto out;
67 while (ptr+4 <= firmware->data+firmware->size) {
68 memcpy(data, ptr, 4);
69 len = (data[0] << 8 | data[1]);
70 req = (data[2] << 8 | data[3]);
71 ptr += 4;
73 if (len == 0x8001)
74 break; /* success */
75 else if (len == 0)
76 continue;
78 for (; len > 0; req += 50) {
79 llen = min(len, 50);
80 len -= llen;
81 if (ptr+llen > firmware->data+firmware->size) {
82 printk(KERN_ERR
83 "Malformed isight firmware");
84 ret = -ENODEV;
85 goto out;
87 memcpy(buf, ptr, llen);
89 ptr += llen;
91 if (usb_control_msg
92 (dev, usb_sndctrlpipe(dev, 0), 0xa0, 0x40, req, 0,
93 buf, llen, 300) != llen) {
94 printk(KERN_ERR
95 "Failed to load isight firmware\n");
96 ret = -ENODEV;
97 goto out;
103 buf[0] = 0x00;
104 if (usb_control_msg
105 (dev, usb_sndctrlpipe(dev, 0), 0xa0, 0x40, 0xe600, 0, buf, 1,
106 300) != 1) {
107 printk(KERN_ERR "isight firmware loading completion failed\n");
108 ret = -ENODEV;
111 out:
112 kfree(buf);
113 release_firmware(firmware);
114 return ret;
117 static void isight_firmware_disconnect(struct usb_interface *intf)
121 static struct usb_driver isight_firmware_driver = {
122 .name = "isight_firmware",
123 .probe = isight_firmware_load,
124 .disconnect = isight_firmware_disconnect,
125 .id_table = id_table,
128 static int __init isight_firmware_init(void)
130 return usb_register(&isight_firmware_driver);
133 static void __exit isight_firmware_exit(void)
135 usb_deregister(&isight_firmware_driver);
138 module_init(isight_firmware_init);
139 module_exit(isight_firmware_exit);
141 MODULE_LICENSE("GPL");
142 MODULE_AUTHOR("Matthew Garrett <mjg@redhat.com>");