b.liu | e958203 | 2025-04-17 19:18:16 +0800 | [diff] [blame] | 1 | From 7c5c4f891ce4746b52d95d9340c7cae063a48350 Mon Sep 17 00:00:00 2001 |
| 2 | From: Laurentiu Palcu <laurentiu.palcu@nxp.com> |
| 3 | Date: Mon, 4 Nov 2019 13:18:48 +0200 |
| 4 | Subject: [PATCH] drm/imx/hdp: add hdr10 metadata property |
| 5 | |
| 6 | The HDR_OUTPUT_METADATA property is needed in order for userspace to instruct |
| 7 | the sink to switch to HDR10 mode. |
| 8 | |
| 9 | Signed-off-by: Laurentiu Palcu <laurentiu.palcu@nxp.com> |
| 10 | --- |
| 11 | drivers/gpu/drm/bridge/cadence/cdns-hdmi-core.c | 72 +++++++++++++++++++++++++ |
| 12 | drivers/gpu/drm/imx/cdn-mhdp-imxdrv.c | 4 ++ |
| 13 | include/drm/bridge/cdns-mhdp-common.h | 1 + |
| 14 | 3 files changed, 77 insertions(+) |
| 15 | |
| 16 | --- a/drivers/gpu/drm/bridge/cadence/cdns-hdmi-core.c |
| 17 | +++ b/drivers/gpu/drm/bridge/cadence/cdns-hdmi-core.c |
| 18 | @@ -170,6 +170,35 @@ static void hdmi_vendor_info_set(struct |
| 19 | cdns_mhdp_infoframe_set(mhdp, 3, sizeof(buf), buf, HDMI_INFOFRAME_TYPE_VENDOR); |
| 20 | } |
| 21 | |
| 22 | +static void hdmi_drm_info_set(struct cdns_mhdp_device *mhdp) |
| 23 | +{ |
| 24 | + struct drm_connector_state *conn_state; |
| 25 | + struct hdmi_drm_infoframe frame; |
| 26 | + u8 buf[32]; |
| 27 | + int ret; |
| 28 | + |
| 29 | + conn_state = mhdp->connector.base.state; |
| 30 | + |
| 31 | + if (!conn_state->hdr_output_metadata) |
| 32 | + return; |
| 33 | + |
| 34 | + ret = drm_hdmi_infoframe_set_hdr_metadata(&frame, conn_state); |
| 35 | + if (ret < 0) { |
| 36 | + DRM_DEBUG_KMS("couldn't set HDR metadata in infoframe\n"); |
| 37 | + return; |
| 38 | + } |
| 39 | + |
| 40 | + ret = hdmi_drm_infoframe_pack(&frame, buf + 1, sizeof(buf) - 1); |
| 41 | + if (ret < 0) { |
| 42 | + DRM_DEBUG_KMS("couldn't pack HDR infoframe\n"); |
| 43 | + return; |
| 44 | + } |
| 45 | + |
| 46 | + buf[0] = 0; |
| 47 | + cdns_mhdp_infoframe_set(mhdp, 3, sizeof(buf), |
| 48 | + buf, HDMI_INFOFRAME_TYPE_DRM); |
| 49 | +} |
| 50 | + |
| 51 | void cdns_hdmi_mode_set(struct cdns_mhdp_device *mhdp) |
| 52 | { |
| 53 | struct drm_display_mode *mode = &mhdp->mode; |
| 54 | @@ -207,6 +236,8 @@ void cdns_hdmi_mode_set(struct cdns_mhdp |
| 55 | /* vendor info frame is enable only when HDMI1.4 4K mode */ |
| 56 | hdmi_vendor_info_set(mhdp, mode); |
| 57 | |
| 58 | + hdmi_drm_info_set(mhdp); |
| 59 | + |
| 60 | ret = cdns_hdmi_mode_config(mhdp, mode, &mhdp->video_info); |
| 61 | if (ret < 0) { |
| 62 | DRM_ERROR("CDN_API_HDMITX_SetVic_blocking ret = %d\n", ret); |
| 63 | @@ -262,6 +293,40 @@ static int cdns_hdmi_connector_get_modes |
| 64 | return num_modes; |
| 65 | } |
| 66 | |
| 67 | +static bool blob_equal(const struct drm_property_blob *a, |
| 68 | + const struct drm_property_blob *b) |
| 69 | +{ |
| 70 | + if (a && b) |
| 71 | + return a->length == b->length && |
| 72 | + !memcmp(a->data, b->data, a->length); |
| 73 | + |
| 74 | + return !a == !b; |
| 75 | +} |
| 76 | + |
| 77 | +static int cdns_hdmi_connector_atomic_check(struct drm_connector *connector, |
| 78 | + struct drm_atomic_state *state) |
| 79 | +{ |
| 80 | + struct drm_connector_state *new_con_state = |
| 81 | + drm_atomic_get_new_connector_state(state, connector); |
| 82 | + struct drm_connector_state *old_con_state = |
| 83 | + drm_atomic_get_old_connector_state(state, connector); |
| 84 | + struct drm_crtc *crtc = new_con_state->crtc; |
| 85 | + struct drm_crtc_state *new_crtc_state; |
| 86 | + |
| 87 | + if (!blob_equal(new_con_state->hdr_output_metadata, |
| 88 | + old_con_state->hdr_output_metadata)) { |
| 89 | + new_crtc_state = drm_atomic_get_crtc_state(state, crtc); |
| 90 | + if (IS_ERR(new_crtc_state)) |
| 91 | + return PTR_ERR(new_crtc_state); |
| 92 | + |
| 93 | + new_crtc_state->mode_changed = |
| 94 | + !new_con_state->hdr_output_metadata || |
| 95 | + !old_con_state->hdr_output_metadata; |
| 96 | + } |
| 97 | + |
| 98 | + return 0; |
| 99 | +} |
| 100 | + |
| 101 | static const struct drm_connector_funcs cdns_hdmi_connector_funcs = { |
| 102 | .fill_modes = drm_helper_probe_single_connector_modes, |
| 103 | .detect = cdns_hdmi_connector_detect, |
| 104 | @@ -273,11 +338,13 @@ static const struct drm_connector_funcs |
| 105 | |
| 106 | static const struct drm_connector_helper_funcs cdns_hdmi_connector_helper_funcs = { |
| 107 | .get_modes = cdns_hdmi_connector_get_modes, |
| 108 | + .atomic_check = cdns_hdmi_connector_atomic_check, |
| 109 | }; |
| 110 | |
| 111 | static int cdns_hdmi_bridge_attach(struct drm_bridge *bridge) |
| 112 | { |
| 113 | struct cdns_mhdp_device *mhdp = bridge->driver_private; |
| 114 | + struct drm_mode_config *config = &bridge->dev->mode_config; |
| 115 | struct drm_encoder *encoder = bridge->encoder; |
| 116 | struct drm_connector *connector = &mhdp->connector.base; |
| 117 | |
| 118 | @@ -289,6 +356,11 @@ static int cdns_hdmi_bridge_attach(struc |
| 119 | drm_connector_init(bridge->dev, connector, &cdns_hdmi_connector_funcs, |
| 120 | DRM_MODE_CONNECTOR_HDMIA); |
| 121 | |
| 122 | + if (!strncmp("imx8mq-hdmi", mhdp->plat_data->plat_name, 11)) |
| 123 | + drm_object_attach_property(&connector->base, |
| 124 | + config->hdr_output_metadata_property, |
| 125 | + 0); |
| 126 | + |
| 127 | drm_connector_attach_encoder(connector, encoder); |
| 128 | |
| 129 | return 0; |
| 130 | --- a/drivers/gpu/drm/imx/cdn-mhdp-imxdrv.c |
| 131 | +++ b/drivers/gpu/drm/imx/cdn-mhdp-imxdrv.c |
| 132 | @@ -54,6 +54,7 @@ static const struct drm_encoder_funcs cd |
| 133 | }; |
| 134 | |
| 135 | static struct cdns_plat_data imx8mq_hdmi_drv_data = { |
| 136 | + .plat_name = "imx8mq-hdmi", |
| 137 | .bind = cdns_hdmi_bind, |
| 138 | .unbind = cdns_hdmi_unbind, |
| 139 | .phy_set = cdns_hdmi_phy_set_imx8mq, |
| 140 | @@ -61,6 +62,7 @@ static struct cdns_plat_data imx8mq_hdmi |
| 141 | }; |
| 142 | |
| 143 | static struct cdns_plat_data imx8mq_dp_drv_data = { |
| 144 | + .plat_name = "imx8mq-dp", |
| 145 | .bind = cdns_dp_bind, |
| 146 | .unbind = cdns_dp_unbind, |
| 147 | .phy_set = cdns_dp_phy_set_imx8mq, |
| 148 | @@ -68,6 +70,7 @@ static struct cdns_plat_data imx8mq_dp_d |
| 149 | }; |
| 150 | |
| 151 | static struct cdns_plat_data imx8qm_hdmi_drv_data = { |
| 152 | + .plat_name = "imx8qm-hdmi", |
| 153 | .bind = cdns_hdmi_bind, |
| 154 | .unbind = cdns_hdmi_unbind, |
| 155 | .phy_set = cdns_hdmi_phy_set_imx8qm, |
| 156 | @@ -81,6 +84,7 @@ static struct cdns_plat_data imx8qm_hdmi |
| 157 | }; |
| 158 | |
| 159 | static struct cdns_plat_data imx8qm_dp_drv_data = { |
| 160 | + .plat_name = "imx8qm-dp", |
| 161 | .bind = cdns_dp_bind, |
| 162 | .unbind = cdns_dp_unbind, |
| 163 | .phy_set = cdns_dp_phy_set_imx8qm, |
| 164 | --- a/include/drm/bridge/cdns-mhdp-common.h |
| 165 | +++ b/include/drm/bridge/cdns-mhdp-common.h |
| 166 | @@ -652,6 +652,7 @@ struct cdns_plat_data { |
| 167 | int bus_type; |
| 168 | int video_format; |
| 169 | char is_dp; |
| 170 | + char *plat_name; |
| 171 | }; |
| 172 | |
| 173 | struct cdns_mhdp_device { |