1 /* SPDX-License-Identifier: MIT */
2 #ifndef __NVKM_DISP_IOR_H__
3 #define __NVKM_DISP_IOR_H__
4 #include "priv.h"
5 struct nvkm_i2c_aux;
6 
7 struct nvkm_ior {
8 	const struct nvkm_ior_func *func;
9 	struct nvkm_disp *disp;
10 	enum nvkm_ior_type {
11 		DAC,
12 		SOR,
13 		PIOR,
14 	} type;
15 	int id;
16 	bool hda;
17 	char name[8];
18 
19 	struct list_head head;
20 	bool identity;
21 
22 	struct nvkm_ior_state {
23 		struct nvkm_outp *outp;
24 		unsigned rgdiv;
25 		unsigned proto_evo:4;
26 		enum nvkm_ior_proto {
27 			CRT,
28 			TV,
29 			TMDS,
30 			LVDS,
31 			DP,
32 			UNKNOWN
33 		} proto:3;
34 		unsigned link:2;
35 		unsigned head:8;
36 	} arm, asy;
37 
38 	/* Armed DP state. */
39 	struct {
40 		bool mst;
41 		bool ef;
42 		u8 nr;
43 		u8 bw;
44 	} dp;
45 
46 	/* Armed TMDS state. */
47 	struct {
48 		bool high_speed;
49 	} tmds;
50 };
51 
52 struct nvkm_ior_func {
53 	struct {
54 		int (*get)(struct nvkm_outp *, int *link);
55 		void (*set)(struct nvkm_outp *, struct nvkm_ior *);
56 	} route;
57 
58 	void (*state)(struct nvkm_ior *, struct nvkm_ior_state *);
59 	void (*power)(struct nvkm_ior *, bool normal, bool pu,
60 		      bool data, bool vsync, bool hsync);
61 	int (*sense)(struct nvkm_ior *, u32 loadval);
62 	void (*clock)(struct nvkm_ior *);
63 	void (*war_2)(struct nvkm_ior *);
64 	void (*war_3)(struct nvkm_ior *);
65 
66 	const struct nvkm_ior_func_hdmi {
67 		void (*ctrl)(struct nvkm_ior *, int head, bool enable, u8 max_ac_packet, u8 rekey);
68 		void (*scdc)(struct nvkm_ior *, u8 scdc);
69 		void (*infoframe_avi)(struct nvkm_ior *, int head, void *data, u32 size);
70 		void (*infoframe_vsi)(struct nvkm_ior *, int head, void *data, u32 size);
71 	} *hdmi;
72 
73 	const struct nvkm_ior_func_dp {
74 		u8 lanes[4];
75 		int (*links)(struct nvkm_ior *, struct nvkm_i2c_aux *);
76 		void (*power)(struct nvkm_ior *, int nr);
77 		void (*pattern)(struct nvkm_ior *, int pattern);
78 		void (*drive)(struct nvkm_ior *, int ln, int pc,
79 			      int dc, int pe, int tx_pu);
80 		void (*vcpi)(struct nvkm_ior *, int head, u8 slot,
81 			     u8 slot_nr, u16 pbn, u16 aligned);
82 		void (*audio)(struct nvkm_ior *, int head, bool enable);
83 		void (*audio_sym)(struct nvkm_ior *, int head, u16 h, u32 v);
84 		void (*activesym)(struct nvkm_ior *, int head,
85 				  u8 TU, u8 VTUa, u8 VTUf, u8 VTUi);
86 		void (*watermark)(struct nvkm_ior *, int head, u8 watermark);
87 	} *dp;
88 
89 	const struct nvkm_ior_func_hda {
90 		void (*hpd)(struct nvkm_ior *, int head, bool present);
91 		void (*eld)(struct nvkm_ior *, int head, u8 *data, u8 size);
92 		void (*device_entry)(struct nvkm_ior *, int head);
93 	} *hda;
94 };
95 
96 int nvkm_ior_new_(const struct nvkm_ior_func *func, struct nvkm_disp *,
97 		  enum nvkm_ior_type type, int id, bool hda);
98 void nvkm_ior_del(struct nvkm_ior **);
99 struct nvkm_ior *nvkm_ior_find(struct nvkm_disp *, enum nvkm_ior_type, int id);
100 
101 static inline u32
102 nv50_ior_base(struct nvkm_ior *ior)
103 {
104 	return ior->id * 0x800;
105 }
106 
107 int nv50_dac_cnt(struct nvkm_disp *, unsigned long *);
108 int nv50_dac_new(struct nvkm_disp *, int);
109 void nv50_dac_power(struct nvkm_ior *, bool, bool, bool, bool, bool);
110 int nv50_dac_sense(struct nvkm_ior *, u32);
111 
112 int gf119_dac_cnt(struct nvkm_disp *, unsigned long *);
113 int gf119_dac_new(struct nvkm_disp *, int);
114 
115 static inline u32
116 nv50_sor_link(struct nvkm_ior *ior)
117 {
118 	return nv50_ior_base(ior) + ((ior->asy.link == 2) * 0x80);
119 }
120 
121 int nv50_sor_cnt(struct nvkm_disp *, unsigned long *);
122 void nv50_sor_state(struct nvkm_ior *, struct nvkm_ior_state *);
123 void nv50_sor_power(struct nvkm_ior *, bool, bool, bool, bool, bool);
124 void nv50_sor_clock(struct nvkm_ior *);
125 
126 int g84_sor_new(struct nvkm_disp *, int);
127 extern const struct nvkm_ior_func_hdmi g84_sor_hdmi;
128 
129 int g94_sor_cnt(struct nvkm_disp *, unsigned long *);
130 
131 void g94_sor_state(struct nvkm_ior *, struct nvkm_ior_state *);
132 extern const struct nvkm_ior_func_dp g94_sor_dp;
133 int g94_sor_dp_links(struct nvkm_ior *, struct nvkm_i2c_aux *);
134 void g94_sor_dp_power(struct nvkm_ior *, int);
135 void g94_sor_dp_pattern(struct nvkm_ior *, int);
136 void g94_sor_dp_drive(struct nvkm_ior *, int, int, int, int, int);
137 void g94_sor_dp_audio_sym(struct nvkm_ior *, int, u16, u32);
138 void g94_sor_dp_activesym(struct nvkm_ior *, int, u8, u8, u8, u8);
139 void g94_sor_dp_watermark(struct nvkm_ior *, int, u8);
140 
141 extern const struct nvkm_ior_func_hdmi gt215_sor_hdmi;
142 void gt215_sor_dp_audio(struct nvkm_ior *, int, bool);
143 extern const struct nvkm_ior_func_hda gt215_sor_hda;
144 
145 int gf119_sor_cnt(struct nvkm_disp *, unsigned long *);
146 void gf119_sor_state(struct nvkm_ior *, struct nvkm_ior_state *);
147 void gf119_sor_clock(struct nvkm_ior *);
148 extern const struct nvkm_ior_func_dp gf119_sor_dp;
149 int gf119_sor_dp_links(struct nvkm_ior *, struct nvkm_i2c_aux *);
150 void gf119_sor_dp_drive(struct nvkm_ior *, int, int, int, int, int);
151 void gf119_sor_dp_vcpi(struct nvkm_ior *, int, u8, u8, u16, u16);
152 void gf119_sor_dp_audio(struct nvkm_ior *, int, bool);
153 void gf119_sor_dp_audio_sym(struct nvkm_ior *, int, u16, u32);
154 void gf119_sor_dp_watermark(struct nvkm_ior *, int, u8);
155 extern const struct nvkm_ior_func_hda gf119_sor_hda;
156 void gf119_sor_hda_hpd(struct nvkm_ior *, int, bool);
157 void gf119_sor_hda_eld(struct nvkm_ior *, int, u8 *, u8);
158 
159 int gk104_sor_new(struct nvkm_disp *, int);
160 extern const struct nvkm_ior_func_hdmi gk104_sor_hdmi;
161 void gk104_sor_hdmi_ctrl(struct nvkm_ior *, int, bool, u8, u8);
162 void gk104_sor_hdmi_infoframe_avi(struct nvkm_ior *, int, void *, u32);
163 void gk104_sor_hdmi_infoframe_vsi(struct nvkm_ior *, int, void *, u32);
164 
165 void gm107_sor_dp_pattern(struct nvkm_ior *, int);
166 
167 void gm200_sor_route_set(struct nvkm_outp *, struct nvkm_ior *);
168 int gm200_sor_route_get(struct nvkm_outp *, int *);
169 extern const struct nvkm_ior_func_hdmi gm200_sor_hdmi;
170 void gm200_sor_hdmi_scdc(struct nvkm_ior *, u8);
171 extern const struct nvkm_ior_func_dp gm200_sor_dp;
172 void gm200_sor_dp_drive(struct nvkm_ior *, int, int, int, int, int);
173 
174 int gp100_sor_new(struct nvkm_disp *, int);
175 
176 int gv100_sor_cnt(struct nvkm_disp *, unsigned long *);
177 void gv100_sor_state(struct nvkm_ior *, struct nvkm_ior_state *);
178 extern const struct nvkm_ior_func_hdmi gv100_sor_hdmi;
179 void gv100_sor_dp_audio(struct nvkm_ior *, int, bool);
180 void gv100_sor_dp_audio_sym(struct nvkm_ior *, int, u16, u32);
181 void gv100_sor_dp_watermark(struct nvkm_ior *, int, u8);
182 extern const struct nvkm_ior_func_hda gv100_sor_hda;
183 
184 void tu102_sor_dp_vcpi(struct nvkm_ior *, int, u8, u8, u16, u16);
185 
186 int nv50_pior_cnt(struct nvkm_disp *, unsigned long *);
187 int nv50_pior_new(struct nvkm_disp *, int);
188 void nv50_pior_depth(struct nvkm_ior *, struct nvkm_ior_state *, u32 ctrl);
189 
190 #define IOR_MSG(i,l,f,a...) do {                                               \
191 	struct nvkm_ior *_ior = (i);                                           \
192 	nvkm_##l(&_ior->disp->engine.subdev, "%s: "f"\n", _ior->name, ##a);    \
193 } while(0)
194 #define IOR_WARN(i,f,a...) IOR_MSG((i), warn, f, ##a)
195 #define IOR_DBG(i,f,a...) IOR_MSG((i), debug, f, ##a)
196 #endif
197