1  /* SPDX-License-Identifier: MIT */
2  #ifndef __NVKM_DISP_OUTP_H__
3  #define __NVKM_DISP_OUTP_H__
4  #include "priv.h"
5  
6  #include <drm/display/drm_dp.h>
7  #include <subdev/bios.h>
8  #include <subdev/bios/dcb.h>
9  #include <subdev/bios/dp.h>
10  
11  struct nvkm_outp {
12  	const struct nvkm_outp_func *func;
13  	struct nvkm_disp *disp;
14  	int index;
15  	struct dcb_output info;
16  
17  	struct nvkm_i2c_bus *i2c;
18  
19  	struct list_head head;
20  	struct nvkm_conn *conn;
21  	bool identity;
22  
23  	/* Assembly state. */
24  #define NVKM_OUTP_PRIV 1
25  #define NVKM_OUTP_USER 2
26  	u8 acquired:2;
27  	struct nvkm_ior *ior;
28  
29  	union {
30  		struct {
31  			bool dual;
32  			bool bpc8;
33  		} lvds;
34  
35  		struct {
36  			struct nvbios_dpout info;
37  			u8 version;
38  			bool mst;
39  			bool increased_wm;
40  
41  			struct nvkm_i2c_aux *aux;
42  
43  			bool enabled;
44  			bool aux_pwr;
45  			bool aux_pwr_pu;
46  			u8 lttpr[6];
47  			u8 lttprs;
48  			u8 dpcd[DP_RECEIVER_CAP_SIZE];
49  
50  			struct {
51  				int dpcd; /* -1, or index into SUPPORTED_LINK_RATES table */
52  				u32 rate;
53  			} rate[8];
54  			int rates;
55  
56  			struct mutex mutex;
57  			struct {
58  				u8 nr;
59  				u8 bw;
60  				bool mst;
61  				bool post_adj;
62  			} lt;
63  		} dp;
64  	};
65  
66  	struct nvkm_object object;
67  	struct {
68  		struct nvkm_head *head;
69  	} asy;
70  };
71  
72  int nvkm_outp_new_(const struct nvkm_outp_func *, struct nvkm_disp *, int index,
73  		   struct dcb_output *, struct nvkm_outp **);
74  int nvkm_outp_new(struct nvkm_disp *, int index, struct dcb_output *, struct nvkm_outp **);
75  void nvkm_outp_del(struct nvkm_outp **);
76  void nvkm_outp_init(struct nvkm_outp *);
77  void nvkm_outp_fini(struct nvkm_outp *);
78  
79  int nvkm_outp_detect(struct nvkm_outp *);
80  
81  struct nvkm_ior *nvkm_outp_inherit(struct nvkm_outp *);
82  int nvkm_outp_acquire(struct nvkm_outp *, bool hda);
83  int nvkm_outp_acquire_or(struct nvkm_outp *, u8 user, bool hda);
84  int nvkm_outp_acquire_ior(struct nvkm_outp *, u8 user, struct nvkm_ior *);
85  void nvkm_outp_release(struct nvkm_outp *);
86  void nvkm_outp_release_or(struct nvkm_outp *, u8 user);
87  
88  int nvkm_outp_bl_get(struct nvkm_outp *);
89  int nvkm_outp_bl_set(struct nvkm_outp *, int level);
90  
91  struct nvkm_outp_func {
92  	void *(*dtor)(struct nvkm_outp *);
93  	void (*init)(struct nvkm_outp *);
94  	void (*fini)(struct nvkm_outp *);
95  
96  	int (*detect)(struct nvkm_outp *);
97  	int (*edid_get)(struct nvkm_outp *, u8 *data, u16 *size);
98  
99  	struct nvkm_ior *(*inherit)(struct nvkm_outp *);
100  	int (*acquire)(struct nvkm_outp *, bool hda);
101  	void (*release)(struct nvkm_outp *);
102  
103  	struct {
104  		int (*get)(struct nvkm_outp *);
105  		int (*set)(struct nvkm_outp *, int level);
106  	} bl;
107  
108  	struct {
109  		int (*aux_pwr)(struct nvkm_outp *, bool pu);
110  		int (*aux_xfer)(struct nvkm_outp *, u8 type, u32 addr, u8 *data, u8 *size);
111  		int (*rates)(struct nvkm_outp *);
112  		int (*train)(struct nvkm_outp *, bool retrain);
113  		int (*drive)(struct nvkm_outp *, u8 lanes, u8 pe[4], u8 vs[4]);
114  		int (*mst_id_get)(struct nvkm_outp *, u32 *id);
115  		int (*mst_id_put)(struct nvkm_outp *, u32 id);
116  	} dp;
117  };
118  
119  #define OUTP_MSG(o,l,f,a...) do {                                              \
120  	struct nvkm_outp *_outp = (o);                                         \
121  	nvkm_##l(&_outp->disp->engine.subdev, "outp %02x:%04x:%04x: "f"\n",    \
122  		 _outp->index, _outp->info.hasht, _outp->info.hashm, ##a);     \
123  } while(0)
124  #define OUTP_ERR(o,f,a...) OUTP_MSG((o), error, f, ##a)
125  #define OUTP_DBG(o,f,a...) OUTP_MSG((o), debug, f, ##a)
126  #define OUTP_TRACE(o,f,a...) OUTP_MSG((o), trace, f, ##a)
127  #endif
128