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.
20 #include <linux/delay.h>
21 #include <linux/pci.h>
23 #include <media/v4l2-ioctl.h>
24 #include <media/v4l2-event.h>
25 #include <media/videobuf-vmalloc.h>
27 #include "atomisp_acc.h"
28 #include "atomisp_cmd.h"
29 #include "atomisp_common.h"
30 #include "atomisp_fops.h"
31 #include "atomisp_internal.h"
32 #include "atomisp_ioctl.h"
33 #include "atomisp-regs.h"
34 #include "atomisp_compat.h"
36 #include "sh_css_hrt.h"
38 #include "gp_device.h"
39 #include "device_access.h"
42 #include "hrt/hive_isp_css_mm_hrt.h"
44 static const char *DRIVER = "atomisp"; /* max size 15 */
45 static const char *CARD = "ATOM ISP"; /* max size 31 */
48 * FIXME: ISP should not know beforehand all CIDs supported by sensor.
49 * Instead, it needs to propagate to sensor unkonwn CIDs.
51 static struct v4l2_queryctrl ci_v4l2_controls[] = {
53 .id = V4L2_CID_AUTO_WHITE_BALANCE,
54 .type = V4L2_CTRL_TYPE_BOOLEAN,
55 .name = "Automatic White Balance",
62 .id = V4L2_CID_RED_BALANCE,
63 .type = V4L2_CTRL_TYPE_INTEGER,
64 .name = "Red Balance",
68 .default_value = 0x00,
71 .id = V4L2_CID_BLUE_BALANCE,
72 .type = V4L2_CTRL_TYPE_INTEGER,
73 .name = "Blue Balance",
77 .default_value = 0x00,
81 .type = V4L2_CTRL_TYPE_INTEGER,
86 .default_value = 0x00,
89 .id = V4L2_CID_POWER_LINE_FREQUENCY,
90 .type = V4L2_CTRL_TYPE_MENU,
91 .name = "Light frequency filter",
98 .id = V4L2_CID_COLORFX,
99 .type = V4L2_CTRL_TYPE_INTEGER,
100 .name = "Image Color Effect",
107 .id = V4L2_CID_COLORFX_CBCR,
108 .type = V4L2_CTRL_TYPE_INTEGER,
109 .name = "Image Color Effect CbCr",
116 .id = V4L2_CID_ATOMISP_BAD_PIXEL_DETECTION,
117 .type = V4L2_CTRL_TYPE_INTEGER,
118 .name = "Bad Pixel Correction",
125 .id = V4L2_CID_ATOMISP_POSTPROCESS_GDC_CAC,
126 .type = V4L2_CTRL_TYPE_INTEGER,
134 .id = V4L2_CID_ATOMISP_VIDEO_STABLIZATION,
135 .type = V4L2_CTRL_TYPE_INTEGER,
136 .name = "Video Stablization",
143 .id = V4L2_CID_ATOMISP_FIXED_PATTERN_NR,
144 .type = V4L2_CTRL_TYPE_INTEGER,
145 .name = "Fixed Pattern Noise Reduction",
152 .id = V4L2_CID_ATOMISP_FALSE_COLOR_CORRECTION,
153 .type = V4L2_CTRL_TYPE_INTEGER,
154 .name = "False Color Correction",
161 .id = V4L2_CID_REQUEST_FLASH,
162 .type = V4L2_CTRL_TYPE_INTEGER,
163 .name = "Request flash frames",
170 .id = V4L2_CID_ATOMISP_LOW_LIGHT,
171 .type = V4L2_CTRL_TYPE_BOOLEAN,
172 .name = "Low light mode",
179 .id = V4L2_CID_BIN_FACTOR_HORZ,
180 .type = V4L2_CTRL_TYPE_INTEGER,
181 .name = "Horizontal binning factor",
188 .id = V4L2_CID_BIN_FACTOR_VERT,
189 .type = V4L2_CTRL_TYPE_INTEGER,
190 .name = "Vertical binning factor",
197 .id = V4L2_CID_2A_STATUS,
198 .type = V4L2_CTRL_TYPE_BITMASK,
199 .name = "AE and AWB status",
201 .maximum = V4L2_2A_STATUS_AE_READY | V4L2_2A_STATUS_AWB_READY,
206 .id = V4L2_CID_EXPOSURE,
207 .type = V4L2_CTRL_TYPE_INTEGER,
215 .id = V4L2_CID_EXPOSURE_ZONE_NUM,
216 .type = V4L2_CTRL_TYPE_INTEGER,
217 .name = "one-time exposure zone number",
224 .id = V4L2_CID_EXPOSURE_AUTO_PRIORITY,
225 .type = V4L2_CTRL_TYPE_INTEGER,
226 .name = "Exposure auto priority",
227 .minimum = V4L2_EXPOSURE_AUTO,
228 .maximum = V4L2_EXPOSURE_APERTURE_PRIORITY,
230 .default_value = V4L2_EXPOSURE_AUTO,
233 .id = V4L2_CID_SCENE_MODE,
234 .type = V4L2_CTRL_TYPE_INTEGER,
235 .name = "scene mode",
242 .id = V4L2_CID_ISO_SENSITIVITY,
243 .type = V4L2_CTRL_TYPE_INTEGER,
251 .id = V4L2_CID_ISO_SENSITIVITY_AUTO,
252 .type = V4L2_CTRL_TYPE_INTEGER,
254 .minimum = V4L2_ISO_SENSITIVITY_MANUAL,
255 .maximum = V4L2_ISO_SENSITIVITY_AUTO,
257 .default_value = V4L2_ISO_SENSITIVITY_AUTO,
260 .id = V4L2_CID_AUTO_N_PRESET_WHITE_BALANCE,
261 .type = V4L2_CTRL_TYPE_INTEGER,
262 .name = "white balance",
269 .id = V4L2_CID_EXPOSURE_METERING,
270 .type = V4L2_CTRL_TYPE_MENU,
278 .id = V4L2_CID_3A_LOCK,
279 .type = V4L2_CTRL_TYPE_BITMASK,
282 .maximum = V4L2_LOCK_EXPOSURE | V4L2_LOCK_WHITE_BALANCE
288 .id = V4L2_CID_TEST_PATTERN,
289 .type = V4L2_CTRL_TYPE_INTEGER,
290 .name = "Test Pattern",
297 .id = V4L2_CID_TEST_PATTERN_COLOR_R,
298 .type = V4L2_CTRL_TYPE_INTEGER,
299 .name = "Test Pattern Solid Color R",
306 .id = V4L2_CID_TEST_PATTERN_COLOR_GR,
307 .type = V4L2_CTRL_TYPE_INTEGER,
308 .name = "Test Pattern Solid Color GR",
315 .id = V4L2_CID_TEST_PATTERN_COLOR_GB,
316 .type = V4L2_CTRL_TYPE_INTEGER,
317 .name = "Test Pattern Solid Color GB",
324 .id = V4L2_CID_TEST_PATTERN_COLOR_B,
325 .type = V4L2_CTRL_TYPE_INTEGER,
326 .name = "Test Pattern Solid Color B",
334 static const u32 ctrls_num = ARRAY_SIZE(ci_v4l2_controls);
337 * supported V4L2 fmts and resolutions
339 const struct atomisp_format_bridge atomisp_output_fmts[] = {
341 .pixelformat = V4L2_PIX_FMT_YUV420,
343 .mbus_code = V4L2_MBUS_FMT_CUSTOM_YUV420,
344 .sh_fmt = IA_CSS_FRAME_FORMAT_YUV420,
345 .description = "YUV420, planar",
348 .pixelformat = V4L2_PIX_FMT_YVU420,
350 .mbus_code = V4L2_MBUS_FMT_CUSTOM_YVU420,
351 .sh_fmt = IA_CSS_FRAME_FORMAT_YV12,
352 .description = "YVU420, planar",
355 .pixelformat = V4L2_PIX_FMT_YUV422P,
357 .mbus_code = V4L2_MBUS_FMT_CUSTOM_YUV422P,
358 .sh_fmt = IA_CSS_FRAME_FORMAT_YUV422,
359 .description = "YUV422, planar",
362 .pixelformat = V4L2_PIX_FMT_YUV444,
364 .mbus_code = V4L2_MBUS_FMT_CUSTOM_YUV444,
365 .sh_fmt = IA_CSS_FRAME_FORMAT_YUV444,
366 .description = "YUV444"
368 .pixelformat = V4L2_PIX_FMT_NV12,
370 .mbus_code = V4L2_MBUS_FMT_CUSTOM_NV12,
371 .sh_fmt = IA_CSS_FRAME_FORMAT_NV12,
372 .description = "NV12, Y-plane, CbCr interleaved",
375 .pixelformat = V4L2_PIX_FMT_NV21,
377 .mbus_code = V4L2_MBUS_FMT_CUSTOM_NV21,
378 .sh_fmt = IA_CSS_FRAME_FORMAT_NV21,
379 .description = "NV21, Y-plane, CbCr interleaved",
382 .pixelformat = V4L2_PIX_FMT_NV16,
384 .mbus_code = V4L2_MBUS_FMT_CUSTOM_NV16,
385 .sh_fmt = IA_CSS_FRAME_FORMAT_NV16,
386 .description = "NV16, Y-plane, CbCr interleaved",
389 .pixelformat = V4L2_PIX_FMT_YUYV,
391 .mbus_code = V4L2_MBUS_FMT_CUSTOM_YUYV,
392 .sh_fmt = IA_CSS_FRAME_FORMAT_YUYV,
393 .description = "YUYV, interleaved"
395 .pixelformat = V4L2_PIX_FMT_UYVY,
397 .mbus_code = MEDIA_BUS_FMT_UYVY8_1X16,
398 .sh_fmt = IA_CSS_FRAME_FORMAT_UYVY,
399 .description = "UYVY, interleaved"
400 }, { /* This one is for parallel sensors! DO NOT USE! */
401 .pixelformat = V4L2_PIX_FMT_UYVY,
403 .mbus_code = MEDIA_BUS_FMT_UYVY8_2X8,
404 .sh_fmt = IA_CSS_FRAME_FORMAT_UYVY,
405 .description = "UYVY, interleaved"
407 .pixelformat = V4L2_PIX_FMT_SBGGR16,
409 .mbus_code = V4L2_MBUS_FMT_CUSTOM_SBGGR16,
410 .sh_fmt = IA_CSS_FRAME_FORMAT_RAW,
411 .description = "Bayer 16"
413 .pixelformat = V4L2_PIX_FMT_SBGGR8,
415 .mbus_code = MEDIA_BUS_FMT_SBGGR8_1X8,
416 .sh_fmt = IA_CSS_FRAME_FORMAT_RAW,
417 .description = "Bayer 8"
419 .pixelformat = V4L2_PIX_FMT_SGBRG8,
421 .mbus_code = MEDIA_BUS_FMT_SGBRG8_1X8,
422 .sh_fmt = IA_CSS_FRAME_FORMAT_RAW,
423 .description = "Bayer 8"
425 .pixelformat = V4L2_PIX_FMT_SGRBG8,
427 .mbus_code = MEDIA_BUS_FMT_SGRBG8_1X8,
428 .sh_fmt = IA_CSS_FRAME_FORMAT_RAW,
429 .description = "Bayer 8"
431 .pixelformat = V4L2_PIX_FMT_SRGGB8,
433 .mbus_code = MEDIA_BUS_FMT_SRGGB8_1X8,
434 .sh_fmt = IA_CSS_FRAME_FORMAT_RAW,
435 .description = "Bayer 8"
437 .pixelformat = V4L2_PIX_FMT_SBGGR10,
439 .mbus_code = MEDIA_BUS_FMT_SBGGR10_1X10,
440 .sh_fmt = IA_CSS_FRAME_FORMAT_RAW,
441 .description = "Bayer 10"
443 .pixelformat = V4L2_PIX_FMT_SGBRG10,
445 .mbus_code = MEDIA_BUS_FMT_SGBRG10_1X10,
446 .sh_fmt = IA_CSS_FRAME_FORMAT_RAW,
447 .description = "Bayer 10"
449 .pixelformat = V4L2_PIX_FMT_SGRBG10,
451 .mbus_code = MEDIA_BUS_FMT_SGRBG10_1X10,
452 .sh_fmt = IA_CSS_FRAME_FORMAT_RAW,
453 .description = "Bayer 10"
455 .pixelformat = V4L2_PIX_FMT_SRGGB10,
457 .mbus_code = MEDIA_BUS_FMT_SRGGB10_1X10,
458 .sh_fmt = IA_CSS_FRAME_FORMAT_RAW,
459 .description = "Bayer 10"
461 .pixelformat = V4L2_PIX_FMT_SBGGR12,
463 .mbus_code = MEDIA_BUS_FMT_SBGGR12_1X12,
464 .sh_fmt = IA_CSS_FRAME_FORMAT_RAW,
465 .description = "Bayer 12"
467 .pixelformat = V4L2_PIX_FMT_SGBRG12,
469 .mbus_code = MEDIA_BUS_FMT_SGBRG12_1X12,
470 .sh_fmt = IA_CSS_FRAME_FORMAT_RAW,
471 .description = "Bayer 12"
473 .pixelformat = V4L2_PIX_FMT_SGRBG12,
475 .mbus_code = MEDIA_BUS_FMT_SGRBG12_1X12,
476 .sh_fmt = IA_CSS_FRAME_FORMAT_RAW,
477 .description = "Bayer 12"
479 .pixelformat = V4L2_PIX_FMT_SRGGB12,
481 .mbus_code = MEDIA_BUS_FMT_SRGGB12_1X12,
482 .sh_fmt = IA_CSS_FRAME_FORMAT_RAW,
483 .description = "Bayer 12"
485 .pixelformat = V4L2_PIX_FMT_RGB32,
487 .mbus_code = V4L2_MBUS_FMT_CUSTOM_RGB32,
488 .sh_fmt = IA_CSS_FRAME_FORMAT_RGBA888,
489 .description = "32 RGB 8-8-8-8"
491 .pixelformat = V4L2_PIX_FMT_RGB565,
493 .mbus_code = MEDIA_BUS_FMT_BGR565_2X8_LE,
494 .sh_fmt = IA_CSS_FRAME_FORMAT_RGB565,
495 .description = "16 RGB 5-6-5"
497 .pixelformat = V4L2_PIX_FMT_JPEG,
499 .mbus_code = MEDIA_BUS_FMT_JPEG_1X8,
500 .sh_fmt = IA_CSS_FRAME_FORMAT_BINARY_8,
501 .description = "JPEG"
505 /* This is a custom format being used by M10MO to send the RAW data */
506 .pixelformat = V4L2_PIX_FMT_CUSTOM_M10MO_RAW,
508 .mbus_code = V4L2_MBUS_FMT_CUSTOM_M10MO_RAW,
509 .sh_fmt = IA_CSS_FRAME_FORMAT_BINARY_8,
510 .description = "Custom RAW for M10MO"
515 const struct atomisp_format_bridge *atomisp_get_format_bridge(
516 unsigned int pixelformat)
520 for (i = 0; i < ARRAY_SIZE(atomisp_output_fmts); i++) {
521 if (atomisp_output_fmts[i].pixelformat == pixelformat)
522 return &atomisp_output_fmts[i];
528 const struct atomisp_format_bridge *atomisp_get_format_bridge_from_mbus(
533 for (i = 0; i < ARRAY_SIZE(atomisp_output_fmts); i++) {
534 if (mbus_code == atomisp_output_fmts[i].mbus_code)
535 return &atomisp_output_fmts[i];
543 * return ISP capabilities
545 static int atomisp_querycap(struct file *file, void *fh,
546 struct v4l2_capability *cap)
548 struct video_device *vdev = video_devdata(file);
549 struct atomisp_device *isp = video_get_drvdata(vdev);
551 strscpy(cap->driver, DRIVER, sizeof(cap->driver) - 1);
552 strscpy(cap->card, CARD, sizeof(cap->card) - 1);
553 snprintf(cap->bus_info, sizeof(cap->bus_info), "PCI:%s",
554 pci_name(isp->pdev));
560 * enum input are used to check primary/secondary camera
562 static int atomisp_enum_input(struct file *file, void *fh,
563 struct v4l2_input *input)
565 struct video_device *vdev = video_devdata(file);
566 struct atomisp_device *isp = video_get_drvdata(vdev);
567 int index = input->index;
568 struct v4l2_subdev *motor;
570 if (index >= isp->input_cnt)
573 if (!isp->inputs[index].camera)
576 memset(input, 0, sizeof(struct v4l2_input));
577 strncpy(input->name, isp->inputs[index].camera->name,
578 sizeof(input->name) - 1);
581 * HACK: append actuator's name to sensor's
582 * As currently userspace can't talk directly to subdev nodes, this
583 * ioctl is the only way to enum inputs + possible external actuators
584 * for 3A tuning purpose.
586 if (!atomisp_hw_is_isp2401)
587 motor = isp->inputs[index].motor;
591 if (motor && strlen(motor->name) > 0) {
592 const int cur_len = strlen(input->name);
593 const int max_size = sizeof(input->name) - cur_len - 1;
596 input->name[cur_len] = '+';
597 strncpy(&input->name[cur_len + 1],
598 motor->name, max_size - 1);
602 input->type = V4L2_INPUT_TYPE_CAMERA;
603 input->index = index;
604 input->reserved[0] = isp->inputs[index].type;
605 input->reserved[1] = isp->inputs[index].port;
610 static unsigned int atomisp_subdev_streaming_count(
611 struct atomisp_sub_device *asd)
613 return asd->video_out_preview.capq.streaming
614 + asd->video_out_capture.capq.streaming
615 + asd->video_out_video_capture.capq.streaming
616 + asd->video_out_vf.capq.streaming
617 + asd->video_in.capq.streaming;
620 unsigned int atomisp_streaming_count(struct atomisp_device *isp)
624 for (i = 0, sum = 0; i < isp->num_of_streams; i++)
625 sum += isp->asd[i].streaming ==
626 ATOMISP_DEVICE_STREAMING_ENABLED;
631 unsigned int atomisp_is_acc_enabled(struct atomisp_device *isp)
635 for (i = 0; i < isp->num_of_streams; i++)
636 if (isp->asd[i].acc.pipeline)
643 * get input are used to get current primary/secondary camera
645 static int atomisp_g_input(struct file *file, void *fh, unsigned int *input)
647 struct video_device *vdev = video_devdata(file);
648 struct atomisp_device *isp = video_get_drvdata(vdev);
649 struct atomisp_sub_device *asd = atomisp_to_video_pipe(vdev)->asd;
651 rt_mutex_lock(&isp->mutex);
652 *input = asd->input_curr;
653 rt_mutex_unlock(&isp->mutex);
659 * set input are used to set current primary/secondary camera
661 static int atomisp_s_input(struct file *file, void *fh, unsigned int input)
663 struct video_device *vdev = video_devdata(file);
664 struct atomisp_device *isp = video_get_drvdata(vdev);
665 struct atomisp_sub_device *asd = atomisp_to_video_pipe(vdev)->asd;
666 struct v4l2_subdev *camera = NULL;
667 struct v4l2_subdev *motor;
670 rt_mutex_lock(&isp->mutex);
671 if (input >= ATOM_ISP_MAX_INPUTS || input >= isp->input_cnt) {
672 dev_dbg(isp->dev, "input_cnt: %d\n", isp->input_cnt);
678 * check whether the request camera:
680 * 2: if in use, whether it is used by other streams
682 if (isp->inputs[input].asd && isp->inputs[input].asd != asd) {
684 "%s, camera is already used by stream: %d\n", __func__,
685 isp->inputs[input].asd->index);
690 camera = isp->inputs[input].camera;
692 dev_err(isp->dev, "%s, no camera\n", __func__);
697 if (atomisp_subdev_streaming_count(asd)) {
699 "ISP is still streaming, stop first\n");
704 /* power off the current owned sensor, as it is not used this time */
705 if (isp->inputs[asd->input_curr].asd == asd &&
706 asd->input_curr != input) {
707 ret = v4l2_subdev_call(isp->inputs[asd->input_curr].camera,
711 "Failed to power-off sensor\n");
712 /* clear the asd field to show this camera is not used */
713 isp->inputs[asd->input_curr].asd = NULL;
716 /* powe on the new sensor */
717 ret = v4l2_subdev_call(isp->inputs[input].camera, core, s_power, 1);
719 dev_err(isp->dev, "Failed to power-on sensor\n");
723 * Some sensor driver resets the run mode during power-on, thus force
724 * update the run mode to sensor after power-on.
726 atomisp_update_run_mode(asd);
728 /* select operating sensor */
729 ret = v4l2_subdev_call(isp->inputs[input].camera, video, s_routing,
730 0, isp->inputs[input].sensor_index, 0);
731 if (ret && (ret != -ENOIOCTLCMD)) {
732 dev_err(isp->dev, "Failed to select sensor\n");
736 if (!atomisp_hw_is_isp2401) {
737 motor = isp->inputs[input].motor;
741 ret = v4l2_subdev_call(motor, core, s_power, 1);
744 if (!isp->sw_contex.file_input && motor)
745 ret = v4l2_subdev_call(motor, core, init, 1);
747 asd->input_curr = input;
748 /* mark this camera is used by the current stream */
749 isp->inputs[input].asd = asd;
750 rt_mutex_unlock(&isp->mutex);
755 rt_mutex_unlock(&isp->mutex);
760 static int atomisp_enum_fmt_cap(struct file *file, void *fh,
761 struct v4l2_fmtdesc *f)
763 struct video_device *vdev = video_devdata(file);
764 struct atomisp_device *isp = video_get_drvdata(vdev);
765 struct atomisp_sub_device *asd = atomisp_to_video_pipe(vdev)->asd;
766 struct v4l2_subdev_mbus_code_enum code = { 0 };
767 unsigned int i, fi = 0;
770 rt_mutex_lock(&isp->mutex);
771 rval = v4l2_subdev_call(isp->inputs[asd->input_curr].camera, pad,
772 enum_mbus_code, NULL, &code);
773 if (rval == -ENOIOCTLCMD) {
775 "enum_mbus_code pad op not supported. Please fix your sensor driver!\n");
776 // rval = v4l2_subdev_call(isp->inputs[asd->input_curr].camera,
777 // video, enum_mbus_fmt, 0, &code.code);
779 rt_mutex_unlock(&isp->mutex);
784 for (i = 0; i < ARRAY_SIZE(atomisp_output_fmts); i++) {
785 const struct atomisp_format_bridge *format =
786 &atomisp_output_fmts[i];
789 * Is the atomisp-supported format is valid for the
790 * sensor (configuration)? If not, skip it.
792 if (format->sh_fmt == IA_CSS_FRAME_FORMAT_RAW
793 && format->mbus_code != code.code)
796 /* Found a match. Now let's pick f->index'th one. */
802 strlcpy(f->description, format->description,
803 sizeof(f->description));
804 f->pixelformat = format->pixelformat;
811 static int atomisp_g_fmt_cap(struct file *file, void *fh,
812 struct v4l2_format *f)
814 struct video_device *vdev = video_devdata(file);
815 struct atomisp_device *isp = video_get_drvdata(vdev);
819 rt_mutex_lock(&isp->mutex);
820 ret = atomisp_get_fmt(vdev, f);
821 rt_mutex_unlock(&isp->mutex);
825 static int atomisp_g_fmt_file(struct file *file, void *fh,
826 struct v4l2_format *f)
828 struct video_device *vdev = video_devdata(file);
829 struct atomisp_device *isp = video_get_drvdata(vdev);
830 struct atomisp_video_pipe *pipe = atomisp_to_video_pipe(vdev);
832 rt_mutex_lock(&isp->mutex);
833 f->fmt.pix = pipe->pix;
834 rt_mutex_unlock(&isp->mutex);
839 /* This function looks up the closest available resolution. */
840 static int atomisp_try_fmt_cap(struct file *file, void *fh,
841 struct v4l2_format *f)
843 struct video_device *vdev = video_devdata(file);
844 struct atomisp_device *isp = video_get_drvdata(vdev);
847 rt_mutex_lock(&isp->mutex);
848 ret = atomisp_try_fmt(vdev, f, NULL);
849 rt_mutex_unlock(&isp->mutex);
853 static int atomisp_s_fmt_cap(struct file *file, void *fh,
854 struct v4l2_format *f)
856 struct video_device *vdev = video_devdata(file);
857 struct atomisp_device *isp = video_get_drvdata(vdev);
860 rt_mutex_lock(&isp->mutex);
861 if (isp->isp_fatal_error) {
863 rt_mutex_unlock(&isp->mutex);
866 ret = atomisp_set_fmt(vdev, f);
867 rt_mutex_unlock(&isp->mutex);
871 static int atomisp_s_fmt_file(struct file *file, void *fh,
872 struct v4l2_format *f)
874 struct video_device *vdev = video_devdata(file);
875 struct atomisp_device *isp = video_get_drvdata(vdev);
878 rt_mutex_lock(&isp->mutex);
879 ret = atomisp_set_fmt_file(vdev, f);
880 rt_mutex_unlock(&isp->mutex);
885 * Free videobuffer buffer priv data
887 void atomisp_videobuf_free_buf(struct videobuf_buffer *vb)
889 struct videobuf_vmalloc_memory *vm_mem;
895 if (vm_mem && vm_mem->vaddr) {
896 atomisp_css_frame_free(vm_mem->vaddr);
897 vm_mem->vaddr = NULL;
902 * this function is used to free video buffer queue
904 static void atomisp_videobuf_free_queue(struct videobuf_queue *q)
908 for (i = 0; i < VIDEO_MAX_FRAME; i++) {
909 atomisp_videobuf_free_buf(q->bufs[i]);
915 int atomisp_alloc_css_stat_bufs(struct atomisp_sub_device *asd,
918 struct atomisp_device *isp = asd->isp;
919 struct atomisp_s3a_buf *s3a_buf = NULL, *_s3a_buf;
920 struct atomisp_dis_buf *dis_buf = NULL, *_dis_buf;
921 struct atomisp_metadata_buf *md_buf = NULL, *_md_buf;
923 struct ia_css_dvs_grid_info *dvs_grid_info =
924 atomisp_css_get_dvs_grid_info(&asd->params.curr_grid_info);
927 if (list_empty(&asd->s3a_stats) &&
928 asd->params.curr_grid_info.s3a_grid.enable) {
929 count = ATOMISP_CSS_Q_DEPTH +
930 ATOMISP_S3A_BUF_QUEUE_DEPTH_FOR_HAL;
931 dev_dbg(isp->dev, "allocating %d 3a buffers\n", count);
933 s3a_buf = kzalloc(sizeof(struct atomisp_s3a_buf), GFP_KERNEL);
937 if (atomisp_css_allocate_stat_buffers(
938 asd, stream_id, s3a_buf, NULL, NULL)) {
943 list_add_tail(&s3a_buf->list, &asd->s3a_stats);
947 if (list_empty(&asd->dis_stats) && dvs_grid_info &&
948 dvs_grid_info->enable) {
949 count = ATOMISP_CSS_Q_DEPTH + 1;
950 dev_dbg(isp->dev, "allocating %d dis buffers\n", count);
952 dis_buf = kzalloc(sizeof(struct atomisp_dis_buf), GFP_KERNEL);
957 if (atomisp_css_allocate_stat_buffers(
958 asd, stream_id, NULL, dis_buf, NULL)) {
963 list_add_tail(&dis_buf->list, &asd->dis_stats);
967 for (i = 0; i < ATOMISP_METADATA_TYPE_NUM; i++) {
968 if (list_empty(&asd->metadata[i]) &&
969 list_empty(&asd->metadata_ready[i]) &&
970 list_empty(&asd->metadata_in_css[i])) {
971 count = ATOMISP_CSS_Q_DEPTH +
972 ATOMISP_METADATA_QUEUE_DEPTH_FOR_HAL;
973 dev_dbg(isp->dev, "allocating %d metadata buffers for type %d\n",
976 md_buf = kzalloc(sizeof(struct atomisp_metadata_buf),
981 if (atomisp_css_allocate_stat_buffers(
982 asd, stream_id, NULL, NULL, md_buf)) {
986 list_add_tail(&md_buf->list, &asd->metadata[i]);
993 dev_err(isp->dev, "failed to allocate statistics buffers\n");
995 list_for_each_entry_safe(dis_buf, _dis_buf, &asd->dis_stats, list) {
996 atomisp_css_free_dis_buffer(dis_buf);
997 list_del(&dis_buf->list);
1001 list_for_each_entry_safe(s3a_buf, _s3a_buf, &asd->s3a_stats, list) {
1002 atomisp_css_free_3a_buffer(s3a_buf);
1003 list_del(&s3a_buf->list);
1007 for (i = 0; i < ATOMISP_METADATA_TYPE_NUM; i++) {
1008 list_for_each_entry_safe(md_buf, _md_buf, &asd->metadata[i],
1010 atomisp_css_free_metadata_buffer(md_buf);
1011 list_del(&md_buf->list);
1019 * Initiate Memory Mapping or User Pointer I/O
1021 int __atomisp_reqbufs(struct file *file, void *fh,
1022 struct v4l2_requestbuffers *req)
1024 struct video_device *vdev = video_devdata(file);
1025 struct atomisp_video_pipe *pipe = atomisp_to_video_pipe(vdev);
1026 struct atomisp_sub_device *asd = pipe->asd;
1027 struct ia_css_frame_info frame_info;
1028 struct ia_css_frame *frame;
1029 struct videobuf_vmalloc_memory *vm_mem;
1030 u16 source_pad = atomisp_subdev_source_pad(vdev);
1031 u16 stream_id = atomisp_source_pad_to_stream_id(asd, source_pad);
1034 if (req->count == 0) {
1035 mutex_lock(&pipe->capq.vb_lock);
1036 if (!list_empty(&pipe->capq.stream))
1037 videobuf_queue_cancel(&pipe->capq);
1039 atomisp_videobuf_free_queue(&pipe->capq);
1040 mutex_unlock(&pipe->capq.vb_lock);
1041 /* clear request config id */
1042 memset(pipe->frame_request_config_id, 0,
1043 VIDEO_MAX_FRAME * sizeof(unsigned int));
1044 memset(pipe->frame_params, 0,
1046 sizeof(struct atomisp_css_params_with_list *));
1050 ret = videobuf_reqbufs(&pipe->capq, req);
1054 atomisp_alloc_css_stat_bufs(asd, stream_id);
1057 * for user pointer type, buffers are not really allcated here,
1058 * buffers are setup in QBUF operation through v4l2_buffer structure
1060 if (req->memory == V4L2_MEMORY_USERPTR)
1063 ret = atomisp_get_css_frame_info(asd, source_pad, &frame_info);
1068 * Allocate the real frame here for selected node using our
1069 * memory management function
1071 for (i = 0; i < req->count; i++) {
1072 if (atomisp_css_frame_allocate_from_info(&frame, &frame_info))
1074 vm_mem = pipe->capq.bufs[i]->priv;
1075 vm_mem->vaddr = frame;
1082 vm_mem = pipe->capq.bufs[i]->priv;
1083 atomisp_css_frame_free(vm_mem->vaddr);
1087 atomisp_css_frame_free(asd->vf_frame);
1092 int atomisp_reqbufs(struct file *file, void *fh,
1093 struct v4l2_requestbuffers *req)
1095 struct video_device *vdev = video_devdata(file);
1096 struct atomisp_device *isp = video_get_drvdata(vdev);
1099 rt_mutex_lock(&isp->mutex);
1100 ret = __atomisp_reqbufs(file, fh, req);
1101 rt_mutex_unlock(&isp->mutex);
1106 static int atomisp_reqbufs_file(struct file *file, void *fh,
1107 struct v4l2_requestbuffers *req)
1109 struct video_device *vdev = video_devdata(file);
1110 struct atomisp_video_pipe *pipe = atomisp_to_video_pipe(vdev);
1112 if (req->count == 0) {
1113 mutex_lock(&pipe->outq.vb_lock);
1114 atomisp_videobuf_free_queue(&pipe->outq);
1115 mutex_unlock(&pipe->outq.vb_lock);
1119 return videobuf_reqbufs(&pipe->outq, req);
1122 /* application query the status of a buffer */
1123 static int atomisp_querybuf(struct file *file, void *fh,
1124 struct v4l2_buffer *buf)
1126 struct video_device *vdev = video_devdata(file);
1127 struct atomisp_video_pipe *pipe = atomisp_to_video_pipe(vdev);
1129 return videobuf_querybuf(&pipe->capq, buf);
1132 static int atomisp_querybuf_file(struct file *file, void *fh,
1133 struct v4l2_buffer *buf)
1135 struct video_device *vdev = video_devdata(file);
1136 struct atomisp_video_pipe *pipe = atomisp_to_video_pipe(vdev);
1138 return videobuf_querybuf(&pipe->outq, buf);
1142 * Applications call the VIDIOC_QBUF ioctl to enqueue an empty (capturing) or
1143 * filled (output) buffer in the drivers incoming queue.
1145 static int atomisp_qbuf(struct file *file, void *fh, struct v4l2_buffer *buf)
1147 static const int NOFLUSH_FLAGS = V4L2_BUF_FLAG_NO_CACHE_INVALIDATE |
1148 V4L2_BUF_FLAG_NO_CACHE_CLEAN;
1149 struct video_device *vdev = video_devdata(file);
1150 struct atomisp_device *isp = video_get_drvdata(vdev);
1151 struct atomisp_video_pipe *pipe = atomisp_to_video_pipe(vdev);
1152 struct atomisp_sub_device *asd = pipe->asd;
1153 struct videobuf_buffer *vb;
1154 struct videobuf_vmalloc_memory *vm_mem;
1155 struct ia_css_frame_info frame_info;
1156 struct ia_css_frame *handle = NULL;
1161 rt_mutex_lock(&isp->mutex);
1162 if (isp->isp_fatal_error) {
1167 if (asd->streaming == ATOMISP_DEVICE_STREAMING_STOPPING) {
1168 dev_err(isp->dev, "%s: reject, as ISP at stopping.\n",
1174 if (!buf || buf->index >= VIDEO_MAX_FRAME ||
1175 !pipe->capq.bufs[buf->index]) {
1176 dev_err(isp->dev, "Invalid index for qbuf.\n");
1182 * For userptr type frame, we convert user space address to physic
1183 * address and reprograme out page table properly
1185 if (buf->memory == V4L2_MEMORY_USERPTR) {
1186 struct hrt_userbuffer_attr attributes;
1188 vb = pipe->capq.bufs[buf->index];
1196 pgnr = (length + (PAGE_SIZE - 1)) >> PAGE_SHIFT;
1198 if (vb->baddr == buf->m.userptr && vm_mem->vaddr)
1201 if (atomisp_get_css_frame_info(asd,
1202 atomisp_subdev_source_pad(vdev), &frame_info)) {
1207 attributes.pgnr = pgnr;
1208 attributes.type = HRT_USR_PTR;
1210 if (!atomisp_hw_is_isp2401) {
1211 if (buf->type == V4L2_BUF_TYPE_VIDEO_CAPTURE_ION)
1212 attributes.type = HRT_USR_ION;
1214 if (buf->type == V4L2_BUF_TYPE_VIDEO_CAPTURE_ION) {
1215 attributes.type = HRT_USR_ION;
1216 if (asd->ion_dev_fd->val != ION_FD_UNSET) {
1217 dev_dbg(isp->dev, "ION buffer queued, share_fd=%lddev_fd=%d.\n",
1218 buf->m.userptr, asd->ion_dev_fd->val);
1220 * Make sure the shared fd we just got
1221 * from user space isn't larger than
1222 * the space we have for it.
1224 if ((buf->m.userptr &
1225 (ATOMISP_ION_DEVICE_FD_MASK)) != 0) {
1227 "Error: v4l2 buffer fd:0X%0lX > 0XFFFF.\n",
1232 buf->m.userptr |= asd->ion_dev_fd->val <<
1233 ATOMISP_ION_DEVICE_FD_OFFSET;
1235 dev_err(isp->dev, "v4l2 buffer type is ION, \
1236 but no dev fd set from userspace.\n");
1243 ret = atomisp_css_frame_map(&handle, &frame_info,
1244 (void __user *)buf->m.userptr,
1247 dev_err(isp->dev, "Failed to map user buffer\n");
1251 if (vm_mem->vaddr) {
1252 mutex_lock(&pipe->capq.vb_lock);
1253 atomisp_css_frame_free(vm_mem->vaddr);
1254 vm_mem->vaddr = NULL;
1255 vb->state = VIDEOBUF_NEEDS_INIT;
1256 mutex_unlock(&pipe->capq.vb_lock);
1259 vm_mem->vaddr = handle;
1261 buf->flags &= ~V4L2_BUF_FLAG_MAPPED;
1262 buf->flags |= V4L2_BUF_FLAG_QUEUED;
1263 buf->flags &= ~V4L2_BUF_FLAG_DONE;
1264 } else if (buf->memory == V4L2_MEMORY_MMAP) {
1265 buf->flags |= V4L2_BUF_FLAG_MAPPED;
1266 buf->flags |= V4L2_BUF_FLAG_QUEUED;
1267 buf->flags &= ~V4L2_BUF_FLAG_DONE;
1271 if (!((buf->flags & NOFLUSH_FLAGS) == NOFLUSH_FLAGS))
1274 if (!atomisp_is_vf_pipe(pipe) &&
1275 (buf->reserved2 & ATOMISP_BUFFER_HAS_PER_FRAME_SETTING)) {
1276 /* this buffer will have a per-frame parameter */
1277 pipe->frame_request_config_id[buf->index] = buf->reserved2 &
1278 ~ATOMISP_BUFFER_HAS_PER_FRAME_SETTING;
1280 "This buffer requires per_frame setting which has isp_config_id %d\n",
1281 pipe->frame_request_config_id[buf->index]);
1283 pipe->frame_request_config_id[buf->index] = 0;
1286 pipe->frame_params[buf->index] = NULL;
1288 rt_mutex_unlock(&isp->mutex);
1290 ret = videobuf_qbuf(&pipe->capq, buf);
1291 rt_mutex_lock(&isp->mutex);
1295 /* TODO: do this better, not best way to queue to css */
1296 if (asd->streaming == ATOMISP_DEVICE_STREAMING_ENABLED) {
1297 if (!list_empty(&pipe->buffers_waiting_for_param)) {
1298 atomisp_handle_parameter_and_buffer(pipe);
1300 atomisp_qbuffers_to_css(asd);
1302 if (!atomisp_hw_is_isp2401) {
1303 if (!atomisp_is_wdt_running(asd) && atomisp_buffers_queued(asd))
1304 atomisp_wdt_start(asd);
1306 if (!atomisp_is_wdt_running(pipe) &&
1307 atomisp_buffers_queued_pipe(pipe))
1308 atomisp_wdt_start_pipe(pipe);
1313 /* Workaround: Due to the design of HALv3,
1314 * sometimes in ZSL or SDV mode HAL needs to
1315 * capture multiple images within one streaming cycle.
1316 * But the capture number cannot be determined by HAL.
1317 * So HAL only sets the capture number to be 1 and queue multiple
1318 * buffers. Atomisp driver needs to check this case and re-trigger
1319 * CSS to do capture when new buffer is queued. */
1320 if (asd->continuous_mode->val &&
1321 atomisp_subdev_source_pad(vdev)
1322 == ATOMISP_SUBDEV_PAD_SOURCE_CAPTURE &&
1323 pipe->capq.streaming &&
1324 !asd->enable_raw_buffer_lock->val &&
1325 asd->params.offline_parm.num_captures == 1) {
1326 if (!atomisp_hw_is_isp2401) {
1327 asd->pending_capture_request++;
1328 dev_dbg(isp->dev, "Add one pending capture request.\n");
1330 if (asd->re_trigger_capture) {
1331 ret = atomisp_css_offline_capture_configure(asd,
1332 asd->params.offline_parm.num_captures,
1333 asd->params.offline_parm.skip_frames,
1334 asd->params.offline_parm.offset);
1335 asd->re_trigger_capture = false;
1336 dev_dbg(isp->dev, "%s Trigger capture again ret=%d\n",
1340 asd->pending_capture_request++;
1341 asd->re_trigger_capture = false;
1342 dev_dbg(isp->dev, "Add one pending capture request.\n");
1346 rt_mutex_unlock(&isp->mutex);
1348 dev_dbg(isp->dev, "qbuf buffer %d (%s) for asd%d\n", buf->index,
1349 vdev->name, asd->index);
1354 rt_mutex_unlock(&isp->mutex);
1358 static int atomisp_qbuf_file(struct file *file, void *fh,
1359 struct v4l2_buffer *buf)
1361 struct video_device *vdev = video_devdata(file);
1362 struct atomisp_device *isp = video_get_drvdata(vdev);
1363 struct atomisp_video_pipe *pipe = atomisp_to_video_pipe(vdev);
1366 rt_mutex_lock(&isp->mutex);
1367 if (isp->isp_fatal_error) {
1372 if (!buf || buf->index >= VIDEO_MAX_FRAME ||
1373 !pipe->outq.bufs[buf->index]) {
1374 dev_err(isp->dev, "Invalid index for qbuf.\n");
1379 if (buf->memory != V4L2_MEMORY_MMAP) {
1380 dev_err(isp->dev, "Unsupported memory method\n");
1385 if (buf->type != V4L2_BUF_TYPE_VIDEO_OUTPUT) {
1386 dev_err(isp->dev, "Unsupported buffer type\n");
1390 rt_mutex_unlock(&isp->mutex);
1392 return videobuf_qbuf(&pipe->outq, buf);
1395 rt_mutex_unlock(&isp->mutex);
1400 static int __get_frame_exp_id(struct atomisp_video_pipe *pipe,
1401 struct v4l2_buffer *buf)
1403 struct videobuf_vmalloc_memory *vm_mem;
1404 struct ia_css_frame *handle;
1407 for (i = 0; pipe->capq.bufs[i]; i++) {
1408 vm_mem = pipe->capq.bufs[i]->priv;
1409 handle = vm_mem->vaddr;
1410 if (buf->index == pipe->capq.bufs[i]->i && handle)
1411 return handle->exp_id;
1417 * Applications call the VIDIOC_DQBUF ioctl to dequeue a filled (capturing) or
1418 * displayed (output buffer)from the driver's outgoing queue
1420 static int atomisp_dqbuf(struct file *file, void *fh, struct v4l2_buffer *buf)
1422 struct video_device *vdev = video_devdata(file);
1423 struct atomisp_video_pipe *pipe = atomisp_to_video_pipe(vdev);
1424 struct atomisp_sub_device *asd = pipe->asd;
1425 struct atomisp_device *isp = video_get_drvdata(vdev);
1428 rt_mutex_lock(&isp->mutex);
1430 if (isp->isp_fatal_error) {
1431 rt_mutex_unlock(&isp->mutex);
1435 if (asd->streaming == ATOMISP_DEVICE_STREAMING_STOPPING) {
1436 rt_mutex_unlock(&isp->mutex);
1437 dev_err(isp->dev, "%s: reject, as ISP at stopping.\n",
1442 rt_mutex_unlock(&isp->mutex);
1444 ret = videobuf_dqbuf(&pipe->capq, buf, file->f_flags & O_NONBLOCK);
1447 dev_dbg(isp->dev, "<%s: %d\n", __func__, ret);
1450 rt_mutex_lock(&isp->mutex);
1451 buf->bytesused = pipe->pix.sizeimage;
1452 buf->reserved = asd->frame_status[buf->index];
1456 * Currently frame_status in the enum type which takes no more lower
1458 * use bit[31:16] for exp_id as it is only in the range of 1~255
1460 buf->reserved &= 0x0000ffff;
1461 if (!(buf->flags & V4L2_BUF_FLAG_ERROR))
1462 buf->reserved |= __get_frame_exp_id(pipe, buf) << 16;
1463 buf->reserved2 = pipe->frame_config_id[buf->index];
1464 rt_mutex_unlock(&isp->mutex);
1467 "dqbuf buffer %d (%s) for asd%d with exp_id %d, isp_config_id %d\n",
1468 buf->index, vdev->name, asd->index, buf->reserved >> 16,
1473 enum ia_css_pipe_id atomisp_get_css_pipe_id(struct atomisp_sub_device *asd)
1475 if (ATOMISP_USE_YUVPP(asd))
1476 return IA_CSS_PIPE_ID_YUVPP;
1478 if (asd->continuous_mode->val) {
1479 if (asd->run_mode->val == ATOMISP_RUN_MODE_VIDEO)
1480 return IA_CSS_PIPE_ID_VIDEO;
1482 return IA_CSS_PIPE_ID_PREVIEW;
1486 * Disable vf_pp and run CSS in video mode. This allows using ISP
1487 * scaling but it has one frame delay due to CSS internal buffering.
1489 if (asd->vfpp->val == ATOMISP_VFPP_DISABLE_SCALER)
1490 return IA_CSS_PIPE_ID_VIDEO;
1493 * Disable vf_pp and run CSS in still capture mode. In this mode
1494 * CSS does not cause extra latency with buffering, but scaling
1497 if (asd->vfpp->val == ATOMISP_VFPP_DISABLE_LOWLAT)
1498 return IA_CSS_PIPE_ID_CAPTURE;
1500 switch (asd->run_mode->val) {
1501 case ATOMISP_RUN_MODE_PREVIEW:
1502 return IA_CSS_PIPE_ID_PREVIEW;
1503 case ATOMISP_RUN_MODE_VIDEO:
1504 return IA_CSS_PIPE_ID_VIDEO;
1505 case ATOMISP_RUN_MODE_STILL_CAPTURE:
1508 return IA_CSS_PIPE_ID_CAPTURE;
1512 static unsigned int atomisp_sensor_start_stream(struct atomisp_sub_device *asd)
1514 struct atomisp_device *isp = asd->isp;
1516 if (isp->inputs[asd->input_curr].camera_caps->
1517 sensor[asd->sensor_curr].stream_num > 1) {
1518 if (asd->high_speed_mode)
1524 if (asd->vfpp->val != ATOMISP_VFPP_ENABLE ||
1528 if (asd->run_mode->val == ATOMISP_RUN_MODE_VIDEO ||
1529 (asd->run_mode->val == ATOMISP_RUN_MODE_STILL_CAPTURE &&
1530 !atomisp_is_mbuscode_raw(
1532 asd->capture_pad].fmt.code) &&
1533 !asd->continuous_mode->val))
1539 int atomisp_stream_on_master_slave_sensor(struct atomisp_device *isp,
1542 unsigned int master = -1, slave = -1, delay_slave = 0;
1546 * ISP only support 2 streams now so ignore multiple master/slave
1547 * case to reduce the delay between 2 stream_on calls.
1549 for (i = 0; i < isp->num_of_streams; i++) {
1550 int sensor_index = isp->asd[i].input_curr;
1552 if (isp->inputs[sensor_index].camera_caps->
1553 sensor[isp->asd[i].sensor_curr].is_slave)
1554 slave = sensor_index;
1556 master = sensor_index;
1559 if (master == -1 || slave == -1) {
1560 master = ATOMISP_DEPTH_DEFAULT_MASTER_SENSOR;
1561 slave = ATOMISP_DEPTH_DEFAULT_SLAVE_SENSOR;
1563 "depth mode use default master=%s.slave=%s.\n",
1564 isp->inputs[master].camera->name,
1565 isp->inputs[slave].camera->name);
1568 ret = v4l2_subdev_call(isp->inputs[master].camera, core,
1569 ioctl, ATOMISP_IOC_G_DEPTH_SYNC_COMP,
1573 "get depth sensor %s compensation delay failed.\n",
1574 isp->inputs[master].camera->name);
1576 ret = v4l2_subdev_call(isp->inputs[master].camera,
1577 video, s_stream, 1);
1579 dev_err(isp->dev, "depth mode master sensor %s stream-on failed.\n",
1580 isp->inputs[master].camera->name);
1584 if (delay_slave != 0)
1585 udelay(delay_slave);
1587 ret = v4l2_subdev_call(isp->inputs[slave].camera,
1588 video, s_stream, 1);
1590 dev_err(isp->dev, "depth mode slave sensor %s stream-on failed.\n",
1591 isp->inputs[slave].camera->name);
1592 v4l2_subdev_call(isp->inputs[master].camera, video, s_stream, 0);
1600 /* FIXME! ISP2400 */
1601 static void __wdt_on_master_slave_sensor(struct atomisp_device *isp,
1602 unsigned int wdt_duration)
1604 if (atomisp_buffers_queued(&isp->asd[0]))
1605 atomisp_wdt_refresh(&isp->asd[0], wdt_duration);
1606 if (atomisp_buffers_queued(&isp->asd[1]))
1607 atomisp_wdt_refresh(&isp->asd[1], wdt_duration);
1610 /* FIXME! ISP2401 */
1611 static void __wdt_on_master_slave_sensor_pipe(struct atomisp_video_pipe *pipe,
1612 unsigned int wdt_duration,
1615 static struct atomisp_video_pipe *pipe0;
1618 if (atomisp_buffers_queued_pipe(pipe0))
1619 atomisp_wdt_refresh_pipe(pipe0, wdt_duration);
1620 if (atomisp_buffers_queued_pipe(pipe))
1621 atomisp_wdt_refresh_pipe(pipe, wdt_duration);
1627 static void atomisp_pause_buffer_event(struct atomisp_device *isp)
1629 struct v4l2_event event = {0};
1632 event.type = V4L2_EVENT_ATOMISP_PAUSE_BUFFER;
1634 for (i = 0; i < isp->num_of_streams; i++) {
1635 int sensor_index = isp->asd[i].input_curr;
1637 if (isp->inputs[sensor_index].camera_caps->
1638 sensor[isp->asd[i].sensor_curr].is_slave) {
1639 v4l2_event_queue(isp->asd[i].subdev.devnode, &event);
1645 /* Input system HW workaround */
1646 /* Input system address translation corrupts burst during */
1647 /* invalidate. SW workaround for this is to set burst length */
1648 /* manually to 128 in case of 13MPx snapshot and to 1 otherwise. */
1649 static void atomisp_dma_burst_len_cfg(struct atomisp_sub_device *asd)
1651 struct v4l2_mbus_framefmt *sink;
1653 sink = atomisp_subdev_get_ffmt(&asd->subdev, NULL,
1654 V4L2_SUBDEV_FORMAT_ACTIVE,
1655 ATOMISP_SUBDEV_PAD_SINK);
1657 if (sink->width * sink->height >= 4096 * 3072)
1658 atomisp_store_uint32(DMA_BURST_SIZE_REG, 0x7F);
1660 atomisp_store_uint32(DMA_BURST_SIZE_REG, 0x00);
1664 * This ioctl start the capture during streaming I/O.
1666 static int atomisp_streamon(struct file *file, void *fh,
1667 enum v4l2_buf_type type)
1669 struct video_device *vdev = video_devdata(file);
1670 struct atomisp_video_pipe *pipe = atomisp_to_video_pipe(vdev);
1671 struct atomisp_sub_device *asd = pipe->asd;
1672 struct atomisp_device *isp = video_get_drvdata(vdev);
1673 enum ia_css_pipe_id css_pipe_id;
1674 unsigned int sensor_start_stream;
1675 unsigned int wdt_duration = ATOMISP_ISP_TIMEOUT_DURATION;
1677 unsigned long irqflags;
1679 dev_dbg(isp->dev, "Start stream on pad %d for asd%d\n",
1680 atomisp_subdev_source_pad(vdev), asd->index);
1682 if (type != V4L2_BUF_TYPE_VIDEO_CAPTURE) {
1683 dev_dbg(isp->dev, "unsupported v4l2 buf type\n");
1687 rt_mutex_lock(&isp->mutex);
1688 if (isp->isp_fatal_error) {
1693 if (asd->streaming == ATOMISP_DEVICE_STREAMING_STOPPING) {
1698 if (pipe->capq.streaming)
1701 /* Input system HW workaround */
1702 atomisp_dma_burst_len_cfg(asd);
1705 * The number of streaming video nodes is based on which
1706 * binary is going to be run.
1708 sensor_start_stream = atomisp_sensor_start_stream(asd);
1710 spin_lock_irqsave(&pipe->irq_lock, irqflags);
1711 if (list_empty(&pipe->capq.stream)) {
1712 spin_unlock_irqrestore(&pipe->irq_lock, irqflags);
1713 dev_dbg(isp->dev, "no buffer in the queue\n");
1717 spin_unlock_irqrestore(&pipe->irq_lock, irqflags);
1719 ret = videobuf_streamon(&pipe->capq);
1723 /* Reset pending capture request count. */
1724 asd->pending_capture_request = 0;
1725 if (atomisp_hw_is_isp2401)
1726 asd->re_trigger_capture = false;
1728 if ((atomisp_subdev_streaming_count(asd) > sensor_start_stream) &&
1729 (!isp->inputs[asd->input_curr].camera_caps->multi_stream_ctrl)) {
1730 /* trigger still capture */
1731 if (asd->continuous_mode->val &&
1732 atomisp_subdev_source_pad(vdev)
1733 == ATOMISP_SUBDEV_PAD_SOURCE_CAPTURE) {
1734 if (asd->run_mode->val == ATOMISP_RUN_MODE_VIDEO)
1735 dev_dbg(isp->dev, "SDV last video raw buffer id: %u\n",
1736 asd->latest_preview_exp_id);
1738 dev_dbg(isp->dev, "ZSL last preview raw buffer id: %u\n",
1739 asd->latest_preview_exp_id);
1741 if (asd->delayed_init == ATOMISP_DELAYED_INIT_QUEUED) {
1742 flush_work(&asd->delayed_init_work);
1743 rt_mutex_unlock(&isp->mutex);
1744 if (wait_for_completion_interruptible(
1745 &asd->init_done) != 0)
1746 return -ERESTARTSYS;
1747 rt_mutex_lock(&isp->mutex);
1750 /* handle per_frame_setting parameter and buffers */
1751 atomisp_handle_parameter_and_buffer(pipe);
1754 * only ZSL/SDV capture request will be here, raise
1755 * the ISP freq to the highest possible to minimize
1758 atomisp_freq_scaling(isp, ATOMISP_DFS_MODE_MAX, false);
1760 * When asd->enable_raw_buffer_lock->val is true,
1761 * An extra IOCTL is needed to call
1762 * atomisp_css_exp_id_capture and trigger real capture
1764 if (!asd->enable_raw_buffer_lock->val) {
1765 ret = atomisp_css_offline_capture_configure(asd,
1766 asd->params.offline_parm.num_captures,
1767 asd->params.offline_parm.skip_frames,
1768 asd->params.offline_parm.offset);
1773 if (asd->depth_mode->val)
1774 atomisp_pause_buffer_event(isp);
1777 atomisp_qbuffers_to_css(asd);
1781 if (asd->streaming == ATOMISP_DEVICE_STREAMING_ENABLED) {
1782 atomisp_qbuffers_to_css(asd);
1786 css_pipe_id = atomisp_get_css_pipe_id(asd);
1788 ret = atomisp_acc_load_extensions(asd);
1790 dev_err(isp->dev, "acc extension failed to load\n");
1794 if (asd->params.css_update_params_needed) {
1795 atomisp_apply_css_parameters(asd, &asd->params.css_param);
1796 if (asd->params.css_param.update_flag.dz_config)
1797 atomisp_css_set_dz_config(asd,
1798 &asd->params.css_param.dz_config);
1799 atomisp_css_update_isp_params(asd);
1800 asd->params.css_update_params_needed = false;
1801 memset(&asd->params.css_param.update_flag, 0,
1802 sizeof(struct atomisp_parameters));
1804 asd->params.dvs_6axis = NULL;
1806 ret = atomisp_css_start(asd, css_pipe_id, false);
1810 asd->streaming = ATOMISP_DEVICE_STREAMING_ENABLED;
1811 atomic_set(&asd->sof_count, -1);
1812 atomic_set(&asd->sequence, -1);
1813 atomic_set(&asd->sequence_temp, -1);
1814 if (isp->sw_contex.file_input)
1815 wdt_duration = ATOMISP_ISP_FILE_TIMEOUT_DURATION;
1817 asd->params.dis_proj_data_valid = false;
1818 asd->latest_preview_exp_id = 0;
1819 asd->postview_exp_id = 1;
1820 asd->preview_exp_id = 1;
1822 /* handle per_frame_setting parameter and buffers */
1823 atomisp_handle_parameter_and_buffer(pipe);
1825 atomisp_qbuffers_to_css(asd);
1827 /* Only start sensor when the last streaming instance started */
1828 if (atomisp_subdev_streaming_count(asd) < sensor_start_stream)
1833 asd->params.num_flash_frames = 0;
1834 asd->params.flash_state = ATOMISP_FLASH_IDLE;
1835 atomisp_setup_flash(asd);
1838 if (!isp->sw_contex.file_input) {
1839 atomisp_css_irq_enable(isp, IA_CSS_IRQ_INFO_CSS_RECEIVER_SOF,
1840 atomisp_css_valid_sof(isp));
1841 atomisp_csi2_configure(asd);
1843 * set freq to max when streaming count > 1 which indicate
1844 * dual camera would run
1846 if (atomisp_streaming_count(isp) > 1) {
1847 if (atomisp_freq_scaling(isp,
1848 ATOMISP_DFS_MODE_MAX, false) < 0)
1849 dev_dbg(isp->dev, "dfs failed!\n");
1851 if (atomisp_freq_scaling(isp,
1852 ATOMISP_DFS_MODE_AUTO, false) < 0)
1853 dev_dbg(isp->dev, "dfs failed!\n");
1856 if (atomisp_freq_scaling(isp, ATOMISP_DFS_MODE_MAX, false) < 0)
1857 dev_dbg(isp->dev, "dfs failed!\n");
1860 if (asd->depth_mode->val && atomisp_streaming_count(isp) ==
1861 ATOMISP_DEPTH_SENSOR_STREAMON_COUNT) {
1862 ret = atomisp_stream_on_master_slave_sensor(isp, false);
1864 dev_err(isp->dev, "master slave sensor stream on failed!\n");
1867 if (!atomisp_hw_is_isp2401) {
1868 __wdt_on_master_slave_sensor(isp, wdt_duration);
1870 __wdt_on_master_slave_sensor_pipe(pipe, wdt_duration, true);
1872 goto start_delay_wq;
1873 } else if (asd->depth_mode->val && (atomisp_streaming_count(isp) <
1874 ATOMISP_DEPTH_SENSOR_STREAMON_COUNT)) {
1875 if (atomisp_hw_is_isp2401)
1876 __wdt_on_master_slave_sensor_pipe(pipe, wdt_duration, false);
1877 goto start_delay_wq;
1880 /* Enable the CSI interface on ANN B0/K0 */
1881 if (isp->media_dev.hw_revision >= ((ATOMISP_HW_REVISION_ISP2401 <<
1882 ATOMISP_HW_REVISION_SHIFT) | ATOMISP_HW_STEPPING_B0)) {
1883 pci_write_config_word(isp->pdev, MRFLD_PCI_CSI_CONTROL,
1884 isp->saved_regs.csi_control |
1885 MRFLD_PCI_CSI_CONTROL_CSI_READY);
1888 /* stream on the sensor */
1889 ret = v4l2_subdev_call(isp->inputs[asd->input_curr].camera,
1890 video, s_stream, 1);
1892 asd->streaming = ATOMISP_DEVICE_STREAMING_DISABLED;
1897 if (!atomisp_hw_is_isp2401) {
1898 if (atomisp_buffers_queued(asd))
1899 atomisp_wdt_refresh(asd, wdt_duration);
1901 if (atomisp_buffers_queued_pipe(pipe))
1902 atomisp_wdt_refresh_pipe(pipe, wdt_duration);
1906 if (asd->continuous_mode->val) {
1907 struct v4l2_mbus_framefmt *sink;
1909 sink = atomisp_subdev_get_ffmt(&asd->subdev, NULL,
1910 V4L2_SUBDEV_FORMAT_ACTIVE,
1911 ATOMISP_SUBDEV_PAD_SINK);
1913 reinit_completion(&asd->init_done);
1914 asd->delayed_init = ATOMISP_DELAYED_INIT_QUEUED;
1915 queue_work(asd->delayed_init_workq, &asd->delayed_init_work);
1916 atomisp_css_set_cont_prev_start_time(isp,
1917 ATOMISP_CALC_CSS_PREV_OVERLAP(sink->height));
1919 asd->delayed_init = ATOMISP_DELAYED_INIT_NOT_QUEUED;
1922 rt_mutex_unlock(&isp->mutex);
1926 int __atomisp_streamoff(struct file *file, void *fh, enum v4l2_buf_type type)
1928 struct video_device *vdev = video_devdata(file);
1929 struct atomisp_device *isp = video_get_drvdata(vdev);
1930 struct atomisp_video_pipe *pipe = atomisp_to_video_pipe(vdev);
1931 struct atomisp_sub_device *asd = pipe->asd;
1932 struct atomisp_video_pipe *capture_pipe = NULL;
1933 struct atomisp_video_pipe *vf_pipe = NULL;
1934 struct atomisp_video_pipe *preview_pipe = NULL;
1935 struct atomisp_video_pipe *video_pipe = NULL;
1936 struct videobuf_buffer *vb, *_vb;
1937 enum ia_css_pipe_id css_pipe_id;
1939 unsigned long flags;
1940 bool first_streamoff = false;
1942 dev_dbg(isp->dev, "Stop stream on pad %d for asd%d\n",
1943 atomisp_subdev_source_pad(vdev), asd->index);
1945 BUG_ON(!rt_mutex_is_locked(&isp->mutex));
1946 BUG_ON(!mutex_is_locked(&isp->streamoff_mutex));
1948 if (type != V4L2_BUF_TYPE_VIDEO_CAPTURE) {
1949 dev_dbg(isp->dev, "unsupported v4l2 buf type\n");
1954 * do only videobuf_streamoff for capture & vf pipes in
1955 * case of continuous capture
1957 if ((asd->continuous_mode->val ||
1958 isp->inputs[asd->input_curr].camera_caps->multi_stream_ctrl) &&
1959 atomisp_subdev_source_pad(vdev) !=
1960 ATOMISP_SUBDEV_PAD_SOURCE_PREVIEW &&
1961 atomisp_subdev_source_pad(vdev) !=
1962 ATOMISP_SUBDEV_PAD_SOURCE_VIDEO) {
1963 if (isp->inputs[asd->input_curr].camera_caps->multi_stream_ctrl) {
1964 v4l2_subdev_call(isp->inputs[asd->input_curr].camera,
1965 video, s_stream, 0);
1966 } else if (atomisp_subdev_source_pad(vdev)
1967 == ATOMISP_SUBDEV_PAD_SOURCE_CAPTURE) {
1968 /* stop continuous still capture if needed */
1969 if (asd->params.offline_parm.num_captures == -1)
1970 atomisp_css_offline_capture_configure(asd,
1972 atomisp_freq_scaling(isp, ATOMISP_DFS_MODE_AUTO, false);
1975 * Currently there is no way to flush buffers queued to css.
1976 * When doing videobuf_streamoff, active buffers will be
1977 * marked as VIDEOBUF_NEEDS_INIT. HAL will be able to use
1978 * these buffers again, and these buffers might be queued to
1979 * css more than once! Warn here, if HAL has not dequeued all
1980 * buffers back before calling streamoff.
1982 if (pipe->buffers_in_css != 0) {
1983 WARN(1, "%s: buffers of vdev %s still in CSS!\n",
1984 __func__, pipe->vdev.name);
1987 * Buffers remained in css maybe dequeued out in the
1988 * next stream on, while this will causes serious
1989 * issues as buffers already get invalid after
1990 * previous stream off.
1992 * No way to flush buffers but to reset the whole css
1994 dev_warn(isp->dev, "Reset CSS to clean up css buffers.\n");
1995 atomisp_css_flush(isp);
1998 return videobuf_streamoff(&pipe->capq);
2001 if (!pipe->capq.streaming)
2004 spin_lock_irqsave(&isp->lock, flags);
2005 if (asd->streaming == ATOMISP_DEVICE_STREAMING_ENABLED) {
2006 asd->streaming = ATOMISP_DEVICE_STREAMING_STOPPING;
2007 first_streamoff = true;
2009 spin_unlock_irqrestore(&isp->lock, flags);
2011 if (first_streamoff) {
2012 /* if other streams are running, should not disable watch dog */
2013 rt_mutex_unlock(&isp->mutex);
2014 atomisp_wdt_stop(asd, true);
2017 * must stop sending pixels into GP_FIFO before stop
2020 if (isp->sw_contex.file_input)
2021 v4l2_subdev_call(isp->inputs[asd->input_curr].camera,
2022 video, s_stream, 0);
2024 rt_mutex_lock(&isp->mutex);
2025 atomisp_acc_unload_extensions(asd);
2028 spin_lock_irqsave(&isp->lock, flags);
2029 if (atomisp_subdev_streaming_count(asd) == 1)
2030 asd->streaming = ATOMISP_DEVICE_STREAMING_DISABLED;
2031 spin_unlock_irqrestore(&isp->lock, flags);
2033 if (!first_streamoff) {
2034 ret = videobuf_streamoff(&pipe->capq);
2040 atomisp_clear_css_buffer_counters(asd);
2042 if (!isp->sw_contex.file_input)
2043 atomisp_css_irq_enable(isp, IA_CSS_IRQ_INFO_CSS_RECEIVER_SOF,
2046 if (asd->delayed_init == ATOMISP_DELAYED_INIT_QUEUED) {
2047 cancel_work_sync(&asd->delayed_init_work);
2048 asd->delayed_init = ATOMISP_DELAYED_INIT_NOT_QUEUED;
2050 if (first_streamoff) {
2051 css_pipe_id = atomisp_get_css_pipe_id(asd);
2052 ret = atomisp_css_stop(asd, css_pipe_id, false);
2054 /* cancel work queue*/
2055 if (asd->video_out_capture.users) {
2056 capture_pipe = &asd->video_out_capture;
2057 wake_up_interruptible(&capture_pipe->capq.wait);
2059 if (asd->video_out_vf.users) {
2060 vf_pipe = &asd->video_out_vf;
2061 wake_up_interruptible(&vf_pipe->capq.wait);
2063 if (asd->video_out_preview.users) {
2064 preview_pipe = &asd->video_out_preview;
2065 wake_up_interruptible(&preview_pipe->capq.wait);
2067 if (asd->video_out_video_capture.users) {
2068 video_pipe = &asd->video_out_video_capture;
2069 wake_up_interruptible(&video_pipe->capq.wait);
2071 ret = videobuf_streamoff(&pipe->capq);
2075 /* cleanup css here */
2076 /* no need for this, as ISP will be reset anyway */
2077 /*atomisp_flush_bufs_in_css(isp);*/
2079 spin_lock_irqsave(&pipe->irq_lock, flags);
2080 list_for_each_entry_safe(vb, _vb, &pipe->activeq, queue) {
2081 vb->state = VIDEOBUF_PREPARED;
2082 list_del(&vb->queue);
2084 list_for_each_entry_safe(vb, _vb, &pipe->buffers_waiting_for_param, queue) {
2085 vb->state = VIDEOBUF_PREPARED;
2086 list_del(&vb->queue);
2087 pipe->frame_request_config_id[vb->i] = 0;
2089 spin_unlock_irqrestore(&pipe->irq_lock, flags);
2091 atomisp_subdev_cleanup_pending_events(asd);
2093 if (atomisp_subdev_streaming_count(asd) + 1
2094 != atomisp_sensor_start_stream(asd))
2097 if (!isp->sw_contex.file_input)
2098 ret = v4l2_subdev_call(isp->inputs[asd->input_curr].camera,
2099 video, s_stream, 0);
2102 asd->params.num_flash_frames = 0;
2103 asd->params.flash_state = ATOMISP_FLASH_IDLE;
2106 /* if other streams are running, isp should not be powered off */
2107 if (atomisp_streaming_count(isp)) {
2108 atomisp_css_flush(isp);
2112 /* Disable the CSI interface on ANN B0/K0 */
2113 if (isp->media_dev.hw_revision >= ((ATOMISP_HW_REVISION_ISP2401 <<
2114 ATOMISP_HW_REVISION_SHIFT) | ATOMISP_HW_STEPPING_B0)) {
2115 pci_write_config_word(isp->pdev, MRFLD_PCI_CSI_CONTROL,
2116 isp->saved_regs.csi_control &
2117 ~MRFLD_PCI_CSI_CONTROL_CSI_READY);
2120 if (atomisp_freq_scaling(isp, ATOMISP_DFS_MODE_LOW, false))
2121 dev_warn(isp->dev, "DFS failed.\n");
2123 * ISP work around, need to reset isp
2124 * Is it correct time to reset ISP when first node does streamoff?
2126 if (isp->sw_contex.power_state == ATOM_ISP_POWER_UP) {
2128 bool recreate_streams[MAX_STREAM_NUM] = {0};
2130 if (isp->isp_timeout)
2131 dev_err(isp->dev, "%s: Resetting with WA activated",
2134 * It is possible that the other asd stream is in the stage
2135 * that v4l2_setfmt is just get called on it, which will
2136 * create css stream on that stream. But at this point, there
2137 * is no way to destroy the css stream created on that stream.
2139 * So force stream destroy here.
2141 for (i = 0; i < isp->num_of_streams; i++) {
2142 if (isp->asd[i].stream_prepared) {
2143 atomisp_destroy_pipes_stream_force(&isp->
2145 recreate_streams[i] = true;
2149 /* disable PUNIT/ISP acknowlede/handshake - SRSE=3 */
2150 pci_write_config_dword(isp->pdev, PCI_I_CONTROL, isp->saved_regs.i_control |
2151 MRFLD_PCI_I_CONTROL_SRSE_RESET_MASK);
2152 dev_err(isp->dev, "atomisp_reset");
2154 for (i = 0; i < isp->num_of_streams; i++) {
2155 if (recreate_streams[i])
2156 atomisp_create_pipes_stream(&isp->asd[i]);
2158 isp->isp_timeout = false;
2163 static int atomisp_streamoff(struct file *file, void *fh,
2164 enum v4l2_buf_type type)
2166 struct video_device *vdev = video_devdata(file);
2167 struct atomisp_device *isp = video_get_drvdata(vdev);
2170 mutex_lock(&isp->streamoff_mutex);
2171 rt_mutex_lock(&isp->mutex);
2172 rval = __atomisp_streamoff(file, fh, type);
2173 rt_mutex_unlock(&isp->mutex);
2174 mutex_unlock(&isp->streamoff_mutex);
2180 * To get the current value of a control.
2181 * applications initialize the id field of a struct v4l2_control and
2182 * call this ioctl with a pointer to this structure
2184 static int atomisp_g_ctrl(struct file *file, void *fh,
2185 struct v4l2_control *control)
2187 struct video_device *vdev = video_devdata(file);
2188 struct atomisp_sub_device *asd = atomisp_to_video_pipe(vdev)->asd;
2189 struct atomisp_device *isp = video_get_drvdata(vdev);
2190 int i, ret = -EINVAL;
2192 for (i = 0; i < ctrls_num; i++) {
2193 if (ci_v4l2_controls[i].id == control->id) {
2202 rt_mutex_lock(&isp->mutex);
2204 switch (control->id) {
2205 case V4L2_CID_IRIS_ABSOLUTE:
2206 case V4L2_CID_EXPOSURE_ABSOLUTE:
2207 case V4L2_CID_FNUMBER_ABSOLUTE:
2208 case V4L2_CID_2A_STATUS:
2209 case V4L2_CID_AUTO_N_PRESET_WHITE_BALANCE:
2210 case V4L2_CID_EXPOSURE:
2211 case V4L2_CID_EXPOSURE_AUTO:
2212 case V4L2_CID_SCENE_MODE:
2213 case V4L2_CID_ISO_SENSITIVITY:
2214 case V4L2_CID_ISO_SENSITIVITY_AUTO:
2215 case V4L2_CID_CONTRAST:
2216 case V4L2_CID_SATURATION:
2217 case V4L2_CID_SHARPNESS:
2218 case V4L2_CID_3A_LOCK:
2219 case V4L2_CID_EXPOSURE_ZONE_NUM:
2220 case V4L2_CID_TEST_PATTERN:
2221 case V4L2_CID_TEST_PATTERN_COLOR_R:
2222 case V4L2_CID_TEST_PATTERN_COLOR_GR:
2223 case V4L2_CID_TEST_PATTERN_COLOR_GB:
2224 case V4L2_CID_TEST_PATTERN_COLOR_B:
2225 rt_mutex_unlock(&isp->mutex);
2226 return v4l2_g_ctrl(isp->inputs[asd->input_curr].camera->
2227 ctrl_handler, control);
2228 case V4L2_CID_COLORFX:
2229 ret = atomisp_color_effect(asd, 0, &control->value);
2231 case V4L2_CID_ATOMISP_BAD_PIXEL_DETECTION:
2232 ret = atomisp_bad_pixel(asd, 0, &control->value);
2234 case V4L2_CID_ATOMISP_POSTPROCESS_GDC_CAC:
2235 ret = atomisp_gdc_cac(asd, 0, &control->value);
2237 case V4L2_CID_ATOMISP_VIDEO_STABLIZATION:
2238 ret = atomisp_video_stable(asd, 0, &control->value);
2240 case V4L2_CID_ATOMISP_FIXED_PATTERN_NR:
2241 ret = atomisp_fixed_pattern(asd, 0, &control->value);
2243 case V4L2_CID_ATOMISP_FALSE_COLOR_CORRECTION:
2244 ret = atomisp_false_color(asd, 0, &control->value);
2246 case V4L2_CID_ATOMISP_LOW_LIGHT:
2247 ret = atomisp_low_light(asd, 0, &control->value);
2254 rt_mutex_unlock(&isp->mutex);
2259 * To change the value of a control.
2260 * applications initialize the id and value fields of a struct v4l2_control
2261 * and call this ioctl.
2263 static int atomisp_s_ctrl(struct file *file, void *fh,
2264 struct v4l2_control *control)
2266 struct video_device *vdev = video_devdata(file);
2267 struct atomisp_sub_device *asd = atomisp_to_video_pipe(vdev)->asd;
2268 struct atomisp_device *isp = video_get_drvdata(vdev);
2269 int i, ret = -EINVAL;
2271 for (i = 0; i < ctrls_num; i++) {
2272 if (ci_v4l2_controls[i].id == control->id) {
2281 rt_mutex_lock(&isp->mutex);
2282 switch (control->id) {
2283 case V4L2_CID_AUTO_N_PRESET_WHITE_BALANCE:
2284 case V4L2_CID_EXPOSURE:
2285 case V4L2_CID_EXPOSURE_AUTO:
2286 case V4L2_CID_EXPOSURE_AUTO_PRIORITY:
2287 case V4L2_CID_SCENE_MODE:
2288 case V4L2_CID_ISO_SENSITIVITY:
2289 case V4L2_CID_ISO_SENSITIVITY_AUTO:
2290 case V4L2_CID_POWER_LINE_FREQUENCY:
2291 case V4L2_CID_EXPOSURE_METERING:
2292 case V4L2_CID_CONTRAST:
2293 case V4L2_CID_SATURATION:
2294 case V4L2_CID_SHARPNESS:
2295 case V4L2_CID_3A_LOCK:
2296 case V4L2_CID_COLORFX_CBCR:
2297 case V4L2_CID_TEST_PATTERN:
2298 case V4L2_CID_TEST_PATTERN_COLOR_R:
2299 case V4L2_CID_TEST_PATTERN_COLOR_GR:
2300 case V4L2_CID_TEST_PATTERN_COLOR_GB:
2301 case V4L2_CID_TEST_PATTERN_COLOR_B:
2302 rt_mutex_unlock(&isp->mutex);
2303 return v4l2_s_ctrl(NULL,
2304 isp->inputs[asd->input_curr].camera->
2305 ctrl_handler, control);
2306 case V4L2_CID_COLORFX:
2307 ret = atomisp_color_effect(asd, 1, &control->value);
2309 case V4L2_CID_ATOMISP_BAD_PIXEL_DETECTION:
2310 ret = atomisp_bad_pixel(asd, 1, &control->value);
2312 case V4L2_CID_ATOMISP_POSTPROCESS_GDC_CAC:
2313 ret = atomisp_gdc_cac(asd, 1, &control->value);
2315 case V4L2_CID_ATOMISP_VIDEO_STABLIZATION:
2316 ret = atomisp_video_stable(asd, 1, &control->value);
2318 case V4L2_CID_ATOMISP_FIXED_PATTERN_NR:
2319 ret = atomisp_fixed_pattern(asd, 1, &control->value);
2321 case V4L2_CID_ATOMISP_FALSE_COLOR_CORRECTION:
2322 ret = atomisp_false_color(asd, 1, &control->value);
2324 case V4L2_CID_REQUEST_FLASH:
2325 ret = atomisp_flash_enable(asd, control->value);
2327 case V4L2_CID_ATOMISP_LOW_LIGHT:
2328 ret = atomisp_low_light(asd, 1, &control->value);
2334 rt_mutex_unlock(&isp->mutex);
2339 * To query the attributes of a control.
2340 * applications set the id field of a struct v4l2_queryctrl and call the
2341 * this ioctl with a pointer to this structure. The driver fills
2342 * the rest of the structure.
2344 static int atomisp_queryctl(struct file *file, void *fh,
2345 struct v4l2_queryctrl *qc)
2347 int i, ret = -EINVAL;
2348 struct video_device *vdev = video_devdata(file);
2349 struct atomisp_sub_device *asd = atomisp_to_video_pipe(vdev)->asd;
2350 struct atomisp_device *isp = video_get_drvdata(vdev);
2353 case V4L2_CID_FOCUS_ABSOLUTE:
2354 case V4L2_CID_FOCUS_RELATIVE:
2355 case V4L2_CID_FOCUS_STATUS:
2356 if (!atomisp_hw_is_isp2401) {
2357 return v4l2_queryctrl(isp->inputs[asd->input_curr].camera->
2362 return v4l2_queryctrl(isp->motor->ctrl_handler, qc);
2364 return v4l2_queryctrl(isp->inputs[asd->input_curr].
2365 camera->ctrl_handler, qc);
2368 if (qc->id & V4L2_CTRL_FLAG_NEXT_CTRL)
2371 for (i = 0; i < ctrls_num; i++) {
2372 if (ci_v4l2_controls[i].id == qc->id) {
2373 memcpy(qc, &ci_v4l2_controls[i],
2374 sizeof(struct v4l2_queryctrl));
2375 qc->reserved[0] = 0;
2381 qc->flags = V4L2_CTRL_FLAG_DISABLED;
2386 static int atomisp_camera_g_ext_ctrls(struct file *file, void *fh,
2387 struct v4l2_ext_controls *c)
2389 struct video_device *vdev = video_devdata(file);
2390 struct atomisp_sub_device *asd = atomisp_to_video_pipe(vdev)->asd;
2391 struct atomisp_device *isp = video_get_drvdata(vdev);
2392 struct v4l2_subdev *motor;
2393 struct v4l2_control ctrl;
2397 if (!atomisp_hw_is_isp2401)
2398 motor = isp->inputs[asd->input_curr].motor;
2402 for (i = 0; i < c->count; i++) {
2403 ctrl.id = c->controls[i].id;
2404 ctrl.value = c->controls[i].value;
2406 case V4L2_CID_EXPOSURE_ABSOLUTE:
2407 case V4L2_CID_EXPOSURE_AUTO:
2408 case V4L2_CID_IRIS_ABSOLUTE:
2409 case V4L2_CID_FNUMBER_ABSOLUTE:
2410 case V4L2_CID_BIN_FACTOR_HORZ:
2411 case V4L2_CID_BIN_FACTOR_VERT:
2412 case V4L2_CID_3A_LOCK:
2413 case V4L2_CID_TEST_PATTERN:
2414 case V4L2_CID_TEST_PATTERN_COLOR_R:
2415 case V4L2_CID_TEST_PATTERN_COLOR_GR:
2416 case V4L2_CID_TEST_PATTERN_COLOR_GB:
2417 case V4L2_CID_TEST_PATTERN_COLOR_B:
2419 * Exposure related control will be handled by sensor
2423 v4l2_g_ctrl(isp->inputs[asd->input_curr].camera->
2424 ctrl_handler, &ctrl);
2426 case V4L2_CID_FOCUS_ABSOLUTE:
2427 case V4L2_CID_FOCUS_RELATIVE:
2428 case V4L2_CID_FOCUS_STATUS:
2429 case V4L2_CID_FOCUS_AUTO:
2431 ret = v4l2_g_ctrl(motor->ctrl_handler, &ctrl);
2433 case V4L2_CID_FLASH_STATUS:
2434 case V4L2_CID_FLASH_INTENSITY:
2435 case V4L2_CID_FLASH_TORCH_INTENSITY:
2436 case V4L2_CID_FLASH_INDICATOR_INTENSITY:
2437 case V4L2_CID_FLASH_TIMEOUT:
2438 case V4L2_CID_FLASH_STROBE:
2439 case V4L2_CID_FLASH_MODE:
2440 case V4L2_CID_FLASH_STATUS_REGISTER:
2443 v4l2_g_ctrl(isp->flash->ctrl_handler,
2446 case V4L2_CID_ZOOM_ABSOLUTE:
2447 rt_mutex_lock(&isp->mutex);
2448 ret = atomisp_digital_zoom(asd, 0, &ctrl.value);
2449 rt_mutex_unlock(&isp->mutex);
2451 case V4L2_CID_G_SKIP_FRAMES:
2452 ret = v4l2_subdev_call(
2453 isp->inputs[asd->input_curr].camera,
2454 sensor, g_skip_frames, (u32 *)&ctrl.value);
2464 c->controls[i].value = ctrl.value;
2469 /* This ioctl allows the application to get multiple controls by class */
2470 static int atomisp_g_ext_ctrls(struct file *file, void *fh,
2471 struct v4l2_ext_controls *c)
2473 struct v4l2_control ctrl;
2476 /* input_lock is not need for the Camera related IOCTLs
2477 * The input_lock downgrade the FPS of 3A*/
2478 ret = atomisp_camera_g_ext_ctrls(file, fh, c);
2482 for (i = 0; i < c->count; i++) {
2483 ctrl.id = c->controls[i].id;
2484 ctrl.value = c->controls[i].value;
2485 ret = atomisp_g_ctrl(file, fh, &ctrl);
2486 c->controls[i].value = ctrl.value;
2495 static int atomisp_camera_s_ext_ctrls(struct file *file, void *fh,
2496 struct v4l2_ext_controls *c)
2498 struct video_device *vdev = video_devdata(file);
2499 struct atomisp_sub_device *asd = atomisp_to_video_pipe(vdev)->asd;
2500 struct atomisp_device *isp = video_get_drvdata(vdev);
2501 struct v4l2_subdev *motor;
2502 struct v4l2_control ctrl;
2507 if (!atomisp_hw_is_isp2401)
2508 motor = isp->inputs[asd->input_curr].motor;
2512 for (i = 0; i < c->count; i++) {
2513 struct v4l2_ctrl *ctr;
2515 ctrl.id = c->controls[i].id;
2516 ctrl.value = c->controls[i].value;
2518 case V4L2_CID_EXPOSURE_ABSOLUTE:
2519 case V4L2_CID_EXPOSURE_AUTO:
2520 case V4L2_CID_EXPOSURE_METERING:
2521 case V4L2_CID_IRIS_ABSOLUTE:
2522 case V4L2_CID_FNUMBER_ABSOLUTE:
2523 case V4L2_CID_VCM_TIMEING:
2524 case V4L2_CID_VCM_SLEW:
2525 case V4L2_CID_3A_LOCK:
2526 case V4L2_CID_TEST_PATTERN:
2527 case V4L2_CID_TEST_PATTERN_COLOR_R:
2528 case V4L2_CID_TEST_PATTERN_COLOR_GR:
2529 case V4L2_CID_TEST_PATTERN_COLOR_GB:
2530 case V4L2_CID_TEST_PATTERN_COLOR_B:
2531 ret = v4l2_s_ctrl(NULL,
2532 isp->inputs[asd->input_curr].camera->
2533 ctrl_handler, &ctrl);
2535 case V4L2_CID_FOCUS_ABSOLUTE:
2536 case V4L2_CID_FOCUS_RELATIVE:
2537 case V4L2_CID_FOCUS_STATUS:
2538 case V4L2_CID_FOCUS_AUTO:
2540 ret = v4l2_s_ctrl(NULL, motor->ctrl_handler,
2543 ret = v4l2_s_ctrl(NULL,
2544 isp->inputs[asd->input_curr].
2545 camera->ctrl_handler, &ctrl);
2547 case V4L2_CID_FLASH_STATUS:
2548 case V4L2_CID_FLASH_INTENSITY:
2549 case V4L2_CID_FLASH_TORCH_INTENSITY:
2550 case V4L2_CID_FLASH_INDICATOR_INTENSITY:
2551 case V4L2_CID_FLASH_TIMEOUT:
2552 case V4L2_CID_FLASH_STROBE:
2553 case V4L2_CID_FLASH_MODE:
2554 case V4L2_CID_FLASH_STATUS_REGISTER:
2555 rt_mutex_lock(&isp->mutex);
2558 v4l2_s_ctrl(NULL, isp->flash->ctrl_handler,
2560 /* When flash mode is changed we need to reset
2562 if (ctrl.id == V4L2_CID_FLASH_MODE) {
2563 asd->params.flash_state =
2565 asd->params.num_flash_frames = 0;
2568 rt_mutex_unlock(&isp->mutex);
2570 case V4L2_CID_ZOOM_ABSOLUTE:
2571 rt_mutex_lock(&isp->mutex);
2572 ret = atomisp_digital_zoom(asd, 1, &ctrl.value);
2573 rt_mutex_unlock(&isp->mutex);
2576 ctr = v4l2_ctrl_find(&asd->ctrl_handler, ctrl.id);
2578 ret = v4l2_ctrl_s_ctrl(ctr, ctrl.value);
2587 c->controls[i].value = ctrl.value;
2592 /* This ioctl allows the application to set multiple controls by class */
2593 static int atomisp_s_ext_ctrls(struct file *file, void *fh,
2594 struct v4l2_ext_controls *c)
2596 struct v4l2_control ctrl;
2599 /* input_lock is not need for the Camera related IOCTLs
2600 * The input_lock downgrade the FPS of 3A*/
2601 ret = atomisp_camera_s_ext_ctrls(file, fh, c);
2605 for (i = 0; i < c->count; i++) {
2606 ctrl.id = c->controls[i].id;
2607 ctrl.value = c->controls[i].value;
2608 ret = atomisp_s_ctrl(file, fh, &ctrl);
2609 c->controls[i].value = ctrl.value;
2619 * vidioc_g/s_param are used to switch isp running mode
2621 static int atomisp_g_parm(struct file *file, void *fh,
2622 struct v4l2_streamparm *parm)
2624 struct video_device *vdev = video_devdata(file);
2625 struct atomisp_sub_device *asd = atomisp_to_video_pipe(vdev)->asd;
2626 struct atomisp_device *isp = video_get_drvdata(vdev);
2628 if (parm->type != V4L2_BUF_TYPE_VIDEO_CAPTURE) {
2629 dev_err(isp->dev, "unsupport v4l2 buf type\n");
2633 rt_mutex_lock(&isp->mutex);
2634 parm->parm.capture.capturemode = asd->run_mode->val;
2635 rt_mutex_unlock(&isp->mutex);
2640 static int atomisp_s_parm(struct file *file, void *fh,
2641 struct v4l2_streamparm *parm)
2643 struct video_device *vdev = video_devdata(file);
2644 struct atomisp_device *isp = video_get_drvdata(vdev);
2645 struct atomisp_sub_device *asd = atomisp_to_video_pipe(vdev)->asd;
2650 if (parm->type != V4L2_BUF_TYPE_VIDEO_CAPTURE) {
2651 dev_err(isp->dev, "unsupport v4l2 buf type\n");
2655 rt_mutex_lock(&isp->mutex);
2657 asd->high_speed_mode = false;
2658 switch (parm->parm.capture.capturemode) {
2659 case CI_MODE_NONE: {
2660 struct v4l2_subdev_frame_interval fi = {0};
2662 fi.interval = parm->parm.capture.timeperframe;
2664 rval = v4l2_subdev_call(isp->inputs[asd->input_curr].camera,
2665 video, s_frame_interval, &fi);
2667 parm->parm.capture.timeperframe = fi.interval;
2669 if (fi.interval.numerator != 0) {
2670 fps = fi.interval.denominator / fi.interval.numerator;
2672 asd->high_speed_mode = true;
2678 mode = ATOMISP_RUN_MODE_VIDEO;
2680 case CI_MODE_STILL_CAPTURE:
2681 mode = ATOMISP_RUN_MODE_STILL_CAPTURE;
2683 case CI_MODE_CONTINUOUS:
2684 mode = ATOMISP_RUN_MODE_CONTINUOUS_CAPTURE;
2686 case CI_MODE_PREVIEW:
2687 mode = ATOMISP_RUN_MODE_PREVIEW;
2694 rval = v4l2_ctrl_s_ctrl(asd->run_mode, mode);
2697 rt_mutex_unlock(&isp->mutex);
2699 return rval == -ENOIOCTLCMD ? 0 : rval;
2702 static int atomisp_s_parm_file(struct file *file, void *fh,
2703 struct v4l2_streamparm *parm)
2705 struct video_device *vdev = video_devdata(file);
2706 struct atomisp_device *isp = video_get_drvdata(vdev);
2708 if (parm->type != V4L2_BUF_TYPE_VIDEO_OUTPUT) {
2709 dev_err(isp->dev, "unsupport v4l2 buf type for output\n");
2713 rt_mutex_lock(&isp->mutex);
2714 isp->sw_contex.file_input = true;
2715 rt_mutex_unlock(&isp->mutex);
2720 static long atomisp_vidioc_default(struct file *file, void *fh,
2721 bool valid_prio, unsigned int cmd, void *arg)
2723 struct video_device *vdev = video_devdata(file);
2724 struct atomisp_device *isp = video_get_drvdata(vdev);
2725 struct atomisp_sub_device *asd;
2726 struct v4l2_subdev *motor;
2730 acc_node = !strcmp(vdev->name, "ATOMISP ISP ACC");
2732 asd = atomisp_to_acc_pipe(vdev)->asd;
2734 asd = atomisp_to_video_pipe(vdev)->asd;
2736 if (!atomisp_hw_is_isp2401)
2737 motor = isp->inputs[asd->input_curr].motor;
2742 case ATOMISP_IOC_G_MOTOR_PRIV_INT_DATA:
2743 case ATOMISP_IOC_S_EXPOSURE:
2744 case ATOMISP_IOC_G_SENSOR_CALIBRATION_GROUP:
2745 case ATOMISP_IOC_G_SENSOR_PRIV_INT_DATA:
2746 case ATOMISP_IOC_EXT_ISP_CTRL:
2747 case ATOMISP_IOC_G_SENSOR_AE_BRACKETING_INFO:
2748 case ATOMISP_IOC_S_SENSOR_AE_BRACKETING_MODE:
2749 case ATOMISP_IOC_G_SENSOR_AE_BRACKETING_MODE:
2750 case ATOMISP_IOC_S_SENSOR_AE_BRACKETING_LUT:
2751 case ATOMISP_IOC_S_SENSOR_EE_CONFIG:
2752 case ATOMISP_IOC_G_UPDATE_EXPOSURE:
2753 /* we do not need take isp->mutex for these IOCTLs */
2756 rt_mutex_lock(&isp->mutex);
2760 case ATOMISP_IOC_S_SENSOR_RUNMODE:
2761 if (atomisp_hw_is_isp2401)
2762 err = atomisp_set_sensor_runmode(asd, arg);
2767 case ATOMISP_IOC_G_XNR:
2768 err = atomisp_xnr(asd, 0, arg);
2771 case ATOMISP_IOC_S_XNR:
2772 err = atomisp_xnr(asd, 1, arg);
2775 case ATOMISP_IOC_G_NR:
2776 err = atomisp_nr(asd, 0, arg);
2779 case ATOMISP_IOC_S_NR:
2780 err = atomisp_nr(asd, 1, arg);
2783 case ATOMISP_IOC_G_TNR:
2784 err = atomisp_tnr(asd, 0, arg);
2787 case ATOMISP_IOC_S_TNR:
2788 err = atomisp_tnr(asd, 1, arg);
2791 case ATOMISP_IOC_G_BLACK_LEVEL_COMP:
2792 err = atomisp_black_level(asd, 0, arg);
2795 case ATOMISP_IOC_S_BLACK_LEVEL_COMP:
2796 err = atomisp_black_level(asd, 1, arg);
2799 case ATOMISP_IOC_G_EE:
2800 err = atomisp_ee(asd, 0, arg);
2803 case ATOMISP_IOC_S_EE:
2804 err = atomisp_ee(asd, 1, arg);
2807 case ATOMISP_IOC_G_DIS_STAT:
2808 err = atomisp_get_dis_stat(asd, arg);
2811 case ATOMISP_IOC_G_DVS2_BQ_RESOLUTIONS:
2812 err = atomisp_get_dvs2_bq_resolutions(asd, arg);
2815 case ATOMISP_IOC_S_DIS_COEFS:
2816 err = atomisp_css_cp_dvs2_coefs(asd, arg,
2817 &asd->params.css_param, true);
2819 asd->params.css_update_params_needed = true;
2822 case ATOMISP_IOC_S_DIS_VECTOR:
2823 err = atomisp_cp_dvs_6axis_config(asd, arg,
2824 &asd->params.css_param, true);
2826 asd->params.css_update_params_needed = true;
2829 case ATOMISP_IOC_G_ISP_PARM:
2830 err = atomisp_param(asd, 0, arg);
2833 case ATOMISP_IOC_S_ISP_PARM:
2834 err = atomisp_param(asd, 1, arg);
2837 case ATOMISP_IOC_G_3A_STAT:
2838 err = atomisp_3a_stat(asd, 0, arg);
2841 case ATOMISP_IOC_G_ISP_GAMMA:
2842 err = atomisp_gamma(asd, 0, arg);
2845 case ATOMISP_IOC_S_ISP_GAMMA:
2846 err = atomisp_gamma(asd, 1, arg);
2849 case ATOMISP_IOC_G_ISP_GDC_TAB:
2850 err = atomisp_gdc_cac_table(asd, 0, arg);
2853 case ATOMISP_IOC_S_ISP_GDC_TAB:
2854 err = atomisp_gdc_cac_table(asd, 1, arg);
2857 case ATOMISP_IOC_G_ISP_MACC:
2858 err = atomisp_macc_table(asd, 0, arg);
2861 case ATOMISP_IOC_S_ISP_MACC:
2862 err = atomisp_macc_table(asd, 1, arg);
2865 case ATOMISP_IOC_G_ISP_BAD_PIXEL_DETECTION:
2866 err = atomisp_bad_pixel_param(asd, 0, arg);
2869 case ATOMISP_IOC_S_ISP_BAD_PIXEL_DETECTION:
2870 err = atomisp_bad_pixel_param(asd, 1, arg);
2873 case ATOMISP_IOC_G_ISP_FALSE_COLOR_CORRECTION:
2874 err = atomisp_false_color_param(asd, 0, arg);
2877 case ATOMISP_IOC_S_ISP_FALSE_COLOR_CORRECTION:
2878 err = atomisp_false_color_param(asd, 1, arg);
2881 case ATOMISP_IOC_G_ISP_CTC:
2882 err = atomisp_ctc(asd, 0, arg);
2885 case ATOMISP_IOC_S_ISP_CTC:
2886 err = atomisp_ctc(asd, 1, arg);
2889 case ATOMISP_IOC_G_ISP_WHITE_BALANCE:
2890 err = atomisp_white_balance_param(asd, 0, arg);
2893 case ATOMISP_IOC_S_ISP_WHITE_BALANCE:
2894 err = atomisp_white_balance_param(asd, 1, arg);
2897 case ATOMISP_IOC_G_3A_CONFIG:
2898 err = atomisp_3a_config_param(asd, 0, arg);
2901 case ATOMISP_IOC_S_3A_CONFIG:
2902 err = atomisp_3a_config_param(asd, 1, arg);
2905 case ATOMISP_IOC_S_ISP_FPN_TABLE:
2906 err = atomisp_fixed_pattern_table(asd, arg);
2909 case ATOMISP_IOC_ISP_MAKERNOTE:
2910 err = atomisp_exif_makernote(asd, arg);
2913 case ATOMISP_IOC_G_SENSOR_MODE_DATA:
2914 err = atomisp_get_sensor_mode_data(asd, arg);
2917 case ATOMISP_IOC_G_MOTOR_PRIV_INT_DATA:
2919 err = v4l2_subdev_call(motor, core, ioctl, cmd, arg);
2921 err = v4l2_subdev_call(isp->inputs[asd->input_curr].camera,
2922 core, ioctl, cmd, arg);
2925 case ATOMISP_IOC_S_EXPOSURE:
2926 case ATOMISP_IOC_G_SENSOR_CALIBRATION_GROUP:
2927 case ATOMISP_IOC_G_SENSOR_PRIV_INT_DATA:
2928 case ATOMISP_IOC_G_SENSOR_AE_BRACKETING_INFO:
2929 case ATOMISP_IOC_S_SENSOR_AE_BRACKETING_MODE:
2930 case ATOMISP_IOC_G_SENSOR_AE_BRACKETING_MODE:
2931 case ATOMISP_IOC_S_SENSOR_AE_BRACKETING_LUT:
2932 err = v4l2_subdev_call(isp->inputs[asd->input_curr].camera,
2933 core, ioctl, cmd, arg);
2935 case ATOMISP_IOC_G_UPDATE_EXPOSURE:
2936 if (atomisp_hw_is_isp2401)
2937 err = v4l2_subdev_call(isp->inputs[asd->input_curr].camera,
2938 core, ioctl, cmd, arg);
2943 case ATOMISP_IOC_ACC_LOAD:
2944 err = atomisp_acc_load(asd, arg);
2947 case ATOMISP_IOC_ACC_LOAD_TO_PIPE:
2948 err = atomisp_acc_load_to_pipe(asd, arg);
2951 case ATOMISP_IOC_ACC_UNLOAD:
2952 err = atomisp_acc_unload(asd, arg);
2955 case ATOMISP_IOC_ACC_START:
2956 err = atomisp_acc_start(asd, arg);
2959 case ATOMISP_IOC_ACC_WAIT:
2960 err = atomisp_acc_wait(asd, arg);
2963 case ATOMISP_IOC_ACC_MAP:
2964 err = atomisp_acc_map(asd, arg);
2967 case ATOMISP_IOC_ACC_UNMAP:
2968 err = atomisp_acc_unmap(asd, arg);
2971 case ATOMISP_IOC_ACC_S_MAPPED_ARG:
2972 err = atomisp_acc_s_mapped_arg(asd, arg);
2975 case ATOMISP_IOC_S_ISP_SHD_TAB:
2976 err = atomisp_set_shading_table(asd, arg);
2979 case ATOMISP_IOC_G_ISP_GAMMA_CORRECTION:
2980 err = atomisp_gamma_correction(asd, 0, arg);
2983 case ATOMISP_IOC_S_ISP_GAMMA_CORRECTION:
2984 err = atomisp_gamma_correction(asd, 1, arg);
2987 case ATOMISP_IOC_S_PARAMETERS:
2988 err = atomisp_set_parameters(vdev, arg);
2991 case ATOMISP_IOC_S_CONT_CAPTURE_CONFIG:
2992 err = atomisp_offline_capture_configure(asd, arg);
2994 case ATOMISP_IOC_G_METADATA:
2995 err = atomisp_get_metadata(asd, 0, arg);
2997 case ATOMISP_IOC_G_METADATA_BY_TYPE:
2998 err = atomisp_get_metadata_by_type(asd, 0, arg);
3000 case ATOMISP_IOC_EXT_ISP_CTRL:
3001 err = v4l2_subdev_call(isp->inputs[asd->input_curr].camera,
3002 core, ioctl, cmd, arg);
3004 case ATOMISP_IOC_EXP_ID_UNLOCK:
3005 err = atomisp_exp_id_unlock(asd, arg);
3007 case ATOMISP_IOC_EXP_ID_CAPTURE:
3008 err = atomisp_exp_id_capture(asd, arg);
3010 case ATOMISP_IOC_S_ENABLE_DZ_CAPT_PIPE:
3011 err = atomisp_enable_dz_capt_pipe(asd, arg);
3013 case ATOMISP_IOC_G_FORMATS_CONFIG:
3014 err = atomisp_formats(asd, 0, arg);
3017 case ATOMISP_IOC_S_FORMATS_CONFIG:
3018 err = atomisp_formats(asd, 1, arg);
3020 case ATOMISP_IOC_S_EXPOSURE_WINDOW:
3021 err = atomisp_s_ae_window(asd, arg);
3023 case ATOMISP_IOC_S_ACC_STATE:
3024 err = atomisp_acc_set_state(asd, arg);
3026 case ATOMISP_IOC_G_ACC_STATE:
3027 err = atomisp_acc_get_state(asd, arg);
3029 case ATOMISP_IOC_INJECT_A_FAKE_EVENT:
3030 err = atomisp_inject_a_fake_event(asd, arg);
3032 case ATOMISP_IOC_G_INVALID_FRAME_NUM:
3033 err = atomisp_get_invalid_frame_num(vdev, arg);
3035 case ATOMISP_IOC_S_ARRAY_RESOLUTION:
3036 err = atomisp_set_array_res(asd, arg);
3044 case ATOMISP_IOC_G_MOTOR_PRIV_INT_DATA:
3045 case ATOMISP_IOC_S_EXPOSURE:
3046 case ATOMISP_IOC_G_SENSOR_CALIBRATION_GROUP:
3047 case ATOMISP_IOC_G_SENSOR_PRIV_INT_DATA:
3048 case ATOMISP_IOC_EXT_ISP_CTRL:
3049 case ATOMISP_IOC_G_SENSOR_AE_BRACKETING_INFO:
3050 case ATOMISP_IOC_S_SENSOR_AE_BRACKETING_MODE:
3051 case ATOMISP_IOC_G_SENSOR_AE_BRACKETING_MODE:
3052 case ATOMISP_IOC_S_SENSOR_AE_BRACKETING_LUT:
3053 case ATOMISP_IOC_G_UPDATE_EXPOSURE:
3056 rt_mutex_unlock(&isp->mutex);
3062 const struct v4l2_ioctl_ops atomisp_ioctl_ops = {
3063 .vidioc_querycap = atomisp_querycap,
3064 .vidioc_enum_input = atomisp_enum_input,
3065 .vidioc_g_input = atomisp_g_input,
3066 .vidioc_s_input = atomisp_s_input,
3067 .vidioc_queryctrl = atomisp_queryctl,
3068 .vidioc_s_ctrl = atomisp_s_ctrl,
3069 .vidioc_g_ctrl = atomisp_g_ctrl,
3070 .vidioc_s_ext_ctrls = atomisp_s_ext_ctrls,
3071 .vidioc_g_ext_ctrls = atomisp_g_ext_ctrls,
3072 .vidioc_enum_fmt_vid_cap = atomisp_enum_fmt_cap,
3073 .vidioc_try_fmt_vid_cap = atomisp_try_fmt_cap,
3074 .vidioc_g_fmt_vid_cap = atomisp_g_fmt_cap,
3075 .vidioc_s_fmt_vid_cap = atomisp_s_fmt_cap,
3076 .vidioc_reqbufs = atomisp_reqbufs,
3077 .vidioc_querybuf = atomisp_querybuf,
3078 .vidioc_qbuf = atomisp_qbuf,
3079 .vidioc_dqbuf = atomisp_dqbuf,
3080 .vidioc_streamon = atomisp_streamon,
3081 .vidioc_streamoff = atomisp_streamoff,
3082 .vidioc_default = atomisp_vidioc_default,
3083 .vidioc_s_parm = atomisp_s_parm,
3084 .vidioc_g_parm = atomisp_g_parm,
3087 const struct v4l2_ioctl_ops atomisp_file_ioctl_ops = {
3088 .vidioc_querycap = atomisp_querycap,
3089 .vidioc_g_fmt_vid_out = atomisp_g_fmt_file,
3090 .vidioc_s_fmt_vid_out = atomisp_s_fmt_file,
3091 .vidioc_s_parm = atomisp_s_parm_file,
3092 .vidioc_reqbufs = atomisp_reqbufs_file,
3093 .vidioc_querybuf = atomisp_querybuf_file,
3094 .vidioc_qbuf = atomisp_qbuf_file,