treewide: Replace GPLv2 boilerplate/reference with SPDX - rule 157
[sfrench/cifs-2.6.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 #include <drm/drmP.h>
19
20 #include "mxsfb_drv.h"
21
22 static struct mxsfb_drm_private *
23 drm_connector_to_mxsfb_drm_private(struct drm_connector *connector)
24 {
25         return container_of(connector, struct mxsfb_drm_private, connector);
26 }
27
28 static int mxsfb_panel_get_modes(struct drm_connector *connector)
29 {
30         struct mxsfb_drm_private *mxsfb =
31                         drm_connector_to_mxsfb_drm_private(connector);
32
33         if (mxsfb->panel)
34                 return mxsfb->panel->funcs->get_modes(mxsfb->panel);
35
36         return 0;
37 }
38
39 static const struct
40 drm_connector_helper_funcs mxsfb_panel_connector_helper_funcs = {
41         .get_modes = mxsfb_panel_get_modes,
42 };
43
44 static enum drm_connector_status
45 mxsfb_panel_connector_detect(struct drm_connector *connector, bool force)
46 {
47         struct mxsfb_drm_private *mxsfb =
48                         drm_connector_to_mxsfb_drm_private(connector);
49
50         if (mxsfb->panel)
51                 return connector_status_connected;
52
53         return connector_status_disconnected;
54 }
55
56 static void mxsfb_panel_connector_destroy(struct drm_connector *connector)
57 {
58         struct mxsfb_drm_private *mxsfb =
59                         drm_connector_to_mxsfb_drm_private(connector);
60
61         if (mxsfb->panel)
62                 drm_panel_detach(mxsfb->panel);
63
64         drm_connector_unregister(connector);
65         drm_connector_cleanup(connector);
66 }
67
68 static const struct drm_connector_funcs mxsfb_panel_connector_funcs = {
69         .detect                 = mxsfb_panel_connector_detect,
70         .fill_modes             = drm_helper_probe_single_connector_modes,
71         .destroy                = mxsfb_panel_connector_destroy,
72         .reset                  = drm_atomic_helper_connector_reset,
73         .atomic_duplicate_state = drm_atomic_helper_connector_duplicate_state,
74         .atomic_destroy_state   = drm_atomic_helper_connector_destroy_state,
75 };
76
77 int mxsfb_create_output(struct drm_device *drm)
78 {
79         struct mxsfb_drm_private *mxsfb = drm->dev_private;
80         struct drm_panel *panel;
81         int ret;
82
83         ret = drm_of_find_panel_or_bridge(drm->dev->of_node, 0, 0, &panel, NULL);
84         if (ret)
85                 return ret;
86
87         mxsfb->connector.dpms = DRM_MODE_DPMS_OFF;
88         mxsfb->connector.polled = 0;
89         drm_connector_helper_add(&mxsfb->connector,
90                         &mxsfb_panel_connector_helper_funcs);
91         ret = drm_connector_init(drm, &mxsfb->connector,
92                                  &mxsfb_panel_connector_funcs,
93                                  DRM_MODE_CONNECTOR_Unknown);
94         if (!ret)
95                 mxsfb->panel = panel;
96
97         return ret;
98 }