summaryrefslogtreecommitdiffstats
path: root/sound
diff options
context:
space:
mode:
authorTakashi Iwai <tiwai@suse.de>2016-05-10 10:06:04 -0400
committerTakashi Iwai <tiwai@suse.de>2016-05-10 10:06:04 -0400
commit2e00fde5c6ed8535244332ebb55e881baa54ae46 (patch)
treef578e02ef1dc6e59630f09404bb2f58500876811 /sound
parent39f0ccde3624e7cf882faccf7f72a47b7a763bfb (diff)
parent3231e2053eaeee70bdfb216a78a30f11e88e2243 (diff)
Merge branch 'for-linus' into for-next
Diffstat (limited to 'sound')
-rw-r--r--sound/hda/ext/hdac_ext_stream.c5
-rw-r--r--sound/pci/hda/hda_sysfs.c8
-rw-r--r--sound/pci/hda/patch_realtek.c13
-rw-r--r--sound/soc/codecs/Kconfig1
-rw-r--r--sound/soc/codecs/arizona.c12
-rw-r--r--sound/soc/codecs/arizona.h2
-rw-r--r--sound/soc/codecs/cs35l32.c17
-rw-r--r--sound/soc/codecs/cs47l24.c3
-rw-r--r--sound/soc/codecs/hdac_hdmi.c94
-rw-r--r--sound/soc/codecs/nau8825.c126
-rw-r--r--sound/soc/codecs/rt5640.c2
-rw-r--r--sound/soc/codecs/rt5640.h36
-rw-r--r--sound/soc/codecs/wm5102.c5
-rw-r--r--sound/soc/codecs/wm5110.c2
-rw-r--r--sound/soc/codecs/wm8962.c2
-rw-r--r--sound/soc/codecs/wm8997.c2
-rw-r--r--sound/soc/codecs/wm8998.c2
-rw-r--r--sound/soc/intel/Kconfig1
-rw-r--r--sound/soc/intel/haswell/sst-haswell-ipc.c2
-rw-r--r--sound/soc/intel/skylake/skl-sst-dsp.c5
-rw-r--r--sound/soc/intel/skylake/skl-topology.c42
-rw-r--r--sound/soc/intel/skylake/skl-topology.h8
-rw-r--r--sound/soc/intel/skylake/skl.c32
-rw-r--r--sound/soc/soc-dapm.c7
-rw-r--r--sound/usb/Kconfig4
-rw-r--r--sound/usb/Makefile2
-rw-r--r--sound/usb/card.c14
-rw-r--r--sound/usb/card.h3
-rw-r--r--sound/usb/media.c318
-rw-r--r--sound/usb/media.h72
-rw-r--r--sound/usb/mixer.h3
-rw-r--r--sound/usb/pcm.c28
-rw-r--r--sound/usb/quirks-table.h1
-rw-r--r--sound/usb/quirks.c2
-rw-r--r--sound/usb/stream.c2
-rw-r--r--sound/usb/usbaudio.h6
36 files changed, 265 insertions, 619 deletions
diff --git a/sound/hda/ext/hdac_ext_stream.c b/sound/hda/ext/hdac_ext_stream.c
index 023cc4cad5c1..626f3bb24c55 100644
--- a/sound/hda/ext/hdac_ext_stream.c
+++ b/sound/hda/ext/hdac_ext_stream.c
@@ -104,12 +104,11 @@ EXPORT_SYMBOL_GPL(snd_hdac_ext_stream_init_all);
104 */ 104 */
105void snd_hdac_stream_free_all(struct hdac_ext_bus *ebus) 105void snd_hdac_stream_free_all(struct hdac_ext_bus *ebus)
106{ 106{
107 struct hdac_stream *s; 107 struct hdac_stream *s, *_s;
108 struct hdac_ext_stream *stream; 108 struct hdac_ext_stream *stream;
109 struct hdac_bus *bus = ebus_to_hbus(ebus); 109 struct hdac_bus *bus = ebus_to_hbus(ebus);
110 110
111 while (!list_empty(&bus->stream_list)) { 111 list_for_each_entry_safe(s, _s, &bus->stream_list, list) {
112 s = list_first_entry(&bus->stream_list, struct hdac_stream, list);
113 stream = stream_to_hdac_ext_stream(s); 112 stream = stream_to_hdac_ext_stream(s);
114 snd_hdac_ext_stream_decouple(ebus, stream, false); 113 snd_hdac_ext_stream_decouple(ebus, stream, false);
115 list_del(&s->list); 114 list_del(&s->list);
diff --git a/sound/pci/hda/hda_sysfs.c b/sound/pci/hda/hda_sysfs.c
index 64e0d1d81ca5..9739fce9e032 100644
--- a/sound/pci/hda/hda_sysfs.c
+++ b/sound/pci/hda/hda_sysfs.c
@@ -141,14 +141,6 @@ static int reconfig_codec(struct hda_codec *codec)
141 err = snd_hda_codec_configure(codec); 141 err = snd_hda_codec_configure(codec);
142 if (err < 0) 142 if (err < 0)
143 goto error; 143 goto error;
144 /* rebuild PCMs */
145 err = snd_hda_codec_build_pcms(codec);
146 if (err < 0)
147 goto error;
148 /* rebuild mixers */
149 err = snd_hda_codec_build_controls(codec);
150 if (err < 0)
151 goto error;
152 err = snd_card_register(codec->card); 144 err = snd_card_register(codec->card);
153 error: 145 error:
154 snd_hda_power_down(codec); 146 snd_hda_power_down(codec);
diff --git a/sound/pci/hda/patch_realtek.c b/sound/pci/hda/patch_realtek.c
index a2fdf5f91d43..002f153bc659 100644
--- a/sound/pci/hda/patch_realtek.c
+++ b/sound/pci/hda/patch_realtek.c
@@ -6438,6 +6438,7 @@ enum {
6438 ALC668_FIXUP_DELL_DISABLE_AAMIX, 6438 ALC668_FIXUP_DELL_DISABLE_AAMIX,
6439 ALC668_FIXUP_DELL_XPS13, 6439 ALC668_FIXUP_DELL_XPS13,
6440 ALC662_FIXUP_ASUS_Nx50, 6440 ALC662_FIXUP_ASUS_Nx50,
6441 ALC668_FIXUP_ASUS_Nx51,
6441}; 6442};
6442 6443
6443static const struct hda_fixup alc662_fixups[] = { 6444static const struct hda_fixup alc662_fixups[] = {
@@ -6684,6 +6685,15 @@ static const struct hda_fixup alc662_fixups[] = {
6684 .chained = true, 6685 .chained = true,
6685 .chain_id = ALC662_FIXUP_BASS_1A 6686 .chain_id = ALC662_FIXUP_BASS_1A
6686 }, 6687 },
6688 [ALC668_FIXUP_ASUS_Nx51] = {
6689 .type = HDA_FIXUP_PINS,
6690 .v.pins = (const struct hda_pintbl[]) {
6691 {0x1a, 0x90170151}, /* bass speaker */
6692 {}
6693 },
6694 .chained = true,
6695 .chain_id = ALC662_FIXUP_BASS_CHMAP,
6696 },
6687}; 6697};
6688 6698
6689static const struct snd_pci_quirk alc662_fixup_tbl[] = { 6699static const struct snd_pci_quirk alc662_fixup_tbl[] = {
@@ -6706,11 +6716,14 @@ static const struct snd_pci_quirk alc662_fixup_tbl[] = {
6706 SND_PCI_QUIRK(0x1028, 0x0698, "Dell", ALC668_FIXUP_DELL_MIC_NO_PRESENCE), 6716 SND_PCI_QUIRK(0x1028, 0x0698, "Dell", ALC668_FIXUP_DELL_MIC_NO_PRESENCE),
6707 SND_PCI_QUIRK(0x1028, 0x069f, "Dell", ALC668_FIXUP_DELL_MIC_NO_PRESENCE), 6717 SND_PCI_QUIRK(0x1028, 0x069f, "Dell", ALC668_FIXUP_DELL_MIC_NO_PRESENCE),
6708 SND_PCI_QUIRK(0x103c, 0x1632, "HP RP5800", ALC662_FIXUP_HP_RP5800), 6718 SND_PCI_QUIRK(0x103c, 0x1632, "HP RP5800", ALC662_FIXUP_HP_RP5800),
6719 SND_PCI_QUIRK(0x1043, 0x1080, "Asus UX501VW", ALC668_FIXUP_HEADSET_MODE),
6709 SND_PCI_QUIRK(0x1043, 0x11cd, "Asus N550", ALC662_FIXUP_ASUS_Nx50), 6720 SND_PCI_QUIRK(0x1043, 0x11cd, "Asus N550", ALC662_FIXUP_ASUS_Nx50),
6710 SND_PCI_QUIRK(0x1043, 0x13df, "Asus N550JX", ALC662_FIXUP_BASS_1A), 6721 SND_PCI_QUIRK(0x1043, 0x13df, "Asus N550JX", ALC662_FIXUP_BASS_1A),
6711 SND_PCI_QUIRK(0x1043, 0x129d, "Asus N750", ALC662_FIXUP_ASUS_Nx50), 6722 SND_PCI_QUIRK(0x1043, 0x129d, "Asus N750", ALC662_FIXUP_ASUS_Nx50),
6712 SND_PCI_QUIRK(0x1043, 0x1477, "ASUS N56VZ", ALC662_FIXUP_BASS_MODE4_CHMAP), 6723 SND_PCI_QUIRK(0x1043, 0x1477, "ASUS N56VZ", ALC662_FIXUP_BASS_MODE4_CHMAP),
6713 SND_PCI_QUIRK(0x1043, 0x15a7, "ASUS UX51VZH", ALC662_FIXUP_BASS_16), 6724 SND_PCI_QUIRK(0x1043, 0x15a7, "ASUS UX51VZH", ALC662_FIXUP_BASS_16),
6725 SND_PCI_QUIRK(0x1043, 0x177d, "ASUS N551", ALC668_FIXUP_ASUS_Nx51),
6726 SND_PCI_QUIRK(0x1043, 0x17bd, "ASUS N751", ALC668_FIXUP_ASUS_Nx51),
6714 SND_PCI_QUIRK(0x1043, 0x1b73, "ASUS N55SF", ALC662_FIXUP_BASS_16), 6727 SND_PCI_QUIRK(0x1043, 0x1b73, "ASUS N55SF", ALC662_FIXUP_BASS_16),
6715 SND_PCI_QUIRK(0x1043, 0x1bf3, "ASUS N76VZ", ALC662_FIXUP_BASS_MODE4_CHMAP), 6728 SND_PCI_QUIRK(0x1043, 0x1bf3, "ASUS N76VZ", ALC662_FIXUP_BASS_MODE4_CHMAP),
6716 SND_PCI_QUIRK(0x1043, 0x8469, "ASUS mobo", ALC662_FIXUP_NO_JACK_DETECT), 6729 SND_PCI_QUIRK(0x1043, 0x8469, "ASUS mobo", ALC662_FIXUP_NO_JACK_DETECT),
diff --git a/sound/soc/codecs/Kconfig b/sound/soc/codecs/Kconfig
index 649e92a252ae..7ef3a0c16478 100644
--- a/sound/soc/codecs/Kconfig
+++ b/sound/soc/codecs/Kconfig
@@ -629,6 +629,7 @@ config SND_SOC_RT5514
629 629
630config SND_SOC_RT5616 630config SND_SOC_RT5616
631 tristate "Realtek RT5616 CODEC" 631 tristate "Realtek RT5616 CODEC"
632 depends on I2C
632 633
633config SND_SOC_RT5631 634config SND_SOC_RT5631
634 tristate "Realtek ALC5631/RT5631 CODEC" 635 tristate "Realtek ALC5631/RT5631 CODEC"
diff --git a/sound/soc/codecs/arizona.c b/sound/soc/codecs/arizona.c
index 92d22a018d68..83959312f7a0 100644
--- a/sound/soc/codecs/arizona.c
+++ b/sound/soc/codecs/arizona.c
@@ -249,6 +249,18 @@ int arizona_init_spk(struct snd_soc_codec *codec)
249} 249}
250EXPORT_SYMBOL_GPL(arizona_init_spk); 250EXPORT_SYMBOL_GPL(arizona_init_spk);
251 251
252int arizona_free_spk(struct snd_soc_codec *codec)
253{
254 struct arizona_priv *priv = snd_soc_codec_get_drvdata(codec);
255 struct arizona *arizona = priv->arizona;
256
257 arizona_free_irq(arizona, ARIZONA_IRQ_SPK_OVERHEAT_WARN, arizona);
258 arizona_free_irq(arizona, ARIZONA_IRQ_SPK_OVERHEAT, arizona);
259
260 return 0;
261}
262EXPORT_SYMBOL_GPL(arizona_free_spk);
263
252static const struct snd_soc_dapm_route arizona_mono_routes[] = { 264static const struct snd_soc_dapm_route arizona_mono_routes[] = {
253 { "OUT1R", NULL, "OUT1L" }, 265 { "OUT1R", NULL, "OUT1L" },
254 { "OUT2R", NULL, "OUT2L" }, 266 { "OUT2R", NULL, "OUT2L" },
diff --git a/sound/soc/codecs/arizona.h b/sound/soc/codecs/arizona.h
index 1ea8e4ecf8d4..ce0531b8c632 100644
--- a/sound/soc/codecs/arizona.h
+++ b/sound/soc/codecs/arizona.h
@@ -307,6 +307,8 @@ extern int arizona_init_spk(struct snd_soc_codec *codec);
307extern int arizona_init_gpio(struct snd_soc_codec *codec); 307extern int arizona_init_gpio(struct snd_soc_codec *codec);
308extern int arizona_init_mono(struct snd_soc_codec *codec); 308extern int arizona_init_mono(struct snd_soc_codec *codec);
309 309
310extern int arizona_free_spk(struct snd_soc_codec *codec);
311
310extern int arizona_init_dai(struct arizona_priv *priv, int dai); 312extern int arizona_init_dai(struct arizona_priv *priv, int dai);
311 313
312int arizona_set_output_mode(struct snd_soc_codec *codec, int output, 314int arizona_set_output_mode(struct snd_soc_codec *codec, int output,
diff --git a/sound/soc/codecs/cs35l32.c b/sound/soc/codecs/cs35l32.c
index 44c30fe3e315..287d13740be4 100644
--- a/sound/soc/codecs/cs35l32.c
+++ b/sound/soc/codecs/cs35l32.c
@@ -274,7 +274,9 @@ static int cs35l32_handle_of_data(struct i2c_client *i2c_client,
274 if (of_property_read_u32(np, "cirrus,sdout-share", &val) >= 0) 274 if (of_property_read_u32(np, "cirrus,sdout-share", &val) >= 0)
275 pdata->sdout_share = val; 275 pdata->sdout_share = val;
276 276
277 of_property_read_u32(np, "cirrus,boost-manager", &val); 277 if (of_property_read_u32(np, "cirrus,boost-manager", &val))
278 val = -1u;
279
278 switch (val) { 280 switch (val) {
279 case CS35L32_BOOST_MGR_AUTO: 281 case CS35L32_BOOST_MGR_AUTO:
280 case CS35L32_BOOST_MGR_AUTO_AUDIO: 282 case CS35L32_BOOST_MGR_AUTO_AUDIO:
@@ -282,13 +284,15 @@ static int cs35l32_handle_of_data(struct i2c_client *i2c_client,
282 case CS35L32_BOOST_MGR_FIXED: 284 case CS35L32_BOOST_MGR_FIXED:
283 pdata->boost_mng = val; 285 pdata->boost_mng = val;
284 break; 286 break;
287 case -1u:
285 default: 288 default:
286 dev_err(&i2c_client->dev, 289 dev_err(&i2c_client->dev,
287 "Wrong cirrus,boost-manager DT value %d\n", val); 290 "Wrong cirrus,boost-manager DT value %d\n", val);
288 pdata->boost_mng = CS35L32_BOOST_MGR_BYPASS; 291 pdata->boost_mng = CS35L32_BOOST_MGR_BYPASS;
289 } 292 }
290 293
291 of_property_read_u32(np, "cirrus,sdout-datacfg", &val); 294 if (of_property_read_u32(np, "cirrus,sdout-datacfg", &val))
295 val = -1u;
292 switch (val) { 296 switch (val) {
293 case CS35L32_DATA_CFG_LR_VP: 297 case CS35L32_DATA_CFG_LR_VP:
294 case CS35L32_DATA_CFG_LR_STAT: 298 case CS35L32_DATA_CFG_LR_STAT:
@@ -296,13 +300,15 @@ static int cs35l32_handle_of_data(struct i2c_client *i2c_client,
296 case CS35L32_DATA_CFG_LR_VPSTAT: 300 case CS35L32_DATA_CFG_LR_VPSTAT:
297 pdata->sdout_datacfg = val; 301 pdata->sdout_datacfg = val;
298 break; 302 break;
303 case -1u:
299 default: 304 default:
300 dev_err(&i2c_client->dev, 305 dev_err(&i2c_client->dev,
301 "Wrong cirrus,sdout-datacfg DT value %d\n", val); 306 "Wrong cirrus,sdout-datacfg DT value %d\n", val);
302 pdata->sdout_datacfg = CS35L32_DATA_CFG_LR; 307 pdata->sdout_datacfg = CS35L32_DATA_CFG_LR;
303 } 308 }
304 309
305 of_property_read_u32(np, "cirrus,battery-threshold", &val); 310 if (of_property_read_u32(np, "cirrus,battery-threshold", &val))
311 val = -1u;
306 switch (val) { 312 switch (val) {
307 case CS35L32_BATT_THRESH_3_1V: 313 case CS35L32_BATT_THRESH_3_1V:
308 case CS35L32_BATT_THRESH_3_2V: 314 case CS35L32_BATT_THRESH_3_2V:
@@ -310,13 +316,15 @@ static int cs35l32_handle_of_data(struct i2c_client *i2c_client,
310 case CS35L32_BATT_THRESH_3_4V: 316 case CS35L32_BATT_THRESH_3_4V:
311 pdata->batt_thresh = val; 317 pdata->batt_thresh = val;
312 break; 318 break;
319 case -1u:
313 default: 320 default:
314 dev_err(&i2c_client->dev, 321 dev_err(&i2c_client->dev,
315 "Wrong cirrus,battery-threshold DT value %d\n", val); 322 "Wrong cirrus,battery-threshold DT value %d\n", val);
316 pdata->batt_thresh = CS35L32_BATT_THRESH_3_3V; 323 pdata->batt_thresh = CS35L32_BATT_THRESH_3_3V;
317 } 324 }
318 325
319 of_property_read_u32(np, "cirrus,battery-recovery", &val); 326 if (of_property_read_u32(np, "cirrus,battery-recovery", &val))
327 val = -1u;
320 switch (val) { 328 switch (val) {
321 case CS35L32_BATT_RECOV_3_1V: 329 case CS35L32_BATT_RECOV_3_1V:
322 case CS35L32_BATT_RECOV_3_2V: 330 case CS35L32_BATT_RECOV_3_2V:
@@ -326,6 +334,7 @@ static int cs35l32_handle_of_data(struct i2c_client *i2c_client,
326 case CS35L32_BATT_RECOV_3_6V: 334 case CS35L32_BATT_RECOV_3_6V:
327 pdata->batt_recov = val; 335 pdata->batt_recov = val;
328 break; 336 break;
337 case -1u:
329 default: 338 default:
330 dev_err(&i2c_client->dev, 339 dev_err(&i2c_client->dev,
331 "Wrong cirrus,battery-recovery DT value %d\n", val); 340 "Wrong cirrus,battery-recovery DT value %d\n", val);
diff --git a/sound/soc/codecs/cs47l24.c b/sound/soc/codecs/cs47l24.c
index 576087bda330..00e9b6fc1b5c 100644
--- a/sound/soc/codecs/cs47l24.c
+++ b/sound/soc/codecs/cs47l24.c
@@ -1108,6 +1108,9 @@ static int cs47l24_codec_remove(struct snd_soc_codec *codec)
1108 priv->core.arizona->dapm = NULL; 1108 priv->core.arizona->dapm = NULL;
1109 1109
1110 arizona_free_irq(arizona, ARIZONA_IRQ_DSP_IRQ1, priv); 1110 arizona_free_irq(arizona, ARIZONA_IRQ_DSP_IRQ1, priv);
1111
1112 arizona_free_spk(codec);
1113
1111 return 0; 1114 return 0;
1112} 1115}
1113 1116
diff --git a/sound/soc/codecs/hdac_hdmi.c b/sound/soc/codecs/hdac_hdmi.c
index 26f9459cb3bc..aaa038ffc8a5 100644
--- a/sound/soc/codecs/hdac_hdmi.c
+++ b/sound/soc/codecs/hdac_hdmi.c
@@ -1420,32 +1420,39 @@ static int hdmi_codec_remove(struct snd_soc_codec *codec)
1420} 1420}
1421 1421
1422#ifdef CONFIG_PM 1422#ifdef CONFIG_PM
1423static int hdmi_codec_resume(struct snd_soc_codec *codec) 1423static int hdmi_codec_prepare(struct device *dev)
1424{ 1424{
1425 struct hdac_ext_device *edev = snd_soc_codec_get_drvdata(codec); 1425 struct hdac_ext_device *edev = to_hda_ext_device(dev);
1426 struct hdac_device *hdac = &edev->hdac;
1427
1428 pm_runtime_get_sync(&edev->hdac.dev);
1429
1430 /*
1431 * Power down afg.
1432 * codec_read is preferred over codec_write to set the power state.
1433 * This way verb is send to set the power state and response
1434 * is received. So setting power state is ensured without using loop
1435 * to read the state.
1436 */
1437 snd_hdac_codec_read(hdac, hdac->afg, 0, AC_VERB_SET_POWER_STATE,
1438 AC_PWRST_D3);
1439
1440 return 0;
1441}
1442
1443static void hdmi_codec_complete(struct device *dev)
1444{
1445 struct hdac_ext_device *edev = to_hda_ext_device(dev);
1426 struct hdac_hdmi_priv *hdmi = edev->private_data; 1446 struct hdac_hdmi_priv *hdmi = edev->private_data;
1427 struct hdac_hdmi_pin *pin; 1447 struct hdac_hdmi_pin *pin;
1428 struct hdac_device *hdac = &edev->hdac; 1448 struct hdac_device *hdac = &edev->hdac;
1429 struct hdac_bus *bus = hdac->bus;
1430 int err;
1431 unsigned long timeout;
1432
1433 hdac_hdmi_skl_enable_all_pins(&edev->hdac);
1434 hdac_hdmi_skl_enable_dp12(&edev->hdac);
1435 1449
1436 /* Power up afg */ 1450 /* Power up afg */
1437 if (!snd_hdac_check_power_state(hdac, hdac->afg, AC_PWRST_D0)) { 1451 snd_hdac_codec_read(hdac, hdac->afg, 0, AC_VERB_SET_POWER_STATE,
1438 1452 AC_PWRST_D0);
1439 snd_hdac_codec_write(hdac, hdac->afg, 0,
1440 AC_VERB_SET_POWER_STATE, AC_PWRST_D0);
1441 1453
1442 /* Wait till power state is set to D0 */ 1454 hdac_hdmi_skl_enable_all_pins(&edev->hdac);
1443 timeout = jiffies + msecs_to_jiffies(1000); 1455 hdac_hdmi_skl_enable_dp12(&edev->hdac);
1444 while (!snd_hdac_check_power_state(hdac, hdac->afg, AC_PWRST_D0)
1445 && time_before(jiffies, timeout)) {
1446 msleep(50);
1447 }
1448 }
1449 1456
1450 /* 1457 /*
1451 * As the ELD notify callback request is not entertained while the 1458 * As the ELD notify callback request is not entertained while the
@@ -1455,28 +1462,16 @@ static int hdmi_codec_resume(struct snd_soc_codec *codec)
1455 list_for_each_entry(pin, &hdmi->pin_list, head) 1462 list_for_each_entry(pin, &hdmi->pin_list, head)
1456 hdac_hdmi_present_sense(pin, 1); 1463 hdac_hdmi_present_sense(pin, 1);
1457 1464
1458 /* 1465 pm_runtime_put_sync(&edev->hdac.dev);
1459 * Codec power is turned ON during controller resume.
1460 * Turn it OFF here
1461 */
1462 err = snd_hdac_display_power(bus, false);
1463 if (err < 0) {
1464 dev_err(bus->dev,
1465 "Cannot turn OFF display power on i915, err: %d\n",
1466 err);
1467 return err;
1468 }
1469
1470 return 0;
1471} 1466}
1472#else 1467#else
1473#define hdmi_codec_resume NULL 1468#define hdmi_codec_prepare NULL
1469#define hdmi_codec_complete NULL
1474#endif 1470#endif
1475 1471
1476static struct snd_soc_codec_driver hdmi_hda_codec = { 1472static struct snd_soc_codec_driver hdmi_hda_codec = {
1477 .probe = hdmi_codec_probe, 1473 .probe = hdmi_codec_probe,
1478 .remove = hdmi_codec_remove, 1474 .remove = hdmi_codec_remove,
1479 .resume = hdmi_codec_resume,
1480 .idle_bias_off = true, 1475 .idle_bias_off = true,
1481}; 1476};
1482 1477
@@ -1561,7 +1556,6 @@ static int hdac_hdmi_runtime_suspend(struct device *dev)
1561 struct hdac_ext_device *edev = to_hda_ext_device(dev); 1556 struct hdac_ext_device *edev = to_hda_ext_device(dev);
1562 struct hdac_device *hdac = &edev->hdac; 1557 struct hdac_device *hdac = &edev->hdac;
1563 struct hdac_bus *bus = hdac->bus; 1558 struct hdac_bus *bus = hdac->bus;
1564 unsigned long timeout;
1565 int err; 1559 int err;
1566 1560
1567 dev_dbg(dev, "Enter: %s\n", __func__); 1561 dev_dbg(dev, "Enter: %s\n", __func__);
@@ -1570,20 +1564,15 @@ static int hdac_hdmi_runtime_suspend(struct device *dev)
1570 if (!bus) 1564 if (!bus)
1571 return 0; 1565 return 0;
1572 1566
1573 /* Power down afg */ 1567 /*
1574 if (!snd_hdac_check_power_state(hdac, hdac->afg, AC_PWRST_D3)) { 1568 * Power down afg.
1575 snd_hdac_codec_write(hdac, hdac->afg, 0, 1569 * codec_read is preferred over codec_write to set the power state.
1576 AC_VERB_SET_POWER_STATE, AC_PWRST_D3); 1570 * This way verb is send to set the power state and response
1577 1571 * is received. So setting power state is ensured without using loop
1578 /* Wait till power state is set to D3 */ 1572 * to read the state.
1579 timeout = jiffies + msecs_to_jiffies(1000); 1573 */
1580 while (!snd_hdac_check_power_state(hdac, hdac->afg, AC_PWRST_D3) 1574 snd_hdac_codec_read(hdac, hdac->afg, 0, AC_VERB_SET_POWER_STATE,
1581 && time_before(jiffies, timeout)) { 1575 AC_PWRST_D3);
1582
1583 msleep(50);
1584 }
1585 }
1586
1587 err = snd_hdac_display_power(bus, false); 1576 err = snd_hdac_display_power(bus, false);
1588 if (err < 0) { 1577 if (err < 0) {
1589 dev_err(bus->dev, "Cannot turn on display power on i915\n"); 1578 dev_err(bus->dev, "Cannot turn on display power on i915\n");
@@ -1616,9 +1605,8 @@ static int hdac_hdmi_runtime_resume(struct device *dev)
1616 hdac_hdmi_skl_enable_dp12(&edev->hdac); 1605 hdac_hdmi_skl_enable_dp12(&edev->hdac);
1617 1606
1618 /* Power up afg */ 1607 /* Power up afg */
1619 if (!snd_hdac_check_power_state(hdac, hdac->afg, AC_PWRST_D0)) 1608 snd_hdac_codec_read(hdac, hdac->afg, 0, AC_VERB_SET_POWER_STATE,
1620 snd_hdac_codec_write(hdac, hdac->afg, 0, 1609 AC_PWRST_D0);
1621 AC_VERB_SET_POWER_STATE, AC_PWRST_D0);
1622 1610
1623 return 0; 1611 return 0;
1624} 1612}
@@ -1629,6 +1617,8 @@ static int hdac_hdmi_runtime_resume(struct device *dev)
1629 1617
1630static const struct dev_pm_ops hdac_hdmi_pm = { 1618static const struct dev_pm_ops hdac_hdmi_pm = {
1631 SET_RUNTIME_PM_OPS(hdac_hdmi_runtime_suspend, hdac_hdmi_runtime_resume, NULL) 1619 SET_RUNTIME_PM_OPS(hdac_hdmi_runtime_suspend, hdac_hdmi_runtime_resume, NULL)
1620 .prepare = hdmi_codec_prepare,
1621 .complete = hdmi_codec_complete,
1632}; 1622};
1633 1623
1634static const struct hda_device_id hdmi_list[] = { 1624static const struct hda_device_id hdmi_list[] = {
diff --git a/sound/soc/codecs/nau8825.c b/sound/soc/codecs/nau8825.c
index 1c8729984c2b..683769f0f246 100644
--- a/sound/soc/codecs/nau8825.c
+++ b/sound/soc/codecs/nau8825.c
@@ -343,9 +343,12 @@ static const struct snd_soc_dapm_widget nau8825_dapm_widgets[] = {
343 SND_SOC_DAPM_SUPPLY("ADC Power", NAU8825_REG_ANALOG_ADC_2, 6, 0, NULL, 343 SND_SOC_DAPM_SUPPLY("ADC Power", NAU8825_REG_ANALOG_ADC_2, 6, 0, NULL,
344 0), 344 0),
345 345
346 /* ADC for button press detection */ 346 /* ADC for button press detection. A dapm supply widget is used to
347 SND_SOC_DAPM_ADC("SAR", NULL, NAU8825_REG_SAR_CTRL, 347 * prevent dapm_power_widgets keeping the codec at SND_SOC_BIAS_ON
348 NAU8825_SAR_ADC_EN_SFT, 0), 348 * during suspend.
349 */
350 SND_SOC_DAPM_SUPPLY("SAR", NAU8825_REG_SAR_CTRL,
351 NAU8825_SAR_ADC_EN_SFT, 0, NULL, 0),
349 352
350 SND_SOC_DAPM_PGA_S("ADACL", 2, NAU8825_REG_RDAC, 12, 0, NULL, 0), 353 SND_SOC_DAPM_PGA_S("ADACL", 2, NAU8825_REG_RDAC, 12, 0, NULL, 0),
351 SND_SOC_DAPM_PGA_S("ADACR", 2, NAU8825_REG_RDAC, 13, 0, NULL, 0), 354 SND_SOC_DAPM_PGA_S("ADACR", 2, NAU8825_REG_RDAC, 13, 0, NULL, 0),
@@ -607,6 +610,16 @@ static bool nau8825_is_jack_inserted(struct regmap *regmap)
607 610
608static void nau8825_restart_jack_detection(struct regmap *regmap) 611static void nau8825_restart_jack_detection(struct regmap *regmap)
609{ 612{
613 /* Chip needs one FSCLK cycle in order to generate interrupts,
614 * as we cannot guarantee one will be provided by the system. Turning
615 * master mode on then off enables us to generate that FSCLK cycle
616 * with a minimum of contention on the clock bus.
617 */
618 regmap_update_bits(regmap, NAU8825_REG_I2S_PCM_CTRL2,
619 NAU8825_I2S_MS_MASK, NAU8825_I2S_MS_MASTER);
620 regmap_update_bits(regmap, NAU8825_REG_I2S_PCM_CTRL2,
621 NAU8825_I2S_MS_MASK, NAU8825_I2S_MS_SLAVE);
622
610 /* this will restart the entire jack detection process including MIC/GND 623 /* this will restart the entire jack detection process including MIC/GND
611 * switching and create interrupts. We have to go from 0 to 1 and back 624 * switching and create interrupts. We have to go from 0 to 1 and back
612 * to 0 to restart. 625 * to 0 to restart.
@@ -728,7 +741,10 @@ static irqreturn_t nau8825_interrupt(int irq, void *data)
728 struct regmap *regmap = nau8825->regmap; 741 struct regmap *regmap = nau8825->regmap;
729 int active_irq, clear_irq = 0, event = 0, event_mask = 0; 742 int active_irq, clear_irq = 0, event = 0, event_mask = 0;
730 743
731 regmap_read(regmap, NAU8825_REG_IRQ_STATUS, &active_irq); 744 if (regmap_read(regmap, NAU8825_REG_IRQ_STATUS, &active_irq)) {
745 dev_err(nau8825->dev, "failed to read irq status\n");
746 return IRQ_NONE;
747 }
732 748
733 if ((active_irq & NAU8825_JACK_EJECTION_IRQ_MASK) == 749 if ((active_irq & NAU8825_JACK_EJECTION_IRQ_MASK) ==
734 NAU8825_JACK_EJECTION_DETECTED) { 750 NAU8825_JACK_EJECTION_DETECTED) {
@@ -1141,33 +1157,74 @@ static int nau8825_set_bias_level(struct snd_soc_codec *codec,
1141 return ret; 1157 return ret;
1142 } 1158 }
1143 } 1159 }
1144
1145 ret = regcache_sync(nau8825->regmap);
1146 if (ret) {
1147 dev_err(codec->dev,
1148 "Failed to sync cache: %d\n", ret);
1149 return ret;
1150 }
1151 } 1160 }
1152
1153 break; 1161 break;
1154 1162
1155 case SND_SOC_BIAS_OFF: 1163 case SND_SOC_BIAS_OFF:
1156 if (nau8825->mclk_freq) 1164 if (nau8825->mclk_freq)
1157 clk_disable_unprepare(nau8825->mclk); 1165 clk_disable_unprepare(nau8825->mclk);
1158
1159 regcache_mark_dirty(nau8825->regmap);
1160 break; 1166 break;
1161 } 1167 }
1162 return 0; 1168 return 0;
1163} 1169}
1164 1170
1171#ifdef CONFIG_PM
1172static int nau8825_suspend(struct snd_soc_codec *codec)
1173{
1174 struct nau8825 *nau8825 = snd_soc_codec_get_drvdata(codec);
1175
1176 disable_irq(nau8825->irq);
1177 regcache_cache_only(nau8825->regmap, true);
1178 regcache_mark_dirty(nau8825->regmap);
1179
1180 return 0;
1181}
1182
1183static int nau8825_resume(struct snd_soc_codec *codec)
1184{
1185 struct nau8825 *nau8825 = snd_soc_codec_get_drvdata(codec);
1186
1187 /* The chip may lose power and reset in S3. regcache_sync restores
1188 * register values including configurations for sysclk, irq, and
1189 * jack/button detection.
1190 */
1191 regcache_cache_only(nau8825->regmap, false);
1192 regcache_sync(nau8825->regmap);
1193
1194 /* Check the jack plug status directly. If the headset is unplugged
1195 * during S3 when the chip has no power, there will be no jack
1196 * detection irq even after the nau8825_restart_jack_detection below,
1197 * because the chip just thinks no headset has ever been plugged in.
1198 */
1199 if (!nau8825_is_jack_inserted(nau8825->regmap)) {
1200 nau8825_eject_jack(nau8825);
1201 snd_soc_jack_report(nau8825->jack, 0, SND_JACK_HEADSET);
1202 }
1203
1204 enable_irq(nau8825->irq);
1205
1206 /* Run jack detection to check the type (OMTP or CTIA) of the headset
1207 * if there is one. This handles the case where a different type of
1208 * headset is plugged in during S3. This triggers an IRQ iff a headset
1209 * is already plugged in.
1210 */
1211 nau8825_restart_jack_detection(nau8825->regmap);
1212
1213 return 0;
1214}
1215#else
1216#define nau8825_suspend NULL
1217#define nau8825_resume NULL
1218#endif
1219
1165static struct snd_soc_codec_driver nau8825_codec_driver = { 1220static struct snd_soc_codec_driver nau8825_codec_driver = {
1166 .probe = nau8825_codec_probe, 1221 .probe = nau8825_codec_probe,
1167 .set_sysclk = nau8825_set_sysclk, 1222 .set_sysclk = nau8825_set_sysclk,
1168 .set_pll = nau8825_set_pll, 1223 .set_pll = nau8825_set_pll,
1169 .set_bias_level = nau8825_set_bias_level, 1224 .set_bias_level = nau8825_set_bias_level,
1170 .suspend_bias_off = true, 1225 .suspend_bias_off = true,
1226 .suspend = nau8825_suspend,
1227 .resume = nau8825_resume,
1171 1228
1172 .controls = nau8825_controls, 1229 .controls = nau8825_controls,
1173 .num_controls = ARRAY_SIZE(nau8825_controls), 1230 .num_controls = ARRAY_SIZE(nau8825_controls),
@@ -1277,16 +1334,6 @@ static int nau8825_setup_irq(struct nau8825 *nau8825)
1277 regmap_update_bits(regmap, NAU8825_REG_ENA_CTRL, 1334 regmap_update_bits(regmap, NAU8825_REG_ENA_CTRL,
1278 NAU8825_ENABLE_DACR, NAU8825_ENABLE_DACR); 1335 NAU8825_ENABLE_DACR, NAU8825_ENABLE_DACR);
1279 1336
1280 /* Chip needs one FSCLK cycle in order to generate interrupts,
1281 * as we cannot guarantee one will be provided by the system. Turning
1282 * master mode on then off enables us to generate that FSCLK cycle
1283 * with a minimum of contention on the clock bus.
1284 */
1285 regmap_update_bits(regmap, NAU8825_REG_I2S_PCM_CTRL2,
1286 NAU8825_I2S_MS_MASK, NAU8825_I2S_MS_MASTER);
1287 regmap_update_bits(regmap, NAU8825_REG_I2S_PCM_CTRL2,
1288 NAU8825_I2S_MS_MASK, NAU8825_I2S_MS_SLAVE);
1289
1290 ret = devm_request_threaded_irq(nau8825->dev, nau8825->irq, NULL, 1337 ret = devm_request_threaded_irq(nau8825->dev, nau8825->irq, NULL,
1291 nau8825_interrupt, IRQF_TRIGGER_LOW | IRQF_ONESHOT, 1338 nau8825_interrupt, IRQF_TRIGGER_LOW | IRQF_ONESHOT,
1292 "nau8825", nau8825); 1339 "nau8825", nau8825);
@@ -1354,36 +1401,6 @@ static int nau8825_i2c_remove(struct i2c_client *client)
1354 return 0; 1401 return 0;
1355} 1402}
1356 1403
1357#ifdef CONFIG_PM_SLEEP
1358static int nau8825_suspend(struct device *dev)
1359{
1360 struct i2c_client *client = to_i2c_client(dev);
1361 struct nau8825 *nau8825 = dev_get_drvdata(dev);
1362
1363 disable_irq(client->irq);
1364 regcache_cache_only(nau8825->regmap, true);
1365 regcache_mark_dirty(nau8825->regmap);
1366
1367 return 0;
1368}
1369
1370static int nau8825_resume(struct device *dev)
1371{
1372 struct i2c_client *client = to_i2c_client(dev);
1373 struct nau8825 *nau8825 = dev_get_drvdata(dev);
1374
1375 regcache_cache_only(nau8825->regmap, false);
1376 regcache_sync(nau8825->regmap);
1377 enable_irq(client->irq);
1378
1379 return 0;
1380}
1381#endif
1382
1383static const struct dev_pm_ops nau8825_pm = {
1384 SET_SYSTEM_SLEEP_PM_OPS(nau8825_suspend, nau8825_resume)
1385};
1386
1387static const struct i2c_device_id nau8825_i2c_ids[] = { 1404static const struct i2c_device_id nau8825_i2c_ids[] = {
1388 { "nau8825", 0 }, 1405 { "nau8825", 0 },
1389 { } 1406 { }
@@ -1410,7 +1427,6 @@ static struct i2c_driver nau8825_driver = {
1410 .name = "nau8825", 1427 .name = "nau8825",
1411 .of_match_table = of_match_ptr(nau8825_of_ids), 1428 .of_match_table = of_match_ptr(nau8825_of_ids),
1412 .acpi_match_table = ACPI_PTR(nau8825_acpi_match), 1429 .acpi_match_table = ACPI_PTR(nau8825_acpi_match),
1413 .pm = &nau8825_pm,
1414 }, 1430 },
1415 .probe = nau8825_i2c_probe, 1431 .probe = nau8825_i2c_probe,
1416 .remove = nau8825_i2c_remove, 1432 .remove = nau8825_i2c_remove,
diff --git a/sound/soc/codecs/rt5640.c b/sound/soc/codecs/rt5640.c
index e8b5ba04417a..09e8988bbb2d 100644
--- a/sound/soc/codecs/rt5640.c
+++ b/sound/soc/codecs/rt5640.c
@@ -359,7 +359,7 @@ static const DECLARE_TLV_DB_RANGE(bst_tlv,
359 359
360/* Interface data select */ 360/* Interface data select */
361static const char * const rt5640_data_select[] = { 361static const char * const rt5640_data_select[] = {
362 "Normal", "left copy to right", "right copy to left", "Swap"}; 362 "Normal", "Swap", "left copy to right", "right copy to left"};
363 363
364static SOC_ENUM_SINGLE_DECL(rt5640_if1_dac_enum, RT5640_DIG_INF_DATA, 364static SOC_ENUM_SINGLE_DECL(rt5640_if1_dac_enum, RT5640_DIG_INF_DATA,
365 RT5640_IF1_DAC_SEL_SFT, rt5640_data_select); 365 RT5640_IF1_DAC_SEL_SFT, rt5640_data_select);
diff --git a/sound/soc/codecs/rt5640.h b/sound/soc/codecs/rt5640.h
index 1761c3a98b76..58b664b06c16 100644
--- a/sound/soc/codecs/rt5640.h
+++ b/sound/soc/codecs/rt5640.h
@@ -443,39 +443,39 @@
443#define RT5640_IF1_DAC_SEL_MASK (0x3 << 14) 443#define RT5640_IF1_DAC_SEL_MASK (0x3 << 14)
444#define RT5640_IF1_DAC_SEL_SFT 14 444#define RT5640_IF1_DAC_SEL_SFT 14
445#define RT5640_IF1_DAC_SEL_NOR (0x0 << 14) 445#define RT5640_IF1_DAC_SEL_NOR (0x0 << 14)
446#define RT5640_IF1_DAC_SEL_L2R (0x1 << 14) 446#define RT5640_IF1_DAC_SEL_SWAP (0x1 << 14)
447#define RT5640_IF1_DAC_SEL_R2L (0x2 << 14) 447#define RT5640_IF1_DAC_SEL_L2R (0x2 << 14)
448#define RT5640_IF1_DAC_SEL_SWAP (0x3 << 14) 448#define RT5640_IF1_DAC_SEL_R2L (0x3 << 14)
449#define RT5640_IF1_ADC_SEL_MASK (0x3 << 12) 449#define RT5640_IF1_ADC_SEL_MASK (0x3 << 12)
450#define RT5640_IF1_ADC_SEL_SFT 12 450#define RT5640_IF1_ADC_SEL_SFT 12
451#define RT5640_IF1_ADC_SEL_NOR (0x0 << 12) 451#define RT5640_IF1_ADC_SEL_NOR (0x0 << 12)
452#define RT5640_IF1_ADC_SEL_L2R (0x1 << 12) 452#define RT5640_IF1_ADC_SEL_SWAP (0x1 << 12)
453#define RT5640_IF1_ADC_SEL_R2L (0x2 << 12) 453#define RT5640_IF1_ADC_SEL_L2R (0x2 << 12)
454#define RT5640_IF1_ADC_SEL_SWAP (0x3 << 12) 454#define RT5640_IF1_ADC_SEL_R2L (0x3 << 12)
455#define RT5640_IF2_DAC_SEL_MASK (0x3 << 10) 455#define RT5640_IF2_DAC_SEL_MASK (0x3 << 10)
456#define RT5640_IF2_DAC_SEL_SFT 10 456#define RT5640_IF2_DAC_SEL_SFT 10
457#define RT5640_IF2_DAC_SEL_NOR (0x0 << 10) 457#define RT5640_IF2_DAC_SEL_NOR (0x0 << 10)
458#define RT5640_IF2_DAC_SEL_L2R (0x1 << 10) 458#define RT5640_IF2_DAC_SEL_SWAP (0x1 << 10)
459#define RT5640_IF2_DAC_SEL_R2L (0x2 << 10) 459#define RT5640_IF2_DAC_SEL_L2R (0x2 << 10)
460#define RT5640_IF2_DAC_SEL_SWAP (0x3 << 10) 460#define RT5640_IF2_DAC_SEL_R2L (0x3 << 10)
461#define RT5640_IF2_ADC_SEL_MASK (0x3 << 8) 461#define RT5640_IF2_ADC_SEL_MASK (0x3 << 8)
462#define RT5640_IF2_ADC_SEL_SFT 8 462#define RT5640_IF2_ADC_SEL_SFT 8
463#define RT5640_IF2_ADC_SEL_NOR (0x0 << 8) 463#define RT5640_IF2_ADC_SEL_NOR (0x0 << 8)
464#define RT5640_IF2_ADC_SEL_L2R (0x1 << 8) 464#define RT5640_IF2_ADC_SEL_SWAP (0x1 << 8)
465#define RT5640_IF2_ADC_SEL_R2L (0x2 << 8) 465#define RT5640_IF2_ADC_SEL_L2R (0x2 << 8)
466#define RT5640_IF2_ADC_SEL_SWAP (0x3 << 8) 466#define RT5640_IF2_ADC_SEL_R2L (0x3 << 8)
467#define RT5640_IF3_DAC_SEL_MASK (0x3 << 6) 467#define RT5640_IF3_DAC_SEL_MASK (0x3 << 6)
468#define RT5640_IF3_DAC_SEL_SFT 6 468#define RT5640_IF3_DAC_SEL_SFT 6
469#define RT5640_IF3_DAC_SEL_NOR (0x0 << 6) 469#define RT5640_IF3_DAC_SEL_NOR (0x0 << 6)
470#define RT5640_IF3_DAC_SEL_L2R (0x1 << 6) 470#define RT5640_IF3_DAC_SEL_SWAP (0x1 << 6)
471#define RT5640_IF3_DAC_SEL_R2L (0x2 << 6) 471#define RT5640_IF3_DAC_SEL_L2R (0x2 << 6)
472#define RT5640_IF3_DAC_SEL_SWAP (0x3 << 6) 472#define RT5640_IF3_DAC_SEL_R2L (0x3 << 6)
473#define RT5640_IF3_ADC_SEL_MASK (0x3 << 4) 473#define RT5640_IF3_ADC_SEL_MASK (0x3 << 4)
474#define RT5640_IF3_ADC_SEL_SFT 4 474#define RT5640_IF3_ADC_SEL_SFT 4
475#define RT5640_IF3_ADC_SEL_NOR (0x0 << 4) 475#define RT5640_IF3_ADC_SEL_NOR (0x0 << 4)
476#define RT5640_IF3_ADC_SEL_L2R (0x1 << 4) 476#define RT5640_IF3_ADC_SEL_SWAP (0x1 << 4)
477#define RT5640_IF3_ADC_SEL_R2L (0x2 << 4) 477#define RT5640_IF3_ADC_SEL_L2R (0x2 << 4)
478#define RT5640_IF3_ADC_SEL_SWAP (0x3 << 4) 478#define RT5640_IF3_ADC_SEL_R2L (0x3 << 4)
479 479
480/* REC Left Mixer Control 1 (0x3b) */ 480/* REC Left Mixer Control 1 (0x3b) */
481#define RT5640_G_HP_L_RM_L_MASK (0x7 << 13) 481#define RT5640_G_HP_L_RM_L_MASK (0x7 << 13)
diff --git a/sound/soc/codecs/wm5102.c b/sound/soc/codecs/wm5102.c
index a8b3e3f701f9..1bae17ee8817 100644
--- a/sound/soc/codecs/wm5102.c
+++ b/sound/soc/codecs/wm5102.c
@@ -1955,11 +1955,16 @@ err_adsp2_codec_probe:
1955static int wm5102_codec_remove(struct snd_soc_codec *codec) 1955static int wm5102_codec_remove(struct snd_soc_codec *codec)
1956{ 1956{
1957 struct wm5102_priv *priv = snd_soc_codec_get_drvdata(codec); 1957 struct wm5102_priv *priv = snd_soc_codec_get_drvdata(codec);
1958 struct arizona *arizona = priv->core.arizona;
1958 1959
1959 wm_adsp2_codec_remove(&priv->core.adsp[0], codec); 1960 wm_adsp2_codec_remove(&priv->core.adsp[0], codec);
1960 1961
1961 priv->core.arizona->dapm = NULL; 1962 priv->core.arizona->dapm = NULL;
1962 1963
1964 arizona_free_irq(arizona, ARIZONA_IRQ_DSP_IRQ1, priv);
1965
1966 arizona_free_spk(codec);
1967
1963 return 0; 1968 return 0;
1964} 1969}
1965 1970
diff --git a/sound/soc/codecs/wm5110.c b/sound/soc/codecs/wm5110.c
index 83ba70fe16e6..2728ac545ffe 100644
--- a/sound/soc/codecs/wm5110.c
+++ b/sound/soc/codecs/wm5110.c
@@ -2298,6 +2298,8 @@ static int wm5110_codec_remove(struct snd_soc_codec *codec)
2298 2298
2299 arizona_free_irq(arizona, ARIZONA_IRQ_DSP_IRQ1, priv); 2299 arizona_free_irq(arizona, ARIZONA_IRQ_DSP_IRQ1, priv);
2300 2300
2301 arizona_free_spk(codec);
2302
2301 return 0; 2303 return 0;
2302} 2304}
2303 2305
diff --git a/sound/soc/codecs/wm8962.c b/sound/soc/codecs/wm8962.c
index 88223608a33f..720a14e0687d 100644
--- a/sound/soc/codecs/wm8962.c
+++ b/sound/soc/codecs/wm8962.c
@@ -2471,7 +2471,7 @@ static void wm8962_configure_bclk(struct snd_soc_codec *codec)
2471 break; 2471 break;
2472 default: 2472 default:
2473 dev_warn(codec->dev, "Unknown DSPCLK divisor read back\n"); 2473 dev_warn(codec->dev, "Unknown DSPCLK divisor read back\n");
2474 dspclk = wm8962->sysclk; 2474 dspclk = wm8962->sysclk_rate;
2475 } 2475 }
2476 2476
2477 dev_dbg(codec->dev, "DSPCLK is %dHz, BCLK %d\n", dspclk, wm8962->bclk); 2477 dev_dbg(codec->dev, "DSPCLK is %dHz, BCLK %d\n", dspclk, wm8962->bclk);
diff --git a/sound/soc/codecs/wm8997.c b/sound/soc/codecs/wm8997.c
index 52d766efe14f..6b0785b5a5c5 100644
--- a/sound/soc/codecs/wm8997.c
+++ b/sound/soc/codecs/wm8997.c
@@ -1072,6 +1072,8 @@ static int wm8997_codec_remove(struct snd_soc_codec *codec)
1072 1072
1073 priv->core.arizona->dapm = NULL; 1073 priv->core.arizona->dapm = NULL;
1074 1074
1075 arizona_free_spk(codec);
1076
1075 return 0; 1077 return 0;
1076} 1078}
1077 1079
diff --git a/sound/soc/codecs/wm8998.c b/sound/soc/codecs/wm8998.c
index 012396074a8a..449f66636205 100644
--- a/sound/soc/codecs/wm8998.c
+++ b/sound/soc/codecs/wm8998.c
@@ -1324,6 +1324,8 @@ static int wm8998_codec_remove(struct snd_soc_codec *codec)
1324 1324
1325 priv->core.arizona->dapm = NULL; 1325 priv->core.arizona->dapm = NULL;
1326 1326
1327 arizona_free_spk(codec);
1328
1327 return 0; 1329 return 0;
1328} 1330}
1329 1331
diff --git a/sound/soc/intel/Kconfig b/sound/soc/intel/Kconfig
index b3e6c2300457..1120f4f4d011 100644
--- a/sound/soc/intel/Kconfig
+++ b/sound/soc/intel/Kconfig
@@ -163,7 +163,6 @@ config SND_SOC_INTEL_SKYLAKE
163 tristate 163 tristate
164 select SND_HDA_EXT_CORE 164 select SND_HDA_EXT_CORE
165 select SND_SOC_TOPOLOGY 165 select SND_SOC_TOPOLOGY
166 select SND_HDA_I915
167 select SND_SOC_INTEL_SST 166 select SND_SOC_INTEL_SST
168 167
169config SND_SOC_INTEL_SKL_RT286_MACH 168config SND_SOC_INTEL_SKL_RT286_MACH
diff --git a/sound/soc/intel/haswell/sst-haswell-ipc.c b/sound/soc/intel/haswell/sst-haswell-ipc.c
index ac60f1301e21..91565229d074 100644
--- a/sound/soc/intel/haswell/sst-haswell-ipc.c
+++ b/sound/soc/intel/haswell/sst-haswell-ipc.c
@@ -1345,7 +1345,7 @@ int sst_hsw_stream_reset(struct sst_hsw *hsw, struct sst_hsw_stream *stream)
1345 return 0; 1345 return 0;
1346 1346
1347 /* wait for pause to complete before we reset the stream */ 1347 /* wait for pause to complete before we reset the stream */
1348 while (stream->running && tries--) 1348 while (stream->running && --tries)
1349 msleep(1); 1349 msleep(1);
1350 if (!tries) { 1350 if (!tries) {
1351 dev_err(hsw->dev, "error: reset stream %d still running\n", 1351 dev_err(hsw->dev, "error: reset stream %d still running\n",
diff --git a/sound/soc/intel/skylake/skl-sst-dsp.c b/sound/soc/intel/skylake/skl-sst-dsp.c
index a5267e8a96e0..2962ef22fc84 100644
--- a/sound/soc/intel/skylake/skl-sst-dsp.c
+++ b/sound/soc/intel/skylake/skl-sst-dsp.c
@@ -336,6 +336,11 @@ void skl_dsp_free(struct sst_dsp *dsp)
336 skl_ipc_int_disable(dsp); 336 skl_ipc_int_disable(dsp);
337 337
338 free_irq(dsp->irq, dsp); 338 free_irq(dsp->irq, dsp);
339 dsp->cl_dev.ops.cl_cleanup_controller(dsp);
340 skl_cldma_int_disable(dsp);
341 skl_ipc_op_int_disable(dsp);
342 skl_ipc_int_disable(dsp);
343
339 skl_dsp_disable_core(dsp); 344 skl_dsp_disable_core(dsp);
340} 345}
341EXPORT_SYMBOL_GPL(skl_dsp_free); 346EXPORT_SYMBOL_GPL(skl_dsp_free);
diff --git a/sound/soc/intel/skylake/skl-topology.c b/sound/soc/intel/skylake/skl-topology.c
index 545b4e77b8aa..cdb78b7e5a14 100644
--- a/sound/soc/intel/skylake/skl-topology.c
+++ b/sound/soc/intel/skylake/skl-topology.c
@@ -239,6 +239,7 @@ static void skl_tplg_update_buffer_size(struct skl_sst *ctx,
239{ 239{
240 int multiplier = 1; 240 int multiplier = 1;
241 struct skl_module_fmt *in_fmt, *out_fmt; 241 struct skl_module_fmt *in_fmt, *out_fmt;
242 int in_rate, out_rate;
242 243
243 244
244 /* Since fixups is applied to pin 0 only, ibs, obs needs 245 /* Since fixups is applied to pin 0 only, ibs, obs needs
@@ -249,15 +250,24 @@ static void skl_tplg_update_buffer_size(struct skl_sst *ctx,
249 250
250 if (mcfg->m_type == SKL_MODULE_TYPE_SRCINT) 251 if (mcfg->m_type == SKL_MODULE_TYPE_SRCINT)
251 multiplier = 5; 252 multiplier = 5;
252 mcfg->ibs = (in_fmt->s_freq / 1000) * 253
253 (mcfg->in_fmt->channels) * 254 if (in_fmt->s_freq % 1000)
254 (mcfg->in_fmt->bit_depth >> 3) * 255 in_rate = (in_fmt->s_freq / 1000) + 1;
255 multiplier; 256 else
256 257 in_rate = (in_fmt->s_freq / 1000);
257 mcfg->obs = (mcfg->out_fmt->s_freq / 1000) * 258
258 (mcfg->out_fmt->channels) * 259 mcfg->ibs = in_rate * (mcfg->in_fmt->channels) *
259 (mcfg->out_fmt->bit_depth >> 3) * 260 (mcfg->in_fmt->bit_depth >> 3) *
260 multiplier; 261 multiplier;
262
263 if (mcfg->out_fmt->s_freq % 1000)
264 out_rate = (mcfg->out_fmt->s_freq / 1000) + 1;
265 else
266 out_rate = (mcfg->out_fmt->s_freq / 1000);
267
268 mcfg->obs = out_rate * (mcfg->out_fmt->channels) *
269 (mcfg->out_fmt->bit_depth >> 3) *
270 multiplier;
261} 271}
262 272
263static int skl_tplg_update_be_blob(struct snd_soc_dapm_widget *w, 273static int skl_tplg_update_be_blob(struct snd_soc_dapm_widget *w,
@@ -485,11 +495,15 @@ skl_tplg_init_pipe_modules(struct skl *skl, struct skl_pipe *pipe)
485 if (!skl_is_pipe_mcps_avail(skl, mconfig)) 495 if (!skl_is_pipe_mcps_avail(skl, mconfig))
486 return -ENOMEM; 496 return -ENOMEM;
487 497
498 skl_tplg_alloc_pipe_mcps(skl, mconfig);
499
488 if (mconfig->is_loadable && ctx->dsp->fw_ops.load_mod) { 500 if (mconfig->is_loadable && ctx->dsp->fw_ops.load_mod) {
489 ret = ctx->dsp->fw_ops.load_mod(ctx->dsp, 501 ret = ctx->dsp->fw_ops.load_mod(ctx->dsp,
490 mconfig->id.module_id, mconfig->guid); 502 mconfig->id.module_id, mconfig->guid);
491 if (ret < 0) 503 if (ret < 0)
492 return ret; 504 return ret;
505
506 mconfig->m_state = SKL_MODULE_LOADED;
493 } 507 }
494 508
495 /* update blob if blob is null for be with default value */ 509 /* update blob if blob is null for be with default value */
@@ -509,7 +523,6 @@ skl_tplg_init_pipe_modules(struct skl *skl, struct skl_pipe *pipe)
509 ret = skl_tplg_set_module_params(w, ctx); 523 ret = skl_tplg_set_module_params(w, ctx);
510 if (ret < 0) 524 if (ret < 0)
511 return ret; 525 return ret;
512 skl_tplg_alloc_pipe_mcps(skl, mconfig);
513 } 526 }
514 527
515 return 0; 528 return 0;
@@ -524,7 +537,8 @@ static int skl_tplg_unload_pipe_modules(struct skl_sst *ctx,
524 list_for_each_entry(w_module, &pipe->w_list, node) { 537 list_for_each_entry(w_module, &pipe->w_list, node) {
525 mconfig = w_module->w->priv; 538 mconfig = w_module->w->priv;
526 539
527 if (mconfig->is_loadable && ctx->dsp->fw_ops.unload_mod) 540 if (mconfig->is_loadable && ctx->dsp->fw_ops.unload_mod &&
541 mconfig->m_state > SKL_MODULE_UNINIT)
528 return ctx->dsp->fw_ops.unload_mod(ctx->dsp, 542 return ctx->dsp->fw_ops.unload_mod(ctx->dsp,
529 mconfig->id.module_id); 543 mconfig->id.module_id);
530 } 544 }
@@ -558,6 +572,9 @@ static int skl_tplg_mixer_dapm_pre_pmu_event(struct snd_soc_dapm_widget *w,
558 if (!skl_is_pipe_mem_avail(skl, mconfig)) 572 if (!skl_is_pipe_mem_avail(skl, mconfig))
559 return -ENOMEM; 573 return -ENOMEM;
560 574
575 skl_tplg_alloc_pipe_mem(skl, mconfig);
576 skl_tplg_alloc_pipe_mcps(skl, mconfig);
577
561 /* 578 /*
562 * Create a list of modules for pipe. 579 * Create a list of modules for pipe.
563 * This list contains modules from source to sink 580 * This list contains modules from source to sink
@@ -601,9 +618,6 @@ static int skl_tplg_mixer_dapm_pre_pmu_event(struct snd_soc_dapm_widget *w,
601 src_module = dst_module; 618 src_module = dst_module;
602 } 619 }
603 620
604 skl_tplg_alloc_pipe_mem(skl, mconfig);
605 skl_tplg_alloc_pipe_mcps(skl, mconfig);
606
607 return 0; 621 return 0;
608} 622}
609 623
diff --git a/sound/soc/intel/skylake/skl-topology.h b/sound/soc/intel/skylake/skl-topology.h
index de3c401284d9..d2d923002d5c 100644
--- a/sound/soc/intel/skylake/skl-topology.h
+++ b/sound/soc/intel/skylake/skl-topology.h
@@ -274,10 +274,10 @@ struct skl_pipe {
274 274
275enum skl_module_state { 275enum skl_module_state {
276 SKL_MODULE_UNINIT = 0, 276 SKL_MODULE_UNINIT = 0,
277 SKL_MODULE_INIT_DONE = 1, 277 SKL_MODULE_LOADED = 1,
278 SKL_MODULE_LOADED = 2, 278 SKL_MODULE_INIT_DONE = 2,
279 SKL_MODULE_UNLOADED = 3, 279 SKL_MODULE_BIND_DONE = 3,
280 SKL_MODULE_BIND_DONE = 4 280 SKL_MODULE_UNLOADED = 4,
281}; 281};
282 282
283struct skl_module_cfg { 283struct skl_module_cfg {
diff --git a/sound/soc/intel/skylake/skl.c b/sound/soc/intel/skylake/skl.c
index ab5e25aaeee3..3982f5536f2d 100644
--- a/sound/soc/intel/skylake/skl.c
+++ b/sound/soc/intel/skylake/skl.c
@@ -222,6 +222,7 @@ static int skl_suspend(struct device *dev)
222 struct hdac_ext_bus *ebus = pci_get_drvdata(pci); 222 struct hdac_ext_bus *ebus = pci_get_drvdata(pci);
223 struct skl *skl = ebus_to_skl(ebus); 223 struct skl *skl = ebus_to_skl(ebus);
224 struct hdac_bus *bus = ebus_to_hbus(ebus); 224 struct hdac_bus *bus = ebus_to_hbus(ebus);
225 int ret = 0;
225 226
226 /* 227 /*
227 * Do not suspend if streams which are marked ignore suspend are 228 * Do not suspend if streams which are marked ignore suspend are
@@ -232,10 +233,20 @@ static int skl_suspend(struct device *dev)
232 enable_irq_wake(bus->irq); 233 enable_irq_wake(bus->irq);
233 pci_save_state(pci); 234 pci_save_state(pci);
234 pci_disable_device(pci); 235 pci_disable_device(pci);
235 return 0;
236 } else { 236 } else {
237 return _skl_suspend(ebus); 237 ret = _skl_suspend(ebus);
238 if (ret < 0)
239 return ret;
240 }
241
242 if (IS_ENABLED(CONFIG_SND_SOC_HDAC_HDMI)) {
243 ret = snd_hdac_display_power(bus, false);
244 if (ret < 0)
245 dev_err(bus->dev,
246 "Cannot turn OFF display power on i915\n");
238 } 247 }
248
249 return ret;
239} 250}
240 251
241static int skl_resume(struct device *dev) 252static int skl_resume(struct device *dev)
@@ -316,17 +327,20 @@ static int skl_free(struct hdac_ext_bus *ebus)
316 327
317 if (bus->irq >= 0) 328 if (bus->irq >= 0)
318 free_irq(bus->irq, (void *)bus); 329 free_irq(bus->irq, (void *)bus);
319 if (bus->remap_addr)
320 iounmap(bus->remap_addr);
321
322 snd_hdac_bus_free_stream_pages(bus); 330 snd_hdac_bus_free_stream_pages(bus);
323 snd_hdac_stream_free_all(ebus); 331 snd_hdac_stream_free_all(ebus);
324 snd_hdac_link_free_all(ebus); 332 snd_hdac_link_free_all(ebus);
333
334 if (bus->remap_addr)
335 iounmap(bus->remap_addr);
336
325 pci_release_regions(skl->pci); 337 pci_release_regions(skl->pci);
326 pci_disable_device(skl->pci); 338 pci_disable_device(skl->pci);
327 339
328 snd_hdac_ext_bus_exit(ebus); 340 snd_hdac_ext_bus_exit(ebus);
329 341
342 if (IS_ENABLED(CONFIG_SND_SOC_HDAC_HDMI))
343 snd_hdac_i915_exit(&ebus->bus);
330 return 0; 344 return 0;
331} 345}
332 346
@@ -719,12 +733,12 @@ static void skl_remove(struct pci_dev *pci)
719 if (skl->tplg) 733 if (skl->tplg)
720 release_firmware(skl->tplg); 734 release_firmware(skl->tplg);
721 735
722 if (IS_ENABLED(CONFIG_SND_SOC_HDAC_HDMI))
723 snd_hdac_i915_exit(&ebus->bus);
724
725 if (pci_dev_run_wake(pci)) 736 if (pci_dev_run_wake(pci))
726 pm_runtime_get_noresume(&pci->dev); 737 pm_runtime_get_noresume(&pci->dev);
727 pci_dev_put(pci); 738
739 /* codec removal, invoke bus_device_remove */
740 snd_hdac_ext_bus_device_remove(ebus);
741
728 skl_platform_unregister(&pci->dev); 742 skl_platform_unregister(&pci->dev);
729 skl_free_dsp(skl); 743 skl_free_dsp(skl);
730 skl_machine_device_unregister(skl); 744 skl_machine_device_unregister(skl);
diff --git a/sound/soc/soc-dapm.c b/sound/soc/soc-dapm.c
index 801ae1a81dfd..c4464858bf01 100644
--- a/sound/soc/soc-dapm.c
+++ b/sound/soc/soc-dapm.c
@@ -2188,6 +2188,13 @@ static ssize_t dapm_widget_show_component(struct snd_soc_component *cmpnt,
2188 int count = 0; 2188 int count = 0;
2189 char *state = "not set"; 2189 char *state = "not set";
2190 2190
2191 /* card won't be set for the dummy component, as a spot fix
2192 * we're checking for that case specifically here but in future
2193 * we will ensure that the dummy component looks like others.
2194 */
2195 if (!cmpnt->card)
2196 return 0;
2197
2191 list_for_each_entry(w, &cmpnt->card->widgets, list) { 2198 list_for_each_entry(w, &cmpnt->card->widgets, list) {
2192 if (w->dapm != dapm) 2199 if (w->dapm != dapm)
2193 continue; 2200 continue;
diff --git a/sound/usb/Kconfig b/sound/usb/Kconfig
index d14bf411515b..a452ad7cec40 100644
--- a/sound/usb/Kconfig
+++ b/sound/usb/Kconfig
@@ -15,7 +15,6 @@ config SND_USB_AUDIO
15 select SND_RAWMIDI 15 select SND_RAWMIDI
16 select SND_PCM 16 select SND_PCM
17 select BITREVERSE 17 select BITREVERSE
18 select SND_USB_AUDIO_USE_MEDIA_CONTROLLER if MEDIA_CONTROLLER && (MEDIA_SUPPORT=y || MEDIA_SUPPORT=SND_USB_AUDIO)
19 help 18 help
20 Say Y here to include support for USB audio and USB MIDI 19 Say Y here to include support for USB audio and USB MIDI
21 devices. 20 devices.
@@ -23,9 +22,6 @@ config SND_USB_AUDIO
23 To compile this driver as a module, choose M here: the module 22 To compile this driver as a module, choose M here: the module
24 will be called snd-usb-audio. 23 will be called snd-usb-audio.
25 24
26config SND_USB_AUDIO_USE_MEDIA_CONTROLLER
27 bool
28
29config SND_USB_UA101 25config SND_USB_UA101
30 tristate "Edirol UA-101/UA-1000 driver" 26 tristate "Edirol UA-101/UA-1000 driver"
31 select SND_PCM 27 select SND_PCM
diff --git a/sound/usb/Makefile b/sound/usb/Makefile
index 8dca3c407f5a..2d2d122b069f 100644
--- a/sound/usb/Makefile
+++ b/sound/usb/Makefile
@@ -15,8 +15,6 @@ snd-usb-audio-objs := card.o \
15 quirks.o \ 15 quirks.o \
16 stream.o 16 stream.o
17 17
18snd-usb-audio-$(CONFIG_SND_USB_AUDIO_USE_MEDIA_CONTROLLER) += media.o
19
20snd-usbmidi-lib-objs := midi.o 18snd-usbmidi-lib-objs := midi.o
21 19
22# Toplevel Module Dependency 20# Toplevel Module Dependency
diff --git a/sound/usb/card.c b/sound/usb/card.c
index c4665dc606ca..69860da473ea 100644
--- a/sound/usb/card.c
+++ b/sound/usb/card.c
@@ -66,7 +66,6 @@
66#include "format.h" 66#include "format.h"
67#include "power.h" 67#include "power.h"
68#include "stream.h" 68#include "stream.h"
69#include "media.h"
70 69
71MODULE_AUTHOR("Takashi Iwai <tiwai@suse.de>"); 70MODULE_AUTHOR("Takashi Iwai <tiwai@suse.de>");
72MODULE_DESCRIPTION("USB Audio"); 71MODULE_DESCRIPTION("USB Audio");
@@ -616,11 +615,6 @@ static int usb_audio_probe(struct usb_interface *intf,
616 if (err < 0) 615 if (err < 0)
617 goto __error; 616 goto __error;
618 617
619 if (quirk->media_device) {
620 /* don't want to fail when media_snd_device_create() fails */
621 media_snd_device_create(chip, intf);
622 }
623
624 usb_chip[chip->index] = chip; 618 usb_chip[chip->index] = chip;
625 chip->num_interfaces++; 619 chip->num_interfaces++;
626 usb_set_intfdata(intf, chip); 620 usb_set_intfdata(intf, chip);
@@ -677,14 +671,6 @@ static void usb_audio_disconnect(struct usb_interface *intf)
677 list_for_each(p, &chip->midi_list) { 671 list_for_each(p, &chip->midi_list) {
678 snd_usbmidi_disconnect(p); 672 snd_usbmidi_disconnect(p);
679 } 673 }
680 /*
681 * Nice to check quirk && quirk->media_device
682 * need some special handlings. Doesn't look like
683 * we have access to quirk here
684 * Acceses mixer_list
685 */
686 media_snd_device_delete(chip);
687
688 /* release mixer resources */ 674 /* release mixer resources */
689 list_for_each_entry(mixer, &chip->mixer_list, list) { 675 list_for_each_entry(mixer, &chip->mixer_list, list) {
690 snd_usb_mixer_disconnect(mixer); 676 snd_usb_mixer_disconnect(mixer);
diff --git a/sound/usb/card.h b/sound/usb/card.h
index 34a0898e2238..71778ca4b26a 100644
--- a/sound/usb/card.h
+++ b/sound/usb/card.h
@@ -105,8 +105,6 @@ struct snd_usb_endpoint {
105 struct list_head list; 105 struct list_head list;
106}; 106};
107 107
108struct media_ctl;
109
110struct snd_usb_substream { 108struct snd_usb_substream {
111 struct snd_usb_stream *stream; 109 struct snd_usb_stream *stream;
112 struct usb_device *dev; 110 struct usb_device *dev;
@@ -158,7 +156,6 @@ struct snd_usb_substream {
158 } dsd_dop; 156 } dsd_dop;
159 157
160 bool trigger_tstamp_pending_update; /* trigger timestamp being updated from initial estimate */ 158 bool trigger_tstamp_pending_update; /* trigger timestamp being updated from initial estimate */
161 struct media_ctl *media_ctl;
162}; 159};
163 160
164struct snd_usb_stream { 161struct snd_usb_stream {
diff --git a/sound/usb/media.c b/sound/usb/media.c
deleted file mode 100644
index 93a50d01490c..000000000000
--- a/sound/usb/media.c
+++ /dev/null
@@ -1,318 +0,0 @@
1/*
2 * media.c - Media Controller specific ALSA driver code
3 *
4 * Copyright (c) 2016 Shuah Khan <shuahkh@osg.samsung.com>
5 * Copyright (c) 2016 Samsung Electronics Co., Ltd.
6 *
7 * This file is released under the GPLv2.
8 */
9
10/*
11 * This file adds Media Controller support to ALSA driver
12 * to use the Media Controller API to share tuner with DVB
13 * and V4L2 drivers that control media device. Media device
14 * is created based on existing quirks framework. Using this
15 * approach, the media controller API usage can be added for
16 * a specific device.
17*/
18
19#include <linux/init.h>
20#include <linux/list.h>
21#include <linux/mutex.h>
22#include <linux/slab.h>
23#include <linux/usb.h>
24
25#include <sound/pcm.h>
26#include <sound/core.h>
27
28#include "usbaudio.h"
29#include "card.h"
30#include "mixer.h"
31#include "media.h"
32
33static int media_snd_enable_source(struct media_ctl *mctl)
34{
35 if (mctl && mctl->media_dev->enable_source)
36 return mctl->media_dev->enable_source(&mctl->media_entity,
37 &mctl->media_pipe);
38 return 0;
39}
40
41static void media_snd_disable_source(struct media_ctl *mctl)
42{
43 if (mctl && mctl->media_dev->disable_source)
44 mctl->media_dev->disable_source(&mctl->media_entity);
45}
46
47int media_snd_stream_init(struct snd_usb_substream *subs, struct snd_pcm *pcm,
48 int stream)
49{
50 struct media_device *mdev;
51 struct media_ctl *mctl;
52 struct device *pcm_dev = &pcm->streams[stream].dev;
53 u32 intf_type;
54 int ret = 0;
55 u16 mixer_pad;
56 struct media_entity *entity;
57
58 mdev = subs->stream->chip->media_dev;
59 if (!mdev)
60 return -ENODEV;
61
62 if (subs->media_ctl)
63 return 0;
64
65 /* allocate media_ctl */
66 mctl = kzalloc(sizeof(*mctl), GFP_KERNEL);
67 if (!mctl)
68 return -ENOMEM;
69
70 mctl->media_dev = mdev;
71 if (stream == SNDRV_PCM_STREAM_PLAYBACK) {
72 intf_type = MEDIA_INTF_T_ALSA_PCM_PLAYBACK;
73 mctl->media_entity.function = MEDIA_ENT_F_AUDIO_PLAYBACK;
74 mctl->media_pad.flags = MEDIA_PAD_FL_SOURCE;
75 mixer_pad = 1;
76 } else {
77 intf_type = MEDIA_INTF_T_ALSA_PCM_CAPTURE;
78 mctl->media_entity.function = MEDIA_ENT_F_AUDIO_CAPTURE;
79 mctl->media_pad.flags = MEDIA_PAD_FL_SINK;
80 mixer_pad = 2;
81 }
82 mctl->media_entity.name = pcm->name;
83 media_entity_pads_init(&mctl->media_entity, 1, &mctl->media_pad);
84 ret = media_device_register_entity(mctl->media_dev,
85 &mctl->media_entity);
86 if (ret)
87 goto free_mctl;
88
89 mctl->intf_devnode = media_devnode_create(mdev, intf_type, 0,
90 MAJOR(pcm_dev->devt),
91 MINOR(pcm_dev->devt));
92 if (!mctl->intf_devnode) {
93 ret = -ENOMEM;
94 goto unregister_entity;
95 }
96 mctl->intf_link = media_create_intf_link(&mctl->media_entity,
97 &mctl->intf_devnode->intf,
98 MEDIA_LNK_FL_ENABLED);
99 if (!mctl->intf_link) {
100 ret = -ENOMEM;
101 goto devnode_remove;
102 }
103
104 /* create link between mixer and audio */
105 media_device_for_each_entity(entity, mdev) {
106 switch (entity->function) {
107 case MEDIA_ENT_F_AUDIO_MIXER:
108 ret = media_create_pad_link(entity, mixer_pad,
109 &mctl->media_entity, 0,
110 MEDIA_LNK_FL_ENABLED);
111 if (ret)
112 goto remove_intf_link;
113 break;
114 }
115 }
116
117 subs->media_ctl = mctl;
118 return 0;
119
120remove_intf_link:
121 media_remove_intf_link(mctl->intf_link);
122devnode_remove:
123 media_devnode_remove(mctl->intf_devnode);
124unregister_entity:
125 media_device_unregister_entity(&mctl->media_entity);
126free_mctl:
127 kfree(mctl);
128 return ret;
129}
130
131void media_snd_stream_delete(struct snd_usb_substream *subs)
132{
133 struct media_ctl *mctl = subs->media_ctl;
134
135 if (mctl && mctl->media_dev) {
136 struct media_device *mdev;
137
138 mdev = subs->stream->chip->media_dev;
139 if (mdev && media_devnode_is_registered(&mdev->devnode)) {
140 media_devnode_remove(mctl->intf_devnode);
141 media_device_unregister_entity(&mctl->media_entity);
142 media_entity_cleanup(&mctl->media_entity);
143 }
144 kfree(mctl);
145 subs->media_ctl = NULL;
146 }
147}
148
149int media_snd_start_pipeline(struct snd_usb_substream *subs)
150{
151 struct media_ctl *mctl = subs->media_ctl;
152
153 if (mctl)
154 return media_snd_enable_source(mctl);
155 return 0;
156}
157
158void media_snd_stop_pipeline(struct snd_usb_substream *subs)
159{
160 struct media_ctl *mctl = subs->media_ctl;
161
162 if (mctl)
163 media_snd_disable_source(mctl);
164}
165
166int media_snd_mixer_init(struct snd_usb_audio *chip)
167{
168 struct device *ctl_dev = &chip->card->ctl_dev;
169 struct media_intf_devnode *ctl_intf;
170 struct usb_mixer_interface *mixer;
171 struct media_device *mdev = chip->media_dev;
172 struct media_mixer_ctl *mctl;
173 u32 intf_type = MEDIA_INTF_T_ALSA_CONTROL;
174 int ret;
175
176 if (!mdev)
177 return -ENODEV;
178
179 ctl_intf = chip->ctl_intf_media_devnode;
180 if (!ctl_intf) {
181 ctl_intf = media_devnode_create(mdev, intf_type, 0,
182 MAJOR(ctl_dev->devt),
183 MINOR(ctl_dev->devt));
184 if (!ctl_intf)
185 return -ENOMEM;
186 chip->ctl_intf_media_devnode = ctl_intf;
187 }
188
189 list_for_each_entry(mixer, &chip->mixer_list, list) {
190
191 if (mixer->media_mixer_ctl)
192 continue;
193
194 /* allocate media_mixer_ctl */
195 mctl = kzalloc(sizeof(*mctl), GFP_KERNEL);
196 if (!mctl)
197 return -ENOMEM;
198
199 mctl->media_dev = mdev;
200 mctl->media_entity.function = MEDIA_ENT_F_AUDIO_MIXER;
201 mctl->media_entity.name = chip->card->mixername;
202 mctl->media_pad[0].flags = MEDIA_PAD_FL_SINK;
203 mctl->media_pad[1].flags = MEDIA_PAD_FL_SOURCE;
204 mctl->media_pad[2].flags = MEDIA_PAD_FL_SOURCE;
205 media_entity_pads_init(&mctl->media_entity, MEDIA_MIXER_PAD_MAX,
206 mctl->media_pad);
207 ret = media_device_register_entity(mctl->media_dev,
208 &mctl->media_entity);
209 if (ret) {
210 kfree(mctl);
211 return ret;
212 }
213
214 mctl->intf_link = media_create_intf_link(&mctl->media_entity,
215 &ctl_intf->intf,
216 MEDIA_LNK_FL_ENABLED);
217 if (!mctl->intf_link) {
218 media_device_unregister_entity(&mctl->media_entity);
219 media_entity_cleanup(&mctl->media_entity);
220 kfree(mctl);
221 return -ENOMEM;
222 }
223 mctl->intf_devnode = ctl_intf;
224 mixer->media_mixer_ctl = mctl;
225 }
226 return 0;
227}
228
229static void media_snd_mixer_delete(struct snd_usb_audio *chip)
230{
231 struct usb_mixer_interface *mixer;
232 struct media_device *mdev = chip->media_dev;
233
234 if (!mdev)
235 return;
236
237 list_for_each_entry(mixer, &chip->mixer_list, list) {
238 struct media_mixer_ctl *mctl;
239
240 mctl = mixer->media_mixer_ctl;
241 if (!mixer->media_mixer_ctl)
242 continue;
243
244 if (media_devnode_is_registered(&mdev->devnode)) {
245 media_device_unregister_entity(&mctl->media_entity);
246 media_entity_cleanup(&mctl->media_entity);
247 }
248 kfree(mctl);
249 mixer->media_mixer_ctl = NULL;
250 }
251 if (media_devnode_is_registered(&mdev->devnode))
252 media_devnode_remove(chip->ctl_intf_media_devnode);
253 chip->ctl_intf_media_devnode = NULL;
254}
255
256int media_snd_device_create(struct snd_usb_audio *chip,
257 struct usb_interface *iface)
258{
259 struct media_device *mdev;
260 struct usb_device *usbdev = interface_to_usbdev(iface);
261 int ret;
262
263 mdev = media_device_get_devres(&usbdev->dev);
264 if (!mdev)
265 return -ENOMEM;
266 if (!mdev->dev) {
267 /* register media device */
268 mdev->dev = &usbdev->dev;
269 if (usbdev->product)
270 strlcpy(mdev->model, usbdev->product,
271 sizeof(mdev->model));
272 if (usbdev->serial)
273 strlcpy(mdev->serial, usbdev->serial,
274 sizeof(mdev->serial));
275 strcpy(mdev->bus_info, usbdev->devpath);
276 mdev->hw_revision = le16_to_cpu(usbdev->descriptor.bcdDevice);
277 media_device_init(mdev);
278 }
279 if (!media_devnode_is_registered(&mdev->devnode)) {
280 ret = media_device_register(mdev);
281 if (ret) {
282 dev_err(&usbdev->dev,
283 "Couldn't register media device. Error: %d\n",
284 ret);
285 return ret;
286 }
287 }
288
289 /* save media device - avoid lookups */
290 chip->media_dev = mdev;
291
292 /* Create media entities for mixer and control dev */
293 ret = media_snd_mixer_init(chip);
294 if (ret) {
295 dev_err(&usbdev->dev,
296 "Couldn't create media mixer entities. Error: %d\n",
297 ret);
298
299 /* clear saved media_dev */
300 chip->media_dev = NULL;
301
302 return ret;
303 }
304 return 0;
305}
306
307void media_snd_device_delete(struct snd_usb_audio *chip)
308{
309 struct media_device *mdev = chip->media_dev;
310
311 media_snd_mixer_delete(chip);
312
313 if (mdev) {
314 if (media_devnode_is_registered(&mdev->devnode))
315 media_device_unregister(mdev);
316 chip->media_dev = NULL;
317 }
318}
diff --git a/sound/usb/media.h b/sound/usb/media.h
deleted file mode 100644
index 1dcdcdc5f7aa..000000000000
--- a/sound/usb/media.h
+++ /dev/null
@@ -1,72 +0,0 @@
1/*
2 * media.h - Media Controller specific ALSA driver code
3 *
4 * Copyright (c) 2016 Shuah Khan <shuahkh@osg.samsung.com>
5 * Copyright (c) 2016 Samsung Electronics Co., Ltd.
6 *
7 * This file is released under the GPLv2.
8 */
9
10/*
11 * This file adds Media Controller support to ALSA driver
12 * to use the Media Controller API to share tuner with DVB
13 * and V4L2 drivers that control media device. Media device
14 * is created based on existing quirks framework. Using this
15 * approach, the media controller API usage can be added for
16 * a specific device.
17*/
18#ifndef __MEDIA_H
19
20#ifdef CONFIG_SND_USB_AUDIO_USE_MEDIA_CONTROLLER
21
22#include <media/media-device.h>
23#include <media/media-entity.h>
24#include <sound/asound.h>
25
26struct media_ctl {
27 struct media_device *media_dev;
28 struct media_entity media_entity;
29 struct media_intf_devnode *intf_devnode;
30 struct media_link *intf_link;
31 struct media_pad media_pad;
32 struct media_pipeline media_pipe;
33};
34
35/*
36 * One source pad each for SNDRV_PCM_STREAM_CAPTURE and
37 * SNDRV_PCM_STREAM_PLAYBACK. One for sink pad to link
38 * to AUDIO Source
39*/
40#define MEDIA_MIXER_PAD_MAX (SNDRV_PCM_STREAM_LAST + 2)
41
42struct media_mixer_ctl {
43 struct media_device *media_dev;
44 struct media_entity media_entity;
45 struct media_intf_devnode *intf_devnode;
46 struct media_link *intf_link;
47 struct media_pad media_pad[MEDIA_MIXER_PAD_MAX];
48 struct media_pipeline media_pipe;
49};
50
51int media_snd_device_create(struct snd_usb_audio *chip,
52 struct usb_interface *iface);
53void media_snd_device_delete(struct snd_usb_audio *chip);
54int media_snd_stream_init(struct snd_usb_substream *subs, struct snd_pcm *pcm,
55 int stream);
56void media_snd_stream_delete(struct snd_usb_substream *subs);
57int media_snd_start_pipeline(struct snd_usb_substream *subs);
58void media_snd_stop_pipeline(struct snd_usb_substream *subs);
59#else
60static inline int media_snd_device_create(struct snd_usb_audio *chip,
61 struct usb_interface *iface)
62 { return 0; }
63static inline void media_snd_device_delete(struct snd_usb_audio *chip) { }
64static inline int media_snd_stream_init(struct snd_usb_substream *subs,
65 struct snd_pcm *pcm, int stream)
66 { return 0; }
67static inline void media_snd_stream_delete(struct snd_usb_substream *subs) { }
68static inline int media_snd_start_pipeline(struct snd_usb_substream *subs)
69 { return 0; }
70static inline void media_snd_stop_pipeline(struct snd_usb_substream *subs) { }
71#endif
72#endif /* __MEDIA_H */
diff --git a/sound/usb/mixer.h b/sound/usb/mixer.h
index f3789446ab9c..3417ef347e40 100644
--- a/sound/usb/mixer.h
+++ b/sound/usb/mixer.h
@@ -3,8 +3,6 @@
3 3
4#include <sound/info.h> 4#include <sound/info.h>
5 5
6struct media_mixer_ctl;
7
8struct usb_mixer_interface { 6struct usb_mixer_interface {
9 struct snd_usb_audio *chip; 7 struct snd_usb_audio *chip;
10 struct usb_host_interface *hostif; 8 struct usb_host_interface *hostif;
@@ -24,7 +22,6 @@ struct usb_mixer_interface {
24 struct urb *rc_urb; 22 struct urb *rc_urb;
25 struct usb_ctrlrequest *rc_setup_packet; 23 struct usb_ctrlrequest *rc_setup_packet;
26 u8 rc_buffer[6]; 24 u8 rc_buffer[6];
27 struct media_mixer_ctl *media_mixer_ctl;
28}; 25};
29 26
30#define MAX_CHANNELS 16 /* max logical channels */ 27#define MAX_CHANNELS 16 /* max logical channels */
diff --git a/sound/usb/pcm.c b/sound/usb/pcm.c
index 0e4e0640c504..44d178ee9177 100644
--- a/sound/usb/pcm.c
+++ b/sound/usb/pcm.c
@@ -35,7 +35,6 @@
35#include "pcm.h" 35#include "pcm.h"
36#include "clock.h" 36#include "clock.h"
37#include "power.h" 37#include "power.h"
38#include "media.h"
39 38
40#define SUBSTREAM_FLAG_DATA_EP_STARTED 0 39#define SUBSTREAM_FLAG_DATA_EP_STARTED 0
41#define SUBSTREAM_FLAG_SYNC_EP_STARTED 1 40#define SUBSTREAM_FLAG_SYNC_EP_STARTED 1
@@ -718,14 +717,10 @@ static int snd_usb_hw_params(struct snd_pcm_substream *substream,
718 struct audioformat *fmt; 717 struct audioformat *fmt;
719 int ret; 718 int ret;
720 719
721 ret = media_snd_start_pipeline(subs);
722 if (ret)
723 return ret;
724
725 ret = snd_pcm_lib_alloc_vmalloc_buffer(substream, 720 ret = snd_pcm_lib_alloc_vmalloc_buffer(substream,
726 params_buffer_bytes(hw_params)); 721 params_buffer_bytes(hw_params));
727 if (ret < 0) 722 if (ret < 0)
728 goto err_ret; 723 return ret;
729 724
730 subs->pcm_format = params_format(hw_params); 725 subs->pcm_format = params_format(hw_params);
731 subs->period_bytes = params_period_bytes(hw_params); 726 subs->period_bytes = params_period_bytes(hw_params);
@@ -739,27 +734,22 @@ static int snd_usb_hw_params(struct snd_pcm_substream *substream,
739 dev_dbg(&subs->dev->dev, 734 dev_dbg(&subs->dev->dev,
740 "cannot set format: format = %#x, rate = %d, channels = %d\n", 735 "cannot set format: format = %#x, rate = %d, channels = %d\n",
741 subs->pcm_format, subs->cur_rate, subs->channels); 736 subs->pcm_format, subs->cur_rate, subs->channels);
742 ret = -EINVAL; 737 return -EINVAL;
743 goto err_ret;
744 } 738 }
745 739
746 ret = snd_usb_lock_shutdown(subs->stream->chip); 740 ret = snd_usb_lock_shutdown(subs->stream->chip);
747 if (ret < 0) 741 if (ret < 0)
748 goto err_ret; 742 return ret;
749 ret = set_format(subs, fmt); 743 ret = set_format(subs, fmt);
750 snd_usb_unlock_shutdown(subs->stream->chip); 744 snd_usb_unlock_shutdown(subs->stream->chip);
751 if (ret < 0) 745 if (ret < 0)
752 goto err_ret; 746 return ret;
753 747
754 subs->interface = fmt->iface; 748 subs->interface = fmt->iface;
755 subs->altset_idx = fmt->altset_idx; 749 subs->altset_idx = fmt->altset_idx;
756 subs->need_setup_ep = true; 750 subs->need_setup_ep = true;
757 751
758 return 0; 752 return 0;
759
760err_ret:
761 media_snd_stop_pipeline(subs);
762 return ret;
763} 753}
764 754
765/* 755/*
@@ -771,7 +761,6 @@ static int snd_usb_hw_free(struct snd_pcm_substream *substream)
771{ 761{
772 struct snd_usb_substream *subs = substream->runtime->private_data; 762 struct snd_usb_substream *subs = substream->runtime->private_data;
773 763
774 media_snd_stop_pipeline(subs);
775 subs->cur_audiofmt = NULL; 764 subs->cur_audiofmt = NULL;
776 subs->cur_rate = 0; 765 subs->cur_rate = 0;
777 subs->period_bytes = 0; 766 subs->period_bytes = 0;
@@ -1232,7 +1221,6 @@ static int snd_usb_pcm_open(struct snd_pcm_substream *substream, int direction)
1232 struct snd_usb_stream *as = snd_pcm_substream_chip(substream); 1221 struct snd_usb_stream *as = snd_pcm_substream_chip(substream);
1233 struct snd_pcm_runtime *runtime = substream->runtime; 1222 struct snd_pcm_runtime *runtime = substream->runtime;
1234 struct snd_usb_substream *subs = &as->substream[direction]; 1223 struct snd_usb_substream *subs = &as->substream[direction];
1235 int ret;
1236 1224
1237 subs->interface = -1; 1225 subs->interface = -1;
1238 subs->altset_idx = 0; 1226 subs->altset_idx = 0;
@@ -1246,12 +1234,7 @@ static int snd_usb_pcm_open(struct snd_pcm_substream *substream, int direction)
1246 subs->dsd_dop.channel = 0; 1234 subs->dsd_dop.channel = 0;
1247 subs->dsd_dop.marker = 1; 1235 subs->dsd_dop.marker = 1;
1248 1236
1249 ret = setup_hw_info(runtime, subs); 1237 return setup_hw_info(runtime, subs);
1250 if (ret == 0)
1251 ret = media_snd_stream_init(subs, as->pcm, direction);
1252 if (ret)
1253 snd_usb_autosuspend(subs->stream->chip);
1254 return ret;
1255} 1238}
1256 1239
1257static int snd_usb_pcm_close(struct snd_pcm_substream *substream, int direction) 1240static int snd_usb_pcm_close(struct snd_pcm_substream *substream, int direction)
@@ -1260,7 +1243,6 @@ static int snd_usb_pcm_close(struct snd_pcm_substream *substream, int direction)
1260 struct snd_usb_substream *subs = &as->substream[direction]; 1243 struct snd_usb_substream *subs = &as->substream[direction];
1261 1244
1262 stop_endpoints(subs, true); 1245 stop_endpoints(subs, true);
1263 media_snd_stop_pipeline(subs);
1264 1246
1265 if (subs->interface >= 0 && 1247 if (subs->interface >= 0 &&
1266 !snd_usb_lock_shutdown(subs->stream->chip)) { 1248 !snd_usb_lock_shutdown(subs->stream->chip)) {
diff --git a/sound/usb/quirks-table.h b/sound/usb/quirks-table.h
index 9d087b19c70c..c60a776e815d 100644
--- a/sound/usb/quirks-table.h
+++ b/sound/usb/quirks-table.h
@@ -2886,7 +2886,6 @@ YAMAHA_DEVICE(0x7010, "UB99"),
2886 .product_name = pname, \ 2886 .product_name = pname, \
2887 .ifnum = QUIRK_ANY_INTERFACE, \ 2887 .ifnum = QUIRK_ANY_INTERFACE, \
2888 .type = QUIRK_AUDIO_ALIGN_TRANSFER, \ 2888 .type = QUIRK_AUDIO_ALIGN_TRANSFER, \
2889 .media_device = 1, \
2890 } \ 2889 } \
2891} 2890}
2892 2891
diff --git a/sound/usb/quirks.c b/sound/usb/quirks.c
index 0adfd9537cf7..7b6dca2d7488 100644
--- a/sound/usb/quirks.c
+++ b/sound/usb/quirks.c
@@ -1138,7 +1138,9 @@ bool snd_usb_get_sample_rate_quirk(struct snd_usb_audio *chip)
1138 case USB_ID(0x047F, 0xAA05): /* Plantronics DA45 */ 1138 case USB_ID(0x047F, 0xAA05): /* Plantronics DA45 */
1139 case USB_ID(0x04D8, 0xFEEA): /* Benchmark DAC1 Pre */ 1139 case USB_ID(0x04D8, 0xFEEA): /* Benchmark DAC1 Pre */
1140 case USB_ID(0x074D, 0x3553): /* Outlaw RR2150 (Micronas UAC3553B) */ 1140 case USB_ID(0x074D, 0x3553): /* Outlaw RR2150 (Micronas UAC3553B) */
1141 case USB_ID(0x1de7, 0x0013): /* Phoenix Audio MT202exe */
1141 case USB_ID(0x1de7, 0x0014): /* Phoenix Audio TMX320 */ 1142 case USB_ID(0x1de7, 0x0014): /* Phoenix Audio TMX320 */
1143 case USB_ID(0x1de7, 0x0114): /* Phoenix Audio MT202pcs */
1142 case USB_ID(0x21B4, 0x0081): /* AudioQuest DragonFly */ 1144 case USB_ID(0x21B4, 0x0081): /* AudioQuest DragonFly */
1143 return true; 1145 return true;
1144 } 1146 }
diff --git a/sound/usb/stream.c b/sound/usb/stream.c
index 6fe7f210bd4e..8e9548bc1f1a 100644
--- a/sound/usb/stream.c
+++ b/sound/usb/stream.c
@@ -36,7 +36,6 @@
36#include "format.h" 36#include "format.h"
37#include "clock.h" 37#include "clock.h"
38#include "stream.h" 38#include "stream.h"
39#include "media.h"
40 39
41/* 40/*
42 * free a substream 41 * free a substream
@@ -53,7 +52,6 @@ static void free_substream(struct snd_usb_substream *subs)
53 kfree(fp); 52 kfree(fp);
54 } 53 }
55 kfree(subs->rate_list.list); 54 kfree(subs->rate_list.list);
56 media_snd_stream_delete(subs);
57} 55}
58 56
59 57
diff --git a/sound/usb/usbaudio.h b/sound/usb/usbaudio.h
index 89b6853030de..4d5c89a7ba2b 100644
--- a/sound/usb/usbaudio.h
+++ b/sound/usb/usbaudio.h
@@ -30,9 +30,6 @@
30 * 30 *
31 */ 31 */
32 32
33struct media_device;
34struct media_intf_devnode;
35
36struct snd_usb_audio { 33struct snd_usb_audio {
37 int index; 34 int index;
38 struct usb_device *dev; 35 struct usb_device *dev;
@@ -64,8 +61,6 @@ struct snd_usb_audio {
64 bool autoclock; /* from the 'autoclock' module param */ 61 bool autoclock; /* from the 'autoclock' module param */
65 62
66 struct usb_host_interface *ctrl_intf; /* the audio control interface */ 63 struct usb_host_interface *ctrl_intf; /* the audio control interface */
67 struct media_device *media_dev;
68 struct media_intf_devnode *ctl_intf_media_devnode;
69}; 64};
70 65
71#define usb_audio_err(chip, fmt, args...) \ 66#define usb_audio_err(chip, fmt, args...) \
@@ -116,7 +111,6 @@ struct snd_usb_audio_quirk {
116 const char *product_name; 111 const char *product_name;
117 int16_t ifnum; 112 int16_t ifnum;
118 uint16_t type; 113 uint16_t type;
119 bool media_device;
120 const void *data; 114 const void *data;
121}; 115};
122 116