2 * Copyright 2015 Freescale Semiconductor, Inc.
4 * Freescale DCU drm device driver
6 * This program is free software; you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License as published by
8 * the Free Software Foundation; either version 2 of the License, or
9 * (at your option) any later version.
12 #include <linux/backlight.h>
13 #include <linux/of_graph.h>
16 #include <drm/drm_atomic_helper.h>
17 #include <drm/drm_crtc_helper.h>
18 #include <drm/drm_of.h>
19 #include <drm/drm_panel.h>
21 #include "fsl_dcu_drm_drv.h"
24 static void fsl_dcu_drm_encoder_destroy(struct drm_encoder
*encoder
)
26 drm_encoder_cleanup(encoder
);
29 static const struct drm_encoder_funcs encoder_funcs
= {
30 .destroy
= fsl_dcu_drm_encoder_destroy
,
33 int fsl_dcu_drm_encoder_create(struct fsl_dcu_drm_device
*fsl_dev
,
34 struct drm_crtc
*crtc
)
36 struct drm_encoder
*encoder
= &fsl_dev
->encoder
;
39 encoder
->possible_crtcs
= 1;
41 /* Use bypass mode for parallel RGB/LVDS encoder */
43 fsl_tcon_bypass_enable(fsl_dev
->tcon
);
45 ret
= drm_encoder_init(fsl_dev
->drm
, encoder
, &encoder_funcs
,
46 DRM_MODE_ENCODER_LVDS
, NULL
);
53 static void fsl_dcu_drm_connector_destroy(struct drm_connector
*connector
)
55 struct fsl_dcu_drm_connector
*fsl_con
= to_fsl_dcu_connector(connector
);
57 drm_connector_unregister(connector
);
58 drm_panel_detach(fsl_con
->panel
);
59 drm_connector_cleanup(connector
);
62 static const struct drm_connector_funcs fsl_dcu_drm_connector_funcs
= {
63 .atomic_duplicate_state
= drm_atomic_helper_connector_duplicate_state
,
64 .atomic_destroy_state
= drm_atomic_helper_connector_destroy_state
,
65 .destroy
= fsl_dcu_drm_connector_destroy
,
66 .fill_modes
= drm_helper_probe_single_connector_modes
,
67 .reset
= drm_atomic_helper_connector_reset
,
70 static int fsl_dcu_drm_connector_get_modes(struct drm_connector
*connector
)
72 struct fsl_dcu_drm_connector
*fsl_connector
;
73 int (*get_modes
)(struct drm_panel
*panel
);
76 fsl_connector
= to_fsl_dcu_connector(connector
);
77 if (fsl_connector
->panel
&& fsl_connector
->panel
->funcs
&&
78 fsl_connector
->panel
->funcs
->get_modes
) {
79 get_modes
= fsl_connector
->panel
->funcs
->get_modes
;
80 num_modes
= get_modes(fsl_connector
->panel
);
86 static int fsl_dcu_drm_connector_mode_valid(struct drm_connector
*connector
,
87 struct drm_display_mode
*mode
)
89 if (mode
->hdisplay
& 0xf)
95 static const struct drm_connector_helper_funcs connector_helper_funcs
= {
96 .get_modes
= fsl_dcu_drm_connector_get_modes
,
97 .mode_valid
= fsl_dcu_drm_connector_mode_valid
,
100 static int fsl_dcu_attach_panel(struct fsl_dcu_drm_device
*fsl_dev
,
101 struct drm_panel
*panel
)
103 struct drm_encoder
*encoder
= &fsl_dev
->encoder
;
104 struct drm_connector
*connector
= &fsl_dev
->connector
.base
;
107 fsl_dev
->connector
.encoder
= encoder
;
109 ret
= drm_connector_init(fsl_dev
->drm
, connector
,
110 &fsl_dcu_drm_connector_funcs
,
111 DRM_MODE_CONNECTOR_LVDS
);
115 drm_connector_helper_add(connector
, &connector_helper_funcs
);
116 ret
= drm_connector_register(connector
);
120 ret
= drm_connector_attach_encoder(connector
, encoder
);
124 ret
= drm_panel_attach(panel
, connector
);
126 dev_err(fsl_dev
->dev
, "failed to attach panel\n");
133 drm_connector_unregister(connector
);
135 drm_connector_cleanup(connector
);
139 int fsl_dcu_create_outputs(struct fsl_dcu_drm_device
*fsl_dev
)
141 struct device_node
*panel_node
;
142 struct drm_panel
*panel
;
143 struct drm_bridge
*bridge
;
146 /* This is for backward compatibility */
147 panel_node
= of_parse_phandle(fsl_dev
->np
, "fsl,panel", 0);
149 fsl_dev
->connector
.panel
= of_drm_find_panel(panel_node
);
150 of_node_put(panel_node
);
151 if (IS_ERR(fsl_dev
->connector
.panel
))
152 return PTR_ERR(fsl_dev
->connector
.panel
);
154 return fsl_dcu_attach_panel(fsl_dev
, fsl_dev
->connector
.panel
);
157 ret
= drm_of_find_panel_or_bridge(fsl_dev
->np
, 0, 0, &panel
, &bridge
);
162 fsl_dev
->connector
.panel
= panel
;
163 return fsl_dcu_attach_panel(fsl_dev
, panel
);
166 return drm_bridge_attach(&fsl_dev
->encoder
, bridge
, NULL
);