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