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