@@ -139,6 +139,7 @@ struct hdmi_spec {
139
139
int num_pins ;
140
140
struct snd_array pins ; /* struct hdmi_spec_per_pin */
141
141
struct hda_pcm * pcm_rec [16 ];
142
+ struct mutex pcm_lock ;
142
143
unsigned int channels_max ; /* max over all cvts */
143
144
144
145
struct hdmi_eld temp_eld ;
@@ -1341,6 +1342,11 @@ static int hdmi_setup_stream(struct hda_codec *codec, hda_nid_t cvt_nid,
1341
1342
return 0 ;
1342
1343
}
1343
1344
1345
+ /* Try to find an available converter
1346
+ * If pin_idx is less then zero, just try to find an available converter.
1347
+ * Otherwise, try to find an available converter and get the cvt mux index
1348
+ * of the pin.
1349
+ */
1344
1350
static int hdmi_choose_cvt (struct hda_codec * codec ,
1345
1351
int pin_idx , int * cvt_id , int * mux_id )
1346
1352
{
@@ -1349,7 +1355,11 @@ static int hdmi_choose_cvt(struct hda_codec *codec,
1349
1355
struct hdmi_spec_per_cvt * per_cvt = NULL ;
1350
1356
int cvt_idx , mux_idx = 0 ;
1351
1357
1352
- per_pin = get_pin (spec , pin_idx );
1358
+ /* pin_idx < 0 means no pin will be bound to the converter */
1359
+ if (pin_idx < 0 )
1360
+ per_pin = NULL ;
1361
+ else
1362
+ per_pin = get_pin (spec , pin_idx );
1353
1363
1354
1364
/* Dynamically assign converter to stream */
1355
1365
for (cvt_idx = 0 ; cvt_idx < spec -> num_cvts ; cvt_idx ++ ) {
@@ -1358,6 +1368,8 @@ static int hdmi_choose_cvt(struct hda_codec *codec,
1358
1368
/* Must not already be assigned */
1359
1369
if (per_cvt -> assigned )
1360
1370
continue ;
1371
+ if (per_pin == NULL )
1372
+ break ;
1361
1373
/* Must be in pin's mux's list of converters */
1362
1374
for (mux_idx = 0 ; mux_idx < per_pin -> num_mux_nids ; mux_idx ++ )
1363
1375
if (per_pin -> mux_nids [mux_idx ] == per_cvt -> cvt_nid )
@@ -1370,9 +1382,10 @@ static int hdmi_choose_cvt(struct hda_codec *codec,
1370
1382
1371
1383
/* No free converters */
1372
1384
if (cvt_idx == spec -> num_cvts )
1373
- return - ENODEV ;
1385
+ return - EBUSY ;
1374
1386
1375
- per_pin -> mux_idx = mux_idx ;
1387
+ if (per_pin != NULL )
1388
+ per_pin -> mux_idx = mux_idx ;
1376
1389
1377
1390
if (cvt_id )
1378
1391
* cvt_id = cvt_idx ;
@@ -1398,6 +1411,20 @@ static void intel_verify_pin_cvt_connect(struct hda_codec *codec,
1398
1411
mux_idx );
1399
1412
}
1400
1413
1414
+ /* get the mux index for the converter of the pins
1415
+ * converter's mux index is the same for all pins on Intel platform
1416
+ */
1417
+ static int intel_cvt_id_to_mux_idx (struct hdmi_spec * spec ,
1418
+ hda_nid_t cvt_nid )
1419
+ {
1420
+ int i ;
1421
+
1422
+ for (i = 0 ; i < spec -> num_cvts ; i ++ )
1423
+ if (spec -> cvt_nids [i ] == cvt_nid )
1424
+ return i ;
1425
+ return - EINVAL ;
1426
+ }
1427
+
1401
1428
/* Intel HDMI workaround to fix audio routing issue:
1402
1429
* For some Intel display codecs, pins share the same connection list.
1403
1430
* So a conveter can be selected by multiple pins and playback on any of these
@@ -1449,6 +1476,69 @@ static void intel_not_share_assigned_cvt(struct hda_codec *codec,
1449
1476
}
1450
1477
}
1451
1478
1479
+ /* A wrapper of intel_not_share_asigned_cvt() */
1480
+ static void intel_not_share_assigned_cvt_nid (struct hda_codec * codec ,
1481
+ hda_nid_t pin_nid , hda_nid_t cvt_nid )
1482
+ {
1483
+ int mux_idx ;
1484
+ struct hdmi_spec * spec = codec -> spec ;
1485
+
1486
+ if (!is_haswell_plus (codec ) && !is_valleyview_plus (codec ))
1487
+ return ;
1488
+
1489
+ /* On Intel platform, the mapping of converter nid to
1490
+ * mux index of the pins are always the same.
1491
+ * The pin nid may be 0, this means all pins will not
1492
+ * share the converter.
1493
+ */
1494
+ mux_idx = intel_cvt_id_to_mux_idx (spec , cvt_nid );
1495
+ if (mux_idx >= 0 )
1496
+ intel_not_share_assigned_cvt (codec , pin_nid , mux_idx );
1497
+ }
1498
+
1499
+ /* called in hdmi_pcm_open when no pin is assigned to the PCM
1500
+ * in dyn_pcm_assign mode.
1501
+ */
1502
+ static int hdmi_pcm_open_no_pin (struct hda_pcm_stream * hinfo ,
1503
+ struct hda_codec * codec ,
1504
+ struct snd_pcm_substream * substream )
1505
+ {
1506
+ struct hdmi_spec * spec = codec -> spec ;
1507
+ struct snd_pcm_runtime * runtime = substream -> runtime ;
1508
+ int cvt_idx ;
1509
+ struct hdmi_spec_per_cvt * per_cvt = NULL ;
1510
+ int err ;
1511
+
1512
+ err = hdmi_choose_cvt (codec , -1 , & cvt_idx , NULL );
1513
+ if (err )
1514
+ return err ;
1515
+
1516
+ per_cvt = get_cvt (spec , cvt_idx );
1517
+ per_cvt -> assigned = 1 ;
1518
+ hinfo -> nid = per_cvt -> cvt_nid ;
1519
+
1520
+ intel_not_share_assigned_cvt_nid (codec , 0 , per_cvt -> cvt_nid );
1521
+
1522
+ /* todo: setup spdif ctls assign */
1523
+
1524
+ /* Initially set the converter's capabilities */
1525
+ hinfo -> channels_min = per_cvt -> channels_min ;
1526
+ hinfo -> channels_max = per_cvt -> channels_max ;
1527
+ hinfo -> rates = per_cvt -> rates ;
1528
+ hinfo -> formats = per_cvt -> formats ;
1529
+ hinfo -> maxbps = per_cvt -> maxbps ;
1530
+
1531
+ /* Store the updated parameters */
1532
+ runtime -> hw .channels_min = hinfo -> channels_min ;
1533
+ runtime -> hw .channels_max = hinfo -> channels_max ;
1534
+ runtime -> hw .formats = hinfo -> formats ;
1535
+ runtime -> hw .rates = hinfo -> rates ;
1536
+
1537
+ snd_pcm_hw_constraint_step (substream -> runtime , 0 ,
1538
+ SNDRV_PCM_HW_PARAM_CHANNELS , 2 );
1539
+ return 0 ;
1540
+ }
1541
+
1452
1542
/*
1453
1543
* HDA PCM callbacks
1454
1544
*/
@@ -1465,19 +1555,36 @@ static int hdmi_pcm_open(struct hda_pcm_stream *hinfo,
1465
1555
int err ;
1466
1556
1467
1557
/* Validate hinfo */
1558
+ mutex_lock (& spec -> pcm_lock );
1468
1559
pin_idx = hinfo_to_pin_index (codec , hinfo );
1469
- if (snd_BUG_ON (pin_idx < 0 ))
1470
- return - EINVAL ;
1471
- per_pin = get_pin (spec , pin_idx );
1472
- eld = & per_pin -> sink_eld ;
1560
+ if (!spec -> dyn_pcm_assign ) {
1561
+ if (snd_BUG_ON (pin_idx < 0 )) {
1562
+ mutex_unlock (& spec -> pcm_lock );
1563
+ return - EINVAL ;
1564
+ }
1565
+ } else {
1566
+ /* no pin is assigned to the PCM
1567
+ * PA need pcm open successfully when probe
1568
+ */
1569
+ if (pin_idx < 0 ) {
1570
+ err = hdmi_pcm_open_no_pin (hinfo , codec , substream );
1571
+ mutex_unlock (& spec -> pcm_lock );
1572
+ return err ;
1573
+ }
1574
+ }
1473
1575
1474
1576
err = hdmi_choose_cvt (codec , pin_idx , & cvt_idx , & mux_idx );
1475
- if (err < 0 )
1577
+ if (err < 0 ) {
1578
+ mutex_unlock (& spec -> pcm_lock );
1476
1579
return err ;
1580
+ }
1477
1581
1478
1582
per_cvt = get_cvt (spec , cvt_idx );
1479
1583
/* Claim converter */
1480
1584
per_cvt -> assigned = 1 ;
1585
+
1586
+
1587
+ per_pin = get_pin (spec , pin_idx );
1481
1588
per_pin -> cvt_nid = per_cvt -> cvt_nid ;
1482
1589
hinfo -> nid = per_cvt -> cvt_nid ;
1483
1590
@@ -1498,6 +1605,7 @@ static int hdmi_pcm_open(struct hda_pcm_stream *hinfo,
1498
1605
hinfo -> formats = per_cvt -> formats ;
1499
1606
hinfo -> maxbps = per_cvt -> maxbps ;
1500
1607
1608
+ eld = & per_pin -> sink_eld ;
1501
1609
/* Restrict capabilities by ELD if this isn't disabled */
1502
1610
if (!static_hdmi_pcm && eld -> eld_valid ) {
1503
1611
snd_hdmi_eld_update_pcm_info (& eld -> info , hinfo );
@@ -1506,10 +1614,12 @@ static int hdmi_pcm_open(struct hda_pcm_stream *hinfo,
1506
1614
per_cvt -> assigned = 0 ;
1507
1615
hinfo -> nid = 0 ;
1508
1616
snd_hda_spdif_ctls_unassign (codec , pin_idx );
1617
+ mutex_unlock (& spec -> pcm_lock );
1509
1618
return - ENODEV ;
1510
1619
}
1511
1620
}
1512
1621
1622
+ mutex_unlock (& spec -> pcm_lock );
1513
1623
/* Store the updated parameters */
1514
1624
runtime -> hw .channels_min = hinfo -> channels_min ;
1515
1625
runtime -> hw .channels_max = hinfo -> channels_max ;
@@ -1854,13 +1964,34 @@ static int generic_hdmi_playback_pcm_prepare(struct hda_pcm_stream *hinfo,
1854
1964
{
1855
1965
hda_nid_t cvt_nid = hinfo -> nid ;
1856
1966
struct hdmi_spec * spec = codec -> spec ;
1857
- int pin_idx = hinfo_to_pin_index ( codec , hinfo ) ;
1858
- struct hdmi_spec_per_pin * per_pin = get_pin ( spec , pin_idx ) ;
1859
- hda_nid_t pin_nid = per_pin -> pin_nid ;
1967
+ int pin_idx ;
1968
+ struct hdmi_spec_per_pin * per_pin ;
1969
+ hda_nid_t pin_nid ;
1860
1970
struct snd_pcm_runtime * runtime = substream -> runtime ;
1861
1971
bool non_pcm ;
1862
1972
int pinctl ;
1973
+ int err ;
1974
+
1975
+ mutex_lock (& spec -> pcm_lock );
1976
+ pin_idx = hinfo_to_pin_index (codec , hinfo );
1977
+ if (spec -> dyn_pcm_assign && pin_idx < 0 ) {
1978
+ /* when dyn_pcm_assign and pcm is not bound to a pin
1979
+ * skip pin setup and return 0 to make audio playback
1980
+ * be ongoing
1981
+ */
1982
+ intel_not_share_assigned_cvt_nid (codec , 0 , cvt_nid );
1983
+ snd_hda_codec_setup_stream (codec , cvt_nid ,
1984
+ stream_tag , 0 , format );
1985
+ mutex_unlock (& spec -> pcm_lock );
1986
+ return 0 ;
1987
+ }
1863
1988
1989
+ if (snd_BUG_ON (pin_idx < 0 )) {
1990
+ mutex_unlock (& spec -> pcm_lock );
1991
+ return - EINVAL ;
1992
+ }
1993
+ per_pin = get_pin (spec , pin_idx );
1994
+ pin_nid = per_pin -> pin_nid ;
1864
1995
if (is_haswell_plus (codec ) || is_valleyview_plus (codec )) {
1865
1996
/* Verify pin:cvt selections to avoid silent audio after S3.
1866
1997
* After S3, the audio driver restores pin:cvt selections
@@ -1885,7 +2016,6 @@ static int generic_hdmi_playback_pcm_prepare(struct hda_pcm_stream *hinfo,
1885
2016
1886
2017
hdmi_setup_audio_infoframe (codec , per_pin , non_pcm );
1887
2018
mutex_unlock (& per_pin -> lock );
1888
-
1889
2019
if (spec -> dyn_pin_out ) {
1890
2020
pinctl = snd_hda_codec_read (codec , pin_nid , 0 ,
1891
2021
AC_VERB_GET_PIN_WIDGET_CONTROL , 0 );
@@ -1894,7 +2024,10 @@ static int generic_hdmi_playback_pcm_prepare(struct hda_pcm_stream *hinfo,
1894
2024
pinctl | PIN_OUT );
1895
2025
}
1896
2026
1897
- return spec -> ops .setup_stream (codec , cvt_nid , pin_nid , stream_tag , format );
2027
+ err = spec -> ops .setup_stream (codec , cvt_nid , pin_nid ,
2028
+ stream_tag , format );
2029
+ mutex_unlock (& spec -> pcm_lock );
2030
+ return err ;
1898
2031
}
1899
2032
1900
2033
static int generic_hdmi_playback_pcm_cleanup (struct hda_pcm_stream * hinfo ,
@@ -1925,9 +2058,17 @@ static int hdmi_pcm_close(struct hda_pcm_stream *hinfo,
1925
2058
per_cvt -> assigned = 0 ;
1926
2059
hinfo -> nid = 0 ;
1927
2060
2061
+ mutex_lock (& spec -> pcm_lock );
1928
2062
pin_idx = hinfo_to_pin_index (codec , hinfo );
1929
- if (snd_BUG_ON (pin_idx < 0 ))
2063
+ if (spec -> dyn_pcm_assign && pin_idx < 0 ) {
2064
+ mutex_unlock (& spec -> pcm_lock );
2065
+ return 0 ;
2066
+ }
2067
+
2068
+ if (snd_BUG_ON (pin_idx < 0 )) {
2069
+ mutex_unlock (& spec -> pcm_lock );
1930
2070
return - EINVAL ;
2071
+ }
1931
2072
per_pin = get_pin (spec , pin_idx );
1932
2073
1933
2074
if (spec -> dyn_pin_out ) {
@@ -1947,6 +2088,7 @@ static int hdmi_pcm_close(struct hda_pcm_stream *hinfo,
1947
2088
per_pin -> setup = false;
1948
2089
per_pin -> channels = 0 ;
1949
2090
mutex_unlock (& per_pin -> lock );
2091
+ mutex_unlock (& spec -> pcm_lock );
1950
2092
}
1951
2093
1952
2094
return 0 ;
@@ -2461,6 +2603,7 @@ static int patch_generic_hdmi(struct hda_codec *codec)
2461
2603
return - ENOMEM ;
2462
2604
2463
2605
spec -> ops = generic_standard_hdmi_ops ;
2606
+ mutex_init (& spec -> pcm_lock );
2464
2607
codec -> spec = spec ;
2465
2608
hdmi_array_init (spec , 4 );
2466
2609
0 commit comments