Skip to content

Commit 1733592

Browse files
povikjannau
authored andcommitted
ASoC: macaudio: Start speaker sense capture support
Signed-off-by: Martin Povišer <povik+lin@cutebit.org>
1 parent 629bc0a commit 1733592

1 file changed

Lines changed: 34 additions & 0 deletions

File tree

sound/soc/apple/macaudio.c

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -57,6 +57,7 @@ struct macaudio_snd_data {
5757
struct macaudio_link_props {
5858
/* frontend props */
5959
unsigned int bclk_ratio;
60+
bool is_sense;
6061

6162
/* backend props */
6263
bool is_speakers;
@@ -82,6 +83,11 @@ SND_SOC_DAILINK_DEFS(secondary,
8283
DAILINK_COMP_ARRAY(COMP_DUMMY()), // CODEC
8384
DAILINK_COMP_ARRAY(COMP_EMPTY()));
8485

86+
SND_SOC_DAILINK_DEFS(sense,
87+
DAILINK_COMP_ARRAY(COMP_CPU("mca-pcm-2")), // CPU
88+
DAILINK_COMP_ARRAY(COMP_DUMMY()), // CODEC
89+
DAILINK_COMP_ARRAY(COMP_EMPTY()));
90+
8591
static struct snd_soc_dai_link macaudio_fe_links[] = {
8692
{
8793
.name = "Primary",
@@ -106,6 +112,17 @@ static struct snd_soc_dai_link macaudio_fe_links[] = {
106112
.dai_fmt = MACAUDIO_DAI_FMT,
107113
SND_SOC_DAILINK_REG(secondary),
108114
},
115+
{
116+
.name = "Speaker Sense",
117+
.stream_name = "Speaker Sense",
118+
.dynamic = 1,
119+
.dpcm_capture = 1,
120+
.dai_fmt = (SND_SOC_DAIFMT_I2S | \
121+
SND_SOC_DAIFMT_CBP_CFP | \
122+
SND_SOC_DAIFMT_GATED | \
123+
SND_SOC_DAIFMT_IB_IF),
124+
SND_SOC_DAILINK_REG(sense),
125+
},
109126
};
110127

111128
static struct macaudio_link_props macaudio_fe_link_props[] = {
@@ -133,6 +150,9 @@ static struct macaudio_link_props macaudio_fe_link_props[] = {
133150
* those fancy speaker arrays.
134151
*/
135152
.bclk_ratio = 256,
153+
},
154+
{
155+
.is_sense = 1,
136156
}
137157
};
138158

@@ -626,6 +646,9 @@ static int macaudio_fe_init(struct snd_soc_pcm_runtime *rtd)
626646
struct macaudio_link_props *props = &ma->link_props[rtd->dai_link->id];
627647
int nslots = props->bclk_ratio / MACAUDIO_SLOTWIDTH;
628648

649+
if (props->is_sense)
650+
return snd_soc_dai_set_tdm_slot(snd_soc_rtd_to_cpu(rtd, 0), 0, 0xffff, 16, 16);
651+
629652
return snd_soc_dai_set_tdm_slot(snd_soc_rtd_to_cpu(rtd, 0), (1 << nslots) - 1,
630653
(1 << nslots) - 1, nslots, MACAUDIO_SLOTWIDTH);
631654
}
@@ -686,6 +709,13 @@ static int macaudio_add_backend_dai_route(struct snd_soc_card *card, struct snd_
686709
r->sink = "Headset Capture";
687710
}
688711

712+
/* If speakers, add sense capture path */
713+
if (is_speakers) {
714+
r = &routes[nroutes++];
715+
r->source = dai->stream[SNDRV_PCM_STREAM_CAPTURE].widget->name;
716+
r->sink = "Speaker Sense Capture";
717+
}
718+
689719
ret = snd_soc_dapm_add_routes(&card->dapm, routes, nroutes);
690720
if (ret)
691721
dev_err(card->dev, "failed adding dynamic DAPM routes for %s\n",
@@ -929,6 +959,7 @@ static const struct snd_soc_dapm_widget macaudio_snd_widgets[] = {
929959
SND_SOC_DAPM_AIF_OUT("Headphone Playback", NULL, 0, SND_SOC_NOPM, 0, 0),
930960

931961
SND_SOC_DAPM_AIF_IN("Headset Capture", NULL, 0, SND_SOC_NOPM, 0, 0),
962+
SND_SOC_DAPM_AIF_IN("Speaker Sense Capture", NULL, 0, SND_SOC_NOPM, 0, 0),
932963
};
933964

934965
static const struct snd_kcontrol_new macaudio_controls[] = {
@@ -952,6 +983,9 @@ static const struct snd_soc_dapm_route macaudio_dapm_routes[] = {
952983

953984
/* Capture paths */
954985
{ "PCM0 RX", NULL, "Headset Capture" },
986+
987+
/* Sense paths */
988+
{ "PCM2 RX", NULL, "Speaker Sense Capture" },
955989
};
956990

957991
static const struct of_device_id macaudio_snd_device_id[] = {

0 commit comments

Comments
 (0)