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