162306a36Sopenharmony_ci// SPDX-License-Identifier: GPL-2.0-only
262306a36Sopenharmony_ci/*
362306a36Sopenharmony_ci * Copyright (c) 2015 MediaTek Inc.
462306a36Sopenharmony_ci */
562306a36Sopenharmony_ci
662306a36Sopenharmony_ci#include <linux/clk.h>
762306a36Sopenharmony_ci#include <linux/iopoll.h>
862306a36Sopenharmony_ci#include <linux/module.h>
962306a36Sopenharmony_ci#include <linux/of.h>
1062306a36Sopenharmony_ci#include <linux/platform_device.h>
1162306a36Sopenharmony_ci#include <linux/regmap.h>
1262306a36Sopenharmony_ci#include <linux/soc/mediatek/mtk-mmsys.h>
1362306a36Sopenharmony_ci#include <linux/soc/mediatek/mtk-mutex.h>
1462306a36Sopenharmony_ci#include <linux/soc/mediatek/mtk-cmdq.h>
1562306a36Sopenharmony_ci
1662306a36Sopenharmony_ci#define MTK_MUTEX_MAX_HANDLES			10
1762306a36Sopenharmony_ci
1862306a36Sopenharmony_ci#define MT2701_MUTEX0_MOD0			0x2c
1962306a36Sopenharmony_ci#define MT2701_MUTEX0_SOF0			0x30
2062306a36Sopenharmony_ci#define MT8183_MUTEX0_MOD0			0x30
2162306a36Sopenharmony_ci#define MT8183_MUTEX0_SOF0			0x2c
2262306a36Sopenharmony_ci
2362306a36Sopenharmony_ci#define DISP_REG_MUTEX_EN(n)			(0x20 + 0x20 * (n))
2462306a36Sopenharmony_ci#define DISP_REG_MUTEX(n)			(0x24 + 0x20 * (n))
2562306a36Sopenharmony_ci#define DISP_REG_MUTEX_RST(n)			(0x28 + 0x20 * (n))
2662306a36Sopenharmony_ci#define DISP_REG_MUTEX_MOD(mutex_mod_reg, n)	(mutex_mod_reg + 0x20 * (n))
2762306a36Sopenharmony_ci#define DISP_REG_MUTEX_MOD1(mutex_mod_reg, n)	((mutex_mod_reg) + 0x20 * (n) + 0x4)
2862306a36Sopenharmony_ci#define DISP_REG_MUTEX_SOF(mutex_sof_reg, n)	(mutex_sof_reg + 0x20 * (n))
2962306a36Sopenharmony_ci#define DISP_REG_MUTEX_MOD2(n)			(0x34 + 0x20 * (n))
3062306a36Sopenharmony_ci
3162306a36Sopenharmony_ci#define INT_MUTEX				BIT(1)
3262306a36Sopenharmony_ci
3362306a36Sopenharmony_ci#define MT8186_MUTEX_MOD_DISP_OVL0		0
3462306a36Sopenharmony_ci#define MT8186_MUTEX_MOD_DISP_OVL0_2L		1
3562306a36Sopenharmony_ci#define MT8186_MUTEX_MOD_DISP_RDMA0		2
3662306a36Sopenharmony_ci#define MT8186_MUTEX_MOD_DISP_COLOR0		4
3762306a36Sopenharmony_ci#define MT8186_MUTEX_MOD_DISP_CCORR0		5
3862306a36Sopenharmony_ci#define MT8186_MUTEX_MOD_DISP_AAL0		7
3962306a36Sopenharmony_ci#define MT8186_MUTEX_MOD_DISP_GAMMA0		8
4062306a36Sopenharmony_ci#define MT8186_MUTEX_MOD_DISP_POSTMASK0		9
4162306a36Sopenharmony_ci#define MT8186_MUTEX_MOD_DISP_DITHER0		10
4262306a36Sopenharmony_ci#define MT8186_MUTEX_MOD_DISP_RDMA1		17
4362306a36Sopenharmony_ci
4462306a36Sopenharmony_ci#define MT8186_MUTEX_SOF_SINGLE_MODE		0
4562306a36Sopenharmony_ci#define MT8186_MUTEX_SOF_DSI0			1
4662306a36Sopenharmony_ci#define MT8186_MUTEX_SOF_DPI0			2
4762306a36Sopenharmony_ci#define MT8186_MUTEX_EOF_DSI0			(MT8186_MUTEX_SOF_DSI0 << 6)
4862306a36Sopenharmony_ci#define MT8186_MUTEX_EOF_DPI0			(MT8186_MUTEX_SOF_DPI0 << 6)
4962306a36Sopenharmony_ci
5062306a36Sopenharmony_ci#define MT8167_MUTEX_MOD_DISP_PWM		1
5162306a36Sopenharmony_ci#define MT8167_MUTEX_MOD_DISP_OVL0		6
5262306a36Sopenharmony_ci#define MT8167_MUTEX_MOD_DISP_OVL1		7
5362306a36Sopenharmony_ci#define MT8167_MUTEX_MOD_DISP_RDMA0		8
5462306a36Sopenharmony_ci#define MT8167_MUTEX_MOD_DISP_RDMA1		9
5562306a36Sopenharmony_ci#define MT8167_MUTEX_MOD_DISP_WDMA0		10
5662306a36Sopenharmony_ci#define MT8167_MUTEX_MOD_DISP_CCORR		11
5762306a36Sopenharmony_ci#define MT8167_MUTEX_MOD_DISP_COLOR		12
5862306a36Sopenharmony_ci#define MT8167_MUTEX_MOD_DISP_AAL		13
5962306a36Sopenharmony_ci#define MT8167_MUTEX_MOD_DISP_GAMMA		14
6062306a36Sopenharmony_ci#define MT8167_MUTEX_MOD_DISP_DITHER		15
6162306a36Sopenharmony_ci#define MT8167_MUTEX_MOD_DISP_UFOE		16
6262306a36Sopenharmony_ci
6362306a36Sopenharmony_ci#define MT8192_MUTEX_MOD_DISP_OVL0		0
6462306a36Sopenharmony_ci#define MT8192_MUTEX_MOD_DISP_OVL0_2L		1
6562306a36Sopenharmony_ci#define MT8192_MUTEX_MOD_DISP_RDMA0		2
6662306a36Sopenharmony_ci#define MT8192_MUTEX_MOD_DISP_COLOR0		4
6762306a36Sopenharmony_ci#define MT8192_MUTEX_MOD_DISP_CCORR0		5
6862306a36Sopenharmony_ci#define MT8192_MUTEX_MOD_DISP_AAL0		6
6962306a36Sopenharmony_ci#define MT8192_MUTEX_MOD_DISP_GAMMA0		7
7062306a36Sopenharmony_ci#define MT8192_MUTEX_MOD_DISP_POSTMASK0		8
7162306a36Sopenharmony_ci#define MT8192_MUTEX_MOD_DISP_DITHER0		9
7262306a36Sopenharmony_ci#define MT8192_MUTEX_MOD_DISP_OVL2_2L		16
7362306a36Sopenharmony_ci#define MT8192_MUTEX_MOD_DISP_RDMA4		17
7462306a36Sopenharmony_ci
7562306a36Sopenharmony_ci#define MT8183_MUTEX_MOD_DISP_RDMA0		0
7662306a36Sopenharmony_ci#define MT8183_MUTEX_MOD_DISP_RDMA1		1
7762306a36Sopenharmony_ci#define MT8183_MUTEX_MOD_DISP_OVL0		9
7862306a36Sopenharmony_ci#define MT8183_MUTEX_MOD_DISP_OVL0_2L		10
7962306a36Sopenharmony_ci#define MT8183_MUTEX_MOD_DISP_OVL1_2L		11
8062306a36Sopenharmony_ci#define MT8183_MUTEX_MOD_DISP_WDMA0		12
8162306a36Sopenharmony_ci#define MT8183_MUTEX_MOD_DISP_COLOR0		13
8262306a36Sopenharmony_ci#define MT8183_MUTEX_MOD_DISP_CCORR0		14
8362306a36Sopenharmony_ci#define MT8183_MUTEX_MOD_DISP_AAL0		15
8462306a36Sopenharmony_ci#define MT8183_MUTEX_MOD_DISP_GAMMA0		16
8562306a36Sopenharmony_ci#define MT8183_MUTEX_MOD_DISP_DITHER0		17
8662306a36Sopenharmony_ci
8762306a36Sopenharmony_ci#define MT8183_MUTEX_MOD_MDP_RDMA0		2
8862306a36Sopenharmony_ci#define MT8183_MUTEX_MOD_MDP_RSZ0		4
8962306a36Sopenharmony_ci#define MT8183_MUTEX_MOD_MDP_RSZ1		5
9062306a36Sopenharmony_ci#define MT8183_MUTEX_MOD_MDP_TDSHP0		6
9162306a36Sopenharmony_ci#define MT8183_MUTEX_MOD_MDP_WROT0		7
9262306a36Sopenharmony_ci#define MT8183_MUTEX_MOD_MDP_WDMA		8
9362306a36Sopenharmony_ci#define MT8183_MUTEX_MOD_MDP_AAL0		23
9462306a36Sopenharmony_ci#define MT8183_MUTEX_MOD_MDP_CCORR0		24
9562306a36Sopenharmony_ci
9662306a36Sopenharmony_ci#define MT8186_MUTEX_MOD_MDP_RDMA0		0
9762306a36Sopenharmony_ci#define MT8186_MUTEX_MOD_MDP_AAL0		2
9862306a36Sopenharmony_ci#define MT8186_MUTEX_MOD_MDP_HDR0		4
9962306a36Sopenharmony_ci#define MT8186_MUTEX_MOD_MDP_RSZ0		5
10062306a36Sopenharmony_ci#define MT8186_MUTEX_MOD_MDP_RSZ1		6
10162306a36Sopenharmony_ci#define MT8186_MUTEX_MOD_MDP_WROT0		7
10262306a36Sopenharmony_ci#define MT8186_MUTEX_MOD_MDP_TDSHP0		9
10362306a36Sopenharmony_ci#define MT8186_MUTEX_MOD_MDP_COLOR0		14
10462306a36Sopenharmony_ci
10562306a36Sopenharmony_ci#define MT8173_MUTEX_MOD_DISP_OVL0		11
10662306a36Sopenharmony_ci#define MT8173_MUTEX_MOD_DISP_OVL1		12
10762306a36Sopenharmony_ci#define MT8173_MUTEX_MOD_DISP_RDMA0		13
10862306a36Sopenharmony_ci#define MT8173_MUTEX_MOD_DISP_RDMA1		14
10962306a36Sopenharmony_ci#define MT8173_MUTEX_MOD_DISP_RDMA2		15
11062306a36Sopenharmony_ci#define MT8173_MUTEX_MOD_DISP_WDMA0		16
11162306a36Sopenharmony_ci#define MT8173_MUTEX_MOD_DISP_WDMA1		17
11262306a36Sopenharmony_ci#define MT8173_MUTEX_MOD_DISP_COLOR0		18
11362306a36Sopenharmony_ci#define MT8173_MUTEX_MOD_DISP_COLOR1		19
11462306a36Sopenharmony_ci#define MT8173_MUTEX_MOD_DISP_AAL		20
11562306a36Sopenharmony_ci#define MT8173_MUTEX_MOD_DISP_GAMMA		21
11662306a36Sopenharmony_ci#define MT8173_MUTEX_MOD_DISP_UFOE		22
11762306a36Sopenharmony_ci#define MT8173_MUTEX_MOD_DISP_PWM0		23
11862306a36Sopenharmony_ci#define MT8173_MUTEX_MOD_DISP_PWM1		24
11962306a36Sopenharmony_ci#define MT8173_MUTEX_MOD_DISP_OD		25
12062306a36Sopenharmony_ci
12162306a36Sopenharmony_ci#define MT8188_MUTEX_MOD_DISP_OVL0		0
12262306a36Sopenharmony_ci#define MT8188_MUTEX_MOD_DISP_WDMA0		1
12362306a36Sopenharmony_ci#define MT8188_MUTEX_MOD_DISP_RDMA0		2
12462306a36Sopenharmony_ci#define MT8188_MUTEX_MOD_DISP_COLOR0		3
12562306a36Sopenharmony_ci#define MT8188_MUTEX_MOD_DISP_CCORR0		4
12662306a36Sopenharmony_ci#define MT8188_MUTEX_MOD_DISP_AAL0		5
12762306a36Sopenharmony_ci#define MT8188_MUTEX_MOD_DISP_GAMMA0		6
12862306a36Sopenharmony_ci#define MT8188_MUTEX_MOD_DISP_DITHER0		7
12962306a36Sopenharmony_ci#define MT8188_MUTEX_MOD_DISP_DSI0		8
13062306a36Sopenharmony_ci#define MT8188_MUTEX_MOD_DISP_DSC_WRAP0_CORE0	9
13162306a36Sopenharmony_ci#define MT8188_MUTEX_MOD_DISP_VPP_MERGE		20
13262306a36Sopenharmony_ci#define MT8188_MUTEX_MOD_DISP_DP_INTF0		21
13362306a36Sopenharmony_ci#define MT8188_MUTEX_MOD_DISP_POSTMASK0		24
13462306a36Sopenharmony_ci#define MT8188_MUTEX_MOD2_DISP_PWM0		33
13562306a36Sopenharmony_ci
13662306a36Sopenharmony_ci#define MT8195_MUTEX_MOD_DISP_OVL0		0
13762306a36Sopenharmony_ci#define MT8195_MUTEX_MOD_DISP_WDMA0		1
13862306a36Sopenharmony_ci#define MT8195_MUTEX_MOD_DISP_RDMA0		2
13962306a36Sopenharmony_ci#define MT8195_MUTEX_MOD_DISP_COLOR0		3
14062306a36Sopenharmony_ci#define MT8195_MUTEX_MOD_DISP_CCORR0		4
14162306a36Sopenharmony_ci#define MT8195_MUTEX_MOD_DISP_AAL0		5
14262306a36Sopenharmony_ci#define MT8195_MUTEX_MOD_DISP_GAMMA0		6
14362306a36Sopenharmony_ci#define MT8195_MUTEX_MOD_DISP_DITHER0		7
14462306a36Sopenharmony_ci#define MT8195_MUTEX_MOD_DISP_DSI0		8
14562306a36Sopenharmony_ci#define MT8195_MUTEX_MOD_DISP_DSC_WRAP0_CORE0	9
14662306a36Sopenharmony_ci#define MT8195_MUTEX_MOD_DISP_VPP_MERGE		20
14762306a36Sopenharmony_ci#define MT8195_MUTEX_MOD_DISP_DP_INTF0		21
14862306a36Sopenharmony_ci#define MT8195_MUTEX_MOD_DISP_PWM0		27
14962306a36Sopenharmony_ci
15062306a36Sopenharmony_ci#define MT8195_MUTEX_MOD_DISP1_MDP_RDMA0	0
15162306a36Sopenharmony_ci#define MT8195_MUTEX_MOD_DISP1_MDP_RDMA1	1
15262306a36Sopenharmony_ci#define MT8195_MUTEX_MOD_DISP1_MDP_RDMA2	2
15362306a36Sopenharmony_ci#define MT8195_MUTEX_MOD_DISP1_MDP_RDMA3	3
15462306a36Sopenharmony_ci#define MT8195_MUTEX_MOD_DISP1_MDP_RDMA4	4
15562306a36Sopenharmony_ci#define MT8195_MUTEX_MOD_DISP1_MDP_RDMA5	5
15662306a36Sopenharmony_ci#define MT8195_MUTEX_MOD_DISP1_MDP_RDMA6	6
15762306a36Sopenharmony_ci#define MT8195_MUTEX_MOD_DISP1_MDP_RDMA7	7
15862306a36Sopenharmony_ci#define MT8195_MUTEX_MOD_DISP1_VPP_MERGE0	8
15962306a36Sopenharmony_ci#define MT8195_MUTEX_MOD_DISP1_VPP_MERGE1	9
16062306a36Sopenharmony_ci#define MT8195_MUTEX_MOD_DISP1_VPP_MERGE2	10
16162306a36Sopenharmony_ci#define MT8195_MUTEX_MOD_DISP1_VPP_MERGE3	11
16262306a36Sopenharmony_ci#define MT8195_MUTEX_MOD_DISP1_VPP_MERGE4	12
16362306a36Sopenharmony_ci#define MT8195_MUTEX_MOD_DISP1_DISP_MIXER	18
16462306a36Sopenharmony_ci#define MT8195_MUTEX_MOD_DISP1_DPI0		25
16562306a36Sopenharmony_ci#define MT8195_MUTEX_MOD_DISP1_DPI1		26
16662306a36Sopenharmony_ci#define MT8195_MUTEX_MOD_DISP1_DP_INTF0		27
16762306a36Sopenharmony_ci
16862306a36Sopenharmony_ci/* VPPSYS0 */
16962306a36Sopenharmony_ci#define MT8195_MUTEX_MOD_MDP_RDMA0             0
17062306a36Sopenharmony_ci#define MT8195_MUTEX_MOD_MDP_FG0               1
17162306a36Sopenharmony_ci#define MT8195_MUTEX_MOD_MDP_STITCH0           2
17262306a36Sopenharmony_ci#define MT8195_MUTEX_MOD_MDP_HDR0              3
17362306a36Sopenharmony_ci#define MT8195_MUTEX_MOD_MDP_AAL0              4
17462306a36Sopenharmony_ci#define MT8195_MUTEX_MOD_MDP_RSZ0              5
17562306a36Sopenharmony_ci#define MT8195_MUTEX_MOD_MDP_TDSHP0            6
17662306a36Sopenharmony_ci#define MT8195_MUTEX_MOD_MDP_COLOR0            7
17762306a36Sopenharmony_ci#define MT8195_MUTEX_MOD_MDP_OVL0              8
17862306a36Sopenharmony_ci#define MT8195_MUTEX_MOD_MDP_PAD0              9
17962306a36Sopenharmony_ci#define MT8195_MUTEX_MOD_MDP_TCC0              10
18062306a36Sopenharmony_ci#define MT8195_MUTEX_MOD_MDP_WROT0             11
18162306a36Sopenharmony_ci
18262306a36Sopenharmony_ci/* VPPSYS1 */
18362306a36Sopenharmony_ci#define MT8195_MUTEX_MOD_MDP_TCC1              3
18462306a36Sopenharmony_ci#define MT8195_MUTEX_MOD_MDP_RDMA1             4
18562306a36Sopenharmony_ci#define MT8195_MUTEX_MOD_MDP_RDMA2             5
18662306a36Sopenharmony_ci#define MT8195_MUTEX_MOD_MDP_RDMA3             6
18762306a36Sopenharmony_ci#define MT8195_MUTEX_MOD_MDP_FG1               7
18862306a36Sopenharmony_ci#define MT8195_MUTEX_MOD_MDP_FG2               8
18962306a36Sopenharmony_ci#define MT8195_MUTEX_MOD_MDP_FG3               9
19062306a36Sopenharmony_ci#define MT8195_MUTEX_MOD_MDP_HDR1              10
19162306a36Sopenharmony_ci#define MT8195_MUTEX_MOD_MDP_HDR2              11
19262306a36Sopenharmony_ci#define MT8195_MUTEX_MOD_MDP_HDR3              12
19362306a36Sopenharmony_ci#define MT8195_MUTEX_MOD_MDP_AAL1              13
19462306a36Sopenharmony_ci#define MT8195_MUTEX_MOD_MDP_AAL2              14
19562306a36Sopenharmony_ci#define MT8195_MUTEX_MOD_MDP_AAL3              15
19662306a36Sopenharmony_ci#define MT8195_MUTEX_MOD_MDP_RSZ1              16
19762306a36Sopenharmony_ci#define MT8195_MUTEX_MOD_MDP_RSZ2              17
19862306a36Sopenharmony_ci#define MT8195_MUTEX_MOD_MDP_RSZ3              18
19962306a36Sopenharmony_ci#define MT8195_MUTEX_MOD_MDP_TDSHP1            19
20062306a36Sopenharmony_ci#define MT8195_MUTEX_MOD_MDP_TDSHP2            20
20162306a36Sopenharmony_ci#define MT8195_MUTEX_MOD_MDP_TDSHP3            21
20262306a36Sopenharmony_ci#define MT8195_MUTEX_MOD_MDP_MERGE2            22
20362306a36Sopenharmony_ci#define MT8195_MUTEX_MOD_MDP_MERGE3            23
20462306a36Sopenharmony_ci#define MT8195_MUTEX_MOD_MDP_COLOR1            24
20562306a36Sopenharmony_ci#define MT8195_MUTEX_MOD_MDP_COLOR2            25
20662306a36Sopenharmony_ci#define MT8195_MUTEX_MOD_MDP_COLOR3            26
20762306a36Sopenharmony_ci#define MT8195_MUTEX_MOD_MDP_OVL1              27
20862306a36Sopenharmony_ci#define MT8195_MUTEX_MOD_MDP_PAD1              28
20962306a36Sopenharmony_ci#define MT8195_MUTEX_MOD_MDP_PAD2              29
21062306a36Sopenharmony_ci#define MT8195_MUTEX_MOD_MDP_PAD3              30
21162306a36Sopenharmony_ci#define MT8195_MUTEX_MOD_MDP_WROT1             31
21262306a36Sopenharmony_ci#define MT8195_MUTEX_MOD_MDP_WROT2             32
21362306a36Sopenharmony_ci#define MT8195_MUTEX_MOD_MDP_WROT3             33
21462306a36Sopenharmony_ci
21562306a36Sopenharmony_ci#define MT8365_MUTEX_MOD_DISP_OVL0		7
21662306a36Sopenharmony_ci#define MT8365_MUTEX_MOD_DISP_OVL0_2L		8
21762306a36Sopenharmony_ci#define MT8365_MUTEX_MOD_DISP_RDMA0		9
21862306a36Sopenharmony_ci#define MT8365_MUTEX_MOD_DISP_RDMA1		10
21962306a36Sopenharmony_ci#define MT8365_MUTEX_MOD_DISP_WDMA0		11
22062306a36Sopenharmony_ci#define MT8365_MUTEX_MOD_DISP_COLOR0		12
22162306a36Sopenharmony_ci#define MT8365_MUTEX_MOD_DISP_CCORR		13
22262306a36Sopenharmony_ci#define MT8365_MUTEX_MOD_DISP_AAL		14
22362306a36Sopenharmony_ci#define MT8365_MUTEX_MOD_DISP_GAMMA		15
22462306a36Sopenharmony_ci#define MT8365_MUTEX_MOD_DISP_DITHER		16
22562306a36Sopenharmony_ci#define MT8365_MUTEX_MOD_DISP_DSI0		17
22662306a36Sopenharmony_ci#define MT8365_MUTEX_MOD_DISP_PWM0		20
22762306a36Sopenharmony_ci#define MT8365_MUTEX_MOD_DISP_DPI0		22
22862306a36Sopenharmony_ci
22962306a36Sopenharmony_ci#define MT2712_MUTEX_MOD_DISP_PWM2		10
23062306a36Sopenharmony_ci#define MT2712_MUTEX_MOD_DISP_OVL0		11
23162306a36Sopenharmony_ci#define MT2712_MUTEX_MOD_DISP_OVL1		12
23262306a36Sopenharmony_ci#define MT2712_MUTEX_MOD_DISP_RDMA0		13
23362306a36Sopenharmony_ci#define MT2712_MUTEX_MOD_DISP_RDMA1		14
23462306a36Sopenharmony_ci#define MT2712_MUTEX_MOD_DISP_RDMA2		15
23562306a36Sopenharmony_ci#define MT2712_MUTEX_MOD_DISP_WDMA0		16
23662306a36Sopenharmony_ci#define MT2712_MUTEX_MOD_DISP_WDMA1		17
23762306a36Sopenharmony_ci#define MT2712_MUTEX_MOD_DISP_COLOR0		18
23862306a36Sopenharmony_ci#define MT2712_MUTEX_MOD_DISP_COLOR1		19
23962306a36Sopenharmony_ci#define MT2712_MUTEX_MOD_DISP_AAL0		20
24062306a36Sopenharmony_ci#define MT2712_MUTEX_MOD_DISP_UFOE		22
24162306a36Sopenharmony_ci#define MT2712_MUTEX_MOD_DISP_PWM0		23
24262306a36Sopenharmony_ci#define MT2712_MUTEX_MOD_DISP_PWM1		24
24362306a36Sopenharmony_ci#define MT2712_MUTEX_MOD_DISP_OD0		25
24462306a36Sopenharmony_ci#define MT2712_MUTEX_MOD2_DISP_AAL1		33
24562306a36Sopenharmony_ci#define MT2712_MUTEX_MOD2_DISP_OD1		34
24662306a36Sopenharmony_ci
24762306a36Sopenharmony_ci#define MT2701_MUTEX_MOD_DISP_OVL		3
24862306a36Sopenharmony_ci#define MT2701_MUTEX_MOD_DISP_WDMA		6
24962306a36Sopenharmony_ci#define MT2701_MUTEX_MOD_DISP_COLOR		7
25062306a36Sopenharmony_ci#define MT2701_MUTEX_MOD_DISP_BLS		9
25162306a36Sopenharmony_ci#define MT2701_MUTEX_MOD_DISP_RDMA0		10
25262306a36Sopenharmony_ci#define MT2701_MUTEX_MOD_DISP_RDMA1		12
25362306a36Sopenharmony_ci
25462306a36Sopenharmony_ci#define MT2712_MUTEX_SOF_SINGLE_MODE		0
25562306a36Sopenharmony_ci#define MT2712_MUTEX_SOF_DSI0			1
25662306a36Sopenharmony_ci#define MT2712_MUTEX_SOF_DSI1			2
25762306a36Sopenharmony_ci#define MT2712_MUTEX_SOF_DPI0			3
25862306a36Sopenharmony_ci#define MT2712_MUTEX_SOF_DPI1			4
25962306a36Sopenharmony_ci#define MT2712_MUTEX_SOF_DSI2			5
26062306a36Sopenharmony_ci#define MT2712_MUTEX_SOF_DSI3			6
26162306a36Sopenharmony_ci#define MT8167_MUTEX_SOF_DPI0			2
26262306a36Sopenharmony_ci#define MT8167_MUTEX_SOF_DPI1			3
26362306a36Sopenharmony_ci#define MT8183_MUTEX_SOF_DSI0			1
26462306a36Sopenharmony_ci#define MT8183_MUTEX_SOF_DPI0			2
26562306a36Sopenharmony_ci#define MT8188_MUTEX_SOF_DSI0			1
26662306a36Sopenharmony_ci#define MT8188_MUTEX_SOF_DP_INTF0		3
26762306a36Sopenharmony_ci#define MT8195_MUTEX_SOF_DSI0			1
26862306a36Sopenharmony_ci#define MT8195_MUTEX_SOF_DSI1			2
26962306a36Sopenharmony_ci#define MT8195_MUTEX_SOF_DP_INTF0		3
27062306a36Sopenharmony_ci#define MT8195_MUTEX_SOF_DP_INTF1		4
27162306a36Sopenharmony_ci#define MT8195_MUTEX_SOF_DPI0			6 /* for HDMI_TX */
27262306a36Sopenharmony_ci#define MT8195_MUTEX_SOF_DPI1			5 /* for digital video out */
27362306a36Sopenharmony_ci
27462306a36Sopenharmony_ci#define MT8183_MUTEX_EOF_DSI0			(MT8183_MUTEX_SOF_DSI0 << 6)
27562306a36Sopenharmony_ci#define MT8183_MUTEX_EOF_DPI0			(MT8183_MUTEX_SOF_DPI0 << 6)
27662306a36Sopenharmony_ci#define MT8188_MUTEX_EOF_DSI0			(MT8188_MUTEX_SOF_DSI0 << 7)
27762306a36Sopenharmony_ci#define MT8188_MUTEX_EOF_DP_INTF0		(MT8188_MUTEX_SOF_DP_INTF0 << 7)
27862306a36Sopenharmony_ci#define MT8195_MUTEX_EOF_DSI0			(MT8195_MUTEX_SOF_DSI0 << 7)
27962306a36Sopenharmony_ci#define MT8195_MUTEX_EOF_DSI1			(MT8195_MUTEX_SOF_DSI1 << 7)
28062306a36Sopenharmony_ci#define MT8195_MUTEX_EOF_DP_INTF0		(MT8195_MUTEX_SOF_DP_INTF0 << 7)
28162306a36Sopenharmony_ci#define MT8195_MUTEX_EOF_DP_INTF1		(MT8195_MUTEX_SOF_DP_INTF1 << 7)
28262306a36Sopenharmony_ci#define MT8195_MUTEX_EOF_DPI0			(MT8195_MUTEX_SOF_DPI0 << 7)
28362306a36Sopenharmony_ci#define MT8195_MUTEX_EOF_DPI1			(MT8195_MUTEX_SOF_DPI1 << 7)
28462306a36Sopenharmony_ci
28562306a36Sopenharmony_cistruct mtk_mutex {
28662306a36Sopenharmony_ci	u8 id;
28762306a36Sopenharmony_ci	bool claimed;
28862306a36Sopenharmony_ci};
28962306a36Sopenharmony_ci
29062306a36Sopenharmony_cienum mtk_mutex_sof_id {
29162306a36Sopenharmony_ci	MUTEX_SOF_SINGLE_MODE,
29262306a36Sopenharmony_ci	MUTEX_SOF_DSI0,
29362306a36Sopenharmony_ci	MUTEX_SOF_DSI1,
29462306a36Sopenharmony_ci	MUTEX_SOF_DPI0,
29562306a36Sopenharmony_ci	MUTEX_SOF_DPI1,
29662306a36Sopenharmony_ci	MUTEX_SOF_DSI2,
29762306a36Sopenharmony_ci	MUTEX_SOF_DSI3,
29862306a36Sopenharmony_ci	MUTEX_SOF_DP_INTF0,
29962306a36Sopenharmony_ci	MUTEX_SOF_DP_INTF1,
30062306a36Sopenharmony_ci	DDP_MUTEX_SOF_MAX,
30162306a36Sopenharmony_ci};
30262306a36Sopenharmony_ci
30362306a36Sopenharmony_cistruct mtk_mutex_data {
30462306a36Sopenharmony_ci	const unsigned int *mutex_mod;
30562306a36Sopenharmony_ci	const unsigned int *mutex_sof;
30662306a36Sopenharmony_ci	const unsigned int mutex_mod_reg;
30762306a36Sopenharmony_ci	const unsigned int mutex_sof_reg;
30862306a36Sopenharmony_ci	const unsigned int *mutex_table_mod;
30962306a36Sopenharmony_ci	const bool no_clk;
31062306a36Sopenharmony_ci};
31162306a36Sopenharmony_ci
31262306a36Sopenharmony_cistruct mtk_mutex_ctx {
31362306a36Sopenharmony_ci	struct device			*dev;
31462306a36Sopenharmony_ci	struct clk			*clk;
31562306a36Sopenharmony_ci	void __iomem			*regs;
31662306a36Sopenharmony_ci	struct mtk_mutex		mutex[MTK_MUTEX_MAX_HANDLES];
31762306a36Sopenharmony_ci	const struct mtk_mutex_data	*data;
31862306a36Sopenharmony_ci	phys_addr_t			addr;
31962306a36Sopenharmony_ci	struct cmdq_client_reg		cmdq_reg;
32062306a36Sopenharmony_ci};
32162306a36Sopenharmony_ci
32262306a36Sopenharmony_cistatic const unsigned int mt2701_mutex_mod[DDP_COMPONENT_ID_MAX] = {
32362306a36Sopenharmony_ci	[DDP_COMPONENT_BLS] = MT2701_MUTEX_MOD_DISP_BLS,
32462306a36Sopenharmony_ci	[DDP_COMPONENT_COLOR0] = MT2701_MUTEX_MOD_DISP_COLOR,
32562306a36Sopenharmony_ci	[DDP_COMPONENT_OVL0] = MT2701_MUTEX_MOD_DISP_OVL,
32662306a36Sopenharmony_ci	[DDP_COMPONENT_RDMA0] = MT2701_MUTEX_MOD_DISP_RDMA0,
32762306a36Sopenharmony_ci	[DDP_COMPONENT_RDMA1] = MT2701_MUTEX_MOD_DISP_RDMA1,
32862306a36Sopenharmony_ci	[DDP_COMPONENT_WDMA0] = MT2701_MUTEX_MOD_DISP_WDMA,
32962306a36Sopenharmony_ci};
33062306a36Sopenharmony_ci
33162306a36Sopenharmony_cistatic const unsigned int mt2712_mutex_mod[DDP_COMPONENT_ID_MAX] = {
33262306a36Sopenharmony_ci	[DDP_COMPONENT_AAL0] = MT2712_MUTEX_MOD_DISP_AAL0,
33362306a36Sopenharmony_ci	[DDP_COMPONENT_AAL1] = MT2712_MUTEX_MOD2_DISP_AAL1,
33462306a36Sopenharmony_ci	[DDP_COMPONENT_COLOR0] = MT2712_MUTEX_MOD_DISP_COLOR0,
33562306a36Sopenharmony_ci	[DDP_COMPONENT_COLOR1] = MT2712_MUTEX_MOD_DISP_COLOR1,
33662306a36Sopenharmony_ci	[DDP_COMPONENT_OD0] = MT2712_MUTEX_MOD_DISP_OD0,
33762306a36Sopenharmony_ci	[DDP_COMPONENT_OD1] = MT2712_MUTEX_MOD2_DISP_OD1,
33862306a36Sopenharmony_ci	[DDP_COMPONENT_OVL0] = MT2712_MUTEX_MOD_DISP_OVL0,
33962306a36Sopenharmony_ci	[DDP_COMPONENT_OVL1] = MT2712_MUTEX_MOD_DISP_OVL1,
34062306a36Sopenharmony_ci	[DDP_COMPONENT_PWM0] = MT2712_MUTEX_MOD_DISP_PWM0,
34162306a36Sopenharmony_ci	[DDP_COMPONENT_PWM1] = MT2712_MUTEX_MOD_DISP_PWM1,
34262306a36Sopenharmony_ci	[DDP_COMPONENT_PWM2] = MT2712_MUTEX_MOD_DISP_PWM2,
34362306a36Sopenharmony_ci	[DDP_COMPONENT_RDMA0] = MT2712_MUTEX_MOD_DISP_RDMA0,
34462306a36Sopenharmony_ci	[DDP_COMPONENT_RDMA1] = MT2712_MUTEX_MOD_DISP_RDMA1,
34562306a36Sopenharmony_ci	[DDP_COMPONENT_RDMA2] = MT2712_MUTEX_MOD_DISP_RDMA2,
34662306a36Sopenharmony_ci	[DDP_COMPONENT_UFOE] = MT2712_MUTEX_MOD_DISP_UFOE,
34762306a36Sopenharmony_ci	[DDP_COMPONENT_WDMA0] = MT2712_MUTEX_MOD_DISP_WDMA0,
34862306a36Sopenharmony_ci	[DDP_COMPONENT_WDMA1] = MT2712_MUTEX_MOD_DISP_WDMA1,
34962306a36Sopenharmony_ci};
35062306a36Sopenharmony_ci
35162306a36Sopenharmony_cistatic const unsigned int mt8167_mutex_mod[DDP_COMPONENT_ID_MAX] = {
35262306a36Sopenharmony_ci	[DDP_COMPONENT_AAL0] = MT8167_MUTEX_MOD_DISP_AAL,
35362306a36Sopenharmony_ci	[DDP_COMPONENT_CCORR] = MT8167_MUTEX_MOD_DISP_CCORR,
35462306a36Sopenharmony_ci	[DDP_COMPONENT_COLOR0] = MT8167_MUTEX_MOD_DISP_COLOR,
35562306a36Sopenharmony_ci	[DDP_COMPONENT_DITHER0] = MT8167_MUTEX_MOD_DISP_DITHER,
35662306a36Sopenharmony_ci	[DDP_COMPONENT_GAMMA] = MT8167_MUTEX_MOD_DISP_GAMMA,
35762306a36Sopenharmony_ci	[DDP_COMPONENT_OVL0] = MT8167_MUTEX_MOD_DISP_OVL0,
35862306a36Sopenharmony_ci	[DDP_COMPONENT_OVL1] = MT8167_MUTEX_MOD_DISP_OVL1,
35962306a36Sopenharmony_ci	[DDP_COMPONENT_PWM0] = MT8167_MUTEX_MOD_DISP_PWM,
36062306a36Sopenharmony_ci	[DDP_COMPONENT_RDMA0] = MT8167_MUTEX_MOD_DISP_RDMA0,
36162306a36Sopenharmony_ci	[DDP_COMPONENT_RDMA1] = MT8167_MUTEX_MOD_DISP_RDMA1,
36262306a36Sopenharmony_ci	[DDP_COMPONENT_UFOE] = MT8167_MUTEX_MOD_DISP_UFOE,
36362306a36Sopenharmony_ci	[DDP_COMPONENT_WDMA0] = MT8167_MUTEX_MOD_DISP_WDMA0,
36462306a36Sopenharmony_ci};
36562306a36Sopenharmony_ci
36662306a36Sopenharmony_cistatic const unsigned int mt8173_mutex_mod[DDP_COMPONENT_ID_MAX] = {
36762306a36Sopenharmony_ci	[DDP_COMPONENT_AAL0] = MT8173_MUTEX_MOD_DISP_AAL,
36862306a36Sopenharmony_ci	[DDP_COMPONENT_COLOR0] = MT8173_MUTEX_MOD_DISP_COLOR0,
36962306a36Sopenharmony_ci	[DDP_COMPONENT_COLOR1] = MT8173_MUTEX_MOD_DISP_COLOR1,
37062306a36Sopenharmony_ci	[DDP_COMPONENT_GAMMA] = MT8173_MUTEX_MOD_DISP_GAMMA,
37162306a36Sopenharmony_ci	[DDP_COMPONENT_OD0] = MT8173_MUTEX_MOD_DISP_OD,
37262306a36Sopenharmony_ci	[DDP_COMPONENT_OVL0] = MT8173_MUTEX_MOD_DISP_OVL0,
37362306a36Sopenharmony_ci	[DDP_COMPONENT_OVL1] = MT8173_MUTEX_MOD_DISP_OVL1,
37462306a36Sopenharmony_ci	[DDP_COMPONENT_PWM0] = MT8173_MUTEX_MOD_DISP_PWM0,
37562306a36Sopenharmony_ci	[DDP_COMPONENT_PWM1] = MT8173_MUTEX_MOD_DISP_PWM1,
37662306a36Sopenharmony_ci	[DDP_COMPONENT_RDMA0] = MT8173_MUTEX_MOD_DISP_RDMA0,
37762306a36Sopenharmony_ci	[DDP_COMPONENT_RDMA1] = MT8173_MUTEX_MOD_DISP_RDMA1,
37862306a36Sopenharmony_ci	[DDP_COMPONENT_RDMA2] = MT8173_MUTEX_MOD_DISP_RDMA2,
37962306a36Sopenharmony_ci	[DDP_COMPONENT_UFOE] = MT8173_MUTEX_MOD_DISP_UFOE,
38062306a36Sopenharmony_ci	[DDP_COMPONENT_WDMA0] = MT8173_MUTEX_MOD_DISP_WDMA0,
38162306a36Sopenharmony_ci	[DDP_COMPONENT_WDMA1] = MT8173_MUTEX_MOD_DISP_WDMA1,
38262306a36Sopenharmony_ci};
38362306a36Sopenharmony_ci
38462306a36Sopenharmony_cistatic const unsigned int mt8183_mutex_mod[DDP_COMPONENT_ID_MAX] = {
38562306a36Sopenharmony_ci	[DDP_COMPONENT_AAL0] = MT8183_MUTEX_MOD_DISP_AAL0,
38662306a36Sopenharmony_ci	[DDP_COMPONENT_CCORR] = MT8183_MUTEX_MOD_DISP_CCORR0,
38762306a36Sopenharmony_ci	[DDP_COMPONENT_COLOR0] = MT8183_MUTEX_MOD_DISP_COLOR0,
38862306a36Sopenharmony_ci	[DDP_COMPONENT_DITHER0] = MT8183_MUTEX_MOD_DISP_DITHER0,
38962306a36Sopenharmony_ci	[DDP_COMPONENT_GAMMA] = MT8183_MUTEX_MOD_DISP_GAMMA0,
39062306a36Sopenharmony_ci	[DDP_COMPONENT_OVL0] = MT8183_MUTEX_MOD_DISP_OVL0,
39162306a36Sopenharmony_ci	[DDP_COMPONENT_OVL_2L0] = MT8183_MUTEX_MOD_DISP_OVL0_2L,
39262306a36Sopenharmony_ci	[DDP_COMPONENT_OVL_2L1] = MT8183_MUTEX_MOD_DISP_OVL1_2L,
39362306a36Sopenharmony_ci	[DDP_COMPONENT_RDMA0] = MT8183_MUTEX_MOD_DISP_RDMA0,
39462306a36Sopenharmony_ci	[DDP_COMPONENT_RDMA1] = MT8183_MUTEX_MOD_DISP_RDMA1,
39562306a36Sopenharmony_ci	[DDP_COMPONENT_WDMA0] = MT8183_MUTEX_MOD_DISP_WDMA0,
39662306a36Sopenharmony_ci};
39762306a36Sopenharmony_ci
39862306a36Sopenharmony_cistatic const unsigned int mt8183_mutex_table_mod[MUTEX_MOD_IDX_MAX] = {
39962306a36Sopenharmony_ci	[MUTEX_MOD_IDX_MDP_RDMA0] = MT8183_MUTEX_MOD_MDP_RDMA0,
40062306a36Sopenharmony_ci	[MUTEX_MOD_IDX_MDP_RSZ0] = MT8183_MUTEX_MOD_MDP_RSZ0,
40162306a36Sopenharmony_ci	[MUTEX_MOD_IDX_MDP_RSZ1] = MT8183_MUTEX_MOD_MDP_RSZ1,
40262306a36Sopenharmony_ci	[MUTEX_MOD_IDX_MDP_TDSHP0] = MT8183_MUTEX_MOD_MDP_TDSHP0,
40362306a36Sopenharmony_ci	[MUTEX_MOD_IDX_MDP_WROT0] = MT8183_MUTEX_MOD_MDP_WROT0,
40462306a36Sopenharmony_ci	[MUTEX_MOD_IDX_MDP_WDMA] = MT8183_MUTEX_MOD_MDP_WDMA,
40562306a36Sopenharmony_ci	[MUTEX_MOD_IDX_MDP_AAL0] = MT8183_MUTEX_MOD_MDP_AAL0,
40662306a36Sopenharmony_ci	[MUTEX_MOD_IDX_MDP_CCORR0] = MT8183_MUTEX_MOD_MDP_CCORR0,
40762306a36Sopenharmony_ci};
40862306a36Sopenharmony_ci
40962306a36Sopenharmony_cistatic const unsigned int mt8186_mutex_mod[DDP_COMPONENT_ID_MAX] = {
41062306a36Sopenharmony_ci	[DDP_COMPONENT_AAL0] = MT8186_MUTEX_MOD_DISP_AAL0,
41162306a36Sopenharmony_ci	[DDP_COMPONENT_CCORR] = MT8186_MUTEX_MOD_DISP_CCORR0,
41262306a36Sopenharmony_ci	[DDP_COMPONENT_COLOR0] = MT8186_MUTEX_MOD_DISP_COLOR0,
41362306a36Sopenharmony_ci	[DDP_COMPONENT_DITHER0] = MT8186_MUTEX_MOD_DISP_DITHER0,
41462306a36Sopenharmony_ci	[DDP_COMPONENT_GAMMA] = MT8186_MUTEX_MOD_DISP_GAMMA0,
41562306a36Sopenharmony_ci	[DDP_COMPONENT_OVL0] = MT8186_MUTEX_MOD_DISP_OVL0,
41662306a36Sopenharmony_ci	[DDP_COMPONENT_OVL_2L0] = MT8186_MUTEX_MOD_DISP_OVL0_2L,
41762306a36Sopenharmony_ci	[DDP_COMPONENT_POSTMASK0] = MT8186_MUTEX_MOD_DISP_POSTMASK0,
41862306a36Sopenharmony_ci	[DDP_COMPONENT_RDMA0] = MT8186_MUTEX_MOD_DISP_RDMA0,
41962306a36Sopenharmony_ci	[DDP_COMPONENT_RDMA1] = MT8186_MUTEX_MOD_DISP_RDMA1,
42062306a36Sopenharmony_ci};
42162306a36Sopenharmony_ci
42262306a36Sopenharmony_cistatic const unsigned int mt8186_mdp_mutex_table_mod[MUTEX_MOD_IDX_MAX] = {
42362306a36Sopenharmony_ci	[MUTEX_MOD_IDX_MDP_RDMA0] = MT8186_MUTEX_MOD_MDP_RDMA0,
42462306a36Sopenharmony_ci	[MUTEX_MOD_IDX_MDP_RSZ0] = MT8186_MUTEX_MOD_MDP_RSZ0,
42562306a36Sopenharmony_ci	[MUTEX_MOD_IDX_MDP_RSZ1] = MT8186_MUTEX_MOD_MDP_RSZ1,
42662306a36Sopenharmony_ci	[MUTEX_MOD_IDX_MDP_TDSHP0] = MT8186_MUTEX_MOD_MDP_TDSHP0,
42762306a36Sopenharmony_ci	[MUTEX_MOD_IDX_MDP_WROT0] = MT8186_MUTEX_MOD_MDP_WROT0,
42862306a36Sopenharmony_ci	[MUTEX_MOD_IDX_MDP_HDR0] = MT8186_MUTEX_MOD_MDP_HDR0,
42962306a36Sopenharmony_ci	[MUTEX_MOD_IDX_MDP_AAL0] = MT8186_MUTEX_MOD_MDP_AAL0,
43062306a36Sopenharmony_ci	[MUTEX_MOD_IDX_MDP_COLOR0] = MT8186_MUTEX_MOD_MDP_COLOR0,
43162306a36Sopenharmony_ci};
43262306a36Sopenharmony_ci
43362306a36Sopenharmony_cistatic const unsigned int mt8188_mutex_mod[DDP_COMPONENT_ID_MAX] = {
43462306a36Sopenharmony_ci	[DDP_COMPONENT_OVL0] = MT8188_MUTEX_MOD_DISP_OVL0,
43562306a36Sopenharmony_ci	[DDP_COMPONENT_WDMA0] = MT8188_MUTEX_MOD_DISP_WDMA0,
43662306a36Sopenharmony_ci	[DDP_COMPONENT_RDMA0] = MT8188_MUTEX_MOD_DISP_RDMA0,
43762306a36Sopenharmony_ci	[DDP_COMPONENT_COLOR0] = MT8188_MUTEX_MOD_DISP_COLOR0,
43862306a36Sopenharmony_ci	[DDP_COMPONENT_CCORR] = MT8188_MUTEX_MOD_DISP_CCORR0,
43962306a36Sopenharmony_ci	[DDP_COMPONENT_AAL0] = MT8188_MUTEX_MOD_DISP_AAL0,
44062306a36Sopenharmony_ci	[DDP_COMPONENT_GAMMA] = MT8188_MUTEX_MOD_DISP_GAMMA0,
44162306a36Sopenharmony_ci	[DDP_COMPONENT_POSTMASK0] = MT8188_MUTEX_MOD_DISP_POSTMASK0,
44262306a36Sopenharmony_ci	[DDP_COMPONENT_DITHER0] = MT8188_MUTEX_MOD_DISP_DITHER0,
44362306a36Sopenharmony_ci	[DDP_COMPONENT_MERGE0] = MT8188_MUTEX_MOD_DISP_VPP_MERGE,
44462306a36Sopenharmony_ci	[DDP_COMPONENT_DSC0] = MT8188_MUTEX_MOD_DISP_DSC_WRAP0_CORE0,
44562306a36Sopenharmony_ci	[DDP_COMPONENT_DSI0] = MT8188_MUTEX_MOD_DISP_DSI0,
44662306a36Sopenharmony_ci	[DDP_COMPONENT_PWM0] = MT8188_MUTEX_MOD2_DISP_PWM0,
44762306a36Sopenharmony_ci	[DDP_COMPONENT_DP_INTF0] = MT8188_MUTEX_MOD_DISP_DP_INTF0,
44862306a36Sopenharmony_ci};
44962306a36Sopenharmony_ci
45062306a36Sopenharmony_cistatic const unsigned int mt8192_mutex_mod[DDP_COMPONENT_ID_MAX] = {
45162306a36Sopenharmony_ci	[DDP_COMPONENT_AAL0] = MT8192_MUTEX_MOD_DISP_AAL0,
45262306a36Sopenharmony_ci	[DDP_COMPONENT_CCORR] = MT8192_MUTEX_MOD_DISP_CCORR0,
45362306a36Sopenharmony_ci	[DDP_COMPONENT_COLOR0] = MT8192_MUTEX_MOD_DISP_COLOR0,
45462306a36Sopenharmony_ci	[DDP_COMPONENT_DITHER0] = MT8192_MUTEX_MOD_DISP_DITHER0,
45562306a36Sopenharmony_ci	[DDP_COMPONENT_GAMMA] = MT8192_MUTEX_MOD_DISP_GAMMA0,
45662306a36Sopenharmony_ci	[DDP_COMPONENT_POSTMASK0] = MT8192_MUTEX_MOD_DISP_POSTMASK0,
45762306a36Sopenharmony_ci	[DDP_COMPONENT_OVL0] = MT8192_MUTEX_MOD_DISP_OVL0,
45862306a36Sopenharmony_ci	[DDP_COMPONENT_OVL_2L0] = MT8192_MUTEX_MOD_DISP_OVL0_2L,
45962306a36Sopenharmony_ci	[DDP_COMPONENT_OVL_2L2] = MT8192_MUTEX_MOD_DISP_OVL2_2L,
46062306a36Sopenharmony_ci	[DDP_COMPONENT_RDMA0] = MT8192_MUTEX_MOD_DISP_RDMA0,
46162306a36Sopenharmony_ci	[DDP_COMPONENT_RDMA4] = MT8192_MUTEX_MOD_DISP_RDMA4,
46262306a36Sopenharmony_ci};
46362306a36Sopenharmony_ci
46462306a36Sopenharmony_cistatic const unsigned int mt8195_mutex_mod[DDP_COMPONENT_ID_MAX] = {
46562306a36Sopenharmony_ci	[DDP_COMPONENT_OVL0] = MT8195_MUTEX_MOD_DISP_OVL0,
46662306a36Sopenharmony_ci	[DDP_COMPONENT_WDMA0] = MT8195_MUTEX_MOD_DISP_WDMA0,
46762306a36Sopenharmony_ci	[DDP_COMPONENT_RDMA0] = MT8195_MUTEX_MOD_DISP_RDMA0,
46862306a36Sopenharmony_ci	[DDP_COMPONENT_COLOR0] = MT8195_MUTEX_MOD_DISP_COLOR0,
46962306a36Sopenharmony_ci	[DDP_COMPONENT_CCORR] = MT8195_MUTEX_MOD_DISP_CCORR0,
47062306a36Sopenharmony_ci	[DDP_COMPONENT_AAL0] = MT8195_MUTEX_MOD_DISP_AAL0,
47162306a36Sopenharmony_ci	[DDP_COMPONENT_GAMMA] = MT8195_MUTEX_MOD_DISP_GAMMA0,
47262306a36Sopenharmony_ci	[DDP_COMPONENT_DITHER0] = MT8195_MUTEX_MOD_DISP_DITHER0,
47362306a36Sopenharmony_ci	[DDP_COMPONENT_MERGE0] = MT8195_MUTEX_MOD_DISP_VPP_MERGE,
47462306a36Sopenharmony_ci	[DDP_COMPONENT_DSC0] = MT8195_MUTEX_MOD_DISP_DSC_WRAP0_CORE0,
47562306a36Sopenharmony_ci	[DDP_COMPONENT_DSI0] = MT8195_MUTEX_MOD_DISP_DSI0,
47662306a36Sopenharmony_ci	[DDP_COMPONENT_PWM0] = MT8195_MUTEX_MOD_DISP_PWM0,
47762306a36Sopenharmony_ci	[DDP_COMPONENT_DP_INTF0] = MT8195_MUTEX_MOD_DISP_DP_INTF0,
47862306a36Sopenharmony_ci	[DDP_COMPONENT_MDP_RDMA0] = MT8195_MUTEX_MOD_DISP1_MDP_RDMA0,
47962306a36Sopenharmony_ci	[DDP_COMPONENT_MDP_RDMA1] = MT8195_MUTEX_MOD_DISP1_MDP_RDMA1,
48062306a36Sopenharmony_ci	[DDP_COMPONENT_MDP_RDMA2] = MT8195_MUTEX_MOD_DISP1_MDP_RDMA2,
48162306a36Sopenharmony_ci	[DDP_COMPONENT_MDP_RDMA3] = MT8195_MUTEX_MOD_DISP1_MDP_RDMA3,
48262306a36Sopenharmony_ci	[DDP_COMPONENT_MDP_RDMA4] = MT8195_MUTEX_MOD_DISP1_MDP_RDMA4,
48362306a36Sopenharmony_ci	[DDP_COMPONENT_MDP_RDMA5] = MT8195_MUTEX_MOD_DISP1_MDP_RDMA5,
48462306a36Sopenharmony_ci	[DDP_COMPONENT_MDP_RDMA6] = MT8195_MUTEX_MOD_DISP1_MDP_RDMA6,
48562306a36Sopenharmony_ci	[DDP_COMPONENT_MDP_RDMA7] = MT8195_MUTEX_MOD_DISP1_MDP_RDMA7,
48662306a36Sopenharmony_ci	[DDP_COMPONENT_MERGE1] = MT8195_MUTEX_MOD_DISP1_VPP_MERGE0,
48762306a36Sopenharmony_ci	[DDP_COMPONENT_MERGE2] = MT8195_MUTEX_MOD_DISP1_VPP_MERGE1,
48862306a36Sopenharmony_ci	[DDP_COMPONENT_MERGE3] = MT8195_MUTEX_MOD_DISP1_VPP_MERGE2,
48962306a36Sopenharmony_ci	[DDP_COMPONENT_MERGE4] = MT8195_MUTEX_MOD_DISP1_VPP_MERGE3,
49062306a36Sopenharmony_ci	[DDP_COMPONENT_ETHDR_MIXER] = MT8195_MUTEX_MOD_DISP1_DISP_MIXER,
49162306a36Sopenharmony_ci	[DDP_COMPONENT_MERGE5] = MT8195_MUTEX_MOD_DISP1_VPP_MERGE4,
49262306a36Sopenharmony_ci	[DDP_COMPONENT_DP_INTF1] = MT8195_MUTEX_MOD_DISP1_DP_INTF0,
49362306a36Sopenharmony_ci};
49462306a36Sopenharmony_ci
49562306a36Sopenharmony_cistatic const unsigned int mt8195_mutex_table_mod[MUTEX_MOD_IDX_MAX] = {
49662306a36Sopenharmony_ci	[MUTEX_MOD_IDX_MDP_RDMA0] = MT8195_MUTEX_MOD_MDP_RDMA0,
49762306a36Sopenharmony_ci	[MUTEX_MOD_IDX_MDP_RDMA1] = MT8195_MUTEX_MOD_MDP_RDMA1,
49862306a36Sopenharmony_ci	[MUTEX_MOD_IDX_MDP_RDMA2] = MT8195_MUTEX_MOD_MDP_RDMA2,
49962306a36Sopenharmony_ci	[MUTEX_MOD_IDX_MDP_RDMA3] = MT8195_MUTEX_MOD_MDP_RDMA3,
50062306a36Sopenharmony_ci	[MUTEX_MOD_IDX_MDP_STITCH0] = MT8195_MUTEX_MOD_MDP_STITCH0,
50162306a36Sopenharmony_ci	[MUTEX_MOD_IDX_MDP_FG0] = MT8195_MUTEX_MOD_MDP_FG0,
50262306a36Sopenharmony_ci	[MUTEX_MOD_IDX_MDP_FG1] = MT8195_MUTEX_MOD_MDP_FG1,
50362306a36Sopenharmony_ci	[MUTEX_MOD_IDX_MDP_FG2] = MT8195_MUTEX_MOD_MDP_FG2,
50462306a36Sopenharmony_ci	[MUTEX_MOD_IDX_MDP_FG3] = MT8195_MUTEX_MOD_MDP_FG3,
50562306a36Sopenharmony_ci	[MUTEX_MOD_IDX_MDP_HDR0] = MT8195_MUTEX_MOD_MDP_HDR0,
50662306a36Sopenharmony_ci	[MUTEX_MOD_IDX_MDP_HDR1] = MT8195_MUTEX_MOD_MDP_HDR1,
50762306a36Sopenharmony_ci	[MUTEX_MOD_IDX_MDP_HDR2] = MT8195_MUTEX_MOD_MDP_HDR2,
50862306a36Sopenharmony_ci	[MUTEX_MOD_IDX_MDP_HDR3] = MT8195_MUTEX_MOD_MDP_HDR3,
50962306a36Sopenharmony_ci	[MUTEX_MOD_IDX_MDP_AAL0] = MT8195_MUTEX_MOD_MDP_AAL0,
51062306a36Sopenharmony_ci	[MUTEX_MOD_IDX_MDP_AAL1] = MT8195_MUTEX_MOD_MDP_AAL1,
51162306a36Sopenharmony_ci	[MUTEX_MOD_IDX_MDP_AAL2] = MT8195_MUTEX_MOD_MDP_AAL2,
51262306a36Sopenharmony_ci	[MUTEX_MOD_IDX_MDP_AAL3] = MT8195_MUTEX_MOD_MDP_AAL3,
51362306a36Sopenharmony_ci	[MUTEX_MOD_IDX_MDP_RSZ0] = MT8195_MUTEX_MOD_MDP_RSZ0,
51462306a36Sopenharmony_ci	[MUTEX_MOD_IDX_MDP_RSZ1] = MT8195_MUTEX_MOD_MDP_RSZ1,
51562306a36Sopenharmony_ci	[MUTEX_MOD_IDX_MDP_RSZ2] = MT8195_MUTEX_MOD_MDP_RSZ2,
51662306a36Sopenharmony_ci	[MUTEX_MOD_IDX_MDP_RSZ3] = MT8195_MUTEX_MOD_MDP_RSZ3,
51762306a36Sopenharmony_ci	[MUTEX_MOD_IDX_MDP_MERGE2] = MT8195_MUTEX_MOD_MDP_MERGE2,
51862306a36Sopenharmony_ci	[MUTEX_MOD_IDX_MDP_MERGE3] = MT8195_MUTEX_MOD_MDP_MERGE3,
51962306a36Sopenharmony_ci	[MUTEX_MOD_IDX_MDP_TDSHP0] = MT8195_MUTEX_MOD_MDP_TDSHP0,
52062306a36Sopenharmony_ci	[MUTEX_MOD_IDX_MDP_TDSHP1] = MT8195_MUTEX_MOD_MDP_TDSHP1,
52162306a36Sopenharmony_ci	[MUTEX_MOD_IDX_MDP_TDSHP2] = MT8195_MUTEX_MOD_MDP_TDSHP2,
52262306a36Sopenharmony_ci	[MUTEX_MOD_IDX_MDP_TDSHP3] = MT8195_MUTEX_MOD_MDP_TDSHP3,
52362306a36Sopenharmony_ci	[MUTEX_MOD_IDX_MDP_COLOR0] = MT8195_MUTEX_MOD_MDP_COLOR0,
52462306a36Sopenharmony_ci	[MUTEX_MOD_IDX_MDP_COLOR1] = MT8195_MUTEX_MOD_MDP_COLOR1,
52562306a36Sopenharmony_ci	[MUTEX_MOD_IDX_MDP_COLOR2] = MT8195_MUTEX_MOD_MDP_COLOR2,
52662306a36Sopenharmony_ci	[MUTEX_MOD_IDX_MDP_COLOR3] = MT8195_MUTEX_MOD_MDP_COLOR3,
52762306a36Sopenharmony_ci	[MUTEX_MOD_IDX_MDP_OVL0] = MT8195_MUTEX_MOD_MDP_OVL0,
52862306a36Sopenharmony_ci	[MUTEX_MOD_IDX_MDP_OVL1] = MT8195_MUTEX_MOD_MDP_OVL1,
52962306a36Sopenharmony_ci	[MUTEX_MOD_IDX_MDP_PAD0] = MT8195_MUTEX_MOD_MDP_PAD0,
53062306a36Sopenharmony_ci	[MUTEX_MOD_IDX_MDP_PAD1] = MT8195_MUTEX_MOD_MDP_PAD1,
53162306a36Sopenharmony_ci	[MUTEX_MOD_IDX_MDP_PAD2] = MT8195_MUTEX_MOD_MDP_PAD2,
53262306a36Sopenharmony_ci	[MUTEX_MOD_IDX_MDP_PAD3] = MT8195_MUTEX_MOD_MDP_PAD3,
53362306a36Sopenharmony_ci	[MUTEX_MOD_IDX_MDP_TCC0] = MT8195_MUTEX_MOD_MDP_TCC0,
53462306a36Sopenharmony_ci	[MUTEX_MOD_IDX_MDP_TCC1] = MT8195_MUTEX_MOD_MDP_TCC1,
53562306a36Sopenharmony_ci	[MUTEX_MOD_IDX_MDP_WROT0] = MT8195_MUTEX_MOD_MDP_WROT0,
53662306a36Sopenharmony_ci	[MUTEX_MOD_IDX_MDP_WROT1] = MT8195_MUTEX_MOD_MDP_WROT1,
53762306a36Sopenharmony_ci	[MUTEX_MOD_IDX_MDP_WROT2] = MT8195_MUTEX_MOD_MDP_WROT2,
53862306a36Sopenharmony_ci	[MUTEX_MOD_IDX_MDP_WROT3] = MT8195_MUTEX_MOD_MDP_WROT3,
53962306a36Sopenharmony_ci};
54062306a36Sopenharmony_ci
54162306a36Sopenharmony_cistatic const unsigned int mt8365_mutex_mod[DDP_COMPONENT_ID_MAX] = {
54262306a36Sopenharmony_ci	[DDP_COMPONENT_AAL0] = MT8365_MUTEX_MOD_DISP_AAL,
54362306a36Sopenharmony_ci	[DDP_COMPONENT_CCORR] = MT8365_MUTEX_MOD_DISP_CCORR,
54462306a36Sopenharmony_ci	[DDP_COMPONENT_COLOR0] = MT8365_MUTEX_MOD_DISP_COLOR0,
54562306a36Sopenharmony_ci	[DDP_COMPONENT_DITHER0] = MT8365_MUTEX_MOD_DISP_DITHER,
54662306a36Sopenharmony_ci	[DDP_COMPONENT_DPI0] = MT8365_MUTEX_MOD_DISP_DPI0,
54762306a36Sopenharmony_ci	[DDP_COMPONENT_DSI0] = MT8365_MUTEX_MOD_DISP_DSI0,
54862306a36Sopenharmony_ci	[DDP_COMPONENT_GAMMA] = MT8365_MUTEX_MOD_DISP_GAMMA,
54962306a36Sopenharmony_ci	[DDP_COMPONENT_OVL0] = MT8365_MUTEX_MOD_DISP_OVL0,
55062306a36Sopenharmony_ci	[DDP_COMPONENT_OVL_2L0] = MT8365_MUTEX_MOD_DISP_OVL0_2L,
55162306a36Sopenharmony_ci	[DDP_COMPONENT_PWM0] = MT8365_MUTEX_MOD_DISP_PWM0,
55262306a36Sopenharmony_ci	[DDP_COMPONENT_RDMA0] = MT8365_MUTEX_MOD_DISP_RDMA0,
55362306a36Sopenharmony_ci	[DDP_COMPONENT_RDMA1] = MT8365_MUTEX_MOD_DISP_RDMA1,
55462306a36Sopenharmony_ci	[DDP_COMPONENT_WDMA0] = MT8365_MUTEX_MOD_DISP_WDMA0,
55562306a36Sopenharmony_ci};
55662306a36Sopenharmony_ci
55762306a36Sopenharmony_cistatic const unsigned int mt2712_mutex_sof[DDP_MUTEX_SOF_MAX] = {
55862306a36Sopenharmony_ci	[MUTEX_SOF_SINGLE_MODE] = MUTEX_SOF_SINGLE_MODE,
55962306a36Sopenharmony_ci	[MUTEX_SOF_DSI0] = MUTEX_SOF_DSI0,
56062306a36Sopenharmony_ci	[MUTEX_SOF_DSI1] = MUTEX_SOF_DSI1,
56162306a36Sopenharmony_ci	[MUTEX_SOF_DPI0] = MUTEX_SOF_DPI0,
56262306a36Sopenharmony_ci	[MUTEX_SOF_DPI1] = MUTEX_SOF_DPI1,
56362306a36Sopenharmony_ci	[MUTEX_SOF_DSI2] = MUTEX_SOF_DSI2,
56462306a36Sopenharmony_ci	[MUTEX_SOF_DSI3] = MUTEX_SOF_DSI3,
56562306a36Sopenharmony_ci};
56662306a36Sopenharmony_ci
56762306a36Sopenharmony_cistatic const unsigned int mt6795_mutex_sof[DDP_MUTEX_SOF_MAX] = {
56862306a36Sopenharmony_ci	[MUTEX_SOF_SINGLE_MODE] = MUTEX_SOF_SINGLE_MODE,
56962306a36Sopenharmony_ci	[MUTEX_SOF_DSI0] = MUTEX_SOF_DSI0,
57062306a36Sopenharmony_ci	[MUTEX_SOF_DSI1] = MUTEX_SOF_DSI1,
57162306a36Sopenharmony_ci	[MUTEX_SOF_DPI0] = MUTEX_SOF_DPI0,
57262306a36Sopenharmony_ci};
57362306a36Sopenharmony_ci
57462306a36Sopenharmony_cistatic const unsigned int mt8167_mutex_sof[DDP_MUTEX_SOF_MAX] = {
57562306a36Sopenharmony_ci	[MUTEX_SOF_SINGLE_MODE] = MUTEX_SOF_SINGLE_MODE,
57662306a36Sopenharmony_ci	[MUTEX_SOF_DSI0] = MUTEX_SOF_DSI0,
57762306a36Sopenharmony_ci	[MUTEX_SOF_DPI0] = MT8167_MUTEX_SOF_DPI0,
57862306a36Sopenharmony_ci	[MUTEX_SOF_DPI1] = MT8167_MUTEX_SOF_DPI1,
57962306a36Sopenharmony_ci};
58062306a36Sopenharmony_ci
58162306a36Sopenharmony_ci/* Add EOF setting so overlay hardware can receive frame done irq */
58262306a36Sopenharmony_cistatic const unsigned int mt8183_mutex_sof[DDP_MUTEX_SOF_MAX] = {
58362306a36Sopenharmony_ci	[MUTEX_SOF_SINGLE_MODE] = MUTEX_SOF_SINGLE_MODE,
58462306a36Sopenharmony_ci	[MUTEX_SOF_DSI0] = MUTEX_SOF_DSI0 | MT8183_MUTEX_EOF_DSI0,
58562306a36Sopenharmony_ci	[MUTEX_SOF_DPI0] = MT8183_MUTEX_SOF_DPI0 | MT8183_MUTEX_EOF_DPI0,
58662306a36Sopenharmony_ci};
58762306a36Sopenharmony_ci
58862306a36Sopenharmony_cistatic const unsigned int mt8186_mutex_sof[MUTEX_SOF_DSI3 + 1] = {
58962306a36Sopenharmony_ci	[MUTEX_SOF_SINGLE_MODE] = MUTEX_SOF_SINGLE_MODE,
59062306a36Sopenharmony_ci	[MUTEX_SOF_DSI0] = MT8186_MUTEX_SOF_DSI0 | MT8186_MUTEX_EOF_DSI0,
59162306a36Sopenharmony_ci	[MUTEX_SOF_DPI0] = MT8186_MUTEX_SOF_DPI0 | MT8186_MUTEX_EOF_DPI0,
59262306a36Sopenharmony_ci};
59362306a36Sopenharmony_ci
59462306a36Sopenharmony_ci/*
59562306a36Sopenharmony_ci * To support refresh mode(video mode), DISP_REG_MUTEX_SOF should
59662306a36Sopenharmony_ci * select the EOF source and configure the EOF plus timing from the
59762306a36Sopenharmony_ci * module that provides the timing signal.
59862306a36Sopenharmony_ci * So that MUTEX can not only send a STREAM_DONE event to GCE
59962306a36Sopenharmony_ci * but also detect the error at end of frame(EAEOF) when EOF signal
60062306a36Sopenharmony_ci * arrives.
60162306a36Sopenharmony_ci */
60262306a36Sopenharmony_cistatic const unsigned int mt8188_mutex_sof[DDP_MUTEX_SOF_MAX] = {
60362306a36Sopenharmony_ci	[MUTEX_SOF_SINGLE_MODE] = MUTEX_SOF_SINGLE_MODE,
60462306a36Sopenharmony_ci	[MUTEX_SOF_DSI0] =
60562306a36Sopenharmony_ci		MT8188_MUTEX_SOF_DSI0 | MT8188_MUTEX_EOF_DSI0,
60662306a36Sopenharmony_ci	[MUTEX_SOF_DP_INTF0] =
60762306a36Sopenharmony_ci		MT8188_MUTEX_SOF_DP_INTF0 | MT8188_MUTEX_EOF_DP_INTF0,
60862306a36Sopenharmony_ci};
60962306a36Sopenharmony_ci
61062306a36Sopenharmony_cistatic const unsigned int mt8195_mutex_sof[DDP_MUTEX_SOF_MAX] = {
61162306a36Sopenharmony_ci	[MUTEX_SOF_SINGLE_MODE] = MUTEX_SOF_SINGLE_MODE,
61262306a36Sopenharmony_ci	[MUTEX_SOF_DSI0] = MT8195_MUTEX_SOF_DSI0 | MT8195_MUTEX_EOF_DSI0,
61362306a36Sopenharmony_ci	[MUTEX_SOF_DSI1] = MT8195_MUTEX_SOF_DSI1 | MT8195_MUTEX_EOF_DSI1,
61462306a36Sopenharmony_ci	[MUTEX_SOF_DPI0] = MT8195_MUTEX_SOF_DPI0 | MT8195_MUTEX_EOF_DPI0,
61562306a36Sopenharmony_ci	[MUTEX_SOF_DPI1] = MT8195_MUTEX_SOF_DPI1 | MT8195_MUTEX_EOF_DPI1,
61662306a36Sopenharmony_ci	[MUTEX_SOF_DP_INTF0] =
61762306a36Sopenharmony_ci		MT8195_MUTEX_SOF_DP_INTF0 | MT8195_MUTEX_EOF_DP_INTF0,
61862306a36Sopenharmony_ci	[MUTEX_SOF_DP_INTF1] =
61962306a36Sopenharmony_ci		MT8195_MUTEX_SOF_DP_INTF1 | MT8195_MUTEX_EOF_DP_INTF1,
62062306a36Sopenharmony_ci};
62162306a36Sopenharmony_ci
62262306a36Sopenharmony_cistatic const struct mtk_mutex_data mt2701_mutex_driver_data = {
62362306a36Sopenharmony_ci	.mutex_mod = mt2701_mutex_mod,
62462306a36Sopenharmony_ci	.mutex_sof = mt2712_mutex_sof,
62562306a36Sopenharmony_ci	.mutex_mod_reg = MT2701_MUTEX0_MOD0,
62662306a36Sopenharmony_ci	.mutex_sof_reg = MT2701_MUTEX0_SOF0,
62762306a36Sopenharmony_ci};
62862306a36Sopenharmony_ci
62962306a36Sopenharmony_cistatic const struct mtk_mutex_data mt2712_mutex_driver_data = {
63062306a36Sopenharmony_ci	.mutex_mod = mt2712_mutex_mod,
63162306a36Sopenharmony_ci	.mutex_sof = mt2712_mutex_sof,
63262306a36Sopenharmony_ci	.mutex_mod_reg = MT2701_MUTEX0_MOD0,
63362306a36Sopenharmony_ci	.mutex_sof_reg = MT2701_MUTEX0_SOF0,
63462306a36Sopenharmony_ci};
63562306a36Sopenharmony_ci
63662306a36Sopenharmony_cistatic const struct mtk_mutex_data mt6795_mutex_driver_data = {
63762306a36Sopenharmony_ci	.mutex_mod = mt8173_mutex_mod,
63862306a36Sopenharmony_ci	.mutex_sof = mt6795_mutex_sof,
63962306a36Sopenharmony_ci	.mutex_mod_reg = MT2701_MUTEX0_MOD0,
64062306a36Sopenharmony_ci	.mutex_sof_reg = MT2701_MUTEX0_SOF0,
64162306a36Sopenharmony_ci};
64262306a36Sopenharmony_ci
64362306a36Sopenharmony_cistatic const struct mtk_mutex_data mt8167_mutex_driver_data = {
64462306a36Sopenharmony_ci	.mutex_mod = mt8167_mutex_mod,
64562306a36Sopenharmony_ci	.mutex_sof = mt8167_mutex_sof,
64662306a36Sopenharmony_ci	.mutex_mod_reg = MT2701_MUTEX0_MOD0,
64762306a36Sopenharmony_ci	.mutex_sof_reg = MT2701_MUTEX0_SOF0,
64862306a36Sopenharmony_ci	.no_clk = true,
64962306a36Sopenharmony_ci};
65062306a36Sopenharmony_ci
65162306a36Sopenharmony_cistatic const struct mtk_mutex_data mt8173_mutex_driver_data = {
65262306a36Sopenharmony_ci	.mutex_mod = mt8173_mutex_mod,
65362306a36Sopenharmony_ci	.mutex_sof = mt2712_mutex_sof,
65462306a36Sopenharmony_ci	.mutex_mod_reg = MT2701_MUTEX0_MOD0,
65562306a36Sopenharmony_ci	.mutex_sof_reg = MT2701_MUTEX0_SOF0,
65662306a36Sopenharmony_ci};
65762306a36Sopenharmony_ci
65862306a36Sopenharmony_cistatic const struct mtk_mutex_data mt8183_mutex_driver_data = {
65962306a36Sopenharmony_ci	.mutex_mod = mt8183_mutex_mod,
66062306a36Sopenharmony_ci	.mutex_sof = mt8183_mutex_sof,
66162306a36Sopenharmony_ci	.mutex_mod_reg = MT8183_MUTEX0_MOD0,
66262306a36Sopenharmony_ci	.mutex_sof_reg = MT8183_MUTEX0_SOF0,
66362306a36Sopenharmony_ci	.mutex_table_mod = mt8183_mutex_table_mod,
66462306a36Sopenharmony_ci	.no_clk = true,
66562306a36Sopenharmony_ci};
66662306a36Sopenharmony_ci
66762306a36Sopenharmony_cistatic const struct mtk_mutex_data mt8186_mdp_mutex_driver_data = {
66862306a36Sopenharmony_ci	.mutex_mod_reg = MT8183_MUTEX0_MOD0,
66962306a36Sopenharmony_ci	.mutex_sof_reg = MT8183_MUTEX0_SOF0,
67062306a36Sopenharmony_ci	.mutex_table_mod = mt8186_mdp_mutex_table_mod,
67162306a36Sopenharmony_ci};
67262306a36Sopenharmony_ci
67362306a36Sopenharmony_cistatic const struct mtk_mutex_data mt8186_mutex_driver_data = {
67462306a36Sopenharmony_ci	.mutex_mod = mt8186_mutex_mod,
67562306a36Sopenharmony_ci	.mutex_sof = mt8186_mutex_sof,
67662306a36Sopenharmony_ci	.mutex_mod_reg = MT8183_MUTEX0_MOD0,
67762306a36Sopenharmony_ci	.mutex_sof_reg = MT8183_MUTEX0_SOF0,
67862306a36Sopenharmony_ci};
67962306a36Sopenharmony_ci
68062306a36Sopenharmony_cistatic const struct mtk_mutex_data mt8188_mutex_driver_data = {
68162306a36Sopenharmony_ci	.mutex_mod = mt8188_mutex_mod,
68262306a36Sopenharmony_ci	.mutex_sof = mt8188_mutex_sof,
68362306a36Sopenharmony_ci	.mutex_mod_reg = MT8183_MUTEX0_MOD0,
68462306a36Sopenharmony_ci	.mutex_sof_reg = MT8183_MUTEX0_SOF0,
68562306a36Sopenharmony_ci};
68662306a36Sopenharmony_ci
68762306a36Sopenharmony_cistatic const struct mtk_mutex_data mt8192_mutex_driver_data = {
68862306a36Sopenharmony_ci	.mutex_mod = mt8192_mutex_mod,
68962306a36Sopenharmony_ci	.mutex_sof = mt8183_mutex_sof,
69062306a36Sopenharmony_ci	.mutex_mod_reg = MT8183_MUTEX0_MOD0,
69162306a36Sopenharmony_ci	.mutex_sof_reg = MT8183_MUTEX0_SOF0,
69262306a36Sopenharmony_ci};
69362306a36Sopenharmony_ci
69462306a36Sopenharmony_cistatic const struct mtk_mutex_data mt8195_mutex_driver_data = {
69562306a36Sopenharmony_ci	.mutex_mod = mt8195_mutex_mod,
69662306a36Sopenharmony_ci	.mutex_sof = mt8195_mutex_sof,
69762306a36Sopenharmony_ci	.mutex_mod_reg = MT8183_MUTEX0_MOD0,
69862306a36Sopenharmony_ci	.mutex_sof_reg = MT8183_MUTEX0_SOF0,
69962306a36Sopenharmony_ci};
70062306a36Sopenharmony_ci
70162306a36Sopenharmony_cistatic const struct mtk_mutex_data mt8195_vpp_mutex_driver_data = {
70262306a36Sopenharmony_ci	.mutex_sof = mt8195_mutex_sof,
70362306a36Sopenharmony_ci	.mutex_mod_reg = MT8183_MUTEX0_MOD0,
70462306a36Sopenharmony_ci	.mutex_sof_reg = MT8183_MUTEX0_SOF0,
70562306a36Sopenharmony_ci	.mutex_table_mod = mt8195_mutex_table_mod,
70662306a36Sopenharmony_ci};
70762306a36Sopenharmony_ci
70862306a36Sopenharmony_cistatic const struct mtk_mutex_data mt8365_mutex_driver_data = {
70962306a36Sopenharmony_ci	.mutex_mod = mt8365_mutex_mod,
71062306a36Sopenharmony_ci	.mutex_sof = mt8183_mutex_sof,
71162306a36Sopenharmony_ci	.mutex_mod_reg = MT8183_MUTEX0_MOD0,
71262306a36Sopenharmony_ci	.mutex_sof_reg = MT8183_MUTEX0_SOF0,
71362306a36Sopenharmony_ci	.no_clk = true,
71462306a36Sopenharmony_ci};
71562306a36Sopenharmony_ci
71662306a36Sopenharmony_cistruct mtk_mutex *mtk_mutex_get(struct device *dev)
71762306a36Sopenharmony_ci{
71862306a36Sopenharmony_ci	struct mtk_mutex_ctx *mtx = dev_get_drvdata(dev);
71962306a36Sopenharmony_ci	int i;
72062306a36Sopenharmony_ci
72162306a36Sopenharmony_ci	for (i = 0; i < MTK_MUTEX_MAX_HANDLES; i++)
72262306a36Sopenharmony_ci		if (!mtx->mutex[i].claimed) {
72362306a36Sopenharmony_ci			mtx->mutex[i].claimed = true;
72462306a36Sopenharmony_ci			return &mtx->mutex[i];
72562306a36Sopenharmony_ci		}
72662306a36Sopenharmony_ci
72762306a36Sopenharmony_ci	return ERR_PTR(-EBUSY);
72862306a36Sopenharmony_ci}
72962306a36Sopenharmony_ciEXPORT_SYMBOL_GPL(mtk_mutex_get);
73062306a36Sopenharmony_ci
73162306a36Sopenharmony_civoid mtk_mutex_put(struct mtk_mutex *mutex)
73262306a36Sopenharmony_ci{
73362306a36Sopenharmony_ci	struct mtk_mutex_ctx *mtx = container_of(mutex, struct mtk_mutex_ctx,
73462306a36Sopenharmony_ci						 mutex[mutex->id]);
73562306a36Sopenharmony_ci
73662306a36Sopenharmony_ci	WARN_ON(&mtx->mutex[mutex->id] != mutex);
73762306a36Sopenharmony_ci
73862306a36Sopenharmony_ci	mutex->claimed = false;
73962306a36Sopenharmony_ci}
74062306a36Sopenharmony_ciEXPORT_SYMBOL_GPL(mtk_mutex_put);
74162306a36Sopenharmony_ci
74262306a36Sopenharmony_ciint mtk_mutex_prepare(struct mtk_mutex *mutex)
74362306a36Sopenharmony_ci{
74462306a36Sopenharmony_ci	struct mtk_mutex_ctx *mtx = container_of(mutex, struct mtk_mutex_ctx,
74562306a36Sopenharmony_ci						 mutex[mutex->id]);
74662306a36Sopenharmony_ci	return clk_prepare_enable(mtx->clk);
74762306a36Sopenharmony_ci}
74862306a36Sopenharmony_ciEXPORT_SYMBOL_GPL(mtk_mutex_prepare);
74962306a36Sopenharmony_ci
75062306a36Sopenharmony_civoid mtk_mutex_unprepare(struct mtk_mutex *mutex)
75162306a36Sopenharmony_ci{
75262306a36Sopenharmony_ci	struct mtk_mutex_ctx *mtx = container_of(mutex, struct mtk_mutex_ctx,
75362306a36Sopenharmony_ci						 mutex[mutex->id]);
75462306a36Sopenharmony_ci	clk_disable_unprepare(mtx->clk);
75562306a36Sopenharmony_ci}
75662306a36Sopenharmony_ciEXPORT_SYMBOL_GPL(mtk_mutex_unprepare);
75762306a36Sopenharmony_ci
75862306a36Sopenharmony_civoid mtk_mutex_add_comp(struct mtk_mutex *mutex,
75962306a36Sopenharmony_ci			enum mtk_ddp_comp_id id)
76062306a36Sopenharmony_ci{
76162306a36Sopenharmony_ci	struct mtk_mutex_ctx *mtx = container_of(mutex, struct mtk_mutex_ctx,
76262306a36Sopenharmony_ci						 mutex[mutex->id]);
76362306a36Sopenharmony_ci	unsigned int reg;
76462306a36Sopenharmony_ci	unsigned int sof_id;
76562306a36Sopenharmony_ci	unsigned int offset;
76662306a36Sopenharmony_ci
76762306a36Sopenharmony_ci	WARN_ON(&mtx->mutex[mutex->id] != mutex);
76862306a36Sopenharmony_ci
76962306a36Sopenharmony_ci	switch (id) {
77062306a36Sopenharmony_ci	case DDP_COMPONENT_DSI0:
77162306a36Sopenharmony_ci		sof_id = MUTEX_SOF_DSI0;
77262306a36Sopenharmony_ci		break;
77362306a36Sopenharmony_ci	case DDP_COMPONENT_DSI1:
77462306a36Sopenharmony_ci		sof_id = MUTEX_SOF_DSI0;
77562306a36Sopenharmony_ci		break;
77662306a36Sopenharmony_ci	case DDP_COMPONENT_DSI2:
77762306a36Sopenharmony_ci		sof_id = MUTEX_SOF_DSI2;
77862306a36Sopenharmony_ci		break;
77962306a36Sopenharmony_ci	case DDP_COMPONENT_DSI3:
78062306a36Sopenharmony_ci		sof_id = MUTEX_SOF_DSI3;
78162306a36Sopenharmony_ci		break;
78262306a36Sopenharmony_ci	case DDP_COMPONENT_DPI0:
78362306a36Sopenharmony_ci		sof_id = MUTEX_SOF_DPI0;
78462306a36Sopenharmony_ci		break;
78562306a36Sopenharmony_ci	case DDP_COMPONENT_DPI1:
78662306a36Sopenharmony_ci		sof_id = MUTEX_SOF_DPI1;
78762306a36Sopenharmony_ci		break;
78862306a36Sopenharmony_ci	case DDP_COMPONENT_DP_INTF0:
78962306a36Sopenharmony_ci		sof_id = MUTEX_SOF_DP_INTF0;
79062306a36Sopenharmony_ci		break;
79162306a36Sopenharmony_ci	case DDP_COMPONENT_DP_INTF1:
79262306a36Sopenharmony_ci		sof_id = MUTEX_SOF_DP_INTF1;
79362306a36Sopenharmony_ci		break;
79462306a36Sopenharmony_ci	default:
79562306a36Sopenharmony_ci		if (mtx->data->mutex_mod[id] < 32) {
79662306a36Sopenharmony_ci			offset = DISP_REG_MUTEX_MOD(mtx->data->mutex_mod_reg,
79762306a36Sopenharmony_ci						    mutex->id);
79862306a36Sopenharmony_ci			reg = readl_relaxed(mtx->regs + offset);
79962306a36Sopenharmony_ci			reg |= 1 << mtx->data->mutex_mod[id];
80062306a36Sopenharmony_ci			writel_relaxed(reg, mtx->regs + offset);
80162306a36Sopenharmony_ci		} else {
80262306a36Sopenharmony_ci			offset = DISP_REG_MUTEX_MOD2(mutex->id);
80362306a36Sopenharmony_ci			reg = readl_relaxed(mtx->regs + offset);
80462306a36Sopenharmony_ci			reg |= 1 << (mtx->data->mutex_mod[id] - 32);
80562306a36Sopenharmony_ci			writel_relaxed(reg, mtx->regs + offset);
80662306a36Sopenharmony_ci		}
80762306a36Sopenharmony_ci		return;
80862306a36Sopenharmony_ci	}
80962306a36Sopenharmony_ci
81062306a36Sopenharmony_ci	writel_relaxed(mtx->data->mutex_sof[sof_id],
81162306a36Sopenharmony_ci		       mtx->regs +
81262306a36Sopenharmony_ci		       DISP_REG_MUTEX_SOF(mtx->data->mutex_sof_reg, mutex->id));
81362306a36Sopenharmony_ci}
81462306a36Sopenharmony_ciEXPORT_SYMBOL_GPL(mtk_mutex_add_comp);
81562306a36Sopenharmony_ci
81662306a36Sopenharmony_civoid mtk_mutex_remove_comp(struct mtk_mutex *mutex,
81762306a36Sopenharmony_ci			   enum mtk_ddp_comp_id id)
81862306a36Sopenharmony_ci{
81962306a36Sopenharmony_ci	struct mtk_mutex_ctx *mtx = container_of(mutex, struct mtk_mutex_ctx,
82062306a36Sopenharmony_ci						 mutex[mutex->id]);
82162306a36Sopenharmony_ci	unsigned int reg;
82262306a36Sopenharmony_ci	unsigned int offset;
82362306a36Sopenharmony_ci
82462306a36Sopenharmony_ci	WARN_ON(&mtx->mutex[mutex->id] != mutex);
82562306a36Sopenharmony_ci
82662306a36Sopenharmony_ci	switch (id) {
82762306a36Sopenharmony_ci	case DDP_COMPONENT_DSI0:
82862306a36Sopenharmony_ci	case DDP_COMPONENT_DSI1:
82962306a36Sopenharmony_ci	case DDP_COMPONENT_DSI2:
83062306a36Sopenharmony_ci	case DDP_COMPONENT_DSI3:
83162306a36Sopenharmony_ci	case DDP_COMPONENT_DPI0:
83262306a36Sopenharmony_ci	case DDP_COMPONENT_DPI1:
83362306a36Sopenharmony_ci	case DDP_COMPONENT_DP_INTF0:
83462306a36Sopenharmony_ci	case DDP_COMPONENT_DP_INTF1:
83562306a36Sopenharmony_ci		writel_relaxed(MUTEX_SOF_SINGLE_MODE,
83662306a36Sopenharmony_ci			       mtx->regs +
83762306a36Sopenharmony_ci			       DISP_REG_MUTEX_SOF(mtx->data->mutex_sof_reg,
83862306a36Sopenharmony_ci						  mutex->id));
83962306a36Sopenharmony_ci		break;
84062306a36Sopenharmony_ci	default:
84162306a36Sopenharmony_ci		if (mtx->data->mutex_mod[id] < 32) {
84262306a36Sopenharmony_ci			offset = DISP_REG_MUTEX_MOD(mtx->data->mutex_mod_reg,
84362306a36Sopenharmony_ci						    mutex->id);
84462306a36Sopenharmony_ci			reg = readl_relaxed(mtx->regs + offset);
84562306a36Sopenharmony_ci			reg &= ~(1 << mtx->data->mutex_mod[id]);
84662306a36Sopenharmony_ci			writel_relaxed(reg, mtx->regs + offset);
84762306a36Sopenharmony_ci		} else {
84862306a36Sopenharmony_ci			offset = DISP_REG_MUTEX_MOD2(mutex->id);
84962306a36Sopenharmony_ci			reg = readl_relaxed(mtx->regs + offset);
85062306a36Sopenharmony_ci			reg &= ~(1 << (mtx->data->mutex_mod[id] - 32));
85162306a36Sopenharmony_ci			writel_relaxed(reg, mtx->regs + offset);
85262306a36Sopenharmony_ci		}
85362306a36Sopenharmony_ci		break;
85462306a36Sopenharmony_ci	}
85562306a36Sopenharmony_ci}
85662306a36Sopenharmony_ciEXPORT_SYMBOL_GPL(mtk_mutex_remove_comp);
85762306a36Sopenharmony_ci
85862306a36Sopenharmony_civoid mtk_mutex_enable(struct mtk_mutex *mutex)
85962306a36Sopenharmony_ci{
86062306a36Sopenharmony_ci	struct mtk_mutex_ctx *mtx = container_of(mutex, struct mtk_mutex_ctx,
86162306a36Sopenharmony_ci						 mutex[mutex->id]);
86262306a36Sopenharmony_ci
86362306a36Sopenharmony_ci	WARN_ON(&mtx->mutex[mutex->id] != mutex);
86462306a36Sopenharmony_ci
86562306a36Sopenharmony_ci	writel(1, mtx->regs + DISP_REG_MUTEX_EN(mutex->id));
86662306a36Sopenharmony_ci}
86762306a36Sopenharmony_ciEXPORT_SYMBOL_GPL(mtk_mutex_enable);
86862306a36Sopenharmony_ci
86962306a36Sopenharmony_ciint mtk_mutex_enable_by_cmdq(struct mtk_mutex *mutex, void *pkt)
87062306a36Sopenharmony_ci{
87162306a36Sopenharmony_ci	struct mtk_mutex_ctx *mtx = container_of(mutex, struct mtk_mutex_ctx,
87262306a36Sopenharmony_ci						 mutex[mutex->id]);
87362306a36Sopenharmony_ci	struct cmdq_pkt *cmdq_pkt = (struct cmdq_pkt *)pkt;
87462306a36Sopenharmony_ci
87562306a36Sopenharmony_ci	WARN_ON(&mtx->mutex[mutex->id] != mutex);
87662306a36Sopenharmony_ci
87762306a36Sopenharmony_ci	if (!mtx->cmdq_reg.size) {
87862306a36Sopenharmony_ci		dev_err(mtx->dev, "mediatek,gce-client-reg hasn't been set");
87962306a36Sopenharmony_ci		return -ENODEV;
88062306a36Sopenharmony_ci	}
88162306a36Sopenharmony_ci
88262306a36Sopenharmony_ci	cmdq_pkt_write(cmdq_pkt, mtx->cmdq_reg.subsys,
88362306a36Sopenharmony_ci		       mtx->addr + DISP_REG_MUTEX_EN(mutex->id), 1);
88462306a36Sopenharmony_ci	return 0;
88562306a36Sopenharmony_ci}
88662306a36Sopenharmony_ciEXPORT_SYMBOL_GPL(mtk_mutex_enable_by_cmdq);
88762306a36Sopenharmony_ci
88862306a36Sopenharmony_civoid mtk_mutex_disable(struct mtk_mutex *mutex)
88962306a36Sopenharmony_ci{
89062306a36Sopenharmony_ci	struct mtk_mutex_ctx *mtx = container_of(mutex, struct mtk_mutex_ctx,
89162306a36Sopenharmony_ci						 mutex[mutex->id]);
89262306a36Sopenharmony_ci
89362306a36Sopenharmony_ci	WARN_ON(&mtx->mutex[mutex->id] != mutex);
89462306a36Sopenharmony_ci
89562306a36Sopenharmony_ci	writel(0, mtx->regs + DISP_REG_MUTEX_EN(mutex->id));
89662306a36Sopenharmony_ci}
89762306a36Sopenharmony_ciEXPORT_SYMBOL_GPL(mtk_mutex_disable);
89862306a36Sopenharmony_ci
89962306a36Sopenharmony_civoid mtk_mutex_acquire(struct mtk_mutex *mutex)
90062306a36Sopenharmony_ci{
90162306a36Sopenharmony_ci	struct mtk_mutex_ctx *mtx = container_of(mutex, struct mtk_mutex_ctx,
90262306a36Sopenharmony_ci						 mutex[mutex->id]);
90362306a36Sopenharmony_ci	u32 tmp;
90462306a36Sopenharmony_ci
90562306a36Sopenharmony_ci	writel(1, mtx->regs + DISP_REG_MUTEX_EN(mutex->id));
90662306a36Sopenharmony_ci	writel(1, mtx->regs + DISP_REG_MUTEX(mutex->id));
90762306a36Sopenharmony_ci	if (readl_poll_timeout_atomic(mtx->regs + DISP_REG_MUTEX(mutex->id),
90862306a36Sopenharmony_ci				      tmp, tmp & INT_MUTEX, 1, 10000))
90962306a36Sopenharmony_ci		pr_err("could not acquire mutex %d\n", mutex->id);
91062306a36Sopenharmony_ci}
91162306a36Sopenharmony_ciEXPORT_SYMBOL_GPL(mtk_mutex_acquire);
91262306a36Sopenharmony_ci
91362306a36Sopenharmony_civoid mtk_mutex_release(struct mtk_mutex *mutex)
91462306a36Sopenharmony_ci{
91562306a36Sopenharmony_ci	struct mtk_mutex_ctx *mtx = container_of(mutex, struct mtk_mutex_ctx,
91662306a36Sopenharmony_ci						 mutex[mutex->id]);
91762306a36Sopenharmony_ci
91862306a36Sopenharmony_ci	writel(0, mtx->regs + DISP_REG_MUTEX(mutex->id));
91962306a36Sopenharmony_ci}
92062306a36Sopenharmony_ciEXPORT_SYMBOL_GPL(mtk_mutex_release);
92162306a36Sopenharmony_ci
92262306a36Sopenharmony_ciint mtk_mutex_write_mod(struct mtk_mutex *mutex,
92362306a36Sopenharmony_ci			enum mtk_mutex_mod_index idx, bool clear)
92462306a36Sopenharmony_ci{
92562306a36Sopenharmony_ci	struct mtk_mutex_ctx *mtx = container_of(mutex, struct mtk_mutex_ctx,
92662306a36Sopenharmony_ci						 mutex[mutex->id]);
92762306a36Sopenharmony_ci	unsigned int reg;
92862306a36Sopenharmony_ci	u32 reg_offset, id_offset = 0;
92962306a36Sopenharmony_ci
93062306a36Sopenharmony_ci	WARN_ON(&mtx->mutex[mutex->id] != mutex);
93162306a36Sopenharmony_ci
93262306a36Sopenharmony_ci	if (idx < MUTEX_MOD_IDX_MDP_RDMA0 ||
93362306a36Sopenharmony_ci	    idx >= MUTEX_MOD_IDX_MAX) {
93462306a36Sopenharmony_ci		dev_err(mtx->dev, "Not supported MOD table index : %d", idx);
93562306a36Sopenharmony_ci		return -EINVAL;
93662306a36Sopenharmony_ci	}
93762306a36Sopenharmony_ci
93862306a36Sopenharmony_ci	/*
93962306a36Sopenharmony_ci	 * Some SoCs may have multiple MUTEX_MOD registers as more than 32 mods
94062306a36Sopenharmony_ci	 * are present, hence requiring multiple 32-bits registers.
94162306a36Sopenharmony_ci	 *
94262306a36Sopenharmony_ci	 * The mutex_table_mod fully represents that by defining the number of
94362306a36Sopenharmony_ci	 * the mod sequentially, later used as a bit number, which can be more
94462306a36Sopenharmony_ci	 * than 0..31.
94562306a36Sopenharmony_ci	 *
94662306a36Sopenharmony_ci	 * In order to retain compatibility with older SoCs, we perform R/W on
94762306a36Sopenharmony_ci	 * the single 32 bits registers, but this requires us to translate the
94862306a36Sopenharmony_ci	 * mutex ID bit accordingly.
94962306a36Sopenharmony_ci	 */
95062306a36Sopenharmony_ci	if (mtx->data->mutex_table_mod[idx] < 32) {
95162306a36Sopenharmony_ci		reg_offset = DISP_REG_MUTEX_MOD(mtx->data->mutex_mod_reg,
95262306a36Sopenharmony_ci						mutex->id);
95362306a36Sopenharmony_ci	} else {
95462306a36Sopenharmony_ci		reg_offset = DISP_REG_MUTEX_MOD1(mtx->data->mutex_mod_reg,
95562306a36Sopenharmony_ci						 mutex->id);
95662306a36Sopenharmony_ci		id_offset = 32;
95762306a36Sopenharmony_ci	}
95862306a36Sopenharmony_ci
95962306a36Sopenharmony_ci	reg = readl_relaxed(mtx->regs + reg_offset);
96062306a36Sopenharmony_ci	if (clear)
96162306a36Sopenharmony_ci		reg &= ~BIT(mtx->data->mutex_table_mod[idx] - id_offset);
96262306a36Sopenharmony_ci	else
96362306a36Sopenharmony_ci		reg |= BIT(mtx->data->mutex_table_mod[idx] - id_offset);
96462306a36Sopenharmony_ci
96562306a36Sopenharmony_ci	writel_relaxed(reg, mtx->regs + reg_offset);
96662306a36Sopenharmony_ci
96762306a36Sopenharmony_ci	return 0;
96862306a36Sopenharmony_ci}
96962306a36Sopenharmony_ciEXPORT_SYMBOL_GPL(mtk_mutex_write_mod);
97062306a36Sopenharmony_ci
97162306a36Sopenharmony_ciint mtk_mutex_write_sof(struct mtk_mutex *mutex,
97262306a36Sopenharmony_ci			enum mtk_mutex_sof_index idx)
97362306a36Sopenharmony_ci{
97462306a36Sopenharmony_ci	struct mtk_mutex_ctx *mtx = container_of(mutex, struct mtk_mutex_ctx,
97562306a36Sopenharmony_ci						 mutex[mutex->id]);
97662306a36Sopenharmony_ci
97762306a36Sopenharmony_ci	WARN_ON(&mtx->mutex[mutex->id] != mutex);
97862306a36Sopenharmony_ci
97962306a36Sopenharmony_ci	if (idx < MUTEX_SOF_IDX_SINGLE_MODE ||
98062306a36Sopenharmony_ci	    idx >= MUTEX_SOF_IDX_MAX) {
98162306a36Sopenharmony_ci		dev_err(mtx->dev, "Not supported SOF index : %d", idx);
98262306a36Sopenharmony_ci		return -EINVAL;
98362306a36Sopenharmony_ci	}
98462306a36Sopenharmony_ci
98562306a36Sopenharmony_ci	writel_relaxed(idx, mtx->regs +
98662306a36Sopenharmony_ci		       DISP_REG_MUTEX_SOF(mtx->data->mutex_sof_reg, mutex->id));
98762306a36Sopenharmony_ci
98862306a36Sopenharmony_ci	return 0;
98962306a36Sopenharmony_ci}
99062306a36Sopenharmony_ciEXPORT_SYMBOL_GPL(mtk_mutex_write_sof);
99162306a36Sopenharmony_ci
99262306a36Sopenharmony_cistatic int mtk_mutex_probe(struct platform_device *pdev)
99362306a36Sopenharmony_ci{
99462306a36Sopenharmony_ci	struct device *dev = &pdev->dev;
99562306a36Sopenharmony_ci	struct mtk_mutex_ctx *mtx;
99662306a36Sopenharmony_ci	struct resource *regs;
99762306a36Sopenharmony_ci	int i, ret;
99862306a36Sopenharmony_ci
99962306a36Sopenharmony_ci	mtx = devm_kzalloc(dev, sizeof(*mtx), GFP_KERNEL);
100062306a36Sopenharmony_ci	if (!mtx)
100162306a36Sopenharmony_ci		return -ENOMEM;
100262306a36Sopenharmony_ci
100362306a36Sopenharmony_ci	for (i = 0; i < MTK_MUTEX_MAX_HANDLES; i++)
100462306a36Sopenharmony_ci		mtx->mutex[i].id = i;
100562306a36Sopenharmony_ci
100662306a36Sopenharmony_ci	mtx->data = of_device_get_match_data(dev);
100762306a36Sopenharmony_ci
100862306a36Sopenharmony_ci	if (!mtx->data->no_clk) {
100962306a36Sopenharmony_ci		mtx->clk = devm_clk_get(dev, NULL);
101062306a36Sopenharmony_ci		if (IS_ERR(mtx->clk))
101162306a36Sopenharmony_ci			return dev_err_probe(dev, PTR_ERR(mtx->clk), "Failed to get clock\n");
101262306a36Sopenharmony_ci	}
101362306a36Sopenharmony_ci
101462306a36Sopenharmony_ci	mtx->regs = devm_platform_get_and_ioremap_resource(pdev, 0, &regs);
101562306a36Sopenharmony_ci	if (IS_ERR(mtx->regs)) {
101662306a36Sopenharmony_ci		dev_err(dev, "Failed to map mutex registers\n");
101762306a36Sopenharmony_ci		return PTR_ERR(mtx->regs);
101862306a36Sopenharmony_ci	}
101962306a36Sopenharmony_ci	mtx->addr = regs->start;
102062306a36Sopenharmony_ci
102162306a36Sopenharmony_ci	/* CMDQ is optional */
102262306a36Sopenharmony_ci	ret = cmdq_dev_get_client_reg(dev, &mtx->cmdq_reg, 0);
102362306a36Sopenharmony_ci	if (ret)
102462306a36Sopenharmony_ci		dev_dbg(dev, "No mediatek,gce-client-reg!\n");
102562306a36Sopenharmony_ci
102662306a36Sopenharmony_ci	platform_set_drvdata(pdev, mtx);
102762306a36Sopenharmony_ci
102862306a36Sopenharmony_ci	return 0;
102962306a36Sopenharmony_ci}
103062306a36Sopenharmony_ci
103162306a36Sopenharmony_cistatic const struct of_device_id mutex_driver_dt_match[] = {
103262306a36Sopenharmony_ci	{ .compatible = "mediatek,mt2701-disp-mutex", .data = &mt2701_mutex_driver_data },
103362306a36Sopenharmony_ci	{ .compatible = "mediatek,mt2712-disp-mutex", .data = &mt2712_mutex_driver_data },
103462306a36Sopenharmony_ci	{ .compatible = "mediatek,mt6795-disp-mutex", .data = &mt6795_mutex_driver_data },
103562306a36Sopenharmony_ci	{ .compatible = "mediatek,mt8167-disp-mutex", .data = &mt8167_mutex_driver_data },
103662306a36Sopenharmony_ci	{ .compatible = "mediatek,mt8173-disp-mutex", .data = &mt8173_mutex_driver_data },
103762306a36Sopenharmony_ci	{ .compatible = "mediatek,mt8183-disp-mutex", .data = &mt8183_mutex_driver_data },
103862306a36Sopenharmony_ci	{ .compatible = "mediatek,mt8186-disp-mutex", .data = &mt8186_mutex_driver_data },
103962306a36Sopenharmony_ci	{ .compatible = "mediatek,mt8186-mdp3-mutex", .data = &mt8186_mdp_mutex_driver_data },
104062306a36Sopenharmony_ci	{ .compatible = "mediatek,mt8188-disp-mutex", .data = &mt8188_mutex_driver_data },
104162306a36Sopenharmony_ci	{ .compatible = "mediatek,mt8192-disp-mutex", .data = &mt8192_mutex_driver_data },
104262306a36Sopenharmony_ci	{ .compatible = "mediatek,mt8195-disp-mutex", .data = &mt8195_mutex_driver_data },
104362306a36Sopenharmony_ci	{ .compatible = "mediatek,mt8195-vpp-mutex",  .data = &mt8195_vpp_mutex_driver_data },
104462306a36Sopenharmony_ci	{ .compatible = "mediatek,mt8365-disp-mutex", .data = &mt8365_mutex_driver_data },
104562306a36Sopenharmony_ci	{ /* sentinel */ },
104662306a36Sopenharmony_ci};
104762306a36Sopenharmony_ciMODULE_DEVICE_TABLE(of, mutex_driver_dt_match);
104862306a36Sopenharmony_ci
104962306a36Sopenharmony_cistatic struct platform_driver mtk_mutex_driver = {
105062306a36Sopenharmony_ci	.probe		= mtk_mutex_probe,
105162306a36Sopenharmony_ci	.driver		= {
105262306a36Sopenharmony_ci		.name	= "mediatek-mutex",
105362306a36Sopenharmony_ci		.of_match_table = mutex_driver_dt_match,
105462306a36Sopenharmony_ci	},
105562306a36Sopenharmony_ci};
105662306a36Sopenharmony_cimodule_platform_driver(mtk_mutex_driver);
105762306a36Sopenharmony_ci
105862306a36Sopenharmony_ciMODULE_AUTHOR("Yongqiang Niu <yongqiang.niu@mediatek.com>");
105962306a36Sopenharmony_ciMODULE_DESCRIPTION("MediaTek SoC MUTEX driver");
106062306a36Sopenharmony_ciMODULE_LICENSE("GPL");
1061