aboutsummaryrefslogtreecommitdiffstats
path: root/drivers/staging/media/atomisp/pci/atomisp2/css2400/hive_isp_css_shared/host/tag.c
blob: 2cf1d58941bfc5f806c1f0920c9587a5f4f1ec59 (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
/*
 * 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 "tag.h"
#include <platform_support.h>	/* NULL */
#include <assert_support.h>
#include "tag_local.h"

/*
 * @brief	Creates the tag description from the given parameters.
 * @param[in]	num_captures
 * @param[in]	skip
 * @param[in]	offset
 * @param[out]	tag_descr
 */
void
sh_css_create_tag_descr(int num_captures,
			unsigned int skip,
			int offset,
			unsigned int exp_id,
			struct sh_css_tag_descr *tag_descr)
{
	assert(tag_descr != NULL);

	tag_descr->num_captures = num_captures;
	tag_descr->skip		= skip;
	tag_descr->offset	= offset;
	tag_descr->exp_id	= exp_id;
}

/*
 * @brief	Encodes the members of tag description into a 32-bit value.
 * @param[in]	tag		Pointer to the tag description
 * @return	(unsigned int)	Encoded 32-bit tag-info
 */
unsigned int
sh_css_encode_tag_descr(struct sh_css_tag_descr *tag)
{
	int num_captures;
	unsigned int num_captures_sign;
	unsigned int skip;
	int offset;
	unsigned int offset_sign;
	unsigned int exp_id;
	unsigned int encoded_tag;

	assert(tag != NULL);

	if (tag->num_captures < 0) {
		num_captures = -tag->num_captures;
		num_captures_sign = 1;
	} else {
		num_captures = tag->num_captures;
		num_captures_sign = 0;
	}
	skip = tag->skip;
	if (tag->offset < 0) {
		offset = -tag->offset;
		offset_sign = 1;
	} else {
		offset = tag->offset;
		offset_sign = 0;
	}
	exp_id = tag->exp_id;

	if (exp_id != 0)
	{
		/* we encode either an exp_id or capture data */
		assert((num_captures == 0) && (skip == 0) && (offset == 0));

		encoded_tag = TAG_EXP | (exp_id & 0xFF) << TAG_EXP_ID_SHIFT;
	}
	else
	{
		encoded_tag = TAG_CAP 
				| ((num_captures_sign & 0x00000001) << TAG_NUM_CAPTURES_SIGN_SHIFT)
				| ((offset_sign       & 0x00000001) << TAG_OFFSET_SIGN_SHIFT)
				| ((num_captures      & 0x000000FF) << TAG_NUM_CAPTURES_SHIFT)
				| ((skip              & 0x000000FF) << TAG_OFFSET_SHIFT)
				| ((offset            & 0x000000FF) << TAG_SKIP_SHIFT);

	}
	return encoded_tag;
}