drm_edid.c (19df0cfa258cd42f7f106f6085f1e625f26283db) drm_edid.c (4fc8cb47fcfdc93e274a1291757e478df4f9c39b)
1/*
2 * Copyright (c) 2006 Luc Verhaegen (quirks list)
3 * Copyright (c) 2007-2008 Intel Corporation
4 * Jesse Barnes <jesse.barnes@intel.com>
5 * Copyright 2010 Red Hat, Inc.
6 *
7 * DDC probing routines (drm_ddc_read & drm_do_probe_ddc_edid) originally from
8 * FB layer.

--- 5869 unchanged lines hidden (view full) ---

5878 */
5879 if (!connector)
5880 return true;
5881
5882 return connector->display_info.hdmi.scdc.supported ||
5883 connector->display_info.color_formats & DRM_COLOR_FORMAT_YCBCR420;
5884}
5885
1/*
2 * Copyright (c) 2006 Luc Verhaegen (quirks list)
3 * Copyright (c) 2007-2008 Intel Corporation
4 * Jesse Barnes <jesse.barnes@intel.com>
5 * Copyright 2010 Red Hat, Inc.
6 *
7 * DDC probing routines (drm_ddc_read & drm_do_probe_ddc_edid) originally from
8 * FB layer.

--- 5869 unchanged lines hidden (view full) ---

5878 */
5879 if (!connector)
5880 return true;
5881
5882 return connector->display_info.hdmi.scdc.supported ||
5883 connector->display_info.color_formats & DRM_COLOR_FORMAT_YCBCR420;
5884}
5885
5886static inline bool is_eotf_supported(u8 output_eotf, u8 sink_eotf)
5887{
5888 return sink_eotf & BIT(output_eotf);
5889}
5890
5891/**
5892 * drm_hdmi_infoframe_set_hdr_metadata() - fill an HDMI DRM infoframe with
5893 * HDR metadata from userspace
5894 * @frame: HDMI DRM infoframe
5895 * @conn_state: Connector state containing HDR metadata
5896 *
5897 * Return: 0 on success or a negative error code on failure.
5898 */
5899int
5900drm_hdmi_infoframe_set_hdr_metadata(struct hdmi_drm_infoframe *frame,
5901 const struct drm_connector_state *conn_state)
5902{
5903 struct drm_connector *connector;
5904 struct hdr_output_metadata *hdr_metadata;
5905 int err;
5906
5907 if (!frame || !conn_state)
5908 return -EINVAL;
5909
5910 connector = conn_state->connector;
5911
5912 if (!conn_state->hdr_output_metadata)
5913 return -EINVAL;
5914
5915 hdr_metadata = conn_state->hdr_output_metadata->data;
5916
5917 if (!hdr_metadata || !connector)
5918 return -EINVAL;
5919
5920 /* Sink EOTF is Bit map while infoframe is absolute values */
5921 if (!is_eotf_supported(hdr_metadata->hdmi_metadata_type1.eotf,
5922 connector->hdr_sink_metadata.hdmi_type1.eotf)) {
5923 DRM_DEBUG_KMS("EOTF Not Supported\n");
5924 return -EINVAL;
5925 }
5926
5927 err = hdmi_drm_infoframe_init(frame);
5928 if (err < 0)
5929 return err;
5930
5931 frame->eotf = hdr_metadata->hdmi_metadata_type1.eotf;
5932 frame->metadata_type = hdr_metadata->hdmi_metadata_type1.metadata_type;
5933
5934 BUILD_BUG_ON(sizeof(frame->display_primaries) !=
5935 sizeof(hdr_metadata->hdmi_metadata_type1.display_primaries));
5936 BUILD_BUG_ON(sizeof(frame->white_point) !=
5937 sizeof(hdr_metadata->hdmi_metadata_type1.white_point));
5938
5939 memcpy(&frame->display_primaries,
5940 &hdr_metadata->hdmi_metadata_type1.display_primaries,
5941 sizeof(frame->display_primaries));
5942
5943 memcpy(&frame->white_point,
5944 &hdr_metadata->hdmi_metadata_type1.white_point,
5945 sizeof(frame->white_point));
5946
5947 frame->max_display_mastering_luminance =
5948 hdr_metadata->hdmi_metadata_type1.max_display_mastering_luminance;
5949 frame->min_display_mastering_luminance =
5950 hdr_metadata->hdmi_metadata_type1.min_display_mastering_luminance;
5951 frame->max_fall = hdr_metadata->hdmi_metadata_type1.max_fall;
5952 frame->max_cll = hdr_metadata->hdmi_metadata_type1.max_cll;
5953
5954 return 0;
5955}
5956EXPORT_SYMBOL(drm_hdmi_infoframe_set_hdr_metadata);
5957
5958static u8 drm_mode_hdmi_vic(const struct drm_connector *connector,
5959 const struct drm_display_mode *mode)
5960{
5961 bool has_hdmi_infoframe = connector ?
5962 connector->display_info.has_hdmi_infoframe : false;
5963
5964 if (!has_hdmi_infoframe)
5965 return 0;

--- 105 unchanged lines hidden (view full) ---

6071 frame->picture_aspect = picture_aspect;
6072 frame->active_aspect = HDMI_ACTIVE_ASPECT_PICTURE;
6073 frame->scan_mode = HDMI_SCAN_MODE_UNDERSCAN;
6074
6075 return 0;
6076}
6077EXPORT_SYMBOL(drm_hdmi_avi_infoframe_from_display_mode);
6078
5886static u8 drm_mode_hdmi_vic(const struct drm_connector *connector,
5887 const struct drm_display_mode *mode)
5888{
5889 bool has_hdmi_infoframe = connector ?
5890 connector->display_info.has_hdmi_infoframe : false;
5891
5892 if (!has_hdmi_infoframe)
5893 return 0;

--- 105 unchanged lines hidden (view full) ---

5999 frame->picture_aspect = picture_aspect;
6000 frame->active_aspect = HDMI_ACTIVE_ASPECT_PICTURE;
6001 frame->scan_mode = HDMI_SCAN_MODE_UNDERSCAN;
6002
6003 return 0;
6004}
6005EXPORT_SYMBOL(drm_hdmi_avi_infoframe_from_display_mode);
6006
6079/* HDMI Colorspace Spec Definitions */
6080#define FULL_COLORIMETRY_MASK 0x1FF
6081#define NORMAL_COLORIMETRY_MASK 0x3
6082#define EXTENDED_COLORIMETRY_MASK 0x7
6083#define EXTENDED_ACE_COLORIMETRY_MASK 0xF
6084
6085#define C(x) ((x) << 0)
6086#define EC(x) ((x) << 2)
6087#define ACE(x) ((x) << 5)
6088
6089#define HDMI_COLORIMETRY_NO_DATA 0x0
6090#define HDMI_COLORIMETRY_SMPTE_170M_YCC (C(1) | EC(0) | ACE(0))
6091#define HDMI_COLORIMETRY_BT709_YCC (C(2) | EC(0) | ACE(0))
6092#define HDMI_COLORIMETRY_XVYCC_601 (C(3) | EC(0) | ACE(0))
6093#define HDMI_COLORIMETRY_XVYCC_709 (C(3) | EC(1) | ACE(0))
6094#define HDMI_COLORIMETRY_SYCC_601 (C(3) | EC(2) | ACE(0))
6095#define HDMI_COLORIMETRY_OPYCC_601 (C(3) | EC(3) | ACE(0))
6096#define HDMI_COLORIMETRY_OPRGB (C(3) | EC(4) | ACE(0))
6097#define HDMI_COLORIMETRY_BT2020_CYCC (C(3) | EC(5) | ACE(0))
6098#define HDMI_COLORIMETRY_BT2020_RGB (C(3) | EC(6) | ACE(0))
6099#define HDMI_COLORIMETRY_BT2020_YCC (C(3) | EC(6) | ACE(0))
6100#define HDMI_COLORIMETRY_DCI_P3_RGB_D65 (C(3) | EC(7) | ACE(0))
6101#define HDMI_COLORIMETRY_DCI_P3_RGB_THEATER (C(3) | EC(7) | ACE(1))
6102
6103static const u32 hdmi_colorimetry_val[] = {
6104 [DRM_MODE_COLORIMETRY_NO_DATA] = HDMI_COLORIMETRY_NO_DATA,
6105 [DRM_MODE_COLORIMETRY_SMPTE_170M_YCC] = HDMI_COLORIMETRY_SMPTE_170M_YCC,
6106 [DRM_MODE_COLORIMETRY_BT709_YCC] = HDMI_COLORIMETRY_BT709_YCC,
6107 [DRM_MODE_COLORIMETRY_XVYCC_601] = HDMI_COLORIMETRY_XVYCC_601,
6108 [DRM_MODE_COLORIMETRY_XVYCC_709] = HDMI_COLORIMETRY_XVYCC_709,
6109 [DRM_MODE_COLORIMETRY_SYCC_601] = HDMI_COLORIMETRY_SYCC_601,
6110 [DRM_MODE_COLORIMETRY_OPYCC_601] = HDMI_COLORIMETRY_OPYCC_601,
6111 [DRM_MODE_COLORIMETRY_OPRGB] = HDMI_COLORIMETRY_OPRGB,
6112 [DRM_MODE_COLORIMETRY_BT2020_CYCC] = HDMI_COLORIMETRY_BT2020_CYCC,
6113 [DRM_MODE_COLORIMETRY_BT2020_RGB] = HDMI_COLORIMETRY_BT2020_RGB,
6114 [DRM_MODE_COLORIMETRY_BT2020_YCC] = HDMI_COLORIMETRY_BT2020_YCC,
6115};
6116
6117#undef C
6118#undef EC
6119#undef ACE
6120
6121/**
6007/**
6122 * drm_hdmi_avi_infoframe_colorimetry() - fill the HDMI AVI infoframe
6123 * colorimetry information
6124 * @frame: HDMI AVI infoframe
6125 * @conn_state: connector state
6126 */
6127void
6128drm_hdmi_avi_infoframe_colorimetry(struct hdmi_avi_infoframe *frame,
6129 const struct drm_connector_state *conn_state)
6130{
6131 u32 colorimetry_val;
6132 u32 colorimetry_index = conn_state->colorspace & FULL_COLORIMETRY_MASK;
6133
6134 if (colorimetry_index >= ARRAY_SIZE(hdmi_colorimetry_val))
6135 colorimetry_val = HDMI_COLORIMETRY_NO_DATA;
6136 else
6137 colorimetry_val = hdmi_colorimetry_val[colorimetry_index];
6138
6139 frame->colorimetry = colorimetry_val & NORMAL_COLORIMETRY_MASK;
6140 /*
6141 * ToDo: Extend it for ACE formats as well. Modify the infoframe
6142 * structure and extend it in drivers/video/hdmi
6143 */
6144 frame->extended_colorimetry = (colorimetry_val >> 2) &
6145 EXTENDED_COLORIMETRY_MASK;
6146}
6147EXPORT_SYMBOL(drm_hdmi_avi_infoframe_colorimetry);
6148
6149/**
6150 * drm_hdmi_avi_infoframe_quant_range() - fill the HDMI AVI infoframe
6151 * quantization range information
6152 * @frame: HDMI AVI infoframe
6153 * @connector: the connector
6154 * @mode: DRM display mode
6155 * @rgb_quant_range: RGB quantization range (Q)
6156 */
6157void

--- 38 unchanged lines hidden (view full) ---

6196 frame->ycc_quantization_range =
6197 HDMI_YCC_QUANTIZATION_RANGE_LIMITED;
6198 else
6199 frame->ycc_quantization_range =
6200 HDMI_YCC_QUANTIZATION_RANGE_FULL;
6201}
6202EXPORT_SYMBOL(drm_hdmi_avi_infoframe_quant_range);
6203
6008 * drm_hdmi_avi_infoframe_quant_range() - fill the HDMI AVI infoframe
6009 * quantization range information
6010 * @frame: HDMI AVI infoframe
6011 * @connector: the connector
6012 * @mode: DRM display mode
6013 * @rgb_quant_range: RGB quantization range (Q)
6014 */
6015void

--- 38 unchanged lines hidden (view full) ---

6054 frame->ycc_quantization_range =
6055 HDMI_YCC_QUANTIZATION_RANGE_LIMITED;
6056 else
6057 frame->ycc_quantization_range =
6058 HDMI_YCC_QUANTIZATION_RANGE_FULL;
6059}
6060EXPORT_SYMBOL(drm_hdmi_avi_infoframe_quant_range);
6061
6204/**
6205 * drm_hdmi_avi_infoframe_bars() - fill the HDMI AVI infoframe
6206 * bar information
6207 * @frame: HDMI AVI infoframe
6208 * @conn_state: connector state
6209 */
6210void
6211drm_hdmi_avi_infoframe_bars(struct hdmi_avi_infoframe *frame,
6212 const struct drm_connector_state *conn_state)
6213{
6214 frame->right_bar = conn_state->tv.margins.right;
6215 frame->left_bar = conn_state->tv.margins.left;
6216 frame->top_bar = conn_state->tv.margins.top;
6217 frame->bottom_bar = conn_state->tv.margins.bottom;
6218}
6219EXPORT_SYMBOL(drm_hdmi_avi_infoframe_bars);
6220
6221static enum hdmi_3d_structure
6222s3d_structure_from_display_mode(const struct drm_display_mode *mode)
6223{
6224 u32 layout = mode->flags & DRM_MODE_FLAG_3D_MASK;
6225
6226 switch (layout) {
6227 case DRM_MODE_FLAG_3D_FRAME_PACKING:
6228 return HDMI_3D_STRUCTURE_FRAME_PACKING;

--- 143 unchanged lines hidden ---
6062static enum hdmi_3d_structure
6063s3d_structure_from_display_mode(const struct drm_display_mode *mode)
6064{
6065 u32 layout = mode->flags & DRM_MODE_FLAG_3D_MASK;
6066
6067 switch (layout) {
6068 case DRM_MODE_FLAG_3D_FRAME_PACKING:
6069 return HDMI_3D_STRUCTURE_FRAME_PACKING;

--- 143 unchanged lines hidden ---