1 /* SPDX-License-Identifier: GPL-2.0 */
2 /*
3  * Support for Medifield PNW Camera Imaging ISP subsystem.
4  *
5  * Copyright (c) 2010 Intel Corporation. All Rights Reserved.
6  *
7  * Copyright (c) 2010 Silicon Hive www.siliconhive.com.
8  *
9  * This program is free software; you can redistribute it and/or
10  * modify it under the terms of the GNU General Public License version
11  * 2 as published by the Free Software Foundation.
12  *
13  * This program is distributed in the hope that it will be useful,
14  * but WITHOUT ANY WARRANTY; without even the implied warranty of
15  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
16  * GNU General Public License for more details.
17  *
18  *
19  */
20 
21 #ifndef	__ATOMISP_CMD_H__
22 #define	__ATOMISP_CMD_H__
23 
24 #include "../../include/linux/atomisp.h"
25 #include <linux/interrupt.h>
26 #include <linux/videodev2.h>
27 
28 #include <media/v4l2-subdev.h>
29 
30 #include "atomisp_internal.h"
31 
32 #include "ia_css_types.h"
33 #include "ia_css.h"
34 
35 struct atomisp_device;
36 struct ia_css_frame;
37 
38 #define MSI_ENABLE_BIT		16
39 #define INTR_DISABLE_BIT	10
40 #define BUS_MASTER_ENABLE	2
41 #define MEMORY_SPACE_ENABLE	1
42 #define INTR_IER		24
43 #define INTR_IIR		16
44 
45 /* Helper function */
46 void dump_sp_dmem(struct atomisp_device *isp, unsigned int addr,
47 		  unsigned int size);
48 struct camera_mipi_info *atomisp_to_sensor_mipi_info(struct v4l2_subdev *sd);
49 struct atomisp_video_pipe *atomisp_to_video_pipe(struct video_device *dev);
50 int atomisp_reset(struct atomisp_device *isp);
51 int atomisp_buffers_in_css(struct atomisp_video_pipe *pipe);
52 void atomisp_buffer_done(struct ia_css_frame *frame, enum vb2_buffer_state state);
53 void atomisp_flush_video_pipe(struct atomisp_video_pipe *pipe, enum vb2_buffer_state state,
54 			      bool warn_on_css_frames);
55 void atomisp_clear_css_buffer_counters(struct atomisp_sub_device *asd);
56 
57 /* Interrupt functions */
58 void atomisp_msi_irq_init(struct atomisp_device *isp);
59 void atomisp_msi_irq_uninit(struct atomisp_device *isp);
60 void atomisp_assert_recovery_work(struct work_struct *work);
61 void atomisp_setup_flash(struct atomisp_sub_device *asd);
62 irqreturn_t atomisp_isr(int irq, void *dev);
63 irqreturn_t atomisp_isr_thread(int irq, void *isp_ptr);
64 const struct atomisp_format_bridge *get_atomisp_format_bridge_from_mbus(
65     u32 mbus_code);
66 bool atomisp_is_mbuscode_raw(uint32_t code);
67 
68 /* Get internal fmt according to V4L2 fmt */
69 bool atomisp_is_viewfinder_support(struct atomisp_device *isp);
70 
71 /* ISP features control function */
72 
73 /*
74  * Function to enable/disable lens geometry distortion correction (GDC) and
75  * chromatic aberration correction (CAC)
76  */
77 int atomisp_gdc_cac(struct atomisp_sub_device *asd, int flag,
78 		    __s32 *value);
79 
80 /* Function to enable/disable low light mode (including ANR) */
81 int atomisp_low_light(struct atomisp_sub_device *asd, int flag,
82 		      __s32 *value);
83 
84 /*
85  * Function to enable/disable extra noise reduction (XNR) in low light
86  * condition
87  */
88 int atomisp_xnr(struct atomisp_sub_device *asd, int flag, int *arg);
89 
90 int atomisp_formats(struct atomisp_sub_device *asd, int flag,
91 		    struct atomisp_formats_config *config);
92 
93 /* Function to configure noise reduction */
94 int atomisp_nr(struct atomisp_sub_device *asd, int flag,
95 	       struct atomisp_nr_config *config);
96 
97 /* Function to configure temporal noise reduction (TNR) */
98 int atomisp_tnr(struct atomisp_sub_device *asd, int flag,
99 		struct atomisp_tnr_config *config);
100 
101 /* Function to configure black level compensation */
102 int atomisp_black_level(struct atomisp_sub_device *asd, int flag,
103 			struct atomisp_ob_config *config);
104 
105 /* Function to configure edge enhancement */
106 int atomisp_ee(struct atomisp_sub_device *asd, int flag,
107 	       struct atomisp_ee_config *config);
108 
109 /* Function to update Gamma table for gamma, brightness and contrast config */
110 int atomisp_gamma(struct atomisp_sub_device *asd, int flag,
111 		  struct atomisp_gamma_table *config);
112 
113 /* Function to update Ctc table for Chroma Enhancement */
114 int atomisp_ctc(struct atomisp_sub_device *asd, int flag,
115 		struct atomisp_ctc_table *config);
116 
117 /* Function to update gamma correction parameters */
118 int atomisp_gamma_correction(struct atomisp_sub_device *asd, int flag,
119 			     struct atomisp_gc_config *config);
120 
121 /* Function to update Gdc table for gdc */
122 int atomisp_gdc_cac_table(struct atomisp_sub_device *asd, int flag,
123 			  struct atomisp_morph_table *config);
124 
125 /* Function to update table for macc */
126 int atomisp_macc_table(struct atomisp_sub_device *asd, int flag,
127 		       struct atomisp_macc_config *config);
128 
129 /* Function to get DIS statistics. */
130 int atomisp_get_dis_stat(struct atomisp_sub_device *asd,
131 			 struct atomisp_dis_statistics *stats);
132 
133 /* Function to get DVS2 BQ resolution settings */
134 int atomisp_get_dvs2_bq_resolutions(struct atomisp_sub_device *asd,
135 				    struct atomisp_dvs2_bq_resolutions *bq_res);
136 
137 /* Function to set the DIS coefficients. */
138 int atomisp_set_dis_coefs(struct atomisp_sub_device *asd,
139 			  struct atomisp_dis_coefficients *coefs);
140 
141 /* Function to set the DIS motion vector. */
142 int atomisp_set_dis_vector(struct atomisp_sub_device *asd,
143 			   struct atomisp_dis_vector *vector);
144 
145 /* Function to set/get 3A stat from isp */
146 int atomisp_3a_stat(struct atomisp_sub_device *asd, int flag,
147 		    struct atomisp_3a_statistics *config);
148 
149 int atomisp_set_parameters(struct video_device *vdev,
150 			   struct atomisp_parameters *arg);
151 
152 /* Function to set/get isp parameters to isp */
153 int atomisp_param(struct atomisp_sub_device *asd, int flag,
154 		  struct atomisp_parm *config);
155 
156 /* Function to configure color effect of the image */
157 int atomisp_color_effect(struct atomisp_sub_device *asd, int flag,
158 			 __s32 *effect);
159 
160 /* Function to configure bad pixel correction */
161 int atomisp_bad_pixel(struct atomisp_sub_device *asd, int flag,
162 		      __s32 *value);
163 
164 /* Function to configure bad pixel correction params */
165 int atomisp_bad_pixel_param(struct atomisp_sub_device *asd, int flag,
166 			    struct atomisp_dp_config *config);
167 
168 /* Function to enable/disable video image stablization */
169 int atomisp_video_stable(struct atomisp_sub_device *asd, int flag,
170 			 __s32 *value);
171 
172 /* Function to configure fixed pattern noise */
173 int atomisp_fixed_pattern(struct atomisp_sub_device *asd, int flag,
174 			  __s32 *value);
175 
176 /* Function to configure fixed pattern noise table */
177 int atomisp_fixed_pattern_table(struct atomisp_sub_device *asd,
178 				struct v4l2_framebuffer *config);
179 
180 /* Function to configure false color correction */
181 int atomisp_false_color(struct atomisp_sub_device *asd, int flag,
182 			__s32 *value);
183 
184 /* Function to configure false color correction params */
185 int atomisp_false_color_param(struct atomisp_sub_device *asd, int flag,
186 			      struct atomisp_de_config *config);
187 
188 /* Function to configure white balance params */
189 int atomisp_white_balance_param(struct atomisp_sub_device *asd, int flag,
190 				struct atomisp_wb_config *config);
191 
192 int atomisp_3a_config_param(struct atomisp_sub_device *asd, int flag,
193 			    struct atomisp_3a_config *config);
194 
195 /* Function to setup digital zoom */
196 int atomisp_digital_zoom(struct atomisp_sub_device *asd, int flag,
197 			 __s32 *value);
198 
199 /* Function  set camera_prefiles.xml current sensor pixel array size */
200 int atomisp_set_array_res(struct atomisp_sub_device *asd,
201 			  struct atomisp_resolution  *config);
202 
203 /* Function to calculate real zoom region for every pipe */
204 int atomisp_calculate_real_zoom_region(struct atomisp_sub_device *asd,
205 				       struct ia_css_dz_config   *dz_config,
206 				       enum ia_css_pipe_id css_pipe_id);
207 
208 int atomisp_cp_general_isp_parameters(struct atomisp_sub_device *asd,
209 				      struct atomisp_parameters *arg,
210 				      struct atomisp_css_params *css_param,
211 				      bool from_user);
212 
213 int atomisp_cp_lsc_table(struct atomisp_sub_device *asd,
214 			 struct atomisp_shading_table *source_st,
215 			 struct atomisp_css_params *css_param,
216 			 bool from_user);
217 
218 int atomisp_css_cp_dvs2_coefs(struct atomisp_sub_device *asd,
219 			      struct ia_css_dvs2_coefficients *coefs,
220 			      struct atomisp_css_params *css_param,
221 			      bool from_user);
222 
223 int atomisp_cp_morph_table(struct atomisp_sub_device *asd,
224 			   struct atomisp_morph_table *source_morph_table,
225 			   struct atomisp_css_params *css_param,
226 			   bool from_user);
227 
228 int atomisp_cp_dvs_6axis_config(struct atomisp_sub_device *asd,
229 				struct atomisp_dvs_6axis_config *user_6axis_config,
230 				struct atomisp_css_params *css_param,
231 				bool from_user);
232 
233 int atomisp_makeup_css_parameters(struct atomisp_sub_device *asd,
234 				  struct atomisp_parameters *arg,
235 				  struct atomisp_css_params *css_param);
236 
237 int atomisp_compare_grid(struct atomisp_sub_device *asd,
238 			 struct atomisp_grid_info *atomgrid);
239 
240 /* Get sensor padding values for the non padded width x height resolution */
241 void atomisp_get_padding(struct atomisp_device *isp, u32 width, u32 height,
242 			 u32 *padding_w, u32 *padding_h);
243 
244 /* This function looks up the closest available resolution. */
245 int atomisp_try_fmt(struct atomisp_device *isp, struct v4l2_pix_format *f,
246 		    const struct atomisp_format_bridge **fmt_ret,
247 		    const struct atomisp_format_bridge **snr_fmt_ret);
248 
249 int atomisp_set_fmt(struct video_device *vdev, struct v4l2_format *f);
250 
251 int atomisp_set_shading_table(struct atomisp_sub_device *asd,
252 			      struct atomisp_shading_table *shading_table);
253 
254 void atomisp_free_internal_buffers(struct atomisp_sub_device *asd);
255 
256 int  atomisp_flash_enable(struct atomisp_sub_device *asd,
257 			  int num_frames);
258 
259 int atomisp_freq_scaling(struct atomisp_device *vdev,
260 			 enum atomisp_dfs_mode mode,
261 			 bool force);
262 
263 void atomisp_buf_done(struct atomisp_sub_device *asd, int error,
264 		      enum ia_css_buffer_type buf_type,
265 		      enum ia_css_pipe_id css_pipe_id,
266 		      bool q_buffers, enum atomisp_input_stream_id stream_id);
267 
268 /* Events. Only one event has to be exported for now. */
269 void atomisp_eof_event(struct atomisp_sub_device *asd, uint8_t exp_id);
270 
271 enum mipi_port_id atomisp_port_to_mipi_port(struct atomisp_device *isp,
272 					    enum atomisp_camera_port port);
273 
274 void atomisp_apply_css_parameters(
275     struct atomisp_sub_device *asd,
276     struct atomisp_css_params *css_param);
277 void atomisp_free_css_parameters(struct atomisp_css_params *css_param);
278 
279 void atomisp_handle_parameter_and_buffer(struct atomisp_video_pipe *pipe);
280 
281 void atomisp_flush_params_queue(struct atomisp_video_pipe *asd);
282 
283 /* Function to do Raw Buffer related operation, after enable Lock Unlock Raw Buffer */
284 int atomisp_exp_id_unlock(struct atomisp_sub_device *asd, int *exp_id);
285 int atomisp_exp_id_capture(struct atomisp_sub_device *asd, int *exp_id);
286 
287 void atomisp_init_raw_buffer_bitmap(struct atomisp_sub_device *asd);
288 
289 /* Function to enable/disable zoom for capture pipe */
290 int atomisp_enable_dz_capt_pipe(struct atomisp_sub_device *asd,
291 				unsigned int *enable);
292 
293 u32 atomisp_get_pixel_depth(u32 pixelformat);
294 
295 /* Function for HAL to inject a fake event to wake up poll thread */
296 int atomisp_inject_a_fake_event(struct atomisp_sub_device *asd, int *event);
297 
298 /*
299  * Function for HAL to query how many invalid frames at the beginning of ISP
300  * pipeline output
301  */
302 int atomisp_get_invalid_frame_num(struct video_device *vdev,
303 				  int *invalid_frame_num);
304 
305 int atomisp_power_off(struct device *dev);
306 int atomisp_power_on(struct device *dev);
307 #endif /* __ATOMISP_CMD_H__ */
308