diff options
author | Daniel Baumann <daniel.baumann@progress-linux.org> | 2024-04-11 08:27:49 +0000 |
---|---|---|
committer | Daniel Baumann <daniel.baumann@progress-linux.org> | 2024-04-11 08:27:49 +0000 |
commit | ace9429bb58fd418f0c81d4c2835699bddf6bde6 (patch) | |
tree | b2d64bc10158fdd5497876388cd68142ca374ed3 /drivers/staging/media/atomisp/pci/camera/util | |
parent | Initial commit. (diff) | |
download | linux-ace9429bb58fd418f0c81d4c2835699bddf6bde6.tar.xz linux-ace9429bb58fd418f0c81d4c2835699bddf6bde6.zip |
Adding upstream version 6.6.15.upstream/6.6.15
Signed-off-by: Daniel Baumann <daniel.baumann@progress-linux.org>
Diffstat (limited to 'drivers/staging/media/atomisp/pci/camera/util')
-rw-r--r-- | drivers/staging/media/atomisp/pci/camera/util/interface/ia_css_util.h | 143 | ||||
-rw-r--r-- | drivers/staging/media/atomisp/pci/camera/util/src/util.c | 197 |
2 files changed, 340 insertions, 0 deletions
diff --git a/drivers/staging/media/atomisp/pci/camera/util/interface/ia_css_util.h b/drivers/staging/media/atomisp/pci/camera/util/interface/ia_css_util.h new file mode 100644 index 0000000000..59df44d696 --- /dev/null +++ b/drivers/staging/media/atomisp/pci/camera/util/interface/ia_css_util.h @@ -0,0 +1,143 @@ +/* SPDX-License-Identifier: GPL-2.0 */ +/* + * 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. + */ + +#ifndef __IA_CSS_UTIL_H__ +#define __IA_CSS_UTIL_H__ + +#include <linux/errno.h> + +#include <ia_css_err.h> +#include <type_support.h> +#include <ia_css_frame_public.h> +#include <ia_css_stream_public.h> +#include <ia_css_stream_format.h> + +/* @brief convert "errno" error code to "ia_css_err" error code + * + * @param[in] "errno" error code + * @return "ia_css_err" error code + * + */ +int ia_css_convert_errno( + int in_err); + +/* @brief check vf frame info. + * + * @param[in] info + * @return 0 or error code upon error. + * + */ +int ia_css_util_check_vf_info( + const struct ia_css_frame_info *const info); + +/* @brief check input configuration. + * + * @param[in] stream_config + * @param[in] must_be_raw + * @return 0 or error code upon error. + * + */ +int ia_css_util_check_input( + const struct ia_css_stream_config *const stream_config, + bool must_be_raw, + bool must_be_yuv); + +/* @brief check vf and out frame info. + * + * @param[in] out_info + * @param[in] vf_info + * @return 0 or error code upon error. + * + */ +int ia_css_util_check_vf_out_info( + const struct ia_css_frame_info *const out_info, + const struct ia_css_frame_info *const vf_info); + +/* @brief check width and height + * + * @param[in] width + * @param[in] height + * @return 0 or error code upon error. + * + */ +int ia_css_util_check_res( + unsigned int width, + unsigned int height); + +/* ISP2401 */ +/* @brief compare resolutions (less or equal) + * + * @param[in] a resolution + * @param[in] b resolution + * @return true if both dimensions of a are less or + * equal than those of b, false otherwise + * + */ +bool ia_css_util_res_leq( + struct ia_css_resolution a, + struct ia_css_resolution b); + +/* ISP2401 */ +/** + * @brief Check if resolution is zero + * + * @param[in] resolution The resolution to check + * + * @returns true if resolution is zero + */ +bool ia_css_util_resolution_is_zero( + const struct ia_css_resolution resolution); + +/* ISP2401 */ +/** + * @brief Check if resolution is even + * + * @param[in] resolution The resolution to check + * + * @returns true if resolution is even + */ +bool ia_css_util_resolution_is_even( + const struct ia_css_resolution resolution); + +/* @brief check width and height + * + * @param[in] stream_format + * @param[in] two_ppc + * @return bits per pixel based on given parameters. + * + */ +unsigned int ia_css_util_input_format_bpp( + enum atomisp_input_format stream_format, + bool two_ppc); + +/* @brief check if input format it raw + * + * @param[in] stream_format + * @return true if the input format is raw or false otherwise + * + */ +bool ia_css_util_is_input_format_raw( + enum atomisp_input_format stream_format); + +/* @brief check if input format it yuv + * + * @param[in] stream_format + * @return true if the input format is yuv or false otherwise + * + */ +bool ia_css_util_is_input_format_yuv( + enum atomisp_input_format stream_format); + +#endif /* __IA_CSS_UTIL_H__ */ diff --git a/drivers/staging/media/atomisp/pci/camera/util/src/util.c b/drivers/staging/media/atomisp/pci/camera/util/src/util.c new file mode 100644 index 0000000000..40a71e37cc --- /dev/null +++ b/drivers/staging/media/atomisp/pci/camera/util/src/util.c @@ -0,0 +1,197 @@ +// SPDX-License-Identifier: GPL-2.0 +/* + * 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_util.h" +#include <ia_css_frame.h> +#include <assert_support.h> +#include <math_support.h> + +/* for ia_css_binary_max_vf_width() */ +#include "ia_css_binary.h" + +/* MW: Table look-up ??? */ +unsigned int ia_css_util_input_format_bpp( + enum atomisp_input_format format, + bool two_ppc) +{ + unsigned int rval = 0; + + switch (format) { + case ATOMISP_INPUT_FORMAT_YUV420_8_LEGACY: + case ATOMISP_INPUT_FORMAT_YUV420_8: + case ATOMISP_INPUT_FORMAT_YUV422_8: + case ATOMISP_INPUT_FORMAT_RGB_888: + case ATOMISP_INPUT_FORMAT_RAW_8: + case ATOMISP_INPUT_FORMAT_BINARY_8: + case ATOMISP_INPUT_FORMAT_EMBEDDED: + rval = 8; + break; + case ATOMISP_INPUT_FORMAT_YUV420_10: + case ATOMISP_INPUT_FORMAT_YUV422_10: + case ATOMISP_INPUT_FORMAT_RAW_10: + rval = 10; + break; + case ATOMISP_INPUT_FORMAT_YUV420_16: + case ATOMISP_INPUT_FORMAT_YUV422_16: + rval = 16; + break; + case ATOMISP_INPUT_FORMAT_RGB_444: + rval = 4; + break; + case ATOMISP_INPUT_FORMAT_RGB_555: + rval = 5; + break; + case ATOMISP_INPUT_FORMAT_RGB_565: + rval = 65; + break; + case ATOMISP_INPUT_FORMAT_RGB_666: + case ATOMISP_INPUT_FORMAT_RAW_6: + rval = 6; + break; + case ATOMISP_INPUT_FORMAT_RAW_7: + rval = 7; + break; + case ATOMISP_INPUT_FORMAT_RAW_12: + rval = 12; + break; + case ATOMISP_INPUT_FORMAT_RAW_14: + if (two_ppc) + rval = 14; + else + rval = 12; + break; + case ATOMISP_INPUT_FORMAT_RAW_16: + if (two_ppc) + rval = 16; + else + rval = 12; + break; + default: + rval = 0; + break; + } + return rval; +} + +int ia_css_util_check_vf_info( + const struct ia_css_frame_info *const info) +{ + int err; + unsigned int max_vf_width; + + assert(info); + err = ia_css_frame_check_info(info); + if (err) + return err; + max_vf_width = ia_css_binary_max_vf_width(); + if (max_vf_width != 0 && info->res.width > max_vf_width * 2) + return -EINVAL; + return 0; +} + +int ia_css_util_check_vf_out_info( + const struct ia_css_frame_info *const out_info, + const struct ia_css_frame_info *const vf_info) +{ + int err; + + assert(out_info); + assert(vf_info); + + err = ia_css_frame_check_info(out_info); + if (err) + return err; + err = ia_css_util_check_vf_info(vf_info); + if (err) + return err; + return 0; +} + +int ia_css_util_check_res(unsigned int width, unsigned int height) +{ + /* height can be odd number for jpeg/embedded data from ISYS2401 */ + if (((width == 0) || + (height == 0) || + IS_ODD(width))) { + return -EINVAL; + } + return 0; +} + +/* ISP2401 */ +bool ia_css_util_res_leq(struct ia_css_resolution a, struct ia_css_resolution b) +{ + return a.width <= b.width && a.height <= b.height; +} + +/* ISP2401 */ +bool ia_css_util_resolution_is_zero(const struct ia_css_resolution resolution) +{ + return (resolution.width == 0) || (resolution.height == 0); +} + +/* ISP2401 */ +bool ia_css_util_resolution_is_even(const struct ia_css_resolution resolution) +{ + return IS_EVEN(resolution.height) && IS_EVEN(resolution.width); +} + +bool ia_css_util_is_input_format_raw(enum atomisp_input_format format) +{ + return ((format == ATOMISP_INPUT_FORMAT_RAW_6) || + (format == ATOMISP_INPUT_FORMAT_RAW_7) || + (format == ATOMISP_INPUT_FORMAT_RAW_8) || + (format == ATOMISP_INPUT_FORMAT_RAW_10) || + (format == ATOMISP_INPUT_FORMAT_RAW_12)); + /* raw_14 and raw_16 are not supported as input formats to the ISP. + * They can only be copied to a frame in memory using the + * copy binary. + */ +} + +bool ia_css_util_is_input_format_yuv(enum atomisp_input_format format) +{ + return format == ATOMISP_INPUT_FORMAT_YUV420_8_LEGACY || + format == ATOMISP_INPUT_FORMAT_YUV420_8 || + format == ATOMISP_INPUT_FORMAT_YUV420_10 || + format == ATOMISP_INPUT_FORMAT_YUV420_16 || + format == ATOMISP_INPUT_FORMAT_YUV422_8 || + format == ATOMISP_INPUT_FORMAT_YUV422_10 || + format == ATOMISP_INPUT_FORMAT_YUV422_16; +} + +int ia_css_util_check_input( + const struct ia_css_stream_config *const stream_config, + bool must_be_raw, + bool must_be_yuv) +{ + assert(stream_config); + + if (!stream_config) + return -EINVAL; + + if (stream_config->input_config.effective_res.width == 0 || + stream_config->input_config.effective_res.height == 0) + return -EINVAL; + if (must_be_raw && + !ia_css_util_is_input_format_raw(stream_config->input_config.format)) + return -EINVAL; + + if (must_be_yuv && + !ia_css_util_is_input_format_yuv(stream_config->input_config.format)) + return -EINVAL; + + return 0; +} |