xref: /linux/drivers/staging/media/atomisp/pci/isp/kernels/ref/ref_1.0/ia_css_ref.host.c (revision 7ae9fb1b7ecbb5d85d07857943f677fd1a559b18)
1 // SPDX-License-Identifier: GPL-2.0
2 /*
3  * Support for Intel Camera Imaging ISP subsystem.
4  * Copyright (c) 2015, Intel Corporation.
5  *
6  * This program is free software; you can redistribute it and/or modify it
7  * under the terms and conditions of the GNU General Public License,
8  * version 2, as published by the Free Software Foundation.
9  *
10  * This program is distributed in the hope it will be useful, but WITHOUT
11  * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
12  * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License for
13  * more details.
14  */
15 
16 #include <assert_support.h>
17 #include <ia_css_frame_public.h>
18 #include <ia_css_frame.h>
19 #include <ia_css_binary.h>
20 #define IA_CSS_INCLUDE_CONFIGURATIONS
21 #include "ia_css_isp_configs.h"
22 #include "isp.h"
23 #include "ia_css_ref.host.h"
24 
ia_css_ref_config(struct sh_css_isp_ref_isp_config * to,const struct ia_css_ref_configuration * from,unsigned int size)25 int ia_css_ref_config(struct sh_css_isp_ref_isp_config *to,
26 		      const struct ia_css_ref_configuration  *from,
27 		      unsigned int size)
28 {
29 	unsigned int elems_a = ISP_VEC_NELEMS, i;
30 	int ret;
31 
32 	if (from->ref_frames[0]) {
33 		ret = ia_css_dma_configure_from_info(&to->port_b, &from->ref_frames[0]->frame_info);
34 		if (ret)
35 			return ret;
36 		to->width_a_over_b = elems_a / to->port_b.elems;
37 		to->dvs_frame_delay = from->dvs_frame_delay;
38 	} else {
39 		to->width_a_over_b = 1;
40 		to->dvs_frame_delay = 0;
41 		to->port_b.elems = elems_a;
42 	}
43 	for (i = 0; i < MAX_NUM_VIDEO_DELAY_FRAMES; i++) {
44 		if (from->ref_frames[i]) {
45 			to->ref_frame_addr_y[i] = from->ref_frames[i]->data +
46 						  from->ref_frames[i]->planes.yuv.y.offset;
47 			to->ref_frame_addr_c[i] = from->ref_frames[i]->data +
48 						  from->ref_frames[i]->planes.yuv.u.offset;
49 		} else {
50 			to->ref_frame_addr_y[i] = 0;
51 			to->ref_frame_addr_c[i] = 0;
52 		}
53 	}
54 
55 	/* Assume divisiblity here, may need to generalize to fixed point. */
56 	if (elems_a % to->port_b.elems != 0)
57 		return -EINVAL;
58 
59 	return 0;
60 }
61 
ia_css_ref_configure(const struct ia_css_binary * binary,const struct ia_css_frame * const * ref_frames,const uint32_t dvs_frame_delay)62 int ia_css_ref_configure(const struct ia_css_binary        *binary,
63 			 const struct ia_css_frame * const *ref_frames,
64 			 const uint32_t dvs_frame_delay)
65 {
66 	struct ia_css_ref_configuration config;
67 	unsigned int i;
68 
69 	for (i = 0; i < MAX_NUM_VIDEO_DELAY_FRAMES; i++)
70 		config.ref_frames[i] = ref_frames[i];
71 
72 	config.dvs_frame_delay = dvs_frame_delay;
73 
74 	return ia_css_configure_ref(binary, &config);
75 }
76 
77 void
ia_css_init_ref_state(struct sh_css_isp_ref_dmem_state * state,unsigned int size)78 ia_css_init_ref_state(
79     struct sh_css_isp_ref_dmem_state *state,
80     unsigned int size)
81 {
82 	(void)size;
83 	assert(MAX_NUM_VIDEO_DELAY_FRAMES >= 2);
84 	state->ref_in_buf_idx = 0;
85 	state->ref_out_buf_idx = 1;
86 }
87