Re: [PATCH v2 2/7] drm/vc4: Switch DSI to the panel-bridge layer, and support bridges.
From: Boris Brezillon
Date: Fri May 12 2017 - 04:02:53 EST
On Thu, 11 May 2017 11:31:23 -0700
Eric Anholt <eric@xxxxxxxxxx> wrote:
> The newer version of the RPi panel driver is going to be a combination
> of a bridge and a panel, but we should also support panels without a
> bridge, so the panel-bridge layer lets us do that cleanly.
>
> v2: Drop "dev" argument.
>
> Signed-off-by: Eric Anholt <eric@xxxxxxxxxx>
> Acked-by: Daniel Vetter <daniel.vetter@xxxxxxxx>
Reviewed-by: Boris Brezillon <boris.brezillon@xxxxxxxxxxxxxxxxxx>
> ---
> drivers/gpu/drm/vc4/Kconfig | 2 +-
> drivers/gpu/drm/vc4/vc4_dsi.c | 154 ++++++------------------------------------
> 2 files changed, 21 insertions(+), 135 deletions(-)
>
> diff --git a/drivers/gpu/drm/vc4/Kconfig b/drivers/gpu/drm/vc4/Kconfig
> index b16aefe4a8d3..4361bdcfd28a 100644
> --- a/drivers/gpu/drm/vc4/Kconfig
> +++ b/drivers/gpu/drm/vc4/Kconfig
> @@ -7,7 +7,7 @@ config DRM_VC4
> select DRM_KMS_HELPER
> select DRM_KMS_CMA_HELPER
> select DRM_GEM_CMA_HELPER
> - select DRM_PANEL
> + select DRM_PANEL_BRIDGE
> select SND_PCM
> select SND_PCM_ELD
> select SND_SOC_GENERIC_DMAENGINE_PCM
> diff --git a/drivers/gpu/drm/vc4/vc4_dsi.c b/drivers/gpu/drm/vc4/vc4_dsi.c
> index deba62008fd0..fb54a9d10360 100644
> --- a/drivers/gpu/drm/vc4/vc4_dsi.c
> +++ b/drivers/gpu/drm/vc4/vc4_dsi.c
> @@ -503,8 +503,8 @@ struct vc4_dsi {
>
> struct mipi_dsi_host dsi_host;
> struct drm_encoder *encoder;
> - struct drm_connector *connector;
> - struct drm_panel *panel;
> + struct drm_bridge *bridge;
> + bool is_panel_bridge;
>
> void __iomem *regs;
>
> @@ -604,18 +604,6 @@ to_vc4_dsi_encoder(struct drm_encoder *encoder)
> return container_of(encoder, struct vc4_dsi_encoder, base.base);
> }
>
> -/* VC4 DSI connector KMS struct */
> -struct vc4_dsi_connector {
> - struct drm_connector base;
> - struct vc4_dsi *dsi;
> -};
> -
> -static inline struct vc4_dsi_connector *
> -to_vc4_dsi_connector(struct drm_connector *connector)
> -{
> - return container_of(connector, struct vc4_dsi_connector, base);
> -}
> -
> #define DSI_REG(reg) { reg, #reg }
> static const struct {
> u32 reg;
> @@ -723,79 +711,6 @@ int vc4_dsi_debugfs_regs(struct seq_file *m, void *unused)
> }
> #endif
>
> -static enum drm_connector_status
> -vc4_dsi_connector_detect(struct drm_connector *connector, bool force)
> -{
> - struct vc4_dsi_connector *vc4_connector =
> - to_vc4_dsi_connector(connector);
> - struct vc4_dsi *dsi = vc4_connector->dsi;
> -
> - if (dsi->panel)
> - return connector_status_connected;
> - else
> - return connector_status_disconnected;
> -}
> -
> -static void vc4_dsi_connector_destroy(struct drm_connector *connector)
> -{
> - drm_connector_unregister(connector);
> - drm_connector_cleanup(connector);
> -}
> -
> -static int vc4_dsi_connector_get_modes(struct drm_connector *connector)
> -{
> - struct vc4_dsi_connector *vc4_connector =
> - to_vc4_dsi_connector(connector);
> - struct vc4_dsi *dsi = vc4_connector->dsi;
> -
> - if (dsi->panel)
> - return drm_panel_get_modes(dsi->panel);
> -
> - return 0;
> -}
> -
> -static const struct drm_connector_funcs vc4_dsi_connector_funcs = {
> - .dpms = drm_atomic_helper_connector_dpms,
> - .detect = vc4_dsi_connector_detect,
> - .fill_modes = drm_helper_probe_single_connector_modes,
> - .destroy = vc4_dsi_connector_destroy,
> - .reset = drm_atomic_helper_connector_reset,
> - .atomic_duplicate_state = drm_atomic_helper_connector_duplicate_state,
> - .atomic_destroy_state = drm_atomic_helper_connector_destroy_state,
> -};
> -
> -static const struct drm_connector_helper_funcs vc4_dsi_connector_helper_funcs = {
> - .get_modes = vc4_dsi_connector_get_modes,
> -};
> -
> -static struct drm_connector *vc4_dsi_connector_init(struct drm_device *dev,
> - struct vc4_dsi *dsi)
> -{
> - struct drm_connector *connector;
> - struct vc4_dsi_connector *dsi_connector;
> -
> - dsi_connector = devm_kzalloc(dev->dev, sizeof(*dsi_connector),
> - GFP_KERNEL);
> - if (!dsi_connector)
> - return ERR_PTR(-ENOMEM);
> -
> - connector = &dsi_connector->base;
> -
> - dsi_connector->dsi = dsi;
> -
> - drm_connector_init(dev, connector, &vc4_dsi_connector_funcs,
> - DRM_MODE_CONNECTOR_DSI);
> - drm_connector_helper_add(connector, &vc4_dsi_connector_helper_funcs);
> -
> - connector->polled = 0;
> - connector->interlace_allowed = 0;
> - connector->doublescan_allowed = 0;
> -
> - drm_mode_connector_attach_encoder(connector, dsi->encoder);
> -
> - return connector;
> -}
> -
> static void vc4_dsi_encoder_destroy(struct drm_encoder *encoder)
> {
> drm_encoder_cleanup(encoder);
> @@ -893,12 +808,8 @@ static void vc4_dsi_encoder_disable(struct drm_encoder *encoder)
> struct vc4_dsi *dsi = vc4_encoder->dsi;
> struct device *dev = &dsi->pdev->dev;
>
> - drm_panel_disable(dsi->panel);
> -
> vc4_dsi_ulps(dsi, true);
>
> - drm_panel_unprepare(dsi->panel);
> -
> clk_disable_unprepare(dsi->pll_phy_clock);
> clk_disable_unprepare(dsi->escape_clock);
> clk_disable_unprepare(dsi->pixel_clock);
> @@ -929,12 +840,6 @@ static void vc4_dsi_encoder_enable(struct drm_encoder *encoder)
> return;
> }
>
> - ret = drm_panel_prepare(dsi->panel);
> - if (ret) {
> - DRM_ERROR("Panel failed to prepare\n");
> - return;
> - }
> -
> if (debug_dump_regs) {
> DRM_INFO("DSI regs before:\n");
> vc4_dsi_dump_regs(dsi);
> @@ -1184,13 +1089,6 @@ static void vc4_dsi_encoder_enable(struct drm_encoder *encoder)
> DRM_INFO("DSI regs after:\n");
> vc4_dsi_dump_regs(dsi);
> }
> -
> - ret = drm_panel_enable(dsi->panel);
> - if (ret) {
> - DRM_ERROR("Panel failed to enable\n");
> - drm_panel_unprepare(dsi->panel);
> - return;
> - }
> }
>
> static ssize_t vc4_dsi_host_transfer(struct mipi_dsi_host *host,
> @@ -1366,17 +1264,22 @@ static int vc4_dsi_host_attach(struct mipi_dsi_host *host,
> return 0;
> }
>
> - dsi->panel = of_drm_find_panel(device->dev.of_node);
> - if (!dsi->panel)
> - return 0;
> -
> - ret = drm_panel_attach(dsi->panel, dsi->connector);
> - if (ret != 0)
> - return ret;
> + dsi->bridge = of_drm_find_bridge(device->dev.of_node);
> + if (!dsi->bridge) {
> + struct drm_panel *panel =
> + of_drm_find_panel(device->dev.of_node);
>
> - drm_helper_hpd_irq_event(dsi->connector->dev);
> + dsi->bridge = drm_panel_bridge_add(panel,
> + DRM_MODE_CONNECTOR_DSI);
> + if (IS_ERR(dsi->bridge)) {
> + ret = PTR_ERR(dsi->bridge);
> + dsi->bridge = NULL;
> + return ret;
> + }
> + dsi->is_panel_bridge = true;
> + }
>
> - return 0;
> + return drm_bridge_attach(dsi->encoder, dsi->bridge, NULL);
> }
>
> static int vc4_dsi_host_detach(struct mipi_dsi_host *host,
> @@ -1384,15 +1287,9 @@ static int vc4_dsi_host_detach(struct mipi_dsi_host *host,
> {
> struct vc4_dsi *dsi = host_to_dsi(host);
>
> - if (dsi->panel) {
> - int ret = drm_panel_detach(dsi->panel);
> -
> - if (ret)
> - return ret;
> -
> - dsi->panel = NULL;
> -
> - drm_helper_hpd_irq_event(dsi->connector->dev);
> + if (dsi->is_panel_bridge) {
> + drm_panel_bridge_remove(dsi->bridge);
> + dsi->bridge = NULL;
> }
>
> return 0;
> @@ -1658,12 +1555,6 @@ static int vc4_dsi_bind(struct device *dev, struct device *master, void *data)
> DRM_MODE_ENCODER_DSI, NULL);
> drm_encoder_helper_add(dsi->encoder, &vc4_dsi_encoder_helper_funcs);
>
> - dsi->connector = vc4_dsi_connector_init(drm, dsi);
> - if (IS_ERR(dsi->connector)) {
> - ret = PTR_ERR(dsi->connector);
> - goto err_destroy_encoder;
> - }
> -
> dsi->dsi_host.ops = &vc4_dsi_host_ops;
> dsi->dsi_host.dev = dev;
>
> @@ -1674,11 +1565,6 @@ static int vc4_dsi_bind(struct device *dev, struct device *master, void *data)
> pm_runtime_enable(dev);
>
> return 0;
> -
> -err_destroy_encoder:
> - vc4_dsi_encoder_destroy(dsi->encoder);
> -
> - return ret;
> }
>
> static void vc4_dsi_unbind(struct device *dev, struct device *master,
> @@ -1690,7 +1576,7 @@ static void vc4_dsi_unbind(struct device *dev, struct device *master,
>
> pm_runtime_disable(dev);
>
> - vc4_dsi_connector_destroy(dsi->connector);
> + drm_bridge_remove(dsi->bridge);
> vc4_dsi_encoder_destroy(dsi->encoder);
>
> mipi_dsi_host_unregister(&dsi->dsi_host);