]> git.proxmox.com Git - mirror_ubuntu-bionic-kernel.git/blob - drivers/staging/media/atomisp/pci/atomisp2/atomisp_subdev.h
ba5c2ab14253419e31f36019d0b777b1d290def3
[mirror_ubuntu-bionic-kernel.git] / drivers / staging / media / atomisp / pci / atomisp2 / atomisp_subdev.h
1 /*
2 * Support for Medifield PNW Camera Imaging ISP subsystem.
3 *
4 * Copyright (c) 2010 Intel Corporation. All Rights Reserved.
5 *
6 * This program is free software; you can redistribute it and/or
7 * modify it under the terms of the GNU General Public License version
8 * 2 as published by the Free Software Foundation.
9 *
10 * This program is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 * GNU General Public License for more details.
14 *
15 * You should have received a copy of the GNU General Public License
16 * along with this program; if not, write to the Free Software
17 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
18 * 02110-1301, USA.
19 *
20 */
21 #ifndef __ATOMISP_SUBDEV_H__
22 #define __ATOMISP_SUBDEV_H__
23
24 #include <media/v4l2-ctrls.h>
25 #include <media/v4l2-device.h>
26 #include <media/v4l2-subdev.h>
27 #include <media/videobuf-core.h>
28
29 #include "atomisp_common.h"
30 #include "atomisp_compat.h"
31 #include "atomisp_v4l2.h"
32
33 #include "ia_css.h"
34
35 /* EXP_ID's ranger is 1 ~ 250 */
36 #define ATOMISP_MAX_EXP_ID (250)
37 enum atomisp_subdev_input_entity {
38 ATOMISP_SUBDEV_INPUT_NONE,
39 ATOMISP_SUBDEV_INPUT_MEMORY,
40 ATOMISP_SUBDEV_INPUT_CSI2,
41 /*
42 * The following enum for CSI2 port must go together in one row.
43 * Otherwise it breaks the code logic.
44 */
45 ATOMISP_SUBDEV_INPUT_CSI2_PORT1,
46 ATOMISP_SUBDEV_INPUT_CSI2_PORT2,
47 ATOMISP_SUBDEV_INPUT_CSI2_PORT3,
48 };
49
50 #define ATOMISP_SUBDEV_PAD_SINK 0
51 /* capture output for still frames */
52 #define ATOMISP_SUBDEV_PAD_SOURCE_CAPTURE 1
53 /* viewfinder output for downscaled capture output */
54 #define ATOMISP_SUBDEV_PAD_SOURCE_VF 2
55 /* preview output for display */
56 #define ATOMISP_SUBDEV_PAD_SOURCE_PREVIEW 3
57 /* main output for video pipeline */
58 #define ATOMISP_SUBDEV_PAD_SOURCE_VIDEO 4
59 #define ATOMISP_SUBDEV_PADS_NUM 5
60
61 struct atomisp_in_fmt_conv {
62 u32 code;
63 uint8_t bpp; /* bits per pixel */
64 uint8_t depth; /* uncompressed */
65 enum atomisp_css_stream_format atomisp_in_fmt;
66 enum atomisp_css_bayer_order bayer_order;
67 enum ia_css_stream_format css_stream_fmt;
68 };
69
70 struct atomisp_sub_device;
71
72 struct atomisp_video_pipe {
73 struct video_device vdev;
74 enum v4l2_buf_type type;
75 struct media_pad pad;
76 struct videobuf_queue capq;
77 struct videobuf_queue outq;
78 struct list_head activeq;
79 struct list_head activeq_out;
80 /*
81 * the buffers waiting for per-frame parameters, this is only valid
82 * in per-frame setting mode.
83 */
84 struct list_head buffers_waiting_for_param;
85 /* the link list to store per_frame parameters */
86 struct list_head per_frame_params;
87
88 unsigned int buffers_in_css;
89
90 /* irq_lock is used to protect video buffer state change operations and
91 * also to make activeq, activeq_out, capq and outq list
92 * operations atomic. */
93 spinlock_t irq_lock;
94 unsigned int users;
95
96 struct atomisp_device *isp;
97 struct v4l2_pix_format pix;
98 uint32_t sh_fmt;
99
100 struct atomisp_sub_device *asd;
101
102 /*
103 * This frame_config_id is got from CSS when dequueues buffers from CSS,
104 * it is used to indicate which parameter it has applied.
105 */
106 unsigned int frame_config_id[VIDEO_MAX_FRAME];
107 /*
108 * This config id is set when camera HAL enqueues buffer, it has a
109 * non-zero value to indicate which parameter it needs to applu
110 */
111 unsigned int frame_request_config_id[VIDEO_MAX_FRAME];
112 struct atomisp_css_params_with_list *frame_params[VIDEO_MAX_FRAME];
113 #ifdef ISP2401
114
115 /*
116 * move wdt from asd struct to create wdt for each pipe
117 */
118 struct timer_list wdt;
119 unsigned int wdt_duration; /* in jiffies */
120 unsigned long wdt_expires;
121 atomic_t wdt_count;
122 #endif
123 };
124
125 struct atomisp_acc_pipe {
126 struct video_device vdev;
127 unsigned int users;
128 bool running;
129 struct atomisp_sub_device *asd;
130 struct atomisp_device *isp;
131 };
132
133 struct atomisp_pad_format {
134 struct v4l2_mbus_framefmt fmt;
135 struct v4l2_rect crop;
136 struct v4l2_rect compose;
137 };
138
139 /* Internal states for flash process */
140 enum atomisp_flash_state {
141 ATOMISP_FLASH_IDLE,
142 ATOMISP_FLASH_REQUESTED,
143 ATOMISP_FLASH_ONGOING,
144 ATOMISP_FLASH_DONE
145 };
146
147 /*
148 * This structure is used to cache the CSS parameters, it aligns to
149 * struct ia_css_isp_config but without un-supported and deprecated parts.
150 */
151 struct atomisp_css_params {
152 struct ia_css_wb_config wb_config;
153 struct ia_css_cc_config cc_config;
154 struct ia_css_tnr_config tnr_config;
155 struct ia_css_ecd_config ecd_config;
156 struct ia_css_ynr_config ynr_config;
157 struct ia_css_fc_config fc_config;
158 struct ia_css_formats_config formats_config;
159 struct ia_css_cnr_config cnr_config;
160 struct ia_css_macc_config macc_config;
161 struct ia_css_ctc_config ctc_config;
162 struct ia_css_aa_config aa_config;
163 struct ia_css_aa_config baa_config;
164 struct ia_css_ce_config ce_config;
165 struct ia_css_ob_config ob_config;
166 struct ia_css_dp_config dp_config;
167 struct ia_css_de_config de_config;
168 struct ia_css_gc_config gc_config;
169 struct ia_css_nr_config nr_config;
170 struct ia_css_ee_config ee_config;
171 struct ia_css_anr_config anr_config;
172 struct ia_css_3a_config s3a_config;
173 struct ia_css_xnr_config xnr_config;
174 struct ia_css_dz_config dz_config;
175 struct ia_css_cc_config yuv2rgb_cc_config;
176 struct ia_css_cc_config rgb2yuv_cc_config;
177 struct ia_css_macc_table macc_table;
178 struct ia_css_gamma_table gamma_table;
179 struct ia_css_ctc_table ctc_table;
180
181 struct ia_css_xnr_table xnr_table;
182 struct ia_css_rgb_gamma_table r_gamma_table;
183 struct ia_css_rgb_gamma_table g_gamma_table;
184 struct ia_css_rgb_gamma_table b_gamma_table;
185
186 struct ia_css_vector motion_vector;
187 struct ia_css_anr_thres anr_thres;
188
189 struct ia_css_dvs_6axis_config *dvs_6axis;
190 struct ia_css_dvs2_coefficients *dvs2_coeff;
191 struct ia_css_shading_table *shading_table;
192 struct ia_css_morph_table *morph_table;
193
194 /*
195 * Used to store the user pointer address of the frame. driver needs to
196 * translate to ia_css_frame * and then set to CSS.
197 */
198 void *output_frame;
199 uint32_t isp_config_id;
200
201 /* Indicates which parameters need to be updated. */
202 struct atomisp_parameters update_flag;
203 };
204
205 struct atomisp_subdev_params {
206 /* FIXME: Determines whether raw capture buffer are being passed to
207 * user space. Unimplemented for now. */
208 int online_process;
209 int yuv_ds_en;
210 unsigned int color_effect;
211 bool gdc_cac_en;
212 bool macc_en;
213 bool bad_pixel_en;
214 bool video_dis_en;
215 bool sc_en;
216 bool fpn_en;
217 bool xnr_en;
218 bool low_light;
219 int false_color;
220 unsigned int histogram_elenum;
221
222 /* Current grid info */
223 struct atomisp_css_grid_info curr_grid_info;
224 enum atomisp_css_pipe_id s3a_enabled_pipe;
225
226 int s3a_output_bytes;
227
228 bool dis_proj_data_valid;
229
230 struct ia_css_dz_config dz_config; /**< Digital Zoom */
231 struct ia_css_capture_config capture_config;
232
233 struct atomisp_css_isp_config config;
234
235 /* current configurations */
236 struct atomisp_css_params css_param;
237
238 /*
239 * Intermediate buffers used to communicate data between
240 * CSS and user space.
241 */
242 struct ia_css_3a_statistics *s3a_user_stat;
243
244 void *metadata_user[ATOMISP_METADATA_TYPE_NUM];
245 uint32_t metadata_width_size;
246
247 struct ia_css_dvs2_statistics *dvs_stat;
248 struct atomisp_css_dvs_6axis *dvs_6axis;
249 uint32_t exp_id;
250 int dvs_hor_coef_bytes;
251 int dvs_ver_coef_bytes;
252 int dvs_ver_proj_bytes;
253 int dvs_hor_proj_bytes;
254
255 /* Flash */
256 int num_flash_frames;
257 enum atomisp_flash_state flash_state;
258 enum atomisp_frame_status last_frame_status;
259
260 /* continuous capture */
261 struct atomisp_cont_capture_conf offline_parm;
262 /* Flag to check if driver needs to update params to css */
263 bool css_update_params_needed;
264 };
265
266 struct atomisp_css_params_with_list {
267 /* parameters for CSS */
268 struct atomisp_css_params params;
269 struct list_head list;
270 };
271
272 struct atomisp_acc_fw {
273 struct atomisp_css_fw_info *fw;
274 unsigned int handle;
275 unsigned int flags;
276 unsigned int type;
277 struct {
278 size_t length;
279 unsigned long css_ptr;
280 } args[ATOMISP_ACC_NR_MEMORY];
281 struct list_head list;
282 };
283
284 struct atomisp_map {
285 ia_css_ptr ptr;
286 size_t length;
287 struct list_head list;
288 /* FIXME: should keep book which maps are currently used
289 * by binaries and not allow releasing those
290 * which are in use. Implement by reference counting.
291 */
292 };
293
294 struct atomisp_sub_device {
295 struct v4l2_subdev subdev;
296 struct media_pad pads[ATOMISP_SUBDEV_PADS_NUM];
297 struct atomisp_pad_format fmt[ATOMISP_SUBDEV_PADS_NUM];
298 uint16_t capture_pad; /* main capture pad; defines much of isp config */
299
300 enum atomisp_subdev_input_entity input;
301 unsigned int output;
302 struct atomisp_video_pipe video_in;
303 struct atomisp_video_pipe video_out_capture; /* capture output */
304 struct atomisp_video_pipe video_out_vf; /* viewfinder output */
305 struct atomisp_video_pipe video_out_preview; /* preview output */
306 struct atomisp_acc_pipe video_acc;
307 /* video pipe main output */
308 struct atomisp_video_pipe video_out_video_capture;
309 /* struct isp_subdev_params params; */
310 spinlock_t lock;
311 struct atomisp_device *isp;
312 struct v4l2_ctrl_handler ctrl_handler;
313 struct v4l2_ctrl *fmt_auto;
314 struct v4l2_ctrl *run_mode;
315 struct v4l2_ctrl *depth_mode;
316 struct v4l2_ctrl *vfpp;
317 struct v4l2_ctrl *continuous_mode;
318 struct v4l2_ctrl *continuous_raw_buffer_size;
319 struct v4l2_ctrl *continuous_viewfinder;
320 struct v4l2_ctrl *enable_raw_buffer_lock;
321 #ifdef ISP2401
322 struct v4l2_ctrl *ion_dev_fd;
323 #endif
324 struct v4l2_ctrl *disable_dz;
325 #ifdef ISP2401
326 struct v4l2_ctrl *select_isp_version;
327 #endif
328
329 struct {
330 struct list_head fw;
331 struct list_head memory_maps;
332 struct atomisp_css_pipeline *pipeline;
333 bool extension_mode;
334 struct ida ida;
335 struct completion acc_done;
336 void *acc_stages;
337 } acc;
338
339 struct atomisp_subdev_params params;
340
341 struct atomisp_stream_env stream_env[ATOMISP_INPUT_STREAM_NUM];
342
343 struct v4l2_pix_format dvs_envelop;
344 unsigned int s3a_bufs_in_css[CSS_PIPE_ID_NUM];
345 unsigned int dis_bufs_in_css;
346
347 unsigned int metadata_bufs_in_css
348 [ATOMISP_INPUT_STREAM_NUM][CSS_PIPE_ID_NUM];
349 /* The list of free and available metadata buffers for CSS */
350 struct list_head metadata[ATOMISP_METADATA_TYPE_NUM];
351 /* The list of metadata buffers which have been en-queued to CSS */
352 struct list_head metadata_in_css[ATOMISP_METADATA_TYPE_NUM];
353 /* The list of metadata buffers which are ready for userspace to get */
354 struct list_head metadata_ready[ATOMISP_METADATA_TYPE_NUM];
355
356 /* The list of free and available s3a stat buffers for CSS */
357 struct list_head s3a_stats;
358 /* The list of s3a stat buffers which have been en-queued to CSS */
359 struct list_head s3a_stats_in_css;
360 /* The list of s3a stat buffers which are ready for userspace to get */
361 struct list_head s3a_stats_ready;
362
363 struct list_head dis_stats;
364 struct list_head dis_stats_in_css;
365 spinlock_t dis_stats_lock;
366
367 struct atomisp_css_frame *vf_frame; /* TODO: needed? */
368 struct atomisp_css_frame *raw_output_frame;
369 enum atomisp_frame_status frame_status[VIDEO_MAX_FRAME];
370
371 /* This field specifies which camera (v4l2 input) is selected. */
372 int input_curr;
373 /* This field specifies which sensor is being selected when there
374 are multiple sensors connected to the same MIPI port. */
375 int sensor_curr;
376
377 atomic_t sof_count;
378 atomic_t sequence; /* Sequence value that is assigned to buffer. */
379 atomic_t sequence_temp;
380
381 unsigned int streaming; /* Hold both mutex and lock to change this */
382 bool stream_prepared; /* whether css stream is created */
383
384 /* subdev index: will be used to show which subdev is holding the
385 * resource, like which camera is used by which subdev
386 */
387 unsigned int index;
388
389 /* delayed memory allocation for css */
390 struct completion init_done;
391 struct workqueue_struct *delayed_init_workq;
392 unsigned int delayed_init;
393 struct work_struct delayed_init_work;
394
395 unsigned int latest_preview_exp_id; /* CSS ZSL/SDV raw buffer id */
396
397 unsigned int mipi_frame_size;
398
399 bool copy_mode; /* CSI2+ use copy mode */
400 bool yuvpp_mode; /* CSI2+ yuvpp pipe */
401
402 int raw_buffer_bitmap[ATOMISP_MAX_EXP_ID/32 + 1]; /* Record each Raw Buffer lock status */
403 int raw_buffer_locked_count;
404 spinlock_t raw_buffer_bitmap_lock;
405
406 #ifndef ISP2401
407 struct timer_list wdt;
408 unsigned int wdt_duration; /* in jiffies */
409 unsigned long wdt_expires;
410
411 #endif
412 struct atomisp_resolution sensor_array_res;
413 bool high_speed_mode; /* Indicate whether now is a high speed mode */
414 int pending_capture_request; /* Indicates the number of pending capture requests. */
415 #ifndef ISP2401
416
417 #else
418 bool re_trigger_capture;
419 #endif
420 unsigned int preview_exp_id;
421 unsigned int postview_exp_id;
422 };
423
424 extern const struct atomisp_in_fmt_conv atomisp_in_fmt_conv[];
425
426 u32 atomisp_subdev_uncompressed_code(u32 code);
427 bool atomisp_subdev_is_compressed(u32 code);
428 const struct atomisp_in_fmt_conv *atomisp_find_in_fmt_conv(u32 code);
429 #ifndef ISP2401
430 const struct atomisp_in_fmt_conv *atomisp_find_in_fmt_conv_by_atomisp_in_fmt(
431 enum atomisp_css_stream_format atomisp_in_fmt);
432 #else
433 const struct atomisp_in_fmt_conv
434 *atomisp_find_in_fmt_conv_by_atomisp_in_fmt(enum atomisp_css_stream_format
435 atomisp_in_fmt);
436 #endif
437 const struct atomisp_in_fmt_conv *atomisp_find_in_fmt_conv_compressed(u32 code);
438 bool atomisp_subdev_format_conversion(struct atomisp_sub_device *asd,
439 unsigned int source_pad);
440 uint16_t atomisp_subdev_source_pad(struct video_device *vdev);
441
442 /* Get pointer to appropriate format */
443 struct v4l2_mbus_framefmt
444 *atomisp_subdev_get_ffmt(struct v4l2_subdev *sd,
445 struct v4l2_subdev_pad_config *cfg, uint32_t which,
446 uint32_t pad);
447 struct v4l2_rect *atomisp_subdev_get_rect(struct v4l2_subdev *sd,
448 struct v4l2_subdev_pad_config *cfg,
449 uint32_t which, uint32_t pad,
450 uint32_t target);
451 int atomisp_subdev_set_selection(struct v4l2_subdev *sd,
452 struct v4l2_subdev_pad_config *cfg,
453 uint32_t which, uint32_t pad, uint32_t target,
454 uint32_t flags, struct v4l2_rect *r);
455 /* Actually set the format */
456 void atomisp_subdev_set_ffmt(struct v4l2_subdev *sd,
457 struct v4l2_subdev_pad_config *cfg, uint32_t which,
458 uint32_t pad, struct v4l2_mbus_framefmt *ffmt);
459
460 int atomisp_update_run_mode(struct atomisp_sub_device *asd);
461
462 void atomisp_subdev_cleanup_pending_events(struct atomisp_sub_device *asd);
463
464 void atomisp_subdev_unregister_entities(struct atomisp_sub_device *asd);
465 int atomisp_subdev_register_entities(struct atomisp_sub_device *asd,
466 struct v4l2_device *vdev);
467 int atomisp_subdev_init(struct atomisp_device *isp);
468 void atomisp_subdev_cleanup(struct atomisp_device *isp);
469 int atomisp_create_pads_links(struct atomisp_device *isp);
470
471 #endif /* __ATOMISP_SUBDEV_H__ */