brcm2708: update linux 4.4 patches to latest version
[openwrt/openwrt.git] / target / linux / brcm2708 / patches-4.4 / 0331-drm-vc4-Add-DPI-driver.patch
1 From fe826daeea975dcf3ce3fca6e8a0850e5761f602 Mon Sep 17 00:00:00 2001
2 From: Eric Anholt <eric@anholt.net>
3 Date: Wed, 10 Feb 2016 11:42:32 -0800
4 Subject: [PATCH] drm/vc4: Add DPI driver
5
6 The DPI interface involves taking a ton of our GPIOs to be used as
7 outputs, and routing display signals over them in parallel.
8
9 v2: Use display_info.bus_formats[] to replace our custom DT
10 properties.
11 v3: Rebase on V3D documentation changes.
12 v4: Fix rebase detritus from V3D documentation changes.
13
14 Signed-off-by: Eric Anholt <eric@anholt.net>
15 Acked-by: Rob Herring <robh@kernel.org>
16 (cherry picked from commit 08302c35b59d306ff37b996e56fb2a488c1d2c2e)
17 ---
18 .../devicetree/bindings/display/brcm,bcm-vc4.txt | 36 ++
19 drivers/gpu/drm/vc4/Kconfig | 1 +
20 drivers/gpu/drm/vc4/Makefile | 1 +
21 drivers/gpu/drm/vc4/vc4_debugfs.c | 1 +
22 drivers/gpu/drm/vc4/vc4_dpi.c | 520 +++++++++++++++++++++
23 drivers/gpu/drm/vc4/vc4_drv.c | 1 +
24 drivers/gpu/drm/vc4/vc4_drv.h | 5 +
25 7 files changed, 565 insertions(+)
26 create mode 100644 drivers/gpu/drm/vc4/vc4_dpi.c
27
28 --- a/Documentation/devicetree/bindings/display/brcm,bcm-vc4.txt
29 +++ b/Documentation/devicetree/bindings/display/brcm,bcm-vc4.txt
30 @@ -35,12 +35,22 @@ Optional properties for HDMI:
31 as an interrupt/status bit in the HDMI controller
32 itself). See bindings/pinctrl/brcm,bcm2835-gpio.txt
33
34 +Required properties for DPI:
35 +- compatible: Should be "brcm,bcm2835-dpi"
36 +- reg: Physical base address and length of the registers
37 +- clocks: a) core: The core clock the unit runs on
38 + b) pixel: The pixel clock that feeds the pixelvalve
39 +- port: Port node with a single endpoint connecting to the panel
40 + device, as defined in [1]
41 +
42 Required properties for V3D:
43 - compatible: Should be "brcm,bcm2835-v3d"
44 - reg: Physical base address and length of the V3D's registers
45 - interrupts: The interrupt number
46 See bindings/interrupt-controller/brcm,bcm2835-armctrl-ic.txt
47
48 +[1] Documentation/devicetree/bindings/media/video-interfaces.txt
49 +
50 Example:
51 pixelvalve@7e807000 {
52 compatible = "brcm,bcm2835-pixelvalve2";
53 @@ -66,6 +76,22 @@ hdmi: hdmi@7e902000 {
54 clock-names = "pixel", "hdmi";
55 };
56
57 +dpi: dpi@7e208000 {
58 + compatible = "brcm,bcm2835-dpi";
59 + reg = <0x7e208000 0x8c>;
60 + clocks = <&clocks BCM2835_CLOCK_VPU>,
61 + <&clocks BCM2835_CLOCK_DPI>;
62 + clock-names = "core", "pixel";
63 + #address-cells = <1>;
64 + #size-cells = <0>;
65 +
66 + port {
67 + dpi_out: endpoint@0 {
68 + remote-endpoint = <&panel_in>;
69 + };
70 + };
71 +};
72 +
73 v3d: v3d@7ec00000 {
74 compatible = "brcm,bcm2835-v3d";
75 reg = <0x7ec00000 0x1000>;
76 @@ -75,3 +101,13 @@ v3d: v3d@7ec00000 {
77 vc4: gpu {
78 compatible = "brcm,bcm2835-vc4";
79 };
80 +
81 +panel: panel {
82 + compatible = "ontat,yx700wv03", "simple-panel";
83 +
84 + port {
85 + panel_in: endpoint {
86 + remote-endpoint = <&dpi_out>;
87 + };
88 + };
89 +};
90 --- a/drivers/gpu/drm/vc4/Kconfig
91 +++ b/drivers/gpu/drm/vc4/Kconfig
92 @@ -5,6 +5,7 @@ config DRM_VC4
93 select DRM_KMS_HELPER
94 select DRM_KMS_CMA_HELPER
95 select DRM_GEM_CMA_HELPER
96 + select DRM_PANEL
97 help
98 Choose this option if you have a system that has a Broadcom
99 VC4 GPU, such as the Raspberry Pi or other BCM2708/BCM2835.
100 --- a/drivers/gpu/drm/vc4/Makefile
101 +++ b/drivers/gpu/drm/vc4/Makefile
102 @@ -7,6 +7,7 @@ vc4-y := \
103 vc4_bo.o \
104 vc4_crtc.o \
105 vc4_drv.o \
106 + vc4_dpi.o \
107 vc4_kms.o \
108 vc4_gem.o \
109 vc4_hdmi.o \
110 --- a/drivers/gpu/drm/vc4/vc4_debugfs.c
111 +++ b/drivers/gpu/drm/vc4/vc4_debugfs.c
112 @@ -17,6 +17,7 @@
113
114 static const struct drm_info_list vc4_debugfs_list[] = {
115 {"bo_stats", vc4_bo_stats_debugfs, 0},
116 + {"dpi_regs", vc4_dpi_debugfs_regs, 0},
117 {"gem_exec", vc4_gem_exec_debugfs, 0},
118 {"hdmi_regs", vc4_hdmi_debugfs_regs, 0},
119 {"hvs_regs", vc4_hvs_debugfs_regs, 0},
120 --- /dev/null
121 +++ b/drivers/gpu/drm/vc4/vc4_dpi.c
122 @@ -0,0 +1,520 @@
123 +/*
124 + * Copyright (C) 2016 Broadcom Limited
125 + *
126 + * This program is free software; you can redistribute it and/or modify it
127 + * under the terms of the GNU General Public License version 2 as published by
128 + * the Free Software Foundation.
129 + *
130 + * This program is distributed in the hope that it will be useful, but WITHOUT
131 + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
132 + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
133 + * more details.
134 + *
135 + * You should have received a copy of the GNU General Public License along with
136 + * this program. If not, see <http://www.gnu.org/licenses/>.
137 + */
138 +
139 +/**
140 + * DOC: VC4 DPI module
141 + *
142 + * The VC4 DPI hardware supports MIPI DPI type 4 and Nokia ViSSI
143 + * signals, which are routed out to GPIO0-27 with the ALT2 function.
144 + */
145 +
146 +#include "drm_atomic_helper.h"
147 +#include "drm_crtc_helper.h"
148 +#include "drm_edid.h"
149 +#include "drm_panel.h"
150 +#include "linux/clk.h"
151 +#include "linux/component.h"
152 +#include "linux/of_graph.h"
153 +#include "linux/of_platform.h"
154 +#include "vc4_drv.h"
155 +#include "vc4_regs.h"
156 +
157 +#define DPI_C 0x00
158 +# define DPI_OUTPUT_ENABLE_MODE BIT(16)
159 +
160 +/* The order field takes the incoming 24 bit RGB from the pixel valve
161 + * and shuffles the 3 channels.
162 + */
163 +# define DPI_ORDER_MASK VC4_MASK(15, 14)
164 +# define DPI_ORDER_SHIFT 14
165 +# define DPI_ORDER_RGB 0
166 +# define DPI_ORDER_BGR 1
167 +# define DPI_ORDER_GRB 2
168 +# define DPI_ORDER_BRG 3
169 +
170 +/* The format field takes the ORDER-shuffled pixel valve data and
171 + * formats it onto the output lines.
172 + */
173 +# define DPI_FORMAT_MASK VC4_MASK(13, 11)
174 +# define DPI_FORMAT_SHIFT 11
175 +/* This define is named in the hardware, but actually just outputs 0. */
176 +# define DPI_FORMAT_9BIT_666_RGB 0
177 +/* Outputs 00000000rrrrrggggggbbbbb */
178 +# define DPI_FORMAT_16BIT_565_RGB_1 1
179 +/* Outputs 000rrrrr00gggggg000bbbbb */
180 +# define DPI_FORMAT_16BIT_565_RGB_2 2
181 +/* Outputs 00rrrrr000gggggg00bbbbb0 */
182 +# define DPI_FORMAT_16BIT_565_RGB_3 3
183 +/* Outputs 000000rrrrrrggggggbbbbbb */
184 +# define DPI_FORMAT_18BIT_666_RGB_1 4
185 +/* Outputs 00rrrrrr00gggggg00bbbbbb */
186 +# define DPI_FORMAT_18BIT_666_RGB_2 5
187 +/* Outputs rrrrrrrrggggggggbbbbbbbb */
188 +# define DPI_FORMAT_24BIT_888_RGB 6
189 +
190 +/* Reverses the polarity of the corresponding signal */
191 +# define DPI_PIXEL_CLK_INVERT BIT(10)
192 +# define DPI_HSYNC_INVERT BIT(9)
193 +# define DPI_VSYNC_INVERT BIT(8)
194 +# define DPI_OUTPUT_ENABLE_INVERT BIT(7)
195 +
196 +/* Outputs the signal the falling clock edge instead of rising. */
197 +# define DPI_HSYNC_NEGATE BIT(6)
198 +# define DPI_VSYNC_NEGATE BIT(5)
199 +# define DPI_OUTPUT_ENABLE_NEGATE BIT(4)
200 +
201 +/* Disables the signal */
202 +# define DPI_HSYNC_DISABLE BIT(3)
203 +# define DPI_VSYNC_DISABLE BIT(2)
204 +# define DPI_OUTPUT_ENABLE_DISABLE BIT(1)
205 +
206 +/* Power gate to the device, full reset at 0 -> 1 transition */
207 +# define DPI_ENABLE BIT(0)
208 +
209 +/* All other registers besides DPI_C return the ID */
210 +#define DPI_ID 0x04
211 +# define DPI_ID_VALUE 0x00647069
212 +
213 +/* General DPI hardware state. */
214 +struct vc4_dpi {
215 + struct platform_device *pdev;
216 +
217 + struct drm_encoder *encoder;
218 + struct drm_connector *connector;
219 + struct drm_panel *panel;
220 +
221 + void __iomem *regs;
222 +
223 + struct clk *pixel_clock;
224 + struct clk *core_clock;
225 +};
226 +
227 +#define DPI_READ(offset) readl(dpi->regs + (offset))
228 +#define DPI_WRITE(offset, val) writel(val, dpi->regs + (offset))
229 +
230 +/* VC4 DPI encoder KMS struct */
231 +struct vc4_dpi_encoder {
232 + struct vc4_encoder base;
233 + struct vc4_dpi *dpi;
234 +};
235 +
236 +static inline struct vc4_dpi_encoder *
237 +to_vc4_dpi_encoder(struct drm_encoder *encoder)
238 +{
239 + return container_of(encoder, struct vc4_dpi_encoder, base.base);
240 +}
241 +
242 +/* VC4 DPI connector KMS struct */
243 +struct vc4_dpi_connector {
244 + struct drm_connector base;
245 + struct vc4_dpi *dpi;
246 +
247 + /* Since the connector is attached to just the one encoder,
248 + * this is the reference to it so we can do the best_encoder()
249 + * hook.
250 + */
251 + struct drm_encoder *encoder;
252 +};
253 +
254 +static inline struct vc4_dpi_connector *
255 +to_vc4_dpi_connector(struct drm_connector *connector)
256 +{
257 + return container_of(connector, struct vc4_dpi_connector, base);
258 +}
259 +
260 +#define DPI_REG(reg) { reg, #reg }
261 +static const struct {
262 + u32 reg;
263 + const char *name;
264 +} dpi_regs[] = {
265 + DPI_REG(DPI_C),
266 + DPI_REG(DPI_ID),
267 +};
268 +
269 +static void vc4_dpi_dump_regs(struct vc4_dpi *dpi)
270 +{
271 + int i;
272 +
273 + for (i = 0; i < ARRAY_SIZE(dpi_regs); i++) {
274 + DRM_INFO("0x%04x (%s): 0x%08x\n",
275 + dpi_regs[i].reg, dpi_regs[i].name,
276 + DPI_READ(dpi_regs[i].reg));
277 + }
278 +}
279 +
280 +#ifdef CONFIG_DEBUG_FS
281 +int vc4_dpi_debugfs_regs(struct seq_file *m, void *unused)
282 +{
283 + struct drm_info_node *node = (struct drm_info_node *)m->private;
284 + struct drm_device *dev = node->minor->dev;
285 + struct vc4_dev *vc4 = to_vc4_dev(dev);
286 + struct vc4_dpi *dpi = vc4->dpi;
287 + int i;
288 +
289 + if (!dpi)
290 + return 0;
291 +
292 + for (i = 0; i < ARRAY_SIZE(dpi_regs); i++) {
293 + seq_printf(m, "%s (0x%04x): 0x%08x\n",
294 + dpi_regs[i].name, dpi_regs[i].reg,
295 + DPI_READ(dpi_regs[i].reg));
296 + }
297 +
298 + return 0;
299 +}
300 +#endif
301 +
302 +static enum drm_connector_status
303 +vc4_dpi_connector_detect(struct drm_connector *connector, bool force)
304 +{
305 + struct vc4_dpi_connector *vc4_connector =
306 + to_vc4_dpi_connector(connector);
307 + struct vc4_dpi *dpi = vc4_connector->dpi;
308 +
309 + if (dpi->panel)
310 + return connector_status_connected;
311 + else
312 + return connector_status_disconnected;
313 +}
314 +
315 +static void vc4_dpi_connector_destroy(struct drm_connector *connector)
316 +{
317 + drm_connector_unregister(connector);
318 + drm_connector_cleanup(connector);
319 +}
320 +
321 +static int vc4_dpi_connector_get_modes(struct drm_connector *connector)
322 +{
323 + struct vc4_dpi_connector *vc4_connector =
324 + to_vc4_dpi_connector(connector);
325 + struct vc4_dpi *dpi = vc4_connector->dpi;
326 +
327 + if (dpi->panel)
328 + return drm_panel_get_modes(dpi->panel);
329 +
330 + return 0;
331 +}
332 +
333 +static struct drm_encoder *
334 +vc4_dpi_connector_best_encoder(struct drm_connector *connector)
335 +{
336 + struct vc4_dpi_connector *dpi_connector =
337 + to_vc4_dpi_connector(connector);
338 + return dpi_connector->encoder;
339 +}
340 +
341 +static const struct drm_connector_funcs vc4_dpi_connector_funcs = {
342 + .dpms = drm_atomic_helper_connector_dpms,
343 + .detect = vc4_dpi_connector_detect,
344 + .fill_modes = drm_helper_probe_single_connector_modes,
345 + .destroy = vc4_dpi_connector_destroy,
346 + .reset = drm_atomic_helper_connector_reset,
347 + .atomic_duplicate_state = drm_atomic_helper_connector_duplicate_state,
348 + .atomic_destroy_state = drm_atomic_helper_connector_destroy_state,
349 +};
350 +
351 +static const struct drm_connector_helper_funcs vc4_dpi_connector_helper_funcs = {
352 + .get_modes = vc4_dpi_connector_get_modes,
353 + .best_encoder = vc4_dpi_connector_best_encoder,
354 +};
355 +
356 +static struct drm_connector *vc4_dpi_connector_init(struct drm_device *dev,
357 + struct vc4_dpi *dpi)
358 +{
359 + struct drm_connector *connector = NULL;
360 + struct vc4_dpi_connector *dpi_connector;
361 + int ret = 0;
362 +
363 + dpi_connector = devm_kzalloc(dev->dev, sizeof(*dpi_connector),
364 + GFP_KERNEL);
365 + if (!dpi_connector) {
366 + ret = -ENOMEM;
367 + goto fail;
368 + }
369 + connector = &dpi_connector->base;
370 +
371 + dpi_connector->encoder = dpi->encoder;
372 + dpi_connector->dpi = dpi;
373 +
374 + drm_connector_init(dev, connector, &vc4_dpi_connector_funcs,
375 + DRM_MODE_CONNECTOR_DPI);
376 + drm_connector_helper_add(connector, &vc4_dpi_connector_helper_funcs);
377 +
378 + connector->polled = 0;
379 + connector->interlace_allowed = 0;
380 + connector->doublescan_allowed = 0;
381 +
382 + drm_mode_connector_attach_encoder(connector, dpi->encoder);
383 +
384 + return connector;
385 +
386 + fail:
387 + if (connector)
388 + vc4_dpi_connector_destroy(connector);
389 +
390 + return ERR_PTR(ret);
391 +}
392 +
393 +static const struct drm_encoder_funcs vc4_dpi_encoder_funcs = {
394 + .destroy = drm_encoder_cleanup,
395 +};
396 +
397 +static void vc4_dpi_encoder_disable(struct drm_encoder *encoder)
398 +{
399 + struct vc4_dpi_encoder *vc4_encoder = to_vc4_dpi_encoder(encoder);
400 + struct vc4_dpi *dpi = vc4_encoder->dpi;
401 +
402 + drm_panel_disable(dpi->panel);
403 +
404 + clk_disable_unprepare(dpi->pixel_clock);
405 +
406 + drm_panel_unprepare(dpi->panel);
407 +}
408 +
409 +static void vc4_dpi_encoder_enable(struct drm_encoder *encoder)
410 +{
411 + struct drm_display_mode *mode = &encoder->crtc->mode;
412 + struct vc4_dpi_encoder *vc4_encoder = to_vc4_dpi_encoder(encoder);
413 + struct vc4_dpi *dpi = vc4_encoder->dpi;
414 + u32 dpi_c = DPI_ENABLE | DPI_OUTPUT_ENABLE_MODE;
415 + int ret;
416 +
417 + ret = drm_panel_prepare(dpi->panel);
418 + if (ret) {
419 + DRM_ERROR("Panel failed to prepare\n");
420 + return;
421 + }
422 +
423 + if (dpi->connector->display_info.num_bus_formats) {
424 + u32 bus_format = dpi->connector->display_info.bus_formats[0];
425 +
426 + switch (bus_format) {
427 + case MEDIA_BUS_FMT_RGB888_1X24:
428 + dpi_c |= VC4_SET_FIELD(DPI_FORMAT_24BIT_888_RGB,
429 + DPI_FORMAT);
430 + break;
431 + case MEDIA_BUS_FMT_BGR888_1X24:
432 + dpi_c |= VC4_SET_FIELD(DPI_FORMAT_24BIT_888_RGB,
433 + DPI_FORMAT);
434 + dpi_c |= VC4_SET_FIELD(DPI_ORDER_BGR, DPI_ORDER);
435 + break;
436 + case MEDIA_BUS_FMT_RGB666_1X24_CPADHI:
437 + dpi_c |= VC4_SET_FIELD(DPI_FORMAT_18BIT_666_RGB_2,
438 + DPI_FORMAT);
439 + break;
440 + case MEDIA_BUS_FMT_RGB666_1X18:
441 + dpi_c |= VC4_SET_FIELD(DPI_FORMAT_18BIT_666_RGB_1,
442 + DPI_FORMAT);
443 + break;
444 + case MEDIA_BUS_FMT_RGB565_1X16:
445 + dpi_c |= VC4_SET_FIELD(DPI_FORMAT_16BIT_565_RGB_3,
446 + DPI_FORMAT);
447 + break;
448 + default:
449 + DRM_ERROR("Unknown media bus format %d\n", bus_format);
450 + break;
451 + }
452 + }
453 +
454 + if (mode->flags & DRM_MODE_FLAG_NHSYNC)
455 + dpi_c |= DPI_HSYNC_INVERT;
456 + else if (!(mode->flags & DRM_MODE_FLAG_PHSYNC))
457 + dpi_c |= DPI_HSYNC_DISABLE;
458 +
459 + if (mode->flags & DRM_MODE_FLAG_NVSYNC)
460 + dpi_c |= DPI_VSYNC_INVERT;
461 + else if (!(mode->flags & DRM_MODE_FLAG_PVSYNC))
462 + dpi_c |= DPI_VSYNC_DISABLE;
463 +
464 + DPI_WRITE(DPI_C, dpi_c);
465 +
466 + ret = clk_set_rate(dpi->pixel_clock, mode->clock * 1000);
467 + if (ret)
468 + DRM_ERROR("Failed to set clock rate: %d\n", ret);
469 +
470 + ret = clk_prepare_enable(dpi->pixel_clock);
471 + if (ret)
472 + DRM_ERROR("Failed to set clock rate: %d\n", ret);
473 +
474 + ret = drm_panel_enable(dpi->panel);
475 + if (ret) {
476 + DRM_ERROR("Panel failed to enable\n");
477 + drm_panel_unprepare(dpi->panel);
478 + return;
479 + }
480 +}
481 +
482 +static const struct drm_encoder_helper_funcs vc4_dpi_encoder_helper_funcs = {
483 + .disable = vc4_dpi_encoder_disable,
484 + .enable = vc4_dpi_encoder_enable,
485 +};
486 +
487 +static const struct of_device_id vc4_dpi_dt_match[] = {
488 + { .compatible = "brcm,bcm2835-dpi", .data = NULL },
489 + {}
490 +};
491 +
492 +/* Walks the OF graph to find the panel node and then asks DRM to look
493 + * up the panel.
494 + */
495 +static struct drm_panel *vc4_dpi_get_panel(struct device *dev)
496 +{
497 + struct device_node *endpoint, *panel_node;
498 + struct device_node *np = dev->of_node;
499 + struct drm_panel *panel;
500 +
501 + endpoint = of_graph_get_next_endpoint(np, NULL);
502 + if (!endpoint) {
503 + dev_err(dev, "no endpoint to fetch DPI panel\n");
504 + return NULL;
505 + }
506 +
507 + /* don't proceed if we have an endpoint but no panel_node tied to it */
508 + panel_node = of_graph_get_remote_port_parent(endpoint);
509 + of_node_put(endpoint);
510 + if (!panel_node) {
511 + dev_err(dev, "no valid panel node\n");
512 + return NULL;
513 + }
514 +
515 + panel = of_drm_find_panel(panel_node);
516 + of_node_put(panel_node);
517 +
518 + return panel;
519 +}
520 +
521 +static int vc4_dpi_bind(struct device *dev, struct device *master, void *data)
522 +{
523 + struct platform_device *pdev = to_platform_device(dev);
524 + struct drm_device *drm = dev_get_drvdata(master);
525 + struct vc4_dev *vc4 = to_vc4_dev(drm);
526 + struct vc4_dpi *dpi;
527 + struct vc4_dpi_encoder *vc4_dpi_encoder;
528 + int ret;
529 +
530 + dpi = devm_kzalloc(dev, sizeof(*dpi), GFP_KERNEL);
531 + if (!dpi)
532 + return -ENOMEM;
533 +
534 + vc4_dpi_encoder = devm_kzalloc(dev, sizeof(*vc4_dpi_encoder),
535 + GFP_KERNEL);
536 + if (!vc4_dpi_encoder)
537 + return -ENOMEM;
538 + vc4_dpi_encoder->base.type = VC4_ENCODER_TYPE_DPI;
539 + vc4_dpi_encoder->dpi = dpi;
540 + dpi->encoder = &vc4_dpi_encoder->base.base;
541 +
542 + dpi->pdev = pdev;
543 + dpi->regs = vc4_ioremap_regs(pdev, 0);
544 + if (IS_ERR(dpi->regs))
545 + return PTR_ERR(dpi->regs);
546 +
547 + vc4_dpi_dump_regs(dpi);
548 +
549 + if (DPI_READ(DPI_ID) != DPI_ID_VALUE) {
550 + dev_err(dev, "Port returned 0x%08x for ID instead of 0x%08x\n",
551 + DPI_READ(DPI_ID), DPI_ID_VALUE);
552 + return -ENODEV;
553 + }
554 +
555 + dpi->core_clock = devm_clk_get(dev, "core");
556 + if (IS_ERR(dpi->core_clock)) {
557 + ret = PTR_ERR(dpi->core_clock);
558 + if (ret != -EPROBE_DEFER)
559 + DRM_ERROR("Failed to get core clock: %d\n", ret);
560 + return ret;
561 + }
562 + dpi->pixel_clock = devm_clk_get(dev, "pixel");
563 + if (IS_ERR(dpi->pixel_clock)) {
564 + ret = PTR_ERR(dpi->pixel_clock);
565 + if (ret != -EPROBE_DEFER)
566 + DRM_ERROR("Failed to get pixel clock: %d\n", ret);
567 + return ret;
568 + }
569 +
570 + ret = clk_prepare_enable(dpi->core_clock);
571 + if (ret)
572 + DRM_ERROR("Failed to turn on core clock: %d\n", ret);
573 +
574 + dpi->panel = vc4_dpi_get_panel(dev);
575 +
576 + drm_encoder_init(drm, dpi->encoder, &vc4_dpi_encoder_funcs,
577 + DRM_MODE_ENCODER_DPI);
578 + drm_encoder_helper_add(dpi->encoder, &vc4_dpi_encoder_helper_funcs);
579 +
580 + dpi->connector = vc4_dpi_connector_init(drm, dpi);
581 + if (IS_ERR(dpi->connector)) {
582 + ret = PTR_ERR(dpi->connector);
583 + goto err_destroy_encoder;
584 + }
585 +
586 + if (dpi->panel)
587 + drm_panel_attach(dpi->panel, dpi->connector);
588 +
589 + dev_set_drvdata(dev, dpi);
590 +
591 + vc4->dpi = dpi;
592 +
593 + return 0;
594 +
595 +err_destroy_encoder:
596 + drm_encoder_cleanup(dpi->encoder);
597 + clk_disable_unprepare(dpi->core_clock);
598 + return ret;
599 +}
600 +
601 +static void vc4_dpi_unbind(struct device *dev, struct device *master,
602 + void *data)
603 +{
604 + struct drm_device *drm = dev_get_drvdata(master);
605 + struct vc4_dev *vc4 = to_vc4_dev(drm);
606 + struct vc4_dpi *dpi = dev_get_drvdata(dev);
607 +
608 + if (dpi->panel)
609 + drm_panel_detach(dpi->panel);
610 +
611 + vc4_dpi_connector_destroy(dpi->connector);
612 + drm_encoder_cleanup(dpi->encoder);
613 +
614 + clk_disable_unprepare(dpi->core_clock);
615 +
616 + vc4->dpi = NULL;
617 +}
618 +
619 +static const struct component_ops vc4_dpi_ops = {
620 + .bind = vc4_dpi_bind,
621 + .unbind = vc4_dpi_unbind,
622 +};
623 +
624 +static int vc4_dpi_dev_probe(struct platform_device *pdev)
625 +{
626 + return component_add(&pdev->dev, &vc4_dpi_ops);
627 +}
628 +
629 +static int vc4_dpi_dev_remove(struct platform_device *pdev)
630 +{
631 + component_del(&pdev->dev, &vc4_dpi_ops);
632 + return 0;
633 +}
634 +
635 +struct platform_driver vc4_dpi_driver = {
636 + .probe = vc4_dpi_dev_probe,
637 + .remove = vc4_dpi_dev_remove,
638 + .driver = {
639 + .name = "vc4_dpi",
640 + .of_match_table = vc4_dpi_dt_match,
641 + },
642 +};
643 --- a/drivers/gpu/drm/vc4/vc4_drv.c
644 +++ b/drivers/gpu/drm/vc4/vc4_drv.c
645 @@ -259,6 +259,7 @@ static const struct component_master_ops
646
647 static struct platform_driver *const component_drivers[] = {
648 &vc4_hdmi_driver,
649 + &vc4_dpi_driver,
650 &vc4_crtc_driver,
651 &vc4_hvs_driver,
652 &vc4_v3d_driver,
653 --- a/drivers/gpu/drm/vc4/vc4_drv.h
654 +++ b/drivers/gpu/drm/vc4/vc4_drv.h
655 @@ -16,6 +16,7 @@ struct vc4_dev {
656 struct vc4_hvs *hvs;
657 struct vc4_crtc *crtc[3];
658 struct vc4_v3d *v3d;
659 + struct vc4_dpi *dpi;
660
661 struct drm_fbdev_cma *fbdev;
662 struct rpi_firmware *firmware;
663 @@ -418,6 +419,10 @@ void vc4_debugfs_cleanup(struct drm_mino
664 /* vc4_drv.c */
665 void __iomem *vc4_ioremap_regs(struct platform_device *dev, int index);
666
667 +/* vc4_dpi.c */
668 +extern struct platform_driver vc4_dpi_driver;
669 +int vc4_dpi_debugfs_regs(struct seq_file *m, void *unused);
670 +
671 /* vc4_gem.c */
672 void vc4_gem_init(struct drm_device *dev);
673 void vc4_gem_destroy(struct drm_device *dev);