xref: /linux/drivers/staging/media/atomisp/pci/isp/kernels/fpn/fpn_1.0/ia_css_fpn.host.c (revision 3a39d672e7f48b8d6b91a09afa4b55352773b4b5)
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)
47 		return;
48 	ia_css_debug_dtrace(level, "Fixed Pattern Noise Reduction:\n");
49 	ia_css_debug_dtrace(level, "\t%-32s = %d\n",
50 			    "fpn_shift", fpn->shift);
51 	ia_css_debug_dtrace(level, "\t%-32s = %d\n",
52 			    "fpn_enabled", fpn->enabled);
53 }
54 
ia_css_fpn_config(struct sh_css_isp_fpn_isp_config * to,const struct ia_css_fpn_configuration * from,unsigned int size)55 int ia_css_fpn_config(struct sh_css_isp_fpn_isp_config *to,
56 		      const struct ia_css_fpn_configuration *from,
57 		      unsigned int size)
58 {
59 	unsigned int elems_a = ISP_VEC_NELEMS;
60 	int ret;
61 
62 	ret = ia_css_dma_configure_from_info(&to->port_b, from->info);
63 	if (ret)
64 		return ret;
65 
66 	to->width_a_over_b = elems_a / to->port_b.elems;
67 
68 	/* Assume divisiblity here, may need to generalize to fixed point. */
69 	if (elems_a % to->port_b.elems != 0)
70 		return -EINVAL;
71 
72 	return 0;
73 }
74 
ia_css_fpn_configure(const struct ia_css_binary * binary,const struct ia_css_frame_info * info)75 int ia_css_fpn_configure(const struct ia_css_binary     *binary,
76 			 const struct ia_css_frame_info *info)
77 {
78 	struct ia_css_frame_info my_info = IA_CSS_BINARY_DEFAULT_FRAME_INFO;
79 	const struct ia_css_fpn_configuration config = {
80 		&my_info
81 	};
82 
83 	my_info.res.width       = CEIL_DIV(info->res.width, 2);		/* Packed by 2x */
84 	my_info.res.height      = info->res.height;
85 	my_info.padded_width    = CEIL_DIV(info->padded_width, 2);	/* Packed by 2x */
86 	my_info.format          = info->format;
87 	my_info.raw_bit_depth   = FPN_BITS_PER_PIXEL;
88 	my_info.raw_bayer_order = info->raw_bayer_order;
89 	my_info.crop_info       = info->crop_info;
90 
91 	return ia_css_configure_fpn(binary, &config);
92 }
93