In preparation for adding hotpluggable bridges we need connectors to be created dynamically, both regular connectors and HDMI ones.
For non-HDMI connectors drm_connector_init() already has a dynamic variant, but there is none for HDMI. Creating one would be easy by creating a mostly-identical copy of drmm_connector_hdmi_init(), but it is a long function so there would be a lot of duplicated code. drmm_connector_hdmi_init() currently has 3 sections: 1. sanity checks 2. call drmm_connector_init() 3. initialize HDMI-specific fields not initialized at step 2 For the dynamic variant, sectons 1 and 3 would be an exact copy, while section 2 needs to be different. To avoid code duplication, split parts 1 and 3 to subfunctions. The next commit will introduce the dynamic variant. No functional changes. Just moving code around. Signed-off-by: Luca Ceresoli <[email protected]> --- Changes in v2: - expanded commit message to clarify rationale - rebased on current drm-misc-next, which required a full rewrite after the signature of drmm_connector_hdmi_init() changed in commit 400c9ede1ea4 ("drm/connector: Add drmm_connector_hdmi_init() with new signature") - renamed drm_connector_hdmi_init() to drm_connector_hdmi_initialize() as or it would look like an HDMI version of drm_connector_init() --- drivers/gpu/drm/drm_connector.c | 88 +++++++++++++++++++++++++---------------- 1 file changed, 55 insertions(+), 33 deletions(-) diff --git a/drivers/gpu/drm/drm_connector.c b/drivers/gpu/drm/drm_connector.c index d94c86bfed86..f5bd08640d25 100644 --- a/drivers/gpu/drm/drm_connector.c +++ b/drivers/gpu/drm/drm_connector.c @@ -542,37 +542,11 @@ int drmm_connector_init(struct drm_device *dev, } EXPORT_SYMBOL(drmm_connector_init); -/** - * drmm_connector_hdmi_init - Init a preallocated HDMI connector - * @dev: DRM device - * @connector: A pointer to the HDMI connector to init - * @funcs: callbacks for this connector - * @hdmi_funcs: HDMI-related callbacks and capabilities for this connector - * @connector_type: user visible type of the connector - * @ddc: optional pointer to the associated ddc adapter - * - * Initialises a preallocated HDMI connector. Connectors can be - * subclassed as part of driver connector objects. - * - * Cleanup is automatically handled with a call to - * drm_connector_cleanup() in a DRM-managed action. - * - * The connector structure should be allocated with drmm_kzalloc(). - * - * The @drm_connector_funcs.destroy hook must be NULL. - * - * Returns: - * Zero on success, error code on failure. - */ -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) +static int drm_connector_hdmi_sanity_checks(struct drm_device *dev, + struct drm_connector *connector, + const struct drm_connector_hdmi_funcs *hdmi_funcs, + int connector_type) { - int ret; - if (!hdmi_funcs) return -EINVAL; @@ -613,9 +587,15 @@ int drmm_connector_hdmi_init(struct drm_device *dev, connector_type == DRM_MODE_CONNECTOR_HDMIB)) return -EINVAL; - ret = drmm_connector_init(dev, connector, funcs, connector_type, ddc); - if (ret) - return ret; + return 0; +} + +/* Initialize HDMI-specific resources of a connector */ +static int drm_connector_hdmi_initialize(struct drm_device *dev, + struct drm_connector *connector, + const struct drm_connector_hdmi_funcs *hdmi_funcs) +{ + int ret; /* TODO: remove after conversion to new drmm_connector_hdmi_init() */ connector->hdmi.supported_formats = hdmi_funcs->supported_formats; @@ -684,6 +664,48 @@ int drmm_connector_hdmi_init(struct drm_device *dev, return 0; } + +/** + * drmm_connector_hdmi_init - Init a preallocated HDMI connector + * @dev: DRM device + * @connector: A pointer to the HDMI connector to init + * @funcs: callbacks for this connector + * @hdmi_funcs: HDMI-related callbacks and capabilities for this connector + * @connector_type: user visible type of the connector + * @ddc: optional pointer to the associated ddc adapter + * + * Initialises a preallocated HDMI connector. Connectors can be + * subclassed as part of driver connector objects. + * + * Cleanup is automatically handled with a call to + * drm_connector_cleanup() in a DRM-managed action. + * + * The connector structure should be allocated with drmm_kzalloc(). + * + * The @drm_connector_funcs.destroy hook must be NULL. + * + * Returns: + * Zero on success, error code on failure. + */ +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) +{ + int ret; + + ret = drm_connector_hdmi_sanity_checks(dev, connector, hdmi_funcs, connector_type); + if (ret) + return ret; + + ret = drmm_connector_init(dev, connector, funcs, connector_type, ddc); + if (ret) + return ret; + + return drm_connector_hdmi_initialize(dev, connector, hdmi_funcs); +} EXPORT_SYMBOL(drmm_connector_hdmi_init); /** -- 2.55.0
