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