[PATCH 3/3] drm/mediatek: Move CMDQ setup to mtk_drm_cmdq_init() function

From: AngeloGioacchino Del Regno
Date: Fri Jun 23 2023 - 05:50:18 EST


In order to enhance human readability, separating the optional
CMDQ mailbox initialization from the rest of the CRTC creation
machinery, move it to a new mtk_drm_cmdq_init() function.

Signed-off-by: AngeloGioacchino Del Regno <angelogioacchino.delregno@xxxxxxxxxxxxx>
---
drivers/gpu/drm/mediatek/mtk_drm_crtc.c | 83 ++++++++++++++-----------
1 file changed, 48 insertions(+), 35 deletions(-)

diff --git a/drivers/gpu/drm/mediatek/mtk_drm_crtc.c b/drivers/gpu/drm/mediatek/mtk_drm_crtc.c
index 88c63330a421..bff65c8c6a0e 100644
--- a/drivers/gpu/drm/mediatek/mtk_drm_crtc.c
+++ b/drivers/gpu/drm/mediatek/mtk_drm_crtc.c
@@ -826,6 +826,48 @@ struct device *mtk_drm_crtc_dma_dev_get(struct drm_crtc *crtc)
return mtk_crtc->dma_dev;
}

+static int mtk_drm_cmdq_init(struct device *dev, struct mtk_drm_private *priv,
+ struct mtk_drm_crtc *mtk_crtc)
+{
+ int ret;
+
+ mtk_crtc->cmdq_client = cmdq_mbox_create(mtk_crtc->mmsys_dev, priv->mbox_index);
+ if (IS_ERR(mtk_crtc->cmdq_client)) {
+ ret = PTR_ERR(mtk_crtc->cmdq_client);
+ dev_dbg(dev, "Failed to create CMDQ client: %d\n", ret);
+ goto error;
+ }
+
+ /* Setup the CMDQ handler callback */
+ mtk_crtc->cmdq_client->priv = mtk_crtc;
+ mtk_crtc->cmdq_client->client.rx_callback = ddp_cmdq_cb;
+
+ ret = of_property_read_u32_index(priv->mutex_node, "mediatek,gce-events",
+ priv->mbox_index, &mtk_crtc->cmdq_event);
+ if (ret) {
+ dev_dbg(dev, "Failed to get mediatek,gce-events: %d\n", ret);
+ goto free_mbox;
+ }
+
+ mtk_crtc->cmdq_handle = cmdq_pkt_create(mtk_crtc->cmdq_client, PAGE_SIZE);
+ if (IS_ERR(mtk_crtc->cmdq_handle)) {
+ ret = PTR_ERR(mtk_crtc->cmdq_handle);
+ dev_err(dev, "Failed to create cmdq packet: %d\n", ret);
+ goto free_mbox;
+ }
+
+ /* for sending blocking cmd in crtc disable */
+ init_waitqueue_head(&mtk_crtc->cb_blocking_queue);
+
+ return 0;
+
+free_mbox:
+ cmdq_mbox_destroy(mtk_crtc->cmdq_client);
+error:
+ mtk_crtc->cmdq_client = NULL;
+ return ret;
+}
+
int mtk_drm_crtc_create(struct drm_device *drm_dev,
const unsigned int *path, unsigned int path_len,
int priv_data_index)
@@ -942,42 +984,13 @@ int mtk_drm_crtc_create(struct drm_device *drm_dev,
drm_crtc_enable_color_mgmt(&mtk_crtc->base, 0, has_ctm, gamma_lut_size);
mutex_init(&mtk_crtc->hw_lock);

- i = priv->mbox_index++;
-
- mtk_crtc->cmdq_client = cmdq_mbox_create(mtk_crtc->mmsys_dev, i);
- if (IS_ERR(mtk_crtc->cmdq_client)) {
- ret = PTR_ERR(mtk_crtc->cmdq_client);
- dev_dbg(dev, "Failed to create CMDQ client: %d\n", ret);
- mtk_crtc->cmdq_client = NULL;
- return 0;
- }
-
- /* Setup the CMDQ handler callback */
- mtk_crtc->cmdq_client->priv = mtk_crtc;
- mtk_crtc->cmdq_client->client.rx_callback = ddp_cmdq_cb;
+ ret = mtk_drm_cmdq_init(dev, priv, mtk_crtc);
+ if (ret)
+ dev_info(dev, "No CMDQ support for CRTC%d: using CPU writes\n",
+ drm_crtc_index(&mtk_crtc->base));

- if (mtk_crtc->cmdq_client) {
- ret = of_property_read_u32_index(priv->mutex_node,
- "mediatek,gce-events",
- i,
- &mtk_crtc->cmdq_event);
- if (ret) {
- dev_dbg(dev, "mtk_crtc %d failed to get mediatek,gce-events property\n",
- drm_crtc_index(&mtk_crtc->base));
- cmdq_mbox_destroy(mtk_crtc->cmdq_client);
- mtk_crtc->cmdq_client = NULL;
- } else {
- mtk_crtc->cmdq_handle = cmdq_pkt_create(mtk_crtc->cmdq_client, PAGE_SIZE);
- if (ret) {
- dev_dbg(dev, "mtk_crtc %d failed to create cmdq packet\n",
- drm_crtc_index(&mtk_crtc->base));
- cmdq_mbox_destroy(mtk_crtc->cmdq_client);
- mtk_crtc->cmdq_client = NULL;
- }
- }
+ /* Unconditionally increment mbox_index */
+ priv->mbox_index++;

- /* for sending blocking cmd in crtc disable */
- init_waitqueue_head(&mtk_crtc->cb_blocking_queue);
- }
return 0;
}
--
2.40.1