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 "tag.h" 17 #include <platform_support.h> /* NULL */ 18 #include <assert_support.h> 19 #include "tag_local.h" 20 21 /* 22 * @brief Creates the tag description from the given parameters. 23 * @param[in] num_captures 24 * @param[in] skip 25 * @param[in] offset 26 * @param[out] tag_descr 27 */ 28 void 29 sh_css_create_tag_descr(int num_captures, 30 unsigned int skip, 31 int offset, 32 unsigned int exp_id, 33 struct sh_css_tag_descr *tag_descr) 34 { 35 assert(tag_descr); 36 37 tag_descr->num_captures = num_captures; 38 tag_descr->skip = skip; 39 tag_descr->offset = offset; 40 tag_descr->exp_id = exp_id; 41 } 42 43 /* 44 * @brief Encodes the members of tag description into a 32-bit value. 45 * @param[in] tag Pointer to the tag description 46 * @return (unsigned int) Encoded 32-bit tag-info 47 */ 48 unsigned int 49 sh_css_encode_tag_descr(struct sh_css_tag_descr *tag) 50 { 51 int num_captures; 52 unsigned int num_captures_sign; 53 unsigned int skip; 54 int offset; 55 unsigned int offset_sign; 56 unsigned int exp_id; 57 unsigned int encoded_tag; 58 59 assert(tag); 60 61 if (tag->num_captures < 0) { 62 num_captures = -tag->num_captures; 63 num_captures_sign = 1; 64 } else { 65 num_captures = tag->num_captures; 66 num_captures_sign = 0; 67 } 68 skip = tag->skip; 69 if (tag->offset < 0) { 70 offset = -tag->offset; 71 offset_sign = 1; 72 } else { 73 offset = tag->offset; 74 offset_sign = 0; 75 } 76 exp_id = tag->exp_id; 77 78 if (exp_id != 0) { 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 } else { 84 encoded_tag = TAG_CAP 85 | ((num_captures_sign & 0x00000001) << TAG_NUM_CAPTURES_SIGN_SHIFT) 86 | ((offset_sign & 0x00000001) << TAG_OFFSET_SIGN_SHIFT) 87 | ((num_captures & 0x000000FF) << TAG_NUM_CAPTURES_SHIFT) 88 | ((skip & 0x000000FF) << TAG_OFFSET_SHIFT) 89 | ((offset & 0x000000FF) << TAG_SKIP_SHIFT); 90 } 91 return encoded_tag; 92 } 93