89e46b904d965c445ea267bc2a0ce64fe39a447b
[openwrt/staging/chunkeey.git] / target / linux / ramips / patches-3.14 / 0057-uvc-add-iPassion-iP2970-support.patch
1 From 0d3e92b4d3e2160873b610aabd46bbc4853ff82e 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 57/57] uvc: add iPassion iP2970 support
5
6 Signed-off-by: John Crispin <blogic@openwrt.org>
7 ---
8 drivers/media/usb/uvc/uvc_driver.c | 14 ++++
9 drivers/media/usb/uvc/uvc_status.c | 2 +
10 drivers/media/usb/uvc/uvc_video.c | 147 ++++++++++++++++++++++++++++++++++++
11 drivers/media/usb/uvc/uvcvideo.h | 3 +
12 4 files changed, 166 insertions(+)
13
14 diff --git a/drivers/media/usb/uvc/uvc_driver.c b/drivers/media/usb/uvc/uvc_driver.c
15 index c3bb250..c6612d4 100644
16 --- a/drivers/media/usb/uvc/uvc_driver.c
17 +++ b/drivers/media/usb/uvc/uvc_driver.c
18 @@ -2467,6 +2467,20 @@ static struct usb_device_id uvc_ids[] = {
19 .bInterfaceProtocol = 0,
20 .driver_info = UVC_QUIRK_PROBE_MINMAX
21 | UVC_QUIRK_IGNORE_SELECTOR_UNIT },
22 +
23 +/* iPassion iP2970 */
24 + { .match_flags = USB_DEVICE_ID_MATCH_DEVICE
25 + | USB_DEVICE_ID_MATCH_INT_INFO,
26 + .idVendor = 0x1B3B,
27 + .idProduct = 0x2970,
28 + .bInterfaceClass = USB_CLASS_VIDEO,
29 + .bInterfaceSubClass = 1,
30 + .bInterfaceProtocol = 0,
31 + .driver_info = UVC_QUIRK_PROBE_MINMAX
32 + | UVC_QUIRK_STREAM_NO_FID
33 + | UVC_QUIRK_MOTION
34 + | UVC_QUIRK_SINGLE_ISO },
35 +
36 /* Generic USB Video Class */
37 { USB_INTERFACE_INFO(USB_CLASS_VIDEO, 1, 0) },
38 {}
39 diff --git a/drivers/media/usb/uvc/uvc_status.c b/drivers/media/usb/uvc/uvc_status.c
40 index f552ab9..7132ad4 100644
41 --- a/drivers/media/usb/uvc/uvc_status.c
42 +++ b/drivers/media/usb/uvc/uvc_status.c
43 @@ -139,6 +139,7 @@ static void uvc_status_complete(struct urb *urb)
44 switch (dev->status[0] & 0x0f) {
45 case UVC_STATUS_TYPE_CONTROL:
46 uvc_event_control(dev, dev->status, len);
47 + dev->motion = 1;
48 break;
49
50 case UVC_STATUS_TYPE_STREAMING:
51 @@ -182,6 +183,7 @@ int uvc_status_init(struct uvc_device *dev)
52 }
53
54 pipe = usb_rcvintpipe(dev->udev, ep->desc.bEndpointAddress);
55 + dev->motion = 0;
56
57 /* For high-speed interrupt endpoints, the bInterval value is used as
58 * an exponent of two. Some developers forgot about it.
59 diff --git a/drivers/media/usb/uvc/uvc_video.c b/drivers/media/usb/uvc/uvc_video.c
60 index 898c208..2e06163 100644
61 --- a/drivers/media/usb/uvc/uvc_video.c
62 +++ b/drivers/media/usb/uvc/uvc_video.c
63 @@ -21,6 +21,11 @@
64 #include <linux/wait.h>
65 #include <linux/atomic.h>
66 #include <asm/unaligned.h>
67 +#include <linux/skbuff.h>
68 +#include <linux/kobject.h>
69 +#include <linux/netlink.h>
70 +#include <linux/kobject.h>
71 +#include <linux/workqueue.h>
72
73 #include <media/v4l2-common.h>
74
75 @@ -1075,9 +1080,149 @@ static void uvc_video_decode_data(struct uvc_streaming *stream,
76 }
77 }
78
79 +struct bh_priv {
80 + unsigned long seen;
81 +};
82 +
83 +struct bh_event {
84 + const char *name;
85 + struct sk_buff *skb;
86 + struct work_struct work;
87 +};
88 +
89 +#define BH_ERR(fmt, args...) printk(KERN_ERR "%s: " fmt, "webcam", ##args )
90 +#define BH_DBG(fmt, args...) do {} while (0)
91 +#define BH_SKB_SIZE 2048
92 +
93 +extern u64 uevent_next_seqnum(void);
94 +static int seen = 0;
95 +
96 +static int bh_event_add_var(struct bh_event *event, int argv,
97 + const char *format, ...)
98 +{
99 + static char buf[128];
100 + char *s;
101 + va_list args;
102 + int len;
103 +
104 + if (argv)
105 + return 0;
106 +
107 + va_start(args, format);
108 + len = vsnprintf(buf, sizeof(buf), format, args);
109 + va_end(args);
110 +
111 + if (len >= sizeof(buf)) {
112 + BH_ERR("buffer size too small\n");
113 + WARN_ON(1);
114 + return -ENOMEM;
115 + }
116 +
117 + s = skb_put(event->skb, len + 1);
118 + strcpy(s, buf);
119 +
120 + BH_DBG("added variable '%s'\n", s);
121 +
122 + return 0;
123 +}
124 +
125 +static int motion_hotplug_fill_event(struct bh_event *event)
126 +{
127 + int s = jiffies;
128 + int ret;
129 +
130 + if (!seen)
131 + seen = jiffies;
132 +
133 + ret = bh_event_add_var(event, 0, "HOME=%s", "/");
134 + if (ret)
135 + return ret;
136 +
137 + ret = bh_event_add_var(event, 0, "PATH=%s",
138 + "/sbin:/bin:/usr/sbin:/usr/bin");
139 + if (ret)
140 + return ret;
141 +
142 + ret = bh_event_add_var(event, 0, "SUBSYSTEM=usb");
143 + if (ret)
144 + return ret;
145 +
146 + ret = bh_event_add_var(event, 0, "ACTION=motion");
147 + if (ret)
148 + return ret;
149 +
150 + ret = bh_event_add_var(event, 0, "SEEN=%d", s - seen);
151 + if (ret)
152 + return ret;
153 + seen = s;
154 +
155 + ret = bh_event_add_var(event, 0, "SEQNUM=%llu", uevent_next_seqnum());
156 +
157 + return ret;
158 +}
159 +
160 +static void motion_hotplug_work(struct work_struct *work)
161 +{
162 + struct bh_event *event = container_of(work, struct bh_event, work);
163 + int ret = 0;
164 +
165 + event->skb = alloc_skb(BH_SKB_SIZE, GFP_KERNEL);
166 + if (!event->skb)
167 + goto out_free_event;
168 +
169 + ret = bh_event_add_var(event, 0, "%s@", "add");
170 + if (ret)
171 + goto out_free_skb;
172 +
173 + ret = motion_hotplug_fill_event(event);
174 + if (ret)
175 + goto out_free_skb;
176 +
177 + NETLINK_CB(event->skb).dst_group = 1;
178 + broadcast_uevent(event->skb, 0, 1, GFP_KERNEL);
179 +
180 +out_free_skb:
181 + if (ret) {
182 + BH_ERR("work error %d\n", ret);
183 + kfree_skb(event->skb);
184 + }
185 +out_free_event:
186 + kfree(event);
187 +}
188 +
189 +static int motion_hotplug_create_event(void)
190 +{
191 + struct bh_event *event;
192 +
193 + event = kzalloc(sizeof(*event), GFP_KERNEL);
194 + if (!event)
195 + return -ENOMEM;
196 +
197 + event->name = "motion";
198 +
199 + INIT_WORK(&event->work, (void *)(void *)motion_hotplug_work);
200 + schedule_work(&event->work);
201 +
202 + return 0;
203 +}
204 +
205 +#define MOTION_FLAG_OFFSET 4
206 static void uvc_video_decode_end(struct uvc_streaming *stream,
207 struct uvc_buffer *buf, const __u8 *data, int len)
208 {
209 + if ((stream->dev->quirks & UVC_QUIRK_MOTION) &&
210 + (data[len - 2] == 0xff) && (data[len - 1] == 0xd9)) {
211 + u8 *mem;
212 + buf->state = UVC_BUF_STATE_READY;
213 + mem = (u8 *) (buf->mem + MOTION_FLAG_OFFSET);
214 + if ( stream->dev->motion ) {
215 + stream->dev->motion = 0;
216 + motion_hotplug_create_event();
217 + } else {
218 + *mem &= 0x7f;
219 + }
220 + }
221 +
222 /* Mark the buffer as done if the EOF marker is set. */
223 if (data[1] & UVC_STREAM_EOF && buf->bytesused != 0) {
224 uvc_trace(UVC_TRACE_FRAME, "Frame complete (EOF found).\n");
225 @@ -1478,6 +1623,8 @@ static int uvc_init_video_isoc(struct uvc_streaming *stream,
226 if (npackets == 0)
227 return -ENOMEM;
228
229 + if (stream->dev->quirks & UVC_QUIRK_SINGLE_ISO)
230 + npackets = 1;
231 size = npackets * psize;
232
233 for (i = 0; i < UVC_URBS; ++i) {
234 diff --git a/drivers/media/usb/uvc/uvcvideo.h b/drivers/media/usb/uvc/uvcvideo.h
235 index 9e35982..3cacdfd 100644
236 --- a/drivers/media/usb/uvc/uvcvideo.h
237 +++ b/drivers/media/usb/uvc/uvcvideo.h
238 @@ -137,6 +137,8 @@
239 #define UVC_QUIRK_FIX_BANDWIDTH 0x00000080
240 #define UVC_QUIRK_PROBE_DEF 0x00000100
241 #define UVC_QUIRK_RESTRICT_FRAME_RATE 0x00000200
242 +#define UVC_QUIRK_MOTION 0x00000400
243 +#define UVC_QUIRK_SINGLE_ISO 0x00000800
244
245 /* Format flags */
246 #define UVC_FMT_FLAG_COMPRESSED 0x00000001
247 @@ -539,6 +541,7 @@ struct uvc_device {
248 __u8 *status;
249 struct input_dev *input;
250 char input_phys[64];
251 + int motion;
252 };
253
254 enum uvc_handle_state {
255 --
256 1.7.10.4
257