1 // SPDX-License-Identifier: GPL-2.0
2 /*
3  * Support for Intel Camera Imaging ISP subsystem.
4  * Copyright (c) 2015, Intel Corporation.
5  */
6 
7 #include <assert_support.h>
8 #include <ia_css_frame_public.h>
9 #include <ia_css_frame.h>
10 #include <ia_css_binary.h>
11 #define IA_CSS_INCLUDE_CONFIGURATIONS
12 #include "ia_css_isp_configs.h"
13 #include "isp.h"
14 #include "ia_css_ref.host.h"
15 
ia_css_ref_config(struct sh_css_isp_ref_isp_config * to,const struct ia_css_ref_configuration * from,unsigned int size)16 int ia_css_ref_config(struct sh_css_isp_ref_isp_config *to,
17 		      const struct ia_css_ref_configuration  *from,
18 		      unsigned int size)
19 {
20 	unsigned int elems_a = ISP_VEC_NELEMS, i;
21 	int ret;
22 
23 	if (from->ref_frames[0]) {
24 		ret = ia_css_dma_configure_from_info(&to->port_b, &from->ref_frames[0]->frame_info);
25 		if (ret)
26 			return ret;
27 		to->width_a_over_b = elems_a / to->port_b.elems;
28 		to->dvs_frame_delay = from->dvs_frame_delay;
29 	} else {
30 		to->width_a_over_b = 1;
31 		to->dvs_frame_delay = 0;
32 		to->port_b.elems = elems_a;
33 	}
34 	for (i = 0; i < MAX_NUM_VIDEO_DELAY_FRAMES; i++) {
35 		if (from->ref_frames[i]) {
36 			to->ref_frame_addr_y[i] = from->ref_frames[i]->data +
37 						  from->ref_frames[i]->planes.yuv.y.offset;
38 			to->ref_frame_addr_c[i] = from->ref_frames[i]->data +
39 						  from->ref_frames[i]->planes.yuv.u.offset;
40 		} else {
41 			to->ref_frame_addr_y[i] = 0;
42 			to->ref_frame_addr_c[i] = 0;
43 		}
44 	}
45 
46 	/* Assume divisiblity here, may need to generalize to fixed point. */
47 	if (elems_a % to->port_b.elems != 0)
48 		return -EINVAL;
49 
50 	return 0;
51 }
52 
ia_css_ref_configure(const struct ia_css_binary * binary,const struct ia_css_frame * const * ref_frames,const uint32_t dvs_frame_delay)53 int ia_css_ref_configure(const struct ia_css_binary        *binary,
54 			 const struct ia_css_frame * const *ref_frames,
55 			 const uint32_t dvs_frame_delay)
56 {
57 	struct ia_css_ref_configuration config;
58 	unsigned int i;
59 
60 	for (i = 0; i < MAX_NUM_VIDEO_DELAY_FRAMES; i++)
61 		config.ref_frames[i] = ref_frames[i];
62 
63 	config.dvs_frame_delay = dvs_frame_delay;
64 
65 	return ia_css_configure_ref(binary, &config);
66 }
67 
68 void
ia_css_init_ref_state(struct sh_css_isp_ref_dmem_state * state,unsigned int size)69 ia_css_init_ref_state(
70     struct sh_css_isp_ref_dmem_state *state,
71     unsigned int size)
72 {
73 	(void)size;
74 	assert(MAX_NUM_VIDEO_DELAY_FRAMES >= 2);
75 	state->ref_in_buf_idx = 0;
76 	state->ref_out_buf_idx = 1;
77 }
78