Skip to content

Commit 85a9234

Browse files
plbossartbardliao
authored andcommitted
ASoC: rt712-sdca: detect the SMART_MIC function during the probe stage
We shouldn't do any devm_ based allocation in the io_init(), this need to happen in the probe(). Luckily, we now have an SDCA helper to look in ACPI tables if a SMART_MIC function is exposed. FIXME: the registers are not well handled today, the regmap lists registers which are not really supported in all platforms. The regmap needs to throw an error if those registers are accessed without existing. Signed-off-by: Pierre-Louis Bossart <pierre-louis.bossart@linux.intel.com>
1 parent 40c8372 commit 85a9234

3 files changed

Lines changed: 31 additions & 9 deletions

File tree

sound/soc/codecs/rt712-sdca-sdw.c

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -507,3 +507,4 @@ module_sdw_driver(rt712_sdca_sdw_driver);
507507
MODULE_DESCRIPTION("ASoC RT712 SDCA SDW driver");
508508
MODULE_AUTHOR("Shuming Fan <shumingf@realtek.com>");
509509
MODULE_LICENSE("GPL");
510+
MODULE_IMPORT_NS(SND_SOC_SDCA);

sound/soc/codecs/rt712-sdca.c

Lines changed: 29 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@
1818
#include <linux/pm_runtime.h>
1919
#include <sound/pcm.h>
2020
#include <sound/pcm_params.h>
21+
#include <sound/sdca.h>
2122
#include <linux/soundwire/sdw_registers.h>
2223
#include <linux/slab.h>
2324
#include <sound/soc-dapm.h>
@@ -1652,6 +1653,17 @@ int rt712_sdca_init(struct device *dev, struct regmap *regmap,
16521653
if (ret < 0)
16531654
return ret;
16541655

1656+
/* only add the dmic component if a SMART_MIC function is exposed in ACPI */
1657+
if (sdca_device_quirk_match(slave, SDCA_QUIRKS_RT712_VB)) {
1658+
ret = devm_snd_soc_register_component(dev,
1659+
&soc_sdca_dev_rt712_dmic,
1660+
rt712_sdca_dmic_dai,
1661+
ARRAY_SIZE(rt712_sdca_dmic_dai));
1662+
if (ret < 0)
1663+
return ret;
1664+
rt712->dmic_function_found = true;
1665+
}
1666+
16551667
/* set autosuspend parameters */
16561668
pm_runtime_set_autosuspend_delay(dev, 3000);
16571669
pm_runtime_use_autosuspend(dev);
@@ -1799,7 +1811,6 @@ static void rt712_sdca_vb_io_init(struct rt712_sdca_priv *rt712)
17991811
int rt712_sdca_io_init(struct device *dev, struct sdw_slave *slave)
18001812
{
18011813
struct rt712_sdca_priv *rt712 = dev_get_drvdata(dev);
1802-
int ret = 0;
18031814
unsigned int val;
18041815
struct sdw_slave_prop *prop = &slave->prop;
18051816

@@ -1829,15 +1840,22 @@ int rt712_sdca_io_init(struct device *dev, struct sdw_slave *slave)
18291840
rt712->version_id = (val & 0x0f00) >> 8;
18301841
dev_dbg(&slave->dev, "%s hw_id=0x%x, version_id=0x%x\n", __func__, rt712->hw_id, rt712->version_id);
18311842

1832-
if (rt712->version_id == RT712_VA)
1843+
if (rt712->version_id == RT712_VA) {
1844+
if (rt712->dmic_function_found) {
1845+
dev_err(&slave->dev, "%s RT712 VA detected but SMART_MIC function exposed in ACPI\n",
1846+
__func__);
1847+
goto suspend;
1848+
}
1849+
18331850
rt712_sdca_va_io_init(rt712);
1834-
else {
1835-
/* multilanes and DMIC are supported by rt712vb */
1836-
ret = devm_snd_soc_register_component(dev,
1837-
&soc_sdca_dev_rt712_dmic, rt712_sdca_dmic_dai, ARRAY_SIZE(rt712_sdca_dmic_dai));
1838-
if (ret < 0)
1839-
return ret;
1851+
} else {
1852+
if (!rt712->dmic_function_found) {
1853+
dev_err(&slave->dev, "%s RT712 VB detected but no SMART_MIC function exposed in ACPI\n",
1854+
__func__);
1855+
goto suspend;
1856+
}
18401857

1858+
/* multilanes and DMIC are supported by rt712vb */
18411859
prop->lane_control_support = true;
18421860
rt712_sdca_vb_io_init(rt712);
18431861
}
@@ -1862,10 +1880,12 @@ int rt712_sdca_io_init(struct device *dev, struct sdw_slave *slave)
18621880
/* Mark Slave initialization complete */
18631881
rt712->hw_init = true;
18641882

1883+
dev_dbg(&slave->dev, "%s hw_init complete\n", __func__);
1884+
1885+
suspend:
18651886
pm_runtime_mark_last_busy(&slave->dev);
18661887
pm_runtime_put_autosuspend(&slave->dev);
18671888

1868-
dev_dbg(&slave->dev, "%s hw_init complete\n", __func__);
18691889
return 0;
18701890
}
18711891

sound/soc/codecs/rt712-sdca.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,7 @@ struct rt712_sdca_priv {
3636
unsigned int scp_sdca_stat2;
3737
unsigned int hw_id;
3838
unsigned int version_id;
39+
bool dmic_function_found;
3940
bool fu0f_dapm_mute;
4041
bool fu0f_mixer_l_mute;
4142
bool fu0f_mixer_r_mute;

0 commit comments

Comments
 (0)