1 From be8d5b55f93b8ccb3a6b5cfb1e858a59aeca2d6c Mon Sep 17 00:00:00 2001
2 From: John Crispin <blogic@openwrt.org>
3 Date: Thu, 19 Sep 2013 01:50:59 +0200
4 Subject: [PATCH] uvc: add iPassion iP2970 support
6 Signed-off-by: John Crispin <blogic@openwrt.org>
8 drivers/media/usb/uvc/uvc_driver.c | 12 +++++++++
9 drivers/media/usb/uvc/uvc_status.c | 2 ++
10 drivers/media/usb/uvc/uvc_v4l2.c | 1 +
11 drivers/media/usb/uvc/uvc_video.c | 50 +++++++++++++++++++++++++++++++-----
12 drivers/media/usb/uvc/uvcvideo.h | 3 +++
13 5 files changed, 61 insertions(+), 7 deletions(-)
15 Index: linux-3.10.12/drivers/media/usb/uvc/uvc_driver.c
16 ===================================================================
17 --- linux-3.10.12.orig/drivers/media/usb/uvc/uvc_driver.c 2013-09-14 15:55:12.000000000 +0200
18 +++ linux-3.10.12/drivers/media/usb/uvc/uvc_driver.c 2013-09-19 04:30:11.825592123 +0200
19 @@ -2420,6 +2420,20 @@
20 .bInterfaceProtocol = 0,
21 .driver_info = UVC_QUIRK_PROBE_MINMAX
22 | UVC_QUIRK_IGNORE_SELECTOR_UNIT },
24 +/* iPassion iP2970 */
25 + { .match_flags = USB_DEVICE_ID_MATCH_DEVICE
26 + | USB_DEVICE_ID_MATCH_INT_INFO,
28 + .idProduct = 0x2970,
29 + .bInterfaceClass = USB_CLASS_VIDEO,
30 + .bInterfaceSubClass = 1,
31 + .bInterfaceProtocol = 0,
32 + .driver_info = UVC_QUIRK_PROBE_MINMAX
33 + | UVC_QUIRK_STREAM_NO_FID
35 + | UVC_QUIRK_SINGLE_ISO },
37 /* Generic USB Video Class */
38 { USB_INTERFACE_INFO(USB_CLASS_VIDEO, 1, 0) },
40 Index: linux-3.10.12/drivers/media/usb/uvc/uvc_status.c
41 ===================================================================
42 --- linux-3.10.12.orig/drivers/media/usb/uvc/uvc_status.c 2013-09-14 15:55:12.000000000 +0200
43 +++ linux-3.10.12/drivers/media/usb/uvc/uvc_status.c 2013-09-19 01:52:55.721188742 +0200
45 switch (dev->status[0] & 0x0f) {
46 case UVC_STATUS_TYPE_CONTROL:
47 uvc_event_control(dev, dev->status, len);
51 case UVC_STATUS_TYPE_STREAMING:
55 pipe = usb_rcvintpipe(dev->udev, ep->desc.bEndpointAddress);
58 /* For high-speed interrupt endpoints, the bInterval value is used as
59 * an exponent of two. Some developers forgot about it.
60 Index: linux-3.10.12/drivers/media/usb/uvc/uvc_video.c
61 ===================================================================
62 --- linux-3.10.12.orig/drivers/media/usb/uvc/uvc_video.c 2013-09-14 15:55:12.000000000 +0200
63 +++ linux-3.10.12/drivers/media/usb/uvc/uvc_video.c 2013-09-19 07:31:28.642057093 +0200
65 #include <linux/wait.h>
66 #include <linux/atomic.h>
67 #include <asm/unaligned.h>
68 +#include <linux/skbuff.h>
69 +#include <linux/kobject.h>
70 +#include <linux/netlink.h>
71 +#include <linux/kobject.h>
72 +#include <linux/workqueue.h>
74 #include <media/v4l2-common.h>
76 @@ -1074,9 +1079,149 @@
86 + struct sk_buff *skb;
87 + struct work_struct work;
90 +#define BH_ERR(fmt, args...) printk(KERN_ERR "%s: " fmt, "webcam", ##args )
91 +#define BH_DBG(fmt, args...) do {} while (0)
92 +#define BH_SKB_SIZE 2048
94 +extern u64 uevent_next_seqnum(void);
97 +static int bh_event_add_var(struct bh_event *event, int argv,
98 + const char *format, ...)
100 + static char buf[128];
108 + va_start(args, format);
109 + len = vsnprintf(buf, sizeof(buf), format, args);
112 + if (len >= sizeof(buf)) {
113 + BH_ERR("buffer size too small\n");
118 + s = skb_put(event->skb, len + 1);
121 + BH_DBG("added variable '%s'\n", s);
126 +static int motion_hotplug_fill_event(struct bh_event *event)
134 + ret = bh_event_add_var(event, 0, "HOME=%s", "/");
138 + ret = bh_event_add_var(event, 0, "PATH=%s",
139 + "/sbin:/bin:/usr/sbin:/usr/bin");
143 + ret = bh_event_add_var(event, 0, "SUBSYSTEM=usb");
147 + ret = bh_event_add_var(event, 0, "ACTION=motion");
151 + ret = bh_event_add_var(event, 0, "SEEN=%d", s - seen);
156 + ret = bh_event_add_var(event, 0, "SEQNUM=%llu", uevent_next_seqnum());
161 +static void motion_hotplug_work(struct work_struct *work)
163 + struct bh_event *event = container_of(work, struct bh_event, work);
166 + event->skb = alloc_skb(BH_SKB_SIZE, GFP_KERNEL);
168 + goto out_free_event;
170 + ret = bh_event_add_var(event, 0, "%s@", "add");
174 + ret = motion_hotplug_fill_event(event);
178 + NETLINK_CB(event->skb).dst_group = 1;
179 + broadcast_uevent(event->skb, 0, 1, GFP_KERNEL);
183 + BH_ERR("work error %d\n", ret);
184 + kfree_skb(event->skb);
190 +static int motion_hotplug_create_event(void)
192 + struct bh_event *event;
194 + event = kzalloc(sizeof(*event), GFP_KERNEL);
198 + event->name = "motion";
200 + INIT_WORK(&event->work, (void *)(void *)motion_hotplug_work);
201 + schedule_work(&event->work);
206 +#define MOTION_FLAG_OFFSET 4
207 static void uvc_video_decode_end(struct uvc_streaming *stream,
208 struct uvc_buffer *buf, const __u8 *data, int len)
210 + if ((stream->dev->quirks & UVC_QUIRK_MOTION) &&
211 + (data[len - 2] == 0xff) && (data[len - 1] == 0xd9)) {
213 + buf->state = UVC_BUF_STATE_READY;
214 + mem = (u8 *) (buf->mem + MOTION_FLAG_OFFSET);
215 + if ( stream->dev->motion ) {
216 + stream->dev->motion = 0;
217 + motion_hotplug_create_event();
223 /* Mark the buffer as done if the EOF marker is set. */
224 if (data[1] & UVC_STREAM_EOF && buf->bytesused != 0) {
225 uvc_trace(UVC_TRACE_FRAME, "Frame complete (EOF found).\n");
226 @@ -1477,6 +1622,8 @@
230 + if (stream->dev->quirks & UVC_QUIRK_SINGLE_ISO)
232 size = npackets * psize;
234 for (i = 0; i < UVC_URBS; ++i) {
235 Index: linux-3.10.12/drivers/media/usb/uvc/uvcvideo.h
236 ===================================================================
237 --- linux-3.10.12.orig/drivers/media/usb/uvc/uvcvideo.h 2013-09-14 15:55:12.000000000 +0200
238 +++ linux-3.10.12/drivers/media/usb/uvc/uvcvideo.h 2013-09-19 04:36:51.801609222 +0200
240 #define UVC_QUIRK_FIX_BANDWIDTH 0x00000080
241 #define UVC_QUIRK_PROBE_DEF 0x00000100
242 #define UVC_QUIRK_RESTRICT_FRAME_RATE 0x00000200
243 +#define UVC_QUIRK_MOTION 0x00000400
244 +#define UVC_QUIRK_SINGLE_ISO 0x00000800
247 #define UVC_FMT_FLAG_COMPRESSED 0x00000001
250 struct input_dev *input;
255 enum uvc_handle_state {