1 /* 2 * isp_controller.cpp - isp controller 3 * 4 * Copyright (c) 2014-2015 Intel Corporation 5 * 6 * Licensed under the Apache License, Version 2.0 (the "License"); 7 * you may not use this file except in compliance with the License. 8 * You may obtain a copy of the License at 9 * 10 * http://www.apache.org/licenses/LICENSE-2.0 11 * 12 * Unless required by applicable law or agreed to in writing, software 13 * distributed under the License is distributed on an "AS IS" BASIS, 14 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 15 * See the License for the specific language governing permissions and 16 * limitations under the License. 17 * 18 * Author: Wind Yuan <feng.yuan (at) intel.com> 19 */ 20 21 #include "isp_controller.h" 22 #include "v4l2_device.h" 23 #include "x3a_statistics_queue.h" 24 #include "x3a_isp_config.h" 25 26 #include <linux/atomisp.h> 27 28 namespace XCam { 29 30 IspController::IspController (SmartPtr<V4l2Device> & device) 31 : _device (device) 32 { 33 } 34 IspController::~IspController () 35 { 36 } 37 38 void 39 IspController::init_sensor_mode_data (struct atomisp_sensor_mode_data *sensor_mode_data) 40 { 41 sensor_mode_data->coarse_integration_time_min = 1; 42 sensor_mode_data->coarse_integration_time_max_margin = 1; 43 sensor_mode_data->fine_integration_time_min = 0; 44 sensor_mode_data->fine_integration_time_max_margin = 0; 45 sensor_mode_data->fine_integration_time_def = 0; 46 sensor_mode_data->frame_length_lines = 1125; 47 sensor_mode_data->line_length_pck = 1320; 48 sensor_mode_data->read_mode = 0; 49 sensor_mode_data->vt_pix_clk_freq_mhz = 37125000; 50 sensor_mode_data->crop_horizontal_start = 0; 51 sensor_mode_data->crop_vertical_start = 0; 52 sensor_mode_data->crop_horizontal_end = 1920; 53 sensor_mode_data->crop_vertical_end = 1080; 54 sensor_mode_data->output_width = 1920; 55 sensor_mode_data->output_height = 1080; 56 sensor_mode_data->binning_factor_x = 1; 57 sensor_mode_data->binning_factor_y = 1; 58 } 59 60 61 XCamReturn 62 IspController::get_sensor_mode_data (struct atomisp_sensor_mode_data &sensor_mode_data) 63 { 64 init_sensor_mode_data (&sensor_mode_data); 65 if (_device->io_control (ATOMISP_IOC_G_SENSOR_MODE_DATA, &sensor_mode_data) < 0) { 66 XCAM_LOG_WARNING (" get ISP sensor mode data failed, use initialized sensor mode data"); 67 } 68 return XCAM_RETURN_NO_ERROR; 69 } 70 71 XCamReturn 72 IspController::get_isp_parameter (struct atomisp_parm ¶meters) 73 { 74 if ( _device->io_control (ATOMISP_IOC_G_ISP_PARM, ¶meters) < 0) { 75 XCAM_LOG_WARNING (" get ISP parameters failed"); 76 return XCAM_RETURN_ERROR_IOCTL; 77 } 78 return XCAM_RETURN_NO_ERROR; 79 } 80 81 XCamReturn 82 IspController::get_3a_statistics (SmartPtr<X3aIspStatistics> &stats) 83 { 84 struct atomisp_3a_statistics *isp_stats = NULL; 85 86 XCAM_ASSERT (stats.ptr()); 87 XCAM_FAIL_RETURN (WARNING, stats.ptr(), 88 XCAM_RETURN_ERROR_PARAM, "stats empty"); 89 90 isp_stats = stats->get_isp_stats (); 91 92 if ( _device->io_control (ATOMISP_IOC_G_3A_STAT, isp_stats) < 0) { 93 XCAM_LOG_WARNING (" get 3a stats failed from ISP"); 94 return XCAM_RETURN_ERROR_IOCTL; 95 } 96 return XCAM_RETURN_NO_ERROR; 97 } 98 99 XCamReturn 100 IspController::set_3a_config (X3aIspConfig *config) 101 { 102 struct atomisp_parameters &isp_config = config->get_isp_configs (); 103 if ( _device->io_control (ATOMISP_IOC_S_PARAMETERS, &isp_config) < 0) { 104 XCAM_LOG_WARNING (" set 3a config failed to ISP"); 105 return XCAM_RETURN_ERROR_IOCTL; 106 } 107 108 return XCAM_RETURN_NO_ERROR; 109 } 110 111 XCamReturn 112 IspController::set_3a_exposure (X3aIspExposureResult *res) 113 { 114 const struct atomisp_exposure &exposure = res->get_isp_config (); 115 return set_3a_exposure (exposure); 116 117 return XCAM_RETURN_NO_ERROR; 118 } 119 120 XCamReturn 121 IspController::set_3a_exposure (const struct atomisp_exposure &exposure) 122 { 123 if ( _device->io_control (ATOMISP_IOC_S_EXPOSURE, (struct atomisp_exposure*)(&exposure)) < 0) { 124 XCAM_LOG_WARNING (" set exposure result failed to device"); 125 return XCAM_RETURN_ERROR_IOCTL; 126 } 127 XCAM_LOG_DEBUG ("isp set exposure result, integration_time:%d, gain code:%d", 128 exposure.integration_time[0], exposure.gain[0]); 129 130 return XCAM_RETURN_NO_ERROR; 131 } 132 133 XCamReturn 134 IspController::set_3a_focus (const XCam3aResultFocus &focus) 135 { 136 int position = focus.position; 137 struct v4l2_control control; 138 139 xcam_mem_clear (control); 140 control.id = V4L2_CID_FOCUS_ABSOLUTE; 141 control.value = position; 142 143 if (_device->io_control (VIDIOC_S_CTRL, &control) < 0) { 144 XCAM_LOG_WARNING (" set focus result failed to device"); 145 return XCAM_RETURN_ERROR_IOCTL; 146 } 147 return XCAM_RETURN_NO_ERROR; 148 } 149 150 151 }; 152