Skip to content

Commit c59faa3

Browse files
j-schambacherpelwell
authored andcommitted
ASoC: adds ADC8x support to the Hifiberry DAC8x
The driver probes for the ADC8x which can be stacked on top of the DAC8x. It enables a symmetric 8 channel capture using the dummy-dai. Signed-off-by: j-schambacher <joerg@hifiberry.com>
1 parent 3535fe1 commit c59faa3

File tree

1 file changed

+34
-4
lines changed

1 file changed

+34
-4
lines changed

sound/soc/bcm/rpi-simple-soundcard.c

Lines changed: 34 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -354,16 +354,46 @@ static struct snd_rpi_simple_drvdata drvdata_hifiberry_dac = {
354354
.dai = snd_hifiberry_dac_dai,
355355
};
356356

357+
SND_SOC_DAILINK_DEFS(hifiberry_dac8x,
358+
DAILINK_COMP_ARRAY(COMP_EMPTY()),
359+
DAILINK_COMP_ARRAY(COMP_CODEC("snd-soc-dummy", "snd-soc-dummy-dai")),
360+
DAILINK_COMP_ARRAY(COMP_EMPTY()));
361+
357362
static int hifiberry_dac8x_init(struct snd_soc_pcm_runtime *rtd)
358363
{
359364
struct snd_soc_dai *codec_dai = snd_soc_rtd_to_codec(rtd, 0);
365+
struct snd_soc_card *card = rtd->card;
366+
struct gpio_desc *gpio_desc;
367+
bool has_adc;
360368

361-
/* override the defaults to reflect 4 x PCM5102A on the card
362-
* and limit the sample rate to 192ksps
363-
*/
369+
/* Configure the codec for 8 channel playback */
364370
codec_dai->driver->playback.channels_max = 8;
365371
codec_dai->driver->playback.rates = SNDRV_PCM_RATE_8000_192000;
366372

373+
/* Activate capture based on ADC8x detection */
374+
gpio_desc = devm_gpiod_get(card->dev, "hasadc", GPIOD_IN);
375+
if (IS_ERR(gpio_desc)) {
376+
dev_err(card->dev, "Failed to get GPIO: %ld\n", PTR_ERR(gpio_desc));
377+
return PTR_ERR(gpio_desc);
378+
}
379+
380+
has_adc = gpiod_get_value(gpio_desc);
381+
382+
if (has_adc) {
383+
struct snd_soc_dai_link *dai = rtd->dai_link;
384+
385+
dev_info(card->dev, "ADC8x detected: capture enabled\n");
386+
codec_dai->driver->symmetric_rate = 1;
387+
codec_dai->driver->symmetric_channels = 1;
388+
codec_dai->driver->symmetric_sample_bits = 1;
389+
codec_dai->driver->capture.rates = SNDRV_PCM_RATE_8000_192000;
390+
dai->name = "HiFiBerry DAC8xADC8x";
391+
dai->stream_name = "HiFiBerry DAC8xADC8x HiFi";
392+
} else {
393+
dev_info(card->dev, "no ADC8x detected\n");
394+
rtd->dai_link->playback_only = 1; // Disable capture
395+
}
396+
367397
return 0;
368398
}
369399

@@ -375,7 +405,7 @@ static struct snd_soc_dai_link snd_hifiberry_dac8x_dai[] = {
375405
SND_SOC_DAIFMT_NB_NF |
376406
SND_SOC_DAIFMT_CBS_CFS,
377407
.init = hifiberry_dac8x_init,
378-
SND_SOC_DAILINK_REG(hifiberry_dac),
408+
SND_SOC_DAILINK_REG(hifiberry_dac8x),
379409
},
380410
};
381411

0 commit comments

Comments
 (0)