Skip to content

Commit 9fe9a85

Browse files
marcanjannau
authored andcommitted
macaudio: Allow DT enabled speakers and gate them off in the driver
For machines where we do not consider things safe yet, require the commandline argument. Without it, speakers are simply disabled, we don't refuse probe entirely. Signed-off-by: Hector Martin <marcan@marcan.st>
1 parent 07fa5db commit 9fe9a85

1 file changed

Lines changed: 15 additions & 22 deletions

File tree

sound/soc/apple/macaudio.c

Lines changed: 15 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -70,6 +70,7 @@ struct macaudio_limit_cfg {
7070
struct macaudio_platform_cfg {
7171
struct macaudio_limit_cfg limits[MAX_LIMITS];
7272
int (*fixup)(struct snd_soc_card *card);
73+
bool enable_speakers;
7374
};
7475

7576
struct macaudio_snd_data {
@@ -487,7 +488,6 @@ static int macaudio_parse_of(struct macaudio_snd_data *ma)
487488
if (!card->dai_link || !ma->link_props)
488489
return -ENOMEM;
489490

490-
card->num_links = num_links;
491491
link = card->dai_link;
492492
link_props = ma->link_props;
493493

@@ -503,6 +503,9 @@ static int macaudio_parse_of(struct macaudio_snd_data *ma)
503503
for (i = 0; i < num_links; i++)
504504
card->dai_link[i].id = i;
505505

506+
/* We might disable the speakers, so count again */
507+
num_links = ARRAY_SIZE(macaudio_fe_links);
508+
506509
/* Fill in the BEs */
507510
for_each_available_child_of_node(dev->of_node, np) {
508511
const char *link_name;
@@ -520,8 +523,13 @@ static int macaudio_parse_of(struct macaudio_snd_data *ma)
520523

521524
speakers = !strcmp(link_name, "Speaker")
522525
|| !strcmp(link_name, "Speakers");
523-
if (speakers)
526+
if (speakers) {
527+
if (!ma->cfg->enable_speakers && !please_blow_up_my_speakers) {
528+
dev_err(card->dev, "driver can't assure safety on this model, disabling speakers\n");
529+
continue;
530+
}
524531
ma->has_speakers = 1;
532+
}
525533

526534
cpu = of_get_child_by_name(np, "cpu");
527535
codec = of_get_child_by_name(np, "codec");
@@ -615,11 +623,15 @@ static int macaudio_parse_of(struct macaudio_snd_data *ma)
615623
of_node_put(codec);
616624
of_node_put(cpu);
617625
cpu = codec = NULL;
626+
627+
num_links += num_bes;
618628
}
619629

620630
for (i = 0; i < ARRAY_SIZE(macaudio_fe_links); i++)
621631
card->dai_link[i].platforms->of_node = platform;
622632

633+
card->num_links = num_links;
634+
623635
return 0;
624636

625637
err_free:
@@ -1112,17 +1124,13 @@ static int macaudio_j274_fixup_controls(struct snd_soc_card *card)
11121124

11131125
struct macaudio_platform_cfg macaudio_j274_cfg = {
11141126
.fixup = macaudio_j274_fixup_controls,
1127+
.enable_speakers = true,
11151128
};
11161129

11171130
static int macaudio_j313_fixup_controls(struct snd_soc_card *card) {
11181131
struct macaudio_snd_data *ma = snd_soc_card_get_drvdata(card);
11191132

11201133
if (ma->has_speakers) {
1121-
if (!please_blow_up_my_speakers) {
1122-
dev_err(card->dev, "driver can't assure safety on this model, refusing probe\n");
1123-
return -EINVAL;
1124-
}
1125-
11261134
CHECK(snd_soc_set_enum_kctl, "* ASI1 Sel", "Left");
11271135
CHECK(snd_soc_deactivate_kctl, "* ASI1 Sel", 0);
11281136

@@ -1155,11 +1163,6 @@ static int macaudio_j314_fixup_controls(struct snd_soc_card *card)
11551163
struct macaudio_snd_data *ma = snd_soc_card_get_drvdata(card);
11561164

11571165
if (ma->has_speakers) {
1158-
if (!please_blow_up_my_speakers) {
1159-
dev_err(card->dev, "driver can't assure safety on this model, refusing probe\n");
1160-
return -EINVAL;
1161-
}
1162-
11631166
CHECK(snd_soc_set_enum_kctl, "* ASI1 Sel", "Left");
11641167
CHECK(snd_soc_deactivate_kctl, "* ASI1 Sel", 0);
11651168
CHECK(snd_soc_limit_volume, "* Amp Gain Volume", 9); // 15 set by macOS, this is 3 dB below
@@ -1223,11 +1226,6 @@ static int macaudio_j375_fixup_controls(struct snd_soc_card *card)
12231226
struct macaudio_snd_data *ma = snd_soc_card_get_drvdata(card);
12241227

12251228
if (ma->has_speakers) {
1226-
if (!please_blow_up_my_speakers) {
1227-
dev_err(card->dev, "driver can't assure safety on this model, refusing probe\n");
1228-
return -EINVAL;
1229-
}
1230-
12311229
CHECK(snd_soc_limit_volume, "* Amp Gain Volume", 14); // 20 set by macOS, this is 3 dB below
12321230

12331231
macaudio_vlimit_update(ma);
@@ -1245,11 +1243,6 @@ static int macaudio_j493_fixup_controls(struct snd_soc_card *card)
12451243
struct macaudio_snd_data *ma = snd_soc_card_get_drvdata(card);
12461244

12471245
if (ma->has_speakers) {
1248-
if (!please_blow_up_my_speakers) {
1249-
dev_err(card->dev, "driver can't assure safety on this model, refusing probe\n");
1250-
return -EINVAL;
1251-
}
1252-
12531246
CHECK(snd_soc_limit_volume, "* Amp Gain Volume", 9); // 15 set by macOS, this is 3 dB below
12541247

12551248
macaudio_vlimit_update(ma);

0 commit comments

Comments
 (0)