Skip to content

Commit

Permalink
drm/connector: hdmi: Add custom hook to filter TMDS character rate
Browse files Browse the repository at this point in the history
Most of the HDMI controllers have an upper TMDS character rate limit
they can't exceed. On "embedded"-grade display controllers, it will
typically be lower than what high-grade monitors can provide these days,
so drivers will filter the TMDS character rate based on the controller
capabilities.

To make that easier to handle for drivers, let's provide an optional
hook to be implemented by drivers so they can tell the HDMI controller
helpers if a given TMDS character rate is reachable for them or not.

This will then be useful to figure out the best format and bpc count for
a given mode.

Reviewed-by: Dave Stevenson <dave.stevenson@raspberrypi.com>
Reviewed-by: Dmitry Baryshkov <dmitry.baryshkov@linaro.org>
Link: https://patchwork.freedesktop.org/patch/msgid/20240527-kms-hdmi-connector-state-v15-13-c5af16c3aae2@kernel.org
Signed-off-by: Maxime Ripard <mripard@kernel.org>
  • Loading branch information
Maxime Ripard committed May 28, 2024
1 parent 62eea52 commit e5030a7
Show file tree
Hide file tree
Showing 5 changed files with 62 additions and 0 deletions.
9 changes: 9 additions & 0 deletions drivers/gpu/drm/display/drm_hdmi_state_helper.c
Original file line number Diff line number Diff line change
Expand Up @@ -53,11 +53,20 @@ hdmi_clock_valid(const struct drm_connector *connector,
const struct drm_display_mode *mode,
unsigned long long clock)
{
const struct drm_connector_hdmi_funcs *funcs = connector->hdmi.funcs;
const struct drm_display_info *info = &connector->display_info;

if (info->max_tmds_clock && clock > info->max_tmds_clock * 1000)
return MODE_CLOCK_HIGH;

if (funcs && funcs->tmds_char_rate_valid) {
enum drm_mode_status status;

status = funcs->tmds_char_rate_valid(connector, mode, clock);
if (status != MODE_OK)
return status;
}

return MODE_OK;
}

Expand Down
4 changes: 4 additions & 0 deletions drivers/gpu/drm/drm_connector.c
Original file line number Diff line number Diff line change
Expand Up @@ -457,6 +457,7 @@ EXPORT_SYMBOL(drmm_connector_init);
* @dev: DRM device
* @connector: A pointer to the HDMI connector to init
* @funcs: callbacks for this connector
* @hdmi_funcs: HDMI-related callbacks for this connector
* @connector_type: user visible type of the connector
* @ddc: optional pointer to the associated ddc adapter
* @supported_formats: Bitmask of @hdmi_colorspace listing supported output formats
Expand All @@ -476,6 +477,7 @@ EXPORT_SYMBOL(drmm_connector_init);
int drmm_connector_hdmi_init(struct drm_device *dev,
struct drm_connector *connector,
const struct drm_connector_funcs *funcs,
const struct drm_connector_hdmi_funcs *hdmi_funcs,
int connector_type,
struct i2c_adapter *ddc,
unsigned long supported_formats,
Expand Down Expand Up @@ -512,6 +514,8 @@ int drmm_connector_hdmi_init(struct drm_device *dev,
if (max_bpc > 8)
drm_connector_attach_hdr_output_metadata_property(connector);

connector->hdmi.funcs = hdmi_funcs;

return 0;
}
EXPORT_SYMBOL(drmm_connector_hdmi_init);
Expand Down
14 changes: 14 additions & 0 deletions drivers/gpu/drm/tests/drm_connector_test.c
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,9 @@ struct drm_connector_init_priv {
struct i2c_adapter ddc;
};

static const struct drm_connector_hdmi_funcs dummy_hdmi_funcs = {
};

static const struct drm_connector_funcs dummy_funcs = {
.atomic_destroy_state = drm_atomic_helper_connector_destroy_state,
.atomic_duplicate_state = drm_atomic_helper_connector_duplicate_state,
Expand Down Expand Up @@ -189,6 +192,7 @@ static void drm_test_connector_hdmi_init_valid(struct kunit *test)

ret = drmm_connector_hdmi_init(&priv->drm, &priv->connector,
&dummy_funcs,
&dummy_hdmi_funcs,
DRM_MODE_CONNECTOR_HDMIA,
&priv->ddc,
BIT(HDMI_COLORSPACE_RGB),
Expand All @@ -207,6 +211,7 @@ static void drm_test_connector_hdmi_init_null_ddc(struct kunit *test)

ret = drmm_connector_hdmi_init(&priv->drm, &priv->connector,
&dummy_funcs,
&dummy_hdmi_funcs,
DRM_MODE_CONNECTOR_HDMIA,
NULL,
BIT(HDMI_COLORSPACE_RGB),
Expand All @@ -225,6 +230,7 @@ static void drm_test_connector_hdmi_init_bpc_invalid(struct kunit *test)

ret = drmm_connector_hdmi_init(&priv->drm, &priv->connector,
&dummy_funcs,
&dummy_hdmi_funcs,
DRM_MODE_CONNECTOR_HDMIA,
&priv->ddc,
BIT(HDMI_COLORSPACE_RGB),
Expand All @@ -243,6 +249,7 @@ static void drm_test_connector_hdmi_init_bpc_null(struct kunit *test)

ret = drmm_connector_hdmi_init(&priv->drm, &priv->connector,
&dummy_funcs,
&dummy_hdmi_funcs,
DRM_MODE_CONNECTOR_HDMIA,
&priv->ddc,
BIT(HDMI_COLORSPACE_RGB),
Expand All @@ -266,6 +273,7 @@ static void drm_test_connector_hdmi_init_bpc_8(struct kunit *test)

ret = drmm_connector_hdmi_init(&priv->drm, connector,
&dummy_funcs,
&dummy_hdmi_funcs,
DRM_MODE_CONNECTOR_HDMIA,
&priv->ddc,
BIT(HDMI_COLORSPACE_RGB),
Expand Down Expand Up @@ -305,6 +313,7 @@ static void drm_test_connector_hdmi_init_bpc_10(struct kunit *test)

ret = drmm_connector_hdmi_init(&priv->drm, connector,
&dummy_funcs,
&dummy_hdmi_funcs,
DRM_MODE_CONNECTOR_HDMIA,
&priv->ddc,
BIT(HDMI_COLORSPACE_RGB),
Expand Down Expand Up @@ -344,6 +353,7 @@ static void drm_test_connector_hdmi_init_bpc_12(struct kunit *test)

ret = drmm_connector_hdmi_init(&priv->drm, connector,
&dummy_funcs,
&dummy_hdmi_funcs,
DRM_MODE_CONNECTOR_HDMIA,
&priv->ddc,
BIT(HDMI_COLORSPACE_RGB),
Expand Down Expand Up @@ -378,6 +388,7 @@ static void drm_test_connector_hdmi_init_formats_empty(struct kunit *test)

ret = drmm_connector_hdmi_init(&priv->drm, &priv->connector,
&dummy_funcs,
&dummy_hdmi_funcs,
DRM_MODE_CONNECTOR_HDMIA,
&priv->ddc,
0,
Expand All @@ -396,6 +407,7 @@ static void drm_test_connector_hdmi_init_formats_no_rgb(struct kunit *test)

ret = drmm_connector_hdmi_init(&priv->drm, &priv->connector,
&dummy_funcs,
&dummy_hdmi_funcs,
DRM_MODE_CONNECTOR_HDMIA,
&priv->ddc,
BIT(HDMI_COLORSPACE_YUV422),
Expand All @@ -415,6 +427,7 @@ static void drm_test_connector_hdmi_init_type_valid(struct kunit *test)

ret = drmm_connector_hdmi_init(&priv->drm, &priv->connector,
&dummy_funcs,
&dummy_hdmi_funcs,
connector_type,
&priv->ddc,
BIT(HDMI_COLORSPACE_RGB),
Expand Down Expand Up @@ -448,6 +461,7 @@ static void drm_test_connector_hdmi_init_type_invalid(struct kunit *test)

ret = drmm_connector_hdmi_init(&priv->drm, &priv->connector,
&dummy_funcs,
&dummy_hdmi_funcs,
connector_type,
&priv->ddc,
BIT(HDMI_COLORSPACE_RGB),
Expand Down
4 changes: 4 additions & 0 deletions drivers/gpu/drm/tests/drm_hdmi_state_helper_test.c
Original file line number Diff line number Diff line change
Expand Up @@ -112,6 +112,9 @@ static int set_connector_edid(struct kunit *test, struct drm_connector *connecto
return 0;
}

static const struct drm_connector_hdmi_funcs dummy_connector_hdmi_funcs = {
};

static int dummy_connector_get_modes(struct drm_connector *connector)
{
struct drm_atomic_helper_connector_hdmi_priv *priv =
Expand Down Expand Up @@ -194,6 +197,7 @@ drm_atomic_helper_connector_hdmi_init(struct kunit *test,
conn = &priv->connector;
ret = drmm_connector_hdmi_init(drm, conn,
&dummy_connector_funcs,
&dummy_connector_hdmi_funcs,
DRM_MODE_CONNECTOR_HDMIA,
NULL,
formats,
Expand Down
31 changes: 31 additions & 0 deletions include/drm/drm_connector.h
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@ struct drm_connector_helper_funcs;
struct drm_modeset_acquire_ctx;
struct drm_device;
struct drm_crtc;
struct drm_display_mode;
struct drm_encoder;
struct drm_panel;
struct drm_property;
Expand Down Expand Up @@ -1057,6 +1058,30 @@ struct drm_connector_state {
} hdmi;
};

/**
* struct drm_connector_hdmi_funcs - drm_hdmi_connector control functions
*/
struct drm_connector_hdmi_funcs {
/**
* @tmds_char_rate_valid:
*
* This callback is invoked at atomic_check time to figure out
* whether a particular TMDS character rate is supported by the
* driver.
*
* The @tmds_char_rate_valid callback is optional.
*
* Returns:
*
* Either &drm_mode_status.MODE_OK or one of the failure reasons
* in &enum drm_mode_status.
*/
enum drm_mode_status
(*tmds_char_rate_valid)(const struct drm_connector *connector,
const struct drm_display_mode *mode,
unsigned long long tmds_rate);
};

/**
* struct drm_connector_funcs - control connectors on a given device
*
Expand Down Expand Up @@ -1929,6 +1954,11 @@ struct drm_connector {
* supported by the controller.
*/
unsigned long supported_formats;

/**
* @funcs: HDMI connector Control Functions
*/
const struct drm_connector_hdmi_funcs *funcs;
} hdmi;
};

Expand All @@ -1951,6 +1981,7 @@ int drmm_connector_init(struct drm_device *dev,
int drmm_connector_hdmi_init(struct drm_device *dev,
struct drm_connector *connector,
const struct drm_connector_funcs *funcs,
const struct drm_connector_hdmi_funcs *hdmi_funcs,
int connector_type,
struct i2c_adapter *ddc,
unsigned long supported_formats,
Expand Down

0 comments on commit e5030a7

Please sign in to comment.