treewide: remove redundant IS_ERR() before error code check
[linux/fpc-iii.git] / drivers / gpu / drm / fsl-dcu / fsl_dcu_drm_rgb.c
blob9598ee3cc4d293422b37e32042eb08a69d2f0b0f
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>
17 #include "fsl_dcu_drm_drv.h"
18 #include "fsl_tcon.h"
20 static void fsl_dcu_drm_encoder_destroy(struct drm_encoder *encoder)
22 drm_encoder_cleanup(encoder);
25 static const struct drm_encoder_funcs encoder_funcs = {
26 .destroy = fsl_dcu_drm_encoder_destroy,
29 int fsl_dcu_drm_encoder_create(struct fsl_dcu_drm_device *fsl_dev,
30 struct drm_crtc *crtc)
32 struct drm_encoder *encoder = &fsl_dev->encoder;
33 int ret;
35 encoder->possible_crtcs = 1;
37 /* Use bypass mode for parallel RGB/LVDS encoder */
38 if (fsl_dev->tcon)
39 fsl_tcon_bypass_enable(fsl_dev->tcon);
41 ret = drm_encoder_init(fsl_dev->drm, encoder, &encoder_funcs,
42 DRM_MODE_ENCODER_LVDS, NULL);
43 if (ret < 0)
44 return ret;
46 return 0;
49 static void fsl_dcu_drm_connector_destroy(struct drm_connector *connector)
51 struct fsl_dcu_drm_connector *fsl_con = to_fsl_dcu_connector(connector);
53 drm_connector_unregister(connector);
54 drm_panel_detach(fsl_con->panel);
55 drm_connector_cleanup(connector);
58 static const struct drm_connector_funcs fsl_dcu_drm_connector_funcs = {
59 .atomic_duplicate_state = drm_atomic_helper_connector_duplicate_state,
60 .atomic_destroy_state = drm_atomic_helper_connector_destroy_state,
61 .destroy = fsl_dcu_drm_connector_destroy,
62 .fill_modes = drm_helper_probe_single_connector_modes,
63 .reset = drm_atomic_helper_connector_reset,
66 static int fsl_dcu_drm_connector_get_modes(struct drm_connector *connector)
68 struct fsl_dcu_drm_connector *fsl_connector;
70 fsl_connector = to_fsl_dcu_connector(connector);
71 return drm_panel_get_modes(fsl_connector->panel, connector);
74 static int fsl_dcu_drm_connector_mode_valid(struct drm_connector *connector,
75 struct drm_display_mode *mode)
77 if (mode->hdisplay & 0xf)
78 return MODE_ERROR;
80 return MODE_OK;
83 static const struct drm_connector_helper_funcs connector_helper_funcs = {
84 .get_modes = fsl_dcu_drm_connector_get_modes,
85 .mode_valid = fsl_dcu_drm_connector_mode_valid,
88 static int fsl_dcu_attach_panel(struct fsl_dcu_drm_device *fsl_dev,
89 struct drm_panel *panel)
91 struct drm_encoder *encoder = &fsl_dev->encoder;
92 struct drm_connector *connector = &fsl_dev->connector.base;
93 int ret;
95 fsl_dev->connector.encoder = encoder;
97 ret = drm_connector_init(fsl_dev->drm, connector,
98 &fsl_dcu_drm_connector_funcs,
99 DRM_MODE_CONNECTOR_LVDS);
100 if (ret < 0)
101 return ret;
103 drm_connector_helper_add(connector, &connector_helper_funcs);
104 ret = drm_connector_register(connector);
105 if (ret < 0)
106 goto err_cleanup;
108 ret = drm_connector_attach_encoder(connector, encoder);
109 if (ret < 0)
110 goto err_sysfs;
112 ret = drm_panel_attach(panel, connector);
113 if (ret) {
114 dev_err(fsl_dev->dev, "failed to attach panel\n");
115 goto err_sysfs;
118 return 0;
120 err_sysfs:
121 drm_connector_unregister(connector);
122 err_cleanup:
123 drm_connector_cleanup(connector);
124 return ret;
127 int fsl_dcu_create_outputs(struct fsl_dcu_drm_device *fsl_dev)
129 struct device_node *panel_node;
130 struct drm_panel *panel;
131 struct drm_bridge *bridge;
132 int ret;
134 /* This is for backward compatibility */
135 panel_node = of_parse_phandle(fsl_dev->np, "fsl,panel", 0);
136 if (panel_node) {
137 fsl_dev->connector.panel = of_drm_find_panel(panel_node);
138 of_node_put(panel_node);
139 if (IS_ERR(fsl_dev->connector.panel))
140 return PTR_ERR(fsl_dev->connector.panel);
142 return fsl_dcu_attach_panel(fsl_dev, fsl_dev->connector.panel);
145 ret = drm_of_find_panel_or_bridge(fsl_dev->np, 0, 0, &panel, &bridge);
146 if (ret)
147 return ret;
149 if (panel) {
150 fsl_dev->connector.panel = panel;
151 return fsl_dcu_attach_panel(fsl_dev, panel);
154 return drm_bridge_attach(&fsl_dev->encoder, bridge, NULL);