18c2ecf20Sopenharmony_ci// SPDX-License-Identifier: GPL-2.0
28c2ecf20Sopenharmony_ci/*
38c2ecf20Sopenharmony_ci * TI j721e Cadence MHDP8546 DP wrapper
48c2ecf20Sopenharmony_ci *
58c2ecf20Sopenharmony_ci * Copyright (C) 2020 Texas Instruments Incorporated - http://www.ti.com/
68c2ecf20Sopenharmony_ci * Author: Jyri Sarha <jsarha@ti.com>
78c2ecf20Sopenharmony_ci */
88c2ecf20Sopenharmony_ci
98c2ecf20Sopenharmony_ci#include <linux/io.h>
108c2ecf20Sopenharmony_ci#include <linux/platform_device.h>
118c2ecf20Sopenharmony_ci
128c2ecf20Sopenharmony_ci#include "cdns-mhdp8546-j721e.h"
138c2ecf20Sopenharmony_ci
148c2ecf20Sopenharmony_ci#define	REVISION			0x00
158c2ecf20Sopenharmony_ci#define	DPTX_IPCFG			0x04
168c2ecf20Sopenharmony_ci#define	ECC_MEM_CFG			0x08
178c2ecf20Sopenharmony_ci#define	DPTX_DSC_CFG			0x0c
188c2ecf20Sopenharmony_ci#define	DPTX_SRC_CFG			0x10
198c2ecf20Sopenharmony_ci#define	DPTX_VIF_SECURE_MODE_CFG	0x14
208c2ecf20Sopenharmony_ci#define	DPTX_VIF_CONN_STATUS		0x18
218c2ecf20Sopenharmony_ci#define	PHY_CLK_STATUS			0x1c
228c2ecf20Sopenharmony_ci
238c2ecf20Sopenharmony_ci#define DPTX_SRC_AIF_EN			BIT(16)
248c2ecf20Sopenharmony_ci#define DPTX_SRC_VIF_3_IN30B		BIT(11)
258c2ecf20Sopenharmony_ci#define DPTX_SRC_VIF_2_IN30B		BIT(10)
268c2ecf20Sopenharmony_ci#define DPTX_SRC_VIF_1_IN30B		BIT(9)
278c2ecf20Sopenharmony_ci#define DPTX_SRC_VIF_0_IN30B		BIT(8)
288c2ecf20Sopenharmony_ci#define DPTX_SRC_VIF_3_SEL_DPI5		BIT(7)
298c2ecf20Sopenharmony_ci#define DPTX_SRC_VIF_3_SEL_DPI3		0
308c2ecf20Sopenharmony_ci#define DPTX_SRC_VIF_2_SEL_DPI4		BIT(6)
318c2ecf20Sopenharmony_ci#define DPTX_SRC_VIF_2_SEL_DPI2		0
328c2ecf20Sopenharmony_ci#define DPTX_SRC_VIF_1_SEL_DPI3		BIT(5)
338c2ecf20Sopenharmony_ci#define DPTX_SRC_VIF_1_SEL_DPI1		0
348c2ecf20Sopenharmony_ci#define DPTX_SRC_VIF_0_SEL_DPI2		BIT(4)
358c2ecf20Sopenharmony_ci#define DPTX_SRC_VIF_0_SEL_DPI0		0
368c2ecf20Sopenharmony_ci#define DPTX_SRC_VIF_3_EN		BIT(3)
378c2ecf20Sopenharmony_ci#define DPTX_SRC_VIF_2_EN		BIT(2)
388c2ecf20Sopenharmony_ci#define DPTX_SRC_VIF_1_EN		BIT(1)
398c2ecf20Sopenharmony_ci#define DPTX_SRC_VIF_0_EN		BIT(0)
408c2ecf20Sopenharmony_ci
418c2ecf20Sopenharmony_ci/* TODO turn DPTX_IPCFG fw_mem_clk_en at pm_runtime_suspend. */
428c2ecf20Sopenharmony_ci
438c2ecf20Sopenharmony_cistatic int cdns_mhdp_j721e_init(struct cdns_mhdp_device *mhdp)
448c2ecf20Sopenharmony_ci{
458c2ecf20Sopenharmony_ci	struct platform_device *pdev = to_platform_device(mhdp->dev);
468c2ecf20Sopenharmony_ci
478c2ecf20Sopenharmony_ci	mhdp->j721e_regs = devm_platform_ioremap_resource(pdev, 1);
488c2ecf20Sopenharmony_ci	return PTR_ERR_OR_ZERO(mhdp->j721e_regs);
498c2ecf20Sopenharmony_ci}
508c2ecf20Sopenharmony_ci
518c2ecf20Sopenharmony_cistatic void cdns_mhdp_j721e_enable(struct cdns_mhdp_device *mhdp)
528c2ecf20Sopenharmony_ci{
538c2ecf20Sopenharmony_ci	/*
548c2ecf20Sopenharmony_ci	 * Enable VIF_0 and select DPI2 as its input. DSS0 DPI0 is connected
558c2ecf20Sopenharmony_ci	 * to eDP DPI2. This is the only supported SST configuration on
568c2ecf20Sopenharmony_ci	 * J721E.
578c2ecf20Sopenharmony_ci	 */
588c2ecf20Sopenharmony_ci	writel(DPTX_SRC_VIF_0_EN | DPTX_SRC_VIF_0_SEL_DPI2,
598c2ecf20Sopenharmony_ci	       mhdp->j721e_regs + DPTX_SRC_CFG);
608c2ecf20Sopenharmony_ci}
618c2ecf20Sopenharmony_ci
628c2ecf20Sopenharmony_cistatic void cdns_mhdp_j721e_disable(struct cdns_mhdp_device *mhdp)
638c2ecf20Sopenharmony_ci{
648c2ecf20Sopenharmony_ci	/* Put everything to defaults  */
658c2ecf20Sopenharmony_ci	writel(0, mhdp->j721e_regs + DPTX_DSC_CFG);
668c2ecf20Sopenharmony_ci}
678c2ecf20Sopenharmony_ci
688c2ecf20Sopenharmony_ciconst struct mhdp_platform_ops mhdp_ti_j721e_ops = {
698c2ecf20Sopenharmony_ci	.init = cdns_mhdp_j721e_init,
708c2ecf20Sopenharmony_ci	.enable = cdns_mhdp_j721e_enable,
718c2ecf20Sopenharmony_ci	.disable = cdns_mhdp_j721e_disable,
728c2ecf20Sopenharmony_ci};
738c2ecf20Sopenharmony_ci
748c2ecf20Sopenharmony_ciconst struct drm_bridge_timings mhdp_ti_j721e_bridge_timings = {
758c2ecf20Sopenharmony_ci	.input_bus_flags = DRM_BUS_FLAG_PIXDATA_SAMPLE_NEGEDGE |
768c2ecf20Sopenharmony_ci			   DRM_BUS_FLAG_SYNC_SAMPLE_NEGEDGE |
778c2ecf20Sopenharmony_ci			   DRM_BUS_FLAG_DE_HIGH,
788c2ecf20Sopenharmony_ci};
79