1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24#include <linux/kernel.h>
25#include <linux/errno.h>
26#include <linux/delay.h>
27#include <linux/init.h>
28#include <linux/slab.h>
29#include <linux/module.h>
30#include <linux/completion.h>
31#include <linux/uaccess.h>
32#include <linux/usb.h>
33#include <linux/printk.h>
34#include <linux/input-polldev.h>
35#include <linux/input/mt.h>
36#include <linux/usb/input.h>
37#include <linux/videodev2.h>
38#include <media/v4l2-device.h>
39#include <media/v4l2-dev.h>
40#include <media/v4l2-ioctl.h>
41#include <media/videobuf2-dma-sg.h>
42
43
44struct sur40_header {
45
46 __le16 type;
47 __le16 count;
48
49 __le32 packet_id;
50
51 __le32 timestamp;
52 __le32 unknown;
53
54} __packed;
55
56struct sur40_blob {
57
58 __le16 blob_id;
59
60 u8 action;
61 u8 unknown;
62
63 __le16 bb_pos_x;
64 __le16 bb_pos_y;
65
66 __le16 bb_size_x;
67 __le16 bb_size_y;
68
69 __le16 pos_x;
70 __le16 pos_y;
71
72 __le16 ctr_x;
73 __le16 ctr_y;
74
75 __le16 axis_x;
76 __le16 axis_y;
77
78 __le32 angle;
79
80
81 __le32 area;
82
83 u8 padding[32];
84
85} __packed;
86
87
88struct sur40_data {
89 struct sur40_header header;
90 struct sur40_blob blobs[];
91} __packed;
92
93
94
95struct sur40_image_header {
96 __le32 magic;
97 __le32 packet_id;
98 __le32 size;
99 __le32 timestamp;
100 __le32 unknown;
101} __packed;
102
103
104#define DRIVER_SHORT "sur40"
105#define DRIVER_LONG "Samsung SUR40"
106#define DRIVER_AUTHOR "Florian 'floe' Echtler <floe@butterbrot.org>"
107#define DRIVER_DESC "Surface2.0/SUR40/PixelSense input driver"
108
109
110#define ID_MICROSOFT 0x045e
111#define ID_SUR40 0x0775
112
113
114#define SENSOR_RES_X 1920
115#define SENSOR_RES_Y 1080
116
117
118#define TOUCH_ENDPOINT 0x86
119
120
121#define VIDEO_ENDPOINT 0x82
122
123
124#define VIDEO_HEADER_MAGIC 0x46425553
125#define VIDEO_PACKET_SIZE 16384
126
127
128#define POLL_INTERVAL 10
129
130
131#define MAX_CONTACTS 64
132
133
134#define SUR40_GET_VERSION 0xb0
135#define SUR40_UNKNOWN1 0xb3
136#define SUR40_UNKNOWN2 0xc1
137
138#define SUR40_GET_STATE 0xc5
139#define SUR40_GET_SENSORS 0xb1
140
141
142struct sur40_state {
143
144 struct usb_device *usbdev;
145 struct device *dev;
146 struct input_polled_dev *input;
147
148 struct v4l2_device v4l2;
149 struct video_device vdev;
150 struct mutex lock;
151
152 struct vb2_queue queue;
153 struct vb2_alloc_ctx *alloc_ctx;
154 struct list_head buf_list;
155 spinlock_t qlock;
156 int sequence;
157
158 struct sur40_data *bulk_in_buffer;
159 size_t bulk_in_size;
160 u8 bulk_in_epaddr;
161
162 char phys[64];
163};
164
165struct sur40_buffer {
166 struct vb2_buffer vb;
167 struct list_head list;
168};
169
170
171static const struct video_device sur40_video_device;
172static const struct v4l2_pix_format sur40_video_format;
173static const struct vb2_queue sur40_queue;
174static void sur40_process_video(struct sur40_state *sur40);
175
176
177
178
179
180
181
182
183
184
185
186static int sur40_command(struct sur40_state *dev,
187 u8 command, u16 index, void *buffer, u16 size)
188{
189 return usb_control_msg(dev->usbdev, usb_rcvctrlpipe(dev->usbdev, 0),
190 command,
191 USB_TYPE_VENDOR | USB_RECIP_DEVICE | USB_DIR_IN,
192 0x00, index, buffer, size, 1000);
193}
194
195
196static int sur40_init(struct sur40_state *dev)
197{
198 int result;
199 u8 buffer[24];
200
201
202 result = sur40_command(dev, SUR40_GET_VERSION, 0x00, buffer, 12);
203 if (result < 0)
204 return result;
205
206 result = sur40_command(dev, SUR40_GET_VERSION, 0x01, buffer, 12);
207 if (result < 0)
208 return result;
209
210 result = sur40_command(dev, SUR40_GET_VERSION, 0x02, buffer, 12);
211 if (result < 0)
212 return result;
213
214 result = sur40_command(dev, SUR40_UNKNOWN2, 0x00, buffer, 24);
215 if (result < 0)
216 return result;
217
218 result = sur40_command(dev, SUR40_UNKNOWN1, 0x00, buffer, 5);
219 if (result < 0)
220 return result;
221
222 result = sur40_command(dev, SUR40_GET_VERSION, 0x03, buffer, 12);
223
224
225
226
227
228
229 return result;
230}
231
232
233
234
235
236
237static void sur40_open(struct input_polled_dev *polldev)
238{
239 struct sur40_state *sur40 = polldev->private;
240
241 dev_dbg(sur40->dev, "open\n");
242 sur40_init(sur40);
243}
244
245
246static void sur40_close(struct input_polled_dev *polldev)
247{
248 struct sur40_state *sur40 = polldev->private;
249
250 dev_dbg(sur40->dev, "close\n");
251
252
253
254
255}
256
257
258
259
260
261static void sur40_report_blob(struct sur40_blob *blob, struct input_dev *input)
262{
263 int wide, major, minor;
264
265 int bb_size_x = le16_to_cpu(blob->bb_size_x);
266 int bb_size_y = le16_to_cpu(blob->bb_size_y);
267
268 int pos_x = le16_to_cpu(blob->pos_x);
269 int pos_y = le16_to_cpu(blob->pos_y);
270
271 int ctr_x = le16_to_cpu(blob->ctr_x);
272 int ctr_y = le16_to_cpu(blob->ctr_y);
273
274 int slotnum = input_mt_get_slot_by_key(input, blob->blob_id);
275 if (slotnum < 0 || slotnum >= MAX_CONTACTS)
276 return;
277
278 input_mt_slot(input, slotnum);
279 input_mt_report_slot_state(input, MT_TOOL_FINGER, 1);
280 wide = (bb_size_x > bb_size_y);
281 major = max(bb_size_x, bb_size_y);
282 minor = min(bb_size_x, bb_size_y);
283
284 input_report_abs(input, ABS_MT_POSITION_X, pos_x);
285 input_report_abs(input, ABS_MT_POSITION_Y, pos_y);
286 input_report_abs(input, ABS_MT_TOOL_X, ctr_x);
287 input_report_abs(input, ABS_MT_TOOL_Y, ctr_y);
288
289
290 input_report_abs(input, ABS_MT_ORIENTATION, wide);
291 input_report_abs(input, ABS_MT_TOUCH_MAJOR, major);
292 input_report_abs(input, ABS_MT_TOUCH_MINOR, minor);
293}
294
295
296static void sur40_poll(struct input_polled_dev *polldev)
297{
298 struct sur40_state *sur40 = polldev->private;
299 struct input_dev *input = polldev->input;
300 int result, bulk_read, need_blobs, packet_blobs, i;
301 u32 uninitialized_var(packet_id);
302
303 struct sur40_header *header = &sur40->bulk_in_buffer->header;
304 struct sur40_blob *inblob = &sur40->bulk_in_buffer->blobs[0];
305
306 dev_dbg(sur40->dev, "poll\n");
307
308 need_blobs = -1;
309
310 do {
311
312
313 result = usb_bulk_msg(sur40->usbdev,
314 usb_rcvbulkpipe(sur40->usbdev, sur40->bulk_in_epaddr),
315 sur40->bulk_in_buffer, sur40->bulk_in_size,
316 &bulk_read, 1000);
317
318 dev_dbg(sur40->dev, "received %d bytes\n", bulk_read);
319
320 if (result < 0) {
321 dev_err(sur40->dev, "error in usb_bulk_read\n");
322 return;
323 }
324
325 result = bulk_read - sizeof(struct sur40_header);
326
327 if (result % sizeof(struct sur40_blob) != 0) {
328 dev_err(sur40->dev, "transfer size mismatch\n");
329 return;
330 }
331
332
333 if (need_blobs == -1) {
334 need_blobs = le16_to_cpu(header->count);
335 dev_dbg(sur40->dev, "need %d blobs\n", need_blobs);
336 packet_id = le32_to_cpu(header->packet_id);
337 }
338
339
340
341
342
343
344 if (packet_id != header->packet_id)
345 dev_warn(sur40->dev, "packet ID mismatch\n");
346
347 packet_blobs = result / sizeof(struct sur40_blob);
348 dev_dbg(sur40->dev, "received %d blobs\n", packet_blobs);
349
350
351 if (packet_blobs > need_blobs)
352 packet_blobs = need_blobs;
353
354 for (i = 0; i < packet_blobs; i++) {
355 need_blobs--;
356 dev_dbg(sur40->dev, "processing blob\n");
357 sur40_report_blob(&(inblob[i]), input);
358 }
359
360 } while (need_blobs > 0);
361
362 input_mt_sync_frame(input);
363 input_sync(input);
364
365 sur40_process_video(sur40);
366}
367
368
369static void sur40_process_video(struct sur40_state *sur40)
370{
371
372 struct sur40_image_header *img = (void *)(sur40->bulk_in_buffer);
373 struct sur40_buffer *new_buf;
374 struct usb_sg_request sgr;
375 struct sg_table *sgt;
376 int result, bulk_read;
377
378 if (!vb2_start_streaming_called(&sur40->queue))
379 return;
380
381
382 spin_lock(&sur40->qlock);
383 if (list_empty(&sur40->buf_list)) {
384 dev_dbg(sur40->dev, "buffer queue empty\n");
385 spin_unlock(&sur40->qlock);
386 return;
387 }
388 new_buf = list_entry(sur40->buf_list.next, struct sur40_buffer, list);
389 list_del(&new_buf->list);
390 spin_unlock(&sur40->qlock);
391
392
393 result = usb_bulk_msg(sur40->usbdev,
394 usb_rcvbulkpipe(sur40->usbdev, VIDEO_ENDPOINT),
395 sur40->bulk_in_buffer, sur40->bulk_in_size,
396 &bulk_read, 1000);
397
398 if (result < 0) {
399 dev_err(sur40->dev, "error in usb_bulk_read\n");
400 goto err_poll;
401 }
402
403 if (bulk_read != sizeof(struct sur40_image_header)) {
404 dev_err(sur40->dev, "received %d bytes (%zd expected)\n",
405 bulk_read, sizeof(struct sur40_image_header));
406 goto err_poll;
407 }
408
409 if (le32_to_cpu(img->magic) != VIDEO_HEADER_MAGIC) {
410 dev_err(sur40->dev, "image magic mismatch\n");
411 goto err_poll;
412 }
413
414 if (le32_to_cpu(img->size) != sur40_video_format.sizeimage) {
415 dev_err(sur40->dev, "image size mismatch\n");
416 goto err_poll;
417 }
418
419 sgt = vb2_dma_sg_plane_desc(&new_buf->vb, 0);
420
421 result = usb_sg_init(&sgr, sur40->usbdev,
422 usb_rcvbulkpipe(sur40->usbdev, VIDEO_ENDPOINT), 0,
423 sgt->sgl, sgt->nents, sur40_video_format.sizeimage, 0);
424 if (result < 0) {
425 dev_err(sur40->dev, "error %d in usb_sg_init\n", result);
426 goto err_poll;
427 }
428
429 usb_sg_wait(&sgr);
430 if (sgr.status < 0) {
431 dev_err(sur40->dev, "error %d in usb_sg_wait\n", sgr.status);
432 goto err_poll;
433 }
434
435
436 v4l2_get_timestamp(&new_buf->vb.v4l2_buf.timestamp);
437 new_buf->vb.v4l2_buf.sequence = sur40->sequence++;
438 new_buf->vb.v4l2_buf.field = V4L2_FIELD_NONE;
439 vb2_buffer_done(&new_buf->vb, VB2_BUF_STATE_DONE);
440 return;
441
442err_poll:
443 vb2_buffer_done(&new_buf->vb, VB2_BUF_STATE_ERROR);
444}
445
446
447static void sur40_input_setup(struct input_dev *input_dev)
448{
449 __set_bit(EV_KEY, input_dev->evbit);
450 __set_bit(EV_ABS, input_dev->evbit);
451
452 input_set_abs_params(input_dev, ABS_MT_POSITION_X,
453 0, SENSOR_RES_X, 0, 0);
454 input_set_abs_params(input_dev, ABS_MT_POSITION_Y,
455 0, SENSOR_RES_Y, 0, 0);
456
457 input_set_abs_params(input_dev, ABS_MT_TOOL_X,
458 0, SENSOR_RES_X, 0, 0);
459 input_set_abs_params(input_dev, ABS_MT_TOOL_Y,
460 0, SENSOR_RES_Y, 0, 0);
461
462
463
464 input_set_abs_params(input_dev, ABS_MT_TOUCH_MAJOR,
465 0, SENSOR_RES_X, 0, 0);
466 input_set_abs_params(input_dev, ABS_MT_TOUCH_MINOR,
467 0, SENSOR_RES_Y, 0, 0);
468
469 input_set_abs_params(input_dev, ABS_MT_ORIENTATION, 0, 1, 0, 0);
470
471 input_mt_init_slots(input_dev, MAX_CONTACTS,
472 INPUT_MT_DIRECT | INPUT_MT_DROP_UNUSED);
473}
474
475
476static int sur40_probe(struct usb_interface *interface,
477 const struct usb_device_id *id)
478{
479 struct usb_device *usbdev = interface_to_usbdev(interface);
480 struct sur40_state *sur40;
481 struct usb_host_interface *iface_desc;
482 struct usb_endpoint_descriptor *endpoint;
483 struct input_polled_dev *poll_dev;
484 int error;
485
486
487 iface_desc = &interface->altsetting[0];
488 if (iface_desc->desc.bInterfaceClass != 0xFF)
489 return -ENODEV;
490
491
492 endpoint = &iface_desc->endpoint[4].desc;
493 if (endpoint->bEndpointAddress != TOUCH_ENDPOINT)
494 return -ENODEV;
495
496
497 sur40 = kzalloc(sizeof(struct sur40_state), GFP_KERNEL);
498 if (!sur40)
499 return -ENOMEM;
500
501 poll_dev = input_allocate_polled_device();
502 if (!poll_dev) {
503 error = -ENOMEM;
504 goto err_free_dev;
505 }
506
507
508 INIT_LIST_HEAD(&sur40->buf_list);
509 spin_lock_init(&sur40->qlock);
510 mutex_init(&sur40->lock);
511
512
513 poll_dev->private = sur40;
514 poll_dev->poll_interval = POLL_INTERVAL;
515 poll_dev->open = sur40_open;
516 poll_dev->poll = sur40_poll;
517 poll_dev->close = sur40_close;
518
519
520 sur40_input_setup(poll_dev->input);
521
522 poll_dev->input->name = DRIVER_LONG;
523 usb_to_input_id(usbdev, &poll_dev->input->id);
524 usb_make_path(usbdev, sur40->phys, sizeof(sur40->phys));
525 strlcat(sur40->phys, "/input0", sizeof(sur40->phys));
526 poll_dev->input->phys = sur40->phys;
527 poll_dev->input->dev.parent = &interface->dev;
528
529 sur40->usbdev = usbdev;
530 sur40->dev = &interface->dev;
531 sur40->input = poll_dev;
532
533
534 sur40->bulk_in_size = usb_endpoint_maxp(endpoint);
535 sur40->bulk_in_epaddr = endpoint->bEndpointAddress;
536 sur40->bulk_in_buffer = kmalloc(sur40->bulk_in_size, GFP_KERNEL);
537 if (!sur40->bulk_in_buffer) {
538 dev_err(&interface->dev, "Unable to allocate input buffer.");
539 error = -ENOMEM;
540 goto err_free_polldev;
541 }
542
543
544 error = input_register_polled_device(poll_dev);
545 if (error) {
546 dev_err(&interface->dev,
547 "Unable to register polled input device.");
548 goto err_free_buffer;
549 }
550
551
552 snprintf(sur40->v4l2.name, sizeof(sur40->v4l2.name), "%s", DRIVER_LONG);
553 error = v4l2_device_register(sur40->dev, &sur40->v4l2);
554 if (error) {
555 dev_err(&interface->dev,
556 "Unable to register video master device.");
557 goto err_unreg_v4l2;
558 }
559
560
561 sur40->queue = sur40_queue;
562 sur40->queue.drv_priv = sur40;
563 sur40->queue.lock = &sur40->lock;
564
565
566 error = vb2_queue_init(&sur40->queue);
567 if (error)
568 goto err_unreg_v4l2;
569
570 sur40->alloc_ctx = vb2_dma_sg_init_ctx(sur40->dev);
571 if (IS_ERR(sur40->alloc_ctx)) {
572 dev_err(sur40->dev, "Can't allocate buffer context");
573 goto err_unreg_v4l2;
574 }
575
576 sur40->vdev = sur40_video_device;
577 sur40->vdev.v4l2_dev = &sur40->v4l2;
578 sur40->vdev.lock = &sur40->lock;
579 sur40->vdev.queue = &sur40->queue;
580 video_set_drvdata(&sur40->vdev, sur40);
581
582 error = video_register_device(&sur40->vdev, VFL_TYPE_GRABBER, -1);
583 if (error) {
584 dev_err(&interface->dev,
585 "Unable to register video subdevice.");
586 goto err_unreg_video;
587 }
588
589
590 usb_set_intfdata(interface, sur40);
591 dev_dbg(&interface->dev, "%s is now attached\n", DRIVER_DESC);
592
593 return 0;
594
595err_unreg_video:
596 video_unregister_device(&sur40->vdev);
597err_unreg_v4l2:
598 v4l2_device_unregister(&sur40->v4l2);
599err_free_buffer:
600 kfree(sur40->bulk_in_buffer);
601err_free_polldev:
602 input_free_polled_device(sur40->input);
603err_free_dev:
604 kfree(sur40);
605
606 return error;
607}
608
609
610static void sur40_disconnect(struct usb_interface *interface)
611{
612 struct sur40_state *sur40 = usb_get_intfdata(interface);
613
614 video_unregister_device(&sur40->vdev);
615 v4l2_device_unregister(&sur40->v4l2);
616 vb2_dma_sg_cleanup_ctx(sur40->alloc_ctx);
617
618 input_unregister_polled_device(sur40->input);
619 input_free_polled_device(sur40->input);
620 kfree(sur40->bulk_in_buffer);
621 kfree(sur40);
622
623 usb_set_intfdata(interface, NULL);
624 dev_dbg(&interface->dev, "%s is now disconnected\n", DRIVER_DESC);
625}
626
627
628
629
630
631
632
633
634static int sur40_queue_setup(struct vb2_queue *q, const struct v4l2_format *fmt,
635 unsigned int *nbuffers, unsigned int *nplanes,
636 unsigned int sizes[], void *alloc_ctxs[])
637{
638 struct sur40_state *sur40 = vb2_get_drv_priv(q);
639
640 if (q->num_buffers + *nbuffers < 3)
641 *nbuffers = 3 - q->num_buffers;
642
643 if (fmt && fmt->fmt.pix.sizeimage < sur40_video_format.sizeimage)
644 return -EINVAL;
645
646 *nplanes = 1;
647 sizes[0] = fmt ? fmt->fmt.pix.sizeimage : sur40_video_format.sizeimage;
648 alloc_ctxs[0] = sur40->alloc_ctx;
649
650 return 0;
651}
652
653
654
655
656
657static int sur40_buffer_prepare(struct vb2_buffer *vb)
658{
659 struct sur40_state *sur40 = vb2_get_drv_priv(vb->vb2_queue);
660 unsigned long size = sur40_video_format.sizeimage;
661
662 if (vb2_plane_size(vb, 0) < size) {
663 dev_err(&sur40->usbdev->dev, "buffer too small (%lu < %lu)\n",
664 vb2_plane_size(vb, 0), size);
665 return -EINVAL;
666 }
667
668 vb2_set_plane_payload(vb, 0, size);
669 return 0;
670}
671
672
673
674
675static void sur40_buffer_queue(struct vb2_buffer *vb)
676{
677 struct sur40_state *sur40 = vb2_get_drv_priv(vb->vb2_queue);
678 struct sur40_buffer *buf = (struct sur40_buffer *)vb;
679
680 spin_lock(&sur40->qlock);
681 list_add_tail(&buf->list, &sur40->buf_list);
682 spin_unlock(&sur40->qlock);
683}
684
685static void return_all_buffers(struct sur40_state *sur40,
686 enum vb2_buffer_state state)
687{
688 struct sur40_buffer *buf, *node;
689
690 spin_lock(&sur40->qlock);
691 list_for_each_entry_safe(buf, node, &sur40->buf_list, list) {
692 vb2_buffer_done(&buf->vb, state);
693 list_del(&buf->list);
694 }
695 spin_unlock(&sur40->qlock);
696}
697
698
699
700
701
702
703
704static int sur40_start_streaming(struct vb2_queue *vq, unsigned int count)
705{
706 struct sur40_state *sur40 = vb2_get_drv_priv(vq);
707
708 sur40->sequence = 0;
709 return 0;
710}
711
712
713
714
715
716static void sur40_stop_streaming(struct vb2_queue *vq)
717{
718 struct sur40_state *sur40 = vb2_get_drv_priv(vq);
719
720
721 return_all_buffers(sur40, VB2_BUF_STATE_ERROR);
722}
723
724
725static int sur40_vidioc_querycap(struct file *file, void *priv,
726 struct v4l2_capability *cap)
727{
728 struct sur40_state *sur40 = video_drvdata(file);
729
730 strlcpy(cap->driver, DRIVER_SHORT, sizeof(cap->driver));
731 strlcpy(cap->card, DRIVER_LONG, sizeof(cap->card));
732 usb_make_path(sur40->usbdev, cap->bus_info, sizeof(cap->bus_info));
733 cap->device_caps = V4L2_CAP_VIDEO_CAPTURE |
734 V4L2_CAP_READWRITE |
735 V4L2_CAP_STREAMING;
736 cap->capabilities = cap->device_caps | V4L2_CAP_DEVICE_CAPS;
737 return 0;
738}
739
740static int sur40_vidioc_enum_input(struct file *file, void *priv,
741 struct v4l2_input *i)
742{
743 if (i->index != 0)
744 return -EINVAL;
745 i->type = V4L2_INPUT_TYPE_CAMERA;
746 i->std = V4L2_STD_UNKNOWN;
747 strlcpy(i->name, "In-Cell Sensor", sizeof(i->name));
748 i->capabilities = 0;
749 return 0;
750}
751
752static int sur40_vidioc_s_input(struct file *file, void *priv, unsigned int i)
753{
754 return (i == 0) ? 0 : -EINVAL;
755}
756
757static int sur40_vidioc_g_input(struct file *file, void *priv, unsigned int *i)
758{
759 *i = 0;
760 return 0;
761}
762
763static int sur40_vidioc_fmt(struct file *file, void *priv,
764 struct v4l2_format *f)
765{
766 f->fmt.pix = sur40_video_format;
767 return 0;
768}
769
770static int sur40_vidioc_enum_fmt(struct file *file, void *priv,
771 struct v4l2_fmtdesc *f)
772{
773 if (f->index != 0)
774 return -EINVAL;
775 strlcpy(f->description, "8-bit greyscale", sizeof(f->description));
776 f->pixelformat = V4L2_PIX_FMT_GREY;
777 f->flags = 0;
778 return 0;
779}
780
781static const struct usb_device_id sur40_table[] = {
782 { USB_DEVICE(ID_MICROSOFT, ID_SUR40) },
783 { }
784};
785MODULE_DEVICE_TABLE(usb, sur40_table);
786
787
788static const struct vb2_ops sur40_queue_ops = {
789 .queue_setup = sur40_queue_setup,
790 .buf_prepare = sur40_buffer_prepare,
791 .buf_queue = sur40_buffer_queue,
792 .start_streaming = sur40_start_streaming,
793 .stop_streaming = sur40_stop_streaming,
794 .wait_prepare = vb2_ops_wait_prepare,
795 .wait_finish = vb2_ops_wait_finish,
796};
797
798static const struct vb2_queue sur40_queue = {
799 .type = V4L2_BUF_TYPE_VIDEO_CAPTURE,
800
801
802
803
804
805 .io_modes = VB2_MMAP | VB2_READ | VB2_DMABUF,
806 .buf_struct_size = sizeof(struct sur40_buffer),
807 .ops = &sur40_queue_ops,
808 .mem_ops = &vb2_dma_sg_memops,
809 .timestamp_flags = V4L2_BUF_FLAG_TIMESTAMP_MONOTONIC,
810 .min_buffers_needed = 3,
811};
812
813static const struct v4l2_file_operations sur40_video_fops = {
814 .owner = THIS_MODULE,
815 .open = v4l2_fh_open,
816 .release = vb2_fop_release,
817 .unlocked_ioctl = video_ioctl2,
818 .read = vb2_fop_read,
819 .mmap = vb2_fop_mmap,
820 .poll = vb2_fop_poll,
821};
822
823static const struct v4l2_ioctl_ops sur40_video_ioctl_ops = {
824
825 .vidioc_querycap = sur40_vidioc_querycap,
826
827 .vidioc_enum_fmt_vid_cap = sur40_vidioc_enum_fmt,
828 .vidioc_try_fmt_vid_cap = sur40_vidioc_fmt,
829 .vidioc_s_fmt_vid_cap = sur40_vidioc_fmt,
830 .vidioc_g_fmt_vid_cap = sur40_vidioc_fmt,
831
832 .vidioc_enum_input = sur40_vidioc_enum_input,
833 .vidioc_g_input = sur40_vidioc_g_input,
834 .vidioc_s_input = sur40_vidioc_s_input,
835
836 .vidioc_reqbufs = vb2_ioctl_reqbufs,
837 .vidioc_create_bufs = vb2_ioctl_create_bufs,
838 .vidioc_querybuf = vb2_ioctl_querybuf,
839 .vidioc_qbuf = vb2_ioctl_qbuf,
840 .vidioc_dqbuf = vb2_ioctl_dqbuf,
841 .vidioc_expbuf = vb2_ioctl_expbuf,
842
843 .vidioc_streamon = vb2_ioctl_streamon,
844 .vidioc_streamoff = vb2_ioctl_streamoff,
845};
846
847static const struct video_device sur40_video_device = {
848 .name = DRIVER_LONG,
849 .fops = &sur40_video_fops,
850 .ioctl_ops = &sur40_video_ioctl_ops,
851 .release = video_device_release_empty,
852};
853
854static const struct v4l2_pix_format sur40_video_format = {
855 .pixelformat = V4L2_PIX_FMT_GREY,
856 .width = SENSOR_RES_X / 2,
857 .height = SENSOR_RES_Y / 2,
858 .field = V4L2_FIELD_NONE,
859 .colorspace = V4L2_COLORSPACE_SRGB,
860 .bytesperline = SENSOR_RES_X / 2,
861 .sizeimage = (SENSOR_RES_X/2) * (SENSOR_RES_Y/2),
862};
863
864
865static struct usb_driver sur40_driver = {
866 .name = DRIVER_SHORT,
867 .probe = sur40_probe,
868 .disconnect = sur40_disconnect,
869 .id_table = sur40_table,
870};
871
872module_usb_driver(sur40_driver);
873
874MODULE_AUTHOR(DRIVER_AUTHOR);
875MODULE_DESCRIPTION(DRIVER_DESC);
876MODULE_LICENSE("GPL");
877