sur40.c 32 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190
  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 <[email protected]>
  6. *
  7. * Derived from the USB Skeleton driver 1.1,
  8. * Copyright (c) 2003 Greg Kroah-Hartman ([email protected])
  9. *
  10. * and from the Apple USB BCM5974 multitouch driver,
  11. * Copyright (c) 2008 Henrik Rydberg ([email protected])
  12. *
  13. * and from the generic hid-multitouch driver,
  14. * Copyright (c) 2010-2012 Stephane Chatty <[email protected]>
  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 <[email protected]>"
  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, 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(sizeof(struct sur40_state), GFP_KERNEL);
  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. if (q->num_buffers + *nbuffers < 3)
  683. *nbuffers = 3 - q->num_buffers;
  684. if (*nplanes)
  685. return sizes[0] < sur40->pix_fmt.sizeimage ? -EINVAL : 0;
  686. *nplanes = 1;
  687. sizes[0] = sur40->pix_fmt.sizeimage;
  688. return 0;
  689. }
  690. /*
  691. * Prepare the buffer for queueing to the DMA engine: check and set the
  692. * payload size.
  693. */
  694. static int sur40_buffer_prepare(struct vb2_buffer *vb)
  695. {
  696. struct sur40_state *sur40 = vb2_get_drv_priv(vb->vb2_queue);
  697. unsigned long size = sur40->pix_fmt.sizeimage;
  698. if (vb2_plane_size(vb, 0) < size) {
  699. dev_err(&sur40->usbdev->dev, "buffer too small (%lu < %lu)\n",
  700. vb2_plane_size(vb, 0), size);
  701. return -EINVAL;
  702. }
  703. vb2_set_plane_payload(vb, 0, size);
  704. return 0;
  705. }
  706. /*
  707. * Queue this buffer to the DMA engine.
  708. */
  709. static void sur40_buffer_queue(struct vb2_buffer *vb)
  710. {
  711. struct sur40_state *sur40 = vb2_get_drv_priv(vb->vb2_queue);
  712. struct sur40_buffer *buf = (struct sur40_buffer *)vb;
  713. spin_lock(&sur40->qlock);
  714. list_add_tail(&buf->list, &sur40->buf_list);
  715. spin_unlock(&sur40->qlock);
  716. }
  717. static void return_all_buffers(struct sur40_state *sur40,
  718. enum vb2_buffer_state state)
  719. {
  720. struct sur40_buffer *buf, *node;
  721. spin_lock(&sur40->qlock);
  722. list_for_each_entry_safe(buf, node, &sur40->buf_list, list) {
  723. vb2_buffer_done(&buf->vb.vb2_buf, state);
  724. list_del(&buf->list);
  725. }
  726. spin_unlock(&sur40->qlock);
  727. }
  728. /*
  729. * Start streaming. First check if the minimum number of buffers have been
  730. * queued. If not, then return -ENOBUFS and the vb2 framework will call
  731. * this function again the next time a buffer has been queued until enough
  732. * buffers are available to actually start the DMA engine.
  733. */
  734. static int sur40_start_streaming(struct vb2_queue *vq, unsigned int count)
  735. {
  736. struct sur40_state *sur40 = vb2_get_drv_priv(vq);
  737. sur40->sequence = 0;
  738. return 0;
  739. }
  740. /*
  741. * Stop the DMA engine. Any remaining buffers in the DMA queue are dequeued
  742. * and passed on to the vb2 framework marked as STATE_ERROR.
  743. */
  744. static void sur40_stop_streaming(struct vb2_queue *vq)
  745. {
  746. struct sur40_state *sur40 = vb2_get_drv_priv(vq);
  747. vb2_wait_for_all_buffers(vq);
  748. sur40->sequence = -1;
  749. /* Release all active buffers */
  750. return_all_buffers(sur40, VB2_BUF_STATE_ERROR);
  751. }
  752. /* V4L ioctl */
  753. static int sur40_vidioc_querycap(struct file *file, void *priv,
  754. struct v4l2_capability *cap)
  755. {
  756. struct sur40_state *sur40 = video_drvdata(file);
  757. strscpy(cap->driver, DRIVER_SHORT, sizeof(cap->driver));
  758. strscpy(cap->card, DRIVER_LONG, sizeof(cap->card));
  759. usb_make_path(sur40->usbdev, cap->bus_info, sizeof(cap->bus_info));
  760. return 0;
  761. }
  762. static int sur40_vidioc_enum_input(struct file *file, void *priv,
  763. struct v4l2_input *i)
  764. {
  765. if (i->index != 0)
  766. return -EINVAL;
  767. i->type = V4L2_INPUT_TYPE_TOUCH;
  768. i->std = V4L2_STD_UNKNOWN;
  769. strscpy(i->name, "In-Cell Sensor", sizeof(i->name));
  770. i->capabilities = 0;
  771. return 0;
  772. }
  773. static int sur40_vidioc_s_input(struct file *file, void *priv, unsigned int i)
  774. {
  775. return (i == 0) ? 0 : -EINVAL;
  776. }
  777. static int sur40_vidioc_g_input(struct file *file, void *priv, unsigned int *i)
  778. {
  779. *i = 0;
  780. return 0;
  781. }
  782. static int sur40_vidioc_try_fmt(struct file *file, void *priv,
  783. struct v4l2_format *f)
  784. {
  785. switch (f->fmt.pix.pixelformat) {
  786. case V4L2_PIX_FMT_GREY:
  787. f->fmt.pix = sur40_pix_format[1];
  788. break;
  789. default:
  790. f->fmt.pix = sur40_pix_format[0];
  791. break;
  792. }
  793. return 0;
  794. }
  795. static int sur40_vidioc_s_fmt(struct file *file, void *priv,
  796. struct v4l2_format *f)
  797. {
  798. struct sur40_state *sur40 = video_drvdata(file);
  799. switch (f->fmt.pix.pixelformat) {
  800. case V4L2_PIX_FMT_GREY:
  801. sur40->pix_fmt = sur40_pix_format[1];
  802. break;
  803. default:
  804. sur40->pix_fmt = sur40_pix_format[0];
  805. break;
  806. }
  807. f->fmt.pix = sur40->pix_fmt;
  808. return 0;
  809. }
  810. static int sur40_vidioc_g_fmt(struct file *file, void *priv,
  811. struct v4l2_format *f)
  812. {
  813. struct sur40_state *sur40 = video_drvdata(file);
  814. f->fmt.pix = sur40->pix_fmt;
  815. return 0;
  816. }
  817. static int sur40_s_ctrl(struct v4l2_ctrl *ctrl)
  818. {
  819. struct sur40_state *sur40 = container_of(ctrl->handler,
  820. struct sur40_state, hdl);
  821. u8 value = sur40->vsvideo;
  822. switch (ctrl->id) {
  823. case V4L2_CID_BRIGHTNESS:
  824. sur40_set_irlevel(sur40, ctrl->val);
  825. break;
  826. case V4L2_CID_CONTRAST:
  827. value = (value & 0x0f) | (ctrl->val << 4);
  828. sur40_set_vsvideo(sur40, value);
  829. break;
  830. case V4L2_CID_GAIN:
  831. value = (value & 0xf0) | (ctrl->val);
  832. sur40_set_vsvideo(sur40, value);
  833. break;
  834. case V4L2_CID_BACKLIGHT_COMPENSATION:
  835. sur40_set_preprocessor(sur40, ctrl->val);
  836. break;
  837. }
  838. return 0;
  839. }
  840. static int sur40_ioctl_parm(struct file *file, void *priv,
  841. struct v4l2_streamparm *p)
  842. {
  843. if (p->type != V4L2_BUF_TYPE_VIDEO_CAPTURE)
  844. return -EINVAL;
  845. p->parm.capture.capability = V4L2_CAP_TIMEPERFRAME;
  846. p->parm.capture.timeperframe.numerator = 1;
  847. p->parm.capture.timeperframe.denominator = 60;
  848. p->parm.capture.readbuffers = 3;
  849. return 0;
  850. }
  851. static int sur40_vidioc_enum_fmt(struct file *file, void *priv,
  852. struct v4l2_fmtdesc *f)
  853. {
  854. if (f->index >= ARRAY_SIZE(sur40_pix_format))
  855. return -EINVAL;
  856. f->pixelformat = sur40_pix_format[f->index].pixelformat;
  857. f->flags = 0;
  858. return 0;
  859. }
  860. static int sur40_vidioc_enum_framesizes(struct file *file, void *priv,
  861. struct v4l2_frmsizeenum *f)
  862. {
  863. struct sur40_state *sur40 = video_drvdata(file);
  864. if ((f->index != 0) || ((f->pixel_format != V4L2_TCH_FMT_TU08)
  865. && (f->pixel_format != V4L2_PIX_FMT_GREY)))
  866. return -EINVAL;
  867. f->type = V4L2_FRMSIZE_TYPE_DISCRETE;
  868. f->discrete.width = sur40->pix_fmt.width;
  869. f->discrete.height = sur40->pix_fmt.height;
  870. return 0;
  871. }
  872. static int sur40_vidioc_enum_frameintervals(struct file *file, void *priv,
  873. struct v4l2_frmivalenum *f)
  874. {
  875. struct sur40_state *sur40 = video_drvdata(file);
  876. if ((f->index > 0) || ((f->pixel_format != V4L2_TCH_FMT_TU08)
  877. && (f->pixel_format != V4L2_PIX_FMT_GREY))
  878. || (f->width != sur40->pix_fmt.width)
  879. || (f->height != sur40->pix_fmt.height))
  880. return -EINVAL;
  881. f->type = V4L2_FRMIVAL_TYPE_DISCRETE;
  882. f->discrete.denominator = 60;
  883. f->discrete.numerator = 1;
  884. return 0;
  885. }
  886. static const struct usb_device_id sur40_table[] = {
  887. { USB_DEVICE(ID_MICROSOFT, ID_SUR40) }, /* Samsung SUR40 */
  888. { } /* terminating null entry */
  889. };
  890. MODULE_DEVICE_TABLE(usb, sur40_table);
  891. /* V4L2 structures */
  892. static const struct vb2_ops sur40_queue_ops = {
  893. .queue_setup = sur40_queue_setup,
  894. .buf_prepare = sur40_buffer_prepare,
  895. .buf_queue = sur40_buffer_queue,
  896. .start_streaming = sur40_start_streaming,
  897. .stop_streaming = sur40_stop_streaming,
  898. .wait_prepare = vb2_ops_wait_prepare,
  899. .wait_finish = vb2_ops_wait_finish,
  900. };
  901. static const struct vb2_queue sur40_queue = {
  902. .type = V4L2_BUF_TYPE_VIDEO_CAPTURE,
  903. /*
  904. * VB2_USERPTR in currently not enabled: passing a user pointer to
  905. * dma-sg will result in segment sizes that are not a multiple of
  906. * 512 bytes, which is required by the host controller.
  907. */
  908. .io_modes = VB2_MMAP | VB2_READ | VB2_DMABUF,
  909. .buf_struct_size = sizeof(struct sur40_buffer),
  910. .ops = &sur40_queue_ops,
  911. .mem_ops = &vb2_dma_sg_memops,
  912. .timestamp_flags = V4L2_BUF_FLAG_TIMESTAMP_MONOTONIC,
  913. .min_buffers_needed = 3,
  914. };
  915. static const struct v4l2_file_operations sur40_video_fops = {
  916. .owner = THIS_MODULE,
  917. .open = v4l2_fh_open,
  918. .release = vb2_fop_release,
  919. .unlocked_ioctl = video_ioctl2,
  920. .read = vb2_fop_read,
  921. .mmap = vb2_fop_mmap,
  922. .poll = vb2_fop_poll,
  923. };
  924. static const struct v4l2_ioctl_ops sur40_video_ioctl_ops = {
  925. .vidioc_querycap = sur40_vidioc_querycap,
  926. .vidioc_enum_fmt_vid_cap = sur40_vidioc_enum_fmt,
  927. .vidioc_try_fmt_vid_cap = sur40_vidioc_try_fmt,
  928. .vidioc_s_fmt_vid_cap = sur40_vidioc_s_fmt,
  929. .vidioc_g_fmt_vid_cap = sur40_vidioc_g_fmt,
  930. .vidioc_enum_framesizes = sur40_vidioc_enum_framesizes,
  931. .vidioc_enum_frameintervals = sur40_vidioc_enum_frameintervals,
  932. .vidioc_g_parm = sur40_ioctl_parm,
  933. .vidioc_s_parm = sur40_ioctl_parm,
  934. .vidioc_enum_input = sur40_vidioc_enum_input,
  935. .vidioc_g_input = sur40_vidioc_g_input,
  936. .vidioc_s_input = sur40_vidioc_s_input,
  937. .vidioc_reqbufs = vb2_ioctl_reqbufs,
  938. .vidioc_create_bufs = vb2_ioctl_create_bufs,
  939. .vidioc_querybuf = vb2_ioctl_querybuf,
  940. .vidioc_qbuf = vb2_ioctl_qbuf,
  941. .vidioc_dqbuf = vb2_ioctl_dqbuf,
  942. .vidioc_expbuf = vb2_ioctl_expbuf,
  943. .vidioc_streamon = vb2_ioctl_streamon,
  944. .vidioc_streamoff = vb2_ioctl_streamoff,
  945. };
  946. static const struct video_device sur40_video_device = {
  947. .name = DRIVER_LONG,
  948. .fops = &sur40_video_fops,
  949. .ioctl_ops = &sur40_video_ioctl_ops,
  950. .release = video_device_release_empty,
  951. .device_caps = V4L2_CAP_VIDEO_CAPTURE | V4L2_CAP_TOUCH |
  952. V4L2_CAP_READWRITE | V4L2_CAP_STREAMING,
  953. };
  954. /* USB-specific object needed to register this driver with the USB subsystem. */
  955. static struct usb_driver sur40_driver = {
  956. .name = DRIVER_SHORT,
  957. .probe = sur40_probe,
  958. .disconnect = sur40_disconnect,
  959. .id_table = sur40_table,
  960. };
  961. module_usb_driver(sur40_driver);
  962. MODULE_AUTHOR(DRIVER_AUTHOR);
  963. MODULE_DESCRIPTION(DRIVER_DESC);
  964. MODULE_LICENSE("GPL");