ralink: make dcs930 uvc camera work
[openwrt/openwrt.git] / target / linux / ramips / patches-3.10 / 0205-uvc-add-iPassion-iP2970-support.patch
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
5
6 Signed-off-by: John Crispin <blogic@openwrt.org>
7 ---
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(-)
14
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 },
23 +
24 +/* iPassion iP2970 */
25 + { .match_flags = USB_DEVICE_ID_MATCH_DEVICE
26 + | USB_DEVICE_ID_MATCH_INT_INFO,
27 + .idVendor = 0x1B3B,
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
34 + | UVC_QUIRK_MOTION
35 + | UVC_QUIRK_SINGLE_ISO },
36 +
37 /* Generic USB Video Class */
38 { USB_INTERFACE_INFO(USB_CLASS_VIDEO, 1, 0) },
39 {}
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
44 @@ -139,6 +139,7 @@
45 switch (dev->status[0] & 0x0f) {
46 case UVC_STATUS_TYPE_CONTROL:
47 uvc_event_control(dev, dev->status, len);
48 + dev->motion = 1;
49 break;
50
51 case UVC_STATUS_TYPE_STREAMING:
52 @@ -182,6 +183,7 @@
53 }
54
55 pipe = usb_rcvintpipe(dev->udev, ep->desc.bEndpointAddress);
56 + dev->motion = 0;
57
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
64 @@ -21,6 +21,11 @@
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>
73
74 #include <media/v4l2-common.h>
75
76 @@ -1074,9 +1079,149 @@
77 }
78 }
79
80 +struct bh_priv {
81 + unsigned long seen;
82 +};
83 +
84 +struct bh_event {
85 + const char *name;
86 + struct sk_buff *skb;
87 + struct work_struct work;
88 +};
89 +
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
93 +
94 +extern u64 uevent_next_seqnum(void);
95 +static int seen = 0;
96 +
97 +static int bh_event_add_var(struct bh_event *event, int argv,
98 + const char *format, ...)
99 +{
100 + static char buf[128];
101 + char *s;
102 + va_list args;
103 + int len;
104 +
105 + if (argv)
106 + return 0;
107 +
108 + va_start(args, format);
109 + len = vsnprintf(buf, sizeof(buf), format, args);
110 + va_end(args);
111 +
112 + if (len >= sizeof(buf)) {
113 + BH_ERR("buffer size too small\n");
114 + WARN_ON(1);
115 + return -ENOMEM;
116 + }
117 +
118 + s = skb_put(event->skb, len + 1);
119 + strcpy(s, buf);
120 +
121 + BH_DBG("added variable '%s'\n", s);
122 +
123 + return 0;
124 +}
125 +
126 +static int motion_hotplug_fill_event(struct bh_event *event)
127 +{
128 + int s = jiffies;
129 + int ret;
130 +
131 + if (!seen)
132 + seen = jiffies;
133 +
134 + ret = bh_event_add_var(event, 0, "HOME=%s", "/");
135 + if (ret)
136 + return ret;
137 +
138 + ret = bh_event_add_var(event, 0, "PATH=%s",
139 + "/sbin:/bin:/usr/sbin:/usr/bin");
140 + if (ret)
141 + return ret;
142 +
143 + ret = bh_event_add_var(event, 0, "SUBSYSTEM=usb");
144 + if (ret)
145 + return ret;
146 +
147 + ret = bh_event_add_var(event, 0, "ACTION=motion");
148 + if (ret)
149 + return ret;
150 +
151 + ret = bh_event_add_var(event, 0, "SEEN=%d", s - seen);
152 + if (ret)
153 + return ret;
154 + seen = s;
155 +
156 + ret = bh_event_add_var(event, 0, "SEQNUM=%llu", uevent_next_seqnum());
157 +
158 + return ret;
159 +}
160 +
161 +static void motion_hotplug_work(struct work_struct *work)
162 +{
163 + struct bh_event *event = container_of(work, struct bh_event, work);
164 + int ret = 0;
165 +
166 + event->skb = alloc_skb(BH_SKB_SIZE, GFP_KERNEL);
167 + if (!event->skb)
168 + goto out_free_event;
169 +
170 + ret = bh_event_add_var(event, 0, "%s@", "add");
171 + if (ret)
172 + goto out_free_skb;
173 +
174 + ret = motion_hotplug_fill_event(event);
175 + if (ret)
176 + goto out_free_skb;
177 +
178 + NETLINK_CB(event->skb).dst_group = 1;
179 + broadcast_uevent(event->skb, 0, 1, GFP_KERNEL);
180 +
181 +out_free_skb:
182 + if (ret) {
183 + BH_ERR("work error %d\n", ret);
184 + kfree_skb(event->skb);
185 + }
186 +out_free_event:
187 + kfree(event);
188 +}
189 +
190 +static int motion_hotplug_create_event(void)
191 +{
192 + struct bh_event *event;
193 +
194 + event = kzalloc(sizeof(*event), GFP_KERNEL);
195 + if (!event)
196 + return -ENOMEM;
197 +
198 + event->name = "motion";
199 +
200 + INIT_WORK(&event->work, (void *)(void *)motion_hotplug_work);
201 + schedule_work(&event->work);
202 +
203 + return 0;
204 +}
205 +
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)
209 {
210 + if ((stream->dev->quirks & UVC_QUIRK_MOTION) &&
211 + (data[len - 2] == 0xff) && (data[len - 1] == 0xd9)) {
212 + u8 *mem;
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();
218 + } else {
219 + *mem &= 0x7f;
220 + }
221 + }
222 +
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 @@
227 if (npackets == 0)
228 return -ENOMEM;
229
230 + if (stream->dev->quirks & UVC_QUIRK_SINGLE_ISO)
231 + npackets = 1;
232 size = npackets * psize;
233
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
239 @@ -137,6 +137,8 @@
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
245
246 /* Format flags */
247 #define UVC_FMT_FLAG_COMPRESSED 0x00000001
248 @@ -538,6 +540,7 @@
249 __u8 *status;
250 struct input_dev *input;
251 char input_phys[64];
252 + int motion;
253 };
254
255 enum uvc_handle_state {