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
) {
531 if (pfmt
->fmt
.pix
.pixelformat
!= V4L2_PIX_FMT_YVU420
) {
537 /* Ok, but check other params, too. */
540 memcpy(&g_pmsm_v4l2_dev
->current_pix_format
.fmt
.pix
, pfmt
,
541 sizeof(struct v4l2_format
));
544 g_pmsm_v4l2_dev
->drv
->ctrl(g_pmsm_v4l2_dev
->drv
->sync
, ctrlcmd
);
549 static int msm_v4l2_g_fmt_overlay(struct file
*f
,
550 void *pctx
, struct v4l2_format
*pfmt
)
553 pfmt
->type
= V4L2_BUF_TYPE_VIDEO_OVERLAY
;
554 pfmt
->fmt
.pix
.width
= MSM_V4L2_WIDTH
;
555 pfmt
->fmt
.pix
.height
= MSM_V4L2_HEIGHT
;
556 pfmt
->fmt
.pix
.pixelformat
= V4L2_PIX_FMT_YVU420
;
557 pfmt
->fmt
.pix
.field
= V4L2_FIELD_ANY
;
558 pfmt
->fmt
.pix
.bytesperline
= 0;
559 pfmt
->fmt
.pix
.sizeimage
= 0;
560 pfmt
->fmt
.pix
.colorspace
= V4L2_COLORSPACE_JPEG
;
561 pfmt
->fmt
.pix
.priv
= 0;
565 static int msm_v4l2_s_fmt_overlay(struct file
*f
,
566 void *pctx
, struct v4l2_format
*pfmt
)
572 static int msm_v4l2_overlay(struct file
*f
, void *pctx
, unsigned int i
)
578 static int msm_v4l2_g_jpegcomp(struct file
*f
,
579 void *pctx
, struct v4l2_jpegcompression
*pcomp
)
585 static int msm_v4l2_s_jpegcomp(struct file
*f
,
586 void *pctx
, struct v4l2_jpegcompression
*pcomp
)
592 #ifdef CONFIG_PROC_FS
593 int msm_v4l2_read_proc(char *pbuf
, char **start
, off_t offset
,
594 int count
, int *eof
, void *data
)
597 len
+= snprintf(pbuf
, strlen("stats\n") + 1, "stats\n");
599 if (g_pmsm_v4l2_dev
) {
600 len
+= snprintf(pbuf
, strlen("mode: ") + 1, "mode: ");
602 if (g_pmsm_v4l2_dev
->current_cap_format
.type
603 == V4L2_BUF_TYPE_VIDEO_CAPTURE
)
604 len
+= snprintf(pbuf
, strlen("capture\n") + 1,
607 len
+= snprintf(pbuf
, strlen("unknown\n") + 1,
610 len
+= snprintf(pbuf
, 21, "resolution: %dx%d\n",
611 g_pmsm_v4l2_dev
->current_cap_format
.fmt
.pix
.
613 g_pmsm_v4l2_dev
->current_cap_format
.fmt
.pix
.
616 len
+= snprintf(pbuf
,
617 strlen("pixel format: ") + 1, "pixel format: ");
618 if (g_pmsm_v4l2_dev
->current_cap_format
.fmt
.pix
.pixelformat
619 == V4L2_PIX_FMT_YVU420
)
620 len
+= snprintf(pbuf
, strlen("yvu420\n") + 1,
623 len
+= snprintf(pbuf
, strlen("unknown\n") + 1,
626 len
+= snprintf(pbuf
, strlen("colorspace: ") + 1,
628 if (g_pmsm_v4l2_dev
->current_cap_format
.fmt
.pix
.colorspace
629 == V4L2_COLORSPACE_JPEG
)
630 len
+= snprintf(pbuf
, strlen("jpeg\n") + 1, "jpeg\n");
632 len
+= snprintf(pbuf
, strlen("unknown\n") + 1,
641 static const struct v4l2_file_operations msm_v4l2_fops
= {
642 .owner
= THIS_MODULE
,
643 .open
= msm_v4l2_open
,
644 .poll
= msm_v4l2_poll
,
645 .release
= msm_v4l2_release
,
646 .ioctl
= msm_v4l2_ioctl
,
649 static void msm_v4l2_dev_init(struct msm_v4l2_device
*pmsm_v4l2_dev
)
651 pmsm_v4l2_dev
->read_queue_lock
=
652 __SPIN_LOCK_UNLOCKED(pmsm_v4l2_dev
->read_queue_lock
);
653 INIT_LIST_HEAD(&pmsm_v4l2_dev
->read_queue
);
656 static int msm_v4l2_try_fmt_cap(struct file
*file
,
657 void *fh
, struct v4l2_format
*f
)
663 static int mm_v4l2_try_fmt_type_private(struct file
*file
,
664 void *fh
, struct v4l2_format
*f
)
671 * should the following structure be used instead of the code in the function?
672 * static const struct v4l2_ioctl_ops msm_v4l2_ioctl_ops = {
673 * .vidioc_querycap = ....
676 static const struct v4l2_ioctl_ops msm_ioctl_ops
= {
677 .vidioc_querycap
= msm_v4l2_querycap
,
678 .vidioc_s_std
= msm_v4l2_s_std
,
680 .vidioc_queryctrl
= msm_v4l2_queryctrl
,
681 .vidioc_g_ctrl
= msm_v4l2_g_ctrl
,
682 .vidioc_s_ctrl
= msm_v4l2_s_ctrl
,
684 .vidioc_reqbufs
= msm_v4l2_reqbufs
,
685 .vidioc_querybuf
= msm_v4l2_querybuf
,
686 .vidioc_qbuf
= msm_v4l2_qbuf
,
687 .vidioc_dqbuf
= msm_v4l2_dqbuf
,
689 .vidioc_streamon
= msm_v4l2_streamon
,
690 .vidioc_streamoff
= msm_v4l2_streamoff
,
692 .vidioc_enum_fmt_vid_overlay
= msm_v4l2_enum_fmt_overlay
,
693 .vidioc_enum_fmt_vid_cap
= msm_v4l2_enum_fmt_cap
,
695 .vidioc_try_fmt_vid_cap
= msm_v4l2_try_fmt_cap
,
696 .vidioc_try_fmt_type_private
= mm_v4l2_try_fmt_type_private
,
698 .vidioc_g_fmt_vid_cap
= msm_v4l2_g_fmt_cap
,
699 .vidioc_s_fmt_vid_cap
= msm_v4l2_s_fmt_cap
,
700 .vidioc_g_fmt_vid_overlay
= msm_v4l2_g_fmt_overlay
,
701 .vidioc_s_fmt_vid_overlay
= msm_v4l2_s_fmt_overlay
,
702 .vidioc_overlay
= msm_v4l2_overlay
,
704 .vidioc_g_jpegcomp
= msm_v4l2_g_jpegcomp
,
705 .vidioc_s_jpegcomp
= msm_v4l2_s_jpegcomp
,
708 static int msm_v4l2_video_dev_init(struct video_device
*pvd
)
710 strncpy(pvd
->name
, MSM_APPS_ID_V4L2
, sizeof(pvd
->name
));
712 pvd
->fops
= &msm_v4l2_fops
;
713 pvd
->release
= msm_v4l2_release_dev
;
715 pvd
->ioctl_ops
= &msm_ioctl_ops
;
716 return msm_v4l2_register(g_pmsm_v4l2_dev
->drv
);
719 static int __init
msm_v4l2_init(void)
722 struct video_device
*pvdev
= NULL
;
723 struct msm_v4l2_device
*pmsm_v4l2_dev
= NULL
;
726 pvdev
= video_device_alloc();
731 kzalloc(sizeof(struct msm_v4l2_device
), GFP_KERNEL
);
732 if (pmsm_v4l2_dev
== NULL
) {
733 video_device_release(pvdev
);
737 msm_v4l2_dev_init(pmsm_v4l2_dev
);
739 g_pmsm_v4l2_dev
= pmsm_v4l2_dev
;
740 g_pmsm_v4l2_dev
->pvdev
= pvdev
;
742 g_pmsm_v4l2_dev
->drv
=
743 kzalloc(sizeof(struct msm_v4l2_driver
), GFP_KERNEL
);
744 if (!g_pmsm_v4l2_dev
->drv
) {
745 video_device_release(pvdev
);
746 kfree(pmsm_v4l2_dev
);
750 rc
= msm_v4l2_video_dev_init(pvdev
);
752 video_device_release(pvdev
);
753 kfree(g_pmsm_v4l2_dev
->drv
);
754 kfree(pmsm_v4l2_dev
);
758 if (video_register_device(pvdev
, VFL_TYPE_GRABBER
,
759 MSM_V4L2_DEVNUM_YUV
)) {
760 D("failed to register device\n");
761 video_device_release(pvdev
);
762 kfree(g_pmsm_v4l2_dev
);
763 g_pmsm_v4l2_dev
= NULL
;
766 #ifdef CONFIG_PROC_FS
767 create_proc_read_entry(MSM_V4L2_PROC_NAME
,
768 0, NULL
, msm_v4l2_read_proc
, NULL
);
774 static void __exit
msm_v4l2_exit(void)
776 struct video_device
*pvdev
= g_pmsm_v4l2_dev
->pvdev
;
778 #ifdef CONFIG_PROC_FS
779 remove_proc_entry(MSM_V4L2_PROC_NAME
, NULL
);
781 video_unregister_device(pvdev
);
782 video_device_release(pvdev
);
784 msm_v4l2_unregister(g_pmsm_v4l2_dev
->drv
);
786 kfree(g_pmsm_v4l2_dev
->drv
);
787 g_pmsm_v4l2_dev
->drv
= NULL
;
789 kfree(g_pmsm_v4l2_dev
);
790 g_pmsm_v4l2_dev
= NULL
;
793 module_init(msm_v4l2_init
);
794 module_exit(msm_v4l2_exit
);
796 MODULE_DESCRIPTION("MSM V4L2 driver");
797 MODULE_LICENSE("GPL v2");