Commit f89c696e authored by Enric Balletbo i Serra's avatar Enric Balletbo i Serra Committed by Chun-Kuang Hu

drm/mediatek: mtk_dpi: Convert to bridge driver

Convert mtk_dpi to a bridge driver with built-in encoder support for
compatibility with existing component drivers.
Signed-off-by: default avatarEnric Balletbo i Serra <enric.balletbo@collabora.com>
Signed-off-by: default avatarChun-Kuang Hu <chunkuang.hu@kernel.org>
parent 8b465f01
...@@ -64,6 +64,7 @@ enum mtk_dpi_out_color_format { ...@@ -64,6 +64,7 @@ enum mtk_dpi_out_color_format {
struct mtk_dpi { struct mtk_dpi {
struct mtk_ddp_comp ddp_comp; struct mtk_ddp_comp ddp_comp;
struct drm_encoder encoder; struct drm_encoder encoder;
struct drm_bridge bridge;
struct drm_bridge *next_bridge; struct drm_bridge *next_bridge;
void __iomem *regs; void __iomem *regs;
struct device *dev; struct device *dev;
...@@ -83,9 +84,9 @@ struct mtk_dpi { ...@@ -83,9 +84,9 @@ struct mtk_dpi {
int refcount; int refcount;
}; };
static inline struct mtk_dpi *mtk_dpi_from_encoder(struct drm_encoder *e) static inline struct mtk_dpi *bridge_to_dpi(struct drm_bridge *b)
{ {
return container_of(e, struct mtk_dpi, encoder); return container_of(b, struct mtk_dpi, bridge);
} }
enum mtk_dpi_polarity { enum mtk_dpi_polarity {
...@@ -521,50 +522,53 @@ static int mtk_dpi_set_display_mode(struct mtk_dpi *dpi, ...@@ -521,50 +522,53 @@ static int mtk_dpi_set_display_mode(struct mtk_dpi *dpi,
return 0; return 0;
} }
static bool mtk_dpi_encoder_mode_fixup(struct drm_encoder *encoder, static void mtk_dpi_encoder_destroy(struct drm_encoder *encoder)
const struct drm_display_mode *mode,
struct drm_display_mode *adjusted_mode)
{ {
return true; drm_encoder_cleanup(encoder);
} }
static void mtk_dpi_encoder_mode_set(struct drm_encoder *encoder, static const struct drm_encoder_funcs mtk_dpi_encoder_funcs = {
struct drm_display_mode *mode, .destroy = mtk_dpi_encoder_destroy,
struct drm_display_mode *adjusted_mode) };
static int mtk_dpi_bridge_attach(struct drm_bridge *bridge,
enum drm_bridge_attach_flags flags)
{ {
struct mtk_dpi *dpi = mtk_dpi_from_encoder(encoder); struct mtk_dpi *dpi = bridge_to_dpi(bridge);
return drm_bridge_attach(bridge->encoder, dpi->next_bridge,
&dpi->bridge, flags);
}
static void mtk_dpi_bridge_mode_set(struct drm_bridge *bridge,
const struct drm_display_mode *mode,
const struct drm_display_mode *adjusted_mode)
{
struct mtk_dpi *dpi = bridge_to_dpi(bridge);
drm_mode_copy(&dpi->mode, adjusted_mode); drm_mode_copy(&dpi->mode, adjusted_mode);
} }
static void mtk_dpi_encoder_disable(struct drm_encoder *encoder) static void mtk_dpi_bridge_disable(struct drm_bridge *bridge)
{ {
struct mtk_dpi *dpi = mtk_dpi_from_encoder(encoder); struct mtk_dpi *dpi = bridge_to_dpi(bridge);
mtk_dpi_power_off(dpi); mtk_dpi_power_off(dpi);
} }
static void mtk_dpi_encoder_enable(struct drm_encoder *encoder) static void mtk_dpi_bridge_enable(struct drm_bridge *bridge)
{ {
struct mtk_dpi *dpi = mtk_dpi_from_encoder(encoder); struct mtk_dpi *dpi = bridge_to_dpi(bridge);
mtk_dpi_power_on(dpi); mtk_dpi_power_on(dpi);
mtk_dpi_set_display_mode(dpi, &dpi->mode); mtk_dpi_set_display_mode(dpi, &dpi->mode);
} }
static int mtk_dpi_atomic_check(struct drm_encoder *encoder, static const struct drm_bridge_funcs mtk_dpi_bridge_funcs = {
struct drm_crtc_state *crtc_state, .attach = mtk_dpi_bridge_attach,
struct drm_connector_state *conn_state) .mode_set = mtk_dpi_bridge_mode_set,
{ .disable = mtk_dpi_bridge_disable,
return 0; .enable = mtk_dpi_bridge_enable,
}
static const struct drm_encoder_helper_funcs mtk_dpi_encoder_helper_funcs = {
.mode_fixup = mtk_dpi_encoder_mode_fixup,
.mode_set = mtk_dpi_encoder_mode_set,
.disable = mtk_dpi_encoder_disable,
.enable = mtk_dpi_encoder_enable,
.atomic_check = mtk_dpi_atomic_check,
}; };
static void mtk_dpi_start(struct mtk_ddp_comp *comp) static void mtk_dpi_start(struct mtk_ddp_comp *comp)
...@@ -605,11 +609,10 @@ static int mtk_dpi_bind(struct device *dev, struct device *master, void *data) ...@@ -605,11 +609,10 @@ static int mtk_dpi_bind(struct device *dev, struct device *master, void *data)
dev_err(dev, "Failed to initialize decoder: %d\n", ret); dev_err(dev, "Failed to initialize decoder: %d\n", ret);
goto err_unregister; goto err_unregister;
} }
drm_encoder_helper_add(&dpi->encoder, &mtk_dpi_encoder_helper_funcs);
dpi->encoder.possible_crtcs = mtk_drm_find_possible_crtc_by_comp(drm_dev, dpi->ddp_comp); dpi->encoder.possible_crtcs = mtk_drm_find_possible_crtc_by_comp(drm_dev, dpi->ddp_comp);
ret = drm_bridge_attach(&dpi->encoder, dpi->next_bridge, NULL, 0); ret = drm_bridge_attach(&dpi->encoder, &dpi->bridge, NULL, 0);
if (ret) { if (ret) {
dev_err(dev, "Failed to attach bridge: %d\n", ret); dev_err(dev, "Failed to attach bridge: %d\n", ret);
goto err_cleanup; goto err_cleanup;
...@@ -790,8 +793,15 @@ static int mtk_dpi_probe(struct platform_device *pdev) ...@@ -790,8 +793,15 @@ static int mtk_dpi_probe(struct platform_device *pdev)
platform_set_drvdata(pdev, dpi); platform_set_drvdata(pdev, dpi);
dpi->bridge.funcs = &mtk_dpi_bridge_funcs;
dpi->bridge.of_node = dev->of_node;
dpi->bridge.type = DRM_MODE_CONNECTOR_DPI;
drm_bridge_add(&dpi->bridge);
ret = component_add(dev, &mtk_dpi_component_ops); ret = component_add(dev, &mtk_dpi_component_ops);
if (ret) { if (ret) {
drm_bridge_remove(&dpi->bridge);
dev_err(dev, "Failed to add component: %d\n", ret); dev_err(dev, "Failed to add component: %d\n", ret);
return ret; return ret;
} }
...@@ -801,7 +811,10 @@ static int mtk_dpi_probe(struct platform_device *pdev) ...@@ -801,7 +811,10 @@ static int mtk_dpi_probe(struct platform_device *pdev)
static int mtk_dpi_remove(struct platform_device *pdev) static int mtk_dpi_remove(struct platform_device *pdev)
{ {
struct mtk_dpi *dpi = platform_get_drvdata(pdev);
component_del(&pdev->dev, &mtk_dpi_component_ops); component_del(&pdev->dev, &mtk_dpi_component_ops);
drm_bridge_remove(&dpi->bridge);
return 0; return 0;
} }
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment