1 /* SPDX-License-Identifier: GPL-2.0 */
2 /*
3  * Support for Clovertrail PNW Camera Imaging ISP subsystem.
4  *
5  * Copyright (c) 2012 Intel Corporation. All Rights Reserved.
6  *
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.
10  *
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.
15  *
16  *
17  */
18 
19 #ifndef __ATOMISP_COMPAT_H__
20 #define __ATOMISP_COMPAT_H__
21 
22 #include "atomisp_compat_css20.h"
23 
24 #include "../../include/linux/atomisp.h"
25 #include <media/videobuf-vmalloc.h>
26 
27 struct atomisp_device;
28 struct atomisp_sub_device;
29 struct video_device;
30 enum atomisp_input_stream_id;
31 
32 struct atomisp_metadata_buf {
33 	struct ia_css_metadata *metadata;
34 	void *md_vptr;
35 	struct list_head list;
36 };
37 
38 void atomisp_css2_hw_store_32(hrt_address addr, uint32_t data);
39 void atomisp_load_uint32(hrt_address addr, uint32_t *data);
40 
41 int atomisp_css_init(struct atomisp_device *isp);
42 
43 void atomisp_css_uninit(struct atomisp_device *isp);
44 
45 void atomisp_css_suspend(struct atomisp_device *isp);
46 
47 int atomisp_css_resume(struct atomisp_device *isp);
48 
49 void atomisp_css_init_struct(struct atomisp_sub_device *asd);
50 
51 int atomisp_css_irq_translate(struct atomisp_device *isp,
52 			      unsigned int *infos);
53 
54 void atomisp_css_rx_get_irq_info(enum mipi_port_id port,
55 				 unsigned int *infos);
56 
57 void atomisp_css_rx_clear_irq_info(enum mipi_port_id port,
58 				   unsigned int infos);
59 
60 int atomisp_css_irq_enable(struct atomisp_device *isp,
61 			   enum ia_css_irq_info info, bool enable);
62 
63 int atomisp_q_video_buffer_to_css(struct atomisp_sub_device *asd,
64 				  struct videobuf_vmalloc_memory *vm_mem,
65 				  enum atomisp_input_stream_id stream_id,
66 				  enum ia_css_buffer_type css_buf_type,
67 				  enum ia_css_pipe_id css_pipe_id);
68 
69 int atomisp_q_s3a_buffer_to_css(struct atomisp_sub_device *asd,
70 				struct atomisp_s3a_buf *s3a_buf,
71 				enum atomisp_input_stream_id stream_id,
72 				enum ia_css_pipe_id css_pipe_id);
73 
74 int atomisp_q_metadata_buffer_to_css(struct atomisp_sub_device *asd,
75 				     struct atomisp_metadata_buf *metadata_buf,
76 				     enum atomisp_input_stream_id stream_id,
77 				     enum ia_css_pipe_id css_pipe_id);
78 
79 int atomisp_q_dis_buffer_to_css(struct atomisp_sub_device *asd,
80 				struct atomisp_dis_buf *dis_buf,
81 				enum atomisp_input_stream_id stream_id,
82 				enum ia_css_pipe_id css_pipe_id);
83 
84 void ia_css_mmu_invalidate_cache(void);
85 
86 void ia_css_mmu_invalidate_cache(void);
87 
88 int atomisp_css_start(struct atomisp_sub_device *asd,
89 		      enum ia_css_pipe_id pipe_id, bool in_reset);
90 
91 void atomisp_css_update_isp_params(struct atomisp_sub_device *asd);
92 void atomisp_css_update_isp_params_on_pipe(struct atomisp_sub_device *asd,
93 	struct ia_css_pipe *pipe);
94 
95 int atomisp_css_queue_buffer(struct atomisp_sub_device *asd,
96 			     enum atomisp_input_stream_id stream_id,
97 			     enum ia_css_pipe_id pipe_id,
98 			     enum ia_css_buffer_type buf_type,
99 			     struct atomisp_css_buffer *isp_css_buffer);
100 
101 int atomisp_css_dequeue_buffer(struct atomisp_sub_device *asd,
102 			       enum atomisp_input_stream_id stream_id,
103 			       enum ia_css_pipe_id pipe_id,
104 			       enum ia_css_buffer_type buf_type,
105 			       struct atomisp_css_buffer *isp_css_buffer);
106 
107 int atomisp_css_allocate_stat_buffers(struct atomisp_sub_device *asd,
108 				      u16 stream_id,
109 				      struct atomisp_s3a_buf *s3a_buf,
110 				      struct atomisp_dis_buf *dis_buf,
111 				      struct atomisp_metadata_buf *md_buf);
112 
113 void atomisp_css_free_stat_buffers(struct atomisp_sub_device *asd);
114 
115 void atomisp_css_free_3a_buffer(struct atomisp_s3a_buf *s3a_buf);
116 
117 void atomisp_css_free_dis_buffer(struct atomisp_dis_buf *dis_buf);
118 
119 void atomisp_css_free_metadata_buffer(struct atomisp_metadata_buf
120 				      *metadata_buf);
121 
122 int atomisp_css_get_grid_info(struct atomisp_sub_device *asd,
123 			      enum ia_css_pipe_id pipe_id,
124 			      int source_pad);
125 
126 int atomisp_alloc_3a_output_buf(struct atomisp_sub_device *asd);
127 
128 int atomisp_alloc_dis_coef_buf(struct atomisp_sub_device *asd);
129 
130 int atomisp_alloc_metadata_output_buf(struct atomisp_sub_device *asd);
131 
132 void atomisp_free_metadata_output_buf(struct atomisp_sub_device *asd);
133 
134 void atomisp_css_get_dis_statistics(struct atomisp_sub_device *asd,
135 				    struct atomisp_css_buffer *isp_css_buffer,
136 				    struct ia_css_isp_dvs_statistics_map *dvs_map);
137 
138 int atomisp_css_dequeue_event(struct atomisp_css_event *current_event);
139 
140 void atomisp_css_temp_pipe_to_pipe_id(struct atomisp_sub_device *asd,
141 				      struct atomisp_css_event *current_event);
142 
143 int atomisp_css_isys_set_resolution(struct atomisp_sub_device *asd,
144 				    enum atomisp_input_stream_id stream_id,
145 				    struct v4l2_mbus_framefmt *ffmt,
146 				    int isys_stream);
147 
148 void atomisp_css_isys_set_link(struct atomisp_sub_device *asd,
149 			       enum atomisp_input_stream_id stream_id,
150 			       int link,
151 			       int isys_stream);
152 
153 void atomisp_css_isys_set_valid(struct atomisp_sub_device *asd,
154 				enum atomisp_input_stream_id stream_id,
155 				bool valid,
156 				int isys_stream);
157 
158 void atomisp_css_isys_set_format(struct atomisp_sub_device *asd,
159 				 enum atomisp_input_stream_id stream_id,
160 				 enum atomisp_input_format format,
161 				 int isys_stream);
162 
163 int atomisp_css_set_default_isys_config(struct atomisp_sub_device *asd,
164 					enum atomisp_input_stream_id stream_id,
165 					struct v4l2_mbus_framefmt *ffmt);
166 
167 int atomisp_css_isys_two_stream_cfg(struct atomisp_sub_device *asd,
168 				    enum atomisp_input_stream_id stream_id,
169 				    enum atomisp_input_format input_format);
170 
171 void atomisp_css_isys_two_stream_cfg_update_stream1(
172     struct atomisp_sub_device *asd,
173     enum atomisp_input_stream_id stream_id,
174     enum atomisp_input_format input_format,
175     unsigned int width, unsigned int height);
176 
177 void atomisp_css_isys_two_stream_cfg_update_stream2(
178     struct atomisp_sub_device *asd,
179     enum atomisp_input_stream_id stream_id,
180     enum atomisp_input_format input_format,
181     unsigned int width, unsigned int height);
182 
183 int atomisp_css_input_set_resolution(struct atomisp_sub_device *asd,
184 				     enum atomisp_input_stream_id stream_id,
185 				     struct v4l2_mbus_framefmt *ffmt);
186 
187 void atomisp_css_input_set_binning_factor(struct atomisp_sub_device *asd,
188 	enum atomisp_input_stream_id stream_id,
189 	unsigned int bin_factor);
190 
191 void atomisp_css_input_set_bayer_order(struct atomisp_sub_device *asd,
192 				       enum atomisp_input_stream_id stream_id,
193 				       enum ia_css_bayer_order bayer_order);
194 
195 void atomisp_css_input_set_format(struct atomisp_sub_device *asd,
196 				  enum atomisp_input_stream_id stream_id,
197 				  enum atomisp_input_format format);
198 
199 int atomisp_css_input_set_effective_resolution(
200     struct atomisp_sub_device *asd,
201     enum atomisp_input_stream_id stream_id,
202     unsigned int width,
203     unsigned int height);
204 
205 void atomisp_css_video_set_dis_envelope(struct atomisp_sub_device *asd,
206 					unsigned int dvs_w, unsigned int dvs_h);
207 
208 void atomisp_css_input_set_two_pixels_per_clock(
209     struct atomisp_sub_device *asd,
210     bool two_ppc);
211 
212 void atomisp_css_enable_raw_binning(struct atomisp_sub_device *asd,
213 				    bool enable);
214 
215 void atomisp_css_enable_dz(struct atomisp_sub_device *asd, bool enable);
216 
217 void atomisp_css_capture_set_mode(struct atomisp_sub_device *asd,
218 				  enum ia_css_capture_mode mode);
219 
220 void atomisp_css_input_set_mode(struct atomisp_sub_device *asd,
221 				enum ia_css_input_mode mode);
222 
223 void atomisp_css_capture_enable_online(struct atomisp_sub_device *asd,
224 				       unsigned short stream_index, bool enable);
225 
226 void atomisp_css_preview_enable_online(struct atomisp_sub_device *asd,
227 				       unsigned short stream_index, bool enable);
228 
229 void atomisp_css_video_enable_online(struct atomisp_sub_device *asd,
230 				     bool enable);
231 
232 void atomisp_css_enable_continuous(struct atomisp_sub_device *asd,
233 				   bool enable);
234 
235 void atomisp_css_enable_cvf(struct atomisp_sub_device *asd,
236 			    bool enable);
237 
238 int atomisp_css_input_configure_port(struct atomisp_sub_device *asd,
239 				     enum mipi_port_id port,
240 				     unsigned int num_lanes,
241 				     unsigned int timeout,
242 				     unsigned int mipi_freq,
243 				     enum atomisp_input_format metadata_format,
244 				     unsigned int metadata_width,
245 				     unsigned int metadata_height);
246 
247 void atomisp_create_pipes_stream(struct atomisp_sub_device *asd);
248 void atomisp_destroy_pipes_stream_force(struct atomisp_sub_device *asd);
249 
250 void atomisp_css_stop(struct atomisp_sub_device *asd,
251 		      enum ia_css_pipe_id pipe_id, bool in_reset);
252 
253 void atomisp_css_continuous_set_num_raw_frames(
254      struct atomisp_sub_device *asd,
255      int num_frames);
256 
257 int atomisp_css_copy_configure_output(struct atomisp_sub_device *asd,
258 				      unsigned int stream_index,
259 				      unsigned int width, unsigned int height,
260 				      unsigned int padded_width,
261 				      enum ia_css_frame_format format);
262 
263 int atomisp_css_yuvpp_configure_output(struct atomisp_sub_device *asd,
264 				       unsigned int stream_index,
265 				       unsigned int width, unsigned int height,
266 				       unsigned int padded_width,
267 				       enum ia_css_frame_format format);
268 
269 int atomisp_css_yuvpp_configure_viewfinder(
270     struct atomisp_sub_device *asd,
271     unsigned int stream_index,
272     unsigned int width, unsigned int height,
273     unsigned int min_width,
274     enum ia_css_frame_format format);
275 
276 int atomisp_css_yuvpp_get_output_frame_info(
277     struct atomisp_sub_device *asd,
278     unsigned int stream_index,
279     struct ia_css_frame_info *info);
280 
281 int atomisp_css_yuvpp_get_viewfinder_frame_info(
282     struct atomisp_sub_device *asd,
283     unsigned int stream_index,
284     struct ia_css_frame_info *info);
285 
286 int atomisp_css_preview_configure_output(struct atomisp_sub_device *asd,
287 	unsigned int width, unsigned int height,
288 	unsigned int min_width,
289 	enum ia_css_frame_format format);
290 
291 int atomisp_css_capture_configure_output(struct atomisp_sub_device *asd,
292 	unsigned int width, unsigned int height,
293 	unsigned int min_width,
294 	enum ia_css_frame_format format);
295 
296 int atomisp_css_video_configure_output(struct atomisp_sub_device *asd,
297 				       unsigned int width, unsigned int height,
298 				       unsigned int min_width,
299 				       enum ia_css_frame_format format);
300 
301 int atomisp_get_css_frame_info(struct atomisp_sub_device *asd,
302 			       u16 source_pad,
303 			       struct ia_css_frame_info *frame_info);
304 
305 int atomisp_css_video_configure_viewfinder(struct atomisp_sub_device *asd,
306 	unsigned int width, unsigned int height,
307 	unsigned int min_width,
308 	enum ia_css_frame_format format);
309 
310 int atomisp_css_capture_configure_viewfinder(
311     struct atomisp_sub_device *asd,
312     unsigned int width, unsigned int height,
313     unsigned int min_width,
314     enum ia_css_frame_format format);
315 
316 int atomisp_css_video_get_viewfinder_frame_info(
317     struct atomisp_sub_device *asd,
318     struct ia_css_frame_info *info);
319 
320 int atomisp_css_capture_get_viewfinder_frame_info(
321     struct atomisp_sub_device *asd,
322     struct ia_css_frame_info *info);
323 
324 int atomisp_css_copy_get_output_frame_info(
325     struct atomisp_sub_device *asd,
326     unsigned int stream_index,
327     struct ia_css_frame_info *info);
328 
329 int atomisp_css_capture_get_output_raw_frame_info(
330     struct atomisp_sub_device *asd,
331     struct ia_css_frame_info *info);
332 
333 int atomisp_css_preview_get_output_frame_info(
334     struct atomisp_sub_device *asd,
335     struct ia_css_frame_info *info);
336 
337 int atomisp_css_capture_get_output_frame_info(
338     struct atomisp_sub_device *asd,
339     struct ia_css_frame_info *info);
340 
341 int atomisp_css_video_get_output_frame_info(
342     struct atomisp_sub_device *asd,
343     struct ia_css_frame_info *info);
344 
345 int atomisp_css_preview_configure_pp_input(
346     struct atomisp_sub_device *asd,
347     unsigned int width, unsigned int height);
348 
349 int atomisp_css_capture_configure_pp_input(
350     struct atomisp_sub_device *asd,
351     unsigned int width, unsigned int height);
352 
353 int atomisp_css_video_configure_pp_input(
354     struct atomisp_sub_device *asd,
355     unsigned int width, unsigned int height);
356 
357 int atomisp_css_offline_capture_configure(struct atomisp_sub_device *asd,
358 	int num_captures, unsigned int skip, int offset);
359 int atomisp_css_exp_id_capture(struct atomisp_sub_device *asd, int exp_id);
360 int atomisp_css_exp_id_unlock(struct atomisp_sub_device *asd, int exp_id);
361 
362 int atomisp_css_capture_enable_xnr(struct atomisp_sub_device *asd,
363 				   bool enable);
364 
365 void atomisp_css_set_ctc_table(struct atomisp_sub_device *asd,
366 			       struct ia_css_ctc_table *ctc_table);
367 
368 void atomisp_css_video_set_dis_vector(struct atomisp_sub_device *asd,
369 				      struct atomisp_dis_vector *vector);
370 
371 void atomisp_css_set_dvs2_coefs(struct atomisp_sub_device *asd,
372 				struct ia_css_dvs2_coefficients *coefs);
373 
374 int atomisp_css_set_dis_coefs(struct atomisp_sub_device *asd,
375 			      struct atomisp_dis_coefficients *coefs);
376 
377 void atomisp_css_set_zoom_factor(struct atomisp_sub_device *asd,
378 				 unsigned int zoom);
379 
380 int atomisp_css_get_wb_config(struct atomisp_sub_device *asd,
381 			      struct atomisp_wb_config *config);
382 
383 int atomisp_css_get_ob_config(struct atomisp_sub_device *asd,
384 			      struct atomisp_ob_config *config);
385 
386 int atomisp_css_get_dp_config(struct atomisp_sub_device *asd,
387 			      struct atomisp_dp_config *config);
388 
389 int atomisp_css_get_de_config(struct atomisp_sub_device *asd,
390 			      struct atomisp_de_config *config);
391 
392 int atomisp_css_get_nr_config(struct atomisp_sub_device *asd,
393 			      struct atomisp_nr_config *config);
394 
395 int atomisp_css_get_ee_config(struct atomisp_sub_device *asd,
396 			      struct atomisp_ee_config *config);
397 
398 int atomisp_css_get_tnr_config(struct atomisp_sub_device *asd,
399 			       struct atomisp_tnr_config *config);
400 
401 int atomisp_css_get_ctc_table(struct atomisp_sub_device *asd,
402 			      struct atomisp_ctc_table *config);
403 
404 int atomisp_css_get_gamma_table(struct atomisp_sub_device *asd,
405 				struct atomisp_gamma_table *config);
406 
407 int atomisp_css_get_gc_config(struct atomisp_sub_device *asd,
408 			      struct atomisp_gc_config *config);
409 
410 int atomisp_css_get_3a_config(struct atomisp_sub_device *asd,
411 			      struct atomisp_3a_config *config);
412 
413 int atomisp_css_get_formats_config(struct atomisp_sub_device *asd,
414 				   struct atomisp_formats_config *formats_config);
415 
416 void atomisp_css_set_formats_config(struct atomisp_sub_device *asd,
417 				    struct ia_css_formats_config *formats_config);
418 
419 int atomisp_css_get_zoom_factor(struct atomisp_sub_device *asd,
420 				unsigned int *zoom);
421 
422 struct ia_css_shading_table *atomisp_css_shading_table_alloc(
423     unsigned int width, unsigned int height);
424 
425 void atomisp_css_set_shading_table(struct atomisp_sub_device *asd,
426 				   struct ia_css_shading_table *table);
427 
428 void atomisp_css_shading_table_free(struct ia_css_shading_table *table);
429 
430 struct ia_css_morph_table *atomisp_css_morph_table_allocate(
431     unsigned int width, unsigned int height);
432 
433 void atomisp_css_set_morph_table(struct atomisp_sub_device *asd,
434 				 struct ia_css_morph_table *table);
435 
436 void atomisp_css_get_morph_table(struct atomisp_sub_device *asd,
437 				 struct ia_css_morph_table *table);
438 
439 void atomisp_css_morph_table_free(struct ia_css_morph_table *table);
440 
441 void atomisp_css_set_cont_prev_start_time(struct atomisp_device *isp,
442 	unsigned int overlap);
443 
444 int atomisp_css_get_dis_stat(struct atomisp_sub_device *asd,
445 			     struct atomisp_dis_statistics *stats);
446 
447 int atomisp_css_update_stream(struct atomisp_sub_device *asd);
448 
449 int atomisp_css_create_acc_pipe(struct atomisp_sub_device *asd);
450 
451 int atomisp_css_start_acc_pipe(struct atomisp_sub_device *asd);
452 
453 int atomisp_css_stop_acc_pipe(struct atomisp_sub_device *asd);
454 
455 void atomisp_css_destroy_acc_pipe(struct atomisp_sub_device *asd);
456 
457 int atomisp_css_load_acc_extension(struct atomisp_sub_device *asd,
458 				   struct ia_css_fw_info *fw,
459 				   enum ia_css_pipe_id pipe_id,
460 				   unsigned int type);
461 
462 void atomisp_css_unload_acc_extension(struct atomisp_sub_device *asd,
463 				      struct ia_css_fw_info *fw,
464 				      enum ia_css_pipe_id pipe_id);
465 
466 int atomisp_css_wait_acc_finish(struct atomisp_sub_device *asd);
467 
468 void atomisp_css_acc_done(struct atomisp_sub_device *asd);
469 
470 int atomisp_css_load_acc_binary(struct atomisp_sub_device *asd,
471 				struct ia_css_fw_info *fw,
472 				unsigned int index);
473 
474 void atomisp_css_unload_acc_binary(struct atomisp_sub_device *asd);
475 
476 struct atomisp_acc_fw;
477 int atomisp_css_set_acc_parameters(struct atomisp_acc_fw *acc_fw);
478 
479 int atomisp_css_isr_thread(struct atomisp_device *isp,
480 			   bool *frame_done_found,
481 			   bool *css_pipe_done);
482 
483 bool atomisp_css_valid_sof(struct atomisp_device *isp);
484 
485 void atomisp_en_dz_capt_pipe(struct atomisp_sub_device *asd, bool enable);
486 
487 #endif
488