1 /* 2 * Support for Intel Camera Imaging ISP subsystem. 3 * Copyright (c) 2015, Intel Corporation. 4 * 5 * This program is free software; you can redistribute it and/or modify it 6 * under the terms and conditions of the GNU General Public License, 7 * version 2, as published by the Free Software Foundation. 8 * 9 * This program is distributed in the hope it will be useful, but WITHOUT 10 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 11 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for 12 * more details. 13 */ 14 15 #include "ia_css_types.h" 16 #include "ia_css_frame.h" 17 #include "sh_css_defs.h" 18 #include "ia_css_debug.h" 19 #include "sh_css_frac.h" 20 #include "assert_support.h" 21 #define IA_CSS_INCLUDE_CONFIGURATIONS 22 #include "ia_css_isp_configs.h" 23 #include "isp.h" 24 25 #include "ia_css_tnr.host.h" 26 const struct ia_css_tnr_config default_tnr_config = { 27 32768, 28 32, 29 32, 30 }; 31 32 void 33 ia_css_tnr_encode( 34 struct sh_css_isp_tnr_params *to, 35 const struct ia_css_tnr_config *from, 36 unsigned int size) 37 { 38 (void)size; 39 to->coef = 40 uDIGIT_FITTING(from->gain, 16, SH_CSS_TNR_COEF_SHIFT); 41 to->threshold_Y = 42 uDIGIT_FITTING(from->threshold_y, 16, SH_CSS_ISP_YUV_BITS); 43 to->threshold_C = 44 uDIGIT_FITTING(from->threshold_uv, 16, SH_CSS_ISP_YUV_BITS); 45 } 46 47 void 48 ia_css_tnr_dump( 49 const struct sh_css_isp_tnr_params *tnr, 50 unsigned int level) 51 { 52 if (!tnr) return; 53 ia_css_debug_dtrace(level, "Temporal Noise Reduction:\n"); 54 ia_css_debug_dtrace(level, "\t%-32s = %d\n", 55 "tnr_coef", tnr->coef); 56 ia_css_debug_dtrace(level, "\t%-32s = %d\n", 57 "tnr_threshold_Y", tnr->threshold_Y); 58 ia_css_debug_dtrace(level, "\t%-32s = %d\n", 59 "tnr_threshold_C", tnr->threshold_C); 60 } 61 62 void 63 ia_css_tnr_debug_dtrace( 64 const struct ia_css_tnr_config *config, 65 unsigned int level) 66 { 67 ia_css_debug_dtrace(level, 68 "config.gain=%d, config.threshold_y=%d, config.threshold_uv=%d\n", 69 config->gain, 70 config->threshold_y, config->threshold_uv); 71 } 72 73 void 74 ia_css_tnr_config( 75 struct sh_css_isp_tnr_isp_config *to, 76 const struct ia_css_tnr_configuration *from, 77 unsigned int size) 78 { 79 unsigned int elems_a = ISP_VEC_NELEMS; 80 unsigned int i; 81 82 (void)size; 83 ia_css_dma_configure_from_info(&to->port_b, &from->tnr_frames[0]->info); 84 to->width_a_over_b = elems_a / to->port_b.elems; 85 to->frame_height = from->tnr_frames[0]->info.res.height; 86 for (i = 0; i < NUM_TNR_FRAMES; i++) { 87 to->tnr_frame_addr[i] = from->tnr_frames[i]->data + 88 from->tnr_frames[i]->planes.yuyv.offset; 89 } 90 91 /* Assume divisiblity here, may need to generalize to fixed point. */ 92 assert(elems_a % to->port_b.elems == 0); 93 } 94 95 void 96 ia_css_tnr_configure( 97 const struct ia_css_binary *binary, 98 const struct ia_css_frame * const *frames) 99 { 100 struct ia_css_tnr_configuration config; 101 unsigned int i; 102 103 for (i = 0; i < NUM_TNR_FRAMES; i++) 104 config.tnr_frames[i] = frames[i]; 105 106 ia_css_configure_tnr(binary, &config); 107 } 108 109 void 110 ia_css_init_tnr_state( 111 struct sh_css_isp_tnr_dmem_state *state, 112 size_t size) 113 { 114 (void)size; 115 116 assert(NUM_TNR_FRAMES >= 2); 117 assert(sizeof(*state) == size); 118 state->tnr_in_buf_idx = 0; 119 state->tnr_out_buf_idx = 1; 120 } 121