3 * Copyright (C) 2008-2009 QUALCOMM Incorporated.
7 #include <linux/workqueue.h>
8 #include <linux/delay.h>
9 #include <linux/types.h>
10 #include <linux/list.h>
11 #include <linux/ioctl.h>
12 #include <linux/spinlock.h>
13 #include <linux/videodev2.h>
14 #include <linux/proc_fs.h>
15 #include <media/v4l2-dev.h>
16 #include <media/msm_camera.h>
17 #include <mach/camera.h>
18 #include <media/v4l2-ioctl.h>
19 /*#include <linux/platform_device.h>*/
21 #define MSM_V4L2_START_SNAPSHOT _IOWR('V', BASE_VIDIOC_PRIVATE+1, \
24 #define MSM_V4L2_GET_PICTURE _IOWR('V', BASE_VIDIOC_PRIVATE+2, \
27 #define MSM_V4L2_DEVICE_NAME "msm_v4l2"
29 #define MSM_V4L2_PROC_NAME "msm_v4l2"
31 #define MSM_V4L2_DEVNUM_MPEG2 0
32 #define MSM_V4L2_DEVNUM_YUV 20
34 /* HVGA-P (portrait) and HVGA-L (landscape) */
35 #define MSM_V4L2_WIDTH 480
36 #define MSM_V4L2_HEIGHT 320
39 #define D(fmt, args...) printk(KERN_INFO "msm_v4l2: " fmt, ##args)
41 #define D(fmt, args...) do {} while (0)
44 #define PREVIEW_FRAMES_NUM 4
46 struct msm_v4l2_device
{
47 struct list_head read_queue
;
48 struct v4l2_format current_cap_format
;
49 struct v4l2_format current_pix_format
;
50 struct video_device
*pvdev
;
51 struct msm_v4l2_driver
*drv
;
54 spinlock_t read_queue_lock
;
57 static struct msm_v4l2_device
*g_pmsm_v4l2_dev
;
60 static DEFINE_MUTEX(msm_v4l2_opencnt_lock
);
62 static int msm_v4l2_open(struct file
*f
)
66 mutex_lock(&msm_v4l2_opencnt_lock
);
67 if (!g_pmsm_v4l2_dev
->opencnt
) {
68 rc
= g_pmsm_v4l2_dev
->drv
->open(
69 g_pmsm_v4l2_dev
->drv
->sync
,
72 g_pmsm_v4l2_dev
->opencnt
++;
73 mutex_unlock(&msm_v4l2_opencnt_lock
);
77 static int msm_v4l2_release(struct file
*f
)
81 mutex_lock(&msm_v4l2_opencnt_lock
);
82 if (!g_pmsm_v4l2_dev
->opencnt
) {
83 g_pmsm_v4l2_dev
->opencnt
--;
84 if (!g_pmsm_v4l2_dev
->opencnt
) {
85 rc
= g_pmsm_v4l2_dev
->drv
->release(
86 g_pmsm_v4l2_dev
->drv
->sync
);
89 mutex_unlock(&msm_v4l2_opencnt_lock
);
93 static unsigned int msm_v4l2_poll(struct file
*f
, struct poll_table_struct
*w
)
95 return g_pmsm_v4l2_dev
->drv
->drv_poll(g_pmsm_v4l2_dev
->drv
->sync
, f
, w
);
98 static long msm_v4l2_ioctl(struct file
*filep
,
99 unsigned int cmd
, unsigned long arg
)
101 struct msm_ctrl_cmd
*ctrlcmd
;
103 D("msm_v4l2_ioctl, cmd = %d, %d\n", cmd
, __LINE__
);
106 case MSM_V4L2_START_SNAPSHOT
:
108 ctrlcmd
= kmalloc(sizeof(struct msm_ctrl_cmd
), GFP_ATOMIC
);
110 CDBG("msm_v4l2_ioctl: cannot allocate buffer\n");
115 ctrlcmd
->value
= NULL
;
116 ctrlcmd
->timeout_ms
= 10000;
118 D("msm_v4l2_ioctl, MSM_V4L2_START_SNAPSHOT v4l2 ioctl %d\n",
120 ctrlcmd
->type
= MSM_V4L2_SNAPSHOT
;
121 return g_pmsm_v4l2_dev
->drv
->ctrl(g_pmsm_v4l2_dev
->drv
->sync
,
124 case MSM_V4L2_GET_PICTURE
:
125 D("msm_v4l2_ioctl, MSM_V4L2_GET_PICTURE v4l2 ioctl %d\n", cmd
);
126 ctrlcmd
= (struct msm_ctrl_cmd
*)arg
;
127 return g_pmsm_v4l2_dev
->drv
->get_pict(
128 g_pmsm_v4l2_dev
->drv
->sync
, ctrlcmd
);
131 D("msm_v4l2_ioctl, standard v4l2 ioctl %d\n", cmd
);
132 return video_ioctl2(filep
, cmd
, arg
);
136 static void msm_v4l2_release_dev(struct video_device
*d
)
141 static int msm_v4l2_querycap(struct file
*f
,
142 void *pctx
, struct v4l2_capability
*pcaps
)
145 strncpy(pcaps
->driver
, MSM_APPS_ID_V4L2
, sizeof(pcaps
->driver
));
147 MSM_V4L2_DEVICE_NAME
, sizeof(pcaps
->card
));
148 pcaps
->capabilities
= V4L2_CAP_VIDEO_CAPTURE
| V4L2_CAP_STREAMING
;
152 static int msm_v4l2_s_std(struct file
*f
, void *pctx
, v4l2_std_id
*pnorm
)
158 static int msm_v4l2_queryctrl(struct file
*f
,
159 void *pctx
, struct v4l2_queryctrl
*pqctrl
)
162 struct msm_ctrl_cmd
*ctrlcmd
;
166 ctrlcmd
= kmalloc(sizeof(struct msm_ctrl_cmd
), GFP_ATOMIC
);
168 CDBG("msm_v4l2_queryctrl: cannot allocate buffer\n");
172 ctrlcmd
->type
= MSM_V4L2_QUERY_CTRL
;
173 ctrlcmd
->length
= sizeof(struct v4l2_queryctrl
);
174 ctrlcmd
->value
= pqctrl
;
175 ctrlcmd
->timeout_ms
= 10000;
177 rc
= g_pmsm_v4l2_dev
->drv
->ctrl(g_pmsm_v4l2_dev
->drv
->sync
, ctrlcmd
);
181 return ctrlcmd
->status
;
184 static int msm_v4l2_g_ctrl(struct file
*f
, void *pctx
, struct v4l2_control
*c
)
187 struct msm_ctrl_cmd
*ctrlcmd
;
191 ctrlcmd
= kmalloc(sizeof(struct msm_ctrl_cmd
), GFP_ATOMIC
);
193 CDBG("msm_v4l2_g_ctrl: cannot allocate buffer\n");
197 ctrlcmd
->type
= MSM_V4L2_GET_CTRL
;
198 ctrlcmd
->length
= sizeof(struct v4l2_control
);
200 ctrlcmd
->timeout_ms
= 10000;
202 rc
= g_pmsm_v4l2_dev
->drv
->ctrl(g_pmsm_v4l2_dev
->drv
->sync
, ctrlcmd
);
206 return ctrlcmd
->status
;
209 static int msm_v4l2_s_ctrl(struct file
*f
, void *pctx
, struct v4l2_control
*c
)
212 struct msm_ctrl_cmd
*ctrlcmd
;
214 ctrlcmd
= kmalloc(sizeof(struct msm_ctrl_cmd
), GFP_ATOMIC
);
216 CDBG("msm_v4l2_s_ctrl: cannot allocate buffer\n");
220 ctrlcmd
->type
= MSM_V4L2_SET_CTRL
;
221 ctrlcmd
->length
= sizeof(struct v4l2_control
);
223 ctrlcmd
->timeout_ms
= 10000;
227 rc
= g_pmsm_v4l2_dev
->drv
->ctrl(g_pmsm_v4l2_dev
->drv
->sync
, ctrlcmd
);
231 return ctrlcmd
->status
;
234 static int msm_v4l2_reqbufs(struct file
*f
,
235 void *pctx
, struct v4l2_requestbuffers
*b
)
241 static int msm_v4l2_querybuf(struct file
*f
, void *pctx
, struct v4l2_buffer
*pb
)
243 struct msm_pmem_info pmem_buf
;
250 /* FIXME: g_pmsm_v4l2_dev->current_pix_format.fmt.pix.width; */
252 /* FIXME: g_pmsm_v4l2_dev->current_pix_format.fmt.pix.height; */
255 D("%s: width = %d, height = %d\n", __func__
, width
, height
);
257 y_size
= width
* height
;
261 __u32 y_pad
= pb
->bytesused
% 4;
263 /* V4L2 videodev will do the copy_from_user. */
265 memset(&pmem_buf
, 0, sizeof(struct msm_pmem_info
));
266 pmem_buf
.type
= MSM_PMEM_OUTPUT2
;
267 pmem_buf
.vaddr
= (void *)pb
->m
.userptr
;
269 pmem_buf
.fd
= (int)pb
->reserved
;
270 /* pmem_buf.cbcr_off = (y_size + y_pad); */
271 pmem_buf
.cbcr_off
= (pb
->bytesused
+ y_pad
);
273 g_pmsm_v4l2_dev
->drv
->reg_pmem(g_pmsm_v4l2_dev
->drv
->sync
, &pmem_buf
);
278 static int msm_v4l2_qbuf(struct file
*f
, void *pctx
, struct v4l2_buffer
*pb
)
289 struct msm_pmem_info meminfo
;
290 struct msm_frame frame
;
293 if ((pb
->flags
>> 16) & 0x0001) {
294 /* this is for previwe */
299 /* V4L2 videodev will do the copy_from_user. */
300 D("%s: width = %d, height = %d\n", __func__
, width
, height
);
301 y_size
= width
* height
;
305 y_pad
= pb
->bytesused
% 4;
307 if (pb
->type
== V4L2_BUF_TYPE_PRIVATE
) {
308 /* this qbuf is actually for releasing */
310 frame
.buffer
= pb
->m
.userptr
;
312 /* frame.cbcr_off = (y_size + y_pad); */
313 frame
.cbcr_off
= (pb
->bytesused
+ y_pad
);
314 frame
.fd
= pb
->reserved
;
316 D("V4L2_BUF_TYPE_PRIVATE: pb->bytesused = %d \n",
319 g_pmsm_v4l2_dev
->drv
->put_frame(
320 g_pmsm_v4l2_dev
->drv
->sync
,
326 D("V4L2_BUF_TYPE_VIDEO_CAPTURE: pb->bytesused = %d \n",
329 meminfo
.type
= MSM_PMEM_OUTPUT2
;
330 meminfo
.fd
= (int)pb
->reserved
;
331 meminfo
.vaddr
= (void *)pb
->m
.userptr
;
333 /* meminfo.cbcr_off = (y_size + y_pad); */
334 meminfo
.cbcr_off
= (pb
->bytesused
+ y_pad
);
335 if (cnt
== PREVIEW_FRAMES_NUM
- 1)
340 g_pmsm_v4l2_dev
->drv
->reg_pmem(g_pmsm_v4l2_dev
->drv
->sync
,
342 } else if ((pb
->flags
) & 0x0001) {
343 /* this is for snapshot */
347 if ((pb
->flags
>> 8) & 0x01) {
349 y_size
= pb
->bytesused
;
351 meminfo
.type
= MSM_PMEM_THUMBAIL
;
352 } else if ((pb
->flags
>> 9) & 0x01) {
354 y_size
= pb
->bytesused
;
356 meminfo
.type
= MSM_PMEM_MAINIMG
;
361 meminfo
.fd
= (int)pb
->reserved
;
362 meminfo
.vaddr
= (void *)pb
->m
.userptr
;
364 /* meminfo.cbcr_off = (y_size + y_pad); */
365 meminfo
.cbcr_off
= (y_size
+ y_pad
);
367 g_pmsm_v4l2_dev
->drv
->reg_pmem(g_pmsm_v4l2_dev
->drv
->sync
,
374 static int msm_v4l2_dqbuf(struct file
*f
, void *pctx
, struct v4l2_buffer
*pb
)
376 struct msm_frame frame
;
379 /* V4L2 videodev will do the copy_to_user. */
380 if (pb
->type
== V4L2_BUF_TYPE_VIDEO_CAPTURE
) {
382 D("%s, %d\n", __func__
, __LINE__
);
384 g_pmsm_v4l2_dev
->drv
->get_frame(
385 g_pmsm_v4l2_dev
->drv
->sync
,
388 pb
->type
= V4L2_BUF_TYPE_VIDEO_CAPTURE
;
389 pb
->m
.userptr
= (unsigned long)frame
.buffer
; /* FIXME */
390 pb
->reserved
= (int)frame
.fd
;
391 /* pb->length = (int)frame.cbcr_off; */
393 pb
->bytesused
= frame
.cbcr_off
;
395 } else if (pb
->type
== V4L2_BUF_TYPE_PRIVATE
) {
396 __u32 y_pad
= pb
->bytesused
% 4;
398 frame
.buffer
= pb
->m
.userptr
;
400 /* frame.cbcr_off = (y_size + y_pad); */
401 frame
.cbcr_off
= (pb
->bytesused
+ y_pad
);
402 frame
.fd
= pb
->reserved
;
404 g_pmsm_v4l2_dev
->drv
->put_frame(
405 g_pmsm_v4l2_dev
->drv
->sync
,
412 static int msm_v4l2_streamon(struct file
*f
, void *pctx
, enum v4l2_buf_type i
)
414 struct msm_ctrl_cmd
*ctrlcmd
;
416 ctrlcmd
= kmalloc(sizeof(struct msm_ctrl_cmd
), GFP_ATOMIC
);
418 CDBG("msm_v4l2_s_fmt_cap: cannot allocate buffer\n");
422 ctrlcmd
->type
= MSM_V4L2_STREAM_ON
;
423 ctrlcmd
->timeout_ms
= 10000;
425 ctrlcmd
->value
= NULL
;
429 g_pmsm_v4l2_dev
->drv
->ctrl(
430 g_pmsm_v4l2_dev
->drv
->sync
,
433 D("%s after drv->ctrl \n", __func__
);
438 static int msm_v4l2_streamoff(struct file
*f
, void *pctx
, enum v4l2_buf_type i
)
440 struct msm_ctrl_cmd
*ctrlcmd
;
442 ctrlcmd
= kmalloc(sizeof(struct msm_ctrl_cmd
), GFP_ATOMIC
);
444 CDBG("msm_v4l2_s_fmt_cap: cannot allocate buffer\n");
448 ctrlcmd
->type
= MSM_V4L2_STREAM_OFF
;
449 ctrlcmd
->timeout_ms
= 10000;
451 ctrlcmd
->value
= NULL
;
456 g_pmsm_v4l2_dev
->drv
->ctrl(
457 g_pmsm_v4l2_dev
->drv
->sync
,
463 static int msm_v4l2_enum_fmt_overlay(struct file
*f
,
464 void *pctx
, struct v4l2_fmtdesc
*pfmtdesc
)
470 static int msm_v4l2_enum_fmt_cap(struct file
*f
,
471 void *pctx
, struct v4l2_fmtdesc
*pfmtdesc
)
475 switch (pfmtdesc
->index
) {
477 pfmtdesc
->type
= V4L2_BUF_TYPE_VIDEO_CAPTURE
;
479 strncpy(pfmtdesc
->description
, "YUV 4:2:0",
480 sizeof(pfmtdesc
->description
));
481 pfmtdesc
->pixelformat
= V4L2_PIX_FMT_YVU420
;
490 static int msm_v4l2_g_fmt_cap(struct file
*f
,
491 void *pctx
, struct v4l2_format
*pfmt
)
494 pfmt
->type
= V4L2_BUF_TYPE_VIDEO_CAPTURE
;
495 pfmt
->fmt
.pix
.width
= MSM_V4L2_WIDTH
;
496 pfmt
->fmt
.pix
.height
= MSM_V4L2_HEIGHT
;
497 pfmt
->fmt
.pix
.pixelformat
= V4L2_PIX_FMT_YVU420
;
498 pfmt
->fmt
.pix
.field
= V4L2_FIELD_ANY
;
499 pfmt
->fmt
.pix
.bytesperline
= 0;
500 pfmt
->fmt
.pix
.sizeimage
= 0;
501 pfmt
->fmt
.pix
.colorspace
= V4L2_COLORSPACE_JPEG
;
502 pfmt
->fmt
.pix
.priv
= 0;
506 static int msm_v4l2_s_fmt_cap(struct file
*f
,
507 void *pctx
, struct v4l2_format
*pfmt
)
509 struct msm_ctrl_cmd
*ctrlcmd
;
513 ctrlcmd
= kmalloc(sizeof(struct msm_ctrl_cmd
), GFP_ATOMIC
);
515 CDBG("msm_v4l2_s_fmt_cap: cannot allocate buffer\n");
519 ctrlcmd
->type
= MSM_V4L2_VID_CAP_TYPE
;
520 ctrlcmd
->length
= sizeof(struct v4l2_format
);
521 ctrlcmd
->value
= pfmt
;
522 ctrlcmd
->timeout_ms
= 10000;
524 if (pfmt
->type
!= V4L2_BUF_TYPE_VIDEO_CAPTURE
)
529 if (pfmt
->fmt
.pix
.pixelformat
!= V4L2_PIX_FMT_YVU420
)
533 /* Ok, but check other params, too. */
536 memcpy(&g_pmsm_v4l2_dev
->current_pix_format
.fmt
.pix
, pfmt
,
537 sizeof(struct v4l2_format
));
540 g_pmsm_v4l2_dev
->drv
->ctrl(g_pmsm_v4l2_dev
->drv
->sync
, ctrlcmd
);
545 static int msm_v4l2_g_fmt_overlay(struct file
*f
,
546 void *pctx
, struct v4l2_format
*pfmt
)
549 pfmt
->type
= V4L2_BUF_TYPE_VIDEO_OVERLAY
;
550 pfmt
->fmt
.pix
.width
= MSM_V4L2_WIDTH
;
551 pfmt
->fmt
.pix
.height
= MSM_V4L2_HEIGHT
;
552 pfmt
->fmt
.pix
.pixelformat
= V4L2_PIX_FMT_YVU420
;
553 pfmt
->fmt
.pix
.field
= V4L2_FIELD_ANY
;
554 pfmt
->fmt
.pix
.bytesperline
= 0;
555 pfmt
->fmt
.pix
.sizeimage
= 0;
556 pfmt
->fmt
.pix
.colorspace
= V4L2_COLORSPACE_JPEG
;
557 pfmt
->fmt
.pix
.priv
= 0;
561 static int msm_v4l2_s_fmt_overlay(struct file
*f
,
562 void *pctx
, struct v4l2_format
*pfmt
)
568 static int msm_v4l2_overlay(struct file
*f
, void *pctx
, unsigned int i
)
574 static int msm_v4l2_g_jpegcomp(struct file
*f
,
575 void *pctx
, struct v4l2_jpegcompression
*pcomp
)
581 static int msm_v4l2_s_jpegcomp(struct file
*f
,
582 void *pctx
, struct v4l2_jpegcompression
*pcomp
)
588 #ifdef CONFIG_PROC_FS
589 int msm_v4l2_read_proc(char *pbuf
, char **start
, off_t offset
,
590 int count
, int *eof
, void *data
)
593 len
+= snprintf(pbuf
, strlen("stats\n") + 1, "stats\n");
595 if (g_pmsm_v4l2_dev
) {
596 len
+= snprintf(pbuf
, strlen("mode: ") + 1, "mode: ");
598 if (g_pmsm_v4l2_dev
->current_cap_format
.type
599 == V4L2_BUF_TYPE_VIDEO_CAPTURE
)
600 len
+= snprintf(pbuf
, strlen("capture\n") + 1,
603 len
+= snprintf(pbuf
, strlen("unknown\n") + 1,
606 len
+= snprintf(pbuf
, 21, "resolution: %dx%d\n",
607 g_pmsm_v4l2_dev
->current_cap_format
.fmt
.pix
.
609 g_pmsm_v4l2_dev
->current_cap_format
.fmt
.pix
.
612 len
+= snprintf(pbuf
,
613 strlen("pixel format: ") + 1, "pixel format: ");
614 if (g_pmsm_v4l2_dev
->current_cap_format
.fmt
.pix
.pixelformat
615 == V4L2_PIX_FMT_YVU420
)
616 len
+= snprintf(pbuf
, strlen("yvu420\n") + 1,
619 len
+= snprintf(pbuf
, strlen("unknown\n") + 1,
622 len
+= snprintf(pbuf
, strlen("colorspace: ") + 1,
624 if (g_pmsm_v4l2_dev
->current_cap_format
.fmt
.pix
.colorspace
625 == V4L2_COLORSPACE_JPEG
)
626 len
+= snprintf(pbuf
, strlen("jpeg\n") + 1, "jpeg\n");
628 len
+= snprintf(pbuf
, strlen("unknown\n") + 1,
637 static const struct v4l2_file_operations msm_v4l2_fops
= {
638 .owner
= THIS_MODULE
,
639 .open
= msm_v4l2_open
,
640 .poll
= msm_v4l2_poll
,
641 .release
= msm_v4l2_release
,
642 .ioctl
= msm_v4l2_ioctl
,
645 static void msm_v4l2_dev_init(struct msm_v4l2_device
*pmsm_v4l2_dev
)
647 pmsm_v4l2_dev
->read_queue_lock
=
648 __SPIN_LOCK_UNLOCKED(pmsm_v4l2_dev
->read_queue_lock
);
649 INIT_LIST_HEAD(&pmsm_v4l2_dev
->read_queue
);
652 static int msm_v4l2_try_fmt_cap(struct file
*file
,
653 void *fh
, struct v4l2_format
*f
)
659 static int mm_v4l2_try_fmt_type_private(struct file
*file
,
660 void *fh
, struct v4l2_format
*f
)
667 * should the following structure be used instead of the code in the function?
668 * static const struct v4l2_ioctl_ops msm_v4l2_ioctl_ops = {
669 * .vidioc_querycap = ....
672 static const struct v4l2_ioctl_ops msm_ioctl_ops
= {
673 .vidioc_querycap
= msm_v4l2_querycap
,
674 .vidioc_s_std
= msm_v4l2_s_std
,
676 .vidioc_queryctrl
= msm_v4l2_queryctrl
,
677 .vidioc_g_ctrl
= msm_v4l2_g_ctrl
,
678 .vidioc_s_ctrl
= msm_v4l2_s_ctrl
,
680 .vidioc_reqbufs
= msm_v4l2_reqbufs
,
681 .vidioc_querybuf
= msm_v4l2_querybuf
,
682 .vidioc_qbuf
= msm_v4l2_qbuf
,
683 .vidioc_dqbuf
= msm_v4l2_dqbuf
,
685 .vidioc_streamon
= msm_v4l2_streamon
,
686 .vidioc_streamoff
= msm_v4l2_streamoff
,
688 .vidioc_enum_fmt_vid_overlay
= msm_v4l2_enum_fmt_overlay
,
689 .vidioc_enum_fmt_vid_cap
= msm_v4l2_enum_fmt_cap
,
691 .vidioc_try_fmt_vid_cap
= msm_v4l2_try_fmt_cap
,
692 .vidioc_try_fmt_type_private
= mm_v4l2_try_fmt_type_private
,
694 .vidioc_g_fmt_vid_cap
= msm_v4l2_g_fmt_cap
,
695 .vidioc_s_fmt_vid_cap
= msm_v4l2_s_fmt_cap
,
696 .vidioc_g_fmt_vid_overlay
= msm_v4l2_g_fmt_overlay
,
697 .vidioc_s_fmt_vid_overlay
= msm_v4l2_s_fmt_overlay
,
698 .vidioc_overlay
= msm_v4l2_overlay
,
700 .vidioc_g_jpegcomp
= msm_v4l2_g_jpegcomp
,
701 .vidioc_s_jpegcomp
= msm_v4l2_s_jpegcomp
,
704 static int msm_v4l2_video_dev_init(struct video_device
*pvd
)
706 strncpy(pvd
->name
, MSM_APPS_ID_V4L2
, sizeof(pvd
->name
));
708 pvd
->fops
= &msm_v4l2_fops
;
709 pvd
->release
= msm_v4l2_release_dev
;
711 pvd
->ioctl_ops
= &msm_ioctl_ops
;
712 return msm_v4l2_register(g_pmsm_v4l2_dev
->drv
);
715 static int __init
msm_v4l2_init(void)
718 struct video_device
*pvdev
= NULL
;
719 struct msm_v4l2_device
*pmsm_v4l2_dev
= NULL
;
722 pvdev
= video_device_alloc();
727 kzalloc(sizeof(struct msm_v4l2_device
), GFP_KERNEL
);
728 if (pmsm_v4l2_dev
== NULL
) {
729 video_device_release(pvdev
);
733 msm_v4l2_dev_init(pmsm_v4l2_dev
);
735 g_pmsm_v4l2_dev
= pmsm_v4l2_dev
;
736 g_pmsm_v4l2_dev
->pvdev
= pvdev
;
738 g_pmsm_v4l2_dev
->drv
=
739 kzalloc(sizeof(struct msm_v4l2_driver
), GFP_KERNEL
);
740 if (!g_pmsm_v4l2_dev
->drv
) {
741 video_device_release(pvdev
);
742 kfree(pmsm_v4l2_dev
);
746 rc
= msm_v4l2_video_dev_init(pvdev
);
748 video_device_release(pvdev
);
749 kfree(g_pmsm_v4l2_dev
->drv
);
750 kfree(pmsm_v4l2_dev
);
754 if (video_register_device(pvdev
, VFL_TYPE_GRABBER
,
755 MSM_V4L2_DEVNUM_YUV
)) {
756 D("failed to register device\n");
757 video_device_release(pvdev
);
758 kfree(g_pmsm_v4l2_dev
);
759 g_pmsm_v4l2_dev
= NULL
;
762 #ifdef CONFIG_PROC_FS
763 create_proc_read_entry(MSM_V4L2_PROC_NAME
,
764 0, NULL
, msm_v4l2_read_proc
, NULL
);
770 static void __exit
msm_v4l2_exit(void)
772 struct video_device
*pvdev
= g_pmsm_v4l2_dev
->pvdev
;
774 #ifdef CONFIG_PROC_FS
775 remove_proc_entry(MSM_V4L2_PROC_NAME
, NULL
);
777 video_unregister_device(pvdev
);
778 video_device_release(pvdev
);
780 msm_v4l2_unregister(g_pmsm_v4l2_dev
->drv
);
782 kfree(g_pmsm_v4l2_dev
->drv
);
783 g_pmsm_v4l2_dev
->drv
= NULL
;
785 kfree(g_pmsm_v4l2_dev
);
786 g_pmsm_v4l2_dev
= NULL
;
789 module_init(msm_v4l2_init
);
790 module_exit(msm_v4l2_exit
);
792 MODULE_DESCRIPTION("MSM V4L2 driver");
793 MODULE_LICENSE("GPL v2");