Merge branch 'vendor/WPA_SUPPLICANT'
[dragonfly.git] / sys / dev / drm / i915 / intel_modes.c
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 <drm/drmP.h>
28 #include <drm/drm_edid.h>
29 #include "intel_drv.h"
30 #include "i915_drv.h"
31 #include <bus/iicbus/iiconf.h>
32
33 bool intel_ddc_probe(struct intel_encoder *intel_encoder, int ddc_bus)
34 {
35         struct drm_i915_private *dev_priv = intel_encoder->base.dev->dev_private;
36         u8 out_buf[] = { 0x0, 0x0};
37         u8 buf[2];
38         struct iic_msg msgs[] = {
39                 {
40                         .slave = DDC_ADDR << 1,
41                         .flags = IIC_M_WR,
42                         .len = 1,
43                         .buf = out_buf,
44                 },
45                 {
46                         .slave = DDC_ADDR << 1,
47                         .flags = IIC_M_RD,
48                         .len = 1,
49                         .buf = buf,
50                 }
51         };
52
53         return (iicbus_transfer(dev_priv->gmbus[ddc_bus], msgs, 2)
54             == 0/* XXXKIB  2*/);
55 }
56
57 /**
58  * intel_connector_update_modes - update connector from edid
59  * @connector: DRM connector device to use
60  * @edid: previously read EDID information
61  */
62 int intel_connector_update_modes(struct drm_connector *connector,
63                                 struct edid *edid)
64 {
65         int ret;
66
67         drm_mode_connector_update_edid_property(connector, edid);
68         ret = drm_add_edid_modes(connector, edid);
69         drm_edid_to_eld(connector, edid);
70
71         return ret;
72 }
73
74 /**
75  * intel_ddc_get_modes - get modelist from monitor
76  * @connector: DRM connector device to use
77  * @adapter: i2c adapter
78  *
79  * Fetch the EDID information from @connector using the DDC bus.
80  */
81 int intel_ddc_get_modes(struct drm_connector *connector,
82                         device_t adapter)
83 {
84         struct edid *edid;
85         int ret;
86
87         edid = drm_get_edid(connector, adapter);
88         if (!edid)
89                 return 0;
90
91         ret = intel_connector_update_modes(connector, edid);
92         kfree(edid, DRM_MEM_KMS);
93
94         return ret;
95 }
96
97 static const struct drm_prop_enum_list force_audio_names[] = {
98         { HDMI_AUDIO_OFF_DVI, "force-dvi" },
99         { HDMI_AUDIO_OFF, "off" },
100         { HDMI_AUDIO_AUTO, "auto" },
101         { HDMI_AUDIO_ON, "on" },
102 };
103
104 void
105 intel_attach_force_audio_property(struct drm_connector *connector)
106 {
107         struct drm_device *dev = connector->dev;
108         struct drm_i915_private *dev_priv = dev->dev_private;
109         struct drm_property *prop;
110
111         prop = dev_priv->force_audio_property;
112         if (prop == NULL) {
113                 prop = drm_property_create_enum(dev, 0,
114                                            "audio",
115                                            force_audio_names,
116                                            ARRAY_SIZE(force_audio_names));
117                 if (prop == NULL)
118                         return;
119
120                 dev_priv->force_audio_property = prop;
121         }
122         drm_object_attach_property(&connector->base, prop, 0);
123 }
124
125 static const struct drm_prop_enum_list broadcast_rgb_names[] = {
126         { 0, "Full" },
127         { 1, "Limited 16:235" },
128 };
129
130 void
131 intel_attach_broadcast_rgb_property(struct drm_connector *connector)
132 {
133         struct drm_device *dev = connector->dev;
134         struct drm_i915_private *dev_priv = dev->dev_private;
135         struct drm_property *prop;
136
137         prop = dev_priv->broadcast_rgb_property;
138         if (prop == NULL) {
139                 prop = drm_property_create_enum(dev, DRM_MODE_PROP_ENUM,
140                                            "Broadcast RGB",
141                                            broadcast_rgb_names,
142                                            ARRAY_SIZE(broadcast_rgb_names));
143                 if (prop == NULL)
144                         return;
145
146                 dev_priv->broadcast_rgb_property = prop;
147         }
148
149         drm_object_attach_property(&connector->base, prop, 0);
150 }