xref: /dflybsd-src/sys/dev/drm/i915/intel_modes.c (revision 3f2dd94a569761201b5b0a18b2f697f97fe1b9dc)
1e3adcf8fSFrançois Tigeot /*
2e3adcf8fSFrançois Tigeot  * Copyright (c) 2007 Dave Airlie <airlied@linux.ie>
3e3adcf8fSFrançois Tigeot  * Copyright (c) 2007, 2010 Intel Corporation
4e3adcf8fSFrançois Tigeot  *   Jesse Barnes <jesse.barnes@intel.com>
5e3adcf8fSFrançois Tigeot  *
6e3adcf8fSFrançois Tigeot  * Permission is hereby granted, free of charge, to any person obtaining a
7e3adcf8fSFrançois Tigeot  * copy of this software and associated documentation files (the "Software"),
8e3adcf8fSFrançois Tigeot  * to deal in the Software without restriction, including without limitation
9e3adcf8fSFrançois Tigeot  * the rights to use, copy, modify, merge, publish, distribute, sublicense,
10e3adcf8fSFrançois Tigeot  * and/or sell copies of the Software, and to permit persons to whom the
11e3adcf8fSFrançois Tigeot  * Software is furnished to do so, subject to the following conditions:
12e3adcf8fSFrançois Tigeot  *
13e3adcf8fSFrançois Tigeot  * The above copyright notice and this permission notice (including the next
14e3adcf8fSFrançois Tigeot  * paragraph) shall be included in all copies or substantial portions of the
15e3adcf8fSFrançois Tigeot  * Software.
16e3adcf8fSFrançois Tigeot  *
17e3adcf8fSFrançois Tigeot  * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
18e3adcf8fSFrançois Tigeot  * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
19e3adcf8fSFrançois Tigeot  * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.  IN NO EVENT SHALL
20e3adcf8fSFrançois Tigeot  * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
21e3adcf8fSFrançois Tigeot  * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
22e3adcf8fSFrançois Tigeot  * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
23e3adcf8fSFrançois Tigeot  * DEALINGS IN THE SOFTWARE.
24e3adcf8fSFrançois Tigeot  */
25e3adcf8fSFrançois Tigeot 
261487f786SFrançois Tigeot #include <linux/slab.h>
272c84b0b6SFrançois Tigeot #include <linux/i2c.h>
2818e26a6dSFrançois Tigeot #include <drm/drm_edid.h>
29a2fdbec6SFrançois Tigeot #include <drm/drmP.h>
30e3adcf8fSFrançois Tigeot #include "intel_drv.h"
3118e26a6dSFrançois Tigeot #include "i915_drv.h"
32e3adcf8fSFrançois Tigeot 
intel_connector_update_eld_conn_type(struct drm_connector * connector)33*3f2dd94aSFrançois Tigeot static void intel_connector_update_eld_conn_type(struct drm_connector *connector)
34*3f2dd94aSFrançois Tigeot {
35*3f2dd94aSFrançois Tigeot 	u8 conn_type;
36*3f2dd94aSFrançois Tigeot 
37*3f2dd94aSFrançois Tigeot 	if (connector->connector_type == DRM_MODE_CONNECTOR_DisplayPort ||
38*3f2dd94aSFrançois Tigeot 	    connector->connector_type == DRM_MODE_CONNECTOR_eDP) {
39*3f2dd94aSFrançois Tigeot 		conn_type = DRM_ELD_CONN_TYPE_DP;
40*3f2dd94aSFrançois Tigeot 	} else {
41*3f2dd94aSFrançois Tigeot 		conn_type = DRM_ELD_CONN_TYPE_HDMI;
42*3f2dd94aSFrançois Tigeot 	}
43*3f2dd94aSFrançois Tigeot 
44*3f2dd94aSFrançois Tigeot 	connector->eld[DRM_ELD_SAD_COUNT_CONN_TYPE] &= ~DRM_ELD_CONN_TYPE_MASK;
45*3f2dd94aSFrançois Tigeot 	connector->eld[DRM_ELD_SAD_COUNT_CONN_TYPE] |= conn_type;
46*3f2dd94aSFrançois Tigeot }
47*3f2dd94aSFrançois Tigeot 
48e3adcf8fSFrançois Tigeot /**
492c84b0b6SFrançois Tigeot  * intel_connector_update_modes - update connector from edid
502c84b0b6SFrançois Tigeot  * @connector: DRM connector device to use
512c84b0b6SFrançois Tigeot  * @edid: previously read EDID information
522c84b0b6SFrançois Tigeot  */
intel_connector_update_modes(struct drm_connector * connector,struct edid * edid)532c84b0b6SFrançois Tigeot int intel_connector_update_modes(struct drm_connector *connector,
542c84b0b6SFrançois Tigeot 				struct edid *edid)
552c84b0b6SFrançois Tigeot {
562c84b0b6SFrançois Tigeot 	int ret;
572c84b0b6SFrançois Tigeot 
582c84b0b6SFrançois Tigeot 	drm_mode_connector_update_edid_property(connector, edid);
592c84b0b6SFrançois Tigeot 	ret = drm_add_edid_modes(connector, edid);
602c84b0b6SFrançois Tigeot 	drm_edid_to_eld(connector, edid);
612c84b0b6SFrançois Tigeot 
62*3f2dd94aSFrançois Tigeot 	intel_connector_update_eld_conn_type(connector);
63*3f2dd94aSFrançois Tigeot 
642c84b0b6SFrançois Tigeot 	return ret;
652c84b0b6SFrançois Tigeot }
662c84b0b6SFrançois Tigeot 
672c84b0b6SFrançois Tigeot /**
68e3adcf8fSFrançois Tigeot  * intel_ddc_get_modes - get modelist from monitor
69e3adcf8fSFrançois Tigeot  * @connector: DRM connector device to use
70e3adcf8fSFrançois Tigeot  * @adapter: i2c adapter
71e3adcf8fSFrançois Tigeot  *
72e3adcf8fSFrançois Tigeot  * Fetch the EDID information from @connector using the DDC bus.
73e3adcf8fSFrançois Tigeot  */
intel_ddc_get_modes(struct drm_connector * connector,struct i2c_adapter * adapter)742c84b0b6SFrançois Tigeot int intel_ddc_get_modes(struct drm_connector *connector,
7524edb884SFrançois Tigeot 			struct i2c_adapter *adapter)
76e3adcf8fSFrançois Tigeot {
77e3adcf8fSFrançois Tigeot 	struct edid *edid;
782c84b0b6SFrançois Tigeot 	int ret;
79e3adcf8fSFrançois Tigeot 
80e3adcf8fSFrançois Tigeot 	edid = drm_get_edid(connector, adapter);
812c84b0b6SFrançois Tigeot 	if (!edid)
822c84b0b6SFrançois Tigeot 		return 0;
832c84b0b6SFrançois Tigeot 
842c84b0b6SFrançois Tigeot 	ret = intel_connector_update_modes(connector, edid);
85158486a6SFrançois Tigeot 	kfree(edid);
86e3adcf8fSFrançois Tigeot 
87e3adcf8fSFrançois Tigeot 	return ret;
88e3adcf8fSFrançois Tigeot }
89e3adcf8fSFrançois Tigeot 
90e3adcf8fSFrançois Tigeot static const struct drm_prop_enum_list force_audio_names[] = {
91e3adcf8fSFrançois Tigeot 	{ HDMI_AUDIO_OFF_DVI, "force-dvi" },
92e3adcf8fSFrançois Tigeot 	{ HDMI_AUDIO_OFF, "off" },
93e3adcf8fSFrançois Tigeot 	{ HDMI_AUDIO_AUTO, "auto" },
94e3adcf8fSFrançois Tigeot 	{ HDMI_AUDIO_ON, "on" },
95e3adcf8fSFrançois Tigeot };
96e3adcf8fSFrançois Tigeot 
97e3adcf8fSFrançois Tigeot void
intel_attach_force_audio_property(struct drm_connector * connector)98e3adcf8fSFrançois Tigeot intel_attach_force_audio_property(struct drm_connector *connector)
99e3adcf8fSFrançois Tigeot {
100e3adcf8fSFrançois Tigeot 	struct drm_device *dev = connector->dev;
101bf017597SFrançois Tigeot 	struct drm_i915_private *dev_priv = to_i915(dev);
102e3adcf8fSFrançois Tigeot 	struct drm_property *prop;
103e3adcf8fSFrançois Tigeot 
104e3adcf8fSFrançois Tigeot 	prop = dev_priv->force_audio_property;
105e3adcf8fSFrançois Tigeot 	if (prop == NULL) {
106e3adcf8fSFrançois Tigeot 		prop = drm_property_create_enum(dev, 0,
107e3adcf8fSFrançois Tigeot 					   "audio",
108e3adcf8fSFrançois Tigeot 					   force_audio_names,
1092c84b0b6SFrançois Tigeot 					   ARRAY_SIZE(force_audio_names));
110e3adcf8fSFrançois Tigeot 		if (prop == NULL)
111e3adcf8fSFrançois Tigeot 			return;
112e3adcf8fSFrançois Tigeot 
113e3adcf8fSFrançois Tigeot 		dev_priv->force_audio_property = prop;
114e3adcf8fSFrançois Tigeot 	}
115b5162e19SFrançois Tigeot 	drm_object_attach_property(&connector->base, prop, 0);
116e3adcf8fSFrançois Tigeot }
117e3adcf8fSFrançois Tigeot 
118e3adcf8fSFrançois Tigeot static const struct drm_prop_enum_list broadcast_rgb_names[] = {
119a2fdbec6SFrançois Tigeot 	{ INTEL_BROADCAST_RGB_AUTO, "Automatic" },
120a2fdbec6SFrançois Tigeot 	{ INTEL_BROADCAST_RGB_FULL, "Full" },
121a2fdbec6SFrançois Tigeot 	{ INTEL_BROADCAST_RGB_LIMITED, "Limited 16:235" },
122e3adcf8fSFrançois Tigeot };
123e3adcf8fSFrançois Tigeot 
124e3adcf8fSFrançois Tigeot void
intel_attach_broadcast_rgb_property(struct drm_connector * connector)125e3adcf8fSFrançois Tigeot intel_attach_broadcast_rgb_property(struct drm_connector *connector)
126e3adcf8fSFrançois Tigeot {
127e3adcf8fSFrançois Tigeot 	struct drm_device *dev = connector->dev;
128bf017597SFrançois Tigeot 	struct drm_i915_private *dev_priv = to_i915(dev);
129e3adcf8fSFrançois Tigeot 	struct drm_property *prop;
130e3adcf8fSFrançois Tigeot 
131e3adcf8fSFrançois Tigeot 	prop = dev_priv->broadcast_rgb_property;
132e3adcf8fSFrançois Tigeot 	if (prop == NULL) {
133e3adcf8fSFrançois Tigeot 		prop = drm_property_create_enum(dev, DRM_MODE_PROP_ENUM,
134e3adcf8fSFrançois Tigeot 					   "Broadcast RGB",
135e3adcf8fSFrançois Tigeot 					   broadcast_rgb_names,
1362c84b0b6SFrançois Tigeot 					   ARRAY_SIZE(broadcast_rgb_names));
137e3adcf8fSFrançois Tigeot 		if (prop == NULL)
138e3adcf8fSFrançois Tigeot 			return;
139e3adcf8fSFrançois Tigeot 
140e3adcf8fSFrançois Tigeot 		dev_priv->broadcast_rgb_property = prop;
141e3adcf8fSFrançois Tigeot 	}
142e3adcf8fSFrançois Tigeot 
143b5162e19SFrançois Tigeot 	drm_object_attach_property(&connector->base, prop, 0);
144e3adcf8fSFrançois Tigeot }
145352ff8bdSFrançois Tigeot 
146352ff8bdSFrançois Tigeot void
intel_attach_aspect_ratio_property(struct drm_connector * connector)147352ff8bdSFrançois Tigeot intel_attach_aspect_ratio_property(struct drm_connector *connector)
148352ff8bdSFrançois Tigeot {
149352ff8bdSFrançois Tigeot 	if (!drm_mode_create_aspect_ratio_property(connector->dev))
150352ff8bdSFrançois Tigeot 		drm_object_attach_property(&connector->base,
151352ff8bdSFrançois Tigeot 			connector->dev->mode_config.aspect_ratio_property,
152352ff8bdSFrançois Tigeot 			DRM_MODE_PICTURE_ASPECT_NONE);
153352ff8bdSFrançois Tigeot }
154