1 // SPDX-License-Identifier: GPL-2.0
3 * Copyright (C) STMicroelectronics SA 2014
4 * Authors: Benjamin Gaignard <benjamin.gaignard@st.com>
5 * Fabien Dessenne <fabien.dessenne@st.com>
6 * for STMicroelectronics.
9 #include <linux/component.h>
11 #include <linux/module.h>
12 #include <linux/platform_device.h>
13 #include <linux/reset.h>
15 #include <drm/drm_device.h>
16 #include <drm/drm_print.h>
17 #include <drm/drm_vblank.h>
19 #include "sti_compositor.h"
21 #include "sti_cursor.h"
24 #include "sti_plane.h"
29 * stiH407 compositor properties
31 static const struct sti_compositor_data stih407_compositor_data = {
34 {STI_CURSOR_SUBDEV, (int)STI_CURSOR, 0x000},
35 {STI_GPD_SUBDEV, (int)STI_GDP_0, 0x100},
36 {STI_GPD_SUBDEV, (int)STI_GDP_1, 0x200},
37 {STI_GPD_SUBDEV, (int)STI_GDP_2, 0x300},
38 {STI_GPD_SUBDEV, (int)STI_GDP_3, 0x400},
39 {STI_VID_SUBDEV, (int)STI_HQVDP_0, 0x700},
40 {STI_MIXER_MAIN_SUBDEV, STI_MIXER_MAIN, 0xC00},
41 {STI_MIXER_AUX_SUBDEV, STI_MIXER_AUX, 0xD00},
45 void sti_compositor_debugfs_init(struct sti_compositor *compo,
46 struct drm_minor *minor)
50 for (i = 0; i < STI_MAX_VID; i++)
52 vid_debugfs_init(compo->vid[i], minor);
54 for (i = 0; i < STI_MAX_MIXER; i++)
56 sti_mixer_debugfs_init(compo->mixer[i], minor);
59 static int sti_compositor_bind(struct device *dev,
60 struct device *master,
63 struct sti_compositor *compo = dev_get_drvdata(dev);
64 struct drm_device *drm_dev = data;
65 unsigned int i, mixer_id = 0, vid_id = 0, crtc_id = 0;
66 struct sti_private *dev_priv = drm_dev->dev_private;
67 struct drm_plane *cursor = NULL;
68 struct drm_plane *primary = NULL;
69 struct sti_compositor_subdev_descriptor *desc = compo->data.subdev_desc;
70 unsigned int array_size = compo->data.nb_subdev;
72 dev_priv->compo = compo;
74 /* Register mixer subdev and video subdev first */
75 for (i = 0; i < array_size; i++) {
76 switch (desc[i].type) {
78 compo->vid[vid_id++] =
79 sti_vid_create(compo->dev, drm_dev, desc[i].id,
80 compo->regs + desc[i].offset);
82 case STI_MIXER_MAIN_SUBDEV:
83 case STI_MIXER_AUX_SUBDEV:
84 compo->mixer[mixer_id++] =
85 sti_mixer_create(compo->dev, drm_dev, desc[i].id,
86 compo->regs + desc[i].offset);
89 case STI_CURSOR_SUBDEV:
90 /* Nothing to do, wait for the second round */
93 DRM_ERROR("Unknown subdev component type\n");
98 /* Register the other subdevs, create crtc and planes */
99 for (i = 0; i < array_size; i++) {
100 enum drm_plane_type plane_type = DRM_PLANE_TYPE_OVERLAY;
102 if (crtc_id < mixer_id)
103 plane_type = DRM_PLANE_TYPE_PRIMARY;
105 switch (desc[i].type) {
106 case STI_MIXER_MAIN_SUBDEV:
107 case STI_MIXER_AUX_SUBDEV:
109 /* Nothing to do, already done at the first round */
111 case STI_CURSOR_SUBDEV:
112 cursor = sti_cursor_create(drm_dev, compo->dev,
114 compo->regs + desc[i].offset,
117 DRM_ERROR("Can't create CURSOR plane\n");
122 primary = sti_gdp_create(drm_dev, compo->dev,
124 compo->regs + desc[i].offset,
128 DRM_ERROR("Can't create GDP plane\n");
133 DRM_ERROR("Unknown subdev component type\n");
137 /* The first planes are reserved for primary planes*/
138 if (crtc_id < mixer_id && primary) {
139 sti_crtc_init(drm_dev, compo->mixer[crtc_id],
147 drm_vblank_init(drm_dev, crtc_id);
152 static void sti_compositor_unbind(struct device *dev, struct device *master,
158 static const struct component_ops sti_compositor_ops = {
159 .bind = sti_compositor_bind,
160 .unbind = sti_compositor_unbind,
163 static const struct of_device_id compositor_of_match[] = {
165 .compatible = "st,stih407-compositor",
166 .data = &stih407_compositor_data,
171 MODULE_DEVICE_TABLE(of, compositor_of_match);
173 static int sti_compositor_probe(struct platform_device *pdev)
175 struct device *dev = &pdev->dev;
176 struct device_node *np = dev->of_node;
177 struct device_node *vtg_np;
178 struct sti_compositor *compo;
179 struct resource *res;
182 compo = devm_kzalloc(dev, sizeof(*compo), GFP_KERNEL);
184 DRM_ERROR("Failed to allocate compositor context\n");
188 for (i = 0; i < STI_MAX_MIXER; i++)
189 compo->vtg_vblank_nb[i].notifier_call = sti_crtc_vblank_cb;
191 /* populate data structure depending on compatibility */
192 BUG_ON(!of_match_node(compositor_of_match, np)->data);
194 memcpy(&compo->data, of_match_node(compositor_of_match, np)->data,
195 sizeof(struct sti_compositor_data));
197 /* Get Memory ressources */
198 res = platform_get_resource(pdev, IORESOURCE_MEM, 0);
200 DRM_ERROR("Get memory resource failed\n");
203 compo->regs = devm_ioremap(dev, res->start, resource_size(res));
204 if (compo->regs == NULL) {
205 DRM_ERROR("Register mapping failed\n");
209 /* Get clock resources */
210 compo->clk_compo_main = devm_clk_get(dev, "compo_main");
211 if (IS_ERR(compo->clk_compo_main)) {
212 DRM_ERROR("Cannot get compo_main clock\n");
213 return PTR_ERR(compo->clk_compo_main);
216 compo->clk_compo_aux = devm_clk_get(dev, "compo_aux");
217 if (IS_ERR(compo->clk_compo_aux)) {
218 DRM_ERROR("Cannot get compo_aux clock\n");
219 return PTR_ERR(compo->clk_compo_aux);
222 compo->clk_pix_main = devm_clk_get(dev, "pix_main");
223 if (IS_ERR(compo->clk_pix_main)) {
224 DRM_ERROR("Cannot get pix_main clock\n");
225 return PTR_ERR(compo->clk_pix_main);
228 compo->clk_pix_aux = devm_clk_get(dev, "pix_aux");
229 if (IS_ERR(compo->clk_pix_aux)) {
230 DRM_ERROR("Cannot get pix_aux clock\n");
231 return PTR_ERR(compo->clk_pix_aux);
234 /* Get reset resources */
235 compo->rst_main = devm_reset_control_get_shared(dev, "compo-main");
236 /* Take compo main out of reset */
237 if (!IS_ERR(compo->rst_main))
238 reset_control_deassert(compo->rst_main);
240 compo->rst_aux = devm_reset_control_get_shared(dev, "compo-aux");
241 /* Take compo aux out of reset */
242 if (!IS_ERR(compo->rst_aux))
243 reset_control_deassert(compo->rst_aux);
245 vtg_np = of_parse_phandle(pdev->dev.of_node, "st,vtg", 0);
247 compo->vtg[STI_MIXER_MAIN] = of_vtg_find(vtg_np);
250 vtg_np = of_parse_phandle(pdev->dev.of_node, "st,vtg", 1);
252 compo->vtg[STI_MIXER_AUX] = of_vtg_find(vtg_np);
255 platform_set_drvdata(pdev, compo);
257 return component_add(&pdev->dev, &sti_compositor_ops);
260 static int sti_compositor_remove(struct platform_device *pdev)
262 component_del(&pdev->dev, &sti_compositor_ops);
266 struct platform_driver sti_compositor_driver = {
268 .name = "sti-compositor",
269 .of_match_table = compositor_of_match,
271 .probe = sti_compositor_probe,
272 .remove = sti_compositor_remove,
275 MODULE_AUTHOR("Benjamin Gaignard <benjamin.gaignard@st.com>");
276 MODULE_DESCRIPTION("STMicroelectronics SoC DRM driver");
277 MODULE_LICENSE("GPL");