It can be helpful to fully register the AUX channel as an i2c bus even before the bridge is created. Let's optionally allow bridges to do that. Specifically the case we're running into: - The panel driver wants to get its DDC bus at probe time. - The ti-sn65dsi86 MIPI-to-eDP bridge code, which provides the DDC bus, wants to get the panel at probe time. The next patches ("drm/bridge: ti-sn65dsi86: Promote the AUX channel to its own sub-dev") solves the chicken-and-egg problem by breaking the ti-sn65dsi86 driver into sub-devices, but in order for it to actually work we need the i2c bus to get registered at probe time and not in bridge attach time. Cc: Lyude Paul <lyude@xxxxxxxxxx> Cc: Thierry Reding <treding@xxxxxxxxxx> Signed-off-by: Douglas Anderson <dianders@xxxxxxxxxxxx> --- Changes in v6: - ("drm/dp: Allow an early call to register DDC i2c bus") new for v6. drivers/gpu/drm/drm_dp_helper.c | 67 +++++++++++++++++++++++++++------ include/drm/drm_dp_helper.h | 2 + 2 files changed, 57 insertions(+), 12 deletions(-) diff --git a/drivers/gpu/drm/drm_dp_helper.c b/drivers/gpu/drm/drm_dp_helper.c index cb56d74e9d38..830294f0b341 100644 --- a/drivers/gpu/drm/drm_dp_helper.c +++ b/drivers/gpu/drm/drm_dp_helper.c @@ -1757,6 +1757,49 @@ void drm_dp_aux_init(struct drm_dp_aux *aux) } EXPORT_SYMBOL(drm_dp_aux_init); +/** + * drm_dp_aux_register_ddc() - register the DDC parts of the aux channel + * @aux: DisplayPort AUX channel + * + * This can be called after drm_dp_aux_init() to fully register the ddc bus + * as an i2c adapter with the rest of Linux. + * + * If you don't explicitly call this function it will be done implicitly as + * part of drm_dp_aux_register(). + * + * Returns 0 on success or a negative error code on failure. + */ +int drm_dp_aux_register_ddc(struct drm_dp_aux *aux) +{ + WARN_ON_ONCE(!aux->dev); + + aux->ddc.class = I2C_CLASS_DDC; + aux->ddc.owner = THIS_MODULE; + aux->ddc.dev.parent = aux->dev; + + strlcpy(aux->ddc.name, aux->name ? aux->name : dev_name(aux->dev), + sizeof(aux->ddc.name)); + + return i2c_add_adapter(&aux->ddc); +} +EXPORT_SYMBOL(drm_dp_aux_register_ddc); + +/** + * drm_dp_aux_unregister_ddc() - unregister the DDC parts of the aux channel + * + * This is useful if you called drm_dp_aux_register_ddc(). If you let + * drm_dp_aux_register() implicitly register the DDC for you then you don't + * need to worry about calling this yourself. + * + * @aux: DisplayPort AUX channel + */ +void drm_dp_aux_unregister_ddc(struct drm_dp_aux *aux) +{ + i2c_del_adapter(&aux->ddc); + aux->ddc.dev.parent = NULL; +} +EXPORT_SYMBOL(drm_dp_aux_unregister_ddc); + /** * drm_dp_aux_register() - initialise and register aux channel * @aux: DisplayPort AUX channel @@ -1793,20 +1836,19 @@ int drm_dp_aux_register(struct drm_dp_aux *aux) if (!aux->ddc.algo) drm_dp_aux_init(aux); - aux->ddc.class = I2C_CLASS_DDC; - aux->ddc.owner = THIS_MODULE; - aux->ddc.dev.parent = aux->dev; - - strlcpy(aux->ddc.name, aux->name ? aux->name : dev_name(aux->dev), - sizeof(aux->ddc.name)); + /* + * Implicitly register if drm_dp_aux_register_ddc() wasn't already + * called (as evidenced by a NULL parent pointer). + */ + if (!aux->ddc.dev.parent) { + ret = drm_dp_aux_register_ddc(aux); + if (ret) + return ret; + } ret = drm_dp_aux_register_devnode(aux); - if (ret) - return ret; - - ret = i2c_add_adapter(&aux->ddc); if (ret) { - drm_dp_aux_unregister_devnode(aux); + drm_dp_aux_unregister_ddc(aux); return ret; } @@ -1821,7 +1863,8 @@ EXPORT_SYMBOL(drm_dp_aux_register); void drm_dp_aux_unregister(struct drm_dp_aux *aux) { drm_dp_aux_unregister_devnode(aux); - i2c_del_adapter(&aux->ddc); + if (aux->ddc.dev.parent) + drm_dp_aux_unregister_ddc(aux); } EXPORT_SYMBOL(drm_dp_aux_unregister); diff --git a/include/drm/drm_dp_helper.h b/include/drm/drm_dp_helper.h index e932b2c40095..d4d2d5e25bb7 100644 --- a/include/drm/drm_dp_helper.h +++ b/include/drm/drm_dp_helper.h @@ -2021,6 +2021,8 @@ bool drm_dp_lttpr_pre_emphasis_level_3_supported(const u8 caps[DP_LTTPR_PHY_CAP_ void drm_dp_remote_aux_init(struct drm_dp_aux *aux); void drm_dp_aux_init(struct drm_dp_aux *aux); +int drm_dp_aux_register_ddc(struct drm_dp_aux *aux); +void drm_dp_aux_unregister_ddc(struct drm_dp_aux *aux); int drm_dp_aux_register(struct drm_dp_aux *aux); void drm_dp_aux_unregister(struct drm_dp_aux *aux); -- 2.31.1.527.g47e6f16901-goog _______________________________________________ dri-devel mailing list dri-devel@xxxxxxxxxxxxxxxxxxxxx https://lists.freedesktop.org/mailman/listinfo/dri-devel