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