Linux Audio

Check our new training course

Loading...
v5.4
 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
21static struct mxsfb_drm_private *
22drm_connector_to_mxsfb_drm_private(struct drm_connector *connector)
23{
24	return container_of(connector, struct mxsfb_drm_private, connector);
25}
26
27static 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 drm_panel_get_modes(mxsfb->panel);
34
35	return 0;
36}
37
38static const struct
39drm_connector_helper_funcs mxsfb_panel_connector_helper_funcs = {
40	.get_modes = mxsfb_panel_get_modes,
41};
42
43static enum drm_connector_status
44mxsfb_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
55static 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
67static 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
76int 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}
v4.10.11
 
  1/*
  2 * Copyright (C) 2016 Marek Vasut <marex@denx.de>
  3 *
  4 * This program is free software; you can redistribute it and/or
  5 * modify it under the terms of the GNU General Public License
  6 * as published by the Free Software Foundation; either version 2
  7 * of the License, or (at your option) any later version.
  8 * This program is distributed in the hope that it will be useful,
  9 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 10 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 11 * GNU General Public License for more details.
 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_panel.h>
 23#include <drm/drm_plane_helper.h>
 
 24#include <drm/drm_simple_kms_helper.h>
 25#include <drm/drmP.h>
 26
 27#include "mxsfb_drv.h"
 28
 29static struct mxsfb_drm_private *
 30drm_connector_to_mxsfb_drm_private(struct drm_connector *connector)
 31{
 32	return container_of(connector, struct mxsfb_drm_private, connector);
 33}
 34
 35static int mxsfb_panel_get_modes(struct drm_connector *connector)
 36{
 37	struct mxsfb_drm_private *mxsfb =
 38			drm_connector_to_mxsfb_drm_private(connector);
 39
 40	if (mxsfb->panel)
 41		return mxsfb->panel->funcs->get_modes(mxsfb->panel);
 42
 43	return 0;
 44}
 45
 46static const struct
 47drm_connector_helper_funcs mxsfb_panel_connector_helper_funcs = {
 48	.get_modes = mxsfb_panel_get_modes,
 49};
 50
 51static enum drm_connector_status
 52mxsfb_panel_connector_detect(struct drm_connector *connector, bool force)
 53{
 54	struct mxsfb_drm_private *mxsfb =
 55			drm_connector_to_mxsfb_drm_private(connector);
 56
 57	if (mxsfb->panel)
 58		return connector_status_connected;
 59
 60	return connector_status_disconnected;
 61}
 62
 63static void mxsfb_panel_connector_destroy(struct drm_connector *connector)
 64{
 65	struct mxsfb_drm_private *mxsfb =
 66			drm_connector_to_mxsfb_drm_private(connector);
 67
 68	if (mxsfb->panel)
 69		drm_panel_detach(mxsfb->panel);
 70
 71	drm_connector_unregister(connector);
 72	drm_connector_cleanup(connector);
 73}
 74
 75static const struct drm_connector_funcs mxsfb_panel_connector_funcs = {
 76	.dpms			= drm_atomic_helper_connector_dpms,
 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
 85static int mxsfb_attach_endpoint(struct drm_device *drm,
 86				 const struct of_endpoint *ep)
 87{
 88	struct mxsfb_drm_private *mxsfb = drm->dev_private;
 89	struct device_node *np;
 90	struct drm_panel *panel;
 91	int ret = -EPROBE_DEFER;
 92
 93	np = of_graph_get_remote_port_parent(ep->local_node);
 94	panel = of_drm_find_panel(np);
 95	of_node_put(np);
 96
 97	if (!panel)
 98		return -EPROBE_DEFER;
 
 99
100	mxsfb->connector.dpms = DRM_MODE_DPMS_OFF;
101	mxsfb->connector.polled = 0;
102	drm_connector_helper_add(&mxsfb->connector,
103			&mxsfb_panel_connector_helper_funcs);
104	ret = drm_connector_init(drm, &mxsfb->connector,
105				 &mxsfb_panel_connector_funcs,
106				 DRM_MODE_CONNECTOR_Unknown);
107	if (!ret)
108		mxsfb->panel = panel;
109
110	return ret;
111}
112
113int mxsfb_create_output(struct drm_device *drm)
114{
115	struct device_node *ep_np = NULL;
116	struct of_endpoint ep;
117	int ret;
118
119	for_each_endpoint_of_node(drm->dev->of_node, ep_np) {
120		ret = of_graph_parse_endpoint(ep_np, &ep);
121		if (!ret)
122			ret = mxsfb_attach_endpoint(drm, &ep);
123
124		if (ret) {
125			of_node_put(ep_np);
126			return ret;
127		}
128	}
129
130	return 0;
131}