summaryrefslogtreecommitdiff
path: root/target/linux/ramips/patches-3.10/0205-uvc-add-iPassion-iP2970-support.patch
blob: 5c5cf7f5968fc88e7f8c3393517c045805066bd1 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
From be8d5b55f93b8ccb3a6b5cfb1e858a59aeca2d6c Mon Sep 17 00:00:00 2001
From: John Crispin <blogic@openwrt.org>
Date: Thu, 19 Sep 2013 01:50:59 +0200
Subject: [PATCH] uvc: add iPassion iP2970 support

Signed-off-by: John Crispin <blogic@openwrt.org>
---
 drivers/media/usb/uvc/uvc_driver.c |   12 +++++++++
 drivers/media/usb/uvc/uvc_status.c |    2 ++
 drivers/media/usb/uvc/uvc_v4l2.c   |    1 +
 drivers/media/usb/uvc/uvc_video.c  |   50 +++++++++++++++++++++++++++++++-----
 drivers/media/usb/uvc/uvcvideo.h   |    3 +++
 5 files changed, 61 insertions(+), 7 deletions(-)

Index: linux-3.10.12/drivers/media/usb/uvc/uvc_driver.c
===================================================================
--- linux-3.10.12.orig/drivers/media/usb/uvc/uvc_driver.c	2013-09-14 15:55:12.000000000 +0200
+++ linux-3.10.12/drivers/media/usb/uvc/uvc_driver.c	2013-09-19 04:30:11.825592123 +0200
@@ -2420,6 +2420,20 @@
 	  .bInterfaceProtocol	= 0,
 	  .driver_info		= UVC_QUIRK_PROBE_MINMAX
 				| UVC_QUIRK_IGNORE_SELECTOR_UNIT },
+
+/* iPassion iP2970 */
+	{ .match_flags          = USB_DEVICE_ID_MATCH_DEVICE
+				| USB_DEVICE_ID_MATCH_INT_INFO,
+	 .idVendor		= 0x1B3B,
+	 .idProduct		= 0x2970,
+	 .bInterfaceClass	= USB_CLASS_VIDEO,
+	 .bInterfaceSubClass	= 1,
+	 .bInterfaceProtocol	= 0,
+	 .driver_info		= UVC_QUIRK_PROBE_MINMAX
+				| UVC_QUIRK_STREAM_NO_FID
+				| UVC_QUIRK_MOTION
+				| UVC_QUIRK_SINGLE_ISO },
+
 	/* Generic USB Video Class */
 	{ USB_INTERFACE_INFO(USB_CLASS_VIDEO, 1, 0) },
 	{}
Index: linux-3.10.12/drivers/media/usb/uvc/uvc_status.c
===================================================================
--- linux-3.10.12.orig/drivers/media/usb/uvc/uvc_status.c	2013-09-14 15:55:12.000000000 +0200
+++ linux-3.10.12/drivers/media/usb/uvc/uvc_status.c	2013-09-19 01:52:55.721188742 +0200
@@ -139,6 +139,7 @@
 		switch (dev->status[0] & 0x0f) {
 		case UVC_STATUS_TYPE_CONTROL:
 			uvc_event_control(dev, dev->status, len);
+			dev->motion = 1;
 			break;
 
 		case UVC_STATUS_TYPE_STREAMING:
@@ -182,6 +183,7 @@
 	}
 
 	pipe = usb_rcvintpipe(dev->udev, ep->desc.bEndpointAddress);
+	dev->motion = 0;
 
 	/* For high-speed interrupt endpoints, the bInterval value is used as
 	 * an exponent of two. Some developers forgot about it.
Index: linux-3.10.12/drivers/media/usb/uvc/uvc_video.c
===================================================================
--- linux-3.10.12.orig/drivers/media/usb/uvc/uvc_video.c	2013-09-14 15:55:12.000000000 +0200
+++ linux-3.10.12/drivers/media/usb/uvc/uvc_video.c	2013-09-19 07:31:28.642057093 +0200
@@ -21,6 +21,11 @@
 #include <linux/wait.h>
 #include <linux/atomic.h>
 #include <asm/unaligned.h>
+#include <linux/skbuff.h>
+#include <linux/kobject.h>
+#include <linux/netlink.h>
+#include <linux/kobject.h>
+#include <linux/workqueue.h>
 
 #include <media/v4l2-common.h>
 
@@ -1074,9 +1079,149 @@
 	}
 }
 
+struct bh_priv {
+	unsigned long	seen;
+};
+
+struct bh_event {
+	const char		*name;
+	struct sk_buff		*skb;
+	struct work_struct	work;
+};
+
+#define BH_ERR(fmt, args...) printk(KERN_ERR "%s: " fmt, "webcam", ##args )
+#define BH_DBG(fmt, args...) do {} while (0)
+#define BH_SKB_SIZE     2048
+
+extern u64 uevent_next_seqnum(void);
+static int seen = 0;
+
+static int bh_event_add_var(struct bh_event *event, int argv,
+		const char *format, ...)
+{
+	static char buf[128];
+	char *s;
+	va_list args;
+	int len;
+
+	if (argv)
+		return 0;
+
+	va_start(args, format);
+	len = vsnprintf(buf, sizeof(buf), format, args);
+	va_end(args);
+
+	if (len >= sizeof(buf)) {
+		BH_ERR("buffer size too small\n");
+		WARN_ON(1);
+		return -ENOMEM;
+	}
+
+	s = skb_put(event->skb, len + 1);
+	strcpy(s, buf);
+
+	BH_DBG("added variable '%s'\n", s);
+
+	return 0;
+}
+
+static int motion_hotplug_fill_event(struct bh_event *event)
+{
+	int s = jiffies;
+	int ret;
+
+	if (!seen)
+		seen = jiffies;
+
+	ret = bh_event_add_var(event, 0, "HOME=%s", "/");
+	if (ret)
+		return ret;
+
+	ret = bh_event_add_var(event, 0, "PATH=%s",
+		"/sbin:/bin:/usr/sbin:/usr/bin");
+	if (ret)
+		return ret;
+
+	ret = bh_event_add_var(event, 0, "SUBSYSTEM=usb");
+	if (ret)
+		return ret;
+
+	ret = bh_event_add_var(event, 0, "ACTION=motion");
+	if (ret)
+		return ret;
+
+	ret = bh_event_add_var(event, 0, "SEEN=%d", s - seen);
+	if (ret)
+		return ret;
+	seen = s;
+
+	ret = bh_event_add_var(event, 0, "SEQNUM=%llu", uevent_next_seqnum());
+
+	return ret;
+}
+
+static void motion_hotplug_work(struct work_struct *work)
+{
+	struct bh_event *event = container_of(work, struct bh_event, work);
+	int ret = 0;
+
+	event->skb = alloc_skb(BH_SKB_SIZE, GFP_KERNEL);
+	if (!event->skb)
+		goto out_free_event;
+
+	ret = bh_event_add_var(event, 0, "%s@", "add");
+	if (ret)
+		goto out_free_skb;
+
+	ret = motion_hotplug_fill_event(event);
+	if (ret)
+		goto out_free_skb;
+
+	NETLINK_CB(event->skb).dst_group = 1;
+	broadcast_uevent(event->skb, 0, 1, GFP_KERNEL);
+
+out_free_skb:
+	if (ret) {
+		BH_ERR("work error %d\n", ret);
+		kfree_skb(event->skb);
+	}
+out_free_event:
+	kfree(event);
+}
+
+static int motion_hotplug_create_event(void)
+{
+	struct bh_event *event;
+
+	event = kzalloc(sizeof(*event), GFP_KERNEL);
+	if (!event)
+		return -ENOMEM;
+
+	event->name = "motion";
+
+	INIT_WORK(&event->work, (void *)(void *)motion_hotplug_work);
+	schedule_work(&event->work);
+
+	return 0;
+}
+
+#define MOTION_FLAG_OFFSET	4
 static void uvc_video_decode_end(struct uvc_streaming *stream,
 		struct uvc_buffer *buf, const __u8 *data, int len)
 {
+	if ((stream->dev->quirks & UVC_QUIRK_MOTION) &&
+			(data[len - 2] == 0xff) && (data[len - 1] == 0xd9)) {
+		u8 *mem;
+		buf->state = UVC_BUF_STATE_READY;
+		mem = (u8 *) (buf->mem + MOTION_FLAG_OFFSET);
+		if ( stream->dev->motion ) {
+			stream->dev->motion = 0;
+			motion_hotplug_create_event();
+		} else {
+			*mem &= 0x7f;
+		}
+	}
+
 	/* Mark the buffer as done if the EOF marker is set. */
 	if (data[1] & UVC_STREAM_EOF && buf->bytesused != 0) {
 		uvc_trace(UVC_TRACE_FRAME, "Frame complete (EOF found).\n");
@@ -1477,6 +1622,8 @@
 	if (npackets == 0)
 		return -ENOMEM;
 
+	if (stream->dev->quirks & UVC_QUIRK_SINGLE_ISO)
+		npackets = 1;
 	size = npackets * psize;
 
 	for (i = 0; i < UVC_URBS; ++i) {
Index: linux-3.10.12/drivers/media/usb/uvc/uvcvideo.h
===================================================================
--- linux-3.10.12.orig/drivers/media/usb/uvc/uvcvideo.h	2013-09-14 15:55:12.000000000 +0200
+++ linux-3.10.12/drivers/media/usb/uvc/uvcvideo.h	2013-09-19 04:36:51.801609222 +0200
@@ -137,6 +137,8 @@
 #define UVC_QUIRK_FIX_BANDWIDTH		0x00000080
 #define UVC_QUIRK_PROBE_DEF		0x00000100
 #define UVC_QUIRK_RESTRICT_FRAME_RATE	0x00000200
+#define UVC_QUIRK_MOTION		0x00000400
+#define UVC_QUIRK_SINGLE_ISO		0x00000800
 
 /* Format flags */
 #define UVC_FMT_FLAG_COMPRESSED		0x00000001
@@ -538,6 +540,7 @@
 	__u8 *status;
 	struct input_dev *input;
 	char input_phys[64];
+	int motion;
 };
 
 enum uvc_handle_state {