18c2ecf20Sopenharmony_ci// SPDX-License-Identifier: GPL-2.0-only
28c2ecf20Sopenharmony_ci/*
38c2ecf20Sopenharmony_ci * Copyright (c) 2014 MediaTek Inc.
48c2ecf20Sopenharmony_ci * Author: James Liao <jamesjj.liao@mediatek.com>
58c2ecf20Sopenharmony_ci */
68c2ecf20Sopenharmony_ci
78c2ecf20Sopenharmony_ci#include <linux/device.h>
88c2ecf20Sopenharmony_ci#include <linux/io.h>
98c2ecf20Sopenharmony_ci#include <linux/of_device.h>
108c2ecf20Sopenharmony_ci#include <linux/platform_device.h>
118c2ecf20Sopenharmony_ci#include <linux/soc/mediatek/mtk-mmsys.h>
128c2ecf20Sopenharmony_ci
138c2ecf20Sopenharmony_ci#define DISP_REG_CONFIG_DISP_OVL0_MOUT_EN	0x040
148c2ecf20Sopenharmony_ci#define DISP_REG_CONFIG_DISP_OVL1_MOUT_EN	0x044
158c2ecf20Sopenharmony_ci#define DISP_REG_CONFIG_DISP_OD_MOUT_EN		0x048
168c2ecf20Sopenharmony_ci#define DISP_REG_CONFIG_DISP_GAMMA_MOUT_EN	0x04c
178c2ecf20Sopenharmony_ci#define DISP_REG_CONFIG_DISP_UFOE_MOUT_EN	0x050
188c2ecf20Sopenharmony_ci#define DISP_REG_CONFIG_DISP_COLOR0_SEL_IN	0x084
198c2ecf20Sopenharmony_ci#define DISP_REG_CONFIG_DISP_COLOR1_SEL_IN	0x088
208c2ecf20Sopenharmony_ci#define DISP_REG_CONFIG_DSIE_SEL_IN		0x0a4
218c2ecf20Sopenharmony_ci#define DISP_REG_CONFIG_DSIO_SEL_IN		0x0a8
228c2ecf20Sopenharmony_ci#define DISP_REG_CONFIG_DPI_SEL_IN		0x0ac
238c2ecf20Sopenharmony_ci#define DISP_REG_CONFIG_DISP_RDMA2_SOUT		0x0b8
248c2ecf20Sopenharmony_ci#define DISP_REG_CONFIG_DISP_RDMA0_SOUT_EN	0x0c4
258c2ecf20Sopenharmony_ci#define DISP_REG_CONFIG_DISP_RDMA1_SOUT_EN	0x0c8
268c2ecf20Sopenharmony_ci#define DISP_REG_CONFIG_MMSYS_CG_CON0		0x100
278c2ecf20Sopenharmony_ci
288c2ecf20Sopenharmony_ci#define DISP_REG_CONFIG_DISP_OVL_MOUT_EN	0x030
298c2ecf20Sopenharmony_ci#define DISP_REG_CONFIG_OUT_SEL			0x04c
308c2ecf20Sopenharmony_ci#define DISP_REG_CONFIG_DSI_SEL			0x050
318c2ecf20Sopenharmony_ci#define DISP_REG_CONFIG_DPI_SEL			0x064
328c2ecf20Sopenharmony_ci
338c2ecf20Sopenharmony_ci#define OVL0_MOUT_EN_COLOR0			0x1
348c2ecf20Sopenharmony_ci#define OD_MOUT_EN_RDMA0			0x1
358c2ecf20Sopenharmony_ci#define OD1_MOUT_EN_RDMA1			BIT(16)
368c2ecf20Sopenharmony_ci#define UFOE_MOUT_EN_DSI0			0x1
378c2ecf20Sopenharmony_ci#define COLOR0_SEL_IN_OVL0			0x1
388c2ecf20Sopenharmony_ci#define OVL1_MOUT_EN_COLOR1			0x1
398c2ecf20Sopenharmony_ci#define GAMMA_MOUT_EN_RDMA1			0x1
408c2ecf20Sopenharmony_ci#define RDMA0_SOUT_DPI0				0x2
418c2ecf20Sopenharmony_ci#define RDMA0_SOUT_DPI1				0x3
428c2ecf20Sopenharmony_ci#define RDMA0_SOUT_DSI1				0x1
438c2ecf20Sopenharmony_ci#define RDMA0_SOUT_DSI2				0x4
448c2ecf20Sopenharmony_ci#define RDMA0_SOUT_DSI3				0x5
458c2ecf20Sopenharmony_ci#define RDMA1_SOUT_DPI0				0x2
468c2ecf20Sopenharmony_ci#define RDMA1_SOUT_DPI1				0x3
478c2ecf20Sopenharmony_ci#define RDMA1_SOUT_DSI1				0x1
488c2ecf20Sopenharmony_ci#define RDMA1_SOUT_DSI2				0x4
498c2ecf20Sopenharmony_ci#define RDMA1_SOUT_DSI3				0x5
508c2ecf20Sopenharmony_ci#define RDMA2_SOUT_DPI0				0x2
518c2ecf20Sopenharmony_ci#define RDMA2_SOUT_DPI1				0x3
528c2ecf20Sopenharmony_ci#define RDMA2_SOUT_DSI1				0x1
538c2ecf20Sopenharmony_ci#define RDMA2_SOUT_DSI2				0x4
548c2ecf20Sopenharmony_ci#define RDMA2_SOUT_DSI3				0x5
558c2ecf20Sopenharmony_ci#define DPI0_SEL_IN_RDMA1			0x1
568c2ecf20Sopenharmony_ci#define DPI0_SEL_IN_RDMA2			0x3
578c2ecf20Sopenharmony_ci#define DPI1_SEL_IN_RDMA1			(0x1 << 8)
588c2ecf20Sopenharmony_ci#define DPI1_SEL_IN_RDMA2			(0x3 << 8)
598c2ecf20Sopenharmony_ci#define DSI0_SEL_IN_RDMA1			0x1
608c2ecf20Sopenharmony_ci#define DSI0_SEL_IN_RDMA2			0x4
618c2ecf20Sopenharmony_ci#define DSI1_SEL_IN_RDMA1			0x1
628c2ecf20Sopenharmony_ci#define DSI1_SEL_IN_RDMA2			0x4
638c2ecf20Sopenharmony_ci#define DSI2_SEL_IN_RDMA1			(0x1 << 16)
648c2ecf20Sopenharmony_ci#define DSI2_SEL_IN_RDMA2			(0x4 << 16)
658c2ecf20Sopenharmony_ci#define DSI3_SEL_IN_RDMA1			(0x1 << 16)
668c2ecf20Sopenharmony_ci#define DSI3_SEL_IN_RDMA2			(0x4 << 16)
678c2ecf20Sopenharmony_ci#define COLOR1_SEL_IN_OVL1			0x1
688c2ecf20Sopenharmony_ci
698c2ecf20Sopenharmony_ci#define OVL_MOUT_EN_RDMA			0x1
708c2ecf20Sopenharmony_ci#define BLS_TO_DSI_RDMA1_TO_DPI1		0x8
718c2ecf20Sopenharmony_ci#define BLS_TO_DPI_RDMA1_TO_DSI			0x2
728c2ecf20Sopenharmony_ci#define DSI_SEL_IN_BLS				0x0
738c2ecf20Sopenharmony_ci#define DPI_SEL_IN_BLS				0x0
748c2ecf20Sopenharmony_ci#define DSI_SEL_IN_RDMA				0x1
758c2ecf20Sopenharmony_ci
768c2ecf20Sopenharmony_cistruct mtk_mmsys_driver_data {
778c2ecf20Sopenharmony_ci	const char *clk_driver;
788c2ecf20Sopenharmony_ci};
798c2ecf20Sopenharmony_ci
808c2ecf20Sopenharmony_cistatic const struct mtk_mmsys_driver_data mt2701_mmsys_driver_data = {
818c2ecf20Sopenharmony_ci	.clk_driver = "clk-mt2701-mm",
828c2ecf20Sopenharmony_ci};
838c2ecf20Sopenharmony_ci
848c2ecf20Sopenharmony_cistatic const struct mtk_mmsys_driver_data mt2712_mmsys_driver_data = {
858c2ecf20Sopenharmony_ci	.clk_driver = "clk-mt2712-mm",
868c2ecf20Sopenharmony_ci};
878c2ecf20Sopenharmony_ci
888c2ecf20Sopenharmony_cistatic const struct mtk_mmsys_driver_data mt6779_mmsys_driver_data = {
898c2ecf20Sopenharmony_ci	.clk_driver = "clk-mt6779-mm",
908c2ecf20Sopenharmony_ci};
918c2ecf20Sopenharmony_ci
928c2ecf20Sopenharmony_cistatic const struct mtk_mmsys_driver_data mt6797_mmsys_driver_data = {
938c2ecf20Sopenharmony_ci	.clk_driver = "clk-mt6797-mm",
948c2ecf20Sopenharmony_ci};
958c2ecf20Sopenharmony_ci
968c2ecf20Sopenharmony_cistatic const struct mtk_mmsys_driver_data mt8173_mmsys_driver_data = {
978c2ecf20Sopenharmony_ci	.clk_driver = "clk-mt8173-mm",
988c2ecf20Sopenharmony_ci};
998c2ecf20Sopenharmony_ci
1008c2ecf20Sopenharmony_cistatic const struct mtk_mmsys_driver_data mt8183_mmsys_driver_data = {
1018c2ecf20Sopenharmony_ci	.clk_driver = "clk-mt8183-mm",
1028c2ecf20Sopenharmony_ci};
1038c2ecf20Sopenharmony_ci
1048c2ecf20Sopenharmony_cistatic unsigned int mtk_mmsys_ddp_mout_en(enum mtk_ddp_comp_id cur,
1058c2ecf20Sopenharmony_ci					  enum mtk_ddp_comp_id next,
1068c2ecf20Sopenharmony_ci					  unsigned int *addr)
1078c2ecf20Sopenharmony_ci{
1088c2ecf20Sopenharmony_ci	unsigned int value;
1098c2ecf20Sopenharmony_ci
1108c2ecf20Sopenharmony_ci	if (cur == DDP_COMPONENT_OVL0 && next == DDP_COMPONENT_COLOR0) {
1118c2ecf20Sopenharmony_ci		*addr = DISP_REG_CONFIG_DISP_OVL0_MOUT_EN;
1128c2ecf20Sopenharmony_ci		value = OVL0_MOUT_EN_COLOR0;
1138c2ecf20Sopenharmony_ci	} else if (cur == DDP_COMPONENT_OVL0 && next == DDP_COMPONENT_RDMA0) {
1148c2ecf20Sopenharmony_ci		*addr = DISP_REG_CONFIG_DISP_OVL_MOUT_EN;
1158c2ecf20Sopenharmony_ci		value = OVL_MOUT_EN_RDMA;
1168c2ecf20Sopenharmony_ci	} else if (cur == DDP_COMPONENT_OD0 && next == DDP_COMPONENT_RDMA0) {
1178c2ecf20Sopenharmony_ci		*addr = DISP_REG_CONFIG_DISP_OD_MOUT_EN;
1188c2ecf20Sopenharmony_ci		value = OD_MOUT_EN_RDMA0;
1198c2ecf20Sopenharmony_ci	} else if (cur == DDP_COMPONENT_UFOE && next == DDP_COMPONENT_DSI0) {
1208c2ecf20Sopenharmony_ci		*addr = DISP_REG_CONFIG_DISP_UFOE_MOUT_EN;
1218c2ecf20Sopenharmony_ci		value = UFOE_MOUT_EN_DSI0;
1228c2ecf20Sopenharmony_ci	} else if (cur == DDP_COMPONENT_OVL1 && next == DDP_COMPONENT_COLOR1) {
1238c2ecf20Sopenharmony_ci		*addr = DISP_REG_CONFIG_DISP_OVL1_MOUT_EN;
1248c2ecf20Sopenharmony_ci		value = OVL1_MOUT_EN_COLOR1;
1258c2ecf20Sopenharmony_ci	} else if (cur == DDP_COMPONENT_GAMMA && next == DDP_COMPONENT_RDMA1) {
1268c2ecf20Sopenharmony_ci		*addr = DISP_REG_CONFIG_DISP_GAMMA_MOUT_EN;
1278c2ecf20Sopenharmony_ci		value = GAMMA_MOUT_EN_RDMA1;
1288c2ecf20Sopenharmony_ci	} else if (cur == DDP_COMPONENT_OD1 && next == DDP_COMPONENT_RDMA1) {
1298c2ecf20Sopenharmony_ci		*addr = DISP_REG_CONFIG_DISP_OD_MOUT_EN;
1308c2ecf20Sopenharmony_ci		value = OD1_MOUT_EN_RDMA1;
1318c2ecf20Sopenharmony_ci	} else if (cur == DDP_COMPONENT_RDMA0 && next == DDP_COMPONENT_DPI0) {
1328c2ecf20Sopenharmony_ci		*addr = DISP_REG_CONFIG_DISP_RDMA0_SOUT_EN;
1338c2ecf20Sopenharmony_ci		value = RDMA0_SOUT_DPI0;
1348c2ecf20Sopenharmony_ci	} else if (cur == DDP_COMPONENT_RDMA0 && next == DDP_COMPONENT_DPI1) {
1358c2ecf20Sopenharmony_ci		*addr = DISP_REG_CONFIG_DISP_RDMA0_SOUT_EN;
1368c2ecf20Sopenharmony_ci		value = RDMA0_SOUT_DPI1;
1378c2ecf20Sopenharmony_ci	} else if (cur == DDP_COMPONENT_RDMA0 && next == DDP_COMPONENT_DSI1) {
1388c2ecf20Sopenharmony_ci		*addr = DISP_REG_CONFIG_DISP_RDMA0_SOUT_EN;
1398c2ecf20Sopenharmony_ci		value = RDMA0_SOUT_DSI1;
1408c2ecf20Sopenharmony_ci	} else if (cur == DDP_COMPONENT_RDMA0 && next == DDP_COMPONENT_DSI2) {
1418c2ecf20Sopenharmony_ci		*addr = DISP_REG_CONFIG_DISP_RDMA0_SOUT_EN;
1428c2ecf20Sopenharmony_ci		value = RDMA0_SOUT_DSI2;
1438c2ecf20Sopenharmony_ci	} else if (cur == DDP_COMPONENT_RDMA0 && next == DDP_COMPONENT_DSI3) {
1448c2ecf20Sopenharmony_ci		*addr = DISP_REG_CONFIG_DISP_RDMA0_SOUT_EN;
1458c2ecf20Sopenharmony_ci		value = RDMA0_SOUT_DSI3;
1468c2ecf20Sopenharmony_ci	} else if (cur == DDP_COMPONENT_RDMA1 && next == DDP_COMPONENT_DSI1) {
1478c2ecf20Sopenharmony_ci		*addr = DISP_REG_CONFIG_DISP_RDMA1_SOUT_EN;
1488c2ecf20Sopenharmony_ci		value = RDMA1_SOUT_DSI1;
1498c2ecf20Sopenharmony_ci	} else if (cur == DDP_COMPONENT_RDMA1 && next == DDP_COMPONENT_DSI2) {
1508c2ecf20Sopenharmony_ci		*addr = DISP_REG_CONFIG_DISP_RDMA1_SOUT_EN;
1518c2ecf20Sopenharmony_ci		value = RDMA1_SOUT_DSI2;
1528c2ecf20Sopenharmony_ci	} else if (cur == DDP_COMPONENT_RDMA1 && next == DDP_COMPONENT_DSI3) {
1538c2ecf20Sopenharmony_ci		*addr = DISP_REG_CONFIG_DISP_RDMA1_SOUT_EN;
1548c2ecf20Sopenharmony_ci		value = RDMA1_SOUT_DSI3;
1558c2ecf20Sopenharmony_ci	} else if (cur == DDP_COMPONENT_RDMA1 && next == DDP_COMPONENT_DPI0) {
1568c2ecf20Sopenharmony_ci		*addr = DISP_REG_CONFIG_DISP_RDMA1_SOUT_EN;
1578c2ecf20Sopenharmony_ci		value = RDMA1_SOUT_DPI0;
1588c2ecf20Sopenharmony_ci	} else if (cur == DDP_COMPONENT_RDMA1 && next == DDP_COMPONENT_DPI1) {
1598c2ecf20Sopenharmony_ci		*addr = DISP_REG_CONFIG_DISP_RDMA1_SOUT_EN;
1608c2ecf20Sopenharmony_ci		value = RDMA1_SOUT_DPI1;
1618c2ecf20Sopenharmony_ci	} else if (cur == DDP_COMPONENT_RDMA2 && next == DDP_COMPONENT_DPI0) {
1628c2ecf20Sopenharmony_ci		*addr = DISP_REG_CONFIG_DISP_RDMA2_SOUT;
1638c2ecf20Sopenharmony_ci		value = RDMA2_SOUT_DPI0;
1648c2ecf20Sopenharmony_ci	} else if (cur == DDP_COMPONENT_RDMA2 && next == DDP_COMPONENT_DPI1) {
1658c2ecf20Sopenharmony_ci		*addr = DISP_REG_CONFIG_DISP_RDMA2_SOUT;
1668c2ecf20Sopenharmony_ci		value = RDMA2_SOUT_DPI1;
1678c2ecf20Sopenharmony_ci	} else if (cur == DDP_COMPONENT_RDMA2 && next == DDP_COMPONENT_DSI1) {
1688c2ecf20Sopenharmony_ci		*addr = DISP_REG_CONFIG_DISP_RDMA2_SOUT;
1698c2ecf20Sopenharmony_ci		value = RDMA2_SOUT_DSI1;
1708c2ecf20Sopenharmony_ci	} else if (cur == DDP_COMPONENT_RDMA2 && next == DDP_COMPONENT_DSI2) {
1718c2ecf20Sopenharmony_ci		*addr = DISP_REG_CONFIG_DISP_RDMA2_SOUT;
1728c2ecf20Sopenharmony_ci		value = RDMA2_SOUT_DSI2;
1738c2ecf20Sopenharmony_ci	} else if (cur == DDP_COMPONENT_RDMA2 && next == DDP_COMPONENT_DSI3) {
1748c2ecf20Sopenharmony_ci		*addr = DISP_REG_CONFIG_DISP_RDMA2_SOUT;
1758c2ecf20Sopenharmony_ci		value = RDMA2_SOUT_DSI3;
1768c2ecf20Sopenharmony_ci	} else {
1778c2ecf20Sopenharmony_ci		value = 0;
1788c2ecf20Sopenharmony_ci	}
1798c2ecf20Sopenharmony_ci
1808c2ecf20Sopenharmony_ci	return value;
1818c2ecf20Sopenharmony_ci}
1828c2ecf20Sopenharmony_ci
1838c2ecf20Sopenharmony_cistatic unsigned int mtk_mmsys_ddp_sel_in(enum mtk_ddp_comp_id cur,
1848c2ecf20Sopenharmony_ci					 enum mtk_ddp_comp_id next,
1858c2ecf20Sopenharmony_ci					 unsigned int *addr)
1868c2ecf20Sopenharmony_ci{
1878c2ecf20Sopenharmony_ci	unsigned int value;
1888c2ecf20Sopenharmony_ci
1898c2ecf20Sopenharmony_ci	if (cur == DDP_COMPONENT_OVL0 && next == DDP_COMPONENT_COLOR0) {
1908c2ecf20Sopenharmony_ci		*addr = DISP_REG_CONFIG_DISP_COLOR0_SEL_IN;
1918c2ecf20Sopenharmony_ci		value = COLOR0_SEL_IN_OVL0;
1928c2ecf20Sopenharmony_ci	} else if (cur == DDP_COMPONENT_RDMA1 && next == DDP_COMPONENT_DPI0) {
1938c2ecf20Sopenharmony_ci		*addr = DISP_REG_CONFIG_DPI_SEL_IN;
1948c2ecf20Sopenharmony_ci		value = DPI0_SEL_IN_RDMA1;
1958c2ecf20Sopenharmony_ci	} else if (cur == DDP_COMPONENT_RDMA1 && next == DDP_COMPONENT_DPI1) {
1968c2ecf20Sopenharmony_ci		*addr = DISP_REG_CONFIG_DPI_SEL_IN;
1978c2ecf20Sopenharmony_ci		value = DPI1_SEL_IN_RDMA1;
1988c2ecf20Sopenharmony_ci	} else if (cur == DDP_COMPONENT_RDMA1 && next == DDP_COMPONENT_DSI0) {
1998c2ecf20Sopenharmony_ci		*addr = DISP_REG_CONFIG_DSIE_SEL_IN;
2008c2ecf20Sopenharmony_ci		value = DSI0_SEL_IN_RDMA1;
2018c2ecf20Sopenharmony_ci	} else if (cur == DDP_COMPONENT_RDMA1 && next == DDP_COMPONENT_DSI1) {
2028c2ecf20Sopenharmony_ci		*addr = DISP_REG_CONFIG_DSIO_SEL_IN;
2038c2ecf20Sopenharmony_ci		value = DSI1_SEL_IN_RDMA1;
2048c2ecf20Sopenharmony_ci	} else if (cur == DDP_COMPONENT_RDMA1 && next == DDP_COMPONENT_DSI2) {
2058c2ecf20Sopenharmony_ci		*addr = DISP_REG_CONFIG_DSIE_SEL_IN;
2068c2ecf20Sopenharmony_ci		value = DSI2_SEL_IN_RDMA1;
2078c2ecf20Sopenharmony_ci	} else if (cur == DDP_COMPONENT_RDMA1 && next == DDP_COMPONENT_DSI3) {
2088c2ecf20Sopenharmony_ci		*addr = DISP_REG_CONFIG_DSIO_SEL_IN;
2098c2ecf20Sopenharmony_ci		value = DSI3_SEL_IN_RDMA1;
2108c2ecf20Sopenharmony_ci	} else if (cur == DDP_COMPONENT_RDMA2 && next == DDP_COMPONENT_DPI0) {
2118c2ecf20Sopenharmony_ci		*addr = DISP_REG_CONFIG_DPI_SEL_IN;
2128c2ecf20Sopenharmony_ci		value = DPI0_SEL_IN_RDMA2;
2138c2ecf20Sopenharmony_ci	} else if (cur == DDP_COMPONENT_RDMA2 && next == DDP_COMPONENT_DPI1) {
2148c2ecf20Sopenharmony_ci		*addr = DISP_REG_CONFIG_DPI_SEL_IN;
2158c2ecf20Sopenharmony_ci		value = DPI1_SEL_IN_RDMA2;
2168c2ecf20Sopenharmony_ci	} else if (cur == DDP_COMPONENT_RDMA2 && next == DDP_COMPONENT_DSI0) {
2178c2ecf20Sopenharmony_ci		*addr = DISP_REG_CONFIG_DSIE_SEL_IN;
2188c2ecf20Sopenharmony_ci		value = DSI0_SEL_IN_RDMA2;
2198c2ecf20Sopenharmony_ci	} else if (cur == DDP_COMPONENT_RDMA2 && next == DDP_COMPONENT_DSI1) {
2208c2ecf20Sopenharmony_ci		*addr = DISP_REG_CONFIG_DSIO_SEL_IN;
2218c2ecf20Sopenharmony_ci		value = DSI1_SEL_IN_RDMA2;
2228c2ecf20Sopenharmony_ci	} else if (cur == DDP_COMPONENT_RDMA2 && next == DDP_COMPONENT_DSI2) {
2238c2ecf20Sopenharmony_ci		*addr = DISP_REG_CONFIG_DSIE_SEL_IN;
2248c2ecf20Sopenharmony_ci		value = DSI2_SEL_IN_RDMA2;
2258c2ecf20Sopenharmony_ci	} else if (cur == DDP_COMPONENT_RDMA2 && next == DDP_COMPONENT_DSI3) {
2268c2ecf20Sopenharmony_ci		*addr = DISP_REG_CONFIG_DSIE_SEL_IN;
2278c2ecf20Sopenharmony_ci		value = DSI3_SEL_IN_RDMA2;
2288c2ecf20Sopenharmony_ci	} else if (cur == DDP_COMPONENT_OVL1 && next == DDP_COMPONENT_COLOR1) {
2298c2ecf20Sopenharmony_ci		*addr = DISP_REG_CONFIG_DISP_COLOR1_SEL_IN;
2308c2ecf20Sopenharmony_ci		value = COLOR1_SEL_IN_OVL1;
2318c2ecf20Sopenharmony_ci	} else if (cur == DDP_COMPONENT_BLS && next == DDP_COMPONENT_DSI0) {
2328c2ecf20Sopenharmony_ci		*addr = DISP_REG_CONFIG_DSI_SEL;
2338c2ecf20Sopenharmony_ci		value = DSI_SEL_IN_BLS;
2348c2ecf20Sopenharmony_ci	} else {
2358c2ecf20Sopenharmony_ci		value = 0;
2368c2ecf20Sopenharmony_ci	}
2378c2ecf20Sopenharmony_ci
2388c2ecf20Sopenharmony_ci	return value;
2398c2ecf20Sopenharmony_ci}
2408c2ecf20Sopenharmony_ci
2418c2ecf20Sopenharmony_cistatic void mtk_mmsys_ddp_sout_sel(void __iomem *config_regs,
2428c2ecf20Sopenharmony_ci				   enum mtk_ddp_comp_id cur,
2438c2ecf20Sopenharmony_ci				   enum mtk_ddp_comp_id next)
2448c2ecf20Sopenharmony_ci{
2458c2ecf20Sopenharmony_ci	if (cur == DDP_COMPONENT_BLS && next == DDP_COMPONENT_DSI0) {
2468c2ecf20Sopenharmony_ci		writel_relaxed(BLS_TO_DSI_RDMA1_TO_DPI1,
2478c2ecf20Sopenharmony_ci			       config_regs + DISP_REG_CONFIG_OUT_SEL);
2488c2ecf20Sopenharmony_ci	} else if (cur == DDP_COMPONENT_BLS && next == DDP_COMPONENT_DPI0) {
2498c2ecf20Sopenharmony_ci		writel_relaxed(BLS_TO_DPI_RDMA1_TO_DSI,
2508c2ecf20Sopenharmony_ci			       config_regs + DISP_REG_CONFIG_OUT_SEL);
2518c2ecf20Sopenharmony_ci		writel_relaxed(DSI_SEL_IN_RDMA,
2528c2ecf20Sopenharmony_ci			       config_regs + DISP_REG_CONFIG_DSI_SEL);
2538c2ecf20Sopenharmony_ci		writel_relaxed(DPI_SEL_IN_BLS,
2548c2ecf20Sopenharmony_ci			       config_regs + DISP_REG_CONFIG_DPI_SEL);
2558c2ecf20Sopenharmony_ci	}
2568c2ecf20Sopenharmony_ci}
2578c2ecf20Sopenharmony_ci
2588c2ecf20Sopenharmony_civoid mtk_mmsys_ddp_connect(struct device *dev,
2598c2ecf20Sopenharmony_ci			   enum mtk_ddp_comp_id cur,
2608c2ecf20Sopenharmony_ci			   enum mtk_ddp_comp_id next)
2618c2ecf20Sopenharmony_ci{
2628c2ecf20Sopenharmony_ci	void __iomem *config_regs = dev_get_drvdata(dev);
2638c2ecf20Sopenharmony_ci	unsigned int addr, value, reg;
2648c2ecf20Sopenharmony_ci
2658c2ecf20Sopenharmony_ci	value = mtk_mmsys_ddp_mout_en(cur, next, &addr);
2668c2ecf20Sopenharmony_ci	if (value) {
2678c2ecf20Sopenharmony_ci		reg = readl_relaxed(config_regs + addr) | value;
2688c2ecf20Sopenharmony_ci		writel_relaxed(reg, config_regs + addr);
2698c2ecf20Sopenharmony_ci	}
2708c2ecf20Sopenharmony_ci
2718c2ecf20Sopenharmony_ci	mtk_mmsys_ddp_sout_sel(config_regs, cur, next);
2728c2ecf20Sopenharmony_ci
2738c2ecf20Sopenharmony_ci	value = mtk_mmsys_ddp_sel_in(cur, next, &addr);
2748c2ecf20Sopenharmony_ci	if (value) {
2758c2ecf20Sopenharmony_ci		reg = readl_relaxed(config_regs + addr) | value;
2768c2ecf20Sopenharmony_ci		writel_relaxed(reg, config_regs + addr);
2778c2ecf20Sopenharmony_ci	}
2788c2ecf20Sopenharmony_ci}
2798c2ecf20Sopenharmony_ciEXPORT_SYMBOL_GPL(mtk_mmsys_ddp_connect);
2808c2ecf20Sopenharmony_ci
2818c2ecf20Sopenharmony_civoid mtk_mmsys_ddp_disconnect(struct device *dev,
2828c2ecf20Sopenharmony_ci			      enum mtk_ddp_comp_id cur,
2838c2ecf20Sopenharmony_ci			      enum mtk_ddp_comp_id next)
2848c2ecf20Sopenharmony_ci{
2858c2ecf20Sopenharmony_ci	void __iomem *config_regs = dev_get_drvdata(dev);
2868c2ecf20Sopenharmony_ci	unsigned int addr, value, reg;
2878c2ecf20Sopenharmony_ci
2888c2ecf20Sopenharmony_ci	value = mtk_mmsys_ddp_mout_en(cur, next, &addr);
2898c2ecf20Sopenharmony_ci	if (value) {
2908c2ecf20Sopenharmony_ci		reg = readl_relaxed(config_regs + addr) & ~value;
2918c2ecf20Sopenharmony_ci		writel_relaxed(reg, config_regs + addr);
2928c2ecf20Sopenharmony_ci	}
2938c2ecf20Sopenharmony_ci
2948c2ecf20Sopenharmony_ci	value = mtk_mmsys_ddp_sel_in(cur, next, &addr);
2958c2ecf20Sopenharmony_ci	if (value) {
2968c2ecf20Sopenharmony_ci		reg = readl_relaxed(config_regs + addr) & ~value;
2978c2ecf20Sopenharmony_ci		writel_relaxed(reg, config_regs + addr);
2988c2ecf20Sopenharmony_ci	}
2998c2ecf20Sopenharmony_ci}
3008c2ecf20Sopenharmony_ciEXPORT_SYMBOL_GPL(mtk_mmsys_ddp_disconnect);
3018c2ecf20Sopenharmony_ci
3028c2ecf20Sopenharmony_cistatic int mtk_mmsys_probe(struct platform_device *pdev)
3038c2ecf20Sopenharmony_ci{
3048c2ecf20Sopenharmony_ci	const struct mtk_mmsys_driver_data *data;
3058c2ecf20Sopenharmony_ci	struct device *dev = &pdev->dev;
3068c2ecf20Sopenharmony_ci	struct platform_device *clks;
3078c2ecf20Sopenharmony_ci	struct platform_device *drm;
3088c2ecf20Sopenharmony_ci	void __iomem *config_regs;
3098c2ecf20Sopenharmony_ci	struct resource *mem;
3108c2ecf20Sopenharmony_ci	int ret;
3118c2ecf20Sopenharmony_ci
3128c2ecf20Sopenharmony_ci	mem = platform_get_resource(pdev, IORESOURCE_MEM, 0);
3138c2ecf20Sopenharmony_ci	config_regs = devm_ioremap_resource(dev, mem);
3148c2ecf20Sopenharmony_ci	if (IS_ERR(config_regs)) {
3158c2ecf20Sopenharmony_ci		ret = PTR_ERR(config_regs);
3168c2ecf20Sopenharmony_ci		dev_err(dev, "Failed to ioremap mmsys-config resource: %d\n",
3178c2ecf20Sopenharmony_ci			ret);
3188c2ecf20Sopenharmony_ci		return ret;
3198c2ecf20Sopenharmony_ci	}
3208c2ecf20Sopenharmony_ci
3218c2ecf20Sopenharmony_ci	platform_set_drvdata(pdev, config_regs);
3228c2ecf20Sopenharmony_ci
3238c2ecf20Sopenharmony_ci	data = of_device_get_match_data(&pdev->dev);
3248c2ecf20Sopenharmony_ci
3258c2ecf20Sopenharmony_ci	clks = platform_device_register_data(&pdev->dev, data->clk_driver,
3268c2ecf20Sopenharmony_ci					     PLATFORM_DEVID_AUTO, NULL, 0);
3278c2ecf20Sopenharmony_ci	if (IS_ERR(clks))
3288c2ecf20Sopenharmony_ci		return PTR_ERR(clks);
3298c2ecf20Sopenharmony_ci
3308c2ecf20Sopenharmony_ci	drm = platform_device_register_data(&pdev->dev, "mediatek-drm",
3318c2ecf20Sopenharmony_ci					    PLATFORM_DEVID_AUTO, NULL, 0);
3328c2ecf20Sopenharmony_ci	if (IS_ERR(drm)) {
3338c2ecf20Sopenharmony_ci		platform_device_unregister(clks);
3348c2ecf20Sopenharmony_ci		return PTR_ERR(drm);
3358c2ecf20Sopenharmony_ci	}
3368c2ecf20Sopenharmony_ci
3378c2ecf20Sopenharmony_ci	return 0;
3388c2ecf20Sopenharmony_ci}
3398c2ecf20Sopenharmony_ci
3408c2ecf20Sopenharmony_cistatic const struct of_device_id of_match_mtk_mmsys[] = {
3418c2ecf20Sopenharmony_ci	{
3428c2ecf20Sopenharmony_ci		.compatible = "mediatek,mt2701-mmsys",
3438c2ecf20Sopenharmony_ci		.data = &mt2701_mmsys_driver_data,
3448c2ecf20Sopenharmony_ci	},
3458c2ecf20Sopenharmony_ci	{
3468c2ecf20Sopenharmony_ci		.compatible = "mediatek,mt2712-mmsys",
3478c2ecf20Sopenharmony_ci		.data = &mt2712_mmsys_driver_data,
3488c2ecf20Sopenharmony_ci	},
3498c2ecf20Sopenharmony_ci	{
3508c2ecf20Sopenharmony_ci		.compatible = "mediatek,mt6779-mmsys",
3518c2ecf20Sopenharmony_ci		.data = &mt6779_mmsys_driver_data,
3528c2ecf20Sopenharmony_ci	},
3538c2ecf20Sopenharmony_ci	{
3548c2ecf20Sopenharmony_ci		.compatible = "mediatek,mt6797-mmsys",
3558c2ecf20Sopenharmony_ci		.data = &mt6797_mmsys_driver_data,
3568c2ecf20Sopenharmony_ci	},
3578c2ecf20Sopenharmony_ci	{
3588c2ecf20Sopenharmony_ci		.compatible = "mediatek,mt8173-mmsys",
3598c2ecf20Sopenharmony_ci		.data = &mt8173_mmsys_driver_data,
3608c2ecf20Sopenharmony_ci	},
3618c2ecf20Sopenharmony_ci	{
3628c2ecf20Sopenharmony_ci		.compatible = "mediatek,mt8183-mmsys",
3638c2ecf20Sopenharmony_ci		.data = &mt8183_mmsys_driver_data,
3648c2ecf20Sopenharmony_ci	},
3658c2ecf20Sopenharmony_ci	{ }
3668c2ecf20Sopenharmony_ci};
3678c2ecf20Sopenharmony_ci
3688c2ecf20Sopenharmony_cistatic struct platform_driver mtk_mmsys_drv = {
3698c2ecf20Sopenharmony_ci	.driver = {
3708c2ecf20Sopenharmony_ci		.name = "mtk-mmsys",
3718c2ecf20Sopenharmony_ci		.of_match_table = of_match_mtk_mmsys,
3728c2ecf20Sopenharmony_ci	},
3738c2ecf20Sopenharmony_ci	.probe = mtk_mmsys_probe,
3748c2ecf20Sopenharmony_ci};
3758c2ecf20Sopenharmony_ci
3768c2ecf20Sopenharmony_cibuiltin_platform_driver(mtk_mmsys_drv);
377