summaryrefslogtreecommitdiff
path: root/drivers/gpu/drm/imx/dc/dc-pe.c
blob: 6676c22f3f458bd365befd4fcc9c92b4bd4acd87 (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
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
// SPDX-License-Identifier: GPL-2.0+
/*
 * Copyright 2024 NXP
 */

#include <linux/clk.h>
#include <linux/component.h>
#include <linux/mod_devicetable.h>
#include <linux/module.h>
#include <linux/of.h>
#include <linux/of_platform.h>
#include <linux/platform_device.h>
#include <linux/pm.h>
#include <linux/pm_runtime.h>

#include "dc-drv.h"
#include "dc-fu.h"
#include "dc-pe.h"

static int dc_pe_bind(struct device *dev, struct device *master, void *data)
{
	struct dc_drm_device *dc_drm = data;
	struct dc_pe *pe;
	int ret;

	pe = devm_kzalloc(dev, sizeof(*pe), GFP_KERNEL);
	if (!pe)
		return -ENOMEM;

	pe->clk_axi = devm_clk_get(dev, NULL);
	if (IS_ERR(pe->clk_axi))
		return dev_err_probe(dev, PTR_ERR(pe->clk_axi),
				     "failed to get AXI clock\n");

	pe->dev = dev;

	dev_set_drvdata(dev, pe);

	ret = devm_pm_runtime_enable(dev);
	if (ret)
		return ret;

	dc_drm->pe = pe;

	return 0;
}

/*
 * It's possible to get the child device pointers from the child component
 * bind callbacks, but it depends on the component helper behavior to bind
 * the pixel engine component first.  To avoid the dependency, post bind to
 * get the pointers from dc_drm in a safe manner.
 */
void dc_pe_post_bind(struct dc_drm_device *dc_drm)
{
	struct dc_pe *pe = dc_drm->pe;
	int i;

	for (i = 0; i < DC_DISPLAYS; i++) {
		pe->cf_safe[i] = dc_drm->cf_safe[i];
		pe->cf_cont[i] = dc_drm->cf_cont[i];
		pe->ed_safe[i] = dc_drm->ed_safe[i];
		pe->ed_cont[i] = dc_drm->ed_cont[i];
	}

	for (i = 0; i < DC_DISP_FU_CNT; i++)
		pe->fu_disp[i] = dc_drm->fu_disp[i];

	for (i = 0; i < DC_LB_CNT; i++)
		pe->lb[i] = dc_drm->lb[i];
}

static const struct component_ops dc_pe_ops = {
	.bind = dc_pe_bind,
};

static int dc_pe_probe(struct platform_device *pdev)
{
	int ret;

	ret = devm_of_platform_populate(&pdev->dev);
	if (ret < 0)
		return ret;

	ret = component_add(&pdev->dev, &dc_pe_ops);
	if (ret)
		return dev_err_probe(&pdev->dev, ret,
				     "failed to add component\n");

	return 0;
}

static void dc_pe_remove(struct platform_device *pdev)
{
	component_del(&pdev->dev, &dc_pe_ops);
}

static int dc_pe_runtime_suspend(struct device *dev)
{
	struct dc_pe *pe = dev_get_drvdata(dev);

	clk_disable_unprepare(pe->clk_axi);

	return 0;
}

static int dc_pe_runtime_resume(struct device *dev)
{
	struct dc_pe *pe = dev_get_drvdata(dev);
	int i, ret;

	ret = clk_prepare_enable(pe->clk_axi);
	if (ret) {
		dev_err(dev, "failed to enable AXI clock: %d\n", ret);
		return ret;
	}

	for (i = 0; i < ARRAY_SIZE(pe->cf_safe); i++)
		dc_cf_init(pe->cf_safe[i]);

	for (i = 0; i < ARRAY_SIZE(pe->cf_cont); i++)
		dc_cf_init(pe->cf_cont[i]);

	for (i = 0; i < ARRAY_SIZE(pe->ed_safe); i++)
		dc_ed_init(pe->ed_safe[i]);

	for (i = 0; i < ARRAY_SIZE(pe->ed_cont); i++)
		dc_ed_init(pe->ed_cont[i]);

	for (i = 0; i < ARRAY_SIZE(pe->fu_disp); i++)
		pe->fu_disp[i]->ops.init(pe->fu_disp[i]);

	for (i = 0; i < ARRAY_SIZE(pe->lb); i++)
		dc_lb_init(pe->lb[i]);

	return 0;
}

static const struct dev_pm_ops dc_pe_pm_ops = {
	RUNTIME_PM_OPS(dc_pe_runtime_suspend, dc_pe_runtime_resume, NULL)
};

static const struct of_device_id dc_pe_dt_ids[] = {
	{ .compatible = "fsl,imx8qxp-dc-pixel-engine", },
	{ /* sentinel */ }
};
MODULE_DEVICE_TABLE(of, dc_pe_dt_ids);

struct platform_driver dc_pe_driver = {
	.probe = dc_pe_probe,
	.remove = dc_pe_remove,
	.driver = {
		.name = "imx8-dc-pixel-engine",
		.suppress_bind_attrs = true,
		.of_match_table = dc_pe_dt_ids,
		.pm = pm_sleep_ptr(&dc_pe_pm_ops),
	},
};