1 // SPDX-License-Identifier: MIT 2 /* 3 * Copyright (C) 2019 NVIDIA Corporation 4 */ 5 6 #include <linux/bug.h> 7 8 #include <sound/hda_verbs.h> 9 10 #include "hda.h" 11 tegra_hda_parse_format(unsigned int format,struct tegra_hda_format * fmt)12void tegra_hda_parse_format(unsigned int format, struct tegra_hda_format *fmt) 13 { 14 unsigned int mul, div, bits, channels; 15 16 if (format & AC_FMT_TYPE_NON_PCM) 17 fmt->pcm = false; 18 else 19 fmt->pcm = true; 20 21 if (format & AC_FMT_BASE_44K) 22 fmt->sample_rate = 44100; 23 else 24 fmt->sample_rate = 48000; 25 26 mul = (format & AC_FMT_MULT_MASK) >> AC_FMT_MULT_SHIFT; 27 div = (format & AC_FMT_DIV_MASK) >> AC_FMT_DIV_SHIFT; 28 29 fmt->sample_rate *= (mul + 1) / (div + 1); 30 31 switch (format & AC_FMT_BITS_MASK) { 32 case AC_FMT_BITS_8: 33 fmt->bits = 8; 34 break; 35 36 case AC_FMT_BITS_16: 37 fmt->bits = 16; 38 break; 39 40 case AC_FMT_BITS_20: 41 fmt->bits = 20; 42 break; 43 44 case AC_FMT_BITS_24: 45 fmt->bits = 24; 46 break; 47 48 case AC_FMT_BITS_32: 49 fmt->bits = 32; 50 break; 51 52 default: 53 bits = (format & AC_FMT_BITS_MASK) >> AC_FMT_BITS_SHIFT; 54 WARN(1, "invalid number of bits: %#x\n", bits); 55 fmt->bits = 8; 56 break; 57 } 58 59 channels = (format & AC_FMT_CHAN_MASK) >> AC_FMT_CHAN_SHIFT; 60 61 /* channels are encoded as n - 1 */ 62 fmt->channels = channels + 1; 63 } 64