Merge tag 'block-5.11-2021-01-10' of git://git.kernel.dk/linux-block
[linux/fpc-iii.git] / drivers / gpu / drm / fsl-dcu / fsl_dcu_drm_rgb.c
blob4d4a715b429d1d4461b7a79debe829c940385655
1 // SPDX-License-Identifier: GPL-2.0-or-later
2 /*
3 * Copyright 2015 Freescale Semiconductor, Inc.
5 * Freescale DCU drm device driver
6 */
8 #include <linux/backlight.h>
9 #include <linux/of_graph.h>
11 #include <drm/drm_atomic_helper.h>
12 #include <drm/drm_bridge.h>
13 #include <drm/drm_of.h>
14 #include <drm/drm_panel.h>
15 #include <drm/drm_probe_helper.h>
16 #include <drm/drm_simple_kms_helper.h>
18 #include "fsl_dcu_drm_drv.h"
19 #include "fsl_tcon.h"
21 int fsl_dcu_drm_encoder_create(struct fsl_dcu_drm_device *fsl_dev,
22 struct drm_crtc *crtc)
24 struct drm_encoder *encoder = &fsl_dev->encoder;
25 int ret;
27 encoder->possible_crtcs = 1;
29 /* Use bypass mode for parallel RGB/LVDS encoder */
30 if (fsl_dev->tcon)
31 fsl_tcon_bypass_enable(fsl_dev->tcon);
33 ret = drm_simple_encoder_init(fsl_dev->drm, encoder,
34 DRM_MODE_ENCODER_LVDS);
35 if (ret < 0)
36 return ret;
38 return 0;
41 static void fsl_dcu_drm_connector_destroy(struct drm_connector *connector)
43 drm_connector_unregister(connector);
44 drm_connector_cleanup(connector);
47 static const struct drm_connector_funcs fsl_dcu_drm_connector_funcs = {
48 .atomic_duplicate_state = drm_atomic_helper_connector_duplicate_state,
49 .atomic_destroy_state = drm_atomic_helper_connector_destroy_state,
50 .destroy = fsl_dcu_drm_connector_destroy,
51 .fill_modes = drm_helper_probe_single_connector_modes,
52 .reset = drm_atomic_helper_connector_reset,
55 static int fsl_dcu_drm_connector_get_modes(struct drm_connector *connector)
57 struct fsl_dcu_drm_connector *fsl_connector;
59 fsl_connector = to_fsl_dcu_connector(connector);
60 return drm_panel_get_modes(fsl_connector->panel, connector);
63 static int fsl_dcu_drm_connector_mode_valid(struct drm_connector *connector,
64 struct drm_display_mode *mode)
66 if (mode->hdisplay & 0xf)
67 return MODE_ERROR;
69 return MODE_OK;
72 static const struct drm_connector_helper_funcs connector_helper_funcs = {
73 .get_modes = fsl_dcu_drm_connector_get_modes,
74 .mode_valid = fsl_dcu_drm_connector_mode_valid,
77 static int fsl_dcu_attach_panel(struct fsl_dcu_drm_device *fsl_dev,
78 struct drm_panel *panel)
80 struct drm_encoder *encoder = &fsl_dev->encoder;
81 struct drm_connector *connector = &fsl_dev->connector.base;
82 int ret;
84 fsl_dev->connector.encoder = encoder;
86 ret = drm_connector_init(fsl_dev->drm, connector,
87 &fsl_dcu_drm_connector_funcs,
88 DRM_MODE_CONNECTOR_LVDS);
89 if (ret < 0)
90 return ret;
92 drm_connector_helper_add(connector, &connector_helper_funcs);
93 ret = drm_connector_register(connector);
94 if (ret < 0)
95 goto err_cleanup;
97 ret = drm_connector_attach_encoder(connector, encoder);
98 if (ret < 0)
99 goto err_sysfs;
101 return 0;
103 err_sysfs:
104 drm_connector_unregister(connector);
105 err_cleanup:
106 drm_connector_cleanup(connector);
107 return ret;
110 int fsl_dcu_create_outputs(struct fsl_dcu_drm_device *fsl_dev)
112 struct device_node *panel_node;
113 struct drm_panel *panel;
114 struct drm_bridge *bridge;
115 int ret;
117 /* This is for backward compatibility */
118 panel_node = of_parse_phandle(fsl_dev->np, "fsl,panel", 0);
119 if (panel_node) {
120 fsl_dev->connector.panel = of_drm_find_panel(panel_node);
121 of_node_put(panel_node);
122 if (IS_ERR(fsl_dev->connector.panel))
123 return PTR_ERR(fsl_dev->connector.panel);
125 return fsl_dcu_attach_panel(fsl_dev, fsl_dev->connector.panel);
128 ret = drm_of_find_panel_or_bridge(fsl_dev->np, 0, 0, &panel, &bridge);
129 if (ret)
130 return ret;
132 if (panel) {
133 fsl_dev->connector.panel = panel;
134 return fsl_dcu_attach_panel(fsl_dev, panel);
137 return drm_bridge_attach(&fsl_dev->encoder, bridge, NULL, 0);