Loading...
1/*
2 * Copyright (c) 2007 Dave Airlie <airlied@linux.ie>
3 * Copyright (c) 2007, 2010 Intel Corporation
4 * Jesse Barnes <jesse.barnes@intel.com>
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 "display/intel_panel.h"
33
34#include "i915_drv.h"
35#include "intel_connector.h"
36#include "intel_display_debugfs.h"
37#include "intel_display_types.h"
38#include "intel_hdcp.h"
39
40int intel_connector_init(struct intel_connector *connector)
41{
42 struct intel_digital_connector_state *conn_state;
43
44 /*
45 * Allocate enough memory to hold intel_digital_connector_state,
46 * This might be a few bytes too many, but for connectors that don't
47 * need it we'll free the state and allocate a smaller one on the first
48 * successful commit anyway.
49 */
50 conn_state = kzalloc(sizeof(*conn_state), GFP_KERNEL);
51 if (!conn_state)
52 return -ENOMEM;
53
54 __drm_atomic_helper_connector_reset(&connector->base,
55 &conn_state->base);
56
57 return 0;
58}
59
60struct intel_connector *intel_connector_alloc(void)
61{
62 struct intel_connector *connector;
63
64 connector = kzalloc(sizeof(*connector), GFP_KERNEL);
65 if (!connector)
66 return NULL;
67
68 if (intel_connector_init(connector) < 0) {
69 kfree(connector);
70 return NULL;
71 }
72
73 return connector;
74}
75
76/*
77 * Free the bits allocated by intel_connector_alloc.
78 * This should only be used after intel_connector_alloc has returned
79 * successfully, and before drm_connector_init returns successfully.
80 * Otherwise the destroy callbacks for the connector and the state should
81 * take care of proper cleanup/free (see intel_connector_destroy).
82 */
83void intel_connector_free(struct intel_connector *connector)
84{
85 kfree(to_intel_digital_connector_state(connector->base.state));
86 kfree(connector);
87}
88
89/*
90 * Connector type independent destroy hook for drm_connector_funcs.
91 */
92void intel_connector_destroy(struct drm_connector *connector)
93{
94 struct intel_connector *intel_connector = to_intel_connector(connector);
95
96 kfree(intel_connector->detect_edid);
97
98 intel_hdcp_cleanup(intel_connector);
99
100 if (!IS_ERR_OR_NULL(intel_connector->edid))
101 kfree(intel_connector->edid);
102
103 intel_panel_fini(&intel_connector->panel);
104
105 drm_connector_cleanup(connector);
106
107 if (intel_connector->port)
108 drm_dp_mst_put_port_malloc(intel_connector->port);
109
110 kfree(connector);
111}
112
113int intel_connector_register(struct drm_connector *connector)
114{
115 struct intel_connector *intel_connector = to_intel_connector(connector);
116 int ret;
117
118 ret = intel_backlight_device_register(intel_connector);
119 if (ret)
120 goto err;
121
122 if (i915_inject_probe_failure(to_i915(connector->dev))) {
123 ret = -EFAULT;
124 goto err_backlight;
125 }
126
127 intel_connector_debugfs_add(connector);
128
129 return 0;
130
131err_backlight:
132 intel_backlight_device_unregister(intel_connector);
133err:
134 return ret;
135}
136
137void intel_connector_unregister(struct drm_connector *connector)
138{
139 struct intel_connector *intel_connector = to_intel_connector(connector);
140
141 intel_backlight_device_unregister(intel_connector);
142}
143
144void intel_connector_attach_encoder(struct intel_connector *connector,
145 struct intel_encoder *encoder)
146{
147 connector->encoder = encoder;
148 drm_connector_attach_encoder(&connector->base, &encoder->base);
149}
150
151/*
152 * Simple connector->get_hw_state implementation for encoders that support only
153 * one connector and no cloning and hence the encoder state determines the state
154 * of the connector.
155 */
156bool intel_connector_get_hw_state(struct intel_connector *connector)
157{
158 enum pipe pipe = 0;
159 struct intel_encoder *encoder = intel_attached_encoder(connector);
160
161 return encoder->get_hw_state(encoder, &pipe);
162}
163
164enum pipe intel_connector_get_pipe(struct intel_connector *connector)
165{
166 struct drm_device *dev = connector->base.dev;
167
168 drm_WARN_ON(dev,
169 !drm_modeset_is_locked(&dev->mode_config.connection_mutex));
170
171 if (!connector->base.state->crtc)
172 return INVALID_PIPE;
173
174 return to_intel_crtc(connector->base.state->crtc)->pipe;
175}
176
177/**
178 * intel_connector_update_modes - update connector from edid
179 * @connector: DRM connector device to use
180 * @edid: previously read EDID information
181 */
182int intel_connector_update_modes(struct drm_connector *connector,
183 struct edid *edid)
184{
185 int ret;
186
187 drm_connector_update_edid_property(connector, edid);
188 ret = drm_add_edid_modes(connector, edid);
189
190 return ret;
191}
192
193/**
194 * intel_ddc_get_modes - get modelist from monitor
195 * @connector: DRM connector device to use
196 * @adapter: i2c adapter
197 *
198 * Fetch the EDID information from @connector using the DDC bus.
199 */
200int intel_ddc_get_modes(struct drm_connector *connector,
201 struct i2c_adapter *adapter)
202{
203 struct edid *edid;
204 int ret;
205
206 edid = drm_get_edid(connector, adapter);
207 if (!edid)
208 return 0;
209
210 ret = intel_connector_update_modes(connector, edid);
211 kfree(edid);
212
213 return ret;
214}
215
216static const struct drm_prop_enum_list force_audio_names[] = {
217 { HDMI_AUDIO_OFF_DVI, "force-dvi" },
218 { HDMI_AUDIO_OFF, "off" },
219 { HDMI_AUDIO_AUTO, "auto" },
220 { HDMI_AUDIO_ON, "on" },
221};
222
223void
224intel_attach_force_audio_property(struct drm_connector *connector)
225{
226 struct drm_device *dev = connector->dev;
227 struct drm_i915_private *dev_priv = to_i915(dev);
228 struct drm_property *prop;
229
230 prop = dev_priv->force_audio_property;
231 if (prop == NULL) {
232 prop = drm_property_create_enum(dev, 0,
233 "audio",
234 force_audio_names,
235 ARRAY_SIZE(force_audio_names));
236 if (prop == NULL)
237 return;
238
239 dev_priv->force_audio_property = prop;
240 }
241 drm_object_attach_property(&connector->base, prop, 0);
242}
243
244static const struct drm_prop_enum_list broadcast_rgb_names[] = {
245 { INTEL_BROADCAST_RGB_AUTO, "Automatic" },
246 { INTEL_BROADCAST_RGB_FULL, "Full" },
247 { INTEL_BROADCAST_RGB_LIMITED, "Limited 16:235" },
248};
249
250void
251intel_attach_broadcast_rgb_property(struct drm_connector *connector)
252{
253 struct drm_device *dev = connector->dev;
254 struct drm_i915_private *dev_priv = to_i915(dev);
255 struct drm_property *prop;
256
257 prop = dev_priv->broadcast_rgb_property;
258 if (prop == NULL) {
259 prop = drm_property_create_enum(dev, DRM_MODE_PROP_ENUM,
260 "Broadcast RGB",
261 broadcast_rgb_names,
262 ARRAY_SIZE(broadcast_rgb_names));
263 if (prop == NULL)
264 return;
265
266 dev_priv->broadcast_rgb_property = prop;
267 }
268
269 drm_object_attach_property(&connector->base, prop, 0);
270}
271
272void
273intel_attach_aspect_ratio_property(struct drm_connector *connector)
274{
275 if (!drm_mode_create_aspect_ratio_property(connector->dev))
276 drm_object_attach_property(&connector->base,
277 connector->dev->mode_config.aspect_ratio_property,
278 DRM_MODE_PICTURE_ASPECT_NONE);
279}
280
281void
282intel_attach_hdmi_colorspace_property(struct drm_connector *connector)
283{
284 if (!drm_mode_create_hdmi_colorspace_property(connector))
285 drm_connector_attach_colorspace_property(connector);
286}
287
288void
289intel_attach_dp_colorspace_property(struct drm_connector *connector)
290{
291 if (!drm_mode_create_dp_colorspace_property(connector))
292 drm_connector_attach_colorspace_property(connector);
293}
1/*
2 * Copyright (c) 2007 Dave Airlie <airlied@linux.ie>
3 * Copyright (c) 2007, 2010 Intel Corporation
4 * Jesse Barnes <jesse.barnes@intel.com>
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_backlight.h"
34#include "intel_connector.h"
35#include "intel_display_debugfs.h"
36#include "intel_display_types.h"
37#include "intel_hdcp.h"
38#include "intel_panel.h"
39
40int intel_connector_init(struct intel_connector *connector)
41{
42 struct intel_digital_connector_state *conn_state;
43
44 /*
45 * Allocate enough memory to hold intel_digital_connector_state,
46 * This might be a few bytes too many, but for connectors that don't
47 * need it we'll free the state and allocate a smaller one on the first
48 * successful commit anyway.
49 */
50 conn_state = kzalloc(sizeof(*conn_state), GFP_KERNEL);
51 if (!conn_state)
52 return -ENOMEM;
53
54 __drm_atomic_helper_connector_reset(&connector->base,
55 &conn_state->base);
56
57 intel_panel_init_alloc(connector);
58
59 return 0;
60}
61
62struct intel_connector *intel_connector_alloc(void)
63{
64 struct intel_connector *connector;
65
66 connector = kzalloc(sizeof(*connector), GFP_KERNEL);
67 if (!connector)
68 return NULL;
69
70 if (intel_connector_init(connector) < 0) {
71 kfree(connector);
72 return NULL;
73 }
74
75 return connector;
76}
77
78/*
79 * Free the bits allocated by intel_connector_alloc.
80 * This should only be used after intel_connector_alloc has returned
81 * successfully, and before drm_connector_init returns successfully.
82 * Otherwise the destroy callbacks for the connector and the state should
83 * take care of proper cleanup/free (see intel_connector_destroy).
84 */
85void intel_connector_free(struct intel_connector *connector)
86{
87 kfree(to_intel_digital_connector_state(connector->base.state));
88 kfree(connector);
89}
90
91/*
92 * Connector type independent destroy hook for drm_connector_funcs.
93 */
94void intel_connector_destroy(struct drm_connector *connector)
95{
96 struct intel_connector *intel_connector = to_intel_connector(connector);
97
98 drm_edid_free(intel_connector->detect_edid);
99
100 intel_hdcp_cleanup(intel_connector);
101
102 intel_panel_fini(intel_connector);
103
104 drm_connector_cleanup(connector);
105
106 if (intel_connector->port)
107 drm_dp_mst_put_port_malloc(intel_connector->port);
108
109 kfree(connector);
110}
111
112int intel_connector_register(struct drm_connector *connector)
113{
114 struct intel_connector *intel_connector = to_intel_connector(connector);
115 int ret;
116
117 ret = intel_backlight_device_register(intel_connector);
118 if (ret)
119 goto err;
120
121 if (i915_inject_probe_failure(to_i915(connector->dev))) {
122 ret = -EFAULT;
123 goto err_backlight;
124 }
125
126 intel_connector_debugfs_add(intel_connector);
127
128 return 0;
129
130err_backlight:
131 intel_backlight_device_unregister(intel_connector);
132err:
133 return ret;
134}
135
136void intel_connector_unregister(struct drm_connector *connector)
137{
138 struct intel_connector *intel_connector = to_intel_connector(connector);
139
140 intel_backlight_device_unregister(intel_connector);
141}
142
143void intel_connector_attach_encoder(struct intel_connector *connector,
144 struct intel_encoder *encoder)
145{
146 connector->encoder = encoder;
147 drm_connector_attach_encoder(&connector->base, &encoder->base);
148}
149
150/*
151 * Simple connector->get_hw_state implementation for encoders that support only
152 * one connector and no cloning and hence the encoder state determines the state
153 * of the connector.
154 */
155bool intel_connector_get_hw_state(struct intel_connector *connector)
156{
157 enum pipe pipe = 0;
158 struct intel_encoder *encoder = intel_attached_encoder(connector);
159
160 return encoder->get_hw_state(encoder, &pipe);
161}
162
163enum pipe intel_connector_get_pipe(struct intel_connector *connector)
164{
165 struct drm_device *dev = connector->base.dev;
166
167 drm_WARN_ON(dev,
168 !drm_modeset_is_locked(&dev->mode_config.connection_mutex));
169
170 if (!connector->base.state->crtc)
171 return INVALID_PIPE;
172
173 return to_intel_crtc(connector->base.state->crtc)->pipe;
174}
175
176/**
177 * intel_connector_update_modes - update connector from edid
178 * @connector: DRM connector device to use
179 * @drm_edid: previously read EDID information
180 */
181int intel_connector_update_modes(struct drm_connector *connector,
182 const struct drm_edid *drm_edid)
183{
184 int ret;
185
186 drm_edid_connector_update(connector, drm_edid);
187 ret = drm_edid_connector_add_modes(connector);
188
189 return ret;
190}
191
192/**
193 * intel_ddc_get_modes - get modelist from monitor
194 * @connector: DRM connector device to use
195 * @ddc: DDC bus i2c adapter
196 *
197 * Fetch the EDID information from @connector using the DDC bus.
198 */
199int intel_ddc_get_modes(struct drm_connector *connector,
200 struct i2c_adapter *ddc)
201{
202 const struct drm_edid *drm_edid;
203 int ret;
204
205 drm_edid = drm_edid_read_ddc(connector, ddc);
206 if (!drm_edid)
207 return 0;
208
209 ret = intel_connector_update_modes(connector, drm_edid);
210 drm_edid_free(drm_edid);
211
212 return ret;
213}
214
215static const struct drm_prop_enum_list force_audio_names[] = {
216 { HDMI_AUDIO_OFF_DVI, "force-dvi" },
217 { HDMI_AUDIO_OFF, "off" },
218 { HDMI_AUDIO_AUTO, "auto" },
219 { HDMI_AUDIO_ON, "on" },
220};
221
222void
223intel_attach_force_audio_property(struct drm_connector *connector)
224{
225 struct drm_device *dev = connector->dev;
226 struct drm_i915_private *dev_priv = to_i915(dev);
227 struct drm_property *prop;
228
229 prop = dev_priv->display.properties.force_audio;
230 if (prop == NULL) {
231 prop = drm_property_create_enum(dev, 0,
232 "audio",
233 force_audio_names,
234 ARRAY_SIZE(force_audio_names));
235 if (prop == NULL)
236 return;
237
238 dev_priv->display.properties.force_audio = prop;
239 }
240 drm_object_attach_property(&connector->base, prop, 0);
241}
242
243static const struct drm_prop_enum_list broadcast_rgb_names[] = {
244 { INTEL_BROADCAST_RGB_AUTO, "Automatic" },
245 { INTEL_BROADCAST_RGB_FULL, "Full" },
246 { INTEL_BROADCAST_RGB_LIMITED, "Limited 16:235" },
247};
248
249void
250intel_attach_broadcast_rgb_property(struct drm_connector *connector)
251{
252 struct drm_device *dev = connector->dev;
253 struct drm_i915_private *dev_priv = to_i915(dev);
254 struct drm_property *prop;
255
256 prop = dev_priv->display.properties.broadcast_rgb;
257 if (prop == NULL) {
258 prop = drm_property_create_enum(dev, DRM_MODE_PROP_ENUM,
259 "Broadcast RGB",
260 broadcast_rgb_names,
261 ARRAY_SIZE(broadcast_rgb_names));
262 if (prop == NULL)
263 return;
264
265 dev_priv->display.properties.broadcast_rgb = prop;
266 }
267
268 drm_object_attach_property(&connector->base, prop, 0);
269}
270
271void
272intel_attach_aspect_ratio_property(struct drm_connector *connector)
273{
274 if (!drm_mode_create_aspect_ratio_property(connector->dev))
275 drm_object_attach_property(&connector->base,
276 connector->dev->mode_config.aspect_ratio_property,
277 DRM_MODE_PICTURE_ASPECT_NONE);
278}
279
280void
281intel_attach_hdmi_colorspace_property(struct drm_connector *connector)
282{
283 if (!drm_mode_create_hdmi_colorspace_property(connector, 0))
284 drm_connector_attach_colorspace_property(connector);
285}
286
287void
288intel_attach_dp_colorspace_property(struct drm_connector *connector)
289{
290 if (!drm_mode_create_dp_colorspace_property(connector, 0))
291 drm_connector_attach_colorspace_property(connector);
292}
293
294void
295intel_attach_scaling_mode_property(struct drm_connector *connector)
296{
297 struct drm_i915_private *i915 = to_i915(connector->dev);
298 u32 scaling_modes;
299
300 scaling_modes = BIT(DRM_MODE_SCALE_ASPECT) |
301 BIT(DRM_MODE_SCALE_FULLSCREEN);
302
303 /* On GMCH platforms borders are only possible on the LVDS port */
304 if (!HAS_GMCH(i915) || connector->connector_type == DRM_MODE_CONNECTOR_LVDS)
305 scaling_modes |= BIT(DRM_MODE_SCALE_CENTER);
306
307 drm_connector_attach_scaling_mode_property(connector, scaling_modes);
308
309 connector->state->scaling_mode = DRM_MODE_SCALE_ASPECT;
310}