Mediatek DRM Next for Linux 5.9
-----BEGIN PGP SIGNATURE----- iQJMBAABCgA2FiEEACwLKSDmq+9RDv5P4cpzo8lZTiQFAl8Q3fcYHGNodW5rdWFu Zy5odUBrZXJuZWwub3JnAAoJEOHKc6PJWU4kocgP/1rmu1KH6qCNYc2Erb2Nzs9G k1iE09WHHbscHdtBecUeauayVxFMyfEvYCO0g6xrBBUr0nePA14wd4aFNz8AVayI RCBn1hQNGrFKAQRVlMRido45OpLm+gsyF0tLNbFz4JjhrVJHDKar86d90u+DpRvr bVeY1fCW28JhQQhCBpRUPYCfJJW3U3qUI8ttVyVY7khssbg6/m16jk7dXdgaPKsx OKJ9RN9nzXdNT6r5q+l4vgN2t7dOFrRD+iNR5I91EhzcYj/L5XwFUy/xA+Mn+bge BuHD+ReO4gT0V9cxsSdtrGu/5tr3QM6rvZgsysL2WuimHNvT29s2sQdcPYkty7gB FnPbu9WRXFIKZxprh/qSxXH8DqvrN9IX+jr7fC0lEI7fUb1OEAn1nYcLuAhG3VmP +oYmQxibZLkWnQ0hSLUg0Vyvywtqx1BqH8DOlRfJsMsCUViw4zSIRvdIGwLJVu3S iOWZhlKs8kbDyW2yoFsCQEEaTNMKtVU29qfAfaIu/K4mfQkqplhWVNevZiAdJZun 2N/9FvXMpTiZka7JiyOqs2uZJIBMWDW99KO4smhrhpDIdqd3bJsEYyXCKmYlBD6y iQzj/arZO6Er0Uq8P/e4Fk6DCf30fOaeE0CFO1b8eWS2U+OfxqcAms8CnVlWliK1 wQOEcAgGa0AaDjdrfgWP =C3jr -----END PGP SIGNATURE----- Merge tag 'mediatek-drm-next-5.9' of https://git.kernel.org/pub/scm/linux/kernel/git/chunkuang.hu/linux into drm-next Mediatek DRM Next for Linux 5.9 This include converting mtk_dsi to drm_bridge API. Signed-off-by: Dave Airlie <airlied@redhat.com> From: Chun-Kuang Hu <chunkuang.hu@kernel.org> Link: https://patchwork.freedesktop.org/patch/msgid/20200716233102.566-1-chunkuang.hu@kernel.org
This commit is contained in:
commit
3afe676684
@ -17,6 +17,7 @@
|
||||
|
||||
#include <drm/drm_atomic_helper.h>
|
||||
#include <drm/drm_bridge.h>
|
||||
#include <drm/drm_bridge_connector.h>
|
||||
#include <drm/drm_mipi_dsi.h>
|
||||
#include <drm/drm_of.h>
|
||||
#include <drm/drm_panel.h>
|
||||
@ -181,9 +182,9 @@ struct mtk_dsi {
|
||||
struct device *dev;
|
||||
struct mipi_dsi_host host;
|
||||
struct drm_encoder encoder;
|
||||
struct drm_connector conn;
|
||||
struct drm_panel *panel;
|
||||
struct drm_bridge *bridge;
|
||||
struct drm_bridge bridge;
|
||||
struct drm_bridge *next_bridge;
|
||||
struct drm_connector *connector;
|
||||
struct phy *phy;
|
||||
|
||||
void __iomem *regs;
|
||||
@ -206,14 +207,9 @@ struct mtk_dsi {
|
||||
const struct mtk_dsi_driver_data *driver_data;
|
||||
};
|
||||
|
||||
static inline struct mtk_dsi *encoder_to_dsi(struct drm_encoder *e)
|
||||
static inline struct mtk_dsi *bridge_to_dsi(struct drm_bridge *b)
|
||||
{
|
||||
return container_of(e, struct mtk_dsi, encoder);
|
||||
}
|
||||
|
||||
static inline struct mtk_dsi *connector_to_dsi(struct drm_connector *c)
|
||||
{
|
||||
return container_of(c, struct mtk_dsi, conn);
|
||||
return container_of(b, struct mtk_dsi, bridge);
|
||||
}
|
||||
|
||||
static inline struct mtk_dsi *host_to_dsi(struct mipi_dsi_host *h)
|
||||
@ -678,16 +674,7 @@ static int mtk_dsi_poweron(struct mtk_dsi *dsi)
|
||||
mtk_dsi_lane0_ulp_mode_leave(dsi);
|
||||
mtk_dsi_clk_hs_mode(dsi, 0);
|
||||
|
||||
if (dsi->panel) {
|
||||
if (drm_panel_prepare(dsi->panel)) {
|
||||
DRM_ERROR("failed to prepare the panel\n");
|
||||
goto err_disable_digital_clk;
|
||||
}
|
||||
}
|
||||
|
||||
return 0;
|
||||
err_disable_digital_clk:
|
||||
clk_disable_unprepare(dsi->digital_clk);
|
||||
err_disable_engine_clk:
|
||||
clk_disable_unprepare(dsi->engine_clk);
|
||||
err_phy_power_off:
|
||||
@ -714,15 +701,7 @@ static void mtk_dsi_poweroff(struct mtk_dsi *dsi)
|
||||
*/
|
||||
mtk_dsi_stop(dsi);
|
||||
|
||||
if (!mtk_dsi_switch_to_cmd_mode(dsi, VM_DONE_INT_FLAG, 500)) {
|
||||
if (dsi->panel) {
|
||||
if (drm_panel_unprepare(dsi->panel)) {
|
||||
DRM_ERROR("failed to unprepare the panel\n");
|
||||
return;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
mtk_dsi_switch_to_cmd_mode(dsi, VM_DONE_INT_FLAG, 500);
|
||||
mtk_dsi_reset_engine(dsi);
|
||||
mtk_dsi_lane0_ulp_mode_enter(dsi);
|
||||
mtk_dsi_clk_ulp_mode_enter(dsi);
|
||||
@ -753,19 +732,7 @@ static void mtk_output_dsi_enable(struct mtk_dsi *dsi)
|
||||
|
||||
mtk_dsi_start(dsi);
|
||||
|
||||
if (dsi->panel) {
|
||||
if (drm_panel_enable(dsi->panel)) {
|
||||
DRM_ERROR("failed to enable the panel\n");
|
||||
goto err_dsi_power_off;
|
||||
}
|
||||
}
|
||||
|
||||
dsi->enabled = true;
|
||||
|
||||
return;
|
||||
err_dsi_power_off:
|
||||
mtk_dsi_stop(dsi);
|
||||
mtk_dsi_poweroff(dsi);
|
||||
}
|
||||
|
||||
static void mtk_output_dsi_disable(struct mtk_dsi *dsi)
|
||||
@ -773,155 +740,51 @@ static void mtk_output_dsi_disable(struct mtk_dsi *dsi)
|
||||
if (!dsi->enabled)
|
||||
return;
|
||||
|
||||
if (dsi->panel) {
|
||||
if (drm_panel_disable(dsi->panel)) {
|
||||
DRM_ERROR("failed to disable the panel\n");
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
mtk_dsi_poweroff(dsi);
|
||||
|
||||
dsi->enabled = false;
|
||||
}
|
||||
|
||||
static bool mtk_dsi_encoder_mode_fixup(struct drm_encoder *encoder,
|
||||
const struct drm_display_mode *mode,
|
||||
struct drm_display_mode *adjusted_mode)
|
||||
static int mtk_dsi_bridge_attach(struct drm_bridge *bridge,
|
||||
enum drm_bridge_attach_flags flags)
|
||||
{
|
||||
return true;
|
||||
struct mtk_dsi *dsi = bridge_to_dsi(bridge);
|
||||
|
||||
/* Attach the panel or bridge to the dsi bridge */
|
||||
return drm_bridge_attach(bridge->encoder, dsi->next_bridge,
|
||||
&dsi->bridge, flags);
|
||||
}
|
||||
|
||||
static void mtk_dsi_encoder_mode_set(struct drm_encoder *encoder,
|
||||
struct drm_display_mode *mode,
|
||||
struct drm_display_mode *adjusted)
|
||||
static void mtk_dsi_bridge_mode_set(struct drm_bridge *bridge,
|
||||
const struct drm_display_mode *mode,
|
||||
const struct drm_display_mode *adjusted)
|
||||
{
|
||||
struct mtk_dsi *dsi = encoder_to_dsi(encoder);
|
||||
struct mtk_dsi *dsi = bridge_to_dsi(bridge);
|
||||
|
||||
drm_display_mode_to_videomode(adjusted, &dsi->vm);
|
||||
}
|
||||
|
||||
static void mtk_dsi_encoder_disable(struct drm_encoder *encoder)
|
||||
static void mtk_dsi_bridge_disable(struct drm_bridge *bridge)
|
||||
{
|
||||
struct mtk_dsi *dsi = encoder_to_dsi(encoder);
|
||||
struct mtk_dsi *dsi = bridge_to_dsi(bridge);
|
||||
|
||||
mtk_output_dsi_disable(dsi);
|
||||
}
|
||||
|
||||
static void mtk_dsi_encoder_enable(struct drm_encoder *encoder)
|
||||
static void mtk_dsi_bridge_enable(struct drm_bridge *bridge)
|
||||
{
|
||||
struct mtk_dsi *dsi = encoder_to_dsi(encoder);
|
||||
struct mtk_dsi *dsi = bridge_to_dsi(bridge);
|
||||
|
||||
mtk_output_dsi_enable(dsi);
|
||||
}
|
||||
|
||||
static int mtk_dsi_connector_get_modes(struct drm_connector *connector)
|
||||
{
|
||||
struct mtk_dsi *dsi = connector_to_dsi(connector);
|
||||
|
||||
return drm_panel_get_modes(dsi->panel, connector);
|
||||
}
|
||||
|
||||
static const struct drm_encoder_helper_funcs mtk_dsi_encoder_helper_funcs = {
|
||||
.mode_fixup = mtk_dsi_encoder_mode_fixup,
|
||||
.mode_set = mtk_dsi_encoder_mode_set,
|
||||
.disable = mtk_dsi_encoder_disable,
|
||||
.enable = mtk_dsi_encoder_enable,
|
||||
static const struct drm_bridge_funcs mtk_dsi_bridge_funcs = {
|
||||
.attach = mtk_dsi_bridge_attach,
|
||||
.disable = mtk_dsi_bridge_disable,
|
||||
.enable = mtk_dsi_bridge_enable,
|
||||
.mode_set = mtk_dsi_bridge_mode_set,
|
||||
};
|
||||
|
||||
static const struct drm_connector_funcs mtk_dsi_connector_funcs = {
|
||||
.fill_modes = drm_helper_probe_single_connector_modes,
|
||||
.destroy = drm_connector_cleanup,
|
||||
.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
|
||||
mtk_dsi_connector_helper_funcs = {
|
||||
.get_modes = mtk_dsi_connector_get_modes,
|
||||
};
|
||||
|
||||
static int mtk_dsi_create_connector(struct drm_device *drm, struct mtk_dsi *dsi)
|
||||
{
|
||||
int ret;
|
||||
|
||||
ret = drm_connector_init(drm, &dsi->conn, &mtk_dsi_connector_funcs,
|
||||
DRM_MODE_CONNECTOR_DSI);
|
||||
if (ret) {
|
||||
DRM_ERROR("Failed to connector init to drm\n");
|
||||
return ret;
|
||||
}
|
||||
|
||||
drm_connector_helper_add(&dsi->conn, &mtk_dsi_connector_helper_funcs);
|
||||
|
||||
dsi->conn.dpms = DRM_MODE_DPMS_OFF;
|
||||
drm_connector_attach_encoder(&dsi->conn, &dsi->encoder);
|
||||
|
||||
if (dsi->panel) {
|
||||
ret = drm_panel_attach(dsi->panel, &dsi->conn);
|
||||
if (ret) {
|
||||
DRM_ERROR("Failed to attach panel to drm\n");
|
||||
goto err_connector_cleanup;
|
||||
}
|
||||
}
|
||||
|
||||
return 0;
|
||||
|
||||
err_connector_cleanup:
|
||||
drm_connector_cleanup(&dsi->conn);
|
||||
return ret;
|
||||
}
|
||||
|
||||
static int mtk_dsi_create_conn_enc(struct drm_device *drm, struct mtk_dsi *dsi)
|
||||
{
|
||||
int ret;
|
||||
|
||||
ret = drm_simple_encoder_init(drm, &dsi->encoder,
|
||||
DRM_MODE_ENCODER_DSI);
|
||||
if (ret) {
|
||||
DRM_ERROR("Failed to encoder init to drm\n");
|
||||
return ret;
|
||||
}
|
||||
drm_encoder_helper_add(&dsi->encoder, &mtk_dsi_encoder_helper_funcs);
|
||||
|
||||
/*
|
||||
* Currently display data paths are statically assigned to a crtc each.
|
||||
* crtc 0 is OVL0 -> COLOR0 -> AAL -> OD -> RDMA0 -> UFOE -> DSI0
|
||||
*/
|
||||
dsi->encoder.possible_crtcs = 1;
|
||||
|
||||
/* If there's a bridge, attach to it and let it create the connector */
|
||||
if (dsi->bridge) {
|
||||
ret = drm_bridge_attach(&dsi->encoder, dsi->bridge, NULL, 0);
|
||||
if (ret) {
|
||||
DRM_ERROR("Failed to attach bridge to drm\n");
|
||||
goto err_encoder_cleanup;
|
||||
}
|
||||
} else {
|
||||
/* Otherwise create our own connector and attach to a panel */
|
||||
ret = mtk_dsi_create_connector(drm, dsi);
|
||||
if (ret)
|
||||
goto err_encoder_cleanup;
|
||||
}
|
||||
|
||||
return 0;
|
||||
|
||||
err_encoder_cleanup:
|
||||
drm_encoder_cleanup(&dsi->encoder);
|
||||
return ret;
|
||||
}
|
||||
|
||||
static void mtk_dsi_destroy_conn_enc(struct mtk_dsi *dsi)
|
||||
{
|
||||
drm_encoder_cleanup(&dsi->encoder);
|
||||
/* Skip connector cleanup if creation was delegated to the bridge */
|
||||
if (dsi->conn.dev)
|
||||
drm_connector_cleanup(&dsi->conn);
|
||||
if (dsi->panel)
|
||||
drm_panel_detach(dsi->panel);
|
||||
}
|
||||
|
||||
static void mtk_dsi_ddp_start(struct mtk_ddp_comp *comp)
|
||||
{
|
||||
struct mtk_dsi *dsi = container_of(comp, struct mtk_dsi, ddp_comp);
|
||||
@ -950,20 +813,6 @@ static int mtk_dsi_host_attach(struct mipi_dsi_host *host,
|
||||
dsi->format = device->format;
|
||||
dsi->mode_flags = device->mode_flags;
|
||||
|
||||
if (dsi->conn.dev)
|
||||
drm_helper_hpd_irq_event(dsi->conn.dev);
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
static int mtk_dsi_host_detach(struct mipi_dsi_host *host,
|
||||
struct mipi_dsi_device *device)
|
||||
{
|
||||
struct mtk_dsi *dsi = host_to_dsi(host);
|
||||
|
||||
if (dsi->conn.dev)
|
||||
drm_helper_hpd_irq_event(dsi->conn.dev);
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
@ -1107,10 +956,46 @@ static ssize_t mtk_dsi_host_transfer(struct mipi_dsi_host *host,
|
||||
|
||||
static const struct mipi_dsi_host_ops mtk_dsi_ops = {
|
||||
.attach = mtk_dsi_host_attach,
|
||||
.detach = mtk_dsi_host_detach,
|
||||
.transfer = mtk_dsi_host_transfer,
|
||||
};
|
||||
|
||||
static int mtk_dsi_encoder_init(struct drm_device *drm, struct mtk_dsi *dsi)
|
||||
{
|
||||
int ret;
|
||||
|
||||
ret = drm_simple_encoder_init(drm, &dsi->encoder,
|
||||
DRM_MODE_ENCODER_DSI);
|
||||
if (ret) {
|
||||
DRM_ERROR("Failed to encoder init to drm\n");
|
||||
return ret;
|
||||
}
|
||||
|
||||
/*
|
||||
* Currently display data paths are statically assigned to a crtc each.
|
||||
* crtc 0 is OVL0 -> COLOR0 -> AAL -> OD -> RDMA0 -> UFOE -> DSI0
|
||||
*/
|
||||
dsi->encoder.possible_crtcs = 1;
|
||||
|
||||
ret = drm_bridge_attach(&dsi->encoder, &dsi->bridge, NULL,
|
||||
DRM_BRIDGE_ATTACH_NO_CONNECTOR);
|
||||
if (ret)
|
||||
goto err_cleanup_encoder;
|
||||
|
||||
dsi->connector = drm_bridge_connector_init(drm, &dsi->encoder);
|
||||
if (IS_ERR(dsi->connector)) {
|
||||
DRM_ERROR("Unable to create bridge connector\n");
|
||||
ret = PTR_ERR(dsi->connector);
|
||||
goto err_cleanup_encoder;
|
||||
}
|
||||
drm_connector_attach_encoder(dsi->connector, &dsi->encoder);
|
||||
|
||||
return 0;
|
||||
|
||||
err_cleanup_encoder:
|
||||
drm_encoder_cleanup(&dsi->encoder);
|
||||
return ret;
|
||||
}
|
||||
|
||||
static int mtk_dsi_bind(struct device *dev, struct device *master, void *data)
|
||||
{
|
||||
int ret;
|
||||
@ -1124,11 +1009,9 @@ static int mtk_dsi_bind(struct device *dev, struct device *master, void *data)
|
||||
return ret;
|
||||
}
|
||||
|
||||
ret = mtk_dsi_create_conn_enc(drm, dsi);
|
||||
if (ret) {
|
||||
DRM_ERROR("Encoder create failed with %d\n", ret);
|
||||
ret = mtk_dsi_encoder_init(drm, dsi);
|
||||
if (ret)
|
||||
goto err_unregister;
|
||||
}
|
||||
|
||||
return 0;
|
||||
|
||||
@ -1143,7 +1026,7 @@ static void mtk_dsi_unbind(struct device *dev, struct device *master,
|
||||
struct drm_device *drm = data;
|
||||
struct mtk_dsi *dsi = dev_get_drvdata(dev);
|
||||
|
||||
mtk_dsi_destroy_conn_enc(dsi);
|
||||
drm_encoder_cleanup(&dsi->encoder);
|
||||
mtk_ddp_comp_unregister(drm, &dsi->ddp_comp);
|
||||
}
|
||||
|
||||
@ -1156,6 +1039,7 @@ static int mtk_dsi_probe(struct platform_device *pdev)
|
||||
{
|
||||
struct mtk_dsi *dsi;
|
||||
struct device *dev = &pdev->dev;
|
||||
struct drm_panel *panel;
|
||||
struct resource *regs;
|
||||
int irq_num;
|
||||
int comp_id;
|
||||
@ -1174,10 +1058,18 @@ static int mtk_dsi_probe(struct platform_device *pdev)
|
||||
}
|
||||
|
||||
ret = drm_of_find_panel_or_bridge(dev->of_node, 0, 0,
|
||||
&dsi->panel, &dsi->bridge);
|
||||
&panel, &dsi->next_bridge);
|
||||
if (ret)
|
||||
goto err_unregister_host;
|
||||
|
||||
if (panel) {
|
||||
dsi->next_bridge = devm_drm_panel_bridge_add(dev, panel);
|
||||
if (IS_ERR(dsi->next_bridge)) {
|
||||
ret = PTR_ERR(dsi->next_bridge);
|
||||
goto err_unregister_host;
|
||||
}
|
||||
}
|
||||
|
||||
dsi->driver_data = of_device_get_match_data(dev);
|
||||
|
||||
dsi->engine_clk = devm_clk_get(dev, "engine");
|
||||
@ -1253,6 +1145,12 @@ static int mtk_dsi_probe(struct platform_device *pdev)
|
||||
|
||||
platform_set_drvdata(pdev, dsi);
|
||||
|
||||
dsi->bridge.funcs = &mtk_dsi_bridge_funcs;
|
||||
dsi->bridge.of_node = dev->of_node;
|
||||
dsi->bridge.type = DRM_MODE_CONNECTOR_DSI;
|
||||
|
||||
drm_bridge_add(&dsi->bridge);
|
||||
|
||||
ret = component_add(&pdev->dev, &mtk_dsi_component_ops);
|
||||
if (ret) {
|
||||
dev_err(&pdev->dev, "failed to add component: %d\n", ret);
|
||||
@ -1271,6 +1169,7 @@ static int mtk_dsi_remove(struct platform_device *pdev)
|
||||
struct mtk_dsi *dsi = platform_get_drvdata(pdev);
|
||||
|
||||
mtk_output_dsi_disable(dsi);
|
||||
drm_bridge_remove(&dsi->bridge);
|
||||
component_del(&pdev->dev, &mtk_dsi_component_ops);
|
||||
mipi_dsi_host_unregister(&dsi->host);
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user