Merge tag 'for-4.15/dm-fixes' of git://git.kernel.org/pub/scm/linux/kernel/git/device...
[sfrench/cifs-2.6.git] / drivers / staging / media / atomisp / pci / atomisp2 / css2400 / hive_isp_css_shared / host / tag.c
1 /*
2  * Support for Intel Camera Imaging ISP subsystem.
3  * Copyright (c) 2015, Intel Corporation.
4  *
5  * This program is free software; you can redistribute it and/or modify it
6  * under the terms and conditions of the GNU General Public License,
7  * version 2, as published by the Free Software Foundation.
8  *
9  * This program is distributed in the hope it will be useful, but WITHOUT
10  * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
11  * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License for
12  * more details.
13  */
14
15 #include "tag.h"
16 #include <platform_support.h>   /* NULL */
17 #include <assert_support.h>
18 #include "tag_local.h"
19
20 /*
21  * @brief       Creates the tag description from the given parameters.
22  * @param[in]   num_captures
23  * @param[in]   skip
24  * @param[in]   offset
25  * @param[out]  tag_descr
26  */
27 void
28 sh_css_create_tag_descr(int num_captures,
29                         unsigned int skip,
30                         int offset,
31                         unsigned int exp_id,
32                         struct sh_css_tag_descr *tag_descr)
33 {
34         assert(tag_descr != NULL);
35
36         tag_descr->num_captures = num_captures;
37         tag_descr->skip         = skip;
38         tag_descr->offset       = offset;
39         tag_descr->exp_id       = exp_id;
40 }
41
42 /*
43  * @brief       Encodes the members of tag description into a 32-bit value.
44  * @param[in]   tag             Pointer to the tag description
45  * @return      (unsigned int)  Encoded 32-bit tag-info
46  */
47 unsigned int
48 sh_css_encode_tag_descr(struct sh_css_tag_descr *tag)
49 {
50         int num_captures;
51         unsigned int num_captures_sign;
52         unsigned int skip;
53         int offset;
54         unsigned int offset_sign;
55         unsigned int exp_id;
56         unsigned int encoded_tag;
57
58         assert(tag != NULL);
59
60         if (tag->num_captures < 0) {
61                 num_captures = -tag->num_captures;
62                 num_captures_sign = 1;
63         } else {
64                 num_captures = tag->num_captures;
65                 num_captures_sign = 0;
66         }
67         skip = tag->skip;
68         if (tag->offset < 0) {
69                 offset = -tag->offset;
70                 offset_sign = 1;
71         } else {
72                 offset = tag->offset;
73                 offset_sign = 0;
74         }
75         exp_id = tag->exp_id;
76
77         if (exp_id != 0)
78         {
79                 /* we encode either an exp_id or capture data */
80                 assert((num_captures == 0) && (skip == 0) && (offset == 0));
81
82                 encoded_tag = TAG_EXP | (exp_id & 0xFF) << TAG_EXP_ID_SHIFT;
83         }
84         else
85         {
86                 encoded_tag = TAG_CAP 
87                                 | ((num_captures_sign & 0x00000001) << TAG_NUM_CAPTURES_SIGN_SHIFT)
88                                 | ((offset_sign       & 0x00000001) << TAG_OFFSET_SIGN_SHIFT)
89                                 | ((num_captures      & 0x000000FF) << TAG_NUM_CAPTURES_SHIFT)
90                                 | ((skip              & 0x000000FF) << TAG_OFFSET_SHIFT)
91                                 | ((offset            & 0x000000FF) << TAG_SKIP_SHIFT);
92
93         }
94         return encoded_tag;
95 }