2 * Copyright (c) 2007 Dave Airlie <airlied@linux.ie>
3 * Copyright (c) 2007, 2010 Intel Corporation
4 * Jesse Barnes <jesse.barnes@intel.com>
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:
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
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.
26 #include <linux/i2c.h>
27 #include <linux/slab.h>
29 #include <drm/drm_atomic_helper.h>
30 #include <drm/drm_edid.h>
32 #include "display/intel_panel.h"
35 #include "intel_connector.h"
36 #include "intel_display_debugfs.h"
37 #include "intel_display_types.h"
38 #include "intel_hdcp.h"
40 int intel_connector_init(struct intel_connector
*connector
)
42 struct intel_digital_connector_state
*conn_state
;
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.
50 conn_state
= kzalloc(sizeof(*conn_state
), GFP_KERNEL
);
54 __drm_atomic_helper_connector_reset(&connector
->base
,
60 struct intel_connector
*intel_connector_alloc(void)
62 struct intel_connector
*connector
;
64 connector
= kzalloc(sizeof(*connector
), GFP_KERNEL
);
68 if (intel_connector_init(connector
) < 0) {
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).
83 void intel_connector_free(struct intel_connector
*connector
)
85 kfree(to_intel_digital_connector_state(connector
->base
.state
));
90 * Connector type independent destroy hook for drm_connector_funcs.
92 void intel_connector_destroy(struct drm_connector
*connector
)
94 struct intel_connector
*intel_connector
= to_intel_connector(connector
);
96 kfree(intel_connector
->detect_edid
);
98 intel_hdcp_cleanup(intel_connector
);
100 if (!IS_ERR_OR_NULL(intel_connector
->edid
))
101 kfree(intel_connector
->edid
);
103 intel_panel_fini(&intel_connector
->panel
);
105 drm_connector_cleanup(connector
);
107 if (intel_connector
->port
)
108 drm_dp_mst_put_port_malloc(intel_connector
->port
);
113 int intel_connector_register(struct drm_connector
*connector
)
115 struct intel_connector
*intel_connector
= to_intel_connector(connector
);
118 ret
= intel_backlight_device_register(intel_connector
);
122 if (i915_inject_probe_failure(to_i915(connector
->dev
))) {
127 intel_connector_debugfs_add(connector
);
132 intel_backlight_device_unregister(intel_connector
);
137 void intel_connector_unregister(struct drm_connector
*connector
)
139 struct intel_connector
*intel_connector
= to_intel_connector(connector
);
141 intel_backlight_device_unregister(intel_connector
);
144 void intel_connector_attach_encoder(struct intel_connector
*connector
,
145 struct intel_encoder
*encoder
)
147 connector
->encoder
= encoder
;
148 drm_connector_attach_encoder(&connector
->base
, &encoder
->base
);
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
156 bool intel_connector_get_hw_state(struct intel_connector
*connector
)
159 struct intel_encoder
*encoder
= intel_attached_encoder(connector
);
161 return encoder
->get_hw_state(encoder
, &pipe
);
164 enum pipe
intel_connector_get_pipe(struct intel_connector
*connector
)
166 struct drm_device
*dev
= connector
->base
.dev
;
169 !drm_modeset_is_locked(&dev
->mode_config
.connection_mutex
));
171 if (!connector
->base
.state
->crtc
)
174 return to_intel_crtc(connector
->base
.state
->crtc
)->pipe
;
178 * intel_connector_update_modes - update connector from edid
179 * @connector: DRM connector device to use
180 * @edid: previously read EDID information
182 int intel_connector_update_modes(struct drm_connector
*connector
,
187 drm_connector_update_edid_property(connector
, edid
);
188 ret
= drm_add_edid_modes(connector
, edid
);
194 * intel_ddc_get_modes - get modelist from monitor
195 * @connector: DRM connector device to use
196 * @adapter: i2c adapter
198 * Fetch the EDID information from @connector using the DDC bus.
200 int intel_ddc_get_modes(struct drm_connector
*connector
,
201 struct i2c_adapter
*adapter
)
206 edid
= drm_get_edid(connector
, adapter
);
210 ret
= intel_connector_update_modes(connector
, edid
);
216 static 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" },
224 intel_attach_force_audio_property(struct drm_connector
*connector
)
226 struct drm_device
*dev
= connector
->dev
;
227 struct drm_i915_private
*dev_priv
= to_i915(dev
);
228 struct drm_property
*prop
;
230 prop
= dev_priv
->force_audio_property
;
232 prop
= drm_property_create_enum(dev
, 0,
235 ARRAY_SIZE(force_audio_names
));
239 dev_priv
->force_audio_property
= prop
;
241 drm_object_attach_property(&connector
->base
, prop
, 0);
244 static 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" },
251 intel_attach_broadcast_rgb_property(struct drm_connector
*connector
)
253 struct drm_device
*dev
= connector
->dev
;
254 struct drm_i915_private
*dev_priv
= to_i915(dev
);
255 struct drm_property
*prop
;
257 prop
= dev_priv
->broadcast_rgb_property
;
259 prop
= drm_property_create_enum(dev
, DRM_MODE_PROP_ENUM
,
262 ARRAY_SIZE(broadcast_rgb_names
));
266 dev_priv
->broadcast_rgb_property
= prop
;
269 drm_object_attach_property(&connector
->base
, prop
, 0);
273 intel_attach_aspect_ratio_property(struct drm_connector
*connector
)
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
);
282 intel_attach_colorspace_property(struct drm_connector
*connector
)
284 switch (connector
->connector_type
) {
285 case DRM_MODE_CONNECTOR_HDMIA
:
286 case DRM_MODE_CONNECTOR_HDMIB
:
287 if (drm_mode_create_hdmi_colorspace_property(connector
))
290 case DRM_MODE_CONNECTOR_DisplayPort
:
291 case DRM_MODE_CONNECTOR_eDP
:
292 if (drm_mode_create_dp_colorspace_property(connector
))
296 MISSING_CASE(connector
->connector_type
);
300 drm_object_attach_property(&connector
->base
,
301 connector
->colorspace_property
, 0);