Skip to content

Commit f7025d9

Browse files
384k: Add support for 352k8 and 384k to ALSA ASoC pcm5102a codec driver
hifiberry-dac overlay is used by both their 1st gen 'B' PCM5102 boards and the later gen DAC+ Light ES9023. (As well as being used by several other third party ES9023 boards.) The PCM5102a is most certainly 352k8/384k capable. The ES9023 datasheet states 192k PCM MAX, but we know that some (not all) chips are 384k capable. (NB: OSC is the other factor. Datasheet requirement is >= 192xFS. Most ES9023 DAC HAT manufacturers use 50MHz OSC.) So we default to supporting 8k-192k MAX, unless dt param, '384k', is specified via hifiberry-dac overlay and parsed by pcm5102a codec driver, in which case, the 8k-384k constraint is used. NB: Original plan, adding 384k support to pcm5102a codec, was to use es9023 codec and hifiberry-dacpluslight overlay for HB DAC+ Light, but HB would prefer to contine with their use of hifiberry_dac/pcm5102a combo for DAC+ Light... "However, at the moment I would like to stick with the PCM5102 driver with the DAC+ Light." Signed-off-by: DigitalDreamtime <[email protected]>
1 parent 1568cef commit f7025d9

File tree

3 files changed

+60
-4
lines changed

3 files changed

+60
-4
lines changed

arch/arm/boot/dts/overlays/README

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -343,8 +343,9 @@ Params: <None>
343343

344344
Name: hifiberry-dac
345345
Info: Configures the HifiBerry DAC audio card
346-
Load: dtoverlay=hifiberry-dac
347-
Params: <None>
346+
Load: dtoverlay=hifiberry-dac,<param>
347+
Params: 384k Instructs the pcm5102a codec driver to support
348+
352k8 and 384k sample rates.
348349

349350

350351
Name: hifiberry-dacplus

arch/arm/boot/dts/overlays/hifiberry-dac-overlay.dts

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@
1515
fragment@1 {
1616
target-path = "/";
1717
__overlay__ {
18-
pcm5102a-codec {
18+
pcm5102a: pcm5102a-codec {
1919
#sound-dai-cells = <0>;
2020
compatible = "ti,pcm5102a";
2121
status = "okay";
@@ -31,4 +31,8 @@
3131
status = "okay";
3232
};
3333
};
34+
35+
__overrides__ {
36+
384k = <&pcm5102a>,"pcm5102a,384k?";
37+
};
3438
};

sound/soc/codecs/pcm5102a.c

Lines changed: 52 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,22 +21,73 @@
2121

2222
#include <sound/soc.h>
2323

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+
2470
static struct snd_soc_dai_driver pcm5102a_dai = {
2571
.name = "pcm5102a-hifi",
2672
.playback = {
2773
.channels_min = 2,
2874
.channels_max = 2,
29-
.rates = SNDRV_PCM_RATE_8000_192000,
75+
.rates = SNDRV_PCM_RATE_KNOT,
3076
.formats = SNDRV_PCM_FMTBIT_S16_LE |
3177
SNDRV_PCM_FMTBIT_S24_LE |
3278
SNDRV_PCM_FMTBIT_S32_LE
3379
},
80+
.ops = &pcm5102a_dai_ops,
3481
};
3582

3683
static struct snd_soc_codec_driver soc_codec_dev_pcm5102a;
3784

3885
static int pcm5102a_probe(struct platform_device *pdev)
3986
{
87+
if (pdev->dev.of_node)
88+
rates_384k = of_property_read_bool(pdev->dev.of_node,
89+
"pcm5102a,384k");
90+
4091
return snd_soc_register_codec(&pdev->dev, &soc_codec_dev_pcm5102a,
4192
&pcm5102a_dai, 1);
4293
}

0 commit comments

Comments
 (0)