Home | History | Annotate | Line # | Download | only in nouveau
      1  1.4  riastrad /*	$NetBSD: nouveau_connector.h,v 1.4 2021/12/19 10:49:21 riastradh Exp $	*/
      2  1.2  riastrad 
      3  1.1  riastrad /*
      4  1.1  riastrad  * Copyright (C) 2008 Maarten Maathuis.
      5  1.1  riastrad  * All Rights Reserved.
      6  1.1  riastrad  *
      7  1.1  riastrad  * Permission is hereby granted, free of charge, to any person obtaining
      8  1.1  riastrad  * a copy of this software and associated documentation files (the
      9  1.1  riastrad  * "Software"), to deal in the Software without restriction, including
     10  1.1  riastrad  * without limitation the rights to use, copy, modify, merge, publish,
     11  1.1  riastrad  * distribute, sublicense, and/or sell copies of the Software, and to
     12  1.1  riastrad  * permit persons to whom the Software is furnished to do so, subject to
     13  1.1  riastrad  * the following conditions:
     14  1.1  riastrad  *
     15  1.1  riastrad  * The above copyright notice and this permission notice (including the
     16  1.1  riastrad  * next paragraph) shall be included in all copies or substantial
     17  1.1  riastrad  * portions of the Software.
     18  1.1  riastrad  *
     19  1.1  riastrad  * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
     20  1.1  riastrad  * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
     21  1.1  riastrad  * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
     22  1.1  riastrad  * IN NO EVENT SHALL THE COPYRIGHT OWNER(S) AND/OR ITS SUPPLIERS BE
     23  1.1  riastrad  * LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
     24  1.1  riastrad  * OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
     25  1.1  riastrad  * WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
     26  1.1  riastrad  *
     27  1.1  riastrad  */
     28  1.1  riastrad 
     29  1.1  riastrad #ifndef __NOUVEAU_CONNECTOR_H__
     30  1.1  riastrad #define __NOUVEAU_CONNECTOR_H__
     31  1.1  riastrad 
     32  1.2  riastrad #include <nvif/notify.h>
     33  1.2  riastrad 
     34  1.3  riastrad #include <drm/drm_crtc.h>
     35  1.1  riastrad #include <drm/drm_edid.h>
     36  1.3  riastrad #include <drm/drm_encoder.h>
     37  1.2  riastrad #include <drm/drm_dp_helper.h>
     38  1.3  riastrad #include <drm/drm_util.h>
     39  1.3  riastrad 
     40  1.1  riastrad #include "nouveau_crtc.h"
     41  1.3  riastrad #include "nouveau_encoder.h"
     42  1.1  riastrad 
     43  1.2  riastrad struct nvkm_i2c_port;
     44  1.3  riastrad struct dcb_output;
     45  1.1  riastrad 
     46  1.3  riastrad #ifdef CONFIG_DRM_NOUVEAU_BACKLIGHT
     47  1.3  riastrad struct nouveau_backlight;
     48  1.3  riastrad #endif
     49  1.3  riastrad 
     50  1.3  riastrad #define nouveau_conn_atom(p)                                                   \
     51  1.3  riastrad 	container_of((p), struct nouveau_conn_atom, state)
     52  1.4  riastrad #define nouveau_conn_atom_const(p)                                             \
     53  1.4  riastrad 	const_container_of((p), struct nouveau_conn_atom, state)
     54  1.3  riastrad 
     55  1.3  riastrad struct nouveau_conn_atom {
     56  1.3  riastrad 	struct drm_connector_state state;
     57  1.3  riastrad 
     58  1.3  riastrad 	struct {
     59  1.3  riastrad 		/* The enum values specifically defined here match nv50/gf119
     60  1.3  riastrad 		 * hw values, and the code relies on this.
     61  1.3  riastrad 		 */
     62  1.3  riastrad 		enum {
     63  1.3  riastrad 			DITHERING_MODE_OFF = 0x00,
     64  1.3  riastrad 			DITHERING_MODE_ON = 0x01,
     65  1.3  riastrad 			DITHERING_MODE_DYNAMIC2X2 = 0x10 | DITHERING_MODE_ON,
     66  1.3  riastrad 			DITHERING_MODE_STATIC2X2 = 0x18 | DITHERING_MODE_ON,
     67  1.3  riastrad 			DITHERING_MODE_TEMPORAL = 0x20 | DITHERING_MODE_ON,
     68  1.3  riastrad 			DITHERING_MODE_AUTO
     69  1.3  riastrad 		} mode;
     70  1.3  riastrad 		enum {
     71  1.3  riastrad 			DITHERING_DEPTH_6BPC = 0x00,
     72  1.3  riastrad 			DITHERING_DEPTH_8BPC = 0x02,
     73  1.3  riastrad 			DITHERING_DEPTH_AUTO
     74  1.3  riastrad 		} depth;
     75  1.3  riastrad 	} dither;
     76  1.3  riastrad 
     77  1.3  riastrad 	struct {
     78  1.3  riastrad 		int mode;	/* DRM_MODE_SCALE_* */
     79  1.3  riastrad 		struct {
     80  1.3  riastrad 			enum {
     81  1.3  riastrad 				UNDERSCAN_OFF,
     82  1.3  riastrad 				UNDERSCAN_ON,
     83  1.3  riastrad 				UNDERSCAN_AUTO,
     84  1.3  riastrad 			} mode;
     85  1.3  riastrad 			u32 hborder;
     86  1.3  riastrad 			u32 vborder;
     87  1.3  riastrad 		} underscan;
     88  1.3  riastrad 		bool full;
     89  1.3  riastrad 	} scaler;
     90  1.3  riastrad 
     91  1.3  riastrad 	struct {
     92  1.3  riastrad 		int color_vibrance;
     93  1.3  riastrad 		int vibrant_hue;
     94  1.3  riastrad 	} procamp;
     95  1.3  riastrad 
     96  1.3  riastrad 	union {
     97  1.3  riastrad 		struct {
     98  1.3  riastrad 			bool dither:1;
     99  1.3  riastrad 			bool scaler:1;
    100  1.3  riastrad 			bool procamp:1;
    101  1.3  riastrad 		};
    102  1.3  riastrad 		u8 mask;
    103  1.3  riastrad 	} set;
    104  1.1  riastrad };
    105  1.1  riastrad 
    106  1.1  riastrad struct nouveau_connector {
    107  1.1  riastrad 	struct drm_connector base;
    108  1.1  riastrad 	enum dcb_connector_type type;
    109  1.1  riastrad 	u8 index;
    110  1.1  riastrad 	u8 *dcb;
    111  1.1  riastrad 
    112  1.2  riastrad 	struct nvif_notify hpd;
    113  1.2  riastrad 
    114  1.2  riastrad 	struct drm_dp_aux aux;
    115  1.1  riastrad 
    116  1.1  riastrad 	int dithering_mode;
    117  1.1  riastrad 	int scaling_mode;
    118  1.1  riastrad 
    119  1.1  riastrad 	struct nouveau_encoder *detected_encoder;
    120  1.1  riastrad 	struct edid *edid;
    121  1.1  riastrad 	struct drm_display_mode *native_mode;
    122  1.3  riastrad #ifdef CONFIG_DRM_NOUVEAU_BACKLIGHT
    123  1.3  riastrad 	struct nouveau_backlight *backlight;
    124  1.3  riastrad #endif
    125  1.3  riastrad 	/*
    126  1.3  riastrad 	 * Our connector property code expects a nouveau_conn_atom struct
    127  1.3  riastrad 	 * even on pre-nv50 where we do not support atomic. This embedded
    128  1.3  riastrad 	 * version gets used in the non atomic modeset case.
    129  1.3  riastrad 	 */
    130  1.3  riastrad 	struct nouveau_conn_atom properties_state;
    131  1.1  riastrad };
    132  1.1  riastrad 
    133  1.1  riastrad static inline struct nouveau_connector *nouveau_connector(
    134  1.1  riastrad 						struct drm_connector *con)
    135  1.1  riastrad {
    136  1.1  riastrad 	return container_of(con, struct nouveau_connector, base);
    137  1.1  riastrad }
    138  1.1  riastrad 
    139  1.3  riastrad static inline bool
    140  1.3  riastrad nouveau_connector_is_mst(struct drm_connector *connector)
    141  1.3  riastrad {
    142  1.3  riastrad 	const struct nouveau_encoder *nv_encoder;
    143  1.3  riastrad 	const struct drm_encoder *encoder;
    144  1.3  riastrad 
    145  1.3  riastrad 	if (connector->connector_type != DRM_MODE_CONNECTOR_DisplayPort)
    146  1.3  riastrad 		return false;
    147  1.3  riastrad 
    148  1.3  riastrad 	nv_encoder = find_encoder(connector, DCB_OUTPUT_ANY);
    149  1.3  riastrad 	if (!nv_encoder)
    150  1.3  riastrad 		return false;
    151  1.3  riastrad 
    152  1.3  riastrad 	encoder = &nv_encoder->base.base;
    153  1.3  riastrad 	return encoder->encoder_type == DRM_MODE_ENCODER_DPMST;
    154  1.3  riastrad }
    155  1.3  riastrad 
    156  1.3  riastrad #define nouveau_for_each_non_mst_connector_iter(connector, iter) \
    157  1.3  riastrad 	drm_for_each_connector_iter(connector, iter) \
    158  1.3  riastrad 		for_each_if(!nouveau_connector_is_mst(connector))
    159  1.3  riastrad 
    160  1.1  riastrad static inline struct nouveau_connector *
    161  1.1  riastrad nouveau_crtc_connector_get(struct nouveau_crtc *nv_crtc)
    162  1.1  riastrad {
    163  1.1  riastrad 	struct drm_device *dev = nv_crtc->base.dev;
    164  1.1  riastrad 	struct drm_connector *connector;
    165  1.3  riastrad 	struct drm_connector_list_iter conn_iter;
    166  1.3  riastrad 	struct nouveau_connector *nv_connector = NULL;
    167  1.1  riastrad 	struct drm_crtc *crtc = to_drm_crtc(nv_crtc);
    168  1.1  riastrad 
    169  1.3  riastrad 	drm_connector_list_iter_begin(dev, &conn_iter);
    170  1.3  riastrad 	nouveau_for_each_non_mst_connector_iter(connector, &conn_iter) {
    171  1.3  riastrad 		if (connector->encoder && connector->encoder->crtc == crtc) {
    172  1.3  riastrad 			nv_connector = nouveau_connector(connector);
    173  1.3  riastrad 			break;
    174  1.3  riastrad 		}
    175  1.1  riastrad 	}
    176  1.3  riastrad 	drm_connector_list_iter_end(&conn_iter);
    177  1.1  riastrad 
    178  1.3  riastrad 	return nv_connector;
    179  1.1  riastrad }
    180  1.1  riastrad 
    181  1.1  riastrad struct drm_connector *
    182  1.3  riastrad nouveau_connector_create(struct drm_device *, const struct dcb_output *);
    183  1.1  riastrad 
    184  1.2  riastrad extern int nouveau_tv_disable;
    185  1.2  riastrad extern int nouveau_ignorelid;
    186  1.2  riastrad extern int nouveau_duallink;
    187  1.3  riastrad extern int nouveau_hdmimhz;
    188  1.3  riastrad 
    189  1.3  riastrad void nouveau_conn_attach_properties(struct drm_connector *);
    190  1.3  riastrad void nouveau_conn_reset(struct drm_connector *);
    191  1.3  riastrad struct drm_connector_state *
    192  1.3  riastrad nouveau_conn_atomic_duplicate_state(struct drm_connector *);
    193  1.3  riastrad void nouveau_conn_atomic_destroy_state(struct drm_connector *,
    194  1.3  riastrad 				       struct drm_connector_state *);
    195  1.3  riastrad int nouveau_conn_atomic_set_property(struct drm_connector *,
    196  1.3  riastrad 				     struct drm_connector_state *,
    197  1.3  riastrad 				     struct drm_property *, u64);
    198  1.3  riastrad int nouveau_conn_atomic_get_property(struct drm_connector *,
    199  1.3  riastrad 				     const struct drm_connector_state *,
    200  1.3  riastrad 				     struct drm_property *, u64 *);
    201  1.3  riastrad struct drm_display_mode *nouveau_conn_native_mode(struct drm_connector *);
    202  1.3  riastrad 
    203  1.3  riastrad #ifdef CONFIG_DRM_NOUVEAU_BACKLIGHT
    204  1.3  riastrad extern int nouveau_backlight_init(struct drm_connector *);
    205  1.3  riastrad extern void nouveau_backlight_fini(struct drm_connector *);
    206  1.3  riastrad extern void nouveau_backlight_ctor(void);
    207  1.3  riastrad extern void nouveau_backlight_dtor(void);
    208  1.3  riastrad #else
    209  1.3  riastrad static inline int
    210  1.3  riastrad nouveau_backlight_init(struct drm_connector *connector)
    211  1.3  riastrad {
    212  1.3  riastrad 	return 0;
    213  1.3  riastrad }
    214  1.3  riastrad 
    215  1.3  riastrad static inline void
    216  1.3  riastrad nouveau_backlight_fini(struct drm_connector *connector) {
    217  1.3  riastrad }
    218  1.3  riastrad 
    219  1.3  riastrad static inline void
    220  1.3  riastrad nouveau_backlight_ctor(void) {
    221  1.3  riastrad }
    222  1.3  riastrad 
    223  1.3  riastrad static inline void
    224  1.3  riastrad nouveau_backlight_dtor(void) {
    225  1.3  riastrad }
    226  1.3  riastrad #endif
    227  1.2  riastrad 
    228  1.1  riastrad #endif /* __NOUVEAU_CONNECTOR_H__ */
    229