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