1 // SPDX-License-Identifier: GPL-2.0-or-later
3 * Copyright 2015 Freescale Semiconductor, Inc.
5 * Freescale DCU drm device driver
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"
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
;
27 encoder
->possible_crtcs
= 1;
29 /* Use bypass mode for parallel RGB/LVDS encoder */
31 fsl_tcon_bypass_enable(fsl_dev
->tcon
);
33 ret
= drm_simple_encoder_init(fsl_dev
->drm
, encoder
,
34 DRM_MODE_ENCODER_LVDS
);
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)
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
;
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
);
92 drm_connector_helper_add(connector
, &connector_helper_funcs
);
93 ret
= drm_connector_register(connector
);
97 ret
= drm_connector_attach_encoder(connector
, encoder
);
104 drm_connector_unregister(connector
);
106 drm_connector_cleanup(connector
);
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
;
117 /* This is for backward compatibility */
118 panel_node
= of_parse_phandle(fsl_dev
->np
, "fsl,panel", 0);
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
);
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);