• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2 *
3 * SPDX-License-Identifier: GPL-2.0
4 *
5 * Copyright (C) 2011-2018 ARM or its affiliates
6 *
7 * This program is free software; you can redistribute it and/or modify
8 * it under the terms of the GNU General Public License as published by
9 * the Free Software Foundation; version 2.
10 * This program is distributed in the hope that it will be useful, but
11 * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
12 * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
13 * for more details.
14 * You should have received a copy of the GNU General Public License along
15 * with this program; if not, write to the Free Software Foundation, Inc.,
16 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
17 *
18 */
19 
20 #include <linux/device.h>
21 #include <linux/slab.h>
22 #include <linux/random.h>
23 #include <asm/div64.h>
24 #include <linux/sched.h>
25 #include <linux/videodev2.h>
26 #include <media/videobuf2-core.h>
27 #include <media/videobuf2-vmalloc.h>
28 
29 #include "system_interrupts.h"
30 #include "acamera_command_api.h"
31 #include "acamera_firmware_settings.h"
32 #include "application_command_api.h"
33 #include "acamera_logger.h"
34 #include "isp-v4l2-common.h"
35 #include "fw-interface.h"
36 #include "runtime_initialization_settings.h"
37 #include <linux/delay.h>
38 
39 //use main_firmware.c routines to initialize fw
40 extern int isp_fw_init( uint32_t hw_isp_addr );
41 extern void isp_fw_exit( void );
42 
43 static int isp_started = 0;
44 static int custom_wdr_mode = 0;
45 static int custom_exp = 0;
46 static int custom_fps = 0;
47 /* ----------------------------------------------------------------
48  * fw_interface control interface
49  */
50 #define FWDEBUG(fmt,arg...) pr_info("[%s.%d]"fmt"\n",__FUNCTION__,__LINE__,##arg)
custom_initialization(uint32_t ctx_num)51 void custom_initialization( uint32_t ctx_num )
52 {
53 
54 }
55 
56 
57 /* fw-interface isp control interface */
fw_intf_isp_init(uint32_t hw_isp_addr)58 int fw_intf_isp_init(  uint32_t hw_isp_addr )
59 {
60 	FWDEBUG("hw_isp_addr:0x%x",hw_isp_addr);
61     LOG( LOG_INFO, "Initializing fw ..." );
62     int rc = 0;
63     /* flag variable update */
64 
65     rc = isp_fw_init(hw_isp_addr);
66 
67     if ( rc == 0 )
68         isp_started = 1;
69 
70     custom_wdr_mode = 0;
71     custom_exp = 0;
72     custom_fps = 0;
73 
74     return rc;
75 }
76 
fw_intf_is_isp_started(void)77 int fw_intf_is_isp_started( void )
78 {
79 	FWDEBUG("");
80     return isp_started;
81 }
82 
fw_intf_isp_deinit(void)83 void fw_intf_isp_deinit( void )
84 {
85 	FWDEBUG("");
86     LOG( LOG_INFO, "Deinitializing fw interface ..." );
87 
88     /* flag variable update */
89     isp_started = 0;
90 
91     isp_fw_exit();
92 }
93 
fw_calibration_update(uint32_t ctx_id)94 uint32_t fw_calibration_update( uint32_t ctx_id )
95 {
96 	FWDEBUG("ctx_id:0x%x",ctx_id);
97     uint32_t retval;
98     acamera_command( ctx_id, TSYSTEM, CALIBRATION_UPDATE, UPDATE, COMMAND_SET, &retval );
99     return retval;
100 }
101 
fw_intf_isp_start(void)102 int fw_intf_isp_start( void )
103 {
104     LOG( LOG_DEBUG, "Starting context" );
105 	FWDEBUG("");
106 
107     return 0;
108 }
109 
fw_intf_isp_stop(void)110 void fw_intf_isp_stop( void )
111 {
112 	FWDEBUG("");
113     LOG( LOG_DEBUG, "Enter" );
114 }
115 
fw_intf_isp_set_current_ctx_id(uint32_t ctx_id)116 int fw_intf_isp_set_current_ctx_id( uint32_t ctx_id )
117 {
118     int active_ctx_id = ctx_id;
119 	FWDEBUG("");
120     if ( !isp_started ) {
121         LOG( LOG_ERR, "ISP FW not inited yet" );
122         return -EBUSY;
123     }
124 
125 #if defined( TGENERAL ) && defined( ACTIVE_CONTEXT )
126     acamera_command( ctx_id, TGENERAL, ACTIVE_CONTEXT, ctx_id, COMMAND_SET, &active_ctx_id );
127 #endif
128 
129     return active_ctx_id;
130 }
131 
fw_intf_isp_get_current_ctx_id(uint32_t ctx_id)132 int fw_intf_isp_get_current_ctx_id( uint32_t ctx_id )
133 {
134     int active_ctx_id = -1;
135 
136     if ( !isp_started ) {
137         LOG( LOG_ERR, "ISP FW not inited yet" );
138         return -EBUSY;
139     }
140 
141 #if defined( TGENERAL ) && defined( ACTIVE_CONTEXT )
142     acamera_command( ctx_id, TGENERAL, ACTIVE_CONTEXT, 0, COMMAND_GET, &active_ctx_id );
143 #endif
144 
145     return active_ctx_id;
146 }
147 
fw_intf_isp_get_sensor_info(uint32_t ctx_id,isp_v4l2_sensor_info * sensor_info)148 int fw_intf_isp_get_sensor_info( uint32_t ctx_id, isp_v4l2_sensor_info *sensor_info )
149 {
150     if ( !isp_started ) {
151         LOG( LOG_ERR, "ISP FW not inited yet" );
152         return -EBUSY;
153     }
154 	FWDEBUG("");
155 #if defined( TSENSOR ) && defined( SENSOR_SUPPORTED_PRESETS ) && defined( SENSOR_INFO_PRESET ) && \
156     defined( SENSOR_INFO_FPS ) && defined( SENSOR_INFO_WIDTH ) && defined( SENSOR_INFO_HEIGHT )
157     int i, j;
158     uint32_t ret_val;
159     uint32_t preset_num;
160 
161     /* reset buffer */
162     memset( sensor_info, 0x0, sizeof( isp_v4l2_sensor_info ) );
163 
164     /* get preset size */
165     acamera_command( ctx_id, TSENSOR, SENSOR_SUPPORTED_PRESETS, 0, COMMAND_GET, &preset_num );
166     if ( preset_num > MAX_SENSOR_PRESET_SIZE ) {
167         LOG( LOG_ERR, "MAX_SENSOR_PRESET_SIZE is too small ! (preset_num = %d)", preset_num );
168         preset_num = MAX_SENSOR_PRESET_SIZE;
169     }
170 
171     /* fill preset values */
172     for ( i = 0; i < preset_num; i++ ) {
173         uint32_t width, height, fps, wdrmode, exposures = 1;
174 
175         /* get next preset */
176         acamera_command( ctx_id, TSENSOR, SENSOR_INFO_PRESET, i, COMMAND_SET, &ret_val );
177         acamera_command( ctx_id, TSENSOR, SENSOR_INFO_FPS, i, COMMAND_GET, &fps );
178         acamera_command( ctx_id, TSENSOR, SENSOR_INFO_WIDTH, i, COMMAND_GET, &width );
179         acamera_command( ctx_id, TSENSOR, SENSOR_INFO_HEIGHT, i, COMMAND_GET, &height );
180 #if defined( SENSOR_INFO_EXPOSURES )
181         acamera_command( ctx_id, TSENSOR, SENSOR_INFO_EXPOSURES, i, COMMAND_GET, &exposures );
182 #endif
183         acamera_command( ctx_id, TSENSOR, SENSOR_INFO_WDR_MODE, i, COMMAND_GET, &wdrmode );
184         /* find proper index from sensor_info */
185         for ( j = 0; j < sensor_info->preset_num; j++ ) {
186             if ( sensor_info->preset[j].width == width &&
187                  sensor_info->preset[j].height == height )
188                 break;
189         }
190 
191         /* store preset */
192         if ( sensor_info->preset[j].fps_num < MAX_SENSOR_FPS_SIZE ) {
193             sensor_info->preset[j].width = width;
194             sensor_info->preset[j].height = height;
195             sensor_info->preset[j].exposures[sensor_info->preset[j].fps_num] = exposures;
196             sensor_info->preset[j].fps[sensor_info->preset[j].fps_num] = fps;
197             sensor_info->preset[j].idx[sensor_info->preset[j].fps_num] = i;
198             sensor_info->preset[j].wdr_mode[sensor_info->preset[j].fps_num] = wdrmode;
199             sensor_info->preset[j].fps_num++;
200             if ( sensor_info->preset_num <= j )
201                 sensor_info->preset_num++;
202         } else {
203             LOG( LOG_ERR, "FPS number overflowed ! (preset#%d / index#%d)", i, j );
204         }
205     }
206     uint32_t spreset, swidth, sheight;
207     acamera_command( ctx_id, TSENSOR, SENSOR_PRESET, 0, COMMAND_GET, &spreset );
208     acamera_command( ctx_id, TSENSOR, SENSOR_WIDTH, 0, COMMAND_GET, &swidth );
209     acamera_command( ctx_id, TSENSOR, SENSOR_HEIGHT, 0, COMMAND_GET, &sheight );
210 
211     for ( i = 0; i < sensor_info->preset_num; i++ ) {
212         if ( swidth == sensor_info->preset[i].width && sheight == sensor_info->preset[i].height ) {
213             sensor_info->preset_cur = i;
214             break;
215         }
216     }
217 
218     if ( i < MAX_SENSOR_PRESET_SIZE ) {
219         for ( j = 0; j < sensor_info->preset[i].fps_num; j++ ) {
220             if ( sensor_info->preset[i].idx[j] == spreset ) {
221                 sensor_info->preset[i].fps_cur = spreset;
222                 break;
223             }
224         }
225     }
226 
227     //check current sensor settings
228     for ( i = 0; i < sensor_info->preset_num; i++ ) {
229         LOG( LOG_DEBUG, "   Idx#%02d - W:%04d H:%04d",
230              i, sensor_info->preset[i].width, sensor_info->preset[i].height );
231         for ( j = 0; j < sensor_info->preset[i].fps_num; j++ )
232             LOG( LOG_DEBUG, "            FPS#%d: %d (preset index = %d) exposures:%d  wdr_mode:%d",
233                  j, sensor_info->preset[i].fps[j] / 256, sensor_info->preset[i].idx[j],
234                  sensor_info->preset[i].exposures[j], sensor_info->preset[i].wdr_mode[j] );
235     }
236 #else
237     /* returning default setting (1080p) */
238     LOG( LOG_ERR, "API not found, initializing sensor_info to default." );
239     sensor_info->preset_num = 1;
240     sensor_info->preset[0].fps = 30 * 256;
241     sensor_info->preset[0].width = 1920;
242     sensor_info->preset[0].height = 1080;
243 #endif
244 	FWDEBUG("sensor_info {w:%d,h:%d,fps:%d,wdr_mode:%d,exposures:%d}",
245 		sensor_info->preset[0].width, sensor_info->preset[0].height,
246 		sensor_info->preset[0].fps[0],
247 		sensor_info->preset[0].wdr_mode[0],
248 		sensor_info->preset[0].exposures[0]);
249     return 0;
250 }
251 
fw_intf_isp_get_sensor_preset(uint32_t ctx_id)252 int fw_intf_isp_get_sensor_preset( uint32_t ctx_id )
253 {
254     int value = -1;
255 
256     if ( !isp_started ) {
257         LOG( LOG_ERR, "ISP FW not inited yet" );
258         return -EBUSY;
259     }
260 
261 #if defined( TSENSOR ) && defined( SENSOR_PRESET )
262     acamera_command( ctx_id, TSENSOR, SENSOR_PRESET, 0, COMMAND_GET, &value );
263 #endif
264 
265     return value;
266 }
267 
fw_intf_isp_set_sensor_preset(uint32_t ctx_id,uint32_t preset)268 int fw_intf_isp_set_sensor_preset( uint32_t ctx_id, uint32_t preset )
269 {
270     int value = -1;
271 
272     LOG( LOG_CRIT, "call fw_intf_isp_set_sensor_preset" );
273 
274     if ( !isp_started ) {
275         LOG( LOG_ERR, "ISP FW not inited yet" );
276         return -EBUSY;
277     }
278 
279 #if defined( TSENSOR ) && defined( SENSOR_PRESET )
280     acamera_command( ctx_id, TSENSOR, SENSOR_PRESET, preset, COMMAND_SET, &value );
281 #endif
282 
283     return value;
284 }
285 
286 /*
287  * fw-interface per-stream control interface
288  */
fw_intf_stream_start(uint32_t ctx_id,isp_v4l2_stream_type_t streamType)289 int fw_intf_stream_start( uint32_t ctx_id, isp_v4l2_stream_type_t streamType )
290 {
291     uint32_t rc = 0;
292 	FWDEBUG("");
293 #if ISP_DMA_RAW_CAPTURE && ISP_HAS_RAW_CB
294     if ( streamType == V4L2_STREAM_TYPE_RAW ) {
295 #if defined( TFPGA ) && defined( DMA_RAW_CAPTURE_ENABLED_ID )
296         uint32_t ret_val;
297         acamera_command( ctx_id, TFPGA, DMA_RAW_CAPTURE_ENABLED_ID, ON, COMMAND_SET, &ret_val );
298 #else
299         LOG( LOG_CRIT, "no api for DMA_RAW_CAPTURE_ENABLED_ID" );
300 #endif
301     }
302 #endif
303     if (streamType == V4L2_STREAM_TYPE_FR || streamType == V4L2_STREAM_TYPE_DS1) {
304         LOG( LOG_ERR, "Starting stream type %d", streamType );
305         acamera_command( ctx_id, TSENSOR, SENSOR_STREAMING, ON, COMMAND_SET, &rc );
306     }
307 
308 #if ISP_HAS_DS2
309     if (streamType == V4L2_STREAM_TYPE_DS2) {
310         uint32_t ret_val;
311         LOG( LOG_ERR, "Starting stream type %d", streamType );
312         acamera_command( ctx_id, TAML_SCALER, SCALER_STREAMING_ON, ON, COMMAND_SET, &ret_val );
313     }
314 #endif
315 
316     return 0;
317 }
318 
fw_intf_stream_stop(uint32_t ctx_id,isp_v4l2_stream_type_t streamType,int stream_on_count)319 void fw_intf_stream_stop( uint32_t ctx_id, isp_v4l2_stream_type_t streamType, int stream_on_count )
320 {
321 	FWDEBUG("");
322     uint32_t rc = 0;
323     LOG( LOG_DEBUG, "Stopping stream type %d", streamType );
324 #if ISP_DMA_RAW_CAPTURE && ISP_HAS_RAW_CB
325     if ( streamType == V4L2_STREAM_TYPE_RAW ) {
326 #if defined( TFPGA ) && defined( DMA_RAW_CAPTURE_ENABLED_ID )
327         uint32_t ret_val;
328         acamera_command( ctx_id, TFPGA, DMA_RAW_CAPTURE_ENABLED_ID, OFF, COMMAND_SET, &ret_val );
329 #else
330         LOG( LOG_CRIT, "no api for DMA_RAW_CAPTURE_ENABLED_ID" );
331 #endif
332     }
333 #endif
334 
335     if (streamType == V4L2_STREAM_TYPE_FR) {
336 		if(stream_on_count == 1)
337             acamera_command( ctx_id, TSENSOR, SENSOR_STREAMING, OFF, COMMAND_SET, &rc );
338         acamera_api_dma_buff_queue_reset(ctx_id, dma_fr);
339     } else if (streamType == V4L2_STREAM_TYPE_DS1) {
340 		if(stream_on_count == 1)
341 		    acamera_command( ctx_id, TSENSOR, SENSOR_STREAMING, OFF, COMMAND_SET, &rc );
342         acamera_api_dma_buff_queue_reset(ctx_id, dma_ds1);
343     }
344 
345 #if ISP_HAS_DS2
346     if (streamType == V4L2_STREAM_TYPE_DS2) {
347         uint32_t ret_val;
348         LOG( LOG_ERR, "Stopping stream type %d", streamType );
349 		if(stream_on_count == 1)
350 			acamera_command( ctx_id, TSENSOR, SENSOR_STREAMING, OFF, COMMAND_SET, &rc );
351         acamera_command( ctx_id, TAML_SCALER, SCALER_STREAMING_OFF, OFF, COMMAND_SET, &ret_val );
352     }
353 #endif
354 
355     LOG( LOG_CRIT, "Stream off %d, user: %d\n",  streamType, stream_on_count);
356 }
357 
fw_intf_stream_pause(uint32_t ctx_id,isp_v4l2_stream_type_t streamType,uint8_t bPause)358 void fw_intf_stream_pause( uint32_t ctx_id, isp_v4l2_stream_type_t streamType, uint8_t bPause )
359 {
360     LOG( LOG_DEBUG, "Pausing/Resuming stream type %d (Flag=%d", streamType, bPause );
361 
362     if ( !isp_started ) {
363         LOG( LOG_ERR, "ISP FW not inited yet" );
364         return;
365     }
366 
367 #if ISP_DMA_RAW_CAPTURE && ISP_HAS_RAW_CB
368     if ( streamType == V4L2_STREAM_TYPE_RAW ) {
369 #if defined( TFPGA ) && defined( DMA_RAW_CAPTURE_ENABLED_ID )
370         uint32_t ret_val;
371         acamera_command( ctx_id, TFPGA, DMA_RAW_CAPTURE_WRITEON_ID, ( bPause ? 0 : 1 ), COMMAND_SET, &ret_val );
372 #else
373         LOG( LOG_CRIT, "no api for DMA_RAW_CAPTURE_WRITEON_ID" );
374 #endif
375     }
376 #endif
377 
378 #if defined( TGENERAL ) && defined( DMA_WRITER_SINGLE_FRAME_MODE )
379 #if ISP_HAS_RAW_CB
380     if ( streamType == V4L2_STREAM_TYPE_RAW ) {
381         uint32_t ret_val;
382 
383         acamera_command( ctx_id, TGENERAL, DMA_WRITER_SINGLE_FRAME_MODE, bPause ? ON : OFF, COMMAND_SET, &ret_val );
384     }
385 #endif
386 #endif
387 }
388 
389 /* fw-interface sensor hw stream control interface */
fw_intf_sensor_pause(uint32_t ctx_id)390 int fw_intf_sensor_pause( uint32_t ctx_id )
391 {
392     uint32_t rc = 0;
393 
394     if ( !isp_started ) {
395         LOG( LOG_ERR, "ISP FW not inited yet" );
396         return -EBUSY;
397     }
398 
399     application_command( TSENSOR, SENSOR_STREAMING, OFF, COMMAND_SET, &rc );
400 
401     return rc;
402 }
403 
fw_intf_sensor_resume(uint32_t ctx_id)404 int fw_intf_sensor_resume( uint32_t ctx_id )
405 {
406     uint32_t rc = 0;
407 
408     if ( !isp_started ) {
409         LOG( LOG_ERR, "ISP FW not inited yet" );
410         return -EBUSY;
411     }
412 
413     application_command( TSENSOR, SENSOR_STREAMING, ON, COMMAND_SET, &rc );
414 
415     return rc;
416 }
417 
fw_intf_find_proper_present_idx(const isp_v4l2_sensor_info * sensor_info,int w,int h,uint32_t * fps)418 uint32_t fw_intf_find_proper_present_idx(const isp_v4l2_sensor_info *sensor_info, int w, int h, uint32_t* fps)
419 {
420   /* search resolution from preset table
421      *   for now, use the highest fps.
422      *   this should be changed properly in the future to pick fps from application
423      */
424     int i, j;
425     uint32_t idx = 0;
426 
427     for ( i = 0; i < sensor_info->preset_num; i++ ) {
428         if ( sensor_info->preset[i].width == w && sensor_info->preset[i].height == h ) {
429             if (custom_wdr_mode == 0) {
430                *( (char *)&sensor_info->preset[i].fps_cur ) = 0;
431                for ( j = 0; j < sensor_info->preset[i].fps_num; j++ ) {
432                    if ( sensor_info->preset[i].wdr_mode[j] == custom_wdr_mode ) {
433                        if (0 != custom_fps) {
434                            if ( sensor_info->preset[i].fps[j] == custom_fps * 256) {
435                                *fps = sensor_info->preset[i].fps[j];
436                                idx = sensor_info->preset[i].idx[j];
437                                *( (char *)&sensor_info->preset[i].fps_cur ) = j;
438                                break;
439                            }
440                        } else {
441                            if ( sensor_info->preset[i].fps[j] > (*fps)) {
442                                *fps = sensor_info->preset[i].fps[j];
443                                idx = sensor_info->preset[i].idx[j];
444                                *( (char *)&sensor_info->preset[i].fps_cur ) = j;
445                            }
446                        }
447                    }
448                }
449                break;
450             } else if ((custom_wdr_mode == 1) || (custom_wdr_mode == 2)) {
451                for (j = 0; j < sensor_info->preset[i].fps_num; j++) {
452                   if ((sensor_info->preset[i].exposures[j] == custom_exp) &&
453                      (sensor_info->preset[i].wdr_mode[j] == custom_wdr_mode)) {
454                      if (0 != custom_fps) {
455                          if ( sensor_info->preset[i].fps[j] == custom_fps * 256) {
456                              *fps = sensor_info->preset[i].fps[j];
457                              idx = sensor_info->preset[i].idx[j];
458                              *( (char *)&sensor_info->preset[i].fps_cur ) = j;
459                              break;
460                          }
461                      } else {
462                          if ( sensor_info->preset[i].fps[j] > (*fps)) {
463                              idx = sensor_info->preset[i].idx[j];
464                              *fps = sensor_info->preset[i].fps[j];
465                              *( (char *)&sensor_info->preset[i].fps_cur ) = j;
466                          }
467                      }
468                   }
469                }
470                break;
471             } else {
472                LOG( LOG_ERR, "Not Support wdr mode\n");
473             }
474         }
475     }
476 
477     if ( i >= sensor_info->preset_num ) {
478         LOG( LOG_CRIT, "invalid resolution (width = %d, height = %d)\n", w, h);
479         return -1;
480     }
481 
482     custom_wdr_mode = sensor_info->preset[i].wdr_mode[sensor_info->preset[i].fps_cur];
483     custom_exp = sensor_info->preset[i].exposures[sensor_info->preset[i].fps_cur];
484     custom_fps = sensor_info->preset[i].fps[sensor_info->preset[i].fps_cur] / 256;
485 	FWDEBUG("custom_wdr_mode:%d, custom_exp:%d, custom_fps:%d",
486 		custom_wdr_mode, custom_exp, custom_fps);
487     return idx;
488 }
489 
490 /* fw-interface per-stream config interface */
fw_intf_stream_set_resolution(uint32_t ctx_id,const isp_v4l2_sensor_info * sensor_info,isp_v4l2_stream_type_t streamType,uint32_t * width,uint32_t * height)491 int fw_intf_stream_set_resolution( uint32_t ctx_id, const isp_v4l2_sensor_info *sensor_info,
492                                    isp_v4l2_stream_type_t streamType, uint32_t *width, uint32_t *height )
493 {
494     /*
495      * StreamType
496      *   - FR : directly update sensor resolution since FR doesn't have down-scaler.
497      *   - DS : need to be implemented.
498      *   - RAW: can't be configured separately from FR.
499      */
500     if ( !isp_started ) {
501         LOG( LOG_ERR, "ISP FW not inited yet" );
502         return -EBUSY;
503     }
504 	FWDEBUG("streamType:%x, width:%d, height:%d", streamType, *width, *height);
505     LOG( LOG_DEBUG, "streamtype:%d, w:%d h:%d\n", streamType, *width, *height );
506     if ( streamType == V4L2_STREAM_TYPE_FR ) {
507 #if defined( TSENSOR ) && defined( SENSOR_PRESET )
508         int result;
509         uint32_t ret_val;
510         uint32_t idx = 0x0;
511         uint32_t fps = 0x0;
512         uint32_t w, h;
513 
514         w = *width;
515         h = *height;
516 
517         uint32_t width_cur, height_cur, exposure_cur, wdr_mode_cur, fps_cur;
518         wdr_mode_cur = 0;
519         exposure_cur = 0;
520         fps_cur = 0;
521         //check if we need to change sensor preset
522         acamera_command( ctx_id, TSENSOR, SENSOR_WIDTH, 0, COMMAND_GET, &width_cur );
523         acamera_command( ctx_id, TSENSOR, SENSOR_HEIGHT, 0, COMMAND_GET, &height_cur );
524         acamera_command( ctx_id, TSENSOR, SENSOR_EXPOSURES, 0, COMMAND_GET, &exposure_cur );
525         acamera_command( ctx_id, TSENSOR, SENSOR_WDR_MODE, 0, COMMAND_GET, &wdr_mode_cur );
526         acamera_command( ctx_id, TSENSOR, SENSOR_FPS, 0, COMMAND_GET, &fps_cur );
527         LOG( LOG_DEBUG, "target (width = %d, height = %d, fps = %d) current (w=%d h=%d exposure_cur = %d wdr_mode_cur = %d, fps = %d)",
528         w, h, custom_fps, width_cur, height_cur, exposure_cur, wdr_mode_cur, fps_cur / 256);
529 
530         if ( width_cur != w || height_cur != h || exposure_cur != custom_exp || wdr_mode_cur != custom_wdr_mode || fps_cur / 256 != custom_fps) {
531 
532             idx = fw_intf_find_proper_present_idx(sensor_info, w, h, &fps);
533 
534             /* set sensor resolution preset */
535             LOG( LOG_CRIT, "Setting new resolution : width = %d, height = %d (preset idx = %d, fps = %d)", w, h, idx, fps / 256 );
536             result = acamera_command( ctx_id, TSENSOR, SENSOR_PRESET, idx, COMMAND_SET, &ret_val );
537             *( (char *)&sensor_info->preset_cur ) = idx;
538             if ( result ) {
539                 LOG( LOG_CRIT, "Failed to set preset to %u, ret_value: %d.", idx, result );
540                 return -EINVAL;
541             }
542         } else {
543             acamera_command( ctx_id, TSENSOR, SENSOR_PRESET, 0, COMMAND_GET, &idx );
544             LOG( LOG_CRIT, "Leaving same sensor settings resolution : width = %d, height = %d (preset idx = %d)", w, h, idx );
545         }
546 #endif
547     }
548 #if ISP_HAS_DS1
549     else if ( streamType == V4L2_STREAM_TYPE_DS1 ) {
550 
551         int result;
552         uint32_t ret_val;
553         uint32_t w, h;
554 
555         w = *width;
556         h = *height;
557 
558         uint32_t width_cur, height_cur;
559         //check if we need to change sensor preset
560         acamera_command( ctx_id, TSENSOR, SENSOR_WIDTH, 0, COMMAND_GET, &width_cur );
561         acamera_command( ctx_id, TSENSOR, SENSOR_HEIGHT, 0, COMMAND_GET, &height_cur );
562         if ( w > width_cur || h > height_cur ) {
563             LOG( LOG_ERR, "Invalid target size: (width = %d, height = %d), current (w=%d h=%d)", w, h, width_cur, height_cur );
564             return -EINVAL;
565         }
566 
567 #if defined( TIMAGE ) && defined( IMAGE_RESIZE_TYPE_ID ) && defined( IMAGE_RESIZE_WIDTH_ID )
568         {
569             result = acamera_command( ctx_id, TIMAGE, IMAGE_RESIZE_TYPE_ID, SCALER, COMMAND_SET, &ret_val );
570             if ( result ) {
571                 LOG( LOG_CRIT, "Failed to set resize_type, ret_value: %d.", result );
572                 return result;
573             }
574 
575             result = acamera_command( ctx_id, TIMAGE, IMAGE_RESIZE_WIDTH_ID, w, COMMAND_SET, &ret_val );
576             if ( result ) {
577                 LOG( LOG_CRIT, "Failed to set resize_width, ret_value: %d.", result );
578                 return result;
579             }
580             result = acamera_command( ctx_id, TIMAGE, IMAGE_RESIZE_HEIGHT_ID, h, COMMAND_SET, &ret_val );
581             if ( result ) {
582                 LOG( LOG_CRIT, "Failed to set resize_height, ret_value: %d.", result );
583                 return result;
584             }
585 
586             result = acamera_command( ctx_id, TIMAGE, IMAGE_RESIZE_ENABLE_ID, RUN, COMMAND_SET, &ret_val );
587             if ( result ) {
588                 LOG( LOG_CRIT, "Failed to set resize_enable, ret_value: %d.", result );
589                 return result;
590             }
591         }
592 #endif
593     }
594 #endif
595 
596 #if ISP_HAS_DS2
597     else if ( streamType == V4L2_STREAM_TYPE_DS2 ) {
598 
599         uint32_t ret_val;
600         uint32_t w, h;
601 
602         w = *width;
603         h = *height;
604 
605         uint32_t width_cur, height_cur;
606         //check if we need to change sensor preset
607         acamera_command( ctx_id, TAML_SCALER, SCALER_WIDTH, 0, COMMAND_GET, &width_cur );
608         acamera_command( ctx_id, TAML_SCALER, SCALER_HEIGHT, 0, COMMAND_GET, &height_cur );
609         LOG( LOG_ERR, "target (width = %d, height = %d) current (w=%d h=%d)", w, h, width_cur, height_cur );
610         if ( w != width_cur || h != height_cur ) {
611             acamera_command(ctx_id, TAML_SCALER, SCALER_WIDTH, w, COMMAND_SET, &ret_val );
612             acamera_command(ctx_id,  TAML_SCALER, SCALER_HEIGHT, h, COMMAND_SET, &ret_val );
613         } else {
614             LOG(LOG_ERR, "target resolution equal current resolution");
615         }
616     }
617 #endif
618 
619     return 0;
620 }
621 
fw_intf_stream_set_output_format(uint32_t ctx_id,isp_v4l2_stream_type_t streamType,uint32_t format)622 int fw_intf_stream_set_output_format( uint32_t ctx_id, isp_v4l2_stream_type_t streamType, uint32_t format )
623 {
624 	FWDEBUG("streamType:%x", streamType);
625 #if defined( TIMAGE ) && defined( FR_FORMAT_BASE_PLANE_ID )
626     uint32_t value;
627 
628     if ( !isp_started ) {
629         LOG( LOG_ERR, "ISP FW not inited yet" );
630         return -EBUSY;
631     }
632 
633     switch ( format ) {
634 #ifdef DMA_FORMAT_RGB32
635     case V4L2_PIX_FMT_RGB32:
636         value = RGB32;
637         break;
638 #endif
639 #ifdef DMA_FORMAT_NV12_Y
640     case V4L2_PIX_FMT_NV12:
641         value = NV12_YUV;
642         break;
643     case V4L2_PIX_FMT_GREY:
644         value = NV12_GREY;
645         break;
646     case V4L2_PIX_FMT_NV21:
647         value = NV12_YVU;
648         break;
649 #endif
650 #ifdef DMA_FORMAT_A2R10G10B10
651     case ISP_V4L2_PIX_FMT_ARGB2101010:
652         value = A2R10G10B10;
653         break;
654 #endif
655 #ifdef DMA_FORMAT_RGB24
656     case V4L2_PIX_FMT_RGB24:
657         value = RGB24;
658         break;
659 #endif
660 #ifdef DMA_FORMAT_AYUV
661     case V4L2_PIX_FMT_YUV444:
662         value = AYUV;
663         break;
664 #endif
665 #ifdef DMA_FORMAT_YUY2
666     case V4L2_PIX_FMT_YUYV:
667         value = YUY2;
668         break;
669 #endif
670 #ifdef DMA_FORMAT_UYVY
671     case V4L2_PIX_FMT_UYVY:
672         value = UYVY;
673         break;
674 #endif
675 #ifdef DMA_FORMAT_RAW16
676     case V4L2_PIX_FMT_SBGGR16:
677         value = RAW16;
678         break;
679 #endif
680 #ifdef DMA_FORMAT_DISABLE
681     case ISP_V4L2_PIX_FMT_NULL:
682         value = DMA_DISABLE;
683         break;
684 #endif
685     case ISP_V4L2_PIX_FMT_META:
686         LOG( LOG_INFO, "Meta format 0x%x doesn't need to be set to firmware", format );
687         return 0;
688         break;
689     default:
690         LOG( LOG_ERR, "Requested format 0x%x is not supported by firmware !", format );
691         return -1;
692         break;
693     }
694 
695     if ( streamType == V4L2_STREAM_TYPE_FR ) {
696 
697         uint8_t result;
698         uint32_t ret_val;
699 
700         result = acamera_command( ctx_id, TIMAGE, FR_FORMAT_BASE_PLANE_ID, value, COMMAND_SET, &ret_val );
701         if ( result ) {
702             LOG( LOG_ERR, "TIMAGE - FR_FORMAT_BASE_PLANE_ID failed (value = 0x%x, result = %d)", value, result );
703         }
704     }
705 #if ISP_HAS_DS1
706     else if ( streamType == V4L2_STREAM_TYPE_DS1 ) {
707 
708         uint8_t result;
709         uint32_t ret_val;
710 
711         result = acamera_command( ctx_id, TIMAGE, DS1_FORMAT_BASE_PLANE_ID, value, COMMAND_SET, &ret_val );
712         if ( result ) {
713             LOG( LOG_ERR, "TIMAGE - DS1_FORMAT_BASE_PLANE_ID failed (value = 0x%x, result = %d)", value, result );
714         }
715     }
716 #endif
717 
718 #if ISP_HAS_DS2
719     else if ( streamType == V4L2_STREAM_TYPE_DS2 ) {
720 
721         uint8_t result;
722         uint32_t ret_val;
723 
724         result = acamera_command( ctx_id, TAML_SCALER, SCALER_OUTPUT_MODE, value, COMMAND_SET, &ret_val );
725         LOG( LOG_ERR, "set format for stream %d to %d (0x%x)", streamType, value, format );
726         if ( result ) {
727             LOG( LOG_ERR, "TIMAGE - DS2_FORMAT_BASE_PLANE_ID failed (value = 0x%x, result = %d)", value, result );
728         }
729     }
730 #endif
731 
732 #else
733     LOG( LOG_ERR, "cannot find proper API for fr base mode ID" );
734 #endif
735 
736 
737     return 0;
738 }
739 
fw_intf_set_fr_fps(uint32_t ctx_id,uint32_t fps)740 static int fw_intf_set_fr_fps(uint32_t ctx_id, uint32_t fps)
741 {
742     uint32_t cur_fps = 0;
743 	FWDEBUG("fps:%d", fps);
744     acamera_command(ctx_id, TSENSOR, SENSOR_FPS, 0, COMMAND_GET, &cur_fps);
745     if (cur_fps == 0) {
746         LOG(LOG_ERR, "Error input param\n");
747         return -1;
748     }
749 
750     cur_fps = cur_fps / 256;
751 
752     acamera_api_set_fps(ctx_id, dma_fr, cur_fps, fps);
753 
754     return 0;
755 }
756 
fw_intf_set_sensor_testpattern(uint32_t ctx_id,uint32_t val)757 static int fw_intf_set_sensor_testpattern(uint32_t ctx_id, uint32_t val)
758 {
759     uint32_t mode = val;
760     uint32_t ret_val;
761     acamera_command(ctx_id, TSENSOR, SENSOR_TESTPATTERN, mode, COMMAND_SET, &ret_val);
762     if (mode <= 0) {
763         LOG(LOG_ERR, "Error input param\n");
764         return -1;
765     }
766     return 0;
767 }
768 
fw_intf_set_sensor_ir_cut_set(uint32_t ctx_id,uint32_t ctrl_val)769 static int fw_intf_set_sensor_ir_cut_set(uint32_t ctx_id, uint32_t ctrl_val)
770 {
771     uint32_t ir_cut_state = ctrl_val;
772 	FWDEBUG("ctrl_val:%d", ctrl_val);
773     acamera_command(ctx_id, TSENSOR, SENSOR_IR_CUT, 0, COMMAND_SET, &ir_cut_state);
774     return 0;
775 }
776 
fw_intf_set_ds1_fps(uint32_t ctx_id,uint32_t fps)777 static int fw_intf_set_ds1_fps(uint32_t ctx_id, uint32_t fps)
778 {
779     uint32_t cur_fps = 0;
780 	FWDEBUG("");
781     acamera_command(ctx_id, TSENSOR, SENSOR_FPS, 0, COMMAND_GET, &cur_fps);
782     if (cur_fps == 0) {
783         LOG(LOG_ERR, "Error input param\n");
784         return -1;
785     }
786 
787     cur_fps = cur_fps / 256;
788 
789     acamera_api_set_fps(ctx_id, dma_ds1, cur_fps, fps);
790 
791     return 0;
792 }
793 
794 
fw_intf_set_ae_zone_weight(uint32_t ctx_id,unsigned long ctrl_val)795 static int fw_intf_set_ae_zone_weight(uint32_t ctx_id, unsigned long ctrl_val)
796 {
797 	FWDEBUG("");
798     acamera_command(ctx_id, TALGORITHMS, AE_ZONE_WEIGHT, 0, COMMAND_SET, (uint32_t *)ctrl_val);
799 
800     return 0;
801 }
802 
fw_intf_set_awb_zone_weight(uint32_t ctx_id,unsigned long ctrl_val)803 static int fw_intf_set_awb_zone_weight(uint32_t ctx_id, unsigned long ctrl_val)
804 {
805     acamera_command(ctx_id, TALGORITHMS, AWB_ZONE_WEIGHT, 0, COMMAND_SET, (uint32_t *)ctrl_val);
806 
807     return 0;
808 }
809 
fw_intf_set_sensor_integration_time(uint32_t ctx_id,uint32_t ctrl_val)810 static int fw_intf_set_sensor_integration_time(uint32_t ctx_id, uint32_t ctrl_val)
811 {
812 	FWDEBUG("");
813     uint32_t manual_sensor_integration_time = ctrl_val;
814     acamera_command(ctx_id, TSYSTEM, SYSTEM_INTEGRATION_TIME, manual_sensor_integration_time, COMMAND_SET, &ctrl_val );
815 
816     return 0;
817 }
818 
fw_intf_set_sensor_analog_gain(uint32_t ctx_id,uint32_t ctrl_val)819 static int fw_intf_set_sensor_analog_gain(uint32_t ctx_id, uint32_t ctrl_val)
820 {
821 	FWDEBUG("");
822     uint32_t manual_sensor_analog_gain = ctrl_val;
823     acamera_command(ctx_id, TSYSTEM, SYSTEM_SENSOR_ANALOG_GAIN, manual_sensor_analog_gain, COMMAND_SET, &ctrl_val );
824 
825     return 0;
826 }
827 
fw_intf_set_isp_digital_gain(uint32_t ctx_id,uint32_t ctrl_val)828 static int fw_intf_set_isp_digital_gain(uint32_t ctx_id, uint32_t ctrl_val)
829 {
830     uint32_t manual_isp_digital_gain = ctrl_val;
831     acamera_command(ctx_id, TSYSTEM, SYSTEM_ISP_DIGITAL_GAIN, manual_isp_digital_gain, COMMAND_SET, &ctrl_val );
832 
833     return 0;
834 }
835 
fw_intf_set_stop_sensor_update(uint32_t ctx_id,uint32_t ctrl_val)836 static int fw_intf_set_stop_sensor_update(uint32_t ctx_id, uint32_t ctrl_val)
837 {
838     uint32_t stop_sensor_update = ctrl_val;
839     LOG(LOG_ERR, "stop_sensor_update = %d\n", stop_sensor_update);
840     acamera_command(ctx_id, TSYSTEM, SYSTEM_FREEZE_FIRMWARE, stop_sensor_update, COMMAND_SET, &ctrl_val);
841     return 0;
842 }
843 
fw_intf_set_sensor_digital_gain(uint32_t ctx_id,uint32_t ctrl_val)844 static int fw_intf_set_sensor_digital_gain(uint32_t ctx_id, uint32_t ctrl_val)
845 {
846 	FWDEBUG("");
847     uint32_t manual_sensor_digital_gain = ctrl_val;
848     acamera_command(ctx_id, TSYSTEM, SYSTEM_SENSOR_DIGITAL_GAIN, manual_sensor_digital_gain, COMMAND_SET, &ctrl_val );
849 
850     return 0;
851 }
852 
fw_intf_set_awb_red_gain(uint32_t ctx_id,uint32_t ctrl_val)853 static int fw_intf_set_awb_red_gain(uint32_t ctx_id, uint32_t ctrl_val)
854 {
855 	FWDEBUG("");
856     uint32_t awb_red_gain = ctrl_val;
857     acamera_command(ctx_id, TSYSTEM, SYSTEM_AWB_RED_GAIN, awb_red_gain, COMMAND_SET, &ctrl_val );
858 
859     return 0;
860 }
861 
fw_intf_set_awb_blue_gain(uint32_t ctx_id,uint32_t ctrl_val)862 static int fw_intf_set_awb_blue_gain(uint32_t ctx_id, uint32_t ctrl_val)
863 {
864 	FWDEBUG("CALL fw_intf_set_awb_blue_gain ctrl_val = %d", ctrl_val);
865     uint32_t awb_blue_gain = ctrl_val;
866     acamera_command(ctx_id, TSYSTEM, SYSTEM_AWB_BLUE_GAIN, awb_blue_gain, COMMAND_SET, &ctrl_val );
867 
868     return 0;
869 }
870 
871 /* ----------------------------------------------------------------
872  * Internal handler for control interface functions
873  */
isp_fw_do_validate_control(uint32_t id)874 static bool isp_fw_do_validate_control( uint32_t id )
875 {
876     return 1;
877 }
878 
isp_fw_do_set_test_pattern(uint32_t ctx_id,int enable)879 static int isp_fw_do_set_test_pattern( uint32_t ctx_id, int enable )
880 {
881 #if defined( TSYSTEM ) && defined( TEST_PATTERN_ENABLE_ID )
882     int result;
883     uint32_t ret_val;
884 
885     LOG( LOG_CRIT, "test_pattern: %d.", enable );
886 
887     if ( enable < 0 )
888         return -EIO;
889 
890     if ( !isp_started ) {
891         LOG( LOG_CRIT, "ISP FW not inited yet" );
892         return -EBUSY;
893     }
894 
895     result = application_command( TSYSTEM, TEST_PATTERN_ENABLE_ID, enable ? ON : OFF, COMMAND_SET, &ret_val );
896     if ( result ) {
897         LOG( LOG_CRIT, "Failed to set TEST_PATTERN_ENABLE_ID to %u, ret_value: %d.", enable, result );
898         return result;
899     }
900 #endif
901 
902     return 0;
903 }
904 
isp_fw_do_set_test_pattern_type(uint32_t ctx_id,int pattern_type)905 static int isp_fw_do_set_test_pattern_type( uint32_t ctx_id, int pattern_type )
906 {
907 #if defined( TSYSTEM ) && defined( TEST_PATTERN_MODE_ID )
908     int result;
909     uint32_t ret_val;
910 
911     if ( !isp_started ) {
912         LOG( LOG_ERR, "ISP FW not inited yet" );
913         return -EBUSY;
914     }
915 
916     result = acamera_command( ctx_id, TSYSTEM, TEST_PATTERN_MODE_ID, pattern_type, COMMAND_SET, &ret_val );
917     if ( result ) {
918         LOG( LOG_ERR, "Failed to set TEST_PATTERN_MODE_ID to %d, ret_value: %d.", pattern_type, result );
919         return result;
920     }
921 #endif
922 
923     return 0;
924 }
925 
926 
isp_fw_do_set_af_refocus(uint32_t ctx_id,int val)927 static int isp_fw_do_set_af_refocus( uint32_t ctx_id, int val )
928 {
929 #if defined( TALGORITHMS ) && defined( AF_MODE_ID )
930     int result;
931     u32 ret_val;
932 
933     result = acamera_command( ctx_id, TALGORITHMS, AF_MODE_ID, AF_AUTO_SINGLE, COMMAND_SET, &ret_val );
934     if ( result ) {
935         LOG( LOG_ERR, "Failed to set AF_MODE_ID to AF_AUTO_SINGLE, ret_value: %u.", ret_val );
936         return result;
937     }
938 #endif
939 
940     return 0;
941 }
942 
isp_fw_do_set_af_roi(uint32_t ctx_id,int val)943 static int isp_fw_do_set_af_roi( uint32_t ctx_id, int val )
944 {
945 #if defined( TALGORITHMS ) && defined( AF_ROI_ID )
946     int result;
947     u32 ret_val;
948 
949     result = acamera_command( ctx_id, TALGORITHMS, AF_ROI_ID, (uint32_t)val, COMMAND_SET, &ret_val );
950     if ( result ) {
951         LOG( LOG_ERR, "Failed to set AF_MODE_ID to AF_AUTO_SINGLE, ret_value: %u.", ret_val );
952         return result;
953     }
954 #endif
955 
956     return 0;
957 }
958 
isp_fw_do_set_brightness(uint32_t ctx_id,int brightness)959 static int isp_fw_do_set_brightness( uint32_t ctx_id, int brightness )
960 {
961 	FWDEBUG("brightness:%d",brightness);
962 #if defined( TSCENE_MODES ) && defined( BRIGHTNESS_STRENGTH_ID )
963     int result;
964     uint32_t ret_val;
965 
966     /* some controls(such brightness) will call acamera_command()
967      * before isp_fw initialed, so we need to check.
968      */
969     if ( !isp_started ) {
970         LOG( LOG_ERR, "ISP FW not inited yet" );
971         return -EBUSY;
972     }
973 
974     result = acamera_command( ctx_id, TSCENE_MODES, BRIGHTNESS_STRENGTH_ID, brightness, COMMAND_SET, &ret_val );
975     if ( result ) {
976         LOG( LOG_ERR, "Failed to set BRIGHTNESS_STRENGTH_ID to %d, ret_value: %d.", brightness, result );
977         return result;
978     }
979 #endif
980 
981     return 0;
982 }
983 
isp_fw_do_set_contrast(uint32_t ctx_id,int contrast)984 static int isp_fw_do_set_contrast( uint32_t ctx_id, int contrast )
985 {
986 	FWDEBUG("contrast:%d",contrast);
987 #if defined( TSCENE_MODES ) && defined( CONTRAST_STRENGTH_ID )
988     int result;
989     uint32_t ret_val;
990 
991     /* some controls(such brightness) will call acamera_command()
992      * before isp_fw initialed, so we need to check.
993      */
994     if ( !isp_started ) {
995         LOG( LOG_ERR, "ISP FW not inited yet" );
996         return -EBUSY;
997     }
998 
999     result = acamera_command( ctx_id, TSCENE_MODES, CONTRAST_STRENGTH_ID, contrast, COMMAND_SET, &ret_val );
1000     if ( result ) {
1001         LOG( LOG_ERR, "Failed to set CONTRAST_STRENGTH_ID to %d, ret_value: %d.", contrast, result );
1002         return result;
1003     }
1004 #endif
1005 
1006     return 0;
1007 }
1008 
isp_fw_do_set_saturation(uint32_t ctx_id,int saturation)1009 static int isp_fw_do_set_saturation( uint32_t ctx_id, int saturation )
1010 {
1011 	FWDEBUG("saturation:%d",saturation);
1012 #if defined( TSCENE_MODES ) && defined( SATURATION_STRENGTH_ID )
1013     int result;
1014     uint32_t ret_val;
1015 
1016     /* some controls(such brightness) will call acamera_command()
1017      * before isp_fw initialed, so we need to check.
1018      */
1019     if ( !isp_started ) {
1020         LOG( LOG_ERR, "ISP FW not inited yet" );
1021         return -EBUSY;
1022     }
1023 
1024     result = acamera_command( ctx_id, TSCENE_MODES, SATURATION_STRENGTH_ID, saturation, COMMAND_SET, &ret_val );
1025     if ( result ) {
1026         LOG( LOG_ERR, "Failed to set SATURATION_STRENGTH_ID to %d, ret_value: %d.", saturation, result );
1027         return result;
1028     }
1029 #endif
1030 
1031     return 0;
1032 }
1033 
isp_fw_do_set_hue(uint32_t ctx_id,int hue)1034 static int isp_fw_do_set_hue( uint32_t ctx_id, int hue )
1035 {
1036 	FWDEBUG("hue:%d",hue);
1037 #if defined( TSCENE_MODES ) && defined( HUE_THETA_ID )
1038     int result;
1039     uint32_t ret_val;
1040 
1041     /* some controls(such brightness) will call acamera_command()
1042      * before isp_fw initialed, so we need to check.
1043      */
1044     if ( !isp_started ) {
1045         LOG( LOG_ERR, "ISP FW not inited yet" );
1046         return -EBUSY;
1047     }
1048 
1049     result = acamera_command( ctx_id, TSCENE_MODES, HUE_THETA_ID, hue, COMMAND_SET, &ret_val );
1050     if ( result ) {
1051         LOG( LOG_ERR, "Failed to set HUE_THETA_ID to %d, ret_value: %d.", hue, result );
1052         return result;
1053     }
1054 #endif
1055 
1056     return 0;
1057 }
1058 
isp_fw_do_set_sharpness(uint32_t ctx_id,int sharpness)1059 static int isp_fw_do_set_sharpness( uint32_t ctx_id, int sharpness )
1060 {
1061 	FWDEBUG("sharpness:%d",sharpness);
1062 #if defined( TSCENE_MODES ) && defined( SHARPENING_STRENGTH_ID )
1063     int result;
1064     uint32_t ret_val;
1065 
1066     /* some controls(such brightness) will call acamera_command()
1067      * before isp_fw initialed, so we need to check.
1068      */
1069     if ( !isp_started ) {
1070         LOG( LOG_ERR, "ISP FW not inited yet" );
1071         return -EBUSY;
1072     }
1073 
1074     result = acamera_command( ctx_id, TSCENE_MODES, SHARPENING_STRENGTH_ID, sharpness, COMMAND_SET, &ret_val );
1075     if ( result ) {
1076         LOG( LOG_ERR, "Failed to set SHARPENING_STRENGTH_ID to %d, ret_value: %d.", sharpness, result );
1077         return result;
1078     }
1079 #endif
1080 
1081     return 0;
1082 }
1083 
isp_fw_do_set_color_fx(uint32_t ctx_id,int idx)1084 static int isp_fw_do_set_color_fx( uint32_t ctx_id, int idx )
1085 {
1086 	FWDEBUG("idx:%d",idx);
1087 #if defined( TSCENE_MODES ) && defined( COLOR_MODE_ID )
1088     int result;
1089     uint32_t ret_val;
1090     int color_idx;
1091 
1092     switch ( idx ) {
1093     case V4L2_COLORFX_NONE:
1094         color_idx = NORMAL;
1095         break;
1096     case V4L2_COLORFX_BW:
1097         color_idx = BLACK_AND_WHITE;
1098         break;
1099     case V4L2_COLORFX_SEPIA:
1100         color_idx = SEPIA;
1101         break;
1102     case V4L2_COLORFX_NEGATIVE:
1103         color_idx = NEGATIVE;
1104         break;
1105     case V4L2_COLORFX_VIVID:
1106         color_idx = VIVID;
1107         break;
1108     default:
1109         return -EINVAL;
1110         break;
1111     }
1112 
1113     /* some controls(such brightness) will call acamera_command()
1114      * before isp_fw initialed, so we need to check.
1115      */
1116     if ( !isp_started ) {
1117         LOG( LOG_ERR, "ISP FW not inited yet" );
1118         return -EBUSY;
1119     }
1120 
1121     result = acamera_command( ctx_id, TSCENE_MODES, COLOR_MODE_ID, color_idx, COMMAND_SET, &ret_val );
1122     if ( result ) {
1123         LOG( LOG_ERR, "Failed to set SYSTEM_ISP_DIGITAL_GAIN to %d, ret_value: %d.", color_idx, result );
1124         return result;
1125     }
1126 #endif
1127 
1128     return 0;
1129 }
1130 
isp_fw_do_set_hflip(uint32_t ctx_id,bool enable)1131 static int isp_fw_do_set_hflip( uint32_t ctx_id, bool enable )
1132 {
1133 	FWDEBUG("enable:%d",enable);
1134 #if defined( TIMAGE ) && defined( ORIENTATION_HFLIP_ID )
1135     int result;
1136     uint32_t ret_val;
1137 
1138     /* some controls(such brightness) will call acamera_command()
1139      * before isp_fw initialed, so we need to check.
1140      */
1141     if ( !isp_started ) {
1142         LOG( LOG_ERR, "ISP FW not inited yet" );
1143         return -EBUSY;
1144     }
1145 
1146     result = acamera_command( ctx_id, TIMAGE, ORIENTATION_HFLIP_ID, enable ? ENABLE : DISABLE, COMMAND_SET, &ret_val );
1147     if ( result ) {
1148         LOG( LOG_ERR, "Failed to set ORIENTATION_HFLIP_ID to %d, ret_value: %d.", enable, result );
1149         return result;
1150     }
1151 #endif
1152 
1153     return 0;
1154 }
1155 
isp_fw_do_set_vflip(uint32_t ctx_id,bool enable)1156 static int isp_fw_do_set_vflip( uint32_t ctx_id, bool enable )
1157 {
1158 	FWDEBUG("enable:%d",enable);
1159 #if defined( TIMAGE ) && defined( ORIENTATION_VFLIP_ID )
1160     int result;
1161     uint32_t ret_val;
1162 
1163     /* some controls(such brightness) will call acamera_command()
1164      * before isp_fw initialed, so we need to check.
1165      */
1166     if ( !isp_started ) {
1167         LOG( LOG_ERR, "ISP FW not inited yet" );
1168         return -EBUSY;
1169     }
1170 
1171     result = acamera_command( ctx_id, TIMAGE, ORIENTATION_VFLIP_ID, enable ? ENABLE : DISABLE, COMMAND_SET, &ret_val );
1172     if ( result ) {
1173         LOG( LOG_ERR, "Failed to set ORIENTATION_VFLIP_ID to %d, ret_value: %d.", enable, result );
1174         return result;
1175     }
1176 #endif
1177 
1178     return 0;
1179 }
1180 
isp_fw_do_set_manual_gain(uint32_t ctx_id,bool enable)1181 static int isp_fw_do_set_manual_gain( uint32_t ctx_id, bool enable )
1182 {
1183 	FWDEBUG("enable:%d",enable);
1184 #if defined( TALGORITHMS ) && defined( AE_MODE_ID )
1185     int result;
1186     uint32_t mode = 0;
1187     uint32_t ret_val;
1188 
1189     /* some controls(such brightness) will call acamera_command()
1190      * before isp_fw initialed, so we need to check.
1191      */
1192     if ( !isp_started ) {
1193         LOG( LOG_ERR, "ISP FW not inited yet" );
1194         return -EBUSY;
1195     }
1196 
1197     result = acamera_command( ctx_id, TALGORITHMS, AE_MODE_ID, 0, COMMAND_GET, &ret_val );
1198     if ( enable ) {
1199         if ( ret_val == AE_AUTO ) {
1200             mode = AE_MANUAL_GAIN;
1201         } else if ( ret_val == AE_MANUAL_EXPOSURE_TIME ) {
1202             mode = AE_FULL_MANUAL;
1203         } else {
1204             LOG( LOG_DEBUG, "Manual gain is already enabled." );
1205             return 0;
1206         }
1207     } else {
1208         if ( ret_val == AE_MANUAL_GAIN ) {
1209             mode = AE_AUTO;
1210         } else if ( ret_val == AE_FULL_MANUAL ) {
1211             mode = AE_MANUAL_EXPOSURE_TIME;
1212         } else {
1213             LOG( LOG_DEBUG, "Manual gain is already disabled." );
1214             return 0;
1215         }
1216     }
1217 
1218     result = acamera_command( ctx_id, TALGORITHMS, AE_MODE_ID, mode, COMMAND_SET, &ret_val );
1219     if ( result ) {
1220         LOG( LOG_ERR, "Failed to set AE_MODE_ID to %u, ret_value: %d.", mode, result );
1221         return result;
1222     }
1223 #endif
1224 
1225     return 0;
1226 }
1227 
isp_fw_do_set_gain(uint32_t ctx_id,int gain)1228 static int isp_fw_do_set_gain( uint32_t ctx_id, int gain )
1229 {
1230 	FWDEBUG("gain:%d",gain);
1231 #if defined( TALGORITHMS ) && defined( AE_GAIN_ID )
1232     int result;
1233     int gain_frac;
1234     uint32_t ret_val;
1235 
1236     /* some controls(such brightness) will call acamera_command()
1237      * before isp_fw initialed, so we need to check.
1238      */
1239     if ( !isp_started ) {
1240         LOG( LOG_ERR, "ISP FW not inited yet" );
1241         return -EBUSY;
1242     }
1243 
1244     result = acamera_command( ctx_id, TALGORITHMS, AE_MODE_ID, 0, COMMAND_GET, &ret_val );
1245     if ( ret_val != AE_FULL_MANUAL && ret_val != AE_MANUAL_GAIN ) {
1246         LOG( LOG_ERR, "Cannot set gain while AE_MODE is %d", ret_val );
1247         return 0;
1248     }
1249 
1250     gain_frac = gain / 100;
1251     gain_frac += ( gain % 100 ) * 256 / 100;
1252 
1253     result = acamera_command( ctx_id, TALGORITHMS, AE_GAIN_ID, gain_frac, COMMAND_SET, &ret_val );
1254     if ( result ) {
1255         LOG( LOG_ERR, "Failed to set AE_GAIN_ID to %d, ret_value: %d.", gain, result );
1256         return result;
1257     }
1258 #endif
1259 
1260     return 0;
1261 }
1262 
isp_fw_do_set_exposure_auto(uint32_t ctx_id,int enable)1263 static int isp_fw_do_set_exposure_auto( uint32_t ctx_id, int enable )
1264 {
1265 #ifdef HDF_CAMERA_XTS_ON
1266     hdf_xts_exposure_auto = enable;
1267     return 0;
1268 #endif
1269 
1270 #if defined( TALGORITHMS ) && defined( AE_MODE_ID )
1271     int result;
1272     uint32_t mode = 0;
1273     uint32_t ret_val;
1274 
1275     /* some controls(such brightness) will call acamera_command()
1276      * before isp_fw initialed, so we need to check.
1277      */
1278     if ( !isp_started ) {
1279         LOG( LOG_ERR, "ISP FW not inited yet" );
1280         return -EBUSY;
1281     }
1282 
1283     result = acamera_command( ctx_id, TALGORITHMS, AE_MODE_ID, 0, COMMAND_GET, &ret_val );
1284     switch ( enable ) {
1285     case true:
1286         if ( ret_val == AE_AUTO ) {
1287             mode = AE_MANUAL_EXPOSURE_TIME;
1288         } else if ( ret_val == AE_MANUAL_GAIN ) {
1289             mode = AE_FULL_MANUAL;
1290         } else {
1291             LOG( LOG_DEBUG, "Manual exposure is already enabled." );
1292             return 0;
1293         }
1294         break;
1295     case false:
1296         if ( ret_val == AE_MANUAL_EXPOSURE_TIME ) {
1297             mode = AE_AUTO;
1298         } else if ( ret_val == AE_FULL_MANUAL ) {
1299             mode = AE_MANUAL_GAIN;
1300         } else {
1301             LOG( LOG_DEBUG, "Manual exposure is already disabled." );
1302             return 0;
1303         }
1304         break;
1305     }
1306 
1307     result = acamera_command( ctx_id, TALGORITHMS, AE_MODE_ID, mode, COMMAND_SET, &ret_val );
1308     if ( result ) {
1309         LOG( LOG_ERR, "Failed to set AE_MODE_ID to %u, ret_value: %d.", mode, result );
1310         return result;
1311     }
1312 #endif
1313 
1314     return 0;
1315 }
1316 
isp_fw_do_get_exposure_auto(uint32_t ctx_id)1317 static int isp_fw_do_get_exposure_auto( uint32_t ctx_id)
1318 {
1319 #ifdef HDF_CAMERA_XTS_ON
1320     return hdf_xts_exposure_auto;
1321 #endif
1322 
1323 #if defined( TALGORITHMS ) && defined( AE_MODE_ID )
1324     int result;
1325     int32_t mode = 0;
1326     uint32_t ret_val;
1327 
1328     /* some controls(such brightness) will call acamera_command()
1329      * before isp_fw initialed, so we need to check.
1330      */
1331     if ( !isp_started ) {
1332         LOG( LOG_ERR, "ISP FW not inited yet" );
1333         return -EBUSY;
1334     }
1335 
1336     result = acamera_command( ctx_id, TALGORITHMS, AE_MODE_ID, 0, COMMAND_GET, &ret_val );
1337     if ( result ) {
1338         LOG( LOG_ERR, "Failed to get AE_MODE_ID ret_value: %d.", result );
1339         return result;
1340     }
1341 
1342     if ( ret_val == AE_AUTO ) {
1343         mode = AE_MANUAL_EXPOSURE_TIME;
1344     } else if ( ret_val == AE_MANUAL_GAIN ) {
1345         mode = AE_FULL_MANUAL;
1346     } else {
1347         LOG( LOG_DEBUG, "Manual exposure is already enabled." );
1348         return 0;
1349     }
1350 #endif
1351 
1352     return mode;
1353 }
1354 
isp_fw_do_set_manual_exposure(uint32_t ctx_id,int enable)1355 static int isp_fw_do_set_manual_exposure( uint32_t ctx_id, int enable )
1356 {
1357 #if defined( TALGORITHMS ) && defined( AE_MODE_ID )
1358     int result_integration_time, result_sensor_analog_gain, result_sensor_digital_gain, result_isp_digital_gain;
1359     uint32_t ret_val;
1360 
1361     LOG( LOG_ERR, "manual exposure enable: %d.", enable );
1362 
1363     /* some controls(such brightness) will call acamera_command()
1364      * before isp_fw initialed, so we need to check.
1365      */
1366     if ( !isp_started ) {
1367         LOG( LOG_ERR, "ISP FW not inited yet" );
1368         return -EBUSY;
1369     }
1370 
1371     result_integration_time = acamera_command( ctx_id, TSYSTEM, SYSTEM_MANUAL_INTEGRATION_TIME, enable, COMMAND_SET, &ret_val );
1372     if ( result_integration_time ) {
1373         LOG( LOG_ERR, "Failed to set manual_integration_time to manual mode, ret_value: %d", result_integration_time );
1374         return ( result_integration_time );
1375     }
1376 
1377     result_sensor_analog_gain = acamera_command( ctx_id, TSYSTEM, SYSTEM_MANUAL_SENSOR_ANALOG_GAIN, enable, COMMAND_SET, &ret_val );
1378     if ( result_sensor_analog_gain ) {
1379         LOG( LOG_ERR, "Failed to set manual_sensor_analog_gain to manual mode, ret_value: %d", result_sensor_analog_gain );
1380         return ( result_sensor_analog_gain );
1381     }
1382 
1383     result_sensor_digital_gain = acamera_command( ctx_id, TSYSTEM, SYSTEM_MANUAL_SENSOR_DIGITAL_GAIN, enable, COMMAND_SET, &ret_val );
1384     if ( result_sensor_analog_gain ) {
1385         LOG( LOG_ERR, "Failed to set manual_sensor_digital_gain to manual mode, ret_value: %d", result_sensor_digital_gain );
1386         return ( result_sensor_digital_gain );
1387     }
1388 
1389     result_isp_digital_gain = acamera_command( ctx_id, TSYSTEM, SYSTEM_MANUAL_ISP_DIGITAL_GAIN, enable, COMMAND_SET, &ret_val );
1390     if ( result_isp_digital_gain ) {
1391         LOG( LOG_ERR, "Failed to set manual_isp_digital_gain to manual mode, ret_value: %d", result_isp_digital_gain );
1392         return ( result_isp_digital_gain );
1393     }
1394 
1395 #endif
1396 
1397     return 0;
1398 }
1399 
1400 /* set exposure in us unit */
isp_fw_do_set_exposure(uint32_t ctx_id,int exp)1401 static int isp_fw_do_set_exposure( uint32_t ctx_id, int exp )
1402 {
1403 #ifdef HDF_CAMERA_XTS_ON
1404     hdf_xts_exposure = exp;
1405     return 0;
1406 #endif
1407 
1408 #if defined( TALGORITHMS ) && defined( AE_EXPOSURE_ID )
1409     int result;
1410     uint32_t ret_val;
1411 
1412     /* some controls(such brightness) will call acamera_command()
1413      * before isp_fw initialed, so we need to check.
1414      */
1415     if ( !isp_started ) {
1416         LOG( LOG_ERR, "ISP FW not inited yet" );
1417         return -EBUSY;
1418     }
1419 
1420     result = acamera_command( ctx_id, TALGORITHMS, AE_EXPOSURE_ID, exp * 1000, COMMAND_SET, &ret_val );
1421     if ( result ) {
1422         LOG( LOG_ERR, "Failed to set AE_EXPOSURE_ID to %d, ret_value: %d.", exp, result );
1423         return result;
1424     }
1425 #endif
1426     return 0;
1427 }
1428 
isp_fw_do_get_exposure(uint32_t ctx_id)1429 static int isp_fw_do_get_exposure( uint32_t ctx_id )
1430 {
1431 #ifdef HDF_CAMERA_XTS_ON
1432     return hdf_xts_exposure;
1433 #endif
1434 
1435 #if defined( TALGORITHMS ) && defined( AE_EXPOSURE_ID )
1436     int result;
1437     uint32_t ret_val;
1438 
1439     /* some controls(such brightness) will call acamera_command()
1440      * before isp_fw initialed, so we need to check.
1441      */
1442     if ( !isp_started ) {
1443         LOG( LOG_ERR, "ISP FW not inited yet" );
1444         return -EBUSY;
1445     }
1446 
1447     result = acamera_command( ctx_id, TALGORITHMS, AE_EXPOSURE_ID, 0, COMMAND_GET, &ret_val );
1448     if ( result ) {
1449         LOG( LOG_ERR, "Failed to get AE_EXPOSURE_ID ret_value: %d.", result );
1450         return result;
1451     }
1452 #endif
1453 
1454     return ret_val;
1455 }
1456 
isp_fw_do_set_variable_frame_rate(uint32_t ctx_id,int enable)1457 static int isp_fw_do_set_variable_frame_rate( uint32_t ctx_id, int enable )
1458 {
1459     // SYSTEM_EXPOSURE_PRIORITY ??
1460     return 0;
1461 }
1462 
isp_fw_do_set_white_balance_mode(uint32_t ctx_id,int wb_mode)1463 static int isp_fw_do_set_white_balance_mode( uint32_t ctx_id, int wb_mode )
1464 {
1465 #ifdef HDF_CAMERA_XTS_ON
1466     hdf_xts_wdr_mode = wb_mode;
1467     return 0;
1468 #endif
1469 
1470 #if defined( TALGORITHMS ) && defined( AWB_MODE_ID )
1471 #if defined( ISP_HAS_AWB_MESH_FSM ) || defined( ISP_HAS_AWB_MESH_NBP_FSM ) || defined( ISP_HAS_AWB_MANUAL_FSM )
1472     static int32_t last_wb_request = AWB_DAY_LIGHT;
1473 #else
1474     static int32_t last_wb_request = AWB_MANUAL;
1475 #endif
1476     int result;
1477     uint32_t mode = 0;
1478     uint32_t ret_val;
1479 
1480     /* some controls(such brightness) will call acamera_command()
1481      * before isp_fw initialed, so we need to check.
1482      */
1483     if ( !isp_started ) {
1484         LOG( LOG_ERR, "ISP FW not inited yet" );
1485         return -EBUSY;
1486     }
1487 
1488     result = acamera_command( ctx_id, TALGORITHMS, AWB_MODE_ID, 0, COMMAND_GET, &ret_val );
1489     LOG( LOG_CRIT, "AWB_MODE_ID = %d", ret_val );
1490     switch ( wb_mode ) {
1491     case AWB_MANUAL:
1492         /* we set the last mode instead of MANUAL */
1493         mode = last_wb_request;
1494         break;
1495     case AWB_AUTO:
1496         /* we set the last mode instead of MANUAL */
1497         if ( ret_val != AWB_AUTO ) {
1498             mode = wb_mode;
1499         } else {
1500             LOG( LOG_DEBUG, "Auto WB is already enabled." );
1501             return 0;
1502         }
1503         break;
1504 #if defined( ISP_HAS_AWB_MESH_FSM ) || defined( ISP_HAS_AWB_MESH_NBP_FSM ) || defined( ISP_HAS_AWB_MANUAL_FSM )
1505     case AWB_DAY_LIGHT:
1506     case AWB_CLOUDY:
1507     case AWB_INCANDESCENT:
1508     case AWB_FLOURESCENT:
1509     case AWB_TWILIGHT:
1510     case AWB_SHADE:
1511     case AWB_WARM_FLOURESCENT:
1512         if ( ret_val != AWB_AUTO ) {
1513             mode = wb_mode;
1514         } else {
1515             /* wb mode is not updated when it's in auto mode */
1516             LOG( LOG_DEBUG, "Auto WB is enabled, remembering mode." );
1517             last_wb_request = wb_mode;
1518             return 0;
1519         }
1520         break;
1521 #endif
1522     default:
1523         return -EINVAL;
1524     }
1525 
1526     result = acamera_command( ctx_id, TALGORITHMS, AWB_MODE_ID, mode, COMMAND_SET, &ret_val );
1527     if ( result ) {
1528         LOG( LOG_ERR, "Failed to set AWB_MODE_ID to %u, ret_value: %d.", mode, result );
1529         return result;
1530     }
1531 #endif
1532     return 0;
1533 }
1534 
isp_fw_do_get_white_balance_mode(uint32_t ctx_id)1535 static int isp_fw_do_get_white_balance_mode( uint32_t ctx_id )
1536 {
1537 #ifdef HDF_CAMERA_XTS_ON
1538     return hdf_xts_wdr_mode;
1539 #endif
1540     int result;
1541     uint32_t ret_val;
1542 
1543     /* some controls(such brightness) will call acamera_command()
1544      * before isp_fw initialed, so we need to check.
1545      */
1546     if ( !isp_started ) {
1547         LOG( LOG_ERR, "ISP FW not inited yet" );
1548         return -EBUSY;
1549     }
1550 
1551     result = acamera_command( ctx_id, TALGORITHMS, AWB_MODE_ID, 0, COMMAND_GET, &ret_val );
1552     if ( result ) {
1553         LOG( LOG_ERR, "Failed to get AWB_MODE_ID ret_value: %d.", result );
1554         return result;
1555     }
1556 
1557     LOG(LOG_CRIT, "AWB_MODE_ID = %d", ret_val );
1558 
1559     return ret_val;
1560 }
1561 
isp_fw_do_set_focus_auto(uint32_t ctx_id,int enable)1562 static int isp_fw_do_set_focus_auto( uint32_t ctx_id, int enable )
1563 {
1564 #if defined( TALGORITHMS ) && defined( AF_MODE_ID )
1565     int result;
1566     uint32_t mode = 0;
1567     uint32_t ret_val;
1568 
1569     /* some controls(such brightness) will call acamera_command()
1570      * before isp_fw initialed, so we need to check.
1571      */
1572     if ( !isp_started ) {
1573         LOG( LOG_ERR, "ISP FW not inited yet" );
1574         return -EBUSY;
1575     }
1576 
1577     result = acamera_command( ctx_id, TALGORITHMS, AF_MODE_ID, 0, COMMAND_GET, &ret_val );
1578     switch ( enable ) {
1579     case 1:
1580         /* we set the last mode instead of MANUAL */
1581         if ( ret_val != AF_AUTO_CONTINUOUS ) {
1582             mode = AF_AUTO_CONTINUOUS;
1583         } else {
1584             LOG( LOG_DEBUG, "Auto focus is already enabled." );
1585             return 0;
1586         }
1587         break;
1588     case 0:
1589         if ( ret_val != AF_MANUAL ) {
1590             mode = AF_MANUAL;
1591         } else {
1592             /* wb mode is not updated when it's in auto mode */
1593             LOG( LOG_DEBUG, "Auto WB is enabled, remembering mode." );
1594             return 0;
1595         }
1596         break;
1597     default:
1598         return -EINVAL;
1599     }
1600 
1601     result = acamera_command( ctx_id, TALGORITHMS, AF_MODE_ID, mode, COMMAND_SET, &ret_val );
1602     if ( result ) {
1603         LOG( LOG_ERR, "Failed to set AF_MODE_ID to %u, ret_value: %d.", mode, result );
1604         return result;
1605     }
1606 #endif
1607 
1608     return 0;
1609 }
1610 
isp_fw_do_set_focus(uint32_t ctx_id,int focus)1611 static int isp_fw_do_set_focus( uint32_t ctx_id, int focus )
1612 {
1613 #if defined( TALGORITHMS ) && defined( AF_MANUAL_CONTROL_ID )
1614     int result;
1615     uint32_t ret_val;
1616 
1617     /* some controls(such brightness) will call acamera_command()
1618      * before isp_fw initialed, so we need to check.
1619      */
1620     if ( !isp_started ) {
1621         LOG( LOG_ERR, "ISP FW not inited yet" );
1622         return -EBUSY;
1623     }
1624 
1625     result = acamera_command( ctx_id, TALGORITHMS, AF_MANUAL_CONTROL_ID, focus, COMMAND_SET, &ret_val );
1626     if ( result ) {
1627         LOG( LOG_ERR, "Failed to set AF_MANUAL_CONTROL_ID to %d, ret_value: %d.", focus, result );
1628         return result;
1629     }
1630 #endif
1631     return 0;
1632 }
1633 
isp_fw_do_set_ae_compensation(uint32_t ctx_id,int val)1634 static int isp_fw_do_set_ae_compensation( uint32_t ctx_id, int val )
1635 {
1636     int result;
1637     uint32_t ret_val;
1638 
1639     if ( val < 0 )
1640         return -EIO;
1641 
1642     if ( !isp_started ) {
1643         LOG( LOG_NOTICE, "ISP FW not inited yet" );
1644         return -EBUSY;
1645     }
1646 
1647     result = acamera_command( ctx_id, TALGORITHMS, AE_COMPENSATION_ID, val, COMMAND_SET, &ret_val );
1648     if ( result ) {
1649         LOG( LOG_ERR, "Failed to set AE_COMPENSATION to %u, ret_value: %d.", val, result );
1650         return result;
1651     }
1652     return 0;
1653 }
1654 
isp_fw_do_set_max_integration_time(uint32_t ctx_id,int val)1655 static int isp_fw_do_set_max_integration_time( uint32_t ctx_id, int val )
1656 {
1657     int result;
1658     uint32_t ret_val;
1659 
1660     if ( val < 0 )
1661         return -EIO;
1662 
1663     if ( !isp_started ) {
1664         LOG( LOG_NOTICE, "ISP FW not inited yet" );
1665         return -EBUSY;
1666     }
1667 
1668     result = acamera_command( ctx_id, TSYSTEM, SYSTEM_MAX_INTEGRATION_TIME, val, COMMAND_SET, &ret_val );
1669     if ( result ) {
1670         LOG( LOG_ERR, "Failed to set max_integration_time to %u, ret_value: %d.", val, result );
1671         return result;
1672     }
1673     return 0;
1674 }
1675 
isp_fw_do_set_snr_manual(uint32_t ctx_id,int val)1676 static int isp_fw_do_set_snr_manual( uint32_t ctx_id, int val )
1677 {
1678     int result;
1679     uint32_t ret_val;
1680 
1681     if ( !isp_started ) {
1682         LOG( LOG_ERR, "ISP FW not inited yet" );
1683         return -EBUSY;
1684     }
1685 
1686     result = acamera_command( ctx_id, TSCENE_MODES, SNR_MANUAL_ID, val, COMMAND_SET, &ret_val );
1687     if ( result ) {
1688         LOG( LOG_ERR, "Failed to set SNR_MANUAL_ID to %d, ret_value: %d.", val, result );
1689         return result;
1690     }
1691 
1692     return 0;
1693 
1694 }
1695 
isp_fw_do_set_snr_strength(uint32_t ctx_id,int val)1696 static int isp_fw_do_set_snr_strength( uint32_t ctx_id, int val )
1697 {
1698     int result;
1699     uint32_t ret_val;
1700 
1701     if ( !isp_started ) {
1702         LOG( LOG_ERR, "ISP FW not inited yet" );
1703         return -EBUSY;
1704     }
1705 
1706     result = acamera_command( ctx_id, TSCENE_MODES, SNR_STRENGTH_ID, val, COMMAND_SET, &ret_val );
1707     if ( result ) {
1708         LOG( LOG_ERR, "Failed to set SNR_OFFSET_ID to %d, ret_value: %d.", val, result );
1709         return result;
1710     }
1711 
1712     return 0;
1713 
1714 }
1715 
isp_fw_do_set_tnr_manual(uint32_t ctx_id,int val)1716 static int isp_fw_do_set_tnr_manual( uint32_t ctx_id, int val )
1717 {
1718     int result;
1719     uint32_t ret_val;
1720 
1721     if ( !isp_started ) {
1722         LOG( LOG_ERR, "ISP FW not inited yet" );
1723         return -EBUSY;
1724     }
1725 
1726     result = acamera_command( ctx_id, TSCENE_MODES, TNR_MANUAL_ID, val, COMMAND_SET, &ret_val );
1727     if ( result ) {
1728         LOG( LOG_ERR, "Failed to set TNR_MANUAL_ID to %d, ret_value: %d.", val, result );
1729         return result;
1730     }
1731 
1732     return 0;
1733 
1734 }
1735 
isp_fw_do_set_tnr_offset(uint32_t ctx_id,int val)1736 static int isp_fw_do_set_tnr_offset( uint32_t ctx_id, int val )
1737 {
1738     int result;
1739     uint32_t ret_val;
1740 
1741     if ( !isp_started ) {
1742         LOG( LOG_ERR, "ISP FW not inited yet" );
1743         return -EBUSY;
1744     }
1745 
1746     result = acamera_command( ctx_id, TSCENE_MODES, TNR_OFFSET_ID, val, COMMAND_SET, &ret_val );
1747     if ( result ) {
1748         LOG( LOG_ERR, "Failed to set TNR_OFFSET_ID to %d, ret_value: %d.", val, result );
1749         return result;
1750     }
1751 
1752     return 0;
1753 
1754 }
1755 
isp_fw_do_set_temper_mode(uint32_t ctx_id,int val)1756 static int isp_fw_do_set_temper_mode( uint32_t ctx_id, int val )
1757 {
1758     int result;
1759     uint32_t ret_val;
1760     uint32_t temper_mode;
1761 
1762     if ( !isp_started ) {
1763         LOG( LOG_ERR, "ISP FW not inited yet" );
1764         return -EBUSY;
1765     }
1766 
1767     if ( val == 1 )
1768         temper_mode = TEMPER2_MODE;
1769     else
1770         temper_mode = TEMPER3_MODE;
1771 
1772     result = acamera_command( ctx_id, TSYSTEM, TEMPER_MODE_ID, temper_mode, COMMAND_SET, &ret_val );
1773     if ( result ) {
1774         LOG( LOG_ERR, "Failed to set TEMPER_MODE_ID to %d, ret_value: %d.", temper_mode, result );
1775         return result;
1776     }
1777 
1778     return 0;
1779 
1780 }
1781 
isp_fw_do_set_sensor_dynamic_mode(uint32_t ctx_id,int val)1782 static int isp_fw_do_set_sensor_dynamic_mode( uint32_t ctx_id, int val )
1783 {
1784     int result;
1785     uint32_t ret_val;
1786     uint32_t preset_mode = val;
1787 
1788     result = acamera_command( ctx_id, TSENSOR, SENSOR_WDRMODE_ID, preset_mode, COMMAND_SET, &ret_val );
1789     if ( result ) {
1790         LOG( LOG_ERR, "Failed to set SENSOR_MODE_SWITCH to %d, ret_value: %d.", preset_mode, result );
1791         return result;
1792     }
1793 
1794     return 0;
1795 }
1796 
isp_fw_do_set_sensor_antiflicker(uint32_t ctx_id,int val)1797 static int isp_fw_do_set_sensor_antiflicker( uint32_t ctx_id, int val )
1798 {
1799     int result;
1800     uint32_t ret_val;
1801     uint32_t fps = val;
1802 
1803     result = acamera_command( ctx_id, TSENSOR, SENSOR_ANTIFLICKER_ID, fps, COMMAND_SET, &ret_val );
1804     if ( result ) {
1805         LOG( LOG_ERR, "Failed to set SENSOR_ANTIFLICKER to %d, ret_value: %d.", fps, result );
1806         return result;
1807     }
1808 
1809     return 0;
1810 }
1811 
isp_fw_do_set_defog_mode(uint32_t ctx_id,int val)1812 static int isp_fw_do_set_defog_mode( uint32_t ctx_id, int val )
1813 {
1814     int result;
1815     uint32_t ret_val;
1816     uint32_t mode = 0;
1817 
1818     switch (val) {
1819     case 0:
1820         mode = DEFOG_DISABLE;
1821     break;
1822     case 1:
1823         mode = DEFOG_ONLY;
1824     break;
1825     case 2:
1826         mode = DEFOG_BLEND;
1827     break;
1828     default:
1829         mode = DEFOG_DISABLE;
1830     break;
1831     }
1832 
1833     result = acamera_command( ctx_id, TALGORITHMS, DEFOG_MODE_ID, mode, COMMAND_SET, &ret_val );
1834     if ( result ) {
1835         LOG( LOG_ERR, "Failed to set SENSOR_MODE_SWITCH to %d, ret_value: %d.", mode, result );
1836         return result;
1837     }
1838 
1839     return 0;
1840 }
1841 
isp_fw_do_set_defog_ratio(uint32_t ctx_id,int val)1842 static int isp_fw_do_set_defog_ratio( uint32_t ctx_id, int val )
1843 {
1844     int result;
1845     uint32_t ret_val;
1846     uint32_t ratio = val;
1847 
1848     result = acamera_command( ctx_id, TALGORITHMS, DEFOG_RATIO_DELTA, ratio, COMMAND_SET, &ret_val );
1849     if ( result ) {
1850         LOG( LOG_ERR, "Failed to set SENSOR_MODE_SWITCH to %d, ret_value: %d.", ratio, result );
1851         return result;
1852     }
1853 
1854     return 0;
1855 }
1856 
isp_fw_do_get_sensor_dynamic_mode(uint32_t ctx_id)1857 static int isp_fw_do_get_sensor_dynamic_mode( uint32_t ctx_id )
1858 {
1859     int result;
1860     uint32_t ret_val;
1861 
1862     if ( !isp_started ) {
1863         LOG( LOG_NOTICE, "ISP FW not inited yet" );
1864         return -EBUSY;
1865     }
1866 
1867     result = acamera_command( ctx_id, TSENSOR, SENSOR_WDRMODE_ID, 0, COMMAND_GET, &ret_val );
1868     if ( result ) {
1869         LOG( LOG_ERR, "Failed to get SENSOR_MODE_SWITCH, ret_value: %d.", result );
1870         return result;
1871     }
1872 
1873     return ret_val;
1874 }
1875 
isp_fw_do_get_sensor_antiflicker(uint32_t ctx_id)1876 static int isp_fw_do_get_sensor_antiflicker( uint32_t ctx_id )
1877 {
1878     int result;
1879     uint32_t ret_val;
1880 
1881     if ( !isp_started ) {
1882         LOG( LOG_NOTICE, "ISP FW not inited yet" );
1883         return -EBUSY;
1884     }
1885 
1886     result = acamera_command( ctx_id, TSENSOR, SENSOR_ANTIFLICKER_ID, 0, COMMAND_GET, &ret_val );
1887     if ( result ) {
1888         LOG( LOG_ERR, "Failed to get SENSOR_ANTIFLICKER, ret_value: %d.", result );
1889         return result;
1890     }
1891 
1892     return ret_val;
1893 }
1894 
isp_fw_do_get_ae_compensation(uint32_t ctx_id)1895 static int isp_fw_do_get_ae_compensation( uint32_t ctx_id )
1896 {
1897     int result;
1898     uint32_t ret_val;
1899 
1900     if ( !isp_started ) {
1901         LOG( LOG_NOTICE, "ISP FW not inited yet" );
1902         return -EBUSY;
1903     }
1904 
1905     result = acamera_command( ctx_id, TALGORITHMS, AE_COMPENSATION_ID, 0, COMMAND_GET, &ret_val );
1906     if ( result ) {
1907         LOG( LOG_ERR, "Failed to set AE_COMPENSATION, ret_value: %d.", result );
1908         return result;
1909     }
1910 
1911     return ret_val;
1912 }
1913 
isp_fw_do_get_snr_manual(uint32_t ctx_id)1914 static int isp_fw_do_get_snr_manual( uint32_t ctx_id )
1915 {
1916     int result;
1917     uint32_t ret_val;
1918 
1919     if ( !isp_started ) {
1920         LOG( LOG_ERR, "ISP FW not inited yet" );
1921         return -EBUSY;
1922     }
1923 
1924     result = acamera_command( ctx_id, TSCENE_MODES, SNR_MANUAL_ID, 0, COMMAND_GET, &ret_val );
1925     if ( result ) {
1926         LOG( LOG_ERR, "Failed to set SNR_MANUAL_ID, ret_value: %d.", result );
1927         return result;
1928     }
1929 
1930     return ret_val;
1931 }
1932 
isp_fw_do_get_snr_strength(uint32_t ctx_id)1933 static int isp_fw_do_get_snr_strength( uint32_t ctx_id )
1934 {
1935     int result;
1936     uint32_t ret_val;
1937 
1938     if ( !isp_started ) {
1939         LOG( LOG_ERR, "ISP FW not inited yet" );
1940         return -EBUSY;
1941     }
1942 
1943     result = acamera_command( ctx_id, TSCENE_MODES, SNR_STRENGTH_ID, 0, COMMAND_GET, &ret_val );
1944     if ( result ) {
1945         LOG( LOG_ERR, "Failed to set SNR_OFFSET_ID, ret_value: %d.", result );
1946         return result;
1947     }
1948 
1949     return ret_val;
1950 
1951 }
1952 
isp_fw_do_get_tnr_manual(uint32_t ctx_id)1953 static int isp_fw_do_get_tnr_manual( uint32_t ctx_id )
1954 {
1955     int result;
1956     uint32_t ret_val;
1957 
1958     if ( !isp_started ) {
1959         LOG( LOG_ERR, "ISP FW not inited yet" );
1960         return -EBUSY;
1961     }
1962 
1963     result = acamera_command( ctx_id, TSCENE_MODES, TNR_MANUAL_ID, 0, COMMAND_GET, &ret_val );
1964 	if ( result ) {
1965         LOG( LOG_ERR, "Failed to set TNR_MANUAL_ID, ret_value: %d.", result );
1966         return result;
1967     }
1968 
1969     return ret_val;
1970 
1971 }
1972 
isp_fw_do_get_tnr_offset(uint32_t ctx_id)1973 static int isp_fw_do_get_tnr_offset( uint32_t ctx_id )
1974 {
1975     int result;
1976     uint32_t ret_val;
1977 
1978     if ( !isp_started ) {
1979         LOG( LOG_ERR, "ISP FW not inited yet" );
1980         return -EBUSY;
1981     }
1982 
1983     result = acamera_command( ctx_id, TSCENE_MODES, TNR_OFFSET_ID, 0, COMMAND_GET, &ret_val );
1984     if ( result ) {
1985         LOG( LOG_ERR, "Failed to set TNR_OFFSET_ID, ret_value: %d.", result );
1986         return result;
1987     }
1988 
1989     return ret_val;
1990 
1991 }
1992 
1993 /* ----------------------------------------------------------------
1994  * fw_interface config interface
1995  */
fw_intf_validate_control(uint32_t id)1996 bool fw_intf_validate_control( uint32_t id )
1997 {
1998     return isp_fw_do_validate_control( id );
1999 }
2000 
fw_intf_set_test_pattern(uint32_t ctx_id,int val)2001 int fw_intf_set_test_pattern( uint32_t ctx_id, int val )
2002 {
2003     return isp_fw_do_set_test_pattern( ctx_id, val );
2004 }
2005 
fw_intf_set_test_pattern_type(uint32_t ctx_id,int val)2006 int fw_intf_set_test_pattern_type( uint32_t ctx_id, int val )
2007 {
2008     return isp_fw_do_set_test_pattern_type( ctx_id, val );
2009 }
2010 
fw_intf_set_af_refocus(uint32_t ctx_id,int val)2011 int fw_intf_set_af_refocus( uint32_t ctx_id, int val )
2012 {
2013     return isp_fw_do_set_af_refocus( ctx_id, val );
2014 }
2015 
fw_intf_set_af_roi(uint32_t ctx_id,int val)2016 int fw_intf_set_af_roi( uint32_t ctx_id, int val )
2017 {
2018     return isp_fw_do_set_af_roi( ctx_id, val );
2019 }
2020 
fw_intf_set_brightness(uint32_t ctx_id,int val)2021 int fw_intf_set_brightness( uint32_t ctx_id, int val )
2022 {
2023     return isp_fw_do_set_brightness( ctx_id, val );
2024 }
2025 
fw_intf_set_contrast(uint32_t ctx_id,int val)2026 int fw_intf_set_contrast( uint32_t ctx_id, int val )
2027 {
2028     return isp_fw_do_set_contrast( ctx_id, val );
2029 }
2030 
fw_intf_set_saturation(uint32_t ctx_id,int val)2031 int fw_intf_set_saturation( uint32_t ctx_id, int val )
2032 {
2033     return isp_fw_do_set_saturation( ctx_id, val );
2034 }
2035 
fw_intf_set_hue(uint32_t ctx_id,int val)2036 int fw_intf_set_hue( uint32_t ctx_id, int val )
2037 {
2038     return isp_fw_do_set_hue( ctx_id, val );
2039 }
2040 
fw_intf_set_sharpness(uint32_t ctx_id,int val)2041 int fw_intf_set_sharpness( uint32_t ctx_id, int val )
2042 {
2043     return isp_fw_do_set_sharpness( ctx_id, val );
2044 }
2045 
fw_intf_set_color_fx(uint32_t ctx_id,int val)2046 int fw_intf_set_color_fx( uint32_t ctx_id, int val )
2047 {
2048     return isp_fw_do_set_color_fx( ctx_id, val );
2049 }
2050 
fw_intf_set_hflip(uint32_t ctx_id,int val)2051 int fw_intf_set_hflip( uint32_t ctx_id, int val )
2052 {
2053     return isp_fw_do_set_hflip( ctx_id, val ? 1 : 0 );
2054 }
2055 
fw_intf_set_vflip(uint32_t ctx_id,int val)2056 int fw_intf_set_vflip( uint32_t ctx_id, int val )
2057 {
2058     return isp_fw_do_set_vflip( ctx_id, val ? 1 : 0 );
2059 }
2060 
fw_intf_set_autogain(uint32_t ctx_id,int val)2061 int fw_intf_set_autogain( uint32_t ctx_id, int val )
2062 {
2063     /* autogain enable: disable manual gain.
2064      * autogain disable: enable manual gain.
2065      */
2066     return isp_fw_do_set_manual_gain( ctx_id, val ? 0 : 1 );
2067 }
2068 
fw_intf_set_gain(uint32_t ctx_id,int val)2069 int fw_intf_set_gain( uint32_t ctx_id, int val )
2070 {
2071     return isp_fw_do_set_gain( ctx_id, val );
2072 }
2073 
fw_intf_set_exposure_auto(uint32_t ctx_id,int val)2074 int fw_intf_set_exposure_auto( uint32_t ctx_id, int val )
2075 {
2076     return isp_fw_do_set_exposure_auto( ctx_id, val );
2077 }
2078 
fw_intf_get_exposure_auto(uint32_t ctx_id)2079 int fw_intf_get_exposure_auto( uint32_t ctx_id)
2080 {
2081     return isp_fw_do_get_exposure_auto( ctx_id );
2082 }
2083 
fw_intf_set_exposure(uint32_t ctx_id,int val)2084 int fw_intf_set_exposure( uint32_t ctx_id, int val )
2085 {
2086     return isp_fw_do_set_exposure( ctx_id, val );
2087 }
2088 
fw_intf_get_exposure(uint32_t ctx_id)2089 int fw_intf_get_exposure( uint32_t ctx_id )
2090 {
2091     return isp_fw_do_get_exposure( ctx_id );
2092 }
2093 
fw_intf_set_variable_frame_rate(uint32_t ctx_id,int val)2094 int fw_intf_set_variable_frame_rate( uint32_t ctx_id, int val )
2095 {
2096     return isp_fw_do_set_variable_frame_rate( ctx_id, val );
2097 }
2098 
fw_intf_set_white_balance_auto(uint32_t ctx_id,int val)2099 int fw_intf_set_white_balance_auto( uint32_t ctx_id, int val )
2100 {
2101 #ifdef AWB_MODE_ID
2102     int mode = val;
2103 
2104 #if defined( ISP_HAS_AWB_MESH_FSM ) || defined( ISP_HAS_AWB_MESH_NBP_FSM ) || defined( ISP_HAS_AWB_MANUAL_FSM )
2105     mode = val;
2106 #else
2107     if ( val == true )
2108         mode = AWB_AUTO;
2109     else
2110         mode = AWB_MANUAL;
2111 #endif
2112 
2113     return isp_fw_do_set_white_balance_mode( ctx_id, mode );
2114 #endif
2115 }
2116 
fw_intf_get_white_balance_auto(uint32_t ctx_id)2117 int fw_intf_get_white_balance_auto( uint32_t ctx_id )
2118 {
2119     return isp_fw_do_get_white_balance_mode( ctx_id );
2120 }
2121 
fw_intf_set_white_balance(uint32_t ctx_id,int val)2122 int fw_intf_set_white_balance( uint32_t ctx_id, int val )
2123 {
2124     int mode = 0;
2125 
2126     switch ( val ) {
2127 #ifdef AWB_MODE_ID
2128 #if defined( ISP_HAS_AWB_MESH_FSM ) || defined( ISP_HAS_AWB_MESH_NBP_FSM ) || defined( ISP_HAS_AWB_MANUAL_FSM )
2129     case 8000:
2130         mode = AWB_SHADE;
2131         break;
2132     case 7000:
2133         mode = AWB_CLOUDY;
2134         break;
2135     case 6000:
2136     case 5000:
2137         mode = AWB_DAY_LIGHT;
2138         break;
2139     case 4000:
2140         mode = AWB_FLOURESCENT;
2141         break;
2142     case 3000:
2143         mode = AWB_WARM_FLOURESCENT;
2144         break;
2145     case 2000:
2146         mode = AWB_INCANDESCENT;
2147         break;
2148 #endif
2149 #endif
2150     default:
2151         // return SUCCESS for compatibility verfication issue
2152         return 0;
2153     }
2154 
2155     return isp_fw_do_set_white_balance_mode( ctx_id, mode );
2156 }
2157 
fw_intf_set_focus_auto(uint32_t ctx_id,int val)2158 int fw_intf_set_focus_auto( uint32_t ctx_id, int val )
2159 {
2160     return isp_fw_do_set_focus_auto( ctx_id, val );
2161 }
2162 
fw_intf_set_focus(uint32_t ctx_id,int val)2163 int fw_intf_set_focus( uint32_t ctx_id, int val )
2164 {
2165     return isp_fw_do_set_focus( ctx_id, val );
2166 }
2167 
fw_intf_set_output_fr_on_off(uint32_t ctx_id,uint32_t ctrl_val)2168 int fw_intf_set_output_fr_on_off( uint32_t ctx_id, uint32_t ctrl_val )
2169 {
2170     return fw_intf_stream_set_output_format( ctx_id, V4L2_STREAM_TYPE_FR, ctrl_val );
2171 }
2172 
fw_intf_set_output_ds1_on_off(uint32_t ctx_id,uint32_t ctrl_val)2173 int fw_intf_set_output_ds1_on_off( uint32_t ctx_id, uint32_t ctrl_val )
2174 {
2175 #if ISP_HAS_DS1
2176     return fw_intf_stream_set_output_format( ctx_id, V4L2_STREAM_TYPE_DS1, ctrl_val );
2177 #else
2178     return 0;
2179 #endif
2180 }
2181 
fw_intf_set_custom_sensor_wdr_mode(uint32_t ctx_id,uint32_t ctrl_val)2182 int fw_intf_set_custom_sensor_wdr_mode(uint32_t ctx_id, uint32_t ctrl_val)
2183 {
2184     custom_wdr_mode = ctrl_val;
2185     return 0;
2186 }
2187 
fw_intf_set_custom_sensor_exposure(uint32_t ctx_id,uint32_t ctrl_val)2188 int fw_intf_set_custom_sensor_exposure(uint32_t ctx_id, uint32_t ctrl_val)
2189 {
2190     custom_exp = ctrl_val;
2191     return 0;
2192 }
2193 
fw_intf_set_custom_sensor_fps(uint32_t ctx_id,uint32_t ctrl_val)2194 int fw_intf_set_custom_sensor_fps(uint32_t ctx_id, uint32_t ctrl_val)
2195 {
2196     custom_fps = ctrl_val;
2197     return 0;
2198 }
2199 
fw_intf_set_custom_snr_manual(uint32_t ctx_id,uint32_t ctrl_val)2200 int fw_intf_set_custom_snr_manual(uint32_t ctx_id, uint32_t ctrl_val)
2201 {
2202     return isp_fw_do_set_snr_manual(ctx_id, ctrl_val);
2203 }
2204 
fw_intf_set_custom_snr_strength(uint32_t ctx_id,uint32_t ctrl_val)2205 int fw_intf_set_custom_snr_strength(uint32_t ctx_id, uint32_t ctrl_val)
2206 {
2207     return isp_fw_do_set_snr_strength(ctx_id, ctrl_val);
2208 }
2209 
fw_intf_set_custom_tnr_manual(uint32_t ctx_id,uint32_t ctrl_val)2210 int fw_intf_set_custom_tnr_manual(uint32_t ctx_id, uint32_t ctrl_val)
2211 {
2212     return isp_fw_do_set_tnr_manual(ctx_id, ctrl_val);
2213 }
2214 
fw_intf_set_custom_tnr_offset(uint32_t ctx_id,uint32_t ctrl_val)2215 int fw_intf_set_custom_tnr_offset(uint32_t ctx_id, uint32_t ctrl_val)
2216 {
2217     return isp_fw_do_set_tnr_offset(ctx_id, ctrl_val);
2218 }
2219 
fw_intf_set_custom_fr_fps(uint32_t ctx_id,uint32_t ctrl_val)2220 int fw_intf_set_custom_fr_fps(uint32_t ctx_id, uint32_t ctrl_val)
2221 {
2222     int rtn = -1;
2223 
2224     rtn = fw_intf_set_fr_fps(ctx_id, ctrl_val);
2225 
2226     return rtn;
2227 }
2228 
fw_intf_set_custom_ds1_fps(uint32_t ctx_id,uint32_t ctrl_val)2229 int fw_intf_set_custom_ds1_fps(uint32_t ctx_id, uint32_t ctrl_val)
2230 {
2231     int rtn = -1;
2232 
2233     rtn = fw_intf_set_ds1_fps(ctx_id, ctrl_val);
2234 
2235     return rtn;
2236 }
2237 
fw_intf_set_custom_sensor_testpattern(uint32_t ctx_id,uint32_t ctrl_val)2238 int fw_intf_set_custom_sensor_testpattern(uint32_t ctx_id, uint32_t ctrl_val)
2239 {
2240     int rtn = -1;
2241 
2242     rtn = fw_intf_set_sensor_testpattern(ctx_id, ctrl_val);
2243 
2244     return rtn;
2245 }
2246 
fw_intf_set_customer_sensor_ir_cut(uint32_t ctx_id,uint32_t ctrl_val)2247 int fw_intf_set_customer_sensor_ir_cut(uint32_t ctx_id, uint32_t ctrl_val)
2248 {
2249     int rtn = -1;
2250 
2251     rtn = fw_intf_set_sensor_ir_cut_set(ctx_id, ctrl_val);
2252 
2253     return rtn;
2254 }
2255 
fw_intf_set_customer_ae_zone_weight(uint32_t ctx_id,unsigned long ctrl_val)2256 int fw_intf_set_customer_ae_zone_weight(uint32_t ctx_id, unsigned long ctrl_val)
2257 {
2258     int rtn = -1;
2259 
2260     rtn = fw_intf_set_ae_zone_weight(ctx_id, ctrl_val);
2261 
2262     return rtn;
2263 }
2264 
fw_intf_set_customer_awb_zone_weight(uint32_t ctx_id,unsigned long ctrl_val)2265 int fw_intf_set_customer_awb_zone_weight(uint32_t ctx_id, unsigned long ctrl_val)
2266 {
2267     int rtn = -1;
2268 
2269     rtn = fw_intf_set_awb_zone_weight(ctx_id, ctrl_val);
2270 
2271     return rtn;
2272 }
2273 
fw_intf_set_customer_manual_exposure(uint32_t ctx_id,int val)2274 int fw_intf_set_customer_manual_exposure( uint32_t ctx_id, int val )
2275 {
2276     int rtn = -1;
2277 
2278     if ( val == -1) {
2279        return 0;
2280     }
2281 
2282     rtn = isp_fw_do_set_manual_exposure( ctx_id, val );
2283 
2284     return rtn;
2285 }
2286 
fw_intf_set_customer_sensor_integration_time(uint32_t ctx_id,uint32_t ctrl_val)2287 int fw_intf_set_customer_sensor_integration_time(uint32_t ctx_id, uint32_t ctrl_val)
2288 {
2289     int rtn = -1;
2290 
2291     if ( ctrl_val == -1) {
2292        return 0;
2293     }
2294 
2295     rtn = fw_intf_set_sensor_integration_time(ctx_id, ctrl_val);
2296 
2297     return rtn;
2298 }
2299 
fw_intf_set_customer_sensor_analog_gain(uint32_t ctx_id,uint32_t ctrl_val)2300 int fw_intf_set_customer_sensor_analog_gain(uint32_t ctx_id, uint32_t ctrl_val)
2301 {
2302     int rtn = -1;
2303 
2304     if ( ctrl_val == -1) {
2305        return 0;
2306     }
2307 
2308     rtn = fw_intf_set_sensor_analog_gain(ctx_id, ctrl_val);
2309 
2310     return rtn;
2311 }
2312 
fw_intf_set_customer_isp_digital_gain(uint32_t ctx_id,uint32_t ctrl_val)2313 int fw_intf_set_customer_isp_digital_gain(uint32_t ctx_id, uint32_t ctrl_val)
2314 {
2315     int rtn = -1;
2316 
2317     if ( ctrl_val == -1) {
2318        return 0;
2319     }
2320 
2321     rtn = fw_intf_set_isp_digital_gain(ctx_id, ctrl_val);
2322 
2323     return rtn;
2324 }
2325 
fw_intf_set_customer_stop_sensor_update(uint32_t ctx_id,uint32_t ctrl_val)2326 int fw_intf_set_customer_stop_sensor_update(uint32_t ctx_id, uint32_t ctrl_val)
2327 {
2328     int rtn = -1;
2329 
2330     if ( ctrl_val == -1) {
2331        return 0;
2332     }
2333 
2334     rtn = fw_intf_set_stop_sensor_update(ctx_id, ctrl_val);
2335 
2336     return rtn;
2337 }
2338 
fw_intf_set_ae_compensation(uint32_t ctx_id,int val)2339 int fw_intf_set_ae_compensation( uint32_t ctx_id, int val )
2340 {
2341     return isp_fw_do_set_ae_compensation( ctx_id, val );
2342 }
2343 
fw_intf_set_customer_sensor_digital_gain(uint32_t ctx_id,uint32_t ctrl_val)2344 int fw_intf_set_customer_sensor_digital_gain(uint32_t ctx_id, uint32_t ctrl_val)
2345 {
2346     int rtn = -1;
2347 
2348     if ( ctrl_val == -1) {
2349        return 0;
2350     }
2351 
2352     rtn = fw_intf_set_sensor_digital_gain(ctx_id, ctrl_val);
2353 
2354     return rtn;
2355 }
2356 
fw_intf_set_customer_awb_red_gain(uint32_t ctx_id,uint32_t ctrl_val)2357 int fw_intf_set_customer_awb_red_gain(uint32_t ctx_id, uint32_t ctrl_val)
2358 {
2359     int rtn = -1;
2360 
2361     if ( ctrl_val == -1) {
2362        return 0;
2363     }
2364 
2365     rtn = fw_intf_set_awb_red_gain(ctx_id, ctrl_val);
2366 
2367     return rtn;
2368 }
2369 
fw_intf_set_customer_awb_blue_gain(uint32_t ctx_id,uint32_t ctrl_val)2370 int fw_intf_set_customer_awb_blue_gain(uint32_t ctx_id, uint32_t ctrl_val)
2371 {
2372     int rtn = -1;
2373 
2374     if ( ctrl_val == -1) {
2375        return 0;
2376     }
2377 
2378     rtn = fw_intf_set_awb_blue_gain(ctx_id, ctrl_val);
2379 
2380     return rtn;
2381 }
2382 
fw_intf_set_customer_max_integration_time(uint32_t ctx_id,uint32_t ctrl_val)2383 int fw_intf_set_customer_max_integration_time(uint32_t ctx_id, uint32_t ctrl_val)
2384 {
2385     if ( ctrl_val == -1) {
2386        return 0;
2387     }
2388     return isp_fw_do_set_max_integration_time(ctx_id, ctrl_val);
2389 }
2390 
fw_intf_set_customer_sensor_mode(uint32_t ctx_id,uint32_t ctrl_val)2391 int fw_intf_set_customer_sensor_mode(uint32_t ctx_id, uint32_t ctrl_val)
2392 {
2393     if ( ctrl_val < 0) {
2394        return 0;
2395     }
2396 
2397     return isp_fw_do_set_sensor_dynamic_mode(ctx_id, ctrl_val);
2398 }
2399 
fw_intf_set_customer_antiflicker(uint32_t ctx_id,uint32_t ctrl_val)2400 int fw_intf_set_customer_antiflicker(uint32_t ctx_id, uint32_t ctrl_val)
2401 {
2402     if ( ctrl_val < 0) {
2403        return 0;
2404     }
2405 
2406     return isp_fw_do_set_sensor_antiflicker(ctx_id, ctrl_val);
2407 }
2408 
fw_intf_set_customer_defog_mode(uint32_t ctx_id,uint32_t ctrl_val)2409 int fw_intf_set_customer_defog_mode(uint32_t ctx_id, uint32_t ctrl_val)
2410 {
2411     if ( ctrl_val < 0 || ctrl_val > 2) {
2412        return -1;
2413     }
2414 
2415     return isp_fw_do_set_defog_mode(ctx_id, ctrl_val);
2416 }
2417 
fw_intf_set_customer_defog_ratio(uint32_t ctx_id,uint32_t ctrl_val)2418 int fw_intf_set_customer_defog_ratio(uint32_t ctx_id, uint32_t ctrl_val)
2419 {
2420     if ( ctrl_val < 0 || ctrl_val > 4096) {
2421        return -1;
2422     }
2423 
2424     return isp_fw_do_set_defog_ratio(ctx_id, ctrl_val);
2425 }
2426 
2427 
fw_intf_get_customer_sensor_mode(uint32_t ctx_id)2428 int fw_intf_get_customer_sensor_mode( uint32_t ctx_id )
2429 {
2430     return isp_fw_do_get_sensor_dynamic_mode( ctx_id );
2431 }
2432 
fw_intf_get_customer_antiflicker(uint32_t ctx_id)2433 int fw_intf_get_customer_antiflicker( uint32_t ctx_id )
2434 {
2435     return isp_fw_do_get_sensor_antiflicker( ctx_id );
2436 }
2437 
fw_intf_set_customer_temper_mode(uint32_t ctx_id,uint32_t ctrl_val)2438 int fw_intf_set_customer_temper_mode(uint32_t ctx_id, uint32_t ctrl_val)
2439 {
2440     if ((ctrl_val != 1) && (ctrl_val != 2)) {
2441        return 0;
2442     }
2443 
2444     settings[ctx_id].temper_frames_number = ctrl_val;
2445 
2446     return isp_fw_do_set_temper_mode(ctx_id, ctrl_val);
2447 }
2448 
fw_intf_get_ae_compensation(uint32_t ctx_id)2449 int fw_intf_get_ae_compensation( uint32_t ctx_id )
2450 {
2451     return isp_fw_do_get_ae_compensation( ctx_id );
2452 }
2453 
fw_intf_get_custom_snr_manual(uint32_t ctx_id)2454 int fw_intf_get_custom_snr_manual(uint32_t ctx_id)
2455 {
2456     return isp_fw_do_get_snr_manual(ctx_id);
2457 }
2458 
fw_intf_get_custom_snr_strength(uint32_t ctx_id)2459 int fw_intf_get_custom_snr_strength(uint32_t ctx_id)
2460 {
2461     return isp_fw_do_get_snr_strength(ctx_id);
2462 }
2463 
fw_intf_get_custom_tnr_manual(uint32_t ctx_id)2464 int fw_intf_get_custom_tnr_manual(uint32_t ctx_id)
2465 {
2466     return isp_fw_do_get_tnr_manual(ctx_id);
2467 }
2468 
fw_intf_get_custom_tnr_offset(uint32_t ctx_id)2469 int fw_intf_get_custom_tnr_offset(uint32_t ctx_id)
2470 {
2471     return isp_fw_do_get_tnr_offset(ctx_id);
2472 }
2473 
fw_intf_get_custom_temper_mode(uint32_t ctx_id)2474 int fw_intf_get_custom_temper_mode(uint32_t ctx_id)
2475 {
2476     return settings[ctx_id].temper_frames_number;
2477 }
2478