soc: mediatek: Cleanup ifdefs for IS_REACHABLE(CONFIG_MTK_CMDQ)
authorAngeloGioacchino Del Regno <angelogioacchino.delregno@collabora.com>
Wed, 22 Feb 2023 09:42:53 +0000 (10:42 +0100)
committerMatthias Brugger <matthias.bgg@gmail.com>
Sun, 2 Apr 2023 16:52:03 +0000 (18:52 +0200)
Now that the mtk-cmdq.h header contains inline functions for cases
in which the driver is not enabled (either module or built-in), we
can safely go on with cleaning up ifdefs for CMDQ handling.

This also shows in a clearer manner that writing through CMDQ HW is
optional and used only for performance purposes when/where wanted,
needed and/or required.

Signed-off-by: AngeloGioacchino Del Regno <angelogioacchino.delregno@collabora.com>
Reviewed-by: Chen-Yu Tsai <wenst@chromium.org>
Link: https://lore.kernel.org/r/20230222094253.23678-10-angelogioacchino.delregno@collabora.com
Signed-off-by: Matthias Brugger <matthias.bgg@gmail.com>
drivers/soc/mediatek/mtk-mmsys.c
drivers/soc/mediatek/mtk-mutex.c

index 0fa6c31f774ce7174f0339156592454b5a390949..b84485670f91b43c5bc9e0f3b11c127bc87e2102 100644 (file)
@@ -131,21 +131,18 @@ struct mtk_mmsys {
 static void mtk_mmsys_update_bits(struct mtk_mmsys *mmsys, u32 offset, u32 mask, u32 val,
                                  struct cmdq_pkt *cmdq_pkt)
 {
+       int ret;
        u32 tmp;
 
-#if IS_REACHABLE(CONFIG_MTK_CMDQ)
-       if (cmdq_pkt) {
-               if (mmsys->cmdq_base.size == 0) {
-                       pr_err("mmsys lose gce property, failed to update mmsys bits with cmdq");
+       if (mmsys->cmdq_base.size && cmdq_pkt) {
+               ret = cmdq_pkt_write_mask(cmdq_pkt, mmsys->cmdq_base.subsys,
+                                         mmsys->cmdq_base.offset + offset, val,
+                                         mask);
+               if (ret)
+                       pr_debug("CMDQ unavailable: using CPU write\n");
+               else
                        return;
-               }
-               cmdq_pkt_write_mask(cmdq_pkt, mmsys->cmdq_base.subsys,
-                                   mmsys->cmdq_base.offset + offset, val,
-                                   mask);
-               return;
        }
-#endif
-
        tmp = readl_relaxed(mmsys->regs + offset);
        tmp = (tmp & ~mask) | (val & mask);
        writel_relaxed(tmp, mmsys->regs + offset);
@@ -376,11 +373,10 @@ static int mtk_mmsys_probe(struct platform_device *pdev)
                }
        }
 
-#if IS_REACHABLE(CONFIG_MTK_CMDQ)
+       /* CMDQ is optional */
        ret = cmdq_dev_get_client_reg(dev, &mmsys->cmdq_base, 0);
        if (ret)
                dev_dbg(dev, "No mediatek,gce-client-reg!\n");
-#endif
 
        platform_set_drvdata(pdev, mmsys);
 
index b106f3d23e0de1426909bba8473dd1b196576bb4..b92cffec7be707d40e519bf4fe7ce038db2c8111 100644 (file)
@@ -871,23 +871,18 @@ int mtk_mutex_enable_by_cmdq(struct mtk_mutex *mutex, void *pkt)
 {
        struct mtk_mutex_ctx *mtx = container_of(mutex, struct mtk_mutex_ctx,
                                                 mutex[mutex->id]);
-#if IS_REACHABLE(CONFIG_MTK_CMDQ)
        struct cmdq_pkt *cmdq_pkt = (struct cmdq_pkt *)pkt;
 
        WARN_ON(&mtx->mutex[mutex->id] != mutex);
 
        if (!mtx->cmdq_reg.size) {
                dev_err(mtx->dev, "mediatek,gce-client-reg hasn't been set");
-               return -EINVAL;
+               return -ENODEV;
        }
 
        cmdq_pkt_write(cmdq_pkt, mtx->cmdq_reg.subsys,
                       mtx->addr + DISP_REG_MUTEX_EN(mutex->id), 1);
        return 0;
-#else
-       dev_err(mtx->dev, "Not support for enable MUTEX by CMDQ");
-       return -ENODEV;
-#endif
 }
 EXPORT_SYMBOL_GPL(mtk_mutex_enable_by_cmdq);
 
@@ -1000,10 +995,7 @@ static int mtk_mutex_probe(struct platform_device *pdev)
        struct device *dev = &pdev->dev;
        struct mtk_mutex_ctx *mtx;
        struct resource *regs;
-       int i;
-#if IS_REACHABLE(CONFIG_MTK_CMDQ)
-       int ret;
-#endif
+       int i, ret;
 
        mtx = devm_kzalloc(dev, sizeof(*mtx), GFP_KERNEL);
        if (!mtx)
@@ -1030,11 +1022,10 @@ static int mtk_mutex_probe(struct platform_device *pdev)
        }
        mtx->addr = regs->start;
 
-#if IS_REACHABLE(CONFIG_MTK_CMDQ)
+       /* CMDQ is optional */
        ret = cmdq_dev_get_client_reg(dev, &mtx->cmdq_reg, 0);
        if (ret)
                dev_dbg(dev, "No mediatek,gce-client-reg!\n");
-#endif
 
        platform_set_drvdata(pdev, mtx);