1
2
3
4
5
6
7
8
9
10
11
12
13
14#include <linux/of_graph.h>
15
16#include <drm/drm_atomic.h>
17#include <drm/drm_atomic_helper.h>
18#include <drm/drm_crtc.h>
19#include <drm/drm_crtc_helper.h>
20#include <drm/drm_fb_cma_helper.h>
21#include <drm/drm_gem_cma_helper.h>
22#include <drm/drm_of.h>
23#include <drm/drm_panel.h>
24#include <drm/drm_plane_helper.h>
25#include <drm/drm_simple_kms_helper.h>
26#include <drm/drmP.h>
27
28#include "mxsfb_drv.h"
29
30static struct mxsfb_drm_private *
31drm_connector_to_mxsfb_drm_private(struct drm_connector *connector)
32{
33 return container_of(connector, struct mxsfb_drm_private, connector);
34}
35
36static int mxsfb_panel_get_modes(struct drm_connector *connector)
37{
38 struct mxsfb_drm_private *mxsfb =
39 drm_connector_to_mxsfb_drm_private(connector);
40
41 if (mxsfb->panel)
42 return mxsfb->panel->funcs->get_modes(mxsfb->panel);
43
44 return 0;
45}
46
47static const struct
48drm_connector_helper_funcs mxsfb_panel_connector_helper_funcs = {
49 .get_modes = mxsfb_panel_get_modes,
50};
51
52static enum drm_connector_status
53mxsfb_panel_connector_detect(struct drm_connector *connector, bool force)
54{
55 struct mxsfb_drm_private *mxsfb =
56 drm_connector_to_mxsfb_drm_private(connector);
57
58 if (mxsfb->panel)
59 return connector_status_connected;
60
61 return connector_status_disconnected;
62}
63
64static void mxsfb_panel_connector_destroy(struct drm_connector *connector)
65{
66 struct mxsfb_drm_private *mxsfb =
67 drm_connector_to_mxsfb_drm_private(connector);
68
69 if (mxsfb->panel)
70 drm_panel_detach(mxsfb->panel);
71
72 drm_connector_unregister(connector);
73 drm_connector_cleanup(connector);
74}
75
76static const struct drm_connector_funcs mxsfb_panel_connector_funcs = {
77 .detect = mxsfb_panel_connector_detect,
78 .fill_modes = drm_helper_probe_single_connector_modes,
79 .destroy = mxsfb_panel_connector_destroy,
80 .reset = drm_atomic_helper_connector_reset,
81 .atomic_duplicate_state = drm_atomic_helper_connector_duplicate_state,
82 .atomic_destroy_state = drm_atomic_helper_connector_destroy_state,
83};
84
85int mxsfb_create_output(struct drm_device *drm)
86{
87 struct mxsfb_drm_private *mxsfb = drm->dev_private;
88 struct drm_panel *panel;
89 int ret;
90
91 ret = drm_of_find_panel_or_bridge(drm->dev->of_node, 0, 0, &panel, NULL);
92 if (ret)
93 return ret;
94
95 mxsfb->connector.dpms = DRM_MODE_DPMS_OFF;
96 mxsfb->connector.polled = 0;
97 drm_connector_helper_add(&mxsfb->connector,
98 &mxsfb_panel_connector_helper_funcs);
99 ret = drm_connector_init(drm, &mxsfb->connector,
100 &mxsfb_panel_connector_funcs,
101 DRM_MODE_CONNECTOR_Unknown);
102 if (!ret)
103 mxsfb->panel = panel;
104
105 return ret;
106}
107