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