@@ -636,15 +636,14 @@ static int i915_audio_component_sync_audio_rate(struct device *dev,
636
636
int port , int rate )
637
637
{
638
638
struct drm_i915_private * dev_priv = dev_to_i915 (dev );
639
- struct drm_device * drm_dev = dev_priv -> dev ;
640
639
struct intel_encoder * intel_encoder ;
641
- struct intel_digital_port * intel_dig_port ;
642
640
struct intel_crtc * crtc ;
643
641
struct drm_display_mode * mode ;
644
642
struct i915_audio_component * acomp = dev_priv -> audio_component ;
645
- enum pipe pipe = -1 ;
643
+ enum pipe pipe = INVALID_PIPE ;
646
644
u32 tmp ;
647
645
int n ;
646
+ int err = 0 ;
648
647
649
648
/* HSW, BDW, SKL, KBL need this fix */
650
649
if (!IS_SKYLAKE (dev_priv ) &&
@@ -655,26 +654,22 @@ static int i915_audio_component_sync_audio_rate(struct device *dev,
655
654
656
655
mutex_lock (& dev_priv -> av_mutex );
657
656
/* 1. get the pipe */
658
- for_each_intel_encoder (drm_dev , intel_encoder ) {
659
- if (intel_encoder -> type != INTEL_OUTPUT_HDMI )
660
- continue ;
661
- intel_dig_port = enc_to_dig_port (& intel_encoder -> base );
662
- if (port == intel_dig_port -> port ) {
663
- crtc = to_intel_crtc (intel_encoder -> base .crtc );
664
- if (!crtc ) {
665
- DRM_DEBUG_KMS ("%s: crtc is NULL\n" , __func__ );
666
- continue ;
667
- }
668
- pipe = crtc -> pipe ;
669
- break ;
670
- }
657
+ intel_encoder = dev_priv -> dig_port_map [port ];
658
+ /* intel_encoder might be NULL for DP MST */
659
+ if (!intel_encoder || !intel_encoder -> base .crtc ||
660
+ intel_encoder -> type != INTEL_OUTPUT_HDMI ) {
661
+ DRM_DEBUG_KMS ("no valid port %c\n" , port_name (port ));
662
+ err = - ENODEV ;
663
+ goto unlock ;
671
664
}
672
-
665
+ crtc = to_intel_crtc (intel_encoder -> base .crtc );
666
+ pipe = crtc -> pipe ;
673
667
if (pipe == INVALID_PIPE ) {
674
668
DRM_DEBUG_KMS ("no pipe for the port %c\n" , port_name (port ));
675
- mutex_unlock ( & dev_priv -> av_mutex ) ;
676
- return - ENODEV ;
669
+ err = - ENODEV ;
670
+ goto unlock ;
677
671
}
672
+
678
673
DRM_DEBUG_KMS ("pipe %c connects port %c\n" ,
679
674
pipe_name (pipe ), port_name (port ));
680
675
mode = & crtc -> config -> base .adjusted_mode ;
@@ -687,8 +682,7 @@ static int i915_audio_component_sync_audio_rate(struct device *dev,
687
682
tmp = I915_READ (HSW_AUD_CFG (pipe ));
688
683
tmp &= ~AUD_CONFIG_N_PROG_ENABLE ;
689
684
I915_WRITE (HSW_AUD_CFG (pipe ), tmp );
690
- mutex_unlock (& dev_priv -> av_mutex );
691
- return 0 ;
685
+ goto unlock ;
692
686
}
693
687
694
688
n = audio_config_get_n (mode , rate );
@@ -698,45 +692,40 @@ static int i915_audio_component_sync_audio_rate(struct device *dev,
698
692
tmp = I915_READ (HSW_AUD_CFG (pipe ));
699
693
tmp &= ~AUD_CONFIG_N_PROG_ENABLE ;
700
694
I915_WRITE (HSW_AUD_CFG (pipe ), tmp );
701
- mutex_unlock (& dev_priv -> av_mutex );
702
- return 0 ;
695
+ goto unlock ;
703
696
}
704
697
705
698
/* 3. set the N/CTS/M */
706
699
tmp = I915_READ (HSW_AUD_CFG (pipe ));
707
700
tmp = audio_config_setup_n_reg (n , tmp );
708
701
I915_WRITE (HSW_AUD_CFG (pipe ), tmp );
709
702
703
+ unlock :
710
704
mutex_unlock (& dev_priv -> av_mutex );
711
- return 0 ;
705
+ return err ;
712
706
}
713
707
714
708
static int i915_audio_component_get_eld (struct device * dev , int port ,
715
709
bool * enabled ,
716
710
unsigned char * buf , int max_bytes )
717
711
{
718
712
struct drm_i915_private * dev_priv = dev_to_i915 (dev );
719
- struct drm_device * drm_dev = dev_priv -> dev ;
720
713
struct intel_encoder * intel_encoder ;
721
714
struct intel_digital_port * intel_dig_port ;
722
715
const u8 * eld ;
723
716
int ret = - EINVAL ;
724
717
725
718
mutex_lock (& dev_priv -> av_mutex );
726
- for_each_intel_encoder ( drm_dev , intel_encoder ) {
727
- if ( intel_encoder -> type != INTEL_OUTPUT_DISPLAYPORT &&
728
- intel_encoder -> type != INTEL_OUTPUT_HDMI )
729
- continue ;
719
+ intel_encoder = dev_priv -> dig_port_map [ port ];
720
+ /* intel_encoder might be NULL for DP MST */
721
+ if ( intel_encoder ) {
722
+ ret = 0 ;
730
723
intel_dig_port = enc_to_dig_port (& intel_encoder -> base );
731
- if (port == intel_dig_port -> port ) {
732
- ret = 0 ;
733
- * enabled = intel_dig_port -> audio_connector != NULL ;
734
- if (!* enabled )
735
- break ;
724
+ * enabled = intel_dig_port -> audio_connector != NULL ;
725
+ if (* enabled ) {
736
726
eld = intel_dig_port -> audio_connector -> eld ;
737
727
ret = drm_eld_size (eld );
738
728
memcpy (buf , eld , min (max_bytes , ret ));
739
- break ;
740
729
}
741
730
}
742
731
0 commit comments