@@ -140,6 +140,7 @@ struct hdmi_spec {
140
140
struct snd_array pins ; /* struct hdmi_spec_per_pin */
141
141
struct hda_pcm * pcm_rec [16 ];
142
142
struct mutex pcm_lock ;
143
+ int pcm_used ; /* counter of pcm_rec[] */
143
144
unsigned int channels_max ; /* max over all cvts */
144
145
145
146
struct hdmi_eld temp_eld ;
@@ -387,6 +388,20 @@ static int pin_nid_to_pin_index(struct hda_codec *codec, hda_nid_t pin_nid)
387
388
return - EINVAL ;
388
389
}
389
390
391
+ static int hinfo_to_pcm_index (struct hda_codec * codec ,
392
+ struct hda_pcm_stream * hinfo )
393
+ {
394
+ struct hdmi_spec * spec = codec -> spec ;
395
+ int pcm_idx ;
396
+
397
+ for (pcm_idx = 0 ; pcm_idx < spec -> pcm_used ; pcm_idx ++ )
398
+ if (get_pcm_rec (spec , pcm_idx )-> stream == hinfo )
399
+ return pcm_idx ;
400
+
401
+ codec_warn (codec , "HDMI: hinfo %p not registered\n" , hinfo );
402
+ return - EINVAL ;
403
+ }
404
+
390
405
static int hinfo_to_pin_index (struct hda_codec * codec ,
391
406
struct hda_pcm_stream * hinfo )
392
407
{
@@ -1548,13 +1563,17 @@ static int hdmi_pcm_open(struct hda_pcm_stream *hinfo,
1548
1563
{
1549
1564
struct hdmi_spec * spec = codec -> spec ;
1550
1565
struct snd_pcm_runtime * runtime = substream -> runtime ;
1551
- int pin_idx , cvt_idx , mux_idx = 0 ;
1566
+ int pin_idx , cvt_idx , pcm_idx , mux_idx = 0 ;
1552
1567
struct hdmi_spec_per_pin * per_pin ;
1553
1568
struct hdmi_eld * eld ;
1554
1569
struct hdmi_spec_per_cvt * per_cvt = NULL ;
1555
1570
int err ;
1556
1571
1557
1572
/* Validate hinfo */
1573
+ pcm_idx = hinfo_to_pcm_index (codec , hinfo );
1574
+ if (pcm_idx < 0 )
1575
+ return - EINVAL ;
1576
+
1558
1577
mutex_lock (& spec -> pcm_lock );
1559
1578
pin_idx = hinfo_to_pin_index (codec , hinfo );
1560
1579
if (!spec -> dyn_pcm_assign ) {
@@ -1596,7 +1615,7 @@ static int hdmi_pcm_open(struct hda_pcm_stream *hinfo,
1596
1615
if (is_haswell_plus (codec ) || is_valleyview_plus (codec ))
1597
1616
intel_not_share_assigned_cvt (codec , per_pin -> pin_nid , mux_idx );
1598
1617
1599
- snd_hda_spdif_ctls_assign (codec , pin_idx , per_cvt -> cvt_nid );
1618
+ snd_hda_spdif_ctls_assign (codec , pcm_idx , per_cvt -> cvt_nid );
1600
1619
1601
1620
/* Initially set the converter's capabilities */
1602
1621
hinfo -> channels_min = per_cvt -> channels_min ;
@@ -1613,7 +1632,7 @@ static int hdmi_pcm_open(struct hda_pcm_stream *hinfo,
1613
1632
!hinfo -> rates || !hinfo -> formats ) {
1614
1633
per_cvt -> assigned = 0 ;
1615
1634
hinfo -> nid = 0 ;
1616
- snd_hda_spdif_ctls_unassign (codec , pin_idx );
1635
+ snd_hda_spdif_ctls_unassign (codec , pcm_idx );
1617
1636
mutex_unlock (& spec -> pcm_lock );
1618
1637
return - ENODEV ;
1619
1638
}
@@ -2043,12 +2062,15 @@ static int hdmi_pcm_close(struct hda_pcm_stream *hinfo,
2043
2062
struct snd_pcm_substream * substream )
2044
2063
{
2045
2064
struct hdmi_spec * spec = codec -> spec ;
2046
- int cvt_idx , pin_idx ;
2065
+ int cvt_idx , pin_idx , pcm_idx ;
2047
2066
struct hdmi_spec_per_cvt * per_cvt ;
2048
2067
struct hdmi_spec_per_pin * per_pin ;
2049
2068
int pinctl ;
2050
2069
2051
2070
if (hinfo -> nid ) {
2071
+ pcm_idx = hinfo_to_pcm_index (codec , hinfo );
2072
+ if (snd_BUG_ON (pcm_idx < 0 ))
2073
+ return - EINVAL ;
2052
2074
cvt_idx = cvt_nid_to_cvt_index (codec , hinfo -> nid );
2053
2075
if (snd_BUG_ON (cvt_idx < 0 ))
2054
2076
return - EINVAL ;
@@ -2079,7 +2101,7 @@ static int hdmi_pcm_close(struct hda_pcm_stream *hinfo,
2079
2101
pinctl & ~PIN_OUT );
2080
2102
}
2081
2103
2082
- snd_hda_spdif_ctls_unassign (codec , pin_idx );
2104
+ snd_hda_spdif_ctls_unassign (codec , pcm_idx );
2083
2105
2084
2106
mutex_lock (& per_pin -> lock );
2085
2107
per_pin -> chmap_set = false;
@@ -2277,6 +2299,7 @@ static int generic_hdmi_build_pcms(struct hda_codec *codec)
2277
2299
per_pin -> pcm = info ;
2278
2300
}
2279
2301
spec -> pcm_rec [pin_idx ] = info ;
2302
+ spec -> pcm_used ++ ;
2280
2303
info -> pcm_type = HDA_PCM_TYPE_HDMI ;
2281
2304
info -> own_chmap = true;
2282
2305
@@ -2353,6 +2376,7 @@ static int generic_hdmi_build_controls(struct hda_codec *codec)
2353
2376
HDA_PCM_TYPE_HDMI );
2354
2377
if (err < 0 )
2355
2378
return err ;
2379
+ /* pin number is the same with pcm number so far */
2356
2380
snd_hda_spdif_ctls_unassign (codec , pin_idx );
2357
2381
2358
2382
/* add control for ELD Bytes */
0 commit comments