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