0057-uvc-add-iPassion-iP2970-support.patch 6.1 KB

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