GNU Linux-libre 4.14.266-gnu1
[releases.git] / drivers / staging / media / atomisp / pci / atomisp2 / atomisp_cmd.h
1 /*
2  * Support for Medifield PNW Camera Imaging ISP subsystem.
3  *
4  * Copyright (c) 2010 Intel Corporation. All Rights Reserved.
5  *
6  * Copyright (c) 2010 Silicon Hive www.siliconhive.com.
7  *
8  * This program is free software; you can redistribute it and/or
9  * modify it under the terms of the GNU General Public License version
10  * 2 as published by the Free Software Foundation.
11  *
12  * This program is distributed in the hope that it will be useful,
13  * but WITHOUT ANY WARRANTY; without even the implied warranty of
14  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
15  * GNU General Public License for more details.
16  *
17  * You should have received a copy of the GNU General Public License
18  * along with this program; if not, write to the Free Software
19  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
20  * 02110-1301, USA.
21  *
22  */
23
24 #ifndef __ATOMISP_CMD_H__
25 #define __ATOMISP_CMD_H__
26
27 #include "../../include/linux/atomisp.h"
28 #include <linux/interrupt.h>
29 #include <linux/videodev2.h>
30
31 #include <media/v4l2-subdev.h>
32
33 #include "atomisp_internal.h"
34
35 #include "ia_css_types.h"
36 #include "ia_css.h"
37
38 struct atomisp_device;
39 struct atomisp_css_frame;
40
41 #define MSI_ENABLE_BIT          16
42 #define INTR_DISABLE_BIT        10
43 #define BUS_MASTER_ENABLE       2
44 #define MEMORY_SPACE_ENABLE     1
45 #define INTR_IER                24
46 #define INTR_IIR                16
47 #ifdef ISP2401
48 #define RUNMODE_MASK (ATOMISP_RUN_MODE_VIDEO | ATOMISP_RUN_MODE_STILL_CAPTURE \
49                         | ATOMISP_RUN_MODE_PREVIEW)
50
51 /* FIXME: check if can go */
52 extern int atomisp_punit_hpll_freq;
53 #endif
54
55 /*
56  * Helper function
57  */
58 void dump_sp_dmem(struct atomisp_device *isp, unsigned int addr,
59                   unsigned int size);
60 struct camera_mipi_info *atomisp_to_sensor_mipi_info(struct v4l2_subdev *sd);
61 struct atomisp_video_pipe *atomisp_to_video_pipe(struct video_device *dev);
62 struct atomisp_acc_pipe *atomisp_to_acc_pipe(struct video_device *dev);
63 int atomisp_reset(struct atomisp_device *isp);
64 void atomisp_flush_bufs_and_wakeup(struct atomisp_sub_device *asd);
65 void atomisp_clear_css_buffer_counters(struct atomisp_sub_device *asd);
66 #ifndef ISP2401
67 bool atomisp_buffers_queued(struct atomisp_sub_device *asd);
68 #else
69 bool atomisp_buffers_queued_pipe(struct atomisp_video_pipe *pipe);
70 #endif
71
72 /* TODO:should be here instead of atomisp_helper.h
73 extern void __iomem *atomisp_io_base;
74
75 static inline void __iomem *atomisp_get_io_virt_addr(unsigned int address)
76 {
77         void __iomem *ret = atomisp_io_base + (address & 0x003FFFFF);
78         return ret;
79 }
80 */
81
82 /*
83  * Interrupt functions
84  */
85 void atomisp_msi_irq_init(struct atomisp_device *isp, struct pci_dev *dev);
86 void atomisp_msi_irq_uninit(struct atomisp_device *isp, struct pci_dev *dev);
87 void atomisp_wdt_work(struct work_struct *work);
88 #ifndef ISP2401
89 void atomisp_wdt(unsigned long isp_addr);
90 #else
91 void atomisp_wdt(unsigned long pipe_addr);
92 #endif
93 void atomisp_setup_flash(struct atomisp_sub_device *asd);
94 irqreturn_t atomisp_isr(int irq, void *dev);
95 irqreturn_t atomisp_isr_thread(int irq, void *isp_ptr);
96 const struct atomisp_format_bridge *get_atomisp_format_bridge_from_mbus(
97         u32 mbus_code);
98 bool atomisp_is_mbuscode_raw(uint32_t code);
99 int atomisp_get_frame_pgnr(struct atomisp_device *isp,
100                            const struct atomisp_css_frame *frame, u32 *p_pgnr);
101 void atomisp_delayed_init_work(struct work_struct *work);
102
103 /*
104  * Get internal fmt according to V4L2 fmt
105  */
106
107 bool atomisp_is_viewfinder_support(struct atomisp_device *isp);
108
109 /*
110  * ISP features control function
111  */
112
113 /*
114 #ifdef ISP2401
115  * Function to set sensor runmode by user when
116  * ATOMISP_IOC_S_SENSOR_RUNMODE ioctl was called
117  */
118 int atomisp_set_sensor_runmode(struct atomisp_sub_device *asd,
119                 struct atomisp_s_runmode *runmode);
120 /*
121 #endif
122  * Function to enable/disable lens geometry distortion correction (GDC) and
123  * chromatic aberration correction (CAC)
124  */
125 int atomisp_gdc_cac(struct atomisp_sub_device *asd, int flag,
126                     __s32 *value);
127
128 /*
129  * Function to enable/disable low light mode (including ANR)
130  */
131 int atomisp_low_light(struct atomisp_sub_device *asd, int flag,
132                       __s32 *value);
133
134 /*
135  * Function to enable/disable extra noise reduction (XNR) in low light
136  * condition
137  */
138 int atomisp_xnr(struct atomisp_sub_device *asd, int flag, int *arg);
139
140 int atomisp_formats(struct atomisp_sub_device *asd, int flag,
141                 struct atomisp_formats_config *config);
142
143 /*
144  * Function to configure noise reduction
145  */
146 int atomisp_nr(struct atomisp_sub_device *asd, int flag,
147                struct atomisp_nr_config *config);
148
149 /*
150  * Function to configure temporal noise reduction (TNR)
151  */
152 int atomisp_tnr(struct atomisp_sub_device *asd, int flag,
153                 struct atomisp_tnr_config *config);
154
155 /*
156  * Function to configure black level compensation
157  */
158 int atomisp_black_level(struct atomisp_sub_device *asd, int flag,
159                         struct atomisp_ob_config *config);
160
161 /*
162  * Function to configure edge enhancement
163  */
164 int atomisp_ee(struct atomisp_sub_device *asd, int flag,
165                struct atomisp_ee_config *config);
166
167 /*
168  * Function to update Gamma table for gamma, brightness and contrast config
169  */
170 int atomisp_gamma(struct atomisp_sub_device *asd, int flag,
171                   struct atomisp_gamma_table *config);
172 /*
173  * Function to update Ctc table for Chroma Enhancement
174  */
175 int atomisp_ctc(struct atomisp_sub_device *asd, int flag,
176                 struct atomisp_ctc_table *config);
177
178 /*
179  * Function to update gamma correction parameters
180  */
181 int atomisp_gamma_correction(struct atomisp_sub_device *asd, int flag,
182         struct atomisp_gc_config *config);
183
184 /*
185  * Function to update Gdc table for gdc
186  */
187 int atomisp_gdc_cac_table(struct atomisp_sub_device *asd, int flag,
188                           struct atomisp_morph_table *config);
189
190 /*
191  * Function to update table for macc
192  */
193 int atomisp_macc_table(struct atomisp_sub_device *asd, int flag,
194                        struct atomisp_macc_config *config);
195 /*
196  * Function to get DIS statistics.
197  */
198 int atomisp_get_dis_stat(struct atomisp_sub_device *asd,
199                          struct atomisp_dis_statistics *stats);
200
201 /*
202  * Function to get DVS2 BQ resolution settings
203  */
204 int atomisp_get_dvs2_bq_resolutions(struct atomisp_sub_device *asd,
205                          struct atomisp_dvs2_bq_resolutions *bq_res);
206
207 /*
208  * Function to set the DIS coefficients.
209  */
210 int atomisp_set_dis_coefs(struct atomisp_sub_device *asd,
211                           struct atomisp_dis_coefficients *coefs);
212
213 /*
214  * Function to set the DIS motion vector.
215  */
216 int atomisp_set_dis_vector(struct atomisp_sub_device *asd,
217                            struct atomisp_dis_vector *vector);
218
219 /*
220  * Function to set/get 3A stat from isp
221  */
222 int atomisp_3a_stat(struct atomisp_sub_device *asd, int flag,
223                     struct atomisp_3a_statistics *config);
224
225 /*
226  * Function to get metadata from isp
227  */
228 int atomisp_get_metadata(struct atomisp_sub_device *asd, int flag,
229                          struct atomisp_metadata *config);
230
231 int atomisp_get_metadata_by_type(struct atomisp_sub_device *asd, int flag,
232                          struct atomisp_metadata_with_type *config);
233
234 int atomisp_set_parameters(struct video_device *vdev,
235                         struct atomisp_parameters *arg);
236 /*
237  * Function to set/get isp parameters to isp
238  */
239 int atomisp_param(struct atomisp_sub_device *asd, int flag,
240                   struct atomisp_parm *config);
241
242 /*
243  * Function to configure color effect of the image
244  */
245 int atomisp_color_effect(struct atomisp_sub_device *asd, int flag,
246                          __s32 *effect);
247
248 /*
249  * Function to configure bad pixel correction
250  */
251 int atomisp_bad_pixel(struct atomisp_sub_device *asd, int flag,
252                       __s32 *value);
253
254 /*
255  * Function to configure bad pixel correction params
256  */
257 int atomisp_bad_pixel_param(struct atomisp_sub_device *asd, int flag,
258                             struct atomisp_dp_config *config);
259
260 /*
261  * Function to enable/disable video image stablization
262  */
263 int atomisp_video_stable(struct atomisp_sub_device *asd, int flag,
264                          __s32 *value);
265
266 /*
267  * Function to configure fixed pattern noise
268  */
269 int atomisp_fixed_pattern(struct atomisp_sub_device *asd, int flag,
270                           __s32 *value);
271
272 /*
273  * Function to configure fixed pattern noise table
274  */
275 int atomisp_fixed_pattern_table(struct atomisp_sub_device *asd,
276                                 struct v4l2_framebuffer *config);
277
278 /*
279  * Function to configure false color correction
280  */
281 int atomisp_false_color(struct atomisp_sub_device *asd, int flag,
282                         __s32 *value);
283
284 /*
285  * Function to configure false color correction params
286  */
287 int atomisp_false_color_param(struct atomisp_sub_device *asd, int flag,
288                               struct atomisp_de_config *config);
289
290 /*
291  * Function to configure white balance params
292  */
293 int atomisp_white_balance_param(struct atomisp_sub_device *asd, int flag,
294                                 struct atomisp_wb_config *config);
295
296 int atomisp_3a_config_param(struct atomisp_sub_device *asd, int flag,
297                             struct atomisp_3a_config *config);
298
299 /*
300  * Function to setup digital zoom
301  */
302 int atomisp_digital_zoom(struct atomisp_sub_device *asd, int flag,
303                          __s32 *value);
304
305 /*
306  * Function  set camera_prefiles.xml current sensor pixel array size
307  */
308 int atomisp_set_array_res(struct atomisp_sub_device *asd,
309                         struct atomisp_resolution  *config);
310
311 /*
312  * Function to calculate real zoom region for every pipe
313  */
314 int atomisp_calculate_real_zoom_region(struct atomisp_sub_device *asd,
315                         struct atomisp_css_dz_config   *dz_config,
316                         enum atomisp_css_pipe_id css_pipe_id);
317
318 int atomisp_cp_general_isp_parameters(struct atomisp_sub_device *asd,
319                                       struct atomisp_parameters *arg,
320                                       struct atomisp_css_params *css_param,
321                                       bool from_user);
322
323 int atomisp_cp_lsc_table(struct atomisp_sub_device *asd,
324                          struct atomisp_shading_table *source_st,
325                          struct atomisp_css_params *css_param,
326                          bool from_user);
327
328 int atomisp_css_cp_dvs2_coefs(struct atomisp_sub_device *asd,
329                               struct ia_css_dvs2_coefficients *coefs,
330                               struct atomisp_css_params *css_param,
331                               bool from_user);
332
333 int atomisp_cp_morph_table(struct atomisp_sub_device *asd,
334                            struct atomisp_morph_table *source_morph_table,
335                            struct atomisp_css_params *css_param,
336                            bool from_user);
337
338 int atomisp_cp_dvs_6axis_config(struct atomisp_sub_device *asd,
339                         struct atomisp_dvs_6axis_config *user_6axis_config,
340                         struct atomisp_css_params *css_param,
341                         bool from_user);
342
343 int atomisp_makeup_css_parameters(struct atomisp_sub_device *asd,
344                                   struct atomisp_parameters *arg,
345                                   struct atomisp_css_params *css_param);
346
347 int atomisp_compare_grid(struct atomisp_sub_device *asd,
348                                 struct atomisp_grid_info *atomgrid);
349
350 int atomisp_get_sensor_mode_data(struct atomisp_sub_device *asd,
351                                  struct atomisp_sensor_mode_data *config);
352
353 int atomisp_get_fmt(struct video_device *vdev, struct v4l2_format *f);
354
355
356 /* This function looks up the closest available resolution. */
357 int atomisp_try_fmt(struct video_device *vdev, struct v4l2_format *f,
358                                                 bool *res_overflow);
359
360 int atomisp_set_fmt(struct video_device *vdev, struct v4l2_format *f);
361 int atomisp_set_fmt_file(struct video_device *vdev, struct v4l2_format *f);
362
363 int atomisp_set_shading_table(struct atomisp_sub_device *asd,
364                               struct atomisp_shading_table *shading_table);
365
366 int atomisp_offline_capture_configure(struct atomisp_sub_device *asd,
367                                 struct atomisp_cont_capture_conf *cvf_config);
368
369 int atomisp_ospm_dphy_down(struct atomisp_device *isp);
370 int atomisp_ospm_dphy_up(struct atomisp_device *isp);
371 int atomisp_exif_makernote(struct atomisp_sub_device *asd,
372                            struct atomisp_makernote_info *config);
373
374 void atomisp_free_internal_buffers(struct atomisp_sub_device *asd);
375
376 int atomisp_s_ae_window(struct atomisp_sub_device *asd,
377                         struct atomisp_ae_window *arg);
378
379 int  atomisp_flash_enable(struct atomisp_sub_device *asd,
380                           int num_frames);
381
382 int atomisp_freq_scaling(struct atomisp_device *vdev,
383                          enum atomisp_dfs_mode mode,
384                          bool force);
385
386 void atomisp_buf_done(struct atomisp_sub_device *asd, int error,
387                       enum atomisp_css_buffer_type buf_type,
388                       enum atomisp_css_pipe_id css_pipe_id,
389                       bool q_buffers, enum atomisp_input_stream_id stream_id);
390
391 void atomisp_css_flush(struct atomisp_device *isp);
392 int atomisp_source_pad_to_stream_id(struct atomisp_sub_device *asd,
393                                            uint16_t source_pad);
394
395 /*
396  * Events. Only one event has to be exported for now.
397  */
398 void atomisp_eof_event(struct atomisp_sub_device *asd, uint8_t exp_id);
399
400 mipi_port_ID_t __get_mipi_port(struct atomisp_device *isp,
401                                 enum atomisp_camera_port port);
402
403 bool atomisp_is_vf_pipe(struct atomisp_video_pipe *pipe);
404
405 void atomisp_apply_css_parameters(
406                                 struct atomisp_sub_device *asd,
407                                 struct atomisp_css_params *css_param);
408 void atomisp_free_css_parameters(struct atomisp_css_params *css_param);
409
410 void atomisp_handle_parameter_and_buffer(struct atomisp_video_pipe *pipe);
411
412 void atomisp_flush_params_queue(struct atomisp_video_pipe *asd);
413 /*
414  * Function to do Raw Buffer related operation, after enable Lock Unlock Raw Buffer
415  */
416 int atomisp_exp_id_unlock(struct atomisp_sub_device *asd, int *exp_id);
417 int atomisp_exp_id_capture(struct atomisp_sub_device *asd, int *exp_id);
418
419 /*
420  * Function to update Raw Buffer bitmap
421  */
422 int atomisp_set_raw_buffer_bitmap(struct atomisp_sub_device *asd, int exp_id);
423 void atomisp_init_raw_buffer_bitmap(struct atomisp_sub_device *asd);
424
425 /*
426  * Function to enable/disable zoom for capture pipe
427  */
428 int atomisp_enable_dz_capt_pipe(struct atomisp_sub_device *asd,
429                                            unsigned int *enable);
430
431 /*
432  * Function to get metadata type bu pipe id
433  */
434 enum atomisp_metadata_type
435 atomisp_get_metadata_type(struct atomisp_sub_device *asd,
436                           enum ia_css_pipe_id pipe_id);
437
438 /*
439  * Function for HAL to inject a fake event to wake up poll thread
440  */
441 int atomisp_inject_a_fake_event(struct atomisp_sub_device *asd, int *event);
442
443 /*
444  * Function for HAL to query how many invalid frames at the beginning of ISP
445  * pipeline output
446  */
447 int atomisp_get_invalid_frame_num(struct video_device *vdev,
448                         int *invalid_frame_num);
449
450 int atomisp_mrfld_power_up(struct atomisp_device *isp);
451 int atomisp_mrfld_power_down(struct atomisp_device *isp);
452 int atomisp_runtime_suspend(struct device *dev);
453 int atomisp_runtime_resume(struct device *dev);
454 #endif /* __ATOMISP_CMD_H__ */