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