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 #include <ia_css_types.h>
21 #include <sh_css_defs.h>
22 #include <ia_css_debug.h>
23 
24 #define IA_CSS_INCLUDE_CONFIGURATIONS
25 #include "ia_css_isp_configs.h"
26 #include "isp.h"
27 
28 #include "ia_css_fpn.host.h"
29 
30 void
ia_css_fpn_encode(struct sh_css_isp_fpn_params * to,const struct ia_css_fpn_table * from,unsigned int size)31 ia_css_fpn_encode(
32     struct sh_css_isp_fpn_params *to,
33     const struct ia_css_fpn_table *from,
34     unsigned int size)
35 {
36 	(void)size;
37 	to->shift = from->shift;
38 	to->enabled = from->data != NULL;
39 }
40 
41 void
ia_css_fpn_dump(const struct sh_css_isp_fpn_params * fpn,unsigned int level)42 ia_css_fpn_dump(
43     const struct sh_css_isp_fpn_params *fpn,
44     unsigned int level)
45 {
46 	if (!fpn) return;
47 	ia_css_debug_dtrace(level, "Fixed Pattern Noise Reduction:\n");
48 	ia_css_debug_dtrace(level, "\t%-32s = %d\n",
49 			    "fpn_shift", fpn->shift);
50 	ia_css_debug_dtrace(level, "\t%-32s = %d\n",
51 			    "fpn_enabled", fpn->enabled);
52 }
53 
ia_css_fpn_config(struct sh_css_isp_fpn_isp_config * to,const struct ia_css_fpn_configuration * from,unsigned int size)54 int ia_css_fpn_config(struct sh_css_isp_fpn_isp_config *to,
55 		      const struct ia_css_fpn_configuration *from,
56 		      unsigned int size)
57 {
58 	unsigned int elems_a = ISP_VEC_NELEMS;
59 	int ret;
60 
61 	ret = ia_css_dma_configure_from_info(&to->port_b, from->info);
62 	if (ret)
63 		return ret;
64 
65 	to->width_a_over_b = elems_a / to->port_b.elems;
66 
67 	/* Assume divisiblity here, may need to generalize to fixed point. */
68 	if (elems_a % to->port_b.elems != 0)
69 		return -EINVAL;
70 
71 	return 0;
72 }
73 
ia_css_fpn_configure(const struct ia_css_binary * binary,const struct ia_css_frame_info * info)74 int ia_css_fpn_configure(const struct ia_css_binary     *binary,
75 			 const struct ia_css_frame_info *info)
76 {
77 	struct ia_css_frame_info my_info = IA_CSS_BINARY_DEFAULT_FRAME_INFO;
78 	const struct ia_css_fpn_configuration config = {
79 		&my_info
80 	};
81 
82 	my_info.res.width       = CEIL_DIV(info->res.width, 2);		/* Packed by 2x */
83 	my_info.res.height      = info->res.height;
84 	my_info.padded_width    = CEIL_DIV(info->padded_width, 2);	/* Packed by 2x */
85 	my_info.format          = info->format;
86 	my_info.raw_bit_depth   = FPN_BITS_PER_PIXEL;
87 	my_info.raw_bayer_order = info->raw_bayer_order;
88 	my_info.crop_info       = info->crop_info;
89 
90 	return ia_css_configure_fpn(binary, &config);
91 }
92