xref: /dflybsd-src/sys/dev/drm/i915/intel_modes.c (revision 352ff8bd644eb2f17a1b01fa757342a01f012051)
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 
262c84b0b6SFrançois Tigeot #include <linux/i2c.h>
2724edb884SFrançois Tigeot #include <linux/fb.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 
33e3adcf8fSFrançois Tigeot /**
342c84b0b6SFrançois Tigeot  * intel_connector_update_modes - update connector from edid
352c84b0b6SFrançois Tigeot  * @connector: DRM connector device to use
362c84b0b6SFrançois Tigeot  * @edid: previously read EDID information
372c84b0b6SFrançois Tigeot  */
382c84b0b6SFrançois Tigeot int intel_connector_update_modes(struct drm_connector *connector,
392c84b0b6SFrançois Tigeot 				struct edid *edid)
402c84b0b6SFrançois Tigeot {
412c84b0b6SFrançois Tigeot 	int ret;
422c84b0b6SFrançois Tigeot 
432c84b0b6SFrançois Tigeot 	drm_mode_connector_update_edid_property(connector, edid);
442c84b0b6SFrançois Tigeot 	ret = drm_add_edid_modes(connector, edid);
452c84b0b6SFrançois Tigeot 	drm_edid_to_eld(connector, edid);
462c84b0b6SFrançois Tigeot 
472c84b0b6SFrançois Tigeot 	return ret;
482c84b0b6SFrançois Tigeot }
492c84b0b6SFrançois Tigeot 
502c84b0b6SFrançois Tigeot /**
51e3adcf8fSFrançois Tigeot  * intel_ddc_get_modes - get modelist from monitor
52e3adcf8fSFrançois Tigeot  * @connector: DRM connector device to use
53e3adcf8fSFrançois Tigeot  * @adapter: i2c adapter
54e3adcf8fSFrançois Tigeot  *
55e3adcf8fSFrançois Tigeot  * Fetch the EDID information from @connector using the DDC bus.
56e3adcf8fSFrançois Tigeot  */
572c84b0b6SFrançois Tigeot int intel_ddc_get_modes(struct drm_connector *connector,
5824edb884SFrançois Tigeot 			struct i2c_adapter *adapter)
59e3adcf8fSFrançois Tigeot {
60e3adcf8fSFrançois Tigeot 	struct edid *edid;
612c84b0b6SFrançois Tigeot 	int ret;
62e3adcf8fSFrançois Tigeot 
63e3adcf8fSFrançois Tigeot 	edid = drm_get_edid(connector, adapter);
642c84b0b6SFrançois Tigeot 	if (!edid)
652c84b0b6SFrançois Tigeot 		return 0;
662c84b0b6SFrançois Tigeot 
672c84b0b6SFrançois Tigeot 	ret = intel_connector_update_modes(connector, edid);
68158486a6SFrançois Tigeot 	kfree(edid);
69e3adcf8fSFrançois Tigeot 
70e3adcf8fSFrançois Tigeot 	return ret;
71e3adcf8fSFrançois Tigeot }
72e3adcf8fSFrançois Tigeot 
73e3adcf8fSFrançois Tigeot static const struct drm_prop_enum_list force_audio_names[] = {
74e3adcf8fSFrançois Tigeot 	{ HDMI_AUDIO_OFF_DVI, "force-dvi" },
75e3adcf8fSFrançois Tigeot 	{ HDMI_AUDIO_OFF, "off" },
76e3adcf8fSFrançois Tigeot 	{ HDMI_AUDIO_AUTO, "auto" },
77e3adcf8fSFrançois Tigeot 	{ HDMI_AUDIO_ON, "on" },
78e3adcf8fSFrançois Tigeot };
79e3adcf8fSFrançois Tigeot 
80e3adcf8fSFrançois Tigeot void
81e3adcf8fSFrançois Tigeot intel_attach_force_audio_property(struct drm_connector *connector)
82e3adcf8fSFrançois Tigeot {
83e3adcf8fSFrançois Tigeot 	struct drm_device *dev = connector->dev;
84e3adcf8fSFrançois Tigeot 	struct drm_i915_private *dev_priv = dev->dev_private;
85e3adcf8fSFrançois Tigeot 	struct drm_property *prop;
86e3adcf8fSFrançois Tigeot 
87e3adcf8fSFrançois Tigeot 	prop = dev_priv->force_audio_property;
88e3adcf8fSFrançois Tigeot 	if (prop == NULL) {
89e3adcf8fSFrançois Tigeot 		prop = drm_property_create_enum(dev, 0,
90e3adcf8fSFrançois Tigeot 					   "audio",
91e3adcf8fSFrançois Tigeot 					   force_audio_names,
922c84b0b6SFrançois Tigeot 					   ARRAY_SIZE(force_audio_names));
93e3adcf8fSFrançois Tigeot 		if (prop == NULL)
94e3adcf8fSFrançois Tigeot 			return;
95e3adcf8fSFrançois Tigeot 
96e3adcf8fSFrançois Tigeot 		dev_priv->force_audio_property = prop;
97e3adcf8fSFrançois Tigeot 	}
98b5162e19SFrançois Tigeot 	drm_object_attach_property(&connector->base, prop, 0);
99e3adcf8fSFrançois Tigeot }
100e3adcf8fSFrançois Tigeot 
101e3adcf8fSFrançois Tigeot static const struct drm_prop_enum_list broadcast_rgb_names[] = {
102a2fdbec6SFrançois Tigeot 	{ INTEL_BROADCAST_RGB_AUTO, "Automatic" },
103a2fdbec6SFrançois Tigeot 	{ INTEL_BROADCAST_RGB_FULL, "Full" },
104a2fdbec6SFrançois Tigeot 	{ INTEL_BROADCAST_RGB_LIMITED, "Limited 16:235" },
105e3adcf8fSFrançois Tigeot };
106e3adcf8fSFrançois Tigeot 
107e3adcf8fSFrançois Tigeot void
108e3adcf8fSFrançois Tigeot intel_attach_broadcast_rgb_property(struct drm_connector *connector)
109e3adcf8fSFrançois Tigeot {
110e3adcf8fSFrançois Tigeot 	struct drm_device *dev = connector->dev;
111e3adcf8fSFrançois Tigeot 	struct drm_i915_private *dev_priv = dev->dev_private;
112e3adcf8fSFrançois Tigeot 	struct drm_property *prop;
113e3adcf8fSFrançois Tigeot 
114e3adcf8fSFrançois Tigeot 	prop = dev_priv->broadcast_rgb_property;
115e3adcf8fSFrançois Tigeot 	if (prop == NULL) {
116e3adcf8fSFrançois Tigeot 		prop = drm_property_create_enum(dev, DRM_MODE_PROP_ENUM,
117e3adcf8fSFrançois Tigeot 					   "Broadcast RGB",
118e3adcf8fSFrançois Tigeot 					   broadcast_rgb_names,
1192c84b0b6SFrançois Tigeot 					   ARRAY_SIZE(broadcast_rgb_names));
120e3adcf8fSFrançois Tigeot 		if (prop == NULL)
121e3adcf8fSFrançois Tigeot 			return;
122e3adcf8fSFrançois Tigeot 
123e3adcf8fSFrançois Tigeot 		dev_priv->broadcast_rgb_property = prop;
124e3adcf8fSFrançois Tigeot 	}
125e3adcf8fSFrançois Tigeot 
126b5162e19SFrançois Tigeot 	drm_object_attach_property(&connector->base, prop, 0);
127e3adcf8fSFrançois Tigeot }
128*352ff8bdSFrançois Tigeot 
129*352ff8bdSFrançois Tigeot void
130*352ff8bdSFrançois Tigeot intel_attach_aspect_ratio_property(struct drm_connector *connector)
131*352ff8bdSFrançois Tigeot {
132*352ff8bdSFrançois Tigeot 	if (!drm_mode_create_aspect_ratio_property(connector->dev))
133*352ff8bdSFrançois Tigeot 		drm_object_attach_property(&connector->base,
134*352ff8bdSFrançois Tigeot 			connector->dev->mode_config.aspect_ratio_property,
135*352ff8bdSFrançois Tigeot 			DRM_MODE_PICTURE_ASPECT_NONE);
136*352ff8bdSFrançois Tigeot }
137