Staging: netwave: delete the driver
[linux/fpc-iii.git] / drivers / gpu / drm / radeon / radeon_mode.h
blob0b8e32776b10930b3dc67266c49a21fce3933a46
1 /*
2 * Copyright 2000 ATI Technologies Inc., Markham, Ontario, and
3 * VA Linux Systems Inc., Fremont, California.
4 * Copyright 2008 Red Hat Inc.
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:
13 * The above copyright notice and this permission notice shall be included in
14 * all copies or substantial portions of the Software.
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.
24 * Original Authors:
25 * Kevin E. Martin, Rickard E. Faith, Alan Hourihane
27 * Kernel port Author: Dave Airlie
30 #ifndef RADEON_MODE_H
31 #define RADEON_MODE_H
33 #include <drm_crtc.h>
34 #include <drm_mode.h>
35 #include <drm_edid.h>
36 #include <drm_dp_helper.h>
37 #include <linux/i2c.h>
38 #include <linux/i2c-id.h>
39 #include <linux/i2c-algo-bit.h>
40 #include "radeon_fixed.h"
42 struct radeon_device;
44 #define to_radeon_crtc(x) container_of(x, struct radeon_crtc, base)
45 #define to_radeon_connector(x) container_of(x, struct radeon_connector, base)
46 #define to_radeon_encoder(x) container_of(x, struct radeon_encoder, base)
47 #define to_radeon_framebuffer(x) container_of(x, struct radeon_framebuffer, base)
49 enum radeon_rmx_type {
50 RMX_OFF,
51 RMX_FULL,
52 RMX_CENTER,
53 RMX_ASPECT
56 enum radeon_tv_std {
57 TV_STD_NTSC,
58 TV_STD_PAL,
59 TV_STD_PAL_M,
60 TV_STD_PAL_60,
61 TV_STD_NTSC_J,
62 TV_STD_SCART_PAL,
63 TV_STD_SECAM,
64 TV_STD_PAL_CN,
65 TV_STD_PAL_N,
68 /* radeon gpio-based i2c
69 * 1. "mask" reg and bits
70 * grabs the gpio pins for software use
71 * 0=not held 1=held
72 * 2. "a" reg and bits
73 * output pin value
74 * 0=low 1=high
75 * 3. "en" reg and bits
76 * sets the pin direction
77 * 0=input 1=output
78 * 4. "y" reg and bits
79 * input pin value
80 * 0=low 1=high
82 struct radeon_i2c_bus_rec {
83 bool valid;
84 /* id used by atom */
85 uint8_t i2c_id;
86 /* id used by atom */
87 uint8_t hpd_id;
88 /* can be used with hw i2c engine */
89 bool hw_capable;
90 /* uses multi-media i2c engine */
91 bool mm_i2c;
92 /* regs and bits */
93 uint32_t mask_clk_reg;
94 uint32_t mask_data_reg;
95 uint32_t a_clk_reg;
96 uint32_t a_data_reg;
97 uint32_t en_clk_reg;
98 uint32_t en_data_reg;
99 uint32_t y_clk_reg;
100 uint32_t y_data_reg;
101 uint32_t mask_clk_mask;
102 uint32_t mask_data_mask;
103 uint32_t a_clk_mask;
104 uint32_t a_data_mask;
105 uint32_t en_clk_mask;
106 uint32_t en_data_mask;
107 uint32_t y_clk_mask;
108 uint32_t y_data_mask;
111 struct radeon_tmds_pll {
112 uint32_t freq;
113 uint32_t value;
116 #define RADEON_MAX_BIOS_CONNECTOR 16
118 /* pll flags */
119 #define RADEON_PLL_USE_BIOS_DIVS (1 << 0)
120 #define RADEON_PLL_NO_ODD_POST_DIV (1 << 1)
121 #define RADEON_PLL_USE_REF_DIV (1 << 2)
122 #define RADEON_PLL_LEGACY (1 << 3)
123 #define RADEON_PLL_PREFER_LOW_REF_DIV (1 << 4)
124 #define RADEON_PLL_PREFER_HIGH_REF_DIV (1 << 5)
125 #define RADEON_PLL_PREFER_LOW_FB_DIV (1 << 6)
126 #define RADEON_PLL_PREFER_HIGH_FB_DIV (1 << 7)
127 #define RADEON_PLL_PREFER_LOW_POST_DIV (1 << 8)
128 #define RADEON_PLL_PREFER_HIGH_POST_DIV (1 << 9)
129 #define RADEON_PLL_USE_FRAC_FB_DIV (1 << 10)
130 #define RADEON_PLL_PREFER_CLOSEST_LOWER (1 << 11)
131 #define RADEON_PLL_USE_POST_DIV (1 << 12)
132 #define RADEON_PLL_IS_LCD (1 << 13)
134 /* pll algo */
135 enum radeon_pll_algo {
136 PLL_ALGO_LEGACY,
137 PLL_ALGO_NEW
140 struct radeon_pll {
141 /* reference frequency */
142 uint32_t reference_freq;
144 /* fixed dividers */
145 uint32_t reference_div;
146 uint32_t post_div;
148 /* pll in/out limits */
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 uint32_t lcd_pll_out_min;
154 uint32_t lcd_pll_out_max;
155 uint32_t best_vco;
157 /* divider limits */
158 uint32_t min_ref_div;
159 uint32_t max_ref_div;
160 uint32_t min_post_div;
161 uint32_t max_post_div;
162 uint32_t min_feedback_div;
163 uint32_t max_feedback_div;
164 uint32_t min_frac_feedback_div;
165 uint32_t max_frac_feedback_div;
167 /* flags for the current clock */
168 uint32_t flags;
170 /* pll id */
171 uint32_t id;
172 /* pll algo */
173 enum radeon_pll_algo algo;
176 struct radeon_i2c_chan {
177 struct i2c_adapter adapter;
178 struct drm_device *dev;
179 union {
180 struct i2c_algo_bit_data bit;
181 struct i2c_algo_dp_aux_data dp;
182 } algo;
183 struct radeon_i2c_bus_rec rec;
186 /* mostly for macs, but really any system without connector tables */
187 enum radeon_connector_table {
188 CT_NONE,
189 CT_GENERIC,
190 CT_IBOOK,
191 CT_POWERBOOK_EXTERNAL,
192 CT_POWERBOOK_INTERNAL,
193 CT_POWERBOOK_VGA,
194 CT_MINI_EXTERNAL,
195 CT_MINI_INTERNAL,
196 CT_IMAC_G5_ISIGHT,
197 CT_EMAC,
200 enum radeon_dvo_chip {
201 DVO_SIL164,
202 DVO_SIL1178,
205 struct radeon_mode_info {
206 struct atom_context *atom_context;
207 struct card_info *atom_card_info;
208 enum radeon_connector_table connector_table;
209 bool mode_config_initialized;
210 struct radeon_crtc *crtcs[6];
211 /* DVI-I properties */
212 struct drm_property *coherent_mode_property;
213 /* DAC enable load detect */
214 struct drm_property *load_detect_property;
215 /* TV standard load detect */
216 struct drm_property *tv_std_property;
217 /* legacy TMDS PLL detect */
218 struct drm_property *tmds_pll_property;
219 /* hardcoded DFP edid from BIOS */
220 struct edid *bios_hardcoded_edid;
223 #define MAX_H_CODE_TIMING_LEN 32
224 #define MAX_V_CODE_TIMING_LEN 32
226 /* need to store these as reading
227 back code tables is excessive */
228 struct radeon_tv_regs {
229 uint32_t tv_uv_adr;
230 uint32_t timing_cntl;
231 uint32_t hrestart;
232 uint32_t vrestart;
233 uint32_t frestart;
234 uint16_t h_code_timing[MAX_H_CODE_TIMING_LEN];
235 uint16_t v_code_timing[MAX_V_CODE_TIMING_LEN];
238 struct radeon_crtc {
239 struct drm_crtc base;
240 int crtc_id;
241 u16 lut_r[256], lut_g[256], lut_b[256];
242 bool enabled;
243 bool can_tile;
244 uint32_t crtc_offset;
245 struct drm_gem_object *cursor_bo;
246 uint64_t cursor_addr;
247 int cursor_width;
248 int cursor_height;
249 uint32_t legacy_display_base_addr;
250 uint32_t legacy_cursor_offset;
251 enum radeon_rmx_type rmx_type;
252 fixed20_12 vsc;
253 fixed20_12 hsc;
254 struct drm_display_mode native_mode;
255 int pll_id;
258 struct radeon_encoder_primary_dac {
259 /* legacy primary dac */
260 uint32_t ps2_pdac_adj;
263 struct radeon_encoder_lvds {
264 /* legacy lvds */
265 uint16_t panel_vcc_delay;
266 uint8_t panel_pwr_delay;
267 uint8_t panel_digon_delay;
268 uint8_t panel_blon_delay;
269 uint16_t panel_ref_divider;
270 uint8_t panel_post_divider;
271 uint16_t panel_fb_divider;
272 bool use_bios_dividers;
273 uint32_t lvds_gen_cntl;
274 /* panel mode */
275 struct drm_display_mode native_mode;
278 struct radeon_encoder_tv_dac {
279 /* legacy tv dac */
280 uint32_t ps2_tvdac_adj;
281 uint32_t ntsc_tvdac_adj;
282 uint32_t pal_tvdac_adj;
284 int h_pos;
285 int v_pos;
286 int h_size;
287 int supported_tv_stds;
288 bool tv_on;
289 enum radeon_tv_std tv_std;
290 struct radeon_tv_regs tv;
293 struct radeon_encoder_int_tmds {
294 /* legacy int tmds */
295 struct radeon_tmds_pll tmds_pll[4];
298 struct radeon_encoder_ext_tmds {
299 /* tmds over dvo */
300 struct radeon_i2c_chan *i2c_bus;
301 uint8_t slave_addr;
302 enum radeon_dvo_chip dvo_chip;
305 /* spread spectrum */
306 struct radeon_atom_ss {
307 uint16_t percentage;
308 uint8_t type;
309 uint8_t step;
310 uint8_t delay;
311 uint8_t range;
312 uint8_t refdiv;
315 struct radeon_encoder_atom_dig {
316 /* atom dig */
317 bool coherent_mode;
318 int dig_encoder; /* -1 disabled, 0 DIGA, 1 DIGB */
319 /* atom lvds */
320 uint32_t lvds_misc;
321 uint16_t panel_pwr_delay;
322 enum radeon_pll_algo pll_algo;
323 struct radeon_atom_ss *ss;
324 /* panel mode */
325 struct drm_display_mode native_mode;
328 struct radeon_encoder_atom_dac {
329 enum radeon_tv_std tv_std;
332 struct radeon_encoder {
333 struct drm_encoder base;
334 uint32_t encoder_id;
335 uint32_t devices;
336 uint32_t active_device;
337 uint32_t flags;
338 uint32_t pixel_clock;
339 enum radeon_rmx_type rmx_type;
340 struct drm_display_mode native_mode;
341 void *enc_priv;
342 int hdmi_offset;
343 int hdmi_config_offset;
344 int hdmi_audio_workaround;
345 int hdmi_buffer_status;
348 struct radeon_connector_atom_dig {
349 uint32_t igp_lane_info;
350 bool linkb;
351 /* displayport */
352 struct radeon_i2c_chan *dp_i2c_bus;
353 u8 dpcd[8];
354 u8 dp_sink_type;
355 int dp_clock;
356 int dp_lane_count;
359 struct radeon_gpio_rec {
360 bool valid;
361 u8 id;
362 u32 reg;
363 u32 mask;
366 enum radeon_hpd_id {
367 RADEON_HPD_NONE = 0,
368 RADEON_HPD_1,
369 RADEON_HPD_2,
370 RADEON_HPD_3,
371 RADEON_HPD_4,
372 RADEON_HPD_5,
373 RADEON_HPD_6,
376 struct radeon_hpd {
377 enum radeon_hpd_id hpd;
378 u8 plugged_state;
379 struct radeon_gpio_rec gpio;
382 struct radeon_connector {
383 struct drm_connector base;
384 uint32_t connector_id;
385 uint32_t devices;
386 struct radeon_i2c_chan *ddc_bus;
387 /* some systems have a an hdmi and vga port with a shared ddc line */
388 bool shared_ddc;
389 bool use_digital;
390 /* we need to mind the EDID between detect
391 and get modes due to analog/digital/tvencoder */
392 struct edid *edid;
393 void *con_priv;
394 bool dac_load_detect;
395 uint16_t connector_object_id;
396 struct radeon_hpd hpd;
399 struct radeon_framebuffer {
400 struct drm_framebuffer base;
401 struct drm_gem_object *obj;
404 extern enum radeon_tv_std
405 radeon_combios_get_tv_info(struct radeon_device *rdev);
406 extern enum radeon_tv_std
407 radeon_atombios_get_tv_info(struct radeon_device *rdev);
409 extern void radeon_connector_hotplug(struct drm_connector *connector);
410 extern bool radeon_dp_needs_link_train(struct radeon_connector *radeon_connector);
411 extern int radeon_dp_mode_valid_helper(struct radeon_connector *radeon_connector,
412 struct drm_display_mode *mode);
413 extern void radeon_dp_set_link_config(struct drm_connector *connector,
414 struct drm_display_mode *mode);
415 extern void dp_link_train(struct drm_encoder *encoder,
416 struct drm_connector *connector);
417 extern u8 radeon_dp_getsinktype(struct radeon_connector *radeon_connector);
418 extern bool radeon_dp_getdpcd(struct radeon_connector *radeon_connector);
419 extern void atombios_dig_encoder_setup(struct drm_encoder *encoder, int action);
420 extern void atombios_dig_transmitter_setup(struct drm_encoder *encoder,
421 int action, uint8_t lane_num,
422 uint8_t lane_set);
423 extern int radeon_dp_i2c_aux_ch(struct i2c_adapter *adapter, int mode,
424 uint8_t write_byte, uint8_t *read_byte);
426 extern struct radeon_i2c_chan *radeon_i2c_create_dp(struct drm_device *dev,
427 struct radeon_i2c_bus_rec *rec,
428 const char *name);
429 extern struct radeon_i2c_chan *radeon_i2c_create(struct drm_device *dev,
430 struct radeon_i2c_bus_rec *rec,
431 const char *name);
432 extern void radeon_i2c_destroy(struct radeon_i2c_chan *i2c);
433 extern void radeon_i2c_get_byte(struct radeon_i2c_chan *i2c_bus,
434 u8 slave_addr,
435 u8 addr,
436 u8 *val);
437 extern void radeon_i2c_put_byte(struct radeon_i2c_chan *i2c,
438 u8 slave_addr,
439 u8 addr,
440 u8 val);
441 extern bool radeon_ddc_probe(struct radeon_connector *radeon_connector);
442 extern int radeon_ddc_get_modes(struct radeon_connector *radeon_connector);
444 extern struct drm_encoder *radeon_best_encoder(struct drm_connector *connector);
446 extern void radeon_compute_pll(struct radeon_pll *pll,
447 uint64_t freq,
448 uint32_t *dot_clock_p,
449 uint32_t *fb_div_p,
450 uint32_t *frac_fb_div_p,
451 uint32_t *ref_div_p,
452 uint32_t *post_div_p);
454 extern void radeon_setup_encoder_clones(struct drm_device *dev);
456 struct drm_encoder *radeon_encoder_legacy_lvds_add(struct drm_device *dev, int bios_index);
457 struct drm_encoder *radeon_encoder_legacy_primary_dac_add(struct drm_device *dev, int bios_index, int with_tv);
458 struct drm_encoder *radeon_encoder_legacy_tv_dac_add(struct drm_device *dev, int bios_index, int with_tv);
459 struct drm_encoder *radeon_encoder_legacy_tmds_int_add(struct drm_device *dev, int bios_index);
460 struct drm_encoder *radeon_encoder_legacy_tmds_ext_add(struct drm_device *dev, int bios_index);
461 extern void atombios_external_tmds_setup(struct drm_encoder *encoder, int action);
462 extern void atombios_digital_setup(struct drm_encoder *encoder, int action);
463 extern int atombios_get_encoder_mode(struct drm_encoder *encoder);
464 extern void radeon_encoder_set_active_device(struct drm_encoder *encoder);
466 extern void radeon_crtc_load_lut(struct drm_crtc *crtc);
467 extern int atombios_crtc_set_base(struct drm_crtc *crtc, int x, int y,
468 struct drm_framebuffer *old_fb);
469 extern int atombios_crtc_mode_set(struct drm_crtc *crtc,
470 struct drm_display_mode *mode,
471 struct drm_display_mode *adjusted_mode,
472 int x, int y,
473 struct drm_framebuffer *old_fb);
474 extern void atombios_crtc_dpms(struct drm_crtc *crtc, int mode);
476 extern int radeon_crtc_set_base(struct drm_crtc *crtc, int x, int y,
477 struct drm_framebuffer *old_fb);
479 extern int radeon_crtc_cursor_set(struct drm_crtc *crtc,
480 struct drm_file *file_priv,
481 uint32_t handle,
482 uint32_t width,
483 uint32_t height);
484 extern int radeon_crtc_cursor_move(struct drm_crtc *crtc,
485 int x, int y);
487 extern bool radeon_combios_check_hardcoded_edid(struct radeon_device *rdev);
488 extern struct edid *
489 radeon_combios_get_hardcoded_edid(struct radeon_device *rdev);
490 extern bool radeon_atom_get_clock_info(struct drm_device *dev);
491 extern bool radeon_combios_get_clock_info(struct drm_device *dev);
492 extern struct radeon_encoder_atom_dig *
493 radeon_atombios_get_lvds_info(struct radeon_encoder *encoder);
494 extern bool radeon_atombios_get_tmds_info(struct radeon_encoder *encoder,
495 struct radeon_encoder_int_tmds *tmds);
496 extern bool radeon_legacy_get_tmds_info_from_combios(struct radeon_encoder *encoder,
497 struct radeon_encoder_int_tmds *tmds);
498 extern bool radeon_legacy_get_tmds_info_from_table(struct radeon_encoder *encoder,
499 struct radeon_encoder_int_tmds *tmds);
500 extern bool radeon_legacy_get_ext_tmds_info_from_combios(struct radeon_encoder *encoder,
501 struct radeon_encoder_ext_tmds *tmds);
502 extern bool radeon_legacy_get_ext_tmds_info_from_table(struct radeon_encoder *encoder,
503 struct radeon_encoder_ext_tmds *tmds);
504 extern struct radeon_encoder_primary_dac *
505 radeon_atombios_get_primary_dac_info(struct radeon_encoder *encoder);
506 extern struct radeon_encoder_tv_dac *
507 radeon_atombios_get_tv_dac_info(struct radeon_encoder *encoder);
508 extern struct radeon_encoder_lvds *
509 radeon_combios_get_lvds_info(struct radeon_encoder *encoder);
510 extern void radeon_combios_get_ext_tmds_info(struct radeon_encoder *encoder);
511 extern struct radeon_encoder_tv_dac *
512 radeon_combios_get_tv_dac_info(struct radeon_encoder *encoder);
513 extern struct radeon_encoder_primary_dac *
514 radeon_combios_get_primary_dac_info(struct radeon_encoder *encoder);
515 extern bool radeon_combios_external_tmds_setup(struct drm_encoder *encoder);
516 extern void radeon_external_tmds_setup(struct drm_encoder *encoder);
517 extern void radeon_combios_output_lock(struct drm_encoder *encoder, bool lock);
518 extern void radeon_combios_initialize_bios_scratch_regs(struct drm_device *dev);
519 extern void radeon_atom_output_lock(struct drm_encoder *encoder, bool lock);
520 extern void radeon_atom_initialize_bios_scratch_regs(struct drm_device *dev);
521 extern void radeon_save_bios_scratch_regs(struct radeon_device *rdev);
522 extern void radeon_restore_bios_scratch_regs(struct radeon_device *rdev);
523 extern void
524 radeon_atombios_encoder_crtc_scratch_regs(struct drm_encoder *encoder, int crtc);
525 extern void
526 radeon_atombios_encoder_dpms_scratch_regs(struct drm_encoder *encoder, bool on);
527 extern void
528 radeon_combios_encoder_crtc_scratch_regs(struct drm_encoder *encoder, int crtc);
529 extern void
530 radeon_combios_encoder_dpms_scratch_regs(struct drm_encoder *encoder, bool on);
531 extern void radeon_crtc_fb_gamma_set(struct drm_crtc *crtc, u16 red, u16 green,
532 u16 blue, int regno);
533 extern void radeon_crtc_fb_gamma_get(struct drm_crtc *crtc, u16 *red, u16 *green,
534 u16 *blue, int regno);
535 struct drm_framebuffer *radeon_framebuffer_create(struct drm_device *dev,
536 struct drm_mode_fb_cmd *mode_cmd,
537 struct drm_gem_object *obj);
539 int radeonfb_probe(struct drm_device *dev);
541 int radeonfb_remove(struct drm_device *dev, struct drm_framebuffer *fb);
542 bool radeon_get_legacy_connector_info_from_bios(struct drm_device *dev);
543 bool radeon_get_legacy_connector_info_from_table(struct drm_device *dev);
544 void radeon_atombios_init_crtc(struct drm_device *dev,
545 struct radeon_crtc *radeon_crtc);
546 void radeon_legacy_init_crtc(struct drm_device *dev,
547 struct radeon_crtc *radeon_crtc);
549 void radeon_get_clock_info(struct drm_device *dev);
551 extern bool radeon_get_atom_connector_info_from_object_table(struct drm_device *dev);
552 extern bool radeon_get_atom_connector_info_from_supported_devices_table(struct drm_device *dev);
554 void radeon_enc_destroy(struct drm_encoder *encoder);
555 void radeon_copy_fb(struct drm_device *dev, struct drm_gem_object *dst_obj);
556 void radeon_combios_asic_init(struct drm_device *dev);
557 extern int radeon_static_clocks_init(struct drm_device *dev);
558 bool radeon_crtc_scaling_mode_fixup(struct drm_crtc *crtc,
559 struct drm_display_mode *mode,
560 struct drm_display_mode *adjusted_mode);
561 void atom_rv515_force_tv_scaler(struct radeon_device *rdev, struct radeon_crtc *radeon_crtc);
563 /* legacy tv */
564 void radeon_legacy_tv_adjust_crtc_reg(struct drm_encoder *encoder,
565 uint32_t *h_total_disp, uint32_t *h_sync_strt_wid,
566 uint32_t *v_total_disp, uint32_t *v_sync_strt_wid);
567 void radeon_legacy_tv_adjust_pll1(struct drm_encoder *encoder,
568 uint32_t *htotal_cntl, uint32_t *ppll_ref_div,
569 uint32_t *ppll_div_3, uint32_t *pixclks_cntl);
570 void radeon_legacy_tv_adjust_pll2(struct drm_encoder *encoder,
571 uint32_t *htotal2_cntl, uint32_t *p2pll_ref_div,
572 uint32_t *p2pll_div_0, uint32_t *pixclks_cntl);
573 void radeon_legacy_tv_mode_set(struct drm_encoder *encoder,
574 struct drm_display_mode *mode,
575 struct drm_display_mode *adjusted_mode);
576 #endif