sur40.c 32 KB

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