From patchwork Tue May 30 12:13:46 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Sharma, Shashank" X-Patchwork-Id: 9754429 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork.web.codeaurora.org (Postfix) with ESMTP id 65939602F0 for ; Tue, 30 May 2017 12:11:39 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 5829728455 for ; Tue, 30 May 2017 12:11:39 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 4D1602847A; Tue, 30 May 2017 12:11:39 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-4.2 required=2.0 tests=BAYES_00, RCVD_IN_DNSWL_MED autolearn=unavailable version=3.3.1 Received: from gabe.freedesktop.org (gabe.freedesktop.org [131.252.210.177]) (using TLSv1.2 with cipher DHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.wl.linuxfoundation.org (Postfix) with ESMTPS id C76C028455 for ; Tue, 30 May 2017 12:11:38 +0000 (UTC) Received: from gabe.freedesktop.org (localhost [127.0.0.1]) by gabe.freedesktop.org (Postfix) with ESMTP id 3D23189F1B; Tue, 30 May 2017 12:11:03 +0000 (UTC) X-Original-To: intel-gfx@lists.freedesktop.org Delivered-To: intel-gfx@lists.freedesktop.org Received: from mga02.intel.com (mga02.intel.com [134.134.136.20]) by gabe.freedesktop.org (Postfix) with ESMTPS id A973489ED6; Tue, 30 May 2017 12:10:55 +0000 (UTC) Received: from fmsmga001.fm.intel.com ([10.253.24.23]) by orsmga101.jf.intel.com with ESMTP/TLS/DHE-RSA-AES256-GCM-SHA384; 30 May 2017 05:10:55 -0700 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos; i="5.38,418,1491289200"; d="scan'208"; a="1154430344" Received: from shashanks-linuxbox.iind.intel.com ([10.223.161.29]) by fmsmga001.fm.intel.com with ESMTP; 30 May 2017 05:10:53 -0700 From: Shashank Sharma To: dri-devel@lists.freedesktop.org, intel-gfx@lists.freedesktop.org Date: Tue, 30 May 2017 17:43:46 +0530 Message-Id: <1496146430-11430-8-git-send-email-shashank.sharma@intel.com> X-Mailer: git-send-email 2.7.4 In-Reply-To: <1496146430-11430-1-git-send-email-shashank.sharma@intel.com> References: <1496146430-11430-1-git-send-email-shashank.sharma@intel.com> Cc: Jose Abreu Subject: [Intel-gfx] [PATCH v2 07/11] drm: add ycbcr helper functions X-BeenThere: intel-gfx@lists.freedesktop.org X-Mailman-Version: 2.1.18 Precedence: list List-Id: Intel graphics driver community testing & development List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , MIME-Version: 1.0 Errors-To: intel-gfx-bounces@lists.freedesktop.org Sender: "Intel-gfx" X-Virus-Scanned: ClamAV using ClamSMTP This patch adds helper functions for ycbcr HDMI output handling. These functions provide functionality like: - getting the highest subsamled ycbcr output - getting the lowest subsamled ycbcr output - check if a given source and sink combination can support any YCBCR output - check if a given source and sink combination can support a particular YCBCR output - check if a give mode can be driven in YCBCR420 subsampling. These functions will be used in next few patches in this series from I915 driver. V2: Added YCBCR functions as helpers in DRM layer, instead of keeping it in I915 layer Cc: Ville Syrjala Cc: Jose Abreu Signed-off-by: Shashank Sharma --- drivers/gpu/drm/drm_edid.c | 2 +- drivers/gpu/drm/drm_modes.c | 177 ++++++++++++++++++++++++++++++++++++++++++++ include/drm/drm_edid.h | 1 + include/drm/drm_modes.h | 16 ++++ 4 files changed, 195 insertions(+), 1 deletion(-) diff --git a/drivers/gpu/drm/drm_edid.c b/drivers/gpu/drm/drm_edid.c index 98e00ce..a9d9b1a 100644 --- a/drivers/gpu/drm/drm_edid.c +++ b/drivers/gpu/drm/drm_edid.c @@ -2949,7 +2949,7 @@ u8 drm_match_cea_mode(const struct drm_display_mode *to_match) } EXPORT_SYMBOL(drm_match_cea_mode); -static bool drm_valid_cea_vic(u8 vic) +bool drm_valid_cea_vic(u8 vic) { return vic > 0 && vic < ARRAY_SIZE(edid_cea_modes); } diff --git a/drivers/gpu/drm/drm_modes.c b/drivers/gpu/drm/drm_modes.c index f2493b9..43c630e 100644 --- a/drivers/gpu/drm/drm_modes.c +++ b/drivers/gpu/drm/drm_modes.c @@ -1576,3 +1576,180 @@ int drm_mode_convert_umode(struct drm_display_mode *out, out: return ret; } + +/** + * drm_mode_is_420 - if a given videomode can be supported in YCBCR420 + * output format also + * + * @connector: drm connector under action. + * @mode: video mode to be tested. + * + * Returns: + * true if the mode can support YCBCR420 output + * false if not. + */ +bool drm_mode_is_420(struct drm_display_info *display, + struct drm_display_mode *mode) +{ + u8 vic = drm_match_cea_mode(mode); + u32 *vcb_map; + u8 index; + + if (!drm_valid_cea_vic(vic)) + return false; + /* + * ycbcr420_vcb_modes is a fix position 128 bit bitmap. This indicates + * support for ycbcr420 output per VIC. Arrangement is bit[n] indicates + * if vic[n+1] supports ycbcr420 output. + * ycbcr420_vcb_modes[0] = |VIC=32 |VIC=31 |............|VIC=2 |VIC=1 | + * ycbcr420_vcb_modes[1] = |VIC=64 |VIC=63 |............|VIC=34|VIC=33| + * ycbcr420_vcb_modes[2] = |VIC=96 |VIC=95 |............|VIC=66|VIC=65| + * ycbcr420_vcb_modes[3] = |VIC=128|VIC=127|............|VIC=34|VIC=97| + */ + vcb_map = &(display->hdmi.ycbcr420_vcb_modes[(vic - 1) / 32]); + index = (vic - 1) % 32; + return *vcb_map & (1 << index); +} + +/** + * drm_can_support_this_ycbcr_output - can a given source and sink combination + * support a particular YCBCR output type. + * + * @display: sink information. + * @mode: video mode from modeset + * @type: enum indicating YCBCR output type + * @source_outputs: bitmap of source supported HDMI output formats. + * + * Returns: + * true on success. + * false on failure. + */ +bool drm_can_support_this_ycbcr_output(struct drm_display_info *display, + struct drm_display_mode *mode, + enum drm_hdmi_output_type type, + u32 source_outputs) +{ + /* YCBCR420 output support can be per mode basis */ + if (type == DRM_HDMI_OUTPUT_YCBCR420 && + !drm_mode_is_420(display, mode)) + return false; + + return display->color_formats & source_outputs & type; +} + +/** + * drm_can_support_any_ycbcr_output - can a given source and sink combination + * support any YCBCR outputs. + * + * @display: sink information. + * @source_outputs: bitmap of source supported HDMI output formats. + * + * Returns: + * true on success. + * false on failure. + */ +bool drm_can_support_any_ycbcr_output(struct drm_display_info *display, + u32 source_outputs) +{ + u32 supported_formats; + + if (!source_outputs || !display->color_formats) { + DRM_DEBUG_KMS("Source/Sink doesn't support any output ?\n"); + return DRM_HDMI_OUTPUT_INVALID; + } + + /* Get the common supported fromats between source and sink */ + supported_formats = display->color_formats & source_outputs; + if (!supported_formats || (supported_formats == + DRM_COLOR_FORMAT_RGB444)) { + DRM_ERROR("No common YCBCR formats between source and sink\n"); + return false; + } + + DRM_DEBUG_KMS("Src and Sink combination can support YCBCR output\n"); + return true; +} + +/** + * drm_get_highest_quality_ycbcr_supported - get the ycbcr output mode + * with highest subsampling rate + * @display: struct drm_display_info from current connector + * @mode: video mode from modeset + * @source_output_map: bitmap of supported HDMI output modes from source + * + * Finds the best possible ycbcr output mode (based on subsampling), for the + * given source and sink combination. + * + * Returns: + * enum corresponding to best output mode on success. + * DRM_HDMI_OUTPUT_INVALID on failure. + */ +enum drm_hdmi_output_type +drm_get_highest_quality_ycbcr_supported(struct drm_display_info *display, + struct drm_display_mode *mode, + u32 source_output_map) +{ + enum drm_hdmi_output_type output = DRM_HDMI_OUTPUT_INVALID; + u32 supported_formats = source_output_map & display->color_formats; + + /* + * Get the ycbcr output with the highest possible subsampling rate. + * Preference should go as: + * ycbcr 444 + * ycbcr 422 + * ycbcr 420 + */ + if (supported_formats & DRM_COLOR_FORMAT_YCRCB444) + output = DRM_COLOR_FORMAT_YCRCB444; + else if (supported_formats & DRM_COLOR_FORMAT_YCRCB422) + output = DRM_COLOR_FORMAT_YCRCB422; + else if (supported_formats & DRM_COLOR_FORMAT_YCRCB420 && + drm_mode_is_420(display, mode)) + output = DRM_COLOR_FORMAT_YCRCB420; + + DRM_DEBUG_KMS("Highest subsampled YCBCR mode supported is %s\n", + drm_get_hdmi_output_name(supported_formats)); + return output; +} + +/** + * drm_get_lowest_quality_ycbcr_supported - get the ycbcr output mode + * with lowest subsampling rate + * @display: struct drm_display_info from current connector + * @mode: video mode from modeset + * @source_output_map: bitmap of supported HDMI output modes from source + * + * Finds the lowest possible ycbcr output mode (based on subsampling), for the + * given source and sink combination. + * + * Returns: + * enum corresponding to best output mode on success. + * DRM_HDMI_OUTPUT_INVALID on failure. + */ +enum drm_hdmi_output_type +drm_get_lowest_quality_ycbcr_supported(struct drm_display_info *display, + struct drm_display_mode *mode, + u32 source_output_map) +{ + enum drm_hdmi_output_type output = DRM_HDMI_OUTPUT_INVALID; + u32 supported_formats = source_output_map & display->color_formats; + + /* + * Get the ycbcr output with the lowest possible subsampling rate. + * Preference should go as: + * ycbcr 420 + * ycbcr 422 + * ycbcr 444 + */ + if (supported_formats & DRM_COLOR_FORMAT_YCRCB420 && + drm_mode_is_420(display, mode)) + output = DRM_HDMI_OUTPUT_YCBCR420; + else if (display->color_formats & DRM_COLOR_FORMAT_YCRCB422) + output = DRM_HDMI_OUTPUT_YCBCR422; + else if (display->color_formats & DRM_COLOR_FORMAT_YCRCB444) + output = DRM_HDMI_OUTPUT_YCBCR420; + + DRM_DEBUG_KMS("Lowest subsampled YCBCR mode supported is %s\n", + drm_get_hdmi_output_name(supported_formats)); + return output; +} diff --git a/include/drm/drm_edid.h b/include/drm/drm_edid.h index 8980366..d025d56 100644 --- a/include/drm/drm_edid.h +++ b/include/drm/drm_edid.h @@ -468,6 +468,7 @@ int drm_add_edid_modes(struct drm_connector *connector, struct edid *edid); u8 drm_match_cea_mode(const struct drm_display_mode *to_match); enum hdmi_picture_aspect drm_get_cea_aspect_ratio(const u8 video_code); +bool drm_valid_cea_vic(u8 vic); bool drm_detect_hdmi_monitor(struct edid *edid); bool drm_detect_monitor_audio(struct edid *edid); bool drm_rgb_quant_range_selectable(struct edid *edid); diff --git a/include/drm/drm_modes.h b/include/drm/drm_modes.h index 6dd34280..fc1aec0 100644 --- a/include/drm/drm_modes.h +++ b/include/drm/drm_modes.h @@ -433,6 +433,22 @@ int drm_mode_convert_umode(struct drm_display_mode *out, const struct drm_mode_modeinfo *in); void drm_mode_probed_add(struct drm_connector *connector, struct drm_display_mode *mode); void drm_mode_debug_printmodeline(const struct drm_display_mode *mode); +bool drm_mode_is_420(struct drm_display_info *display, + struct drm_display_mode *mode); +bool drm_can_support_this_ycbcr_output(struct drm_display_info *display, + struct drm_display_mode *mode, + enum drm_hdmi_output_type type, + u32 source_outputs); +bool drm_can_support_any_ycbcr_output(struct drm_display_info *display, + u32 source_outputs); +enum drm_hdmi_output_type +drm_get_highest_quality_ycbcr_supported(struct drm_display_info *display, + struct drm_display_mode *mode, + u32 source_output_map); +enum drm_hdmi_output_type +drm_get_lowest_quality_ycbcr_supported(struct drm_display_info *display, + struct drm_display_mode *mode, + u32 source_output_map); struct drm_display_mode *drm_cvt_mode(struct drm_device *dev, int hdisplay, int vdisplay, int vrefresh,