drm/vc4: hdmi: Replace drm_detect_hdmi_monitor() with is_hdmi
authorJosé Expósito <jose.exposito89@gmail.com>
Wed, 20 Apr 2022 11:44:59 +0000 (13:44 +0200)
committerPhil Elwell <8911409+pelwell@users.noreply.github.com>
Mon, 19 Sep 2022 19:33:09 +0000 (20:33 +0100)
Once EDID is parsed, the monitor HDMI support information is cached in
drm_display_info.is_hdmi by drm_parse_hdmi_vsdb_video().

This driver calls drm_detect_hdmi_monitor() to receive the same
information and stores its own cached value in
vc4_hdmi_encoder.hdmi_monitor, which is less efficient.

Avoid calling drm_detect_hdmi_monitor() and use drm_display_info.is_hdmi
instead. This also allows to remove vc4_hdmi_encoder.hdmi_monitor.

drm_detect_hdmi_monitor() is called in vc4_hdmi_connector_detect() and
vc4_hdmi_connector_get_modes(). In both cases it is safe to rely on
drm_display_info.is_hdmi as shown by ftrace:

$ sudo trace-cmd record -p function_graph -l "vc4_hdmi_*" -l "drm_*"

vc4_hdmi_connector_detect:

    vc4_hdmi_connector_detect() {
      drm_get_edid() {
        drm_connector_update_edid_property() {
          drm_add_display_info() {
            drm_reset_display_info();
            drm_for_each_detailed_block.part.0();
            drm_parse_cea_ext() {
              drm_find_cea_extension();
              drm_parse_hdmi_vsdb_video();
              /* drm_display_info.is_hdmi is cached here */
            }
          }
        }
      }
      /* drm_display_info.is_hdmi is used here */
    }

vc4_hdmi_connector_get_modes:

    vc4_hdmi_connector_get_modes() {
      drm_get_edid() {
        drm_connector_update_edid_property() {
          drm_add_display_info() {
            drm_reset_display_info();
            drm_for_each_detailed_block.part.0();
            drm_parse_cea_ext() {
              drm_find_cea_extension();
              drm_parse_hdmi_vsdb_video();
              /* drm_display_info.is_hdmi is cached here */
            }
          }
        }
      }
      /* drm_display_info.is_hdmi is used here */
      drm_connector_update_edid_property();
    }

Signed-off-by: José Expósito <jose.exposito89@gmail.com>
Signed-off-by: Maxime Ripard <maxime@cerno.tech>
Link: https://patchwork.freedesktop.org/patch/msgid/20220420114500.187664-2-jose.exposito89@gmail.com
drivers/gpu/drm/vc4/vc4_hdmi.c
drivers/gpu/drm/vc4/vc4_hdmi.h

index fe71014..d9c125e 100644 (file)
@@ -151,13 +151,13 @@ static bool vc4_hdmi_mode_needs_scrambling(const struct drm_display_mode *mode,
 static bool vc4_hdmi_is_full_range(struct vc4_hdmi *vc4_hdmi,
                                   const struct drm_display_mode *mode)
 {
-       struct vc4_hdmi_encoder *vc4_encoder = &vc4_hdmi->encoder;
+       struct drm_display_info *display = &vc4_hdmi->connector.display_info;
 
        if (vc4_hdmi->broadcast_rgb == VC4_BROADCAST_RGB_LIMITED)
                return false;
        else if (vc4_hdmi->broadcast_rgb == VC4_BROADCAST_RGB_FULL)
                return true;
-       return !vc4_encoder->hdmi_monitor ||
+       return !display->is_hdmi ||
                drm_default_rgb_quant_range(mode) == HDMI_QUANTIZATION_RANGE_FULL;
 }
 
@@ -319,10 +319,7 @@ vc4_hdmi_connector_detect(struct drm_connector *connector, bool force)
 
                        if (edid) {
                                cec_s_phys_addr_from_edid(vc4_hdmi->cec_adap, edid);
-                               vc4_hdmi->encoder.hdmi_monitor = drm_detect_hdmi_monitor(edid);
                                kfree(edid);
-                       } else {
-                               vc4_hdmi->encoder.hdmi_monitor = false;
                        }
                }
 
@@ -332,8 +329,6 @@ vc4_hdmi_connector_detect(struct drm_connector *connector, bool force)
                return connector_status_connected;
        }
 
-       vc4_hdmi->encoder.hdmi_monitor = false;
-
        cec_phys_addr_invalidate(vc4_hdmi->cec_adap);
        pm_runtime_put(&vc4_hdmi->pdev->dev);
        mutex_unlock(&vc4_hdmi->mutex);
@@ -343,7 +338,6 @@ vc4_hdmi_connector_detect(struct drm_connector *connector, bool force)
 static int vc4_hdmi_connector_get_modes(struct drm_connector *connector)
 {
        struct vc4_hdmi *vc4_hdmi = connector_to_vc4_hdmi(connector);
-       struct vc4_hdmi_encoder *vc4_encoder = &vc4_hdmi->encoder;
        struct vc4_dev *vc4 = to_vc4_dev(connector->dev);
        int ret = 0;
        struct edid *edid;
@@ -357,8 +351,6 @@ static int vc4_hdmi_connector_get_modes(struct drm_connector *connector)
                goto out;
        }
 
-       vc4_encoder->hdmi_monitor = drm_detect_hdmi_monitor(edid);
-
        drm_connector_update_edid_property(connector, edid);
        ret = drm_add_edid_modes(connector, edid);
        kfree(edid);
@@ -832,13 +824,12 @@ static void vc4_hdmi_set_infoframes(struct drm_encoder *encoder)
 static bool vc4_hdmi_supports_scrambling(struct drm_encoder *encoder,
                                         struct drm_display_mode *mode)
 {
-       struct vc4_hdmi_encoder *vc4_encoder = to_vc4_hdmi_encoder(encoder);
        struct vc4_hdmi *vc4_hdmi = encoder_to_vc4_hdmi(encoder);
        struct drm_display_info *display = &vc4_hdmi->connector.display_info;
 
        lockdep_assert_held(&vc4_hdmi->mutex);
 
-       if (!vc4_encoder->hdmi_monitor)
+       if (!display->is_hdmi)
                return false;
 
        if (!display->hdmi.scdc.supported ||
@@ -1662,7 +1653,7 @@ static void vc4_hdmi_encoder_post_crtc_enable(struct drm_encoder *encoder,
        struct vc4_hdmi *vc4_hdmi = encoder_to_vc4_hdmi(encoder);
        struct drm_device *drm = vc4_hdmi->connector.dev;
        struct drm_display_mode *mode = &vc4_hdmi->saved_adjusted_mode;
-       struct vc4_hdmi_encoder *vc4_encoder = to_vc4_hdmi_encoder(encoder);
+       struct drm_display_info *display = &vc4_hdmi->connector.display_info;
        bool hsync_pos = mode->flags & DRM_MODE_FLAG_PHSYNC;
        bool vsync_pos = mode->flags & DRM_MODE_FLAG_PVSYNC;
        unsigned long flags;
@@ -1687,7 +1678,7 @@ static void vc4_hdmi_encoder_post_crtc_enable(struct drm_encoder *encoder,
        HDMI_WRITE(HDMI_VID_CTL,
                   HDMI_READ(HDMI_VID_CTL) & ~VC4_HD_VID_CTL_BLANKPIX);
 
-       if (vc4_encoder->hdmi_monitor) {
+       if (display->is_hdmi) {
                HDMI_WRITE(HDMI_SCHEDULER_CONTROL,
                           HDMI_READ(HDMI_SCHEDULER_CONTROL) |
                           VC4_HDMI_SCHEDULER_CONTROL_MODE_HDMI);
@@ -1714,7 +1705,7 @@ static void vc4_hdmi_encoder_post_crtc_enable(struct drm_encoder *encoder,
                          "!VC4_HDMI_SCHEDULER_CONTROL_HDMI_ACTIVE\n");
        }
 
-       if (vc4_encoder->hdmi_monitor) {
+       if (display->is_hdmi) {
                spin_lock_irqsave(&vc4_hdmi->hw_lock, flags);
 
                WARN_ON(!(HDMI_READ(HDMI_SCHEDULER_CONTROL) &
@@ -2193,13 +2184,15 @@ static inline struct vc4_hdmi *dai_to_hdmi(struct snd_soc_dai *dai)
 
 static bool vc4_hdmi_audio_can_stream(struct vc4_hdmi *vc4_hdmi)
 {
+       struct drm_display_info *display = &vc4_hdmi->connector.display_info;
+
        lockdep_assert_held(&vc4_hdmi->mutex);
 
        /*
         * If the encoder is currently in DVI mode, treat the codec DAI
         * as missing.
         */
-       if (!vc4_hdmi->encoder.hdmi_monitor)
+       if (!display->is_hdmi)
                return false;
 
        return true;
index b83e419..2d6a0e2 100644 (file)
@@ -11,7 +11,6 @@
 /* VC4 HDMI encoder KMS struct */
 struct vc4_hdmi_encoder {
        struct vc4_encoder base;
-       bool hdmi_monitor;
 };
 
 static inline struct vc4_hdmi_encoder *