hc
2023-12-08 01573e231f18eb2d99162747186f59511f56b64d
kernel/sound/soc/codecs/hdac_hdmi.c
....@@ -1,3 +1,4 @@
1
+// SPDX-License-Identifier: GPL-2.0-only
12 /*
23 * hdac_hdmi.c - ASoc HDA-HDMI codec driver for Intel platforms
34 *
....@@ -6,17 +7,9 @@
67 * Subhransu S. Prusty <subhransu.s.prusty@intel.com>
78 * ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
89 *
9
- * This program is free software; you can redistribute it and/or modify
10
- * it under the terms of the GNU General Public License as published by
11
- * the Free Software Foundation; version 2 of the License.
12
- *
13
- * This program is distributed in the hope that it will be useful, but
14
- * WITHOUT ANY WARRANTY; without even the implied warranty of
15
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
16
- * General Public License for more details.
17
- *
1810 * ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
1911 */
12
+
2013 #include <linux/init.h>
2114 #include <linux/delay.h>
2215 #include <linux/module.h>
....@@ -96,8 +89,10 @@
9689 hda_nid_t mux_nids[HDA_MAX_CONNECTIONS];
9790 struct hdac_hdmi_eld eld;
9891 const char *jack_pin;
92
+ bool is_connect;
9993 struct snd_soc_dapm_context *dapm;
10094 const char *output_pin;
95
+ struct work_struct dapm_work;
10196 };
10297
10398 struct hdac_hdmi_pcm {
....@@ -113,6 +108,7 @@
113108 unsigned char chmap[8]; /* ALSA API channel-map */
114109 struct mutex lock;
115110 int jack_event;
111
+ struct snd_kcontrol *eld_ctl;
116112 };
117113
118114 struct hdac_hdmi_dai_port_map {
....@@ -163,11 +159,7 @@
163159 {
164160 struct hdac_device *hdev = port->pin->hdev;
165161
166
- if (is_connect)
167
- snd_soc_dapm_enable_pin(port->dapm, port->jack_pin);
168
- else
169
- snd_soc_dapm_disable_pin(port->dapm, port->jack_pin);
170
-
162
+ port->is_connect = is_connect;
171163 if (is_connect) {
172164 /*
173165 * Report Jack connect event when a device is connected
....@@ -193,8 +185,30 @@
193185 if (pcm->jack_event > 0)
194186 pcm->jack_event--;
195187 }
188
+}
196189
190
+static void hdac_hdmi_port_dapm_update(struct hdac_hdmi_port *port)
191
+{
192
+ if (port->is_connect)
193
+ snd_soc_dapm_enable_pin(port->dapm, port->jack_pin);
194
+ else
195
+ snd_soc_dapm_disable_pin(port->dapm, port->jack_pin);
197196 snd_soc_dapm_sync(port->dapm);
197
+}
198
+
199
+static void hdac_hdmi_jack_dapm_work(struct work_struct *work)
200
+{
201
+ struct hdac_hdmi_port *port;
202
+
203
+ port = container_of(work, struct hdac_hdmi_port, dapm_work);
204
+ hdac_hdmi_port_dapm_update(port);
205
+}
206
+
207
+static void hdac_hdmi_jack_report_sync(struct hdac_hdmi_pcm *pcm,
208
+ struct hdac_hdmi_port *port, bool is_connect)
209
+{
210
+ hdac_hdmi_jack_report(pcm, port, is_connect);
211
+ hdac_hdmi_port_dapm_update(port);
198212 }
199213
200214 /* MST supported verbs */
....@@ -447,24 +461,11 @@
447461 struct snd_pcm_hw_params *hparams, struct snd_soc_dai *dai)
448462 {
449463 struct hdac_hdmi_priv *hdmi = snd_soc_dai_get_drvdata(dai);
450
- struct hdac_device *hdev = hdmi->hdev;
451464 struct hdac_hdmi_dai_port_map *dai_map;
452
- struct hdac_hdmi_port *port;
453465 struct hdac_hdmi_pcm *pcm;
454466 int format;
455467
456468 dai_map = &hdmi->dai_map[dai->id];
457
- port = dai_map->port;
458
-
459
- if (!port)
460
- return -ENODEV;
461
-
462
- if ((!port->eld.monitor_present) || (!port->eld.eld_valid)) {
463
- dev_err(&hdev->dev,
464
- "device is not configured for this pin:port%d:%d\n",
465
- port->pin->nid, port->id);
466
- return -ENODEV;
467
- }
468469
469470 format = snd_hdac_calc_stream_format(params_rate(hparams),
470471 params_channels(hparams), params_format(hparams),
....@@ -549,6 +550,29 @@
549550 }
550551
551552 return NULL;
553
+}
554
+
555
+/*
556
+ * Go through all converters and ensure connection is set to
557
+ * the correct pin as set via kcontrols.
558
+ */
559
+static void hdac_hdmi_verify_connect_sel_all_pins(struct hdac_device *hdev)
560
+{
561
+ struct hdac_hdmi_priv *hdmi = hdev_to_hdmi_priv(hdev);
562
+ struct hdac_hdmi_port *port;
563
+ struct hdac_hdmi_cvt *cvt;
564
+ int cvt_idx = 0;
565
+
566
+ list_for_each_entry(cvt, &hdmi->cvt_list, head) {
567
+ port = hdac_hdmi_get_port_from_cvt(hdev, hdmi, cvt);
568
+ if (port && port->pin) {
569
+ snd_hdac_codec_write(hdev, port->pin->nid, 0,
570
+ AC_VERB_SET_CONNECT_SEL, cvt_idx);
571
+ dev_dbg(&hdev->dev, "%s: %s set connect %d -> %d\n",
572
+ __func__, cvt->name, port->pin->nid, cvt_idx);
573
+ }
574
+ ++cvt_idx;
575
+ }
552576 }
553577
554578 /*
....@@ -811,6 +835,14 @@
811835 AC_VERB_SET_CHANNEL_STREAMID, pcm->stream_tag);
812836 snd_hdac_codec_write(hdev, cvt->nid, 0,
813837 AC_VERB_SET_STREAM_FORMAT, pcm->format);
838
+
839
+ /*
840
+ * The connection indices are shared by all converters and
841
+ * may interfere with each other. Ensure correct
842
+ * routing for all converters at stream start.
843
+ */
844
+ hdac_hdmi_verify_connect_sel_all_pins(hdev);
845
+
814846 break;
815847
816848 case SND_SOC_DAPM_POST_PMD:
....@@ -886,7 +918,7 @@
886918 list_for_each_entry_safe(p, p_next, &pcm->port_list, head) {
887919 if (p == port && p->id == port->id &&
888920 p->pin == port->pin) {
889
- hdac_hdmi_jack_report(pcm, port, false);
921
+ hdac_hdmi_jack_report_sync(pcm, port, false);
890922 list_del(&p->head);
891923 }
892924 }
....@@ -900,7 +932,7 @@
900932 if (!strcmp(cvt_name, pcm->cvt->name)) {
901933 list_add_tail(&port->head, &pcm->port_list);
902934 if (port->eld.monitor_present && port->eld.eld_valid) {
903
- hdac_hdmi_jack_report(pcm, port, true);
935
+ hdac_hdmi_jack_report_sync(pcm, port, true);
904936 mutex_unlock(&hdmi->pin_mutex);
905937 return ret;
906938 }
....@@ -1168,13 +1200,15 @@
11681200 struct hdac_hdmi_cvt *cvt;
11691201 char name[NAME_SIZE];
11701202
1171
- cvt = kzalloc(sizeof(*cvt), GFP_KERNEL);
1203
+ cvt = devm_kzalloc(&hdev->dev, sizeof(*cvt), GFP_KERNEL);
11721204 if (!cvt)
11731205 return -ENOMEM;
11741206
11751207 cvt->nid = nid;
11761208 sprintf(name, "cvt %d", cvt->nid);
1177
- cvt->name = kstrdup(name, GFP_KERNEL);
1209
+ cvt->name = devm_kstrdup(&hdev->dev, name, GFP_KERNEL);
1210
+ if (!cvt->name)
1211
+ return -ENOMEM;
11781212
11791213 list_add_tail(&cvt->head, &hdmi->cvt_list);
11801214 hdmi->num_cvt++;
....@@ -1216,6 +1250,7 @@
12161250 struct hdac_hdmi_pcm *pcm;
12171251 int size = 0;
12181252 int port_id = -1;
1253
+ bool eld_valid, eld_changed;
12191254
12201255 if (!hdmi)
12211256 return;
....@@ -1241,6 +1276,8 @@
12411276 size = -EINVAL;
12421277 }
12431278
1279
+ eld_valid = port->eld.eld_valid;
1280
+
12441281 if (size > 0) {
12451282 port->eld.eld_valid = true;
12461283 port->eld.eld_size = size;
....@@ -1248,6 +1285,8 @@
12481285 port->eld.eld_valid = false;
12491286 port->eld.eld_size = 0;
12501287 }
1288
+
1289
+ eld_changed = (eld_valid != port->eld.eld_valid);
12511290
12521291 pcm = hdac_hdmi_get_pcm(hdev, port);
12531292
....@@ -1261,26 +1300,36 @@
12611300 * report jack here. It will be done in usermode mux
12621301 * control select.
12631302 */
1264
- if (pcm)
1303
+ if (pcm) {
12651304 hdac_hdmi_jack_report(pcm, port, false);
1305
+ schedule_work(&port->dapm_work);
1306
+ }
12661307
12671308 mutex_unlock(&hdmi->pin_mutex);
12681309 return;
12691310 }
12701311
12711312 if (port->eld.monitor_present && port->eld.eld_valid) {
1272
- if (pcm)
1313
+ if (pcm) {
12731314 hdac_hdmi_jack_report(pcm, port, true);
1315
+ schedule_work(&port->dapm_work);
1316
+ }
12741317
12751318 print_hex_dump_debug("ELD: ", DUMP_PREFIX_OFFSET, 16, 1,
12761319 port->eld.eld_buffer, port->eld.eld_size, false);
12771320
12781321 }
12791322 mutex_unlock(&hdmi->pin_mutex);
1323
+
1324
+ if (eld_changed && pcm)
1325
+ snd_ctl_notify(hdmi->card,
1326
+ SNDRV_CTL_EVENT_MASK_VALUE |
1327
+ SNDRV_CTL_EVENT_MASK_INFO,
1328
+ &pcm->eld_ctl->id);
12801329 }
12811330
1282
-static int hdac_hdmi_add_ports(struct hdac_hdmi_priv *hdmi,
1283
- struct hdac_hdmi_pin *pin)
1331
+static int hdac_hdmi_add_ports(struct hdac_device *hdev,
1332
+ struct hdac_hdmi_pin *pin)
12841333 {
12851334 struct hdac_hdmi_port *ports;
12861335 int max_ports = HDA_MAX_PORTS;
....@@ -1292,13 +1341,14 @@
12921341 * implemented.
12931342 */
12941343
1295
- ports = kcalloc(max_ports, sizeof(*ports), GFP_KERNEL);
1344
+ ports = devm_kcalloc(&hdev->dev, max_ports, sizeof(*ports), GFP_KERNEL);
12961345 if (!ports)
12971346 return -ENOMEM;
12981347
12991348 for (i = 0; i < max_ports; i++) {
13001349 ports[i].id = i;
13011350 ports[i].pin = pin;
1351
+ INIT_WORK(&ports[i].dapm_work, hdac_hdmi_jack_dapm_work);
13021352 }
13031353 pin->ports = ports;
13041354 pin->num_ports = max_ports;
....@@ -1311,14 +1361,14 @@
13111361 struct hdac_hdmi_pin *pin;
13121362 int ret;
13131363
1314
- pin = kzalloc(sizeof(*pin), GFP_KERNEL);
1364
+ pin = devm_kzalloc(&hdev->dev, sizeof(*pin), GFP_KERNEL);
13151365 if (!pin)
13161366 return -ENOMEM;
13171367
13181368 pin->nid = nid;
13191369 pin->mst_capable = false;
13201370 pin->hdev = hdev;
1321
- ret = hdac_hdmi_add_ports(hdmi, pin);
1371
+ ret = hdac_hdmi_add_ports(hdev, pin);
13221372 if (ret < 0)
13231373 return ret;
13241374
....@@ -1372,6 +1422,122 @@
13721422 if (vendor_param == -1)
13731423 return;
13741424
1425
+}
1426
+
1427
+static int hdac_hdmi_eld_ctl_info(struct snd_kcontrol *kcontrol,
1428
+ struct snd_ctl_elem_info *uinfo)
1429
+{
1430
+ struct snd_soc_component *component = snd_kcontrol_chip(kcontrol);
1431
+ struct hdac_hdmi_priv *hdmi = snd_soc_component_get_drvdata(component);
1432
+ struct hdac_hdmi_pcm *pcm;
1433
+ struct hdac_hdmi_port *port;
1434
+ struct hdac_hdmi_eld *eld;
1435
+
1436
+ uinfo->type = SNDRV_CTL_ELEM_TYPE_BYTES;
1437
+ uinfo->count = 0;
1438
+
1439
+ pcm = get_hdmi_pcm_from_id(hdmi, kcontrol->id.device);
1440
+ if (!pcm) {
1441
+ dev_dbg(component->dev, "%s: no pcm, device %d\n", __func__,
1442
+ kcontrol->id.device);
1443
+ return 0;
1444
+ }
1445
+
1446
+ if (list_empty(&pcm->port_list)) {
1447
+ dev_dbg(component->dev, "%s: empty port list, device %d\n",
1448
+ __func__, kcontrol->id.device);
1449
+ return 0;
1450
+ }
1451
+
1452
+ mutex_lock(&hdmi->pin_mutex);
1453
+
1454
+ list_for_each_entry(port, &pcm->port_list, head) {
1455
+ eld = &port->eld;
1456
+
1457
+ if (eld->eld_valid) {
1458
+ uinfo->count = eld->eld_size;
1459
+ break;
1460
+ }
1461
+ }
1462
+
1463
+ mutex_unlock(&hdmi->pin_mutex);
1464
+
1465
+ return 0;
1466
+}
1467
+
1468
+static int hdac_hdmi_eld_ctl_get(struct snd_kcontrol *kcontrol,
1469
+ struct snd_ctl_elem_value *ucontrol)
1470
+{
1471
+ struct snd_soc_component *component = snd_kcontrol_chip(kcontrol);
1472
+ struct hdac_hdmi_priv *hdmi = snd_soc_component_get_drvdata(component);
1473
+ struct hdac_hdmi_pcm *pcm;
1474
+ struct hdac_hdmi_port *port;
1475
+ struct hdac_hdmi_eld *eld;
1476
+
1477
+ memset(ucontrol->value.bytes.data, 0, sizeof(ucontrol->value.bytes.data));
1478
+
1479
+ pcm = get_hdmi_pcm_from_id(hdmi, kcontrol->id.device);
1480
+ if (!pcm) {
1481
+ dev_dbg(component->dev, "%s: no pcm, device %d\n", __func__,
1482
+ kcontrol->id.device);
1483
+ return 0;
1484
+ }
1485
+
1486
+ if (list_empty(&pcm->port_list)) {
1487
+ dev_dbg(component->dev, "%s: empty port list, device %d\n",
1488
+ __func__, kcontrol->id.device);
1489
+ return 0;
1490
+ }
1491
+
1492
+ mutex_lock(&hdmi->pin_mutex);
1493
+
1494
+ list_for_each_entry(port, &pcm->port_list, head) {
1495
+ eld = &port->eld;
1496
+
1497
+ if (!eld->eld_valid)
1498
+ continue;
1499
+
1500
+ if (eld->eld_size > ARRAY_SIZE(ucontrol->value.bytes.data) ||
1501
+ eld->eld_size > ELD_MAX_SIZE) {
1502
+ mutex_unlock(&hdmi->pin_mutex);
1503
+
1504
+ dev_err(component->dev, "%s: buffer too small, device %d eld_size %d\n",
1505
+ __func__, kcontrol->id.device, eld->eld_size);
1506
+ snd_BUG();
1507
+ return -EINVAL;
1508
+ }
1509
+
1510
+ memcpy(ucontrol->value.bytes.data, eld->eld_buffer,
1511
+ eld->eld_size);
1512
+ break;
1513
+ }
1514
+
1515
+ mutex_unlock(&hdmi->pin_mutex);
1516
+
1517
+ return 0;
1518
+}
1519
+
1520
+static int hdac_hdmi_create_eld_ctl(struct snd_soc_component *component, struct hdac_hdmi_pcm *pcm)
1521
+{
1522
+ struct snd_kcontrol *kctl;
1523
+ struct snd_kcontrol_new hdmi_eld_ctl = {
1524
+ .access = SNDRV_CTL_ELEM_ACCESS_READ |
1525
+ SNDRV_CTL_ELEM_ACCESS_VOLATILE,
1526
+ .iface = SNDRV_CTL_ELEM_IFACE_PCM,
1527
+ .name = "ELD",
1528
+ .info = hdac_hdmi_eld_ctl_info,
1529
+ .get = hdac_hdmi_eld_ctl_get,
1530
+ .device = pcm->pcm_id,
1531
+ };
1532
+
1533
+ /* add ELD ctl with the device number corresponding to the PCM stream */
1534
+ kctl = snd_ctl_new1(&hdmi_eld_ctl, component);
1535
+ if (!kctl)
1536
+ return -ENOMEM;
1537
+
1538
+ pcm->eld_ctl = kctl;
1539
+
1540
+ return snd_ctl_add(component->card->snd_card, kctl);
13751541 }
13761542
13771543 static const struct snd_soc_dai_ops hdmi_dai_ops = {
....@@ -1459,8 +1625,6 @@
14591625 {
14601626 hda_nid_t nid;
14611627 int i, num_nodes;
1462
- struct hdac_hdmi_cvt *temp_cvt, *cvt_next;
1463
- struct hdac_hdmi_pin *temp_pin, *pin_next;
14641628 struct hdac_hdmi_priv *hdmi = hdev_to_hdmi_priv(hdev);
14651629 int ret;
14661630
....@@ -1488,51 +1652,35 @@
14881652 case AC_WID_AUD_OUT:
14891653 ret = hdac_hdmi_add_cvt(hdev, nid);
14901654 if (ret < 0)
1491
- goto free_widgets;
1655
+ return ret;
14921656 break;
14931657
14941658 case AC_WID_PIN:
14951659 ret = hdac_hdmi_add_pin(hdev, nid);
14961660 if (ret < 0)
1497
- goto free_widgets;
1661
+ return ret;
14981662 break;
14991663 }
15001664 }
15011665
15021666 if (!hdmi->num_pin || !hdmi->num_cvt) {
15031667 ret = -EIO;
1504
- goto free_widgets;
1668
+ dev_err(&hdev->dev, "Bad pin/cvt setup in %s\n", __func__);
1669
+ return ret;
15051670 }
15061671
15071672 ret = hdac_hdmi_create_dais(hdev, dais, hdmi, hdmi->num_cvt);
15081673 if (ret) {
15091674 dev_err(&hdev->dev, "Failed to create dais with err: %d\n",
1510
- ret);
1511
- goto free_widgets;
1675
+ ret);
1676
+ return ret;
15121677 }
15131678
15141679 *num_dais = hdmi->num_cvt;
15151680 ret = hdac_hdmi_init_dai_map(hdev);
15161681 if (ret < 0)
1517
- goto free_widgets;
1518
-
1519
- return ret;
1520
-
1521
-free_widgets:
1522
- list_for_each_entry_safe(temp_cvt, cvt_next, &hdmi->cvt_list, head) {
1523
- list_del(&temp_cvt->head);
1524
- kfree(temp_cvt->name);
1525
- kfree(temp_cvt);
1526
- }
1527
-
1528
- list_for_each_entry_safe(temp_pin, pin_next, &hdmi->pin_list, head) {
1529
- for (i = 0; i < temp_pin->num_ports; i++)
1530
- temp_pin->ports[i].pin = NULL;
1531
- kfree(temp_pin->ports);
1532
- list_del(&temp_pin->head);
1533
- kfree(temp_pin);
1534
- }
1535
-
1682
+ dev_err(&hdev->dev, "Failed to init DAI map with err: %d\n",
1683
+ ret);
15361684 return ret;
15371685 }
15381686
....@@ -1604,7 +1752,7 @@
16041752 {
16051753 struct snd_soc_pcm_runtime *rtd;
16061754
1607
- list_for_each_entry(rtd, &card->rtd_list, list) {
1755
+ for_each_card_rtds(card, rtd) {
16081756 if (rtd->pcm && (rtd->pcm->device == device))
16091757 return rtd->pcm;
16101758 }
....@@ -1745,7 +1893,7 @@
17451893 * this is a new PCM device, create new pcm and
17461894 * add to the pcm list
17471895 */
1748
- pcm = kzalloc(sizeof(*pcm), GFP_KERNEL);
1896
+ pcm = devm_kzalloc(&hdev->dev, sizeof(*pcm), GFP_KERNEL);
17491897 if (!pcm)
17501898 return -ENOMEM;
17511899 pcm->pcm_id = device;
....@@ -1761,9 +1909,17 @@
17611909 dev_err(&hdev->dev,
17621910 "chmap control add failed with err: %d for pcm: %d\n",
17631911 err, device);
1764
- kfree(pcm);
17651912 return err;
17661913 }
1914
+ }
1915
+
1916
+ /* add control for ELD Bytes */
1917
+ err = hdac_hdmi_create_eld_ctl(component, pcm);
1918
+ if (err < 0) {
1919
+ dev_err(&hdev->dev,
1920
+ "eld control add failed with err: %d for pcm: %d\n",
1921
+ err, device);
1922
+ return err;
17671923 }
17681924
17691925 list_add_tail(&pcm->head, &hdmi->pcm_list);
....@@ -1870,51 +2026,31 @@
18702026 pm_runtime_disable(&hdev->dev);
18712027 }
18722028
1873
-#ifdef CONFIG_PM
1874
-static int hdmi_codec_prepare(struct device *dev)
1875
-{
1876
- struct hdac_device *hdev = dev_to_hdac_dev(dev);
1877
-
1878
- pm_runtime_get_sync(&hdev->dev);
1879
-
1880
- /*
1881
- * Power down afg.
1882
- * codec_read is preferred over codec_write to set the power state.
1883
- * This way verb is send to set the power state and response
1884
- * is received. So setting power state is ensured without using loop
1885
- * to read the state.
1886
- */
1887
- snd_hdac_codec_read(hdev, hdev->afg, 0, AC_VERB_SET_POWER_STATE,
1888
- AC_PWRST_D3);
1889
-
1890
- return 0;
1891
-}
1892
-
1893
-static void hdmi_codec_complete(struct device *dev)
2029
+#ifdef CONFIG_PM_SLEEP
2030
+static int hdmi_codec_resume(struct device *dev)
18942031 {
18952032 struct hdac_device *hdev = dev_to_hdac_dev(dev);
18962033 struct hdac_hdmi_priv *hdmi = hdev_to_hdmi_priv(hdev);
2034
+ int ret;
18972035
1898
- /* Power up afg */
1899
- snd_hdac_codec_read(hdev, hdev->afg, 0, AC_VERB_SET_POWER_STATE,
1900
- AC_PWRST_D0);
1901
-
1902
- hdac_hdmi_skl_enable_all_pins(hdev);
1903
- hdac_hdmi_skl_enable_dp12(hdev);
1904
-
2036
+ ret = pm_runtime_force_resume(dev);
2037
+ if (ret < 0)
2038
+ return ret;
19052039 /*
19062040 * As the ELD notify callback request is not entertained while the
19072041 * device is in suspend state. Need to manually check detection of
19082042 * all pins here. pin capablity change is not support, so use the
19092043 * already set pin caps.
2044
+ *
2045
+ * NOTE: this is safe to call even if the codec doesn't actually resume.
2046
+ * The pin check involves only with DRM audio component hooks, so it
2047
+ * works even if the HD-audio side is still dreaming peacefully.
19102048 */
19112049 hdac_hdmi_present_sense_all_pins(hdev, hdmi, false);
1912
-
1913
- pm_runtime_put_sync(&hdev->dev);
2050
+ return 0;
19142051 }
19152052 #else
1916
-#define hdmi_codec_prepare NULL
1917
-#define hdmi_codec_complete NULL
2053
+#define hdmi_codec_resume NULL
19182054 #endif
19192055
19202056 static const struct snd_soc_component_driver hdmi_hda_codec = {
....@@ -1984,9 +2120,6 @@
19842120
19852121 port = list_first_entry(&pcm->port_list, struct hdac_hdmi_port, head);
19862122
1987
- if (!port)
1988
- return 0;
1989
-
19902123 if (!port || !port->eld.eld_valid)
19912124 return 0;
19922125
....@@ -2003,11 +2136,11 @@
20032136
20042137 static int hdac_hdmi_dev_probe(struct hdac_device *hdev)
20052138 {
2006
- struct hdac_hdmi_priv *hdmi_priv = NULL;
2139
+ struct hdac_hdmi_priv *hdmi_priv;
20072140 struct snd_soc_dai_driver *hdmi_dais = NULL;
2008
- struct hdac_ext_link *hlink = NULL;
2141
+ struct hdac_ext_link *hlink;
20092142 int num_dais = 0;
2010
- int ret = 0;
2143
+ int ret;
20112144 struct hdac_driver *hdrv = drv_to_hdac_driver(hdev->dev.driver);
20122145 const struct hda_device_id *hdac_id = hdac_get_device_id(hdev, hdrv);
20132146
....@@ -2051,13 +2184,7 @@
20512184 * Turned off in the runtime_suspend during the first explicit
20522185 * pm_runtime_suspend call.
20532186 */
2054
- ret = snd_hdac_display_power(hdev->bus, true);
2055
- if (ret < 0) {
2056
- dev_err(&hdev->dev,
2057
- "Cannot turn on display power on i915 err: %d\n",
2058
- ret);
2059
- return ret;
2060
- }
2187
+ snd_hdac_display_power(hdev->bus, hdev->addr, true);
20612188
20622189 ret = hdac_hdmi_parse_and_map_nid(hdev, &hdmi_dais, &num_dais);
20632190 if (ret < 0) {
....@@ -2065,7 +2192,7 @@
20652192 "Failed in parse and map nid with err: %d\n", ret);
20662193 return ret;
20672194 }
2068
- snd_hdac_refresh_widgets(hdev, true);
2195
+ snd_hdac_refresh_widgets(hdev);
20692196
20702197 /* ASoC specific initialization */
20712198 ret = devm_snd_soc_register_component(&hdev->dev, &hdmi_hda_codec,
....@@ -2076,121 +2203,31 @@
20762203 return ret;
20772204 }
20782205
2079
-static int hdac_hdmi_dev_remove(struct hdac_device *hdev)
2206
+static void clear_dapm_works(struct hdac_device *hdev)
20802207 {
20812208 struct hdac_hdmi_priv *hdmi = hdev_to_hdmi_priv(hdev);
2082
- struct hdac_hdmi_pin *pin, *pin_next;
2083
- struct hdac_hdmi_cvt *cvt, *cvt_next;
2084
- struct hdac_hdmi_pcm *pcm, *pcm_next;
2085
- struct hdac_hdmi_port *port, *port_next;
2209
+ struct hdac_hdmi_pin *pin;
20862210 int i;
20872211
2088
- list_for_each_entry_safe(pcm, pcm_next, &hdmi->pcm_list, head) {
2089
- pcm->cvt = NULL;
2090
- if (list_empty(&pcm->port_list))
2091
- continue;
2092
-
2093
- list_for_each_entry_safe(port, port_next,
2094
- &pcm->port_list, head)
2095
- list_del(&port->head);
2096
-
2097
- list_del(&pcm->head);
2098
- kfree(pcm);
2099
- }
2100
-
2101
- list_for_each_entry_safe(cvt, cvt_next, &hdmi->cvt_list, head) {
2102
- list_del(&cvt->head);
2103
- kfree(cvt->name);
2104
- kfree(cvt);
2105
- }
2106
-
2107
- list_for_each_entry_safe(pin, pin_next, &hdmi->pin_list, head) {
2212
+ list_for_each_entry(pin, &hdmi->pin_list, head)
21082213 for (i = 0; i < pin->num_ports; i++)
2109
- pin->ports[i].pin = NULL;
2110
- kfree(pin->ports);
2111
- list_del(&pin->head);
2112
- kfree(pin);
2113
- }
2214
+ cancel_work_sync(&pin->ports[i].dapm_work);
2215
+}
2216
+
2217
+static int hdac_hdmi_dev_remove(struct hdac_device *hdev)
2218
+{
2219
+ clear_dapm_works(hdev);
2220
+ snd_hdac_display_power(hdev->bus, hdev->addr, false);
21142221
21152222 return 0;
21162223 }
21172224
21182225 #ifdef CONFIG_PM
2119
-/*
2120
- * Power management sequences
2121
- * ==========================
2122
- *
2123
- * The following explains the PM handling of HDAC HDMI with its parent
2124
- * device SKL and display power usage
2125
- *
2126
- * Probe
2127
- * -----
2128
- * In SKL probe,
2129
- * 1. skl_probe_work() powers up the display (refcount++ -> 1)
2130
- * 2. enumerates the codecs on the link
2131
- * 3. powers down the display (refcount-- -> 0)
2132
- *
2133
- * In HDAC HDMI probe,
2134
- * 1. hdac_hdmi_dev_probe() powers up the display (refcount++ -> 1)
2135
- * 2. probe the codec
2136
- * 3. put the HDAC HDMI device to runtime suspend
2137
- * 4. hdac_hdmi_runtime_suspend() powers down the display (refcount-- -> 0)
2138
- *
2139
- * Once children are runtime suspended, SKL device also goes to runtime
2140
- * suspend
2141
- *
2142
- * HDMI Playback
2143
- * -------------
2144
- * Open HDMI device,
2145
- * 1. skl_runtime_resume() invoked
2146
- * 2. hdac_hdmi_runtime_resume() powers up the display (refcount++ -> 1)
2147
- *
2148
- * Close HDMI device,
2149
- * 1. hdac_hdmi_runtime_suspend() powers down the display (refcount-- -> 0)
2150
- * 2. skl_runtime_suspend() invoked
2151
- *
2152
- * S0/S3 Cycle with playback in progress
2153
- * -------------------------------------
2154
- * When the device is opened for playback, the device is runtime active
2155
- * already and the display refcount is 1 as explained above.
2156
- *
2157
- * Entering to S3,
2158
- * 1. hdmi_codec_prepare() invoke the runtime resume of codec which just
2159
- * increments the PM runtime usage count of the codec since the device
2160
- * is in use already
2161
- * 2. skl_suspend() powers down the display (refcount-- -> 0)
2162
- *
2163
- * Wakeup from S3,
2164
- * 1. skl_resume() powers up the display (refcount++ -> 1)
2165
- * 2. hdmi_codec_complete() invokes the runtime suspend of codec which just
2166
- * decrements the PM runtime usage count of the codec since the device
2167
- * is in use already
2168
- *
2169
- * Once playback is stopped, the display refcount is set to 0 as explained
2170
- * above in the HDMI playback sequence. The PM handlings are designed in
2171
- * such way that to balance the refcount of display power when the codec
2172
- * device put to S3 while playback is going on.
2173
- *
2174
- * S0/S3 Cycle without playback in progress
2175
- * ----------------------------------------
2176
- * Entering to S3,
2177
- * 1. hdmi_codec_prepare() invoke the runtime resume of codec
2178
- * 2. skl_runtime_resume() invoked
2179
- * 3. hdac_hdmi_runtime_resume() powers up the display (refcount++ -> 1)
2180
- * 4. skl_suspend() powers down the display (refcount-- -> 0)
2181
- *
2182
- * Wakeup from S3,
2183
- * 1. skl_resume() powers up the display (refcount++ -> 1)
2184
- * 2. hdmi_codec_complete() invokes the runtime suspend of codec
2185
- * 3. hdac_hdmi_runtime_suspend() powers down the display (refcount-- -> 0)
2186
- * 4. skl_runtime_suspend() invoked
2187
- */
21882226 static int hdac_hdmi_runtime_suspend(struct device *dev)
21892227 {
21902228 struct hdac_device *hdev = dev_to_hdac_dev(dev);
21912229 struct hdac_bus *bus = hdev->bus;
21922230 struct hdac_ext_link *hlink = NULL;
2193
- int err;
21942231
21952232 dev_dbg(dev, "Enter: %s\n", __func__);
21962233
....@@ -2214,13 +2251,12 @@
22142251 return -EIO;
22152252 }
22162253
2254
+ snd_hdac_codec_link_down(hdev);
22172255 snd_hdac_ext_bus_link_put(bus, hlink);
22182256
2219
- err = snd_hdac_display_power(bus, false);
2220
- if (err < 0)
2221
- dev_err(dev, "Cannot turn off display power on i915\n");
2257
+ snd_hdac_display_power(bus, hdev->addr, false);
22222258
2223
- return err;
2259
+ return 0;
22242260 }
22252261
22262262 static int hdac_hdmi_runtime_resume(struct device *dev)
....@@ -2228,7 +2264,6 @@
22282264 struct hdac_device *hdev = dev_to_hdac_dev(dev);
22292265 struct hdac_bus *bus = hdev->bus;
22302266 struct hdac_ext_link *hlink = NULL;
2231
- int err;
22322267
22332268 dev_dbg(dev, "Enter: %s\n", __func__);
22342269
....@@ -2243,12 +2278,9 @@
22432278 }
22442279
22452280 snd_hdac_ext_bus_link_get(bus, hlink);
2281
+ snd_hdac_codec_link_up(hdev);
22462282
2247
- err = snd_hdac_display_power(bus, true);
2248
- if (err < 0) {
2249
- dev_err(dev, "Cannot turn on display power on i915\n");
2250
- return err;
2251
- }
2283
+ snd_hdac_display_power(bus, hdev->addr, true);
22522284
22532285 hdac_hdmi_skl_enable_all_pins(hdev);
22542286 hdac_hdmi_skl_enable_dp12(hdev);
....@@ -2266,8 +2298,7 @@
22662298
22672299 static const struct dev_pm_ops hdac_hdmi_pm = {
22682300 SET_RUNTIME_PM_OPS(hdac_hdmi_runtime_suspend, hdac_hdmi_runtime_resume, NULL)
2269
- .prepare = hdmi_codec_prepare,
2270
- .complete = hdmi_codec_complete,
2301
+ SET_SYSTEM_SLEEP_PM_OPS(pm_runtime_force_suspend, hdmi_codec_resume)
22712302 };
22722303
22732304 static const struct hda_device_id hdmi_list[] = {