6f89d4938059bbfc1cca45682fc3e475f589f027
[linux-2.6-microblaze.git] / drivers / gpu / drm / nouveau / nouveau_connector.h
1 /*
2  * Copyright (C) 2008 Maarten Maathuis.
3  * All Rights Reserved.
4  *
5  * Permission is hereby granted, free of charge, to any person obtaining
6  * a copy of this software and associated documentation files (the
7  * "Software"), to deal in the Software without restriction, including
8  * without limitation the rights to use, copy, modify, merge, publish,
9  * distribute, sublicense, and/or sell copies of the Software, and to
10  * permit persons to whom the Software is furnished to do so, subject to
11  * the following conditions:
12  *
13  * The above copyright notice and this permission notice (including the
14  * next paragraph) shall be included in all copies or substantial
15  * portions of the Software.
16  *
17  * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
18  * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
19  * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
20  * IN NO EVENT SHALL THE COPYRIGHT OWNER(S) AND/OR ITS SUPPLIERS BE
21  * LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
22  * OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
23  * WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
24  *
25  */
26
27 #ifndef __NOUVEAU_CONNECTOR_H__
28 #define __NOUVEAU_CONNECTOR_H__
29
30 #include <nvif/notify.h>
31
32 #include <drm/drm_edid.h>
33 #include <drm/drm_encoder.h>
34 #include <drm/drm_dp_helper.h>
35 #include <drm/drm_util.h>
36
37 #include "nouveau_crtc.h"
38 #include "nouveau_encoder.h"
39
40 struct nvkm_i2c_port;
41
42 #ifdef CONFIG_DRM_NOUVEAU_BACKLIGHT
43 struct nouveau_backlight;
44 #endif
45
46 struct nouveau_connector {
47         struct drm_connector base;
48         enum dcb_connector_type type;
49         u8 index;
50         u8 *dcb;
51
52         struct nvif_notify hpd;
53
54         struct drm_dp_aux aux;
55
56         int dithering_mode;
57         int scaling_mode;
58
59         struct nouveau_encoder *detected_encoder;
60         struct edid *edid;
61         struct drm_display_mode *native_mode;
62 #ifdef CONFIG_DRM_NOUVEAU_BACKLIGHT
63         struct nouveau_backlight *backlight;
64 #endif
65 };
66
67 static inline struct nouveau_connector *nouveau_connector(
68                                                 struct drm_connector *con)
69 {
70         return container_of(con, struct nouveau_connector, base);
71 }
72
73 static inline bool
74 nouveau_connector_is_mst(struct drm_connector *connector)
75 {
76         const struct nouveau_encoder *nv_encoder;
77         const struct drm_encoder *encoder;
78
79         if (connector->connector_type != DRM_MODE_CONNECTOR_DisplayPort)
80                 return false;
81
82         nv_encoder = find_encoder(connector, DCB_OUTPUT_ANY);
83         if (!nv_encoder)
84                 return false;
85
86         encoder = &nv_encoder->base.base;
87         return encoder->encoder_type == DRM_MODE_ENCODER_DPMST;
88 }
89
90 #define nouveau_for_each_non_mst_connector_iter(connector, iter) \
91         drm_for_each_connector_iter(connector, iter) \
92                 for_each_if(!nouveau_connector_is_mst(connector))
93
94 static inline struct nouveau_connector *
95 nouveau_crtc_connector_get(struct nouveau_crtc *nv_crtc)
96 {
97         struct drm_device *dev = nv_crtc->base.dev;
98         struct drm_connector *connector;
99         struct drm_connector_list_iter conn_iter;
100         struct nouveau_connector *nv_connector = NULL;
101         struct drm_crtc *crtc = to_drm_crtc(nv_crtc);
102
103         drm_connector_list_iter_begin(dev, &conn_iter);
104         nouveau_for_each_non_mst_connector_iter(connector, &conn_iter) {
105                 if (connector->encoder && connector->encoder->crtc == crtc) {
106                         nv_connector = nouveau_connector(connector);
107                         break;
108                 }
109         }
110         drm_connector_list_iter_end(&conn_iter);
111
112         return nv_connector;
113 }
114
115 struct drm_connector *
116 nouveau_connector_create(struct drm_device *, int index);
117
118 extern int nouveau_tv_disable;
119 extern int nouveau_ignorelid;
120 extern int nouveau_duallink;
121 extern int nouveau_hdmimhz;
122
123 #include <drm/drm_crtc.h>
124 #define nouveau_conn_atom(p)                                                   \
125         container_of((p), struct nouveau_conn_atom, state)
126
127 struct nouveau_conn_atom {
128         struct drm_connector_state state;
129
130         struct {
131                 /* The enum values specifically defined here match nv50/gf119
132                  * hw values, and the code relies on this.
133                  */
134                 enum {
135                         DITHERING_MODE_OFF = 0x00,
136                         DITHERING_MODE_ON = 0x01,
137                         DITHERING_MODE_DYNAMIC2X2 = 0x10 | DITHERING_MODE_ON,
138                         DITHERING_MODE_STATIC2X2 = 0x18 | DITHERING_MODE_ON,
139                         DITHERING_MODE_TEMPORAL = 0x20 | DITHERING_MODE_ON,
140                         DITHERING_MODE_AUTO
141                 } mode;
142                 enum {
143                         DITHERING_DEPTH_6BPC = 0x00,
144                         DITHERING_DEPTH_8BPC = 0x02,
145                         DITHERING_DEPTH_AUTO
146                 } depth;
147         } dither;
148
149         struct {
150                 int mode;       /* DRM_MODE_SCALE_* */
151                 struct {
152                         enum {
153                                 UNDERSCAN_OFF,
154                                 UNDERSCAN_ON,
155                                 UNDERSCAN_AUTO,
156                         } mode;
157                         u32 hborder;
158                         u32 vborder;
159                 } underscan;
160                 bool full;
161         } scaler;
162
163         struct {
164                 int color_vibrance;
165                 int vibrant_hue;
166         } procamp;
167
168         union {
169                 struct {
170                         bool dither:1;
171                         bool scaler:1;
172                         bool procamp:1;
173                 };
174                 u8 mask;
175         } set;
176 };
177
178 void nouveau_conn_attach_properties(struct drm_connector *);
179 void nouveau_conn_reset(struct drm_connector *);
180 struct drm_connector_state *
181 nouveau_conn_atomic_duplicate_state(struct drm_connector *);
182 void nouveau_conn_atomic_destroy_state(struct drm_connector *,
183                                        struct drm_connector_state *);
184 int nouveau_conn_atomic_set_property(struct drm_connector *,
185                                      struct drm_connector_state *,
186                                      struct drm_property *, u64);
187 int nouveau_conn_atomic_get_property(struct drm_connector *,
188                                      const struct drm_connector_state *,
189                                      struct drm_property *, u64 *);
190 struct drm_display_mode *nouveau_conn_native_mode(struct drm_connector *);
191
192 #ifdef CONFIG_DRM_NOUVEAU_BACKLIGHT
193 extern int nouveau_backlight_init(struct drm_connector *);
194 extern void nouveau_backlight_exit(struct drm_connector *);
195 extern void nouveau_backlight_ctor(void);
196 extern void nouveau_backlight_dtor(void);
197 #else
198 static inline int
199 nouveau_backlight_init(struct drm_connector *connector)
200 {
201         return 0;
202 }
203
204 static inline void
205 nouveau_backlight_exit(struct drm_connector *connector) {
206 }
207
208 static inline void
209 nouveau_backlight_ctor(void) {
210 }
211
212 static inline void
213 nouveau_backlight_dtor(void) {
214 }
215 #endif
216
217 #endif /* __NOUVEAU_CONNECTOR_H__ */