xref: /linux/drivers/media/dvb-frontends/cxd2880/cxd2880_common.c (revision c13aca79ff3c4af5fd31a5b2743a90eba6e36a26)
1*1a3ef038SYasunari Takiguchi // SPDX-License-Identifier: GPL-2.0
2*1a3ef038SYasunari Takiguchi /*
3*1a3ef038SYasunari Takiguchi  * cxd2880_common.c
4*1a3ef038SYasunari Takiguchi  * Sony CXD2880 DVB-T2/T tuner + demodulator driver
5*1a3ef038SYasunari Takiguchi  * common functions
6*1a3ef038SYasunari Takiguchi  *
7*1a3ef038SYasunari Takiguchi  * Copyright (C) 2016, 2017, 2018 Sony Semiconductor Solutions Corporation
8*1a3ef038SYasunari Takiguchi  */
9*1a3ef038SYasunari Takiguchi 
10*1a3ef038SYasunari Takiguchi #include "cxd2880_common.h"
11*1a3ef038SYasunari Takiguchi 
cxd2880_convert2s_complement(u32 value,u32 bitlen)12*1a3ef038SYasunari Takiguchi int cxd2880_convert2s_complement(u32 value, u32 bitlen)
13*1a3ef038SYasunari Takiguchi {
14*1a3ef038SYasunari Takiguchi 	if (!bitlen || bitlen >= 32)
15*1a3ef038SYasunari Takiguchi 		return (int)value;
16*1a3ef038SYasunari Takiguchi 
17*1a3ef038SYasunari Takiguchi 	if (value & (u32)(1 << (bitlen - 1)))
18*1a3ef038SYasunari Takiguchi 		return (int)(GENMASK(31, bitlen) | value);
19*1a3ef038SYasunari Takiguchi 	else
20*1a3ef038SYasunari Takiguchi 		return (int)(GENMASK(bitlen - 1, 0) & value);
21*1a3ef038SYasunari Takiguchi }
22