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 	struct {
67 		void (*ctrl)(struct nvkm_ior *, int head, bool enable,
68 			     u8 max_ac_packet, u8 rekey, u8 *avi, u8 avi_size,
69 			     u8 *vendor, u8 vendor_size);
70 		void (*scdc)(struct nvkm_ior *, u8 scdc);
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 void g84_sor_hdmi_ctrl(struct nvkm_ior *, int, bool, u8, u8, u8 *, u8 , u8 *, u8);
128 
129 int g94_sor_cnt(struct nvkm_disp *, unsigned long *);
130 void g94_sor_state(struct nvkm_ior *, struct nvkm_ior_state *);
131 extern const struct nvkm_ior_func_dp g94_sor_dp;
132 int g94_sor_dp_links(struct nvkm_ior *, struct nvkm_i2c_aux *);
133 void g94_sor_dp_power(struct nvkm_ior *, int);
134 void g94_sor_dp_pattern(struct nvkm_ior *, int);
135 void g94_sor_dp_drive(struct nvkm_ior *, int, int, int, int, int);
136 void g94_sor_dp_audio_sym(struct nvkm_ior *, int, u16, u32);
137 void g94_sor_dp_activesym(struct nvkm_ior *, int, u8, u8, u8, u8);
138 void g94_sor_dp_watermark(struct nvkm_ior *, int, u8);
139 
140 void gt215_sor_hdmi_ctrl(struct nvkm_ior *, int, bool, u8, u8, u8 *, u8 , u8 *, u8);
141 void gt215_sor_dp_audio(struct nvkm_ior *, int, bool);
142 extern const struct nvkm_ior_func_hda gt215_sor_hda;
143 
144 int gf119_sor_cnt(struct nvkm_disp *, unsigned long *);
145 void gf119_sor_state(struct nvkm_ior *, struct nvkm_ior_state *);
146 void gf119_sor_clock(struct nvkm_ior *);
147 extern const struct nvkm_ior_func_dp gf119_sor_dp;
148 int gf119_sor_dp_links(struct nvkm_ior *, struct nvkm_i2c_aux *);
149 void gf119_sor_dp_drive(struct nvkm_ior *, int, int, int, int, int);
150 void gf119_sor_dp_vcpi(struct nvkm_ior *, int, u8, u8, u16, u16);
151 void gf119_sor_dp_audio(struct nvkm_ior *, int, bool);
152 void gf119_sor_dp_audio_sym(struct nvkm_ior *, int, u16, u32);
153 void gf119_sor_dp_watermark(struct nvkm_ior *, int, u8);
154 extern const struct nvkm_ior_func_hda gf119_sor_hda;
155 void gf119_sor_hda_hpd(struct nvkm_ior *, int, bool);
156 void gf119_sor_hda_eld(struct nvkm_ior *, int, u8 *, u8);
157 
158 int gk104_sor_new(struct nvkm_disp *, int);
159 void gk104_sor_hdmi_ctrl(struct nvkm_ior *, int, bool, u8, u8, u8 *, u8 , u8 *, u8);
160 
161 void gm107_sor_dp_pattern(struct nvkm_ior *, int);
162 
163 void gm200_sor_route_set(struct nvkm_outp *, struct nvkm_ior *);
164 int gm200_sor_route_get(struct nvkm_outp *, int *);
165 void gm200_sor_hdmi_scdc(struct nvkm_ior *, u8);
166 extern const struct nvkm_ior_func_dp gm200_sor_dp;
167 void gm200_sor_dp_drive(struct nvkm_ior *, int, int, int, int, int);
168 
169 int gp100_sor_new(struct nvkm_disp *, int);
170 
171 int gv100_sor_cnt(struct nvkm_disp *, unsigned long *);
172 void gv100_sor_state(struct nvkm_ior *, struct nvkm_ior_state *);
173 void gv100_sor_hdmi_ctrl(struct nvkm_ior *, int, bool, u8, u8, u8 *, u8 , u8 *, u8);
174 void gv100_sor_dp_audio(struct nvkm_ior *, int, bool);
175 void gv100_sor_dp_audio_sym(struct nvkm_ior *, int, u16, u32);
176 void gv100_sor_dp_watermark(struct nvkm_ior *, int, u8);
177 extern const struct nvkm_ior_func_hda gv100_sor_hda;
178 
179 void tu102_sor_dp_vcpi(struct nvkm_ior *, int, u8, u8, u16, u16);
180 
181 int nv50_pior_cnt(struct nvkm_disp *, unsigned long *);
182 int nv50_pior_new(struct nvkm_disp *, int);
183 void nv50_pior_depth(struct nvkm_ior *, struct nvkm_ior_state *, u32 ctrl);
184 
185 #define IOR_MSG(i,l,f,a...) do {                                               \
186 	struct nvkm_ior *_ior = (i);                                           \
187 	nvkm_##l(&_ior->disp->engine.subdev, "%s: "f"\n", _ior->name, ##a);    \
188 } while(0)
189 #define IOR_WARN(i,f,a...) IOR_MSG((i), warn, f, ##a)
190 #define IOR_DBG(i,f,a...) IOR_MSG((i), debug, f, ##a)
191 #endif
192