aboutsummaryrefslogtreecommitdiffstatshomepage
path: root/drivers/staging/media/atomisp/pci/isp/kernels/ob/ob_1.0/ia_css_ob.host.c
blob: 6367d94275fb0df18b26c4f3c12e603b99840b53 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
/*
 * Support for Intel Camera Imaging ISP subsystem.
 * Copyright (c) 2015, Intel Corporation.
 *
 * This program is free software; you can redistribute it and/or modify it
 * under the terms and conditions of the GNU General Public License,
 * version 2, as published by the Free Software Foundation.
 *
 * This program is distributed in the hope it will be useful, but WITHOUT
 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
 * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License for
 * more details.
 */

#include "ia_css_types.h"
#include "sh_css_defs.h"
#include "ia_css_debug.h"
#include "isp.h"

#include "ia_css_ob.host.h"

const struct ia_css_ob_config default_ob_config = {
	IA_CSS_OB_MODE_NONE,
	0,
	0,
	0,
	0,
	0,
	0
};

/* TODO: include ob.isp.h to get isp knowledge and
   add assert on platform restrictions */

void
ia_css_ob_configure(
    struct sh_css_isp_ob_stream_config *config,
    unsigned int isp_pipe_version,
    unsigned int raw_bit_depth)
{
	config->isp_pipe_version = isp_pipe_version;
	config->raw_bit_depth    = raw_bit_depth;
}

void
ia_css_ob_encode(
    struct sh_css_isp_ob_params *to,
    const struct ia_css_ob_config *from,
    const struct sh_css_isp_ob_stream_config *config,
    unsigned int size)
{
	unsigned int ob_bit_depth
	    = config->isp_pipe_version == 2 ? SH_CSS_BAYER_BITS : config->raw_bit_depth;
	unsigned int scale = 16 - ob_bit_depth;

	(void)size;
	switch (from->mode) {
	case IA_CSS_OB_MODE_FIXED:
		to->blacklevel_gr = from->level_gr >> scale;
		to->blacklevel_r  = from->level_r  >> scale;
		to->blacklevel_b  = from->level_b  >> scale;
		to->blacklevel_gb = from->level_gb >> scale;
		to->area_start_bq = 0;
		to->area_length_bq = 0;
		to->area_length_bq_inverse = 0;
		break;
	case IA_CSS_OB_MODE_RASTER:
		to->blacklevel_gr = 0;
		to->blacklevel_r = 0;
		to->blacklevel_b = 0;
		to->blacklevel_gb = 0;
		to->area_start_bq = from->start_position;
		to->area_length_bq =
		    (from->end_position - from->start_position) + 1;
		to->area_length_bq_inverse = AREA_LENGTH_UNIT / to->area_length_bq;
		break;
	default:
		to->blacklevel_gr = 0;
		to->blacklevel_r = 0;
		to->blacklevel_b = 0;
		to->blacklevel_gb = 0;
		to->area_start_bq = 0;
		to->area_length_bq = 0;
		to->area_length_bq_inverse = 0;
		break;
	}
}

void
ia_css_ob_vmem_encode(
    struct sh_css_isp_ob_vmem_params *to,
    const struct ia_css_ob_config *from,
    const struct sh_css_isp_ob_stream_config *config,
    unsigned int size)
{
	struct sh_css_isp_ob_params tmp;
	struct sh_css_isp_ob_params *ob = &tmp;

	(void)size;
	ia_css_ob_encode(&tmp, from, config, sizeof(tmp));

	{
		unsigned int i;
		unsigned int sp_obarea_start_bq  = ob->area_start_bq;
		unsigned int sp_obarea_length_bq = ob->area_length_bq;
		unsigned int low = sp_obarea_start_bq;
		unsigned int high = low + sp_obarea_length_bq;
		u16 all_ones = ~0;

		for (i = 0; i < OBAREA_MASK_SIZE; i++) {
			if (i >= low && i < high)
				to->vmask[i / ISP_VEC_NELEMS][i % ISP_VEC_NELEMS] = all_ones;
			else
				to->vmask[i / ISP_VEC_NELEMS][i % ISP_VEC_NELEMS] = 0;
		}
	}
}

void
ia_css_ob_dump(
    const struct sh_css_isp_ob_params *ob,
    unsigned int level)
{
	if (!ob) return;
	ia_css_debug_dtrace(level, "Optical Black:\n");
	ia_css_debug_dtrace(level, "\t%-32s = %d\n",
			    "ob_blacklevel_gr", ob->blacklevel_gr);
	ia_css_debug_dtrace(level, "\t%-32s = %d\n",
			    "ob_blacklevel_r", ob->blacklevel_r);
	ia_css_debug_dtrace(level, "\t%-32s = %d\n",
			    "ob_blacklevel_b", ob->blacklevel_b);
	ia_css_debug_dtrace(level, "\t%-32s = %d\n",
			    "ob_blacklevel_gb", ob->blacklevel_gb);
	ia_css_debug_dtrace(level, "\t%-32s = %d\n",
			    "obarea_start_bq", ob->area_start_bq);
	ia_css_debug_dtrace(level, "\t%-32s = %d\n",
			    "obarea_length_bq", ob->area_length_bq);
	ia_css_debug_dtrace(level, "\t%-32s = %d\n",
			    "obarea_length_bq_inverse",
			    ob->area_length_bq_inverse);
}

void
ia_css_ob_debug_dtrace(
    const struct ia_css_ob_config *config,
    unsigned int level)
{
	ia_css_debug_dtrace(level,
			    "config.mode=%d, config.level_gr=%d, config.level_r=%d, config.level_b=%d,  config.level_gb=%d, config.start_position=%d, config.end_position=%d\n",
			    config->mode,
			    config->level_gr, config->level_r,
			    config->level_b, config->level_gb,
			    config->start_position, config->end_position);
}