brintos

brintos / linux-shallow public Read only

0
0
Text · 2.0 KiB · 4a3d554 Raw
92 lines · c
1// SPDX-License-Identifier: GPL-2.02/*3 * camss-format.c4 *5 * Qualcomm MSM Camera Subsystem - Format helpers6 *7 * Copyright (c) 2023, The Linux Foundation. All rights reserved.8 * Copyright (c) 2023 Qualcomm Technologies, Inc.9 */10#include <linux/bug.h>11#include <linux/errno.h>12 13#include "camss-format.h"14 15/*16 * camss_format_get_bpp - Map media bus format to bits per pixel17 * @formats: supported media bus formats array18 * @nformats: size of @formats array19 * @code: media bus format code20 *21 * Return number of bits per pixel22 */23u8 camss_format_get_bpp(const struct camss_format_info *formats, unsigned int nformats, u32 code)24{25	unsigned int i;26 27	for (i = 0; i < nformats; i++)28		if (code == formats[i].code)29			return formats[i].mbus_bpp;30 31	WARN(1, "Unknown format\n");32 33	return formats[0].mbus_bpp;34}35 36/*37 * camss_format_find_code - Find a format code in an array38 * @code: a pointer to media bus format codes array39 * @n_code: size of @code array40 * @index: index of code in the array41 * @req_code: required code42 *43 * Return media bus format code44 */45u32 camss_format_find_code(u32 *code, unsigned int n_code, unsigned int index, u32 req_code)46{47	unsigned int i;48 49	if (!req_code && index >= n_code)50		return 0;51 52	for (i = 0; i < n_code; i++) {53		if (req_code) {54			if (req_code == code[i])55				return req_code;56		} else {57			if (i == index)58				return code[i];59		}60	}61 62	return code[0];63}64 65/*66 * camss_format_find_format - Find a format in an array67 * @code: media bus format code68 * @pixelformat: V4L2 pixel format FCC identifier69 * @formats: a pointer to formats array70 * @nformats: size of @formats array71 *72 * Return index of a format or a negative error code otherwise73 */74int camss_format_find_format(u32 code, u32 pixelformat, const struct camss_format_info *formats,75			     unsigned int nformats)76{77	unsigned int i;78 79	for (i = 0; i < nformats; i++) {80		if (formats[i].code == code &&81		    formats[i].pixelformat == pixelformat)82			return i;83	}84 85	for (i = 0; i < nformats; i++) {86		if (formats[i].code == code)87			return i;88	}89 90	return -EINVAL;91}92