9290b3b9cb3b7b3d79d65829b3a34ff5397e8b53
[openwrt/openwrt.git] /
1 From e28e3e0d01c0fcb628e841977b51c45189b43f47 Mon Sep 17 00:00:00 2001
2 From: Viorel Suman <viorel.suman@nxp.com>
3 Date: Thu, 8 Mar 2018 14:37:30 +0200
4 Subject: [PATCH] MLK-17580: ASoC: fsl: dsd: Add DSD utilities helper
5
6 Add DSD utilities helper.
7
8 Signed-off-by: Viorel Suman <viorel.suman@nxp.com>
9 Reviewed-by: Shengjiu Wang <shengjiu.wang@nxp.com
10 ---
11 sound/soc/fsl/fsl_dsd.h | 59 +++++++++++++++++++++++++++++++++++++++++++++++++
12 1 file changed, 59 insertions(+)
13 create mode 100644 sound/soc/fsl/fsl_dsd.h
14
15 --- /dev/null
16 +++ b/sound/soc/fsl/fsl_dsd.h
17 @@ -0,0 +1,59 @@
18 +/*
19 + * Copyright 2018 NXP
20 + *
21 + * This program is free software; you can redistribute it and/or modify
22 + * it under the terms of the GNU General Public License version 2 as
23 + * published by the Free Software Foundation.
24 + */
25 +
26 +#ifndef __FSL_DSD_H
27 +#define __FSL_DSD_H
28 +
29 +#include <linux/pinctrl/consumer.h>
30 +#include <sound/pcm_params.h>
31 +#include <sound/soc.h>
32 +
33 +static bool fsl_is_dsd(struct snd_pcm_hw_params *params)
34 +{
35 + snd_pcm_format_t format = params_format(params);
36 +
37 + switch (format) {
38 + case SNDRV_PCM_FORMAT_DSD_U8:
39 + case SNDRV_PCM_FORMAT_DSD_U16_LE:
40 + case SNDRV_PCM_FORMAT_DSD_U16_BE:
41 + case SNDRV_PCM_FORMAT_DSD_U32_LE:
42 + case SNDRV_PCM_FORMAT_DSD_U32_BE:
43 + return true;
44 + default:
45 + return false;
46 + }
47 +}
48 +
49 +static struct pinctrl_state *fsl_get_pins_state(struct pinctrl *pinctrl,
50 + struct snd_pcm_hw_params *params)
51 +{
52 + int dsd_bclk;
53 + struct pinctrl_state *state = 0;
54 +
55 + if (fsl_is_dsd(params)) {
56 + dsd_bclk = params_rate(params) * params_physical_width(params);
57 +
58 + switch (dsd_bclk) {
59 + case 22579200: /* DSD512 */
60 + state = pinctrl_lookup_state(pinctrl, "dsd512");
61 + break;
62 + }
63 +
64 + /* Get default DSD state */
65 + if (IS_ERR_OR_NULL(state))
66 + state = pinctrl_lookup_state(pinctrl, "dsd");
67 + }
68 +
69 + /* Get default state */
70 + if (IS_ERR_OR_NULL(state))
71 + state = pinctrl_lookup_state(pinctrl, "default");
72 +
73 + return state;
74 +}
75 +
76 +#endif /* __FSL_DSD_H */