@@ -1413,6 +1413,16 @@ static int soc_probe_component(struct snd_soc_card *card,
1413
1413
component -> name );
1414
1414
}
1415
1415
1416
+ /* machine specific init */
1417
+ if (component -> init ) {
1418
+ ret = component -> init (component );
1419
+ if (ret < 0 ) {
1420
+ dev_err (component -> dev ,
1421
+ "Failed to do machine specific init %d\n" , ret );
1422
+ goto err_probe ;
1423
+ }
1424
+ }
1425
+
1416
1426
if (component -> controls )
1417
1427
snd_soc_add_component_controls (component , component -> controls ,
1418
1428
component -> num_controls );
@@ -1657,65 +1667,81 @@ static int soc_probe_link_dais(struct snd_soc_card *card,
1657
1667
1658
1668
static int soc_bind_aux_dev (struct snd_soc_card * card , int num )
1659
1669
{
1660
- struct snd_soc_pcm_runtime * rtd = & card -> rtd_aux [num ];
1661
1670
struct snd_soc_aux_dev * aux_dev = & card -> aux_dev [num ];
1662
- const char * name = aux_dev -> codec_name ;
1663
-
1664
- rtd -> component = soc_find_component (aux_dev -> codec_of_node , name );
1665
- if (!rtd -> component ) {
1666
- if (aux_dev -> codec_of_node )
1667
- name = of_node_full_name (aux_dev -> codec_of_node );
1668
-
1669
- dev_err (card -> dev , "ASoC: %s not registered\n" , name );
1670
- return - EPROBE_DEFER ;
1671
+ struct snd_soc_component * component ;
1672
+ const char * name ;
1673
+ struct device_node * codec_of_node ;
1674
+
1675
+ if (aux_dev -> codec_of_node || aux_dev -> codec_name ) {
1676
+ /* codecs, usually analog devices */
1677
+ name = aux_dev -> codec_name ;
1678
+ codec_of_node = aux_dev -> codec_of_node ;
1679
+ component = soc_find_component (codec_of_node , name );
1680
+ if (!component ) {
1681
+ if (codec_of_node )
1682
+ name = of_node_full_name (codec_of_node );
1683
+ goto err_defer ;
1684
+ }
1685
+ } else if (aux_dev -> name ) {
1686
+ /* generic components */
1687
+ name = aux_dev -> name ;
1688
+ component = soc_find_component (NULL , name );
1689
+ if (!component )
1690
+ goto err_defer ;
1691
+ } else {
1692
+ dev_err (card -> dev , "ASoC: Invalid auxiliary device\n" );
1693
+ return - EINVAL ;
1671
1694
}
1672
1695
1673
- /*
1674
- * Some places still reference rtd->codec, so we have to keep that
1675
- * initialized if the component is a CODEC. Once all those references
1676
- * have been removed, this code can be removed as well.
1677
- */
1678
- rtd -> codec = rtd -> component -> codec ;
1679
-
1696
+ component -> init = aux_dev -> init ;
1697
+ list_add (& component -> list_aux , & card -> aux_comp_list );
1680
1698
return 0 ;
1699
+
1700
+ err_defer :
1701
+ dev_err (card -> dev , "ASoC: %s not registered\n" , name );
1702
+ return - EPROBE_DEFER ;
1681
1703
}
1682
1704
1683
- static int soc_probe_aux_dev (struct snd_soc_card * card , int num )
1705
+ static int soc_probe_aux_devices (struct snd_soc_card * card )
1684
1706
{
1685
- struct snd_soc_pcm_runtime * rtd = & card -> rtd_aux [ num ] ;
1686
- struct snd_soc_aux_dev * aux_dev = & card -> aux_dev [ num ] ;
1707
+ struct snd_soc_component * comp ;
1708
+ int order ;
1687
1709
int ret ;
1688
1710
1689
- ret = soc_probe_component (card , rtd -> component );
1690
- if (ret < 0 )
1691
- return ret ;
1692
-
1693
- /* do machine specific initialization */
1694
- if (aux_dev -> init ) {
1695
- ret = aux_dev -> init (rtd -> component );
1696
- if (ret < 0 ) {
1697
- dev_err (card -> dev , "ASoC: failed to init %s: %d\n" ,
1698
- aux_dev -> name , ret );
1699
- return ret ;
1711
+ for (order = SND_SOC_COMP_ORDER_FIRST ; order <= SND_SOC_COMP_ORDER_LAST ;
1712
+ order ++ ) {
1713
+ list_for_each_entry (comp , & card -> aux_comp_list , list_aux ) {
1714
+ if (comp -> driver -> probe_order == order ) {
1715
+ ret = soc_probe_component (card , comp );
1716
+ if (ret < 0 ) {
1717
+ dev_err (card -> dev ,
1718
+ "ASoC: failed to probe aux component %s %d\n" ,
1719
+ comp -> name , ret );
1720
+ return ret ;
1721
+ }
1722
+ }
1700
1723
}
1701
1724
}
1702
1725
1703
- return soc_post_component_init ( rtd , aux_dev -> name ) ;
1726
+ return 0 ;
1704
1727
}
1705
1728
1706
- static void soc_remove_aux_dev (struct snd_soc_card * card , int num )
1729
+ static void soc_remove_aux_devices (struct snd_soc_card * card )
1707
1730
{
1708
- struct snd_soc_pcm_runtime * rtd = & card -> rtd_aux [ num ] ;
1709
- struct snd_soc_component * component = rtd -> component ;
1731
+ struct snd_soc_component * comp , * _comp ;
1732
+ int order ;
1710
1733
1711
- /* unregister the rtd device */
1712
- if (rtd -> dev_registered ) {
1713
- device_unregister (rtd -> dev );
1714
- rtd -> dev_registered = 0 ;
1734
+ for (order = SND_SOC_COMP_ORDER_FIRST ; order <= SND_SOC_COMP_ORDER_LAST ;
1735
+ order ++ ) {
1736
+ list_for_each_entry_safe (comp , _comp ,
1737
+ & card -> aux_comp_list , list_aux ) {
1738
+ if (comp -> driver -> remove_order == order ) {
1739
+ soc_remove_component (comp );
1740
+ /* remove it from the card's aux_comp_list */
1741
+ list_del (& comp -> list_aux );
1742
+ }
1743
+ }
1715
1744
}
1716
-
1717
- if (component )
1718
- soc_remove_component (component );
1719
1745
}
1720
1746
1721
1747
static int snd_soc_init_codec_cache (struct snd_soc_codec * codec )
@@ -1894,6 +1920,11 @@ static int snd_soc_instantiate_card(struct snd_soc_card *card)
1894
1920
}
1895
1921
}
1896
1922
1923
+ /* probe auxiliary components */
1924
+ ret = soc_probe_aux_devices (card );
1925
+ if (ret < 0 )
1926
+ goto probe_dai_err ;
1927
+
1897
1928
/* Find new DAI links added during probing components and bind them.
1898
1929
* Components with topology may bring new DAIs and DAI links.
1899
1930
*/
@@ -1923,16 +1954,6 @@ static int snd_soc_instantiate_card(struct snd_soc_card *card)
1923
1954
}
1924
1955
}
1925
1956
1926
- for (i = 0 ; i < card -> num_aux_devs ; i ++ ) {
1927
- ret = soc_probe_aux_dev (card , i );
1928
- if (ret < 0 ) {
1929
- dev_err (card -> dev ,
1930
- "ASoC: failed to add auxiliary devices %d\n" ,
1931
- ret );
1932
- goto probe_aux_dev_err ;
1933
- }
1934
- }
1935
-
1936
1957
snd_soc_dapm_link_dai_widgets (card );
1937
1958
snd_soc_dapm_connect_dai_link_widgets (card );
1938
1959
@@ -1992,8 +2013,7 @@ static int snd_soc_instantiate_card(struct snd_soc_card *card)
1992
2013
return 0 ;
1993
2014
1994
2015
probe_aux_dev_err :
1995
- for (i = 0 ; i < card -> num_aux_devs ; i ++ )
1996
- soc_remove_aux_dev (card , i );
2016
+ soc_remove_aux_devices (card );
1997
2017
1998
2018
probe_dai_err :
1999
2019
soc_remove_dai_links (card );
@@ -2039,20 +2059,18 @@ static int soc_probe(struct platform_device *pdev)
2039
2059
static int soc_cleanup_card_resources (struct snd_soc_card * card )
2040
2060
{
2041
2061
struct snd_soc_pcm_runtime * rtd ;
2042
- int i ;
2043
2062
2044
2063
/* make sure any delayed work runs */
2045
2064
list_for_each_entry (rtd , & card -> rtd_list , list )
2046
2065
flush_delayed_work (& rtd -> delayed_work );
2047
2066
2048
- /* remove auxiliary devices */
2049
- for (i = 0 ; i < card -> num_aux_devs ; i ++ )
2050
- soc_remove_aux_dev (card , i );
2051
-
2052
2067
/* remove and free each DAI */
2053
2068
soc_remove_dai_links (card );
2054
2069
soc_remove_pcm_runtimes (card );
2055
2070
2071
+ /* remove auxiliary devices */
2072
+ soc_remove_aux_devices (card );
2073
+
2056
2074
soc_cleanup_card_debugfs (card );
2057
2075
2058
2076
/* remove the card */
@@ -2608,16 +2626,6 @@ int snd_soc_register_card(struct snd_soc_card *card)
2608
2626
INIT_LIST_HEAD (& card -> rtd_list );
2609
2627
card -> num_rtd = 0 ;
2610
2628
2611
- card -> rtd_aux = devm_kzalloc (card -> dev ,
2612
- sizeof (struct snd_soc_pcm_runtime ) *
2613
- card -> num_aux_devs ,
2614
- GFP_KERNEL );
2615
- if (card -> rtd_aux == NULL )
2616
- return - ENOMEM ;
2617
-
2618
- for (i = 0 ; i < card -> num_aux_devs ; i ++ )
2619
- card -> rtd_aux [i ].card = card ;
2620
-
2621
2629
INIT_LIST_HEAD (& card -> dapm_dirty );
2622
2630
INIT_LIST_HEAD (& card -> dobj_list );
2623
2631
card -> instantiated = 0 ;
0 commit comments