Linux Audio

Check our new training course

Loading...
v5.9
  1// SPDX-License-Identifier: GPL-2.0
  2/*
  3 * Driver for loading USB isight firmware
  4 *
  5 * Copyright (C) 2008 Matthew Garrett <mjg@redhat.com>
  6 *
 
 
 
 
  7 * The USB isight cameras in recent Apples are roughly compatible with the USB
  8 * video class specification, and can be driven by uvcvideo. However, they
  9 * need firmware to be loaded beforehand. After firmware loading, the device
 10 * detaches from the USB bus and reattaches with a new device ID. It can then
 11 * be claimed by the uvc driver.
 12 *
 13 * The firmware is non-free and must be extracted by the user. Tools to do this
 14 * are available at http://bersace03.free.fr/ift/
 15 *
 16 * The isight firmware loading was reverse engineered by Johannes Berg
 17 * <johannes@sipsolutions.de>, and this driver is based on code by Ronald
 18 * Bultje <rbultje@ronald.bitfreak.net>
 19 */
 20
 21#include <linux/usb.h>
 22#include <linux/firmware.h>
 23#include <linux/errno.h>
 24#include <linux/module.h>
 25#include <linux/slab.h>
 26
 27static const struct usb_device_id id_table[] = {
 28	{USB_DEVICE(0x05ac, 0x8300)},
 29	{},
 30};
 31
 32MODULE_DEVICE_TABLE(usb, id_table);
 33
 34static int isight_firmware_load(struct usb_interface *intf,
 35				const struct usb_device_id *id)
 36{
 37	struct usb_device *dev = interface_to_usbdev(intf);
 38	int llen, len, req, ret = 0;
 39	const struct firmware *firmware;
 40	unsigned char *buf = kmalloc(50, GFP_KERNEL);
 41	unsigned char data[4];
 42	const u8 *ptr;
 43
 44	if (!buf)
 45		return -ENOMEM;
 46
 47	if (request_firmware(&firmware, "isight.fw", &dev->dev) != 0) {
 48		printk(KERN_ERR "Unable to load isight firmware\n");
 49		ret = -ENODEV;
 50		goto out;
 51	}
 52
 53	ptr = firmware->data;
 54
 55	buf[0] = 0x01;
 56	if (usb_control_msg
 57	    (dev, usb_sndctrlpipe(dev, 0), 0xa0, 0x40, 0xe600, 0, buf, 1,
 58	     300) != 1) {
 59		printk(KERN_ERR
 60		       "Failed to initialise isight firmware loader\n");
 61		ret = -ENODEV;
 62		goto out;
 63	}
 64
 65	while (ptr+4 <= firmware->data+firmware->size) {
 66		memcpy(data, ptr, 4);
 67		len = (data[0] << 8 | data[1]);
 68		req = (data[2] << 8 | data[3]);
 69		ptr += 4;
 70
 71		if (len == 0x8001)
 72			break;	/* success */
 73		else if (len == 0)
 74			continue;
 75
 76		for (; len > 0; req += 50) {
 77			llen = min(len, 50);
 78			len -= llen;
 79			if (ptr+llen > firmware->data+firmware->size) {
 80				printk(KERN_ERR
 81				       "Malformed isight firmware");
 82				ret = -ENODEV;
 83				goto out;
 84			}
 85			memcpy(buf, ptr, llen);
 86
 87			ptr += llen;
 88
 89			if (usb_control_msg
 90			    (dev, usb_sndctrlpipe(dev, 0), 0xa0, 0x40, req, 0,
 91			     buf, llen, 300) != llen) {
 92				printk(KERN_ERR
 93				       "Failed to load isight firmware\n");
 94				ret = -ENODEV;
 95				goto out;
 96			}
 97
 98		}
 99	}
100
101	buf[0] = 0x00;
102	if (usb_control_msg
103	    (dev, usb_sndctrlpipe(dev, 0), 0xa0, 0x40, 0xe600, 0, buf, 1,
104	     300) != 1) {
105		printk(KERN_ERR "isight firmware loading completion failed\n");
106		ret = -ENODEV;
107	}
108
109out:
110	kfree(buf);
111	release_firmware(firmware);
112	return ret;
113}
114
115MODULE_FIRMWARE("isight.fw");
116
117static void isight_firmware_disconnect(struct usb_interface *intf)
118{
119}
120
121static 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,
126};
127
128module_usb_driver(isight_firmware_driver);
 
 
 
 
 
 
 
 
 
 
 
129
130MODULE_LICENSE("GPL");
131MODULE_AUTHOR("Matthew Garrett <mjg@redhat.com>");
v3.1
 
  1/*
  2 * Driver for loading USB isight firmware
  3 *
  4 * Copyright (C) 2008 Matthew Garrett <mjg@redhat.com>
  5 *
  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.
  9 *
 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.
 15 *
 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/
 18 *
 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>
 22 */
 23
 24#include <linux/usb.h>
 25#include <linux/firmware.h>
 26#include <linux/errno.h>
 27#include <linux/module.h>
 28#include <linux/slab.h>
 29
 30static const struct usb_device_id id_table[] = {
 31	{USB_DEVICE(0x05ac, 0x8300)},
 32	{},
 33};
 34
 35MODULE_DEVICE_TABLE(usb, id_table);
 36
 37static int isight_firmware_load(struct usb_interface *intf,
 38				const struct usb_device_id *id)
 39{
 40	struct usb_device *dev = interface_to_usbdev(intf);
 41	int llen, len, req, ret = 0;
 42	const struct firmware *firmware;
 43	unsigned char *buf = kmalloc(50, GFP_KERNEL);
 44	unsigned char data[4];
 45	const u8 *ptr;
 46
 47	if (!buf)
 48		return -ENOMEM;
 49
 50	if (request_firmware(&firmware, "isight.fw", &dev->dev) != 0) {
 51		printk(KERN_ERR "Unable to load isight firmware\n");
 52		ret = -ENODEV;
 53		goto out;
 54	}
 55
 56	ptr = firmware->data;
 57
 
 58	if (usb_control_msg
 59	    (dev, usb_sndctrlpipe(dev, 0), 0xa0, 0x40, 0xe600, 0, "\1", 1,
 60	     300) != 1) {
 61		printk(KERN_ERR
 62		       "Failed to initialise isight firmware loader\n");
 63		ret = -ENODEV;
 64		goto out;
 65	}
 66
 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;
 72
 73		if (len == 0x8001)
 74			break;	/* success */
 75		else if (len == 0)
 76			continue;
 77
 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;
 86			}
 87			memcpy(buf, ptr, llen);
 88
 89			ptr += llen;
 90
 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;
 98			}
 99
100		}
101	}
102
 
103	if (usb_control_msg
104	    (dev, usb_sndctrlpipe(dev, 0), 0xa0, 0x40, 0xe600, 0, "\0", 1,
105	     300) != 1) {
106		printk(KERN_ERR "isight firmware loading completion failed\n");
107		ret = -ENODEV;
108	}
109
110out:
111	kfree(buf);
112	release_firmware(firmware);
113	return ret;
114}
115
116MODULE_FIRMWARE("isight.fw");
117
118static void isight_firmware_disconnect(struct usb_interface *intf)
119{
120}
121
122static struct usb_driver isight_firmware_driver = {
123	.name = "isight_firmware",
124	.probe = isight_firmware_load,
125	.disconnect = isight_firmware_disconnect,
126	.id_table = id_table,
127};
128
129static int __init isight_firmware_init(void)
130{
131	return usb_register(&isight_firmware_driver);
132}
133
134static void __exit isight_firmware_exit(void)
135{
136	usb_deregister(&isight_firmware_driver);
137}
138
139module_init(isight_firmware_init);
140module_exit(isight_firmware_exit);
141
142MODULE_LICENSE("GPL");
143MODULE_AUTHOR("Matthew Garrett <mjg@redhat.com>");