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
{
86 /* can be used with hw i2c engine */
88 /* uses multi-media i2c engine */
91 uint32_t mask_clk_reg
;
92 uint32_t mask_data_reg
;
99 uint32_t mask_clk_mask
;
100 uint32_t mask_data_mask
;
102 uint32_t a_data_mask
;
103 uint32_t en_clk_mask
;
104 uint32_t en_data_mask
;
106 uint32_t y_data_mask
;
109 struct radeon_tmds_pll
{
114 #define RADEON_MAX_BIOS_CONNECTOR 16
116 #define RADEON_PLL_USE_BIOS_DIVS (1 << 0)
117 #define RADEON_PLL_NO_ODD_POST_DIV (1 << 1)
118 #define RADEON_PLL_USE_REF_DIV (1 << 2)
119 #define RADEON_PLL_LEGACY (1 << 3)
120 #define RADEON_PLL_PREFER_LOW_REF_DIV (1 << 4)
121 #define RADEON_PLL_PREFER_HIGH_REF_DIV (1 << 5)
122 #define RADEON_PLL_PREFER_LOW_FB_DIV (1 << 6)
123 #define RADEON_PLL_PREFER_HIGH_FB_DIV (1 << 7)
124 #define RADEON_PLL_PREFER_LOW_POST_DIV (1 << 8)
125 #define RADEON_PLL_PREFER_HIGH_POST_DIV (1 << 9)
126 #define RADEON_PLL_USE_FRAC_FB_DIV (1 << 10)
127 #define RADEON_PLL_PREFER_CLOSEST_LOWER (1 << 11)
128 #define RADEON_PLL_USE_POST_DIV (1 << 12)
131 /* reference frequency */
132 uint32_t reference_freq
;
135 uint32_t reference_div
;
138 /* pll in/out limits */
141 uint32_t pll_out_min
;
142 uint32_t pll_out_max
;
146 uint32_t min_ref_div
;
147 uint32_t max_ref_div
;
148 uint32_t min_post_div
;
149 uint32_t max_post_div
;
150 uint32_t min_feedback_div
;
151 uint32_t max_feedback_div
;
152 uint32_t min_frac_feedback_div
;
153 uint32_t max_frac_feedback_div
;
155 /* flags for the current clock */
162 struct radeon_i2c_chan
{
163 struct i2c_adapter adapter
;
164 struct drm_device
*dev
;
166 struct i2c_algo_dp_aux_data dp
;
167 struct i2c_algo_bit_data bit
;
169 struct radeon_i2c_bus_rec rec
;
172 /* mostly for macs, but really any system without connector tables */
173 enum radeon_connector_table
{
177 CT_POWERBOOK_EXTERNAL
,
178 CT_POWERBOOK_INTERNAL
,
186 enum radeon_dvo_chip
{
191 struct radeon_mode_info
{
192 struct atom_context
*atom_context
;
193 struct card_info
*atom_card_info
;
194 enum radeon_connector_table connector_table
;
195 bool mode_config_initialized
;
196 struct radeon_crtc
*crtcs
[2];
197 /* DVI-I properties */
198 struct drm_property
*coherent_mode_property
;
199 /* DAC enable load detect */
200 struct drm_property
*load_detect_property
;
201 /* TV standard load detect */
202 struct drm_property
*tv_std_property
;
203 /* legacy TMDS PLL detect */
204 struct drm_property
*tmds_pll_property
;
208 #define MAX_H_CODE_TIMING_LEN 32
209 #define MAX_V_CODE_TIMING_LEN 32
211 /* need to store these as reading
212 back code tables is excessive */
213 struct radeon_tv_regs
{
215 uint32_t timing_cntl
;
219 uint16_t h_code_timing
[MAX_H_CODE_TIMING_LEN
];
220 uint16_t v_code_timing
[MAX_V_CODE_TIMING_LEN
];
224 struct drm_crtc base
;
226 u16 lut_r
[256], lut_g
[256], lut_b
[256];
229 uint32_t crtc_offset
;
230 struct drm_gem_object
*cursor_bo
;
231 uint64_t cursor_addr
;
234 uint32_t legacy_display_base_addr
;
235 uint32_t legacy_cursor_offset
;
236 enum radeon_rmx_type rmx_type
;
239 struct drm_display_mode native_mode
;
242 struct radeon_encoder_primary_dac
{
243 /* legacy primary dac */
244 uint32_t ps2_pdac_adj
;
247 struct radeon_encoder_lvds
{
249 uint16_t panel_vcc_delay
;
250 uint8_t panel_pwr_delay
;
251 uint8_t panel_digon_delay
;
252 uint8_t panel_blon_delay
;
253 uint16_t panel_ref_divider
;
254 uint8_t panel_post_divider
;
255 uint16_t panel_fb_divider
;
256 bool use_bios_dividers
;
257 uint32_t lvds_gen_cntl
;
259 struct drm_display_mode native_mode
;
262 struct radeon_encoder_tv_dac
{
264 uint32_t ps2_tvdac_adj
;
265 uint32_t ntsc_tvdac_adj
;
266 uint32_t pal_tvdac_adj
;
271 int supported_tv_stds
;
273 enum radeon_tv_std tv_std
;
274 struct radeon_tv_regs tv
;
277 struct radeon_encoder_int_tmds
{
278 /* legacy int tmds */
279 struct radeon_tmds_pll tmds_pll
[4];
282 struct radeon_encoder_ext_tmds
{
284 struct radeon_i2c_chan
*i2c_bus
;
286 enum radeon_dvo_chip dvo_chip
;
289 /* spread spectrum */
290 struct radeon_atom_ss
{
299 struct radeon_encoder_atom_dig
{
305 uint16_t panel_pwr_delay
;
306 struct radeon_atom_ss
*ss
;
308 struct drm_display_mode native_mode
;
311 struct radeon_encoder_atom_dac
{
312 enum radeon_tv_std tv_std
;
315 struct radeon_encoder
{
316 struct drm_encoder base
;
319 uint32_t active_device
;
321 uint32_t pixel_clock
;
322 enum radeon_rmx_type rmx_type
;
323 struct drm_display_mode native_mode
;
326 int hdmi_audio_workaround
;
327 int hdmi_buffer_status
;
330 struct radeon_connector_atom_dig
{
331 uint32_t igp_lane_info
;
334 struct radeon_i2c_chan
*dp_i2c_bus
;
341 struct radeon_gpio_rec
{
359 enum radeon_hpd_id hpd
;
361 struct radeon_gpio_rec gpio
;
364 struct radeon_connector
{
365 struct drm_connector base
;
366 uint32_t connector_id
;
368 struct radeon_i2c_chan
*ddc_bus
;
369 /* some systems have a an hdmi and vga port with a shared ddc line */
372 /* we need to mind the EDID between detect
373 and get modes due to analog/digital/tvencoder */
376 bool dac_load_detect
;
377 uint16_t connector_object_id
;
378 struct radeon_hpd hpd
;
381 struct radeon_framebuffer
{
382 struct drm_framebuffer base
;
383 struct drm_gem_object
*obj
;
386 extern enum radeon_tv_std
387 radeon_combios_get_tv_info(struct radeon_device
*rdev
);
388 extern enum radeon_tv_std
389 radeon_atombios_get_tv_info(struct radeon_device
*rdev
);
391 extern void radeon_connector_hotplug(struct drm_connector
*connector
);
392 extern bool radeon_dp_needs_link_train(struct radeon_connector
*radeon_connector
);
393 extern int radeon_dp_mode_valid_helper(struct radeon_connector
*radeon_connector
,
394 struct drm_display_mode
*mode
);
395 extern void radeon_dp_set_link_config(struct drm_connector
*connector
,
396 struct drm_display_mode
*mode
);
397 extern void dp_link_train(struct drm_encoder
*encoder
,
398 struct drm_connector
*connector
);
399 extern u8
radeon_dp_getsinktype(struct radeon_connector
*radeon_connector
);
400 extern bool radeon_dp_getdpcd(struct radeon_connector
*radeon_connector
);
401 extern void atombios_dig_transmitter_setup(struct drm_encoder
*encoder
,
402 int action
, uint8_t lane_num
,
404 extern int radeon_dp_i2c_aux_ch(struct i2c_adapter
*adapter
, int mode
,
405 uint8_t write_byte
, uint8_t *read_byte
);
407 extern struct radeon_i2c_chan
*radeon_i2c_create_dp(struct drm_device
*dev
,
408 struct radeon_i2c_bus_rec
*rec
,
410 extern struct radeon_i2c_chan
*radeon_i2c_create(struct drm_device
*dev
,
411 struct radeon_i2c_bus_rec
*rec
,
413 extern void radeon_i2c_destroy(struct radeon_i2c_chan
*i2c
);
414 extern void radeon_i2c_sw_get_byte(struct radeon_i2c_chan
*i2c_bus
,
418 extern void radeon_i2c_sw_put_byte(struct radeon_i2c_chan
*i2c
,
422 extern bool radeon_ddc_probe(struct radeon_connector
*radeon_connector
);
423 extern int radeon_ddc_get_modes(struct radeon_connector
*radeon_connector
);
425 extern struct drm_encoder
*radeon_best_encoder(struct drm_connector
*connector
);
427 extern void radeon_compute_pll(struct radeon_pll
*pll
,
429 uint32_t *dot_clock_p
,
431 uint32_t *frac_fb_div_p
,
433 uint32_t *post_div_p
);
435 extern void radeon_compute_pll_avivo(struct radeon_pll
*pll
,
437 uint32_t *dot_clock_p
,
439 uint32_t *frac_fb_div_p
,
441 uint32_t *post_div_p
);
443 extern void radeon_setup_encoder_clones(struct drm_device
*dev
);
445 struct drm_encoder
*radeon_encoder_legacy_lvds_add(struct drm_device
*dev
, int bios_index
);
446 struct drm_encoder
*radeon_encoder_legacy_primary_dac_add(struct drm_device
*dev
, int bios_index
, int with_tv
);
447 struct drm_encoder
*radeon_encoder_legacy_tv_dac_add(struct drm_device
*dev
, int bios_index
, int with_tv
);
448 struct drm_encoder
*radeon_encoder_legacy_tmds_int_add(struct drm_device
*dev
, int bios_index
);
449 struct drm_encoder
*radeon_encoder_legacy_tmds_ext_add(struct drm_device
*dev
, int bios_index
);
450 extern void atombios_external_tmds_setup(struct drm_encoder
*encoder
, int action
);
451 extern void atombios_digital_setup(struct drm_encoder
*encoder
, int action
);
452 extern int atombios_get_encoder_mode(struct drm_encoder
*encoder
);
453 extern void radeon_encoder_set_active_device(struct drm_encoder
*encoder
);
455 extern void radeon_crtc_load_lut(struct drm_crtc
*crtc
);
456 extern int atombios_crtc_set_base(struct drm_crtc
*crtc
, int x
, int y
,
457 struct drm_framebuffer
*old_fb
);
458 extern int atombios_crtc_mode_set(struct drm_crtc
*crtc
,
459 struct drm_display_mode
*mode
,
460 struct drm_display_mode
*adjusted_mode
,
462 struct drm_framebuffer
*old_fb
);
463 extern void atombios_crtc_dpms(struct drm_crtc
*crtc
, int mode
);
465 extern int radeon_crtc_set_base(struct drm_crtc
*crtc
, int x
, int y
,
466 struct drm_framebuffer
*old_fb
);
468 extern int radeon_crtc_cursor_set(struct drm_crtc
*crtc
,
469 struct drm_file
*file_priv
,
473 extern int radeon_crtc_cursor_move(struct drm_crtc
*crtc
,
476 extern bool radeon_atom_get_clock_info(struct drm_device
*dev
);
477 extern bool radeon_combios_get_clock_info(struct drm_device
*dev
);
478 extern struct radeon_encoder_atom_dig
*
479 radeon_atombios_get_lvds_info(struct radeon_encoder
*encoder
);
480 extern bool radeon_atombios_get_tmds_info(struct radeon_encoder
*encoder
,
481 struct radeon_encoder_int_tmds
*tmds
);
482 extern bool radeon_legacy_get_tmds_info_from_combios(struct radeon_encoder
*encoder
,
483 struct radeon_encoder_int_tmds
*tmds
);
484 extern bool radeon_legacy_get_tmds_info_from_table(struct radeon_encoder
*encoder
,
485 struct radeon_encoder_int_tmds
*tmds
);
486 extern bool radeon_legacy_get_ext_tmds_info_from_combios(struct radeon_encoder
*encoder
,
487 struct radeon_encoder_ext_tmds
*tmds
);
488 extern bool radeon_legacy_get_ext_tmds_info_from_table(struct radeon_encoder
*encoder
,
489 struct radeon_encoder_ext_tmds
*tmds
);
490 extern struct radeon_encoder_primary_dac
*
491 radeon_atombios_get_primary_dac_info(struct radeon_encoder
*encoder
);
492 extern struct radeon_encoder_tv_dac
*
493 radeon_atombios_get_tv_dac_info(struct radeon_encoder
*encoder
);
494 extern struct radeon_encoder_lvds
*
495 radeon_combios_get_lvds_info(struct radeon_encoder
*encoder
);
496 extern void radeon_combios_get_ext_tmds_info(struct radeon_encoder
*encoder
);
497 extern struct radeon_encoder_tv_dac
*
498 radeon_combios_get_tv_dac_info(struct radeon_encoder
*encoder
);
499 extern struct radeon_encoder_primary_dac
*
500 radeon_combios_get_primary_dac_info(struct radeon_encoder
*encoder
);
501 extern bool radeon_combios_external_tmds_setup(struct drm_encoder
*encoder
);
502 extern void radeon_external_tmds_setup(struct drm_encoder
*encoder
);
503 extern void radeon_combios_output_lock(struct drm_encoder
*encoder
, bool lock
);
504 extern void radeon_combios_initialize_bios_scratch_regs(struct drm_device
*dev
);
505 extern void radeon_atom_output_lock(struct drm_encoder
*encoder
, bool lock
);
506 extern void radeon_atom_initialize_bios_scratch_regs(struct drm_device
*dev
);
507 extern void radeon_save_bios_scratch_regs(struct radeon_device
*rdev
);
508 extern void radeon_restore_bios_scratch_regs(struct radeon_device
*rdev
);
510 radeon_atombios_encoder_crtc_scratch_regs(struct drm_encoder
*encoder
, int crtc
);
512 radeon_atombios_encoder_dpms_scratch_regs(struct drm_encoder
*encoder
, bool on
);
514 radeon_combios_encoder_crtc_scratch_regs(struct drm_encoder
*encoder
, int crtc
);
516 radeon_combios_encoder_dpms_scratch_regs(struct drm_encoder
*encoder
, bool on
);
517 extern void radeon_crtc_fb_gamma_set(struct drm_crtc
*crtc
, u16 red
, u16 green
,
518 u16 blue
, int regno
);
519 extern void radeon_crtc_fb_gamma_get(struct drm_crtc
*crtc
, u16
*red
, u16
*green
,
520 u16
*blue
, int regno
);
521 struct drm_framebuffer
*radeon_framebuffer_create(struct drm_device
*dev
,
522 struct drm_mode_fb_cmd
*mode_cmd
,
523 struct drm_gem_object
*obj
);
525 int radeonfb_probe(struct drm_device
*dev
);
527 int radeonfb_remove(struct drm_device
*dev
, struct drm_framebuffer
*fb
);
528 bool radeon_get_legacy_connector_info_from_bios(struct drm_device
*dev
);
529 bool radeon_get_legacy_connector_info_from_table(struct drm_device
*dev
);
530 void radeon_atombios_init_crtc(struct drm_device
*dev
,
531 struct radeon_crtc
*radeon_crtc
);
532 void radeon_legacy_init_crtc(struct drm_device
*dev
,
533 struct radeon_crtc
*radeon_crtc
);
534 extern void radeon_i2c_do_lock(struct radeon_i2c_chan
*i2c
, int lock_state
);
536 void radeon_get_clock_info(struct drm_device
*dev
);
538 extern bool radeon_get_atom_connector_info_from_object_table(struct drm_device
*dev
);
539 extern bool radeon_get_atom_connector_info_from_supported_devices_table(struct drm_device
*dev
);
541 void radeon_enc_destroy(struct drm_encoder
*encoder
);
542 void radeon_copy_fb(struct drm_device
*dev
, struct drm_gem_object
*dst_obj
);
543 void radeon_combios_asic_init(struct drm_device
*dev
);
544 extern int radeon_static_clocks_init(struct drm_device
*dev
);
545 bool radeon_crtc_scaling_mode_fixup(struct drm_crtc
*crtc
,
546 struct drm_display_mode
*mode
,
547 struct drm_display_mode
*adjusted_mode
);
548 void atom_rv515_force_tv_scaler(struct radeon_device
*rdev
, struct radeon_crtc
*radeon_crtc
);
551 void radeon_legacy_tv_adjust_crtc_reg(struct drm_encoder
*encoder
,
552 uint32_t *h_total_disp
, uint32_t *h_sync_strt_wid
,
553 uint32_t *v_total_disp
, uint32_t *v_sync_strt_wid
);
554 void radeon_legacy_tv_adjust_pll1(struct drm_encoder
*encoder
,
555 uint32_t *htotal_cntl
, uint32_t *ppll_ref_div
,
556 uint32_t *ppll_div_3
, uint32_t *pixclks_cntl
);
557 void radeon_legacy_tv_adjust_pll2(struct drm_encoder
*encoder
,
558 uint32_t *htotal2_cntl
, uint32_t *p2pll_ref_div
,
559 uint32_t *p2pll_div_0
, uint32_t *pixclks_cntl
);
560 void radeon_legacy_tv_mode_set(struct drm_encoder
*encoder
,
561 struct drm_display_mode
*mode
,
562 struct drm_display_mode
*adjusted_mode
);