aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorDave Airlie <airlied@redhat.com>2016-11-10 20:55:11 -0500
committerDave Airlie <airlied@redhat.com>2016-11-10 20:55:11 -0500
commite2384535a623ed51151d1bbed5263b9f8a87a74d (patch)
tree62d28c0fab4b609e30b41339403802be4ab1b86a
parent76af753bf8d11c40cc4950cc32d9cc3aee852b25 (diff)
parent7bc61cc5df808008b77a3b72cf814960c675518b (diff)
Merge branch 'topic-arcpgu-fixes' of https://github.com/foss-for-synopsys-dwc-arc-processors/linux into drm-fixes
* 'topic-arcpgu-fixes' of https://github.com/foss-for-synopsys-dwc-arc-processors/linux: drm/arcpgu: Accommodate adv7511 switch to DRM bridge
-rw-r--r--drivers/gpu/drm/arc/arcpgu_hdmi.c159
1 files changed, 17 insertions, 142 deletions
diff --git a/drivers/gpu/drm/arc/arcpgu_hdmi.c b/drivers/gpu/drm/arc/arcpgu_hdmi.c
index b7a8b2ac4055..b69c66b4897e 100644
--- a/drivers/gpu/drm/arc/arcpgu_hdmi.c
+++ b/drivers/gpu/drm/arc/arcpgu_hdmi.c
@@ -14,170 +14,45 @@
14 * 14 *
15 */ 15 */
16 16
17#include <drm/drm_crtc_helper.h> 17#include <drm/drm_crtc.h>
18#include <drm/drm_encoder_slave.h> 18#include <drm/drm_encoder_slave.h>
19#include <drm/drm_atomic_helper.h>
20 19
21#include "arcpgu.h" 20#include "arcpgu.h"
22 21
23struct arcpgu_drm_connector {
24 struct drm_connector connector;
25 struct drm_encoder_slave *encoder_slave;
26};
27
28static int arcpgu_drm_connector_get_modes(struct drm_connector *connector)
29{
30 const struct drm_encoder_slave_funcs *sfuncs;
31 struct drm_encoder_slave *slave;
32 struct arcpgu_drm_connector *con =
33 container_of(connector, struct arcpgu_drm_connector, connector);
34
35 slave = con->encoder_slave;
36 if (slave == NULL) {
37 dev_err(connector->dev->dev,
38 "connector_get_modes: cannot find slave encoder for connector\n");
39 return 0;
40 }
41
42 sfuncs = slave->slave_funcs;
43 if (sfuncs->get_modes == NULL)
44 return 0;
45
46 return sfuncs->get_modes(&slave->base, connector);
47}
48
49static enum drm_connector_status
50arcpgu_drm_connector_detect(struct drm_connector *connector, bool force)
51{
52 enum drm_connector_status status = connector_status_unknown;
53 const struct drm_encoder_slave_funcs *sfuncs;
54 struct drm_encoder_slave *slave;
55
56 struct arcpgu_drm_connector *con =
57 container_of(connector, struct arcpgu_drm_connector, connector);
58
59 slave = con->encoder_slave;
60 if (slave == NULL) {
61 dev_err(connector->dev->dev,
62 "connector_detect: cannot find slave encoder for connector\n");
63 return status;
64 }
65
66 sfuncs = slave->slave_funcs;
67 if (sfuncs && sfuncs->detect)
68 return sfuncs->detect(&slave->base, connector);
69
70 dev_err(connector->dev->dev, "connector_detect: could not detect slave funcs\n");
71 return status;
72}
73
74static void arcpgu_drm_connector_destroy(struct drm_connector *connector)
75{
76 drm_connector_unregister(connector);
77 drm_connector_cleanup(connector);
78}
79
80static const struct drm_connector_helper_funcs
81arcpgu_drm_connector_helper_funcs = {
82 .get_modes = arcpgu_drm_connector_get_modes,
83};
84
85static const struct drm_connector_funcs arcpgu_drm_connector_funcs = {
86 .dpms = drm_helper_connector_dpms,
87 .reset = drm_atomic_helper_connector_reset,
88 .detect = arcpgu_drm_connector_detect,
89 .fill_modes = drm_helper_probe_single_connector_modes,
90 .destroy = arcpgu_drm_connector_destroy,
91 .atomic_duplicate_state = drm_atomic_helper_connector_duplicate_state,
92 .atomic_destroy_state = drm_atomic_helper_connector_destroy_state,
93};
94
95static struct drm_encoder_helper_funcs arcpgu_drm_encoder_helper_funcs = {
96 .dpms = drm_i2c_encoder_dpms,
97 .mode_fixup = drm_i2c_encoder_mode_fixup,
98 .mode_set = drm_i2c_encoder_mode_set,
99 .prepare = drm_i2c_encoder_prepare,
100 .commit = drm_i2c_encoder_commit,
101 .detect = drm_i2c_encoder_detect,
102};
103
104static struct drm_encoder_funcs arcpgu_drm_encoder_funcs = { 22static struct drm_encoder_funcs arcpgu_drm_encoder_funcs = {
105 .destroy = drm_encoder_cleanup, 23 .destroy = drm_encoder_cleanup,
106}; 24};
107 25
108int arcpgu_drm_hdmi_init(struct drm_device *drm, struct device_node *np) 26int arcpgu_drm_hdmi_init(struct drm_device *drm, struct device_node *np)
109{ 27{
110 struct arcpgu_drm_connector *arcpgu_connector; 28 struct drm_encoder *encoder;
111 struct drm_i2c_encoder_driver *driver; 29 struct drm_bridge *bridge;
112 struct drm_encoder_slave *encoder; 30
113 struct drm_connector *connector; 31 int ret = 0;
114 struct i2c_client *i2c_slave;
115 int ret;
116 32
117 encoder = devm_kzalloc(drm->dev, sizeof(*encoder), GFP_KERNEL); 33 encoder = devm_kzalloc(drm->dev, sizeof(*encoder), GFP_KERNEL);
118 if (encoder == NULL) 34 if (encoder == NULL)
119 return -ENOMEM; 35 return -ENOMEM;
120 36
121 i2c_slave = of_find_i2c_device_by_node(np); 37 /* Locate drm bridge from the hdmi encoder DT node */
122 if (!i2c_slave || !i2c_get_clientdata(i2c_slave)) { 38 bridge = of_drm_find_bridge(np);
123 dev_err(drm->dev, "failed to find i2c slave encoder\n"); 39 if (!bridge)
124 return -EPROBE_DEFER;
125 }
126
127 if (i2c_slave->dev.driver == NULL) {
128 dev_err(drm->dev, "failed to find i2c slave driver\n");
129 return -EPROBE_DEFER; 40 return -EPROBE_DEFER;
130 }
131 41
132 driver = 42 encoder->possible_crtcs = 1;
133 to_drm_i2c_encoder_driver(to_i2c_driver(i2c_slave->dev.driver)); 43 encoder->possible_clones = 0;
134 ret = driver->encoder_init(i2c_slave, drm, encoder); 44 ret = drm_encoder_init(drm, encoder, &arcpgu_drm_encoder_funcs,
135 if (ret) {
136 dev_err(drm->dev, "failed to initialize i2c encoder slave\n");
137 return ret;
138 }
139
140 encoder->base.possible_crtcs = 1;
141 encoder->base.possible_clones = 0;
142 ret = drm_encoder_init(drm, &encoder->base, &arcpgu_drm_encoder_funcs,
143 DRM_MODE_ENCODER_TMDS, NULL); 45 DRM_MODE_ENCODER_TMDS, NULL);
144 if (ret) 46 if (ret)
145 return ret; 47 return ret;
146 48
147 drm_encoder_helper_add(&encoder->base, 49 /* Link drm_bridge to encoder */
148 &arcpgu_drm_encoder_helper_funcs); 50 bridge->encoder = encoder;
149 51 encoder->bridge = bridge;
150 arcpgu_connector = devm_kzalloc(drm->dev, sizeof(*arcpgu_connector),
151 GFP_KERNEL);
152 if (!arcpgu_connector) {
153 ret = -ENOMEM;
154 goto error_encoder_cleanup;
155 }
156
157 connector = &arcpgu_connector->connector;
158 drm_connector_helper_add(connector, &arcpgu_drm_connector_helper_funcs);
159 ret = drm_connector_init(drm, connector, &arcpgu_drm_connector_funcs,
160 DRM_MODE_CONNECTOR_HDMIA);
161 if (ret < 0) {
162 dev_err(drm->dev, "failed to initialize drm connector\n");
163 goto error_encoder_cleanup;
164 }
165 52
166 ret = drm_mode_connector_attach_encoder(connector, &encoder->base); 53 ret = drm_bridge_attach(drm, bridge);
167 if (ret < 0) { 54 if (ret)
168 dev_err(drm->dev, "could not attach connector to encoder\n"); 55 drm_encoder_cleanup(encoder);
169 drm_connector_unregister(connector);
170 goto error_connector_cleanup;
171 }
172
173 arcpgu_connector->encoder_slave = encoder;
174
175 return 0;
176
177error_connector_cleanup:
178 drm_connector_cleanup(connector);
179 56
180error_encoder_cleanup:
181 drm_encoder_cleanup(&encoder->base);
182 return ret; 57 return ret;
183} 58}