Home | History | Annotate | Line # | Download | only in nouveau
nouveau_connector.h revision 1.3
      1 /*	$NetBSD: nouveau_connector.h,v 1.3 2021/12/18 23:45:32 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 
     53 struct nouveau_conn_atom {
     54 	struct drm_connector_state state;
     55 
     56 	struct {
     57 		/* The enum values specifically defined here match nv50/gf119
     58 		 * hw values, and the code relies on this.
     59 		 */
     60 		enum {
     61 			DITHERING_MODE_OFF = 0x00,
     62 			DITHERING_MODE_ON = 0x01,
     63 			DITHERING_MODE_DYNAMIC2X2 = 0x10 | DITHERING_MODE_ON,
     64 			DITHERING_MODE_STATIC2X2 = 0x18 | DITHERING_MODE_ON,
     65 			DITHERING_MODE_TEMPORAL = 0x20 | DITHERING_MODE_ON,
     66 			DITHERING_MODE_AUTO
     67 		} mode;
     68 		enum {
     69 			DITHERING_DEPTH_6BPC = 0x00,
     70 			DITHERING_DEPTH_8BPC = 0x02,
     71 			DITHERING_DEPTH_AUTO
     72 		} depth;
     73 	} dither;
     74 
     75 	struct {
     76 		int mode;	/* DRM_MODE_SCALE_* */
     77 		struct {
     78 			enum {
     79 				UNDERSCAN_OFF,
     80 				UNDERSCAN_ON,
     81 				UNDERSCAN_AUTO,
     82 			} mode;
     83 			u32 hborder;
     84 			u32 vborder;
     85 		} underscan;
     86 		bool full;
     87 	} scaler;
     88 
     89 	struct {
     90 		int color_vibrance;
     91 		int vibrant_hue;
     92 	} procamp;
     93 
     94 	union {
     95 		struct {
     96 			bool dither:1;
     97 			bool scaler:1;
     98 			bool procamp:1;
     99 		};
    100 		u8 mask;
    101 	} set;
    102 };
    103 
    104 struct nouveau_connector {
    105 	struct drm_connector base;
    106 	enum dcb_connector_type type;
    107 	u8 index;
    108 	u8 *dcb;
    109 
    110 	struct nvif_notify hpd;
    111 
    112 	struct drm_dp_aux aux;
    113 
    114 	int dithering_mode;
    115 	int scaling_mode;
    116 
    117 	struct nouveau_encoder *detected_encoder;
    118 	struct edid *edid;
    119 	struct drm_display_mode *native_mode;
    120 #ifdef CONFIG_DRM_NOUVEAU_BACKLIGHT
    121 	struct nouveau_backlight *backlight;
    122 #endif
    123 	/*
    124 	 * Our connector property code expects a nouveau_conn_atom struct
    125 	 * even on pre-nv50 where we do not support atomic. This embedded
    126 	 * version gets used in the non atomic modeset case.
    127 	 */
    128 	struct nouveau_conn_atom properties_state;
    129 };
    130 
    131 static inline struct nouveau_connector *nouveau_connector(
    132 						struct drm_connector *con)
    133 {
    134 	return container_of(con, struct nouveau_connector, base);
    135 }
    136 
    137 static inline bool
    138 nouveau_connector_is_mst(struct drm_connector *connector)
    139 {
    140 	const struct nouveau_encoder *nv_encoder;
    141 	const struct drm_encoder *encoder;
    142 
    143 	if (connector->connector_type != DRM_MODE_CONNECTOR_DisplayPort)
    144 		return false;
    145 
    146 	nv_encoder = find_encoder(connector, DCB_OUTPUT_ANY);
    147 	if (!nv_encoder)
    148 		return false;
    149 
    150 	encoder = &nv_encoder->base.base;
    151 	return encoder->encoder_type == DRM_MODE_ENCODER_DPMST;
    152 }
    153 
    154 #define nouveau_for_each_non_mst_connector_iter(connector, iter) \
    155 	drm_for_each_connector_iter(connector, iter) \
    156 		for_each_if(!nouveau_connector_is_mst(connector))
    157 
    158 static inline struct nouveau_connector *
    159 nouveau_crtc_connector_get(struct nouveau_crtc *nv_crtc)
    160 {
    161 	struct drm_device *dev = nv_crtc->base.dev;
    162 	struct drm_connector *connector;
    163 	struct drm_connector_list_iter conn_iter;
    164 	struct nouveau_connector *nv_connector = NULL;
    165 	struct drm_crtc *crtc = to_drm_crtc(nv_crtc);
    166 
    167 	drm_connector_list_iter_begin(dev, &conn_iter);
    168 	nouveau_for_each_non_mst_connector_iter(connector, &conn_iter) {
    169 		if (connector->encoder && connector->encoder->crtc == crtc) {
    170 			nv_connector = nouveau_connector(connector);
    171 			break;
    172 		}
    173 	}
    174 	drm_connector_list_iter_end(&conn_iter);
    175 
    176 	return nv_connector;
    177 }
    178 
    179 struct drm_connector *
    180 nouveau_connector_create(struct drm_device *, const struct dcb_output *);
    181 
    182 extern int nouveau_tv_disable;
    183 extern int nouveau_ignorelid;
    184 extern int nouveau_duallink;
    185 extern int nouveau_hdmimhz;
    186 
    187 void nouveau_conn_attach_properties(struct drm_connector *);
    188 void nouveau_conn_reset(struct drm_connector *);
    189 struct drm_connector_state *
    190 nouveau_conn_atomic_duplicate_state(struct drm_connector *);
    191 void nouveau_conn_atomic_destroy_state(struct drm_connector *,
    192 				       struct drm_connector_state *);
    193 int nouveau_conn_atomic_set_property(struct drm_connector *,
    194 				     struct drm_connector_state *,
    195 				     struct drm_property *, u64);
    196 int nouveau_conn_atomic_get_property(struct drm_connector *,
    197 				     const struct drm_connector_state *,
    198 				     struct drm_property *, u64 *);
    199 struct drm_display_mode *nouveau_conn_native_mode(struct drm_connector *);
    200 
    201 #ifdef CONFIG_DRM_NOUVEAU_BACKLIGHT
    202 extern int nouveau_backlight_init(struct drm_connector *);
    203 extern void nouveau_backlight_fini(struct drm_connector *);
    204 extern void nouveau_backlight_ctor(void);
    205 extern void nouveau_backlight_dtor(void);
    206 #else
    207 static inline int
    208 nouveau_backlight_init(struct drm_connector *connector)
    209 {
    210 	return 0;
    211 }
    212 
    213 static inline void
    214 nouveau_backlight_fini(struct drm_connector *connector) {
    215 }
    216 
    217 static inline void
    218 nouveau_backlight_ctor(void) {
    219 }
    220 
    221 static inline void
    222 nouveau_backlight_dtor(void) {
    223 }
    224 #endif
    225 
    226 #endif /* __NOUVEAU_CONNECTOR_H__ */
    227