2 * Support for Medifield PNW Camera Imaging ISP subsystem.
4 * Copyright (c) 2010 Intel Corporation. All Rights Reserved.
6 * Copyright (c) 2010 Silicon Hive www.siliconhive.com.
8 * This program is free software; you can redistribute it and/or
9 * modify it under the terms of the GNU General Public License version
10 * 2 as published by the Free Software Foundation.
12 * This program is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 * GNU General Public License for more details.
17 * You should have received a copy of the GNU General Public License
18 * along with this program; if not, write to the Free Software
19 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
24 #include <linux/delay.h>
25 #include <linux/pci.h>
27 #include <asm/intel-mid.h>
29 #include <media/v4l2-ioctl.h>
30 #include <media/v4l2-event.h>
31 #include <media/videobuf-vmalloc.h>
33 #include "atomisp_acc.h"
34 #include "atomisp_cmd.h"
35 #include "atomisp_common.h"
36 #include "atomisp_fops.h"
37 #include "atomisp_internal.h"
38 #include "atomisp_ioctl.h"
39 #include "atomisp-regs.h"
40 #include "atomisp_compat.h"
42 #include "sh_css_hrt.h"
44 #include "gp_device.h"
45 #include "device_access.h"
48 #include "hrt/hive_isp_css_mm_hrt.h"
50 /* for v4l2_capability */
51 static const char *DRIVER = "atomisp"; /* max size 15 */
52 static const char *CARD = "ATOM ISP"; /* max size 31 */
53 static const char *BUS_INFO = "PCI-3"; /* max size 31 */
56 * FIXME: ISP should not know beforehand all CIDs supported by sensor.
57 * Instead, it needs to propagate to sensor unkonwn CIDs.
59 static struct v4l2_queryctrl ci_v4l2_controls[] = {
61 .id = V4L2_CID_AUTO_WHITE_BALANCE,
62 .type = V4L2_CTRL_TYPE_BOOLEAN,
63 .name = "Automatic White Balance",
70 .id = V4L2_CID_RED_BALANCE,
71 .type = V4L2_CTRL_TYPE_INTEGER,
72 .name = "Red Balance",
76 .default_value = 0x00,
79 .id = V4L2_CID_BLUE_BALANCE,
80 .type = V4L2_CTRL_TYPE_INTEGER,
81 .name = "Blue Balance",
85 .default_value = 0x00,
89 .type = V4L2_CTRL_TYPE_INTEGER,
94 .default_value = 0x00,
97 .id = V4L2_CID_POWER_LINE_FREQUENCY,
98 .type = V4L2_CTRL_TYPE_MENU,
99 .name = "Light frequency filter",
106 .id = V4L2_CID_COLORFX,
107 .type = V4L2_CTRL_TYPE_INTEGER,
108 .name = "Image Color Effect",
115 .id = V4L2_CID_COLORFX_CBCR,
116 .type = V4L2_CTRL_TYPE_INTEGER,
117 .name = "Image Color Effect CbCr",
124 .id = V4L2_CID_ATOMISP_BAD_PIXEL_DETECTION,
125 .type = V4L2_CTRL_TYPE_INTEGER,
126 .name = "Bad Pixel Correction",
133 .id = V4L2_CID_ATOMISP_POSTPROCESS_GDC_CAC,
134 .type = V4L2_CTRL_TYPE_INTEGER,
142 .id = V4L2_CID_ATOMISP_VIDEO_STABLIZATION,
143 .type = V4L2_CTRL_TYPE_INTEGER,
144 .name = "Video Stablization",
151 .id = V4L2_CID_ATOMISP_FIXED_PATTERN_NR,
152 .type = V4L2_CTRL_TYPE_INTEGER,
153 .name = "Fixed Pattern Noise Reduction",
160 .id = V4L2_CID_ATOMISP_FALSE_COLOR_CORRECTION,
161 .type = V4L2_CTRL_TYPE_INTEGER,
162 .name = "False Color Correction",
169 .id = V4L2_CID_REQUEST_FLASH,
170 .type = V4L2_CTRL_TYPE_INTEGER,
171 .name = "Request flash frames",
178 .id = V4L2_CID_ATOMISP_LOW_LIGHT,
179 .type = V4L2_CTRL_TYPE_BOOLEAN,
180 .name = "Low light mode",
187 .id = V4L2_CID_BIN_FACTOR_HORZ,
188 .type = V4L2_CTRL_TYPE_INTEGER,
189 .name = "Horizontal binning factor",
196 .id = V4L2_CID_BIN_FACTOR_VERT,
197 .type = V4L2_CTRL_TYPE_INTEGER,
198 .name = "Vertical binning factor",
205 .id = V4L2_CID_2A_STATUS,
206 .type = V4L2_CTRL_TYPE_BITMASK,
207 .name = "AE and AWB status",
209 .maximum = V4L2_2A_STATUS_AE_READY | V4L2_2A_STATUS_AWB_READY,
214 .id = V4L2_CID_EXPOSURE,
215 .type = V4L2_CTRL_TYPE_INTEGER,
223 .id = V4L2_CID_EXPOSURE_ZONE_NUM,
224 .type = V4L2_CTRL_TYPE_INTEGER,
225 .name = "one-time exposure zone number",
232 .id = V4L2_CID_EXPOSURE_AUTO_PRIORITY,
233 .type = V4L2_CTRL_TYPE_INTEGER,
234 .name = "Exposure auto priority",
235 .minimum = V4L2_EXPOSURE_AUTO,
236 .maximum = V4L2_EXPOSURE_APERTURE_PRIORITY,
238 .default_value = V4L2_EXPOSURE_AUTO,
241 .id = V4L2_CID_SCENE_MODE,
242 .type = V4L2_CTRL_TYPE_INTEGER,
243 .name = "scene mode",
250 .id = V4L2_CID_ISO_SENSITIVITY,
251 .type = V4L2_CTRL_TYPE_INTEGER,
259 .id = V4L2_CID_ISO_SENSITIVITY_AUTO,
260 .type = V4L2_CTRL_TYPE_INTEGER,
262 .minimum = V4L2_ISO_SENSITIVITY_MANUAL,
263 .maximum = V4L2_ISO_SENSITIVITY_AUTO,
265 .default_value = V4L2_ISO_SENSITIVITY_AUTO,
268 .id = V4L2_CID_AUTO_N_PRESET_WHITE_BALANCE,
269 .type = V4L2_CTRL_TYPE_INTEGER,
270 .name = "white balance",
277 .id = V4L2_CID_EXPOSURE_METERING,
278 .type = V4L2_CTRL_TYPE_MENU,
286 .id = V4L2_CID_3A_LOCK,
287 .type = V4L2_CTRL_TYPE_BITMASK,
290 .maximum = V4L2_LOCK_EXPOSURE | V4L2_LOCK_WHITE_BALANCE
296 .id = V4L2_CID_TEST_PATTERN,
297 .type = V4L2_CTRL_TYPE_INTEGER,
298 .name = "Test Pattern",
305 .id = V4L2_CID_TEST_PATTERN_COLOR_R,
306 .type = V4L2_CTRL_TYPE_INTEGER,
307 .name = "Test Pattern Solid Color R",
314 .id = V4L2_CID_TEST_PATTERN_COLOR_GR,
315 .type = V4L2_CTRL_TYPE_INTEGER,
316 .name = "Test Pattern Solid Color GR",
323 .id = V4L2_CID_TEST_PATTERN_COLOR_GB,
324 .type = V4L2_CTRL_TYPE_INTEGER,
325 .name = "Test Pattern Solid Color GB",
332 .id = V4L2_CID_TEST_PATTERN_COLOR_B,
333 .type = V4L2_CTRL_TYPE_INTEGER,
334 .name = "Test Pattern Solid Color B",
341 static const u32 ctrls_num = ARRAY_SIZE(ci_v4l2_controls);
344 * supported V4L2 fmts and resolutions
346 const struct atomisp_format_bridge atomisp_output_fmts[] = {
348 .pixelformat = V4L2_PIX_FMT_YUV420,
350 .mbus_code = V4L2_MBUS_FMT_CUSTOM_YUV420,
351 .sh_fmt = CSS_FRAME_FORMAT_YUV420,
352 .description = "YUV420, planar",
355 .pixelformat = V4L2_PIX_FMT_YVU420,
357 .mbus_code = V4L2_MBUS_FMT_CUSTOM_YVU420,
358 .sh_fmt = CSS_FRAME_FORMAT_YV12,
359 .description = "YVU420, planar",
362 .pixelformat = V4L2_PIX_FMT_YUV422P,
364 .mbus_code = V4L2_MBUS_FMT_CUSTOM_YUV422P,
365 .sh_fmt = CSS_FRAME_FORMAT_YUV422,
366 .description = "YUV422, planar",
369 .pixelformat = V4L2_PIX_FMT_YUV444,
371 .mbus_code = V4L2_MBUS_FMT_CUSTOM_YUV444,
372 .sh_fmt = CSS_FRAME_FORMAT_YUV444,
373 .description = "YUV444"
375 .pixelformat = V4L2_PIX_FMT_NV12,
377 .mbus_code = V4L2_MBUS_FMT_CUSTOM_NV12,
378 .sh_fmt = CSS_FRAME_FORMAT_NV12,
379 .description = "NV12, Y-plane, CbCr interleaved",
382 .pixelformat = V4L2_PIX_FMT_NV21,
384 .mbus_code = V4L2_MBUS_FMT_CUSTOM_NV21,
385 .sh_fmt = CSS_FRAME_FORMAT_NV21,
386 .description = "NV21, Y-plane, CbCr interleaved",
389 .pixelformat = V4L2_PIX_FMT_NV16,
391 .mbus_code = V4L2_MBUS_FMT_CUSTOM_NV16,
392 .sh_fmt = CSS_FRAME_FORMAT_NV16,
393 .description = "NV16, Y-plane, CbCr interleaved",
396 .pixelformat = V4L2_PIX_FMT_YUYV,
398 .mbus_code = V4L2_MBUS_FMT_CUSTOM_YUYV,
399 .sh_fmt = CSS_FRAME_FORMAT_YUYV,
400 .description = "YUYV, interleaved"
402 .pixelformat = V4L2_PIX_FMT_UYVY,
404 .mbus_code = MEDIA_BUS_FMT_UYVY8_1X16,
405 .sh_fmt = CSS_FRAME_FORMAT_UYVY,
406 .description = "UYVY, interleaved"
407 }, { /* This one is for parallel sensors! DO NOT USE! */
408 .pixelformat = V4L2_PIX_FMT_UYVY,
410 .mbus_code = MEDIA_BUS_FMT_UYVY8_2X8,
411 .sh_fmt = CSS_FRAME_FORMAT_UYVY,
412 .description = "UYVY, interleaved"
414 .pixelformat = V4L2_PIX_FMT_SBGGR16,
416 .mbus_code = V4L2_MBUS_FMT_CUSTOM_SBGGR16,
417 .sh_fmt = CSS_FRAME_FORMAT_RAW,
418 .description = "Bayer 16"
420 .pixelformat = V4L2_PIX_FMT_SBGGR8,
422 .mbus_code = MEDIA_BUS_FMT_SBGGR8_1X8,
423 .sh_fmt = CSS_FRAME_FORMAT_RAW,
424 .description = "Bayer 8"
426 .pixelformat = V4L2_PIX_FMT_SGBRG8,
428 .mbus_code = MEDIA_BUS_FMT_SGBRG8_1X8,
429 .sh_fmt = CSS_FRAME_FORMAT_RAW,
430 .description = "Bayer 8"
432 .pixelformat = V4L2_PIX_FMT_SGRBG8,
434 .mbus_code = MEDIA_BUS_FMT_SGRBG8_1X8,
435 .sh_fmt = CSS_FRAME_FORMAT_RAW,
436 .description = "Bayer 8"
438 .pixelformat = V4L2_PIX_FMT_SRGGB8,
440 .mbus_code = MEDIA_BUS_FMT_SRGGB8_1X8,
441 .sh_fmt = CSS_FRAME_FORMAT_RAW,
442 .description = "Bayer 8"
444 .pixelformat = V4L2_PIX_FMT_SBGGR10,
446 .mbus_code = MEDIA_BUS_FMT_SBGGR10_1X10,
447 .sh_fmt = CSS_FRAME_FORMAT_RAW,
448 .description = "Bayer 10"
450 .pixelformat = V4L2_PIX_FMT_SGBRG10,
452 .mbus_code = MEDIA_BUS_FMT_SGBRG10_1X10,
453 .sh_fmt = CSS_FRAME_FORMAT_RAW,
454 .description = "Bayer 10"
456 .pixelformat = V4L2_PIX_FMT_SGRBG10,
458 .mbus_code = MEDIA_BUS_FMT_SGRBG10_1X10,
459 .sh_fmt = CSS_FRAME_FORMAT_RAW,
460 .description = "Bayer 10"
462 .pixelformat = V4L2_PIX_FMT_SRGGB10,
464 .mbus_code = MEDIA_BUS_FMT_SRGGB10_1X10,
465 .sh_fmt = CSS_FRAME_FORMAT_RAW,
466 .description = "Bayer 10"
468 .pixelformat = V4L2_PIX_FMT_SBGGR12,
470 .mbus_code = MEDIA_BUS_FMT_SBGGR12_1X12,
471 .sh_fmt = CSS_FRAME_FORMAT_RAW,
472 .description = "Bayer 12"
474 .pixelformat = V4L2_PIX_FMT_SGBRG12,
476 .mbus_code = MEDIA_BUS_FMT_SGBRG12_1X12,
477 .sh_fmt = CSS_FRAME_FORMAT_RAW,
478 .description = "Bayer 12"
480 .pixelformat = V4L2_PIX_FMT_SGRBG12,
482 .mbus_code = MEDIA_BUS_FMT_SGRBG12_1X12,
483 .sh_fmt = CSS_FRAME_FORMAT_RAW,
484 .description = "Bayer 12"
486 .pixelformat = V4L2_PIX_FMT_SRGGB12,
488 .mbus_code = MEDIA_BUS_FMT_SRGGB12_1X12,
489 .sh_fmt = CSS_FRAME_FORMAT_RAW,
490 .description = "Bayer 12"
492 .pixelformat = V4L2_PIX_FMT_RGB32,
494 .mbus_code = V4L2_MBUS_FMT_CUSTOM_RGB32,
495 .sh_fmt = CSS_FRAME_FORMAT_RGBA888,
496 .description = "32 RGB 8-8-8-8"
498 .pixelformat = V4L2_PIX_FMT_RGB565,
500 .mbus_code = MEDIA_BUS_FMT_BGR565_2X8_LE,
501 .sh_fmt = CSS_FRAME_FORMAT_RGB565,
502 .description = "16 RGB 5-6-5"
504 .pixelformat = V4L2_PIX_FMT_JPEG,
506 .mbus_code = MEDIA_BUS_FMT_JPEG_1X8,
507 .sh_fmt = CSS_FRAME_FORMAT_BINARY_8,
508 .description = "JPEG"
510 /* This is a custom format being used by M10MO to send the RAW data */
511 .pixelformat = V4L2_PIX_FMT_CUSTOM_M10MO_RAW,
513 .mbus_code = V4L2_MBUS_FMT_CUSTOM_M10MO_RAW,
514 .sh_fmt = CSS_FRAME_FORMAT_BINARY_8,
515 .description = "Custom RAW for M10MO"
519 const struct atomisp_format_bridge *atomisp_get_format_bridge(
520 unsigned int pixelformat)
524 for (i = 0; i < ARRAY_SIZE(atomisp_output_fmts); i++) {
525 if (atomisp_output_fmts[i].pixelformat == pixelformat)
526 return &atomisp_output_fmts[i];
532 const struct atomisp_format_bridge *atomisp_get_format_bridge_from_mbus(
537 for (i = 0; i < ARRAY_SIZE(atomisp_output_fmts); i++) {
538 if (mbus_code == atomisp_output_fmts[i].mbus_code)
539 return &atomisp_output_fmts[i];
547 * return ISP capabilities
549 * FIXME: capabilities should be different for video0/video2/video3
551 static int atomisp_querycap(struct file *file, void *fh,
552 struct v4l2_capability *cap)
554 memset(cap, 0, sizeof(struct v4l2_capability));
556 WARN_ON(sizeof(DRIVER) > sizeof(cap->driver) ||
557 sizeof(CARD) > sizeof(cap->card) ||
558 sizeof(BUS_INFO) > sizeof(cap->bus_info));
560 strncpy(cap->driver, DRIVER, sizeof(cap->driver) - 1);
561 strncpy(cap->card, CARD, sizeof(cap->card) - 1);
562 strncpy(cap->bus_info, BUS_INFO, sizeof(cap->card) - 1);
564 cap->device_caps = V4L2_CAP_VIDEO_CAPTURE |
565 V4L2_CAP_STREAMING | V4L2_CAP_VIDEO_OUTPUT;
566 cap->capabilities = cap->device_caps | V4L2_CAP_DEVICE_CAPS;
571 * enum input are used to check primary/secondary camera
573 static int atomisp_enum_input(struct file *file, void *fh,
574 struct v4l2_input *input)
576 struct video_device *vdev = video_devdata(file);
577 struct atomisp_device *isp = video_get_drvdata(vdev);
578 int index = input->index;
580 if (index >= isp->input_cnt)
583 if (!isp->inputs[index].camera)
586 memset(input, 0, sizeof(struct v4l2_input));
587 strncpy(input->name, isp->inputs[index].camera->name,
588 sizeof(input->name) - 1);
591 * HACK: append actuator's name to sensor's
592 * As currently userspace can't talk directly to subdev nodes, this
593 * ioctl is the only way to enum inputs + possible external actuators
594 * for 3A tuning purpose.
597 if (isp->inputs[index].motor &&
598 strlen(isp->inputs[index].motor->name) > 0) {
601 strlen(isp->motor->name) > 0) {
603 const int cur_len = strlen(input->name);
604 const int max_size = sizeof(input->name) - cur_len - 1;
607 input->name[cur_len] = '+';
608 strncpy(&input->name[cur_len + 1],
610 isp->inputs[index].motor->name, max_size - 1);
612 isp->motor->name, max_size - 1);
617 input->type = V4L2_INPUT_TYPE_CAMERA;
618 input->index = index;
619 input->reserved[0] = isp->inputs[index].type;
620 input->reserved[1] = isp->inputs[index].port;
625 static unsigned int atomisp_subdev_streaming_count(
626 struct atomisp_sub_device *asd)
628 return asd->video_out_preview.capq.streaming
629 + asd->video_out_capture.capq.streaming
630 + asd->video_out_video_capture.capq.streaming
631 + asd->video_out_vf.capq.streaming
632 + asd->video_in.capq.streaming;
635 unsigned int atomisp_streaming_count(struct atomisp_device *isp)
639 for (i = 0, sum = 0; i < isp->num_of_streams; i++)
640 sum += isp->asd[i].streaming ==
641 ATOMISP_DEVICE_STREAMING_ENABLED;
646 unsigned int atomisp_is_acc_enabled(struct atomisp_device *isp)
650 for (i = 0; i < isp->num_of_streams; i++)
651 if (isp->asd[i].acc.pipeline)
657 * get input are used to get current primary/secondary camera
659 static int atomisp_g_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;
665 rt_mutex_lock(&isp->mutex);
666 *input = asd->input_curr;
667 rt_mutex_unlock(&isp->mutex);
672 * set input are used to set current primary/secondary camera
674 static int atomisp_s_input(struct file *file, void *fh, unsigned int input)
676 struct video_device *vdev = video_devdata(file);
677 struct atomisp_device *isp = video_get_drvdata(vdev);
678 struct atomisp_sub_device *asd = atomisp_to_video_pipe(vdev)->asd;
679 struct v4l2_subdev *camera = NULL;
682 rt_mutex_lock(&isp->mutex);
683 if (input >= ATOM_ISP_MAX_INPUTS || input >= isp->input_cnt) {
684 dev_dbg(isp->dev, "input_cnt: %d\n", isp->input_cnt);
690 * check whether the request camera:
692 * 2: if in use, whether it is used by other streams
694 if (isp->inputs[input].asd != NULL && isp->inputs[input].asd != asd) {
696 "%s, camera is already used by stream: %d\n", __func__,
697 isp->inputs[input].asd->index);
702 camera = isp->inputs[input].camera;
704 dev_err(isp->dev, "%s, no camera\n", __func__);
709 if (atomisp_subdev_streaming_count(asd)) {
711 "ISP is still streaming, stop first\n");
716 /* power off the current owned sensor, as it is not used this time */
717 if (isp->inputs[asd->input_curr].asd == asd &&
718 asd->input_curr != input) {
719 ret = v4l2_subdev_call(isp->inputs[asd->input_curr].camera,
723 "Failed to power-off sensor\n");
724 /* clear the asd field to show this camera is not used */
725 isp->inputs[asd->input_curr].asd = NULL;
728 /* powe on the new sensor */
729 ret = v4l2_subdev_call(isp->inputs[input].camera, core, s_power, 1);
731 dev_err(isp->dev, "Failed to power-on sensor\n");
735 * Some sensor driver resets the run mode during power-on, thus force
736 * update the run mode to sensor after power-on.
738 atomisp_update_run_mode(asd);
740 /* select operating sensor */
741 ret = v4l2_subdev_call(isp->inputs[input].camera, video, s_routing,
742 0, isp->inputs[input].sensor_index, 0);
743 if (ret && (ret != -ENOIOCTLCMD)) {
744 dev_err(isp->dev, "Failed to select sensor\n");
749 if (!isp->sw_contex.file_input && isp->inputs[input].motor)
750 ret = v4l2_subdev_call(isp->inputs[input].motor, core,
754 ret = v4l2_subdev_call(isp->motor, core, s_power, 1);
756 if (!isp->sw_contex.file_input && isp->motor)
757 ret = v4l2_subdev_call(isp->motor, core, init, 1);
760 asd->input_curr = input;
761 /* mark this camera is used by the current stream */
762 isp->inputs[input].asd = asd;
763 rt_mutex_unlock(&isp->mutex);
768 rt_mutex_unlock(&isp->mutex);
773 static int atomisp_enum_fmt_cap(struct file *file, void *fh,
774 struct v4l2_fmtdesc *f)
776 struct video_device *vdev = video_devdata(file);
777 struct atomisp_device *isp = video_get_drvdata(vdev);
778 struct atomisp_sub_device *asd = atomisp_to_video_pipe(vdev)->asd;
779 struct v4l2_subdev_mbus_code_enum code = { 0 };
780 unsigned int i, fi = 0;
783 rt_mutex_lock(&isp->mutex);
784 rval = v4l2_subdev_call(isp->inputs[asd->input_curr].camera, pad,
785 enum_mbus_code, NULL, &code);
786 if (rval == -ENOIOCTLCMD) {
787 dev_warn(isp->dev, "enum_mbus_code pad op not supported. Please fix your sensor driver!\n");
788 // rval = v4l2_subdev_call(isp->inputs[asd->input_curr].camera,
789 // video, enum_mbus_fmt, 0, &code.code);
791 rt_mutex_unlock(&isp->mutex);
796 for (i = 0; i < ARRAY_SIZE(atomisp_output_fmts); i++) {
797 const struct atomisp_format_bridge *format =
798 &atomisp_output_fmts[i];
801 * Is the atomisp-supported format is valid for the
802 * sensor (configuration)? If not, skip it.
804 if (format->sh_fmt == CSS_FRAME_FORMAT_RAW
805 && format->mbus_code != code.code)
808 /* Found a match. Now let's pick f->index'th one. */
814 strlcpy(f->description, format->description,
815 sizeof(f->description));
816 f->pixelformat = format->pixelformat;
823 static int atomisp_g_fmt_cap(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);
831 rt_mutex_lock(&isp->mutex);
832 ret = atomisp_get_fmt(vdev, f);
833 rt_mutex_unlock(&isp->mutex);
837 static int atomisp_g_fmt_file(struct file *file, void *fh,
838 struct v4l2_format *f)
840 struct video_device *vdev = video_devdata(file);
841 struct atomisp_device *isp = video_get_drvdata(vdev);
842 struct atomisp_video_pipe *pipe = atomisp_to_video_pipe(vdev);
844 rt_mutex_lock(&isp->mutex);
845 f->fmt.pix = pipe->pix;
846 rt_mutex_unlock(&isp->mutex);
851 /* This function looks up the closest available resolution. */
852 static int atomisp_try_fmt_cap(struct file *file, void *fh,
853 struct v4l2_format *f)
855 struct video_device *vdev = video_devdata(file);
856 struct atomisp_device *isp = video_get_drvdata(vdev);
859 rt_mutex_lock(&isp->mutex);
860 ret = atomisp_try_fmt(vdev, f, NULL);
861 rt_mutex_unlock(&isp->mutex);
865 static int atomisp_s_fmt_cap(struct file *file, void *fh,
866 struct v4l2_format *f)
868 struct video_device *vdev = video_devdata(file);
869 struct atomisp_device *isp = video_get_drvdata(vdev);
872 rt_mutex_lock(&isp->mutex);
873 if (isp->isp_fatal_error) {
875 rt_mutex_unlock(&isp->mutex);
878 ret = atomisp_set_fmt(vdev, f);
879 rt_mutex_unlock(&isp->mutex);
883 static int atomisp_s_fmt_file(struct file *file, void *fh,
884 struct v4l2_format *f)
886 struct video_device *vdev = video_devdata(file);
887 struct atomisp_device *isp = video_get_drvdata(vdev);
890 rt_mutex_lock(&isp->mutex);
891 ret = atomisp_set_fmt_file(vdev, f);
892 rt_mutex_unlock(&isp->mutex);
897 * Free videobuffer buffer priv data
899 void atomisp_videobuf_free_buf(struct videobuf_buffer *vb)
901 struct videobuf_vmalloc_memory *vm_mem;
907 if (vm_mem && vm_mem->vaddr) {
908 atomisp_css_frame_free(vm_mem->vaddr);
909 vm_mem->vaddr = NULL;
914 * this function is used to free video buffer queue
916 static void atomisp_videobuf_free_queue(struct videobuf_queue *q)
920 for (i = 0; i < VIDEO_MAX_FRAME; i++) {
921 atomisp_videobuf_free_buf(q->bufs[i]);
927 int atomisp_alloc_css_stat_bufs(struct atomisp_sub_device *asd,
930 struct atomisp_device *isp = asd->isp;
931 struct atomisp_s3a_buf *s3a_buf = NULL, *_s3a_buf;
932 struct atomisp_dis_buf *dis_buf = NULL, *_dis_buf;
933 struct atomisp_metadata_buf *md_buf = NULL, *_md_buf;
935 struct atomisp_css_dvs_grid_info *dvs_grid_info =
936 atomisp_css_get_dvs_grid_info(&asd->params.curr_grid_info);
939 if (list_empty(&asd->s3a_stats) &&
940 asd->params.curr_grid_info.s3a_grid.enable) {
941 count = ATOMISP_CSS_Q_DEPTH +
942 ATOMISP_S3A_BUF_QUEUE_DEPTH_FOR_HAL;
943 dev_dbg(isp->dev, "allocating %d 3a buffers\n", count);
945 s3a_buf = kzalloc(sizeof(struct atomisp_s3a_buf), GFP_KERNEL);
947 dev_err(isp->dev, "s3a stat buf alloc failed\n");
951 if (atomisp_css_allocate_stat_buffers(
952 asd, stream_id, s3a_buf, NULL, NULL)) {
957 list_add_tail(&s3a_buf->list, &asd->s3a_stats);
961 if (list_empty(&asd->dis_stats) && dvs_grid_info &&
962 dvs_grid_info->enable) {
963 count = ATOMISP_CSS_Q_DEPTH + 1;
964 dev_dbg(isp->dev, "allocating %d dis buffers\n", count);
966 dis_buf = kzalloc(sizeof(struct atomisp_dis_buf), GFP_KERNEL);
968 dev_err(isp->dev, "dis stat buf alloc failed\n");
972 if (atomisp_css_allocate_stat_buffers(
973 asd, stream_id, NULL, dis_buf, NULL)) {
978 list_add_tail(&dis_buf->list, &asd->dis_stats);
982 for (i = 0; i < ATOMISP_METADATA_TYPE_NUM; i++) {
983 if (list_empty(&asd->metadata[i]) &&
984 list_empty(&asd->metadata_ready[i]) &&
985 list_empty(&asd->metadata_in_css[i])) {
986 count = ATOMISP_CSS_Q_DEPTH +
987 ATOMISP_METADATA_QUEUE_DEPTH_FOR_HAL;
988 dev_dbg(isp->dev, "allocating %d metadata buffers for type %d\n",
991 md_buf = kzalloc(sizeof(struct atomisp_metadata_buf),
994 dev_err(isp->dev, "metadata buf alloc failed\n");
998 if (atomisp_css_allocate_stat_buffers(
999 asd, stream_id, NULL, NULL, md_buf)) {
1003 list_add_tail(&md_buf->list, &asd->metadata[i]);
1010 dev_err(isp->dev, "failed to allocate statistics buffers\n");
1012 list_for_each_entry_safe(dis_buf, _dis_buf, &asd->dis_stats, list) {
1013 atomisp_css_free_dis_buffer(dis_buf);
1014 list_del(&dis_buf->list);
1018 list_for_each_entry_safe(s3a_buf, _s3a_buf, &asd->s3a_stats, list) {
1019 atomisp_css_free_3a_buffer(s3a_buf);
1020 list_del(&s3a_buf->list);
1024 for (i = 0; i < ATOMISP_METADATA_TYPE_NUM; i++) {
1025 list_for_each_entry_safe(md_buf, _md_buf, &asd->metadata[i],
1027 atomisp_css_free_metadata_buffer(md_buf);
1028 list_del(&md_buf->list);
1036 * Initiate Memory Mapping or User Pointer I/O
1038 int __atomisp_reqbufs(struct file *file, void *fh,
1039 struct v4l2_requestbuffers *req)
1041 struct video_device *vdev = video_devdata(file);
1042 struct atomisp_video_pipe *pipe = atomisp_to_video_pipe(vdev);
1043 struct atomisp_sub_device *asd = pipe->asd;
1044 struct atomisp_css_frame_info frame_info;
1045 struct atomisp_css_frame *frame;
1046 struct videobuf_vmalloc_memory *vm_mem;
1047 uint16_t source_pad = atomisp_subdev_source_pad(vdev);
1048 uint16_t stream_id = atomisp_source_pad_to_stream_id(asd, source_pad);
1051 if (req->count == 0) {
1052 mutex_lock(&pipe->capq.vb_lock);
1053 if (!list_empty(&pipe->capq.stream))
1054 videobuf_queue_cancel(&pipe->capq);
1056 atomisp_videobuf_free_queue(&pipe->capq);
1057 mutex_unlock(&pipe->capq.vb_lock);
1058 /* clear request config id */
1059 memset(pipe->frame_request_config_id, 0,
1060 VIDEO_MAX_FRAME * sizeof(unsigned int));
1061 memset(pipe->frame_params, 0,
1063 sizeof(struct atomisp_css_params_with_list *));
1067 ret = videobuf_reqbufs(&pipe->capq, req);
1071 atomisp_alloc_css_stat_bufs(asd, stream_id);
1074 * for user pointer type, buffers are not really allcated here,
1075 * buffers are setup in QBUF operation through v4l2_buffer structure
1077 if (req->memory == V4L2_MEMORY_USERPTR)
1080 ret = atomisp_get_css_frame_info(asd, source_pad, &frame_info);
1085 * Allocate the real frame here for selected node using our
1086 * memory management function
1088 for (i = 0; i < req->count; i++) {
1089 if (atomisp_css_frame_allocate_from_info(&frame, &frame_info))
1091 vm_mem = pipe->capq.bufs[i]->priv;
1092 vm_mem->vaddr = frame;
1099 vm_mem = pipe->capq.bufs[i]->priv;
1100 atomisp_css_frame_free(vm_mem->vaddr);
1104 atomisp_css_frame_free(asd->vf_frame);
1109 int atomisp_reqbufs(struct file *file, void *fh,
1110 struct v4l2_requestbuffers *req)
1112 struct video_device *vdev = video_devdata(file);
1113 struct atomisp_device *isp = video_get_drvdata(vdev);
1116 rt_mutex_lock(&isp->mutex);
1117 ret = __atomisp_reqbufs(file, fh, req);
1118 rt_mutex_unlock(&isp->mutex);
1123 static int atomisp_reqbufs_file(struct file *file, void *fh,
1124 struct v4l2_requestbuffers *req)
1126 struct video_device *vdev = video_devdata(file);
1127 struct atomisp_video_pipe *pipe = atomisp_to_video_pipe(vdev);
1129 if (req->count == 0) {
1130 mutex_lock(&pipe->outq.vb_lock);
1131 atomisp_videobuf_free_queue(&pipe->outq);
1132 mutex_unlock(&pipe->outq.vb_lock);
1136 return videobuf_reqbufs(&pipe->outq, req);
1139 /* application query the status of a buffer */
1140 static int atomisp_querybuf(struct file *file, void *fh,
1141 struct v4l2_buffer *buf)
1143 struct video_device *vdev = video_devdata(file);
1144 struct atomisp_video_pipe *pipe = atomisp_to_video_pipe(vdev);
1146 return videobuf_querybuf(&pipe->capq, buf);
1149 static int atomisp_querybuf_file(struct file *file, void *fh,
1150 struct v4l2_buffer *buf)
1152 struct video_device *vdev = video_devdata(file);
1153 struct atomisp_video_pipe *pipe = atomisp_to_video_pipe(vdev);
1155 return videobuf_querybuf(&pipe->outq, buf);
1159 * Applications call the VIDIOC_QBUF ioctl to enqueue an empty (capturing) or
1160 * filled (output) buffer in the drivers incoming queue.
1162 static int atomisp_qbuf(struct file *file, void *fh, struct v4l2_buffer *buf)
1164 static const int NOFLUSH_FLAGS = V4L2_BUF_FLAG_NO_CACHE_INVALIDATE |
1165 V4L2_BUF_FLAG_NO_CACHE_CLEAN;
1166 struct video_device *vdev = video_devdata(file);
1167 struct atomisp_device *isp = video_get_drvdata(vdev);
1168 struct atomisp_video_pipe *pipe = atomisp_to_video_pipe(vdev);
1169 struct atomisp_sub_device *asd = pipe->asd;
1170 struct videobuf_buffer *vb;
1171 struct videobuf_vmalloc_memory *vm_mem;
1172 struct atomisp_css_frame_info frame_info;
1173 struct atomisp_css_frame *handle = NULL;
1178 rt_mutex_lock(&isp->mutex);
1179 if (isp->isp_fatal_error) {
1184 if (asd->streaming == ATOMISP_DEVICE_STREAMING_STOPPING) {
1185 dev_err(isp->dev, "%s: reject, as ISP at stopping.\n",
1191 if (!buf || buf->index >= VIDEO_MAX_FRAME ||
1192 !pipe->capq.bufs[buf->index]) {
1193 dev_err(isp->dev, "Invalid index for qbuf.\n");
1199 * For userptr type frame, we convert user space address to physic
1200 * address and reprograme out page table properly
1202 if (buf->memory == V4L2_MEMORY_USERPTR) {
1203 struct hrt_userbuffer_attr attributes;
1204 vb = pipe->capq.bufs[buf->index];
1212 pgnr = (length + (PAGE_SIZE - 1)) >> PAGE_SHIFT;
1214 if (vb->baddr == buf->m.userptr && vm_mem->vaddr)
1217 if (atomisp_get_css_frame_info(asd,
1218 atomisp_subdev_source_pad(vdev), &frame_info)) {
1223 attributes.pgnr = pgnr;
1226 attributes.type = buf->type == V4L2_BUF_TYPE_VIDEO_CAPTURE_ION
1227 ? HRT_USR_ION : HRT_USR_PTR;
1229 if (buf->reserved & ATOMISP_BUFFER_TYPE_IS_ION) {
1230 attributes.type = HRT_USR_ION;
1231 if (asd->ion_dev_fd->val != ION_FD_UNSET) {
1232 dev_dbg(isp->dev, "ION buffer queued, share_fd=%lddev_fd=%d.\n",
1233 buf->m.userptr, asd->ion_dev_fd->val);
1235 * Make sure the shared fd we just got
1236 * from user space isn't larger than
1237 * the space we have for it.
1239 if ((buf->m.userptr &
1240 (ATOMISP_ION_DEVICE_FD_MASK)) != 0) {
1242 "Error: v4l2 buffer fd:0X%0lX > 0XFFFF.\n",
1247 buf->m.userptr |= asd->ion_dev_fd->val <<
1248 ATOMISP_ION_DEVICE_FD_OFFSET;
1250 dev_err(isp->dev, "v4l2 buffer type is ION, \
1251 but no dev fd set from userspace.\n");
1256 attributes.type = HRT_USR_PTR;
1260 attributes.type = HRT_USR_PTR;
1262 ret = atomisp_css_frame_map(&handle, &frame_info,
1263 (void *)buf->m.userptr,
1266 dev_err(isp->dev, "Failed to map user buffer\n");
1270 if (vm_mem->vaddr) {
1271 mutex_lock(&pipe->capq.vb_lock);
1272 atomisp_css_frame_free(vm_mem->vaddr);
1273 vm_mem->vaddr = NULL;
1274 vb->state = VIDEOBUF_NEEDS_INIT;
1275 mutex_unlock(&pipe->capq.vb_lock);
1278 vm_mem->vaddr = handle;
1280 buf->flags &= ~V4L2_BUF_FLAG_MAPPED;
1281 buf->flags |= V4L2_BUF_FLAG_QUEUED;
1282 buf->flags &= ~V4L2_BUF_FLAG_DONE;
1283 } else if (buf->memory == V4L2_MEMORY_MMAP) {
1284 buf->flags |= V4L2_BUF_FLAG_MAPPED;
1285 buf->flags |= V4L2_BUF_FLAG_QUEUED;
1286 buf->flags &= ~V4L2_BUF_FLAG_DONE;
1290 if (!((buf->flags & NOFLUSH_FLAGS) == NOFLUSH_FLAGS))
1293 if (!atomisp_is_vf_pipe(pipe) &&
1294 (buf->reserved2 & ATOMISP_BUFFER_HAS_PER_FRAME_SETTING)) {
1295 /* this buffer will have a per-frame parameter */
1296 pipe->frame_request_config_id[buf->index] = buf->reserved2 &
1297 ~ATOMISP_BUFFER_HAS_PER_FRAME_SETTING;
1298 dev_dbg(isp->dev, "This buffer requires per_frame setting which has isp_config_id %d\n",
1299 pipe->frame_request_config_id[buf->index]);
1301 pipe->frame_request_config_id[buf->index] = 0;
1304 pipe->frame_params[buf->index] = NULL;
1306 rt_mutex_unlock(&isp->mutex);
1308 ret = videobuf_qbuf(&pipe->capq, buf);
1309 rt_mutex_lock(&isp->mutex);
1313 /* TODO: do this better, not best way to queue to css */
1314 if (asd->streaming == ATOMISP_DEVICE_STREAMING_ENABLED) {
1315 if (!list_empty(&pipe->buffers_waiting_for_param)) {
1316 atomisp_handle_parameter_and_buffer(pipe);
1318 atomisp_qbuffers_to_css(asd);
1321 if (!atomisp_is_wdt_running(asd) && atomisp_buffers_queued(asd))
1322 atomisp_wdt_start(asd);
1324 if (!atomisp_is_wdt_running(pipe) &&
1325 atomisp_buffers_queued_pipe(pipe))
1326 atomisp_wdt_start(pipe);
1331 /* Workaround: Due to the design of HALv3,
1332 * sometimes in ZSL or SDV mode HAL needs to
1333 * capture multiple images within one streaming cycle.
1334 * But the capture number cannot be determined by HAL.
1335 * So HAL only sets the capture number to be 1 and queue multiple
1336 * buffers. Atomisp driver needs to check this case and re-trigger
1337 * CSS to do capture when new buffer is queued. */
1338 if (asd->continuous_mode->val &&
1339 atomisp_subdev_source_pad(vdev)
1340 == ATOMISP_SUBDEV_PAD_SOURCE_CAPTURE &&
1341 pipe->capq.streaming &&
1342 !asd->enable_raw_buffer_lock->val &&
1343 asd->params.offline_parm.num_captures == 1) {
1345 asd->pending_capture_request++;
1346 dev_dbg(isp->dev, "Add one pending capture request.\n");
1348 if (asd->re_trigger_capture) {
1349 ret = atomisp_css_offline_capture_configure(asd,
1350 asd->params.offline_parm.num_captures,
1351 asd->params.offline_parm.skip_frames,
1352 asd->params.offline_parm.offset);
1353 asd->re_trigger_capture = false;
1354 dev_dbg(isp->dev, "%s Trigger capture again ret=%d\n",
1358 asd->pending_capture_request++;
1359 asd->re_trigger_capture = false;
1360 dev_dbg(isp->dev, "Add one pending capture request.\n");
1364 rt_mutex_unlock(&isp->mutex);
1366 dev_dbg(isp->dev, "qbuf buffer %d (%s) for asd%d\n", buf->index,
1367 vdev->name, asd->index);
1372 rt_mutex_unlock(&isp->mutex);
1376 static int atomisp_qbuf_file(struct file *file, void *fh,
1377 struct v4l2_buffer *buf)
1379 struct video_device *vdev = video_devdata(file);
1380 struct atomisp_device *isp = video_get_drvdata(vdev);
1381 struct atomisp_video_pipe *pipe = atomisp_to_video_pipe(vdev);
1384 rt_mutex_lock(&isp->mutex);
1385 if (isp->isp_fatal_error) {
1390 if (!buf || buf->index >= VIDEO_MAX_FRAME ||
1391 !pipe->outq.bufs[buf->index]) {
1392 dev_err(isp->dev, "Invalid index for qbuf.\n");
1397 if (buf->memory != V4L2_MEMORY_MMAP) {
1398 dev_err(isp->dev, "Unsupported memory method\n");
1403 if (buf->type != V4L2_BUF_TYPE_VIDEO_OUTPUT) {
1404 dev_err(isp->dev, "Unsupported buffer type\n");
1408 rt_mutex_unlock(&isp->mutex);
1410 return videobuf_qbuf(&pipe->outq, buf);
1413 rt_mutex_unlock(&isp->mutex);
1418 static int __get_frame_exp_id(struct atomisp_video_pipe *pipe,
1419 struct v4l2_buffer *buf)
1421 struct videobuf_vmalloc_memory *vm_mem;
1422 struct atomisp_css_frame *handle;
1425 for (i = 0; pipe->capq.bufs[i]; i++) {
1426 vm_mem = pipe->capq.bufs[i]->priv;
1427 handle = vm_mem->vaddr;
1428 if (buf->index == pipe->capq.bufs[i]->i && handle)
1429 return handle->exp_id;
1435 * Applications call the VIDIOC_DQBUF ioctl to dequeue a filled (capturing) or
1436 * displayed (output buffer)from the driver's outgoing queue
1438 static int atomisp_dqbuf(struct file *file, void *fh, struct v4l2_buffer *buf)
1440 struct video_device *vdev = video_devdata(file);
1441 struct atomisp_video_pipe *pipe = atomisp_to_video_pipe(vdev);
1442 struct atomisp_sub_device *asd = pipe->asd;
1443 struct atomisp_device *isp = video_get_drvdata(vdev);
1446 rt_mutex_lock(&isp->mutex);
1448 if (isp->isp_fatal_error) {
1449 rt_mutex_unlock(&isp->mutex);
1453 if (asd->streaming == ATOMISP_DEVICE_STREAMING_STOPPING) {
1454 rt_mutex_unlock(&isp->mutex);
1455 dev_err(isp->dev, "%s: reject, as ISP at stopping.\n",
1460 rt_mutex_unlock(&isp->mutex);
1462 ret = videobuf_dqbuf(&pipe->capq, buf, file->f_flags & O_NONBLOCK);
1464 dev_dbg(isp->dev, "<%s: %d\n", __func__, ret);
1467 rt_mutex_lock(&isp->mutex);
1468 buf->bytesused = pipe->pix.sizeimage;
1469 buf->reserved = asd->frame_status[buf->index];
1473 * Currently frame_status in the enum type which takes no more lower
1475 * use bit[31:16] for exp_id as it is only in the range of 1~255
1477 buf->reserved &= 0x0000ffff;
1478 if (!(buf->flags & V4L2_BUF_FLAG_ERROR))
1479 buf->reserved |= __get_frame_exp_id(pipe, buf) << 16;
1480 buf->reserved2 = pipe->frame_config_id[buf->index];
1481 rt_mutex_unlock(&isp->mutex);
1483 dev_dbg(isp->dev, "dqbuf buffer %d (%s) for asd%d with exp_id %d, isp_config_id %d\n",
1484 buf->index, vdev->name, asd->index, buf->reserved >> 16,
1489 enum atomisp_css_pipe_id atomisp_get_css_pipe_id(struct atomisp_sub_device *asd)
1491 if (ATOMISP_USE_YUVPP(asd))
1492 return CSS_PIPE_ID_YUVPP;
1494 if (asd->continuous_mode->val) {
1495 if (asd->run_mode->val == ATOMISP_RUN_MODE_VIDEO)
1496 return CSS_PIPE_ID_VIDEO;
1498 return CSS_PIPE_ID_PREVIEW;
1502 * Disable vf_pp and run CSS in video mode. This allows using ISP
1503 * scaling but it has one frame delay due to CSS internal buffering.
1505 if (asd->vfpp->val == ATOMISP_VFPP_DISABLE_SCALER)
1506 return CSS_PIPE_ID_VIDEO;
1509 * Disable vf_pp and run CSS in still capture mode. In this mode
1510 * CSS does not cause extra latency with buffering, but scaling
1513 if (asd->vfpp->val == ATOMISP_VFPP_DISABLE_LOWLAT)
1514 return CSS_PIPE_ID_CAPTURE;
1516 switch (asd->run_mode->val) {
1517 case ATOMISP_RUN_MODE_PREVIEW:
1518 return CSS_PIPE_ID_PREVIEW;
1519 case ATOMISP_RUN_MODE_VIDEO:
1520 return CSS_PIPE_ID_VIDEO;
1521 case ATOMISP_RUN_MODE_STILL_CAPTURE:
1524 return CSS_PIPE_ID_CAPTURE;
1528 static unsigned int atomisp_sensor_start_stream(struct atomisp_sub_device *asd)
1530 struct atomisp_device *isp = asd->isp;
1532 if (isp->inputs[asd->input_curr].camera_caps->
1533 sensor[asd->sensor_curr].stream_num > 1) {
1534 if (asd->high_speed_mode)
1540 if (asd->vfpp->val != ATOMISP_VFPP_ENABLE ||
1544 if (asd->run_mode->val == ATOMISP_RUN_MODE_VIDEO ||
1545 (asd->run_mode->val == ATOMISP_RUN_MODE_STILL_CAPTURE &&
1546 !atomisp_is_mbuscode_raw(
1548 asd->capture_pad].fmt.code) &&
1549 !asd->continuous_mode->val))
1555 int atomisp_stream_on_master_slave_sensor(struct atomisp_device *isp,
1558 unsigned int master = -1, slave = -1, delay_slave = 0;
1562 * ISP only support 2 streams now so ignore multiple master/slave
1563 * case to reduce the delay between 2 stream_on calls.
1565 for (i = 0; i < isp->num_of_streams; i++) {
1566 int sensor_index = isp->asd[i].input_curr;
1567 if (isp->inputs[sensor_index].camera_caps->
1568 sensor[isp->asd[i].sensor_curr].is_slave)
1569 slave = sensor_index;
1571 master = sensor_index;
1574 if (master == -1 || slave == -1) {
1575 master = ATOMISP_DEPTH_DEFAULT_MASTER_SENSOR;
1576 slave = ATOMISP_DEPTH_DEFAULT_SLAVE_SENSOR;
1578 "depth mode use default master=%s.slave=%s.\n",
1579 isp->inputs[master].camera->name,
1580 isp->inputs[slave].camera->name);
1583 ret = v4l2_subdev_call(isp->inputs[master].camera, core,
1584 ioctl, ATOMISP_IOC_G_DEPTH_SYNC_COMP,
1588 "get depth sensor %s compensation delay failed.\n",
1589 isp->inputs[master].camera->name);
1591 ret = v4l2_subdev_call(isp->inputs[master].camera,
1592 video, s_stream, 1);
1594 dev_err(isp->dev, "depth mode master sensor %s stream-on failed.\n",
1595 isp->inputs[master].camera->name);
1599 if (delay_slave != 0)
1600 udelay(delay_slave);
1602 ret = v4l2_subdev_call(isp->inputs[slave].camera,
1603 video, s_stream, 1);
1605 dev_err(isp->dev, "depth mode slave sensor %s stream-on failed.\n",
1606 isp->inputs[slave].camera->name);
1607 v4l2_subdev_call(isp->inputs[master].camera, video, s_stream, 0);
1617 void __wdt_on_master_slave_sensor(struct atomisp_device *isp, unsigned int wdt_duration)
1619 void __wdt_on_master_slave_sensor(struct atomisp_video_pipe *pipe,
1620 unsigned int wdt_duration, bool enable)
1624 if (atomisp_buffers_queued(&isp->asd[0]))
1625 atomisp_wdt_refresh(&isp->asd[0], wdt_duration);
1626 if (atomisp_buffers_queued(&isp->asd[1]))
1627 atomisp_wdt_refresh(&isp->asd[1], wdt_duration);
1629 static struct atomisp_video_pipe *pipe0;
1632 if (atomisp_buffers_queued_pipe(pipe0))
1633 atomisp_wdt_refresh_pipe(pipe0, wdt_duration);
1634 if (atomisp_buffers_queued_pipe(pipe))
1635 atomisp_wdt_refresh_pipe(pipe, wdt_duration);
1642 static void atomisp_pause_buffer_event(struct atomisp_device *isp)
1644 struct v4l2_event event = {0};
1647 event.type = V4L2_EVENT_ATOMISP_PAUSE_BUFFER;
1649 for (i = 0; i < isp->num_of_streams; i++) {
1650 int sensor_index = isp->asd[i].input_curr;
1651 if (isp->inputs[sensor_index].camera_caps->
1652 sensor[isp->asd[i].sensor_curr].is_slave) {
1653 v4l2_event_queue(isp->asd[i].subdev.devnode, &event);
1659 /* Input system HW workaround */
1660 /* Input system address translation corrupts burst during */
1661 /* invalidate. SW workaround for this is to set burst length */
1662 /* manually to 128 in case of 13MPx snapshot and to 1 otherwise. */
1663 static void atomisp_dma_burst_len_cfg(struct atomisp_sub_device *asd)
1666 struct v4l2_mbus_framefmt *sink;
1667 sink = atomisp_subdev_get_ffmt(&asd->subdev, NULL,
1668 V4L2_SUBDEV_FORMAT_ACTIVE,
1669 ATOMISP_SUBDEV_PAD_SINK);
1671 if (sink->width * sink->height >= 4096*3072)
1672 atomisp_store_uint32(DMA_BURST_SIZE_REG, 0x7F);
1674 atomisp_store_uint32(DMA_BURST_SIZE_REG, 0x00);
1678 * This ioctl start the capture during streaming I/O.
1680 static int atomisp_streamon(struct file *file, void *fh,
1681 enum v4l2_buf_type type)
1683 struct video_device *vdev = video_devdata(file);
1684 struct atomisp_video_pipe *pipe = atomisp_to_video_pipe(vdev);
1685 struct atomisp_sub_device *asd = pipe->asd;
1686 struct atomisp_device *isp = video_get_drvdata(vdev);
1687 enum atomisp_css_pipe_id css_pipe_id;
1688 unsigned int sensor_start_stream;
1689 unsigned int wdt_duration = ATOMISP_ISP_TIMEOUT_DURATION;
1691 unsigned long irqflags;
1693 dev_dbg(isp->dev, "Start stream on pad %d for asd%d\n",
1694 atomisp_subdev_source_pad(vdev), asd->index);
1696 if (type != V4L2_BUF_TYPE_VIDEO_CAPTURE) {
1697 dev_dbg(isp->dev, "unsupported v4l2 buf type\n");
1701 rt_mutex_lock(&isp->mutex);
1702 if (isp->isp_fatal_error) {
1707 if (asd->streaming == ATOMISP_DEVICE_STREAMING_STOPPING) {
1712 if (pipe->capq.streaming)
1715 /* Input system HW workaround */
1716 atomisp_dma_burst_len_cfg(asd);
1719 * The number of streaming video nodes is based on which
1720 * binary is going to be run.
1722 sensor_start_stream = atomisp_sensor_start_stream(asd);
1724 spin_lock_irqsave(&pipe->irq_lock, irqflags);
1725 if (list_empty(&(pipe->capq.stream))) {
1726 spin_unlock_irqrestore(&pipe->irq_lock, irqflags);
1727 dev_dbg(isp->dev, "no buffer in the queue\n");
1731 spin_unlock_irqrestore(&pipe->irq_lock, irqflags);
1733 ret = videobuf_streamon(&pipe->capq);
1737 /* Reset pending capture request count. */
1738 asd->pending_capture_request = 0;
1740 asd->re_trigger_capture = false;
1743 if ((atomisp_subdev_streaming_count(asd) > sensor_start_stream) &&
1744 (!isp->inputs[asd->input_curr].camera_caps->multi_stream_ctrl)) {
1745 /* trigger still capture */
1746 if (asd->continuous_mode->val &&
1747 atomisp_subdev_source_pad(vdev)
1748 == ATOMISP_SUBDEV_PAD_SOURCE_CAPTURE) {
1749 if (asd->run_mode->val == ATOMISP_RUN_MODE_VIDEO)
1750 dev_dbg(isp->dev, "SDV last video raw buffer id: %u\n",
1751 asd->latest_preview_exp_id);
1753 dev_dbg(isp->dev, "ZSL last preview raw buffer id: %u\n",
1754 asd->latest_preview_exp_id);
1756 if (asd->delayed_init == ATOMISP_DELAYED_INIT_QUEUED) {
1757 flush_work(&asd->delayed_init_work);
1758 rt_mutex_unlock(&isp->mutex);
1759 if (wait_for_completion_interruptible(
1760 &asd->init_done) != 0)
1761 return -ERESTARTSYS;
1762 rt_mutex_lock(&isp->mutex);
1765 /* handle per_frame_setting parameter and buffers */
1766 atomisp_handle_parameter_and_buffer(pipe);
1769 * only ZSL/SDV capture request will be here, raise
1770 * the ISP freq to the highest possible to minimize
1773 atomisp_freq_scaling(isp, ATOMISP_DFS_MODE_MAX, false);
1775 * When asd->enable_raw_buffer_lock->val is true,
1776 * An extra IOCTL is needed to call
1777 * atomisp_css_exp_id_capture and trigger real capture
1779 if (!asd->enable_raw_buffer_lock->val) {
1780 ret = atomisp_css_offline_capture_configure(asd,
1781 asd->params.offline_parm.num_captures,
1782 asd->params.offline_parm.skip_frames,
1783 asd->params.offline_parm.offset);
1788 if (asd->depth_mode->val)
1789 atomisp_pause_buffer_event(isp);
1792 atomisp_qbuffers_to_css(asd);
1796 if (asd->streaming == ATOMISP_DEVICE_STREAMING_ENABLED) {
1797 atomisp_qbuffers_to_css(asd);
1801 css_pipe_id = atomisp_get_css_pipe_id(asd);
1803 ret = atomisp_acc_load_extensions(asd);
1805 dev_err(isp->dev, "acc extension failed to load\n");
1809 if (asd->params.css_update_params_needed) {
1810 atomisp_apply_css_parameters(asd, &asd->params.css_param);
1811 if (asd->params.css_param.update_flag.dz_config)
1812 atomisp_css_set_dz_config(asd,
1813 &asd->params.css_param.dz_config);
1814 atomisp_css_update_isp_params(asd);
1815 asd->params.css_update_params_needed = false;
1816 memset(&asd->params.css_param.update_flag, 0,
1817 sizeof(struct atomisp_parameters));
1819 asd->params.dvs_6axis = NULL;
1821 ret = atomisp_css_start(asd, css_pipe_id, false);
1825 asd->streaming = ATOMISP_DEVICE_STREAMING_ENABLED;
1826 atomic_set(&asd->sof_count, -1);
1827 atomic_set(&asd->sequence, -1);
1828 atomic_set(&asd->sequence_temp, -1);
1829 if (isp->sw_contex.file_input)
1830 wdt_duration = ATOMISP_ISP_FILE_TIMEOUT_DURATION;
1832 asd->params.dis_proj_data_valid = false;
1833 asd->latest_preview_exp_id = 0;
1834 asd->postview_exp_id = 1;
1835 asd->preview_exp_id = 1;
1837 /* handle per_frame_setting parameter and buffers */
1838 atomisp_handle_parameter_and_buffer(pipe);
1840 atomisp_qbuffers_to_css(asd);
1842 /* Only start sensor when the last streaming instance started */
1843 if (atomisp_subdev_streaming_count(asd) < sensor_start_stream)
1848 asd->params.num_flash_frames = 0;
1849 asd->params.flash_state = ATOMISP_FLASH_IDLE;
1850 atomisp_setup_flash(asd);
1853 if (!isp->sw_contex.file_input) {
1854 atomisp_css_irq_enable(isp, CSS_IRQ_INFO_CSS_RECEIVER_SOF,
1855 atomisp_css_valid_sof(isp));
1856 atomisp_csi2_configure(asd);
1858 * set freq to max when streaming count > 1 which indicate
1859 * dual camera would run
1861 if (atomisp_streaming_count(isp) > 1) {
1862 if (atomisp_freq_scaling(isp,
1863 ATOMISP_DFS_MODE_MAX, false) < 0)
1864 dev_dbg(isp->dev, "dfs failed!\n");
1866 if (atomisp_freq_scaling(isp,
1867 ATOMISP_DFS_MODE_AUTO, false) < 0)
1868 dev_dbg(isp->dev, "dfs failed!\n");
1871 if (atomisp_freq_scaling(isp, ATOMISP_DFS_MODE_MAX, false) < 0)
1872 dev_dbg(isp->dev, "dfs failed!\n");
1875 if (asd->depth_mode->val && atomisp_streaming_count(isp) ==
1876 ATOMISP_DEPTH_SENSOR_STREAMON_COUNT) {
1877 ret = atomisp_stream_on_master_slave_sensor(isp, false);
1879 dev_err(isp->dev, "master slave sensor stream on failed!\n");
1883 __wdt_on_master_slave_sensor(isp, wdt_duration);
1885 __wdt_on_master_slave_sensor(pipe, wdt_duration, true);
1887 goto start_delay_wq;
1888 } else if (asd->depth_mode->val && (atomisp_streaming_count(isp) <
1889 ATOMISP_DEPTH_SENSOR_STREAMON_COUNT)) {
1891 __wdt_on_master_slave_sensor(pipe, wdt_duration, false);
1893 goto start_delay_wq;
1896 /* Enable the CSI interface on ANN B0/K0 */
1897 if (isp->media_dev.hw_revision >= ((ATOMISP_HW_REVISION_ISP2401 <<
1898 ATOMISP_HW_REVISION_SHIFT) | ATOMISP_HW_STEPPING_B0)) {
1899 pci_write_config_word(isp->pdev, MRFLD_PCI_CSI_CONTROL,
1900 isp->saved_regs.csi_control |
1901 MRFLD_PCI_CSI_CONTROL_CSI_READY);
1904 /* stream on the sensor */
1905 ret = v4l2_subdev_call(isp->inputs[asd->input_curr].camera,
1906 video, s_stream, 1);
1908 asd->streaming = ATOMISP_DEVICE_STREAMING_DISABLED;
1914 if (atomisp_buffers_queued(asd))
1915 atomisp_wdt_refresh(asd, wdt_duration);
1917 if (atomisp_buffers_queued_pipe(pipe))
1918 atomisp_wdt_refresh_pipe(pipe, wdt_duration);
1922 if (asd->continuous_mode->val) {
1923 struct v4l2_mbus_framefmt *sink;
1925 sink = atomisp_subdev_get_ffmt(&asd->subdev, NULL,
1926 V4L2_SUBDEV_FORMAT_ACTIVE,
1927 ATOMISP_SUBDEV_PAD_SINK);
1929 reinit_completion(&asd->init_done);
1930 asd->delayed_init = ATOMISP_DELAYED_INIT_QUEUED;
1931 queue_work(asd->delayed_init_workq, &asd->delayed_init_work);
1932 atomisp_css_set_cont_prev_start_time(isp,
1933 ATOMISP_CALC_CSS_PREV_OVERLAP(sink->height));
1935 asd->delayed_init = ATOMISP_DELAYED_INIT_NOT_QUEUED;
1938 rt_mutex_unlock(&isp->mutex);
1942 int __atomisp_streamoff(struct file *file, void *fh, enum v4l2_buf_type type)
1944 struct video_device *vdev = video_devdata(file);
1945 struct atomisp_device *isp = video_get_drvdata(vdev);
1946 struct atomisp_video_pipe *pipe = atomisp_to_video_pipe(vdev);
1947 struct atomisp_sub_device *asd = pipe->asd;
1948 struct atomisp_video_pipe *capture_pipe = NULL;
1949 struct atomisp_video_pipe *vf_pipe = NULL;
1950 struct atomisp_video_pipe *preview_pipe = NULL;
1951 struct atomisp_video_pipe *video_pipe = NULL;
1952 struct videobuf_buffer *vb, *_vb;
1953 enum atomisp_css_pipe_id css_pipe_id;
1955 unsigned long flags;
1956 bool first_streamoff = false;
1958 dev_dbg(isp->dev, "Stop stream on pad %d for asd%d\n",
1959 atomisp_subdev_source_pad(vdev), asd->index);
1961 BUG_ON(!rt_mutex_is_locked(&isp->mutex));
1962 BUG_ON(!mutex_is_locked(&isp->streamoff_mutex));
1964 if (type != V4L2_BUF_TYPE_VIDEO_CAPTURE) {
1965 dev_dbg(isp->dev, "unsupported v4l2 buf type\n");
1970 * do only videobuf_streamoff for capture & vf pipes in
1971 * case of continuous capture
1973 if ((asd->continuous_mode->val ||
1974 isp->inputs[asd->input_curr].camera_caps->multi_stream_ctrl) &&
1975 atomisp_subdev_source_pad(vdev) !=
1976 ATOMISP_SUBDEV_PAD_SOURCE_PREVIEW &&
1977 atomisp_subdev_source_pad(vdev) !=
1978 ATOMISP_SUBDEV_PAD_SOURCE_VIDEO) {
1980 if (isp->inputs[asd->input_curr].camera_caps->multi_stream_ctrl) {
1981 v4l2_subdev_call(isp->inputs[asd->input_curr].camera,
1982 video, s_stream, 0);
1983 } else if (atomisp_subdev_source_pad(vdev)
1984 == ATOMISP_SUBDEV_PAD_SOURCE_CAPTURE) {
1985 /* stop continuous still capture if needed */
1986 if (asd->params.offline_parm.num_captures == -1)
1987 atomisp_css_offline_capture_configure(asd,
1989 atomisp_freq_scaling(isp, ATOMISP_DFS_MODE_AUTO, false);
1992 * Currently there is no way to flush buffers queued to css.
1993 * When doing videobuf_streamoff, active buffers will be
1994 * marked as VIDEOBUF_NEEDS_INIT. HAL will be able to use
1995 * these buffers again, and these buffers might be queued to
1996 * css more than once! Warn here, if HAL has not dequeued all
1997 * buffers back before calling streamoff.
1999 if (pipe->buffers_in_css != 0) {
2000 WARN(1, "%s: buffers of vdev %s still in CSS!\n",
2001 __func__, pipe->vdev.name);
2004 * Buffers remained in css maybe dequeued out in the
2005 * next stream on, while this will causes serious
2006 * issues as buffers already get invalid after
2007 * previous stream off.
2009 * No way to flush buffers but to reset the whole css
2011 dev_warn(isp->dev, "Reset CSS to clean up css buffers.\n");
2012 atomisp_css_flush(isp);
2015 return videobuf_streamoff(&pipe->capq);
2018 if (!pipe->capq.streaming)
2021 spin_lock_irqsave(&isp->lock, flags);
2022 if (asd->streaming == ATOMISP_DEVICE_STREAMING_ENABLED) {
2023 asd->streaming = ATOMISP_DEVICE_STREAMING_STOPPING;
2024 first_streamoff = true;
2026 spin_unlock_irqrestore(&isp->lock, flags);
2028 if (first_streamoff) {
2029 /* if other streams are running, should not disable watch dog */
2030 rt_mutex_unlock(&isp->mutex);
2031 atomisp_wdt_stop(asd, true);
2034 * must stop sending pixels into GP_FIFO before stop
2037 if (isp->sw_contex.file_input)
2038 v4l2_subdev_call(isp->inputs[asd->input_curr].camera,
2039 video, s_stream, 0);
2041 rt_mutex_lock(&isp->mutex);
2042 atomisp_acc_unload_extensions(asd);
2045 spin_lock_irqsave(&isp->lock, flags);
2046 if (atomisp_subdev_streaming_count(asd) == 1)
2047 asd->streaming = ATOMISP_DEVICE_STREAMING_DISABLED;
2048 spin_unlock_irqrestore(&isp->lock, flags);
2050 if (!first_streamoff) {
2051 ret = videobuf_streamoff(&pipe->capq);
2057 atomisp_clear_css_buffer_counters(asd);
2059 if (!isp->sw_contex.file_input)
2060 atomisp_css_irq_enable(isp, CSS_IRQ_INFO_CSS_RECEIVER_SOF,
2063 if (asd->delayed_init == ATOMISP_DELAYED_INIT_QUEUED) {
2064 cancel_work_sync(&asd->delayed_init_work);
2065 asd->delayed_init = ATOMISP_DELAYED_INIT_NOT_QUEUED;
2067 if (first_streamoff) {
2068 css_pipe_id = atomisp_get_css_pipe_id(asd);
2069 ret = atomisp_css_stop(asd, css_pipe_id, false);
2071 /* cancel work queue*/
2072 if (asd->video_out_capture.users) {
2073 capture_pipe = &asd->video_out_capture;
2074 wake_up_interruptible(&capture_pipe->capq.wait);
2076 if (asd->video_out_vf.users) {
2077 vf_pipe = &asd->video_out_vf;
2078 wake_up_interruptible(&vf_pipe->capq.wait);
2080 if (asd->video_out_preview.users) {
2081 preview_pipe = &asd->video_out_preview;
2082 wake_up_interruptible(&preview_pipe->capq.wait);
2084 if (asd->video_out_video_capture.users) {
2085 video_pipe = &asd->video_out_video_capture;
2086 wake_up_interruptible(&video_pipe->capq.wait);
2088 ret = videobuf_streamoff(&pipe->capq);
2092 /* cleanup css here */
2093 /* no need for this, as ISP will be reset anyway */
2094 /*atomisp_flush_bufs_in_css(isp);*/
2096 spin_lock_irqsave(&pipe->irq_lock, flags);
2097 list_for_each_entry_safe(vb, _vb, &pipe->activeq, queue) {
2098 vb->state = VIDEOBUF_PREPARED;
2099 list_del(&vb->queue);
2101 list_for_each_entry_safe(vb, _vb, &pipe->buffers_waiting_for_param, queue) {
2102 vb->state = VIDEOBUF_PREPARED;
2103 list_del(&vb->queue);
2104 pipe->frame_request_config_id[vb->i] = 0;
2106 spin_unlock_irqrestore(&pipe->irq_lock, flags);
2108 atomisp_subdev_cleanup_pending_events(asd);
2110 if (atomisp_subdev_streaming_count(asd) + 1
2111 != atomisp_sensor_start_stream(asd))
2114 if (!isp->sw_contex.file_input)
2115 ret = v4l2_subdev_call(isp->inputs[asd->input_curr].camera,
2116 video, s_stream, 0);
2119 asd->params.num_flash_frames = 0;
2120 asd->params.flash_state = ATOMISP_FLASH_IDLE;
2123 /* if other streams are running, isp should not be powered off */
2124 if (atomisp_streaming_count(isp)) {
2125 atomisp_css_flush(isp);
2129 /* Disable the CSI interface on ANN B0/K0 */
2130 if (isp->media_dev.hw_revision >= ((ATOMISP_HW_REVISION_ISP2401 <<
2131 ATOMISP_HW_REVISION_SHIFT) | ATOMISP_HW_STEPPING_B0)) {
2132 pci_write_config_word(isp->pdev, MRFLD_PCI_CSI_CONTROL,
2133 isp->saved_regs.csi_control &
2134 ~MRFLD_PCI_CSI_CONTROL_CSI_READY);
2137 if (atomisp_freq_scaling(isp, ATOMISP_DFS_MODE_LOW, false))
2138 dev_warn(isp->dev, "DFS failed.\n");
2140 * ISP work around, need to reset isp
2141 * Is it correct time to reset ISP when first node does streamoff?
2143 if (isp->sw_contex.power_state == ATOM_ISP_POWER_UP) {
2145 bool recreate_streams[MAX_STREAM_NUM] = {0};
2146 if (isp->isp_timeout)
2147 dev_err(isp->dev, "%s: Resetting with WA activated",
2150 * It is possible that the other asd stream is in the stage
2151 * that v4l2_setfmt is just get called on it, which will
2152 * create css stream on that stream. But at this point, there
2153 * is no way to destroy the css stream created on that stream.
2155 * So force stream destroy here.
2157 for (i = 0; i < isp->num_of_streams; i++) {
2158 if (isp->asd[i].stream_prepared) {
2159 atomisp_destroy_pipes_stream_force(&isp->
2161 recreate_streams[i] = true;
2165 /* disable PUNIT/ISP acknowlede/handshake - SRSE=3 */
2166 pci_write_config_dword(isp->pdev, PCI_I_CONTROL, isp->saved_regs.i_control |
2167 MRFLD_PCI_I_CONTROL_SRSE_RESET_MASK);
2168 dev_err(isp->dev, "atomisp_reset");
2170 for (i = 0; i < isp->num_of_streams; i++) {
2171 if (recreate_streams[i])
2172 atomisp_create_pipes_stream(&isp->asd[i]);
2174 isp->isp_timeout = false;
2179 static int atomisp_streamoff(struct file *file, void *fh,
2180 enum v4l2_buf_type type)
2182 struct video_device *vdev = video_devdata(file);
2183 struct atomisp_device *isp = video_get_drvdata(vdev);
2186 mutex_lock(&isp->streamoff_mutex);
2187 rt_mutex_lock(&isp->mutex);
2188 rval = __atomisp_streamoff(file, fh, type);
2189 rt_mutex_unlock(&isp->mutex);
2190 mutex_unlock(&isp->streamoff_mutex);
2196 * To get the current value of a control.
2197 * applications initialize the id field of a struct v4l2_control and
2198 * call this ioctl with a pointer to this structure
2200 static int atomisp_g_ctrl(struct file *file, void *fh,
2201 struct v4l2_control *control)
2203 struct video_device *vdev = video_devdata(file);
2204 struct atomisp_sub_device *asd = atomisp_to_video_pipe(vdev)->asd;
2205 struct atomisp_device *isp = video_get_drvdata(vdev);
2206 int i, ret = -EINVAL;
2208 for (i = 0; i < ctrls_num; i++) {
2209 if (ci_v4l2_controls[i].id == control->id) {
2218 rt_mutex_lock(&isp->mutex);
2220 switch (control->id) {
2221 case V4L2_CID_IRIS_ABSOLUTE:
2222 case V4L2_CID_EXPOSURE_ABSOLUTE:
2223 case V4L2_CID_FNUMBER_ABSOLUTE:
2224 case V4L2_CID_2A_STATUS:
2225 case V4L2_CID_AUTO_N_PRESET_WHITE_BALANCE:
2226 case V4L2_CID_EXPOSURE:
2227 case V4L2_CID_EXPOSURE_AUTO:
2228 case V4L2_CID_SCENE_MODE:
2229 case V4L2_CID_ISO_SENSITIVITY:
2230 case V4L2_CID_ISO_SENSITIVITY_AUTO:
2231 case V4L2_CID_CONTRAST:
2232 case V4L2_CID_SATURATION:
2233 case V4L2_CID_SHARPNESS:
2234 case V4L2_CID_3A_LOCK:
2235 case V4L2_CID_EXPOSURE_ZONE_NUM:
2236 case V4L2_CID_TEST_PATTERN:
2237 case V4L2_CID_TEST_PATTERN_COLOR_R:
2238 case V4L2_CID_TEST_PATTERN_COLOR_GR:
2239 case V4L2_CID_TEST_PATTERN_COLOR_GB:
2240 case V4L2_CID_TEST_PATTERN_COLOR_B:
2241 rt_mutex_unlock(&isp->mutex);
2242 return v4l2_g_ctrl(isp->inputs[asd->input_curr].camera->
2243 ctrl_handler, control);
2244 case V4L2_CID_COLORFX:
2245 ret = atomisp_color_effect(asd, 0, &control->value);
2247 case V4L2_CID_ATOMISP_BAD_PIXEL_DETECTION:
2248 ret = atomisp_bad_pixel(asd, 0, &control->value);
2250 case V4L2_CID_ATOMISP_POSTPROCESS_GDC_CAC:
2251 ret = atomisp_gdc_cac(asd, 0, &control->value);
2253 case V4L2_CID_ATOMISP_VIDEO_STABLIZATION:
2254 ret = atomisp_video_stable(asd, 0, &control->value);
2256 case V4L2_CID_ATOMISP_FIXED_PATTERN_NR:
2257 ret = atomisp_fixed_pattern(asd, 0, &control->value);
2259 case V4L2_CID_ATOMISP_FALSE_COLOR_CORRECTION:
2260 ret = atomisp_false_color(asd, 0, &control->value);
2262 case V4L2_CID_ATOMISP_LOW_LIGHT:
2263 ret = atomisp_low_light(asd, 0, &control->value);
2270 rt_mutex_unlock(&isp->mutex);
2275 * To change the value of a control.
2276 * applications initialize the id and value fields of a struct v4l2_control
2277 * and call this ioctl.
2279 static int atomisp_s_ctrl(struct file *file, void *fh,
2280 struct v4l2_control *control)
2282 struct video_device *vdev = video_devdata(file);
2283 struct atomisp_sub_device *asd = atomisp_to_video_pipe(vdev)->asd;
2284 struct atomisp_device *isp = video_get_drvdata(vdev);
2285 int i, ret = -EINVAL;
2287 for (i = 0; i < ctrls_num; i++) {
2288 if (ci_v4l2_controls[i].id == control->id) {
2297 rt_mutex_lock(&isp->mutex);
2298 switch (control->id) {
2299 case V4L2_CID_AUTO_N_PRESET_WHITE_BALANCE:
2300 case V4L2_CID_EXPOSURE:
2301 case V4L2_CID_EXPOSURE_AUTO:
2302 case V4L2_CID_EXPOSURE_AUTO_PRIORITY:
2303 case V4L2_CID_SCENE_MODE:
2304 case V4L2_CID_ISO_SENSITIVITY:
2305 case V4L2_CID_ISO_SENSITIVITY_AUTO:
2306 case V4L2_CID_POWER_LINE_FREQUENCY:
2307 case V4L2_CID_EXPOSURE_METERING:
2308 case V4L2_CID_CONTRAST:
2309 case V4L2_CID_SATURATION:
2310 case V4L2_CID_SHARPNESS:
2311 case V4L2_CID_3A_LOCK:
2312 case V4L2_CID_COLORFX_CBCR:
2313 case V4L2_CID_TEST_PATTERN:
2314 case V4L2_CID_TEST_PATTERN_COLOR_R:
2315 case V4L2_CID_TEST_PATTERN_COLOR_GR:
2316 case V4L2_CID_TEST_PATTERN_COLOR_GB:
2317 case V4L2_CID_TEST_PATTERN_COLOR_B:
2318 rt_mutex_unlock(&isp->mutex);
2319 return v4l2_s_ctrl(NULL,
2320 isp->inputs[asd->input_curr].camera->
2321 ctrl_handler, control);
2322 case V4L2_CID_COLORFX:
2323 ret = atomisp_color_effect(asd, 1, &control->value);
2325 case V4L2_CID_ATOMISP_BAD_PIXEL_DETECTION:
2326 ret = atomisp_bad_pixel(asd, 1, &control->value);
2328 case V4L2_CID_ATOMISP_POSTPROCESS_GDC_CAC:
2329 ret = atomisp_gdc_cac(asd, 1, &control->value);
2331 case V4L2_CID_ATOMISP_VIDEO_STABLIZATION:
2332 ret = atomisp_video_stable(asd, 1, &control->value);
2334 case V4L2_CID_ATOMISP_FIXED_PATTERN_NR:
2335 ret = atomisp_fixed_pattern(asd, 1, &control->value);
2337 case V4L2_CID_ATOMISP_FALSE_COLOR_CORRECTION:
2338 ret = atomisp_false_color(asd, 1, &control->value);
2340 case V4L2_CID_REQUEST_FLASH:
2341 ret = atomisp_flash_enable(asd, control->value);
2343 case V4L2_CID_ATOMISP_LOW_LIGHT:
2344 ret = atomisp_low_light(asd, 1, &control->value);
2350 rt_mutex_unlock(&isp->mutex);
2354 * To query the attributes of a control.
2355 * applications set the id field of a struct v4l2_queryctrl and call the
2356 * this ioctl with a pointer to this structure. The driver fills
2357 * the rest of the structure.
2359 static int atomisp_queryctl(struct file *file, void *fh,
2360 struct v4l2_queryctrl *qc)
2362 int i, ret = -EINVAL;
2363 struct video_device *vdev = video_devdata(file);
2364 struct atomisp_sub_device *asd = atomisp_to_video_pipe(vdev)->asd;
2365 struct atomisp_device *isp = video_get_drvdata(vdev);
2368 case V4L2_CID_FOCUS_ABSOLUTE:
2369 case V4L2_CID_FOCUS_RELATIVE:
2370 case V4L2_CID_FOCUS_STATUS:
2372 return v4l2_queryctrl(isp->inputs[asd->input_curr].camera->
2376 return v4l2_queryctrl(isp->motor->ctrl_handler, qc);
2378 return v4l2_queryctrl(isp->inputs[asd->input_curr].
2379 camera->ctrl_handler, qc);
2383 if (qc->id & V4L2_CTRL_FLAG_NEXT_CTRL)
2386 for (i = 0; i < ctrls_num; i++) {
2387 if (ci_v4l2_controls[i].id == qc->id) {
2388 memcpy(qc, &ci_v4l2_controls[i],
2389 sizeof(struct v4l2_queryctrl));
2390 qc->reserved[0] = 0;
2396 qc->flags = V4L2_CTRL_FLAG_DISABLED;
2401 static int atomisp_camera_g_ext_ctrls(struct file *file, void *fh,
2402 struct v4l2_ext_controls *c)
2404 struct video_device *vdev = video_devdata(file);
2405 struct atomisp_sub_device *asd = atomisp_to_video_pipe(vdev)->asd;
2406 struct atomisp_device *isp = video_get_drvdata(vdev);
2407 struct v4l2_control ctrl;
2411 for (i = 0; i < c->count; i++) {
2412 ctrl.id = c->controls[i].id;
2413 ctrl.value = c->controls[i].value;
2415 case V4L2_CID_EXPOSURE_ABSOLUTE:
2416 case V4L2_CID_EXPOSURE_AUTO:
2417 case V4L2_CID_IRIS_ABSOLUTE:
2418 case V4L2_CID_FNUMBER_ABSOLUTE:
2419 case V4L2_CID_BIN_FACTOR_HORZ:
2420 case V4L2_CID_BIN_FACTOR_VERT:
2421 case V4L2_CID_3A_LOCK:
2422 case V4L2_CID_TEST_PATTERN:
2423 case V4L2_CID_TEST_PATTERN_COLOR_R:
2424 case V4L2_CID_TEST_PATTERN_COLOR_GR:
2425 case V4L2_CID_TEST_PATTERN_COLOR_GB:
2426 case V4L2_CID_TEST_PATTERN_COLOR_B:
2428 * Exposure related control will be handled by sensor
2432 v4l2_g_ctrl(isp->inputs[asd->input_curr].camera->
2433 ctrl_handler, &ctrl);
2435 case V4L2_CID_FOCUS_ABSOLUTE:
2436 case V4L2_CID_FOCUS_RELATIVE:
2437 case V4L2_CID_FOCUS_STATUS:
2438 case V4L2_CID_FOCUS_AUTO:
2440 if (isp->inputs[asd->input_curr].motor)
2446 v4l2_g_ctrl(isp->inputs[asd->input_curr].
2447 motor->ctrl_handler, &ctrl);
2449 v4l2_g_ctrl(isp->motor->ctrl_handler,
2454 v4l2_g_ctrl(isp->inputs[asd->input_curr].
2455 camera->ctrl_handler, &ctrl);
2457 case V4L2_CID_FLASH_STATUS:
2458 case V4L2_CID_FLASH_INTENSITY:
2459 case V4L2_CID_FLASH_TORCH_INTENSITY:
2460 case V4L2_CID_FLASH_INDICATOR_INTENSITY:
2461 case V4L2_CID_FLASH_TIMEOUT:
2462 case V4L2_CID_FLASH_STROBE:
2463 case V4L2_CID_FLASH_MODE:
2464 case V4L2_CID_FLASH_STATUS_REGISTER:
2467 v4l2_g_ctrl(isp->flash->ctrl_handler,
2470 case V4L2_CID_ZOOM_ABSOLUTE:
2471 rt_mutex_lock(&isp->mutex);
2472 ret = atomisp_digital_zoom(asd, 0, &ctrl.value);
2473 rt_mutex_unlock(&isp->mutex);
2475 case V4L2_CID_G_SKIP_FRAMES:
2476 ret = v4l2_subdev_call(
2477 isp->inputs[asd->input_curr].camera,
2478 sensor, g_skip_frames, (u32 *)&ctrl.value);
2488 c->controls[i].value = ctrl.value;
2493 /* This ioctl allows the application to get multiple controls by class */
2494 static int atomisp_g_ext_ctrls(struct file *file, void *fh,
2495 struct v4l2_ext_controls *c)
2497 struct v4l2_control ctrl;
2500 /* input_lock is not need for the Camera releated IOCTLs
2501 * The input_lock downgrade the FPS of 3A*/
2502 ret = atomisp_camera_g_ext_ctrls(file, fh, c);
2506 for (i = 0; i < c->count; i++) {
2507 ctrl.id = c->controls[i].id;
2508 ctrl.value = c->controls[i].value;
2509 ret = atomisp_g_ctrl(file, fh, &ctrl);
2510 c->controls[i].value = ctrl.value;
2519 static int atomisp_camera_s_ext_ctrls(struct file *file, void *fh,
2520 struct v4l2_ext_controls *c)
2522 struct video_device *vdev = video_devdata(file);
2523 struct atomisp_sub_device *asd = atomisp_to_video_pipe(vdev)->asd;
2524 struct atomisp_device *isp = video_get_drvdata(vdev);
2525 struct v4l2_control ctrl;
2529 for (i = 0; i < c->count; i++) {
2530 struct v4l2_ctrl *ctr;
2532 ctrl.id = c->controls[i].id;
2533 ctrl.value = c->controls[i].value;
2535 case V4L2_CID_EXPOSURE_ABSOLUTE:
2536 case V4L2_CID_EXPOSURE_AUTO:
2537 case V4L2_CID_EXPOSURE_METERING:
2538 case V4L2_CID_IRIS_ABSOLUTE:
2539 case V4L2_CID_FNUMBER_ABSOLUTE:
2540 case V4L2_CID_VCM_TIMEING:
2541 case V4L2_CID_VCM_SLEW:
2542 case V4L2_CID_3A_LOCK:
2543 case V4L2_CID_TEST_PATTERN:
2544 case V4L2_CID_TEST_PATTERN_COLOR_R:
2545 case V4L2_CID_TEST_PATTERN_COLOR_GR:
2546 case V4L2_CID_TEST_PATTERN_COLOR_GB:
2547 case V4L2_CID_TEST_PATTERN_COLOR_B:
2548 ret = v4l2_s_ctrl(NULL,
2549 isp->inputs[asd->input_curr].camera->
2550 ctrl_handler, &ctrl);
2552 case V4L2_CID_FOCUS_ABSOLUTE:
2553 case V4L2_CID_FOCUS_RELATIVE:
2554 case V4L2_CID_FOCUS_STATUS:
2555 case V4L2_CID_FOCUS_AUTO:
2557 if (isp->inputs[asd->input_curr].motor)
2561 ret = v4l2_s_ctrl(NULL,
2563 isp->inputs[asd->input_curr].
2564 motor->ctrl_handler, &ctrl);
2566 isp->motor->ctrl_handler,
2570 ret = v4l2_s_ctrl(NULL,
2571 isp->inputs[asd->input_curr].
2572 camera->ctrl_handler, &ctrl);
2574 case V4L2_CID_FLASH_STATUS:
2575 case V4L2_CID_FLASH_INTENSITY:
2576 case V4L2_CID_FLASH_TORCH_INTENSITY:
2577 case V4L2_CID_FLASH_INDICATOR_INTENSITY:
2578 case V4L2_CID_FLASH_TIMEOUT:
2579 case V4L2_CID_FLASH_STROBE:
2580 case V4L2_CID_FLASH_MODE:
2581 case V4L2_CID_FLASH_STATUS_REGISTER:
2582 rt_mutex_lock(&isp->mutex);
2585 v4l2_s_ctrl(NULL, isp->flash->ctrl_handler,
2587 /* When flash mode is changed we need to reset
2589 if (ctrl.id == V4L2_CID_FLASH_MODE) {
2590 asd->params.flash_state =
2592 asd->params.num_flash_frames = 0;
2595 rt_mutex_unlock(&isp->mutex);
2597 case V4L2_CID_ZOOM_ABSOLUTE:
2598 rt_mutex_lock(&isp->mutex);
2599 ret = atomisp_digital_zoom(asd, 1, &ctrl.value);
2600 rt_mutex_unlock(&isp->mutex);
2603 ctr = v4l2_ctrl_find(&asd->ctrl_handler, ctrl.id);
2605 ret = v4l2_ctrl_s_ctrl(ctr, ctrl.value);
2614 c->controls[i].value = ctrl.value;
2619 /* This ioctl allows the application to set multiple controls by class */
2620 static int atomisp_s_ext_ctrls(struct file *file, void *fh,
2621 struct v4l2_ext_controls *c)
2623 struct v4l2_control ctrl;
2626 /* input_lock is not need for the Camera releated IOCTLs
2627 * The input_lock downgrade the FPS of 3A*/
2628 ret = atomisp_camera_s_ext_ctrls(file, fh, c);
2632 for (i = 0; i < c->count; i++) {
2633 ctrl.id = c->controls[i].id;
2634 ctrl.value = c->controls[i].value;
2635 ret = atomisp_s_ctrl(file, fh, &ctrl);
2636 c->controls[i].value = ctrl.value;
2646 * vidioc_g/s_param are used to switch isp running mode
2648 static int atomisp_g_parm(struct file *file, void *fh,
2649 struct v4l2_streamparm *parm)
2651 struct video_device *vdev = video_devdata(file);
2652 struct atomisp_sub_device *asd = atomisp_to_video_pipe(vdev)->asd;
2653 struct atomisp_device *isp = video_get_drvdata(vdev);
2655 if (parm->type != V4L2_BUF_TYPE_VIDEO_CAPTURE) {
2656 dev_err(isp->dev, "unsupport v4l2 buf type\n");
2660 rt_mutex_lock(&isp->mutex);
2661 parm->parm.capture.capturemode = asd->run_mode->val;
2662 rt_mutex_unlock(&isp->mutex);
2667 static int atomisp_s_parm(struct file *file, void *fh,
2668 struct v4l2_streamparm *parm)
2670 struct video_device *vdev = video_devdata(file);
2671 struct atomisp_device *isp = video_get_drvdata(vdev);
2672 struct atomisp_sub_device *asd = atomisp_to_video_pipe(vdev)->asd;
2677 if (parm->type != V4L2_BUF_TYPE_VIDEO_CAPTURE) {
2678 dev_err(isp->dev, "unsupport v4l2 buf type\n");
2682 rt_mutex_lock(&isp->mutex);
2684 asd->high_speed_mode = false;
2685 switch (parm->parm.capture.capturemode) {
2686 case CI_MODE_NONE: {
2687 struct v4l2_subdev_frame_interval fi = {0};
2689 fi.interval = parm->parm.capture.timeperframe;
2691 rval = v4l2_subdev_call(isp->inputs[asd->input_curr].camera,
2692 video, s_frame_interval, &fi);
2694 parm->parm.capture.timeperframe = fi.interval;
2696 if (fi.interval.numerator != 0) {
2697 fps = fi.interval.denominator / fi.interval.numerator;
2699 asd->high_speed_mode = true;
2705 mode = ATOMISP_RUN_MODE_VIDEO;
2707 case CI_MODE_STILL_CAPTURE:
2708 mode = ATOMISP_RUN_MODE_STILL_CAPTURE;
2710 case CI_MODE_CONTINUOUS:
2711 mode = ATOMISP_RUN_MODE_CONTINUOUS_CAPTURE;
2713 case CI_MODE_PREVIEW:
2714 mode = ATOMISP_RUN_MODE_PREVIEW;
2721 rval = v4l2_ctrl_s_ctrl(asd->run_mode, mode);
2724 rt_mutex_unlock(&isp->mutex);
2726 return rval == -ENOIOCTLCMD ? 0 : rval;
2729 static int atomisp_s_parm_file(struct file *file, void *fh,
2730 struct v4l2_streamparm *parm)
2732 struct video_device *vdev = video_devdata(file);
2733 struct atomisp_device *isp = video_get_drvdata(vdev);
2735 if (parm->type != V4L2_BUF_TYPE_VIDEO_OUTPUT) {
2736 dev_err(isp->dev, "unsupport v4l2 buf type for output\n");
2740 rt_mutex_lock(&isp->mutex);
2741 isp->sw_contex.file_input = 1;
2742 rt_mutex_unlock(&isp->mutex);
2747 static long atomisp_vidioc_default(struct file *file, void *fh,
2748 bool valid_prio, unsigned int cmd, void *arg)
2750 struct video_device *vdev = video_devdata(file);
2751 struct atomisp_device *isp = video_get_drvdata(vdev);
2752 struct atomisp_sub_device *asd;
2756 acc_node = !strncmp(vdev->name, "ATOMISP ISP ACC",
2757 sizeof(vdev->name));
2759 asd = atomisp_to_acc_pipe(vdev)->asd;
2761 asd = atomisp_to_video_pipe(vdev)->asd;
2764 case ATOMISP_IOC_G_MOTOR_PRIV_INT_DATA:
2765 case ATOMISP_IOC_S_EXPOSURE:
2766 case ATOMISP_IOC_G_SENSOR_CALIBRATION_GROUP:
2767 case ATOMISP_IOC_G_SENSOR_PRIV_INT_DATA:
2768 case ATOMISP_IOC_EXT_ISP_CTRL:
2769 case ATOMISP_IOC_G_SENSOR_AE_BRACKETING_INFO:
2770 case ATOMISP_IOC_S_SENSOR_AE_BRACKETING_MODE:
2771 case ATOMISP_IOC_G_SENSOR_AE_BRACKETING_MODE:
2772 case ATOMISP_IOC_S_SENSOR_AE_BRACKETING_LUT:
2773 case ATOMISP_IOC_S_SENSOR_EE_CONFIG:
2775 case ATOMISP_IOC_G_UPDATE_EXPOSURE:
2777 /* we do not need take isp->mutex for these IOCTLs */
2780 rt_mutex_lock(&isp->mutex);
2785 case ATOMISP_IOC_S_SENSOR_RUNMODE:
2786 err = atomisp_set_sensor_runmode(asd, arg);
2790 case ATOMISP_IOC_G_XNR:
2791 err = atomisp_xnr(asd, 0, arg);
2794 case ATOMISP_IOC_S_XNR:
2795 err = atomisp_xnr(asd, 1, arg);
2798 case ATOMISP_IOC_G_NR:
2799 err = atomisp_nr(asd, 0, arg);
2802 case ATOMISP_IOC_S_NR:
2803 err = atomisp_nr(asd, 1, arg);
2806 case ATOMISP_IOC_G_TNR:
2807 err = atomisp_tnr(asd, 0, arg);
2810 case ATOMISP_IOC_S_TNR:
2811 err = atomisp_tnr(asd, 1, arg);
2814 case ATOMISP_IOC_G_BLACK_LEVEL_COMP:
2815 err = atomisp_black_level(asd, 0, arg);
2818 case ATOMISP_IOC_S_BLACK_LEVEL_COMP:
2819 err = atomisp_black_level(asd, 1, arg);
2822 case ATOMISP_IOC_G_EE:
2823 err = atomisp_ee(asd, 0, arg);
2826 case ATOMISP_IOC_S_EE:
2827 err = atomisp_ee(asd, 1, arg);
2830 case ATOMISP_IOC_G_DIS_STAT:
2831 err = atomisp_get_dis_stat(asd, arg);
2834 case ATOMISP_IOC_G_DVS2_BQ_RESOLUTIONS:
2835 err = atomisp_get_dvs2_bq_resolutions(asd, arg);
2838 case ATOMISP_IOC_S_DIS_COEFS:
2839 err = atomisp_css_cp_dvs2_coefs(asd, arg,
2840 &asd->params.css_param, true);
2842 asd->params.css_update_params_needed = true;
2845 case ATOMISP_IOC_S_DIS_VECTOR:
2846 err = atomisp_cp_dvs_6axis_config(asd, arg,
2847 &asd->params.css_param, true);
2849 asd->params.css_update_params_needed = true;
2852 case ATOMISP_IOC_G_ISP_PARM:
2853 err = atomisp_param(asd, 0, arg);
2856 case ATOMISP_IOC_S_ISP_PARM:
2857 err = atomisp_param(asd, 1, arg);
2860 case ATOMISP_IOC_G_3A_STAT:
2861 err = atomisp_3a_stat(asd, 0, arg);
2864 case ATOMISP_IOC_G_ISP_GAMMA:
2865 err = atomisp_gamma(asd, 0, arg);
2868 case ATOMISP_IOC_S_ISP_GAMMA:
2869 err = atomisp_gamma(asd, 1, arg);
2872 case ATOMISP_IOC_G_ISP_GDC_TAB:
2873 err = atomisp_gdc_cac_table(asd, 0, arg);
2876 case ATOMISP_IOC_S_ISP_GDC_TAB:
2877 err = atomisp_gdc_cac_table(asd, 1, arg);
2880 case ATOMISP_IOC_G_ISP_MACC:
2881 err = atomisp_macc_table(asd, 0, arg);
2884 case ATOMISP_IOC_S_ISP_MACC:
2885 err = atomisp_macc_table(asd, 1, arg);
2888 case ATOMISP_IOC_G_ISP_BAD_PIXEL_DETECTION:
2889 err = atomisp_bad_pixel_param(asd, 0, arg);
2892 case ATOMISP_IOC_S_ISP_BAD_PIXEL_DETECTION:
2893 err = atomisp_bad_pixel_param(asd, 1, arg);
2896 case ATOMISP_IOC_G_ISP_FALSE_COLOR_CORRECTION:
2897 err = atomisp_false_color_param(asd, 0, arg);
2900 case ATOMISP_IOC_S_ISP_FALSE_COLOR_CORRECTION:
2901 err = atomisp_false_color_param(asd, 1, arg);
2904 case ATOMISP_IOC_G_ISP_CTC:
2905 err = atomisp_ctc(asd, 0, arg);
2908 case ATOMISP_IOC_S_ISP_CTC:
2909 err = atomisp_ctc(asd, 1, arg);
2912 case ATOMISP_IOC_G_ISP_WHITE_BALANCE:
2913 err = atomisp_white_balance_param(asd, 0, arg);
2916 case ATOMISP_IOC_S_ISP_WHITE_BALANCE:
2917 err = atomisp_white_balance_param(asd, 1, arg);
2920 case ATOMISP_IOC_G_3A_CONFIG:
2921 err = atomisp_3a_config_param(asd, 0, arg);
2924 case ATOMISP_IOC_S_3A_CONFIG:
2925 err = atomisp_3a_config_param(asd, 1, arg);
2928 case ATOMISP_IOC_S_ISP_FPN_TABLE:
2929 err = atomisp_fixed_pattern_table(asd, arg);
2932 case ATOMISP_IOC_ISP_MAKERNOTE:
2933 err = atomisp_exif_makernote(asd, arg);
2936 case ATOMISP_IOC_G_SENSOR_MODE_DATA:
2937 err = atomisp_get_sensor_mode_data(asd, arg);
2940 case ATOMISP_IOC_G_MOTOR_PRIV_INT_DATA:
2942 if (isp->inputs[asd->input_curr].motor)
2946 err = v4l2_subdev_call(
2948 isp->inputs[asd->input_curr].motor,
2952 core, ioctl, cmd, arg);
2954 err = v4l2_subdev_call(
2955 isp->inputs[asd->input_curr].camera,
2956 core, ioctl, cmd, arg);
2959 case ATOMISP_IOC_S_EXPOSURE:
2960 case ATOMISP_IOC_G_SENSOR_CALIBRATION_GROUP:
2961 case ATOMISP_IOC_G_SENSOR_PRIV_INT_DATA:
2962 case ATOMISP_IOC_G_SENSOR_AE_BRACKETING_INFO:
2963 case ATOMISP_IOC_S_SENSOR_AE_BRACKETING_MODE:
2964 case ATOMISP_IOC_G_SENSOR_AE_BRACKETING_MODE:
2965 case ATOMISP_IOC_S_SENSOR_AE_BRACKETING_LUT:
2967 case ATOMISP_IOC_G_UPDATE_EXPOSURE:
2969 err = v4l2_subdev_call(isp->inputs[asd->input_curr].camera,
2970 core, ioctl, cmd, arg);
2973 case ATOMISP_IOC_ACC_LOAD:
2974 err = atomisp_acc_load(asd, arg);
2977 case ATOMISP_IOC_ACC_LOAD_TO_PIPE:
2978 err = atomisp_acc_load_to_pipe(asd, arg);
2981 case ATOMISP_IOC_ACC_UNLOAD:
2982 err = atomisp_acc_unload(asd, arg);
2985 case ATOMISP_IOC_ACC_START:
2986 err = atomisp_acc_start(asd, arg);
2989 case ATOMISP_IOC_ACC_WAIT:
2990 err = atomisp_acc_wait(asd, arg);
2993 case ATOMISP_IOC_ACC_MAP:
2994 err = atomisp_acc_map(asd, arg);
2997 case ATOMISP_IOC_ACC_UNMAP:
2998 err = atomisp_acc_unmap(asd, arg);
3001 case ATOMISP_IOC_ACC_S_MAPPED_ARG:
3002 err = atomisp_acc_s_mapped_arg(asd, arg);
3005 case ATOMISP_IOC_S_ISP_SHD_TAB:
3006 err = atomisp_set_shading_table(asd, arg);
3009 case ATOMISP_IOC_G_ISP_GAMMA_CORRECTION:
3010 err = atomisp_gamma_correction(asd, 0, arg);
3013 case ATOMISP_IOC_S_ISP_GAMMA_CORRECTION:
3014 err = atomisp_gamma_correction(asd, 1, arg);
3017 case ATOMISP_IOC_S_PARAMETERS:
3018 err = atomisp_set_parameters(vdev, arg);
3021 case ATOMISP_IOC_S_CONT_CAPTURE_CONFIG:
3022 err = atomisp_offline_capture_configure(asd, arg);
3024 case ATOMISP_IOC_G_METADATA:
3025 err = atomisp_get_metadata(asd, 0, arg);
3027 case ATOMISP_IOC_G_METADATA_BY_TYPE:
3028 err = atomisp_get_metadata_by_type(asd, 0, arg);
3030 case ATOMISP_IOC_EXT_ISP_CTRL:
3031 err = v4l2_subdev_call(isp->inputs[asd->input_curr].camera,
3032 core, ioctl, cmd, arg);
3034 case ATOMISP_IOC_EXP_ID_UNLOCK:
3035 err = atomisp_exp_id_unlock(asd, arg);
3037 case ATOMISP_IOC_EXP_ID_CAPTURE:
3038 err = atomisp_exp_id_capture(asd, arg);
3040 case ATOMISP_IOC_S_ENABLE_DZ_CAPT_PIPE:
3041 err = atomisp_enable_dz_capt_pipe(asd, arg);
3043 case ATOMISP_IOC_G_FORMATS_CONFIG:
3044 err = atomisp_formats(asd, 0, arg);
3047 case ATOMISP_IOC_S_FORMATS_CONFIG:
3048 err = atomisp_formats(asd, 1, arg);
3050 case ATOMISP_IOC_S_EXPOSURE_WINDOW:
3051 err = atomisp_s_ae_window(asd, arg);
3053 case ATOMISP_IOC_S_ACC_STATE:
3054 err = atomisp_acc_set_state(asd, arg);
3056 case ATOMISP_IOC_G_ACC_STATE:
3057 err = atomisp_acc_get_state(asd, arg);
3059 case ATOMISP_IOC_INJECT_A_FAKE_EVENT:
3060 err = atomisp_inject_a_fake_event(asd, arg);
3062 case ATOMISP_IOC_G_INVALID_FRAME_NUM:
3063 err = atomisp_get_invalid_frame_num(vdev, arg);
3065 case ATOMISP_IOC_S_ARRAY_RESOLUTION:
3066 err = atomisp_set_array_res(asd, arg);
3074 case ATOMISP_IOC_G_MOTOR_PRIV_INT_DATA:
3075 case ATOMISP_IOC_S_EXPOSURE:
3076 case ATOMISP_IOC_G_SENSOR_CALIBRATION_GROUP:
3077 case ATOMISP_IOC_G_SENSOR_PRIV_INT_DATA:
3078 case ATOMISP_IOC_EXT_ISP_CTRL:
3079 case ATOMISP_IOC_G_SENSOR_AE_BRACKETING_INFO:
3080 case ATOMISP_IOC_S_SENSOR_AE_BRACKETING_MODE:
3081 case ATOMISP_IOC_G_SENSOR_AE_BRACKETING_MODE:
3082 case ATOMISP_IOC_S_SENSOR_AE_BRACKETING_LUT:
3084 case ATOMISP_IOC_G_UPDATE_EXPOSURE:
3088 rt_mutex_unlock(&isp->mutex);
3094 const struct v4l2_ioctl_ops atomisp_ioctl_ops = {
3095 .vidioc_querycap = atomisp_querycap,
3096 .vidioc_enum_input = atomisp_enum_input,
3097 .vidioc_g_input = atomisp_g_input,
3098 .vidioc_s_input = atomisp_s_input,
3099 .vidioc_queryctrl = atomisp_queryctl,
3100 .vidioc_s_ctrl = atomisp_s_ctrl,
3101 .vidioc_g_ctrl = atomisp_g_ctrl,
3102 .vidioc_s_ext_ctrls = atomisp_s_ext_ctrls,
3103 .vidioc_g_ext_ctrls = atomisp_g_ext_ctrls,
3104 .vidioc_enum_fmt_vid_cap = atomisp_enum_fmt_cap,
3105 .vidioc_try_fmt_vid_cap = atomisp_try_fmt_cap,
3106 .vidioc_g_fmt_vid_cap = atomisp_g_fmt_cap,
3107 .vidioc_s_fmt_vid_cap = atomisp_s_fmt_cap,
3108 .vidioc_reqbufs = atomisp_reqbufs,
3109 .vidioc_querybuf = atomisp_querybuf,
3110 .vidioc_qbuf = atomisp_qbuf,
3111 .vidioc_dqbuf = atomisp_dqbuf,
3112 .vidioc_streamon = atomisp_streamon,
3113 .vidioc_streamoff = atomisp_streamoff,
3114 .vidioc_default = atomisp_vidioc_default,
3115 .vidioc_s_parm = atomisp_s_parm,
3116 .vidioc_g_parm = atomisp_g_parm,
3119 const struct v4l2_ioctl_ops atomisp_file_ioctl_ops = {
3120 .vidioc_querycap = atomisp_querycap,
3121 .vidioc_g_fmt_vid_out = atomisp_g_fmt_file,
3122 .vidioc_s_fmt_vid_out = atomisp_s_fmt_file,
3123 .vidioc_s_parm = atomisp_s_parm_file,
3124 .vidioc_reqbufs = atomisp_reqbufs_file,
3125 .vidioc_querybuf = atomisp_querybuf_file,
3126 .vidioc_qbuf = atomisp_qbuf_file,