1 // SPDX-License-Identifier: GPL-2.0-only
2 /*
3 * ARC PGU DRM driver.
4 *
5 * Copyright (C) 2016 Synopsys, Inc. (www.synopsys.com)
6 */
7
8 #include <drm/drm_bridge.h>
9 #include <drm/drm_crtc.h>
10 #include <drm/drm_encoder.h>
11 #include <drm/drm_device.h>
12
13 #include "arcpgu.h"
14
15 static struct drm_encoder_funcs arcpgu_drm_encoder_funcs = {
16 .destroy = drm_encoder_cleanup,
17 };
18
arcpgu_drm_hdmi_init(struct drm_device * drm,struct device_node * np)19 int arcpgu_drm_hdmi_init(struct drm_device *drm, struct device_node *np)
20 {
21 struct drm_encoder *encoder;
22 struct drm_bridge *bridge;
23
24 int ret = 0;
25
26 encoder = devm_kzalloc(drm->dev, sizeof(*encoder), GFP_KERNEL);
27 if (encoder == NULL)
28 return -ENOMEM;
29
30 /* Locate drm bridge from the hdmi encoder DT node */
31 bridge = of_drm_find_bridge(np);
32 if (!bridge)
33 return -EPROBE_DEFER;
34
35 encoder->possible_crtcs = 1;
36 encoder->possible_clones = 0;
37 ret = drm_encoder_init(drm, encoder, &arcpgu_drm_encoder_funcs,
38 DRM_MODE_ENCODER_TMDS, NULL);
39 if (ret)
40 return ret;
41
42 /* Link drm_bridge to encoder */
43 ret = drm_bridge_attach(encoder, bridge, NULL, 0);
44 if (ret)
45 drm_encoder_cleanup(encoder);
46
47 return ret;
48 }
49