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