]> Git Repo - linux.git/blob - drivers/gpu/drm/i915/intel_connector.c
Merge tag 'drm-intel-next-2019-05-24' of git://anongit.freedesktop.org/drm/drm-intel...
[linux.git] / drivers / gpu / drm / i915 / intel_connector.c
1 /*
2  * Copyright (c) 2007 Dave Airlie <[email protected]>
3  * Copyright (c) 2007, 2010 Intel Corporation
4  *   Jesse Barnes <[email protected]>
5  *
6  * Permission is hereby granted, free of charge, to any person obtaining a
7  * copy of this software and associated documentation files (the "Software"),
8  * to deal in the Software without restriction, including without limitation
9  * the rights to use, copy, modify, merge, publish, distribute, sublicense,
10  * and/or sell copies of the Software, and to permit persons to whom the
11  * Software is furnished to do so, subject to the following conditions:
12  *
13  * The above copyright notice and this permission notice (including the next
14  * paragraph) shall be included in all copies or substantial portions of the
15  * Software.
16  *
17  * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
18  * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
19  * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.  IN NO EVENT SHALL
20  * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
21  * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
22  * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
23  * DEALINGS IN THE SOFTWARE.
24  */
25
26 #include <linux/i2c.h>
27 #include <linux/slab.h>
28
29 #include <drm/drm_atomic_helper.h>
30 #include <drm/drm_edid.h>
31
32 #include "i915_drv.h"
33 #include "intel_connector.h"
34 #include "intel_drv.h"
35 #include "intel_hdcp.h"
36 #include "intel_panel.h"
37
38 int intel_connector_init(struct intel_connector *connector)
39 {
40         struct intel_digital_connector_state *conn_state;
41
42         /*
43          * Allocate enough memory to hold intel_digital_connector_state,
44          * This might be a few bytes too many, but for connectors that don't
45          * need it we'll free the state and allocate a smaller one on the first
46          * successful commit anyway.
47          */
48         conn_state = kzalloc(sizeof(*conn_state), GFP_KERNEL);
49         if (!conn_state)
50                 return -ENOMEM;
51
52         __drm_atomic_helper_connector_reset(&connector->base,
53                                             &conn_state->base);
54
55         return 0;
56 }
57
58 struct intel_connector *intel_connector_alloc(void)
59 {
60         struct intel_connector *connector;
61
62         connector = kzalloc(sizeof(*connector), GFP_KERNEL);
63         if (!connector)
64                 return NULL;
65
66         if (intel_connector_init(connector) < 0) {
67                 kfree(connector);
68                 return NULL;
69         }
70
71         return connector;
72 }
73
74 /*
75  * Free the bits allocated by intel_connector_alloc.
76  * This should only be used after intel_connector_alloc has returned
77  * successfully, and before drm_connector_init returns successfully.
78  * Otherwise the destroy callbacks for the connector and the state should
79  * take care of proper cleanup/free (see intel_connector_destroy).
80  */
81 void intel_connector_free(struct intel_connector *connector)
82 {
83         kfree(to_intel_digital_connector_state(connector->base.state));
84         kfree(connector);
85 }
86
87 /*
88  * Connector type independent destroy hook for drm_connector_funcs.
89  */
90 void intel_connector_destroy(struct drm_connector *connector)
91 {
92         struct intel_connector *intel_connector = to_intel_connector(connector);
93
94         kfree(intel_connector->detect_edid);
95
96         intel_hdcp_cleanup(intel_connector);
97
98         if (!IS_ERR_OR_NULL(intel_connector->edid))
99                 kfree(intel_connector->edid);
100
101         intel_panel_fini(&intel_connector->panel);
102
103         drm_connector_cleanup(connector);
104
105         if (intel_connector->port)
106                 drm_dp_mst_put_port_malloc(intel_connector->port);
107
108         kfree(connector);
109 }
110
111 int intel_connector_register(struct drm_connector *connector)
112 {
113         struct intel_connector *intel_connector = to_intel_connector(connector);
114         int ret;
115
116         ret = intel_backlight_device_register(intel_connector);
117         if (ret)
118                 goto err;
119
120         if (i915_inject_load_failure()) {
121                 ret = -EFAULT;
122                 goto err_backlight;
123         }
124
125         return 0;
126
127 err_backlight:
128         intel_backlight_device_unregister(intel_connector);
129 err:
130         return ret;
131 }
132
133 void intel_connector_unregister(struct drm_connector *connector)
134 {
135         struct intel_connector *intel_connector = to_intel_connector(connector);
136
137         intel_backlight_device_unregister(intel_connector);
138 }
139
140 void intel_connector_attach_encoder(struct intel_connector *connector,
141                                     struct intel_encoder *encoder)
142 {
143         connector->encoder = encoder;
144         drm_connector_attach_encoder(&connector->base, &encoder->base);
145 }
146
147 /*
148  * Simple connector->get_hw_state implementation for encoders that support only
149  * one connector and no cloning and hence the encoder state determines the state
150  * of the connector.
151  */
152 bool intel_connector_get_hw_state(struct intel_connector *connector)
153 {
154         enum pipe pipe = 0;
155         struct intel_encoder *encoder = connector->encoder;
156
157         return encoder->get_hw_state(encoder, &pipe);
158 }
159
160 enum pipe intel_connector_get_pipe(struct intel_connector *connector)
161 {
162         struct drm_device *dev = connector->base.dev;
163
164         WARN_ON(!drm_modeset_is_locked(&dev->mode_config.connection_mutex));
165
166         if (!connector->base.state->crtc)
167                 return INVALID_PIPE;
168
169         return to_intel_crtc(connector->base.state->crtc)->pipe;
170 }
171
172 /**
173  * intel_connector_update_modes - update connector from edid
174  * @connector: DRM connector device to use
175  * @edid: previously read EDID information
176  */
177 int intel_connector_update_modes(struct drm_connector *connector,
178                                 struct edid *edid)
179 {
180         int ret;
181
182         drm_connector_update_edid_property(connector, edid);
183         ret = drm_add_edid_modes(connector, edid);
184
185         return ret;
186 }
187
188 /**
189  * intel_ddc_get_modes - get modelist from monitor
190  * @connector: DRM connector device to use
191  * @adapter: i2c adapter
192  *
193  * Fetch the EDID information from @connector using the DDC bus.
194  */
195 int intel_ddc_get_modes(struct drm_connector *connector,
196                         struct i2c_adapter *adapter)
197 {
198         struct edid *edid;
199         int ret;
200
201         edid = drm_get_edid(connector, adapter);
202         if (!edid)
203                 return 0;
204
205         ret = intel_connector_update_modes(connector, edid);
206         kfree(edid);
207
208         return ret;
209 }
210
211 static const struct drm_prop_enum_list force_audio_names[] = {
212         { HDMI_AUDIO_OFF_DVI, "force-dvi" },
213         { HDMI_AUDIO_OFF, "off" },
214         { HDMI_AUDIO_AUTO, "auto" },
215         { HDMI_AUDIO_ON, "on" },
216 };
217
218 void
219 intel_attach_force_audio_property(struct drm_connector *connector)
220 {
221         struct drm_device *dev = connector->dev;
222         struct drm_i915_private *dev_priv = to_i915(dev);
223         struct drm_property *prop;
224
225         prop = dev_priv->force_audio_property;
226         if (prop == NULL) {
227                 prop = drm_property_create_enum(dev, 0,
228                                            "audio",
229                                            force_audio_names,
230                                            ARRAY_SIZE(force_audio_names));
231                 if (prop == NULL)
232                         return;
233
234                 dev_priv->force_audio_property = prop;
235         }
236         drm_object_attach_property(&connector->base, prop, 0);
237 }
238
239 static const struct drm_prop_enum_list broadcast_rgb_names[] = {
240         { INTEL_BROADCAST_RGB_AUTO, "Automatic" },
241         { INTEL_BROADCAST_RGB_FULL, "Full" },
242         { INTEL_BROADCAST_RGB_LIMITED, "Limited 16:235" },
243 };
244
245 void
246 intel_attach_broadcast_rgb_property(struct drm_connector *connector)
247 {
248         struct drm_device *dev = connector->dev;
249         struct drm_i915_private *dev_priv = to_i915(dev);
250         struct drm_property *prop;
251
252         prop = dev_priv->broadcast_rgb_property;
253         if (prop == NULL) {
254                 prop = drm_property_create_enum(dev, DRM_MODE_PROP_ENUM,
255                                            "Broadcast RGB",
256                                            broadcast_rgb_names,
257                                            ARRAY_SIZE(broadcast_rgb_names));
258                 if (prop == NULL)
259                         return;
260
261                 dev_priv->broadcast_rgb_property = prop;
262         }
263
264         drm_object_attach_property(&connector->base, prop, 0);
265 }
266
267 void
268 intel_attach_aspect_ratio_property(struct drm_connector *connector)
269 {
270         if (!drm_mode_create_aspect_ratio_property(connector->dev))
271                 drm_object_attach_property(&connector->base,
272                         connector->dev->mode_config.aspect_ratio_property,
273                         DRM_MODE_PICTURE_ASPECT_NONE);
274 }
275
276 void
277 intel_attach_colorspace_property(struct drm_connector *connector)
278 {
279         if (!drm_mode_create_colorspace_property(connector))
280                 drm_object_attach_property(&connector->base,
281                                            connector->colorspace_property, 0);
282 }
This page took 0.050398 seconds and 4 git commands to generate.