1 // SPDX-License-Identifier: GPL-2.0
3 * Support for Medifield PNW Camera Imaging ISP subsystem.
5 * Copyright (c) 2010 Intel Corporation. All Rights Reserved.
7 * Copyright (c) 2010 Silicon Hive www.siliconhive.com.
9 * This program is free software; you can redistribute it and/or
10 * modify it under the terms of the GNU General Public License version
11 * 2 as published by the Free Software Foundation.
13 * This program is distributed in the hope that it will be useful,
14 * but WITHOUT ANY WARRANTY; without even the implied warranty of
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 * GNU General Public License for more details.
21 #include <linux/delay.h>
22 #include <linux/pci.h>
24 #include <media/v4l2-ioctl.h>
25 #include <media/v4l2-event.h>
26 #include <media/videobuf-vmalloc.h>
28 #include "atomisp_acc.h"
29 #include "atomisp_cmd.h"
30 #include "atomisp_common.h"
31 #include "atomisp_fops.h"
32 #include "atomisp_internal.h"
33 #include "atomisp_ioctl.h"
34 #include "atomisp-regs.h"
35 #include "atomisp_compat.h"
37 #include "sh_css_hrt.h"
39 #include "gp_device.h"
40 #include "device_access.h"
43 static const char *DRIVER = "atomisp"; /* max size 15 */
44 static const char *CARD = "ATOM ISP"; /* max size 31 */
47 * FIXME: ISP should not know beforehand all CIDs supported by sensor.
48 * Instead, it needs to propagate to sensor unkonwn CIDs.
50 static struct v4l2_queryctrl ci_v4l2_controls[] = {
52 .id = V4L2_CID_AUTO_WHITE_BALANCE,
53 .type = V4L2_CTRL_TYPE_BOOLEAN,
54 .name = "Automatic White Balance",
61 .id = V4L2_CID_RED_BALANCE,
62 .type = V4L2_CTRL_TYPE_INTEGER,
63 .name = "Red Balance",
67 .default_value = 0x00,
70 .id = V4L2_CID_BLUE_BALANCE,
71 .type = V4L2_CTRL_TYPE_INTEGER,
72 .name = "Blue Balance",
76 .default_value = 0x00,
80 .type = V4L2_CTRL_TYPE_INTEGER,
85 .default_value = 0x00,
88 .id = V4L2_CID_POWER_LINE_FREQUENCY,
89 .type = V4L2_CTRL_TYPE_MENU,
90 .name = "Light frequency filter",
97 .id = V4L2_CID_COLORFX,
98 .type = V4L2_CTRL_TYPE_INTEGER,
99 .name = "Image Color Effect",
106 .id = V4L2_CID_COLORFX_CBCR,
107 .type = V4L2_CTRL_TYPE_INTEGER,
108 .name = "Image Color Effect CbCr",
115 .id = V4L2_CID_ATOMISP_BAD_PIXEL_DETECTION,
116 .type = V4L2_CTRL_TYPE_INTEGER,
117 .name = "Bad Pixel Correction",
124 .id = V4L2_CID_ATOMISP_POSTPROCESS_GDC_CAC,
125 .type = V4L2_CTRL_TYPE_INTEGER,
133 .id = V4L2_CID_ATOMISP_VIDEO_STABLIZATION,
134 .type = V4L2_CTRL_TYPE_INTEGER,
135 .name = "Video Stablization",
142 .id = V4L2_CID_ATOMISP_FIXED_PATTERN_NR,
143 .type = V4L2_CTRL_TYPE_INTEGER,
144 .name = "Fixed Pattern Noise Reduction",
151 .id = V4L2_CID_ATOMISP_FALSE_COLOR_CORRECTION,
152 .type = V4L2_CTRL_TYPE_INTEGER,
153 .name = "False Color Correction",
160 .id = V4L2_CID_REQUEST_FLASH,
161 .type = V4L2_CTRL_TYPE_INTEGER,
162 .name = "Request flash frames",
169 .id = V4L2_CID_ATOMISP_LOW_LIGHT,
170 .type = V4L2_CTRL_TYPE_BOOLEAN,
171 .name = "Low light mode",
178 .id = V4L2_CID_BIN_FACTOR_HORZ,
179 .type = V4L2_CTRL_TYPE_INTEGER,
180 .name = "Horizontal binning factor",
187 .id = V4L2_CID_BIN_FACTOR_VERT,
188 .type = V4L2_CTRL_TYPE_INTEGER,
189 .name = "Vertical binning factor",
196 .id = V4L2_CID_2A_STATUS,
197 .type = V4L2_CTRL_TYPE_BITMASK,
198 .name = "AE and AWB status",
200 .maximum = V4L2_2A_STATUS_AE_READY | V4L2_2A_STATUS_AWB_READY,
205 .id = V4L2_CID_EXPOSURE,
206 .type = V4L2_CTRL_TYPE_INTEGER,
214 .id = V4L2_CID_EXPOSURE_ZONE_NUM,
215 .type = V4L2_CTRL_TYPE_INTEGER,
216 .name = "one-time exposure zone number",
223 .id = V4L2_CID_EXPOSURE_AUTO_PRIORITY,
224 .type = V4L2_CTRL_TYPE_INTEGER,
225 .name = "Exposure auto priority",
226 .minimum = V4L2_EXPOSURE_AUTO,
227 .maximum = V4L2_EXPOSURE_APERTURE_PRIORITY,
229 .default_value = V4L2_EXPOSURE_AUTO,
232 .id = V4L2_CID_SCENE_MODE,
233 .type = V4L2_CTRL_TYPE_INTEGER,
234 .name = "scene mode",
241 .id = V4L2_CID_ISO_SENSITIVITY,
242 .type = V4L2_CTRL_TYPE_INTEGER,
250 .id = V4L2_CID_ISO_SENSITIVITY_AUTO,
251 .type = V4L2_CTRL_TYPE_INTEGER,
253 .minimum = V4L2_ISO_SENSITIVITY_MANUAL,
254 .maximum = V4L2_ISO_SENSITIVITY_AUTO,
256 .default_value = V4L2_ISO_SENSITIVITY_AUTO,
259 .id = V4L2_CID_AUTO_N_PRESET_WHITE_BALANCE,
260 .type = V4L2_CTRL_TYPE_INTEGER,
261 .name = "white balance",
268 .id = V4L2_CID_EXPOSURE_METERING,
269 .type = V4L2_CTRL_TYPE_MENU,
277 .id = V4L2_CID_3A_LOCK,
278 .type = V4L2_CTRL_TYPE_BITMASK,
281 .maximum = V4L2_LOCK_EXPOSURE | V4L2_LOCK_WHITE_BALANCE
287 .id = V4L2_CID_TEST_PATTERN,
288 .type = V4L2_CTRL_TYPE_INTEGER,
289 .name = "Test Pattern",
296 .id = V4L2_CID_TEST_PATTERN_COLOR_R,
297 .type = V4L2_CTRL_TYPE_INTEGER,
298 .name = "Test Pattern Solid Color R",
305 .id = V4L2_CID_TEST_PATTERN_COLOR_GR,
306 .type = V4L2_CTRL_TYPE_INTEGER,
307 .name = "Test Pattern Solid Color GR",
314 .id = V4L2_CID_TEST_PATTERN_COLOR_GB,
315 .type = V4L2_CTRL_TYPE_INTEGER,
316 .name = "Test Pattern Solid Color GB",
323 .id = V4L2_CID_TEST_PATTERN_COLOR_B,
324 .type = V4L2_CTRL_TYPE_INTEGER,
325 .name = "Test Pattern Solid Color B",
333 static const u32 ctrls_num = ARRAY_SIZE(ci_v4l2_controls);
336 * supported V4L2 fmts and resolutions
338 const struct atomisp_format_bridge atomisp_output_fmts[] = {
340 .pixelformat = V4L2_PIX_FMT_YUV420,
342 .mbus_code = V4L2_MBUS_FMT_CUSTOM_YUV420,
343 .sh_fmt = IA_CSS_FRAME_FORMAT_YUV420,
344 .description = "YUV420, planar",
347 .pixelformat = V4L2_PIX_FMT_YVU420,
349 .mbus_code = V4L2_MBUS_FMT_CUSTOM_YVU420,
350 .sh_fmt = IA_CSS_FRAME_FORMAT_YV12,
351 .description = "YVU420, planar",
354 .pixelformat = V4L2_PIX_FMT_YUV422P,
356 .mbus_code = V4L2_MBUS_FMT_CUSTOM_YUV422P,
357 .sh_fmt = IA_CSS_FRAME_FORMAT_YUV422,
358 .description = "YUV422, planar",
361 .pixelformat = V4L2_PIX_FMT_YUV444,
363 .mbus_code = V4L2_MBUS_FMT_CUSTOM_YUV444,
364 .sh_fmt = IA_CSS_FRAME_FORMAT_YUV444,
365 .description = "YUV444"
367 .pixelformat = V4L2_PIX_FMT_NV12,
369 .mbus_code = V4L2_MBUS_FMT_CUSTOM_NV12,
370 .sh_fmt = IA_CSS_FRAME_FORMAT_NV12,
371 .description = "NV12, Y-plane, CbCr interleaved",
374 .pixelformat = V4L2_PIX_FMT_NV21,
376 .mbus_code = V4L2_MBUS_FMT_CUSTOM_NV21,
377 .sh_fmt = IA_CSS_FRAME_FORMAT_NV21,
378 .description = "NV21, Y-plane, CbCr interleaved",
381 .pixelformat = V4L2_PIX_FMT_NV16,
383 .mbus_code = V4L2_MBUS_FMT_CUSTOM_NV16,
384 .sh_fmt = IA_CSS_FRAME_FORMAT_NV16,
385 .description = "NV16, Y-plane, CbCr interleaved",
388 .pixelformat = V4L2_PIX_FMT_YUYV,
390 .mbus_code = V4L2_MBUS_FMT_CUSTOM_YUYV,
391 .sh_fmt = IA_CSS_FRAME_FORMAT_YUYV,
392 .description = "YUYV, interleaved"
394 .pixelformat = V4L2_PIX_FMT_UYVY,
396 .mbus_code = MEDIA_BUS_FMT_UYVY8_1X16,
397 .sh_fmt = IA_CSS_FRAME_FORMAT_UYVY,
398 .description = "UYVY, interleaved"
399 }, { /* This one is for parallel sensors! DO NOT USE! */
400 .pixelformat = V4L2_PIX_FMT_UYVY,
402 .mbus_code = MEDIA_BUS_FMT_UYVY8_2X8,
403 .sh_fmt = IA_CSS_FRAME_FORMAT_UYVY,
404 .description = "UYVY, interleaved"
406 .pixelformat = V4L2_PIX_FMT_SBGGR16,
408 .mbus_code = V4L2_MBUS_FMT_CUSTOM_SBGGR16,
409 .sh_fmt = IA_CSS_FRAME_FORMAT_RAW,
410 .description = "Bayer 16"
412 .pixelformat = V4L2_PIX_FMT_SBGGR8,
414 .mbus_code = MEDIA_BUS_FMT_SBGGR8_1X8,
415 .sh_fmt = IA_CSS_FRAME_FORMAT_RAW,
416 .description = "Bayer 8"
418 .pixelformat = V4L2_PIX_FMT_SGBRG8,
420 .mbus_code = MEDIA_BUS_FMT_SGBRG8_1X8,
421 .sh_fmt = IA_CSS_FRAME_FORMAT_RAW,
422 .description = "Bayer 8"
424 .pixelformat = V4L2_PIX_FMT_SGRBG8,
426 .mbus_code = MEDIA_BUS_FMT_SGRBG8_1X8,
427 .sh_fmt = IA_CSS_FRAME_FORMAT_RAW,
428 .description = "Bayer 8"
430 .pixelformat = V4L2_PIX_FMT_SRGGB8,
432 .mbus_code = MEDIA_BUS_FMT_SRGGB8_1X8,
433 .sh_fmt = IA_CSS_FRAME_FORMAT_RAW,
434 .description = "Bayer 8"
436 .pixelformat = V4L2_PIX_FMT_SBGGR10,
438 .mbus_code = MEDIA_BUS_FMT_SBGGR10_1X10,
439 .sh_fmt = IA_CSS_FRAME_FORMAT_RAW,
440 .description = "Bayer 10"
442 .pixelformat = V4L2_PIX_FMT_SGBRG10,
444 .mbus_code = MEDIA_BUS_FMT_SGBRG10_1X10,
445 .sh_fmt = IA_CSS_FRAME_FORMAT_RAW,
446 .description = "Bayer 10"
448 .pixelformat = V4L2_PIX_FMT_SGRBG10,
450 .mbus_code = MEDIA_BUS_FMT_SGRBG10_1X10,
451 .sh_fmt = IA_CSS_FRAME_FORMAT_RAW,
452 .description = "Bayer 10"
454 .pixelformat = V4L2_PIX_FMT_SRGGB10,
456 .mbus_code = MEDIA_BUS_FMT_SRGGB10_1X10,
457 .sh_fmt = IA_CSS_FRAME_FORMAT_RAW,
458 .description = "Bayer 10"
460 .pixelformat = V4L2_PIX_FMT_SBGGR12,
462 .mbus_code = MEDIA_BUS_FMT_SBGGR12_1X12,
463 .sh_fmt = IA_CSS_FRAME_FORMAT_RAW,
464 .description = "Bayer 12"
466 .pixelformat = V4L2_PIX_FMT_SGBRG12,
468 .mbus_code = MEDIA_BUS_FMT_SGBRG12_1X12,
469 .sh_fmt = IA_CSS_FRAME_FORMAT_RAW,
470 .description = "Bayer 12"
472 .pixelformat = V4L2_PIX_FMT_SGRBG12,
474 .mbus_code = MEDIA_BUS_FMT_SGRBG12_1X12,
475 .sh_fmt = IA_CSS_FRAME_FORMAT_RAW,
476 .description = "Bayer 12"
478 .pixelformat = V4L2_PIX_FMT_SRGGB12,
480 .mbus_code = MEDIA_BUS_FMT_SRGGB12_1X12,
481 .sh_fmt = IA_CSS_FRAME_FORMAT_RAW,
482 .description = "Bayer 12"
484 .pixelformat = V4L2_PIX_FMT_RGB32,
486 .mbus_code = V4L2_MBUS_FMT_CUSTOM_RGB32,
487 .sh_fmt = IA_CSS_FRAME_FORMAT_RGBA888,
488 .description = "32 RGB 8-8-8-8"
490 .pixelformat = V4L2_PIX_FMT_RGB565,
492 .mbus_code = MEDIA_BUS_FMT_BGR565_2X8_LE,
493 .sh_fmt = IA_CSS_FRAME_FORMAT_RGB565,
494 .description = "16 RGB 5-6-5"
496 .pixelformat = V4L2_PIX_FMT_JPEG,
498 .mbus_code = MEDIA_BUS_FMT_JPEG_1X8,
499 .sh_fmt = IA_CSS_FRAME_FORMAT_BINARY_8,
500 .description = "JPEG"
504 /* This is a custom format being used by M10MO to send the RAW data */
505 .pixelformat = V4L2_PIX_FMT_CUSTOM_M10MO_RAW,
507 .mbus_code = V4L2_MBUS_FMT_CUSTOM_M10MO_RAW,
508 .sh_fmt = IA_CSS_FRAME_FORMAT_BINARY_8,
509 .description = "Custom RAW for M10MO"
514 const struct atomisp_format_bridge *
515 atomisp_get_format_bridge(unsigned int pixelformat)
519 for (i = 0; i < ARRAY_SIZE(atomisp_output_fmts); i++) {
520 if (atomisp_output_fmts[i].pixelformat == pixelformat)
521 return &atomisp_output_fmts[i];
527 const struct atomisp_format_bridge *
528 atomisp_get_format_bridge_from_mbus(u32 mbus_code)
532 for (i = 0; i < ARRAY_SIZE(atomisp_output_fmts); i++) {
533 if (mbus_code == atomisp_output_fmts[i].mbus_code)
534 return &atomisp_output_fmts[i];
542 * return ISP capabilities
544 static int atomisp_querycap(struct file *file, void *fh,
545 struct v4l2_capability *cap)
547 struct video_device *vdev = video_devdata(file);
548 struct atomisp_device *isp = video_get_drvdata(vdev);
550 strscpy(cap->driver, DRIVER, sizeof(cap->driver));
551 strscpy(cap->card, CARD, sizeof(cap->card));
552 snprintf(cap->bus_info, sizeof(cap->bus_info), "PCI:%s", dev_name(isp->dev));
558 * enum input are used to check primary/secondary camera
560 static int atomisp_enum_input(struct file *file, void *fh,
561 struct v4l2_input *input)
563 struct video_device *vdev = video_devdata(file);
564 struct atomisp_device *isp = video_get_drvdata(vdev);
565 int index = input->index;
566 struct v4l2_subdev *motor;
568 if (index >= isp->input_cnt)
571 if (!isp->inputs[index].camera)
574 memset(input, 0, sizeof(struct v4l2_input));
575 strscpy(input->name, isp->inputs[index].camera->name,
576 sizeof(input->name));
579 * HACK: append actuator's name to sensor's
580 * As currently userspace can't talk directly to subdev nodes, this
581 * ioctl is the only way to enum inputs + possible external actuators
582 * for 3A tuning purpose.
585 motor = isp->inputs[index].motor;
589 if (motor && strlen(motor->name) > 0) {
590 const int cur_len = strlen(input->name);
591 const int max_size = sizeof(input->name) - cur_len - 1;
594 input->name[cur_len] = '+';
595 strscpy(&input->name[cur_len + 1],
596 motor->name, max_size);
600 input->type = V4L2_INPUT_TYPE_CAMERA;
601 input->index = index;
602 input->reserved[0] = isp->inputs[index].type;
603 input->reserved[1] = isp->inputs[index].port;
609 atomisp_subdev_streaming_count(struct atomisp_sub_device *asd)
611 return asd->video_out_preview.capq.streaming
612 + asd->video_out_capture.capq.streaming
613 + asd->video_out_video_capture.capq.streaming
614 + asd->video_out_vf.capq.streaming
615 + asd->video_in.capq.streaming;
618 unsigned int atomisp_streaming_count(struct atomisp_device *isp)
622 for (i = 0, sum = 0; i < isp->num_of_streams; i++)
623 sum += isp->asd[i].streaming ==
624 ATOMISP_DEVICE_STREAMING_ENABLED;
629 unsigned int atomisp_is_acc_enabled(struct atomisp_device *isp)
633 for (i = 0; i < isp->num_of_streams; i++)
634 if (isp->asd[i].acc.pipeline)
641 * get input are used to get current primary/secondary camera
643 static int atomisp_g_input(struct file *file, void *fh, unsigned int *input)
645 struct video_device *vdev = video_devdata(file);
646 struct atomisp_device *isp = video_get_drvdata(vdev);
647 struct atomisp_sub_device *asd = atomisp_to_video_pipe(vdev)->asd;
649 rt_mutex_lock(&isp->mutex);
650 *input = asd->input_curr;
651 rt_mutex_unlock(&isp->mutex);
657 * set input are used to set current primary/secondary camera
659 static int atomisp_s_input(struct file *file, void *fh, unsigned int input)
661 struct video_device *vdev = video_devdata(file);
662 struct atomisp_device *isp = video_get_drvdata(vdev);
663 struct atomisp_sub_device *asd = atomisp_to_video_pipe(vdev)->asd;
664 struct v4l2_subdev *camera = NULL;
665 struct v4l2_subdev *motor;
668 rt_mutex_lock(&isp->mutex);
669 if (input >= ATOM_ISP_MAX_INPUTS || input >= isp->input_cnt) {
670 dev_dbg(isp->dev, "input_cnt: %d\n", isp->input_cnt);
676 * check whether the request camera:
678 * 2: if in use, whether it is used by other streams
680 if (isp->inputs[input].asd && isp->inputs[input].asd != asd) {
682 "%s, camera is already used by stream: %d\n", __func__,
683 isp->inputs[input].asd->index);
688 camera = isp->inputs[input].camera;
690 dev_err(isp->dev, "%s, no camera\n", __func__);
695 if (atomisp_subdev_streaming_count(asd)) {
697 "ISP is still streaming, stop first\n");
702 /* power off the current owned sensor, as it is not used this time */
703 if (isp->inputs[asd->input_curr].asd == asd &&
704 asd->input_curr != input) {
705 ret = v4l2_subdev_call(isp->inputs[asd->input_curr].camera,
709 "Failed to power-off sensor\n");
710 /* clear the asd field to show this camera is not used */
711 isp->inputs[asd->input_curr].asd = NULL;
714 /* powe on the new sensor */
715 ret = v4l2_subdev_call(isp->inputs[input].camera, core, s_power, 1);
717 dev_err(isp->dev, "Failed to power-on sensor\n");
721 * Some sensor driver resets the run mode during power-on, thus force
722 * update the run mode to sensor after power-on.
724 atomisp_update_run_mode(asd);
726 /* select operating sensor */
727 ret = v4l2_subdev_call(isp->inputs[input].camera, video, s_routing,
728 0, isp->inputs[input].sensor_index, 0);
729 if (ret && (ret != -ENOIOCTLCMD)) {
730 dev_err(isp->dev, "Failed to select sensor\n");
735 motor = isp->inputs[input].motor;
739 ret = v4l2_subdev_call(motor, core, s_power, 1);
742 if (!isp->sw_contex.file_input && motor)
743 ret = v4l2_subdev_call(motor, core, init, 1);
745 asd->input_curr = input;
746 /* mark this camera is used by the current stream */
747 isp->inputs[input].asd = asd;
748 rt_mutex_unlock(&isp->mutex);
753 rt_mutex_unlock(&isp->mutex);
758 static int atomisp_enum_fmt_cap(struct file *file, void *fh,
759 struct v4l2_fmtdesc *f)
761 struct video_device *vdev = video_devdata(file);
762 struct atomisp_device *isp = video_get_drvdata(vdev);
763 struct atomisp_sub_device *asd = atomisp_to_video_pipe(vdev)->asd;
764 struct v4l2_subdev_mbus_code_enum code = { 0 };
765 unsigned int i, fi = 0;
768 rt_mutex_lock(&isp->mutex);
769 rval = v4l2_subdev_call(isp->inputs[asd->input_curr].camera, pad,
770 enum_mbus_code, NULL, &code);
771 if (rval == -ENOIOCTLCMD) {
773 "enum_mbus_code pad op not supported. Please fix your sensor driver!\n");
774 // rval = v4l2_subdev_call(isp->inputs[asd->input_curr].camera,
775 // video, enum_mbus_fmt, 0, &code.code);
777 rt_mutex_unlock(&isp->mutex);
782 for (i = 0; i < ARRAY_SIZE(atomisp_output_fmts); i++) {
783 const struct atomisp_format_bridge *format =
784 &atomisp_output_fmts[i];
787 * Is the atomisp-supported format is valid for the
788 * sensor (configuration)? If not, skip it.
790 if (format->sh_fmt == IA_CSS_FRAME_FORMAT_RAW
791 && format->mbus_code != code.code)
794 /* Found a match. Now let's pick f->index'th one. */
800 strlcpy(f->description, format->description,
801 sizeof(f->description));
802 f->pixelformat = format->pixelformat;
809 static int atomisp_g_fmt_cap(struct file *file, void *fh,
810 struct v4l2_format *f)
812 struct video_device *vdev = video_devdata(file);
813 struct atomisp_device *isp = video_get_drvdata(vdev);
817 rt_mutex_lock(&isp->mutex);
818 ret = atomisp_get_fmt(vdev, f);
819 rt_mutex_unlock(&isp->mutex);
823 static int atomisp_g_fmt_file(struct file *file, void *fh,
824 struct v4l2_format *f)
826 struct video_device *vdev = video_devdata(file);
827 struct atomisp_device *isp = video_get_drvdata(vdev);
828 struct atomisp_video_pipe *pipe = atomisp_to_video_pipe(vdev);
830 rt_mutex_lock(&isp->mutex);
831 f->fmt.pix = pipe->pix;
832 rt_mutex_unlock(&isp->mutex);
837 /* This function looks up the closest available resolution. */
838 static int atomisp_try_fmt_cap(struct file *file, void *fh,
839 struct v4l2_format *f)
841 struct video_device *vdev = video_devdata(file);
842 struct atomisp_device *isp = video_get_drvdata(vdev);
845 rt_mutex_lock(&isp->mutex);
846 ret = atomisp_try_fmt(vdev, f, NULL);
847 rt_mutex_unlock(&isp->mutex);
851 static int atomisp_s_fmt_cap(struct file *file, void *fh,
852 struct v4l2_format *f)
854 struct video_device *vdev = video_devdata(file);
855 struct atomisp_device *isp = video_get_drvdata(vdev);
858 rt_mutex_lock(&isp->mutex);
859 if (isp->isp_fatal_error) {
861 rt_mutex_unlock(&isp->mutex);
864 ret = atomisp_set_fmt(vdev, f);
865 rt_mutex_unlock(&isp->mutex);
869 static int atomisp_s_fmt_file(struct file *file, void *fh,
870 struct v4l2_format *f)
872 struct video_device *vdev = video_devdata(file);
873 struct atomisp_device *isp = video_get_drvdata(vdev);
876 rt_mutex_lock(&isp->mutex);
877 ret = atomisp_set_fmt_file(vdev, f);
878 rt_mutex_unlock(&isp->mutex);
883 * Free videobuffer buffer priv data
885 void atomisp_videobuf_free_buf(struct videobuf_buffer *vb)
887 struct videobuf_vmalloc_memory *vm_mem;
893 if (vm_mem && vm_mem->vaddr) {
894 ia_css_frame_free(vm_mem->vaddr);
895 vm_mem->vaddr = NULL;
900 * this function is used to free video buffer queue
902 static void atomisp_videobuf_free_queue(struct videobuf_queue *q)
906 for (i = 0; i < VIDEO_MAX_FRAME; i++) {
907 atomisp_videobuf_free_buf(q->bufs[i]);
913 int atomisp_alloc_css_stat_bufs(struct atomisp_sub_device *asd,
916 struct atomisp_device *isp = asd->isp;
917 struct atomisp_s3a_buf *s3a_buf = NULL, *_s3a_buf;
918 struct atomisp_dis_buf *dis_buf = NULL, *_dis_buf;
919 struct atomisp_metadata_buf *md_buf = NULL, *_md_buf;
921 struct ia_css_dvs_grid_info *dvs_grid_info =
922 atomisp_css_get_dvs_grid_info(&asd->params.curr_grid_info);
925 if (list_empty(&asd->s3a_stats) &&
926 asd->params.curr_grid_info.s3a_grid.enable) {
927 count = ATOMISP_CSS_Q_DEPTH +
928 ATOMISP_S3A_BUF_QUEUE_DEPTH_FOR_HAL;
929 dev_dbg(isp->dev, "allocating %d 3a buffers\n", count);
931 s3a_buf = kzalloc(sizeof(struct atomisp_s3a_buf), GFP_KERNEL);
935 if (atomisp_css_allocate_stat_buffers(
936 asd, stream_id, s3a_buf, NULL, NULL)) {
941 list_add_tail(&s3a_buf->list, &asd->s3a_stats);
945 if (list_empty(&asd->dis_stats) && dvs_grid_info &&
946 dvs_grid_info->enable) {
947 count = ATOMISP_CSS_Q_DEPTH + 1;
948 dev_dbg(isp->dev, "allocating %d dis buffers\n", count);
950 dis_buf = kzalloc(sizeof(struct atomisp_dis_buf), GFP_KERNEL);
955 if (atomisp_css_allocate_stat_buffers(
956 asd, stream_id, NULL, dis_buf, NULL)) {
961 list_add_tail(&dis_buf->list, &asd->dis_stats);
965 for (i = 0; i < ATOMISP_METADATA_TYPE_NUM; i++) {
966 if (list_empty(&asd->metadata[i]) &&
967 list_empty(&asd->metadata_ready[i]) &&
968 list_empty(&asd->metadata_in_css[i])) {
969 count = ATOMISP_CSS_Q_DEPTH +
970 ATOMISP_METADATA_QUEUE_DEPTH_FOR_HAL;
971 dev_dbg(isp->dev, "allocating %d metadata buffers for type %d\n",
974 md_buf = kzalloc(sizeof(struct atomisp_metadata_buf),
979 if (atomisp_css_allocate_stat_buffers(
980 asd, stream_id, NULL, NULL, md_buf)) {
984 list_add_tail(&md_buf->list, &asd->metadata[i]);
991 dev_err(isp->dev, "failed to allocate statistics buffers\n");
993 list_for_each_entry_safe(dis_buf, _dis_buf, &asd->dis_stats, list) {
994 atomisp_css_free_dis_buffer(dis_buf);
995 list_del(&dis_buf->list);
999 list_for_each_entry_safe(s3a_buf, _s3a_buf, &asd->s3a_stats, list) {
1000 atomisp_css_free_3a_buffer(s3a_buf);
1001 list_del(&s3a_buf->list);
1005 for (i = 0; i < ATOMISP_METADATA_TYPE_NUM; i++) {
1006 list_for_each_entry_safe(md_buf, _md_buf, &asd->metadata[i],
1008 atomisp_css_free_metadata_buffer(md_buf);
1009 list_del(&md_buf->list);
1017 * Initiate Memory Mapping or User Pointer I/O
1019 int __atomisp_reqbufs(struct file *file, void *fh,
1020 struct v4l2_requestbuffers *req)
1022 struct video_device *vdev = video_devdata(file);
1023 struct atomisp_video_pipe *pipe = atomisp_to_video_pipe(vdev);
1024 struct atomisp_sub_device *asd = pipe->asd;
1025 struct ia_css_frame_info frame_info;
1026 struct ia_css_frame *frame;
1027 struct videobuf_vmalloc_memory *vm_mem;
1028 u16 source_pad = atomisp_subdev_source_pad(vdev);
1029 u16 stream_id = atomisp_source_pad_to_stream_id(asd, source_pad);
1032 if (req->count == 0) {
1033 mutex_lock(&pipe->capq.vb_lock);
1034 if (!list_empty(&pipe->capq.stream))
1035 videobuf_queue_cancel(&pipe->capq);
1037 atomisp_videobuf_free_queue(&pipe->capq);
1038 mutex_unlock(&pipe->capq.vb_lock);
1039 /* clear request config id */
1040 memset(pipe->frame_request_config_id, 0,
1041 VIDEO_MAX_FRAME * sizeof(unsigned int));
1042 memset(pipe->frame_params, 0,
1044 sizeof(struct atomisp_css_params_with_list *));
1048 ret = videobuf_reqbufs(&pipe->capq, req);
1052 atomisp_alloc_css_stat_bufs(asd, stream_id);
1055 * for user pointer type, buffers are not really allocated here,
1056 * buffers are setup in QBUF operation through v4l2_buffer structure
1058 if (req->memory == V4L2_MEMORY_USERPTR)
1061 ret = atomisp_get_css_frame_info(asd, source_pad, &frame_info);
1066 * Allocate the real frame here for selected node using our
1067 * memory management function
1069 for (i = 0; i < req->count; i++) {
1070 if (ia_css_frame_allocate_from_info(&frame, &frame_info))
1072 vm_mem = pipe->capq.bufs[i]->priv;
1073 vm_mem->vaddr = frame;
1080 vm_mem = pipe->capq.bufs[i]->priv;
1081 ia_css_frame_free(vm_mem->vaddr);
1085 ia_css_frame_free(asd->vf_frame);
1090 int atomisp_reqbufs(struct file *file, void *fh,
1091 struct v4l2_requestbuffers *req)
1093 struct video_device *vdev = video_devdata(file);
1094 struct atomisp_device *isp = video_get_drvdata(vdev);
1097 rt_mutex_lock(&isp->mutex);
1098 ret = __atomisp_reqbufs(file, fh, req);
1099 rt_mutex_unlock(&isp->mutex);
1104 static int atomisp_reqbufs_file(struct file *file, void *fh,
1105 struct v4l2_requestbuffers *req)
1107 struct video_device *vdev = video_devdata(file);
1108 struct atomisp_video_pipe *pipe = atomisp_to_video_pipe(vdev);
1110 if (req->count == 0) {
1111 mutex_lock(&pipe->outq.vb_lock);
1112 atomisp_videobuf_free_queue(&pipe->outq);
1113 mutex_unlock(&pipe->outq.vb_lock);
1117 return videobuf_reqbufs(&pipe->outq, req);
1120 /* application query the status of a buffer */
1121 static int atomisp_querybuf(struct file *file, void *fh,
1122 struct v4l2_buffer *buf)
1124 struct video_device *vdev = video_devdata(file);
1125 struct atomisp_video_pipe *pipe = atomisp_to_video_pipe(vdev);
1127 return videobuf_querybuf(&pipe->capq, buf);
1130 static int atomisp_querybuf_file(struct file *file, void *fh,
1131 struct v4l2_buffer *buf)
1133 struct video_device *vdev = video_devdata(file);
1134 struct atomisp_video_pipe *pipe = atomisp_to_video_pipe(vdev);
1136 return videobuf_querybuf(&pipe->outq, buf);
1140 * Applications call the VIDIOC_QBUF ioctl to enqueue an empty (capturing) or
1141 * filled (output) buffer in the drivers incoming queue.
1143 static int atomisp_qbuf(struct file *file, void *fh, struct v4l2_buffer *buf)
1145 static const int NOFLUSH_FLAGS = V4L2_BUF_FLAG_NO_CACHE_INVALIDATE |
1146 V4L2_BUF_FLAG_NO_CACHE_CLEAN;
1147 struct video_device *vdev = video_devdata(file);
1148 struct atomisp_device *isp = video_get_drvdata(vdev);
1149 struct atomisp_video_pipe *pipe = atomisp_to_video_pipe(vdev);
1150 struct atomisp_sub_device *asd = pipe->asd;
1151 struct videobuf_buffer *vb;
1152 struct videobuf_vmalloc_memory *vm_mem;
1153 struct ia_css_frame_info frame_info;
1154 struct ia_css_frame *handle = NULL;
1159 rt_mutex_lock(&isp->mutex);
1160 if (isp->isp_fatal_error) {
1165 if (asd->streaming == ATOMISP_DEVICE_STREAMING_STOPPING) {
1166 dev_err(isp->dev, "%s: reject, as ISP at stopping.\n",
1172 if (!buf || buf->index >= VIDEO_MAX_FRAME ||
1173 !pipe->capq.bufs[buf->index]) {
1174 dev_err(isp->dev, "Invalid index for qbuf.\n");
1180 * For userptr type frame, we convert user space address to physic
1181 * address and reprograme out page table properly
1183 if (buf->memory == V4L2_MEMORY_USERPTR) {
1184 vb = pipe->capq.bufs[buf->index];
1192 pgnr = (length + (PAGE_SIZE - 1)) >> PAGE_SHIFT;
1194 if (vb->baddr == buf->m.userptr && vm_mem->vaddr)
1197 if (atomisp_get_css_frame_info(asd,
1198 atomisp_subdev_source_pad(vdev), &frame_info)) {
1203 ret = ia_css_frame_map(&handle, &frame_info,
1204 (void __user *)buf->m.userptr,
1207 dev_err(isp->dev, "Failed to map user buffer\n");
1211 if (vm_mem->vaddr) {
1212 mutex_lock(&pipe->capq.vb_lock);
1213 ia_css_frame_free(vm_mem->vaddr);
1214 vm_mem->vaddr = NULL;
1215 vb->state = VIDEOBUF_NEEDS_INIT;
1216 mutex_unlock(&pipe->capq.vb_lock);
1219 vm_mem->vaddr = handle;
1221 buf->flags &= ~V4L2_BUF_FLAG_MAPPED;
1222 buf->flags |= V4L2_BUF_FLAG_QUEUED;
1223 buf->flags &= ~V4L2_BUF_FLAG_DONE;
1224 } else if (buf->memory == V4L2_MEMORY_MMAP) {
1225 buf->flags |= V4L2_BUF_FLAG_MAPPED;
1226 buf->flags |= V4L2_BUF_FLAG_QUEUED;
1227 buf->flags &= ~V4L2_BUF_FLAG_DONE;
1230 * For mmap, frames were allocated at request buffers
1235 if (!((buf->flags & NOFLUSH_FLAGS) == NOFLUSH_FLAGS))
1238 if (!atomisp_is_vf_pipe(pipe) &&
1239 (buf->reserved2 & ATOMISP_BUFFER_HAS_PER_FRAME_SETTING)) {
1240 /* this buffer will have a per-frame parameter */
1241 pipe->frame_request_config_id[buf->index] = buf->reserved2 &
1242 ~ATOMISP_BUFFER_HAS_PER_FRAME_SETTING;
1244 "This buffer requires per_frame setting which has isp_config_id %d\n",
1245 pipe->frame_request_config_id[buf->index]);
1247 pipe->frame_request_config_id[buf->index] = 0;
1250 pipe->frame_params[buf->index] = NULL;
1252 rt_mutex_unlock(&isp->mutex);
1254 ret = videobuf_qbuf(&pipe->capq, buf);
1255 rt_mutex_lock(&isp->mutex);
1259 /* TODO: do this better, not best way to queue to css */
1260 if (asd->streaming == ATOMISP_DEVICE_STREAMING_ENABLED) {
1261 if (!list_empty(&pipe->buffers_waiting_for_param)) {
1262 atomisp_handle_parameter_and_buffer(pipe);
1264 atomisp_qbuffers_to_css(asd);
1267 if (!atomisp_is_wdt_running(asd) && atomisp_buffers_queued(asd))
1268 atomisp_wdt_start(asd);
1270 if (!atomisp_is_wdt_running(pipe) &&
1271 atomisp_buffers_queued_pipe(pipe))
1272 atomisp_wdt_start_pipe(pipe);
1278 * Workaround: Due to the design of HALv3,
1279 * sometimes in ZSL or SDV mode HAL needs to
1280 * capture multiple images within one streaming cycle.
1281 * But the capture number cannot be determined by HAL.
1282 * So HAL only sets the capture number to be 1 and queue multiple
1283 * buffers. Atomisp driver needs to check this case and re-trigger
1284 * CSS to do capture when new buffer is queued.
1286 if (asd->continuous_mode->val &&
1287 atomisp_subdev_source_pad(vdev)
1288 == ATOMISP_SUBDEV_PAD_SOURCE_CAPTURE &&
1289 pipe->capq.streaming &&
1290 !asd->enable_raw_buffer_lock->val &&
1291 asd->params.offline_parm.num_captures == 1) {
1293 asd->pending_capture_request++;
1294 dev_dbg(isp->dev, "Add one pending capture request.\n");
1296 if (asd->re_trigger_capture) {
1297 ret = atomisp_css_offline_capture_configure(asd,
1298 asd->params.offline_parm.num_captures,
1299 asd->params.offline_parm.skip_frames,
1300 asd->params.offline_parm.offset);
1301 asd->re_trigger_capture = false;
1302 dev_dbg(isp->dev, "%s Trigger capture again ret=%d\n",
1306 asd->pending_capture_request++;
1307 asd->re_trigger_capture = false;
1308 dev_dbg(isp->dev, "Add one pending capture request.\n");
1312 rt_mutex_unlock(&isp->mutex);
1314 dev_dbg(isp->dev, "qbuf buffer %d (%s) for asd%d\n", buf->index,
1315 vdev->name, asd->index);
1320 rt_mutex_unlock(&isp->mutex);
1324 static int atomisp_qbuf_file(struct file *file, void *fh,
1325 struct v4l2_buffer *buf)
1327 struct video_device *vdev = video_devdata(file);
1328 struct atomisp_device *isp = video_get_drvdata(vdev);
1329 struct atomisp_video_pipe *pipe = atomisp_to_video_pipe(vdev);
1332 rt_mutex_lock(&isp->mutex);
1333 if (isp->isp_fatal_error) {
1338 if (!buf || buf->index >= VIDEO_MAX_FRAME ||
1339 !pipe->outq.bufs[buf->index]) {
1340 dev_err(isp->dev, "Invalid index for qbuf.\n");
1345 if (buf->memory != V4L2_MEMORY_MMAP) {
1346 dev_err(isp->dev, "Unsupported memory method\n");
1351 if (buf->type != V4L2_BUF_TYPE_VIDEO_OUTPUT) {
1352 dev_err(isp->dev, "Unsupported buffer type\n");
1356 rt_mutex_unlock(&isp->mutex);
1358 return videobuf_qbuf(&pipe->outq, buf);
1361 rt_mutex_unlock(&isp->mutex);
1366 static int __get_frame_exp_id(struct atomisp_video_pipe *pipe,
1367 struct v4l2_buffer *buf)
1369 struct videobuf_vmalloc_memory *vm_mem;
1370 struct ia_css_frame *handle;
1373 for (i = 0; pipe->capq.bufs[i]; i++) {
1374 vm_mem = pipe->capq.bufs[i]->priv;
1375 handle = vm_mem->vaddr;
1376 if (buf->index == pipe->capq.bufs[i]->i && handle)
1377 return handle->exp_id;
1383 * Applications call the VIDIOC_DQBUF ioctl to dequeue a filled (capturing) or
1384 * displayed (output buffer)from the driver's outgoing queue
1386 static int atomisp_dqbuf(struct file *file, void *fh, struct v4l2_buffer *buf)
1388 struct video_device *vdev = video_devdata(file);
1389 struct atomisp_video_pipe *pipe = atomisp_to_video_pipe(vdev);
1390 struct atomisp_sub_device *asd = pipe->asd;
1391 struct atomisp_device *isp = video_get_drvdata(vdev);
1394 rt_mutex_lock(&isp->mutex);
1396 if (isp->isp_fatal_error) {
1397 rt_mutex_unlock(&isp->mutex);
1401 if (asd->streaming == ATOMISP_DEVICE_STREAMING_STOPPING) {
1402 rt_mutex_unlock(&isp->mutex);
1403 dev_err(isp->dev, "%s: reject, as ISP at stopping.\n",
1408 rt_mutex_unlock(&isp->mutex);
1410 ret = videobuf_dqbuf(&pipe->capq, buf, file->f_flags & O_NONBLOCK);
1413 dev_dbg(isp->dev, "<%s: %d\n", __func__, ret);
1416 rt_mutex_lock(&isp->mutex);
1417 buf->bytesused = pipe->pix.sizeimage;
1418 buf->reserved = asd->frame_status[buf->index];
1422 * Currently frame_status in the enum type which takes no more lower
1424 * use bit[31:16] for exp_id as it is only in the range of 1~255
1426 buf->reserved &= 0x0000ffff;
1427 if (!(buf->flags & V4L2_BUF_FLAG_ERROR))
1428 buf->reserved |= __get_frame_exp_id(pipe, buf) << 16;
1429 buf->reserved2 = pipe->frame_config_id[buf->index];
1430 rt_mutex_unlock(&isp->mutex);
1433 "dqbuf buffer %d (%s) for asd%d with exp_id %d, isp_config_id %d\n",
1434 buf->index, vdev->name, asd->index, buf->reserved >> 16,
1439 enum ia_css_pipe_id atomisp_get_css_pipe_id(struct atomisp_sub_device *asd)
1441 if (ATOMISP_USE_YUVPP(asd))
1442 return IA_CSS_PIPE_ID_YUVPP;
1444 if (asd->continuous_mode->val) {
1445 if (asd->run_mode->val == ATOMISP_RUN_MODE_VIDEO)
1446 return IA_CSS_PIPE_ID_VIDEO;
1448 return IA_CSS_PIPE_ID_PREVIEW;
1452 * Disable vf_pp and run CSS in video mode. This allows using ISP
1453 * scaling but it has one frame delay due to CSS internal buffering.
1455 if (asd->vfpp->val == ATOMISP_VFPP_DISABLE_SCALER)
1456 return IA_CSS_PIPE_ID_VIDEO;
1459 * Disable vf_pp and run CSS in still capture mode. In this mode
1460 * CSS does not cause extra latency with buffering, but scaling
1463 if (asd->vfpp->val == ATOMISP_VFPP_DISABLE_LOWLAT)
1464 return IA_CSS_PIPE_ID_CAPTURE;
1466 switch (asd->run_mode->val) {
1467 case ATOMISP_RUN_MODE_PREVIEW:
1468 return IA_CSS_PIPE_ID_PREVIEW;
1469 case ATOMISP_RUN_MODE_VIDEO:
1470 return IA_CSS_PIPE_ID_VIDEO;
1471 case ATOMISP_RUN_MODE_STILL_CAPTURE:
1474 return IA_CSS_PIPE_ID_CAPTURE;
1478 static unsigned int atomisp_sensor_start_stream(struct atomisp_sub_device *asd)
1480 struct atomisp_device *isp = asd->isp;
1482 if (isp->inputs[asd->input_curr].camera_caps->
1483 sensor[asd->sensor_curr].stream_num > 1) {
1484 if (asd->high_speed_mode)
1490 if (asd->vfpp->val != ATOMISP_VFPP_ENABLE ||
1494 if (asd->run_mode->val == ATOMISP_RUN_MODE_VIDEO ||
1495 (asd->run_mode->val == ATOMISP_RUN_MODE_STILL_CAPTURE &&
1496 !atomisp_is_mbuscode_raw(
1498 asd->capture_pad].fmt.code) &&
1499 !asd->continuous_mode->val))
1505 int atomisp_stream_on_master_slave_sensor(struct atomisp_device *isp,
1508 unsigned int master = -1, slave = -1, delay_slave = 0;
1512 * ISP only support 2 streams now so ignore multiple master/slave
1513 * case to reduce the delay between 2 stream_on calls.
1515 for (i = 0; i < isp->num_of_streams; i++) {
1516 int sensor_index = isp->asd[i].input_curr;
1518 if (isp->inputs[sensor_index].camera_caps->
1519 sensor[isp->asd[i].sensor_curr].is_slave)
1520 slave = sensor_index;
1522 master = sensor_index;
1525 if (master == -1 || slave == -1) {
1526 master = ATOMISP_DEPTH_DEFAULT_MASTER_SENSOR;
1527 slave = ATOMISP_DEPTH_DEFAULT_SLAVE_SENSOR;
1529 "depth mode use default master=%s.slave=%s.\n",
1530 isp->inputs[master].camera->name,
1531 isp->inputs[slave].camera->name);
1534 ret = v4l2_subdev_call(isp->inputs[master].camera, core,
1535 ioctl, ATOMISP_IOC_G_DEPTH_SYNC_COMP,
1539 "get depth sensor %s compensation delay failed.\n",
1540 isp->inputs[master].camera->name);
1542 ret = v4l2_subdev_call(isp->inputs[master].camera,
1543 video, s_stream, 1);
1545 dev_err(isp->dev, "depth mode master sensor %s stream-on failed.\n",
1546 isp->inputs[master].camera->name);
1550 if (delay_slave != 0)
1551 udelay(delay_slave);
1553 ret = v4l2_subdev_call(isp->inputs[slave].camera,
1554 video, s_stream, 1);
1556 dev_err(isp->dev, "depth mode slave sensor %s stream-on failed.\n",
1557 isp->inputs[slave].camera->name);
1558 v4l2_subdev_call(isp->inputs[master].camera, video, s_stream, 0);
1566 /* FIXME! ISP2400 */
1567 static void __wdt_on_master_slave_sensor(struct atomisp_device *isp,
1568 unsigned int wdt_duration)
1570 if (atomisp_buffers_queued(&isp->asd[0]))
1571 atomisp_wdt_refresh(&isp->asd[0], wdt_duration);
1572 if (atomisp_buffers_queued(&isp->asd[1]))
1573 atomisp_wdt_refresh(&isp->asd[1], wdt_duration);
1576 /* FIXME! ISP2401 */
1577 static void __wdt_on_master_slave_sensor_pipe(struct atomisp_video_pipe *pipe,
1578 unsigned int wdt_duration,
1581 static struct atomisp_video_pipe *pipe0;
1584 if (atomisp_buffers_queued_pipe(pipe0))
1585 atomisp_wdt_refresh_pipe(pipe0, wdt_duration);
1586 if (atomisp_buffers_queued_pipe(pipe))
1587 atomisp_wdt_refresh_pipe(pipe, wdt_duration);
1593 static void atomisp_pause_buffer_event(struct atomisp_device *isp)
1595 struct v4l2_event event = {0};
1598 event.type = V4L2_EVENT_ATOMISP_PAUSE_BUFFER;
1600 for (i = 0; i < isp->num_of_streams; i++) {
1601 int sensor_index = isp->asd[i].input_curr;
1603 if (isp->inputs[sensor_index].camera_caps->
1604 sensor[isp->asd[i].sensor_curr].is_slave) {
1605 v4l2_event_queue(isp->asd[i].subdev.devnode, &event);
1611 /* Input system HW workaround */
1612 /* Input system address translation corrupts burst during */
1613 /* invalidate. SW workaround for this is to set burst length */
1614 /* manually to 128 in case of 13MPx snapshot and to 1 otherwise. */
1615 static void atomisp_dma_burst_len_cfg(struct atomisp_sub_device *asd)
1617 struct v4l2_mbus_framefmt *sink;
1619 sink = atomisp_subdev_get_ffmt(&asd->subdev, NULL,
1620 V4L2_SUBDEV_FORMAT_ACTIVE,
1621 ATOMISP_SUBDEV_PAD_SINK);
1623 if (sink->width * sink->height >= 4096 * 3072)
1624 atomisp_css2_hw_store_32(DMA_BURST_SIZE_REG, 0x7F);
1626 atomisp_css2_hw_store_32(DMA_BURST_SIZE_REG, 0x00);
1630 * This ioctl start the capture during streaming I/O.
1632 static int atomisp_streamon(struct file *file, void *fh,
1633 enum v4l2_buf_type type)
1635 struct video_device *vdev = video_devdata(file);
1636 struct atomisp_video_pipe *pipe = atomisp_to_video_pipe(vdev);
1637 struct atomisp_sub_device *asd = pipe->asd;
1638 struct atomisp_device *isp = video_get_drvdata(vdev);
1639 struct pci_dev *pdev = to_pci_dev(isp->dev);
1640 enum ia_css_pipe_id css_pipe_id;
1641 unsigned int sensor_start_stream;
1642 unsigned int wdt_duration = ATOMISP_ISP_TIMEOUT_DURATION;
1644 unsigned long irqflags;
1646 dev_dbg(isp->dev, "Start stream on pad %d for asd%d\n",
1647 atomisp_subdev_source_pad(vdev), asd->index);
1649 if (type != V4L2_BUF_TYPE_VIDEO_CAPTURE) {
1650 dev_dbg(isp->dev, "unsupported v4l2 buf type\n");
1654 rt_mutex_lock(&isp->mutex);
1655 if (isp->isp_fatal_error) {
1660 if (asd->streaming == ATOMISP_DEVICE_STREAMING_STOPPING) {
1665 if (pipe->capq.streaming)
1668 /* Input system HW workaround */
1669 atomisp_dma_burst_len_cfg(asd);
1672 * The number of streaming video nodes is based on which
1673 * binary is going to be run.
1675 sensor_start_stream = atomisp_sensor_start_stream(asd);
1677 spin_lock_irqsave(&pipe->irq_lock, irqflags);
1678 if (list_empty(&pipe->capq.stream)) {
1679 spin_unlock_irqrestore(&pipe->irq_lock, irqflags);
1680 dev_dbg(isp->dev, "no buffer in the queue\n");
1684 spin_unlock_irqrestore(&pipe->irq_lock, irqflags);
1686 ret = videobuf_streamon(&pipe->capq);
1690 /* Reset pending capture request count. */
1691 asd->pending_capture_request = 0;
1693 asd->re_trigger_capture = false;
1695 if ((atomisp_subdev_streaming_count(asd) > sensor_start_stream) &&
1696 (!isp->inputs[asd->input_curr].camera_caps->multi_stream_ctrl)) {
1697 /* trigger still capture */
1698 if (asd->continuous_mode->val &&
1699 atomisp_subdev_source_pad(vdev)
1700 == ATOMISP_SUBDEV_PAD_SOURCE_CAPTURE) {
1701 if (asd->run_mode->val == ATOMISP_RUN_MODE_VIDEO)
1702 dev_dbg(isp->dev, "SDV last video raw buffer id: %u\n",
1703 asd->latest_preview_exp_id);
1705 dev_dbg(isp->dev, "ZSL last preview raw buffer id: %u\n",
1706 asd->latest_preview_exp_id);
1708 if (asd->delayed_init == ATOMISP_DELAYED_INIT_QUEUED) {
1709 flush_work(&asd->delayed_init_work);
1710 rt_mutex_unlock(&isp->mutex);
1711 if (wait_for_completion_interruptible(
1712 &asd->init_done) != 0)
1713 return -ERESTARTSYS;
1714 rt_mutex_lock(&isp->mutex);
1717 /* handle per_frame_setting parameter and buffers */
1718 atomisp_handle_parameter_and_buffer(pipe);
1721 * only ZSL/SDV capture request will be here, raise
1722 * the ISP freq to the highest possible to minimize
1725 atomisp_freq_scaling(isp, ATOMISP_DFS_MODE_MAX, false);
1727 * When asd->enable_raw_buffer_lock->val is true,
1728 * An extra IOCTL is needed to call
1729 * atomisp_css_exp_id_capture and trigger real capture
1731 if (!asd->enable_raw_buffer_lock->val) {
1732 ret = atomisp_css_offline_capture_configure(asd,
1733 asd->params.offline_parm.num_captures,
1734 asd->params.offline_parm.skip_frames,
1735 asd->params.offline_parm.offset);
1740 if (asd->depth_mode->val)
1741 atomisp_pause_buffer_event(isp);
1744 atomisp_qbuffers_to_css(asd);
1748 if (asd->streaming == ATOMISP_DEVICE_STREAMING_ENABLED) {
1749 atomisp_qbuffers_to_css(asd);
1753 css_pipe_id = atomisp_get_css_pipe_id(asd);
1755 ret = atomisp_acc_load_extensions(asd);
1757 dev_err(isp->dev, "acc extension failed to load\n");
1761 if (asd->params.css_update_params_needed) {
1762 atomisp_apply_css_parameters(asd, &asd->params.css_param);
1763 if (asd->params.css_param.update_flag.dz_config)
1764 asd->params.config.dz_config = &asd->params.css_param.dz_config;
1765 atomisp_css_update_isp_params(asd);
1766 asd->params.css_update_params_needed = false;
1767 memset(&asd->params.css_param.update_flag, 0,
1768 sizeof(struct atomisp_parameters));
1770 asd->params.dvs_6axis = NULL;
1772 ret = atomisp_css_start(asd, css_pipe_id, false);
1776 asd->streaming = ATOMISP_DEVICE_STREAMING_ENABLED;
1777 atomic_set(&asd->sof_count, -1);
1778 atomic_set(&asd->sequence, -1);
1779 atomic_set(&asd->sequence_temp, -1);
1780 if (isp->sw_contex.file_input)
1781 wdt_duration = ATOMISP_ISP_FILE_TIMEOUT_DURATION;
1783 asd->params.dis_proj_data_valid = false;
1784 asd->latest_preview_exp_id = 0;
1785 asd->postview_exp_id = 1;
1786 asd->preview_exp_id = 1;
1788 /* handle per_frame_setting parameter and buffers */
1789 atomisp_handle_parameter_and_buffer(pipe);
1791 atomisp_qbuffers_to_css(asd);
1793 /* Only start sensor when the last streaming instance started */
1794 if (atomisp_subdev_streaming_count(asd) < sensor_start_stream)
1799 asd->params.num_flash_frames = 0;
1800 asd->params.flash_state = ATOMISP_FLASH_IDLE;
1801 atomisp_setup_flash(asd);
1804 if (!isp->sw_contex.file_input) {
1805 atomisp_css_irq_enable(isp, IA_CSS_IRQ_INFO_CSS_RECEIVER_SOF,
1806 atomisp_css_valid_sof(isp));
1807 atomisp_csi2_configure(asd);
1809 * set freq to max when streaming count > 1 which indicate
1810 * dual camera would run
1812 if (atomisp_streaming_count(isp) > 1) {
1813 if (atomisp_freq_scaling(isp,
1814 ATOMISP_DFS_MODE_MAX, false) < 0)
1815 dev_dbg(isp->dev, "DFS max mode failed!\n");
1817 if (atomisp_freq_scaling(isp,
1818 ATOMISP_DFS_MODE_AUTO, false) < 0)
1819 dev_dbg(isp->dev, "DFS auto mode failed!\n");
1822 if (atomisp_freq_scaling(isp, ATOMISP_DFS_MODE_MAX, false) < 0)
1823 dev_dbg(isp->dev, "DFS max mode failed!\n");
1826 if (asd->depth_mode->val && atomisp_streaming_count(isp) ==
1827 ATOMISP_DEPTH_SENSOR_STREAMON_COUNT) {
1828 ret = atomisp_stream_on_master_slave_sensor(isp, false);
1830 dev_err(isp->dev, "master slave sensor stream on failed!\n");
1834 __wdt_on_master_slave_sensor(isp, wdt_duration);
1836 __wdt_on_master_slave_sensor_pipe(pipe, wdt_duration, true);
1837 goto start_delay_wq;
1838 } else if (asd->depth_mode->val && (atomisp_streaming_count(isp) <
1839 ATOMISP_DEPTH_SENSOR_STREAMON_COUNT)) {
1841 __wdt_on_master_slave_sensor_pipe(pipe, wdt_duration, false);
1842 goto start_delay_wq;
1845 /* Enable the CSI interface on ANN B0/K0 */
1846 if (isp->media_dev.hw_revision >= ((ATOMISP_HW_REVISION_ISP2401 <<
1847 ATOMISP_HW_REVISION_SHIFT) | ATOMISP_HW_STEPPING_B0)) {
1848 pci_write_config_word(pdev, MRFLD_PCI_CSI_CONTROL,
1849 isp->saved_regs.csi_control | MRFLD_PCI_CSI_CONTROL_CSI_READY);
1852 /* stream on the sensor */
1853 ret = v4l2_subdev_call(isp->inputs[asd->input_curr].camera,
1854 video, s_stream, 1);
1856 asd->streaming = ATOMISP_DEVICE_STREAMING_DISABLED;
1862 if (atomisp_buffers_queued(asd))
1863 atomisp_wdt_refresh(asd, wdt_duration);
1865 if (atomisp_buffers_queued_pipe(pipe))
1866 atomisp_wdt_refresh_pipe(pipe, wdt_duration);
1870 if (asd->continuous_mode->val) {
1871 struct v4l2_mbus_framefmt *sink;
1873 sink = atomisp_subdev_get_ffmt(&asd->subdev, NULL,
1874 V4L2_SUBDEV_FORMAT_ACTIVE,
1875 ATOMISP_SUBDEV_PAD_SINK);
1877 reinit_completion(&asd->init_done);
1878 asd->delayed_init = ATOMISP_DELAYED_INIT_QUEUED;
1879 queue_work(asd->delayed_init_workq, &asd->delayed_init_work);
1880 atomisp_css_set_cont_prev_start_time(isp,
1881 ATOMISP_CALC_CSS_PREV_OVERLAP(sink->height));
1883 asd->delayed_init = ATOMISP_DELAYED_INIT_NOT_QUEUED;
1886 rt_mutex_unlock(&isp->mutex);
1890 int __atomisp_streamoff(struct file *file, void *fh, enum v4l2_buf_type type)
1892 struct video_device *vdev = video_devdata(file);
1893 struct atomisp_device *isp = video_get_drvdata(vdev);
1894 struct pci_dev *pdev = to_pci_dev(isp->dev);
1895 struct atomisp_video_pipe *pipe = atomisp_to_video_pipe(vdev);
1896 struct atomisp_sub_device *asd = pipe->asd;
1897 struct atomisp_video_pipe *capture_pipe = NULL;
1898 struct atomisp_video_pipe *vf_pipe = NULL;
1899 struct atomisp_video_pipe *preview_pipe = NULL;
1900 struct atomisp_video_pipe *video_pipe = NULL;
1901 struct videobuf_buffer *vb, *_vb;
1902 enum ia_css_pipe_id css_pipe_id;
1904 unsigned long flags;
1905 bool first_streamoff = false;
1907 dev_dbg(isp->dev, "Stop stream on pad %d for asd%d\n",
1908 atomisp_subdev_source_pad(vdev), asd->index);
1910 BUG_ON(!rt_mutex_is_locked(&isp->mutex));
1911 BUG_ON(!mutex_is_locked(&isp->streamoff_mutex));
1913 if (type != V4L2_BUF_TYPE_VIDEO_CAPTURE) {
1914 dev_dbg(isp->dev, "unsupported v4l2 buf type\n");
1919 * do only videobuf_streamoff for capture & vf pipes in
1920 * case of continuous capture
1922 if ((asd->continuous_mode->val ||
1923 isp->inputs[asd->input_curr].camera_caps->multi_stream_ctrl) &&
1924 atomisp_subdev_source_pad(vdev) !=
1925 ATOMISP_SUBDEV_PAD_SOURCE_PREVIEW &&
1926 atomisp_subdev_source_pad(vdev) !=
1927 ATOMISP_SUBDEV_PAD_SOURCE_VIDEO) {
1928 if (isp->inputs[asd->input_curr].camera_caps->multi_stream_ctrl) {
1929 v4l2_subdev_call(isp->inputs[asd->input_curr].camera,
1930 video, s_stream, 0);
1931 } else if (atomisp_subdev_source_pad(vdev)
1932 == ATOMISP_SUBDEV_PAD_SOURCE_CAPTURE) {
1933 /* stop continuous still capture if needed */
1934 if (asd->params.offline_parm.num_captures == -1)
1935 atomisp_css_offline_capture_configure(asd,
1937 atomisp_freq_scaling(isp, ATOMISP_DFS_MODE_AUTO, false);
1940 * Currently there is no way to flush buffers queued to css.
1941 * When doing videobuf_streamoff, active buffers will be
1942 * marked as VIDEOBUF_NEEDS_INIT. HAL will be able to use
1943 * these buffers again, and these buffers might be queued to
1944 * css more than once! Warn here, if HAL has not dequeued all
1945 * buffers back before calling streamoff.
1947 if (pipe->buffers_in_css != 0) {
1948 WARN(1, "%s: buffers of vdev %s still in CSS!\n",
1949 __func__, pipe->vdev.name);
1952 * Buffers remained in css maybe dequeued out in the
1953 * next stream on, while this will causes serious
1954 * issues as buffers already get invalid after
1955 * previous stream off.
1957 * No way to flush buffers but to reset the whole css
1959 dev_warn(isp->dev, "Reset CSS to clean up css buffers.\n");
1960 atomisp_css_flush(isp);
1963 return videobuf_streamoff(&pipe->capq);
1966 if (!pipe->capq.streaming)
1969 spin_lock_irqsave(&isp->lock, flags);
1970 if (asd->streaming == ATOMISP_DEVICE_STREAMING_ENABLED) {
1971 asd->streaming = ATOMISP_DEVICE_STREAMING_STOPPING;
1972 first_streamoff = true;
1974 spin_unlock_irqrestore(&isp->lock, flags);
1976 if (first_streamoff) {
1977 /* if other streams are running, should not disable watch dog */
1978 rt_mutex_unlock(&isp->mutex);
1979 atomisp_wdt_stop(asd, true);
1982 * must stop sending pixels into GP_FIFO before stop
1985 if (isp->sw_contex.file_input)
1986 v4l2_subdev_call(isp->inputs[asd->input_curr].camera,
1987 video, s_stream, 0);
1989 rt_mutex_lock(&isp->mutex);
1990 atomisp_acc_unload_extensions(asd);
1993 spin_lock_irqsave(&isp->lock, flags);
1994 if (atomisp_subdev_streaming_count(asd) == 1)
1995 asd->streaming = ATOMISP_DEVICE_STREAMING_DISABLED;
1996 spin_unlock_irqrestore(&isp->lock, flags);
1998 if (!first_streamoff) {
1999 ret = videobuf_streamoff(&pipe->capq);
2005 atomisp_clear_css_buffer_counters(asd);
2007 if (!isp->sw_contex.file_input)
2008 atomisp_css_irq_enable(isp, IA_CSS_IRQ_INFO_CSS_RECEIVER_SOF,
2011 if (asd->delayed_init == ATOMISP_DELAYED_INIT_QUEUED) {
2012 cancel_work_sync(&asd->delayed_init_work);
2013 asd->delayed_init = ATOMISP_DELAYED_INIT_NOT_QUEUED;
2015 if (first_streamoff) {
2016 css_pipe_id = atomisp_get_css_pipe_id(asd);
2017 ret = atomisp_css_stop(asd, css_pipe_id, false);
2019 /* cancel work queue*/
2020 if (asd->video_out_capture.users) {
2021 capture_pipe = &asd->video_out_capture;
2022 wake_up_interruptible(&capture_pipe->capq.wait);
2024 if (asd->video_out_vf.users) {
2025 vf_pipe = &asd->video_out_vf;
2026 wake_up_interruptible(&vf_pipe->capq.wait);
2028 if (asd->video_out_preview.users) {
2029 preview_pipe = &asd->video_out_preview;
2030 wake_up_interruptible(&preview_pipe->capq.wait);
2032 if (asd->video_out_video_capture.users) {
2033 video_pipe = &asd->video_out_video_capture;
2034 wake_up_interruptible(&video_pipe->capq.wait);
2036 ret = videobuf_streamoff(&pipe->capq);
2040 /* cleanup css here */
2041 /* no need for this, as ISP will be reset anyway */
2042 /*atomisp_flush_bufs_in_css(isp);*/
2044 spin_lock_irqsave(&pipe->irq_lock, flags);
2045 list_for_each_entry_safe(vb, _vb, &pipe->activeq, queue) {
2046 vb->state = VIDEOBUF_PREPARED;
2047 list_del(&vb->queue);
2049 list_for_each_entry_safe(vb, _vb, &pipe->buffers_waiting_for_param, queue) {
2050 vb->state = VIDEOBUF_PREPARED;
2051 list_del(&vb->queue);
2052 pipe->frame_request_config_id[vb->i] = 0;
2054 spin_unlock_irqrestore(&pipe->irq_lock, flags);
2056 atomisp_subdev_cleanup_pending_events(asd);
2058 if (atomisp_subdev_streaming_count(asd) + 1
2059 != atomisp_sensor_start_stream(asd))
2062 if (!isp->sw_contex.file_input)
2063 ret = v4l2_subdev_call(isp->inputs[asd->input_curr].camera,
2064 video, s_stream, 0);
2067 asd->params.num_flash_frames = 0;
2068 asd->params.flash_state = ATOMISP_FLASH_IDLE;
2071 /* if other streams are running, isp should not be powered off */
2072 if (atomisp_streaming_count(isp)) {
2073 atomisp_css_flush(isp);
2077 /* Disable the CSI interface on ANN B0/K0 */
2078 if (isp->media_dev.hw_revision >= ((ATOMISP_HW_REVISION_ISP2401 <<
2079 ATOMISP_HW_REVISION_SHIFT) | ATOMISP_HW_STEPPING_B0)) {
2080 pci_write_config_word(pdev, MRFLD_PCI_CSI_CONTROL,
2081 isp->saved_regs.csi_control & ~MRFLD_PCI_CSI_CONTROL_CSI_READY);
2084 if (atomisp_freq_scaling(isp, ATOMISP_DFS_MODE_LOW, false))
2085 dev_warn(isp->dev, "DFS failed.\n");
2087 * ISP work around, need to reset isp
2088 * Is it correct time to reset ISP when first node does streamoff?
2090 if (isp->sw_contex.power_state == ATOM_ISP_POWER_UP) {
2092 bool recreate_streams[MAX_STREAM_NUM] = {0};
2094 if (isp->isp_timeout)
2095 dev_err(isp->dev, "%s: Resetting with WA activated",
2098 * It is possible that the other asd stream is in the stage
2099 * that v4l2_setfmt is just get called on it, which will
2100 * create css stream on that stream. But at this point, there
2101 * is no way to destroy the css stream created on that stream.
2103 * So force stream destroy here.
2105 for (i = 0; i < isp->num_of_streams; i++) {
2106 if (isp->asd[i].stream_prepared) {
2107 atomisp_destroy_pipes_stream_force(&isp->
2109 recreate_streams[i] = true;
2113 /* disable PUNIT/ISP acknowlede/handshake - SRSE=3 */
2114 pci_write_config_dword(pdev, PCI_I_CONTROL,
2115 isp->saved_regs.i_control | MRFLD_PCI_I_CONTROL_SRSE_RESET_MASK);
2116 dev_err(isp->dev, "atomisp_reset");
2118 for (i = 0; i < isp->num_of_streams; i++) {
2119 if (recreate_streams[i])
2120 atomisp_create_pipes_stream(&isp->asd[i]);
2122 isp->isp_timeout = false;
2127 static int atomisp_streamoff(struct file *file, void *fh,
2128 enum v4l2_buf_type type)
2130 struct video_device *vdev = video_devdata(file);
2131 struct atomisp_device *isp = video_get_drvdata(vdev);
2134 mutex_lock(&isp->streamoff_mutex);
2135 rt_mutex_lock(&isp->mutex);
2136 rval = __atomisp_streamoff(file, fh, type);
2137 rt_mutex_unlock(&isp->mutex);
2138 mutex_unlock(&isp->streamoff_mutex);
2144 * To get the current value of a control.
2145 * applications initialize the id field of a struct v4l2_control and
2146 * call this ioctl with a pointer to this structure
2148 static int atomisp_g_ctrl(struct file *file, void *fh,
2149 struct v4l2_control *control)
2151 struct video_device *vdev = video_devdata(file);
2152 struct atomisp_sub_device *asd = atomisp_to_video_pipe(vdev)->asd;
2153 struct atomisp_device *isp = video_get_drvdata(vdev);
2154 int i, ret = -EINVAL;
2156 for (i = 0; i < ctrls_num; i++) {
2157 if (ci_v4l2_controls[i].id == control->id) {
2166 rt_mutex_lock(&isp->mutex);
2168 switch (control->id) {
2169 case V4L2_CID_IRIS_ABSOLUTE:
2170 case V4L2_CID_EXPOSURE_ABSOLUTE:
2171 case V4L2_CID_FNUMBER_ABSOLUTE:
2172 case V4L2_CID_2A_STATUS:
2173 case V4L2_CID_AUTO_N_PRESET_WHITE_BALANCE:
2174 case V4L2_CID_EXPOSURE:
2175 case V4L2_CID_EXPOSURE_AUTO:
2176 case V4L2_CID_SCENE_MODE:
2177 case V4L2_CID_ISO_SENSITIVITY:
2178 case V4L2_CID_ISO_SENSITIVITY_AUTO:
2179 case V4L2_CID_CONTRAST:
2180 case V4L2_CID_SATURATION:
2181 case V4L2_CID_SHARPNESS:
2182 case V4L2_CID_3A_LOCK:
2183 case V4L2_CID_EXPOSURE_ZONE_NUM:
2184 case V4L2_CID_TEST_PATTERN:
2185 case V4L2_CID_TEST_PATTERN_COLOR_R:
2186 case V4L2_CID_TEST_PATTERN_COLOR_GR:
2187 case V4L2_CID_TEST_PATTERN_COLOR_GB:
2188 case V4L2_CID_TEST_PATTERN_COLOR_B:
2189 rt_mutex_unlock(&isp->mutex);
2190 return v4l2_g_ctrl(isp->inputs[asd->input_curr].camera->
2191 ctrl_handler, control);
2192 case V4L2_CID_COLORFX:
2193 ret = atomisp_color_effect(asd, 0, &control->value);
2195 case V4L2_CID_ATOMISP_BAD_PIXEL_DETECTION:
2196 ret = atomisp_bad_pixel(asd, 0, &control->value);
2198 case V4L2_CID_ATOMISP_POSTPROCESS_GDC_CAC:
2199 ret = atomisp_gdc_cac(asd, 0, &control->value);
2201 case V4L2_CID_ATOMISP_VIDEO_STABLIZATION:
2202 ret = atomisp_video_stable(asd, 0, &control->value);
2204 case V4L2_CID_ATOMISP_FIXED_PATTERN_NR:
2205 ret = atomisp_fixed_pattern(asd, 0, &control->value);
2207 case V4L2_CID_ATOMISP_FALSE_COLOR_CORRECTION:
2208 ret = atomisp_false_color(asd, 0, &control->value);
2210 case V4L2_CID_ATOMISP_LOW_LIGHT:
2211 ret = atomisp_low_light(asd, 0, &control->value);
2218 rt_mutex_unlock(&isp->mutex);
2223 * To change the value of a control.
2224 * applications initialize the id and value fields of a struct v4l2_control
2225 * and call this ioctl.
2227 static int atomisp_s_ctrl(struct file *file, void *fh,
2228 struct v4l2_control *control)
2230 struct video_device *vdev = video_devdata(file);
2231 struct atomisp_sub_device *asd = atomisp_to_video_pipe(vdev)->asd;
2232 struct atomisp_device *isp = video_get_drvdata(vdev);
2233 int i, ret = -EINVAL;
2235 for (i = 0; i < ctrls_num; i++) {
2236 if (ci_v4l2_controls[i].id == control->id) {
2245 rt_mutex_lock(&isp->mutex);
2246 switch (control->id) {
2247 case V4L2_CID_AUTO_N_PRESET_WHITE_BALANCE:
2248 case V4L2_CID_EXPOSURE:
2249 case V4L2_CID_EXPOSURE_AUTO:
2250 case V4L2_CID_EXPOSURE_AUTO_PRIORITY:
2251 case V4L2_CID_SCENE_MODE:
2252 case V4L2_CID_ISO_SENSITIVITY:
2253 case V4L2_CID_ISO_SENSITIVITY_AUTO:
2254 case V4L2_CID_POWER_LINE_FREQUENCY:
2255 case V4L2_CID_EXPOSURE_METERING:
2256 case V4L2_CID_CONTRAST:
2257 case V4L2_CID_SATURATION:
2258 case V4L2_CID_SHARPNESS:
2259 case V4L2_CID_3A_LOCK:
2260 case V4L2_CID_COLORFX_CBCR:
2261 case V4L2_CID_TEST_PATTERN:
2262 case V4L2_CID_TEST_PATTERN_COLOR_R:
2263 case V4L2_CID_TEST_PATTERN_COLOR_GR:
2264 case V4L2_CID_TEST_PATTERN_COLOR_GB:
2265 case V4L2_CID_TEST_PATTERN_COLOR_B:
2266 rt_mutex_unlock(&isp->mutex);
2267 return v4l2_s_ctrl(NULL,
2268 isp->inputs[asd->input_curr].camera->
2269 ctrl_handler, control);
2270 case V4L2_CID_COLORFX:
2271 ret = atomisp_color_effect(asd, 1, &control->value);
2273 case V4L2_CID_ATOMISP_BAD_PIXEL_DETECTION:
2274 ret = atomisp_bad_pixel(asd, 1, &control->value);
2276 case V4L2_CID_ATOMISP_POSTPROCESS_GDC_CAC:
2277 ret = atomisp_gdc_cac(asd, 1, &control->value);
2279 case V4L2_CID_ATOMISP_VIDEO_STABLIZATION:
2280 ret = atomisp_video_stable(asd, 1, &control->value);
2282 case V4L2_CID_ATOMISP_FIXED_PATTERN_NR:
2283 ret = atomisp_fixed_pattern(asd, 1, &control->value);
2285 case V4L2_CID_ATOMISP_FALSE_COLOR_CORRECTION:
2286 ret = atomisp_false_color(asd, 1, &control->value);
2288 case V4L2_CID_REQUEST_FLASH:
2289 ret = atomisp_flash_enable(asd, control->value);
2291 case V4L2_CID_ATOMISP_LOW_LIGHT:
2292 ret = atomisp_low_light(asd, 1, &control->value);
2298 rt_mutex_unlock(&isp->mutex);
2303 * To query the attributes of a control.
2304 * applications set the id field of a struct v4l2_queryctrl and call the
2305 * this ioctl with a pointer to this structure. The driver fills
2306 * the rest of the structure.
2308 static int atomisp_queryctl(struct file *file, void *fh,
2309 struct v4l2_queryctrl *qc)
2311 int i, ret = -EINVAL;
2312 struct video_device *vdev = video_devdata(file);
2313 struct atomisp_sub_device *asd = atomisp_to_video_pipe(vdev)->asd;
2314 struct atomisp_device *isp = video_get_drvdata(vdev);
2317 case V4L2_CID_FOCUS_ABSOLUTE:
2318 case V4L2_CID_FOCUS_RELATIVE:
2319 case V4L2_CID_FOCUS_STATUS:
2321 return v4l2_queryctrl(isp->inputs[asd->input_curr].camera->
2326 return v4l2_queryctrl(isp->motor->ctrl_handler, qc);
2328 return v4l2_queryctrl(isp->inputs[asd->input_curr].
2329 camera->ctrl_handler, qc);
2332 if (qc->id & V4L2_CTRL_FLAG_NEXT_CTRL)
2335 for (i = 0; i < ctrls_num; i++) {
2336 if (ci_v4l2_controls[i].id == qc->id) {
2337 memcpy(qc, &ci_v4l2_controls[i],
2338 sizeof(struct v4l2_queryctrl));
2339 qc->reserved[0] = 0;
2345 qc->flags = V4L2_CTRL_FLAG_DISABLED;
2350 static int atomisp_camera_g_ext_ctrls(struct file *file, void *fh,
2351 struct v4l2_ext_controls *c)
2353 struct video_device *vdev = video_devdata(file);
2354 struct atomisp_sub_device *asd = atomisp_to_video_pipe(vdev)->asd;
2355 struct atomisp_device *isp = video_get_drvdata(vdev);
2356 struct v4l2_subdev *motor;
2357 struct v4l2_control ctrl;
2362 motor = isp->inputs[asd->input_curr].motor;
2366 for (i = 0; i < c->count; i++) {
2367 ctrl.id = c->controls[i].id;
2368 ctrl.value = c->controls[i].value;
2370 case V4L2_CID_EXPOSURE_ABSOLUTE:
2371 case V4L2_CID_EXPOSURE_AUTO:
2372 case V4L2_CID_IRIS_ABSOLUTE:
2373 case V4L2_CID_FNUMBER_ABSOLUTE:
2374 case V4L2_CID_BIN_FACTOR_HORZ:
2375 case V4L2_CID_BIN_FACTOR_VERT:
2376 case V4L2_CID_3A_LOCK:
2377 case V4L2_CID_TEST_PATTERN:
2378 case V4L2_CID_TEST_PATTERN_COLOR_R:
2379 case V4L2_CID_TEST_PATTERN_COLOR_GR:
2380 case V4L2_CID_TEST_PATTERN_COLOR_GB:
2381 case V4L2_CID_TEST_PATTERN_COLOR_B:
2383 * Exposure related control will be handled by sensor
2387 v4l2_g_ctrl(isp->inputs[asd->input_curr].camera->
2388 ctrl_handler, &ctrl);
2390 case V4L2_CID_FOCUS_ABSOLUTE:
2391 case V4L2_CID_FOCUS_RELATIVE:
2392 case V4L2_CID_FOCUS_STATUS:
2393 case V4L2_CID_FOCUS_AUTO:
2395 ret = v4l2_g_ctrl(motor->ctrl_handler, &ctrl);
2397 case V4L2_CID_FLASH_STATUS:
2398 case V4L2_CID_FLASH_INTENSITY:
2399 case V4L2_CID_FLASH_TORCH_INTENSITY:
2400 case V4L2_CID_FLASH_INDICATOR_INTENSITY:
2401 case V4L2_CID_FLASH_TIMEOUT:
2402 case V4L2_CID_FLASH_STROBE:
2403 case V4L2_CID_FLASH_MODE:
2404 case V4L2_CID_FLASH_STATUS_REGISTER:
2407 v4l2_g_ctrl(isp->flash->ctrl_handler,
2410 case V4L2_CID_ZOOM_ABSOLUTE:
2411 rt_mutex_lock(&isp->mutex);
2412 ret = atomisp_digital_zoom(asd, 0, &ctrl.value);
2413 rt_mutex_unlock(&isp->mutex);
2415 case V4L2_CID_G_SKIP_FRAMES:
2416 ret = v4l2_subdev_call(
2417 isp->inputs[asd->input_curr].camera,
2418 sensor, g_skip_frames, (u32 *)&ctrl.value);
2428 c->controls[i].value = ctrl.value;
2433 /* This ioctl allows the application to get multiple controls by class */
2434 static int atomisp_g_ext_ctrls(struct file *file, void *fh,
2435 struct v4l2_ext_controls *c)
2437 struct v4l2_control ctrl;
2441 * input_lock is not need for the Camera related IOCTLs
2442 * The input_lock downgrade the FPS of 3A
2444 ret = atomisp_camera_g_ext_ctrls(file, fh, c);
2448 for (i = 0; i < c->count; i++) {
2449 ctrl.id = c->controls[i].id;
2450 ctrl.value = c->controls[i].value;
2451 ret = atomisp_g_ctrl(file, fh, &ctrl);
2452 c->controls[i].value = ctrl.value;
2461 static int atomisp_camera_s_ext_ctrls(struct file *file, void *fh,
2462 struct v4l2_ext_controls *c)
2464 struct video_device *vdev = video_devdata(file);
2465 struct atomisp_sub_device *asd = atomisp_to_video_pipe(vdev)->asd;
2466 struct atomisp_device *isp = video_get_drvdata(vdev);
2467 struct v4l2_subdev *motor;
2468 struct v4l2_control ctrl;
2473 motor = isp->inputs[asd->input_curr].motor;
2477 for (i = 0; i < c->count; i++) {
2478 struct v4l2_ctrl *ctr;
2480 ctrl.id = c->controls[i].id;
2481 ctrl.value = c->controls[i].value;
2483 case V4L2_CID_EXPOSURE_ABSOLUTE:
2484 case V4L2_CID_EXPOSURE_AUTO:
2485 case V4L2_CID_EXPOSURE_METERING:
2486 case V4L2_CID_IRIS_ABSOLUTE:
2487 case V4L2_CID_FNUMBER_ABSOLUTE:
2488 case V4L2_CID_VCM_TIMING:
2489 case V4L2_CID_VCM_SLEW:
2490 case V4L2_CID_3A_LOCK:
2491 case V4L2_CID_TEST_PATTERN:
2492 case V4L2_CID_TEST_PATTERN_COLOR_R:
2493 case V4L2_CID_TEST_PATTERN_COLOR_GR:
2494 case V4L2_CID_TEST_PATTERN_COLOR_GB:
2495 case V4L2_CID_TEST_PATTERN_COLOR_B:
2496 ret = v4l2_s_ctrl(NULL,
2497 isp->inputs[asd->input_curr].camera->
2498 ctrl_handler, &ctrl);
2500 case V4L2_CID_FOCUS_ABSOLUTE:
2501 case V4L2_CID_FOCUS_RELATIVE:
2502 case V4L2_CID_FOCUS_STATUS:
2503 case V4L2_CID_FOCUS_AUTO:
2505 ret = v4l2_s_ctrl(NULL, motor->ctrl_handler,
2508 ret = v4l2_s_ctrl(NULL,
2509 isp->inputs[asd->input_curr].
2510 camera->ctrl_handler, &ctrl);
2512 case V4L2_CID_FLASH_STATUS:
2513 case V4L2_CID_FLASH_INTENSITY:
2514 case V4L2_CID_FLASH_TORCH_INTENSITY:
2515 case V4L2_CID_FLASH_INDICATOR_INTENSITY:
2516 case V4L2_CID_FLASH_TIMEOUT:
2517 case V4L2_CID_FLASH_STROBE:
2518 case V4L2_CID_FLASH_MODE:
2519 case V4L2_CID_FLASH_STATUS_REGISTER:
2520 rt_mutex_lock(&isp->mutex);
2523 v4l2_s_ctrl(NULL, isp->flash->ctrl_handler,
2526 * When flash mode is changed we need to reset
2529 if (ctrl.id == V4L2_CID_FLASH_MODE) {
2530 asd->params.flash_state =
2532 asd->params.num_flash_frames = 0;
2535 rt_mutex_unlock(&isp->mutex);
2537 case V4L2_CID_ZOOM_ABSOLUTE:
2538 rt_mutex_lock(&isp->mutex);
2539 ret = atomisp_digital_zoom(asd, 1, &ctrl.value);
2540 rt_mutex_unlock(&isp->mutex);
2543 ctr = v4l2_ctrl_find(&asd->ctrl_handler, ctrl.id);
2545 ret = v4l2_ctrl_s_ctrl(ctr, ctrl.value);
2554 c->controls[i].value = ctrl.value;
2559 /* This ioctl allows the application to set multiple controls by class */
2560 static int atomisp_s_ext_ctrls(struct file *file, void *fh,
2561 struct v4l2_ext_controls *c)
2563 struct v4l2_control ctrl;
2567 * input_lock is not need for the Camera related IOCTLs
2568 * The input_lock downgrade the FPS of 3A
2570 ret = atomisp_camera_s_ext_ctrls(file, fh, c);
2574 for (i = 0; i < c->count; i++) {
2575 ctrl.id = c->controls[i].id;
2576 ctrl.value = c->controls[i].value;
2577 ret = atomisp_s_ctrl(file, fh, &ctrl);
2578 c->controls[i].value = ctrl.value;
2588 * vidioc_g/s_param are used to switch isp running mode
2590 static int atomisp_g_parm(struct file *file, void *fh,
2591 struct v4l2_streamparm *parm)
2593 struct video_device *vdev = video_devdata(file);
2594 struct atomisp_sub_device *asd = atomisp_to_video_pipe(vdev)->asd;
2595 struct atomisp_device *isp = video_get_drvdata(vdev);
2597 if (parm->type != V4L2_BUF_TYPE_VIDEO_CAPTURE) {
2598 dev_err(isp->dev, "unsupport v4l2 buf type\n");
2602 rt_mutex_lock(&isp->mutex);
2603 parm->parm.capture.capturemode = asd->run_mode->val;
2604 rt_mutex_unlock(&isp->mutex);
2609 static int atomisp_s_parm(struct file *file, void *fh,
2610 struct v4l2_streamparm *parm)
2612 struct video_device *vdev = video_devdata(file);
2613 struct atomisp_device *isp = video_get_drvdata(vdev);
2614 struct atomisp_sub_device *asd = atomisp_to_video_pipe(vdev)->asd;
2619 if (parm->type != V4L2_BUF_TYPE_VIDEO_CAPTURE) {
2620 dev_err(isp->dev, "unsupport v4l2 buf type\n");
2624 rt_mutex_lock(&isp->mutex);
2626 asd->high_speed_mode = false;
2627 switch (parm->parm.capture.capturemode) {
2628 case CI_MODE_NONE: {
2629 struct v4l2_subdev_frame_interval fi = {0};
2631 fi.interval = parm->parm.capture.timeperframe;
2633 rval = v4l2_subdev_call(isp->inputs[asd->input_curr].camera,
2634 video, s_frame_interval, &fi);
2636 parm->parm.capture.timeperframe = fi.interval;
2638 if (fi.interval.numerator != 0) {
2639 fps = fi.interval.denominator / fi.interval.numerator;
2641 asd->high_speed_mode = true;
2647 mode = ATOMISP_RUN_MODE_VIDEO;
2649 case CI_MODE_STILL_CAPTURE:
2650 mode = ATOMISP_RUN_MODE_STILL_CAPTURE;
2652 case CI_MODE_CONTINUOUS:
2653 mode = ATOMISP_RUN_MODE_CONTINUOUS_CAPTURE;
2655 case CI_MODE_PREVIEW:
2656 mode = ATOMISP_RUN_MODE_PREVIEW;
2663 rval = v4l2_ctrl_s_ctrl(asd->run_mode, mode);
2666 rt_mutex_unlock(&isp->mutex);
2668 return rval == -ENOIOCTLCMD ? 0 : rval;
2671 static int atomisp_s_parm_file(struct file *file, void *fh,
2672 struct v4l2_streamparm *parm)
2674 struct video_device *vdev = video_devdata(file);
2675 struct atomisp_device *isp = video_get_drvdata(vdev);
2677 if (parm->type != V4L2_BUF_TYPE_VIDEO_OUTPUT) {
2678 dev_err(isp->dev, "unsupport v4l2 buf type for output\n");
2682 rt_mutex_lock(&isp->mutex);
2683 isp->sw_contex.file_input = true;
2684 rt_mutex_unlock(&isp->mutex);
2689 static long atomisp_vidioc_default(struct file *file, void *fh,
2690 bool valid_prio, unsigned int cmd, void *arg)
2692 struct video_device *vdev = video_devdata(file);
2693 struct atomisp_device *isp = video_get_drvdata(vdev);
2694 struct atomisp_sub_device *asd;
2695 struct v4l2_subdev *motor;
2699 acc_node = !strcmp(vdev->name, "ATOMISP ISP ACC");
2701 asd = atomisp_to_acc_pipe(vdev)->asd;
2703 asd = atomisp_to_video_pipe(vdev)->asd;
2706 motor = isp->inputs[asd->input_curr].motor;
2711 case ATOMISP_IOC_G_MOTOR_PRIV_INT_DATA:
2712 case ATOMISP_IOC_S_EXPOSURE:
2713 case ATOMISP_IOC_G_SENSOR_CALIBRATION_GROUP:
2714 case ATOMISP_IOC_G_SENSOR_PRIV_INT_DATA:
2715 case ATOMISP_IOC_EXT_ISP_CTRL:
2716 case ATOMISP_IOC_G_SENSOR_AE_BRACKETING_INFO:
2717 case ATOMISP_IOC_S_SENSOR_AE_BRACKETING_MODE:
2718 case ATOMISP_IOC_G_SENSOR_AE_BRACKETING_MODE:
2719 case ATOMISP_IOC_S_SENSOR_AE_BRACKETING_LUT:
2720 case ATOMISP_IOC_S_SENSOR_EE_CONFIG:
2721 case ATOMISP_IOC_G_UPDATE_EXPOSURE:
2722 /* we do not need take isp->mutex for these IOCTLs */
2725 rt_mutex_lock(&isp->mutex);
2729 case ATOMISP_IOC_S_SENSOR_RUNMODE:
2731 err = atomisp_set_sensor_runmode(asd, arg);
2736 case ATOMISP_IOC_G_XNR:
2737 err = atomisp_xnr(asd, 0, arg);
2740 case ATOMISP_IOC_S_XNR:
2741 err = atomisp_xnr(asd, 1, arg);
2744 case ATOMISP_IOC_G_NR:
2745 err = atomisp_nr(asd, 0, arg);
2748 case ATOMISP_IOC_S_NR:
2749 err = atomisp_nr(asd, 1, arg);
2752 case ATOMISP_IOC_G_TNR:
2753 err = atomisp_tnr(asd, 0, arg);
2756 case ATOMISP_IOC_S_TNR:
2757 err = atomisp_tnr(asd, 1, arg);
2760 case ATOMISP_IOC_G_BLACK_LEVEL_COMP:
2761 err = atomisp_black_level(asd, 0, arg);
2764 case ATOMISP_IOC_S_BLACK_LEVEL_COMP:
2765 err = atomisp_black_level(asd, 1, arg);
2768 case ATOMISP_IOC_G_EE:
2769 err = atomisp_ee(asd, 0, arg);
2772 case ATOMISP_IOC_S_EE:
2773 err = atomisp_ee(asd, 1, arg);
2776 case ATOMISP_IOC_G_DIS_STAT:
2777 err = atomisp_get_dis_stat(asd, arg);
2780 case ATOMISP_IOC_G_DVS2_BQ_RESOLUTIONS:
2781 err = atomisp_get_dvs2_bq_resolutions(asd, arg);
2784 case ATOMISP_IOC_S_DIS_COEFS:
2785 err = atomisp_css_cp_dvs2_coefs(asd, arg,
2786 &asd->params.css_param, true);
2788 asd->params.css_update_params_needed = true;
2791 case ATOMISP_IOC_S_DIS_VECTOR:
2792 err = atomisp_cp_dvs_6axis_config(asd, arg,
2793 &asd->params.css_param, true);
2795 asd->params.css_update_params_needed = true;
2798 case ATOMISP_IOC_G_ISP_PARM:
2799 err = atomisp_param(asd, 0, arg);
2802 case ATOMISP_IOC_S_ISP_PARM:
2803 err = atomisp_param(asd, 1, arg);
2806 case ATOMISP_IOC_G_3A_STAT:
2807 err = atomisp_3a_stat(asd, 0, arg);
2810 case ATOMISP_IOC_G_ISP_GAMMA:
2811 err = atomisp_gamma(asd, 0, arg);
2814 case ATOMISP_IOC_S_ISP_GAMMA:
2815 err = atomisp_gamma(asd, 1, arg);
2818 case ATOMISP_IOC_G_ISP_GDC_TAB:
2819 err = atomisp_gdc_cac_table(asd, 0, arg);
2822 case ATOMISP_IOC_S_ISP_GDC_TAB:
2823 err = atomisp_gdc_cac_table(asd, 1, arg);
2826 case ATOMISP_IOC_G_ISP_MACC:
2827 err = atomisp_macc_table(asd, 0, arg);
2830 case ATOMISP_IOC_S_ISP_MACC:
2831 err = atomisp_macc_table(asd, 1, arg);
2834 case ATOMISP_IOC_G_ISP_BAD_PIXEL_DETECTION:
2835 err = atomisp_bad_pixel_param(asd, 0, arg);
2838 case ATOMISP_IOC_S_ISP_BAD_PIXEL_DETECTION:
2839 err = atomisp_bad_pixel_param(asd, 1, arg);
2842 case ATOMISP_IOC_G_ISP_FALSE_COLOR_CORRECTION:
2843 err = atomisp_false_color_param(asd, 0, arg);
2846 case ATOMISP_IOC_S_ISP_FALSE_COLOR_CORRECTION:
2847 err = atomisp_false_color_param(asd, 1, arg);
2850 case ATOMISP_IOC_G_ISP_CTC:
2851 err = atomisp_ctc(asd, 0, arg);
2854 case ATOMISP_IOC_S_ISP_CTC:
2855 err = atomisp_ctc(asd, 1, arg);
2858 case ATOMISP_IOC_G_ISP_WHITE_BALANCE:
2859 err = atomisp_white_balance_param(asd, 0, arg);
2862 case ATOMISP_IOC_S_ISP_WHITE_BALANCE:
2863 err = atomisp_white_balance_param(asd, 1, arg);
2866 case ATOMISP_IOC_G_3A_CONFIG:
2867 err = atomisp_3a_config_param(asd, 0, arg);
2870 case ATOMISP_IOC_S_3A_CONFIG:
2871 err = atomisp_3a_config_param(asd, 1, arg);
2874 case ATOMISP_IOC_S_ISP_FPN_TABLE:
2875 err = atomisp_fixed_pattern_table(asd, arg);
2878 case ATOMISP_IOC_ISP_MAKERNOTE:
2879 err = atomisp_exif_makernote(asd, arg);
2882 case ATOMISP_IOC_G_SENSOR_MODE_DATA:
2883 err = atomisp_get_sensor_mode_data(asd, arg);
2886 case ATOMISP_IOC_G_MOTOR_PRIV_INT_DATA:
2888 err = v4l2_subdev_call(motor, core, ioctl, cmd, arg);
2890 err = v4l2_subdev_call(isp->inputs[asd->input_curr].camera,
2891 core, ioctl, cmd, arg);
2894 case ATOMISP_IOC_S_EXPOSURE:
2895 case ATOMISP_IOC_G_SENSOR_CALIBRATION_GROUP:
2896 case ATOMISP_IOC_G_SENSOR_PRIV_INT_DATA:
2897 case ATOMISP_IOC_G_SENSOR_AE_BRACKETING_INFO:
2898 case ATOMISP_IOC_S_SENSOR_AE_BRACKETING_MODE:
2899 case ATOMISP_IOC_G_SENSOR_AE_BRACKETING_MODE:
2900 case ATOMISP_IOC_S_SENSOR_AE_BRACKETING_LUT:
2901 err = v4l2_subdev_call(isp->inputs[asd->input_curr].camera,
2902 core, ioctl, cmd, arg);
2904 case ATOMISP_IOC_G_UPDATE_EXPOSURE:
2906 err = v4l2_subdev_call(isp->inputs[asd->input_curr].camera,
2907 core, ioctl, cmd, arg);
2912 case ATOMISP_IOC_ACC_LOAD:
2913 err = atomisp_acc_load(asd, arg);
2916 case ATOMISP_IOC_ACC_LOAD_TO_PIPE:
2917 err = atomisp_acc_load_to_pipe(asd, arg);
2920 case ATOMISP_IOC_ACC_UNLOAD:
2921 err = atomisp_acc_unload(asd, arg);
2924 case ATOMISP_IOC_ACC_START:
2925 err = atomisp_acc_start(asd, arg);
2928 case ATOMISP_IOC_ACC_WAIT:
2929 err = atomisp_acc_wait(asd, arg);
2932 case ATOMISP_IOC_ACC_MAP:
2933 err = atomisp_acc_map(asd, arg);
2936 case ATOMISP_IOC_ACC_UNMAP:
2937 err = atomisp_acc_unmap(asd, arg);
2940 case ATOMISP_IOC_ACC_S_MAPPED_ARG:
2941 err = atomisp_acc_s_mapped_arg(asd, arg);
2944 case ATOMISP_IOC_S_ISP_SHD_TAB:
2945 err = atomisp_set_shading_table(asd, arg);
2948 case ATOMISP_IOC_G_ISP_GAMMA_CORRECTION:
2949 err = atomisp_gamma_correction(asd, 0, arg);
2952 case ATOMISP_IOC_S_ISP_GAMMA_CORRECTION:
2953 err = atomisp_gamma_correction(asd, 1, arg);
2956 case ATOMISP_IOC_S_PARAMETERS:
2957 err = atomisp_set_parameters(vdev, arg);
2960 case ATOMISP_IOC_S_CONT_CAPTURE_CONFIG:
2961 err = atomisp_offline_capture_configure(asd, arg);
2963 case ATOMISP_IOC_G_METADATA:
2964 err = atomisp_get_metadata(asd, 0, arg);
2966 case ATOMISP_IOC_G_METADATA_BY_TYPE:
2967 err = atomisp_get_metadata_by_type(asd, 0, arg);
2969 case ATOMISP_IOC_EXT_ISP_CTRL:
2970 err = v4l2_subdev_call(isp->inputs[asd->input_curr].camera,
2971 core, ioctl, cmd, arg);
2973 case ATOMISP_IOC_EXP_ID_UNLOCK:
2974 err = atomisp_exp_id_unlock(asd, arg);
2976 case ATOMISP_IOC_EXP_ID_CAPTURE:
2977 err = atomisp_exp_id_capture(asd, arg);
2979 case ATOMISP_IOC_S_ENABLE_DZ_CAPT_PIPE:
2980 err = atomisp_enable_dz_capt_pipe(asd, arg);
2982 case ATOMISP_IOC_G_FORMATS_CONFIG:
2983 err = atomisp_formats(asd, 0, arg);
2986 case ATOMISP_IOC_S_FORMATS_CONFIG:
2987 err = atomisp_formats(asd, 1, arg);
2989 case ATOMISP_IOC_S_EXPOSURE_WINDOW:
2990 err = atomisp_s_ae_window(asd, arg);
2992 case ATOMISP_IOC_S_ACC_STATE:
2993 err = atomisp_acc_set_state(asd, arg);
2995 case ATOMISP_IOC_G_ACC_STATE:
2996 err = atomisp_acc_get_state(asd, arg);
2998 case ATOMISP_IOC_INJECT_A_FAKE_EVENT:
2999 err = atomisp_inject_a_fake_event(asd, arg);
3001 case ATOMISP_IOC_G_INVALID_FRAME_NUM:
3002 err = atomisp_get_invalid_frame_num(vdev, arg);
3004 case ATOMISP_IOC_S_ARRAY_RESOLUTION:
3005 err = atomisp_set_array_res(asd, arg);
3013 case ATOMISP_IOC_G_MOTOR_PRIV_INT_DATA:
3014 case ATOMISP_IOC_S_EXPOSURE:
3015 case ATOMISP_IOC_G_SENSOR_CALIBRATION_GROUP:
3016 case ATOMISP_IOC_G_SENSOR_PRIV_INT_DATA:
3017 case ATOMISP_IOC_EXT_ISP_CTRL:
3018 case ATOMISP_IOC_G_SENSOR_AE_BRACKETING_INFO:
3019 case ATOMISP_IOC_S_SENSOR_AE_BRACKETING_MODE:
3020 case ATOMISP_IOC_G_SENSOR_AE_BRACKETING_MODE:
3021 case ATOMISP_IOC_S_SENSOR_AE_BRACKETING_LUT:
3022 case ATOMISP_IOC_G_UPDATE_EXPOSURE:
3025 rt_mutex_unlock(&isp->mutex);
3031 const struct v4l2_ioctl_ops atomisp_ioctl_ops = {
3032 .vidioc_querycap = atomisp_querycap,
3033 .vidioc_enum_input = atomisp_enum_input,
3034 .vidioc_g_input = atomisp_g_input,
3035 .vidioc_s_input = atomisp_s_input,
3036 .vidioc_queryctrl = atomisp_queryctl,
3037 .vidioc_s_ctrl = atomisp_s_ctrl,
3038 .vidioc_g_ctrl = atomisp_g_ctrl,
3039 .vidioc_s_ext_ctrls = atomisp_s_ext_ctrls,
3040 .vidioc_g_ext_ctrls = atomisp_g_ext_ctrls,
3041 .vidioc_enum_fmt_vid_cap = atomisp_enum_fmt_cap,
3042 .vidioc_try_fmt_vid_cap = atomisp_try_fmt_cap,
3043 .vidioc_g_fmt_vid_cap = atomisp_g_fmt_cap,
3044 .vidioc_s_fmt_vid_cap = atomisp_s_fmt_cap,
3045 .vidioc_reqbufs = atomisp_reqbufs,
3046 .vidioc_querybuf = atomisp_querybuf,
3047 .vidioc_qbuf = atomisp_qbuf,
3048 .vidioc_dqbuf = atomisp_dqbuf,
3049 .vidioc_streamon = atomisp_streamon,
3050 .vidioc_streamoff = atomisp_streamoff,
3051 .vidioc_default = atomisp_vidioc_default,
3052 .vidioc_s_parm = atomisp_s_parm,
3053 .vidioc_g_parm = atomisp_g_parm,
3056 const struct v4l2_ioctl_ops atomisp_file_ioctl_ops = {
3057 .vidioc_querycap = atomisp_querycap,
3058 .vidioc_g_fmt_vid_out = atomisp_g_fmt_file,
3059 .vidioc_s_fmt_vid_out = atomisp_s_fmt_file,
3060 .vidioc_s_parm = atomisp_s_parm_file,
3061 .vidioc_reqbufs = atomisp_reqbufs_file,
3062 .vidioc_querybuf = atomisp_querybuf_file,
3063 .vidioc_qbuf = atomisp_qbuf_file,