blob: 134201ecc6fd98b65f286c0dd6f1135e04aaabc6 [file] [log] [blame]
Benjamin Gaignardd2196732014-07-30 19:28:27 +02001/*
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"
Vincent Abriou9e1f05b2015-07-31 11:32:34 +020017#include "sti_crtc.h"
Vincent Abriou871bcdf2015-07-31 11:32:13 +020018#include "sti_cursor.h"
Vincent Abriou9e1f05b2015-07-31 11:32:34 +020019#include "sti_drv.h"
Benjamin Gaignardd2196732014-07-30 19:28:27 +020020#include "sti_gdp.h"
Vincent Abriou9e1f05b2015-07-31 11:32:34 +020021#include "sti_plane.h"
Vincent Abriou871bcdf2015-07-31 11:32:13 +020022#include "sti_vid.h"
Benjamin Gaignardd2196732014-07-30 19:28:27 +020023#include "sti_vtg.h"
24
25/*
26 * stiH407 compositor properties
27 */
28struct sti_compositor_data stih407_compositor_data = {
Benjamin Gaignard96006a72014-12-11 13:34:42 +010029 .nb_subdev = 8,
Benjamin Gaignardd2196732014-07-30 19:28:27 +020030 .subdev_desc = {
Benjamin Gaignard96006a72014-12-11 13:34:42 +010031 {STI_CURSOR_SUBDEV, (int)STI_CURSOR, 0x000},
Benjamin Gaignardd2196732014-07-30 19:28:27 +020032 {STI_GPD_SUBDEV, (int)STI_GDP_0, 0x100},
33 {STI_GPD_SUBDEV, (int)STI_GDP_1, 0x200},
34 {STI_GPD_SUBDEV, (int)STI_GDP_2, 0x300},
35 {STI_GPD_SUBDEV, (int)STI_GDP_3, 0x400},
Vincent Abriou871bcdf2015-07-31 11:32:13 +020036 {STI_VID_SUBDEV, (int)STI_HQVDP_0, 0x700},
Benjamin Gaignard5e03abc2014-12-08 17:32:36 +010037 {STI_MIXER_MAIN_SUBDEV, STI_MIXER_MAIN, 0xC00},
38 {STI_MIXER_AUX_SUBDEV, STI_MIXER_AUX, 0xD00},
Benjamin Gaignardd2196732014-07-30 19:28:27 +020039 },
40};
41
42/*
43 * stiH416 compositor properties
44 * Note:
45 * on stih416 MIXER_AUX has a different base address from MIXER_MAIN
46 * Moreover, GDPx is different for Main and Aux Mixer. So this subdev map does
47 * not fit for stiH416 if we want to enable the MIXER_AUX.
48 */
49struct sti_compositor_data stih416_compositor_data = {
50 .nb_subdev = 3,
51 .subdev_desc = {
52 {STI_GPD_SUBDEV, (int)STI_GDP_0, 0x100},
53 {STI_GPD_SUBDEV, (int)STI_GDP_1, 0x200},
54 {STI_MIXER_MAIN_SUBDEV, STI_MIXER_MAIN, 0xC00}
55 },
56};
57
Benjamin Gaignard83af0a42016-06-21 15:09:39 +020058int sti_compositor_debufs_init(struct sti_compositor *compo,
59 struct drm_minor *minor)
60{
61 int ret = 0, i;
62
63 for (i = 0; compo->vid[i]; i++) {
64 ret = vid_debugfs_init(compo->vid[i], minor);
65 if (ret)
66 return ret;
67 }
68
69 for (i = 0; compo->mixer[i]; i++) {
70 ret = sti_mixer_debugfs_init(compo->mixer[i], minor);
71 if (ret)
72 return ret;
73 }
74
75 return 0;
76}
77
Vincent Abriou871bcdf2015-07-31 11:32:13 +020078static int sti_compositor_bind(struct device *dev,
79 struct device *master,
80 void *data)
Benjamin Gaignardd2196732014-07-30 19:28:27 +020081{
Vincent Abriou871bcdf2015-07-31 11:32:13 +020082 struct sti_compositor *compo = dev_get_drvdata(dev);
83 struct drm_device *drm_dev = data;
Vincent Abriou29d1dc62015-08-03 14:22:16 +020084 unsigned int i, mixer_id = 0, vid_id = 0, crtc_id = 0;
Vincent Abriou9e1f05b2015-07-31 11:32:34 +020085 struct sti_private *dev_priv = drm_dev->dev_private;
Vincent Abriou871bcdf2015-07-31 11:32:13 +020086 struct drm_plane *cursor = NULL;
87 struct drm_plane *primary = NULL;
88 struct sti_compositor_subdev_descriptor *desc = compo->data.subdev_desc;
89 unsigned int array_size = compo->data.nb_subdev;
Benjamin Gaignardd2196732014-07-30 19:28:27 +020090
Vincent Abriou871bcdf2015-07-31 11:32:13 +020091 dev_priv->compo = compo;
92
93 /* Register mixer subdev and video subdev first */
Benjamin Gaignardd2196732014-07-30 19:28:27 +020094 for (i = 0; i < array_size; i++) {
95 switch (desc[i].type) {
Vincent Abriou871bcdf2015-07-31 11:32:13 +020096 case STI_VID_SUBDEV:
97 compo->vid[vid_id++] =
Vincent Abriou90dffef2016-02-04 16:58:45 +010098 sti_vid_create(compo->dev, drm_dev, desc[i].id,
Vincent Abriou871bcdf2015-07-31 11:32:13 +020099 compo->regs + desc[i].offset);
100 break;
Benjamin Gaignardd2196732014-07-30 19:28:27 +0200101 case STI_MIXER_MAIN_SUBDEV:
102 case STI_MIXER_AUX_SUBDEV:
103 compo->mixer[mixer_id++] =
Vincent Abrioua5f81072016-02-04 17:44:50 +0100104 sti_mixer_create(compo->dev, drm_dev, desc[i].id,
Benjamin Gaignardd2196732014-07-30 19:28:27 +0200105 compo->regs + desc[i].offset);
106 break;
107 case STI_GPD_SUBDEV:
Benjamin Gaignard96006a72014-12-11 13:34:42 +0100108 case STI_CURSOR_SUBDEV:
Vincent Abriou871bcdf2015-07-31 11:32:13 +0200109 /* Nothing to do, wait for the second round */
Benjamin Gaignardd2196732014-07-30 19:28:27 +0200110 break;
Benjamin Gaignardd2196732014-07-30 19:28:27 +0200111 default:
112 DRM_ERROR("Unknow subdev compoment type\n");
113 return 1;
114 }
Benjamin Gaignardd2196732014-07-30 19:28:27 +0200115 }
Benjamin Gaignardd2196732014-07-30 19:28:27 +0200116
Vincent Abriou871bcdf2015-07-31 11:32:13 +0200117 /* Register the other subdevs, create crtc and planes */
118 for (i = 0; i < array_size; i++) {
119 enum drm_plane_type plane_type = DRM_PLANE_TYPE_OVERLAY;
Benjamin Gaignardd2196732014-07-30 19:28:27 +0200120
Vincent Abriou871bcdf2015-07-31 11:32:13 +0200121 if (crtc_id < mixer_id)
122 plane_type = DRM_PLANE_TYPE_PRIMARY;
Benjamin Gaignard9bbf86f2014-07-31 09:39:11 +0200123
Vincent Abriou871bcdf2015-07-31 11:32:13 +0200124 switch (desc[i].type) {
125 case STI_MIXER_MAIN_SUBDEV:
126 case STI_MIXER_AUX_SUBDEV:
127 case STI_VID_SUBDEV:
128 /* Nothing to do, already done at the first round */
129 break;
130 case STI_CURSOR_SUBDEV:
Vincent Abriou29d1dc62015-08-03 14:22:16 +0200131 cursor = sti_cursor_create(drm_dev, compo->dev,
132 desc[i].id,
133 compo->regs + desc[i].offset,
134 1);
135 if (!cursor) {
Vincent Abriou871bcdf2015-07-31 11:32:13 +0200136 DRM_ERROR("Can't create CURSOR plane\n");
Dave Airlie8bb652e2014-08-05 09:41:42 +1000137 break;
Benjamin Gaignard9bbf86f2014-07-31 09:39:11 +0200138 }
Vincent Abriou871bcdf2015-07-31 11:32:13 +0200139 break;
140 case STI_GPD_SUBDEV:
Vincent Abriou29d1dc62015-08-03 14:22:16 +0200141 primary = sti_gdp_create(drm_dev, compo->dev,
142 desc[i].id,
143 compo->regs + desc[i].offset,
144 (1 << mixer_id) - 1,
145 plane_type);
146 if (!primary) {
Vincent Abriou871bcdf2015-07-31 11:32:13 +0200147 DRM_ERROR("Can't create GDP plane\n");
148 break;
Benjamin Gaignard9bbf86f2014-07-31 09:39:11 +0200149 }
Vincent Abriou871bcdf2015-07-31 11:32:13 +0200150 break;
151 default:
152 DRM_ERROR("Unknown subdev compoment type\n");
153 return 1;
154 }
155
156 /* The first planes are reserved for primary planes*/
157 if (crtc_id < mixer_id && primary) {
Vincent Abriou9e1f05b2015-07-31 11:32:34 +0200158 sti_crtc_init(drm_dev, compo->mixer[crtc_id],
159 primary, cursor);
Vincent Abriou871bcdf2015-07-31 11:32:13 +0200160 crtc_id++;
161 cursor = NULL;
162 primary = NULL;
Benjamin Gaignard9bbf86f2014-07-31 09:39:11 +0200163 }
164 }
Benjamin Gaignardd2196732014-07-30 19:28:27 +0200165
Vincent Abriou871bcdf2015-07-31 11:32:13 +0200166 drm_vblank_init(drm_dev, crtc_id);
Benjamin Gaignardd2196732014-07-30 19:28:27 +0200167 /* Allow usage of vblank without having to call drm_irq_install */
168 drm_dev->irq_enabled = 1;
169
Benjamin Gaignardd2196732014-07-30 19:28:27 +0200170 return 0;
171}
172
173static void sti_compositor_unbind(struct device *dev, struct device *master,
174 void *data)
175{
176 /* do nothing */
177}
178
179static const struct component_ops sti_compositor_ops = {
180 .bind = sti_compositor_bind,
181 .unbind = sti_compositor_unbind,
182};
183
184static const struct of_device_id compositor_of_match[] = {
185 {
186 .compatible = "st,stih416-compositor",
187 .data = &stih416_compositor_data,
188 }, {
189 .compatible = "st,stih407-compositor",
190 .data = &stih407_compositor_data,
191 }, {
192 /* end node */
193 }
194};
195MODULE_DEVICE_TABLE(of, compositor_of_match);
196
197static int sti_compositor_probe(struct platform_device *pdev)
198{
199 struct device *dev = &pdev->dev;
200 struct device_node *np = dev->of_node;
201 struct device_node *vtg_np;
202 struct sti_compositor *compo;
203 struct resource *res;
Benjamin Gaignardd2196732014-07-30 19:28:27 +0200204
205 compo = devm_kzalloc(dev, sizeof(*compo), GFP_KERNEL);
206 if (!compo) {
207 DRM_ERROR("Failed to allocate compositor context\n");
208 return -ENOMEM;
209 }
210 compo->dev = dev;
Vincent Abriou9e1f05b2015-07-31 11:32:34 +0200211 compo->vtg_vblank_nb.notifier_call = sti_crtc_vblank_cb;
Benjamin Gaignardd2196732014-07-30 19:28:27 +0200212
213 /* populate data structure depending on compatibility */
214 BUG_ON(!of_match_node(compositor_of_match, np)->data);
215
216 memcpy(&compo->data, of_match_node(compositor_of_match, np)->data,
217 sizeof(struct sti_compositor_data));
218
219 /* Get Memory ressources */
220 res = platform_get_resource(pdev, IORESOURCE_MEM, 0);
221 if (res == NULL) {
222 DRM_ERROR("Get memory resource failed\n");
223 return -ENXIO;
224 }
225 compo->regs = devm_ioremap(dev, res->start, resource_size(res));
226 if (compo->regs == NULL) {
227 DRM_ERROR("Register mapping failed\n");
228 return -ENXIO;
229 }
230
231 /* Get clock resources */
232 compo->clk_compo_main = devm_clk_get(dev, "compo_main");
233 if (IS_ERR(compo->clk_compo_main)) {
234 DRM_ERROR("Cannot get compo_main clock\n");
235 return PTR_ERR(compo->clk_compo_main);
236 }
237
238 compo->clk_compo_aux = devm_clk_get(dev, "compo_aux");
239 if (IS_ERR(compo->clk_compo_aux)) {
240 DRM_ERROR("Cannot get compo_aux clock\n");
241 return PTR_ERR(compo->clk_compo_aux);
242 }
243
244 compo->clk_pix_main = devm_clk_get(dev, "pix_main");
245 if (IS_ERR(compo->clk_pix_main)) {
246 DRM_ERROR("Cannot get pix_main clock\n");
247 return PTR_ERR(compo->clk_pix_main);
248 }
249
250 compo->clk_pix_aux = devm_clk_get(dev, "pix_aux");
251 if (IS_ERR(compo->clk_pix_aux)) {
252 DRM_ERROR("Cannot get pix_aux clock\n");
253 return PTR_ERR(compo->clk_pix_aux);
254 }
255
256 /* Get reset resources */
Lee Jonesc084c8d2016-07-25 11:09:33 +0100257 compo->rst_main = devm_reset_control_get_shared(dev, "compo-main");
Benjamin Gaignardd2196732014-07-30 19:28:27 +0200258 /* Take compo main out of reset */
259 if (!IS_ERR(compo->rst_main))
260 reset_control_deassert(compo->rst_main);
261
Lee Jonesc084c8d2016-07-25 11:09:33 +0100262 compo->rst_aux = devm_reset_control_get_shared(dev, "compo-aux");
Benjamin Gaignardd2196732014-07-30 19:28:27 +0200263 /* Take compo aux out of reset */
264 if (!IS_ERR(compo->rst_aux))
265 reset_control_deassert(compo->rst_aux);
266
267 vtg_np = of_parse_phandle(pdev->dev.of_node, "st,vtg", 0);
268 if (vtg_np)
269 compo->vtg_main = of_vtg_find(vtg_np);
Peter Chen9897f792016-07-05 10:04:49 +0800270 of_node_put(vtg_np);
Benjamin Gaignardd2196732014-07-30 19:28:27 +0200271
272 vtg_np = of_parse_phandle(pdev->dev.of_node, "st,vtg", 1);
273 if (vtg_np)
274 compo->vtg_aux = of_vtg_find(vtg_np);
Peter Chen9897f792016-07-05 10:04:49 +0800275 of_node_put(vtg_np);
Benjamin Gaignardd2196732014-07-30 19:28:27 +0200276
Benjamin Gaignardd2196732014-07-30 19:28:27 +0200277 platform_set_drvdata(pdev, compo);
278
279 return component_add(&pdev->dev, &sti_compositor_ops);
280}
281
282static int sti_compositor_remove(struct platform_device *pdev)
283{
284 component_del(&pdev->dev, &sti_compositor_ops);
285 return 0;
286}
287
Thierry Redingdcec16e2015-09-24 19:02:40 +0200288struct platform_driver sti_compositor_driver = {
Benjamin Gaignardd2196732014-07-30 19:28:27 +0200289 .driver = {
290 .name = "sti-compositor",
Benjamin Gaignardd2196732014-07-30 19:28:27 +0200291 .of_match_table = compositor_of_match,
292 },
293 .probe = sti_compositor_probe,
294 .remove = sti_compositor_remove,
295};
296
Benjamin Gaignardd2196732014-07-30 19:28:27 +0200297MODULE_AUTHOR("Benjamin Gaignard <benjamin.gaignard@st.com>");
298MODULE_DESCRIPTION("STMicroelectronics SoC DRM driver");
299MODULE_LICENSE("GPL");