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/slab.h>
27 #include <linux/i2c.h>
28 #include <drm/drm_atomic_helper.h>
29 #include <drm/drm_edid.h>
30 #include "intel_drv.h"
33 int intel_connector_init(struct intel_connector *connector)
35 struct intel_digital_connector_state *conn_state;
38 * Allocate enough memory to hold intel_digital_connector_state,
39 * This might be a few bytes too many, but for connectors that don't
40 * need it we'll free the state and allocate a smaller one on the first
41 * successful commit anyway.
43 conn_state = kzalloc(sizeof(*conn_state), GFP_KERNEL);
47 __drm_atomic_helper_connector_reset(&connector->base,
53 struct intel_connector *intel_connector_alloc(void)
55 struct intel_connector *connector;
57 connector = kzalloc(sizeof(*connector), GFP_KERNEL);
61 if (intel_connector_init(connector) < 0) {
70 * Free the bits allocated by intel_connector_alloc.
71 * This should only be used after intel_connector_alloc has returned
72 * successfully, and before drm_connector_init returns successfully.
73 * Otherwise the destroy callbacks for the connector and the state should
74 * take care of proper cleanup/free (see intel_connector_destroy).
76 void intel_connector_free(struct intel_connector *connector)
78 kfree(to_intel_digital_connector_state(connector->base.state));
83 * Connector type independent destroy hook for drm_connector_funcs.
85 void intel_connector_destroy(struct drm_connector *connector)
87 struct intel_connector *intel_connector = to_intel_connector(connector);
89 kfree(intel_connector->detect_edid);
91 if (!IS_ERR_OR_NULL(intel_connector->edid))
92 kfree(intel_connector->edid);
94 intel_panel_fini(&intel_connector->panel);
96 drm_connector_cleanup(connector);
98 if (intel_connector->port)
99 drm_dp_mst_put_port_malloc(intel_connector->port);
104 int intel_connector_register(struct drm_connector *connector)
106 struct intel_connector *intel_connector = to_intel_connector(connector);
109 ret = intel_backlight_device_register(intel_connector);
113 if (i915_inject_load_failure()) {
121 intel_backlight_device_unregister(intel_connector);
126 void intel_connector_unregister(struct drm_connector *connector)
128 struct intel_connector *intel_connector = to_intel_connector(connector);
130 intel_backlight_device_unregister(intel_connector);
133 void intel_connector_attach_encoder(struct intel_connector *connector,
134 struct intel_encoder *encoder)
136 connector->encoder = encoder;
137 drm_connector_attach_encoder(&connector->base, &encoder->base);
141 * Simple connector->get_hw_state implementation for encoders that support only
142 * one connector and no cloning and hence the encoder state determines the state
145 bool intel_connector_get_hw_state(struct intel_connector *connector)
148 struct intel_encoder *encoder = connector->encoder;
150 return encoder->get_hw_state(encoder, &pipe);
153 enum pipe intel_connector_get_pipe(struct intel_connector *connector)
155 struct drm_device *dev = connector->base.dev;
157 WARN_ON(!drm_modeset_is_locked(&dev->mode_config.connection_mutex));
159 if (!connector->base.state->crtc)
162 return to_intel_crtc(connector->base.state->crtc)->pipe;
166 * intel_connector_update_modes - update connector from edid
167 * @connector: DRM connector device to use
168 * @edid: previously read EDID information
170 int intel_connector_update_modes(struct drm_connector *connector,
175 drm_connector_update_edid_property(connector, edid);
176 ret = drm_add_edid_modes(connector, edid);
182 * intel_ddc_get_modes - get modelist from monitor
183 * @connector: DRM connector device to use
184 * @adapter: i2c adapter
186 * Fetch the EDID information from @connector using the DDC bus.
188 int intel_ddc_get_modes(struct drm_connector *connector,
189 struct i2c_adapter *adapter)
194 edid = drm_get_edid(connector, adapter);
198 ret = intel_connector_update_modes(connector, edid);
204 static const struct drm_prop_enum_list force_audio_names[] = {
205 { HDMI_AUDIO_OFF_DVI, "force-dvi" },
206 { HDMI_AUDIO_OFF, "off" },
207 { HDMI_AUDIO_AUTO, "auto" },
208 { HDMI_AUDIO_ON, "on" },
212 intel_attach_force_audio_property(struct drm_connector *connector)
214 struct drm_device *dev = connector->dev;
215 struct drm_i915_private *dev_priv = to_i915(dev);
216 struct drm_property *prop;
218 prop = dev_priv->force_audio_property;
220 prop = drm_property_create_enum(dev, 0,
223 ARRAY_SIZE(force_audio_names));
227 dev_priv->force_audio_property = prop;
229 drm_object_attach_property(&connector->base, prop, 0);
232 static const struct drm_prop_enum_list broadcast_rgb_names[] = {
233 { INTEL_BROADCAST_RGB_AUTO, "Automatic" },
234 { INTEL_BROADCAST_RGB_FULL, "Full" },
235 { INTEL_BROADCAST_RGB_LIMITED, "Limited 16:235" },
239 intel_attach_broadcast_rgb_property(struct drm_connector *connector)
241 struct drm_device *dev = connector->dev;
242 struct drm_i915_private *dev_priv = to_i915(dev);
243 struct drm_property *prop;
245 prop = dev_priv->broadcast_rgb_property;
247 prop = drm_property_create_enum(dev, DRM_MODE_PROP_ENUM,
250 ARRAY_SIZE(broadcast_rgb_names));
254 dev_priv->broadcast_rgb_property = prop;
257 drm_object_attach_property(&connector->base, prop, 0);
261 intel_attach_aspect_ratio_property(struct drm_connector *connector)
263 if (!drm_mode_create_aspect_ratio_property(connector->dev))
264 drm_object_attach_property(&connector->base,
265 connector->dev->mode_config.aspect_ratio_property,
266 DRM_MODE_PICTURE_ASPECT_NONE);