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