drm: sti: enable auxiliary CRTC
[deliverable/linux.git] / drivers / gpu / drm / sti / sti_compositor.c
CommitLineData
d219673d
BG
1/*
2 * Copyright (C) STMicroelectronics SA 2014
3 * Authors: Benjamin Gaignard <benjamin.gaignard@st.com>
4 * Fabien Dessenne <fabien.dessenne@st.com>
5 * for STMicroelectronics.
6 * License terms: GNU General Public License (GPL), version 2
7 */
8
9#include <linux/component.h>
10#include <linux/module.h>
11#include <linux/platform_device.h>
12#include <linux/reset.h>
13
14#include <drm/drmP.h>
15
16#include "sti_compositor.h"
9bbf86fe
BG
17#include "sti_drm_crtc.h"
18#include "sti_drm_drv.h"
19#include "sti_drm_plane.h"
d219673d
BG
20#include "sti_gdp.h"
21#include "sti_vtg.h"
22
23/*
24 * stiH407 compositor properties
25 */
26struct sti_compositor_data stih407_compositor_data = {
5e03abc5 27 .nb_subdev = 7,
d219673d
BG
28 .subdev_desc = {
29 {STI_GPD_SUBDEV, (int)STI_GDP_0, 0x100},
30 {STI_GPD_SUBDEV, (int)STI_GDP_1, 0x200},
31 {STI_GPD_SUBDEV, (int)STI_GDP_2, 0x300},
32 {STI_GPD_SUBDEV, (int)STI_GDP_3, 0x400},
33 {STI_VID_SUBDEV, (int)STI_VID_0, 0x700},
5e03abc5
BG
34 {STI_MIXER_MAIN_SUBDEV, STI_MIXER_MAIN, 0xC00},
35 {STI_MIXER_AUX_SUBDEV, STI_MIXER_AUX, 0xD00},
d219673d
BG
36 },
37};
38
39/*
40 * stiH416 compositor properties
41 * Note:
42 * on stih416 MIXER_AUX has a different base address from MIXER_MAIN
43 * Moreover, GDPx is different for Main and Aux Mixer. So this subdev map does
44 * not fit for stiH416 if we want to enable the MIXER_AUX.
45 */
46struct sti_compositor_data stih416_compositor_data = {
47 .nb_subdev = 3,
48 .subdev_desc = {
49 {STI_GPD_SUBDEV, (int)STI_GDP_0, 0x100},
50 {STI_GPD_SUBDEV, (int)STI_GDP_1, 0x200},
51 {STI_MIXER_MAIN_SUBDEV, STI_MIXER_MAIN, 0xC00}
52 },
53};
54
55static int sti_compositor_init_subdev(struct sti_compositor *compo,
56 struct sti_compositor_subdev_descriptor *desc,
57 unsigned int array_size)
58{
59 unsigned int i, mixer_id = 0, layer_id = 0;
60
61 for (i = 0; i < array_size; i++) {
62 switch (desc[i].type) {
63 case STI_MIXER_MAIN_SUBDEV:
64 case STI_MIXER_AUX_SUBDEV:
65 compo->mixer[mixer_id++] =
66 sti_mixer_create(compo->dev, desc[i].id,
67 compo->regs + desc[i].offset);
68 break;
69 case STI_GPD_SUBDEV:
70 case STI_VID_SUBDEV:
71 compo->layer[layer_id++] =
72 sti_layer_create(compo->dev, desc[i].id,
73 compo->regs + desc[i].offset);
74 break;
75 /* case STI_CURSOR_SUBDEV : TODO */
76 default:
77 DRM_ERROR("Unknow subdev compoment type\n");
78 return 1;
79 }
80
81 }
82 compo->nb_mixers = mixer_id;
83 compo->nb_layers = layer_id;
84
85 return 0;
86}
87
88static int sti_compositor_bind(struct device *dev, struct device *master,
89 void *data)
90{
91 struct sti_compositor *compo = dev_get_drvdata(dev);
92 struct drm_device *drm_dev = data;
93 unsigned int i, crtc = 0, plane = 0;
9bbf86fe
BG
94 struct sti_drm_private *dev_priv = drm_dev->dev_private;
95 struct drm_plane *cursor = NULL;
96 struct drm_plane *primary = NULL;
97
98 dev_priv->compo = compo;
99
100 for (i = 0; i < compo->nb_layers; i++) {
101 if (compo->layer[i]) {
102 enum sti_layer_desc desc = compo->layer[i]->desc;
103 enum sti_layer_type type = desc & STI_LAYER_TYPE_MASK;
104 enum drm_plane_type plane_type = DRM_PLANE_TYPE_OVERLAY;
105
5e03abc5 106 if (crtc < compo->nb_mixers)
9bbf86fe
BG
107 plane_type = DRM_PLANE_TYPE_PRIMARY;
108
109 switch (type) {
110 case STI_CUR:
111 cursor = sti_drm_plane_init(drm_dev,
112 compo->layer[i],
5e03abc5 113 1, DRM_PLANE_TYPE_CURSOR);
9bbf86fe
BG
114 break;
115 case STI_GDP:
116 case STI_VID:
117 primary = sti_drm_plane_init(drm_dev,
118 compo->layer[i],
5e03abc5
BG
119 (1 << compo->nb_mixers) - 1,
120 plane_type);
9bbf86fe
BG
121 plane++;
122 break;
8bb652eb
DA
123 case STI_BCK:
124 break;
9bbf86fe
BG
125 }
126
127 /* The first planes are reserved for primary planes*/
5e03abc5 128 if (crtc < compo->nb_mixers) {
9bbf86fe
BG
129 sti_drm_crtc_init(drm_dev, compo->mixer[crtc],
130 primary, cursor);
131 crtc++;
132 cursor = NULL;
133 }
134 }
135 }
d219673d
BG
136
137 drm_vblank_init(drm_dev, crtc);
138 /* Allow usage of vblank without having to call drm_irq_install */
139 drm_dev->irq_enabled = 1;
140
d219673d
BG
141 DRM_DEBUG_DRIVER("Initialized %d DRM CRTC(s) and %d DRM plane(s)\n",
142 crtc, plane);
143 DRM_DEBUG_DRIVER("DRM plane(s) for VID/VDP not created yet\n");
144
145 return 0;
146}
147
148static void sti_compositor_unbind(struct device *dev, struct device *master,
149 void *data)
150{
151 /* do nothing */
152}
153
154static const struct component_ops sti_compositor_ops = {
155 .bind = sti_compositor_bind,
156 .unbind = sti_compositor_unbind,
157};
158
159static const struct of_device_id compositor_of_match[] = {
160 {
161 .compatible = "st,stih416-compositor",
162 .data = &stih416_compositor_data,
163 }, {
164 .compatible = "st,stih407-compositor",
165 .data = &stih407_compositor_data,
166 }, {
167 /* end node */
168 }
169};
170MODULE_DEVICE_TABLE(of, compositor_of_match);
171
172static int sti_compositor_probe(struct platform_device *pdev)
173{
174 struct device *dev = &pdev->dev;
175 struct device_node *np = dev->of_node;
176 struct device_node *vtg_np;
177 struct sti_compositor *compo;
178 struct resource *res;
179 int err;
180
181 compo = devm_kzalloc(dev, sizeof(*compo), GFP_KERNEL);
182 if (!compo) {
183 DRM_ERROR("Failed to allocate compositor context\n");
184 return -ENOMEM;
185 }
186 compo->dev = dev;
9bbf86fe 187 compo->vtg_vblank_nb.notifier_call = sti_drm_crtc_vblank_cb;
d219673d
BG
188
189 /* populate data structure depending on compatibility */
190 BUG_ON(!of_match_node(compositor_of_match, np)->data);
191
192 memcpy(&compo->data, of_match_node(compositor_of_match, np)->data,
193 sizeof(struct sti_compositor_data));
194
195 /* Get Memory ressources */
196 res = platform_get_resource(pdev, IORESOURCE_MEM, 0);
197 if (res == NULL) {
198 DRM_ERROR("Get memory resource failed\n");
199 return -ENXIO;
200 }
201 compo->regs = devm_ioremap(dev, res->start, resource_size(res));
202 if (compo->regs == NULL) {
203 DRM_ERROR("Register mapping failed\n");
204 return -ENXIO;
205 }
206
207 /* Get clock resources */
208 compo->clk_compo_main = devm_clk_get(dev, "compo_main");
209 if (IS_ERR(compo->clk_compo_main)) {
210 DRM_ERROR("Cannot get compo_main clock\n");
211 return PTR_ERR(compo->clk_compo_main);
212 }
213
214 compo->clk_compo_aux = devm_clk_get(dev, "compo_aux");
215 if (IS_ERR(compo->clk_compo_aux)) {
216 DRM_ERROR("Cannot get compo_aux clock\n");
217 return PTR_ERR(compo->clk_compo_aux);
218 }
219
220 compo->clk_pix_main = devm_clk_get(dev, "pix_main");
221 if (IS_ERR(compo->clk_pix_main)) {
222 DRM_ERROR("Cannot get pix_main clock\n");
223 return PTR_ERR(compo->clk_pix_main);
224 }
225
226 compo->clk_pix_aux = devm_clk_get(dev, "pix_aux");
227 if (IS_ERR(compo->clk_pix_aux)) {
228 DRM_ERROR("Cannot get pix_aux clock\n");
229 return PTR_ERR(compo->clk_pix_aux);
230 }
231
232 /* Get reset resources */
233 compo->rst_main = devm_reset_control_get(dev, "compo-main");
234 /* Take compo main out of reset */
235 if (!IS_ERR(compo->rst_main))
236 reset_control_deassert(compo->rst_main);
237
238 compo->rst_aux = devm_reset_control_get(dev, "compo-aux");
239 /* Take compo aux out of reset */
240 if (!IS_ERR(compo->rst_aux))
241 reset_control_deassert(compo->rst_aux);
242
243 vtg_np = of_parse_phandle(pdev->dev.of_node, "st,vtg", 0);
244 if (vtg_np)
245 compo->vtg_main = of_vtg_find(vtg_np);
246
247 vtg_np = of_parse_phandle(pdev->dev.of_node, "st,vtg", 1);
248 if (vtg_np)
249 compo->vtg_aux = of_vtg_find(vtg_np);
250
251 /* Initialize compositor subdevices */
252 err = sti_compositor_init_subdev(compo, compo->data.subdev_desc,
253 compo->data.nb_subdev);
254 if (err)
255 return err;
256
257 platform_set_drvdata(pdev, compo);
258
259 return component_add(&pdev->dev, &sti_compositor_ops);
260}
261
262static int sti_compositor_remove(struct platform_device *pdev)
263{
264 component_del(&pdev->dev, &sti_compositor_ops);
265 return 0;
266}
267
268static struct platform_driver sti_compositor_driver = {
269 .driver = {
270 .name = "sti-compositor",
271 .owner = THIS_MODULE,
272 .of_match_table = compositor_of_match,
273 },
274 .probe = sti_compositor_probe,
275 .remove = sti_compositor_remove,
276};
277
278module_platform_driver(sti_compositor_driver);
279
280MODULE_AUTHOR("Benjamin Gaignard <benjamin.gaignard@st.com>");
281MODULE_DESCRIPTION("STMicroelectronics SoC DRM driver");
282MODULE_LICENSE("GPL");
This page took 0.055319 seconds and 5 git commands to generate.