4 * Copyright (C) 2006--2009 Nokia Corporation
5 * Copyright (C) 2007--2009 Texas Instruments
7 * Contact: Sakari Ailus <sakari.ailus@nokia.com>
8 * Tuukka Toivonen <tuukka.o.toivonen@nokia.com>
10 * Originally based on the OMAP 2 camera driver.
12 * Written by Sakari Ailus <sakari.ailus@nokia.com>
13 * Tuukka Toivonen <tuukka.o.toivonen@nokia.com>
14 * Sergio Aguirre <saaguirre@ti.com>
19 * This program is free software; you can redistribute it and/or
20 * modify it under the terms of the GNU General Public License
21 * version 2 as published by the Free Software Foundation.
23 * This program is distributed in the hope that it will be useful, but
24 * WITHOUT ANY WARRANTY; without even the implied warranty of
25 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
26 * General Public License for more details.
28 * You should have received a copy of the GNU General Public License
29 * along with this program; if not, write to the Free Software
30 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
35 #include <linux/videodev2.h>
36 #include <linux/version.h>
37 #include <linux/sched.h>
38 #include <linux/vmalloc.h>
40 #include <linux/dma-mapping.h>
42 #include <media/v4l2-common.h>
43 #include <media/v4l2-ioctl.h>
44 #include <media/v4l2-int-device.h>
45 #include <media/tvp514x-int.h>
47 #include "omap34xxcam.h"
50 #define OMAP34XXCAM_VERSION KERNEL_VERSION(0, 0, 0)
52 /* global variables */
53 static struct omap34xxcam_device
*omap34xxcam
;
62 * omap34xxcam_slave_power_set - set slave power state
63 * @vdev: per-video device data structure
64 * @power: new power state
66 static int omap34xxcam_slave_power_set(struct omap34xxcam_videodev
*vdev
,
67 enum v4l2_power power
,
72 BUG_ON(!mutex_is_locked(&vdev
->mutex
));
74 #ifdef OMAP34XXCAM_POWEROFF_DELAY
75 vdev
->power_state_wish
= -1;
78 for (i
= 0; i
<= OMAP34XXCAM_SLAVE_FLASH
; i
++) {
79 if (vdev
->slave
[i
] == v4l2_int_device_dummy())
82 if (!(mask
& (1 << i
))
83 || power
== vdev
->power_state
[i
])
86 rval
= vidioc_int_s_power(vdev
->slave
[i
], power
);
88 if (rval
&& power
!= V4L2_POWER_OFF
) {
89 power
= V4L2_POWER_OFF
;
93 vdev
->power_state
[i
] = power
;
99 for (i
--; i
>= 0; i
--) {
100 if (vdev
->slave
[i
] == v4l2_int_device_dummy())
103 if (!(mask
& (1 << i
)))
106 vidioc_int_s_power(vdev
->slave
[i
], power
);
107 vdev
->power_state
[i
] = power
;
113 #ifdef OMAP34XXCAM_POWEROFF_DELAY
114 static void omap34xxcam_slave_power_work(struct work_struct
*work
)
116 struct omap34xxcam_videodev
*vdev
=
117 container_of(work
, struct omap34xxcam_videodev
, poweroff_work
);
119 mutex_lock(&vdev
->mutex
);
121 if (vdev
->power_state_wish
!= -1)
122 omap34xxcam_slave_power_set(vdev
, vdev
->power_state_wish
,
123 vdev
->power_state_mask
);
125 mutex_unlock(&vdev
->mutex
);
128 static void omap34xxcam_slave_power_timer(unsigned long ptr
)
130 struct omap34xxcam_videodev
*vdev
= (void *)ptr
;
132 schedule_work(&vdev
->poweroff_work
);
136 * omap34xxcam_slave_power_suggest - delayed power state change
138 * @vdev: per-video device data structure
139 * @power: new power state
141 static void omap34xxcam_slave_power_suggest(struct omap34xxcam_videodev
*vdev
,
142 enum v4l2_power power
,
145 BUG_ON(!mutex_is_locked(&vdev
->mutex
));
147 del_timer(&vdev
->poweroff_timer
);
149 vdev
->power_state_wish
= power
;
150 vdev
->power_state_mask
= mask
;
152 mod_timer(&vdev
->poweroff_timer
, jiffies
+ OMAP34XXCAM_POWEROFF_DELAY
);
154 #else /* OMAP34XXCAM_POWEROFF_DELAY */
155 #define omap34xxcam_slave_power_suggest(a, b, c) do {} while (0)
156 #endif /* OMAP34XXCAM_POWEROFF_DELAY */
159 * omap34xxcam_update_vbq - Updates VBQ with completed input buffer
160 * @vb: ptr. to standard V4L2 video buffer structure
162 * Updates video buffer queue with completed buffer passed as
163 * input parameter. Also updates ISP H3A timestamp and field count
166 void omap34xxcam_vbq_complete(struct videobuf_buffer
*vb
, void *priv
)
168 struct omap34xxcam_fh
*fh
= priv
;
170 do_gettimeofday(&vb
->ts
);
171 vb
->field_count
= atomic_add_return(2, &fh
->field_count
);
177 * omap34xxcam_vbq_setup - Calcs size and num of buffs allowed in queue
178 * @vbq: ptr. to standard V4L2 video buffer queue structure
179 * @cnt: ptr to location to hold the count of buffers to be in the queue
180 * @size: ptr to location to hold the size of a frame
182 * Calculates the number of buffers of current image size that can be
183 * supported by the available capture memory.
185 static int omap34xxcam_vbq_setup(struct videobuf_queue
*vbq
, unsigned int *cnt
,
188 struct omap34xxcam_fh
*fh
= vbq
->priv_data
;
189 struct omap34xxcam_videodev
*vdev
= fh
->vdev
;
192 *cnt
= VIDEO_MAX_FRAME
; /* supply a default number of buffers */
194 if (*cnt
> VIDEO_MAX_FRAME
)
195 *cnt
= VIDEO_MAX_FRAME
;
197 *size
= vdev
->pix
.sizeimage
;
199 while (*size
* *cnt
> fh
->vdev
->vdev_sensor_config
.capture_mem
)
202 return isp_vbq_setup(vdev
->cam
->isp
, vbq
, cnt
, size
);
206 * omap34xxcam_vbq_release - Free resources for input VBQ and VB
207 * @vbq: ptr. to standard V4L2 video buffer queue structure
208 * @vb: ptr to standard V4L2 video buffer structure
210 * Unmap and free all memory associated with input VBQ and VB, also
211 * unmap the address in ISP MMU. Reset the VB state.
213 static void omap34xxcam_vbq_release(struct videobuf_queue
*vbq
,
214 struct videobuf_buffer
*vb
)
216 struct omap34xxcam_fh
*fh
= vbq
->priv_data
;
217 struct omap34xxcam_videodev
*vdev
= fh
->vdev
;
218 struct device
*isp
= vdev
->cam
->isp
;
220 if (!vbq
->streaming
) {
221 isp_vbq_release(isp
, vbq
, vb
);
222 videobuf_dma_unmap(vbq
, videobuf_to_dma(vb
));
223 videobuf_dma_free(videobuf_to_dma(vb
));
224 vb
->state
= VIDEOBUF_NEEDS_INIT
;
232 * This function is work around for the videobuf_iolock API,
233 * for User memory allocated with ioremap (VM_IO flag) the API
234 * get_user_pages fails.
236 * To fulfill this requirement, we have completely ignored VM layer of
237 * Linux, and configuring the ISP MMU with physical address.
239 static int omap_videobuf_dma_init_user(struct videobuf_buffer
*vb
,
240 unsigned long physp
, unsigned long asize
)
242 struct videobuf_dmabuf
*dma
;
243 struct scatterlist
*sglist
;
244 unsigned long data
, first
, last
;
247 dma
= videobuf_to_dma(vb
);
250 first
= (data
& PAGE_MASK
) >> PAGE_SHIFT
;
251 last
= ((data
+asize
-1) & PAGE_MASK
) >> PAGE_SHIFT
;
252 dma
->offset
= data
& ~PAGE_MASK
;
253 dma
->nr_pages
= last
-first
+1;
255 dma
->direction
= DMA_FROM_DEVICE
;
257 BUG_ON(0 == dma
->nr_pages
);
259 * Allocate array of sglen + 1, to add entry of extra page
260 * for input buffer. Driver always uses 0th buffer as input buffer.
262 sglist
= vmalloc(dma
->nr_pages
* sizeof(*sglist
));
266 sg_init_table(sglist
, dma
->nr_pages
);
268 sglist
[0].offset
= 0;
269 sglist
[0].length
= PAGE_SIZE
- dma
->offset
;
270 sglist
[0].dma_address
= (dma_addr_t
)physp
;
271 physp
+= sglist
[0].length
;
273 * Iterate in a loop for the number of pages
275 for (i
= 1; i
< dma
->nr_pages
; i
++) {
276 sglist
[i
].offset
= 0;
277 sglist
[i
].length
= PAGE_SIZE
;
278 sglist
[i
].dma_address
= (dma_addr_t
)physp
;
281 dma
->sglist
= sglist
;
282 dma
->sglen
= dma
->nr_pages
;
289 * omap34xxcam_vbq_prepare - V4L2 video ops buf_prepare handler
290 * @vbq: ptr. to standard V4L2 video buffer queue structure
291 * @vb: ptr to standard V4L2 video buffer structure
292 * @field: standard V4L2 field enum
294 * Verifies there is sufficient locked memory for the requested
295 * buffer, or if there is not, allocates, locks and initializes
298 static int omap34xxcam_vbq_prepare(struct videobuf_queue
*vbq
,
299 struct videobuf_buffer
*vb
,
300 enum v4l2_field field
)
302 struct omap34xxcam_fh
*fh
= vbq
->priv_data
;
303 struct omap34xxcam_videodev
*vdev
= fh
->vdev
;
304 struct device
*isp
= vdev
->cam
->isp
;
309 * Accessing pix here is okay since it's constant while
310 * streaming is on (and we only get called then).
313 /* This is a userspace buffer. */
314 if (vdev
->pix
.sizeimage
> vb
->bsize
||
315 vb
->baddr
!= (vb
->baddr
& ~0x1F))
316 /* The buffer isn't big enough. */
319 if (vb
->state
!= VIDEOBUF_NEEDS_INIT
320 && vdev
->pix
.sizeimage
> vb
->bsize
)
322 * We have a kernel bounce buffer that has
323 * already been allocated.
325 omap34xxcam_vbq_release(vbq
, vb
);
328 vb
->size
= vdev
->pix
.bytesperline
* vdev
->pix
.height
;
329 vb
->width
= vdev
->pix
.width
;
330 vb
->height
= vdev
->pix
.height
;
333 if (vb
->state
== VIDEOBUF_NEEDS_INIT
) {
334 struct videobuf_dmabuf
*dma
;
335 struct vm_area_struct
*vma
;
336 dma
= videobuf_to_dma(vb
);
337 vma
= find_vma(current
->mm
, vb
->baddr
);
338 if ((vma
) && (vma
->vm_flags
& VM_IO
) && (vma
->vm_pgoff
)) {
339 /* This will catch ioremaped buffers to the kernel.
340 * It gives two possible scenarios -
341 * - Driver allocates buffer using either
342 * dma_alloc_coherent or get_free_pages,
343 * and maps to user space using
344 * io_remap_pfn_range/remap_pfn_range
345 * - Drivers maps memory outside from Linux using
348 unsigned long physp
= 0;
349 if ((vb
->baddr
+ vb
->bsize
) > vma
->vm_end
) {
350 dev_err(&vdev
->vfd
->dev
,
351 "User Buffer Allocation:" \
353 (vma
->vm_end
- vb
->baddr
),
357 physp
= (vma
->vm_pgoff
<< PAGE_SHIFT
) +
358 (vb
->baddr
- vma
->vm_start
);
359 err
= omap_videobuf_dma_init_user(vb
, physp
, vb
->bsize
);
361 err
= videobuf_iolock(vbq
, vb
, NULL
);
365 /* isp_addr will be stored locally inside isp code */
366 err
= isp_vbq_prepare(isp
, vbq
, vb
, field
);
371 vb
->state
= VIDEOBUF_PREPARED
;
373 omap34xxcam_vbq_release(vbq
, vb
);
379 * omap34xxcam_vbq_queue - V4L2 video ops buf_queue handler
380 * @vbq: ptr. to standard V4L2 video buffer queue structure
381 * @vb: ptr to standard V4L2 video buffer structure
383 * Maps the video buffer to sgdma and through the isp, sets
384 * the isp buffer done callback and sets the video buffer state
387 static void omap34xxcam_vbq_queue(struct videobuf_queue
*vbq
,
388 struct videobuf_buffer
*vb
)
390 struct omap34xxcam_fh
*fh
= vbq
->priv_data
;
391 struct omap34xxcam_videodev
*vdev
= fh
->vdev
;
392 struct device
*isp
= vdev
->cam
->isp
;
394 isp_buf_queue(isp
, vb
, omap34xxcam_vbq_complete
, (void *)fh
);
397 static struct videobuf_queue_ops omap34xxcam_vbq_ops
= {
398 .buf_setup
= omap34xxcam_vbq_setup
,
399 .buf_prepare
= omap34xxcam_vbq_prepare
,
400 .buf_queue
= omap34xxcam_vbq_queue
,
401 .buf_release
= omap34xxcam_vbq_release
,
411 * vidioc_querycap - V4L2 query capabilities IOCTL handler
412 * @file: ptr. to system file structure
413 * @fh: ptr to hold address of omap34xxcam_fh struct (per-filehandle data)
414 * @cap: ptr to standard V4L2 capability structure
416 * Fill in the V4L2 capabliity structure for the camera device
418 static int vidioc_querycap(struct file
*file
, void *fh
,
419 struct v4l2_capability
*cap
)
421 struct omap34xxcam_fh
*ofh
= fh
;
422 struct omap34xxcam_videodev
*vdev
= ofh
->vdev
;
424 strlcpy(cap
->driver
, CAM_SHORT_NAME
, sizeof(cap
->driver
));
425 strlcpy(cap
->card
, vdev
->vfd
->name
, sizeof(cap
->card
));
426 cap
->version
= OMAP34XXCAM_VERSION
;
427 if (vdev
->vdev_sensor
!= v4l2_int_device_dummy())
428 cap
->capabilities
= V4L2_CAP_VIDEO_CAPTURE
| V4L2_CAP_STREAMING
;
434 * vidioc_enum_fmt_vid_cap - V4L2 enumerate format capabilities IOCTL handler
435 * @file: ptr. to system file structure
436 * @fh: ptr to hold address of omap34xxcam_fh struct (per-filehandle data)
437 * @f: ptr to standard V4L2 format description structure
439 * Fills in enumerate format capabilities information for sensor (if SOC
440 * sensor attached) or ISP (if raw sensor attached).
442 static int vidioc_enum_fmt_vid_cap(struct file
*file
, void *fh
,
443 struct v4l2_fmtdesc
*f
)
445 struct omap34xxcam_fh
*ofh
= fh
;
446 struct omap34xxcam_videodev
*vdev
= ofh
->vdev
;
449 if (vdev
->vdev_sensor
== v4l2_int_device_dummy())
452 if (vdev
->vdev_sensor_mode
)
453 rval
= isp_enum_fmt_cap(f
);
454 else if (vdev
->vdev_sensor_config
.sensor_isp
)
455 rval
= vidioc_int_enum_fmt_cap(vdev
->vdev_sensor
, f
);
457 rval
= isp_enum_fmt_cap(f
);
463 * vidioc_g_fmt_vid_cap - V4L2 get format capabilities IOCTL handler
464 * @file: ptr. to system file structure
465 * @fh: ptr to hold address of omap34xxcam_fh struct (per-filehandle data)
466 * @f: ptr to standard V4L2 format structure
468 * Fills in format capabilities for sensor (if SOC sensor attached) or ISP
469 * (if raw sensor attached).
471 static int vidioc_g_fmt_vid_cap(struct file
*file
, void *fh
,
472 struct v4l2_format
*f
)
474 struct omap34xxcam_fh
*ofh
= fh
;
475 struct omap34xxcam_videodev
*vdev
= ofh
->vdev
;
476 struct device
*isp
= vdev
->cam
->isp
;
478 if (vdev
->vdev_sensor
== v4l2_int_device_dummy())
481 mutex_lock(&vdev
->mutex
);
482 f
->fmt
.pix
= vdev
->pix
;
483 mutex_unlock(&vdev
->mutex
);
488 static int try_pix_parm(struct omap34xxcam_videodev
*vdev
,
489 struct v4l2_pix_format
*best_pix_in
,
490 struct v4l2_pix_format
*wanted_pix_out
,
491 struct v4l2_fract
*best_ival
)
496 struct v4l2_pix_format best_pix_out
;
497 struct device
*isp
= vdev
->cam
->isp
;
499 if (best_ival
->numerator
== 0
500 || best_ival
->denominator
== 0)
501 *best_ival
= vdev
->vdev_sensor_config
.ival_default
;
503 fps
= best_ival
->denominator
/ best_ival
->numerator
;
505 memset(best_pix_in
, 0, sizeof(*best_pix_in
));
507 best_ival
->denominator
= 0;
508 best_pix_out
.height
= INT_MAX
>> 1;
509 best_pix_out
.width
= best_pix_out
.height
;
511 for (fmtd_index
= 0; ; fmtd_index
++) {
513 struct v4l2_fmtdesc fmtd
;
515 fmtd
.index
= fmtd_index
;
516 fmtd
.type
= V4L2_BUF_TYPE_VIDEO_CAPTURE
;
517 rval
= vidioc_int_enum_fmt_cap(vdev
->vdev_sensor
, &fmtd
);
520 dev_dbg(&vdev
->vfd
->dev
, "trying fmt %8.8x (%d)\n",
521 fmtd
.pixelformat
, fmtd_index
);
523 * Get supported resolutions.
525 for (size_index
= 0; ; size_index
++) {
526 struct v4l2_frmsizeenum frms
;
527 struct v4l2_pix_format pix_tmp_in
, pix_tmp_out
;
530 frms
.index
= size_index
;
531 frms
.pixel_format
= fmtd
.pixelformat
;
533 rval
= vidioc_int_enum_framesizes(vdev
->vdev_sensor
,
538 pix_tmp_in
.pixelformat
= frms
.pixel_format
;
539 pix_tmp_in
.width
= frms
.discrete
.width
;
540 pix_tmp_in
.height
= frms
.discrete
.height
;
541 pix_tmp_out
= *wanted_pix_out
;
542 /* Don't do upscaling. */
543 if (pix_tmp_out
.width
> pix_tmp_in
.width
)
544 pix_tmp_out
.width
= pix_tmp_in
.width
;
545 if (pix_tmp_out
.height
> pix_tmp_in
.height
)
546 pix_tmp_out
.height
= pix_tmp_in
.height
;
547 rval
= isp_try_fmt_cap(isp
, &pix_tmp_in
, &pix_tmp_out
);
551 dev_dbg(&vdev
->vfd
->dev
, "this w %d\th %d\tfmt %8.8x\t"
552 "-> w %d\th %d\t fmt %8.8x"
553 "\twanted w %d\th %d\t fmt %8.8x\n",
554 pix_tmp_in
.width
, pix_tmp_in
.height
,
555 pix_tmp_in
.pixelformat
,
556 pix_tmp_out
.width
, pix_tmp_out
.height
,
557 pix_tmp_out
.pixelformat
,
558 wanted_pix_out
->width
, wanted_pix_out
->height
,
559 wanted_pix_out
->pixelformat
);
561 #define IS_SMALLER_OR_EQUAL(pix1, pix2) \
562 ((pix1)->width + (pix1)->height \
563 < (pix2)->width + (pix2)->height)
564 #define SIZE_DIFF(pix1, pix2) \
565 (abs((pix1)->width - (pix2)->width) \
566 + abs((pix1)->height - (pix2)->height))
569 * Don't use modes that are farther from wanted size
570 * that what we already got.
572 if (SIZE_DIFF(&pix_tmp_out
, wanted_pix_out
)
573 > SIZE_DIFF(&best_pix_out
, wanted_pix_out
)) {
574 dev_dbg(&vdev
->vfd
->dev
, "size diff bigger: "
575 "w %d\th %d\tw %d\th %d\n",
576 pix_tmp_out
.width
, pix_tmp_out
.height
,
578 best_pix_out
.height
);
583 * There's an input mode that can provide output
586 if (SIZE_DIFF(&pix_tmp_out
, wanted_pix_out
)
587 < SIZE_DIFF(&best_pix_out
, wanted_pix_out
)) {
588 /* Force renegotation of fps etc. */
589 best_ival
->denominator
= 0;
590 dev_dbg(&vdev
->vfd
->dev
, "renegotiate: "
591 "w %d\th %d\tw %d\th %d\n",
592 pix_tmp_out
.width
, pix_tmp_out
.height
,
594 best_pix_out
.height
);
597 for (ival_index
= 0; ; ival_index
++) {
598 struct v4l2_frmivalenum frmi
;
600 frmi
.index
= ival_index
;
601 frmi
.pixel_format
= frms
.pixel_format
;
602 frmi
.width
= frms
.discrete
.width
;
603 frmi
.height
= frms
.discrete
.height
;
604 /* FIXME: try to fix standard... */
605 frmi
.reserved
[0] = 0xdeafbeef;
607 rval
= vidioc_int_enum_frameintervals(
608 vdev
->vdev_sensor
, &frmi
);
612 dev_dbg(&vdev
->vfd
->dev
, "fps %d\n",
613 frmi
.discrete
.denominator
614 / frmi
.discrete
.numerator
);
616 if (best_ival
->denominator
== 0)
619 if (best_pix_in
->width
== 0)
623 * We aim to use maximum resolution
624 * from the sensor, provided that the
625 * fps is at least as close as on the
628 #define FPS_ABS_DIFF(fps, ival) abs(fps - (ival).denominator / (ival).numerator)
630 /* Select mode with closest fps. */
631 if (FPS_ABS_DIFF(fps
, frmi
.discrete
)
632 < FPS_ABS_DIFF(fps
, *best_ival
)) {
633 dev_dbg(&vdev
->vfd
->dev
, "closer fps: "
634 "fps %ld\t fps %ld\n",
637 FPS_ABS_DIFF(fps
, *best_ival
));
642 * Select bigger resolution if it's available
645 if (frmi
.width
+ frmi
.height
646 > best_pix_in
->width
+ best_pix_in
->height
647 && FPS_ABS_DIFF(fps
, frmi
.discrete
)
648 <= FPS_ABS_DIFF(fps
, *best_ival
)) {
649 dev_dbg(&vdev
->vfd
->dev
, "bigger res, "
651 "w %d\th %d\tw %d\th %d\n",
652 frmi
.width
, frmi
.height
,
654 best_pix_in
->height
);
658 dev_dbg(&vdev
->vfd
->dev
, "falling through\n");
663 *best_ival
= frmi
.discrete
;
664 best_pix_out
= pix_tmp_out
;
665 best_pix_in
->width
= frmi
.width
;
666 best_pix_in
->height
= frmi
.height
;
667 best_pix_in
->pixelformat
= frmi
.pixel_format
;
669 dev_dbg(&vdev
->vfd
->dev
,
670 "best_pix_in: w %d\th %d\tfmt %8.8x"
674 best_pix_in
->pixelformat
,
675 best_ival
->numerator
,
676 best_ival
->denominator
);
681 if (best_ival
->denominator
== 0)
684 *wanted_pix_out
= best_pix_out
;
686 dev_dbg(&vdev
->vfd
->dev
, "w %d, h %d, fmt %8.8x -> w %d, h %d\n",
687 best_pix_in
->width
, best_pix_in
->height
,
688 best_pix_in
->pixelformat
,
689 best_pix_out
.width
, best_pix_out
.height
);
694 static int s_pix_parm(struct omap34xxcam_videodev
*vdev
,
695 struct v4l2_pix_format
*best_pix
,
696 struct v4l2_pix_format
*pix
,
697 struct v4l2_fract
*best_ival
)
699 struct device
*isp
= vdev
->cam
->isp
;
700 struct v4l2_streamparm a
;
701 struct v4l2_format fmt
;
702 struct v4l2_format old_fmt
;
705 rval
= try_pix_parm(vdev
, best_pix
, pix
, best_ival
);
709 rval
= isp_s_fmt_cap(isp
, best_pix
, pix
);
713 fmt
.type
= V4L2_BUF_TYPE_VIDEO_CAPTURE
;
714 fmt
.fmt
.pix
= *best_pix
;
715 vidioc_int_g_fmt_cap(vdev
->vdev_sensor
, &old_fmt
);
716 rval
= vidioc_int_s_fmt_cap(vdev
->vdev_sensor
, &fmt
);
720 a
.type
= V4L2_BUF_TYPE_VIDEO_CAPTURE
;
721 a
.parm
.capture
.timeperframe
= *best_ival
;
722 rval
= vidioc_int_s_parm(vdev
->vdev_sensor
, &a
);
728 * vidioc_s_fmt_vid_cap - V4L2 set format capabilities IOCTL handler
729 * @file: ptr. to system file structure
730 * @fh: ptr to hold address of omap34xxcam_fh struct (per-filehandle data)
731 * @f: ptr to standard V4L2 format structure
733 * Attempts to set input format with the sensor driver (first) and then the
734 * ISP. Returns the return code from vidioc_g_fmt_vid_cap().
736 static int vidioc_s_fmt_vid_cap(struct file
*file
, void *fh
,
737 struct v4l2_format
*f
)
739 struct omap34xxcam_fh
*ofh
= fh
;
740 struct omap34xxcam_videodev
*vdev
= ofh
->vdev
;
741 struct v4l2_pix_format pix_tmp
;
742 struct v4l2_fract timeperframe
;
745 if (vdev
->vdev_sensor
== v4l2_int_device_dummy())
748 mutex_lock(&vdev
->mutex
);
749 if (vdev
->streaming
) {
754 if (vdev
->vdev_sensor_mode
) {
755 struct v4l2_format input_fmt
= *f
;
756 struct v4l2_pix_format
*pix
= &f
->fmt
.pix
;
757 struct device
*isp
= vdev
->cam
->isp
;
759 rval
= isp_try_fmt_cap(isp
, pix
, pix
);
762 /* Always negotiate with the sensor first */
763 rval
= vidioc_int_s_fmt_cap(vdev
->vdev_sensor
, &input_fmt
);
766 pix
->width
= input_fmt
.fmt
.pix
.width
;
767 pix
->height
= input_fmt
.fmt
.pix
.height
;
768 pix
->pixelformat
= input_fmt
.fmt
.pix
.pixelformat
;
769 pix
->field
= input_fmt
.fmt
.pix
.field
;
770 pix
->bytesperline
= input_fmt
.fmt
.pix
.bytesperline
;
771 pix
->colorspace
= input_fmt
.fmt
.pix
.colorspace
;
772 pix
->sizeimage
= input_fmt
.fmt
.pix
.sizeimage
;
773 /* Negotiate with OMAP3 ISP */
774 rval
= isp_s_fmt_cap(isp
, pix
, pix
);
776 vdev
->pix
= f
->fmt
.pix
;
778 vdev
->want_pix
= f
->fmt
.pix
;
780 timeperframe
= vdev
->want_timeperframe
;
782 rval
= s_pix_parm(vdev
, &pix_tmp
, &f
->fmt
.pix
, &timeperframe
);
784 vdev
->pix
= f
->fmt
.pix
;
787 mutex_unlock(&vdev
->mutex
);
793 * vidioc_try_fmt_vid_cap - V4L2 try format capabilities IOCTL handler
794 * @file: ptr. to system file structure
795 * @fh: ptr to hold address of omap34xxcam_fh struct (per-filehandle data)
796 * @f: ptr to standard V4L2 format structure
798 * Checks if the given format is supported by the sensor driver and
801 static int vidioc_try_fmt_vid_cap(struct file
*file
, void *fh
,
802 struct v4l2_format
*f
)
804 struct omap34xxcam_fh
*ofh
= fh
;
805 struct omap34xxcam_videodev
*vdev
= ofh
->vdev
;
806 struct v4l2_pix_format pix_tmp
;
807 struct v4l2_fract timeperframe
;
810 if (vdev
->vdev_sensor
== v4l2_int_device_dummy())
813 mutex_lock(&vdev
->mutex
);
815 timeperframe
= vdev
->want_timeperframe
;
817 rval
= try_pix_parm(vdev
, &pix_tmp
, &f
->fmt
.pix
, &timeperframe
);
819 mutex_unlock(&vdev
->mutex
);
825 * vidioc_reqbufs - V4L2 request buffers IOCTL handler
826 * @file: ptr. to system file structure
827 * @fh: ptr to hold address of omap34xxcam_fh struct (per-filehandle data)
828 * @b: ptr to standard V4L2 request buffers structure
830 * Attempts to get a buffer from the buffer queue associated with the
831 * fh through the video buffer library API.
833 static int vidioc_reqbufs(struct file
*file
, void *fh
,
834 struct v4l2_requestbuffers
*b
)
836 struct omap34xxcam_fh
*ofh
= fh
;
837 struct omap34xxcam_videodev
*vdev
= ofh
->vdev
;
840 if (vdev
->vdev_sensor
== v4l2_int_device_dummy())
843 mutex_lock(&vdev
->mutex
);
844 if (vdev
->streaming
) {
845 mutex_unlock(&vdev
->mutex
);
849 rval
= videobuf_reqbufs(&ofh
->vbq
, b
);
851 mutex_unlock(&vdev
->mutex
);
854 * Either videobuf_reqbufs failed or the buffers are not
855 * memory-mapped (which would need special attention).
857 if (rval
< 0 || b
->memory
!= V4L2_MEMORY_MMAP
)
865 * vidioc_querybuf - V4L2 query buffer IOCTL handler
866 * @file: ptr. to system file structure
867 * @fh: ptr to hold address of omap34xxcam_fh struct (per-filehandle data)
868 * @b: ptr to standard V4L2 buffer structure
870 * Attempts to fill in the v4l2_buffer structure for the buffer queue
871 * associated with the fh through the video buffer library API.
873 static int vidioc_querybuf(struct file
*file
, void *fh
, struct v4l2_buffer
*b
)
875 struct omap34xxcam_fh
*ofh
= fh
;
877 return videobuf_querybuf(&ofh
->vbq
, b
);
881 * vidioc_qbuf - V4L2 queue buffer IOCTL handler
882 * @file: ptr. to system file structure
883 * @fh: ptr to hold address of omap34xxcam_fh struct (per-filehandle data)
884 * @b: ptr to standard V4L2 buffer structure
886 * Attempts to queue the v4l2_buffer on the buffer queue
887 * associated with the fh through the video buffer library API.
889 static int vidioc_qbuf(struct file
*file
, void *fh
, struct v4l2_buffer
*b
)
891 struct omap34xxcam_fh
*ofh
= fh
;
893 return videobuf_qbuf(&ofh
->vbq
, b
);
897 * vidioc_dqbuf - V4L2 dequeue buffer IOCTL handler
898 * @file: ptr. to system file structure
899 * @fh: ptr to hold address of omap34xxcam_fh struct (per-filehandle data)
900 * @b: ptr to standard V4L2 buffer structure
902 * Attempts to dequeue the v4l2_buffer from the buffer queue
903 * associated with the fh through the video buffer library API. If the
904 * buffer is a user space buffer, then this function will also requeue it,
905 * as user does not expect to do this.
907 static int vidioc_dqbuf(struct file
*file
, void *fh
, struct v4l2_buffer
*b
)
909 struct omap34xxcam_fh
*ofh
= fh
;
912 videobuf_dqbuf_again
:
913 rval
= videobuf_dqbuf(&ofh
->vbq
, b
, file
->f_flags
& O_NONBLOCK
);
916 * This is a hack. We don't want to show -EIO to the user
917 * space. Requeue the buffer and try again if we're not doing
918 * this in non-blocking mode.
921 videobuf_qbuf(&ofh
->vbq
, b
);
922 if (!(file
->f_flags
& O_NONBLOCK
))
923 goto videobuf_dqbuf_again
;
925 * We don't have a videobuf_buffer now --- maybe next
935 * vidioc_streamon - V4L2 streamon IOCTL handler
936 * @file: ptr. to system file structure
937 * @fh: ptr to hold address of omap34xxcam_fh struct (per-filehandle data)
938 * @i: V4L2 buffer type
940 * Attempts to start streaming by enabling the sensor interface and turning
941 * on video buffer streaming through the video buffer library API. Upon
942 * success the function returns 0, otherwise an error code is returned.
944 static int vidioc_streamon(struct file
*file
, void *fh
, enum v4l2_buf_type i
)
946 struct omap34xxcam_fh
*ofh
= fh
;
947 struct omap34xxcam_videodev
*vdev
= ofh
->vdev
;
948 struct device
*isp
= vdev
->cam
->isp
;
951 if (vdev
->vdev_sensor
== v4l2_int_device_dummy())
954 mutex_lock(&vdev
->mutex
);
955 if (vdev
->streaming
) {
960 rval
= omap34xxcam_slave_power_set(vdev
, V4L2_POWER_ON
,
961 OMAP34XXCAM_SLAVE_POWER_SENSOR_LENS
);
963 dev_dbg(&vdev
->vfd
->dev
,
964 "omap34xxcam_slave_power_set failed\n");
970 rval
= videobuf_streamon(&ofh
->vbq
);
973 omap34xxcam_slave_power_set(
974 vdev
, V4L2_POWER_OFF
,
975 OMAP34XXCAM_SLAVE_POWER_SENSOR_LENS
);
977 vdev
->streaming
= file
;
980 mutex_unlock(&vdev
->mutex
);
986 * vidioc_streamoff - V4L2 streamoff IOCTL handler
987 * @file: ptr. to system file structure
988 * @fh: ptr to hold address of omap34xxcam_fh struct (per-filehandle data)
989 * @i: V4L2 buffer type
991 * Attempts to stop streaming by flushing all scheduled work, waiting on
992 * any queued buffers to complete and then stopping the ISP and turning
993 * off video buffer streaming through the video buffer library API. Upon
994 * success the function returns 0, otherwise an error code is returned.
996 static int vidioc_streamoff(struct file
*file
, void *fh
, enum v4l2_buf_type i
)
998 struct omap34xxcam_fh
*ofh
= fh
;
999 struct omap34xxcam_videodev
*vdev
= ofh
->vdev
;
1000 struct device
*isp
= vdev
->cam
->isp
;
1001 struct videobuf_queue
*q
= &ofh
->vbq
;
1004 mutex_lock(&vdev
->mutex
);
1006 if (vdev
->streaming
== file
)
1009 rval
= videobuf_streamoff(q
);
1011 vdev
->streaming
= NULL
;
1013 omap34xxcam_slave_power_set(vdev
, V4L2_POWER_STANDBY
,
1014 OMAP34XXCAM_SLAVE_POWER_SENSOR
);
1015 omap34xxcam_slave_power_suggest(vdev
, V4L2_POWER_STANDBY
,
1016 OMAP34XXCAM_SLAVE_POWER_LENS
);
1019 mutex_unlock(&vdev
->mutex
);
1025 * vidioc_enum_input - V4L2 enumerate input IOCTL handler
1026 * @file: ptr. to system file structure
1027 * @fh: ptr to hold address of omap34xxcam_fh struct (per-filehandle data)
1028 * @inp: V4L2 input type information structure
1030 * Fills in v4l2_input structure. Returns 0.
1032 static int vidioc_enum_input(struct file
*file
, void *fh
,
1033 struct v4l2_input
*inp
)
1035 struct omap34xxcam_videodev
*vdev
= ((struct omap34xxcam_fh
*)fh
)->vdev
;
1037 if (vdev
->vdev_sensor_mode
) {
1038 if (inp
->index
== 0) {
1039 strlcpy(inp
->name
, "COMPOSITE", sizeof(inp
->name
));
1040 inp
->type
= V4L2_INPUT_TYPE_CAMERA
;
1041 } else if (inp
->index
== 1) {
1042 strlcpy(inp
->name
, "S-VIDEO", sizeof(inp
->name
));
1043 inp
->type
= V4L2_INPUT_TYPE_CAMERA
;
1049 strlcpy(inp
->name
, "camera", sizeof(inp
->name
));
1050 inp
->type
= V4L2_INPUT_TYPE_CAMERA
;
1057 * vidioc_g_input - V4L2 get input IOCTL handler
1058 * @file: ptr. to system file structure
1059 * @fh: ptr to hold address of omap34xxcam_fh struct (per-filehandle data)
1060 * @i: address to hold index of input supported
1064 static int vidioc_g_input(struct file
*file
, void *fh
, unsigned int *i
)
1066 struct omap34xxcam_videodev
*vdev
= ((struct omap34xxcam_fh
*)fh
)->vdev
;
1069 mutex_lock(&vdev
->mutex
);
1070 if (vdev
->vdev_sensor_mode
) {
1071 if (vdev
->slave_config
[OMAP34XXCAM_SLAVE_SENSOR
].cur_input
1074 else if (vdev
->slave_config
[OMAP34XXCAM_SLAVE_SENSOR
].cur_input
1075 == INPUT_SVIDEO_VI2C_VI1C
)
1080 mutex_unlock(&vdev
->mutex
);
1086 * vidioc_s_input - V4L2 set input IOCTL handler
1087 * @file: ptr. to system file structure
1088 * @fh: ptr to hold address of omap34xxcam_fh struct (per-filehandle data)
1089 * @i: index of input selected
1091 * 0 is only index supported.
1093 static int vidioc_s_input(struct file
*file
, void *fh
, unsigned int i
)
1095 struct omap34xxcam_fh
*ofh
= fh
;
1096 struct omap34xxcam_videodev
*vdev
= ofh
->vdev
;
1098 struct v4l2_routing route
;
1100 mutex_lock(&vdev
->mutex
);
1101 if (vdev
->vdev_sensor_mode
) {
1103 route
.input
= INPUT_CVBS_VI4A
;
1105 route
.input
= INPUT_SVIDEO_VI2C_VI1C
;
1108 rval
= vidioc_int_s_video_routing(vdev
->vdev_sensor
, &route
);
1110 vdev
->slave_config
[OMAP34XXCAM_SLAVE_SENSOR
].cur_input
1116 mutex_unlock(&vdev
->mutex
);
1122 * vidioc_queryctrl - V4L2 query control IOCTL handler
1123 * @file: ptr. to system file structure
1124 * @fh: ptr to hold address of omap34xxcam_fh struct (per-filehandle data)
1125 * @a: standard V4L2 query control ioctl structure
1127 * If the requested control is supported, returns the control information
1128 * in the v4l2_queryctrl structure. Otherwise, returns -EINVAL if the
1129 * control is not supported. If the sensor being used is a "smart sensor",
1130 * this request is passed to the sensor driver, otherwise the ISP is
1131 * queried and if it does not support the requested control, the request
1132 * is forwarded to the "raw" sensor driver to see if it supports it.
1134 static int vidioc_queryctrl(struct file
*file
, void *fh
,
1135 struct v4l2_queryctrl
*a
)
1137 struct omap34xxcam_fh
*ofh
= fh
;
1138 struct omap34xxcam_videodev
*vdev
= ofh
->vdev
;
1139 struct v4l2_queryctrl a_tmp
;
1140 int best_slave
= -1;
1141 u32 best_ctrl
= (u32
)-1;
1144 if (vdev
->vdev_sensor_config
.sensor_isp
)
1145 return vidioc_int_queryctrl(vdev
->vdev_sensor
, a
);
1147 /* No next flags: try slaves directly. */
1148 if (!(a
->id
& V4L2_CTRL_FLAG_NEXT_CTRL
)) {
1149 for (i
= 0; i
<= OMAP34XXCAM_SLAVE_FLASH
; i
++) {
1150 if (!vidioc_int_queryctrl(vdev
->slave
[i
], a
))
1153 return isp_queryctrl(a
);
1156 /* Find slave with smallest next control id. */
1157 for (i
= 0; i
<= OMAP34XXCAM_SLAVE_FLASH
; i
++) {
1160 if (vidioc_int_queryctrl(vdev
->slave
[i
], &a_tmp
))
1163 if (a_tmp
.id
< best_ctrl
) {
1165 best_ctrl
= a_tmp
.id
;
1170 if (!isp_queryctrl(&a_tmp
)) {
1171 if (a_tmp
.id
< best_ctrl
) {
1178 if (best_slave
== -1)
1182 return vidioc_int_queryctrl(vdev
->slave
[best_slave
], a
);
1186 * vidioc_querymenu - V4L2 query menu IOCTL handler
1187 * @file: ptr. to system file structure
1188 * @fh: ptr to hold address of omap34xxcam_fh struct (per-filehandle data)
1189 * @a: standard V4L2 query menu ioctl structure
1191 * If the requested control is supported, returns the menu information
1192 * in the v4l2_querymenu structure. Otherwise, returns -EINVAL if the
1193 * control is not supported or is not a menu. If the sensor being used
1194 * is a "smart sensor", this request is passed to the sensor driver,
1195 * otherwise the ISP is queried and if it does not support the requested
1196 * menu control, the request is forwarded to the "raw" sensor driver to
1197 * see if it supports it.
1199 static int vidioc_querymenu(struct file
*file
, void *fh
,
1200 struct v4l2_querymenu
*a
)
1202 struct omap34xxcam_fh
*ofh
= fh
;
1203 struct omap34xxcam_videodev
*vdev
= ofh
->vdev
;
1206 if (vdev
->vdev_sensor_config
.sensor_isp
)
1207 return vidioc_int_querymenu(vdev
->vdev_sensor
, a
);
1209 /* Try slaves directly. */
1210 for (i
= 0; i
<= OMAP34XXCAM_SLAVE_FLASH
; i
++) {
1211 if (!vidioc_int_querymenu(vdev
->slave
[i
], a
))
1214 return isp_querymenu(a
);
1217 static int vidioc_g_ext_ctrls(struct file
*file
, void *fh
,
1218 struct v4l2_ext_controls
*a
)
1220 struct omap34xxcam_fh
*ofh
= fh
;
1221 struct omap34xxcam_videodev
*vdev
= ofh
->vdev
;
1222 struct device
*isp
= vdev
->cam
->isp
;
1223 int i
, ctrl_idx
, rval
= 0;
1225 mutex_lock(&vdev
->mutex
);
1227 for (ctrl_idx
= 0; ctrl_idx
< a
->count
; ctrl_idx
++) {
1228 struct v4l2_control ctrl
;
1230 ctrl
.id
= a
->controls
[ctrl_idx
].id
;
1232 if (vdev
->vdev_sensor_config
.sensor_isp
) {
1233 rval
= vidioc_int_g_ctrl(vdev
->vdev_sensor
, &ctrl
);
1235 for (i
= 0; i
<= OMAP34XXCAM_SLAVE_FLASH
; i
++) {
1236 rval
= vidioc_int_g_ctrl(vdev
->slave
[i
], &ctrl
);
1243 rval
= isp_g_ctrl(isp
, &ctrl
);
1246 a
->error_idx
= ctrl_idx
;
1250 a
->controls
[ctrl_idx
].value
= ctrl
.value
;
1253 mutex_unlock(&vdev
->mutex
);
1258 static int vidioc_s_ext_ctrls(struct file
*file
, void *fh
,
1259 struct v4l2_ext_controls
*a
)
1261 struct omap34xxcam_fh
*ofh
= fh
;
1262 struct omap34xxcam_videodev
*vdev
= ofh
->vdev
;
1263 struct device
*isp
= vdev
->cam
->isp
;
1264 int i
, ctrl_idx
, rval
= 0;
1266 mutex_lock(&vdev
->mutex
);
1268 for (ctrl_idx
= 0; ctrl_idx
< a
->count
; ctrl_idx
++) {
1269 struct v4l2_control ctrl
;
1271 ctrl
.id
= a
->controls
[ctrl_idx
].id
;
1272 ctrl
.value
= a
->controls
[ctrl_idx
].value
;
1274 if (vdev
->vdev_sensor_config
.sensor_isp
) {
1275 rval
= vidioc_int_s_ctrl(vdev
->vdev_sensor
, &ctrl
);
1277 for (i
= 0; i
<= OMAP34XXCAM_SLAVE_FLASH
; i
++) {
1278 rval
= vidioc_int_s_ctrl(vdev
->slave
[i
], &ctrl
);
1285 rval
= isp_s_ctrl(isp
, &ctrl
);
1288 a
->error_idx
= ctrl_idx
;
1292 a
->controls
[ctrl_idx
].value
= ctrl
.value
;
1295 mutex_unlock(&vdev
->mutex
);
1301 * vidioc_g_parm - V4L2 get parameters IOCTL handler
1302 * @file: ptr. to system file structure
1303 * @fh: ptr to hold address of omap34xxcam_fh struct (per-filehandle data)
1304 * @a: standard V4L2 stream parameters structure
1306 * If request is for video capture buffer type, handles request by
1307 * forwarding to sensor driver.
1309 static int vidioc_g_parm(struct file
*file
, void *fh
, struct v4l2_streamparm
*a
)
1311 struct omap34xxcam_fh
*ofh
= fh
;
1312 struct omap34xxcam_videodev
*vdev
= ofh
->vdev
;
1315 if (a
->type
!= V4L2_BUF_TYPE_VIDEO_CAPTURE
)
1318 mutex_lock(&vdev
->mutex
);
1319 rval
= vidioc_int_g_parm(vdev
->vdev_sensor
, a
);
1320 mutex_unlock(&vdev
->mutex
);
1326 * vidioc_s_parm - V4L2 set parameters IOCTL handler
1327 * @file: ptr. to system file structure
1328 * @fh: ptr to hold address of omap34xxcam_fh struct (per-filehandle data)
1329 * @a: standard V4L2 stream parameters structure
1331 * If request is for video capture buffer type, handles request by
1332 * first getting current stream parameters from sensor, then forwarding
1333 * request to set new parameters to sensor driver. It then attempts to
1334 * enable the sensor interface with the new parameters. If this fails, it
1335 * reverts back to the previous parameters.
1337 static int vidioc_s_parm(struct file
*file
, void *fh
, struct v4l2_streamparm
*a
)
1339 struct omap34xxcam_fh
*ofh
= fh
;
1340 struct omap34xxcam_videodev
*vdev
= ofh
->vdev
;
1341 struct v4l2_pix_format pix_tmp_sensor
, pix_tmp
;
1344 if (a
->type
!= V4L2_BUF_TYPE_VIDEO_CAPTURE
)
1347 if (vdev
->vdev_sensor
== v4l2_int_device_dummy())
1350 mutex_lock(&vdev
->mutex
);
1351 if (vdev
->streaming
) {
1356 vdev
->want_timeperframe
= a
->parm
.capture
.timeperframe
;
1358 pix_tmp
= vdev
->want_pix
;
1360 rval
= s_pix_parm(vdev
, &pix_tmp_sensor
, &pix_tmp
,
1361 &a
->parm
.capture
.timeperframe
);
1364 mutex_unlock(&vdev
->mutex
);
1370 * vidioc_cropcap - V4L2 crop capture IOCTL handler
1371 * @file: ptr. to system file structure
1372 * @fh: ptr to hold address of omap34xxcam_fh struct (per-filehandle data)
1373 * @a: standard V4L2 crop capture structure
1375 * If using a "smart" sensor, just forwards request to the sensor driver,
1376 * otherwise fills in the v4l2_cropcap values locally.
1378 static int vidioc_cropcap(struct file
*file
, void *fh
, struct v4l2_cropcap
*a
)
1380 struct omap34xxcam_fh
*ofh
= fh
;
1381 struct omap34xxcam_videodev
*vdev
= ofh
->vdev
;
1382 struct v4l2_cropcap
*cropcap
= a
;
1385 if (vdev
->vdev_sensor
== v4l2_int_device_dummy())
1388 mutex_lock(&vdev
->mutex
);
1390 rval
= vidioc_int_cropcap(vdev
->vdev_sensor
, a
);
1392 if (rval
&& !vdev
->vdev_sensor_config
.sensor_isp
) {
1393 struct v4l2_format f
;
1395 /* cropcap failed, try to do this via g_fmt_cap */
1396 rval
= vidioc_int_g_fmt_cap(vdev
->vdev_sensor
, &f
);
1398 cropcap
->bounds
.top
= 0;
1399 cropcap
->bounds
.left
= 0;
1400 cropcap
->bounds
.width
= f
.fmt
.pix
.width
;
1401 cropcap
->bounds
.height
= f
.fmt
.pix
.height
;
1402 cropcap
->defrect
= cropcap
->bounds
;
1403 cropcap
->pixelaspect
.numerator
= 1;
1404 cropcap
->pixelaspect
.denominator
= 1;
1408 mutex_unlock(&vdev
->mutex
);
1414 * vidioc_g_crop - V4L2 get capture crop IOCTL handler
1415 * @file: ptr. to system file structure
1416 * @fh: ptr to hold address of omap34xxcam_fh struct (per-filehandle data)
1417 * @a: standard V4L2 crop structure
1419 * If using a "smart" sensor, just forwards request to the sensor driver,
1420 * otherwise calls the isp functions to fill in current crop values.
1422 static int vidioc_g_crop(struct file
*file
, void *fh
, struct v4l2_crop
*a
)
1424 struct omap34xxcam_fh
*ofh
= fh
;
1425 struct omap34xxcam_videodev
*vdev
= ofh
->vdev
;
1426 struct device
*isp
= vdev
->cam
->isp
;
1429 if (vdev
->vdev_sensor
== v4l2_int_device_dummy())
1432 mutex_lock(&vdev
->mutex
);
1434 if (vdev
->vdev_sensor_config
.sensor_isp
)
1435 rval
= vidioc_int_g_crop(vdev
->vdev_sensor
, a
);
1437 rval
= isp_g_crop(isp
, a
);
1439 mutex_unlock(&vdev
->mutex
);
1445 * vidioc_s_crop - V4L2 set capture crop IOCTL handler
1446 * @file: ptr. to system file structure
1447 * @fh: ptr to hold address of omap34xxcam_fh struct (per-filehandle data)
1448 * @a: standard V4L2 crop structure
1450 * If using a "smart" sensor, just forwards request to the sensor driver,
1451 * otherwise calls the isp functions to set the current crop values.
1453 static int vidioc_s_crop(struct file
*file
, void *fh
, struct v4l2_crop
*a
)
1455 struct omap34xxcam_fh
*ofh
= fh
;
1456 struct omap34xxcam_videodev
*vdev
= ofh
->vdev
;
1457 struct device
*isp
= vdev
->cam
->isp
;
1460 if (vdev
->vdev_sensor
== v4l2_int_device_dummy())
1463 mutex_lock(&vdev
->mutex
);
1465 if (vdev
->vdev_sensor_config
.sensor_isp
)
1466 rval
= vidioc_int_s_crop(vdev
->vdev_sensor
, a
);
1468 rval
= isp_s_crop(isp
, a
);
1470 mutex_unlock(&vdev
->mutex
);
1475 static int vidioc_enum_framesizes(struct file
*file
, void *fh
,
1476 struct v4l2_frmsizeenum
*frms
)
1478 struct omap34xxcam_fh
*ofh
= fh
;
1479 struct omap34xxcam_videodev
*vdev
= ofh
->vdev
;
1483 mutex_lock(&vdev
->mutex
);
1485 if (vdev
->vdev_sensor_config
.sensor_isp
) {
1486 rval
= vidioc_int_enum_framesizes(vdev
->vdev_sensor
, frms
);
1488 pixel_format
= frms
->pixel_format
;
1489 frms
->pixel_format
= -1; /* ISP does format conversion */
1490 rval
= vidioc_int_enum_framesizes(vdev
->vdev_sensor
, frms
);
1491 frms
->pixel_format
= pixel_format
;
1494 mutex_unlock(&vdev
->mutex
);
1498 static int vidioc_enum_frameintervals(struct file
*file
, void *fh
,
1499 struct v4l2_frmivalenum
*frmi
)
1501 struct omap34xxcam_fh
*ofh
= fh
;
1502 struct omap34xxcam_videodev
*vdev
= ofh
->vdev
;
1506 mutex_lock(&vdev
->mutex
);
1508 if (vdev
->vdev_sensor_config
.sensor_isp
) {
1509 rval
= vidioc_int_enum_frameintervals(vdev
->vdev_sensor
, frmi
);
1511 pixel_format
= frmi
->pixel_format
;
1512 frmi
->pixel_format
= -1; /* ISP does format conversion */
1513 rval
= vidioc_int_enum_frameintervals(vdev
->vdev_sensor
, frmi
);
1514 frmi
->pixel_format
= pixel_format
;
1517 mutex_unlock(&vdev
->mutex
);
1522 * vidioc_querystd - V4L2 query current standard IOCTL handler
1523 * @file: ptr. to system file structure
1524 * @fh: ptr to hold address of omap34xxcam_fh struct (per-filehandle data)
1525 * @std: standard V4L2 v4l2_std_id enum
1527 * If using a "smart" sensor, just forwards request to the sensor driver,
1528 * otherwise returns error
1530 static int vidioc_querystd(struct file
*file
, void *fh
, v4l2_std_id
*std
)
1532 struct omap34xxcam_fh
*ofh
= fh
;
1533 struct omap34xxcam_videodev
*vdev
= ofh
->vdev
;
1536 mutex_lock(&vdev
->mutex
);
1537 if (vdev
->vdev_sensor_mode
) {
1538 rval
= vidioc_int_querystd(vdev
->vdev_sensor
, std
);
1540 vdev
->vfd
->current_norm
= *std
;
1543 mutex_unlock(&vdev
->mutex
);
1549 * vidioc_s_std - V4L2 set standard IOCTL handler
1550 * @file: ptr. to system file structure
1551 * @fh: ptr to hold address of omap34xxcam_fh struct (per-filehandle data)
1552 * @std: standard V4L2 v4l2_std_id enum
1554 * If using a "smart" sensor, just forwards request to the sensor driver,
1555 * otherwise returns error
1557 static int vidioc_s_std(struct file
*file
, void *fh
, v4l2_std_id
*std
)
1559 struct omap34xxcam_fh
*ofh
= fh
;
1560 struct omap34xxcam_videodev
*vdev
= ofh
->vdev
;
1563 mutex_lock(&vdev
->mutex
);
1564 if (vdev
->vdev_sensor_mode
) {
1565 rval
= vidioc_int_s_std(vdev
->vdev_sensor
, std
);
1567 vdev
->vfd
->current_norm
= *std
;
1570 mutex_unlock(&vdev
->mutex
);
1576 * vidioc_default - private IOCTL handler
1577 * @file: ptr. to system file structure
1578 * @fh: ptr to hold address of omap34xxcam_fh struct (per-filehandle data)
1579 * @cmd: ioctl cmd value
1580 * @arg: ioctl arg value
1582 * If the sensor being used is a "smart sensor", this request is returned to
1583 * caller with -EINVAL err code. Otherwise if the control id is the private
1584 * VIDIOC_PRIVATE_ISP_AEWB_REQ to update the analog gain or exposure,
1585 * then this request is forwared directly to the sensor to incorporate the
1586 * feedback. The request is then passed on to the ISP private IOCTL handler,
1587 * isp_handle_private()
1589 static long vidioc_default(struct file
*file
, void *fh
, int cmd
, void *arg
)
1591 struct omap34xxcam_fh
*ofh
= file
->private_data
;
1592 struct omap34xxcam_videodev
*vdev
= ofh
->vdev
;
1593 struct device
*isp
= vdev
->cam
->isp
;
1596 if (cmd
== VIDIOC_PRIVATE_OMAP34XXCAM_SENSOR_INFO
) {
1598 struct v4l2_pix_format active_size
, full_size
;
1599 struct omap34xxcam_sensor_info
*ret_sensor_info
;
1601 ret_sensor_info
= (struct omap34xxcam_sensor_info
*)arg
;
1602 mutex_lock(&vdev
->mutex
);
1603 rval
= vidioc_int_priv_g_pixclk(vdev
->vdev_sensor
, &pixclk
);
1604 mutex_unlock(&vdev
->mutex
);
1607 mutex_lock(&vdev
->mutex
);
1608 rval
= vidioc_int_priv_g_activesize(vdev
->vdev_sensor
,
1610 mutex_unlock(&vdev
->mutex
);
1613 mutex_lock(&vdev
->mutex
);
1614 rval
= vidioc_int_priv_g_fullsize(vdev
->vdev_sensor
,
1616 mutex_unlock(&vdev
->mutex
);
1619 ret_sensor_info
->current_xclk
= pixclk
;
1620 memcpy(&ret_sensor_info
->active_size
, &active_size
,
1621 sizeof(struct v4l2_pix_format
));
1622 memcpy(&ret_sensor_info
->full_size
, &full_size
,
1623 sizeof(struct v4l2_pix_format
));
1628 if (vdev
->vdev_sensor_config
.sensor_isp
) {
1632 case VIDIOC_PRIVATE_ISP_AEWB_REQ
:
1634 /* Need to update sensor first */
1635 struct isph3a_aewb_data
*data
;
1636 struct v4l2_control vc
;
1638 data
= (struct isph3a_aewb_data
*) arg
;
1639 if (data
->update
& SET_EXPOSURE
) {
1640 dev_dbg(&vdev
->vfd
->dev
, "using "
1641 "VIDIOC_PRIVATE_ISP_AEWB_REQ to set "
1642 "exposure is deprecated!\n");
1643 vc
.id
= V4L2_CID_EXPOSURE
;
1644 vc
.value
= data
->shutter
;
1645 mutex_lock(&vdev
->mutex
);
1646 rval
= vidioc_int_s_ctrl(vdev
->vdev_sensor
,
1648 mutex_unlock(&vdev
->mutex
);
1652 if (data
->update
& SET_ANALOG_GAIN
) {
1653 dev_dbg(&vdev
->vfd
->dev
, "using "
1654 "VIDIOC_PRIVATE_ISP_AEWB_REQ to set "
1655 "gain is deprecated!\n");
1656 vc
.id
= V4L2_CID_GAIN
;
1657 vc
.value
= data
->gain
;
1658 mutex_lock(&vdev
->mutex
);
1659 rval
= vidioc_int_s_ctrl(vdev
->vdev_sensor
,
1661 mutex_unlock(&vdev
->mutex
);
1667 case VIDIOC_PRIVATE_ISP_AF_REQ
: {
1668 /* Need to update lens first */
1669 struct isp_af_data
*data
;
1670 struct v4l2_control vc
;
1672 if (!vdev
->vdev_lens
) {
1676 data
= (struct isp_af_data
*) arg
;
1677 if (data
->update
& LENS_DESIRED_POSITION
) {
1678 dev_dbg(&vdev
->vfd
->dev
, "using "
1679 "VIDIOC_PRIVATE_ISP_AF_REQ to set "
1680 "lens position is deprecated!\n");
1681 vc
.id
= V4L2_CID_FOCUS_ABSOLUTE
;
1682 vc
.value
= data
->desired_lens_direction
;
1683 mutex_lock(&vdev
->mutex
);
1684 rval
= vidioc_int_s_ctrl(vdev
->vdev_lens
, &vc
);
1685 mutex_unlock(&vdev
->mutex
);
1693 mutex_lock(&vdev
->mutex
);
1694 rval
= isp_handle_private(isp
, cmd
, arg
);
1695 mutex_unlock(&vdev
->mutex
);
1708 * omap34xxcam_poll - file operations poll handler
1709 * @file: ptr. to system file structure
1710 * @wait: system poll table structure
1713 static unsigned int omap34xxcam_poll(struct file
*file
,
1714 struct poll_table_struct
*wait
)
1716 struct omap34xxcam_fh
*fh
= file
->private_data
;
1717 struct omap34xxcam_videodev
*vdev
= fh
->vdev
;
1718 struct videobuf_buffer
*vb
;
1720 mutex_lock(&vdev
->mutex
);
1721 if (vdev
->streaming
!= file
) {
1722 mutex_unlock(&vdev
->mutex
);
1725 mutex_unlock(&vdev
->mutex
);
1727 mutex_lock(&fh
->vbq
.vb_lock
);
1728 if (list_empty(&fh
->vbq
.stream
)) {
1729 mutex_unlock(&fh
->vbq
.vb_lock
);
1732 vb
= list_entry(fh
->vbq
.stream
.next
, struct videobuf_buffer
, stream
);
1733 mutex_unlock(&fh
->vbq
.vb_lock
);
1735 poll_wait(file
, &vb
->done
, wait
);
1737 if (vb
->state
== VIDEOBUF_DONE
|| vb
->state
== VIDEOBUF_ERROR
)
1738 return POLLIN
| POLLRDNORM
;
1744 * omap34xxcam_mmap - file operations mmap handler
1745 * @file: ptr. to system file structure
1746 * @vma: system virt. mem. area structure
1748 * Maps a virtual memory area via the video buffer API
1750 static int omap34xxcam_mmap(struct file
*file
, struct vm_area_struct
*vma
)
1752 struct omap34xxcam_fh
*fh
= file
->private_data
;
1753 return videobuf_mmap_mapper(&fh
->vbq
, vma
);
1757 * omap34xxcam_open - file operations open handler
1758 * @inode: ptr. to system inode structure
1759 * @file: ptr. to system file structure
1761 * Allocates and initializes the per-filehandle data (omap34xxcam_fh),
1762 * enables the sensor, opens/initializes the ISP interface and the
1763 * video buffer queue. Note that this function will allow multiple
1764 * file handles to be open simultaneously, however only the first
1765 * handle opened will initialize the ISP. It is the application
1766 * responsibility to only use one handle for streaming and the others
1768 * This function returns 0 upon success and -ENODEV upon error.
1770 static int omap34xxcam_open(struct file
*file
)
1773 struct omap34xxcam_videodev
*vdev
= NULL
;
1774 struct omap34xxcam_device
*cam
= omap34xxcam
;
1776 struct omap34xxcam_fh
*fh
;
1777 struct v4l2_format sensor_format
;
1781 for (i
= 0; i
< OMAP34XXCAM_VIDEODEVS
; i
++) {
1782 if (cam
->vdevs
[i
].vfd
1783 && cam
->vdevs
[i
].vfd
->minor
==
1784 iminor(file
->f_dentry
->d_inode
)) {
1785 vdev
= &cam
->vdevs
[i
];
1790 if (!vdev
|| !vdev
->vfd
)
1793 fh
= kzalloc(sizeof(*fh
), GFP_KERNEL
);
1799 mutex_lock(&vdev
->mutex
);
1800 for (i
= 0; i
<= OMAP34XXCAM_SLAVE_FLASH
; i
++) {
1801 if (vdev
->slave
[i
] != v4l2_int_device_dummy()
1802 && !try_module_get(vdev
->slave
[i
]->module
)) {
1803 mutex_unlock(&vdev
->mutex
);
1804 dev_err(&vdev
->vfd
->dev
, "can't try_module_get %s\n",
1805 vdev
->slave
[i
]->name
);
1807 goto out_try_module_get
;
1811 if (atomic_inc_return(&vdev
->users
) == 1) {
1816 dev_err(&vdev
->vfd
->dev
, "can't get isp\n");
1820 if (omap34xxcam_slave_power_set(vdev
, V4L2_POWER_ON
,
1821 OMAP34XXCAM_SLAVE_POWER_ALL
)) {
1822 dev_err(&vdev
->vfd
->dev
, "can't power up slaves\n");
1824 goto out_slave_power_set_standby
;
1826 omap34xxcam_slave_power_set(
1827 vdev
, V4L2_POWER_STANDBY
,
1828 OMAP34XXCAM_SLAVE_POWER_SENSOR
);
1829 omap34xxcam_slave_power_suggest(
1830 vdev
, V4L2_POWER_STANDBY
,
1831 OMAP34XXCAM_SLAVE_POWER_LENS
);
1834 if (vdev
->vdev_sensor
== v4l2_int_device_dummy() || !first_user
)
1837 if (vdev
->vdev_sensor_config
.sensor_isp
) {
1838 if ((vdev
->slave_config
[OMAP34XXCAM_SLAVE_SENSOR
].cur_input
1839 != INPUT_CVBS_VI4A
) &&
1840 (vdev
->slave_config
[OMAP34XXCAM_SLAVE_SENSOR
].
1841 cur_input
!= INPUT_SVIDEO_VI2C_VI1C
)) {
1842 struct v4l2_routing route
;
1844 route
.input
= INPUT_CVBS_VI4A
;
1846 rval
= vidioc_int_s_video_routing(vdev
->vdev_sensor
,
1849 route
.input
= INPUT_SVIDEO_VI2C_VI1C
;
1850 rval
= vidioc_int_s_video_routing(
1851 vdev
->vdev_sensor
, &route
);
1854 vdev
->slave_config
[OMAP34XXCAM_SLAVE_SENSOR
]
1855 .cur_input
= route
.input
;
1857 sensor_format
.type
= V4L2_BUF_TYPE_VIDEO_CAPTURE
;
1860 /* Get the format the sensor is using. */
1861 rval
= vidioc_int_g_fmt_cap(vdev
->vdev_sensor
, &sensor_format
);
1863 dev_err(&vdev
->vfd
->dev
,
1864 "can't get current pix from sensor!\n");
1865 goto out_vidioc_int_g_fmt_cap
;
1868 if (!vdev
->pix
.width
)
1869 vdev
->pix
= sensor_format
.fmt
.pix
;
1871 if (!vdev
->vdev_sensor_config
.sensor_isp
) {
1872 struct v4l2_pix_format pix
;
1873 struct v4l2_fract timeperframe
=
1874 vdev
->want_timeperframe
;
1876 rval
= s_pix_parm(vdev
, &pix
, &vdev
->pix
, &timeperframe
);
1878 dev_err(&vdev
->vfd
->dev
,
1879 "isp doesn't like the sensor!\n");
1880 goto out_isp_s_fmt_cap
;
1885 mutex_unlock(&vdev
->mutex
);
1887 file
->private_data
= fh
;
1889 spin_lock_init(&fh
->vbq_lock
);
1891 videobuf_queue_sg_init(&fh
->vbq
, &omap34xxcam_vbq_ops
, NULL
,
1892 &fh
->vbq_lock
, V4L2_BUF_TYPE_VIDEO_CAPTURE
,
1894 sizeof(struct videobuf_buffer
), fh
);
1899 out_vidioc_int_g_fmt_cap
:
1900 omap34xxcam_slave_power_set(vdev
, V4L2_POWER_OFF
,
1901 OMAP34XXCAM_SLAVE_POWER_ALL
);
1902 out_slave_power_set_standby
:
1906 atomic_dec(&vdev
->users
);
1907 mutex_unlock(&vdev
->mutex
);
1910 for (i
--; i
>= 0; i
--)
1911 if (vdev
->slave
[i
] != v4l2_int_device_dummy())
1912 module_put(vdev
->slave
[i
]->module
);
1920 * omap34xxcam_release - file operations release handler
1921 * @inode: ptr. to system inode structure
1922 * @file: ptr. to system file structure
1924 * Complement of omap34xxcam_open. This function will flush any scheduled
1925 * work, disable the sensor, close the ISP interface, stop the
1926 * video buffer queue from streaming and free the per-filehandle data
1927 * (omap34xxcam_fh). Note that because multiple open file handles
1928 * are allowed, this function will only close the ISP and disable the
1929 * sensor when the last open file handle (by count) is closed.
1930 * This function returns 0.
1932 static int omap34xxcam_release(struct file
*file
)
1934 struct omap34xxcam_fh
*fh
= file
->private_data
;
1935 struct omap34xxcam_videodev
*vdev
= fh
->vdev
;
1936 struct device
*isp
= vdev
->cam
->isp
;
1939 mutex_lock(&vdev
->mutex
);
1940 if (vdev
->streaming
== file
) {
1942 videobuf_streamoff(&fh
->vbq
);
1943 omap34xxcam_slave_power_set(
1944 vdev
, V4L2_POWER_STANDBY
,
1945 OMAP34XXCAM_SLAVE_POWER_SENSOR
);
1946 omap34xxcam_slave_power_suggest(
1947 vdev
, V4L2_POWER_STANDBY
,
1948 OMAP34XXCAM_SLAVE_POWER_LENS
);
1949 vdev
->streaming
= NULL
;
1952 if (atomic_dec_return(&vdev
->users
) == 0) {
1953 omap34xxcam_slave_power_set(vdev
, V4L2_POWER_OFF
,
1954 OMAP34XXCAM_SLAVE_POWER_ALL
);
1957 mutex_unlock(&vdev
->mutex
);
1959 file
->private_data
= NULL
;
1961 for (i
= 0; i
<= OMAP34XXCAM_SLAVE_FLASH
; i
++)
1962 if (vdev
->slave
[i
] != v4l2_int_device_dummy())
1963 module_put(vdev
->slave
[i
]->module
);
1970 static struct v4l2_file_operations omap34xxcam_fops
= {
1971 .owner
= THIS_MODULE
,
1972 .unlocked_ioctl
= video_ioctl2
,
1973 .poll
= omap34xxcam_poll
,
1974 .mmap
= omap34xxcam_mmap
,
1975 .open
= omap34xxcam_open
,
1976 .release
= omap34xxcam_release
,
1979 static void omap34xxcam_vfd_name_update(struct omap34xxcam_videodev
*vdev
)
1981 struct video_device
*vfd
= vdev
->vfd
;
1984 strlcpy(vfd
->name
, CAM_SHORT_NAME
, sizeof(vfd
->name
));
1985 for (i
= 0; i
<= OMAP34XXCAM_SLAVE_FLASH
; i
++) {
1986 strlcat(vfd
->name
, "/", sizeof(vfd
->name
));
1987 if (vdev
->slave
[i
] == v4l2_int_device_dummy())
1989 strlcat(vfd
->name
, vdev
->slave
[i
]->name
, sizeof(vfd
->name
));
1991 dev_dbg(&vdev
->vfd
->dev
, "video%d is now %s\n", vfd
->num
, vfd
->name
);
1995 * omap34xxcam_device_unregister - V4L2 detach handler
1996 * @s: ptr. to standard V4L2 device information structure
1998 * Detach sensor and unregister and release the video device.
2000 static void omap34xxcam_device_unregister(struct v4l2_int_device
*s
)
2002 struct omap34xxcam_videodev
*vdev
= s
->u
.slave
->master
->priv
;
2003 struct omap34xxcam_hw_config hwc
;
2005 BUG_ON(vidioc_int_g_priv(s
, &hwc
) < 0);
2007 mutex_lock(&vdev
->mutex
);
2009 if (vdev
->slave
[hwc
.dev_type
] != v4l2_int_device_dummy()) {
2010 vdev
->slave
[hwc
.dev_type
] = v4l2_int_device_dummy();
2012 omap34xxcam_vfd_name_update(vdev
);
2015 if (vdev
->slaves
== 0 && vdev
->vfd
) {
2016 if (vdev
->vfd
->minor
== -1) {
2018 * The device was never registered, so release the
2019 * video_device struct directly.
2021 video_device_release(vdev
->vfd
);
2024 * The unregister function will release the
2025 * video_device struct as well as
2028 video_unregister_device(vdev
->vfd
);
2033 mutex_unlock(&vdev
->mutex
);
2036 static const struct v4l2_ioctl_ops omap34xxcam_ioctl_ops
= {
2037 .vidioc_querycap
= vidioc_querycap
,
2038 .vidioc_enum_fmt_vid_cap
= vidioc_enum_fmt_vid_cap
,
2039 .vidioc_g_fmt_vid_cap
= vidioc_g_fmt_vid_cap
,
2040 .vidioc_s_fmt_vid_cap
= vidioc_s_fmt_vid_cap
,
2041 .vidioc_try_fmt_vid_cap
= vidioc_try_fmt_vid_cap
,
2042 .vidioc_reqbufs
= vidioc_reqbufs
,
2043 .vidioc_querybuf
= vidioc_querybuf
,
2044 .vidioc_qbuf
= vidioc_qbuf
,
2045 .vidioc_dqbuf
= vidioc_dqbuf
,
2046 .vidioc_streamon
= vidioc_streamon
,
2047 .vidioc_streamoff
= vidioc_streamoff
,
2048 .vidioc_enum_input
= vidioc_enum_input
,
2049 .vidioc_g_input
= vidioc_g_input
,
2050 .vidioc_s_input
= vidioc_s_input
,
2051 .vidioc_queryctrl
= vidioc_queryctrl
,
2052 .vidioc_querymenu
= vidioc_querymenu
,
2053 .vidioc_g_ext_ctrls
= vidioc_g_ext_ctrls
,
2054 .vidioc_s_ext_ctrls
= vidioc_s_ext_ctrls
,
2055 .vidioc_g_parm
= vidioc_g_parm
,
2056 .vidioc_s_parm
= vidioc_s_parm
,
2057 .vidioc_cropcap
= vidioc_cropcap
,
2058 .vidioc_g_crop
= vidioc_g_crop
,
2059 .vidioc_s_crop
= vidioc_s_crop
,
2060 .vidioc_enum_framesizes
= vidioc_enum_framesizes
,
2061 .vidioc_enum_frameintervals
= vidioc_enum_frameintervals
,
2062 .vidioc_s_std
= vidioc_s_std
,
2063 .vidioc_querystd
= vidioc_querystd
,
2064 .vidioc_default
= vidioc_default
,
2068 * omap34xxcam_device_register - V4L2 attach handler
2069 * @s: ptr. to standard V4L2 device information structure
2071 * Allocates and initializes the V4L2 video_device structure, initializes
2072 * the sensor, and finally
2073 registers the device with V4L2 based on the
2074 * video_device structure.
2076 * Returns 0 on success, otherwise an appropriate error code on
2079 static int omap34xxcam_device_register(struct v4l2_int_device
*s
)
2081 struct omap34xxcam_videodev
*vdev
= s
->u
.slave
->master
->priv
;
2082 struct omap34xxcam_hw_config hwc
;
2083 struct v4l2_ifparm ifparm
;
2087 /* We need to check rval just once. The place is here. */
2088 if (vidioc_int_g_priv(s
, &hwc
))
2091 if (vdev
->index
!= hwc
.dev_index
)
2094 if (hwc
.dev_type
< 0 || hwc
.dev_type
> OMAP34XXCAM_SLAVE_FLASH
)
2097 if (vdev
->slave
[hwc
.dev_type
] != v4l2_int_device_dummy())
2100 mutex_lock(&vdev
->mutex
);
2101 if (atomic_read(&vdev
->users
)) {
2102 printk(KERN_ERR
"%s: we're open (%d), can't register\n",
2103 __func__
, atomic_read(&vdev
->users
));
2104 mutex_unlock(&vdev
->mutex
);
2110 vdev
->slave
[hwc
.dev_type
] = s
;
2111 vdev
->slave_config
[hwc
.dev_type
] = hwc
;
2113 if (hwc
.dev_type
== OMAP34XXCAM_SLAVE_SENSOR
) {
2117 printk(KERN_ERR
"%s: can't get ISP, "
2118 "sensor init failed\n", __func__
);
2121 vdev
->cam
->isp
= isp
;
2123 rval
= omap34xxcam_slave_power_set(vdev
, V4L2_POWER_ON
,
2126 goto err_omap34xxcam_slave_power_set
;
2127 if (hwc
.dev_type
== OMAP34XXCAM_SLAVE_SENSOR
) {
2128 struct v4l2_format format
;
2130 format
.type
= V4L2_BUF_TYPE_VIDEO_CAPTURE
;
2131 rval
= vidioc_int_g_fmt_cap(vdev
->vdev_sensor
, &format
);
2135 vdev
->want_pix
= format
.fmt
.pix
;
2137 omap34xxcam_slave_power_set(vdev
, V4L2_POWER_OFF
, 1 << hwc
.dev_type
);
2138 if (hwc
.dev_type
== OMAP34XXCAM_SLAVE_SENSOR
)
2144 /* Are we the first slave? */
2145 if (vdev
->slaves
== 1) {
2146 /* initialize the video_device struct */
2147 vdev
->vfd
= video_device_alloc();
2149 printk(KERN_ERR
"%s: could not allocate "
2150 "video device struct\n", __func__
);
2154 vdev
->vfd
->release
= video_device_release
;
2155 vdev
->vfd
->minor
= -1;
2156 vdev
->vfd
->fops
= &omap34xxcam_fops
;
2157 vdev
->vfd
->ioctl_ops
= &omap34xxcam_ioctl_ops
;
2158 video_set_drvdata(vdev
->vfd
, vdev
);
2160 if (video_register_device(vdev
->vfd
, VFL_TYPE_GRABBER
,
2161 hwc
.dev_minor
) < 0) {
2162 printk(KERN_ERR
"%s: could not register V4L device\n",
2164 vdev
->vfd
->minor
= -1;
2169 /*Determine whether the slave connected is BT656 decoder or a sensor*/
2170 if (!vidioc_int_g_ifparm(s
, &ifparm
)) {
2171 if (ifparm
.if_type
== V4L2_IF_TYPE_BT656
) {
2172 vdev
->vfd
->current_norm
= V4L2_STD_NTSC
;
2173 vdev
->vfd
->tvnorms
= V4L2_STD_NTSC
| V4L2_STD_PAL
;
2174 if ((ifparm
.u
.bt656
.mode
==
2175 V4L2_IF_TYPE_BT656_MODE_BT_8BIT
) ||
2176 (ifparm
.u
.bt656
.mode
==
2177 V4L2_IF_TYPE_BT656_MODE_BT_10BIT
))
2178 vdev
->slave_mode
[hwc
.dev_type
] = 1;
2181 omap34xxcam_vfd_name_update(vdev
);
2183 mutex_unlock(&vdev
->mutex
);
2187 err_omap34xxcam_slave_power_set
:
2188 if (hwc
.dev_type
== OMAP34XXCAM_SLAVE_SENSOR
)
2192 if (s
== vdev
->slave
[hwc
.dev_type
]) {
2193 vdev
->slave
[hwc
.dev_type
] = v4l2_int_device_dummy();
2197 mutex_unlock(&vdev
->mutex
);
2198 omap34xxcam_device_unregister(s
);
2203 static struct v4l2_int_master omap34xxcam_master
= {
2204 .attach
= omap34xxcam_device_register
,
2205 .detach
= omap34xxcam_device_unregister
,
2210 * Module initialisation and deinitialisation
2214 static void omap34xxcam_exit(void)
2216 struct omap34xxcam_device
*cam
= omap34xxcam
;
2222 for (i
= 0; i
< OMAP34XXCAM_VIDEODEVS
; i
++) {
2223 if (cam
->vdevs
[i
].cam
== NULL
)
2226 v4l2_int_device_unregister(&cam
->vdevs
[i
].master
);
2227 cam
->vdevs
[i
].cam
= NULL
;
2235 static int __init
omap34xxcam_init(void)
2237 struct omap34xxcam_device
*cam
;
2240 cam
= kzalloc(sizeof(*cam
), GFP_KERNEL
);
2242 printk(KERN_ERR
"%s: could not allocate memory\n", __func__
);
2248 for (i
= 0; i
< OMAP34XXCAM_VIDEODEVS
; i
++) {
2249 struct omap34xxcam_videodev
*vdev
= &cam
->vdevs
[i
];
2250 struct v4l2_int_device
*m
= &vdev
->master
;
2252 m
->module
= THIS_MODULE
;
2253 strlcpy(m
->name
, CAM_NAME
, sizeof(m
->name
));
2254 m
->type
= v4l2_int_type_master
;
2255 m
->u
.master
= &omap34xxcam_master
;
2258 mutex_init(&vdev
->mutex
);
2263 vdev
->vdev_flash
= v4l2_int_device_dummy();
2264 #ifdef OMAP34XXCAM_POWEROFF_DELAY
2265 setup_timer(&vdev
->poweroff_timer
,
2266 omap34xxcam_slave_power_timer
, (unsigned long)vdev
);
2267 INIT_WORK(&vdev
->poweroff_work
, omap34xxcam_slave_power_work
);
2268 #endif /* OMAP34XXCAM_POWEROFF_DELAY */
2270 if (v4l2_int_device_register(m
))
2281 MODULE_AUTHOR("Sakari Ailus <sakari.ailus@nokia.com>");
2282 MODULE_DESCRIPTION("OMAP34xx Video for Linux camera driver");
2283 MODULE_LICENSE("GPL");
2285 late_initcall(omap34xxcam_init
);
2286 module_exit(omap34xxcam_exit
);