radeon: get primary dac adj info from bios tables
[platform/upstream/libdrm.git] / linux-core / radeon_mode.h
1 /*
2  * Copyright 2000 ATI Technologies Inc., Markham, Ontario, and
3  *                VA Linux Systems Inc., Fremont, California.
4  * Copyright 2008 Red Hat Inc.
5  *
6  * Permission is hereby granted, free of charge, to any person obtaining a
7  * copy of this software and associated documentation files (the "Software"),
8  * to deal in the Software without restriction, including without limitation
9  * the rights to use, copy, modify, merge, publish, distribute, sublicense,
10  * and/or sell copies of the Software, and to permit persons to whom the
11  * Software is furnished to do so, subject to the following conditions:
12  *
13  * The above copyright notice and this permission notice shall be included in
14  * all copies or substantial portions of the Software.
15  *
16  * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
17  * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
18  * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.  IN NO EVENT SHALL
19  * THE COPYRIGHT HOLDER(S) OR AUTHOR(S) BE LIABLE FOR ANY CLAIM, DAMAGES OR
20  * OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
21  * ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
22  * OTHER DEALINGS IN THE SOFTWARE.
23  *
24  * Original Authors:
25  *   Kevin E. Martin, Rickard E. Faith, Alan Hourihane
26  *
27  * Kernel port Author: Dave Airlie
28  */
29
30 #ifndef RADEON_MODE_H
31 #define RADEON_MODE_H
32
33 #include <linux/i2c.h>
34 #include <linux/i2c-id.h>
35 #include <linux/i2c-algo-bit.h>
36
37 #define to_radeon_crtc(x) container_of(x, struct radeon_crtc, base)
38 #define to_radeon_connector(x) container_of(x, struct radeon_connector, base)
39 #define to_radeon_encoder(x) container_of(x, struct radeon_encoder, base)
40 #define to_radeon_framebuffer(x) container_of(x, struct radeon_framebuffer, base)
41
42 enum radeon_connector_type {
43         CONNECTOR_NONE,
44         CONNECTOR_VGA,
45         CONNECTOR_DVI_I,
46         CONNECTOR_DVI_D,
47         CONNECTOR_DVI_A,
48         CONNECTOR_STV,
49         CONNECTOR_CTV,
50         CONNECTOR_LVDS,
51         CONNECTOR_DIGITAL,
52         CONNECTOR_SCART,
53         CONNECTOR_HDMI_TYPE_A,
54         CONNECTOR_HDMI_TYPE_B,
55         CONNECTOR_0XC,
56         CONNECTOR_0XD,
57         CONNECTOR_DIN,
58         CONNECTOR_DISPLAY_PORT,
59         CONNECTOR_UNSUPPORTED
60 };
61
62 enum radeon_dac_type {
63         DAC_NONE = 0,
64         DAC_PRIMARY = 1,
65         DAC_TVDAC = 2,
66         DAC_EXT = 3
67 };
68
69 enum radeon_tmds_type {
70         TMDS_NONE = 0,
71         TMDS_INT = 1,
72         TMDS_EXT = 2,
73         TMDS_LVTMA = 3,
74         TMDS_DDIA = 4,
75         TMDS_UNIPHY = 5
76 };
77
78 enum radeon_dvi_type {
79         DVI_AUTO,
80         DVI_DIGITAL,
81         DVI_ANALOG
82 };
83
84 enum radeon_rmx_type {
85         RMX_OFF,
86         RMX_FULL,
87         RMX_CENTER,
88 };
89
90 enum radeon_tv_std {
91         TV_STD_NTSC,
92         TV_STD_PAL,
93         TV_STD_PAL_M,
94         TV_STD_PAL_60,
95         TV_STD_NTSC_J,
96         TV_STD_SCART_PAL,
97         TV_STD_SECAM,
98         TV_STD_PAL_CN,
99 };
100
101 struct radeon_i2c_bus_rec {
102         bool valid;
103         uint32_t mask_clk_reg;
104         uint32_t mask_data_reg;
105         uint32_t a_clk_reg;
106         uint32_t a_data_reg;
107         uint32_t put_clk_reg;
108         uint32_t put_data_reg;
109         uint32_t get_clk_reg;
110         uint32_t get_data_reg;
111         uint32_t mask_clk_mask;
112         uint32_t mask_data_mask;
113         uint32_t put_clk_mask;
114         uint32_t put_data_mask;
115         uint32_t get_clk_mask;
116         uint32_t get_data_mask;
117         uint32_t a_clk_mask;
118         uint32_t a_data_mask;
119 };
120
121 struct radeon_bios_connector {
122         enum radeon_dac_type dac_type;
123         enum radeon_tmds_type tmds_type;
124         enum radeon_connector_type connector_type;
125         bool valid;
126         int output_id;
127         int devices;
128         int hpd_mask;
129         struct radeon_i2c_bus_rec ddc_i2c;
130         int igp_lane_info;
131 };
132
133 struct radeon_tmds_pll {
134     uint32_t freq;
135     uint32_t value;
136 };
137
138 #define RADEON_MAX_BIOS_CONNECTOR 16
139
140 #define RADEON_PLL_USE_BIOS_DIVS   (1 << 0)
141 #define RADEON_PLL_NO_ODD_POST_DIV (1 << 1)
142 #define RADEON_PLL_USE_REF_DIV     (1 << 2)
143 #define RADEON_PLL_LEGACY          (1 << 3)
144 #define RADEON_PLL_PREFER_LOW_REF_DIV (1 << 4)
145
146 struct radeon_pll {
147         uint16_t reference_freq;
148         uint16_t reference_div;
149         uint32_t pll_in_min;
150         uint32_t pll_in_max;
151         uint32_t pll_out_min;
152         uint32_t pll_out_max;
153         uint16_t xclk;
154
155         uint32_t min_ref_div;
156         uint32_t max_ref_div;
157         uint32_t min_post_div;
158         uint32_t max_post_div;
159         uint32_t min_feedback_div;
160         uint32_t max_feedback_div;
161         uint32_t best_vco;
162 };
163
164 #define MAX_H_CODE_TIMING_LEN 32
165 #define MAX_V_CODE_TIMING_LEN 32
166
167 struct radeon_legacy_state {
168
169         uint32_t bus_cntl;
170
171         /* DAC */
172         uint32_t dac_cntl;
173         uint32_t dac2_cntl;
174         uint32_t dac_macro_cntl;
175
176         /* CRTC 1 */
177         uint32_t crtc_gen_cntl;
178         uint32_t crtc_ext_cntl;
179         uint32_t crtc_h_total_disp;
180         uint32_t crtc_h_sync_strt_wid;
181         uint32_t crtc_v_total_disp;
182         uint32_t crtc_v_sync_strt_wid;
183         uint32_t crtc_offset;
184         uint32_t crtc_offset_cntl;
185         uint32_t crtc_pitch;
186         uint32_t disp_merge_cntl;
187         uint32_t grph_buffer_cntl;
188         uint32_t crtc_more_cntl;
189         uint32_t crtc_tile_x0_y0;
190
191         /* CRTC 2 */
192         uint32_t crtc2_gen_cntl;
193         uint32_t crtc2_h_total_disp;
194         uint32_t crtc2_h_sync_strt_wid;
195         uint32_t crtc2_v_total_disp;
196         uint32_t crtc2_v_sync_strt_wid;
197         uint32_t crtc2_offset;
198         uint32_t crtc2_offset_cntl;
199         uint32_t crtc2_pitch;
200         uint32_t crtc2_tile_x0_y0;
201
202         uint32_t disp_output_cntl;
203         uint32_t disp_tv_out_cntl;
204         uint32_t disp_hw_debug;
205         uint32_t disp2_merge_cntl;
206         uint32_t grph2_buffer_cntl;
207
208         /* FP regs */
209         uint32_t fp_crtc_h_total_disp;
210         uint32_t fp_crtc_v_total_disp;
211         uint32_t fp_gen_cntl;
212         uint32_t fp2_gen_cntl;
213         uint32_t fp_h_sync_strt_wid;
214         uint32_t fp_h2_sync_strt_wid;
215         uint32_t fp_horz_stretch;
216         uint32_t fp_horz_vert_active;
217         uint32_t fp_panel_cntl;
218         uint32_t fp_v_sync_strt_wid;
219         uint32_t fp_v2_sync_strt_wid;
220         uint32_t fp_vert_stretch;
221         uint32_t lvds_gen_cntl;
222         uint32_t lvds_pll_cntl;
223         uint32_t tmds_pll_cntl;
224         uint32_t tmds_transmitter_cntl;
225
226         /* Computed values for PLL */
227         uint32_t dot_clock_freq;
228         uint32_t pll_output_freq;
229         int  feedback_div;
230         int  reference_div;
231         int  post_div;
232
233         /* PLL registers */
234         uint32_t ppll_ref_div;
235         uint32_t ppll_div_3;
236         uint32_t htotal_cntl;
237         uint32_t vclk_ecp_cntl;
238
239         /* Computed values for PLL2 */
240         uint32_t dot_clock_freq_2;
241         uint32_t pll_output_freq_2;
242         int feedback_div_2;
243         int reference_div_2;
244         int post_div_2;
245
246         /* PLL2 registers */
247         uint32_t p2pll_ref_div;
248         uint32_t p2pll_div_0;
249         uint32_t htotal_cntl2;
250         uint32_t pixclks_cntl;
251
252         bool palette_valid;
253         uint32_t palette[256];
254         uint32_t palette2[256];
255
256         uint32_t disp2_req_cntl1;
257         uint32_t disp2_req_cntl2;
258         uint32_t dmif_mem_cntl1;
259         uint32_t disp1_req_cntl1;
260
261         uint32_t fp_2nd_gen_cntl;
262         uint32_t fp2_2_gen_cntl;
263         uint32_t tmds2_cntl;
264         uint32_t tmds2_transmitter_cntl;
265
266         /* TV out registers */
267         uint32_t tv_master_cntl;
268         uint32_t tv_htotal;
269         uint32_t tv_hsize;
270         uint32_t tv_hdisp;
271         uint32_t tv_hstart;
272         uint32_t tv_vtotal;
273         uint32_t tv_vdisp;
274         uint32_t tv_timing_cntl;
275         uint32_t tv_vscaler_cntl1;
276         uint32_t tv_vscaler_cntl2;
277         uint32_t tv_sync_size;
278         uint32_t tv_vrestart;
279         uint32_t tv_hrestart;
280         uint32_t tv_frestart;
281         uint32_t tv_ftotal;
282         uint32_t tv_clock_sel_cntl;
283         uint32_t tv_clkout_cntl;
284         uint32_t tv_data_delay_a;
285         uint32_t tv_data_delay_b;
286         uint32_t tv_dac_cntl;
287         uint32_t tv_pll_cntl;
288         uint32_t tv_pll_cntl1;
289         uint32_t tv_pll_fine_cntl;
290         uint32_t tv_modulator_cntl1;
291         uint32_t tv_modulator_cntl2;
292         uint32_t tv_frame_lock_cntl;
293         uint32_t tv_pre_dac_mux_cntl;
294         uint32_t tv_rgb_cntl;
295         uint32_t tv_y_saw_tooth_cntl;
296         uint32_t tv_y_rise_cntl;
297         uint32_t tv_y_fall_cntl;
298         uint32_t tv_uv_adr;
299         uint32_t tv_upsamp_and_gain_cntl;
300         uint32_t tv_gain_limit_settings;
301         uint32_t tv_linear_gain_settings;
302         uint32_t tv_crc_cntl;
303         uint32_t tv_sync_cntl;
304         uint32_t gpiopad_a;
305         uint32_t pll_test_cntl;
306
307         uint16_t h_code_timing[MAX_H_CODE_TIMING_LEN];
308         uint16_t v_code_timing[MAX_V_CODE_TIMING_LEN];
309
310
311 };
312
313 struct radeon_mode_info {
314         struct atom_context *atom_context;
315         struct radeon_bios_connector bios_connector[RADEON_MAX_BIOS_CONNECTOR];
316         struct radeon_pll pll;
317         struct radeon_legacy_state legacy_state;
318 };
319
320 struct radeon_crtc {
321         struct drm_crtc base;
322         int crtc_id;
323         u8 lut_r[256], lut_g[256], lut_b[256];
324         bool enabled;
325         bool can_tile;
326         uint32_t crtc_offset;
327         struct radeon_framebuffer *fbdev_fb;
328         struct drm_mode_set mode_set;
329 };
330
331 struct radeon_i2c_chan {
332         struct drm_device *dev;
333         struct i2c_adapter adapter;
334         struct i2c_algo_bit_data algo;
335         struct radeon_i2c_bus_rec rec;
336 };
337
338
339 #define RADEON_USE_RMX 1
340
341 struct radeon_encoder {
342         struct drm_encoder base;
343         uint32_t encoder_mode;
344         uint32_t flags;
345         enum radeon_rmx_type rmx_type;
346         union {
347                 enum radeon_dac_type dac;
348                 enum radeon_tmds_type tmds;
349         } type;
350         int atom_device; /* atom devices */
351
352         /* preferred mode */
353         uint32_t panel_xres, panel_yres;
354         uint32_t hoverplus, hsync_width;
355         uint32_t hblank;
356         uint32_t voverplus, vsync_width;
357         uint32_t vblank;
358         uint32_t dotclock;
359
360         /* legacy lvds */
361         uint16_t panel_vcc_delay;
362         uint16_t panel_pwr_delay;
363         uint16_t panel_digon_delay;
364         uint16_t panel_blon_delay;
365         uint32_t panel_ref_divider;
366         uint32_t panel_post_divider;
367         uint32_t panel_fb_divider;
368         bool use_bios_dividers;
369         uint32_t lvds_gen_cntl;
370
371         /* legacy primary dac */
372         uint32_t ps2_pdac_adj;
373
374         /* legacy tv dac */
375         uint32_t ps2_tvdac_adj;
376         uint32_t ntsc_tvdac_adj;
377         uint32_t pal_tvdac_adj;
378         enum radeon_tv_std tv_std;
379
380         /* legacy int tmds */
381         struct radeon_tmds_pll tmds_pll[4];
382 };
383
384 struct radeon_connector {
385         struct drm_connector base;
386         struct radeon_i2c_chan *ddc_bus;
387         int use_digital;
388 };
389
390 struct radeon_framebuffer {
391         struct drm_framebuffer base;
392         struct drm_gem_object *obj;
393         struct drm_bo_kmap_obj kmap_obj;
394 };
395
396 extern struct radeon_i2c_chan *radeon_i2c_create(struct drm_device *dev,
397                                                  struct radeon_i2c_bus_rec *rec,
398                                                  const char *name);
399 extern void radeon_i2c_destroy(struct radeon_i2c_chan *i2c);
400 extern int radeon_ddc_get_modes(struct radeon_connector *radeon_connector);
401 extern struct drm_connector *radeon_connector_add(struct drm_device *dev, int bios_index);
402
403 extern struct drm_encoder *radeon_best_encoder(struct drm_connector *connector);
404
405 extern void radeon_compute_pll(struct radeon_pll *pll,
406                                uint64_t freq,
407                                uint32_t *dot_clock_p,
408                                uint32_t *fb_div_p,
409                                uint32_t *ref_div_p,
410                                uint32_t *post_div_p,
411                                int flags);
412
413 struct drm_encoder *radeon_encoder_lvtma_add(struct drm_device *dev, int bios_index);
414 struct drm_encoder *radeon_encoder_atom_dac_add(struct drm_device *dev, int bios_index, int dac_id, int with_tv);
415 struct drm_encoder *radeon_encoder_atom_tmds_add(struct drm_device *dev, int bios_index, int tmds_type);
416 struct drm_encoder *radeon_encoder_legacy_lvds_add(struct drm_device *dev, int bios_index);
417 struct drm_encoder *radeon_encoder_legacy_primary_dac_add(struct drm_device *dev, int bios_index, int with_tv);
418 struct drm_encoder *radeon_encoder_legacy_tv_dac_add(struct drm_device *dev, int bios_index, int with_tv);
419 struct drm_encoder *radeon_encoder_legacy_tmds_int_add(struct drm_device *dev, int bios_index);
420 struct drm_encoder *radeon_encoder_legacy_tmds_ext_add(struct drm_device *dev, int bios_index);
421
422 extern void radeon_crtc_load_lut(struct drm_crtc *crtc);
423 extern void atombios_crtc_set_base(struct drm_crtc *crtc, int x, int y);
424 extern void atombios_crtc_mode_set(struct drm_crtc *crtc,
425                                    struct drm_display_mode *mode,
426                                    struct drm_display_mode *adjusted_mode,
427                                    int x, int y);
428 extern void atombios_crtc_dpms(struct drm_crtc *crtc, int mode);
429
430 extern int radeon_crtc_cursor_set(struct drm_crtc *crtc,
431                                   struct drm_file *file_priv,
432                                   uint32_t handle,
433                                   uint32_t width,
434                                   uint32_t height);
435 extern int radeon_crtc_cursor_move(struct drm_crtc *crtc,
436                                    int x, int y);
437
438 extern bool radeon_atom_get_clock_info(struct drm_device *dev);
439 extern bool radeon_combios_get_clock_info(struct drm_device *dev);
440 extern void radeon_get_lvds_info(struct radeon_encoder *encoder);
441 extern bool radeon_combios_get_lvds_info(struct radeon_encoder *encoder);
442 extern bool radeon_combios_get_tmds_info(struct radeon_encoder *encoder);
443 extern bool radeon_combios_get_tv_info(struct radeon_encoder *encoder);
444 extern bool radeon_combios_get_tv_dac_info(struct radeon_encoder *encoder);
445 extern bool radeon_combios_get_primary_dac_info(struct radeon_encoder *encoder);
446 extern void radeon_crtc_fb_gamma_set(struct drm_crtc *crtc, u16 red, u16 green,
447                                      u16 blue, int regno);
448 struct drm_framebuffer *radeon_user_framebuffer_create(struct drm_device *dev,
449                                                        struct drm_file *filp,
450                                                        struct drm_mode_fb_cmd *mode_cmd);
451
452 int radeonfb_probe(struct drm_device *dev);
453
454 int radeonfb_remove(struct drm_device *dev, struct drm_framebuffer *fb);
455 bool radeon_get_legacy_connector_info_from_bios(struct drm_device *dev);
456 void radeon_atombios_init_crtc(struct drm_device *dev,
457                                struct radeon_crtc *radeon_crtc);
458 void radeon_legacy_init_crtc(struct drm_device *dev,
459                              struct radeon_crtc *radeon_crtc);
460 void radeon_i2c_do_lock(struct radeon_connector *radeon_connector, int lock_state);
461
462 void radeon_atom_static_pwrmgt_setup(struct drm_device *dev, int enable);
463 void radeon_atom_dyn_clk_setup(struct drm_device *dev, int enable);
464 void radeon_get_clock_info(struct drm_device *dev);
465 extern bool radeon_get_atom_connector_info_from_bios_connector_table(struct drm_device *dev);
466
467 void radeon_rmx_mode_fixup(struct drm_encoder *encoder,
468                            struct drm_display_mode *mode,
469                            struct drm_display_mode *adjusted_mode);
470 void radeon_enc_destroy(struct drm_encoder *encoder);
471
472 #endif