Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

soc: mediatek: mutex: add functions that operate registers by CMDQ

Due to HW limitations, MDP3 is necessary to enable MUTEX in each frame
for SOF triggering and cooperate with CMDQ control to reduce the amount
of interrupts generated(also, reduce frame latency).

In response to the above situation, a new interface
"mtk_mutex_enable_by_cmdq" has been added to achieve the purpose.

Signed-off-by: Moudy Ho <moudy.ho@mediatek.com>
Reviewed-by: AngeloGioacchino Del Regno <angelogioacchino.delregno@collabora.com>
Reviewed-by: Rex-BC Chen <rex-bc.chen@mediatek.com>
Reviewed-by: CK Hu <ck.hu@mediatek.com>
Link: https://lore.kernel.org/r/20220610063424.7800-7-moudy.ho@mediatek.com
Signed-off-by: Matthias Brugger <matthias.bgg@gmail.com>

authored by

Moudy Ho and committed by
Matthias Brugger
e5758850 e3b6b5a9

+46 -1
+44 -1
drivers/soc/mediatek/mtk-mutex.c
··· 7 7 #include <linux/iopoll.h> 8 8 #include <linux/module.h> 9 9 #include <linux/of_device.h> 10 + #include <linux/of_address.h> 10 11 #include <linux/platform_device.h> 11 12 #include <linux/regmap.h> 12 13 #include <linux/soc/mediatek/mtk-mmsys.h> 13 14 #include <linux/soc/mediatek/mtk-mutex.h> 15 + #include <linux/soc/mediatek/mtk-cmdq.h> 14 16 15 17 #define MT2701_MUTEX0_MOD0 0x2c 16 18 #define MT2701_MUTEX0_SOF0 0x30 ··· 220 218 void __iomem *regs; 221 219 struct mtk_mutex mutex[10]; 222 220 const struct mtk_mutex_data *data; 221 + phys_addr_t addr; 222 + struct cmdq_client_reg cmdq_reg; 223 223 }; 224 224 225 225 static const unsigned int mt2701_mutex_mod[DDP_COMPONENT_ID_MAX] = { ··· 636 632 } 637 633 EXPORT_SYMBOL_GPL(mtk_mutex_enable); 638 634 635 + int mtk_mutex_enable_by_cmdq(struct mtk_mutex *mutex, void *pkt) 636 + { 637 + struct mtk_mutex_ctx *mtx = container_of(mutex, struct mtk_mutex_ctx, 638 + mutex[mutex->id]); 639 + #if IS_REACHABLE(CONFIG_MTK_CMDQ) 640 + struct cmdq_pkt *cmdq_pkt = (struct cmdq_pkt *)pkt; 641 + 642 + WARN_ON(&mtx->mutex[mutex->id] != mutex); 643 + 644 + if (!mtx->cmdq_reg.size) { 645 + dev_err(mtx->dev, "mediatek,gce-client-reg hasn't been set"); 646 + return -EINVAL; 647 + } 648 + 649 + cmdq_pkt_write(cmdq_pkt, mtx->cmdq_reg.subsys, 650 + mtx->addr + DISP_REG_MUTEX_EN(mutex->id), 1); 651 + return 0; 652 + #else 653 + dev_err(mtx->dev, "Not support for enable MUTEX by CMDQ"); 654 + return -ENODEV; 655 + #endif 656 + } 657 + EXPORT_SYMBOL_GPL(mtk_mutex_enable_by_cmdq); 658 + 639 659 void mtk_mutex_disable(struct mtk_mutex *mutex) 640 660 { 641 661 struct mtk_mutex_ctx *mtx = container_of(mutex, struct mtk_mutex_ctx, ··· 750 722 { 751 723 struct device *dev = &pdev->dev; 752 724 struct mtk_mutex_ctx *mtx; 753 - struct resource *regs; 725 + struct resource *regs, addr; 754 726 int i; 727 + #if IS_REACHABLE(CONFIG_MTK_CMDQ) 728 + int ret; 729 + #endif 755 730 756 731 mtx = devm_kzalloc(dev, sizeof(*mtx), GFP_KERNEL); 757 732 if (!mtx) ··· 773 742 return PTR_ERR(mtx->clk); 774 743 } 775 744 } 745 + 746 + if (of_address_to_resource(dev->of_node, 0, &addr) < 0) { 747 + dev_err(dev, "Failed to get addr\n"); 748 + return -EINVAL; 749 + } 750 + mtx->addr = addr.start; 751 + 752 + #if IS_REACHABLE(CONFIG_MTK_CMDQ) 753 + ret = cmdq_dev_get_client_reg(dev, &mtx->cmdq_reg, 0); 754 + if (ret) 755 + dev_dbg(dev, "No mediatek,gce-client-reg!\n"); 756 + #endif 776 757 777 758 regs = platform_get_resource(pdev, IORESOURCE_MEM, 0); 778 759 mtx->regs = devm_ioremap_resource(dev, regs);
+2
include/linux/soc/mediatek/mtk-mutex.h
··· 35 35 void mtk_mutex_add_comp(struct mtk_mutex *mutex, 36 36 enum mtk_ddp_comp_id id); 37 37 void mtk_mutex_enable(struct mtk_mutex *mutex); 38 + int mtk_mutex_enable_by_cmdq(struct mtk_mutex *mutex, 39 + void *pkt); 38 40 void mtk_mutex_disable(struct mtk_mutex *mutex); 39 41 void mtk_mutex_remove_comp(struct mtk_mutex *mutex, 40 42 enum mtk_ddp_comp_id id);