sur40.c 32 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189
  1. // SPDX-License-Identifier: GPL-2.0-or-later
  2. /*
  3. * Surface2.0/SUR40/PixelSense input driver
  4. *
  5. * Copyright (c) 2014 by Florian 'floe' Echtler <floe@butterbrot.org>
  6. *
  7. * Derived from the USB Skeleton driver 1.1,
  8. * Copyright (c) 2003 Greg Kroah-Hartman (greg@kroah.com)
  9. *
  10. * and from the Apple USB BCM5974 multitouch driver,
  11. * Copyright (c) 2008 Henrik Rydberg (rydberg@euromail.se)
  12. *
  13. * and from the generic hid-multitouch driver,
  14. * Copyright (c) 2010-2012 Stephane Chatty <chatty@enac.fr>
  15. *
  16. * and from the v4l2-pci-skeleton driver,
  17. * Copyright (c) Copyright 2014 Cisco Systems, Inc.
  18. */
  19. #include <linux/kernel.h>
  20. #include <linux/errno.h>
  21. #include <linux/delay.h>
  22. #include <linux/init.h>
  23. #include <linux/slab.h>
  24. #include <linux/module.h>
  25. #include <linux/completion.h>
  26. #include <linux/uaccess.h>
  27. #include <linux/usb.h>
  28. #include <linux/printk.h>
  29. #include <linux/input.h>
  30. #include <linux/input/mt.h>
  31. #include <linux/usb/input.h>
  32. #include <linux/videodev2.h>
  33. #include <media/v4l2-device.h>
  34. #include <media/v4l2-dev.h>
  35. #include <media/v4l2-ioctl.h>
  36. #include <media/v4l2-ctrls.h>
  37. #include <media/videobuf2-v4l2.h>
  38. #include <media/videobuf2-dma-sg.h>
  39. /* read 512 bytes from endpoint 0x86 -> get header + blobs */
  40. struct sur40_header {
  41. __le16 type; /* always 0x0001 */
  42. __le16 count; /* count of blobs (if 0: continue prev. packet) */
  43. __le32 packet_id; /* unique ID for all packets in one frame */
  44. __le32 timestamp; /* milliseconds (inc. by 16 or 17 each frame) */
  45. __le32 unknown; /* "epoch?" always 02/03 00 00 00 */
  46. } __packed;
  47. struct sur40_blob {
  48. __le16 blob_id;
  49. u8 action; /* 0x02 = enter/exit, 0x03 = update (?) */
  50. u8 type; /* bitmask (0x01 blob, 0x02 touch, 0x04 tag) */
  51. __le16 bb_pos_x; /* upper left corner of bounding box */
  52. __le16 bb_pos_y;
  53. __le16 bb_size_x; /* size of bounding box */
  54. __le16 bb_size_y;
  55. __le16 pos_x; /* finger tip position */
  56. __le16 pos_y;
  57. __le16 ctr_x; /* centroid position */
  58. __le16 ctr_y;
  59. __le16 axis_x; /* somehow related to major/minor axis, mostly: */
  60. __le16 axis_y; /* axis_x == bb_size_y && axis_y == bb_size_x */
  61. __le32 angle; /* orientation in radians relative to x axis -
  62. actually an IEEE754 float, don't use in kernel */
  63. __le32 area; /* size in pixels/pressure (?) */
  64. u8 padding[24];
  65. __le32 tag_id; /* valid when type == 0x04 (SUR40_TAG) */
  66. __le32 unknown;
  67. } __packed;
  68. /* combined header/blob data */
  69. struct sur40_data {
  70. struct sur40_header header;
  71. struct sur40_blob blobs[];
  72. } __packed;
  73. /* read 512 bytes from endpoint 0x82 -> get header below
  74. * continue reading 16k blocks until header.size bytes read */
  75. struct sur40_image_header {
  76. __le32 magic; /* "SUBF" */
  77. __le32 packet_id;
  78. __le32 size; /* always 0x0007e900 = 960x540 */
  79. __le32 timestamp; /* milliseconds (increases by 16 or 17 each frame) */
  80. __le32 unknown; /* "epoch?" always 02/03 00 00 00 */
  81. } __packed;
  82. /* version information */
  83. #define DRIVER_SHORT "sur40"
  84. #define DRIVER_LONG "Samsung SUR40"
  85. #define DRIVER_AUTHOR "Florian 'floe' Echtler <floe@butterbrot.org>"
  86. #define DRIVER_DESC "Surface2.0/SUR40/PixelSense input driver"
  87. /* vendor and device IDs */
  88. #define ID_MICROSOFT 0x045e
  89. #define ID_SUR40 0x0775
  90. /* sensor resolution */
  91. #define SENSOR_RES_X 1920
  92. #define SENSOR_RES_Y 1080
  93. /* touch data endpoint */
  94. #define TOUCH_ENDPOINT 0x86
  95. /* video data endpoint */
  96. #define VIDEO_ENDPOINT 0x82
  97. /* video header fields */
  98. #define VIDEO_HEADER_MAGIC 0x46425553
  99. #define VIDEO_PACKET_SIZE 16384
  100. /* polling interval (ms) */
  101. #define POLL_INTERVAL 1
  102. /* maximum number of contacts FIXME: this is a guess? */
  103. #define MAX_CONTACTS 64
  104. /* control commands */
  105. #define SUR40_GET_VERSION 0xb0 /* 12 bytes string */
  106. #define SUR40_ACCEL_CAPS 0xb3 /* 5 bytes */
  107. #define SUR40_SENSOR_CAPS 0xc1 /* 24 bytes */
  108. #define SUR40_POKE 0xc5 /* poke register byte */
  109. #define SUR40_PEEK 0xc4 /* 48 bytes registers */
  110. #define SUR40_GET_STATE 0xc5 /* 4 bytes state (?) */
  111. #define SUR40_GET_SENSORS 0xb1 /* 8 bytes sensors */
  112. #define SUR40_BLOB 0x01
  113. #define SUR40_TOUCH 0x02
  114. #define SUR40_TAG 0x04
  115. /* video controls */
  116. #define SUR40_BRIGHTNESS_MAX 0xff
  117. #define SUR40_BRIGHTNESS_MIN 0x00
  118. #define SUR40_BRIGHTNESS_DEF 0xff
  119. #define SUR40_CONTRAST_MAX 0x0f
  120. #define SUR40_CONTRAST_MIN 0x00
  121. #define SUR40_CONTRAST_DEF 0x0a
  122. #define SUR40_GAIN_MAX 0x09
  123. #define SUR40_GAIN_MIN 0x00
  124. #define SUR40_GAIN_DEF 0x08
  125. #define SUR40_BACKLIGHT_MAX 0x01
  126. #define SUR40_BACKLIGHT_MIN 0x00
  127. #define SUR40_BACKLIGHT_DEF 0x01
  128. #define sur40_str(s) #s
  129. #define SUR40_PARAM_RANGE(lo, hi) " (range " sur40_str(lo) "-" sur40_str(hi) ")"
  130. /* module parameters */
  131. static uint brightness = SUR40_BRIGHTNESS_DEF;
  132. module_param(brightness, uint, 0644);
  133. MODULE_PARM_DESC(brightness, "set initial brightness"
  134. SUR40_PARAM_RANGE(SUR40_BRIGHTNESS_MIN, SUR40_BRIGHTNESS_MAX));
  135. static uint contrast = SUR40_CONTRAST_DEF;
  136. module_param(contrast, uint, 0644);
  137. MODULE_PARM_DESC(contrast, "set initial contrast"
  138. SUR40_PARAM_RANGE(SUR40_CONTRAST_MIN, SUR40_CONTRAST_MAX));
  139. static uint gain = SUR40_GAIN_DEF;
  140. module_param(gain, uint, 0644);
  141. MODULE_PARM_DESC(gain, "set initial gain"
  142. SUR40_PARAM_RANGE(SUR40_GAIN_MIN, SUR40_GAIN_MAX));
  143. static const struct v4l2_pix_format sur40_pix_format[] = {
  144. {
  145. .pixelformat = V4L2_TCH_FMT_TU08,
  146. .width = SENSOR_RES_X / 2,
  147. .height = SENSOR_RES_Y / 2,
  148. .field = V4L2_FIELD_NONE,
  149. .colorspace = V4L2_COLORSPACE_RAW,
  150. .bytesperline = SENSOR_RES_X / 2,
  151. .sizeimage = (SENSOR_RES_X/2) * (SENSOR_RES_Y/2),
  152. },
  153. {
  154. .pixelformat = V4L2_PIX_FMT_GREY,
  155. .width = SENSOR_RES_X / 2,
  156. .height = SENSOR_RES_Y / 2,
  157. .field = V4L2_FIELD_NONE,
  158. .colorspace = V4L2_COLORSPACE_RAW,
  159. .bytesperline = SENSOR_RES_X / 2,
  160. .sizeimage = (SENSOR_RES_X/2) * (SENSOR_RES_Y/2),
  161. }
  162. };
  163. /* master device state */
  164. struct sur40_state {
  165. struct usb_device *usbdev;
  166. struct device *dev;
  167. struct input_dev *input;
  168. struct v4l2_device v4l2;
  169. struct video_device vdev;
  170. struct mutex lock;
  171. struct v4l2_pix_format pix_fmt;
  172. struct v4l2_ctrl_handler hdl;
  173. struct vb2_queue queue;
  174. struct list_head buf_list;
  175. spinlock_t qlock;
  176. int sequence;
  177. struct sur40_data *bulk_in_buffer;
  178. size_t bulk_in_size;
  179. u8 bulk_in_epaddr;
  180. u8 vsvideo;
  181. char phys[64];
  182. };
  183. struct sur40_buffer {
  184. struct vb2_v4l2_buffer vb;
  185. struct list_head list;
  186. };
  187. /* forward declarations */
  188. static const struct video_device sur40_video_device;
  189. static const struct vb2_queue sur40_queue;
  190. static void sur40_process_video(struct sur40_state *sur40);
  191. static int sur40_s_ctrl(struct v4l2_ctrl *ctrl);
  192. static const struct v4l2_ctrl_ops sur40_ctrl_ops = {
  193. .s_ctrl = sur40_s_ctrl,
  194. };
  195. /*
  196. * Note: an earlier, non-public version of this driver used USB_RECIP_ENDPOINT
  197. * here by mistake which is very likely to have corrupted the firmware EEPROM
  198. * on two separate SUR40 devices. Thanks to Alan Stern who spotted this bug.
  199. * Should you ever run into a similar problem, the background story to this
  200. * incident and instructions on how to fix the corrupted EEPROM are available
  201. * at https://floe.butterbrot.org/matrix/hacking/surface/brick.html
  202. */
  203. /* command wrapper */
  204. static int sur40_command(struct sur40_state *dev,
  205. u8 command, u16 index, void *buffer, u16 size)
  206. {
  207. return usb_control_msg(dev->usbdev, usb_rcvctrlpipe(dev->usbdev, 0),
  208. command,
  209. USB_TYPE_VENDOR | USB_RECIP_DEVICE | USB_DIR_IN,
  210. 0x00, index, buffer, size, 1000);
  211. }
  212. /* poke a byte in the panel register space */
  213. static int sur40_poke(struct sur40_state *dev, u8 offset, u8 value)
  214. {
  215. int result;
  216. u8 index = 0x96; // 0xae for permanent write
  217. result = usb_control_msg(dev->usbdev, usb_sndctrlpipe(dev->usbdev, 0),
  218. SUR40_POKE, USB_TYPE_VENDOR | USB_RECIP_DEVICE | USB_DIR_OUT,
  219. 0x32, index, NULL, 0, 1000);
  220. if (result < 0)
  221. goto error;
  222. msleep(5);
  223. result = usb_control_msg(dev->usbdev, usb_sndctrlpipe(dev->usbdev, 0),
  224. SUR40_POKE, USB_TYPE_VENDOR | USB_RECIP_DEVICE | USB_DIR_OUT,
  225. 0x72, offset, NULL, 0, 1000);
  226. if (result < 0)
  227. goto error;
  228. msleep(5);
  229. result = usb_control_msg(dev->usbdev, usb_sndctrlpipe(dev->usbdev, 0),
  230. SUR40_POKE, USB_TYPE_VENDOR | USB_RECIP_DEVICE | USB_DIR_OUT,
  231. 0xb2, value, NULL, 0, 1000);
  232. if (result < 0)
  233. goto error;
  234. msleep(5);
  235. error:
  236. return result;
  237. }
  238. static int sur40_set_preprocessor(struct sur40_state *dev, u8 value)
  239. {
  240. u8 setting_07[2] = { 0x01, 0x00 };
  241. u8 setting_17[2] = { 0x85, 0x80 };
  242. int result;
  243. if (value > 1)
  244. return -ERANGE;
  245. result = usb_control_msg(dev->usbdev, usb_sndctrlpipe(dev->usbdev, 0),
  246. SUR40_POKE, USB_TYPE_VENDOR | USB_RECIP_DEVICE | USB_DIR_OUT,
  247. 0x07, setting_07[value], NULL, 0, 1000);
  248. if (result < 0)
  249. goto error;
  250. msleep(5);
  251. result = usb_control_msg(dev->usbdev, usb_sndctrlpipe(dev->usbdev, 0),
  252. SUR40_POKE, USB_TYPE_VENDOR | USB_RECIP_DEVICE | USB_DIR_OUT,
  253. 0x17, setting_17[value], NULL, 0, 1000);
  254. if (result < 0)
  255. goto error;
  256. msleep(5);
  257. error:
  258. return result;
  259. }
  260. static void sur40_set_vsvideo(struct sur40_state *handle, u8 value)
  261. {
  262. int i;
  263. for (i = 0; i < 4; i++)
  264. sur40_poke(handle, 0x1c+i, value);
  265. handle->vsvideo = value;
  266. }
  267. static void sur40_set_irlevel(struct sur40_state *handle, u8 value)
  268. {
  269. int i;
  270. for (i = 0; i < 8; i++)
  271. sur40_poke(handle, 0x08+(2*i), value);
  272. }
  273. /* Initialization routine, called from sur40_open */
  274. static int sur40_init(struct sur40_state *dev)
  275. {
  276. int result;
  277. u8 *buffer;
  278. buffer = kmalloc(24, GFP_KERNEL);
  279. if (!buffer) {
  280. result = -ENOMEM;
  281. goto error;
  282. }
  283. /* stupidly replay the original MS driver init sequence */
  284. result = sur40_command(dev, SUR40_GET_VERSION, 0x00, buffer, 12);
  285. if (result < 0)
  286. goto error;
  287. result = sur40_command(dev, SUR40_GET_VERSION, 0x01, buffer, 12);
  288. if (result < 0)
  289. goto error;
  290. result = sur40_command(dev, SUR40_GET_VERSION, 0x02, buffer, 12);
  291. if (result < 0)
  292. goto error;
  293. result = sur40_command(dev, SUR40_SENSOR_CAPS, 0x00, buffer, 24);
  294. if (result < 0)
  295. goto error;
  296. result = sur40_command(dev, SUR40_ACCEL_CAPS, 0x00, buffer, 5);
  297. if (result < 0)
  298. goto error;
  299. result = sur40_command(dev, SUR40_GET_VERSION, 0x03, buffer, 12);
  300. if (result < 0)
  301. goto error;
  302. result = 0;
  303. /*
  304. * Discard the result buffer - no known data inside except
  305. * some version strings, maybe extract these sometime...
  306. */
  307. error:
  308. kfree(buffer);
  309. return result;
  310. }
  311. /*
  312. * Callback routines from input_dev
  313. */
  314. /* Enable the device, polling will now start. */
  315. static int sur40_open(struct input_dev *input)
  316. {
  317. struct sur40_state *sur40 = input_get_drvdata(input);
  318. dev_dbg(sur40->dev, "open\n");
  319. return sur40_init(sur40);
  320. }
  321. /* Disable device, polling has stopped. */
  322. static void sur40_close(struct input_dev *input)
  323. {
  324. struct sur40_state *sur40 = input_get_drvdata(input);
  325. dev_dbg(sur40->dev, "close\n");
  326. /*
  327. * There is no known way to stop the device, so we simply
  328. * stop polling.
  329. */
  330. }
  331. /*
  332. * This function is called when a whole contact has been processed,
  333. * so that it can assign it to a slot and store the data there.
  334. */
  335. static void sur40_report_blob(struct sur40_blob *blob, struct input_dev *input)
  336. {
  337. int wide, major, minor;
  338. int bb_size_x, bb_size_y, pos_x, pos_y, ctr_x, ctr_y, slotnum;
  339. if (blob->type != SUR40_TOUCH)
  340. return;
  341. slotnum = input_mt_get_slot_by_key(input, le16_to_cpu(blob->blob_id));
  342. if (slotnum < 0 || slotnum >= MAX_CONTACTS)
  343. return;
  344. bb_size_x = le16_to_cpu(blob->bb_size_x);
  345. bb_size_y = le16_to_cpu(blob->bb_size_y);
  346. pos_x = le16_to_cpu(blob->pos_x);
  347. pos_y = le16_to_cpu(blob->pos_y);
  348. ctr_x = le16_to_cpu(blob->ctr_x);
  349. ctr_y = le16_to_cpu(blob->ctr_y);
  350. input_mt_slot(input, slotnum);
  351. input_mt_report_slot_state(input, MT_TOOL_FINGER, 1);
  352. wide = (bb_size_x > bb_size_y);
  353. major = max(bb_size_x, bb_size_y);
  354. minor = min(bb_size_x, bb_size_y);
  355. input_report_abs(input, ABS_MT_POSITION_X, pos_x);
  356. input_report_abs(input, ABS_MT_POSITION_Y, pos_y);
  357. input_report_abs(input, ABS_MT_TOOL_X, ctr_x);
  358. input_report_abs(input, ABS_MT_TOOL_Y, ctr_y);
  359. /* TODO: use a better orientation measure */
  360. input_report_abs(input, ABS_MT_ORIENTATION, wide);
  361. input_report_abs(input, ABS_MT_TOUCH_MAJOR, major);
  362. input_report_abs(input, ABS_MT_TOUCH_MINOR, minor);
  363. }
  364. /* core function: poll for new input data */
  365. static void sur40_poll(struct input_dev *input)
  366. {
  367. struct sur40_state *sur40 = input_get_drvdata(input);
  368. int result, bulk_read, need_blobs, packet_blobs, i;
  369. struct sur40_header *header = &sur40->bulk_in_buffer->header;
  370. struct sur40_blob *inblob = &sur40->bulk_in_buffer->blobs[0];
  371. dev_dbg(sur40->dev, "poll\n");
  372. need_blobs = -1;
  373. do {
  374. /* perform a blocking bulk read to get data from the device */
  375. result = usb_bulk_msg(sur40->usbdev,
  376. usb_rcvbulkpipe(sur40->usbdev, sur40->bulk_in_epaddr),
  377. sur40->bulk_in_buffer, sur40->bulk_in_size,
  378. &bulk_read, 1000);
  379. dev_dbg(sur40->dev, "received %d bytes\n", bulk_read);
  380. if (result < 0) {
  381. dev_err(sur40->dev, "error in usb_bulk_read\n");
  382. return;
  383. }
  384. result = bulk_read - sizeof(struct sur40_header);
  385. if (result % sizeof(struct sur40_blob) != 0) {
  386. dev_err(sur40->dev, "transfer size mismatch\n");
  387. return;
  388. }
  389. /* first packet? */
  390. if (need_blobs == -1) {
  391. need_blobs = le16_to_cpu(header->count);
  392. dev_dbg(sur40->dev, "need %d blobs\n", need_blobs);
  393. /* packet_id = le32_to_cpu(header->packet_id); */
  394. }
  395. /*
  396. * Sanity check. when video data is also being retrieved, the
  397. * packet ID will usually increase in the middle of a series
  398. * instead of at the end. However, the data is still consistent,
  399. * so the packet ID is probably just valid for the first packet
  400. * in a series.
  401. if (packet_id != le32_to_cpu(header->packet_id))
  402. dev_dbg(sur40->dev, "packet ID mismatch\n");
  403. */
  404. packet_blobs = result / sizeof(struct sur40_blob);
  405. dev_dbg(sur40->dev, "received %d blobs\n", packet_blobs);
  406. /* packets always contain at least 4 blobs, even if empty */
  407. if (packet_blobs > need_blobs)
  408. packet_blobs = need_blobs;
  409. for (i = 0; i < packet_blobs; i++) {
  410. need_blobs--;
  411. dev_dbg(sur40->dev, "processing blob\n");
  412. sur40_report_blob(&(inblob[i]), input);
  413. }
  414. } while (need_blobs > 0);
  415. input_mt_sync_frame(input);
  416. input_sync(input);
  417. sur40_process_video(sur40);
  418. }
  419. /* deal with video data */
  420. static void sur40_process_video(struct sur40_state *sur40)
  421. {
  422. struct sur40_image_header *img = (void *)(sur40->bulk_in_buffer);
  423. struct sur40_buffer *new_buf;
  424. struct usb_sg_request sgr;
  425. struct sg_table *sgt;
  426. int result, bulk_read;
  427. if (!vb2_start_streaming_called(&sur40->queue))
  428. return;
  429. /* get a new buffer from the list */
  430. spin_lock(&sur40->qlock);
  431. if (list_empty(&sur40->buf_list)) {
  432. dev_dbg(sur40->dev, "buffer queue empty\n");
  433. spin_unlock(&sur40->qlock);
  434. return;
  435. }
  436. new_buf = list_entry(sur40->buf_list.next, struct sur40_buffer, list);
  437. list_del(&new_buf->list);
  438. spin_unlock(&sur40->qlock);
  439. dev_dbg(sur40->dev, "buffer acquired\n");
  440. /* retrieve data via bulk read */
  441. result = usb_bulk_msg(sur40->usbdev,
  442. usb_rcvbulkpipe(sur40->usbdev, VIDEO_ENDPOINT),
  443. sur40->bulk_in_buffer, sur40->bulk_in_size,
  444. &bulk_read, 1000);
  445. if (result < 0) {
  446. dev_err(sur40->dev, "error in usb_bulk_read\n");
  447. goto err_poll;
  448. }
  449. if (bulk_read != sizeof(struct sur40_image_header)) {
  450. dev_err(sur40->dev, "received %d bytes (%zd expected)\n",
  451. bulk_read, sizeof(struct sur40_image_header));
  452. goto err_poll;
  453. }
  454. if (le32_to_cpu(img->magic) != VIDEO_HEADER_MAGIC) {
  455. dev_err(sur40->dev, "image magic mismatch\n");
  456. goto err_poll;
  457. }
  458. if (le32_to_cpu(img->size) != sur40->pix_fmt.sizeimage) {
  459. dev_err(sur40->dev, "image size mismatch\n");
  460. goto err_poll;
  461. }
  462. dev_dbg(sur40->dev, "header acquired\n");
  463. sgt = vb2_dma_sg_plane_desc(&new_buf->vb.vb2_buf, 0);
  464. result = usb_sg_init(&sgr, sur40->usbdev,
  465. usb_rcvbulkpipe(sur40->usbdev, VIDEO_ENDPOINT), 0,
  466. sgt->sgl, sgt->nents, sur40->pix_fmt.sizeimage, 0);
  467. if (result < 0) {
  468. dev_err(sur40->dev, "error %d in usb_sg_init\n", result);
  469. goto err_poll;
  470. }
  471. usb_sg_wait(&sgr);
  472. if (sgr.status < 0) {
  473. dev_err(sur40->dev, "error %d in usb_sg_wait\n", sgr.status);
  474. goto err_poll;
  475. }
  476. dev_dbg(sur40->dev, "image acquired\n");
  477. /* return error if streaming was stopped in the meantime */
  478. if (sur40->sequence == -1)
  479. return;
  480. /* mark as finished */
  481. new_buf->vb.vb2_buf.timestamp = ktime_get_ns();
  482. new_buf->vb.sequence = sur40->sequence++;
  483. new_buf->vb.field = V4L2_FIELD_NONE;
  484. vb2_buffer_done(&new_buf->vb.vb2_buf, VB2_BUF_STATE_DONE);
  485. dev_dbg(sur40->dev, "buffer marked done\n");
  486. return;
  487. err_poll:
  488. vb2_buffer_done(&new_buf->vb.vb2_buf, VB2_BUF_STATE_ERROR);
  489. }
  490. /* Initialize input device parameters. */
  491. static int sur40_input_setup_events(struct input_dev *input_dev)
  492. {
  493. int error;
  494. input_set_abs_params(input_dev, ABS_MT_POSITION_X,
  495. 0, SENSOR_RES_X, 0, 0);
  496. input_set_abs_params(input_dev, ABS_MT_POSITION_Y,
  497. 0, SENSOR_RES_Y, 0, 0);
  498. input_set_abs_params(input_dev, ABS_MT_TOOL_X,
  499. 0, SENSOR_RES_X, 0, 0);
  500. input_set_abs_params(input_dev, ABS_MT_TOOL_Y,
  501. 0, SENSOR_RES_Y, 0, 0);
  502. /* max value unknown, but major/minor axis
  503. * can never be larger than screen */
  504. input_set_abs_params(input_dev, ABS_MT_TOUCH_MAJOR,
  505. 0, SENSOR_RES_X, 0, 0);
  506. input_set_abs_params(input_dev, ABS_MT_TOUCH_MINOR,
  507. 0, SENSOR_RES_Y, 0, 0);
  508. input_set_abs_params(input_dev, ABS_MT_ORIENTATION, 0, 1, 0, 0);
  509. error = input_mt_init_slots(input_dev, MAX_CONTACTS,
  510. INPUT_MT_DIRECT | INPUT_MT_DROP_UNUSED);
  511. if (error) {
  512. dev_err(input_dev->dev.parent, "failed to set up slots\n");
  513. return error;
  514. }
  515. return 0;
  516. }
  517. /* Check candidate USB interface. */
  518. static int sur40_probe(struct usb_interface *interface,
  519. const struct usb_device_id *id)
  520. {
  521. struct usb_device *usbdev = interface_to_usbdev(interface);
  522. struct sur40_state *sur40;
  523. struct usb_host_interface *iface_desc;
  524. struct usb_endpoint_descriptor *endpoint;
  525. struct input_dev *input;
  526. int error;
  527. /* Check if we really have the right interface. */
  528. iface_desc = interface->cur_altsetting;
  529. if (iface_desc->desc.bInterfaceClass != 0xFF)
  530. return -ENODEV;
  531. if (iface_desc->desc.bNumEndpoints < 5)
  532. return -ENODEV;
  533. /* Use endpoint #4 (0x86). */
  534. endpoint = &iface_desc->endpoint[4].desc;
  535. if (endpoint->bEndpointAddress != TOUCH_ENDPOINT)
  536. return -ENODEV;
  537. /* Allocate memory for our device state and initialize it. */
  538. sur40 = kzalloc_obj(*sur40);
  539. if (!sur40)
  540. return -ENOMEM;
  541. input = input_allocate_device();
  542. if (!input) {
  543. error = -ENOMEM;
  544. goto err_free_dev;
  545. }
  546. /* initialize locks/lists */
  547. INIT_LIST_HEAD(&sur40->buf_list);
  548. spin_lock_init(&sur40->qlock);
  549. mutex_init(&sur40->lock);
  550. /* Set up regular input device structure */
  551. input->name = DRIVER_LONG;
  552. usb_to_input_id(usbdev, &input->id);
  553. usb_make_path(usbdev, sur40->phys, sizeof(sur40->phys));
  554. strlcat(sur40->phys, "/input0", sizeof(sur40->phys));
  555. input->phys = sur40->phys;
  556. input->dev.parent = &interface->dev;
  557. input->open = sur40_open;
  558. input->close = sur40_close;
  559. error = sur40_input_setup_events(input);
  560. if (error)
  561. goto err_free_input;
  562. input_set_drvdata(input, sur40);
  563. error = input_setup_polling(input, sur40_poll);
  564. if (error) {
  565. dev_err(&interface->dev, "failed to set up polling");
  566. goto err_free_input;
  567. }
  568. input_set_poll_interval(input, POLL_INTERVAL);
  569. sur40->usbdev = usbdev;
  570. sur40->dev = &interface->dev;
  571. sur40->input = input;
  572. /* use the bulk-in endpoint tested above */
  573. sur40->bulk_in_size = usb_endpoint_maxp(endpoint);
  574. sur40->bulk_in_epaddr = endpoint->bEndpointAddress;
  575. sur40->bulk_in_buffer = kmalloc(sur40->bulk_in_size, GFP_KERNEL);
  576. if (!sur40->bulk_in_buffer) {
  577. dev_err(&interface->dev, "Unable to allocate input buffer.");
  578. error = -ENOMEM;
  579. goto err_free_input;
  580. }
  581. /* register the polled input device */
  582. error = input_register_device(input);
  583. if (error) {
  584. dev_err(&interface->dev,
  585. "Unable to register polled input device.");
  586. goto err_free_buffer;
  587. }
  588. /* register the video master device */
  589. snprintf(sur40->v4l2.name, sizeof(sur40->v4l2.name), "%s", DRIVER_LONG);
  590. error = v4l2_device_register(sur40->dev, &sur40->v4l2);
  591. if (error) {
  592. dev_err(&interface->dev,
  593. "Unable to register video master device.");
  594. goto err_unreg_v4l2;
  595. }
  596. /* initialize the lock and subdevice */
  597. sur40->queue = sur40_queue;
  598. sur40->queue.drv_priv = sur40;
  599. sur40->queue.lock = &sur40->lock;
  600. sur40->queue.dev = sur40->dev;
  601. /* initialize the queue */
  602. error = vb2_queue_init(&sur40->queue);
  603. if (error)
  604. goto err_unreg_v4l2;
  605. sur40->pix_fmt = sur40_pix_format[0];
  606. sur40->vdev = sur40_video_device;
  607. sur40->vdev.v4l2_dev = &sur40->v4l2;
  608. sur40->vdev.lock = &sur40->lock;
  609. sur40->vdev.queue = &sur40->queue;
  610. video_set_drvdata(&sur40->vdev, sur40);
  611. /* initialize the control handler for 4 controls */
  612. v4l2_ctrl_handler_init(&sur40->hdl, 4);
  613. sur40->v4l2.ctrl_handler = &sur40->hdl;
  614. sur40->vsvideo = (SUR40_CONTRAST_DEF << 4) | SUR40_GAIN_DEF;
  615. v4l2_ctrl_new_std(&sur40->hdl, &sur40_ctrl_ops, V4L2_CID_BRIGHTNESS,
  616. SUR40_BRIGHTNESS_MIN, SUR40_BRIGHTNESS_MAX, 1, clamp(brightness,
  617. (uint)SUR40_BRIGHTNESS_MIN, (uint)SUR40_BRIGHTNESS_MAX));
  618. v4l2_ctrl_new_std(&sur40->hdl, &sur40_ctrl_ops, V4L2_CID_CONTRAST,
  619. SUR40_CONTRAST_MIN, SUR40_CONTRAST_MAX, 1, clamp(contrast,
  620. (uint)SUR40_CONTRAST_MIN, (uint)SUR40_CONTRAST_MAX));
  621. v4l2_ctrl_new_std(&sur40->hdl, &sur40_ctrl_ops, V4L2_CID_GAIN,
  622. SUR40_GAIN_MIN, SUR40_GAIN_MAX, 1, clamp(gain,
  623. (uint)SUR40_GAIN_MIN, (uint)SUR40_GAIN_MAX));
  624. v4l2_ctrl_new_std(&sur40->hdl, &sur40_ctrl_ops,
  625. V4L2_CID_BACKLIGHT_COMPENSATION, SUR40_BACKLIGHT_MIN,
  626. SUR40_BACKLIGHT_MAX, 1, SUR40_BACKLIGHT_DEF);
  627. v4l2_ctrl_handler_setup(&sur40->hdl);
  628. if (sur40->hdl.error) {
  629. dev_err(&interface->dev,
  630. "Unable to register video controls.");
  631. v4l2_ctrl_handler_free(&sur40->hdl);
  632. error = sur40->hdl.error;
  633. goto err_unreg_v4l2;
  634. }
  635. error = video_register_device(&sur40->vdev, VFL_TYPE_TOUCH, -1);
  636. if (error) {
  637. dev_err(&interface->dev,
  638. "Unable to register video subdevice.");
  639. goto err_unreg_video;
  640. }
  641. /* we can register the device now, as it is ready */
  642. usb_set_intfdata(interface, sur40);
  643. dev_dbg(&interface->dev, "%s is now attached\n", DRIVER_DESC);
  644. return 0;
  645. err_unreg_video:
  646. video_unregister_device(&sur40->vdev);
  647. err_unreg_v4l2:
  648. v4l2_device_unregister(&sur40->v4l2);
  649. err_free_buffer:
  650. kfree(sur40->bulk_in_buffer);
  651. err_free_input:
  652. input_free_device(input);
  653. err_free_dev:
  654. kfree(sur40);
  655. return error;
  656. }
  657. /* Unregister device & clean up. */
  658. static void sur40_disconnect(struct usb_interface *interface)
  659. {
  660. struct sur40_state *sur40 = usb_get_intfdata(interface);
  661. v4l2_ctrl_handler_free(&sur40->hdl);
  662. video_unregister_device(&sur40->vdev);
  663. v4l2_device_unregister(&sur40->v4l2);
  664. input_unregister_device(sur40->input);
  665. kfree(sur40->bulk_in_buffer);
  666. kfree(sur40);
  667. usb_set_intfdata(interface, NULL);
  668. dev_dbg(&interface->dev, "%s is now disconnected\n", DRIVER_DESC);
  669. }
  670. /*
  671. * Setup the constraints of the queue: besides setting the number of planes
  672. * per buffer and the size and allocation context of each plane, it also
  673. * checks if sufficient buffers have been allocated. Usually 3 is a good
  674. * minimum number: many DMA engines need a minimum of 2 buffers in the
  675. * queue and you need to have another available for userspace processing.
  676. */
  677. static int sur40_queue_setup(struct vb2_queue *q,
  678. unsigned int *nbuffers, unsigned int *nplanes,
  679. unsigned int sizes[], struct device *alloc_devs[])
  680. {
  681. struct sur40_state *sur40 = vb2_get_drv_priv(q);
  682. unsigned int q_num_bufs = vb2_get_num_buffers(q);
  683. if (q_num_bufs + *nbuffers < 3)
  684. *nbuffers = 3 - q_num_bufs;
  685. if (*nplanes)
  686. return sizes[0] < sur40->pix_fmt.sizeimage ? -EINVAL : 0;
  687. *nplanes = 1;
  688. sizes[0] = sur40->pix_fmt.sizeimage;
  689. return 0;
  690. }
  691. /*
  692. * Prepare the buffer for queueing to the DMA engine: check and set the
  693. * payload size.
  694. */
  695. static int sur40_buffer_prepare(struct vb2_buffer *vb)
  696. {
  697. struct sur40_state *sur40 = vb2_get_drv_priv(vb->vb2_queue);
  698. unsigned long size = sur40->pix_fmt.sizeimage;
  699. if (vb2_plane_size(vb, 0) < size) {
  700. dev_err(&sur40->usbdev->dev, "buffer too small (%lu < %lu)\n",
  701. vb2_plane_size(vb, 0), size);
  702. return -EINVAL;
  703. }
  704. vb2_set_plane_payload(vb, 0, size);
  705. return 0;
  706. }
  707. /*
  708. * Queue this buffer to the DMA engine.
  709. */
  710. static void sur40_buffer_queue(struct vb2_buffer *vb)
  711. {
  712. struct sur40_state *sur40 = vb2_get_drv_priv(vb->vb2_queue);
  713. struct sur40_buffer *buf = (struct sur40_buffer *)vb;
  714. spin_lock(&sur40->qlock);
  715. list_add_tail(&buf->list, &sur40->buf_list);
  716. spin_unlock(&sur40->qlock);
  717. }
  718. static void return_all_buffers(struct sur40_state *sur40,
  719. enum vb2_buffer_state state)
  720. {
  721. struct sur40_buffer *buf, *node;
  722. spin_lock(&sur40->qlock);
  723. list_for_each_entry_safe(buf, node, &sur40->buf_list, list) {
  724. vb2_buffer_done(&buf->vb.vb2_buf, state);
  725. list_del(&buf->list);
  726. }
  727. spin_unlock(&sur40->qlock);
  728. }
  729. /*
  730. * Start streaming. First check if the minimum number of buffers have been
  731. * queued. If not, then return -ENOBUFS and the vb2 framework will call
  732. * this function again the next time a buffer has been queued until enough
  733. * buffers are available to actually start the DMA engine.
  734. */
  735. static int sur40_start_streaming(struct vb2_queue *vq, unsigned int count)
  736. {
  737. struct sur40_state *sur40 = vb2_get_drv_priv(vq);
  738. sur40->sequence = 0;
  739. return 0;
  740. }
  741. /*
  742. * Stop the DMA engine. Any remaining buffers in the DMA queue are dequeued
  743. * and passed on to the vb2 framework marked as STATE_ERROR.
  744. */
  745. static void sur40_stop_streaming(struct vb2_queue *vq)
  746. {
  747. struct sur40_state *sur40 = vb2_get_drv_priv(vq);
  748. vb2_wait_for_all_buffers(vq);
  749. sur40->sequence = -1;
  750. /* Release all active buffers */
  751. return_all_buffers(sur40, VB2_BUF_STATE_ERROR);
  752. }
  753. /* V4L ioctl */
  754. static int sur40_vidioc_querycap(struct file *file, void *priv,
  755. struct v4l2_capability *cap)
  756. {
  757. struct sur40_state *sur40 = video_drvdata(file);
  758. strscpy(cap->driver, DRIVER_SHORT, sizeof(cap->driver));
  759. strscpy(cap->card, DRIVER_LONG, sizeof(cap->card));
  760. usb_make_path(sur40->usbdev, cap->bus_info, sizeof(cap->bus_info));
  761. return 0;
  762. }
  763. static int sur40_vidioc_enum_input(struct file *file, void *priv,
  764. struct v4l2_input *i)
  765. {
  766. if (i->index != 0)
  767. return -EINVAL;
  768. i->type = V4L2_INPUT_TYPE_TOUCH;
  769. i->std = V4L2_STD_UNKNOWN;
  770. strscpy(i->name, "In-Cell Sensor", sizeof(i->name));
  771. i->capabilities = 0;
  772. return 0;
  773. }
  774. static int sur40_vidioc_s_input(struct file *file, void *priv, unsigned int i)
  775. {
  776. return (i == 0) ? 0 : -EINVAL;
  777. }
  778. static int sur40_vidioc_g_input(struct file *file, void *priv, unsigned int *i)
  779. {
  780. *i = 0;
  781. return 0;
  782. }
  783. static int sur40_vidioc_try_fmt(struct file *file, void *priv,
  784. struct v4l2_format *f)
  785. {
  786. switch (f->fmt.pix.pixelformat) {
  787. case V4L2_PIX_FMT_GREY:
  788. f->fmt.pix = sur40_pix_format[1];
  789. break;
  790. default:
  791. f->fmt.pix = sur40_pix_format[0];
  792. break;
  793. }
  794. return 0;
  795. }
  796. static int sur40_vidioc_s_fmt(struct file *file, void *priv,
  797. struct v4l2_format *f)
  798. {
  799. struct sur40_state *sur40 = video_drvdata(file);
  800. switch (f->fmt.pix.pixelformat) {
  801. case V4L2_PIX_FMT_GREY:
  802. sur40->pix_fmt = sur40_pix_format[1];
  803. break;
  804. default:
  805. sur40->pix_fmt = sur40_pix_format[0];
  806. break;
  807. }
  808. f->fmt.pix = sur40->pix_fmt;
  809. return 0;
  810. }
  811. static int sur40_vidioc_g_fmt(struct file *file, void *priv,
  812. struct v4l2_format *f)
  813. {
  814. struct sur40_state *sur40 = video_drvdata(file);
  815. f->fmt.pix = sur40->pix_fmt;
  816. return 0;
  817. }
  818. static int sur40_s_ctrl(struct v4l2_ctrl *ctrl)
  819. {
  820. struct sur40_state *sur40 = container_of(ctrl->handler,
  821. struct sur40_state, hdl);
  822. u8 value = sur40->vsvideo;
  823. switch (ctrl->id) {
  824. case V4L2_CID_BRIGHTNESS:
  825. sur40_set_irlevel(sur40, ctrl->val);
  826. break;
  827. case V4L2_CID_CONTRAST:
  828. value = (value & 0x0f) | (ctrl->val << 4);
  829. sur40_set_vsvideo(sur40, value);
  830. break;
  831. case V4L2_CID_GAIN:
  832. value = (value & 0xf0) | (ctrl->val);
  833. sur40_set_vsvideo(sur40, value);
  834. break;
  835. case V4L2_CID_BACKLIGHT_COMPENSATION:
  836. sur40_set_preprocessor(sur40, ctrl->val);
  837. break;
  838. }
  839. return 0;
  840. }
  841. static int sur40_ioctl_parm(struct file *file, void *priv,
  842. struct v4l2_streamparm *p)
  843. {
  844. if (p->type != V4L2_BUF_TYPE_VIDEO_CAPTURE)
  845. return -EINVAL;
  846. p->parm.capture.capability = V4L2_CAP_TIMEPERFRAME;
  847. p->parm.capture.timeperframe.numerator = 1;
  848. p->parm.capture.timeperframe.denominator = 60;
  849. p->parm.capture.readbuffers = 3;
  850. return 0;
  851. }
  852. static int sur40_vidioc_enum_fmt(struct file *file, void *priv,
  853. struct v4l2_fmtdesc *f)
  854. {
  855. if (f->index >= ARRAY_SIZE(sur40_pix_format))
  856. return -EINVAL;
  857. f->pixelformat = sur40_pix_format[f->index].pixelformat;
  858. f->flags = 0;
  859. return 0;
  860. }
  861. static int sur40_vidioc_enum_framesizes(struct file *file, void *priv,
  862. struct v4l2_frmsizeenum *f)
  863. {
  864. struct sur40_state *sur40 = video_drvdata(file);
  865. if ((f->index != 0) || ((f->pixel_format != V4L2_TCH_FMT_TU08)
  866. && (f->pixel_format != V4L2_PIX_FMT_GREY)))
  867. return -EINVAL;
  868. f->type = V4L2_FRMSIZE_TYPE_DISCRETE;
  869. f->discrete.width = sur40->pix_fmt.width;
  870. f->discrete.height = sur40->pix_fmt.height;
  871. return 0;
  872. }
  873. static int sur40_vidioc_enum_frameintervals(struct file *file, void *priv,
  874. struct v4l2_frmivalenum *f)
  875. {
  876. struct sur40_state *sur40 = video_drvdata(file);
  877. if ((f->index > 0) || ((f->pixel_format != V4L2_TCH_FMT_TU08)
  878. && (f->pixel_format != V4L2_PIX_FMT_GREY))
  879. || (f->width != sur40->pix_fmt.width)
  880. || (f->height != sur40->pix_fmt.height))
  881. return -EINVAL;
  882. f->type = V4L2_FRMIVAL_TYPE_DISCRETE;
  883. f->discrete.denominator = 60;
  884. f->discrete.numerator = 1;
  885. return 0;
  886. }
  887. static const struct usb_device_id sur40_table[] = {
  888. { USB_DEVICE(ID_MICROSOFT, ID_SUR40) }, /* Samsung SUR40 */
  889. { } /* terminating null entry */
  890. };
  891. MODULE_DEVICE_TABLE(usb, sur40_table);
  892. /* V4L2 structures */
  893. static const struct vb2_ops sur40_queue_ops = {
  894. .queue_setup = sur40_queue_setup,
  895. .buf_prepare = sur40_buffer_prepare,
  896. .buf_queue = sur40_buffer_queue,
  897. .start_streaming = sur40_start_streaming,
  898. .stop_streaming = sur40_stop_streaming,
  899. };
  900. static const struct vb2_queue sur40_queue = {
  901. .type = V4L2_BUF_TYPE_VIDEO_CAPTURE,
  902. /*
  903. * VB2_USERPTR in currently not enabled: passing a user pointer to
  904. * dma-sg will result in segment sizes that are not a multiple of
  905. * 512 bytes, which is required by the host controller.
  906. */
  907. .io_modes = VB2_MMAP | VB2_READ | VB2_DMABUF,
  908. .buf_struct_size = sizeof(struct sur40_buffer),
  909. .ops = &sur40_queue_ops,
  910. .mem_ops = &vb2_dma_sg_memops,
  911. .timestamp_flags = V4L2_BUF_FLAG_TIMESTAMP_MONOTONIC,
  912. .min_queued_buffers = 3,
  913. };
  914. static const struct v4l2_file_operations sur40_video_fops = {
  915. .owner = THIS_MODULE,
  916. .open = v4l2_fh_open,
  917. .release = vb2_fop_release,
  918. .unlocked_ioctl = video_ioctl2,
  919. .read = vb2_fop_read,
  920. .mmap = vb2_fop_mmap,
  921. .poll = vb2_fop_poll,
  922. };
  923. static const struct v4l2_ioctl_ops sur40_video_ioctl_ops = {
  924. .vidioc_querycap = sur40_vidioc_querycap,
  925. .vidioc_enum_fmt_vid_cap = sur40_vidioc_enum_fmt,
  926. .vidioc_try_fmt_vid_cap = sur40_vidioc_try_fmt,
  927. .vidioc_s_fmt_vid_cap = sur40_vidioc_s_fmt,
  928. .vidioc_g_fmt_vid_cap = sur40_vidioc_g_fmt,
  929. .vidioc_enum_framesizes = sur40_vidioc_enum_framesizes,
  930. .vidioc_enum_frameintervals = sur40_vidioc_enum_frameintervals,
  931. .vidioc_g_parm = sur40_ioctl_parm,
  932. .vidioc_s_parm = sur40_ioctl_parm,
  933. .vidioc_enum_input = sur40_vidioc_enum_input,
  934. .vidioc_g_input = sur40_vidioc_g_input,
  935. .vidioc_s_input = sur40_vidioc_s_input,
  936. .vidioc_reqbufs = vb2_ioctl_reqbufs,
  937. .vidioc_create_bufs = vb2_ioctl_create_bufs,
  938. .vidioc_querybuf = vb2_ioctl_querybuf,
  939. .vidioc_qbuf = vb2_ioctl_qbuf,
  940. .vidioc_dqbuf = vb2_ioctl_dqbuf,
  941. .vidioc_expbuf = vb2_ioctl_expbuf,
  942. .vidioc_streamon = vb2_ioctl_streamon,
  943. .vidioc_streamoff = vb2_ioctl_streamoff,
  944. };
  945. static const struct video_device sur40_video_device = {
  946. .name = DRIVER_LONG,
  947. .fops = &sur40_video_fops,
  948. .ioctl_ops = &sur40_video_ioctl_ops,
  949. .release = video_device_release_empty,
  950. .device_caps = V4L2_CAP_VIDEO_CAPTURE | V4L2_CAP_TOUCH |
  951. V4L2_CAP_READWRITE | V4L2_CAP_STREAMING,
  952. };
  953. /* USB-specific object needed to register this driver with the USB subsystem. */
  954. static struct usb_driver sur40_driver = {
  955. .name = DRIVER_SHORT,
  956. .probe = sur40_probe,
  957. .disconnect = sur40_disconnect,
  958. .id_table = sur40_table,
  959. };
  960. module_usb_driver(sur40_driver);
  961. MODULE_AUTHOR(DRIVER_AUTHOR);
  962. MODULE_DESCRIPTION(DRIVER_DESC);
  963. MODULE_LICENSE("GPL");