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