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