Skip to content

Commit 5bc7d9d

Browse files
committed
ASoC: Intel: boards: remove device properties
Some Intel machine drivers set device properties but rely on the device core to remove them. To help with future API rename or removals based on a direct use of fwnodes, follow the recommendation to remove device properties in the driver. This change was already added for SoundWire boards, but is extended to cover the case where the card registration fails (e.g. due to a bad topology or configuration). Legacy drivers are also modified in the same way. In a follow-up optimization, a generic helper could be created to avoid the copy-paste of remove_properties(). Tested with SoundWire/rt711 and Cherrytrail/rt5640 (no hardware available for the two other configurations). Suggested-by: Andy Shevchenko <andriy.shevchenko@linux.intel.com> Signed-off-by: Pierre-Louis Bossart <pierre-louis.bossart@linux.intel.com>
1 parent 33b5740 commit 5bc7d9d

File tree

5 files changed

+131
-50
lines changed

5 files changed

+131
-50
lines changed

sound/soc/intel/boards/bytcht_es8316.c

Lines changed: 22 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -462,6 +462,20 @@ static const struct dmi_system_id byt_cht_es8316_quirk_table[] = {
462462
{}
463463
};
464464

465+
static int remove_properties(struct bus_type *bus, char *codec_name)
466+
{
467+
struct device *dev;
468+
469+
dev = bus_find_device_by_name(bus, NULL, codec_name);
470+
if (!dev)
471+
return -EINVAL;
472+
473+
device_remove_properties(dev);
474+
put_device(dev);
475+
476+
return 0;
477+
}
478+
465479
static int snd_byt_cht_es8316_mc_probe(struct platform_device *pdev)
466480
{
467481
static const char * const mic_name[] = { "in1", "in2" };
@@ -575,7 +589,7 @@ static int snd_byt_cht_es8316_mc_probe(struct platform_device *pdev)
575589
dev_err(dev, "get speaker GPIO failed: %d\n", ret);
576590
/* fall through */
577591
case -EPROBE_DEFER:
578-
return ret;
592+
goto err;
579593
}
580594
}
581595

@@ -598,10 +612,14 @@ static int snd_byt_cht_es8316_mc_probe(struct platform_device *pdev)
598612
if (ret) {
599613
gpiod_put(priv->speaker_en_gpio);
600614
dev_err(dev, "snd_soc_register_card failed: %d\n", ret);
601-
return ret;
615+
goto err;
602616
}
603617
platform_set_drvdata(pdev, &byt_cht_es8316_card);
604618
return 0;
619+
620+
err:
621+
remove_properties(&i2c_bus_type, codec_name);
622+
return ret;
605623
}
606624

607625
static int snd_byt_cht_es8316_mc_remove(struct platform_device *pdev)
@@ -610,7 +628,8 @@ static int snd_byt_cht_es8316_mc_remove(struct platform_device *pdev)
610628
struct byt_cht_es8316_private *priv = snd_soc_card_get_drvdata(card);
611629

612630
gpiod_put(priv->speaker_en_gpio);
613-
return 0;
631+
632+
return remove_properties(&i2c_bus_type, codec_name);
614633
}
615634

616635
static struct platform_driver snd_byt_cht_es8316_mc_driver = {

sound/soc/intel/boards/bytcr_rt5640.c

Lines changed: 27 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1156,6 +1156,20 @@ struct acpi_chan_package { /* ACPICA seems to require 64 bit integers */
11561156
u64 mclock_value; /* usually 25MHz (0x17d7940), ignored */
11571157
};
11581158

1159+
static int remove_properties(struct bus_type *bus, char *codec_name)
1160+
{
1161+
struct device *dev;
1162+
1163+
dev = bus_find_device_by_name(bus, NULL, codec_name);
1164+
if (!dev)
1165+
return -EINVAL;
1166+
1167+
device_remove_properties(dev);
1168+
put_device(dev);
1169+
1170+
return 0;
1171+
}
1172+
11591173
static int snd_byt_rt5640_mc_probe(struct platform_device *pdev)
11601174
{
11611175
static const char * const map_name[] = { "dmic1", "dmic2", "in1", "in3" };
@@ -1300,7 +1314,7 @@ static int snd_byt_rt5640_mc_probe(struct platform_device *pdev)
13001314
* for all other errors, including -EPROBE_DEFER
13011315
*/
13021316
if (ret_val != -ENOENT)
1303-
return ret_val;
1317+
goto err;
13041318
byt_rt5640_quirk &= ~BYT_RT5640_MCLK_EN;
13051319
}
13061320
}
@@ -1325,17 +1339,26 @@ static int snd_byt_rt5640_mc_probe(struct platform_device *pdev)
13251339
ret_val = snd_soc_fixup_dai_links_platform_name(&byt_rt5640_card,
13261340
platform_name);
13271341
if (ret_val)
1328-
return ret_val;
1342+
goto err;
13291343

13301344
ret_val = devm_snd_soc_register_card(&pdev->dev, &byt_rt5640_card);
13311345

13321346
if (ret_val) {
13331347
dev_err(&pdev->dev, "devm_snd_soc_register_card failed %d\n",
13341348
ret_val);
1335-
return ret_val;
1349+
goto err;
13361350
}
13371351
platform_set_drvdata(pdev, &byt_rt5640_card);
13381352
return ret_val;
1353+
1354+
err:
1355+
remove_properties(&i2c_bus_type, byt_rt5640_codec_name);
1356+
return ret_val;
1357+
}
1358+
1359+
static int snd_byt_rt5640_mc_remove(struct platform_device *pdev)
1360+
{
1361+
return remove_properties(&i2c_bus_type, byt_rt5640_codec_name);
13391362
}
13401363

13411364
static struct platform_driver snd_byt_rt5640_mc_driver = {
@@ -1346,6 +1369,7 @@ static struct platform_driver snd_byt_rt5640_mc_driver = {
13461369
#endif
13471370
},
13481371
.probe = snd_byt_rt5640_mc_probe,
1372+
.remove = snd_byt_rt5640_mc_remove
13491373
};
13501374

13511375
module_platform_driver(snd_byt_rt5640_mc_driver);

sound/soc/intel/boards/bytcr_rt5651.c

Lines changed: 29 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -868,6 +868,20 @@ struct acpi_chan_package { /* ACPICA seems to require 64 bit integers */
868868
u64 mclock_value; /* usually 25MHz (0x17d7940), ignored */
869869
};
870870

871+
static int remove_properties(struct bus_type *bus, char *codec_name)
872+
{
873+
struct device *dev;
874+
875+
dev = bus_find_device_by_name(bus, NULL, codec_name);
876+
if (!dev)
877+
return -EINVAL;
878+
879+
device_remove_properties(dev);
880+
put_device(dev);
881+
882+
return 0;
883+
}
884+
871885
static int snd_byt_rt5651_mc_probe(struct platform_device *pdev)
872886
{
873887
static const char * const mic_name[] = { "dmic", "in1", "in2", "in12" };
@@ -1012,7 +1026,7 @@ static int snd_byt_rt5651_mc_probe(struct platform_device *pdev)
10121026
/* fall through */
10131027
case -EPROBE_DEFER:
10141028
put_device(codec_dev);
1015-
return ret_val;
1029+
goto err;
10161030
}
10171031
}
10181032
priv->hp_detect = devm_fwnode_gpiod_get(&pdev->dev,
@@ -1032,7 +1046,7 @@ static int snd_byt_rt5651_mc_probe(struct platform_device *pdev)
10321046
/* fall through */
10331047
case -EPROBE_DEFER:
10341048
put_device(codec_dev);
1035-
return ret_val;
1049+
goto err;
10361050
}
10371051
}
10381052
}
@@ -1062,7 +1076,7 @@ static int snd_byt_rt5651_mc_probe(struct platform_device *pdev)
10621076
* for all other errors, including -EPROBE_DEFER
10631077
*/
10641078
if (ret_val != -ENOENT)
1065-
return ret_val;
1079+
goto err;
10661080
byt_rt5651_quirk &= ~BYT_RT5651_MCLK_EN;
10671081
}
10681082
}
@@ -1091,17 +1105,26 @@ static int snd_byt_rt5651_mc_probe(struct platform_device *pdev)
10911105
ret_val = snd_soc_fixup_dai_links_platform_name(&byt_rt5651_card,
10921106
platform_name);
10931107
if (ret_val)
1094-
return ret_val;
1108+
goto err;
10951109

10961110
ret_val = devm_snd_soc_register_card(&pdev->dev, &byt_rt5651_card);
10971111

10981112
if (ret_val) {
10991113
dev_err(&pdev->dev, "devm_snd_soc_register_card failed %d\n",
11001114
ret_val);
1101-
return ret_val;
1115+
goto err;
11021116
}
11031117
platform_set_drvdata(pdev, &byt_rt5651_card);
11041118
return ret_val;
1119+
1120+
err:
1121+
remove_properties(&i2c_bus_type, byt_rt5651_codec_name);
1122+
return ret_val;
1123+
}
1124+
1125+
static int snd_byt_rt5651_mc_remove(struct platform_device *pdev)
1126+
{
1127+
return remove_properties(&i2c_bus_type, byt_rt5651_codec_name);
11051128
}
11061129

11071130
static struct platform_driver snd_byt_rt5651_mc_driver = {
@@ -1112,6 +1135,7 @@ static struct platform_driver snd_byt_rt5651_mc_driver = {
11121135
#endif
11131136
},
11141137
.probe = snd_byt_rt5651_mc_probe,
1138+
.remove = snd_byt_rt5651_mc_remove,
11151139
};
11161140

11171141
module_platform_driver(snd_byt_rt5651_mc_driver);

sound/soc/intel/boards/sof_sdw.c

Lines changed: 38 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -945,6 +945,34 @@ static int sof_card_dai_links_create(struct device *dev,
945945
return 0;
946946
}
947947

948+
static int sof_card_dai_links_exit(struct device *dev, struct snd_soc_card *card)
949+
{
950+
struct snd_soc_dai_link *link;
951+
int ret;
952+
int i, j;
953+
954+
for (i = 0; i < ARRAY_SIZE(codec_info_list); i++) {
955+
if (!codec_info_list[i].exit)
956+
continue;
957+
/*
958+
* We don't need to call .exit function if there is no matched
959+
* dai link found.
960+
*/
961+
for_each_card_prelinks(card, j, link) {
962+
if (!strcmp(link->codecs[0].dai_name,
963+
codec_info_list[i].dai_name)) {
964+
ret = codec_info_list[i].exit(dev, link);
965+
if (ret)
966+
dev_warn(dev, "dai_name %s codec exit failed %d\n",
967+
codec_info_list[i].dai_name, ret);
968+
break;
969+
}
970+
}
971+
}
972+
973+
return 0;
974+
}
975+
948976
static int sof_sdw_card_late_probe(struct snd_soc_card *card)
949977
{
950978
int i, ret;
@@ -1020,51 +1048,33 @@ static int mc_probe(struct platform_device *pdev)
10201048
"cfg-spk:%d cfg-amp:%d",
10211049
(sof_sdw_quirk & SOF_SDW_FOUR_SPK)
10221050
? 4 : 2, amp_num);
1023-
if (!card->components)
1024-
return -ENOMEM;
1025-
1051+
if (!card->components) {
1052+
ret = -ENOMEM;
1053+
goto err;
1054+
}
10261055
card->long_name = sdw_card_long_name;
10271056

10281057
/* Register the card */
10291058
ret = devm_snd_soc_register_card(&pdev->dev, card);
10301059
if (ret) {
10311060
dev_err(card->dev, "snd_soc_register_card failed %d\n", ret);
1032-
return ret;
1061+
goto err;
10331062
}
10341063

10351064
platform_set_drvdata(pdev, card);
10361065

10371066
return ret;
1067+
1068+
err:
1069+
sof_card_dai_links_exit(&pdev->dev, card);
1070+
return ret;
10381071
}
10391072

10401073
static int mc_remove(struct platform_device *pdev)
10411074
{
10421075
struct snd_soc_card *card = platform_get_drvdata(pdev);
1043-
struct snd_soc_dai_link *link;
1044-
int ret;
1045-
int i, j;
10461076

1047-
for (i = 0; i < ARRAY_SIZE(codec_info_list); i++) {
1048-
if (!codec_info_list[i].exit)
1049-
continue;
1050-
/*
1051-
* We don't need to call .exit function if there is no matched
1052-
* dai link found.
1053-
*/
1054-
for_each_card_prelinks(card, j, link) {
1055-
if (!strcmp(link->codecs[0].dai_name,
1056-
codec_info_list[i].dai_name)) {
1057-
ret = codec_info_list[i].exit(&pdev->dev, link);
1058-
if (ret)
1059-
dev_warn(&pdev->dev,
1060-
"codec exit failed %d\n",
1061-
ret);
1062-
break;
1063-
}
1064-
}
1065-
}
1066-
1067-
return 0;
1077+
return sof_card_dai_links_exit(&pdev->dev, card);
10681078
}
10691079

10701080
static struct platform_driver sof_sdw_driver = {

sound/soc/intel/boards/sof_sdw_rt711.c

Lines changed: 15 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,20 @@ static int rt711_add_codec_device_props(const char *sdw_dev_name)
4040
return ret;
4141
}
4242

43+
static int remove_properties(struct bus_type *bus, const char *codec_name)
44+
{
45+
struct device *dev;
46+
47+
dev = bus_find_device_by_name(bus, NULL, codec_name);
48+
if (!dev)
49+
return -EINVAL;
50+
51+
device_remove_properties(dev);
52+
put_device(dev);
53+
54+
return 0;
55+
}
56+
4357
static const struct snd_soc_dapm_widget rt711_widgets[] = {
4458
SND_SOC_DAPM_HP("Headphone", NULL),
4559
SND_SOC_DAPM_MIC("Headset Mic", NULL),
@@ -135,17 +149,7 @@ static int rt711_rtd_init(struct snd_soc_pcm_runtime *rtd)
135149

136150
int sof_sdw_rt711_exit(struct device *dev, struct snd_soc_dai_link *dai_link)
137151
{
138-
struct device *sdw_dev;
139-
140-
sdw_dev = bus_find_device_by_name(&sdw_bus_type, NULL,
141-
dai_link->codecs[0].name);
142-
if (!sdw_dev)
143-
return -EINVAL;
144-
145-
device_remove_properties(sdw_dev);
146-
put_device(sdw_dev);
147-
148-
return 0;
152+
return remove_properties(&sdw_bus_type, dai_link->codecs[0].name);
149153
}
150154

151155
int sof_sdw_rt711_init(const struct snd_soc_acpi_link_adr *link,

0 commit comments

Comments
 (0)