参照元

説明

引数

返り値

参考

実装

/**
 * snd_soc_read_signed - Read a codec register and interprete as signed value
 * @component: component
 * @reg: Register to read
 * @mask: Mask to use after shifting the register value
 * @shift: Right shift of register value
 * @sign_bit: Bit that describes if a number is negative or not.
 * @signed_val: Pointer to where the read value should be stored
 *
 * This functions reads a codec register. The register value is shifted right
 * by 'shift' bits and masked with the given 'mask'. Afterwards it translates
 * the given registervalue into a signed integer if sign_bit is non-zero.
 *
 * Returns 0 on sucess, otherwise an error value
 */
static int snd_soc_read_signed(struct snd_soc_component *component,
        unsigned int reg, unsigned int mask, unsigned int shift,
        unsigned int sign_bit, int *signed_val)
{
        int ret;
        unsigned int val;

        ret = snd_soc_component_read(component, reg, &val);
        if (ret < 0)
                return ret;
        val = (val >> shift) & mask;

        if (!sign_bit) {
                *signed_val = val;
                return 0;
        }

        /* non-negative number */
        if (!(val & BIT(sign_bit))) {
                *signed_val = val;
                return 0;
        }
        ret = val;

        /*
         * The register most probably does not contain a full-sized int.
         * Instead we have an arbitrary number of bits in a signed
         * representation which has to be translated into a full-sized int.
         * This is done by filling up all bits above the sign-bit.
         */
        ret |= ~((int)(BIT(sign_bit) - 1));

        *signed_val = ret;

        return 0;
}

コメント


トップ   編集 凍結 差分 履歴 添付 複製 名前変更 リロード   新規 一覧 検索 最終更新   ヘルプ   最終更新のRSS
Last-modified: 2016-06-08 (水) 13:01:24