summaryrefslogtreecommitdiff
path: root/drivers/gpu/imx/dcss/dcss-blkctl.c
blob: 2f13b33dba3538e284bb5e6931a55d2ea164183c (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
/*
 * Copyright 2017 NXP
 *
 * This program is free software; you can redistribute it and/or modify it
 * under the terms of the GNU General Public License as published by the
 * Free Software Foundation; either version 2 of the License, or (at your
 * option) any later version.
 *
 * This program is distributed in the hope that it will be useful, but
 * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
 * or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
 * for more details.
 */

#include <linux/device.h>
#include <linux/io.h>
#include <linux/bitops.h>
#include <linux/of.h>
#include <linux/delay.h>
#include <soc/imx8/soc.h>

#include "dcss-prv.h"
#include <video/imx-dcss.h>

#define DCSS_BLKCTL_RESET_CTRL		0x00
#define   B_CLK_RESETN			BIT(0)
#define   APB_CLK_RESETN		BIT(1)
#define   P_CLK_RESETN			BIT(2)
#define   RTR_CLK_RESETN		BIT(3)
#define   HDMI_RESETN			BIT(4)
#define DCSS_BLKCTL_CONTROL0		0x10
#define   HDMI_MIPI_CLK_SEL		BIT(0)
#define   DISPMIX_REFCLK_SEL_POS	4
#define   DISPMIX_REFCLK_SEL_MASK	GENMASK(5, 4)
#define   DISPMIX_PIXCLK_SEL		BIT(8)
#define   HDMI_SRC_SECURE_EN		BIT(16)

#define B0_SILICON_ID			0x20

static struct dcss_debug_reg blkctl_debug_reg[] = {
	DCSS_DBG_REG(DCSS_BLKCTL_RESET_CTRL),
	DCSS_DBG_REG(DCSS_BLKCTL_CONTROL0),
};

struct dcss_blkctl_priv {
	struct dcss_soc *dcss;
	void __iomem *base_reg;

	bool hdmi_output;
	u32 clk_setting;
};

#ifdef CONFIG_DEBUG_FS
void dcss_blkctl_dump_regs(struct seq_file *s, void *data)
{
	struct dcss_soc *dcss = data;
	int j;

	seq_puts(s, ">> Dumping BLKCTL:\n");
	for (j = 0; j < ARRAY_SIZE(blkctl_debug_reg); j++)
		seq_printf(s, "%-35s(0x%04x) -> 0x%08x\n",
			   blkctl_debug_reg[j].name,
			   blkctl_debug_reg[j].ofs,
			   dcss_readl(dcss->blkctl_priv->base_reg +
				      blkctl_debug_reg[j].ofs));
}
#endif

static void dcss_blkctl_clk_reset(struct dcss_blkctl_priv *blkctl,
				  u32 assert, u32 deassert)
{
	if (assert)
		dcss_clr(assert, blkctl->base_reg + DCSS_BLKCTL_RESET_CTRL);

	if (deassert)
		dcss_set(deassert, blkctl->base_reg + DCSS_BLKCTL_RESET_CTRL);
}

void dcss_blkctl_cfg(struct dcss_soc *dcss)
{
	struct dcss_blkctl_priv *blkctl = dcss->blkctl_priv;

	if (blkctl->hdmi_output)
		dcss_writel((blkctl->clk_setting ^ HDMI_MIPI_CLK_SEL),
		    blkctl->base_reg + DCSS_BLKCTL_CONTROL0);
	else
		dcss_writel((blkctl->clk_setting ^ HDMI_MIPI_CLK_SEL) |
			    DISPMIX_PIXCLK_SEL,
			    blkctl->base_reg + DCSS_BLKCTL_CONTROL0);

	/* deassert clock domains resets */
	dcss_blkctl_clk_reset(blkctl, 0, 0xffffff);
}

int dcss_blkctl_init(struct dcss_soc *dcss, unsigned long blkctl_base)
{
	struct device_node *node = dcss->dev->of_node;
	int len;
	const char *disp_dev;
	struct dcss_blkctl_priv *blkctl;

	blkctl = devm_kzalloc(dcss->dev, sizeof(*blkctl), GFP_KERNEL);
	if (!blkctl)
		return -ENOMEM;

	blkctl->base_reg = devm_ioremap(dcss->dev, blkctl_base, SZ_4K);
	if (!blkctl->base_reg) {
		dev_err(dcss->dev, "unable to remap BLK CTRL base\n");
		return -ENOMEM;
	}

	blkctl->dcss = dcss;
	dcss->blkctl_priv = blkctl;

	disp_dev = of_get_property(node, "disp-dev", &len);
	if (!disp_dev || !strncmp(disp_dev, "hdmi_disp", 9))
		blkctl->hdmi_output = true;

	if (imx8_get_soc_revision() >= B0_SILICON_ID)
		blkctl->clk_setting = HDMI_MIPI_CLK_SEL;

	dcss_blkctl_cfg(dcss);

	return 0;
}

void dcss_blkctl_exit(struct dcss_soc *dcss)
{
	/* assert clock domains resets */
	dcss_blkctl_clk_reset(dcss->blkctl_priv,
			      B_CLK_RESETN | APB_CLK_RESETN | P_CLK_RESETN |
			      HDMI_RESETN | RTR_CLK_RESETN, 0);
}

/* disabled only by cold reset/reboot */
void dcss_blkctl_hdmi_secure_src_en(struct dcss_soc *dcss)
{
	struct dcss_blkctl_priv *blkctl = dcss->blkctl_priv;

	dcss_set(HDMI_SRC_SECURE_EN, blkctl->base_reg + DCSS_BLKCTL_CONTROL0);
}
EXPORT_SYMBOL(dcss_blkctl_hdmi_secure_src_en);