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.
25 * Kevin E. Martin, Rickard E. Faith, Alan Hourihane
27 * Kernel port Author: Dave Airlie
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"
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
{
68 /* radeon gpio-based i2c
69 * 1. "mask" reg and bits
70 * grabs the gpio pins for software use
75 * 3. "en" reg and bits
76 * sets the pin direction
82 struct radeon_i2c_bus_rec
{
88 /* can be used with hw i2c engine */
90 /* uses multi-media i2c engine */
93 uint32_t mask_clk_reg
;
94 uint32_t mask_data_reg
;
101 uint32_t mask_clk_mask
;
102 uint32_t mask_data_mask
;
104 uint32_t a_data_mask
;
105 uint32_t en_clk_mask
;
106 uint32_t en_data_mask
;
108 uint32_t y_data_mask
;
111 struct radeon_tmds_pll
{
116 #define RADEON_MAX_BIOS_CONNECTOR 16
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)
135 enum radeon_pll_algo
{
141 /* reference frequency */
142 uint32_t reference_freq
;
145 uint32_t reference_div
;
148 /* pll in/out limits */
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
;
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 */
173 enum radeon_pll_algo algo
;
176 struct radeon_i2c_chan
{
177 struct i2c_adapter adapter
;
178 struct drm_device
*dev
;
180 struct i2c_algo_bit_data bit
;
181 struct i2c_algo_dp_aux_data dp
;
183 struct radeon_i2c_bus_rec rec
;
186 /* mostly for macs, but really any system without connector tables */
187 enum radeon_connector_table
{
191 CT_POWERBOOK_EXTERNAL
,
192 CT_POWERBOOK_INTERNAL
,
200 enum radeon_dvo_chip
{
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
{
230 uint32_t timing_cntl
;
234 uint16_t h_code_timing
[MAX_H_CODE_TIMING_LEN
];
235 uint16_t v_code_timing
[MAX_V_CODE_TIMING_LEN
];
239 struct drm_crtc base
;
241 u16 lut_r
[256], lut_g
[256], lut_b
[256];
244 uint32_t crtc_offset
;
245 struct drm_gem_object
*cursor_bo
;
246 uint64_t cursor_addr
;
249 uint32_t legacy_display_base_addr
;
250 uint32_t legacy_cursor_offset
;
251 enum radeon_rmx_type rmx_type
;
254 struct drm_display_mode native_mode
;
258 struct radeon_encoder_primary_dac
{
259 /* legacy primary dac */
260 uint32_t ps2_pdac_adj
;
263 struct radeon_encoder_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
;
275 struct drm_display_mode native_mode
;
278 struct radeon_encoder_tv_dac
{
280 uint32_t ps2_tvdac_adj
;
281 uint32_t ntsc_tvdac_adj
;
282 uint32_t pal_tvdac_adj
;
287 int supported_tv_stds
;
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
{
300 struct radeon_i2c_chan
*i2c_bus
;
302 enum radeon_dvo_chip dvo_chip
;
305 /* spread spectrum */
306 struct radeon_atom_ss
{
315 struct radeon_encoder_atom_dig
{
318 int dig_encoder
; /* -1 disabled, 0 DIGA, 1 DIGB */
321 uint16_t panel_pwr_delay
;
322 enum radeon_pll_algo pll_algo
;
323 struct radeon_atom_ss
*ss
;
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
;
336 uint32_t active_device
;
338 uint32_t pixel_clock
;
339 enum radeon_rmx_type rmx_type
;
340 struct drm_display_mode native_mode
;
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
;
352 struct radeon_i2c_chan
*dp_i2c_bus
;
359 struct radeon_gpio_rec
{
377 enum radeon_hpd_id hpd
;
379 struct radeon_gpio_rec gpio
;
382 struct radeon_connector
{
383 struct drm_connector base
;
384 uint32_t connector_id
;
386 struct radeon_i2c_chan
*ddc_bus
;
387 /* some systems have a an hdmi and vga port with a shared ddc line */
390 /* we need to mind the EDID between detect
391 and get modes due to analog/digital/tvencoder */
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
,
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
,
429 extern struct radeon_i2c_chan
*radeon_i2c_create(struct drm_device
*dev
,
430 struct radeon_i2c_bus_rec
*rec
,
432 extern void radeon_i2c_destroy(struct radeon_i2c_chan
*i2c
);
433 extern void radeon_i2c_get_byte(struct radeon_i2c_chan
*i2c_bus
,
437 extern void radeon_i2c_put_byte(struct radeon_i2c_chan
*i2c
,
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
,
448 uint32_t *dot_clock_p
,
450 uint32_t *frac_fb_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
,
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
,
484 extern int radeon_crtc_cursor_move(struct drm_crtc
*crtc
,
487 extern bool radeon_combios_check_hardcoded_edid(struct radeon_device
*rdev
);
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
);
524 radeon_atombios_encoder_crtc_scratch_regs(struct drm_encoder
*encoder
, int crtc
);
526 radeon_atombios_encoder_dpms_scratch_regs(struct drm_encoder
*encoder
, bool on
);
528 radeon_combios_encoder_crtc_scratch_regs(struct drm_encoder
*encoder
, int crtc
);
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
);
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
);