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 /* ISP2401 */
46 #define RUNMODE_MASK (ATOMISP_RUN_MODE_VIDEO | ATOMISP_RUN_MODE_STILL_CAPTURE \
47 			| ATOMISP_RUN_MODE_PREVIEW)
48 
49 /* FIXME: check if can go */
50 extern int atomisp_punit_hpll_freq;
51 
52 /* Helper function */
53 void dump_sp_dmem(struct atomisp_device *isp, unsigned int addr,
54 		  unsigned int size);
55 struct camera_mipi_info *atomisp_to_sensor_mipi_info(struct v4l2_subdev *sd);
56 struct atomisp_video_pipe *atomisp_to_video_pipe(struct video_device *dev);
57 int atomisp_reset(struct atomisp_device *isp);
58 int atomisp_buffers_in_css(struct atomisp_video_pipe *pipe);
59 void atomisp_buffer_done(struct ia_css_frame *frame, enum vb2_buffer_state state);
60 void atomisp_flush_video_pipe(struct atomisp_video_pipe *pipe, enum vb2_buffer_state state,
61 			      bool warn_on_css_frames);
62 void atomisp_clear_css_buffer_counters(struct atomisp_sub_device *asd);
63 
64 /* Interrupt functions */
65 void atomisp_msi_irq_init(struct atomisp_device *isp);
66 void atomisp_msi_irq_uninit(struct atomisp_device *isp);
67 void atomisp_assert_recovery_work(struct work_struct *work);
68 void atomisp_setup_flash(struct atomisp_sub_device *asd);
69 irqreturn_t atomisp_isr(int irq, void *dev);
70 irqreturn_t atomisp_isr_thread(int irq, void *isp_ptr);
71 const struct atomisp_format_bridge *get_atomisp_format_bridge_from_mbus(
72     u32 mbus_code);
73 bool atomisp_is_mbuscode_raw(uint32_t code);
74 
75 /* Get internal fmt according to V4L2 fmt */
76 bool atomisp_is_viewfinder_support(struct atomisp_device *isp);
77 
78 /* ISP features control function */
79 
80 /*
81  * Function to set sensor runmode by user when
82  * ATOMISP_IOC_S_SENSOR_RUNMODE ioctl was called
83  */
84 int atomisp_set_sensor_runmode(struct atomisp_sub_device *asd,
85 			       struct atomisp_s_runmode *runmode);
86 /*
87  * Function to enable/disable lens geometry distortion correction (GDC) and
88  * chromatic aberration correction (CAC)
89  */
90 int atomisp_gdc_cac(struct atomisp_sub_device *asd, int flag,
91 		    __s32 *value);
92 
93 /* Function to enable/disable low light mode (including ANR) */
94 int atomisp_low_light(struct atomisp_sub_device *asd, int flag,
95 		      __s32 *value);
96 
97 /*
98  * Function to enable/disable extra noise reduction (XNR) in low light
99  * condition
100  */
101 int atomisp_xnr(struct atomisp_sub_device *asd, int flag, int *arg);
102 
103 int atomisp_formats(struct atomisp_sub_device *asd, int flag,
104 		    struct atomisp_formats_config *config);
105 
106 /* Function to configure noise reduction */
107 int atomisp_nr(struct atomisp_sub_device *asd, int flag,
108 	       struct atomisp_nr_config *config);
109 
110 /* Function to configure temporal noise reduction (TNR) */
111 int atomisp_tnr(struct atomisp_sub_device *asd, int flag,
112 		struct atomisp_tnr_config *config);
113 
114 /* Function to configure black level compensation */
115 int atomisp_black_level(struct atomisp_sub_device *asd, int flag,
116 			struct atomisp_ob_config *config);
117 
118 /* Function to configure edge enhancement */
119 int atomisp_ee(struct atomisp_sub_device *asd, int flag,
120 	       struct atomisp_ee_config *config);
121 
122 /* Function to update Gamma table for gamma, brightness and contrast config */
123 int atomisp_gamma(struct atomisp_sub_device *asd, int flag,
124 		  struct atomisp_gamma_table *config);
125 
126 /* Function to update Ctc table for Chroma Enhancement */
127 int atomisp_ctc(struct atomisp_sub_device *asd, int flag,
128 		struct atomisp_ctc_table *config);
129 
130 /* Function to update gamma correction parameters */
131 int atomisp_gamma_correction(struct atomisp_sub_device *asd, int flag,
132 			     struct atomisp_gc_config *config);
133 
134 /* Function to update Gdc table for gdc */
135 int atomisp_gdc_cac_table(struct atomisp_sub_device *asd, int flag,
136 			  struct atomisp_morph_table *config);
137 
138 /* Function to update table for macc */
139 int atomisp_macc_table(struct atomisp_sub_device *asd, int flag,
140 		       struct atomisp_macc_config *config);
141 
142 /* Function to get DIS statistics. */
143 int atomisp_get_dis_stat(struct atomisp_sub_device *asd,
144 			 struct atomisp_dis_statistics *stats);
145 
146 /* Function to get DVS2 BQ resolution settings */
147 int atomisp_get_dvs2_bq_resolutions(struct atomisp_sub_device *asd,
148 				    struct atomisp_dvs2_bq_resolutions *bq_res);
149 
150 /* Function to set the DIS coefficients. */
151 int atomisp_set_dis_coefs(struct atomisp_sub_device *asd,
152 			  struct atomisp_dis_coefficients *coefs);
153 
154 /* Function to set the DIS motion vector. */
155 int atomisp_set_dis_vector(struct atomisp_sub_device *asd,
156 			   struct atomisp_dis_vector *vector);
157 
158 /* Function to set/get 3A stat from isp */
159 int atomisp_3a_stat(struct atomisp_sub_device *asd, int flag,
160 		    struct atomisp_3a_statistics *config);
161 
162 int atomisp_set_parameters(struct video_device *vdev,
163 			   struct atomisp_parameters *arg);
164 
165 /* Function to set/get isp parameters to isp */
166 int atomisp_param(struct atomisp_sub_device *asd, int flag,
167 		  struct atomisp_parm *config);
168 
169 /* Function to configure color effect of the image */
170 int atomisp_color_effect(struct atomisp_sub_device *asd, int flag,
171 			 __s32 *effect);
172 
173 /* Function to configure bad pixel correction */
174 int atomisp_bad_pixel(struct atomisp_sub_device *asd, int flag,
175 		      __s32 *value);
176 
177 /* Function to configure bad pixel correction params */
178 int atomisp_bad_pixel_param(struct atomisp_sub_device *asd, int flag,
179 			    struct atomisp_dp_config *config);
180 
181 /* Function to enable/disable video image stablization */
182 int atomisp_video_stable(struct atomisp_sub_device *asd, int flag,
183 			 __s32 *value);
184 
185 /* Function to configure fixed pattern noise */
186 int atomisp_fixed_pattern(struct atomisp_sub_device *asd, int flag,
187 			  __s32 *value);
188 
189 /* Function to configure fixed pattern noise table */
190 int atomisp_fixed_pattern_table(struct atomisp_sub_device *asd,
191 				struct v4l2_framebuffer *config);
192 
193 /* Function to configure false color correction */
194 int atomisp_false_color(struct atomisp_sub_device *asd, int flag,
195 			__s32 *value);
196 
197 /* Function to configure false color correction params */
198 int atomisp_false_color_param(struct atomisp_sub_device *asd, int flag,
199 			      struct atomisp_de_config *config);
200 
201 /* Function to configure white balance params */
202 int atomisp_white_balance_param(struct atomisp_sub_device *asd, int flag,
203 				struct atomisp_wb_config *config);
204 
205 int atomisp_3a_config_param(struct atomisp_sub_device *asd, int flag,
206 			    struct atomisp_3a_config *config);
207 
208 /* Function to setup digital zoom */
209 int atomisp_digital_zoom(struct atomisp_sub_device *asd, int flag,
210 			 __s32 *value);
211 
212 /* Function  set camera_prefiles.xml current sensor pixel array size */
213 int atomisp_set_array_res(struct atomisp_sub_device *asd,
214 			  struct atomisp_resolution  *config);
215 
216 /* Function to calculate real zoom region for every pipe */
217 int atomisp_calculate_real_zoom_region(struct atomisp_sub_device *asd,
218 				       struct ia_css_dz_config   *dz_config,
219 				       enum ia_css_pipe_id css_pipe_id);
220 
221 int atomisp_cp_general_isp_parameters(struct atomisp_sub_device *asd,
222 				      struct atomisp_parameters *arg,
223 				      struct atomisp_css_params *css_param,
224 				      bool from_user);
225 
226 int atomisp_cp_lsc_table(struct atomisp_sub_device *asd,
227 			 struct atomisp_shading_table *source_st,
228 			 struct atomisp_css_params *css_param,
229 			 bool from_user);
230 
231 int atomisp_css_cp_dvs2_coefs(struct atomisp_sub_device *asd,
232 			      struct ia_css_dvs2_coefficients *coefs,
233 			      struct atomisp_css_params *css_param,
234 			      bool from_user);
235 
236 int atomisp_cp_morph_table(struct atomisp_sub_device *asd,
237 			   struct atomisp_morph_table *source_morph_table,
238 			   struct atomisp_css_params *css_param,
239 			   bool from_user);
240 
241 int atomisp_cp_dvs_6axis_config(struct atomisp_sub_device *asd,
242 				struct atomisp_dvs_6axis_config *user_6axis_config,
243 				struct atomisp_css_params *css_param,
244 				bool from_user);
245 
246 int atomisp_makeup_css_parameters(struct atomisp_sub_device *asd,
247 				  struct atomisp_parameters *arg,
248 				  struct atomisp_css_params *css_param);
249 
250 int atomisp_compare_grid(struct atomisp_sub_device *asd,
251 			 struct atomisp_grid_info *atomgrid);
252 
253 /* Get sensor padding values for the non padded width x height resolution */
254 void atomisp_get_padding(struct atomisp_device *isp, u32 width, u32 height,
255 			 u32 *padding_w, u32 *padding_h);
256 
257 /* This function looks up the closest available resolution. */
258 int atomisp_try_fmt(struct atomisp_device *isp, struct v4l2_pix_format *f,
259 		    const struct atomisp_format_bridge **fmt_ret,
260 		    const struct atomisp_format_bridge **snr_fmt_ret);
261 
262 int atomisp_set_fmt(struct video_device *vdev, struct v4l2_format *f);
263 
264 int atomisp_set_shading_table(struct atomisp_sub_device *asd,
265 			      struct atomisp_shading_table *shading_table);
266 
267 void atomisp_free_internal_buffers(struct atomisp_sub_device *asd);
268 
269 int  atomisp_flash_enable(struct atomisp_sub_device *asd,
270 			  int num_frames);
271 
272 int atomisp_freq_scaling(struct atomisp_device *vdev,
273 			 enum atomisp_dfs_mode mode,
274 			 bool force);
275 
276 void atomisp_buf_done(struct atomisp_sub_device *asd, int error,
277 		      enum ia_css_buffer_type buf_type,
278 		      enum ia_css_pipe_id css_pipe_id,
279 		      bool q_buffers, enum atomisp_input_stream_id stream_id);
280 
281 /* Events. Only one event has to be exported for now. */
282 void atomisp_eof_event(struct atomisp_sub_device *asd, uint8_t exp_id);
283 
284 enum mipi_port_id atomisp_port_to_mipi_port(struct atomisp_device *isp,
285 					    enum atomisp_camera_port port);
286 
287 void atomisp_apply_css_parameters(
288     struct atomisp_sub_device *asd,
289     struct atomisp_css_params *css_param);
290 void atomisp_free_css_parameters(struct atomisp_css_params *css_param);
291 
292 void atomisp_handle_parameter_and_buffer(struct atomisp_video_pipe *pipe);
293 
294 void atomisp_flush_params_queue(struct atomisp_video_pipe *asd);
295 
296 /* Function to do Raw Buffer related operation, after enable Lock Unlock Raw Buffer */
297 int atomisp_exp_id_unlock(struct atomisp_sub_device *asd, int *exp_id);
298 int atomisp_exp_id_capture(struct atomisp_sub_device *asd, int *exp_id);
299 
300 void atomisp_init_raw_buffer_bitmap(struct atomisp_sub_device *asd);
301 
302 /* Function to enable/disable zoom for capture pipe */
303 int atomisp_enable_dz_capt_pipe(struct atomisp_sub_device *asd,
304 				unsigned int *enable);
305 
306 u32 atomisp_get_pixel_depth(u32 pixelformat);
307 
308 /* Function for HAL to inject a fake event to wake up poll thread */
309 int atomisp_inject_a_fake_event(struct atomisp_sub_device *asd, int *event);
310 
311 /*
312  * Function for HAL to query how many invalid frames at the beginning of ISP
313  * pipeline output
314  */
315 int atomisp_get_invalid_frame_num(struct video_device *vdev,
316 				  int *invalid_frame_num);
317 
318 int atomisp_power_off(struct device *dev);
319 int atomisp_power_on(struct device *dev);
320 #endif /* __ATOMISP_CMD_H__ */
321