xref: /openbsd-src/sys/dev/pci/drm/amd/amdgpu/amdgpu_mode.h (revision f005ef32267c16bdb134f0e9fa4477dbe07c263a)
1fb4d8502Sjsg /*
2fb4d8502Sjsg  * Copyright 2000 ATI Technologies Inc., Markham, Ontario, and
3fb4d8502Sjsg  *                VA Linux Systems Inc., Fremont, California.
4fb4d8502Sjsg  * Copyright 2008 Red Hat Inc.
5fb4d8502Sjsg  *
6fb4d8502Sjsg  * Permission is hereby granted, free of charge, to any person obtaining a
7fb4d8502Sjsg  * copy of this software and associated documentation files (the "Software"),
8fb4d8502Sjsg  * to deal in the Software without restriction, including without limitation
9fb4d8502Sjsg  * the rights to use, copy, modify, merge, publish, distribute, sublicense,
10fb4d8502Sjsg  * and/or sell copies of the Software, and to permit persons to whom the
11fb4d8502Sjsg  * Software is furnished to do so, subject to the following conditions:
12fb4d8502Sjsg  *
13fb4d8502Sjsg  * The above copyright notice and this permission notice shall be included in
14fb4d8502Sjsg  * all copies or substantial portions of the Software.
15fb4d8502Sjsg  *
16fb4d8502Sjsg  * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
17fb4d8502Sjsg  * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
18fb4d8502Sjsg  * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.  IN NO EVENT SHALL
19fb4d8502Sjsg  * THE COPYRIGHT HOLDER(S) OR AUTHOR(S) BE LIABLE FOR ANY CLAIM, DAMAGES OR
20fb4d8502Sjsg  * OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
21fb4d8502Sjsg  * ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
22fb4d8502Sjsg  * OTHER DEALINGS IN THE SOFTWARE.
23fb4d8502Sjsg  *
24fb4d8502Sjsg  * Original Authors:
25fb4d8502Sjsg  *   Kevin E. Martin, Rickard E. Faith, Alan Hourihane
26fb4d8502Sjsg  *
27fb4d8502Sjsg  * Kernel port Author: Dave Airlie
28fb4d8502Sjsg  */
29fb4d8502Sjsg 
30fb4d8502Sjsg #ifndef AMDGPU_MODE_H
31fb4d8502Sjsg #define AMDGPU_MODE_H
32fb4d8502Sjsg 
331bb76ff1Sjsg #include <drm/display/drm_dp_helper.h>
34fb4d8502Sjsg #include <drm/drm_crtc.h>
35fb4d8502Sjsg #include <drm/drm_edid.h>
36fb4d8502Sjsg #include <drm/drm_encoder.h>
37fb4d8502Sjsg #include <drm/drm_fixed.h>
381bb76ff1Sjsg #include <drm/drm_framebuffer.h>
39c349dbc7Sjsg #include <drm/drm_probe_helper.h>
40fb4d8502Sjsg #include <linux/i2c.h>
41fb4d8502Sjsg #include <linux/i2c-algo-bit.h>
42fb4d8502Sjsg #include <linux/hrtimer.h>
43fb4d8502Sjsg #include "amdgpu_irq.h"
44fb4d8502Sjsg 
451bb76ff1Sjsg #include <drm/display/drm_dp_mst_helper.h>
46fb4d8502Sjsg #include "modules/inc/mod_freesync.h"
47ad8b1aafSjsg #include "amdgpu_dm_irq_params.h"
48fb4d8502Sjsg 
49fb4d8502Sjsg struct amdgpu_bo;
50fb4d8502Sjsg struct amdgpu_device;
51fb4d8502Sjsg struct amdgpu_encoder;
52fb4d8502Sjsg struct amdgpu_router;
53fb4d8502Sjsg struct amdgpu_hpd;
54fb4d8502Sjsg 
55fb4d8502Sjsg #define to_amdgpu_crtc(x) container_of(x, struct amdgpu_crtc, base)
56fb4d8502Sjsg #define to_amdgpu_connector(x) container_of(x, struct amdgpu_connector, base)
57fb4d8502Sjsg #define to_amdgpu_encoder(x) container_of(x, struct amdgpu_encoder, base)
58fb4d8502Sjsg #define to_amdgpu_framebuffer(x) container_of(x, struct amdgpu_framebuffer, base)
59fb4d8502Sjsg 
60c349dbc7Sjsg #define to_dm_plane_state(x)	container_of(x, struct dm_plane_state, base)
61fb4d8502Sjsg 
62fb4d8502Sjsg #define AMDGPU_MAX_HPD_PINS 6
63fb4d8502Sjsg #define AMDGPU_MAX_CRTCS 6
64fb4d8502Sjsg #define AMDGPU_MAX_PLANES 6
65fb4d8502Sjsg #define AMDGPU_MAX_AFMT_BLOCKS 9
66fb4d8502Sjsg 
67fb4d8502Sjsg enum amdgpu_rmx_type {
68fb4d8502Sjsg 	RMX_OFF,
69fb4d8502Sjsg 	RMX_FULL,
70fb4d8502Sjsg 	RMX_CENTER,
71fb4d8502Sjsg 	RMX_ASPECT
72fb4d8502Sjsg };
73fb4d8502Sjsg 
74fb4d8502Sjsg enum amdgpu_underscan_type {
75fb4d8502Sjsg 	UNDERSCAN_OFF,
76fb4d8502Sjsg 	UNDERSCAN_ON,
77fb4d8502Sjsg 	UNDERSCAN_AUTO,
78fb4d8502Sjsg };
79fb4d8502Sjsg 
80fb4d8502Sjsg #define AMDGPU_HPD_CONNECT_INT_DELAY_IN_MS 50
81fb4d8502Sjsg #define AMDGPU_HPD_DISCONNECT_INT_DELAY_IN_MS 10
82fb4d8502Sjsg 
83fb4d8502Sjsg enum amdgpu_hpd_id {
84fb4d8502Sjsg 	AMDGPU_HPD_1 = 0,
85fb4d8502Sjsg 	AMDGPU_HPD_2,
86fb4d8502Sjsg 	AMDGPU_HPD_3,
87fb4d8502Sjsg 	AMDGPU_HPD_4,
88fb4d8502Sjsg 	AMDGPU_HPD_5,
89fb4d8502Sjsg 	AMDGPU_HPD_6,
90fb4d8502Sjsg 	AMDGPU_HPD_NONE = 0xff,
91fb4d8502Sjsg };
92fb4d8502Sjsg 
93fb4d8502Sjsg enum amdgpu_crtc_irq {
94fb4d8502Sjsg 	AMDGPU_CRTC_IRQ_VBLANK1 = 0,
95fb4d8502Sjsg 	AMDGPU_CRTC_IRQ_VBLANK2,
96fb4d8502Sjsg 	AMDGPU_CRTC_IRQ_VBLANK3,
97fb4d8502Sjsg 	AMDGPU_CRTC_IRQ_VBLANK4,
98fb4d8502Sjsg 	AMDGPU_CRTC_IRQ_VBLANK5,
99fb4d8502Sjsg 	AMDGPU_CRTC_IRQ_VBLANK6,
100fb4d8502Sjsg 	AMDGPU_CRTC_IRQ_VLINE1,
101fb4d8502Sjsg 	AMDGPU_CRTC_IRQ_VLINE2,
102fb4d8502Sjsg 	AMDGPU_CRTC_IRQ_VLINE3,
103fb4d8502Sjsg 	AMDGPU_CRTC_IRQ_VLINE4,
104fb4d8502Sjsg 	AMDGPU_CRTC_IRQ_VLINE5,
105fb4d8502Sjsg 	AMDGPU_CRTC_IRQ_VLINE6,
106fb4d8502Sjsg 	AMDGPU_CRTC_IRQ_NONE = 0xff
107fb4d8502Sjsg };
108fb4d8502Sjsg 
109fb4d8502Sjsg enum amdgpu_pageflip_irq {
110fb4d8502Sjsg 	AMDGPU_PAGEFLIP_IRQ_D1 = 0,
111fb4d8502Sjsg 	AMDGPU_PAGEFLIP_IRQ_D2,
112fb4d8502Sjsg 	AMDGPU_PAGEFLIP_IRQ_D3,
113fb4d8502Sjsg 	AMDGPU_PAGEFLIP_IRQ_D4,
114fb4d8502Sjsg 	AMDGPU_PAGEFLIP_IRQ_D5,
115fb4d8502Sjsg 	AMDGPU_PAGEFLIP_IRQ_D6,
116fb4d8502Sjsg 	AMDGPU_PAGEFLIP_IRQ_NONE = 0xff
117fb4d8502Sjsg };
118fb4d8502Sjsg 
119fb4d8502Sjsg enum amdgpu_flip_status {
120fb4d8502Sjsg 	AMDGPU_FLIP_NONE,
121fb4d8502Sjsg 	AMDGPU_FLIP_PENDING,
122fb4d8502Sjsg 	AMDGPU_FLIP_SUBMITTED
123fb4d8502Sjsg };
124fb4d8502Sjsg 
125fb4d8502Sjsg #define AMDGPU_MAX_I2C_BUS 16
126fb4d8502Sjsg 
127fb4d8502Sjsg /* amdgpu gpio-based i2c
128fb4d8502Sjsg  * 1. "mask" reg and bits
129fb4d8502Sjsg  *    grabs the gpio pins for software use
130fb4d8502Sjsg  *    0=not held  1=held
131fb4d8502Sjsg  * 2. "a" reg and bits
132fb4d8502Sjsg  *    output pin value
133fb4d8502Sjsg  *    0=low 1=high
134fb4d8502Sjsg  * 3. "en" reg and bits
135fb4d8502Sjsg  *    sets the pin direction
136fb4d8502Sjsg  *    0=input 1=output
137fb4d8502Sjsg  * 4. "y" reg and bits
138fb4d8502Sjsg  *    input pin value
139fb4d8502Sjsg  *    0=low 1=high
140fb4d8502Sjsg  */
141fb4d8502Sjsg struct amdgpu_i2c_bus_rec {
142fb4d8502Sjsg 	bool valid;
143fb4d8502Sjsg 	/* id used by atom */
144fb4d8502Sjsg 	uint8_t i2c_id;
145fb4d8502Sjsg 	/* id used by atom */
146fb4d8502Sjsg 	enum amdgpu_hpd_id hpd;
147fb4d8502Sjsg 	/* can be used with hw i2c engine */
148fb4d8502Sjsg 	bool hw_capable;
149fb4d8502Sjsg 	/* uses multi-media i2c engine */
150fb4d8502Sjsg 	bool mm_i2c;
151fb4d8502Sjsg 	/* regs and bits */
152fb4d8502Sjsg 	uint32_t mask_clk_reg;
153fb4d8502Sjsg 	uint32_t mask_data_reg;
154fb4d8502Sjsg 	uint32_t a_clk_reg;
155fb4d8502Sjsg 	uint32_t a_data_reg;
156fb4d8502Sjsg 	uint32_t en_clk_reg;
157fb4d8502Sjsg 	uint32_t en_data_reg;
158fb4d8502Sjsg 	uint32_t y_clk_reg;
159fb4d8502Sjsg 	uint32_t y_data_reg;
160fb4d8502Sjsg 	uint32_t mask_clk_mask;
161fb4d8502Sjsg 	uint32_t mask_data_mask;
162fb4d8502Sjsg 	uint32_t a_clk_mask;
163fb4d8502Sjsg 	uint32_t a_data_mask;
164fb4d8502Sjsg 	uint32_t en_clk_mask;
165fb4d8502Sjsg 	uint32_t en_data_mask;
166fb4d8502Sjsg 	uint32_t y_clk_mask;
167fb4d8502Sjsg 	uint32_t y_data_mask;
168fb4d8502Sjsg };
169fb4d8502Sjsg 
170fb4d8502Sjsg #define AMDGPU_MAX_BIOS_CONNECTOR 16
171fb4d8502Sjsg 
172fb4d8502Sjsg /* pll flags */
173fb4d8502Sjsg #define AMDGPU_PLL_USE_BIOS_DIVS        (1 << 0)
174fb4d8502Sjsg #define AMDGPU_PLL_NO_ODD_POST_DIV      (1 << 1)
175fb4d8502Sjsg #define AMDGPU_PLL_USE_REF_DIV          (1 << 2)
176fb4d8502Sjsg #define AMDGPU_PLL_LEGACY               (1 << 3)
177fb4d8502Sjsg #define AMDGPU_PLL_PREFER_LOW_REF_DIV   (1 << 4)
178fb4d8502Sjsg #define AMDGPU_PLL_PREFER_HIGH_REF_DIV  (1 << 5)
179fb4d8502Sjsg #define AMDGPU_PLL_PREFER_LOW_FB_DIV    (1 << 6)
180fb4d8502Sjsg #define AMDGPU_PLL_PREFER_HIGH_FB_DIV   (1 << 7)
181fb4d8502Sjsg #define AMDGPU_PLL_PREFER_LOW_POST_DIV  (1 << 8)
182fb4d8502Sjsg #define AMDGPU_PLL_PREFER_HIGH_POST_DIV (1 << 9)
183fb4d8502Sjsg #define AMDGPU_PLL_USE_FRAC_FB_DIV      (1 << 10)
184fb4d8502Sjsg #define AMDGPU_PLL_PREFER_CLOSEST_LOWER (1 << 11)
185fb4d8502Sjsg #define AMDGPU_PLL_USE_POST_DIV         (1 << 12)
186fb4d8502Sjsg #define AMDGPU_PLL_IS_LCD               (1 << 13)
187fb4d8502Sjsg #define AMDGPU_PLL_PREFER_MINM_OVER_MAXP (1 << 14)
188fb4d8502Sjsg 
189fb4d8502Sjsg struct amdgpu_pll {
190fb4d8502Sjsg 	/* reference frequency */
191fb4d8502Sjsg 	uint32_t reference_freq;
192fb4d8502Sjsg 
193fb4d8502Sjsg 	/* fixed dividers */
194fb4d8502Sjsg 	uint32_t reference_div;
195fb4d8502Sjsg 	uint32_t post_div;
196fb4d8502Sjsg 
197fb4d8502Sjsg 	/* pll in/out limits */
198fb4d8502Sjsg 	uint32_t pll_in_min;
199fb4d8502Sjsg 	uint32_t pll_in_max;
200fb4d8502Sjsg 	uint32_t pll_out_min;
201fb4d8502Sjsg 	uint32_t pll_out_max;
202fb4d8502Sjsg 	uint32_t lcd_pll_out_min;
203fb4d8502Sjsg 	uint32_t lcd_pll_out_max;
204fb4d8502Sjsg 	uint32_t best_vco;
205fb4d8502Sjsg 
206fb4d8502Sjsg 	/* divider limits */
207fb4d8502Sjsg 	uint32_t min_ref_div;
208fb4d8502Sjsg 	uint32_t max_ref_div;
209fb4d8502Sjsg 	uint32_t min_post_div;
210fb4d8502Sjsg 	uint32_t max_post_div;
211fb4d8502Sjsg 	uint32_t min_feedback_div;
212fb4d8502Sjsg 	uint32_t max_feedback_div;
213fb4d8502Sjsg 	uint32_t min_frac_feedback_div;
214fb4d8502Sjsg 	uint32_t max_frac_feedback_div;
215fb4d8502Sjsg 
216fb4d8502Sjsg 	/* flags for the current clock */
217fb4d8502Sjsg 	uint32_t flags;
218fb4d8502Sjsg 
219fb4d8502Sjsg 	/* pll id */
220fb4d8502Sjsg 	uint32_t id;
221fb4d8502Sjsg };
222fb4d8502Sjsg 
223fb4d8502Sjsg struct amdgpu_i2c_chan {
224fb4d8502Sjsg 	struct i2c_adapter adapter;
225fb4d8502Sjsg 	struct drm_device *dev;
226fb4d8502Sjsg 	struct i2c_algo_bit_data bit;
227fb4d8502Sjsg 	struct amdgpu_i2c_bus_rec rec;
228fb4d8502Sjsg 	struct drm_dp_aux aux;
229fb4d8502Sjsg 	bool has_aux;
230fb4d8502Sjsg 	struct rwlock mutex;
231fb4d8502Sjsg };
232fb4d8502Sjsg 
233fb4d8502Sjsg struct amdgpu_afmt {
234fb4d8502Sjsg 	bool enabled;
235fb4d8502Sjsg 	int offset;
236fb4d8502Sjsg 	bool last_buffer_filled_status;
237fb4d8502Sjsg 	int id;
238fb4d8502Sjsg 	struct amdgpu_audio_pin *pin;
239fb4d8502Sjsg };
240fb4d8502Sjsg 
241fb4d8502Sjsg /*
242fb4d8502Sjsg  * Audio
243fb4d8502Sjsg  */
244fb4d8502Sjsg struct amdgpu_audio_pin {
245fb4d8502Sjsg 	int			channels;
246fb4d8502Sjsg 	int			rate;
247fb4d8502Sjsg 	int			bits_per_sample;
248fb4d8502Sjsg 	u8			status_bits;
249fb4d8502Sjsg 	u8			category_code;
250fb4d8502Sjsg 	u32			offset;
251fb4d8502Sjsg 	bool			connected;
252fb4d8502Sjsg 	u32			id;
253fb4d8502Sjsg };
254fb4d8502Sjsg 
255fb4d8502Sjsg struct amdgpu_audio {
256fb4d8502Sjsg 	bool enabled;
257fb4d8502Sjsg 	struct amdgpu_audio_pin pin[AMDGPU_MAX_AFMT_BLOCKS];
258fb4d8502Sjsg 	int num_pins;
259fb4d8502Sjsg };
260fb4d8502Sjsg 
261fb4d8502Sjsg struct amdgpu_display_funcs {
262fb4d8502Sjsg 	/* display watermarks */
263fb4d8502Sjsg 	void (*bandwidth_update)(struct amdgpu_device *adev);
264fb4d8502Sjsg 	/* get frame count */
265fb4d8502Sjsg 	u32 (*vblank_get_counter)(struct amdgpu_device *adev, int crtc);
266fb4d8502Sjsg 	/* set backlight level */
267fb4d8502Sjsg 	void (*backlight_set_level)(struct amdgpu_encoder *amdgpu_encoder,
268fb4d8502Sjsg 				    u8 level);
269fb4d8502Sjsg 	/* get backlight level */
270fb4d8502Sjsg 	u8 (*backlight_get_level)(struct amdgpu_encoder *amdgpu_encoder);
271fb4d8502Sjsg 	/* hotplug detect */
272fb4d8502Sjsg 	bool (*hpd_sense)(struct amdgpu_device *adev, enum amdgpu_hpd_id hpd);
273fb4d8502Sjsg 	void (*hpd_set_polarity)(struct amdgpu_device *adev,
274fb4d8502Sjsg 				 enum amdgpu_hpd_id hpd);
275fb4d8502Sjsg 	u32 (*hpd_get_gpio_reg)(struct amdgpu_device *adev);
276fb4d8502Sjsg 	/* pageflipping */
277fb4d8502Sjsg 	void (*page_flip)(struct amdgpu_device *adev,
278fb4d8502Sjsg 			  int crtc_id, u64 crtc_base, bool async);
279fb4d8502Sjsg 	int (*page_flip_get_scanoutpos)(struct amdgpu_device *adev, int crtc,
280fb4d8502Sjsg 					u32 *vbl, u32 *position);
281fb4d8502Sjsg 	/* display topology setup */
282fb4d8502Sjsg 	void (*add_encoder)(struct amdgpu_device *adev,
283fb4d8502Sjsg 			    uint32_t encoder_enum,
284fb4d8502Sjsg 			    uint32_t supported_device,
285fb4d8502Sjsg 			    u16 caps);
286fb4d8502Sjsg 	void (*add_connector)(struct amdgpu_device *adev,
287fb4d8502Sjsg 			      uint32_t connector_id,
288fb4d8502Sjsg 			      uint32_t supported_device,
289fb4d8502Sjsg 			      int connector_type,
290fb4d8502Sjsg 			      struct amdgpu_i2c_bus_rec *i2c_bus,
291fb4d8502Sjsg 			      uint16_t connector_object_id,
292fb4d8502Sjsg 			      struct amdgpu_hpd *hpd,
293fb4d8502Sjsg 			      struct amdgpu_router *router);
294fb4d8502Sjsg 
295fb4d8502Sjsg 
296fb4d8502Sjsg };
297fb4d8502Sjsg 
298fb4d8502Sjsg struct amdgpu_framebuffer {
299fb4d8502Sjsg 	struct drm_framebuffer base;
300fb4d8502Sjsg 
3015ca02815Sjsg 	uint64_t tiling_flags;
3025ca02815Sjsg 	bool tmz_surface;
3035ca02815Sjsg 
304fb4d8502Sjsg 	/* caching for later use */
305fb4d8502Sjsg 	uint64_t address;
306fb4d8502Sjsg };
307fb4d8502Sjsg 
308fb4d8502Sjsg struct amdgpu_mode_info {
309fb4d8502Sjsg 	struct atom_context *atom_context;
310fb4d8502Sjsg 	struct card_info *atom_card_info;
311fb4d8502Sjsg 	bool mode_config_initialized;
312fb4d8502Sjsg 	struct amdgpu_crtc *crtcs[AMDGPU_MAX_CRTCS];
313c349dbc7Sjsg 	struct drm_plane *planes[AMDGPU_MAX_PLANES];
314fb4d8502Sjsg 	struct amdgpu_afmt *afmt[AMDGPU_MAX_AFMT_BLOCKS];
315fb4d8502Sjsg 	/* DVI-I properties */
316fb4d8502Sjsg 	struct drm_property *coherent_mode_property;
317fb4d8502Sjsg 	/* DAC enable load detect */
318fb4d8502Sjsg 	struct drm_property *load_detect_property;
319fb4d8502Sjsg 	/* underscan */
320fb4d8502Sjsg 	struct drm_property *underscan_property;
321fb4d8502Sjsg 	struct drm_property *underscan_hborder_property;
322fb4d8502Sjsg 	struct drm_property *underscan_vborder_property;
323fb4d8502Sjsg 	/* audio */
324fb4d8502Sjsg 	struct drm_property *audio_property;
325fb4d8502Sjsg 	/* FMT dithering */
326fb4d8502Sjsg 	struct drm_property *dither_property;
327c349dbc7Sjsg 	/* Adaptive Backlight Modulation (power feature) */
328c349dbc7Sjsg 	struct drm_property *abm_level_property;
329fb4d8502Sjsg 	/* hardcoded DFP edid from BIOS */
330fb4d8502Sjsg 	struct edid *bios_hardcoded_edid;
331fb4d8502Sjsg 	int bios_hardcoded_edid_size;
332fb4d8502Sjsg 
333fb4d8502Sjsg 	/* firmware flags */
3345ca02815Sjsg 	u32 firmware_flags;
335fb4d8502Sjsg 	/* pointer to backlight encoder */
336fb4d8502Sjsg 	struct amdgpu_encoder *bl_encoder;
337fb4d8502Sjsg 	u8 bl_level; /* saved backlight level */
338fb4d8502Sjsg 	struct amdgpu_audio	audio; /* audio stuff */
339fb4d8502Sjsg 	int			num_crtc; /* number of crtcs */
340fb4d8502Sjsg 	int			num_hpd; /* number of hpd pins */
341fb4d8502Sjsg 	int			num_dig; /* number of dig blocks */
3421bb76ff1Sjsg 	bool			gpu_vm_support; /* supports display from GTT */
343fb4d8502Sjsg 	int			disp_priority;
344fb4d8502Sjsg 	const struct amdgpu_display_funcs *funcs;
345fb4d8502Sjsg 	const enum drm_plane_type *plane_type;
346fb4d8502Sjsg };
347fb4d8502Sjsg 
348fb4d8502Sjsg #define AMDGPU_MAX_BL_LEVEL 0xFF
349fb4d8502Sjsg 
350fb4d8502Sjsg struct amdgpu_backlight_privdata {
351fb4d8502Sjsg 	struct amdgpu_encoder *encoder;
352fb4d8502Sjsg 	uint8_t negative;
353fb4d8502Sjsg };
354fb4d8502Sjsg 
355fb4d8502Sjsg struct amdgpu_atom_ss {
356fb4d8502Sjsg 	uint16_t percentage;
357fb4d8502Sjsg 	uint16_t percentage_divider;
358fb4d8502Sjsg 	uint8_t type;
359fb4d8502Sjsg 	uint16_t step;
360fb4d8502Sjsg 	uint8_t delay;
361fb4d8502Sjsg 	uint8_t range;
362fb4d8502Sjsg 	uint8_t refdiv;
363fb4d8502Sjsg 	/* asic_ss */
364fb4d8502Sjsg 	uint16_t rate;
365fb4d8502Sjsg 	uint16_t amount;
366fb4d8502Sjsg };
367fb4d8502Sjsg 
368fb4d8502Sjsg struct amdgpu_crtc {
369fb4d8502Sjsg 	struct drm_crtc base;
370fb4d8502Sjsg 	int crtc_id;
371fb4d8502Sjsg 	bool enabled;
372fb4d8502Sjsg 	bool can_tile;
373fb4d8502Sjsg 	uint32_t crtc_offset;
374fb4d8502Sjsg 	struct drm_gem_object *cursor_bo;
375fb4d8502Sjsg 	uint64_t cursor_addr;
376fb4d8502Sjsg 	int cursor_x;
377fb4d8502Sjsg 	int cursor_y;
378fb4d8502Sjsg 	int cursor_hot_x;
379fb4d8502Sjsg 	int cursor_hot_y;
380fb4d8502Sjsg 	int cursor_width;
381fb4d8502Sjsg 	int cursor_height;
382fb4d8502Sjsg 	int max_cursor_width;
383fb4d8502Sjsg 	int max_cursor_height;
384fb4d8502Sjsg 	enum amdgpu_rmx_type rmx_type;
385fb4d8502Sjsg 	u8 h_border;
386fb4d8502Sjsg 	u8 v_border;
387fb4d8502Sjsg 	fixed20_12 vsc;
388fb4d8502Sjsg 	fixed20_12 hsc;
389fb4d8502Sjsg 	struct drm_display_mode native_mode;
390fb4d8502Sjsg 	u32 pll_id;
391fb4d8502Sjsg 	/* page flipping */
392fb4d8502Sjsg 	struct amdgpu_flip_work *pflip_works;
393fb4d8502Sjsg 	enum amdgpu_flip_status pflip_status;
394fb4d8502Sjsg 	int deferred_flip_completion;
395ad8b1aafSjsg 	/* parameters access from DM IRQ handler */
396ad8b1aafSjsg 	struct dm_irq_params dm_irq_params;
397fb4d8502Sjsg 	/* pll sharing */
398fb4d8502Sjsg 	struct amdgpu_atom_ss ss;
399fb4d8502Sjsg 	bool ss_enabled;
400fb4d8502Sjsg 	u32 adjusted_clock;
401fb4d8502Sjsg 	int bpc;
402fb4d8502Sjsg 	u32 pll_reference_div;
403fb4d8502Sjsg 	u32 pll_post_div;
404fb4d8502Sjsg 	u32 pll_flags;
405fb4d8502Sjsg 	struct drm_encoder *encoder;
406fb4d8502Sjsg 	struct drm_connector *connector;
407fb4d8502Sjsg 	/* for dpm */
408fb4d8502Sjsg 	u32 line_time;
409fb4d8502Sjsg 	u32 wm_low;
410fb4d8502Sjsg 	u32 wm_high;
411fb4d8502Sjsg 	u32 lb_vblank_lead_lines;
412fb4d8502Sjsg 	struct drm_display_mode hw_mode;
413fb4d8502Sjsg 	/* for virtual dce */
414fb4d8502Sjsg #ifdef __linux__
415fb4d8502Sjsg 	struct hrtimer vblank_timer;
416fb4d8502Sjsg #else
417fb4d8502Sjsg 	struct timeout vblank_timer;
418fb4d8502Sjsg #endif
419fb4d8502Sjsg 	enum amdgpu_interrupt_state vsync_timer_enabled;
420fb4d8502Sjsg 
421fb4d8502Sjsg 	int otg_inst;
422fb4d8502Sjsg 	struct drm_pending_vblank_event *event;
423fb4d8502Sjsg };
424fb4d8502Sjsg 
425fb4d8502Sjsg struct amdgpu_encoder_atom_dig {
426fb4d8502Sjsg 	bool linkb;
427fb4d8502Sjsg 	/* atom dig */
428fb4d8502Sjsg 	bool coherent_mode;
429fb4d8502Sjsg 	int dig_encoder; /* -1 disabled, 0 DIGA, 1 DIGB, etc. */
430fb4d8502Sjsg 	/* atom lvds/edp */
431fb4d8502Sjsg 	uint32_t lcd_misc;
432fb4d8502Sjsg 	uint16_t panel_pwr_delay;
433fb4d8502Sjsg 	uint32_t lcd_ss_id;
434fb4d8502Sjsg 	/* panel mode */
435fb4d8502Sjsg 	struct drm_display_mode native_mode;
436fb4d8502Sjsg 	struct backlight_device *bl_dev;
437fb4d8502Sjsg 	int dpms_mode;
438fb4d8502Sjsg 	uint8_t backlight_level;
439fb4d8502Sjsg 	int panel_mode;
440fb4d8502Sjsg 	struct amdgpu_afmt *afmt;
441fb4d8502Sjsg };
442fb4d8502Sjsg 
443fb4d8502Sjsg struct amdgpu_encoder {
444fb4d8502Sjsg 	struct drm_encoder base;
445fb4d8502Sjsg 	uint32_t encoder_enum;
446fb4d8502Sjsg 	uint32_t encoder_id;
447fb4d8502Sjsg 	uint32_t devices;
448fb4d8502Sjsg 	uint32_t active_device;
449fb4d8502Sjsg 	uint32_t flags;
450fb4d8502Sjsg 	uint32_t pixel_clock;
451fb4d8502Sjsg 	enum amdgpu_rmx_type rmx_type;
452fb4d8502Sjsg 	enum amdgpu_underscan_type underscan_type;
453fb4d8502Sjsg 	uint32_t underscan_hborder;
454fb4d8502Sjsg 	uint32_t underscan_vborder;
455fb4d8502Sjsg 	struct drm_display_mode native_mode;
456fb4d8502Sjsg 	void *enc_priv;
457fb4d8502Sjsg 	int audio_polling_active;
458fb4d8502Sjsg 	bool is_ext_encoder;
459fb4d8502Sjsg 	u16 caps;
460fb4d8502Sjsg };
461fb4d8502Sjsg 
462fb4d8502Sjsg struct amdgpu_connector_atom_dig {
463fb4d8502Sjsg 	/* displayport */
464fb4d8502Sjsg 	u8 dpcd[DP_RECEIVER_CAP_SIZE];
465ad8b1aafSjsg 	u8 downstream_ports[DP_MAX_DOWNSTREAM_PORTS];
466fb4d8502Sjsg 	u8 dp_sink_type;
467fb4d8502Sjsg 	int dp_clock;
468fb4d8502Sjsg 	int dp_lane_count;
469fb4d8502Sjsg 	bool edp_on;
470fb4d8502Sjsg };
471fb4d8502Sjsg 
472fb4d8502Sjsg struct amdgpu_gpio_rec {
473fb4d8502Sjsg 	bool valid;
474fb4d8502Sjsg 	u8 id;
475fb4d8502Sjsg 	u32 reg;
476fb4d8502Sjsg 	u32 mask;
477fb4d8502Sjsg 	u32 shift;
478fb4d8502Sjsg };
479fb4d8502Sjsg 
480fb4d8502Sjsg struct amdgpu_hpd {
481fb4d8502Sjsg 	enum amdgpu_hpd_id hpd;
482fb4d8502Sjsg 	u8 plugged_state;
483fb4d8502Sjsg 	struct amdgpu_gpio_rec gpio;
484fb4d8502Sjsg };
485fb4d8502Sjsg 
486fb4d8502Sjsg struct amdgpu_router {
487fb4d8502Sjsg 	u32 router_id;
488fb4d8502Sjsg 	struct amdgpu_i2c_bus_rec i2c_info;
489fb4d8502Sjsg 	u8 i2c_addr;
490fb4d8502Sjsg 	/* i2c mux */
491fb4d8502Sjsg 	bool ddc_valid;
492fb4d8502Sjsg 	u8 ddc_mux_type;
493fb4d8502Sjsg 	u8 ddc_mux_control_pin;
494fb4d8502Sjsg 	u8 ddc_mux_state;
495fb4d8502Sjsg 	/* clock/data mux */
496fb4d8502Sjsg 	bool cd_valid;
497fb4d8502Sjsg 	u8 cd_mux_type;
498fb4d8502Sjsg 	u8 cd_mux_control_pin;
499fb4d8502Sjsg 	u8 cd_mux_state;
500fb4d8502Sjsg };
501fb4d8502Sjsg 
502fb4d8502Sjsg enum amdgpu_connector_audio {
503fb4d8502Sjsg 	AMDGPU_AUDIO_DISABLE = 0,
504fb4d8502Sjsg 	AMDGPU_AUDIO_ENABLE = 1,
505fb4d8502Sjsg 	AMDGPU_AUDIO_AUTO = 2
506fb4d8502Sjsg };
507fb4d8502Sjsg 
508fb4d8502Sjsg enum amdgpu_connector_dither {
509fb4d8502Sjsg 	AMDGPU_FMT_DITHER_DISABLE = 0,
510fb4d8502Sjsg 	AMDGPU_FMT_DITHER_ENABLE = 1,
511fb4d8502Sjsg };
512fb4d8502Sjsg 
513fb4d8502Sjsg struct amdgpu_dm_dp_aux {
514fb4d8502Sjsg 	struct drm_dp_aux aux;
515fb4d8502Sjsg 	struct ddc_service *ddc_service;
516fb4d8502Sjsg };
517fb4d8502Sjsg 
518fb4d8502Sjsg struct amdgpu_i2c_adapter {
519fb4d8502Sjsg 	struct i2c_adapter base;
520fb4d8502Sjsg 
521fb4d8502Sjsg 	struct ddc_service *ddc_service;
522fb4d8502Sjsg };
523fb4d8502Sjsg 
524fb4d8502Sjsg #define TO_DM_AUX(x) container_of((x), struct amdgpu_dm_dp_aux, aux)
525fb4d8502Sjsg 
526fb4d8502Sjsg struct amdgpu_connector {
527fb4d8502Sjsg 	struct drm_connector base;
528fb4d8502Sjsg 	uint32_t connector_id;
529fb4d8502Sjsg 	uint32_t devices;
530fb4d8502Sjsg 	struct amdgpu_i2c_chan *ddc_bus;
531fb4d8502Sjsg 	/* some systems have an hdmi and vga port with a shared ddc line */
532fb4d8502Sjsg 	bool shared_ddc;
533fb4d8502Sjsg 	bool use_digital;
534fb4d8502Sjsg 	/* we need to mind the EDID between detect
535fb4d8502Sjsg 	   and get modes due to analog/digital/tvencoder */
536fb4d8502Sjsg 	struct edid *edid;
537fb4d8502Sjsg 	void *con_priv;
538fb4d8502Sjsg 	bool dac_load_detect;
539fb4d8502Sjsg 	bool detected_by_load; /* if the connection status was determined by load */
540*f005ef32Sjsg 	bool detected_hpd_without_ddc; /* if an HPD signal was detected on DVI, but ddc probing failed */
541fb4d8502Sjsg 	uint16_t connector_object_id;
542fb4d8502Sjsg 	struct amdgpu_hpd hpd;
543fb4d8502Sjsg 	struct amdgpu_router router;
544fb4d8502Sjsg 	struct amdgpu_i2c_chan *router_bus;
545fb4d8502Sjsg 	enum amdgpu_connector_audio audio;
546fb4d8502Sjsg 	enum amdgpu_connector_dither dither;
547fb4d8502Sjsg 	unsigned pixelclock_for_modeset;
548fb4d8502Sjsg };
549fb4d8502Sjsg 
550fb4d8502Sjsg /* TODO: start to use this struct and remove same field from base one */
551fb4d8502Sjsg struct amdgpu_mst_connector {
552fb4d8502Sjsg 	struct amdgpu_connector base;
553fb4d8502Sjsg 
554fb4d8502Sjsg 	struct drm_dp_mst_topology_mgr mst_mgr;
555fb4d8502Sjsg 	struct amdgpu_dm_dp_aux dm_dp_aux;
556*f005ef32Sjsg 	struct drm_dp_mst_port *mst_output_port;
557*f005ef32Sjsg 	struct amdgpu_connector *mst_root;
558fb4d8502Sjsg 	bool is_mst_connector;
559fb4d8502Sjsg 	struct amdgpu_encoder *mst_encoder;
560fb4d8502Sjsg };
561fb4d8502Sjsg 
562fb4d8502Sjsg #define ENCODER_MODE_IS_DP(em) (((em) == ATOM_ENCODER_MODE_DP) || \
563fb4d8502Sjsg 				((em) == ATOM_ENCODER_MODE_DP_MST))
564fb4d8502Sjsg 
565fb4d8502Sjsg /* Driver internal use only flags of amdgpu_display_get_crtc_scanoutpos() */
566fb4d8502Sjsg #define DRM_SCANOUTPOS_VALID        (1 << 0)
567fb4d8502Sjsg #define DRM_SCANOUTPOS_IN_VBLANK    (1 << 1)
568fb4d8502Sjsg #define DRM_SCANOUTPOS_ACCURATE     (1 << 2)
569fb4d8502Sjsg #define USE_REAL_VBLANKSTART		(1 << 30)
570fb4d8502Sjsg #define GET_DISTANCE_TO_VBLANKSTART	(1 << 31)
571fb4d8502Sjsg 
572fb4d8502Sjsg void amdgpu_link_encoder_connector(struct drm_device *dev);
573fb4d8502Sjsg 
574fb4d8502Sjsg struct drm_connector *
575fb4d8502Sjsg amdgpu_get_connector_for_encoder(struct drm_encoder *encoder);
576fb4d8502Sjsg struct drm_connector *
577fb4d8502Sjsg amdgpu_get_connector_for_encoder_init(struct drm_encoder *encoder);
578fb4d8502Sjsg bool amdgpu_dig_monitor_is_duallink(struct drm_encoder *encoder,
579fb4d8502Sjsg 				    u32 pixel_clock);
580fb4d8502Sjsg 
581fb4d8502Sjsg u16 amdgpu_encoder_get_dp_bridge_encoder_id(struct drm_encoder *encoder);
582fb4d8502Sjsg struct drm_encoder *amdgpu_get_external_encoder(struct drm_encoder *encoder);
583fb4d8502Sjsg 
584fb4d8502Sjsg bool amdgpu_display_ddc_probe(struct amdgpu_connector *amdgpu_connector,
585fb4d8502Sjsg 			      bool use_aux);
586fb4d8502Sjsg 
587fb4d8502Sjsg void amdgpu_encoder_set_active_device(struct drm_encoder *encoder);
588fb4d8502Sjsg 
589fb4d8502Sjsg int amdgpu_display_get_crtc_scanoutpos(struct drm_device *dev,
590fb4d8502Sjsg 			unsigned int pipe, unsigned int flags, int *vpos,
591fb4d8502Sjsg 			int *hpos, ktime_t *stime, ktime_t *etime,
592fb4d8502Sjsg 			const struct drm_display_mode *mode);
593fb4d8502Sjsg 
594fb4d8502Sjsg int amdgpufb_remove(struct drm_device *dev, struct drm_framebuffer *fb);
595fb4d8502Sjsg 
596fb4d8502Sjsg void amdgpu_enc_destroy(struct drm_encoder *encoder);
597fb4d8502Sjsg void amdgpu_copy_fb(struct drm_device *dev, struct drm_gem_object *dst_obj);
598fb4d8502Sjsg bool amdgpu_display_crtc_scaling_mode_fixup(struct drm_crtc *crtc,
599fb4d8502Sjsg 				const struct drm_display_mode *mode,
600fb4d8502Sjsg 				struct drm_display_mode *adjusted_mode);
601fb4d8502Sjsg void amdgpu_panel_mode_fixup(struct drm_encoder *encoder,
602fb4d8502Sjsg 			     struct drm_display_mode *adjusted_mode);
603fb4d8502Sjsg int amdgpu_display_crtc_idx_to_irq_type(struct amdgpu_device *adev, int crtc);
604fb4d8502Sjsg 
605c349dbc7Sjsg bool amdgpu_crtc_get_scanout_position(struct drm_crtc *crtc,
606c349dbc7Sjsg 			bool in_vblank_irq, int *vpos,
607c349dbc7Sjsg 			int *hpos, ktime_t *stime, ktime_t *etime,
608c349dbc7Sjsg 			const struct drm_display_mode *mode);
609c349dbc7Sjsg 
610fb4d8502Sjsg /* amdgpu_display.c */
611fb4d8502Sjsg void amdgpu_display_print_display_setup(struct drm_device *dev);
612fb4d8502Sjsg int amdgpu_display_modeset_create_props(struct amdgpu_device *adev);
613fb4d8502Sjsg int amdgpu_display_crtc_set_config(struct drm_mode_set *set,
614fb4d8502Sjsg 				   struct drm_modeset_acquire_ctx *ctx);
615fb4d8502Sjsg int amdgpu_display_crtc_page_flip_target(struct drm_crtc *crtc,
616fb4d8502Sjsg 				struct drm_framebuffer *fb,
617fb4d8502Sjsg 				struct drm_pending_vblank_event *event,
618fb4d8502Sjsg 				uint32_t page_flip_flags, uint32_t target,
619fb4d8502Sjsg 				struct drm_modeset_acquire_ctx *ctx);
620fb4d8502Sjsg extern const struct drm_mode_config_funcs amdgpu_mode_funcs;
621fb4d8502Sjsg 
622fb4d8502Sjsg #endif
623