drm/dp: Add drm_dp_downstream_mode()
authorVille Syrjälä <ville.syrjala@linux.intel.com>
Fri, 4 Sep 2020 11:53:49 +0000 (14:53 +0300)
committerVille Syrjälä <ville.syrjala@linux.intel.com>
Thu, 17 Sep 2020 15:33:22 +0000 (18:33 +0300)
The downstream facing port caps in the DPCD can give us a hint
as to what kind of display mode the sink can use if it doesn't
have an EDID. Use that information to pick a suitable mode.

v2: Use Returns: for kdoc (Lyude)
    Add kdocs for drm_display_mode_from_cea_vic() (Lyude)

Signed-off-by: Ville Syrjälä <ville.syrjala@linux.intel.com>
Link: https://patchwork.freedesktop.org/patch/msgid/20200904115354.25336-14-ville.syrjala@linux.intel.com
Reviewed-by: Lyude Paul <lyude@redhat.com>
Acked-by: Daniel Vetter <daniel.vetter@ffwll.ch>
drivers/gpu/drm/drm_dp_helper.c
drivers/gpu/drm/drm_edid.c
include/drm/drm_dp_helper.h
include/drm/drm_edid.h

index 5d8c9bd700c97efc6b553a777c576e40995cfc3b..63ac94c54e9590dbdcb35c9061675db2984d02f5 100644 (file)
@@ -808,6 +808,60 @@ int drm_dp_downstream_max_bpc(const u8 dpcd[DP_RECEIVER_CAP_SIZE],
 }
 EXPORT_SYMBOL(drm_dp_downstream_max_bpc);
 
+/**
+ * drm_dp_downstream_mode() - return a mode for downstream facing port
+ * @dpcd: DisplayPort configuration data
+ * @port_cap: port capabilities
+ *
+ * Provides a suitable mode for downstream facing ports without EDID.
+ *
+ * Returns: A new drm_display_mode on success or NULL on failure
+ */
+struct drm_display_mode *
+drm_dp_downstream_mode(struct drm_device *dev,
+                      const u8 dpcd[DP_RECEIVER_CAP_SIZE],
+                      const u8 port_cap[4])
+
+{
+       u8 vic;
+
+       if (!drm_dp_is_branch(dpcd))
+               return NULL;
+
+       if (dpcd[DP_DPCD_REV] < 0x11)
+               return NULL;
+
+       switch (port_cap[0] & DP_DS_PORT_TYPE_MASK) {
+       case DP_DS_PORT_TYPE_NON_EDID:
+               switch (port_cap[0] & DP_DS_NON_EDID_MASK) {
+               case DP_DS_NON_EDID_720x480i_60:
+                       vic = 6;
+                       break;
+               case DP_DS_NON_EDID_720x480i_50:
+                       vic = 21;
+                       break;
+               case DP_DS_NON_EDID_1920x1080i_60:
+                       vic = 5;
+                       break;
+               case DP_DS_NON_EDID_1920x1080i_50:
+                       vic = 20;
+                       break;
+               case DP_DS_NON_EDID_1280x720_60:
+                       vic = 4;
+                       break;
+               case DP_DS_NON_EDID_1280x720_50:
+                       vic = 19;
+                       break;
+               default:
+                       return NULL;
+               }
+               return drm_display_mode_from_cea_vic(dev, vic);
+       default:
+               return NULL;
+       }
+}
+EXPORT_SYMBOL(drm_dp_downstream_mode);
+
 /**
  * drm_dp_downstream_id() - identify branch device
  * @aux: DisplayPort AUX channel
index 6840f0530a38963ab3d939c3a7d8768fe93b0837..a82f37d4425826b72f9bb036fad293c51408574f 100644 (file)
@@ -3738,6 +3738,34 @@ drm_add_cmdb_modes(struct drm_connector *connector, u8 svd)
        bitmap_set(hdmi->y420_cmdb_modes, vic, 1);
 }
 
+/**
+ * drm_display_mode_from_cea_vic() - return a mode for CEA VIC
+ * @dev: DRM device
+ * @vic: CEA VIC of the mode
+ *
+ * Creates a new mode matching the specified CEA VIC.
+ *
+ * Returns: A new drm_display_mode on success or NULL on failure
+ */
+struct drm_display_mode *
+drm_display_mode_from_cea_vic(struct drm_device *dev,
+                             u8 video_code)
+{
+       const struct drm_display_mode *cea_mode;
+       struct drm_display_mode *newmode;
+
+       cea_mode = cea_mode_for_vic(video_code);
+       if (!cea_mode)
+               return NULL;
+
+       newmode = drm_mode_duplicate(dev, cea_mode);
+       if (!newmode)
+               return NULL;
+
+       return newmode;
+}
+EXPORT_SYMBOL(drm_display_mode_from_cea_vic);
+
 static int
 do_cea_modes(struct drm_connector *connector, const u8 *db, u8 len)
 {
index 6812a3e0de8dd10d7d8723c55fd72b70a4314758..fbba4a0f73665e4b57e11a4a82ae138ea2f66bd0 100644 (file)
@@ -28,6 +28,8 @@
 #include <linux/types.h>
 #include <drm/drm_connector.h>
 
+struct drm_device;
+
 /*
  * Unless otherwise noted, all values are from the DP 1.1a spec.  Note that
  * DP and DPCD versions are independent.  Differences from 1.0 are not noted,
 # define DP_DS_PORT_TYPE_DP_DUALMODE        5
 # define DP_DS_PORT_TYPE_WIRELESS           6
 # define DP_DS_PORT_HPD                            (1 << 3)
+# define DP_DS_NON_EDID_MASK               (0xf << 4)
+# define DP_DS_NON_EDID_720x480i_60        (1 << 4)
+# define DP_DS_NON_EDID_720x480i_50        (2 << 4)
+# define DP_DS_NON_EDID_1920x1080i_60      (3 << 4)
+# define DP_DS_NON_EDID_1920x1080i_50      (4 << 4)
+# define DP_DS_NON_EDID_1280x720_60        (5 << 4)
+# define DP_DS_NON_EDID_1280x720_50        (7 << 4)
 /* offset 1 for VGA is maximum megapixels per second / 8 */
 /* offset 1 for DVI/HDMI is maximum TMDS clock in Mbps / 2.5 */
 /* offset 2 for VGA/DVI/HDMI */
@@ -1654,6 +1663,9 @@ int drm_dp_downstream_min_tmds_clock(const u8 dpcd[DP_RECEIVER_CAP_SIZE],
 int drm_dp_downstream_max_bpc(const u8 dpcd[DP_RECEIVER_CAP_SIZE],
                              const u8 port_cap[4],
                              const struct edid *edid);
+struct drm_display_mode *drm_dp_downstream_mode(struct drm_device *dev,
+                                               const u8 dpcd[DP_RECEIVER_CAP_SIZE],
+                                               const u8 port_cap[4]);
 int drm_dp_downstream_id(struct drm_dp_aux *aux, char id[6]);
 void drm_dp_downstream_debug(struct seq_file *m,
                             const u8 dpcd[DP_RECEIVER_CAP_SIZE],
index cfa4f5af49afd9a9f0fbf55ec89488cb7ca55541..b27a0e2169c8f56bdcd882ea18f5cd200248a327 100644 (file)
@@ -517,4 +517,8 @@ void drm_edid_get_monitor_name(struct edid *edid, char *name,
 struct drm_display_mode *drm_mode_find_dmt(struct drm_device *dev,
                                           int hsize, int vsize, int fresh,
                                           bool rb);
+struct drm_display_mode *
+drm_display_mode_from_cea_vic(struct drm_device *dev,
+                             u8 video_code);
+
 #endif /* __DRM_EDID_H__ */