|
21 | 21 |
|
22 | 22 | #include <sound/soc.h>
|
23 | 23 |
|
| 24 | +static bool rates_384k = false; |
| 25 | + |
| 26 | +static const u32 pcm5102a_dai_rates_192k[] = { |
| 27 | + 8000, 11025, 16000, 22050, 32000, 44100, 48000, 64000, 88200, 96000, |
| 28 | + 176400, 192000, |
| 29 | +}; |
| 30 | + |
| 31 | +static const struct snd_pcm_hw_constraint_list constraints_rates_192k = { |
| 32 | + .list = pcm5102a_dai_rates_192k, |
| 33 | + .count = ARRAY_SIZE(pcm5102a_dai_rates_192k), |
| 34 | +}; |
| 35 | + |
| 36 | +static const u32 pcm5102a_dai_rates_384k[] = { |
| 37 | + 8000, 11025, 16000, 22050, 32000, 44100, 48000, 64000, 88200, 96000, |
| 38 | + 176400, 192000, 352800, 384000, |
| 39 | +}; |
| 40 | + |
| 41 | +static const struct snd_pcm_hw_constraint_list constraints_rates_384k = { |
| 42 | + .list = pcm5102a_dai_rates_384k, |
| 43 | + .count = ARRAY_SIZE(pcm5102a_dai_rates_384k), |
| 44 | +}; |
| 45 | + |
| 46 | +static int pcm5102a_dai_startup(struct snd_pcm_substream *substream, |
| 47 | + struct snd_soc_dai *dai) |
| 48 | +{ |
| 49 | + struct snd_soc_codec *codec = dai->codec; |
| 50 | + int ret; |
| 51 | + |
| 52 | + dev_dbg(codec->dev, "%s: setup rates (%s) constraint.\n", __func__, |
| 53 | + (rates_384k ? "8k-384k" : "8k-192k")); |
| 54 | + |
| 55 | + ret = snd_pcm_hw_constraint_list(substream->runtime, 0, |
| 56 | + SNDRV_PCM_HW_PARAM_RATE, |
| 57 | + (rates_384k ? &constraints_rates_384k |
| 58 | + : &constraints_rates_192k)); |
| 59 | + if (ret != 0) |
| 60 | + dev_err(codec->dev, "%s: Failed to set rates constraint: %d!\n", |
| 61 | + __func__, ret); |
| 62 | + |
| 63 | + return ret; |
| 64 | +} |
| 65 | + |
| 66 | +static const struct snd_soc_dai_ops pcm5102a_dai_ops = { |
| 67 | + .startup = pcm5102a_dai_startup, |
| 68 | +}; |
| 69 | + |
24 | 70 | static struct snd_soc_dai_driver pcm5102a_dai = {
|
25 | 71 | .name = "pcm5102a-hifi",
|
26 | 72 | .playback = {
|
27 | 73 | .channels_min = 2,
|
28 | 74 | .channels_max = 2,
|
29 |
| - .rates = SNDRV_PCM_RATE_8000_192000, |
| 75 | + .rates = SNDRV_PCM_RATE_KNOT, |
30 | 76 | .formats = SNDRV_PCM_FMTBIT_S16_LE |
|
31 | 77 | SNDRV_PCM_FMTBIT_S24_LE |
|
32 | 78 | SNDRV_PCM_FMTBIT_S32_LE
|
33 | 79 | },
|
| 80 | + .ops = &pcm5102a_dai_ops, |
34 | 81 | };
|
35 | 82 |
|
36 | 83 | static struct snd_soc_codec_driver soc_codec_dev_pcm5102a;
|
37 | 84 |
|
38 | 85 | static int pcm5102a_probe(struct platform_device *pdev)
|
39 | 86 | {
|
| 87 | + if (pdev->dev.of_node) |
| 88 | + rates_384k = of_property_read_bool(pdev->dev.of_node, |
| 89 | + "pcm5102a,384k"); |
| 90 | + |
40 | 91 | return snd_soc_register_codec(&pdev->dev, &soc_codec_dev_pcm5102a,
|
41 | 92 | &pcm5102a_dai, 1);
|
42 | 93 | }
|
|
0 commit comments