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_crop.host.h"
24 
25 static const struct ia_css_crop_configuration default_config = {
26 	.info = (struct ia_css_frame_info *)NULL,
27 };
28 
29 void
ia_css_crop_encode(struct sh_css_isp_crop_isp_params * to,const struct ia_css_crop_config * from,unsigned int size)30 ia_css_crop_encode(
31     struct sh_css_isp_crop_isp_params *to,
32     const struct ia_css_crop_config *from,
33     unsigned int size)
34 {
35 	(void)size;
36 	to->crop_pos = from->crop_pos;
37 }
38 
ia_css_crop_config(struct sh_css_isp_crop_isp_config * to,const struct ia_css_crop_configuration * from,unsigned int size)39 int ia_css_crop_config(struct sh_css_isp_crop_isp_config *to,
40 		       const struct ia_css_crop_configuration *from,
41 		       unsigned int size)
42 {
43 	unsigned int elems_a = ISP_VEC_NELEMS;
44 	int ret;
45 
46 	ret = ia_css_dma_configure_from_info(&to->port_b, from->info);
47 	if (ret)
48 		return ret;
49 
50 	to->width_a_over_b = elems_a / to->port_b.elems;
51 
52 	/* Assume divisiblity here, may need to generalize to fixed point. */
53 	if (elems_a % to->port_b.elems != 0)
54 		return -EINVAL;
55 
56 	return 0;
57 }
58 
ia_css_crop_configure(const struct ia_css_binary * binary,const struct ia_css_frame_info * info)59 int ia_css_crop_configure(const struct ia_css_binary     *binary,
60 			  const struct ia_css_frame_info *info)
61 {
62 	struct ia_css_crop_configuration config = default_config;
63 
64 	config.info = info;
65 
66 	return ia_css_configure_crop(binary, &config);
67 }
68