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