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_ENCODER_H__
28 #define __NOUVEAU_ENCODER_H__
29 
30 #include <subdev/bios/dcb.h>
31 
32 #include <drm/drm_encoder_slave.h>
33 #include <drm/drm_dp_mst_helper.h>
34 #include "dispnv04/disp.h"
35 struct nv50_head_atom;
36 struct nouveau_connector;
37 
38 #define NV_DPMS_CLEARED 0x80
39 
40 struct nvkm_i2c_port;
41 
42 struct nouveau_encoder {
43 	struct drm_encoder_slave base;
44 
45 	struct dcb_output *dcb;
46 	int or;
47 	int link;
48 
49 	struct i2c_adapter *i2c;
50 	struct nvkm_i2c_aux *aux;
51 
52 	/* different to drm_encoder.crtc, this reflects what's
53 	 * actually programmed on the hw, not the proposed crtc */
54 	struct drm_crtc *crtc;
55 	u32 ctrl;
56 	bool audio;
57 
58 	struct drm_display_mode mode;
59 	int last_dpms;
60 
61 	struct nv04_output_reg restore;
62 
63 	union {
64 		struct {
65 			struct nv50_mstm *mstm;
66 			int link_nr;
67 			int link_bw;
68 
69 			/* Protects DP state that needs to be accessed outside
70 			 * connector reprobing contexts
71 			 */
72 			struct mutex hpd_irq_lock;
73 
74 			u8 dpcd[DP_RECEIVER_CAP_SIZE];
75 			u8 downstream_ports[DP_MAX_DOWNSTREAM_PORTS];
76 			struct drm_dp_desc desc;
77 
78 			u8 sink_count;
79 		} dp;
80 	};
81 
82 	struct {
83 		bool dp_interlace : 1;
84 	} caps;
85 
86 	void (*enc_save)(struct drm_encoder *encoder);
87 	void (*enc_restore)(struct drm_encoder *encoder);
88 	void (*update)(struct nouveau_encoder *, u8 head,
89 		       struct nv50_head_atom *, u8 proto, u8 depth);
90 };
91 
92 struct nv50_mstm {
93 	struct nouveau_encoder *outp;
94 
95 	struct drm_dp_mst_topology_mgr mgr;
96 
97 	/* Protected under nouveau_encoder->dp.hpd_irq_lock */
98 	bool can_mst;
99 	bool is_mst;
100 	bool suspended;
101 
102 	bool modified;
103 	bool disabled;
104 	int links;
105 };
106 
107 struct nouveau_encoder *
108 find_encoder(struct drm_connector *connector, int type);
109 
110 static inline struct nouveau_encoder *nouveau_encoder(struct drm_encoder *enc)
111 {
112 	struct drm_encoder_slave *slave = to_encoder_slave(enc);
113 
114 	return container_of(slave, struct nouveau_encoder, base);
115 }
116 
117 static inline struct drm_encoder *to_drm_encoder(struct nouveau_encoder *enc)
118 {
119 	return &enc->base.base;
120 }
121 
122 static inline const struct drm_encoder_slave_funcs *
123 get_slave_funcs(struct drm_encoder *enc)
124 {
125 	return to_encoder_slave(enc)->slave_funcs;
126 }
127 
128 /* nouveau_dp.c */
129 enum nouveau_dp_status {
130 	NOUVEAU_DP_NONE,
131 	NOUVEAU_DP_SST,
132 	NOUVEAU_DP_MST,
133 };
134 
135 int nouveau_dp_detect(struct nouveau_connector *, struct nouveau_encoder *);
136 void nouveau_dp_irq(struct nouveau_drm *drm,
137 		    struct nouveau_connector *nv_connector);
138 enum drm_mode_status nv50_dp_mode_valid(struct drm_connector *,
139 					struct nouveau_encoder *,
140 					const struct drm_display_mode *,
141 					unsigned *clock);
142 
143 struct nouveau_connector *
144 nv50_outp_get_new_connector(struct nouveau_encoder *outp,
145 			    struct drm_atomic_state *state);
146 struct nouveau_connector *
147 nv50_outp_get_old_connector(struct nouveau_encoder *outp,
148 			    struct drm_atomic_state *state);
149 
150 int nv50_mstm_detect(struct nouveau_encoder *encoder);
151 void nv50_mstm_remove(struct nv50_mstm *mstm);
152 bool nv50_mstm_service(struct nouveau_drm *drm,
153 		       struct nouveau_connector *nv_connector,
154 		       struct nv50_mstm *mstm);
155 #endif /* __NOUVEAU_ENCODER_H__ */
156