1 /* SPDX-License-Identifier: GPL-2.0 */
3 * Support for Medifield PNW Camera Imaging ISP subsystem.
5 * Copyright (c) 2010 Intel Corporation. All Rights Reserved.
7 * This program is free software; you can redistribute it and/or
8 * modify it under the terms of the GNU General Public License version
9 * 2 as published by the Free Software Foundation.
11 * This program is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 * GNU General Public License for more details.
18 #ifndef __ATOMISP_SUBDEV_H__
19 #define __ATOMISP_SUBDEV_H__
21 #include <media/v4l2-ctrls.h>
22 #include <media/v4l2-device.h>
23 #include <media/v4l2-subdev.h>
24 #include <media/videobuf-core.h>
26 #include "atomisp_common.h"
27 #include "atomisp_compat.h"
28 #include "atomisp_v4l2.h"
32 /* EXP_ID's ranger is 1 ~ 250 */
33 #define ATOMISP_MAX_EXP_ID (250)
34 enum atomisp_subdev_input_entity {
35 ATOMISP_SUBDEV_INPUT_NONE,
36 ATOMISP_SUBDEV_INPUT_MEMORY,
37 ATOMISP_SUBDEV_INPUT_CSI2,
39 * The following enum for CSI2 port must go together in one row.
40 * Otherwise it breaks the code logic.
42 ATOMISP_SUBDEV_INPUT_CSI2_PORT1,
43 ATOMISP_SUBDEV_INPUT_CSI2_PORT2,
44 ATOMISP_SUBDEV_INPUT_CSI2_PORT3,
47 #define ATOMISP_SUBDEV_PAD_SINK 0
48 /* capture output for still frames */
49 #define ATOMISP_SUBDEV_PAD_SOURCE_CAPTURE 1
50 /* viewfinder output for downscaled capture output */
51 #define ATOMISP_SUBDEV_PAD_SOURCE_VF 2
52 /* preview output for display */
53 #define ATOMISP_SUBDEV_PAD_SOURCE_PREVIEW 3
54 /* main output for video pipeline */
55 #define ATOMISP_SUBDEV_PAD_SOURCE_VIDEO 4
56 #define ATOMISP_SUBDEV_PADS_NUM 5
58 struct atomisp_in_fmt_conv {
60 u8 bpp; /* bits per pixel */
61 u8 depth; /* uncompressed */
62 enum atomisp_input_format atomisp_in_fmt;
63 enum ia_css_bayer_order bayer_order;
66 struct atomisp_sub_device;
68 struct atomisp_video_pipe {
69 struct video_device vdev;
70 enum v4l2_buf_type type;
72 struct videobuf_queue capq;
73 struct list_head activeq;
75 * the buffers waiting for per-frame parameters, this is only valid
76 * in per-frame setting mode.
78 struct list_head buffers_waiting_for_param;
79 /* the link list to store per_frame parameters */
80 struct list_head per_frame_params;
82 /* Store here the initial run mode */
83 unsigned int default_run_mode;
84 /* Set from streamoff to disallow queuing further buffers in CSS */
86 unsigned int buffers_in_css;
89 * irq_lock is used to protect video buffer state change operations and
90 * also to make activeq and capq operations atomic.
95 struct atomisp_device *isp;
96 struct v4l2_pix_format pix;
99 struct atomisp_sub_device *asd;
102 * This frame_config_id is got from CSS when dequueues buffers from CSS,
103 * it is used to indicate which parameter it has applied.
105 unsigned int frame_config_id[VIDEO_MAX_FRAME];
107 * This config id is set when camera HAL enqueues buffer, it has a
108 * non-zero value to indicate which parameter it needs to applu
110 unsigned int frame_request_config_id[VIDEO_MAX_FRAME];
111 struct atomisp_css_params_with_list *frame_params[VIDEO_MAX_FRAME];
114 struct atomisp_pad_format {
115 struct v4l2_mbus_framefmt fmt;
116 struct v4l2_rect crop;
117 struct v4l2_rect compose;
120 /* Internal states for flash process */
121 enum atomisp_flash_state {
123 ATOMISP_FLASH_REQUESTED,
124 ATOMISP_FLASH_ONGOING,
129 * This structure is used to cache the CSS parameters, it aligns to
130 * struct ia_css_isp_config but without un-supported and deprecated parts.
132 struct atomisp_css_params {
133 struct ia_css_wb_config wb_config;
134 struct ia_css_cc_config cc_config;
135 struct ia_css_tnr_config tnr_config;
136 struct ia_css_ecd_config ecd_config;
137 struct ia_css_ynr_config ynr_config;
138 struct ia_css_fc_config fc_config;
139 struct ia_css_formats_config formats_config;
140 struct ia_css_cnr_config cnr_config;
141 struct ia_css_macc_config macc_config;
142 struct ia_css_ctc_config ctc_config;
143 struct ia_css_aa_config aa_config;
144 struct ia_css_aa_config baa_config;
145 struct ia_css_ce_config ce_config;
146 struct ia_css_ob_config ob_config;
147 struct ia_css_dp_config dp_config;
148 struct ia_css_de_config de_config;
149 struct ia_css_gc_config gc_config;
150 struct ia_css_nr_config nr_config;
151 struct ia_css_ee_config ee_config;
152 struct ia_css_anr_config anr_config;
153 struct ia_css_3a_config s3a_config;
154 struct ia_css_xnr_config xnr_config;
155 struct ia_css_dz_config dz_config;
156 struct ia_css_cc_config yuv2rgb_cc_config;
157 struct ia_css_cc_config rgb2yuv_cc_config;
158 struct ia_css_macc_table macc_table;
159 struct ia_css_gamma_table gamma_table;
160 struct ia_css_ctc_table ctc_table;
162 struct ia_css_xnr_table xnr_table;
163 struct ia_css_rgb_gamma_table r_gamma_table;
164 struct ia_css_rgb_gamma_table g_gamma_table;
165 struct ia_css_rgb_gamma_table b_gamma_table;
167 struct ia_css_vector motion_vector;
168 struct ia_css_anr_thres anr_thres;
170 struct ia_css_dvs_6axis_config *dvs_6axis;
171 struct ia_css_dvs2_coefficients *dvs2_coeff;
172 struct ia_css_shading_table *shading_table;
173 struct ia_css_morph_table *morph_table;
176 * Used to store the user pointer address of the frame. driver needs to
177 * translate to ia_css_frame * and then set to CSS.
182 /* Indicates which parameters need to be updated. */
183 struct atomisp_parameters update_flag;
186 struct atomisp_subdev_params {
187 /* FIXME: Determines whether raw capture buffer are being passed to
188 * user space. Unimplemented for now. */
191 unsigned int color_effect;
201 unsigned int histogram_elenum;
203 /* Current grid info */
204 struct ia_css_grid_info curr_grid_info;
205 enum ia_css_pipe_id s3a_enabled_pipe;
207 int s3a_output_bytes;
209 bool dis_proj_data_valid;
211 struct ia_css_dz_config dz_config; /** Digital Zoom */
212 struct ia_css_capture_config capture_config;
214 struct ia_css_isp_config config;
216 /* current configurations */
217 struct atomisp_css_params css_param;
220 * Intermediate buffers used to communicate data between
221 * CSS and user space.
223 struct ia_css_3a_statistics *s3a_user_stat;
225 void *metadata_user[ATOMISP_METADATA_TYPE_NUM];
226 u32 metadata_width_size;
228 struct ia_css_dvs2_statistics *dvs_stat;
229 struct ia_css_dvs_6axis_config *dvs_6axis;
231 int dvs_hor_coef_bytes;
232 int dvs_ver_coef_bytes;
233 int dvs_ver_proj_bytes;
234 int dvs_hor_proj_bytes;
237 int num_flash_frames;
238 enum atomisp_flash_state flash_state;
239 enum atomisp_frame_status last_frame_status;
241 /* continuous capture */
242 struct atomisp_cont_capture_conf offline_parm;
243 /* Flag to check if driver needs to update params to css */
244 bool css_update_params_needed;
247 struct atomisp_css_params_with_list {
248 /* parameters for CSS */
249 struct atomisp_css_params params;
250 struct list_head list;
253 struct atomisp_sub_device {
254 struct v4l2_subdev subdev;
255 struct media_pad pads[ATOMISP_SUBDEV_PADS_NUM];
256 struct atomisp_pad_format fmt[ATOMISP_SUBDEV_PADS_NUM];
257 u16 capture_pad; /* main capture pad; defines much of isp config */
259 enum atomisp_subdev_input_entity input;
261 struct atomisp_video_pipe video_out_capture; /* capture output */
262 struct atomisp_video_pipe video_out_vf; /* viewfinder output */
263 struct atomisp_video_pipe video_out_preview; /* preview output */
264 /* video pipe main output */
265 struct atomisp_video_pipe video_out_video_capture;
266 /* struct isp_subdev_params params; */
267 struct atomisp_device *isp;
268 struct v4l2_ctrl_handler ctrl_handler;
269 struct v4l2_ctrl *fmt_auto;
270 struct v4l2_ctrl *run_mode;
271 struct v4l2_ctrl *depth_mode;
272 struct v4l2_ctrl *vfpp;
273 struct v4l2_ctrl *continuous_mode;
274 struct v4l2_ctrl *continuous_raw_buffer_size;
275 struct v4l2_ctrl *continuous_viewfinder;
276 struct v4l2_ctrl *enable_raw_buffer_lock;
279 struct v4l2_ctrl *ion_dev_fd;
281 struct v4l2_ctrl *disable_dz;
283 struct atomisp_subdev_params params;
285 struct atomisp_stream_env stream_env[ATOMISP_INPUT_STREAM_NUM];
287 struct v4l2_pix_format dvs_envelop;
288 unsigned int s3a_bufs_in_css[IA_CSS_PIPE_ID_NUM];
289 unsigned int dis_bufs_in_css;
291 unsigned int metadata_bufs_in_css
292 [ATOMISP_INPUT_STREAM_NUM][IA_CSS_PIPE_ID_NUM];
293 /* The list of free and available metadata buffers for CSS */
294 struct list_head metadata[ATOMISP_METADATA_TYPE_NUM];
295 /* The list of metadata buffers which have been en-queued to CSS */
296 struct list_head metadata_in_css[ATOMISP_METADATA_TYPE_NUM];
297 /* The list of metadata buffers which are ready for userspace to get */
298 struct list_head metadata_ready[ATOMISP_METADATA_TYPE_NUM];
300 /* The list of free and available s3a stat buffers for CSS */
301 struct list_head s3a_stats;
302 /* The list of s3a stat buffers which have been en-queued to CSS */
303 struct list_head s3a_stats_in_css;
304 /* The list of s3a stat buffers which are ready for userspace to get */
305 struct list_head s3a_stats_ready;
307 struct list_head dis_stats;
308 struct list_head dis_stats_in_css;
309 spinlock_t dis_stats_lock;
311 struct ia_css_frame *vf_frame; /* TODO: needed? */
312 struct ia_css_frame *raw_output_frame;
313 enum atomisp_frame_status frame_status[VIDEO_MAX_FRAME];
315 /* This field specifies which camera (v4l2 input) is selected. */
319 atomic_t sequence; /* Sequence value that is assigned to buffer. */
320 atomic_t sequence_temp;
323 * Writers of streaming must hold both isp->mutex and isp->lock.
324 * Readers of streaming need to hold only one of the two locks.
326 unsigned int streaming;
327 bool stream_prepared; /* whether css stream is created */
329 /* subdev index: will be used to show which subdev is holding the
330 * resource, like which camera is used by which subdev
334 /* delayed memory allocation for css */
335 struct completion init_done;
336 struct workqueue_struct *delayed_init_workq;
337 unsigned int delayed_init;
338 struct work_struct delayed_init_work;
340 unsigned int latest_preview_exp_id; /* CSS ZSL/SDV raw buffer id */
342 unsigned int mipi_frame_size;
344 bool copy_mode; /* CSI2+ use copy mode */
345 bool yuvpp_mode; /* CSI2+ yuvpp pipe */
347 int raw_buffer_bitmap[ATOMISP_MAX_EXP_ID / 32 +
348 1]; /* Record each Raw Buffer lock status */
349 int raw_buffer_locked_count;
350 spinlock_t raw_buffer_bitmap_lock;
353 bool re_trigger_capture;
355 struct atomisp_resolution sensor_array_res;
356 bool high_speed_mode; /* Indicate whether now is a high speed mode */
357 int pending_capture_request; /* Indicates the number of pending capture requests. */
359 unsigned int preview_exp_id;
360 unsigned int postview_exp_id;
363 extern const struct atomisp_in_fmt_conv atomisp_in_fmt_conv[];
365 u32 atomisp_subdev_uncompressed_code(u32 code);
366 bool atomisp_subdev_is_compressed(u32 code);
367 const struct atomisp_in_fmt_conv *atomisp_find_in_fmt_conv(u32 code);
370 const struct atomisp_in_fmt_conv *atomisp_find_in_fmt_conv_by_atomisp_in_fmt(
371 enum atomisp_input_format atomisp_in_fmt);
374 const struct atomisp_in_fmt_conv
375 *atomisp_find_in_fmt_conv_by_atomisp_in_fmt(enum atomisp_input_format
378 const struct atomisp_in_fmt_conv *atomisp_find_in_fmt_conv_compressed(u32 code);
379 bool atomisp_subdev_format_conversion(struct atomisp_sub_device *asd,
380 unsigned int source_pad);
381 uint16_t atomisp_subdev_source_pad(struct video_device *vdev);
383 /* Get pointer to appropriate format */
384 struct v4l2_mbus_framefmt
385 *atomisp_subdev_get_ffmt(struct v4l2_subdev *sd,
386 struct v4l2_subdev_state *sd_state, uint32_t which,
388 struct v4l2_rect *atomisp_subdev_get_rect(struct v4l2_subdev *sd,
389 struct v4l2_subdev_state *sd_state,
390 u32 which, uint32_t pad,
392 int atomisp_subdev_set_selection(struct v4l2_subdev *sd,
393 struct v4l2_subdev_state *sd_state,
394 u32 which, uint32_t pad, uint32_t target,
395 u32 flags, struct v4l2_rect *r);
396 /* Actually set the format */
397 void atomisp_subdev_set_ffmt(struct v4l2_subdev *sd,
398 struct v4l2_subdev_state *sd_state,
400 u32 pad, struct v4l2_mbus_framefmt *ffmt);
402 int atomisp_update_run_mode(struct atomisp_sub_device *asd);
404 void atomisp_subdev_cleanup_pending_events(struct atomisp_sub_device *asd);
406 void atomisp_subdev_unregister_entities(struct atomisp_sub_device *asd);
407 int atomisp_subdev_register_subdev(struct atomisp_sub_device *asd,
408 struct v4l2_device *vdev);
409 int atomisp_subdev_register_video_nodes(struct atomisp_sub_device *asd,
410 struct v4l2_device *vdev);
411 int atomisp_subdev_init(struct atomisp_device *isp);
412 void atomisp_subdev_cleanup(struct atomisp_device *isp);
413 int atomisp_create_pads_links(struct atomisp_device *isp);
415 #endif /* __ATOMISP_SUBDEV_H__ */